From a5e145377938b589996b86703e03fd396fd36596 Mon Sep 17 00:00:00 2001 From: Steven Ng Date: Mon, 14 Jun 2021 23:59:28 +0100 Subject: [PATCH] Reattach LauncherAppWidgetHostView to its parent after canceling drag onDrop isn't called if the drag is canceled at Launcher.onPause. Let's also reattach LauncherAppWidgetHostView to its parent in this case. Test: long press and hold a widget and, at the same time, press the power button. Don't let go of the long press and press the power button. No crash observed. Fix: 190950646 Change-Id: Id52a51291863b7ef63c861eb6dc23b015484be65 --- src/com/android/launcher3/Workspace.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 2e1cc58aa0..303bb01df0 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -2791,6 +2791,10 @@ public class Workspace extends PagedView removeWorkspaceItem(mDragInfo.cell); } } else if (mDragInfo != null) { + // When drag is cancelled, reattach content view back to its original parent. + if (mDragInfo.cell instanceof LauncherAppWidgetHostView) { + d.dragView.detachContentView(/* reattachToPreviousParent= */ true); + } final CellLayout cellLayout = mLauncher.getCellLayout( mDragInfo.container, mDragInfo.screenId); if (cellLayout != null) {