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