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

Commit 7779852b authored by Charlie Anderson's avatar Charlie Anderson
Browse files

add more logging for failure to load Widgets

Bug: 294386159
Test: locally
Flag: N/A
Change-Id: Ib1fc2c28d1f20142658077047bbe6bc2eabe49d4
parent 1a59da4e
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -333,7 +333,7 @@ public class DatabaseHelper extends NoLocaleSQLiteHelper implements
            for (int widgetId : allWidgets) {
                if (!validWidgets.contains(widgetId)) {
                    try {
                        FileLog.d(TAG, "Deleting invalid widget " + widgetId);
                        FileLog.d(TAG, "Deleting widget not found in db: appWidgetId=" + widgetId);
                        holder.deleteAppWidgetId(widgetId);
                        isAnyWidgetRemoved = true;
                    } catch (RuntimeException e) {
@@ -342,15 +342,17 @@ public class DatabaseHelper extends NoLocaleSQLiteHelper implements
                }
            }
            if (isAnyWidgetRemoved) {
                final String allWidgetsIds = Arrays.stream(allWidgets).mapToObj(String::valueOf)
                final String allLauncherHostWidgetIds = Arrays.stream(allWidgets)
                        .mapToObj(String::valueOf)
                        .collect(Collectors.joining(",", "[", "]"));
                final String validWidgetsIds = Arrays.stream(
                final String allValidLauncherDbWidgetIds = Arrays.stream(
                                validWidgets.getArray().toArray()).mapToObj(String::valueOf)
                        .collect(Collectors.joining(",", "[", "]"));
                FileLog.d(TAG,
                        "One or more widgets was removed. db_path=" + db.getPath()
                                + " allWidgetsIds=" + allWidgetsIds
                                + ", validWidgetsIds=" + validWidgetsIds);
                        "One or more widgets was removed: "
                                + " allLauncherHostWidgetIds=" + allLauncherHostWidgetIds
                                + ", allValidLauncherDbWidgetIds=" + allValidLauncherDbWidgetIds
                );
            }
        } finally {
            holder.destroy();
+24 −5
Original line number Diff line number Diff line
@@ -410,14 +410,21 @@ class WorkspaceItemProcessor(
        appWidgetInfo.restoreStatus = c.restoreFlag
        if (appWidgetInfo.spanX <= 0 || appWidgetInfo.spanY <= 0) {
            c.markDeleted(
                "Widget has invalid size: ${appWidgetInfo.spanX}x${appWidgetInfo.spanY}",
                "processWidget: Widget has invalid size: ${appWidgetInfo.spanX}x${appWidgetInfo.spanY}" +
                    ", id=${c.id}," +
                    ", appWidgetId=${c.appWidgetId}," +
                    ", component=${component}",
                RestoreError.INVALID_LOCATION
            )
            return
        }
        if (!c.isOnWorkspaceOrHotseat) {
            c.markDeleted(
                "Widget found where container != CONTAINER_DESKTOP nor CONTAINER_HOTSEAT - ignoring!",
                "processWidget: invalid Widget container != CONTAINER_DESKTOP nor CONTAINER_HOTSEAT." +
                    " id=${c.id}," +
                    ", appWidgetId=${c.appWidgetId}," +
                    ", component=${component}," +
                    ", container=${c.container}",
                RestoreError.INVALID_LOCATION
            )
            return
@@ -428,7 +435,12 @@ class WorkspaceItemProcessor(
        val inflationResult = widgetInflater.inflateAppWidget(appWidgetInfo)
        var shouldUpdate = inflationResult.isUpdate
        val lapi = inflationResult.widgetInfo

        FileLog.d(
            TAG,
            "processWidget: id=${c.id}" +
                ", appWidgetId=${c.appWidgetId}" +
                ", inflationResult=$inflationResult"
        )
        when (inflationResult.type) {
            WidgetInflater.TYPE_DELETE -> {
                c.markDeleted(inflationResult.reason, inflationResult.restoreErrorType)
@@ -448,7 +460,11 @@ class WorkspaceItemProcessor(
                ) {
                    // Restore never started
                    c.markDeleted(
                        "Unrestored widget removed: $component",
                        "processWidget: Unrestored Pending widget removed:" +
                            " id=${c.id}" +
                            ", appWidgetId=${c.appWidgetId}" +
                            ", component=${component}" +
                            ", restoreFlag:=${c.restoreFlag}",
                        RestoreError.APP_NOT_INSTALLED
                    )
                    return
@@ -491,7 +507,10 @@ class WorkspaceItemProcessor(
            if (appWidgetInfo.spanX < lapi.minSpanX || appWidgetInfo.spanY < lapi.minSpanY) {
                FileLog.d(
                    TAG,
                    "Widget ${lapi.component} minSizes not meet: span=${appWidgetInfo.spanX}x${appWidgetInfo.spanY} minSpan=${lapi.minSpanX}x${lapi.minSpanY}"
                    " processWidget: Widget ${lapi.component} minSizes not met: span=${appWidgetInfo.spanX}x${appWidgetInfo.spanY} minSpan=${lapi.minSpanX}x${lapi.minSpanY}," +
                        " id: ${c.id}," +
                        " appWidgetId: ${c.appWidgetId}," +
                        " component=${component}"
                )
                logWidgetInfo(app.invariantDeviceProfile, lapi)
            }
+1 −1
Original line number Diff line number Diff line
@@ -456,7 +456,7 @@ public class RestoreDbTask {
        logDatabaseWidgetInfo(controller);

        for (int i = 0; i < oldWidgetIds.length; i++) {
            FileLog.i(TAG, "Widget state restore id " + oldWidgetIds[i] + " => " + newWidgetIds[i]);
            FileLog.i(TAG, "migrating appWidgetId: " + oldWidgetIds[i] + " => " + newWidgetIds[i]);

            final AppWidgetProviderInfo provider = widgets.getAppWidgetInfo(newWidgetIds[i]);
            final int state;
+12 −3
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;

import com.android.launcher3.logging.FileLog;
import com.android.launcher3.model.WidgetsModel;
import com.android.launcher3.model.data.LauncherAppWidgetInfo;
import com.android.launcher3.pm.UserCache;
@@ -46,6 +47,7 @@ import java.util.stream.Stream;
 */
public class WidgetManagerHelper {

    private static final String TAG = "WidgetManagerHelper";
    //TODO: replace this with OPTION_APPWIDGET_RESTORE_COMPLETED b/63667276
    public static final String WIDGET_OPTION_RESTORE_COMPLETED = "appWidgetRestoreCompleted";

@@ -60,6 +62,7 @@ public class WidgetManagerHelper {
    /**
     * @see AppWidgetManager#getAppWidgetInfo(int)
     */
    @Nullable
    public LauncherAppWidgetProviderInfo getLauncherAppWidgetInfo(
            int appWidgetId, ComponentName componentName) {

@@ -69,7 +72,14 @@ public class WidgetManagerHelper {
        }

        AppWidgetProviderInfo info = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
        return info == null ? null : LauncherAppWidgetProviderInfo.fromProviderInfo(mContext, info);
        if (info == null) {
            FileLog.w(TAG,
                    "getLauncherAppWidgetInfo: AppWidgetManager returned null AppWidgetInfo for"
                            + " appWidgetId=" + appWidgetId
                            + ", componentName=" + componentName);
            return null;
        }
        return LauncherAppWidgetProviderInfo.fromProviderInfo(mContext, info);
    }

    /**
@@ -139,7 +149,6 @@ public class WidgetManagerHelper {
     *
     * @param info           The provider info for the widget you want to preview.
     * @param widgetCategory The widget category for which you want to display previews.
     *
     * @return Returns the widget preview that matches selected category, if available.
     */
    @Nullable