Loading src/com/android/settings/biometrics/face/FaceSettingsAppsPreferenceController.java +15 −2 Original line number Diff line number Diff line Loading @@ -20,7 +20,9 @@ import static android.provider.Settings.Secure.FACE_APP_ENABLED; import android.app.settings.SettingsEnums; import android.content.Context; import android.hardware.biometrics.SensorProperties; import android.hardware.face.FaceManager; import android.hardware.face.FaceSensorPropertiesInternal; import android.provider.Settings; import androidx.annotation.NonNull; Loading @@ -36,10 +38,21 @@ public class FaceSettingsAppsPreferenceController extends private static final int DEFAULT = ON; private FaceManager mFaceManager; private boolean mIsAllowed; public FaceSettingsAppsPreferenceController(@NonNull Context context, @NonNull String key) { super(context, key); mFaceManager = Utils.getFaceManagerOrNull(context); if (mFaceManager != null) { for (final FaceSensorPropertiesInternal sensorProps : mFaceManager.getSensorPropertiesInternal()) { if (sensorProps.sensorStrength == SensorProperties.STRENGTH_WEAK || sensorProps.sensorStrength == SensorProperties.STRENGTH_STRONG) { mIsAllowed = true; break; } } } } @Override Loading Loading @@ -74,8 +87,8 @@ public class FaceSettingsAppsPreferenceController extends public int getAvailabilityStatus() { final ActiveUnlockStatusUtils activeUnlockStatusUtils = new ActiveUnlockStatusUtils(mContext); if (!Utils.hasFaceHardware(mContext) && !activeUnlockStatusUtils.isAvailable()) { if ((!Utils.hasFaceHardware(mContext) && !activeUnlockStatusUtils.isAvailable()) || !mIsAllowed) { return UNSUPPORTED_ON_DEVICE; } if (mFaceManager == null) { Loading tests/unit/src/com/android/settings/biometrics/face/FaceSettingsAppsPreferenceControllerTest.java +43 −2 Original line number Diff line number Diff line Loading @@ -16,14 +16,22 @@ package com.android.settings.biometrics.face; import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE; import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.app.settings.SettingsEnums; import android.content.Context; import android.hardware.biometrics.ComponentInfoInternal; import android.hardware.biometrics.SensorProperties; import android.hardware.face.FaceManager; import android.hardware.face.FaceSensorProperties; import android.hardware.face.FaceSensorPropertiesInternal; import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; Loading @@ -31,18 +39,45 @@ import androidx.test.ext.junit.runners.AndroidJUnit4; import com.android.settings.testutils.FakeFeatureFactory; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Spy; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; import java.util.ArrayList; @RunWith(AndroidJUnit4.class) public class FaceSettingsAppsPreferenceControllerTest { private Context mContext; @Rule public final MockitoRule mMockitoRule = MockitoJUnit.rule(); @Spy private Context mContext = ApplicationProvider.getApplicationContext(); @Mock private FaceManager mFaceManager; private FaceSettingsAppsPreferenceController mController; private FaceSensorPropertiesInternal mConvenienceSensorProperty = new FaceSensorPropertiesInternal( 0 /* sensorId */, SensorProperties.STRENGTH_CONVENIENCE, 1 /* maxEnrollmentsPerUser */, new ArrayList<ComponentInfoInternal>(), FaceSensorProperties.TYPE_UNKNOWN, true /* supportsFaceDetection */, true /* supportsSelfIllumination */, true /* resetLockoutRequiresChallenge */); private FakeFeatureFactory mFeatureFactory; @Before public void setUp() { mContext = ApplicationProvider.getApplicationContext(); when(mContext.getSystemService(Context.FACE_SERVICE)).thenReturn(mFaceManager); final ArrayList<FaceSensorPropertiesInternal> list = new ArrayList<>(); list.add(mConvenienceSensorProperty); when(mFaceManager.getSensorPropertiesInternal()).thenReturn(list); mFeatureFactory = FakeFeatureFactory.setupForTest(); mController = new FaceSettingsAppsPreferenceController( mContext, "biometric_settings_face_app"); Loading @@ -66,4 +101,10 @@ public class FaceSettingsAppsPreferenceControllerTest { verify(mFeatureFactory.metricsFeatureProvider).action(any(), eq(SettingsEnums.ACTION_FACE_ENABLED_FOR_APP_SETTINGS), eq(false)); } @Test public void getAvailabilityStatus_strengthConvenience_returnUnsupported() { int status = mController.getAvailabilityStatus(); assertThat(status).isEqualTo(UNSUPPORTED_ON_DEVICE); } } Loading
src/com/android/settings/biometrics/face/FaceSettingsAppsPreferenceController.java +15 −2 Original line number Diff line number Diff line Loading @@ -20,7 +20,9 @@ import static android.provider.Settings.Secure.FACE_APP_ENABLED; import android.app.settings.SettingsEnums; import android.content.Context; import android.hardware.biometrics.SensorProperties; import android.hardware.face.FaceManager; import android.hardware.face.FaceSensorPropertiesInternal; import android.provider.Settings; import androidx.annotation.NonNull; Loading @@ -36,10 +38,21 @@ public class FaceSettingsAppsPreferenceController extends private static final int DEFAULT = ON; private FaceManager mFaceManager; private boolean mIsAllowed; public FaceSettingsAppsPreferenceController(@NonNull Context context, @NonNull String key) { super(context, key); mFaceManager = Utils.getFaceManagerOrNull(context); if (mFaceManager != null) { for (final FaceSensorPropertiesInternal sensorProps : mFaceManager.getSensorPropertiesInternal()) { if (sensorProps.sensorStrength == SensorProperties.STRENGTH_WEAK || sensorProps.sensorStrength == SensorProperties.STRENGTH_STRONG) { mIsAllowed = true; break; } } } } @Override Loading Loading @@ -74,8 +87,8 @@ public class FaceSettingsAppsPreferenceController extends public int getAvailabilityStatus() { final ActiveUnlockStatusUtils activeUnlockStatusUtils = new ActiveUnlockStatusUtils(mContext); if (!Utils.hasFaceHardware(mContext) && !activeUnlockStatusUtils.isAvailable()) { if ((!Utils.hasFaceHardware(mContext) && !activeUnlockStatusUtils.isAvailable()) || !mIsAllowed) { return UNSUPPORTED_ON_DEVICE; } if (mFaceManager == null) { Loading
tests/unit/src/com/android/settings/biometrics/face/FaceSettingsAppsPreferenceControllerTest.java +43 −2 Original line number Diff line number Diff line Loading @@ -16,14 +16,22 @@ package com.android.settings.biometrics.face; import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE; import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.app.settings.SettingsEnums; import android.content.Context; import android.hardware.biometrics.ComponentInfoInternal; import android.hardware.biometrics.SensorProperties; import android.hardware.face.FaceManager; import android.hardware.face.FaceSensorProperties; import android.hardware.face.FaceSensorPropertiesInternal; import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; Loading @@ -31,18 +39,45 @@ import androidx.test.ext.junit.runners.AndroidJUnit4; import com.android.settings.testutils.FakeFeatureFactory; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Spy; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; import java.util.ArrayList; @RunWith(AndroidJUnit4.class) public class FaceSettingsAppsPreferenceControllerTest { private Context mContext; @Rule public final MockitoRule mMockitoRule = MockitoJUnit.rule(); @Spy private Context mContext = ApplicationProvider.getApplicationContext(); @Mock private FaceManager mFaceManager; private FaceSettingsAppsPreferenceController mController; private FaceSensorPropertiesInternal mConvenienceSensorProperty = new FaceSensorPropertiesInternal( 0 /* sensorId */, SensorProperties.STRENGTH_CONVENIENCE, 1 /* maxEnrollmentsPerUser */, new ArrayList<ComponentInfoInternal>(), FaceSensorProperties.TYPE_UNKNOWN, true /* supportsFaceDetection */, true /* supportsSelfIllumination */, true /* resetLockoutRequiresChallenge */); private FakeFeatureFactory mFeatureFactory; @Before public void setUp() { mContext = ApplicationProvider.getApplicationContext(); when(mContext.getSystemService(Context.FACE_SERVICE)).thenReturn(mFaceManager); final ArrayList<FaceSensorPropertiesInternal> list = new ArrayList<>(); list.add(mConvenienceSensorProperty); when(mFaceManager.getSensorPropertiesInternal()).thenReturn(list); mFeatureFactory = FakeFeatureFactory.setupForTest(); mController = new FaceSettingsAppsPreferenceController( mContext, "biometric_settings_face_app"); Loading @@ -66,4 +101,10 @@ public class FaceSettingsAppsPreferenceControllerTest { verify(mFeatureFactory.metricsFeatureProvider).action(any(), eq(SettingsEnums.ACTION_FACE_ENABLED_FOR_APP_SETTINGS), eq(false)); } @Test public void getAvailabilityStatus_strengthConvenience_returnUnsupported() { int status = mController.getAvailabilityStatus(); assertThat(status).isEqualTo(UNSUPPORTED_ON_DEVICE); } }