diff options
Diffstat (limited to 'core/java/android/os/PowerManager.java')
| -rw-r--r-- | core/java/android/os/PowerManager.java | 73 |
1 files changed, 54 insertions, 19 deletions
diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java index 8f2d218a20c1..13ca2c34b27e 100644 --- a/core/java/android/os/PowerManager.java +++ b/core/java/android/os/PowerManager.java @@ -463,21 +463,22 @@ public final class PowerManager { /** * @hide */ - public static String sleepReasonToString(int sleepReason) { + public static String sleepReasonToString(@GoToSleepReason int sleepReason) { switch (sleepReason) { + case GO_TO_SLEEP_REASON_ACCESSIBILITY: return "accessibility"; case GO_TO_SLEEP_REASON_APPLICATION: return "application"; case GO_TO_SLEEP_REASON_DEVICE_ADMIN: return "device_admin"; - case GO_TO_SLEEP_REASON_TIMEOUT: return "timeout"; + case GO_TO_SLEEP_REASON_DEVICE_FOLD: return "device_folded"; + case GO_TO_SLEEP_REASON_DISPLAY_GROUP_REMOVED: return "display_group_removed"; + case GO_TO_SLEEP_REASON_DISPLAY_GROUPS_TURNED_OFF: return "display_groups_turned_off"; + case GO_TO_SLEEP_REASON_FORCE_SUSPEND: return "force_suspend"; + case GO_TO_SLEEP_REASON_HDMI: return "hdmi"; + case GO_TO_SLEEP_REASON_INATTENTIVE: return "inattentive"; case GO_TO_SLEEP_REASON_LID_SWITCH: return "lid_switch"; case GO_TO_SLEEP_REASON_POWER_BUTTON: return "power_button"; - case GO_TO_SLEEP_REASON_HDMI: return "hdmi"; + case GO_TO_SLEEP_REASON_QUIESCENT: return "quiescent"; 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"; - case GO_TO_SLEEP_REASON_DISPLAY_GROUP_REMOVED: return "display_group_removed"; - case GO_TO_SLEEP_REASON_DISPLAY_GROUPS_TURNED_OFF: return "display_groups_turned_off"; - case GO_TO_SLEEP_REASON_DEVICE_FOLD: return "device_folded"; + case GO_TO_SLEEP_REASON_TIMEOUT: return "timeout"; default: return Integer.toString(sleepReason); } } @@ -576,18 +577,20 @@ public final class PowerManager { * @hide */ @IntDef(prefix = { "GO_TO_SLEEP_REASON_" }, value = { + GO_TO_SLEEP_REASON_ACCESSIBILITY, GO_TO_SLEEP_REASON_APPLICATION, GO_TO_SLEEP_REASON_DEVICE_ADMIN, - GO_TO_SLEEP_REASON_TIMEOUT, - GO_TO_SLEEP_REASON_LID_SWITCH, - GO_TO_SLEEP_REASON_POWER_BUTTON, - GO_TO_SLEEP_REASON_HDMI, - GO_TO_SLEEP_REASON_SLEEP_BUTTON, - GO_TO_SLEEP_REASON_ACCESSIBILITY, + GO_TO_SLEEP_REASON_DEVICE_FOLD, + GO_TO_SLEEP_REASON_DISPLAY_GROUP_REMOVED, + GO_TO_SLEEP_REASON_DISPLAY_GROUPS_TURNED_OFF, GO_TO_SLEEP_REASON_FORCE_SUSPEND, + GO_TO_SLEEP_REASON_HDMI, GO_TO_SLEEP_REASON_INATTENTIVE, + GO_TO_SLEEP_REASON_LID_SWITCH, + GO_TO_SLEEP_REASON_POWER_BUTTON, GO_TO_SLEEP_REASON_QUIESCENT, - GO_TO_SLEEP_REASON_DEVICE_FOLD + GO_TO_SLEEP_REASON_SLEEP_BUTTON, + GO_TO_SLEEP_REASON_TIMEOUT, }) @Retention(RetentionPolicy.SOURCE) public @interface GoToSleepReason{} @@ -704,6 +707,8 @@ public final class PowerManager { } /** + * Information related to the device waking up, triggered by {@link #wakeUp}. + * * @hide */ public static class WakeData { @@ -712,9 +717,9 @@ public final class PowerManager { this.wakeReason = wakeReason; this.sleepDuration = sleepDuration; } - public long wakeTime; - public @WakeReason int wakeReason; - public long sleepDuration; + public final long wakeTime; + public final @WakeReason int wakeReason; + public final long sleepDuration; @Override public boolean equals(@Nullable Object o) { @@ -733,6 +738,35 @@ public final class PowerManager { } /** + * Information related to the device going to sleep, triggered by {@link #goToSleep}. + * + * @hide + */ + public static class SleepData { + public SleepData(long goToSleepUptimeMillis, @GoToSleepReason int goToSleepReason) { + this.goToSleepUptimeMillis = goToSleepUptimeMillis; + this.goToSleepReason = goToSleepReason; + } + public final long goToSleepUptimeMillis; + public final @GoToSleepReason int goToSleepReason; + + @Override + public boolean equals(@Nullable Object o) { + if (o instanceof SleepData) { + final SleepData other = (SleepData) o; + return goToSleepUptimeMillis == other.goToSleepUptimeMillis + && goToSleepReason == other.goToSleepReason; + } + return false; + } + + @Override + public int hashCode() { + return Objects.hash(goToSleepUptimeMillis, goToSleepReason); + } + } + + /** * The value to pass as the 'reason' argument to reboot() to reboot into * recovery mode for tasks other than applying system updates, such as * doing factory resets. @@ -2644,6 +2678,7 @@ public final class PowerManager { * * @hide */ + @GoToSleepReason public int getLastSleepReason() { try { return mService.getLastSleepReason(); |
