blob: 39bf01a0d97d412efc333e2245fed609fe60fe71 [file] [log] [blame]
Amith Yamasanib14e1e02010-11-02 09:52:29 -07001/*
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
17package com.android.settings;
18
Andres Moralesab61b0d2014-08-26 13:54:12 -070019import android.app.ProgressDialog;
Andres Morales7ab89292014-07-10 16:10:43 -070020import android.content.Context;
Jason Monk39b46742015-09-10 15:52:51 -040021import android.content.Intent;
Andres Moralesab61b0d2014-08-26 13:54:12 -070022import android.content.pm.ActivityInfo;
23import android.os.AsyncTask;
Amith Yamasanib14e1e02010-11-02 09:52:29 -070024import android.os.Bundle;
Sudheer Shanka7dbbe132016-02-16 14:19:32 +000025import android.os.UserHandle;
Julia Reynolds2c539332014-06-11 12:56:02 -040026import android.os.UserManager;
Andrew Scullc23357e2017-04-18 09:40:11 +010027import android.service.oemlock.OemLockManager;
Jason Monk39b46742015-09-10 15:52:51 -040028import android.service.persistentdata.PersistentDataBlockManager;
Amith Yamasanib14e1e02010-11-02 09:52:29 -070029import android.view.LayoutInflater;
30import android.view.View;
31import android.view.ViewGroup;
32import android.widget.Button;
Julia Reynoldsce25af42015-07-08 16:56:31 -040033import android.widget.TextView;
Amith Yamasanib14e1e02010-11-02 09:52:29 -070034
Tamas Berghammer265d3c22016-06-22 15:34:45 +010035import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Sudheer Shanka7dbbe132016-02-16 14:19:32 +000036import com.android.settingslib.RestrictedLockUtils;
37
38import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
Jason Monk39b46742015-09-10 15:52:51 -040039
Amith Yamasanib14e1e02010-11-02 09:52:29 -070040/**
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 Saini0708d9e2016-03-28 16:35:13 -070050public class MasterClearConfirm extends OptionsMenuFragment {
Amith Yamasanib14e1e02010-11-02 09:52:29 -070051
52 private View mContentView;
53 private boolean mEraseSdCard;
qingxi072f2862017-04-11 18:28:40 -070054 private boolean mEraseEsims;
Amith Yamasanib14e1e02010-11-02 09:52:29 -070055
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 Moralesab61b0d2014-08-26 13:54:12 -070068 final PersistentDataBlockManager pdbManager = (PersistentDataBlockManager)
Andres Morales7ab89292014-07-10 16:10:43 -070069 getActivity().getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
Andrew Scullc23357e2017-04-18 09:40:11 +010070 final OemLockManager oemLockManager = (OemLockManager)
71 getActivity().getSystemService(Context.OEM_LOCK_SERVICE);
Andres Morales7ab89292014-07-10 16:10:43 -070072
Andrew Scullc23357e2017-04-18 09:40:11 +010073 if (pdbManager != null && !oemLockManager.isOemUnlockAllowed() &&
Udam Saini679f7ad2016-03-25 10:47:00 -070074 Utils.isDeviceProvisioned(getActivity())) {
Andrew Scullc23357e2017-04-18 09:40:11 +010075 // if OEM unlock is allowed, the persistent data block will be wiped during FR
76 // process. If disabled, it will be wiped here, unless the device is still being
77 // provisioned, in which case the persistent data block will be preserved.
Andres Moralese6bf2a52014-09-08 13:14:00 -070078 new AsyncTask<Void, Void, Void>() {
Andres Moralesc17ec1b2015-06-01 16:23:41 -070079 int mOldOrientation;
80 ProgressDialog mProgressDialog;
81
Andres Moralese6bf2a52014-09-08 13:14:00 -070082 @Override
83 protected Void doInBackground(Void... params) {
84 pdbManager.wipe();
85 return null;
86 }
Andres Moralesab61b0d2014-08-26 13:54:12 -070087
Andres Moralese6bf2a52014-09-08 13:14:00 -070088 @Override
89 protected void onPostExecute(Void aVoid) {
Andres Moralesc17ec1b2015-06-01 16:23:41 -070090 mProgressDialog.hide();
Julia Reynolds8a388012015-08-19 16:19:55 -040091 if (getActivity() != null) {
92 getActivity().setRequestedOrientation(mOldOrientation);
93 doMasterClear();
94 }
Andres Moralese6bf2a52014-09-08 13:14:00 -070095 }
Andres Moralesc17ec1b2015-06-01 16:23:41 -070096
97 @Override
98 protected void onPreExecute() {
99 mProgressDialog = getProgressDialog();
100 mProgressDialog.show();
101
102 // need to prevent orientation changes as we're about to go into
103 // a long IO request, so we won't be able to access inflate resources on flash
104 mOldOrientation = getActivity().getRequestedOrientation();
105 getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
106 }
Andres Moralese6bf2a52014-09-08 13:14:00 -0700107 }.execute();
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700108 } else {
Andres Moralesab61b0d2014-08-26 13:54:12 -0700109 doMasterClear();
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700110 }
111 }
Andres Moralesab61b0d2014-08-26 13:54:12 -0700112
113 private ProgressDialog getProgressDialog() {
114 final ProgressDialog progressDialog = new ProgressDialog(getActivity());
115 progressDialog.setIndeterminate(true);
116 progressDialog.setCancelable(false);
117 progressDialog.setTitle(
118 getActivity().getString(R.string.master_clear_progress_title));
119 progressDialog.setMessage(
120 getActivity().getString(R.string.master_clear_progress_text));
121 return progressDialog;
122 }
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700123 };
124
Andres Moralesab61b0d2014-08-26 13:54:12 -0700125 private void doMasterClear() {
Lenka Trochtova3393dac2017-02-13 15:05:27 +0100126 Intent intent = new Intent(Intent.ACTION_FACTORY_RESET);
Christopher Tate1e99f0c2017-01-25 14:46:48 -0800127 intent.setPackage("android");
Rubin Xuccbdc572015-06-26 15:27:23 +0100128 intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
129 intent.putExtra(Intent.EXTRA_REASON, "MasterClearConfirm");
130 intent.putExtra(Intent.EXTRA_WIPE_EXTERNAL_STORAGE, mEraseSdCard);
qingxi072f2862017-04-11 18:28:40 -0700131 intent.putExtra(Intent.EXTRA_WIPE_ESIMS, mEraseEsims);
Rubin Xuccbdc572015-06-26 15:27:23 +0100132 getActivity().sendBroadcast(intent);
133 // Intent handling is asynchronous -- assume it will happen soon.
Andres Moralesab61b0d2014-08-26 13:54:12 -0700134 }
135
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700136 /**
137 * Configure the UI for the final confirmation interaction
138 */
139 private void establishFinalConfirmationState() {
Andres Moralesab61b0d2014-08-26 13:54:12 -0700140 mContentView.findViewById(R.id.execute_master_clear)
141 .setOnClickListener(mFinalClickListener);
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700142 }
143
144 @Override
145 public View onCreateView(LayoutInflater inflater, ViewGroup container,
146 Bundle savedInstanceState) {
Sudheer Shanka7dbbe132016-02-16 14:19:32 +0000147 final EnforcedAdmin admin = RestrictedLockUtils.checkIfRestrictionEnforced(
148 getActivity(), UserManager.DISALLOW_FACTORY_RESET, UserHandle.myUserId());
149 if (RestrictedLockUtils.hasBaseUserRestriction(getActivity(),
150 UserManager.DISALLOW_FACTORY_RESET, UserHandle.myUserId())) {
Julia Reynolds2c539332014-06-11 12:56:02 -0400151 return inflater.inflate(R.layout.master_clear_disallowed_screen, null);
Sudheer Shanka7dbbe132016-02-16 14:19:32 +0000152 } else if (admin != null) {
153 View view = inflater.inflate(R.layout.admin_support_details_empty_view, null);
154 ShowAdminSupportDetailsDialog.setAdminSupportDetails(getActivity(), view, admin, false);
155 view.setVisibility(View.VISIBLE);
156 return view;
Julia Reynolds2c539332014-06-11 12:56:02 -0400157 }
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700158 mContentView = inflater.inflate(R.layout.master_clear_confirm, null);
159 establishFinalConfirmationState();
Julia Reynoldsce25af42015-07-08 16:56:31 -0400160 setAccessibilityTitle();
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700161 return mContentView;
162 }
163
Julia Reynoldsce25af42015-07-08 16:56:31 -0400164 private void setAccessibilityTitle() {
165 CharSequence currentTitle = getActivity().getTitle();
166 TextView confirmationMessage =
167 (TextView) mContentView.findViewById(R.id.master_clear_confirm);
168 if (confirmationMessage != null) {
169 String accessibileText = new StringBuilder(currentTitle).append(",").append(
170 confirmationMessage.getText()).toString();
171 getActivity().setTitle(Utils.createAccessibleSequence(currentTitle, accessibileText));
172 }
173 }
174
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700175 @Override
176 public void onCreate(Bundle savedInstanceState) {
177 super.onCreate(savedInstanceState);
178
179 Bundle args = getArguments();
Andres Moralesc17ec1b2015-06-01 16:23:41 -0700180 mEraseSdCard = args != null
181 && args.getBoolean(MasterClear.ERASE_EXTERNAL_EXTRA);
qingxi072f2862017-04-11 18:28:40 -0700182 mEraseEsims = args != null
183 && args.getBoolean(MasterClear.ERASE_ESIMS_EXTRA);
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700184 }
Chris Wren8a963ba2015-03-20 10:29:14 -0400185
186 @Override
Fan Zhang65076132016-08-08 10:25:13 -0700187 public int getMetricsCategory() {
Chris Wren9d1bfd12016-01-26 18:04:01 -0500188 return MetricsEvent.MASTER_CLEAR_CONFIRM;
Chris Wren8a963ba2015-03-20 10:29:14 -0400189 }
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700190}