1 /* <lambda>null2 * Copyright (C) 2024 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.shade.domain.interactor 18 19 import com.android.systemui.dagger.SysUISingleton 20 import com.android.systemui.dagger.qualifiers.Application 21 import com.android.systemui.privacy.OngoingPrivacyChip 22 import com.android.systemui.privacy.PrivacyDialogController 23 import com.android.systemui.privacy.PrivacyDialogControllerV2 24 import com.android.systemui.privacy.PrivacyItem 25 import com.android.systemui.shade.data.repository.PrivacyChipRepository 26 import com.android.systemui.statusbar.policy.DeviceProvisionedController 27 import javax.inject.Inject 28 import kotlinx.coroutines.CoroutineScope 29 import kotlinx.coroutines.flow.SharingStarted 30 import kotlinx.coroutines.flow.StateFlow 31 import kotlinx.coroutines.flow.combine 32 import kotlinx.coroutines.flow.map 33 import kotlinx.coroutines.flow.stateIn 34 35 @SysUISingleton 36 class PrivacyChipInteractor 37 @Inject 38 constructor( 39 @Application applicationScope: CoroutineScope, 40 private val repository: PrivacyChipRepository, 41 private val privacyDialogController: PrivacyDialogController, 42 private val privacyDialogControllerV2: PrivacyDialogControllerV2, 43 private val deviceProvisionedController: DeviceProvisionedController, 44 private val shadeDialogContextInteractor: ShadeDialogContextInteractor, 45 ) { 46 /** The list of PrivacyItems to be displayed by the privacy chip. */ 47 val privacyItems: StateFlow<List<PrivacyItem>> = repository.privacyItems 48 49 /** Whether or not mic & camera indicators are enabled in the device privacy config. */ 50 val isMicCameraIndicationEnabled: StateFlow<Boolean> = repository.isMicCameraIndicationEnabled 51 52 /** Whether or not location indicators are enabled in the device privacy config. */ 53 val isLocationIndicationEnabled: StateFlow<Boolean> = repository.isLocationIndicationEnabled 54 55 /** Whether or not the privacy chip should be visible. */ 56 val isChipVisible: StateFlow<Boolean> = 57 privacyItems 58 .map { it.isNotEmpty() } 59 .stateIn( 60 scope = applicationScope, 61 started = SharingStarted.WhileSubscribed(), 62 initialValue = false, 63 ) 64 65 /** Whether or not the privacy chip is enabled in the device privacy config. */ 66 val isChipEnabled: StateFlow<Boolean> = 67 combine( 68 isMicCameraIndicationEnabled, 69 isLocationIndicationEnabled, 70 ) { micCamera, location -> 71 micCamera || location 72 } 73 .stateIn( 74 scope = applicationScope, 75 started = SharingStarted.WhileSubscribed(), 76 initialValue = false, 77 ) 78 79 /** Notifies that the privacy chip was clicked. */ 80 fun onPrivacyChipClicked(privacyChip: OngoingPrivacyChip) { 81 if (!deviceProvisionedController.isDeviceProvisioned) return 82 83 if (repository.isSafetyCenterEnabled.value) { 84 privacyDialogControllerV2.showDialog(shadeDialogContextInteractor.context, privacyChip) 85 } else { 86 privacyDialogController.showDialog(shadeDialogContextInteractor.context) 87 } 88 } 89 } 90