From 59a7b980e5474bf74ace2bb8696766be98b65f90 Mon Sep 17 00:00:00 2001 From: Mady Mellor Date: Mon, 11 May 2020 15:19:59 -0700 Subject: [PATCH] Use mock window manager for BubbleController in tests Bubbles are no longer part of the status bar window and live in their own window now. This resulted in a new window being created each time setUp step happened in BubbleControllerTests without ever being removed, resulting in OOM when running tests :( This CL fixes it by using a mock window manager in tests. Test: atest Fixes: 155805511 Change-Id: Id1940aeb7ee94801fa5669a30a98e2ea9c92126b --- .../systemui/bubbles/BubbleController.java | 30 ++----------------- .../systemui/bubbles/dagger/BubbleModule.java | 7 +++-- .../bubbles/BubbleControllerTest.java | 3 +- .../NewNotifPipelineBubbleControllerTest.java | 3 +- .../bubbles/TestableBubbleController.java | 7 +++-- 5 files changed, 17 insertions(+), 33 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java index ad8d57bbf23f2..6691331452e6d 100644 --- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java +++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java @@ -280,31 +280,6 @@ public class BubbleController implements ConfigurationController.ConfigurationLi } } - public BubbleController(Context context, - NotificationShadeWindowController notificationShadeWindowController, - StatusBarStateController statusBarStateController, - ShadeController shadeController, - BubbleData data, - ConfigurationController configurationController, - NotificationInterruptStateProvider interruptionStateProvider, - ZenModeController zenModeController, - NotificationLockscreenUserManager notifUserManager, - NotificationGroupManager groupManager, - NotificationEntryManager entryManager, - NotifPipeline notifPipeline, - FeatureFlags featureFlags, - DumpManager dumpManager, - FloatingContentCoordinator floatingContentCoordinator, - BubbleDataRepository dataRepository, - SysUiState sysUiState, - INotificationManager notificationManager) { - this(context, notificationShadeWindowController, statusBarStateController, shadeController, - data, null /* synchronizer */, configurationController, interruptionStateProvider, - zenModeController, notifUserManager, groupManager, entryManager, - notifPipeline, featureFlags, dumpManager, floatingContentCoordinator, - dataRepository, sysUiState, notificationManager); - } - /** * Injected constructor. See {@link BubbleModule}. */ @@ -326,7 +301,8 @@ public class BubbleController implements ConfigurationController.ConfigurationLi FloatingContentCoordinator floatingContentCoordinator, BubbleDataRepository dataRepository, SysUiState sysUiState, - INotificationManager notificationManager) { + INotificationManager notificationManager, + WindowManager windowManager) { dumpManager.registerDumpable(TAG, this); mContext = context; mShadeController = shadeController; @@ -395,7 +371,7 @@ public class BubbleController implements ConfigurationController.ConfigurationLi } mSurfaceSynchronizer = synchronizer; - mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); + mWindowManager = windowManager; mBarService = IStatusBarService.Stub.asInterface( ServiceManager.getService(Context.STATUS_BAR_SERVICE)); diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/dagger/BubbleModule.java b/packages/SystemUI/src/com/android/systemui/bubbles/dagger/BubbleModule.java index e3b630b049f57..d1d07f6ba4ce8 100644 --- a/packages/SystemUI/src/com/android/systemui/bubbles/dagger/BubbleModule.java +++ b/packages/SystemUI/src/com/android/systemui/bubbles/dagger/BubbleModule.java @@ -18,6 +18,7 @@ package com.android.systemui.bubbles.dagger; import android.app.INotificationManager; import android.content.Context; +import android.view.WindowManager; import com.android.systemui.bubbles.BubbleController; import com.android.systemui.bubbles.BubbleData; @@ -68,7 +69,8 @@ public interface BubbleModule { FloatingContentCoordinator floatingContentCoordinator, BubbleDataRepository bubbleDataRepository, SysUiState sysUiState, - INotificationManager notifManager) { + INotificationManager notifManager, + WindowManager windowManager) { return new BubbleController( context, notificationShadeWindowController, @@ -88,6 +90,7 @@ public interface BubbleModule { floatingContentCoordinator, bubbleDataRepository, sysUiState, - notifManager); + notifManager, + windowManager); } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/bubbles/BubbleControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/bubbles/BubbleControllerTest.java index e2f303e87d871..96e868d2a6180 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/bubbles/BubbleControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/bubbles/BubbleControllerTest.java @@ -279,7 +279,8 @@ public class BubbleControllerTest extends SysuiTestCase { mFloatingContentCoordinator, mDataRepository, mSysUiState, - mock(INotificationManager.class)); + mock(INotificationManager.class), + mWindowManager); mBubbleController.setExpandListener(mBubbleExpandListener); // Get a reference to the BubbleController's entry listener diff --git a/packages/SystemUI/tests/src/com/android/systemui/bubbles/NewNotifPipelineBubbleControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/bubbles/NewNotifPipelineBubbleControllerTest.java index 8a83b84c6b5ee..73b8760198630 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/bubbles/NewNotifPipelineBubbleControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/bubbles/NewNotifPipelineBubbleControllerTest.java @@ -254,7 +254,8 @@ public class NewNotifPipelineBubbleControllerTest extends SysuiTestCase { mFloatingContentCoordinator, mDataRepository, mSysUiState, - mock(INotificationManager.class)); + mock(INotificationManager.class), + mWindowManager); mBubbleController.addNotifCallback(mNotifCallback); mBubbleController.setExpandListener(mBubbleExpandListener); diff --git a/packages/SystemUI/tests/src/com/android/systemui/bubbles/TestableBubbleController.java b/packages/SystemUI/tests/src/com/android/systemui/bubbles/TestableBubbleController.java index 1542b8675ede2..bdb79449ea2a0 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/bubbles/TestableBubbleController.java +++ b/packages/SystemUI/tests/src/com/android/systemui/bubbles/TestableBubbleController.java @@ -18,6 +18,7 @@ package com.android.systemui.bubbles; import android.app.INotificationManager; import android.content.Context; +import android.view.WindowManager; import com.android.systemui.dump.DumpManager; import com.android.systemui.model.SysUiState; @@ -57,13 +58,15 @@ public class TestableBubbleController extends BubbleController { FloatingContentCoordinator floatingContentCoordinator, BubbleDataRepository dataRepository, SysUiState sysUiState, - INotificationManager notificationManager) { + INotificationManager notificationManager, + WindowManager windowManager) { super(context, notificationShadeWindowController, statusBarStateController, shadeController, data, Runnable::run, configurationController, interruptionStateProvider, zenModeController, lockscreenUserManager, groupManager, entryManager, notifPipeline, featureFlags, dumpManager, floatingContentCoordinator, - dataRepository, sysUiState, notificationManager); + dataRepository, sysUiState, notificationManager, + windowManager); setInflateSynchronously(true); } }