package com.google.android.gms.common.api.internal; import android.content.Context; import android.os.Bundle; import android.os.Looper; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GoogleApiAvailabilityLight; import com.google.android.gms.common.api.Api; import com.google.android.gms.common.api.Result; import com.google.android.gms.common.api.internal.BaseImplementation; import com.google.android.gms.common.internal.ClientSettings; import com.google.android.gms.common.internal.Preconditions; import com.google.android.gms.signin.SignInOptions; import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Lock; import org.checkerframework.checker.initialization.qual.NotOnlyInitialized; /* loaded from: classes.dex */ public final class zabi implements zaca, zau { final Map, Api.Client> zaa; final ClientSettings zac; final Map, Boolean> zad; final Api.AbstractClientBuilder zae; int zaf; final zabe zag; final zabz zah; private final Lock zai; private final Condition zaj; private final Context zak; private final GoogleApiAvailabilityLight zal; private final zabh zam; @NotOnlyInitialized private volatile zabf zan; final Map, ConnectionResult> zab = new HashMap(); private ConnectionResult zao = null; public zabi(Context context, zabe zabeVar, Lock lock, Looper looper, GoogleApiAvailabilityLight googleApiAvailabilityLight, Map, Api.Client> map, ClientSettings clientSettings, Map, Boolean> map2, Api.AbstractClientBuilder abstractClientBuilder, ArrayList arrayList, zabz zabzVar) { this.zak = context; this.zai = lock; this.zal = googleApiAvailabilityLight; this.zaa = map; this.zac = clientSettings; this.zad = map2; this.zae = abstractClientBuilder; this.zag = zabeVar; this.zah = zabzVar; int size = arrayList.size(); for (int i = 0; i < size; i++) { arrayList.get(i).zaa(this); } this.zam = new zabh(this, looper); this.zaj = lock.newCondition(); this.zan = new zaax(this); } @Override // com.google.android.gms.common.api.internal.ConnectionCallbacks public final void onConnected(Bundle bundle) { this.zai.lock(); try { this.zan.zag(bundle); } finally { this.zai.unlock(); } } @Override // com.google.android.gms.common.api.internal.ConnectionCallbacks public final void onConnectionSuspended(int i) { this.zai.lock(); try { this.zan.zai(i); } finally { this.zai.unlock(); } } @Override // com.google.android.gms.common.api.internal.zau public final void zaa(ConnectionResult connectionResult, Api api, boolean z) { this.zai.lock(); try { this.zan.zah(connectionResult, api, z); } finally { this.zai.unlock(); } } @Override // com.google.android.gms.common.api.internal.zaca public final ConnectionResult zab() { zaq(); while (this.zan instanceof zaaw) { try { this.zaj.await(); } catch (InterruptedException unused) { Thread.currentThread().interrupt(); return new ConnectionResult(15, null); } } if (this.zan instanceof zaaj) { return ConnectionResult.RESULT_SUCCESS; } ConnectionResult connectionResult = this.zao; return connectionResult != null ? connectionResult : new ConnectionResult(13, null); } @Override // com.google.android.gms.common.api.internal.zaca public final ConnectionResult zac(long j, TimeUnit timeUnit) { zaq(); long nanos = timeUnit.toNanos(j); while (this.zan instanceof zaaw) { if (nanos > 0) { try { nanos = this.zaj.awaitNanos(nanos); } catch (InterruptedException unused) { Thread.currentThread().interrupt(); return new ConnectionResult(15, null); } } else { zar(); return new ConnectionResult(14, null); } Thread.currentThread().interrupt(); return new ConnectionResult(15, null); } if (this.zan instanceof zaaj) { return ConnectionResult.RESULT_SUCCESS; } ConnectionResult connectionResult = this.zao; return connectionResult != null ? connectionResult : new ConnectionResult(13, null); } @Override // com.google.android.gms.common.api.internal.zaca public final ConnectionResult zad(Api api) { Api.AnyClientKey zab = api.zab(); if (!this.zaa.containsKey(zab)) { return null; } if (this.zaa.get(zab).isConnected()) { return ConnectionResult.RESULT_SUCCESS; } if (this.zab.containsKey(zab)) { return this.zab.get(zab); } return null; } @Override // com.google.android.gms.common.api.internal.zaca public final > T zae(T t) { t.zak(); this.zan.zaa(t); return t; } @Override // com.google.android.gms.common.api.internal.zaca public final > T zaf(T t) { t.zak(); return (T) this.zan.zab(t); } /* JADX INFO: Access modifiers changed from: package-private */ public final void zai() { this.zai.lock(); try { this.zag.zak(); this.zan = new zaaj(this); this.zan.zad(); this.zaj.signalAll(); } finally { this.zai.unlock(); } } /* JADX INFO: Access modifiers changed from: package-private */ public final void zaj() { this.zai.lock(); try { this.zan = new zaaw(this, this.zac, this.zad, this.zal, this.zae, this.zai, this.zak); this.zan.zad(); this.zaj.signalAll(); } finally { this.zai.unlock(); } } /* JADX INFO: Access modifiers changed from: package-private */ public final void zak(ConnectionResult connectionResult) { this.zai.lock(); try { this.zao = connectionResult; this.zan = new zaax(this); this.zan.zad(); this.zaj.signalAll(); } finally { this.zai.unlock(); } } /* JADX INFO: Access modifiers changed from: package-private */ public final void zal(zabg zabgVar) { this.zam.sendMessage(this.zam.obtainMessage(1, zabgVar)); } /* JADX INFO: Access modifiers changed from: package-private */ public final void zam(RuntimeException runtimeException) { this.zam.sendMessage(this.zam.obtainMessage(2, runtimeException)); } @Override // com.google.android.gms.common.api.internal.zaca public final void zaq() { this.zan.zae(); } @Override // com.google.android.gms.common.api.internal.zaca public final void zar() { if (this.zan.zaj()) { this.zab.clear(); } } @Override // com.google.android.gms.common.api.internal.zaca public final void zas(String str, FileDescriptor fileDescriptor, PrintWriter printWriter, String[] strArr) { String concat = String.valueOf(str).concat(" "); printWriter.append((CharSequence) str).append("mState=").println(this.zan); for (Api api : this.zad.keySet()) { printWriter.append((CharSequence) str).append((CharSequence) api.zad()).println(":"); ((Api.Client) Preconditions.checkNotNull(this.zaa.get(api.zab()))).dump(concat, fileDescriptor, printWriter, strArr); } } @Override // com.google.android.gms.common.api.internal.zaca public final void zat() { if (this.zan instanceof zaaj) { ((zaaj) this.zan).zaf(); } } @Override // com.google.android.gms.common.api.internal.zaca public final void zau() { } @Override // com.google.android.gms.common.api.internal.zaca public final boolean zaw() { return this.zan instanceof zaaj; } @Override // com.google.android.gms.common.api.internal.zaca public final boolean zax() { return this.zan instanceof zaaw; } @Override // com.google.android.gms.common.api.internal.zaca public final boolean zay(SignInConnectionListener signInConnectionListener) { return false; } }