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

Commit 25399261 authored by mpodolian's avatar mpodolian
Browse files

Added handling for shortcuts and pending intents.

Updated BubbleController to support shortcuts and pending intents.

Test: atest BubbleControllerTest
Test: Manual. Have a shortcut and app icons in the taskbar.
Drag and drop both items over the bubble drop zone.
Observe that items are added to the bubble bar.
Video: http://recall/-/gx8ASgewUeUS3QYohfrd1J/fnHDKrNWzJEzRw6rgIm0fG
Flag: com.android.wm.shell.enable_create_any_bubble
Bug: 388894910

Change-Id: I0b050bea64df89f0999ac27622cac5a353f28be3
parent 944d40f2
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -24,4 +24,9 @@ public class DragAndDropConstants {
     * ignore drag events.
     */
    public static final String EXTRA_DISALLOW_HIT_REGION = "DISALLOW_HIT_REGION";

    /**
     * An Intent extra that Launcher can use to specify the {@link android.content.pm.ShortcutInfo}
     */
    public static final String EXTRA_SHORTCUT_INFO = "EXTRA_SHORTCUT_INFO";
}
+33 −0
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ import com.android.launcher3.icons.BubbleIconFactory;
import com.android.wm.shell.Flags;
import com.android.wm.shell.bubbles.bar.BubbleBarExpandedView;
import com.android.wm.shell.bubbles.bar.BubbleBarLayerView;
import com.android.wm.shell.common.ComponentUtils;
import com.android.wm.shell.shared.annotations.ShellBackgroundThread;
import com.android.wm.shell.shared.annotations.ShellMainThread;
import com.android.wm.shell.shared.bubbles.BubbleInfo;
@@ -282,6 +283,29 @@ public class Bubble implements BubbleViewProvider {
        mPackageName = intent.getPackage();
    }

    private Bubble(
            PendingIntent intent,
            UserHandle user,
            String key,
            @ShellMainThread Executor mainExecutor,
            @ShellBackgroundThread Executor bgExecutor) {
        mGroupKey = null;
        mLocusId = null;
        mFlags = 0;
        mUser = user;
        mIcon = null;
        mType = BubbleType.TYPE_APP;
        mKey = key;
        mShowBubbleUpdateDot = false;
        mMainExecutor = mainExecutor;
        mBgExecutor = bgExecutor;
        mTaskId = INVALID_TASK_ID;
        mPendingIntent = intent;
        mIntent = null;
        mDesiredHeight = Integer.MAX_VALUE;
        mPackageName = ComponentUtils.getPackageName(intent);
    }

    private Bubble(ShortcutInfo info, @ShellMainThread Executor mainExecutor,
            @ShellBackgroundThread Executor bgExecutor) {
        mGroupKey = null;
@@ -335,6 +359,15 @@ public class Bubble implements BubbleViewProvider {
                mainExecutor, bgExecutor);
    }

    /** Creates an app bubble. */
    public static Bubble createAppBubble(PendingIntent intent, UserHandle user,
            @ShellMainThread Executor mainExecutor, @ShellBackgroundThread Executor bgExecutor) {
        return new Bubble(intent,
                user,
                /* key= */ getAppBubbleKeyForApp(ComponentUtils.getPackageName(intent), user),
                mainExecutor, bgExecutor);
    }

    /** Creates an app bubble. */
    public static Bubble createAppBubble(Intent intent, UserHandle user, @Nullable Icon icon,
            @ShellMainThread Executor mainExecutor, @ShellBackgroundThread Executor bgExecutor) {
+52 −15
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import android.app.NotificationChannel;
import android.app.PendingIntent;
import android.app.TaskInfo;
import android.content.BroadcastReceiver;
import android.content.ClipDescription;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
@@ -118,6 +119,7 @@ import com.android.wm.shell.shared.bubbles.BubbleBarLocation;
import com.android.wm.shell.shared.bubbles.BubbleBarUpdate;
import com.android.wm.shell.shared.bubbles.BubbleDropTargetBoundsProvider;
import com.android.wm.shell.shared.bubbles.DeviceConfig;
import com.android.wm.shell.shared.draganddrop.DragAndDropConstants;
import com.android.wm.shell.sysui.ConfigurationChangeListener;
import com.android.wm.shell.sysui.ShellCommandHandler;
import com.android.wm.shell.sysui.ShellController;
@@ -872,11 +874,19 @@ public class BubbleController implements ConfigurationChangeListener,
    }

    @Override
    public void onItemDroppedOverBubbleBarDragZone(BubbleBarLocation location, Intent appIntent,
            UserHandle userHandle) {
        if (isShowingAsBubbleBar() && BubbleAnythingFlagHelper.enableCreateAnyBubble()) {
    public void onItemDroppedOverBubbleBarDragZone(BubbleBarLocation location, Intent itemIntent) {
        hideBubbleBarExpandedViewDropTarget();
            expandStackAndSelectBubble(appIntent, userHandle, location);
        ShortcutInfo shortcutInfo = (ShortcutInfo) itemIntent
                .getExtra(DragAndDropConstants.EXTRA_SHORTCUT_INFO);
        if (shortcutInfo != null) {
            expandStackAndSelectBubble(shortcutInfo, location);
            return;
        }
        UserHandle user = (UserHandle) itemIntent.getExtra(Intent.EXTRA_USER);
        PendingIntent pendingIntent = (PendingIntent) itemIntent
                .getExtra(ClipDescription.EXTRA_PENDING_INTENT);
        if (pendingIntent != null && user != null) {
            expandStackAndSelectBubble(pendingIntent, user, location);
        }
    }

@@ -1508,9 +1518,16 @@ public class BubbleController implements ConfigurationChangeListener,
     * Expands and selects a bubble created or found via the provided shortcut info.
     *
     * @param info the shortcut info for the bubble.
     * @param bubbleBarLocation optional location in case bubble bar should be repositioned.
     */
    public void expandStackAndSelectBubble(ShortcutInfo info) {
    public void expandStackAndSelectBubble(ShortcutInfo info,
            @Nullable BubbleBarLocation bubbleBarLocation) {
        if (!BubbleAnythingFlagHelper.enableCreateAnyBubble()) return;
        if (bubbleBarLocation != null) {
            //TODO (b/388894910) combine location update with the setSelectedBubbleAndExpandStack &
            // fix bubble bar flicking
            setBubbleBarLocation(bubbleBarLocation, BubbleBarLocation.UpdateSource.APP_ICON_DRAG);
        }
        Bubble b = mBubbleData.getOrCreateBubble(info); // Removes from overflow
        ProtoLog.v(WM_SHELL_BUBBLES, "expandStackAndSelectBubble - shortcut=%s", info);
        if (b.isInflated()) {
@@ -1526,7 +1543,25 @@ public class BubbleController implements ConfigurationChangeListener,
     *
     * @param intent the intent for the bubble.
     */
    public void expandStackAndSelectBubble(Intent intent, UserHandle user,
    public void expandStackAndSelectBubble(Intent intent, UserHandle user) {
        if (!BubbleAnythingFlagHelper.enableCreateAnyBubble()) return;
        Bubble b = mBubbleData.getOrCreateBubble(intent, user); // Removes from overflow
        ProtoLog.v(WM_SHELL_BUBBLES, "expandStackAndSelectBubble - intent=%s", intent);
        if (b.isInflated()) {
            mBubbleData.setSelectedBubbleAndExpandStack(b);
        } else {
            b.enable(Notification.BubbleMetadata.FLAG_AUTO_EXPAND_BUBBLE);
            inflateAndAdd(b, /* suppressFlyout= */ true, /* showInShade= */ false);
        }
    }

    /**
     * Expands and selects a bubble created or found for this app.
     *
     * @param pendingIntent     the intent for the bubble.
     * @param bubbleBarLocation optional location in case bubble bar should be repositioned.
     */
    public void expandStackAndSelectBubble(PendingIntent pendingIntent, UserHandle user,
            @Nullable BubbleBarLocation bubbleBarLocation) {
        if (!BubbleAnythingFlagHelper.enableCreateAnyBubble()) return;
        if (bubbleBarLocation != null) {
@@ -1534,8 +1569,9 @@ public class BubbleController implements ConfigurationChangeListener,
            // fix bubble bar flicking
            setBubbleBarLocation(bubbleBarLocation, BubbleBarLocation.UpdateSource.APP_ICON_DRAG);
        }
        Bubble b = mBubbleData.getOrCreateBubble(intent, user); // Removes from overflow
        ProtoLog.v(WM_SHELL_BUBBLES, "expandStackAndSelectBubble - intent=%s", intent);
        Bubble b = mBubbleData.getOrCreateBubble(pendingIntent, user);
        ProtoLog.v(WM_SHELL_BUBBLES, "expandStackAndSelectBubble - pendingIntent=%s",
                pendingIntent);
        if (b.isInflated()) {
            mBubbleData.setSelectedBubbleAndExpandStack(b);
        } else {
@@ -2761,13 +2797,13 @@ public class BubbleController implements ConfigurationChangeListener,

        @Override
        public void showShortcutBubble(ShortcutInfo info) {
            mMainExecutor.execute(() -> mController.expandStackAndSelectBubble(info));
            mMainExecutor.execute(() -> mController
                    .expandStackAndSelectBubble(info, /* bubbleBarLocation = */ null));
        }

        @Override
        public void showAppBubble(Intent intent, UserHandle user) {
            mMainExecutor.execute(() -> mController.expandStackAndSelectBubble(intent,
                    user, /* bubbleBarLocation = */ null));
            mMainExecutor.execute(() -> mController.expandStackAndSelectBubble(intent, user));
        }

        @Override
@@ -2988,9 +3024,10 @@ public class BubbleController implements ConfigurationChangeListener,

        @Override
        public void expandStackAndSelectBubble(ShortcutInfo info) {
            mMainExecutor.execute(() -> {
                BubbleController.this.expandStackAndSelectBubble(info);
            });
            mMainExecutor.execute(() ->
                    BubbleController.this
                            .expandStackAndSelectBubble(info, /* bubbleBarLocation = */ null)
            );
        }

        @Override
+10 −0
Original line number Diff line number Diff line
@@ -471,6 +471,16 @@ public class BubbleData {
        return bubbleToReturn;
    }

    Bubble getOrCreateBubble(PendingIntent pendingIntent, UserHandle user) {
        String bubbleKey = Bubble.getAppBubbleKeyForApp(pendingIntent.getCreatorPackage(), user);
        Bubble bubbleToReturn = findAndRemoveBubbleFromOverflow(bubbleKey);
        if (bubbleToReturn == null) {
            bubbleToReturn = Bubble.createAppBubble(pendingIntent, user, mMainExecutor,
                    mBgExecutor);
        }
        return bubbleToReturn;
    }

    Bubble getOrCreateBubble(TaskInfo taskInfo) {
        UserHandle user = UserHandle.of(mCurrentUserId);
        String bubbleKey = Bubble.getAppBubbleKeyForTask(taskInfo);
+18 −9
Original line number Diff line number Diff line
@@ -117,15 +117,24 @@ public class BubbleTaskViewHelper {
                        Context context =
                                mContext.createContextAsUser(
                                        mBubble.getUser(), Context.CONTEXT_RESTRICTED);
                        PendingIntent pi = PendingIntent.getActivity(
                        Intent fillInIntent = null;
                        //first try get pending intent from the bubble
                        PendingIntent pi = mBubble.getPendingIntent();
                        if (pi == null) {
                            // if null - create new one
                            pi = PendingIntent.getActivity(
                                    context,
                                    /* requestCode= */ 0,
                                    mBubble.getIntent()
                                            .addFlags(FLAG_ACTIVITY_MULTIPLE_TASK),
                                PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT,
                                    PendingIntent.FLAG_IMMUTABLE
                                            | PendingIntent.FLAG_UPDATE_CURRENT,
                                    /* options= */ null);
                        mTaskView.startActivity(pi, /* fillInIntent= */ null, options,
                                launchBounds);
                        } else {
                            fillInIntent = new Intent(pi.getIntent());
                            fillInIntent.addFlags(FLAG_ACTIVITY_MULTIPLE_TASK);
                        }
                        mTaskView.startActivity(pi, fillInIntent, options, launchBounds);
                    } else if (isShortcutBubble) {
                        options.setLaunchedFromBubble(true);
                        options.setApplyActivityFlagsForBubbles(true);
Loading