From 138c24fb136cdbd3953f81cbb7e6b875877fc0f4 Mon Sep 17 00:00:00 2001 From: Darryl L Johnson Date: Fri, 5 Jun 2020 12:20:32 -0700 Subject: [PATCH] Ensure split-screen support isn't reported on devices with small displays. Several partners with devices that have small displays have run into issues w/ CTS-on-GSI testing as these builds hardcode support for split-screen. This prevents split-screen from being reported as supported if the display isn't compatible according to the CDD. Bug: 158310372 Test: android.server.wm.SplitScreenTests#testMinimumDeviceSize() Change-Id: I0dfd6caca5116dccc115d64b755998171abe831f --- api/test-current.txt | 1 + .../java/android/app/ActivityTaskManager.java | 20 ++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/api/test-current.txt b/api/test-current.txt index e788e6f6d8e25..b701948d6b497 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -143,6 +143,7 @@ package android.app { method @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS) public void stopSystemLockTaskMode(); method public static boolean supportsMultiWindow(android.content.Context); method public static boolean supportsSplitScreenMultiWindow(android.content.Context); + field public static final int DEFAULT_MINIMAL_SPLIT_SCREEN_DISPLAY_SIZE_DP = 440; // 0x1b8 field public static final int INVALID_STACK_ID = -1; // 0xffffffff field public static final int SPLIT_SCREEN_CREATE_MODE_BOTTOM_OR_RIGHT = 1; // 0x1 field public static final int SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT = 0; // 0x0 diff --git a/core/java/android/app/ActivityTaskManager.java b/core/java/android/app/ActivityTaskManager.java index 1cc63da3db0a6..ef9034d8fa6b0 100644 --- a/core/java/android/app/ActivityTaskManager.java +++ b/core/java/android/app/ActivityTaskManager.java @@ -31,6 +31,7 @@ import android.os.Handler; import android.os.IBinder; import android.os.RemoteException; import android.os.ServiceManager; +import android.util.DisplayMetrics; import android.util.Singleton; import java.util.List; @@ -139,6 +140,8 @@ public class ActivityTaskManager { public static final String EXTRA_IGNORE_TARGET_SECURITY = "android.app.extra.EXTRA_IGNORE_TARGET_SECURITY"; + /** The minimal size of a display's long-edge needed to support split-screen multi-window. */ + public static final int DEFAULT_MINIMAL_SPLIT_SCREEN_DISPLAY_SIZE_DP = 440; private static int sMaxRecentTasks = -1; @@ -282,8 +285,23 @@ public class ActivityTaskManager { com.android.internal.R.bool.config_supportsMultiWindow); } - /** Returns true if the system supports split screen multi-window. */ + /** + * Returns {@code true} if the display the context is associated with supports split screen + * multi-window. + * + * @throws UnsupportedOperationException if the supplied {@link Context} is not associated with + * a display. + */ public static boolean supportsSplitScreenMultiWindow(Context context) { + DisplayMetrics dm = new DisplayMetrics(); + context.getDisplay().getRealMetrics(dm); + + int widthDp = (int) (dm.widthPixels / dm.density); + int heightDp = (int) (dm.heightPixels / dm.density); + if (Math.max(widthDp, heightDp) < DEFAULT_MINIMAL_SPLIT_SCREEN_DISPLAY_SIZE_DP) { + return false; + } + return supportsMultiWindow(context) && Resources.getSystem().getBoolean( com.android.internal.R.bool.config_supportsSplitScreenMultiWindow);