blob: 2c9701832ee0eafe0746edb343ae5e43904520ab [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;
jackqdyulei0b3edc72016-12-13 17:07:08 -080084 private ScrollView mScrollView;
85
86 private final OnGlobalLayoutListener mOnGlobalLayoutListener = new OnGlobalLayoutListener() {
87 @Override
88 public void onGlobalLayout() {
89 mScrollView.getViewTreeObserver().removeOnGlobalLayoutListener(mOnGlobalLayoutListener);
90 mInitiateButton.setEnabled(hasReachedBottom(mScrollView));
91 }
92 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080093
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080094 /**
Jim Miller2deec7e2010-04-13 17:43:36 -070095 * Keyguard validation is run using the standard {@link ConfirmLockPattern}
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080096 * component as a subactivity
Jim Miller2deec7e2010-04-13 17:43:36 -070097 * @param request the request code to be returned once confirmation finishes
98 * @return true if confirmation launched
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080099 */
Jim Miller2deec7e2010-04-13 17:43:36 -0700100 private boolean runKeyguardConfirmation(int request) {
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700101 Resources res = getActivity().getResources();
Jorim Jaggi8a09b612015-04-06 17:47:18 -0700102 return new ChooseLockSettingsHelper(getActivity(), this).launchConfirmationActivity(
103 request, res.getText(R.string.master_clear_title));
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800104 }
105
106 @Override
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700107 public void onActivityResult(int requestCode, int resultCode, Intent data) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800108 super.onActivityResult(requestCode, resultCode, data);
109
Julia Reynolds2c539332014-06-11 12:56:02 -0400110 if (requestCode != KEYGUARD_REQUEST) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800111 return;
112 }
113
114 // If the user entered a valid keyguard trace, present the final
115 // confirmation prompt; otherwise, go back to the initial state.
116 if (resultCode == Activity.RESULT_OK) {
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700117 showFinalConfirmation();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800118 } else {
119 establishInitialState();
120 }
121 }
122
qingxi072f2862017-04-11 18:28:40 -0700123 @VisibleForTesting
124 void showFinalConfirmation() {
Stuart Scottbe903412014-07-24 19:22:06 -0700125 Bundle args = new Bundle();
126 args.putBoolean(ERASE_EXTERNAL_EXTRA, mExternalStorage.isChecked());
Jeff Davidsona0b84722017-07-26 17:38:41 -0700127 // TODO: Offer the user a choice to wipe eSIMs when it is technically feasible to do so.
128 args.putBoolean(ERASE_ESIMS_EXTRA, true);
Fan Zhangc6ca3142017-02-14 15:02:35 -0800129 ((SettingsActivity) getActivity()).startPreferencePanel(
130 this, MasterClearConfirm.class.getName(),
Stuart Scottbe903412014-07-24 19:22:06 -0700131 args, R.string.master_clear_confirm_title, null, null, 0);
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700132 }
133
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800134 /**
135 * If the user clicks to begin the reset sequence, we next require a
136 * keyguard confirmation if the user has currently enabled one. If there
137 * is no keyguard available, we simply go to the final confirmation prompt.
Christine Franksa09eb382017-06-23 14:28:21 -0700138 *
139 * 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 -0800140 */
Christine Franksa09eb382017-06-23 14:28:21 -0700141 @VisibleForTesting
142 protected final Button.OnClickListener mInitiateListener = new Button.OnClickListener() {
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700143
Christine Franksa09eb382017-06-23 14:28:21 -0700144 public void onClick(View view) {
145 final Context context = view.getContext();
146 if (Utils.isDemoUser(context)) {
Justin Klaassen30257272017-08-08 21:58:05 -0700147 final ComponentName componentName = Utils.getDeviceOwnerComponent(context);
148 if (componentName != null) {
Christine Franksa09eb382017-06-23 14:28:21 -0700149 final Intent requestFactoryReset = new Intent()
Justin Klaassen30257272017-08-08 21:58:05 -0700150 .setPackage(componentName.getPackageName())
Christine Franksa09eb382017-06-23 14:28:21 -0700151 .setAction(Intent.ACTION_FACTORY_RESET);
152 context.startActivity(requestFactoryReset);
Christine Franksd7713c92017-01-20 11:24:14 -0800153 }
154 } else if (!runKeyguardConfirmation(KEYGUARD_REQUEST)) {
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700155 showFinalConfirmation();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800156 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800157 }
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700158 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800159
160 /**
161 * In its initial state, the activity presents a button for the user to
162 * click in order to initiate a confirmation sequence. This method is
163 * called from various other points in the code to reset the activity to
164 * this base state.
Jim Miller47d380f2010-01-20 13:37:14 -0800165 *
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800166 * <p>Reinflating views from resources is expensive and prevents us from
167 * caching widget pointers, so we use a single-inflate pattern: we lazy-
168 * inflate each view, caching all of the widget pointers we'll need at the
169 * time, then simply reuse the inflated views directly whenever we need
170 * to change contents.
171 */
172 private void establishInitialState() {
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700173 mInitiateButton = (Button) mContentView.findViewById(R.id.initiate_master_clear);
174 mInitiateButton.setOnClickListener(mInitiateListener);
175 mExternalStorageContainer = mContentView.findViewById(R.id.erase_external_container);
176 mExternalStorage = (CheckBox) mContentView.findViewById(R.id.erase_external);
jackqdyulei0b3edc72016-12-13 17:07:08 -0800177 mScrollView = (ScrollView) mContentView.findViewById(R.id.master_clear_scrollview);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800178
Kenny Root3785e392011-01-18 15:14:32 -0800179 /*
180 * If the external storage is emulated, it will be erased with a factory
181 * reset at any rate. There is no need to have a separate option until
182 * we have a factory reset that only erases some directories and not
Ben Komalo2a321922011-09-07 16:42:34 -0700183 * others. Likewise, if it's non-removable storage, it could potentially have been
184 * encrypted, and will also need to be wiped.
Kenny Root3785e392011-01-18 15:14:32 -0800185 */
Ben Komalo2a321922011-09-07 16:42:34 -0700186 boolean isExtStorageEmulated = Environment.isExternalStorageEmulated();
187 if (isExtStorageEmulated
188 || (!Environment.isExternalStorageRemovable() && isExtStorageEncrypted())) {
Kenny Root3785e392011-01-18 15:14:32 -0800189 mExternalStorageContainer.setVisibility(View.GONE);
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700190
Kenny Root3785e392011-01-18 15:14:32 -0800191 final View externalOption = mContentView.findViewById(R.id.erase_external_option_text);
192 externalOption.setVisibility(View.GONE);
193
194 final View externalAlsoErased = mContentView.findViewById(R.id.also_erases_external);
195 externalAlsoErased.setVisibility(View.VISIBLE);
Ben Komalo2a321922011-09-07 16:42:34 -0700196
197 // If it's not emulated, it is on a separate partition but it means we're doing
198 // a force wipe due to encryption.
199 mExternalStorage.setChecked(!isExtStorageEmulated);
Kenny Root3785e392011-01-18 15:14:32 -0800200 } else {
201 mExternalStorageContainer.setOnClickListener(new View.OnClickListener() {
202
203 @Override
204 public void onClick(View v) {
205 mExternalStorage.toggle();
206 }
207 });
208 }
Joe Onoratob51886d2010-11-08 18:25:51 -0800209
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -0700210 if (showWipeEuicc()) {
Jeff Davidsona0b84722017-07-26 17:38:41 -0700211 final View esimAlsoErased = mContentView.findViewById(R.id.also_erases_esim);
212 esimAlsoErased.setVisibility(View.VISIBLE);
qingxi072f2862017-04-11 18:28:40 -0700213
Jeff Davidsona0b84722017-07-26 17:38:41 -0700214 final View noCancelMobilePlan = mContentView.findViewById(R.id.no_cancel_mobile_plan);
215 noCancelMobilePlan.setVisibility(View.VISIBLE);
qingxi072f2862017-04-11 18:28:40 -0700216 }
217
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100218 final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
219 loadAccountList(um);
Julia Reynoldsce25af42015-07-08 16:56:31 -0400220 StringBuffer contentDescription = new StringBuffer();
221 View masterClearContainer = mContentView.findViewById(R.id.master_clear_container);
222 getContentDescription(masterClearContainer, contentDescription);
223 masterClearContainer.setContentDescription(contentDescription);
jackqdyulei0b3edc72016-12-13 17:07:08 -0800224
225 // Set the status of initiateButton based on scrollview
226 mScrollView.setOnScrollChangeListener(new OnScrollChangeListener() {
227 @Override
228 public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX,
229 int oldScrollY) {
230 if (v instanceof ScrollView && hasReachedBottom((ScrollView) v)) {
231 mInitiateButton.setEnabled(true);
232 }
233 }
234 });
235
236 // Set the initial state of the initiateButton
237 mScrollView.getViewTreeObserver().addOnGlobalLayoutListener(mOnGlobalLayoutListener);
238 }
239
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -0700240 /**
Jeff Davidsona0b84722017-07-26 17:38:41 -0700241 * Whether to show strings indicating that the eUICC will be wiped.
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -0700242 *
Jeff Davidsona0b84722017-07-26 17:38:41 -0700243 * <p>We show the strings on any device which supports eUICC as long as the eUICC was ever
Jeff Davidson4ba74782017-06-30 18:02:13 -0700244 * provisioned (that is, at least one profile was ever downloaded onto it).
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -0700245 */
246 @VisibleForTesting
247 boolean showWipeEuicc() {
248 Context context = getContext();
249 if (!isEuiccEnabled(context)) {
250 return false;
251 }
252 ContentResolver cr = context.getContentResolver();
Jeff Davidson4ba74782017-06-30 18:02:13 -0700253 return Settings.Global.getInt(cr, Settings.Global.EUICC_PROVISIONED, 0) != 0;
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -0700254 }
255
256 @VisibleForTesting
257 protected boolean isEuiccEnabled(Context context) {
258 EuiccManager euiccManager = (EuiccManager) context.getSystemService(Context.EUICC_SERVICE);
259 return euiccManager.isEnabled();
260 }
261
jackqdyulei0b3edc72016-12-13 17:07:08 -0800262 @VisibleForTesting
263 boolean hasReachedBottom(final ScrollView scrollView) {
264 if (scrollView.getChildCount() < 1) {
265 return true;
266 }
267
268 final View view = scrollView.getChildAt(0);
269 final int diff = view.getBottom() - (scrollView.getHeight() + scrollView.getScrollY());
270
271 return diff <= 0;
Julia Reynoldsce25af42015-07-08 16:56:31 -0400272 }
273
274 private void getContentDescription(View v, StringBuffer description) {
Jason Monkfda77412016-05-06 14:28:09 -0400275 if (v.getVisibility() != View.VISIBLE) {
276 return;
277 }
Julia Reynoldsce25af42015-07-08 16:56:31 -0400278 if (v instanceof ViewGroup) {
279 ViewGroup vGroup = (ViewGroup) v;
280 for (int i = 0; i < vGroup.getChildCount(); i++) {
281 View nextChild = vGroup.getChildAt(i);
282 getContentDescription(nextChild, description);
283 }
284 } else if (v instanceof TextView) {
285 TextView vText = (TextView) v;
286 description.append(vText.getText());
287 description.append(","); // Allow Talkback to pause between sections.
288 }
Joe Onoratob51886d2010-11-08 18:25:51 -0800289 }
290
Ben Komalo2a321922011-09-07 16:42:34 -0700291 private boolean isExtStorageEncrypted() {
292 String state = SystemProperties.get("vold.decrypt");
293 return !"".equals(state);
294 }
295
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100296 private void loadAccountList(final UserManager um) {
Joe Onoratob51886d2010-11-08 18:25:51 -0800297 View accountsLabel = mContentView.findViewById(R.id.accounts_label);
298 LinearLayout contents = (LinearLayout)mContentView.findViewById(R.id.accounts);
Amith Yamasani3f45de52011-09-22 14:34:17 -0700299 contents.removeAllViews();
Joe Onoratob51886d2010-11-08 18:25:51 -0800300
301 Context context = getActivity();
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100302 final List<UserInfo> profiles = um.getProfiles(UserHandle.myUserId());
303 final int profilesSize = profiles.size();
Joe Onoratob51886d2010-11-08 18:25:51 -0800304
305 AccountManager mgr = AccountManager.get(context);
Joe Onoratob51886d2010-11-08 18:25:51 -0800306
307 LayoutInflater inflater = (LayoutInflater)context.getSystemService(
308 Context.LAYOUT_INFLATER_SERVICE);
309
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100310 int accountsCount = 0;
311 for (int profileIndex = 0; profileIndex < profilesSize; profileIndex++) {
312 final UserInfo userInfo = profiles.get(profileIndex);
313 final int profileId = userInfo.id;
314 final UserHandle userHandle = new UserHandle(profileId);
315 Account[] accounts = mgr.getAccountsAsUser(profileId);
316 final int N = accounts.length;
317 if (N == 0) {
Joe Onoratob51886d2010-11-08 18:25:51 -0800318 continue;
319 }
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100320 accountsCount += N;
Joe Onoratob51886d2010-11-08 18:25:51 -0800321
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100322 AuthenticatorDescription[] descs = AccountManager.get(context)
323 .getAuthenticatorTypesAsUser(profileId);
324 final int M = descs.length;
325
Bartosz Fabianowski30ba8682017-04-19 11:51:43 +0200326 if (profilesSize > 1) {
327 View titleView = Utils.inflateCategoryHeader(inflater, contents);
328 final TextView titleText = (TextView) titleView.findViewById(android.R.id.title);
329 titleText.setText(userInfo.isManagedProfile() ? R.string.category_work
330 : R.string.category_personal);
331 contents.addView(titleView);
332 }
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100333
334 for (int i = 0; i < N; i++) {
335 Account account = accounts[i];
336 AuthenticatorDescription desc = null;
337 for (int j = 0; j < M; j++) {
338 if (account.type.equals(descs[j].type)) {
339 desc = descs[j];
340 break;
341 }
342 }
343 if (desc == null) {
344 Log.w(TAG, "No descriptor for account name=" + account.name
345 + " type=" + account.type);
346 continue;
347 }
348 Drawable icon = null;
349 try {
350 if (desc.iconId != 0) {
Zoltan Szatmary-Ban546790c2014-12-02 17:22:10 +0000351 Context authContext = context.createPackageContextAsUser(desc.packageName,
352 0, userHandle);
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100353 icon = context.getPackageManager().getUserBadgedIcon(
354 authContext.getDrawable(desc.iconId), userHandle);
355 }
356 } catch (PackageManager.NameNotFoundException e) {
Rubin Xud1ce82a2015-06-08 17:21:19 +0100357 Log.w(TAG, "Bad package name for account type " + desc.type);
358 } catch (Resources.NotFoundException e) {
359 Log.w(TAG, "Invalid icon id for account type " + desc.type, e);
360 }
361 if (icon == null) {
362 icon = context.getPackageManager().getDefaultActivityIcon();
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100363 }
364
Fan Zhang6b2bb392016-09-28 09:07:44 -0700365 View child = inflater.inflate(R.layout.master_clear_account, contents, false);
366 ((ImageView) child.findViewById(android.R.id.icon)).setImageDrawable(icon);
367 ((TextView) child.findViewById(android.R.id.title)).setText(account.name);
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100368 contents.addView(child);
Joe Onoratob51886d2010-11-08 18:25:51 -0800369 }
Joe Onoratob51886d2010-11-08 18:25:51 -0800370 }
371
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100372 if (accountsCount > 0) {
373 accountsLabel.setVisibility(View.VISIBLE);
374 contents.setVisibility(View.VISIBLE);
375 }
376 // Checking for all other users and their profiles if any.
377 View otherUsers = mContentView.findViewById(R.id.other_users_present);
378 final boolean hasOtherUsers = (um.getUserCount() - profilesSize) > 0;
379 otherUsers.setVisibility(hasOtherUsers ? View.VISIBLE : View.GONE);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800380 }
381
382 @Override
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700383 public View onCreateView(LayoutInflater inflater, ViewGroup container,
384 Bundle savedInstanceState) {
Christine Franks14782222017-01-23 16:44:02 -0800385 final Context context = getContext();
386 final EnforcedAdmin admin = RestrictedLockUtils.checkIfRestrictionEnforced(context,
387 UserManager.DISALLOW_FACTORY_RESET, UserHandle.myUserId());
388 final UserManager um = UserManager.get(context);
389 final boolean disallow = !um.isAdminUser() || RestrictedLockUtils.hasBaseUserRestriction(
390 context, UserManager.DISALLOW_FACTORY_RESET, UserHandle.myUserId());
Christine Franksa09eb382017-06-23 14:28:21 -0700391 if (disallow && !Utils.isDemoUser(context)) {
Julia Reynolds2c539332014-06-11 12:56:02 -0400392 return inflater.inflate(R.layout.master_clear_disallowed_screen, null);
Sudheer Shanka7dbbe132016-02-16 14:19:32 +0000393 } else if (admin != null) {
394 View view = inflater.inflate(R.layout.admin_support_details_empty_view, null);
395 ShowAdminSupportDetailsDialog.setAdminSupportDetails(getActivity(), view, admin, false);
396 view.setVisibility(View.VISIBLE);
397 return view;
Julia Reynolds2c539332014-06-11 12:56:02 -0400398 }
399
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700400 mContentView = inflater.inflate(R.layout.master_clear, null);
Joe Onoratob51886d2010-11-08 18:25:51 -0800401
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800402 establishInitialState();
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700403 return mContentView;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800404 }
Chris Wren8a963ba2015-03-20 10:29:14 -0400405
406 @Override
Fan Zhang65076132016-08-08 10:25:13 -0700407 public int getMetricsCategory() {
Chris Wren9d1bfd12016-01-26 18:04:01 -0500408 return MetricsEvent.MASTER_CLEAR;
Chris Wren8a963ba2015-03-20 10:29:14 -0400409 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800410}