From 553f62019b0a87daf900919c85358400c82cac6a Mon Sep 17 00:00:00 2001 From: Jerry Chang Date: Tue, 7 Sep 2021 09:02:44 +0800 Subject: [PATCH] Prevent NPE when checking focused stage before root task is ready If the root task of the stage is not created, treat the stage as not focused to prevent trowing NPE when traversing the root task and its child. Fix: 199060332 Test: manual check isFocused won't throw before root task is ready Change-Id: I3869f934b641c8ffd77730452d0501d65063785c --- .../wm/shell/splitscreen/StageTaskListener.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageTaskListener.java b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageTaskListener.java index 3512a0c3727bf..da91c1c41473f 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageTaskListener.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageTaskListener.java @@ -113,10 +113,20 @@ class StageTaskListener implements ShellTaskOrganizer.TaskListener { /** @return {@code true} if this listener contains the currently focused task. */ boolean isFocused() { - if (mRootTaskInfo.isFocused) return true; - for (int i = mChildrenTaskInfo.size() - 1; i >= 0; --i) { - if (mChildrenTaskInfo.valueAt(i).isFocused) return true; + if (mRootTaskInfo == null) { + return false; } + + if (mRootTaskInfo.isFocused) { + return true; + } + + for (int i = mChildrenTaskInfo.size() - 1; i >= 0; --i) { + if (mChildrenTaskInfo.valueAt(i).isFocused) { + return true; + } + } + return false; }