diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml index 340cb3ad73584..84b472b8f006b 100644 --- a/packages/SystemUI/res/values/config.xml +++ b/packages/SystemUI/res/values/config.xml @@ -276,7 +276,6 @@ - com.android.systemui.Dependency$DependencyCreator com.android.systemui.util.NotificationChannels com.android.systemui.statusbar.CommandQueue$CommandQueueStart com.android.systemui.keyguard.KeyguardViewMediator @@ -307,7 +306,6 @@ - com.android.systemui.Dependency$DependencyCreator com.android.systemui.util.NotificationChannels diff --git a/packages/SystemUI/src/com/android/systemui/Dependency.java b/packages/SystemUI/src/com/android/systemui/Dependency.java index 6c36bc98996b7..15bea2484d7f3 100644 --- a/packages/SystemUI/src/com/android/systemui/Dependency.java +++ b/packages/SystemUI/src/com/android/systemui/Dependency.java @@ -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; - } - } } diff --git a/packages/SystemUI/src/com/android/systemui/ForegroundServicesDialog.java b/packages/SystemUI/src/com/android/systemui/ForegroundServicesDialog.java index cb9523fcaed15..6fec92c84fecd 100644 --- a/packages/SystemUI/src/com/android/systemui/ForegroundServicesDialog.java +++ b/packages/SystemUI/src/com/android/systemui/ForegroundServicesDialog.java @@ -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); diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java b/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java index f8449add6dce8..48127a75b86e8 100644 --- a/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java +++ b/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java @@ -62,19 +62,28 @@ public class SystemUIApplication extends Application implements SysUiServiceProv private final Map, 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. *

This method must only be called from the main thread.

*/ @@ -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) { diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java b/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java index 2cdc81fcf6951..c7f4c389fb3f6 100644 --- a/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java +++ b/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java @@ -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, diff --git a/packages/SystemUI/src/com/android/systemui/SystemUISecondaryUserService.java b/packages/SystemUI/src/com/android/systemui/SystemUISecondaryUserService.java index c8a2e1758ad15..2d2d91db4fe18 100644 --- a/packages/SystemUI/src/com/android/systemui/SystemUISecondaryUserService.java +++ b/packages/SystemUI/src/com/android/systemui/SystemUISecondaryUserService.java @@ -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); } } diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIService.java b/packages/SystemUI/src/com/android/systemui/SystemUIService.java index dc1218d334984..1c5e80005d846 100644 --- a/packages/SystemUI/src/com/android/systemui/SystemUIService.java +++ b/packages/SystemUI/src/com/android/systemui/SystemUIService.java @@ -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)) { diff --git a/packages/SystemUI/src/com/android/systemui/tuner/TunerActivity.java b/packages/SystemUI/src/com/android/systemui/tuner/TunerActivity.java index 1d4f9b33b0bc0..97507900e2698 100644 --- a/packages/SystemUI/src/com/android/systemui/tuner/TunerActivity.java +++ b/packages/SystemUI/src/com/android/systemui/tuner/TunerActivity.java @@ -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(); diff --git a/packages/SystemUI/tests/src/com/android/systemui/DependencyTest.java b/packages/SystemUI/tests/src/com/android/systemui/DependencyTest.java index b1ca169eac0c6..b9d09ce91c1a1 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/DependencyTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/DependencyTest.java @@ -74,6 +74,6 @@ public class DependencyTest extends SysuiTestCase { @Test public void testInitDependency() { Dependency.clearDependencies(); - Dependency.initDependencies(mContext); + Dependency.initDependencies(SystemUIFactory.getInstance().getRootComponent()); } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/TestableDependency.java b/packages/SystemUI/tests/src/com/android/systemui/TestableDependency.java index 18bf75e3cfb14..0c53b03de4d2a 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/TestableDependency.java +++ b/packages/SystemUI/tests/src/com/android/systemui/TestableDependency.java @@ -25,10 +25,6 @@ public class TestableDependency extends Dependency { private final ArraySet mInstantiatedObjects = new ArraySet<>(); public TestableDependency(Context context) { - if (context instanceof SysuiTestableContext) { - mComponents = ((SysuiTestableContext) context).getComponents(); - } - mContext = context; SystemUIFactory.createFromConfig(context); SystemUIFactory.getInstance().getRootComponent() .createDependency() diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarRemoteInputCallbackTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarRemoteInputCallbackTest.java index a97832f94924e..4b6ca56fc8e3f 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarRemoteInputCallbackTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarRemoteInputCallbackTest.java @@ -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)));