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

Commit d863a778 authored by Jacqueline Bronger's avatar Jacqueline Bronger Committed by Android (Google) Code Review
Browse files

Merge "Remove if(DEBUG) around ProtoLogs for TV PiP code"

parents 6a8a3321 3e09772f
Loading
Loading
Loading
Loading
+47 −71
Original line number Diff line number Diff line
@@ -49,11 +49,10 @@ import java.util.Set;
 * Contains pip bounds calculations that are specific to TV.
 */
public class TvPipBoundsAlgorithm extends PipBoundsAlgorithm {

    private static final String TAG = TvPipBoundsAlgorithm.class.getSimpleName();
    private static final boolean DEBUG = TvPipController.DEBUG;

    private final @NonNull TvPipBoundsState mTvPipBoundsState;
    @NonNull
    private final TvPipBoundsState mTvPipBoundsState;

    private int mFixedExpandedHeightInPx;
    private int mFixedExpandedWidthInPx;
@@ -91,10 +90,9 @@ public class TvPipBoundsAlgorithm extends PipBoundsAlgorithm {
    /** Returns the destination bounds to place the PIP window on entry. */
    @Override
    public Rect getEntryDestinationBounds() {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: getEntryDestinationBounds()", TAG);
        }

        updateExpandedPipSize();
        final boolean isPipExpanded = mTvPipBoundsState.isTvExpandedPipSupported()
                && mTvPipBoundsState.getDesiredTvExpandedAspectRatio() != 0
@@ -109,10 +107,8 @@ public class TvPipBoundsAlgorithm extends PipBoundsAlgorithm {
    /** Returns the current bounds adjusted to the new aspect ratio, if valid. */
    @Override
    public Rect getAdjustedDestinationBounds(Rect currentBounds, float newAspectRatio) {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: getAdjustedDestinationBounds: %f", TAG, newAspectRatio);
        }
        return adjustBoundsForTemporaryDecor(getTvPipPlacement().getBounds());
    }

@@ -156,7 +152,6 @@ public class TvPipBoundsAlgorithm extends PipBoundsAlgorithm {
                restrictedKeepClearAreas,
                unrestrictedKeepClearAreas);

        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: screenSize: %s", TAG, screenSize);
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
@@ -173,7 +168,6 @@ public class TvPipBoundsAlgorithm extends PipBoundsAlgorithm {
                "%s: unrestrictedKeepClearAreas: %s", TAG, unrestrictedKeepClearAreas);
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: placement: %s", TAG, placement);
        }

        return placement;
    }
@@ -182,13 +176,11 @@ public class TvPipBoundsAlgorithm extends PipBoundsAlgorithm {
     * @return previous gravity if it is to be saved, or {@link Gravity#NO_GRAVITY} if not.
     */
    int updateGravityOnExpandToggled(int previousGravity, boolean expanding) {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: updateGravityOnExpandToggled(), expanding: %b"
                        + ", mOrientation: %d, previous gravity: %s",
                TAG, expanding, mTvPipBoundsState.getTvFixedPipOrientation(),
                Gravity.toString(previousGravity));
        }

        if (!mTvPipBoundsState.isTvExpandedPipSupported()) {
            return Gravity.NO_GRAVITY;
@@ -239,10 +231,8 @@ public class TvPipBoundsAlgorithm extends PipBoundsAlgorithm {
            }
        }
        mTvPipBoundsState.setTvPipGravity(updatedGravity);
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: new gravity: %s", TAG, Gravity.toString(updatedGravity));
        }

        return gravityToSave;
    }
@@ -251,10 +241,8 @@ public class TvPipBoundsAlgorithm extends PipBoundsAlgorithm {
     * @return true if gravity changed
     */
    boolean updateGravity(int keycode) {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: updateGravity, keycode: %d", TAG, keycode);
        }

        // Check if position change is valid
        if (mTvPipBoundsState.isTvPipExpanded()) {
@@ -311,10 +299,8 @@ public class TvPipBoundsAlgorithm extends PipBoundsAlgorithm {

        if (updatedGravity != currentGravity) {
            mTvPipBoundsState.setTvPipGravity(updatedGravity);
            if (DEBUG) {
            ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                    "%s: new gravity: %s", TAG, Gravity.toString(updatedGravity));
            }
            return true;
        }
        return false;
@@ -358,16 +344,12 @@ public class TvPipBoundsAlgorithm extends PipBoundsAlgorithm {
                float aspectRatioHeight = mFixedExpandedWidthInPx / expandedRatio;

                if (maxHeight > aspectRatioHeight) {
                    if (DEBUG) {
                    ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                            "%s: Accommodate aspect ratio", TAG);
                    }
                    expandedSize = new Size(mFixedExpandedWidthInPx, (int) aspectRatioHeight);
                } else {
                    if (DEBUG) {
                    ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                            "%s: Aspect ratio is too extreme, use max size", TAG);
                    }
                    expandedSize = new Size(mFixedExpandedWidthInPx, maxHeight);
                }
            }
@@ -380,26 +362,20 @@ public class TvPipBoundsAlgorithm extends PipBoundsAlgorithm {
                        - pipDecorations.left - pipDecorations.right;
                float aspectRatioWidth = mFixedExpandedHeightInPx * expandedRatio;
                if (maxWidth > aspectRatioWidth) {
                    if (DEBUG) {
                    ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                            "%s: Accommodate aspect ratio", TAG);
                    }
                    expandedSize = new Size((int) aspectRatioWidth, mFixedExpandedHeightInPx);
                } else {
                    if (DEBUG) {
                    ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                            "%s: Aspect ratio is too extreme, use max size", TAG);
                    }
                    expandedSize = new Size(maxWidth, mFixedExpandedHeightInPx);
                }
            }
        }

        mTvPipBoundsState.setTvExpandedSize(expandedSize);
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: updateExpandedPipSize(): expanded size, width: %d, height: %d",
                TAG, expandedSize.getWidth(), expandedSize.getHeight());
    }
}
}
+7 −14
Original line number Diff line number Diff line
@@ -39,7 +39,6 @@ import java.util.function.Supplier;
 * Manages debouncing of PiP movements and scheduling of unstashing.
 */
public class TvPipBoundsController {
    private static final boolean DEBUG = false;
    private static final String TAG = "TvPipBoundsController";

    /**
@@ -133,11 +132,9 @@ public class TvPipBoundsController {

    private void schedulePinnedStackPlacement(@NonNull final Placement placement,
            int animationDuration) {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: schedulePinnedStackPlacement() - pip bounds: %s",
                TAG, placement.getBounds().toShortString());
        }

        if (mPendingPlacement != null && Objects.equals(mPendingPlacement.getBounds(),
                placement.getBounds())) {
@@ -171,10 +168,8 @@ public class TvPipBoundsController {
    }

    private void applyPendingPlacement() {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: applyPendingPlacement()", TAG);
        }
        if (mPendingPlacement != null) {
            applyPlacement(mPendingPlacement, mPendingStash, mPendingPlacementAnimationDuration);
            mPendingStash = false;
@@ -226,10 +221,8 @@ public class TvPipBoundsController {
        }

        mPipTargetBounds = bounds;
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: movePipTo() - new pip bounds: %s", TAG, bounds.toShortString());
        }

        if (mListener != null) {
            mListener.onPipTargetBoundsChange(bounds, animationDuration);
+52 −94
Original line number Diff line number Diff line
@@ -70,7 +70,6 @@ public class TvPipController implements PipTransitionController.PipTransitionCal
        TvPipNotificationController.Delegate, DisplayController.OnDisplaysChangedListener,
        ConfigurationChangeListener, UserChangeListener {
    private static final String TAG = "TvPipController";
    static final boolean DEBUG = false;

    private static final int NONEXISTENT_TASK_ID = -1;

@@ -80,7 +79,8 @@ public class TvPipController implements PipTransitionController.PipTransitionCal
            STATE_PIP,
            STATE_PIP_MENU,
    })
    public @interface State {}
    public @interface State {
    }

    /**
     * State when there is no applications in Pip.
@@ -117,7 +117,8 @@ public class TvPipController implements PipTransitionController.PipTransitionCal
    private final ShellExecutor mMainExecutor;
    private final TvPipImpl mImpl = new TvPipImpl();

    private @State int mState = STATE_NO_PIP;
    @State
    private int mState = STATE_NO_PIP;
    private int mPreviousGravity = TvPipBoundsState.DEFAULT_TV_GRAVITY;
    private int mPinnedTaskId = NONEXISTENT_TASK_ID;

@@ -236,16 +237,12 @@ public class TvPipController implements PipTransitionController.PipTransitionCal

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: onConfigurationChanged(), state=%s", TAG, stateToName(mState));
        }

        if (isPipShown()) {
            if (DEBUG) {
            ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                    "%s:  > closing Pip.", TAG);
            }
            closePip();
        }

@@ -268,16 +265,12 @@ public class TvPipController implements PipTransitionController.PipTransitionCal
     */
    @Override
    public void showPictureInPictureMenu() {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: showPictureInPictureMenu(), state=%s", TAG, stateToName(mState));
        }

        if (mState == STATE_NO_PIP) {
            if (DEBUG) {
            ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                    "%s:  > cannot open Menu from the current state.", TAG);
            }
            return;
        }

@@ -288,10 +281,8 @@ public class TvPipController implements PipTransitionController.PipTransitionCal

    @Override
    public void onMenuClosed() {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: closeMenu(), state before=%s", TAG, stateToName(mState));
        }
        setState(STATE_PIP);
        updatePinnedStackBounds();
    }
@@ -306,10 +297,8 @@ public class TvPipController implements PipTransitionController.PipTransitionCal
     */
    @Override
    public void movePipToFullscreen() {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: movePipToFullscreen(), state=%s", TAG, stateToName(mState));
        }

        mPipTaskOrganizer.exitPip(mResizeAnimationDuration, false /* requestEnterSplit */);
        onPipDisappeared();
@@ -317,10 +306,8 @@ public class TvPipController implements PipTransitionController.PipTransitionCal

    @Override
    public void togglePipExpansion() {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: togglePipExpansion()", TAG);
        }
        boolean expanding = !mTvPipBoundsState.isTvPipExpanded();
        int saveGravity = mTvPipBoundsAlgorithm
                .updateGravityOnExpandToggled(mPreviousGravity, expanding);
@@ -347,12 +334,10 @@ public class TvPipController implements PipTransitionController.PipTransitionCal
            mPreviousGravity = Gravity.NO_GRAVITY;
            updatePinnedStackBounds();
        } else {
            if (DEBUG) {
            ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                    "%s: Position hasn't changed", TAG);
        }
    }
    }

    @Override
    public int getPipGravity() {
@@ -403,11 +388,9 @@ public class TvPipController implements PipTransitionController.PipTransitionCal
     */
    @Override
    public void closePip() {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: closePip(), state=%s, loseAction=%s", TAG, stateToName(mState),
                mCloseAction);
        }

        if (mCloseAction != null) {
            try {
@@ -443,10 +426,8 @@ public class TvPipController implements PipTransitionController.PipTransitionCal

    private void checkIfPinnedTaskAppeared() {
        final TaskInfo pinnedTask = getPinnedTaskInfo();
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: checkIfPinnedTaskAppeared(), task=%s", TAG, pinnedTask);
        }
        if (pinnedTask == null || pinnedTask.topActivity == null) return;
        mPinnedTaskId = pinnedTask.taskId;

@@ -455,10 +436,8 @@ public class TvPipController implements PipTransitionController.PipTransitionCal
    }

    private void checkIfPinnedTaskIsGone() {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: onTaskStackChanged()", TAG);
        }

        if (isPipShown() && getPinnedTaskInfo() == null) {
            ProtoLog.w(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
@@ -468,10 +447,8 @@ public class TvPipController implements PipTransitionController.PipTransitionCal
    }

    private void onPipDisappeared() {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: onPipDisappeared() state=%s", TAG, stateToName(mState));
        }

        mPipNotificationController.dismiss();
        mTvPipMenuController.closeMenu();
@@ -483,19 +460,15 @@ public class TvPipController implements PipTransitionController.PipTransitionCal

    @Override
    public void onPipTransitionStarted(int direction, Rect pipBounds) {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: onPipTransition_Started(), state=%s", TAG, stateToName(mState));
        }
        mTvPipMenuController.notifyPipAnimating(true);
    }

    @Override
    public void onPipTransitionCanceled(int direction) {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: onPipTransition_Canceled(), state=%s", TAG, stateToName(mState));
        }
        mTvPipMenuController.notifyPipAnimating(false);
    }

@@ -504,19 +477,15 @@ public class TvPipController implements PipTransitionController.PipTransitionCal
        if (PipAnimationController.isInPipDirection(direction) && mState == STATE_NO_PIP) {
            setState(STATE_PIP);
        }
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: onPipTransition_Finished(), state=%s", TAG, stateToName(mState));
        }
        mTvPipMenuController.notifyPipAnimating(false);
    }

    private void setState(@State int state) {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: setState(), state=%s, prev=%s",
                TAG, stateToName(state), stateToName(mState));
        }
        mState = state;
    }

@@ -550,11 +519,8 @@ public class TvPipController implements PipTransitionController.PipTransitionCal
            public void onActivityRestartAttempt(ActivityManager.RunningTaskInfo task,
                    boolean homeTaskVisible, boolean clearedTask, boolean wasVisible) {
                if (task.getWindowingMode() == WINDOWING_MODE_PINNED) {
                    if (DEBUG) {
                    ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                            "%s: onPinnedActivityRestartAttempt()", TAG);
                    }

                    // If the "Pip-ed" Activity is launched again by Launcher or intent, make it
                    // fullscreen.
                    movePipToFullscreen();
@@ -635,11 +601,9 @@ public class TvPipController implements PipTransitionController.PipTransitionCal
            wmShell.addPinnedStackListener(new PinnedStackListenerForwarder.PinnedTaskListener() {
                @Override
                public void onImeVisibilityChanged(boolean imeVisible, int imeHeight) {
                    if (DEBUG) {
                    ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                            "%s: onImeVisibilityChanged(), visible=%b, height=%d",
                            TAG, imeVisible, imeHeight);
                    }

                    if (imeVisible == mTvPipBoundsState.isImeShowing()
                            && (!imeVisible || imeHeight == mTvPipBoundsState.getImeHeight())) {
@@ -661,17 +625,13 @@ public class TvPipController implements PipTransitionController.PipTransitionCal
    }

    private static TaskInfo getPinnedTaskInfo() {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: getPinnedTaskInfo()", TAG);
        }
        try {
            final TaskInfo taskInfo = ActivityTaskManager.getService().getRootTaskInfo(
                    WINDOWING_MODE_PINNED, ACTIVITY_TYPE_UNDEFINED);
            if (DEBUG) {
            ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                    "%s: taskInfo=%s", TAG, taskInfo);
            }
            return taskInfo;
        } catch (RemoteException e) {
            ProtoLog.e(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
@@ -681,10 +641,8 @@ public class TvPipController implements PipTransitionController.PipTransitionCal
    }

    private static void removeTask(int taskId) {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: removeTask(), taskId=%d", TAG, taskId);
        }
        try {
            ActivityTaskManager.getService().removeTask(taskId);
        } catch (Exception e) {
+51 −85
Original line number Diff line number Diff line
@@ -54,7 +54,6 @@ import java.util.Objects;
 */
public class TvPipMenuController implements PipMenuController, TvPipMenuView.Listener {
    private static final String TAG = "TvPipMenuController";
    private static final boolean DEBUG = TvPipController.DEBUG;
    private static final String BACKGROUND_WINDOW_TITLE = "PipBackgroundView";

    private final Context mContext;
@@ -119,10 +118,8 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis
    }

    void setDelegate(Delegate delegate) {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: setDelegate(), delegate=%s", TAG, delegate);
        }
        if (mDelegate != null) {
            throw new IllegalStateException(
                    "The delegate has already been set and should not change.");
@@ -145,10 +142,8 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis
    }

    private void attachPipMenu() {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: attachPipMenu()", TAG);
        }

        if (mPipMenuView != null) {
            detachPipMenu();
@@ -205,10 +200,8 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis
    }

    void showMovementMenuOnly() {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: showMovementMenuOnly()", TAG);
        }
        setInMoveMode(true);
        mCloseAfterExitMoveMenu = true;
        showMenuInternal();
@@ -216,9 +209,7 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis

    @Override
    public void showMenu() {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE, "%s: showMenu()", TAG);
        }
        setInMoveMode(false);
        mCloseAfterExitMoveMenu = false;
        showMenuInternal();
@@ -274,15 +265,12 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis
    }

    void closeMenu() {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: closeMenu()", TAG);
        }

        if (mPipMenuView == null) {
            return;
        }

        mPipMenuView.hideAllUserControls();
        grantPipMenuFocus(false);
        mDelegate.onMenuClosed();
@@ -296,7 +284,6 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis
        if (mInMoveMode == moveMode) {
            return;
        }

        mInMoveMode = moveMode;
        if (mDelegate != null) {
            mDelegate.onInMoveModeChanged();
@@ -305,22 +292,19 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis

    @Override
    public void onEnterMoveMode() {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: onEnterMoveMode - %b, close when exiting move menu: %b", TAG, mInMoveMode,
                mCloseAfterExitMoveMenu);
        }
        setInMoveMode(true);
        mPipMenuView.showMoveMenu(mDelegate.getPipGravity());
    }

    @Override
    public boolean onExitMoveMode() {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: onExitMoveMode - %b, close when exiting move menu: %b", TAG, mInMoveMode,
                mCloseAfterExitMoveMenu);
        }

        if (mCloseAfterExitMoveMenu) {
            setInMoveMode(false);
            mCloseAfterExitMoveMenu = false;
@@ -337,10 +321,8 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis

    @Override
    public boolean onPipMovement(int keycode) {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: onPipMovement - %b", TAG, mInMoveMode);
        }
        if (mInMoveMode) {
            mDelegate.movePip(keycode);
        }
@@ -357,18 +339,14 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis

    @Override
    public void setAppActions(List<RemoteAction> actions, RemoteAction closeAction) {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: setAppActions()", TAG);
        }
        updateAdditionalActionsList(mAppActions, actions, closeAction);
    }

    private void onMediaActionsChanged(List<RemoteAction> actions) {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: onMediaActionsChanged()", TAG);
        }

        // Hide disabled actions.
        List<RemoteAction> enabledActions = new ArrayList<>();
@@ -420,10 +398,8 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis
    public void resizePipMenu(@Nullable SurfaceControl pipLeash,
            @Nullable SurfaceControl.Transaction t,
            Rect destinationBounds) {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: resizePipMenu: %s", TAG, destinationBounds.toShortString());
        }
        if (destinationBounds.isEmpty()) {
            return;
        }
@@ -467,13 +443,11 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis
    @Override
    public void movePipMenu(SurfaceControl pipLeash, SurfaceControl.Transaction transaction,
            Rect pipDestBounds) {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: movePipMenu: %s", TAG, pipDestBounds.toShortString());
        }

        if (pipDestBounds.isEmpty()) {
            if (transaction == null && DEBUG) {
            if (transaction == null) {
                ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                        "%s: no transaction given", TAG);
            }
@@ -489,16 +463,12 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis
        // resizing and the PiP menu is also resized. We then want to do a scale from the current
        // new menu bounds.
        if (pipLeash != null && transaction != null) {
            if (DEBUG) {
            ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                    "%s: tmpSourceBounds based on mPipMenuView.getBoundsOnScreen()", TAG);
            }
            mPipMenuView.getBoundsOnScreen(tmpSourceBounds);
        } else {
            if (DEBUG) {
            ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                    "%s: tmpSourceBounds based on menu width and height", TAG);
            }
            tmpSourceBounds.set(0, 0, menuDestBounds.width(), menuDestBounds.height());
        }

@@ -567,10 +537,8 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis
    @Override
    public void updateMenuBounds(Rect destinationBounds) {
        final Rect menuBounds = calculateMenuSurfaceBounds(destinationBounds);
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: updateMenuBounds: %s", TAG, menuBounds.toShortString());
        }
        mSystemWindows.updateViewLayout(mPipBackgroundView,
                getPipMenuLayoutParams(mContext, BACKGROUND_WINDOW_TITLE, menuBounds.width(),
                        menuBounds.height()));
@@ -629,10 +597,8 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis
    }

    private void grantPipMenuFocus(boolean grantFocus) {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: grantWindowFocus(%b)", TAG, grantFocus);
        }

        try {
            WindowManagerGlobal.getWindowSession().grantEmbeddedWindowFocus(null /* window */,
+14 −29
Original line number Diff line number Diff line
@@ -71,7 +71,6 @@ import java.util.List;
 */
public class TvPipMenuView extends FrameLayout implements View.OnClickListener {
    private static final String TAG = "TvPipMenuView";
    private static final boolean DEBUG = TvPipController.DEBUG;

    private static final int FIRST_CUSTOM_ACTION_POSITION = 3;

@@ -448,10 +447,8 @@ public class TvPipMenuView extends FrameLayout implements View.OnClickListener {
    }

    void setIsExpanded(boolean expanded) {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: setIsExpanded, expanded: %b", TAG, expanded);
        }
        mExpandButton.setImageResource(
                expanded ? R.drawable.pip_ic_collapse : R.drawable.pip_ic_expand);
        mExpandButton.setTextAndDescription(
@@ -462,9 +459,7 @@ public class TvPipMenuView extends FrameLayout implements View.OnClickListener {
     * @param gravity for the arrow hints
     */
    void showMoveMenu(int gravity) {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE, "%s: showMoveMenu()", TAG);
        }
        mButtonMenuIsVisible = false;
        mMoveMenuIsVisible = true;
        showButtonsMenu(false);
@@ -476,11 +471,8 @@ public class TvPipMenuView extends FrameLayout implements View.OnClickListener {
    }

    void showButtonsMenu() {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: showButtonsMenu()", TAG);
        }

        mButtonMenuIsVisible = true;
        mMoveMenuIsVisible = false;
        showButtonsMenu(true);
@@ -553,10 +545,8 @@ public class TvPipMenuView extends FrameLayout implements View.OnClickListener {
     */
    void setAdditionalActions(List<RemoteAction> actions, RemoteAction closeAction,
            Handler mainHandler) {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: setAdditionalActions()", TAG);
        }

        // Replace system close action with custom close action if available
        if (closeAction != null) {
@@ -707,10 +697,8 @@ public class TvPipMenuView extends FrameLayout implements View.OnClickListener {
     * Shows user hints for moving the PiP, e.g. arrows.
     */
    public void showMovementHints(int gravity) {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: showMovementHints(), position: %s", TAG, Gravity.toString(gravity));
        }

        animateAlphaTo(checkGravity(gravity, Gravity.BOTTOM) ? 1f : 0f, mArrowUp);
        animateAlphaTo(checkGravity(gravity, Gravity.TOP) ? 1f : 0f, mArrowDown);
@@ -752,10 +740,9 @@ public class TvPipMenuView extends FrameLayout implements View.OnClickListener {
     * Hides user hints for moving the PiP, e.g. arrows.
     */
    public void hideMovementHints() {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: hideMovementHints()", TAG);
        }

        animateAlphaTo(0, mArrowUp);
        animateAlphaTo(0, mArrowRight);
        animateAlphaTo(0, mArrowDown);
@@ -767,10 +754,8 @@ public class TvPipMenuView extends FrameLayout implements View.OnClickListener {
     * Show or hide the pip buttons menu.
     */
    public void showButtonsMenu(boolean show) {
        if (DEBUG) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "%s: showUserActions: %b", TAG, show);
        }
        if (show) {
            mActionButtonsContainer.setVisibility(VISIBLE);
            refocusPreviousButton();