package A1;

import android.app.Notification;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Bitmap;
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.os.Build;
import android.os.Bundle;
import android.os.HandlerThread;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;
import androidx.core.graphics.drawable.IconCompat;
import java.lang.reflect.InvocationTargetException;
import java.security.GeneralSecurityException;
import java.security.InvalidAlgorithmParameterException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import n4.u0;
import x0.AbstractC1709a;

/* JADX INFO: loaded from: classes.dex */
public final class L implements S3.a {

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public int f95q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public final Object f96r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public Object f97s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public Object f98t;

    public L(String str, SecretKeySpec secretKeySpec) throws GeneralSecurityException {
        U3.l lVar = new U3.l(this);
        this.f97s = lVar;
        if (!I1.a.c(2)) {
            throw new GeneralSecurityException("Can not use HMAC in FIPS-mode, as BoringCrypto module is not available.");
        }
        this.f96r = str;
        this.f98t = secretKeySpec;
        if (secretKeySpec.getEncoded().length < 16) {
            throw new InvalidAlgorithmParameterException("key size too small, need at least 16 bytes");
        }
        switch (str) {
            case "HMACSHA1":
                this.f95q = 20;
                break;
            case "HMACSHA224":
                this.f95q = 28;
                break;
            case "HMACSHA256":
                this.f95q = 32;
                break;
            case "HMACSHA384":
                this.f95q = 48;
                break;
            case "HMACSHA512":
                this.f95q = 64;
                break;
            default:
                throw new NoSuchAlgorithmException("unknown Hmac algorithm: ".concat(str));
        }
        lVar.get();
    }

    public static void e(Notification notification) {
        notification.sound = null;
        notification.vibrate = null;
        notification.defaults &= -4;
    }

    public int a() {
        int i = this.f95q;
        if (i != 2) {
            return i != 3 ? 0 : 512;
        }
        return 2048;
    }

    public Looper b() {
        Looper looper;
        synchronized (this.f96r) {
            try {
                if (((Looper) this.f97s) == null) {
                    AbstractC1709a.j(this.f95q == 0 && ((HandlerThread) this.f98t) == null);
                    HandlerThread handlerThread = new HandlerThread("ExoPlayer:Playback", -16);
                    this.f98t = handlerThread;
                    handlerThread.start();
                    this.f97s = ((HandlerThread) this.f98t).getLooper();
                }
                this.f95q++;
                looper = (Looper) this.f97s;
            } catch (Throwable th) {
                throw th;
            }
        }
        return looper;
    }

    public void c() {
        HandlerThread handlerThread;
        synchronized (this.f96r) {
            try {
                AbstractC1709a.j(this.f95q > 0);
                int i = this.f95q - 1;
                this.f95q = i;
                if (i == 0 && (handlerThread = (HandlerThread) this.f98t) != null) {
                    handlerThread.quit();
                    this.f98t = null;
                    this.f97s = null;
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    @Override // S3.a
    public byte[] d(int i, byte[] bArr) throws InvalidAlgorithmParameterException {
        if (i > this.f95q) {
            throw new InvalidAlgorithmParameterException("tag size too big");
        }
        U3.l lVar = (U3.l) this.f97s;
        ((Mac) lVar.get()).update(bArr);
        return Arrays.copyOf(((Mac) lVar.get()).doFinal(), i);
    }

    public L() {
        this.f96r = new Object();
        this.f97s = null;
        this.f98t = null;
        this.f95q = 0;
    }

    /* JADX WARN: Removed duplicated region for block: B:81:0x0252  */
    /* JADX WARN: Removed duplicated region for block: B:84:0x025b  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public L(B.f fVar) {
        Bundle bundle;
        int i;
        ArrayList arrayList;
        ArrayList arrayList2;
        char c3;
        int i5;
        Icon iconCreateWithBitmap;
        Bundle bundle2;
        String strD;
        ColorStateList colorStateList;
        PorterDuff.Mode mode;
        int i8;
        new ArrayList();
        this.f98t = new Bundle();
        this.f97s = fVar;
        Context context = fVar.f471a;
        int i9 = 26;
        if (Build.VERSION.SDK_INT >= 26) {
            this.f96r = B.h.a(context, fVar.f482m);
        } else {
            this.f96r = new Notification.Builder(fVar.f471a);
        }
        Notification notification = fVar.f484o;
        char c8 = 2;
        int i10 = 0;
        ((Notification.Builder) this.f96r).setWhen(notification.when).setSmallIcon(notification.icon, notification.iconLevel).setContent(notification.contentView).setTicker(notification.tickerText, null).setVibrate(notification.vibrate).setLights(notification.ledARGB, notification.ledOnMS, notification.ledOffMS).setOngoing((notification.flags & 2) != 0).setOnlyAlertOnce((notification.flags & 8) != 0).setAutoCancel((notification.flags & 16) != 0).setDefaults(notification.defaults).setContentTitle(fVar.f475e).setContentText(fVar.f476f).setContentInfo(null).setContentIntent(fVar.f477g).setDeleteIntent(notification.deleteIntent).setFullScreenIntent(null, (notification.flags & 128) != 0).setNumber(0).setProgress(0, 0, false);
        ((Notification.Builder) this.f96r).setLargeIcon((Icon) null);
        ((Notification.Builder) this.f96r).setSubText(null).setUsesChronometer(false).setPriority(fVar.f478h);
        ArrayList arrayList3 = fVar.f472b;
        int size = arrayList3.size();
        int i11 = 0;
        while (i11 < size) {
            int i12 = i11 + 1;
            B.e eVar = (B.e) arrayList3.get(i11);
            int i13 = Build.VERSION.SDK_INT;
            if (eVar.f465b == null && (i8 = eVar.f468e) != 0) {
                eVar.f465b = IconCompat.a(i8);
            }
            IconCompat iconCompat = eVar.f465b;
            if (iconCompat != null) {
                int i14 = iconCompat.f7949a;
                i5 = i10;
                switch (i14) {
                    case -1:
                        arrayList2 = arrayList3;
                        c3 = c8;
                        iconCreateWithBitmap = (Icon) iconCompat.f7950b;
                        break;
                    case u0.f15495q /* 0 */:
                    default:
                        throw new IllegalArgumentException("Unknown type");
                    case 1:
                        arrayList2 = arrayList3;
                        c3 = c8;
                        iconCreateWithBitmap = Icon.createWithBitmap((Bitmap) iconCompat.f7950b);
                        colorStateList = iconCompat.f7955g;
                        if (colorStateList != null) {
                            iconCreateWithBitmap.setTintList(colorStateList);
                        }
                        mode = iconCompat.f7956h;
                        if (mode != IconCompat.f7948k) {
                            iconCreateWithBitmap.setTintMode(mode);
                        }
                        break;
                    case 2:
                        arrayList2 = arrayList3;
                        if (i14 == -1) {
                            Object obj = iconCompat.f7950b;
                            if (i13 >= 28) {
                                strD = B.a.d(obj);
                            } else {
                                try {
                                    strD = (String) obj.getClass().getMethod("getResPackage", null).invoke(obj, null);
                                } catch (IllegalAccessException e8) {
                                    Log.e("IconCompat", "Unable to get icon package", e8);
                                    strD = null;
                                } catch (NoSuchMethodException e9) {
                                    Log.e("IconCompat", "Unable to get icon package", e9);
                                    strD = null;
                                } catch (InvocationTargetException e10) {
                                    Log.e("IconCompat", "Unable to get icon package", e10);
                                    strD = null;
                                }
                            }
                            c3 = 2;
                            break;
                        } else {
                            c3 = 2;
                            if (i14 == 2) {
                                String str = iconCompat.f7957j;
                                if (str != null && !TextUtils.isEmpty(str)) {
                                    strD = iconCompat.f7957j;
                                } else {
                                    strD = ((String) iconCompat.f7950b).split(":", -1)[i5];
                                }
                            } else {
                                throw new IllegalStateException("called getResPackage() on " + iconCompat);
                            }
                        }
                        iconCreateWithBitmap = Icon.createWithResource(strD, iconCompat.f7953e);
                        colorStateList = iconCompat.f7955g;
                        if (colorStateList != null) {
                        }
                        mode = iconCompat.f7956h;
                        if (mode != IconCompat.f7948k) {
                        }
                        break;
                    case 3:
                        arrayList2 = arrayList3;
                        iconCreateWithBitmap = Icon.createWithData((byte[]) iconCompat.f7950b, iconCompat.f7953e, iconCompat.f7954f);
                        c3 = 2;
                        colorStateList = iconCompat.f7955g;
                        if (colorStateList != null) {
                        }
                        mode = iconCompat.f7956h;
                        if (mode != IconCompat.f7948k) {
                        }
                        break;
                    case 4:
                        arrayList2 = arrayList3;
                        iconCreateWithBitmap = Icon.createWithContentUri((String) iconCompat.f7950b);
                        c3 = 2;
                        colorStateList = iconCompat.f7955g;
                        if (colorStateList != null) {
                        }
                        mode = iconCompat.f7956h;
                        if (mode != IconCompat.f7948k) {
                        }
                        break;
                    case 5:
                        if (i13 >= i9) {
                            iconCreateWithBitmap = B.h.b((Bitmap) iconCompat.f7950b);
                            arrayList2 = arrayList3;
                            c3 = c8;
                            colorStateList = iconCompat.f7955g;
                            if (colorStateList != null) {
                            }
                            mode = iconCompat.f7956h;
                            if (mode != IconCompat.f7948k) {
                            }
                        } else {
                            Bitmap bitmap = (Bitmap) iconCompat.f7950b;
                            int iMin = (int) (Math.min(bitmap.getWidth(), bitmap.getHeight()) * 0.6666667f);
                            Bitmap bitmapCreateBitmap = Bitmap.createBitmap(iMin, iMin, Bitmap.Config.ARGB_8888);
                            Canvas canvas = new Canvas(bitmapCreateBitmap);
                            Paint paint = new Paint(3);
                            float f3 = iMin * 0.5f;
                            paint.setColor(-16777216);
                            arrayList2 = arrayList3;
                            Shader.TileMode tileMode = Shader.TileMode.CLAMP;
                            BitmapShader bitmapShader = new BitmapShader(bitmap, tileMode, tileMode);
                            Matrix matrix = new Matrix();
                            matrix.setTranslate((-(bitmap.getWidth() - iMin)) / 2.0f, (-(bitmap.getHeight() - iMin)) / 2.0f);
                            bitmapShader.setLocalMatrix(matrix);
                            paint.setShader(bitmapShader);
                            canvas.drawCircle(f3, f3, f3 * 0.9166667f, paint);
                            canvas.setBitmap(null);
                            iconCreateWithBitmap = Icon.createWithBitmap(bitmapCreateBitmap);
                            c3 = 2;
                            colorStateList = iconCompat.f7955g;
                            if (colorStateList != null) {
                            }
                            mode = iconCompat.f7956h;
                            if (mode != IconCompat.f7948k) {
                            }
                        }
                        break;
                    case Z.g.STRING_SET_FIELD_NUMBER /* 6 */:
                        if (i13 >= 30) {
                            iconCreateWithBitmap = G.a.a(iconCompat.c());
                            arrayList2 = arrayList3;
                            c3 = c8;
                            colorStateList = iconCompat.f7955g;
                            if (colorStateList != null) {
                            }
                            mode = iconCompat.f7956h;
                            if (mode != IconCompat.f7948k) {
                            }
                        } else {
                            throw new IllegalArgumentException("Context is required to resolve the file uri of the icon: " + iconCompat.c());
                        }
                        break;
                }
            } else {
                arrayList2 = arrayList3;
                c3 = c8;
                i5 = i10;
                iconCreateWithBitmap = null;
            }
            Notification.Action.Builder builder = new Notification.Action.Builder(iconCreateWithBitmap, eVar.f469f, eVar.f470g);
            Bundle bundle3 = eVar.f464a;
            if (bundle3 != null) {
                bundle2 = new Bundle(bundle3);
            } else {
                bundle2 = new Bundle();
            }
            boolean z8 = eVar.f466c;
            bundle2.putBoolean("android.support.allowGeneratedReplies", z8);
            if (i13 >= 24) {
                B.g.h(builder, z8);
            }
            bundle2.putInt("android.support.action.semanticAction", i5);
            if (i13 >= 28) {
                B.a.k(builder);
            }
            if (i13 >= 29) {
                B.b.f(builder);
            }
            if (i13 >= 31) {
                B.i.a(builder);
            }
            bundle2.putBoolean("android.support.action.showsUserInterface", eVar.f467d);
            builder.addExtras(bundle2);
            ((Notification.Builder) this.f96r).addAction(builder.build());
            c8 = c3;
            i11 = i12;
            arrayList3 = arrayList2;
            i9 = 26;
            i10 = 0;
        }
        Bundle bundle4 = fVar.f481l;
        if (bundle4 != null) {
            ((Bundle) this.f98t).putAll(bundle4);
        }
        int i15 = Build.VERSION.SDK_INT;
        ((Notification.Builder) this.f96r).setShowWhen(fVar.i);
        ((Notification.Builder) this.f96r).setLocalOnly(fVar.f480k);
        ((Notification.Builder) this.f96r).setGroup(null);
        ((Notification.Builder) this.f96r).setSortKey(null);
        ((Notification.Builder) this.f96r).setGroupSummary(false);
        this.f95q = 0;
        ((Notification.Builder) this.f96r).setCategory(null);
        ((Notification.Builder) this.f96r).setColor(0);
        ((Notification.Builder) this.f96r).setVisibility(0);
        ((Notification.Builder) this.f96r).setPublicVersion(null);
        ((Notification.Builder) this.f96r).setSound(notification.sound, notification.audioAttributes);
        ArrayList arrayList4 = fVar.f486q;
        ArrayList arrayList5 = fVar.f473c;
        if (i15 < 28) {
            if (arrayList5 == null) {
                arrayList = null;
            } else {
                arrayList = new ArrayList(arrayList5.size());
                Iterator it = arrayList5.iterator();
                if (it.hasNext()) {
                    it.next().getClass();
                    throw new ClassCastException();
                }
            }
            if (arrayList != null) {
                if (arrayList4 == null) {
                    arrayList4 = arrayList;
                } else {
                    q.f fVar2 = new q.f(arrayList4.size() + arrayList.size());
                    fVar2.addAll(arrayList);
                    fVar2.addAll(arrayList4);
                    arrayList4 = new ArrayList(fVar2);
                }
            }
        }
        if (arrayList4 != null && !arrayList4.isEmpty()) {
            int size2 = arrayList4.size();
            int i16 = 0;
            while (i16 < size2) {
                Object obj2 = arrayList4.get(i16);
                i16++;
                ((Notification.Builder) this.f96r).addPerson((String) obj2);
            }
        }
        ArrayList arrayList6 = fVar.f474d;
        if (arrayList6.size() > 0) {
            if (fVar.f481l == null) {
                fVar.f481l = new Bundle();
            }
            Bundle bundle5 = fVar.f481l.getBundle("android.car.EXTENSIONS");
            bundle5 = bundle5 == null ? new Bundle() : bundle5;
            Bundle bundle6 = new Bundle(bundle5);
            Bundle bundle7 = new Bundle();
            for (int i17 = 0; i17 < arrayList6.size(); i17++) {
                String string = Integer.toString(i17);
                B.e eVar2 = (B.e) arrayList6.get(i17);
                Bundle bundle8 = new Bundle();
                if (eVar2.f465b == null && (i = eVar2.f468e) != 0) {
                    eVar2.f465b = IconCompat.a(i);
                }
                IconCompat iconCompat2 = eVar2.f465b;
                bundle8.putInt("icon", iconCompat2 != null ? iconCompat2.b() : 0);
                bundle8.putCharSequence("title", eVar2.f469f);
                bundle8.putParcelable("actionIntent", eVar2.f470g);
                Bundle bundle9 = eVar2.f464a;
                if (bundle9 != null) {
                    bundle = new Bundle(bundle9);
                } else {
                    bundle = new Bundle();
                }
                bundle.putBoolean("android.support.allowGeneratedReplies", eVar2.f466c);
                bundle8.putBundle("extras", bundle);
                bundle8.putParcelableArray("remoteInputs", null);
                bundle8.putBoolean("showsUserInterface", eVar2.f467d);
                bundle8.putInt("semanticAction", 0);
                bundle7.putBundle(string, bundle8);
            }
            bundle5.putBundle("invisible_actions", bundle7);
            bundle6.putBundle("invisible_actions", bundle7);
            if (fVar.f481l == null) {
                fVar.f481l = new Bundle();
            }
            fVar.f481l.putBundle("android.car.EXTENSIONS", bundle5);
            ((Bundle) this.f98t).putBundle("android.car.EXTENSIONS", bundle6);
        }
        int i18 = Build.VERSION.SDK_INT;
        if (i18 >= 24) {
            ((Notification.Builder) this.f96r).setExtras(fVar.f481l);
            B.g.i((Notification.Builder) this.f96r);
        }
        if (i18 >= 26) {
            B.h.h((Notification.Builder) this.f96r);
            B.h.n((Notification.Builder) this.f96r);
            B.h.o((Notification.Builder) this.f96r);
            B.h.p((Notification.Builder) this.f96r);
            B.h.j((Notification.Builder) this.f96r, 0);
            if (!TextUtils.isEmpty(fVar.f482m)) {
                ((Notification.Builder) this.f96r).setSound(null).setDefaults(0).setLights(0, 0, 0).setVibrate(null);
            }
        }
        if (i18 >= 28) {
            Iterator it2 = arrayList5.iterator();
            if (it2.hasNext()) {
                it2.next().getClass();
                throw new ClassCastException();
            }
        }
        if (i18 >= 29) {
            B.b.d((Notification.Builder) this.f96r, fVar.f483n);
            B.b.e((Notification.Builder) this.f96r);
        }
        if (fVar.f485p) {
            ((B.f) this.f97s).getClass();
            this.f95q = 1;
            ((Notification.Builder) this.f96r).setVibrate(null);
            ((Notification.Builder) this.f96r).setSound(null);
            int i19 = notification.defaults & (-4);
            notification.defaults = i19;
            ((Notification.Builder) this.f96r).setDefaults(i19);
            if (i18 >= 26) {
                ((B.f) this.f97s).getClass();
                if (TextUtils.isEmpty(null)) {
                    ((Notification.Builder) this.f96r).setGroup("silent");
                }
                B.h.j((Notification.Builder) this.f96r, 1);
            }
        }
    }

    public L(int i, String str, int i5, ArrayList arrayList, byte[] bArr) {
        List listUnmodifiableList;
        this.f96r = str;
        this.f95q = i5;
        if (arrayList == null) {
            listUnmodifiableList = Collections.EMPTY_LIST;
        } else {
            listUnmodifiableList = Collections.unmodifiableList(arrayList);
        }
        this.f97s = listUnmodifiableList;
        this.f98t = bArr;
    }
}
