diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 80257c8ed575e..03257a0dc1a75 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -7343,12 +7343,14 @@ package android.os { public class RecoverySystem { method @RequiresPermission(android.Manifest.permission.RECOVERY) public static void cancelScheduledUpdate(android.content.Context) throws java.io.IOException; - method @RequiresPermission(android.Manifest.permission.RECOVERY) public static void clearPrepareForUnattendedUpdate(@NonNull android.content.Context) throws java.io.IOException; + method @RequiresPermission(anyOf={android.Manifest.permission.RECOVERY, android.Manifest.permission.REBOOT}) public static void clearPrepareForUnattendedUpdate(@NonNull android.content.Context) throws java.io.IOException; method @RequiresPermission(android.Manifest.permission.RECOVERY) public static void installPackage(android.content.Context, java.io.File, boolean) throws java.io.IOException; - method @RequiresPermission(android.Manifest.permission.RECOVERY) public static void prepareForUnattendedUpdate(@NonNull android.content.Context, @NonNull String, @Nullable android.content.IntentSender) throws java.io.IOException; + method @RequiresPermission(anyOf={android.Manifest.permission.RECOVERY, android.Manifest.permission.REBOOT}) public static boolean isPreparedForUnattendedUpdate(@NonNull android.content.Context) throws java.io.IOException; + method @RequiresPermission(anyOf={android.Manifest.permission.RECOVERY, android.Manifest.permission.REBOOT}) public static void prepareForUnattendedUpdate(@NonNull android.content.Context, @NonNull String, @Nullable android.content.IntentSender) throws java.io.IOException; method @RequiresPermission(android.Manifest.permission.RECOVERY) public static void processPackage(android.content.Context, java.io.File, android.os.RecoverySystem.ProgressListener, android.os.Handler) throws java.io.IOException; method @RequiresPermission(android.Manifest.permission.RECOVERY) public static void processPackage(android.content.Context, java.io.File, android.os.RecoverySystem.ProgressListener) throws java.io.IOException; - method @RequiresPermission(android.Manifest.permission.RECOVERY) public static void rebootAndApply(@NonNull android.content.Context, @NonNull String, @NonNull String) throws java.io.IOException; + method @RequiresPermission(anyOf={android.Manifest.permission.RECOVERY, android.Manifest.permission.REBOOT}) public static void rebootAndApply(@NonNull android.content.Context, @NonNull String, @NonNull String) throws java.io.IOException; + method @RequiresPermission(anyOf={android.Manifest.permission.RECOVERY, android.Manifest.permission.REBOOT}) public static void rebootAndApply(@NonNull android.content.Context, @NonNull String, boolean) throws java.io.IOException; method @RequiresPermission(allOf={android.Manifest.permission.RECOVERY, android.Manifest.permission.REBOOT}) public static void rebootWipeAb(android.content.Context, java.io.File, String) throws java.io.IOException; method @RequiresPermission(android.Manifest.permission.RECOVERY) public static void scheduleUpdateOnBoot(android.content.Context, java.io.File) throws java.io.IOException; method public static boolean verifyPackageCompatibility(java.io.File) throws java.io.IOException; diff --git a/core/java/android/os/RecoverySystem.java b/core/java/android/os/RecoverySystem.java index 71b9f15be2974..189e62baba00c 100644 --- a/core/java/android/os/RecoverySystem.java +++ b/core/java/android/os/RecoverySystem.java @@ -631,10 +631,19 @@ public class RecoverySystem { /** * Prepare to apply an unattended update by asking the user for their Lock Screen Knowledge * Factor (LSKF). If supplied, the {@code intentSender} will be called when the system is setup - * and ready to apply the OTA. + * and ready to apply the OTA. This API is expected to handle requests from multiple clients + * simultaneously, e.g. from ota and mainline. + * + *
The behavior of multi-client Resume on Reboot works as follows + *
Note that the API won't clear the underlying Resume on Reboot preparation state if + * another client has requested. So the reboot call from the other client can still succeed. + * * @param context the Context to use. * @throws IOException if there were any errors clearing the unattended update state * @hide */ @SystemApi - @RequiresPermission(android.Manifest.permission.RECOVERY) + @RequiresPermission(anyOf = {android.Manifest.permission.RECOVERY, + android.Manifest.permission.REBOOT}) public static void clearPrepareForUnattendedUpdate(@NonNull Context context) throws IOException { RecoverySystem rs = (RecoverySystem) context.getSystemService(Context.RECOVERY_SERVICE); @@ -673,7 +687,8 @@ public class RecoverySystem { } /** - * Request that the device reboot and apply the update that has been prepared. + * Request that the device reboot and apply the update that has been prepared. Callers are + * recommended to use {@link #rebootAndApply(Context, String, boolean)} instead. * * @param context the Context to use. * @param updateToken this parameter is deprecated and won't be used. See details in @@ -686,7 +701,8 @@ public class RecoverySystem { * @hide */ @SystemApi - @RequiresPermission(android.Manifest.permission.RECOVERY) + @RequiresPermission(anyOf = {android.Manifest.permission.RECOVERY, + android.Manifest.permission.REBOOT}) public static void rebootAndApply(@NonNull Context context, @NonNull String updateToken, @NonNull String reason) throws IOException { if (updateToken == null) { @@ -699,6 +715,45 @@ public class RecoverySystem { } } + /** + * Query if Resume on Reboot has been prepared for a given caller. + * + * @param context the Context to use. + * @throws IOException if there were any errors connecting to the service or querying the state. + * @hide + */ + @SystemApi + @RequiresPermission(anyOf = {android.Manifest.permission.RECOVERY, + android.Manifest.permission.REBOOT}) + public static boolean isPreparedForUnattendedUpdate(@NonNull Context context) + throws IOException { + RecoverySystem rs = context.getSystemService(RecoverySystem.class); + return rs.isLskfCaptured(context.getPackageName()); + } + + /** + * Request that the device reboot and apply the update that has been prepared. + * {@link #prepareForUnattendedUpdate} must be called before for the given client, + * otherwise the function call will fail. + * + * @param context the Context to use. + * @param reason the reboot reason to give to the {@link PowerManager} + * @param slotSwitch true if the caller intends to switch the slot on an A/B device. + * @throws IOException if the reboot couldn't proceed because the device wasn't ready for an + * unattended reboot. + * @hide + */ + @SystemApi + @RequiresPermission(anyOf = {android.Manifest.permission.RECOVERY, + android.Manifest.permission.REBOOT}) + public static void rebootAndApply(@NonNull Context context, + @NonNull String reason, boolean slotSwitch) throws IOException { + RecoverySystem rs = context.getSystemService(RecoverySystem.class); + if (!rs.rebootWithLskf(context.getPackageName(), reason, slotSwitch)) { + throw new IOException("system not prepared to apply update"); + } + } + /** * Schedule to install the given package on next boot. The caller needs to ensure that the * package must have been processed (uncrypt'd) if needed. It sets up the command in BCB @@ -1278,7 +1333,7 @@ public class RecoverySystem { /** * Begins the process of asking the user for the Lock Screen Knowledge Factor. * - * @param packageName the package name of the caller who requests resume on reboot + * @param packageName the package name of the caller who requests Resume on Reboot * @return true if the request was correct * @throws IOException if the recovery system service could not be contacted */ @@ -1305,10 +1360,10 @@ public class RecoverySystem { } /** - * Queries if the resume on reboot has been prepared for a given caller. + * Queries if the Resume on Reboot has been prepared for a given caller. * - * @param packageName the identifier of the caller who requests resume on reboot - * @return true if resume on reboot is prepared. + * @param packageName the identifier of the caller who requests Resume on Reboot + * @return true if Resume on Reboot is prepared. * @throws IOException if the recovery system service could not be contacted */ private boolean isLskfCaptured(String packageName) throws IOException {