package com.google.android.gms.common.internal;

import android.content.Context;
import android.content.ServiceConnection;
import android.os.Looper;
import androidx.annotation.Nullable;
import java.util.HashMap;
import java.util.concurrent.Executor;

/* JADX INFO: loaded from: classes2.dex */
public final class g1 extends m {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final HashMap f8338b = new HashMap();

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public volatile o8.e f8340d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final h8.a f8341e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final long f8342f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final long f8343g;

    @Nullable
    private volatile Executor zzi;

    public g1(Context context, Looper looper, @Nullable Executor executor) {
        l5.i iVar = new l5.i(this);
        this.f8339c = context.getApplicationContext();
        this.f8340d = new o8.e(looper, iVar, 2);
        this.f8341e = h8.a.b();
        this.f8342f = 5000L;
        this.f8343g = 300000L;
        this.zzi = executor;
    }

    @Override // com.google.android.gms.common.internal.m
    public final e8.b zza(e1 e1Var, ServiceConnection serviceConnection, String str, @Nullable Executor executor) {
        e8.b bVarA;
        if (serviceConnection == null) {
            throw new NullPointerException("ServiceConnection must not be null");
        }
        HashMap map = this.f8338b;
        synchronized (map) {
            try {
                f1 f1Var = (f1) map.get(e1Var);
                if (executor == null) {
                    executor = this.zzi;
                }
                if (f1Var == null) {
                    f1Var = new f1(this, e1Var);
                    f1Var.f8330a.put(serviceConnection, serviceConnection);
                    bVarA = f1Var.a(str, executor);
                    map.put(e1Var, f1Var);
                } else {
                    this.f8340d.removeMessages(0, e1Var);
                    if (f1Var.f8330a.containsKey(serviceConnection)) {
                        String string = e1Var.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());
                    }
                    f1Var.f8330a.put(serviceConnection, serviceConnection);
                    int i10 = f1Var.f8331b;
                    if (i10 == 1) {
                        serviceConnection.onServiceConnected(f1Var.f8334e, f1Var.zzh());
                    } else if (i10 == 2) {
                        bVarA = f1Var.a(str, executor);
                    }
                    bVarA = null;
                }
                if (f1Var.f8332c) {
                    return e8.b.f25512c;
                }
                if (bVarA == null) {
                    bVarA = new e8.b(-1, null, null);
                }
                return bVarA;
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final void zze(@Nullable Executor executor) {
        synchronized (this.f8338b) {
            this.zzi = executor;
        }
    }
}
