Ensure Wakelock display group is still valid.
If a wakelock is obtained for a particular display group and then that display group is removed then the wakelock should be ignored. Bug: 186666967 Test: atest PowerManagerServiceTest#testRemovedDisplayGroupWakeLock_affectsNoDisplayGroups Change-Id: Id191fdd9bad924455e29394f8139ab3b2881f34a
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -922,6 +922,47 @@ public class PowerManagerServiceTest {
|
||||
WAKEFULNESS_AWAKE);
|
||||
}
|
||||
|
||||
@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();
|
||||
|
||||
Reference in New Issue
Block a user