Stand up an example of a WMShell api.

Fixes: 166173556
Test: manual
Change-Id: I43e3ebeddb48430ae76f8f58027363c048fb4d83
This commit is contained in:
Dave Mankoff
2020-08-24 22:49:40 -04:00
parent 9fa9c1f83b
commit 4654239fce
8 changed files with 120 additions and 42 deletions

View File

@@ -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;
}

View File

@@ -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 {
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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

View File

@@ -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();
}

View File

@@ -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();
}
}

View File

@@ -16,7 +16,6 @@
package com.android.systemui.util.concurrency;
import android.content.Context;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
@@ -31,7 +30,6 @@ 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;
@@ -39,7 +37,7 @@ import dagger.Provides;
* Dagger Module for classes found within the concurrent package.
*/
@Module
public abstract class ConcurrencyModule {
public abstract class SysUIConcurrencyModule {
/** Background Looper */
@Provides
@SysUISingleton
@@ -62,13 +60,6 @@ public abstract class ConcurrencyModule {
return thread.getLooper();
}
/** Main Looper */
@Provides
@Main
public static Looper provideMainLooper() {
return Looper.getMainLooper();
}
/**
* Background Handler.
*
@@ -80,17 +71,6 @@ public abstract class ConcurrencyModule {
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.
*/
@@ -120,15 +100,6 @@ public abstract class ConcurrencyModule {
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.
*/
@@ -199,10 +170,4 @@ public abstract class ConcurrencyModule {
public static Executor provideUiBackgroundExecutor() {
return Executors.newSingleThreadExecutor();
}
/**
* Binds {@link ThreadFactoryImpl} to {@link ThreadFactory}.
*/
@Binds
public abstract ThreadFactory bindExecutorFactory(ThreadFactoryImpl impl);
}