Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cfdeb062 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix bug where existing icon is removed when install session is...

Merge "Fix bug where existing icon is removed when install session is abandonded." into ub-launcher3-qt-qpr1-dev
parents 791dd732 1c247cf4
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -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);
+10 −4
Original line number Diff line number Diff line
@@ -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);
                }
            }
        }