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; |
Jiashen Wang | bbcd54d | 2020-08-09 20:18:13 -0700 | [diff] [blame] | 24 | import android.app.AlertDialog; |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 25 | import android.app.ProgressDialog; |
Alex Johnston | 74260a7 | 2020-03-19 17:34:46 +0000 | [diff] [blame] | 26 | import android.app.admin.DevicePolicyManager; |
| 27 | import android.app.admin.FactoryResetProtectionPolicy; |
Fan Zhang | 31b2100 | 2019-01-16 13:49:47 -0800 | [diff] [blame] | 28 | import android.app.settings.SettingsEnums; |
Andres Morales | 7ab8929 | 2014-07-10 16:10:43 -0700 | [diff] [blame] | 29 | import android.content.Context; |
Jiashen Wang | bbcd54d | 2020-08-09 20:18:13 -0700 | [diff] [blame] | 30 | import android.content.DialogInterface; |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 31 | import android.content.Intent; |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 32 | import android.content.pm.ActivityInfo; |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 33 | import android.graphics.Color; |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 34 | import android.os.AsyncTask; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 35 | import android.os.Bundle; |
Jiashen Wang | bbcd54d | 2020-08-09 20:18:13 -0700 | [diff] [blame] | 36 | import android.os.PowerManager; |
Sudheer Shanka | 7dbbe13 | 2016-02-16 14:19:32 +0000 | [diff] [blame] | 37 | import android.os.UserHandle; |
Julia Reynolds | 2c53933 | 2014-06-11 12:56:02 -0400 | [diff] [blame] | 38 | import android.os.UserManager; |
Andrew Scull | c23357e | 2017-04-18 09:40:11 +0100 | [diff] [blame] | 39 | import android.service.oemlock.OemLockManager; |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 40 | import android.service.persistentdata.PersistentDataBlockManager; |
Jiashen Wang | bbcd54d | 2020-08-09 20:18:13 -0700 | [diff] [blame] | 41 | import android.telephony.TelephonyManager; |
| 42 | import android.telephony.UiccSlotInfo; |
| 43 | import android.telephony.euicc.EuiccManager; |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 44 | import android.util.Log; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 45 | import android.view.LayoutInflater; |
| 46 | import android.view.View; |
| 47 | import android.view.ViewGroup; |
| 48 | import android.widget.Button; |
Julia Reynolds | ce25af4 | 2015-07-08 16:56:31 -0400 | [diff] [blame] | 49 | import android.widget.TextView; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 50 | |
Andrew Sapperstein | 88930e3 | 2019-03-07 14:18:15 -0800 | [diff] [blame] | 51 | import androidx.annotation.VisibleForTesting; |
| 52 | |
Doris Ling | 7248972 | 2017-11-16 11:03:40 -0800 | [diff] [blame] | 53 | import com.android.settings.core.InstrumentedFragment; |
arangelov | 9308154 | 2017-10-27 13:51:28 +0100 | [diff] [blame] | 54 | import com.android.settings.enterprise.ActionDisabledByAdminDialogHelper; |
Philip P. Moltmann | e3f7211 | 2018-08-28 15:01:43 -0700 | [diff] [blame] | 55 | import com.android.settingslib.RestrictedLockUtilsInternal; |
Pasty Chang | c1f8600 | 2018-12-11 02:22:55 +0000 | [diff] [blame] | 56 | |
pastychang | 9bdb59a | 2019-01-21 09:49:15 +0800 | [diff] [blame] | 57 | import com.google.android.setupcompat.template.FooterBarMixin; |
| 58 | import com.google.android.setupcompat.template.FooterButton; |
| 59 | import com.google.android.setupcompat.template.FooterButton.ButtonType; |
Raff Tsai | c898775 | 2019-10-18 09:57:49 +0800 | [diff] [blame] | 60 | import com.google.android.setupcompat.util.WizardManagerHelper; |
Maurice Lam | 59f1c1a | 2019-02-14 22:04:30 +0000 | [diff] [blame] | 61 | import com.google.android.setupdesign.GlifLayout; |
Sudheer Shanka | 7dbbe13 | 2016-02-16 14:19:32 +0000 | [diff] [blame] | 62 | |
Jiashen Wang | bbcd54d | 2020-08-09 20:18:13 -0700 | [diff] [blame] | 63 | import java.util.Arrays; |
| 64 | |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 65 | /** |
| 66 | * Confirm and execute a reset of the device to a clean "just out of the box" |
| 67 | * state. Multiple confirmations are required: first, a general "are you sure |
| 68 | * you want to do this?" prompt, followed by a keyguard pattern trace if the user |
| 69 | * has defined one, followed by a final strongly-worded "THIS WILL ERASE EVERYTHING |
| 70 | * ON THE PHONE" prompt. If at any time the phone is allowed to go to sleep, is |
| 71 | * locked, et cetera, then the confirmation sequence is abandoned. |
| 72 | * |
| 73 | * This is the confirmation screen. |
| 74 | */ |
Doris Ling | 7248972 | 2017-11-16 11:03:40 -0800 | [diff] [blame] | 75 | public class MasterClearConfirm extends InstrumentedFragment { |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 76 | private final static String TAG = "MasterClearConfirm"; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 77 | |
Andrew Sapperstein | 88930e3 | 2019-03-07 14:18:15 -0800 | [diff] [blame] | 78 | @VisibleForTesting View mContentView; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 79 | private boolean mEraseSdCard; |
Andrew Sapperstein | 88930e3 | 2019-03-07 14:18:15 -0800 | [diff] [blame] | 80 | @VisibleForTesting boolean mEraseEsims; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 81 | |
| 82 | /** |
| 83 | * The user has gone through the multiple confirmation, so now we go ahead |
| 84 | * and invoke the Checkin Service to reset the device to its factory-default |
| 85 | * state (rebooting in the process). |
| 86 | */ |
| 87 | private Button.OnClickListener mFinalClickListener = new Button.OnClickListener() { |
| 88 | |
| 89 | public void onClick(View v) { |
| 90 | if (Utils.isMonkeyRunning()) { |
| 91 | return; |
| 92 | } |
| 93 | |
Jiashen Wang | bbcd54d | 2020-08-09 20:18:13 -0700 | [diff] [blame] | 94 | // If the eSIM slot is in an error state, display a dialog to warn users that their eSIM |
| 95 | // profiles may not be fully deleted during FDR. |
| 96 | if (shouldShowEsimEraseFailureDialog()) { |
| 97 | Log.e(TAG, "eUICC card is in an error state. Display a dialog to warn the user."); |
| 98 | showEsimErrorDialog(); |
| 99 | return; |
| 100 | } |
| 101 | |
| 102 | performFactoryReset(); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Returns true if the user choose to erase eSIM profile but the eUICC card is in an error |
| 107 | * state. |
| 108 | */ |
| 109 | private boolean shouldShowEsimEraseFailureDialog() { |
| 110 | EuiccManager euiccManager = getActivity().getSystemService(EuiccManager.class); |
| 111 | TelephonyManager telephonyManager = |
| 112 | getActivity().getSystemService(TelephonyManager.class); |
| 113 | |
| 114 | if (euiccManager == null || !euiccManager.isEnabled()) { |
| 115 | Log.i( |
| 116 | TAG, |
| 117 | "eSIM manager is disabled. No need to check eSIM slot before FDR."); |
| 118 | return false; |
| 119 | } |
| 120 | if (!mEraseEsims) { |
| 121 | Log.i( |
| 122 | TAG, |
| 123 | "eSIM does not need to be reset. No need to check eSIM slot before FDR."); |
| 124 | return false; |
| 125 | } |
| 126 | UiccSlotInfo[] slotInfos = telephonyManager.getUiccSlotsInfo(); |
| 127 | if (slotInfos == null) { |
| 128 | Log.i(TAG, "Unable to get UICC slots."); |
| 129 | return false; |
| 130 | } |
| 131 | // If getIsEuicc() returns false for an eSIM slot, it means the eSIM is in the error |
| 132 | // state. |
| 133 | return Arrays.stream(slotInfos).anyMatch( |
| 134 | slot -> slot != null && !slot.isRemovable() && !slot.getIsEuicc()); |
| 135 | } |
| 136 | |
| 137 | private void showEsimErrorDialog() { |
| 138 | new AlertDialog.Builder(getActivity()) |
| 139 | .setTitle(R.string.fdr_esim_failure_title) |
| 140 | .setMessage(R.string.fdr_esim_failure_text) |
| 141 | .setNeutralButton(R.string.dlg_cancel, |
| 142 | (DialogInterface.OnClickListener) (dialog, which) -> { |
| 143 | dialog.dismiss(); |
| 144 | }) |
| 145 | .setNegativeButton(R.string.fdr_esim_failure_reboot_btn, |
| 146 | (DialogInterface.OnClickListener) (dialog, which) -> { |
| 147 | dialog.dismiss(); |
| 148 | PowerManager pm = (PowerManager) getActivity() |
| 149 | .getSystemService(Context.POWER_SERVICE); |
| 150 | pm.reboot(null); |
| 151 | }) |
| 152 | .setPositiveButton(R.string.lockpassword_continue_label, |
| 153 | (DialogInterface.OnClickListener) (dialog, which) -> { |
| 154 | dialog.dismiss(); |
| 155 | showContinueFdrDialog(); |
| 156 | }) |
| 157 | .show(); |
| 158 | } |
| 159 | |
| 160 | private void showContinueFdrDialog() { |
| 161 | new AlertDialog.Builder(getActivity()) |
| 162 | .setTitle(R.string.fdr_continue_title) |
| 163 | .setMessage(R.string.fdr_continue_text) |
| 164 | .setNegativeButton(R.string.dlg_cancel, |
| 165 | (DialogInterface.OnClickListener) (dialog, which) -> { |
| 166 | dialog.dismiss(); |
| 167 | }) |
| 168 | .setPositiveButton(R.string.fdr_continue_btn, |
| 169 | (DialogInterface.OnClickListener) (dialog, which) -> { |
| 170 | dialog.dismiss(); |
| 171 | performFactoryReset(); |
| 172 | }) |
| 173 | .show(); |
| 174 | } |
| 175 | |
| 176 | private void performFactoryReset() { |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 177 | final PersistentDataBlockManager pdbManager = (PersistentDataBlockManager) |
Andres Morales | 7ab8929 | 2014-07-10 16:10:43 -0700 | [diff] [blame] | 178 | getActivity().getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE); |
| 179 | |
Alex Johnston | 74260a7 | 2020-03-19 17:34:46 +0000 | [diff] [blame] | 180 | if (shouldWipePersistentDataBlock(pdbManager)) { |
| 181 | |
Andres Morales | e6bf2a5 | 2014-09-08 13:14:00 -0700 | [diff] [blame] | 182 | new AsyncTask<Void, Void, Void>() { |
Andres Morales | c17ec1b | 2015-06-01 16:23:41 -0700 | [diff] [blame] | 183 | int mOldOrientation; |
| 184 | ProgressDialog mProgressDialog; |
| 185 | |
Andres Morales | e6bf2a5 | 2014-09-08 13:14:00 -0700 | [diff] [blame] | 186 | @Override |
| 187 | protected Void doInBackground(Void... params) { |
| 188 | pdbManager.wipe(); |
| 189 | return null; |
| 190 | } |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 191 | |
Andres Morales | e6bf2a5 | 2014-09-08 13:14:00 -0700 | [diff] [blame] | 192 | @Override |
| 193 | protected void onPostExecute(Void aVoid) { |
Andres Morales | c17ec1b | 2015-06-01 16:23:41 -0700 | [diff] [blame] | 194 | mProgressDialog.hide(); |
Julia Reynolds | 8a38801 | 2015-08-19 16:19:55 -0400 | [diff] [blame] | 195 | if (getActivity() != null) { |
| 196 | getActivity().setRequestedOrientation(mOldOrientation); |
| 197 | doMasterClear(); |
| 198 | } |
Andres Morales | e6bf2a5 | 2014-09-08 13:14:00 -0700 | [diff] [blame] | 199 | } |
Andres Morales | c17ec1b | 2015-06-01 16:23:41 -0700 | [diff] [blame] | 200 | |
| 201 | @Override |
| 202 | protected void onPreExecute() { |
| 203 | mProgressDialog = getProgressDialog(); |
| 204 | mProgressDialog.show(); |
| 205 | |
| 206 | // need to prevent orientation changes as we're about to go into |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 207 | // a long IO request, so we won't be able to access inflate resources on |
| 208 | // flash |
Andres Morales | c17ec1b | 2015-06-01 16:23:41 -0700 | [diff] [blame] | 209 | mOldOrientation = getActivity().getRequestedOrientation(); |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 210 | getActivity().setRequestedOrientation( |
| 211 | ActivityInfo.SCREEN_ORIENTATION_LOCKED); |
Andres Morales | c17ec1b | 2015-06-01 16:23:41 -0700 | [diff] [blame] | 212 | } |
Andres Morales | e6bf2a5 | 2014-09-08 13:14:00 -0700 | [diff] [blame] | 213 | }.execute(); |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 214 | } else { |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 215 | doMasterClear(); |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 216 | } |
| 217 | } |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 218 | |
| 219 | private ProgressDialog getProgressDialog() { |
| 220 | final ProgressDialog progressDialog = new ProgressDialog(getActivity()); |
| 221 | progressDialog.setIndeterminate(true); |
| 222 | progressDialog.setCancelable(false); |
| 223 | progressDialog.setTitle( |
| 224 | getActivity().getString(R.string.master_clear_progress_title)); |
| 225 | progressDialog.setMessage( |
| 226 | getActivity().getString(R.string.master_clear_progress_text)); |
| 227 | return progressDialog; |
| 228 | } |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 229 | }; |
| 230 | |
Alex Johnston | 74260a7 | 2020-03-19 17:34:46 +0000 | [diff] [blame] | 231 | @VisibleForTesting |
| 232 | boolean shouldWipePersistentDataBlock(PersistentDataBlockManager pdbManager) { |
| 233 | if (pdbManager == null) { |
| 234 | return false; |
| 235 | } |
| 236 | // The persistent data block will persist if the device is still being provisioned. |
| 237 | if (isDeviceStillBeingProvisioned()) { |
| 238 | return false; |
| 239 | } |
| 240 | // If OEM unlock is allowed, the persistent data block will be wiped during FR |
| 241 | // process. If disabled, it will be wiped here instead. |
| 242 | if (isOemUnlockedAllowed()) { |
| 243 | return false; |
| 244 | } |
Alex Johnston | 05c0ab0 | 2020-04-28 13:47:14 +0100 | [diff] [blame] | 245 | final DevicePolicyManager dpm = (DevicePolicyManager) getActivity() |
| 246 | .getSystemService(Context.DEVICE_POLICY_SERVICE); |
| 247 | // Do not erase the factory reset protection data (from Settings) if factory reset |
| 248 | // protection policy is not supported on the device. |
| 249 | if (!dpm.isFactoryResetProtectionPolicySupported()) { |
| 250 | return false; |
| 251 | } |
Alex Johnston | 74260a7 | 2020-03-19 17:34:46 +0000 | [diff] [blame] | 252 | // Do not erase the factory reset protection data (from Settings) if the |
| 253 | // device is an organization-owned managed profile device and a factory |
| 254 | // reset protection policy has been set. |
Alex Johnston | 74260a7 | 2020-03-19 17:34:46 +0000 | [diff] [blame] | 255 | FactoryResetProtectionPolicy frpPolicy = dpm.getFactoryResetProtectionPolicy(null); |
| 256 | if (dpm.isOrganizationOwnedDeviceWithManagedProfile() && frpPolicy != null |
| 257 | && frpPolicy.isNotEmpty()) { |
| 258 | return false; |
| 259 | } |
| 260 | return true; |
| 261 | } |
| 262 | |
| 263 | @VisibleForTesting |
| 264 | boolean isOemUnlockedAllowed() { |
| 265 | return ((OemLockManager) getActivity().getSystemService( |
| 266 | Context.OEM_LOCK_SERVICE)).isOemUnlockAllowed(); |
| 267 | } |
| 268 | |
| 269 | @VisibleForTesting |
| 270 | boolean isDeviceStillBeingProvisioned() { |
| 271 | return !WizardManagerHelper.isDeviceProvisioned(getActivity()); |
| 272 | } |
| 273 | |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 274 | private void doMasterClear() { |
Lenka Trochtova | 3393dac | 2017-02-13 15:05:27 +0100 | [diff] [blame] | 275 | Intent intent = new Intent(Intent.ACTION_FACTORY_RESET); |
Christopher Tate | 1e99f0c | 2017-01-25 14:46:48 -0800 | [diff] [blame] | 276 | intent.setPackage("android"); |
Rubin Xu | ccbdc57 | 2015-06-26 15:27:23 +0100 | [diff] [blame] | 277 | intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); |
| 278 | intent.putExtra(Intent.EXTRA_REASON, "MasterClearConfirm"); |
| 279 | intent.putExtra(Intent.EXTRA_WIPE_EXTERNAL_STORAGE, mEraseSdCard); |
qingxi | 072f286 | 2017-04-11 18:28:40 -0700 | [diff] [blame] | 280 | intent.putExtra(Intent.EXTRA_WIPE_ESIMS, mEraseEsims); |
Rubin Xu | ccbdc57 | 2015-06-26 15:27:23 +0100 | [diff] [blame] | 281 | getActivity().sendBroadcast(intent); |
| 282 | // Intent handling is asynchronous -- assume it will happen soon. |
Andres Morales | ab61b0d | 2014-08-26 13:54:12 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 285 | /** |
| 286 | * Configure the UI for the final confirmation interaction |
| 287 | */ |
| 288 | private void establishFinalConfirmationState() { |
Maurice Lam | 59f1c1a | 2019-02-14 22:04:30 +0000 | [diff] [blame] | 289 | final GlifLayout layout = mContentView.findViewById(R.id.setup_wizard_layout); |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 290 | |
pastychang | 9bdb59a | 2019-01-21 09:49:15 +0800 | [diff] [blame] | 291 | final FooterBarMixin mixin = layout.getMixin(FooterBarMixin.class); |
| 292 | mixin.setPrimaryButton( |
pastychang | 908501e | 2018-12-26 10:46:40 +0800 | [diff] [blame] | 293 | new FooterButton.Builder(getActivity()) |
| 294 | .setText(R.string.master_clear_button_text) |
| 295 | .setListener(mFinalClickListener) |
| 296 | .setButtonType(ButtonType.OTHER) |
pastychang | 7961482 | 2019-01-03 10:12:54 +0800 | [diff] [blame] | 297 | .setTheme(R.style.SudGlifButton_Primary) |
pastychang | 908501e | 2018-12-26 10:46:40 +0800 | [diff] [blame] | 298 | .build() |
pastychang | 103409b | 2018-12-13 23:00:17 +0800 | [diff] [blame] | 299 | ); |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | private void setUpActionBarAndTitle() { |
| 303 | final Activity activity = getActivity(); |
| 304 | if (activity == null) { |
| 305 | Log.e(TAG, "No activity attached, skipping setUpActionBarAndTitle"); |
| 306 | return; |
| 307 | } |
| 308 | final ActionBar actionBar = activity.getActionBar(); |
| 309 | if (actionBar == null) { |
| 310 | Log.e(TAG, "No actionbar, skipping setUpActionBarAndTitle"); |
| 311 | return; |
| 312 | } |
| 313 | actionBar.hide(); |
| 314 | activity.getWindow().setStatusBarColor(Color.TRANSPARENT); |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | @Override |
| 318 | public View onCreateView(LayoutInflater inflater, ViewGroup container, |
| 319 | Bundle savedInstanceState) { |
Philip P. Moltmann | e3f7211 | 2018-08-28 15:01:43 -0700 | [diff] [blame] | 320 | final EnforcedAdmin admin = RestrictedLockUtilsInternal.checkIfRestrictionEnforced( |
Sudheer Shanka | 7dbbe13 | 2016-02-16 14:19:32 +0000 | [diff] [blame] | 321 | getActivity(), UserManager.DISALLOW_FACTORY_RESET, UserHandle.myUserId()); |
Philip P. Moltmann | e3f7211 | 2018-08-28 15:01:43 -0700 | [diff] [blame] | 322 | if (RestrictedLockUtilsInternal.hasBaseUserRestriction(getActivity(), |
Sudheer Shanka | 7dbbe13 | 2016-02-16 14:19:32 +0000 | [diff] [blame] | 323 | UserManager.DISALLOW_FACTORY_RESET, UserHandle.myUserId())) { |
Julia Reynolds | 2c53933 | 2014-06-11 12:56:02 -0400 | [diff] [blame] | 324 | return inflater.inflate(R.layout.master_clear_disallowed_screen, null); |
Sudheer Shanka | 7dbbe13 | 2016-02-16 14:19:32 +0000 | [diff] [blame] | 325 | } else if (admin != null) { |
arangelov | 9308154 | 2017-10-27 13:51:28 +0100 | [diff] [blame] | 326 | new ActionDisabledByAdminDialogHelper(getActivity()) |
| 327 | .prepareDialogBuilder(UserManager.DISALLOW_FACTORY_RESET, admin) |
| 328 | .setOnDismissListener(__ -> getActivity().finish()) |
| 329 | .show(); |
| 330 | return new View(getActivity()); |
Julia Reynolds | 2c53933 | 2014-06-11 12:56:02 -0400 | [diff] [blame] | 331 | } |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 332 | mContentView = inflater.inflate(R.layout.master_clear_confirm, null); |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 333 | setUpActionBarAndTitle(); |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 334 | establishFinalConfirmationState(); |
Julia Reynolds | ce25af4 | 2015-07-08 16:56:31 -0400 | [diff] [blame] | 335 | setAccessibilityTitle(); |
Andrew Sapperstein | 88930e3 | 2019-03-07 14:18:15 -0800 | [diff] [blame] | 336 | setSubtitle(); |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 337 | return mContentView; |
| 338 | } |
| 339 | |
Julia Reynolds | ce25af4 | 2015-07-08 16:56:31 -0400 | [diff] [blame] | 340 | private void setAccessibilityTitle() { |
| 341 | CharSequence currentTitle = getActivity().getTitle(); |
pastychang | fa68ec4 | 2019-04-12 16:22:17 +0800 | [diff] [blame] | 342 | TextView confirmationMessage = mContentView.findViewById(R.id.sud_layout_description); |
Julia Reynolds | ce25af4 | 2015-07-08 16:56:31 -0400 | [diff] [blame] | 343 | if (confirmationMessage != null) { |
arangelov | 9308154 | 2017-10-27 13:51:28 +0100 | [diff] [blame] | 344 | String accessibleText = new StringBuilder(currentTitle).append(",").append( |
Julia Reynolds | ce25af4 | 2015-07-08 16:56:31 -0400 | [diff] [blame] | 345 | confirmationMessage.getText()).toString(); |
arangelov | 9308154 | 2017-10-27 13:51:28 +0100 | [diff] [blame] | 346 | getActivity().setTitle(Utils.createAccessibleSequence(currentTitle, accessibleText)); |
Julia Reynolds | ce25af4 | 2015-07-08 16:56:31 -0400 | [diff] [blame] | 347 | } |
| 348 | } |
| 349 | |
Andrew Sapperstein | 88930e3 | 2019-03-07 14:18:15 -0800 | [diff] [blame] | 350 | @VisibleForTesting |
| 351 | void setSubtitle() { |
| 352 | if (mEraseEsims) { |
pastychang | fa68ec4 | 2019-04-12 16:22:17 +0800 | [diff] [blame] | 353 | ((TextView) mContentView.findViewById(R.id.sud_layout_description)) |
Andrew Sapperstein | 88930e3 | 2019-03-07 14:18:15 -0800 | [diff] [blame] | 354 | .setText(R.string.master_clear_final_desc_esim); |
| 355 | } |
| 356 | } |
| 357 | |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 358 | @Override |
| 359 | public void onCreate(Bundle savedInstanceState) { |
| 360 | super.onCreate(savedInstanceState); |
| 361 | |
| 362 | Bundle args = getArguments(); |
Andres Morales | c17ec1b | 2015-06-01 16:23:41 -0700 | [diff] [blame] | 363 | mEraseSdCard = args != null |
| 364 | && args.getBoolean(MasterClear.ERASE_EXTERNAL_EXTRA); |
qingxi | 072f286 | 2017-04-11 18:28:40 -0700 | [diff] [blame] | 365 | mEraseEsims = args != null |
| 366 | && args.getBoolean(MasterClear.ERASE_ESIMS_EXTRA); |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 367 | } |
Chris Wren | 8a963ba | 2015-03-20 10:29:14 -0400 | [diff] [blame] | 368 | |
| 369 | @Override |
Fan Zhang | 6507613 | 2016-08-08 10:25:13 -0700 | [diff] [blame] | 370 | public int getMetricsCategory() { |
Fan Zhang | 31b2100 | 2019-01-16 13:49:47 -0800 | [diff] [blame] | 371 | return SettingsEnums.MASTER_CLEAR_CONFIRM; |
Chris Wren | 8a963ba | 2015-03-20 10:29:14 -0400 | [diff] [blame] | 372 | } |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 373 | } |