diff --git a/src/com/android/settings/safetycenter/BiometricsSafetySource.java b/src/com/android/settings/safetycenter/BiometricsSafetySource.java index ac486d708c1..1fe366d69a7 100644 --- a/src/com/android/settings/safetycenter/BiometricsSafetySource.java +++ b/src/com/android/settings/safetycenter/BiometricsSafetySource.java @@ -29,6 +29,7 @@ import android.safetycenter.SafetySourceStatus; import com.android.settings.Utils; import com.android.settings.biometrics.BiometricNavigationUtils; +import com.android.settings.biometrics.activeunlock.ActiveUnlockStatusUtils; import com.android.settings.biometrics.combination.CombinedBiometricStatusUtils; import com.android.settings.biometrics.face.FaceStatusUtils; import com.android.settings.biometrics.fingerprint.FingerprintStatusUtils; @@ -57,7 +58,25 @@ public final class BiometricsSafetySource { userId); final CombinedBiometricStatusUtils combinedBiometricStatusUtils = new CombinedBiometricStatusUtils(context, userId); + final ActiveUnlockStatusUtils activeUnlockStatusUtils = + new ActiveUnlockStatusUtils(context); + if (activeUnlockStatusUtils.isAvailable()) { + final RestrictedLockUtils.EnforcedAdmin disablingAdmin = + combinedBiometricStatusUtils.getDisablingAdmin(); + setBiometricSafetySourceData(context, + activeUnlockStatusUtils.getTitleForActiveUnlock(), + combinedBiometricStatusUtils.getSummary(), + createPendingIntent(context, + biometricNavigationUtils.getBiometricSettingsIntent(context, + combinedBiometricStatusUtils.getSettingsClassName(), + disablingAdmin, Bundle.EMPTY), + REQUEST_CODE_COMBINED_BIOMETRIC_SETTING), + disablingAdmin == null /* enabled */, + combinedBiometricStatusUtils.hasEnrolled(), + safetyEvent); + return; + } if (combinedBiometricStatusUtils.isAvailable()) { final RestrictedLockUtils.EnforcedAdmin disablingAdmin = combinedBiometricStatusUtils.getDisablingAdmin(); diff --git a/tests/unit/src/com/android/settings/safetycenter/BiometricsSafetySourceTest.java b/tests/unit/src/com/android/settings/safetycenter/BiometricsSafetySourceTest.java index 9e22e8d0b35..01c2143740b 100644 --- a/tests/unit/src/com/android/settings/safetycenter/BiometricsSafetySourceTest.java +++ b/tests/unit/src/com/android/settings/safetycenter/BiometricsSafetySourceTest.java @@ -48,6 +48,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4; import com.android.settings.Settings; import com.android.settings.biometrics.face.FaceEnrollIntroductionInternal; import com.android.settings.biometrics.fingerprint.FingerprintSettings; +import com.android.settings.testutils.ActiveUnlockTestUtils; import com.android.settings.testutils.ResourcesUtils; import com.android.settingslib.utils.StringUtil; @@ -408,6 +409,62 @@ public class BiometricsSafetySourceTest { Settings.CombinedBiometricSettingsActivity.class.getName()); } + @Test + public void setSafetySourceData_activeUnlockEnabled_withFingerprintOnly_setsData() { + final int enrolledFingerprintsCount = 1; + when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true); + when(mFingerprintManager.isHardwareDetected()).thenReturn(true); + when(mFaceManager.isHardwareDetected()).thenReturn(false); + when(mFingerprintManager.getEnrolledFingerprints(anyInt())).thenReturn( + createFingerprintList(enrolledFingerprintsCount)); + + ActiveUnlockTestUtils.enable(mApplicationContext); + + BiometricsSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED); + + assertSafetySourceEnabledDataSetWithPluralSummary( + "security_settings_fingerprint_preference_title", + "security_settings_fingerprint_preference_summary", + enrolledFingerprintsCount, + Settings.CombinedBiometricSettingsActivity.class.getName()); + } + + @Test + public void setSafetySourceData_activeUnlockEnabled_withFaceOnly_setsData() { + when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true); + when(mFingerprintManager.isHardwareDetected()).thenReturn(false); + when(mFaceManager.isHardwareDetected()).thenReturn(true); + when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(true); + ActiveUnlockTestUtils.enable(mApplicationContext); + + BiometricsSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED); + + assertSafetySourceEnabledDataSetWithSingularSummary( + "security_settings_face_preference_title", + "security_settings_face_preference_summary", + Settings.CombinedBiometricSettingsActivity.class.getName()); + } + + @Test + public void setSafetySourceData_activeUnlockEnabled_withFaceAndFingerprint_setsData() { + final int enrolledFingerprintsCount = 1; + when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true); + when(mFingerprintManager.isHardwareDetected()).thenReturn(true); + when(mFaceManager.isHardwareDetected()).thenReturn(true); + when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(true); + when(mFingerprintManager.getEnrolledFingerprints(anyInt())).thenReturn( + createFingerprintList(enrolledFingerprintsCount)); + ActiveUnlockTestUtils.enable(mApplicationContext); + + BiometricsSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED); + + assertSafetySourceEnabledDataSetWithSingularSummary( + "security_settings_biometric_preference_title", + "security_settings_biometric_preference_summary_both_fp_single", + Settings.CombinedBiometricSettingsActivity.class.getName()); + + } + @Test public void setSafetySourceData_faceAndFingerprint_whenNoFaceEnrolled_withFingers_setsData() { final int enrolledFingerprintsCount = 1; diff --git a/tests/unit/src/com/android/settings/testutils/ActiveUnlockTestUtils.java b/tests/unit/src/com/android/settings/testutils/ActiveUnlockTestUtils.java new file mode 100644 index 00000000000..0cecaee2939 --- /dev/null +++ b/tests/unit/src/com/android/settings/testutils/ActiveUnlockTestUtils.java @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.testutils; + +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.anyInt; +import static org.mockito.Mockito.when; + +import android.content.Context; +import android.content.pm.ActivityInfo; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.content.pm.ProviderInfo; +import android.content.pm.ResolveInfo; +import android.provider.DeviceConfig; +import android.provider.Settings; + +import com.android.settings.biometrics.activeunlock.ActiveUnlockStatusUtils; + +import java.util.ArrayList; + +/** Utilities class to enable or disable the Active Unlock flag in tests. */ +public final class ActiveUnlockTestUtils { + + public static final String TARGET = "com.active.unlock.target"; + public static final String PROVIDER = "com.active.unlock.provider"; + public static final String TARGET_SETTING = "active_unlock_target"; + public static final String PROVIDER_SETTING = "active_unlock_provider"; + + public static void enable(Context context) { + ActiveUnlockTestUtils.enable(context, ActiveUnlockStatusUtils.UNLOCK_INTENT_LAYOUT); + } + + public static void enable(Context context, String flagValue) { + Settings.Secure.putString( + context.getContentResolver(), TARGET_SETTING, TARGET); + Settings.Secure.putString( + context.getContentResolver(), PROVIDER_SETTING, PROVIDER); + + PackageManager packageManager = context.getPackageManager(); + ApplicationInfo applicationInfo = new ApplicationInfo(); + applicationInfo.flags = ApplicationInfo.FLAG_SYSTEM; + + ResolveInfo resolveInfo = new ResolveInfo(); + resolveInfo.activityInfo = new ActivityInfo(); + resolveInfo.activityInfo.applicationInfo = applicationInfo; + when(packageManager.resolveActivity(any(), anyInt())).thenReturn(resolveInfo); + + PackageInfo packageInfo = new PackageInfo(); + packageInfo.applicationInfo = applicationInfo; + ProviderInfo providerInfo = new ProviderInfo(); + providerInfo.authority = PROVIDER; + providerInfo.applicationInfo = applicationInfo; + packageInfo.providers = new ProviderInfo[] { providerInfo }; + ArrayList packageInfos = new ArrayList<>(); + packageInfos.add(packageInfo); + when(packageManager.getInstalledPackages(any())).thenReturn(packageInfos); + + DeviceConfig.setProperty( + DeviceConfig.NAMESPACE_REMOTE_AUTH, + ActiveUnlockStatusUtils.CONFIG_FLAG_NAME, + flagValue, + false /* makeDefault */); + } + + public static void disable(Context context) { + DeviceConfig.setProperty( + DeviceConfig.NAMESPACE_REMOTE_AUTH, + ActiveUnlockStatusUtils.CONFIG_FLAG_NAME, + null /* value */, + false /* makeDefault */); + } +}