package cm;

import android.os.Handler;
import android.os.HandlerThread;

/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes3.dex */
public class k {

    /* renamed from: e, reason: collision with root package name */
    private static k f12093e;

    /* renamed from: a, reason: collision with root package name */
    private Handler f12094a;

    /* renamed from: b, reason: collision with root package name */
    private HandlerThread f12095b;

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

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

    private k() {
    }

    private void a() {
        synchronized (this.f12097d) {
            if (this.f12094a == null) {
                if (this.f12096c <= 0) {
                    throw new IllegalStateException("CameraThread is not open");
                }
                HandlerThread handlerThread = new HandlerThread("CameraThread");
                this.f12095b = handlerThread;
                handlerThread.start();
                this.f12094a = new Handler(this.f12095b.getLooper());
            }
        }
    }

    public static k d() {
        if (f12093e == null) {
            f12093e = new k();
        }
        return f12093e;
    }

    private void f() {
        synchronized (this.f12097d) {
            this.f12095b.quit();
            this.f12095b = null;
            this.f12094a = null;
        }
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public void b() {
        synchronized (this.f12097d) {
            int i10 = this.f12096c - 1;
            this.f12096c = i10;
            if (i10 == 0) {
                f();
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public void c(Runnable runnable) {
        synchronized (this.f12097d) {
            a();
            this.f12094a.post(runnable);
        }
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public void e(Runnable runnable) {
        synchronized (this.f12097d) {
            this.f12096c++;
            c(runnable);
        }
    }
}
