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

Commit 3a68287c authored by Winson Chung's avatar Winson Chung
Browse files

Tightening up rotation behavior for PIP (1/3)

- Defer getting the default bounds until after the task has been reparented
  to the pinned stack
- Also move pinned stack-related methods into pinned stack window
  controller and listener

Bug: 36879891
Test: android.server.cts.ActivityManagerPinnedStackTests

Change-Id: Ib2bd81ad9e2a3829b556177010f39c7512ba35bf
parent c59a2a76
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -7834,9 +7834,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                    final float aspectRatio = r.pictureInPictureArgs.getAspectRatio();
                    final List<RemoteAction> actions = r.pictureInPictureArgs.getActions();
                    final Rect sourceBounds = r.pictureInPictureArgs.getSourceRectHint();
                    final Rect destBounds = mWindowManager.getPictureInPictureBounds(DEFAULT_DISPLAY,
                            aspectRatio);
                    mStackSupervisor.moveActivityToPinnedStackLocked(r, sourceBounds, destBounds,
                    mStackSupervisor.moveActivityToPinnedStackLocked(r, sourceBounds, aspectRatio,
                            true /* moveHomeStackToFront */, "enterPictureInPictureMode");
                    final PinnedActivityStack stack = mStackSupervisor.getStack(PINNED_STACK_ID);
                    stack.setPictureInPictureAspectRatio(aspectRatio);
+7 −2
Original line number Diff line number Diff line
@@ -2857,12 +2857,12 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
            return false;
        }

        moveActivityToPinnedStackLocked(r, null /* sourceBounds */, destBounds,
        moveActivityToPinnedStackLocked(r, null /* sourceBounds */, 0f /* aspectRatio */,
                true /* moveHomeStackToFront */, "moveTopActivityToPinnedStack");
        return true;
    }

    void moveActivityToPinnedStackLocked(ActivityRecord r, Rect sourceBounds, Rect destBounds,
    void moveActivityToPinnedStackLocked(ActivityRecord r, Rect sourceBounds, float aspectRatio,
            boolean moveHomeStackToFront, String reason) {

        mWindowManager.deferSurfaceLayout();
@@ -2932,6 +2932,11 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
        ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
        resumeFocusedStackTopActivityLocked();

        // Calculate the default bounds (don't use existing stack bounds as we may have just created
        // the stack
        final Rect destBounds = mWindowManager.getPictureInPictureBounds(DEFAULT_DISPLAY,
                aspectRatio, false /* useExistingStackBounds */);

        // TODO(b/36099777): Schedule the PiP mode change here immediately until we can defer all
        // callbacks until after the bounds animation
        scheduleUpdatePictureInPictureModeIfNeeded(r.getTask(), destBounds, true /* immediate */);
+3 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.graphics.Rect;

import com.android.server.am.ActivityStackSupervisor.ActivityContainer;
import com.android.server.wm.PinnedStackWindowController;
import com.android.server.wm.PinnedStackWindowListener;
import com.android.server.wm.StackWindowController;

import java.util.ArrayList;
@@ -29,7 +30,8 @@ import java.util.List;
/**
 * State and management of the pinned stack of activities.
 */
class PinnedActivityStack extends ActivityStack<PinnedStackWindowController> {
class PinnedActivityStack extends ActivityStack<PinnedStackWindowController>
        implements PinnedStackWindowListener {

    PinnedActivityStack(ActivityContainer activityContainer,
            RecentTasks recentTasks, boolean onTop) {
+16 −3
Original line number Diff line number Diff line
@@ -32,8 +32,8 @@ public class PinnedStackWindowController extends StackWindowController {

    private Rect mTmpBoundsRect = new Rect();

    public PinnedStackWindowController(int stackId, StackWindowListener listener, int displayId,
            boolean onTop, Rect outBounds) {
    public PinnedStackWindowController(int stackId, PinnedStackWindowListener listener,
            int displayId, boolean onTop, Rect outBounds) {
        super(stackId, listener, displayId, onTop, outBounds, WindowManagerService.getInstance());
    }

@@ -84,7 +84,8 @@ public class PinnedStackWindowController extends StackWindowController {
            }

            final int displayId = mContainer.getDisplayContent().getDisplayId();
            final Rect toBounds = mService.getPictureInPictureBounds(displayId, aspectRatio);
            final Rect toBounds = mService.getPictureInPictureBounds(displayId, aspectRatio,
                    true /* useExistingStackBounds */);
            final Rect targetBounds = new Rect();
            mContainer.getAnimatingBounds(targetBounds);
            final PinnedStackController pinnedStackController =
@@ -132,4 +133,16 @@ public class PinnedStackWindowController extends StackWindowController {
        }
        return bounds;
    }

    /**
     * The following calls are made from WM to AM.
     */

    /** Calls directly into activity manager so window manager lock shouldn't held. */
    public void updatePictureInPictureModeForPinnedStackAnimation(Rect targetStackBounds) {
        if (mListener != null) {
            PinnedStackWindowListener listener = (PinnedStackWindowListener) mListener;
            listener.updatePictureInPictureModeForPinnedStackAnimation(targetStackBounds);
        }
    }
}
+32 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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
 */

package com.android.server.wm;

import android.graphics.Rect;

/**
 * Interface used by the creator of {@link PinnedStackWindowController} to listen to changes with
 * the stack container.
 */
public interface PinnedStackWindowListener extends StackWindowListener {

    /**
     * Called when the stack container pinned stack animation will change the picture-in-picture
     * mode. This is a direct call into ActivityManager.
     */
    default void updatePictureInPictureModeForPinnedStackAnimation(Rect targetStackBounds) {}
}
Loading