package o; 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 java.io.File; import java.io.FileNotFoundException; import java.io.InputStream; import o.InterfaceC12232euN; import o.SCe; /* loaded from: classes.dex */ public final class wZP implements SCe { private final Context a; private final SCe b; private final SCe c; private final Class e; @Override // o.SCe public final /* synthetic */ boolean d(Uri uri) { return Build.VERSION.SDK_INT >= 29 && C15604gzZ.DL_(uri); } @Override // o.SCe public final /* synthetic */ SCe.IeS e(Uri uri, int i, int i2, unA una) { Uri uri2 = uri; return new SCe.IeS(new xBn(uri2), new LWm(this.a, this.c, this.b, uri2, i, i2, una, this.e)); } wZP(Context context, SCe sCe, SCe sCe2, Class cls) { this.a = context.getApplicationContext(); this.c = sCe; this.b = sCe2; this.e = cls; } /* loaded from: classes.dex */ static final class LWm implements InterfaceC12232euN { private static final String[] d = {"_data"}; private final Class a; private volatile InterfaceC12232euN b; private final Context c; private final SCe e; private volatile boolean f; private final unA g; private final Uri h; private final SCe i; private final int j; private final int n; LWm(Context context, SCe sCe, SCe sCe2, Uri uri, int i, int i2, unA una, Class cls) { this.c = context.getApplicationContext(); this.e = sCe; this.i = sCe2; this.h = uri; this.n = i; this.j = i2; this.g = una; this.a = cls; } @Override // o.InterfaceC12232euN public final void e() { InterfaceC12232euN interfaceC12232euN = this.b; if (interfaceC12232euN != null) { interfaceC12232euN.e(); } } @Override // o.InterfaceC12232euN public final void a() { this.f = true; InterfaceC12232euN interfaceC12232euN = this.b; if (interfaceC12232euN != null) { interfaceC12232euN.a(); } } @Override // o.InterfaceC12232euN public final pNW d() { return pNW.LOCAL; } private File EA_(Uri uri) throws FileNotFoundException { Cursor cursor = null; try { Cursor query = this.c.getContentResolver().query(uri, d, null, null, null); if (query == null || !query.moveToFirst()) { StringBuilder sb = new StringBuilder("Failed to media store entry for: "); sb.append(uri); throw new FileNotFoundException(sb.toString()); } String string = query.getString(query.getColumnIndexOrThrow("_data")); if (TextUtils.isEmpty(string)) { StringBuilder sb2 = new StringBuilder("File path was empty in media store for: "); sb2.append(uri); throw new FileNotFoundException(sb2.toString()); } File file = new File(string); if (query != null) { query.close(); } return file; } catch (Throwable th) { if (0 != 0) { cursor.close(); } throw th; } } @Override // o.InterfaceC12232euN public final void c(EnumC3495ayd enumC3495ayd, InterfaceC12232euN.IeS ieS) { SCe.IeS e; try { if (Environment.isExternalStorageLegacy()) { e = this.e.e(EA_(this.h), this.n, this.j, this.g); } else { e = this.i.e(this.c.checkSelfPermission("android.permission.ACCESS_MEDIA_LOCATION") == 0 ? MediaStore.setRequireOriginal(this.h) : this.h, this.n, this.j, this.g); } InterfaceC12232euN interfaceC12232euN = e != null ? e.d : null; if (interfaceC12232euN == null) { StringBuilder sb = new StringBuilder("Failed to build fetcher for: "); sb.append(this.h); ieS.a((Exception) new IllegalArgumentException(sb.toString())); return; } this.b = interfaceC12232euN; if (this.f) { this.f = true; InterfaceC12232euN interfaceC12232euN2 = this.b; if (interfaceC12232euN2 != null) { interfaceC12232euN2.a(); return; } return; } interfaceC12232euN.c(enumC3495ayd, ieS); } catch (FileNotFoundException e2) { ieS.a((Exception) e2); } } @Override // o.InterfaceC12232euN public final Class c() { return this.a; } } /* loaded from: classes.dex */ public static final class HBt extends Sts { public HBt(Context context) { super(context, InputStream.class); } } /* loaded from: classes.dex */ public static final class IeS extends Sts { public IeS(Context context) { super(context, ParcelFileDescriptor.class); } } /* loaded from: classes.dex */ static abstract class Sts implements rIx { private final Context c; private final Class d; Sts(Context context, Class cls) { this.c = context; this.d = cls; } @Override // o.rIx public final SCe c(Vzp vzp) { return new wZP(this.c, vzp.b(File.class, this.d), vzp.b(Uri.class, this.d), this.d); } } }