package androidx.core.graphics.drawable; import android.content.Context; 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.Icon; import android.net.Uri; import android.os.Build; import android.os.Parcelable; import android.text.TextUtils; import android.util.Log; import androidx.versionedparcelable.CustomVersionedParcelable; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.lang.reflect.InvocationTargetException; import java.nio.charset.Charset; import r.d; /* loaded from: classes.dex */ public class IconCompat extends CustomVersionedParcelable { /* renamed from: k, reason: collision with root package name */ static final PorterDuff.Mode f1484k = PorterDuff.Mode.SRC_IN; /* renamed from: a, reason: collision with root package name */ public int f1485a; /* renamed from: b, reason: collision with root package name */ Object f1486b; /* renamed from: c, reason: collision with root package name */ public byte[] f1487c; /* renamed from: d, reason: collision with root package name */ public Parcelable f1488d; /* renamed from: e, reason: collision with root package name */ public int f1489e; /* renamed from: f, reason: collision with root package name */ public int f1490f; /* renamed from: g, reason: collision with root package name */ public ColorStateList f1491g; /* renamed from: h, reason: collision with root package name */ PorterDuff.Mode f1492h; /* renamed from: i, reason: collision with root package name */ public String f1493i; /* renamed from: j, reason: collision with root package name */ public String f1494j; public IconCompat() { this.f1485a = -1; this.f1487c = null; this.f1488d = null; this.f1489e = 0; this.f1490f = 0; this.f1491g = null; this.f1492h = f1484k; this.f1493i = null; } static Bitmap a(Bitmap bitmap, boolean z10) { int min = (int) (Math.min(bitmap.getWidth(), bitmap.getHeight()) * 0.6666667f); Bitmap createBitmap = Bitmap.createBitmap(min, min, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(createBitmap); Paint paint = new Paint(3); float f10 = min; float f11 = 0.5f * f10; float f12 = 0.9166667f * f11; if (z10) { float f13 = 0.010416667f * f10; paint.setColor(0); paint.setShadowLayer(f13, 0.0f, f10 * 0.020833334f, 1023410176); canvas.drawCircle(f11, f11, f12, paint); paint.setShadowLayer(f13, 0.0f, 0.0f, 503316480); canvas.drawCircle(f11, f11, f12, paint); paint.clearShadowLayer(); } paint.setColor(-16777216); Shader.TileMode tileMode = Shader.TileMode.CLAMP; BitmapShader bitmapShader = new BitmapShader(bitmap, tileMode, tileMode); Matrix matrix = new Matrix(); matrix.setTranslate((-(bitmap.getWidth() - min)) / 2, (-(bitmap.getHeight() - min)) / 2); bitmapShader.setLocalMatrix(matrix); paint.setShader(bitmapShader); canvas.drawCircle(f11, f11, f12, paint); canvas.setBitmap(null); return createBitmap; } public static IconCompat b(Bitmap bitmap) { if (bitmap == null) { throw new IllegalArgumentException("Bitmap must not be null."); } IconCompat iconCompat = new IconCompat(1); iconCompat.f1486b = bitmap; return iconCompat; } public static IconCompat c(Resources resources, String str, int i10) { if (str == null) { throw new IllegalArgumentException("Package must not be null."); } if (i10 == 0) { throw new IllegalArgumentException("Drawable resource ID must not be 0"); } IconCompat iconCompat = new IconCompat(2); iconCompat.f1489e = i10; if (resources != null) { try { iconCompat.f1486b = resources.getResourceName(i10); } catch (Resources.NotFoundException unused) { throw new IllegalArgumentException("Icon resource cannot be found"); } } else { iconCompat.f1486b = str; } iconCompat.f1494j = str; return iconCompat; } private static int f(Icon icon) { int resId; if (Build.VERSION.SDK_INT >= 28) { resId = icon.getResId(); return resId; } try { return ((Integer) icon.getClass().getMethod("getResId", new Class[0]).invoke(icon, new Object[0])).intValue(); } catch (IllegalAccessException e10) { Log.e("IconCompat", "Unable to get icon resource", e10); return 0; } catch (NoSuchMethodException e11) { Log.e("IconCompat", "Unable to get icon resource", e11); return 0; } catch (InvocationTargetException e12) { Log.e("IconCompat", "Unable to get icon resource", e12); return 0; } } private static String h(Icon icon) { String resPackage; if (Build.VERSION.SDK_INT >= 28) { resPackage = icon.getResPackage(); return resPackage; } try { return (String) icon.getClass().getMethod("getResPackage", new Class[0]).invoke(icon, new Object[0]); } catch (IllegalAccessException e10) { Log.e("IconCompat", "Unable to get icon package", e10); return null; } catch (NoSuchMethodException e11) { Log.e("IconCompat", "Unable to get icon package", e11); return null; } catch (InvocationTargetException e12) { Log.e("IconCompat", "Unable to get icon package", e12); return null; } } private static int j(Icon icon) { int type; if (Build.VERSION.SDK_INT >= 28) { type = icon.getType(); return type; } try { return ((Integer) icon.getClass().getMethod("getType", new Class[0]).invoke(icon, new Object[0])).intValue(); } catch (IllegalAccessException e10) { Log.e("IconCompat", "Unable to get icon type " + icon, e10); return -1; } catch (NoSuchMethodException e11) { Log.e("IconCompat", "Unable to get icon type " + icon, e11); return -1; } catch (InvocationTargetException e12) { Log.e("IconCompat", "Unable to get icon type " + icon, e12); return -1; } } private static Uri l(Icon icon) { Uri uri; if (Build.VERSION.SDK_INT >= 28) { uri = icon.getUri(); return uri; } try { return (Uri) icon.getClass().getMethod("getUri", new Class[0]).invoke(icon, new Object[0]); } catch (IllegalAccessException e10) { Log.e("IconCompat", "Unable to get icon uri", e10); return null; } catch (NoSuchMethodException e11) { Log.e("IconCompat", "Unable to get icon uri", e11); return null; } catch (InvocationTargetException e12) { Log.e("IconCompat", "Unable to get icon uri", e12); return null; } } private static String r(int i10) { switch (i10) { 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"; } } public Bitmap d() { int i10 = this.f1485a; if (i10 == -1 && Build.VERSION.SDK_INT >= 23) { Object obj = this.f1486b; if (obj instanceof Bitmap) { return (Bitmap) obj; } return null; } if (i10 == 1) { return (Bitmap) this.f1486b; } if (i10 == 5) { return a((Bitmap) this.f1486b, true); } throw new IllegalStateException("called getBitmap() on " + this); } public int e() { int i10 = this.f1485a; if (i10 == -1 && Build.VERSION.SDK_INT >= 23) { return f(d.a(this.f1486b)); } if (i10 == 2) { return this.f1489e; } throw new IllegalStateException("called getResId() on " + this); } public String g() { int i10 = this.f1485a; if (i10 == -1 && Build.VERSION.SDK_INT >= 23) { return h(d.a(this.f1486b)); } if (i10 == 2) { return TextUtils.isEmpty(this.f1494j) ? ((String) this.f1486b).split(":", -1)[0] : this.f1494j; } throw new IllegalStateException("called getResPackage() on " + this); } public int i() { int i10 = this.f1485a; return (i10 != -1 || Build.VERSION.SDK_INT < 23) ? i10 : j(d.a(this.f1486b)); } public Uri k() { int i10 = this.f1485a; if (i10 == -1 && Build.VERSION.SDK_INT >= 23) { return l(d.a(this.f1486b)); } if (i10 == 4 || i10 == 6) { return Uri.parse((String) this.f1486b); } throw new IllegalStateException("called getUri() on " + this); } public InputStream m(Context context) { Uri k10 = k(); String scheme = k10.getScheme(); if ("content".equals(scheme) || "file".equals(scheme)) { try { return context.getContentResolver().openInputStream(k10); } catch (Exception e10) { Log.w("IconCompat", "Unable to load image from URI: " + k10, e10); return null; } } try { return new FileInputStream(new File((String) this.f1486b)); } catch (FileNotFoundException e11) { Log.w("IconCompat", "Unable to load image from path: " + k10, e11); return null; } } public void n() { this.f1492h = PorterDuff.Mode.valueOf(this.f1493i); switch (this.f1485a) { case -1: Parcelable parcelable = this.f1488d; if (parcelable == null) { throw new IllegalArgumentException("Invalid icon"); } this.f1486b = parcelable; return; case 0: default: return; case 1: case 5: Parcelable parcelable2 = this.f1488d; if (parcelable2 != null) { this.f1486b = parcelable2; return; } byte[] bArr = this.f1487c; this.f1486b = bArr; this.f1485a = 3; this.f1489e = 0; this.f1490f = bArr.length; return; case 2: case 4: case 6: String str = new String(this.f1487c, Charset.forName("UTF-16")); this.f1486b = str; if (this.f1485a == 2 && this.f1494j == null) { this.f1494j = str.split(":", -1)[0]; return; } return; case 3: this.f1486b = this.f1487c; return; } } public void o(boolean z10) { this.f1493i = this.f1492h.name(); switch (this.f1485a) { case -1: if (z10) { throw new IllegalArgumentException("Can't serialize Icon created with IconCompat#createFromIcon"); } this.f1488d = (Parcelable) this.f1486b; return; case 0: default: return; case 1: case 5: if (!z10) { this.f1488d = (Parcelable) this.f1486b; return; } Bitmap bitmap = (Bitmap) this.f1486b; ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 90, byteArrayOutputStream); this.f1487c = byteArrayOutputStream.toByteArray(); return; case 2: this.f1487c = ((String) this.f1486b).getBytes(Charset.forName("UTF-16")); return; case 3: this.f1487c = (byte[]) this.f1486b; return; case 4: case 6: this.f1487c = this.f1486b.toString().getBytes(Charset.forName("UTF-16")); return; } } public Icon p() { return q(null); } public Icon q(Context context) { Icon createWithBitmap; switch (this.f1485a) { case -1: return d.a(this.f1486b); case 0: default: throw new IllegalArgumentException("Unknown type"); case 1: createWithBitmap = Icon.createWithBitmap((Bitmap) this.f1486b); break; case 2: createWithBitmap = Icon.createWithResource(g(), this.f1489e); break; case 3: createWithBitmap = Icon.createWithData((byte[]) this.f1486b, this.f1489e, this.f1490f); break; case 4: createWithBitmap = Icon.createWithContentUri((String) this.f1486b); break; case 5: if (Build.VERSION.SDK_INT < 26) { createWithBitmap = Icon.createWithBitmap(a((Bitmap) this.f1486b, false)); break; } else { createWithBitmap = Icon.createWithAdaptiveBitmap((Bitmap) this.f1486b); break; } case 6: int i10 = Build.VERSION.SDK_INT; if (i10 >= 30) { createWithBitmap = Icon.createWithAdaptiveBitmapContentUri(k()); break; } else { if (context == null) { throw new IllegalArgumentException("Context is required to resolve the file uri of the icon: " + k()); } InputStream m10 = m(context); if (m10 == null) { throw new IllegalStateException("Cannot load adaptive icon from uri: " + k()); } if (i10 < 26) { createWithBitmap = Icon.createWithBitmap(a(BitmapFactory.decodeStream(m10), false)); break; } else { createWithBitmap = Icon.createWithAdaptiveBitmap(BitmapFactory.decodeStream(m10)); break; } } } ColorStateList colorStateList = this.f1491g; if (colorStateList != null) { createWithBitmap.setTintList(colorStateList); } PorterDuff.Mode mode = this.f1492h; if (mode != f1484k) { createWithBitmap.setTintMode(mode); } return createWithBitmap; } public String toString() { if (this.f1485a == -1) { return String.valueOf(this.f1486b); } StringBuilder sb = new StringBuilder("Icon(typ="); sb.append(r(this.f1485a)); switch (this.f1485a) { case 1: case 5: sb.append(" size="); sb.append(((Bitmap) this.f1486b).getWidth()); sb.append("x"); sb.append(((Bitmap) this.f1486b).getHeight()); break; case 2: sb.append(" pkg="); sb.append(this.f1494j); sb.append(" id="); sb.append(String.format("0x%08x", Integer.valueOf(e()))); break; case 3: sb.append(" len="); sb.append(this.f1489e); if (this.f1490f != 0) { sb.append(" off="); sb.append(this.f1490f); break; } break; case 4: case 6: sb.append(" uri="); sb.append(this.f1486b); break; } if (this.f1491g != null) { sb.append(" tint="); sb.append(this.f1491g); } if (this.f1492h != f1484k) { sb.append(" mode="); sb.append(this.f1492h); } sb.append(")"); return sb.toString(); } private IconCompat(int i10) { this.f1487c = null; this.f1488d = null; this.f1489e = 0; this.f1490f = 0; this.f1491g = null; this.f1492h = f1484k; this.f1493i = null; this.f1485a = i10; } }