diff options
| -rw-r--r-- | services/core/java/com/android/server/power/PowerManagerService.java | 16 | ||||
| -rw-r--r-- | services/tests/servicestests/src/com/android/server/power/PowerManagerServiceTest.java | 41 |
2 files changed, 54 insertions, 3 deletions
diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java index 3018e5f8fa33..b5f3253eea0e 100644 --- a/services/core/java/com/android/server/power/PowerManagerService.java +++ b/services/core/java/com/android/server/power/PowerManagerService.java @@ -2329,10 +2329,14 @@ public final class PowerManagerService extends SystemService final int numWakeLocks = mWakeLocks.size(); for (int i = 0; i < numWakeLocks; i++) { final WakeLock wakeLock = mWakeLocks.get(i); + final Integer groupId = wakeLock.getDisplayGroupId(); + if (groupId == null) { + continue; + } + final int wakeLockFlags = getWakeLockSummaryFlags(wakeLock); mWakeLockSummary |= wakeLockFlags; - final int groupId = wakeLock.getDisplayGroupId(); if (groupId != Display.INVALID_DISPLAY_GROUP) { int wakeLockSummary = mDisplayGroupPowerStateMapper.getWakeLockSummaryLocked( groupId); @@ -4876,13 +4880,19 @@ public final class PowerManagerService extends SystemService mWorkSource = copyWorkSource(workSource); } - public int getDisplayGroupId() { + /** Returns the DisplayGroup Id of this wakeLock or {@code null} if no longer valid. */ + public Integer getDisplayGroupId() { if (!mSystemReady || mDisplayId == Display.INVALID_DISPLAY) { return Display.INVALID_DISPLAY_GROUP; } + final int[] ids = mDisplayGroupPowerStateMapper.getDisplayGroupIdsLocked(); final DisplayInfo displayInfo = mDisplayManagerInternal.getDisplayInfo(mDisplayId); - return displayInfo == null ? Display.INVALID_DISPLAY_GROUP : displayInfo.displayGroupId; + if (displayInfo != null && ArrayUtils.contains(ids, displayInfo.displayGroupId)) { + return displayInfo.displayGroupId; + } + + return null; } @Override diff --git a/services/tests/servicestests/src/com/android/server/power/PowerManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/power/PowerManagerServiceTest.java index 874f8dc538aa..38f976c32d6d 100644 --- a/services/tests/servicestests/src/com/android/server/power/PowerManagerServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/power/PowerManagerServiceTest.java @@ -923,6 +923,47 @@ public class PowerManagerServiceTest { } @Test + public void testRemovedDisplayGroupWakeLock_affectsNoDisplayGroups() throws Exception { + final int nonDefaultDisplayGroupId = Display.DEFAULT_DISPLAY_GROUP + 1; + final int nonDefaultDisplay = Display.DEFAULT_DISPLAY + 1; + final AtomicReference<DisplayManagerInternal.DisplayGroupListener> listener = + new AtomicReference<>(); + doAnswer((Answer<Void>) invocation -> { + listener.set(invocation.getArgument(0)); + return null; + }).when(mDisplayManagerInternalMock).registerDisplayGroupListener(any()); + final DisplayInfo info = new DisplayInfo(); + info.displayGroupId = nonDefaultDisplayGroupId; + when(mDisplayManagerInternalMock.getDisplayInfo(nonDefaultDisplay)).thenReturn(info); + + final String pkg = mContextSpy.getOpPackageName(); + final Binder token = new Binder(); + final String tag = "testRemovedDisplayGroupWakeLock_affectsNoDisplayGroups"; + + setMinimumScreenOffTimeoutConfig(5); + createService(); + startSystem(); + listener.get().onDisplayGroupAdded(nonDefaultDisplayGroupId); + + mService.getBinderServiceInstance().acquireWakeLock(token, + PowerManager.SCREEN_BRIGHT_WAKE_LOCK, tag, pkg, + null /* workSource */, null /* historyTag */, nonDefaultDisplay); + + assertThat(mService.getWakefulnessLocked(Display.DEFAULT_DISPLAY_GROUP)).isEqualTo( + WAKEFULNESS_AWAKE); + assertThat(mService.getWakefulnessLocked(nonDefaultDisplayGroupId)).isEqualTo( + WAKEFULNESS_AWAKE); + assertThat(mService.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_AWAKE); + + listener.get().onDisplayGroupRemoved(nonDefaultDisplayGroupId); + + advanceTime(15000); + assertThat(mService.getWakefulnessLocked(Display.DEFAULT_DISPLAY_GROUP)).isEqualTo( + WAKEFULNESS_DOZING); + assertThat(mService.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_DOZING); + } + + @Test public void testBoot_ShouldBeAwake() throws Exception { createService(); startSystem(); |