Loading api/current.txt +2 −1 Original line number Diff line number Diff line Loading @@ -35445,11 +35445,12 @@ package android.os { method public boolean isIgnoringBatteryOptimizations(String); method public boolean isInteractive(); method public boolean isPowerSaveMode(); method public boolean isRebootingUserspaceSupported(); method @Deprecated public boolean isScreenOn(); method public boolean isSustainedPerformanceModeSupported(); method public boolean isWakeLockLevelSupported(int); method public android.os.PowerManager.WakeLock newWakeLock(int, String); method public void reboot(String); method public void reboot(@Nullable String); method public void removeThermalStatusListener(@NonNull android.os.PowerManager.OnThermalStatusChangedListener); field public static final int ACQUIRE_CAUSES_WAKEUP = 268435456; // 0x10000000 field public static final String ACTION_DEVICE_IDLE_MODE_CHANGED = "android.os.action.DEVICE_IDLE_MODE_CHANGED"; api/system-current.txt +1 −0 Original line number Diff line number Diff line Loading @@ -6642,6 +6642,7 @@ package android.os { method @RequiresPermission(anyOf={android.Manifest.permission.DEVICE_POWER, android.Manifest.permission.USER_ACTIVITY}) public void userActivity(long, int, int); field public static final int POWER_SAVE_MODE_TRIGGER_DYNAMIC = 1; // 0x1 field public static final int POWER_SAVE_MODE_TRIGGER_PERCENTAGE = 0; // 0x0 field public static final String REBOOT_USERSPACE = "userspace"; field public static final int USER_ACTIVITY_EVENT_ACCESSIBILITY = 3; // 0x3 field public static final int USER_ACTIVITY_EVENT_BUTTON = 1; // 0x1 field public static final int USER_ACTIVITY_EVENT_OTHER = 0; // 0x0 Loading core/java/android/os/PowerManager.java +23 −1 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.Manifest.permission; import android.annotation.CallbackExecutor; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.RequiresPermission; import android.annotation.SdkConstant; import android.annotation.SystemApi; Loading Loading @@ -551,6 +552,13 @@ public final class PowerManager { */ public static final String REBOOT_SAFE_MODE = "safemode"; /** * The 'reason' value used for rebooting userspace. * @hide */ @SystemApi public static final String REBOOT_USERSPACE = "userspace"; /** * The 'reason' value used when rebooting the device without turning on the screen. * @hide Loading Loading @@ -1325,6 +1333,14 @@ public final class PowerManager { } } /** * Returns {@code true} if this device supports rebooting userspace. */ // TODO(b/138605180): add link to documentation once it's ready. public boolean isRebootingUserspaceSupported() { return SystemProperties.getBoolean("ro.init.userspace_reboot.is_supported", false); } /** * Reboot the device. Will not return if the reboot is successful. * <p> Loading @@ -1333,8 +1349,14 @@ public final class PowerManager { * * @param reason code to pass to the kernel (e.g., "recovery") to * request special boot modes, or null. * @throws UnsupportedOperationException if userspace reboot was requested on a device that * doesn't support it. */ public void reboot(String reason) { public void reboot(@Nullable String reason) { if (REBOOT_USERSPACE.equals(reason) && !isRebootingUserspaceSupported()) { throw new UnsupportedOperationException( "Attempted userspace reboot on a device that doesn't support it"); } try { mService.reboot(false, reason, true); } catch (RemoteException e) { Loading core/tests/coretests/src/android/os/PowerManagerTest.java +13 −0 Original line number Diff line number Diff line Loading @@ -239,4 +239,17 @@ public class PowerManagerTest extends AndroidTestCase { verify(mListener2, timeout(CALLBACK_TIMEOUT_MILLI_SEC) .times(1)).onThermalStatusChanged(status); } @Test public void testUserspaceRebootNotSupported_throwsUnsupportedOperationException() { // Can't use assumption framework with AndroidTestCase :( if (mPm.isRebootingUserspaceSupported()) { return; } try { mPm.reboot(PowerManager.REBOOT_USERSPACE); fail("UnsupportedOperationException not thrown"); } catch (UnsupportedOperationException expected) { } } } Loading
api/current.txt +2 −1 Original line number Diff line number Diff line Loading @@ -35445,11 +35445,12 @@ package android.os { method public boolean isIgnoringBatteryOptimizations(String); method public boolean isInteractive(); method public boolean isPowerSaveMode(); method public boolean isRebootingUserspaceSupported(); method @Deprecated public boolean isScreenOn(); method public boolean isSustainedPerformanceModeSupported(); method public boolean isWakeLockLevelSupported(int); method public android.os.PowerManager.WakeLock newWakeLock(int, String); method public void reboot(String); method public void reboot(@Nullable String); method public void removeThermalStatusListener(@NonNull android.os.PowerManager.OnThermalStatusChangedListener); field public static final int ACQUIRE_CAUSES_WAKEUP = 268435456; // 0x10000000 field public static final String ACTION_DEVICE_IDLE_MODE_CHANGED = "android.os.action.DEVICE_IDLE_MODE_CHANGED";
api/system-current.txt +1 −0 Original line number Diff line number Diff line Loading @@ -6642,6 +6642,7 @@ package android.os { method @RequiresPermission(anyOf={android.Manifest.permission.DEVICE_POWER, android.Manifest.permission.USER_ACTIVITY}) public void userActivity(long, int, int); field public static final int POWER_SAVE_MODE_TRIGGER_DYNAMIC = 1; // 0x1 field public static final int POWER_SAVE_MODE_TRIGGER_PERCENTAGE = 0; // 0x0 field public static final String REBOOT_USERSPACE = "userspace"; field public static final int USER_ACTIVITY_EVENT_ACCESSIBILITY = 3; // 0x3 field public static final int USER_ACTIVITY_EVENT_BUTTON = 1; // 0x1 field public static final int USER_ACTIVITY_EVENT_OTHER = 0; // 0x0 Loading
core/java/android/os/PowerManager.java +23 −1 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.Manifest.permission; import android.annotation.CallbackExecutor; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.RequiresPermission; import android.annotation.SdkConstant; import android.annotation.SystemApi; Loading Loading @@ -551,6 +552,13 @@ public final class PowerManager { */ public static final String REBOOT_SAFE_MODE = "safemode"; /** * The 'reason' value used for rebooting userspace. * @hide */ @SystemApi public static final String REBOOT_USERSPACE = "userspace"; /** * The 'reason' value used when rebooting the device without turning on the screen. * @hide Loading Loading @@ -1325,6 +1333,14 @@ public final class PowerManager { } } /** * Returns {@code true} if this device supports rebooting userspace. */ // TODO(b/138605180): add link to documentation once it's ready. public boolean isRebootingUserspaceSupported() { return SystemProperties.getBoolean("ro.init.userspace_reboot.is_supported", false); } /** * Reboot the device. Will not return if the reboot is successful. * <p> Loading @@ -1333,8 +1349,14 @@ public final class PowerManager { * * @param reason code to pass to the kernel (e.g., "recovery") to * request special boot modes, or null. * @throws UnsupportedOperationException if userspace reboot was requested on a device that * doesn't support it. */ public void reboot(String reason) { public void reboot(@Nullable String reason) { if (REBOOT_USERSPACE.equals(reason) && !isRebootingUserspaceSupported()) { throw new UnsupportedOperationException( "Attempted userspace reboot on a device that doesn't support it"); } try { mService.reboot(false, reason, true); } catch (RemoteException e) { Loading
core/tests/coretests/src/android/os/PowerManagerTest.java +13 −0 Original line number Diff line number Diff line Loading @@ -239,4 +239,17 @@ public class PowerManagerTest extends AndroidTestCase { verify(mListener2, timeout(CALLBACK_TIMEOUT_MILLI_SEC) .times(1)).onThermalStatusChanged(status); } @Test public void testUserspaceRebootNotSupported_throwsUnsupportedOperationException() { // Can't use assumption framework with AndroidTestCase :( if (mPm.isRebootingUserspaceSupported()) { return; } try { mPm.reboot(PowerManager.REBOOT_USERSPACE); fail("UnsupportedOperationException not thrown"); } catch (UnsupportedOperationException expected) { } } }