Loading packages/SystemUI/src/com/android/systemui/statusbar/notification/icon/IconManager.kt +97 −91 Original line number Diff line number Diff line Loading @@ -48,7 +48,9 @@ import javax.inject.Inject * Long-term, it should probably live somewhere in the content inflation pipeline. */ @SysUISingleton class IconManager @Inject constructor( class IconManager @Inject constructor( private val notifCollection: CommonNotifCollection, private val launcherApps: LauncherApps, private val iconBuilder: IconBuilder Loading @@ -59,7 +61,8 @@ class IconManager @Inject constructor( notifCollection.addCollectionListener(entryListener) } private val entryListener = object : NotifCollectionListener { private val entryListener = object : NotifCollectionListener { override fun onEntryInit(entry: NotificationEntry) { entry.addOnSensitivityChangedListener(sensitivityListener) } Loading @@ -74,15 +77,14 @@ class IconManager @Inject constructor( } } private val sensitivityListener = NotificationEntry.OnSensitivityChangedListener { entry -> updateIconsSafe(entry) } private val sensitivityListener = NotificationEntry.OnSensitivityChangedListener { entry -> updateIconsSafe(entry) } private fun recalculateForImportantConversationChange() { for (entry in notifCollection.allNotifs) { val isImportant = isImportantConversation(entry) if (entry.icons.areIconsAvailable && isImportant != entry.icons.isImportantConversation if ( entry.icons.areIconsAvailable && isImportant != entry.icons.isImportantConversation ) { updateIconsSafe(entry) } Loading @@ -97,7 +99,8 @@ class IconManager @Inject constructor( * @throws InflationException Exception if required icons are not valid or specified */ @Throws(InflationException::class) fun createIcons(entry: NotificationEntry) = traceSection("IconManager.createIcons") { fun createIcons(entry: NotificationEntry) = traceSection("IconManager.createIcons") { // Construct the status bar icon view. val sbIcon = iconBuilder.createIconView(entry) sbIcon.scaleType = ImageView.ScaleType.CENTER_INSIDE Loading Loading @@ -133,7 +136,8 @@ class IconManager @Inject constructor( * @throws InflationException Exception if required icons are not valid or specified */ @Throws(InflationException::class) fun updateIcons(entry: NotificationEntry) = traceSection("IconManager.updateIcons") { fun updateIcons(entry: NotificationEntry) = traceSection("IconManager.updateIcons") { if (!entry.icons.areIconsAvailable) { return@traceSection } Loading @@ -141,9 +145,8 @@ class IconManager @Inject constructor( entry.icons.peopleAvatarDescriptor = null val (normalIconDescriptor, sensitiveIconDescriptor) = getIconDescriptors(entry) val notificationContentDescription = entry.sbn.notification?.let { iconBuilder.getIconContentDescription(it) } val notificationContentDescription = entry.sbn.notification?.let { iconBuilder.getIconContentDescription(it) } entry.icons.statusBarIcon?.let { it.setNotification(entry.sbn, notificationContentDescription) Loading @@ -152,7 +155,7 @@ class IconManager @Inject constructor( entry.icons.shelfIcon?.let { it.setNotification(entry.sbn, notificationContentDescription) setIcon(entry, normalIconDescriptor, it) setIcon(entry, sensitiveIconDescriptor, it) } entry.icons.aodIcon?.let { Loading @@ -173,7 +176,8 @@ class IconManager @Inject constructor( @Throws(InflationException::class) private fun getIconDescriptors(entry: NotificationEntry): Pair<StatusBarIcon, StatusBarIcon> { val iconDescriptor = getIconDescriptor(entry, redact = false) val sensitiveDescriptor = if (entry.isSensitive) { val sensitiveDescriptor = if (entry.isSensitive) { getIconDescriptor(entry, redact = true) } else { iconDescriptor Loading Loading @@ -201,10 +205,11 @@ class IconManager @Inject constructor( createPeopleAvatar(entry) } else { n.smallIcon }) ?: throw InflationException( "No icon in notification from " + entry.sbn.packageName) }) ?: throw InflationException("No icon in notification from " + entry.sbn.packageName) val ic = StatusBarIcon( val ic = StatusBarIcon( entry.sbn.user, entry.sbn.packageName, icon, Loading Loading @@ -282,8 +287,8 @@ class IconManager @Inject constructor( /** * Determines if this icon shows a conversation based on the sensitivity of the icon, its * context and the user's indicated sensitivity preference. If we're using a fall back icon * of the small icon, we don't consider this to be showing a conversation * context and the user's indicated sensitivity preference. If we're using a fall back icon of * the small icon, we don't consider this to be showing a conversation * * @param iconView The icon that shows the conversation. */ Loading @@ -295,7 +300,8 @@ class IconManager @Inject constructor( val usedInSensitiveContext = iconView === entry.icons.shelfIcon || iconView === entry.icons.aodIcon val isSmallIcon = iconDescriptor.icon.equals(entry.sbn.notification.smallIcon) return isImportantConversation(entry) && !isSmallIcon && return isImportantConversation(entry) && !isSmallIcon && (!usedInSensitiveContext || !entry.isSensitive) } Loading Loading @@ -323,8 +329,8 @@ private const val TAG = "IconManager" interface ConversationIconManager { /** * Sets the complete current set of notification keys which should (for the purposes of icon * presentation) be considered unimportant. This tells the icon manager to remove the avatar * of a group from which the priority notification has been removed. * presentation) be considered unimportant. This tells the icon manager to remove the avatar of * a group from which the priority notification has been removed. */ fun setUnimportantConversations(keys: Collection<String>) } packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/icon/IconManagerTest.kt +14 −0 Original line number Diff line number Diff line Loading @@ -166,6 +166,20 @@ class IconManagerTest : SysuiTestCase() { assertThat(entry?.icons?.aodIcon?.sourceIcon).isEqualTo(smallIc) } @Test fun testUpdateIcons_sensitiveImportantConversation() { val entry = notificationEntry(hasShortcut = true, hasMessageSenderIcon = true, hasLargeIcon = false) entry?.setSensitive(true, true) entry?.channel?.isImportantConversation = true entry?.let { iconManager.createIcons(it) } // Updating the icons after creation shouldn't break anything entry?.let { iconManager.updateIcons(it) } assertThat(entry?.icons?.statusBarIcon?.sourceIcon).isEqualTo(shortcutIc) assertThat(entry?.icons?.shelfIcon?.sourceIcon).isEqualTo(smallIc) assertThat(entry?.icons?.aodIcon?.sourceIcon).isEqualTo(smallIc) } @Test fun testUpdateIcons_sensitivityChange() { val entry = Loading Loading
packages/SystemUI/src/com/android/systemui/statusbar/notification/icon/IconManager.kt +97 −91 Original line number Diff line number Diff line Loading @@ -48,7 +48,9 @@ import javax.inject.Inject * Long-term, it should probably live somewhere in the content inflation pipeline. */ @SysUISingleton class IconManager @Inject constructor( class IconManager @Inject constructor( private val notifCollection: CommonNotifCollection, private val launcherApps: LauncherApps, private val iconBuilder: IconBuilder Loading @@ -59,7 +61,8 @@ class IconManager @Inject constructor( notifCollection.addCollectionListener(entryListener) } private val entryListener = object : NotifCollectionListener { private val entryListener = object : NotifCollectionListener { override fun onEntryInit(entry: NotificationEntry) { entry.addOnSensitivityChangedListener(sensitivityListener) } Loading @@ -74,15 +77,14 @@ class IconManager @Inject constructor( } } private val sensitivityListener = NotificationEntry.OnSensitivityChangedListener { entry -> updateIconsSafe(entry) } private val sensitivityListener = NotificationEntry.OnSensitivityChangedListener { entry -> updateIconsSafe(entry) } private fun recalculateForImportantConversationChange() { for (entry in notifCollection.allNotifs) { val isImportant = isImportantConversation(entry) if (entry.icons.areIconsAvailable && isImportant != entry.icons.isImportantConversation if ( entry.icons.areIconsAvailable && isImportant != entry.icons.isImportantConversation ) { updateIconsSafe(entry) } Loading @@ -97,7 +99,8 @@ class IconManager @Inject constructor( * @throws InflationException Exception if required icons are not valid or specified */ @Throws(InflationException::class) fun createIcons(entry: NotificationEntry) = traceSection("IconManager.createIcons") { fun createIcons(entry: NotificationEntry) = traceSection("IconManager.createIcons") { // Construct the status bar icon view. val sbIcon = iconBuilder.createIconView(entry) sbIcon.scaleType = ImageView.ScaleType.CENTER_INSIDE Loading Loading @@ -133,7 +136,8 @@ class IconManager @Inject constructor( * @throws InflationException Exception if required icons are not valid or specified */ @Throws(InflationException::class) fun updateIcons(entry: NotificationEntry) = traceSection("IconManager.updateIcons") { fun updateIcons(entry: NotificationEntry) = traceSection("IconManager.updateIcons") { if (!entry.icons.areIconsAvailable) { return@traceSection } Loading @@ -141,9 +145,8 @@ class IconManager @Inject constructor( entry.icons.peopleAvatarDescriptor = null val (normalIconDescriptor, sensitiveIconDescriptor) = getIconDescriptors(entry) val notificationContentDescription = entry.sbn.notification?.let { iconBuilder.getIconContentDescription(it) } val notificationContentDescription = entry.sbn.notification?.let { iconBuilder.getIconContentDescription(it) } entry.icons.statusBarIcon?.let { it.setNotification(entry.sbn, notificationContentDescription) Loading @@ -152,7 +155,7 @@ class IconManager @Inject constructor( entry.icons.shelfIcon?.let { it.setNotification(entry.sbn, notificationContentDescription) setIcon(entry, normalIconDescriptor, it) setIcon(entry, sensitiveIconDescriptor, it) } entry.icons.aodIcon?.let { Loading @@ -173,7 +176,8 @@ class IconManager @Inject constructor( @Throws(InflationException::class) private fun getIconDescriptors(entry: NotificationEntry): Pair<StatusBarIcon, StatusBarIcon> { val iconDescriptor = getIconDescriptor(entry, redact = false) val sensitiveDescriptor = if (entry.isSensitive) { val sensitiveDescriptor = if (entry.isSensitive) { getIconDescriptor(entry, redact = true) } else { iconDescriptor Loading Loading @@ -201,10 +205,11 @@ class IconManager @Inject constructor( createPeopleAvatar(entry) } else { n.smallIcon }) ?: throw InflationException( "No icon in notification from " + entry.sbn.packageName) }) ?: throw InflationException("No icon in notification from " + entry.sbn.packageName) val ic = StatusBarIcon( val ic = StatusBarIcon( entry.sbn.user, entry.sbn.packageName, icon, Loading Loading @@ -282,8 +287,8 @@ class IconManager @Inject constructor( /** * Determines if this icon shows a conversation based on the sensitivity of the icon, its * context and the user's indicated sensitivity preference. If we're using a fall back icon * of the small icon, we don't consider this to be showing a conversation * context and the user's indicated sensitivity preference. If we're using a fall back icon of * the small icon, we don't consider this to be showing a conversation * * @param iconView The icon that shows the conversation. */ Loading @@ -295,7 +300,8 @@ class IconManager @Inject constructor( val usedInSensitiveContext = iconView === entry.icons.shelfIcon || iconView === entry.icons.aodIcon val isSmallIcon = iconDescriptor.icon.equals(entry.sbn.notification.smallIcon) return isImportantConversation(entry) && !isSmallIcon && return isImportantConversation(entry) && !isSmallIcon && (!usedInSensitiveContext || !entry.isSensitive) } Loading Loading @@ -323,8 +329,8 @@ private const val TAG = "IconManager" interface ConversationIconManager { /** * Sets the complete current set of notification keys which should (for the purposes of icon * presentation) be considered unimportant. This tells the icon manager to remove the avatar * of a group from which the priority notification has been removed. * presentation) be considered unimportant. This tells the icon manager to remove the avatar of * a group from which the priority notification has been removed. */ fun setUnimportantConversations(keys: Collection<String>) }
packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/icon/IconManagerTest.kt +14 −0 Original line number Diff line number Diff line Loading @@ -166,6 +166,20 @@ class IconManagerTest : SysuiTestCase() { assertThat(entry?.icons?.aodIcon?.sourceIcon).isEqualTo(smallIc) } @Test fun testUpdateIcons_sensitiveImportantConversation() { val entry = notificationEntry(hasShortcut = true, hasMessageSenderIcon = true, hasLargeIcon = false) entry?.setSensitive(true, true) entry?.channel?.isImportantConversation = true entry?.let { iconManager.createIcons(it) } // Updating the icons after creation shouldn't break anything entry?.let { iconManager.updateIcons(it) } assertThat(entry?.icons?.statusBarIcon?.sourceIcon).isEqualTo(shortcutIc) assertThat(entry?.icons?.shelfIcon?.sourceIcon).isEqualTo(smallIc) assertThat(entry?.icons?.aodIcon?.sourceIcon).isEqualTo(smallIc) } @Test fun testUpdateIcons_sensitivityChange() { val entry = Loading