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