jimu-decompiled/sources/com/google/firebase/iid/zzh.java
2025-05-13 19:24:51 +02:00

124 lines
4.7 KiB
Java

package com.google.firebase.iid;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.util.Log;
import com.google.android.gms.common.stats.ConnectionTracker;
import com.google.android.gms.common.util.concurrent.NamedThreadFactory;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
/* loaded from: classes.dex */
public final class zzh implements ServiceConnection {
private final Context a;
private final Intent b;
private final ScheduledExecutorService c;
private final Queue<zzd> d;
private zzf e;
private boolean f;
public zzh(Context context, String str) {
this(context, str, new ScheduledThreadPoolExecutor(0, new NamedThreadFactory("Firebase-FirebaseInstanceIdServiceConnection")));
}
private final void b() {
while (!this.d.isEmpty()) {
this.d.poll().a();
}
}
public final synchronized void a(Intent intent, BroadcastReceiver.PendingResult pendingResult) {
if (Log.isLoggable("EnhancedIntentService", 3)) {
Log.d("EnhancedIntentService", "new intent queued in the bind-strategy delivery");
}
this.d.add(new zzd(intent, pendingResult, this.c));
a();
}
@Override // android.content.ServiceConnection
public final void onServiceConnected(ComponentName componentName, IBinder iBinder) {
synchronized (this) {
this.f = false;
this.e = (zzf) iBinder;
if (Log.isLoggable("EnhancedIntentService", 3)) {
String valueOf = String.valueOf(componentName);
StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 20);
sb.append("onServiceConnected: ");
sb.append(valueOf);
Log.d("EnhancedIntentService", sb.toString());
}
if (iBinder == null) {
Log.e("EnhancedIntentService", "Null service connection");
b();
} else {
a();
}
}
}
@Override // android.content.ServiceConnection
public final void onServiceDisconnected(ComponentName componentName) {
if (Log.isLoggable("EnhancedIntentService", 3)) {
String valueOf = String.valueOf(componentName);
StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 23);
sb.append("onServiceDisconnected: ");
sb.append(valueOf);
Log.d("EnhancedIntentService", sb.toString());
}
a();
}
private zzh(Context context, String str, ScheduledExecutorService scheduledExecutorService) {
this.d = new ArrayDeque();
this.f = false;
this.a = context.getApplicationContext();
this.b = new Intent(str).setPackage(this.a.getPackageName());
this.c = scheduledExecutorService;
}
private final synchronized void a() {
if (Log.isLoggable("EnhancedIntentService", 3)) {
Log.d("EnhancedIntentService", "flush queue called");
}
while (!this.d.isEmpty()) {
if (Log.isLoggable("EnhancedIntentService", 3)) {
Log.d("EnhancedIntentService", "found intent to be delivered");
}
if (this.e != null && this.e.isBinderAlive()) {
if (Log.isLoggable("EnhancedIntentService", 3)) {
Log.d("EnhancedIntentService", "binder is alive, sending the intent.");
}
this.e.a(this.d.poll());
} else {
if (Log.isLoggable("EnhancedIntentService", 3)) {
boolean z = !this.f;
StringBuilder sb = new StringBuilder(39);
sb.append("binder is dead. start connection? ");
sb.append(z);
Log.d("EnhancedIntentService", sb.toString());
}
if (!this.f) {
this.f = true;
try {
} catch (SecurityException e) {
Log.e("EnhancedIntentService", "Exception while binding the service", e);
}
if (ConnectionTracker.a().a(this.a, this.b, this, 65)) {
return;
}
Log.e("EnhancedIntentService", "binding to the service failed");
this.f = false;
b();
}
return;
}
}
}
}