package androidx.window.core;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.res.AssetFileDescriptor;
import android.media.MediaMetadataRetriever;
import android.os.ParcelFileDescriptor;
import c7.o;
import com.google.android.gms.common.api.internal.q;
import com.google.android.gms.internal.ads.q0;
import g5.n;
import j5.h0;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.concurrent.Executors;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import xyz.stream.utils.e0;

/* JADX INFO: loaded from: classes.dex */
public final class h implements u4.d, e5.c, n, h0, n5.h, n5.g, u5.c, x6.b, q, l8.a, l8.b {

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

    public /* synthetic */ h(int i10) {
        this.f4429a = i10;
    }

    public static void k(Closeable closeable) {
        if (closeable != null) {
            try {
                closeable.close();
            } catch (IOException unused) {
            }
        }
    }

    public static e0 m(Context context, String[] strArr, String str, s6.b bVar) {
        String[] strArrP = p(context);
        int length = strArrP.length;
        int i10 = 0;
        int i11 = 0;
        while (true) {
            ZipFile zipFile = null;
            if (i11 >= length) {
                return null;
            }
            String str2 = strArrP[i11];
            int i12 = 0;
            while (true) {
                int i13 = i12 + 1;
                if (i12 >= 5) {
                    break;
                }
                try {
                    zipFile = new ZipFile(new File(str2), 1);
                    break;
                } catch (IOException unused) {
                    i12 = i13;
                }
            }
            if (zipFile != null) {
                int i14 = 0;
                while (true) {
                    int i15 = i14 + 1;
                    if (i14 < 5) {
                        for (String str3 : strArr) {
                            StringBuilder sb = new StringBuilder("lib");
                            char c6 = File.separatorChar;
                            sb.append(c6);
                            sb.append(str3);
                            sb.append(c6);
                            sb.append(str);
                            String string = sb.toString();
                            bVar.getClass();
                            s6.b.d("Looking for %s in APK %s...", string, str2);
                            ZipEntry entry = zipFile.getEntry(string);
                            if (entry != null) {
                                return new e0(zipFile, entry, 9, i10);
                            }
                        }
                        i14 = i15;
                    } else {
                        try {
                            zipFile.close();
                            break;
                        } catch (IOException unused2) {
                        }
                    }
                }
            }
            i11++;
        }
    }

    public static String[] o(Context context, String str) {
        StringBuilder sb = new StringBuilder("lib");
        char c6 = File.separatorChar;
        sb.append(c6);
        sb.append("([^\\");
        sb.append(c6);
        sb.append("]*)");
        sb.append(c6);
        sb.append(str);
        Pattern patternCompile = Pattern.compile(sb.toString());
        HashSet hashSet = new HashSet();
        for (String str2 : p(context)) {
            try {
                Enumeration<? extends ZipEntry> enumerationEntries = new ZipFile(new File(str2), 1).entries();
                while (enumerationEntries.hasMoreElements()) {
                    Matcher matcher = patternCompile.matcher(enumerationEntries.nextElement().getName());
                    if (matcher.matches()) {
                        hashSet.add(matcher.group(1));
                    }
                }
            } catch (IOException unused) {
            }
        }
        return (String[]) hashSet.toArray(new String[hashSet.size()]);
    }

    public static String[] p(Context context) {
        ApplicationInfo applicationInfo = context.getApplicationInfo();
        String[] strArr = applicationInfo.splitSourceDirs;
        if (strArr == null || strArr.length == 0) {
            return new String[]{applicationInfo.sourceDir};
        }
        String[] strArr2 = new String[strArr.length + 1];
        strArr2[0] = applicationInfo.sourceDir;
        System.arraycopy(strArr, 0, strArr2, 1, strArr.length);
        return strArr2;
    }

    public static j q(Object obj, VerificationMode verificationMode) {
        int i10 = i.f4430a;
        a aVar = a.f4413a;
        nb.g.i(obj, "<this>");
        nb.g.i(verificationMode, "verificationMode");
        return new j(obj, verificationMode, aVar);
    }

    @Override // g5.n
    public final Class a() {
        return ParcelFileDescriptor.class;
    }

    @Override // l8.b
    public final q0 b(Context context, String str, l8.a aVar) {
        q0 q0Var = new q0(1);
        int iE = aVar.e(context, str);
        q0Var.f15558a = iE;
        if (iE != 0) {
            q0Var.f15560c = -1;
        } else {
            int iD = aVar.d(context, str, true);
            q0Var.f15559b = iD;
            if (iD != 0) {
                q0Var.f15560c = 1;
            }
        }
        return q0Var;
    }

    @Override // u4.d
    public final int c(Object obj) {
        return ((Integer) obj).intValue();
    }

    @Override // l8.a
    public final int d(Context context, String str, boolean z10) {
        return l8.c.d(context, str, z10);
    }

    @Override // l8.a
    public final int e(Context context, String str) {
        return l8.c.a(context, str);
    }

    @Override // n5.h
    public final void f(n5.i iVar) {
        iVar.d();
    }

    @Override // n5.g
    public final void g() {
    }

    @Override // jd.a
    public final Object get() {
        switch (this.f4429a) {
            case 23:
                return new p4.b(Executors.newSingleThreadExecutor(), 1);
            case 24:
                return Integer.valueOf(o.f4937d);
            default:
                return new e7.c(1);
        }
    }

    @Override // g5.n
    public final Object h(File file) {
        return ParcelFileDescriptor.open(file, 268435456);
    }

    @Override // n5.h
    public final void i(n5.i iVar) {
    }

    @Override // j5.h0
    public final void j(MediaMetadataRetriever mediaMetadataRetriever, Object obj) {
        AssetFileDescriptor assetFileDescriptor = (AssetFileDescriptor) obj;
        mediaMetadataRetriever.setDataSource(assetFileDescriptor.getFileDescriptor(), assetFileDescriptor.getStartOffset(), assetFileDescriptor.getLength());
    }

    @Override // e5.c
    public final void l(Throwable th) {
        switch (this.f4429a) {
            case 9:
                return;
            default:
                throw new RuntimeException("Request threw uncaught throwable", th);
        }
    }

    @Override // g5.n
    public final void n(Object obj) throws IOException {
        ((ParcelFileDescriptor) obj).close();
    }

    /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
    public /* synthetic */ h(int i10, int i11) {
        this(0);
        this.f4429a = i10;
        int i12 = 1;
        if (i10 == 1) {
            this(i12);
            return;
        }
        int i13 = 2;
        if (i10 == 2) {
            this(i13);
            return;
        }
        int i14 = 3;
        if (i10 == 3) {
            this(i14);
            return;
        }
        int i15 = 4;
        if (i10 != 4) {
        } else {
            this(i15);
        }
    }

    /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
    public /* synthetic */ h() {
        this(13);
        this.f4429a = 13;
    }
}
