package l2;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.util.Base64OutputStream;
import androidx.media3.common.Format;
import androidx.media3.common.MimeTypes;
import androidx.media3.common.util.Log;
import androidx.media3.common.util.ParsableByteArray;
import androidx.media3.common.util.Util;
import com.google.android.gms.internal.ads.ck;
import com.google.android.gms.internal.ads.qc;
import com.google.android.gms.internal.ads.xj;
import com.google.android.gms.internal.ads.yj;
import com.google.android.gms.internal.ads.zj;
import com.google.android.gms.internal.ads.zv1;
import java.io.IOException;
import java.lang.reflect.Array;
import java.text.Normalizer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;

/* JADX INFO: loaded from: classes.dex */
public final class h implements e {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final /* synthetic */ int f29995a;

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

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

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

    public h(int i10, int i11, int i12) {
        this.f29995a = 4;
        this.f29996b = i10;
        i11 = (i11 > 64 || i11 < 0) ? 64 : i11;
        if (i12 <= 0) {
            this.f29997c = 1;
        } else {
            this.f29997c = i12;
        }
        this.f29998d = new ck(i11);
    }

    @Override // l2.e
    public final int a() {
        return this.f29996b;
    }

    @Override // l2.e
    public final int b() {
        return this.f29997c;
    }

    @Override // l2.e
    public final int c() {
        int i10 = this.f29996b;
        return i10 == -1 ? ((ParsableByteArray) this.f29998d).readUnsignedIntToInt() : i10;
    }

    public final byte d(int i10, int i11) {
        return ((byte[][]) this.f29998d)[i11][i10];
    }

    public final void e(int i10, int i11, int i12) {
        ((byte[][]) this.f29998d)[i11][i10] = (byte) i12;
    }

    public final synchronized int f() {
        PackageInfo packageInfoB;
        if (this.f29996b == 0) {
            try {
                packageInfoB = j8.e.a((Context) this.f29998d).b(0, "com.google.android.gms");
            } catch (PackageManager.NameNotFoundException e10) {
                "Failed to find package ".concat(e10.toString());
                packageInfoB = null;
            }
            if (packageInfoB != null) {
                this.f29996b = packageInfoB.versionCode;
            }
        }
        return this.f29996b;
    }

    /* JADX WARN: Removed duplicated region for block: B:29:0x0092  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final String g(ArrayList arrayList, ArrayList arrayList2) {
        Collections.sort(arrayList2, new qc(this));
        HashSet hashSet = new HashSet();
        loop0: for (int i10 = 0; i10 < arrayList2.size(); i10++) {
            String[] strArrSplit = Normalizer.normalize((CharSequence) arrayList.get(((xj) arrayList2.get(i10)).f18449e), Normalizer.Form.NFKC).toLowerCase(Locale.US).split("\n");
            if (strArrSplit.length != 0) {
                for (String str : strArrSplit) {
                    if (str.contains("'")) {
                        StringBuilder sb = new StringBuilder(str);
                        int i11 = 1;
                        boolean z10 = false;
                        while (true) {
                            int i12 = i11 + 2;
                            if (i12 > sb.length()) {
                                break;
                            }
                            if (sb.charAt(i11) == '\'') {
                                if (sb.charAt(i11 - 1) != ' ') {
                                    int i13 = i11 + 1;
                                    if ((sb.charAt(i13) == 's' || sb.charAt(i13) == 'S') && (i12 == sb.length() || sb.charAt(i12) == ' ')) {
                                        sb.insert(i11, ' ');
                                        i11 = i12;
                                    } else {
                                        sb.setCharAt(i11, ' ');
                                    }
                                    z10 = true;
                                }
                            }
                            i11++;
                        }
                        String string = z10 ? sb.toString() : null;
                        if (string != null) {
                            str = string;
                        }
                    }
                    String[] strArrZzb = zj.zzb(str, true);
                    int length = strArrZzb.length;
                    int i14 = this.f29997c;
                    if (length >= i14) {
                        for (int i15 = 0; i15 < strArrZzb.length; i15++) {
                            String strConcat = "";
                            for (int i16 = 0; i16 < i14; i16++) {
                                int i17 = i15 + i16;
                                if (i17 >= strArrZzb.length) {
                                    break;
                                }
                                if (i16 > 0) {
                                    strConcat = strConcat.concat(" ");
                                }
                                strConcat = strConcat.concat(String.valueOf(strArrZzb[i17]));
                            }
                            hashSet.add(strConcat);
                            if (hashSet.size() >= this.f29996b) {
                                break loop0;
                            }
                        }
                        if (hashSet.size() >= this.f29996b) {
                            break loop0;
                        }
                    }
                }
            }
        }
        zv1 zv1Var = new zv1(9);
        Iterator it = hashSet.iterator();
        while (it.hasNext()) {
            try {
                ((Base64OutputStream) zv1Var.f19405c).write(((yj) this.f29998d).a((String) it.next()));
            } catch (IOException unused) {
            }
        }
        return zv1Var.toString();
    }

    /* JADX WARN: Removed duplicated region for block: B:21:0x0049 A[Catch: all -> 0x0047, TryCatch #0 {all -> 0x0047, blocks: (B:3:0x0001, B:7:0x0007, B:12:0x0027, B:14:0x002e, B:16:0x0040, B:26:0x0063, B:21:0x0049, B:23:0x005c, B:29:0x0067, B:33:0x006f), top: B:38:0x0001 }] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final synchronized int h() {
        try {
            int i10 = this.f29997c;
            if (i10 != 0) {
                return i10;
            }
            Context context = (Context) this.f29998d;
            PackageManager packageManager = context.getPackageManager();
            if (j8.e.a(context).f28722a.getPackageManager().checkPermission("com.google.android.c2dm.permission.SEND", "com.google.android.gms") == -1) {
                return 0;
            }
            int i11 = 1;
            if (!com.bumptech.glide.g.l()) {
                Intent intent = new Intent("com.google.android.c2dm.intent.REGISTER");
                intent.setPackage("com.google.android.gms");
                List<ResolveInfo> listQueryIntentServices = packageManager.queryIntentServices(intent, 0);
                if (listQueryIntentServices == null || listQueryIntentServices.isEmpty()) {
                    Intent intent2 = new Intent("com.google.iid.TOKEN_REQUEST");
                    intent2.setPackage("com.google.android.gms");
                    List<ResolveInfo> listQueryBroadcastReceivers = packageManager.queryBroadcastReceivers(intent2, 0);
                    if (listQueryBroadcastReceivers == null || listQueryBroadcastReceivers.isEmpty()) {
                        if (true == com.bumptech.glide.g.l()) {
                            i11 = 2;
                        }
                        this.f29997c = i11;
                        return i11;
                    }
                    i11 = 2;
                }
            }
            this.f29997c = i11;
            return i11;
        } catch (Throwable th) {
            throw th;
        }
    }

    public final String toString() {
        switch (this.f29995a) {
            case 6:
                StringBuilder sb = new StringBuilder((this.f29996b * 2 * this.f29997c) + 2);
                for (int i10 = 0; i10 < this.f29997c; i10++) {
                    byte[] bArr = ((byte[][]) this.f29998d)[i10];
                    for (int i11 = 0; i11 < this.f29996b; i11++) {
                        byte b10 = bArr[i11];
                        if (b10 == 0) {
                            sb.append(" 0");
                        } else if (b10 != 1) {
                            sb.append("  ");
                        } else {
                            sb.append(" 1");
                        }
                    }
                    sb.append('\n');
                }
                return sb.toString();
            default:
                return super.toString();
        }
    }

    public h(Context context) {
        this.f29995a = 2;
        this.f29997c = 0;
        this.f29998d = context;
    }

    public /* synthetic */ h(String str, int i10, int i11) {
        this.f29995a = 3;
        this.f29996b = i10;
        this.f29997c = i11;
        this.f29998d = str;
    }

    public h(int i10, int i11) {
        this.f29995a = 6;
        this.f29998d = (byte[][]) Array.newInstance((Class<?>) Byte.TYPE, i11, i10);
        this.f29996b = i10;
        this.f29997c = i11;
    }

    public h() {
        this.f29995a = 1;
        this.f29996b = 0;
        this.f29998d = new ArrayList();
        this.f29997c = 1;
    }

    public h(boolean[] zArr, int i10, int i11) {
        this.f29995a = 5;
        this.f29998d = zArr;
        this.f29996b = i10;
        this.f29997c = i11;
    }

    public h(q1.e eVar, Format format) {
        this.f29995a = 0;
        ParsableByteArray parsableByteArray = eVar.f32095c;
        this.f29998d = parsableByteArray;
        parsableByteArray.setPosition(12);
        int unsignedIntToInt = parsableByteArray.readUnsignedIntToInt();
        if (MimeTypes.AUDIO_RAW.equals(format.sampleMimeType)) {
            int pcmFrameSize = Util.getPcmFrameSize(format.pcmEncoding, format.channelCount);
            if (unsignedIntToInt == 0 || unsignedIntToInt % pcmFrameSize != 0) {
                Log.w("BoxParsers", "Audio sample size mismatch. stsd sample size: " + pcmFrameSize + ", stsz sample size: " + unsignedIntToInt);
                unsignedIntToInt = pcmFrameSize;
            }
        }
        this.f29996b = unsignedIntToInt == 0 ? -1 : unsignedIntToInt;
        this.f29997c = parsableByteArray.readUnsignedIntToInt();
    }
}
