- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
273 lines
12 KiB
Java
273 lines
12 KiB
Java
package com.google.firebase.messaging;
|
|
|
|
import android.content.Context;
|
|
import android.util.Log;
|
|
import androidx.collection.ArrayMap;
|
|
import com.google.android.gms.tasks.Task;
|
|
import com.google.android.gms.tasks.TaskCompletionSource;
|
|
import com.google.android.gms.tasks.Tasks;
|
|
import java.io.IOException;
|
|
import java.util.ArrayDeque;
|
|
import java.util.Map;
|
|
import java.util.concurrent.Callable;
|
|
import java.util.concurrent.ExecutionException;
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeoutException;
|
|
|
|
/* loaded from: classes3.dex */
|
|
public class TopicsSubscriber {
|
|
public static final long MAX_DELAY_SEC = TimeUnit.HOURS.toSeconds(8);
|
|
public final Context context;
|
|
public final FirebaseMessaging firebaseMessaging;
|
|
public final Metadata metadata;
|
|
public final GmsRpc rpc;
|
|
public final TopicsStore store;
|
|
public final ScheduledExecutorService syncExecutor;
|
|
public final Map pendingOperations = new ArrayMap();
|
|
public boolean syncScheduledOrRunning = false;
|
|
|
|
public static Task createInstance(final FirebaseMessaging firebaseMessaging, final Metadata metadata, final GmsRpc gmsRpc, final Context context, final ScheduledExecutorService scheduledExecutorService) {
|
|
return Tasks.call(scheduledExecutorService, new Callable() { // from class: com.google.firebase.messaging.TopicsSubscriber$$ExternalSyntheticLambda0
|
|
@Override // java.util.concurrent.Callable
|
|
public final Object call() {
|
|
TopicsSubscriber lambda$createInstance$0;
|
|
lambda$createInstance$0 = TopicsSubscriber.lambda$createInstance$0(context, scheduledExecutorService, firebaseMessaging, metadata, gmsRpc);
|
|
return lambda$createInstance$0;
|
|
}
|
|
});
|
|
}
|
|
|
|
public static /* synthetic */ TopicsSubscriber lambda$createInstance$0(Context context, ScheduledExecutorService scheduledExecutorService, FirebaseMessaging firebaseMessaging, Metadata metadata, GmsRpc gmsRpc) {
|
|
return new TopicsSubscriber(firebaseMessaging, metadata, TopicsStore.getInstance(context, scheduledExecutorService), gmsRpc, context, scheduledExecutorService);
|
|
}
|
|
|
|
public TopicsSubscriber(FirebaseMessaging firebaseMessaging, Metadata metadata, TopicsStore topicsStore, GmsRpc gmsRpc, Context context, ScheduledExecutorService scheduledExecutorService) {
|
|
this.firebaseMessaging = firebaseMessaging;
|
|
this.metadata = metadata;
|
|
this.store = topicsStore;
|
|
this.rpc = gmsRpc;
|
|
this.context = context;
|
|
this.syncExecutor = scheduledExecutorService;
|
|
}
|
|
|
|
public boolean hasPendingOperation() {
|
|
return this.store.getNextTopicOperation() != null;
|
|
}
|
|
|
|
public void startTopicsSyncIfNecessary() {
|
|
if (hasPendingOperation()) {
|
|
startSync();
|
|
}
|
|
}
|
|
|
|
public final void startSync() {
|
|
if (isSyncScheduledOrRunning()) {
|
|
return;
|
|
}
|
|
syncWithDelaySecondsInternal(0L);
|
|
}
|
|
|
|
public void syncWithDelaySecondsInternal(long j) {
|
|
scheduleSyncTaskWithDelaySeconds(new TopicsSyncTask(this, this.context, this.metadata, Math.min(Math.max(30L, 2 * j), MAX_DELAY_SEC)), j);
|
|
setSyncScheduledOrRunning(true);
|
|
}
|
|
|
|
public void scheduleSyncTaskWithDelaySeconds(Runnable runnable, long j) {
|
|
this.syncExecutor.schedule(runnable, j, TimeUnit.SECONDS);
|
|
}
|
|
|
|
public boolean syncTopics() {
|
|
while (true) {
|
|
synchronized (this) {
|
|
try {
|
|
TopicOperation nextTopicOperation = this.store.getNextTopicOperation();
|
|
if (nextTopicOperation == null) {
|
|
isDebugLogEnabled();
|
|
return true;
|
|
}
|
|
if (!performTopicOperation(nextTopicOperation)) {
|
|
return false;
|
|
}
|
|
this.store.removeTopicOperation(nextTopicOperation);
|
|
markCompletePendingOperation(nextTopicOperation);
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public final void markCompletePendingOperation(TopicOperation topicOperation) {
|
|
synchronized (this.pendingOperations) {
|
|
try {
|
|
String serialize = topicOperation.serialize();
|
|
if (this.pendingOperations.containsKey(serialize)) {
|
|
ArrayDeque arrayDeque = (ArrayDeque) this.pendingOperations.get(serialize);
|
|
TaskCompletionSource taskCompletionSource = (TaskCompletionSource) arrayDeque.poll();
|
|
if (taskCompletionSource != null) {
|
|
taskCompletionSource.setResult(null);
|
|
}
|
|
if (arrayDeque.isEmpty()) {
|
|
this.pendingOperations.remove(serialize);
|
|
}
|
|
}
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
}
|
|
}
|
|
|
|
/* JADX WARN: Removed duplicated region for block: B:11:0x002e */
|
|
/* JADX WARN: Removed duplicated region for block: B:20:0x006b A[Catch: IOException -> 0x001d, TryCatch #0 {IOException -> 0x001d, blocks: (B:3:0x0001, B:12:0x0030, B:14:0x0036, B:17:0x0049, B:19:0x0056, B:20:0x006b, B:22:0x0078, B:23:0x0013, B:26:0x001f), top: B:2:0x0001 }] */
|
|
/*
|
|
Code decompiled incorrectly, please refer to instructions dump.
|
|
To view partially-correct add '--show-bad-code' argument
|
|
*/
|
|
public boolean performTopicOperation(com.google.firebase.messaging.TopicOperation r6) {
|
|
/*
|
|
r5 = this;
|
|
r0 = 0
|
|
java.lang.String r1 = r6.getOperation() // Catch: java.io.IOException -> L1d
|
|
int r2 = r1.hashCode() // Catch: java.io.IOException -> L1d
|
|
r3 = 83
|
|
r4 = 1
|
|
if (r2 == r3) goto L1f
|
|
r3 = 85
|
|
if (r2 == r3) goto L13
|
|
goto L29
|
|
L13:
|
|
java.lang.String r2 = "U"
|
|
boolean r1 = r1.equals(r2) // Catch: java.io.IOException -> L1d
|
|
if (r1 == 0) goto L29
|
|
r1 = r4
|
|
goto L2a
|
|
L1d:
|
|
r6 = move-exception
|
|
goto L8d
|
|
L1f:
|
|
java.lang.String r2 = "S"
|
|
boolean r1 = r1.equals(r2) // Catch: java.io.IOException -> L1d
|
|
if (r1 == 0) goto L29
|
|
r1 = r0
|
|
goto L2a
|
|
L29:
|
|
r1 = -1
|
|
L2a:
|
|
java.lang.String r2 = " succeeded."
|
|
if (r1 == 0) goto L6b
|
|
if (r1 == r4) goto L49
|
|
boolean r1 = isDebugLogEnabled() // Catch: java.io.IOException -> L1d
|
|
if (r1 == 0) goto L8c
|
|
java.lang.StringBuilder r1 = new java.lang.StringBuilder // Catch: java.io.IOException -> L1d
|
|
r1.<init>() // Catch: java.io.IOException -> L1d
|
|
java.lang.String r2 = "Unknown topic operation"
|
|
r1.append(r2) // Catch: java.io.IOException -> L1d
|
|
r1.append(r6) // Catch: java.io.IOException -> L1d
|
|
java.lang.String r6 = "."
|
|
r1.append(r6) // Catch: java.io.IOException -> L1d
|
|
goto L8c
|
|
L49:
|
|
java.lang.String r1 = r6.getTopic() // Catch: java.io.IOException -> L1d
|
|
r5.blockingUnsubscribeFromTopic(r1) // Catch: java.io.IOException -> L1d
|
|
boolean r1 = isDebugLogEnabled() // Catch: java.io.IOException -> L1d
|
|
if (r1 == 0) goto L8c
|
|
java.lang.StringBuilder r1 = new java.lang.StringBuilder // Catch: java.io.IOException -> L1d
|
|
r1.<init>() // Catch: java.io.IOException -> L1d
|
|
java.lang.String r3 = "Unsubscribe from topic: "
|
|
r1.append(r3) // Catch: java.io.IOException -> L1d
|
|
java.lang.String r6 = r6.getTopic() // Catch: java.io.IOException -> L1d
|
|
r1.append(r6) // Catch: java.io.IOException -> L1d
|
|
r1.append(r2) // Catch: java.io.IOException -> L1d
|
|
goto L8c
|
|
L6b:
|
|
java.lang.String r1 = r6.getTopic() // Catch: java.io.IOException -> L1d
|
|
r5.blockingSubscribeToTopic(r1) // Catch: java.io.IOException -> L1d
|
|
boolean r1 = isDebugLogEnabled() // Catch: java.io.IOException -> L1d
|
|
if (r1 == 0) goto L8c
|
|
java.lang.StringBuilder r1 = new java.lang.StringBuilder // Catch: java.io.IOException -> L1d
|
|
r1.<init>() // Catch: java.io.IOException -> L1d
|
|
java.lang.String r3 = "Subscribe to topic: "
|
|
r1.append(r3) // Catch: java.io.IOException -> L1d
|
|
java.lang.String r6 = r6.getTopic() // Catch: java.io.IOException -> L1d
|
|
r1.append(r6) // Catch: java.io.IOException -> L1d
|
|
r1.append(r2) // Catch: java.io.IOException -> L1d
|
|
L8c:
|
|
return r4
|
|
L8d:
|
|
java.lang.String r1 = "SERVICE_NOT_AVAILABLE"
|
|
java.lang.String r2 = r6.getMessage()
|
|
boolean r1 = r1.equals(r2)
|
|
java.lang.String r2 = "FirebaseMessaging"
|
|
if (r1 != 0) goto Lb5
|
|
java.lang.String r1 = "INTERNAL_SERVER_ERROR"
|
|
java.lang.String r3 = r6.getMessage()
|
|
boolean r1 = r1.equals(r3)
|
|
if (r1 == 0) goto La8
|
|
goto Lb5
|
|
La8:
|
|
java.lang.String r1 = r6.getMessage()
|
|
if (r1 != 0) goto Lb4
|
|
java.lang.String r6 = "Topic operation failed without exception message. Will retry Topic operation."
|
|
android.util.Log.e(r2, r6)
|
|
return r0
|
|
Lb4:
|
|
throw r6
|
|
Lb5:
|
|
java.lang.StringBuilder r1 = new java.lang.StringBuilder
|
|
r1.<init>()
|
|
java.lang.String r3 = "Topic operation failed: "
|
|
r1.append(r3)
|
|
java.lang.String r6 = r6.getMessage()
|
|
r1.append(r6)
|
|
java.lang.String r6 = ". Will retry Topic operation."
|
|
r1.append(r6)
|
|
java.lang.String r6 = r1.toString()
|
|
android.util.Log.e(r2, r6)
|
|
return r0
|
|
*/
|
|
throw new UnsupportedOperationException("Method not decompiled: com.google.firebase.messaging.TopicsSubscriber.performTopicOperation(com.google.firebase.messaging.TopicOperation):boolean");
|
|
}
|
|
|
|
public final void blockingSubscribeToTopic(String str) {
|
|
awaitTask(this.rpc.subscribeToTopic(this.firebaseMessaging.blockingGetToken(), str));
|
|
}
|
|
|
|
public final void blockingUnsubscribeFromTopic(String str) {
|
|
awaitTask(this.rpc.unsubscribeFromTopic(this.firebaseMessaging.blockingGetToken(), str));
|
|
}
|
|
|
|
public static void awaitTask(Task task) {
|
|
try {
|
|
Tasks.await(task, 30L, TimeUnit.SECONDS);
|
|
} catch (InterruptedException e) {
|
|
e = e;
|
|
throw new IOException("SERVICE_NOT_AVAILABLE", e);
|
|
} catch (ExecutionException e2) {
|
|
Throwable cause = e2.getCause();
|
|
if (cause instanceof IOException) {
|
|
throw ((IOException) cause);
|
|
}
|
|
if (cause instanceof RuntimeException) {
|
|
throw ((RuntimeException) cause);
|
|
}
|
|
throw new IOException(e2);
|
|
} catch (TimeoutException e3) {
|
|
e = e3;
|
|
throw new IOException("SERVICE_NOT_AVAILABLE", e);
|
|
}
|
|
}
|
|
|
|
public synchronized boolean isSyncScheduledOrRunning() {
|
|
return this.syncScheduledOrRunning;
|
|
}
|
|
|
|
public synchronized void setSyncScheduledOrRunning(boolean z) {
|
|
this.syncScheduledOrRunning = z;
|
|
}
|
|
|
|
public static boolean isDebugLogEnabled() {
|
|
return Log.isLoggable("FirebaseMessaging", 3);
|
|
}
|
|
}
|