blob: 3cc722bbffa336e0d6395db0263d70b3201dbdfc [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;
Carlos Valdiviaa9736ed2018-01-16 13:59:31 -080031import android.content.pm.ResolveInfo;
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +010032import android.content.pm.UserInfo;
Amith Yamasanib14e1e02010-11-02 09:52:29 -070033import android.content.res.Resources;
Joe Onoratob51886d2010-11-08 18:25:51 -080034import android.graphics.drawable.Drawable;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080035import android.os.Bundle;
Kenny Root3785e392011-01-18 15:14:32 -080036import android.os.Environment;
Ben Komalo2a321922011-09-07 16:42:34 -070037import android.os.SystemProperties;
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +010038import android.os.UserHandle;
Amith Yamasani7eedcf42013-07-02 14:15:29 -070039import android.os.UserManager;
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -070040import android.provider.Settings;
jackqdyulei0b3edc72016-12-13 17:07:08 -080041import android.support.annotation.VisibleForTesting;
qingxi072f2862017-04-11 18:28:40 -070042import android.telephony.euicc.EuiccManager;
Carlos Valdiviaa9736ed2018-01-16 13:59:31 -080043import android.text.TextUtils;
Joe Onoratob51886d2010-11-08 18:25:51 -080044import android.util.Log;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080045import android.view.LayoutInflater;
46import android.view.View;
jackqdyulei0b3edc72016-12-13 17:07:08 -080047import android.view.View.OnScrollChangeListener;
Amith Yamasanib14e1e02010-11-02 09:52:29 -070048import android.view.ViewGroup;
jackqdyulei0b3edc72016-12-13 17:07:08 -080049import android.view.ViewTreeObserver.OnGlobalLayoutListener;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080050import android.widget.Button;
Dianne Hackborn1337d0f2010-10-14 11:58:30 -070051import android.widget.CheckBox;
Fan Zhang6b2bb392016-09-28 09:07:44 -070052import android.widget.ImageView;
Joe Onoratob51886d2010-11-08 18:25:51 -080053import android.widget.LinearLayout;
jackqdyulei0b3edc72016-12-13 17:07:08 -080054import android.widget.ScrollView;
Joe Onoratob51886d2010-11-08 18:25:51 -080055import android.widget.TextView;
Jason Monk39b46742015-09-10 15:52:51 -040056
Tamas Berghammer265d3c22016-06-22 15:34:45 +010057import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Doris Linged4685f2017-10-25 14:08:57 -070058import com.android.settings.core.InstrumentedPreferenceFragment;
Maurice Lam2eb170c2017-04-28 16:18:47 -070059import com.android.settings.password.ChooseLockSettingsHelper;
60import com.android.settings.password.ConfirmLockPattern;
Sudheer Shanka7dbbe132016-02-16 14:19:32 +000061import com.android.settingslib.RestrictedLockUtils;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080062
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +010063import java.util.List;
64
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080065/**
66 * Confirm and execute a reset of the device to a clean "just out of the box"
67 * state. Multiple confirmations are required: first, a general "are you sure
68 * you want to do this?" prompt, followed by a keyguard pattern trace if the user
69 * has defined one, followed by a final strongly-worded "THIS WILL ERASE EVERYTHING
70 * ON THE PHONE" prompt. If at any time the phone is allowed to go to sleep, is
71 * locked, et cetera, then the confirmation sequence is abandoned.
Amith Yamasanib14e1e02010-11-02 09:52:29 -070072 *
73 * This is the initial screen.
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080074 */
Doris Linged4685f2017-10-25 14:08:57 -070075public class MasterClear extends InstrumentedPreferenceFragment {
Joe Onoratob51886d2010-11-08 18:25:51 -080076 private static final String TAG = "MasterClear";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080077
78 private static final int KEYGUARD_REQUEST = 55;
Carlos Valdiviaa9736ed2018-01-16 13:59:31 -080079 private static final int CREDENTIAL_CONFIRM_REQUEST = 56;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080080
Amith Yamasanib14e1e02010-11-02 09:52:29 -070081 static final String ERASE_EXTERNAL_EXTRA = "erase_sd";
qingxi072f2862017-04-11 18:28:40 -070082 static final String ERASE_ESIMS_EXTRA = "erase_esim";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080083
Amith Yamasanib14e1e02010-11-02 09:52:29 -070084 private View mContentView;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080085 private Button mInitiateButton;
Dianne Hackborn1337d0f2010-10-14 11:58:30 -070086 private View mExternalStorageContainer;
qingxi072f2862017-04-11 18:28:40 -070087 @VisibleForTesting CheckBox mExternalStorage;
jackqdyulei0b3edc72016-12-13 17:07:08 -080088 private ScrollView mScrollView;
89
90 private final OnGlobalLayoutListener mOnGlobalLayoutListener = new OnGlobalLayoutListener() {
91 @Override
92 public void onGlobalLayout() {
93 mScrollView.getViewTreeObserver().removeOnGlobalLayoutListener(mOnGlobalLayoutListener);
94 mInitiateButton.setEnabled(hasReachedBottom(mScrollView));
95 }
96 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080097
Doris Ling03a3b512017-10-18 14:25:01 -070098 @Override
Doris Linged4685f2017-10-25 14:08:57 -070099 public void onCreate(@Nullable Bundle savedInstanceState) {
100 super.onCreate(savedInstanceState);
Doris Ling4a012832017-11-13 17:58:13 -0800101 getActivity().setTitle(R.string.master_clear_title);
Doris Ling03a3b512017-10-18 14:25:01 -0700102 }
103
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800104 /**
Jim Miller2deec7e2010-04-13 17:43:36 -0700105 * Keyguard validation is run using the standard {@link ConfirmLockPattern}
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800106 * component as a subactivity
Jim Miller2deec7e2010-04-13 17:43:36 -0700107 * @param request the request code to be returned once confirmation finishes
108 * @return true if confirmation launched
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800109 */
Jim Miller2deec7e2010-04-13 17:43:36 -0700110 private boolean runKeyguardConfirmation(int request) {
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700111 Resources res = getActivity().getResources();
Jorim Jaggi8a09b612015-04-06 17:47:18 -0700112 return new ChooseLockSettingsHelper(getActivity(), this).launchConfirmationActivity(
113 request, res.getText(R.string.master_clear_title));
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800114 }
115
116 @Override
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700117 public void onActivityResult(int requestCode, int resultCode, Intent data) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800118 super.onActivityResult(requestCode, resultCode, data);
119
Carlos Valdiviaa9736ed2018-01-16 13:59:31 -0800120 if (requestCode != KEYGUARD_REQUEST || requestCode != CREDENTIAL_CONFIRM_REQUEST) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800121 return;
122 }
123
124 // If the user entered a valid keyguard trace, present the final
125 // confirmation prompt; otherwise, go back to the initial state.
126 if (resultCode == Activity.RESULT_OK) {
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700127 showFinalConfirmation();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800128 } else {
129 establishInitialState();
130 }
131 }
132
qingxi072f2862017-04-11 18:28:40 -0700133 @VisibleForTesting
134 void showFinalConfirmation() {
Stuart Scottbe903412014-07-24 19:22:06 -0700135 Bundle args = new Bundle();
136 args.putBoolean(ERASE_EXTERNAL_EXTRA, mExternalStorage.isChecked());
Jeff Davidsona0b84722017-07-26 17:38:41 -0700137 // TODO: Offer the user a choice to wipe eSIMs when it is technically feasible to do so.
138 args.putBoolean(ERASE_ESIMS_EXTRA, true);
Fan Zhangc6ca3142017-02-14 15:02:35 -0800139 ((SettingsActivity) getActivity()).startPreferencePanel(
140 this, MasterClearConfirm.class.getName(),
Stuart Scottbe903412014-07-24 19:22:06 -0700141 args, R.string.master_clear_confirm_title, null, null, 0);
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700142 }
143
Carlos Valdiviaa9736ed2018-01-16 13:59:31 -0800144 @VisibleForTesting
145 boolean tryShowAccountConfirmation() {
146 final Context context = getActivity();
147 final String accountType = context.getString(R.string.account_type);
148 final String packageName = context.getString(R.string.account_confirmation_package);
149 if (TextUtils.isEmpty(accountType) || TextUtils.isEmpty(packageName)) {
150 return false;
151 }
152 final AccountManager am = AccountManager.get(context);
153 Account[] accounts = am.getAccountsByType(accountType);
154 if (accounts != null && accounts.length > 0) {
155 final Intent requestAccountConfirmation = new Intent()
156 .setPackage(packageName)
157 .setAction("android.accounts.action.PRE_FACTORY_RESET");
158 // Check to make sure that the intent is supported.
159 final PackageManager pm = context.getPackageManager();
160 final List<ResolveInfo> resolutions =
161 pm.queryIntentActivities(requestAccountConfirmation, 0);
162 if (resolutions != null && resolutions.size() > 0) {
163 getActivity().startActivityForResult(
164 requestAccountConfirmation, CREDENTIAL_CONFIRM_REQUEST);
165 return true;
166 }
167 }
168 return false;
169 }
170
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800171 /**
172 * If the user clicks to begin the reset sequence, we next require a
173 * keyguard confirmation if the user has currently enabled one. If there
174 * is no keyguard available, we simply go to the final confirmation prompt.
Christine Franksa09eb382017-06-23 14:28:21 -0700175 *
176 * 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 -0800177 */
Christine Franksa09eb382017-06-23 14:28:21 -0700178 @VisibleForTesting
179 protected final Button.OnClickListener mInitiateListener = new Button.OnClickListener() {
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700180
Christine Franksa09eb382017-06-23 14:28:21 -0700181 public void onClick(View view) {
182 final Context context = view.getContext();
183 if (Utils.isDemoUser(context)) {
Justin Klaassen30257272017-08-08 21:58:05 -0700184 final ComponentName componentName = Utils.getDeviceOwnerComponent(context);
185 if (componentName != null) {
Christine Franksa09eb382017-06-23 14:28:21 -0700186 final Intent requestFactoryReset = new Intent()
Justin Klaassen30257272017-08-08 21:58:05 -0700187 .setPackage(componentName.getPackageName())
Christine Franksa09eb382017-06-23 14:28:21 -0700188 .setAction(Intent.ACTION_FACTORY_RESET);
189 context.startActivity(requestFactoryReset);
Christine Franksd7713c92017-01-20 11:24:14 -0800190 }
Carlos Valdiviaa9736ed2018-01-16 13:59:31 -0800191 return;
192 }
193
194 if (!tryShowAccountConfirmation() && !runKeyguardConfirmation(KEYGUARD_REQUEST)) {
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700195 showFinalConfirmation();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800196 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800197 }
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700198 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800199
200 /**
201 * In its initial state, the activity presents a button for the user to
202 * click in order to initiate a confirmation sequence. This method is
203 * called from various other points in the code to reset the activity to
204 * this base state.
Jim Miller47d380f2010-01-20 13:37:14 -0800205 *
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800206 * <p>Reinflating views from resources is expensive and prevents us from
207 * caching widget pointers, so we use a single-inflate pattern: we lazy-
208 * inflate each view, caching all of the widget pointers we'll need at the
209 * time, then simply reuse the inflated views directly whenever we need
210 * to change contents.
211 */
212 private void establishInitialState() {
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700213 mInitiateButton = (Button) mContentView.findViewById(R.id.initiate_master_clear);
214 mInitiateButton.setOnClickListener(mInitiateListener);
215 mExternalStorageContainer = mContentView.findViewById(R.id.erase_external_container);
216 mExternalStorage = (CheckBox) mContentView.findViewById(R.id.erase_external);
jackqdyulei0b3edc72016-12-13 17:07:08 -0800217 mScrollView = (ScrollView) mContentView.findViewById(R.id.master_clear_scrollview);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800218
Kenny Root3785e392011-01-18 15:14:32 -0800219 /*
220 * If the external storage is emulated, it will be erased with a factory
221 * reset at any rate. There is no need to have a separate option until
222 * we have a factory reset that only erases some directories and not
Ben Komalo2a321922011-09-07 16:42:34 -0700223 * others. Likewise, if it's non-removable storage, it could potentially have been
224 * encrypted, and will also need to be wiped.
Kenny Root3785e392011-01-18 15:14:32 -0800225 */
Ben Komalo2a321922011-09-07 16:42:34 -0700226 boolean isExtStorageEmulated = Environment.isExternalStorageEmulated();
227 if (isExtStorageEmulated
228 || (!Environment.isExternalStorageRemovable() && isExtStorageEncrypted())) {
Kenny Root3785e392011-01-18 15:14:32 -0800229 mExternalStorageContainer.setVisibility(View.GONE);
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700230
Kenny Root3785e392011-01-18 15:14:32 -0800231 final View externalOption = mContentView.findViewById(R.id.erase_external_option_text);
232 externalOption.setVisibility(View.GONE);
233
234 final View externalAlsoErased = mContentView.findViewById(R.id.also_erases_external);
235 externalAlsoErased.setVisibility(View.VISIBLE);
Ben Komalo2a321922011-09-07 16:42:34 -0700236
237 // If it's not emulated, it is on a separate partition but it means we're doing
238 // a force wipe due to encryption.
239 mExternalStorage.setChecked(!isExtStorageEmulated);
Kenny Root3785e392011-01-18 15:14:32 -0800240 } else {
241 mExternalStorageContainer.setOnClickListener(new View.OnClickListener() {
242
243 @Override
244 public void onClick(View v) {
245 mExternalStorage.toggle();
246 }
247 });
248 }
Joe Onoratob51886d2010-11-08 18:25:51 -0800249
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -0700250 if (showWipeEuicc()) {
Jeff Davidsona0b84722017-07-26 17:38:41 -0700251 final View esimAlsoErased = mContentView.findViewById(R.id.also_erases_esim);
252 esimAlsoErased.setVisibility(View.VISIBLE);
qingxi072f2862017-04-11 18:28:40 -0700253
Jeff Davidsona0b84722017-07-26 17:38:41 -0700254 final View noCancelMobilePlan = mContentView.findViewById(R.id.no_cancel_mobile_plan);
255 noCancelMobilePlan.setVisibility(View.VISIBLE);
qingxi072f2862017-04-11 18:28:40 -0700256 }
257
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100258 final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
259 loadAccountList(um);
Julia Reynoldsce25af42015-07-08 16:56:31 -0400260 StringBuffer contentDescription = new StringBuffer();
261 View masterClearContainer = mContentView.findViewById(R.id.master_clear_container);
262 getContentDescription(masterClearContainer, contentDescription);
263 masterClearContainer.setContentDescription(contentDescription);
jackqdyulei0b3edc72016-12-13 17:07:08 -0800264
265 // Set the status of initiateButton based on scrollview
266 mScrollView.setOnScrollChangeListener(new OnScrollChangeListener() {
267 @Override
268 public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX,
269 int oldScrollY) {
270 if (v instanceof ScrollView && hasReachedBottom((ScrollView) v)) {
271 mInitiateButton.setEnabled(true);
272 }
273 }
274 });
275
276 // Set the initial state of the initiateButton
277 mScrollView.getViewTreeObserver().addOnGlobalLayoutListener(mOnGlobalLayoutListener);
278 }
279
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -0700280 /**
Jeff Davidsona0b84722017-07-26 17:38:41 -0700281 * Whether to show strings indicating that the eUICC will be wiped.
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -0700282 *
Jeff Davidsona0b84722017-07-26 17:38:41 -0700283 * <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 -0700284 * provisioned (that is, at least one profile was ever downloaded onto it).
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -0700285 */
286 @VisibleForTesting
287 boolean showWipeEuicc() {
288 Context context = getContext();
289 if (!isEuiccEnabled(context)) {
290 return false;
291 }
292 ContentResolver cr = context.getContentResolver();
Jeff Davidson4ba74782017-06-30 18:02:13 -0700293 return Settings.Global.getInt(cr, Settings.Global.EUICC_PROVISIONED, 0) != 0;
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -0700294 }
295
296 @VisibleForTesting
297 protected boolean isEuiccEnabled(Context context) {
298 EuiccManager euiccManager = (EuiccManager) context.getSystemService(Context.EUICC_SERVICE);
299 return euiccManager.isEnabled();
300 }
301
jackqdyulei0b3edc72016-12-13 17:07:08 -0800302 @VisibleForTesting
303 boolean hasReachedBottom(final ScrollView scrollView) {
304 if (scrollView.getChildCount() < 1) {
305 return true;
306 }
307
308 final View view = scrollView.getChildAt(0);
309 final int diff = view.getBottom() - (scrollView.getHeight() + scrollView.getScrollY());
310
311 return diff <= 0;
Julia Reynoldsce25af42015-07-08 16:56:31 -0400312 }
313
314 private void getContentDescription(View v, StringBuffer description) {
Jason Monkfda77412016-05-06 14:28:09 -0400315 if (v.getVisibility() != View.VISIBLE) {
316 return;
317 }
Julia Reynoldsce25af42015-07-08 16:56:31 -0400318 if (v instanceof ViewGroup) {
319 ViewGroup vGroup = (ViewGroup) v;
320 for (int i = 0; i < vGroup.getChildCount(); i++) {
321 View nextChild = vGroup.getChildAt(i);
322 getContentDescription(nextChild, description);
323 }
324 } else if (v instanceof TextView) {
325 TextView vText = (TextView) v;
326 description.append(vText.getText());
327 description.append(","); // Allow Talkback to pause between sections.
328 }
Joe Onoratob51886d2010-11-08 18:25:51 -0800329 }
330
Ben Komalo2a321922011-09-07 16:42:34 -0700331 private boolean isExtStorageEncrypted() {
332 String state = SystemProperties.get("vold.decrypt");
333 return !"".equals(state);
334 }
335
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100336 private void loadAccountList(final UserManager um) {
Joe Onoratob51886d2010-11-08 18:25:51 -0800337 View accountsLabel = mContentView.findViewById(R.id.accounts_label);
338 LinearLayout contents = (LinearLayout)mContentView.findViewById(R.id.accounts);
Amith Yamasani3f45de52011-09-22 14:34:17 -0700339 contents.removeAllViews();
Joe Onoratob51886d2010-11-08 18:25:51 -0800340
341 Context context = getActivity();
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100342 final List<UserInfo> profiles = um.getProfiles(UserHandle.myUserId());
343 final int profilesSize = profiles.size();
Joe Onoratob51886d2010-11-08 18:25:51 -0800344
345 AccountManager mgr = AccountManager.get(context);
Joe Onoratob51886d2010-11-08 18:25:51 -0800346
347 LayoutInflater inflater = (LayoutInflater)context.getSystemService(
348 Context.LAYOUT_INFLATER_SERVICE);
349
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100350 int accountsCount = 0;
351 for (int profileIndex = 0; profileIndex < profilesSize; profileIndex++) {
352 final UserInfo userInfo = profiles.get(profileIndex);
353 final int profileId = userInfo.id;
354 final UserHandle userHandle = new UserHandle(profileId);
355 Account[] accounts = mgr.getAccountsAsUser(profileId);
356 final int N = accounts.length;
357 if (N == 0) {
Joe Onoratob51886d2010-11-08 18:25:51 -0800358 continue;
359 }
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100360 accountsCount += N;
Joe Onoratob51886d2010-11-08 18:25:51 -0800361
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100362 AuthenticatorDescription[] descs = AccountManager.get(context)
363 .getAuthenticatorTypesAsUser(profileId);
364 final int M = descs.length;
365
Bartosz Fabianowski30ba8682017-04-19 11:51:43 +0200366 if (profilesSize > 1) {
367 View titleView = Utils.inflateCategoryHeader(inflater, contents);
368 final TextView titleText = (TextView) titleView.findViewById(android.R.id.title);
369 titleText.setText(userInfo.isManagedProfile() ? R.string.category_work
370 : R.string.category_personal);
371 contents.addView(titleView);
372 }
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100373
374 for (int i = 0; i < N; i++) {
375 Account account = accounts[i];
376 AuthenticatorDescription desc = null;
377 for (int j = 0; j < M; j++) {
378 if (account.type.equals(descs[j].type)) {
379 desc = descs[j];
380 break;
381 }
382 }
383 if (desc == null) {
384 Log.w(TAG, "No descriptor for account name=" + account.name
385 + " type=" + account.type);
386 continue;
387 }
388 Drawable icon = null;
389 try {
390 if (desc.iconId != 0) {
Zoltan Szatmary-Ban546790c2014-12-02 17:22:10 +0000391 Context authContext = context.createPackageContextAsUser(desc.packageName,
392 0, userHandle);
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100393 icon = context.getPackageManager().getUserBadgedIcon(
394 authContext.getDrawable(desc.iconId), userHandle);
395 }
396 } catch (PackageManager.NameNotFoundException e) {
Rubin Xud1ce82a2015-06-08 17:21:19 +0100397 Log.w(TAG, "Bad package name for account type " + desc.type);
398 } catch (Resources.NotFoundException e) {
399 Log.w(TAG, "Invalid icon id for account type " + desc.type, e);
400 }
401 if (icon == null) {
402 icon = context.getPackageManager().getDefaultActivityIcon();
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100403 }
404
Fan Zhang6b2bb392016-09-28 09:07:44 -0700405 View child = inflater.inflate(R.layout.master_clear_account, contents, false);
406 ((ImageView) child.findViewById(android.R.id.icon)).setImageDrawable(icon);
407 ((TextView) child.findViewById(android.R.id.title)).setText(account.name);
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100408 contents.addView(child);
Joe Onoratob51886d2010-11-08 18:25:51 -0800409 }
Joe Onoratob51886d2010-11-08 18:25:51 -0800410 }
411
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100412 if (accountsCount > 0) {
413 accountsLabel.setVisibility(View.VISIBLE);
414 contents.setVisibility(View.VISIBLE);
415 }
416 // Checking for all other users and their profiles if any.
417 View otherUsers = mContentView.findViewById(R.id.other_users_present);
418 final boolean hasOtherUsers = (um.getUserCount() - profilesSize) > 0;
419 otherUsers.setVisibility(hasOtherUsers ? View.VISIBLE : View.GONE);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800420 }
421
422 @Override
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700423 public View onCreateView(LayoutInflater inflater, ViewGroup container,
424 Bundle savedInstanceState) {
Christine Franks14782222017-01-23 16:44:02 -0800425 final Context context = getContext();
426 final EnforcedAdmin admin = RestrictedLockUtils.checkIfRestrictionEnforced(context,
427 UserManager.DISALLOW_FACTORY_RESET, UserHandle.myUserId());
428 final UserManager um = UserManager.get(context);
429 final boolean disallow = !um.isAdminUser() || RestrictedLockUtils.hasBaseUserRestriction(
430 context, UserManager.DISALLOW_FACTORY_RESET, UserHandle.myUserId());
Christine Franksa09eb382017-06-23 14:28:21 -0700431 if (disallow && !Utils.isDemoUser(context)) {
Julia Reynolds2c539332014-06-11 12:56:02 -0400432 return inflater.inflate(R.layout.master_clear_disallowed_screen, null);
Sudheer Shanka7dbbe132016-02-16 14:19:32 +0000433 } else if (admin != null) {
434 View view = inflater.inflate(R.layout.admin_support_details_empty_view, null);
435 ShowAdminSupportDetailsDialog.setAdminSupportDetails(getActivity(), view, admin, false);
436 view.setVisibility(View.VISIBLE);
437 return view;
Julia Reynolds2c539332014-06-11 12:56:02 -0400438 }
439
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700440 mContentView = inflater.inflate(R.layout.master_clear, null);
Joe Onoratob51886d2010-11-08 18:25:51 -0800441
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800442 establishInitialState();
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700443 return mContentView;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800444 }
Chris Wren8a963ba2015-03-20 10:29:14 -0400445
446 @Override
Fan Zhang65076132016-08-08 10:25:13 -0700447 public int getMetricsCategory() {
Chris Wren9d1bfd12016-01-26 18:04:01 -0500448 return MetricsEvent.MASTER_CLEAR;
Chris Wren8a963ba2015-03-20 10:29:14 -0400449 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800450}