diff options
| author | Nikita Ioffe <ioffe@google.com> | 2019-12-18 13:45:15 +0000 |
|---|---|---|
| committer | Nikita Ioffe <ioffe@google.com> | 2019-12-19 17:26:19 +0000 |
| commit | 717dbbf1a48e7aa722591de5044816f854150da5 (patch) | |
| tree | c53d5fcf62d87a49a4dd9b9d4f6b8159e5e714c1 /core/java/android/os/PowerManager.java | |
| parent | f5b6267d93647d9cb992442071f76f19e37d3a44 (diff) | |
Add an API to tell whenever device supports userspace reboot
If device doesn't support userspace reboot then call to
PowerManager.reboot("userspace") will throw an
UnsupportedOperationException.
For the case of upgrading devices, Treble enforces that previous vendor
image should work with the new system image. Since userspace reboot
requires services to be stopped and restarted cleanly, which upgrading
devices might not be able to comply with, we need to have an API to
distinguish between devices that support userspace reboot and the ones
that do not.
Test: atest PowerManagerTest
Test: atest CtsUserspaceRebootHostSideTestCases
Bug: 138605273
Bug: 135984674
Change-Id: I8303f43ab29499eb2995f0256854c787055d9560
Diffstat (limited to 'core/java/android/os/PowerManager.java')
| -rw-r--r-- | core/java/android/os/PowerManager.java | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java index ab4d424ac053..c618dbc2b551 100644 --- a/core/java/android/os/PowerManager.java +++ b/core/java/android/os/PowerManager.java @@ -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; @@ -605,6 +606,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 */ @@ -1383,6 +1391,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> * Requires the {@link android.Manifest.permission#REBOOT} permission. @@ -1390,8 +1406,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) { |
