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

Commit f28bd2e8 authored by Liran Binyamin's avatar Liran Binyamin
Browse files

Wrap BubbleBarLocation and UpdateSource in an object

This CL introduces an object that wraps the location and the update
source to simplify an API that takes an optional location update
request.

Bug: 407475117
Flag: com.android.wm.shell.enable_create_any_bubble
Test: builds
Change-Id: I0d5c85839415f2b37fc9dcbbe0bca905dc9ffa4d
parent 988def1e
Loading
Loading
Loading
Loading
+17 −15
Original line number Diff line number Diff line
@@ -19,13 +19,11 @@ import android.annotation.IntDef
import android.os.Parcel
import android.os.Parcelable

/**
 * The location of the bubble bar.
 */
/** The location of the bubble bar. */
enum class BubbleBarLocation : Parcelable {
    /**
     * Place bubble bar at the default location for the chosen system language.
     * If an RTL language is used, it is on the left. Otherwise on the right.
     * Place bubble bar at the default location for the chosen system language. If an RTL language
     * is used, it is on the left. Otherwise on the right.
     */
    DEFAULT,
    /** Default bubble bar location is overridden. Place bubble bar on the left. */
@@ -33,9 +31,7 @@ enum class BubbleBarLocation : Parcelable {
    /** Default bubble bar location is overridden. Place bubble bar on the right. */
    RIGHT;

    /**
     * Returns whether bubble bar is pinned to the left edge or right edge.
     */
    /** Returns whether bubble bar is pinned to the left edge or right edge. */
    fun isOnLeft(isRtl: Boolean): Boolean {
        if (this == DEFAULT) {
            return isRtl
@@ -53,7 +49,8 @@ enum class BubbleBarLocation : Parcelable {

    companion object {
        @JvmField
        val CREATOR = object : Parcelable.Creator<BubbleBarLocation> {
        val CREATOR =
            object : Parcelable.Creator<BubbleBarLocation> {
                override fun createFromParcel(parcel: Parcel): BubbleBarLocation {
                    return parcel.readString()?.let { valueOf(it) } ?: DEFAULT
                }
@@ -71,7 +68,9 @@ enum class BubbleBarLocation : Parcelable {
            second: BubbleBarLocation?,
            isRtl: Boolean
        ): Boolean {
            return first != null && second != null && first.isOnLeft(isRtl) != second.isOnLeft(isRtl)
            return first != null &&
                second != null &&
                first.isOnLeft(isRtl) != second.isOnLeft(isRtl)
        }
    }

@@ -114,4 +113,7 @@ enum class BubbleBarLocation : Parcelable {
            const val DRAG_TASK = 8
        }
    }

    /** A request to update the location of the bubble bar. */
    data class UpdateLocationRequest(val location: BubbleBarLocation, @UpdateSource val source: Int)
}
+32 −13
Original line number Diff line number Diff line
@@ -128,6 +128,7 @@ 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.BubbleBarLocation;
import com.android.wm.shell.shared.bubbles.BubbleBarLocation.UpdateLocationRequest;
import com.android.wm.shell.shared.bubbles.BubbleBarLocation.UpdateSource;
import com.android.wm.shell.shared.bubbles.BubbleBarUpdate;
import com.android.wm.shell.shared.bubbles.BubbleDropTargetBoundsProvider;
@@ -1668,7 +1669,11 @@ public class BubbleController implements ConfigurationChangeListener,
        if (!BubbleAnythingFlagHelper.enableCreateAnyBubble()) return;
        Bubble b = mBubbleData.getOrCreateBubble(info); // Removes from overflow
        ProtoLog.v(WM_SHELL_BUBBLES, "expandStackAndSelectBubble - shortcut=%s", info);
        expandStackAndSelectAppBubble(b, bubbleBarLocation, UpdateSource.APP_ICON_DRAG);
        UpdateLocationRequest updateLocationRequest =
                bubbleBarLocation == null
                        ? null
                        : new UpdateLocationRequest(bubbleBarLocation, UpdateSource.APP_ICON_DRAG);
        expandStackAndSelectAppBubble(b, updateLocationRequest);
    }

    /**
@@ -1681,7 +1686,11 @@ public class BubbleController implements ConfigurationChangeListener,
        if (!BubbleAnythingFlagHelper.enableCreateAnyBubble()) return;
        Bubble b = mBubbleData.getOrCreateBubble(intent, user); // Removes from overflow
        ProtoLog.v(WM_SHELL_BUBBLES, "expandStackAndSelectBubble - intent=%s", intent);
        expandStackAndSelectAppBubble(b, bubbleBarLocation, UpdateSource.APP_ICON_DRAG);
        UpdateLocationRequest updateLocationRequest =
                bubbleBarLocation == null
                        ? null
                        : new UpdateLocationRequest(bubbleBarLocation, UpdateSource.APP_ICON_DRAG);
        expandStackAndSelectAppBubble(b, updateLocationRequest);
    }

    /**
@@ -1696,20 +1705,31 @@ public class BubbleController implements ConfigurationChangeListener,
        Bubble b = mBubbleData.getOrCreateBubble(pendingIntent, user); // Removes from overflow
        ProtoLog.v(WM_SHELL_BUBBLES, "expandStackAndSelectBubble - pendingIntent=%s",
                pendingIntent);
        expandStackAndSelectAppBubble(b, bubbleBarLocation, UpdateSource.APP_ICON_DRAG);
        UpdateLocationRequest updateLocationRequest =
                bubbleBarLocation == null
                        ? null
                        : new UpdateLocationRequest(bubbleBarLocation, UpdateSource.APP_ICON_DRAG);
        expandStackAndSelectAppBubble(b, updateLocationRequest);
    }

    void expandStackAndSelectAppBubble(Bubble b, @Nullable BubbleBarLocation bubbleBarLocation,
            @UpdateSource int source) {
    void expandStackAndSelectAppBubble(Bubble b) {
        expandStackAndSelectAppBubble(b, /* updateLocationRequest= */ null);
    }

    void expandStackAndSelectAppBubble(Bubble b,
            @Nullable UpdateLocationRequest updateLocationRequest) {
        if (!BubbleAnythingFlagHelper.enableCreateAnyBubble()) return;
        BubbleBarLocation updateLocation = isShowingAsBubbleBar() ? bubbleBarLocation : null;
        if (updateLocation != null) {
        BubbleBarLocation location =
                isShowingAsBubbleBar() && updateLocationRequest != null
                        ? updateLocationRequest.getLocation()
                        : null;
        if (location != null) {
            // does not update the bubble bar location of the bubble bar, just expanded view
            updateExpandedViewForBubbleBarLocation(updateLocation, source);
            updateExpandedViewForBubbleBarLocation(location, updateLocationRequest.getSource());
        }
        if (b.isInflated()) {
            // mBubbleData should be updated with the new location to update the bubble bar location
            mBubbleData.setSelectedBubbleAndExpandStack(b, updateLocation);
            mBubbleData.setSelectedBubbleAndExpandStack(b, location);
        } else {
            b.enable(Notification.BubbleMetadata.FLAG_AUTO_EXPAND_BUBBLE);

@@ -1717,10 +1737,9 @@ public class BubbleController implements ConfigurationChangeListener,
                ensureBubbleViewsAndWindowCreated();
                mBubbleTransitions.startLaunchIntoOrConvertToBubble(b, mExpandedViewManager,
                        mBubbleTaskViewFactory, mBubblePositioner, mStackView, mLayerView,
                        mBubbleIconFactory, mInflateSynchronously, bubbleBarLocation);
                        mBubbleIconFactory, mInflateSynchronously, location);
            } else {
                inflateAndAdd(b, /* suppressFlyout= */ true, /* showInShade= */ false,
                        updateLocation);
                inflateAndAdd(b, /* suppressFlyout= */ true, /* showInShade= */ false, location);
            }
        }
    }
@@ -2383,7 +2402,7 @@ public class BubbleController implements ConfigurationChangeListener,
        b.setIsBubble(isBubble);
        if (b.isApp() && isBubble) {
            Bubble bubble = mBubbleData.getOrCreateBubble(null, b);
            expandStackAndSelectAppBubble(bubble, null, UpdateSource.DRAG_BUBBLE);
            expandStackAndSelectAppBubble(bubble);
            return;
        }
        mSysuiProxy.getPendingOrActiveEntry(b.getKey(), (entry) -> {
+2 −5
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.content.Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED;

import static com.android.wm.shell.bubbles.Bubbles.DISMISS_NO_LONGER_BUBBLE;
import static com.android.wm.shell.shared.bubbles.BubbleBarLocation.UpdateSource.A11Y_ACTION_BUBBLE;

import android.annotation.BinderThread;
import android.annotation.Nullable;
@@ -97,8 +96,7 @@ public class BubbleMultitaskingDelegate extends IMultitaskingDelegate.Stub {
                            Slog.d(TAG, "Created a collapsed bubble");
                        }
                    } else {
                        mController.expandStackAndSelectAppBubble(b, null /* bubbleBarLocation */,
                                A11Y_ACTION_BUBBLE); // Any update source - location doesn't change
                        mController.expandStackAndSelectAppBubble(b);
                        if (DEBUG) {
                            Slog.d(TAG, "Created an expanded bubble");
                        }
@@ -126,8 +124,7 @@ public class BubbleMultitaskingDelegate extends IMultitaskingDelegate.Stub {
                        }
                    } else {
                        final Bubble bubble = getBubbleWithToken(token);
                        mController.expandStackAndSelectAppBubble(bubble,
                                null /* bubbleBarLocation */, A11Y_ACTION_BUBBLE);
                        mController.expandStackAndSelectAppBubble(bubble);
                        if (DEBUG) {
                            Slog.d(TAG, "Expanded bubbles");
                        }