1b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani/* 2b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani * Copyright (C) 2010 The Android Open Source Project 3b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani * 4b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani * Licensed under the Apache License, Version 2.0 (the "License"); 5b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani * you may not use this file except in compliance with the License. 6b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani * You may obtain a copy of the License at 7b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani * 8b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani * http://www.apache.org/licenses/LICENSE-2.0 9b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani * 10b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani * Unless required by applicable law or agreed to in writing, software 11b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani * distributed under the License is distributed on an "AS IS" BASIS, 12b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani * See the License for the specific language governing permissions and 14b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani * limitations under the License. 15b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani */ 16b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani 17b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasanipackage com.android.settings; 18b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani 19b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasaniimport com.android.internal.os.storage.ExternalStorageFormatter; 20b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasaniimport com.android.internal.widget.LockPatternUtils; 21b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani 22b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasaniimport android.app.Activity; 23b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasaniimport android.app.Fragment; 24b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasaniimport android.content.Intent; 25b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasaniimport android.content.res.Resources; 26b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasaniimport android.os.Bundle; 27b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasaniimport android.view.LayoutInflater; 28b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasaniimport android.view.View; 29b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasaniimport android.view.ViewGroup; 30b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasaniimport android.widget.Button; 31b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasaniimport android.widget.CheckBox; 32b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani 33b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani/** 34b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani * Confirm and execute a reset of the device to a clean "just out of the box" 35b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani * state. Multiple confirmations are required: first, a general "are you sure 36b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani * you want to do this?" prompt, followed by a keyguard pattern trace if the user 37b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani * has defined one, followed by a final strongly-worded "THIS WILL ERASE EVERYTHING 38b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani * ON THE PHONE" prompt. If at any time the phone is allowed to go to sleep, is 39b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani * locked, et cetera, then the confirmation sequence is abandoned. 40b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani * 41b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani * This is the confirmation screen. 42b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani */ 43b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasanipublic class MasterClearConfirm extends Fragment { 44b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani 45b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani private View mContentView; 46b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani private boolean mEraseSdCard; 47b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani private Button mFinalButton; 48b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani 49b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani /** 50b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani * The user has gone through the multiple confirmation, so now we go ahead 51b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani * and invoke the Checkin Service to reset the device to its factory-default 52b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani * state (rebooting in the process). 53b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani */ 54b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani private Button.OnClickListener mFinalClickListener = new Button.OnClickListener() { 55b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani 56b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani public void onClick(View v) { 57b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani if (Utils.isMonkeyRunning()) { 58b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani return; 59b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani } 60b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani 61b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani if (mEraseSdCard) { 62b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani Intent intent = new Intent(ExternalStorageFormatter.FORMAT_AND_FACTORY_RESET); 63b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani intent.setComponent(ExternalStorageFormatter.COMPONENT_NAME); 64b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani getActivity().startService(intent); 65b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani } else { 66b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani getActivity().sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR")); 67b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani // Intent handling is asynchronous -- assume it will happen soon. 68b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani } 69b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani } 70b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani }; 71b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani 72b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani /** 73b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani * Configure the UI for the final confirmation interaction 74b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani */ 75b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani private void establishFinalConfirmationState() { 76b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani mFinalButton = (Button) mContentView.findViewById(R.id.execute_master_clear); 77b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani mFinalButton.setOnClickListener(mFinalClickListener); 78b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani } 79b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani 80b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani @Override 81b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani public View onCreateView(LayoutInflater inflater, ViewGroup container, 82b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani Bundle savedInstanceState) { 83b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani mContentView = inflater.inflate(R.layout.master_clear_confirm, null); 84b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani establishFinalConfirmationState(); 85b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani return mContentView; 86b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani } 87b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani 88b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani @Override 89b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani public void onCreate(Bundle savedInstanceState) { 90b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani super.onCreate(savedInstanceState); 91b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani 92b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani Bundle args = getArguments(); 93b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani mEraseSdCard = args != null ? args.getBoolean(MasterClear.ERASE_EXTERNAL_EXTRA) : false; 94b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani } 95b14e1e04939ca610fd5f2439f879265450b0a6cdAmith Yamasani} 96