From 4654239fce4a6da737b0704aa5059f06a01a031d Mon Sep 17 00:00:00 2001 From: Dave Mankoff Date: Mon, 24 Aug 2020 22:49:40 -0400 Subject: Stand up an example of a WMShell api. Fixes: 166173556 Test: manual Change-Id: I43e3ebeddb48430ae76f8f58027363c048fb4d83 --- .../src/com/android/systemui/SystemUIFactory.java | 17 +- .../com/android/systemui/dagger/GlobalModule.java | 6 +- .../systemui/dagger/GlobalRootComponent.java | 7 + .../android/systemui/dagger/SysUIComponent.java | 4 + .../android/systemui/dagger/SystemUIModule.java | 4 +- .../com/android/systemui/dagger/WMComponent.java | 17 ++ .../util/concurrency/ConcurrencyModule.java | 208 --------------------- .../util/concurrency/GlobalConcurrencyModule.java | 70 +++++++ .../util/concurrency/SysUIConcurrencyModule.java | 173 +++++++++++++++++ 9 files changed, 292 insertions(+), 214 deletions(-) delete mode 100644 packages/SystemUI/src/com/android/systemui/util/concurrency/ConcurrencyModule.java create mode 100644 packages/SystemUI/src/com/android/systemui/util/concurrency/GlobalConcurrencyModule.java create mode 100644 packages/SystemUI/src/com/android/systemui/util/concurrency/SysUIConcurrencyModule.java diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java b/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java index f5c364947a2f..941fd6f320e2 100644 --- a/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java +++ b/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java @@ -38,6 +38,7 @@ import com.android.systemui.statusbar.phone.KeyguardBouncer; import com.android.systemui.statusbar.phone.KeyguardBypassController; import com.android.systemui.statusbar.policy.KeyguardStateController; +import java.util.concurrent.ExecutionException; import java.util.concurrent.Executor; /** @@ -83,11 +84,16 @@ public class SystemUIFactory { public SystemUIFactory() {} - private void init(Context context) { + private void init(Context context) throws ExecutionException, InterruptedException { mRootComponent = buildGlobalRootComponent(context); + // Stand up WMComponent mWMComponent = mRootComponent.getWMComponentBuilder().build(); - // TODO: use WMComponent to pass APIs into the SysUIComponent. - mSysUIComponent = mRootComponent.getSysUIComponent().build(); + + // And finally, retrieve whatever SysUI needs from WMShell and build SysUI. + // TODO: StubAPIClass is just a placeholder. + mSysUIComponent = mRootComponent.getSysUIComponent() + .setStubAPIClass(mWMComponent.createStubAPIClass()) + .build(); // Every other part of our codebase currently relies on Dependency, so we // really need to ensure the Dependency gets initialized early on. @@ -101,10 +107,15 @@ public class SystemUIFactory { .build(); } + public GlobalRootComponent getRootComponent() { return mRootComponent; } + public WMComponent getWMComponent() { + return mWMComponent; + } + public SysUIComponent getSysUIComponent() { return mSysUIComponent; } diff --git a/packages/SystemUI/src/com/android/systemui/dagger/GlobalModule.java b/packages/SystemUI/src/com/android/systemui/dagger/GlobalModule.java index fd4a4093110f..c5dc8cccfdf4 100644 --- a/packages/SystemUI/src/com/android/systemui/dagger/GlobalModule.java +++ b/packages/SystemUI/src/com/android/systemui/dagger/GlobalModule.java @@ -16,6 +16,8 @@ package com.android.systemui.dagger; +import com.android.systemui.util.concurrency.GlobalConcurrencyModule; + import dagger.Module; /** @@ -33,6 +35,8 @@ import dagger.Module; * * Please use discretion when adding things to the global scope. */ -@Module(includes = {FrameworkServicesModule.class}) +@Module(includes = { + FrameworkServicesModule.class, + GlobalConcurrencyModule.class}) public class GlobalModule { } diff --git a/packages/SystemUI/src/com/android/systemui/dagger/GlobalRootComponent.java b/packages/SystemUI/src/com/android/systemui/dagger/GlobalRootComponent.java index 36fd3373290d..00fdf55b28e0 100644 --- a/packages/SystemUI/src/com/android/systemui/dagger/GlobalRootComponent.java +++ b/packages/SystemUI/src/com/android/systemui/dagger/GlobalRootComponent.java @@ -18,6 +18,8 @@ package com.android.systemui.dagger; import android.content.Context; +import com.android.systemui.util.concurrency.ThreadFactory; + import javax.inject.Singleton; import dagger.BindsInstance; @@ -53,4 +55,9 @@ public interface GlobalRootComponent { * Builder for a SysuiComponent. */ SysUIComponent.Builder getSysUIComponent(); + + /** + * Build a {@link ThreadFactory}. + */ + ThreadFactory createThreadFactory(); } diff --git a/packages/SystemUI/src/com/android/systemui/dagger/SysUIComponent.java b/packages/SystemUI/src/com/android/systemui/dagger/SysUIComponent.java index a8ed043c4361..2622593880ba 100644 --- a/packages/SystemUI/src/com/android/systemui/dagger/SysUIComponent.java +++ b/packages/SystemUI/src/com/android/systemui/dagger/SysUIComponent.java @@ -26,6 +26,7 @@ import com.android.systemui.pip.phone.dagger.PipModule; import com.android.systemui.statusbar.policy.ConfigurationController; import com.android.systemui.util.InjectionInflationController; +import dagger.BindsInstance; import dagger.Subcomponent; /** @@ -46,6 +47,9 @@ public interface SysUIComponent { */ @Subcomponent.Builder interface Builder { + @BindsInstance + Builder setStubAPIClass(WMComponent.StubAPIClass stubAPIClass); + SysUIComponent build(); } diff --git a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java index 3afe7210f073..99a3a9119f89 100644 --- a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java +++ b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java @@ -42,7 +42,7 @@ import com.android.systemui.statusbar.phone.dagger.StatusBarComponent; import com.android.systemui.statusbar.policy.HeadsUpManager; import com.android.systemui.statusbar.policy.dagger.StatusBarPolicyModule; import com.android.systemui.tuner.dagger.TunerModule; -import com.android.systemui.util.concurrency.ConcurrencyModule; +import com.android.systemui.util.concurrency.SysUIConcurrencyModule; import com.android.systemui.util.dagger.UtilModule; import com.android.systemui.util.sensors.SensorModule; import com.android.systemui.util.settings.SettingsUtilModule; @@ -62,7 +62,6 @@ import dagger.Provides; @Module(includes = { AppOpsModule.class, AssistModule.class, - ConcurrencyModule.class, ControlsModule.class, DemoModeModule.class, LogModule.class, @@ -74,6 +73,7 @@ import dagger.Provides; SettingsModule.class, SettingsUtilModule.class, StatusBarPolicyModule.class, + SysUIConcurrencyModule.class, TunerModule.class, UtilModule.class, VolumeModule.class diff --git a/packages/SystemUI/src/com/android/systemui/dagger/WMComponent.java b/packages/SystemUI/src/com/android/systemui/dagger/WMComponent.java index 929b61a3421c..ad90eff3c969 100644 --- a/packages/SystemUI/src/com/android/systemui/dagger/WMComponent.java +++ b/packages/SystemUI/src/com/android/systemui/dagger/WMComponent.java @@ -16,6 +16,8 @@ package com.android.systemui.dagger; +import javax.inject.Inject; + import dagger.Subcomponent; /** @@ -32,4 +34,19 @@ public interface WMComponent { interface Builder { WMComponent build(); } + + + /** + * Example class used for passing an API to SysUI from WMShell. + * + * TODO: Remove this once real WM classes are ready to go. + **/ + @WMSingleton + class StubAPIClass { + @Inject + StubAPIClass() {} + } + + /** Create a StubAPIClass. */ + StubAPIClass createStubAPIClass(); } diff --git a/packages/SystemUI/src/com/android/systemui/util/concurrency/ConcurrencyModule.java b/packages/SystemUI/src/com/android/systemui/util/concurrency/ConcurrencyModule.java deleted file mode 100644 index 628c808aa12b..000000000000 --- a/packages/SystemUI/src/com/android/systemui/util/concurrency/ConcurrencyModule.java +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright (C) 2019 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.systemui.util.concurrency; - -import android.content.Context; -import android.os.Handler; -import android.os.HandlerThread; -import android.os.Looper; -import android.os.Process; - -import com.android.systemui.dagger.SysUISingleton; -import com.android.systemui.dagger.qualifiers.Background; -import com.android.systemui.dagger.qualifiers.LongRunning; -import com.android.systemui.dagger.qualifiers.Main; -import com.android.systemui.dagger.qualifiers.UiBackground; - -import java.util.concurrent.Executor; -import java.util.concurrent.Executors; - -import dagger.Binds; -import dagger.Module; -import dagger.Provides; - -/** - * Dagger Module for classes found within the concurrent package. - */ -@Module -public abstract class ConcurrencyModule { - /** Background Looper */ - @Provides - @SysUISingleton - @Background - public static Looper provideBgLooper() { - HandlerThread thread = new HandlerThread("SysUiBg", - Process.THREAD_PRIORITY_BACKGROUND); - thread.start(); - return thread.getLooper(); - } - - /** Long running tasks Looper */ - @Provides - @SysUISingleton - @LongRunning - public static Looper provideLongRunningLooper() { - HandlerThread thread = new HandlerThread("SysUiLng", - Process.THREAD_PRIORITY_BACKGROUND); - thread.start(); - return thread.getLooper(); - } - - /** Main Looper */ - @Provides - @Main - public static Looper provideMainLooper() { - return Looper.getMainLooper(); - } - - /** - * Background Handler. - * - * Prefer the Background Executor when possible. - */ - @Provides - @Background - public static Handler provideBgHandler(@Background Looper bgLooper) { - return new Handler(bgLooper); - } - - /** - * Main Handler. - * - * Prefer the Main Executor when possible. - */ - @Provides - @Main - public static Handler provideMainHandler(@Main Looper mainLooper) { - return new Handler(mainLooper); - } - - /** - * Provide a Background-Thread Executor by default. - */ - @Provides - @SysUISingleton - public static Executor provideExecutor(@Background Looper looper) { - return new ExecutorImpl(looper); - } - - /** - * Provide a Long running Executor by default. - */ - @Provides - @SysUISingleton - @LongRunning - public static Executor provideLongRunningExecutor(@LongRunning Looper looper) { - return new ExecutorImpl(looper); - } - - /** - * Provide a Background-Thread Executor. - */ - @Provides - @SysUISingleton - @Background - public static Executor provideBackgroundExecutor(@Background Looper looper) { - return new ExecutorImpl(looper); - } - - /** - * Provide a Main-Thread Executor. - */ - @Provides - @Main - public static Executor provideMainExecutor(Context context) { - return context.getMainExecutor(); - } - - /** - * Provide a Background-Thread Executor by default. - */ - @Provides - @SysUISingleton - public static DelayableExecutor provideDelayableExecutor(@Background Looper looper) { - return new ExecutorImpl(looper); - } - - /** - * Provide a Background-Thread Executor. - */ - @Provides - @SysUISingleton - @Background - public static DelayableExecutor provideBackgroundDelayableExecutor(@Background Looper looper) { - return new ExecutorImpl(looper); - } - - /** - * Provide a Main-Thread Executor. - */ - @Provides - @SysUISingleton - @Main - public static DelayableExecutor provideMainDelayableExecutor(@Main Looper looper) { - return new ExecutorImpl(looper); - } - - /** - * Provide a Background-Thread Executor by default. - */ - @Provides - @SysUISingleton - public static RepeatableExecutor provideRepeatableExecutor(@Background DelayableExecutor exec) { - return new RepeatableExecutorImpl(exec); - } - - /** - * Provide a Background-Thread Executor. - */ - @Provides - @SysUISingleton - @Background - public static RepeatableExecutor provideBackgroundRepeatableExecutor( - @Background DelayableExecutor exec) { - return new RepeatableExecutorImpl(exec); - } - - /** - * Provide a Main-Thread Executor. - */ - @Provides - @SysUISingleton - @Main - public static RepeatableExecutor provideMainRepeatableExecutor(@Main DelayableExecutor exec) { - return new RepeatableExecutorImpl(exec); - } - - /** - * Provide an Executor specifically for running UI operations on a separate thread. - * - * Keep submitted runnables short and to the point, just as with any other UI code. - */ - @Provides - @SysUISingleton - @UiBackground - public static Executor provideUiBackgroundExecutor() { - return Executors.newSingleThreadExecutor(); - } - - /** - * Binds {@link ThreadFactoryImpl} to {@link ThreadFactory}. - */ - @Binds - public abstract ThreadFactory bindExecutorFactory(ThreadFactoryImpl impl); -} diff --git a/packages/SystemUI/src/com/android/systemui/util/concurrency/GlobalConcurrencyModule.java b/packages/SystemUI/src/com/android/systemui/util/concurrency/GlobalConcurrencyModule.java new file mode 100644 index 000000000000..5946af383b0f --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/util/concurrency/GlobalConcurrencyModule.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2019 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.systemui.util.concurrency; + +import android.content.Context; +import android.os.Handler; +import android.os.Looper; + +import com.android.systemui.dagger.qualifiers.Main; + +import java.util.concurrent.Executor; + +import dagger.Binds; +import dagger.Module; +import dagger.Provides; + +/** + * Dagger Module for classes found within the concurrent package. + */ +@Module +public abstract class GlobalConcurrencyModule { + + /** + * Binds {@link ThreadFactoryImpl} to {@link ThreadFactory}. + */ + @Binds + public abstract ThreadFactory bindExecutorFactory(ThreadFactoryImpl impl); + + /** Main Looper */ + @Provides + @Main + public static Looper provideMainLooper() { + return Looper.getMainLooper(); + } + + /** + * Main Handler. + * + * Prefer the Main Executor when possible. + */ + @Provides + @Main + public static Handler provideMainHandler(@Main Looper mainLooper) { + return new Handler(mainLooper); + } + + /** + * Provide a Main-Thread Executor. + */ + @Provides + @Main + public static Executor provideMainExecutor(Context context) { + return context.getMainExecutor(); + } + +} diff --git a/packages/SystemUI/src/com/android/systemui/util/concurrency/SysUIConcurrencyModule.java b/packages/SystemUI/src/com/android/systemui/util/concurrency/SysUIConcurrencyModule.java new file mode 100644 index 000000000000..b9b20c73c5d5 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/util/concurrency/SysUIConcurrencyModule.java @@ -0,0 +1,173 @@ +/* + * Copyright (C) 2019 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.systemui.util.concurrency; + +import android.os.Handler; +import android.os.HandlerThread; +import android.os.Looper; +import android.os.Process; + +import com.android.systemui.dagger.SysUISingleton; +import com.android.systemui.dagger.qualifiers.Background; +import com.android.systemui.dagger.qualifiers.LongRunning; +import com.android.systemui.dagger.qualifiers.Main; +import com.android.systemui.dagger.qualifiers.UiBackground; + +import java.util.concurrent.Executor; +import java.util.concurrent.Executors; + +import dagger.Module; +import dagger.Provides; + +/** + * Dagger Module for classes found within the concurrent package. + */ +@Module +public abstract class SysUIConcurrencyModule { + /** Background Looper */ + @Provides + @SysUISingleton + @Background + public static Looper provideBgLooper() { + HandlerThread thread = new HandlerThread("SysUiBg", + Process.THREAD_PRIORITY_BACKGROUND); + thread.start(); + return thread.getLooper(); + } + + /** Long running tasks Looper */ + @Provides + @SysUISingleton + @LongRunning + public static Looper provideLongRunningLooper() { + HandlerThread thread = new HandlerThread("SysUiLng", + Process.THREAD_PRIORITY_BACKGROUND); + thread.start(); + return thread.getLooper(); + } + + /** + * Background Handler. + * + * Prefer the Background Executor when possible. + */ + @Provides + @Background + public static Handler provideBgHandler(@Background Looper bgLooper) { + return new Handler(bgLooper); + } + + /** + * Provide a Background-Thread Executor by default. + */ + @Provides + @SysUISingleton + public static Executor provideExecutor(@Background Looper looper) { + return new ExecutorImpl(looper); + } + + /** + * Provide a Long running Executor by default. + */ + @Provides + @SysUISingleton + @LongRunning + public static Executor provideLongRunningExecutor(@LongRunning Looper looper) { + return new ExecutorImpl(looper); + } + + /** + * Provide a Background-Thread Executor. + */ + @Provides + @SysUISingleton + @Background + public static Executor provideBackgroundExecutor(@Background Looper looper) { + return new ExecutorImpl(looper); + } + + /** + * Provide a Background-Thread Executor by default. + */ + @Provides + @SysUISingleton + public static DelayableExecutor provideDelayableExecutor(@Background Looper looper) { + return new ExecutorImpl(looper); + } + + /** + * Provide a Background-Thread Executor. + */ + @Provides + @SysUISingleton + @Background + public static DelayableExecutor provideBackgroundDelayableExecutor(@Background Looper looper) { + return new ExecutorImpl(looper); + } + + /** + * Provide a Main-Thread Executor. + */ + @Provides + @SysUISingleton + @Main + public static DelayableExecutor provideMainDelayableExecutor(@Main Looper looper) { + return new ExecutorImpl(looper); + } + + /** + * Provide a Background-Thread Executor by default. + */ + @Provides + @SysUISingleton + public static RepeatableExecutor provideRepeatableExecutor(@Background DelayableExecutor exec) { + return new RepeatableExecutorImpl(exec); + } + + /** + * Provide a Background-Thread Executor. + */ + @Provides + @SysUISingleton + @Background + public static RepeatableExecutor provideBackgroundRepeatableExecutor( + @Background DelayableExecutor exec) { + return new RepeatableExecutorImpl(exec); + } + + /** + * Provide a Main-Thread Executor. + */ + @Provides + @SysUISingleton + @Main + public static RepeatableExecutor provideMainRepeatableExecutor(@Main DelayableExecutor exec) { + return new RepeatableExecutorImpl(exec); + } + + /** + * Provide an Executor specifically for running UI operations on a separate thread. + * + * Keep submitted runnables short and to the point, just as with any other UI code. + */ + @Provides + @SysUISingleton + @UiBackground + public static Executor provideUiBackgroundExecutor() { + return Executors.newSingleThreadExecutor(); + } +} -- cgit v1.2.3-59-g8ed1b