diff options
author | 2024-08-23 17:15:30 -0700 | |
---|---|---|
committer | 2024-08-28 12:11:47 -0700 | |
commit | bd8633133f79d2da8d13776e48751a00f54e37ee (patch) | |
tree | 59c2a62c1f13a23f42ad5f3872cb4a70564f5095 | |
parent | d064e58ff09979c1c04cfac1dc5a8b77838b8172 (diff) |
Setup Dagger for Launcher (1/n)
Bug: 361850561
Test: Manual
Flag: NONE Dagger Integration
Change-Id: Idbe19f1aa747f519417e21fe8a23a41c52ececc1
5 files changed, 126 insertions, 8 deletions
diff --git a/Android.bp b/Android.bp index def024efee..b205d0c35c 100644 --- a/Android.bp +++ b/Android.bp @@ -27,7 +27,7 @@ java_defaults { "android.os.flags-aconfig-java", "android.appwidget.flags-aconfig-java", "com.android.window.flags.window-aconfig-java", - ] + ], } // Common source files used to build launcher (java and kotlin) @@ -153,7 +153,7 @@ launcher_compose_java_defaults { soong_config_variables: { release_enable_compose_in_launcher: { srcs: [ - ":launcher-compose-enabled-src" + ":launcher-compose-enabled-src", ], // Compose dependencies @@ -166,7 +166,7 @@ launcher_compose_java_defaults { // in compose/launcher3/facade/disabled/. conditions_default: { srcs: [ - ":launcher-compose-disabled-src" + ":launcher-compose-disabled-src", ], static_libs: [], }, @@ -179,7 +179,7 @@ quickstep_compose_java_defaults { soong_config_variables: { release_enable_compose_in_launcher: { srcs: [ - ":launcher-quickstep-compose-enabled-src" + ":launcher-quickstep-compose-enabled-src", ], // Compose dependencies @@ -192,7 +192,7 @@ quickstep_compose_java_defaults { // in compose/quickstep/facade/disabled/. conditions_default: { srcs: [ - ":launcher-quickstep-compose-disabled-src" + ":launcher-quickstep-compose-disabled-src", ], static_libs: [], }, @@ -322,6 +322,8 @@ android_library { "kotlinx_coroutines", "com_android_launcher3_flags_lib", "com_android_wm_shell_flags_lib", + "dagger2", + "jsr330", ], manifest: "AndroidManifest-common.xml", @@ -357,6 +359,7 @@ android_app { sdk_version: "current", min_sdk_version: min_launcher3_sdk_version, target_sdk_version: "current", + plugins: ["dagger2-compiler"], privileged: true, system_ext_specific: true, @@ -392,6 +395,7 @@ android_library { "lottie", "SystemUISharedLib", "SettingsLibSettingsTheme", + "dagger2", ], manifest: "quickstep/AndroidManifest.xml", min_sdk_version: "current", @@ -421,7 +425,10 @@ android_library { "QuickstepResLib", "androidx.room_room-runtime", ], - plugins: ["androidx.room_room-compiler-plugin"], + plugins: [ + "androidx.room_room-compiler-plugin", + "dagger2-compiler", + ], manifest: "quickstep/AndroidManifest.xml", additional_manifests: [ "go/AndroidManifest.xml", @@ -437,7 +444,7 @@ android_library { name: "Launcher3QuickStepLib", defaults: [ "launcher_compose_defaults", - "quickstep_compose_defaults" + "quickstep_compose_defaults", ], srcs: [ ":launcher-src", @@ -458,6 +465,7 @@ android_library { ], manifest: "quickstep/AndroidManifest.xml", platform_apis: true, + plugins: ["dagger2-compiler"], min_sdk_version: "current", // TODO(b/319712088): re-enable use_resource_processor use_resource_processor: false, @@ -500,7 +508,6 @@ android_app { } - // Build rule for Launcher3 Go app with quickstep for Android Go devices. // Note that the following two rules are exactly same, and should // eventually be merged into a single target @@ -540,6 +547,7 @@ android_app { include_filter: ["com.android.launcher3.*"], }, } + android_app { name: "Launcher3QuickStepGo", static_libs: ["Launcher3GoLib"], diff --git a/quickstep/src/com/android/launcher3/dagger/LauncherAppComponent.java b/quickstep/src/com/android/launcher3/dagger/LauncherAppComponent.java new file mode 100644 index 0000000000..dab25820ce --- /dev/null +++ b/quickstep/src/com/android/launcher3/dagger/LauncherAppComponent.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher3.dagger; + +import dagger.Component; + +import javax.inject.Singleton; + +/** + * Root component for Dagger injection for Launcher Quickstep. + */ +@Singleton +@Component +public interface LauncherAppComponent extends LauncherBaseAppComponent { + /** Builder for quickstep LauncherAppComponent. */ + @Component.Builder + interface Builder extends LauncherBaseAppComponent.Builder { + LauncherAppComponent build(); + } +} diff --git a/src/com/android/launcher3/LauncherApplication.java b/src/com/android/launcher3/LauncherApplication.java index 40873be369..8969b60534 100644 --- a/src/com/android/launcher3/LauncherApplication.java +++ b/src/com/android/launcher3/LauncherApplication.java @@ -17,14 +17,23 @@ package com.android.launcher3; import android.app.Application; +import com.android.launcher3.dagger.DaggerLauncherAppComponent; +import com.android.launcher3.dagger.LauncherBaseAppComponent; + /** * Main application class for Launcher */ public class LauncherApplication extends Application { + private LauncherBaseAppComponent mAppComponent; @Override public void onCreate() { super.onCreate(); MainProcessInitializer.initialize(this); + mAppComponent = DaggerLauncherAppComponent.builder().build(); + } + + public LauncherBaseAppComponent getAppComponent() { + return mAppComponent; } } diff --git a/src/com/android/launcher3/dagger/LauncherBaseAppComponent.java b/src/com/android/launcher3/dagger/LauncherBaseAppComponent.java new file mode 100644 index 0000000000..3488c95333 --- /dev/null +++ b/src/com/android/launcher3/dagger/LauncherBaseAppComponent.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher3.dagger; + +/** + * Launcher base component for Dagger injection. + * + * This class is not actually annotated as a Dagger component, since it is not used directly as one. + * Doing so generates unnecessary code bloat. + * + * See {@link LauncherAppComponent} for the one actually used by AOSP. + */ +public interface LauncherBaseAppComponent { + /** Builder for LauncherBaseAppComponent. */ + interface Builder { + LauncherBaseAppComponent build(); + } +} diff --git a/src_no_quickstep/com/android/launcher3/dagger/LauncherAppComponent.java b/src_no_quickstep/com/android/launcher3/dagger/LauncherAppComponent.java new file mode 100644 index 0000000000..4d7f93701e --- /dev/null +++ b/src_no_quickstep/com/android/launcher3/dagger/LauncherAppComponent.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher3.dagger; + +import dagger.Component; + +import javax.inject.Singleton; + +/** + * Root component for Dagger injection for Launcher AOSP. + */ +@Singleton +@Component +public interface LauncherAppComponent extends LauncherBaseAppComponent { + /** Builder for aosp LauncherAppComponent. */ + @Component.Builder + interface Builder extends LauncherBaseAppComponent.Builder { + LauncherAppComponent build(); + } +} + |