From 50216bcc62a3dd1a81f94c73aef85612acb26283 Mon Sep 17 00:00:00 2001 From: Gaurav Bhola Date: Thu, 18 May 2023 09:26:12 -0700 Subject: [PATCH] Handle the case where launch root is not attached - Throw illegalstateException if the task that is being set as launch root task is not attached to the wm hierarchy - in other words: when it doesn't have a display area. - This makes sure that system server doesn't crash with NPE when this happens. Bug: 283152174 Test: Tested manually using the car portrait target Change-Id: I330560cbb1ecf8f267c37e1696084b6872c3068e --- .../com/android/server/wm/WindowOrganizerController.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/wm/WindowOrganizerController.java b/services/core/java/com/android/server/wm/WindowOrganizerController.java index 09312bac593f2..7e34d15ddcfce 100644 --- a/services/core/java/com/android/server/wm/WindowOrganizerController.java +++ b/services/core/java/com/android/server/wm/WindowOrganizerController.java @@ -845,11 +845,14 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub case HIERARCHY_OP_TYPE_SET_LAUNCH_ROOT: { final WindowContainer wc = WindowContainer.fromBinder(hop.getContainer()); final Task task = wc != null ? wc.asTask() : null; - if (task != null) { + if (task == null) { + throw new IllegalArgumentException("Cannot set non-task as launch root: " + wc); + } else if (task.getTaskDisplayArea() == null) { + throw new IllegalArgumentException("Cannot set a task without display area as " + + "launch root: " + wc); + } else { task.getDisplayArea().setLaunchRootTask(task, hop.getWindowingModes(), hop.getActivityTypes()); - } else { - throw new IllegalArgumentException("Cannot set non-task as launch root: " + wc); } break; }