Merge "Ensure Wakelock display group is still valid." into sc-dev

This commit is contained in:
Sean Stout
2021-05-21 21:19:29 +00:00
committed by Android (Google) Code Review
2 changed files with 54 additions and 3 deletions

View File

@@ -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

View File

@@ -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();