Allow dozing default display when other displays are awake
Fixes: 219958577 Test: atest PowerManagerServiceTest Change-Id: I74385ad361f46a8f4ed77be172d2b778d3790b92
This commit is contained in:
@@ -3190,7 +3190,7 @@ public final class PowerManagerService extends SystemService
|
||||
wakefulness = powerGroup.getWakefulnessLocked();
|
||||
if ((wakefulness == WAKEFULNESS_DREAMING || wakefulness == WAKEFULNESS_DOZING) &&
|
||||
powerGroup.isSandmanSummonedLocked() && powerGroup.isReadyLocked()) {
|
||||
startDreaming = canDreamLocked(powerGroup) || canDozeLocked();
|
||||
startDreaming = canDreamLocked(powerGroup) || canDozeLocked(powerGroup);
|
||||
powerGroup.setSandmanSummonedLocked(/* isSandmanSummoned= */ false);
|
||||
} else {
|
||||
startDreaming = false;
|
||||
@@ -3329,9 +3329,9 @@ public final class PowerManagerService extends SystemService
|
||||
* Returns true if the device is allowed to doze in its current state.
|
||||
*/
|
||||
@GuardedBy("mLock")
|
||||
private boolean canDozeLocked() {
|
||||
// TODO (b/175764708): Support per-display doze.
|
||||
return getGlobalWakefulnessLocked() == WAKEFULNESS_DOZING;
|
||||
private boolean canDozeLocked(PowerGroup powerGroup) {
|
||||
return powerGroup.supportsSandmanLocked()
|
||||
&& powerGroup.getWakefulnessLocked() == WAKEFULNESS_DOZING;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1683,6 +1683,58 @@ public class PowerManagerServiceTest {
|
||||
assertThat(wakeData.sleepDuration).isEqualTo(eventTime3 - eventTime2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiDisplay_defaultDisplayCanDoze() {
|
||||
createService();
|
||||
startSystem();
|
||||
assertThat(mService.getGlobalWakefulnessLocked()).isEqualTo(WAKEFULNESS_AWAKE);
|
||||
assertThat(mService.getWakefulnessLocked(Display.DEFAULT_DISPLAY_GROUP)).isEqualTo(
|
||||
WAKEFULNESS_AWAKE);
|
||||
|
||||
forceDozing();
|
||||
// Allow handleSandman() to be called asynchronously
|
||||
advanceTime(500);
|
||||
verify(mDreamManagerInternalMock).startDream(eq(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiDisplay_twoDisplays_defaultDisplayCanDoze() {
|
||||
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);
|
||||
|
||||
createService();
|
||||
startSystem();
|
||||
|
||||
listener.get().onDisplayGroupAdded(nonDefaultDisplayGroupId);
|
||||
|
||||
assertThat(mService.getWakefulnessLocked(Display.DEFAULT_DISPLAY_GROUP)).isEqualTo(
|
||||
WAKEFULNESS_AWAKE);
|
||||
assertThat(mService.getWakefulnessLocked(nonDefaultDisplayGroupId)).isEqualTo(
|
||||
WAKEFULNESS_AWAKE);
|
||||
assertThat(mService.getGlobalWakefulnessLocked()).isEqualTo(WAKEFULNESS_AWAKE);
|
||||
|
||||
forceDozing();
|
||||
|
||||
assertThat(mService.getWakefulnessLocked(Display.DEFAULT_DISPLAY_GROUP)).isEqualTo(
|
||||
WAKEFULNESS_DOZING);
|
||||
assertThat(mService.getWakefulnessLocked(nonDefaultDisplayGroupId)).isEqualTo(
|
||||
WAKEFULNESS_AWAKE);
|
||||
assertThat(mService.getGlobalWakefulnessLocked()).isEqualTo(WAKEFULNESS_AWAKE);
|
||||
|
||||
// Allow handleSandman() to be called asynchronously
|
||||
advanceTime(500);
|
||||
verify(mDreamManagerInternalMock).startDream(eq(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLastSleepTime_notUpdatedWhenDreaming() {
|
||||
createService();
|
||||
|
||||
Reference in New Issue
Block a user