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

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

Merge "Ensure task description icon resources are loaded from the right package"

parents 6a989fbf d6722037
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -4188,15 +4188,15 @@ package android.app {
  }
  public static class ActivityManager.TaskDescription implements android.os.Parcelable {
    ctor @Deprecated public ActivityManager.TaskDescription(String, android.graphics.Bitmap, int);
    ctor public ActivityManager.TaskDescription(String, @DrawableRes int, int);
    ctor @Deprecated public ActivityManager.TaskDescription(String, android.graphics.Bitmap);
    ctor public ActivityManager.TaskDescription(String, @DrawableRes int);
    ctor public ActivityManager.TaskDescription(String);
    ctor public ActivityManager.TaskDescription();
    ctor @Deprecated public ActivityManager.TaskDescription(String, android.graphics.Bitmap, int);
    ctor @Deprecated public ActivityManager.TaskDescription(String, android.graphics.Bitmap);
    ctor public ActivityManager.TaskDescription(android.app.ActivityManager.TaskDescription);
    method public int describeContents();
    method public android.graphics.Bitmap getIcon();
    method @Deprecated public android.graphics.Bitmap getIcon();
    method public String getLabel();
    method public int getPrimaryColor();
    method public void readFromParcel(android.os.Parcel);
+1 −0
Original line number Diff line number Diff line
@@ -98,6 +98,7 @@ package android.app {
  public static class ActivityManager.TaskDescription implements android.os.Parcelable {
    method public String getIconFilename();
    method public int getIconResource();
    method @Nullable public String getIconResourcePackage();
  }

  public class ActivityOptions {
+2 −1
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
import android.media.AudioManager;
import android.media.session.MediaController;
import android.net.Uri;
@@ -6897,7 +6898,7 @@ public class Activity extends ContextThemeWrapper
                final int size = ActivityManager.getLauncherLargeIconSizeInner(this);
                final Bitmap icon = Bitmap.createScaledBitmap(taskDescription.getIcon(), size, size,
                        true);
                mTaskDescription.setIcon(icon);
                mTaskDescription.setIcon(Icon.createWithBitmap(icon));
            }
        }
        try {
+138 −78
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ import android.graphics.GraphicBuffer;
import android.graphics.Matrix;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.Icon;
import android.os.BatteryStats;
import android.os.Binder;
import android.os.Build;
@@ -84,6 +85,7 @@ import com.android.internal.util.MemInfoReader;
import com.android.internal.util.Preconditions;
import com.android.server.LocalServices;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlSerializer;

import java.io.FileDescriptor;
@@ -1012,10 +1014,12 @@ public class ActivityManager {
                ATTR_TASKDESCRIPTION_PREFIX + "icon_filename";
        private static final String ATTR_TASKDESCRIPTIONICON_RESOURCE =
                ATTR_TASKDESCRIPTION_PREFIX + "icon_resource";
        private static final String ATTR_TASKDESCRIPTIONICON_RESOURCE_PACKAGE =
                ATTR_TASKDESCRIPTION_PREFIX + "icon_package";

        private String mLabel;
        private Bitmap mIcon;
        private int mIconRes;
        @Nullable
        private Icon mIcon;
        private String mIconFilename;
        private int mColorPrimary;
        private int mColorBackground;
@@ -1027,19 +1031,19 @@ public class ActivityManager {
        private int mMinWidth;
        private int mMinHeight;


        /**
         * Creates the TaskDescription to the specified values.
         *
         * @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 iconRes A drawable resource of an icon that represents the current state of this
         *                activity.
         * @param colorPrimary A color to override the theme's primary color.  This color must be
         *                     opaque.
         * @deprecated use TaskDescription constructor with icon resource instead
         */
        @Deprecated
        public TaskDescription(String label, Bitmap icon, int colorPrimary) {
            this(label, icon, 0, null, colorPrimary, 0, 0, 0, false, false,
                    RESIZE_MODE_RESIZEABLE, -1, -1);
        public TaskDescription(String label, @DrawableRes int iconRes, int colorPrimary) {
            this(label, Icon.createWithResource(ActivityThread.currentPackageName(), iconRes),
                    colorPrimary, 0, 0, 0, false, false, RESIZE_MODE_RESIZEABLE, -1, -1);
            if ((colorPrimary != 0) && (Color.alpha(colorPrimary) != 255)) {
                throw new RuntimeException("A TaskDescription's primary color should be opaque");
            }
@@ -1048,70 +1052,71 @@ public class ActivityManager {
        /**
         * Creates the TaskDescription to the specified values.
         *
         * @param label A label and description of the current state of this task.
         * @param label A label and description of the current state of this activity.
         * @param iconRes A drawable resource of an icon that represents the current state of this
         *                activity.
         * @param colorPrimary A color to override the theme's primary color.  This color must be
         *                     opaque.
         */
        public TaskDescription(String label, @DrawableRes int iconRes, int colorPrimary) {
            this(label, null, iconRes, null, colorPrimary, 0, 0, 0, false, false,
                    RESIZE_MODE_RESIZEABLE, -1, -1);
            if ((colorPrimary != 0) && (Color.alpha(colorPrimary) != 255)) {
                throw new RuntimeException("A TaskDescription's primary color should be opaque");
            }
        public TaskDescription(String label, @DrawableRes int iconRes) {
            this(label, Icon.createWithResource(ActivityThread.currentPackageName(), iconRes),
                    0, 0, 0, 0, false, false, RESIZE_MODE_RESIZEABLE, -1, -1);
        }

        /**
         * 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.
         * @deprecated use TaskDescription constructor with icon resource instead
         */
        @Deprecated
        public TaskDescription(String label, Bitmap icon) {
            this(label, icon, 0, null, 0, 0, 0, 0, false, false, RESIZE_MODE_RESIZEABLE, -1, -1);
        public TaskDescription(String label) {
            this(label, null, 0, 0, 0, 0, false, false, RESIZE_MODE_RESIZEABLE, -1, -1);
        }

        /**
         * Creates the TaskDescription to the specified values.
         *
         * @param label A label and description of the current state of this activity.
         * @param iconRes A drawable resource of an icon that represents the current state of this
         *                activity.
         * Creates an empty TaskDescription.
         */
        public TaskDescription(String label, @DrawableRes int iconRes) {
            this(label, null, iconRes, null, 0, 0, 0, 0, false, false,
                    RESIZE_MODE_RESIZEABLE, -1, -1);
        public TaskDescription() {
            this(null, null, 0, 0, 0, 0, false, false, RESIZE_MODE_RESIZEABLE, -1, -1);
        }

        /**
         * Creates the TaskDescription to the specified values.
         *
         * @param label A label and description of the current state of this activity.
         * @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.
         * @deprecated use TaskDescription constructor with icon resource instead
         */
        public TaskDescription(String label) {
            this(label, null, 0, null, 0, 0, 0, 0, false, false, RESIZE_MODE_RESIZEABLE, -1, -1);
        @Deprecated
        public TaskDescription(String label, Bitmap icon, int colorPrimary) {
            this(label, icon != null ? Icon.createWithBitmap(icon) : null, colorPrimary, 0, 0, 0,
                    false, false, RESIZE_MODE_RESIZEABLE, -1, -1);
            if ((colorPrimary != 0) && (Color.alpha(colorPrimary) != 255)) {
                throw new RuntimeException("A TaskDescription's primary color should be opaque");
            }
        }

        /**
         * Creates an empty TaskDescription.
         * 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.
         * @deprecated use TaskDescription constructor with icon resource instead
         */
        public TaskDescription() {
            this(null, null, 0, null, 0, 0, 0, 0, false, false, RESIZE_MODE_RESIZEABLE, -1, -1);
        @Deprecated
        public TaskDescription(String label, Bitmap icon) {
            this(label, icon != null ? Icon.createWithBitmap(icon) : null, 0, 0, 0, 0, false, false,
                    RESIZE_MODE_RESIZEABLE, -1, -1);
        }

        /** @hide */
        public TaskDescription(String label, Bitmap bitmap, int iconRes, String iconFilename,
                int colorPrimary, int colorBackground, int statusBarColor, int navigationBarColor,
        public TaskDescription(@Nullable String label, @Nullable Icon icon,
                int colorPrimary, int colorBackground,
                int statusBarColor, int navigationBarColor,
                boolean ensureStatusBarContrastWhenTransparent,
                boolean ensureNavigationBarContrastWhenTransparent, int resizeMode, int minWidth,
                int minHeight) {
            mLabel = label;
            mIcon = bitmap;
            mIconRes = iconRes;
            mIconFilename = iconFilename;
            mIcon = icon;
            mColorPrimary = colorPrimary;
            mColorBackground = colorBackground;
            mStatusBarColor = statusBarColor;
@@ -1138,7 +1143,6 @@ public class ActivityManager {
        public void copyFrom(TaskDescription other) {
            mLabel = other.mLabel;
            mIcon = other.mIcon;
            mIconRes = other.mIconRes;
            mIconFilename = other.mIconFilename;
            mColorPrimary = other.mColorPrimary;
            mColorBackground = other.mColorBackground;
@@ -1160,7 +1164,6 @@ public class ActivityManager {
        public void copyFromPreserveHiddenFields(TaskDescription other) {
            mLabel = other.mLabel;
            mIcon = other.mIcon;
            mIconRes = other.mIconRes;
            mIconFilename = other.mIconFilename;
            mColorPrimary = other.mColorPrimary;

@@ -1239,21 +1242,12 @@ public class ActivityManager {
            mNavigationBarColor = navigationBarColor;
        }

        /**
         * Sets the icon for this task description.
         * @hide
         */
        @UnsupportedAppUsage
        public void setIcon(Bitmap icon) {
            mIcon = icon;
        }

        /**
         * Sets the icon resource for this task description.
         * @hide
         */
        public void setIcon(int iconRes) {
            mIconRes = iconRes;
        public void setIcon(Icon icon) {
            mIcon = icon;
        }

        /**
@@ -1263,8 +1257,11 @@ public class ActivityManager {
         */
        public void setIconFilename(String iconFilename) {
            mIconFilename = iconFilename;
            if (iconFilename != null) {
                // Only reset the icon if an actual persisted icon filepath was set
                mIcon = null;
            }
        }

        /**
         * Sets the resize mode for this task description. Resize mode as in
@@ -1301,19 +1298,57 @@ public class ActivityManager {
        }

        /**
         * @return The icon that represents the current state of this task.
         * @return The actual icon that represents the current state of this task if it is in memory
         *         or loads it from disk if available.
         * @hide
         */
        public Bitmap getIcon() {
        public Icon loadIcon() {
            if (mIcon != null) {
                return mIcon;
            }
            Bitmap loadedIcon = loadTaskDescriptionIcon(mIconFilename, UserHandle.myUserId());
            if (loadedIcon != null) {
                return Icon.createWithBitmap(loadedIcon);
            }
            return null;
        }

        /**
         * @return The in-memory or loaded icon that represents the current state of this task.
         * @deprecated This call is no longer supported.
         */
        @Deprecated
        public Bitmap getIcon() {
            Bitmap icon = getInMemoryIcon();
            if (icon != null) {
                return icon;
            }
            return loadTaskDescriptionIcon(mIconFilename, UserHandle.myUserId());
        }

        /** @hide */
        @Nullable
        public Icon getRawIcon() {
            return mIcon;
        }

        /** @hide */
        @TestApi
        @Nullable
        public String getIconResourcePackage() {
            if (mIcon != null && mIcon.getType() == Icon.TYPE_RESOURCE) {
                return mIcon.getResPackage();
            }
            return "";
        }

        /** @hide */
        @TestApi
        public int getIconResource() {
            return mIconRes;
            if (mIcon != null && mIcon.getType() == Icon.TYPE_RESOURCE) {
                return mIcon.getResId();
            }
            return 0;
        }

        /** @hide */
@@ -1325,7 +1360,10 @@ public class ActivityManager {
        /** @hide */
        @UnsupportedAppUsage
        public Bitmap getInMemoryIcon() {
            return mIcon;
            if (mIcon != null && mIcon.getType() == Icon.TYPE_BITMAP) {
                return mIcon.getBitmap();
            }
            return null;
        }

        /** @hide */
@@ -1440,23 +1478,42 @@ public class ActivityManager {
            if (mIconFilename != null) {
                out.attribute(null, ATTR_TASKDESCRIPTIONICON_FILENAME, mIconFilename);
            }
            if (mIconRes != 0) {
                out.attribute(null, ATTR_TASKDESCRIPTIONICON_RESOURCE, Integer.toString(mIconRes));
            if (mIcon != null && mIcon.getType() == Icon.TYPE_RESOURCE) {
                out.attribute(null, ATTR_TASKDESCRIPTIONICON_RESOURCE,
                        Integer.toString(mIcon.getResId()));
                out.attribute(null, ATTR_TASKDESCRIPTIONICON_RESOURCE_PACKAGE,
                        mIcon.getResPackage());
            }
        }

        /** @hide */
        public void restoreFromXml(String attrName, String attrValue) {
            if (ATTR_TASKDESCRIPTIONLABEL.equals(attrName)) {
                setLabel(attrValue);
            } else if (ATTR_TASKDESCRIPTIONCOLOR_PRIMARY.equals(attrName)) {
                setPrimaryColor((int) Long.parseLong(attrValue, 16));
            } else if (ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND.equals(attrName)) {
                setBackgroundColor((int) Long.parseLong(attrValue, 16));
            } else if (ATTR_TASKDESCRIPTIONICON_FILENAME.equals(attrName)) {
                setIconFilename(attrValue);
            } else if (ATTR_TASKDESCRIPTIONICON_RESOURCE.equals(attrName)) {
                setIcon(Integer.parseInt(attrValue, 10));
        public void restoreFromXml(XmlPullParser in) {
            final String label = in.getAttributeValue(null, ATTR_TASKDESCRIPTIONLABEL);
            if (label != null) {
                setLabel(label);
            }
            final String colorPrimary = in.getAttributeValue(null,
                    ATTR_TASKDESCRIPTIONCOLOR_PRIMARY);
            if (colorPrimary != null) {
                setPrimaryColor((int) Long.parseLong(colorPrimary, 16));
            }
            final String colorBackground = in.getAttributeValue(null,
                    ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND);
            if (colorBackground != null) {
                setBackgroundColor((int) Long.parseLong(colorBackground, 16));
            }
            final String iconFilename = in.getAttributeValue(null,
                    ATTR_TASKDESCRIPTIONICON_FILENAME);
            if (iconFilename != null) {
                setIconFilename(iconFilename);
            }
            final String iconResourceId = in.getAttributeValue(null,
                    ATTR_TASKDESCRIPTIONICON_RESOURCE);
            final String iconResourcePackage = in.getAttributeValue(null,
                    ATTR_TASKDESCRIPTIONICON_RESOURCE_PACKAGE);
            if (iconResourceId != null && iconResourcePackage != null) {
                setIcon(Icon.createWithResource(iconResourcePackage,
                        Integer.parseInt(iconResourceId, 10)));
            }
        }

@@ -1473,13 +1530,15 @@ public class ActivityManager {
                dest.writeInt(1);
                dest.writeString(mLabel);
            }
            if (mIcon == null || mIcon.isRecycled()) {
            final Bitmap bitmapIcon = getInMemoryIcon();
            if (mIcon == null || (bitmapIcon != null && bitmapIcon.isRecycled())) {
                // If there is no icon, or if the icon is a bitmap that has been recycled, then
                // don't write anything to disk
                dest.writeInt(0);
            } else {
                dest.writeInt(1);
                mIcon.writeToParcel(dest, 0);
            }
            dest.writeInt(mIconRes);
            dest.writeInt(mColorPrimary);
            dest.writeInt(mColorBackground);
            dest.writeInt(mStatusBarColor);
@@ -1499,8 +1558,9 @@ public class ActivityManager {

        public void readFromParcel(Parcel source) {
            mLabel = source.readInt() > 0 ? source.readString() : null;
            mIcon = source.readInt() > 0 ? Bitmap.CREATOR.createFromParcel(source) : null;
            mIconRes = source.readInt();
            if (source.readInt() > 0) {
                mIcon = Icon.CREATOR.createFromParcel(source);
            }
            mColorPrimary = source.readInt();
            mColorBackground = source.readInt();
            mStatusBarColor = source.readInt();
@@ -1526,7 +1586,7 @@ public class ActivityManager {
        @Override
        public String toString() {
            return "TaskDescription Label: " + mLabel + " Icon: " + mIcon
                    + " IconRes: " + mIconRes + " IconFilename: " + mIconFilename
                    + " IconFilename: " + mIconFilename
                    + " colorPrimary: " + mColorPrimary + " colorBackground: " + mColorBackground
                    + " statusBarColor: " + mStatusBarColor
                    + (mEnsureStatusBarContrastWhenTransparent ? " (contrast when transparent)"
@@ -1643,7 +1703,7 @@ public class ActivityManager {
                pw.print(" taskDescription {");
                pw.print(" colorBackground=#" + Integer.toHexString(td.getBackgroundColor()));
                pw.print(" colorPrimary=#" + Integer.toHexString(td.getPrimaryColor()));
                pw.print(" iconRes=" + (td.getIconResource() != 0));
                pw.print(" iconRes=" + td.getIconResourcePackage() + "/" + td.getIconResource());
                pw.print(" iconBitmap=" + (td.getIconFilename() != null
                        || td.getInMemoryIcon() != null));
                pw.print(" resizeMode=" + ActivityInfo.resizeModeToString(td.getResizeMode()));
+7 −15
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.content.Context;
import android.content.pm.ConfigurationInfo;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.drawable.Icon;
import android.os.Parcel;
import android.os.Parcelable;
import android.test.AndroidTestCase;
@@ -122,9 +123,7 @@ public class ActivityManagerTest extends AndroidTestCase {
    public void testTaskDescriptionCopyFrom() {
        TaskDescription td1 = new TaskDescription(
                "test label",            // label
                null,                    // bitmap
                21,                      // iconRes
                "dummy file",            // iconFilename
                Icon.createWithResource(mContext.getPackageName(), 21), // icon
                0x111111,                // colorPrimary
                0x222222,                // colorBackground
                0x333333,                // statusBarColor
@@ -147,9 +146,7 @@ public class ActivityManagerTest extends AndroidTestCase {
    public void testTaskDescriptionCopyFromPreserveHiddenFields() {
        TaskDescription td1 = new TaskDescription(
                "test label",              // label
                null,                      // bitmap
                21,                        // iconRes
                "dummy file",              // iconFilename
                Icon.createWithResource(mContext.getPackageName(), 21), // icon
                0x111111,                  // colorPrimary
                0x222222,                  // colorBackground
                0x333333,                  // statusBarColor
@@ -163,9 +160,7 @@ public class ActivityManagerTest extends AndroidTestCase {

        TaskDescription td2 = new TaskDescription(
                "test label2",           // label
                null,                    // bitmap
                212,                     // iconRes
                "dummy file2",           // iconFilename
                Icon.createWithResource(mContext.getPackageName(), 212), // icon
                0x1111112,               // colorPrimary
                0x2222222,               // colorBackground
                0x3333332,               // statusBarColor
@@ -194,9 +189,7 @@ public class ActivityManagerTest extends AndroidTestCase {
    public void testTaskDescriptionParceling() throws Exception {
        TaskDescription tdBitmapNull = new TaskDescription(
                "test label",              // label
                null,                      // bitmap
                21,                        // iconRes
                "dummy file",              // iconFilename
                Icon.createWithResource(mContext.getPackageName(), 21), // icon
                0x111111,                  // colorPrimary
                0x222222,                  // colorBackground
                0x333333,                  // statusBarColor
@@ -217,9 +210,7 @@ public class ActivityManagerTest extends AndroidTestCase {
        assertTrue(recycledBitmap.isRecycled());
        TaskDescription tdBitmapRecycled = new TaskDescription(
                "test label",              // label
                recycledBitmap,                      // bitmap
                21,                        // iconRes
                "dummy file",              // iconFilename
                Icon.createWithBitmap(recycledBitmap), // icon
                0x111111,                  // colorPrimary
                0x222222,                  // colorBackground
                0x333333,                  // statusBarColor
@@ -242,6 +233,7 @@ public class ActivityManagerTest extends AndroidTestCase {
            assertEquals(td1.getLabel(), td2.getLabel());
            assertEquals(td1.getInMemoryIcon(), td2.getInMemoryIcon());
            assertEquals(td1.getIconFilename(), td2.getIconFilename());
            assertEquals(td1.getIconResourcePackage(), td2.getIconResourcePackage());
            assertEquals(td1.getIconResource(), td2.getIconResource());
            assertEquals(td1.getPrimaryColor(), td2.getPrimaryColor());
            assertEquals(td1.getEnsureStatusBarContrastWhenTransparent(),
Loading