Merge "Fix tests in Settings that break with the changes in ParentalControlsUtils introduced in ag/31121556." into main
diff --git a/tests/unit/src/com/android/settings/biometrics/combination/CombinedBiometricStatusUtilsTest.java b/tests/unit/src/com/android/settings/biometrics/combination/CombinedBiometricStatusUtilsTest.java
index 3a330f2..f2cf6b9 100644
--- a/tests/unit/src/com/android/settings/biometrics/combination/CombinedBiometricStatusUtilsTest.java
+++ b/tests/unit/src/com/android/settings/biometrics/combination/CombinedBiometricStatusUtilsTest.java
@@ -26,6 +26,7 @@
import static org.mockito.Mockito.when;
import android.app.admin.DevicePolicyManager;
+import android.app.supervision.SupervisionManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
@@ -34,6 +35,8 @@
import android.hardware.fingerprint.FingerprintManager;
import android.os.UserHandle;
import android.os.UserManager;
+import android.platform.test.annotations.DisableFlags;
+import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import androidx.test.core.app.ApplicationProvider;
@@ -70,6 +73,8 @@
private FingerprintManager mFingerprintManager;
@Mock
private FaceManager mFaceManager;
+ @Mock
+ private SupervisionManager mSupervisionManager;
private Context mApplicationContext;
private CombinedBiometricStatusUtils mCombinedBiometricStatusUtils;
@@ -83,13 +88,13 @@
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);
+ when(mApplicationContext.getSystemService(Context.SUPERVISION_SERVICE))
+ .thenReturn(mSupervisionManager);
mCombinedBiometricStatusUtils = new CombinedBiometricStatusUtils(
mApplicationContext, USER_ID);
}
@@ -175,7 +180,10 @@
}
@Test
+ @DisableFlags(android.app.supervision.flags.Flags.FLAG_DEPRECATE_DPM_SUPERVISION_APIS)
public void getDisabledAdmin_whenFingerprintDisabled_whenFaceDisabled_returnsEnforcedAdmin() {
+ when(mDevicePolicyManager.getProfileOwnerOrDeviceOwnerSupervisionComponent(USER_HANDLE))
+ .thenReturn(COMPONENT_NAME);
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME))
.thenReturn(KEYGUARD_DISABLE_FACE | KEYGUARD_DISABLE_FINGERPRINT);
@@ -187,6 +195,20 @@
}
@Test
+ @EnableFlags(android.app.supervision.flags.Flags.FLAG_DEPRECATE_DPM_SUPERVISION_APIS)
+ public void getDisabledAdmin_whenFingerprintDisabled_whenFaceDisabled_returnsRestrictions() {
+ when(mSupervisionManager.isSupervisionEnabledForUser(USER_ID)).thenReturn(true);
+ when(mDevicePolicyManager.getKeyguardDisabledFeatures(null))
+ .thenReturn(KEYGUARD_DISABLE_FACE | KEYGUARD_DISABLE_FINGERPRINT);
+
+ final RestrictedLockUtils.EnforcedAdmin admin =
+ mCombinedBiometricStatusUtils.getDisablingAdmin();
+
+ assertThat(admin.enforcedRestriction).isEqualTo(UserManager.DISALLOW_BIOMETRIC);
+ assertThat(admin.user).isEqualTo(USER_HANDLE);
+ }
+
+ @Test
public void getDisabledAdmin_whenFingerprintDisabled_whenFaceEnabled_returnsNull() {
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME))
.thenReturn(KEYGUARD_DISABLE_FINGERPRINT);
diff --git a/tests/unit/src/com/android/settings/biometrics/face/FaceStatusUtilsTest.java b/tests/unit/src/com/android/settings/biometrics/face/FaceStatusUtilsTest.java
index 6dfb1e6..f5d090a 100644
--- a/tests/unit/src/com/android/settings/biometrics/face/FaceStatusUtilsTest.java
+++ b/tests/unit/src/com/android/settings/biometrics/face/FaceStatusUtilsTest.java
@@ -23,6 +23,7 @@
import static org.mockito.Mockito.when;
import android.app.admin.DevicePolicyManager;
+import android.app.supervision.SupervisionManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
@@ -30,6 +31,9 @@
import android.hardware.fingerprint.FingerprintManager;
import android.os.UserHandle;
import android.os.UserManager;
+import android.platform.test.annotations.DisableFlags;
+import android.platform.test.annotations.EnableFlags;
+import android.platform.test.flag.junit.SetFlagsRule;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -39,6 +43,7 @@
import com.android.settingslib.RestrictedLockUtils;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -47,12 +52,14 @@
@RunWith(AndroidJUnit4.class)
public class FaceStatusUtilsTest {
+ @Rule
+ public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
+
private static final ComponentName COMPONENT_NAME =
new ComponentName("package", "class");
private static final int USER_ID = UserHandle.myUserId();
private static final UserHandle USER_HANDLE = new UserHandle(USER_ID);
-
@Mock
private PackageManager mPackageManager;
@Mock
@@ -61,6 +68,8 @@
private FingerprintManager mFingerprintManager;
@Mock
private FaceManager mFaceManager;
+ @Mock
+ private SupervisionManager mSupervisionManager;
private Context mApplicationContext;
private FaceStatusUtils mFaceStatusUtils;
@@ -72,13 +81,13 @@
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);
+ when(mApplicationContext.getSystemService(Context.SUPERVISION_SERVICE))
+ .thenReturn(mSupervisionManager);
mFaceStatusUtils = new FaceStatusUtils(mApplicationContext, mFaceManager, USER_ID);
}
@@ -129,7 +138,10 @@
}
@Test
+ @DisableFlags(android.app.supervision.flags.Flags.FLAG_DEPRECATE_DPM_SUPERVISION_APIS)
public void getDisabledAdmin_whenFaceDisabled_returnsEnforcedAdmin() {
+ when(mDevicePolicyManager.getProfileOwnerOrDeviceOwnerSupervisionComponent(USER_HANDLE))
+ .thenReturn(COMPONENT_NAME);
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME))
.thenReturn(DevicePolicyManager.KEYGUARD_DISABLE_FACE);
@@ -140,6 +152,19 @@
}
@Test
+ @EnableFlags(android.app.supervision.flags.Flags.FLAG_DEPRECATE_DPM_SUPERVISION_APIS)
+ public void getDisabledAdmin_whenFaceDisabled_returnsRestriction() {
+ when(mSupervisionManager.isSupervisionEnabledForUser(USER_ID)).thenReturn(true);
+ when(mDevicePolicyManager.getKeyguardDisabledFeatures(null))
+ .thenReturn(DevicePolicyManager.KEYGUARD_DISABLE_FACE);
+
+ final RestrictedLockUtils.EnforcedAdmin admin = mFaceStatusUtils.getDisablingAdmin();
+
+ assertThat(admin.enforcedRestriction).isEqualTo(UserManager.DISALLOW_BIOMETRIC);
+ assertThat(admin.user).isEqualTo(USER_HANDLE);
+ }
+
+ @Test
public void getDisabledAdmin_withFaceEnabled_returnsNull() {
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
diff --git a/tests/unit/src/com/android/settings/biometrics/fingerprint/FingerprintStatusUtilsTest.java b/tests/unit/src/com/android/settings/biometrics/fingerprint/FingerprintStatusUtilsTest.java
index 450adc6..375c1ff 100644
--- a/tests/unit/src/com/android/settings/biometrics/fingerprint/FingerprintStatusUtilsTest.java
+++ b/tests/unit/src/com/android/settings/biometrics/fingerprint/FingerprintStatusUtilsTest.java
@@ -23,6 +23,7 @@
import static org.mockito.Mockito.when;
import android.app.admin.DevicePolicyManager;
+import android.app.supervision.SupervisionManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
@@ -31,6 +32,9 @@
import android.hardware.fingerprint.FingerprintManager;
import android.os.UserHandle;
import android.os.UserManager;
+import android.platform.test.annotations.DisableFlags;
+import android.platform.test.annotations.EnableFlags;
+import android.platform.test.flag.junit.SetFlagsRule;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -40,6 +44,7 @@
import com.android.settingslib.utils.StringUtil;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -51,12 +56,14 @@
@RunWith(AndroidJUnit4.class)
public class FingerprintStatusUtilsTest {
+ @Rule
+ public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
+
private static final ComponentName COMPONENT_NAME =
new ComponentName("package", "class");
private static final int USER_ID = UserHandle.myUserId();
private static final UserHandle USER_HANDLE = new UserHandle(USER_ID);
-
@Mock
private PackageManager mPackageManager;
@Mock
@@ -65,6 +72,8 @@
private FingerprintManager mFingerprintManager;
@Mock
private FaceManager mFaceManager;
+ @Mock
+ private SupervisionManager mSupervisionManager;
private Context mApplicationContext;
private FingerprintStatusUtils mFingerprintStatusUtils;
@@ -76,13 +85,13 @@
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);
+ when(mApplicationContext.getSystemService(Context.SUPERVISION_SERVICE))
+ .thenReturn(mSupervisionManager);
mFingerprintStatusUtils =
new FingerprintStatusUtils(mApplicationContext, mFingerprintManager, USER_ID);
}
@@ -134,7 +143,10 @@
}
@Test
+ @DisableFlags(android.app.supervision.flags.Flags.FLAG_DEPRECATE_DPM_SUPERVISION_APIS)
public void getDisabledAdmin_whenFingerprintDisabled_returnsEnforcedAdmin() {
+ when(mDevicePolicyManager.getProfileOwnerOrDeviceOwnerSupervisionComponent(USER_HANDLE))
+ .thenReturn(COMPONENT_NAME);
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME))
.thenReturn(DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT);
@@ -146,6 +158,20 @@
}
@Test
+ @EnableFlags(android.app.supervision.flags.Flags.FLAG_DEPRECATE_DPM_SUPERVISION_APIS)
+ public void getDisabledAdmin_whenFingerprintDisabled_returnsRestriction() {
+ when(mSupervisionManager.isSupervisionEnabledForUser(USER_ID)).thenReturn(true);
+ when(mDevicePolicyManager.getKeyguardDisabledFeatures(null))
+ .thenReturn(DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT);
+
+ final RestrictedLockUtils.EnforcedAdmin admin =
+ mFingerprintStatusUtils.getDisablingAdmin();
+
+ assertThat(admin.enforcedRestriction).isEqualTo(UserManager.DISALLOW_BIOMETRIC);
+ assertThat(admin.user).isEqualTo(USER_HANDLE);
+ }
+
+ @Test
public void getDisabledAdmin_withFingerprintEnabled_returnsNull() {
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
diff --git a/tests/unit/src/com/android/settings/safetycenter/FaceSafetySourceTest.java b/tests/unit/src/com/android/settings/safetycenter/FaceSafetySourceTest.java
index f956087..716c21e 100644
--- a/tests/unit/src/com/android/settings/safetycenter/FaceSafetySourceTest.java
+++ b/tests/unit/src/com/android/settings/safetycenter/FaceSafetySourceTest.java
@@ -31,15 +31,17 @@
import static org.mockito.Mockito.when;
import android.app.admin.DevicePolicyManager;
+import android.app.supervision.SupervisionManager;
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.DisableFlags;
+import android.platform.test.annotations.EnableFlags;
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;
import android.safetycenter.SafetySourceStatus;
@@ -68,12 +70,13 @@
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 int USER_ID = UserHandle.myUserId();
+ private static final UserHandle USER_HANDLE = new UserHandle(USER_ID);
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();
+ public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
private Context mApplicationContext;
@@ -82,6 +85,7 @@
@Mock private FaceManager mFaceManager;
@Mock private LockPatternUtils mLockPatternUtils;
@Mock private SafetyCenterManagerWrapper mSafetyCenterManagerWrapper;
+ @Mock private SupervisionManager mSupervisionManager;
@Before
public void setUp() {
@@ -90,11 +94,11 @@
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);
+ when(mApplicationContext.getSystemService(Context.SUPERVISION_SERVICE))
+ .thenReturn(mSupervisionManager);
FakeFeatureFactory featureFactory = FakeFeatureFactory.setupForTest();
when(featureFactory.securityFeatureProvider.getLockPatternUtils(mApplicationContext))
.thenReturn(mLockPatternUtils);
@@ -153,7 +157,10 @@
}
@Test
+ @DisableFlags(android.app.supervision.flags.Flags.FLAG_DEPRECATE_DPM_SUPERVISION_APIS)
public void setSafetySourceData_withFaceNotEnrolled_whenDisabledByAdmin_setsData() {
+ when(mDevicePolicyManager.getProfileOwnerOrDeviceOwnerSupervisionComponent(USER_HANDLE))
+ .thenReturn(COMPONENT_NAME);
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mFaceManager.isHardwareDetected()).thenReturn(true);
when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(false);
@@ -168,6 +175,23 @@
}
@Test
+ @EnableFlags(android.app.supervision.flags.Flags.FLAG_DEPRECATE_DPM_SUPERVISION_APIS)
+ public void setSafetySourceData_withFaceNotEnrolled_whenSupervisionIsOn_setsData() {
+ when(mSupervisionManager.isSupervisionEnabledForUser(USER_ID)).thenReturn(true);
+ when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
+ when(mFaceManager.isHardwareDetected()).thenReturn(true);
+ when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(false);
+ when(mDevicePolicyManager.getKeyguardDisabledFeatures(null))
+ .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);
@@ -183,7 +207,10 @@
}
@Test
+ @DisableFlags(android.app.supervision.flags.Flags.FLAG_DEPRECATE_DPM_SUPERVISION_APIS)
public void setSafetySourceData_withFaceEnrolled_whenDisabledByAdmin_setsData() {
+ when(mDevicePolicyManager.getProfileOwnerOrDeviceOwnerSupervisionComponent(USER_HANDLE))
+ .thenReturn(COMPONENT_NAME);
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mFaceManager.isHardwareDetected()).thenReturn(true);
when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(true);
@@ -198,6 +225,23 @@
}
@Test
+ @EnableFlags(android.app.supervision.flags.Flags.FLAG_DEPRECATE_DPM_SUPERVISION_APIS)
+ public void setSafetySourceData_withFaceEnrolled_whenSupervisionIsOn_setsData() {
+ when(mSupervisionManager.isSupervisionEnabledForUser(USER_ID)).thenReturn(true);
+ when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
+ when(mFaceManager.isHardwareDetected()).thenReturn(true);
+ when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(true);
+ when(mDevicePolicyManager.getKeyguardDisabledFeatures(null))
+ .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);
diff --git a/tests/unit/src/com/android/settings/safetycenter/FingerprintSafetySourceTest.java b/tests/unit/src/com/android/settings/safetycenter/FingerprintSafetySourceTest.java
index 68e5349..a12979c 100644
--- a/tests/unit/src/com/android/settings/safetycenter/FingerprintSafetySourceTest.java
+++ b/tests/unit/src/com/android/settings/safetycenter/FingerprintSafetySourceTest.java
@@ -31,6 +31,7 @@
import static org.mockito.Mockito.when;
import android.app.admin.DevicePolicyManager;
+import android.app.supervision.SupervisionManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -38,9 +39,10 @@
import android.hardware.fingerprint.Fingerprint;
import android.hardware.fingerprint.FingerprintManager;
import android.os.UserHandle;
+import android.platform.test.annotations.DisableFlags;
+import android.platform.test.annotations.EnableFlags;
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;
import android.safetycenter.SafetySourceStatus;
@@ -72,12 +74,13 @@
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 int USER_ID = UserHandle.myUserId();
+ private static final UserHandle USER_HANDLE = new UserHandle(USER_ID);
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();
+ public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
private Context mApplicationContext;
@@ -86,6 +89,7 @@
@Mock private FingerprintManager mFingerprintManager;
@Mock private LockPatternUtils mLockPatternUtils;
@Mock private SafetyCenterManagerWrapper mSafetyCenterManagerWrapper;
+ @Mock private SupervisionManager mSupervisionManager;
@Before
public void setUp() {
@@ -94,12 +98,12 @@
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.SUPERVISION_SERVICE))
+ .thenReturn(mSupervisionManager);
FakeFeatureFactory featureFactory = FakeFeatureFactory.setupForTest();
when(featureFactory.securityFeatureProvider.getLockPatternUtils(mApplicationContext))
.thenReturn(mLockPatternUtils);
@@ -166,7 +170,10 @@
}
@Test
+ @DisableFlags(android.app.supervision.flags.Flags.FLAG_DEPRECATE_DPM_SUPERVISION_APIS)
public void setSafetySourceData_withFingerprintNotEnrolled_whenDisabledByAdmin_setsData() {
+ when(mDevicePolicyManager.getProfileOwnerOrDeviceOwnerSupervisionComponent(USER_HANDLE))
+ .thenReturn(COMPONENT_NAME);
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(false);
@@ -182,6 +189,24 @@
}
@Test
+ @EnableFlags(android.app.supervision.flags.Flags.FLAG_DEPRECATE_DPM_SUPERVISION_APIS)
+ public void setSafetySourceData_withFingerprintNotEnrolled_whenSupervisionIsOn_setsData() {
+ when(mSupervisionManager.isSupervisionEnabledForUser(USER_ID)).thenReturn(true);
+ when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
+ when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
+ when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(false);
+ when(mDevicePolicyManager.getKeyguardDisabledFeatures(null))
+ .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);
@@ -198,8 +223,11 @@
}
@Test
+ @DisableFlags(android.app.supervision.flags.Flags.FLAG_DEPRECATE_DPM_SUPERVISION_APIS)
public void setSafetySourceData_withFingerprintsEnrolled_whenDisabledByAdmin_setsData() {
int enrolledFingerprintsCount = 2;
+ when(mDevicePolicyManager.getProfileOwnerOrDeviceOwnerSupervisionComponent(USER_HANDLE))
+ .thenReturn(COMPONENT_NAME);
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(true);
@@ -218,6 +246,28 @@
}
@Test
+ @EnableFlags(android.app.supervision.flags.Flags.FLAG_DEPRECATE_DPM_SUPERVISION_APIS)
+ public void setSafetySourceData_withFingerprintsEnrolled_whenSupervisionIsOn_setsData() {
+ int enrolledFingerprintsCount = 2;
+ when(mSupervisionManager.isSupervisionEnabledForUser(USER_ID)).thenReturn(true);
+ 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(null))
+ .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);