Deleting invalid icons when an app is restored

When a app is restored, it may not be in exactly the same state as it was when backed up.
Some components might be missing, and some shortcuts may be disabled or unavailable

Bug: 63525806
Change-Id: I09e6c0e9a9d2c1e8ccd73430f94bd065bdf2718e
This commit is contained in:
Sunny Goyal
2018-05-30 15:22:00 -07:00
parent 813ab5c83e
commit e48fe1095d
3 changed files with 37 additions and 14 deletions

View File

@@ -18,7 +18,6 @@ package com.android.launcher3.model;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Process;
import android.os.UserHandle;
import android.util.ArrayMap;
@@ -42,6 +41,9 @@ import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.graphics.BitmapInfo;
import com.android.launcher3.graphics.LauncherIcons;
import com.android.launcher3.logging.FileLog;
import com.android.launcher3.shortcuts.DeepShortcutManager;
import com.android.launcher3.shortcuts.ShortcutInfoCompat;
import com.android.launcher3.util.FlagOp;
import com.android.launcher3.util.ItemInfoMatcher;
import com.android.launcher3.util.LongArrayMap;
@@ -52,6 +54,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
/**
* Handles updates due to changes in package manager (app installed/updated/removed)
@@ -162,12 +165,7 @@ public class PackageUpdatedTask extends BaseModelUpdateTask {
final ArrayMap<ComponentName, AppInfo> addedOrUpdatedApps = new ArrayMap<>();
if (!addedOrModified.isEmpty()) {
scheduleCallbackTask(new CallbackTask() {
@Override
public void execute(Callbacks callbacks) {
callbacks.bindAppsAddedOrUpdated(addedOrModified);
}
});
scheduleCallbackTask((callbacks) -> callbacks.bindAppsAddedOrUpdated(addedOrModified));
for (AppInfo ai : addedOrModified) {
addedOrUpdatedApps.put(ai.componentName, ai);
}
@@ -213,11 +211,26 @@ public class PackageUpdatedTask extends BaseModelUpdateTask {
}
if (si.isPromise() && isNewApkAvailable) {
boolean isTargetValid = true;
if (si.itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
List<ShortcutInfoCompat> shortcut = DeepShortcutManager
.getInstance(context).queryForPinnedShortcuts(
cn.getPackageName(),
Arrays.asList(si.getDeepShortcutId()), mUser);
if (shortcut.isEmpty()) {
isTargetValid = false;
} else {
si.updateFromDeepShortcutInfo(shortcut.get(0), context);
infoUpdated = true;
}
} else if (!cn.getClassName().equals(IconCache.EMPTY_CLASS_NAME)) {
isTargetValid = LauncherAppsCompat.getInstance(context)
.isActivityEnabledForProfile(cn, mUser);
}
if (si.hasStatusFlag(ShortcutInfo.FLAG_AUTOINSTALL_ICON)) {
// Auto install icon
LauncherAppsCompat launcherApps
= LauncherAppsCompat.getInstance(context);
if (!launcherApps.isActivityEnabledForProfile(cn, mUser)) {
if (!isTargetValid) {
// Try to find the best match activity.
Intent intent = new PackageManagerHelper(context)
.getAppLaunchIntent(cn.getPackageName(), mUser);
@@ -235,6 +248,11 @@ public class PackageUpdatedTask extends BaseModelUpdateTask {
continue;
}
}
} else if (!isTargetValid) {
removedShortcuts.put(si.id, true);
FileLog.e(TAG, "Restored shortcut no longer valid "
+ si.intent);
continue;
} else {
si.status = ShortcutInfo.DEFAULT;
infoUpdated = true;