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

Commit ea7d9389 authored by Steven Ng's avatar Steven Ng
Browse files

Allow callers to specify UserHandle when launching an intent in a Bubble

Test: atest SystemUITests:com.android.systemui.wmshell.BubblesTest
atest SystemUITests:com.android.systemui.notetask.NoteTaskControllerTest
Fix: 268351693

Change-Id: I853102bb1e6866d1efde19eb65cbd33680ea753b
parent 81a6dbd3
Loading
Loading
Loading
Loading
+9 −8
Original line number Diff line number Diff line
@@ -1028,19 +1028,21 @@ public class BubbleController implements ConfigurationChangeListener {
     * the bubble or bubble stack.
     *
     * Some notes:
     *    - Only one app bubble is supported at a time
     *    - Only one app bubble is supported at a time, regardless of users. Multi-users support is
     *      tracked in b/273533235.
     *    - Calling this method with a different intent than the existing app bubble will do nothing
     *
     * @param intent the intent to display in the bubble expanded view.
     * @param user the {@link UserHandle} of the user to start this activity for.
     */
    public void showOrHideAppBubble(Intent intent) {
    public void showOrHideAppBubble(Intent intent, UserHandle user) {
        if (intent == null || intent.getPackage() == null) {
            Log.w(TAG, "App bubble failed to show, invalid intent: " + intent
                    + ((intent != null) ? " with package: " + intent.getPackage() : " "));
            return;
        }

        PackageManager packageManager = getPackageManagerForUser(mContext, mCurrentUserId);
        PackageManager packageManager = getPackageManagerForUser(mContext, user.getIdentifier());
        if (!isResizableActivity(intent, packageManager, KEY_APP_BUBBLE)) return;

        Bubble existingAppBubble = mBubbleData.getBubbleInStackWithKey(KEY_APP_BUBBLE);
@@ -1061,7 +1063,7 @@ public class BubbleController implements ConfigurationChangeListener {
            }
        } else {
            // App bubble does not exist, lets add and expand it
            Bubble b = new Bubble(intent, UserHandle.of(mCurrentUserId), mMainExecutor);
            Bubble b = new Bubble(intent, user, mMainExecutor);
            b.setShouldAutoExpand(true);
            inflateAndAdd(b, /* suppressFlyout= */ true, /* showInShade= */ false);
        }
@@ -1869,10 +1871,9 @@ public class BubbleController implements ConfigurationChangeListener {
        }

        @Override
        public void showOrHideAppBubble(Intent intent) {
            mMainExecutor.execute(() -> {
                BubbleController.this.showOrHideAppBubble(intent);
            });
        public void showOrHideAppBubble(Intent intent, UserHandle user) {
            mMainExecutor.execute(
                    () -> BubbleController.this.showOrHideAppBubble(intent, user));
        }

        @Override
+7 −2
Original line number Diff line number Diff line
@@ -236,12 +236,17 @@ public class BubbleExpandedView extends LinearLayout {
                    fillInIntent.addFlags(FLAG_ACTIVITY_MULTIPLE_TASK);

                    if (mBubble.isAppBubble()) {
                        PendingIntent pi = PendingIntent.getActivity(mContext, 0,
                        Context context =
                                mContext.createContextAsUser(
                                        mBubble.getUser(), Context.CONTEXT_RESTRICTED);
                        PendingIntent pi = PendingIntent.getActivity(
                                context,
                                /* requestCode= */ 0,
                                mBubble.getAppBubbleIntent()
                                        .addFlags(FLAG_ACTIVITY_NEW_DOCUMENT)
                                        .addFlags(FLAG_ACTIVITY_MULTIPLE_TASK),
                                PendingIntent.FLAG_IMMUTABLE,
                                null);
                                /* options= */ null);
                        mTaskView.startActivity(pi, /* fillInIntent= */ null, options,
                                launchBounds);
                    } else if (!mIsOverflow && mBubble.hasMetadataShortcutId()) {
+4 −2
Original line number Diff line number Diff line
@@ -129,12 +129,14 @@ public interface Bubbles {
     * the bubble or bubble stack.
     *
     * Some notes:
     *    - Only one app bubble is supported at a time
     *    - Only one app bubble is supported at a time, regardless of users. Multi-users support is
     *      tracked in b/273533235.
     *    - Calling this method with a different intent than the existing app bubble will do nothing
     *
     * @param intent the intent to display in the bubble expanded view.
     * @param user the {@link UserHandle} of the user to start this activity for.
     */
    void showOrHideAppBubble(Intent intent);
    void showOrHideAppBubble(Intent intent, UserHandle user);

    /** @return true if the specified {@code taskId} corresponds to app bubble's taskId. */
    boolean isAppBubbleTaskId(int taskId);
+1 −2
Original line number Diff line number Diff line
@@ -129,8 +129,7 @@ constructor(
            logDebug { "onShowNoteTask - start: $info" }
            when (info.launchMode) {
                is NoteTaskLaunchMode.AppBubble -> {
                    // TODO(b/267634412, b/268351693): Should use `showOrHideAppBubbleAsUser`
                    bubbles.showOrHideAppBubble(intent)
                    bubbles.showOrHideAppBubble(intent, userTracker.userHandle)
                    // App bubble logging happens on `onBubbleExpandChanged`.
                    logDebug { "onShowNoteTask - opened as app bubble: $info" }
                }
+3 −3
Original line number Diff line number Diff line
@@ -232,7 +232,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() {

        verifyZeroInteractions(context)
        val intentCaptor = argumentCaptor<Intent>()
        verify(bubbles).showOrHideAppBubble(capture(intentCaptor))
        verify(bubbles).showOrHideAppBubble(capture(intentCaptor), eq(userTracker.userHandle))
        intentCaptor.value.let { intent ->
            assertThat(intent.action).isEqualTo(Intent.ACTION_CREATE_NOTE)
            assertThat(intent.`package`).isEqualTo(NOTES_PACKAGE_NAME)
@@ -366,7 +366,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() {
        createNoteTaskController().showNoteTask(entryPoint = NoteTaskEntryPoint.QUICK_AFFORDANCE)

        val intentCaptor = argumentCaptor<Intent>()
        verify(bubbles).showOrHideAppBubble(capture(intentCaptor))
        verify(bubbles).showOrHideAppBubble(capture(intentCaptor), eq(userTracker.userHandle))
        intentCaptor.value.let { intent ->
            assertThat(intent.action).isEqualTo(Intent.ACTION_CREATE_NOTE)
            assertThat(intent.`package`).isEqualTo(NOTES_PACKAGE_NAME)
@@ -389,7 +389,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() {
        createNoteTaskController().showNoteTask(entryPoint = NoteTaskEntryPoint.QUICK_AFFORDANCE)

        val intentCaptor = argumentCaptor<Intent>()
        verify(bubbles).showOrHideAppBubble(capture(intentCaptor))
        verify(bubbles).showOrHideAppBubble(capture(intentCaptor), eq(userTracker.userHandle))
        intentCaptor.value.let { intent ->
            assertThat(intent.action).isEqualTo(Intent.ACTION_CREATE_NOTE)
            assertThat(intent.`package`).isEqualTo(NOTES_PACKAGE_NAME)
Loading