From 822394b0658a84a55c2534428b6625eb3208704b Mon Sep 17 00:00:00 2001 From: Robert Horvath Date: Thu, 24 Jun 2021 14:44:49 +0200 Subject: [PATCH] Dismiss Inattentive Sleep Warning when inattentive sleep is disabled Make sure that if attentive_timeout is set < 0, maybeHideInattentiveSleepWarningLocked is still called to dismiss the warning. Bug: 191822171 Test: Show warning: adb shell settings put secure attentive_timeout 30000 Disable inattentive sleep: adb shell settings put secure attentive_timeout -1 Verify warning is dismissed Test: atest PowerManagerServiceTest#testInattentiveSleep_hideWarningIfInattentiveSleepIsDisabled Test: atest --rerun-until-failure 20 InattentiveSleepTests#testInattentiveSleep_noWarningShownIfInattentiveSleepDisabled Change-Id: I9e5f956924bba9f29ae6cac94b087bd73ed0bac0 --- .../server/power/PowerManagerService.java | 14 ++++++-------- .../server/power/PowerManagerServiceTest.java | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java index b5f3253eea0ee..9638255dfc799 100644 --- a/services/core/java/com/android/server/power/PowerManagerService.java +++ b/services/core/java/com/android/server/power/PowerManagerService.java @@ -1344,7 +1344,8 @@ public final class PowerManagerService extends SystemService mDirty |= DIRTY_SETTINGS; } - private void handleSettingsChangedLocked() { + @VisibleForTesting + void handleSettingsChangedLocked() { updateSettingsLocked(); updatePowerStateLocked(); } @@ -2651,9 +2652,6 @@ public final class PowerManagerService extends SystemService private void updateAttentiveStateLocked(long now, int dirty) { long attentiveTimeout = getAttentiveTimeoutLocked(); - if (attentiveTimeout < 0) { - return; - } // Attentive state only applies to the default display group. long goToSleepTime = mDisplayGroupPowerStateMapper.getLastUserActivityTimeLocked( Display.DEFAULT_DISPLAY_GROUP) + attentiveTimeout; @@ -2661,10 +2659,10 @@ public final class PowerManagerService extends SystemService boolean warningDismissed = maybeHideInattentiveSleepWarningLocked(now, showWarningTime); - if (warningDismissed || - (dirty & (DIRTY_ATTENTIVE | DIRTY_STAY_ON | DIRTY_SCREEN_BRIGHTNESS_BOOST - | DIRTY_PROXIMITY_POSITIVE | DIRTY_WAKEFULNESS | DIRTY_BOOT_COMPLETED - | DIRTY_SETTINGS)) != 0) { + if (attentiveTimeout >= 0 && (warningDismissed + || (dirty & (DIRTY_ATTENTIVE | DIRTY_STAY_ON | DIRTY_SCREEN_BRIGHTNESS_BOOST + | DIRTY_PROXIMITY_POSITIVE | DIRTY_WAKEFULNESS | DIRTY_BOOT_COMPLETED + | DIRTY_SETTINGS)) != 0)) { if (DEBUG_SPEW) { Slog.d(TAG, "Updating attentive state"); } 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 38f976c32d6d3..5eabc1bea1484 100644 --- a/services/tests/servicestests/src/com/android/server/power/PowerManagerServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/power/PowerManagerServiceTest.java @@ -760,6 +760,25 @@ public class PowerManagerServiceTest { verify(mInattentiveSleepWarningControllerMock, atLeastOnce()).dismiss(true); } + @Test + public void testInattentiveSleep_hideWarningIfInattentiveSleepIsDisabled() throws Exception { + setMinimumScreenOffTimeoutConfig(5); + setAttentiveWarningDuration(120); + setAttentiveTimeout(100); + + createService(); + startSystem(); + + verify(mInattentiveSleepWarningControllerMock, times(1)).show(); + verify(mInattentiveSleepWarningControllerMock, never()).dismiss(anyBoolean()); + when(mInattentiveSleepWarningControllerMock.isShown()).thenReturn(true); + + setAttentiveTimeout(-1); + mService.handleSettingsChangedLocked(); + + verify(mInattentiveSleepWarningControllerMock, atLeastOnce()).dismiss(true); + } + @Test public void testInattentiveSleep_userActivityDismissesWarning() throws Exception { final DisplayInfo info = new DisplayInfo();