• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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.systemui.plugins.statusbar.StatusBarStateController
20 import com.android.systemui.statusbar.StatusBarState
21 import com.android.systemui.statusbar.notification.collection.NotifPipeline
22 import com.android.systemui.statusbar.notification.collection.NotificationEntry
23 import com.android.systemui.statusbar.notification.collection.coordinator.dagger.CoordinatorScope
24 import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifFilter
25 import com.android.systemui.statusbar.notification.collection.provider.SectionHeaderVisibilityProvider
26 import com.android.systemui.statusbar.notification.interruption.KeyguardNotificationVisibilityProvider
27 import javax.inject.Inject
28 
29 /**
30  * Filters low priority and privacy-sensitive notifications from the lockscreen, and hides section
31  * headers on the lockscreen. If enabled, it will also track and hide seen notifications on the
32  * lockscreen.
33  */
34 @CoordinatorScope
35 class KeyguardCoordinator
36 @Inject
37 constructor(
38     private val keyguardNotificationVisibilityProvider: KeyguardNotificationVisibilityProvider,
39     private val sectionHeaderVisibilityProvider: SectionHeaderVisibilityProvider,
40     private val statusBarStateController: StatusBarStateController,
41 ) : Coordinator {
42 
attachnull43     override fun attach(pipeline: NotifPipeline) {
44         setupInvalidateNotifListCallbacks()
45         // Filter at the "finalize" stage so that views remain bound by PreparationCoordinator
46         pipeline.addFinalizeFilter(notifFilter)
47         keyguardNotificationVisibilityProvider.addOnStateChangedListener(::invalidateListFromFilter)
48         updateSectionHeadersVisibility()
49     }
50 
51     private val notifFilter: NotifFilter =
52         object : NotifFilter(TAG) {
shouldFilterOutnull53             override fun shouldFilterOut(entry: NotificationEntry, now: Long): Boolean =
54                 keyguardNotificationVisibilityProvider.shouldHideNotification(entry)
55         }
56 
57     // TODO(b/206118999): merge this class with SensitiveContentCoordinator which also depends on
58     //  these same updates
59     private fun setupInvalidateNotifListCallbacks() {}
60 
invalidateListFromFilternull61     private fun invalidateListFromFilter(reason: String) {
62         updateSectionHeadersVisibility()
63         notifFilter.invalidateList(reason)
64     }
65 
updateSectionHeadersVisibilitynull66     private fun updateSectionHeadersVisibility() {
67         val onKeyguard = statusBarStateController.state == StatusBarState.KEYGUARD
68         val neverShowSections = sectionHeaderVisibilityProvider.neverShowSectionHeaders
69         val showSections = !onKeyguard && !neverShowSections
70         sectionHeaderVisibilityProvider.sectionHeadersVisible = showSections
71     }
72 
73     companion object {
74         private const val TAG = "KeyguardCoordinator"
75     }
76 }
77