Merge "Fix icon touch dialog in Enrolling page" into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
3e41d936b3
@@ -29,9 +29,16 @@ import static com.android.settings.biometrics2.utils.FingerprintRepositoryUtils.
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.hardware.biometrics.SensorProperties;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal;
|
||||
import android.hardware.fingerprint.IFingerprintAuthenticatorsRegisteredCallback;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
@@ -46,6 +53,8 @@ import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class FingerprintRepositoryTest {
|
||||
|
||||
@@ -139,4 +148,56 @@ public class FingerprintRepositoryTest {
|
||||
assertThat(repository.getMaxFingerprintsInSuw(mResources)).isEqualTo(20);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFirstFingerprintSensorPropertiesInternal() {
|
||||
final ArrayList<FingerprintSensorPropertiesInternal> props = new ArrayList<>();
|
||||
final FingerprintSensorPropertiesInternal prop = new FingerprintSensorPropertiesInternal(
|
||||
0 /* sensorId */,
|
||||
SensorProperties.STRENGTH_STRONG,
|
||||
5,
|
||||
new ArrayList<>() /* componentInfo */,
|
||||
TYPE_UDFPS_OPTICAL,
|
||||
true /* resetLockoutRequiresHardwareAuthToken */);
|
||||
props.add(prop);
|
||||
doAnswer(invocation -> {
|
||||
final IFingerprintAuthenticatorsRegisteredCallback callback =
|
||||
invocation.getArgument(0);
|
||||
callback.onAllAuthenticatorsRegistered(props);
|
||||
return null;
|
||||
}).when(mFingerprintManager).addAuthenticatorsRegisteredCallback(any());
|
||||
|
||||
final FingerprintRepository repository = new FingerprintRepository(mFingerprintManager);
|
||||
assertThat(repository.getFirstFingerprintSensorPropertiesInternal()).isEqualTo(prop);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetEnrollStageCount() {
|
||||
final FingerprintRepository repository = newFingerprintRepository(mFingerprintManager,
|
||||
TYPE_UNKNOWN, 999);
|
||||
|
||||
final int expectedValue = 24;
|
||||
doReturn(expectedValue).when(mFingerprintManager).getEnrollStageCount();
|
||||
|
||||
assertThat(repository.getEnrollStageCount()).isEqualTo(expectedValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetEnrollStageThreshold() {
|
||||
final FingerprintRepository repository = newFingerprintRepository(mFingerprintManager,
|
||||
TYPE_UNKNOWN, 999);
|
||||
|
||||
final float expectedValue0 = 0.42f;
|
||||
final float expectedValue1 = 0.24f;
|
||||
final float expectedValue2 = 0.33f;
|
||||
final float expectedValue3 = 0.90f;
|
||||
doReturn(expectedValue0).when(mFingerprintManager).getEnrollStageThreshold(0);
|
||||
doReturn(expectedValue1).when(mFingerprintManager).getEnrollStageThreshold(1);
|
||||
doReturn(expectedValue2).when(mFingerprintManager).getEnrollStageThreshold(2);
|
||||
doReturn(expectedValue3).when(mFingerprintManager).getEnrollStageThreshold(3);
|
||||
|
||||
assertThat(repository.getEnrollStageThreshold(2)).isEqualTo(expectedValue2);
|
||||
assertThat(repository.getEnrollStageThreshold(1)).isEqualTo(expectedValue1);
|
||||
assertThat(repository.getEnrollStageThreshold(3)).isEqualTo(expectedValue3);
|
||||
assertThat(repository.getEnrollStageThreshold(0)).isEqualTo(expectedValue0);
|
||||
}
|
||||
}
|
||||
|
@@ -48,11 +48,10 @@ public class CredentialModelTest {
|
||||
|
||||
private final Clock mClock = SystemClock.elapsedRealtimeClock();
|
||||
|
||||
public static Bundle newCredentialModelIntentExtras(int userId, long challenge, int sensorId,
|
||||
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.putInt(EXTRA_KEY_SENSOR_ID, sensorId);
|
||||
bundle.putLong(EXTRA_KEY_CHALLENGE, challenge);
|
||||
bundle.putByteArray(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, token);
|
||||
bundle.putLong(ChooseLockSettingsHelper.EXTRA_KEY_GK_PW_HANDLE, gkPwHandle);
|
||||
@@ -60,17 +59,17 @@ public class CredentialModelTest {
|
||||
}
|
||||
|
||||
public static Bundle newValidTokenCredentialIntentExtras(int userId) {
|
||||
return newCredentialModelIntentExtras(userId, 1L, 1, new byte[] { 0, 1, 2 },
|
||||
return newCredentialModelIntentExtras(userId, 1L, new byte[] { 0, 1, 2 },
|
||||
INVALID_GK_PW_HANDLE);
|
||||
}
|
||||
|
||||
public static Bundle newOnlySensorValidCredentialIntentExtras(int userId) {
|
||||
return newCredentialModelIntentExtras(userId, INVALID_CHALLENGE, 1, null,
|
||||
return newCredentialModelIntentExtras(userId, INVALID_CHALLENGE, null,
|
||||
INVALID_GK_PW_HANDLE);
|
||||
}
|
||||
|
||||
public static Bundle newGkPwHandleCredentialIntentExtras(int userId, long gkPwHandle) {
|
||||
return newCredentialModelIntentExtras(userId, INVALID_CHALLENGE, 1, null, gkPwHandle);
|
||||
return newCredentialModelIntentExtras(userId, INVALID_CHALLENGE, null, gkPwHandle);
|
||||
}
|
||||
|
||||
private static void checkBundleLongValue(@NonNull Bundle bundle1, @NonNull Bundle bundle2,
|
||||
@@ -118,7 +117,6 @@ public class CredentialModelTest {
|
||||
@NonNull CredentialModel model2) {
|
||||
|
||||
assertThat(model1.getUserId()).isEqualTo(model2.getUserId());
|
||||
assertThat(model1.getSensorId()).isEqualTo(model2.getSensorId());
|
||||
assertThat(model1.getChallenge()).isEqualTo(model2.getChallenge());
|
||||
assertThat(model1.getGkPwHandle()).isEqualTo(model2.getGkPwHandle());
|
||||
|
||||
@@ -154,7 +152,7 @@ public class CredentialModelTest {
|
||||
|
||||
@Test
|
||||
public void testSameValueFromBundle() {
|
||||
final Bundle bundle = newCredentialModelIntentExtras(1234, 6677L, 1,
|
||||
final Bundle bundle = newCredentialModelIntentExtras(1234, 6677L,
|
||||
new byte[] { 33, 44, 55 }, 987654321);
|
||||
|
||||
final CredentialModel model1 = new CredentialModel(bundle, mClock);
|
||||
@@ -165,7 +163,7 @@ public class CredentialModelTest {
|
||||
|
||||
@Test
|
||||
public void testSameValueFromBundle_nullToken() {
|
||||
final Bundle bundle = newCredentialModelIntentExtras(22, 33L, 1, null, 21L);
|
||||
final Bundle bundle = newCredentialModelIntentExtras(22, 33L, null, 21L);
|
||||
|
||||
final CredentialModel model1 = new CredentialModel(bundle, mClock);
|
||||
final CredentialModel model2 = new CredentialModel(model1.getBundle(), mClock);
|
||||
|
@@ -22,10 +22,8 @@ import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_SOMETHING;
|
||||
import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
|
||||
|
||||
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.biometrics2.ui.model.CredentialModel.INVALID_SENSOR_ID;
|
||||
import static com.android.settings.biometrics2.ui.model.CredentialModelTest.newCredentialModelIntentExtras;
|
||||
import static com.android.settings.biometrics2.ui.model.CredentialModelTest.newGkPwHandleCredentialIntentExtras;
|
||||
import static com.android.settings.biometrics2.ui.model.CredentialModelTest.newOnlySensorValidCredentialIntentExtras;
|
||||
@@ -103,7 +101,7 @@ public class AutoCredentialViewModelTest {
|
||||
|
||||
@Test
|
||||
public void testSetCredentialModel_sameResultFromSavedInstanceOrIntent() {
|
||||
final Bundle extras = newCredentialModelIntentExtras(12, 33, 1, new byte[] { 2, 3 }, 3L);
|
||||
final Bundle extras = newCredentialModelIntentExtras(12, 33, new byte[] { 2, 3 }, 3L);
|
||||
|
||||
AutoCredentialViewModel viewModel2 = new AutoCredentialViewModel(
|
||||
ApplicationProvider.getApplicationContext(),
|
||||
@@ -115,18 +113,9 @@ public class AutoCredentialViewModelTest {
|
||||
mViewModel.onSaveInstanceState(savedInstance);
|
||||
viewModel2.setCredentialModel(savedInstance, new Intent());
|
||||
|
||||
final Bundle bundle1 = mViewModel.createCredentialIntentExtra();
|
||||
final Bundle bundle2 = viewModel2.createCredentialIntentExtra();
|
||||
assertThat(bundle1.getLong(EXTRA_KEY_GK_PW_HANDLE))
|
||||
.isEqualTo(bundle2.getLong(EXTRA_KEY_GK_PW_HANDLE));
|
||||
assertThat(bundle1.getLong(Intent.EXTRA_USER_ID))
|
||||
.isEqualTo(bundle2.getLong(Intent.EXTRA_USER_ID));
|
||||
assertThat(bundle1.getLong(EXTRA_KEY_CHALLENGE))
|
||||
.isEqualTo(bundle2.getLong(EXTRA_KEY_CHALLENGE));
|
||||
assertThat(bundle1.getInt(EXTRA_KEY_SENSOR_ID))
|
||||
.isEqualTo(bundle2.getInt(EXTRA_KEY_SENSOR_ID));
|
||||
final byte[] token1 = bundle1.getByteArray(EXTRA_KEY_CHALLENGE_TOKEN);
|
||||
final byte[] token2 = bundle2.getByteArray(EXTRA_KEY_CHALLENGE_TOKEN);
|
||||
assertThat(mViewModel.getUserId()).isEqualTo(viewModel2.getUserId());
|
||||
final byte[] token1 = mViewModel.getToken();
|
||||
final byte[] token2 = viewModel2.getToken();
|
||||
assertThat(token1).isNotNull();
|
||||
assertThat(token2).isNotNull();
|
||||
assertThat(token1.length).isEqualTo(token2.length);
|
||||
@@ -138,7 +127,7 @@ public class AutoCredentialViewModelTest {
|
||||
@Test
|
||||
public void testSetCredentialModel_sameResultFromSavedInstanceOrIntent_invalidValues() {
|
||||
final Bundle extras = newCredentialModelIntentExtras(UserHandle.USER_NULL,
|
||||
INVALID_CHALLENGE, INVALID_SENSOR_ID, null, INVALID_GK_PW_HANDLE);
|
||||
INVALID_CHALLENGE, null, INVALID_GK_PW_HANDLE);
|
||||
|
||||
AutoCredentialViewModel viewModel2 = new AutoCredentialViewModel(
|
||||
ApplicationProvider.getApplicationContext(),
|
||||
@@ -150,16 +139,10 @@ public class AutoCredentialViewModelTest {
|
||||
mViewModel.onSaveInstanceState(savedInstance);
|
||||
viewModel2.setCredentialModel(savedInstance, new Intent());
|
||||
|
||||
final Bundle bundle1 = mViewModel.createCredentialIntentExtra();
|
||||
final Bundle bundle2 = viewModel2.createCredentialIntentExtra();
|
||||
assertThat(bundle1.containsKey(EXTRA_KEY_GK_PW_HANDLE)).isFalse();
|
||||
assertThat(bundle2.containsKey(EXTRA_KEY_GK_PW_HANDLE)).isFalse();
|
||||
assertThat(bundle1.containsKey(EXTRA_KEY_CHALLENGE_TOKEN)).isFalse();
|
||||
assertThat(bundle2.containsKey(EXTRA_KEY_CHALLENGE_TOKEN)).isFalse();
|
||||
assertThat(bundle1.containsKey(EXTRA_KEY_SENSOR_ID)).isTrue();
|
||||
assertThat(bundle2.containsKey(EXTRA_KEY_SENSOR_ID)).isTrue();
|
||||
assertThat(bundle1.containsKey(Intent.EXTRA_USER_ID)).isFalse();
|
||||
assertThat(bundle2.containsKey(Intent.EXTRA_USER_ID)).isFalse();
|
||||
assertThat(mViewModel.getUserId()).isEqualTo(UserHandle.USER_NULL);
|
||||
assertThat(viewModel2.getUserId()).isEqualTo(UserHandle.USER_NULL);
|
||||
assertThat(mViewModel.getToken()).isNull();
|
||||
assertThat(viewModel2.getToken()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -316,12 +299,7 @@ public class AutoCredentialViewModelTest {
|
||||
assertThat(mViewModel.getGenerateChallengeFailedLiveData().getValue()).isNull();
|
||||
|
||||
// Check data inside CredentialModel
|
||||
final Bundle extras = mViewModel.createCredentialIntentExtra();
|
||||
assertThat(extras.getInt(EXTRA_KEY_SENSOR_ID)).isEqualTo(newSensorId);
|
||||
assertThat(extras.getLong(EXTRA_KEY_CHALLENGE)).isEqualTo(newChallenge);
|
||||
assertThat(extras.getByteArray(EXTRA_KEY_CHALLENGE_TOKEN)).isNotNull();
|
||||
assertThat(extras.getLong(EXTRA_KEY_GK_PW_HANDLE)).isEqualTo(INVALID_GK_PW_HANDLE);
|
||||
assertThat(extras.getLong(EXTRA_KEY_CHALLENGE)).isNotEqualTo(INVALID_CHALLENGE);
|
||||
assertThat(mViewModel.getToken()).isNotNull();
|
||||
assertThat(mChallengeGenerator.mCallbackRunCount).isEqualTo(1);
|
||||
assertThat(hasCalledRemoveGkPwHandle.get()).isFalse();
|
||||
|
||||
@@ -534,11 +512,7 @@ public class AutoCredentialViewModelTest {
|
||||
|
||||
assertThat(ret).isTrue();
|
||||
assertThat(mViewModel.getGenerateChallengeFailedLiveData().getValue()).isNull();
|
||||
final Bundle extras = mViewModel.createCredentialIntentExtra();
|
||||
assertThat(extras.getInt(EXTRA_KEY_SENSOR_ID)).isEqualTo(newSensorId);
|
||||
assertThat(extras.getLong(EXTRA_KEY_CHALLENGE)).isEqualTo(newChallenge);
|
||||
assertThat(extras.getByteArray(EXTRA_KEY_CHALLENGE_TOKEN)).isNotNull();
|
||||
assertThat(extras.getLong(EXTRA_KEY_GK_PW_HANDLE)).isEqualTo(INVALID_GK_PW_HANDLE);
|
||||
assertThat(mViewModel.getToken()).isNotNull();
|
||||
assertThat(mChallengeGenerator.mCallbackRunCount).isEqualTo(1);
|
||||
assertThat(hasCalledRemoveGkPwHandle.get()).isTrue();
|
||||
}
|
||||
@@ -571,17 +545,13 @@ public class AutoCredentialViewModelTest {
|
||||
|
||||
assertThat(ret).isTrue();
|
||||
assertThat(mViewModel.getGenerateChallengeFailedLiveData().getValue()).isNull();
|
||||
final Bundle extras = mViewModel.createCredentialIntentExtra();
|
||||
assertThat(extras.getInt(EXTRA_KEY_SENSOR_ID)).isEqualTo(newSensorId);
|
||||
assertThat(extras.getLong(EXTRA_KEY_CHALLENGE)).isEqualTo(newChallenge);
|
||||
assertThat(extras.getByteArray(EXTRA_KEY_CHALLENGE_TOKEN)).isNotNull();
|
||||
assertThat(extras.getLong(EXTRA_KEY_GK_PW_HANDLE)).isEqualTo(INVALID_GK_PW_HANDLE);
|
||||
assertThat(mViewModel.getToken()).isNotNull();
|
||||
assertThat(mChallengeGenerator.mCallbackRunCount).isEqualTo(1);
|
||||
assertThat(hasCalledRemoveGkPwHandle.get()).isTrue();
|
||||
}
|
||||
|
||||
public static class TestChallengeGenerator implements ChallengeGenerator {
|
||||
public int mSensorId = INVALID_SENSOR_ID;
|
||||
public int mSensorId = -1;
|
||||
public int mUserId = UserHandle.myUserId();
|
||||
public long mChallenge = INVALID_CHALLENGE;
|
||||
public int mCallbackRunCount = 0;
|
||||
|
@@ -0,0 +1,231 @@
|
||||
/*
|
||||
* 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.viewmodel;
|
||||
|
||||
import static android.hardware.fingerprint.FingerprintSensorProperties.TYPE_REAR;
|
||||
import static android.hardware.fingerprint.FingerprintSensorProperties.TYPE_UDFPS_OPTICAL;
|
||||
import static android.hardware.fingerprint.FingerprintSensorProperties.TYPE_UDFPS_ULTRASONIC;
|
||||
|
||||
import static com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollEnrollingViewModel.ErrorDialogData;
|
||||
import static com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollEnrollingViewModel.FINGERPRINT_ENROLL_ENROLLING_ACTION_DISMISS_ICON_TOUCH_DIALOG;
|
||||
import static com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollEnrollingViewModel.FINGERPRINT_ENROLL_ENROLLING_ACTION_SHOW_ICON_TOUCH_DIALOG;
|
||||
import static com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollEnrollingViewModel.FINGERPRINT_ENROLL_ENROLLING_CANCELED_BECAUSE_BACK_PRESSED;
|
||||
import static com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollEnrollingViewModel.FINGERPRINT_ENROLL_ENROLLING_CANCELED_BECAUSE_USER_SKIP;
|
||||
import static com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollEnrollingViewModel.FINGERPRINT_ERROR_DIALOG_ACTION_RESTART;
|
||||
import static com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollEnrollingViewModel.FINGERPRINT_ERROR_DIALOG_ACTION_SET_RESULT_FINISH;
|
||||
import static com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollEnrollingViewModel.FINGERPRINT_ERROR_DIALOG_ACTION_SET_RESULT_TIMEOUT;
|
||||
import static com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollEnrollingViewModel.FingerprintErrorDialogAction;
|
||||
import static com.android.settings.biometrics2.utils.FingerprintRepositoryUtils.newFingerprintRepository;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
|
||||
import android.app.Application;
|
||||
import android.hardware.biometrics.SensorProperties;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal;
|
||||
import android.hardware.fingerprint.IFingerprintAuthenticatorsRegisteredCallback;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.biometrics2.data.repository.FingerprintRepository;
|
||||
import com.android.settings.testutils.InstantTaskExecutorRule;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class FingerprintEnrollEnrollingViewModelTest {
|
||||
|
||||
private static final int TEST_USER_ID = 33;
|
||||
|
||||
@Rule
|
||||
public final MockitoRule mockito = MockitoJUnit.rule();
|
||||
@Rule
|
||||
public final InstantTaskExecutorRule mTaskExecutorRule = new InstantTaskExecutorRule();
|
||||
|
||||
@Mock
|
||||
private FingerprintManager mFingerprintManager;
|
||||
|
||||
private Application mApplication;
|
||||
private FingerprintEnrollEnrollingViewModel mViewModel;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mApplication = ApplicationProvider.getApplicationContext();
|
||||
mViewModel = new FingerprintEnrollEnrollingViewModel(
|
||||
mApplication,
|
||||
TEST_USER_ID,
|
||||
newFingerprintRepository(mFingerprintManager, TYPE_UDFPS_OPTICAL, 5)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShowErrorDialogLiveData() {
|
||||
assertThat(mViewModel.getErrorDialogLiveData().getValue()).isEqualTo(null);
|
||||
|
||||
final ErrorDialogData data = new ErrorDialogData("errMsg", "errTitle", 0);
|
||||
mViewModel.showErrorDialog(data);
|
||||
assertThat(mViewModel.getErrorDialogLiveData().getValue()).isEqualTo(data);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIconTouchDialog() {
|
||||
final LiveData<Integer> actionLiveData = mViewModel.getActionLiveData();
|
||||
assertThat(actionLiveData.getValue()).isEqualTo(null);
|
||||
|
||||
mViewModel.showIconTouchDialog();
|
||||
assertThat(actionLiveData.getValue()).isEqualTo(
|
||||
FINGERPRINT_ENROLL_ENROLLING_ACTION_SHOW_ICON_TOUCH_DIALOG);
|
||||
|
||||
mViewModel.onIconTouchDialogDismiss();
|
||||
assertThat(actionLiveData.getValue()).isEqualTo(
|
||||
FINGERPRINT_ENROLL_ENROLLING_ACTION_DISMISS_ICON_TOUCH_DIALOG);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorDialogActionLiveData() {
|
||||
assertThat(mViewModel.getErrorDialogActionLiveData().getValue()).isEqualTo(null);
|
||||
|
||||
@FingerprintErrorDialogAction int action = FINGERPRINT_ERROR_DIALOG_ACTION_RESTART;
|
||||
mViewModel.onErrorDialogAction(action);
|
||||
assertThat(mViewModel.getErrorDialogActionLiveData().getValue()).isEqualTo(action);
|
||||
|
||||
action = FINGERPRINT_ERROR_DIALOG_ACTION_SET_RESULT_TIMEOUT;
|
||||
mViewModel.onErrorDialogAction(action);
|
||||
assertThat(mViewModel.getErrorDialogActionLiveData().getValue()).isEqualTo(action);
|
||||
|
||||
action = FINGERPRINT_ERROR_DIALOG_ACTION_SET_RESULT_FINISH;
|
||||
mViewModel.onErrorDialogAction(action);
|
||||
assertThat(mViewModel.getErrorDialogActionLiveData().getValue()).isEqualTo(action);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tesBackPressedScenario() {
|
||||
final LiveData<Integer> actionLiveData = mViewModel.getActionLiveData();
|
||||
assertThat(actionLiveData.getValue()).isEqualTo(null);
|
||||
assertThat(mViewModel.getOnBackPressed()).isEqualTo(false);
|
||||
|
||||
mViewModel.setOnBackPressed();
|
||||
assertThat(mViewModel.getOnBackPressed()).isEqualTo(true);
|
||||
|
||||
mViewModel.onCancelledDueToOnBackPressed();
|
||||
assertThat(mViewModel.getOnBackPressed()).isEqualTo(false);
|
||||
assertThat(actionLiveData.getValue()).isEqualTo(
|
||||
FINGERPRINT_ENROLL_ENROLLING_CANCELED_BECAUSE_BACK_PRESSED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSkipPressedScenario() {
|
||||
final LiveData<Integer> actionLiveData = mViewModel.getActionLiveData();
|
||||
assertThat(actionLiveData.getValue()).isEqualTo(null);
|
||||
assertThat(mViewModel.getOnSkipPressed()).isEqualTo(false);
|
||||
|
||||
mViewModel.setOnSkipPressed();
|
||||
assertThat(mViewModel.getOnSkipPressed()).isEqualTo(true);
|
||||
|
||||
mViewModel.onCancelledDueToOnSkipPressed();
|
||||
assertThat(mViewModel.getOnSkipPressed()).isEqualTo(false);
|
||||
assertThat(actionLiveData.getValue()).isEqualTo(
|
||||
FINGERPRINT_ENROLL_ENROLLING_CANCELED_BECAUSE_USER_SKIP);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCanAssumeUdfps_forUdfpsUltrasonicSensor() {
|
||||
mViewModel = new FingerprintEnrollEnrollingViewModel(
|
||||
mApplication,
|
||||
TEST_USER_ID,
|
||||
newFingerprintRepository(mFingerprintManager, TYPE_UDFPS_ULTRASONIC, 5)
|
||||
);
|
||||
assertThat(mViewModel.canAssumeUdfps()).isEqualTo(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCanAssumeUdfps_forRearSensor() {
|
||||
mViewModel = new FingerprintEnrollEnrollingViewModel(
|
||||
mApplication,
|
||||
TEST_USER_ID,
|
||||
newFingerprintRepository(mFingerprintManager, TYPE_REAR, 5)
|
||||
);
|
||||
assertThat(mViewModel.canAssumeUdfps()).isEqualTo(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFirstFingerprintSensorPropertiesInternal() {
|
||||
final ArrayList<FingerprintSensorPropertiesInternal> props = new ArrayList<>();
|
||||
final FingerprintSensorPropertiesInternal prop = new FingerprintSensorPropertiesInternal(
|
||||
0 /* sensorId */,
|
||||
SensorProperties.STRENGTH_STRONG,
|
||||
5,
|
||||
new ArrayList<>() /* componentInfo */,
|
||||
TYPE_UDFPS_OPTICAL,
|
||||
true /* resetLockoutRequiresHardwareAuthToken */);
|
||||
props.add(prop);
|
||||
doAnswer(invocation -> {
|
||||
final IFingerprintAuthenticatorsRegisteredCallback callback =
|
||||
invocation.getArgument(0);
|
||||
callback.onAllAuthenticatorsRegistered(props);
|
||||
return null;
|
||||
}).when(mFingerprintManager).addAuthenticatorsRegisteredCallback(any());
|
||||
|
||||
mViewModel = new FingerprintEnrollEnrollingViewModel(
|
||||
mApplication,
|
||||
TEST_USER_ID,
|
||||
new FingerprintRepository(mFingerprintManager)
|
||||
);
|
||||
|
||||
assertThat(mViewModel.getFirstFingerprintSensorPropertiesInternal()).isEqualTo(prop);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetEnrollStageCount() {
|
||||
final int expectedValue = 24;
|
||||
doReturn(expectedValue).when(mFingerprintManager).getEnrollStageCount();
|
||||
|
||||
assertThat(mViewModel.getEnrollStageCount()).isEqualTo(expectedValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetEnrollStageThreshold() {
|
||||
final float expectedValue0 = 0.42f;
|
||||
final float expectedValue1 = 0.24f;
|
||||
final float expectedValue2 = 0.33f;
|
||||
final float expectedValue3 = 0.90f;
|
||||
|
||||
doReturn(expectedValue0).when(mFingerprintManager).getEnrollStageThreshold(0);
|
||||
doReturn(expectedValue1).when(mFingerprintManager).getEnrollStageThreshold(1);
|
||||
doReturn(expectedValue2).when(mFingerprintManager).getEnrollStageThreshold(2);
|
||||
doReturn(expectedValue3).when(mFingerprintManager).getEnrollStageThreshold(3);
|
||||
|
||||
assertThat(mViewModel.getEnrollStageThreshold(2)).isEqualTo(expectedValue2);
|
||||
assertThat(mViewModel.getEnrollStageThreshold(1)).isEqualTo(expectedValue1);
|
||||
assertThat(mViewModel.getEnrollStageThreshold(3)).isEqualTo(expectedValue3);
|
||||
assertThat(mViewModel.getEnrollStageThreshold(0)).isEqualTo(expectedValue0);
|
||||
}
|
||||
}
|
@@ -18,7 +18,6 @@ package com.android.settings.biometrics2.ui.viewmodel;
|
||||
|
||||
import static com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollFindSensorViewModel.FINGERPRINT_ENROLL_FIND_SENSOR_ACTION_DIALOG;
|
||||
import static com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollFindSensorViewModel.FINGERPRINT_ENROLL_FIND_SENSOR_ACTION_SKIP;
|
||||
import static com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollFindSensorViewModel.FINGERPRINT_ENROLL_FIND_SENSOR_ACTION_START;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@@ -40,61 +39,45 @@ public class FingerprintEnrollFindSensorViewModelTest {
|
||||
@Rule public final InstantTaskExecutorRule mTaskExecutorRule = new InstantTaskExecutorRule();
|
||||
|
||||
private Application mApplication;
|
||||
private FingerprintEnrollFindSensorViewModel mViewModel;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mApplication = ApplicationProvider.getApplicationContext();
|
||||
mViewModel = new FingerprintEnrollFindSensorViewModel(mApplication, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClickStartButton() {
|
||||
final FingerprintEnrollFindSensorViewModel viewModel =
|
||||
new FingerprintEnrollFindSensorViewModel(mApplication, false);
|
||||
|
||||
viewModel.onStartButtonClick();
|
||||
assertThat(viewModel.getActionLiveData().getValue()).isEqualTo(
|
||||
FINGERPRINT_ENROLL_FIND_SENSOR_ACTION_START);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClickSkipButton() {
|
||||
final FingerprintEnrollFindSensorViewModel viewModel =
|
||||
new FingerprintEnrollFindSensorViewModel(mApplication, false);
|
||||
|
||||
viewModel.onSkipButtonClick();
|
||||
assertThat(viewModel.getActionLiveData().getValue()).isEqualTo(
|
||||
public void testClickSkipButtonNotInSuw() {
|
||||
mViewModel = new FingerprintEnrollFindSensorViewModel(mApplication, false);
|
||||
mViewModel.onSkipButtonClick();
|
||||
assertThat(mViewModel.getActionLiveData().getValue()).isEqualTo(
|
||||
FINGERPRINT_ENROLL_FIND_SENSOR_ACTION_SKIP);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClickSkipButtonInSuw() {
|
||||
final FingerprintEnrollFindSensorViewModel viewModel =
|
||||
new FingerprintEnrollFindSensorViewModel(mApplication, true);
|
||||
|
||||
viewModel.onSkipButtonClick();
|
||||
assertThat(viewModel.getActionLiveData().getValue()).isEqualTo(
|
||||
mViewModel = new FingerprintEnrollFindSensorViewModel(mApplication, true);
|
||||
mViewModel.onSkipButtonClick();
|
||||
assertThat(mViewModel.getActionLiveData().getValue()).isEqualTo(
|
||||
FINGERPRINT_ENROLL_FIND_SENSOR_ACTION_DIALOG);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClickSkipDialogButton() {
|
||||
final FingerprintEnrollFindSensorViewModel viewModel =
|
||||
new FingerprintEnrollFindSensorViewModel(mApplication, true);
|
||||
|
||||
viewModel.onSkipDialogButtonClick();
|
||||
assertThat(viewModel.getActionLiveData().getValue()).isEqualTo(
|
||||
mViewModel.onSkipDialogButtonClick();
|
||||
assertThat(mViewModel.getActionLiveData().getValue()).isEqualTo(
|
||||
FINGERPRINT_ENROLL_FIND_SENSOR_ACTION_SKIP);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClearActionLiveData() {
|
||||
final FingerprintEnrollFindSensorViewModel viewModel =
|
||||
new FingerprintEnrollFindSensorViewModel(mApplication, false);
|
||||
assertThat(mViewModel.getActionLiveData().getValue()).isNull();
|
||||
|
||||
viewModel.onStartButtonClick();
|
||||
assertThat(viewModel.getActionLiveData().getValue()).isNotNull();
|
||||
mViewModel.onStartButtonClick();
|
||||
assertThat(mViewModel.getActionLiveData().getValue()).isNotNull();
|
||||
|
||||
viewModel.clearActionLiveData();
|
||||
assertThat(viewModel.getActionLiveData().getValue()).isNull();
|
||||
mViewModel.clearActionLiveData();
|
||||
assertThat(mViewModel.getActionLiveData().getValue()).isNull();
|
||||
}
|
||||
}
|
||||
|
@@ -211,7 +211,7 @@ public class FingerprintEnrollIntroViewModelTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void textCanAssumeUdfps_forUdfpsUltrasonicSensor() {
|
||||
public void testCanAssumeUdfps_forUdfpsUltrasonicSensor() {
|
||||
final FingerprintEnrollIntroViewModel viewModel = newFingerprintEnrollIntroViewModel(
|
||||
newFingerprintRepository(mFingerprintManager, TYPE_UDFPS_ULTRASONIC, 5),
|
||||
newAllFalseRequest(mApplication));
|
||||
@@ -220,7 +220,7 @@ public class FingerprintEnrollIntroViewModelTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void textCanAssumeUdfps_forRearSensor() {
|
||||
public void testCanAssumeUdfps_forRearSensor() {
|
||||
final FingerprintEnrollIntroViewModel viewModel = newFingerprintEnrollIntroViewModel(
|
||||
newFingerprintRepository(mFingerprintManager, TYPE_REAR, 5),
|
||||
newAllFalseRequest(mApplication));
|
||||
|
@@ -69,27 +69,34 @@ public class FingerprintEnrollmentViewModelTest {
|
||||
public void testSetSavedInstanceState() {
|
||||
// setSavedInstanceState() as false
|
||||
final Bundle bundle = new Bundle();
|
||||
final Bundle outBundle = new Bundle();
|
||||
|
||||
// Set SAVED_STATE_IS_WAITING_ACTIVITY_RESULT to true
|
||||
bundle.putBoolean(SAVED_STATE_IS_WAITING_ACTIVITY_RESULT, false);
|
||||
mViewModel.setSavedInstanceState(bundle);
|
||||
assertThat(mViewModel.isWaitingActivityResult().get()).isFalse();
|
||||
|
||||
// setSavedInstanceState() as false
|
||||
// Set SAVED_STATE_IS_WAITING_ACTIVITY_RESULT to true
|
||||
bundle.clear();
|
||||
bundle.putBoolean(SAVED_STATE_IS_WAITING_ACTIVITY_RESULT, true);
|
||||
mViewModel.setSavedInstanceState(bundle);
|
||||
assertThat(mViewModel.isWaitingActivityResult().get()).isTrue();
|
||||
|
||||
// setSavedInstanceState() as false
|
||||
// Set SAVED_STATE_IS_NEW_FINGERPRINT_ADDED to false
|
||||
bundle.clear();
|
||||
bundle.putBoolean(SAVED_STATE_IS_NEW_FINGERPRINT_ADDED, false);
|
||||
mViewModel.setSavedInstanceState(bundle);
|
||||
assertThat(mViewModel.isNewFingerprintAdded()).isFalse();
|
||||
outBundle.clear();
|
||||
mViewModel.onSaveInstanceState(outBundle);
|
||||
assertThat(outBundle.getBoolean(SAVED_STATE_IS_NEW_FINGERPRINT_ADDED)).isFalse();
|
||||
|
||||
// setSavedInstanceState() as false
|
||||
// Set SAVED_STATE_IS_NEW_FINGERPRINT_ADDED to true
|
||||
bundle.clear();
|
||||
bundle.putBoolean(SAVED_STATE_IS_NEW_FINGERPRINT_ADDED, true);
|
||||
mViewModel.setSavedInstanceState(bundle);
|
||||
assertThat(mViewModel.isNewFingerprintAdded()).isTrue();
|
||||
outBundle.clear();
|
||||
mViewModel.onSaveInstanceState(outBundle);
|
||||
assertThat(outBundle.getBoolean(SAVED_STATE_IS_NEW_FINGERPRINT_ADDED)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user