package o; import android.content.Context; import android.os.Bundle; import android.os.Handler; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.Api; import com.google.android.gms.common.api.GoogleApiClient; import java.util.Arrays; import java.util.Iterator; import java.util.List; import pl.charmas.android.reactivelocation2.observables.GoogleAPIConnectionException; import pl.charmas.android.reactivelocation2.observables.GoogleAPIConnectionSuspendedException; /* renamed from: o.guv, reason: case insensitive filesystem */ /* loaded from: classes6.dex */ public abstract class AbstractC15591guv implements InterfaceC13170fSr { private final Handler b; private final List> d; private final Context e; protected abstract void b(GoogleApiClient googleApiClient, InterfaceC13168fSp interfaceC13168fSp); /* JADX INFO: Access modifiers changed from: protected */ @SafeVarargs public AbstractC15591guv(guw guwVar, Api... apiArr) { this.e = guwVar.c; this.b = guwVar.b; this.d = Arrays.asList(apiArr); } /* renamed from: o.guv$LWm */ /* loaded from: classes6.dex */ class LWm implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener { private AbstractC15591guv a; private final InterfaceC13168fSp c; GoogleApiClient d; private LWm(AbstractC15591guv abstractC15591guv, InterfaceC13168fSp interfaceC13168fSp) { this.a = abstractC15591guv; this.c = interfaceC13168fSp; } @Override // com.google.android.gms.common.api.internal.ConnectionCallbacks public final void onConnected(Bundle bundle) { try { this.a.b(this.d, this.c); } catch (Throwable th) { if (this.c.isDisposed()) { return; } this.c.c(th); } } @Override // com.google.android.gms.common.api.internal.ConnectionCallbacks public final void onConnectionSuspended(int i) { if (this.c.isDisposed()) { return; } this.c.c(new GoogleAPIConnectionSuspendedException(i)); } @Override // com.google.android.gms.common.api.internal.OnConnectionFailedListener public final void onConnectionFailed(ConnectionResult connectionResult) { if (this.c.isDisposed()) { return; } this.c.c(new GoogleAPIConnectionException("Error connecting to GoogleApiClient.", connectionResult)); } /* synthetic */ LWm(AbstractC15591guv abstractC15591guv, InterfaceC13168fSp interfaceC13168fSp, byte b) { this(abstractC15591guv, interfaceC13168fSp); } } @Override // o.InterfaceC13170fSr public final void b(InterfaceC13168fSp interfaceC13168fSp) throws Exception { LWm lWm = new LWm(this, interfaceC13168fSp, (byte) 0); GoogleApiClient.Builder builder = new GoogleApiClient.Builder(this.e); Iterator> it = this.d.iterator(); while (it.hasNext()) { builder = builder.addApi(it.next()); } GoogleApiClient.Builder addOnConnectionFailedListener = builder.addConnectionCallbacks(lWm).addOnConnectionFailedListener(lWm); Handler handler = this.b; if (handler != null) { addOnConnectionFailedListener = addOnConnectionFailedListener.setHandler(handler); } final GoogleApiClient build = addOnConnectionFailedListener.build(); lWm.d = build; try { build.connect(); } catch (Throwable th) { if (!interfaceC13168fSp.isDisposed()) { interfaceC13168fSp.c(th); } } interfaceC13168fSp.d(fSJ.c(new fSP(this, build) { // from class: o.gux private GoogleApiClient b; private AbstractC15591guv e; @Override // o.fSP public final void c() { this.b.disconnect(); } { this.e = this; this.b = build; } })); } }