Merge "Add API to prefer docking big overlays"

This commit is contained in:
Galia Peycheva
2022-02-16 05:41:04 +00:00
committed by Android (Google) Code Review
12 changed files with 87 additions and 0 deletions

View File

@@ -4275,6 +4275,7 @@ package android.app {
method public void setLocusContext(@Nullable android.content.LocusId, @Nullable android.os.Bundle);
method public final void setMediaController(android.media.session.MediaController);
method public void setPictureInPictureParams(@NonNull android.app.PictureInPictureParams);
method public void setPreferDockBigOverlays(boolean);
method @Deprecated public final void setProgress(int);
method @Deprecated public final void setProgressBarIndeterminate(boolean);
method @Deprecated public final void setProgressBarIndeterminateVisibility(boolean);

View File

@@ -418,6 +418,7 @@ package android.app {
method @NonNull public android.content.res.Configuration getConfiguration();
method public int getParentTaskId();
method @Nullable public android.app.PictureInPictureParams getPictureInPictureParams();
method public boolean getPreferDockBigOverlays();
method @NonNull public android.window.WindowContainerToken getToken();
method public boolean hasParentTask();
}

View File

@@ -2965,6 +2965,27 @@ public class Activity extends ContextThemeWrapper
return false;
}
/**
* Specifies a preference to dock big overlays like the expanded picture-in-picture on TV
* (see {@link PictureInPictureParams.Builder#setExpandedAspectRatio}). Docking puts the
* big overlay side-by-side next to this activity, so that both windows are fully visible to
* the user.
*
* <p> If unspecified, whether the overlay window will be docked or not, will be defined
* by the system.
*
* <p> If specified, the system will try to respect the preference, but it may be
* overridden by a user preference.
*
* @param preferDockBigOverlays indicates that the activity prefers big overlays to be
* docked next to it instead of overlaying its content
*
* @see PictureInPictureParams.Builder#setExpandedAspectRatio
*/
public void setPreferDockBigOverlays(boolean preferDockBigOverlays) {
ActivityClient.getInstance().setPreferDockBigOverlays(mToken, preferDockBigOverlays);
}
void dispatchMovedToDisplay(int displayId, Configuration config) {
updateDisplay(displayId);
onMovedToDisplay(displayId, config);

View File

@@ -324,6 +324,14 @@ public class ActivityClient {
}
}
void setPreferDockBigOverlays(IBinder token, boolean preferDockBigOverlays) {
try {
getActivityClientController().setPreferDockBigOverlays(token, preferDockBigOverlays);
} catch (RemoteException e) {
e.rethrowFromSystemServer();
}
}
void toggleFreeformWindowingMode(IBinder token) {
try {
getActivityClientController().toggleFreeformWindowingMode(token);

View File

@@ -88,6 +88,7 @@ interface IActivityClientController {
boolean enterPictureInPictureMode(in IBinder token, in PictureInPictureParams params);
void setPictureInPictureParams(in IBinder token, in PictureInPictureParams params);
oneway void setPreferDockBigOverlays(in IBinder token, in boolean preferDockBigOverlays);
void toggleFreeformWindowingMode(in IBinder token);
oneway void startLockTaskModeByToken(in IBinder token);

View File

@@ -185,6 +185,11 @@ public class TaskInfo {
@Nullable
public PictureInPictureParams pictureInPictureParams;
/**
* @hide
*/
public boolean preferDockBigOverlays;
/**
* 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),
@@ -378,6 +383,12 @@ public class TaskInfo {
return pictureInPictureParams;
}
/** @hide */
@TestApi
public boolean getPreferDockBigOverlays() {
return preferDockBigOverlays;
}
/** @hide */
@WindowConfiguration.WindowingMode
public int getWindowingMode() {
@@ -447,6 +458,7 @@ public class TaskInfo {
&& displayAreaFeatureId == that.displayAreaFeatureId
&& Objects.equals(positionInParent, that.positionInParent)
&& Objects.equals(pictureInPictureParams, that.pictureInPictureParams)
&& Objects.equals(preferDockBigOverlays, that.preferDockBigOverlays)
&& Objects.equals(displayCutoutInsets, that.displayCutoutInsets)
&& getWindowingMode() == that.getWindowingMode()
&& Objects.equals(taskDescription, that.taskDescription)
@@ -503,6 +515,7 @@ public class TaskInfo {
token = WindowContainerToken.CREATOR.createFromParcel(source);
topActivityType = source.readInt();
pictureInPictureParams = source.readTypedObject(PictureInPictureParams.CREATOR);
preferDockBigOverlays = source.readBoolean();
displayCutoutInsets = source.readTypedObject(Rect.CREATOR);
topActivityInfo = source.readTypedObject(ActivityInfo.CREATOR);
isResizeable = source.readBoolean();
@@ -548,6 +561,7 @@ public class TaskInfo {
token.writeToParcel(dest, flags);
dest.writeInt(topActivityType);
dest.writeTypedObject(pictureInPictureParams, flags);
dest.writeBoolean(preferDockBigOverlays);
dest.writeTypedObject(displayCutoutInsets, flags);
dest.writeTypedObject(topActivityInfo, flags);
dest.writeBoolean(isResizeable);
@@ -587,6 +601,7 @@ public class TaskInfo {
+ " token=" + token
+ " topActivityType=" + topActivityType
+ " pictureInPictureParams=" + pictureInPictureParams
+ " preferDockBigOverlays=" + preferDockBigOverlays
+ " displayCutoutSafeInsets=" + displayCutoutInsets
+ " topActivityInfo=" + topActivityInfo
+ " launchCookies=" + launchCookies

View File

@@ -45,6 +45,10 @@
<item name="config_pictureInPictureExpandedVerticalWidth"
format="dimension" type="dimen">110dp</item>
<!-- The behavior when an activity has not specified a preference to dock big overlays or not.
Docking puts the activity side-by-side next to the big overlay windows. -->
<bool name="config_dockBigOverlayWindows">true</bool>
<!-- Whether the device uses the default focus highlight when focus state isn't specified. -->
<bool name="config_useDefaultFocusHighlight">false</bool>

View File

@@ -3738,6 +3738,10 @@
must be no less than 3 for back compatibility. -->
<integer name="config_pictureInPictureMaxNumberOfActions">3</integer>
<!-- The behavior when an activity has not specified a preference to dock big overlays or not.
Docking puts the activity side-by-side next to the big overlay windows. -->
<bool name="config_dockBigOverlayWindows">false</bool>
<!-- Controls the snap mode for the docked stack divider
0 - 3 snap targets: left/top has 16:9 ratio, 1:1, and right/bottom has 16:9 ratio
1 - 3 snap targets: fixed ratio, 1:1, (1 - fixed ratio)

View File

@@ -418,6 +418,7 @@
<java-symbol type="integer" name="config_pictureInPictureMaxNumberOfActions" />
<java-symbol type="dimen" name="config_pictureInPictureExpandedHorizontalHeight" />
<java-symbol type="dimen" name="config_pictureInPictureExpandedVerticalWidth" />
<java-symbol type="bool" name="config_dockBigOverlayWindows" />
<java-symbol type="dimen" name="config_closeToSquareDisplayMaxAspectRatio" />
<java-symbol type="integer" name="config_burnInProtectionMinHorizontalOffset" />
<java-symbol type="integer" name="config_burnInProtectionMaxHorizontalOffset" />

View File

@@ -756,6 +756,19 @@ class ActivityClientController extends IActivityClientController.Stub {
}
}
@Override
public void setPreferDockBigOverlays(IBinder token, boolean preferDockBigOverlays) {
final long origId = Binder.clearCallingIdentity();
try {
synchronized (mGlobalLock) {
final ActivityRecord r = ActivityRecord.forTokenLocked(token);
r.setPreferDockBigOverlays(preferDockBigOverlays);
}
} finally {
Binder.restoreCallingIdentity(origId);
}
}
/**
* Splash screen view is attached to activity.
*/

View File

@@ -532,6 +532,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
// activity can enter picture in picture while pausing (only when switching to another task)
PictureInPictureParams pictureInPictureArgs = new PictureInPictureParams.Builder().build();
// The PiP params used when deferring the entering of picture-in-picture.
boolean preferDockBigOverlays;
int launchCount; // count of launches since last state
long lastLaunchTime; // time of last launch of this activity
ComponentName requestedVrComponent; // the requested component for handling VR mode.
@@ -1959,6 +1960,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
mLetterboxUiController = new LetterboxUiController(mWmService, this);
mCameraCompatControlEnabled = mWmService.mContext.getResources()
.getBoolean(R.bool.config_isCameraCompatControlForStretchedIssuesEnabled);
preferDockBigOverlays = mWmService.mContext.getResources()
.getBoolean(R.bool.config_dockBigOverlayWindows);
if (_createTime > 0) {
createTime = _createTime;
@@ -9433,6 +9436,11 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
getTask().getRootTask().onPictureInPictureParamsChanged();
}
void setPreferDockBigOverlays(boolean preferDockBigOverlays) {
this.preferDockBigOverlays = preferDockBigOverlays;
getTask().getRootTask().onPreferDockBigOverlaysChanged();
}
@Override
boolean isSyncFinished() {
if (!super.isSyncFinished()) return false;

View File

@@ -3397,6 +3397,7 @@ class Task extends TaskFragment {
info.positionInParent = getRelativePosition();
info.pictureInPictureParams = getPictureInPictureParams(top);
info.preferDockBigOverlays = getPreferDockBigOverlays();
info.displayCutoutInsets = top != null ? top.getDisplayCutoutInsets() : null;
info.topActivityInfo = mReuseActivitiesReport.top != null
? mReuseActivitiesReport.top.info
@@ -3443,6 +3444,11 @@ class Task extends TaskFragment {
? null : new PictureInPictureParams(topMostActivity.pictureInPictureArgs);
}
private boolean getPreferDockBigOverlays() {
final ActivityRecord topMostActivity = getTopMostActivity();
return topMostActivity != null && topMostActivity.preferDockBigOverlays;
}
Rect getDisplayCutoutInsets() {
if (mDisplayContent == null || getDisplayInfo().displayCutout == null) return null;
final WindowState w = getTopVisibleAppMainWindow();
@@ -4336,6 +4342,10 @@ class Task extends TaskFragment {
}
}
void onPreferDockBigOverlaysChanged() {
dispatchTaskInfoChangedIfNeeded(true /* force */);
}
/** Called when the top activity in the Root Task enters or exits size compat mode. */
void onSizeCompatActivityChanged() {
// Trigger TaskInfoChanged to update the size compat restart button.