Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7526b925 authored by Joshua McCloskey's avatar Joshua McCloskey
Browse files

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
parent 2bf233e3
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -11,6 +11,11 @@
        android:name="com.android.settings.BATTERY_DATA"
        android:protectionLevel="signature|privileged"/>

    <!-- Permission for using the Biometric Settings Provider. -->
    <permission
        android:name="com.android.settings.USE_BIOMETRIC_PROVIDER"
        android:protectionLevel="signature|privileged"/>

    <uses-permission android:name="android.permission.REQUEST_NETWORK_SCORES" />
    <uses-permission android:name="android.permission.WRITE_MEDIA_STORAGE" />
    <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
@@ -4971,6 +4976,16 @@
                android:value="@string/menu_key_security"/>
        </activity>

         <provider
            android:name=".biometrics.BiometricSettingsProvider"
            android:authorities="${applicationId}.biometrics.provider"
            android:exported="true"
            android:permission="com.android.settings.USE_BIOMETRIC_PROVIDER">
            <intent-filter>
                <action android:name="com.android.settings.biometrics.BIOMETRIC_SETTINGS_PROVIDER" />
            </intent-filter>
        </provider>

        <activity-alias android:name="UsageStatsActivity"
                        android:exported="true"
                        android:label="@string/testing_usage_stats"
+1 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ aconfig_declarations {
        "settings_telephony_flag_declarations.aconfig",
        "settings_biometrics_integration_declarations.aconfig",
        "settings_voice_activation_apps_flag_declarations.aconfig",
        "settings_biometrics_framework_flag_declarations.aconfig",
    ],
}

+8 −0
Original line number Diff line number Diff line
package: "com.android.settings.flags"

flag {
  name: "biometric_settings_provider"
  namespace: "biometrics_framework"
  description: "This flag enables or disables the BiometricSettingsProvider"
  bug: "303595205"
}
+78 −0
Original line number Diff line number Diff line
/*
 * 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.ContentProvider
import android.content.ContentValues
import android.database.Cursor
import android.net.Uri
import android.os.Bundle
import com.android.settings.flags.Flags

class BiometricSettingsProvider : ContentProvider() {
  companion object {
    const val GET_SUW_FACE_ENABLED = "getSuwFaceEnabled"
    const val SUW_FACE_ENABLED = "suw_face_enabled"
  }

  override fun delete(uri: Uri, selection: String?, selectionArgs: Array<out String>?): 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<out String>?,
    selection: String?,
    selectionArgs: Array<out String>?,
    sortOrder: String?
  ): Cursor? {
    throw UnsupportedOperationException("query not supported")
  }

  override fun update(
    uri: Uri,
    values: ContentValues?,
    selection: String?,
    selectionArgs: Array<out String>?
  ): 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
  }
}
+92 −0
Original line number Diff line number Diff line
/*
 * 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)
  }
}