Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ece9feac authored by Louis Chang's avatar Louis Chang
Browse files

Prevent systemui crash by adding view to an invalid display

The newly added display was removed before the #onDisplayAdded()
is called, which resulted InvalidDisplayException while adding view.

Bug: 173683353
Test: presubmit
Change-Id: I8f6b939e906ab2e898ff908d6a96b8cd3986ed8d
parent f2b1d840
Loading
Loading
Loading
Loading
+17 −5
Original line number Diff line number Diff line
@@ -54,7 +54,6 @@ import com.android.wm.shell.common.DisplayController;
import com.android.wm.shell.protolog.ShellProtoLogGroup;
import com.android.wm.shell.splitscreen.SplitScreen;

import java.util.Objects;
import java.util.Optional;

/**
@@ -108,16 +107,22 @@ public class DragAndDropController implements DisplayController.OnDisplaysChange
        DragLayout dragLayout = new DragLayout(context, mSplitScreen);
        rootView.addView(dragLayout,
                new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
        try {
            wm.addView(rootView, layoutParams);

            mDisplayDropTargets.put(displayId,
                    new PerDisplay(displayId, context, wm, rootView, dragLayout));
        } catch (WindowManager.InvalidDisplayException e) {
            Slog.w(TAG, "Unable to add view for display id: " + displayId);
        }
    }

    @Override
    public void onDisplayConfigurationChanged(int displayId, Configuration newConfig) {
        ProtoLog.v(ShellProtoLogGroup.WM_SHELL_DRAG_AND_DROP, "Display changed: %d", displayId);
        final PerDisplay pd = mDisplayDropTargets.get(displayId);
        if (pd == null) {
            return;
        }
        pd.rootView.requestApplyInsets();
    }

@@ -125,6 +130,9 @@ public class DragAndDropController implements DisplayController.OnDisplaysChange
    public void onDisplayRemoved(int displayId) {
        ProtoLog.v(ShellProtoLogGroup.WM_SHELL_DRAG_AND_DROP, "Display removed: %d", displayId);
        final PerDisplay pd = mDisplayDropTargets.get(displayId);
        if (pd == null) {
            return;
        }
        pd.wm.removeViewImmediate(pd.rootView);
        mDisplayDropTargets.remove(displayId);
    }
@@ -139,6 +147,10 @@ public class DragAndDropController implements DisplayController.OnDisplaysChange
        final PerDisplay pd = mDisplayDropTargets.get(displayId);
        final ClipDescription description = event.getClipDescription();

        if (pd == null) {
            return false;
        }

        if (event.getAction() == ACTION_DRAG_STARTED) {
            final boolean hasValidClipData = event.getClipData().getItemCount() > 0
                    && (description.hasMimeType(MIMETYPE_APPLICATION_ACTIVITY)