package b0;

import L1.A;
import a.AbstractC0212a;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Handler;
import androidx.lifecycle.G;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import p0.AbstractC0928a;

/* JADX INFO: loaded from: classes.dex */
public final class o implements i {

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

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public final M.e f4658l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final A f4659m;

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

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public Handler f4661o;
    public ThreadPoolExecutor p;
    public ThreadPoolExecutor q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public AbstractC0212a f4662r;

    public o(Context context, M.e eVar) {
        A a5 = p.f4663d;
        this.f4660n = new Object();
        S4.d.h("Context cannot be null", context);
        this.f4657k = context.getApplicationContext();
        this.f4658l = eVar;
        this.f4659m = a5;
    }

    public final void a() {
        synchronized (this.f4660n) {
            try {
                this.f4662r = null;
                Handler handler = this.f4661o;
                if (handler != null) {
                    handler.removeCallbacks(null);
                }
                this.f4661o = null;
                ThreadPoolExecutor threadPoolExecutor = this.q;
                if (threadPoolExecutor != null) {
                    threadPoolExecutor.shutdown();
                }
                this.p = null;
                this.q = null;
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    @Override // b0.i
    public final void b(AbstractC0212a abstractC0212a) {
        synchronized (this.f4660n) {
            this.f4662r = abstractC0212a;
        }
        synchronized (this.f4660n) {
            try {
                if (this.f4662r == null) {
                    return;
                }
                if (this.p == null) {
                    ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(0, 1, 15L, TimeUnit.SECONDS, new LinkedBlockingDeque(), new ThreadFactoryC0322a("emojiCompat"));
                    threadPoolExecutor.allowCoreThreadTimeOut(true);
                    this.q = threadPoolExecutor;
                    this.p = threadPoolExecutor;
                }
                this.p.execute(new G(1, this));
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final M.k c() {
        try {
            A a5 = this.f4659m;
            Context context = this.f4657k;
            M.e eVar = this.f4658l;
            a5.getClass();
            Object[] objArr = {eVar};
            ArrayList arrayList = new ArrayList(1);
            Object obj = objArr[0];
            Objects.requireNonNull(obj);
            arrayList.add(obj);
            M.j jVarA = M.d.a(context, Collections.unmodifiableList(arrayList));
            int i = jVarA.f2135k;
            if (i != 0) {
                throw new RuntimeException(AbstractC0928a.j(i, "fetchFonts failed (", ")"));
            }
            M.k[] kVarArr = (M.k[]) ((List) jVarA.f2136l).get(0);
            if (kVarArr == null || kVarArr.length == 0) {
                throw new RuntimeException("fetchFonts failed (empty result)");
            }
            return kVarArr[0];
        } catch (PackageManager.NameNotFoundException e2) {
            throw new RuntimeException("provider not found", e2);
        }
    }
}
