From 7526b9259eebd5f0d7c7ed85469a384e3a3a9012 Mon Sep 17 00:00:00 2001 From: Joshua McCloskey Date: Thu, 19 Oct 2023 00:15:14 +0000 Subject: [PATCH] Created biometric provider. Test: Manually verified data was fetched successfully. Test: adb shell device_config put biometrics_framework com.android.settings.flags.biometric_settings_provider true Test: atest BiometricSettingsProviderTest Bug: 303595205 Change-Id: I154754eed7c36d659853ed83cc18a2e446fb7678 --- AndroidManifest.xml | 15 +++ aconfig/Android.bp | 1 + ...etrics_framework_flag_declarations.aconfig | 8 ++ .../biometrics/BiometricSettingsProvider.kt | 78 ++++++++++++++++ .../BiometricSettingsProviderTest.kt | 92 +++++++++++++++++++ 5 files changed, 194 insertions(+) create mode 100644 aconfig/settings_biometrics_framework_flag_declarations.aconfig create mode 100644 src/com/android/settings/biometrics/BiometricSettingsProvider.kt create mode 100644 tests/robotests/src/com/android/settings/biometrics/BiometricSettingsProviderTest.kt diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 9e334671e81..29d9d39671a 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -11,6 +11,11 @@ android:name="com.android.settings.BATTERY_DATA" android:protectionLevel="signature|privileged"/> + + + @@ -4971,6 +4976,16 @@ android:value="@string/menu_key_security"/> + + + + + + ?): Int { + throw UnsupportedOperationException("query operation not supported currently.") + } + + override fun getType(uri: Uri): String? { + throw UnsupportedOperationException("getType not supported") + } + + override fun insert(uri: Uri, values: ContentValues?): Uri? { + throw UnsupportedOperationException("insert not supported") + } + + override fun query( + uri: Uri, + projection: Array?, + selection: String?, + selectionArgs: Array?, + sortOrder: String? + ): Cursor? { + throw UnsupportedOperationException("query not supported") + } + + override fun update( + uri: Uri, + values: ContentValues?, + selection: String?, + selectionArgs: Array? + ): Int { + throw UnsupportedOperationException("update not supported") + } + + override fun onCreate(): Boolean = true + + override fun call(method: String, arg: String?, extras: Bundle?): Bundle? { + val bundle = Bundle() + if (Flags.biometricSettingsProvider()) { + if (GET_SUW_FACE_ENABLED == method) { + val faceEnabled = + requireContext() + .resources + .getBoolean(com.android.settings.R.bool.config_suw_support_face_enroll) + bundle.putBoolean(SUW_FACE_ENABLED, faceEnabled) + } + } + return bundle + } +} diff --git a/tests/robotests/src/com/android/settings/biometrics/BiometricSettingsProviderTest.kt b/tests/robotests/src/com/android/settings/biometrics/BiometricSettingsProviderTest.kt new file mode 100644 index 00000000000..edb1230719a --- /dev/null +++ b/tests/robotests/src/com/android/settings/biometrics/BiometricSettingsProviderTest.kt @@ -0,0 +1,92 @@ +/* + * 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.biometrics + +import android.content.Context +import android.content.res.Resources +import android.net.Uri +import android.os.Bundle +import android.platform.test.annotations.RequiresFlagsEnabled +import android.platform.test.flag.junit.CheckFlagsRule +import android.platform.test.flag.junit.DeviceFlagsValueProvider +import com.android.settings.flags.Flags +import com.google.common.truth.Truth.assertThat +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mockito.spy +import org.mockito.Mockito.`when` as whenever +import org.mockito.Spy +import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment + +@RunWith(RobolectricTestRunner::class) +class BiometricSettingsProviderTest { + @Spy private var context: Context = spy(RuntimeEnvironment.application) + @Spy private var resources: Resources = spy(context.resources) + private lateinit var provider: BiometricSettingsProvider + + @get:Rule val checkFlagsRule: CheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule() + + @Before + fun setUp() { + provider = BiometricSettingsProvider() + } + + @Test(expected = UnsupportedOperationException::class) + fun query_shouldCrash() { + provider.query(Uri.EMPTY, null, null, null, null) + } + + @Test(expected = UnsupportedOperationException::class) + fun getType_shouldCrash() { + provider.getType(Uri.EMPTY) + } + + @Test(expected = UnsupportedOperationException::class) + fun insert_shouldCrash() { + provider.insert(Uri.EMPTY, null) + } + + @Test(expected = UnsupportedOperationException::class) + fun delete_shouldCrash() { + provider.delete(Uri.EMPTY, null, null) + } + + @Test(expected = UnsupportedOperationException::class) + fun update_shouldCrash() { + provider.update(Uri.EMPTY, null, null, null) + } + + @Test + @RequiresFlagsEnabled(Flags.FLAG_BIOMETRIC_SETTINGS_PROVIDER) + fun getSuggestionState_shouldQueryFeatureProvider() { + val expectedValue = false + setSupportFaceEnroll(expectedValue) + + val bundle = + provider.call(BiometricSettingsProvider.GET_SUW_FACE_ENABLED, null, Bundle()) + assertThat(bundle!!.getString(BiometricSettingsProvider.SUW_FACE_ENABLED)) + .isEqualTo(expectedValue) + } + + private fun setSupportFaceEnroll(toThis: Boolean) { + whenever(resources.getBoolean(com.android.settings.R.bool.config_suw_support_face_enroll)) + .thenReturn(toThis) + } +}