blob: 4ee17b810024382aa46d39b205f63154de849d35 [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
19import com.android.internal.os.storage.ExternalStorageFormatter;
20import com.android.internal.widget.LockPatternUtils;
21
22import android.app.Activity;
23import android.app.Fragment;
24import android.content.Intent;
25import android.content.res.Resources;
26import android.os.Bundle;
Julia Reynolds2c539332014-06-11 12:56:02 -040027import android.os.UserManager;
Amith Yamasanib14e1e02010-11-02 09:52:29 -070028import android.view.LayoutInflater;
29import android.view.View;
30import android.view.ViewGroup;
31import android.widget.Button;
32import android.widget.CheckBox;
33
34/**
35 * Confirm and execute a reset of the device to a clean "just out of the box"
36 * state. Multiple confirmations are required: first, a general "are you sure
37 * you want to do this?" prompt, followed by a keyguard pattern trace if the user
38 * has defined one, followed by a final strongly-worded "THIS WILL ERASE EVERYTHING
39 * ON THE PHONE" prompt. If at any time the phone is allowed to go to sleep, is
40 * locked, et cetera, then the confirmation sequence is abandoned.
41 *
42 * This is the confirmation screen.
43 */
44public class MasterClearConfirm extends Fragment {
45
46 private View mContentView;
47 private boolean mEraseSdCard;
48 private Button mFinalButton;
49
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
62 if (mEraseSdCard) {
63 Intent intent = new Intent(ExternalStorageFormatter.FORMAT_AND_FACTORY_RESET);
64 intent.setComponent(ExternalStorageFormatter.COMPONENT_NAME);
65 getActivity().startService(intent);
66 } else {
67 getActivity().sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR"));
68 // Intent handling is asynchronous -- assume it will happen soon.
69 }
70 }
71 };
72
73 /**
74 * Configure the UI for the final confirmation interaction
75 */
76 private void establishFinalConfirmationState() {
77 mFinalButton = (Button) mContentView.findViewById(R.id.execute_master_clear);
78 mFinalButton.setOnClickListener(mFinalClickListener);
79 }
80
81 @Override
82 public View onCreateView(LayoutInflater inflater, ViewGroup container,
83 Bundle savedInstanceState) {
Julia Reynolds2c539332014-06-11 12:56:02 -040084 if (UserManager.get(getActivity()).hasUserRestriction(
85 UserManager.DISALLOW_FACTORY_RESET)) {
86 return inflater.inflate(R.layout.master_clear_disallowed_screen, null);
87 }
Amith Yamasanib14e1e02010-11-02 09:52:29 -070088 mContentView = inflater.inflate(R.layout.master_clear_confirm, null);
89 establishFinalConfirmationState();
90 return mContentView;
91 }
92
93 @Override
94 public void onCreate(Bundle savedInstanceState) {
95 super.onCreate(savedInstanceState);
96
97 Bundle args = getArguments();
98 mEraseSdCard = args != null ? args.getBoolean(MasterClear.ERASE_EXTERNAL_EXTRA) : false;
99 }
100}