Bugfix: Remove widgets and deep shortcuts of app which gets archived.
* Once app is archived, remove widgets and deep shortcuts corresponding to the app from the home screen.
* However during backup & restore, widgets should not be removed if they are being restored.
Test: verified bugfix locally.
Bug: 326567866
Flag: ACONFIG com.android.launcher3.enable_support_for_archiving DEVELOPMENT
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:bef2930f5a29655f6c403f2d5eefd4e99a733b04)
Merged-In: Ib3a112aadc7bd901fd6a0ba86f472ec6acf8d626
Change-Id: Ib3a112aadc7bd901fd6a0ba86f472ec6acf8d626
diff --git a/src/com/android/launcher3/model/ShortcutsChangedTask.java b/src/com/android/launcher3/model/ShortcutsChangedTask.java
index a6a04a7..59dd1b1 100644
--- a/src/com/android/launcher3/model/ShortcutsChangedTask.java
+++ b/src/com/android/launcher3/model/ShortcutsChangedTask.java
@@ -78,10 +78,12 @@
if (!matchingWorkspaceItems.isEmpty()) {
if (mShortcuts.isEmpty()) {
+ PackageManagerHelper packageManagerHelper = new PackageManagerHelper(
+ app.getContext());
// Verify that the app is indeed installed.
- if (!new PackageManagerHelper(app.getContext())
- .isAppInstalled(mPackageName, mUser)) {
- // App is not installed, ignoring package events
+ if (!packageManagerHelper.isAppInstalled(mPackageName, mUser)
+ && !packageManagerHelper.isAppArchivedForUser(mPackageName, mUser)) {
+ // App is not installed or archived, ignoring package events
return;
}
}
diff --git a/src/com/android/launcher3/util/PackageManagerHelper.java b/src/com/android/launcher3/util/PackageManagerHelper.java
index 11d8e97..606918e 100644
--- a/src/com/android/launcher3/util/PackageManagerHelper.java
+++ b/src/com/android/launcher3/util/PackageManagerHelper.java
@@ -105,6 +105,21 @@
}
/**
+ * Returns whether the target app is archived for a given user
+ */
+ public boolean isAppArchivedForUser(@NonNull final String packageName,
+ @NonNull final UserHandle user) {
+ if (!Utilities.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")
@@ -172,7 +187,7 @@
public void startDetailsActivityForInfo(ItemInfo info, Rect sourceBounds, Bundle opts) {
if (info instanceof ItemInfoWithIcon
&& (((ItemInfoWithIcon) info).runtimeStatusFlags
- & ItemInfoWithIcon.FLAG_INSTALL_SESSION_ACTIVE) != 0) {
+ & ItemInfoWithIcon.FLAG_INSTALL_SESSION_ACTIVE) != 0) {
ItemInfoWithIcon appInfo = (ItemInfoWithIcon) info;
mContext.startActivity(ApiWrapper.getAppMarketActivityIntent(mContext,
appInfo.getTargetComponent().getPackageName(), Process.myUserHandle()));
@@ -251,6 +266,7 @@
/**
* Returns true if Launcher has the permission to access shortcuts.
+ *
* @see LauncherApps#hasShortcutHostPermission()
*/
public static boolean hasShortcutsPermission(Context context) {