Move all the shared data from biometric controllers to separate utility classes
Test: atest SettingsUnitTests Bug: 215517420 Change-Id: Ic5421cd910ae77d4e7c0a29ae0337edb98a1d3b9
This commit is contained in:
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* 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.biometrics;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserManager;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class BiometricNavigationUtilsTest {
|
||||
|
||||
private static final String SETTINGS_CLASS_NAME = "SettingsClassName";
|
||||
private static final String EXTRA_KEY = "EXTRA_KEY";
|
||||
|
||||
@Mock
|
||||
private UserManager mUserManager;
|
||||
private Context mContext;
|
||||
private BiometricNavigationUtils mBiometricNavigationUtils;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
|
||||
doNothing().when(mContext).startActivity(any());
|
||||
mBiometricNavigationUtils = new BiometricNavigationUtils();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openBiometricSettings_quietMode_launchesQuiteModeDialog() {
|
||||
when(mUserManager.isQuietModeEnabled(any())).thenReturn(true);
|
||||
|
||||
mBiometricNavigationUtils.launchBiometricSettings(mContext, SETTINGS_CLASS_NAME,
|
||||
Bundle.EMPTY);
|
||||
|
||||
assertQuietModeDialogLaunchRequested();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openBiometricSettings_quietMode_returnsFalse() {
|
||||
when(mUserManager.isQuietModeEnabled(any())).thenReturn(true);
|
||||
|
||||
assertThat(mBiometricNavigationUtils.launchBiometricSettings(
|
||||
mContext, SETTINGS_CLASS_NAME, Bundle.EMPTY)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openBiometricSettings_noQuietMode_emptyExtras_launchesFragmentWithoutExtras() {
|
||||
when(mUserManager.isQuietModeEnabled(any())).thenReturn(false);
|
||||
|
||||
mBiometricNavigationUtils.launchBiometricSettings(
|
||||
mContext, SETTINGS_CLASS_NAME, Bundle.EMPTY);
|
||||
|
||||
assertSettingsPageLaunchRequested(false /* shouldContainExtras */);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openBiometricSettings_noQuietMode_emptyExtras_returnsTrue() {
|
||||
when(mUserManager.isQuietModeEnabled(any())).thenReturn(false);
|
||||
|
||||
assertThat(mBiometricNavigationUtils.launchBiometricSettings(
|
||||
mContext, SETTINGS_CLASS_NAME, Bundle.EMPTY)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openBiometricSettings_noQuietMode_withExtras_launchesFragmentWithExtras() {
|
||||
when(mUserManager.isQuietModeEnabled(any())).thenReturn(false);
|
||||
|
||||
final Bundle extras = createNotEmptyExtras();
|
||||
mBiometricNavigationUtils.launchBiometricSettings(mContext, SETTINGS_CLASS_NAME, extras);
|
||||
|
||||
assertSettingsPageLaunchRequested(true /* shouldContainExtras */);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openBiometricSettings_noQuietMode_withExtras_returnsTrue() {
|
||||
when(mUserManager.isQuietModeEnabled(any())).thenReturn(false);
|
||||
|
||||
assertThat(mBiometricNavigationUtils.launchBiometricSettings(
|
||||
mContext, SETTINGS_CLASS_NAME, createNotEmptyExtras())).isTrue();
|
||||
}
|
||||
|
||||
private Bundle createNotEmptyExtras() {
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putInt(EXTRA_KEY, 0);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
private void assertQuietModeDialogLaunchRequested() {
|
||||
ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
verify(mContext).startActivity(intentCaptor.capture());
|
||||
|
||||
Intent intent = intentCaptor.getValue();
|
||||
assertThat(intent.getComponent().getPackageName())
|
||||
.isEqualTo("android");
|
||||
assertThat(intent.getComponent().getClassName())
|
||||
.isEqualTo("com.android.internal.app.UnlaunchableAppActivity");
|
||||
}
|
||||
|
||||
private void assertSettingsPageLaunchRequested(boolean shouldContainExtras) {
|
||||
ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
verify(mContext).startActivity(intentCaptor.capture());
|
||||
|
||||
Intent intent = intentCaptor.getValue();
|
||||
assertThat(intent.getComponent().getPackageName())
|
||||
.isEqualTo("com.android.settings");
|
||||
assertThat(intent.getComponent().getClassName())
|
||||
.isEqualTo(SETTINGS_CLASS_NAME);
|
||||
assertThat(intent.getExtras().containsKey(EXTRA_KEY)).isEqualTo(shouldContainExtras);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,263 @@
|
||||
/*
|
||||
* 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.biometrics.combination;
|
||||
|
||||
import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_FACE;
|
||||
import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.hardware.face.FaceManager;
|
||||
import android.hardware.fingerprint.Fingerprint;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.Settings;
|
||||
import com.android.settings.testutils.ResourcesUtils;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class CombinedBiometricStatusUtilsTest {
|
||||
|
||||
private static final ComponentName COMPONENT_NAME =
|
||||
new ComponentName("package", "class");
|
||||
private static final UserHandle USER_HANDLE = new UserHandle(UserHandle.myUserId());
|
||||
|
||||
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
@Mock
|
||||
private DevicePolicyManager mDevicePolicyManager;
|
||||
@Mock
|
||||
private FingerprintManager mFingerprintManager;
|
||||
@Mock
|
||||
private FaceManager mFaceManager;
|
||||
|
||||
private Context mApplicationContext;
|
||||
private CombinedBiometricStatusUtils mCombinedBiometricStatusUtils;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mApplicationContext = spy(ApplicationProvider.getApplicationContext());
|
||||
when(mApplicationContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)).thenReturn(true);
|
||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE)).thenReturn(true);
|
||||
when(mDevicePolicyManager.getProfileOwnerOrDeviceOwnerSupervisionComponent(USER_HANDLE))
|
||||
.thenReturn(COMPONENT_NAME);
|
||||
when(mApplicationContext.getSystemService(Context.FINGERPRINT_SERVICE))
|
||||
.thenReturn(mFingerprintManager);
|
||||
when(mApplicationContext.getSystemService(Context.DEVICE_POLICY_SERVICE))
|
||||
.thenReturn(mDevicePolicyManager);
|
||||
when(mApplicationContext.getSystemService(Context.FACE_SERVICE)).thenReturn(mFaceManager);
|
||||
mCombinedBiometricStatusUtils = new CombinedBiometricStatusUtils(mApplicationContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_withoutFingerprint_withoutFace_returnsFalse() {
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(false);
|
||||
|
||||
assertThat(mCombinedBiometricStatusUtils.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_withoutFingerprint_whenFace_returnsFalse() {
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
|
||||
assertThat(mCombinedBiometricStatusUtils.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_whenFingerprint_withoutFace_returnsFalse() {
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(false);
|
||||
|
||||
assertThat(mCombinedBiometricStatusUtils.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_whenFingerprint_whenFace_returnsTrue() {
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
|
||||
assertThat(mCombinedBiometricStatusUtils.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDisabledAdmin_whenFingerprintDisabled_whenFaceDisabled_returnsEnforcedAdmin() {
|
||||
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME))
|
||||
.thenReturn(KEYGUARD_DISABLE_FACE | KEYGUARD_DISABLE_FINGERPRINT);
|
||||
|
||||
final RestrictedLockUtils.EnforcedAdmin admin =
|
||||
mCombinedBiometricStatusUtils.getDisablingAdmin();
|
||||
|
||||
assertThat(admin).isEqualTo(new RestrictedLockUtils.EnforcedAdmin(
|
||||
COMPONENT_NAME, UserManager.DISALLOW_BIOMETRIC, USER_HANDLE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDisabledAdmin_whenFingerprintDisabled_whenFaceEnabled_returnsNull() {
|
||||
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME))
|
||||
.thenReturn(KEYGUARD_DISABLE_FINGERPRINT);
|
||||
|
||||
assertThat(mCombinedBiometricStatusUtils.getDisablingAdmin()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDisabledAdmin_whenFingerprintEnabled_whenFaceDisabled_returnsNull() {
|
||||
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME))
|
||||
.thenReturn(KEYGUARD_DISABLE_FACE);
|
||||
|
||||
assertThat(mCombinedBiometricStatusUtils.getDisablingAdmin()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDisabledAdmin_whenFingerprintEnabled_whenFaceEnabled_returnsNull() {
|
||||
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
|
||||
|
||||
assertThat(mCombinedBiometricStatusUtils.getDisablingAdmin()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_whenFaceEnrolled_whenMultipleFingerprints_returnsBothFpMultiple() {
|
||||
when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(true);
|
||||
when(mFingerprintManager.getEnrolledFingerprints(anyInt()))
|
||||
.thenReturn(createFingerprintList(2));
|
||||
|
||||
assertThat(mCombinedBiometricStatusUtils.getSummary())
|
||||
.isEqualTo(ResourcesUtils.getResourcesString(
|
||||
mApplicationContext,
|
||||
"security_settings_biometric_preference_summary_both_fp_multiple"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_whenFaceEnrolled_whenSingleFingerprint_returnsBothFpSingle() {
|
||||
when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(true);
|
||||
when(mFingerprintManager.getEnrolledFingerprints(anyInt()))
|
||||
.thenReturn(createFingerprintList(1));
|
||||
|
||||
assertThat(mCombinedBiometricStatusUtils.getSummary())
|
||||
.isEqualTo(ResourcesUtils.getResourcesString(
|
||||
mApplicationContext,
|
||||
"security_settings_biometric_preference_summary_both_fp_single"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_whenFaceEnrolled_whenNoFingerprints_returnsFace() {
|
||||
when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(true);
|
||||
when(mFingerprintManager.getEnrolledFingerprints(anyInt()))
|
||||
.thenReturn(createFingerprintList(0));
|
||||
|
||||
assertThat(mCombinedBiometricStatusUtils.getSummary())
|
||||
.isEqualTo(ResourcesUtils.getResourcesString(
|
||||
mApplicationContext,
|
||||
"security_settings_face_preference_summary"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_whenNoFaceEnrolled_whenMultipleFingerprints_returnsFingerprints() {
|
||||
final int enrolledFingerprintsCount = 2;
|
||||
final int stringResId = ResourcesUtils.getResourcesId(
|
||||
ApplicationProvider.getApplicationContext(), "plurals",
|
||||
"security_settings_fingerprint_preference_summary");
|
||||
final String summary = mApplicationContext.getResources().getQuantityString(
|
||||
stringResId, enrolledFingerprintsCount /* quantity */,
|
||||
enrolledFingerprintsCount /* formatArgs */);
|
||||
|
||||
when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(false);
|
||||
when(mFingerprintManager.getEnrolledFingerprints(anyInt()))
|
||||
.thenReturn(createFingerprintList(enrolledFingerprintsCount));
|
||||
|
||||
assertThat(mCombinedBiometricStatusUtils.getSummary()).isEqualTo(summary);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_whenNoFaceEnrolled_whenSingleFingerprints_returnsFingerprints() {
|
||||
final int enrolledFingerprintsCount = 1;
|
||||
final int stringResId = ResourcesUtils.getResourcesId(
|
||||
ApplicationProvider.getApplicationContext(), "plurals",
|
||||
"security_settings_fingerprint_preference_summary");
|
||||
final String summary = mApplicationContext.getResources().getQuantityString(
|
||||
stringResId, enrolledFingerprintsCount /* quantity */,
|
||||
enrolledFingerprintsCount /* formatArgs */);
|
||||
|
||||
when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(false);
|
||||
when(mFingerprintManager.getEnrolledFingerprints(anyInt()))
|
||||
.thenReturn(createFingerprintList(enrolledFingerprintsCount));
|
||||
|
||||
assertThat(mCombinedBiometricStatusUtils.getSummary()).isEqualTo(summary);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_whenNoFaceEnrolled_whenNoFingerprints_returnsNoneEnrolled() {
|
||||
when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(false);
|
||||
when(mFingerprintManager.getEnrolledFingerprints(anyInt()))
|
||||
.thenReturn(createFingerprintList(0));
|
||||
|
||||
assertThat(mCombinedBiometricStatusUtils.getSummary())
|
||||
.isEqualTo(ResourcesUtils.getResourcesString(
|
||||
mApplicationContext,
|
||||
"security_settings_biometric_preference_summary_none_enrolled"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSettingsClassName_returnsCombinedBiometricSettings() {
|
||||
when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(false);
|
||||
|
||||
assertThat(mCombinedBiometricStatusUtils.getSettingsClassName())
|
||||
.isEqualTo(Settings.CombinedBiometricSettingsActivity.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getProfileSettingsClassName_returnsCombinedBiometricProfileSettings() {
|
||||
when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(false);
|
||||
|
||||
assertThat(mCombinedBiometricStatusUtils.getProfileSettingsClassName())
|
||||
.isEqualTo(Settings.CombinedBiometricProfileSettingsActivity.class.getName());
|
||||
}
|
||||
|
||||
private List<Fingerprint> createFingerprintList(int size) {
|
||||
final List<Fingerprint> fingerprintList = new ArrayList<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
fingerprintList.add(new Fingerprint("fingerprint" + i, 0, 0));
|
||||
}
|
||||
return fingerprintList;
|
||||
}
|
||||
}
|
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* 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.biometrics.face;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.hardware.face.FaceManager;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.Settings;
|
||||
import com.android.settings.testutils.ResourcesUtils;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class FaceStatusUtilsTest {
|
||||
|
||||
private static final ComponentName COMPONENT_NAME =
|
||||
new ComponentName("package", "class");
|
||||
private static final UserHandle USER_HANDLE = new UserHandle(UserHandle.myUserId());
|
||||
|
||||
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
@Mock
|
||||
private DevicePolicyManager mDevicePolicyManager;
|
||||
@Mock
|
||||
private FingerprintManager mFingerprintManager;
|
||||
@Mock
|
||||
private FaceManager mFaceManager;
|
||||
|
||||
private Context mApplicationContext;
|
||||
private FaceStatusUtils mFaceStatusUtils;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mApplicationContext = spy(ApplicationProvider.getApplicationContext());
|
||||
when(mApplicationContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)).thenReturn(true);
|
||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE)).thenReturn(true);
|
||||
when(mDevicePolicyManager.getProfileOwnerOrDeviceOwnerSupervisionComponent(USER_HANDLE))
|
||||
.thenReturn(COMPONENT_NAME);
|
||||
when(mApplicationContext.getSystemService(Context.FINGERPRINT_SERVICE))
|
||||
.thenReturn(mFingerprintManager);
|
||||
when(mApplicationContext.getSystemService(Context.DEVICE_POLICY_SERVICE))
|
||||
.thenReturn(mDevicePolicyManager);
|
||||
when(mApplicationContext.getSystemService(Context.FACE_SERVICE)).thenReturn(mFaceManager);
|
||||
mFaceStatusUtils = new FaceStatusUtils(mApplicationContext, mFaceManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_withoutFingerprint_withoutFace_returnsFalse() {
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(false);
|
||||
|
||||
assertThat(mFaceStatusUtils.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_withoutFingerprint_withFace_returnsTrue() {
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
|
||||
assertThat(mFaceStatusUtils.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_withFingerprint_withoutFace_returnsFalse() {
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(false);
|
||||
|
||||
assertThat(mFaceStatusUtils.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_withFingerprint_withFace_returnsFalse() {
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
|
||||
assertThat(mFaceStatusUtils.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDisabledAdmin_whenFaceDisabled_returnsEnforcedAdmin() {
|
||||
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME))
|
||||
.thenReturn(DevicePolicyManager.KEYGUARD_DISABLE_FACE);
|
||||
|
||||
final RestrictedLockUtils.EnforcedAdmin admin = mFaceStatusUtils.getDisablingAdmin();
|
||||
|
||||
assertThat(admin).isEqualTo(new RestrictedLockUtils.EnforcedAdmin(
|
||||
COMPONENT_NAME, UserManager.DISALLOW_BIOMETRIC, USER_HANDLE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDisabledAdmin_withFaceEnabled_returnsNull() {
|
||||
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
|
||||
|
||||
assertThat(mFaceStatusUtils.getDisablingAdmin()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_whenNotEnrolled_returnsSummaryNone() {
|
||||
when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(false);
|
||||
|
||||
assertThat(mFaceStatusUtils.getSummary())
|
||||
.isEqualTo(ResourcesUtils.getResourcesString(
|
||||
mApplicationContext,
|
||||
"security_settings_face_preference_summary_none"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_whenEnrolled_returnsSummary() {
|
||||
when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(true);
|
||||
|
||||
assertThat(mFaceStatusUtils.getSummary())
|
||||
.isEqualTo(ResourcesUtils.getResourcesString(
|
||||
mApplicationContext,
|
||||
"security_settings_face_preference_summary"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSettingsClassName_whenNotEnrolled_returnsFaceEnrollInduction() {
|
||||
when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(false);
|
||||
|
||||
assertThat(mFaceStatusUtils.getSettingsClassName())
|
||||
.isEqualTo(FaceEnrollIntroduction.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSettingsClassName_whenEnrolled_returnsFaceSettings() {
|
||||
when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(true);
|
||||
|
||||
assertThat(mFaceStatusUtils.getSettingsClassName())
|
||||
.isEqualTo(Settings.FaceSettingsActivity.class.getName());
|
||||
}
|
||||
}
|
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
* 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.biometrics.fingerprint;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.hardware.face.FaceManager;
|
||||
import android.hardware.fingerprint.Fingerprint;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.testutils.ResourcesUtils;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class FingerprintStatusUtilsTest {
|
||||
|
||||
private static final ComponentName COMPONENT_NAME =
|
||||
new ComponentName("package", "class");
|
||||
private static final UserHandle USER_HANDLE = new UserHandle(UserHandle.myUserId());
|
||||
|
||||
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
@Mock
|
||||
private DevicePolicyManager mDevicePolicyManager;
|
||||
@Mock
|
||||
private FingerprintManager mFingerprintManager;
|
||||
@Mock
|
||||
private FaceManager mFaceManager;
|
||||
|
||||
private Context mApplicationContext;
|
||||
private FingerprintStatusUtils mFingerprintStatusUtils;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mApplicationContext = spy(ApplicationProvider.getApplicationContext());
|
||||
when(mApplicationContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)).thenReturn(true);
|
||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE)).thenReturn(true);
|
||||
when(mDevicePolicyManager.getProfileOwnerOrDeviceOwnerSupervisionComponent(USER_HANDLE))
|
||||
.thenReturn(COMPONENT_NAME);
|
||||
when(mApplicationContext.getSystemService(Context.FINGERPRINT_SERVICE))
|
||||
.thenReturn(mFingerprintManager);
|
||||
when(mApplicationContext.getSystemService(Context.DEVICE_POLICY_SERVICE))
|
||||
.thenReturn(mDevicePolicyManager);
|
||||
when(mApplicationContext.getSystemService(Context.FACE_SERVICE)).thenReturn(mFaceManager);
|
||||
mFingerprintStatusUtils =
|
||||
new FingerprintStatusUtils(mApplicationContext, mFingerprintManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_withoutFingerprint_withoutFace_returnsFalse() {
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(false);
|
||||
|
||||
assertThat(mFingerprintStatusUtils.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_withoutFingerprint_withFace_returnsFalse() {
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
|
||||
assertThat(mFingerprintStatusUtils.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_withFingerprint_withoutFace_returnsTrue() {
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(false);
|
||||
|
||||
assertThat(mFingerprintStatusUtils.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_withFingerprint_withFace_returnsFalse() {
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
|
||||
assertThat(mFingerprintStatusUtils.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDisabledAdmin_whenFingerprintDisabled_returnsEnforcedAdmin() {
|
||||
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME))
|
||||
.thenReturn(DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT);
|
||||
|
||||
final RestrictedLockUtils.EnforcedAdmin admin =
|
||||
mFingerprintStatusUtils.getDisablingAdmin();
|
||||
|
||||
assertThat(admin).isEqualTo(new RestrictedLockUtils.EnforcedAdmin(
|
||||
COMPONENT_NAME, UserManager.DISALLOW_BIOMETRIC, USER_HANDLE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDisabledAdmin_withFingerprintEnabled_returnsNull() {
|
||||
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
|
||||
|
||||
assertThat(mFingerprintStatusUtils.getDisablingAdmin()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_whenNotEnrolled_returnsSummaryNone() {
|
||||
when(mFingerprintManager.hasEnrolledTemplates(anyInt())).thenReturn(false);
|
||||
|
||||
assertThat(mFingerprintStatusUtils.getSummary())
|
||||
.isEqualTo(ResourcesUtils.getResourcesString(
|
||||
mApplicationContext,
|
||||
"security_settings_fingerprint_preference_summary_none"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_whenEnrolled_returnsSummary() {
|
||||
final int enrolledFingerprintsCount = 2;
|
||||
final int stringResId = ResourcesUtils.getResourcesId(
|
||||
ApplicationProvider.getApplicationContext(), "plurals",
|
||||
"security_settings_fingerprint_preference_summary");
|
||||
final String summary = mApplicationContext.getResources().getQuantityString(
|
||||
stringResId, enrolledFingerprintsCount /* quantity */,
|
||||
enrolledFingerprintsCount /* formatArgs */);
|
||||
|
||||
when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(true);
|
||||
when(mFingerprintManager.getEnrolledFingerprints(anyInt())).thenReturn(
|
||||
createFingerprintList(enrolledFingerprintsCount));
|
||||
|
||||
assertThat(mFingerprintStatusUtils.getSummary()).isEqualTo(summary);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSettingsClassName_whenNotEnrolled_returnsFingerprintEnrollInduction() {
|
||||
when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(false);
|
||||
|
||||
assertThat(mFingerprintStatusUtils.getSettingsClassName())
|
||||
.isEqualTo(FingerprintEnrollIntroduction.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSettingsClassName_whenEnrolled_returnsFingerprintSettings() {
|
||||
when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(true);
|
||||
|
||||
assertThat(mFingerprintStatusUtils.getSettingsClassName())
|
||||
.isEqualTo(FingerprintSettings.class.getName());
|
||||
}
|
||||
|
||||
private List<Fingerprint> createFingerprintList(int size) {
|
||||
final List<Fingerprint> fingerprintList = new ArrayList<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
fingerprintList.add(new Fingerprint("fingerprint" + i, 0, 0));
|
||||
}
|
||||
return fingerprintList;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user