From a5858ed4e44fbc1b6c291d2e7506952f95633b06 Mon Sep 17 00:00:00 2001 From: Evan Rosky Date: Tue, 21 Apr 2020 18:47:37 -0700 Subject: [PATCH] Ignore task-info changed callbacks in uninitialized Divider Apparently there is a chance that SysUI crashes without system server receiving binder-death (or maybe it receives binder-death too late?). In this situation, when sys-ui restarts, the split root-tasks will still exist so there is a small window of time during init() where WM might send messages to the new organizer before init() finishes running. This avoids a cycle of crashes by returning early, but if this is hit, the system is likely in a weird state and Divider probably won't work. Bug: 153811023 Test: Will need to wait and see. Too low repro rate. Change-Id: Id42569b4699699dbc7eaa63eaff801c7c52314c7 --- .../stackdivider/SplitScreenTaskOrganizer.java | 14 ++++++++++---- .../systemui/stackdivider/WindowManagerProxy.java | 5 ----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/stackdivider/SplitScreenTaskOrganizer.java b/packages/SystemUI/src/com/android/systemui/stackdivider/SplitScreenTaskOrganizer.java index a4b1310687aa7..f5d6cb6fd4b0a 100644 --- a/packages/SystemUI/src/com/android/systemui/stackdivider/SplitScreenTaskOrganizer.java +++ b/packages/SystemUI/src/com/android/systemui/stackdivider/SplitScreenTaskOrganizer.java @@ -33,10 +33,8 @@ import android.view.SurfaceControl; import android.view.SurfaceSession; import android.window.TaskOrganizer; -import java.util.ArrayList; - class SplitScreenTaskOrganizer extends TaskOrganizer { - private static final String TAG = "SplitScreenTaskOrganizer"; + private static final String TAG = "SplitScreenTaskOrg"; private static final boolean DEBUG = Divider.DEBUG; RunningTaskInfo mPrimary; @@ -45,7 +43,6 @@ class SplitScreenTaskOrganizer extends TaskOrganizer { SurfaceControl mSecondarySurface; SurfaceControl mPrimaryDim; SurfaceControl mSecondaryDim; - ArrayList mHomeAndRecentsSurfaces = new ArrayList<>(); Rect mHomeBounds = new Rect(); final Divider mDivider; private boolean mSplitScreenSupported = false; @@ -110,6 +107,15 @@ class SplitScreenTaskOrganizer extends TaskOrganizer { * presentations based on the contents of the split regions. */ private void handleTaskInfoChanged(RunningTaskInfo info) { + if (!mSplitScreenSupported) { + // This shouldn't happen; but apparently there is a chance that SysUI crashes without + // system server receiving binder-death (or maybe it receives binder-death too late?). + // In this situation, when sys-ui restarts, the split root-tasks will still exist so + // there is a small window of time during init() where WM might send messages here + // before init() fails. So, avoid a cycle of crashes by returning early. + Log.e(TAG, "Got handleTaskInfoChanged when not initialized: " + info); + return; + } final boolean secondaryWasHomeOrRecents = mSecondary.topActivityType == ACTIVITY_TYPE_HOME || mSecondary.topActivityType == ACTIVITY_TYPE_RECENTS; final boolean primaryWasEmpty = mPrimary.topActivityType == ACTIVITY_TYPE_UNDEFINED; diff --git a/packages/SystemUI/src/com/android/systemui/stackdivider/WindowManagerProxy.java b/packages/SystemUI/src/com/android/systemui/stackdivider/WindowManagerProxy.java index 5aa7946bcb7f4..3027bd225216c 100644 --- a/packages/SystemUI/src/com/android/systemui/stackdivider/WindowManagerProxy.java +++ b/packages/SystemUI/src/com/android/systemui/stackdivider/WindowManagerProxy.java @@ -174,12 +174,8 @@ public class WindowManagerProxy { if (rootTasks.isEmpty()) { return false; } - tiles.mHomeAndRecentsSurfaces.clear(); for (int i = rootTasks.size() - 1; i >= 0; --i) { final ActivityManager.RunningTaskInfo rootTask = rootTasks.get(i); - if (isHomeOrRecentTask(rootTask)) { - tiles.mHomeAndRecentsSurfaces.add(rootTask.token.getLeash()); - } // Only move resizeable task to split secondary. WM will just ignore this anyways... if (!rootTask.isResizable()) continue; // Only move fullscreen tasks to split secondary. @@ -211,7 +207,6 @@ public class WindowManagerProxy { // Set launch root first so that any task created after getChildContainers and // before reparent (pretty unlikely) are put into fullscreen. TaskOrganizer.setLaunchRoot(Display.DEFAULT_DISPLAY, null); - tiles.mHomeAndRecentsSurfaces.clear(); // TODO(task-org): Once task-org is more complete, consider using Appeared/Vanished // plus specific APIs to clean this up. List primaryChildren =