Fix inattentive sleep failing to go to sleep while dreaming

Sets the user activity summary to 0 if the attentive timeout is expired.
This leads `canDreamLocked` to return `false`, and `handleSandman` to
end the dream and put the device to sleep.

Bug: 199967105
Bug: 209963168
Bug: 206737976
Test: atest PowerManagerServiceTest
Change-Id: I33320b6e38886b0c58ace33d901fea38f828d2c6
This commit is contained in:
Robert Horvath
2022-01-13 16:47:37 +01:00
parent 0547403805
commit cea1f0c9ee
2 changed files with 25 additions and 3 deletions

View File

@@ -2682,8 +2682,8 @@ public final class PowerManagerService extends SystemService
@GuardedBy("mLock")
private void updateUserActivitySummaryLocked(long now, int dirty) {
// Update the status of the user activity timeout timer.
if ((dirty & (DIRTY_DISPLAY_GROUP_WAKEFULNESS | DIRTY_WAKE_LOCKS
| DIRTY_USER_ACTIVITY | DIRTY_WAKEFULNESS | DIRTY_SETTINGS)) == 0) {
if ((dirty & (DIRTY_DISPLAY_GROUP_WAKEFULNESS | DIRTY_WAKE_LOCKS | DIRTY_USER_ACTIVITY
| DIRTY_WAKEFULNESS | DIRTY_SETTINGS | DIRTY_ATTENTIVE)) == 0) {
return;
}
mHandler.removeMessages(MSG_USER_ACTIVITY_TIMEOUT);
@@ -2770,6 +2770,11 @@ public final class PowerManagerService extends SystemService
screenDimDuration);
}
if (isAttentiveTimeoutExpired(powerGroup, now)) {
groupUserActivitySummary = 0;
groupNextTimeout = -1;
}
hasUserActivitySummary |= groupUserActivitySummary != 0;
if (nextTimeout == -1) {
@@ -3125,7 +3130,7 @@ public final class PowerManagerService extends SystemService
Message msg = mHandler.obtainMessage(MSG_SANDMAN);
msg.arg1 = powerGroup.getGroupId();
msg.setAsynchronous(true);
mHandler.sendMessage(msg);
mHandler.sendMessageAtTime(msg, mClock.uptimeMillis());
}
}
}

View File

@@ -1058,6 +1058,23 @@ public class PowerManagerServiceTest {
assertThat(mService.getGlobalWakefulnessLocked()).isNotEqualTo(WAKEFULNESS_ASLEEP);
}
@SuppressWarnings("GuardedBy")
@Test
public void testInattentiveSleep_goesToSleepFromDream() throws Exception {
setAttentiveTimeout(20000);
createService();
startSystem();
setPluggedIn(true);
forceAwake();
forceDream();
when(mDreamManagerInternalMock.isDreaming()).thenReturn(true);
assertThat(mService.getGlobalWakefulnessLocked()).isEqualTo(WAKEFULNESS_DREAMING);
advanceTime(20500);
assertThat(mService.getGlobalWakefulnessLocked()).isEqualTo(WAKEFULNESS_ASLEEP);
}
@Test
public void testWakeLock_affectsProperDisplayGroup() {
final int nonDefaultDisplayGroupId = Display.DEFAULT_DISPLAY_GROUP + 1;