Merge "Split biometrics resource into three." into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
88d40f1c1f
@@ -39,6 +39,9 @@ import android.hardware.face.FaceManager;
|
||||
import android.hardware.fingerprint.Fingerprint;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.os.UserHandle;
|
||||
import android.platform.test.annotations.RequiresFlagsDisabled;
|
||||
import android.platform.test.flag.junit.CheckFlagsRule;
|
||||
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
|
||||
import android.safetycenter.SafetyEvent;
|
||||
import android.safetycenter.SafetySourceData;
|
||||
import android.safetycenter.SafetySourceStatus;
|
||||
@@ -50,6 +53,7 @@ import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.settings.Settings;
|
||||
import com.android.settings.biometrics.face.FaceEnrollIntroductionInternal;
|
||||
import com.android.settings.biometrics.fingerprint.FingerprintSettings;
|
||||
import com.android.settings.flags.Flags;
|
||||
import com.android.settings.testutils.ActiveUnlockTestUtils;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.ResourcesUtils;
|
||||
@@ -57,6 +61,7 @@ import com.android.settingslib.utils.StringUtil;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
@@ -67,6 +72,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@RequiresFlagsDisabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class BiometricsSafetySourceTest {
|
||||
|
||||
@@ -75,6 +81,9 @@ public class BiometricsSafetySourceTest {
|
||||
private static final SafetyEvent EVENT_SOURCE_STATE_CHANGED =
|
||||
new SafetyEvent.Builder(SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED).build();
|
||||
|
||||
@Rule
|
||||
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
|
||||
|
||||
private Context mApplicationContext;
|
||||
|
||||
@Mock private PackageManager mPackageManager;
|
||||
@@ -196,7 +205,7 @@ public class BiometricsSafetySourceTest {
|
||||
|
||||
@Test
|
||||
public void setSafetySourceData_withFingerprintsEnrolled_whenDisabledByAdmin_setsData() {
|
||||
final int enrolledFingerprintsCount = 2;
|
||||
int enrolledFingerprintsCount = 2;
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(false);
|
||||
@@ -216,7 +225,7 @@ public class BiometricsSafetySourceTest {
|
||||
|
||||
@Test
|
||||
public void setSafetySourceData_withFingerprintsEnrolled_whenNotDisabledByAdmin_setsData() {
|
||||
final int enrolledFingerprintsCount = 2;
|
||||
int enrolledFingerprintsCount = 2;
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(false);
|
||||
@@ -364,7 +373,7 @@ public class BiometricsSafetySourceTest {
|
||||
|
||||
@Test
|
||||
public void setSafetySourceData_faceAndFingerprint_whenFaceEnrolled_withMpFingers_setsData() {
|
||||
final int enrolledFingerprintsCount = 2;
|
||||
int enrolledFingerprintsCount = 2;
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
@@ -382,7 +391,7 @@ public class BiometricsSafetySourceTest {
|
||||
|
||||
@Test
|
||||
public void setSafetySourceData_faceAndFingerprint_whenFaceEnrolled_withOneFinger_setsData() {
|
||||
final int enrolledFingerprintsCount = 1;
|
||||
int enrolledFingerprintsCount = 1;
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
@@ -417,7 +426,7 @@ public class BiometricsSafetySourceTest {
|
||||
|
||||
@Test
|
||||
public void setSafetySourceData_activeUnlockEnabled_withFingerprintOnly_setsData() {
|
||||
final int enrolledFingerprintsCount = 1;
|
||||
int enrolledFingerprintsCount = 1;
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(false);
|
||||
@@ -453,7 +462,7 @@ public class BiometricsSafetySourceTest {
|
||||
|
||||
@Test
|
||||
public void setSafetySourceData_activeUnlockEnabled_withFaceAndFingerprint_setsData() {
|
||||
final int enrolledFingerprintsCount = 1;
|
||||
int enrolledFingerprintsCount = 1;
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
@@ -472,7 +481,7 @@ public class BiometricsSafetySourceTest {
|
||||
|
||||
@Test
|
||||
public void setSafetySourceData_faceAndFingerprint_whenNoFaceEnrolled_withFingers_setsData() {
|
||||
final int enrolledFingerprintsCount = 1;
|
||||
int enrolledFingerprintsCount = 1;
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
@@ -660,7 +669,7 @@ public class BiometricsSafetySourceTest {
|
||||
String expectedTitleResName,
|
||||
String expectedSummaryResName,
|
||||
int expectedSummaryQuantity) {
|
||||
final int stringResId =
|
||||
int stringResId =
|
||||
ResourcesUtils.getResourcesId(
|
||||
ApplicationProvider.getApplicationContext(),
|
||||
"string",
|
||||
@@ -676,7 +685,7 @@ public class BiometricsSafetySourceTest {
|
||||
String expectedSummaryResName,
|
||||
int expectedSummaryQuantity,
|
||||
String expectedSettingsClassName) {
|
||||
final int stringResId =
|
||||
int stringResId =
|
||||
ResourcesUtils.getResourcesId(
|
||||
ApplicationProvider.getApplicationContext(),
|
||||
"string",
|
||||
@@ -705,7 +714,7 @@ public class BiometricsSafetySourceTest {
|
||||
assertThat(safetySourceStatus.getSeverityLevel())
|
||||
.isEqualTo(SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED);
|
||||
|
||||
final Intent clickIntent = safetySourceStatus.getPendingIntent().getIntent();
|
||||
Intent clickIntent = safetySourceStatus.getPendingIntent().getIntent();
|
||||
assertThat(clickIntent).isNotNull();
|
||||
assertThat(clickIntent.getAction()).isEqualTo(ACTION_SHOW_ADMIN_SUPPORT_DETAILS);
|
||||
}
|
||||
@@ -725,14 +734,14 @@ public class BiometricsSafetySourceTest {
|
||||
assertThat(safetySourceStatus.getTitle().toString()).isEqualTo(expectedTitle);
|
||||
assertThat(safetySourceStatus.getSummary().toString()).isEqualTo(expectedSummary);
|
||||
assertThat(safetySourceStatus.isEnabled()).isTrue();
|
||||
final Intent clickIntent = safetySourceStatus.getPendingIntent().getIntent();
|
||||
Intent clickIntent = safetySourceStatus.getPendingIntent().getIntent();
|
||||
assertThat(clickIntent).isNotNull();
|
||||
assertThat(clickIntent.getComponent().getPackageName()).isEqualTo("com.android.settings");
|
||||
assertThat(clickIntent.getComponent().getClassName()).isEqualTo(expectedSettingsClassName);
|
||||
}
|
||||
|
||||
private List<Fingerprint> createFingerprintList(int size) {
|
||||
final List<Fingerprint> fingerprintList = new ArrayList<>(size);
|
||||
List<Fingerprint> fingerprintList = new ArrayList<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
fingerprintList.add(new Fingerprint("fingerprint" + i, 0, 0));
|
||||
}
|
||||
|
@@ -0,0 +1,302 @@
|
||||
/*
|
||||
* 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.safetycenter;
|
||||
|
||||
import static android.provider.Settings.ACTION_SHOW_ADMIN_SUPPORT_DETAILS;
|
||||
import static android.safetycenter.SafetyEvent.SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.hardware.face.FaceManager;
|
||||
import android.os.UserHandle;
|
||||
import android.platform.test.annotations.RequiresFlagsEnabled;
|
||||
import android.platform.test.flag.junit.CheckFlagsRule;
|
||||
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
|
||||
import android.safetycenter.SafetyEvent;
|
||||
import android.safetycenter.SafetySourceData;
|
||||
import android.safetycenter.SafetySourceStatus;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.settings.Settings;
|
||||
import com.android.settings.biometrics.face.FaceEnrollIntroductionInternal;
|
||||
import com.android.settings.flags.Flags;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.ResourcesUtils;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
@RequiresFlagsEnabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class FaceSafetySourceTest {
|
||||
|
||||
private static final ComponentName COMPONENT_NAME = new ComponentName("package", "class");
|
||||
private static final UserHandle USER_HANDLE = new UserHandle(UserHandle.myUserId());
|
||||
private static final SafetyEvent EVENT_SOURCE_STATE_CHANGED =
|
||||
new SafetyEvent.Builder(SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED).build();
|
||||
|
||||
@Rule
|
||||
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
|
||||
|
||||
private Context mApplicationContext;
|
||||
|
||||
@Mock private PackageManager mPackageManager;
|
||||
@Mock private DevicePolicyManager mDevicePolicyManager;
|
||||
@Mock private FaceManager mFaceManager;
|
||||
@Mock private LockPatternUtils mLockPatternUtils;
|
||||
@Mock private SafetyCenterManagerWrapper mSafetyCenterManagerWrapper;
|
||||
|
||||
@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.DEVICE_POLICY_SERVICE))
|
||||
.thenReturn(mDevicePolicyManager);
|
||||
when(mApplicationContext.getSystemService(Context.FACE_SERVICE)).thenReturn(mFaceManager);
|
||||
FakeFeatureFactory featureFactory = FakeFeatureFactory.setupForTest();
|
||||
when(featureFactory.securityFeatureProvider.getLockPatternUtils(mApplicationContext))
|
||||
.thenReturn(mLockPatternUtils);
|
||||
doReturn(true).when(mLockPatternUtils).isSecure(anyInt());
|
||||
SafetyCenterManagerWrapper.sInstance = mSafetyCenterManagerWrapper;
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
SafetyCenterManagerWrapper.sInstance = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSafetyData_whenSafetyCenterIsDisabled_doesNotSetData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(false);
|
||||
|
||||
FaceSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
verify(mSafetyCenterManagerWrapper, never())
|
||||
.setSafetySourceData(any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSafetySourceData_whenSafetyCenterIsEnabled_withoutFaceHardware_setsNullData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(false);
|
||||
|
||||
FaceSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
verify(mSafetyCenterManagerWrapper)
|
||||
.setSafetySourceData(any(), eq(FaceSafetySource.SAFETY_SOURCE_ID), eq(null), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSafetySourceData_setsDataForFaceSource() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
|
||||
|
||||
FaceSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
verify(mSafetyCenterManagerWrapper)
|
||||
.setSafetySourceData(any(), eq(FaceSafetySource.SAFETY_SOURCE_ID), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSafetySourceData_setsDataWithCorrectSafetyEvent() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
|
||||
|
||||
FaceSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
verify(mSafetyCenterManagerWrapper)
|
||||
.setSafetySourceData(any(), any(), any(), eq(EVENT_SOURCE_STATE_CHANGED));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSafetySourceData_withFaceNotEnrolled_whenDisabledByAdmin_setsData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(false);
|
||||
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME))
|
||||
.thenReturn(DevicePolicyManager.KEYGUARD_DISABLE_FACE);
|
||||
|
||||
FaceSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
assertSafetySourceDisabledDataSetWithSingularSummary(
|
||||
"security_settings_face_preference_title_new",
|
||||
"security_settings_face_preference_summary_none");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSafetySourceData_withFaceNotEnrolled_whenNotDisabledByAdmin_setsData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(false);
|
||||
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
|
||||
|
||||
FaceSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
assertSafetySourceEnabledDataSetWithSingularSummary(
|
||||
"security_settings_face_preference_title_new",
|
||||
"security_settings_face_preference_summary_none",
|
||||
FaceEnrollIntroductionInternal.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSafetySourceData_withFaceEnrolled_whenDisabledByAdmin_setsData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(true);
|
||||
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME))
|
||||
.thenReturn(DevicePolicyManager.KEYGUARD_DISABLE_FACE);
|
||||
|
||||
FaceSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
assertSafetySourceDisabledDataSetWithSingularSummary(
|
||||
"security_settings_face_preference_title_new",
|
||||
"security_settings_face_preference_summary");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSafetySourceData_withFaceEnrolled_whenNotDisabledByAdmin_setsData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(true);
|
||||
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
|
||||
|
||||
FaceSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
assertSafetySourceEnabledDataSetWithSingularSummary(
|
||||
"security_settings_face_preference_title_new",
|
||||
"security_settings_face_preference_summary",
|
||||
Settings.FaceSettingsInternalActivity.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSafetySourceData_face_whenEnrolled_setsInfoSeverity() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(true);
|
||||
|
||||
FaceSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
|
||||
verify(mSafetyCenterManagerWrapper)
|
||||
.setSafetySourceData(
|
||||
any(), eq(FaceSafetySource.SAFETY_SOURCE_ID), captor.capture(), any());
|
||||
SafetySourceStatus safetySourceStatus = captor.getValue().getStatus();
|
||||
assertThat(safetySourceStatus.getSeverityLevel())
|
||||
.isEqualTo(SafetySourceData.SEVERITY_LEVEL_INFORMATION);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSafetySourceData_face_whenNotEnrolled_setsUnspSeverity() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(false);
|
||||
|
||||
FaceSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
|
||||
verify(mSafetyCenterManagerWrapper)
|
||||
.setSafetySourceData(
|
||||
any(), eq(FaceSafetySource.SAFETY_SOURCE_ID), captor.capture(), any());
|
||||
SafetySourceStatus safetySourceStatus = captor.getValue().getStatus();
|
||||
assertThat(safetySourceStatus.getSeverityLevel())
|
||||
.isEqualTo(SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED);
|
||||
}
|
||||
|
||||
private void assertSafetySourceDisabledDataSetWithSingularSummary(
|
||||
String expectedTitleResName, String expectedSummaryResName) {
|
||||
assertSafetySourceDisabledDataSet(
|
||||
ResourcesUtils.getResourcesString(mApplicationContext, expectedTitleResName),
|
||||
ResourcesUtils.getResourcesString(mApplicationContext, expectedSummaryResName));
|
||||
}
|
||||
|
||||
private void assertSafetySourceEnabledDataSetWithSingularSummary(
|
||||
String expectedTitleResName,
|
||||
String expectedSummaryResName,
|
||||
String expectedSettingsClassName) {
|
||||
assertSafetySourceEnabledDataSet(
|
||||
ResourcesUtils.getResourcesString(mApplicationContext, expectedTitleResName),
|
||||
ResourcesUtils.getResourcesString(mApplicationContext, expectedSummaryResName),
|
||||
expectedSettingsClassName);
|
||||
}
|
||||
|
||||
private void assertSafetySourceDisabledDataSet(String expectedTitle, String expectedSummary) {
|
||||
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
|
||||
verify(mSafetyCenterManagerWrapper)
|
||||
.setSafetySourceData(
|
||||
any(), eq(FaceSafetySource.SAFETY_SOURCE_ID), captor.capture(), any());
|
||||
SafetySourceData safetySourceData = captor.getValue();
|
||||
SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
|
||||
|
||||
assertThat(safetySourceStatus.getTitle().toString()).isEqualTo(expectedTitle);
|
||||
assertThat(safetySourceStatus.getSummary().toString()).isEqualTo(expectedSummary);
|
||||
assertThat(safetySourceStatus.isEnabled()).isFalse();
|
||||
assertThat(safetySourceStatus.getSeverityLevel())
|
||||
.isEqualTo(SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED);
|
||||
|
||||
Intent clickIntent = safetySourceStatus.getPendingIntent().getIntent();
|
||||
assertThat(clickIntent).isNotNull();
|
||||
assertThat(clickIntent.getAction()).isEqualTo(ACTION_SHOW_ADMIN_SUPPORT_DETAILS);
|
||||
}
|
||||
|
||||
private void assertSafetySourceEnabledDataSet(
|
||||
String expectedTitle, String expectedSummary, String expectedSettingsClassName) {
|
||||
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
|
||||
verify(mSafetyCenterManagerWrapper)
|
||||
.setSafetySourceData(
|
||||
any(), eq(FaceSafetySource.SAFETY_SOURCE_ID), captor.capture(), any());
|
||||
SafetySourceData safetySourceData = captor.getValue();
|
||||
SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
|
||||
|
||||
assertThat(safetySourceStatus.getTitle().toString()).isEqualTo(expectedTitle);
|
||||
assertThat(safetySourceStatus.getSummary().toString()).isEqualTo(expectedSummary);
|
||||
assertThat(safetySourceStatus.isEnabled()).isTrue();
|
||||
Intent clickIntent = safetySourceStatus.getPendingIntent().getIntent();
|
||||
assertThat(clickIntent).isNotNull();
|
||||
assertThat(clickIntent.getComponent().getPackageName()).isEqualTo("com.android.settings");
|
||||
assertThat(clickIntent.getComponent().getClassName()).isEqualTo(expectedSettingsClassName);
|
||||
}
|
||||
}
|
@@ -0,0 +1,381 @@
|
||||
/*
|
||||
* 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.safetycenter;
|
||||
|
||||
import static android.provider.Settings.ACTION_SHOW_ADMIN_SUPPORT_DETAILS;
|
||||
import static android.safetycenter.SafetyEvent.SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.hardware.fingerprint.Fingerprint;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.os.UserHandle;
|
||||
import android.platform.test.annotations.RequiresFlagsEnabled;
|
||||
import android.platform.test.flag.junit.CheckFlagsRule;
|
||||
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
|
||||
import android.safetycenter.SafetyEvent;
|
||||
import android.safetycenter.SafetySourceData;
|
||||
import android.safetycenter.SafetySourceStatus;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.settings.biometrics.fingerprint.FingerprintSettings;
|
||||
import com.android.settings.flags.Flags;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.ResourcesUtils;
|
||||
import com.android.settingslib.utils.StringUtil;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RequiresFlagsEnabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class FingerprintSafetySourceTest {
|
||||
|
||||
private static final ComponentName COMPONENT_NAME = new ComponentName("package", "class");
|
||||
private static final UserHandle USER_HANDLE = new UserHandle(UserHandle.myUserId());
|
||||
private static final SafetyEvent EVENT_SOURCE_STATE_CHANGED =
|
||||
new SafetyEvent.Builder(SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED).build();
|
||||
|
||||
@Rule
|
||||
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
|
||||
|
||||
private Context mApplicationContext;
|
||||
|
||||
@Mock private PackageManager mPackageManager;
|
||||
@Mock private DevicePolicyManager mDevicePolicyManager;
|
||||
@Mock private FingerprintManager mFingerprintManager;
|
||||
@Mock private LockPatternUtils mLockPatternUtils;
|
||||
@Mock private SafetyCenterManagerWrapper mSafetyCenterManagerWrapper;
|
||||
|
||||
@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);
|
||||
FakeFeatureFactory featureFactory = FakeFeatureFactory.setupForTest();
|
||||
when(featureFactory.securityFeatureProvider.getLockPatternUtils(mApplicationContext))
|
||||
.thenReturn(mLockPatternUtils);
|
||||
doReturn(true).when(mLockPatternUtils).isSecure(anyInt());
|
||||
SafetyCenterManagerWrapper.sInstance = mSafetyCenterManagerWrapper;
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
SafetyCenterManagerWrapper.sInstance = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSafetyData_whenSafetyCenterIsDisabled_doesNotSetData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(false);
|
||||
|
||||
FingerprintSafetySource.setSafetySourceData(
|
||||
mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
verify(mSafetyCenterManagerWrapper, never())
|
||||
.setSafetySourceData(any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSafetySourceData_whenSafetyCenterIsEnabled_withoutFingerprint_setsNullData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
|
||||
|
||||
FingerprintSafetySource.setSafetySourceData(
|
||||
mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
verify(mSafetyCenterManagerWrapper)
|
||||
.setSafetySourceData(
|
||||
any(), eq(FingerprintSafetySource.SAFETY_SOURCE_ID), eq(null), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSafetySourceData_setsDataForFingerprintSource() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(false);
|
||||
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
|
||||
|
||||
FingerprintSafetySource.setSafetySourceData(
|
||||
mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
verify(mSafetyCenterManagerWrapper)
|
||||
.setSafetySourceData(
|
||||
any(), eq(FingerprintSafetySource.SAFETY_SOURCE_ID), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSafetySourceData_setsDataWithCorrectSafetyEvent() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(false);
|
||||
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
|
||||
|
||||
FingerprintSafetySource.setSafetySourceData(
|
||||
mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
verify(mSafetyCenterManagerWrapper)
|
||||
.setSafetySourceData(any(), any(), any(), eq(EVENT_SOURCE_STATE_CHANGED));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSafetySourceData_withFingerprintNotEnrolled_whenDisabledByAdmin_setsData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(false);
|
||||
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME))
|
||||
.thenReturn(DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT);
|
||||
|
||||
FingerprintSafetySource.setSafetySourceData(
|
||||
mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
assertSafetySourceDisabledDataSetWithSingularSummary(
|
||||
"security_settings_fingerprint",
|
||||
"security_settings_fingerprint_preference_summary_none");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSafetySourceData_withFingerprintNotEnrolled_whenNotDisabledByAdmin_setsData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(false);
|
||||
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
|
||||
|
||||
FingerprintSafetySource.setSafetySourceData(
|
||||
mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
assertSafetySourceEnabledDataSetWithSingularSummary(
|
||||
"security_settings_fingerprint",
|
||||
"security_settings_fingerprint_preference_summary_none",
|
||||
FingerprintSettings.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSafetySourceData_withFingerprintsEnrolled_whenDisabledByAdmin_setsData() {
|
||||
int enrolledFingerprintsCount = 2;
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(true);
|
||||
when(mFingerprintManager.getEnrolledFingerprints(anyInt()))
|
||||
.thenReturn(createFingerprintList(enrolledFingerprintsCount));
|
||||
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME))
|
||||
.thenReturn(DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT);
|
||||
|
||||
FingerprintSafetySource.setSafetySourceData(
|
||||
mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
assertSafetySourceDisabledDataSetWithPluralSummary(
|
||||
"security_settings_fingerprint",
|
||||
"security_settings_fingerprint_preference_summary",
|
||||
enrolledFingerprintsCount);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSafetySourceData_withFingerprintsEnrolled_whenNotDisabledByAdmin_setsData() {
|
||||
int enrolledFingerprintsCount = 2;
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(true);
|
||||
when(mFingerprintManager.getEnrolledFingerprints(anyInt()))
|
||||
.thenReturn(createFingerprintList(enrolledFingerprintsCount));
|
||||
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
|
||||
|
||||
FingerprintSafetySource.setSafetySourceData(
|
||||
mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
assertSafetySourceEnabledDataSetWithPluralSummary(
|
||||
"security_settings_fingerprint",
|
||||
"security_settings_fingerprint_preference_summary",
|
||||
enrolledFingerprintsCount,
|
||||
FingerprintSettings.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSafetySourceData_fingerprint_whenEnrolled_setsInfoSeverity() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(true);
|
||||
|
||||
FingerprintSafetySource.setSafetySourceData(
|
||||
mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
|
||||
verify(mSafetyCenterManagerWrapper)
|
||||
.setSafetySourceData(
|
||||
any(),
|
||||
eq(FingerprintSafetySource.SAFETY_SOURCE_ID),
|
||||
captor.capture(),
|
||||
any());
|
||||
SafetySourceStatus safetySourceStatus = captor.getValue().getStatus();
|
||||
assertThat(safetySourceStatus.getSeverityLevel())
|
||||
.isEqualTo(SafetySourceData.SEVERITY_LEVEL_INFORMATION);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSafetySourceData_fingerprint_whenNotEnrolled_setsUnspSeverity() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(false);
|
||||
|
||||
FingerprintSafetySource.setSafetySourceData(
|
||||
mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
|
||||
verify(mSafetyCenterManagerWrapper)
|
||||
.setSafetySourceData(
|
||||
any(),
|
||||
eq(FingerprintSafetySource.SAFETY_SOURCE_ID),
|
||||
captor.capture(),
|
||||
any());
|
||||
SafetySourceStatus safetySourceStatus = captor.getValue().getStatus();
|
||||
assertThat(safetySourceStatus.getSeverityLevel())
|
||||
.isEqualTo(SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED);
|
||||
}
|
||||
|
||||
private void assertSafetySourceDisabledDataSetWithSingularSummary(
|
||||
String expectedTitleResName, String expectedSummaryResName) {
|
||||
assertSafetySourceDisabledDataSet(
|
||||
ResourcesUtils.getResourcesString(mApplicationContext, expectedTitleResName),
|
||||
ResourcesUtils.getResourcesString(mApplicationContext, expectedSummaryResName));
|
||||
}
|
||||
|
||||
private void assertSafetySourceEnabledDataSetWithSingularSummary(
|
||||
String expectedTitleResName,
|
||||
String expectedSummaryResName,
|
||||
String expectedSettingsClassName) {
|
||||
assertSafetySourceEnabledDataSet(
|
||||
ResourcesUtils.getResourcesString(mApplicationContext, expectedTitleResName),
|
||||
ResourcesUtils.getResourcesString(mApplicationContext, expectedSummaryResName),
|
||||
expectedSettingsClassName);
|
||||
}
|
||||
|
||||
private void assertSafetySourceDisabledDataSetWithPluralSummary(
|
||||
String expectedTitleResName,
|
||||
String expectedSummaryResName,
|
||||
int expectedSummaryQuantity) {
|
||||
int stringResId =
|
||||
ResourcesUtils.getResourcesId(
|
||||
ApplicationProvider.getApplicationContext(),
|
||||
"string",
|
||||
expectedSummaryResName);
|
||||
assertSafetySourceDisabledDataSet(
|
||||
ResourcesUtils.getResourcesString(mApplicationContext, expectedTitleResName),
|
||||
StringUtil.getIcuPluralsString(
|
||||
mApplicationContext, expectedSummaryQuantity, stringResId));
|
||||
}
|
||||
|
||||
private void assertSafetySourceEnabledDataSetWithPluralSummary(
|
||||
String expectedTitleResName,
|
||||
String expectedSummaryResName,
|
||||
int expectedSummaryQuantity,
|
||||
String expectedSettingsClassName) {
|
||||
int stringResId =
|
||||
ResourcesUtils.getResourcesId(
|
||||
ApplicationProvider.getApplicationContext(),
|
||||
"string",
|
||||
expectedSummaryResName);
|
||||
assertSafetySourceEnabledDataSet(
|
||||
ResourcesUtils.getResourcesString(mApplicationContext, expectedTitleResName),
|
||||
StringUtil.getIcuPluralsString(
|
||||
mApplicationContext, expectedSummaryQuantity, stringResId),
|
||||
expectedSettingsClassName);
|
||||
}
|
||||
|
||||
private void assertSafetySourceDisabledDataSet(String expectedTitle, String expectedSummary) {
|
||||
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
|
||||
verify(mSafetyCenterManagerWrapper)
|
||||
.setSafetySourceData(
|
||||
any(),
|
||||
eq(FingerprintSafetySource.SAFETY_SOURCE_ID),
|
||||
captor.capture(),
|
||||
any());
|
||||
SafetySourceData safetySourceData = captor.getValue();
|
||||
SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
|
||||
|
||||
assertThat(safetySourceStatus.getTitle().toString()).isEqualTo(expectedTitle);
|
||||
assertThat(safetySourceStatus.getSummary().toString()).isEqualTo(expectedSummary);
|
||||
assertThat(safetySourceStatus.isEnabled()).isFalse();
|
||||
assertThat(safetySourceStatus.getSeverityLevel())
|
||||
.isEqualTo(SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED);
|
||||
|
||||
Intent clickIntent = safetySourceStatus.getPendingIntent().getIntent();
|
||||
assertThat(clickIntent).isNotNull();
|
||||
assertThat(clickIntent.getAction()).isEqualTo(ACTION_SHOW_ADMIN_SUPPORT_DETAILS);
|
||||
}
|
||||
|
||||
private void assertSafetySourceEnabledDataSet(
|
||||
String expectedTitle, String expectedSummary, String expectedSettingsClassName) {
|
||||
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
|
||||
verify(mSafetyCenterManagerWrapper)
|
||||
.setSafetySourceData(
|
||||
any(),
|
||||
eq(FingerprintSafetySource.SAFETY_SOURCE_ID),
|
||||
captor.capture(),
|
||||
any());
|
||||
SafetySourceData safetySourceData = captor.getValue();
|
||||
SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
|
||||
|
||||
assertThat(safetySourceStatus.getTitle().toString()).isEqualTo(expectedTitle);
|
||||
assertThat(safetySourceStatus.getSummary().toString()).isEqualTo(expectedSummary);
|
||||
assertThat(safetySourceStatus.isEnabled()).isTrue();
|
||||
Intent clickIntent = safetySourceStatus.getPendingIntent().getIntent();
|
||||
assertThat(clickIntent).isNotNull();
|
||||
assertThat(clickIntent.getComponent().getPackageName()).isEqualTo("com.android.settings");
|
||||
assertThat(clickIntent.getComponent().getClassName()).isEqualTo(expectedSettingsClassName);
|
||||
}
|
||||
|
||||
private List<Fingerprint> createFingerprintList(int size) {
|
||||
List<Fingerprint> fingerprintList = new ArrayList<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
fingerprintList.add(new Fingerprint("fingerprint" + i, 0, 0));
|
||||
}
|
||||
return fingerprintList;
|
||||
}
|
||||
}
|
@@ -29,6 +29,10 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.platform.test.annotations.RequiresFlagsDisabled;
|
||||
import android.platform.test.annotations.RequiresFlagsEnabled;
|
||||
import android.platform.test.flag.junit.CheckFlagsRule;
|
||||
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
|
||||
import android.safetycenter.SafetyEvent;
|
||||
import android.safetycenter.SafetySourceData;
|
||||
import android.safetycenter.SafetySourceIssue;
|
||||
@@ -39,12 +43,14 @@ import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.settings.flags.Flags;
|
||||
import com.android.settings.security.ScreenLockPreferenceDetailsUtils;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.ResourcesUtils;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
@@ -62,6 +68,9 @@ public class LockScreenSafetySourceTest {
|
||||
private static final SafetyEvent EVENT_SOURCE_STATE_CHANGED =
|
||||
new SafetyEvent.Builder(SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED).build();
|
||||
|
||||
@Rule
|
||||
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
|
||||
|
||||
private Context mApplicationContext;
|
||||
|
||||
@Mock private SafetyCenterManagerWrapper mSafetyCenterManagerWrapper;
|
||||
@@ -486,7 +495,9 @@ public class LockScreenSafetySourceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onLockScreenChange_whenSafetyCenterEnabled_setsLockscreenAndBiometricData() {
|
||||
@RequiresFlagsDisabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
|
||||
public void
|
||||
onLockScreenChange_whenSafetyCenterEnabled_flagOff_setsLockscreenAndBiometricData() {
|
||||
whenScreenLockIsEnabled();
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
|
||||
@@ -500,6 +511,24 @@ public class LockScreenSafetySourceTest {
|
||||
any(), eq(BiometricsSafetySource.SAFETY_SOURCE_ID), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsEnabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
|
||||
public void onLockScreenChange_whenSafetyCenterEnabled_flagOn_setsLockscreenAndBiometricData() {
|
||||
whenScreenLockIsEnabled();
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
|
||||
LockScreenSafetySource.onLockScreenChange(mApplicationContext);
|
||||
|
||||
verify(mSafetyCenterManagerWrapper)
|
||||
.setSafetySourceData(
|
||||
any(), eq(LockScreenSafetySource.SAFETY_SOURCE_ID), any(), any());
|
||||
verify(mSafetyCenterManagerWrapper)
|
||||
.setSafetySourceData(any(), eq(FaceSafetySource.SAFETY_SOURCE_ID), any(), any());
|
||||
verify(mSafetyCenterManagerWrapper)
|
||||
.setSafetySourceData(
|
||||
any(), eq(FingerprintSafetySource.SAFETY_SOURCE_ID), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onLockScreenChange_whenSafetyCenterDisabled_doesNotSetData() {
|
||||
whenScreenLockIsEnabled();
|
||||
|
@@ -21,8 +21,11 @@ import static android.safetycenter.SafetyCenterManager.EXTRA_REFRESH_SAFETY_SOUR
|
||||
import static android.safetycenter.SafetyCenterManager.EXTRA_REFRESH_SAFETY_SOURCE_IDS;
|
||||
import static android.safetycenter.SafetyEvent.SAFETY_EVENT_TYPE_DEVICE_REBOOTED;
|
||||
import static android.safetycenter.SafetyEvent.SAFETY_EVENT_TYPE_REFRESH_REQUESTED;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -30,7 +33,10 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Flags;
|
||||
import android.platform.test.annotations.RequiresFlagsDisabled;
|
||||
import android.platform.test.annotations.RequiresFlagsEnabled;
|
||||
import android.platform.test.flag.junit.CheckFlagsRule;
|
||||
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.safetycenter.SafetyEvent;
|
||||
import android.safetycenter.SafetySourceData;
|
||||
@@ -39,6 +45,7 @@ import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.settings.flags.Flags;
|
||||
import com.android.settings.privatespace.PrivateSpaceSafetySource;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
|
||||
@@ -51,7 +58,6 @@ import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@@ -61,6 +67,9 @@ public class SafetySourceBroadcastReceiverTest {
|
||||
|
||||
private Context mApplicationContext;
|
||||
|
||||
@Rule
|
||||
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
|
||||
|
||||
@Mock private SafetyCenterManagerWrapper mSafetyCenterManagerWrapper;
|
||||
|
||||
@Mock private LockPatternUtils mLockPatternUtils;
|
||||
@@ -202,6 +211,7 @@ public class SafetySourceBroadcastReceiverTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsDisabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
|
||||
public void onReceive_onRefresh_withBiometricsSourceId_setsBiometricData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
Intent intent =
|
||||
@@ -220,9 +230,49 @@ public class SafetySourceBroadcastReceiverTest {
|
||||
assertThat(captor.getValue()).isEqualTo(BiometricsSafetySource.SAFETY_SOURCE_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsEnabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
|
||||
public void onReceive_onRefresh_withFaceUnlockSourceId_setsFaceUnlockData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
Intent intent =
|
||||
new Intent()
|
||||
.setAction(ACTION_REFRESH_SAFETY_SOURCES)
|
||||
.putExtra(
|
||||
EXTRA_REFRESH_SAFETY_SOURCE_IDS,
|
||||
new String[] {FaceSafetySource.SAFETY_SOURCE_ID})
|
||||
.putExtra(EXTRA_REFRESH_SAFETY_SOURCES_BROADCAST_ID, REFRESH_BROADCAST_ID);
|
||||
|
||||
new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent);
|
||||
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
||||
verify(mSafetyCenterManagerWrapper, times(1))
|
||||
.setSafetySourceData(any(), captor.capture(), any(), any());
|
||||
|
||||
assertThat(captor.getValue()).isEqualTo(FaceSafetySource.SAFETY_SOURCE_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsEnabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
|
||||
public void onReceive_onRefresh_withFingerprintUnlockSourceId_setsFingerprintUnlockData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
Intent intent =
|
||||
new Intent()
|
||||
.setAction(ACTION_REFRESH_SAFETY_SOURCES)
|
||||
.putExtra(
|
||||
EXTRA_REFRESH_SAFETY_SOURCE_IDS,
|
||||
new String[] {FingerprintSafetySource.SAFETY_SOURCE_ID})
|
||||
.putExtra(EXTRA_REFRESH_SAFETY_SOURCES_BROADCAST_ID, REFRESH_BROADCAST_ID);
|
||||
|
||||
new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent);
|
||||
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
||||
verify(mSafetyCenterManagerWrapper, times(1))
|
||||
.setSafetySourceData(any(), captor.capture(), any(), any());
|
||||
|
||||
assertThat(captor.getValue()).isEqualTo(FingerprintSafetySource.SAFETY_SOURCE_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that on receiving the refresh broadcast request with the PS source id, the PS data
|
||||
* is set.
|
||||
* Tests that on receiving the refresh broadcast request with the PS source id, the PS data is
|
||||
* set.
|
||||
*/
|
||||
@Test
|
||||
public void onReceive_onRefresh_withPrivateSpaceSourceId_setsPrivateSpaceData() {
|
||||
@@ -247,7 +297,8 @@ public class SafetySourceBroadcastReceiverTest {
|
||||
@Test
|
||||
public void onReceive_onRefresh_withPrivateSpaceFeatureDisabled_setsNullData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
mSetFlagsRule.disableFlags(Flags.FLAG_ALLOW_PRIVATE_PROFILE,
|
||||
mSetFlagsRule.disableFlags(
|
||||
android.os.Flags.FLAG_ALLOW_PRIVATE_PROFILE,
|
||||
android.multiuser.Flags.FLAG_ENABLE_PRIVATE_SPACE_FEATURES);
|
||||
|
||||
Intent intent =
|
||||
@@ -273,16 +324,48 @@ public class SafetySourceBroadcastReceiverTest {
|
||||
|
||||
new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent);
|
||||
ArgumentCaptor<SafetyEvent> captor = ArgumentCaptor.forClass(SafetyEvent.class);
|
||||
verify(mSafetyCenterManagerWrapper, times(3))
|
||||
verify(mSafetyCenterManagerWrapper, atLeastOnce())
|
||||
.setSafetySourceData(any(), any(), any(), captor.capture());
|
||||
|
||||
SafetyEvent bootEvent = new SafetyEvent.Builder(SAFETY_EVENT_TYPE_DEVICE_REBOOTED).build();
|
||||
assertThat(captor.getAllValues())
|
||||
.containsExactlyElementsIn(Arrays.asList(bootEvent, bootEvent, bootEvent));
|
||||
assertThat(captor.getAllValues()).contains(bootEvent);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onReceive_onBootCompleted_sendsAllSafetySourcesData() {
|
||||
@RequiresFlagsEnabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
|
||||
public void onReceive_onBootCompleted_flagOn_sendsAllSafetySourcesData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
Intent intent = new Intent().setAction(Intent.ACTION_BOOT_COMPLETED);
|
||||
|
||||
new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent);
|
||||
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
||||
verify(mSafetyCenterManagerWrapper, times(4))
|
||||
.setSafetySourceData(any(), captor.capture(), any(), any());
|
||||
List<String> safetySourceIdList = captor.getAllValues();
|
||||
|
||||
assertThat(
|
||||
safetySourceIdList.stream()
|
||||
.anyMatch(id -> id.equals(LockScreenSafetySource.SAFETY_SOURCE_ID)))
|
||||
.isTrue();
|
||||
assertThat(
|
||||
safetySourceIdList.stream()
|
||||
.anyMatch(id -> id.equals(FaceSafetySource.SAFETY_SOURCE_ID)))
|
||||
.isTrue();
|
||||
assertThat(
|
||||
safetySourceIdList.stream()
|
||||
.anyMatch(
|
||||
id -> id.equals(FingerprintSafetySource.SAFETY_SOURCE_ID)))
|
||||
.isTrue();
|
||||
assertThat(
|
||||
safetySourceIdList.stream()
|
||||
.anyMatch(
|
||||
id -> id.equals(PrivateSpaceSafetySource.SAFETY_SOURCE_ID)))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsDisabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
|
||||
public void onReceive_onBootCompleted_flagOff_sendsAllSafetySourcesData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
Intent intent = new Intent().setAction(Intent.ACTION_BOOT_COMPLETED);
|
||||
|
||||
@@ -292,11 +375,18 @@ public class SafetySourceBroadcastReceiverTest {
|
||||
.setSafetySourceData(any(), captor.capture(), any(), any());
|
||||
List<String> safetySourceIdList = captor.getAllValues();
|
||||
|
||||
assertThat(safetySourceIdList.stream().anyMatch(
|
||||
id -> id.equals(LockScreenSafetySource.SAFETY_SOURCE_ID))).isTrue();
|
||||
assertThat(safetySourceIdList.stream().anyMatch(
|
||||
id -> id.equals(BiometricsSafetySource.SAFETY_SOURCE_ID))).isTrue();
|
||||
assertThat(safetySourceIdList.stream().anyMatch(
|
||||
id -> id.equals(PrivateSpaceSafetySource.SAFETY_SOURCE_ID))).isTrue();
|
||||
assertThat(
|
||||
safetySourceIdList.stream()
|
||||
.anyMatch(id -> id.equals(LockScreenSafetySource.SAFETY_SOURCE_ID)))
|
||||
.isTrue();
|
||||
assertThat(
|
||||
safetySourceIdList.stream()
|
||||
.anyMatch(id -> id.equals(BiometricsSafetySource.SAFETY_SOURCE_ID)))
|
||||
.isTrue();
|
||||
assertThat(
|
||||
safetySourceIdList.stream()
|
||||
.anyMatch(
|
||||
id -> id.equals(PrivateSpaceSafetySource.SAFETY_SOURCE_ID)))
|
||||
.isTrue();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user