package c0;

import A1.C0005f;
import B0.RunnableC0014a;
import P2.C0253j;
import a.AbstractC0386a;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Handler;
import com.google.android.gms.internal.measurement.C1;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Objects;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/* JADX INFO: loaded from: classes.dex */
public final class n implements InterfaceC0571h {

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public final Context f9311q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public final J.e f9312r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public final C0253j f9313s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public final Object f9314t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public Handler f9315u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public ThreadPoolExecutor f9316v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public ThreadPoolExecutor f9317w;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public C1 f9318x;

    public n(Context context, J.e eVar) {
        C0253j c0253j = o.f9319d;
        this.f9314t = new Object();
        AbstractC0386a.j(context, "Context cannot be null");
        this.f9311q = context.getApplicationContext();
        this.f9312r = eVar;
        this.f9313s = c0253j;
    }

    @Override // c0.InterfaceC0571h
    public final void a(C1 c12) {
        synchronized (this.f9314t) {
            this.f9318x = c12;
        }
        c();
    }

    public final void b() {
        synchronized (this.f9314t) {
            try {
                this.f9318x = null;
                Handler handler = this.f9315u;
                if (handler != null) {
                    handler.removeCallbacks(null);
                }
                this.f9315u = null;
                ThreadPoolExecutor threadPoolExecutor = this.f9317w;
                if (threadPoolExecutor != null) {
                    threadPoolExecutor.shutdown();
                }
                this.f9316v = null;
                this.f9317w = null;
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final void c() {
        synchronized (this.f9314t) {
            try {
                if (this.f9318x == null) {
                    return;
                }
                if (this.f9316v == null) {
                    ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(0, 1, 15L, TimeUnit.SECONDS, new LinkedBlockingDeque(), new ThreadFactoryC0564a(0, "emojiCompat"));
                    threadPoolExecutor.allowCoreThreadTimeOut(true);
                    this.f9317w = threadPoolExecutor;
                    this.f9316v = threadPoolExecutor;
                }
                this.f9316v.execute(new RunnableC0014a(17, this));
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final J.j d() {
        try {
            C0253j c0253j = this.f9313s;
            Context context = this.f9311q;
            J.e eVar = this.f9312r;
            c0253j.getClass();
            Object[] objArr = {eVar};
            ArrayList arrayList = new ArrayList(1);
            Object obj = objArr[0];
            Objects.requireNonNull(obj);
            arrayList.add(obj);
            C0005f c0005fA = J.d.a(context, Collections.unmodifiableList(arrayList));
            int i = c0005fA.f155a;
            if (i != 0) {
                throw new RuntimeException(I1.a.k(i, "fetchFonts failed (", ")"));
            }
            J.j[] jVarArr = (J.j[]) c0005fA.f156b.get(0);
            if (jVarArr == null || jVarArr.length == 0) {
                throw new RuntimeException("fetchFonts failed (empty result)");
            }
            return jVarArr[0];
        } catch (PackageManager.NameNotFoundException e8) {
            throw new RuntimeException("provider not found", e8);
        }
    }
}
