1 /* 2 * Copyright (C) 2023 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.biometrics 18 19 import android.content.Context 20 import android.content.res.Resources 21 import android.net.Uri 22 import android.os.Bundle 23 import android.platform.test.annotations.RequiresFlagsEnabled 24 import android.platform.test.flag.junit.CheckFlagsRule 25 import android.platform.test.flag.junit.DeviceFlagsValueProvider 26 import com.android.settings.flags.Flags 27 import com.google.common.truth.Truth.assertThat 28 import org.junit.Before 29 import org.junit.Rule 30 import org.junit.Test 31 import org.junit.runner.RunWith 32 import org.mockito.Mockito.spy 33 import org.mockito.Mockito.`when` as whenever 34 import org.mockito.Spy 35 import org.robolectric.RobolectricTestRunner 36 import org.robolectric.RuntimeEnvironment 37 38 @RunWith(RobolectricTestRunner::class) 39 class BiometricSettingsProviderTest { 40 @Spy private var context: Context = spy(RuntimeEnvironment.application) 41 @Spy private var resources: Resources = spy(context.resources) 42 private lateinit var provider: BiometricSettingsProvider 43 44 @get:Rule val checkFlagsRule: CheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule() 45 46 @Before setUpnull47 fun setUp() { 48 whenever(context.resources).thenReturn(resources) 49 provider = BiometricSettingsProvider() 50 provider.attachInfo(context, null) 51 } 52 53 @Test(expected = UnsupportedOperationException::class) query_shouldCrashnull54 fun query_shouldCrash() { 55 provider.query(Uri.EMPTY, null, null, null, null) 56 } 57 58 @Test(expected = UnsupportedOperationException::class) getType_shouldCrashnull59 fun getType_shouldCrash() { 60 provider.getType(Uri.EMPTY) 61 } 62 63 @Test(expected = UnsupportedOperationException::class) insert_shouldCrashnull64 fun insert_shouldCrash() { 65 provider.insert(Uri.EMPTY, null) 66 } 67 68 @Test(expected = UnsupportedOperationException::class) delete_shouldCrashnull69 fun delete_shouldCrash() { 70 provider.delete(Uri.EMPTY, null, null) 71 } 72 73 @Test(expected = UnsupportedOperationException::class) update_shouldCrashnull74 fun update_shouldCrash() { 75 provider.update(Uri.EMPTY, null, null, null) 76 } 77 78 @Test 79 @RequiresFlagsEnabled(Flags.FLAG_BIOMETRIC_SETTINGS_PROVIDER) getSuggestionState_shouldQueryFeatureProvidernull80 fun getSuggestionState_shouldQueryFeatureProvider() { 81 val expectedValue = false 82 setSupportFaceEnroll(expectedValue) 83 84 val bundle = provider.call(BiometricSettingsProvider.GET_SUW_FACE_ENABLED, null, Bundle()) 85 assertThat(bundle!!.getBoolean(BiometricSettingsProvider.SUW_FACE_ENABLED)) 86 .isEqualTo(expectedValue) 87 } 88 setSupportFaceEnrollnull89 private fun setSupportFaceEnroll(toThis: Boolean) { 90 whenever(resources.getBoolean(com.android.settings.R.bool.config_suw_support_face_enroll)) 91 .thenReturn(toThis) 92 } 93 } 94