blob: da10b2a3feea4f9399356f4b2e76d801950a2089 [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;
Andres Moralesab61b0d2014-08-26 13:54:12 -070021import android.content.pm.ActivityInfo;
22import android.os.AsyncTask;
Russell Brennerde4fc8e2015-11-05 16:03:20 -080023import android.provider.Settings;
Andres Morales7ab89292014-07-10 16:10:43 -070024import android.service.persistentdata.PersistentDataBlockManager;
Julia Reynoldsce25af42015-07-08 16:56:31 -040025
Chris Wren8a963ba2015-03-20 10:29:14 -040026import com.android.internal.logging.MetricsLogger;
Amith Yamasanib14e1e02010-11-02 09:52:29 -070027
Amith Yamasanib14e1e02010-11-02 09:52:29 -070028import android.content.Intent;
Amith Yamasanib14e1e02010-11-02 09:52:29 -070029import android.os.Bundle;
Julia Reynolds2c539332014-06-11 12:56:02 -040030import android.os.UserManager;
Amith Yamasanib14e1e02010-11-02 09:52:29 -070031import android.view.LayoutInflater;
32import android.view.View;
33import android.view.ViewGroup;
34import android.widget.Button;
Julia Reynoldsce25af42015-07-08 16:56:31 -040035import android.widget.TextView;
Amith Yamasanib14e1e02010-11-02 09:52:29 -070036
37/**
38 * Confirm and execute a reset of the device to a clean "just out of the box"
39 * state. Multiple confirmations are required: first, a general "are you sure
40 * you want to do this?" prompt, followed by a keyguard pattern trace if the user
41 * has defined one, followed by a final strongly-worded "THIS WILL ERASE EVERYTHING
42 * ON THE PHONE" prompt. If at any time the phone is allowed to go to sleep, is
43 * locked, et cetera, then the confirmation sequence is abandoned.
44 *
45 * This is the confirmation screen.
46 */
Chris Wren8a963ba2015-03-20 10:29:14 -040047public class MasterClearConfirm extends InstrumentedFragment {
Amith Yamasanib14e1e02010-11-02 09:52:29 -070048
49 private View mContentView;
50 private boolean mEraseSdCard;
Amith Yamasanib14e1e02010-11-02 09:52:29 -070051
52 /**
53 * The user has gone through the multiple confirmation, so now we go ahead
54 * and invoke the Checkin Service to reset the device to its factory-default
55 * state (rebooting in the process).
56 */
57 private Button.OnClickListener mFinalClickListener = new Button.OnClickListener() {
58
59 public void onClick(View v) {
60 if (Utils.isMonkeyRunning()) {
61 return;
62 }
63
Andres Moralesab61b0d2014-08-26 13:54:12 -070064 final PersistentDataBlockManager pdbManager = (PersistentDataBlockManager)
Andres Morales7ab89292014-07-10 16:10:43 -070065 getActivity().getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
66
Russell Brennerde4fc8e2015-11-05 16:03:20 -080067 if (pdbManager != null && !pdbManager.getOemUnlockEnabled() &&
68 Settings.Global.getInt(getActivity().getContentResolver(),
69 Settings.Global.DEVICE_PROVISIONED, 0) != 0) {
70 // if OEM unlock is enabled, this will be wiped during FR process. If disabled, it
71 // will be wiped here, unless the device is still being provisioned, in which case
72 // the persistent data block will be preserved.
Andres Moralese6bf2a52014-09-08 13:14:00 -070073 new AsyncTask<Void, Void, Void>() {
Andres Moralesc17ec1b2015-06-01 16:23:41 -070074 int mOldOrientation;
75 ProgressDialog mProgressDialog;
76
Andres Moralese6bf2a52014-09-08 13:14:00 -070077 @Override
78 protected Void doInBackground(Void... params) {
79 pdbManager.wipe();
80 return null;
81 }
Andres Moralesab61b0d2014-08-26 13:54:12 -070082
Andres Moralese6bf2a52014-09-08 13:14:00 -070083 @Override
84 protected void onPostExecute(Void aVoid) {
Andres Moralesc17ec1b2015-06-01 16:23:41 -070085 mProgressDialog.hide();
86 getActivity().setRequestedOrientation(mOldOrientation);
Andres Moralese6bf2a52014-09-08 13:14:00 -070087 doMasterClear();
88 }
Andres Moralesc17ec1b2015-06-01 16:23:41 -070089
90 @Override
91 protected void onPreExecute() {
92 mProgressDialog = getProgressDialog();
93 mProgressDialog.show();
94
95 // need to prevent orientation changes as we're about to go into
96 // a long IO request, so we won't be able to access inflate resources on flash
97 mOldOrientation = getActivity().getRequestedOrientation();
98 getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
99 }
Andres Moralese6bf2a52014-09-08 13:14:00 -0700100 }.execute();
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700101 } else {
Andres Moralesab61b0d2014-08-26 13:54:12 -0700102 doMasterClear();
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700103 }
104 }
Andres Moralesab61b0d2014-08-26 13:54:12 -0700105
106 private ProgressDialog getProgressDialog() {
107 final ProgressDialog progressDialog = new ProgressDialog(getActivity());
108 progressDialog.setIndeterminate(true);
109 progressDialog.setCancelable(false);
110 progressDialog.setTitle(
111 getActivity().getString(R.string.master_clear_progress_title));
112 progressDialog.setMessage(
113 getActivity().getString(R.string.master_clear_progress_text));
114 return progressDialog;
115 }
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700116 };
117
Andres Moralesab61b0d2014-08-26 13:54:12 -0700118 private void doMasterClear() {
Rubin Xuccbdc572015-06-26 15:27:23 +0100119 Intent intent = new Intent(Intent.ACTION_MASTER_CLEAR);
120 intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
121 intent.putExtra(Intent.EXTRA_REASON, "MasterClearConfirm");
122 intent.putExtra(Intent.EXTRA_WIPE_EXTERNAL_STORAGE, mEraseSdCard);
123 getActivity().sendBroadcast(intent);
124 // Intent handling is asynchronous -- assume it will happen soon.
Andres Moralesab61b0d2014-08-26 13:54:12 -0700125 }
126
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700127 /**
128 * Configure the UI for the final confirmation interaction
129 */
130 private void establishFinalConfirmationState() {
Andres Moralesab61b0d2014-08-26 13:54:12 -0700131 mContentView.findViewById(R.id.execute_master_clear)
132 .setOnClickListener(mFinalClickListener);
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700133 }
134
135 @Override
136 public View onCreateView(LayoutInflater inflater, ViewGroup container,
137 Bundle savedInstanceState) {
Julia Reynolds2c539332014-06-11 12:56:02 -0400138 if (UserManager.get(getActivity()).hasUserRestriction(
139 UserManager.DISALLOW_FACTORY_RESET)) {
140 return inflater.inflate(R.layout.master_clear_disallowed_screen, null);
141 }
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700142 mContentView = inflater.inflate(R.layout.master_clear_confirm, null);
143 establishFinalConfirmationState();
Julia Reynoldsce25af42015-07-08 16:56:31 -0400144 setAccessibilityTitle();
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700145 return mContentView;
146 }
147
Julia Reynoldsce25af42015-07-08 16:56:31 -0400148 private void setAccessibilityTitle() {
149 CharSequence currentTitle = getActivity().getTitle();
150 TextView confirmationMessage =
151 (TextView) mContentView.findViewById(R.id.master_clear_confirm);
152 if (confirmationMessage != null) {
153 String accessibileText = new StringBuilder(currentTitle).append(",").append(
154 confirmationMessage.getText()).toString();
155 getActivity().setTitle(Utils.createAccessibleSequence(currentTitle, accessibileText));
156 }
157 }
158
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700159 @Override
160 public void onCreate(Bundle savedInstanceState) {
161 super.onCreate(savedInstanceState);
162
163 Bundle args = getArguments();
Andres Moralesc17ec1b2015-06-01 16:23:41 -0700164 mEraseSdCard = args != null
165 && args.getBoolean(MasterClear.ERASE_EXTERNAL_EXTRA);
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700166 }
Chris Wren8a963ba2015-03-20 10:29:14 -0400167
168 @Override
169 protected int getMetricsCategory() {
170 return MetricsLogger.MASTER_CLEAR_CONFIRM;
171 }
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700172}