/** {@hide} */
public static final String EXTRA_REASON = "android.intent.extra.REASON";
+ /** {@hide} */
+ public static final String EXTRA_WIPE_EXTERNAL_STORAGE = "android.intent.extra.WIPE_EXTERNAL_STORAGE";
+
/**
* Optional {@link android.app.PendingIntent} extra used to deliver the result of the SIM
* activation request.
/**
* Takes care of unmounting and formatting external storage.
+ *
+ * @deprecated Please use {@link Intent#ACTION_MASTER_CLEAR} broadcast with extra
+ * {@link Intent#EXTRA_WIPE_EXTERNAL_STORAGE} to wipe and factory reset, or call
+ * {@link StorageManager#wipeAdoptableDisks} directly to format external storages.
*/
public class ExternalStorageFormatter extends Service {
static final String TAG = "ExternalStorageFormatter";
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;
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.
}
}
};
- 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();
+ }
+
}
}
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
+import android.os.storage.StorageManager;
import android.provider.ContactsContract.QuickContact;
import android.provider.ContactsInternal;
import android.provider.Settings;
import android.view.inputmethod.InputMethodManager;
import com.android.internal.R;
-import com.android.internal.os.storage.ExternalStorageFormatter;
import com.android.internal.statusbar.IStatusBarService;
import com.android.internal.util.FastXmlSerializer;
import com.android.internal.util.JournaledFile;
}
private void wipeDataLocked(boolean wipeExtRequested, String reason) {
- // TODO: wipe all public volumes on device
-
- // If the SD card is encrypted and non-removable, we have to force a wipe.
- boolean forceExtWipe = !Environment.isExternalStorageRemovable() && isExtStorageEncrypted();
-
- // Note: we can only do the wipe via ExternalStorageFormatter if the volume is not emulated.
- if ((forceExtWipe || wipeExtRequested) && !Environment.isExternalStorageEmulated()) {
- Intent intent = new Intent(ExternalStorageFormatter.FORMAT_AND_FACTORY_RESET);
- intent.putExtra(ExternalStorageFormatter.EXTRA_ALWAYS_RESET, true);
- intent.putExtra(Intent.EXTRA_REASON, reason);
- intent.setComponent(ExternalStorageFormatter.COMPONENT_NAME);
- mWakeLock.acquire(10000);
- mContext.startService(intent);
- } else {
- try {
- RecoverySystem.rebootWipeUserData(mContext, reason);
- } catch (IOException | SecurityException e) {
- Slog.w(LOG_TAG, "Failed requesting data wipe", e);
- }
+ if (wipeExtRequested) {
+ StorageManager sm = (StorageManager) mContext.getSystemService(
+ Context.STORAGE_SERVICE);
+ sm.wipeAdoptableDisks();
+ }
+ try {
+ RecoverySystem.rebootWipeUserData(mContext, reason);
+ } catch (IOException | SecurityException e) {
+ Slog.w(LOG_TAG, "Failed requesting data wipe", e);
}
}