From fad7f25eeb1c45be1d1503d6ab61c192ce9752d1 Mon Sep 17 00:00:00 2001 From: Andrii Kulian Date: Thu, 16 Jun 2022 23:53:48 +0000 Subject: [PATCH] Check Task windowing mode when reporting display features If an application uses ActivityEmbedding it would not be able to observe display features (like folds or hinges) because they are filtered out for activities in multi-window mode. One of the reasons is because the client won't always know the correct position of the window on screen in multi-window, and the position of the hinge could be translated incorrectly to the task coordinate space. However, it would still be OK to report the display features when activities are in multi-window due to ActivityEmbedding as long as the task is not in multi-window. Bug: 236295340 Test: Sample app with embedding and display features. Merged-In: I00f62574124df6df61f121228bd91ff9bc751c2a Change-Id: I00f62574124df6df61f121228bd91ff9bc751c2a --- .../layout/WindowLayoutComponentImpl.java | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/libs/WindowManager/Jetpack/src/androidx/window/extensions/layout/WindowLayoutComponentImpl.java b/libs/WindowManager/Jetpack/src/androidx/window/extensions/layout/WindowLayoutComponentImpl.java index a6f638822d10a..c1d1c8e8d4e08 100644 --- a/libs/WindowManager/Jetpack/src/androidx/window/extensions/layout/WindowLayoutComponentImpl.java +++ b/libs/WindowManager/Jetpack/src/androidx/window/extensions/layout/WindowLayoutComponentImpl.java @@ -25,7 +25,10 @@ import static androidx.window.util.ExtensionHelper.transformToWindowSpaceRect; import android.annotation.Nullable; import android.app.Activity; +import android.app.ActivityManager; +import android.app.ActivityManager.AppTask; import android.app.Application; +import android.app.WindowConfiguration; import android.content.Context; import android.graphics.Rect; import android.os.Bundle; @@ -183,7 +186,7 @@ public class WindowLayoutComponentImpl implements WindowLayoutComponent { return features; } - if (activity.isInMultiWindowMode()) { + if (isTaskInMultiWindowMode(activity)) { // It is recommended not to report any display features in multi-window mode, since it // won't be possible to synchronize the display feature positions with window movement. return features; @@ -209,6 +212,32 @@ public class WindowLayoutComponentImpl implements WindowLayoutComponent { return features; } + /** + * Checks whether the task associated with the activity is in multi-window. If task info is not + * available it defaults to {@code true}. + */ + private boolean isTaskInMultiWindowMode(@NonNull Activity activity) { + final ActivityManager am = activity.getSystemService(ActivityManager.class); + if (am == null) { + return true; + } + + final List appTasks = am.getAppTasks(); + final int taskId = activity.getTaskId(); + AppTask task = null; + for (AppTask t : appTasks) { + if (t.getTaskInfo().taskId == taskId) { + task = t; + break; + } + } + if (task == null) { + // The task might be removed on the server already. + return true; + } + return WindowConfiguration.inMultiWindowMode(task.getTaskInfo().getWindowingMode()); + } + /** * Returns {@link true} if a {@link Rect} has zero width and zero height, * {@code false} otherwise.