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

Commit 9db72481 authored by Wale Ogunwale's avatar Wale Ogunwale Committed by jorgegil@google.com
Browse files

Add support for explicit Auto Pip

Adds a new parameter to PictureInPictureParams that
allows activities to explicitly allow the system to
put them in PIP mode without them having to call
enterPictureInPictureMode().

Test: atest PinnedStackTests#testAutoPipAllowedBypassesExplicitEnterPip
Bug: 163048957
Change-Id: Ib6fda0e231408f2756a4e1b9fda08536889a1be5
parent ae5e7178
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -6188,6 +6188,7 @@ package android.app {
    method public android.app.PictureInPictureParams build();
    method public android.app.PictureInPictureParams.Builder setActions(java.util.List<android.app.RemoteAction>);
    method public android.app.PictureInPictureParams.Builder setAspectRatio(android.util.Rational);
    method @NonNull public android.app.PictureInPictureParams.Builder setAutoEnterAllowed(boolean);
    method public android.app.PictureInPictureParams.Builder setSourceRectHint(android.graphics.Rect);
  }
+46 −3
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.app;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.TestApi;
import android.graphics.Rect;
@@ -46,6 +47,8 @@ public final class PictureInPictureParams implements Parcelable {
        @Nullable
        private Rect mSourceRectHint;

        private boolean mAutoEnterAllowed;

        /**
         * Sets the aspect ratio.  This aspect ratio is defined as the desired width / height, and
         * does not change upon device rotation.
@@ -102,6 +105,25 @@ public final class PictureInPictureParams implements Parcelable {
            return this;
        }

        /**
         * Sets whether the system is allowed to automatically put the activity in
         * picture-in-picture mode without needing/waiting for the activity to call
         * {@link Activity#enterPictureInPictureMode(PictureInPictureParams)}.
         *
         * If true, {@link Activity#onPictureInPictureRequested()} will never be called.
         *
         * This property is false by default.
         * @param autoEnterAllowed {@code true} if the system is allowed to automatically put the
         *                                  activity in picture-in-picture mode.
         *
         * @return this builder instance.
         */
        @NonNull
        public Builder setAutoEnterAllowed(boolean autoEnterAllowed) {
            mAutoEnterAllowed = autoEnterAllowed;
            return this;
        }

        /**
         * @return an immutable {@link PictureInPictureParams} to be used when entering or updating
         * the activity in picture-in-picture.
@@ -111,7 +133,7 @@ public final class PictureInPictureParams implements Parcelable {
         */
        public PictureInPictureParams build() {
            PictureInPictureParams params = new PictureInPictureParams(mAspectRatio, mUserActions,
                    mSourceRectHint);
                    mSourceRectHint, mAutoEnterAllowed);
            return params;
        }
    }
@@ -136,6 +158,11 @@ public final class PictureInPictureParams implements Parcelable {
    @Nullable
    private Rect mSourceRectHint;

    /**
     * Whether the system is allowed to automatically put the activity in picture-in-picture mode.
     */
    private boolean mAutoEnterAllowed;

    /** {@hide} */
    PictureInPictureParams() {
    }
@@ -152,14 +179,18 @@ public final class PictureInPictureParams implements Parcelable {
        if (in.readInt() != 0) {
            mSourceRectHint = Rect.CREATOR.createFromParcel(in);
        }
        if (in.readInt() != 0) {
            mAutoEnterAllowed = in.readBoolean();
        }
    }

    /** {@hide} */
    PictureInPictureParams(Rational aspectRatio, List<RemoteAction> actions,
            Rect sourceRectHint) {
            Rect sourceRectHint, boolean autoEnterAllowed) {
        mAspectRatio = aspectRatio;
        mUserActions = actions;
        mSourceRectHint = sourceRectHint;
        mAutoEnterAllowed = autoEnterAllowed;
    }

    /**
@@ -176,6 +207,7 @@ public final class PictureInPictureParams implements Parcelable {
        if (otherArgs.hasSourceBoundsHint()) {
            mSourceRectHint = new Rect(otherArgs.getSourceRectHint());
        }
        mAutoEnterAllowed = otherArgs.mAutoEnterAllowed;
    }

    /**
@@ -247,12 +279,21 @@ public final class PictureInPictureParams implements Parcelable {
        return mSourceRectHint != null && !mSourceRectHint.isEmpty();
    }

    /**
     * @return whether auto pip allowed.
     * @hide
     */
    public boolean isAutoEnterAllowed() {
        return mAutoEnterAllowed;
    }

    /**
     * @return True if no parameters are set
     * @hide
     */
    public boolean empty() {
        return !hasSourceBoundsHint() && !hasSetActions() && !hasSetAspectRatio();
        return !hasSourceBoundsHint() && !hasSetActions() && !hasSetAspectRatio()
                && !mAutoEnterAllowed;
    }

    @Override
@@ -281,6 +322,8 @@ public final class PictureInPictureParams implements Parcelable {
        } else {
            out.writeInt(0);
        }
        out.writeInt(1);
        out.writeBoolean(mAutoEnterAllowed);
    }

    public static final @android.annotation.NonNull Creator<PictureInPictureParams> CREATOR =
+1 −0
Original line number Diff line number Diff line
@@ -316,6 +316,7 @@ message ActivityRecordProto {
    optional bool front_of_task = 28;
    optional int32 proc_id = 29;
    optional bool translucent = 30;
    optional bool pip_auto_enter_allowed = 31;
}

/* represents WindowToken */
+1 −0
Original line number Diff line number Diff line
@@ -6188,6 +6188,7 @@ package android.app {
    method public android.app.PictureInPictureParams build();
    method public android.app.PictureInPictureParams.Builder setActions(java.util.List<android.app.RemoteAction>);
    method public android.app.PictureInPictureParams.Builder setAspectRatio(android.util.Rational);
    method @NonNull public android.app.PictureInPictureParams.Builder setAutoEnterAllowed(boolean);
    method public android.app.PictureInPictureParams.Builder setSourceRectHint(android.graphics.Rect);
  }
+7 −0
Original line number Diff line number Diff line
@@ -129,6 +129,7 @@ import static com.android.server.wm.ActivityRecordProto.LAST_SURFACE_SHOWING;
import static com.android.server.wm.ActivityRecordProto.NAME;
import static com.android.server.wm.ActivityRecordProto.NUM_DRAWN_WINDOWS;
import static com.android.server.wm.ActivityRecordProto.NUM_INTERESTING_WINDOWS;
import static com.android.server.wm.ActivityRecordProto.PIP_AUTO_ENTER_ALLOWED;
import static com.android.server.wm.ActivityRecordProto.PROC_ID;
import static com.android.server.wm.ActivityRecordProto.REPORTED_DRAWN;
import static com.android.server.wm.ActivityRecordProto.REPORTED_VISIBLE;
@@ -4749,6 +4750,11 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
            // returns. Just need to confirm this reasoning makes sense.
            final boolean deferHidingClient = canEnterPictureInPicture
                    && !isState(STARTED, STOPPING, STOPPED, PAUSED);
            if (deferHidingClient && pictureInPictureArgs.isAutoEnterAllowed()) {
                // Go ahead and just put the activity in pip if it supports auto-pip.
                mAtmService.enterPictureInPictureMode(this, pictureInPictureArgs);
                return;
            }
            setDeferHidingClient(deferHidingClient);
            setVisibility(false);

@@ -7699,6 +7705,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        if (hasProcess()) {
            proto.write(PROC_ID, app.getPid());
        }
        proto.write(PIP_AUTO_ENTER_ALLOWED, pictureInPictureArgs.isAutoEnterAllowed());
    }

    @Override
Loading