jimu-decompiled/sources/com/google/android/gms/common/internal/BaseGmsClient.java
2025-05-13 19:24:51 +02:00

804 lines
28 KiB
Java

package com.google.android.gms.common.internal;
import android.accounts.Account;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.DeadObjectException;
import android.os.Handler;
import android.os.IBinder;
import android.os.IInterface;
import android.os.Looper;
import android.os.Message;
import android.os.Parcel;
import android.os.RemoteException;
import android.text.TextUtils;
import android.util.Log;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.Feature;
import com.google.android.gms.common.GoogleApiAvailabilityLight;
import com.google.android.gms.common.api.Scope;
import com.google.android.gms.common.internal.GmsClientSupervisor;
import com.google.android.gms.common.internal.IGmsCallbacks;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
/* loaded from: classes.dex */
public abstract class BaseGmsClient<T extends IInterface> {
private static final Feature[] v = new Feature[0];
private zzh a;
private final Context b;
private final GmsClientSupervisor c;
private final GoogleApiAvailabilityLight d;
final Handler e;
private final Object f;
private final Object g;
private IGmsServiceBroker h;
protected ConnectionProgressReportCallbacks i;
private T j;
private final ArrayList<zzc<?>> k;
private zze l;
private int m;
private final BaseConnectionCallbacks n;
private final BaseOnConnectionFailedListener o;
private final int p;
private final String q;
private ConnectionResult r;
private boolean s;
private volatile com.google.android.gms.common.internal.zzb t;
protected AtomicInteger u;
public interface BaseConnectionCallbacks {
void d(Bundle bundle);
void i(int i);
}
public interface BaseOnConnectionFailedListener {
void a(ConnectionResult connectionResult);
}
public interface ConnectionProgressReportCallbacks {
void a(ConnectionResult connectionResult);
}
protected class LegacyClientCallbackAdapter implements ConnectionProgressReportCallbacks {
public LegacyClientCallbackAdapter() {
}
@Override // com.google.android.gms.common.internal.BaseGmsClient.ConnectionProgressReportCallbacks
public void a(ConnectionResult connectionResult) {
if (connectionResult.isSuccess()) {
BaseGmsClient baseGmsClient = BaseGmsClient.this;
baseGmsClient.a((IAccountAccessor) null, baseGmsClient.r());
} else if (BaseGmsClient.this.o != null) {
BaseGmsClient.this.o.a(connectionResult);
}
}
}
public interface SignOutCallbacks {
void a();
}
private abstract class zza extends zzc<Boolean> {
private final int d;
private final Bundle e;
protected zza(int i, Bundle bundle) {
super(true);
this.d = i;
this.e = bundle;
}
protected abstract void a(ConnectionResult connectionResult);
@Override // com.google.android.gms.common.internal.BaseGmsClient.zzc
protected final /* synthetic */ void a(Boolean bool) {
if (bool == null) {
BaseGmsClient.this.b(1, null);
return;
}
int i = this.d;
if (i == 0) {
if (e()) {
return;
}
BaseGmsClient.this.b(1, null);
a(new ConnectionResult(8, null));
return;
}
if (i == 10) {
BaseGmsClient.this.b(1, null);
throw new IllegalStateException(String.format("A fatal developer error has occurred. Class name: %s. Start service action: %s. Service Descriptor: %s. ", getClass().getSimpleName(), BaseGmsClient.this.u(), BaseGmsClient.this.t()));
}
BaseGmsClient.this.b(1, null);
Bundle bundle = this.e;
a(new ConnectionResult(this.d, bundle != null ? (PendingIntent) bundle.getParcelable("pendingIntent") : null));
}
@Override // com.google.android.gms.common.internal.BaseGmsClient.zzc
protected final void c() {
}
protected abstract boolean e();
}
final class zzb extends com.google.android.gms.internal.common.zze {
public zzb(Looper looper) {
super(looper);
}
private static void a(Message message) {
zzc zzcVar = (zzc) message.obj;
zzcVar.c();
zzcVar.b();
}
private static boolean b(Message message) {
int i = message.what;
return i == 2 || i == 1 || i == 7;
}
@Override // android.os.Handler
public final void handleMessage(Message message) {
if (BaseGmsClient.this.u.get() != message.arg1) {
if (b(message)) {
a(message);
return;
}
return;
}
int i = message.what;
if ((i == 1 || i == 7 || i == 4 || i == 5) && !BaseGmsClient.this.d()) {
a(message);
return;
}
int i2 = message.what;
if (i2 == 4) {
BaseGmsClient.this.r = new ConnectionResult(message.arg2);
if (BaseGmsClient.this.z() && !BaseGmsClient.this.s) {
BaseGmsClient.this.b(3, null);
return;
}
ConnectionResult connectionResult = BaseGmsClient.this.r != null ? BaseGmsClient.this.r : new ConnectionResult(8);
BaseGmsClient.this.i.a(connectionResult);
BaseGmsClient.this.a(connectionResult);
return;
}
if (i2 == 5) {
ConnectionResult connectionResult2 = BaseGmsClient.this.r != null ? BaseGmsClient.this.r : new ConnectionResult(8);
BaseGmsClient.this.i.a(connectionResult2);
BaseGmsClient.this.a(connectionResult2);
return;
}
if (i2 == 3) {
Object obj = message.obj;
ConnectionResult connectionResult3 = new ConnectionResult(message.arg2, obj instanceof PendingIntent ? (PendingIntent) obj : null);
BaseGmsClient.this.i.a(connectionResult3);
BaseGmsClient.this.a(connectionResult3);
return;
}
if (i2 == 6) {
BaseGmsClient.this.b(5, null);
if (BaseGmsClient.this.n != null) {
BaseGmsClient.this.n.i(message.arg2);
}
BaseGmsClient.this.a(message.arg2);
BaseGmsClient.this.a(5, 1, (int) null);
return;
}
if (i2 == 2 && !BaseGmsClient.this.b()) {
a(message);
return;
}
if (b(message)) {
((zzc) message.obj).d();
return;
}
int i3 = message.what;
StringBuilder sb = new StringBuilder(45);
sb.append("Don't know how to handle message: ");
sb.append(i3);
Log.wtf("GmsClient", sb.toString(), new Exception());
}
}
protected abstract class zzc<TListener> {
private TListener a;
private boolean b = false;
public zzc(TListener tlistener) {
this.a = tlistener;
}
public final void a() {
synchronized (this) {
this.a = null;
}
}
protected abstract void a(TListener tlistener);
public final void b() {
a();
synchronized (BaseGmsClient.this.k) {
BaseGmsClient.this.k.remove(this);
}
}
protected abstract void c();
public final void d() {
TListener tlistener;
synchronized (this) {
tlistener = this.a;
if (this.b) {
String valueOf = String.valueOf(this);
StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 47);
sb.append("Callback proxy ");
sb.append(valueOf);
sb.append(" being reused. This is not safe.");
Log.w("GmsClient", sb.toString());
}
}
if (tlistener != null) {
try {
a(tlistener);
} catch (RuntimeException e) {
c();
throw e;
}
} else {
c();
}
synchronized (this) {
this.b = true;
}
b();
}
}
public final class zze implements ServiceConnection {
private final int a;
public zze(int i) {
this.a = i;
}
@Override // android.content.ServiceConnection
public final void onServiceConnected(ComponentName componentName, final IBinder iBinder) {
IGmsServiceBroker iGmsServiceBroker;
if (iBinder == null) {
BaseGmsClient.this.c(16);
return;
}
synchronized (BaseGmsClient.this.g) {
BaseGmsClient baseGmsClient = BaseGmsClient.this;
if (iBinder == null) {
iGmsServiceBroker = null;
} else {
IInterface queryLocalInterface = iBinder.queryLocalInterface("com.google.android.gms.common.internal.IGmsServiceBroker");
iGmsServiceBroker = (queryLocalInterface == null || !(queryLocalInterface instanceof IGmsServiceBroker)) ? new IGmsServiceBroker(iBinder) { // from class: com.google.android.gms.common.internal.IGmsServiceBroker$Stub$zza
private final IBinder a;
{
this.a = iBinder;
}
@Override // com.google.android.gms.common.internal.IGmsServiceBroker
public final void a(IGmsCallbacks iGmsCallbacks, GetServiceRequest getServiceRequest) throws RemoteException {
Parcel obtain = Parcel.obtain();
Parcel obtain2 = Parcel.obtain();
try {
obtain.writeInterfaceToken("com.google.android.gms.common.internal.IGmsServiceBroker");
obtain.writeStrongBinder(iGmsCallbacks != null ? iGmsCallbacks.asBinder() : null);
if (getServiceRequest != null) {
obtain.writeInt(1);
getServiceRequest.writeToParcel(obtain, 0);
} else {
obtain.writeInt(0);
}
this.a.transact(46, obtain, obtain2, 0);
obtain2.readException();
} finally {
obtain2.recycle();
obtain.recycle();
}
}
@Override // android.os.IInterface
public final IBinder asBinder() {
return this.a;
}
} : (IGmsServiceBroker) queryLocalInterface;
}
baseGmsClient.h = iGmsServiceBroker;
}
BaseGmsClient.this.a(0, (Bundle) null, this.a);
}
@Override // android.content.ServiceConnection
public final void onServiceDisconnected(ComponentName componentName) {
synchronized (BaseGmsClient.this.g) {
BaseGmsClient.this.h = null;
}
Handler handler = BaseGmsClient.this.e;
handler.sendMessage(handler.obtainMessage(6, this.a, 1));
}
}
protected final class zzf extends zza {
private final IBinder g;
public zzf(int i, IBinder iBinder, Bundle bundle) {
super(i, bundle);
this.g = iBinder;
}
@Override // com.google.android.gms.common.internal.BaseGmsClient.zza
protected final void a(ConnectionResult connectionResult) {
if (BaseGmsClient.this.o != null) {
BaseGmsClient.this.o.a(connectionResult);
}
BaseGmsClient.this.a(connectionResult);
}
@Override // com.google.android.gms.common.internal.BaseGmsClient.zza
protected final boolean e() {
try {
String interfaceDescriptor = this.g.getInterfaceDescriptor();
if (!BaseGmsClient.this.t().equals(interfaceDescriptor)) {
String t = BaseGmsClient.this.t();
StringBuilder sb = new StringBuilder(String.valueOf(t).length() + 34 + String.valueOf(interfaceDescriptor).length());
sb.append("service descriptor mismatch: ");
sb.append(t);
sb.append(" vs. ");
sb.append(interfaceDescriptor);
Log.e("GmsClient", sb.toString());
return false;
}
IInterface a = BaseGmsClient.this.a(this.g);
if (a == null || !(BaseGmsClient.this.a(2, 4, (int) a) || BaseGmsClient.this.a(3, 4, (int) a))) {
return false;
}
BaseGmsClient.this.r = null;
Bundle n = BaseGmsClient.this.n();
if (BaseGmsClient.this.n == null) {
return true;
}
BaseGmsClient.this.n.d(n);
return true;
} catch (RemoteException unused) {
Log.w("GmsClient", "service probably died");
return false;
}
}
}
protected final class zzg extends zza {
public zzg(int i, Bundle bundle) {
super(i, null);
}
@Override // com.google.android.gms.common.internal.BaseGmsClient.zza
protected final void a(ConnectionResult connectionResult) {
BaseGmsClient.this.i.a(connectionResult);
BaseGmsClient.this.a(connectionResult);
}
@Override // com.google.android.gms.common.internal.BaseGmsClient.zza
protected final boolean e() {
BaseGmsClient.this.i.a(ConnectionResult.RESULT_SUCCESS);
return true;
}
}
static {
new String[]{"service_esmobile", "service_googleme"};
}
/* JADX WARN: Illegal instructions before constructor call */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct code enable 'Show inconsistent code' option in preferences
*/
protected BaseGmsClient(android.content.Context r10, android.os.Looper r11, int r12, com.google.android.gms.common.internal.BaseGmsClient.BaseConnectionCallbacks r13, com.google.android.gms.common.internal.BaseGmsClient.BaseOnConnectionFailedListener r14, java.lang.String r15) {
/*
r9 = this;
com.google.android.gms.common.internal.GmsClientSupervisor r3 = com.google.android.gms.common.internal.GmsClientSupervisor.a(r10)
com.google.android.gms.common.GoogleApiAvailabilityLight r4 = com.google.android.gms.common.GoogleApiAvailabilityLight.a()
com.google.android.gms.common.internal.Preconditions.a(r13)
r6 = r13
com.google.android.gms.common.internal.BaseGmsClient$BaseConnectionCallbacks r6 = (com.google.android.gms.common.internal.BaseGmsClient.BaseConnectionCallbacks) r6
com.google.android.gms.common.internal.Preconditions.a(r14)
r7 = r14
com.google.android.gms.common.internal.BaseGmsClient$BaseOnConnectionFailedListener r7 = (com.google.android.gms.common.internal.BaseGmsClient.BaseOnConnectionFailedListener) r7
r0 = r9
r1 = r10
r2 = r11
r5 = r12
r8 = r15
r0.<init>(r1, r2, r3, r4, r5, r6, r7, r8)
return
*/
throw new UnsupportedOperationException("Method not decompiled: com.google.android.gms.common.internal.BaseGmsClient.<init>(android.content.Context, android.os.Looper, int, com.google.android.gms.common.internal.BaseGmsClient$BaseConnectionCallbacks, com.google.android.gms.common.internal.BaseGmsClient$BaseOnConnectionFailedListener, java.lang.String):void");
}
/* JADX INFO: Access modifiers changed from: private */
public final void a(com.google.android.gms.common.internal.zzb zzbVar) {
this.t = zzbVar;
}
/* JADX INFO: Access modifiers changed from: private */
public final void b(int i, T t) {
Preconditions.a((i == 4) == (t != null));
synchronized (this.f) {
this.m = i;
this.j = t;
a(i, (int) t);
if (i != 1) {
if (i == 2 || i == 3) {
if (this.l != null && this.a != null) {
String c = this.a.c();
String a = this.a.a();
StringBuilder sb = new StringBuilder(String.valueOf(c).length() + 70 + String.valueOf(a).length());
sb.append("Calling connect() while still connected, missing disconnect() for ");
sb.append(c);
sb.append(" on ");
sb.append(a);
Log.e("GmsClient", sb.toString());
this.c.a(this.a.c(), this.a.a(), this.a.b(), this.l, x());
this.u.incrementAndGet();
}
this.l = new zze(this.u.get());
this.a = (this.m != 3 || q() == null) ? new zzh(v(), u(), false, 129) : new zzh(o().getPackageName(), q(), true, 129);
if (!this.c.a(new GmsClientSupervisor.zza(this.a.c(), this.a.a(), this.a.b()), this.l, x())) {
String c2 = this.a.c();
String a2 = this.a.a();
StringBuilder sb2 = new StringBuilder(String.valueOf(c2).length() + 34 + String.valueOf(a2).length());
sb2.append("unable to connect to service: ");
sb2.append(c2);
sb2.append(" on ");
sb2.append(a2);
Log.e("GmsClient", sb2.toString());
a(16, (Bundle) null, this.u.get());
}
} else if (i == 4) {
a((BaseGmsClient<T>) t);
}
} else if (this.l != null) {
this.c.a(u(), v(), 129, this.l, x());
this.l = null;
}
}
}
/* JADX INFO: Access modifiers changed from: private */
public final void c(int i) {
int i2;
if (y()) {
i2 = 5;
this.s = true;
} else {
i2 = 4;
}
Handler handler = this.e;
handler.sendMessage(handler.obtainMessage(i2, this.u.get(), 16));
}
private final String x() {
String str = this.q;
return str == null ? this.b.getClass().getName() : str;
}
private final boolean y() {
boolean z;
synchronized (this.f) {
z = this.m == 3;
}
return z;
}
/* JADX INFO: Access modifiers changed from: private */
public final boolean z() {
if (this.s || TextUtils.isEmpty(t()) || TextUtils.isEmpty(q())) {
return false;
}
try {
Class.forName(t());
return true;
} catch (ClassNotFoundException unused) {
return false;
}
}
protected abstract T a(IBinder iBinder);
void a(int i, T t) {
}
public boolean d() {
boolean z;
synchronized (this.f) {
z = this.m == 2 || this.m == 3;
}
return z;
}
public String e() {
zzh zzhVar;
if (!b() || (zzhVar = this.a) == null) {
throw new RuntimeException("Failed to connect when checking package");
}
return zzhVar.a();
}
public boolean f() {
return true;
}
public int g() {
return GoogleApiAvailabilityLight.a;
}
public final Feature[] h() {
com.google.android.gms.common.internal.zzb zzbVar = this.t;
if (zzbVar == null) {
return null;
}
return zzbVar.zzda;
}
public boolean i() {
return false;
}
public void j() {
int a = this.d.a(this.b, g());
if (a == 0) {
a(new LegacyClientCallbackAdapter());
} else {
b(1, null);
a(new LegacyClientCallbackAdapter(), a, (PendingIntent) null);
}
}
protected final void k() {
if (!b()) {
throw new IllegalStateException("Not connected. Call connect() and wait for onConnected() to be called.");
}
}
public Account l() {
return null;
}
public Feature[] m() {
return v;
}
public Bundle n() {
return null;
}
public final Context o() {
return this.b;
}
protected Bundle p() {
return new Bundle();
}
protected String q() {
return null;
}
protected Set<Scope> r() {
return Collections.EMPTY_SET;
}
public final T s() throws DeadObjectException {
T t;
synchronized (this.f) {
if (this.m == 5) {
throw new DeadObjectException();
}
k();
Preconditions.b(this.j != null, "Client is connected but service is null");
t = this.j;
}
return t;
}
protected abstract String t();
protected abstract String u();
protected String v() {
return "com.google.android.gms";
}
public boolean w() {
return false;
}
protected void a(T t) {
System.currentTimeMillis();
}
public static final class zzd extends IGmsCallbacks.zza {
private BaseGmsClient a;
private final int b;
public zzd(BaseGmsClient baseGmsClient, int i) {
this.a = baseGmsClient;
this.b = i;
}
@Override // com.google.android.gms.common.internal.IGmsCallbacks
public final void a(int i, IBinder iBinder, Bundle bundle) {
Preconditions.a(this.a, "onPostInitComplete can be called only once per call to getRemoteService");
this.a.a(i, iBinder, bundle, this.b);
this.a = null;
}
@Override // com.google.android.gms.common.internal.IGmsCallbacks
public final void b(int i, Bundle bundle) {
Log.wtf("GmsClient", "received deprecated onAccountValidationComplete callback, ignoring", new Exception());
}
@Override // com.google.android.gms.common.internal.IGmsCallbacks
public final void a(int i, IBinder iBinder, com.google.android.gms.common.internal.zzb zzbVar) {
Preconditions.a(this.a, "onPostInitCompleteWithConnectionInfo can be called only once per call togetRemoteService");
Preconditions.a(zzbVar);
this.a.a(zzbVar);
a(i, iBinder, zzbVar.zzcz);
}
}
protected void a(int i) {
System.currentTimeMillis();
}
protected void a(ConnectionResult connectionResult) {
connectionResult.getErrorCode();
System.currentTimeMillis();
}
protected BaseGmsClient(Context context, Looper looper, GmsClientSupervisor gmsClientSupervisor, GoogleApiAvailabilityLight googleApiAvailabilityLight, int i, BaseConnectionCallbacks baseConnectionCallbacks, BaseOnConnectionFailedListener baseOnConnectionFailedListener, String str) {
this.f = new Object();
this.g = new Object();
this.k = new ArrayList<>();
this.m = 1;
this.r = null;
this.s = false;
this.t = null;
this.u = new AtomicInteger(0);
Preconditions.a(context, "Context must not be null");
this.b = context;
Preconditions.a(looper, "Looper must not be null");
Preconditions.a(gmsClientSupervisor, "Supervisor must not be null");
this.c = gmsClientSupervisor;
Preconditions.a(googleApiAvailabilityLight, "API availability must not be null");
this.d = googleApiAvailabilityLight;
this.e = new zzb(looper);
this.p = i;
this.n = baseConnectionCallbacks;
this.o = baseOnConnectionFailedListener;
this.q = str;
}
/* JADX INFO: Access modifiers changed from: private */
public final boolean a(int i, int i2, T t) {
synchronized (this.f) {
if (this.m != i) {
return false;
}
b(i2, t);
return true;
}
}
public void a(ConnectionProgressReportCallbacks connectionProgressReportCallbacks) {
Preconditions.a(connectionProgressReportCallbacks, "Connection progress callbacks cannot be null.");
this.i = connectionProgressReportCallbacks;
b(2, null);
}
public void a() {
this.u.incrementAndGet();
synchronized (this.k) {
int size = this.k.size();
for (int i = 0; i < size; i++) {
this.k.get(i).a();
}
this.k.clear();
}
synchronized (this.g) {
this.h = null;
}
b(1, null);
}
protected void a(ConnectionProgressReportCallbacks connectionProgressReportCallbacks, int i, PendingIntent pendingIntent) {
Preconditions.a(connectionProgressReportCallbacks, "Connection progress callbacks cannot be null.");
this.i = connectionProgressReportCallbacks;
Handler handler = this.e;
handler.sendMessage(handler.obtainMessage(3, this.u.get(), i, pendingIntent));
}
protected void a(int i, IBinder iBinder, Bundle bundle, int i2) {
Handler handler = this.e;
handler.sendMessage(handler.obtainMessage(1, i2, -1, new zzf(i, iBinder, bundle)));
}
protected final void a(int i, Bundle bundle, int i2) {
Handler handler = this.e;
handler.sendMessage(handler.obtainMessage(7, i2, -1, new zzg(i, null)));
}
public void a(IAccountAccessor iAccountAccessor, Set<Scope> set) {
Bundle p = p();
GetServiceRequest getServiceRequest = new GetServiceRequest(this.p);
getServiceRequest.zzdh = this.b.getPackageName();
getServiceRequest.zzdk = p;
if (set != null) {
getServiceRequest.zzdj = (Scope[]) set.toArray(new Scope[set.size()]);
}
if (i()) {
getServiceRequest.zzdl = l() != null ? l() : new Account("<<default account>>", "com.google");
if (iAccountAccessor != null) {
getServiceRequest.zzdi = iAccountAccessor.asBinder();
}
} else if (w()) {
getServiceRequest.zzdl = l();
}
getServiceRequest.zzdm = v;
getServiceRequest.zzdn = m();
try {
synchronized (this.g) {
if (this.h != null) {
this.h.a(new zzd(this, this.u.get()), getServiceRequest);
} else {
Log.w("GmsClient", "mServiceBroker is null, client disconnected");
}
}
} catch (DeadObjectException e) {
Log.w("GmsClient", "IGmsServiceBroker.getService failed", e);
b(1);
} catch (RemoteException e2) {
e = e2;
Log.w("GmsClient", "IGmsServiceBroker.getService failed", e);
a(8, (IBinder) null, (Bundle) null, this.u.get());
} catch (SecurityException e3) {
throw e3;
} catch (RuntimeException e4) {
e = e4;
Log.w("GmsClient", "IGmsServiceBroker.getService failed", e);
a(8, (IBinder) null, (Bundle) null, this.u.get());
}
}
public boolean b() {
boolean z;
synchronized (this.f) {
z = this.m == 4;
}
return z;
}
public void b(int i) {
Handler handler = this.e;
handler.sendMessage(handler.obtainMessage(6, this.u.get(), i));
}
public void a(SignOutCallbacks signOutCallbacks) {
signOutCallbacks.a();
}
}