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

Commit d0c7c20e authored by Winson Chung's avatar Winson Chung Committed by Android (Google) Code Review
Browse files

Merge "Save and pass last snapshot data with recents task info" into sc-dev

parents a7f6e5ea 71718ad7
Loading
Loading
Loading
Loading
+77 −1
Original line number Diff line number Diff line
@@ -50,7 +50,9 @@ import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.Icon;
import android.hardware.HardwareBuffer;
import android.os.BatteryStats;
import android.os.Binder;
import android.os.Build;
@@ -76,6 +78,7 @@ import android.util.Singleton;
import android.util.Size;
import android.util.TypedXmlPullParser;
import android.util.TypedXmlSerializer;
import android.window.TaskSnapshot;

import com.android.internal.app.LocalePicker;
import com.android.internal.app.procstats.ProcessStats;
@@ -1739,6 +1742,62 @@ public class ActivityManager {
     * started or visited.
     */
    public static class RecentTaskInfo extends TaskInfo implements Parcelable {
        /**
         * @hide
         */
        public static class PersistedTaskSnapshotData {
            /**
             * The bounds of the task when the last snapshot was taken, may be null if the task is
             * not yet attached to the hierarchy.
             * @see {@link android.window.TaskSnapshot#mTaskSize}.
             * @hide
             */
            public @Nullable Point taskSize;

            /**
             * The content insets of the task when the task snapshot was taken.
             * @see {@link android.window.TaskSnapshot#mContentInsets}.
             * @hide
             */
            public @Nullable Rect contentInsets;

            /**
             * The size of the last snapshot taken, may be null if there is no associated snapshot.
             * @see {@link android.window.TaskSnapshot#mSnapshot}.
             * @hide
             */
            public @Nullable Point bufferSize;

            /**
             * Sets the data from the other data.
             * @hide
             */
            public void set(PersistedTaskSnapshotData other) {
                taskSize = other.taskSize;
                contentInsets = other.contentInsets;
                bufferSize = other.bufferSize;
            }

            /**
             * Sets the data from the provided {@param snapshot}.
             * @hide
             */
            public void set(TaskSnapshot snapshot) {
                if (snapshot == null) {
                    taskSize = null;
                    contentInsets = null;
                    bufferSize = null;
                    return;
                }
                final HardwareBuffer buffer = snapshot.getHardwareBuffer();
                taskSize = new Point(snapshot.getTaskSize());
                contentInsets = new Rect(snapshot.getContentInsets());
                bufferSize = buffer != null
                        ? new Point(buffer.getWidth(), buffer.getHeight())
                        : null;
            }
        }

        /**
         * If this task is currently running, this is the identifier for it.
         * If it is not running, this will be -1.
@@ -1782,6 +1841,12 @@ public class ActivityManager {
         */
        public ArrayList<RecentTaskInfo> childrenTaskInfos = new ArrayList<>();

        /**
         * Information about the last snapshot taken for this task.
         * @hide
         */
        public PersistedTaskSnapshotData lastSnapshotData = new PersistedTaskSnapshotData();

        public RecentTaskInfo() {
        }

@@ -1798,6 +1863,9 @@ public class ActivityManager {
            id = source.readInt();
            persistentId = source.readInt();
            childrenTaskInfos = source.readArrayList(RecentTaskInfo.class.getClassLoader());
            lastSnapshotData.taskSize = source.readTypedObject(Point.CREATOR);
            lastSnapshotData.contentInsets = source.readTypedObject(Rect.CREATOR);
            lastSnapshotData.bufferSize = source.readTypedObject(Point.CREATOR);
            super.readFromParcel(source);
        }

@@ -1806,6 +1874,9 @@ public class ActivityManager {
            dest.writeInt(id);
            dest.writeInt(persistentId);
            dest.writeList(childrenTaskInfos);
            dest.writeTypedObject(lastSnapshotData.taskSize, flags);
            dest.writeTypedObject(lastSnapshotData.contentInsets, flags);
            dest.writeTypedObject(lastSnapshotData.bufferSize, flags);
            super.writeToParcel(dest, flags);
        }

@@ -1825,7 +1896,6 @@ public class ActivityManager {
        public void dump(PrintWriter pw, String indent) {
            pw.println(); pw.print("   ");
            pw.print(" id="); pw.print(persistentId);
            pw.print(" stackId="); pw.print(stackId);
            pw.print(" userId="); pw.print(userId);
            pw.print(" hasTask="); pw.print((id != -1));
            pw.print(" lastActiveTime="); pw.println(lastActiveTime);
@@ -1872,6 +1942,12 @@ public class ActivityManager {
                pw.print(Integer.toHexString(td.getBackgroundColorFloating()));
                pw.println(" }");
            }
            pw.print("   ");
            pw.print(" lastSnapshotData {");
            pw.print(" taskSize=" + lastSnapshotData.taskSize);
            pw.print(" contentInsets=" + lastSnapshotData.contentInsets);
            pw.print(" bufferSize=" + lastSnapshotData.bufferSize);
            pw.println(" }");
        }
    }

+1 −10
Original line number Diff line number Diff line
@@ -52,13 +52,6 @@ public class TaskInfo {
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    public int userId;

    /**
     * The id of the ActivityStack that currently contains this task.
     * @hide
     */
    @UnsupportedAppUsage
    public int stackId;

    /**
     * The identifier for this task.
     */
@@ -358,7 +351,6 @@ public class TaskInfo {
     */
    void readFromParcel(Parcel source) {
        userId = source.readInt();
        stackId = source.readInt();
        taskId = source.readInt();
        displayId = source.readInt();
        isRunning = source.readBoolean();
@@ -394,7 +386,6 @@ public class TaskInfo {
     */
    void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(userId);
        dest.writeInt(stackId);
        dest.writeInt(taskId);
        dest.writeInt(displayId);
        dest.writeBoolean(isRunning);
@@ -428,7 +419,7 @@ public class TaskInfo {

    @Override
    public String toString() {
        return "TaskInfo{userId=" + userId + " stackId=" + stackId + " taskId=" + taskId
        return "TaskInfo{userId=" + userId + " taskId=" + taskId
                + " displayId=" + displayId
                + " isRunning=" + isRunning
                + " baseIntent=" + baseIntent + " baseActivity=" + baseActivity
+22 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.graphics;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Parcel;
import android.os.Parcelable;

@@ -95,6 +96,27 @@ public class Point implements Parcelable {
        return "Point(" + x + ", " + y + ")";
    }

    /**
     * @return Returns a {@link String} that represents this point which can be parsed with
     * {@link #unflattenFromString(String)}.
     * @hide
     */
    @NonNull
    public String flattenToString() {
        return x + "x" + y;
    }

    /**
     * @return Returns a {@link Point} from a short string created from {@link #flattenToString()}.
     * @hide
     */
    @Nullable
    public static Point unflattenFromString(String s) throws NumberFormatException {
        final int sep_ix = s.indexOf("x");
        return new Point(Integer.parseInt(s.substring(0, sep_ix)),
                Integer.parseInt(s.substring(sep_ix + 1)));
    }

    /**
     * Parcelable interface methods
     */
+12 −141
Original line number Diff line number Diff line
@@ -43,17 +43,6 @@ public class Task {

    public static final String TAG = "Task";

    /* Task callbacks */
    @Deprecated
    public interface TaskCallbacks {
        /* Notifies when a task has been bound */
        void onTaskDataLoaded(Task task, ThumbnailData thumbnailData);
        /* Notifies when a task has been unbound */
        void onTaskDataUnloaded();
        /* Notifies when a task's windowing mode has changed. */
        void onTaskWindowingModeChanged();
    }

    /**
     * The Task Key represents the unique primary key for the task
     */
@@ -208,12 +197,6 @@ public class Task {
    @ViewDebug.ExportedProperty(deepExport=true, prefix="key_")
    public TaskKey key;

    /**
     * The temporary sort index in the stack, used when ordering the stack.
     */
    @Deprecated
    public int temporarySortIndexInStack;

    /**
     * The icon is the task description icon (if provided), which falls back to the activity icon,
     * which can then fall back to the application icon.
@@ -229,45 +212,24 @@ public class Task {
    public int colorPrimary;
    @ViewDebug.ExportedProperty(category="recents")
    public int colorBackground;
    @ViewDebug.ExportedProperty(category="recents")
    @Deprecated
    public boolean useLightOnPrimaryColor;

    /**
     * The task description for this task, only used to reload task icons.
     */
    public TaskDescription taskDescription;

    /**
     * The state isLaunchTarget will be set for the correct task upon launching Recents.
     */
    @ViewDebug.ExportedProperty(category="recents")
    @Deprecated
    public boolean isLaunchTarget;
    @ViewDebug.ExportedProperty(category="recents")
    @Deprecated
    public boolean isStackTask;
    @ViewDebug.ExportedProperty(category="recents")
    @Deprecated
    public boolean isSystemApp;
    @ViewDebug.ExportedProperty(category="recents")
    public boolean isDockable;

    /**
     * Resize mode. See {@link ActivityInfo#resizeMode}.
     */
    @ViewDebug.ExportedProperty(category="recents")
    @Deprecated
    public int resizeMode;

    @ViewDebug.ExportedProperty(category="recents")
    public ComponentName topActivity;

    @ViewDebug.ExportedProperty(category="recents")
    public boolean isLocked;

    @Deprecated
    private ArrayList<TaskCallbacks> mCallbacks = new ArrayList<>();
    // Last snapshot data, only used for recent tasks
    public ActivityManager.RecentTaskInfo.PersistedTaskSnapshotData lastSnapshotData =
            new ActivityManager.RecentTaskInfo.PersistedTaskSnapshotData();

    public Task() {
        // Do nothing
@@ -289,6 +251,15 @@ public class Task {
        this.taskDescription = new TaskDescription();
    }

    public Task(Task other) {
        this(other.key, other.colorPrimary, other.colorBackground, other.isDockable,
                other.isLocked, other.taskDescription, other.topActivity);
    }

    /**
     * Use {@link Task#Task(Task)}.
     */
    @Deprecated
    public Task(TaskKey key, int colorPrimary, int colorBackground,
            boolean isDockable, boolean isLocked, TaskDescription taskDescription,
            ComponentName topActivity) {
@@ -301,103 +272,6 @@ public class Task {
        this.topActivity = topActivity;
    }

    @Deprecated
    public Task(TaskKey key, Drawable icon, ThumbnailData thumbnail, String title,
            String titleDescription, int colorPrimary, int colorBackground, boolean isLaunchTarget,
            boolean isStackTask, boolean isSystemApp, boolean isDockable,
            TaskDescription taskDescription, int resizeMode, ComponentName topActivity,
            boolean isLocked) {
        this.key = key;
        this.icon = icon;
        this.thumbnail = thumbnail;
        this.title = title;
        this.titleDescription = titleDescription;
        this.colorPrimary = colorPrimary;
        this.colorBackground = colorBackground;
        this.useLightOnPrimaryColor = Utilities.computeContrastBetweenColors(this.colorPrimary,
                Color.WHITE) > 3f;
        this.taskDescription = taskDescription;
        this.isLaunchTarget = isLaunchTarget;
        this.isStackTask = isStackTask;
        this.isSystemApp = isSystemApp;
        this.isDockable = isDockable;
        this.resizeMode = resizeMode;
        this.topActivity = topActivity;
        this.isLocked = isLocked;
    }

    /**
     * Copies the metadata from another task, but retains the current callbacks.
     */
    @Deprecated
    public void copyFrom(Task o) {
        this.key = o.key;
        this.icon = o.icon;
        this.thumbnail = o.thumbnail;
        this.title = o.title;
        this.titleDescription = o.titleDescription;
        this.colorPrimary = o.colorPrimary;
        this.colorBackground = o.colorBackground;
        this.useLightOnPrimaryColor = o.useLightOnPrimaryColor;
        this.taskDescription = o.taskDescription;
        this.isLaunchTarget = o.isLaunchTarget;
        this.isStackTask = o.isStackTask;
        this.isSystemApp = o.isSystemApp;
        this.isDockable = o.isDockable;
        this.resizeMode = o.resizeMode;
        this.isLocked = o.isLocked;
        this.topActivity = o.topActivity;
    }

    /**
     * Add a callback.
     */
    @Deprecated
    public void addCallback(TaskCallbacks cb) {
        if (!mCallbacks.contains(cb)) {
            mCallbacks.add(cb);
        }
    }

    /**
     * Remove a callback.
     */
    @Deprecated
    public void removeCallback(TaskCallbacks cb) {
        mCallbacks.remove(cb);
    }

    /** Updates the task's windowing mode. */
    @Deprecated
    public void setWindowingMode(int windowingMode) {
        key.setWindowingMode(windowingMode);
        int callbackCount = mCallbacks.size();
        for (int i = 0; i < callbackCount; i++) {
            mCallbacks.get(i).onTaskWindowingModeChanged();
        }
    }

    /** Notifies the callback listeners that this task has been loaded */
    @Deprecated
    public void notifyTaskDataLoaded(ThumbnailData thumbnailData, Drawable applicationIcon) {
        this.icon = applicationIcon;
        this.thumbnail = thumbnailData;
        int callbackCount = mCallbacks.size();
        for (int i = 0; i < callbackCount; i++) {
            mCallbacks.get(i).onTaskDataLoaded(this, thumbnailData);
        }
    }

    /** Notifies the callback listeners that this task has been unloaded */
    @Deprecated
    public void notifyTaskDataUnloaded(Drawable defaultApplicationIcon) {
        icon = defaultApplicationIcon;
        thumbnail = null;
        for (int i = mCallbacks.size() - 1; i >= 0; i--) {
            mCallbacks.get(i).onTaskDataUnloaded();
        }
    }

    /**
     * Returns the top activity component.
     */
@@ -424,9 +298,6 @@ public class Task {
        if (!isDockable) {
            writer.print(" dockable=N");
        }
        if (isLaunchTarget) {
            writer.print(" launchTarget=Y");
        }
        if (isLocked) {
            writer.print(" locked=Y");
        }
+3 −0
Original line number Diff line number Diff line
@@ -58,6 +58,8 @@ import android.content.pm.ParceledListSlice;
import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.graphics.Rect;
import android.os.Environment;
import android.os.IBinder;
import android.os.RemoteException;
@@ -1886,6 +1888,7 @@ class RecentTasks {
        // Fill in some deprecated values.
        rti.id = rti.isRunning ? rti.taskId : INVALID_TASK_ID;
        rti.persistentId = rti.taskId;
        rti.lastSnapshotData.set(tr.mLastTaskSnapshotData);

        // Fill in organized child task info for the task created by organizer.
        if (tr.mCreatedByOrganizer) {
Loading