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

Commit bdd4b201 authored by Jorim Jaggi's avatar Jorim Jaggi
Browse files

Don't preload task description icons when opening recents

Bug: 17624331
Change-Id: I55a1184efd5982122f87fab99a5402336b380d7c
parent 759962ab
Loading
Loading
Loading
Loading
+17 −7
Original line number Original line Diff line number Diff line
@@ -635,21 +635,31 @@ public class ActivityManager {
            if (mIcon != null) {
            if (mIcon != null) {
                return mIcon;
                return mIcon;
            }
            }
            if (mIconFilename != null) {
            return loadTaskDescriptionIcon(mIconFilename);
        }

        /** @hide */
        public String getIconFilename() {
            return mIconFilename;
        }

        /** @hide */
        public Bitmap getInMemoryIcon() {
            return mIcon;
        }

        /** @hide */
        public static Bitmap loadTaskDescriptionIcon(String iconFilename) {
            if (iconFilename != null) {
                try {
                try {
                    return ActivityManagerNative.getDefault().
                    return ActivityManagerNative.getDefault().
                            getTaskDescriptionIcon(mIconFilename);
                            getTaskDescriptionIcon(iconFilename);
                } catch (RemoteException e) {
                } catch (RemoteException e) {
                }
                }
            }
            }
            return null;
            return null;
        }
        }


        /** @hide */
        public String getIconFilename() {
            return mIconFilename;
        }

        /**
        /**
         * @return The color override on the theme's primary color.
         * @return The color override on the theme's primary color.
         */
         */
+44 −13
Original line number Original line Diff line number Diff line
@@ -177,16 +177,24 @@ class TaskResourceLoader implements Runnable {
                if (t != null) {
                if (t != null) {
                    Drawable cachedIcon = mApplicationIconCache.get(t.key);
                    Drawable cachedIcon = mApplicationIconCache.get(t.key);
                    Bitmap cachedThumbnail = mThumbnailCache.get(t.key);
                    Bitmap cachedThumbnail = mThumbnailCache.get(t.key);

                    // Load the application icon if it is stale or we haven't cached one yet
                    // Load the application icon if it is stale or we haven't cached one yet
                    if (cachedIcon == null) {
                        cachedIcon = getTaskDescriptionIcon(t.key, t.icon, t.iconFilename, ssp,
                                mContext.getResources());

                        if (cachedIcon == null) {
                        if (cachedIcon == null) {
                            ActivityInfo info = ssp.getActivityInfo(t.key.baseIntent.getComponent(),
                            ActivityInfo info = ssp.getActivityInfo(t.key.baseIntent.getComponent(),
                                    t.key.userId);
                                    t.key.userId);
                            if (info != null) {
                            if (info != null) {
                                cachedIcon = ssp.getActivityIcon(info, t.key.userId);
                                cachedIcon = ssp.getActivityIcon(info, t.key.userId);
                            }
                            }
                        }

                        if (cachedIcon == null) {
                        if (cachedIcon == null) {
                            cachedIcon = mDefaultApplicationIcon;
                            cachedIcon = mDefaultApplicationIcon;
                        }
                        }

                        // At this point, even if we can't load the icon, we will set the default
                        // At this point, even if we can't load the icon, we will set the default
                        // icon.
                        // icon.
                        mApplicationIconCache.put(t.key, cachedIcon);
                        mApplicationIconCache.put(t.key, cachedIcon);
@@ -230,6 +238,17 @@ class TaskResourceLoader implements Runnable {
            }
            }
        }
        }
    }
    }

    Drawable getTaskDescriptionIcon(Task.TaskKey taskKey, Bitmap iconBitmap, String iconFilename,
            SystemServicesProxy ssp, Resources res) {
        Bitmap tdIcon = iconBitmap != null
                ? iconBitmap
                : ActivityManager.TaskDescription.loadTaskDescriptionIcon(iconFilename);
        if (tdIcon != null) {
            return ssp.getBadgedIcon(new BitmapDrawable(res, tdIcon), taskKey.userId);
        }
        return null;
    }
}
}


/* Recents task loader
/* Recents task loader
@@ -321,15 +340,20 @@ public class RecentsTaskLoader {
        if (icon != null) {
        if (icon != null) {
            return icon;
            return icon;
        }
        }
        // Return the task description icon if it exists

        if (td != null && td.getIcon() != null) {
        // If we are preloading this task, continue to load the task description icon or the
            icon = ssp.getBadgedIcon(new BitmapDrawable(res, td.getIcon()), taskKey.userId);
        // activity icon
            mApplicationIconCache.put(taskKey, icon);
            return icon;
        }
        // If we are preloading this task, continue to load the activity icon
        if (preloadTask) {
        if (preloadTask) {
            // All short paths failed, load the icon from the activity info and cache it

            // Return and cache the task description icon if it exists
            Drawable tdDrawable = mLoader.getTaskDescriptionIcon(taskKey, td.getInMemoryIcon(),
                    td.getIconFilename(), ssp, res);
            if (tdDrawable != null) {
                mApplicationIconCache.put(taskKey, tdDrawable);
                return tdDrawable;
            }

            // Load the icon from the activity info and cache it
            if (infoHandle.info == null) {
            if (infoHandle.info == null) {
                infoHandle.info = ssp.getActivityInfo(taskKey.baseIntent.getComponent(),
                infoHandle.info = ssp.getActivityInfo(taskKey.baseIntent.getComponent(),
                        taskKey.userId);
                        taskKey.userId);
@@ -453,10 +477,17 @@ public class RecentsTaskLoader {
                activityInfoCache.put(cnKey, infoHandle);
                activityInfoCache.put(cnKey, infoHandle);
            }
            }


            Bitmap icon = t.taskDescription != null
                    ? t.taskDescription.getInMemoryIcon()
                    : null;
            String iconFilename = t.taskDescription != null
                    ? t.taskDescription.getIconFilename()
                    : null;

            // Add the task to the stack
            // Add the task to the stack
            Task task = new Task(taskKey, (t.id > -1), t.affiliatedTaskId, t.affiliatedTaskColor,
            Task task = new Task(taskKey, (t.id > -1), t.affiliatedTaskId, t.affiliatedTaskColor,
                    activityLabel, activityIcon, activityColor, (i == (taskCount - 1)),
                    activityLabel, activityIcon, activityColor, (i == (taskCount - 1)),
                    config.lockToAppEnabled);
                    config.lockToAppEnabled, icon, iconFilename);


            if (preloadTask && loadTaskThumbnails) {
            if (preloadTask && loadTaskThumbnails) {
                // Load the thumbnail from the cache if possible
                // Load the thumbnail from the cache if possible
+6 −2
Original line number Original line Diff line number Diff line
@@ -124,7 +124,8 @@ public class Task {
    public boolean isActive;
    public boolean isActive;
    public boolean lockToThisTask;
    public boolean lockToThisTask;
    public boolean lockToTaskEnabled;
    public boolean lockToTaskEnabled;

    public Bitmap icon;
    public String iconFilename;
    TaskCallbacks mCb;
    TaskCallbacks mCb;


    public Task() {
    public Task() {
@@ -133,7 +134,8 @@ public class Task {


    public Task(TaskKey key, boolean isActive, int taskAffiliation, int taskAffiliationColor,
    public Task(TaskKey key, boolean isActive, int taskAffiliation, int taskAffiliationColor,
                String activityTitle, Drawable activityIcon, int colorPrimary,
                String activityTitle, Drawable activityIcon, int colorPrimary,
                boolean lockToThisTask, boolean lockToTaskEnabled) {
                boolean lockToThisTask, boolean lockToTaskEnabled, Bitmap icon,
                String iconFilename) {
        boolean isInAffiliationGroup = (taskAffiliation != key.id);
        boolean isInAffiliationGroup = (taskAffiliation != key.id);
        boolean hasAffiliationGroupColor = isInAffiliationGroup && (taskAffiliationColor != 0);
        boolean hasAffiliationGroupColor = isInAffiliationGroup && (taskAffiliationColor != 0);
        this.key = key;
        this.key = key;
@@ -147,6 +149,8 @@ public class Task {
        this.isActive = isActive;
        this.isActive = isActive;
        this.lockToThisTask = lockToTaskEnabled && lockToThisTask;
        this.lockToThisTask = lockToTaskEnabled && lockToThisTask;
        this.lockToTaskEnabled = lockToTaskEnabled;
        this.lockToTaskEnabled = lockToTaskEnabled;
        this.icon = icon;
        this.iconFilename = iconFilename;
    }
    }


    /** Copies the other task. */
    /** Copies the other task. */