package p138.p176.p177.p242.p246.p249;

import android.content.ComponentName;
import android.content.Context;
import android.content.ServiceConnection;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import java.util.HashMap;
import javax.annotation.concurrent.GuardedBy;
import p000.p001.p002.p003.p004.C0567;
import p138.p176.p177.p242.p246.p249.AbstractC4269;
import p138.p176.p177.p242.p246.p252.C4306;
import p138.p176.p177.p242.p258.p261.HandlerC4360;

/* JADX INFO: renamed from: ދ.ހ.֏.ހ.ހ.ފ.ޖ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public final class C4291 extends AbstractC4269 implements Handler.Callback {

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public final Context f13573;

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public final Handler f13574;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    @GuardedBy("mConnectionStatus")
    public final HashMap<AbstractC4269.C4270, ServiceConnectionC4292> f13572 = new HashMap<>();

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    public final C4306 f13575 = C4306.m7206();

    /* JADX INFO: renamed from: މ, reason: contains not printable characters */
    public final long f13576 = 5000;

    /* JADX INFO: renamed from: ފ, reason: contains not printable characters */
    public final long f13577 = 300000;

    public C4291(Context context) {
        this.f13573 = context.getApplicationContext();
        this.f13574 = new HandlerC4360(context.getMainLooper(), this);
    }

    @Override // android.os.Handler.Callback
    public final boolean handleMessage(Message message) {
        int i = message.what;
        if (i == 0) {
            synchronized (this.f13572) {
                AbstractC4269.C4270 c4270 = (AbstractC4269.C4270) message.obj;
                ServiceConnectionC4292 serviceConnectionC4292 = this.f13572.get(c4270);
                if (serviceConnectionC4292 != null && serviceConnectionC4292.f13578.isEmpty()) {
                    if (serviceConnectionC4292.f13580) {
                        serviceConnectionC4292.f13584.f13574.removeMessages(1, serviceConnectionC4292.f13582);
                        C4291 c4291 = serviceConnectionC4292.f13584;
                        C4306 c4306 = c4291.f13575;
                        Context context = c4291.f13573;
                        if (c4306 == null) {
                            throw null;
                        }
                        context.unbindService(serviceConnectionC4292);
                        serviceConnectionC4292.f13580 = false;
                        serviceConnectionC4292.f13579 = 2;
                    }
                    this.f13572.remove(c4270);
                }
            }
            return true;
        }
        if (i != 1) {
            return false;
        }
        synchronized (this.f13572) {
            AbstractC4269.C4270 c42702 = (AbstractC4269.C4270) message.obj;
            ServiceConnectionC4292 serviceConnectionC42922 = this.f13572.get(c42702);
            if (serviceConnectionC42922 != null && serviceConnectionC42922.f13579 == 3) {
                String strValueOf = String.valueOf(c42702);
                StringBuilder sb = new StringBuilder(strValueOf.length() + 47);
                sb.append("Timeout waiting for ServiceConnection callback ");
                sb.append(strValueOf);
                Log.e("GmsClientSupervisor", sb.toString(), new Exception());
                ComponentName componentName = serviceConnectionC42922.f13583;
                if (componentName == null) {
                    componentName = c42702.f13551;
                }
                if (componentName == null) {
                    componentName = new ComponentName(c42702.f13550, "unknown");
                }
                serviceConnectionC42922.onServiceDisconnected(componentName);
            }
        }
        return true;
    }

    @Override // p138.p176.p177.p242.p246.p249.AbstractC4269
    /* JADX INFO: renamed from: ֏ */
    public final boolean mo6954(AbstractC4269.C4270 c4270, ServiceConnection serviceConnection, String str) {
        boolean z;
        C0567.m1857(serviceConnection, (Object) "ServiceConnection must not be null");
        synchronized (this.f13572) {
            ServiceConnectionC4292 serviceConnectionC4292 = this.f13572.get(c4270);
            if (serviceConnectionC4292 == null) {
                serviceConnectionC4292 = new ServiceConnectionC4292(this, c4270);
                C4306 c4306 = serviceConnectionC4292.f13584.f13575;
                serviceConnectionC4292.f13582.m6956();
                serviceConnectionC4292.f13578.add(serviceConnection);
                serviceConnectionC4292.m6964(str);
                this.f13572.put(c4270, serviceConnectionC4292);
            } else {
                this.f13574.removeMessages(0, c4270);
                if (serviceConnectionC4292.f13578.contains(serviceConnection)) {
                    String strValueOf = String.valueOf(c4270);
                    StringBuilder sb = new StringBuilder(strValueOf.length() + 81);
                    sb.append("Trying to bind a GmsServiceConnection that was already connected before.  config=");
                    sb.append(strValueOf);
                    throw new IllegalStateException(sb.toString());
                }
                C4306 c43062 = serviceConnectionC4292.f13584.f13575;
                serviceConnectionC4292.f13582.m6956();
                serviceConnectionC4292.f13578.add(serviceConnection);
                int i = serviceConnectionC4292.f13579;
                if (i == 1) {
                    serviceConnection.onServiceConnected(serviceConnectionC4292.f13583, serviceConnectionC4292.f13581);
                } else if (i == 2) {
                    serviceConnectionC4292.m6964(str);
                }
            }
            z = serviceConnectionC4292.f13580;
        }
        return z;
    }

    @Override // p138.p176.p177.p242.p246.p249.AbstractC4269
    /* JADX INFO: renamed from: ؠ */
    public final void mo6955(AbstractC4269.C4270 c4270, ServiceConnection serviceConnection, String str) {
        C0567.m1857(serviceConnection, (Object) "ServiceConnection must not be null");
        synchronized (this.f13572) {
            ServiceConnectionC4292 serviceConnectionC4292 = this.f13572.get(c4270);
            if (serviceConnectionC4292 == null) {
                String strValueOf = String.valueOf(c4270);
                StringBuilder sb = new StringBuilder(strValueOf.length() + 50);
                sb.append("Nonexistent connection status for service config: ");
                sb.append(strValueOf);
                throw new IllegalStateException(sb.toString());
            }
            if (!serviceConnectionC4292.f13578.contains(serviceConnection)) {
                String strValueOf2 = String.valueOf(c4270);
                StringBuilder sb2 = new StringBuilder(strValueOf2.length() + 76);
                sb2.append("Trying to unbind a GmsServiceConnection  that was not bound before.  config=");
                sb2.append(strValueOf2);
                throw new IllegalStateException(sb2.toString());
            }
            C4306 c4306 = serviceConnectionC4292.f13584.f13575;
            serviceConnectionC4292.f13578.remove(serviceConnection);
            if (serviceConnectionC4292.f13578.isEmpty()) {
                this.f13574.sendMessageDelayed(this.f13574.obtainMessage(0, c4270), this.f13576);
            }
        }
    }
}
