diff options
5 files changed, 18 insertions, 68 deletions
diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index 9c21e4c0121e..ec4bdf91bcca 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -202,7 +202,6 @@ import android.os.Build; import android.os.Debug; import android.os.IBinder; import android.os.PowerManager; -import android.os.PowerManager.WakeReason; import android.os.RemoteCallbackList; import android.os.RemoteException; import android.os.SystemClock; @@ -702,11 +701,6 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP */ private final Region mTapExcludeRegion = new Region(); - /** - * Used for testing because the real PowerManager is final. - */ - private PowerManagerWrapper mPowerManagerWrapper; - private static final StringBuilder sTmpSB = new StringBuilder(); /** @@ -1061,34 +1055,9 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP return mOnBackInvokedCallbackInfo; } - interface PowerManagerWrapper { - void wakeUp(long time, @WakeReason int reason, String details); - - boolean isInteractive(); - - } - WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token, WindowState parentWindow, int appOp, WindowManager.LayoutParams a, int viewVisibility, int ownerId, int showUserId, boolean ownerCanAddInternalSystemWindow) { - this(service, s, c, token, parentWindow, appOp, a, viewVisibility, ownerId, showUserId, - ownerCanAddInternalSystemWindow, new PowerManagerWrapper() { - @Override - public void wakeUp(long time, @WakeReason int reason, String details) { - service.mPowerManager.wakeUp(time, reason, details); - } - - @Override - public boolean isInteractive() { - return service.mPowerManager.isInteractive(); - } - }); - } - - WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token, - WindowState parentWindow, int appOp, WindowManager.LayoutParams a, int viewVisibility, - int ownerId, int showUserId, boolean ownerCanAddInternalSystemWindow, - PowerManagerWrapper powerManagerWrapper) { super(service); mTmpTransaction = service.mTransactionFactory.get(); mSession = s; @@ -1106,7 +1075,6 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP mViewVisibility = viewVisibility; mPolicy = mWmService.mPolicy; mContext = mWmService.mContext; - mPowerManagerWrapper = powerManagerWrapper; mForceSeamlesslyRotate = token.mRoundedCornerOverlay; mInputWindowHandle = new InputWindowHandleWrapper(new InputWindowHandle( mActivityRecord != null @@ -2831,12 +2799,12 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP boolean canTurnScreenOn = mActivityRecord == null || mActivityRecord.currentLaunchCanTurnScreenOn(); if (allowTheaterMode && canTurnScreenOn - && (mWmService.mAtmService.isDreaming() - || !mPowerManagerWrapper.isInteractive())) { + && (mWmService.mAtmService.isDreaming() + || !mWmService.mPowerManager.isInteractive())) { if (DEBUG_VISIBILITY || DEBUG_POWER) { Slog.v(TAG, "Relayout window turning screen on: " + this); } - mPowerManagerWrapper.wakeUp(SystemClock.uptimeMillis(), + mWmService.mPowerManager.wakeUp(SystemClock.uptimeMillis(), PowerManager.WAKE_REASON_APPLICATION, "android.server.wm:SCREEN_ON_FLAG"); } diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java index 85c6f9e9b2fe..718c59875c1a 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java @@ -202,8 +202,7 @@ public class ActivityRecordTests extends WindowTestsBase { } private TestStartingWindowOrganizer registerTestStartingWindowOrganizer() { - return new TestStartingWindowOrganizer(mAtm, - mSystemServicesTestRule.getPowerManagerWrapper()); + return new TestStartingWindowOrganizer(mAtm); } @Test diff --git a/services/tests/wmtests/src/com/android/server/wm/SystemServicesTestRule.java b/services/tests/wmtests/src/com/android/server/wm/SystemServicesTestRule.java index 51f0404e2396..8cd9ff359111 100644 --- a/services/tests/wmtests/src/com/android/server/wm/SystemServicesTestRule.java +++ b/services/tests/wmtests/src/com/android/server/wm/SystemServicesTestRule.java @@ -134,7 +134,6 @@ public class SystemServicesTestRule implements TestRule { private StaticMockitoSession mMockitoSession; private ActivityTaskManagerService mAtmService; private WindowManagerService mWmService; - private WindowState.PowerManagerWrapper mPowerManagerWrapper; private InputManagerService mImService; private InputChannel mInputChannel; private Runnable mOnBeforeServicesCreated; @@ -360,7 +359,6 @@ public class SystemServicesTestRule implements TestRule { } private void setUpWindowManagerService() { - mPowerManagerWrapper = mock(WindowState.PowerManagerWrapper.class); TestWindowManagerPolicy wmPolicy = new TestWindowManagerPolicy(); TestDisplayWindowSettingsProvider testDisplayWindowSettingsProvider = new TestDisplayWindowSettingsProvider(); @@ -485,10 +483,6 @@ public class SystemServicesTestRule implements TestRule { return mAtmService; } - WindowState.PowerManagerWrapper getPowerManagerWrapper() { - return mPowerManagerWrapper; - } - /** Creates a no-op wakelock object. */ PowerManager.WakeLock createStubbedWakeLock(boolean needVerification) { if (needVerification) { diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowStateTests.java b/services/tests/wmtests/src/com/android/server/wm/WindowStateTests.java index 2007f680f1ae..75e252f9a415 100644 --- a/services/tests/wmtests/src/com/android/server/wm/WindowStateTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/WindowStateTests.java @@ -52,7 +52,6 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doThrow; import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; import static com.android.dx.mockito.inline.extended.ExtendedMockito.never; -import static com.android.dx.mockito.inline.extended.ExtendedMockito.reset; import static com.android.dx.mockito.inline.extended.ExtendedMockito.spy; import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; @@ -368,28 +367,26 @@ public class WindowStateTests extends WindowTestsBase { firstWindow.mAttrs.flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON; secondWindow.mAttrs.flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON; - final WindowState.PowerManagerWrapper powerManagerWrapper = - mSystemServicesTestRule.getPowerManagerWrapper(); - reset(powerManagerWrapper); + final var powerManager = mWm.mPowerManager; + clearInvocations(powerManager); firstWindow.prepareWindowToDisplayDuringRelayout(false /*wasVisible*/); - verify(powerManagerWrapper).wakeUp(anyLong(), anyInt(), anyString()); + verify(powerManager).wakeUp(anyLong(), anyInt(), anyString()); - reset(powerManagerWrapper); + clearInvocations(powerManager); secondWindow.prepareWindowToDisplayDuringRelayout(false /*wasVisible*/); - verify(powerManagerWrapper).wakeUp(anyLong(), anyInt(), anyString()); + verify(powerManager).wakeUp(anyLong(), anyInt(), anyString()); } private void testPrepareWindowToDisplayDuringRelayout(WindowState appWindow, boolean expectedWakeupCalled, boolean expectedCurrentLaunchCanTurnScreenOn) { - final WindowState.PowerManagerWrapper powerManagerWrapper = - mSystemServicesTestRule.getPowerManagerWrapper(); - reset(powerManagerWrapper); + final var powerManager = mWm.mPowerManager; + clearInvocations(powerManager); appWindow.prepareWindowToDisplayDuringRelayout(false /* wasVisible */); if (expectedWakeupCalled) { - verify(powerManagerWrapper).wakeUp(anyLong(), anyInt(), anyString()); + verify(powerManager).wakeUp(anyLong(), anyInt(), anyString()); } else { - verify(powerManagerWrapper, never()).wakeUp(anyLong(), anyInt(), anyString()); + verify(powerManager, never()).wakeUp(anyLong(), anyInt(), anyString()); } // If wakeup is expected to be called, the currentLaunchCanTurnScreenOn should be false // because the state will be consumed. diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowTestsBase.java b/services/tests/wmtests/src/com/android/server/wm/WindowTestsBase.java index 616a23e7ab5b..a5f6190f2d51 100644 --- a/services/tests/wmtests/src/com/android/server/wm/WindowTestsBase.java +++ b/services/tests/wmtests/src/com/android/server/wm/WindowTestsBase.java @@ -637,14 +637,12 @@ class WindowTestsBase extends SystemServiceTestsBase { WindowState createWindow(WindowState parent, int type, WindowToken token, String name, int ownerId, boolean ownerCanAddInternalSystemWindow, IWindow iwindow) { return createWindow(parent, type, token, name, ownerId, UserHandle.getUserId(ownerId), - ownerCanAddInternalSystemWindow, mWm, getTestSession(token), iwindow, - mSystemServicesTestRule.getPowerManagerWrapper()); + ownerCanAddInternalSystemWindow, mWm, getTestSession(token), iwindow); } static WindowState createWindow(WindowState parent, int type, WindowToken token, String name, int ownerId, int userId, boolean ownerCanAddInternalSystemWindow, - WindowManagerService service, Session session, IWindow iWindow, - WindowState.PowerManagerWrapper powerManagerWrapper) { + WindowManagerService service, Session session, IWindow iWindow) { SystemServicesTestRule.checkHoldsLock(service.mGlobalLock); final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams(type); @@ -652,9 +650,7 @@ class WindowTestsBase extends SystemServiceTestsBase { attrs.packageName = "test"; final WindowState w = new WindowState(service, session, iWindow, token, parent, - OP_NONE, attrs, VISIBLE, ownerId, userId, - ownerCanAddInternalSystemWindow, - powerManagerWrapper); + OP_NONE, attrs, VISIBLE, ownerId, userId, ownerCanAddInternalSystemWindow); // TODO: Probably better to make this call in the WindowState ctor to avoid errors with // adding it to the token... token.addWindow(w); @@ -1738,17 +1734,14 @@ class WindowTestsBase extends SystemServiceTestsBase { static class TestStartingWindowOrganizer extends WindowOrganizerTests.StubOrganizer { private final ActivityTaskManagerService mAtm; private final WindowManagerService mWMService; - private final WindowState.PowerManagerWrapper mPowerManagerWrapper; private Runnable mRunnableWhenAddingSplashScreen; private final SparseArray<IBinder> mTaskAppMap = new SparseArray<>(); private final HashMap<IBinder, WindowState> mAppWindowMap = new HashMap<>(); - TestStartingWindowOrganizer(ActivityTaskManagerService service, - WindowState.PowerManagerWrapper powerManagerWrapper) { + TestStartingWindowOrganizer(ActivityTaskManagerService service) { mAtm = service; mWMService = mAtm.mWindowManager; - mPowerManagerWrapper = powerManagerWrapper; mAtm.mTaskOrganizerController.setDeferTaskOrgCallbacksConsumer(Runnable::run); mAtm.mTaskOrganizerController.registerTaskOrganizer(this); } @@ -1767,8 +1760,7 @@ class WindowTestsBase extends SystemServiceTestsBase { final WindowState window = WindowTestsBase.createWindow(null, TYPE_APPLICATION_STARTING, activity, "Starting window", 0 /* ownerId */, 0 /* userId*/, - false /* internalWindows */, mWMService, createTestSession(mAtm), iWindow, - mPowerManagerWrapper); + false /* internalWindows */, mWMService, createTestSession(mAtm), iWindow); activity.mStartingWindow = window; mAppWindowMap.put(info.appToken, window); mTaskAppMap.put(info.taskInfo.taskId, info.appToken); |