Revert^2 "Restore Archived Pinned Shortcuts instead of removing them."

This reverts commit f5cb1b664b.

Reason for revert: adding test fix and reverting

Change-Id: I2fc8dc83259b2ee7992ac2291df6ee4246a2e9d5
This commit is contained in:
Charlie Anderson committed 2025-02-07 12:14:55 -08:00
1 parent 126566a096
commit ceb401c3e7
7 files changed
+252 -71

No files matched your search

@@ -46,6 +46,7 @@ import androidx.annotation.Nullable;
import com.android.launcher3.BuildConfig;
import com.android.launcher3.Workspace;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.logging.FileLog;
import com.android.launcher3.model.data.AppInfo;
import com.android.launcher3.model.data.CollectionInfo;
import com.android.launcher3.model.data.ItemInfo;
@@ -210,7 +211,7 @@ public class BgDataModel {
}
/**
* Updates the deep shortucts state in system to match out internal model, pinning any missing
* Updates the deep shortcuts state in system to match out internal model, pinning any missing
* shortcuts and unpinning any extra shortcuts.
*/
public void updateShortcutPinnedState(Context context) {
@@ -266,6 +267,8 @@ public class BgDataModel {
|| !systemShortcuts.containsAll(modelShortcuts)) {
// Update system state for this package
try {
FileLog.d(TAG, "updateShortcutPinnedState:"
+ " Pinning Shortcuts: " + entry.getKey() + ": " + modelShortcuts);
context.getSystemService(LauncherApps.class).pinShortcuts(
entry.getKey(), new ArrayList<>(modelShortcuts), user);
} catch (SecurityException | IllegalStateException e) {
@@ -278,6 +281,9 @@ public class BgDataModel {
systemMap.keySet().forEach(packageName -> {
// Update system state
try {
FileLog.d(TAG, "updateShortcutPinnedState:"
+ " Unpinning extra Shortcuts for package: " + packageName
+ ": " + systemMap.get(packageName));
context.getSystemService(LauncherApps.class).pinShortcuts(
packageName, Collections.emptyList(), user);
} catch (SecurityException | IllegalStateException e) {
@@ -24,6 +24,7 @@ import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SH
import static com.android.launcher3.LauncherSettings.Favorites.TABLE_NAME;
import static com.android.launcher3.Utilities.SHOULD_SHOW_FIRST_PAGE_WIDGET;
import static com.android.launcher3.icons.cache.CacheLookupFlag.DEFAULT_LOOKUP_FLAG;
import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_ARCHIVED;
import android.content.ComponentName;
import android.content.ContentValues;
@@ -307,7 +308,7 @@ public class LoaderCursor extends CursorWrapper {
* Make an WorkspaceItemInfo object for a restored application or shortcut item that points
* to a package that is not yet installed on the system.
*/
public WorkspaceItemInfo getRestoredItemInfo(Intent intent) {
public WorkspaceItemInfo getRestoredItemInfo(Intent intent, boolean isArchived) {
final WorkspaceItemInfo info = new WorkspaceItemInfo();
info.user = user;
info.intent = intent;
@@ -317,7 +318,7 @@ public class LoaderCursor extends CursorWrapper {
mIconCache.getTitleAndIcon(info, DEFAULT_LOOKUP_FLAG);
}
if (hasRestoreFlag(WorkspaceItemInfo.FLAG_RESTORED_ICON)) {
if (hasRestoreFlag(WorkspaceItemInfo.FLAG_RESTORED_ICON) || isArchived) {
String title = getTitle();
if (!TextUtils.isEmpty(title)) {
info.title = Utilities.trim(title);
@@ -333,6 +334,7 @@ public class LoaderCursor extends CursorWrapper {
info.contentDescription = mIconCache.getUserBadgedLabel(info.title, info.user);
info.itemType = itemType;
info.status = restoreFlag;
if (isArchived) info.runtimeStatusFlags |= FLAG_ARCHIVED;
return info;
}
@@ -15,6 +15,7 @@
*/
package com.android.launcher3.model;
import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT;
import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_PRIVATE_PROFILE_QUIET_MODE_ENABLED;
import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_QUIET_MODE_ENABLED;
import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_WORK_PROFILE_QUIET_MODE_ENABLED;
@@ -39,7 +40,6 @@ import androidx.annotation.NonNull;
import com.android.launcher3.Flags;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherModel.ModelUpdateTask;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.icons.IconCache;
@@ -238,19 +238,22 @@ public class PackageUpdatedTask implements ModelUpdateTask {
if (itemInfo.isPromise() && isNewApkAvailable) {
boolean isTargetValid = !cn.getClassName().equals(
IconCache.EMPTY_CLASS_NAME);
if (itemInfo.itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
if (itemInfo.itemType == ITEM_TYPE_DEEP_SHORTCUT) {
List<ShortcutInfo> shortcut =
new ShortcutRequest(context, mUser)
.forPackage(cn.getPackageName(),
itemInfo.getDeepShortcutId())
.query(ShortcutRequest.PINNED);
if (shortcut.isEmpty()) {
if (shortcut.isEmpty()
&& !(Flags.restoreArchivedShortcuts()
&& !itemInfo.isArchived())
) {
isTargetValid = false;
if (DEBUG) {
Log.d(TAG, "Pinned Shortcut not found for updated"
+ " package=" + itemInfo.getTargetPackage());
}
} else {
} else if (!shortcut.isEmpty()) {
if (DEBUG) {
Log.d(TAG, "Found pinned shortcut for updated"
+ " package=" + itemInfo.getTargetPackage()
@@ -269,7 +272,7 @@ public class PackageUpdatedTask implements ModelUpdateTask {
|| itemInfo.isArchived())) {
if (updateWorkspaceItemIntent(context, itemInfo, packageName)) {
infoUpdated = true;
} else if (itemInfo.hasPromiseIconUi()) {
} else if (shouldRemoveRestoredShortcut(itemInfo)) {
removedShortcuts.add(itemInfo.id);
if (DEBUG) {
FileLog.w(TAG, "Removing restored shortcut promise icon"
@@ -436,7 +439,7 @@ public class PackageUpdatedTask implements ModelUpdateTask {
*/
private boolean updateWorkspaceItemIntent(Context context,
WorkspaceItemInfo si, String packageName) {
if (si.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
if (si.itemType == ITEM_TYPE_DEEP_SHORTCUT) {
// Do not update intent for deep shortcuts as they contain additional information
// about the shortcut.
return false;
@@ -452,6 +455,15 @@ public class PackageUpdatedTask implements ModelUpdateTask {
return false;
}
private boolean shouldRemoveRestoredShortcut(WorkspaceItemInfo itemInfo) {
if (itemInfo.hasPromiseIconUi() && !Flags.restoreArchivedShortcuts()) {
return true;
}
return Flags.restoreArchivedShortcuts()
&& !itemInfo.isArchived()
&& itemInfo.itemType == ITEM_TYPE_DEEP_SHORTCUT;
}
private String getOpString() {
return switch (mOp) {
case OP_NONE -> "NONE";
@@ -17,6 +17,7 @@ package com.android.launcher3.model
import android.content.pm.ShortcutInfo
import android.os.UserHandle
import com.android.launcher3.Flags
import com.android.launcher3.LauncherModel.ModelUpdateTask
import com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT
import com.android.launcher3.icons.CacheableShortcutInfo
@@ -59,8 +60,11 @@ class ShortcutsChangedTask(
val infoWrapper = ApplicationInfoWrapper(context, packageName, user)
if (shortcuts.isEmpty()) {
// Verify that the app is indeed installed.
if (!infoWrapper.isInstalled() && !infoWrapper.isArchived()) {
// App is not installed or archived, ignoring package events
if (
(!infoWrapper.isInstalled() && !infoWrapper.isArchived()) ||
(Flags.restoreArchivedShortcuts() && infoWrapper.isArchived())
) {
// App is not installed or is archived, ignoring package events
return
}
}
@@ -75,7 +79,7 @@ class ShortcutsChangedTask(
val nonPinnedIds: MutableSet<String> = HashSet(allLauncherKnownIds)
val updatedWorkspaceItemInfos = ArrayList<WorkspaceItemInfo>()
for (fullDetails in shortcuts) {
if (!fullDetails.isPinned) {
if (!fullDetails.isPinned && !Flags.restoreArchivedShortcuts()) {
continue
}
val shortcutId = fullDetails.id
@@ -194,27 +194,36 @@ class WorkspaceItemProcessor(
if (intent.`package` == null) {
intent.`package` = targetPkg
}
val isPreArchived = appInfoWrapper.isArchived() && c.restoreFlag != 0
// else if cn == null => can't infer much, leave it
// else if !validPkg => could be restored icon or missing sd-card
when {
!TextUtils.isEmpty(targetPkg) && !validTarget -> {
!TextUtils.isEmpty(targetPkg) && (!validTarget || isPreArchived) -> {
// Points to a valid app (superset of cn != null) but the apk
// is not available.
when {
c.restoreFlag != 0 -> {
c.restoreFlag != 0 || isPreArchived -> {
// Package is not yet available but might be
// installed later.
FileLog.d(TAG, "package not yet restored: $targetPkg")
FileLog.d(
TAG,
"package not yet restored: $targetPkg, itemType=${c.itemType}" +
"isPreArchived=$isPreArchived, restoreFlag=${c.restoreFlag}",
)
tempPackageKey.update(targetPkg, c.user)
when {
c.hasRestoreFlag(WorkspaceItemInfo.FLAG_RESTORE_STARTED) -> {
// Restore has started once.
}
installingPkgs.containsKey(tempPackageKey) -> {
installingPkgs.containsKey(tempPackageKey) || isPreArchived -> {
// App restore has started. Update the flag
c.restoreFlag =
c.restoreFlag or WorkspaceItemInfo.FLAG_RESTORE_STARTED
FileLog.d(TAG, "restore started for installing app: $targetPkg")
FileLog.d(
TAG,
"restore started for installing app: $targetPkg, itemType=${c.itemType}",
)
c.updater().put(Favorites.RESTORED, c.restoreFlag).commit()
}
else -> {
@@ -253,9 +262,18 @@ class WorkspaceItemProcessor(
}
}
if (c.restoreFlag and WorkspaceItemInfo.FLAG_SUPPORTS_WEB_UI != 0) {
FileLog.d(
TAG,
"restore flag set AND WorkspaceItemInfo.FLAG_SUPPORTS_WEB_UI != 0, setting valid target to false: $targetPkg, itemType=${c.itemType}, restoreFlag=${c.restoreFlag}",
)
validTarget = false
}
if (validTarget) {
if (validTarget && !isPreArchived) {
FileLog.d(
TAG,
"valid target true, marking restored: $targetPkg," +
" itemType=${c.itemType}, restoreFlag=${c.restoreFlag}",
)
// The shortcut points to a valid target (either no target
// or something which is ready to be used)
c.markRestored()
@@ -265,7 +283,7 @@ class WorkspaceItemProcessor(
when {
c.restoreFlag != 0 -> {
// Already verified above that user is same as default user
info = c.getRestoredItemInfo(intent)
info = c.getRestoredItemInfo(intent, isPreArchived)
}
c.itemType == Favorites.ITEM_TYPE_APPLICATION ->
info = c.getAppShortcutInfo(intent, allowMissingTarget, useLowResIcon, false)