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.statusbar.notification.promoted.domain.interactor 18 19 import com.android.systemui.dagger.SysUISingleton 20 import com.android.systemui.dump.DumpManager 21 import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor 22 import com.android.systemui.statusbar.notification.promoted.shared.model.PromotedNotificationContentModel 23 import com.android.systemui.statusbar.policy.domain.interactor.SensitiveNotificationProtectionInteractor 24 import com.android.systemui.util.kotlin.FlowDumperImpl 25 import javax.inject.Inject 26 import kotlinx.coroutines.flow.Flow 27 import kotlinx.coroutines.flow.combine 28 import kotlinx.coroutines.flow.distinctUntilChanged 29 import kotlinx.coroutines.flow.map 30 31 @SysUISingleton 32 class AODPromotedNotificationInteractor 33 @Inject 34 constructor( 35 promotedNotificationsInteractor: PromotedNotificationsInteractor, 36 keyguardInteractor: KeyguardInteractor, 37 sensitiveNotificationProtectionInteractor: SensitiveNotificationProtectionInteractor, 38 dumpManager: DumpManager, 39 ) : FlowDumperImpl(dumpManager) { 40 41 /** 42 * Whether the system is unlocked and not screensharing such that private notification content 43 * is allowed to show on the aod 44 */ 45 private val canShowPrivateNotificationContent: Flow<Boolean> = 46 combine( 47 keyguardInteractor.isKeyguardDismissible, 48 sensitiveNotificationProtectionInteractor.isSensitiveStateActive, 49 ) { isKeyguardDismissible, isSensitive -> 50 isKeyguardDismissible && !isSensitive 51 } 52 53 /** The content to show as the promoted notification on AOD */ 54 val content: Flow<PromotedNotificationContentModel?> = 55 combine( 56 promotedNotificationsInteractor.aodPromotedNotification, 57 canShowPrivateNotificationContent, 58 ) { promotedContent, showPrivateContent -> 59 if (showPrivateContent) promotedContent?.privateVersion 60 else promotedContent?.publicVersion 61 } 62 .distinctUntilNewInstance() 63 64 val isPresent: Flow<Boolean> = content.map { it != null }.dumpWhileCollecting("isPresent") 65 66 /** 67 * Returns flow where all subsequent repetitions of the same object instance are filtered out. 68 */ 69 private fun <T> Flow<T>.distinctUntilNewInstance() = distinctUntilChanged { a, b -> a === b } 70 } 71