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
This commit is contained in:
Winson Chung
2024-04-22 12:35:03 +00:00
parent 1ebeb1d1ae
commit bb32b7e0de
13 changed files with 47 additions and 34 deletions
@@ -168,7 +168,7 @@ public class InstallSessionHelper {
synchronized (mSessionVerifiedMap) {
if (!mSessionVerifiedMap.containsKey(pkg)) {
boolean hasSystemFlag = DEBUG || mAppContext.getPackageName().equals(pkg)
|| new PackageManagerHelper(mAppContext)
|| PackageManagerHelper.INSTANCE.get(mAppContext)
.getApplicationInfo(pkg, user, ApplicationInfo.FLAG_SYSTEM) != null;
mSessionVerifiedMap.put(pkg, hasSystemFlag);
}
@@ -242,7 +242,7 @@ public class InstallSessionHelper {
&& sessionInfo.getInstallReason() == PackageManager.INSTALL_REASON_USER
&& sessionInfo.getAppIcon() != null
&& !TextUtils.isEmpty(sessionInfo.getAppLabel())
&& !new PackageManagerHelper(mAppContext).isAppInstalled(
&& !PackageManagerHelper.INSTANCE.get(mAppContext).isAppInstalled(
sessionInfo.getAppPackageName(), getUserHandle(sessionInfo));
}