Use updated lockscreen validation API in Settings.

Test: manual
Test: m RunSettingsRoboTests -j ROBOTEST_FILTER=com.android.settings.password
Bug: 269256333
Change-Id: I660dea98eace96ed241b0a90f12ddeb742381dc0
diff --git a/src/com/android/settings/password/ChooseLockSettingsHelper.java b/src/com/android/settings/password/ChooseLockSettingsHelper.java
index a1cd09f..020b725 100644
--- a/src/com/android/settings/password/ChooseLockSettingsHelper.java
+++ b/src/com/android/settings/password/ChooseLockSettingsHelper.java
@@ -22,7 +22,7 @@
 import android.annotation.Nullable;
 import android.app.Activity;
 import android.app.KeyguardManager;
-import android.app.StartLockscreenValidationRequest;
+import android.app.RemoteLockscreenValidationSession;
 import android.app.admin.DevicePolicyManager;
 import android.content.ComponentName;
 import android.content.Intent;
@@ -145,7 +145,7 @@
         private boolean mAllowAnyUserId;
         private boolean mForceVerifyPath;
         private boolean mRemoteLockscreenValidation;
-        @Nullable private StartLockscreenValidationRequest mStartLockscreenValidationRequest;
+        @Nullable private RemoteLockscreenValidationSession mRemoteLockscreenValidationSession;
         @Nullable private ComponentName mRemoteLockscreenValidationServiceComponent;
         boolean mRequestGatekeeperPasswordHandle;
 
@@ -272,7 +272,7 @@
 
         /**
          * @param isRemoteLockscreenValidation if true, remote device validation flow will be
-         *                                 started. {@link #setStartLockscreenValidationRequest} and
+         *                                 started. {@link #setRemoteLockscreenValidationSession},
          *                                 {@link #setRemoteLockscreenValidationServiceComponent}
          *                                 must also be used to set the required data.
          */
@@ -283,14 +283,14 @@
         }
 
         /**
-         * @param startLockScreenValidationRequest contains information necessary to perform remote
+         * @param remoteLockscreenValidationSession contains information necessary to perform remote
          *                                         lockscreen validation such as the remote device's
          *                                         lockscreen type, public key to be used for
          *                                         encryption, and remaining attempts.
          */
-        @NonNull public Builder setStartLockscreenValidationRequest(
-                StartLockscreenValidationRequest startLockScreenValidationRequest) {
-            mStartLockscreenValidationRequest = startLockScreenValidationRequest;
+        @NonNull public Builder setRemoteLockscreenValidationSession(
+                RemoteLockscreenValidationSession remoteLockscreenValidationSession) {
+            mRemoteLockscreenValidationSession = remoteLockscreenValidationSession;
             return this;
         }
 
@@ -369,7 +369,7 @@
                 mBuilder.mDescription, mBuilder.mReturnCredentials, mBuilder.mExternal,
                 mBuilder.mForceVerifyPath, mBuilder.mUserId, mBuilder.mAlternateButton,
                 mBuilder.mCheckBoxLabel, mBuilder.mRemoteLockscreenValidation,
-                mBuilder.mStartLockscreenValidationRequest,
+                mBuilder.mRemoteLockscreenValidationSession,
                 mBuilder.mRemoteLockscreenValidationServiceComponent, mBuilder.mAllowAnyUserId,
                 mBuilder.mForegroundOnly, mBuilder.mRequestGatekeeperPasswordHandle);
     }
@@ -379,18 +379,18 @@
             boolean returnCredentials, boolean external, boolean forceVerifyPath,
             int userId, @Nullable CharSequence alternateButton,
             @Nullable CharSequence checkboxLabel, boolean remoteLockscreenValidation,
-            @Nullable StartLockscreenValidationRequest startLockScreenValidationRequest,
+            @Nullable RemoteLockscreenValidationSession remoteLockscreenValidationSession,
             @Nullable ComponentName remoteLockscreenValidationServiceComponent,
             boolean allowAnyUser, boolean foregroundOnly, boolean requestGatekeeperPasswordHandle) {
         Optional<Class<?>> activityClass = determineAppropriateActivityClass(
-                returnCredentials, forceVerifyPath, userId, startLockScreenValidationRequest);
+                returnCredentials, forceVerifyPath, userId, remoteLockscreenValidationSession);
         if (activityClass.isEmpty()) {
             return false;
         }
 
         return launchConfirmationActivity(request, title, header, description, activityClass.get(),
                 returnCredentials, external, forceVerifyPath, userId, alternateButton,
-                checkboxLabel, remoteLockscreenValidation, startLockScreenValidationRequest,
+                checkboxLabel, remoteLockscreenValidation, remoteLockscreenValidationSession,
                 remoteLockscreenValidationServiceComponent, allowAnyUser, foregroundOnly,
                 requestGatekeeperPasswordHandle);
     }
@@ -400,7 +400,7 @@
             boolean external, boolean forceVerifyPath, int userId,
             @Nullable CharSequence alternateButton, @Nullable CharSequence checkbox,
             boolean remoteLockscreenValidation,
-            @Nullable StartLockscreenValidationRequest startLockScreenValidationRequest,
+            @Nullable RemoteLockscreenValidationSession remoteLockscreenValidationSession,
             @Nullable ComponentName remoteLockscreenValidationServiceComponent,
             boolean allowAnyUser, boolean foregroundOnly, boolean requestGatekeeperPasswordHandle) {
         final Intent intent = new Intent();
@@ -419,8 +419,8 @@
         intent.putExtra(Intent.EXTRA_USER_ID, userId);
         intent.putExtra(KeyguardManager.EXTRA_ALTERNATE_BUTTON_LABEL, alternateButton);
         intent.putExtra(KeyguardManager.EXTRA_CHECKBOX_LABEL, checkbox);
-        intent.putExtra(KeyguardManager.EXTRA_START_LOCKSCREEN_VALIDATION_REQUEST,
-                startLockScreenValidationRequest);
+        intent.putExtra(KeyguardManager.EXTRA_REMOTE_LOCKSCREEN_VALIDATION_SESSION,
+                remoteLockscreenValidationSession);
         intent.putExtra(Intent.EXTRA_COMPONENT_NAME, remoteLockscreenValidationServiceComponent);
         intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOREGROUND_ONLY, foregroundOnly);
         intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_ALLOW_ANY_USER, allowAnyUser);
@@ -477,10 +477,10 @@
 
     private Optional<Class<?>> determineAppropriateActivityClass(boolean returnCredentials,
             boolean forceVerifyPath, int userId,
-            @Nullable StartLockscreenValidationRequest startLockscreenValidationRequest) {
+            @Nullable RemoteLockscreenValidationSession remoteLockscreenValidationSession) {
         int lockType;
-        if (startLockscreenValidationRequest != null) {
-            lockType = startLockscreenValidationRequest.getLockscreenUiType();
+        if (remoteLockscreenValidationSession != null) {
+            lockType = remoteLockscreenValidationSession.getLockType();
         } else {
             final int effectiveUserId = UserManager
                     .get(mActivity).getCredentialOwnerProfile(userId);
diff --git a/src/com/android/settings/password/ConfirmDeviceCredentialActivity.java b/src/com/android/settings/password/ConfirmDeviceCredentialActivity.java
index 31d9c74..328e440 100644
--- a/src/com/android/settings/password/ConfirmDeviceCredentialActivity.java
+++ b/src/com/android/settings/password/ConfirmDeviceCredentialActivity.java
@@ -28,7 +28,7 @@
 
 import android.app.Activity;
 import android.app.KeyguardManager;
-import android.app.StartLockscreenValidationRequest;
+import android.app.RemoteLockscreenValidationSession;
 import android.app.admin.DevicePolicyManager;
 import android.app.trust.TrustManager;
 import android.content.ComponentName;
@@ -235,10 +235,10 @@
                     .setUserId(LockPatternUtils.USER_FRP)
                     .show();
         } else if (remoteValidation) {
-            StartLockscreenValidationRequest startLockScreenValidationRequest =
+            RemoteLockscreenValidationSession remoteLockscreenValidationSession =
                     intent.getParcelableExtra(
-                            KeyguardManager.EXTRA_START_LOCKSCREEN_VALIDATION_REQUEST,
-                            StartLockscreenValidationRequest.class);
+                            KeyguardManager.EXTRA_REMOTE_LOCKSCREEN_VALIDATION_SESSION,
+                            RemoteLockscreenValidationSession.class);
             ComponentName remoteLockscreenValidationServiceComponent =
                     intent.getParcelableExtra(Intent.EXTRA_COMPONENT_NAME, ComponentName.class);
 
@@ -247,7 +247,7 @@
                     new ChooseLockSettingsHelper.Builder(this);
             launchedCDC = builder
                     .setRemoteLockscreenValidation(true)
-                    .setStartLockscreenValidationRequest(startLockScreenValidationRequest)
+                    .setRemoteLockscreenValidationSession(remoteLockscreenValidationSession)
                     .setRemoteLockscreenValidationServiceComponent(
                             remoteLockscreenValidationServiceComponent)
                     .setHeader(mTitle) // Show the title in the header location
diff --git a/src/com/android/settings/password/ConfirmDeviceCredentialBaseFragment.java b/src/com/android/settings/password/ConfirmDeviceCredentialBaseFragment.java
index 7c3df61..1bb6df0 100644
--- a/src/com/android/settings/password/ConfirmDeviceCredentialBaseFragment.java
+++ b/src/com/android/settings/password/ConfirmDeviceCredentialBaseFragment.java
@@ -25,7 +25,7 @@
 import android.app.Dialog;
 import android.app.KeyguardManager;
 import android.app.RemoteLockscreenValidationResult;
-import android.app.StartLockscreenValidationRequest;
+import android.app.RemoteLockscreenValidationSession;
 import android.app.admin.DevicePolicyManager;
 import android.app.admin.ManagedSubscriptionsPolicy;
 import android.content.ComponentName;
@@ -107,7 +107,7 @@
     protected boolean mRemoteValidation;
     protected CharSequence mAlternateButtonText;
     protected BiometricManager mBiometricManager;
-    @Nullable protected StartLockscreenValidationRequest mStartLockscreenValidationRequest;
+    @Nullable protected RemoteLockscreenValidationSession mRemoteLockscreenValidationSession;
     /** Credential saved so the credential can be set for device if remote validation passes */
     @Nullable protected LockscreenCredential mDeviceCredentialGuess;
     @Nullable protected RemoteLockscreenValidationClient mRemoteLockscreenValidationClient;
@@ -141,12 +141,12 @@
             }
         }
         if (mRemoteValidation) {
-            mStartLockscreenValidationRequest = intent.getParcelableExtra(
-                    KeyguardManager.EXTRA_START_LOCKSCREEN_VALIDATION_REQUEST,
-                    StartLockscreenValidationRequest.class);
-            if (mStartLockscreenValidationRequest == null
-                    || mStartLockscreenValidationRequest.getRemainingAttempts() == 0) {
-                Log.e(TAG, "StartLockscreenValidationRequest is null or "
+            mRemoteLockscreenValidationSession = intent.getParcelableExtra(
+                    KeyguardManager.EXTRA_REMOTE_LOCKSCREEN_VALIDATION_SESSION,
+                    RemoteLockscreenValidationSession.class);
+            if (mRemoteLockscreenValidationSession == null
+                    || mRemoteLockscreenValidationSession.getRemainingAttempts() == 0) {
+                Log.e(TAG, "RemoteLockscreenValidationSession is null or "
                         + "no more attempts for remote lockscreen validation.");
                 getActivity().finish();
             }
@@ -437,7 +437,7 @@
 
     private byte[] encryptDeviceCredentialGuess(byte[] guess) {
         try {
-            byte[] encodedPublicKey = mStartLockscreenValidationRequest.getSourcePublicKey();
+            byte[] encodedPublicKey = mRemoteLockscreenValidationSession.getSourcePublicKey();
             PublicKey publicKey = SecureBox.decodePublicKey(encodedPublicKey);
             return SecureBox.encrypt(
                     publicKey,
diff --git a/src/com/android/settings/password/ConfirmLockPassword.java b/src/com/android/settings/password/ConfirmLockPassword.java
index 83dc85c..427b4ff 100644
--- a/src/com/android/settings/password/ConfirmLockPassword.java
+++ b/src/com/android/settings/password/ConfirmLockPassword.java
@@ -166,7 +166,7 @@
             mErrorTextView = (TextView) view.findViewById(R.id.errorText);
 
             if (mRemoteValidation) {
-                mIsAlpha = mStartLockscreenValidationRequest.getLockscreenUiType()
+                mIsAlpha = mRemoteLockscreenValidationSession.getLockType()
                         == KeyguardManager.PASSWORD;
                 // ProgressBar visibility is set to GONE until interacted with.
                 // Set progress bar to INVISIBLE, so the EditText does not get bumped down later.
@@ -633,6 +633,9 @@
                     break;
                 case RemoteLockscreenValidationResult.RESULT_NO_REMAINING_ATTEMPTS:
                     getActivity().finish();
+                    break;
+                case RemoteLockscreenValidationResult.RESULT_SESSION_EXPIRED:
+                    getActivity().finish();
             }
             mGlifLayout.setProgressBarShown(false);
         }
diff --git a/src/com/android/settings/password/ConfirmLockPattern.java b/src/com/android/settings/password/ConfirmLockPattern.java
index 0013d7a..c664daf 100644
--- a/src/com/android/settings/password/ConfirmLockPattern.java
+++ b/src/com/android/settings/password/ConfirmLockPattern.java
@@ -646,6 +646,9 @@
                     break;
                 case RemoteLockscreenValidationResult.RESULT_NO_REMAINING_ATTEMPTS:
                     getActivity().finish();
+                    break;
+                case RemoteLockscreenValidationResult.RESULT_SESSION_EXPIRED:
+                    getActivity().finish();
             }
             mGlifLayout.setProgressBarShown(false);
         }
diff --git a/tests/robotests/src/com/android/settings/password/ChooseLockSettingsHelperTest.java b/tests/robotests/src/com/android/settings/password/ChooseLockSettingsHelperTest.java
index 2777529..fcab797 100644
--- a/tests/robotests/src/com/android/settings/password/ChooseLockSettingsHelperTest.java
+++ b/tests/robotests/src/com/android/settings/password/ChooseLockSettingsHelperTest.java
@@ -2,7 +2,7 @@
 
 import static com.android.settings.password.TestUtils.COMPONENT_NAME;
 import static com.android.settings.password.TestUtils.VALID_REMAINING_ATTEMPTS;
-import static com.android.settings.password.TestUtils.createStartLockscreenValidationRequest;
+import static com.android.settings.password.TestUtils.createRemoteLockscreenValidationSession;
 
 import static com.google.common.truth.Truth.assertThat;
 
@@ -15,7 +15,7 @@
 
 import android.app.Activity;
 import android.app.KeyguardManager;
-import android.app.StartLockscreenValidationRequest;
+import android.app.RemoteLockscreenValidationSession;
 import android.app.admin.DevicePolicyManager;
 import android.content.ComponentName;
 import android.content.Intent;
@@ -170,13 +170,13 @@
     public void launchConfirmPassword_remoteValidation_passwordLockType() throws Exception {
         Activity activity = Robolectric.setupActivity(Activity.class);
         ShadowActivity shadowActivity = Shadows.shadowOf(activity);
-        StartLockscreenValidationRequest request = createStartLockscreenValidationRequest(
+        RemoteLockscreenValidationSession request = createRemoteLockscreenValidationSession(
                 KeyguardManager.PASSWORD, VALID_REMAINING_ATTEMPTS);
 
         ChooseLockSettingsHelper chooseLockSettingsHelper = getChooseLockSettingsHelper(
                 new ChooseLockSettingsHelper.Builder(activity)
                         .setRemoteLockscreenValidation(true)
-                        .setStartLockscreenValidationRequest(request)
+                        .setRemoteLockscreenValidationSession(request)
                         .setRemoteLockscreenValidationServiceComponent(COMPONENT_NAME));
         chooseLockSettingsHelper.launch();
 
@@ -187,8 +187,8 @@
                 ConfirmDeviceCredentialBaseFragment.IS_REMOTE_LOCKSCREEN_VALIDATION, false)
         ).isTrue();
         assertThat(startedIntent.getParcelableExtra(
-                KeyguardManager.EXTRA_START_LOCKSCREEN_VALIDATION_REQUEST,
-                StartLockscreenValidationRequest.class)
+                KeyguardManager.EXTRA_REMOTE_LOCKSCREEN_VALIDATION_SESSION,
+                RemoteLockscreenValidationSession.class)
         ).isEqualTo(request);
         assertThat(startedIntent.getParcelableExtra(
                 Intent.EXTRA_COMPONENT_NAME, ComponentName.class)
@@ -199,13 +199,13 @@
     public void launchConfirmPassword_remoteValidation_pinLockType() throws Exception {
         Activity activity = Robolectric.setupActivity(Activity.class);
         ShadowActivity shadowActivity = Shadows.shadowOf(activity);
-        StartLockscreenValidationRequest request = createStartLockscreenValidationRequest(
+        RemoteLockscreenValidationSession request = createRemoteLockscreenValidationSession(
                 KeyguardManager.PIN, VALID_REMAINING_ATTEMPTS);
 
         ChooseLockSettingsHelper chooseLockSettingsHelper = getChooseLockSettingsHelper(
                 new ChooseLockSettingsHelper.Builder(activity)
                         .setRemoteLockscreenValidation(true)
-                        .setStartLockscreenValidationRequest(request)
+                        .setRemoteLockscreenValidationSession(request)
                         .setRemoteLockscreenValidationServiceComponent(COMPONENT_NAME));
         chooseLockSettingsHelper.launch();
 
@@ -216,8 +216,8 @@
                 ConfirmDeviceCredentialBaseFragment.IS_REMOTE_LOCKSCREEN_VALIDATION, false)
         ).isTrue();
         assertThat(startedIntent.getParcelableExtra(
-                KeyguardManager.EXTRA_START_LOCKSCREEN_VALIDATION_REQUEST,
-                StartLockscreenValidationRequest.class)
+                KeyguardManager.EXTRA_REMOTE_LOCKSCREEN_VALIDATION_SESSION,
+                RemoteLockscreenValidationSession.class)
         ).isEqualTo(request);
         assertThat(startedIntent.getParcelableExtra(
                 Intent.EXTRA_COMPONENT_NAME, ComponentName.class)
@@ -228,13 +228,13 @@
     public void launchConfirmPattern_remoteValidation_patternLockType() throws Exception {
         Activity activity = Robolectric.setupActivity(Activity.class);
         ShadowActivity shadowActivity = Shadows.shadowOf(activity);
-        StartLockscreenValidationRequest request = createStartLockscreenValidationRequest(
+        RemoteLockscreenValidationSession request = createRemoteLockscreenValidationSession(
                 KeyguardManager.PATTERN, VALID_REMAINING_ATTEMPTS);
 
         ChooseLockSettingsHelper chooseLockSettingsHelper = getChooseLockSettingsHelper(
                 new ChooseLockSettingsHelper.Builder(activity)
                         .setRemoteLockscreenValidation(true)
-                        .setStartLockscreenValidationRequest(request)
+                        .setRemoteLockscreenValidationSession(request)
                         .setRemoteLockscreenValidationServiceComponent(COMPONENT_NAME));
         chooseLockSettingsHelper.launch();
 
@@ -245,8 +245,8 @@
                 ConfirmDeviceCredentialBaseFragment.IS_REMOTE_LOCKSCREEN_VALIDATION, false)
         ).isTrue();
         assertThat(startedIntent.getParcelableExtra(
-                KeyguardManager.EXTRA_START_LOCKSCREEN_VALIDATION_REQUEST,
-                StartLockscreenValidationRequest.class)
+                KeyguardManager.EXTRA_REMOTE_LOCKSCREEN_VALIDATION_SESSION,
+                RemoteLockscreenValidationSession.class)
         ).isEqualTo(request);
         assertThat(startedIntent.getParcelableExtra(
                 Intent.EXTRA_COMPONENT_NAME, ComponentName.class)
diff --git a/tests/robotests/src/com/android/settings/password/ConfirmCredentialTest.java b/tests/robotests/src/com/android/settings/password/ConfirmCredentialTest.java
index 40b359e..299b1eb 100644
--- a/tests/robotests/src/com/android/settings/password/ConfirmCredentialTest.java
+++ b/tests/robotests/src/com/android/settings/password/ConfirmCredentialTest.java
@@ -23,7 +23,7 @@
 import static com.android.settings.password.TestUtils.buildConfirmDeviceCredentialBaseActivity;
 import static com.android.settings.password.TestUtils.createPackageInfoWithService;
 import static com.android.settings.password.TestUtils.createRemoteLockscreenValidationIntent;
-import static com.android.settings.password.TestUtils.createStartLockscreenValidationRequest;
+import static com.android.settings.password.TestUtils.createRemoteLockscreenValidationSession;
 import static com.android.settings.password.TestUtils.getConfirmDeviceCredentialBaseFragment;
 
 import static com.google.common.truth.Truth.assertThat;
@@ -132,8 +132,8 @@
             throws Exception {
         Intent intentWithInvalidComponentName = new Intent()
                 .putExtra(ConfirmDeviceCredentialBaseFragment.IS_REMOTE_LOCKSCREEN_VALIDATION, true)
-                .putExtra(KeyguardManager.EXTRA_START_LOCKSCREEN_VALIDATION_REQUEST,
-                        createStartLockscreenValidationRequest(
+                .putExtra(KeyguardManager.EXTRA_REMOTE_LOCKSCREEN_VALIDATION_SESSION,
+                        createRemoteLockscreenValidationSession(
                                 KeyguardManager.PASSWORD, VALID_REMAINING_ATTEMPTS))
                 .putExtra(Intent.EXTRA_COMPONENT_NAME, new ComponentName("pkg", "cls"));
 
diff --git a/tests/robotests/src/com/android/settings/password/TestUtils.java b/tests/robotests/src/com/android/settings/password/TestUtils.java
index 246d926..ef08f05 100644
--- a/tests/robotests/src/com/android/settings/password/TestUtils.java
+++ b/tests/robotests/src/com/android/settings/password/TestUtils.java
@@ -18,7 +18,7 @@
 
 import android.app.KeyguardManager;
 import android.app.RemoteLockscreenValidationResult;
-import android.app.StartLockscreenValidationRequest;
+import android.app.RemoteLockscreenValidationSession;
 import android.content.ComponentName;
 import android.content.Intent;
 import android.content.pm.ApplicationInfo;
@@ -79,15 +79,15 @@
             int lockscreenType, int remainingAttempts) throws Exception {
         return new Intent()
                 .putExtra(ConfirmDeviceCredentialBaseFragment.IS_REMOTE_LOCKSCREEN_VALIDATION, true)
-                .putExtra(KeyguardManager.EXTRA_START_LOCKSCREEN_VALIDATION_REQUEST,
-                        createStartLockscreenValidationRequest(lockscreenType, remainingAttempts))
+                .putExtra(KeyguardManager.EXTRA_REMOTE_LOCKSCREEN_VALIDATION_SESSION,
+                        createRemoteLockscreenValidationSession(lockscreenType, remainingAttempts))
                 .putExtra(Intent.EXTRA_COMPONENT_NAME, COMPONENT_NAME);
     }
 
-    public static StartLockscreenValidationRequest createStartLockscreenValidationRequest(
+    public static RemoteLockscreenValidationSession createRemoteLockscreenValidationSession(
             int lockscreenType, int remainingAttempts) throws NoSuchAlgorithmException {
-        return new StartLockscreenValidationRequest.Builder()
-                .setLockscreenUiType(lockscreenType)
+        return new RemoteLockscreenValidationSession.Builder()
+                .setLockType(lockscreenType)
                 .setRemainingAttempts(remainingAttempts)
                 .setSourcePublicKey(SecureBox.genKeyPair().getPublic().getEncoded())
                 .build();