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; |
Russell Brenner | de4fc8e | 2015-11-05 16:03:20 -0800 | [diff] [blame^] | 23 | import android.provider.Settings; |
Andres Morales | 7ab8929 | 2014-07-10 16:10:43 -0700 | [diff] [blame] | 24 | import android.service.persistentdata.PersistentDataBlockManager; |
Julia Reynolds | ce25af4 | 2015-07-08 16:56:31 -0400 | [diff] [blame] | 25 | |
Chris Wren | 8a963ba | 2015-03-20 10:29:14 -0400 | [diff] [blame] | 26 | import com.android.internal.logging.MetricsLogger; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 27 | |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 28 | import android.content.Intent; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 29 | import android.os.Bundle; |
Julia Reynolds | 2c53933 | 2014-06-11 12:56:02 -0400 | [diff] [blame] | 30 | import android.os.UserManager; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 31 | import android.view.LayoutInflater; |
| 32 | import android.view.View; |
| 33 | import android.view.ViewGroup; |
| 34 | import android.widget.Button; |
Julia Reynolds | ce25af4 | 2015-07-08 16:56:31 -0400 | [diff] [blame] | 35 | import android.widget.TextView; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 36 | |
| 37 | /** |
| 38 | * Confirm and execute a reset of the device to a clean "just out of the box" |
| 39 | * state. Multiple confirmations are required: first, a general "are you sure |
| 40 | * you want to do this?" prompt, followed by a keyguard pattern trace if the user |
| 41 | * has defined one, followed by a final strongly-worded "THIS WILL ERASE EVERYTHING |
| 42 | * ON THE PHONE" prompt. If at any time the phone is allowed to go to sleep, is |
| 43 | * locked, et cetera, then the confirmation sequence is abandoned. |
| 44 | * |
| 45 | * This is the confirmation screen. |
| 46 | */ |
Chris Wren | 8a963ba | 2015-03-20 10:29:14 -0400 | [diff] [blame] | 47 | public class MasterClearConfirm extends InstrumentedFragment { |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 48 | |
| 49 | private View mContentView; |
| 50 | private boolean mEraseSdCard; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 51 | |
| 52 | /** |
| 53 | * The user has gone through the multiple confirmation, so now we go ahead |
| 54 | * and invoke the Checkin Service to reset the device to its factory-default |
| 55 | * state (rebooting in the process). |
| 56 | */ |
| 57 | private Button.OnClickListener mFinalClickListener = new Button.OnClickListener() { |
| 58 | |
| 59 | public void onClick(View v) { |
| 60 | if (Utils.isMonkeyRunning()) { |
| 61 | return; |
| 62 | } |
| 63 | |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 64 | final PersistentDataBlockManager pdbManager = (PersistentDataBlockManager) |
Andres Morales | 7ab8929 | 2014-07-10 16:10:43 -0700 | [diff] [blame] | 65 | getActivity().getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE); |
| 66 | |
Russell Brenner | de4fc8e | 2015-11-05 16:03:20 -0800 | [diff] [blame^] | 67 | if (pdbManager != null && !pdbManager.getOemUnlockEnabled() && |
| 68 | Settings.Global.getInt(getActivity().getContentResolver(), |
| 69 | Settings.Global.DEVICE_PROVISIONED, 0) != 0) { |
| 70 | // if OEM unlock is enabled, this will be wiped during FR process. If disabled, it |
| 71 | // will be wiped here, unless the device is still being provisioned, in which case |
| 72 | // the persistent data block will be preserved. |
Andres Morales | e6bf2a5 | 2014-09-08 13:14:00 -0700 | [diff] [blame] | 73 | new AsyncTask<Void, Void, Void>() { |
Andres Morales | c17ec1b | 2015-06-01 16:23:41 -0700 | [diff] [blame] | 74 | int mOldOrientation; |
| 75 | ProgressDialog mProgressDialog; |
| 76 | |
Andres Morales | e6bf2a5 | 2014-09-08 13:14:00 -0700 | [diff] [blame] | 77 | @Override |
| 78 | protected Void doInBackground(Void... params) { |
| 79 | pdbManager.wipe(); |
| 80 | return null; |
| 81 | } |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 82 | |
Andres Morales | e6bf2a5 | 2014-09-08 13:14:00 -0700 | [diff] [blame] | 83 | @Override |
| 84 | protected void onPostExecute(Void aVoid) { |
Andres Morales | c17ec1b | 2015-06-01 16:23:41 -0700 | [diff] [blame] | 85 | mProgressDialog.hide(); |
| 86 | getActivity().setRequestedOrientation(mOldOrientation); |
Andres Morales | e6bf2a5 | 2014-09-08 13:14:00 -0700 | [diff] [blame] | 87 | doMasterClear(); |
| 88 | } |
Andres Morales | c17ec1b | 2015-06-01 16:23:41 -0700 | [diff] [blame] | 89 | |
| 90 | @Override |
| 91 | protected void onPreExecute() { |
| 92 | mProgressDialog = getProgressDialog(); |
| 93 | mProgressDialog.show(); |
| 94 | |
| 95 | // need to prevent orientation changes as we're about to go into |
| 96 | // a long IO request, so we won't be able to access inflate resources on flash |
| 97 | mOldOrientation = getActivity().getRequestedOrientation(); |
| 98 | getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED); |
| 99 | } |
Andres Morales | e6bf2a5 | 2014-09-08 13:14:00 -0700 | [diff] [blame] | 100 | }.execute(); |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 101 | } else { |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 102 | doMasterClear(); |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 103 | } |
| 104 | } |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 105 | |
| 106 | private ProgressDialog getProgressDialog() { |
| 107 | final ProgressDialog progressDialog = new ProgressDialog(getActivity()); |
| 108 | progressDialog.setIndeterminate(true); |
| 109 | progressDialog.setCancelable(false); |
| 110 | progressDialog.setTitle( |
| 111 | getActivity().getString(R.string.master_clear_progress_title)); |
| 112 | progressDialog.setMessage( |
| 113 | getActivity().getString(R.string.master_clear_progress_text)); |
| 114 | return progressDialog; |
| 115 | } |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 116 | }; |
| 117 | |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 118 | private void doMasterClear() { |
Rubin Xu | ccbdc57 | 2015-06-26 15:27:23 +0100 | [diff] [blame] | 119 | Intent intent = new Intent(Intent.ACTION_MASTER_CLEAR); |
| 120 | intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); |
| 121 | intent.putExtra(Intent.EXTRA_REASON, "MasterClearConfirm"); |
| 122 | intent.putExtra(Intent.EXTRA_WIPE_EXTERNAL_STORAGE, mEraseSdCard); |
| 123 | getActivity().sendBroadcast(intent); |
| 124 | // Intent handling is asynchronous -- assume it will happen soon. |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 127 | /** |
| 128 | * Configure the UI for the final confirmation interaction |
| 129 | */ |
| 130 | private void establishFinalConfirmationState() { |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 131 | mContentView.findViewById(R.id.execute_master_clear) |
| 132 | .setOnClickListener(mFinalClickListener); |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | @Override |
| 136 | public View onCreateView(LayoutInflater inflater, ViewGroup container, |
| 137 | Bundle savedInstanceState) { |
Julia Reynolds | 2c53933 | 2014-06-11 12:56:02 -0400 | [diff] [blame] | 138 | if (UserManager.get(getActivity()).hasUserRestriction( |
| 139 | UserManager.DISALLOW_FACTORY_RESET)) { |
| 140 | return inflater.inflate(R.layout.master_clear_disallowed_screen, null); |
| 141 | } |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 142 | mContentView = inflater.inflate(R.layout.master_clear_confirm, null); |
| 143 | establishFinalConfirmationState(); |
Julia Reynolds | ce25af4 | 2015-07-08 16:56:31 -0400 | [diff] [blame] | 144 | setAccessibilityTitle(); |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 145 | return mContentView; |
| 146 | } |
| 147 | |
Julia Reynolds | ce25af4 | 2015-07-08 16:56:31 -0400 | [diff] [blame] | 148 | private void setAccessibilityTitle() { |
| 149 | CharSequence currentTitle = getActivity().getTitle(); |
| 150 | TextView confirmationMessage = |
| 151 | (TextView) mContentView.findViewById(R.id.master_clear_confirm); |
| 152 | if (confirmationMessage != null) { |
| 153 | String accessibileText = new StringBuilder(currentTitle).append(",").append( |
| 154 | confirmationMessage.getText()).toString(); |
| 155 | getActivity().setTitle(Utils.createAccessibleSequence(currentTitle, accessibileText)); |
| 156 | } |
| 157 | } |
| 158 | |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 159 | @Override |
| 160 | public void onCreate(Bundle savedInstanceState) { |
| 161 | super.onCreate(savedInstanceState); |
| 162 | |
| 163 | Bundle args = getArguments(); |
Andres Morales | c17ec1b | 2015-06-01 16:23:41 -0700 | [diff] [blame] | 164 | mEraseSdCard = args != null |
| 165 | && args.getBoolean(MasterClear.ERASE_EXTERNAL_EXTRA); |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 166 | } |
Chris Wren | 8a963ba | 2015-03-20 10:29:14 -0400 | [diff] [blame] | 167 | |
| 168 | @Override |
| 169 | protected int getMetricsCategory() { |
| 170 | return MetricsLogger.MASTER_CLEAR_CONFIRM; |
| 171 | } |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 172 | } |