From 77a1393c4484a78da20cc3943ed3221976e68a93 Mon Sep 17 00:00:00 2001 From: Steven Ng Date: Fri, 11 Jun 2021 20:17:02 +0100 Subject: [PATCH] Fix CellLayout cast exception when drag is canceled Test: Long press a widget and then release when the resize frame is shown. Then, click the content of the widget to launch the widget's activity. Go back to home screen and then immediately long press the same widget again. No crash was observed. Bug: 189814379 Change-Id: I4232ecf9d9d9efaba817b7777314f0814bb7ef21 --- src/com/android/launcher3/Workspace.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 17c8edce6e..2e1cc58aa0 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -1922,6 +1922,11 @@ public class Workspace extends PagedView CellLayout layout = (CellLayout) cell.getParent().getParent(); layout.markCellsAsOccupiedForView(cell); } + } else { + // When drag is cancelled, reattach content view back to its original parent. + if (mDragInfo.cell instanceof LauncherAppWidgetHostView) { + d.dragView.detachContentView(/* reattachToPreviousParent= */ true); + } } final CellLayout parent = (CellLayout) cell.getParent().getParent();