package defpackage;

import android.content.Context;
import android.util.Pair;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.concurrent.Callable;
import java.util.zip.GZIPInputStream;
import java.util.zip.ZipInputStream;

/* JADX INFO: loaded from: classes.dex */
public final /* synthetic */ class bk5 implements Callable {
    public final /* synthetic */ int a;
    public final /* synthetic */ Context b;
    public final /* synthetic */ String c;
    public final /* synthetic */ String d;

    public /* synthetic */ bk5(Context context, String str, int i, String str2) {
        this.a = i;
        this.b = context;
        this.c = str;
        this.d = str2;
    }

    /* JADX WARN: Code restructure failed: missing block: B:26:0x0053, code lost:
    
        r0 = move-exception;
     */
    /* JADX WARN: Code restructure failed: missing block: B:31:0x0059, code lost:
    
        throw r0;
     */
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:48:0x0099  */
    /* JADX WARN: Type inference failed for: r1v1 */
    /* JADX WARN: Type inference failed for: r1v11, types: [bl5] */
    /* JADX WARN: Type inference failed for: r1v16 */
    /* JADX WARN: Type inference failed for: r1v17 */
    /* JADX WARN: Type inference failed for: r1v18 */
    /* JADX WARN: Type inference failed for: r1v2 */
    /* JADX WARN: Type inference failed for: r1v5, types: [bl5] */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:84:0x012c -> B:107:0x012f). Please report as a decompilation issue!!! */
    @Override // java.util.concurrent.Callable
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object call() throws Throwable {
        zj5 zj5Var;
        Throwable th;
        q02 q02VarA;
        bl5 bl5Var;
        zj5 zj5Var2;
        Pair pair;
        bl5 bl5VarG;
        File fileB;
        pk6 pk6Var;
        switch (this.a) {
            case 0:
                Context context = this.b;
                String str = this.c;
                String str2 = this.d;
                HashMap map = ek5.a;
                il6 il6Var = n55.a;
                if (il6Var == null) {
                    synchronized (il6.class) {
                        try {
                            il6Var = n55.a;
                            if (il6Var == null) {
                                Context applicationContext = context.getApplicationContext();
                                pk6 pk6Var2 = n55.b;
                                if (pk6Var2 == null) {
                                    synchronized (pk6.class) {
                                        pk6Var = n55.b;
                                        if (pk6Var == null) {
                                            pk6Var = new pk6(new m55(applicationContext));
                                            n55.b = pk6Var;
                                        }
                                        break;
                                    }
                                    pk6Var2 = pk6Var;
                                }
                                il6Var = new il6(pk6Var2, new r02());
                                n55.a = il6Var;
                            }
                        } finally {
                        }
                    }
                }
                bl5 bl5Var2 = il6Var;
                q02 q02Var = null;
                if (str2 != null) {
                    try {
                        fileB = bl5Var2.a.b(str);
                    } catch (FileNotFoundException unused) {
                    }
                    if (fileB == null) {
                        pair = null;
                    } else {
                        FileInputStream fileInputStream = new FileInputStream(fileB);
                        cy2 cy2Var = fileB.getAbsolutePath().endsWith(".zip") ? cy2.ZIP : fileB.getAbsolutePath().endsWith(".gz") ? cy2.GZIP : cy2.JSON;
                        fileB.getAbsolutePath();
                        gh5.a();
                        pair = new Pair(cy2Var, fileInputStream);
                    }
                    if (pair == null) {
                        zj5Var = null;
                    } else {
                        cy2 cy2Var2 = (cy2) pair.first;
                        InputStream inputStream = (InputStream) pair.second;
                        int iOrdinal = cy2Var2.ordinal();
                        if (iOrdinal == 1) {
                            bl5VarG = ek5.g(context, new ZipInputStream(inputStream), str2);
                        } else if (iOrdinal != 2) {
                            bl5VarG = ek5.d(inputStream, str2);
                        } else {
                            try {
                                bl5VarG = ek5.d(new GZIPInputStream(inputStream), str2);
                            } catch (IOException e) {
                                bl5VarG = new bl5(e);
                            }
                        }
                        zj5Var = bl5VarG.a;
                        if (zj5Var == null) {
                        }
                    }
                    break;
                }
                if (zj5Var == null) {
                    gh5.a();
                    gh5.a();
                    try {
                        try {
                            try {
                                q02VarA = bl5Var2.b.a(str);
                            } catch (Exception e2) {
                                e = e2;
                            }
                        } catch (Throwable th2) {
                            th = th2;
                        }
                    } catch (IOException e3) {
                        gh5.c("LottieFetchResult close failed ", e3);
                        bl5Var2 = bl5Var2;
                    }
                    try {
                        if (q02VarA.b()) {
                            bl5 bl5VarA = bl5Var2.a(context, str, q02VarA.a.getInputStream(), q02VarA.a.getContentType(), str2);
                            zj5 zj5Var3 = bl5VarA.a;
                            gh5.a();
                            bl5Var = bl5VarA;
                        } else {
                            bl5Var = new bl5(new IllegalArgumentException(q02VarA.a()));
                        }
                        q02VarA.close();
                        bl5Var2 = bl5Var;
                    } catch (Exception e4) {
                        e = e4;
                        q02Var = q02VarA;
                        bl5Var2 = new bl5(e);
                        if (q02Var != null) {
                            q02Var.close();
                            bl5Var2 = bl5Var2;
                        }
                        if (str2 != null) {
                            ak5.b.a.put(str2, zj5Var2);
                        }
                        return bl5Var2;
                    } catch (Throwable th3) {
                        th = th3;
                        q02Var = q02VarA;
                        if (q02Var == null) {
                            throw th;
                        }
                        try {
                            q02Var.close();
                            throw th;
                        } catch (IOException e5) {
                            gh5.c("LottieFetchResult close failed ", e5);
                            throw th;
                        }
                    }
                    break;
                } else {
                    bl5Var2 = new bl5(zj5Var);
                }
                if (str2 != null && (zj5Var2 = bl5Var2.a) != null) {
                    ak5.b.a.put(str2, zj5Var2);
                }
                return bl5Var2;
            default:
                return ek5.b(this.b, this.c, this.d);
        }
    }
}
