216 lines
7.5 KiB
Java
216 lines
7.5 KiB
Java
package org.webrtc;
|
|
|
|
import android.os.Handler;
|
|
import android.os.Looper;
|
|
import android.os.SystemClock;
|
|
import androidx.annotation.Nullable;
|
|
import java.util.concurrent.Callable;
|
|
import java.util.concurrent.CountDownLatch;
|
|
import java.util.concurrent.TimeUnit;
|
|
public class ThreadUtils {
|
|
|
|
/* renamed from: org.webrtc.ThreadUtils$1 reason: invalid class name */
|
|
public class AnonymousClass1 implements BlockingOperation {
|
|
public final /* synthetic */ Thread val$thread;
|
|
|
|
public AnonymousClass1(Thread thread) {
|
|
this.val$thread = thread;
|
|
}
|
|
|
|
@Override // org.webrtc.ThreadUtils.BlockingOperation
|
|
public void run() throws InterruptedException {
|
|
this.val$thread.join();
|
|
}
|
|
}
|
|
|
|
/* renamed from: org.webrtc.ThreadUtils$1CaughtException reason: invalid class name */
|
|
public class AnonymousClass1CaughtException {
|
|
public Exception e;
|
|
}
|
|
|
|
/* renamed from: org.webrtc.ThreadUtils$1Result reason: invalid class name */
|
|
public class AnonymousClass1Result {
|
|
public V value;
|
|
}
|
|
|
|
/* renamed from: org.webrtc.ThreadUtils$2 reason: invalid class name */
|
|
public class AnonymousClass2 implements BlockingOperation {
|
|
public final /* synthetic */ CountDownLatch val$latch;
|
|
|
|
public AnonymousClass2(CountDownLatch countDownLatch) {
|
|
this.val$latch = countDownLatch;
|
|
}
|
|
|
|
@Override // org.webrtc.ThreadUtils.BlockingOperation
|
|
public void run() throws InterruptedException {
|
|
this.val$latch.await();
|
|
}
|
|
}
|
|
|
|
/* renamed from: org.webrtc.ThreadUtils$3 reason: invalid class name */
|
|
public class AnonymousClass3 implements Runnable {
|
|
public final /* synthetic */ CountDownLatch val$barrier;
|
|
public final /* synthetic */ Callable val$callable;
|
|
public final /* synthetic */ AnonymousClass1CaughtException val$caughtException;
|
|
public final /* synthetic */ AnonymousClass1Result val$result;
|
|
|
|
public AnonymousClass3(AnonymousClass1Result r1, Callable callable, AnonymousClass1CaughtException r3, CountDownLatch countDownLatch) {
|
|
this.val$result = r1;
|
|
this.val$callable = callable;
|
|
this.val$caughtException = r3;
|
|
this.val$barrier = countDownLatch;
|
|
}
|
|
|
|
/* JADX WARNING: Unknown variable types count: 1 */
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
try {
|
|
this.val$result.value = this.val$callable.call();
|
|
} catch (Exception e) {
|
|
this.val$caughtException.e = e;
|
|
}
|
|
this.val$barrier.countDown();
|
|
}
|
|
}
|
|
|
|
/* renamed from: org.webrtc.ThreadUtils$4 reason: invalid class name */
|
|
public class AnonymousClass4 implements Callable<Void> {
|
|
public final /* synthetic */ Runnable val$runner;
|
|
|
|
public AnonymousClass4(Runnable runnable) {
|
|
this.val$runner = runnable;
|
|
}
|
|
|
|
@Override // java.util.concurrent.Callable
|
|
public Void call() {
|
|
this.val$runner.run();
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public interface BlockingOperation {
|
|
void run() throws InterruptedException;
|
|
}
|
|
|
|
public static class ThreadChecker {
|
|
@Nullable
|
|
private Thread thread = Thread.currentThread();
|
|
|
|
public void checkIsOnValidThread() {
|
|
if (this.thread == null) {
|
|
this.thread = Thread.currentThread();
|
|
}
|
|
if (Thread.currentThread() != this.thread) {
|
|
throw new IllegalStateException("Wrong thread");
|
|
}
|
|
}
|
|
|
|
public void detachThread() {
|
|
this.thread = null;
|
|
}
|
|
}
|
|
|
|
public static void awaitUninterruptibly(CountDownLatch countDownLatch) {
|
|
executeUninterruptibly(new AnonymousClass2(countDownLatch));
|
|
}
|
|
|
|
public static boolean awaitUninterruptibly(CountDownLatch countDownLatch, long j) {
|
|
long elapsedRealtime = SystemClock.elapsedRealtime();
|
|
boolean z2 = false;
|
|
long j2 = j;
|
|
boolean z3 = false;
|
|
do {
|
|
try {
|
|
z2 = countDownLatch.await(j2, TimeUnit.MILLISECONDS);
|
|
break;
|
|
} catch (InterruptedException unused) {
|
|
z3 = true;
|
|
j2 = j - (SystemClock.elapsedRealtime() - elapsedRealtime);
|
|
if (j2 <= 0) {
|
|
}
|
|
}
|
|
} while (j2 <= 0);
|
|
if (z3) {
|
|
Thread.currentThread().interrupt();
|
|
}
|
|
return z2;
|
|
}
|
|
|
|
public static void checkIsOnMainThread() {
|
|
if (Thread.currentThread() != Looper.getMainLooper().getThread()) {
|
|
throw new IllegalStateException("Not on main thread!");
|
|
}
|
|
}
|
|
|
|
public static StackTraceElement[] concatStackTraces(StackTraceElement[] stackTraceElementArr, StackTraceElement[] stackTraceElementArr2) {
|
|
StackTraceElement[] stackTraceElementArr3 = new StackTraceElement[(stackTraceElementArr.length + stackTraceElementArr2.length)];
|
|
System.arraycopy(stackTraceElementArr, 0, stackTraceElementArr3, 0, stackTraceElementArr.length);
|
|
System.arraycopy(stackTraceElementArr2, 0, stackTraceElementArr3, stackTraceElementArr.length, stackTraceElementArr2.length);
|
|
return stackTraceElementArr3;
|
|
}
|
|
|
|
public static void executeUninterruptibly(BlockingOperation blockingOperation) {
|
|
boolean z2 = false;
|
|
while (true) {
|
|
try {
|
|
blockingOperation.run();
|
|
break;
|
|
} catch (InterruptedException unused) {
|
|
z2 = true;
|
|
}
|
|
}
|
|
if (z2) {
|
|
Thread.currentThread().interrupt();
|
|
}
|
|
}
|
|
|
|
public static <V> V invokeAtFrontUninterruptibly(Handler handler, Callable<V> callable) {
|
|
if (handler.getLooper().getThread() == Thread.currentThread()) {
|
|
try {
|
|
return callable.call();
|
|
} catch (Exception e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
} else {
|
|
AnonymousClass1Result r0 = new AnonymousClass1Result();
|
|
AnonymousClass1CaughtException r1 = new AnonymousClass1CaughtException();
|
|
CountDownLatch countDownLatch = new CountDownLatch(1);
|
|
handler.post(new AnonymousClass3(r0, callable, r1, countDownLatch));
|
|
awaitUninterruptibly(countDownLatch);
|
|
if (r1.e == null) {
|
|
return r0.value;
|
|
}
|
|
RuntimeException runtimeException = new RuntimeException(r1.e);
|
|
runtimeException.setStackTrace(concatStackTraces(r1.e.getStackTrace(), runtimeException.getStackTrace()));
|
|
throw runtimeException;
|
|
}
|
|
}
|
|
|
|
public static void invokeAtFrontUninterruptibly(Handler handler, Runnable runnable) {
|
|
invokeAtFrontUninterruptibly(handler, new AnonymousClass4(runnable));
|
|
}
|
|
|
|
public static void joinUninterruptibly(Thread thread) {
|
|
executeUninterruptibly(new AnonymousClass1(thread));
|
|
}
|
|
|
|
public static boolean joinUninterruptibly(Thread thread, long j) {
|
|
long elapsedRealtime = SystemClock.elapsedRealtime();
|
|
boolean z2 = false;
|
|
long j2 = j;
|
|
while (j2 > 0) {
|
|
try {
|
|
thread.join(j2);
|
|
break;
|
|
} catch (InterruptedException unused) {
|
|
j2 = j - (SystemClock.elapsedRealtime() - elapsedRealtime);
|
|
z2 = true;
|
|
}
|
|
}
|
|
if (z2) {
|
|
Thread.currentThread().interrupt();
|
|
}
|
|
return !thread.isAlive();
|
|
}
|
|
}
|