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.stack 18 19 import com.android.internal.util.LatencyTracker 20 import com.android.internal.util.LatencyTracker.ACTION_NOTIFICATIONS_HIDDEN_FOR_MEASURE 21 import com.android.internal.util.LatencyTracker.ACTION_NOTIFICATIONS_HIDDEN_FOR_MEASURE_WITH_SHADE_OPEN 22 import com.android.systemui.shade.domain.interactor.ShadeInteractor 23 import kotlinx.coroutines.flow.Flow 24 import kotlinx.coroutines.flow.combine 25 import kotlinx.coroutines.flow.distinctUntilChanged 26 import javax.inject.Inject 27 28 /** 29 * Tracks latencies related to temporary hiding notifications while measuring 30 * them, which is an optimization to show some content as early as possible 31 * and perform notifications measurement later. 32 * See [HideNotificationsInteractor]. 33 */ 34 class DisplaySwitchNotificationsHiderTracker @Inject constructor( 35 private val notificationsInteractor: ShadeInteractor, 36 private val latencyTracker: LatencyTracker 37 ) { 38 39 suspend fun trackNotificationHideTime(shouldHideNotifications: Flow<Boolean>) { 40 shouldHideNotifications 41 .collect { shouldHide -> 42 if (shouldHide) { 43 latencyTracker.onActionStart(ACTION_NOTIFICATIONS_HIDDEN_FOR_MEASURE) 44 } else { 45 latencyTracker.onActionEnd(ACTION_NOTIFICATIONS_HIDDEN_FOR_MEASURE) 46 } 47 } 48 } 49 50 suspend fun trackNotificationHideTimeWhenVisible(shouldHideNotifications: Flow<Boolean>) { 51 combine(shouldHideNotifications, notificationsInteractor.isAnyExpanded) 52 { hidden, shadeExpanded -> hidden && shadeExpanded } 53 .distinctUntilChanged() 54 .collect { hiddenButShouldBeVisible -> 55 if (hiddenButShouldBeVisible) { 56 latencyTracker.onActionStart( 57 ACTION_NOTIFICATIONS_HIDDEN_FOR_MEASURE_WITH_SHADE_OPEN) 58 } else { 59 latencyTracker.onActionEnd( 60 ACTION_NOTIFICATIONS_HIDDEN_FOR_MEASURE_WITH_SHADE_OPEN) 61 } 62 } 63 } 64 }