Merge "Initialize Dependency with the Application when Dagger starts." into qt-qpr1-sysui-dev
This commit is contained in:
@@ -273,7 +273,6 @@
|
||||
|
||||
<!-- SystemUI Services: The classes of the stuff to start. -->
|
||||
<string-array name="config_systemUIServiceComponents" translatable="false">
|
||||
<item>com.android.systemui.Dependency$DependencyCreator</item>
|
||||
<item>com.android.systemui.util.NotificationChannels</item>
|
||||
<item>com.android.systemui.statusbar.CommandQueue$CommandQueueStart</item>
|
||||
<item>com.android.systemui.keyguard.KeyguardViewMediator</item>
|
||||
@@ -304,7 +303,6 @@
|
||||
|
||||
<!-- SystemUI Services (per user): The classes of the stuff to start for each user. This is a subset of the config_systemUIServiceComponents -->
|
||||
<string-array name="config_systemUIServiceComponentsPerUser" translatable="false">
|
||||
<item>com.android.systemui.Dependency$DependencyCreator</item>
|
||||
<item>com.android.systemui.util.NotificationChannels</item>
|
||||
</string-array>
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ package com.android.systemui;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.app.INotificationManager;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.hardware.SensorPrivacyManager;
|
||||
import android.hardware.display.NightDisplayListener;
|
||||
@@ -114,7 +113,6 @@ import com.android.systemui.util.leak.LeakReporter;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -138,9 +136,7 @@ import dagger.Subcomponent;
|
||||
* they have no clients they should not have any registered resources like bound
|
||||
* services, registered receivers, etc.
|
||||
*/
|
||||
public class Dependency extends SystemUI {
|
||||
private static final String TAG = "Dependency";
|
||||
|
||||
public class Dependency {
|
||||
/**
|
||||
* Key for getting a background Looper for background work.
|
||||
*/
|
||||
@@ -305,8 +301,20 @@ public class Dependency extends SystemUI {
|
||||
public Dependency() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
|
||||
/**
|
||||
* Initialize Depenency.
|
||||
*/
|
||||
public static void initDependencies(SystemUIRootComponent rootComponent) {
|
||||
if (sDependency != null) {
|
||||
return;
|
||||
}
|
||||
sDependency = new Dependency();
|
||||
rootComponent.createDependency().createSystemUI(sDependency);
|
||||
sDependency.start();
|
||||
}
|
||||
|
||||
protected void start() {
|
||||
// TODO: Think about ways to push these creation rules out of Dependency to cut down
|
||||
// on imports.
|
||||
mProviders.put(TIME_TICK_HANDLER, mTimeTickHandler::get);
|
||||
@@ -486,10 +494,14 @@ public class Dependency extends SystemUI {
|
||||
sDependency = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
|
||||
super.dump(fd, pw, args);
|
||||
static void staticDump(FileDescriptor fd, PrintWriter pw, String[] args) {
|
||||
sDependency.dump(fd, pw, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@see SystemUI.dump}
|
||||
*/
|
||||
public synchronized void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
|
||||
// Make sure that the DumpController gets added to mDependencies, as they are only added
|
||||
// with Dependency#get.
|
||||
getDependency(DumpController.class);
|
||||
@@ -509,9 +521,11 @@ public class Dependency extends SystemUI {
|
||||
.forEach(o -> ((Dumpable) o).dump(fd, pw, args));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected static void staticOnConfigurationChanged(Configuration newConfig) {
|
||||
sDependency.onConfigurationChanged(newConfig);
|
||||
}
|
||||
|
||||
protected synchronized void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
mDependencies.values().stream().filter(obj -> obj instanceof ConfigurationChangedReceiver)
|
||||
.forEach(o -> ((ConfigurationChangedReceiver) o).onConfigurationChanged(newConfig));
|
||||
}
|
||||
@@ -564,20 +578,6 @@ public class Dependency extends SystemUI {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used in separate processes (like tuner settings) to init the dependencies.
|
||||
*/
|
||||
public static void initDependencies(Context context) {
|
||||
if (sDependency != null) return;
|
||||
Dependency d = new Dependency();
|
||||
SystemUIFactory.getInstance().getRootComponent()
|
||||
.createDependency()
|
||||
.createSystemUI(d);
|
||||
d.mContext = context;
|
||||
d.mComponents = new HashMap<>();
|
||||
d.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Used in separate process teardown to ensure the context isn't leaked.
|
||||
*
|
||||
@@ -629,15 +629,4 @@ public class Dependency extends SystemUI {
|
||||
public interface DependencyInjector {
|
||||
void createSystemUI(Dependency dependency);
|
||||
}
|
||||
|
||||
public static class DependencyCreator implements Injector {
|
||||
@Override
|
||||
public SystemUI apply(Context context) {
|
||||
Dependency dependency = new Dependency();
|
||||
SystemUIFactory.getInstance().getRootComponent()
|
||||
.createDependency()
|
||||
.createSystemUI(dependency);
|
||||
return dependency;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ public final class ForegroundServicesDialog extends AlertActivity implements
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Dependency.initDependencies(getApplicationContext());
|
||||
Dependency.initDependencies(SystemUIFactory.getInstance().getRootComponent());
|
||||
|
||||
mMetricsLogger = Dependency.get(MetricsLogger.class);
|
||||
|
||||
|
||||
@@ -62,19 +62,28 @@ public class SystemUIApplication extends Application implements SysUiServiceProv
|
||||
private final Map<Class<?>, Object> mComponents = new HashMap<>();
|
||||
private ContextAvailableCallback mContextAvailableCallback;
|
||||
|
||||
public SystemUIApplication() {
|
||||
super();
|
||||
Log.v(TAG, "SystemUIApplication constructed.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
Log.v(TAG, "SystemUIApplication created.");
|
||||
// This line is used to setup Dagger's dependency injection and should be kept at the
|
||||
// top of this method.
|
||||
TimingsTraceLog log = new TimingsTraceLog("SystemUIBootTiming",
|
||||
Trace.TRACE_TAG_APP);
|
||||
log.traceBegin("DependencyInjection");
|
||||
mContextAvailableCallback.onContextAvailable(this);
|
||||
log.traceEnd();
|
||||
|
||||
// Set the application theme that is inherited by all services. Note that setting the
|
||||
// application theme in the manifest does only work for activities. Keep this in sync with
|
||||
// the theme set there.
|
||||
setTheme(R.style.Theme_SystemUI);
|
||||
|
||||
|
||||
if (Process.myUserHandle().equals(UserHandle.SYSTEM)) {
|
||||
IntentFilter bootCompletedFilter = new IntentFilter(Intent.ACTION_BOOT_COMPLETED);
|
||||
bootCompletedFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
||||
@@ -138,7 +147,7 @@ public class SystemUIApplication extends Application implements SysUiServiceProv
|
||||
|
||||
/**
|
||||
* Ensures that all the Secondary user SystemUI services are running. If they are already
|
||||
* running, this is a no-op. This is needed to conditinally start all the services, as we only
|
||||
* running, this is a no-op. This is needed to conditionally start all the services, as we only
|
||||
* need to have it in the main process.
|
||||
* <p>This method must only be called from the main thread.</p>
|
||||
*/
|
||||
@@ -159,7 +168,9 @@ public class SystemUIApplication extends Application implements SysUiServiceProv
|
||||
// see ActivityManagerService.finishBooting()
|
||||
if ("1".equals(SystemProperties.get("sys.boot_completed"))) {
|
||||
mBootCompleted = true;
|
||||
if (DEBUG) Log.v(TAG, "BOOT_COMPLETED was already sent");
|
||||
if (DEBUG) {
|
||||
Log.v(TAG, "BOOT_COMPLETED was already sent");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,6 +284,7 @@ public class SystemUIApplication extends Application implements SysUiServiceProv
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
if (mServicesStarted) {
|
||||
Dependency.staticOnConfigurationChanged(newConfig);
|
||||
int len = mServices.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (mServices[i] != null) {
|
||||
|
||||
@@ -115,6 +115,10 @@ public class SystemUIFactory {
|
||||
.dependencyProvider(new com.android.systemui.DependencyProvider())
|
||||
.contextHolder(new ContextHolder(context))
|
||||
.build();
|
||||
|
||||
// Every other part of our codebase currently relies on Dependency, so we
|
||||
// really need to ensure the Dependency gets initialized early on.
|
||||
Dependency.initDependencies(mRootComponent);
|
||||
}
|
||||
|
||||
public SystemUIRootComponent getRootComponent() {
|
||||
@@ -127,7 +131,7 @@ public class SystemUIFactory {
|
||||
}
|
||||
|
||||
public KeyguardBouncer createKeyguardBouncer(Context context, ViewMediatorCallback callback,
|
||||
LockPatternUtils lockPatternUtils, ViewGroup container,
|
||||
LockPatternUtils lockPatternUtils, ViewGroup container,
|
||||
DismissCallbackRegistry dismissCallbackRegistry,
|
||||
KeyguardBouncer.BouncerExpansionCallback expansionCallback) {
|
||||
return new KeyguardBouncer(context, callback, lockPatternUtils, container,
|
||||
|
||||
@@ -38,25 +38,8 @@ public class SystemUISecondaryUserService extends Service {
|
||||
|
||||
@Override
|
||||
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
|
||||
SystemUI[] services = ((SystemUIApplication) getApplication()).getServices();
|
||||
if (args == null || args.length == 0) {
|
||||
for (SystemUI ui: services) {
|
||||
if (ui != null) {
|
||||
pw.println("dumping service: " + ui.getClass().getName());
|
||||
ui.dump(fd, pw, args);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
String svc = args[0];
|
||||
for (SystemUI ui: services) {
|
||||
if (ui != null) {
|
||||
String name = ui.getClass().getName();
|
||||
if (name.endsWith(svc)) {
|
||||
ui.dump(fd, pw, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
SystemUIService.dumpServices(
|
||||
((SystemUIApplication) getApplication()).getServices(), fd, pw, args);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,8 +66,14 @@ public class SystemUIService extends Service {
|
||||
|
||||
@Override
|
||||
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
|
||||
SystemUI[] services = ((SystemUIApplication) getApplication()).getServices();
|
||||
dumpServices(((SystemUIApplication) getApplication()).getServices(), fd, pw, args);
|
||||
}
|
||||
|
||||
static void dumpServices(
|
||||
SystemUI[] services, FileDescriptor fd, PrintWriter pw, String[] args) {
|
||||
if (args == null || args.length == 0) {
|
||||
pw.println("dumping service: " + Dependency.class.getName());
|
||||
Dependency.staticDump(fd, pw, args);
|
||||
for (SystemUI ui: services) {
|
||||
pw.println("dumping service: " + ui.getClass().getName());
|
||||
ui.dump(fd, pw, args);
|
||||
@@ -78,6 +84,9 @@ public class SystemUIService extends Service {
|
||||
}
|
||||
} else {
|
||||
String svc = args[0].toLowerCase();
|
||||
if (Dependency.class.getName().endsWith(svc)) {
|
||||
Dependency.staticDump(fd, pw, args);
|
||||
}
|
||||
for (SystemUI ui: services) {
|
||||
String name = ui.getClass().getName().toLowerCase();
|
||||
if (name.endsWith(svc)) {
|
||||
|
||||
@@ -31,6 +31,7 @@ import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.systemui.Dependency;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.SystemUIFactory;
|
||||
import com.android.systemui.fragments.FragmentService;
|
||||
|
||||
public class TunerActivity extends Activity implements
|
||||
@@ -50,7 +51,7 @@ public class TunerActivity extends Activity implements
|
||||
setActionBar(toolbar);
|
||||
}
|
||||
|
||||
Dependency.initDependencies(this);
|
||||
Dependency.initDependencies(SystemUIFactory.getInstance().getRootComponent());
|
||||
|
||||
if (getFragmentManager().findFragmentByTag(TAG_TUNER) == null) {
|
||||
final String action = getIntent().getAction();
|
||||
|
||||
@@ -74,6 +74,6 @@ public class DependencyTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void testInitDependency() {
|
||||
Dependency.clearDependencies();
|
||||
Dependency.initDependencies(mContext);
|
||||
Dependency.initDependencies(SystemUIFactory.getInstance().getRootComponent());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,10 +25,6 @@ public class TestableDependency extends Dependency {
|
||||
private final ArraySet<Object> mInstantiatedObjects = new ArraySet<>();
|
||||
|
||||
public TestableDependency(Context context) {
|
||||
if (context instanceof SysuiTestableContext) {
|
||||
mComponents = ((SysuiTestableContext) context).getComponents();
|
||||
}
|
||||
mContext = context;
|
||||
SystemUIFactory.createFromConfig(context);
|
||||
SystemUIFactory.getInstance().getRootComponent()
|
||||
.createDependency()
|
||||
|
||||
@@ -68,7 +68,7 @@ public class StatusBarRemoteInputCallbackTest extends SysuiTestCase {
|
||||
mDependency.injectTestDependency(ShadeController.class, mShadeController);
|
||||
mDependency.injectTestDependency(NotificationLockscreenUserManager.class,
|
||||
mNotificationLockscreenUserManager);
|
||||
mDependency.putComponent(CommandQueue.class, mock(CommandQueue.class));
|
||||
mContext.putComponent(CommandQueue.class, mock(CommandQueue.class));
|
||||
|
||||
mRemoteInputCallback = spy(new StatusBarRemoteInputCallback(mContext,
|
||||
mock(NotificationGroupManager.class)));
|
||||
|
||||
Reference in New Issue
Block a user