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

Commit 8294a8bd authored by Mady Mellor's avatar Mady Mellor Committed by Android (Google) Code Review
Browse files

Merge changes I4c337195,Id3e95dd9,I3b85ea4d into main

* changes:
  Use the bubble type to determine if the app badge is shown
  Use the type not the null check to identify a shortcut bubble
  Introduce bubble types & clean up some naming
parents 6fc6575d ca346975
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ import org.mockito.kotlin.mock
import org.mockito.kotlin.whenever
import java.util.Optional

/** Tests for [BubbleControllerTest] */
/** Tests for [BubbleController] */
@SmallTest
@RunWith(AndroidJUnit4::class)
class BubbleControllerTest {
@@ -140,7 +140,7 @@ class BubbleControllerTest {

        assertThat(bubbleController.hasBubbles()).isTrue()
        assertThat(bubbleData.getAnyBubbleWithKey(expectedKey)).isNotNull()
        assertThat(bubbleData.getAnyBubbleWithKey(expectedKey)!!.isNoteBubble).isTrue()
        assertThat(bubbleData.getAnyBubbleWithKey(expectedKey)!!.isNote).isTrue()
    }


+3 −3
Original line number Diff line number Diff line
@@ -357,9 +357,9 @@ public class BadgedImageView extends ConstraintLayout {

    void showBadge() {
        Bitmap appBadgeBitmap = mBubble.getAppBadge();
        final boolean isAppLaunchIntent = (mBubble instanceof Bubble)
                && ((Bubble) mBubble).isAppLaunchIntent();
        if (appBadgeBitmap == null || isAppLaunchIntent) {
        final boolean showAppBadge = (mBubble instanceof Bubble)
                && ((Bubble) mBubble).showAppBadge();
        if (appBadgeBitmap == null || !showAppBadge) {
            mAppIcon.setVisibility(GONE);
            return;
        }
+51 −46
Original line number Diff line number Diff line
@@ -56,7 +56,6 @@ import com.android.wm.shell.bubbles.bar.BubbleBarExpandedView;
import com.android.wm.shell.bubbles.bar.BubbleBarLayerView;
import com.android.wm.shell.shared.annotations.ShellBackgroundThread;
import com.android.wm.shell.shared.annotations.ShellMainThread;
import com.android.wm.shell.shared.bubbles.BubbleAnythingFlagHelper;
import com.android.wm.shell.shared.bubbles.BubbleInfo;
import com.android.wm.shell.shared.bubbles.ParcelableFlyoutMessage;
import com.android.wm.shell.taskview.TaskView;
@@ -78,11 +77,19 @@ public class Bubble implements BubbleViewProvider {
    /** A string prefix used in note bubbles' {@link #mKey}. */
    public static final String KEY_NOTE_BUBBLE = "key_note_bubble";

    /** Whether the bubble is an app bubble. */
    private final boolean mIsAppBubble;
    /** The possible types a bubble may be. */
    public enum BubbleType {
        /** Chat is from a notification. */
        TYPE_CHAT,
        /** Notes are from the note taking API. */
        TYPE_NOTE,
        /** Shortcuts from bubble anything, based on {@link ShortcutInfo}. */
        TYPE_SHORTCUT,
        /** Apps are from bubble anything. */
        TYPE_APP,
    }

    /** Whether the bubble is a notetaking bubble. */
    private final boolean mIsNoteBubble;
    private final BubbleType mType;

    private final String mKey;
    @Nullable
@@ -221,7 +228,6 @@ public class Bubble implements BubbleViewProvider {
     * Create a bubble with limited information based on given {@link ShortcutInfo}.
     * Note: Currently this is only being used when the bubble is persisted to disk.
     */
    @VisibleForTesting(visibility = PRIVATE)
    public Bubble(@NonNull final String key, @NonNull final ShortcutInfo shortcutInfo,
            final int desiredHeight, final int desiredHeightResId, @Nullable final String title,
            int taskId, @Nullable final String locus, boolean isDismissable,
@@ -248,16 +254,15 @@ public class Bubble implements BubbleViewProvider {
        mBgExecutor = bgExecutor;
        mTaskId = taskId;
        mBubbleMetadataFlagListener = listener;
        mIsAppBubble = false;
        mIsNoteBubble = false;
        // TODO (b/394085999) read/write type to xml
        mType = BubbleType.TYPE_CHAT;
    }

    private Bubble(
            Intent intent,
            UserHandle user,
            @Nullable Icon icon,
            boolean isAppBubble,
            boolean isNoteBubble,
            BubbleType type,
            String key,
            @ShellMainThread Executor mainExecutor,
            @ShellBackgroundThread Executor bgExecutor) {
@@ -266,8 +271,7 @@ public class Bubble implements BubbleViewProvider {
        mFlags = 0;
        mUser = user;
        mIcon = icon;
        mIsAppBubble = isAppBubble;
        mIsNoteBubble = isNoteBubble;
        mType = type;
        mKey = key;
        mShowBubbleUpdateDot = false;
        mMainExecutor = mainExecutor;
@@ -285,8 +289,7 @@ public class Bubble implements BubbleViewProvider {
        mFlags = 0;
        mUser = info.getUserHandle();
        mIcon = info.getIcon();
        mIsAppBubble = false;
        mIsNoteBubble = false;
        mType = BubbleType.TYPE_SHORTCUT;
        mKey = getBubbleKeyForShortcut(info);
        mShowBubbleUpdateDot = false;
        mMainExecutor = mainExecutor;
@@ -310,8 +313,7 @@ public class Bubble implements BubbleViewProvider {
        mFlags = 0;
        mUser = user;
        mIcon = icon;
        mIsAppBubble = true;
        mIsNoteBubble = false;
        mType = BubbleType.TYPE_APP;
        mKey = key;
        mShowBubbleUpdateDot = false;
        mMainExecutor = mainExecutor;
@@ -328,9 +330,8 @@ public class Bubble implements BubbleViewProvider {
        return new Bubble(intent,
                user,
                icon,
                /* isAppBubble= */ true,
                /* isNoteBubble= */ true,
                /* key= */ getNoteBubbleKeyForApp(intent.getPackage(), user),
                BubbleType.TYPE_NOTE,
                getNoteBubbleKeyForApp(intent.getPackage(), user),
                mainExecutor, bgExecutor);
    }

@@ -340,9 +341,8 @@ public class Bubble implements BubbleViewProvider {
        return new Bubble(intent,
                user,
                icon,
                /* isAppBubble= */ true,
                /* isNoteBubble= */ false,
                /* key= */ getAppBubbleKeyForApp(intent.getPackage(), user),
                BubbleType.TYPE_APP,
                getAppBubbleKeyForApp(intent.getPackage(), user),
                mainExecutor, bgExecutor);
    }

@@ -400,13 +400,15 @@ public class Bubble implements BubbleViewProvider {
        return KEY_APP_BUBBLE + ":" + taskInfo.taskId;
    }

    /**
     * Creates a chat bubble based on a notification (contents of {@link BubbleEntry}.
     */
    @VisibleForTesting(visibility = PRIVATE)
    public Bubble(@NonNull final BubbleEntry entry,
            final Bubbles.BubbleMetadataFlagListener listener,
            final Bubbles.PendingIntentCanceledListener intentCancelListener,
            @ShellMainThread Executor mainExecutor, @ShellBackgroundThread Executor bgExecutor) {
        mIsAppBubble = false;
        mIsNoteBubble = false;
        mType = BubbleType.TYPE_CHAT;
        mKey = entry.getKey();
        mGroupKey = entry.getGroupKey();
        mLocusId = entry.getLocusId();
@@ -436,7 +438,7 @@ public class Bubble implements BubbleViewProvider {
                getTitle(),
                getAppName(),
                isImportantConversation(),
                !isAppLaunchIntent(),
                showAppBadge(),
                getParcelableFlyoutMessage());
    }

@@ -1004,13 +1006,6 @@ public class Bubble implements BubbleViewProvider {
        return mIsImportantConversation;
    }

    /**
     * Whether this bubble is conversation
     */
    public boolean isConversation() {
        return null != mShortcutInfo;
    }

    /**
     * Sets whether this notification should be suppressed in the shade.
     */
@@ -1128,14 +1123,10 @@ public class Bubble implements BubbleViewProvider {
    }

    /**
     * Whether this bubble represents the full app, i.e. the intent used is the launch
     * intent for an app. In this case we don't show a badge on the icon.
     * Whether an app badge should be shown for this bubble.
     */
    public boolean isAppLaunchIntent() {
        if (BubbleAnythingFlagHelper.enableCreateAnyBubble() && mIntent != null) {
            return mIntent.hasCategory("android.intent.category.LAUNCHER");
        }
        return false;
    public boolean showAppBadge() {
        return isChat() || isShortcut() || isNote();
    }

    /**
@@ -1162,17 +1153,31 @@ public class Bubble implements BubbleViewProvider {
    }

    /**
     * Returns whether this bubble is from an app (as well as notetaking) versus a notification.
     * Returns whether this bubble is a conversation from the notification API.
     */
    public boolean isChat() {
        return mType == BubbleType.TYPE_CHAT;
    }

    /**
     * Returns whether this bubble is a note from the note taking API.
     */
    public boolean isNote() {
        return mType == BubbleType.TYPE_NOTE;
    }

    /**
     * Returns whether this bubble is a shortcut.
     */
    public boolean isAppBubble() {
        return mIsAppBubble;
    public boolean isShortcut() {
        return mType == BubbleType.TYPE_SHORTCUT;
    }

    /**
     * Returns whether this bubble is specific from the notetaking API.
     * Returns whether this bubble is an app.
     */
    public boolean isNoteBubble() {
        return mIsNoteBubble;
    public boolean isApp() {
        return mType == BubbleType.TYPE_APP;
    }

    /** Creates open app settings intent */
+1 −1
Original line number Diff line number Diff line
@@ -2890,7 +2890,7 @@ public class BubbleController implements ConfigurationChangeListener,
                    mShortcutIdToBubble.put(b.getShortcutId(), b);
                    updateBubbleSuppressedState(b);

                    if (b.isNoteBubble()) {
                    if (b.isNote()) {
                        mNoteBubbleTaskIds.put(b.getKey(), b.getTaskId());
                    }
                }
+1 −1
Original line number Diff line number Diff line
@@ -83,4 +83,4 @@ class BubbleEducationController(private val context: Context) {

/** Convenience extension method to check if the bubble is a conversation bubble */
private val BubbleViewProvider.isConversationBubble: Boolean
    get() = if (this is Bubble) isConversation else false
    get() = if (this is Bubble) isChat else false
Loading