package ඓ.ῲ.K.ᕣ.㿎.ؿ;

import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
import com.bumptech.glide.load.ImageHeaderParser;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import ඓ.ῲ.K.ᕣ.ᨨ.ゎ.AbstractC0967;
import ῲ.ᨨ.㳳.C1841;

/* renamed from: ඓ.ῲ.K.ᕣ.㿎.ؿ.㸾  reason: contains not printable characters */
/* compiled from: ThumbnailStreamOpener */
public class C1129 {

    /* renamed from: 㴹  reason: contains not printable characters */
    public static final C1128 f4598 = new C1128();

    /* renamed from: ʬ  reason: contains not printable characters */
    public final AbstractC0967 f4599;

    /* renamed from: ඓ  reason: contains not printable characters */
    public final List<ImageHeaderParser> f4600;

    /* renamed from: ῲ  reason: contains not printable characters */
    public final AbstractC1124 f4601;

    /* renamed from: K  reason: contains not printable characters */
    public final C1128 f4602 = f4598;

    /* renamed from: 㸾  reason: contains not printable characters */
    public final ContentResolver f4603;

    public C1129(List<ImageHeaderParser> list, AbstractC1124 r3, AbstractC0967 r4, ContentResolver contentResolver) {
        this.f4601 = r3;
        this.f4599 = r4;
        this.f4603 = contentResolver;
        this.f4600 = list;
    }

    /* JADX WARNING: Code restructure failed: missing block: B:12:0x0020, code lost:
        if (r3 != null) goto L_0x0022;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:13:0x0022, code lost:
        r3.close();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:14:0x0025, code lost:
        r0 = null;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:23:0x0048, code lost:
        if (r3 == null) goto L_0x0025;
     */
    /* JADX WARNING: Removed duplicated region for block: B:22:0x0034 A[Catch:{ all -> 0x001a }] */
    /* JADX WARNING: Removed duplicated region for block: B:42:0x00a3  */
    /* renamed from: ῲ  reason: contains not printable characters */
    public InputStream m3021(Uri uri) throws FileNotFoundException {
        Throwable th;
        SecurityException e;
        Cursor cursor;
        boolean z = false;
        Cursor cursor2 = null;
        try {
            cursor = this.f4601.m3010(uri);
            if (cursor != null) {
                try {
                    if (cursor.moveToFirst()) {
                        String str = cursor.getString(0);
                        cursor.close();
                        if (TextUtils.isEmpty(str)) {
                            return null;
                        }
                        File r0 = this.f4602.m3019(str);
                        if (this.f4602.m3020(r0) && 0 < this.f4602.m3018(r0)) {
                            z = true;
                        }
                        if (!z) {
                            return null;
                        }
                        Uri fromFile = Uri.fromFile(r0);
                        try {
                            return this.f4603.openInputStream(fromFile);
                        } catch (NullPointerException e2) {
                            throw ((FileNotFoundException) new FileNotFoundException("NPE opening uri: " + uri + " -> " + fromFile).initCause(e2));
                        }
                    }
                } catch (SecurityException e3) {
                    e = e3;
                    try {
                        if (Log.isLoggable("ThumbStreamOpener", 3)) {
                            Log.d("ThumbStreamOpener", "Failed to query for thumbnail for Uri: " + uri, e);
                        }
                    } catch (Throwable th2) {
                        th = th2;
                        cursor2 = cursor;
                        if (cursor2 != null) {
                            cursor2.close();
                        }
                        throw th;
                    }
                }
            }
        } catch (SecurityException e4) {
            e = e4;
            cursor = null;
            if (Log.isLoggable("ThumbStreamOpener", 3)) {
            }
        } catch (Throwable th3) {
            th = th3;
            if (cursor2 != null) {
            }
            throw th;
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public int m3022(Uri uri) {
        InputStream inputStream = null;
        try {
            inputStream = this.f4603.openInputStream(uri);
            int r6 = C1841.m4772(this.f4600, inputStream, this.f4599);
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException unused) {
                }
            }
            return r6;
        } catch (IOException | NullPointerException e) {
            if (Log.isLoggable("ThumbStreamOpener", 3)) {
                Log.d("ThumbStreamOpener", "Failed to open uri: " + uri, e);
            }
            if (inputStream == null) {
                return -1;
            }
            try {
                inputStream.close();
                return -1;
            } catch (IOException unused2) {
                return -1;
            }
        } catch (Throwable th) {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException unused3) {
                }
            }
            throw th;
        }
    }
}
