Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 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 | |
Andres Morales | 7ab8929 | 2014-07-10 16:10:43 -0700 | [diff] [blame] | 19 | import android.content.Context; |
| 20 | import android.service.persistentdata.PersistentDataBlockManager; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 21 | import com.android.internal.os.storage.ExternalStorageFormatter; |
| 22 | import com.android.internal.widget.LockPatternUtils; |
| 23 | |
| 24 | import android.app.Activity; |
| 25 | import android.app.Fragment; |
| 26 | import android.content.Intent; |
| 27 | import android.content.res.Resources; |
| 28 | import android.os.Bundle; |
Julia Reynolds | 2c53933 | 2014-06-11 12:56:02 -0400 | [diff] [blame] | 29 | import android.os.UserManager; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 30 | import android.view.LayoutInflater; |
| 31 | import android.view.View; |
| 32 | import android.view.ViewGroup; |
| 33 | import android.widget.Button; |
| 34 | import 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 | */ |
| 46 | public 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 Morales | 7ab8929 | 2014-07-10 16:10:43 -0700 | [diff] [blame] | 64 | PersistentDataBlockManager pdbManager = (PersistentDataBlockManager) |
| 65 | getActivity().getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE); |
| 66 | |
| 67 | if (pdbManager != null) { |
| 68 | pdbManager.wipe(); |
| 69 | } |
| 70 | |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 71 | if (mEraseSdCard) { |
| 72 | Intent intent = new Intent(ExternalStorageFormatter.FORMAT_AND_FACTORY_RESET); |
| 73 | intent.setComponent(ExternalStorageFormatter.COMPONENT_NAME); |
| 74 | getActivity().startService(intent); |
| 75 | } else { |
| 76 | getActivity().sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR")); |
| 77 | // Intent handling is asynchronous -- assume it will happen soon. |
| 78 | } |
| 79 | } |
| 80 | }; |
| 81 | |
| 82 | /** |
| 83 | * Configure the UI for the final confirmation interaction |
| 84 | */ |
| 85 | private void establishFinalConfirmationState() { |
| 86 | mFinalButton = (Button) mContentView.findViewById(R.id.execute_master_clear); |
| 87 | mFinalButton.setOnClickListener(mFinalClickListener); |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public View onCreateView(LayoutInflater inflater, ViewGroup container, |
| 92 | Bundle savedInstanceState) { |
Julia Reynolds | 2c53933 | 2014-06-11 12:56:02 -0400 | [diff] [blame] | 93 | if (UserManager.get(getActivity()).hasUserRestriction( |
| 94 | UserManager.DISALLOW_FACTORY_RESET)) { |
| 95 | return inflater.inflate(R.layout.master_clear_disallowed_screen, null); |
| 96 | } |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 97 | mContentView = inflater.inflate(R.layout.master_clear_confirm, null); |
| 98 | establishFinalConfirmationState(); |
| 99 | return mContentView; |
| 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public void onCreate(Bundle savedInstanceState) { |
| 104 | super.onCreate(savedInstanceState); |
| 105 | |
| 106 | Bundle args = getArguments(); |
| 107 | mEraseSdCard = args != null ? args.getBoolean(MasterClear.ERASE_EXTERNAL_EXTRA) : false; |
| 108 | } |
| 109 | } |