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

Commit 3535df26 authored by Winson Chung's avatar Winson Chung
Browse files

Move activity to fullscreen stack when it is relaunched in PIP.

- Only happens when the caller is not from the same package.

Bug: 33754261
Test: Open a PIP activity, try to launch it again from launcher
Change-Id: I3c364ebe31a7626b9133d9c4c1fafc718c2eecf9
parent 114aeea5
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -31,8 +31,10 @@ oneway interface ITaskStackListener {
     * Called whenever IActivityManager.startActivity is called on an activity that is already
     * running in the pinned stack and the activity is not actually started, but the task is either
     * brought to the front or a new Intent is delivered to it.
     *
     * @param sourceComponent the component name of the activity that initiated the restart attempt
     */
    void onPinnedActivityRestartAttempt();
    void onPinnedActivityRestartAttempt(in ComponentName sourceComponent);

    /**
     * Called whenever the pinned stack is done animating a resize.
+1 −1
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ public abstract class TaskStackListener extends ITaskStackListener.Stub {
    }

    @Override
    public void onPinnedActivityRestartAttempt() throws RemoteException {
    public void onPinnedActivityRestartAttempt(ComponentName sourceComponent) throws RemoteException {
    }

    @Override
+35 −2
Original line number Diff line number Diff line
@@ -16,14 +16,20 @@

package com.android.systemui.pip.phone;

import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
import static android.view.Display.DEFAULT_DISPLAY;

import android.app.ActivityManager;
import android.app.ActivityManager.StackInfo;
import android.app.ActivityOptions;
import android.app.IActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ParceledListSlice;
import android.os.Handler;
import android.os.RemoteException;
import android.os.UserHandle;
import android.util.Log;
import android.view.IPinnedStackController;
import android.view.IPinnedStackListener;
@@ -57,6 +63,9 @@ public class PipManager {
    TaskStackListener mTaskStackListener = new TaskStackListener() {
        @Override
        public void onActivityPinned() {
            if (!checkCurrentUserId(false /* debug */)) {
                return;
            }
            mTouchHandler.onActivityPinned();
        }

@@ -66,8 +75,32 @@ public class PipManager {
        }

        @Override
        public void onPinnedActivityRestartAttempt() {
            // TODO(winsonc): Hide the menu and expand the PiP
        public void onPinnedActivityRestartAttempt(ComponentName sourceComponent) {
            if (!checkCurrentUserId(false /* debug */)) {
                return;
            }

            // Expand the activity back to fullscreen only if it was attempted to be restarted from
            // another package than the top activity in the stack
            boolean expandPipToFullscreen = true;
            if (sourceComponent != null) {
                try {
                    StackInfo pinnedStackInfo = mActivityManager.getStackInfo(PINNED_STACK_ID);
                    if (pinnedStackInfo != null && pinnedStackInfo.taskIds != null &&
                            pinnedStackInfo.taskIds.length > 0) {
                        expandPipToFullscreen =
                                !pinnedStackInfo.topActivity.getPackageName().equals(
                                        sourceComponent.getPackageName());
                    }
                } catch (RemoteException e) {
                    Log.w(TAG, "Unable to get pinned stack.");
                }
            }
            if (expandPipToFullscreen) {
                mTouchHandler.expandPinnedStackToFullscreen();
            } else {
                Log.w(TAG, "Can not expand PiP to fullscreen via intent from the same package.");
            }
        }
    };

+1 −1
Original line number Diff line number Diff line
@@ -487,7 +487,7 @@ public class PipTouchHandler implements TunerService.Tunable {
    /**
     * Resizes the pinned stack back to fullscreen.
     */
    private void expandPinnedStackToFullscreen() {
    void expandPinnedStackToFullscreen() {
        BackgroundThread.getHandler().post(() -> {
            try {
                mActivityManager.resizeStack(PINNED_STACK_ID, null /* bounds */,
+5 −25
Original line number Diff line number Diff line
@@ -590,7 +590,7 @@ public class PipManager {
        @Override
        public void onTaskStackChanged() {
            if (DEBUG) Log.d(TAG, "onTaskStackChanged()");
            if (!checkCurrentUserId()) {
            if (!checkCurrentUserId(DEBUG)) {
                return;
            }
            if (mState != STATE_NO_PIP) {
@@ -627,7 +627,7 @@ public class PipManager {
        @Override
        public void onActivityPinned() {
            if (DEBUG) Log.d(TAG, "onActivityPinned()");
            if (!checkCurrentUserId()) {
            if (!checkCurrentUserId(DEBUG)) {
                return;
            }
            StackInfo stackInfo = getPinnedStackInfo();
@@ -658,9 +658,9 @@ public class PipManager {
        }

        @Override
        public void onPinnedActivityRestartAttempt() {
        public void onPinnedActivityRestartAttempt(ComponentName sourceComponent) {
            if (DEBUG) Log.d(TAG, "onPinnedActivityRestartAttempt()");
            if (!checkCurrentUserId()) {
            if (!checkCurrentUserId(DEBUG)) {
                return;
            }
            // If PIPed activity is launched again by Launcher or intent, make it fullscreen.
@@ -670,7 +670,7 @@ public class PipManager {
        @Override
        public void onPinnedStackAnimationEnded() {
            if (DEBUG) Log.d(TAG, "onPinnedStackAnimationEnded()");
            if (!checkCurrentUserId()) {
            if (!checkCurrentUserId(DEBUG)) {
                return;
            }
            switch (mState) {
@@ -693,26 +693,6 @@ public class PipManager {
                    break;
            }
        }

        // {@link android.app.ITaskStackListener} isn't multi-user aware.
        // Check the current uid and current SystemUI's running uid
        // so we can handle the PIP status change only once.
        private boolean checkCurrentUserId() {
            try {
                int processUserId = UserHandle.myUserId();
                int currentUserId = mActivityManager.getCurrentUser().id;
                if (processUserId != currentUserId) {
                    if (DEBUG) {
                        Log.d(TAG, "UID mismatch. SystemUI is running uid=" + processUserId
                            + " and the current user is uid=" + currentUserId);
                    }
                    return false;
                }
            } catch (RemoteException e) {
                Log.w(TAG, "Unable to get current user.");
            }
            return true;
        }
    };

    /**
Loading