package g6; import android.content.ContentResolver; import android.content.Context; import android.database.Cursor; import android.net.Uri; import android.provider.MediaStore; import android.util.Log; import f6.d; import f6.g; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; /* loaded from: classes2.dex */ public class b implements f6.d { /* renamed from: a, reason: collision with root package name */ private final Uri f9721a; /* renamed from: b, reason: collision with root package name */ private final e f9722b; /* renamed from: c, reason: collision with root package name */ private InputStream f9723c; static class a implements d { /* renamed from: b, reason: collision with root package name */ private static final String[] f9724b = {"_data"}; /* renamed from: a, reason: collision with root package name */ private final ContentResolver f9725a; a(ContentResolver contentResolver) { this.f9725a = contentResolver; } @Override // g6.d public Cursor a(Uri uri) { return this.f9725a.query(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, f9724b, "kind = 1 AND image_id = ?", new String[]{uri.getLastPathSegment()}, null); } } /* renamed from: g6.b$b, reason: collision with other inner class name */ static class C0145b implements d { /* renamed from: b, reason: collision with root package name */ private static final String[] f9726b = {"_data"}; /* renamed from: a, reason: collision with root package name */ private final ContentResolver f9727a; C0145b(ContentResolver contentResolver) { this.f9727a = contentResolver; } @Override // g6.d public Cursor a(Uri uri) { return this.f9727a.query(MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI, f9726b, "kind = 1 AND video_id = ?", new String[]{uri.getLastPathSegment()}, null); } } b(Uri uri, e eVar) { this.f9721a = uri; this.f9722b = eVar; } private static b c(Context context, Uri uri, d dVar) { return new b(uri, new e(b6.e.m(context).q().g(), dVar, b6.e.m(context).n(), context.getContentResolver())); } private InputStream e() { InputStream d10 = this.f9722b.d(this.f9721a); int a10 = d10 != null ? this.f9722b.a(this.f9721a) : -1; return a10 != -1 ? new g(d10, a10) : d10; } public static b g(Context context, Uri uri) { return c(context, uri, new a(context.getContentResolver())); } public static b h(Context context, Uri uri) { return c(context, uri, new C0145b(context.getContentResolver())); } @Override // f6.d public Class a() { return InputStream.class; } @Override // f6.d public void b() { InputStream inputStream = this.f9723c; if (inputStream != null) { try { inputStream.close(); } catch (IOException unused) { } } } @Override // f6.d public void cancel() { } @Override // f6.d public e6.a d() { return e6.a.LOCAL; } @Override // f6.d public void f(b6.g gVar, d.a aVar) { try { InputStream e10 = e(); this.f9723c = e10; aVar.e(e10); } catch (FileNotFoundException e11) { if (Log.isLoggable("MediaStoreThumbFetcher", 3)) { Log.d("MediaStoreThumbFetcher", "Failed to find thumbnail file", e11); } aVar.c(e11); } } }