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

Commit bb32b7e0 authored by Winson Chung's avatar Winson Chung
Browse files

Migrate PackageManagerHelper to MainThreadInitializedObject

- This is in preparation for other things that can be loaded with
  PMH initialization and prevents duplicate temporary helpers from
  loading this many times.
- Most calls in PMH can use the app context, but one call requires
  starting activities/showing toasts so that one needs to take the
  context and can be made static instead.

Bug: 323112914
Test: atest NexusLauncherTests
Change-Id: Id11c780955880cf49c022cbf2744c41e1b696355
parent 1ebeb1d1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ public final class TaskUtils {
            return "";
        }
        UserHandle user = UserHandle.of(userId);
        ApplicationInfo applicationInfo = new PackageManagerHelper(context)
        ApplicationInfo applicationInfo = PackageManagerHelper.INSTANCE.get(context)
                .getApplicationInfo(packageName, user, 0);
        if (applicationInfo == null) {
            Log.e(TAG, "Failed to get title for userId=" + userId + ", packageName=" + packageName);
+2 −2
Original line number Diff line number Diff line
@@ -447,8 +447,8 @@ public class LauncherModel implements InstallSessionTracker.Callback {
                IconCache iconCache = app.getIconCache();
                final IntSet removedIds = new IntSet();
                HashSet<WorkspaceItemInfo> archivedWorkspaceItemsToCacheRefresh = new HashSet<>();
                boolean isAppArchived = new PackageManagerHelper(
                        mApp.getContext()).isAppArchivedForUser(packageName, user);
                boolean isAppArchived = PackageManagerHelper.INSTANCE.get(mApp.getContext())
                        .isAppArchivedForUser(packageName, user);
                synchronized (dataModel) {
                    if (isAppArchived) {
                        // Remove package icon cache entry for archived app in case of a session
+1 −1
Original line number Diff line number Diff line
@@ -362,7 +362,7 @@ public class SecondaryDropTarget extends ButtonDropTarget implements OnAlarmList

        public void onLauncherResume() {
            // We use MATCH_UNINSTALLED_PACKAGES as the app can be on SD card as well.
            if (new PackageManagerHelper(mContext).getApplicationInfo(mPackageName,
            if (PackageManagerHelper.INSTANCE.get(mContext).getApplicationInfo(mPackageName,
                    mDragObject.dragInfo.user, PackageManager.MATCH_UNINSTALLED_PACKAGES) == null) {
                mDragObject.dragSource = mOriginal;
                mOriginal.onDropCompleted(SecondaryDropTarget.this, mDragObject, true);
+1 −1
Original line number Diff line number Diff line
@@ -162,7 +162,7 @@ public class AddItemActivity extends BaseActivity
            finish();
            return;
        }
        ApplicationInfo info = new PackageManagerHelper(this)
        ApplicationInfo info = PackageManagerHelper.INSTANCE.get(this)
                .getApplicationInfo(targetApp.packageName, targetApp.user, 0);
        if (info == null) {
            finish();
+7 −5
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */
package com.android.launcher3.model;

import android.content.Context;
import android.content.Intent;
import android.content.pm.LauncherActivityInfo;
import android.content.pm.LauncherApps;
@@ -85,6 +86,7 @@ public class AddWorkspaceItemsTask extends BaseModelUpdateTask {

        final ArrayList<ItemInfo> addedItemsFinal = new ArrayList<>();
        final IntArray addedWorkspaceScreensFinal = new IntArray();
        final Context context = app.getContext();

        synchronized (dataModel) {
            IntArray workspaceScreens = dataModel.collectWorkspaceScreens();
@@ -99,7 +101,7 @@ public class AddWorkspaceItemsTask extends BaseModelUpdateTask {
                    }

                    // b/139663018 Short-circuit this logic if the icon is a system app
                    if (PackageManagerHelper.isSystemApp(app.getContext(),
                    if (PackageManagerHelper.isSystemApp(context,
                            Objects.requireNonNull(item.getIntent()))) {
                        continue;
                    }
@@ -112,7 +114,7 @@ public class AddWorkspaceItemsTask extends BaseModelUpdateTask {

                if (item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
                    if (item instanceof WorkspaceItemFactory) {
                        item = ((WorkspaceItemFactory) item).makeWorkspaceItem(app.getContext());
                        item = ((WorkspaceItemFactory) item).makeWorkspaceItem(context);
                    }
                }
                if (item != null) {
@@ -121,8 +123,8 @@ public class AddWorkspaceItemsTask extends BaseModelUpdateTask {
            }

            InstallSessionHelper packageInstaller =
                    InstallSessionHelper.INSTANCE.get(app.getContext());
            LauncherApps launcherApps = app.getContext().getSystemService(LauncherApps.class);
                    InstallSessionHelper.INSTANCE.get(context);
            LauncherApps launcherApps = context.getSystemService(LauncherApps.class);

            for (ItemInfo item : filteredItems) {
                // Find appropriate space for the item.
@@ -135,7 +137,7 @@ public class AddWorkspaceItemsTask extends BaseModelUpdateTask {
                        || item instanceof LauncherAppWidgetInfo) {
                    itemInfo = item;
                } else if (item instanceof WorkspaceItemFactory) {
                    itemInfo = ((WorkspaceItemFactory) item).makeWorkspaceItem(app.getContext());
                    itemInfo = ((WorkspaceItemFactory) item).makeWorkspaceItem(context);
                } else {
                    throw new RuntimeException("Unexpected info type");
                }
Loading