blob: 697c5c9898e8e68382cf80aabbb1c5cc976b10bb [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;
Julia Reynolds2c539332014-06-11 12:56:02 -040025import android.os.UserManager;
Russell Brennerff8a6802015-11-18 09:13:31 -080026import android.provider.Settings;
Jason Monk39b46742015-09-10 15:52:51 -040027import android.service.persistentdata.PersistentDataBlockManager;
Amith Yamasanib14e1e02010-11-02 09:52:29 -070028import android.view.LayoutInflater;
29import android.view.View;
30import android.view.ViewGroup;
31import android.widget.Button;
Julia Reynoldsce25af42015-07-08 16:56:31 -040032import android.widget.TextView;
Amith Yamasanib14e1e02010-11-02 09:52:29 -070033
Chris Wren9d1bfd12016-01-26 18:04:01 -050034import com.android.internal.logging.MetricsProto.MetricsEvent;
Jason Monk39b46742015-09-10 15:52:51 -040035
Amith Yamasanib14e1e02010-11-02 09:52:29 -070036/**
37 * Confirm and execute a reset of the device to a clean "just out of the box"
38 * state. Multiple confirmations are required: first, a general "are you sure
39 * you want to do this?" prompt, followed by a keyguard pattern trace if the user
40 * has defined one, followed by a final strongly-worded "THIS WILL ERASE EVERYTHING
41 * ON THE PHONE" prompt. If at any time the phone is allowed to go to sleep, is
42 * locked, et cetera, then the confirmation sequence is abandoned.
43 *
44 * This is the confirmation screen.
45 */
Chris Wren8a963ba2015-03-20 10:29:14 -040046public class MasterClearConfirm extends InstrumentedFragment {
Amith Yamasanib14e1e02010-11-02 09:52:29 -070047
48 private View mContentView;
49 private boolean mEraseSdCard;
Amith Yamasanib14e1e02010-11-02 09:52:29 -070050
51 /**
52 * The user has gone through the multiple confirmation, so now we go ahead
53 * and invoke the Checkin Service to reset the device to its factory-default
54 * state (rebooting in the process).
55 */
56 private Button.OnClickListener mFinalClickListener = new Button.OnClickListener() {
57
58 public void onClick(View v) {
59 if (Utils.isMonkeyRunning()) {
60 return;
61 }
62
Andres Moralesab61b0d2014-08-26 13:54:12 -070063 final PersistentDataBlockManager pdbManager = (PersistentDataBlockManager)
Andres Morales7ab89292014-07-10 16:10:43 -070064 getActivity().getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
65
Russell Brennerde4fc8e2015-11-05 16:03:20 -080066 if (pdbManager != null && !pdbManager.getOemUnlockEnabled() &&
67 Settings.Global.getInt(getActivity().getContentResolver(),
68 Settings.Global.DEVICE_PROVISIONED, 0) != 0) {
69 // if OEM unlock is enabled, this will be wiped during FR process. If disabled, it
70 // will be wiped here, unless the device is still being provisioned, in which case
71 // the persistent data block will be preserved.
Andres Moralese6bf2a52014-09-08 13:14:00 -070072 new AsyncTask<Void, Void, Void>() {
Andres Moralesc17ec1b2015-06-01 16:23:41 -070073 int mOldOrientation;
74 ProgressDialog mProgressDialog;
75
Andres Moralese6bf2a52014-09-08 13:14:00 -070076 @Override
77 protected Void doInBackground(Void... params) {
78 pdbManager.wipe();
79 return null;
80 }
Andres Moralesab61b0d2014-08-26 13:54:12 -070081
Andres Moralese6bf2a52014-09-08 13:14:00 -070082 @Override
83 protected void onPostExecute(Void aVoid) {
Andres Moralesc17ec1b2015-06-01 16:23:41 -070084 mProgressDialog.hide();
Julia Reynolds8a388012015-08-19 16:19:55 -040085 if (getActivity() != null) {
86 getActivity().setRequestedOrientation(mOldOrientation);
87 doMasterClear();
88 }
Andres Moralese6bf2a52014-09-08 13:14:00 -070089 }
Andres Moralesc17ec1b2015-06-01 16:23:41 -070090
91 @Override
92 protected void onPreExecute() {
93 mProgressDialog = getProgressDialog();
94 mProgressDialog.show();
95
96 // need to prevent orientation changes as we're about to go into
97 // a long IO request, so we won't be able to access inflate resources on flash
98 mOldOrientation = getActivity().getRequestedOrientation();
99 getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
100 }
Andres Moralese6bf2a52014-09-08 13:14:00 -0700101 }.execute();
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700102 } else {
Andres Moralesab61b0d2014-08-26 13:54:12 -0700103 doMasterClear();
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700104 }
105 }
Andres Moralesab61b0d2014-08-26 13:54:12 -0700106
107 private ProgressDialog getProgressDialog() {
108 final ProgressDialog progressDialog = new ProgressDialog(getActivity());
109 progressDialog.setIndeterminate(true);
110 progressDialog.setCancelable(false);
111 progressDialog.setTitle(
112 getActivity().getString(R.string.master_clear_progress_title));
113 progressDialog.setMessage(
114 getActivity().getString(R.string.master_clear_progress_text));
115 return progressDialog;
116 }
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700117 };
118
Andres Moralesab61b0d2014-08-26 13:54:12 -0700119 private void doMasterClear() {
Rubin Xuccbdc572015-06-26 15:27:23 +0100120 Intent intent = new Intent(Intent.ACTION_MASTER_CLEAR);
121 intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
122 intent.putExtra(Intent.EXTRA_REASON, "MasterClearConfirm");
123 intent.putExtra(Intent.EXTRA_WIPE_EXTERNAL_STORAGE, mEraseSdCard);
124 getActivity().sendBroadcast(intent);
125 // Intent handling is asynchronous -- assume it will happen soon.
Andres Moralesab61b0d2014-08-26 13:54:12 -0700126 }
127
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700128 /**
129 * Configure the UI for the final confirmation interaction
130 */
131 private void establishFinalConfirmationState() {
Andres Moralesab61b0d2014-08-26 13:54:12 -0700132 mContentView.findViewById(R.id.execute_master_clear)
133 .setOnClickListener(mFinalClickListener);
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700134 }
135
136 @Override
137 public View onCreateView(LayoutInflater inflater, ViewGroup container,
138 Bundle savedInstanceState) {
Julia Reynolds2c539332014-06-11 12:56:02 -0400139 if (UserManager.get(getActivity()).hasUserRestriction(
140 UserManager.DISALLOW_FACTORY_RESET)) {
141 return inflater.inflate(R.layout.master_clear_disallowed_screen, null);
142 }
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700143 mContentView = inflater.inflate(R.layout.master_clear_confirm, null);
144 establishFinalConfirmationState();
Julia Reynoldsce25af42015-07-08 16:56:31 -0400145 setAccessibilityTitle();
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700146 return mContentView;
147 }
148
Julia Reynoldsce25af42015-07-08 16:56:31 -0400149 private void setAccessibilityTitle() {
150 CharSequence currentTitle = getActivity().getTitle();
151 TextView confirmationMessage =
152 (TextView) mContentView.findViewById(R.id.master_clear_confirm);
153 if (confirmationMessage != null) {
154 String accessibileText = new StringBuilder(currentTitle).append(",").append(
155 confirmationMessage.getText()).toString();
156 getActivity().setTitle(Utils.createAccessibleSequence(currentTitle, accessibileText));
157 }
158 }
159
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700160 @Override
161 public void onCreate(Bundle savedInstanceState) {
162 super.onCreate(savedInstanceState);
163
164 Bundle args = getArguments();
Andres Moralesc17ec1b2015-06-01 16:23:41 -0700165 mEraseSdCard = args != null
166 && args.getBoolean(MasterClear.ERASE_EXTERNAL_EXTRA);
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700167 }
Chris Wren8a963ba2015-03-20 10:29:14 -0400168
169 @Override
170 protected int getMetricsCategory() {
Chris Wren9d1bfd12016-01-26 18:04:01 -0500171 return MetricsEvent.MASTER_CLEAR_CONFIRM;
Chris Wren8a963ba2015-03-20 10:29:14 -0400172 }
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700173}