am d1858a7d: am 0a202eac: Merge "Use StorageManager.wipeAdoptableDisks to wipe external disks" into mnc-dev

* commit 'd1858a7d3e648f6c7382bba5bd3982a7ecc15257':
  Use StorageManager.wipeAdoptableDisks to wipe external disks
This commit is contained in:
Rubin Xu
2015-06-26 22:54:50 +00:00
committed by Android Git Automerger
4 changed files with 68 additions and 21 deletions

View File

@@ -3784,6 +3784,9 @@ public class Intent implements Parcelable, Cloneable {
/** {@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.

View File

@@ -17,6 +17,10 @@ import com.android.internal.R;
/**
* 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";

View File

@@ -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();
}
}
}

View File

@@ -85,6 +85,7 @@ import android.os.SystemClock;
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;
@@ -108,7 +109,6 @@ import android.view.inputmethod.InputMethodInfo;
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;
@@ -3307,25 +3307,15 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
}
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);
}
}