diff --git a/core/java/android/os/ICheckinService.aidl b/core/java/android/os/ICheckinService.aidl index e56b55d78cd51..5bb399282a27c 100644 --- a/core/java/android/os/ICheckinService.aidl +++ b/core/java/android/os/ICheckinService.aidl @@ -44,6 +44,9 @@ interface ICheckinService { /** Reboot into the recovery system and wipe all user data. */ void masterClear(); + /** Reboot into the recovery system, wipe all user data and enable Encrypted File Systems. */ + void masterClearAndToggleEFS(boolean efsEnabled); + /** * Determine if the device is under parental control. Return null if * we are unable to check the parental control status. diff --git a/core/java/com/android/internal/os/RecoverySystem.java b/core/java/com/android/internal/os/RecoverySystem.java index c938610b612e5..3aca683ebcc28 100644 --- a/core/java/com/android/internal/os/RecoverySystem.java +++ b/core/java/com/android/internal/os/RecoverySystem.java @@ -74,6 +74,21 @@ public class RecoverySystem { bootCommand("--wipe_data"); } + /** + * Reboot into the recovery system to wipe the /data partition and toggle + * Encrypted File Systems on/off. + * @param extras to add to the RECOVERY_COMPLETED intent after rebooting. + * @throws IOException if something goes wrong. + * @hide + */ + public static void rebootAndToggleEFS(boolean efsEnabled) throws IOException { + if (efsEnabled) { + bootCommand("--set_encrypted_filesystem=on"); + } else { + bootCommand("--set_encrypted_filesystem=off"); + } + } + /** * Reboot into the recovery system with the supplied argument. * @param arg to pass to the recovery utility. diff --git a/services/java/com/android/server/FallbackCheckinService.java b/services/java/com/android/server/FallbackCheckinService.java index cf224466e7650..32c15e944757a 100644 --- a/services/java/com/android/server/FallbackCheckinService.java +++ b/services/java/com/android/server/FallbackCheckinService.java @@ -66,6 +66,23 @@ public final class FallbackCheckinService extends ICheckinService.Stub { } } + public void masterClearAndToggleEFS(boolean efsEnabled) { + if (mContext.checkCallingOrSelfPermission("android.permission.MASTER_CLEAR") != + PackageManager.PERMISSION_GRANTED) { + Log.e(TAG, "Permission Denial: can't invoke masterClearAndToggleEFS from " + + "pid=" + Binder.getCallingPid() + ", " + + "uid=" + Binder.getCallingUid()); + return; + } + + // Save the android ID so the new system can get it erased. + try { + RecoverySystem.rebootAndToggleEFS(efsEnabled); + } catch (IOException e) { + Log.e(TAG, "Reboot for toggle EFS failed", e); + } + } + public void getParentalControlState(IParentalControlCallback p, String requestingApp) throws android.os.RemoteException { ParentalControlState state = new ParentalControlState();