Merge "Support ignoring app orientation request per display"

This commit is contained in:
TreeHugger Robot
2020-10-15 02:58:43 +00:00
committed by Android (Google) Code Review
7 changed files with 138 additions and 9 deletions

View File

@@ -337,11 +337,16 @@ interface IWindowManager
*/
boolean isDisplayRotationFrozen(int displayId);
/**
/**
* Sets if display rotation is fixed to user specified value for given displayId.
*/
void setFixedToUserRotation(int displayId, int fixedToUserRotation);
/**
* Sets if all requested fixed orientation should be ignored for given displayId.
*/
void setIgnoreOrientationRequest(int displayId, boolean ignoreOrientationRequest);
/**
* Screenshot the current wallpaper layer, including the whole screen.
*/

View File

@@ -101,6 +101,18 @@ public class WindowManagerWrapper {
params.providesInsetsTypes = providesInsetsTypes;
}
/**
* Sets if app requested fixed orientation should be ignored for given displayId.
*/
public void setIgnoreOrientationRequest(int displayId, boolean ignoreOrientationRequest) {
try {
WindowManagerGlobal.getWindowManagerService().setIgnoreOrientationRequest(
displayId, ignoreOrientationRequest);
} catch (RemoteException e) {
Log.e(TAG, "Failed to setIgnoreOrientationRequest()", e);
}
}
/**
* @return the stable insets for the primary display.
*/

View File

@@ -181,6 +181,10 @@ public class DisplayArea<T extends WindowContainer> extends WindowContainer<T> {
return false;
}
boolean getIgnoreOrientationRequest() {
return mIgnoreOrientationRequest;
}
/**
* When a {@link DisplayArea} is repositioned, it should only be moved among its siblings of the
* same {@link Type}.

View File

@@ -5356,8 +5356,13 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
return mDisplayPolicy.getSystemUiContext();
}
Point getDisplayPosition() {
return mWmService.mDisplayManagerInternal.getDisplayPosition(getDisplayId());
@Override
boolean setIgnoreOrientationRequest(boolean ignoreOrientationRequest) {
if (mIgnoreOrientationRequest == ignoreOrientationRequest) return false;
final boolean rotationChanged = super.setIgnoreOrientationRequest(ignoreOrientationRequest);
mWmService.mDisplayWindowSettings.setIgnoreOrientationRequest(
this, mIgnoreOrientationRequest);
return rotationChanged;
}
/**

View File

@@ -112,6 +112,7 @@ class DisplayWindowSettings {
private boolean mShouldShowSystemDecors = false;
private boolean mShouldShowIme = false;
private int mFixedToUserRotation = IWindowManager.FIXED_TO_USER_ROTATION_DEFAULT;
private boolean mIgnoreOrientationRequest = false;
private Entry(String name) {
mName = name;
@@ -131,6 +132,7 @@ class DisplayWindowSettings {
mShouldShowSystemDecors = copyFrom.mShouldShowSystemDecors;
mShouldShowIme = copyFrom.mShouldShowIme;
mFixedToUserRotation = copyFrom.mFixedToUserRotation;
mIgnoreOrientationRequest = copyFrom.mIgnoreOrientationRequest;
}
/** @return {@code true} if all values are default. */
@@ -144,7 +146,8 @@ class DisplayWindowSettings {
&& !mShouldShowWithInsecureKeyguard
&& !mShouldShowSystemDecors
&& !mShouldShowIme
&& mFixedToUserRotation == IWindowManager.FIXED_TO_USER_ROTATION_DEFAULT;
&& mFixedToUserRotation == IWindowManager.FIXED_TO_USER_ROTATION_DEFAULT
&& !mIgnoreOrientationRequest;
}
}
@@ -248,6 +251,15 @@ class DisplayWindowSettings {
writeSettingsIfNeeded(entry, displayInfo);
}
void setIgnoreOrientationRequest(
DisplayContent displayContent, boolean ignoreOrientationRequest) {
final DisplayInfo displayInfo = displayContent.getDisplayInfo();
final Entry entry = getOrCreateEntry(displayInfo);
if (entry.mIgnoreOrientationRequest == ignoreOrientationRequest) return;
entry.mIgnoreOrientationRequest = ignoreOrientationRequest;
writeSettingsIfNeeded(entry, displayInfo);
}
private int getWindowingModeLocked(Entry entry, DisplayContent dc) {
int windowingMode = entry != null ? entry.mWindowingMode
: WindowConfiguration.WINDOWING_MODE_UNDEFINED;
@@ -389,6 +401,7 @@ class DisplayWindowSettings {
final boolean hasSizeOverride = entry.mForcedWidth != 0 && entry.mForcedHeight != 0;
dc.mIsDensityForced = hasDensityOverride;
dc.mIsSizeForced = hasSizeOverride;
dc.setIgnoreOrientationRequest(entry.mIgnoreOrientationRequest);
final int width = hasSizeOverride ? entry.mForcedWidth : dc.mBaseDisplayWidth;
final int height = hasSizeOverride ? entry.mForcedHeight : dc.mBaseDisplayHeight;
@@ -529,6 +542,8 @@ class DisplayWindowSettings {
entry.mShouldShowSystemDecors = getBooleanAttribute(parser, "shouldShowSystemDecors");
entry.mShouldShowIme = getBooleanAttribute(parser, "shouldShowIme");
entry.mFixedToUserRotation = getIntAttribute(parser, "fixedToUserRotation");
entry.mIgnoreOrientationRequest
= getBooleanAttribute(parser, "ignoreOrientationRequest");
mEntries.put(name, entry);
}
XmlUtils.skipCurrentTag(parser);
@@ -613,6 +628,10 @@ class DisplayWindowSettings {
out.attribute(null, "fixedToUserRotation",
Integer.toString(entry.mFixedToUserRotation));
}
if (entry.mIgnoreOrientationRequest) {
out.attribute(null, "ignoreOrientationRequest",
Boolean.toString(entry.mIgnoreOrientationRequest));
}
out.endTag(null, "display");
}

View File

@@ -3709,16 +3709,52 @@ public class WindowManagerService extends IWindowManager.Stub
@Override
public void setFixedToUserRotation(int displayId, int fixedToUserRotation) {
if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
"freezeRotation()")) {
"setFixedToUserRotation()")) {
throw new SecurityException("Requires SET_ORIENTATION permission");
}
final long origId = Binder.clearCallingIdentity();
try {
synchronized (mGlobalLock) {
final DisplayContent display = mRoot.getDisplayContent(displayId);
if (display == null) {
Slog.w(TAG, "Trying to set rotate for app for a missing display.");
return;
}
display.getDisplayRotation().setFixedToUserRotation(fixedToUserRotation);
}
} finally {
Binder.restoreCallingIdentity(origId);
}
}
@Override
public void setIgnoreOrientationRequest(int displayId, boolean ignoreOrientationRequest) {
mAtmInternal.enforceCallerIsRecentsOrHasPermission(
android.Manifest.permission.SET_ORIENTATION, "setIgnoreOrientationRequest()");
final long origId = Binder.clearCallingIdentity();
try {
synchronized (mGlobalLock) {
final DisplayContent display = mRoot.getDisplayContent(displayId);
if (display == null) {
Slog.w(TAG, "Trying to setIgnoreOrientationRequest() for a missing display.");
return;
}
display.setIgnoreOrientationRequest(ignoreOrientationRequest);
}
} finally {
Binder.restoreCallingIdentity(origId);
}
}
boolean getIgnoreOrientationRequest(int displayId) {
synchronized (mGlobalLock) {
final DisplayContent display = mRoot.getDisplayContent(displayId);
if (display == null) {
Slog.w(TAG, "Trying to set rotate for app for a missing display.");
return;
Slog.w(TAG, "Trying to getIgnoreOrientationRequest() for a missing display.");
return false;
}
display.getDisplayRotation().setFixedToUserRotation(fixedToUserRotation);
return display.getIgnoreOrientationRequest();
}
}

View File

@@ -106,6 +106,10 @@ public class WindowManagerShellCommand extends ShellCommand {
return runSetDisplayUserRotation(pw);
case "set-fix-to-user-rotation":
return runSetFixToUserRotation(pw);
case "set-ignore-orientation-request":
return runSetIgnoreOrientationRequest(pw);
case "get-ignore-orientation-request":
return runGetIgnoreOrientationRequest(pw);
case "dump-visible-window-views":
return runDumpVisibleWindowViews(pw);
default:
@@ -368,6 +372,47 @@ public class WindowManagerShellCommand extends ShellCommand {
return 0;
}
private int runSetIgnoreOrientationRequest(PrintWriter pw) throws RemoteException {
int displayId = Display.DEFAULT_DISPLAY;
String arg = getNextArgRequired();
if ("-d".equals(arg)) {
displayId = Integer.parseInt(getNextArgRequired());
arg = getNextArgRequired();
}
final boolean ignoreOrientationRequest;
switch (arg) {
case "true":
case "1":
ignoreOrientationRequest = true;
break;
case "false":
case "0":
ignoreOrientationRequest = false;
break;
default:
getErrPrintWriter().println("Error: expecting true, 1, false, 0, but we "
+ "get " + arg);
return -1;
}
mInterface.setIgnoreOrientationRequest(displayId, ignoreOrientationRequest);
return 0;
}
private int runGetIgnoreOrientationRequest(PrintWriter pw) throws RemoteException {
int displayId = Display.DEFAULT_DISPLAY;
String arg = getNextArg();
if ("-d".equals(arg)) {
displayId = Integer.parseInt(getNextArgRequired());
}
final boolean ignoreOrientationRequest = mInternal.getIgnoreOrientationRequest(displayId);
pw.println("ignoreOrientationRequest " + ignoreOrientationRequest
+ " for displayId=" + displayId);
return 0;
}
private int runDumpVisibleWindowViews(PrintWriter pw) {
if (!mInternal.checkCallingPermission(android.Manifest.permission.DUMP,
"runDumpVisibleWindowViews()")) {
@@ -433,8 +478,11 @@ public class WindowManagerShellCommand extends ShellCommand {
pw.println(" Set user rotation mode and user rotation.");
pw.println(" dump-visible-window-views");
pw.println(" Dumps the encoded view hierarchies of visible windows");
pw.println(" set-fix-to-user-rotation [-d DISPLAY_ID] [enabled|disabled]");
pw.println(" set-fix-to-user-rotation [-d DISPLAY_ID] [enabled|disabled|default]");
pw.println(" Enable or disable rotating display for app requested orientation.");
pw.println(" set-ignore-orientation-request [-d DISPLAY_ID] [true|1|false|0]");
pw.println(" get-ignore-orientation-request [-d DISPLAY_ID] ");
pw.println(" If app requested orientation should be ignored.");
if (!IS_USER) {
pw.println(" tracing (start | stop)");
pw.println(" Start or stop window tracing.");