package T1;

import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Handler;
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;

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

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final C1.f f6607b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final u4.c f6608c;

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

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

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

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

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public L4.a f6613h;

    public o(Context context, C1.f fVar) {
        u4.c cVar = p.f6614d;
        this.f6609d = new Object();
        A4.g.n(context, "Context cannot be null");
        this.f6606a = context.getApplicationContext();
        this.f6607b = fVar;
        this.f6608c = cVar;
    }

    @Override // T1.g
    public final void a(L4.a aVar) {
        synchronized (this.f6609d) {
            this.f6613h = aVar;
        }
        synchronized (this.f6609d) {
            try {
                if (this.f6613h == null) {
                    return;
                }
                if (this.f6611f == null) {
                    ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(0, 1, 15L, TimeUnit.SECONDS, new LinkedBlockingDeque(), new a("emojiCompat", 0));
                    threadPoolExecutor.allowCoreThreadTimeOut(true);
                    this.f6612g = threadPoolExecutor;
                    this.f6611f = threadPoolExecutor;
                }
                this.f6611f.execute(new F1.r(this, 3));
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final void b() {
        synchronized (this.f6609d) {
            try {
                this.f6613h = null;
                Handler handler = this.f6610e;
                if (handler != null) {
                    handler.removeCallbacks(null);
                }
                this.f6610e = null;
                ThreadPoolExecutor threadPoolExecutor = this.f6612g;
                if (threadPoolExecutor != null) {
                    threadPoolExecutor.shutdown();
                }
                this.f6611f = null;
                this.f6612g = null;
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final C1.l c() {
        try {
            u4.c cVar = this.f6608c;
            Context context = this.f6606a;
            C1.f fVar = this.f6607b;
            cVar.getClass();
            Object[] objArr = {fVar};
            ArrayList arrayList = new ArrayList(1);
            Object obj = objArr[0];
            Objects.requireNonNull(obj);
            arrayList.add(obj);
            C1.k kVarA = C1.e.a(context, Collections.unmodifiableList(arrayList));
            int i6 = kVarA.f690b;
            if (i6 != 0) {
                throw new RuntimeException(Z0.o.j(i6, "fetchFonts failed (", ")"));
            }
            C1.l[] lVarArr = (C1.l[]) ((List) kVarA.f691c).get(0);
            if (lVarArr == null || lVarArr.length == 0) {
                throw new RuntimeException("fetchFonts failed (empty result)");
            }
            return lVarArr[0];
        } catch (PackageManager.NameNotFoundException e6) {
            throw new RuntimeException("provider not found", e6);
        }
    }
}
