From f452138f7bc4e51f1471ecbaf924c48a02e054f6 Mon Sep 17 00:00:00 2001 From: Emilian Peev Date: Wed, 2 Mar 2022 14:52:45 -0800 Subject: [PATCH] CameraServiceProxy: Extend the recent app resizeable query The camera rotate & crop heuristics depend on the package resizeability flag which is queried from the task manager recent list. In split screen mode the list can include several packages and the camera app may not be the first entry in that list. Bug: 222350953 Test: Manual using camera application Change-Id: Iad7a974e09830fab533202cde149a880821cd13a --- .../server/camera/CameraServiceProxy.java | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/services/core/java/com/android/server/camera/CameraServiceProxy.java b/services/core/java/com/android/server/camera/CameraServiceProxy.java index e0b768d7c5926..ecb43f601a86c 100644 --- a/services/core/java/com/android/server/camera/CameraServiceProxy.java +++ b/services/core/java/com/android/server/camera/CameraServiceProxy.java @@ -467,7 +467,8 @@ public class CameraServiceProxy extends SystemService ParceledListSlice recentTasks = null; try { - recentTasks = ActivityTaskManager.getService().getRecentTasks(/*maxNum*/1, + // Get 2 recent tasks in case we are running in split mode + recentTasks = ActivityTaskManager.getService().getRecentTasks(/*maxNum*/2, /*flags*/ 0, userId); } catch (RemoteException e) { Log.e(TAG, "Failed to query recent tasks!"); @@ -475,23 +476,27 @@ public class CameraServiceProxy extends SystemService } if ((recentTasks != null) && (!recentTasks.getList().isEmpty())) { - ActivityManager.RecentTaskInfo task = recentTasks.getList().get(0); - if (packageName.equals(task.topActivityInfo.packageName)) { - taskInfo = new TaskInfo(); - taskInfo.frontTaskId = task.taskId; - taskInfo.isResizeable = - (task.topActivityInfo.resizeMode != RESIZE_MODE_UNRESIZEABLE); - taskInfo.displayId = task.displayId; - taskInfo.userId = task.userId; - taskInfo.isFixedOrientationLandscape = - ActivityInfo.isFixedOrientationLandscape( - task.topActivityInfo.screenOrientation); - taskInfo.isFixedOrientationPortrait = - ActivityInfo.isFixedOrientationPortrait( - task.topActivityInfo.screenOrientation); - } else { - Log.e(TAG, "Recent task package name: " + task.topActivityInfo.packageName - + " doesn't match with camera client package name: " + packageName); + for (ActivityManager.RecentTaskInfo task : recentTasks.getList()) { + if (packageName.equals(task.topActivityInfo.packageName)) { + taskInfo = new TaskInfo(); + taskInfo.frontTaskId = task.taskId; + taskInfo.isResizeable = + (task.topActivityInfo.resizeMode != RESIZE_MODE_UNRESIZEABLE); + taskInfo.displayId = task.displayId; + taskInfo.userId = task.userId; + taskInfo.isFixedOrientationLandscape = + ActivityInfo.isFixedOrientationLandscape( + task.topActivityInfo.screenOrientation); + taskInfo.isFixedOrientationPortrait = + ActivityInfo.isFixedOrientationPortrait( + task.topActivityInfo.screenOrientation); + break; + } + } + + if (taskInfo == null) { + Log.e(TAG, "Recent tasks don't include camera client package name: " + + packageName); return CaptureRequest.SCALER_ROTATE_AND_CROP_NONE; } } else {