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

Commit c0d7e900 authored by Mady Mellor's avatar Mady Mellor
Browse files

Introduce bubble types & clean up some naming

When creating a bubble, a type is set internally.
It can be chat, note, app, or shortcut.

The type is based on the constructor content.

The constructors are a bit messy and I'll be cleaning
them up in a future change.

This CL adds methods to check the type and updates
some of the other related naming to be more consistent.

In some places isAppBubble was really checking both
app & notes, this is now made more explicit by checking
for both.

Adds tests for the types.

Fixes up a test in BubblesTests where you could make a
non-chat notification-based bubble, which doesn't exist.

Flag: EXEMPT minor refactor
Test: atest BubbleTest
Bug: 390496034
Change-Id: I3b85ea4d607bc81cd5b45632e3b07d372fe30f54
parent 9278bafb
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()
    }


+47 −37
Original line number Diff line number Diff line
@@ -78,11 +78,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 +229,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 +255,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 +272,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 +290,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 +314,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 +331,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 +342,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 +401,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();
@@ -1004,13 +1007,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.
     */
@@ -1162,17 +1158,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
@@ -2869,7 +2869,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
+3 −2
Original line number Diff line number Diff line
@@ -230,7 +230,8 @@ public class BubbleExpandedView extends LinearLayout {
                            || (mBubble.getShortcutInfo() != null
                            && BubbleAnythingFlagHelper.enableCreateAnyBubble()));

                    if (mBubble.isAppBubble()) {
                    // TODO - currently based on type, really it's what the "launch item" is.
                    if (mBubble.isApp() || mBubble.isNote()) {
                        Context context =
                                mContext.createContextAsUser(
                                        mBubble.getUser(), Context.CONTEXT_RESTRICTED);
@@ -284,7 +285,7 @@ public class BubbleExpandedView extends LinearLayout {
            // The taskId is saved to use for removeTask, preventing appearance in recent tasks.
            mTaskId = taskId;

            if (mBubble != null && mBubble.isNoteBubble()) {
            if (mBubble != null && mBubble.isNote()) {
                // Let the controller know sooner what the taskId is.
                mManager.setNoteBubbleTaskId(mBubble.getKey(), mTaskId);
            }
Loading