package oh;

import android.os.Process;
import android.os.StrictMode;
import android.text.TextUtils;
import android.util.Log;
import com.google.android.gms.common.api.Api;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/* loaded from: classes4.dex */
public final class a implements ExecutorService {

    /* renamed from: q, reason: collision with root package name */
    private static final long f31435q = TimeUnit.SECONDS.toMillis(10);

    /* renamed from: r, reason: collision with root package name */
    private static volatile int f31436r;

    /* renamed from: p, reason: collision with root package name */
    private final ExecutorService f31437p;

    /* loaded from: classes4.dex */
    public static final class b {

        /* renamed from: a, reason: collision with root package name */
        private final boolean f31438a;

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

        /* renamed from: c, reason: collision with root package name */
        private int f31440c;

        /* renamed from: d, reason: collision with root package name */
        private final ThreadFactory f31441d = new c();

        /* renamed from: e, reason: collision with root package name */
        private e f31442e = e.f31456d;

        /* renamed from: f, reason: collision with root package name */
        private String f31443f;

        /* renamed from: g, reason: collision with root package name */
        private long f31444g;

        b(boolean z10) {
            this.f31438a = z10;
        }

        public a a() {
            if (TextUtils.isEmpty(this.f31443f)) {
                throw new IllegalArgumentException("Name must be non-null and non-empty, but given: " + this.f31443f);
            }
            ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(this.f31439b, this.f31440c, this.f31444g, TimeUnit.MILLISECONDS, new PriorityBlockingQueue(), new d(this.f31441d, this.f31443f, this.f31442e, this.f31438a));
            if (this.f31444g != 0) {
                threadPoolExecutor.allowCoreThreadTimeOut(true);
            }
            return new a(threadPoolExecutor);
        }

        public b b(String str) {
            this.f31443f = str;
            return this;
        }

        public b c(int i10) {
            this.f31439b = i10;
            this.f31440c = i10;
            return this;
        }
    }

    /* loaded from: classes4.dex */
    private static final class c implements ThreadFactory {

        /* renamed from: oh.a$c$a, reason: collision with other inner class name */
        /* loaded from: classes4.dex */
        class C0721a extends Thread {
            C0721a(Runnable runnable) {
                super(runnable);
            }

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

        private c() {
        }

        @Override // java.util.concurrent.ThreadFactory
        public Thread newThread(Runnable runnable) {
            return new C0721a(runnable);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes4.dex */
    public static final class d implements ThreadFactory {

        /* renamed from: a, reason: collision with root package name */
        private final ThreadFactory f31446a;

        /* renamed from: b, reason: collision with root package name */
        private final String f31447b;

        /* renamed from: c, reason: collision with root package name */
        final e f31448c;

        /* renamed from: d, reason: collision with root package name */
        final boolean f31449d;

        /* renamed from: e, reason: collision with root package name */
        private final AtomicInteger f31450e = new AtomicInteger();

        /* renamed from: oh.a$d$a, reason: collision with other inner class name */
        /* loaded from: classes4.dex */
        class RunnableC0722a implements Runnable {

            /* renamed from: p, reason: collision with root package name */
            final /* synthetic */ Runnable f31451p;

            RunnableC0722a(Runnable runnable) {
                this.f31451p = runnable;
            }

            @Override // java.lang.Runnable
            public void run() {
                if (d.this.f31449d) {
                    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectNetwork().penaltyDeath().build());
                }
                try {
                    this.f31451p.run();
                } catch (Throwable th2) {
                    d.this.f31448c.a(th2);
                }
            }
        }

        d(ThreadFactory threadFactory, String str, e eVar, boolean z10) {
            this.f31446a = threadFactory;
            this.f31447b = str;
            this.f31448c = eVar;
            this.f31449d = z10;
        }

        @Override // java.util.concurrent.ThreadFactory
        public Thread newThread(Runnable runnable) {
            Thread newThread = this.f31446a.newThread(new RunnableC0722a(runnable));
            newThread.setName("glide-" + this.f31447b + "-thread-" + this.f31450e.getAndIncrement());
            return newThread;
        }
    }

    /* loaded from: classes4.dex */
    public interface e {

        /* renamed from: a, reason: collision with root package name */
        public static final e f31453a = new C0723a();

        /* renamed from: b, reason: collision with root package name */
        public static final e f31454b;

        /* renamed from: c, reason: collision with root package name */
        public static final e f31455c;

        /* renamed from: d, reason: collision with root package name */
        public static final e f31456d;

        /* renamed from: oh.a$e$a, reason: collision with other inner class name */
        /* loaded from: classes4.dex */
        class C0723a implements e {
            C0723a() {
            }

            @Override // oh.a.e
            public void a(Throwable th2) {
            }
        }

        /* loaded from: classes4.dex */
        class b implements e {
            b() {
            }

            @Override // oh.a.e
            public void a(Throwable th2) {
                if (th2 == null || !Log.isLoggable("GlideExecutor", 6)) {
                    return;
                }
                Log.e("GlideExecutor", "Request threw uncaught throwable", th2);
            }
        }

        /* loaded from: classes4.dex */
        class c implements e {
            c() {
            }

            @Override // oh.a.e
            public void a(Throwable th2) {
                if (th2 != null) {
                    throw new RuntimeException("Request threw uncaught throwable", th2);
                }
            }
        }

        static {
            b bVar = new b();
            f31454b = bVar;
            f31455c = new c();
            f31456d = bVar;
        }

        void a(Throwable th2);
    }

    a(ExecutorService executorService) {
        this.f31437p = executorService;
    }

    static int a() {
        return b() >= 4 ? 2 : 1;
    }

    public static int b() {
        if (f31436r == 0) {
            f31436r = Math.min(4, oh.b.a());
        }
        return f31436r;
    }

    public static b c() {
        return new b(true).c(a()).b("animation");
    }

    public static a d() {
        return c().a();
    }

    public static b f() {
        return new b(true).c(1).b("disk-cache");
    }

    public static a g() {
        return f().a();
    }

    public static b h() {
        return new b(false).c(b()).b("source");
    }

    public static a i() {
        return h().a();
    }

    public static a j() {
        return new a(new ThreadPoolExecutor(0, Api.BaseClientBuilder.API_PRIORITY_OTHER, f31435q, TimeUnit.MILLISECONDS, new SynchronousQueue(), new d(new c(), "source-unlimited", e.f31456d, false)));
    }

    @Override // java.util.concurrent.ExecutorService
    public boolean awaitTermination(long j10, TimeUnit timeUnit) {
        return this.f31437p.awaitTermination(j10, timeUnit);
    }

    @Override // java.util.concurrent.Executor
    public void execute(Runnable runnable) {
        this.f31437p.execute(runnable);
    }

    @Override // java.util.concurrent.ExecutorService
    public List invokeAll(Collection collection) {
        return this.f31437p.invokeAll(collection);
    }

    @Override // java.util.concurrent.ExecutorService
    public Object invokeAny(Collection collection) {
        return this.f31437p.invokeAny(collection);
    }

    @Override // java.util.concurrent.ExecutorService
    public boolean isShutdown() {
        return this.f31437p.isShutdown();
    }

    @Override // java.util.concurrent.ExecutorService
    public boolean isTerminated() {
        return this.f31437p.isTerminated();
    }

    @Override // java.util.concurrent.ExecutorService
    public void shutdown() {
        this.f31437p.shutdown();
    }

    @Override // java.util.concurrent.ExecutorService
    public List shutdownNow() {
        return this.f31437p.shutdownNow();
    }

    @Override // java.util.concurrent.ExecutorService
    public Future submit(Runnable runnable) {
        return this.f31437p.submit(runnable);
    }

    public String toString() {
        return this.f31437p.toString();
    }

    @Override // java.util.concurrent.ExecutorService
    public List invokeAll(Collection collection, long j10, TimeUnit timeUnit) {
        return this.f31437p.invokeAll(collection, j10, timeUnit);
    }

    @Override // java.util.concurrent.ExecutorService
    public Object invokeAny(Collection collection, long j10, TimeUnit timeUnit) {
        return this.f31437p.invokeAny(collection, j10, timeUnit);
    }

    @Override // java.util.concurrent.ExecutorService
    public Future submit(Runnable runnable, Object obj) {
        return this.f31437p.submit(runnable, obj);
    }

    @Override // java.util.concurrent.ExecutorService
    public Future submit(Callable callable) {
        return this.f31437p.submit(callable);
    }
}
