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 | |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 19 | |
Fan Zhang | c7162cd | 2018-06-18 15:21:41 -0700 | [diff] [blame] | 20 | import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; |
| 21 | |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 22 | import android.app.ActionBar; |
| 23 | import android.app.Activity; |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 24 | import android.app.ProgressDialog; |
Fan Zhang | 31b2100 | 2019-01-16 13:49:47 -0800 | [diff] [blame] | 25 | import android.app.settings.SettingsEnums; |
Andres Morales | 7ab8929 | 2014-07-10 16:10:43 -0700 | [diff] [blame] | 26 | import android.content.Context; |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 27 | import android.content.Intent; |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 28 | import android.content.pm.ActivityInfo; |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 29 | import android.graphics.Color; |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 30 | import android.os.AsyncTask; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 31 | import android.os.Bundle; |
Sudheer Shanka | 7dbbe13 | 2016-02-16 14:19:32 +0000 | [diff] [blame] | 32 | import android.os.UserHandle; |
Julia Reynolds | 2c53933 | 2014-06-11 12:56:02 -0400 | [diff] [blame] | 33 | import android.os.UserManager; |
Andrew Scull | c23357e | 2017-04-18 09:40:11 +0100 | [diff] [blame] | 34 | import android.service.oemlock.OemLockManager; |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 35 | import android.service.persistentdata.PersistentDataBlockManager; |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 36 | import android.util.Log; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 37 | import android.view.LayoutInflater; |
| 38 | import android.view.View; |
| 39 | import android.view.ViewGroup; |
| 40 | import android.widget.Button; |
Julia Reynolds | ce25af4 | 2015-07-08 16:56:31 -0400 | [diff] [blame] | 41 | import android.widget.TextView; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 42 | |
Doris Ling | 7248972 | 2017-11-16 11:03:40 -0800 | [diff] [blame] | 43 | import com.android.settings.core.InstrumentedFragment; |
arangelov | 9308154 | 2017-10-27 13:51:28 +0100 | [diff] [blame] | 44 | import com.android.settings.enterprise.ActionDisabledByAdminDialogHelper; |
Philip P. Moltmann | e3f7211 | 2018-08-28 15:01:43 -0700 | [diff] [blame] | 45 | import com.android.settingslib.RestrictedLockUtilsInternal; |
Pasty Chang | c1f8600 | 2018-12-11 02:22:55 +0000 | [diff] [blame] | 46 | |
Maurice Lam | 0111db7 | 2019-02-14 22:01:10 +0000 | [diff] [blame^] | 47 | import com.google.android.setupcompat.TemplateLayout; |
pastychang | 9bdb59a | 2019-01-21 09:49:15 +0800 | [diff] [blame] | 48 | import com.google.android.setupcompat.template.FooterBarMixin; |
| 49 | import com.google.android.setupcompat.template.FooterButton; |
| 50 | import com.google.android.setupcompat.template.FooterButton.ButtonType; |
Sudheer Shanka | 7dbbe13 | 2016-02-16 14:19:32 +0000 | [diff] [blame] | 51 | |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 52 | /** |
| 53 | * Confirm and execute a reset of the device to a clean "just out of the box" |
| 54 | * state. Multiple confirmations are required: first, a general "are you sure |
| 55 | * you want to do this?" prompt, followed by a keyguard pattern trace if the user |
| 56 | * has defined one, followed by a final strongly-worded "THIS WILL ERASE EVERYTHING |
| 57 | * ON THE PHONE" prompt. If at any time the phone is allowed to go to sleep, is |
| 58 | * locked, et cetera, then the confirmation sequence is abandoned. |
| 59 | * |
| 60 | * This is the confirmation screen. |
| 61 | */ |
Doris Ling | 7248972 | 2017-11-16 11:03:40 -0800 | [diff] [blame] | 62 | public class MasterClearConfirm extends InstrumentedFragment { |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 63 | private final static String TAG = "MasterClearConfirm"; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 64 | |
| 65 | private View mContentView; |
| 66 | private boolean mEraseSdCard; |
qingxi | 072f286 | 2017-04-11 18:28:40 -0700 | [diff] [blame] | 67 | private boolean mEraseEsims; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 68 | |
| 69 | /** |
| 70 | * The user has gone through the multiple confirmation, so now we go ahead |
| 71 | * and invoke the Checkin Service to reset the device to its factory-default |
| 72 | * state (rebooting in the process). |
| 73 | */ |
| 74 | private Button.OnClickListener mFinalClickListener = new Button.OnClickListener() { |
| 75 | |
| 76 | public void onClick(View v) { |
| 77 | if (Utils.isMonkeyRunning()) { |
| 78 | return; |
| 79 | } |
| 80 | |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 81 | final PersistentDataBlockManager pdbManager = (PersistentDataBlockManager) |
Andres Morales | 7ab8929 | 2014-07-10 16:10:43 -0700 | [diff] [blame] | 82 | getActivity().getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE); |
Andrew Scull | c23357e | 2017-04-18 09:40:11 +0100 | [diff] [blame] | 83 | final OemLockManager oemLockManager = (OemLockManager) |
| 84 | getActivity().getSystemService(Context.OEM_LOCK_SERVICE); |
Andres Morales | 7ab8929 | 2014-07-10 16:10:43 -0700 | [diff] [blame] | 85 | |
Andrew Scull | c23357e | 2017-04-18 09:40:11 +0100 | [diff] [blame] | 86 | if (pdbManager != null && !oemLockManager.isOemUnlockAllowed() && |
Udam Saini | 679f7ad | 2016-03-25 10:47:00 -0700 | [diff] [blame] | 87 | Utils.isDeviceProvisioned(getActivity())) { |
Andrew Scull | c23357e | 2017-04-18 09:40:11 +0100 | [diff] [blame] | 88 | // if OEM unlock is allowed, the persistent data block will be wiped during FR |
| 89 | // process. If disabled, it will be wiped here, unless the device is still being |
| 90 | // provisioned, in which case the persistent data block will be preserved. |
Andres Morales | e6bf2a5 | 2014-09-08 13:14:00 -0700 | [diff] [blame] | 91 | new AsyncTask<Void, Void, Void>() { |
Andres Morales | c17ec1b | 2015-06-01 16:23:41 -0700 | [diff] [blame] | 92 | int mOldOrientation; |
| 93 | ProgressDialog mProgressDialog; |
| 94 | |
Andres Morales | e6bf2a5 | 2014-09-08 13:14:00 -0700 | [diff] [blame] | 95 | @Override |
| 96 | protected Void doInBackground(Void... params) { |
| 97 | pdbManager.wipe(); |
| 98 | return null; |
| 99 | } |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 100 | |
Andres Morales | e6bf2a5 | 2014-09-08 13:14:00 -0700 | [diff] [blame] | 101 | @Override |
| 102 | protected void onPostExecute(Void aVoid) { |
Andres Morales | c17ec1b | 2015-06-01 16:23:41 -0700 | [diff] [blame] | 103 | mProgressDialog.hide(); |
Julia Reynolds | 8a38801 | 2015-08-19 16:19:55 -0400 | [diff] [blame] | 104 | if (getActivity() != null) { |
| 105 | getActivity().setRequestedOrientation(mOldOrientation); |
| 106 | doMasterClear(); |
| 107 | } |
Andres Morales | e6bf2a5 | 2014-09-08 13:14:00 -0700 | [diff] [blame] | 108 | } |
Andres Morales | c17ec1b | 2015-06-01 16:23:41 -0700 | [diff] [blame] | 109 | |
| 110 | @Override |
| 111 | protected void onPreExecute() { |
| 112 | mProgressDialog = getProgressDialog(); |
| 113 | mProgressDialog.show(); |
| 114 | |
| 115 | // need to prevent orientation changes as we're about to go into |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 116 | // a long IO request, so we won't be able to access inflate resources on |
| 117 | // flash |
Andres Morales | c17ec1b | 2015-06-01 16:23:41 -0700 | [diff] [blame] | 118 | mOldOrientation = getActivity().getRequestedOrientation(); |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 119 | getActivity().setRequestedOrientation( |
| 120 | ActivityInfo.SCREEN_ORIENTATION_LOCKED); |
Andres Morales | c17ec1b | 2015-06-01 16:23:41 -0700 | [diff] [blame] | 121 | } |
Andres Morales | e6bf2a5 | 2014-09-08 13:14:00 -0700 | [diff] [blame] | 122 | }.execute(); |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 123 | } else { |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 124 | doMasterClear(); |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 125 | } |
| 126 | } |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 127 | |
| 128 | private ProgressDialog getProgressDialog() { |
| 129 | final ProgressDialog progressDialog = new ProgressDialog(getActivity()); |
| 130 | progressDialog.setIndeterminate(true); |
| 131 | progressDialog.setCancelable(false); |
| 132 | progressDialog.setTitle( |
| 133 | getActivity().getString(R.string.master_clear_progress_title)); |
| 134 | progressDialog.setMessage( |
| 135 | getActivity().getString(R.string.master_clear_progress_text)); |
| 136 | return progressDialog; |
| 137 | } |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 138 | }; |
| 139 | |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 140 | private void doMasterClear() { |
Lenka Trochtova | 3393dac | 2017-02-13 15:05:27 +0100 | [diff] [blame] | 141 | Intent intent = new Intent(Intent.ACTION_FACTORY_RESET); |
Christopher Tate | 1e99f0c | 2017-01-25 14:46:48 -0800 | [diff] [blame] | 142 | intent.setPackage("android"); |
Rubin Xu | ccbdc57 | 2015-06-26 15:27:23 +0100 | [diff] [blame] | 143 | intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); |
| 144 | intent.putExtra(Intent.EXTRA_REASON, "MasterClearConfirm"); |
| 145 | intent.putExtra(Intent.EXTRA_WIPE_EXTERNAL_STORAGE, mEraseSdCard); |
qingxi | 072f286 | 2017-04-11 18:28:40 -0700 | [diff] [blame] | 146 | intent.putExtra(Intent.EXTRA_WIPE_ESIMS, mEraseEsims); |
Rubin Xu | ccbdc57 | 2015-06-26 15:27:23 +0100 | [diff] [blame] | 147 | getActivity().sendBroadcast(intent); |
| 148 | // Intent handling is asynchronous -- assume it will happen soon. |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 151 | /** |
| 152 | * Configure the UI for the final confirmation interaction |
| 153 | */ |
| 154 | private void establishFinalConfirmationState() { |
Maurice Lam | 0111db7 | 2019-02-14 22:01:10 +0000 | [diff] [blame^] | 155 | final TemplateLayout layout = mContentView.findViewById(R.id.setup_wizard_layout); |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 156 | |
pastychang | 9bdb59a | 2019-01-21 09:49:15 +0800 | [diff] [blame] | 157 | final FooterBarMixin mixin = layout.getMixin(FooterBarMixin.class); |
| 158 | mixin.setPrimaryButton( |
pastychang | 908501e | 2018-12-26 10:46:40 +0800 | [diff] [blame] | 159 | new FooterButton.Builder(getActivity()) |
| 160 | .setText(R.string.master_clear_button_text) |
| 161 | .setListener(mFinalClickListener) |
| 162 | .setButtonType(ButtonType.OTHER) |
pastychang | 7961482 | 2019-01-03 10:12:54 +0800 | [diff] [blame] | 163 | .setTheme(R.style.SudGlifButton_Primary) |
pastychang | 908501e | 2018-12-26 10:46:40 +0800 | [diff] [blame] | 164 | .build() |
pastychang | 103409b | 2018-12-13 23:00:17 +0800 | [diff] [blame] | 165 | ); |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | private void setUpActionBarAndTitle() { |
| 169 | final Activity activity = getActivity(); |
| 170 | if (activity == null) { |
| 171 | Log.e(TAG, "No activity attached, skipping setUpActionBarAndTitle"); |
| 172 | return; |
| 173 | } |
| 174 | final ActionBar actionBar = activity.getActionBar(); |
| 175 | if (actionBar == null) { |
| 176 | Log.e(TAG, "No actionbar, skipping setUpActionBarAndTitle"); |
| 177 | return; |
| 178 | } |
| 179 | actionBar.hide(); |
| 180 | activity.getWindow().setStatusBarColor(Color.TRANSPARENT); |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | @Override |
| 184 | public View onCreateView(LayoutInflater inflater, ViewGroup container, |
| 185 | Bundle savedInstanceState) { |
Philip P. Moltmann | e3f7211 | 2018-08-28 15:01:43 -0700 | [diff] [blame] | 186 | final EnforcedAdmin admin = RestrictedLockUtilsInternal.checkIfRestrictionEnforced( |
Sudheer Shanka | 7dbbe13 | 2016-02-16 14:19:32 +0000 | [diff] [blame] | 187 | getActivity(), UserManager.DISALLOW_FACTORY_RESET, UserHandle.myUserId()); |
Philip P. Moltmann | e3f7211 | 2018-08-28 15:01:43 -0700 | [diff] [blame] | 188 | if (RestrictedLockUtilsInternal.hasBaseUserRestriction(getActivity(), |
Sudheer Shanka | 7dbbe13 | 2016-02-16 14:19:32 +0000 | [diff] [blame] | 189 | UserManager.DISALLOW_FACTORY_RESET, UserHandle.myUserId())) { |
Julia Reynolds | 2c53933 | 2014-06-11 12:56:02 -0400 | [diff] [blame] | 190 | return inflater.inflate(R.layout.master_clear_disallowed_screen, null); |
Sudheer Shanka | 7dbbe13 | 2016-02-16 14:19:32 +0000 | [diff] [blame] | 191 | } else if (admin != null) { |
arangelov | 9308154 | 2017-10-27 13:51:28 +0100 | [diff] [blame] | 192 | new ActionDisabledByAdminDialogHelper(getActivity()) |
| 193 | .prepareDialogBuilder(UserManager.DISALLOW_FACTORY_RESET, admin) |
| 194 | .setOnDismissListener(__ -> getActivity().finish()) |
| 195 | .show(); |
| 196 | return new View(getActivity()); |
Julia Reynolds | 2c53933 | 2014-06-11 12:56:02 -0400 | [diff] [blame] | 197 | } |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 198 | mContentView = inflater.inflate(R.layout.master_clear_confirm, null); |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 199 | setUpActionBarAndTitle(); |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 200 | establishFinalConfirmationState(); |
Julia Reynolds | ce25af4 | 2015-07-08 16:56:31 -0400 | [diff] [blame] | 201 | setAccessibilityTitle(); |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 202 | return mContentView; |
| 203 | } |
| 204 | |
Julia Reynolds | ce25af4 | 2015-07-08 16:56:31 -0400 | [diff] [blame] | 205 | private void setAccessibilityTitle() { |
| 206 | CharSequence currentTitle = getActivity().getTitle(); |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 207 | TextView confirmationMessage = mContentView.findViewById(R.id.master_clear_confirm); |
Julia Reynolds | ce25af4 | 2015-07-08 16:56:31 -0400 | [diff] [blame] | 208 | if (confirmationMessage != null) { |
arangelov | 9308154 | 2017-10-27 13:51:28 +0100 | [diff] [blame] | 209 | String accessibleText = new StringBuilder(currentTitle).append(",").append( |
Julia Reynolds | ce25af4 | 2015-07-08 16:56:31 -0400 | [diff] [blame] | 210 | confirmationMessage.getText()).toString(); |
arangelov | 9308154 | 2017-10-27 13:51:28 +0100 | [diff] [blame] | 211 | getActivity().setTitle(Utils.createAccessibleSequence(currentTitle, accessibleText)); |
Julia Reynolds | ce25af4 | 2015-07-08 16:56:31 -0400 | [diff] [blame] | 212 | } |
| 213 | } |
| 214 | |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 215 | @Override |
| 216 | public void onCreate(Bundle savedInstanceState) { |
| 217 | super.onCreate(savedInstanceState); |
| 218 | |
| 219 | Bundle args = getArguments(); |
Andres Morales | c17ec1b | 2015-06-01 16:23:41 -0700 | [diff] [blame] | 220 | mEraseSdCard = args != null |
| 221 | && args.getBoolean(MasterClear.ERASE_EXTERNAL_EXTRA); |
qingxi | 072f286 | 2017-04-11 18:28:40 -0700 | [diff] [blame] | 222 | mEraseEsims = args != null |
| 223 | && args.getBoolean(MasterClear.ERASE_ESIMS_EXTRA); |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 224 | } |
Chris Wren | 8a963ba | 2015-03-20 10:29:14 -0400 | [diff] [blame] | 225 | |
| 226 | @Override |
Fan Zhang | 6507613 | 2016-08-08 10:25:13 -0700 | [diff] [blame] | 227 | public int getMetricsCategory() { |
Fan Zhang | 31b2100 | 2019-01-16 13:49:47 -0800 | [diff] [blame] | 228 | return SettingsEnums.MASTER_CLEAR_CONFIRM; |
Chris Wren | 8a963ba | 2015-03-20 10:29:14 -0400 | [diff] [blame] | 229 | } |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 230 | } |