From 2e484926ff783fa982e4d84d9f0462b6f6e7536d Mon Sep 17 00:00:00 2001 From: Dave Mankoff Date: Thu, 31 Oct 2019 12:25:08 -0400 Subject: [PATCH] Register OverlayPlugins in StatusBar directly. This removes the last call to getComponent(StatusBar.class). Prior to this change, we would register a listener for OverlayPlugins inside the SystemUIApp. Because they are directly related to the StatusBar, it is safe and appropriate to have the StatusBar register with the PluginManager itself. Bug: 143224715 Test: atest SystemUITests Change-Id: I5ecdf6a4dae05ba674bcbcd940b9f2655d2b1cbb --- .../android/systemui/CarSystemUIBinder.java | 3 + .../systemui/statusbar/car/CarStatusBar.java | 6 +- .../android/systemui/SystemUIApplication.java | 68 ------------------- .../systemui/dagger/SystemUIBinder.java | 7 +- .../systemui/statusbar/phone/StatusBar.java | 53 ++++++++++++++- .../statusbar/phone/StatusBarTest.java | 6 +- 6 files changed, 69 insertions(+), 74 deletions(-) diff --git a/packages/CarSystemUI/src/com/android/systemui/CarSystemUIBinder.java b/packages/CarSystemUI/src/com/android/systemui/CarSystemUIBinder.java index 57e7fb374cf50..b2859f6e719e1 100644 --- a/packages/CarSystemUI/src/com/android/systemui/CarSystemUIBinder.java +++ b/packages/CarSystemUI/src/com/android/systemui/CarSystemUIBinder.java @@ -42,6 +42,7 @@ import com.android.systemui.plugins.FalsingManager; import com.android.systemui.power.PowerUI; import com.android.systemui.recents.Recents; import com.android.systemui.recents.RecentsModule; +import com.android.systemui.shared.plugins.PluginManager; import com.android.systemui.statusbar.CommandQueue; import com.android.systemui.statusbar.FeatureFlags; import com.android.systemui.statusbar.NavigationBarController; @@ -275,6 +276,7 @@ public abstract class CarSystemUIBinder { PowerManager powerManager, DozeScrimController dozeScrimController, CommandQueue commandQueue, + PluginManager pluginManager, CarNavigationBarController carNavigationBarController) { return new CarStatusBar( context, @@ -341,6 +343,7 @@ public abstract class CarSystemUIBinder { powerManager, dozeScrimController, commandQueue, + pluginManager, carNavigationBarController); } } diff --git a/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java b/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java index a463d37802657..7ab2036251db3 100644 --- a/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java +++ b/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java @@ -80,6 +80,7 @@ import com.android.systemui.navigationbar.car.CarNavigationBarView; import com.android.systemui.plugins.FalsingManager; import com.android.systemui.plugins.qs.QS; import com.android.systemui.qs.car.CarQSFragment; +import com.android.systemui.shared.plugins.PluginManager; import com.android.systemui.statusbar.CommandQueue; import com.android.systemui.statusbar.FeatureFlags; import com.android.systemui.statusbar.FlingAnimationUtils; @@ -299,6 +300,8 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt PowerManager powerManager, DozeScrimController dozeScrimController, CommandQueue commandQueue, + PluginManager pluginManager, + /* Car Settings injected components. */ CarNavigationBarController carNavigationBarController) { super( @@ -366,7 +369,8 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt dozeServiceHost, powerManager, dozeScrimController, - commandQueue); + commandQueue, + pluginManager); mScrimController = scrimController; mCarNavigationBarController = carNavigationBarController; } diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java b/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java index 022bf06838a61..aab4041aba5f3 100644 --- a/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java +++ b/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java @@ -24,23 +24,14 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.pm.ApplicationInfo; import android.content.res.Configuration; -import android.os.Handler; -import android.os.Looper; import android.os.Process; import android.os.SystemProperties; import android.os.Trace; import android.os.UserHandle; -import android.util.ArraySet; import android.util.Log; import android.util.TimingsTraceLog; import com.android.systemui.dagger.ContextComponentHelper; -import com.android.systemui.plugins.OverlayPlugin; -import com.android.systemui.plugins.PluginListener; -import com.android.systemui.shared.plugins.PluginManager; -import com.android.systemui.statusbar.phone.DozeParameters; -import com.android.systemui.statusbar.phone.StatusBar; -import com.android.systemui.statusbar.phone.StatusBarWindowController; import com.android.systemui.util.NotificationChannels; import java.lang.reflect.Constructor; @@ -224,65 +215,6 @@ public class SystemUIApplication extends Application implements SysUiServiceProv } Dependency.get(InitController.class).executePostInitTasks(); log.traceEnd(); - final Handler mainHandler = new Handler(Looper.getMainLooper()); - Dependency.get(PluginManager.class).addPluginListener( - new PluginListener() { - private ArraySet mOverlays = new ArraySet<>(); - - @Override - public void onPluginConnected(OverlayPlugin plugin, Context pluginContext) { - mainHandler.post(new Runnable() { - @Override - public void run() { - StatusBar statusBar = getComponent(StatusBar.class); - if (statusBar != null) { - plugin.setup(statusBar.getStatusBarWindow(), - statusBar.getNavigationBarView(), new Callback(plugin), - Dependency.get(DozeParameters.class)); - } - } - }); - } - - @Override - public void onPluginDisconnected(OverlayPlugin plugin) { - mainHandler.post(new Runnable() { - @Override - public void run() { - mOverlays.remove(plugin); - Dependency.get(StatusBarWindowController.class).setForcePluginOpen( - mOverlays.size() != 0); - } - }); - } - - class Callback implements OverlayPlugin.Callback { - private final OverlayPlugin mPlugin; - - Callback(OverlayPlugin plugin) { - mPlugin = plugin; - } - - @Override - public void onHoldStatusBarOpenChange() { - if (mPlugin.holdStatusBarOpen()) { - mOverlays.add(mPlugin); - } else { - mOverlays.remove(mPlugin); - } - mainHandler.post(new Runnable() { - @Override - public void run() { - Dependency.get(StatusBarWindowController.class) - .setStateListener(b -> mOverlays.forEach( - o -> o.setCollapseDesired(b))); - Dependency.get(StatusBarWindowController.class) - .setForcePluginOpen(mOverlays.size() != 0); - } - }); - } - } - }, OverlayPlugin.class, true /* Allow multiple plugins */); mServicesStarted = true; } diff --git a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIBinder.java b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIBinder.java index ead6de2b7f0ee..88ec76c7706b8 100644 --- a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIBinder.java +++ b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIBinder.java @@ -48,6 +48,7 @@ import com.android.systemui.plugins.FalsingManager; import com.android.systemui.power.PowerUI; import com.android.systemui.recents.Recents; import com.android.systemui.recents.RecentsModule; +import com.android.systemui.shared.plugins.PluginManager; import com.android.systemui.statusbar.CommandQueue; import com.android.systemui.statusbar.FeatureFlags; import com.android.systemui.statusbar.NavigationBarController; @@ -271,7 +272,8 @@ public abstract class SystemUIBinder { DozeServiceHost dozeServiceHost, PowerManager powerManager, DozeScrimController dozeScrimController, - CommandQueue commandQueue) { + CommandQueue commandQueue, + PluginManager pluginManager) { return new StatusBar( context, featureFlags, @@ -337,7 +339,8 @@ public abstract class SystemUIBinder { dozeServiceHost, powerManager, dozeScrimController, - commandQueue); + commandQueue, + pluginManager); } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java index 4f9f1314918cd..2125d126752a5 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -100,6 +100,7 @@ import android.provider.Settings; import android.service.dreams.DreamService; import android.service.dreams.IDreamManager; import android.service.notification.StatusBarNotification; +import android.util.ArraySet; import android.util.DisplayMetrics; import android.util.EventLog; import android.util.Log; @@ -168,7 +169,9 @@ import com.android.systemui.keyguard.WakefulnessLifecycle; import com.android.systemui.plugins.ActivityStarter; import com.android.systemui.plugins.DarkIconDispatcher; import com.android.systemui.plugins.FalsingManager; +import com.android.systemui.plugins.OverlayPlugin; import com.android.systemui.plugins.PluginDependencyProvider; +import com.android.systemui.plugins.PluginListener; import com.android.systemui.plugins.qs.QS; import com.android.systemui.plugins.statusbar.NotificationSwipeActionHelper.SnoozeOption; import com.android.systemui.plugins.statusbar.StatusBarStateController; @@ -176,6 +179,7 @@ import com.android.systemui.qs.QSFragment; import com.android.systemui.qs.QSPanel; import com.android.systemui.recents.Recents; import com.android.systemui.recents.ScreenPinningRequest; +import com.android.systemui.shared.plugins.PluginManager; import com.android.systemui.shared.system.WindowManagerWrapper; import com.android.systemui.stackdivider.Divider; import com.android.systemui.stackdivider.WindowManagerProxy; @@ -396,6 +400,7 @@ public class StatusBar extends SystemUI implements DemoMode, private final NotifLog mNotifLog; private final DozeParameters mDozeParameters; private final Lazy mBiometricUnlockControllerLazy; + private final PluginManager mPluginManager; // expanded notifications protected NotificationPanelView mNotificationPanel; // the sliding/resizing panel within the notification window @@ -697,7 +702,8 @@ public class StatusBar extends SystemUI implements DemoMode, DozeServiceHost dozeServiceHost, PowerManager powerManager, DozeScrimController dozeScrimController, - CommandQueue commandQueue) { + CommandQueue commandQueue, + PluginManager pluginManager) { super(context); mFeatureFlags = featureFlags; mLightBarController = lightBarController; @@ -763,6 +769,7 @@ public class StatusBar extends SystemUI implements DemoMode, mDozeScrimController = dozeScrimController; mBiometricUnlockControllerLazy = biometricUnlockControllerLazy; mCommandQueue = commandQueue; + mPluginManager = pluginManager; mBubbleExpandListener = (isExpanding, key) -> { @@ -929,6 +936,50 @@ public class StatusBar extends SystemUI implements DemoMode, int disabledFlags2 = result.mDisabledFlags2; Dependency.get(InitController.class).addPostInitTask( () -> setUpDisableFlags(disabledFlags1, disabledFlags2)); + + mPluginManager.addPluginListener( + new PluginListener() { + private ArraySet mOverlays = new ArraySet<>(); + + @Override + public void onPluginConnected(OverlayPlugin plugin, Context pluginContext) { + mMainThreadHandler.post( + () -> plugin.setup(getStatusBarWindow(), getNavigationBarView(), + new Callback(plugin), mDozeParameters)); + } + + @Override + public void onPluginDisconnected(OverlayPlugin plugin) { + mMainThreadHandler.post(() -> { + mOverlays.remove(plugin); + mStatusBarWindowController.setForcePluginOpen(mOverlays.size() != 0); + }); + } + + class Callback implements OverlayPlugin.Callback { + private final OverlayPlugin mPlugin; + + Callback(OverlayPlugin plugin) { + mPlugin = plugin; + } + + @Override + public void onHoldStatusBarOpenChange() { + if (mPlugin.holdStatusBarOpen()) { + mOverlays.add(mPlugin); + } else { + mOverlays.remove(mPlugin); + } + mMainThreadHandler.post(() -> { + mStatusBarWindowController + .setStateListener(b -> mOverlays.forEach( + o -> o.setCollapseDesired(b))); + mStatusBarWindowController + .setForcePluginOpen(mOverlays.size() != 0); + }); + } + } + }, OverlayPlugin.class, true /* Allow multiple plugins */); } // ================================================================================ diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java index bace30b1e00b6..5d152054fdd3e 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java @@ -91,6 +91,7 @@ import com.android.systemui.keyguard.ScreenLifecycle; import com.android.systemui.keyguard.WakefulnessLifecycle; import com.android.systemui.plugins.ActivityStarter.OnDismissAction; import com.android.systemui.plugins.statusbar.StatusBarStateController; +import com.android.systemui.shared.plugins.PluginManager; import com.android.systemui.statusbar.CommandQueue; import com.android.systemui.statusbar.FeatureFlags; import com.android.systemui.statusbar.KeyguardIndicationController; @@ -230,6 +231,7 @@ public class StatusBarTest extends SysuiTestCase { @Mock private ViewMediatorCallback mKeyguardVieMediatorCallback; @Mock private KeyguardLiftController mKeyguardLiftController; @Mock private CommandQueue mCommandQueue; + @Mock private PluginManager mPluginManager; @Before public void setup() throws Exception { @@ -366,7 +368,8 @@ public class StatusBarTest extends SysuiTestCase { mDozeServiceHost, mPowerManager, mDozeScrimController, - mCommandQueue); + mCommandQueue, + mPluginManager); when(mStatusBarWindowView.findViewById(R.id.lock_icon_container)).thenReturn( mLockIconContainer); @@ -392,7 +395,6 @@ public class StatusBarTest extends SysuiTestCase { mStatusBar.mStackScroller = mStackScroller; mStatusBar.mStatusBarWindowViewController = mStatusBarWindowViewController; mStatusBar.startKeyguard(); - mStatusBar.putComponent(StatusBar.class, mStatusBar); Dependency.get(InitController.class).executePostInitTasks(); entryManager.setUpForTest(mock(NotificationPresenter.class), mStackScroller, mHeadsUpManager);