diff options
| author | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2019-12-20 02:27:51 +0000 |
|---|---|---|
| committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2019-12-20 02:27:51 +0000 |
| commit | 6af4789825dd28fd516df963203965564a004936 (patch) | |
| tree | 6b663bc7972124cd3ebc287933a76e42660371e9 /core/java/android/os/PowerManager.java | |
| parent | 3714b23180d489ddcdb92475ce48c692cbe6c3fb (diff) | |
| parent | 0b11673991d8bddf77d4706fbe1c8f0d43a68c02 (diff) | |
Merge "Add an API to tell whenever device supports userspace reboot" am: 670352e807 am: d1c0e074c0 am: 0b11673991
Change-Id: I797923d568645425aca0659d02cd8dc0364a25ff
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 2f8e30e42b7e..82b04a661b54 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; @@ -552,6 +553,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 */ @@ -1326,6 +1334,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. @@ -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) { |
