Log the reason why a WorkspaceItemInfo was removed
In the past we've seen a WorkspaceItem disappeared from the workspace
but wasn't able to determine why it was removed. This CL includes the
reason why it was removed in the error log, which hopefully would help
us debugging similar issues in the future.
Bug: 231239260
Test: make
Change-Id: Iba3d57568c9b3e011a6b65b26f0d4170d42fe1a5
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 135b88d..11bc11f 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -1956,6 +1956,19 @@
* @param deleteFromDb whether or not to delete this item from the db.
*/
public boolean removeItem(View v, final ItemInfo itemInfo, boolean deleteFromDb) {
+ return removeItem(v, itemInfo, deleteFromDb, null);
+ }
+
+ /**
+ * Unbinds the view for the specified item, and removes the item and all its children.
+ *
+ * @param v the view being removed.
+ * @param itemInfo the {@link ItemInfo} for this view.
+ * @param deleteFromDb whether or not to delete this item from the db.
+ * @param reason the resaon for removal.
+ */
+ public boolean removeItem(View v, final ItemInfo itemInfo, boolean deleteFromDb,
+ @Nullable final String reason) {
if (itemInfo instanceof WorkspaceItemInfo) {
// Remove the shortcut from the folder before removing it from launcher
View folderIcon = mWorkspace.getHomescreenIconByItemId(itemInfo.container);
@@ -1965,7 +1978,7 @@
mWorkspace.removeWorkspaceItem(v);
}
if (deleteFromDb) {
- getModelWriter().deleteItemFromDatabase(itemInfo);
+ getModelWriter().deleteItemFromDatabase(itemInfo, reason);
}
} else if (itemInfo instanceof FolderInfo) {
final FolderInfo folderInfo = (FolderInfo) itemInfo;
@@ -1980,7 +1993,7 @@
final LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) itemInfo;
mWorkspace.removeWorkspaceItem(v);
if (deleteFromDb) {
- getModelWriter().deleteWidgetInfo(widgetInfo, getAppWidgetHost());
+ getModelWriter().deleteWidgetInfo(widgetInfo, getAppWidgetHost(), reason);
}
} else {
return false;
@@ -2399,8 +2412,7 @@
if (FeatureFlags.IS_STUDIO_BUILD) {
throw (new RuntimeException(desc));
} else {
- Log.d(TAG, desc);
- getModelWriter().deleteItemFromDatabase(item);
+ getModelWriter().deleteItemFromDatabase(item, desc);
if (TestProtocol.sDebugTracing) {
Log.d(TestProtocol.MISSING_PROMISE_ICON,
TAG + "bindItems failed for item=" + item);
@@ -2480,7 +2492,8 @@
if (item.hasOptionFlag(LauncherAppWidgetInfo.OPTION_SEARCH_WIDGET)) {
item.providerName = QsbContainerView.getSearchComponentName(this);
if (item.providerName == null) {
- getModelWriter().deleteItemFromDatabase(item);
+ getModelWriter().deleteItemFromDatabase(item,
+ "search widget removed because search component cannot be found");
return null;
}
}
@@ -2531,10 +2544,10 @@
if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY)
&& (item.restoreStatus != LauncherAppWidgetInfo.RESTORE_COMPLETED)) {
if (appWidgetInfo == null) {
- FileLog.d(TAG, "Removing restored widget: id=" + item.appWidgetId
+ getModelWriter().deleteItemFromDatabase(item,
+ "Removing restored widget: id=" + item.appWidgetId
+ " belongs to component " + item.providerName + " user " + item.user
+ ", as the provider is null and " + removalReason);
- getModelWriter().deleteItemFromDatabase(item);
return null;
}
@@ -2604,7 +2617,7 @@
// Verify that we own the widget
if (appWidgetInfo == null) {
FileLog.e(TAG, "Removing invalid widget: id=" + item.appWidgetId);
- getModelWriter().deleteWidgetInfo(item, getAppWidgetHost());
+ getModelWriter().deleteWidgetInfo(item, getAppWidgetHost(), removalReason);
return null;
}