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

Commit 26256f79 authored by Jon Miranda's avatar Jon Miranda
Browse files

Fix work profile promise icon bugs.

- We did not pass in the user when creating the workspace item infos.
- Added check for if app is installed before adding item to workspace
  to prevent any stale promise icons. This seems to happen when uninstalling
  and then immediately reinstalling an application.

Bug: 141556707
Change-Id: I2db2d8da449c37eb248a59fbc9e7b517f50855c1
parent 892cf58a
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -454,6 +454,8 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
                    .object()
                    .key(LAUNCH_INTENT_KEY).value(launchIntent.toUri(0))
                    .key(NAME_KEY).value(name)
                    .key(USER_HANDLE_KEY).value(
                            UserManagerCompat.getInstance(mContext).getSerialNumberForUser(user))
                    .key(APP_SHORTCUT_TYPE_KEY).value(isActivity);
                if (icon != null) {
                    byte[] iconByteArray = GraphicsUtils.flattenBitmap(icon);
@@ -475,7 +477,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver {

        public Pair<ItemInfo, Object> getItemInfo() {
            if (isActivity) {
                WorkspaceItemInfo si = createWorkspaceItemInfo(data,
                WorkspaceItemInfo si = createWorkspaceItemInfo(data, user,
                        LauncherAppState.getInstance(mContext));
                si.itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
                si.status |= WorkspaceItemInfo.FLAG_AUTOINSTALL_ICON;
@@ -500,7 +502,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
                return Pair.create(widgetInfo, providerInfo);
            } else {
                WorkspaceItemInfo itemInfo =
                        createWorkspaceItemInfo(data, LauncherAppState.getInstance(mContext));
                        createWorkspaceItemInfo(data, user, LauncherAppState.getInstance(mContext));
                return Pair.create(itemInfo, null);
            }
        }
@@ -618,7 +620,8 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
        return new PendingInstallShortcutInfo(info, original.mContext);
    }

    private static WorkspaceItemInfo createWorkspaceItemInfo(Intent data, LauncherAppState app) {
    private static WorkspaceItemInfo createWorkspaceItemInfo(Intent data, UserHandle user,
            LauncherAppState app) {
        if (data == null) {
            Log.e(TAG, "Can't construct WorkspaceItemInfo with null data");
            return null;
@@ -635,10 +638,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
        }

        final WorkspaceItemInfo info = new WorkspaceItemInfo();

        // Only support intents for current user for now. Intents sent from other
        // users wouldn't get here without intent forwarding anyway.
        info.user = Process.myUserHandle();
        info.user = user;

        BitmapInfo iconInfo = null;
        LauncherIcons li = LauncherIcons.obtain(app.getContext());
+17 −12
Original line number Diff line number Diff line
@@ -117,11 +117,22 @@ public class AddWorkspaceItemsTask extends BaseModelUpdateTask {
                    }
                    SessionInfo sessionInfo = packageInstaller.getActiveSessionInfo(item.user,
                            packageName);
                    if (sessionInfo == null) {
                    List<LauncherActivityInfo> activities = launcherApps
                            .getActivityList(packageName, item.user);
                        if (activities != null && !activities.isEmpty()) {
                            // App was installed while launcher was in the background.
                    boolean hasActivity = activities != null && !activities.isEmpty();

                    if (sessionInfo == null) {
                        if (!hasActivity) {
                            // Session was cancelled, do not add.
                            continue;
                        }
                    } else {
                        workspaceInfo.setInstallProgress((int) sessionInfo.getProgress());
                    }

                    if (hasActivity) {
                        // App was installed while launcher was in the background,
                        // or app was already installed for another user.
                        itemInfo = new AppInfo(app.getContext(), activities.get(0), item.user)
                                .makeWorkspaceItem();
                        WorkspaceItemInfo wii = (WorkspaceItemInfo) itemInfo;
@@ -129,12 +140,6 @@ public class AddWorkspaceItemsTask extends BaseModelUpdateTask {
                        wii.applyFrom(app.getIconCache().getDefaultIcon(item.user));
                        app.getIconCache().getTitleAndIcon(wii,
                                ((WorkspaceItemInfo) itemInfo).usingLowResIcon());
                        } else {
                            // Session was cancelled, do not add.
                            continue;
                        }
                    } else {
                        workspaceInfo.setInstallProgress((int) sessionInfo.getProgress());
                    }
                }