Skip to content

Commit fe05380

Browse files
author
Julia Reynolds
committed
Restrict factory reset with user restrictions.
Bug: 15985879 Change-Id: I524bd8a790798a85a679aa195e634f6e0227d09f
1 parent 63c2d7d commit fe05380

3 files changed

Lines changed: 11 additions & 0 deletions

File tree

core/java/android/os/RecoverySystem.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import android.content.BroadcastReceiver;
2020
import android.content.Context;
2121
import android.content.Intent;
22+
import android.os.UserManager;
2223
import android.util.Log;
2324

2425
import java.io.ByteArrayInputStream;
@@ -348,6 +349,7 @@ public static void installPackage(Context context, File packageFile)
348349
*
349350
* @throws IOException if writing the recovery command file
350351
* fails, or if the reboot itself fails.
352+
* @throws SecurityException if the current user is not allowed to wipe data.
351353
*/
352354
public static void rebootWipeUserData(Context context) throws IOException {
353355
rebootWipeUserData(context, false);
@@ -367,11 +369,16 @@ public static void rebootWipeUserData(Context context) throws IOException {
367369
*
368370
* @throws IOException if writing the recovery command file
369371
* fails, or if the reboot itself fails.
372+
* @throws SecurityException if the current user is not allowed to wipe data.
370373
*
371374
* @hide
372375
*/
373376
public static void rebootWipeUserData(Context context, boolean shutdown)
374377
throws IOException {
378+
UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
379+
if (um.hasUserRestriction(UserManager.DISALLOW_FACTORY_RESET)) {
380+
throw new SecurityException("Wiping data is not allowed for this user.");
381+
}
375382
final ConditionVariable condition = new ConditionVariable();
376383

377384
Intent intent = new Intent("android.intent.action.MASTER_CLEAR_NOTIFICATION");

services/core/java/com/android/server/MasterClearReceiver.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public void run() {
4949
Log.wtf(TAG, "Still running after master clear?!");
5050
} catch (IOException e) {
5151
Slog.e(TAG, "Can't perform master clear/factory reset", e);
52+
} catch (SecurityException e) {
53+
Slog.e(TAG, "Can't perform master clear/factory reset", e);
5254
}
5355
}
5456
};

services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2480,6 +2480,8 @@ void wipeDataLocked(int flags) {
24802480
RecoverySystem.rebootWipeUserData(mContext);
24812481
} catch (IOException e) {
24822482
Slog.w(LOG_TAG, "Failed requesting data wipe", e);
2483+
} catch (SecurityException e) {
2484+
Slog.w(LOG_TAG, "Failed requesting data wipe", e);
24832485
}
24842486
}
24852487
}

0 commit comments

Comments
 (0)