[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/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)
+ }
+}