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

Commit 0171058c authored by Charlie Anderson's avatar Charlie Anderson Committed by Android (Google) Code Review
Browse files

Merge "add more logging around package updates and widget click handling in Launcher" into main

parents 399638ac 5fa4f02c
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ public class AllAppsList {

    private static final String TAG = "AllAppsList";
    private static final Consumer<AppInfo> NO_OP_CONSUMER = a -> { };

    private static final boolean DEBUG = true;

    public static final int DEFAULT_APPLICATIONS_NUMBER = 42;

@@ -220,6 +220,11 @@ public class AllAppsList {
                    updatedAppInfos.add(appInfo);
                } else if (installInfo.state == PackageInstallInfo.STATUS_FAILED
                        && !appInfo.isAppStartable()) {
                    if (DEBUG) {
                        Log.w(TAG, "updatePromiseInstallInfo: removing app due to install"
                                + " failure and appInfo not startable."
                                + " package=" + appInfo.getTargetPackage());
                    }
                    removeApp(i);
                }
            }
@@ -312,7 +317,10 @@ public class AllAppsList {
                if (user.equals(applicationInfo.user)
                        && packageName.equals(applicationInfo.componentName.getPackageName())) {
                    if (!findActivity(matches, applicationInfo.componentName)) {
                        Log.w(TAG, "Changing shortcut target due to app component name change.");
                        if (DEBUG) {
                            Log.w(TAG, "Changing shortcut target due to app component name change."
                                    + " package=" + packageName);
                        }
                        removeApp(i);
                    }
                }
@@ -337,6 +345,10 @@ public class AllAppsList {
            }
        } else {
            // Remove all data for this package.
            if (DEBUG) {
                Log.w(TAG, "updatePromiseInstallInfo: no Activities matched updated package,"
                        + " removing all apps from package=" + packageName);
            }
            for (int i = data.size() - 1; i >= 0; i--) {
                final AppInfo applicationInfo = data.get(i);
                if (user.equals(applicationInfo.user)
+53 −12
Original line number Diff line number Diff line
@@ -74,8 +74,8 @@ import java.util.stream.Collectors;
public class PackageUpdatedTask implements ModelUpdateTask {

    // TODO(b/290090023): Set to false after root causing is done.
    private static final boolean DEBUG = true;
    private static final String TAG = "PackageUpdatedTask";
    private static final boolean DEBUG = true;

    public static final int OP_NONE = 0;
    public static final int OP_ADD = 1;
@@ -117,13 +117,19 @@ public class PackageUpdatedTask implements ModelUpdateTask {
                : ItemInfoMatcher.ofPackages(packageSet, mUser);
        final HashSet<ComponentName> removedComponents = new HashSet<>();
        final HashMap<String, List<LauncherActivityInfo>> activitiesLists = new HashMap<>();

        if (DEBUG) {
            Log.d(TAG, "Package updated: mOp=" + getOpString()
                    + " packages=" + Arrays.toString(packages));
        }
        switch (mOp) {
            case OP_ADD: {
                for (int i = 0; i < N; i++) {
                    if (DEBUG) Log.d(TAG, "mAllAppsList.addPackage " + packages[i]);
                    iconCache.updateIconsForPkg(packages[i], mUser);
                    if (FeatureFlags.PROMISE_APPS_IN_ALL_APPS.get()) {
                        if (DEBUG) {
                            Log.d(TAG, "OP_ADD: PROMISE_APPS_IN_ALL_APPS enabled:"
                                    + " removing promise icon apps from package=" + packages[i]);
                        }
                        appsList.removePackage(packages[i], mUser);
                    }
                    activitiesLists.put(packages[i],
@@ -133,10 +139,14 @@ public class PackageUpdatedTask implements ModelUpdateTask {
                break;
            }
            case OP_UPDATE:
                try (SafeCloseable t =
                             appsList.trackRemoves(a -> removedComponents.add(a.componentName))) {
                try (SafeCloseable t = appsList.trackRemoves(a -> {
                    Log.d(TAG, "OP_UPDATE - AllAppsList.trackRemoves callback:"
                            + " removed component=" + a.componentName
                            + " id=" + a.id
                            + " Look for earlier AllAppsList logs to find more information.");
                    removedComponents.add(a.componentName);
                })) {
                    for (int i = 0; i < N; i++) {
                        if (DEBUG) Log.d(TAG, "mAllAppsList.updatePackage " + packages[i]);
                        iconCache.updateIconsForPkg(packages[i], mUser);
                        activitiesLists.put(packages[i],
                                appsList.updatePackage(context, packages[i], mUser));
@@ -147,14 +157,15 @@ public class PackageUpdatedTask implements ModelUpdateTask {
                break;
            case OP_REMOVE: {
                for (int i = 0; i < N; i++) {
                    FileLog.d(TAG, "Removing app icon: " + packages[i]);
                    iconCache.removeIconsForPkg(packages[i], mUser);
                }
                // Fall through
            }
            case OP_UNAVAILABLE:
                for (int i = 0; i < N; i++) {
                    if (DEBUG) Log.d(TAG, "mAllAppsList.removePackage " + packages[i]);
                    if (DEBUG) {
                        Log.d(TAG, getOpString() + ": removing package=" + packages[i]);
                    }
                    appsList.removePackage(packages[i], mUser);
                }
                flagOp = FlagOp.NO_OP.addFlag(WorkspaceItemInfo.FLAG_DISABLED_NOT_AVAILABLE);
@@ -163,7 +174,6 @@ public class PackageUpdatedTask implements ModelUpdateTask {
            case OP_UNSUSPEND:
                flagOp = FlagOp.NO_OP.setFlag(
                        WorkspaceItemInfo.FLAG_DISABLED_SUSPENDED, mOp == OP_SUSPEND);
                if (DEBUG) Log.d(TAG, "mAllAppsList.(un)suspend " + N);
                appsList.updateDisabledFlags(matcher, flagOp);
                break;
            case OP_USER_AVAILABILITY_CHANGE: {
@@ -249,12 +259,21 @@ public class PackageUpdatedTask implements ModelUpdateTask {
                                    infoUpdated = true;
                                } else if (si.hasPromiseIconUi()) {
                                    removedShortcuts.add(si.id);
                                    if (DEBUG) {
                                        Log.d(TAG, "Removing restored shortcut promise icon"
                                                + " that no longer points to valid component."
                                                + " id=" + si.id
                                                + ", package=" + si.getTargetPackage());
                                    }
                                    return;
                                }
                            } else if (!isTargetValid) {
                                removedShortcuts.add(si.id);
                                FileLog.e(TAG, "Restored shortcut no longer valid "
                                        + si.getIntent());
                                FileLog.e(TAG, "Removing shortcut that no longer points to"
                                        + " valid component."
                                        + " id=" + si.id
                                        + " package=" + si.getTargetPackage()
                                        + " status=" + si.status);
                                return;
                            } else {
                                si.status = WorkspaceItemInfo.DEFAULT;
@@ -336,7 +355,8 @@ public class PackageUpdatedTask implements ModelUpdateTask {
            if (!removedShortcuts.isEmpty()) {
                taskController.deleteAndBindComponentsRemoved(
                        ItemInfoMatcher.ofItemIds(removedShortcuts),
                        "removed because the target component is invalid");
                        "removing shortcuts with invalid target components."
                                + " ids=" + removedShortcuts);
            }

            if (!widgets.isEmpty()) {
@@ -348,6 +368,9 @@ public class PackageUpdatedTask implements ModelUpdateTask {
        if (mOp == OP_REMOVE) {
            // Mark all packages in the broadcast to be removed
            Collections.addAll(removedPackages, packages);
            if (DEBUG) {
                Log.d(TAG, "OP_REMOVE: removing packages=" + Arrays.toString(packages));
            }

            // No need to update the removedComponents as
            // removedPackages is a super-set of removedComponents
@@ -356,6 +379,10 @@ public class PackageUpdatedTask implements ModelUpdateTask {
            final LauncherApps launcherApps = context.getSystemService(LauncherApps.class);
            for (int i=0; i<N; i++) {
                if (!launcherApps.isPackageEnabled(packages[i], mUser)) {
                    if (DEBUG) {
                        Log.d(TAG, "OP_UPDATE:"
                                + " package " + packages[i] + " is disabled, removing package.");
                    }
                    removedPackages.add(packages[i]);
                }
            }
@@ -410,4 +437,18 @@ public class PackageUpdatedTask implements ModelUpdateTask {
        }
        return false;
    }

    private String getOpString() {
        return switch (mOp) {
            case OP_NONE -> "NONE";
            case OP_ADD -> "ADD";
            case OP_UPDATE -> "UPDATE";
            case OP_REMOVE -> "REMOVE";
            case OP_UNAVAILABLE -> "UNAVAILABLE";
            case OP_SUSPEND -> "SUSPEND";
            case OP_UNSUSPEND -> "UNSUSPEND";
            case OP_USER_AVAILABILITY_CHANGE -> "USER_AVAILABILITY_CHANGE";
            default -> "UNKNOWN";
        };
    }
}
+24 −0
Original line number Diff line number Diff line
@@ -85,6 +85,7 @@ import java.util.function.Consumer;
public class ItemClickHandler {

    private static final String TAG = "ItemClickHandler";
    private static final boolean DEBUG = true;

    /**
     * Instance used for click handling on items
@@ -110,7 +111,19 @@ public class ItemClickHandler {
            startAppShortcutOrInfoActivity(v, (AppInfo) tag, launcher);
        } else if (tag instanceof LauncherAppWidgetInfo) {
            if (v instanceof PendingAppWidgetHostView) {
                if (DEBUG) {
                    String targetPackage = ((LauncherAppWidgetInfo) tag).getTargetPackage();
                    Log.d(TAG, "onClick: PendingAppWidgetHostView clicked for"
                            + " package=" + targetPackage);
                }
                onClickPendingWidget((PendingAppWidgetHostView) v, launcher);
            } else {
                if (DEBUG) {
                    String targetPackage = ((LauncherAppWidgetInfo) tag).getTargetPackage();
                    Log.d(TAG, "onClick: LauncherAppWidgetInfo clicked,"
                            + " but not instance of PendingAppWidgetHostView. Returning."
                            + " package=" + targetPackage);
                }
            }
        } else if (tag instanceof ItemClickProxy) {
            ((ItemClickProxy) tag).onItemClicked(v);
@@ -120,6 +133,10 @@ public class ItemClickHandler {
                    launcher.getString(R.string.long_accessible_way_to_add_shortcut));
            Snackbar.show(launcher, msg, null);
        } else if (tag instanceof PendingAddWidgetInfo) {
            if (DEBUG) {
                String targetPackage = ((PendingAddWidgetInfo) tag).getTargetPackage();
                Log.d(TAG, "onClick: PendingAddWidgetInfo clicked for package=" + targetPackage);
            }
            CharSequence msg = Utilities.wrapForTts(
                    launcher.getText(R.string.long_press_widget_to_add),
                    launcher.getString(R.string.long_accessible_way_to_add));
@@ -199,6 +216,9 @@ public class ItemClickHandler {
            LauncherAppWidgetProviderInfo appWidgetInfo = new WidgetManagerHelper(launcher)
                    .findProvider(info.providerName, info.user);
            if (appWidgetInfo == null) {
                Log.e(TAG, "onClickPendingWidget: Pending widget ready for click setup,"
                        + " but LauncherAppWidgetProviderInfo was null. Returning."
                        + " component=" + info.getTargetComponent());
                return;
            }
            WidgetAddFlowHandler addFlowHandler = new WidgetAddFlowHandler(appWidgetInfo);
@@ -206,6 +226,10 @@ public class ItemClickHandler {
            if (info.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
                if (!info.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_ALLOCATED)) {
                    // This should not happen, as we make sure that an Id is allocated during bind.
                    Log.e(TAG, "onClickPendingWidget: Pending widget ready for click setup,"
                            + " and LauncherAppWidgetProviderInfo was found. However,"
                            + " no appWidgetId was allocated. Returning."
                            + " component=" + info.getTargetComponent());
                    return;
                }
                addFlowHandler.startBindFlow(launcher, info.appWidgetId, info,
+5 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.os.UserHandle;
import android.util.Log;
import android.widget.RemoteViews;

import androidx.annotation.NonNull;
@@ -104,6 +105,8 @@ public class WidgetManagerHelper {
            // If exception is thrown because of device is locked, it means a race condition occurs
            // that the user got locked again while launcher is processing the event. In this case
            // we should return empty list.
            Log.e(TAG, "getAllProviders: Error getting installed providers for"
                    + " package=" + packageUser.mPackageName, e);
            return Collections.emptyList();
        }
    }
@@ -133,6 +136,8 @@ public class WidgetManagerHelper {
                return LauncherAppWidgetProviderInfo.fromProviderInfo(mContext, info);
            }
        }
        Log.w(TAG, "findProvider: No App Widget Provider found for component=" + provider
                + " user=" + user);
        return null;
    }