Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5560f386 authored by Robert Horvath's avatar Robert Horvath
Browse files

Add setting to go to sleep after long user inactivity

The European Commision prescribes an auto-standby feature for TV panels:
After some hours of inactivity, the device has to go from on-mode to
standby-mode or off-mode, or another condition not exceeding the
applicable requirements for standby-mode or for off-mode.

After a long time of no user activity the device should go to sleep,
even if wakelocks are held (eg. during video playback).

Test: 1. Set attentive timeout low, to 35s:
         `adb shell settings put secure attentive_timeout 35000`
      2. Play a YouTube video
      3. Observe warning dialog appearing after 5s
      4. Verify: Clicking a remote button or changing the setting higher hides
         the warning. Remote button press is consumed.
      5. Verify: After 35s of not pressing a button the device goes to sleep
      6. Verify: If "Stay awake" developer option is enabled, then
         warning is not displayed and device does not go to sleep after 35s
      7. Verify: No warning or sleep if setting is set to -1
Test: `atest frameworks/base/services/tests/servicestests/src/com/android/server/power/PowerManagerServiceTest.java`
Bug: 137633812
Change-Id: I551b6cffc336437fb1c5a00b4102f68ae0e003e9
parent 94eebca4
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -426,9 +426,15 @@ public final class PowerManager {
    public static final int GO_TO_SLEEP_REASON_FORCE_SUSPEND = 8;

    /**
     * Go to sleep reason code: Going to sleep due to user inattentiveness.
     * @hide
     */
    public static final int GO_TO_SLEEP_REASON_MAX = GO_TO_SLEEP_REASON_FORCE_SUSPEND;
    public static final int GO_TO_SLEEP_REASON_INATTENTIVE = 9;

    /**
     * @hide
     */
    public static final int GO_TO_SLEEP_REASON_MAX = GO_TO_SLEEP_REASON_INATTENTIVE;

    /**
     * @hide
@@ -444,6 +450,7 @@ public final class PowerManager {
            case GO_TO_SLEEP_REASON_SLEEP_BUTTON: return "sleep_button";
            case GO_TO_SLEEP_REASON_ACCESSIBILITY: return "accessibility";
            case GO_TO_SLEEP_REASON_FORCE_SUSPEND: return "force_suspend";
            case GO_TO_SLEEP_REASON_INATTENTIVE: return "inattentive";
            default: return Integer.toString(sleepReason);
        }
    }
+14 −0
Original line number Diff line number Diff line
@@ -7676,6 +7676,20 @@ public final class Settings {
         */
        public static final String SLEEP_TIMEOUT = "sleep_timeout";
        /**
         * The timeout in milliseconds before the device goes to sleep due to user inattentiveness,
         * even if the system is holding wakelocks. It should generally be longer than {@code
         * config_attentiveWarningDuration}, as otherwise the device will show the attentive
         * warning constantly. Small timeouts are discouraged, as they will cause the device to
         * go to sleep quickly after waking up.
         * <p>
         * Use -1 to disable this timeout.
         * </p>
         *
         * @hide
         */
        public static final String ATTENTIVE_TIMEOUT = "attentive_timeout";
        /**
         * Controls whether double tap to wake is enabled.
         * @hide
+10 −0
Original line number Diff line number Diff line
@@ -188,4 +188,14 @@ oneway interface IStatusBar
     * @param types the internal insets types of the bars are about to abort the transient state.
     */
    void abortTransient(int displayId, in int[] types);

    /**
     * Show a warning that the device is about to go to sleep due to user inactivity.
     */
    void showInattentiveSleepWarning();

    /**
     * Dismiss the warning that the device is about to go to sleep due to user inactivity.
     */
    void dismissInattentiveSleepWarning();
}
+10 −0
Original line number Diff line number Diff line
@@ -113,4 +113,14 @@ interface IStatusBarService
    void onBiometricError(int modality, int error, int vendorCode);
    // Used to hide the authentication dialog, e.g. when the application cancels authentication
    void hideAuthenticationDialog();

    /**
     * Show a warning that the device is about to go to sleep due to user inactivity.
     */
    void showInattentiveSleepWarning();

    /**
     * Dismiss the warning that the device is about to go to sleep due to user inactivity.
     */
    void dismissInattentiveSleepWarning();
}
+8 −0
Original line number Diff line number Diff line
@@ -172,6 +172,8 @@ message PowerManagerServiceDumpProto {
    repeated SuspendBlockerProto suspend_blockers = 48;
    optional WirelessChargerDetectorProto wireless_charger_detector = 49;
    optional BatterySaverStateMachineProto battery_saver_state_machine = 50;
    // Attentive timeout in ms. The timeout is disabled if it is set to -1.
    optional sint32 attentive_timeout_ms = 51;
}

// A com.android.server.power.PowerManagerService.SuspendBlockerImpl object.
@@ -310,6 +312,12 @@ message PowerServiceSettingsAndConfigurationDumpProto {
    optional bool is_vr_mode_enabled = 35;
    // True if Sidekick is controlling the display and we shouldn't change its power mode.
    optional bool draw_wake_lock_override_from_sidekick = 36;
    // The attentive timeout setting value in milliseconds. Default value is -1.
    optional sint32 attentive_timeout_setting_ms = 37;
    // The attentive timeout config value in milliseconds.
    optional sint32 attentive_timeout_config_ms = 38;
    // The attentive warning duration config value in milliseconds.
    optional sint32 attentive_warning_duration_config_ms = 39;
}

message BatterySaverStateMachineProto {
Loading