• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.collection.coordinator
18 
19 import com.android.app.tracing.traceSection
20 import com.android.server.notification.Flags.screenshareNotificationHiding
21 import com.android.systemui.Flags.screenshareNotificationHidingBugFix
22 import com.android.systemui.statusbar.notification.collection.PipelineEntry
23 import com.android.systemui.statusbar.notification.collection.NotifPipeline
24 import com.android.systemui.statusbar.notification.collection.coordinator.dagger.CoordinatorScope
25 import com.android.systemui.statusbar.notification.collection.render.GroupExpansionManagerImpl
26 import com.android.systemui.statusbar.notification.data.model.NotifStats
27 import com.android.systemui.statusbar.notification.domain.interactor.ActiveNotificationsInteractor
28 import com.android.systemui.statusbar.notification.domain.interactor.RenderNotificationListInteractor
29 import com.android.systemui.statusbar.notification.stack.BUCKET_SILENT
30 import com.android.systemui.statusbar.policy.SensitiveNotificationProtectionController
31 import javax.inject.Inject
32 
33 /**
34  * A small coordinator which updates the notif stack (the view layer which holds notifications) with
35  * high-level data after the stack is populated with the final entries.
36  */
37 @CoordinatorScope
38 class StackCoordinator
39 @Inject
40 internal constructor(
41     private val groupExpansionManagerImpl: GroupExpansionManagerImpl,
42     private val renderListInteractor: RenderNotificationListInteractor,
43     private val activeNotificationsInteractor: ActiveNotificationsInteractor,
44     private val sensitiveNotificationProtectionController:
45         SensitiveNotificationProtectionController,
46 ) : Coordinator {
47 
attachnull48     override fun attach(pipeline: NotifPipeline) {
49         pipeline.addOnAfterRenderListListener(::onAfterRenderList)
50         groupExpansionManagerImpl.attach(pipeline)
51     }
52 
onAfterRenderListnull53     private fun onAfterRenderList(entries: List<PipelineEntry>) =
54         traceSection("StackCoordinator.onAfterRenderList") {
55             val notifStats = calculateNotifStats(entries)
56             activeNotificationsInteractor.setNotifStats(notifStats)
57             renderListInteractor.setRenderedList(entries)
58         }
59 
calculateNotifStatsnull60     private fun calculateNotifStats(entries: List<PipelineEntry>): NotifStats {
61         var hasNonClearableAlertingNotifs = false
62         var hasClearableAlertingNotifs = false
63         var hasNonClearableSilentNotifs = false
64         var hasClearableSilentNotifs = false
65         val isSensitiveContentProtectionActive =
66             screenshareNotificationHiding() &&
67                 screenshareNotificationHidingBugFix() &&
68                 sensitiveNotificationProtectionController.isSensitiveStateActive
69         entries.forEach {
70             val section = checkNotNull(it.section) { "Null section for ${it.key}" }
71             val entry = checkNotNull(it.representativeEntry) { "Null notif entry for ${it.key}" }
72             val isSilent = section.bucket == BUCKET_SILENT
73             // NOTE: NotificationEntry.isClearable will internally check group children to ensure
74             //  the group itself definitively clearable.
75             val isClearable =
76                 !isSensitiveContentProtectionActive && entry.isClearable && !entry.isSensitive.value
77             when {
78                 isSilent && isClearable -> hasClearableSilentNotifs = true
79                 isSilent && !isClearable -> hasNonClearableSilentNotifs = true
80                 !isSilent && isClearable -> hasClearableAlertingNotifs = true
81                 else -> hasNonClearableAlertingNotifs = true
82             }
83         }
84         return NotifStats(
85             hasNonClearableAlertingNotifs = hasNonClearableAlertingNotifs,
86             hasClearableAlertingNotifs = hasClearableAlertingNotifs,
87             hasNonClearableSilentNotifs = hasNonClearableSilentNotifs,
88             hasClearableSilentNotifs = hasClearableSilentNotifs,
89         )
90     }
91 }
92