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

Commit 49c076af authored by Merissa Mitchell's avatar Merissa Mitchell
Browse files

Don't handle touch event if WindowDecoration is null

When an app crashes while dragging the window, handling the
ACTION_CANCEL touch event will cause a crash due to the WindowDecoration
being null. We should really bypass the touch handling if there is no
WindowDecoration in onTouch.

Bug: 409313582
Test: atest DesktopModeWindowDecorViewModelTests
Flag: EXEMPT bugfix
Change-Id: I71718ce00a43de9308eeaf77e6623d131640e81b
parent 5210ef7e
Loading
Loading
Loading
Loading
+7 −9
Original line number Diff line number Diff line
@@ -1169,6 +1169,10 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
            mMotionEvent = e;
            final int id = v.getId();
            final DesktopModeWindowDecoration decoration = mWindowDecorByTaskId.get(mTaskId);
            if (decoration == null) {
                return false;
            }
            final ActivityManager.RunningTaskInfo taskInfo = decoration.mTaskInfo;
            final boolean touchscreenSource =
                    (e.getSource() & SOURCE_TOUCHSCREEN) == SOURCE_TOUCHSCREEN;
            // Disable long click during events from a non-touchscreen source
@@ -1180,7 +1184,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
                    && id != R.id.maximize_window && id != R.id.minimize_window) {
                return false;
            }
            final boolean isAppHandle = !getTaskInfo().isFreeform();
            final boolean isAppHandle = !taskInfo.isFreeform();
            final int actionMasked = e.getActionMasked();
            final boolean isDown = actionMasked == MotionEvent.ACTION_DOWN;
            final boolean isUpOrCancel = actionMasked == MotionEvent.ACTION_CANCEL
@@ -1193,7 +1197,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
                //  task surface to the top of other tasks and reorder once the user releases the
                //  gesture together with the bounds' WCT. This is probably still valid for other
                //  gestures like simple clicks.
                moveTaskToFront(decoration.mTaskInfo);
                moveTaskToFront(taskInfo);

                final boolean downInCustomizableCaptionRegion =
                        decoration.checkTouchEventInCustomizableRegion(e);
@@ -1202,7 +1206,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
                final boolean downInExclusionRegion =
                        exclusionRegion.contains((int) e.getRawX(), (int) e.getRawY());
                final boolean isTransparentCaption =
                        TaskInfoKt.isTransparentCaptionBarAppearance(decoration.mTaskInfo);
                        TaskInfoKt.isTransparentCaptionBarAppearance(taskInfo);
                // MotionEvent's coordinates are relative to view, we want location in window
                // to offset position relative to caption as a whole.
                int[] viewLocation = new int[2];
@@ -1314,12 +1318,6 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
            }
        }

        @NonNull
        private RunningTaskInfo getTaskInfo() {
            final DesktopModeWindowDecoration decoration = mWindowDecorByTaskId.get(mTaskId);
            return decoration.mTaskInfo;
        }

        private boolean handleNonFreeformMotionEvent(DesktopModeWindowDecoration decoration,
                View v, MotionEvent e) {
            final int id = v.getId();