1 /* 2 * Copyright (C) 2020 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.inflation; 18 19 import com.android.systemui.dagger.SysUISingleton; 20 import com.android.systemui.statusbar.FeatureFlags; 21 import com.android.systemui.statusbar.notification.collection.GroupEntry; 22 import com.android.systemui.statusbar.notification.collection.NotificationEntry; 23 import com.android.systemui.statusbar.notification.collection.legacy.NotificationGroupManagerLegacy; 24 import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; 25 import com.android.systemui.statusbar.notification.row.RowContentBindParams; 26 import com.android.systemui.statusbar.notification.row.RowContentBindStage; 27 28 import javax.inject.Inject; 29 30 /** 31 * Helper class that provide methods to help check when we need to inflate a low priority version 32 * ot notification content. 33 */ 34 @SysUISingleton 35 public class LowPriorityInflationHelper { 36 private final FeatureFlags mFeatureFlags; 37 private final NotificationGroupManagerLegacy mGroupManager; 38 private final RowContentBindStage mRowContentBindStage; 39 40 @Inject LowPriorityInflationHelper( FeatureFlags featureFlags, NotificationGroupManagerLegacy groupManager, RowContentBindStage rowContentBindStage)41 LowPriorityInflationHelper( 42 FeatureFlags featureFlags, 43 NotificationGroupManagerLegacy groupManager, 44 RowContentBindStage rowContentBindStage) { 45 mFeatureFlags = featureFlags; 46 mGroupManager = groupManager; 47 mRowContentBindStage = rowContentBindStage; 48 } 49 50 /** 51 * Check if we inflated the wrong version of the view and if we need to reinflate the 52 * content views to be their low priority version or not. 53 * 54 * Whether we inflate the low priority view or not depends on the notification being visually 55 * part of a group. Since group membership is determined AFTER inflation, we're forced to check 56 * again at a later point in the pipeline to see if we inflated the wrong view and reinflate 57 * the correct one here. 58 * 59 * TODO: The group manager should run before inflation so that we don't deal with this 60 */ recheckLowPriorityViewAndInflate( NotificationEntry entry, ExpandableNotificationRow row)61 public void recheckLowPriorityViewAndInflate( 62 NotificationEntry entry, 63 ExpandableNotificationRow row) { 64 RowContentBindParams params = mRowContentBindStage.getStageParams(entry); 65 final boolean shouldBeLowPriority = shouldUseLowPriorityView(entry); 66 if (!row.isRemoved() && row.isLowPriority() != shouldBeLowPriority) { 67 params.setUseLowPriority(shouldBeLowPriority); 68 mRowContentBindStage.requestRebind(entry, 69 en -> row.setIsLowPriority(shouldBeLowPriority)); 70 } 71 } 72 73 /** 74 * Whether the notification should inflate a low priority version of its content views. 75 */ shouldUseLowPriorityView(NotificationEntry entry)76 public boolean shouldUseLowPriorityView(NotificationEntry entry) { 77 boolean isGroupChild; 78 if (mFeatureFlags.isNewNotifPipelineRenderingEnabled()) { 79 isGroupChild = (entry.getParent() != GroupEntry.ROOT_ENTRY); 80 } else { 81 isGroupChild = mGroupManager.isChildInGroup(entry); 82 } 83 return entry.isAmbient() && !isGroupChild; 84 } 85 } 86