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

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Build;
import android.os.IBinder;
import android.os.StrictMode;
import androidx.annotation.Nullable;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Objects;
import java.util.concurrent.Executor;

/* JADX INFO: loaded from: classes2.dex */
public final class f1 implements ServiceConnection {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final HashMap f8330a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public int f8331b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public boolean f8332c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final e1 f8333d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public ComponentName f8334e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final /* synthetic */ g1 f8335f;

    @Nullable
    private IBinder zze;

    public f1(g1 g1Var, e1 e1Var) {
        Objects.requireNonNull(g1Var);
        this.f8335f = g1Var;
        this.f8333d = e1Var;
        this.f8330a = new HashMap();
        this.f8331b = 2;
    }

    public final e8.b a(String str, Executor executor) {
        e8.b bVar;
        try {
            Intent intentA = v0.a(this.f8335f.f8339c, this.f8333d);
            this.f8331b = 3;
            StrictMode.VmPolicy vmPolicy = StrictMode.getVmPolicy();
            if (Build.VERSION.SDK_INT >= 31) {
                StrictMode.setVmPolicy(i8.k.a(new StrictMode.VmPolicy.Builder(vmPolicy)).build());
            }
            try {
                g1 g1Var = this.f8335f;
                h8.a aVar = g1Var.f8341e;
                Context context = g1Var.f8339c;
                e1 e1Var = this.f8333d;
                boolean zD = aVar.d(context, str, intentA, this, 4225, executor);
                this.f8332c = zD;
                if (zD) {
                    g1Var.f8340d.sendMessageDelayed(g1Var.f8340d.obtainMessage(1, e1Var), g1Var.f8343g);
                    bVar = e8.b.f25512c;
                } else {
                    this.f8331b = 2;
                    try {
                        g1Var.f8341e.c(g1Var.f8339c, this);
                    } catch (IllegalArgumentException unused) {
                    }
                    bVar = new e8.b(16, null, null);
                }
                return bVar;
            } finally {
                StrictMode.setVmPolicy(vmPolicy);
            }
        } catch (zzaf e10) {
            return e10.zza;
        }
    }

    @Override // android.content.ServiceConnection
    public final void onBindingDied(ComponentName componentName) {
        onServiceDisconnected(componentName);
    }

    @Override // android.content.ServiceConnection
    public final void onServiceConnected(ComponentName componentName, IBinder iBinder) {
        g1 g1Var = this.f8335f;
        synchronized (g1Var.f8338b) {
            try {
                g1Var.f8340d.removeMessages(1, this.f8333d);
                this.zze = iBinder;
                this.f8334e = componentName;
                Iterator it = this.f8330a.values().iterator();
                while (it.hasNext()) {
                    ((ServiceConnection) it.next()).onServiceConnected(componentName, iBinder);
                }
                this.f8331b = 1;
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    @Override // android.content.ServiceConnection
    public final void onServiceDisconnected(ComponentName componentName) {
        g1 g1Var = this.f8335f;
        synchronized (g1Var.f8338b) {
            try {
                g1Var.f8340d.removeMessages(1, this.f8333d);
                this.zze = null;
                this.f8334e = componentName;
                Iterator it = this.f8330a.values().iterator();
                while (it.hasNext()) {
                    ((ServiceConnection) it.next()).onServiceDisconnected(componentName);
                }
                this.f8331b = 2;
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    @Nullable
    public final IBinder zzh() {
        return this.zze;
    }
}
