From c1d296813e09b1a603b64befcdead3a0e6131230 Mon Sep 17 00:00:00 2001 From: caizhixing Date: Tue, 10 Nov 2026 22:58:30 -0800 Subject: [PATCH] fix: NPE in Workspace.onDropExternal when the dropped view fails to attach to the workspace (#7524) Co-authored-by: caizhixing --- src/com/android/launcher3/Workspace.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 343c943988..1c885932c2 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -3239,6 +3239,16 @@ public class Workspace extends PagedView cellLayout.onDropChild(view); cellLayout.getShortcutsAndWidgets().measureChild(view); + // addInScreen can fail to attach the view through any of its silent failure + // branches (unknown screen id, missing hotseat page, or addViewToCellLayout + // returning false). Animating a detached view into position then crashes with + // an NPE in DragLayer#animateViewIntoPosition when it dereferences the missing + // parent. Skip the drop animation and clean up the drag view instead; the item + // was already committed to the model above and reappears on the next bind. + if (!(view.getParent() instanceof ShortcutAndWidgetContainer)) { + d.deferDragViewCleanupPostAnimation = false; + return; + } if (d.dragView != null) { // We wrap the animation call in the temporary set and reset of the current // cellLayout to its final transform -- this means we animate the drag view to