Fix bug where existing icon is removed when install session is abandonded.

- Ensure we only add promise icons for apps that aren't already installed to
  our internal list of session ids.
- Ensure we only remove promise icons created from the install session when
  that session is abandonded.

Bug: 140819614
Change-Id: I3c93865b5e96a9c7a160154b45a38eb90ac9d183
This commit is contained in:
Jon Miranda
2019-09-10 13:38:06 -07:00
parent 599b1fc4d3
commit 1c247cf451
2 changed files with 36 additions and 4 deletions

View File

@@ -20,6 +20,7 @@ import static com.android.launcher3.LauncherAppState.ACTION_FORCE_ROLOAD;
import static com.android.launcher3.config.FeatureFlags.IS_DOGFOOD_BUILD;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ShortcutInfo;
@@ -51,6 +52,7 @@ import com.android.launcher3.model.UserLockStateChangedTask;
import com.android.launcher3.shortcuts.DeepShortcutManager;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.IntArray;
import com.android.launcher3.util.IntSparseArrayMap;
import com.android.launcher3.util.ItemInfoMatcher;
import com.android.launcher3.util.PackageUserKey;
import com.android.launcher3.util.Preconditions;
@@ -211,6 +213,30 @@ public class LauncherModel extends BroadcastReceiver
enqueueModelUpdateTask(new PackageUpdatedTask(op, user, packageName));
}
public void onSessionFailure(String packageName, UserHandle user) {
enqueueModelUpdateTask(new BaseModelUpdateTask() {
@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
final IntSparseArrayMap<Boolean> removedIds = new IntSparseArrayMap<>();
synchronized (dataModel) {
for (ItemInfo info : dataModel.itemsIdMap) {
if (info instanceof WorkspaceItemInfo
&& ((WorkspaceItemInfo) info).hasPromiseIconUi()
&& user.equals(info.user)
&& info.getIntent() != null
&& TextUtils.equals(packageName, info.getIntent().getPackage())) {
removedIds.put(info.id, false /* unused value */);
}
}
}
if (!removedIds.isEmpty()) {
deleteAndBindComponentsRemoved(ItemInfoMatcher.ofItemIds(removedIds, false));
}
}
});
}
@Override
public void onPackageRemoved(String packageName, UserHandle user) {
onPackagesRemoved(user, packageName);