Throw up ProgressDialog when erasing PST partition

This needs to be done here, but we should let the user know
we're doing work.

Bug: 17185720
Change-Id: I0d71ae38145e0649a430a8231b7e3f250c003ee8
This commit is contained in:
Andres Morales
2014-08-26 13:54:12 -07:00
parent 8dade422e5
commit ab61b0df4a
2 changed files with 55 additions and 18 deletions

View File

@@ -2493,6 +2493,10 @@
<string name="master_clear_confirm_title">Reset?</string> <string name="master_clear_confirm_title">Reset?</string>
<!-- Error message for users that aren't allowed to factory reset [CHAR LIMIT=none] --> <!-- Error message for users that aren't allowed to factory reset [CHAR LIMIT=none] -->
<string name="master_clear_not_available">Factory reset is not available for this user</string> <string name="master_clear_not_available">Factory reset is not available for this user</string>
<!-- Master clear progress screen title [CHAR LIMIT=30] -->
<string name="master_clear_progress_title" >Erasing</string>
<!-- Master clear progress screen text [CHAR LIMIT=75] -->
<string name="master_clear_progress_text">Please wait...</string>
<!-- Media Format --> <!-- Media Format -->
<!-- SD card & phone storage settings screen, setting option name under Internal phone storage heading [CHAR LIMIT=25] --> <!-- SD card & phone storage settings screen, setting option name under Internal phone storage heading [CHAR LIMIT=25] -->

View File

@@ -16,22 +16,21 @@
package com.android.settings; package com.android.settings;
import android.app.ProgressDialog;
import android.content.Context; import android.content.Context;
import android.content.pm.ActivityInfo;
import android.os.AsyncTask;
import android.service.persistentdata.PersistentDataBlockManager; import android.service.persistentdata.PersistentDataBlockManager;
import com.android.internal.os.storage.ExternalStorageFormatter; import com.android.internal.os.storage.ExternalStorageFormatter;
import com.android.internal.widget.LockPatternUtils;
import android.app.Activity;
import android.app.Fragment; import android.app.Fragment;
import android.content.Intent; import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
import android.os.UserManager; import android.os.UserManager;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox;
/** /**
* Confirm and execute a reset of the device to a clean "just out of the box" * Confirm and execute a reset of the device to a clean "just out of the box"
@@ -47,7 +46,6 @@ public class MasterClearConfirm extends Fragment {
private View mContentView; private View mContentView;
private boolean mEraseSdCard; private boolean mEraseSdCard;
private Button mFinalButton;
/** /**
* The user has gone through the multiple confirmation, so now we go ahead * The user has gone through the multiple confirmation, so now we go ahead
@@ -61,33 +59,68 @@ public class MasterClearConfirm extends Fragment {
return; return;
} }
PersistentDataBlockManager pdbManager = (PersistentDataBlockManager) final PersistentDataBlockManager pdbManager = (PersistentDataBlockManager)
getActivity().getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE); getActivity().getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
if (pdbManager != null) { if (pdbManager != null) {
// if OEM unlock is enabled, this will be wiped during FR process. // if OEM unlock is enabled, this will be wiped during FR process.
if (!pdbManager.getOemUnlockEnabled()) { if (!pdbManager.getOemUnlockEnabled()) {
pdbManager.wipe(); final ProgressDialog progressDialog = getProgressDialog();
} progressDialog.show();
}
if (mEraseSdCard) { // need to prevent orientation changes as we're about to go into
Intent intent = new Intent(ExternalStorageFormatter.FORMAT_AND_FACTORY_RESET); // a long IO request, so we won't be able to access inflate resources on flash
intent.setComponent(ExternalStorageFormatter.COMPONENT_NAME); final int oldOrientation = getActivity().getRequestedOrientation();
getActivity().startService(intent); getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
pdbManager.wipe();
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
progressDialog.hide();
getActivity().setRequestedOrientation(oldOrientation);
doMasterClear();
}
}.execute();
}
} else { } else {
getActivity().sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR")); doMasterClear();
// Intent handling is asynchronous -- assume it will happen soon.
} }
} }
private ProgressDialog getProgressDialog() {
final ProgressDialog progressDialog = new ProgressDialog(getActivity());
progressDialog.setIndeterminate(true);
progressDialog.setCancelable(false);
progressDialog.setTitle(
getActivity().getString(R.string.master_clear_progress_title));
progressDialog.setMessage(
getActivity().getString(R.string.master_clear_progress_text));
return progressDialog;
}
}; };
private void doMasterClear() {
if (mEraseSdCard) {
Intent intent = new Intent(ExternalStorageFormatter.FORMAT_AND_FACTORY_RESET);
intent.setComponent(ExternalStorageFormatter.COMPONENT_NAME);
getActivity().startService(intent);
} else {
getActivity().sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR"));
// Intent handling is asynchronous -- assume it will happen soon.
}
}
/** /**
* Configure the UI for the final confirmation interaction * Configure the UI for the final confirmation interaction
*/ */
private void establishFinalConfirmationState() { private void establishFinalConfirmationState() {
mFinalButton = (Button) mContentView.findViewById(R.id.execute_master_clear); mContentView.findViewById(R.id.execute_master_clear)
mFinalButton.setOnClickListener(mFinalClickListener); .setOnClickListener(mFinalClickListener);
} }
@Override @Override
@@ -107,6 +140,6 @@ public class MasterClearConfirm extends Fragment {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Bundle args = getArguments(); Bundle args = getArguments();
mEraseSdCard = args != null ? args.getBoolean(MasterClear.ERASE_EXTERNAL_EXTRA) : false; mEraseSdCard = args != null && args.getBoolean(MasterClear.ERASE_EXTERNAL_EXTRA);
} }
} }