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.systemui.statusbar.notification.collection.ListEntry 20 import com.android.systemui.statusbar.notification.collection.NotifPipeline 21 import com.android.systemui.statusbar.notification.collection.coordinator.dagger.CoordinatorScope 22 import com.android.systemui.statusbar.notification.collection.render.NotifStackController 23 import com.android.systemui.statusbar.notification.collection.render.NotifStats 24 import com.android.systemui.statusbar.notification.stack.BUCKET_SILENT 25 import com.android.systemui.statusbar.phone.NotificationIconAreaController 26 import com.android.systemui.util.traceSection 27 import javax.inject.Inject 28 29 /** 30 * A small coordinator which updates the notif stack (the view layer which holds notifications) 31 * with high-level data after the stack is populated with the final entries. 32 */ 33 @CoordinatorScope 34 class StackCoordinator @Inject internal constructor( 35 private val notificationIconAreaController: NotificationIconAreaController 36 ) : Coordinator { 37 attachnull38 override fun attach(pipeline: NotifPipeline) { 39 pipeline.addOnAfterRenderListListener(::onAfterRenderList) 40 } 41 onAfterRenderListnull42 fun onAfterRenderList(entries: List<ListEntry>, controller: NotifStackController) = 43 traceSection("StackCoordinator.onAfterRenderList") { 44 controller.setNotifStats(calculateNotifStats(entries)) 45 notificationIconAreaController.updateNotificationIcons(entries) 46 } 47 calculateNotifStatsnull48 private fun calculateNotifStats(entries: List<ListEntry>): NotifStats { 49 var hasNonClearableAlertingNotifs = false 50 var hasClearableAlertingNotifs = false 51 var hasNonClearableSilentNotifs = false 52 var hasClearableSilentNotifs = false 53 entries.forEach { 54 val section = checkNotNull(it.section) { "Null section for ${it.key}" } 55 val entry = checkNotNull(it.representativeEntry) { "Null notif entry for ${it.key}" } 56 val isSilent = section.bucket == BUCKET_SILENT 57 // NOTE: NotificationEntry.isClearable will internally check group children to ensure 58 // the group itself definitively clearable. 59 val isClearable = entry.isClearable 60 when { 61 isSilent && isClearable -> hasClearableSilentNotifs = true 62 isSilent && !isClearable -> hasNonClearableSilentNotifs = true 63 !isSilent && isClearable -> hasClearableAlertingNotifs = true 64 !isSilent && !isClearable -> hasNonClearableAlertingNotifs = true 65 } 66 } 67 return NotifStats( 68 numActiveNotifs = entries.size, 69 hasNonClearableAlertingNotifs = hasNonClearableAlertingNotifs, 70 hasClearableAlertingNotifs = hasClearableAlertingNotifs, 71 hasNonClearableSilentNotifs = hasNonClearableSilentNotifs, 72 hasClearableSilentNotifs = hasClearableSilentNotifs 73 ) 74 } 75 }