Merge "Fix letterbox issue when auto-enter-pip from landscape" into sc-v2-dev am: 109a5be4e7

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15275746

Change-Id: I4d86b1588965c99baf00d4f7d6d0066ce7df89f9
This commit is contained in:
Hongwei Wang
2021-07-14 21:12:44 +00:00
committed by Automerger Merge Worker
6 changed files with 40 additions and 67 deletions

View File

@@ -29,11 +29,13 @@ import android.content.LocusId;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.graphics.Point; import android.graphics.Point;
import android.graphics.Rect;
import android.os.Build; import android.os.Build;
import android.os.IBinder; import android.os.IBinder;
import android.os.Parcel; import android.os.Parcel;
import android.os.RemoteException; import android.os.RemoteException;
import android.util.Log; import android.util.Log;
import android.view.DisplayCutout;
import android.window.TaskSnapshot; import android.window.TaskSnapshot;
import android.window.WindowContainerToken; import android.window.WindowContainerToken;
@@ -180,6 +182,15 @@ public class TaskInfo {
@Nullable @Nullable
public PictureInPictureParams pictureInPictureParams; public PictureInPictureParams pictureInPictureParams;
/**
* The {@link Rect} copied from {@link DisplayCutout#getSafeInsets()} if the cutout is not of
* (LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES, LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS),
* {@code null} otherwise.
* @hide
*/
@Nullable
public Rect displayCutoutInsets;
/** /**
* The activity type of the top activity in this task. * The activity type of the top activity in this task.
* @hide * @hide
@@ -345,6 +356,7 @@ public class TaskInfo {
&& displayAreaFeatureId == that.displayAreaFeatureId && displayAreaFeatureId == that.displayAreaFeatureId
&& Objects.equals(positionInParent, that.positionInParent) && Objects.equals(positionInParent, that.positionInParent)
&& Objects.equals(pictureInPictureParams, that.pictureInPictureParams) && Objects.equals(pictureInPictureParams, that.pictureInPictureParams)
&& Objects.equals(displayCutoutInsets, that.displayCutoutInsets)
&& getWindowingMode() == that.getWindowingMode() && getWindowingMode() == that.getWindowingMode()
&& Objects.equals(taskDescription, that.taskDescription) && Objects.equals(taskDescription, that.taskDescription)
&& isFocused == that.isFocused && isFocused == that.isFocused
@@ -396,6 +408,7 @@ public class TaskInfo {
token = WindowContainerToken.CREATOR.createFromParcel(source); token = WindowContainerToken.CREATOR.createFromParcel(source);
topActivityType = source.readInt(); topActivityType = source.readInt();
pictureInPictureParams = source.readTypedObject(PictureInPictureParams.CREATOR); pictureInPictureParams = source.readTypedObject(PictureInPictureParams.CREATOR);
displayCutoutInsets = source.readTypedObject(Rect.CREATOR);
topActivityInfo = source.readTypedObject(ActivityInfo.CREATOR); topActivityInfo = source.readTypedObject(ActivityInfo.CREATOR);
isResizeable = source.readBoolean(); isResizeable = source.readBoolean();
source.readBinderList(launchCookies); source.readBinderList(launchCookies);
@@ -435,6 +448,7 @@ public class TaskInfo {
token.writeToParcel(dest, flags); token.writeToParcel(dest, flags);
dest.writeInt(topActivityType); dest.writeInt(topActivityType);
dest.writeTypedObject(pictureInPictureParams, flags); dest.writeTypedObject(pictureInPictureParams, flags);
dest.writeTypedObject(displayCutoutInsets, flags);
dest.writeTypedObject(topActivityInfo, flags); dest.writeTypedObject(topActivityInfo, flags);
dest.writeBoolean(isResizeable); dest.writeBoolean(isResizeable);
dest.writeBinderList(launchCookies); dest.writeBinderList(launchCookies);
@@ -465,6 +479,7 @@ public class TaskInfo {
+ " token=" + token + " token=" + token
+ " topActivityType=" + topActivityType + " topActivityType=" + topActivityType
+ " pictureInPictureParams=" + pictureInPictureParams + " pictureInPictureParams=" + pictureInPictureParams
+ " displayCutoutSafeInsets=" + displayCutoutInsets
+ " topActivityInfo=" + topActivityInfo + " topActivityInfo=" + topActivityInfo
+ " launchCookies=" + launchCookies + " launchCookies=" + launchCookies
+ " positionInParent=" + positionInParent + " positionInParent=" + positionInParent

View File

@@ -1,67 +0,0 @@
/*
* Copyright (C) 2018 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.systemui.shared.system;
import android.app.ActivityManager;
import android.app.PictureInPictureParams;
import android.app.TaskInfo;
import android.content.ComponentName;
import android.content.pm.ActivityInfo;
import android.graphics.Rect;
public class TaskInfoCompat {
public static int getUserId(TaskInfo info) {
return info.userId;
}
public static int getActivityType(TaskInfo info) {
return info.configuration.windowConfiguration.getActivityType();
}
public static int getWindowingMode(TaskInfo info) {
return info.configuration.windowConfiguration.getWindowingMode();
}
public static Rect getWindowConfigurationBounds(TaskInfo info) {
return info.configuration.windowConfiguration.getBounds();
}
public static boolean supportsSplitScreenMultiWindow(TaskInfo info) {
return info.supportsSplitScreenMultiWindow;
}
public static ComponentName getTopActivity(TaskInfo info) {
return info.topActivity;
}
public static ActivityManager.TaskDescription getTaskDescription(TaskInfo info) {
return info.taskDescription;
}
public static ActivityInfo getTopActivityInfo(TaskInfo info) {
return info.topActivityInfo;
}
public static boolean isAutoEnterPipEnabled(PictureInPictureParams params) {
return params.isAutoEnterEnabled();
}
public static Rect getPipSourceRectHint(PictureInPictureParams params) {
return params.getSourceRectHint();
}
}

View File

@@ -830,6 +830,10 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
// Tracking cookie for the launch of this activity and it's task. // Tracking cookie for the launch of this activity and it's task.
IBinder mLaunchCookie; IBinder mLaunchCookie;
// Entering PiP is usually done in two phases, we put the task into pinned mode first and
// SystemUi sets the pinned mode on activity after transition is done.
boolean mWaitForEnteringPinnedMode;
private final Runnable mPauseTimeoutRunnable = new Runnable() { private final Runnable mPauseTimeoutRunnable = new Runnable() {
@Override @Override
public void run() { public void run() {
@@ -7894,6 +7898,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
// mode (see RootWindowContainer#moveActivityToPinnedRootTask). So once the windowing mode // mode (see RootWindowContainer#moveActivityToPinnedRootTask). So once the windowing mode
// of activity is changed, it is the signal of the last step to update the PiP states. // of activity is changed, it is the signal of the last step to update the PiP states.
if (!wasInPictureInPicture && inPinnedWindowingMode() && task != null) { if (!wasInPictureInPicture && inPinnedWindowingMode() && task != null) {
mWaitForEnteringPinnedMode = false;
mTaskSupervisor.scheduleUpdatePictureInPictureModeIfNeeded(task, task.getBounds()); mTaskSupervisor.scheduleUpdatePictureInPictureModeIfNeeded(task, task.getBounds());
} }

View File

@@ -1648,6 +1648,10 @@ public class DisplayPolicy {
layoutStatusBar(displayFrames, mBarContentFrames.get(TYPE_STATUS_BAR)); layoutStatusBar(displayFrames, mBarContentFrames.get(TYPE_STATUS_BAR));
return; return;
} }
if (win.mActivityRecord != null && win.mActivityRecord.mWaitForEnteringPinnedMode) {
// Skip layout of the window when in transition to pip mode.
return;
}
final WindowManager.LayoutParams attrs = win.getLayoutingAttrs(displayFrames.mRotation); final WindowManager.LayoutParams attrs = win.getLayoutingAttrs(displayFrames.mRotation);
final int type = attrs.type; final int type = attrs.type;

View File

@@ -2197,6 +2197,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
// from doing work and changing the activity visuals while animating // from doing work and changing the activity visuals while animating
// TODO(task-org): Figure-out more structured way to do this long term. // TODO(task-org): Figure-out more structured way to do this long term.
r.setWindowingMode(intermediateWindowingMode); r.setWindowingMode(intermediateWindowingMode);
r.mWaitForEnteringPinnedMode = true;
rootTask.setWindowingMode(WINDOWING_MODE_PINNED); rootTask.setWindowingMode(WINDOWING_MODE_PINNED);
rootTask.setDeferTaskAppear(false); rootTask.setDeferTaskAppear(false);

View File

@@ -54,6 +54,8 @@ import static android.provider.Settings.Secure.USER_SETUP_COMPLETE;
import static android.view.Display.DEFAULT_DISPLAY; import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.Display.INVALID_DISPLAY; import static android.view.Display.INVALID_DISPLAY;
import static android.view.SurfaceControl.METADATA_TASK_ID; import static android.view.SurfaceControl.METADATA_TASK_ID;
import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
import static android.view.WindowManager.TRANSIT_CHANGE; import static android.view.WindowManager.TRANSIT_CHANGE;
import static android.view.WindowManager.TRANSIT_CLOSE; import static android.view.WindowManager.TRANSIT_CLOSE;
@@ -3335,6 +3337,7 @@ class Task extends TaskFragment {
info.positionInParent = getRelativePosition(); info.positionInParent = getRelativePosition();
info.pictureInPictureParams = getPictureInPictureParams(top); info.pictureInPictureParams = getPictureInPictureParams(top);
info.displayCutoutInsets = getDisplayCutoutInsets(top);
info.topActivityInfo = mReuseActivitiesReport.top != null info.topActivityInfo = mReuseActivitiesReport.top != null
? mReuseActivitiesReport.top.info ? mReuseActivitiesReport.top.info
: null; : null;
@@ -3370,6 +3373,18 @@ class Task extends TaskFragment {
? null : new PictureInPictureParams(topMostActivity.pictureInPictureArgs); ? null : new PictureInPictureParams(topMostActivity.pictureInPictureArgs);
} }
private Rect getDisplayCutoutInsets(Task top) {
if (top == null || top.mDisplayContent == null
|| top.getDisplayInfo().displayCutout == null) return null;
final WindowState w = top.getTopVisibleAppMainWindow();
final int displayCutoutMode = w == null
? WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT
: w.getAttrs().layoutInDisplayCutoutMode;
return (displayCutoutMode == LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS
|| displayCutoutMode == LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES)
? null : top.getDisplayInfo().displayCutout.getSafeInsets();
}
/** /**
* Returns a {@link TaskInfo} with information from this task. * Returns a {@link TaskInfo} with information from this task.
*/ */