From ca5598dd1001fb9d6f01623e9ac1c5959c7e932d Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Thu, 4 Nov 2021 19:22:25 -0700 Subject: [PATCH] Move dagger modules into shell library for reuse - Certain system ui implementations which use the shell don't depend on SystemUI-core, which means that the dagger modules for providing the core Shell components need to be copied (which makes it more cumbersome to make changes). Instead, move these modules back into the shell lib for any SysUI app to reference. Bug: 205019015 Test: make SystemUIGoogle Test: make CarSystemUI Test: make ArcSystemUI Change-Id: I8dc938a7695972f9d7b3d7ea8e3ce65a7b454b13 --- libs/WindowManager/Shell/Android.bp | 3 +- .../WindowManager/Shell/res/values/config.xml | 4 +++ .../annotations/ExternalMainThread.java | 34 +++++++++++++++++++ .../com/android/wm/shell/dagger/README.txt | 13 +++++++ .../android/wm/shell/dagger}/TvPipModule.java | 5 ++- .../wm/shell/dagger}/TvWMShellModule.java | 6 ++-- .../wm/shell/dagger}/WMShellBaseModule.java | 6 ++-- .../dagger}/WMShellConcurrencyModule.java | 33 +++++++++++++----- .../wm/shell/dagger}/WMShellModule.java | 6 ++-- .../android/wm/shell}/dagger/WMSingleton.java | 4 +-- packages/SystemUI/res/values/config.xml | 3 -- .../android/systemui/dagger/WMComponent.java | 5 +-- .../android/systemui/tv/TvWMComponent.java | 4 +-- 13 files changed, 92 insertions(+), 34 deletions(-) create mode 100644 libs/WindowManager/Shell/src/com/android/wm/shell/common/annotations/ExternalMainThread.java create mode 100644 libs/WindowManager/Shell/src/com/android/wm/shell/dagger/README.txt rename {packages/SystemUI/src/com/android/systemui/wmshell => libs/WindowManager/Shell/src/com/android/wm/shell/dagger}/TvPipModule.java (98%) rename {packages/SystemUI/src/com/android/systemui/wmshell => libs/WindowManager/Shell/src/com/android/wm/shell/dagger}/TvWMShellModule.java (95%) rename {packages/SystemUI/src/com/android/systemui/wmshell => libs/WindowManager/Shell/src/com/android/wm/shell/dagger}/WMShellBaseModule.java (99%) rename {packages/SystemUI/src/com/android/systemui/wmshell => libs/WindowManager/Shell/src/com/android/wm/shell/dagger}/WMShellConcurrencyModule.java (87%) rename {packages/SystemUI/src/com/android/systemui/wmshell => libs/WindowManager/Shell/src/com/android/wm/shell/dagger}/WMShellModule.java (98%) rename {packages/SystemUI/src/com/android/systemui => libs/WindowManager/Shell/src/com/android/wm/shell}/dagger/WMSingleton.java (90%) diff --git a/libs/WindowManager/Shell/Android.bp b/libs/WindowManager/Shell/Android.bp index 73c2e8bfa78f7..8e3d726362f2c 100644 --- a/libs/WindowManager/Shell/Android.bp +++ b/libs/WindowManager/Shell/Android.bp @@ -132,11 +132,12 @@ android_library { "kotlinx-coroutines-android", "kotlinx-coroutines-core", "iconloader_base", - "jsr330", "protolog-lib", "WindowManager-Shell-proto", + "dagger2", "jsr330", ], kotlincflags: ["-Xjvm-default=enable"], manifest: "AndroidManifest.xml", + plugins: ["dagger2-compiler"], } diff --git a/libs/WindowManager/Shell/res/values/config.xml b/libs/WindowManager/Shell/res/values/config.xml index d0e4f7a02ffcf..0cdaa206c156b 100644 --- a/libs/WindowManager/Shell/res/values/config.xml +++ b/libs/WindowManager/Shell/res/values/config.xml @@ -15,6 +15,10 @@ limitations under the License. --> + + false + 425 diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/annotations/ExternalMainThread.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/annotations/ExternalMainThread.java new file mode 100644 index 0000000000000..9ac7a12bc5095 --- /dev/null +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/annotations/ExternalMainThread.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2021 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.wm.shell.common.annotations; + +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; + +import javax.inject.Qualifier; + +/** + * Annotates a method or qualifies a provider that runs on the main-thread of the process using + * this library. + */ +@Qualifier +@Documented +@Retention(RUNTIME) +public @interface ExternalMainThread { +} diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/README.txt b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/README.txt new file mode 100644 index 0000000000000..1cd69edf7cd23 --- /dev/null +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/README.txt @@ -0,0 +1,13 @@ +The dagger modules in this directory can be included by the host SysUI using the Shell library for +explicity injection of Shell components. Apps using this library are not required to use these +dagger modules for setup, but it is recommended for them to include them as needed. + +The modules are currently inherited as such: + ++- WMShellBaseModule (common shell features across SysUI) + | + +- WMShellModule (handheld) + | + +- TvPipModule (tv pip) + | + +- TvWMShellModule (tv) \ No newline at end of file diff --git a/packages/SystemUI/src/com/android/systemui/wmshell/TvPipModule.java b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/TvPipModule.java similarity index 98% rename from packages/SystemUI/src/com/android/systemui/wmshell/TvPipModule.java rename to libs/WindowManager/Shell/src/com/android/wm/shell/dagger/TvPipModule.java index 4e80151d009d7..711a0ac76702a 100644 --- a/packages/SystemUI/src/com/android/systemui/wmshell/TvPipModule.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/TvPipModule.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 The Android Open Source Project + * Copyright (C) 2021 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. @@ -14,12 +14,11 @@ * limitations under the License. */ -package com.android.systemui.wmshell; +package com.android.wm.shell.dagger; import android.content.Context; import android.os.Handler; -import com.android.systemui.dagger.WMSingleton; import com.android.wm.shell.ShellTaskOrganizer; import com.android.wm.shell.WindowManagerShellWrapper; import com.android.wm.shell.common.DisplayController; diff --git a/packages/SystemUI/src/com/android/systemui/wmshell/TvWMShellModule.java b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/TvWMShellModule.java similarity index 95% rename from packages/SystemUI/src/com/android/systemui/wmshell/TvWMShellModule.java rename to libs/WindowManager/Shell/src/com/android/wm/shell/dagger/TvWMShellModule.java index dbdc460b7d83c..6997d60c75f14 100644 --- a/packages/SystemUI/src/com/android/systemui/wmshell/TvWMShellModule.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/TvWMShellModule.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 The Android Open Source Project + * Copyright (C) 2021 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. @@ -14,14 +14,12 @@ * limitations under the License. */ -package com.android.systemui.wmshell; +package com.android.wm.shell.dagger; import android.animation.AnimationHandler; import android.content.Context; import android.view.IWindowManager; -import com.android.systemui.dagger.WMComponent; -import com.android.systemui.dagger.WMSingleton; import com.android.wm.shell.ShellTaskOrganizer; import com.android.wm.shell.common.DisplayController; import com.android.wm.shell.common.DisplayImeController; diff --git a/packages/SystemUI/src/com/android/systemui/wmshell/WMShellBaseModule.java b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellBaseModule.java similarity index 99% rename from packages/SystemUI/src/com/android/systemui/wmshell/WMShellBaseModule.java rename to libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellBaseModule.java index b85ceefb4aab0..a56494943885c 100644 --- a/packages/SystemUI/src/com/android/systemui/wmshell/WMShellBaseModule.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellBaseModule.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 The Android Open Source Project + * Copyright (C) 2021 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.systemui.wmshell; +package com.android.wm.shell.dagger; import android.app.ActivityTaskManager; import android.content.Context; @@ -27,8 +27,6 @@ import android.view.WindowManager; import com.android.internal.logging.UiEventLogger; import com.android.internal.statusbar.IStatusBarService; import com.android.launcher3.icons.IconProvider; -import com.android.systemui.dagger.WMComponent; -import com.android.systemui.dagger.WMSingleton; import com.android.wm.shell.RootDisplayAreaOrganizer; import com.android.wm.shell.RootTaskDisplayAreaOrganizer; import com.android.wm.shell.ShellCommandHandler; diff --git a/packages/SystemUI/src/com/android/systemui/wmshell/WMShellConcurrencyModule.java b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellConcurrencyModule.java similarity index 87% rename from packages/SystemUI/src/com/android/systemui/wmshell/WMShellConcurrencyModule.java rename to libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellConcurrencyModule.java index 61f50b5aae302..5c205f97beb70 100644 --- a/packages/SystemUI/src/com/android/systemui/wmshell/WMShellConcurrencyModule.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellConcurrencyModule.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 The Android Open Source Project + * Copyright (C) 2021 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.systemui.wmshell; +package com.android.wm.shell.dagger; import static android.os.Process.THREAD_PRIORITY_DISPLAY; import static android.os.Process.THREAD_PRIORITY_TOP_APP_BOOST; @@ -24,18 +24,18 @@ import android.content.Context; import android.os.Build; import android.os.Handler; import android.os.HandlerThread; +import android.os.Looper; import android.os.Trace; import com.android.internal.graphics.SfVsyncFrameCallbackProvider; -import com.android.systemui.R; -import com.android.systemui.dagger.WMSingleton; -import com.android.systemui.dagger.qualifiers.Main; import com.android.wm.shell.common.HandlerExecutor; import com.android.wm.shell.common.ShellExecutor; import com.android.wm.shell.common.annotations.ChoreographerSfVsync; +import com.android.wm.shell.common.annotations.ExternalMainThread; import com.android.wm.shell.common.annotations.ShellAnimationThread; import com.android.wm.shell.common.annotations.ShellMainThread; import com.android.wm.shell.common.annotations.ShellSplashscreenThread; +import com.android.wm.shell.R; import dagger.Module; import dagger.Provides; @@ -61,13 +61,26 @@ public abstract class WMShellConcurrencyModule { // Shell Concurrency - Components used for managing threading in the Shell and SysUI // + + /** + * Provide a SysUI main-thread Handler. + * + * Prefer the Main Executor when possible. + */ + @Provides + @ExternalMainThread + public static Handler provideMainHandler() { + return new Handler(Looper.getMainLooper()); + } + /** * Provide a SysUI main-thread Executor. */ @WMSingleton @Provides - @Main - public static ShellExecutor provideSysUIMainExecutor(@Main Handler sysuiMainHandler) { + @ExternalMainThread + public static ShellExecutor provideSysUIMainExecutor( + @ExternalMainThread Handler sysuiMainHandler) { return new HandlerExecutor(sysuiMainHandler); } @@ -78,7 +91,8 @@ public abstract class WMShellConcurrencyModule { @WMSingleton @Provides @ShellMainThread - public static Handler provideShellMainHandler(Context context, @Main Handler sysuiMainHandler) { + public static Handler provideShellMainHandler(Context context, + @ExternalMainThread Handler sysuiMainHandler) { if (enableShellMainThread(context)) { HandlerThread mainThread = new HandlerThread("wmshell.main", THREAD_PRIORITY_DISPLAY); mainThread.start(); @@ -99,7 +113,8 @@ public abstract class WMShellConcurrencyModule { @Provides @ShellMainThread public static ShellExecutor provideShellMainExecutor(Context context, - @ShellMainThread Handler mainHandler, @Main ShellExecutor sysuiMainExecutor) { + @ShellMainThread Handler mainHandler, + @ExternalMainThread ShellExecutor sysuiMainExecutor) { if (enableShellMainThread(context)) { return new HandlerExecutor(mainHandler); } diff --git a/packages/SystemUI/src/com/android/systemui/wmshell/WMShellModule.java b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java similarity index 98% rename from packages/SystemUI/src/com/android/systemui/wmshell/WMShellModule.java rename to libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java index 5f8bcf935a95a..ec701470354cc 100644 --- a/packages/SystemUI/src/com/android/systemui/wmshell/WMShellModule.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 The Android Open Source Project + * Copyright (C) 2021 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. @@ -14,15 +14,13 @@ * limitations under the License. */ -package com.android.systemui.wmshell; +package com.android.wm.shell.dagger; import android.animation.AnimationHandler; import android.content.Context; import android.os.Handler; import android.view.IWindowManager; -import com.android.systemui.dagger.WMComponent; -import com.android.systemui.dagger.WMSingleton; import com.android.wm.shell.ShellTaskOrganizer; import com.android.wm.shell.WindowManagerShellWrapper; import com.android.wm.shell.apppairs.AppPairsController; diff --git a/packages/SystemUI/src/com/android/systemui/dagger/WMSingleton.java b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMSingleton.java similarity index 90% rename from packages/SystemUI/src/com/android/systemui/dagger/WMSingleton.java rename to libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMSingleton.java index 7292b9e459e08..7f45c38d19a39 100644 --- a/packages/SystemUI/src/com/android/systemui/dagger/WMSingleton.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMSingleton.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 The Android Open Source Project + * Copyright (C) 2021 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.systemui.dagger; +package com.android.wm.shell.dagger; import static java.lang.annotation.RetentionPolicy.RUNTIME; diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml index d0de876a6b27b..16006b4faf6eb 100644 --- a/packages/SystemUI/res/values/config.xml +++ b/packages/SystemUI/res/values/config.xml @@ -654,9 +654,6 @@ false - - false - M25.5,16.3283C28.47,14.8433 31.9167,14 35.5834,14C39.2501,14 42.6968,14.8433 45.6668,16.3283 diff --git a/packages/SystemUI/src/com/android/systemui/dagger/WMComponent.java b/packages/SystemUI/src/com/android/systemui/dagger/WMComponent.java index 634349ec7ea11..d8b77426703e0 100644 --- a/packages/SystemUI/src/com/android/systemui/dagger/WMComponent.java +++ b/packages/SystemUI/src/com/android/systemui/dagger/WMComponent.java @@ -20,13 +20,14 @@ import android.content.Context; import com.android.systemui.SystemUIFactory; import com.android.systemui.tv.TvWMComponent; -import com.android.systemui.wmshell.TvWMShellModule; -import com.android.systemui.wmshell.WMShellModule; +import com.android.wm.shell.dagger.TvWMShellModule; +import com.android.wm.shell.dagger.WMShellModule; import com.android.wm.shell.ShellCommandHandler; import com.android.wm.shell.ShellInit; import com.android.wm.shell.TaskViewFactory; import com.android.wm.shell.apppairs.AppPairs; import com.android.wm.shell.bubbles.Bubbles; +import com.android.wm.shell.dagger.WMSingleton; import com.android.wm.shell.displayareahelper.DisplayAreaHelper; import com.android.wm.shell.hidedisplaycutout.HideDisplayCutout; import com.android.wm.shell.legacysplitscreen.LegacySplitScreen; diff --git a/packages/SystemUI/src/com/android/systemui/tv/TvWMComponent.java b/packages/SystemUI/src/com/android/systemui/tv/TvWMComponent.java index f678513f2ce6b..83706156927b4 100644 --- a/packages/SystemUI/src/com/android/systemui/tv/TvWMComponent.java +++ b/packages/SystemUI/src/com/android/systemui/tv/TvWMComponent.java @@ -17,8 +17,8 @@ package com.android.systemui.tv; import com.android.systemui.dagger.WMComponent; -import com.android.systemui.dagger.WMSingleton; -import com.android.systemui.wmshell.TvWMShellModule; +import com.android.wm.shell.dagger.WMSingleton; +import com.android.wm.shell.dagger.TvWMShellModule; import dagger.Subcomponent;