Jim Miller | 46c7f6d | 2014-10-13 18:15:17 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | |
Jim Miller | aa03767 | 2014-10-17 18:28:52 -0700 | [diff] [blame] | 19 | import android.accessibilityservice.AccessibilityServiceInfo; |
Maurice Lam | 18d7965 | 2017-03-21 17:57:55 -0700 | [diff] [blame] | 20 | import android.app.Activity; |
Jim Miller | 47adff0 | 2014-10-17 17:43:18 -0700 | [diff] [blame] | 21 | import android.app.AlertDialog; |
| 22 | import android.app.Dialog; |
Jim Miller | 46c7f6d | 2014-10-13 18:15:17 -0700 | [diff] [blame] | 23 | import android.app.admin.DevicePolicyManager; |
| 24 | import android.content.Context; |
Jim Miller | 47adff0 | 2014-10-17 17:43:18 -0700 | [diff] [blame] | 25 | import android.content.DialogInterface; |
Jim Miller | 46c7f6d | 2014-10-13 18:15:17 -0700 | [diff] [blame] | 26 | import android.content.Intent; |
Maurice Lam | 9990f39 | 2017-06-28 15:06:09 -0700 | [diff] [blame] | 27 | import android.content.res.Resources; |
Jim Miller | 46c7f6d | 2014-10-13 18:15:17 -0700 | [diff] [blame] | 28 | import android.os.Bundle; |
Udam Saini | edac136 | 2015-12-08 17:28:19 -0800 | [diff] [blame] | 29 | import android.util.Log; |
Jim Miller | 46c7f6d | 2014-10-13 18:15:17 -0700 | [diff] [blame] | 30 | import android.view.LayoutInflater; |
Maurice Lam | d189ac5 | 2016-06-15 13:39:34 -0700 | [diff] [blame] | 31 | import android.view.View; |
| 32 | import android.view.ViewGroup; |
Jim Miller | 47adff0 | 2014-10-17 17:43:18 -0700 | [diff] [blame] | 33 | import android.view.accessibility.AccessibilityManager; |
Maurice Lam | d189ac5 | 2016-06-15 13:39:34 -0700 | [diff] [blame] | 34 | import android.widget.LinearLayout; |
Jim Miller | 46c7f6d | 2014-10-13 18:15:17 -0700 | [diff] [blame] | 35 | import android.widget.TextView; |
| 36 | |
Tamas Berghammer | 265d3c2 | 2016-06-22 15:34:45 +0100 | [diff] [blame] | 37 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Maurice Lam | 18d7965 | 2017-03-21 17:57:55 -0700 | [diff] [blame] | 38 | import com.android.settings.core.InstrumentedFragment; |
| 39 | import com.android.settings.core.instrumentation.InstrumentedDialogFragment; |
Maurice Lam | 2eb170c | 2017-04-28 16:18:47 -0700 | [diff] [blame] | 40 | import com.android.settings.password.ChooseLockSettingsHelper; |
Maurice Lam | 9be96e0 | 2017-02-23 14:43:48 -0800 | [diff] [blame] | 41 | import com.android.setupwizardlib.GlifLayout; |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 42 | |
| 43 | import java.util.List; |
| 44 | |
Jim Miller | 46c7f6d | 2014-10-13 18:15:17 -0700 | [diff] [blame] | 45 | public class EncryptionInterstitial extends SettingsActivity { |
Maurice Lam | d189ac5 | 2016-06-15 13:39:34 -0700 | [diff] [blame] | 46 | private static final String TAG = EncryptionInterstitial.class.getSimpleName(); |
Jim Miller | 46c7f6d | 2014-10-13 18:15:17 -0700 | [diff] [blame] | 47 | |
Maurice Lam | 0973c31 | 2014-12-05 12:19:05 -0800 | [diff] [blame] | 48 | protected static final String EXTRA_PASSWORD_QUALITY = "extra_password_quality"; |
Udam Saini | edac136 | 2015-12-08 17:28:19 -0800 | [diff] [blame] | 49 | protected static final String EXTRA_UNLOCK_METHOD_INTENT = "extra_unlock_method_intent"; |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 50 | public static final String EXTRA_REQUIRE_PASSWORD = "extra_require_password"; |
Udam Saini | edac136 | 2015-12-08 17:28:19 -0800 | [diff] [blame] | 51 | private static final int CHOOSE_LOCK_REQUEST = 100; |
Jim Miller | 46c7f6d | 2014-10-13 18:15:17 -0700 | [diff] [blame] | 52 | |
| 53 | @Override |
| 54 | public Intent getIntent() { |
| 55 | Intent modIntent = new Intent(super.getIntent()); |
| 56 | modIntent.putExtra(EXTRA_SHOW_FRAGMENT, EncryptionInterstitialFragment.class.getName()); |
| 57 | return modIntent; |
| 58 | } |
| 59 | |
| 60 | @Override |
Maurice Lam | 9990f39 | 2017-06-28 15:06:09 -0700 | [diff] [blame] | 61 | protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) { |
| 62 | resid = SetupWizardUtils.getTheme(getIntent()); |
| 63 | super.onApplyThemeResource(theme, resid, first); |
| 64 | } |
| 65 | |
| 66 | @Override |
Jim Miller | 46c7f6d | 2014-10-13 18:15:17 -0700 | [diff] [blame] | 67 | protected boolean isValidFragment(String fragmentName) { |
| 68 | return EncryptionInterstitialFragment.class.getName().equals(fragmentName); |
| 69 | } |
| 70 | |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 71 | public static Intent createStartIntent(Context ctx, int quality, |
Udam Saini | edac136 | 2015-12-08 17:28:19 -0800 | [diff] [blame] | 72 | boolean requirePasswordDefault, Intent unlockMethodIntent) { |
Jim Miller | 46c7f6d | 2014-10-13 18:15:17 -0700 | [diff] [blame] | 73 | return new Intent(ctx, EncryptionInterstitial.class) |
Jim Miller | 46c7f6d | 2014-10-13 18:15:17 -0700 | [diff] [blame] | 74 | .putExtra(EXTRA_PASSWORD_QUALITY, quality) |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 75 | .putExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, R.string.encryption_interstitial_header) |
Udam Saini | edac136 | 2015-12-08 17:28:19 -0800 | [diff] [blame] | 76 | .putExtra(EXTRA_REQUIRE_PASSWORD, requirePasswordDefault) |
| 77 | .putExtra(EXTRA_UNLOCK_METHOD_INTENT, unlockMethodIntent); |
Jim Miller | 46c7f6d | 2014-10-13 18:15:17 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Maurice Lam | d189ac5 | 2016-06-15 13:39:34 -0700 | [diff] [blame] | 80 | @Override |
| 81 | protected void onCreate(Bundle savedInstance) { |
| 82 | super.onCreate(savedInstance); |
| 83 | LinearLayout layout = (LinearLayout) findViewById(R.id.content_parent); |
| 84 | layout.setFitsSystemWindows(false); |
| 85 | } |
| 86 | |
Maurice Lam | 18d7965 | 2017-03-21 17:57:55 -0700 | [diff] [blame] | 87 | public static class EncryptionInterstitialFragment extends InstrumentedFragment |
| 88 | implements View.OnClickListener { |
Udam Saini | d553abc | 2016-02-16 17:54:13 -0800 | [diff] [blame] | 89 | |
Maurice Lam | 9be96e0 | 2017-02-23 14:43:48 -0800 | [diff] [blame] | 90 | private View mRequirePasswordToDecrypt; |
| 91 | private View mDontRequirePasswordToDecrypt; |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 92 | private boolean mPasswordRequired; |
Udam Saini | edac136 | 2015-12-08 17:28:19 -0800 | [diff] [blame] | 93 | private Intent mUnlockMethodIntent; |
Maurice Lam | 8890f7a | 2016-05-12 16:24:41 -0700 | [diff] [blame] | 94 | private int mRequestedPasswordQuality; |
Jim Miller | 46c7f6d | 2014-10-13 18:15:17 -0700 | [diff] [blame] | 95 | |
| 96 | @Override |
Fan Zhang | 6507613 | 2016-08-08 10:25:13 -0700 | [diff] [blame] | 97 | public int getMetricsCategory() { |
Chris Wren | 9d1bfd1 | 2016-01-26 18:04:01 -0500 | [diff] [blame] | 98 | return MetricsEvent.ENCRYPTION; |
Chris Wren | 8a963ba | 2015-03-20 10:29:14 -0400 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | @Override |
Maurice Lam | 9be96e0 | 2017-02-23 14:43:48 -0800 | [diff] [blame] | 102 | public View onCreateView( |
| 103 | LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
| 104 | return inflater.inflate(R.layout.encryption_interstitial, container, false); |
| 105 | } |
Maurice Lam | 7e83103 | 2015-07-20 16:08:38 -0700 | [diff] [blame] | 106 | |
Maurice Lam | 9be96e0 | 2017-02-23 14:43:48 -0800 | [diff] [blame] | 107 | @Override |
| 108 | public void onViewCreated(View view, Bundle savedInstanceState) { |
| 109 | super.onViewCreated(view, savedInstanceState); |
Udam Saini | d553abc | 2016-02-16 17:54:13 -0800 | [diff] [blame] | 110 | |
Maurice Lam | 9be96e0 | 2017-02-23 14:43:48 -0800 | [diff] [blame] | 111 | mRequirePasswordToDecrypt = view.findViewById(R.id.encrypt_require_password); |
| 112 | mDontRequirePasswordToDecrypt = view.findViewById(R.id.encrypt_dont_require_password); |
Maurice Lam | c0e7879 | 2015-07-20 14:49:29 -0700 | [diff] [blame] | 113 | boolean forFingerprint = getActivity().getIntent().getBooleanExtra( |
| 114 | ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT, false); |
Udam Saini | edac136 | 2015-12-08 17:28:19 -0800 | [diff] [blame] | 115 | Intent intent = getActivity().getIntent(); |
Maurice Lam | 8890f7a | 2016-05-12 16:24:41 -0700 | [diff] [blame] | 116 | mRequestedPasswordQuality = intent.getIntExtra(EXTRA_PASSWORD_QUALITY, 0); |
| 117 | mUnlockMethodIntent = intent.getParcelableExtra(EXTRA_UNLOCK_METHOD_INTENT); |
Jim Miller | 46c7f6d | 2014-10-13 18:15:17 -0700 | [diff] [blame] | 118 | final int msgId; |
Maurice Lam | 8890f7a | 2016-05-12 16:24:41 -0700 | [diff] [blame] | 119 | switch (mRequestedPasswordQuality) { |
Jim Miller | 46c7f6d | 2014-10-13 18:15:17 -0700 | [diff] [blame] | 120 | case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING: |
Maurice Lam | c0e7879 | 2015-07-20 14:49:29 -0700 | [diff] [blame] | 121 | msgId = forFingerprint ? |
| 122 | R.string.encryption_interstitial_message_pattern_for_fingerprint : |
| 123 | R.string.encryption_interstitial_message_pattern; |
Jim Miller | 46c7f6d | 2014-10-13 18:15:17 -0700 | [diff] [blame] | 124 | break; |
| 125 | case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC: |
| 126 | case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX: |
Maurice Lam | c0e7879 | 2015-07-20 14:49:29 -0700 | [diff] [blame] | 127 | msgId = forFingerprint ? |
| 128 | R.string.encryption_interstitial_message_pin_for_fingerprint : |
| 129 | R.string.encryption_interstitial_message_pin; |
Jim Miller | 46c7f6d | 2014-10-13 18:15:17 -0700 | [diff] [blame] | 130 | break; |
| 131 | default: |
Maurice Lam | c0e7879 | 2015-07-20 14:49:29 -0700 | [diff] [blame] | 132 | msgId = forFingerprint ? |
| 133 | R.string.encryption_interstitial_message_password_for_fingerprint : |
| 134 | R.string.encryption_interstitial_message_password; |
Jim Miller | 46c7f6d | 2014-10-13 18:15:17 -0700 | [diff] [blame] | 135 | break; |
| 136 | } |
Maurice Lam | 9be96e0 | 2017-02-23 14:43:48 -0800 | [diff] [blame] | 137 | TextView message = (TextView) getActivity().findViewById(R.id.encryption_message); |
Udam Saini | d553abc | 2016-02-16 17:54:13 -0800 | [diff] [blame] | 138 | message.setText(msgId); |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 139 | |
Maurice Lam | 9be96e0 | 2017-02-23 14:43:48 -0800 | [diff] [blame] | 140 | mRequirePasswordToDecrypt.setOnClickListener(this); |
| 141 | mDontRequirePasswordToDecrypt.setOnClickListener(this); |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 142 | |
Jim Miller | 47adff0 | 2014-10-17 17:43:18 -0700 | [diff] [blame] | 143 | setRequirePasswordState(getActivity().getIntent().getBooleanExtra( |
| 144 | EXTRA_REQUIRE_PASSWORD, true)); |
Udam Saini | edac136 | 2015-12-08 17:28:19 -0800 | [diff] [blame] | 145 | |
Maurice Lam | 9be96e0 | 2017-02-23 14:43:48 -0800 | [diff] [blame] | 146 | GlifLayout layout = (GlifLayout) view; |
Maurice Lam | d189ac5 | 2016-06-15 13:39:34 -0700 | [diff] [blame] | 147 | layout.setHeaderText(getActivity().getTitle()); |
Udam Saini | edac136 | 2015-12-08 17:28:19 -0800 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | protected void startLockIntent() { |
| 151 | if (mUnlockMethodIntent != null) { |
| 152 | mUnlockMethodIntent.putExtra(EXTRA_REQUIRE_PASSWORD, mPasswordRequired); |
| 153 | startActivityForResult(mUnlockMethodIntent, CHOOSE_LOCK_REQUEST); |
| 154 | } else { |
| 155 | Log.wtf(TAG, "no unlock intent to start"); |
| 156 | finish(); |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | @Override |
| 161 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 162 | super.onActivityResult(requestCode, resultCode, data); |
Maurice Lam | e9d2abc | 2015-12-14 18:03:54 -0800 | [diff] [blame] | 163 | if (requestCode == CHOOSE_LOCK_REQUEST && resultCode != RESULT_CANCELED) { |
| 164 | getActivity().setResult(resultCode, data); |
Udam Saini | edac136 | 2015-12-08 17:28:19 -0800 | [diff] [blame] | 165 | finish(); |
| 166 | } |
Jim Miller | 46c7f6d | 2014-10-13 18:15:17 -0700 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | @Override |
Maurice Lam | 9be96e0 | 2017-02-23 14:43:48 -0800 | [diff] [blame] | 170 | public void onClick(View view) { |
| 171 | if (view == mRequirePasswordToDecrypt) { |
Jim Miller | 47adff0 | 2014-10-17 17:43:18 -0700 | [diff] [blame] | 172 | final boolean accEn = AccessibilityManager.getInstance(getActivity()).isEnabled(); |
| 173 | if (accEn && !mPasswordRequired) { |
| 174 | setRequirePasswordState(false); // clear the UI state |
Maurice Lam | 18d7965 | 2017-03-21 17:57:55 -0700 | [diff] [blame] | 175 | AccessibilityWarningDialogFragment.newInstance(mRequestedPasswordQuality) |
| 176 | .show( |
| 177 | getChildFragmentManager(), |
| 178 | AccessibilityWarningDialogFragment.TAG); |
Jim Miller | 47adff0 | 2014-10-17 17:43:18 -0700 | [diff] [blame] | 179 | } else { |
| 180 | setRequirePasswordState(true); |
Udam Saini | d553abc | 2016-02-16 17:54:13 -0800 | [diff] [blame] | 181 | startLockIntent(); |
Jim Miller | 47adff0 | 2014-10-17 17:43:18 -0700 | [diff] [blame] | 182 | } |
| 183 | } else { |
| 184 | setRequirePasswordState(false); |
Udam Saini | d553abc | 2016-02-16 17:54:13 -0800 | [diff] [blame] | 185 | startLockIntent(); |
Jim Miller | 47adff0 | 2014-10-17 17:43:18 -0700 | [diff] [blame] | 186 | } |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Jim Miller | 47adff0 | 2014-10-17 17:43:18 -0700 | [diff] [blame] | 189 | private void setRequirePasswordState(boolean required) { |
| 190 | mPasswordRequired = required; |
Jim Miller | 46c7f6d | 2014-10-13 18:15:17 -0700 | [diff] [blame] | 191 | } |
Jim Miller | 47adff0 | 2014-10-17 17:43:18 -0700 | [diff] [blame] | 192 | |
Maurice Lam | 18d7965 | 2017-03-21 17:57:55 -0700 | [diff] [blame] | 193 | public void finish() { |
| 194 | Activity activity = getActivity(); |
| 195 | if (activity == null) return; |
| 196 | if (getFragmentManager().getBackStackEntryCount() > 0) { |
| 197 | getFragmentManager().popBackStack(); |
| 198 | } else { |
| 199 | activity.finish(); |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | public static class AccessibilityWarningDialogFragment extends InstrumentedDialogFragment |
| 205 | implements DialogInterface.OnClickListener { |
| 206 | |
| 207 | public static final String TAG = "AccessibilityWarningDialog"; |
| 208 | |
| 209 | public static AccessibilityWarningDialogFragment newInstance(int passwordQuality) { |
| 210 | AccessibilityWarningDialogFragment fragment = new AccessibilityWarningDialogFragment(); |
| 211 | Bundle args = new Bundle(1); |
| 212 | args.putInt(EXTRA_PASSWORD_QUALITY, passwordQuality); |
| 213 | fragment.setArguments(args); |
| 214 | return fragment; |
| 215 | } |
| 216 | |
| 217 | @Override |
| 218 | public Dialog onCreateDialog(Bundle savedInstanceState) { |
| 219 | final int titleId; |
| 220 | final int messageId; |
| 221 | switch (getArguments().getInt(EXTRA_PASSWORD_QUALITY)) { |
| 222 | case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING: |
| 223 | titleId = R.string.encrypt_talkback_dialog_require_pattern; |
| 224 | messageId = R.string.encrypt_talkback_dialog_message_pattern; |
| 225 | break; |
| 226 | case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC: |
| 227 | case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX: |
| 228 | titleId = R.string.encrypt_talkback_dialog_require_pin; |
| 229 | messageId = R.string.encrypt_talkback_dialog_message_pin; |
| 230 | break; |
| 231 | default: |
| 232 | titleId = R.string.encrypt_talkback_dialog_require_password; |
| 233 | messageId = R.string.encrypt_talkback_dialog_message_password; |
| 234 | break; |
| 235 | } |
| 236 | |
| 237 | |
| 238 | final Activity activity = getActivity(); |
| 239 | List<AccessibilityServiceInfo> list = |
| 240 | AccessibilityManager.getInstance(activity) |
| 241 | .getEnabledAccessibilityServiceList( |
| 242 | AccessibilityServiceInfo.FEEDBACK_ALL_MASK); |
| 243 | final CharSequence exampleAccessibility; |
| 244 | if (list.isEmpty()) { |
| 245 | // This should never happen. But we shouldn't crash |
| 246 | exampleAccessibility = ""; |
| 247 | } else { |
| 248 | exampleAccessibility = list.get(0).getResolveInfo() |
| 249 | .loadLabel(activity.getPackageManager()); |
| 250 | } |
| 251 | return new AlertDialog.Builder(activity) |
| 252 | .setTitle(titleId) |
| 253 | .setMessage(getString(messageId, exampleAccessibility)) |
| 254 | .setCancelable(true) |
| 255 | .setPositiveButton(android.R.string.ok, this) |
| 256 | .setNegativeButton(android.R.string.cancel, this) |
| 257 | .create(); |
| 258 | } |
| 259 | |
| 260 | @Override |
| 261 | public int getMetricsCategory() { |
| 262 | return MetricsEvent.DIALOG_ENCRYPTION_INTERSTITIAL_ACCESSIBILITY; |
| 263 | } |
| 264 | |
Jim Miller | 47adff0 | 2014-10-17 17:43:18 -0700 | [diff] [blame] | 265 | @Override |
| 266 | public void onClick(DialogInterface dialog, int which) { |
Maurice Lam | 18d7965 | 2017-03-21 17:57:55 -0700 | [diff] [blame] | 267 | EncryptionInterstitialFragment fragment = |
| 268 | (EncryptionInterstitialFragment) getParentFragment(); |
| 269 | if (fragment != null) { |
| 270 | if (which == DialogInterface.BUTTON_POSITIVE) { |
| 271 | fragment.setRequirePasswordState(true); |
| 272 | fragment.startLockIntent(); |
| 273 | } else if (which == DialogInterface.BUTTON_NEGATIVE) { |
| 274 | fragment.setRequirePasswordState(false); |
| 275 | } |
Jim Miller | 47adff0 | 2014-10-17 17:43:18 -0700 | [diff] [blame] | 276 | } |
| 277 | } |
Jim Miller | 46c7f6d | 2014-10-13 18:15:17 -0700 | [diff] [blame] | 278 | } |
| 279 | } |