• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settings.safetycenter;
18 
19 import static android.provider.Settings.ACTION_SHOW_ADMIN_SUPPORT_DETAILS;
20 import static android.safetycenter.SafetyEvent.SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED;
21 
22 import static com.google.common.truth.Truth.assertThat;
23 
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.ArgumentMatchers.anyInt;
26 import static org.mockito.ArgumentMatchers.eq;
27 import static org.mockito.Mockito.doReturn;
28 import static org.mockito.Mockito.never;
29 import static org.mockito.Mockito.spy;
30 import static org.mockito.Mockito.verify;
31 import static org.mockito.Mockito.when;
32 
33 import android.app.admin.DevicePolicyManager;
34 import android.app.supervision.SupervisionManager;
35 import android.content.ComponentName;
36 import android.content.Context;
37 import android.content.Intent;
38 import android.content.pm.PackageManager;
39 import android.hardware.face.FaceManager;
40 import android.hardware.fingerprint.Fingerprint;
41 import android.hardware.fingerprint.FingerprintManager;
42 import android.os.UserHandle;
43 import android.platform.test.annotations.DisableFlags;
44 import android.platform.test.annotations.EnableFlags;
45 import android.platform.test.annotations.RequiresFlagsDisabled;
46 import android.platform.test.annotations.RequiresFlagsEnabled;
47 import android.platform.test.flag.junit.SetFlagsRule;
48 import android.safetycenter.SafetyEvent;
49 import android.safetycenter.SafetySourceData;
50 import android.safetycenter.SafetySourceStatus;
51 
52 import androidx.test.core.app.ApplicationProvider;
53 import androidx.test.ext.junit.runners.AndroidJUnit4;
54 
55 import com.android.internal.widget.LockPatternUtils;
56 import com.android.settings.biometrics.BiometricEnrollActivity;
57 import com.android.settings.biometrics.fingerprint.FingerprintSettings;
58 import com.android.settings.flags.Flags;
59 import com.android.settings.testutils.FakeFeatureFactory;
60 import com.android.settings.testutils.ResourcesUtils;
61 import com.android.settingslib.utils.StringUtil;
62 
63 import org.junit.After;
64 import org.junit.Before;
65 import org.junit.Rule;
66 import org.junit.Test;
67 import org.junit.runner.RunWith;
68 import org.mockito.ArgumentCaptor;
69 import org.mockito.Mock;
70 import org.mockito.MockitoAnnotations;
71 
72 import java.util.ArrayList;
73 import java.util.List;
74 
75 @RunWith(AndroidJUnit4.class)
76 public class FingerprintSafetySourceTest {
77 
78     private static final ComponentName COMPONENT_NAME = new ComponentName("package", "class");
79     private static final int USER_ID = UserHandle.myUserId();
80     private static final UserHandle USER_HANDLE = new UserHandle(USER_ID);
81     private static final SafetyEvent EVENT_SOURCE_STATE_CHANGED =
82             new SafetyEvent.Builder(SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED).build();
83 
84     @Rule
85     public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
86 
87     private Context mApplicationContext;
88 
89     @Mock private PackageManager mPackageManager;
90     @Mock private DevicePolicyManager mDevicePolicyManager;
91     @Mock private FingerprintManager mFingerprintManager;
92     @Mock private FaceManager mFaceManager;
93     @Mock private LockPatternUtils mLockPatternUtils;
94     @Mock private SafetyCenterManagerWrapper mSafetyCenterManagerWrapper;
95     @Mock private SupervisionManager mSupervisionManager;
96 
97     @Before
setUp()98     public void setUp() {
99         MockitoAnnotations.initMocks(this);
100         mApplicationContext = spy(ApplicationProvider.getApplicationContext());
101         when(mApplicationContext.getPackageManager()).thenReturn(mPackageManager);
102         when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)).thenReturn(true);
103         when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE)).thenReturn(true);
104         when(mApplicationContext.getSystemService(Context.FINGERPRINT_SERVICE))
105                 .thenReturn(mFingerprintManager);
106         when(mApplicationContext.getSystemService(Context.FACE_SERVICE)).thenReturn(mFaceManager);
107         when(mApplicationContext.getSystemService(Context.DEVICE_POLICY_SERVICE))
108                 .thenReturn(mDevicePolicyManager);
109         when(mApplicationContext.getSystemService(Context.SUPERVISION_SERVICE))
110                 .thenReturn(mSupervisionManager);
111         FakeFeatureFactory featureFactory = FakeFeatureFactory.setupForTest();
112         when(featureFactory.securityFeatureProvider.getLockPatternUtils(mApplicationContext))
113                 .thenReturn(mLockPatternUtils);
114         doReturn(true).when(mLockPatternUtils).isSecure(anyInt());
115         SafetyCenterManagerWrapper.sInstance = mSafetyCenterManagerWrapper;
116     }
117 
118     @After
tearDown()119     public void tearDown() {
120         SafetyCenterManagerWrapper.sInstance = null;
121     }
122 
123     @Test
124     @RequiresFlagsEnabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
setSafetyData_whenSafetyCenterIsDisabled_doesNotSetData()125     public void setSafetyData_whenSafetyCenterIsDisabled_doesNotSetData() {
126         when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(false);
127 
128         FingerprintSafetySource.setSafetySourceData(
129                 mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
130 
131         verify(mSafetyCenterManagerWrapper, never())
132                 .setSafetySourceData(any(), any(), any(), any());
133     }
134 
135     @Test
136     @RequiresFlagsDisabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
setSafetySourceData_whenSeparateBiometricsFlagOff_setsNullData()137     public void setSafetySourceData_whenSeparateBiometricsFlagOff_setsNullData() {
138         when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
139 
140         FingerprintSafetySource.setSafetySourceData(
141                 mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
142 
143         verify(mSafetyCenterManagerWrapper)
144                 .setSafetySourceData(
145                         any(), eq(FingerprintSafetySource.SAFETY_SOURCE_ID), eq(null), any());
146     }
147 
148     @Test
149     @RequiresFlagsEnabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
setSafetySourceData_whenSafetyCenterIsEnabled_withoutFingerprint_setsNullData()150     public void setSafetySourceData_whenSafetyCenterIsEnabled_withoutFingerprint_setsNullData() {
151         when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
152         when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
153 
154         FingerprintSafetySource.setSafetySourceData(
155                 mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
156 
157         verify(mSafetyCenterManagerWrapper)
158                 .setSafetySourceData(
159                         any(), eq(FingerprintSafetySource.SAFETY_SOURCE_ID), eq(null), any());
160     }
161 
162     @Test
163     @RequiresFlagsEnabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
setSafetySourceData_setsDataForFingerprintSource()164     public void setSafetySourceData_setsDataForFingerprintSource() {
165         when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
166         when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
167         when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(false);
168         when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
169 
170         FingerprintSafetySource.setSafetySourceData(
171                 mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
172 
173         verify(mSafetyCenterManagerWrapper)
174                 .setSafetySourceData(
175                         any(), eq(FingerprintSafetySource.SAFETY_SOURCE_ID), any(), any());
176     }
177 
178     @Test
179     @RequiresFlagsEnabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
setSafetySourceData_setsDataWithCorrectSafetyEvent()180     public void setSafetySourceData_setsDataWithCorrectSafetyEvent() {
181         when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
182         when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
183         when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(false);
184         when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
185 
186         FingerprintSafetySource.setSafetySourceData(
187                 mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
188 
189         verify(mSafetyCenterManagerWrapper)
190                 .setSafetySourceData(any(), any(), any(), eq(EVENT_SOURCE_STATE_CHANGED));
191     }
192 
193     @Test
194     @RequiresFlagsEnabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
195     @DisableFlags(android.app.supervision.flags.Flags.FLAG_DEPRECATE_DPM_SUPERVISION_APIS)
setSafetySourceData_withFingerprintNotEnrolled_whenDisabledByAdmin_setsData()196     public void setSafetySourceData_withFingerprintNotEnrolled_whenDisabledByAdmin_setsData() {
197         when(mDevicePolicyManager.getProfileOwnerOrDeviceOwnerSupervisionComponent(USER_HANDLE))
198                 .thenReturn(COMPONENT_NAME);
199         when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
200         when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
201         when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(false);
202         when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME))
203                 .thenReturn(DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT);
204 
205         FingerprintSafetySource.setSafetySourceData(
206                 mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
207 
208         assertSafetySourceDisabledDataSetWithSingularSummary(
209                 "security_settings_fingerprint",
210                 "security_settings_fingerprint_preference_summary_none_new");
211     }
212 
213     @Test
214     @RequiresFlagsEnabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
215     @EnableFlags(android.app.supervision.flags.Flags.FLAG_DEPRECATE_DPM_SUPERVISION_APIS)
setSafetySourceData_withFingerprintNotEnrolled_whenSupervisionIsOn_setsData()216     public void setSafetySourceData_withFingerprintNotEnrolled_whenSupervisionIsOn_setsData() {
217         when(mSupervisionManager.isSupervisionEnabledForUser(USER_ID)).thenReturn(true);
218         when(mSupervisionManager.getActiveSupervisionAppPackage()).thenReturn("supervision.pkg");
219         when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
220         when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
221         when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(false);
222         when(mDevicePolicyManager.getKeyguardDisabledFeatures(null))
223                 .thenReturn(DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT);
224 
225         FingerprintSafetySource.setSafetySourceData(
226                 mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
227 
228         assertSafetySourceDisabledDataSetWithSingularSummary(
229                 "security_settings_fingerprint",
230                 "security_settings_fingerprint_preference_summary_none_new");
231     }
232 
233     @Test
234     @RequiresFlagsEnabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
setSafetySourceData_onlyFingerprintNotEnrolled_whenNotDisabledByAdmin_setsData()235     public void setSafetySourceData_onlyFingerprintNotEnrolled_whenNotDisabledByAdmin_setsData() {
236         when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
237         when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
238         when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(false);
239         when(mFaceManager.isHardwareDetected()).thenReturn(true);
240         when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(true);
241         when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
242 
243         FingerprintSafetySource.setSafetySourceData(
244                 mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
245 
246         assertSafetySourceEnabledDataSetWithSingularSummary(
247                 "security_settings_fingerprint",
248                 "security_settings_fingerprint_preference_summary_none_new",
249                 FingerprintSettings.class.getName());
250     }
251 
252     @Test
253     @RequiresFlagsEnabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
setSafetySourceData_noBiometricEnrolled_whenNotDisabledByAdmin_setsData()254     public void setSafetySourceData_noBiometricEnrolled_whenNotDisabledByAdmin_setsData() {
255         when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
256         when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
257         when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(false);
258         when(mFaceManager.isHardwareDetected()).thenReturn(true);
259         when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(false);
260         when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
261 
262         FingerprintSafetySource.setSafetySourceData(
263                 mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
264 
265         assertSafetySourceEnabledDataSetWithSingularSummary(
266                 "security_settings_fingerprint",
267                 "security_settings_fingerprint_preference_summary_none_new",
268                 BiometricEnrollActivity.InternalActivity.class.getName());
269     }
270 
271     @Test
272     @RequiresFlagsEnabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
273     @DisableFlags(android.app.supervision.flags.Flags.FLAG_DEPRECATE_DPM_SUPERVISION_APIS)
setSafetySourceData_withFingerprintsEnrolled_whenDisabledByAdmin_setsData()274     public void setSafetySourceData_withFingerprintsEnrolled_whenDisabledByAdmin_setsData() {
275         int enrolledFingerprintsCount = 2;
276         when(mDevicePolicyManager.getProfileOwnerOrDeviceOwnerSupervisionComponent(USER_HANDLE))
277                 .thenReturn(COMPONENT_NAME);
278         when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
279         when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
280         when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(true);
281         when(mFingerprintManager.getEnrolledFingerprints(anyInt()))
282                 .thenReturn(createFingerprintList(enrolledFingerprintsCount));
283         when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME))
284                 .thenReturn(DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT);
285 
286         FingerprintSafetySource.setSafetySourceData(
287                 mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
288 
289         assertSafetySourceDisabledDataSetWithPluralSummary(
290                 "security_settings_fingerprint",
291                 "security_settings_fingerprint_preference_summary",
292                 enrolledFingerprintsCount);
293     }
294 
295     @Test
296     @RequiresFlagsEnabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
297     @EnableFlags(android.app.supervision.flags.Flags.FLAG_DEPRECATE_DPM_SUPERVISION_APIS)
setSafetySourceData_withFingerprintsEnrolled_whenSupervisionIsOn_setsData()298     public void setSafetySourceData_withFingerprintsEnrolled_whenSupervisionIsOn_setsData() {
299         int enrolledFingerprintsCount = 2;
300         when(mSupervisionManager.isSupervisionEnabledForUser(USER_ID)).thenReturn(true);
301         when(mSupervisionManager.getActiveSupervisionAppPackage()).thenReturn("supervision.pkg");
302         when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
303         when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
304         when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(true);
305         when(mFingerprintManager.getEnrolledFingerprints(anyInt()))
306                 .thenReturn(createFingerprintList(enrolledFingerprintsCount));
307         when(mDevicePolicyManager.getKeyguardDisabledFeatures(null))
308                 .thenReturn(DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT);
309 
310         FingerprintSafetySource.setSafetySourceData(
311                 mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
312 
313         assertSafetySourceDisabledDataSetWithPluralSummary(
314                 "security_settings_fingerprint",
315                 "security_settings_fingerprint_preference_summary",
316                 enrolledFingerprintsCount);
317     }
318 
319     @Test
320     @RequiresFlagsEnabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
setSafetySourceData_withFingerprintsEnrolled_whenNotDisabledByAdmin_setsData()321     public void setSafetySourceData_withFingerprintsEnrolled_whenNotDisabledByAdmin_setsData() {
322         int enrolledFingerprintsCount = 2;
323         when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
324         when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
325         when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(true);
326         when(mFingerprintManager.getEnrolledFingerprints(anyInt()))
327                 .thenReturn(createFingerprintList(enrolledFingerprintsCount));
328         when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
329 
330         FingerprintSafetySource.setSafetySourceData(
331                 mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
332 
333         assertSafetySourceEnabledDataSetWithPluralSummary(
334                 "security_settings_fingerprint",
335                 "security_settings_fingerprint_preference_summary",
336                 enrolledFingerprintsCount,
337                 FingerprintSettings.class.getName());
338     }
339 
340     @Test
341     @RequiresFlagsEnabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
setSafetySourceData_fingerprint_whenEnrolled_setsInfoSeverity()342     public void setSafetySourceData_fingerprint_whenEnrolled_setsInfoSeverity() {
343         when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
344         when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
345         when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(true);
346 
347         FingerprintSafetySource.setSafetySourceData(
348                 mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
349 
350         ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
351         verify(mSafetyCenterManagerWrapper)
352                 .setSafetySourceData(
353                         any(),
354                         eq(FingerprintSafetySource.SAFETY_SOURCE_ID),
355                         captor.capture(),
356                         any());
357         SafetySourceStatus safetySourceStatus = captor.getValue().getStatus();
358         assertThat(safetySourceStatus.getSeverityLevel())
359                 .isEqualTo(SafetySourceData.SEVERITY_LEVEL_INFORMATION);
360     }
361 
362     @Test
363     @RequiresFlagsEnabled(Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
setSafetySourceData_fingerprint_whenNotEnrolled_setsUnspSeverity()364     public void setSafetySourceData_fingerprint_whenNotEnrolled_setsUnspSeverity() {
365         when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
366         when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
367         when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(false);
368 
369         FingerprintSafetySource.setSafetySourceData(
370                 mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
371 
372         ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
373         verify(mSafetyCenterManagerWrapper)
374                 .setSafetySourceData(
375                         any(),
376                         eq(FingerprintSafetySource.SAFETY_SOURCE_ID),
377                         captor.capture(),
378                         any());
379         SafetySourceStatus safetySourceStatus = captor.getValue().getStatus();
380         assertThat(safetySourceStatus.getSeverityLevel())
381                 .isEqualTo(SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED);
382     }
383 
assertSafetySourceDisabledDataSetWithSingularSummary( String expectedTitleResName, String expectedSummaryResName)384     private void assertSafetySourceDisabledDataSetWithSingularSummary(
385             String expectedTitleResName, String expectedSummaryResName) {
386         assertSafetySourceDisabledDataSet(
387                 ResourcesUtils.getResourcesString(mApplicationContext, expectedTitleResName),
388                 ResourcesUtils.getResourcesString(mApplicationContext, expectedSummaryResName));
389     }
390 
assertSafetySourceEnabledDataSetWithSingularSummary( String expectedTitleResName, String expectedSummaryResName, String expectedSettingsClassName)391     private void assertSafetySourceEnabledDataSetWithSingularSummary(
392             String expectedTitleResName,
393             String expectedSummaryResName,
394             String expectedSettingsClassName) {
395         assertSafetySourceEnabledDataSet(
396                 ResourcesUtils.getResourcesString(mApplicationContext, expectedTitleResName),
397                 ResourcesUtils.getResourcesString(mApplicationContext, expectedSummaryResName),
398                 expectedSettingsClassName);
399     }
400 
assertSafetySourceDisabledDataSetWithPluralSummary( String expectedTitleResName, String expectedSummaryResName, int expectedSummaryQuantity)401     private void assertSafetySourceDisabledDataSetWithPluralSummary(
402             String expectedTitleResName,
403             String expectedSummaryResName,
404             int expectedSummaryQuantity) {
405         int stringResId =
406                 ResourcesUtils.getResourcesId(
407                         ApplicationProvider.getApplicationContext(),
408                         "string",
409                         expectedSummaryResName);
410         assertSafetySourceDisabledDataSet(
411                 ResourcesUtils.getResourcesString(mApplicationContext, expectedTitleResName),
412                 StringUtil.getIcuPluralsString(
413                         mApplicationContext, expectedSummaryQuantity, stringResId));
414     }
415 
assertSafetySourceEnabledDataSetWithPluralSummary( String expectedTitleResName, String expectedSummaryResName, int expectedSummaryQuantity, String expectedSettingsClassName)416     private void assertSafetySourceEnabledDataSetWithPluralSummary(
417             String expectedTitleResName,
418             String expectedSummaryResName,
419             int expectedSummaryQuantity,
420             String expectedSettingsClassName) {
421         int stringResId =
422                 ResourcesUtils.getResourcesId(
423                         ApplicationProvider.getApplicationContext(),
424                         "string",
425                         expectedSummaryResName);
426         assertSafetySourceEnabledDataSet(
427                 ResourcesUtils.getResourcesString(mApplicationContext, expectedTitleResName),
428                 StringUtil.getIcuPluralsString(
429                         mApplicationContext, expectedSummaryQuantity, stringResId),
430                 expectedSettingsClassName);
431     }
432 
assertSafetySourceDisabledDataSet(String expectedTitle, String expectedSummary)433     private void assertSafetySourceDisabledDataSet(String expectedTitle, String expectedSummary) {
434         ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
435         verify(mSafetyCenterManagerWrapper)
436                 .setSafetySourceData(
437                         any(),
438                         eq(FingerprintSafetySource.SAFETY_SOURCE_ID),
439                         captor.capture(),
440                         any());
441         SafetySourceData safetySourceData = captor.getValue();
442         SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
443 
444         assertThat(safetySourceStatus.getTitle().toString()).isEqualTo(expectedTitle);
445         assertThat(safetySourceStatus.getSummary().toString()).isEqualTo(expectedSummary);
446         assertThat(safetySourceStatus.isEnabled()).isFalse();
447         assertThat(safetySourceStatus.getSeverityLevel())
448                 .isEqualTo(SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED);
449 
450         Intent clickIntent = safetySourceStatus.getPendingIntent().getIntent();
451         assertThat(clickIntent).isNotNull();
452         assertThat(clickIntent.getAction()).isEqualTo(ACTION_SHOW_ADMIN_SUPPORT_DETAILS);
453     }
454 
assertSafetySourceEnabledDataSet( String expectedTitle, String expectedSummary, String expectedSettingsClassName)455     private void assertSafetySourceEnabledDataSet(
456             String expectedTitle, String expectedSummary, String expectedSettingsClassName) {
457         ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
458         verify(mSafetyCenterManagerWrapper)
459                 .setSafetySourceData(
460                         any(),
461                         eq(FingerprintSafetySource.SAFETY_SOURCE_ID),
462                         captor.capture(),
463                         any());
464         SafetySourceData safetySourceData = captor.getValue();
465         SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
466 
467         assertThat(safetySourceStatus.getTitle().toString()).isEqualTo(expectedTitle);
468         assertThat(safetySourceStatus.getSummary().toString()).isEqualTo(expectedSummary);
469         assertThat(safetySourceStatus.isEnabled()).isTrue();
470         Intent clickIntent = safetySourceStatus.getPendingIntent().getIntent();
471         assertThat(clickIntent).isNotNull();
472         assertThat(clickIntent.getComponent().getPackageName()).isEqualTo("com.android.settings");
473         assertThat(clickIntent.getComponent().getClassName()).isEqualTo(expectedSettingsClassName);
474     }
475 
createFingerprintList(int size)476     private List<Fingerprint> createFingerprintList(int size) {
477         List<Fingerprint> fingerprintList = new ArrayList<>(size);
478         for (int i = 0; i < size; i++) {
479             fingerprintList.add(new Fingerprint("fingerprint" + i, 0, 0));
480         }
481         return fingerprintList;
482     }
483 }
484