Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 56c73604 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Verify that the widget id is valid, before binding the widget

Bug: 23820213
Bug: 24054205
Bug: 24582322
Change-Id: I25a09b0a2a706812a7d82729b5dc554ffba84a2a
parent cf12698f
Loading
Loading
Loading
Loading
+17 −8
Original line number Diff line number Diff line
@@ -2398,11 +2398,13 @@ public class Launcher extends Activity
            }
        } else if (itemInfo instanceof LauncherAppWidgetInfo) {
            final LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) itemInfo;
            unbindAppWidget(widgetInfo, deleteFromDb);
            mWorkspace.removeWorkspaceItem(v);
            removeWidgetToAutoAdvance(widgetInfo.hostView);
            widgetInfo.hostView = null;
            if (deleteFromDb) {
                LauncherModel.deleteItemFromDatabase(this, widgetInfo);
                deleteWidgetInfo(widgetInfo);
            }

        } else {
            return false;
        }
@@ -2417,12 +2419,11 @@ public class Launcher extends Activity
    }

    /**
     * Unbinds any launcher references to the widget and deletes the app widget id.
     * Deletes the widget info and the widget id.
     */
    private void unbindAppWidget(final LauncherAppWidgetInfo widgetInfo, boolean deleteAppWidgetId) {
    private void deleteWidgetInfo(final LauncherAppWidgetInfo widgetInfo) {
        final LauncherAppWidgetHost appWidgetHost = getAppWidgetHost();
        if (deleteAppWidgetId && appWidgetHost != null &&
                !widgetInfo.isCustomWidget() && widgetInfo.isWidgetIdValid()) {
        if (appWidgetHost != null && !widgetInfo.isCustomWidget() && widgetInfo.isWidgetIdValid()) {
            // Deleting an app widget ID is a void call but writes to disk before returning
            // to the caller...
            new AsyncTask<Void, Void, Void>() {
@@ -2432,8 +2433,7 @@ public class Launcher extends Activity
                }
            }.executeOnExecutor(Utilities.THREAD_POOL_EXECUTOR);
        }
        removeWidgetToAutoAdvance(widgetInfo.hostView);
        widgetInfo.hostView = null;
        LauncherModel.deleteItemFromDatabase(this, widgetInfo);
    }

    @Override
@@ -4001,6 +4001,15 @@ public class Launcher extends Activity
                        + appWidgetInfo.provider);
            }

            // Verify that we own the widget
            AppWidgetProviderInfo info = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
            if (info == null || appWidgetInfo == null ||
                    !info.provider.equals(appWidgetInfo.provider)) {
                Log.e(TAG, "Removing invalid widget: id=" + item.appWidgetId);
                deleteWidgetInfo(item);
                return;
            }

            item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
            item.minSpanX = appWidgetInfo.minSpanX;
            item.minSpanY = appWidgetInfo.minSpanY;