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:
@@ -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);
|
||||
|
||||
@@ -141,6 +141,8 @@ public class PackageInstallerCompatVL extends PackageInstallerCompat {
|
||||
* - The settings for it are enabled
|
||||
* - The user installed the app
|
||||
* - There is an app icon and label (For apps with no launching activity, no icon is provided).
|
||||
* - The app is not already installed
|
||||
* - A promise icon for the session has not already been created
|
||||
*/
|
||||
private void tryQueuePromiseAppIcon(SessionInfo sessionInfo) {
|
||||
if (Utilities.ATLEAST_OREO && FeatureFlags.PROMISE_APPS_NEW_INSTALLS.get()
|
||||
@@ -149,7 +151,9 @@ public class PackageInstallerCompatVL extends PackageInstallerCompat {
|
||||
&& sessionInfo.getInstallReason() == PackageManager.INSTALL_REASON_USER
|
||||
&& sessionInfo.getAppIcon() != null
|
||||
&& !TextUtils.isEmpty(sessionInfo.getAppLabel())
|
||||
&& !mPromiseIconIds.contains(sessionInfo.getSessionId())) {
|
||||
&& !mPromiseIconIds.contains(sessionInfo.getSessionId())
|
||||
&& mLauncherApps.getApplicationInfo(sessionInfo.getAppPackageName(), 0,
|
||||
getUserHandle(sessionInfo)) == null) {
|
||||
SessionCommitReceiver.queuePromiseAppIconAddition(mAppContext, sessionInfo);
|
||||
mPromiseIconIds.add(sessionInfo.getSessionId());
|
||||
updatePromiseIconPrefs();
|
||||
@@ -184,12 +188,14 @@ public class PackageInstallerCompatVL extends PackageInstallerCompat {
|
||||
sendUpdate(PackageInstallInfo.fromState(success ? STATUS_INSTALLED : STATUS_FAILED,
|
||||
packageName, key.mUser));
|
||||
|
||||
if (!success && FeatureFlags.PROMISE_APPS_NEW_INSTALLS.get()) {
|
||||
if (!success && FeatureFlags.PROMISE_APPS_NEW_INSTALLS.get()
|
||||
&& mPromiseIconIds.contains(sessionId)) {
|
||||
LauncherAppState appState = LauncherAppState.getInstanceNoCreate();
|
||||
if (appState != null) {
|
||||
LauncherModel model = appState.getModel();
|
||||
model.onPackageRemoved(packageName, key.mUser);
|
||||
appState.getModel().onSessionFailure(packageName, key.mUser);
|
||||
}
|
||||
// If it is successful, the id is removed in the the package added flow.
|
||||
removePromiseIconId(sessionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user