blob: d521ded228f346bb6a0a70e02415739334e3bb60 [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;
Russell Brennerff8a6802015-11-18 09:13:31 -080027import android.provider.Settings;
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
Chris Wren9d1bfd12016-01-26 18:04:01 -050035import com.android.internal.logging.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;
Amith Yamasanib14e1e02010-11-02 09:52:29 -070054
55 /**
56 * The user has gone through the multiple confirmation, so now we go ahead
57 * and invoke the Checkin Service to reset the device to its factory-default
58 * state (rebooting in the process).
59 */
60 private Button.OnClickListener mFinalClickListener = new Button.OnClickListener() {
61
62 public void onClick(View v) {
63 if (Utils.isMonkeyRunning()) {
64 return;
65 }
66
Andres Moralesab61b0d2014-08-26 13:54:12 -070067 final PersistentDataBlockManager pdbManager = (PersistentDataBlockManager)
Andres Morales7ab89292014-07-10 16:10:43 -070068 getActivity().getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
69
Russell Brennerde4fc8e2015-11-05 16:03:20 -080070 if (pdbManager != null && !pdbManager.getOemUnlockEnabled() &&
71 Settings.Global.getInt(getActivity().getContentResolver(),
72 Settings.Global.DEVICE_PROVISIONED, 0) != 0) {
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 Moralese6bf2a52014-09-08 13:14:00 -070076 new AsyncTask<Void, Void, Void>() {
Andres Moralesc17ec1b2015-06-01 16:23:41 -070077 int mOldOrientation;
78 ProgressDialog mProgressDialog;
79
Andres Moralese6bf2a52014-09-08 13:14:00 -070080 @Override
81 protected Void doInBackground(Void... params) {
82 pdbManager.wipe();
83 return null;
84 }
Andres Moralesab61b0d2014-08-26 13:54:12 -070085
Andres Moralese6bf2a52014-09-08 13:14:00 -070086 @Override
87 protected void onPostExecute(Void aVoid) {
Andres Moralesc17ec1b2015-06-01 16:23:41 -070088 mProgressDialog.hide();
Julia Reynolds8a388012015-08-19 16:19:55 -040089 if (getActivity() != null) {
90 getActivity().setRequestedOrientation(mOldOrientation);
91 doMasterClear();
92 }
Andres Moralese6bf2a52014-09-08 13:14:00 -070093 }
Andres Moralesc17ec1b2015-06-01 16:23:41 -070094
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 Moralese6bf2a52014-09-08 13:14:00 -0700105 }.execute();
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700106 } else {
Andres Moralesab61b0d2014-08-26 13:54:12 -0700107 doMasterClear();
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700108 }
109 }
Andres Moralesab61b0d2014-08-26 13:54:12 -0700110
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 Yamasanib14e1e02010-11-02 09:52:29 -0700121 };
122
Andres Moralesab61b0d2014-08-26 13:54:12 -0700123 private void doMasterClear() {
Rubin Xuccbdc572015-06-26 15:27:23 +0100124 Intent intent = new Intent(Intent.ACTION_MASTER_CLEAR);
125 intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
126 intent.putExtra(Intent.EXTRA_REASON, "MasterClearConfirm");
127 intent.putExtra(Intent.EXTRA_WIPE_EXTERNAL_STORAGE, mEraseSdCard);
128 getActivity().sendBroadcast(intent);
129 // Intent handling is asynchronous -- assume it will happen soon.
Andres Moralesab61b0d2014-08-26 13:54:12 -0700130 }
131
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700132 /**
133 * Configure the UI for the final confirmation interaction
134 */
135 private void establishFinalConfirmationState() {
Andres Moralesab61b0d2014-08-26 13:54:12 -0700136 mContentView.findViewById(R.id.execute_master_clear)
137 .setOnClickListener(mFinalClickListener);
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700138 }
139
140 @Override
141 public View onCreateView(LayoutInflater inflater, ViewGroup container,
142 Bundle savedInstanceState) {
Sudheer Shanka7dbbe132016-02-16 14:19:32 +0000143 final EnforcedAdmin admin = RestrictedLockUtils.checkIfRestrictionEnforced(
144 getActivity(), UserManager.DISALLOW_FACTORY_RESET, UserHandle.myUserId());
145 if (RestrictedLockUtils.hasBaseUserRestriction(getActivity(),
146 UserManager.DISALLOW_FACTORY_RESET, UserHandle.myUserId())) {
Julia Reynolds2c539332014-06-11 12:56:02 -0400147 return inflater.inflate(R.layout.master_clear_disallowed_screen, null);
Sudheer Shanka7dbbe132016-02-16 14:19:32 +0000148 } else if (admin != null) {
149 View view = inflater.inflate(R.layout.admin_support_details_empty_view, null);
150 ShowAdminSupportDetailsDialog.setAdminSupportDetails(getActivity(), view, admin, false);
151 view.setVisibility(View.VISIBLE);
152 return view;
Julia Reynolds2c539332014-06-11 12:56:02 -0400153 }
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700154 mContentView = inflater.inflate(R.layout.master_clear_confirm, null);
155 establishFinalConfirmationState();
Julia Reynoldsce25af42015-07-08 16:56:31 -0400156 setAccessibilityTitle();
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700157 return mContentView;
158 }
159
Julia Reynoldsce25af42015-07-08 16:56:31 -0400160 private void setAccessibilityTitle() {
161 CharSequence currentTitle = getActivity().getTitle();
162 TextView confirmationMessage =
163 (TextView) mContentView.findViewById(R.id.master_clear_confirm);
164 if (confirmationMessage != null) {
165 String accessibileText = new StringBuilder(currentTitle).append(",").append(
166 confirmationMessage.getText()).toString();
167 getActivity().setTitle(Utils.createAccessibleSequence(currentTitle, accessibileText));
168 }
169 }
170
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700171 @Override
172 public void onCreate(Bundle savedInstanceState) {
173 super.onCreate(savedInstanceState);
174
175 Bundle args = getArguments();
Andres Moralesc17ec1b2015-06-01 16:23:41 -0700176 mEraseSdCard = args != null
177 && args.getBoolean(MasterClear.ERASE_EXTERNAL_EXTRA);
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700178 }
Chris Wren8a963ba2015-03-20 10:29:14 -0400179
180 @Override
181 protected int getMetricsCategory() {
Chris Wren9d1bfd12016-01-26 18:04:01 -0500182 return MetricsEvent.MASTER_CLEAR_CONFIRM;
Chris Wren8a963ba2015-03-20 10:29:14 -0400183 }
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700184}