From 2a32192329ac47da1e64f7085f4317212e99a3bf Mon Sep 17 00:00:00 2001 From: Ben Komalo Date: Wed, 7 Sep 2011 16:42:34 -0700 Subject: [PATCH] Force storage wipe if not removable and encrypted Bug: 5017638 Change-Id: I43c98359eff7202437249675060ba964e1bd085c --- src/com/android/settings/MasterClear.java | 21 ++++++++++++++++----- src/com/android/settings/deviceinfo/Memory.java | 8 ++++---- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/com/android/settings/MasterClear.java b/src/com/android/settings/MasterClear.java index 29a92b106b..39b17a9f94 100644 --- a/src/com/android/settings/MasterClear.java +++ b/src/com/android/settings/MasterClear.java @@ -16,8 +16,6 @@ package com.android.settings; -import com.android.settings.R; - import android.accounts.Account; import android.accounts.AccountManager; import android.accounts.AuthenticatorDescription; @@ -30,6 +28,7 @@ import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.Environment; +import android.os.SystemProperties; import android.preference.Preference; import android.preference.PreferenceActivity; import android.util.Log; @@ -107,7 +106,7 @@ public class MasterClear extends Fragment { * keyguard confirmation if the user has currently enabled one. If there * is no keyguard available, we simply go to the final confirmation prompt. */ - private Button.OnClickListener mInitiateListener = new Button.OnClickListener() { + private final Button.OnClickListener mInitiateListener = new Button.OnClickListener() { public void onClick(View v) { if (!runKeyguardConfirmation(KEYGUARD_REQUEST)) { @@ -138,9 +137,12 @@ public class MasterClear extends Fragment { * If the external storage is emulated, it will be erased with a factory * reset at any rate. There is no need to have a separate option until * we have a factory reset that only erases some directories and not - * others. + * others. Likewise, if it's non-removable storage, it could potentially have been + * encrypted, and will also need to be wiped. */ - if (Environment.isExternalStorageEmulated()) { + boolean isExtStorageEmulated = Environment.isExternalStorageEmulated(); + if (isExtStorageEmulated + || (!Environment.isExternalStorageRemovable() && isExtStorageEncrypted())) { mExternalStorageContainer.setVisibility(View.GONE); final View externalOption = mContentView.findViewById(R.id.erase_external_option_text); @@ -148,6 +150,10 @@ public class MasterClear extends Fragment { final View externalAlsoErased = mContentView.findViewById(R.id.also_erases_external); externalAlsoErased.setVisibility(View.VISIBLE); + + // If it's not emulated, it is on a separate partition but it means we're doing + // a force wipe due to encryption. + mExternalStorage.setChecked(!isExtStorageEmulated); } else { mExternalStorageContainer.setOnClickListener(new View.OnClickListener() { @@ -161,6 +167,11 @@ public class MasterClear extends Fragment { loadAccountList(); } + private boolean isExtStorageEncrypted() { + String state = SystemProperties.get("vold.decrypt"); + return !"".equals(state); + } + private void loadAccountList() { View accountsLabel = mContentView.findViewById(R.id.accounts_label); LinearLayout contents = (LinearLayout)mContentView.findViewById(R.id.accounts); diff --git a/src/com/android/settings/deviceinfo/Memory.java b/src/com/android/settings/deviceinfo/Memory.java index e257f86997..728e558c5f 100644 --- a/src/com/android/settings/deviceinfo/Memory.java +++ b/src/com/android/settings/deviceinfo/Memory.java @@ -60,7 +60,7 @@ public class Memory extends SettingsPreferenceFragment { // one's preference is disabled private Preference mLastClickedMountToggle; private String mClickedMountPoint; - + // Access using getMountService() private IMountService mMountService = null; @@ -197,7 +197,7 @@ public class Memory extends SettingsPreferenceFragment { } return mMountService; } - + @Override public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { for (int i = 0; i < mStorageVolumePreferenceCategories.length; i++) { @@ -225,7 +225,7 @@ public class Memory extends SettingsPreferenceFragment { return false; } - + private final BroadcastReceiver mMediaScannerReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { @@ -267,7 +267,7 @@ public class Memory extends SettingsPreferenceFragment { mLastClickedMountToggle.setEnabled(false); mLastClickedMountToggle.setTitle(mResources.getString(R.string.sd_ejecting_title)); mLastClickedMountToggle.setSummary(mResources.getString(R.string.sd_ejecting_summary)); - mountService.unmountVolume(mClickedMountPoint, true); + mountService.unmountVolume(mClickedMountPoint, true, false); } catch (RemoteException e) { // Informative dialog to user that unmount failed. showDialogInner(DLG_ERROR_UNMOUNT); -- 2.11.0