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
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 17c8edc..2e1cc58 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -1922,6 +1922,11 @@
                     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();