Merge "[SafetyCenter] Update Settings to align with renamed SafetyCenterManager APIs" into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
5ccb07df85
@@ -17,6 +17,7 @@
|
||||
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;
|
||||
|
||||
@@ -36,6 +37,7 @@ import android.hardware.face.FaceManager;
|
||||
import android.hardware.fingerprint.Fingerprint;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.os.UserHandle;
|
||||
import android.safetycenter.SafetyEvent;
|
||||
import android.safetycenter.SafetySourceData;
|
||||
import android.safetycenter.SafetySourceStatus;
|
||||
|
||||
@@ -66,6 +68,8 @@ public class BiometricsSafetySourceTest {
|
||||
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();
|
||||
|
||||
private Context mApplicationContext;
|
||||
|
||||
@@ -103,27 +107,61 @@ public class BiometricsSafetySourceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_whenSafetyCenterIsDisabled_sendsNoData() {
|
||||
public void setSafetyData_whenSafetyCenterIsDisabled_doesNotSetData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(false);
|
||||
|
||||
BiometricsSafetySource.sendSafetyData(mApplicationContext);
|
||||
BiometricsSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
verify(mSafetyCenterManagerWrapper, never()).sendSafetyCenterUpdate(any(), any());
|
||||
verify(mSafetyCenterManagerWrapper, never()).setSafetySourceData(
|
||||
any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_whenSafetyCenterIsEnabled_withoutBiometrics_sendsNoData() {
|
||||
public void setSafetySourceData_whenSafetyCenterIsEnabled_withoutBiometrics_doesNotSetData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(false);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(false);
|
||||
|
||||
BiometricsSafetySource.sendSafetyData(mApplicationContext);
|
||||
BiometricsSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
verify(mSafetyCenterManagerWrapper, never()).sendSafetyCenterUpdate(any(), any());
|
||||
verify(mSafetyCenterManagerWrapper, never()).setSafetySourceData(
|
||||
any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_withFingerprintNotEnrolled_whenDisabledByAdmin_sendsData() {
|
||||
public void setSafetySourceData_setsDataForBiometricSource() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(false);
|
||||
when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(false);
|
||||
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
|
||||
|
||||
BiometricsSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
||||
verify(mSafetyCenterManagerWrapper).setSafetySourceData(
|
||||
any(), captor.capture(), any(), any());
|
||||
|
||||
assertThat(captor.getValue()).isEqualTo(BiometricsSafetySource.SAFETY_SOURCE_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSafetySourceData_setsDataWithCorrectSafetyEvent() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(false);
|
||||
when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(false);
|
||||
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
|
||||
|
||||
BiometricsSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
ArgumentCaptor<SafetyEvent> captor = ArgumentCaptor.forClass(SafetyEvent.class);
|
||||
verify(mSafetyCenterManagerWrapper).setSafetySourceData(
|
||||
any(), any(), any(), captor.capture());
|
||||
|
||||
assertThat(captor.getValue()).isEqualTo(EVENT_SOURCE_STATE_CHANGED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSafetySourceData_withFingerprintNotEnrolled_whenDisabledByAdmin_setsData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(false);
|
||||
@@ -131,31 +169,31 @@ public class BiometricsSafetySourceTest {
|
||||
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME))
|
||||
.thenReturn(DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT);
|
||||
|
||||
BiometricsSafetySource.sendSafetyData(mApplicationContext);
|
||||
BiometricsSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
assertSafetySourceDisabledDataSentWithSingularSummary(
|
||||
assertSafetySourceDisabledDataSetWithSingularSummary(
|
||||
"security_settings_fingerprint_preference_title",
|
||||
"security_settings_fingerprint_preference_summary_none");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_withFingerprintNotEnrolled_whenNotDisabledByAdmin_sendsData() {
|
||||
public void setSafetySourceData_withFingerprintNotEnrolled_whenNotDisabledByAdmin_setsData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(false);
|
||||
when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(false);
|
||||
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
|
||||
|
||||
BiometricsSafetySource.sendSafetyData(mApplicationContext);
|
||||
BiometricsSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
assertSafetySourceEnabledDataSentWithSingularSummary(
|
||||
assertSafetySourceEnabledDataSetWithSingularSummary(
|
||||
"security_settings_fingerprint_preference_title",
|
||||
"security_settings_fingerprint_preference_summary_none",
|
||||
FingerprintEnrollIntroduction.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_withFingerprintsEnrolled_whenDisabledByAdmin_sendsData() {
|
||||
public void setSafetySourceData_withFingerprintsEnrolled_whenDisabledByAdmin_setsData() {
|
||||
final int enrolledFingerprintsCount = 2;
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
@@ -166,16 +204,16 @@ public class BiometricsSafetySourceTest {
|
||||
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME))
|
||||
.thenReturn(DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT);
|
||||
|
||||
BiometricsSafetySource.sendSafetyData(mApplicationContext);
|
||||
BiometricsSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
assertSafetySourceDisabledDataSentWithPluralSummary(
|
||||
assertSafetySourceDisabledDataSetWithPluralSummary(
|
||||
"security_settings_fingerprint_preference_title",
|
||||
"security_settings_fingerprint_preference_summary",
|
||||
enrolledFingerprintsCount);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_withFingerprintsEnrolled_whenNotDisabledByAdmin_sendsData() {
|
||||
public void setSafetySourceData_withFingerprintsEnrolled_whenNotDisabledByAdmin_setsData() {
|
||||
final int enrolledFingerprintsCount = 2;
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
@@ -185,16 +223,16 @@ public class BiometricsSafetySourceTest {
|
||||
.thenReturn(createFingerprintList(enrolledFingerprintsCount));
|
||||
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
|
||||
|
||||
BiometricsSafetySource.sendSafetyData(mApplicationContext);
|
||||
BiometricsSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
assertSafetySourceEnabledDataSentWithPluralSummary(
|
||||
assertSafetySourceEnabledDataSetWithPluralSummary(
|
||||
"security_settings_fingerprint_preference_title",
|
||||
"security_settings_fingerprint_preference_summary", enrolledFingerprintsCount,
|
||||
FingerprintSettings.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_withFaceNotEnrolled_whenDisabledByAdmin_sendsData() {
|
||||
public void setSafetySourceData_withFaceNotEnrolled_whenDisabledByAdmin_setsData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
@@ -202,31 +240,31 @@ public class BiometricsSafetySourceTest {
|
||||
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME))
|
||||
.thenReturn(DevicePolicyManager.KEYGUARD_DISABLE_FACE);
|
||||
|
||||
BiometricsSafetySource.sendSafetyData(mApplicationContext);
|
||||
BiometricsSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
assertSafetySourceDisabledDataSentWithSingularSummary(
|
||||
assertSafetySourceDisabledDataSetWithSingularSummary(
|
||||
"security_settings_face_preference_title",
|
||||
"security_settings_face_preference_summary_none");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_withFaceNotEnrolled_whenNotDisabledByAdmin_sendsData() {
|
||||
public void setSafetySourceData_withFaceNotEnrolled_whenNotDisabledByAdmin_setsData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(false);
|
||||
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
|
||||
|
||||
BiometricsSafetySource.sendSafetyData(mApplicationContext);
|
||||
BiometricsSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
assertSafetySourceEnabledDataSentWithSingularSummary(
|
||||
assertSafetySourceEnabledDataSetWithSingularSummary(
|
||||
"security_settings_face_preference_title",
|
||||
"security_settings_face_preference_summary_none",
|
||||
FaceEnrollIntroduction.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_withFaceEnrolled_whenDisabledByAdmin_sendsData() {
|
||||
public void setSafetySourceData_withFaceEnrolled_whenDisabledByAdmin_setsData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
@@ -234,78 +272,78 @@ public class BiometricsSafetySourceTest {
|
||||
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME))
|
||||
.thenReturn(DevicePolicyManager.KEYGUARD_DISABLE_FACE);
|
||||
|
||||
BiometricsSafetySource.sendSafetyData(mApplicationContext);
|
||||
BiometricsSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
assertSafetySourceDisabledDataSentWithSingularSummary(
|
||||
assertSafetySourceDisabledDataSetWithSingularSummary(
|
||||
"security_settings_face_preference_title",
|
||||
"security_settings_face_preference_summary");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_withFaceEnrolled_whenNotDisabledByAdmin_sendsData() {
|
||||
public void setSafetySourceData_withFaceEnrolled_whenNotDisabledByAdmin_setsData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(true);
|
||||
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
|
||||
|
||||
BiometricsSafetySource.sendSafetyData(mApplicationContext);
|
||||
BiometricsSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
assertSafetySourceEnabledDataSentWithSingularSummary(
|
||||
assertSafetySourceEnabledDataSetWithSingularSummary(
|
||||
"security_settings_face_preference_title",
|
||||
"security_settings_face_preference_summary",
|
||||
Settings.FaceSettingsActivity.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sandSafetyData_withFaceAndFingerprint_whenBothNotDisabledByAdmin_sendsData() {
|
||||
public void setSafetySourceData_withFaceAndFingerprint_whenBothNotDisabledByAdmin_setsData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
|
||||
|
||||
BiometricsSafetySource.sendSafetyData(mApplicationContext);
|
||||
BiometricsSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
assertSafetySourceEnabledDataSentWithSingularSummary(
|
||||
assertSafetySourceEnabledDataSetWithSingularSummary(
|
||||
"security_settings_biometric_preference_title",
|
||||
"security_settings_biometric_preference_summary_none_enrolled",
|
||||
Settings.CombinedBiometricSettingsActivity.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sandSafetyData_withFaceAndFingerprint_whenFaceDisabledByAdmin_sendsData() {
|
||||
public void setSafetySourceData_withFaceAndFingerprint_whenFaceDisabledByAdmin_setsData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME))
|
||||
.thenReturn(DevicePolicyManager.KEYGUARD_DISABLE_FACE);
|
||||
|
||||
BiometricsSafetySource.sendSafetyData(mApplicationContext);
|
||||
BiometricsSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
assertSafetySourceEnabledDataSentWithSingularSummary(
|
||||
assertSafetySourceEnabledDataSetWithSingularSummary(
|
||||
"security_settings_biometric_preference_title",
|
||||
"security_settings_biometric_preference_summary_none_enrolled",
|
||||
Settings.CombinedBiometricSettingsActivity.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sandSafetyData_withFaceAndFingerprint_whenFingerprintDisabledByAdmin_sendsData() {
|
||||
public void setSafetySourceData_faceAndFingerprint_whenFingerprintDisabledByAdmin_setsData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME))
|
||||
.thenReturn(DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT);
|
||||
|
||||
BiometricsSafetySource.sendSafetyData(mApplicationContext);
|
||||
BiometricsSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
assertSafetySourceEnabledDataSentWithSingularSummary(
|
||||
assertSafetySourceEnabledDataSetWithSingularSummary(
|
||||
"security_settings_biometric_preference_title",
|
||||
"security_settings_biometric_preference_summary_none_enrolled",
|
||||
Settings.CombinedBiometricSettingsActivity.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sandSafetyData_withFaceAndFingerprint_whenBothDisabledByAdmin_sendsData() {
|
||||
public void setSafetySourceData_faceAndFingerprint_whenBothDisabledByAdmin_setsData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
@@ -313,15 +351,15 @@ public class BiometricsSafetySourceTest {
|
||||
.thenReturn(DevicePolicyManager.KEYGUARD_DISABLE_FACE
|
||||
| DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT);
|
||||
|
||||
BiometricsSafetySource.sendSafetyData(mApplicationContext);
|
||||
BiometricsSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
assertSafetySourceDisabledDataSentWithSingularSummary(
|
||||
assertSafetySourceDisabledDataSetWithSingularSummary(
|
||||
"security_settings_biometric_preference_title",
|
||||
"security_settings_biometric_preference_summary_none_enrolled");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sandSafetyData_withFaceAndFingerprint_whenFaceEnrolled_withMpFingers_sendsData() {
|
||||
public void setSafetySourceData_faceAndFingerprint_whenFaceEnrolled_withMpFingers_setsData() {
|
||||
final int enrolledFingerprintsCount = 2;
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
@@ -330,16 +368,16 @@ public class BiometricsSafetySourceTest {
|
||||
when(mFingerprintManager.getEnrolledFingerprints(anyInt())).thenReturn(
|
||||
createFingerprintList(enrolledFingerprintsCount));
|
||||
|
||||
BiometricsSafetySource.sendSafetyData(mApplicationContext);
|
||||
BiometricsSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
assertSafetySourceEnabledDataSentWithSingularSummary(
|
||||
assertSafetySourceEnabledDataSetWithSingularSummary(
|
||||
"security_settings_biometric_preference_title",
|
||||
"security_settings_biometric_preference_summary_both_fp_multiple",
|
||||
Settings.CombinedBiometricSettingsActivity.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sandSafetyData_withFaceAndFingerprint_whenFaceEnrolled_withOneFinger_sendsData() {
|
||||
public void setSafetySourceData_faceAndFingerprint_whenFaceEnrolled_withOneFinger_setsData() {
|
||||
final int enrolledFingerprintsCount = 1;
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
@@ -348,16 +386,16 @@ public class BiometricsSafetySourceTest {
|
||||
when(mFingerprintManager.getEnrolledFingerprints(anyInt())).thenReturn(
|
||||
createFingerprintList(enrolledFingerprintsCount));
|
||||
|
||||
BiometricsSafetySource.sendSafetyData(mApplicationContext);
|
||||
BiometricsSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
assertSafetySourceEnabledDataSentWithSingularSummary(
|
||||
assertSafetySourceEnabledDataSetWithSingularSummary(
|
||||
"security_settings_biometric_preference_title",
|
||||
"security_settings_biometric_preference_summary_both_fp_single",
|
||||
Settings.CombinedBiometricSettingsActivity.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sandSafetyData_withFaceAndFingerprint_whenFaceEnrolled_withNoFingers_sendsData() {
|
||||
public void setSafetySourceData_faceAndFingerprint_whenFaceEnrolled_withNoFingers_setsData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
when(mFaceManager.isHardwareDetected()).thenReturn(true);
|
||||
@@ -365,16 +403,16 @@ public class BiometricsSafetySourceTest {
|
||||
when(mFingerprintManager.getEnrolledFingerprints(anyInt())).thenReturn(
|
||||
Collections.emptyList());
|
||||
|
||||
BiometricsSafetySource.sendSafetyData(mApplicationContext);
|
||||
BiometricsSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
assertSafetySourceEnabledDataSentWithSingularSummary(
|
||||
assertSafetySourceEnabledDataSetWithSingularSummary(
|
||||
"security_settings_biometric_preference_title",
|
||||
"security_settings_face_preference_summary",
|
||||
Settings.CombinedBiometricSettingsActivity.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sandSafetyData_withFaceAndFingerprint_whenNoFaceEnrolled_withFingers_sendsData() {
|
||||
public void setSafetySourceData_faceAndFingerprint_whenNoFaceEnrolled_withFingers_setsData() {
|
||||
final int enrolledFingerprintsCount = 1;
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
|
||||
@@ -383,38 +421,38 @@ public class BiometricsSafetySourceTest {
|
||||
when(mFingerprintManager.getEnrolledFingerprints(anyInt())).thenReturn(
|
||||
createFingerprintList(enrolledFingerprintsCount));
|
||||
|
||||
BiometricsSafetySource.sendSafetyData(mApplicationContext);
|
||||
BiometricsSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
assertSafetySourceEnabledDataSentWithPluralSummary(
|
||||
assertSafetySourceEnabledDataSetWithPluralSummary(
|
||||
"security_settings_biometric_preference_title",
|
||||
"security_settings_fingerprint_preference_summary", enrolledFingerprintsCount,
|
||||
Settings.CombinedBiometricSettingsActivity.class.getName());
|
||||
}
|
||||
|
||||
private void assertSafetySourceDisabledDataSentWithSingularSummary(String expectedTitleResName,
|
||||
private void assertSafetySourceDisabledDataSetWithSingularSummary(String expectedTitleResName,
|
||||
String expectedSummaryResName) {
|
||||
assertSafetySourceDisabledDataSent(
|
||||
assertSafetySourceDisabledDataSet(
|
||||
ResourcesUtils.getResourcesString(mApplicationContext, expectedTitleResName),
|
||||
ResourcesUtils.getResourcesString(mApplicationContext, expectedSummaryResName)
|
||||
);
|
||||
}
|
||||
|
||||
private void assertSafetySourceEnabledDataSentWithSingularSummary(String expectedTitleResName,
|
||||
private void assertSafetySourceEnabledDataSetWithSingularSummary(String expectedTitleResName,
|
||||
String expectedSummaryResName,
|
||||
String expectedSettingsClassName) {
|
||||
assertSafetySourceEnabledDataSent(
|
||||
assertSafetySourceEnabledDataSet(
|
||||
ResourcesUtils.getResourcesString(mApplicationContext, expectedTitleResName),
|
||||
ResourcesUtils.getResourcesString(mApplicationContext, expectedSummaryResName),
|
||||
expectedSettingsClassName
|
||||
);
|
||||
}
|
||||
|
||||
private void assertSafetySourceDisabledDataSentWithPluralSummary(String expectedTitleResName,
|
||||
private void assertSafetySourceDisabledDataSetWithPluralSummary(String expectedTitleResName,
|
||||
String expectedSummaryResName, int expectedSummaryQuantity) {
|
||||
final int stringResId = ResourcesUtils.getResourcesId(
|
||||
ApplicationProvider.getApplicationContext(), "plurals",
|
||||
expectedSummaryResName);
|
||||
assertSafetySourceDisabledDataSent(
|
||||
assertSafetySourceDisabledDataSet(
|
||||
ResourcesUtils.getResourcesString(mApplicationContext, expectedTitleResName),
|
||||
mApplicationContext.getResources().getQuantityString(stringResId,
|
||||
expectedSummaryQuantity /* quantity */,
|
||||
@@ -422,13 +460,13 @@ public class BiometricsSafetySourceTest {
|
||||
);
|
||||
}
|
||||
|
||||
private void assertSafetySourceEnabledDataSentWithPluralSummary(String expectedTitleResName,
|
||||
private void assertSafetySourceEnabledDataSetWithPluralSummary(String expectedTitleResName,
|
||||
String expectedSummaryResName, int expectedSummaryQuantity,
|
||||
String expectedSettingsClassName) {
|
||||
final int stringResId = ResourcesUtils.getResourcesId(
|
||||
ApplicationProvider.getApplicationContext(), "plurals",
|
||||
expectedSummaryResName);
|
||||
assertSafetySourceEnabledDataSent(
|
||||
assertSafetySourceEnabledDataSet(
|
||||
ResourcesUtils.getResourcesString(mApplicationContext, expectedTitleResName),
|
||||
mApplicationContext.getResources().getQuantityString(stringResId,
|
||||
expectedSummaryQuantity /* quantity */,
|
||||
@@ -437,13 +475,13 @@ public class BiometricsSafetySourceTest {
|
||||
);
|
||||
}
|
||||
|
||||
private void assertSafetySourceDisabledDataSent(String expectedTitle, String expectedSummary) {
|
||||
private void assertSafetySourceDisabledDataSet(String expectedTitle, String expectedSummary) {
|
||||
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
|
||||
verify(mSafetyCenterManagerWrapper).sendSafetyCenterUpdate(any(), captor.capture());
|
||||
verify(mSafetyCenterManagerWrapper).setSafetySourceData(
|
||||
any(), any(), captor.capture(), any());
|
||||
SafetySourceData safetySourceData = captor.getValue();
|
||||
SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
|
||||
|
||||
assertThat(safetySourceData.getId()).isEqualTo(BiometricsSafetySource.SAFETY_SOURCE_ID);
|
||||
assertThat(safetySourceStatus.getTitle().toString()).isEqualTo(expectedTitle);
|
||||
assertThat(safetySourceStatus.getSummary().toString()).isEqualTo(expectedSummary);
|
||||
assertThat(safetySourceStatus.isEnabled()).isFalse();
|
||||
@@ -452,14 +490,14 @@ public class BiometricsSafetySourceTest {
|
||||
assertThat(clickIntent.getAction()).isEqualTo(ACTION_SHOW_ADMIN_SUPPORT_DETAILS);
|
||||
}
|
||||
|
||||
private void assertSafetySourceEnabledDataSent(String expectedTitle, String expectedSummary,
|
||||
private void assertSafetySourceEnabledDataSet(String expectedTitle, String expectedSummary,
|
||||
String expectedSettingsClassName) {
|
||||
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
|
||||
verify(mSafetyCenterManagerWrapper).sendSafetyCenterUpdate(any(), captor.capture());
|
||||
verify(mSafetyCenterManagerWrapper).setSafetySourceData(
|
||||
any(), any(), captor.capture(), any());
|
||||
SafetySourceData safetySourceData = captor.getValue();
|
||||
SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
|
||||
|
||||
assertThat(safetySourceData.getId()).isEqualTo(BiometricsSafetySource.SAFETY_SOURCE_ID);
|
||||
assertThat(safetySourceStatus.getTitle().toString()).isEqualTo(expectedTitle);
|
||||
assertThat(safetySourceStatus.getSummary().toString()).isEqualTo(expectedSummary);
|
||||
assertThat(safetySourceStatus.isEnabled()).isTrue();
|
||||
|
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.safetycenter;
|
||||
|
||||
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;
|
||||
@@ -26,6 +28,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.safetycenter.SafetyEvent;
|
||||
import android.safetycenter.SafetySourceData;
|
||||
import android.safetycenter.SafetySourceIssue;
|
||||
import android.safetycenter.SafetySourceStatus;
|
||||
@@ -53,6 +56,8 @@ public class LockScreenSafetySourceTest {
|
||||
private static final String SUMMARY = "summary";
|
||||
private static final String FAKE_ACTION_CHOOSE_LOCK_GENERIC_FRAGMENT = "choose_lock_generic";
|
||||
private static final String FAKE_ACTION_SCREEN_LOCK_SETTINGS = "screen_lock_settings";
|
||||
private static final SafetyEvent EVENT_SOURCE_STATE_CHANGED =
|
||||
new SafetyEvent.Builder(SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED).build();
|
||||
|
||||
private Context mApplicationContext;
|
||||
|
||||
@@ -81,42 +86,74 @@ public class LockScreenSafetySourceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_whenScreenLockIsEnabled_whenSafetyCenterIsDisabled_sendsNoData() {
|
||||
public void setSafetySourceData_whenScreenLockEnabled_safetyCenterDisabled_doesNotSetData() {
|
||||
whenScreenLockIsEnabled();
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(false);
|
||||
when(mScreenLockPreferenceDetailsUtils.isAvailable()).thenReturn(true);
|
||||
|
||||
LockScreenSafetySource.sendSafetyData(mApplicationContext,
|
||||
mScreenLockPreferenceDetailsUtils);
|
||||
LockScreenSafetySource.setSafetySourceData(mApplicationContext,
|
||||
mScreenLockPreferenceDetailsUtils, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
verify(mSafetyCenterManagerWrapper, never()).sendSafetyCenterUpdate(any(), any());
|
||||
verify(mSafetyCenterManagerWrapper, never()).setSafetySourceData(
|
||||
any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_whenScreenLockIsDisabled_sendsNoData() {
|
||||
public void setSafetySourceData_whenScreenLockIsDisabled_doesNotSetData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mScreenLockPreferenceDetailsUtils.isAvailable()).thenReturn(false);
|
||||
|
||||
LockScreenSafetySource.sendSafetyData(mApplicationContext,
|
||||
mScreenLockPreferenceDetailsUtils);
|
||||
LockScreenSafetySource.setSafetySourceData(mApplicationContext,
|
||||
mScreenLockPreferenceDetailsUtils, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
verify(mSafetyCenterManagerWrapper, never()).sendSafetyCenterUpdate(any(), any());
|
||||
verify(mSafetyCenterManagerWrapper, never()).setSafetySourceData(
|
||||
any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_whenScreenLockIsEnabled_sendsData() {
|
||||
public void setSafetySourceData_setsDataForLockscreenSafetySource() {
|
||||
whenScreenLockIsEnabled();
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
|
||||
LockScreenSafetySource.sendSafetyData(mApplicationContext,
|
||||
mScreenLockPreferenceDetailsUtils);
|
||||
LockScreenSafetySource.setSafetySourceData(mApplicationContext,
|
||||
mScreenLockPreferenceDetailsUtils, EVENT_SOURCE_STATE_CHANGED);
|
||||
ArgumentCaptor<String> idCaptor = ArgumentCaptor.forClass(String.class);
|
||||
verify(mSafetyCenterManagerWrapper).setSafetySourceData(
|
||||
any(), idCaptor.capture(), any(), any());
|
||||
String safetySourceId = idCaptor.getValue();
|
||||
|
||||
assertThat(safetySourceId).isEqualTo(LockScreenSafetySource.SAFETY_SOURCE_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSafetySourceData_setsDataWithCorrectSafetyEvent() {
|
||||
whenScreenLockIsEnabled();
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
|
||||
LockScreenSafetySource.setSafetySourceData(mApplicationContext,
|
||||
mScreenLockPreferenceDetailsUtils, EVENT_SOURCE_STATE_CHANGED);
|
||||
ArgumentCaptor<SafetyEvent> eventCaptor = ArgumentCaptor.forClass(SafetyEvent.class);
|
||||
verify(mSafetyCenterManagerWrapper).setSafetySourceData(
|
||||
any(), any(), any(), eventCaptor.capture());
|
||||
SafetyEvent safetyEvent = eventCaptor.getValue();
|
||||
|
||||
assertThat(safetyEvent).isEqualTo(EVENT_SOURCE_STATE_CHANGED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSafetySourceData_whenScreenLockIsEnabled_setData() {
|
||||
whenScreenLockIsEnabled();
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
|
||||
LockScreenSafetySource.setSafetySourceData(mApplicationContext,
|
||||
mScreenLockPreferenceDetailsUtils, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
|
||||
verify(mSafetyCenterManagerWrapper).sendSafetyCenterUpdate(any(), captor.capture());
|
||||
verify(mSafetyCenterManagerWrapper).setSafetySourceData(
|
||||
any(), any(), captor.capture(), any());
|
||||
SafetySourceData safetySourceData = captor.getValue();
|
||||
SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
|
||||
|
||||
assertThat(safetySourceData.getId()).isEqualTo(LockScreenSafetySource.SAFETY_SOURCE_ID);
|
||||
assertThat(safetySourceStatus.getTitle().toString())
|
||||
.isEqualTo(ResourcesUtils.getResourcesString(
|
||||
mApplicationContext,
|
||||
@@ -129,16 +166,17 @@ public class LockScreenSafetySourceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_whenLockPatternIsSecure_sendsStatusLevelOk() {
|
||||
public void setSafetySourceData_whenLockPatternIsSecure_setStatusLevelOk() {
|
||||
whenScreenLockIsEnabled();
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mScreenLockPreferenceDetailsUtils.isLockPatternSecure()).thenReturn(true);
|
||||
|
||||
LockScreenSafetySource.sendSafetyData(mApplicationContext,
|
||||
mScreenLockPreferenceDetailsUtils);
|
||||
LockScreenSafetySource.setSafetySourceData(mApplicationContext,
|
||||
mScreenLockPreferenceDetailsUtils, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
|
||||
verify(mSafetyCenterManagerWrapper).sendSafetyCenterUpdate(any(), captor.capture());
|
||||
verify(mSafetyCenterManagerWrapper).setSafetySourceData(
|
||||
any(), any(), captor.capture(), any());
|
||||
SafetySourceData safetySourceData = captor.getValue();
|
||||
SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
|
||||
|
||||
@@ -147,16 +185,17 @@ public class LockScreenSafetySourceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_whenLockPatternIsNotSecure_sendsStatusLevelRecommendation() {
|
||||
public void setSafetySourceData_whenLockPatternIsNotSecure_setStatusLevelRecommendation() {
|
||||
whenScreenLockIsEnabled();
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mScreenLockPreferenceDetailsUtils.isLockPatternSecure()).thenReturn(false);
|
||||
|
||||
LockScreenSafetySource.sendSafetyData(mApplicationContext,
|
||||
mScreenLockPreferenceDetailsUtils);
|
||||
LockScreenSafetySource.setSafetySourceData(mApplicationContext,
|
||||
mScreenLockPreferenceDetailsUtils, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
|
||||
verify(mSafetyCenterManagerWrapper).sendSafetyCenterUpdate(any(), captor.capture());
|
||||
verify(mSafetyCenterManagerWrapper).setSafetySourceData(
|
||||
any(), any(), captor.capture(), any());
|
||||
SafetySourceData safetySourceData = captor.getValue();
|
||||
SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
|
||||
|
||||
@@ -165,32 +204,34 @@ public class LockScreenSafetySourceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_whenLockPatternIsSecure_sendsNoIssues() {
|
||||
public void setSafetySourceData_whenLockPatternIsSecure_doesNotSetIssues() {
|
||||
whenScreenLockIsEnabled();
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mScreenLockPreferenceDetailsUtils.isLockPatternSecure()).thenReturn(true);
|
||||
|
||||
LockScreenSafetySource.sendSafetyData(mApplicationContext,
|
||||
mScreenLockPreferenceDetailsUtils);
|
||||
LockScreenSafetySource.setSafetySourceData(mApplicationContext,
|
||||
mScreenLockPreferenceDetailsUtils, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
|
||||
verify(mSafetyCenterManagerWrapper).sendSafetyCenterUpdate(any(), captor.capture());
|
||||
verify(mSafetyCenterManagerWrapper).setSafetySourceData(
|
||||
any(), any(), captor.capture(), any());
|
||||
SafetySourceData safetySourceData = captor.getValue();
|
||||
|
||||
assertThat(safetySourceData.getIssues()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_whenLockPatternIsNotSecure_sendsIssue() {
|
||||
public void setSafetySourceData_whenLockPatternIsNotSecure_setIssue() {
|
||||
whenScreenLockIsEnabled();
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mScreenLockPreferenceDetailsUtils.isLockPatternSecure()).thenReturn(false);
|
||||
|
||||
LockScreenSafetySource.sendSafetyData(mApplicationContext,
|
||||
mScreenLockPreferenceDetailsUtils);
|
||||
LockScreenSafetySource.setSafetySourceData(mApplicationContext,
|
||||
mScreenLockPreferenceDetailsUtils, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
|
||||
verify(mSafetyCenterManagerWrapper).sendSafetyCenterUpdate(any(), captor.capture());
|
||||
verify(mSafetyCenterManagerWrapper).setSafetySourceData(
|
||||
any(), any(), captor.capture(), any());
|
||||
SafetySourceData safetySourceData = captor.getValue();
|
||||
|
||||
assertThat(safetySourceData.getIssues()).hasSize(1);
|
||||
@@ -218,17 +259,18 @@ public class LockScreenSafetySourceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_whenPasswordQualityIsManaged_sendsDisabled() {
|
||||
public void setSafetySourceData_whenPasswordQualityIsManaged_setDisabled() {
|
||||
whenScreenLockIsEnabled();
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mScreenLockPreferenceDetailsUtils.isPasswordQualityManaged(anyInt(), any()))
|
||||
.thenReturn(true);
|
||||
|
||||
LockScreenSafetySource.sendSafetyData(mApplicationContext,
|
||||
mScreenLockPreferenceDetailsUtils);
|
||||
LockScreenSafetySource.setSafetySourceData(mApplicationContext,
|
||||
mScreenLockPreferenceDetailsUtils, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
|
||||
verify(mSafetyCenterManagerWrapper).sendSafetyCenterUpdate(any(), captor.capture());
|
||||
verify(mSafetyCenterManagerWrapper).setSafetySourceData(
|
||||
any(), any(), captor.capture(), any());
|
||||
SafetySourceData safetySourceData = captor.getValue();
|
||||
SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
|
||||
|
||||
@@ -236,17 +278,18 @@ public class LockScreenSafetySourceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_whenPasswordQualityIsNotManaged_sendsEnabled() {
|
||||
public void setSafetySourceData_whenPasswordQualityIsNotManaged_setEnabled() {
|
||||
whenScreenLockIsEnabled();
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mScreenLockPreferenceDetailsUtils.isPasswordQualityManaged(anyInt(), any()))
|
||||
.thenReturn(false);
|
||||
|
||||
LockScreenSafetySource.sendSafetyData(mApplicationContext,
|
||||
mScreenLockPreferenceDetailsUtils);
|
||||
LockScreenSafetySource.setSafetySourceData(mApplicationContext,
|
||||
mScreenLockPreferenceDetailsUtils, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
|
||||
verify(mSafetyCenterManagerWrapper).sendSafetyCenterUpdate(any(), captor.capture());
|
||||
verify(mSafetyCenterManagerWrapper).setSafetySourceData(
|
||||
any(), any(), captor.capture(), any());
|
||||
SafetySourceData safetySourceData = captor.getValue();
|
||||
SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
|
||||
|
||||
@@ -254,7 +297,7 @@ public class LockScreenSafetySourceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_whenShouldShowGearMenu_sendsGearMenuActionIcon() {
|
||||
public void setSafetySourceData_whenShouldShowGearMenu_setGearMenuActionIcon() {
|
||||
whenScreenLockIsEnabled();
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
final Intent launchScreenLockSettings = new Intent(FAKE_ACTION_SCREEN_LOCK_SETTINGS);
|
||||
@@ -262,12 +305,13 @@ public class LockScreenSafetySourceTest {
|
||||
.thenReturn(launchScreenLockSettings);
|
||||
when(mScreenLockPreferenceDetailsUtils.shouldShowGearMenu()).thenReturn(true);
|
||||
|
||||
LockScreenSafetySource.sendSafetyData(mApplicationContext,
|
||||
mScreenLockPreferenceDetailsUtils);
|
||||
LockScreenSafetySource.setSafetySourceData(mApplicationContext,
|
||||
mScreenLockPreferenceDetailsUtils, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
final ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(
|
||||
SafetySourceData.class);
|
||||
verify(mSafetyCenterManagerWrapper).sendSafetyCenterUpdate(any(), captor.capture());
|
||||
verify(mSafetyCenterManagerWrapper).setSafetySourceData(
|
||||
any(), any(), captor.capture(), any());
|
||||
final IconAction iconAction = captor.getValue().getStatus().getIconAction();
|
||||
|
||||
assertThat(iconAction.getIconType()).isEqualTo(IconAction.ICON_TYPE_GEAR);
|
||||
@@ -276,16 +320,17 @@ public class LockScreenSafetySourceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_whenShouldNotShowGearMenu_sendsNoGearMenuActionIcon() {
|
||||
public void setSafetySourceData_whenShouldNotShowGearMenu_doesNotSetGearMenuActionIcon() {
|
||||
whenScreenLockIsEnabled();
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mScreenLockPreferenceDetailsUtils.shouldShowGearMenu()).thenReturn(false);
|
||||
|
||||
LockScreenSafetySource.sendSafetyData(mApplicationContext,
|
||||
mScreenLockPreferenceDetailsUtils);
|
||||
LockScreenSafetySource.setSafetySourceData(mApplicationContext,
|
||||
mScreenLockPreferenceDetailsUtils, EVENT_SOURCE_STATE_CHANGED);
|
||||
|
||||
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
|
||||
verify(mSafetyCenterManagerWrapper).sendSafetyCenterUpdate(any(), captor.capture());
|
||||
verify(mSafetyCenterManagerWrapper).setSafetySourceData(
|
||||
any(), any(), captor.capture(), any());
|
||||
SafetySourceData safetySourceData = captor.getValue();
|
||||
SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
|
||||
|
||||
@@ -293,23 +338,24 @@ public class LockScreenSafetySourceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onLockScreenChange_whenSafetyCenterEnabled_sendsData() {
|
||||
public void onLockScreenChange_whenSafetyCenterEnabled_setData() {
|
||||
whenScreenLockIsEnabled();
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
|
||||
LockScreenSafetySource.onLockScreenChange(mApplicationContext);
|
||||
|
||||
verify(mSafetyCenterManagerWrapper).sendSafetyCenterUpdate(any(), any());
|
||||
verify(mSafetyCenterManagerWrapper).setSafetySourceData(any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onLockScreenChange_whenSafetyCenterDisabled_sendsNoData() {
|
||||
public void onLockScreenChange_whenSafetyCenterDisabled_doesNotSetData() {
|
||||
whenScreenLockIsEnabled();
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(false);
|
||||
|
||||
LockScreenSafetySource.onLockScreenChange(mApplicationContext);
|
||||
|
||||
verify(mSafetyCenterManagerWrapper, never()).sendSafetyCenterUpdate(any(), any());
|
||||
verify(mSafetyCenterManagerWrapper, never()).setSafetySourceData(
|
||||
any(), any(), any(), any());
|
||||
}
|
||||
|
||||
private void whenScreenLockIsEnabled() {
|
||||
|
@@ -18,6 +18,8 @@ package com.android.settings.safetycenter;
|
||||
|
||||
import static android.safetycenter.SafetyCenterManager.ACTION_REFRESH_SAFETY_SOURCES;
|
||||
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;
|
||||
|
||||
@@ -29,7 +31,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.safetycenter.SafetySourceData;
|
||||
import android.safetycenter.SafetyEvent;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
@@ -45,6 +47,7 @@ import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@@ -74,17 +77,18 @@ public class SafetySourceBroadcastReceiverTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_whenSafetyCenterIsEnabled_withNoIntentAction_sendsNoData() {
|
||||
public void onReceive_onRefresh_whenSafetyCenterIsEnabled_withNoIntentAction_doesNotSetData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
Intent intent = new Intent().putExtra(EXTRA_REFRESH_SAFETY_SOURCE_IDS, new String[]{});
|
||||
|
||||
new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent);
|
||||
|
||||
verify(mSafetyCenterManagerWrapper, never()).sendSafetyCenterUpdate(any(), any());
|
||||
verify(mSafetyCenterManagerWrapper, never()).setSafetySourceData(
|
||||
any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_whenSafetyCenterIsDisabled_sendsNoData() {
|
||||
public void onReceive_onRefresh_whenSafetyCenterIsDisabled_doesNotSetData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(false);
|
||||
Intent intent =
|
||||
new Intent()
|
||||
@@ -95,21 +99,23 @@ public class SafetySourceBroadcastReceiverTest {
|
||||
|
||||
new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent);
|
||||
|
||||
verify(mSafetyCenterManagerWrapper, never()).sendSafetyCenterUpdate(any(), any());
|
||||
verify(mSafetyCenterManagerWrapper, never()).setSafetySourceData(
|
||||
any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_whenSafetyCenterIsEnabled_withNullSourceIds_sendsNoData() {
|
||||
public void onReceive_onRefresh_whenSafetyCenterIsEnabled_withNullSourceIds_doesNotSetData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
Intent intent = new Intent().setAction(ACTION_REFRESH_SAFETY_SOURCES);
|
||||
|
||||
new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent);
|
||||
|
||||
verify(mSafetyCenterManagerWrapper, never()).sendSafetyCenterUpdate(any(), any());
|
||||
verify(mSafetyCenterManagerWrapper, never()).setSafetySourceData(
|
||||
any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_whenSafetyCenterIsEnabled_withNoSourceIds_sendsNoData() {
|
||||
public void onReceive_onRefresh_whenSafetyCenterIsEnabled_withNoSourceIds_doesNotSetData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
Intent intent =
|
||||
new Intent()
|
||||
@@ -118,11 +124,12 @@ public class SafetySourceBroadcastReceiverTest {
|
||||
|
||||
new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent);
|
||||
|
||||
verify(mSafetyCenterManagerWrapper, never()).sendSafetyCenterUpdate(any(), any());
|
||||
verify(mSafetyCenterManagerWrapper, never()).setSafetySourceData(
|
||||
any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_withLockscreenSourceId_sendsLockscreenData() {
|
||||
public void onReceive_onRefresh_setsRefreshEvent() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
Intent intent =
|
||||
new Intent()
|
||||
@@ -132,16 +139,34 @@ public class SafetySourceBroadcastReceiverTest {
|
||||
new String[]{ LockScreenSafetySource.SAFETY_SOURCE_ID });
|
||||
|
||||
new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent);
|
||||
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
|
||||
ArgumentCaptor<SafetyEvent> captor = ArgumentCaptor.forClass(SafetyEvent.class);
|
||||
verify(mSafetyCenterManagerWrapper, times(1))
|
||||
.sendSafetyCenterUpdate(any(), captor.capture());
|
||||
SafetySourceData safetySourceData = captor.getValue();
|
||||
.setSafetySourceData(any(), any(), any(), captor.capture());
|
||||
|
||||
assertThat(safetySourceData.getId()).isEqualTo(LockScreenSafetySource.SAFETY_SOURCE_ID);
|
||||
assertThat(captor.getValue()).isEqualTo(
|
||||
new SafetyEvent.Builder(SAFETY_EVENT_TYPE_REFRESH_REQUESTED).build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_withBiometricsSourceId_sendsBiometricData() {
|
||||
public void onReceive_onRefresh_withLockscreenSourceId_setsLockscreenData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
Intent intent =
|
||||
new Intent()
|
||||
.setAction(ACTION_REFRESH_SAFETY_SOURCES)
|
||||
.putExtra(
|
||||
EXTRA_REFRESH_SAFETY_SOURCE_IDS,
|
||||
new String[]{ LockScreenSafetySource.SAFETY_SOURCE_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(LockScreenSafetySource.SAFETY_SOURCE_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onReceive_onRefresh_withBiometricsSourceId_setsBiometricData() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
Intent intent =
|
||||
new Intent()
|
||||
@@ -151,28 +176,42 @@ public class SafetySourceBroadcastReceiverTest {
|
||||
new String[]{ BiometricsSafetySource.SAFETY_SOURCE_ID });
|
||||
|
||||
new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent);
|
||||
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
|
||||
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
||||
verify(mSafetyCenterManagerWrapper, times(1))
|
||||
.sendSafetyCenterUpdate(any(), captor.capture());
|
||||
SafetySourceData safetySourceData = captor.getValue();
|
||||
.setSafetySourceData(any(), captor.capture(), any(), any());
|
||||
|
||||
assertThat(safetySourceData.getId()).isEqualTo(BiometricsSafetySource.SAFETY_SOURCE_ID);
|
||||
assertThat(captor.getValue()).isEqualTo(BiometricsSafetySource.SAFETY_SOURCE_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_onBootCompleted_sendsBiometricAndLockscreenData() {
|
||||
public void onReceive_onBootCompleted_setsBootCompleteEvent() {
|
||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
Intent intent = new Intent().setAction(Intent.ACTION_BOOT_COMPLETED);
|
||||
|
||||
new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent);
|
||||
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
|
||||
ArgumentCaptor<SafetyEvent> captor = ArgumentCaptor.forClass(SafetyEvent.class);
|
||||
verify(mSafetyCenterManagerWrapper, times(2))
|
||||
.sendSafetyCenterUpdate(any(), captor.capture());
|
||||
List<SafetySourceData> safetySourceDataList = captor.getAllValues();
|
||||
.setSafetySourceData(any(), any(), any(), captor.capture());
|
||||
|
||||
assertThat(safetySourceDataList.stream().anyMatch(
|
||||
data -> data.getId().equals(LockScreenSafetySource.SAFETY_SOURCE_ID))).isTrue();
|
||||
assertThat(safetySourceDataList.stream().anyMatch(
|
||||
data -> data.getId().equals(BiometricsSafetySource.SAFETY_SOURCE_ID))).isTrue();
|
||||
SafetyEvent bootEvent = new SafetyEvent.Builder(SAFETY_EVENT_TYPE_DEVICE_REBOOTED).build();
|
||||
assertThat(captor.getAllValues())
|
||||
.containsExactlyElementsIn(Arrays.asList(bootEvent, bootEvent));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onReceive_onBootCompleted_sendsBiometricAndLockscreenData() {
|
||||
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(2))
|
||||
.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();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user