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