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.systemui.bouncer.data.repository 18 19 import android.content.res.Resources 20 import com.android.internal.R 21 import com.android.systemui.common.ui.data.repository.ConfigurationRepository 22 import com.android.systemui.dagger.SysUISingleton 23 import com.android.systemui.dagger.qualifiers.Application 24 import com.android.systemui.dagger.qualifiers.Main 25 import javax.inject.Inject 26 import kotlinx.coroutines.CoroutineScope 27 import kotlinx.coroutines.flow.SharingStarted 28 import kotlinx.coroutines.flow.StateFlow 29 import kotlinx.coroutines.flow.map 30 import kotlinx.coroutines.flow.stateIn 31 32 /** Encapsulates Emergency Services related state. */ 33 @SysUISingleton 34 class EmergencyServicesRepository 35 @Inject 36 constructor( 37 @Application private val applicationScope: CoroutineScope, 38 @Main private val resources: Resources, 39 configurationRepository: ConfigurationRepository, 40 ) { 41 /** 42 * Whether to enable emergency services calls while the SIM card is locked. This is disabled in 43 * certain countries that don't support this. 44 */ 45 val enableEmergencyCallWhileSimLocked: StateFlow<Boolean> = 46 configurationRepository.onConfigurationChange <lambda>null47 .map { getEnableEmergencyCallWhileSimLocked() } 48 .stateIn( 49 scope = applicationScope, 50 started = SharingStarted.Eagerly, 51 initialValue = getEnableEmergencyCallWhileSimLocked() 52 ) 53 getEnableEmergencyCallWhileSimLockednull54 private fun getEnableEmergencyCallWhileSimLocked(): Boolean { 55 return resources.getBoolean(R.bool.config_enable_emergency_call_while_sim_locked) 56 } 57 } 58