blob: bc3656abde6fb6f2cfdcd0c96daaed50d3d820ba [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;
Chris Wren8a963ba2015-03-20 10:29:14 -040024import com.android.internal.logging.MetricsLogger;
Amith Yamasanib14e1e02010-11-02 09:52:29 -070025import com.android.internal.os.storage.ExternalStorageFormatter;
Amith Yamasanib14e1e02010-11-02 09:52:29 -070026
Amith Yamasanib14e1e02010-11-02 09:52:29 -070027import android.app.Fragment;
28import 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;
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 final ProgressDialog progressDialog = getProgressDialog();
69 progressDialog.show();
Andres Morales7ab89292014-07-10 16:10:43 -070070
Andres Moralese6bf2a52014-09-08 13:14:00 -070071 // need to prevent orientation changes as we're about to go into
72 // a long IO request, so we won't be able to access inflate resources on flash
73 final int oldOrientation = getActivity().getRequestedOrientation();
74 getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
75 new AsyncTask<Void, Void, Void>() {
76 @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) {
84 progressDialog.hide();
85 getActivity().setRequestedOrientation(oldOrientation);
86 doMasterClear();
87 }
88 }.execute();
Amith Yamasanib14e1e02010-11-02 09:52:29 -070089 } else {
Andres Moralesab61b0d2014-08-26 13:54:12 -070090 doMasterClear();
Amith Yamasanib14e1e02010-11-02 09:52:29 -070091 }
92 }
Andres Moralesab61b0d2014-08-26 13:54:12 -070093
94 private ProgressDialog getProgressDialog() {
95 final ProgressDialog progressDialog = new ProgressDialog(getActivity());
96 progressDialog.setIndeterminate(true);
97 progressDialog.setCancelable(false);
98 progressDialog.setTitle(
99 getActivity().getString(R.string.master_clear_progress_title));
100 progressDialog.setMessage(
101 getActivity().getString(R.string.master_clear_progress_text));
102 return progressDialog;
103 }
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700104 };
105
Andres Moralesab61b0d2014-08-26 13:54:12 -0700106 private void doMasterClear() {
107 if (mEraseSdCard) {
108 Intent intent = new Intent(ExternalStorageFormatter.FORMAT_AND_FACTORY_RESET);
Jeff Sharkey1de688d2014-09-24 13:57:07 -0700109 intent.putExtra(Intent.EXTRA_REASON, "MasterClearConfirm");
Andres Moralesab61b0d2014-08-26 13:54:12 -0700110 intent.setComponent(ExternalStorageFormatter.COMPONENT_NAME);
111 getActivity().startService(intent);
112 } else {
Jeff Sharkey1de688d2014-09-24 13:57:07 -0700113 Intent intent = new Intent(Intent.ACTION_MASTER_CLEAR);
114 intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
115 intent.putExtra(Intent.EXTRA_REASON, "MasterClearConfirm");
116 getActivity().sendBroadcast(intent);
Andres Moralesab61b0d2014-08-26 13:54:12 -0700117 // Intent handling is asynchronous -- assume it will happen soon.
118 }
119 }
120
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700121 /**
122 * Configure the UI for the final confirmation interaction
123 */
124 private void establishFinalConfirmationState() {
Andres Moralesab61b0d2014-08-26 13:54:12 -0700125 mContentView.findViewById(R.id.execute_master_clear)
126 .setOnClickListener(mFinalClickListener);
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700127 }
128
129 @Override
130 public View onCreateView(LayoutInflater inflater, ViewGroup container,
131 Bundle savedInstanceState) {
Julia Reynolds2c539332014-06-11 12:56:02 -0400132 if (UserManager.get(getActivity()).hasUserRestriction(
133 UserManager.DISALLOW_FACTORY_RESET)) {
134 return inflater.inflate(R.layout.master_clear_disallowed_screen, null);
135 }
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700136 mContentView = inflater.inflate(R.layout.master_clear_confirm, null);
137 establishFinalConfirmationState();
138 return mContentView;
139 }
140
141 @Override
142 public void onCreate(Bundle savedInstanceState) {
143 super.onCreate(savedInstanceState);
144
145 Bundle args = getArguments();
Andres Moralesab61b0d2014-08-26 13:54:12 -0700146 mEraseSdCard = args != null && args.getBoolean(MasterClear.ERASE_EXTERNAL_EXTRA);
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700147 }
Chris Wren8a963ba2015-03-20 10:29:14 -0400148
149 @Override
150 protected int getMetricsCategory() {
151 return MetricsLogger.MASTER_CLEAR_CONFIRM;
152 }
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700153}