package m6; import android.content.Context; import android.database.Cursor; import android.net.Uri; import android.os.Build; import android.os.Environment; import android.os.ParcelFileDescriptor; import android.provider.MediaStore; import android.text.TextUtils; import b6.g; import e6.j; import f6.d; import java.io.File; import java.io.FileNotFoundException; import java.io.InputStream; import l6.m; import l6.n; import l6.p; /* loaded from: classes2.dex */ public final class d implements m { /* renamed from: a, reason: collision with root package name */ private final Context f11883a; /* renamed from: b, reason: collision with root package name */ private final m f11884b; /* renamed from: c, reason: collision with root package name */ private final m f11885c; /* renamed from: d, reason: collision with root package name */ private final Class f11886d; public static final class a extends c { public a(Context context) { super(context, ParcelFileDescriptor.class); } } public static final class b extends c { public b(Context context) { super(context, InputStream.class); } } private static abstract class c implements n { /* renamed from: a, reason: collision with root package name */ private final Context f11887a; /* renamed from: b, reason: collision with root package name */ private final Class f11888b; c(Context context, Class cls) { this.f11887a = context; this.f11888b = cls; } @Override // l6.n public final m b(p pVar) { return new d(this.f11887a, pVar.g(File.class, this.f11888b), pVar.g(Uri.class, this.f11888b), this.f11888b); } } /* renamed from: m6.d$d, reason: collision with other inner class name */ private static final class C0191d implements f6.d { /* renamed from: k, reason: collision with root package name */ private static final String[] f11889k = {"_data"}; /* renamed from: a, reason: collision with root package name */ private final Context f11890a; /* renamed from: b, reason: collision with root package name */ private final m f11891b; /* renamed from: c, reason: collision with root package name */ private final m f11892c; /* renamed from: d, reason: collision with root package name */ private final Uri f11893d; /* renamed from: e, reason: collision with root package name */ private final int f11894e; /* renamed from: f, reason: collision with root package name */ private final int f11895f; /* renamed from: g, reason: collision with root package name */ private final j f11896g; /* renamed from: h, reason: collision with root package name */ private final Class f11897h; /* renamed from: i, reason: collision with root package name */ private volatile boolean f11898i; /* renamed from: j, reason: collision with root package name */ private volatile f6.d f11899j; C0191d(Context context, m mVar, m mVar2, Uri uri, int i10, int i11, j jVar, Class cls) { this.f11890a = context.getApplicationContext(); this.f11891b = mVar; this.f11892c = mVar2; this.f11893d = uri; this.f11894e = i10; this.f11895f = i11; this.f11896g = jVar; this.f11897h = cls; } private File c(Uri uri) { Cursor cursor = null; try { Cursor query = this.f11890a.getContentResolver().query(uri, f11889k, null, null, null); if (query == null || !query.moveToFirst()) { throw new FileNotFoundException("Failed to media store entry for: " + uri); } String string = query.getString(query.getColumnIndexOrThrow("_data")); if (!TextUtils.isEmpty(string)) { File file = new File(string); query.close(); return file; } throw new FileNotFoundException("File path was empty in media store for: " + uri); } catch (Throwable th) { if (0 != 0) { cursor.close(); } throw th; } } private m.a e() { boolean isExternalStorageLegacy; isExternalStorageLegacy = Environment.isExternalStorageLegacy(); if (isExternalStorageLegacy) { return this.f11891b.b(c(this.f11893d), this.f11894e, this.f11895f, this.f11896g); } return this.f11892c.b(h() ? MediaStore.setRequireOriginal(this.f11893d) : this.f11893d, this.f11894e, this.f11895f, this.f11896g); } private f6.d g() { m.a e10 = e(); if (e10 != null) { return e10.f11676c; } return null; } private boolean h() { int checkSelfPermission; checkSelfPermission = this.f11890a.checkSelfPermission("android.permission.ACCESS_MEDIA_LOCATION"); return checkSelfPermission == 0; } @Override // f6.d public Class a() { return this.f11897h; } @Override // f6.d public void b() { f6.d dVar = this.f11899j; if (dVar != null) { dVar.b(); } } @Override // f6.d public void cancel() { this.f11898i = true; f6.d dVar = this.f11899j; if (dVar != null) { dVar.cancel(); } } @Override // f6.d public e6.a d() { return e6.a.LOCAL; } @Override // f6.d public void f(g gVar, d.a aVar) { try { f6.d g10 = g(); if (g10 == null) { aVar.c(new IllegalArgumentException("Failed to build fetcher for: " + this.f11893d)); return; } this.f11899j = g10; if (this.f11898i) { cancel(); } else { g10.f(gVar, aVar); } } catch (FileNotFoundException e10) { aVar.c(e10); } } } d(Context context, m mVar, m mVar2, Class cls) { this.f11883a = context.getApplicationContext(); this.f11884b = mVar; this.f11885c = mVar2; this.f11886d = cls; } @Override // l6.m /* renamed from: c, reason: merged with bridge method [inline-methods] */ public m.a b(Uri uri, int i10, int i11, j jVar) { return new m.a(new a7.d(uri), new C0191d(this.f11883a, this.f11884b, this.f11885c, uri, i10, i11, jVar, this.f11886d)); } @Override // l6.m /* renamed from: d, reason: merged with bridge method [inline-methods] */ public boolean a(Uri uri) { return Build.VERSION.SDK_INT >= 29 && g6.a.c(uri); } }