1 /* 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 17 package com.android.settings; 18 19 import com.android.internal.os.storage.ExternalStorageFormatter; 20 import com.android.internal.widget.LockPatternUtils; 21 22 import android.app.Activity; 23 import android.app.Fragment; 24 import android.content.Intent; 25 import android.content.res.Resources; 26 import android.os.Bundle; 27 import android.view.LayoutInflater; 28 import android.view.View; 29 import android.view.ViewGroup; 30 import android.widget.Button; 31 import android.widget.CheckBox; 32 33 /** 34 * Confirm and execute a reset of the device to a clean "just out of the box" 35 * state. Multiple confirmations are required: first, a general "are you sure 36 * you want to do this?" prompt, followed by a keyguard pattern trace if the user 37 * has defined one, followed by a final strongly-worded "THIS WILL ERASE EVERYTHING 38 * ON THE PHONE" prompt. If at any time the phone is allowed to go to sleep, is 39 * locked, et cetera, then the confirmation sequence is abandoned. 40 * 41 * This is the confirmation screen. 42 */ 43 public class MasterClearConfirm extends Fragment { 44 45 private View mContentView; 46 private boolean mEraseSdCard; 47 private Button mFinalButton; 48 49 /** 50 * The user has gone through the multiple confirmation, so now we go ahead 51 * and invoke the Checkin Service to reset the device to its factory-default 52 * state (rebooting in the process). 53 */ 54 private Button.OnClickListener mFinalClickListener = new Button.OnClickListener() { 55 56 public void onClick(View v) { 57 if (Utils.isMonkeyRunning()) { 58 return; 59 } 60 61 if (mEraseSdCard) { 62 Intent intent = new Intent(ExternalStorageFormatter.FORMAT_AND_FACTORY_RESET); 63 intent.setComponent(ExternalStorageFormatter.COMPONENT_NAME); 64 getActivity().startService(intent); 65 } else { 66 getActivity().sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR")); 67 // Intent handling is asynchronous -- assume it will happen soon. 68 } 69 } 70 }; 71 72 /** 73 * Configure the UI for the final confirmation interaction 74 */ 75 private void establishFinalConfirmationState() { 76 mFinalButton = (Button) mContentView.findViewById(R.id.execute_master_clear); 77 mFinalButton.setOnClickListener(mFinalClickListener); 78 } 79 80 @Override 81 public View onCreateView(LayoutInflater inflater, ViewGroup container, 82 Bundle savedInstanceState) { 83 mContentView = inflater.inflate(R.layout.master_clear_confirm, null); 84 establishFinalConfirmationState(); 85 return mContentView; 86 } 87 88 @Override 89 public void onCreate(Bundle savedInstanceState) { 90 super.onCreate(savedInstanceState); 91 92 Bundle args = getArguments(); 93 mEraseSdCard = args != null ? args.getBoolean(MasterClear.ERASE_EXTERNAL_EXTRA) : false; 94 } 95 } 96