blob: d14ad39a079d6e47395ccfa86633b1e441c953de [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 Morales7ab89292014-07-10 16:10:43 -070019import android.content.Context;
20import android.service.persistentdata.PersistentDataBlockManager;
Amith Yamasanib14e1e02010-11-02 09:52:29 -070021import com.android.internal.os.storage.ExternalStorageFormatter;
22import com.android.internal.widget.LockPatternUtils;
23
24import android.app.Activity;
25import android.app.Fragment;
26import android.content.Intent;
27import android.content.res.Resources;
28import 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;
34import android.widget.CheckBox;
35
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 */
46public class MasterClearConfirm extends Fragment {
47
48 private View mContentView;
49 private boolean mEraseSdCard;
50 private Button mFinalButton;
51
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 Morales7ab89292014-07-10 16:10:43 -070064 PersistentDataBlockManager pdbManager = (PersistentDataBlockManager)
65 getActivity().getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
66
67 if (pdbManager != null) {
Andres Moralesae583232014-08-06 17:01:19 -070068 // if OEM unlock is enabled, this will be wiped during FR process.
69 if (!pdbManager.getOemUnlockEnabled()) {
70 pdbManager.wipe();
71 }
Andres Morales7ab89292014-07-10 16:10:43 -070072 }
73
Amith Yamasanib14e1e02010-11-02 09:52:29 -070074 if (mEraseSdCard) {
75 Intent intent = new Intent(ExternalStorageFormatter.FORMAT_AND_FACTORY_RESET);
76 intent.setComponent(ExternalStorageFormatter.COMPONENT_NAME);
77 getActivity().startService(intent);
78 } else {
79 getActivity().sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR"));
80 // Intent handling is asynchronous -- assume it will happen soon.
81 }
82 }
83 };
84
85 /**
86 * Configure the UI for the final confirmation interaction
87 */
88 private void establishFinalConfirmationState() {
89 mFinalButton = (Button) mContentView.findViewById(R.id.execute_master_clear);
90 mFinalButton.setOnClickListener(mFinalClickListener);
91 }
92
93 @Override
94 public View onCreateView(LayoutInflater inflater, ViewGroup container,
95 Bundle savedInstanceState) {
Julia Reynolds2c539332014-06-11 12:56:02 -040096 if (UserManager.get(getActivity()).hasUserRestriction(
97 UserManager.DISALLOW_FACTORY_RESET)) {
98 return inflater.inflate(R.layout.master_clear_disallowed_screen, null);
99 }
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700100 mContentView = inflater.inflate(R.layout.master_clear_confirm, null);
101 establishFinalConfirmationState();
102 return mContentView;
103 }
104
105 @Override
106 public void onCreate(Bundle savedInstanceState) {
107 super.onCreate(savedInstanceState);
108
109 Bundle args = getArguments();
110 mEraseSdCard = args != null ? args.getBoolean(MasterClear.ERASE_EXTERNAL_EXTRA) : false;
111 }
112}