Use MaskableIconDrawable only in dogfood builds

Bug: 32063838
Change-Id: Id0d15c4fff54b9429dbe5f9ee7ef26fd9cf8703d
This commit is contained in:
Hyunyoung Song 2017-01-11 12:30:45 -08:00
parent a39a98dac9
commit 9a5203a539
1 changed files with 18 additions and 0 deletions

View File

@ -36,7 +36,11 @@ import android.os.UserHandle;
import com.android.launcher3.LauncherAppState; import com.android.launcher3.LauncherAppState;
import com.android.launcher3.R; import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.config.ProviderConfig;
import java.lang.reflect.Method;
/** /**
* Helper methods for generating various launcher icons * Helper methods for generating various launcher icons
@ -174,6 +178,7 @@ public class LauncherIcons {
* @param scale the scale to apply before drawing {@param icon} on the canvas * @param scale the scale to apply before drawing {@param icon} on the canvas
*/ */
public static Bitmap createIconBitmap(Drawable icon, Context context, float scale) { public static Bitmap createIconBitmap(Drawable icon, Context context, float scale) {
icon = castToMaskableIconDrawable(icon);
synchronized (sCanvas) { synchronized (sCanvas) {
final int iconBitmapSize = getIconBitmapSize(); final int iconBitmapSize = getIconBitmapSize();
@ -229,6 +234,19 @@ public class LauncherIcons {
} }
} }
static Drawable castToMaskableIconDrawable(Drawable drawable) {
if (!(ProviderConfig.IS_DOGFOOD_BUILD && Utilities.isAtLeastO())) {
return drawable;
}
try {
Class clazz = Class.forName("android.graphics.drawable.MaskableIconDrawable");
Method method = clazz.getDeclaredMethod("wrap", Drawable.class);
return (Drawable) method.invoke(null, drawable);
} catch (Exception e) {
return drawable;
}
}
/** /**
* An extension of {@link BitmapDrawable} which returns the bitmap pixel size as intrinsic size. * An extension of {@link BitmapDrawable} which returns the bitmap pixel size as intrinsic size.
* This allows the badging to be done based on the action bitmap size rather than * This allows the badging to be done based on the action bitmap size rather than