The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 | |
Maurice Lam | 2eb170c | 2017-04-28 16:18:47 -0700 | [diff] [blame^] | 19 | import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; |
| 20 | |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 21 | import android.accounts.Account; |
| 22 | import android.accounts.AccountManager; |
| 23 | import android.accounts.AuthenticatorDescription; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 24 | import android.app.Activity; |
Christine Franks | d7713c9 | 2017-01-20 11:24:14 -0800 | [diff] [blame] | 25 | import android.app.FragmentManager; |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 26 | import android.content.Context; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 27 | import android.content.Intent; |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 28 | import android.content.pm.PackageManager; |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 29 | import android.content.pm.UserInfo; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 30 | import android.content.res.Resources; |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 31 | import android.graphics.drawable.Drawable; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 32 | import android.os.Bundle; |
Kenny Root | 3785e39 | 2011-01-18 15:14:32 -0800 | [diff] [blame] | 33 | import android.os.Environment; |
Ben Komalo | 2a32192 | 2011-09-07 16:42:34 -0700 | [diff] [blame] | 34 | import android.os.SystemProperties; |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 35 | import android.os.UserHandle; |
Amith Yamasani | 7eedcf4 | 2013-07-02 14:15:29 -0700 | [diff] [blame] | 36 | import android.os.UserManager; |
jackqdyulei | 0b3edc7 | 2016-12-13 17:07:08 -0800 | [diff] [blame] | 37 | import android.support.annotation.VisibleForTesting; |
qingxi | 072f286 | 2017-04-11 18:28:40 -0700 | [diff] [blame] | 38 | import android.telephony.euicc.EuiccManager; |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 39 | import android.util.Log; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 40 | import android.view.LayoutInflater; |
| 41 | import android.view.View; |
jackqdyulei | 0b3edc7 | 2016-12-13 17:07:08 -0800 | [diff] [blame] | 42 | import android.view.View.OnScrollChangeListener; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 43 | import android.view.ViewGroup; |
jackqdyulei | 0b3edc7 | 2016-12-13 17:07:08 -0800 | [diff] [blame] | 44 | import android.view.ViewTreeObserver.OnGlobalLayoutListener; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 45 | import android.widget.Button; |
Dianne Hackborn | 1337d0f | 2010-10-14 11:58:30 -0700 | [diff] [blame] | 46 | import android.widget.CheckBox; |
Fan Zhang | 6b2bb39 | 2016-09-28 09:07:44 -0700 | [diff] [blame] | 47 | import android.widget.ImageView; |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 48 | import android.widget.LinearLayout; |
jackqdyulei | 0b3edc7 | 2016-12-13 17:07:08 -0800 | [diff] [blame] | 49 | import android.widget.ScrollView; |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 50 | import android.widget.TextView; |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 51 | |
Tamas Berghammer | 265d3c2 | 2016-06-22 15:34:45 +0100 | [diff] [blame] | 52 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Maurice Lam | 2eb170c | 2017-04-28 16:18:47 -0700 | [diff] [blame^] | 53 | import com.android.settings.password.ChooseLockSettingsHelper; |
| 54 | import com.android.settings.password.ConfirmLockPattern; |
Christine Franks | d7713c9 | 2017-01-20 11:24:14 -0800 | [diff] [blame] | 55 | import com.android.settings.widget.CarrierDemoPasswordDialogFragment; |
Sudheer Shanka | 7dbbe13 | 2016-02-16 14:19:32 +0000 | [diff] [blame] | 56 | import com.android.settingslib.RestrictedLockUtils; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 57 | |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 58 | import java.util.List; |
| 59 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 60 | /** |
| 61 | * Confirm and execute a reset of the device to a clean "just out of the box" |
| 62 | * state. Multiple confirmations are required: first, a general "are you sure |
| 63 | * you want to do this?" prompt, followed by a keyguard pattern trace if the user |
| 64 | * has defined one, followed by a final strongly-worded "THIS WILL ERASE EVERYTHING |
| 65 | * ON THE PHONE" prompt. If at any time the phone is allowed to go to sleep, is |
| 66 | * locked, et cetera, then the confirmation sequence is abandoned. |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 67 | * |
| 68 | * This is the initial screen. |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 69 | */ |
Christine Franks | d7713c9 | 2017-01-20 11:24:14 -0800 | [diff] [blame] | 70 | public class MasterClear extends OptionsMenuFragment |
| 71 | implements CarrierDemoPasswordDialogFragment.Callback { |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 72 | private static final String TAG = "MasterClear"; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 73 | |
| 74 | private static final int KEYGUARD_REQUEST = 55; |
| 75 | |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 76 | static final String ERASE_EXTERNAL_EXTRA = "erase_sd"; |
qingxi | 072f286 | 2017-04-11 18:28:40 -0700 | [diff] [blame] | 77 | static final String ERASE_ESIMS_EXTRA = "erase_esim"; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 78 | |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 79 | private View mContentView; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 80 | private Button mInitiateButton; |
Dianne Hackborn | 1337d0f | 2010-10-14 11:58:30 -0700 | [diff] [blame] | 81 | private View mExternalStorageContainer; |
qingxi | 072f286 | 2017-04-11 18:28:40 -0700 | [diff] [blame] | 82 | @VisibleForTesting CheckBox mExternalStorage; |
| 83 | private View mEsimStorageContainer; |
| 84 | @VisibleForTesting CheckBox mEsimStorage; |
jackqdyulei | 0b3edc7 | 2016-12-13 17:07:08 -0800 | [diff] [blame] | 85 | private ScrollView mScrollView; |
| 86 | |
| 87 | private final OnGlobalLayoutListener mOnGlobalLayoutListener = new OnGlobalLayoutListener() { |
| 88 | @Override |
| 89 | public void onGlobalLayout() { |
| 90 | mScrollView.getViewTreeObserver().removeOnGlobalLayoutListener(mOnGlobalLayoutListener); |
| 91 | mInitiateButton.setEnabled(hasReachedBottom(mScrollView)); |
| 92 | } |
| 93 | }; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 94 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 95 | /** |
Jim Miller | 2deec7e | 2010-04-13 17:43:36 -0700 | [diff] [blame] | 96 | * Keyguard validation is run using the standard {@link ConfirmLockPattern} |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 97 | * component as a subactivity |
Jim Miller | 2deec7e | 2010-04-13 17:43:36 -0700 | [diff] [blame] | 98 | * @param request the request code to be returned once confirmation finishes |
| 99 | * @return true if confirmation launched |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 100 | */ |
Jim Miller | 2deec7e | 2010-04-13 17:43:36 -0700 | [diff] [blame] | 101 | private boolean runKeyguardConfirmation(int request) { |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 102 | Resources res = getActivity().getResources(); |
Jorim Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 103 | return new ChooseLockSettingsHelper(getActivity(), this).launchConfirmationActivity( |
| 104 | request, res.getText(R.string.master_clear_title)); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | @Override |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 108 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 109 | super.onActivityResult(requestCode, resultCode, data); |
| 110 | |
Julia Reynolds | 2c53933 | 2014-06-11 12:56:02 -0400 | [diff] [blame] | 111 | if (requestCode != KEYGUARD_REQUEST) { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 112 | return; |
| 113 | } |
| 114 | |
| 115 | // If the user entered a valid keyguard trace, present the final |
| 116 | // confirmation prompt; otherwise, go back to the initial state. |
| 117 | if (resultCode == Activity.RESULT_OK) { |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 118 | showFinalConfirmation(); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 119 | } else { |
| 120 | establishInitialState(); |
| 121 | } |
| 122 | } |
| 123 | |
qingxi | 072f286 | 2017-04-11 18:28:40 -0700 | [diff] [blame] | 124 | @VisibleForTesting |
| 125 | void showFinalConfirmation() { |
Stuart Scott | be90341 | 2014-07-24 19:22:06 -0700 | [diff] [blame] | 126 | Bundle args = new Bundle(); |
| 127 | args.putBoolean(ERASE_EXTERNAL_EXTRA, mExternalStorage.isChecked()); |
qingxi | 072f286 | 2017-04-11 18:28:40 -0700 | [diff] [blame] | 128 | args.putBoolean(ERASE_ESIMS_EXTRA, mEsimStorage.isChecked()); |
Fan Zhang | c6ca314 | 2017-02-14 15:02:35 -0800 | [diff] [blame] | 129 | ((SettingsActivity) getActivity()).startPreferencePanel( |
| 130 | this, MasterClearConfirm.class.getName(), |
Stuart Scott | be90341 | 2014-07-24 19:22:06 -0700 | [diff] [blame] | 131 | args, R.string.master_clear_confirm_title, null, null, 0); |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 132 | } |
| 133 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 134 | /** |
| 135 | * If the user clicks to begin the reset sequence, we next require a |
| 136 | * keyguard confirmation if the user has currently enabled one. If there |
| 137 | * is no keyguard available, we simply go to the final confirmation prompt. |
| 138 | */ |
Ben Komalo | 2a32192 | 2011-09-07 16:42:34 -0700 | [diff] [blame] | 139 | private final Button.OnClickListener mInitiateListener = new Button.OnClickListener() { |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 140 | |
| 141 | public void onClick(View v) { |
Christine Franks | d7713c9 | 2017-01-20 11:24:14 -0800 | [diff] [blame] | 142 | if ( Utils.isCarrierDemoUser(v.getContext())) { |
| 143 | // Require the carrier password before displaying the final confirmation. |
| 144 | final FragmentManager fm = getChildFragmentManager(); |
| 145 | if (fm != null && !fm.isDestroyed()) { |
| 146 | new CarrierDemoPasswordDialogFragment().show(fm, null /* tag */); |
| 147 | } |
| 148 | } else if (!runKeyguardConfirmation(KEYGUARD_REQUEST)) { |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 149 | showFinalConfirmation(); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 150 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 151 | } |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 152 | }; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 153 | |
Christine Franks | d7713c9 | 2017-01-20 11:24:14 -0800 | [diff] [blame] | 154 | @Override |
| 155 | public void onPasswordVerified() { |
| 156 | showFinalConfirmation(); |
| 157 | } |
| 158 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 159 | /** |
| 160 | * In its initial state, the activity presents a button for the user to |
| 161 | * click in order to initiate a confirmation sequence. This method is |
| 162 | * called from various other points in the code to reset the activity to |
| 163 | * this base state. |
Jim Miller | 47d380f | 2010-01-20 13:37:14 -0800 | [diff] [blame] | 164 | * |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 165 | * <p>Reinflating views from resources is expensive and prevents us from |
| 166 | * caching widget pointers, so we use a single-inflate pattern: we lazy- |
| 167 | * inflate each view, caching all of the widget pointers we'll need at the |
| 168 | * time, then simply reuse the inflated views directly whenever we need |
| 169 | * to change contents. |
| 170 | */ |
| 171 | private void establishInitialState() { |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 172 | mInitiateButton = (Button) mContentView.findViewById(R.id.initiate_master_clear); |
| 173 | mInitiateButton.setOnClickListener(mInitiateListener); |
| 174 | mExternalStorageContainer = mContentView.findViewById(R.id.erase_external_container); |
| 175 | mExternalStorage = (CheckBox) mContentView.findViewById(R.id.erase_external); |
qingxi | 072f286 | 2017-04-11 18:28:40 -0700 | [diff] [blame] | 176 | mEsimStorageContainer = mContentView.findViewById(R.id.erase_esim_container); |
| 177 | mEsimStorage = (CheckBox) mContentView.findViewById(R.id.erase_esim); |
jackqdyulei | 0b3edc7 | 2016-12-13 17:07:08 -0800 | [diff] [blame] | 178 | mScrollView = (ScrollView) mContentView.findViewById(R.id.master_clear_scrollview); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 179 | |
Kenny Root | 3785e39 | 2011-01-18 15:14:32 -0800 | [diff] [blame] | 180 | /* |
| 181 | * If the external storage is emulated, it will be erased with a factory |
| 182 | * reset at any rate. There is no need to have a separate option until |
| 183 | * we have a factory reset that only erases some directories and not |
Ben Komalo | 2a32192 | 2011-09-07 16:42:34 -0700 | [diff] [blame] | 184 | * others. Likewise, if it's non-removable storage, it could potentially have been |
| 185 | * encrypted, and will also need to be wiped. |
Kenny Root | 3785e39 | 2011-01-18 15:14:32 -0800 | [diff] [blame] | 186 | */ |
Ben Komalo | 2a32192 | 2011-09-07 16:42:34 -0700 | [diff] [blame] | 187 | boolean isExtStorageEmulated = Environment.isExternalStorageEmulated(); |
| 188 | if (isExtStorageEmulated |
| 189 | || (!Environment.isExternalStorageRemovable() && isExtStorageEncrypted())) { |
Kenny Root | 3785e39 | 2011-01-18 15:14:32 -0800 | [diff] [blame] | 190 | mExternalStorageContainer.setVisibility(View.GONE); |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 191 | |
Kenny Root | 3785e39 | 2011-01-18 15:14:32 -0800 | [diff] [blame] | 192 | final View externalOption = mContentView.findViewById(R.id.erase_external_option_text); |
| 193 | externalOption.setVisibility(View.GONE); |
| 194 | |
| 195 | final View externalAlsoErased = mContentView.findViewById(R.id.also_erases_external); |
| 196 | externalAlsoErased.setVisibility(View.VISIBLE); |
Ben Komalo | 2a32192 | 2011-09-07 16:42:34 -0700 | [diff] [blame] | 197 | |
| 198 | // If it's not emulated, it is on a separate partition but it means we're doing |
| 199 | // a force wipe due to encryption. |
| 200 | mExternalStorage.setChecked(!isExtStorageEmulated); |
Kenny Root | 3785e39 | 2011-01-18 15:14:32 -0800 | [diff] [blame] | 201 | } else { |
| 202 | mExternalStorageContainer.setOnClickListener(new View.OnClickListener() { |
| 203 | |
| 204 | @Override |
| 205 | public void onClick(View v) { |
| 206 | mExternalStorage.toggle(); |
| 207 | } |
| 208 | }); |
| 209 | } |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 210 | |
qingxi | 072f286 | 2017-04-11 18:28:40 -0700 | [diff] [blame] | 211 | EuiccManager euiccManager = |
| 212 | (EuiccManager) getActivity().getSystemService(Context.EUICC_SERVICE); |
| 213 | if (euiccManager.isEnabled()) { |
| 214 | mEsimStorageContainer.setOnClickListener(new View.OnClickListener() { |
| 215 | |
| 216 | @Override |
| 217 | public void onClick(View v) { |
| 218 | mEsimStorage.toggle(); |
| 219 | } |
| 220 | }); |
| 221 | } else { |
| 222 | mEsimStorageContainer.setVisibility(View.GONE); |
| 223 | } |
| 224 | |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 225 | final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE); |
| 226 | loadAccountList(um); |
Julia Reynolds | ce25af4 | 2015-07-08 16:56:31 -0400 | [diff] [blame] | 227 | StringBuffer contentDescription = new StringBuffer(); |
| 228 | View masterClearContainer = mContentView.findViewById(R.id.master_clear_container); |
| 229 | getContentDescription(masterClearContainer, contentDescription); |
| 230 | masterClearContainer.setContentDescription(contentDescription); |
jackqdyulei | 0b3edc7 | 2016-12-13 17:07:08 -0800 | [diff] [blame] | 231 | |
| 232 | // Set the status of initiateButton based on scrollview |
| 233 | mScrollView.setOnScrollChangeListener(new OnScrollChangeListener() { |
| 234 | @Override |
| 235 | public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, |
| 236 | int oldScrollY) { |
| 237 | if (v instanceof ScrollView && hasReachedBottom((ScrollView) v)) { |
| 238 | mInitiateButton.setEnabled(true); |
| 239 | } |
| 240 | } |
| 241 | }); |
| 242 | |
| 243 | // Set the initial state of the initiateButton |
| 244 | mScrollView.getViewTreeObserver().addOnGlobalLayoutListener(mOnGlobalLayoutListener); |
| 245 | } |
| 246 | |
| 247 | @VisibleForTesting |
| 248 | boolean hasReachedBottom(final ScrollView scrollView) { |
| 249 | if (scrollView.getChildCount() < 1) { |
| 250 | return true; |
| 251 | } |
| 252 | |
| 253 | final View view = scrollView.getChildAt(0); |
| 254 | final int diff = view.getBottom() - (scrollView.getHeight() + scrollView.getScrollY()); |
| 255 | |
| 256 | return diff <= 0; |
Julia Reynolds | ce25af4 | 2015-07-08 16:56:31 -0400 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | private void getContentDescription(View v, StringBuffer description) { |
Jason Monk | fda7741 | 2016-05-06 14:28:09 -0400 | [diff] [blame] | 260 | if (v.getVisibility() != View.VISIBLE) { |
| 261 | return; |
| 262 | } |
Julia Reynolds | ce25af4 | 2015-07-08 16:56:31 -0400 | [diff] [blame] | 263 | if (v instanceof ViewGroup) { |
| 264 | ViewGroup vGroup = (ViewGroup) v; |
| 265 | for (int i = 0; i < vGroup.getChildCount(); i++) { |
| 266 | View nextChild = vGroup.getChildAt(i); |
| 267 | getContentDescription(nextChild, description); |
| 268 | } |
| 269 | } else if (v instanceof TextView) { |
| 270 | TextView vText = (TextView) v; |
| 271 | description.append(vText.getText()); |
| 272 | description.append(","); // Allow Talkback to pause between sections. |
| 273 | } |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 274 | } |
| 275 | |
Ben Komalo | 2a32192 | 2011-09-07 16:42:34 -0700 | [diff] [blame] | 276 | private boolean isExtStorageEncrypted() { |
| 277 | String state = SystemProperties.get("vold.decrypt"); |
| 278 | return !"".equals(state); |
| 279 | } |
| 280 | |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 281 | private void loadAccountList(final UserManager um) { |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 282 | View accountsLabel = mContentView.findViewById(R.id.accounts_label); |
| 283 | LinearLayout contents = (LinearLayout)mContentView.findViewById(R.id.accounts); |
Amith Yamasani | 3f45de5 | 2011-09-22 14:34:17 -0700 | [diff] [blame] | 284 | contents.removeAllViews(); |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 285 | |
| 286 | Context context = getActivity(); |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 287 | final List<UserInfo> profiles = um.getProfiles(UserHandle.myUserId()); |
| 288 | final int profilesSize = profiles.size(); |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 289 | |
| 290 | AccountManager mgr = AccountManager.get(context); |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 291 | |
| 292 | LayoutInflater inflater = (LayoutInflater)context.getSystemService( |
| 293 | Context.LAYOUT_INFLATER_SERVICE); |
| 294 | |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 295 | int accountsCount = 0; |
| 296 | for (int profileIndex = 0; profileIndex < profilesSize; profileIndex++) { |
| 297 | final UserInfo userInfo = profiles.get(profileIndex); |
| 298 | final int profileId = userInfo.id; |
| 299 | final UserHandle userHandle = new UserHandle(profileId); |
| 300 | Account[] accounts = mgr.getAccountsAsUser(profileId); |
| 301 | final int N = accounts.length; |
| 302 | if (N == 0) { |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 303 | continue; |
| 304 | } |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 305 | accountsCount += N; |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 306 | |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 307 | AuthenticatorDescription[] descs = AccountManager.get(context) |
| 308 | .getAuthenticatorTypesAsUser(profileId); |
| 309 | final int M = descs.length; |
| 310 | |
Bartosz Fabianowski | 30ba868 | 2017-04-19 11:51:43 +0200 | [diff] [blame] | 311 | if (profilesSize > 1) { |
| 312 | View titleView = Utils.inflateCategoryHeader(inflater, contents); |
| 313 | final TextView titleText = (TextView) titleView.findViewById(android.R.id.title); |
| 314 | titleText.setText(userInfo.isManagedProfile() ? R.string.category_work |
| 315 | : R.string.category_personal); |
| 316 | contents.addView(titleView); |
| 317 | } |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 318 | |
| 319 | for (int i = 0; i < N; i++) { |
| 320 | Account account = accounts[i]; |
| 321 | AuthenticatorDescription desc = null; |
| 322 | for (int j = 0; j < M; j++) { |
| 323 | if (account.type.equals(descs[j].type)) { |
| 324 | desc = descs[j]; |
| 325 | break; |
| 326 | } |
| 327 | } |
| 328 | if (desc == null) { |
| 329 | Log.w(TAG, "No descriptor for account name=" + account.name |
| 330 | + " type=" + account.type); |
| 331 | continue; |
| 332 | } |
| 333 | Drawable icon = null; |
| 334 | try { |
| 335 | if (desc.iconId != 0) { |
Zoltan Szatmary-Ban | 546790c | 2014-12-02 17:22:10 +0000 | [diff] [blame] | 336 | Context authContext = context.createPackageContextAsUser(desc.packageName, |
| 337 | 0, userHandle); |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 338 | icon = context.getPackageManager().getUserBadgedIcon( |
| 339 | authContext.getDrawable(desc.iconId), userHandle); |
| 340 | } |
| 341 | } catch (PackageManager.NameNotFoundException e) { |
Rubin Xu | d1ce82a | 2015-06-08 17:21:19 +0100 | [diff] [blame] | 342 | Log.w(TAG, "Bad package name for account type " + desc.type); |
| 343 | } catch (Resources.NotFoundException e) { |
| 344 | Log.w(TAG, "Invalid icon id for account type " + desc.type, e); |
| 345 | } |
| 346 | if (icon == null) { |
| 347 | icon = context.getPackageManager().getDefaultActivityIcon(); |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 348 | } |
| 349 | |
Fan Zhang | 6b2bb39 | 2016-09-28 09:07:44 -0700 | [diff] [blame] | 350 | View child = inflater.inflate(R.layout.master_clear_account, contents, false); |
| 351 | ((ImageView) child.findViewById(android.R.id.icon)).setImageDrawable(icon); |
| 352 | ((TextView) child.findViewById(android.R.id.title)).setText(account.name); |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 353 | contents.addView(child); |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 354 | } |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 355 | } |
| 356 | |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 357 | if (accountsCount > 0) { |
| 358 | accountsLabel.setVisibility(View.VISIBLE); |
| 359 | contents.setVisibility(View.VISIBLE); |
| 360 | } |
| 361 | // Checking for all other users and their profiles if any. |
| 362 | View otherUsers = mContentView.findViewById(R.id.other_users_present); |
| 363 | final boolean hasOtherUsers = (um.getUserCount() - profilesSize) > 0; |
| 364 | otherUsers.setVisibility(hasOtherUsers ? View.VISIBLE : View.GONE); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | @Override |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 368 | public View onCreateView(LayoutInflater inflater, ViewGroup container, |
| 369 | Bundle savedInstanceState) { |
Christine Franks | 1478222 | 2017-01-23 16:44:02 -0800 | [diff] [blame] | 370 | final Context context = getContext(); |
| 371 | final EnforcedAdmin admin = RestrictedLockUtils.checkIfRestrictionEnforced(context, |
| 372 | UserManager.DISALLOW_FACTORY_RESET, UserHandle.myUserId()); |
| 373 | final UserManager um = UserManager.get(context); |
| 374 | final boolean disallow = !um.isAdminUser() || RestrictedLockUtils.hasBaseUserRestriction( |
| 375 | context, UserManager.DISALLOW_FACTORY_RESET, UserHandle.myUserId()); |
| 376 | if (disallow && !Utils.isCarrierDemoUser(context)) { |
Julia Reynolds | 2c53933 | 2014-06-11 12:56:02 -0400 | [diff] [blame] | 377 | return inflater.inflate(R.layout.master_clear_disallowed_screen, null); |
Sudheer Shanka | 7dbbe13 | 2016-02-16 14:19:32 +0000 | [diff] [blame] | 378 | } else if (admin != null) { |
| 379 | View view = inflater.inflate(R.layout.admin_support_details_empty_view, null); |
| 380 | ShowAdminSupportDetailsDialog.setAdminSupportDetails(getActivity(), view, admin, false); |
| 381 | view.setVisibility(View.VISIBLE); |
| 382 | return view; |
Julia Reynolds | 2c53933 | 2014-06-11 12:56:02 -0400 | [diff] [blame] | 383 | } |
| 384 | |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 385 | mContentView = inflater.inflate(R.layout.master_clear, null); |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 386 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 387 | establishInitialState(); |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 388 | return mContentView; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 389 | } |
Chris Wren | 8a963ba | 2015-03-20 10:29:14 -0400 | [diff] [blame] | 390 | |
| 391 | @Override |
Fan Zhang | 6507613 | 2016-08-08 10:25:13 -0700 | [diff] [blame] | 392 | public int getMetricsCategory() { |
Chris Wren | 9d1bfd1 | 2016-01-26 18:04:01 -0500 | [diff] [blame] | 393 | return MetricsEvent.MASTER_CLEAR; |
Chris Wren | 8a963ba | 2015-03-20 10:29:14 -0400 | [diff] [blame] | 394 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 395 | } |