package defpackage;

import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
import com.bumptech.glide.ComponentCallbacks2C0017;
import j$.util.Objects;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;

/* JADX INFO: renamed from: ᵳᵔ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C4586 implements InterfaceC5071 {

    /* JADX INFO: renamed from: ˌᴵ, reason: contains not printable characters */
    public final /* synthetic */ int f17460;

    /* JADX INFO: renamed from: ᵔᵖᵹᵫ, reason: contains not printable characters */
    public final Object f17461;

    /* JADX INFO: renamed from: ᵜᵪʾ, reason: contains not printable characters */
    public final Comparable f17462;

    /* JADX INFO: renamed from: ᵨᵼⁱ, reason: contains not printable characters */
    public Object f17463;

    public /* synthetic */ C4586(Comparable comparable, Object obj, int i) {
        this.f17460 = i;
        this.f17462 = comparable;
        this.f17461 = obj;
    }

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    private final void m9662() {
    }

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public static C4586 m9663(Context context, Uri uri, InterfaceC1015 interfaceC1015) {
        return new C4586(uri, new ᵥᵵᵶᵩ(ComponentCallbacks2C0017.m801(context).f1000.m5115().m2857(), interfaceC1015, ComponentCallbacks2C0017.m801(context).f1001, context.getContentResolver(), 2), 1);
    }

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    private final void m9664() {
    }

    @Override // defpackage.InterfaceC5071
    public final void cancel() {
        int i = this.f17460;
    }

    @Override // defpackage.InterfaceC5071
    /* JADX INFO: renamed from: ʽˈˋ */
    public final Class mo1311() {
        switch (this.f17460) {
            case 0:
                return ((InterfaceC2958) this.f17461).mo6212();
            default:
                return InputStream.class;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:24:0x004a  */
    /* JADX WARN: Removed duplicated region for block: B:25:0x004c  */
    /* JADX WARN: Removed duplicated region for block: B:52:0x00bd  */
    /* JADX WARN: Removed duplicated region for block: B:54:0x00c0  */
    /* JADX WARN: Removed duplicated region for block: B:57:0x00c9  */
    /* JADX WARN: Removed duplicated region for block: B:75:0x0090 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:79:? A[RETURN, SYNTHETIC] */
    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public InputStream m9665() throws Throwable {
        Cursor cursorMo3360;
        String string;
        InputStream inputStreamOpenInputStream;
        int i;
        ᵥᵵᵶᵩ r1 = (ᵥᵵᵶᵩ) this.f17461;
        ContentResolver contentResolver = (ContentResolver) r1.ᵯᵷʽ;
        Uri uri = (Uri) this.f17462;
        Cursor cursor = null;
        inputStreamOpenInputStream = null;
        inputStreamOpenInputStream = null;
        InputStream inputStreamOpenInputStream2 = null;
        try {
            cursorMo3360 = ((InterfaceC1015) r1.ᵔᵖᵹᵫ).mo3360(uri);
        } catch (SecurityException unused) {
            cursorMo3360 = null;
        } catch (Throwable th) {
            th = th;
            if (cursor != null) {
            }
            throw th;
        }
        try {
            if (cursorMo3360 != null) {
                try {
                    try {
                    } catch (SecurityException unused2) {
                        if (Log.isLoggable("ThumbStreamOpener", 3)) {
                            Objects.toString(uri);
                        }
                        if (cursorMo3360 != null) {
                        }
                        string = null;
                        if (TextUtils.isEmpty(string)) {
                        }
                        if (inputStreamOpenInputStream != null) {
                        }
                        if (i != -1) {
                        }
                    }
                    if (cursorMo3360.moveToFirst()) {
                        string = cursorMo3360.getString(0);
                        cursorMo3360.close();
                        if (TextUtils.isEmpty(string)) {
                            inputStreamOpenInputStream = null;
                        } else {
                            File file = new File(string);
                            if (file.exists() && 0 < file.length()) {
                                Uri uriFromFile = Uri.fromFile(file);
                                try {
                                    inputStreamOpenInputStream = contentResolver.openInputStream(uriFromFile);
                                } catch (NullPointerException e) {
                                    throw ((FileNotFoundException) new FileNotFoundException("NPE opening uri: " + uri + " -> " + uriFromFile).initCause(e));
                                }
                            }
                        }
                        if (inputStreamOpenInputStream != null) {
                            try {
                                inputStreamOpenInputStream2 = contentResolver.openInputStream(uri);
                                i = ᵣˉ.ˌᴵ((ArrayList) r1.ᵜᵪʾ, inputStreamOpenInputStream2, (C5540) r1.ᵨᵼⁱ);
                                if (inputStreamOpenInputStream2 != null) {
                                    try {
                                        inputStreamOpenInputStream2.close();
                                    } catch (IOException unused3) {
                                    }
                                }
                            } catch (IOException | NullPointerException unused4) {
                                if (Log.isLoggable("ThumbStreamOpener", 3)) {
                                    Objects.toString(uri);
                                }
                                if (inputStreamOpenInputStream2 != null) {
                                    try {
                                        inputStreamOpenInputStream2.close();
                                    } catch (IOException unused5) {
                                    }
                                }
                                i = -1;
                            }
                        } else {
                            i = -1;
                        }
                        return i != -1 ? new C3644(inputStreamOpenInputStream, i) : inputStreamOpenInputStream;
                    }
                } catch (Throwable th2) {
                    th = th2;
                    cursor = cursorMo3360;
                    if (cursor != null) {
                        cursor.close();
                    }
                    throw th;
                }
            }
            if (inputStreamOpenInputStream != null) {
            }
            if (i != -1) {
            }
        } catch (Throwable th3) {
            if (inputStreamOpenInputStream2 != null) {
                try {
                    inputStreamOpenInputStream2.close();
                } catch (IOException unused6) {
                }
            }
            throw th3;
        }
        if (cursorMo3360 != null) {
            cursorMo3360.close();
        }
        string = null;
        if (TextUtils.isEmpty(string)) {
        }
    }

    @Override // defpackage.InterfaceC5071
    /* JADX INFO: renamed from: ᵨᵣ */
    public final void mo1314(EnumC4810 enumC4810, InterfaceC3368 interfaceC3368) throws Throwable {
        switch (this.f17460) {
            case 0:
                try {
                    Object objMo7051 = ((InterfaceC2958) this.f17461).mo7051((File) this.f17462);
                    this.f17463 = objMo7051;
                    interfaceC3368.mo1312(objMo7051);
                } catch (FileNotFoundException e) {
                    Log.isLoggable("FileLoader", 3);
                    interfaceC3368.mo1313(e);
                    return;
                }
                break;
            default:
                try {
                    InputStream inputStreamM9665 = m9665();
                    this.f17463 = inputStreamM9665;
                    interfaceC3368.mo1312(inputStreamM9665);
                } catch (FileNotFoundException e2) {
                    Log.isLoggable("MediaStoreThumbFetcher", 3);
                    interfaceC3368.mo1313(e2);
                }
                break;
        }
    }

    @Override // defpackage.InterfaceC5071
    /* JADX INFO: renamed from: ᵷᵺʾᵖ */
    public final void mo1316() {
        switch (this.f17460) {
            case 0:
                Object obj = this.f17463;
                if (obj != null) {
                    try {
                        ((InterfaceC2958) this.f17461).mo7052(obj);
                    } catch (IOException unused) {
                        return;
                    }
                }
                break;
            default:
                InputStream inputStream = (InputStream) this.f17463;
                if (inputStream != null) {
                    try {
                        inputStream.close();
                    } catch (IOException unused2) {
                        return;
                    }
                }
                break;
        }
    }

    @Override // defpackage.InterfaceC5071
    /* JADX INFO: renamed from: ᵻˈᵦʼ */
    public final int mo1317() {
        switch (this.f17460) {
        }
        return 1;
    }
}
