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