Fix widget restore for pre-archived apps
Widgets which were expected to be restored, were missing for apps which were pre-archived.
The fix adds checks for archived apps when processing widgets and ensures that icon with cloud overlay is present on the widget.
Test: Flashed device with build containing this fix.
Screenshot right after SuW- http://shortn/_LoLudMXEaT
Bug: 321297173
Flag: ACONFIG com.android.launcher3.enable_support_for_archiving DEVELOPMENT
Change-Id: Ic5fd6b5b2a12f7b2b053ee4ec7c5c7330f0d07e1
diff --git a/src/com/android/launcher3/model/WorkspaceItemProcessor.kt b/src/com/android/launcher3/model/WorkspaceItemProcessor.kt
index 31ae7c2..88b98aa 100644
--- a/src/com/android/launcher3/model/WorkspaceItemProcessor.kt
+++ b/src/com/android/launcher3/model/WorkspaceItemProcessor.kt
@@ -433,7 +433,9 @@
!c.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_RESTORE_STARTED) &&
!isSafeMode &&
(si == null) &&
- (lapi == null)
+ (lapi == null) &&
+ !(Utilities.enableSupportForArchiving() &&
+ pmHelper.isAppArchived(component.packageName))
) {
// Restore never started
c.markDeleted(
diff --git a/src/com/android/launcher3/util/PackageManagerHelper.java b/src/com/android/launcher3/util/PackageManagerHelper.java
index 50d8886..92288e1 100644
--- a/src/com/android/launcher3/util/PackageManagerHelper.java
+++ b/src/com/android/launcher3/util/PackageManagerHelper.java
@@ -107,6 +107,23 @@
}
/**
+ * 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 application info for the provided package or null
*/
@Nullable