package bk;

import android.content.Context;
import android.content.ServiceConnection;
import android.os.IInterface;
import java.util.concurrent.atomic.AtomicInteger;

/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes3.dex */
public final class c0 extends y {

    /* renamed from: q, reason: collision with root package name */
    final /* synthetic */ d f6937q;

    /* JADX INFO: Access modifiers changed from: package-private */
    public c0(d dVar) {
        this.f6937q = dVar;
    }

    @Override // bk.y
    public final void b() {
        Object obj;
        AtomicInteger atomicInteger;
        IInterface iInterface;
        x xVar;
        Context context;
        ServiceConnection serviceConnection;
        AtomicInteger atomicInteger2;
        x xVar2;
        obj = this.f6937q.f6944f;
        synchronized (obj) {
            atomicInteger = this.f6937q.f6950l;
            if (atomicInteger.get() > 0) {
                atomicInteger2 = this.f6937q.f6950l;
                if (atomicInteger2.decrementAndGet() > 0) {
                    xVar2 = this.f6937q.f6940b;
                    xVar2.c("Leaving the connection open for other ongoing calls.", new Object[0]);
                    return;
                }
            }
            d dVar = this.f6937q;
            iInterface = dVar.f6952n;
            if (iInterface != null) {
                xVar = dVar.f6940b;
                xVar.c("Unbind from service.", new Object[0]);
                d dVar2 = this.f6937q;
                context = dVar2.f6939a;
                serviceConnection = dVar2.f6951m;
                context.unbindService(serviceConnection);
                this.f6937q.f6945g = false;
                this.f6937q.f6952n = null;
                this.f6937q.f6951m = null;
            }
            this.f6937q.x();
        }
    }
}
