Moving various application into related methods to a separate class
> This avoids duplicate RPCs when trying to get multiple properties
from AppInfo
> This would be used in a followup cl when AppInfo is added to caching
logic in IconCache
Bug: 366237794
Test: atest ApplicationInfoWrapperTest
Flag: EXEMPT refactor
Change-Id: I55b964d4f8cfa1ff1770e310ac278719495e285d
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index ca1b2a9..7ad17d9 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -71,6 +71,7 @@
import com.android.launcher3.pm.PackageInstallInfo;
import com.android.launcher3.pm.UserCache;
import com.android.launcher3.shortcuts.ShortcutRequest;
+import com.android.launcher3.util.ApplicationInfoWrapper;
import com.android.launcher3.util.IntSet;
import com.android.launcher3.util.ItemInfoMatcher;
import com.android.launcher3.util.PackageManagerHelper;
@@ -446,8 +447,8 @@
IconCache iconCache = mApp.getIconCache();
final IntSet removedIds = new IntSet();
HashSet<WorkspaceItemInfo> archivedWorkspaceItemsToCacheRefresh = new HashSet<>();
- boolean isAppArchived = PackageManagerHelper.INSTANCE.get(mApp.getContext())
- .isAppArchivedForUser(packageName, user);
+ boolean isAppArchived =
+ new ApplicationInfoWrapper(mApp.getContext(), packageName, user).isArchived();
synchronized (dataModel) {
if (isAppArchived) {
// Remove package icon cache entry for archived app in case of a session
diff --git a/src/com/android/launcher3/SecondaryDropTarget.java b/src/com/android/launcher3/SecondaryDropTarget.java
index 8d1e61f..b3cb948 100644
--- a/src/com/android/launcher3/SecondaryDropTarget.java
+++ b/src/com/android/launcher3/SecondaryDropTarget.java
@@ -22,7 +22,6 @@
import android.content.pm.ApplicationInfo;
import android.content.pm.LauncherActivityInfo;
import android.content.pm.LauncherApps;
-import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.UserHandle;
@@ -44,7 +43,7 @@
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.ItemInfoWithIcon;
import com.android.launcher3.pm.UserCache;
-import com.android.launcher3.util.PackageManagerHelper;
+import com.android.launcher3.util.ApplicationInfoWrapper;
import com.android.launcher3.widget.LauncherAppWidgetProviderInfo;
import java.net.URISyntaxException;
@@ -342,9 +341,8 @@
}
public void onLauncherResume() {
- // We use MATCH_UNINSTALLED_PACKAGES as the app can be on SD card as well.
- if (PackageManagerHelper.INSTANCE.get(mContext).getApplicationInfo(mPackageName,
- mDragObject.dragInfo.user, PackageManager.MATCH_UNINSTALLED_PACKAGES) == null) {
+ if (new ApplicationInfoWrapper(mContext, mPackageName, mDragObject.dragInfo.user)
+ .getInfo() == null) {
mDragObject.dragSource = mOriginal;
mOriginal.onDropCompleted(SecondaryDropTarget.this, mDragObject, true);
mStatsLogManager.logger().withInstanceId(mDragObject.logInstanceId)
diff --git a/src/com/android/launcher3/dragndrop/AddItemActivity.java b/src/com/android/launcher3/dragndrop/AddItemActivity.java
index 85eb39b..a3cfe5c 100644
--- a/src/com/android/launcher3/dragndrop/AddItemActivity.java
+++ b/src/com/android/launcher3/dragndrop/AddItemActivity.java
@@ -68,7 +68,7 @@
import com.android.launcher3.model.data.PackageItemInfo;
import com.android.launcher3.pm.PinRequestHelper;
import com.android.launcher3.util.ApiWrapper;
-import com.android.launcher3.util.PackageManagerHelper;
+import com.android.launcher3.util.ApplicationInfoWrapper;
import com.android.launcher3.util.SystemUiController;
import com.android.launcher3.views.AbstractSlideInView;
import com.android.launcher3.views.BaseDragLayer;
@@ -164,8 +164,8 @@
finish();
return;
}
- ApplicationInfo info = PackageManagerHelper.INSTANCE.get(this)
- .getApplicationInfo(targetApp.packageName, targetApp.user, 0);
+ ApplicationInfo info = new ApplicationInfoWrapper(
+ this, targetApp.packageName, targetApp.user).getInfo();
if (info == null) {
finish();
return;
diff --git a/src/com/android/launcher3/model/AddWorkspaceItemsTask.java b/src/com/android/launcher3/model/AddWorkspaceItemsTask.java
index 427fb97..55bcb70 100644
--- a/src/com/android/launcher3/model/AddWorkspaceItemsTask.java
+++ b/src/com/android/launcher3/model/AddWorkspaceItemsTask.java
@@ -41,6 +41,7 @@
import com.android.launcher3.model.data.WorkspaceItemInfo;
import com.android.launcher3.pm.InstallSessionHelper;
import com.android.launcher3.pm.PackageInstallInfo;
+import com.android.launcher3.util.ApplicationInfoWrapper;
import com.android.launcher3.util.IntArray;
import com.android.launcher3.util.PackageManagerHelper;
@@ -103,8 +104,8 @@
}
// b/139663018 Short-circuit this logic if the icon is a system app
- if (PackageManagerHelper.isSystemApp(context,
- Objects.requireNonNull(item.getIntent()))) {
+ if (new ApplicationInfoWrapper(context,
+ Objects.requireNonNull(item.getIntent())).isSystem()) {
continue;
}
diff --git a/src/com/android/launcher3/model/AllAppsList.java b/src/com/android/launcher3/model/AllAppsList.java
index 1f60f13..7bc9273 100644
--- a/src/com/android/launcher3/model/AllAppsList.java
+++ b/src/com/android/launcher3/model/AllAppsList.java
@@ -40,6 +40,7 @@
import com.android.launcher3.pm.PackageInstallInfo;
import com.android.launcher3.pm.UserCache;
import com.android.launcher3.util.ApiWrapper;
+import com.android.launcher3.util.ApplicationInfoWrapper;
import com.android.launcher3.util.FlagOp;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.util.SafeCloseable;
@@ -169,8 +170,8 @@
public AppInfo addPromiseApp(
Context context, PackageInstallInfo installInfo, boolean loadIcon) {
// only if not yet installed
- if (PackageManagerHelper.INSTANCE.get(context)
- .isAppInstalled(installInfo.packageName, installInfo.user)) {
+ if (new ApplicationInfoWrapper(context, installInfo.packageName, installInfo.user)
+ .isInstalled()) {
return null;
}
AppInfo promiseAppInfo = new AppInfo(installInfo);
diff --git a/src/com/android/launcher3/model/SdCardAvailableReceiver.java b/src/com/android/launcher3/model/SdCardAvailableReceiver.java
index 5293316..9e3f0e1 100644
--- a/src/com/android/launcher3/model/SdCardAvailableReceiver.java
+++ b/src/com/android/launcher3/model/SdCardAvailableReceiver.java
@@ -24,7 +24,7 @@
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherModel;
-import com.android.launcher3.util.PackageManagerHelper;
+import com.android.launcher3.util.ApplicationInfoWrapper;
import com.android.launcher3.util.PackageUserKey;
import java.util.ArrayList;
@@ -52,7 +52,6 @@
@Override
public void onReceive(Context context, Intent intent) {
final LauncherApps launcherApps = context.getSystemService(LauncherApps.class);
- final PackageManagerHelper pmHelper = PackageManagerHelper.INSTANCE.get(context);
for (PackageUserKey puk : mPackages) {
UserHandle user = puk.mUser;
@@ -60,7 +59,7 @@
final ArrayList<String> packagesUnavailable = new ArrayList<>();
if (!launcherApps.isPackageEnabled(puk.mPackageName, user)) {
- if (pmHelper.isAppOnSdcard(puk.mPackageName, user)) {
+ if (new ApplicationInfoWrapper(context, puk.mPackageName, user).isOnSdCard()) {
packagesUnavailable.add(puk.mPackageName);
} else {
packagesRemoved.add(puk.mPackageName);
diff --git a/src/com/android/launcher3/model/ShortcutsChangedTask.java b/src/com/android/launcher3/model/ShortcutsChangedTask.java
index 1916d23..55c4d30 100644
--- a/src/com/android/launcher3/model/ShortcutsChangedTask.java
+++ b/src/com/android/launcher3/model/ShortcutsChangedTask.java
@@ -27,8 +27,8 @@
import com.android.launcher3.model.data.WorkspaceItemInfo;
import com.android.launcher3.shortcuts.ShortcutKey;
import com.android.launcher3.shortcuts.ShortcutRequest;
+import com.android.launcher3.util.ApplicationInfoWrapper;
import com.android.launcher3.util.ItemInfoMatcher;
-import com.android.launcher3.util.PackageManagerHelper;
import java.util.ArrayList;
import java.util.HashSet;
@@ -80,11 +80,10 @@
if (!matchingWorkspaceItems.isEmpty()) {
if (mShortcuts.isEmpty()) {
- PackageManagerHelper packageManagerHelper =
- PackageManagerHelper.INSTANCE.get(context);
+ ApplicationInfoWrapper infoWrapper =
+ new ApplicationInfoWrapper(context, mPackageName, mUser);
// Verify that the app is indeed installed.
- if (!packageManagerHelper.isAppInstalled(mPackageName, mUser)
- && !packageManagerHelper.isAppArchivedForUser(mPackageName, mUser)) {
+ if (!infoWrapper.isInstalled() && !infoWrapper.isArchived()) {
// App is not installed or archived, ignoring package events
return;
}
diff --git a/src/com/android/launcher3/model/WorkspaceItemProcessor.kt b/src/com/android/launcher3/model/WorkspaceItemProcessor.kt
index 1f1e514..18c7f95 100644
--- a/src/com/android/launcher3/model/WorkspaceItemProcessor.kt
+++ b/src/com/android/launcher3/model/WorkspaceItemProcessor.kt
@@ -44,6 +44,7 @@
import com.android.launcher3.pm.UserCache
import com.android.launcher3.shortcuts.ShortcutKey
import com.android.launcher3.util.ApiWrapper
+import com.android.launcher3.util.ApplicationInfoWrapper
import com.android.launcher3.util.ComponentKey
import com.android.launcher3.util.PackageManagerHelper
import com.android.launcher3.util.PackageUserKey
@@ -152,6 +153,7 @@
c.markDeleted("No target package for item id=${c.id}", RestoreError.MISSING_INFO)
return
}
+ val appInfoWrapper = ApplicationInfoWrapper(app.context, targetPkg, c.user)
var validTarget = launcherApps.isPackageEnabled(targetPkg, c.user)
// If it's a deep shortcut, we'll use pinned shortcuts to restore it
@@ -218,7 +220,7 @@
}
}
}
- pmHelper.isAppOnSdcard(targetPkg, c.user) -> {
+ appInfoWrapper.isOnSdCard() -> {
// Package is present but not available.
disabledState =
disabledState or WorkspaceItemInfo.FLAG_DISABLED_NOT_AVAILABLE
@@ -277,7 +279,7 @@
// If the pinned deep shortcut is no longer published,
// use the last saved icon instead of the default.
iconCache.getShortcutIcon(info, pinnedShortcut, c::loadIcon)
- if (pmHelper.isAppSuspended(pinnedShortcut.getPackage(), info.user)) {
+ if (appInfoWrapper.isSuspended()) {
info.runtimeStatusFlags =
info.runtimeStatusFlags or ItemInfoWithIcon.FLAG_DISABLED_SUSPENDED
}
@@ -294,7 +296,7 @@
info = c.loadSimpleWorkspaceItem()
// Shortcuts are only available on the primary profile
- if (!TextUtils.isEmpty(targetPkg) && pmHelper.isAppSuspended(targetPkg, c.user)) {
+ if (appInfoWrapper.isSuspended()) {
disabledState = disabledState or ItemInfoWithIcon.FLAG_DISABLED_SUSPENDED
}
info.options = c.options
@@ -325,7 +327,7 @@
info.spanX = 1
info.spanY = 1
info.runtimeStatusFlags = info.runtimeStatusFlags or disabledState
- if (isSafeMode && !PackageManagerHelper.isSystemApp(app.context, intent)) {
+ if (isSafeMode && !appInfoWrapper.isSystem()) {
info.runtimeStatusFlags =
info.runtimeStatusFlags or ItemInfoWithIcon.FLAG_DISABLED_SAFEMODE
}
@@ -486,7 +488,8 @@
(si == null) &&
(lapi == null) &&
!(Flags.enableSupportForArchiving() &&
- pmHelper.isAppArchived(component.packageName))
+ ApplicationInfoWrapper(app.context, component.packageName, c.user)
+ .isArchived())
) {
// Restore never started
c.markDeleted(
diff --git a/src/com/android/launcher3/model/data/AppInfo.java b/src/com/android/launcher3/model/data/AppInfo.java
index a4281f8..97b62b4 100644
--- a/src/com/android/launcher3/model/data/AppInfo.java
+++ b/src/com/android/launcher3/model/data/AppInfo.java
@@ -21,7 +21,6 @@
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
-import android.content.pm.ApplicationInfo;
import android.content.pm.LauncherActivityInfo;
import android.os.UserHandle;
import android.os.UserManager;
@@ -36,6 +35,7 @@
import com.android.launcher3.pm.PackageInstallInfo;
import com.android.launcher3.pm.UserCache;
import com.android.launcher3.util.ApiWrapper;
+import com.android.launcher3.util.ApplicationInfoWrapper;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.util.UserIconInfo;
@@ -187,8 +187,8 @@
ApiWrapper apiWrapper, PackageManagerHelper pmHelper) {
final int oldProgressLevel = info.getProgressLevel();
final int oldRuntimeStatusFlags = info.runtimeStatusFlags;
- ApplicationInfo appInfo = lai.getApplicationInfo();
- if (PackageManagerHelper.isAppSuspended(appInfo)) {
+ ApplicationInfoWrapper appInfo = new ApplicationInfoWrapper(lai.getApplicationInfo());
+ if (appInfo.isSuspended()) {
info.runtimeStatusFlags |= FLAG_DISABLED_SUSPENDED;
} else {
info.runtimeStatusFlags &= ~FLAG_DISABLED_SUSPENDED;
@@ -200,8 +200,7 @@
info.runtimeStatusFlags &= ~FLAG_ARCHIVED;
}
}
- info.runtimeStatusFlags |= (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0
- ? FLAG_SYSTEM_NO : FLAG_SYSTEM_YES;
+ info.runtimeStatusFlags |= appInfo.isSystem() ? FLAG_SYSTEM_YES : FLAG_SYSTEM_NO;
if (Flags.privateSpaceRestrictAccessibilityDrag()) {
if (userIconInfo.isPrivate()) {
diff --git a/src/com/android/launcher3/pm/InstallSessionHelper.java b/src/com/android/launcher3/pm/InstallSessionHelper.java
index e66f496..124907f 100644
--- a/src/com/android/launcher3/pm/InstallSessionHelper.java
+++ b/src/com/android/launcher3/pm/InstallSessionHelper.java
@@ -17,7 +17,6 @@
package com.android.launcher3.pm;
import android.content.Context;
-import android.content.pm.ApplicationInfo;
import android.content.pm.LauncherApps;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageInstaller.SessionInfo;
@@ -34,10 +33,10 @@
import com.android.launcher3.SessionCommitReceiver;
import com.android.launcher3.logging.FileLog;
import com.android.launcher3.model.ItemInstallQueue;
+import com.android.launcher3.util.ApplicationInfoWrapper;
import com.android.launcher3.util.IntArray;
import com.android.launcher3.util.IntSet;
import com.android.launcher3.util.MainThreadInitializedObject;
-import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.util.PackageUserKey;
import com.android.launcher3.util.Preconditions;
import com.android.launcher3.util.SafeCloseable;
@@ -171,8 +170,7 @@
synchronized (mSessionVerifiedMap) {
if (!mSessionVerifiedMap.containsKey(pkg)) {
boolean hasSystemFlag = DEBUG || mAppContext.getPackageName().equals(pkg)
- || PackageManagerHelper.INSTANCE.get(mAppContext)
- .getApplicationInfo(pkg, user, ApplicationInfo.FLAG_SYSTEM) != null;
+ || new ApplicationInfoWrapper(mAppContext, pkg, user).isSystem();
mSessionVerifiedMap.put(pkg, hasSystemFlag);
}
}
@@ -245,8 +243,8 @@
&& sessionInfo.getInstallReason() == PackageManager.INSTALL_REASON_USER
&& sessionInfo.getAppIcon() != null
&& !TextUtils.isEmpty(sessionInfo.getAppLabel())
- && !PackageManagerHelper.INSTANCE.get(mAppContext).isAppInstalled(
- sessionInfo.getAppPackageName(), getUserHandle(sessionInfo));
+ && !new ApplicationInfoWrapper(mAppContext, sessionInfo.getAppPackageName(),
+ getUserHandle(sessionInfo)).isInstalled();
}
public InstallSessionTracker registerInstallTracker(
diff --git a/src/com/android/launcher3/util/ApplicationInfoWrapper.kt b/src/com/android/launcher3/util/ApplicationInfoWrapper.kt
new file mode 100644
index 0000000..e75b3bc
--- /dev/null
+++ b/src/com/android/launcher3/util/ApplicationInfoWrapper.kt
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.launcher3.util
+
+import android.content.Context
+import android.content.Intent
+import android.content.pm.ApplicationInfo
+import android.content.pm.ApplicationInfo.FLAG_EXTERNAL_STORAGE
+import android.content.pm.ApplicationInfo.FLAG_INSTALLED
+import android.content.pm.ApplicationInfo.FLAG_SUSPENDED
+import android.content.pm.ApplicationInfo.FLAG_SYSTEM
+import android.content.pm.LauncherApps
+import android.content.pm.PackageManager
+import android.content.pm.PackageManager.NameNotFoundException
+import android.os.UserHandle
+import com.android.launcher3.Flags.enableSupportForArchiving
+import com.android.launcher3.Utilities.ATLEAST_V
+import kotlin.LazyThreadSafetyMode.NONE
+
+/**
+ * A set of utility methods around ApplicationInfo with support for fetching the actual info lazily
+ */
+class ApplicationInfoWrapper private constructor(provider: () -> ApplicationInfo?) {
+
+ constructor(appInfo: ApplicationInfo?) : this({ appInfo })
+
+ constructor(
+ ctx: Context,
+ pkg: String,
+ user: UserHandle,
+ ) : this({
+ try {
+ ctx.getSystemService(LauncherApps::class.java)
+ ?.getApplicationInfo(pkg, PackageManager.MATCH_UNINSTALLED_PACKAGES, user)
+ ?.let { ai ->
+ // its enabled and (either installed or archived)
+ if (
+ ai.enabled &&
+ (ai.flags.and(FLAG_INSTALLED) != 0 ||
+ (ATLEAST_V && enableSupportForArchiving() && ai.isArchived))
+ ) {
+ ai
+ } else {
+ null
+ }
+ }
+ } catch (e: NameNotFoundException) {
+ null
+ }
+ })
+
+ constructor(
+ ctx: Context,
+ intent: Intent,
+ ) : this(
+ provider@{
+ try {
+ val pm = ctx.packageManager
+ val packageName: String =
+ intent.component?.packageName
+ ?: intent.getPackage()
+ ?: return@provider pm.resolveActivity(
+ intent,
+ PackageManager.MATCH_DEFAULT_ONLY,
+ )
+ ?.activityInfo
+ ?.applicationInfo
+ pm.getApplicationInfo(packageName, 0)
+ } catch (e: NameNotFoundException) {
+ null
+ }
+ }
+ )
+
+ private val appInfo: ApplicationInfo? by lazy(NONE, provider)
+
+ private fun hasFlag(flag: Int) = appInfo?.let { it.flags.and(flag) != 0 } ?: false
+
+ /**
+ * Returns true if the app can possibly be on the SDCard. This is just a workaround and doesn't
+ * guarantee that the app is on SD card.
+ */
+ fun isOnSdCard() = hasFlag(FLAG_EXTERNAL_STORAGE)
+
+ /** Returns whether the target app is installed for a given user */
+ fun isInstalled() = hasFlag(FLAG_INSTALLED)
+
+ /**
+ * Returns whether the target app is suspended for a given user as per
+ * [android.app.admin.DevicePolicyManager.isPackageSuspended].
+ */
+ fun isSuspended() = hasFlag(FLAG_INSTALLED) && hasFlag(FLAG_SUSPENDED)
+
+ /** Returns whether the target app is archived for a given user */
+ fun isArchived() = ATLEAST_V && enableSupportForArchiving() && appInfo?.isArchived ?: false
+
+ /** Returns whether the target app is a system app */
+ fun isSystem() = hasFlag(FLAG_SYSTEM)
+
+ fun getInfo(): ApplicationInfo? = appInfo
+}
diff --git a/src/com/android/launcher3/util/PackageManagerHelper.java b/src/com/android/launcher3/util/PackageManagerHelper.java
index b1913c0..e51609a 100644
--- a/src/com/android/launcher3/util/PackageManagerHelper.java
+++ b/src/com/android/launcher3/util/PackageManagerHelper.java
@@ -24,13 +24,10 @@
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
-import android.content.pm.ApplicationInfo;
import android.content.pm.LauncherActivityInfo;
import android.content.pm.LauncherApps;
-import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
-import android.content.pm.ResolveInfo;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Process;
@@ -42,7 +39,6 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
-import com.android.launcher3.Flags;
import com.android.launcher3.PendingAddItemInfo;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
@@ -89,69 +85,6 @@
public void close() { }
/**
- * Returns true if the app can possibly be on the SDCard. This is just a workaround and doesn't
- * guarantee that the app is on SD card.
- */
- public boolean isAppOnSdcard(@NonNull final String packageName,
- @NonNull final UserHandle user) {
- final ApplicationInfo info = getApplicationInfo(
- packageName, user, PackageManager.MATCH_UNINSTALLED_PACKAGES);
- return info != null && (info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0;
- }
-
- /**
- * Returns whether the target app is suspended for a given user as per
- * {@link android.app.admin.DevicePolicyManager#isPackageSuspended}.
- */
- public boolean isAppSuspended(@NonNull final String packageName,
- @NonNull final UserHandle user) {
- final ApplicationInfo info = getApplicationInfo(packageName, user, 0);
- return info != null && isAppSuspended(info);
- }
-
- /**
- * Returns whether the target app is installed for a given user
- */
- public boolean isAppInstalled(@NonNull final String packageName,
- @NonNull final UserHandle user) {
- final ApplicationInfo info = getApplicationInfo(packageName, user, 0);
- return info != null;
- }
-
- /**
- * Returns whether the target app is archived for a given user
- */
- @SuppressWarnings("NewApi")
- public boolean isAppArchivedForUser(@NonNull final String packageName,
- @NonNull final UserHandle user) {
- if (!Flags.enableSupportForArchiving()) {
- return false;
- }
- final ApplicationInfo info = getApplicationInfo(
- // LauncherApps does not support long flags currently. Since archived apps are
- // subset of uninstalled apps, this filter also includes archived apps.
- packageName, user, PackageManager.MATCH_UNINSTALLED_PACKAGES);
- return info != null && info.isArchived;
- }
-
- /**
- * Returns whether the target app is in archived state
- */
- @SuppressWarnings("NewApi")
- public boolean isAppArchived(@NonNull final String packageName) {
- final ApplicationInfo info;
- try {
- info = mPm.getPackageInfo(packageName,
- PackageManager.PackageInfoFlags.of(
- PackageManager.MATCH_ARCHIVED_PACKAGES)).applicationInfo;
- return info.isArchived;
- } catch (NameNotFoundException e) {
- Log.e(TAG, "Failed to get applicationInfo for package: " + packageName, e);
- return false;
- }
- }
-
- /**
* Returns the installing app package for the given package
*/
public String getAppInstallerPackage(@NonNull final String packageName) {
@@ -164,20 +97,6 @@
}
/**
- * Returns the application info for the provided package or null
- */
- @Nullable
- public ApplicationInfo getApplicationInfo(@NonNull final String packageName,
- @NonNull final UserHandle user, final int flags) {
- try {
- ApplicationInfo info = mLauncherApps.getApplicationInfo(packageName, flags, user);
- return !isPackageInstalledOrArchived(info) || !info.enabled ? null : info;
- } catch (PackageManager.NameNotFoundException e) {
- return null;
- }
- }
-
- /**
* Returns the preferred launch activity intent for a given package.
*/
@Nullable
@@ -197,14 +116,6 @@
}
/**
- * Returns whether an application is suspended as per
- * {@link android.app.admin.DevicePolicyManager#isPackageSuspended}.
- */
- public static boolean isAppSuspended(ApplicationInfo info) {
- return (info.flags & ApplicationInfo.FLAG_SUSPENDED) != 0;
- }
-
- /**
* Starts the details activity for {@code info}
*/
public static void startDetailsActivityForInfo(Context context, ItemInfo info,
@@ -236,35 +147,6 @@
}
}
- public static boolean isSystemApp(@NonNull final Context context,
- @NonNull final Intent intent) {
- PackageManager pm = context.getPackageManager();
- ComponentName cn = intent.getComponent();
- String packageName = null;
- if (cn == null) {
- ResolveInfo info = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
- if ((info != null) && (info.activityInfo != null)) {
- packageName = info.activityInfo.packageName;
- }
- } else {
- packageName = cn.getPackageName();
- }
- if (packageName == null) {
- packageName = intent.getPackage();
- }
- if (packageName != null) {
- try {
- PackageInfo info = pm.getPackageInfo(packageName, 0);
- return (info != null) && (info.applicationInfo != null) &&
- ((info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0);
- } catch (NameNotFoundException e) {
- return false;
- }
- } else {
- return false;
- }
- }
-
/**
* Returns true if the intent is a valid launch intent for a launcher activity of an app.
* This is used to identify shortcuts which are different from the ones exposed by the
@@ -306,13 +188,6 @@
return (int) (100 * info.getLoadingProgress());
}
- /** Returns true in case app is installed on the device or in archived state. */
- @SuppressWarnings("NewApi")
- private boolean isPackageInstalledOrArchived(ApplicationInfo info) {
- return (info.flags & ApplicationInfo.FLAG_INSTALLED) != 0 || (
- Flags.enableSupportForArchiving() && info.isArchived);
- }
-
/**
* Returns whether the given component or its application has the multi-instance property set.
*/
diff --git a/src/com/android/launcher3/views/ActivityContext.java b/src/com/android/launcher3/views/ActivityContext.java
index d3160e0..8131a23 100644
--- a/src/com/android/launcher3/views/ActivityContext.java
+++ b/src/com/android/launcher3/views/ActivityContext.java
@@ -76,7 +76,7 @@
import com.android.launcher3.model.data.WorkspaceItemInfo;
import com.android.launcher3.popup.PopupDataProvider;
import com.android.launcher3.util.ActivityOptionsWrapper;
-import com.android.launcher3.util.PackageManagerHelper;
+import com.android.launcher3.util.ApplicationInfoWrapper;
import com.android.launcher3.util.Preconditions;
import com.android.launcher3.util.RunnableList;
import com.android.launcher3.util.SplitConfigurationOptions;
@@ -391,7 +391,7 @@
View v, Intent intent, @Nullable ItemInfo item) {
Preconditions.assertUIThread();
Context context = (Context) this;
- if (isAppBlockedForSafeMode() && !PackageManagerHelper.isSystemApp(context, intent)) {
+ if (isAppBlockedForSafeMode() && !new ApplicationInfoWrapper(context, intent).isSystem()) {
Toast.makeText(context, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
return null;
}
diff --git a/src/com/android/launcher3/widget/picker/WidgetRecommendationCategoryProvider.java b/src/com/android/launcher3/widget/picker/WidgetRecommendationCategoryProvider.java
index 9253b37..f8dc6b0 100644
--- a/src/com/android/launcher3/widget/picker/WidgetRecommendationCategoryProvider.java
+++ b/src/com/android/launcher3/widget/picker/WidgetRecommendationCategoryProvider.java
@@ -24,7 +24,7 @@
import com.android.launcher3.R;
import com.android.launcher3.model.WidgetItem;
-import com.android.launcher3.util.PackageManagerHelper;
+import com.android.launcher3.util.ApplicationInfoWrapper;
import com.android.launcher3.util.Preconditions;
import com.android.launcher3.util.ResourceBasedOverride;
@@ -62,14 +62,14 @@
// via the overridden WidgetRecommendationCategoryProvider resource.
Preconditions.assertWorkerThread();
- try (PackageManagerHelper pmHelper = new PackageManagerHelper(context)) {
- if (item.widgetInfo != null && item.widgetInfo.getComponent() != null) {
- ApplicationInfo applicationInfo = pmHelper.getApplicationInfo(
- item.widgetInfo.getComponent().getPackageName(), item.widgetInfo.getUser(),
- 0 /* flags */);
- if (applicationInfo != null) {
- return getCategoryFromApplicationCategory(applicationInfo.category);
- }
+ if (item.widgetInfo != null && item.widgetInfo.getComponent() != null) {
+ ApplicationInfo applicationInfo = new ApplicationInfoWrapper(
+ context,
+ item.widgetInfo.getComponent().getPackageName(),
+ item.widgetInfo.getUser())
+ .getInfo();
+ if (applicationInfo != null) {
+ return getCategoryFromApplicationCategory(applicationInfo.category);
}
}
return null;