package b5;

import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

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

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final c5.b f4729b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final ContentResolver f4730c;

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

    public e(ArrayList arrayList, d dVar, c5.b bVar, ContentResolver contentResolver) {
        this.f4728a = dVar;
        this.f4729b = bVar;
        this.f4730c = contentResolver;
        this.f4731d = arrayList;
    }

    /* JADX WARN: Removed duplicated region for block: B:25:0x0038  */
    @Nullable
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private String getPath(@NonNull Uri uri) throws Throwable {
        Cursor cursorA;
        Cursor cursor = null;
        try {
            cursorA = this.f4728a.a(uri);
            if (cursorA != null) {
                try {
                    try {
                        if (cursorA.moveToFirst()) {
                            String string = cursorA.getString(0);
                            cursorA.close();
                            return string;
                        }
                    } catch (SecurityException unused) {
                        if (Log.isLoggable("ThumbStreamOpener", 3)) {
                            Objects.toString(uri);
                        }
                        if (cursorA != null) {
                            cursorA.close();
                        }
                        return null;
                    }
                } catch (Throwable th) {
                    th = th;
                    cursor = cursorA;
                    if (cursor != null) {
                        cursor.close();
                    }
                    throw th;
                }
            }
            if (cursorA != null) {
                cursorA.close();
            }
            return null;
        } catch (SecurityException unused2) {
            cursorA = null;
        } catch (Throwable th2) {
            th = th2;
            if (cursor != null) {
            }
            throw th;
        }
    }

    public final InputStream a(Uri uri) throws Throwable {
        String path = getPath(uri);
        if (TextUtils.isEmpty(path)) {
            return null;
        }
        File file = new File(path);
        if (!file.exists() || 0 >= file.length()) {
            return null;
        }
        Uri uriFromFile = Uri.fromFile(file);
        try {
            return this.f4730c.openInputStream(uriFromFile);
        } catch (NullPointerException e10) {
            throw ((FileNotFoundException) new FileNotFoundException("NPE opening uri: " + uri + " -> " + uriFromFile).initCause(e10));
        }
    }
}
