package com.google.ads.interactivemedia.v3.internal;

import android.content.Context;
import android.os.Build;
import android.text.TextUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.HashSet;
import java.util.regex.Pattern;

/* JADX INFO: loaded from: classes2.dex */
public final class zzol {
    public static boolean zza(int i10) {
        int i11 = i10 - 1;
        return i11 == 2 || i11 == 4 || i11 == 5 || i11 == 6 || i11 == 7;
    }

    /* JADX WARN: Removed duplicated region for block: B:51:0x00c8  */
    /* JADX WARN: Removed duplicated region for block: B:76:0x0121  */
    /* JADX WARN: Removed duplicated region for block: B:87:0x013d  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final int zzb(Context context, zznt zzntVar) {
        int i10;
        FileInputStream fileInputStream;
        byte[] bArr;
        File file = new File(new File(context.getApplicationInfo().dataDir), "lib");
        if (file.exists()) {
            File[] fileArrListFiles = file.listFiles(new zzta(Pattern.compile(".*\\.so$", 2)));
            if (fileArrListFiles != null && fileArrListFiles.length != 0) {
                try {
                    fileInputStream = new FileInputStream(fileArrListFiles[0]);
                    try {
                        bArr = new byte[20];
                    } finally {
                    }
                } catch (IOException e10) {
                    zzd(null, e10.toString(), context, zzntVar);
                }
                if (fileInputStream.read(bArr) == 20) {
                    byte[] bArr2 = {0, 0};
                    if (bArr[5] != 2) {
                        bArr2[0] = bArr[19];
                        bArr2[1] = bArr[18];
                        short s10 = ByteBuffer.wrap(bArr2).getShort();
                        if (s10 == 3) {
                            fileInputStream.close();
                            i10 = 5;
                        } else if (s10 == 40) {
                            fileInputStream.close();
                            i10 = 3;
                        } else if (s10 == 62) {
                            fileInputStream.close();
                            i10 = 7;
                        } else if (s10 == 183) {
                            fileInputStream.close();
                            i10 = 6;
                        } else if (s10 != 243) {
                            zzd(bArr, null, context, zzntVar);
                        } else {
                            fileInputStream.close();
                            i10 = 8;
                        }
                        if (i10 == 1000) {
                            String strZzc = zzc(context, zzntVar);
                            if (TextUtils.isEmpty(strZzc)) {
                                zzd(null, "Empty dev arch", context, zzntVar);
                            } else if (strZzc.equalsIgnoreCase("i686") || strZzc.equalsIgnoreCase("x86")) {
                                i10 = 5;
                            } else if (strZzc.equalsIgnoreCase("x86_64")) {
                                i10 = 7;
                            } else if (strZzc.equalsIgnoreCase("arm64-v8a")) {
                                i10 = 6;
                            } else if (strZzc.equalsIgnoreCase("armeabi-v7a") || strZzc.equalsIgnoreCase("armv71")) {
                                i10 = 3;
                            } else if (strZzc.equalsIgnoreCase("riscv64")) {
                                i10 = 8;
                            } else {
                                zzd(null, strZzc, context, zzntVar);
                            }
                            i10 = 1;
                        }
                        zzntVar.zzb(5018, i10 != 1 ? i10 != 3 ? i10 != 5 ? i10 != 6 ? i10 != 7 ? i10 != 8 ? "null" : "RISCV64" : "X86_64" : "ARM64" : "X86" : "ARM7" : "UNSUPPORTED");
                        return i10;
                    }
                    zzd(bArr, null, context, zzntVar);
                }
                fileInputStream.close();
                i10 = 1;
                if (i10 == 1000) {
                }
                zzntVar.zzb(5018, i10 != 1 ? i10 != 3 ? i10 != 5 ? i10 != 6 ? i10 != 7 ? i10 != 8 ? "null" : "RISCV64" : "X86_64" : "ARM64" : "X86" : "ARM7" : "UNSUPPORTED");
                return i10;
            }
            zzntVar.zzb(5017, "No .so");
        } else {
            zzntVar.zzb(5017, "No lib/");
        }
        i10 = 1000;
        if (i10 == 1000) {
        }
        zzntVar.zzb(5018, i10 != 1 ? i10 != 3 ? i10 != 5 ? i10 != 6 ? i10 != 7 ? i10 != 8 ? "null" : "RISCV64" : "X86_64" : "ARM64" : "X86" : "ARM7" : "UNSUPPORTED");
        return i10;
    }

    private static final String zzc(Context context, zznt zzntVar) {
        HashSet hashSet = new HashSet(Arrays.asList("i686", "armv71"));
        String strZza = zzql.OS_ARCH.zza();
        if (!TextUtils.isEmpty(strZza) && hashSet.contains(strZza)) {
            return strZza;
        }
        try {
            String[] strArr = (String[]) Build.class.getField("SUPPORTED_ABIS").get(null);
            if (strArr != null && strArr.length > 0) {
                return strArr[0];
            }
        } catch (IllegalAccessException e10) {
            zzntVar.zzc(2024, 0L, e10);
        } catch (NoSuchFieldException e11) {
            zzntVar.zzc(2024, 0L, e11);
        }
        String str = Build.CPU_ABI;
        return str != null ? str : Build.CPU_ABI2;
    }

    private static final void zzd(byte[] bArr, String str, Context context, zznt zzntVar) {
        StringBuilder sb = new StringBuilder("os.arch:");
        sb.append(zzql.OS_ARCH.zza());
        sb.append(";");
        try {
            String[] strArr = (String[]) Build.class.getField("SUPPORTED_ABIS").get(null);
            if (strArr != null) {
                sb.append("supported_abis:");
                sb.append(Arrays.toString(strArr));
                sb.append(";");
            }
        } catch (IllegalAccessException | NoSuchFieldException unused) {
        }
        sb.append("CPU_ABI:");
        sb.append(Build.CPU_ABI);
        sb.append(";CPU_ABI2:");
        sb.append(Build.CPU_ABI2);
        sb.append(";");
        if (bArr != null) {
            sb.append("ELF:");
            sb.append(Arrays.toString(bArr));
            sb.append(";");
        }
        if (str != null) {
            sb.append("dbg:");
            sb.append(str);
            sb.append(";");
        }
        zzntVar.zzb(4007, sb.toString());
    }
}
