Initial commit
This commit is contained in:
305
sources/com/google/firebase/iid/zzad.java
Normal file
305
sources/com/google/firebase/iid/zzad.java
Normal file
@@ -0,0 +1,305 @@
|
||||
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.Log;
|
||||
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;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
final class zzad implements ServiceConnection {
|
||||
int a;
|
||||
final Messenger b;
|
||||
zzai c;
|
||||
final Queue<zzak<?>> d;
|
||||
final SparseArray<zzak<?>> e;
|
||||
final /* synthetic */ zzab f;
|
||||
|
||||
private zzad(zzab zzabVar) {
|
||||
this.f = zzabVar;
|
||||
this.a = 0;
|
||||
this.b = new Messenger(new com.google.android.gms.internal.firebase_messaging.zza(Looper.getMainLooper(), new Handler.Callback(this) { // from class: com.google.firebase.iid.zzae
|
||||
private final zzad a;
|
||||
|
||||
{
|
||||
this.a = this;
|
||||
}
|
||||
|
||||
@Override // android.os.Handler.Callback
|
||||
public final boolean handleMessage(Message message) {
|
||||
return this.a.a(message);
|
||||
}
|
||||
}));
|
||||
this.d = new ArrayDeque();
|
||||
this.e = new SparseArray<>();
|
||||
}
|
||||
|
||||
private final void c() {
|
||||
ScheduledExecutorService scheduledExecutorService;
|
||||
scheduledExecutorService = this.f.b;
|
||||
scheduledExecutorService.execute(new Runnable(this) { // from class: com.google.firebase.iid.zzag
|
||||
private final zzad a;
|
||||
|
||||
{
|
||||
this.a = this;
|
||||
}
|
||||
|
||||
@Override // java.lang.Runnable
|
||||
public final void run() {
|
||||
final zzak<?> poll;
|
||||
ScheduledExecutorService scheduledExecutorService2;
|
||||
Context context;
|
||||
final zzad zzadVar = this.a;
|
||||
while (true) {
|
||||
synchronized (zzadVar) {
|
||||
if (zzadVar.a != 2) {
|
||||
return;
|
||||
}
|
||||
if (zzadVar.d.isEmpty()) {
|
||||
zzadVar.b();
|
||||
return;
|
||||
}
|
||||
poll = zzadVar.d.poll();
|
||||
zzadVar.e.put(poll.a, poll);
|
||||
scheduledExecutorService2 = zzadVar.f.b;
|
||||
scheduledExecutorService2.schedule(new Runnable(zzadVar, poll) { // from class: com.google.firebase.iid.zzah
|
||||
private final zzad a;
|
||||
private final zzak b;
|
||||
|
||||
{
|
||||
this.a = zzadVar;
|
||||
this.b = poll;
|
||||
}
|
||||
|
||||
@Override // java.lang.Runnable
|
||||
public final void run() {
|
||||
this.a.a(this.b.a);
|
||||
}
|
||||
}, 30L, TimeUnit.SECONDS);
|
||||
}
|
||||
if (Log.isLoggable("MessengerIpcClient", 3)) {
|
||||
String valueOf = String.valueOf(poll);
|
||||
StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 8);
|
||||
sb.append("Sending ");
|
||||
sb.append(valueOf);
|
||||
Log.d("MessengerIpcClient", sb.toString());
|
||||
}
|
||||
context = zzadVar.f.a;
|
||||
Messenger messenger = zzadVar.b;
|
||||
Message obtain = Message.obtain();
|
||||
obtain.what = poll.c;
|
||||
obtain.arg1 = poll.a;
|
||||
obtain.replyTo = messenger;
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putBoolean("oneWay", poll.a());
|
||||
bundle.putString("pkg", context.getPackageName());
|
||||
bundle.putBundle("data", poll.d);
|
||||
obtain.setData(bundle);
|
||||
try {
|
||||
zzadVar.c.a(obtain);
|
||||
} catch (RemoteException e) {
|
||||
zzadVar.a(2, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
final synchronized boolean a(zzak zzakVar) {
|
||||
Context context;
|
||||
ScheduledExecutorService scheduledExecutorService;
|
||||
int i = this.a;
|
||||
if (i == 0) {
|
||||
this.d.add(zzakVar);
|
||||
Preconditions.b(this.a == 0);
|
||||
if (Log.isLoggable("MessengerIpcClient", 2)) {
|
||||
Log.v("MessengerIpcClient", "Starting bind to GmsCore");
|
||||
}
|
||||
this.a = 1;
|
||||
Intent intent = new Intent("com.google.android.c2dm.intent.REGISTER");
|
||||
intent.setPackage("com.google.android.gms");
|
||||
ConnectionTracker a = ConnectionTracker.a();
|
||||
context = this.f.a;
|
||||
if (a.a(context, intent, this, 1)) {
|
||||
scheduledExecutorService = this.f.b;
|
||||
scheduledExecutorService.schedule(new Runnable(this) { // from class: com.google.firebase.iid.zzaf
|
||||
private final zzad a;
|
||||
|
||||
{
|
||||
this.a = this;
|
||||
}
|
||||
|
||||
@Override // java.lang.Runnable
|
||||
public final void run() {
|
||||
this.a.a();
|
||||
}
|
||||
}, 30L, TimeUnit.SECONDS);
|
||||
} else {
|
||||
a(0, "Unable to bind to service");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (i == 1) {
|
||||
this.d.add(zzakVar);
|
||||
return true;
|
||||
}
|
||||
if (i == 2) {
|
||||
this.d.add(zzakVar);
|
||||
c();
|
||||
return true;
|
||||
}
|
||||
if (i != 3 && i != 4) {
|
||||
int i2 = this.a;
|
||||
StringBuilder sb = new StringBuilder(26);
|
||||
sb.append("Unknown state: ");
|
||||
sb.append(i2);
|
||||
throw new IllegalStateException(sb.toString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
final synchronized void b() {
|
||||
Context context;
|
||||
if (this.a == 2 && this.d.isEmpty() && this.e.size() == 0) {
|
||||
if (Log.isLoggable("MessengerIpcClient", 2)) {
|
||||
Log.v("MessengerIpcClient", "Finished handling requests, unbinding");
|
||||
}
|
||||
this.a = 3;
|
||||
ConnectionTracker a = ConnectionTracker.a();
|
||||
context = this.f.a;
|
||||
a.a(context, this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // android.content.ServiceConnection
|
||||
public final synchronized void onServiceConnected(ComponentName componentName, IBinder iBinder) {
|
||||
if (Log.isLoggable("MessengerIpcClient", 2)) {
|
||||
Log.v("MessengerIpcClient", "Service connected");
|
||||
}
|
||||
if (iBinder == null) {
|
||||
a(0, "Null service connection");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
this.c = new zzai(iBinder);
|
||||
this.a = 2;
|
||||
c();
|
||||
} catch (RemoteException e) {
|
||||
a(0, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override // android.content.ServiceConnection
|
||||
public final synchronized void onServiceDisconnected(ComponentName componentName) {
|
||||
if (Log.isLoggable("MessengerIpcClient", 2)) {
|
||||
Log.v("MessengerIpcClient", "Service disconnected");
|
||||
}
|
||||
a(2, "Service disconnected");
|
||||
}
|
||||
|
||||
final boolean a(Message message) {
|
||||
int i = message.arg1;
|
||||
if (Log.isLoggable("MessengerIpcClient", 3)) {
|
||||
StringBuilder sb = new StringBuilder(41);
|
||||
sb.append("Received response to request: ");
|
||||
sb.append(i);
|
||||
Log.d("MessengerIpcClient", sb.toString());
|
||||
}
|
||||
synchronized (this) {
|
||||
zzak<?> zzakVar = this.e.get(i);
|
||||
if (zzakVar == null) {
|
||||
StringBuilder sb2 = new StringBuilder(50);
|
||||
sb2.append("Received response for unknown request: ");
|
||||
sb2.append(i);
|
||||
Log.w("MessengerIpcClient", sb2.toString());
|
||||
return true;
|
||||
}
|
||||
this.e.remove(i);
|
||||
b();
|
||||
Bundle data = message.getData();
|
||||
if (data.getBoolean("unsupported", false)) {
|
||||
zzakVar.a(new zzal(4, "Not supported by GmsCore"));
|
||||
} else {
|
||||
zzakVar.a(data);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
final synchronized void a(int i, String str) {
|
||||
Context context;
|
||||
if (Log.isLoggable("MessengerIpcClient", 3)) {
|
||||
String valueOf = String.valueOf(str);
|
||||
Log.d("MessengerIpcClient", valueOf.length() != 0 ? "Disconnected: ".concat(valueOf) : new String("Disconnected: "));
|
||||
}
|
||||
int i2 = this.a;
|
||||
if (i2 == 0) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
if (i2 != 1 && i2 != 2) {
|
||||
if (i2 != 3) {
|
||||
if (i2 == 4) {
|
||||
return;
|
||||
}
|
||||
int i3 = this.a;
|
||||
StringBuilder sb = new StringBuilder(26);
|
||||
sb.append("Unknown state: ");
|
||||
sb.append(i3);
|
||||
throw new IllegalStateException(sb.toString());
|
||||
}
|
||||
this.a = 4;
|
||||
return;
|
||||
}
|
||||
if (Log.isLoggable("MessengerIpcClient", 2)) {
|
||||
Log.v("MessengerIpcClient", "Unbinding service");
|
||||
}
|
||||
this.a = 4;
|
||||
ConnectionTracker a = ConnectionTracker.a();
|
||||
context = this.f.a;
|
||||
a.a(context, this);
|
||||
zzal zzalVar = new zzal(i, str);
|
||||
Iterator<zzak<?>> it = this.d.iterator();
|
||||
while (it.hasNext()) {
|
||||
it.next().a(zzalVar);
|
||||
}
|
||||
this.d.clear();
|
||||
for (int i4 = 0; i4 < this.e.size(); i4++) {
|
||||
this.e.valueAt(i4).a(zzalVar);
|
||||
}
|
||||
this.e.clear();
|
||||
}
|
||||
|
||||
final synchronized void a() {
|
||||
if (this.a == 1) {
|
||||
a(1, "Timed out while binding");
|
||||
}
|
||||
}
|
||||
|
||||
final synchronized void a(int i) {
|
||||
zzak<?> zzakVar = this.e.get(i);
|
||||
if (zzakVar != null) {
|
||||
StringBuilder sb = new StringBuilder(31);
|
||||
sb.append("Timing out request: ");
|
||||
sb.append(i);
|
||||
Log.w("MessengerIpcClient", sb.toString());
|
||||
this.e.remove(i);
|
||||
zzakVar.a(new zzal(3, "Timed out waiting for response"));
|
||||
b();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user