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

Commit a449dc03 authored by Winson Chung's avatar Winson Chung
Browse files

Refactoring RecentsActivityValues into TaskDescription, and ensuring they are...

Refactoring RecentsActivityValues into TaskDescription, and ensuring they are resolved when set. (Bug 14995928, 14832629)

Change-Id: I582221468e63a96a5dfd132a31b09e72099b170f
parent d4bac5ea
Loading
Loading
Loading
Loading
+16 −17
Original line number Diff line number Diff line
@@ -3352,12 +3352,12 @@ package android.app {
    method public final void setProgressBarIndeterminate(boolean);
    method public final void setProgressBarIndeterminateVisibility(boolean);
    method public final void setProgressBarVisibility(boolean);
    method public void setRecentsActivityValues(android.app.ActivityManager.RecentsActivityValues);
    method public void setRequestedOrientation(int);
    method public final void setResult(int);
    method public final void setResult(int, android.content.Intent);
    method public final void setSecondaryProgress(int);
    method public void setSharedElementListener(android.app.SharedElementListener);
    method public void setTaskDescription(android.app.ActivityManager.TaskDescription);
    method public void setTitle(java.lang.CharSequence);
    method public void setTitle(int);
    method public deprecated void setTitleColor(int);
@@ -3482,7 +3482,6 @@ package android.app {
    method public void readFromParcel(android.os.Parcel);
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator CREATOR;
    field public android.app.ActivityManager.RecentsActivityValues activityValues;
    field public android.content.Intent baseIntent;
    field public java.lang.CharSequence description;
    field public int id;
@@ -3490,21 +3489,6 @@ package android.app {
    field public int persistentId;
  }
  public static class ActivityManager.RecentsActivityValues implements android.os.Parcelable {
    ctor public ActivityManager.RecentsActivityValues(android.app.ActivityManager.RecentsActivityValues);
    ctor public ActivityManager.RecentsActivityValues(java.lang.CharSequence, android.graphics.Bitmap, int);
    ctor public ActivityManager.RecentsActivityValues(java.lang.CharSequence, android.graphics.Bitmap);
    ctor public ActivityManager.RecentsActivityValues(java.lang.CharSequence);
    ctor public ActivityManager.RecentsActivityValues();
    method public int describeContents();
    method public void readFromParcel(android.os.Parcel);
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator CREATOR;
    field public int colorPrimary;
    field public android.graphics.Bitmap icon;
    field public java.lang.CharSequence label;
  }
  public static class ActivityManager.RunningAppProcessInfo implements android.os.Parcelable {
    ctor public ActivityManager.RunningAppProcessInfo();
    ctor public ActivityManager.RunningAppProcessInfo(java.lang.String, int, java.lang.String[]);
@@ -3574,6 +3558,21 @@ package android.app {
    field public android.content.ComponentName topActivity;
  }
  public static class ActivityManager.TaskDescription implements android.os.Parcelable {
    ctor public ActivityManager.TaskDescription(android.app.ActivityManager.TaskDescription);
    ctor public ActivityManager.TaskDescription(java.lang.CharSequence, android.graphics.Bitmap, int);
    ctor public ActivityManager.TaskDescription(java.lang.CharSequence, android.graphics.Bitmap);
    ctor public ActivityManager.TaskDescription(java.lang.CharSequence);
    ctor public ActivityManager.TaskDescription();
    method public int describeContents();
    method public android.graphics.Bitmap getIcon();
    method public java.lang.CharSequence getLabel();
    method public int getPrimaryColor();
    method public void readFromParcel(android.os.Parcel);
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator CREATOR;
  }
  public class ActivityOptions {
    method public static android.app.ActivityOptions makeCustomAnimation(android.content.Context, int, int);
    method public static android.app.ActivityOptions makeScaleUpAnimation(android.view.View, int, int, int, int);
+21 −18
Original line number Diff line number Diff line
@@ -3611,15 +3611,15 @@ public class Activity extends ContextThemeWrapper
            theme.applyStyle(resid, false);
        }

        // Get the primary color and update the RecentsActivityValues for this activity
        // Get the primary color and update the TaskDescription for this activity
        if (theme != null) {
            TypedArray a = theme.obtainStyledAttributes(com.android.internal.R.styleable.Theme);
            int colorPrimary = a.getColor(com.android.internal.R.styleable.Theme_colorPrimary, 0);
            a.recycle();
            if (colorPrimary != 0) {
                ActivityManager.RecentsActivityValues v = new ActivityManager.RecentsActivityValues();
                v.colorPrimary = colorPrimary;
                setRecentsActivityValues(v);
                ActivityManager.TaskDescription v = new ActivityManager.TaskDescription(null, null,
                        colorPrimary);
                setTaskDescription(v);
            }
        }
    }
@@ -4924,27 +4924,30 @@ public class Activity extends ContextThemeWrapper
    }

    /**
     * Sets information describing this Activity for presentation inside the Recents System UI. When
     * {@link ActivityManager#getRecentTasks} is called, the activities of each task are
     * traversed in order from the topmost activity to the bottommost. The traversal continues for
     * each property until a suitable value is found. For each task those values will be returned in
     * {@link android.app.ActivityManager.RecentsActivityValues}.
     * Sets information describing the task with this activity for presentation inside the Recents
     * System UI. When {@link ActivityManager#getRecentTasks} is called, the activities of each task
     * are traversed in order from the topmost activity to the bottommost. The traversal continues
     * for each property until a suitable value is found. For each task the taskDescription will be
     * returned in {@link android.app.ActivityManager.TaskDescription}.
     *
     * @see ActivityManager#getRecentTasks
     * @see android.app.ActivityManager.RecentsActivityValues
     * @see android.app.ActivityManager.TaskDescription
     *
     * @param values The Recents values that describe this activity.
     * @param taskDescription The TaskDescription properties that describe the task with this activity
     */
    public void setRecentsActivityValues(ActivityManager.RecentsActivityValues values) {
        ActivityManager.RecentsActivityValues activityValues =
                new ActivityManager.RecentsActivityValues(values);
        // Scale the icon down to something reasonable
        if (values.icon != null) {
    public void setTaskDescription(ActivityManager.TaskDescription taskDescription) {
        ActivityManager.TaskDescription td;
        // Scale the icon down to something reasonable if it is provided
        if (taskDescription.getIcon() != null) {
            final int size = ActivityManager.getLauncherLargeIconSizeInner(this);
            activityValues.icon = Bitmap.createScaledBitmap(values.icon, size, size, true);
            final Bitmap icon = Bitmap.createScaledBitmap(taskDescription.getIcon(), size, size, true);
            td = new ActivityManager.TaskDescription(taskDescription.getLabel(), icon,
                    taskDescription.getPrimaryColor());
        } else {
            td = taskDescription;
        }
        try {
            ActivityManagerNative.getDefault().setRecentsActivityValues(mToken, activityValues);
            ActivityManagerNative.getDefault().setTaskDescription(mToken, td);
        } catch (RemoteException e) {
        }
    }
+78 −52
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Debug;
@@ -477,65 +478,84 @@ public class ActivityManager {
    /**
     * Information you can set and retrieve about the current activity within the recent task list.
     */
    public static class RecentsActivityValues implements Parcelable {
        public CharSequence label;
        public Bitmap icon;
        public int colorPrimary;

        public RecentsActivityValues(RecentsActivityValues values) {
            copyFrom(values);
        }
    public static class TaskDescription implements Parcelable {
        private String mLabel;
        private Bitmap mIcon;
        private int mColorPrimary;

        /**
         * Creates the RecentsActivityValues to the specified values.
         * Creates the TaskDescription to the specified values.
         *
         * @param label A label and description of the current state of this activity.
         * @param icon An icon that represents the current state of this activity.
         * @param color A color to override the theme's primary color.
         * @param label A label and description of the current state of this task.
         * @param icon An icon that represents the current state of this task.
         * @param colorPrimary A color to override the theme's primary color.  This color must be opaque.
         */
        public RecentsActivityValues(CharSequence label, Bitmap icon, int color) {
            this.label = label;
            this.icon = icon;
            this.colorPrimary = color;
        public TaskDescription(String label, Bitmap icon, int colorPrimary) {
            if ((colorPrimary != 0) && (Color.alpha(colorPrimary) != 255)) {
                throw new RuntimeException("A TaskDescription's primary color should be opaque");
            }

            mLabel = label;
            mIcon = icon;
            mColorPrimary = colorPrimary;
        }

        /**
         * Creates the RecentsActivityValues to the specified values.
         * Creates the TaskDescription to the specified values.
         *
         * @param label A label and description of the current state of this activity.
         * @param icon An icon that represents the current state of this activity.
         */
        public RecentsActivityValues(CharSequence label, Bitmap icon) {
        public TaskDescription(String label, Bitmap icon) {
            this(label, icon, 0);
        }

        /**
         * Creates the RecentsActivityValues to the specified values.
         * Creates the TaskDescription to the specified values.
         *
         * @param label A label and description of the current state of this activity.
         */
        public RecentsActivityValues(CharSequence label) {
        public TaskDescription(String label) {
            this(label, null, 0);
        }

        public RecentsActivityValues() {
        /**
         * Creates an empty TaskDescription.
         */
        public TaskDescription() {
            this(null, null, 0);
        }

        private RecentsActivityValues(Parcel source) {
        /**
         * Creates a copy of another TaskDescription.
         */
        public TaskDescription(TaskDescription td) {
            this(td.getLabel(), td.getIcon(), td.getPrimaryColor());
        }

        private TaskDescription(Parcel source) {
            readFromParcel(source);
        }

        /**
         * Do a shallow copy of another set of activity values.
         * @hide
         * @return The label and description of the current state of this task.
         */
        public void copyFrom(RecentsActivityValues v) {
            if (v != null) {
                label = v.label;
                icon = v.icon;
                colorPrimary = v.colorPrimary;
        public String getLabel() {
            return mLabel;
        }

        /**
         * @return The icon that represents the current state of this task.
         */
        public Bitmap getIcon() {
            return mIcon;
        }

        /**
         * @return The color override on the theme's primary color.
         */
        public int getPrimaryColor() {
            return mColorPrimary;
        }

        @Override
@@ -545,37 +565,41 @@ public class ActivityManager {

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            TextUtils.writeToParcel(label, dest,
                    Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
            if (icon == null) {
            if (mLabel == null) {
                dest.writeInt(0);
            } else {
                dest.writeInt(1);
                icon.writeToParcel(dest, 0);
                dest.writeString(mLabel);
            }
            dest.writeInt(colorPrimary);
            if (mIcon == null) {
                dest.writeInt(0);
            } else {
                dest.writeInt(1);
                mIcon.writeToParcel(dest, 0);
            }
            dest.writeInt(mColorPrimary);
        }

        public void readFromParcel(Parcel source) {
            label = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
            icon = source.readInt() > 0 ? Bitmap.CREATOR.createFromParcel(source) : null;
            colorPrimary = source.readInt();
            mLabel = source.readInt() > 0 ? source.readString() : null;
            mIcon = source.readInt() > 0 ? Bitmap.CREATOR.createFromParcel(source) : null;
            mColorPrimary = source.readInt();
        }

        public static final Creator<RecentsActivityValues> CREATOR
                = new Creator<RecentsActivityValues>() {
            public RecentsActivityValues createFromParcel(Parcel source) {
                return new RecentsActivityValues(source);
        public static final Creator<TaskDescription> CREATOR
                = new Creator<TaskDescription>() {
            public TaskDescription createFromParcel(Parcel source) {
                return new TaskDescription(source);
            }
            public RecentsActivityValues[] newArray(int size) {
                return new RecentsActivityValues[size];
            public TaskDescription[] newArray(int size) {
                return new TaskDescription[size];
            }
        };

        @Override
        public String toString() {
            return "RecentsActivityValues Label: " + label + " Icon: " + icon +
                    " colorPrimary: " + colorPrimary;
            return "TaskDescription Label: " + mLabel + " Icon: " + mIcon +
                    " colorPrimary: " + mColorPrimary;
        }
    }

@@ -629,9 +653,11 @@ public class ActivityManager {

        /**
         * The recent activity values for the highest activity in the stack to have set the values.
         * {@link Activity#setRecentsActivityValues(android.app.ActivityManager.RecentsActivityValues)}.
         * {@link Activity#setTaskDescription(android.app.ActivityManager.TaskDescription)}.
         *
         * @hide
         */
        public RecentsActivityValues activityValues;
        public TaskDescription taskDescription;

        public RecentTaskInfo() {
        }
@@ -654,9 +680,9 @@ public class ActivityManager {
            ComponentName.writeToParcel(origActivity, dest);
            TextUtils.writeToParcel(description, dest,
                    Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
            if (activityValues != null) {
            if (taskDescription != null) {
                dest.writeInt(1);
                activityValues.writeToParcel(dest, 0);
                taskDescription.writeToParcel(dest, 0);
            } else {
                dest.writeInt(0);
            }
@@ -670,8 +696,8 @@ public class ActivityManager {
            baseIntent = source.readInt() > 0 ? Intent.CREATOR.createFromParcel(source) : null;
            origActivity = ComponentName.readFromParcel(source);
            description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
            activityValues = source.readInt() > 0 ?
                    RecentsActivityValues.CREATOR.createFromParcel(source) : null;
            taskDescription = source.readInt() > 0 ?
                    TaskDescription.CREATOR.createFromParcel(source) : null;
            stackId = source.readInt();
            userId = source.readInt();
        }
+6 −6
Original line number Diff line number Diff line
@@ -2158,12 +2158,12 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM
            return true;
        }

        case SET_RECENTS_ACTIVITY_VALUES_TRANSACTION: {
        case SET_TASK_DESCRIPTION_TRANSACTION: {
            data.enforceInterface(IActivityManager.descriptor);
            IBinder token = data.readStrongBinder();
            ActivityManager.RecentsActivityValues values =
                    ActivityManager.RecentsActivityValues.CREATOR.createFromParcel(data);
            setRecentsActivityValues(token, values);
            ActivityManager.TaskDescription values =
                    ActivityManager.TaskDescription.CREATOR.createFromParcel(data);
            setTaskDescription(token, values);
            reply.writeNoException();
            return true;
        }
@@ -4967,14 +4967,14 @@ class ActivityManagerProxy implements IActivityManager
    }

    @Override
    public void setRecentsActivityValues(IBinder token, ActivityManager.RecentsActivityValues values)
    public void setTaskDescription(IBinder token, ActivityManager.TaskDescription values)
            throws RemoteException {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
        data.writeInterfaceToken(IActivityManager.descriptor);
        data.writeStrongBinder(token);
        values.writeToParcel(data, 0);
        mRemote.transact(SET_RECENTS_ACTIVITY_VALUES_TRANSACTION, data, reply, IBinder.FLAG_ONEWAY);
        mRemote.transact(SET_TASK_DESCRIPTION_TRANSACTION, data, reply, IBinder.FLAG_ONEWAY);
        reply.readException();
        data.recycle();
        reply.recycle();
+2 −2
Original line number Diff line number Diff line
@@ -440,7 +440,7 @@ public interface IActivityManager extends IInterface {
    public boolean isInLockTaskMode() throws RemoteException;

    /** @hide */
    public void setRecentsActivityValues(IBinder token, ActivityManager.RecentsActivityValues values)
    public void setTaskDescription(IBinder token, ActivityManager.TaskDescription values)
            throws RemoteException;

    /*
@@ -739,7 +739,7 @@ public interface IActivityManager extends IInterface {
    int START_LOCK_TASK_BY_TOKEN_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+214;
    int STOP_LOCK_TASK_MODE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+215;
    int IS_IN_LOCK_TASK_MODE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+216;
    int SET_RECENTS_ACTIVITY_VALUES_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+217;
    int SET_TASK_DESCRIPTION_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+217;
    int START_VOICE_ACTIVITY_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+218;
    int GET_ACTIVITY_OPTIONS_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+219;
    int GET_APP_TASKS_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+220;
Loading