package com.google.android.gms.common.internal; import android.content.ComponentName; import android.content.Context; import android.content.ServiceConnection; import android.os.Handler; import android.os.IBinder; import android.os.Message; import android.os.StrictMode; import androidx.annotation.Nullable; import com.google.android.gms.common.stats.ConnectionTracker; import com.google.android.gms.common.util.PlatformVersion; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.concurrent.Executor; /* loaded from: classes2.dex */ final class zzp implements ServiceConnection, zzt { final /* synthetic */ zzs zza; private final Map zzb = new HashMap(); private int zzc = 2; private boolean zzd; @Nullable private IBinder zze; private final zzo zzf; private ComponentName zzg; public zzp(zzs zzsVar, zzo zzoVar) { this.zza = zzsVar; this.zzf = zzoVar; } @Override // android.content.ServiceConnection public final void onBindingDied(ComponentName componentName) { onServiceDisconnected(componentName); } @Override // android.content.ServiceConnection public final void onServiceConnected(ComponentName componentName, IBinder iBinder) { HashMap hashMap; Handler handler; hashMap = this.zza.zzb; synchronized (hashMap) { try { handler = this.zza.zzd; handler.removeMessages(1, this.zzf); this.zze = iBinder; this.zzg = componentName; Iterator it = this.zzb.values().iterator(); while (it.hasNext()) { ((ServiceConnection) it.next()).onServiceConnected(componentName, iBinder); } this.zzc = 1; } catch (Throwable th) { throw th; } } } @Override // android.content.ServiceConnection public final void onServiceDisconnected(ComponentName componentName) { HashMap hashMap; Handler handler; hashMap = this.zza.zzb; synchronized (hashMap) { try { handler = this.zza.zzd; handler.removeMessages(1, this.zzf); this.zze = null; this.zzg = componentName; Iterator it = this.zzb.values().iterator(); while (it.hasNext()) { ((ServiceConnection) it.next()).onServiceDisconnected(componentName); } this.zzc = 2; } catch (Throwable th) { throw th; } } } public final int zza() { return this.zzc; } public final ComponentName zzb() { return this.zzg; } @Nullable public final IBinder zzc() { return this.zze; } public final void zzd(ServiceConnection serviceConnection, ServiceConnection serviceConnection2, String str) { this.zzb.put(serviceConnection, serviceConnection2); } public final void zze(String str, @Nullable Executor executor) { ConnectionTracker connectionTracker; Context context; Context context2; ConnectionTracker connectionTracker2; Context context3; Handler handler; Handler handler2; long j; StrictMode.VmPolicy.Builder permitUnsafeIntentLaunch; this.zzc = 3; StrictMode.VmPolicy vmPolicy = StrictMode.getVmPolicy(); if (PlatformVersion.isAtLeastS()) { permitUnsafeIntentLaunch = new StrictMode.VmPolicy.Builder(vmPolicy).permitUnsafeIntentLaunch(); StrictMode.setVmPolicy(permitUnsafeIntentLaunch.build()); } try { zzs zzsVar = this.zza; connectionTracker = zzsVar.zzf; context = zzsVar.zzc; zzo zzoVar = this.zzf; context2 = zzsVar.zzc; boolean zza = connectionTracker.zza(context, str, zzoVar.zzb(context2), this, 4225, executor); this.zzd = zza; if (zza) { handler = this.zza.zzd; Message obtainMessage = handler.obtainMessage(1, this.zzf); handler2 = this.zza.zzd; j = this.zza.zzh; handler2.sendMessageDelayed(obtainMessage, j); } else { this.zzc = 2; try { zzs zzsVar2 = this.zza; connectionTracker2 = zzsVar2.zzf; context3 = zzsVar2.zzc; connectionTracker2.unbindService(context3, this); } catch (IllegalArgumentException unused) { } } StrictMode.setVmPolicy(vmPolicy); } catch (Throwable th) { StrictMode.setVmPolicy(vmPolicy); throw th; } } public final void zzf(ServiceConnection serviceConnection, String str) { this.zzb.remove(serviceConnection); } public final void zzg(String str) { Handler handler; ConnectionTracker connectionTracker; Context context; zzo zzoVar = this.zzf; handler = this.zza.zzd; handler.removeMessages(1, zzoVar); zzs zzsVar = this.zza; connectionTracker = zzsVar.zzf; context = zzsVar.zzc; connectionTracker.unbindService(context, this); this.zzd = false; this.zzc = 2; } public final boolean zzh(ServiceConnection serviceConnection) { return this.zzb.containsKey(serviceConnection); } public final boolean zzi() { return this.zzb.isEmpty(); } public final boolean zzj() { return this.zzd; } }