blob: 96cc390558011b55a86adae28b07002021e3f1b6 [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;
Doris Linged4685f2017-10-25 14:08:57 -070024import android.annotation.Nullable;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080025import android.app.Activity;
Christine Franksa09eb382017-06-23 14:28:21 -070026import android.content.ComponentName;
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -070027import android.content.ContentResolver;
Joe Onoratob51886d2010-11-08 18:25:51 -080028import android.content.Context;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080029import android.content.Intent;
Joe Onoratob51886d2010-11-08 18:25:51 -080030import android.content.pm.PackageManager;
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +010031import android.content.pm.UserInfo;
Amith Yamasanib14e1e02010-11-02 09:52:29 -070032import android.content.res.Resources;
Joe Onoratob51886d2010-11-08 18:25:51 -080033import android.graphics.drawable.Drawable;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080034import android.os.Bundle;
Kenny Root3785e392011-01-18 15:14:32 -080035import android.os.Environment;
Ben Komalo2a321922011-09-07 16:42:34 -070036import android.os.SystemProperties;
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +010037import android.os.UserHandle;
Amith Yamasani7eedcf42013-07-02 14:15:29 -070038import android.os.UserManager;
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -070039import android.provider.Settings;
jackqdyulei0b3edc72016-12-13 17:07:08 -080040import android.support.annotation.VisibleForTesting;
qingxi072f2862017-04-11 18:28:40 -070041import android.telephony.euicc.EuiccManager;
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;
Doris Linged4685f2017-10-25 14:08:57 -070056import com.android.settings.core.InstrumentedPreferenceFragment;
Maurice Lam2eb170c2017-04-28 16:18:47 -070057import com.android.settings.password.ChooseLockSettingsHelper;
58import com.android.settings.password.ConfirmLockPattern;
Sudheer Shanka7dbbe132016-02-16 14:19:32 +000059import com.android.settingslib.RestrictedLockUtils;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080060
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +010061import java.util.List;
62
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080063/**
64 * Confirm and execute a reset of the device to a clean "just out of the box"
65 * state. Multiple confirmations are required: first, a general "are you sure
66 * you want to do this?" prompt, followed by a keyguard pattern trace if the user
67 * has defined one, followed by a final strongly-worded "THIS WILL ERASE EVERYTHING
68 * ON THE PHONE" prompt. If at any time the phone is allowed to go to sleep, is
69 * locked, et cetera, then the confirmation sequence is abandoned.
Amith Yamasanib14e1e02010-11-02 09:52:29 -070070 *
71 * This is the initial screen.
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080072 */
Doris Linged4685f2017-10-25 14:08:57 -070073public class MasterClear extends InstrumentedPreferenceFragment {
Joe Onoratob51886d2010-11-08 18:25:51 -080074 private static final String TAG = "MasterClear";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080075
76 private static final int KEYGUARD_REQUEST = 55;
77
Amith Yamasanib14e1e02010-11-02 09:52:29 -070078 static final String ERASE_EXTERNAL_EXTRA = "erase_sd";
qingxi072f2862017-04-11 18:28:40 -070079 static final String ERASE_ESIMS_EXTRA = "erase_esim";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080080
Amith Yamasanib14e1e02010-11-02 09:52:29 -070081 private View mContentView;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080082 private Button mInitiateButton;
Dianne Hackborn1337d0f2010-10-14 11:58:30 -070083 private View mExternalStorageContainer;
qingxi072f2862017-04-11 18:28:40 -070084 @VisibleForTesting CheckBox mExternalStorage;
jackqdyulei0b3edc72016-12-13 17:07:08 -080085 private ScrollView mScrollView;
86
87 private final OnGlobalLayoutListener mOnGlobalLayoutListener = new OnGlobalLayoutListener() {
88 @Override
89 public void onGlobalLayout() {
90 mScrollView.getViewTreeObserver().removeOnGlobalLayoutListener(mOnGlobalLayoutListener);
91 mInitiateButton.setEnabled(hasReachedBottom(mScrollView));
92 }
93 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080094
Doris Ling03a3b512017-10-18 14:25:01 -070095 @Override
Doris Linged4685f2017-10-25 14:08:57 -070096 public void onCreate(@Nullable Bundle savedInstanceState) {
97 super.onCreate(savedInstanceState);
98 if (usePreferenceScreenTitle()) {
99 getActivity().setTitle(R.string.master_clear_title);
100 }
Doris Ling03a3b512017-10-18 14:25:01 -0700101 }
102
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800103 /**
Jim Miller2deec7e2010-04-13 17:43:36 -0700104 * Keyguard validation is run using the standard {@link ConfirmLockPattern}
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800105 * component as a subactivity
Jim Miller2deec7e2010-04-13 17:43:36 -0700106 * @param request the request code to be returned once confirmation finishes
107 * @return true if confirmation launched
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800108 */
Jim Miller2deec7e2010-04-13 17:43:36 -0700109 private boolean runKeyguardConfirmation(int request) {
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700110 Resources res = getActivity().getResources();
Jorim Jaggi8a09b612015-04-06 17:47:18 -0700111 return new ChooseLockSettingsHelper(getActivity(), this).launchConfirmationActivity(
112 request, res.getText(R.string.master_clear_title));
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800113 }
114
115 @Override
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700116 public void onActivityResult(int requestCode, int resultCode, Intent data) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800117 super.onActivityResult(requestCode, resultCode, data);
118
Julia Reynolds2c539332014-06-11 12:56:02 -0400119 if (requestCode != KEYGUARD_REQUEST) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800120 return;
121 }
122
123 // If the user entered a valid keyguard trace, present the final
124 // confirmation prompt; otherwise, go back to the initial state.
125 if (resultCode == Activity.RESULT_OK) {
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700126 showFinalConfirmation();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800127 } else {
128 establishInitialState();
129 }
130 }
131
qingxi072f2862017-04-11 18:28:40 -0700132 @VisibleForTesting
133 void showFinalConfirmation() {
Stuart Scottbe903412014-07-24 19:22:06 -0700134 Bundle args = new Bundle();
135 args.putBoolean(ERASE_EXTERNAL_EXTRA, mExternalStorage.isChecked());
Jeff Davidsona0b84722017-07-26 17:38:41 -0700136 // TODO: Offer the user a choice to wipe eSIMs when it is technically feasible to do so.
137 args.putBoolean(ERASE_ESIMS_EXTRA, true);
Fan Zhangc6ca3142017-02-14 15:02:35 -0800138 ((SettingsActivity) getActivity()).startPreferencePanel(
139 this, MasterClearConfirm.class.getName(),
Stuart Scottbe903412014-07-24 19:22:06 -0700140 args, R.string.master_clear_confirm_title, null, null, 0);
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700141 }
142
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800143 /**
144 * If the user clicks to begin the reset sequence, we next require a
145 * keyguard confirmation if the user has currently enabled one. If there
146 * is no keyguard available, we simply go to the final confirmation prompt.
Christine Franksa09eb382017-06-23 14:28:21 -0700147 *
148 * 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 -0800149 */
Christine Franksa09eb382017-06-23 14:28:21 -0700150 @VisibleForTesting
151 protected final Button.OnClickListener mInitiateListener = new Button.OnClickListener() {
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700152
Christine Franksa09eb382017-06-23 14:28:21 -0700153 public void onClick(View view) {
154 final Context context = view.getContext();
155 if (Utils.isDemoUser(context)) {
Justin Klaassen30257272017-08-08 21:58:05 -0700156 final ComponentName componentName = Utils.getDeviceOwnerComponent(context);
157 if (componentName != null) {
Christine Franksa09eb382017-06-23 14:28:21 -0700158 final Intent requestFactoryReset = new Intent()
Justin Klaassen30257272017-08-08 21:58:05 -0700159 .setPackage(componentName.getPackageName())
Christine Franksa09eb382017-06-23 14:28:21 -0700160 .setAction(Intent.ACTION_FACTORY_RESET);
161 context.startActivity(requestFactoryReset);
Christine Franksd7713c92017-01-20 11:24:14 -0800162 }
163 } else if (!runKeyguardConfirmation(KEYGUARD_REQUEST)) {
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700164 showFinalConfirmation();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800165 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800166 }
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700167 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800168
169 /**
170 * In its initial state, the activity presents a button for the user to
171 * click in order to initiate a confirmation sequence. This method is
172 * called from various other points in the code to reset the activity to
173 * this base state.
Jim Miller47d380f2010-01-20 13:37:14 -0800174 *
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800175 * <p>Reinflating views from resources is expensive and prevents us from
176 * caching widget pointers, so we use a single-inflate pattern: we lazy-
177 * inflate each view, caching all of the widget pointers we'll need at the
178 * time, then simply reuse the inflated views directly whenever we need
179 * to change contents.
180 */
181 private void establishInitialState() {
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700182 mInitiateButton = (Button) mContentView.findViewById(R.id.initiate_master_clear);
183 mInitiateButton.setOnClickListener(mInitiateListener);
184 mExternalStorageContainer = mContentView.findViewById(R.id.erase_external_container);
185 mExternalStorage = (CheckBox) mContentView.findViewById(R.id.erase_external);
jackqdyulei0b3edc72016-12-13 17:07:08 -0800186 mScrollView = (ScrollView) mContentView.findViewById(R.id.master_clear_scrollview);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800187
Kenny Root3785e392011-01-18 15:14:32 -0800188 /*
189 * If the external storage is emulated, it will be erased with a factory
190 * reset at any rate. There is no need to have a separate option until
191 * we have a factory reset that only erases some directories and not
Ben Komalo2a321922011-09-07 16:42:34 -0700192 * others. Likewise, if it's non-removable storage, it could potentially have been
193 * encrypted, and will also need to be wiped.
Kenny Root3785e392011-01-18 15:14:32 -0800194 */
Ben Komalo2a321922011-09-07 16:42:34 -0700195 boolean isExtStorageEmulated = Environment.isExternalStorageEmulated();
196 if (isExtStorageEmulated
197 || (!Environment.isExternalStorageRemovable() && isExtStorageEncrypted())) {
Kenny Root3785e392011-01-18 15:14:32 -0800198 mExternalStorageContainer.setVisibility(View.GONE);
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700199
Kenny Root3785e392011-01-18 15:14:32 -0800200 final View externalOption = mContentView.findViewById(R.id.erase_external_option_text);
201 externalOption.setVisibility(View.GONE);
202
203 final View externalAlsoErased = mContentView.findViewById(R.id.also_erases_external);
204 externalAlsoErased.setVisibility(View.VISIBLE);
Ben Komalo2a321922011-09-07 16:42:34 -0700205
206 // If it's not emulated, it is on a separate partition but it means we're doing
207 // a force wipe due to encryption.
208 mExternalStorage.setChecked(!isExtStorageEmulated);
Kenny Root3785e392011-01-18 15:14:32 -0800209 } else {
210 mExternalStorageContainer.setOnClickListener(new View.OnClickListener() {
211
212 @Override
213 public void onClick(View v) {
214 mExternalStorage.toggle();
215 }
216 });
217 }
Joe Onoratob51886d2010-11-08 18:25:51 -0800218
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -0700219 if (showWipeEuicc()) {
Jeff Davidsona0b84722017-07-26 17:38:41 -0700220 final View esimAlsoErased = mContentView.findViewById(R.id.also_erases_esim);
221 esimAlsoErased.setVisibility(View.VISIBLE);
qingxi072f2862017-04-11 18:28:40 -0700222
Jeff Davidsona0b84722017-07-26 17:38:41 -0700223 final View noCancelMobilePlan = mContentView.findViewById(R.id.no_cancel_mobile_plan);
224 noCancelMobilePlan.setVisibility(View.VISIBLE);
qingxi072f2862017-04-11 18:28:40 -0700225 }
226
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100227 final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
228 loadAccountList(um);
Julia Reynoldsce25af42015-07-08 16:56:31 -0400229 StringBuffer contentDescription = new StringBuffer();
230 View masterClearContainer = mContentView.findViewById(R.id.master_clear_container);
231 getContentDescription(masterClearContainer, contentDescription);
232 masterClearContainer.setContentDescription(contentDescription);
jackqdyulei0b3edc72016-12-13 17:07:08 -0800233
234 // Set the status of initiateButton based on scrollview
235 mScrollView.setOnScrollChangeListener(new OnScrollChangeListener() {
236 @Override
237 public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX,
238 int oldScrollY) {
239 if (v instanceof ScrollView && hasReachedBottom((ScrollView) v)) {
240 mInitiateButton.setEnabled(true);
241 }
242 }
243 });
244
245 // Set the initial state of the initiateButton
246 mScrollView.getViewTreeObserver().addOnGlobalLayoutListener(mOnGlobalLayoutListener);
247 }
248
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -0700249 /**
Jeff Davidsona0b84722017-07-26 17:38:41 -0700250 * Whether to show strings indicating that the eUICC will be wiped.
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -0700251 *
Jeff Davidsona0b84722017-07-26 17:38:41 -0700252 * <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 -0700253 * provisioned (that is, at least one profile was ever downloaded onto it).
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -0700254 */
255 @VisibleForTesting
256 boolean showWipeEuicc() {
257 Context context = getContext();
258 if (!isEuiccEnabled(context)) {
259 return false;
260 }
261 ContentResolver cr = context.getContentResolver();
Jeff Davidson4ba74782017-06-30 18:02:13 -0700262 return Settings.Global.getInt(cr, Settings.Global.EUICC_PROVISIONED, 0) != 0;
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -0700263 }
264
265 @VisibleForTesting
266 protected boolean isEuiccEnabled(Context context) {
267 EuiccManager euiccManager = (EuiccManager) context.getSystemService(Context.EUICC_SERVICE);
268 return euiccManager.isEnabled();
269 }
270
jackqdyulei0b3edc72016-12-13 17:07:08 -0800271 @VisibleForTesting
272 boolean hasReachedBottom(final ScrollView scrollView) {
273 if (scrollView.getChildCount() < 1) {
274 return true;
275 }
276
277 final View view = scrollView.getChildAt(0);
278 final int diff = view.getBottom() - (scrollView.getHeight() + scrollView.getScrollY());
279
280 return diff <= 0;
Julia Reynoldsce25af42015-07-08 16:56:31 -0400281 }
282
283 private void getContentDescription(View v, StringBuffer description) {
Jason Monkfda77412016-05-06 14:28:09 -0400284 if (v.getVisibility() != View.VISIBLE) {
285 return;
286 }
Julia Reynoldsce25af42015-07-08 16:56:31 -0400287 if (v instanceof ViewGroup) {
288 ViewGroup vGroup = (ViewGroup) v;
289 for (int i = 0; i < vGroup.getChildCount(); i++) {
290 View nextChild = vGroup.getChildAt(i);
291 getContentDescription(nextChild, description);
292 }
293 } else if (v instanceof TextView) {
294 TextView vText = (TextView) v;
295 description.append(vText.getText());
296 description.append(","); // Allow Talkback to pause between sections.
297 }
Joe Onoratob51886d2010-11-08 18:25:51 -0800298 }
299
Ben Komalo2a321922011-09-07 16:42:34 -0700300 private boolean isExtStorageEncrypted() {
301 String state = SystemProperties.get("vold.decrypt");
302 return !"".equals(state);
303 }
304
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100305 private void loadAccountList(final UserManager um) {
Joe Onoratob51886d2010-11-08 18:25:51 -0800306 View accountsLabel = mContentView.findViewById(R.id.accounts_label);
307 LinearLayout contents = (LinearLayout)mContentView.findViewById(R.id.accounts);
Amith Yamasani3f45de52011-09-22 14:34:17 -0700308 contents.removeAllViews();
Joe Onoratob51886d2010-11-08 18:25:51 -0800309
310 Context context = getActivity();
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100311 final List<UserInfo> profiles = um.getProfiles(UserHandle.myUserId());
312 final int profilesSize = profiles.size();
Joe Onoratob51886d2010-11-08 18:25:51 -0800313
314 AccountManager mgr = AccountManager.get(context);
Joe Onoratob51886d2010-11-08 18:25:51 -0800315
316 LayoutInflater inflater = (LayoutInflater)context.getSystemService(
317 Context.LAYOUT_INFLATER_SERVICE);
318
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100319 int accountsCount = 0;
320 for (int profileIndex = 0; profileIndex < profilesSize; profileIndex++) {
321 final UserInfo userInfo = profiles.get(profileIndex);
322 final int profileId = userInfo.id;
323 final UserHandle userHandle = new UserHandle(profileId);
324 Account[] accounts = mgr.getAccountsAsUser(profileId);
325 final int N = accounts.length;
326 if (N == 0) {
Joe Onoratob51886d2010-11-08 18:25:51 -0800327 continue;
328 }
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100329 accountsCount += N;
Joe Onoratob51886d2010-11-08 18:25:51 -0800330
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100331 AuthenticatorDescription[] descs = AccountManager.get(context)
332 .getAuthenticatorTypesAsUser(profileId);
333 final int M = descs.length;
334
Bartosz Fabianowski30ba8682017-04-19 11:51:43 +0200335 if (profilesSize > 1) {
336 View titleView = Utils.inflateCategoryHeader(inflater, contents);
337 final TextView titleText = (TextView) titleView.findViewById(android.R.id.title);
338 titleText.setText(userInfo.isManagedProfile() ? R.string.category_work
339 : R.string.category_personal);
340 contents.addView(titleView);
341 }
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100342
343 for (int i = 0; i < N; i++) {
344 Account account = accounts[i];
345 AuthenticatorDescription desc = null;
346 for (int j = 0; j < M; j++) {
347 if (account.type.equals(descs[j].type)) {
348 desc = descs[j];
349 break;
350 }
351 }
352 if (desc == null) {
353 Log.w(TAG, "No descriptor for account name=" + account.name
354 + " type=" + account.type);
355 continue;
356 }
357 Drawable icon = null;
358 try {
359 if (desc.iconId != 0) {
Zoltan Szatmary-Ban546790c2014-12-02 17:22:10 +0000360 Context authContext = context.createPackageContextAsUser(desc.packageName,
361 0, userHandle);
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100362 icon = context.getPackageManager().getUserBadgedIcon(
363 authContext.getDrawable(desc.iconId), userHandle);
364 }
365 } catch (PackageManager.NameNotFoundException e) {
Rubin Xud1ce82a2015-06-08 17:21:19 +0100366 Log.w(TAG, "Bad package name for account type " + desc.type);
367 } catch (Resources.NotFoundException e) {
368 Log.w(TAG, "Invalid icon id for account type " + desc.type, e);
369 }
370 if (icon == null) {
371 icon = context.getPackageManager().getDefaultActivityIcon();
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100372 }
373
Fan Zhang6b2bb392016-09-28 09:07:44 -0700374 View child = inflater.inflate(R.layout.master_clear_account, contents, false);
375 ((ImageView) child.findViewById(android.R.id.icon)).setImageDrawable(icon);
376 ((TextView) child.findViewById(android.R.id.title)).setText(account.name);
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100377 contents.addView(child);
Joe Onoratob51886d2010-11-08 18:25:51 -0800378 }
Joe Onoratob51886d2010-11-08 18:25:51 -0800379 }
380
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100381 if (accountsCount > 0) {
382 accountsLabel.setVisibility(View.VISIBLE);
383 contents.setVisibility(View.VISIBLE);
384 }
385 // Checking for all other users and their profiles if any.
386 View otherUsers = mContentView.findViewById(R.id.other_users_present);
387 final boolean hasOtherUsers = (um.getUserCount() - profilesSize) > 0;
388 otherUsers.setVisibility(hasOtherUsers ? View.VISIBLE : View.GONE);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800389 }
390
391 @Override
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700392 public View onCreateView(LayoutInflater inflater, ViewGroup container,
393 Bundle savedInstanceState) {
Christine Franks14782222017-01-23 16:44:02 -0800394 final Context context = getContext();
395 final EnforcedAdmin admin = RestrictedLockUtils.checkIfRestrictionEnforced(context,
396 UserManager.DISALLOW_FACTORY_RESET, UserHandle.myUserId());
397 final UserManager um = UserManager.get(context);
398 final boolean disallow = !um.isAdminUser() || RestrictedLockUtils.hasBaseUserRestriction(
399 context, UserManager.DISALLOW_FACTORY_RESET, UserHandle.myUserId());
Christine Franksa09eb382017-06-23 14:28:21 -0700400 if (disallow && !Utils.isDemoUser(context)) {
Julia Reynolds2c539332014-06-11 12:56:02 -0400401 return inflater.inflate(R.layout.master_clear_disallowed_screen, null);
Sudheer Shanka7dbbe132016-02-16 14:19:32 +0000402 } else if (admin != null) {
403 View view = inflater.inflate(R.layout.admin_support_details_empty_view, null);
404 ShowAdminSupportDetailsDialog.setAdminSupportDetails(getActivity(), view, admin, false);
405 view.setVisibility(View.VISIBLE);
406 return view;
Julia Reynolds2c539332014-06-11 12:56:02 -0400407 }
408
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700409 mContentView = inflater.inflate(R.layout.master_clear, null);
Joe Onoratob51886d2010-11-08 18:25:51 -0800410
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800411 establishInitialState();
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700412 return mContentView;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800413 }
Chris Wren8a963ba2015-03-20 10:29:14 -0400414
415 @Override
Fan Zhang65076132016-08-08 10:25:13 -0700416 public int getMetricsCategory() {
Chris Wren9d1bfd12016-01-26 18:04:01 -0500417 return MetricsEvent.MASTER_CLEAR;
Chris Wren8a963ba2015-03-20 10:29:14 -0400418 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800419}