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 | |
Maurice Lam | 2eb170c | 2017-04-28 16:18:47 -0700 | [diff] [blame] | 19 | import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; |
| 20 | |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 21 | import android.accounts.Account; |
| 22 | import android.accounts.AccountManager; |
| 23 | import android.accounts.AuthenticatorDescription; |
Doris Ling | ed4685f | 2017-10-25 14:08:57 -0700 | [diff] [blame] | 24 | import android.annotation.Nullable; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 25 | import android.app.Activity; |
Christine Franks | a09eb38 | 2017-06-23 14:28:21 -0700 | [diff] [blame] | 26 | import android.content.ComponentName; |
Jeff Davidson | f1c13fa | 2017-05-19 17:03:32 -0700 | [diff] [blame] | 27 | import android.content.ContentResolver; |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 28 | import android.content.Context; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 29 | import android.content.Intent; |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 30 | import android.content.pm.PackageManager; |
Carlos Valdivia | a9736ed | 2018-01-16 13:59:31 -0800 | [diff] [blame] | 31 | import android.content.pm.ResolveInfo; |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 32 | import android.content.pm.UserInfo; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 33 | import android.content.res.Resources; |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 34 | import android.graphics.drawable.Drawable; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 35 | import android.os.Bundle; |
Kenny Root | 3785e39 | 2011-01-18 15:14:32 -0800 | [diff] [blame] | 36 | import android.os.Environment; |
Ben Komalo | 2a32192 | 2011-09-07 16:42:34 -0700 | [diff] [blame] | 37 | import android.os.SystemProperties; |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 38 | import android.os.UserHandle; |
Amith Yamasani | 7eedcf4 | 2013-07-02 14:15:29 -0700 | [diff] [blame] | 39 | import android.os.UserManager; |
Jeff Davidson | f1c13fa | 2017-05-19 17:03:32 -0700 | [diff] [blame] | 40 | import android.provider.Settings; |
jackqdyulei | 0b3edc7 | 2016-12-13 17:07:08 -0800 | [diff] [blame] | 41 | import android.support.annotation.VisibleForTesting; |
qingxi | 072f286 | 2017-04-11 18:28:40 -0700 | [diff] [blame] | 42 | import android.telephony.euicc.EuiccManager; |
Carlos Valdivia | a9736ed | 2018-01-16 13:59:31 -0800 | [diff] [blame] | 43 | import android.text.TextUtils; |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 44 | import android.util.Log; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 45 | import android.view.LayoutInflater; |
| 46 | import android.view.View; |
jackqdyulei | 0b3edc7 | 2016-12-13 17:07:08 -0800 | [diff] [blame] | 47 | import android.view.View.OnScrollChangeListener; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 48 | import android.view.ViewGroup; |
jackqdyulei | 0b3edc7 | 2016-12-13 17:07:08 -0800 | [diff] [blame] | 49 | import android.view.ViewTreeObserver.OnGlobalLayoutListener; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 50 | import android.widget.Button; |
Dianne Hackborn | 1337d0f | 2010-10-14 11:58:30 -0700 | [diff] [blame] | 51 | import android.widget.CheckBox; |
Fan Zhang | 6b2bb39 | 2016-09-28 09:07:44 -0700 | [diff] [blame] | 52 | import android.widget.ImageView; |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 53 | import android.widget.LinearLayout; |
jackqdyulei | 0b3edc7 | 2016-12-13 17:07:08 -0800 | [diff] [blame] | 54 | import android.widget.ScrollView; |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 55 | import android.widget.TextView; |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 56 | |
Tamas Berghammer | 265d3c2 | 2016-06-22 15:34:45 +0100 | [diff] [blame] | 57 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Doris Ling | ed4685f | 2017-10-25 14:08:57 -0700 | [diff] [blame] | 58 | import com.android.settings.core.InstrumentedPreferenceFragment; |
Maurice Lam | 2eb170c | 2017-04-28 16:18:47 -0700 | [diff] [blame] | 59 | import com.android.settings.password.ChooseLockSettingsHelper; |
| 60 | import com.android.settings.password.ConfirmLockPattern; |
Sudheer Shanka | 7dbbe13 | 2016-02-16 14:19:32 +0000 | [diff] [blame] | 61 | import com.android.settingslib.RestrictedLockUtils; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 62 | |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 63 | import java.util.List; |
| 64 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 65 | /** |
| 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 Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 72 | * |
| 73 | * This is the initial screen. |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 74 | */ |
Doris Ling | ed4685f | 2017-10-25 14:08:57 -0700 | [diff] [blame] | 75 | public class MasterClear extends InstrumentedPreferenceFragment { |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 76 | private static final String TAG = "MasterClear"; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 77 | |
| 78 | private static final int KEYGUARD_REQUEST = 55; |
Carlos Valdivia | a9736ed | 2018-01-16 13:59:31 -0800 | [diff] [blame] | 79 | private static final int CREDENTIAL_CONFIRM_REQUEST = 56; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 80 | |
Qingxi Li | c8a2b04 | 2018-01-11 11:35:07 -0800 | [diff] [blame^] | 81 | private static final String KEY_SHOW_ESIM_RESET_CHECKBOX |
| 82 | = "masterclear.allow_retain_esim_profiles_after_fdr"; |
| 83 | |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 84 | static final String ERASE_EXTERNAL_EXTRA = "erase_sd"; |
qingxi | 072f286 | 2017-04-11 18:28:40 -0700 | [diff] [blame] | 85 | static final String ERASE_ESIMS_EXTRA = "erase_esim"; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 86 | |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 87 | private View mContentView; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 88 | private Button mInitiateButton; |
Dianne Hackborn | 1337d0f | 2010-10-14 11:58:30 -0700 | [diff] [blame] | 89 | private View mExternalStorageContainer; |
qingxi | 072f286 | 2017-04-11 18:28:40 -0700 | [diff] [blame] | 90 | @VisibleForTesting CheckBox mExternalStorage; |
Qingxi Li | c8a2b04 | 2018-01-11 11:35:07 -0800 | [diff] [blame^] | 91 | private View mEsimStorageContainer; |
| 92 | @VisibleForTesting CheckBox mEsimStorage; |
jackqdyulei | 0b3edc7 | 2016-12-13 17:07:08 -0800 | [diff] [blame] | 93 | 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 Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 102 | |
Doris Ling | 03a3b51 | 2017-10-18 14:25:01 -0700 | [diff] [blame] | 103 | @Override |
Doris Ling | ed4685f | 2017-10-25 14:08:57 -0700 | [diff] [blame] | 104 | public void onCreate(@Nullable Bundle savedInstanceState) { |
| 105 | super.onCreate(savedInstanceState); |
Doris Ling | 4a01283 | 2017-11-13 17:58:13 -0800 | [diff] [blame] | 106 | getActivity().setTitle(R.string.master_clear_title); |
Doris Ling | 03a3b51 | 2017-10-18 14:25:01 -0700 | [diff] [blame] | 107 | } |
| 108 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 109 | /** |
Jim Miller | 2deec7e | 2010-04-13 17:43:36 -0700 | [diff] [blame] | 110 | * Keyguard validation is run using the standard {@link ConfirmLockPattern} |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 111 | * component as a subactivity |
Jim Miller | 2deec7e | 2010-04-13 17:43:36 -0700 | [diff] [blame] | 112 | * @param request the request code to be returned once confirmation finishes |
| 113 | * @return true if confirmation launched |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 114 | */ |
Jim Miller | 2deec7e | 2010-04-13 17:43:36 -0700 | [diff] [blame] | 115 | private boolean runKeyguardConfirmation(int request) { |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 116 | Resources res = getActivity().getResources(); |
Jorim Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 117 | return new ChooseLockSettingsHelper(getActivity(), this).launchConfirmationActivity( |
| 118 | request, res.getText(R.string.master_clear_title)); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | @Override |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 122 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 123 | super.onActivityResult(requestCode, resultCode, data); |
| 124 | |
Carlos Valdivia | a9736ed | 2018-01-16 13:59:31 -0800 | [diff] [blame] | 125 | if (requestCode != KEYGUARD_REQUEST || requestCode != CREDENTIAL_CONFIRM_REQUEST) { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 126 | return; |
| 127 | } |
| 128 | |
| 129 | // If the user entered a valid keyguard trace, present the final |
| 130 | // confirmation prompt; otherwise, go back to the initial state. |
| 131 | if (resultCode == Activity.RESULT_OK) { |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 132 | showFinalConfirmation(); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 133 | } else { |
| 134 | establishInitialState(); |
| 135 | } |
| 136 | } |
| 137 | |
qingxi | 072f286 | 2017-04-11 18:28:40 -0700 | [diff] [blame] | 138 | @VisibleForTesting |
| 139 | void showFinalConfirmation() { |
Stuart Scott | be90341 | 2014-07-24 19:22:06 -0700 | [diff] [blame] | 140 | Bundle args = new Bundle(); |
| 141 | args.putBoolean(ERASE_EXTERNAL_EXTRA, mExternalStorage.isChecked()); |
Qingxi Li | c8a2b04 | 2018-01-11 11:35:07 -0800 | [diff] [blame^] | 142 | args.putBoolean(ERASE_ESIMS_EXTRA, mEsimStorage.isChecked()); |
Fan Zhang | c6ca314 | 2017-02-14 15:02:35 -0800 | [diff] [blame] | 143 | ((SettingsActivity) getActivity()).startPreferencePanel( |
| 144 | this, MasterClearConfirm.class.getName(), |
Stuart Scott | be90341 | 2014-07-24 19:22:06 -0700 | [diff] [blame] | 145 | args, R.string.master_clear_confirm_title, null, null, 0); |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 146 | } |
| 147 | |
Carlos Valdivia | a9736ed | 2018-01-16 13:59:31 -0800 | [diff] [blame] | 148 | @VisibleForTesting |
| 149 | boolean tryShowAccountConfirmation() { |
| 150 | final Context context = getActivity(); |
| 151 | final String accountType = context.getString(R.string.account_type); |
| 152 | final String packageName = context.getString(R.string.account_confirmation_package); |
| 153 | if (TextUtils.isEmpty(accountType) || TextUtils.isEmpty(packageName)) { |
| 154 | return false; |
| 155 | } |
| 156 | final AccountManager am = AccountManager.get(context); |
| 157 | Account[] accounts = am.getAccountsByType(accountType); |
| 158 | if (accounts != null && accounts.length > 0) { |
| 159 | final Intent requestAccountConfirmation = new Intent() |
| 160 | .setPackage(packageName) |
| 161 | .setAction("android.accounts.action.PRE_FACTORY_RESET"); |
| 162 | // Check to make sure that the intent is supported. |
| 163 | final PackageManager pm = context.getPackageManager(); |
| 164 | final List<ResolveInfo> resolutions = |
| 165 | pm.queryIntentActivities(requestAccountConfirmation, 0); |
| 166 | if (resolutions != null && resolutions.size() > 0) { |
| 167 | getActivity().startActivityForResult( |
| 168 | requestAccountConfirmation, CREDENTIAL_CONFIRM_REQUEST); |
| 169 | return true; |
| 170 | } |
| 171 | } |
| 172 | return false; |
| 173 | } |
| 174 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 175 | /** |
| 176 | * If the user clicks to begin the reset sequence, we next require a |
| 177 | * keyguard confirmation if the user has currently enabled one. If there |
| 178 | * is no keyguard available, we simply go to the final confirmation prompt. |
Christine Franks | a09eb38 | 2017-06-23 14:28:21 -0700 | [diff] [blame] | 179 | * |
| 180 | * 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] | 181 | */ |
Christine Franks | a09eb38 | 2017-06-23 14:28:21 -0700 | [diff] [blame] | 182 | @VisibleForTesting |
| 183 | protected final Button.OnClickListener mInitiateListener = new Button.OnClickListener() { |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 184 | |
Christine Franks | a09eb38 | 2017-06-23 14:28:21 -0700 | [diff] [blame] | 185 | public void onClick(View view) { |
| 186 | final Context context = view.getContext(); |
| 187 | if (Utils.isDemoUser(context)) { |
Justin Klaassen | 3025727 | 2017-08-08 21:58:05 -0700 | [diff] [blame] | 188 | final ComponentName componentName = Utils.getDeviceOwnerComponent(context); |
| 189 | if (componentName != null) { |
Christine Franks | a09eb38 | 2017-06-23 14:28:21 -0700 | [diff] [blame] | 190 | final Intent requestFactoryReset = new Intent() |
Justin Klaassen | 3025727 | 2017-08-08 21:58:05 -0700 | [diff] [blame] | 191 | .setPackage(componentName.getPackageName()) |
Christine Franks | a09eb38 | 2017-06-23 14:28:21 -0700 | [diff] [blame] | 192 | .setAction(Intent.ACTION_FACTORY_RESET); |
| 193 | context.startActivity(requestFactoryReset); |
Christine Franks | d7713c9 | 2017-01-20 11:24:14 -0800 | [diff] [blame] | 194 | } |
Carlos Valdivia | a9736ed | 2018-01-16 13:59:31 -0800 | [diff] [blame] | 195 | return; |
| 196 | } |
| 197 | |
| 198 | if (!tryShowAccountConfirmation() && !runKeyguardConfirmation(KEYGUARD_REQUEST)) { |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 199 | showFinalConfirmation(); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 200 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 201 | } |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 202 | }; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 203 | |
| 204 | /** |
| 205 | * In its initial state, the activity presents a button for the user to |
| 206 | * click in order to initiate a confirmation sequence. This method is |
| 207 | * called from various other points in the code to reset the activity to |
| 208 | * this base state. |
Jim Miller | 47d380f | 2010-01-20 13:37:14 -0800 | [diff] [blame] | 209 | * |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 210 | * <p>Reinflating views from resources is expensive and prevents us from |
| 211 | * caching widget pointers, so we use a single-inflate pattern: we lazy- |
| 212 | * inflate each view, caching all of the widget pointers we'll need at the |
| 213 | * time, then simply reuse the inflated views directly whenever we need |
| 214 | * to change contents. |
| 215 | */ |
| 216 | private void establishInitialState() { |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 217 | mInitiateButton = (Button) mContentView.findViewById(R.id.initiate_master_clear); |
| 218 | mInitiateButton.setOnClickListener(mInitiateListener); |
| 219 | mExternalStorageContainer = mContentView.findViewById(R.id.erase_external_container); |
| 220 | mExternalStorage = (CheckBox) mContentView.findViewById(R.id.erase_external); |
Qingxi Li | c8a2b04 | 2018-01-11 11:35:07 -0800 | [diff] [blame^] | 221 | mEsimStorageContainer = mContentView.findViewById(R.id.erase_esim_container); |
| 222 | mEsimStorage = (CheckBox) mContentView.findViewById(R.id.erase_esim); |
jackqdyulei | 0b3edc7 | 2016-12-13 17:07:08 -0800 | [diff] [blame] | 223 | mScrollView = (ScrollView) mContentView.findViewById(R.id.master_clear_scrollview); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 224 | |
Kenny Root | 3785e39 | 2011-01-18 15:14:32 -0800 | [diff] [blame] | 225 | /* |
| 226 | * If the external storage is emulated, it will be erased with a factory |
| 227 | * reset at any rate. There is no need to have a separate option until |
| 228 | * we have a factory reset that only erases some directories and not |
Ben Komalo | 2a32192 | 2011-09-07 16:42:34 -0700 | [diff] [blame] | 229 | * others. Likewise, if it's non-removable storage, it could potentially have been |
| 230 | * encrypted, and will also need to be wiped. |
Kenny Root | 3785e39 | 2011-01-18 15:14:32 -0800 | [diff] [blame] | 231 | */ |
Ben Komalo | 2a32192 | 2011-09-07 16:42:34 -0700 | [diff] [blame] | 232 | boolean isExtStorageEmulated = Environment.isExternalStorageEmulated(); |
| 233 | if (isExtStorageEmulated |
| 234 | || (!Environment.isExternalStorageRemovable() && isExtStorageEncrypted())) { |
Kenny Root | 3785e39 | 2011-01-18 15:14:32 -0800 | [diff] [blame] | 235 | mExternalStorageContainer.setVisibility(View.GONE); |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 236 | |
Kenny Root | 3785e39 | 2011-01-18 15:14:32 -0800 | [diff] [blame] | 237 | final View externalOption = mContentView.findViewById(R.id.erase_external_option_text); |
| 238 | externalOption.setVisibility(View.GONE); |
| 239 | |
| 240 | final View externalAlsoErased = mContentView.findViewById(R.id.also_erases_external); |
| 241 | externalAlsoErased.setVisibility(View.VISIBLE); |
Ben Komalo | 2a32192 | 2011-09-07 16:42:34 -0700 | [diff] [blame] | 242 | |
| 243 | // If it's not emulated, it is on a separate partition but it means we're doing |
| 244 | // a force wipe due to encryption. |
| 245 | mExternalStorage.setChecked(!isExtStorageEmulated); |
Kenny Root | 3785e39 | 2011-01-18 15:14:32 -0800 | [diff] [blame] | 246 | } else { |
| 247 | mExternalStorageContainer.setOnClickListener(new View.OnClickListener() { |
| 248 | |
| 249 | @Override |
| 250 | public void onClick(View v) { |
| 251 | mExternalStorage.toggle(); |
| 252 | } |
| 253 | }); |
| 254 | } |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 255 | |
Jeff Davidson | f1c13fa | 2017-05-19 17:03:32 -0700 | [diff] [blame] | 256 | if (showWipeEuicc()) { |
Qingxi Li | c8a2b04 | 2018-01-11 11:35:07 -0800 | [diff] [blame^] | 257 | if (showWipeEuiccCheckbox()) { |
| 258 | TextView title = mContentView.findViewById(R.id.erase_esim_title); |
| 259 | title.setText(R.string.erase_esim_storage); |
| 260 | mEsimStorageContainer.setVisibility(View.VISIBLE); |
| 261 | mEsimStorageContainer.setOnClickListener(new View.OnClickListener() { |
| 262 | @Override |
| 263 | public void onClick(View v) { |
| 264 | mEsimStorage.toggle(); |
| 265 | } |
| 266 | }); |
| 267 | } else { |
| 268 | final View esimAlsoErased = mContentView.findViewById(R.id.also_erases_esim); |
| 269 | esimAlsoErased.setVisibility(View.VISIBLE); |
qingxi | 072f286 | 2017-04-11 18:28:40 -0700 | [diff] [blame] | 270 | |
Qingxi Li | c8a2b04 | 2018-01-11 11:35:07 -0800 | [diff] [blame^] | 271 | final View noCancelMobilePlan = mContentView.findViewById( |
| 272 | R.id.no_cancel_mobile_plan); |
| 273 | noCancelMobilePlan.setVisibility(View.VISIBLE); |
| 274 | mEsimStorage.setChecked(true /* checked */); |
| 275 | } |
qingxi | 072f286 | 2017-04-11 18:28:40 -0700 | [diff] [blame] | 276 | } |
| 277 | |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 278 | final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE); |
| 279 | loadAccountList(um); |
Julia Reynolds | ce25af4 | 2015-07-08 16:56:31 -0400 | [diff] [blame] | 280 | StringBuffer contentDescription = new StringBuffer(); |
| 281 | View masterClearContainer = mContentView.findViewById(R.id.master_clear_container); |
| 282 | getContentDescription(masterClearContainer, contentDescription); |
| 283 | masterClearContainer.setContentDescription(contentDescription); |
jackqdyulei | 0b3edc7 | 2016-12-13 17:07:08 -0800 | [diff] [blame] | 284 | |
| 285 | // Set the status of initiateButton based on scrollview |
| 286 | mScrollView.setOnScrollChangeListener(new OnScrollChangeListener() { |
| 287 | @Override |
| 288 | public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, |
| 289 | int oldScrollY) { |
| 290 | if (v instanceof ScrollView && hasReachedBottom((ScrollView) v)) { |
| 291 | mInitiateButton.setEnabled(true); |
| 292 | } |
| 293 | } |
| 294 | }); |
| 295 | |
| 296 | // Set the initial state of the initiateButton |
| 297 | mScrollView.getViewTreeObserver().addOnGlobalLayoutListener(mOnGlobalLayoutListener); |
| 298 | } |
| 299 | |
Jeff Davidson | f1c13fa | 2017-05-19 17:03:32 -0700 | [diff] [blame] | 300 | /** |
Jeff Davidson | a0b8472 | 2017-07-26 17:38:41 -0700 | [diff] [blame] | 301 | * Whether to show strings indicating that the eUICC will be wiped. |
Jeff Davidson | f1c13fa | 2017-05-19 17:03:32 -0700 | [diff] [blame] | 302 | * |
Jeff Davidson | a0b8472 | 2017-07-26 17:38:41 -0700 | [diff] [blame] | 303 | * <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] | 304 | * provisioned (that is, at least one profile was ever downloaded onto it). |
Jeff Davidson | f1c13fa | 2017-05-19 17:03:32 -0700 | [diff] [blame] | 305 | */ |
| 306 | @VisibleForTesting |
| 307 | boolean showWipeEuicc() { |
| 308 | Context context = getContext(); |
| 309 | if (!isEuiccEnabled(context)) { |
| 310 | return false; |
| 311 | } |
| 312 | ContentResolver cr = context.getContentResolver(); |
Jeff Davidson | 4ba7478 | 2017-06-30 18:02:13 -0700 | [diff] [blame] | 313 | return Settings.Global.getInt(cr, Settings.Global.EUICC_PROVISIONED, 0) != 0; |
Jeff Davidson | f1c13fa | 2017-05-19 17:03:32 -0700 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | @VisibleForTesting |
Qingxi Li | c8a2b04 | 2018-01-11 11:35:07 -0800 | [diff] [blame^] | 317 | boolean showWipeEuiccCheckbox() { |
| 318 | return SystemProperties |
| 319 | .getBoolean(KEY_SHOW_ESIM_RESET_CHECKBOX, false /* def */); |
| 320 | } |
| 321 | |
| 322 | @VisibleForTesting |
Jeff Davidson | f1c13fa | 2017-05-19 17:03:32 -0700 | [diff] [blame] | 323 | protected boolean isEuiccEnabled(Context context) { |
| 324 | EuiccManager euiccManager = (EuiccManager) context.getSystemService(Context.EUICC_SERVICE); |
| 325 | return euiccManager.isEnabled(); |
| 326 | } |
| 327 | |
jackqdyulei | 0b3edc7 | 2016-12-13 17:07:08 -0800 | [diff] [blame] | 328 | @VisibleForTesting |
| 329 | boolean hasReachedBottom(final ScrollView scrollView) { |
| 330 | if (scrollView.getChildCount() < 1) { |
| 331 | return true; |
| 332 | } |
| 333 | |
| 334 | final View view = scrollView.getChildAt(0); |
| 335 | final int diff = view.getBottom() - (scrollView.getHeight() + scrollView.getScrollY()); |
| 336 | |
| 337 | return diff <= 0; |
Julia Reynolds | ce25af4 | 2015-07-08 16:56:31 -0400 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | private void getContentDescription(View v, StringBuffer description) { |
Jason Monk | fda7741 | 2016-05-06 14:28:09 -0400 | [diff] [blame] | 341 | if (v.getVisibility() != View.VISIBLE) { |
| 342 | return; |
| 343 | } |
Julia Reynolds | ce25af4 | 2015-07-08 16:56:31 -0400 | [diff] [blame] | 344 | if (v instanceof ViewGroup) { |
| 345 | ViewGroup vGroup = (ViewGroup) v; |
| 346 | for (int i = 0; i < vGroup.getChildCount(); i++) { |
| 347 | View nextChild = vGroup.getChildAt(i); |
| 348 | getContentDescription(nextChild, description); |
| 349 | } |
| 350 | } else if (v instanceof TextView) { |
| 351 | TextView vText = (TextView) v; |
| 352 | description.append(vText.getText()); |
| 353 | description.append(","); // Allow Talkback to pause between sections. |
| 354 | } |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 355 | } |
| 356 | |
Ben Komalo | 2a32192 | 2011-09-07 16:42:34 -0700 | [diff] [blame] | 357 | private boolean isExtStorageEncrypted() { |
| 358 | String state = SystemProperties.get("vold.decrypt"); |
| 359 | return !"".equals(state); |
| 360 | } |
| 361 | |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 362 | private void loadAccountList(final UserManager um) { |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 363 | View accountsLabel = mContentView.findViewById(R.id.accounts_label); |
| 364 | LinearLayout contents = (LinearLayout)mContentView.findViewById(R.id.accounts); |
Amith Yamasani | 3f45de5 | 2011-09-22 14:34:17 -0700 | [diff] [blame] | 365 | contents.removeAllViews(); |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 366 | |
| 367 | Context context = getActivity(); |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 368 | final List<UserInfo> profiles = um.getProfiles(UserHandle.myUserId()); |
| 369 | final int profilesSize = profiles.size(); |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 370 | |
| 371 | AccountManager mgr = AccountManager.get(context); |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 372 | |
| 373 | LayoutInflater inflater = (LayoutInflater)context.getSystemService( |
| 374 | Context.LAYOUT_INFLATER_SERVICE); |
| 375 | |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 376 | int accountsCount = 0; |
| 377 | for (int profileIndex = 0; profileIndex < profilesSize; profileIndex++) { |
| 378 | final UserInfo userInfo = profiles.get(profileIndex); |
| 379 | final int profileId = userInfo.id; |
| 380 | final UserHandle userHandle = new UserHandle(profileId); |
| 381 | Account[] accounts = mgr.getAccountsAsUser(profileId); |
| 382 | final int N = accounts.length; |
| 383 | if (N == 0) { |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 384 | continue; |
| 385 | } |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 386 | accountsCount += N; |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 387 | |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 388 | AuthenticatorDescription[] descs = AccountManager.get(context) |
| 389 | .getAuthenticatorTypesAsUser(profileId); |
| 390 | final int M = descs.length; |
| 391 | |
Bartosz Fabianowski | 30ba868 | 2017-04-19 11:51:43 +0200 | [diff] [blame] | 392 | if (profilesSize > 1) { |
| 393 | View titleView = Utils.inflateCategoryHeader(inflater, contents); |
| 394 | final TextView titleText = (TextView) titleView.findViewById(android.R.id.title); |
| 395 | titleText.setText(userInfo.isManagedProfile() ? R.string.category_work |
| 396 | : R.string.category_personal); |
| 397 | contents.addView(titleView); |
| 398 | } |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 399 | |
| 400 | for (int i = 0; i < N; i++) { |
| 401 | Account account = accounts[i]; |
| 402 | AuthenticatorDescription desc = null; |
| 403 | for (int j = 0; j < M; j++) { |
| 404 | if (account.type.equals(descs[j].type)) { |
| 405 | desc = descs[j]; |
| 406 | break; |
| 407 | } |
| 408 | } |
| 409 | if (desc == null) { |
| 410 | Log.w(TAG, "No descriptor for account name=" + account.name |
| 411 | + " type=" + account.type); |
| 412 | continue; |
| 413 | } |
| 414 | Drawable icon = null; |
| 415 | try { |
| 416 | if (desc.iconId != 0) { |
Zoltan Szatmary-Ban | 546790c | 2014-12-02 17:22:10 +0000 | [diff] [blame] | 417 | Context authContext = context.createPackageContextAsUser(desc.packageName, |
| 418 | 0, userHandle); |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 419 | icon = context.getPackageManager().getUserBadgedIcon( |
| 420 | authContext.getDrawable(desc.iconId), userHandle); |
| 421 | } |
| 422 | } catch (PackageManager.NameNotFoundException e) { |
Rubin Xu | d1ce82a | 2015-06-08 17:21:19 +0100 | [diff] [blame] | 423 | Log.w(TAG, "Bad package name for account type " + desc.type); |
| 424 | } catch (Resources.NotFoundException e) { |
| 425 | Log.w(TAG, "Invalid icon id for account type " + desc.type, e); |
| 426 | } |
| 427 | if (icon == null) { |
| 428 | icon = context.getPackageManager().getDefaultActivityIcon(); |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 429 | } |
| 430 | |
Fan Zhang | 6b2bb39 | 2016-09-28 09:07:44 -0700 | [diff] [blame] | 431 | View child = inflater.inflate(R.layout.master_clear_account, contents, false); |
| 432 | ((ImageView) child.findViewById(android.R.id.icon)).setImageDrawable(icon); |
| 433 | ((TextView) child.findViewById(android.R.id.title)).setText(account.name); |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 434 | contents.addView(child); |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 435 | } |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 436 | } |
| 437 | |
Zoltan Szatmary-Ban | 7cc1b9e | 2014-10-24 18:03:18 +0100 | [diff] [blame] | 438 | if (accountsCount > 0) { |
| 439 | accountsLabel.setVisibility(View.VISIBLE); |
| 440 | contents.setVisibility(View.VISIBLE); |
| 441 | } |
| 442 | // Checking for all other users and their profiles if any. |
| 443 | View otherUsers = mContentView.findViewById(R.id.other_users_present); |
| 444 | final boolean hasOtherUsers = (um.getUserCount() - profilesSize) > 0; |
| 445 | otherUsers.setVisibility(hasOtherUsers ? View.VISIBLE : View.GONE); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | @Override |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 449 | public View onCreateView(LayoutInflater inflater, ViewGroup container, |
| 450 | Bundle savedInstanceState) { |
Christine Franks | 1478222 | 2017-01-23 16:44:02 -0800 | [diff] [blame] | 451 | final Context context = getContext(); |
| 452 | final EnforcedAdmin admin = RestrictedLockUtils.checkIfRestrictionEnforced(context, |
| 453 | UserManager.DISALLOW_FACTORY_RESET, UserHandle.myUserId()); |
| 454 | final UserManager um = UserManager.get(context); |
| 455 | final boolean disallow = !um.isAdminUser() || RestrictedLockUtils.hasBaseUserRestriction( |
| 456 | context, UserManager.DISALLOW_FACTORY_RESET, UserHandle.myUserId()); |
Christine Franks | a09eb38 | 2017-06-23 14:28:21 -0700 | [diff] [blame] | 457 | if (disallow && !Utils.isDemoUser(context)) { |
Julia Reynolds | 2c53933 | 2014-06-11 12:56:02 -0400 | [diff] [blame] | 458 | return inflater.inflate(R.layout.master_clear_disallowed_screen, null); |
Sudheer Shanka | 7dbbe13 | 2016-02-16 14:19:32 +0000 | [diff] [blame] | 459 | } else if (admin != null) { |
| 460 | View view = inflater.inflate(R.layout.admin_support_details_empty_view, null); |
| 461 | ShowAdminSupportDetailsDialog.setAdminSupportDetails(getActivity(), view, admin, false); |
| 462 | view.setVisibility(View.VISIBLE); |
| 463 | return view; |
Julia Reynolds | 2c53933 | 2014-06-11 12:56:02 -0400 | [diff] [blame] | 464 | } |
| 465 | |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 466 | mContentView = inflater.inflate(R.layout.master_clear, null); |
Joe Onorato | b51886d | 2010-11-08 18:25:51 -0800 | [diff] [blame] | 467 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 468 | establishInitialState(); |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 469 | return mContentView; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 470 | } |
Chris Wren | 8a963ba | 2015-03-20 10:29:14 -0400 | [diff] [blame] | 471 | |
| 472 | @Override |
Fan Zhang | 6507613 | 2016-08-08 10:25:13 -0700 | [diff] [blame] | 473 | public int getMetricsCategory() { |
Chris Wren | 9d1bfd1 | 2016-01-26 18:04:01 -0500 | [diff] [blame] | 474 | return MetricsEvent.MASTER_CLEAR; |
Chris Wren | 8a963ba | 2015-03-20 10:29:14 -0400 | [diff] [blame] | 475 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 476 | } |