blob: 1bdd6f432fd76ac7efb1e68b9cf2dad0301d6385 [file] [log] [blame]
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001/*
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
17package com.android.settings;
18
Maurice Lam2eb170c2017-04-28 16:18:47 -070019import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
20
Joe Onoratob51886d2010-11-08 18:25:51 -080021import android.accounts.Account;
22import android.accounts.AccountManager;
23import android.accounts.AuthenticatorDescription;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080024import android.app.Activity;
Christine Franksa09eb382017-06-23 14:28:21 -070025import android.content.ComponentName;
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -070026import android.content.ContentResolver;
Joe Onoratob51886d2010-11-08 18:25:51 -080027import android.content.Context;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080028import android.content.Intent;
Joe Onoratob51886d2010-11-08 18:25:51 -080029import android.content.pm.PackageManager;
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +010030import android.content.pm.UserInfo;
Amith Yamasanib14e1e02010-11-02 09:52:29 -070031import android.content.res.Resources;
Joe Onoratob51886d2010-11-08 18:25:51 -080032import android.graphics.drawable.Drawable;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080033import android.os.Bundle;
Kenny Root3785e392011-01-18 15:14:32 -080034import android.os.Environment;
Ben Komalo2a321922011-09-07 16:42:34 -070035import android.os.SystemProperties;
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +010036import android.os.UserHandle;
Amith Yamasani7eedcf42013-07-02 14:15:29 -070037import android.os.UserManager;
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -070038import android.provider.Settings;
jackqdyulei0b3edc72016-12-13 17:07:08 -080039import android.support.annotation.VisibleForTesting;
qingxi072f2862017-04-11 18:28:40 -070040import android.telephony.euicc.EuiccManager;
Christine Franksa09eb382017-06-23 14:28:21 -070041import android.text.TextUtils;
Joe Onoratob51886d2010-11-08 18:25:51 -080042import android.util.Log;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080043import android.view.LayoutInflater;
44import android.view.View;
jackqdyulei0b3edc72016-12-13 17:07:08 -080045import android.view.View.OnScrollChangeListener;
Amith Yamasanib14e1e02010-11-02 09:52:29 -070046import android.view.ViewGroup;
jackqdyulei0b3edc72016-12-13 17:07:08 -080047import android.view.ViewTreeObserver.OnGlobalLayoutListener;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080048import android.widget.Button;
Dianne Hackborn1337d0f2010-10-14 11:58:30 -070049import android.widget.CheckBox;
Fan Zhang6b2bb392016-09-28 09:07:44 -070050import android.widget.ImageView;
Joe Onoratob51886d2010-11-08 18:25:51 -080051import android.widget.LinearLayout;
jackqdyulei0b3edc72016-12-13 17:07:08 -080052import android.widget.ScrollView;
Joe Onoratob51886d2010-11-08 18:25:51 -080053import android.widget.TextView;
Jason Monk39b46742015-09-10 15:52:51 -040054
Tamas Berghammer265d3c22016-06-22 15:34:45 +010055import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Maurice Lam2eb170c2017-04-28 16:18:47 -070056import com.android.settings.password.ChooseLockSettingsHelper;
57import com.android.settings.password.ConfirmLockPattern;
Sudheer Shanka7dbbe132016-02-16 14:19:32 +000058import com.android.settingslib.RestrictedLockUtils;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080059
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +010060import java.util.List;
61
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080062/**
63 * Confirm and execute a reset of the device to a clean "just out of the box"
64 * state. Multiple confirmations are required: first, a general "are you sure
65 * you want to do this?" prompt, followed by a keyguard pattern trace if the user
66 * has defined one, followed by a final strongly-worded "THIS WILL ERASE EVERYTHING
67 * ON THE PHONE" prompt. If at any time the phone is allowed to go to sleep, is
68 * locked, et cetera, then the confirmation sequence is abandoned.
Amith Yamasanib14e1e02010-11-02 09:52:29 -070069 *
70 * This is the initial screen.
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080071 */
Christine Franksa09eb382017-06-23 14:28:21 -070072public class MasterClear extends OptionsMenuFragment {
Joe Onoratob51886d2010-11-08 18:25:51 -080073 private static final String TAG = "MasterClear";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080074
75 private static final int KEYGUARD_REQUEST = 55;
76
Amith Yamasanib14e1e02010-11-02 09:52:29 -070077 static final String ERASE_EXTERNAL_EXTRA = "erase_sd";
qingxi072f2862017-04-11 18:28:40 -070078 static final String ERASE_ESIMS_EXTRA = "erase_esim";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080079
Amith Yamasanib14e1e02010-11-02 09:52:29 -070080 private View mContentView;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080081 private Button mInitiateButton;
Dianne Hackborn1337d0f2010-10-14 11:58:30 -070082 private View mExternalStorageContainer;
qingxi072f2862017-04-11 18:28:40 -070083 @VisibleForTesting CheckBox mExternalStorage;
84 private View mEsimStorageContainer;
85 @VisibleForTesting CheckBox mEsimStorage;
jackqdyulei0b3edc72016-12-13 17:07:08 -080086 private ScrollView mScrollView;
87
88 private final OnGlobalLayoutListener mOnGlobalLayoutListener = new OnGlobalLayoutListener() {
89 @Override
90 public void onGlobalLayout() {
91 mScrollView.getViewTreeObserver().removeOnGlobalLayoutListener(mOnGlobalLayoutListener);
92 mInitiateButton.setEnabled(hasReachedBottom(mScrollView));
93 }
94 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080095
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080096 /**
Jim Miller2deec7e2010-04-13 17:43:36 -070097 * Keyguard validation is run using the standard {@link ConfirmLockPattern}
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080098 * component as a subactivity
Jim Miller2deec7e2010-04-13 17:43:36 -070099 * @param request the request code to be returned once confirmation finishes
100 * @return true if confirmation launched
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800101 */
Jim Miller2deec7e2010-04-13 17:43:36 -0700102 private boolean runKeyguardConfirmation(int request) {
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700103 Resources res = getActivity().getResources();
Jorim Jaggi8a09b612015-04-06 17:47:18 -0700104 return new ChooseLockSettingsHelper(getActivity(), this).launchConfirmationActivity(
105 request, res.getText(R.string.master_clear_title));
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800106 }
107
108 @Override
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700109 public void onActivityResult(int requestCode, int resultCode, Intent data) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800110 super.onActivityResult(requestCode, resultCode, data);
111
Julia Reynolds2c539332014-06-11 12:56:02 -0400112 if (requestCode != KEYGUARD_REQUEST) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800113 return;
114 }
115
116 // If the user entered a valid keyguard trace, present the final
117 // confirmation prompt; otherwise, go back to the initial state.
118 if (resultCode == Activity.RESULT_OK) {
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700119 showFinalConfirmation();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800120 } else {
121 establishInitialState();
122 }
123 }
124
qingxi072f2862017-04-11 18:28:40 -0700125 @VisibleForTesting
126 void showFinalConfirmation() {
Stuart Scottbe903412014-07-24 19:22:06 -0700127 Bundle args = new Bundle();
128 args.putBoolean(ERASE_EXTERNAL_EXTRA, mExternalStorage.isChecked());
qingxi072f2862017-04-11 18:28:40 -0700129 args.putBoolean(ERASE_ESIMS_EXTRA, mEsimStorage.isChecked());
Fan Zhangc6ca3142017-02-14 15:02:35 -0800130 ((SettingsActivity) getActivity()).startPreferencePanel(
131 this, MasterClearConfirm.class.getName(),
Stuart Scottbe903412014-07-24 19:22:06 -0700132 args, R.string.master_clear_confirm_title, null, null, 0);
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700133 }
134
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800135 /**
136 * If the user clicks to begin the reset sequence, we next require a
137 * keyguard confirmation if the user has currently enabled one. If there
138 * is no keyguard available, we simply go to the final confirmation prompt.
Christine Franksa09eb382017-06-23 14:28:21 -0700139 *
140 * If the user is in demo mode, route to the demo mode app for confirmation.
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800141 */
Christine Franksa09eb382017-06-23 14:28:21 -0700142 @VisibleForTesting
143 protected final Button.OnClickListener mInitiateListener = new Button.OnClickListener() {
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700144
Christine Franksa09eb382017-06-23 14:28:21 -0700145 public void onClick(View view) {
146 final Context context = view.getContext();
147 if (Utils.isDemoUser(context)) {
148 final String packageName = Utils.getDemoModePackageName(context);
149 if (!TextUtils.isEmpty(packageName)) {
150 final Intent requestFactoryReset = new Intent()
151 .setPackage(packageName)
152 .setAction(Intent.ACTION_FACTORY_RESET);
153 context.startActivity(requestFactoryReset);
Christine Franksd7713c92017-01-20 11:24:14 -0800154 }
155 } else if (!runKeyguardConfirmation(KEYGUARD_REQUEST)) {
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700156 showFinalConfirmation();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800157 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800158 }
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700159 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800160
161 /**
162 * In its initial state, the activity presents a button for the user to
163 * click in order to initiate a confirmation sequence. This method is
164 * called from various other points in the code to reset the activity to
165 * this base state.
Jim Miller47d380f2010-01-20 13:37:14 -0800166 *
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800167 * <p>Reinflating views from resources is expensive and prevents us from
168 * caching widget pointers, so we use a single-inflate pattern: we lazy-
169 * inflate each view, caching all of the widget pointers we'll need at the
170 * time, then simply reuse the inflated views directly whenever we need
171 * to change contents.
172 */
173 private void establishInitialState() {
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700174 mInitiateButton = (Button) mContentView.findViewById(R.id.initiate_master_clear);
175 mInitiateButton.setOnClickListener(mInitiateListener);
176 mExternalStorageContainer = mContentView.findViewById(R.id.erase_external_container);
177 mExternalStorage = (CheckBox) mContentView.findViewById(R.id.erase_external);
qingxi072f2862017-04-11 18:28:40 -0700178 mEsimStorageContainer = mContentView.findViewById(R.id.erase_esim_container);
179 mEsimStorage = (CheckBox) mContentView.findViewById(R.id.erase_esim);
jackqdyulei0b3edc72016-12-13 17:07:08 -0800180 mScrollView = (ScrollView) mContentView.findViewById(R.id.master_clear_scrollview);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800181
Kenny Root3785e392011-01-18 15:14:32 -0800182 /*
183 * If the external storage is emulated, it will be erased with a factory
184 * reset at any rate. There is no need to have a separate option until
185 * we have a factory reset that only erases some directories and not
Ben Komalo2a321922011-09-07 16:42:34 -0700186 * others. Likewise, if it's non-removable storage, it could potentially have been
187 * encrypted, and will also need to be wiped.
Kenny Root3785e392011-01-18 15:14:32 -0800188 */
Ben Komalo2a321922011-09-07 16:42:34 -0700189 boolean isExtStorageEmulated = Environment.isExternalStorageEmulated();
190 if (isExtStorageEmulated
191 || (!Environment.isExternalStorageRemovable() && isExtStorageEncrypted())) {
Kenny Root3785e392011-01-18 15:14:32 -0800192 mExternalStorageContainer.setVisibility(View.GONE);
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700193
Kenny Root3785e392011-01-18 15:14:32 -0800194 final View externalOption = mContentView.findViewById(R.id.erase_external_option_text);
195 externalOption.setVisibility(View.GONE);
196
197 final View externalAlsoErased = mContentView.findViewById(R.id.also_erases_external);
198 externalAlsoErased.setVisibility(View.VISIBLE);
Ben Komalo2a321922011-09-07 16:42:34 -0700199
200 // If it's not emulated, it is on a separate partition but it means we're doing
201 // a force wipe due to encryption.
202 mExternalStorage.setChecked(!isExtStorageEmulated);
Kenny Root3785e392011-01-18 15:14:32 -0800203 } else {
204 mExternalStorageContainer.setOnClickListener(new View.OnClickListener() {
205
206 @Override
207 public void onClick(View v) {
208 mExternalStorage.toggle();
209 }
210 });
211 }
Joe Onoratob51886d2010-11-08 18:25:51 -0800212
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -0700213 if (showWipeEuicc()) {
qingxi072f2862017-04-11 18:28:40 -0700214 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-Ban7cc1b9e2014-10-24 18:03:18 +0100225 final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
226 loadAccountList(um);
Julia Reynoldsce25af42015-07-08 16:56:31 -0400227 StringBuffer contentDescription = new StringBuffer();
228 View masterClearContainer = mContentView.findViewById(R.id.master_clear_container);
229 getContentDescription(masterClearContainer, contentDescription);
230 masterClearContainer.setContentDescription(contentDescription);
jackqdyulei0b3edc72016-12-13 17:07:08 -0800231
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
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -0700247 /**
248 * Whether to show the checkbox to wipe the eUICC.
249 *
Jeff Davidson4ba74782017-06-30 18:02:13 -0700250 * <p>We show the checkbox on any device which supports eUICC as long as the eUICC was ever
251 * provisioned (that is, at least one profile was ever downloaded onto it).
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -0700252 */
253 @VisibleForTesting
254 boolean showWipeEuicc() {
255 Context context = getContext();
256 if (!isEuiccEnabled(context)) {
257 return false;
258 }
259 ContentResolver cr = context.getContentResolver();
Jeff Davidson4ba74782017-06-30 18:02:13 -0700260 return Settings.Global.getInt(cr, Settings.Global.EUICC_PROVISIONED, 0) != 0;
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -0700261 }
262
263 @VisibleForTesting
264 protected boolean isEuiccEnabled(Context context) {
265 EuiccManager euiccManager = (EuiccManager) context.getSystemService(Context.EUICC_SERVICE);
266 return euiccManager.isEnabled();
267 }
268
jackqdyulei0b3edc72016-12-13 17:07:08 -0800269 @VisibleForTesting
270 boolean hasReachedBottom(final ScrollView scrollView) {
271 if (scrollView.getChildCount() < 1) {
272 return true;
273 }
274
275 final View view = scrollView.getChildAt(0);
276 final int diff = view.getBottom() - (scrollView.getHeight() + scrollView.getScrollY());
277
278 return diff <= 0;
Julia Reynoldsce25af42015-07-08 16:56:31 -0400279 }
280
281 private void getContentDescription(View v, StringBuffer description) {
Jason Monkfda77412016-05-06 14:28:09 -0400282 if (v.getVisibility() != View.VISIBLE) {
283 return;
284 }
Julia Reynoldsce25af42015-07-08 16:56:31 -0400285 if (v instanceof ViewGroup) {
286 ViewGroup vGroup = (ViewGroup) v;
287 for (int i = 0; i < vGroup.getChildCount(); i++) {
288 View nextChild = vGroup.getChildAt(i);
289 getContentDescription(nextChild, description);
290 }
291 } else if (v instanceof TextView) {
292 TextView vText = (TextView) v;
293 description.append(vText.getText());
294 description.append(","); // Allow Talkback to pause between sections.
295 }
Joe Onoratob51886d2010-11-08 18:25:51 -0800296 }
297
Ben Komalo2a321922011-09-07 16:42:34 -0700298 private boolean isExtStorageEncrypted() {
299 String state = SystemProperties.get("vold.decrypt");
300 return !"".equals(state);
301 }
302
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100303 private void loadAccountList(final UserManager um) {
Joe Onoratob51886d2010-11-08 18:25:51 -0800304 View accountsLabel = mContentView.findViewById(R.id.accounts_label);
305 LinearLayout contents = (LinearLayout)mContentView.findViewById(R.id.accounts);
Amith Yamasani3f45de52011-09-22 14:34:17 -0700306 contents.removeAllViews();
Joe Onoratob51886d2010-11-08 18:25:51 -0800307
308 Context context = getActivity();
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100309 final List<UserInfo> profiles = um.getProfiles(UserHandle.myUserId());
310 final int profilesSize = profiles.size();
Joe Onoratob51886d2010-11-08 18:25:51 -0800311
312 AccountManager mgr = AccountManager.get(context);
Joe Onoratob51886d2010-11-08 18:25:51 -0800313
314 LayoutInflater inflater = (LayoutInflater)context.getSystemService(
315 Context.LAYOUT_INFLATER_SERVICE);
316
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100317 int accountsCount = 0;
318 for (int profileIndex = 0; profileIndex < profilesSize; profileIndex++) {
319 final UserInfo userInfo = profiles.get(profileIndex);
320 final int profileId = userInfo.id;
321 final UserHandle userHandle = new UserHandle(profileId);
322 Account[] accounts = mgr.getAccountsAsUser(profileId);
323 final int N = accounts.length;
324 if (N == 0) {
Joe Onoratob51886d2010-11-08 18:25:51 -0800325 continue;
326 }
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100327 accountsCount += N;
Joe Onoratob51886d2010-11-08 18:25:51 -0800328
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100329 AuthenticatorDescription[] descs = AccountManager.get(context)
330 .getAuthenticatorTypesAsUser(profileId);
331 final int M = descs.length;
332
Bartosz Fabianowski30ba8682017-04-19 11:51:43 +0200333 if (profilesSize > 1) {
334 View titleView = Utils.inflateCategoryHeader(inflater, contents);
335 final TextView titleText = (TextView) titleView.findViewById(android.R.id.title);
336 titleText.setText(userInfo.isManagedProfile() ? R.string.category_work
337 : R.string.category_personal);
338 contents.addView(titleView);
339 }
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100340
341 for (int i = 0; i < N; i++) {
342 Account account = accounts[i];
343 AuthenticatorDescription desc = null;
344 for (int j = 0; j < M; j++) {
345 if (account.type.equals(descs[j].type)) {
346 desc = descs[j];
347 break;
348 }
349 }
350 if (desc == null) {
351 Log.w(TAG, "No descriptor for account name=" + account.name
352 + " type=" + account.type);
353 continue;
354 }
355 Drawable icon = null;
356 try {
357 if (desc.iconId != 0) {
Zoltan Szatmary-Ban546790c2014-12-02 17:22:10 +0000358 Context authContext = context.createPackageContextAsUser(desc.packageName,
359 0, userHandle);
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100360 icon = context.getPackageManager().getUserBadgedIcon(
361 authContext.getDrawable(desc.iconId), userHandle);
362 }
363 } catch (PackageManager.NameNotFoundException e) {
Rubin Xud1ce82a2015-06-08 17:21:19 +0100364 Log.w(TAG, "Bad package name for account type " + desc.type);
365 } catch (Resources.NotFoundException e) {
366 Log.w(TAG, "Invalid icon id for account type " + desc.type, e);
367 }
368 if (icon == null) {
369 icon = context.getPackageManager().getDefaultActivityIcon();
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100370 }
371
Fan Zhang6b2bb392016-09-28 09:07:44 -0700372 View child = inflater.inflate(R.layout.master_clear_account, contents, false);
373 ((ImageView) child.findViewById(android.R.id.icon)).setImageDrawable(icon);
374 ((TextView) child.findViewById(android.R.id.title)).setText(account.name);
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100375 contents.addView(child);
Joe Onoratob51886d2010-11-08 18:25:51 -0800376 }
Joe Onoratob51886d2010-11-08 18:25:51 -0800377 }
378
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100379 if (accountsCount > 0) {
380 accountsLabel.setVisibility(View.VISIBLE);
381 contents.setVisibility(View.VISIBLE);
382 }
383 // Checking for all other users and their profiles if any.
384 View otherUsers = mContentView.findViewById(R.id.other_users_present);
385 final boolean hasOtherUsers = (um.getUserCount() - profilesSize) > 0;
386 otherUsers.setVisibility(hasOtherUsers ? View.VISIBLE : View.GONE);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800387 }
388
389 @Override
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700390 public View onCreateView(LayoutInflater inflater, ViewGroup container,
391 Bundle savedInstanceState) {
Christine Franks14782222017-01-23 16:44:02 -0800392 final Context context = getContext();
393 final EnforcedAdmin admin = RestrictedLockUtils.checkIfRestrictionEnforced(context,
394 UserManager.DISALLOW_FACTORY_RESET, UserHandle.myUserId());
395 final UserManager um = UserManager.get(context);
396 final boolean disallow = !um.isAdminUser() || RestrictedLockUtils.hasBaseUserRestriction(
397 context, UserManager.DISALLOW_FACTORY_RESET, UserHandle.myUserId());
Christine Franksa09eb382017-06-23 14:28:21 -0700398 if (disallow && !Utils.isDemoUser(context)) {
Julia Reynolds2c539332014-06-11 12:56:02 -0400399 return inflater.inflate(R.layout.master_clear_disallowed_screen, null);
Sudheer Shanka7dbbe132016-02-16 14:19:32 +0000400 } else if (admin != null) {
401 View view = inflater.inflate(R.layout.admin_support_details_empty_view, null);
402 ShowAdminSupportDetailsDialog.setAdminSupportDetails(getActivity(), view, admin, false);
403 view.setVisibility(View.VISIBLE);
404 return view;
Julia Reynolds2c539332014-06-11 12:56:02 -0400405 }
406
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700407 mContentView = inflater.inflate(R.layout.master_clear, null);
Joe Onoratob51886d2010-11-08 18:25:51 -0800408
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800409 establishInitialState();
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700410 return mContentView;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800411 }
Chris Wren8a963ba2015-03-20 10:29:14 -0400412
413 @Override
Fan Zhang65076132016-08-08 10:25:13 -0700414 public int getMetricsCategory() {
Chris Wren9d1bfd12016-01-26 18:04:01 -0500415 return MetricsEvent.MASTER_CLEAR;
Chris Wren8a963ba2015-03-20 10:29:14 -0400416 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800417}