blob: 7319a4e98dd0129032a8aade0cc719baaa78bbd3 [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;
Andres Morales7ab89292014-07-10 16:10:43 -070023import android.service.persistentdata.PersistentDataBlockManager;
Julia Reynoldsce25af42015-07-08 16:56:31 -040024
Chris Wren8a963ba2015-03-20 10:29:14 -040025import com.android.internal.logging.MetricsLogger;
Amith Yamasanib14e1e02010-11-02 09:52:29 -070026
Amith Yamasanib14e1e02010-11-02 09:52:29 -070027import android.content.Intent;
Amith Yamasanib14e1e02010-11-02 09:52:29 -070028import android.os.Bundle;
Julia Reynolds2c539332014-06-11 12:56:02 -040029import android.os.UserManager;
Amith Yamasanib14e1e02010-11-02 09:52:29 -070030import android.view.LayoutInflater;
31import android.view.View;
32import android.view.ViewGroup;
33import android.widget.Button;
Julia Reynoldsce25af42015-07-08 16:56:31 -040034import android.widget.TextView;
Amith Yamasanib14e1e02010-11-02 09:52:29 -070035
36/**
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
Andres Moralese6bf2a52014-09-08 13:14:00 -070066 if (pdbManager != null && !pdbManager.getOemUnlockEnabled()) {
Andres Moralesae583232014-08-06 17:01:19 -070067 // if OEM unlock is enabled, this will be wiped during FR process.
Andres Moralese6bf2a52014-09-08 13:14:00 -070068 new AsyncTask<Void, Void, Void>() {
Andres Moralesc17ec1b2015-06-01 16:23:41 -070069 int mOldOrientation;
70 ProgressDialog mProgressDialog;
71
Andres Moralese6bf2a52014-09-08 13:14:00 -070072 @Override
73 protected Void doInBackground(Void... params) {
74 pdbManager.wipe();
75 return null;
76 }
Andres Moralesab61b0d2014-08-26 13:54:12 -070077
Andres Moralese6bf2a52014-09-08 13:14:00 -070078 @Override
79 protected void onPostExecute(Void aVoid) {
Andres Moralesc17ec1b2015-06-01 16:23:41 -070080 mProgressDialog.hide();
81 getActivity().setRequestedOrientation(mOldOrientation);
Andres Moralese6bf2a52014-09-08 13:14:00 -070082 doMasterClear();
83 }
Andres Moralesc17ec1b2015-06-01 16:23:41 -070084
85 @Override
86 protected void onPreExecute() {
87 mProgressDialog = getProgressDialog();
88 mProgressDialog.show();
89
90 // need to prevent orientation changes as we're about to go into
91 // a long IO request, so we won't be able to access inflate resources on flash
92 mOldOrientation = getActivity().getRequestedOrientation();
93 getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
94 }
Andres Moralese6bf2a52014-09-08 13:14:00 -070095 }.execute();
Amith Yamasanib14e1e02010-11-02 09:52:29 -070096 } else {
Andres Moralesab61b0d2014-08-26 13:54:12 -070097 doMasterClear();
Amith Yamasanib14e1e02010-11-02 09:52:29 -070098 }
99 }
Andres Moralesab61b0d2014-08-26 13:54:12 -0700100
101 private ProgressDialog getProgressDialog() {
102 final ProgressDialog progressDialog = new ProgressDialog(getActivity());
103 progressDialog.setIndeterminate(true);
104 progressDialog.setCancelable(false);
105 progressDialog.setTitle(
106 getActivity().getString(R.string.master_clear_progress_title));
107 progressDialog.setMessage(
108 getActivity().getString(R.string.master_clear_progress_text));
109 return progressDialog;
110 }
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700111 };
112
Andres Moralesab61b0d2014-08-26 13:54:12 -0700113 private void doMasterClear() {
Rubin Xuccbdc572015-06-26 15:27:23 +0100114 Intent intent = new Intent(Intent.ACTION_MASTER_CLEAR);
115 intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
116 intent.putExtra(Intent.EXTRA_REASON, "MasterClearConfirm");
117 intent.putExtra(Intent.EXTRA_WIPE_EXTERNAL_STORAGE, mEraseSdCard);
118 getActivity().sendBroadcast(intent);
119 // Intent handling is asynchronous -- assume it will happen soon.
Andres Moralesab61b0d2014-08-26 13:54:12 -0700120 }
121
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700122 /**
123 * Configure the UI for the final confirmation interaction
124 */
125 private void establishFinalConfirmationState() {
Andres Moralesab61b0d2014-08-26 13:54:12 -0700126 mContentView.findViewById(R.id.execute_master_clear)
127 .setOnClickListener(mFinalClickListener);
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700128 }
129
130 @Override
131 public View onCreateView(LayoutInflater inflater, ViewGroup container,
132 Bundle savedInstanceState) {
Julia Reynolds2c539332014-06-11 12:56:02 -0400133 if (UserManager.get(getActivity()).hasUserRestriction(
134 UserManager.DISALLOW_FACTORY_RESET)) {
135 return inflater.inflate(R.layout.master_clear_disallowed_screen, null);
136 }
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700137 mContentView = inflater.inflate(R.layout.master_clear_confirm, null);
138 establishFinalConfirmationState();
Julia Reynoldsce25af42015-07-08 16:56:31 -0400139 setAccessibilityTitle();
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700140 return mContentView;
141 }
142
Julia Reynoldsce25af42015-07-08 16:56:31 -0400143 private void setAccessibilityTitle() {
144 CharSequence currentTitle = getActivity().getTitle();
145 TextView confirmationMessage =
146 (TextView) mContentView.findViewById(R.id.master_clear_confirm);
147 if (confirmationMessage != null) {
148 String accessibileText = new StringBuilder(currentTitle).append(",").append(
149 confirmationMessage.getText()).toString();
150 getActivity().setTitle(Utils.createAccessibleSequence(currentTitle, accessibileText));
151 }
152 }
153
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700154 @Override
155 public void onCreate(Bundle savedInstanceState) {
156 super.onCreate(savedInstanceState);
157
158 Bundle args = getArguments();
Andres Moralesc17ec1b2015-06-01 16:23:41 -0700159 mEraseSdCard = args != null
160 && args.getBoolean(MasterClear.ERASE_EXTERNAL_EXTRA);
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700161 }
Chris Wren8a963ba2015-03-20 10:29:14 -0400162
163 @Override
164 protected int getMetricsCategory() {
165 return MetricsLogger.MASTER_CLEAR_CONFIRM;
166 }
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700167}