blob: a3caf2946a621b8fc9f6ffce5dd7df0038ac1bcb [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;
Jason Monk39b46742015-09-10 15:52:51 -040026import android.service.persistentdata.PersistentDataBlockManager;
Amith Yamasanib14e1e02010-11-02 09:52:29 -070027import android.view.LayoutInflater;
28import android.view.View;
29import android.view.ViewGroup;
30import android.widget.Button;
Julia Reynoldsce25af42015-07-08 16:56:31 -040031import android.widget.TextView;
Amith Yamasanib14e1e02010-11-02 09:52:29 -070032
Jason Monk39b46742015-09-10 15:52:51 -040033import com.android.internal.logging.MetricsLogger;
34
Amith Yamasanib14e1e02010-11-02 09:52:29 -070035/**
36 * Confirm and execute a reset of the device to a clean "just out of the box"
37 * state. Multiple confirmations are required: first, a general "are you sure
38 * you want to do this?" prompt, followed by a keyguard pattern trace if the user
39 * has defined one, followed by a final strongly-worded "THIS WILL ERASE EVERYTHING
40 * ON THE PHONE" prompt. If at any time the phone is allowed to go to sleep, is
41 * locked, et cetera, then the confirmation sequence is abandoned.
42 *
43 * This is the confirmation screen.
44 */
Chris Wren8a963ba2015-03-20 10:29:14 -040045public class MasterClearConfirm extends InstrumentedFragment {
Amith Yamasanib14e1e02010-11-02 09:52:29 -070046
47 private View mContentView;
48 private boolean mEraseSdCard;
Amith Yamasanib14e1e02010-11-02 09:52:29 -070049
50 /**
51 * The user has gone through the multiple confirmation, so now we go ahead
52 * and invoke the Checkin Service to reset the device to its factory-default
53 * state (rebooting in the process).
54 */
55 private Button.OnClickListener mFinalClickListener = new Button.OnClickListener() {
56
57 public void onClick(View v) {
58 if (Utils.isMonkeyRunning()) {
59 return;
60 }
61
Andres Moralesab61b0d2014-08-26 13:54:12 -070062 final PersistentDataBlockManager pdbManager = (PersistentDataBlockManager)
Andres Morales7ab89292014-07-10 16:10:43 -070063 getActivity().getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
64
Andres Moralese6bf2a52014-09-08 13:14:00 -070065 if (pdbManager != null && !pdbManager.getOemUnlockEnabled()) {
Andres Moralesae583232014-08-06 17:01:19 -070066 // if OEM unlock is enabled, this will be wiped during FR process.
Andres Moralese6bf2a52014-09-08 13:14:00 -070067 new AsyncTask<Void, Void, Void>() {
Andres Moralesc17ec1b2015-06-01 16:23:41 -070068 int mOldOrientation;
69 ProgressDialog mProgressDialog;
70
Andres Moralese6bf2a52014-09-08 13:14:00 -070071 @Override
72 protected Void doInBackground(Void... params) {
73 pdbManager.wipe();
74 return null;
75 }
Andres Moralesab61b0d2014-08-26 13:54:12 -070076
Andres Moralese6bf2a52014-09-08 13:14:00 -070077 @Override
78 protected void onPostExecute(Void aVoid) {
Andres Moralesc17ec1b2015-06-01 16:23:41 -070079 mProgressDialog.hide();
Julia Reynolds8a388012015-08-19 16:19:55 -040080 if (getActivity() != null) {
81 getActivity().setRequestedOrientation(mOldOrientation);
82 doMasterClear();
83 }
Andres Moralese6bf2a52014-09-08 13:14:00 -070084 }
Andres Moralesc17ec1b2015-06-01 16:23:41 -070085
86 @Override
87 protected void onPreExecute() {
88 mProgressDialog = getProgressDialog();
89 mProgressDialog.show();
90
91 // need to prevent orientation changes as we're about to go into
92 // a long IO request, so we won't be able to access inflate resources on flash
93 mOldOrientation = getActivity().getRequestedOrientation();
94 getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
95 }
Andres Moralese6bf2a52014-09-08 13:14:00 -070096 }.execute();
Amith Yamasanib14e1e02010-11-02 09:52:29 -070097 } else {
Andres Moralesab61b0d2014-08-26 13:54:12 -070098 doMasterClear();
Amith Yamasanib14e1e02010-11-02 09:52:29 -070099 }
100 }
Andres Moralesab61b0d2014-08-26 13:54:12 -0700101
102 private ProgressDialog getProgressDialog() {
103 final ProgressDialog progressDialog = new ProgressDialog(getActivity());
104 progressDialog.setIndeterminate(true);
105 progressDialog.setCancelable(false);
106 progressDialog.setTitle(
107 getActivity().getString(R.string.master_clear_progress_title));
108 progressDialog.setMessage(
109 getActivity().getString(R.string.master_clear_progress_text));
110 return progressDialog;
111 }
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700112 };
113
Andres Moralesab61b0d2014-08-26 13:54:12 -0700114 private void doMasterClear() {
Rubin Xuccbdc572015-06-26 15:27:23 +0100115 Intent intent = new Intent(Intent.ACTION_MASTER_CLEAR);
116 intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
117 intent.putExtra(Intent.EXTRA_REASON, "MasterClearConfirm");
118 intent.putExtra(Intent.EXTRA_WIPE_EXTERNAL_STORAGE, mEraseSdCard);
119 getActivity().sendBroadcast(intent);
120 // Intent handling is asynchronous -- assume it will happen soon.
Andres Moralesab61b0d2014-08-26 13:54:12 -0700121 }
122
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700123 /**
124 * Configure the UI for the final confirmation interaction
125 */
126 private void establishFinalConfirmationState() {
Andres Moralesab61b0d2014-08-26 13:54:12 -0700127 mContentView.findViewById(R.id.execute_master_clear)
128 .setOnClickListener(mFinalClickListener);
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700129 }
130
131 @Override
132 public View onCreateView(LayoutInflater inflater, ViewGroup container,
133 Bundle savedInstanceState) {
Julia Reynolds2c539332014-06-11 12:56:02 -0400134 if (UserManager.get(getActivity()).hasUserRestriction(
135 UserManager.DISALLOW_FACTORY_RESET)) {
136 return inflater.inflate(R.layout.master_clear_disallowed_screen, null);
137 }
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700138 mContentView = inflater.inflate(R.layout.master_clear_confirm, null);
139 establishFinalConfirmationState();
Julia Reynoldsce25af42015-07-08 16:56:31 -0400140 setAccessibilityTitle();
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700141 return mContentView;
142 }
143
Julia Reynoldsce25af42015-07-08 16:56:31 -0400144 private void setAccessibilityTitle() {
145 CharSequence currentTitle = getActivity().getTitle();
146 TextView confirmationMessage =
147 (TextView) mContentView.findViewById(R.id.master_clear_confirm);
148 if (confirmationMessage != null) {
149 String accessibileText = new StringBuilder(currentTitle).append(",").append(
150 confirmationMessage.getText()).toString();
151 getActivity().setTitle(Utils.createAccessibleSequence(currentTitle, accessibileText));
152 }
153 }
154
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700155 @Override
156 public void onCreate(Bundle savedInstanceState) {
157 super.onCreate(savedInstanceState);
158
159 Bundle args = getArguments();
Andres Moralesc17ec1b2015-06-01 16:23:41 -0700160 mEraseSdCard = args != null
161 && args.getBoolean(MasterClear.ERASE_EXTERNAL_EXTRA);
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700162 }
Chris Wren8a963ba2015-03-20 10:29:14 -0400163
164 @Override
165 protected int getMetricsCategory() {
166 return MetricsLogger.MASTER_CLEAR_CONFIRM;
167 }
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700168}