summaryrefslogtreecommitdiffstats
path: root/services/core/java/com/android/server/MasterClearReceiver.java
diff options
context:
space:
mode:
authorRubin Xu <rubinxu@google.com>2015-06-25 12:17:48 +0100
committerRubin Xu <rubinxu@google.com>2015-06-26 15:58:21 +0100
commite8490f1d78a62826742ddf4af8943e6666a1a8d0 (patch)
tree154d2a3a6a7cb94fa8b5e088f51b464cce4d560f /services/core/java/com/android/server/MasterClearReceiver.java
parent729ffa299ca786eb21ba8330096b33c7bcd66fbf (diff)
downloadframeworks_base-e8490f1d78a62826742ddf4af8943e6666a1a8d0.zip
frameworks_base-e8490f1d78a62826742ddf4af8943e6666a1a8d0.tar.gz
frameworks_base-e8490f1d78a62826742ddf4af8943e6666a1a8d0.tar.bz2
Use StorageManager.wipeAdoptableDisks to wipe external disks
Retire FORMAT_AND_FACTORY_RESET which is more fragile. Bug: 9433509 Change-Id: I158ee987274bb4db41d466de9f1e3c60ffc1d140
Diffstat (limited to 'services/core/java/com/android/server/MasterClearReceiver.java')
-rw-r--r--services/core/java/com/android/server/MasterClearReceiver.java52
1 files changed, 51 insertions, 1 deletions
diff --git a/services/core/java/com/android/server/MasterClearReceiver.java b/services/core/java/com/android/server/MasterClearReceiver.java
index f1d5aa3..1653db9 100644
--- a/services/core/java/com/android/server/MasterClearReceiver.java
+++ b/services/core/java/com/android/server/MasterClearReceiver.java
@@ -16,12 +16,18 @@
package com.android.server;
+import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
+import android.os.AsyncTask;
import android.os.RecoverySystem;
+import android.os.storage.StorageManager;
import android.util.Log;
import android.util.Slog;
+import android.view.WindowManager;
+
+import com.android.internal.R;
import java.io.IOException;
@@ -39,6 +45,8 @@ public class MasterClearReceiver extends BroadcastReceiver {
final boolean shutdown = intent.getBooleanExtra("shutdown", false);
final String reason = intent.getStringExtra(Intent.EXTRA_REASON);
+ final boolean wipeExternalStorage = intent.getBooleanExtra(
+ Intent.EXTRA_WIPE_EXTERNAL_STORAGE, false);
Slog.w(TAG, "!!! FACTORY RESET !!!");
// The reboot call is blocking, so we need to do it on another thread.
@@ -55,6 +63,48 @@ public class MasterClearReceiver extends BroadcastReceiver {
}
}
};
- thr.start();
+
+ if (wipeExternalStorage) {
+ // thr will be started at the end of this task.
+ new WipeAdoptableDisksTask(context, thr).execute();
+ } else {
+ thr.start();
+ }
+ }
+
+ private class WipeAdoptableDisksTask extends AsyncTask<Void, Void, Void> {
+ private final Thread mChainedTask;
+ private final Context mContext;
+ private final ProgressDialog mProgressDialog;
+
+ public WipeAdoptableDisksTask(Context context, Thread chainedTask) {
+ mContext = context;
+ mChainedTask = chainedTask;
+ mProgressDialog = new ProgressDialog(context);
+ }
+
+ @Override
+ protected void onPreExecute() {
+ mProgressDialog.setIndeterminate(true);
+ mProgressDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
+ mProgressDialog.setMessage(mContext.getText(R.string.progress_erasing));
+ mProgressDialog.show();
+ }
+
+ @Override
+ protected Void doInBackground(Void... params) {
+ Slog.w(TAG, "Wiping adoptable disks");
+ StorageManager sm = (StorageManager) mContext.getSystemService(
+ Context.STORAGE_SERVICE);
+ sm.wipeAdoptableDisks();
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(Void result) {
+ mProgressDialog.dismiss();
+ mChainedTask.start();
+ }
+
}
}