Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.settings; |
| 18 | |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 19 | import android.app.ProgressDialog; |
Andres Morales | 7ab8929 | 2014-07-10 16:10:43 -0700 | [diff] [blame] | 20 | import android.content.Context; |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 21 | import android.content.pm.ActivityInfo; |
| 22 | import android.os.AsyncTask; |
Andres Morales | 7ab8929 | 2014-07-10 16:10:43 -0700 | [diff] [blame] | 23 | import android.service.persistentdata.PersistentDataBlockManager; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 24 | import com.android.internal.os.storage.ExternalStorageFormatter; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 25 | |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 26 | import android.app.Fragment; |
| 27 | import android.content.Intent; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 28 | import android.os.Bundle; |
Julia Reynolds | 2c53933 | 2014-06-11 12:56:02 -0400 | [diff] [blame] | 29 | import android.os.UserManager; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 30 | import android.view.LayoutInflater; |
| 31 | import android.view.View; |
| 32 | import android.view.ViewGroup; |
| 33 | import android.widget.Button; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * Confirm and execute a reset of the device to a clean "just out of the box" |
| 37 | * state. Multiple confirmations are required: first, a general "are you sure |
| 38 | * you want to do this?" prompt, followed by a keyguard pattern trace if the user |
| 39 | * has defined one, followed by a final strongly-worded "THIS WILL ERASE EVERYTHING |
| 40 | * ON THE PHONE" prompt. If at any time the phone is allowed to go to sleep, is |
| 41 | * locked, et cetera, then the confirmation sequence is abandoned. |
| 42 | * |
| 43 | * This is the confirmation screen. |
| 44 | */ |
| 45 | public class MasterClearConfirm extends Fragment { |
| 46 | |
| 47 | private View mContentView; |
| 48 | private boolean mEraseSdCard; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 49 | |
| 50 | /** |
| 51 | * The user has gone through the multiple confirmation, so now we go ahead |
| 52 | * and invoke the Checkin Service to reset the device to its factory-default |
| 53 | * state (rebooting in the process). |
| 54 | */ |
| 55 | private Button.OnClickListener mFinalClickListener = new Button.OnClickListener() { |
| 56 | |
| 57 | public void onClick(View v) { |
| 58 | if (Utils.isMonkeyRunning()) { |
| 59 | return; |
| 60 | } |
| 61 | |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 62 | final PersistentDataBlockManager pdbManager = (PersistentDataBlockManager) |
Andres Morales | 7ab8929 | 2014-07-10 16:10:43 -0700 | [diff] [blame] | 63 | getActivity().getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE); |
| 64 | |
| 65 | if (pdbManager != null) { |
Andres Morales | ae58323 | 2014-08-06 17:01:19 -0700 | [diff] [blame] | 66 | // if OEM unlock is enabled, this will be wiped during FR process. |
| 67 | if (!pdbManager.getOemUnlockEnabled()) { |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 68 | final ProgressDialog progressDialog = getProgressDialog(); |
| 69 | progressDialog.show(); |
Andres Morales | 7ab8929 | 2014-07-10 16:10:43 -0700 | [diff] [blame] | 70 | |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 71 | // need to prevent orientation changes as we're about to go into |
| 72 | // a long IO request, so we won't be able to access inflate resources on flash |
| 73 | final int oldOrientation = getActivity().getRequestedOrientation(); |
| 74 | getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED); |
| 75 | new AsyncTask<Void, Void, Void>() { |
| 76 | @Override |
| 77 | protected Void doInBackground(Void... params) { |
| 78 | pdbManager.wipe(); |
| 79 | return null; |
| 80 | } |
| 81 | |
| 82 | @Override |
| 83 | protected void onPostExecute(Void aVoid) { |
| 84 | progressDialog.hide(); |
| 85 | getActivity().setRequestedOrientation(oldOrientation); |
| 86 | doMasterClear(); |
| 87 | } |
| 88 | }.execute(); |
| 89 | } |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 90 | } else { |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 91 | doMasterClear(); |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 92 | } |
| 93 | } |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 94 | |
| 95 | private ProgressDialog getProgressDialog() { |
| 96 | final ProgressDialog progressDialog = new ProgressDialog(getActivity()); |
| 97 | progressDialog.setIndeterminate(true); |
| 98 | progressDialog.setCancelable(false); |
| 99 | progressDialog.setTitle( |
| 100 | getActivity().getString(R.string.master_clear_progress_title)); |
| 101 | progressDialog.setMessage( |
| 102 | getActivity().getString(R.string.master_clear_progress_text)); |
| 103 | return progressDialog; |
| 104 | } |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 105 | }; |
| 106 | |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 107 | private void doMasterClear() { |
| 108 | if (mEraseSdCard) { |
| 109 | Intent intent = new Intent(ExternalStorageFormatter.FORMAT_AND_FACTORY_RESET); |
| 110 | intent.setComponent(ExternalStorageFormatter.COMPONENT_NAME); |
| 111 | getActivity().startService(intent); |
| 112 | } else { |
| 113 | getActivity().sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR")); |
| 114 | // Intent handling is asynchronous -- assume it will happen soon. |
| 115 | } |
| 116 | } |
| 117 | |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 118 | /** |
| 119 | * Configure the UI for the final confirmation interaction |
| 120 | */ |
| 121 | private void establishFinalConfirmationState() { |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 122 | mContentView.findViewById(R.id.execute_master_clear) |
| 123 | .setOnClickListener(mFinalClickListener); |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | @Override |
| 127 | public View onCreateView(LayoutInflater inflater, ViewGroup container, |
| 128 | Bundle savedInstanceState) { |
Julia Reynolds | 2c53933 | 2014-06-11 12:56:02 -0400 | [diff] [blame] | 129 | if (UserManager.get(getActivity()).hasUserRestriction( |
| 130 | UserManager.DISALLOW_FACTORY_RESET)) { |
| 131 | return inflater.inflate(R.layout.master_clear_disallowed_screen, null); |
| 132 | } |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 133 | mContentView = inflater.inflate(R.layout.master_clear_confirm, null); |
| 134 | establishFinalConfirmationState(); |
| 135 | return mContentView; |
| 136 | } |
| 137 | |
| 138 | @Override |
| 139 | public void onCreate(Bundle savedInstanceState) { |
| 140 | super.onCreate(savedInstanceState); |
| 141 | |
| 142 | Bundle args = getArguments(); |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 143 | mEraseSdCard = args != null && args.getBoolean(MasterClear.ERASE_EXTERNAL_EXTRA); |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 144 | } |
| 145 | } |