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