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

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

Merge "Expose some methods in the recents lib."

parents 9f4e7dbf b05b398c
Loading
Loading
Loading
Loading
+7 −18
Original line number Diff line number Diff line
@@ -69,21 +69,6 @@ public class RecentsTaskLoadPlan {
        mKeyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
    }

    /**
     * An optimization to preload the raw list of tasks. The raw tasks are saved in least-recent
     * to most-recent order.
     *
     * Note: Do not lock, callers should synchronize on the loader before making this call.
     */
    void preloadRawTasks() {
        int currentUserId = ActivityManagerWrapper.getInstance().getCurrentUserId();
        mRawTasks = ActivityManagerWrapper.getInstance().getRecentTasks(
                ActivityManager.getMaxRecentTasksStatic(), currentUserId);

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

    /**
     * Preloads the list of recent tasks from the system. After this call, the TaskStack will
     * have a list of all the recent tasks with their metadata, not including icons or
@@ -95,11 +80,15 @@ public class RecentsTaskLoadPlan {
     * Note: Do not lock, since this can be calling back to the loader, which separately also drives
     * this call (callers should synchronize on the loader before making this call).
     */
    void preloadPlan(RecentsTaskLoader loader, int runningTaskId) {
    public void preloadPlan(RecentsTaskLoader loader, int runningTaskId, int currentUserId) {
        Resources res = mContext.getResources();
        ArrayList<Task> allTasks = new ArrayList<>();
        if (mRawTasks == null) {
            preloadRawTasks();
            mRawTasks = ActivityManagerWrapper.getInstance().getRecentTasks(
                    ActivityManager.getMaxRecentTasksStatic(), currentUserId);

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

        int taskCount = mRawTasks.size();
@@ -160,7 +149,7 @@ public class RecentsTaskLoadPlan {
     * Note: Do not lock, since this can be calling back to the loader, which separately also drives
     * this call (callers should synchronize on the loader before making this call).
     */
    void executePlan(Options opts, RecentsTaskLoader loader) {
    public void executePlan(Options opts, RecentsTaskLoader loader) {
        Resources res = mContext.getResources();

        // Iterate through each of the tasks and load them according to the load conditions.
+7 −1
Original line number Diff line number Diff line
@@ -147,9 +147,15 @@ public class RecentsTaskLoader {

    /** Preloads recents tasks using the specified plan to store the output. */
    public synchronized void preloadTasks(RecentsTaskLoadPlan plan, int runningTaskId) {
        preloadTasks(plan, runningTaskId, ActivityManagerWrapper.getInstance().getCurrentUserId());
    }

    /** Preloads recents tasks using the specified plan to store the output. */
    public synchronized void preloadTasks(RecentsTaskLoadPlan plan, int runningTaskId,
            int currentUserId) {
        try {
            Trace.beginSection("preloadPlan");
            plan.preloadPlan(this, runningTaskId);
            plan.preloadPlan(this, runningTaskId, currentUserId);
        } finally {
            Trace.endSection();
        }
+1 −1
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ import android.util.SparseArray;
/**
 * An interface for a task filter to query whether a particular task should show in a stack.
 */
interface TaskFilter {
public interface TaskFilter {
    /** Returns whether the filter accepts the specified task */
    boolean acceptTask(SparseArray<Task> taskIdMap, Task t, int index);
}
+84 −0
Original line number Diff line number Diff line
@@ -17,10 +17,17 @@
package com.android.systemui.shared.system;

import static android.app.ActivityManager.RECENT_IGNORE_UNAVAILABLE;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY;
import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY;
import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;

import android.annotation.NonNull;
import android.app.ActivityManager;
import android.app.ActivityManager.RecentTaskInfo;
import android.app.ActivityOptions;
import android.app.AppGlobals;
import android.content.Context;
import android.content.pm.ActivityInfo;
@@ -32,15 +39,19 @@ import android.content.res.Resources.NotFoundException;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.RemoteException;
import android.os.UserHandle;
import android.util.IconDrawableFactory;
import android.util.Log;

import com.android.systemui.shared.recents.model.Task;
import com.android.systemui.shared.recents.model.Task.TaskKey;
import com.android.systemui.shared.recents.model.ThumbnailData;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

public class ActivityManagerWrapper {

@@ -76,6 +87,25 @@ public class ActivityManagerWrapper {
        }
    }

    /**
     * @return the top running task (can be {@code null}).
     */
    public ActivityManager.RunningTaskInfo getRunningTask() {
        // Note: The set of running tasks from the system is ordered by recency
        try {
            List<ActivityManager.RunningTaskInfo> tasks =
                    ActivityManager.getService().getFilteredTasks(1,
                            ACTIVITY_TYPE_RECENTS /* ignoreActivityType */,
                            WINDOWING_MODE_PINNED /* ignoreWindowingMode */);
            if (tasks.isEmpty()) {
                return null;
            }
            return tasks.get(0);
        } catch (RemoteException e) {
            return null;
        }
    }

    /**
     * @return a list of the recents tasks.
     */
@@ -201,6 +231,60 @@ public class ActivityManagerWrapper {
        return label;
    }

    /**
     * Starts a task from Recents.
     *
     * @see {@link #startActivityFromRecents(TaskKey, ActivityOptions, int, int, Consumer, Handler)}
     */
    public void startActivityFromRecents(Task.TaskKey taskKey, ActivityOptions options,
            Consumer<Boolean> resultCallback, Handler resultCallbackHandler) {
        startActivityFromRecents(taskKey, options, WINDOWING_MODE_UNDEFINED,
                ACTIVITY_TYPE_UNDEFINED, resultCallback, resultCallbackHandler);
    }

    /**
     * Starts a task from Recents.
     *
     * @param resultCallback The result success callback
     * @param resultCallbackHandler The handler to receive the result callback
     */
    public void startActivityFromRecents(Task.TaskKey taskKey, ActivityOptions options,
            int windowingMode, int activityType, Consumer<Boolean> resultCallback,
            Handler resultCallbackHandler) {
        if (taskKey.windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
            // We show non-visible docked tasks in Recents, but we always want to launch
            // them in the fullscreen stack.
            if (options == null) {
                options = ActivityOptions.makeBasic();
            }
            options.setLaunchWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY);
        } else if (windowingMode != WINDOWING_MODE_UNDEFINED
                || activityType != ACTIVITY_TYPE_UNDEFINED) {
            if (options == null) {
                options = ActivityOptions.makeBasic();
            }
            options.setLaunchWindowingMode(windowingMode);
            options.setLaunchActivityType(activityType);
        }
        final ActivityOptions finalOptions = options;

        // Execute this from another thread such that we can do other things (like caching the
        // bitmap for the thumbnail) while AM is busy starting our activity.
        mBackgroundExecutor.submit(() -> {
            try {
                ActivityManager.getService().startActivityFromRecents(taskKey.id,
                        finalOptions == null ? null : finalOptions.toBundle());
                if (resultCallback != null) {
                    resultCallbackHandler.post(() -> resultCallback.accept(true));
                }
            } catch (Exception e) {
                if (resultCallback != null) {
                    resultCallbackHandler.post(() -> resultCallback.accept(false));
                }
            }
        });
    }

    /**
     * Requests that the system close any open system windows (including other SystemUI).
     */
+3 −3
Original line number Diff line number Diff line
@@ -411,12 +411,12 @@ public class Recents extends SystemUI
        }

        int currentUser = sSystemServicesProxy.getCurrentUser();
        SystemServicesProxy ssp = Recents.getSystemServices();
        ActivityManager.RunningTaskInfo runningTask = ssp.getRunningTask();
        ActivityManager.RunningTaskInfo runningTask =
                ActivityManagerWrapper.getInstance().getRunningTask();
        final int activityType = runningTask != null
                ? runningTask.configuration.windowConfiguration.getActivityType()
                : ACTIVITY_TYPE_UNDEFINED;
        boolean screenPinningActive = ssp.isScreenPinningActive();
        boolean screenPinningActive = sSystemServicesProxy.isScreenPinningActive();
        boolean isRunningTaskInHomeOrRecentsStack =
                activityType == ACTIVITY_TYPE_HOME || activityType == ACTIVITY_TYPE_RECENTS;
        if (runningTask != null && !isRunningTaskInHomeOrRecentsStack && !screenPinningActive) {
Loading