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

Commit 6e6bd877 authored by Winson's avatar Winson
Browse files

Make mock tasks work again.

- Rename it so that it’s a bit more clear that they are mock tasks.

Change-Id: I53b9dab1789a208e74538cd8c3ee4ec58cfa364f
parent 3c107166
Loading
Loading
Loading
Loading
+12 −11
Original line number Diff line number Diff line
@@ -26,10 +26,6 @@ import com.android.systemui.tuner.TunerService;
 */
public class RecentsDebugFlags implements TunerService.Tunable {

    private static final String KEY_FAST_TOGGLE = "overview_fast_toggle_via_button";
    private static final String KEY_FAST_TOGGLE_INDICATOR = "overview_fast_toggle_indicator";
    private static final String KEY_INITIAL_STATE_PAGING = "overview_initial_state_paging";

    public static class Static {
        // Enables debug drawing for the transition thumbnail
        public static final boolean EnableTransitionThumbnailDebugMode = false;
@@ -39,18 +35,23 @@ public class RecentsDebugFlags implements TunerService.Tunable {
        public static final boolean DisableBackgroundCache = false;
        // Enables the task affiliations
        public static final boolean EnableAffiliatedTaskGroups = true;
        // Enables the simulated task affiliations
        public static final boolean EnableSimulatedTaskGroups = false;
        // Defines the number of mock task affiliations per group
        public static final int TaskAffiliationsGroupCount = 12;

        // Enables us to create mock recents tasks
        public static final boolean EnableSystemServicesProxy = false;
        public static final boolean EnableMockTasks = false;
        // Defines the number of mock recents packages to create
        public static final int SystemServicesProxyMockPackageCount = 3;
        public static final int MockTasksPackageCount = 3;
        // Defines the number of mock recents tasks to create
        public static final int SystemServicesProxyMockTaskCount = 100;
        public static final int MockTaskCount = 100;
        // Enables the simulated task affiliations
        public static final boolean EnableMockTaskGroups = false;
        // Defines the number of mock task affiliations per group
        public static final int MockTaskGroupsTaskCount = 12;
    }

    private static final String KEY_FAST_TOGGLE = "overview_fast_toggle_via_button";
    private static final String KEY_FAST_TOGGLE_INDICATOR = "overview_fast_toggle_indicator";
    private static final String KEY_INITIAL_STATE_PAGING = "overview_initial_state_paging";

    private boolean mFastToggleRecents;
    private boolean mFastToggleIndicator;
    private boolean mInitialStatePaging;
+21 −16
Original line number Diff line number Diff line
@@ -151,7 +151,7 @@ public class SystemServicesProxy {
        // Resolve the assist intent
        mAssistComponent = mAssistUtils.getAssistComponentForUser(UserHandle.myUserId());

        if (RecentsDebugFlags.Static.EnableSystemServicesProxy) {
        if (RecentsDebugFlags.Static.EnableMockTasks) {
            // Create a dummy icon
            mDummyIcon = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
            mDummyIcon.eraseColor(0xFF999999);
@@ -164,20 +164,20 @@ public class SystemServicesProxy {
        if (mAm == null) return null;

        // If we are mocking, then create some recent tasks
        if (RecentsDebugFlags.Static.EnableSystemServicesProxy) {
        if (RecentsDebugFlags.Static.EnableMockTasks) {
            ArrayList<ActivityManager.RecentTaskInfo> tasks =
                    new ArrayList<ActivityManager.RecentTaskInfo>();
            int count = Math.min(numLatestTasks, RecentsDebugFlags.Static.SystemServicesProxyMockTaskCount);
            int count = Math.min(numLatestTasks, RecentsDebugFlags.Static.MockTaskCount);
            for (int i = 0; i < count; i++) {
                // Create a dummy component name
                int packageIndex = i % RecentsDebugFlags.Static.SystemServicesProxyMockPackageCount;
                int packageIndex = i % RecentsDebugFlags.Static.MockTasksPackageCount;
                ComponentName cn = new ComponentName("com.android.test" + packageIndex,
                        "com.android.test" + i + ".Activity");
                String description = "" + i + " - " +
                        Long.toString(Math.abs(new Random().nextLong()), 36);
                // Create the recent task info
                ActivityManager.RecentTaskInfo rti = new ActivityManager.RecentTaskInfo();
                rti.id = rti.persistentId = i;
                rti.id = rti.persistentId = rti.affiliatedTaskId = i;
                rti.baseIntent = new Intent();
                rti.baseIntent.setComponent(cn);
                rti.description = description;
@@ -418,7 +418,7 @@ public class SystemServicesProxy {
        if (mAm == null) return null;

        // If we are mocking, then just return a dummy thumbnail
        if (RecentsDebugFlags.Static.EnableSystemServicesProxy) {
        if (RecentsDebugFlags.Static.EnableMockTasks) {
            Bitmap thumbnail = Bitmap.createBitmap(mDummyThumbnailWidth, mDummyThumbnailHeight,
                    Bitmap.Config.ARGB_8888);
            thumbnail.eraseColor(0xff333333);
@@ -484,7 +484,7 @@ public class SystemServicesProxy {
    /** Moves a task to the front with the specified activity options. */
    public void moveTaskToFront(int taskId, ActivityOptions opts) {
        if (mAm == null) return;
        if (RecentsDebugFlags.Static.EnableSystemServicesProxy) return;
        if (RecentsDebugFlags.Static.EnableMockTasks) return;

        if (opts != null) {
            mAm.moveTaskToFront(taskId, ActivityManager.MOVE_TASK_WITH_HOME,
@@ -497,7 +497,7 @@ public class SystemServicesProxy {
    /** Removes the task */
    public void removeTask(final int taskId) {
        if (mAm == null) return;
        if (RecentsDebugFlags.Static.EnableSystemServicesProxy) return;
        if (RecentsDebugFlags.Static.EnableMockTasks) return;

        // Remove the task.
        BackgroundThread.getHandler().post(new Runnable() {
@@ -528,7 +528,7 @@ public class SystemServicesProxy {
     */
    public ActivityInfo getActivityInfo(ComponentName cn, int userId) {
        if (mIpm == null) return null;
        if (RecentsDebugFlags.Static.EnableSystemServicesProxy) return new ActivityInfo();
        if (RecentsDebugFlags.Static.EnableMockTasks) return new ActivityInfo();

        try {
            return mIpm.getActivityInfo(cn, PackageManager.GET_META_DATA, userId);
@@ -545,7 +545,7 @@ public class SystemServicesProxy {
     */
    public ActivityInfo getActivityInfo(ComponentName cn) {
        if (mPm == null) return null;
        if (RecentsDebugFlags.Static.EnableSystemServicesProxy) return new ActivityInfo();
        if (RecentsDebugFlags.Static.EnableMockTasks) return new ActivityInfo();

        try {
            return mPm.getActivityInfo(cn, PackageManager.GET_META_DATA);
@@ -562,7 +562,7 @@ public class SystemServicesProxy {
        if (mPm == null) return null;

        // If we are mocking, then return a mock label
        if (RecentsDebugFlags.Static.EnableSystemServicesProxy) {
        if (RecentsDebugFlags.Static.EnableMockTasks) {
            return "Recent Task: " + userId;
        }

@@ -576,7 +576,7 @@ public class SystemServicesProxy {
        if (mPm == null) return null;

        // If we are mocking, then return a mock label
        if (RecentsDebugFlags.Static.EnableSystemServicesProxy) {
        if (RecentsDebugFlags.Static.EnableMockTasks) {
            return "Recent Task App: " + userId;
        }

@@ -588,6 +588,11 @@ public class SystemServicesProxy {
     * description joins the app and activity labels.
     */
    public String getBadgedContentDescription(ActivityInfo info, int userId, Resources res) {
        // If we are mocking, then return a mock label
        if (RecentsDebugFlags.Static.EnableMockTasks) {
            return "Recent Task Content Description: " + userId;
        }

        String activityLabel = info.loadLabel(mPm).toString();
        String applicationLabel = info.applicationInfo.loadLabel(mPm).toString();
        String badgedApplicationLabel = getBadgedLabel(applicationLabel, userId);
@@ -604,7 +609,7 @@ public class SystemServicesProxy {
        if (mPm == null) return null;

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

@@ -620,7 +625,7 @@ public class SystemServicesProxy {
        if (mPm == null) return null;

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

@@ -635,7 +640,7 @@ public class SystemServicesProxy {
            int userId, Resources res) {

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

@@ -673,7 +678,7 @@ public class SystemServicesProxy {
    /** Returns the package name of the home activity. */
    public String getHomeActivityPackageName() {
        if (mPm == null) return null;
        if (RecentsDebugFlags.Static.EnableSystemServicesProxy) return null;
        if (RecentsDebugFlags.Static.EnableMockTasks) return null;

        ArrayList<ResolveInfo> homeActivities = new ArrayList<>();
        ComponentName defaultHomeActivity = mPm.getHomeActivities(homeActivities);
+5 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Debug;
import android.os.UserHandle;
import android.os.UserManager;
import android.util.ArraySet;
@@ -31,6 +32,7 @@ import com.android.systemui.Prefs;
import com.android.systemui.R;
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;
@@ -130,6 +132,9 @@ public class RecentsTaskLoadPlan {
                R.string.accessibility_recents_item_will_be_dismissed);
        long lastStackActiveTime = Prefs.getLong(mContext,
                Prefs.Key.OVERVIEW_LAST_STACK_TASK_ACTIVE_TIME, 0);
        if (RecentsDebugFlags.Static.EnableMockTasks) {
            lastStackActiveTime = 0;
        }
        long newLastStackActiveTime = -1;
        int taskCount = mRawTasks.size();
        for (int i = 0; i < taskCount; i++) {
+3 −3
Original line number Diff line number Diff line
@@ -776,7 +776,7 @@ public class TaskStack {
     * Temporary: This method will simulate affiliation groups by
     */
    public void createAffiliatedGroupings(Context context) {
        if (RecentsDebugFlags.Static.EnableSimulatedTaskGroups) {
        if (RecentsDebugFlags.Static.EnableMockTaskGroups) {
            ArrayMap<Task.TaskKey, Task> taskMap = new ArrayMap<>();
            // Sort all tasks by increasing firstActiveTime of the task
            ArrayList<Task> tasks = mStackTaskList.getTasks();
@@ -792,7 +792,7 @@ public class TaskStack {
            String prevPackage = "";
            int prevAffiliation = -1;
            Random r = new Random();
            int groupCountDown = RecentsDebugFlags.Static.TaskAffiliationsGroupCount;
            int groupCountDown = RecentsDebugFlags.Static.MockTaskGroupsTaskCount;
            for (int i = 0; i < taskCount; i++) {
                Task t = tasks.get(i);
                String packageName = t.key.getComponent().getPackageName();
@@ -807,7 +807,7 @@ public class TaskStack {
                    addGroup(group);
                    prevAffiliation = affiliation;
                    prevPackage = packageName;
                    groupCountDown = RecentsDebugFlags.Static.TaskAffiliationsGroupCount;
                    groupCountDown = RecentsDebugFlags.Static.MockTaskGroupsTaskCount;
                }
                group.addTask(t);
                taskMap.put(t.key, t);