diff --git a/api/current.xml b/api/current.xml index 6ab6b61242a44..5611e0d6d1264 100644 --- a/api/current.xml +++ b/api/current.xml @@ -37902,6 +37902,17 @@ visibility="public" > + + + android:permission="android.permission.MASTER_CLEAR" + android:priority="100" > @@ -1399,8 +1400,11 @@ + + + - - diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index 25757a82b90ee..1d2e7804728fb 100755 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -2404,4 +2404,33 @@ Done + + + + Unmounting USB storage... + + Unmounting SD card... + + Erasing USB storage... + + Erasing SD card... + + Failed to erase USB storage. + + Failed to erase SD card. + + SD card was removed before being unmounted. + + USB storage is currently being checked. + + SD card is currently being checked. + + SD card has been removed. + + USB storage is currently in use by a computer. + + SD card is currently in use by a computer. + + External media in unknown state. + diff --git a/services/java/com/android/server/DevicePolicyManagerService.java b/services/java/com/android/server/DevicePolicyManagerService.java index 28126b948942c..081bd30a597c2 100644 --- a/services/java/com/android/server/DevicePolicyManagerService.java +++ b/services/java/com/android/server/DevicePolicyManagerService.java @@ -17,6 +17,7 @@ package com.android.server; import com.android.internal.content.PackageMonitor; +import com.android.internal.os.storage.ExternalStorageFormatter; import com.android.internal.util.FastXmlSerializer; import com.android.internal.util.JournaledFile; import com.android.internal.util.XmlUtils; @@ -42,6 +43,7 @@ import android.content.pm.PackageManager.NameNotFoundException; import android.os.Binder; import android.os.IBinder; import android.os.IPowerManager; +import android.os.PowerManager; import android.os.RecoverySystem; import android.os.RemoteCallback; import android.os.RemoteException; @@ -76,6 +78,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { final Context mContext; final MyPackageMonitor mMonitor; + final PowerManager.WakeLock mWakeLock; IPowerManager mIPowerManager; @@ -343,6 +346,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { mContext = context; mMonitor = new MyPackageMonitor(); mMonitor.register(context, true); + mWakeLock = ((PowerManager)context.getSystemService(Context.POWER_SERVICE)) + .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DPM"); } private IPowerManager getIPowerManager() { @@ -1345,10 +1350,17 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { } void wipeDataLocked(int flags) { - try { - RecoverySystem.rebootWipeUserData(mContext); - } catch (IOException e) { - Slog.w(TAG, "Failed requesting data wipe", e); + if ((flags&DevicePolicyManager.WIPE_EXTERNAL_STORAGE) != 0) { + Intent intent = new Intent(ExternalStorageFormatter.FORMAT_AND_FACTORY_RESET); + intent.setComponent(ExternalStorageFormatter.COMPONENT_NAME); + mWakeLock.acquire(10000); + mContext.startService(intent); + } else { + try { + RecoverySystem.rebootWipeUserData(mContext); + } catch (IOException e) { + Slog.w(TAG, "Failed requesting data wipe", e); + } } } diff --git a/services/java/com/android/server/MasterClearReceiver.java b/services/java/com/android/server/MasterClearReceiver.java index 4d04cee3952d1..bdb5a24f664df 100644 --- a/services/java/com/android/server/MasterClearReceiver.java +++ b/services/java/com/android/server/MasterClearReceiver.java @@ -29,7 +29,7 @@ public class MasterClearReceiver extends BroadcastReceiver { private static final String TAG = "MasterClear"; @Override - public void onReceive(Context context, Intent intent) { + public void onReceive(final Context context, final Intent intent) { if (intent.getAction().equals(Intent.ACTION_REMOTE_INTENT)) { if (!"google.com".equals(intent.getStringExtra("from"))) { Slog.w(TAG, "Ignoring master clear request -- not from trusted server."); @@ -37,16 +37,23 @@ public class MasterClearReceiver extends BroadcastReceiver { } } - try { - Slog.w(TAG, "!!! FACTORY RESET !!!"); - if (intent.hasExtra("enableEFS")) { - RecoverySystem.rebootToggleEFS(context, intent.getBooleanExtra("enableEFS", false)); - } else { - RecoverySystem.rebootWipeUserData(context); + Slog.w(TAG, "!!! FACTORY RESET !!!"); + // The reboot call is blocking, so we need to do it on another thread. + Thread thr = new Thread("Reboot") { + @Override + public void run() { + try { + if (intent.hasExtra("enableEFS")) { + RecoverySystem.rebootToggleEFS(context, intent.getBooleanExtra("enableEFS", false)); + } else { + RecoverySystem.rebootWipeUserData(context); + } + Log.wtf(TAG, "Still running after master clear?!"); + } catch (IOException e) { + Slog.e(TAG, "Can't perform master clear/factory reset", e); + } } - Log.wtf(TAG, "Still running after master clear?!"); - } catch (IOException e) { - Slog.e(TAG, "Can't perform master clear/factory reset", e); - } + }; + thr.start(); } } diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java index 9c2c56204ae5d..b0ace2fcf1b69 100644 --- a/services/java/com/android/server/am/ActivityManagerService.java +++ b/services/java/com/android/server/am/ActivityManagerService.java @@ -7137,6 +7137,9 @@ public final class ActivityManagerService extends ActivityManagerNative if (mHeavyWeightProcess == app) { currApp.flags |= ActivityManager.RunningAppProcessInfo.FLAG_CANT_SAVE_STATE; } + if (app.persistent) { + currApp.flags |= ActivityManager.RunningAppProcessInfo.FLAG_PERSISTENT; + } int adj = app.curAdj; if (adj >= EMPTY_APP_ADJ) { currApp.importance = ActivityManager.RunningAppProcessInfo.IMPORTANCE_EMPTY;