alexandroid/decompiled/jadx/sources/okio/AsyncTimeout.java
KaKi87 a47fad5135 📦 Add decompiled Alexa 2.2.730155.0 (jadx, apktool, Hermes strings)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-07 00:04:16 +01:00

444 lines
20 KiB
Java

package okio;
import androidx.exifinterface.media.ExifInterface;
import com.amazon.alexa.accessory.notificationpublisher.conversation.metrics.SpeechMetric;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
import kotlin.Metadata;
import kotlin.PublishedApi;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.InlineMarker;
import kotlin.jvm.internal.SourceDebugExtension;
import org.aspectj.lang.JoinPoint;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
@Metadata(d1 = {"\u0000@\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u000b\n\u0002\b\u0002\n\u0002\u0010\t\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\u0004\b\u0016\u0018\u0000 \u001b2\u00020\u0001:\u0002\u001b\u001cB\u0005¢\u0006\u0002\u0010\u0002J\u0012\u0010\b\u001a\u00020\t2\b\u0010\n\u001a\u0004\u0018\u00010\tH\u0001J\u0006\u0010\u000b\u001a\u00020\fJ\u0006\u0010\r\u001a\u00020\u0004J\u0012\u0010\u000e\u001a\u00020\t2\b\u0010\n\u001a\u0004\u0018\u00010\tH\u0014J\u0010\u0010\u000f\u001a\u00020\u00072\u0006\u0010\u0010\u001a\u00020\u0007H\u0002J\u000e\u0010\u0011\u001a\u00020\u00122\u0006\u0010\u0011\u001a\u00020\u0012J\u000e\u0010\u0013\u001a\u00020\u00142\u0006\u0010\u0013\u001a\u00020\u0014J\b\u0010\u0015\u001a\u00020\fH\u0014J%\u0010\u0016\u001a\u0002H\u0017\"\u0004\b\u0000\u0010\u00172\f\u0010\u0018\u001a\b\u0012\u0004\u0012\u0002H\u00170\u0019H\u0086\bø\u0001\u0000¢\u0006\u0002\u0010\u001aR\u000e\u0010\u0003\u001a\u00020\u0004X\u0082\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\u0005\u001a\u0004\u0018\u00010\u0000X\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0006\u001a\u00020\u0007X\u0082\u000e¢\u0006\u0002\n\u0000\u0082\u0002\u0007\n\u0005\b\u009920\u0001¨\u0006\u001d"}, d2 = {"Lokio/AsyncTimeout;", "Lokio/Timeout;", "()V", "inQueue", "", "next", "timeoutAt", "", "access$newTimeoutException", "Ljava/io/IOException;", "cause", "enter", "", "exit", "newTimeoutException", "remainingNanos", "now", "sink", "Lokio/Sink;", "source", "Lokio/Source;", SpeechMetric.TIMED_OUT, "withTimeout", ExifInterface.GPS_DIRECTION_TRUE, "block", "Lkotlin/Function0;", "(Lkotlin/jvm/functions/Function0;)Ljava/lang/Object;", "Companion", "Watchdog", "okio"}, k = 1, mv = {1, 9, 0}, xi = 48)
/* loaded from: classes10.dex */
public class AsyncTimeout extends Timeout {
/* renamed from: Companion, reason: from kotlin metadata */
@NotNull
public static final Companion INSTANCE = new Companion(null);
private static final long IDLE_TIMEOUT_MILLIS;
private static final long IDLE_TIMEOUT_NANOS;
private static final int TIMEOUT_WRITE_SIZE = 65536;
@NotNull
private static final Condition condition;
@Nullable
private static AsyncTimeout head;
@NotNull
private static final ReentrantLock lock;
private boolean inQueue;
@Nullable
private AsyncTimeout next;
private long timeoutAt;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
@Metadata(d1 = {"\u0000\u0012\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0000\b\u0002\u0018\u00002\u00020\u0001B\u0007\b\u0000¢\u0006\u0002\u0010\u0002J\b\u0010\u0003\u001a\u00020\u0004H\u0016¨\u0006\u0005"}, d2 = {"Lokio/AsyncTimeout$Watchdog;", "Ljava/lang/Thread;", "()V", "run", "", "okio"}, k = 1, mv = {1, 9, 0}, xi = 48)
public static final class Watchdog extends Thread {
public Watchdog() {
super("Okio Watchdog");
setDaemon(true);
}
@Override // java.lang.Thread, java.lang.Runnable
public void run() {
ReentrantLock lock;
AsyncTimeout awaitTimeout$okio;
while (true) {
try {
Companion companion = AsyncTimeout.INSTANCE;
lock = companion.getLock();
lock.lock();
try {
awaitTimeout$okio = companion.awaitTimeout$okio();
} finally {
lock.unlock();
}
} catch (InterruptedException unused) {
}
if (awaitTimeout$okio == AsyncTimeout.head) {
AsyncTimeout.head = null;
return;
}
Unit unit = Unit.INSTANCE;
lock.unlock();
if (awaitTimeout$okio != null) {
awaitTimeout$okio.timedOut();
}
}
}
}
static {
ReentrantLock reentrantLock = new ReentrantLock();
lock = reentrantLock;
Condition newCondition = reentrantLock.newCondition();
newCondition.getClass();
condition = newCondition;
IDLE_TIMEOUT_MILLIS = 60000L;
IDLE_TIMEOUT_NANOS = TimeUnit.MILLISECONDS.toNanos(60000L);
}
/* JADX INFO: Access modifiers changed from: private */
public final long remainingNanos(long now) {
return this.timeoutAt - now;
}
@PublishedApi
@NotNull
public final IOException access$newTimeoutException(@Nullable IOException cause) {
return newTimeoutException(cause);
}
public final void enter() {
long timeoutNanos = getTimeoutNanos();
boolean hasDeadline = getHasDeadline();
if (timeoutNanos != 0 || hasDeadline) {
INSTANCE.scheduleTimeout(this, timeoutNanos, hasDeadline);
}
}
public final boolean exit() {
return INSTANCE.cancelScheduledTimeout(this);
}
@NotNull
public IOException newTimeoutException(@Nullable IOException cause) {
InterruptedIOException interruptedIOException = new InterruptedIOException("timeout");
if (cause != null) {
interruptedIOException.initCause(cause);
}
return interruptedIOException;
}
@NotNull
public final Sink sink(@NotNull final Sink sink) {
sink.getClass();
return new Sink() { // from class: okio.AsyncTimeout$sink$1
@Override // okio.Sink, java.io.Closeable, java.lang.AutoCloseable
public void close() {
AsyncTimeout asyncTimeout = AsyncTimeout.this;
Sink sink2 = sink;
asyncTimeout.enter();
try {
sink2.close();
Unit unit = Unit.INSTANCE;
if (asyncTimeout.exit()) {
throw asyncTimeout.access$newTimeoutException(null);
}
} catch (IOException e) {
if (!asyncTimeout.exit()) {
throw e;
}
throw asyncTimeout.access$newTimeoutException(e);
} finally {
asyncTimeout.exit();
}
}
@Override // okio.Sink, java.io.Flushable
public void flush() {
AsyncTimeout asyncTimeout = AsyncTimeout.this;
Sink sink2 = sink;
asyncTimeout.enter();
try {
sink2.flush();
Unit unit = Unit.INSTANCE;
if (asyncTimeout.exit()) {
throw asyncTimeout.access$newTimeoutException(null);
}
} catch (IOException e) {
if (!asyncTimeout.exit()) {
throw e;
}
throw asyncTimeout.access$newTimeoutException(e);
} finally {
asyncTimeout.exit();
}
}
@NotNull
public String toString() {
return "AsyncTimeout.sink(" + sink + ')';
}
@Override // okio.Sink
public void write(@NotNull Buffer source, long byteCount) {
source.getClass();
SegmentedByteString.checkOffsetAndCount(source.size(), 0L, byteCount);
while (true) {
long j = 0;
if (byteCount <= 0) {
return;
}
Segment segment = source.head;
segment.getClass();
while (true) {
if (j >= 65536) {
break;
}
j += segment.limit - segment.pos;
if (j >= byteCount) {
j = byteCount;
break;
} else {
segment = segment.next;
segment.getClass();
}
}
AsyncTimeout asyncTimeout = AsyncTimeout.this;
Sink sink2 = sink;
asyncTimeout.enter();
try {
try {
sink2.write(source, j);
Unit unit = Unit.INSTANCE;
if (asyncTimeout.exit()) {
throw asyncTimeout.access$newTimeoutException(null);
}
byteCount -= j;
} catch (IOException e) {
if (!asyncTimeout.exit()) {
throw e;
}
throw asyncTimeout.access$newTimeoutException(e);
}
} catch (Throwable th) {
asyncTimeout.exit();
throw th;
}
}
}
@Override // okio.Sink
@NotNull
/* renamed from: timeout, reason: from getter */
public AsyncTimeout getThis$0() {
return AsyncTimeout.this;
}
};
}
@NotNull
public final Source source(@NotNull final Source source) {
source.getClass();
return new Source() { // from class: okio.AsyncTimeout$source$1
@Override // okio.Source, java.io.Closeable, java.lang.AutoCloseable
public void close() {
AsyncTimeout asyncTimeout = AsyncTimeout.this;
Source source2 = source;
asyncTimeout.enter();
try {
source2.close();
Unit unit = Unit.INSTANCE;
if (asyncTimeout.exit()) {
throw asyncTimeout.access$newTimeoutException(null);
}
} catch (IOException e) {
if (!asyncTimeout.exit()) {
throw e;
}
throw asyncTimeout.access$newTimeoutException(e);
} finally {
asyncTimeout.exit();
}
}
@Override // okio.Source
public long read(@NotNull Buffer sink, long byteCount) {
sink.getClass();
AsyncTimeout asyncTimeout = AsyncTimeout.this;
Source source2 = source;
asyncTimeout.enter();
try {
long read = source2.read(sink, byteCount);
if (asyncTimeout.exit()) {
throw asyncTimeout.access$newTimeoutException(null);
}
return read;
} catch (IOException e) {
if (asyncTimeout.exit()) {
throw asyncTimeout.access$newTimeoutException(e);
}
throw e;
} finally {
asyncTimeout.exit();
}
}
@NotNull
public String toString() {
return "AsyncTimeout.source(" + source + ')';
}
@Override // okio.Source
@NotNull
/* renamed from: timeout, reason: from getter */
public AsyncTimeout getThis$0() {
return AsyncTimeout.this;
}
};
}
public final <T> T withTimeout(@NotNull Function0<? extends T> block) {
block.getClass();
enter();
try {
try {
T invoke = block.invoke();
InlineMarker.finallyStart(1);
if (exit()) {
throw access$newTimeoutException(null);
}
InlineMarker.finallyEnd(1);
return invoke;
} catch (IOException e) {
if (exit()) {
throw access$newTimeoutException(e);
}
throw e;
}
} catch (Throwable th) {
InlineMarker.finallyStart(1);
exit();
InlineMarker.finallyEnd(1);
throw th;
}
}
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
@Metadata(d1 = {"\u0000@\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\t\n\u0002\b\u0002\n\u0002\u0010\b\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0010\u000b\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0002\b\u0003\b\u0086\u0003\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002J\u000f\u0010\u0012\u001a\u0004\u0018\u00010\rH\u0000¢\u0006\u0002\b\u0013J\u0010\u0010\u0014\u001a\u00020\u00152\u0006\u0010\u0016\u001a\u00020\rH\u0002J \u0010\u0017\u001a\u00020\u00182\u0006\u0010\u0016\u001a\u00020\r2\u0006\u0010\u0019\u001a\u00020\u00042\u0006\u0010\u001a\u001a\u00020\u0015H\u0002R\u000e\u0010\u0003\u001a\u00020\u0004X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0005\u001a\u00020\u0004X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0006\u001a\u00020\u0007X\u0082T¢\u0006\u0002\n\u0000R\u0011\u0010\b\u001a\u00020\t¢\u0006\b\n\u0000\u001a\u0004\b\n\u0010\u000bR\u0010\u0010\f\u001a\u0004\u0018\u00010\rX\u0082\u000e¢\u0006\u0002\n\u0000R\u0011\u0010\u000e\u001a\u00020\u000f¢\u0006\b\n\u0000\u001a\u0004\b\u0010\u0010\u0011¨\u0006\u001b"}, d2 = {"Lokio/AsyncTimeout$Companion;", "", "()V", "IDLE_TIMEOUT_MILLIS", "", "IDLE_TIMEOUT_NANOS", "TIMEOUT_WRITE_SIZE", "", "condition", "Ljava/util/concurrent/locks/Condition;", "getCondition", "()Ljava/util/concurrent/locks/Condition;", "head", "Lokio/AsyncTimeout;", JoinPoint.SYNCHRONIZATION_LOCK, "Ljava/util/concurrent/locks/ReentrantLock;", "getLock", "()Ljava/util/concurrent/locks/ReentrantLock;", "awaitTimeout", "awaitTimeout$okio", "cancelScheduledTimeout", "", "node", "scheduleTimeout", "", "timeoutNanos", "hasDeadline", "okio"}, k = 1, mv = {1, 9, 0}, xi = 48)
@SourceDebugExtension({"SMAP\nAsyncTimeout.kt\nKotlin\n*S Kotlin\n*F\n+ 1 AsyncTimeout.kt\nokio/AsyncTimeout$Companion\n+ 2 fake.kt\nkotlin/jvm/internal/FakeKt\n*L\n1#1,331:1\n1#2:332\n*E\n"})
public static final class Companion {
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
/* JADX INFO: Access modifiers changed from: private */
public final boolean cancelScheduledTimeout(AsyncTimeout node) {
ReentrantLock lock = AsyncTimeout.INSTANCE.getLock();
lock.lock();
try {
if (!node.inQueue) {
return false;
}
node.inQueue = false;
for (AsyncTimeout asyncTimeout = AsyncTimeout.head; asyncTimeout != null; asyncTimeout = asyncTimeout.next) {
if (asyncTimeout.next == node) {
asyncTimeout.next = node.next;
node.next = null;
return false;
}
}
lock.unlock();
return true;
} finally {
lock.unlock();
}
}
/* JADX INFO: Access modifiers changed from: private */
public final void scheduleTimeout(AsyncTimeout node, long timeoutNanos, boolean hasDeadline) {
ReentrantLock lock = AsyncTimeout.INSTANCE.getLock();
lock.lock();
try {
if (node.inQueue) {
throw new IllegalStateException("Unbalanced enter/exit");
}
node.inQueue = true;
if (AsyncTimeout.head == null) {
AsyncTimeout.head = new AsyncTimeout();
new Watchdog().start();
}
long nanoTime = System.nanoTime();
if (timeoutNanos != 0 && hasDeadline) {
node.timeoutAt = Math.min(timeoutNanos, node.deadlineNanoTime() - nanoTime) + nanoTime;
} else if (timeoutNanos != 0) {
node.timeoutAt = timeoutNanos + nanoTime;
} else {
if (!hasDeadline) {
throw new AssertionError();
}
node.timeoutAt = node.deadlineNanoTime();
}
long remainingNanos = node.remainingNanos(nanoTime);
AsyncTimeout asyncTimeout = AsyncTimeout.head;
asyncTimeout.getClass();
while (asyncTimeout.next != null) {
AsyncTimeout asyncTimeout2 = asyncTimeout.next;
asyncTimeout2.getClass();
if (remainingNanos < asyncTimeout2.remainingNanos(nanoTime)) {
break;
}
asyncTimeout = asyncTimeout.next;
asyncTimeout.getClass();
}
node.next = asyncTimeout.next;
asyncTimeout.next = node;
if (asyncTimeout == AsyncTimeout.head) {
AsyncTimeout.INSTANCE.getCondition().signal();
}
Unit unit = Unit.INSTANCE;
lock.unlock();
} catch (Throwable th) {
lock.unlock();
throw th;
}
}
@Nullable
public final AsyncTimeout awaitTimeout$okio() throws InterruptedException {
AsyncTimeout asyncTimeout = AsyncTimeout.head;
asyncTimeout.getClass();
AsyncTimeout asyncTimeout2 = asyncTimeout.next;
if (asyncTimeout2 == null) {
long nanoTime = System.nanoTime();
getCondition().await(AsyncTimeout.IDLE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
AsyncTimeout asyncTimeout3 = AsyncTimeout.head;
asyncTimeout3.getClass();
if (asyncTimeout3.next != null || System.nanoTime() - nanoTime < AsyncTimeout.IDLE_TIMEOUT_NANOS) {
return null;
}
return AsyncTimeout.head;
}
long remainingNanos = asyncTimeout2.remainingNanos(System.nanoTime());
if (remainingNanos > 0) {
getCondition().await(remainingNanos, TimeUnit.NANOSECONDS);
return null;
}
AsyncTimeout asyncTimeout4 = AsyncTimeout.head;
asyncTimeout4.getClass();
asyncTimeout4.next = asyncTimeout2.next;
asyncTimeout2.next = null;
return asyncTimeout2;
}
@NotNull
public final Condition getCondition() {
return AsyncTimeout.condition;
}
@NotNull
public final ReentrantLock getLock() {
return AsyncTimeout.lock;
}
private Companion() {
}
}
public void timedOut() {
}
}