what-the-bank/sources/com/google/firebase/iid/zzac.java

322 lines
12 KiB
Java

package com.google.firebase.iid;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.Messenger;
import android.os.RemoteException;
import android.util.SparseArray;
import com.google.android.gms.common.internal.Preconditions;
import com.google.android.gms.common.stats.ConnectionTracker;
import java.util.ArrayDeque;
import java.util.Iterator;
import java.util.Queue;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public final class zzac implements ServiceConnection {
int zza;
final Messenger zzb;
zzal zzc;
final Queue<zzan<?>> zzd;
final SparseArray<zzan<?>> zze;
final zzab zzf;
private zzac(zzab zzabVar) {
this.zzf = zzabVar;
this.zza = 0;
this.zzb = new Messenger(new com.google.android.gms.internal.firebase_messaging.zze(Looper.getMainLooper(), new Handler.Callback(this) { // from class: com.google.firebase.iid.zzaf
private final zzac zza;
@Override // android.os.Handler.Callback
public final boolean handleMessage(Message message) {
return this.zza.zza(message);
}
/* JADX INFO: Access modifiers changed from: package-private */
{
this.zza = this;
}
}));
this.zzd = new ArrayDeque();
this.zze = new SparseArray<>();
}
/* JADX INFO: Access modifiers changed from: package-private */
public final boolean zza(zzan<?> zzanVar) {
Context context;
ScheduledExecutorService scheduledExecutorService;
synchronized (this) {
int i = this.zza;
if (i == 0) {
this.zzd.add(zzanVar);
Preconditions.checkState(this.zza == 0);
this.zza = 1;
Intent intent = new Intent("com.google.android.c2dm.intent.REGISTER");
intent.setPackage("com.google.android.gms");
ConnectionTracker connectionTracker = ConnectionTracker.getInstance();
context = this.zzf.zzb;
if (!connectionTracker.bindService(context, intent, this, 1)) {
zza(0, "Unable to bind to service");
} else {
scheduledExecutorService = this.zzf.zzc;
scheduledExecutorService.schedule(new Runnable(this) { // from class: com.google.firebase.iid.zzae
private final zzac zza;
@Override // java.lang.Runnable
public final void run() {
this.zza.zzc();
}
/* JADX INFO: Access modifiers changed from: package-private */
{
this.zza = this;
}
}, 30L, TimeUnit.SECONDS);
}
return true;
}
if (i == 1) {
this.zzd.add(zzanVar);
return true;
}
if (i == 2) {
this.zzd.add(zzanVar);
zza();
return true;
}
if (i != 3 && i != 4) {
int i2 = this.zza;
StringBuilder sb = new StringBuilder(26);
sb.append("Unknown state: ");
sb.append(i2);
throw new IllegalStateException(sb.toString());
}
return false;
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public final boolean zza(Message message) {
int i = message.arg1;
synchronized (this) {
zzan<?> zzanVar = this.zze.get(i);
if (zzanVar == null) {
return true;
}
this.zze.remove(i);
zzb();
Bundle data = message.getData();
if (data.getBoolean("unsupported", false)) {
zzanVar.zza(new zzam(4, "Not supported by GmsCore"));
} else {
zzanVar.zza(data);
}
return true;
}
}
@Override // android.content.ServiceConnection
public final void onServiceConnected(ComponentName componentName, final IBinder iBinder) {
ScheduledExecutorService scheduledExecutorService;
scheduledExecutorService = this.zzf.zzc;
scheduledExecutorService.execute(new Runnable(this, iBinder) { // from class: com.google.firebase.iid.zzah
private final zzac zza;
private final IBinder zzb;
@Override // java.lang.Runnable
public final void run() {
zzac zzacVar = this.zza;
IBinder iBinder2 = this.zzb;
synchronized (zzacVar) {
if (iBinder2 == null) {
zzacVar.zza(0, "Null service connection");
return;
}
try {
zzacVar.zzc = new zzal(iBinder2);
zzacVar.zza = 2;
zzacVar.zza();
} catch (RemoteException e) {
zzacVar.zza(0, e.getMessage());
}
}
}
/* JADX INFO: Access modifiers changed from: package-private */
{
this.zza = this;
this.zzb = iBinder;
}
});
}
/* JADX INFO: Access modifiers changed from: package-private */
public final void zza() {
ScheduledExecutorService scheduledExecutorService;
scheduledExecutorService = this.zzf.zzc;
scheduledExecutorService.execute(new Runnable(this) { // from class: com.google.firebase.iid.zzag
private final zzac zza;
@Override // java.lang.Runnable
public final void run() {
final zzan<?> poll;
ScheduledExecutorService scheduledExecutorService2;
Context context;
final zzac zzacVar = this.zza;
while (true) {
synchronized (zzacVar) {
if (zzacVar.zza != 2) {
return;
}
if (zzacVar.zzd.isEmpty()) {
zzacVar.zzb();
return;
}
poll = zzacVar.zzd.poll();
zzacVar.zze.put(poll.zza, poll);
scheduledExecutorService2 = zzacVar.zzf.zzc;
scheduledExecutorService2.schedule(new Runnable(zzacVar, poll) { // from class: com.google.firebase.iid.zzai
private final zzac zza;
private final zzan zzb;
@Override // java.lang.Runnable
public final void run() {
this.zza.zza(this.zzb.zza);
}
/* JADX INFO: Access modifiers changed from: package-private */
{
this.zza = zzacVar;
this.zzb = poll;
}
}, 30L, TimeUnit.SECONDS);
}
context = zzacVar.zzf.zzb;
Messenger messenger = zzacVar.zzb;
Message obtain = Message.obtain();
obtain.what = poll.zzc;
obtain.arg1 = poll.zza;
obtain.replyTo = messenger;
Bundle bundle = new Bundle();
bundle.putBoolean("oneWay", poll.zza());
bundle.putString("pkg", context.getPackageName());
bundle.putBundle("data", poll.zzd);
obtain.setData(bundle);
try {
zzacVar.zzc.zza(obtain);
} catch (RemoteException e) {
zzacVar.zza(2, e.getMessage());
}
}
}
/* JADX INFO: Access modifiers changed from: package-private */
{
this.zza = this;
}
});
}
@Override // android.content.ServiceConnection
public final void onServiceDisconnected(ComponentName componentName) {
ScheduledExecutorService scheduledExecutorService;
scheduledExecutorService = this.zzf.zzc;
scheduledExecutorService.execute(new Runnable(this) { // from class: com.google.firebase.iid.zzaj
private final zzac zza;
@Override // java.lang.Runnable
public final void run() {
this.zza.zza(2, "Service disconnected");
}
/* JADX INFO: Access modifiers changed from: package-private */
{
this.zza = this;
}
});
}
/* JADX INFO: Access modifiers changed from: package-private */
public final void zza(int i, String str) {
Context context;
synchronized (this) {
int i2 = this.zza;
if (i2 == 0) {
throw new IllegalStateException();
}
if (i2 != 1 && i2 != 2) {
if (i2 == 3) {
this.zza = 4;
return;
} else {
if (i2 == 4) {
return;
}
int i3 = this.zza;
StringBuilder sb = new StringBuilder(26);
sb.append("Unknown state: ");
sb.append(i3);
throw new IllegalStateException(sb.toString());
}
}
this.zza = 4;
ConnectionTracker connectionTracker = ConnectionTracker.getInstance();
context = this.zzf.zzb;
connectionTracker.unbindService(context, this);
zzam zzamVar = new zzam(i, str);
Iterator<zzan<?>> it = this.zzd.iterator();
while (it.hasNext()) {
it.next().zza(zzamVar);
}
this.zzd.clear();
for (int i4 = 0; i4 < this.zze.size(); i4++) {
this.zze.valueAt(i4).zza(zzamVar);
}
this.zze.clear();
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public final void zzb() {
Context context;
synchronized (this) {
if (this.zza == 2 && this.zzd.isEmpty() && this.zze.size() == 0) {
this.zza = 3;
ConnectionTracker connectionTracker = ConnectionTracker.getInstance();
context = this.zzf.zzb;
connectionTracker.unbindService(context, this);
}
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public final void zzc() {
synchronized (this) {
if (this.zza == 1) {
zza(1, "Timed out while binding");
}
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public final void zza(int i) {
synchronized (this) {
zzan<?> zzanVar = this.zze.get(i);
if (zzanVar != null) {
this.zze.remove(i);
zzanVar.zza(new zzam(3, "Timed out waiting for response"));
zzb();
}
}
}
}