diff options
| author | 2021-04-13 09:11:26 +0000 | |
|---|---|---|
| committer | 2021-04-13 09:11:26 +0000 | |
| commit | f636fcb38eb2621185df047d957d4c0fa21ecaae (patch) | |
| tree | a6860adabb6b5335dd29b3b3af2e00548fe040b2 | |
| parent | a13c9782b86f5c3ee5a61a56776a3c74dbb28fd1 (diff) | |
| parent | c72f8d78d6e5bba3a79f915c0e02f10c36124134 (diff) | |
Merge "Shell command to toggle sandboxing" into sc-dev
5 files changed, 111 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index e0724fd27cf4..5b4e6a032050 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -7430,6 +7430,10 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A getPid(), info.applicationInfo.uid) == PERMISSION_GRANTED) { return false; } + // Do not sandbox to activity window bounds if the feature is disabled. + if (mDisplayContent != null && !mDisplayContent.sandboxDisplayApis()) { + return false; + } // Max bounds should be sandboxed where an activity is letterboxed (activity bounds will be // smaller than task bounds). if (!matchParentBounds()) { diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index 74e90e02ae8d..4b735c2c218e 100644 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -348,6 +348,14 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp int mBaseDisplayWidth = 0; int mBaseDisplayHeight = 0; boolean mIsSizeForced = false; + + /** + * Overridden display size and metrics to activity window bounds. Set via + * "adb shell wm set-sandbox-display-apis". Default to true, since only disable for debugging. + * @see WindowManagerService#setSandboxDisplayApis(int, boolean) + */ + private boolean mSandboxDisplayApis = true; + /** * Overridden display density for current user. Initialized with {@link #mInitialDisplayDensity} * but can be set from Settings or via shell command "adb shell wm density". @@ -5736,6 +5744,21 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp return true; } + /** + * Sets if Display APIs should be sandboxed to the activity window bounds. + */ + void setSandboxDisplayApis(boolean sandboxDisplayApis) { + mSandboxDisplayApis = sandboxDisplayApis; + } + + /** + * Returns {@code true} is Display APIs should be sandboxed to the activity window bounds, + * {@code false} otherwise. Default to true, unless set for debugging purposes. + */ + boolean sandboxDisplayApis() { + return mSandboxDisplayApis; + } + /** The entry for proceeding to handle {@link #mFixedRotationLaunchingApp}. */ class FixedRotationTransitionListener extends WindowManagerInternal.AppTransitionListener { diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index e5ec3c9a2225..e0e71e0d6e4c 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -5571,6 +5571,25 @@ public class WindowManagerService extends IWindowManager.Stub } } + void setSandboxDisplayApis(int displayId, boolean sandboxDisplayApis) { + if (mContext.checkCallingOrSelfPermission(WRITE_SECURE_SETTINGS) + != PackageManager.PERMISSION_GRANTED) { + throw new SecurityException("Must hold permission " + WRITE_SECURE_SETTINGS); + } + + final long ident = Binder.clearCallingIdentity(); + try { + synchronized (mGlobalLock) { + final DisplayContent displayContent = mRoot.getDisplayContent(displayId); + if (displayContent != null) { + displayContent.setSandboxDisplayApis(sandboxDisplayApis); + } + } + } finally { + Binder.restoreCallingIdentity(ident); + } + } + /** The global settings only apply to default display. */ private boolean applyForcedPropertiesForDefaultDisplay() { boolean changed = false; diff --git a/services/core/java/com/android/server/wm/WindowManagerShellCommand.java b/services/core/java/com/android/server/wm/WindowManagerShellCommand.java index 9d016d187eb0..5942f34048e7 100644 --- a/services/core/java/com/android/server/wm/WindowManagerShellCommand.java +++ b/services/core/java/com/android/server/wm/WindowManagerShellCommand.java @@ -143,6 +143,8 @@ public class WindowManagerShellCommand extends ShellCommand { return runSetLetterboxBackgroundWallpaperDarkScrimAlpha(pw); case "get-letterbox-background-wallpaper-dark-scrim-alpha": return runGetLetterboxBackgroundWallpaperDarkScrimAlpha(pw); + case "set-sandbox-display-apis": + return runSandboxDisplayApis(pw); case "reset": return runReset(pw); case "disable-blur": @@ -353,6 +355,37 @@ public class WindowManagerShellCommand extends ShellCommand { return 0; } + /** + * Override display size and metrics to reflect the DisplayArea of the calling activity. + */ + private int runSandboxDisplayApis(PrintWriter pw) throws RemoteException { + int displayId = Display.DEFAULT_DISPLAY; + String arg = getNextArgRequired(); + if ("-d".equals(arg)) { + displayId = Integer.parseInt(getNextArgRequired()); + arg = getNextArgRequired(); + } + + final boolean sandboxDisplayApis; + switch (arg) { + case "true": + case "1": + sandboxDisplayApis = true; + break; + case "false": + case "0": + sandboxDisplayApis = false; + break; + default: + getErrPrintWriter().println("Error: expecting true, 1, false, 0, but we " + + "get " + arg); + return -1; + } + + mInternal.setSandboxDisplayApis(displayId, sandboxDisplayApis); + return 0; + } + private int runDismissKeyguard(PrintWriter pw) throws RemoteException { mInterface.dismissKeyguard(null /* callback */, null /* message */); return 0; @@ -855,6 +888,9 @@ public class WindowManagerShellCommand extends ShellCommand { // set-letterbox-background-wallpaper-dark-scrim-alpha mInternal.resetLetterboxBackgroundWallpaperDarkScrimAlpha(); + // set-sandbox-display-apis + mInternal.setSandboxDisplayApis(displayId, /* sandboxDisplayApis= */ true); + pw.println("Reset all settings for displayId=" + displayId); return 0; } @@ -918,6 +954,10 @@ public class WindowManagerShellCommand extends ShellCommand { pw.println(" letterbox background. If alpha < 0 or >= 1 both it and"); pw.println(" R.dimen.config_letterboxBackgroundWallaperDarkScrimAlpha are ignored and "); pw.println(" 0.0 (transparent) is used instead."); + pw.println(" set-sandbox-display-apis [true|1|false|0]"); + pw.println(" Sets override of Display APIs getRealSize / getRealMetrics to reflect "); + pw.println(" DisplayArea of the activity, or the window bounds if in letterbox or"); + pw.println(" Size Compat Mode."); pw.println(" reset [-d DISPLAY_ID]"); pw.println(" Reset all override settings."); if (!IS_USER) { diff --git a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java index 97cead1583e1..7c2cfab50821 100644 --- a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java @@ -1360,6 +1360,31 @@ public class SizeCompatTests extends WindowTestsBase { } @Test + public void testSandboxDisplayApis_letterboxAppNotSandboxed() { + // Set up a display in landscape with an unresizable app. + setUpDisplaySizeWithApp(2500, 1000); + mActivity.mDisplayContent.setSandboxDisplayApis(false /* sandboxDisplayApis */); + prepareUnresizable(mActivity, 1.5f, SCREEN_ORIENTATION_LANDSCAPE); + assertFitted(); + + // Activity max bounds not be sandboxed since sandboxing is disabled. + assertThat(mActivity.getMaxBounds()).isEqualTo(mActivity.mDisplayContent.getBounds()); + } + + @Test + public void testSandboxDisplayApis_letterboxAppSandboxed() { + // Set up a display in landscape with an unresizable app. + setUpDisplaySizeWithApp(2500, 1000); + mActivity.mDisplayContent.setSandboxDisplayApis(true /* sandboxDisplayApis */); + prepareUnresizable(mActivity, 1.5f, SCREEN_ORIENTATION_LANDSCAPE); + assertFitted(); + + // Activity max bounds should be sandboxed since sandboxing is enabled. + assertActivityMaxBoundsSandboxed(); + } + + + @Test public void testTaskDisplayAreaNotFillDisplay() { setUpDisplaySizeWithApp(1400, 2800); final DisplayContent display = mActivity.mDisplayContent; |