blob: f66b1f91a6120c84498355dd394d11bd187a7abb [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 Ling72489722017-11-16 11:03:40 -080058import com.android.settings.core.InstrumentedFragment;
Fan Zhang7cf99f52018-02-16 10:37:37 -080059import com.android.settings.core.SubSettingLauncher;
Maurice Lam2eb170c2017-04-28 16:18:47 -070060import com.android.settings.password.ChooseLockSettingsHelper;
61import com.android.settings.password.ConfirmLockPattern;
Sudheer Shanka7dbbe132016-02-16 14:19:32 +000062import com.android.settingslib.RestrictedLockUtils;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080063
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +010064import java.util.List;
65
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080066/**
67 * Confirm and execute a reset of the device to a clean "just out of the box"
68 * state. Multiple confirmations are required: first, a general "are you sure
69 * you want to do this?" prompt, followed by a keyguard pattern trace if the user
70 * has defined one, followed by a final strongly-worded "THIS WILL ERASE EVERYTHING
71 * ON THE PHONE" prompt. If at any time the phone is allowed to go to sleep, is
72 * locked, et cetera, then the confirmation sequence is abandoned.
Amith Yamasanib14e1e02010-11-02 09:52:29 -070073 *
74 * This is the initial screen.
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080075 */
Doris Ling72489722017-11-16 11:03:40 -080076public class MasterClear extends InstrumentedFragment {
Joe Onoratob51886d2010-11-08 18:25:51 -080077 private static final String TAG = "MasterClear";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080078
Carlos Valdivia5dd6ed42018-01-23 09:12:59 -080079 @VisibleForTesting static final int KEYGUARD_REQUEST = 55;
Carlos Valdivia08c88202018-01-21 18:57:28 -080080 @VisibleForTesting static final int CREDENTIAL_CONFIRM_REQUEST = 56;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080081
Qingxi Lic8a2b042018-01-11 11:35:07 -080082 private static final String KEY_SHOW_ESIM_RESET_CHECKBOX
83 = "masterclear.allow_retain_esim_profiles_after_fdr";
84
Amith Yamasanib14e1e02010-11-02 09:52:29 -070085 static final String ERASE_EXTERNAL_EXTRA = "erase_sd";
qingxi072f2862017-04-11 18:28:40 -070086 static final String ERASE_ESIMS_EXTRA = "erase_esim";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080087
Amith Yamasanib14e1e02010-11-02 09:52:29 -070088 private View mContentView;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080089 private Button mInitiateButton;
Dianne Hackborn1337d0f2010-10-14 11:58:30 -070090 private View mExternalStorageContainer;
qingxi072f2862017-04-11 18:28:40 -070091 @VisibleForTesting CheckBox mExternalStorage;
Qingxi Lic8a2b042018-01-11 11:35:07 -080092 private View mEsimStorageContainer;
93 @VisibleForTesting CheckBox mEsimStorage;
jackqdyulei0b3edc72016-12-13 17:07:08 -080094 private ScrollView mScrollView;
95
96 private final OnGlobalLayoutListener mOnGlobalLayoutListener = new OnGlobalLayoutListener() {
97 @Override
98 public void onGlobalLayout() {
99 mScrollView.getViewTreeObserver().removeOnGlobalLayoutListener(mOnGlobalLayoutListener);
100 mInitiateButton.setEnabled(hasReachedBottom(mScrollView));
101 }
102 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800103
Doris Ling03a3b512017-10-18 14:25:01 -0700104 @Override
Doris Linged4685f2017-10-25 14:08:57 -0700105 public void onCreate(@Nullable Bundle savedInstanceState) {
106 super.onCreate(savedInstanceState);
Doris Ling4a012832017-11-13 17:58:13 -0800107 getActivity().setTitle(R.string.master_clear_title);
Doris Ling03a3b512017-10-18 14:25:01 -0700108 }
109
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800110 /**
Jim Miller2deec7e2010-04-13 17:43:36 -0700111 * Keyguard validation is run using the standard {@link ConfirmLockPattern}
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800112 * component as a subactivity
Jim Miller2deec7e2010-04-13 17:43:36 -0700113 * @param request the request code to be returned once confirmation finishes
114 * @return true if confirmation launched
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800115 */
Jim Miller2deec7e2010-04-13 17:43:36 -0700116 private boolean runKeyguardConfirmation(int request) {
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700117 Resources res = getActivity().getResources();
Jorim Jaggi8a09b612015-04-06 17:47:18 -0700118 return new ChooseLockSettingsHelper(getActivity(), this).launchConfirmationActivity(
119 request, res.getText(R.string.master_clear_title));
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800120 }
121
Carlos Valdivia5dd6ed42018-01-23 09:12:59 -0800122 @VisibleForTesting
123 boolean isValidRequestCode(int requestCode) {
124 return !((requestCode != KEYGUARD_REQUEST) && (requestCode != CREDENTIAL_CONFIRM_REQUEST));
125 }
126
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800127 @Override
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700128 public void onActivityResult(int requestCode, int resultCode, Intent data) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800129 super.onActivityResult(requestCode, resultCode, data);
Carlos Valdivia4b34dad2018-01-29 18:30:33 -0800130 onActivityResultInternal(requestCode, resultCode, data);
131 }
132
133 /*
134 * Internal method that allows easy testing without dealing with super references.
135 */
136 @VisibleForTesting
137 void onActivityResultInternal(int requestCode, int resultCode, Intent data) {
Carlos Valdivia5dd6ed42018-01-23 09:12:59 -0800138 if (!isValidRequestCode(requestCode)) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800139 return;
140 }
141
Carlos Valdivia4b34dad2018-01-29 18:30:33 -0800142 if (resultCode != Activity.RESULT_OK) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800143 establishInitialState();
Carlos Valdivia4b34dad2018-01-29 18:30:33 -0800144 return;
145 }
146
147 Intent intent = null;
148 // If returning from a Keyguard request, try to show an account confirmation request if
149 // applciable.
150 if (CREDENTIAL_CONFIRM_REQUEST != requestCode
151 && (intent = getAccountConfirmationIntent()) != null) {
152 showAccountCredentialConfirmation(intent);
153 } else {
154 showFinalConfirmation();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800155 }
156 }
157
qingxi072f2862017-04-11 18:28:40 -0700158 @VisibleForTesting
159 void showFinalConfirmation() {
Fan Zhang7cf99f52018-02-16 10:37:37 -0800160 final Bundle args = new Bundle();
Stuart Scottbe903412014-07-24 19:22:06 -0700161 args.putBoolean(ERASE_EXTERNAL_EXTRA, mExternalStorage.isChecked());
Qingxi Lic8a2b042018-01-11 11:35:07 -0800162 args.putBoolean(ERASE_ESIMS_EXTRA, mEsimStorage.isChecked());
Fan Zhang7cf99f52018-02-16 10:37:37 -0800163 new SubSettingLauncher(getContext())
164 .setDestination(MasterClearConfirm.class.getName())
165 .setArguments(args)
166 .setTitle(R.string.master_clear_confirm_title)
167 .setSourceMetricsCategory(getMetricsCategory())
168 .launch();
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700169 }
170
Carlos Valdiviaa9736ed2018-01-16 13:59:31 -0800171 @VisibleForTesting
Carlos Valdivia4b34dad2018-01-29 18:30:33 -0800172 void showAccountCredentialConfirmation(Intent intent) {
173 startActivityForResult(intent, CREDENTIAL_CONFIRM_REQUEST);
174 }
175
176 @VisibleForTesting
177 Intent getAccountConfirmationIntent() {
Carlos Valdiviaa9736ed2018-01-16 13:59:31 -0800178 final Context context = getActivity();
179 final String accountType = context.getString(R.string.account_type);
180 final String packageName = context.getString(R.string.account_confirmation_package);
Carlos Valdivia51146042018-01-23 17:17:56 -0800181 final String className = context.getString(R.string.account_confirmation_class);
182 if (TextUtils.isEmpty(accountType)
183 || TextUtils.isEmpty(packageName)
184 || TextUtils.isEmpty(className)) {
Carlos Valdivia4b34dad2018-01-29 18:30:33 -0800185 Log.i(TAG, "Resources not set for account confirmation.");
186 return null;
Carlos Valdiviaa9736ed2018-01-16 13:59:31 -0800187 }
188 final AccountManager am = AccountManager.get(context);
189 Account[] accounts = am.getAccountsByType(accountType);
190 if (accounts != null && accounts.length > 0) {
191 final Intent requestAccountConfirmation = new Intent()
192 .setPackage(packageName)
Carlos Valdivia51146042018-01-23 17:17:56 -0800193 .setComponent(new ComponentName(packageName, className));
Carlos Valdiviaa9736ed2018-01-16 13:59:31 -0800194 // Check to make sure that the intent is supported.
195 final PackageManager pm = context.getPackageManager();
Carlos Valdivia08c88202018-01-21 18:57:28 -0800196 final ResolveInfo resolution = pm.resolveActivity(requestAccountConfirmation, 0);
197 if (resolution != null
198 && resolution.activityInfo != null
199 && packageName.equals(resolution.activityInfo.packageName)) {
200 // Note that we need to check the packagename to make sure that an Activity resolver
201 // wasn't returned.
Carlos Valdivia4b34dad2018-01-29 18:30:33 -0800202 return requestAccountConfirmation;
203 } else {
204 Log.i(TAG, "Unable to resolve Activity: " + packageName + "/" + className);
Carlos Valdiviaa9736ed2018-01-16 13:59:31 -0800205 }
Carlos Valdivia4b34dad2018-01-29 18:30:33 -0800206 } else {
207 Log.d(TAG, "No " + accountType + " accounts installed!");
Carlos Valdiviaa9736ed2018-01-16 13:59:31 -0800208 }
Carlos Valdivia4b34dad2018-01-29 18:30:33 -0800209 return null;
Carlos Valdiviaa9736ed2018-01-16 13:59:31 -0800210 }
211
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800212 /**
213 * If the user clicks to begin the reset sequence, we next require a
214 * keyguard confirmation if the user has currently enabled one. If there
215 * is no keyguard available, we simply go to the final confirmation prompt.
Christine Franksa09eb382017-06-23 14:28:21 -0700216 *
217 * 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 -0800218 */
Christine Franksa09eb382017-06-23 14:28:21 -0700219 @VisibleForTesting
220 protected final Button.OnClickListener mInitiateListener = new Button.OnClickListener() {
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700221
Christine Franksa09eb382017-06-23 14:28:21 -0700222 public void onClick(View view) {
223 final Context context = view.getContext();
224 if (Utils.isDemoUser(context)) {
Justin Klaassen30257272017-08-08 21:58:05 -0700225 final ComponentName componentName = Utils.getDeviceOwnerComponent(context);
226 if (componentName != null) {
Christine Franksa09eb382017-06-23 14:28:21 -0700227 final Intent requestFactoryReset = new Intent()
Justin Klaassen30257272017-08-08 21:58:05 -0700228 .setPackage(componentName.getPackageName())
Christine Franksa09eb382017-06-23 14:28:21 -0700229 .setAction(Intent.ACTION_FACTORY_RESET);
230 context.startActivity(requestFactoryReset);
Christine Franksd7713c92017-01-20 11:24:14 -0800231 }
Carlos Valdiviaa9736ed2018-01-16 13:59:31 -0800232 return;
233 }
234
Carlos Valdivia4b34dad2018-01-29 18:30:33 -0800235 if (runKeyguardConfirmation(KEYGUARD_REQUEST)) {
236 return;
237 }
238
239 Intent intent = getAccountConfirmationIntent();
240 if (intent != null) {
241 showAccountCredentialConfirmation(intent);
242 } else {
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700243 showFinalConfirmation();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800244 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800245 }
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700246 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800247
248 /**
249 * In its initial state, the activity presents a button for the user to
250 * click in order to initiate a confirmation sequence. This method is
251 * called from various other points in the code to reset the activity to
252 * this base state.
Jim Miller47d380f2010-01-20 13:37:14 -0800253 *
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800254 * <p>Reinflating views from resources is expensive and prevents us from
255 * caching widget pointers, so we use a single-inflate pattern: we lazy-
256 * inflate each view, caching all of the widget pointers we'll need at the
257 * time, then simply reuse the inflated views directly whenever we need
258 * to change contents.
259 */
Carlos Valdivia4b34dad2018-01-29 18:30:33 -0800260 @VisibleForTesting
261 void establishInitialState() {
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700262 mInitiateButton = (Button) mContentView.findViewById(R.id.initiate_master_clear);
263 mInitiateButton.setOnClickListener(mInitiateListener);
264 mExternalStorageContainer = mContentView.findViewById(R.id.erase_external_container);
265 mExternalStorage = (CheckBox) mContentView.findViewById(R.id.erase_external);
Qingxi Lic8a2b042018-01-11 11:35:07 -0800266 mEsimStorageContainer = mContentView.findViewById(R.id.erase_esim_container);
267 mEsimStorage = (CheckBox) mContentView.findViewById(R.id.erase_esim);
jackqdyulei0b3edc72016-12-13 17:07:08 -0800268 mScrollView = (ScrollView) mContentView.findViewById(R.id.master_clear_scrollview);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800269
Kenny Root3785e392011-01-18 15:14:32 -0800270 /*
271 * If the external storage is emulated, it will be erased with a factory
272 * reset at any rate. There is no need to have a separate option until
273 * we have a factory reset that only erases some directories and not
Ben Komalo2a321922011-09-07 16:42:34 -0700274 * others. Likewise, if it's non-removable storage, it could potentially have been
275 * encrypted, and will also need to be wiped.
Kenny Root3785e392011-01-18 15:14:32 -0800276 */
Ben Komalo2a321922011-09-07 16:42:34 -0700277 boolean isExtStorageEmulated = Environment.isExternalStorageEmulated();
278 if (isExtStorageEmulated
279 || (!Environment.isExternalStorageRemovable() && isExtStorageEncrypted())) {
Kenny Root3785e392011-01-18 15:14:32 -0800280 mExternalStorageContainer.setVisibility(View.GONE);
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700281
Kenny Root3785e392011-01-18 15:14:32 -0800282 final View externalOption = mContentView.findViewById(R.id.erase_external_option_text);
283 externalOption.setVisibility(View.GONE);
284
285 final View externalAlsoErased = mContentView.findViewById(R.id.also_erases_external);
286 externalAlsoErased.setVisibility(View.VISIBLE);
Ben Komalo2a321922011-09-07 16:42:34 -0700287
288 // If it's not emulated, it is on a separate partition but it means we're doing
289 // a force wipe due to encryption.
290 mExternalStorage.setChecked(!isExtStorageEmulated);
Kenny Root3785e392011-01-18 15:14:32 -0800291 } else {
292 mExternalStorageContainer.setOnClickListener(new View.OnClickListener() {
293
294 @Override
295 public void onClick(View v) {
296 mExternalStorage.toggle();
297 }
298 });
299 }
Joe Onoratob51886d2010-11-08 18:25:51 -0800300
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -0700301 if (showWipeEuicc()) {
Qingxi Lic8a2b042018-01-11 11:35:07 -0800302 if (showWipeEuiccCheckbox()) {
303 TextView title = mContentView.findViewById(R.id.erase_esim_title);
304 title.setText(R.string.erase_esim_storage);
305 mEsimStorageContainer.setVisibility(View.VISIBLE);
306 mEsimStorageContainer.setOnClickListener(new View.OnClickListener() {
307 @Override
308 public void onClick(View v) {
309 mEsimStorage.toggle();
310 }
311 });
312 } else {
313 final View esimAlsoErased = mContentView.findViewById(R.id.also_erases_esim);
314 esimAlsoErased.setVisibility(View.VISIBLE);
qingxi072f2862017-04-11 18:28:40 -0700315
Qingxi Lic8a2b042018-01-11 11:35:07 -0800316 final View noCancelMobilePlan = mContentView.findViewById(
317 R.id.no_cancel_mobile_plan);
318 noCancelMobilePlan.setVisibility(View.VISIBLE);
319 mEsimStorage.setChecked(true /* checked */);
320 }
qingxi072f2862017-04-11 18:28:40 -0700321 }
322
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100323 final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
324 loadAccountList(um);
Julia Reynoldsce25af42015-07-08 16:56:31 -0400325 StringBuffer contentDescription = new StringBuffer();
326 View masterClearContainer = mContentView.findViewById(R.id.master_clear_container);
327 getContentDescription(masterClearContainer, contentDescription);
328 masterClearContainer.setContentDescription(contentDescription);
jackqdyulei0b3edc72016-12-13 17:07:08 -0800329
330 // Set the status of initiateButton based on scrollview
331 mScrollView.setOnScrollChangeListener(new OnScrollChangeListener() {
332 @Override
333 public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX,
334 int oldScrollY) {
335 if (v instanceof ScrollView && hasReachedBottom((ScrollView) v)) {
336 mInitiateButton.setEnabled(true);
337 }
338 }
339 });
340
341 // Set the initial state of the initiateButton
342 mScrollView.getViewTreeObserver().addOnGlobalLayoutListener(mOnGlobalLayoutListener);
343 }
344
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -0700345 /**
Jeff Davidsona0b84722017-07-26 17:38:41 -0700346 * Whether to show strings indicating that the eUICC will be wiped.
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -0700347 *
Jeff Davidsona0b84722017-07-26 17:38:41 -0700348 * <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 -0700349 * provisioned (that is, at least one profile was ever downloaded onto it).
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -0700350 */
351 @VisibleForTesting
352 boolean showWipeEuicc() {
353 Context context = getContext();
354 if (!isEuiccEnabled(context)) {
355 return false;
356 }
357 ContentResolver cr = context.getContentResolver();
Jeff Davidson4ba74782017-06-30 18:02:13 -0700358 return Settings.Global.getInt(cr, Settings.Global.EUICC_PROVISIONED, 0) != 0;
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -0700359 }
360
361 @VisibleForTesting
Qingxi Lic8a2b042018-01-11 11:35:07 -0800362 boolean showWipeEuiccCheckbox() {
363 return SystemProperties
364 .getBoolean(KEY_SHOW_ESIM_RESET_CHECKBOX, false /* def */);
365 }
366
367 @VisibleForTesting
Jeff Davidsonf1c13fa2017-05-19 17:03:32 -0700368 protected boolean isEuiccEnabled(Context context) {
369 EuiccManager euiccManager = (EuiccManager) context.getSystemService(Context.EUICC_SERVICE);
370 return euiccManager.isEnabled();
371 }
372
jackqdyulei0b3edc72016-12-13 17:07:08 -0800373 @VisibleForTesting
374 boolean hasReachedBottom(final ScrollView scrollView) {
375 if (scrollView.getChildCount() < 1) {
376 return true;
377 }
378
379 final View view = scrollView.getChildAt(0);
380 final int diff = view.getBottom() - (scrollView.getHeight() + scrollView.getScrollY());
381
382 return diff <= 0;
Julia Reynoldsce25af42015-07-08 16:56:31 -0400383 }
384
385 private void getContentDescription(View v, StringBuffer description) {
Jason Monkfda77412016-05-06 14:28:09 -0400386 if (v.getVisibility() != View.VISIBLE) {
387 return;
388 }
Julia Reynoldsce25af42015-07-08 16:56:31 -0400389 if (v instanceof ViewGroup) {
390 ViewGroup vGroup = (ViewGroup) v;
391 for (int i = 0; i < vGroup.getChildCount(); i++) {
392 View nextChild = vGroup.getChildAt(i);
393 getContentDescription(nextChild, description);
394 }
395 } else if (v instanceof TextView) {
396 TextView vText = (TextView) v;
397 description.append(vText.getText());
398 description.append(","); // Allow Talkback to pause between sections.
399 }
Joe Onoratob51886d2010-11-08 18:25:51 -0800400 }
401
Ben Komalo2a321922011-09-07 16:42:34 -0700402 private boolean isExtStorageEncrypted() {
403 String state = SystemProperties.get("vold.decrypt");
404 return !"".equals(state);
405 }
406
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100407 private void loadAccountList(final UserManager um) {
Joe Onoratob51886d2010-11-08 18:25:51 -0800408 View accountsLabel = mContentView.findViewById(R.id.accounts_label);
409 LinearLayout contents = (LinearLayout)mContentView.findViewById(R.id.accounts);
Amith Yamasani3f45de52011-09-22 14:34:17 -0700410 contents.removeAllViews();
Joe Onoratob51886d2010-11-08 18:25:51 -0800411
412 Context context = getActivity();
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100413 final List<UserInfo> profiles = um.getProfiles(UserHandle.myUserId());
414 final int profilesSize = profiles.size();
Joe Onoratob51886d2010-11-08 18:25:51 -0800415
416 AccountManager mgr = AccountManager.get(context);
Joe Onoratob51886d2010-11-08 18:25:51 -0800417
418 LayoutInflater inflater = (LayoutInflater)context.getSystemService(
419 Context.LAYOUT_INFLATER_SERVICE);
420
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100421 int accountsCount = 0;
422 for (int profileIndex = 0; profileIndex < profilesSize; profileIndex++) {
423 final UserInfo userInfo = profiles.get(profileIndex);
424 final int profileId = userInfo.id;
425 final UserHandle userHandle = new UserHandle(profileId);
426 Account[] accounts = mgr.getAccountsAsUser(profileId);
427 final int N = accounts.length;
428 if (N == 0) {
Joe Onoratob51886d2010-11-08 18:25:51 -0800429 continue;
430 }
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100431 accountsCount += N;
Joe Onoratob51886d2010-11-08 18:25:51 -0800432
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100433 AuthenticatorDescription[] descs = AccountManager.get(context)
434 .getAuthenticatorTypesAsUser(profileId);
435 final int M = descs.length;
436
Bartosz Fabianowski30ba8682017-04-19 11:51:43 +0200437 if (profilesSize > 1) {
438 View titleView = Utils.inflateCategoryHeader(inflater, contents);
439 final TextView titleText = (TextView) titleView.findViewById(android.R.id.title);
440 titleText.setText(userInfo.isManagedProfile() ? R.string.category_work
441 : R.string.category_personal);
442 contents.addView(titleView);
443 }
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100444
445 for (int i = 0; i < N; i++) {
446 Account account = accounts[i];
447 AuthenticatorDescription desc = null;
448 for (int j = 0; j < M; j++) {
449 if (account.type.equals(descs[j].type)) {
450 desc = descs[j];
451 break;
452 }
453 }
454 if (desc == null) {
455 Log.w(TAG, "No descriptor for account name=" + account.name
456 + " type=" + account.type);
457 continue;
458 }
459 Drawable icon = null;
460 try {
461 if (desc.iconId != 0) {
Zoltan Szatmary-Ban546790c2014-12-02 17:22:10 +0000462 Context authContext = context.createPackageContextAsUser(desc.packageName,
463 0, userHandle);
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100464 icon = context.getPackageManager().getUserBadgedIcon(
465 authContext.getDrawable(desc.iconId), userHandle);
466 }
467 } catch (PackageManager.NameNotFoundException e) {
Rubin Xud1ce82a2015-06-08 17:21:19 +0100468 Log.w(TAG, "Bad package name for account type " + desc.type);
469 } catch (Resources.NotFoundException e) {
470 Log.w(TAG, "Invalid icon id for account type " + desc.type, e);
471 }
472 if (icon == null) {
473 icon = context.getPackageManager().getDefaultActivityIcon();
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100474 }
475
Fan Zhang6b2bb392016-09-28 09:07:44 -0700476 View child = inflater.inflate(R.layout.master_clear_account, contents, false);
477 ((ImageView) child.findViewById(android.R.id.icon)).setImageDrawable(icon);
478 ((TextView) child.findViewById(android.R.id.title)).setText(account.name);
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100479 contents.addView(child);
Joe Onoratob51886d2010-11-08 18:25:51 -0800480 }
Joe Onoratob51886d2010-11-08 18:25:51 -0800481 }
482
Zoltan Szatmary-Ban7cc1b9e2014-10-24 18:03:18 +0100483 if (accountsCount > 0) {
484 accountsLabel.setVisibility(View.VISIBLE);
485 contents.setVisibility(View.VISIBLE);
486 }
487 // Checking for all other users and their profiles if any.
488 View otherUsers = mContentView.findViewById(R.id.other_users_present);
489 final boolean hasOtherUsers = (um.getUserCount() - profilesSize) > 0;
490 otherUsers.setVisibility(hasOtherUsers ? View.VISIBLE : View.GONE);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800491 }
492
493 @Override
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700494 public View onCreateView(LayoutInflater inflater, ViewGroup container,
495 Bundle savedInstanceState) {
Christine Franks14782222017-01-23 16:44:02 -0800496 final Context context = getContext();
497 final EnforcedAdmin admin = RestrictedLockUtils.checkIfRestrictionEnforced(context,
498 UserManager.DISALLOW_FACTORY_RESET, UserHandle.myUserId());
499 final UserManager um = UserManager.get(context);
500 final boolean disallow = !um.isAdminUser() || RestrictedLockUtils.hasBaseUserRestriction(
501 context, UserManager.DISALLOW_FACTORY_RESET, UserHandle.myUserId());
Christine Franksa09eb382017-06-23 14:28:21 -0700502 if (disallow && !Utils.isDemoUser(context)) {
Julia Reynolds2c539332014-06-11 12:56:02 -0400503 return inflater.inflate(R.layout.master_clear_disallowed_screen, null);
Sudheer Shanka7dbbe132016-02-16 14:19:32 +0000504 } else if (admin != null) {
505 View view = inflater.inflate(R.layout.admin_support_details_empty_view, null);
506 ShowAdminSupportDetailsDialog.setAdminSupportDetails(getActivity(), view, admin, false);
507 view.setVisibility(View.VISIBLE);
508 return view;
Julia Reynolds2c539332014-06-11 12:56:02 -0400509 }
510
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700511 mContentView = inflater.inflate(R.layout.master_clear, null);
Joe Onoratob51886d2010-11-08 18:25:51 -0800512
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800513 establishInitialState();
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700514 return mContentView;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800515 }
Chris Wren8a963ba2015-03-20 10:29:14 -0400516
517 @Override
Fan Zhang65076132016-08-08 10:25:13 -0700518 public int getMetricsCategory() {
Chris Wren9d1bfd12016-01-26 18:04:01 -0500519 return MetricsEvent.MASTER_CLEAR;
Chris Wren8a963ba2015-03-20 10:29:14 -0400520 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800521}