[BiometricsV2] Refactor model code to kotlin
Bug: 286196884
Test: atest FingerprintEnrollmentActivityTest CredentialModelTest
EnrollmentRequestTest FingerprintEnrollIntroViewModelTest
FingerprintEnrollmentViewModelTest
Test: atest biometrics-enrollment-test
Change-Id: I2bdae4d2dd052d3664a790cd982edf51fcebec09
diff --git a/src/com/android/settings/biometrics2/ui/model/CredentialModel.java b/src/com/android/settings/biometrics2/ui/model/CredentialModel.java
deleted file mode 100644
index caff80a..0000000
--- a/src/com/android/settings/biometrics2/ui/model/CredentialModel.java
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.biometrics2.ui.model;
-
-import static com.android.settings.biometrics.BiometricEnrollBase.EXTRA_KEY_CHALLENGE;
-import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN;
-import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_GK_PW_HANDLE;
-
-import android.content.Intent;
-import android.os.Bundle;
-import android.os.UserHandle;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.annotation.VisibleForTesting;
-
-import java.time.Clock;
-
-/**
- * Secret credential data including
- * 1. userId
- * 2. challenge
- * 3. token
- * 4. gkPwHandle
- */
-public final class CredentialModel {
-
- /**
- * Default value for an invalid challenge
- */
- @VisibleForTesting
- public static final long INVALID_CHALLENGE = -1L;
-
- /**
- * Default value if GkPwHandle is invalid.
- */
- @VisibleForTesting
- public static final long INVALID_GK_PW_HANDLE = 0L;
-
- private final Clock mClock;
-
- private final long mInitMillis;
-
- private final int mUserId;
-
- private long mChallenge;
- @Nullable
- private Long mUpdateChallengeMillis = null;
-
- @Nullable
- private byte[] mToken;
- @Nullable
- private Long mUpdateTokenMillis = null;
-
- private long mGkPwHandle;
- @Nullable
- private Long mClearGkPwHandleMillis = null;
-
- public CredentialModel(@Nullable Bundle bundle, @NonNull Clock clock) {
- if (bundle == null) {
- bundle = new Bundle();
- }
- mUserId = bundle.getInt(Intent.EXTRA_USER_ID, UserHandle.myUserId());
- mChallenge = bundle.getLong(EXTRA_KEY_CHALLENGE, INVALID_CHALLENGE);
- mToken = bundle.getByteArray(EXTRA_KEY_CHALLENGE_TOKEN);
- mGkPwHandle = bundle.getLong(EXTRA_KEY_GK_PW_HANDLE, INVALID_GK_PW_HANDLE);
- mClock = clock;
- mInitMillis = mClock.millis();
- }
-
- /**
- * Get a bundle which can be used to recreate CredentialModel
- */
- @NonNull
- public Bundle getBundle() {
- final Bundle bundle = new Bundle();
- bundle.putInt(Intent.EXTRA_USER_ID, mUserId);
- bundle.putLong(EXTRA_KEY_CHALLENGE, mChallenge);
- bundle.putByteArray(EXTRA_KEY_CHALLENGE_TOKEN, mToken);
- bundle.putLong(EXTRA_KEY_GK_PW_HANDLE, mGkPwHandle);
- return bundle;
- }
-
- /**
- * Get userId for this credential
- */
- public int getUserId() {
- return mUserId;
- }
-
- /**
- * Check user id is valid or not
- */
- public boolean isValidUserId() {
- return mUserId != UserHandle.USER_NULL;
- }
-
- /**
- * Get challenge
- */
- public long getChallenge() {
- return mChallenge;
- }
-
- /**
- * Set challenge
- */
- public void setChallenge(long value) {
- mUpdateChallengeMillis = mClock.millis();
- mChallenge = value;
- }
-
- /**
- * Check challenge is valid or not
- */
- public boolean isValidChallenge() {
- return mChallenge != INVALID_CHALLENGE;
- }
-
- /**
- * Get challenge token
- */
- @Nullable
- public byte[] getToken() {
- return mToken;
- }
-
- /**
- * Set challenge token
- */
- public void setToken(@Nullable byte[] value) {
- mUpdateTokenMillis = mClock.millis();
- mToken = value;
- }
-
- /**
- * Check challengeToken is valid or not
- */
- public boolean isValidToken() {
- return mToken != null;
- }
-
- /**
- * Get gatekeeper password handle
- */
- public long getGkPwHandle() {
- return mGkPwHandle;
- }
-
- /**
- * Clear gatekeeper password handle data
- */
- public void clearGkPwHandle() {
- mClearGkPwHandleMillis = mClock.millis();
- mGkPwHandle = INVALID_GK_PW_HANDLE;
- }
-
- /**
- * Check gkPwHandle is valid or not
- */
- public boolean isValidGkPwHandle() {
- return mGkPwHandle != INVALID_GK_PW_HANDLE;
- }
-
- /**
- * Returns a string representation of the object
- */
- @Override
- public String toString() {
- final int gkPwHandleLen = ("" + mGkPwHandle).length();
- final int tokenLen = mToken == null ? 0 : mToken.length;
- final int challengeLen = ("" + mChallenge).length();
- return getClass().getSimpleName() + ":{initMillis:" + mInitMillis
- + ", userId:" + mUserId
- + ", challenge:{len:" + challengeLen
- + ", updateMillis:" + mUpdateChallengeMillis + "}"
- + ", token:{len:" + tokenLen + ", isValid:" + isValidToken()
- + ", updateMillis:" + mUpdateTokenMillis + "}"
- + ", gkPwHandle:{len:" + gkPwHandleLen + ", isValid:" + isValidGkPwHandle()
- + ", clearMillis:" + mClearGkPwHandleMillis + "}"
- + " }";
- }
-}
diff --git a/src/com/android/settings/biometrics2/ui/model/CredentialModel.kt b/src/com/android/settings/biometrics2/ui/model/CredentialModel.kt
new file mode 100644
index 0000000..7999ab8
--- /dev/null
+++ b/src/com/android/settings/biometrics2/ui/model/CredentialModel.kt
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.biometrics2.ui.model
+
+import android.content.Intent.EXTRA_USER_ID
+import android.os.Bundle
+import android.os.UserHandle
+import androidx.annotation.VisibleForTesting
+import com.android.settings.biometrics.BiometricEnrollBase.EXTRA_KEY_CHALLENGE
+import com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN
+import com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_GK_PW_HANDLE
+import java.time.Clock
+
+/**
+ * Secret credential data including
+ * 1. userId
+ * 2. challenge
+ * 3. token
+ * 4. gkPwHandle
+ */
+class CredentialModel(bundle: Bundle?, private val clock: Clock) {
+
+ private val mInitMillis = clock.millis()
+
+ /** userId for this credential */
+ val userId: Int = (bundle ?: Bundle()).getInt(EXTRA_USER_ID, UserHandle.myUserId())
+
+ private var clearGkPwHandleMillis: Long? = null
+
+ /** Gatekeeper password handle */
+ var gkPwHandle: Long = (bundle ?: Bundle()).getLong(EXTRA_KEY_GK_PW_HANDLE, INVALID_GK_PW_HANDLE)
+ private set
+
+ val isValidGkPwHandle: Boolean
+ get() = gkPwHandle != INVALID_GK_PW_HANDLE
+
+ /** Clear gatekeeper password handle data */
+ fun clearGkPwHandle() {
+ clearGkPwHandleMillis = clock.millis()
+ gkPwHandle = INVALID_GK_PW_HANDLE
+ }
+
+ /** Check user id is valid or not */
+ val isValidUserId: Boolean
+ get() = userId != UserHandle.USER_NULL
+
+ private var updateChallengeMillis: Long? = null
+
+ var challenge: Long = (bundle ?: Bundle()).getLong(EXTRA_KEY_CHALLENGE, INVALID_CHALLENGE)
+ set(value) {
+ updateChallengeMillis = clock.millis()
+ field = value
+ }
+
+ val isValidChallenge: Boolean
+ get() = challenge != INVALID_CHALLENGE
+
+ private var updateTokenMillis: Long? = null
+
+ /** Challenge token */
+ var token: ByteArray? = (bundle ?: Bundle()).getByteArray(EXTRA_KEY_CHALLENGE_TOKEN)
+ set(value) {
+ updateTokenMillis = clock.millis()
+ field = value
+ }
+
+ val isValidToken: Boolean
+ get() = token != null
+
+ val bundle: Bundle
+ /**
+ * Get a bundle which can be used to recreate CredentialModel
+ */
+ get() {
+ val bundle = Bundle()
+ bundle.putInt(EXTRA_USER_ID, userId)
+ bundle.putLong(EXTRA_KEY_CHALLENGE, challenge)
+ bundle.putByteArray(EXTRA_KEY_CHALLENGE_TOKEN, token)
+ bundle.putLong(EXTRA_KEY_GK_PW_HANDLE, gkPwHandle)
+ return bundle
+ }
+
+
+ /** Returns a string representation of the object */
+ override fun toString(): String {
+ val gkPwHandleLen = "$gkPwHandle".length
+ val tokenLen = token?.size ?: 0
+ val challengeLen = "$challenge".length
+ return (javaClass.simpleName + ":{initMillis:$mInitMillis"
+ + ", userId:$userId"
+ + ", challenge:{len:$challengeLen"
+ + ", updateMillis:$updateChallengeMillis}"
+ + ", token:{len:$tokenLen, isValid:$isValidToken"
+ + ", updateMillis:$updateTokenMillis}"
+ + ", gkPwHandle:{len:$gkPwHandleLen, isValid:$isValidGkPwHandle"
+ + ", clearMillis:$clearGkPwHandleMillis}"
+ + " }")
+ }
+
+ companion object {
+ /** Default value for an invalid challenge */
+ @VisibleForTesting
+ const val INVALID_CHALLENGE = -1L
+
+ /** Default value if GkPwHandle is invalid */
+ @VisibleForTesting
+ const val INVALID_GK_PW_HANDLE = 0L
+ }
+}
diff --git a/src/com/android/settings/biometrics2/ui/model/EnrollmentProgress.java b/src/com/android/settings/biometrics2/ui/model/EnrollmentProgress.java
deleted file mode 100644
index c62d670..0000000
--- a/src/com/android/settings/biometrics2/ui/model/EnrollmentProgress.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.biometrics2.ui.model;
-
-/**
- * Biometric Enrollment progress
- */
-public final class EnrollmentProgress {
-
- public static final int INITIAL_STEPS = -1;
- public static final int INITIAL_REMAINING = 0;
-
- private final int mSteps;
- private final int mRemaining;
-
- public EnrollmentProgress(int steps, int remaining) {
- mSteps = steps;
- mRemaining = remaining;
- }
-
- public int getSteps() {
- return mSteps;
- }
-
- public int getRemaining() {
- return mRemaining;
- }
-
- public boolean isInitialStep() {
- return mSteps == INITIAL_STEPS;
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() + "@" + Integer.toHexString(hashCode())
- + "{steps:" + mSteps + ", remaining:" + mRemaining + "}";
- }
-}
diff --git a/src/com/android/settings/biometrics2/ui/model/EnrollmentProgress.kt b/src/com/android/settings/biometrics2/ui/model/EnrollmentProgress.kt
new file mode 100644
index 0000000..7b35a68
--- /dev/null
+++ b/src/com/android/settings/biometrics2/ui/model/EnrollmentProgress.kt
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.biometrics2.ui.model
+
+/** Biometric Enrollment progress */
+class EnrollmentProgress(val steps: Int, val remaining: Int) {
+
+ val isInitialStep: Boolean
+ get() = steps == INITIAL_STEPS
+
+ override fun toString(): String {
+ return ("${javaClass.simpleName}@${Integer.toHexString(hashCode())}"
+ + "{steps:$steps, remaining:$remaining}")
+ }
+
+ companion object {
+ const val INITIAL_STEPS = -1
+ const val INITIAL_REMAINING = 0
+ }
+}
diff --git a/src/com/android/settings/biometrics2/ui/model/EnrollmentRequest.java b/src/com/android/settings/biometrics2/ui/model/EnrollmentRequest.java
deleted file mode 100644
index 0c3f08d..0000000
--- a/src/com/android/settings/biometrics2/ui/model/EnrollmentRequest.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.biometrics2.ui.model;
-
-import static com.google.android.setupcompat.util.WizardManagerHelper.EXTRA_IS_SUW_SUGGESTED_ACTION_FLOW;
-
-import android.content.Context;
-import android.content.Intent;
-import android.os.Bundle;
-
-import androidx.annotation.NonNull;
-
-import com.android.settings.SetupWizardUtils;
-import com.android.settings.biometrics.BiometricEnrollActivity;
-
-import com.google.android.setupcompat.util.WizardManagerHelper;
-
-/**
- * Biometric enrollment generic intent data, which includes
- * 1. isSuw
- * 2. isAfterSuwOrSuwSuggestedAction
- * 3. theme
- * 4. isFromSettingsSummery
- * 5. isSkipIntro
- * 6. isSkipFindSensor
- * 7. a helper method, getSetupWizardExtras
- */
-public final class EnrollmentRequest {
-
- public static final String EXTRA_SKIP_FIND_SENSOR = "skip_find_sensor";
-
- private final boolean mIsSuw;
- private final boolean mIsAfterSuwOrSuwSuggestedAction;
- private final boolean mIsSkipIntro;
- private final boolean mIsSkipFindSensor;
- private final int mTheme;
- private final Bundle mSuwExtras;
-
- public EnrollmentRequest(@NonNull Intent intent, @NonNull Context context,
- boolean isSetupActivity) {
- // Only allow mIsSuw to be enabled through SetupActivity for security reason
- mIsSuw = isSetupActivity && WizardManagerHelper.isAnySetupWizard(intent);
- mIsAfterSuwOrSuwSuggestedAction = isSetupActivity
- && (WizardManagerHelper.isDeferredSetupWizard(intent)
- || WizardManagerHelper.isPortalSetupWizard(intent)
- || intent.getBooleanExtra(EXTRA_IS_SUW_SUGGESTED_ACTION_FLOW, false));
- mSuwExtras = getSuwExtras(mIsSuw, intent);
- mIsSkipIntro = intent.getBooleanExtra(BiometricEnrollActivity.EXTRA_SKIP_INTRO, false);
- mIsSkipFindSensor = intent.getBooleanExtra(EXTRA_SKIP_FIND_SENSOR, false);
- mTheme = SetupWizardUtils.getTheme(context, intent);
- }
-
- public boolean isSuw() {
- return mIsSuw;
- }
-
- public boolean isAfterSuwOrSuwSuggestedAction() {
- return mIsAfterSuwOrSuwSuggestedAction;
- }
-
- public boolean isSkipIntro() {
- return mIsSkipIntro;
- }
-
- public boolean isSkipFindSensor() {
- return mIsSkipFindSensor;
- }
-
- public int getTheme() {
- return mTheme;
- }
-
- @NonNull
- public Bundle getSuwExtras() {
- return new Bundle(mSuwExtras);
- }
-
- /**
- * Returns a string representation of the object
- */
- @Override
- public String toString() {
- return getClass().getSimpleName() + ":{isSuw:" + mIsSuw
- + ", isAfterSuwOrSuwSuggestedAction:" + mIsAfterSuwOrSuwSuggestedAction
- + "}";
- }
-
- @NonNull
- private static Bundle getSuwExtras(boolean isSuw, @NonNull Intent intent) {
- final Intent toIntent = new Intent();
- if (isSuw) {
- SetupWizardUtils.copySetupExtras(intent, toIntent);
- }
- return toIntent.getExtras() != null ? toIntent.getExtras() : new Bundle();
- }
-}
diff --git a/src/com/android/settings/biometrics2/ui/model/EnrollmentRequest.kt b/src/com/android/settings/biometrics2/ui/model/EnrollmentRequest.kt
new file mode 100644
index 0000000..4696c62
--- /dev/null
+++ b/src/com/android/settings/biometrics2/ui/model/EnrollmentRequest.kt
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.biometrics2.ui.model
+
+import android.content.Context
+import android.content.Intent
+import android.os.Bundle
+import com.android.settings.SetupWizardUtils
+import com.android.settings.biometrics.BiometricEnrollActivity.EXTRA_SKIP_INTRO
+import com.google.android.setupcompat.util.WizardManagerHelper
+import com.google.android.setupcompat.util.WizardManagerHelper.EXTRA_IS_SUW_SUGGESTED_ACTION_FLOW
+
+/**
+ * Biometric enrollment generic intent data, which includes
+ * 1. isSuw
+ * 2. isAfterSuwOrSuwSuggestedAction
+ * 3. theme
+ * 4. isFromSettingsSummery
+ * 5. isSkipIntro
+ * 6. isSkipFindSensor
+ * 7. a helper method, getSetupWizardExtras
+ */
+class EnrollmentRequest(
+ intent: Intent,
+ context: Context,
+ isSetupActivity: Boolean
+) {
+ val isSuw: Boolean = isSetupActivity && WizardManagerHelper.isAnySetupWizard(intent)
+
+ val isAfterSuwOrSuwSuggestedAction = (isSetupActivity
+ && (WizardManagerHelper.isDeferredSetupWizard(intent)
+ || WizardManagerHelper.isPortalSetupWizard(intent)
+ || intent.getBooleanExtra(EXTRA_IS_SUW_SUGGESTED_ACTION_FLOW, false)))
+
+ private val _suwExtras = getSuwExtras(isSuw, intent)
+
+ val isSkipIntro = intent.getBooleanExtra(EXTRA_SKIP_INTRO, false)
+
+ val isSkipFindSensor = intent.getBooleanExtra(EXTRA_SKIP_FIND_SENSOR, false)
+
+ val theme = SetupWizardUtils.getTheme(context, intent)
+
+ val suwExtras: Bundle
+ get() = Bundle(_suwExtras)
+
+ /**
+ * Returns a string representation of the object
+ */
+ override fun toString(): String {
+ return (javaClass.simpleName + ":{isSuw:" + isSuw
+ + ", isAfterSuwOrSuwSuggestedAction:" + isAfterSuwOrSuwSuggestedAction
+ + "}")
+ }
+
+ companion object {
+ const val EXTRA_SKIP_FIND_SENSOR = "skip_find_sensor"
+ private fun getSuwExtras(isSuw: Boolean, intent: Intent): Bundle {
+ val toIntent = Intent()
+ if (isSuw) {
+ SetupWizardUtils.copySetupExtras(intent, toIntent)
+ }
+ return toIntent.extras ?: Bundle()
+ }
+ }
+}
diff --git a/src/com/android/settings/biometrics2/ui/model/EnrollmentStatusMessage.java b/src/com/android/settings/biometrics2/ui/model/EnrollmentStatusMessage.java
deleted file mode 100644
index 184e1d1..0000000
--- a/src/com/android/settings/biometrics2/ui/model/EnrollmentStatusMessage.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.biometrics2.ui.model;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-
-/**
- * Enrolling status message (help or error)
- */
-public final class EnrollmentStatusMessage {
-
- private final int mMsgId;
- @NonNull private final CharSequence mStr;
-
- public EnrollmentStatusMessage(int msgId, @Nullable CharSequence str) {
- mMsgId = msgId;
- mStr = str != null ? str : "";
- }
-
- public int getMsgId() {
- return mMsgId;
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() + "@" + Integer.toHexString(hashCode())
- + "{id:" + mMsgId + ", str:" + mStr + "}";
- }
-
- /**
- * Gets status string
- */
- @NonNull
- public CharSequence getStr() {
- return mStr;
- }
-}
diff --git a/src/com/android/settings/biometrics2/ui/model/EnrollmentStatusMessage.kt b/src/com/android/settings/biometrics2/ui/model/EnrollmentStatusMessage.kt
new file mode 100644
index 0000000..6dd0c5c
--- /dev/null
+++ b/src/com/android/settings/biometrics2/ui/model/EnrollmentStatusMessage.kt
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.biometrics2.ui.model
+
+/** Enrolling status message (help or error) */
+class EnrollmentStatusMessage(val msgId: Int, string: CharSequence?) {
+
+ /** Status string */
+ val str: CharSequence = string ?: ""
+
+ override fun toString(): String {
+ return "${javaClass.simpleName}@${Integer.toHexString(hashCode())}{id:$msgId, str:$str}"
+ }
+}
diff --git a/src/com/android/settings/biometrics2/ui/model/FingerprintEnrollIntroStatus.java b/src/com/android/settings/biometrics2/ui/model/FingerprintEnrollIntroStatus.java
deleted file mode 100644
index cbfacee..0000000
--- a/src/com/android/settings/biometrics2/ui/model/FingerprintEnrollIntroStatus.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.biometrics2.ui.model;
-
-import android.annotation.IntDef;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-
-/**
- * Fingerprint onboarding introduction page data, it contains following information which needs
- * to be passed from view model to view.
- * 1. mEnrollableStatus: User is allowed to enroll a new fingerprint or not.
- * 2. mHasScrollToBottom: User has scrolled to the bottom of this page or not.
- */
-public final class FingerprintEnrollIntroStatus {
-
- /**
- * Unconfirmed case, it means that this value is invalid, and view shall bypass this value.
- */
- public static final int FINGERPRINT_ENROLLABLE_UNKNOWN = -1;
-
- /**
- * User is allowed to enrolled a new fingerprint.
- */
- public static final int FINGERPRINT_ENROLLABLE_OK = 0;
-
- /**
- * User is not allowed to enrolled a new fingerprint because the number of enrolled fingerprint
- * has reached maximum.
- */
- public static final int FINGERPRINT_ENROLLABLE_ERROR_REACH_MAX = 1;
-
- @IntDef(prefix = {"FINGERPRINT_ENROLLABLE_"}, value = {
- FINGERPRINT_ENROLLABLE_UNKNOWN,
- FINGERPRINT_ENROLLABLE_OK,
- FINGERPRINT_ENROLLABLE_ERROR_REACH_MAX
- })
- @Retention(RetentionPolicy.SOURCE)
- public @interface FingerprintEnrollableStatus {
- }
-
- private final boolean mHasScrollToBottom;
-
- @FingerprintEnrollableStatus
- private final int mEnrollableStatus;
-
- public FingerprintEnrollIntroStatus(boolean hasScrollToBottom, int enrollableStatus) {
- mEnrollableStatus = enrollableStatus;
- mHasScrollToBottom = hasScrollToBottom;
- }
-
- /**
- * Get enrollable status. It means that user is allowed to enroll a new fingerprint or not.
- */
- @FingerprintEnrollableStatus
- public int getEnrollableStatus() {
- return mEnrollableStatus;
- }
-
- /**
- * Get info for this onboarding introduction page has scrolled to bottom or not
- */
- public boolean hasScrollToBottom() {
- return mHasScrollToBottom;
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() + "@" + Integer.toHexString(hashCode())
- + "{scrollToBottom:" + mHasScrollToBottom
- + ", enrollableStatus:" + mEnrollableStatus + "}";
- }
-}
diff --git a/src/com/android/settings/biometrics2/ui/model/FingerprintEnrollIntroStatus.kt b/src/com/android/settings/biometrics2/ui/model/FingerprintEnrollIntroStatus.kt
new file mode 100644
index 0000000..4cbaffa
--- /dev/null
+++ b/src/com/android/settings/biometrics2/ui/model/FingerprintEnrollIntroStatus.kt
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.biometrics2.ui.model
+
+
+enum class FingerprintEnrollable {
+ // Unconfirmed case, this value is invalid, and view shall bypass this value
+ FINGERPRINT_ENROLLABLE_UNKNOWN,
+ // User is allowed to enrolled a new fingerprint
+ FINGERPRINT_ENROLLABLE_OK,
+ // User is not allowed to enroll because the number has reached maximum
+ FINGERPRINT_ENROLLABLE_ERROR_REACH_MAX
+}
+
+/**
+ * Fingerprint onboarding introduction page data, it contains following information which needs
+ * to be passed from view model to view.
+ * 1. mEnrollableStatus: User is allowed to enroll a new fingerprint or not.
+ * 2. mHasScrollToBottom: User has scrolled to the bottom of this page or not.
+ */
+class FingerprintEnrollIntroStatus(
+ private val mHasScrollToBottom: Boolean,
+ /** Enrollable status. It means that user is allowed to enroll a new fingerprint or not. */
+ val enrollableStatus: FingerprintEnrollable
+) {
+ /** Get info for this onboarding introduction page has scrolled to bottom or not */
+ fun hasScrollToBottom(): Boolean {
+ return mHasScrollToBottom
+ }
+
+ override fun toString(): String {
+ return ("${javaClass.simpleName}@${Integer.toHexString(hashCode())}"
+ + "{scrollToBottom:$mHasScrollToBottom"
+ + ", enrollableStatus:$enrollableStatus}")
+ }
+}
diff --git a/src/com/android/settings/biometrics2/ui/view/FingerprintEnrollIntroFragment.java b/src/com/android/settings/biometrics2/ui/view/FingerprintEnrollIntroFragment.java
index b151e1a..9cafdae 100644
--- a/src/com/android/settings/biometrics2/ui/view/FingerprintEnrollIntroFragment.java
+++ b/src/com/android/settings/biometrics2/ui/view/FingerprintEnrollIntroFragment.java
@@ -18,9 +18,7 @@
import static android.app.admin.DevicePolicyResources.Strings.Settings.FINGERPRINT_UNLOCK_DISABLED;
-import static com.android.settings.biometrics2.ui.model.FingerprintEnrollIntroStatus.FINGERPRINT_ENROLLABLE_ERROR_REACH_MAX;
-import static com.android.settings.biometrics2.ui.model.FingerprintEnrollIntroStatus.FINGERPRINT_ENROLLABLE_OK;
-import static com.android.settings.biometrics2.ui.model.FingerprintEnrollIntroStatus.FINGERPRINT_ENROLLABLE_UNKNOWN;
+import static com.android.settings.biometrics2.ui.model.FingerprintEnrollable.FINGERPRINT_ENROLLABLE_ERROR_REACH_MAX;
import static com.google.android.setupdesign.util.DynamicColorPalette.ColorType.ACCENT;
diff --git a/src/com/android/settings/biometrics2/ui/viewmodel/FingerprintEnrollIntroViewModel.java b/src/com/android/settings/biometrics2/ui/viewmodel/FingerprintEnrollIntroViewModel.java
index 5e8a807..5e9085a 100644
--- a/src/com/android/settings/biometrics2/ui/viewmodel/FingerprintEnrollIntroViewModel.java
+++ b/src/com/android/settings/biometrics2/ui/viewmodel/FingerprintEnrollIntroViewModel.java
@@ -16,9 +16,9 @@
package com.android.settings.biometrics2.ui.viewmodel;
-import static com.android.settings.biometrics2.ui.model.FingerprintEnrollIntroStatus.FINGERPRINT_ENROLLABLE_ERROR_REACH_MAX;
-import static com.android.settings.biometrics2.ui.model.FingerprintEnrollIntroStatus.FINGERPRINT_ENROLLABLE_OK;
-import static com.android.settings.biometrics2.ui.model.FingerprintEnrollIntroStatus.FINGERPRINT_ENROLLABLE_UNKNOWN;
+import static com.android.settings.biometrics2.ui.model.FingerprintEnrollable.FINGERPRINT_ENROLLABLE_ERROR_REACH_MAX;
+import static com.android.settings.biometrics2.ui.model.FingerprintEnrollable.FINGERPRINT_ENROLLABLE_OK;
+import static com.android.settings.biometrics2.ui.model.FingerprintEnrollable.FINGERPRINT_ENROLLABLE_UNKNOWN;
import android.annotation.IntDef;
import android.app.Application;
@@ -33,6 +33,7 @@
import com.android.settings.biometrics2.data.repository.FingerprintRepository;
import com.android.settings.biometrics2.ui.model.EnrollmentRequest;
import com.android.settings.biometrics2.ui.model.FingerprintEnrollIntroStatus;
+import com.android.settings.biometrics2.ui.model.FingerprintEnrollable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -44,7 +45,8 @@
private static final String TAG = "FingerprintEnrollIntroViewModel";
private static final boolean HAS_SCROLLED_TO_BOTTOM_DEFAULT = false;
- private static final int ENROLLABLE_STATUS_DEFAULT = FINGERPRINT_ENROLLABLE_UNKNOWN;
+ private static final FingerprintEnrollable ENROLLABLE_STATUS_DEFAULT =
+ FINGERPRINT_ENROLLABLE_UNKNOWN;
/**
* User clicks 'Done' button on this page
@@ -73,7 +75,7 @@
private final MutableLiveData<Boolean> mHasScrolledToBottomLiveData =
new MutableLiveData<>(HAS_SCROLLED_TO_BOTTOM_DEFAULT);
- private final MutableLiveData<Integer> mEnrollableStatusLiveData =
+ private final MutableLiveData<FingerprintEnrollable> mEnrollableStatusLiveData =
new MutableLiveData<>(ENROLLABLE_STATUS_DEFAULT);
private final MediatorLiveData<FingerprintEnrollIntroStatus> mPageStatusLiveData =
new MediatorLiveData<>();
@@ -101,7 +103,8 @@
mPageStatusLiveData.addSource(
mHasScrolledToBottomLiveData,
hasScrolledToBottom -> {
- final Integer enrollableValue = mEnrollableStatusLiveData.getValue();
+ final FingerprintEnrollable enrollableValue =
+ mEnrollableStatusLiveData.getValue();
final FingerprintEnrollIntroStatus status = new FingerprintEnrollIntroStatus(
hasScrolledToBottom,
enrollableValue != null ? enrollableValue : ENROLLABLE_STATUS_DEFAULT);
@@ -181,7 +184,7 @@
* User clicks next button
*/
public void onNextButtonClick() {
- final Integer status = mEnrollableStatusLiveData.getValue();
+ final FingerprintEnrollable status = mEnrollableStatusLiveData.getValue();
switch (status != null ? status : ENROLLABLE_STATUS_DEFAULT) {
case FINGERPRINT_ENROLLABLE_ERROR_REACH_MAX:
mActionLiveData.postValue(FINGERPRINT_ENROLL_INTRO_ACTION_DONE_AND_FINISH);
diff --git a/tests/unit/Android.bp b/tests/unit/Android.bp
index 8e81218..8dfb52e 100644
--- a/tests/unit/Android.bp
+++ b/tests/unit/Android.bp
@@ -41,7 +41,10 @@
},
// Include all test java files.
- srcs: ["src/**/*.java"],
+ srcs: [
+ "src/**/*.java",
+ "src/**/*.kt",
+ ],
platform_apis: true,
test_suites: ["device-tests"],
diff --git a/tests/unit/src/com/android/settings/biometrics2/ui/model/CredentialModelTest.java b/tests/unit/src/com/android/settings/biometrics2/ui/model/CredentialModelTest.java
deleted file mode 100644
index 8dfca01..0000000
--- a/tests/unit/src/com/android/settings/biometrics2/ui/model/CredentialModelTest.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * Copyright (C) 2023 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.biometrics2.ui.model;
-
-import static com.android.settings.biometrics.BiometricEnrollBase.EXTRA_KEY_CHALLENGE;
-import static com.android.settings.biometrics.BiometricEnrollBase.EXTRA_KEY_SENSOR_ID;
-import static com.android.settings.biometrics2.ui.model.CredentialModel.INVALID_CHALLENGE;
-import static com.android.settings.biometrics2.ui.model.CredentialModel.INVALID_GK_PW_HANDLE;
-import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_GK_PW_HANDLE;
-
-import static com.google.common.truth.Truth.assertThat;
-import static com.google.common.truth.Truth.assertWithMessage;
-
-import android.annotation.NonNull;
-import android.content.Intent;
-import android.os.Bundle;
-import android.os.SystemClock;
-import android.os.UserHandle;
-
-import androidx.annotation.Nullable;
-import androidx.test.ext.junit.runners.AndroidJUnit4;
-
-import com.android.settings.password.ChooseLockSettingsHelper;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import java.time.Clock;
-import java.util.Arrays;
-import java.util.Set;
-
-@RunWith(AndroidJUnit4.class)
-public class CredentialModelTest {
-
- private final Clock mClock = SystemClock.elapsedRealtimeClock();
-
- public static Bundle newCredentialModelIntentExtras(int userId, long challenge,
- @Nullable byte[] token, long gkPwHandle) {
- final Bundle bundle = new Bundle();
- bundle.putInt(Intent.EXTRA_USER_ID, userId);
- bundle.putLong(EXTRA_KEY_CHALLENGE, challenge);
- bundle.putByteArray(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, token);
- bundle.putLong(ChooseLockSettingsHelper.EXTRA_KEY_GK_PW_HANDLE, gkPwHandle);
- return bundle;
- }
-
- public static Bundle newValidTokenCredentialIntentExtras(int userId) {
- return newCredentialModelIntentExtras(userId, 1L, new byte[] { 0, 1, 2 },
- INVALID_GK_PW_HANDLE);
- }
-
- public static Bundle newOnlySensorValidCredentialIntentExtras(int userId) {
- return newCredentialModelIntentExtras(userId, INVALID_CHALLENGE, null,
- INVALID_GK_PW_HANDLE);
- }
-
- public static Bundle newGkPwHandleCredentialIntentExtras(int userId, long gkPwHandle) {
- return newCredentialModelIntentExtras(userId, INVALID_CHALLENGE, null, gkPwHandle);
- }
-
- private static void checkBundleLongValue(@NonNull Bundle bundle1, @NonNull Bundle bundle2,
- @NonNull String key) {
- if (!bundle1.containsKey(key)) {
- return;
- }
- final int value1 = bundle1.getInt(key);
- final int value2 = bundle2.getInt(key);
- assertWithMessage("bundle not match, key:" + key + ", value1:" + value1 + ", value2:"
- + value2).that(value1).isEqualTo(value2);
- }
-
- private static void checkBundleIntValue(@NonNull Bundle bundle1, @NonNull Bundle bundle2,
- @NonNull String key) {
- if (!bundle1.containsKey(key)) {
- return;
- }
- final long value1 = bundle1.getLong(key);
- final long value2 = bundle2.getLong(key);
- assertWithMessage("bundle not match, key:" + key + ", value1:" + value1 + ", value2:"
- + value2).that(value1).isEqualTo(value2);
- }
-
- private static void checkBundleByteArrayValue(@NonNull Bundle bundle1, @NonNull Bundle bundle2,
- @NonNull String key) {
- if (!bundle1.containsKey(key)) {
- return;
- }
- final byte[] value1 = bundle1.getByteArray(key);
- final byte[] value2 = bundle2.getByteArray(key);
- final String errMsg = "bundle not match, key:" + key + ", value1:" + Arrays.toString(value1)
- + ", value2:" + Arrays.toString(value2);
- if (value1 == null) {
- assertWithMessage(errMsg).that(value2).isNull();
- } else {
- assertWithMessage(errMsg).that(value1.length).isEqualTo(value2.length);
- for (int i = 0; i < value1.length; ++i) {
- assertWithMessage(errMsg).that(value1[i]).isEqualTo(value2[i]);
- }
- }
- }
-
- public static void verifySameCredentialModels(@NonNull CredentialModel model1,
- @NonNull CredentialModel model2) {
-
- assertThat(model1.getUserId()).isEqualTo(model2.getUserId());
- assertThat(model1.getChallenge()).isEqualTo(model2.getChallenge());
- assertThat(model1.getGkPwHandle()).isEqualTo(model2.getGkPwHandle());
-
- final byte[] token1 = model1.getToken();
- final byte[] token2 = model2.getToken();
- if (token1 == null) {
- assertThat(token2).isNull();
- } else {
- assertThat(token2).isNotNull();
- assertThat(token1.length).isEqualTo(token2.length);
- for (int i = 0; i < token1.length; ++i) {
- assertThat(token1[i]).isEqualTo(token2[i]);
- }
- }
-
- final Bundle bundle1 = model1.getBundle();
- final Bundle bundle2 = model2.getBundle();
- final Set<String> keySet1 = bundle1.keySet();
- assertThat(keySet1.equals(bundle2.keySet())).isTrue();
- checkBundleIntValue(bundle1, bundle2, Intent.EXTRA_USER_ID);
- checkBundleIntValue(bundle1, bundle2, EXTRA_KEY_SENSOR_ID);
- checkBundleLongValue(bundle1, bundle2, EXTRA_KEY_CHALLENGE);
- checkBundleByteArrayValue(bundle1, bundle2, EXTRA_KEY_CHALLENGE);
- checkBundleLongValue(bundle1, bundle2, EXTRA_KEY_GK_PW_HANDLE);
- }
-
- @Test
- public void testNullBundle() {
- final CredentialModel credentialModel = new CredentialModel(null, mClock);
-
- assertThat(credentialModel.getUserId()).isEqualTo(UserHandle.myUserId());
- }
-
- @Test
- public void testSameValueFromBundle() {
- final Bundle bundle = newCredentialModelIntentExtras(1234, 6677L,
- new byte[] { 33, 44, 55 }, 987654321);
-
- final CredentialModel model1 = new CredentialModel(bundle, mClock);
- final CredentialModel model2 = new CredentialModel(model1.getBundle(), mClock);
-
- verifySameCredentialModels(model1, model2);
- }
-
- @Test
- public void testSameValueFromBundle_nullToken() {
- final Bundle bundle = newCredentialModelIntentExtras(22, 33L, null, 21L);
-
- final CredentialModel model1 = new CredentialModel(bundle, mClock);
- final CredentialModel model2 = new CredentialModel(model1.getBundle(), mClock);
-
- verifySameCredentialModels(model1, model2);
- }
-}
diff --git a/tests/unit/src/com/android/settings/biometrics2/ui/model/CredentialModelTest.kt b/tests/unit/src/com/android/settings/biometrics2/ui/model/CredentialModelTest.kt
new file mode 100644
index 0000000..d718db6
--- /dev/null
+++ b/tests/unit/src/com/android/settings/biometrics2/ui/model/CredentialModelTest.kt
@@ -0,0 +1,183 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.biometrics2.ui.model
+
+import android.content.Intent
+import android.os.Bundle
+import android.os.SystemClock
+import android.os.UserHandle
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.android.settings.biometrics.BiometricEnrollBase
+import com.android.settings.password.ChooseLockSettingsHelper
+import com.google.common.truth.Truth
+import org.junit.Test
+import org.junit.runner.RunWith
+import java.util.Arrays
+
+@RunWith(AndroidJUnit4::class)
+class CredentialModelTest {
+
+ private val clock = SystemClock.elapsedRealtimeClock()
+
+ @Test
+ fun testNullBundle() {
+ val credentialModel = CredentialModel(null, clock)
+ Truth.assertThat(credentialModel.userId).isEqualTo(UserHandle.myUserId())
+ }
+
+ @Test
+ fun testSameValueFromBundle() {
+ val bundle = newCredentialModelIntentExtras(1234, 6677L, byteArrayOf(33, 44, 55), 987654321)
+ val model1 = CredentialModel(bundle, clock)
+ val model2 = CredentialModel(model1.bundle, clock)
+ verifySameCredentialModels(model1, model2)
+ }
+
+ @Test
+ fun testSameValueFromBundle_nullToken() {
+ val bundle = newCredentialModelIntentExtras(22, 33L, null, 21L)
+ val model1 = CredentialModel(bundle, clock)
+ val model2 = CredentialModel(model1.bundle, clock)
+ verifySameCredentialModels(model1, model2)
+ }
+
+ companion object {
+ @JvmStatic
+ fun newCredentialModelIntentExtras(
+ userId: Int, challenge: Long,
+ token: ByteArray?, gkPwHandle: Long
+ ): Bundle {
+ val bundle = Bundle()
+ bundle.putInt(Intent.EXTRA_USER_ID, userId)
+ bundle.putLong(BiometricEnrollBase.EXTRA_KEY_CHALLENGE, challenge)
+ bundle.putByteArray(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, token)
+ bundle.putLong(ChooseLockSettingsHelper.EXTRA_KEY_GK_PW_HANDLE, gkPwHandle)
+ return bundle
+ }
+
+ @JvmStatic
+ fun newValidTokenCredentialIntentExtras(userId: Int): Bundle {
+ return newCredentialModelIntentExtras(
+ userId, 1L, byteArrayOf(0, 1, 2),
+ CredentialModel.INVALID_GK_PW_HANDLE
+ )
+ }
+
+ @JvmStatic
+ fun newOnlySensorValidCredentialIntentExtras(userId: Int): Bundle {
+ return newCredentialModelIntentExtras(
+ userId, CredentialModel.INVALID_CHALLENGE, null,
+ CredentialModel.INVALID_GK_PW_HANDLE
+ )
+ }
+
+ @JvmStatic
+ fun newGkPwHandleCredentialIntentExtras(userId: Int, gkPwHandle: Long): Bundle {
+ return newCredentialModelIntentExtras(
+ userId,
+ CredentialModel.INVALID_CHALLENGE,
+ null,
+ gkPwHandle
+ )
+ }
+
+ private fun checkBundleLongValue(
+ bundle1: Bundle, bundle2: Bundle,
+ key: String
+ ) {
+ if (!bundle1.containsKey(key)) {
+ return
+ }
+ val value1 = bundle1.getInt(key)
+ val value2 = bundle2.getInt(key)
+ Truth.assertWithMessage(
+ "bundle not match, key:" + key + ", value1:" + value1 + ", value2:"
+ + value2
+ ).that(value1).isEqualTo(value2)
+ }
+
+ private fun checkBundleIntValue(
+ bundle1: Bundle, bundle2: Bundle,
+ key: String
+ ) {
+ if (!bundle1.containsKey(key)) {
+ return
+ }
+ val value1 = bundle1.getLong(key)
+ val value2 = bundle2.getLong(key)
+ Truth.assertWithMessage(
+ "bundle not match, key:" + key + ", value1:" + value1 + ", value2:"
+ + value2
+ ).that(value1).isEqualTo(value2)
+ }
+
+ private fun checkBundleByteArrayValue(
+ bundle1: Bundle, bundle2: Bundle,
+ key: String
+ ) {
+ if (!bundle1.containsKey(key)) {
+ return
+ }
+ val value1 = bundle1.getByteArray(key)
+ val value2 = bundle2.getByteArray(key)
+ val errMsg = ("bundle not match, key:" + key + ", value1:" + Arrays.toString(value1)
+ + ", value2:" + Arrays.toString(value2))
+ if (value1 == null) {
+ Truth.assertWithMessage(errMsg).that(value2).isNull()
+ } else {
+ Truth.assertWithMessage(errMsg).that(value1.size).isEqualTo(
+ value2!!.size
+ )
+ for (i in value1.indices) {
+ Truth.assertWithMessage(errMsg).that(value1[i]).isEqualTo(
+ value2[i]
+ )
+ }
+ }
+ }
+
+ fun verifySameCredentialModels(
+ model1: CredentialModel,
+ model2: CredentialModel
+ ) {
+ Truth.assertThat(model1.userId).isEqualTo(model2.userId)
+ Truth.assertThat(model1.challenge).isEqualTo(model2.challenge)
+ Truth.assertThat(model1.gkPwHandle).isEqualTo(model2.gkPwHandle)
+ val token1 = model1.token
+ val token2 = model2.token
+ if (token1 == null) {
+ Truth.assertThat(token2).isNull()
+ } else {
+ Truth.assertThat(token2).isNotNull()
+ Truth.assertThat(token1.size).isEqualTo(token2!!.size)
+ for (i in token1.indices) {
+ Truth.assertThat(token1[i]).isEqualTo(
+ token2[i]
+ )
+ }
+ }
+ val bundle1 = model1.bundle
+ val bundle2 = model2.bundle
+ val keySet1 = bundle1.keySet()
+ Truth.assertThat(keySet1 == bundle2.keySet()).isTrue()
+ checkBundleIntValue(bundle1, bundle2, Intent.EXTRA_USER_ID)
+ checkBundleIntValue(bundle1, bundle2, BiometricEnrollBase.EXTRA_KEY_SENSOR_ID)
+ checkBundleLongValue(bundle1, bundle2, BiometricEnrollBase.EXTRA_KEY_CHALLENGE)
+ checkBundleByteArrayValue(bundle1, bundle2, BiometricEnrollBase.EXTRA_KEY_CHALLENGE)
+ checkBundleLongValue(bundle1, bundle2, ChooseLockSettingsHelper.EXTRA_KEY_GK_PW_HANDLE)
+ }
+ }
+}
diff --git a/tests/unit/src/com/android/settings/biometrics2/ui/model/EnrollmentRequestTest.java b/tests/unit/src/com/android/settings/biometrics2/ui/model/EnrollmentRequestTest.java
deleted file mode 100644
index f060815..0000000
--- a/tests/unit/src/com/android/settings/biometrics2/ui/model/EnrollmentRequestTest.java
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * Copyright (C) 2023 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.biometrics2.ui.model;
-
-import static com.android.settings.biometrics.BiometricEnrollActivity.EXTRA_SKIP_INTRO;
-import static com.android.settings.biometrics2.ui.model.EnrollmentRequest.EXTRA_SKIP_FIND_SENSOR;
-
-import static com.google.android.setupcompat.util.WizardManagerHelper.EXTRA_IS_DEFERRED_SETUP;
-import static com.google.android.setupcompat.util.WizardManagerHelper.EXTRA_IS_PORTAL_SETUP;
-import static com.google.android.setupcompat.util.WizardManagerHelper.EXTRA_IS_SETUP_FLOW;
-import static com.google.android.setupcompat.util.WizardManagerHelper.EXTRA_IS_SUW_SUGGESTED_ACTION_FLOW;
-import static com.google.common.truth.Truth.assertThat;
-
-import android.annotation.NonNull;
-import android.content.Context;
-import android.content.Intent;
-import android.os.Bundle;
-
-import androidx.test.core.app.ApplicationProvider;
-import androidx.test.ext.junit.runners.AndroidJUnit4;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith(AndroidJUnit4.class)
-public class EnrollmentRequestTest {
-
- @NonNull
- private final Context mContext = ApplicationProvider.getApplicationContext();
-
- @Test
- public void testIsSuw() {
- // Default false
- assertThat(new EnrollmentRequest(new Intent(), mContext, true).isSuw()).isFalse();
- assertThat(new EnrollmentRequest(new Intent(), mContext, false).isSuw()).isFalse();
-
- final Intent trueIntent = new Intent();
- trueIntent.putExtra(EXTRA_IS_SETUP_FLOW, true);
- assertThat(new EnrollmentRequest(trueIntent, mContext, true).isSuw()).isTrue();
- assertThat(new EnrollmentRequest(trueIntent, mContext, false).isSuw()).isFalse();
-
- final Intent falseIntent = new Intent();
- trueIntent.putExtra(EXTRA_IS_SETUP_FLOW, false);
- assertThat(new EnrollmentRequest(falseIntent, mContext, true).isSuw()).isFalse();
- assertThat(new EnrollmentRequest(falseIntent, mContext, false).isSuw()).isFalse();
- }
-
- @Test
- public void testIsAfterSuwOrSuwSuggestedAction() {
- // Default false
- assertThat(new EnrollmentRequest(new Intent(), mContext, true)
- .isAfterSuwOrSuwSuggestedAction()).isFalse();
- assertThat(new EnrollmentRequest(new Intent(), mContext, false)
- .isAfterSuwOrSuwSuggestedAction()).isFalse();
-
- final Intent deferredTrueIntent = new Intent();
- deferredTrueIntent.putExtra(EXTRA_IS_DEFERRED_SETUP, true);
- assertThat(new EnrollmentRequest(deferredTrueIntent, mContext, true)
- .isAfterSuwOrSuwSuggestedAction()).isTrue();
- assertThat(new EnrollmentRequest(deferredTrueIntent, mContext, false)
- .isAfterSuwOrSuwSuggestedAction()).isFalse();
-
- final Intent deferredFalseIntent = new Intent();
- deferredFalseIntent.putExtra(EXTRA_IS_DEFERRED_SETUP, false);
- assertThat(new EnrollmentRequest(deferredFalseIntent, mContext, false)
- .isAfterSuwOrSuwSuggestedAction()).isFalse();
- assertThat(new EnrollmentRequest(deferredFalseIntent, mContext, false)
- .isAfterSuwOrSuwSuggestedAction()).isFalse();
-
- final Intent portalTrueIntent = new Intent();
- portalTrueIntent.putExtra(EXTRA_IS_PORTAL_SETUP, true);
- assertThat(new EnrollmentRequest(portalTrueIntent, mContext, true)
- .isAfterSuwOrSuwSuggestedAction()).isTrue();
- assertThat(new EnrollmentRequest(portalTrueIntent, mContext, false)
- .isAfterSuwOrSuwSuggestedAction()).isFalse();
-
- final Intent portalFalseIntent = new Intent();
- portalFalseIntent.putExtra(EXTRA_IS_PORTAL_SETUP, false);
- assertThat(new EnrollmentRequest(portalFalseIntent, mContext, false)
- .isAfterSuwOrSuwSuggestedAction()).isFalse();
- assertThat(new EnrollmentRequest(portalFalseIntent, mContext, false)
- .isAfterSuwOrSuwSuggestedAction()).isFalse();
-
- final Intent suggestedTrueIntent = new Intent();
- suggestedTrueIntent.putExtra(EXTRA_IS_SUW_SUGGESTED_ACTION_FLOW, true);
- assertThat(new EnrollmentRequest(suggestedTrueIntent, mContext, true)
- .isAfterSuwOrSuwSuggestedAction()).isTrue();
- assertThat(new EnrollmentRequest(suggestedTrueIntent, mContext, false)
- .isAfterSuwOrSuwSuggestedAction()).isFalse();
-
- final Intent suggestedFalseIntent = new Intent();
- suggestedFalseIntent.putExtra(EXTRA_IS_SUW_SUGGESTED_ACTION_FLOW, false);
- assertThat(new EnrollmentRequest(suggestedFalseIntent, mContext, false)
- .isAfterSuwOrSuwSuggestedAction()).isFalse();
- assertThat(new EnrollmentRequest(suggestedFalseIntent, mContext, false)
- .isAfterSuwOrSuwSuggestedAction()).isFalse();
- }
-
- @Test
- public void testGetSuwExtras_inSuw() {
- final Intent suwIntent = new Intent();
- suwIntent.putExtra(EXTRA_IS_SETUP_FLOW, true);
- final EnrollmentRequest setupRequest = new EnrollmentRequest(suwIntent, mContext, true);
-
- final Bundle bundle = setupRequest.getSuwExtras();
- assertThat(bundle).isNotNull();
- assertThat(bundle.size()).isAtLeast(1);
- assertThat(bundle.getBoolean(EXTRA_IS_SETUP_FLOW)).isTrue();
- }
-
- @Test
- public void testGetSuwExtras_notInSuw() {
- final Intent suwIntent = new Intent();
- suwIntent.putExtra(EXTRA_IS_SETUP_FLOW, true);
- final EnrollmentRequest setupRequest = new EnrollmentRequest(suwIntent, mContext, false);
-
- final Bundle bundle = setupRequest.getSuwExtras();
- assertThat(bundle).isNotNull();
- assertThat(bundle.size()).isEqualTo(0);
- }
-
- @Test
- public void testIsSkipIntro() {
- // Default false
- assertThat(new EnrollmentRequest(new Intent(), mContext, true).isSkipIntro()).isFalse();
- assertThat(new EnrollmentRequest(new Intent(), mContext, false).isSkipIntro()).isFalse();
-
- final Intent trueIntent = new Intent();
- trueIntent.putExtra(EXTRA_SKIP_INTRO, true);
- assertThat(new EnrollmentRequest(trueIntent, mContext, true).isSkipIntro()).isTrue();
- assertThat(new EnrollmentRequest(trueIntent, mContext, false).isSkipIntro()).isTrue();
-
- final Intent falseIntent = new Intent();
- falseIntent.putExtra(EXTRA_SKIP_INTRO, false);
- assertThat(new EnrollmentRequest(falseIntent, mContext, false).isSkipIntro()).isFalse();
- assertThat(new EnrollmentRequest(falseIntent, mContext, false).isSkipIntro()).isFalse();
- }
-
- @Test
- public void testIsSkipFindSensor() {
- // Default false
- assertThat(new EnrollmentRequest(new Intent(), mContext, true).isSkipFindSensor())
- .isFalse();
- assertThat(new EnrollmentRequest(new Intent(), mContext, false).isSkipFindSensor())
- .isFalse();
-
- final Intent trueIntent = new Intent();
- trueIntent.putExtra(EXTRA_SKIP_FIND_SENSOR, true);
- assertThat(new EnrollmentRequest(trueIntent, mContext, true).isSkipFindSensor()).isTrue();
- assertThat(new EnrollmentRequest(trueIntent, mContext, false).isSkipFindSensor()).isTrue();
-
- final Intent falseIntent = new Intent();
- falseIntent.putExtra(EXTRA_SKIP_FIND_SENSOR, false);
- assertThat(new EnrollmentRequest(falseIntent, mContext, false).isSkipFindSensor())
- .isFalse();
- assertThat(new EnrollmentRequest(falseIntent, mContext, false).isSkipFindSensor())
- .isFalse();
- }
-
-}
diff --git a/tests/unit/src/com/android/settings/biometrics2/ui/model/EnrollmentRequestTest.kt b/tests/unit/src/com/android/settings/biometrics2/ui/model/EnrollmentRequestTest.kt
new file mode 100644
index 0000000..b301433
--- /dev/null
+++ b/tests/unit/src/com/android/settings/biometrics2/ui/model/EnrollmentRequestTest.kt
@@ -0,0 +1,175 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.biometrics2.ui.model
+
+import android.content.Context
+import android.content.Intent
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.android.settings.biometrics.BiometricEnrollActivity
+import com.google.android.setupcompat.util.WizardManagerHelper
+import com.google.common.truth.Truth
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@RunWith(AndroidJUnit4::class)
+class EnrollmentRequestTest {
+
+ private val context = ApplicationProvider.getApplicationContext<Context>()
+
+ @Test
+ fun testIsSuw() {
+ // Default false
+ Truth.assertThat(EnrollmentRequest(Intent(), context, true).isSuw).isFalse()
+ Truth.assertThat(EnrollmentRequest(Intent(), context, false).isSuw).isFalse()
+ val trueIntent = Intent()
+ trueIntent.putExtra(WizardManagerHelper.EXTRA_IS_SETUP_FLOW, true)
+ Truth.assertThat(EnrollmentRequest(trueIntent, context, true).isSuw).isTrue()
+ Truth.assertThat(EnrollmentRequest(trueIntent, context, false).isSuw).isFalse()
+ val falseIntent = Intent()
+ trueIntent.putExtra(WizardManagerHelper.EXTRA_IS_SETUP_FLOW, false)
+ Truth.assertThat(EnrollmentRequest(falseIntent, context, true).isSuw).isFalse()
+ Truth.assertThat(EnrollmentRequest(falseIntent, context, false).isSuw).isFalse()
+ }
+
+ @Test
+ fun testIsAfterSuwOrSuwSuggestedAction() {
+ // Default false
+ Truth.assertThat(
+ EnrollmentRequest(Intent(), context, true)
+ .isAfterSuwOrSuwSuggestedAction
+ ).isFalse()
+ Truth.assertThat(
+ EnrollmentRequest(Intent(), context, false)
+ .isAfterSuwOrSuwSuggestedAction
+ ).isFalse()
+ val deferredTrueIntent = Intent()
+ deferredTrueIntent.putExtra(WizardManagerHelper.EXTRA_IS_DEFERRED_SETUP, true)
+ Truth.assertThat(
+ EnrollmentRequest(deferredTrueIntent, context, true)
+ .isAfterSuwOrSuwSuggestedAction
+ ).isTrue()
+ Truth.assertThat(
+ EnrollmentRequest(deferredTrueIntent, context, false)
+ .isAfterSuwOrSuwSuggestedAction
+ ).isFalse()
+ val deferredFalseIntent = Intent()
+ deferredFalseIntent.putExtra(WizardManagerHelper.EXTRA_IS_DEFERRED_SETUP, false)
+ Truth.assertThat(
+ EnrollmentRequest(deferredFalseIntent, context, false)
+ .isAfterSuwOrSuwSuggestedAction
+ ).isFalse()
+ Truth.assertThat(
+ EnrollmentRequest(deferredFalseIntent, context, false)
+ .isAfterSuwOrSuwSuggestedAction
+ ).isFalse()
+ val portalTrueIntent = Intent()
+ portalTrueIntent.putExtra(WizardManagerHelper.EXTRA_IS_PORTAL_SETUP, true)
+ Truth.assertThat(
+ EnrollmentRequest(portalTrueIntent, context, true)
+ .isAfterSuwOrSuwSuggestedAction
+ ).isTrue()
+ Truth.assertThat(
+ EnrollmentRequest(portalTrueIntent, context, false)
+ .isAfterSuwOrSuwSuggestedAction
+ ).isFalse()
+ val portalFalseIntent = Intent()
+ portalFalseIntent.putExtra(WizardManagerHelper.EXTRA_IS_PORTAL_SETUP, false)
+ Truth.assertThat(
+ EnrollmentRequest(portalFalseIntent, context, false)
+ .isAfterSuwOrSuwSuggestedAction
+ ).isFalse()
+ Truth.assertThat(
+ EnrollmentRequest(portalFalseIntent, context, false)
+ .isAfterSuwOrSuwSuggestedAction
+ ).isFalse()
+ val suggestedTrueIntent = Intent()
+ suggestedTrueIntent.putExtra(WizardManagerHelper.EXTRA_IS_SUW_SUGGESTED_ACTION_FLOW, true)
+ Truth.assertThat(
+ EnrollmentRequest(suggestedTrueIntent, context, true)
+ .isAfterSuwOrSuwSuggestedAction
+ ).isTrue()
+ Truth.assertThat(
+ EnrollmentRequest(suggestedTrueIntent, context, false)
+ .isAfterSuwOrSuwSuggestedAction
+ ).isFalse()
+ val suggestedFalseIntent = Intent()
+ suggestedFalseIntent.putExtra(WizardManagerHelper.EXTRA_IS_SUW_SUGGESTED_ACTION_FLOW, false)
+ Truth.assertThat(
+ EnrollmentRequest(suggestedFalseIntent, context, false)
+ .isAfterSuwOrSuwSuggestedAction
+ ).isFalse()
+ Truth.assertThat(
+ EnrollmentRequest(suggestedFalseIntent, context, false)
+ .isAfterSuwOrSuwSuggestedAction
+ ).isFalse()
+ }
+
+ @Test
+ fun testGetSuwExtras_inSuw() {
+ val suwIntent = Intent()
+ suwIntent.putExtra(WizardManagerHelper.EXTRA_IS_SETUP_FLOW, true)
+ val setupRequest = EnrollmentRequest(suwIntent, context, true)
+ val bundle = setupRequest.suwExtras
+ Truth.assertThat(bundle).isNotNull()
+ Truth.assertThat(bundle.size()).isAtLeast(1)
+ Truth.assertThat(bundle.getBoolean(WizardManagerHelper.EXTRA_IS_SETUP_FLOW)).isTrue()
+ }
+
+ @Test
+ fun testGetSuwExtras_notInSuw() {
+ val suwIntent = Intent()
+ suwIntent.putExtra(WizardManagerHelper.EXTRA_IS_SETUP_FLOW, true)
+ val setupRequest = EnrollmentRequest(suwIntent, context, false)
+ val bundle = setupRequest.suwExtras
+ Truth.assertThat(bundle).isNotNull()
+ Truth.assertThat(bundle.size()).isEqualTo(0)
+ }
+
+ @Test
+ fun testIsSkipIntro() {
+ // Default false
+ Truth.assertThat(EnrollmentRequest(Intent(), context, true).isSkipIntro).isFalse()
+ Truth.assertThat(EnrollmentRequest(Intent(), context, false).isSkipIntro).isFalse()
+ val trueIntent = Intent()
+ trueIntent.putExtra(BiometricEnrollActivity.EXTRA_SKIP_INTRO, true)
+ Truth.assertThat(EnrollmentRequest(trueIntent, context, true).isSkipIntro).isTrue()
+ Truth.assertThat(EnrollmentRequest(trueIntent, context, false).isSkipIntro).isTrue()
+ val falseIntent = Intent()
+ falseIntent.putExtra(BiometricEnrollActivity.EXTRA_SKIP_INTRO, false)
+ Truth.assertThat(EnrollmentRequest(falseIntent, context, false).isSkipIntro).isFalse()
+ Truth.assertThat(EnrollmentRequest(falseIntent, context, false).isSkipIntro).isFalse()
+ }
+
+ @Test
+ fun testIsSkipFindSensor() {
+ // Default false
+ Truth.assertThat(EnrollmentRequest(Intent(), context, true).isSkipFindSensor)
+ .isFalse()
+ Truth.assertThat(EnrollmentRequest(Intent(), context, false).isSkipFindSensor)
+ .isFalse()
+ val trueIntent = Intent()
+ trueIntent.putExtra(EnrollmentRequest.EXTRA_SKIP_FIND_SENSOR, true)
+ Truth.assertThat(EnrollmentRequest(trueIntent, context, true).isSkipFindSensor).isTrue()
+ Truth.assertThat(EnrollmentRequest(trueIntent, context, false).isSkipFindSensor).isTrue()
+ val falseIntent = Intent()
+ falseIntent.putExtra(EnrollmentRequest.EXTRA_SKIP_FIND_SENSOR, false)
+ Truth.assertThat(EnrollmentRequest(falseIntent, context, false).isSkipFindSensor)
+ .isFalse()
+ Truth.assertThat(EnrollmentRequest(falseIntent, context, false).isSkipFindSensor)
+ .isFalse()
+ }
+}
diff --git a/tests/unit/src/com/android/settings/biometrics2/ui/viewmodel/FingerprintEnrollIntroViewModelTest.java b/tests/unit/src/com/android/settings/biometrics2/ui/viewmodel/FingerprintEnrollIntroViewModelTest.java
index 73ff2e2..12b860b 100644
--- a/tests/unit/src/com/android/settings/biometrics2/ui/viewmodel/FingerprintEnrollIntroViewModelTest.java
+++ b/tests/unit/src/com/android/settings/biometrics2/ui/viewmodel/FingerprintEnrollIntroViewModelTest.java
@@ -18,8 +18,8 @@
import static android.hardware.fingerprint.FingerprintSensorProperties.TYPE_UDFPS_OPTICAL;
-import static com.android.settings.biometrics2.ui.model.FingerprintEnrollIntroStatus.FINGERPRINT_ENROLLABLE_ERROR_REACH_MAX;
-import static com.android.settings.biometrics2.ui.model.FingerprintEnrollIntroStatus.FINGERPRINT_ENROLLABLE_OK;
+import static com.android.settings.biometrics2.ui.model.FingerprintEnrollable.FINGERPRINT_ENROLLABLE_ERROR_REACH_MAX;
+import static com.android.settings.biometrics2.ui.model.FingerprintEnrollable.FINGERPRINT_ENROLLABLE_OK;
import static com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollIntroViewModel.FINGERPRINT_ENROLL_INTRO_ACTION_CONTINUE_ENROLL;
import static com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollIntroViewModel.FINGERPRINT_ENROLL_INTRO_ACTION_DONE_AND_FINISH;
import static com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollIntroViewModel.FINGERPRINT_ENROLL_INTRO_ACTION_SKIP_OR_CANCEL;
diff --git a/tests/unit/src/com/android/settings/biometrics2/utils/EnrollmentRequestUtils.java b/tests/unit/src/com/android/settings/biometrics2/utils/EnrollmentRequestUtils.java
deleted file mode 100644
index a97f223..0000000
--- a/tests/unit/src/com/android/settings/biometrics2/utils/EnrollmentRequestUtils.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Copyright (C) 2023 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.biometrics2.utils;
-
-import static com.android.settings.biometrics.BiometricEnrollBase.EXTRA_FROM_SETTINGS_SUMMARY;
-
-import static com.google.android.setupcompat.util.WizardManagerHelper.EXTRA_IS_DEFERRED_SETUP;
-import static com.google.android.setupcompat.util.WizardManagerHelper.EXTRA_IS_FIRST_RUN;
-import static com.google.android.setupcompat.util.WizardManagerHelper.EXTRA_IS_PORTAL_SETUP;
-import static com.google.android.setupcompat.util.WizardManagerHelper.EXTRA_IS_SETUP_FLOW;
-import static com.google.android.setupcompat.util.WizardManagerHelper.EXTRA_IS_SUW_SUGGESTED_ACTION_FLOW;
-import static com.google.android.setupcompat.util.WizardManagerHelper.EXTRA_THEME;
-
-import android.content.Context;
-import android.content.Intent;
-import android.text.TextUtils;
-
-import androidx.annotation.NonNull;
-
-import com.android.settings.biometrics2.ui.model.EnrollmentRequest;
-
-public class EnrollmentRequestUtils {
-
- @NonNull
- public static EnrollmentRequest newAllFalseRequest(@NonNull Context context) {
- return newRequest(context, false, false, false, false, false, false, null);
- }
-
- @NonNull
- public static EnrollmentRequest newIsSuwRequest(@NonNull Context context) {
- return newRequest(context, true, false, false, false, false, false, null);
- }
-
- @NonNull
- public static EnrollmentRequest newIsSuwDeferredRequest(@NonNull Context context) {
- return newRequest(context, true, true, false, false, false, false, null);
- }
-
- @NonNull
- public static EnrollmentRequest newIsSuwPortalRequest(@NonNull Context context) {
- return newRequest(context, true, false, true, false, false, false, null);
- }
-
- @NonNull
- public static EnrollmentRequest newIsSuwSuggestedActionFlowRequest(
- @NonNull Context context) {
- return newRequest(context, true, false, false, true, false, false, null);
- }
-
- @NonNull
- public static EnrollmentRequest newRequest(@NonNull Context context, boolean isSuw,
- boolean isSuwDeferred, boolean isSuwPortal, boolean isSuwSuggestedActionFlow,
- boolean isSuwFirstRun, boolean isFromSettingsSummery, String theme) {
- Intent i = new Intent();
- i.putExtra(EXTRA_IS_SETUP_FLOW, isSuw);
- i.putExtra(EXTRA_IS_DEFERRED_SETUP, isSuwDeferred);
- i.putExtra(EXTRA_IS_PORTAL_SETUP, isSuwPortal);
- i.putExtra(EXTRA_IS_SUW_SUGGESTED_ACTION_FLOW, isSuwSuggestedActionFlow);
- i.putExtra(EXTRA_IS_FIRST_RUN, isSuwFirstRun);
- i.putExtra(EXTRA_FROM_SETTINGS_SUMMARY, isFromSettingsSummery);
- if (!TextUtils.isEmpty(theme)) {
- i.putExtra(EXTRA_THEME, theme);
- }
- return new EnrollmentRequest(i, context, true);
- }
-
-}
diff --git a/tests/unit/src/com/android/settings/biometrics2/utils/EnrollmentRequestUtils.kt b/tests/unit/src/com/android/settings/biometrics2/utils/EnrollmentRequestUtils.kt
new file mode 100644
index 0000000..755f6d0
--- /dev/null
+++ b/tests/unit/src/com/android/settings/biometrics2/utils/EnrollmentRequestUtils.kt
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.biometrics2.utils
+
+import android.content.Context
+import android.content.Intent
+import android.text.TextUtils
+import com.android.settings.biometrics.BiometricEnrollBase
+import com.android.settings.biometrics2.ui.model.EnrollmentRequest
+import com.google.android.setupcompat.util.WizardManagerHelper
+
+object EnrollmentRequestUtils {
+ @JvmStatic
+ fun newAllFalseRequest(context: Context): EnrollmentRequest {
+ return newRequest(
+ context = context,
+ isSuw = false,
+ isSuwDeferred = false,
+ isSuwPortal = false,
+ isSuwSuggestedActionFlow = false,
+ isSuwFirstRun = false,
+ isFromSettingsSummery = false)
+ }
+
+ @JvmStatic
+ fun newIsSuwRequest(context: Context): EnrollmentRequest {
+ return newRequest(
+ context = context,
+ isSuw = true,
+ isSuwDeferred = false,
+ isSuwPortal = false,
+ isSuwSuggestedActionFlow = false,
+ isSuwFirstRun = false,
+ isFromSettingsSummery = false)
+ }
+
+ @JvmStatic
+ fun newIsSuwDeferredRequest(context: Context): EnrollmentRequest {
+ return newRequest(
+ context = context,
+ isSuw = true,
+ isSuwDeferred = true,
+ isSuwPortal = false,
+ isSuwSuggestedActionFlow = false,
+ isSuwFirstRun = false,
+ isFromSettingsSummery = false, null)
+ }
+
+ @JvmStatic
+ fun newIsSuwPortalRequest(context: Context): EnrollmentRequest {
+ return newRequest(
+ context = context,
+ isSuw = true,
+ isSuwDeferred = false,
+ isSuwPortal = true,
+ isSuwSuggestedActionFlow = false,
+ isSuwFirstRun = false,
+ isFromSettingsSummery = false)
+ }
+
+ @JvmStatic
+ fun newIsSuwSuggestedActionFlowRequest(
+ context: Context
+ ): EnrollmentRequest {
+ return newRequest(
+ context = context,
+ isSuw = true,
+ isSuwDeferred = false,
+ isSuwPortal = false,
+ isSuwSuggestedActionFlow = true,
+ isSuwFirstRun = false,
+ isFromSettingsSummery = false)
+ }
+
+ fun newRequest(
+ context: Context,
+ isSuw: Boolean,
+ isSuwDeferred: Boolean,
+ isSuwPortal: Boolean,
+ isSuwSuggestedActionFlow: Boolean,
+ isSuwFirstRun: Boolean,
+ isFromSettingsSummery: Boolean,
+ theme: String? = null
+ ): EnrollmentRequest {
+ val i = Intent()
+ i.putExtra(WizardManagerHelper.EXTRA_IS_SETUP_FLOW, isSuw)
+ i.putExtra(WizardManagerHelper.EXTRA_IS_DEFERRED_SETUP, isSuwDeferred)
+ i.putExtra(WizardManagerHelper.EXTRA_IS_PORTAL_SETUP, isSuwPortal)
+ i.putExtra(WizardManagerHelper.EXTRA_IS_SUW_SUGGESTED_ACTION_FLOW, isSuwSuggestedActionFlow)
+ i.putExtra(WizardManagerHelper.EXTRA_IS_FIRST_RUN, isSuwFirstRun)
+ i.putExtra(BiometricEnrollBase.EXTRA_FROM_SETTINGS_SUMMARY, isFromSettingsSummery)
+ if (!TextUtils.isEmpty(theme)) {
+ i.putExtra(WizardManagerHelper.EXTRA_THEME, theme)
+ }
+ return EnrollmentRequest(i, context, true)
+ }
+}