The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.settings; |
| 18 | |
Jonathan Scott | e0d4394 | 2022-01-19 15:19:08 +0000 | [diff] [blame] | 19 | import static android.app.admin.DevicePolicyResources.Strings.Settings.PERSONAL_CATEGORY_HEADER; |
| 20 | import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_CATEGORY_HEADER; |
| 21 | |
Maurice Lam | 2eb170c | 2017-04-28 16:18:47 -0700 | [diff] [blame] | 22 | import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; |
| 23 | |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 24 | import android.accounts.Account; |
| 25 | import android.accounts.AccountManager; |
| 26 | import android.accounts.AuthenticatorDescription; |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 27 | import android.app.ActionBar; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 28 | import android.app.Activity; |
Jonathan Scott | e0d4394 | 2022-01-19 15:19:08 +0000 | [diff] [blame] | 29 | import android.app.admin.DevicePolicyManager; |
Fan Zhang | 31b2100 | 2019-01-16 13:49:47 -0800 | [diff] [blame] | 30 | import android.app.settings.SettingsEnums; |
Christine Franks | a09eb38 | 2017-06-23 14:28:21 -0700 | [diff] [blame] | 31 | import android.content.ComponentName; |
Jeff Davidson | f1c13fa | 2017-05-19 17:03:32 -0700 | [diff] [blame] | 32 | import android.content.ContentResolver; |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 33 | import android.content.Context; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 34 | import android.content.Intent; |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 35 | import android.content.pm.PackageManager; |
Carlos Valdivia | a9736ed | 2018-01-16 13:59:31 -0800 | [diff] [blame] | 36 | import android.content.pm.ResolveInfo; |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 37 | import android.content.pm.UserInfo; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 38 | import android.content.res.Resources; |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 39 | import android.graphics.Color; |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 40 | import android.graphics.drawable.Drawable; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 41 | import android.os.Bundle; |
Kenny Root | 3785e39 | 2011-01-18 15:14:32 -0800 | [diff] [blame] | 42 | import android.os.Environment; |
Ben Komalo | 2a32192 | 2011-09-07 16:42:34 -0700 | [diff] [blame] | 43 | import android.os.SystemProperties; |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 44 | import android.os.UserHandle; |
Amith Yamasani | 7eedcf4 | 2013-07-02 14:15:29 -0700 | [diff] [blame] | 45 | import android.os.UserManager; |
Jeff Davidson | f1c13fa | 2017-05-19 17:03:32 -0700 | [diff] [blame] | 46 | import android.provider.Settings; |
qingxi | 072f286 | 2017-04-11 18:28:40 -0700 | [diff] [blame] | 47 | import android.telephony.euicc.EuiccManager; |
Carlos Valdivia | a9736ed | 2018-01-16 13:59:31 -0800 | [diff] [blame] | 48 | import android.text.TextUtils; |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 49 | import android.util.Log; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 50 | import android.view.LayoutInflater; |
| 51 | import android.view.View; |
jackqdyulei | 0b3edc7 | 2016-12-13 17:07:08 -0800 | [diff] [blame] | 52 | import android.view.View.OnScrollChangeListener; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 53 | import android.view.ViewGroup; |
jackqdyulei | 0b3edc7 | 2016-12-13 17:07:08 -0800 | [diff] [blame] | 54 | import android.view.ViewTreeObserver.OnGlobalLayoutListener; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 55 | import android.widget.Button; |
Dianne Hackborn | 1337d0f | 2010-10-14 11:58:30 -0700 | [diff] [blame] | 56 | import android.widget.CheckBox; |
Fan Zhang | 6b2bb39 | 2016-09-28 09:07:44 -0700 | [diff] [blame] | 57 | import android.widget.ImageView; |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 58 | import android.widget.LinearLayout; |
jackqdyulei | 0b3edc7 | 2016-12-13 17:07:08 -0800 | [diff] [blame] | 59 | import android.widget.ScrollView; |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 60 | import android.widget.TextView; |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 61 | |
Fan Zhang | 23f8d59 | 2018-08-28 15:11:40 -0700 | [diff] [blame] | 62 | import androidx.annotation.VisibleForTesting; |
| 63 | |
Doris Ling | 7248972 | 2017-11-16 11:03:40 -0800 | [diff] [blame] | 64 | import com.android.settings.core.InstrumentedFragment; |
arangelov | e35badd | 2017-10-27 13:51:28 +0100 | [diff] [blame] | 65 | import com.android.settings.enterprise.ActionDisabledByAdminDialogHelper; |
Maurice Lam | 2eb170c | 2017-04-28 16:18:47 -0700 | [diff] [blame] | 66 | import com.android.settings.password.ChooseLockSettingsHelper; |
| 67 | import com.android.settings.password.ConfirmLockPattern; |
Philip P. Moltmann | e3f7211 | 2018-08-28 15:01:43 -0700 | [diff] [blame] | 68 | import com.android.settingslib.RestrictedLockUtilsInternal; |
Mill Chen | 1e60790 | 2021-02-25 15:03:25 +0800 | [diff] [blame] | 69 | import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; |
Taesu Lee | 39e4fbb | 2019-07-22 19:20:05 +0900 | [diff] [blame] | 70 | import com.android.settingslib.development.DevelopmentSettingsEnabler; |
Pasty Chang | c1f8600 | 2018-12-11 02:22:55 +0000 | [diff] [blame] | 71 | |
pastychang | 9bdb59a | 2019-01-21 09:49:15 +0800 | [diff] [blame] | 72 | import com.google.android.setupcompat.template.FooterBarMixin; |
| 73 | import com.google.android.setupcompat.template.FooterButton; |
| 74 | import com.google.android.setupcompat.template.FooterButton.ButtonType; |
Maurice Lam | 59f1c1a | 2019-02-14 22:04:30 +0000 | [diff] [blame] | 75 | import com.google.android.setupdesign.GlifLayout; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 76 | |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 77 | import java.util.List; |
| 78 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 79 | /** |
| 80 | * Confirm and execute a reset of the device to a clean "just out of the box" |
| 81 | * state. Multiple confirmations are required: first, a general "are you sure |
| 82 | * you want to do this?" prompt, followed by a keyguard pattern trace if the user |
| 83 | * has defined one, followed by a final strongly-worded "THIS WILL ERASE EVERYTHING |
| 84 | * ON THE PHONE" prompt. If at any time the phone is allowed to go to sleep, is |
| 85 | * locked, et cetera, then the confirmation sequence is abandoned. |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 86 | * |
| 87 | * This is the initial screen. |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 88 | */ |
Edgar Wang | 21f8cb3 | 2020-08-04 23:13:05 +0800 | [diff] [blame] | 89 | public class MainClear extends InstrumentedFragment implements OnGlobalLayoutListener { |
| 90 | private static final String TAG = "MainClear"; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 91 | |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 92 | @VisibleForTesting |
| 93 | static final int KEYGUARD_REQUEST = 55; |
| 94 | @VisibleForTesting |
| 95 | static final int CREDENTIAL_CONFIRM_REQUEST = 56; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 96 | |
Edgar Wang | 21f8cb3 | 2020-08-04 23:13:05 +0800 | [diff] [blame] | 97 | private static final String KEY_SHOW_ESIM_RESET_CHECKBOX = |
| 98 | "masterclear.allow_retain_esim_profiles_after_fdr"; |
Qingxi Li | c8a2b04 | 2018-01-11 11:35:07 -0800 | [diff] [blame] | 99 | |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 100 | static final String ERASE_EXTERNAL_EXTRA = "erase_sd"; |
qingxi | 072f286 | 2017-04-11 18:28:40 -0700 | [diff] [blame] | 101 | static final String ERASE_ESIMS_EXTRA = "erase_esim"; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 102 | |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 103 | private View mContentView; |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 104 | @VisibleForTesting |
pastychang | 103409b | 2018-12-13 23:00:17 +0800 | [diff] [blame] | 105 | FooterButton mInitiateButton; |
Dianne Hackborn | 1337d0f | 2010-10-14 11:58:30 -0700 | [diff] [blame] | 106 | private View mExternalStorageContainer; |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 107 | @VisibleForTesting |
| 108 | CheckBox mExternalStorage; |
Andrew Sapperstein | 88930e3 | 2019-03-07 14:18:15 -0800 | [diff] [blame] | 109 | @VisibleForTesting |
| 110 | View mEsimStorageContainer; |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 111 | @VisibleForTesting |
| 112 | CheckBox mEsimStorage; |
| 113 | @VisibleForTesting |
| 114 | ScrollView mScrollView; |
jackqdyulei | 0b3edc7 | 2016-12-13 17:07:08 -0800 | [diff] [blame] | 115 | |
Doris Ling | 1f49715 | 2018-02-22 16:33:07 -0800 | [diff] [blame] | 116 | @Override |
| 117 | public void onGlobalLayout() { |
| 118 | mInitiateButton.setEnabled(hasReachedBottom(mScrollView)); |
| 119 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 120 | |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 121 | private void setUpActionBarAndTitle() { |
| 122 | final Activity activity = getActivity(); |
| 123 | if (activity == null) { |
| 124 | Log.e(TAG, "No activity attached, skipping setUpActionBarAndTitle"); |
| 125 | return; |
| 126 | } |
| 127 | final ActionBar actionBar = activity.getActionBar(); |
| 128 | if (actionBar == null) { |
| 129 | Log.e(TAG, "No actionbar, skipping setUpActionBarAndTitle"); |
| 130 | return; |
| 131 | } |
| 132 | actionBar.hide(); |
| 133 | activity.getWindow().setStatusBarColor(Color.TRANSPARENT); |
Doris Ling | 03a3b51 | 2017-10-18 14:25:01 -0700 | [diff] [blame] | 134 | } |
| 135 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 136 | /** |
Jim Miller | 2deec7e | 2010-04-13 17:43:36 -0700 | [diff] [blame] | 137 | * Keyguard validation is run using the standard {@link ConfirmLockPattern} |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 138 | * component as a subactivity |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 139 | * |
Jim Miller | 2deec7e | 2010-04-13 17:43:36 -0700 | [diff] [blame] | 140 | * @param request the request code to be returned once confirmation finishes |
| 141 | * @return true if confirmation launched |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 142 | */ |
Jim Miller | 2deec7e | 2010-04-13 17:43:36 -0700 | [diff] [blame] | 143 | private boolean runKeyguardConfirmation(int request) { |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 144 | Resources res = getActivity().getResources(); |
Kevin Chyn | b13bc50 | 2020-07-20 23:35:21 -0700 | [diff] [blame] | 145 | final ChooseLockSettingsHelper.Builder builder = |
| 146 | new ChooseLockSettingsHelper.Builder(getActivity(), this); |
| 147 | return builder.setRequestCode(request) |
Edgar Wang | 21f8cb3 | 2020-08-04 23:13:05 +0800 | [diff] [blame] | 148 | .setTitle(res.getText(R.string.main_clear_short_title)) |
Kevin Chyn | b13bc50 | 2020-07-20 23:35:21 -0700 | [diff] [blame] | 149 | .show(); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 150 | } |
| 151 | |
Carlos Valdivia | 5dd6ed4 | 2018-01-23 09:12:59 -0800 | [diff] [blame] | 152 | @VisibleForTesting |
| 153 | boolean isValidRequestCode(int requestCode) { |
| 154 | return !((requestCode != KEYGUARD_REQUEST) && (requestCode != CREDENTIAL_CONFIRM_REQUEST)); |
| 155 | } |
| 156 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 157 | @Override |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 158 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 159 | super.onActivityResult(requestCode, resultCode, data); |
Carlos Valdivia | 4b34dad | 2018-01-29 18:30:33 -0800 | [diff] [blame] | 160 | onActivityResultInternal(requestCode, resultCode, data); |
| 161 | } |
| 162 | |
| 163 | /* |
| 164 | * Internal method that allows easy testing without dealing with super references. |
| 165 | */ |
| 166 | @VisibleForTesting |
| 167 | void onActivityResultInternal(int requestCode, int resultCode, Intent data) { |
Carlos Valdivia | 5dd6ed4 | 2018-01-23 09:12:59 -0800 | [diff] [blame] | 168 | if (!isValidRequestCode(requestCode)) { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 169 | return; |
| 170 | } |
| 171 | |
Carlos Valdivia | 4b34dad | 2018-01-29 18:30:33 -0800 | [diff] [blame] | 172 | if (resultCode != Activity.RESULT_OK) { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 173 | establishInitialState(); |
Carlos Valdivia | 4b34dad | 2018-01-29 18:30:33 -0800 | [diff] [blame] | 174 | return; |
| 175 | } |
| 176 | |
| 177 | Intent intent = null; |
| 178 | // If returning from a Keyguard request, try to show an account confirmation request if |
| 179 | // applciable. |
| 180 | if (CREDENTIAL_CONFIRM_REQUEST != requestCode |
| 181 | && (intent = getAccountConfirmationIntent()) != null) { |
| 182 | showAccountCredentialConfirmation(intent); |
| 183 | } else { |
| 184 | showFinalConfirmation(); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 185 | } |
| 186 | } |
| 187 | |
qingxi | 072f286 | 2017-04-11 18:28:40 -0700 | [diff] [blame] | 188 | @VisibleForTesting |
| 189 | void showFinalConfirmation() { |
Fan Zhang | 7cf99f5 | 2018-02-16 10:37:37 -0800 | [diff] [blame] | 190 | final Bundle args = new Bundle(); |
Stuart Scott | be90341 | 2014-07-24 19:22:06 -0700 | [diff] [blame] | 191 | args.putBoolean(ERASE_EXTERNAL_EXTRA, mExternalStorage.isChecked()); |
Antony Sargent | 8d2baf6 | 2019-07-11 11:04:09 -0700 | [diff] [blame] | 192 | args.putBoolean(ERASE_ESIMS_EXTRA, mEsimStorage.isChecked()); |
Mill Chen | 1e60790 | 2021-02-25 15:03:25 +0800 | [diff] [blame] | 193 | final Intent intent = new Intent(); |
| 194 | intent.setClass(getContext(), |
| 195 | com.android.settings.Settings.FactoryResetConfirmActivity.class); |
| 196 | intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT, MainClearConfirm.class.getName()); |
| 197 | intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, args); |
| 198 | intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RESID, |
| 199 | R.string.main_clear_confirm_title); |
| 200 | intent.putExtra(MetricsFeatureProvider.EXTRA_SOURCE_METRICS_CATEGORY, getMetricsCategory()); |
| 201 | getContext().startActivity(intent); |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Carlos Valdivia | a9736ed | 2018-01-16 13:59:31 -0800 | [diff] [blame] | 204 | @VisibleForTesting |
Carlos Valdivia | 4b34dad | 2018-01-29 18:30:33 -0800 | [diff] [blame] | 205 | void showAccountCredentialConfirmation(Intent intent) { |
| 206 | startActivityForResult(intent, CREDENTIAL_CONFIRM_REQUEST); |
| 207 | } |
| 208 | |
| 209 | @VisibleForTesting |
| 210 | Intent getAccountConfirmationIntent() { |
Carlos Valdivia | a9736ed | 2018-01-16 13:59:31 -0800 | [diff] [blame] | 211 | final Context context = getActivity(); |
| 212 | final String accountType = context.getString(R.string.account_type); |
| 213 | final String packageName = context.getString(R.string.account_confirmation_package); |
Carlos Valdivia | 5114604 | 2018-01-23 17:17:56 -0800 | [diff] [blame] | 214 | final String className = context.getString(R.string.account_confirmation_class); |
| 215 | if (TextUtils.isEmpty(accountType) |
| 216 | || TextUtils.isEmpty(packageName) |
| 217 | || TextUtils.isEmpty(className)) { |
Carlos Valdivia | 4b34dad | 2018-01-29 18:30:33 -0800 | [diff] [blame] | 218 | Log.i(TAG, "Resources not set for account confirmation."); |
| 219 | return null; |
Carlos Valdivia | a9736ed | 2018-01-16 13:59:31 -0800 | [diff] [blame] | 220 | } |
| 221 | final AccountManager am = AccountManager.get(context); |
| 222 | Account[] accounts = am.getAccountsByType(accountType); |
| 223 | if (accounts != null && accounts.length > 0) { |
| 224 | final Intent requestAccountConfirmation = new Intent() |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 225 | .setPackage(packageName) |
| 226 | .setComponent(new ComponentName(packageName, className)); |
Carlos Valdivia | a9736ed | 2018-01-16 13:59:31 -0800 | [diff] [blame] | 227 | // Check to make sure that the intent is supported. |
| 228 | final PackageManager pm = context.getPackageManager(); |
Carlos Valdivia | 08c8820 | 2018-01-21 18:57:28 -0800 | [diff] [blame] | 229 | final ResolveInfo resolution = pm.resolveActivity(requestAccountConfirmation, 0); |
| 230 | if (resolution != null |
| 231 | && resolution.activityInfo != null |
| 232 | && packageName.equals(resolution.activityInfo.packageName)) { |
| 233 | // Note that we need to check the packagename to make sure that an Activity resolver |
| 234 | // wasn't returned. |
Carlos Valdivia | 4b34dad | 2018-01-29 18:30:33 -0800 | [diff] [blame] | 235 | return requestAccountConfirmation; |
| 236 | } else { |
| 237 | Log.i(TAG, "Unable to resolve Activity: " + packageName + "/" + className); |
Carlos Valdivia | a9736ed | 2018-01-16 13:59:31 -0800 | [diff] [blame] | 238 | } |
Carlos Valdivia | 4b34dad | 2018-01-29 18:30:33 -0800 | [diff] [blame] | 239 | } else { |
| 240 | Log.d(TAG, "No " + accountType + " accounts installed!"); |
Carlos Valdivia | a9736ed | 2018-01-16 13:59:31 -0800 | [diff] [blame] | 241 | } |
Carlos Valdivia | 4b34dad | 2018-01-29 18:30:33 -0800 | [diff] [blame] | 242 | return null; |
Carlos Valdivia | a9736ed | 2018-01-16 13:59:31 -0800 | [diff] [blame] | 243 | } |
| 244 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 245 | /** |
| 246 | * If the user clicks to begin the reset sequence, we next require a |
| 247 | * keyguard confirmation if the user has currently enabled one. If there |
| 248 | * is no keyguard available, we simply go to the final confirmation prompt. |
Christine Franks | a09eb38 | 2017-06-23 14:28:21 -0700 | [diff] [blame] | 249 | * |
| 250 | * If the user is in demo mode, route to the demo mode app for confirmation. |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 251 | */ |
Christine Franks | a09eb38 | 2017-06-23 14:28:21 -0700 | [diff] [blame] | 252 | @VisibleForTesting |
| 253 | protected final Button.OnClickListener mInitiateListener = new Button.OnClickListener() { |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 254 | |
Christine Franks | a09eb38 | 2017-06-23 14:28:21 -0700 | [diff] [blame] | 255 | public void onClick(View view) { |
| 256 | final Context context = view.getContext(); |
| 257 | if (Utils.isDemoUser(context)) { |
Justin Klaassen | 3025727 | 2017-08-08 21:58:05 -0700 | [diff] [blame] | 258 | final ComponentName componentName = Utils.getDeviceOwnerComponent(context); |
| 259 | if (componentName != null) { |
Christine Franks | a09eb38 | 2017-06-23 14:28:21 -0700 | [diff] [blame] | 260 | final Intent requestFactoryReset = new Intent() |
Justin Klaassen | 3025727 | 2017-08-08 21:58:05 -0700 | [diff] [blame] | 261 | .setPackage(componentName.getPackageName()) |
Christine Franks | a09eb38 | 2017-06-23 14:28:21 -0700 | [diff] [blame] | 262 | .setAction(Intent.ACTION_FACTORY_RESET); |
| 263 | context.startActivity(requestFactoryReset); |
Christine Franks | d7713c9 | 2017-01-20 11:24:14 -0800 | [diff] [blame] | 264 | } |
Carlos Valdivia | a9736ed | 2018-01-16 13:59:31 -0800 | [diff] [blame] | 265 | return; |
| 266 | } |
| 267 | |
Carlos Valdivia | 4b34dad | 2018-01-29 18:30:33 -0800 | [diff] [blame] | 268 | if (runKeyguardConfirmation(KEYGUARD_REQUEST)) { |
| 269 | return; |
| 270 | } |
| 271 | |
| 272 | Intent intent = getAccountConfirmationIntent(); |
| 273 | if (intent != null) { |
| 274 | showAccountCredentialConfirmation(intent); |
| 275 | } else { |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 276 | showFinalConfirmation(); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 277 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 278 | } |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 279 | }; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 280 | |
| 281 | /** |
| 282 | * In its initial state, the activity presents a button for the user to |
| 283 | * click in order to initiate a confirmation sequence. This method is |
| 284 | * called from various other points in the code to reset the activity to |
| 285 | * this base state. |
Jim Miller | 47d380f | 2010-01-20 13:37:14 -0800 | [diff] [blame] | 286 | * |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 287 | * <p>Reinflating views from resources is expensive and prevents us from |
| 288 | * caching widget pointers, so we use a single-inflate pattern: we lazy- |
| 289 | * inflate each view, caching all of the widget pointers we'll need at the |
| 290 | * time, then simply reuse the inflated views directly whenever we need |
| 291 | * to change contents. |
| 292 | */ |
Carlos Valdivia | 4b34dad | 2018-01-29 18:30:33 -0800 | [diff] [blame] | 293 | @VisibleForTesting |
| 294 | void establishInitialState() { |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 295 | setUpActionBarAndTitle(); |
| 296 | setUpInitiateButton(); |
| 297 | |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 298 | mExternalStorageContainer = mContentView.findViewById(R.id.erase_external_container); |
Doris Ling | 1f49715 | 2018-02-22 16:33:07 -0800 | [diff] [blame] | 299 | mExternalStorage = mContentView.findViewById(R.id.erase_external); |
Qingxi Li | c8a2b04 | 2018-01-11 11:35:07 -0800 | [diff] [blame] | 300 | mEsimStorageContainer = mContentView.findViewById(R.id.erase_esim_container); |
Doris Ling | 1f49715 | 2018-02-22 16:33:07 -0800 | [diff] [blame] | 301 | mEsimStorage = mContentView.findViewById(R.id.erase_esim); |
| 302 | if (mScrollView != null) { |
| 303 | mScrollView.getViewTreeObserver().removeOnGlobalLayoutListener(this); |
| 304 | } |
Edgar Wang | 21f8cb3 | 2020-08-04 23:13:05 +0800 | [diff] [blame] | 305 | mScrollView = mContentView.findViewById(R.id.main_clear_scrollview); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 306 | |
Kenny Root | 3785e39 | 2011-01-18 15:14:32 -0800 | [diff] [blame] | 307 | /* |
| 308 | * If the external storage is emulated, it will be erased with a factory |
| 309 | * reset at any rate. There is no need to have a separate option until |
| 310 | * we have a factory reset that only erases some directories and not |
Eric Biggers | 8c25415 | 2022-04-25 21:27:03 +0000 | [diff] [blame] | 311 | * others. |
Kenny Root | 3785e39 | 2011-01-18 15:14:32 -0800 | [diff] [blame] | 312 | */ |
Eric Biggers | 8c25415 | 2022-04-25 21:27:03 +0000 | [diff] [blame] | 313 | if (Environment.isExternalStorageEmulated()) { |
Kenny Root | 3785e39 | 2011-01-18 15:14:32 -0800 | [diff] [blame] | 314 | mExternalStorageContainer.setVisibility(View.GONE); |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 315 | |
Kenny Root | 3785e39 | 2011-01-18 15:14:32 -0800 | [diff] [blame] | 316 | final View externalOption = mContentView.findViewById(R.id.erase_external_option_text); |
| 317 | externalOption.setVisibility(View.GONE); |
| 318 | |
| 319 | final View externalAlsoErased = mContentView.findViewById(R.id.also_erases_external); |
| 320 | externalAlsoErased.setVisibility(View.VISIBLE); |
Ben Komalo | 2a32192 | 2011-09-07 16:42:34 -0700 | [diff] [blame] | 321 | |
Eric Biggers | 8c25415 | 2022-04-25 21:27:03 +0000 | [diff] [blame] | 322 | mExternalStorage.setChecked(false); |
Kenny Root | 3785e39 | 2011-01-18 15:14:32 -0800 | [diff] [blame] | 323 | } else { |
| 324 | mExternalStorageContainer.setOnClickListener(new View.OnClickListener() { |
| 325 | |
| 326 | @Override |
| 327 | public void onClick(View v) { |
| 328 | mExternalStorage.toggle(); |
| 329 | } |
| 330 | }); |
| 331 | } |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 332 | |
Jeff Davidson | f1c13fa | 2017-05-19 17:03:32 -0700 | [diff] [blame] | 333 | if (showWipeEuicc()) { |
Qingxi Li | c8a2b04 | 2018-01-11 11:35:07 -0800 | [diff] [blame] | 334 | if (showWipeEuiccCheckbox()) { |
Qingxi Li | c8a2b04 | 2018-01-11 11:35:07 -0800 | [diff] [blame] | 335 | mEsimStorageContainer.setVisibility(View.VISIBLE); |
| 336 | mEsimStorageContainer.setOnClickListener(new View.OnClickListener() { |
| 337 | @Override |
| 338 | public void onClick(View v) { |
| 339 | mEsimStorage.toggle(); |
| 340 | } |
| 341 | }); |
| 342 | } else { |
| 343 | final View esimAlsoErased = mContentView.findViewById(R.id.also_erases_esim); |
| 344 | esimAlsoErased.setVisibility(View.VISIBLE); |
qingxi | 072f286 | 2017-04-11 18:28:40 -0700 | [diff] [blame] | 345 | |
Qingxi Li | c8a2b04 | 2018-01-11 11:35:07 -0800 | [diff] [blame] | 346 | final View noCancelMobilePlan = mContentView.findViewById( |
| 347 | R.id.no_cancel_mobile_plan); |
| 348 | noCancelMobilePlan.setVisibility(View.VISIBLE); |
| 349 | mEsimStorage.setChecked(true /* checked */); |
| 350 | } |
Edgar Wang | 514d746 | 2020-03-25 16:17:40 +0800 | [diff] [blame] | 351 | } else { |
| 352 | mEsimStorage.setChecked(false /* checked */); |
qingxi | 072f286 | 2017-04-11 18:28:40 -0700 | [diff] [blame] | 353 | } |
| 354 | |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 355 | final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE); |
| 356 | loadAccountList(um); |
Doris Ling | 1f49715 | 2018-02-22 16:33:07 -0800 | [diff] [blame] | 357 | final StringBuffer contentDescription = new StringBuffer(); |
Edgar Wang | 21f8cb3 | 2020-08-04 23:13:05 +0800 | [diff] [blame] | 358 | final View mainClearContainer = mContentView.findViewById(R.id.main_clear_container); |
| 359 | getContentDescription(mainClearContainer, contentDescription); |
| 360 | mainClearContainer.setContentDescription(contentDescription); |
jackqdyulei | 0b3edc7 | 2016-12-13 17:07:08 -0800 | [diff] [blame] | 361 | |
| 362 | // Set the status of initiateButton based on scrollview |
| 363 | mScrollView.setOnScrollChangeListener(new OnScrollChangeListener() { |
| 364 | @Override |
| 365 | public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 366 | int oldScrollY) { |
jackqdyulei | 0b3edc7 | 2016-12-13 17:07:08 -0800 | [diff] [blame] | 367 | if (v instanceof ScrollView && hasReachedBottom((ScrollView) v)) { |
| 368 | mInitiateButton.setEnabled(true); |
Doris Ling | 1f49715 | 2018-02-22 16:33:07 -0800 | [diff] [blame] | 369 | mScrollView.setOnScrollChangeListener(null); |
jackqdyulei | 0b3edc7 | 2016-12-13 17:07:08 -0800 | [diff] [blame] | 370 | } |
| 371 | } |
| 372 | }); |
| 373 | |
| 374 | // Set the initial state of the initiateButton |
Doris Ling | 1f49715 | 2018-02-22 16:33:07 -0800 | [diff] [blame] | 375 | mScrollView.getViewTreeObserver().addOnGlobalLayoutListener(this); |
jackqdyulei | 0b3edc7 | 2016-12-13 17:07:08 -0800 | [diff] [blame] | 376 | } |
| 377 | |
Jeff Davidson | f1c13fa | 2017-05-19 17:03:32 -0700 | [diff] [blame] | 378 | /** |
Jeff Davidson | a0b8472 | 2017-07-26 17:38:41 -0700 | [diff] [blame] | 379 | * Whether to show strings indicating that the eUICC will be wiped. |
Jeff Davidson | f1c13fa | 2017-05-19 17:03:32 -0700 | [diff] [blame] | 380 | * |
Jeff Davidson | a0b8472 | 2017-07-26 17:38:41 -0700 | [diff] [blame] | 381 | * <p>We show the strings on any device which supports eUICC as long as the eUICC was ever |
Jeff Davidson | 4ba7478 | 2017-06-30 18:02:13 -0700 | [diff] [blame] | 382 | * provisioned (that is, at least one profile was ever downloaded onto it). |
Jeff Davidson | f1c13fa | 2017-05-19 17:03:32 -0700 | [diff] [blame] | 383 | */ |
| 384 | @VisibleForTesting |
| 385 | boolean showWipeEuicc() { |
| 386 | Context context = getContext(); |
| 387 | if (!isEuiccEnabled(context)) { |
| 388 | return false; |
| 389 | } |
| 390 | ContentResolver cr = context.getContentResolver(); |
Qingxi Li | e0681db | 2018-03-14 16:00:47 -0700 | [diff] [blame] | 391 | return Settings.Global.getInt(cr, Settings.Global.EUICC_PROVISIONED, 0) != 0 |
Taesu Lee | 39e4fbb | 2019-07-22 19:20:05 +0900 | [diff] [blame] | 392 | || DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(context); |
Jeff Davidson | f1c13fa | 2017-05-19 17:03:32 -0700 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | @VisibleForTesting |
Qingxi Li | c8a2b04 | 2018-01-11 11:35:07 -0800 | [diff] [blame] | 396 | boolean showWipeEuiccCheckbox() { |
| 397 | return SystemProperties |
| 398 | .getBoolean(KEY_SHOW_ESIM_RESET_CHECKBOX, false /* def */); |
| 399 | } |
| 400 | |
| 401 | @VisibleForTesting |
Jeff Davidson | f1c13fa | 2017-05-19 17:03:32 -0700 | [diff] [blame] | 402 | protected boolean isEuiccEnabled(Context context) { |
| 403 | EuiccManager euiccManager = (EuiccManager) context.getSystemService(Context.EUICC_SERVICE); |
| 404 | return euiccManager.isEnabled(); |
| 405 | } |
| 406 | |
jackqdyulei | 0b3edc7 | 2016-12-13 17:07:08 -0800 | [diff] [blame] | 407 | @VisibleForTesting |
| 408 | boolean hasReachedBottom(final ScrollView scrollView) { |
| 409 | if (scrollView.getChildCount() < 1) { |
| 410 | return true; |
| 411 | } |
| 412 | |
| 413 | final View view = scrollView.getChildAt(0); |
| 414 | final int diff = view.getBottom() - (scrollView.getHeight() + scrollView.getScrollY()); |
| 415 | |
| 416 | return diff <= 0; |
Julia Reynolds | ce25af4 | 2015-07-08 16:56:31 -0400 | [diff] [blame] | 417 | } |
| 418 | |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 419 | private void setUpInitiateButton() { |
| 420 | if (mInitiateButton != null) { |
| 421 | return; |
| 422 | } |
| 423 | |
Maurice Lam | 59f1c1a | 2019-02-14 22:04:30 +0000 | [diff] [blame] | 424 | final GlifLayout layout = mContentView.findViewById(R.id.setup_wizard_layout); |
pastychang | 9bdb59a | 2019-01-21 09:49:15 +0800 | [diff] [blame] | 425 | final FooterBarMixin mixin = layout.getMixin(FooterBarMixin.class); |
| 426 | mixin.setPrimaryButton( |
pastychang | 908501e | 2018-12-26 10:46:40 +0800 | [diff] [blame] | 427 | new FooterButton.Builder(getActivity()) |
Edgar Wang | 21f8cb3 | 2020-08-04 23:13:05 +0800 | [diff] [blame] | 428 | .setText(R.string.main_clear_button_text) |
pastychang | 908501e | 2018-12-26 10:46:40 +0800 | [diff] [blame] | 429 | .setListener(mInitiateListener) |
| 430 | .setButtonType(ButtonType.OTHER) |
pastychang | 7961482 | 2019-01-03 10:12:54 +0800 | [diff] [blame] | 431 | .setTheme(R.style.SudGlifButton_Primary) |
pastychang | 908501e | 2018-12-26 10:46:40 +0800 | [diff] [blame] | 432 | .build() |
pastychang | 103409b | 2018-12-13 23:00:17 +0800 | [diff] [blame] | 433 | ); |
pastychang | 9bdb59a | 2019-01-21 09:49:15 +0800 | [diff] [blame] | 434 | mInitiateButton = mixin.getPrimaryButton(); |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 435 | } |
| 436 | |
Julia Reynolds | ce25af4 | 2015-07-08 16:56:31 -0400 | [diff] [blame] | 437 | private void getContentDescription(View v, StringBuffer description) { |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 438 | if (v.getVisibility() != View.VISIBLE) { |
| 439 | return; |
| 440 | } |
| 441 | if (v instanceof ViewGroup) { |
| 442 | ViewGroup vGroup = (ViewGroup) v; |
| 443 | for (int i = 0; i < vGroup.getChildCount(); i++) { |
| 444 | View nextChild = vGroup.getChildAt(i); |
| 445 | getContentDescription(nextChild, description); |
| 446 | } |
| 447 | } else if (v instanceof TextView) { |
| 448 | TextView vText = (TextView) v; |
| 449 | description.append(vText.getText()); |
| 450 | description.append(","); // Allow Talkback to pause between sections. |
| 451 | } |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 452 | } |
| 453 | |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 454 | private void loadAccountList(final UserManager um) { |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 455 | View accountsLabel = mContentView.findViewById(R.id.accounts_label); |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 456 | LinearLayout contents = (LinearLayout) mContentView.findViewById(R.id.accounts); |
Amith Yamasani | 3f45de5 | 2011-09-22 14:34:17 -0700 | [diff] [blame] | 457 | contents.removeAllViews(); |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 458 | |
| 459 | Context context = getActivity(); |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 460 | final List<UserInfo> profiles = um.getProfiles(UserHandle.myUserId()); |
| 461 | final int profilesSize = profiles.size(); |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 462 | |
| 463 | AccountManager mgr = AccountManager.get(context); |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 464 | |
felkachang | a6cec47 | 2018-03-29 12:08:20 +0800 | [diff] [blame] | 465 | LayoutInflater inflater = (LayoutInflater) context.getSystemService( |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 466 | Context.LAYOUT_INFLATER_SERVICE); |
| 467 | |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 468 | int accountsCount = 0; |
| 469 | for (int profileIndex = 0; profileIndex < profilesSize; profileIndex++) { |
| 470 | final UserInfo userInfo = profiles.get(profileIndex); |
| 471 | final int profileId = userInfo.id; |
| 472 | final UserHandle userHandle = new UserHandle(profileId); |
| 473 | Account[] accounts = mgr.getAccountsAsUser(profileId); |
Edgar Wang | 21f8cb3 | 2020-08-04 23:13:05 +0800 | [diff] [blame] | 474 | final int accountLength = accounts.length; |
| 475 | if (accountLength == 0) { |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 476 | continue; |
| 477 | } |
Edgar Wang | 21f8cb3 | 2020-08-04 23:13:05 +0800 | [diff] [blame] | 478 | accountsCount += accountLength; |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 479 | |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 480 | AuthenticatorDescription[] descs = AccountManager.get(context) |
| 481 | .getAuthenticatorTypesAsUser(profileId); |
Edgar Wang | 21f8cb3 | 2020-08-04 23:13:05 +0800 | [diff] [blame] | 482 | final int descLength = descs.length; |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 483 | |
Bartosz Fabianowski | 30ba868 | 2017-04-19 11:51:43 +0200 | [diff] [blame] | 484 | if (profilesSize > 1) { |
| 485 | View titleView = Utils.inflateCategoryHeader(inflater, contents); |
Edgar Wang | 0e92c7e | 2022-05-02 13:39:28 +0800 | [diff] [blame] | 486 | titleView.setPadding(0 /* left */, titleView.getPaddingTop(), |
| 487 | 0 /* right */, titleView.getPaddingBottom()); |
Bartosz Fabianowski | 30ba868 | 2017-04-19 11:51:43 +0200 | [diff] [blame] | 488 | final TextView titleText = (TextView) titleView.findViewById(android.R.id.title); |
Jonathan Scott | e0d4394 | 2022-01-19 15:19:08 +0000 | [diff] [blame] | 489 | |
| 490 | DevicePolicyManager devicePolicyManager = |
| 491 | context.getSystemService(DevicePolicyManager.class); |
| 492 | |
| 493 | if (userInfo.isManagedProfile()) { |
kholoud mohamed | 90afe19 | 2022-03-14 11:11:33 +0000 | [diff] [blame] | 494 | titleText.setText(devicePolicyManager.getResources().getString( |
Jonathan Scott | e0d4394 | 2022-01-19 15:19:08 +0000 | [diff] [blame] | 495 | WORK_CATEGORY_HEADER, () -> getString(R.string.category_work))); |
| 496 | } else { |
kholoud mohamed | 90afe19 | 2022-03-14 11:11:33 +0000 | [diff] [blame] | 497 | titleText.setText(devicePolicyManager.getResources().getString( |
Jonathan Scott | e0d4394 | 2022-01-19 15:19:08 +0000 | [diff] [blame] | 498 | PERSONAL_CATEGORY_HEADER, () -> getString(R.string.category_personal))); |
| 499 | } |
Bartosz Fabianowski | 30ba868 | 2017-04-19 11:51:43 +0200 | [diff] [blame] | 500 | contents.addView(titleView); |
| 501 | } |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 502 | |
Edgar Wang | 21f8cb3 | 2020-08-04 23:13:05 +0800 | [diff] [blame] | 503 | for (int i = 0; i < accountLength; i++) { |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 504 | Account account = accounts[i]; |
| 505 | AuthenticatorDescription desc = null; |
Edgar Wang | 21f8cb3 | 2020-08-04 23:13:05 +0800 | [diff] [blame] | 506 | for (int j = 0; j < descLength; j++) { |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 507 | if (account.type.equals(descs[j].type)) { |
| 508 | desc = descs[j]; |
| 509 | break; |
| 510 | } |
| 511 | } |
| 512 | if (desc == null) { |
| 513 | Log.w(TAG, "No descriptor for account name=" + account.name |
| 514 | + " type=" + account.type); |
| 515 | continue; |
| 516 | } |
| 517 | Drawable icon = null; |
| 518 | try { |
| 519 | if (desc.iconId != 0) { |
Zoltan Szatmary-Ban | 546790c | 2014-12-02 17:22:10 +0000 | [diff] [blame] | 520 | Context authContext = context.createPackageContextAsUser(desc.packageName, |
| 521 | 0, userHandle); |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 522 | icon = context.getPackageManager().getUserBadgedIcon( |
| 523 | authContext.getDrawable(desc.iconId), userHandle); |
| 524 | } |
| 525 | } catch (PackageManager.NameNotFoundException e) { |
Rubin Xu | d1ce82a | 2015-06-08 17:21:19 +0100 | [diff] [blame] | 526 | Log.w(TAG, "Bad package name for account type " + desc.type); |
| 527 | } catch (Resources.NotFoundException e) { |
| 528 | Log.w(TAG, "Invalid icon id for account type " + desc.type, e); |
| 529 | } |
| 530 | if (icon == null) { |
| 531 | icon = context.getPackageManager().getDefaultActivityIcon(); |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 532 | } |
| 533 | |
Edgar Wang | 21f8cb3 | 2020-08-04 23:13:05 +0800 | [diff] [blame] | 534 | View child = inflater.inflate(R.layout.main_clear_account, contents, false); |
Fan Zhang | 6b2bb39 | 2016-09-28 09:07:44 -0700 | [diff] [blame] | 535 | ((ImageView) child.findViewById(android.R.id.icon)).setImageDrawable(icon); |
| 536 | ((TextView) child.findViewById(android.R.id.title)).setText(account.name); |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 537 | contents.addView(child); |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 538 | } |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 539 | } |
| 540 | |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 541 | if (accountsCount > 0) { |
| 542 | accountsLabel.setVisibility(View.VISIBLE); |
| 543 | contents.setVisibility(View.VISIBLE); |
| 544 | } |
| 545 | // Checking for all other users and their profiles if any. |
| 546 | View otherUsers = mContentView.findViewById(R.id.other_users_present); |
| 547 | final boolean hasOtherUsers = (um.getUserCount() - profilesSize) > 0; |
| 548 | otherUsers.setVisibility(hasOtherUsers ? View.VISIBLE : View.GONE); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | @Override |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 552 | public View onCreateView(LayoutInflater inflater, ViewGroup container, |
| 553 | Bundle savedInstanceState) { |
Christine Franks | 1478222 | 2017-01-23 16:44:02 -0800 | [diff] [blame] | 554 | final Context context = getContext(); |
Philip P. Moltmann | e3f7211 | 2018-08-28 15:01:43 -0700 | [diff] [blame] | 555 | final EnforcedAdmin admin = RestrictedLockUtilsInternal.checkIfRestrictionEnforced(context, |
Christine Franks | 1478222 | 2017-01-23 16:44:02 -0800 | [diff] [blame] | 556 | UserManager.DISALLOW_FACTORY_RESET, UserHandle.myUserId()); |
| 557 | final UserManager um = UserManager.get(context); |
Philip P. Moltmann | e3f7211 | 2018-08-28 15:01:43 -0700 | [diff] [blame] | 558 | final boolean disallow = !um.isAdminUser() || RestrictedLockUtilsInternal |
| 559 | .hasBaseUserRestriction(context, UserManager.DISALLOW_FACTORY_RESET, |
| 560 | UserHandle.myUserId()); |
Christine Franks | a09eb38 | 2017-06-23 14:28:21 -0700 | [diff] [blame] | 561 | if (disallow && !Utils.isDemoUser(context)) { |
Edgar Wang | 21f8cb3 | 2020-08-04 23:13:05 +0800 | [diff] [blame] | 562 | return inflater.inflate(R.layout.main_clear_disallowed_screen, null); |
Sudheer Shanka | 7dbbe13 | 2016-02-16 14:19:32 +0000 | [diff] [blame] | 563 | } else if (admin != null) { |
arangelov | e35badd | 2017-10-27 13:51:28 +0100 | [diff] [blame] | 564 | new ActionDisabledByAdminDialogHelper(getActivity()) |
| 565 | .prepareDialogBuilder(UserManager.DISALLOW_FACTORY_RESET, admin) |
| 566 | .setOnDismissListener(__ -> getActivity().finish()) |
| 567 | .show(); |
| 568 | return new View(getContext()); |
Julia Reynolds | 2c53933 | 2014-06-11 12:56:02 -0400 | [diff] [blame] | 569 | } |
| 570 | |
Edgar Wang | 21f8cb3 | 2020-08-04 23:13:05 +0800 | [diff] [blame] | 571 | mContentView = inflater.inflate(R.layout.main_clear, null); |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 572 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 573 | establishInitialState(); |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 574 | return mContentView; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 575 | } |
Chris Wren | 8a963ba | 2015-03-20 10:29:14 -0400 | [diff] [blame] | 576 | |
| 577 | @Override |
Fan Zhang | 6507613 | 2016-08-08 10:25:13 -0700 | [diff] [blame] | 578 | public int getMetricsCategory() { |
Fan Zhang | 31b2100 | 2019-01-16 13:49:47 -0800 | [diff] [blame] | 579 | return SettingsEnums.MASTER_CLEAR; |
Chris Wren | 8a963ba | 2015-03-20 10:29:14 -0400 | [diff] [blame] | 580 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 581 | } |