package com.fyber.inneractive.sdk.player.cache; import android.net.Uri; import android.os.HandlerThread; import android.text.TextUtils; import com.fyber.inneractive.sdk.config.IAConfigManager; import com.fyber.inneractive.sdk.config.global.features.r; import com.fyber.inneractive.sdk.config.global.s; import com.fyber.inneractive.sdk.player.cache.j; import com.fyber.inneractive.sdk.util.n0; import com.fyber.inneractive.sdk.util.t; import com.google.firebase.perf.network.FirebasePerfUrlConnection; import com.mbridge.msdk.foundation.download.Command; import java.io.ByteArrayOutputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; import java.nio.ByteBuffer; import java.util.Locale; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; /* loaded from: classes2.dex */ public final class d implements com.fyber.inneractive.sdk.player.exoplayer2.upstream.f { public com.fyber.inneractive.sdk.player.cache.a b; public j c; public Uri d; public FileInputStream f; public FileInputStream g; public b h; public c i; public int j; public s k; public boolean a = false; public long e = 0; public class a implements j.g { public final /* synthetic */ com.fyber.inneractive.sdk.util.i a; public final /* synthetic */ AtomicReference b; public final /* synthetic */ CountDownLatch c; public a(com.fyber.inneractive.sdk.util.i iVar, AtomicReference atomicReference, CountDownLatch countDownLatch) { this.a = iVar; this.b = atomicReference; this.c = countDownLatch; } } public interface b { } public interface c { } @Override // com.fyber.inneractive.sdk.player.exoplayer2.upstream.f public final Uri a() { return this.d; } @Override // com.fyber.inneractive.sdk.player.exoplayer2.upstream.f public final long a(com.fyber.inneractive.sdk.player.exoplayer2.upstream.i iVar) throws IOException { com.fyber.inneractive.sdk.player.cache.b lVar; r.d dVar; if (this.b == null) { CountDownLatch countDownLatch = new CountDownLatch(1); AtomicReference atomicReference = new AtomicReference(); com.fyber.inneractive.sdk.util.i iVar2 = new com.fyber.inneractive.sdk.util.i(); Uri uri = iVar.a; this.d = uri; p pVar = p.f; int i = this.j; String uri2 = uri.toString(); s sVar = this.k; a aVar = new a(iVar2, atomicReference, countDownLatch); com.fyber.inneractive.sdk.player.cache.c cVar = pVar.b; boolean a2 = IAConfigManager.L.t.b.a(false, "validateHasVideoTracks"); r rVar = sVar == null ? null : (r) sVar.a(r.class); if (rVar != null) { int[] iArr = j.b.a; r.d dVar2 = r.d.LEGACY; String a3 = rVar.a("v_type", dVar2.key); r.d[] values = r.d.values(); int length = values.length; int i2 = 0; while (true) { if (i2 >= length) { dVar = dVar2; break; } int i3 = length; r.d dVar3 = values[i2]; r.d[] dVarArr = values; if (TextUtils.equals(dVar3.key, a3.toLowerCase(Locale.US))) { dVar = dVar3; break; } i2++; length = i3; values = dVarArr; } int i4 = iArr[dVar.ordinal()]; lVar = i4 != 1 ? i4 != 2 ? new l(a2) : new k() : new m(); } else { lVar = new l(a2); } j jVar = new j(cVar, uri2, lVar, i, sVar); jVar.g = aVar; pVar.d.add(jVar.a()); this.c = jVar; jVar.q = iVar2; jVar.o = true; HandlerThread handlerThread = jVar.i; if (handlerThread != null) { handlerThread.start(); n0 n0Var = new n0(jVar.i.getLooper(), jVar); jVar.j = n0Var; n0Var.post(new f(jVar)); } c cVar2 = this.i; if (cVar2 != null) { ((com.fyber.inneractive.sdk.player.controller.d) cVar2).E.add(this.c); } try { countDownLatch.await(7L, TimeUnit.SECONDS); if (this.b == null) { if (atomicReference.get() == null) { throw new IOException("Cache has failed to download"); } throw new IOException((Throwable) atomicReference.get()); } } catch (InterruptedException e) { j jVar2 = this.c; jVar2.a(jVar2.o); throw new IOException(e); } } this.e = iVar.d; com.fyber.inneractive.sdk.player.cache.a aVar2 = this.b; String valueOf = aVar2.c ? (String) aVar2.e.get("http.file.length") : String.valueOf(aVar2.a().length()); if (valueOf == null || !TextUtils.isDigitsOnly(valueOf)) { return -1L; } return Long.parseLong(valueOf); } /* JADX WARN: Removed duplicated region for block: B:35:0x0086 A[Catch: all -> 0x001f, TryCatch #1 {all -> 0x001f, blocks: (B:10:0x000c, B:12:0x0019, B:13:0x001d, B:15:0x0022, B:22:0x0032, B:23:0x0035, B:26:0x0042, B:27:0x0047, B:29:0x0048, B:31:0x004c, B:33:0x0082, B:35:0x0086, B:36:0x0088, B:39:0x0090, B:42:0x009b, B:43:0x00a2, B:44:0x00a3, B:45:0x00b1, B:48:0x005b, B:50:0x005f), top: B:9:0x000c, inners: #0 }] */ @Override // com.fyber.inneractive.sdk.player.exoplayer2.upstream.f /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct add '--show-bad-code' argument */ public final int read(byte[] r10, int r11, int r12) throws java.io.IOException { /* r9 = this; com.fyber.inneractive.sdk.player.cache.a r0 = r9.b if (r0 != 0) goto L6 r10 = -1 return r10 L6: if (r12 != 0) goto L9 return r12 L9: java.lang.Object r0 = r0.d monitor-enter(r0) com.fyber.inneractive.sdk.player.cache.a r1 = r9.b // Catch: java.lang.Throwable -> L1f java.io.File r1 = r1.a() // Catch: java.lang.Throwable -> L1f long r1 = r1.length() // Catch: java.lang.Throwable -> L1f int r1 = (int) r1 // Catch: java.lang.Throwable -> L1f if (r11 <= r1) goto L22 int r10 = r9.a(r10, r11, r12) // Catch: java.lang.Throwable -> L1f monitor-exit(r0) // Catch: java.lang.Throwable -> L1f return r10 L1f: r10 = move-exception goto Lb9 L22: com.fyber.inneractive.sdk.player.cache.a r2 = r9.b // Catch: java.lang.Throwable -> L1f boolean r2 = r2.c // Catch: java.lang.Throwable -> L1f r3 = 0 r5 = 0 r6 = 1 if (r2 == 0) goto L5b L2c: int r2 = r1 - r11 if (r2 > 0) goto L48 r1 = 50 r9.wait(r3, r1) // Catch: java.lang.Throwable -> L1f java.lang.InterruptedException -> L41 com.fyber.inneractive.sdk.player.cache.a r1 = r9.b // Catch: java.lang.Throwable -> L1f java.io.File r1 = r1.a() // Catch: java.lang.Throwable -> L1f long r1 = r1.length() // Catch: java.lang.Throwable -> L1f int r1 = (int) r1 // Catch: java.lang.Throwable -> L1f goto L2c L41: r10 = move-exception java.io.IOException r11 = new java.io.IOException // Catch: java.lang.Throwable -> L1f r11.(r10) // Catch: java.lang.Throwable -> L1f throw r11 // Catch: java.lang.Throwable -> L1f L48: java.io.FileInputStream r2 = r9.g // Catch: java.lang.Throwable -> L1f if (r2 != 0) goto L82 java.io.FileInputStream r2 = new java.io.FileInputStream // Catch: java.lang.Throwable -> L1f com.fyber.inneractive.sdk.player.cache.a r5 = r9.b // Catch: java.lang.Throwable -> L1f java.io.File r5 = r5.a() // Catch: java.lang.Throwable -> L1f r2.(r5) // Catch: java.lang.Throwable -> L1f r9.g = r2 // Catch: java.lang.Throwable -> L1f L59: r5 = r6 goto L82 L5b: java.io.FileInputStream r2 = r9.f // Catch: java.lang.Throwable -> L1f if (r2 != 0) goto L82 java.lang.String r2 = "%s creating a single instance of fis" java.lang.Object[] r7 = new java.lang.Object[r6] // Catch: java.lang.Throwable -> L1f java.lang.String r8 = r9.toString() // Catch: java.lang.Throwable -> L1f r7[r5] = r8 // Catch: java.lang.Throwable -> L1f com.fyber.inneractive.sdk.util.IAlog.a(r2, r7) // Catch: java.lang.Throwable -> L1f java.io.FileInputStream r2 = new java.io.FileInputStream // Catch: java.lang.Throwable -> L1f com.fyber.inneractive.sdk.player.cache.a r5 = r9.b // Catch: java.lang.Throwable -> L1f java.io.File r5 = r5.a() // Catch: java.lang.Throwable -> L1f r2.(r5) // Catch: java.lang.Throwable -> L1f r9.f = r2 // Catch: java.lang.Throwable -> L1f java.io.FileInputStream r2 = r9.g // Catch: java.lang.Throwable -> L1f com.fyber.inneractive.sdk.util.t.b(r2) // Catch: java.lang.Throwable -> L1f r2 = 0 r9.g = r2 // Catch: java.lang.Throwable -> L1f goto L59 L82: java.io.FileInputStream r2 = r9.f // Catch: java.lang.Throwable -> L1f if (r2 != 0) goto L88 java.io.FileInputStream r2 = r9.g // Catch: java.lang.Throwable -> L1f L88: long r6 = r9.e // Catch: java.lang.Throwable -> L1f int r3 = (r6 > r3 ? 1 : (r6 == r3 ? 0 : -1)) if (r3 <= 0) goto La3 if (r5 == 0) goto La3 long r3 = r2.skip(r6) // Catch: java.lang.Throwable -> L1f long r5 = r9.e // Catch: java.lang.Throwable -> L1f int r3 = (r3 > r5 ? 1 : (r3 == r5 ? 0 : -1)) if (r3 != 0) goto L9b goto La3 L9b: java.io.IOException r10 = new java.io.IOException // Catch: java.lang.Throwable -> L1f java.lang.String r11 = "Failed to skip the stream" r10.(r11) // Catch: java.lang.Throwable -> L1f throw r10 // Catch: java.lang.Throwable -> L1f La3: int r1 = r1 - r11 int r3 = r10.length // Catch: java.lang.Throwable -> L1f int r1 = java.lang.Math.min(r3, r1) // Catch: java.lang.Throwable -> L1f int r12 = java.lang.Math.min(r1, r12) // Catch: java.lang.Throwable -> L1f int r10 = r2.read(r10, r11, r12) // Catch: java.lang.Throwable -> L1f monitor-exit(r0) // Catch: java.lang.Throwable -> L1f long r11 = r9.e long r0 = (long) r10 long r11 = r11 + r0 r9.e = r11 return r10 Lb9: monitor-exit(r0) // Catch: java.lang.Throwable -> L1f throw r10 */ throw new UnsupportedOperationException("Method not decompiled: com.fyber.inneractive.sdk.player.cache.d.read(byte[], int, int):int"); } @Override // com.fyber.inneractive.sdk.player.exoplayer2.upstream.f public final void close() throws IOException { this.a = true; this.e = 0L; t.b(this.f); t.b(this.g); this.f = null; this.g = null; } public final int a(byte[] bArr, int i, int i2) throws IOException { InputStream inputStream; InputStream inputStream2; InputStream inputStream3; HttpURLConnection httpURLConnection; String str = this.b.b; ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(bArr.length); int i3 = (int) this.e; ByteBuffer byteBuffer = (ByteBuffer) com.fyber.inneractive.sdk.util.g.b.a.poll(); if (byteBuffer == null) { byteBuffer = ByteBuffer.allocateDirect(16384); } HttpURLConnection httpURLConnection2 = null; try { httpURLConnection = (HttpURLConnection) ((URLConnection) FirebasePerfUrlConnection.instrument(new URL(str).openConnection())); } catch (IOException e) { e = e; inputStream2 = null; } catch (Throwable unused) { inputStream = null; } try { httpURLConnection.setRequestProperty(Command.HTTP_HEADER_RANGE, String.format(Locale.ENGLISH, "bytes=%d-", Integer.valueOf(i3))); httpURLConnection.connect(); } catch (IOException e2) { e = e2; inputStream2 = null; httpURLConnection2 = httpURLConnection; try { throw e; } finally { } } catch (Throwable unused2) { httpURLConnection2 = httpURLConnection; inputStream = null; if (httpURLConnection2 != null) { try { httpURLConnection2.disconnect(); } catch (Exception unused3) { } } if (inputStream != null) { inputStream3 = inputStream; try { inputStream3.close(); } catch (Exception unused4) { } } System.arraycopy(byteArrayOutputStream.toByteArray(), 0, bArr, i, i2); return i2; } if (httpURLConnection.getResponseCode() == 206) { inputStream3 = httpURLConnection.getInputStream(); byte[] array = byteBuffer.array(); while (inputStream3.read(array) != -1) { byteArrayOutputStream.write(array); } inputStream3.close(); httpURLConnection.disconnect(); try { httpURLConnection.disconnect(); } catch (Exception unused5) { } inputStream3.close(); System.arraycopy(byteArrayOutputStream.toByteArray(), 0, bArr, i, i2); return i2; } throw new IOException("Server did not reply with proper range."); } }