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