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

Commit 9fd025cd authored by Merissa Mitchell's avatar Merissa Mitchell
Browse files

[PIP2] Attach PiP menu to leash.

Recall: http://recall/clips/a4248f21-10d6-422c-837c-30117540bac4
Winscope: https://screenshot.googleplex.com/6yTWd3Q5HZKZhsb

Bug: 322548939
Test: Launch PiP and verify menu is present and app actions are usable.
Flag: com.android.wm.shell.enable_pip2
Change-Id: I9d21f576b7764bb5d697573f93be0260e2367327
parent 336a7e7c
Loading
Loading
Loading
Loading
+39 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
    Copyright (C) 2024 The Android Open Source Project

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->
<com.android.wm.shell.pip2.phone.PipMenuActionView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="@dimen/pip_action_size"
    android:layout_height="@dimen/pip_action_size"
    android:background="?android:selectableItemBackgroundBorderless"
    android:forceHasOverlappingRendering="false">

    <ImageView
        android:id="@+id/custom_close_bg"
        android:layout_width="@dimen/pip_custom_close_bg_size"
        android:layout_height="@dimen/pip_custom_close_bg_size"
        android:layout_gravity="center"
        android:src="@drawable/pip_custom_close_bg"
        android:visibility="gone"/>

    <ImageView
        android:id="@+id/image"
        android:layout_width="@dimen/pip_action_inner_size"
        android:layout_height="@dimen/pip_action_inner_size"
        android:layout_gravity="center"
        android:scaleType="fitXY"/>

</com.android.wm.shell.pip2.phone.PipMenuActionView>
+5 −4
Original line number Diff line number Diff line
@@ -125,11 +125,9 @@ public abstract class Pip2Module {
    @Provides
    static PipScheduler providePipScheduler(Context context,
            PipBoundsState pipBoundsState,
            PhonePipMenuController pipMenuController,
            @ShellMainThread ShellExecutor mainExecutor,
            PipTransitionState pipTransitionState) {
        return new PipScheduler(context, pipBoundsState, pipMenuController,
                mainExecutor, pipTransitionState);
        return new PipScheduler(context, pipBoundsState, mainExecutor, pipTransitionState);
    }

    @WMSingleton
@@ -138,10 +136,13 @@ public abstract class Pip2Module {
            PipBoundsState pipBoundsState, PipMediaController pipMediaController,
            SystemWindows systemWindows,
            PipUiEventLogger pipUiEventLogger,
            PipTaskListener pipTaskListener,
            @NonNull PipTransitionState pipTransitionState,
            @ShellMainThread ShellExecutor mainExecutor,
            @ShellMainThread Handler mainHandler) {
        return new PhonePipMenuController(context, pipBoundsState, pipMediaController,
                systemWindows, pipUiEventLogger, mainExecutor, mainHandler);
                systemWindows, pipUiEventLogger, pipTaskListener, pipTransitionState, mainExecutor,
                mainHandler);
    }


+42 −7
Original line number Diff line number Diff line
@@ -18,10 +18,12 @@ package com.android.wm.shell.pip2.phone;

import static android.view.WindowManager.SHELL_ROOT_LAYER_PIP;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.RemoteAction;
import android.content.Context;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Debug;
import android.os.Handler;
import android.os.RemoteException;
@@ -52,7 +54,8 @@ import java.util.List;
 * The current media session provides actions whenever there are no valid actions provided by the
 * current PiP activity. Otherwise, those actions always take precedence.
 */
public class PhonePipMenuController implements PipMenuController {
public class PhonePipMenuController implements PipMenuController,
        PipTransitionState.PipTransitionStateChangedListener {

    private static final String TAG = "PhonePipMenuController";
    private static final boolean DEBUG = false;
@@ -113,6 +116,11 @@ public class PhonePipMenuController implements PipMenuController {

    private PipMenuView mPipMenuView;

    private final PipTaskListener mPipTaskListener;

    @NonNull
    private final PipTransitionState mPipTransitionState;

    private SurfaceControl mLeash;

    private ActionListener mMediaActionListener = new ActionListener() {
@@ -125,15 +133,27 @@ public class PhonePipMenuController implements PipMenuController {

    public PhonePipMenuController(Context context, PipBoundsState pipBoundsState,
            PipMediaController mediaController, SystemWindows systemWindows,
            PipUiEventLogger pipUiEventLogger,
            ShellExecutor mainExecutor, Handler mainHandler) {
            PipUiEventLogger pipUiEventLogger, PipTaskListener pipTaskListener,
            @NonNull PipTransitionState pipTransitionState, ShellExecutor mainExecutor,
            Handler mainHandler) {
        mContext = context;
        mPipBoundsState = pipBoundsState;
        mMediaController = mediaController;
        mSystemWindows = systemWindows;
        mPipTaskListener = pipTaskListener;
        mPipTransitionState = pipTransitionState;
        mMainExecutor = mainExecutor;
        mMainHandler = mainHandler;
        mPipUiEventLogger = pipUiEventLogger;

        mPipTransitionState.addPipTransitionStateChangedListener(this);

        mPipTaskListener.addParamsChangedListener(new PipTaskListener.PipParamsChangedCallback() {
            @Override
            public void onActionsChanged(List<RemoteAction> actions, RemoteAction closeAction) {
                setAppActions(actions, closeAction);
            }
        });
    }

    public boolean isMenuVisible() {
@@ -438,8 +458,7 @@ public class PhonePipMenuController implements PipMenuController {
     * Sets the menu actions to the actions provided by the current PiP menu.
     */
    @Override
    public void setAppActions(List<RemoteAction> appActions,
            RemoteAction closeAction) {
    public void setAppActions(List<RemoteAction> appActions, RemoteAction closeAction) {
        mAppActions = appActions;
        mCloseAction = closeAction;
        updateMenuActions();
@@ -468,8 +487,8 @@ public class PhonePipMenuController implements PipMenuController {
     */
    private void updateMenuActions() {
        if (mPipMenuView != null) {
            mPipMenuView.setActions(mPipBoundsState.getBounds(),
                    resolveMenuActions(), mCloseAction);
            mPipMenuView.setActions(mPipBoundsState.getBounds(), resolveMenuActions(),
                    mCloseAction);
        }
    }

@@ -567,6 +586,22 @@ public class PhonePipMenuController implements PipMenuController {
        }
    }

    @Override
    public void onPipTransitionStateChanged(@PipTransitionState.TransitionState int oldState,
            @PipTransitionState.TransitionState int newState, Bundle extra) {
        switch (newState) {
            case PipTransitionState.ENTERED_PIP:
                attach(mPipTransitionState.mPinnedTaskLeash);
                break;
            case PipTransitionState.EXITED_PIP:
                detach();
                break;
            case PipTransitionState.CHANGED_PIP_BOUNDS:
                updateMenuLayout(mPipBoundsState.getBounds());
                break;
        }
    }

    void dump(PrintWriter pw, String prefix) {
        final String innerPrefix = prefix + "  ";
        pw.println(prefix + TAG);
+1 −1
Original line number Diff line number Diff line
@@ -447,7 +447,7 @@ public class PipMenuView extends FrameLayout {
                final LayoutInflater inflater = LayoutInflater.from(mContext);
                while (mActionsGroup.getChildCount() < mActions.size()) {
                    final PipMenuActionView actionView = (PipMenuActionView) inflater.inflate(
                            R.layout.pip_menu_action, mActionsGroup, false);
                            R.layout.pip2_menu_action, mActionsGroup, false);
                    mActionsGroup.addView(actionView);
                }

+0 −4
Original line number Diff line number Diff line
@@ -52,7 +52,6 @@ public class PipScheduler {

    private final Context mContext;
    private final PipBoundsState mPipBoundsState;
    private final PhonePipMenuController mPipMenuController;
    private final ShellExecutor mMainExecutor;
    private final PipTransitionState mPipTransitionState;
    private PipSchedulerReceiver mSchedulerReceiver;
@@ -97,12 +96,10 @@ public class PipScheduler {

    public PipScheduler(Context context,
            PipBoundsState pipBoundsState,
            PhonePipMenuController pipMenuController,
            ShellExecutor mainExecutor,
            PipTransitionState pipTransitionState) {
        mContext = context;
        mPipBoundsState = pipBoundsState;
        mPipMenuController = pipMenuController;
        mMainExecutor = mainExecutor;
        mPipTransitionState = pipTransitionState;

@@ -263,7 +260,6 @@ public class PipScheduler {
            return;
        }
        mPipBoundsState.setBounds(newBounds);
        mPipMenuController.updateMenuLayout(newBounds);
        maybeUpdateMovementBounds();
    }
}
Loading