blob: 687e6458361b37074e772d785230e46ac3d7193e [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
Carlos Valdivia5dd6ed42018-01-23 09:12:59 -080078 @VisibleForTesting static final int KEYGUARD_REQUEST = 55;
Carlos Valdivia08c88202018-01-21 18:57:28 -080079 @VisibleForTesting static final int CREDENTIAL_CONFIRM_REQUEST = 56;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080080
Qingxi Lic8a2b042018-01-11 11:35:07 -080081 private static final String KEY_SHOW_ESIM_RESET_CHECKBOX
82 = "masterclear.allow_retain_esim_profiles_after_fdr";
83
Amith Yamasanib14e1e02010-11-02 09:52:29 -070084 static final String ERASE_EXTERNAL_EXTRA = "erase_sd";
qingxi072f2862017-04-11 18:28:40 -070085 static final String ERASE_ESIMS_EXTRA = "erase_esim";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080086
Amith Yamasanib14e1e02010-11-02 09:52:29 -070087 private View mContentView;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080088 private Button mInitiateButton;
Dianne Hackborn1337d0f2010-10-14 11:58:30 -070089 private View mExternalStorageContainer;
qingxi072f2862017-04-11 18:28:40 -070090 @VisibleForTesting CheckBox mExternalStorage;
Qingxi Lic8a2b042018-01-11 11:35:07 -080091 private View mEsimStorageContainer;
92 @VisibleForTesting CheckBox mEsimStorage;
jackqdyulei0b3edc72016-12-13 17:07:08 -080093 private ScrollView mScrollView;
94
95 private final OnGlobalLayoutListener mOnGlobalLayoutListener = new OnGlobalLayoutListener() {
96 @Override
97 public void onGlobalLayout() {
98 mScrollView.getViewTreeObserver().removeOnGlobalLayoutListener(mOnGlobalLayoutListener);
99 mInitiateButton.setEnabled(hasReachedBottom(mScrollView));
100 }
101 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800102
Doris Ling03a3b512017-10-18 14:25:01 -0700103 @Override
Doris Linged4685f2017-10-25 14:08:57 -0700104 public void onCreate(@Nullable Bundle savedInstanceState) {
105 super.onCreate(savedInstanceState);
Doris Ling4a012832017-11-13 17:58:13 -0800106 getActivity().setTitle(R.string.master_clear_title);
Doris Ling03a3b512017-10-18 14:25:01 -0700107 }
108
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800109 /**
Jim Miller2deec7e2010-04-13 17:43:36 -0700110 * Keyguard validation is run using the standard {@link ConfirmLockPattern}
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800111 * component as a subactivity
Jim Miller2deec7e2010-04-13 17:43:36 -0700112 * @param request the request code to be returned once confirmation finishes
113 * @return true if confirmation launched
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800114 */
Jim Miller2deec7e2010-04-13 17:43:36 -0700115 private boolean runKeyguardConfirmation(int request) {
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700116 Resources res = getActivity().getResources();
Jorim Jaggi8a09b612015-04-06 17:47:18 -0700117 return new ChooseLockSettingsHelper(getActivity(), this).launchConfirmationActivity(
118 request, res.getText(R.string.master_clear_title));
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800119 }
120
Carlos Valdivia5dd6ed42018-01-23 09:12:59 -0800121 @VisibleForTesting
122 boolean isValidRequestCode(int requestCode) {
123 return !((requestCode != KEYGUARD_REQUEST) && (requestCode != CREDENTIAL_CONFIRM_REQUEST));
124 }
125
Carlos Valdivia51146042018-01-23 17:17:56 -0800126 @VisibleForTesting
127 boolean isShowFinalConfirmation(int requestCode, int resultCode) {
128 return (resultCode == Activity.RESULT_OK) || (requestCode == CREDENTIAL_CONFIRM_REQUEST);
129 }
130
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800131 @Override
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700132 public void onActivityResult(int requestCode, int resultCode, Intent data) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800133 super.onActivityResult(requestCode, resultCode, data);
Carlos Valdivia5dd6ed42018-01-23 09:12:59 -0800134 if (!isValidRequestCode(requestCode)) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800135 return;
136 }
137
138 // If the user entered a valid keyguard trace, present the final
139 // confirmation prompt; otherwise, go back to the initial state.
Carlos Valdivia51146042018-01-23 17:17:56 -0800140 if (isShowFinalConfirmation(requestCode, resultCode)) {
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700141 showFinalConfirmation();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800142 } else {
143 establishInitialState();
144 }
145 }
146
qingxi072f2862017-04-11 18:28:40 -0700147 @VisibleForTesting
148 void showFinalConfirmation() {
Stuart Scottbe903412014-07-24 19:22:06 -0700149 Bundle args = new Bundle();
150 args.putBoolean(ERASE_EXTERNAL_EXTRA, mExternalStorage.isChecked());
Qingxi Lic8a2b042018-01-11 11:35:07 -0800151 args.putBoolean(ERASE_ESIMS_EXTRA, mEsimStorage.isChecked());
Fan Zhangc6ca3142017-02-14 15:02:35 -0800152 ((SettingsActivity) getActivity()).startPreferencePanel(
153 this, MasterClearConfirm.class.getName(),
Stuart Scottbe903412014-07-24 19:22:06 -0700154 args, R.string.master_clear_confirm_title, null, null, 0);
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700155 }
156
Carlos Valdiviaa9736ed2018-01-16 13:59:31 -0800157 @VisibleForTesting
158 boolean tryShowAccountConfirmation() {
159 final Context context = getActivity();
160 final String accountType = context.getString(R.string.account_type);
161 final String packageName = context.getString(R.string.account_confirmation_package);
Carlos Valdivia51146042018-01-23 17:17:56 -0800162 final String className = context.getString(R.string.account_confirmation_class);
163 if (TextUtils.isEmpty(accountType)
164 || TextUtils.isEmpty(packageName)
165 || TextUtils.isEmpty(className)) {
Carlos Valdiviaa9736ed2018-01-16 13:59:31 -0800166 return false;
167 }
168 final AccountManager am = AccountManager.get(context);
169 Account[] accounts = am.getAccountsByType(accountType);
170 if (accounts != null && accounts.length > 0) {
171 final Intent requestAccountConfirmation = new Intent()
172 .setPackage(packageName)
Carlos Valdivia51146042018-01-23 17:17:56 -0800173 .setComponent(new ComponentName(packageName, className));
Carlos Valdiviaa9736ed2018-01-16 13:59:31 -0800174 // Check to make sure that the intent is supported.
175 final PackageManager pm = context.getPackageManager();
Carlos Valdivia08c88202018-01-21 18:57:28 -0800176 final ResolveInfo resolution = pm.resolveActivity(requestAccountConfirmation, 0);
177 if (resolution != null
178 && resolution.activityInfo != null
179 && packageName.equals(resolution.activityInfo.packageName)) {
180 // Note that we need to check the packagename to make sure that an Activity resolver
181 // wasn't returned.
Carlos Valdivia51146042018-01-23 17:17:56 -0800182 startActivityForResult(
Carlos Valdiviaa9736ed2018-01-16 13:59:31 -0800183 requestAccountConfirmation, CREDENTIAL_CONFIRM_REQUEST);
184 return true;
185 }
186 }
187 return false;
188 }
189
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800190 /**
191 * If the user clicks to begin the reset sequence, we next require a
192 * keyguard confirmation if the user has currently enabled one. If there
193 * is no keyguard available, we simply go to the final confirmation prompt.
Christine Franksa09eb382017-06-23 14:28:21 -0700194 *
195 * 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 -0800196 */
Christine Franksa09eb382017-06-23 14:28:21 -0700197 @VisibleForTesting
198 protected final Button.OnClickListener mInitiateListener = new Button.OnClickListener() {
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700199
Christine Franksa09eb382017-06-23 14:28:21 -0700200 public void onClick(View view) {
201 final Context context = view.getContext();
202 if (Utils.isDemoUser(context)) {
Justin Klaassen30257272017-08-08 21:58:05 -0700203 final ComponentName componentName = Utils.getDeviceOwnerComponent(context);
204 if (componentName != null) {
Christine Franksa09eb382017-06-23 14:28:21 -0700205 final Intent requestFactoryReset = new Intent()
Justin Klaassen30257272017-08-08 21:58:05 -0700206 .setPackage(componentName.getPackageName())
Christine Franksa09eb382017-06-23 14:28:21 -0700207 .setAction(Intent.ACTION_FACTORY_RESET);
208 context.startActivity(requestFactoryReset);
Christine Franksd7713c92017-01-20 11:24:14 -0800209 }
Carlos Valdiviaa9736ed2018-01-16 13:59:31 -0800210 return;
211 }
212
213 if (!tryShowAccountConfirmation() && !runKeyguardConfirmation(KEYGUARD_REQUEST)) {
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700214 showFinalConfirmation();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800215 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800216 }
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700217 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800218
219 /**
220 * In its initial state, the activity presents a button for the user to
221 * click in order to initiate a confirmation sequence. This method is
222 * called from various other points in the code to reset the activity to
223 * this base state.
Jim Miller47d380f2010-01-20 13:37:14 -0800224 *
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800225 * <p>Reinflating views from resources is expensive and prevents us from
226 * caching widget pointers, so we use a single-inflate pattern: we lazy-
227 * inflate each view, caching all of the widget pointers we'll need at the
228 * time, then simply reuse the inflated views directly whenever we need
229 * to change contents.
230 */
231 private void establishInitialState() {
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700232 mInitiateButton = (Button) mContentView.findViewById(R.id.initiate_master_clear);
233 mInitiateButton.setOnClickListener(mInitiateListener);
234 mExternalStorageContainer = mContentView.findViewById(R.id.erase_external_container);
235 mExternalStorage = (CheckBox) mContentView.findViewById(R.id.erase_external);
Qingxi Lic8a2b042018-01-11 11:35:07 -0800236 mEsimStorageContainer = mContentView.findViewById(R.id.erase_esim_container);
237 mEsimStorage = (CheckBox) mContentView.findViewById(R.id.erase_esim);
jackqdyulei0b3edc72016-12-13 17:07:08 -0800238 mScrollView = (ScrollView) mContentView.findViewById(R.id.master_clear_scrollview);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800239
Kenny Root3785e392011-01-18 15:14:32 -0800240 /*
241 * If the external storage is emulated, it will be erased with a factory
242 * reset at any rate. There is no need to have a separate option until
243 * we have a factory reset that only erases some directories and not
Ben Komalo2a321922011-09-07 16:42:34 -0700244 * others. Likewise, if it's non-removable storage, it could potentially have been
245 * encrypted, and will also need to be wiped.
Kenny Root3785e392011-01-18 15:14:32 -0800246 */
Ben Komalo2a321922011-09-07 16:42:34 -0700247 boolean isExtStorageEmulated = Environment.isExternalStorageEmulated();
248 if (isExtStorageEmulated
249 || (!Environment.isExternalStorageRemovable() && isExtStorageEncrypted())) {
Kenny Root3785e392011-01-18 15:14:32 -0800250 mExternalStorageContainer.setVisibility(View.GONE);
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700251
Kenny Root3785e392011-01-18 15:14:32 -0800252 final View externalOption = mContentView.findViewById(R.id.erase_external_option_text);
253 externalOption.setVisibility(View.GONE);
254
255 final View externalAlsoErased = mContentView.findViewById(R.id.also_erases_external);
256 externalAlsoErased.setVisibility(View.VISIBLE);
Ben Komalo2a321922011-09-07 16:42:34 -0700257
258 // If it's not emulated, it is on a separate partition but it means we're doing
259 // a force wipe due to encryption.
260 mExternalStorage.setChecked(!isExtStorageEmulated);
Kenny Root3785e392011-01-18 15:14:32 -0800261 } else {
262 mExternalStorageContainer.setOnClickListener(new View.OnClickListener() {
263
264 @Override
265 public void onClick(View v) {
266 mExternalStorage.toggle();
267 }
268 });
269 }
Joe Onoratob51886d2010-11-08 18:25:51 -0800270
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -0700271 if (showWipeEuicc()) {
Qingxi Lic8a2b042018-01-11 11:35:07 -0800272 if (showWipeEuiccCheckbox()) {
273 TextView title = mContentView.findViewById(R.id.erase_esim_title);
274 title.setText(R.string.erase_esim_storage);
275 mEsimStorageContainer.setVisibility(View.VISIBLE);
276 mEsimStorageContainer.setOnClickListener(new View.OnClickListener() {
277 @Override
278 public void onClick(View v) {
279 mEsimStorage.toggle();
280 }
281 });
282 } else {
283 final View esimAlsoErased = mContentView.findViewById(R.id.also_erases_esim);
284 esimAlsoErased.setVisibility(View.VISIBLE);
qingxi072f2862017-04-11 18:28:40 -0700285
Qingxi Lic8a2b042018-01-11 11:35:07 -0800286 final View noCancelMobilePlan = mContentView.findViewById(
287 R.id.no_cancel_mobile_plan);
288 noCancelMobilePlan.setVisibility(View.VISIBLE);
289 mEsimStorage.setChecked(true /* checked */);
290 }
qingxi072f2862017-04-11 18:28:40 -0700291 }
292
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100293 final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
294 loadAccountList(um);
Julia Reynoldsce25af42015-07-08 16:56:31 -0400295 StringBuffer contentDescription = new StringBuffer();
296 View masterClearContainer = mContentView.findViewById(R.id.master_clear_container);
297 getContentDescription(masterClearContainer, contentDescription);
298 masterClearContainer.setContentDescription(contentDescription);
jackqdyulei0b3edc72016-12-13 17:07:08 -0800299
300 // Set the status of initiateButton based on scrollview
301 mScrollView.setOnScrollChangeListener(new OnScrollChangeListener() {
302 @Override
303 public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX,
304 int oldScrollY) {
305 if (v instanceof ScrollView && hasReachedBottom((ScrollView) v)) {
306 mInitiateButton.setEnabled(true);
307 }
308 }
309 });
310
311 // Set the initial state of the initiateButton
312 mScrollView.getViewTreeObserver().addOnGlobalLayoutListener(mOnGlobalLayoutListener);
313 }
314
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -0700315 /**
Jeff Davidsona0b84722017-07-26 17:38:41 -0700316 * Whether to show strings indicating that the eUICC will be wiped.
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -0700317 *
Jeff Davidsona0b84722017-07-26 17:38:41 -0700318 * <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 -0700319 * provisioned (that is, at least one profile was ever downloaded onto it).
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -0700320 */
321 @VisibleForTesting
322 boolean showWipeEuicc() {
323 Context context = getContext();
324 if (!isEuiccEnabled(context)) {
325 return false;
326 }
327 ContentResolver cr = context.getContentResolver();
Jeff Davidson4ba74782017-06-30 18:02:13 -0700328 return Settings.Global.getInt(cr, Settings.Global.EUICC_PROVISIONED, 0) != 0;
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -0700329 }
330
331 @VisibleForTesting
Qingxi Lic8a2b042018-01-11 11:35:07 -0800332 boolean showWipeEuiccCheckbox() {
333 return SystemProperties
334 .getBoolean(KEY_SHOW_ESIM_RESET_CHECKBOX, false /* def */);
335 }
336
337 @VisibleForTesting
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -0700338 protected boolean isEuiccEnabled(Context context) {
339 EuiccManager euiccManager = (EuiccManager) context.getSystemService(Context.EUICC_SERVICE);
340 return euiccManager.isEnabled();
341 }
342
jackqdyulei0b3edc72016-12-13 17:07:08 -0800343 @VisibleForTesting
344 boolean hasReachedBottom(final ScrollView scrollView) {
345 if (scrollView.getChildCount() < 1) {
346 return true;
347 }
348
349 final View view = scrollView.getChildAt(0);
350 final int diff = view.getBottom() - (scrollView.getHeight() + scrollView.getScrollY());
351
352 return diff <= 0;
Julia Reynoldsce25af42015-07-08 16:56:31 -0400353 }
354
355 private void getContentDescription(View v, StringBuffer description) {
Jason Monkfda77412016-05-06 14:28:09 -0400356 if (v.getVisibility() != View.VISIBLE) {
357 return;
358 }
Julia Reynoldsce25af42015-07-08 16:56:31 -0400359 if (v instanceof ViewGroup) {
360 ViewGroup vGroup = (ViewGroup) v;
361 for (int i = 0; i < vGroup.getChildCount(); i++) {
362 View nextChild = vGroup.getChildAt(i);
363 getContentDescription(nextChild, description);
364 }
365 } else if (v instanceof TextView) {
366 TextView vText = (TextView) v;
367 description.append(vText.getText());
368 description.append(","); // Allow Talkback to pause between sections.
369 }
Joe Onoratob51886d2010-11-08 18:25:51 -0800370 }
371
Ben Komalo2a321922011-09-07 16:42:34 -0700372 private boolean isExtStorageEncrypted() {
373 String state = SystemProperties.get("vold.decrypt");
374 return !"".equals(state);
375 }
376
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100377 private void loadAccountList(final UserManager um) {
Joe Onoratob51886d2010-11-08 18:25:51 -0800378 View accountsLabel = mContentView.findViewById(R.id.accounts_label);
379 LinearLayout contents = (LinearLayout)mContentView.findViewById(R.id.accounts);
Amith Yamasani3f45de52011-09-22 14:34:17 -0700380 contents.removeAllViews();
Joe Onoratob51886d2010-11-08 18:25:51 -0800381
382 Context context = getActivity();
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100383 final List<UserInfo> profiles = um.getProfiles(UserHandle.myUserId());
384 final int profilesSize = profiles.size();
Joe Onoratob51886d2010-11-08 18:25:51 -0800385
386 AccountManager mgr = AccountManager.get(context);
Joe Onoratob51886d2010-11-08 18:25:51 -0800387
388 LayoutInflater inflater = (LayoutInflater)context.getSystemService(
389 Context.LAYOUT_INFLATER_SERVICE);
390
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100391 int accountsCount = 0;
392 for (int profileIndex = 0; profileIndex < profilesSize; profileIndex++) {
393 final UserInfo userInfo = profiles.get(profileIndex);
394 final int profileId = userInfo.id;
395 final UserHandle userHandle = new UserHandle(profileId);
396 Account[] accounts = mgr.getAccountsAsUser(profileId);
397 final int N = accounts.length;
398 if (N == 0) {
Joe Onoratob51886d2010-11-08 18:25:51 -0800399 continue;
400 }
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100401 accountsCount += N;
Joe Onoratob51886d2010-11-08 18:25:51 -0800402
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100403 AuthenticatorDescription[] descs = AccountManager.get(context)
404 .getAuthenticatorTypesAsUser(profileId);
405 final int M = descs.length;
406
Bartosz Fabianowski30ba8682017-04-19 11:51:43 +0200407 if (profilesSize > 1) {
408 View titleView = Utils.inflateCategoryHeader(inflater, contents);
409 final TextView titleText = (TextView) titleView.findViewById(android.R.id.title);
410 titleText.setText(userInfo.isManagedProfile() ? R.string.category_work
411 : R.string.category_personal);
412 contents.addView(titleView);
413 }
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100414
415 for (int i = 0; i < N; i++) {
416 Account account = accounts[i];
417 AuthenticatorDescription desc = null;
418 for (int j = 0; j < M; j++) {
419 if (account.type.equals(descs[j].type)) {
420 desc = descs[j];
421 break;
422 }
423 }
424 if (desc == null) {
425 Log.w(TAG, "No descriptor for account name=" + account.name
426 + " type=" + account.type);
427 continue;
428 }
429 Drawable icon = null;
430 try {
431 if (desc.iconId != 0) {
Zoltan Szatmary-Ban546790c2014-12-02 17:22:10 +0000432 Context authContext = context.createPackageContextAsUser(desc.packageName,
433 0, userHandle);
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100434 icon = context.getPackageManager().getUserBadgedIcon(
435 authContext.getDrawable(desc.iconId), userHandle);
436 }
437 } catch (PackageManager.NameNotFoundException e) {
Rubin Xud1ce82a2015-06-08 17:21:19 +0100438 Log.w(TAG, "Bad package name for account type " + desc.type);
439 } catch (Resources.NotFoundException e) {
440 Log.w(TAG, "Invalid icon id for account type " + desc.type, e);
441 }
442 if (icon == null) {
443 icon = context.getPackageManager().getDefaultActivityIcon();
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100444 }
445
Fan Zhang6b2bb392016-09-28 09:07:44 -0700446 View child = inflater.inflate(R.layout.master_clear_account, contents, false);
447 ((ImageView) child.findViewById(android.R.id.icon)).setImageDrawable(icon);
448 ((TextView) child.findViewById(android.R.id.title)).setText(account.name);
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100449 contents.addView(child);
Joe Onoratob51886d2010-11-08 18:25:51 -0800450 }
Joe Onoratob51886d2010-11-08 18:25:51 -0800451 }
452
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100453 if (accountsCount > 0) {
454 accountsLabel.setVisibility(View.VISIBLE);
455 contents.setVisibility(View.VISIBLE);
456 }
457 // Checking for all other users and their profiles if any.
458 View otherUsers = mContentView.findViewById(R.id.other_users_present);
459 final boolean hasOtherUsers = (um.getUserCount() - profilesSize) > 0;
460 otherUsers.setVisibility(hasOtherUsers ? View.VISIBLE : View.GONE);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800461 }
462
463 @Override
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700464 public View onCreateView(LayoutInflater inflater, ViewGroup container,
465 Bundle savedInstanceState) {
Christine Franks14782222017-01-23 16:44:02 -0800466 final Context context = getContext();
467 final EnforcedAdmin admin = RestrictedLockUtils.checkIfRestrictionEnforced(context,
468 UserManager.DISALLOW_FACTORY_RESET, UserHandle.myUserId());
469 final UserManager um = UserManager.get(context);
470 final boolean disallow = !um.isAdminUser() || RestrictedLockUtils.hasBaseUserRestriction(
471 context, UserManager.DISALLOW_FACTORY_RESET, UserHandle.myUserId());
Christine Franksa09eb382017-06-23 14:28:21 -0700472 if (disallow && !Utils.isDemoUser(context)) {
Julia Reynolds2c539332014-06-11 12:56:02 -0400473 return inflater.inflate(R.layout.master_clear_disallowed_screen, null);
Sudheer Shanka7dbbe132016-02-16 14:19:32 +0000474 } else if (admin != null) {
475 View view = inflater.inflate(R.layout.admin_support_details_empty_view, null);
476 ShowAdminSupportDetailsDialog.setAdminSupportDetails(getActivity(), view, admin, false);
477 view.setVisibility(View.VISIBLE);
478 return view;
Julia Reynolds2c539332014-06-11 12:56:02 -0400479 }
480
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700481 mContentView = inflater.inflate(R.layout.master_clear, null);
Joe Onoratob51886d2010-11-08 18:25:51 -0800482
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800483 establishInitialState();
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700484 return mContentView;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800485 }
Chris Wren8a963ba2015-03-20 10:29:14 -0400486
487 @Override
Fan Zhang65076132016-08-08 10:25:13 -0700488 public int getMetricsCategory() {
Chris Wren9d1bfd12016-01-26 18:04:01 -0500489 return MetricsEvent.MASTER_CLEAR;
Chris Wren8a963ba2015-03-20 10:29:14 -0400490 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800491}