Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 58dc5197 authored by Mady Mellor's avatar Mady Mellor
Browse files

Fix up bubble images from experimental bubbles

* If we're using the small icon make sure to tint it
* If there's a person try to use the icon from message style layout, this
  requires us to add the bubble after the notification has been inflated by
  changing onPendingEntryAdded to onNotificationAdded, this should
  be fine for bubbles / no big difference between these.

Bug: 146233974
Test: atest BubbleControllerTest
Test: manual:
      1) create bubble from telegram user without an image
      => observe that the image looks like what's in the notification
      2) create bubble from snapchat
      => observe that the small notification icon is used & tinted
Change-Id: I67c70619824912b2cbcbcb21df6cd219cc8796c0
parent 330ef764
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -103,7 +103,6 @@ import java.lang.annotation.Target;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.function.Consumer;

import javax.inject.Inject;
@@ -725,7 +724,7 @@ public class BubbleController implements ConfigurationController.ConfigurationLi
    @SuppressWarnings("FieldCanBeLocal")
    private final NotificationEntryListener mEntryListener = new NotificationEntryListener() {
        @Override
        public void onPendingEntryAdded(NotificationEntry entry) {
        public void onNotificationAdded(NotificationEntry entry) {
            boolean previouslyUserCreated = mUserCreatedBubbles.contains(entry.getKey());
            boolean wasAdjusted = BubbleExperimentConfig.adjustForExperiments(
                    mContext, entry, previouslyUserCreated);
+25 −5
Original line number Diff line number Diff line
@@ -32,6 +32,9 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.LauncherApps;
import android.content.pm.ShortcutInfo;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
import android.os.Bundle;
import android.os.Parcelable;
@@ -39,8 +42,11 @@ import android.os.UserHandle;
import android.provider.Settings;
import android.util.Log;

import com.android.internal.graphics.ColorUtils;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.ContrastColorUtil;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.people.PeopleHubNotificationListenerKt;

import java.util.ArrayList;
import java.util.Arrays;
@@ -225,15 +231,29 @@ public class BubbleExperimentConfig {
        List<Person> personList = getPeopleFromNotification(entry);
        if (personList.size() > 0) {
            final Person person = personList.get(0);

            if (person != null) {
                icon = person.getIcon();
                if (icon == null) {
                    // Lets try and grab the icon constructed by the layout
                    Drawable d = PeopleHubNotificationListenerKt.extractAvatarFromRow(entry);
                    if (d instanceof  BitmapDrawable) {
                        icon = Icon.createWithBitmap(((BitmapDrawable) d).getBitmap());
                    }
                }
            }
        }
        if (icon == null) {
            icon = notification.getLargeIcon() != null
                    ? notification.getLargeIcon()
                    : notification.getSmallIcon();
            boolean shouldTint = notification.getLargeIcon() == null;
            icon = shouldTint
                    ? notification.getSmallIcon()
                    : notification.getLargeIcon();
            if (shouldTint) {
                int notifColor = entry.getSbn().getNotification().color;
                notifColor = ColorUtils.setAlphaComponent(notifColor, 255);
                notifColor = ContrastColorUtil.findContrastColor(notifColor, Color.WHITE,
                        true /* findFg */, 3f);
                icon.setTint(notifColor);
            }
        }
        if (intent != null) {
            return new Notification.BubbleMetadata.Builder()
@@ -283,7 +303,7 @@ public class BubbleExperimentConfig {
    }

    static boolean isShortcutIntent(PendingIntent intent) {
        return intent.equals(sDummyShortcutIntent);
        return intent != null && intent.equals(sDummyShortcutIntent);
    }

    static List<Person> getPeopleFromNotification(NotificationEntry entry) {
+1 −1
Original line number Diff line number Diff line
@@ -249,7 +249,7 @@ private fun addBadgeToDrawable(
    }
}

private fun extractAvatarFromRow(entry: NotificationEntry): Drawable? =
fun extractAvatarFromRow(entry: NotificationEntry): Drawable? =
        entry.row
                ?.childrenWithId(R.id.expanded)
                ?.mapNotNull { it as? ViewGroup }
+18 −18
Original line number Diff line number Diff line
@@ -263,7 +263,7 @@ public class BubbleControllerTest extends SysuiTestCase {

    @Test
    public void testRemoveBubble_withDismissedNotif() {
        mEntryListener.onPendingEntryAdded(mRow.getEntry());
        mEntryListener.onNotificationAdded(mRow.getEntry());
        mBubbleController.updateBubble(mRow.getEntry());

        assertTrue(mBubbleController.hasBubbles());
@@ -306,7 +306,7 @@ public class BubbleControllerTest extends SysuiTestCase {
        assertFalse(mBubbleController.isStackExpanded());

        // Mark it as a bubble and add it explicitly
        mEntryListener.onPendingEntryAdded(mRow.getEntry());
        mEntryListener.onNotificationAdded(mRow.getEntry());
        mBubbleController.updateBubble(mRow.getEntry());

        // We should have bubbles & their notifs should not be suppressed
@@ -336,8 +336,8 @@ public class BubbleControllerTest extends SysuiTestCase {
    @Test
    public void testCollapseAfterChangingExpandedBubble() {
        // Mark it as a bubble and add it explicitly
        mEntryListener.onPendingEntryAdded(mRow.getEntry());
        mEntryListener.onPendingEntryAdded(mRow2.getEntry());
        mEntryListener.onNotificationAdded(mRow.getEntry());
        mEntryListener.onNotificationAdded(mRow2.getEntry());
        mBubbleController.updateBubble(mRow.getEntry());
        mBubbleController.updateBubble(mRow2.getEntry());

@@ -379,7 +379,7 @@ public class BubbleControllerTest extends SysuiTestCase {
    @Test
    public void testExpansionRemovesShowInShadeAndDot() {
        // Mark it as a bubble and add it explicitly
        mEntryListener.onPendingEntryAdded(mRow.getEntry());
        mEntryListener.onNotificationAdded(mRow.getEntry());
        mBubbleController.updateBubble(mRow.getEntry());

        // We should have bubbles & their notifs should not be suppressed
@@ -405,7 +405,7 @@ public class BubbleControllerTest extends SysuiTestCase {
    @Test
    public void testUpdateWhileExpanded_DoesntChangeShowInShadeAndDot() {
        // Mark it as a bubble and add it explicitly
        mEntryListener.onPendingEntryAdded(mRow.getEntry());
        mEntryListener.onNotificationAdded(mRow.getEntry());
        mBubbleController.updateBubble(mRow.getEntry());

        // We should have bubbles & their notifs should not be suppressed
@@ -441,8 +441,8 @@ public class BubbleControllerTest extends SysuiTestCase {
    @Test
    public void testRemoveLastExpandedCollapses() {
        // Mark it as a bubble and add it explicitly
        mEntryListener.onPendingEntryAdded(mRow.getEntry());
        mEntryListener.onPendingEntryAdded(mRow2.getEntry());
        mEntryListener.onNotificationAdded(mRow.getEntry());
        mEntryListener.onNotificationAdded(mRow2.getEntry());
        mBubbleController.updateBubble(mRow.getEntry());
        mBubbleController.updateBubble(mRow2.getEntry());
        verify(mBubbleStateChangeListener).onHasBubblesChanged(true);
@@ -485,7 +485,7 @@ public class BubbleControllerTest extends SysuiTestCase {
                Notification.BubbleMetadata.FLAG_AUTO_EXPAND_BUBBLE, false /* enableFlag */);

        // Add the auto expand bubble
        mEntryListener.onPendingEntryAdded(mRow.getEntry());
        mEntryListener.onNotificationAdded(mRow.getEntry());
        mBubbleController.updateBubble(mRow.getEntry());

        // Expansion shouldn't change
@@ -503,7 +503,7 @@ public class BubbleControllerTest extends SysuiTestCase {
                Notification.BubbleMetadata.FLAG_AUTO_EXPAND_BUBBLE, true /* enableFlag */);

        // Add the auto expand bubble
        mEntryListener.onPendingEntryAdded(mRow.getEntry());
        mEntryListener.onNotificationAdded(mRow.getEntry());
        mBubbleController.updateBubble(mRow.getEntry());

        // Expansion should change
@@ -521,7 +521,7 @@ public class BubbleControllerTest extends SysuiTestCase {
                Notification.BubbleMetadata.FLAG_SUPPRESS_NOTIFICATION, true /* enableFlag */);

        // Add the suppress notif bubble
        mEntryListener.onPendingEntryAdded(mRow.getEntry());
        mEntryListener.onNotificationAdded(mRow.getEntry());
        mBubbleController.updateBubble(mRow.getEntry());

        // Notif should be suppressed because we were foreground
@@ -566,7 +566,7 @@ public class BubbleControllerTest extends SysuiTestCase {
    public void testExpandStackAndSelectBubble_removedFirst() {
        final String key = mRow.getEntry().getKey();

        mEntryListener.onPendingEntryAdded(mRow.getEntry());
        mEntryListener.onNotificationAdded(mRow.getEntry());
        mBubbleController.updateBubble(mRow.getEntry());

        // Simulate notification cancellation.
@@ -578,7 +578,7 @@ public class BubbleControllerTest extends SysuiTestCase {

    @Test
    public void testMarkNewNotificationAsShowInShade() {
        mEntryListener.onPendingEntryAdded(mRow.getEntry());
        mEntryListener.onNotificationAdded(mRow.getEntry());
        assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade(
                mRow.getEntry().getKey()));

@@ -588,7 +588,7 @@ public class BubbleControllerTest extends SysuiTestCase {

    @Test
    public void testAddNotif_notBubble() {
        mEntryListener.onPendingEntryAdded(mNonBubbleNotifRow.getEntry());
        mEntryListener.onNotificationAdded(mNonBubbleNotifRow.getEntry());
        mEntryListener.onPreEntryUpdated(mNonBubbleNotifRow.getEntry());

        verify(mBubbleStateChangeListener, never()).onHasBubblesChanged(anyBoolean());
@@ -633,7 +633,7 @@ public class BubbleControllerTest extends SysuiTestCase {

    @Test
    public void testRemoveBubble_succeeds_appCancel() {
        mEntryListener.onPendingEntryAdded(mRow.getEntry());
        mEntryListener.onNotificationAdded(mRow.getEntry());
        mBubbleController.updateBubble(mRow.getEntry());

        assertTrue(mBubbleController.hasBubbles());
@@ -648,7 +648,7 @@ public class BubbleControllerTest extends SysuiTestCase {

    @Test
    public void removeBubble_fails_clearAll()  {
        mEntryListener.onPendingEntryAdded(mRow.getEntry());
        mEntryListener.onNotificationAdded(mRow.getEntry());
        mBubbleController.updateBubble(mRow.getEntry());

        assertTrue(mBubbleController.hasBubbles());
@@ -671,7 +671,7 @@ public class BubbleControllerTest extends SysuiTestCase {

    @Test
    public void removeBubble_fails_userDismissNotif() {
        mEntryListener.onPendingEntryAdded(mRow.getEntry());
        mEntryListener.onNotificationAdded(mRow.getEntry());
        mBubbleController.updateBubble(mRow.getEntry());

        assertTrue(mBubbleController.hasBubbles());
@@ -694,7 +694,7 @@ public class BubbleControllerTest extends SysuiTestCase {

    @Test
    public void removeBubble_succeeds_userDismissBubble_userDimissNotif() {
        mEntryListener.onPendingEntryAdded(mRow.getEntry());
        mEntryListener.onNotificationAdded(mRow.getEntry());
        mBubbleController.updateBubble(mRow.getEntry());

        assertTrue(mBubbleController.hasBubbles());