alexandroid/decompiled/jadx/sources/com/google/firebase/messaging/WithinAppServiceConnection.java
KaKi87 a47fad5135 📦 Add decompiled Alexa 2.2.730155.0 (jadx, apktool, Hermes strings)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-07 00:04:16 +01:00

164 lines
6.1 KiB
Java

package com.google.firebase.messaging;
import android.annotation.SuppressLint;
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 androidx.annotation.GuardedBy;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import com.google.android.gms.common.stats.ConnectionTracker;
import com.google.android.gms.common.util.concurrent.NamedThreadFactory;
import com.google.android.gms.tasks.Task;
import com.google.android.gms.tasks.TaskCompletionSource;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.ArrayDeque;
import java.util.Objects;
import java.util.Queue;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
/* loaded from: classes8.dex */
class WithinAppServiceConnection implements ServiceConnection {
@Nullable
private WithinAppServiceBinder binder;
@GuardedBy("this")
private boolean connectionInProgress;
private final Intent connectionIntent;
private final Context context;
private final Queue<BindRequest> intentQueue;
private final ScheduledExecutorService scheduledExecutorService;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
public static class BindRequest {
final Intent intent;
private final TaskCompletionSource<Void> taskCompletionSource = new TaskCompletionSource<>();
public BindRequest(Intent intent) {
this.intent = intent;
}
/* JADX INFO: Access modifiers changed from: private */
public /* synthetic */ void lambda$arrangeTimeout$0() {
Log.w(Constants.TAG, "Service took too long to process intent: " + this.intent.getAction() + " finishing.");
finish();
}
public void arrangeTimeout(ScheduledExecutorService scheduledExecutorService) {
getTask().addOnCompleteListener(scheduledExecutorService, new GmsRpc$$ExternalSyntheticLambda0(scheduledExecutorService.schedule(new SharedPreferencesQueue$$ExternalSyntheticLambda0(this, 1), 20L, TimeUnit.SECONDS), 3));
}
public void finish() {
this.taskCompletionSource.trySetResult(null);
}
public Task<Void> getTask() {
return this.taskCompletionSource.getTask();
}
}
@VisibleForTesting
public WithinAppServiceConnection(Context context, String str, ScheduledExecutorService scheduledExecutorService) {
this.intentQueue = new ArrayDeque();
this.connectionInProgress = false;
Context applicationContext = context.getApplicationContext();
this.context = applicationContext;
this.connectionIntent = new Intent(str).setPackage(applicationContext.getPackageName());
this.scheduledExecutorService = scheduledExecutorService;
}
@GuardedBy("this")
private void finishAllInQueue() {
while (!this.intentQueue.isEmpty()) {
this.intentQueue.poll().finish();
}
}
private synchronized void flushQueue() {
try {
Log.isLoggable(Constants.TAG, 3);
while (!this.intentQueue.isEmpty()) {
Log.isLoggable(Constants.TAG, 3);
WithinAppServiceBinder withinAppServiceBinder = this.binder;
if (withinAppServiceBinder == null || !withinAppServiceBinder.isBinderAlive()) {
startConnectionIfNeeded();
return;
} else {
Log.isLoggable(Constants.TAG, 3);
this.binder.send(this.intentQueue.poll());
}
}
} catch (Throwable th) {
throw th;
}
}
@GuardedBy("this")
private void startConnectionIfNeeded() {
Log.isLoggable(Constants.TAG, 3);
if (this.connectionInProgress) {
return;
}
this.connectionInProgress = true;
try {
} catch (SecurityException e) {
Log.e(Constants.TAG, "Exception while binding the service", e);
}
if (ConnectionTracker.getInstance().bindService(this.context, this.connectionIntent, this, 65)) {
return;
}
Log.e(Constants.TAG, "binding to the service failed");
this.connectionInProgress = false;
finishAllInQueue();
}
@Override // android.content.ServiceConnection
public synchronized void onServiceConnected(ComponentName componentName, IBinder iBinder) {
try {
if (Log.isLoggable(Constants.TAG, 3)) {
Objects.toString(componentName);
}
this.connectionInProgress = false;
if (iBinder instanceof WithinAppServiceBinder) {
this.binder = (WithinAppServiceBinder) iBinder;
flushQueue();
} else {
Log.e(Constants.TAG, "Invalid service connection: " + iBinder);
finishAllInQueue();
}
} catch (Throwable th) {
throw th;
}
}
@Override // android.content.ServiceConnection
public void onServiceDisconnected(ComponentName componentName) {
if (Log.isLoggable(Constants.TAG, 3)) {
Objects.toString(componentName);
}
flushQueue();
}
@CanIgnoreReturnValue
public synchronized Task<Void> sendIntent(Intent intent) {
BindRequest bindRequest;
Log.isLoggable(Constants.TAG, 3);
bindRequest = new BindRequest(intent);
bindRequest.arrangeTimeout(this.scheduledExecutorService);
this.intentQueue.add(bindRequest);
flushQueue();
return bindRequest.getTask();
}
@SuppressLint({"ThreadPoolCreation"})
public WithinAppServiceConnection(Context context, String str) {
this(context, str, new ScheduledThreadPoolExecutor(0, new NamedThreadFactory("Firebase-FirebaseInstanceIdServiceConnection")));
}
}