Merge "[Settings UX] Enlarge data usage clickable area"
diff --git a/res/layout/trusted_credential_list_container.xml b/res/layout/trusted_credential_list_container.xml
index aca0bc8..42dbfd9 100644
--- a/res/layout/trusted_credential_list_container.xml
+++ b/res/layout/trusted_credential_list_container.xml
@@ -16,6 +16,8 @@
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
               android:layout_width="match_parent"
               android:layout_height="match_parent"
+              android:clipToPadding="true"
+              android:clipChildren="true"
               android:orientation="vertical">
     <LinearLayout
         android:id="@+id/header_view"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 53f96a0..a730aa1 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -4048,14 +4048,6 @@
     <!-- About phone settings screen, Safety Legal dialog title until the link is fully loaded -->
     <string name="settings_safetylegal_activity_loading">Loading\u2026</string>
 
-    <!-- ConfirmDeviceCredential settings-->
-    <!-- Button text shown on BiometricPrompt (system dialog that asks for biometric authentication) giving the user the option to use an alternate form of authentication (Pin) [CHAR LIMIT=30] -->
-    <string name="confirm_device_credential_pin">Use PIN</string>
-    <!-- Button text shown on BiometricPrompt (system dialog that asks for biometric authentication) giving the user the option to use an alternate form of authentication (Pattern) [CHAR LIMIT=30] -->
-    <string name="confirm_device_credential_pattern">Use pattern</string>
-    <!-- Button text shown on BiometricPrompt (system dialog that asks for biometric authentication) giving the user the option to use an alternate form of authentication (Pass) [CHAR LIMIT=30] -->
-    <string name="confirm_device_credential_password">Use password</string>
-
     <!-- Lock Pattern settings -->
     <!-- Header on first screen of choose password/PIN flow [CHAR LIMIT=40] -->
     <string name="lockpassword_choose_your_screen_lock_header">Set screen lock</string>
diff --git a/res/xml/firmware_version.xml b/res/xml/firmware_version.xml
index f55ee11..443ae35 100644
--- a/res/xml/firmware_version.xml
+++ b/res/xml/firmware_version.xml
@@ -27,6 +27,7 @@
         android:key="os_firmware_version"
         android:title="@string/firmware_version"
         android:summary="@string/summary_placeholder"
+        android:selectable="false"
         settings:enableCopying="true"
         settings:controller="com.android.settings.deviceinfo.firmwareversion.FirmwareVersionDetailPreferenceController"/>
 
@@ -42,6 +43,7 @@
         android:key="module_version"
         android:title="@string/module_version"
         android:summary="@string/summary_placeholder"
+        android:selectable="false"
         settings:enableCopying="true"
         settings:controller="com.android.settings.deviceinfo.firmwareversion.MainlineModuleVersionPreferenceController"/>
 
@@ -50,6 +52,7 @@
         android:key="base_band"
         android:title="@string/baseband_version"
         android:summary="@string/summary_placeholder"
+        android:selectable="false"
         settings:enableCopying="true"
         settings:controller="com.android.settings.deviceinfo.firmwareversion.BasebandVersionPreferenceController"/>
 
@@ -58,6 +61,7 @@
         android:key="kernel_version"
         android:title="@string/kernel_version"
         android:summary="@string/summary_placeholder"
+        android:selectable="false"
         settings:enableCopying="true"
         settings:controller="com.android.settings.deviceinfo.firmwareversion.KernelVersionPreferenceController"/>
 
@@ -66,7 +70,8 @@
         android:key="os_build_number"
         android:title="@string/build_number"
         android:summary="@string/summary_placeholder"
+        android:selectable="false"
         settings:enableCopying="true"
         settings:controller="com.android.settings.deviceinfo.firmwareversion.SimpleBuildNumberPreferenceController"/>
 
-</PreferenceScreen>
\ No newline at end of file
+</PreferenceScreen>
diff --git a/src/com/android/settings/password/BiometricFragment.java b/src/com/android/settings/password/BiometricFragment.java
index 66b665b..9898719 100644
--- a/src/com/android/settings/password/BiometricFragment.java
+++ b/src/com/android/settings/password/BiometricFragment.java
@@ -24,7 +24,6 @@
 import android.hardware.biometrics.BiometricPrompt;
 import android.hardware.biometrics.BiometricPrompt.AuthenticationCallback;
 import android.hardware.biometrics.BiometricPrompt.AuthenticationResult;
-import android.hardware.biometrics.IBiometricConfirmDeviceCredentialCallback;
 import android.os.Bundle;
 import android.os.CancellationSignal;
 import android.os.Handler;
@@ -91,20 +90,6 @@
         }
     };
 
-    // TODO(b/123378871): Remove when moved.
-    private final IBiometricConfirmDeviceCredentialCallback mCancelCallback
-        = new IBiometricConfirmDeviceCredentialCallback.Stub() {
-        @Override
-        public void cancel() {
-            final Activity activity = getActivity();
-            if (activity != null) {
-                activity.finish();
-            } else {
-                Log.e(TAG, "Activity null!");
-            }
-        }
-    };
-
     /**
      * @param bundle Bundle passed from {@link BiometricPrompt.Builder#buildIntent()}
      * @return
@@ -150,46 +135,19 @@
         final BiometricPrompt.Builder builder = new BiometricPrompt.Builder(getContext())
                 .setTitle(mBundle.getString(BiometricPrompt.KEY_TITLE))
                 .setUseDefaultTitle() // use default title if title is null/empty
-                .setFromConfirmDeviceCredential()
+                .setDeviceCredentialAllowed(true)
                 .setSubtitle(mBundle.getString(BiometricPrompt.KEY_SUBTITLE))
                 .setDescription(mBundle.getString(BiometricPrompt.KEY_DESCRIPTION))
                 .setConfirmationRequired(
                         mBundle.getBoolean(BiometricPrompt.KEY_REQUIRE_CONFIRMATION, true));
 
-        final LockPatternUtils lockPatternUtils = FeatureFactory.getFactory(
-                getContext())
-                .getSecurityFeatureProvider()
-                .getLockPatternUtils(getContext());
-
-        switch (lockPatternUtils.getKeyguardStoredPasswordQuality(mUserId)) {
-            case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
-                builder.setNegativeButton(getResources().getString(
-                        R.string.confirm_device_credential_pattern),
-                        mClientExecutor, mNegativeButtonListener);
-                break;
-            case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
-            case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX:
-                builder.setNegativeButton(getResources().getString(
-                        R.string.confirm_device_credential_pin),
-                        mClientExecutor, mNegativeButtonListener);
-                break;
-            case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
-            case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
-            case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX:
-            case DevicePolicyManager.PASSWORD_QUALITY_MANAGED:
-                builder.setNegativeButton(getResources().getString(
-                        R.string.confirm_device_credential_password),
-                        mClientExecutor, mNegativeButtonListener);
-                break;
-        }
-
         mBiometricPrompt = builder.build();
         mCancellationSignal = new CancellationSignal();
 
         // TODO: CC doesn't use crypto for now
         mAuthenticating = true;
         mBiometricPrompt.authenticateUser(mCancellationSignal, mClientExecutor,
-                mAuthenticationCallback, mUserId, mCancelCallback);
+                mAuthenticationCallback, mUserId);
     }
 
     @Override
diff --git a/src/com/android/settings/password/ChooseLockGeneric.java b/src/com/android/settings/password/ChooseLockGeneric.java
index 4e2e90d..f86292b 100644
--- a/src/com/android/settings/password/ChooseLockGeneric.java
+++ b/src/com/android/settings/password/ChooseLockGeneric.java
@@ -725,30 +725,6 @@
         }
 
         /**
-         * Keeps track of the biometric removal status. When all biometrics (including managed
-         * profiles) are removed, finishes the activity. Otherwise, it's possible the UI still
-         * shows enrolled biometrics due to the async remove.
-         */
-        private class RemovalTracker {
-            boolean mFingerprintDone;
-            boolean mFaceDone;
-
-            void onFingerprintDone() {
-                mFingerprintDone = true;
-                if (mFingerprintDone && mFaceDone) {
-                    finish();
-                }
-            }
-
-            void onFaceDone() {
-                mFaceDone = true;
-                if (mFingerprintDone && mFaceDone) {
-                    finish();
-                }
-            }
-        }
-
-        /**
          * Invokes an activity to change the user's pattern, password or PIN based on given quality
          * and minimum quality specified by DevicePolicyManager. If quality is
          * {@link DevicePolicyManager#PASSWORD_QUALITY_UNSPECIFIED}, password is cleared.
@@ -781,21 +757,15 @@
             }
 
             if (quality == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
+                // Clearing of user biometrics when screen lock is cleared is done at
+                // LockSettingsService.removeBiometricsForUser().
                 mChooseLockSettingsHelper.utils().clearLock(mUserPassword, mUserId);
                 mChooseLockSettingsHelper.utils().setLockScreenDisabled(disabled, mUserId);
                 getActivity().setResult(Activity.RESULT_OK);
-                removeAllBiometricsForUserAndFinish(mUserId);
-            } else {
-                removeAllBiometricsForUserAndFinish(mUserId);
+                finish();
             }
         }
 
-        private void removeAllBiometricsForUserAndFinish(final int userId) {
-            final RemovalTracker tracker = new RemovalTracker();
-            removeAllFingerprintForUserAndFinish(userId, tracker);
-            removeAllFaceForUserAndFinish(userId, tracker);
-        }
-
         private Intent getIntentForUnlockMethod(int quality) {
             Intent intent = null;
             if (quality >= DevicePolicyManager.PASSWORD_QUALITY_MANAGED) {
@@ -808,128 +778,6 @@
             return intent;
         }
 
-        private void removeAllFingerprintForUserAndFinish(final int userId,
-                RemovalTracker tracker) {
-            if (mFingerprintManager != null && mFingerprintManager.isHardwareDetected()) {
-                if (mFingerprintManager.hasEnrolledFingerprints(userId)) {
-                    mFingerprintManager.setActiveUser(userId);
-                    // For the purposes of M and N, groupId is the same as userId.
-                    final int groupId = userId;
-                    Fingerprint finger = new Fingerprint(null, groupId, 0, 0);
-                    mFingerprintManager.remove(finger, userId,
-                            new RemovalCallback() {
-                                @Override
-                                public void onRemovalError(Fingerprint fp, int errMsgId,
-                                        CharSequence errString) {
-                                    Log.e(TAG, String.format(
-                                            "Can't remove fingerprint %d in group %d. Reason: %s",
-                                            fp.getBiometricId(), fp.getGroupId(), errString));
-                                    // TODO: need to proceed with the removal of managed profile
-                                    // fingerprints and finish() gracefully.
-                                }
-
-                                @Override
-                                public void onRemovalSucceeded(Fingerprint fp, int remaining) {
-                                    if (remaining == 0) {
-                                        removeManagedProfileFingerprintsAndFinishIfNecessary(userId,
-                                                tracker);
-                                    }
-                                }
-                            });
-                } else {
-                    // No fingerprints in this user, we may also want to delete managed profile
-                    // fingerprints
-                    removeManagedProfileFingerprintsAndFinishIfNecessary(userId, tracker);
-                }
-            } else {
-                // The removal callback will call finish, once all fingerprints are removed.
-                // We need to wait for that to occur, otherwise, the UI will still show that
-                // fingerprints exist even though they are (about to) be removed depending on
-                // the race condition.
-                tracker.onFingerprintDone();
-            }
-        }
-
-        private void removeManagedProfileFingerprintsAndFinishIfNecessary(final int parentUserId,
-                RemovalTracker tracker) {
-            if (mFingerprintManager != null && mFingerprintManager.isHardwareDetected()) {
-                mFingerprintManager.setActiveUser(UserHandle.myUserId());
-            }
-            boolean hasChildProfile = false;
-            if (!mUserManager.getUserInfo(parentUserId).isManagedProfile()) {
-                // Current user is primary profile, remove work profile fingerprints if necessary
-                final List<UserInfo> profiles = mUserManager.getProfiles(parentUserId);
-                final int profilesSize = profiles.size();
-                for (int i = 0; i < profilesSize; i++) {
-                    final UserInfo userInfo = profiles.get(i);
-                    if (userInfo.isManagedProfile() && !mLockPatternUtils
-                            .isSeparateProfileChallengeEnabled(userInfo.id)) {
-                        removeAllFingerprintForUserAndFinish(userInfo.id, tracker);
-                        hasChildProfile = true;
-                        break;
-                    }
-                }
-            }
-            if (!hasChildProfile) {
-                tracker.onFingerprintDone();
-            }
-        }
-
-        // TODO: figure out how to eliminate duplicated code. It's a bit hard due to the async-ness
-        private void removeAllFaceForUserAndFinish(final int userId, RemovalTracker tracker) {
-            if (mFaceManager != null && mFaceManager.isHardwareDetected()) {
-                if (mFaceManager.hasEnrolledTemplates(userId)) {
-                    mFaceManager.setActiveUser(userId);
-                    Face face = new Face(null, 0, 0);
-                    mFaceManager.remove(face, userId,
-                            new FaceManager.RemovalCallback() {
-                        @Override
-                        public void onRemovalError(Face face, int errMsgId, CharSequence err) {
-                            Log.e(TAG, String.format("Can't remove face %d. Reason: %s",
-                                    face.getBiometricId(), err));
-                        }
-                        @Override
-                        public void onRemovalSucceeded(Face face, int remaining) {
-                            if (remaining == 0) {
-                                removeManagedProfileFacesAndFinishIfNecessary(userId, tracker);
-                            }
-                        }
-                    });
-                } else {
-                    // No faces in this user, we may also want to delete managed profile faces
-                    removeManagedProfileFacesAndFinishIfNecessary(userId, tracker);
-                }
-            } else {
-                tracker.onFaceDone();
-            }
-        }
-
-        // TODO: figure out how to eliminate duplicated code. It's a bit hard due to the async-ness
-        private void removeManagedProfileFacesAndFinishIfNecessary(final int parentUserId,
-                RemovalTracker tracker) {
-            if (mFaceManager != null && mFaceManager.isHardwareDetected()) {
-                mFaceManager.setActiveUser(UserHandle.myUserId());
-            }
-            boolean hasChildProfile = false;
-            if (!mUserManager.getUserInfo(parentUserId).isManagedProfile()) {
-                // Current user is primary profile, remove work profile faces if necessary
-                final List<UserInfo> profiles = mUserManager.getProfiles(parentUserId);
-                final int profilesSize = profiles.size();
-                for (int i = 0; i < profilesSize; i++) {
-                    final UserInfo userInfo = profiles.get(i);
-                    if (userInfo.isManagedProfile() && !mLockPatternUtils
-                            .isSeparateProfileChallengeEnabled(userInfo.id)) {
-                        removeAllFaceForUserAndFinish(userInfo.id, tracker);
-                        hasChildProfile = true;
-                        break;
-                    }
-                }
-            }
-            if (!hasChildProfile) {
-                tracker.onFaceDone();
-            }
-        }
-
         @Override
         public void onDestroy() {
             super.onDestroy();
diff --git a/src/com/android/settings/password/ConfirmDeviceCredentialActivity.java b/src/com/android/settings/password/ConfirmDeviceCredentialActivity.java
index 8476f92..1da2a63 100644
--- a/src/com/android/settings/password/ConfirmDeviceCredentialActivity.java
+++ b/src/com/android/settings/password/ConfirmDeviceCredentialActivity.java
@@ -90,8 +90,6 @@
     private TrustManager mTrustManager;
     private ChooseLockSettingsHelper mChooseLockSettingsHelper;
     private Handler mHandler = new Handler(Looper.getMainLooper());
-    private boolean mIsFallback; // BiometricPrompt fallback
-    private boolean mCCLaunched;
 
     private String mTitle;
     private String mDetails;
@@ -108,10 +106,6 @@
             if (!mGoingToBackground) {
                 if (errorCode == BiometricPrompt.BIOMETRIC_ERROR_USER_CANCELED
                         || errorCode == BiometricPrompt.BIOMETRIC_ERROR_CANCELED) {
-                    if (mIsFallback) {
-                        mBiometricManager.onConfirmDeviceCredentialError(
-                                errorCode, getStringForError(errorCode));
-                    }
                     finish();
                 } else {
                     // All other errors go to some version of CC
@@ -128,10 +122,6 @@
             ConfirmDeviceCredentialUtils.checkForPendingIntent(
                     ConfirmDeviceCredentialActivity.this);
 
-            if (mIsFallback) {
-                mBiometricManager.onConfirmDeviceCredentialSuccess();
-            }
-
             setResult(Activity.RESULT_OK);
             finish();
         }
@@ -183,17 +173,11 @@
         mChooseLockSettingsHelper = new ChooseLockSettingsHelper(this);
         final LockPatternUtils lockPatternUtils = new LockPatternUtils(this);
 
-        Bundle bpBundle =
-                intent.getBundleExtra(KeyguardManager.EXTRA_BIOMETRIC_PROMPT_BUNDLE);
-        if (bpBundle != null) {
-            mIsFallback = true;
-            mTitle = bpBundle.getString(BiometricPrompt.KEY_TITLE);
-            mDetails = bpBundle.getString(BiometricPrompt.KEY_SUBTITLE);
-        } else {
-            bpBundle = new Bundle();
-            bpBundle.putString(BiometricPrompt.KEY_TITLE, mTitle);
-            bpBundle.putString(BiometricPrompt.KEY_DESCRIPTION, mDetails);
-        }
+        final Bundle bpBundle = new Bundle();
+        mTitle = bpBundle.getString(BiometricPrompt.KEY_TITLE);
+        mDetails = bpBundle.getString(BiometricPrompt.KEY_SUBTITLE);
+        bpBundle.putString(BiometricPrompt.KEY_TITLE, mTitle);
+        bpBundle.putString(BiometricPrompt.KEY_DESCRIPTION, mDetails);
 
         boolean launchedBiometric = false;
         boolean launchedCDC = false;
@@ -257,12 +241,6 @@
                 }
             }
 
-            if (mIsFallback && !mCCLaunched) {
-                mBiometricManager.onConfirmDeviceCredentialError(
-                        BiometricConstants.BIOMETRIC_ERROR_CANCELED,
-                        getString(com.android.internal.R.string.biometric_error_user_canceled));
-            }
-
             finish();
         } else {
             mGoingToBackground = false;
@@ -314,7 +292,6 @@
      * Shows ConfirmDeviceCredentials for normal apps.
      */
     private void showConfirmCredentials() {
-        mCCLaunched = true;
         boolean launched = false;
         // The only difference between CREDENTIAL_MANAGED and CREDENTIAL_NORMAL is that for
         // CREDENTIAL_MANAGED, we launch the real confirm credential activity with an explicit
diff --git a/src/com/android/settings/password/ConfirmDeviceCredentialBaseActivity.java b/src/com/android/settings/password/ConfirmDeviceCredentialBaseActivity.java
index 5407776..a30d2e1 100644
--- a/src/com/android/settings/password/ConfirmDeviceCredentialBaseActivity.java
+++ b/src/com/android/settings/password/ConfirmDeviceCredentialBaseActivity.java
@@ -17,15 +17,12 @@
 package com.android.settings.password;
 
 import android.app.KeyguardManager;
-import android.hardware.biometrics.BiometricConstants;
 import android.hardware.biometrics.BiometricManager;
-import android.hardware.biometrics.IBiometricConfirmDeviceCredentialCallback;
 import android.os.Bundle;
 import android.os.UserManager;
 import android.util.Log;
 import android.view.MenuItem;
 import android.view.WindowManager;
-import android.widget.LinearLayout;
 
 import androidx.fragment.app.Fragment;
 
@@ -50,16 +47,6 @@
     private boolean mFirstTimeVisible = true;
     private boolean mIsKeyguardLocked = false;
     private ConfirmCredentialTheme mConfirmCredentialTheme;
-    private BiometricManager mBiometricManager;
-
-    // TODO(b/123378871): Remove when moved.
-    private final IBiometricConfirmDeviceCredentialCallback mCancelCallback
-            = new IBiometricConfirmDeviceCredentialCallback.Stub() {
-        @Override
-        public void cancel() {
-            finish();
-        }
-    };
 
     private boolean isInternalActivity() {
         return (this instanceof ConfirmLockPassword.InternalActivity)
@@ -90,9 +77,6 @@
         }
         super.onCreate(savedState);
 
-        mBiometricManager = getSystemService(BiometricManager.class);
-        mBiometricManager.registerCancellationCallback(mCancelCallback);
-
         if (mConfirmCredentialTheme == ConfirmCredentialTheme.NORMAL) {
             // Prevent the content parent from consuming the window insets because GlifLayout uses
             // it to show the status bar background.
@@ -167,15 +151,10 @@
     @Override
     public void onStop() {
         super.onStop();
-        // TODO(b/123378871): Remove when moved.
-        if (!isChangingConfigurations()) {
-            mBiometricManager.onConfirmDeviceCredentialError(
-                    BiometricConstants.BIOMETRIC_ERROR_USER_CANCELED,
-                    getString(com.android.internal.R.string.biometric_error_user_canceled));
-            if (getIntent().getBooleanExtra(
-                    ChooseLockSettingsHelper.EXTRA_KEY_FOREGROUND_ONLY, false)) {
-                finish();
-            }
+        final boolean foregroundOnly = getIntent().getBooleanExtra(
+                ChooseLockSettingsHelper.EXTRA_KEY_FOREGROUND_ONLY, false);
+        if (!isChangingConfigurations() && foregroundOnly) {
+            finish();
         }
     }
 
diff --git a/src/com/android/settings/password/ConfirmLockPassword.java b/src/com/android/settings/password/ConfirmLockPassword.java
index 12b2724..5c891cd 100644
--- a/src/com/android/settings/password/ConfirmLockPassword.java
+++ b/src/com/android/settings/password/ConfirmLockPassword.java
@@ -446,7 +446,6 @@
                     ConfirmDeviceCredentialUtils.reportSuccessfulAttempt(mLockPatternUtils,
                             mUserManager, mEffectiveUserId);
                 }
-                mBiometricManager.onConfirmDeviceCredentialSuccess();
                 startDisappearAnimation(intent);
                 ConfirmDeviceCredentialUtils.checkForPendingIntent(getActivity());
             } else {
diff --git a/src/com/android/settings/password/ConfirmLockPattern.java b/src/com/android/settings/password/ConfirmLockPattern.java
index f43ee7f..b1d8e60 100644
--- a/src/com/android/settings/password/ConfirmLockPattern.java
+++ b/src/com/android/settings/password/ConfirmLockPattern.java
@@ -490,7 +490,6 @@
                     ConfirmDeviceCredentialUtils.reportSuccessfulAttempt(mLockPatternUtils,
                             mUserManager, mEffectiveUserId);
                 }
-                mBiometricManager.onConfirmDeviceCredentialSuccess();
                 startDisappearAnimation(intent);
                 ConfirmDeviceCredentialUtils.checkForPendingIntent(getActivity());
             } else {