From e4179e2c4e674b32390a9133bb9fbb3ef5df651b Mon Sep 17 00:00:00 2001 From: Hyunyoung Song Date: Wed, 1 Mar 2017 12:51:26 -0800 Subject: [PATCH] Change MaskableBitmap to AdaptiveBitmap Test: $ make dist -j30 b/35399620 Change-Id: I96d6eaceaf7ce9dec7de21634a5fa2bd40b0deba --- api/current.txt | 2 +- api/system-current.txt | 2 +- api/test-current.txt | 2 +- .../java/android/content/pm/LauncherApps.java | 4 +-- .../java/android/content/pm/ShortcutInfo.java | 15 +++++---- .../android/graphics/drawable/IconTest.java | 10 +++--- .../java/android/graphics/drawable/Icon.java | 32 +++++++++---------- .../android/server/pm/ShortcutPackage.java | 4 +-- .../android/server/pm/ShortcutService.java | 9 +++--- .../server/pm/ShortcutManagerTest1.java | 4 +-- .../server/pm/ShortcutManagerTest2.java | 5 ++- 11 files changed, 44 insertions(+), 45 deletions(-) diff --git a/api/current.txt b/api/current.txt index c7074cca6e0e1..ddff373834245 100644 --- a/api/current.txt +++ b/api/current.txt @@ -13829,12 +13829,12 @@ package android.graphics.drawable { } public final class Icon implements android.os.Parcelable { + method public static android.graphics.drawable.Icon createWithAdaptiveBitmap(android.graphics.Bitmap); method public static android.graphics.drawable.Icon createWithBitmap(android.graphics.Bitmap); method public static android.graphics.drawable.Icon createWithContentUri(java.lang.String); method public static android.graphics.drawable.Icon createWithContentUri(android.net.Uri); method public static android.graphics.drawable.Icon createWithData(byte[], int, int); method public static android.graphics.drawable.Icon createWithFilePath(java.lang.String); - method public static android.graphics.drawable.Icon createWithMaskableBitmap(android.graphics.Bitmap); method public static android.graphics.drawable.Icon createWithResource(android.content.Context, int); method public static android.graphics.drawable.Icon createWithResource(java.lang.String, int); method public int describeContents(); diff --git a/api/system-current.txt b/api/system-current.txt index a46735122ef53..2e2794361cc9b 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -14465,12 +14465,12 @@ package android.graphics.drawable { } public final class Icon implements android.os.Parcelable { + method public static android.graphics.drawable.Icon createWithAdaptiveBitmap(android.graphics.Bitmap); method public static android.graphics.drawable.Icon createWithBitmap(android.graphics.Bitmap); method public static android.graphics.drawable.Icon createWithContentUri(java.lang.String); method public static android.graphics.drawable.Icon createWithContentUri(android.net.Uri); method public static android.graphics.drawable.Icon createWithData(byte[], int, int); method public static android.graphics.drawable.Icon createWithFilePath(java.lang.String); - method public static android.graphics.drawable.Icon createWithMaskableBitmap(android.graphics.Bitmap); method public static android.graphics.drawable.Icon createWithResource(android.content.Context, int); method public static android.graphics.drawable.Icon createWithResource(java.lang.String, int); method public int describeContents(); diff --git a/api/test-current.txt b/api/test-current.txt index 1a12b4c088ebe..5586199cf4c1b 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -13867,12 +13867,12 @@ package android.graphics.drawable { } public final class Icon implements android.os.Parcelable { + method public static android.graphics.drawable.Icon createWithAdaptiveBitmap(android.graphics.Bitmap); method public static android.graphics.drawable.Icon createWithBitmap(android.graphics.Bitmap); method public static android.graphics.drawable.Icon createWithContentUri(java.lang.String); method public static android.graphics.drawable.Icon createWithContentUri(android.net.Uri); method public static android.graphics.drawable.Icon createWithData(byte[], int, int); method public static android.graphics.drawable.Icon createWithFilePath(java.lang.String); - method public static android.graphics.drawable.Icon createWithMaskableBitmap(android.graphics.Bitmap); method public static android.graphics.drawable.Icon createWithResource(android.content.Context, int); method public static android.graphics.drawable.Icon createWithResource(java.lang.String, int); method public int describeContents(); diff --git a/core/java/android/content/pm/LauncherApps.java b/core/java/android/content/pm/LauncherApps.java index 776492a140c3a..c3fd08932f774 100644 --- a/core/java/android/content/pm/LauncherApps.java +++ b/core/java/android/content/pm/LauncherApps.java @@ -829,7 +829,7 @@ public class LauncherApps { final Bitmap bmp = BitmapFactory.decodeFileDescriptor(pfd.getFileDescriptor()); if (bmp != null) { BitmapDrawable dr = new BitmapDrawable(mContext.getResources(), bmp); - if (shortcut.hasMaskableBitmap()) { + if (shortcut.hasAdaptiveBitmap()) { return new AdaptiveIconDrawable(null, dr); } else { return dr; @@ -854,7 +854,7 @@ public class LauncherApps { icon.getResId(), shortcut.getUserHandle(), density); } case Icon.TYPE_BITMAP: - case Icon.TYPE_BITMAP_MASKABLE: { + case Icon.TYPE_ADAPTIVE_BITMAP: { return icon.loadDrawable(mContext); } default: diff --git a/core/java/android/content/pm/ShortcutInfo.java b/core/java/android/content/pm/ShortcutInfo.java index d3d3c66b20c08..5201694997187 100644 --- a/core/java/android/content/pm/ShortcutInfo.java +++ b/core/java/android/content/pm/ShortcutInfo.java @@ -96,7 +96,7 @@ public final class ShortcutInfo implements Parcelable { public static final int FLAG_IMMUTABLE = 1 << 8; /** @hide */ - public static final int FLAG_MASKABLE_BITMAP = 1 << 9; + public static final int FLAG_ADAPTIVE_BITMAP = 1 << 9; /** @hide */ public static final int FLAG_CHOOSER = 1 << 10; @@ -118,7 +118,7 @@ public final class ShortcutInfo implements Parcelable { FLAG_DISABLED, FLAG_STRINGS_RESOLVED, FLAG_IMMUTABLE, - FLAG_MASKABLE_BITMAP, + FLAG_ADAPTIVE_BITMAP, FLAG_CHOOSER, }) @Retention(RetentionPolicy.SOURCE) @@ -784,7 +784,7 @@ public final class ShortcutInfo implements Parcelable { switch (icon.getType()) { case Icon.TYPE_RESOURCE: case Icon.TYPE_BITMAP: - case Icon.TYPE_BITMAP_MASKABLE: + case Icon.TYPE_ADAPTIVE_BITMAP: break; // OK default: throw getInvalidIconException(); @@ -917,7 +917,7 @@ public final class ShortcutInfo implements Parcelable { * and will be ignored. * *

Only icons created with {@link Icon#createWithBitmap(Bitmap)}, - * {@link Icon#createWithMaskableBitmap(Bitmap)} + * {@link Icon#createWithAdaptiveBitmap(Bitmap)} * and {@link Icon#createWithResource} are supported. * Other types, such as URI-based icons, are not supported. * @@ -1615,12 +1615,13 @@ public final class ShortcutInfo implements Parcelable { } /** - * Return whether a shortcut's icon is maskable. + * Return whether a shortcut's icon is adaptive bitmap following design guideline + * defined in {@link AdaptiveIconDrawable}. * * @hide internal/unit tests only */ - public boolean hasMaskableBitmap() { - return hasFlags(FLAG_MASKABLE_BITMAP); + public boolean hasAdaptiveBitmap() { + return hasFlags(FLAG_ADAPTIVE_BITMAP); } /** diff --git a/core/tests/coretests/src/android/graphics/drawable/IconTest.java b/core/tests/coretests/src/android/graphics/drawable/IconTest.java index cf132890d9676..b50955b82b368 100644 --- a/core/tests/coretests/src/android/graphics/drawable/IconTest.java +++ b/core/tests/coretests/src/android/graphics/drawable/IconTest.java @@ -108,13 +108,13 @@ public class IconTest extends AndroidTestCase { } @SmallTest - public void testWithMaskableBitmap() throws Exception { + public void testWithAdaptiveBitmap() throws Exception { final Bitmap bm1 = Bitmap.createBitmap(150, 150, Bitmap.Config.ARGB_8888); final Canvas can1 = new Canvas(bm1); can1.drawColor(0xFFFF0000); - final Icon im1 = Icon.createWithMaskableBitmap(bm1); + final Icon im1 = Icon.createWithAdaptiveBitmap(bm1); final AdaptiveIconDrawable draw1 = (AdaptiveIconDrawable) im1.loadDrawable(mContext); @@ -132,12 +132,12 @@ public class IconTest extends AndroidTestCase { L("writing temp bitmaps to %s...", dir); bm1.compress(Bitmap.CompressFormat.PNG, 100, - new FileOutputStream(new File(dir, "maskable-bitmap1-original.png"))); + new FileOutputStream(new File(dir, "adaptive-bitmap1-original.png"))); test1.compress(Bitmap.CompressFormat.PNG, 100, - new FileOutputStream(new File(dir, "maskable-bitmap1-test.png"))); + new FileOutputStream(new File(dir, "adaptive-bitmap1-test.png"))); if (!equalBitmaps(bm1, test1, draw1.getSafeZone())) { findBitmapDifferences(bm1, test1); - fail("maskable bitmap1 differs, check " + dir); + fail("adaptive bitmap1 differs, check " + dir); } } diff --git a/graphics/java/android/graphics/drawable/Icon.java b/graphics/java/android/graphics/drawable/Icon.java index ff1312a4cd586..8ce7ed02de14a 100644 --- a/graphics/java/android/graphics/drawable/Icon.java +++ b/graphics/java/android/graphics/drawable/Icon.java @@ -68,7 +68,7 @@ public final class Icon implements Parcelable { /** @hide */ public static final int TYPE_URI = 4; /** @hide */ - public static final int TYPE_BITMAP_MASKABLE = 5; + public static final int TYPE_ADAPTIVE_BITMAP = 5; private static final int VERSION_STREAM_SERIALIZER = 1; @@ -103,7 +103,7 @@ public final class Icon implements Parcelable { * {@link #TYPE_RESOURCE}, * {@link #TYPE_DATA}, or * {@link #TYPE_URI}. - * {@link #TYPE_BITMAP_MASKABLE} + * {@link #TYPE_ADAPTIVE_BITMAP} * @hide */ public int getType() { @@ -115,7 +115,7 @@ public final class Icon implements Parcelable { * @hide */ public Bitmap getBitmap() { - if (mType != TYPE_BITMAP && mType != TYPE_BITMAP_MASKABLE) { + if (mType != TYPE_BITMAP && mType != TYPE_ADAPTIVE_BITMAP) { throw new IllegalStateException("called getBitmap() on " + this); } return (Bitmap) mObj1; @@ -221,7 +221,7 @@ public final class Icon implements Parcelable { private static final String typeToString(int x) { switch (x) { case TYPE_BITMAP: return "BITMAP"; - case TYPE_BITMAP_MASKABLE: return "BITMAP_MASKABLE"; + case TYPE_ADAPTIVE_BITMAP: return "BITMAP_MASKABLE"; case TYPE_DATA: return "DATA"; case TYPE_RESOURCE: return "RESOURCE"; case TYPE_URI: return "URI"; @@ -289,7 +289,7 @@ public final class Icon implements Parcelable { switch (mType) { case TYPE_BITMAP: return new BitmapDrawable(context.getResources(), getBitmap()); - case TYPE_BITMAP_MASKABLE: + case TYPE_ADAPTIVE_BITMAP: return new AdaptiveIconDrawable(null, new BitmapDrawable(context.getResources(), getBitmap())); case TYPE_RESOURCE: @@ -395,7 +395,7 @@ public final class Icon implements Parcelable { * @hide */ public void convertToAshmem() { - if ((mType == TYPE_BITMAP || mType == TYPE_BITMAP_MASKABLE) && + if ((mType == TYPE_BITMAP || mType == TYPE_ADAPTIVE_BITMAP) && getBitmap().isMutable() && getBitmap().getAllocationByteCount() >= MIN_ASHMEM_ICON_SIZE) { setBitmap(getBitmap().createAshmemBitmap()); @@ -416,7 +416,7 @@ public final class Icon implements Parcelable { switch (mType) { case TYPE_BITMAP: - case TYPE_BITMAP_MASKABLE: + case TYPE_ADAPTIVE_BITMAP: getBitmap().compress(Bitmap.CompressFormat.PNG, 100, dataStream); break; case TYPE_DATA: @@ -452,8 +452,8 @@ public final class Icon implements Parcelable { switch (type) { case TYPE_BITMAP: return createWithBitmap(BitmapFactory.decodeStream(inputStream)); - case TYPE_BITMAP_MASKABLE: - return createWithMaskableBitmap(BitmapFactory.decodeStream(inputStream)); + case TYPE_ADAPTIVE_BITMAP: + return createWithAdaptiveBitmap(BitmapFactory.decodeStream(inputStream)); case TYPE_DATA: final int length = inputStream.readInt(); final byte[] data = new byte[length]; @@ -488,7 +488,7 @@ public final class Icon implements Parcelable { } switch (mType) { case TYPE_BITMAP: - case TYPE_BITMAP_MASKABLE: + case TYPE_ADAPTIVE_BITMAP: return getBitmap() == otherIcon.getBitmap(); case TYPE_DATA: return getDataLength() == otherIcon.getDataLength() @@ -566,11 +566,11 @@ public final class Icon implements Parcelable { * by {@link AdaptiveIconDrawable}. * @param bits A valid {@link android.graphics.Bitmap} object */ - public static Icon createWithMaskableBitmap(Bitmap bits) { + public static Icon createWithAdaptiveBitmap(Bitmap bits) { if (bits == null) { throw new IllegalArgumentException("Bitmap must not be null."); } - final Icon rep = new Icon(TYPE_BITMAP_MASKABLE); + final Icon rep = new Icon(TYPE_ADAPTIVE_BITMAP); rep.setBitmap(bits); return rep; } @@ -679,7 +679,7 @@ public final class Icon implements Parcelable { final StringBuilder sb = new StringBuilder("Icon(typ=").append(typeToString(mType)); switch (mType) { case TYPE_BITMAP: - case TYPE_BITMAP_MASKABLE: + case TYPE_ADAPTIVE_BITMAP: sb.append(" size=") .append(getBitmap().getWidth()) .append("x") @@ -718,7 +718,7 @@ public final class Icon implements Parcelable { * Parcelable interface */ public int describeContents() { - return (mType == TYPE_BITMAP || mType == TYPE_BITMAP_MASKABLE || mType == TYPE_DATA) + return (mType == TYPE_BITMAP || mType == TYPE_ADAPTIVE_BITMAP || mType == TYPE_DATA) ? Parcelable.CONTENTS_FILE_DESCRIPTOR : 0; } @@ -728,7 +728,7 @@ public final class Icon implements Parcelable { this(in.readInt()); switch (mType) { case TYPE_BITMAP: - case TYPE_BITMAP_MASKABLE: + case TYPE_ADAPTIVE_BITMAP: final Bitmap bits = Bitmap.CREATOR.createFromParcel(in); mObj1 = bits; break; @@ -767,7 +767,7 @@ public final class Icon implements Parcelable { dest.writeInt(mType); switch (mType) { case TYPE_BITMAP: - case TYPE_BITMAP_MASKABLE: + case TYPE_ADAPTIVE_BITMAP: final Bitmap bits = getBitmap(); getBitmap().writeToParcel(dest, flags); break; diff --git a/services/core/java/com/android/server/pm/ShortcutPackage.java b/services/core/java/com/android/server/pm/ShortcutPackage.java index ac98ab96f9cad..7885748fdf139 100644 --- a/services/core/java/com/android/server/pm/ShortcutPackage.java +++ b/services/core/java/com/android/server/pm/ShortcutPackage.java @@ -1635,10 +1635,10 @@ class ShortcutPackage extends ShortcutPackageItem { Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId() + " still has an icon"); } - if (si.hasMaskableBitmap() && !si.hasIconFile()) { + if (si.hasAdaptiveBitmap() && !si.hasIconFile()) { failed = true; Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId() - + " has maskable bitmap but was not saved to a file."); + + " has adaptive bitmap but was not saved to a file."); } if (si.hasIconFile() && si.hasIconResource()) { failed = true; diff --git a/services/core/java/com/android/server/pm/ShortcutService.java b/services/core/java/com/android/server/pm/ShortcutService.java index 74eb340b23e3c..43288cd8fc9dd 100644 --- a/services/core/java/com/android/server/pm/ShortcutService.java +++ b/services/core/java/com/android/server/pm/ShortcutService.java @@ -46,7 +46,6 @@ import android.content.pm.PackageManagerInternal; import android.content.pm.ParceledListSlice; import android.content.pm.ResolveInfo; import android.content.pm.ShortcutInfo; -import android.content.pm.ShortcutManager; import android.content.pm.ShortcutServiceInternal; import android.content.pm.ShortcutServiceInternal.ShortcutChangeListener; import android.content.pm.UserInfo; @@ -1219,7 +1218,7 @@ public class ShortcutService extends IShortcutService.Stub { shortcut.setIconResourceId(0); shortcut.setIconResName(null); shortcut.clearFlags(ShortcutInfo.FLAG_HAS_ICON_FILE | - ShortcutInfo.FLAG_MASKABLE_BITMAP | ShortcutInfo.FLAG_HAS_ICON_RES); + ShortcutInfo.FLAG_ADAPTIVE_BITMAP | ShortcutInfo.FLAG_HAS_ICON_RES); } public void cleanupBitmapsForPackage(@UserIdInt int userId, String packageName) { @@ -1355,7 +1354,7 @@ public class ShortcutService extends IShortcutService.Stub { return; } case Icon.TYPE_BITMAP: - case Icon.TYPE_BITMAP_MASKABLE: { + case Icon.TYPE_ADAPTIVE_BITMAP: { bitmap = icon.getBitmap(); // Don't recycle in this case. break; } @@ -1386,8 +1385,8 @@ public class ShortcutService extends IShortcutService.Stub { shortcut.setBitmapPath(out.getFile().getAbsolutePath()); shortcut.addFlags(ShortcutInfo.FLAG_HAS_ICON_FILE); - if (icon.getType() == Icon.TYPE_BITMAP_MASKABLE) { - shortcut.addFlags(ShortcutInfo.FLAG_MASKABLE_BITMAP); + if (icon.getType() == Icon.TYPE_ADAPTIVE_BITMAP) { + shortcut.addFlags(ShortcutInfo.FLAG_ADAPTIVE_BITMAP); } } finally { IoUtils.closeQuietly(out); diff --git a/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java b/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java index 94ff07fb9d718..4b3c2f8e39486 100644 --- a/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java +++ b/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java @@ -247,7 +247,7 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest { final Icon icon1 = Icon.createWithResource(getTestContext(), R.drawable.icon1); final Icon icon2 = Icon.createWithBitmap(BitmapFactory.decodeResource( getTestContext().getResources(), R.drawable.icon2)); - final Icon icon3 = Icon.createWithMaskableBitmap(BitmapFactory.decodeResource( + final Icon icon3 = Icon.createWithAdaptiveBitmap(BitmapFactory.decodeResource( getTestContext().getResources(), R.drawable.icon2)); final ShortcutInfo si1 = makeShortcut( @@ -567,7 +567,7 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest { final Icon bmp32x32 = Icon.createWithBitmap(BitmapFactory.decodeResource( getTestContext().getResources(), R.drawable.black_32x32)); - final Icon bmp64x64_maskable = Icon.createWithMaskableBitmap(BitmapFactory.decodeResource( + final Icon bmp64x64_maskable = Icon.createWithAdaptiveBitmap(BitmapFactory.decodeResource( getTestContext().getResources(), R.drawable.black_64x64)); final Icon bmp512x512 = Icon.createWithBitmap(BitmapFactory.decodeResource( getTestContext().getResources(), R.drawable.black_512x512)); diff --git a/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest2.java b/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest2.java index c54fa02b68ef1..900da091481b9 100644 --- a/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest2.java +++ b/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest2.java @@ -46,7 +46,6 @@ import android.test.MoreAsserts; import android.test.suitebuilder.annotation.SmallTest; import com.android.frameworks.servicestests.R; -import com.android.server.pm.ShortcutService.ConfigConstants; import com.android.server.pm.ShortcutUser.PackageWithUser; import java.io.File; @@ -993,7 +992,7 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest { setCaller(CALLING_PACKAGE_1, USER_10); - final Icon bmp32x32 = Icon.createWithMaskableBitmap(BitmapFactory.decodeResource( + final Icon bmp32x32 = Icon.createWithAdaptiveBitmap(BitmapFactory.decodeResource( getTestContext().getResources(), R.drawable.black_32x32)); PersistableBundle pb = new PersistableBundle(); @@ -1047,7 +1046,7 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest { assertEquals(1, si.getExtras().getInt("k")); assertEquals(ShortcutInfo.FLAG_DYNAMIC | ShortcutInfo.FLAG_HAS_ICON_FILE - | ShortcutInfo.FLAG_STRINGS_RESOLVED | ShortcutInfo.FLAG_MASKABLE_BITMAP, + | ShortcutInfo.FLAG_STRINGS_RESOLVED | ShortcutInfo.FLAG_ADAPTIVE_BITMAP, si.getFlags()); assertNotNull(si.getBitmapPath()); // Something should be set. assertEquals(0, si.getIconResourceId());