package androidx.core.graphics.drawable; import android.app.ActivityManager; import android.content.Context; import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.res.ColorStateList; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.BitmapShader; import android.graphics.Canvas; import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.PorterDuff; import android.graphics.Shader; import android.graphics.drawable.AdaptiveIconDrawable; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.Icon; import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.Parcelable; import android.text.TextUtils; import android.util.Log; import androidx.annotation.ColorInt; import androidx.annotation.DrawableRes; import androidx.annotation.IdRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import androidx.annotation.RestrictTo; import androidx.annotation.VisibleForTesting; import androidx.appcompat.widget.ActivityChooserModel; import androidx.core.content.ContextCompat; import androidx.core.content.res.ResourcesCompat; import androidx.core.util.Preconditions; import androidx.core.view.ViewCompat; import androidx.versionedparcelable.CustomVersionedParcelable; import c.d.b.a.a; import com.discord.widgets.chat.input.autocomplete.AutocompleteViewModel; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.reflect.InvocationTargetException; import java.nio.charset.Charset; public class IconCompat extends CustomVersionedParcelable { private static final float ADAPTIVE_ICON_INSET_FACTOR = 0.25f; private static final int AMBIENT_SHADOW_ALPHA = 30; private static final float BLUR_FACTOR = 0.010416667f; public static final PorterDuff.Mode DEFAULT_TINT_MODE = PorterDuff.Mode.SRC_IN; private static final float DEFAULT_VIEW_PORT_SCALE = 0.6666667f; private static final String EXTRA_INT1 = "int1"; private static final String EXTRA_INT2 = "int2"; private static final String EXTRA_OBJ = "obj"; private static final String EXTRA_TINT_LIST = "tint_list"; private static final String EXTRA_TINT_MODE = "tint_mode"; private static final String EXTRA_TYPE = "type"; private static final float ICON_DIAMETER_FACTOR = 0.9166667f; private static final int KEY_SHADOW_ALPHA = 61; private static final float KEY_SHADOW_OFFSET_FACTOR = 0.020833334f; private static final String TAG = "IconCompat"; public static final int TYPE_ADAPTIVE_BITMAP = 5; public static final int TYPE_BITMAP = 1; public static final int TYPE_DATA = 3; public static final int TYPE_RESOURCE = 2; public static final int TYPE_UNKNOWN = -1; public static final int TYPE_URI = 4; public static final int TYPE_URI_ADAPTIVE_BITMAP = 6; @RestrictTo({RestrictTo.Scope.LIBRARY}) public byte[] mData = null; @RestrictTo({RestrictTo.Scope.LIBRARY}) public int mInt1 = 0; @RestrictTo({RestrictTo.Scope.LIBRARY}) public int mInt2 = 0; public Object mObj1; @RestrictTo({RestrictTo.Scope.LIBRARY}) public Parcelable mParcelable = null; @RestrictTo({RestrictTo.Scope.LIBRARY}) public ColorStateList mTintList = null; public PorterDuff.Mode mTintMode = DEFAULT_TINT_MODE; @RestrictTo({RestrictTo.Scope.LIBRARY}) public String mTintModeStr = null; @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public int mType = -1; @Retention(RetentionPolicy.SOURCE) @RestrictTo({RestrictTo.Scope.LIBRARY}) public @interface IconType { } @RestrictTo({RestrictTo.Scope.LIBRARY}) public IconCompat() { } private IconCompat(int i) { this.mType = i; } @Nullable public static IconCompat createFromBundle(@NonNull Bundle bundle) { int i = bundle.getInt("type"); IconCompat iconCompat = new IconCompat(i); iconCompat.mInt1 = bundle.getInt(EXTRA_INT1); iconCompat.mInt2 = bundle.getInt(EXTRA_INT2); if (bundle.containsKey(EXTRA_TINT_LIST)) { iconCompat.mTintList = (ColorStateList) bundle.getParcelable(EXTRA_TINT_LIST); } if (bundle.containsKey(EXTRA_TINT_MODE)) { iconCompat.mTintMode = PorterDuff.Mode.valueOf(bundle.getString(EXTRA_TINT_MODE)); } switch (i) { case -1: case 1: case 5: iconCompat.mObj1 = bundle.getParcelable(EXTRA_OBJ); break; case 0: default: a.j0("Unknown type ", i, TAG); return null; case 2: case 4: case 6: iconCompat.mObj1 = bundle.getString(EXTRA_OBJ); break; case 3: iconCompat.mObj1 = bundle.getByteArray(EXTRA_OBJ); break; } return iconCompat; } @Nullable @RequiresApi(23) public static IconCompat createFromIcon(@NonNull Context context, @NonNull Icon icon) { Preconditions.checkNotNull(icon); int type = getType(icon); if (type == 2) { String resPackage = getResPackage(icon); try { return createWithResource(getResources(context, resPackage), resPackage, getResId(icon)); } catch (Resources.NotFoundException unused) { throw new IllegalArgumentException("Icon resource cannot be found"); } } else if (type == 4) { return createWithContentUri(getUri(icon)); } else { if (type == 6) { return createWithAdaptiveBitmapContentUri(getUri(icon)); } IconCompat iconCompat = new IconCompat(-1); iconCompat.mObj1 = icon; return iconCompat; } } @Nullable @RequiresApi(23) @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public static IconCompat createFromIcon(@NonNull Icon icon) { Preconditions.checkNotNull(icon); int type = getType(icon); if (type == 2) { return createWithResource(null, getResPackage(icon), getResId(icon)); } if (type == 4) { return createWithContentUri(getUri(icon)); } if (type == 6) { return createWithAdaptiveBitmapContentUri(getUri(icon)); } IconCompat iconCompat = new IconCompat(-1); iconCompat.mObj1 = icon; return iconCompat; } @Nullable @RequiresApi(23) @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public static IconCompat createFromIconOrNullIfZeroResId(@NonNull Icon icon) { if (getType(icon) == 2 && getResId(icon) == 0) { return null; } return createFromIcon(icon); } @VisibleForTesting public static Bitmap createLegacyIconFromAdaptiveIcon(Bitmap bitmap, boolean z2) { int min = (int) (((float) Math.min(bitmap.getWidth(), bitmap.getHeight())) * DEFAULT_VIEW_PORT_SCALE); Bitmap createBitmap = Bitmap.createBitmap(min, min, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(createBitmap); Paint paint = new Paint(3); float f = (float) min; float f2 = 0.5f * f; float f3 = ICON_DIAMETER_FACTOR * f2; if (z2) { float f4 = BLUR_FACTOR * f; paint.setColor(0); paint.setShadowLayer(f4, 0.0f, f * KEY_SHADOW_OFFSET_FACTOR, 1023410176); canvas.drawCircle(f2, f2, f3, paint); paint.setShadowLayer(f4, 0.0f, 0.0f, 503316480); canvas.drawCircle(f2, f2, f3, paint); paint.clearShadowLayer(); } paint.setColor(ViewCompat.MEASURED_STATE_MASK); Shader.TileMode tileMode = Shader.TileMode.CLAMP; BitmapShader bitmapShader = new BitmapShader(bitmap, tileMode, tileMode); Matrix matrix = new Matrix(); matrix.setTranslate((float) ((-(bitmap.getWidth() - min)) / 2), (float) ((-(bitmap.getHeight() - min)) / 2)); bitmapShader.setLocalMatrix(matrix); paint.setShader(bitmapShader); canvas.drawCircle(f2, f2, f3, paint); canvas.setBitmap(null); return createBitmap; } public static IconCompat createWithAdaptiveBitmap(Bitmap bitmap) { if (bitmap != null) { IconCompat iconCompat = new IconCompat(5); iconCompat.mObj1 = bitmap; return iconCompat; } throw new IllegalArgumentException("Bitmap must not be null."); } @NonNull public static IconCompat createWithAdaptiveBitmapContentUri(@NonNull Uri uri) { if (uri != null) { return createWithAdaptiveBitmapContentUri(uri.toString()); } throw new IllegalArgumentException("Uri must not be null."); } @NonNull public static IconCompat createWithAdaptiveBitmapContentUri(@NonNull String str) { if (str != null) { IconCompat iconCompat = new IconCompat(6); iconCompat.mObj1 = str; return iconCompat; } throw new IllegalArgumentException("Uri must not be null."); } public static IconCompat createWithBitmap(Bitmap bitmap) { if (bitmap != null) { IconCompat iconCompat = new IconCompat(1); iconCompat.mObj1 = bitmap; return iconCompat; } throw new IllegalArgumentException("Bitmap must not be null."); } public static IconCompat createWithContentUri(Uri uri) { if (uri != null) { return createWithContentUri(uri.toString()); } throw new IllegalArgumentException("Uri must not be null."); } public static IconCompat createWithContentUri(String str) { if (str != null) { IconCompat iconCompat = new IconCompat(4); iconCompat.mObj1 = str; return iconCompat; } throw new IllegalArgumentException("Uri must not be null."); } public static IconCompat createWithData(byte[] bArr, int i, int i2) { if (bArr != null) { IconCompat iconCompat = new IconCompat(3); iconCompat.mObj1 = bArr; iconCompat.mInt1 = i; iconCompat.mInt2 = i2; return iconCompat; } throw new IllegalArgumentException("Data must not be null."); } public static IconCompat createWithResource(Context context, @DrawableRes int i) { if (context != null) { return createWithResource(context.getResources(), context.getPackageName(), i); } throw new IllegalArgumentException("Context must not be null."); } @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public static IconCompat createWithResource(Resources resources, String str, @DrawableRes int i) { if (str == null) { throw new IllegalArgumentException("Package must not be null."); } else if (i != 0) { IconCompat iconCompat = new IconCompat(2); iconCompat.mInt1 = i; if (resources != null) { try { iconCompat.mObj1 = resources.getResourceName(i); } catch (Resources.NotFoundException unused) { throw new IllegalArgumentException("Icon resource cannot be found"); } } else { iconCompat.mObj1 = str; } return iconCompat; } else { throw new IllegalArgumentException("Drawable resource ID must not be 0"); } } @DrawableRes @IdRes @RequiresApi(23) private static int getResId(@NonNull Icon icon) { if (Build.VERSION.SDK_INT >= 28) { return icon.getResId(); } try { return ((Integer) icon.getClass().getMethod("getResId", new Class[0]).invoke(icon, new Object[0])).intValue(); } catch (IllegalAccessException e) { Log.e(TAG, "Unable to get icon resource", e); return 0; } catch (InvocationTargetException e2) { Log.e(TAG, "Unable to get icon resource", e2); return 0; } catch (NoSuchMethodException e3) { Log.e(TAG, "Unable to get icon resource", e3); return 0; } } @Nullable @RequiresApi(23) private static String getResPackage(@NonNull Icon icon) { if (Build.VERSION.SDK_INT >= 28) { return icon.getResPackage(); } try { return (String) icon.getClass().getMethod("getResPackage", new Class[0]).invoke(icon, new Object[0]); } catch (IllegalAccessException e) { Log.e(TAG, "Unable to get icon package", e); return null; } catch (InvocationTargetException e2) { Log.e(TAG, "Unable to get icon package", e2); return null; } catch (NoSuchMethodException e3) { Log.e(TAG, "Unable to get icon package", e3); return null; } } private static Resources getResources(Context context, String str) { if ("android".equals(str)) { return Resources.getSystem(); } PackageManager packageManager = context.getPackageManager(); try { ApplicationInfo applicationInfo = packageManager.getApplicationInfo(str, 8192); if (applicationInfo != null) { return packageManager.getResourcesForApplication(applicationInfo); } return null; } catch (PackageManager.NameNotFoundException e) { Log.e(TAG, String.format("Unable to find pkg=%s for icon", str), e); return null; } } @RequiresApi(23) private static int getType(@NonNull Icon icon) { if (Build.VERSION.SDK_INT >= 28) { return icon.getType(); } try { return ((Integer) icon.getClass().getMethod("getType", new Class[0]).invoke(icon, new Object[0])).intValue(); } catch (IllegalAccessException e) { Log.e(TAG, "Unable to get icon type " + icon, e); return -1; } catch (InvocationTargetException e2) { Log.e(TAG, "Unable to get icon type " + icon, e2); return -1; } catch (NoSuchMethodException e3) { Log.e(TAG, "Unable to get icon type " + icon, e3); return -1; } } @Nullable @RequiresApi(23) private static Uri getUri(@NonNull Icon icon) { if (Build.VERSION.SDK_INT >= 28) { return icon.getUri(); } try { return (Uri) icon.getClass().getMethod("getUri", new Class[0]).invoke(icon, new Object[0]); } catch (IllegalAccessException e) { Log.e(TAG, "Unable to get icon uri", e); return null; } catch (InvocationTargetException e2) { Log.e(TAG, "Unable to get icon uri", e2); return null; } catch (NoSuchMethodException e3) { Log.e(TAG, "Unable to get icon uri", e3); return null; } } private InputStream getUriInputStream(Context context) { Uri uri = getUri(); String scheme = uri.getScheme(); if ("content".equals(scheme) || "file".equals(scheme)) { try { return context.getContentResolver().openInputStream(uri); } catch (Exception e) { Log.w(TAG, "Unable to load image from URI: " + uri, e); return null; } } else { try { return new FileInputStream(new File((String) this.mObj1)); } catch (FileNotFoundException e2) { Log.w(TAG, "Unable to load image from path: " + uri, e2); return null; } } } private Drawable loadDrawableInner(Context context) { switch (this.mType) { case 1: return new BitmapDrawable(context.getResources(), (Bitmap) this.mObj1); case 2: String resPackage = getResPackage(); if (TextUtils.isEmpty(resPackage)) { resPackage = context.getPackageName(); } try { return ResourcesCompat.getDrawable(getResources(context, resPackage), this.mInt1, context.getTheme()); } catch (RuntimeException e) { Log.e(TAG, String.format("Unable to load resource 0x%08x from pkg=%s", Integer.valueOf(this.mInt1), this.mObj1), e); break; } case 3: return new BitmapDrawable(context.getResources(), BitmapFactory.decodeByteArray((byte[]) this.mObj1, this.mInt1, this.mInt2)); case 4: InputStream uriInputStream = getUriInputStream(context); if (uriInputStream != null) { return new BitmapDrawable(context.getResources(), BitmapFactory.decodeStream(uriInputStream)); } break; case 5: return new BitmapDrawable(context.getResources(), createLegacyIconFromAdaptiveIcon((Bitmap) this.mObj1, false)); case 6: InputStream uriInputStream2 = getUriInputStream(context); if (uriInputStream2 != null) { return Build.VERSION.SDK_INT >= 26 ? new AdaptiveIconDrawable(null, new BitmapDrawable(context.getResources(), BitmapFactory.decodeStream(uriInputStream2))) : new BitmapDrawable(context.getResources(), createLegacyIconFromAdaptiveIcon(BitmapFactory.decodeStream(uriInputStream2), false)); } break; } return null; } private static String typeToString(int i) { switch (i) { case 1: return "BITMAP"; case 2: return "RESOURCE"; case 3: return "DATA"; case 4: return "URI"; case 5: return "BITMAP_MASKABLE"; case 6: return "URI_MASKABLE"; default: return "UNKNOWN"; } } @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public void addToShortcutIntent(@NonNull Intent intent, @Nullable Drawable drawable, @NonNull Context context) { Bitmap bitmap; checkResource(context); int i = this.mType; if (i == 1) { bitmap = (Bitmap) this.mObj1; if (drawable != null) { bitmap = bitmap.copy(bitmap.getConfig(), true); } } else if (i == 2) { try { Context createPackageContext = context.createPackageContext(getResPackage(), 0); if (drawable == null) { intent.putExtra("android.intent.extra.shortcut.ICON_RESOURCE", Intent.ShortcutIconResource.fromContext(createPackageContext, this.mInt1)); return; } Drawable drawable2 = ContextCompat.getDrawable(createPackageContext, this.mInt1); if (drawable2.getIntrinsicWidth() > 0) { if (drawable2.getIntrinsicHeight() > 0) { bitmap = Bitmap.createBitmap(drawable2.getIntrinsicWidth(), drawable2.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); drawable2.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight()); drawable2.draw(new Canvas(bitmap)); } } int launcherLargeIconSize = ((ActivityManager) createPackageContext.getSystemService(ActivityChooserModel.ATTRIBUTE_ACTIVITY)).getLauncherLargeIconSize(); bitmap = Bitmap.createBitmap(launcherLargeIconSize, launcherLargeIconSize, Bitmap.Config.ARGB_8888); drawable2.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight()); drawable2.draw(new Canvas(bitmap)); } catch (PackageManager.NameNotFoundException e) { StringBuilder P = a.P("Can't find package "); P.append(this.mObj1); throw new IllegalArgumentException(P.toString(), e); } } else if (i == 5) { bitmap = createLegacyIconFromAdaptiveIcon((Bitmap) this.mObj1, true); } else { throw new IllegalArgumentException("Icon type not supported for intent shortcuts"); } if (drawable != null) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); drawable.setBounds(width / 2, height / 2, width, height); drawable.draw(new Canvas(bitmap)); } intent.putExtra("android.intent.extra.shortcut.ICON", bitmap); } @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public void checkResource(@NonNull Context context) { if (this.mType == 2) { String str = (String) this.mObj1; if (str.contains(":")) { String str2 = str.split(":", -1)[1]; String str3 = str2.split(AutocompleteViewModel.COMMAND_DISCOVER_TOKEN, -1)[0]; String str4 = str2.split(AutocompleteViewModel.COMMAND_DISCOVER_TOKEN, -1)[1]; String str5 = str.split(":", -1)[0]; int identifier = getResources(context, str5).getIdentifier(str4, str3, str5); if (this.mInt1 != identifier) { Log.i(TAG, "Id has changed for " + str5 + AutocompleteViewModel.COMMAND_DISCOVER_TOKEN + str4); this.mInt1 = identifier; } } } } @Nullable @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public Bitmap getBitmap() { int i = this.mType; if (i == -1 && Build.VERSION.SDK_INT >= 23) { Object obj = this.mObj1; if (obj instanceof Bitmap) { return (Bitmap) obj; } return null; } else if (i == 1) { return (Bitmap) this.mObj1; } else { if (i == 5) { return createLegacyIconFromAdaptiveIcon((Bitmap) this.mObj1, true); } throw new IllegalStateException("called getBitmap() on " + this); } } @IdRes public int getResId() { int i = this.mType; if (i == -1 && Build.VERSION.SDK_INT >= 23) { return getResId((Icon) this.mObj1); } if (i == 2) { return this.mInt1; } throw new IllegalStateException("called getResId() on " + this); } @NonNull public String getResPackage() { int i = this.mType; if (i == -1 && Build.VERSION.SDK_INT >= 23) { return getResPackage((Icon) this.mObj1); } if (i == 2) { return ((String) this.mObj1).split(":", -1)[0]; } throw new IllegalStateException("called getResPackage() on " + this); } public int getType() { int i = this.mType; return (i != -1 || Build.VERSION.SDK_INT < 23) ? i : getType((Icon) this.mObj1); } @NonNull public Uri getUri() { int i = this.mType; if (i == -1 && Build.VERSION.SDK_INT >= 23) { return getUri((Icon) this.mObj1); } if (i == 4 || i == 6) { return Uri.parse((String) this.mObj1); } throw new IllegalStateException("called getUri() on " + this); } @Nullable public Drawable loadDrawable(@NonNull Context context) { checkResource(context); if (Build.VERSION.SDK_INT >= 23) { return toIcon(context).loadDrawable(context); } Drawable loadDrawableInner = loadDrawableInner(context); if (!(loadDrawableInner == null || (this.mTintList == null && this.mTintMode == DEFAULT_TINT_MODE))) { loadDrawableInner.mutate(); DrawableCompat.setTintList(loadDrawableInner, this.mTintList); DrawableCompat.setTintMode(loadDrawableInner, this.mTintMode); } return loadDrawableInner; } @Override // androidx.versionedparcelable.CustomVersionedParcelable public void onPostParceling() { this.mTintMode = PorterDuff.Mode.valueOf(this.mTintModeStr); switch (this.mType) { case -1: Parcelable parcelable = this.mParcelable; if (parcelable != null) { this.mObj1 = parcelable; return; } throw new IllegalArgumentException("Invalid icon"); case 0: default: return; case 1: case 5: Parcelable parcelable2 = this.mParcelable; if (parcelable2 != null) { this.mObj1 = parcelable2; return; } byte[] bArr = this.mData; this.mObj1 = bArr; this.mType = 3; this.mInt1 = 0; this.mInt2 = bArr.length; return; case 2: case 4: case 6: this.mObj1 = new String(this.mData, Charset.forName("UTF-16")); return; case 3: this.mObj1 = this.mData; return; } } @Override // androidx.versionedparcelable.CustomVersionedParcelable public void onPreParceling(boolean z2) { this.mTintModeStr = this.mTintMode.name(); switch (this.mType) { case -1: if (!z2) { this.mParcelable = (Parcelable) this.mObj1; return; } throw new IllegalArgumentException("Can't serialize Icon created with IconCompat#createFromIcon"); case 0: default: return; case 1: case 5: if (z2) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ((Bitmap) this.mObj1).compress(Bitmap.CompressFormat.PNG, 90, byteArrayOutputStream); this.mData = byteArrayOutputStream.toByteArray(); return; } this.mParcelable = (Parcelable) this.mObj1; return; case 2: this.mData = ((String) this.mObj1).getBytes(Charset.forName("UTF-16")); return; case 3: this.mData = (byte[]) this.mObj1; return; case 4: case 6: this.mData = this.mObj1.toString().getBytes(Charset.forName("UTF-16")); return; } } public IconCompat setTint(@ColorInt int i) { return setTintList(ColorStateList.valueOf(i)); } public IconCompat setTintList(ColorStateList colorStateList) { this.mTintList = colorStateList; return this; } public IconCompat setTintMode(PorterDuff.Mode mode) { this.mTintMode = mode; return this; } public Bundle toBundle() { Bundle bundle = new Bundle(); switch (this.mType) { case -1: bundle.putParcelable(EXTRA_OBJ, (Parcelable) this.mObj1); break; case 0: default: throw new IllegalArgumentException("Invalid icon"); case 1: case 5: bundle.putParcelable(EXTRA_OBJ, (Bitmap) this.mObj1); break; case 2: case 4: case 6: bundle.putString(EXTRA_OBJ, (String) this.mObj1); break; case 3: bundle.putByteArray(EXTRA_OBJ, (byte[]) this.mObj1); break; } bundle.putInt("type", this.mType); bundle.putInt(EXTRA_INT1, this.mInt1); bundle.putInt(EXTRA_INT2, this.mInt2); ColorStateList colorStateList = this.mTintList; if (colorStateList != null) { bundle.putParcelable(EXTRA_TINT_LIST, colorStateList); } PorterDuff.Mode mode = this.mTintMode; if (mode != DEFAULT_TINT_MODE) { bundle.putString(EXTRA_TINT_MODE, mode.name()); } return bundle; } @NonNull @RequiresApi(23) @Deprecated public Icon toIcon() { return toIcon(null); } @NonNull @RequiresApi(23) public Icon toIcon(@Nullable Context context) { Icon icon; switch (this.mType) { case -1: return (Icon) this.mObj1; case 0: default: throw new IllegalArgumentException("Unknown type"); case 1: icon = Icon.createWithBitmap((Bitmap) this.mObj1); break; case 2: icon = Icon.createWithResource(getResPackage(), this.mInt1); break; case 3: icon = Icon.createWithData((byte[]) this.mObj1, this.mInt1, this.mInt2); break; case 4: icon = Icon.createWithContentUri((String) this.mObj1); break; case 5: if (Build.VERSION.SDK_INT < 26) { icon = Icon.createWithBitmap(createLegacyIconFromAdaptiveIcon((Bitmap) this.mObj1, false)); break; } else { icon = Icon.createWithAdaptiveBitmap((Bitmap) this.mObj1); break; } case 6: if (context != null) { InputStream uriInputStream = getUriInputStream(context); if (uriInputStream != null) { if (Build.VERSION.SDK_INT < 26) { icon = Icon.createWithBitmap(createLegacyIconFromAdaptiveIcon(BitmapFactory.decodeStream(uriInputStream), false)); break; } else { icon = Icon.createWithAdaptiveBitmap(BitmapFactory.decodeStream(uriInputStream)); break; } } else { StringBuilder P = a.P("Cannot load adaptive icon from uri: "); P.append(getUri()); throw new IllegalStateException(P.toString()); } } else { StringBuilder P2 = a.P("Context is required to resolve the file uri of the icon: "); P2.append(getUri()); throw new IllegalArgumentException(P2.toString()); } } ColorStateList colorStateList = this.mTintList; if (colorStateList != null) { icon.setTintList(colorStateList); } PorterDuff.Mode mode = this.mTintMode; if (mode != DEFAULT_TINT_MODE) { icon.setTintMode(mode); } return icon; } @NonNull public String toString() { if (this.mType == -1) { return String.valueOf(this.mObj1); } StringBuilder sb = new StringBuilder("Icon(typ="); sb.append(typeToString(this.mType)); switch (this.mType) { case 1: case 5: sb.append(" size="); sb.append(((Bitmap) this.mObj1).getWidth()); sb.append("x"); sb.append(((Bitmap) this.mObj1).getHeight()); break; case 2: sb.append(" pkg="); sb.append(getResPackage()); sb.append(" id="); sb.append(String.format("0x%08x", Integer.valueOf(getResId()))); break; case 3: sb.append(" len="); sb.append(this.mInt1); if (this.mInt2 != 0) { sb.append(" off="); sb.append(this.mInt2); break; } break; case 4: case 6: sb.append(" uri="); sb.append(this.mObj1); break; } if (this.mTintList != null) { sb.append(" tint="); sb.append(this.mTintList); } if (this.mTintMode != DEFAULT_TINT_MODE) { sb.append(" mode="); sb.append(this.mTintMode); } sb.append(")"); return sb.toString(); } }