package x1; 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 com.bumptech.glide.load.data.d; import java.io.File; import java.io.FileNotFoundException; import java.io.InputStream; import q1.h; import w1.m; import w1.n; import w1.q; /* loaded from: classes.dex */ public final class d implements m { /* renamed from: a, reason: collision with root package name */ private final Context f15265a; /* renamed from: b, reason: collision with root package name */ private final m f15266b; /* renamed from: c, reason: collision with root package name */ private final m f15267c; /* renamed from: d, reason: collision with root package name */ private final Class f15268d; private static abstract class a implements n { /* renamed from: a, reason: collision with root package name */ private final Context f15269a; /* renamed from: b, reason: collision with root package name */ private final Class f15270b; a(Context context, Class cls) { this.f15269a = context; this.f15270b = cls; } @Override // w1.n public final m b(q qVar) { return new d(this.f15269a, qVar.d(File.class, this.f15270b), qVar.d(Uri.class, this.f15270b), this.f15270b); } } public static final class b extends a { public b(Context context) { super(context, ParcelFileDescriptor.class); } } public static final class c extends a { public c(Context context) { super(context, InputStream.class); } } /* renamed from: x1.d$d, reason: collision with other inner class name */ private static final class C0262d implements com.bumptech.glide.load.data.d { /* renamed from: k, reason: collision with root package name */ private static final String[] f15271k = {"_data"}; /* renamed from: a, reason: collision with root package name */ private final Context f15272a; /* renamed from: b, reason: collision with root package name */ private final m f15273b; /* renamed from: c, reason: collision with root package name */ private final m f15274c; /* renamed from: d, reason: collision with root package name */ private final Uri f15275d; /* renamed from: e, reason: collision with root package name */ private final int f15276e; /* renamed from: f, reason: collision with root package name */ private final int f15277f; /* renamed from: g, reason: collision with root package name */ private final h f15278g; /* renamed from: h, reason: collision with root package name */ private final Class f15279h; /* renamed from: i, reason: collision with root package name */ private volatile boolean f15280i; /* renamed from: j, reason: collision with root package name */ private volatile com.bumptech.glide.load.data.d f15281j; C0262d(Context context, m mVar, m mVar2, Uri uri, int i10, int i11, h hVar, Class cls) { this.f15272a = context.getApplicationContext(); this.f15273b = mVar; this.f15274c = mVar2; this.f15275d = uri; this.f15276e = i10; this.f15277f = i11; this.f15278g = hVar; this.f15279h = cls; } private m.a c() { boolean isExternalStorageLegacy; isExternalStorageLegacy = Environment.isExternalStorageLegacy(); if (isExternalStorageLegacy) { return this.f15273b.b(h(this.f15275d), this.f15276e, this.f15277f, this.f15278g); } return this.f15274c.b(g() ? MediaStore.setRequireOriginal(this.f15275d) : this.f15275d, this.f15276e, this.f15277f, this.f15278g); } private com.bumptech.glide.load.data.d e() { m.a c10 = c(); if (c10 != null) { return c10.f15058c; } return null; } private boolean g() { int checkSelfPermission; checkSelfPermission = this.f15272a.checkSelfPermission("android.permission.ACCESS_MEDIA_LOCATION"); return checkSelfPermission == 0; } private File h(Uri uri) { Cursor cursor = null; try { Cursor query = this.f15272a.getContentResolver().query(uri, f15271k, 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; } } @Override // com.bumptech.glide.load.data.d public Class a() { return this.f15279h; } @Override // com.bumptech.glide.load.data.d public void b() { com.bumptech.glide.load.data.d dVar = this.f15281j; if (dVar != null) { dVar.b(); } } @Override // com.bumptech.glide.load.data.d public void cancel() { this.f15280i = true; com.bumptech.glide.load.data.d dVar = this.f15281j; if (dVar != null) { dVar.cancel(); } } @Override // com.bumptech.glide.load.data.d public q1.a d() { return q1.a.LOCAL; } @Override // com.bumptech.glide.load.data.d public void f(com.bumptech.glide.g gVar, d.a aVar) { try { com.bumptech.glide.load.data.d e10 = e(); if (e10 == null) { aVar.c(new IllegalArgumentException("Failed to build fetcher for: " + this.f15275d)); return; } this.f15281j = e10; if (this.f15280i) { cancel(); } else { e10.f(gVar, aVar); } } catch (FileNotFoundException e11) { aVar.c(e11); } } } d(Context context, m mVar, m mVar2, Class cls) { this.f15265a = context.getApplicationContext(); this.f15266b = mVar; this.f15267c = mVar2; this.f15268d = cls; } @Override // w1.m /* renamed from: c, reason: merged with bridge method [inline-methods] */ public m.a b(Uri uri, int i10, int i11, h hVar) { return new m.a(new l2.b(uri), new C0262d(this.f15265a, this.f15266b, this.f15267c, uri, i10, i11, hVar, this.f15268d)); } @Override // w1.m /* renamed from: d, reason: merged with bridge method [inline-methods] */ public boolean a(Uri uri) { return Build.VERSION.SDK_INT >= 29 && r1.b.b(uri); } }