package defpackage;

import android.content.Context;
import android.content.ServiceConnection;
import android.os.HandlerThread;
import android.os.Looper;
import java.util.HashMap;
import java.util.concurrent.Executor;

/* renamed from: ᵛⁱˋ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C2782 {

    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    public static final Object f10717 = new Object();

    /* renamed from: ᵝᵵᵺ, reason: contains not printable characters */
    public static HandlerThread f10718;

    /* renamed from: ᵹᵝᵶ, reason: contains not printable characters */
    public static C2782 f10719;

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public final long f10720;

    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public final long f10721;

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public volatile HandlerC5094 f10722;

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final HashMap f10723 = new HashMap();

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final Context f10724;

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public final C3580 f10725;

    public C2782(Context context, Looper looper) {
        C0824 c0824 = new C0824(2, this);
        this.f10724 = context.getApplicationContext();
        HandlerC5094 handlerC5094 = new HandlerC5094(looper, c0824);
        Looper.getMainLooper();
        this.f10722 = handlerC5094;
        this.f10725 = C3580.m8186();
        this.f10720 = 5000L;
        this.f10721 = 300000L;
    }

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public static C2782 m6867(Context context) {
        synchronized (f10717) {
            try {
                if (f10719 == null) {
                    f10719 = new C2782(context.getApplicationContext(), context.getMainLooper());
                }
            } catch (Throwable th) {
                throw th;
            }
        }
        return f10719;
    }

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public static HandlerThread m6868() {
        synchronized (f10717) {
            try {
                HandlerThread handlerThread = f10718;
                if (handlerThread != null) {
                    return handlerThread;
                }
                HandlerThread handlerThread2 = new HandlerThread("GoogleApiHandler", 9);
                f10718 = handlerThread2;
                handlerThread2.start();
                return f10718;
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final C0548 m6869(C2224 c2224, ServiceConnectionC3772 serviceConnectionC3772, String str, Executor executor) {
        C0548 c0548M3687;
        HashMap map = this.f10723;
        synchronized (map) {
            try {
                ServiceConnectionC1180 serviceConnectionC1180 = (ServiceConnectionC1180) map.get(c2224);
                if (executor == null) {
                    executor = null;
                }
                if (serviceConnectionC1180 == null) {
                    serviceConnectionC1180 = new ServiceConnectionC1180(this, c2224);
                    serviceConnectionC1180.f5015.put(serviceConnectionC3772, serviceConnectionC3772);
                    c0548M3687 = serviceConnectionC1180.m3687(str, executor);
                    map.put(c2224, serviceConnectionC1180);
                } else {
                    this.f10722.removeMessages(0, c2224);
                    if (serviceConnectionC1180.f5015.containsKey(serviceConnectionC3772)) {
                        String string = c2224.toString();
                        StringBuilder sb = new StringBuilder(string.length() + 81);
                        sb.append("Trying to bind a GmsServiceConnection that was already connected before.  config=");
                        sb.append(string);
                        throw new IllegalStateException(sb.toString());
                    }
                    serviceConnectionC1180.f5015.put(serviceConnectionC3772, serviceConnectionC3772);
                    int i = serviceConnectionC1180.f5013;
                    if (i == 1) {
                        serviceConnectionC3772.onServiceConnected(serviceConnectionC1180.f5012, serviceConnectionC1180.f5016);
                    } else if (i == 2) {
                        c0548M3687 = serviceConnectionC1180.m3687(str, executor);
                    }
                    c0548M3687 = null;
                }
                if (serviceConnectionC1180.f5017) {
                    return C0548.f2845;
                }
                if (c0548M3687 == null) {
                    c0548M3687 = new C0548(-1, null, null);
                }
                return c0548M3687;
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public final void m6870(String str, ServiceConnection serviceConnection, boolean z) {
        C2224 c2224 = new C2224(str, z);
        ᵩʛʽ.ᵶᵷᵕ(serviceConnection, "ServiceConnection must not be null");
        HashMap map = this.f10723;
        synchronized (map) {
            try {
                ServiceConnectionC1180 serviceConnectionC1180 = (ServiceConnectionC1180) map.get(c2224);
                if (serviceConnectionC1180 == null) {
                    String string = c2224.toString();
                    StringBuilder sb = new StringBuilder(string.length() + 50);
                    sb.append("Nonexistent connection status for service config: ");
                    sb.append(string);
                    throw new IllegalStateException(sb.toString());
                }
                if (!serviceConnectionC1180.f5015.containsKey(serviceConnection)) {
                    String string2 = c2224.toString();
                    StringBuilder sb2 = new StringBuilder(string2.length() + 76);
                    sb2.append("Trying to unbind a GmsServiceConnection  that was not bound before.  config=");
                    sb2.append(string2);
                    throw new IllegalStateException(sb2.toString());
                }
                serviceConnectionC1180.f5015.remove(serviceConnection);
                if (serviceConnectionC1180.f5015.isEmpty()) {
                    this.f10722.sendMessageDelayed(this.f10722.obtainMessage(0, c2224), this.f10720);
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }
}
