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

Commit 296278a0 authored by Winson Chung's avatar Winson Chung
Browse files

Fixing potential issue with wrong task descriptions being loaded.

- Also cleaning up the Task to remove some confusing nomenclature
  related to task properties.  Now there is a single icon and title,
  and we keep a copy of the TaskDescription for future icon loading.
- Also changing a few cases where we should be calling isFreeformTask()

Bug: 26221779
Change-Id: Iac20cc7b4912f76c14232a323981ab2e8f62628a
parent aaeaac17
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@
    android:layout_height="@dimen/recents_task_bar_height"
    android:layout_gravity="top|center_horizontal">
    <com.android.systemui.recents.views.FixedSizeImageView
        android:id="@+id/application_icon"
        android:id="@+id/icon"
        android:contentDescription="@string/recents_app_info_button_label"
        android:layout_width="@dimen/recents_task_view_application_icon_size"
        android:layout_height="@dimen/recents_task_view_application_icon_size"
@@ -29,7 +29,7 @@
        android:padding="8dp"
        android:background="@drawable/recents_button_bg" />
    <TextView
        android:id="@+id/activity_description"
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|start"
+3 −3
Original line number Diff line number Diff line
@@ -207,7 +207,7 @@ public class RecentsImpl extends IRecentsNonSystemUserCallbacks.Stub implements
        RecentsTaskLoadPlan plan = loader.createLoadPlan(mContext);
        loader.preloadTasks(plan, true /* isTopTaskHome */);
        RecentsTaskLoadPlan.Options launchOpts = new RecentsTaskLoadPlan.Options();
        launchOpts.numVisibleTasks = loader.getApplicationIconCacheSize();
        launchOpts.numVisibleTasks = loader.getIconCacheSize();
        launchOpts.numVisibleTaskThumbnails = loader.getThumbnailCacheSize();
        launchOpts.onlyLoadForCache = true;
        loader.loadTasks(mContext, plan, launchOpts);
@@ -452,7 +452,7 @@ public class RecentsImpl extends IRecentsNonSystemUserCallbacks.Stub implements
        }

        // Launch the task
        ssp.startActivityFromRecents(mContext, toTask.key.id, toTask.activityLabel, launchOpts);
        ssp.startActivityFromRecents(mContext, toTask.key.id, toTask.title, launchOpts);
    }

    /**
@@ -524,7 +524,7 @@ public class RecentsImpl extends IRecentsNonSystemUserCallbacks.Stub implements
        MetricsLogger.count(mContext, "overview_affiliated_task_launch", 1);

        // Launch the task
        ssp.startActivityFromRecents(mContext, toTask.key.id, toTask.activityLabel, launchOpts);
        ssp.startActivityFromRecents(mContext, toTask.key.id, toTask.title, launchOpts);
    }

    public void showNextAffiliatedTask() {
+3 −4
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ import com.android.systemui.recents.Recents;
import com.android.systemui.recents.events.EventBus;
import com.android.systemui.recents.events.activity.HideHistoryButtonEvent;
import com.android.systemui.recents.events.activity.HideHistoryEvent;
import com.android.systemui.recents.misc.ReferenceCountedTrigger;
import com.android.systemui.recents.misc.SystemServicesProxy;
import com.android.systemui.recents.model.RecentsTaskLoader;
import com.android.systemui.recents.model.Task;
@@ -72,7 +71,7 @@ public class RecentsHistoryAdapter extends RecyclerView.Adapter<RecentsHistoryAd
        public void onTaskDataLoaded(Task task) {
            // This callback is only made for TaskRow view holders
            ImageView iv = (ImageView) content.findViewById(R.id.icon);
            iv.setImageDrawable(task.applicationIcon);
            iv.setImageDrawable(task.icon);
        }

        @Override
@@ -128,7 +127,7 @@ public class RecentsHistoryAdapter extends RecyclerView.Adapter<RecentsHistoryAd
        @Override
        public void onClick(View v) {
            SystemServicesProxy ssp = Recents.getSystemServices();
            ssp.startActivityFromRecents(v.getContext(), task.key.id, task.activityLabel,
            ssp.startActivityFromRecents(v.getContext(), task.key.id, task.title,
                    ActivityOptions.makeBasic());
        }

@@ -240,7 +239,7 @@ public class RecentsHistoryAdapter extends RecyclerView.Adapter<RecentsHistoryAd
                TaskRow taskRow = (TaskRow) row;
                taskRow.task.addCallback(holder);
                TextView tv = (TextView) holder.content.findViewById(R.id.description);
                tv.setText(taskRow.task.activityLabel);
                tv.setText(taskRow.task.title);
                holder.content.setOnClickListener(taskRow);
                loader.loadTaskData(taskRow.task);
                break;
+26 −3
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import android.graphics.Point;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
@@ -572,7 +573,7 @@ public class SystemServicesProxy {
     * Returns the activity icon for the ActivityInfo for a user, badging if
     * necessary.
     */
    public Drawable getActivityIcon(ActivityInfo info, int userId) {
    public Drawable getBadgedActivityIcon(ActivityInfo info, int userId) {
        if (mPm == null) return null;

        // If we are mocking, then return a mock label
@@ -584,10 +585,32 @@ public class SystemServicesProxy {
        return getBadgedIcon(icon, userId);
    }

    /**
     * Returns the task description icon, loading and badging it if it necessary.
     */
    public Drawable getBadgedTaskDescriptionIcon(ActivityManager.TaskDescription taskDescription,
            int userId, Resources res) {

        // If we are mocking, then return a mock label
        if (RecentsDebugFlags.Static.EnableSystemServicesProxy) {
            return new ColorDrawable(0xFF666666);
        }

        Bitmap tdIcon = taskDescription.getInMemoryIcon();
        if (tdIcon == null) {
            tdIcon = ActivityManager.TaskDescription.loadTaskDescriptionIcon(
                    taskDescription.getIconFilename(), userId);
        }
        if (tdIcon != null) {
            return getBadgedIcon(new BitmapDrawable(res, tdIcon), userId);
        }
        return null;
    }

    /**
     * Returns the given icon for a user, badging if necessary.
     */
    public Drawable getBadgedIcon(Drawable icon, int userId) {
    private Drawable getBadgedIcon(Drawable icon, int userId) {
        if (userId != UserHandle.myUserId()) {
            icon = mPm.getUserBadgedIcon(icon, new UserHandle(userId));
        }
@@ -597,7 +620,7 @@ public class SystemServicesProxy {
    /**
     * Returns the given label for a user, badging if necessary.
     */
    public String getBadgedLabel(String label, int userId) {
    private String getBadgedLabel(String label, int userId) {
        if (userId != UserHandle.myUserId()) {
            label = mPm.getUserBadgedLabel(label, new UserHandle(userId)).toString();
        }
+15 −48
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ import android.util.Log;
import com.android.systemui.Prefs;
import com.android.systemui.recents.Recents;
import com.android.systemui.recents.RecentsConfiguration;
import com.android.systemui.recents.RecentsDebugFlags;
import com.android.systemui.recents.misc.SystemServicesProxy;

import java.util.ArrayList;
@@ -47,9 +46,6 @@ import java.util.List;
 */
public class RecentsTaskLoadPlan {

    private static String TAG = "RecentsTaskLoadPlan";
    private static boolean DEBUG = false;

    private static int MIN_NUM_TASKS = 5;
    private static int SESSION_BEGIN_TIME = 1000 /* ms/s */ * 60 /* s/min */ * 60 /* min/hr */ *
            6 /* hrs */;
@@ -107,13 +103,6 @@ public class RecentsTaskLoadPlan {

        // Since the raw tasks are given in most-recent to least-recent order, we need to reverse it
        Collections.reverse(mRawTasks);

        if (DEBUG) {
            Log.d(TAG, "preloadRawTasks, tasks: " + mRawTasks.size());
            for (ActivityManager.RecentTaskInfo info : mRawTasks) {
                Log.d(TAG, "  " + info.baseIntent + ", " + info.lastActiveTime);
            }
        }
    }

    /**
@@ -126,8 +115,6 @@ public class RecentsTaskLoadPlan {
     * - least-recent to most-recent freeform tasks
     */
    public synchronized void preloadPlan(RecentsTaskLoader loader, boolean isTopTaskHome) {
        if (DEBUG) Log.d(TAG, "preloadPlan");

        RecentsConfiguration config = Recents.getConfiguration();
        SystemServicesProxy ssp = Recents.getSystemServices();
        Resources res = mContext.getResources();
@@ -149,38 +136,26 @@ public class RecentsTaskLoadPlan {

            // This task is only shown in the stack if it statisfies the historical time or min
            // number of tasks constraints. Freeform tasks are also always shown.
            boolean isStackTask = true;
            boolean isFreeformTask = SystemServicesProxy.isFreeformStack(t.stackId);
            isStackTask = isFreeformTask || (!isHistoricalTask(t) ||
                    (t.lastActiveTime >= lastStackActiveTime &&
                            i >= (taskCount - MIN_NUM_TASKS)));
            boolean isStackTask = isFreeformTask || (!isHistoricalTask(t) ||
                    (t.lastActiveTime >= lastStackActiveTime && i >= (taskCount - MIN_NUM_TASKS)));
            if (isStackTask && newLastStackActiveTime < 0) {
                newLastStackActiveTime = t.lastActiveTime;
            }

            // Load the label, icon, and color
            String activityLabel = loader.getAndUpdateActivityLabel(taskKey, t.taskDescription,
                    ssp);
            String contentDescription = loader.getAndUpdateContentDescription(taskKey,
                    activityLabel, ssp, res);
            Drawable activityIcon = isStackTask
                    ? loader.getAndUpdateActivityIcon(taskKey, t.taskDescription, ssp, res, false)
            // Load the title, icon, and color
            String title = loader.getAndUpdateActivityTitle(taskKey, t.taskDescription);
            String contentDescription = loader.getAndUpdateContentDescription(taskKey, title, res);
            Drawable icon = isStackTask
                    ? loader.getAndUpdateActivityIcon(taskKey, t.taskDescription, res, false)
                    : null;
            Bitmap thumbnail = loader.getAndUpdateThumbnail(taskKey, false);
            int activityColor = loader.getActivityPrimaryColor(t.taskDescription);

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

            // Add the task to the stack
            Task task = new Task(taskKey, t.affiliatedTaskId, t.affiliatedTaskColor, activityLabel,
                    contentDescription, activityIcon, activityColor, (i == (taskCount - 1)),
                    config.lockToAppEnabled, !isStackTask, icon, iconFilename, t.bounds);
            task.thumbnail = loader.getAndUpdateThumbnail(taskKey, ssp, false);
            if (DEBUG) {
                Log.d(TAG, activityLabel + " bounds: " + t.bounds);
            }
            Task task = new Task(taskKey, t.affiliatedTaskId, t.affiliatedTaskColor, icon,
                    thumbnail, title, contentDescription, activityColor, !isStackTask,
                    (i == (taskCount - 1)), config.lockToAppEnabled, t.bounds, t.taskDescription);

            allTasks.add(task);
        }
@@ -200,19 +175,13 @@ public class RecentsTaskLoadPlan {
     */
    public synchronized void executePlan(Options opts, RecentsTaskLoader loader,
            TaskResourceLoadQueue loadQueue) {
        if (DEBUG) Log.d(TAG, "executePlan, # tasks: " + opts.numVisibleTasks +
                ", # thumbnails: " + opts.numVisibleTaskThumbnails +
                ", running task id: " + opts.runningTaskId);

        RecentsConfiguration config = Recents.getConfiguration();
        SystemServicesProxy ssp = Recents.getSystemServices();
        Resources res = mContext.getResources();

        // Iterate through each of the tasks and load them according to the load conditions.
        ArrayList<Task> tasks = mStack.getStackTasks();
        int taskCount = tasks.size();
        for (int i = 0; i < taskCount; i++) {
            ActivityManager.RecentTaskInfo t = mRawTasks.get(i);
            Task task = tasks.get(i);
            Task.TaskKey taskKey = task.key;

@@ -226,17 +195,15 @@ public class RecentsTaskLoadPlan {
            }

            if (opts.loadIcons && (isRunningTask || isVisibleTask)) {
                if (task.activityIcon == null) {
                    if (DEBUG) Log.d(TAG, "\tLoading icon: " + taskKey);
                    task.activityIcon = loader.getAndUpdateActivityIcon(taskKey, t.taskDescription,
                            ssp, res, true);
                if (task.icon == null) {
                    task.icon = loader.getAndUpdateActivityIcon(taskKey, task.taskDescription,
                            res, true);
                }
            }
            if (opts.loadThumbnails && (isRunningTask || isVisibleThumbnail)) {
                if (task.thumbnail == null || isRunningTask) {
                    if (DEBUG) Log.d(TAG, "\tLoading thumbnail: " + taskKey);
                    if (config.svelteLevel <= RecentsConfiguration.SVELTE_LIMIT_CACHE) {
                        task.thumbnail = loader.getAndUpdateThumbnail(taskKey, ssp, true);
                        task.thumbnail = loader.getAndUpdateThumbnail(taskKey, true);
                    } else if (config.svelteLevel == RecentsConfiguration.SVELTE_DISABLE_CACHE) {
                        loadQueue.addTask(task);
                    }
Loading