package androidx.core.provider;

import android.os.Handler;
import android.os.Process;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

/* JADX INFO: compiled from: RequestExecutor.java */
/* JADX INFO: loaded from: classes.dex */
class h {

    /* JADX INFO: compiled from: RequestExecutor.java */
    private static class a implements ThreadFactory {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        private String f1782a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        private int f1783b;

        /* JADX INFO: renamed from: androidx.core.provider.h$a$a, reason: collision with other inner class name */
        /* JADX INFO: compiled from: RequestExecutor.java */
        private static class C0015a extends Thread {

            /* JADX INFO: renamed from: e, reason: collision with root package name */
            private final int f1784e;

            C0015a(Runnable runnable, String str, int i3) {
                super(runnable, str);
                this.f1784e = i3;
            }

            @Override // java.lang.Thread, java.lang.Runnable
            public void run() {
                Process.setThreadPriority(this.f1784e);
                super.run();
            }
        }

        a(String str, int i3) {
            this.f1782a = str;
            this.f1783b = i3;
        }

        @Override // java.util.concurrent.ThreadFactory
        public Thread newThread(Runnable runnable) {
            return new C0015a(runnable, this.f1782a, this.f1783b);
        }
    }

    /* JADX INFO: compiled from: RequestExecutor.java */
    private static class b<T> implements Runnable {

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        private Callable<T> f1785e;

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        private androidx.core.util.a<T> f1786f;

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        private Handler f1787g;

        /* JADX INFO: compiled from: RequestExecutor.java */
        class a implements Runnable {

            /* JADX INFO: renamed from: e, reason: collision with root package name */
            final /* synthetic */ androidx.core.util.a f1788e;

            /* JADX INFO: renamed from: f, reason: collision with root package name */
            final /* synthetic */ Object f1789f;

            a(b bVar, androidx.core.util.a aVar, Object obj) {
                this.f1788e = aVar;
                this.f1789f = obj;
            }

            /* JADX WARN: Multi-variable type inference failed */
            @Override // java.lang.Runnable
            public void run() {
                this.f1788e.a(this.f1789f);
            }
        }

        b(Handler handler, Callable<T> callable, androidx.core.util.a<T> aVar) {
            this.f1785e = callable;
            this.f1786f = aVar;
            this.f1787g = handler;
        }

        @Override // java.lang.Runnable
        public void run() {
            T tCall;
            try {
                tCall = this.f1785e.call();
            } catch (Exception unused) {
                tCall = null;
            }
            this.f1787g.post(new a(this, this.f1786f, tCall));
        }
    }

    static ThreadPoolExecutor a(String str, int i3, int i4) {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(0, 1, i4, TimeUnit.MILLISECONDS, new LinkedBlockingDeque(), new a(str, i3));
        threadPoolExecutor.allowCoreThreadTimeOut(true);
        return threadPoolExecutor;
    }

    static <T> void b(Executor executor, Callable<T> callable, androidx.core.util.a<T> aVar) {
        executor.execute(new b(androidx.core.provider.b.a(), callable, aVar));
    }

    static <T> T c(ExecutorService executorService, Callable<T> callable, int i3) throws InterruptedException {
        try {
            return executorService.submit(callable).get(i3, TimeUnit.MILLISECONDS);
        } catch (InterruptedException e3) {
            throw e3;
        } catch (ExecutionException e4) {
            throw new RuntimeException(e4);
        } catch (TimeoutException unused) {
            throw new InterruptedException("timeout");
        }
    }
}
