mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-11-13 01:17:17 +01:00
317 lines
14 KiB
Java
317 lines
14 KiB
Java
package com.google.android.gms.cloudmessaging;
|
|
|
|
import android.app.PendingIntent;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.os.Bundle;
|
|
import android.os.Looper;
|
|
import android.os.Message;
|
|
import android.os.Messenger;
|
|
import android.os.Parcelable;
|
|
import android.os.RemoteException;
|
|
import android.util.Log;
|
|
import androidx.annotation.AnyThread;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
import androidx.biometric.ErrorUtils$$ExternalSyntheticOutline0;
|
|
import androidx.collection.SimpleArrayMap;
|
|
import com.google.android.gms.tasks.Continuation;
|
|
import com.google.android.gms.tasks.OnCompleteListener;
|
|
import com.google.android.gms.tasks.SuccessContinuation;
|
|
import com.google.android.gms.tasks.Task;
|
|
import com.google.android.gms.tasks.TaskCompletionSource;
|
|
import com.google.android.gms.tasks.Tasks;
|
|
import defpackage.a$$ExternalSyntheticOutline0;
|
|
import java.io.IOException;
|
|
import java.util.concurrent.Executor;
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
import java.util.concurrent.ScheduledFuture;
|
|
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
import javax.annotation.concurrent.GuardedBy;
|
|
import okio.Buffer$$ExternalSyntheticBUOutline0;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
/* loaded from: classes7.dex */
|
|
public class Rpc {
|
|
private static int zza;
|
|
private static PendingIntent zzb;
|
|
private static final Executor zzc = new Executor() { // from class: com.google.android.gms.cloudmessaging.zzz
|
|
@Override // java.util.concurrent.Executor
|
|
public final void execute(Runnable runnable) {
|
|
runnable.run();
|
|
}
|
|
};
|
|
private static final Pattern zzd = Pattern.compile("\\|ID\\|([^|]+)\\|:?+(.*)");
|
|
private final Context zzf;
|
|
private final zzt zzg;
|
|
private final ScheduledExecutorService zzh;
|
|
private Messenger zzj;
|
|
private zzd zzk;
|
|
|
|
@GuardedBy("responseCallbacks")
|
|
private final SimpleArrayMap<String, TaskCompletionSource<Bundle>> zze = new SimpleArrayMap<>();
|
|
private Messenger zzi = new Messenger(new zzaa(this, Looper.getMainLooper()));
|
|
|
|
public Rpc(@NonNull Context context) {
|
|
this.zzf = context;
|
|
this.zzg = new zzt(context);
|
|
ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1);
|
|
scheduledThreadPoolExecutor.setKeepAliveTime(60L, TimeUnit.SECONDS);
|
|
scheduledThreadPoolExecutor.allowCoreThreadTimeOut(true);
|
|
this.zzh = scheduledThreadPoolExecutor;
|
|
}
|
|
|
|
public static /* synthetic */ Task zza(Bundle bundle) throws Exception {
|
|
return zzi(bundle) ? Tasks.forResult(null) : Tasks.forResult(bundle);
|
|
}
|
|
|
|
public static /* bridge */ /* synthetic */ void zzc(Rpc rpc, Message message) {
|
|
if (message != null) {
|
|
Object obj = message.obj;
|
|
if (obj instanceof Intent) {
|
|
Intent intent = (Intent) obj;
|
|
intent.setExtrasClassLoader(new zzc());
|
|
if (intent.hasExtra("google.messenger")) {
|
|
Parcelable parcelableExtra = intent.getParcelableExtra("google.messenger");
|
|
if (parcelableExtra instanceof zzd) {
|
|
rpc.zzk = (zzd) parcelableExtra;
|
|
}
|
|
if (parcelableExtra instanceof Messenger) {
|
|
rpc.zzj = (Messenger) parcelableExtra;
|
|
}
|
|
}
|
|
Intent intent2 = (Intent) message.obj;
|
|
String action = intent2.getAction();
|
|
if (!"com.google.android.c2dm.intent.REGISTRATION".equals(action)) {
|
|
if (Log.isLoggable("Rpc", 3)) {
|
|
String valueOf = String.valueOf(action);
|
|
if (valueOf.length() != 0) {
|
|
"Unexpected response action: ".concat(valueOf);
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
String stringExtra = intent2.getStringExtra("registration_id");
|
|
if (stringExtra == null) {
|
|
stringExtra = intent2.getStringExtra("unregistered");
|
|
}
|
|
if (stringExtra != null) {
|
|
Matcher matcher = zzd.matcher(stringExtra);
|
|
if (!matcher.matches()) {
|
|
if (!Log.isLoggable("Rpc", 3) || stringExtra.length() == 0) {
|
|
return;
|
|
}
|
|
"Unexpected response string: ".concat(stringExtra);
|
|
return;
|
|
}
|
|
String group = matcher.group(1);
|
|
String group2 = matcher.group(2);
|
|
if (group != null) {
|
|
Bundle extras = intent2.getExtras();
|
|
extras.putString("registration_id", group2);
|
|
rpc.zzh(group, extras);
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
String stringExtra2 = intent2.getStringExtra("error");
|
|
if (stringExtra2 == null) {
|
|
String valueOf2 = String.valueOf(intent2.getExtras());
|
|
a$$ExternalSyntheticOutline0.m(new StringBuilder(valueOf2.length() + 49), "Unexpected response, no error or registration id ", valueOf2, "Rpc");
|
|
return;
|
|
}
|
|
if (Log.isLoggable("Rpc", 3) && stringExtra2.length() != 0) {
|
|
"Received InstanceID error ".concat(stringExtra2);
|
|
}
|
|
if (!stringExtra2.startsWith("|")) {
|
|
synchronized (rpc.zze) {
|
|
for (int i = 0; i < rpc.zze.getSize(); i++) {
|
|
try {
|
|
rpc.zzh(rpc.zze.keyAt(i), intent2.getExtras());
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
String[] split = stringExtra2.split("\\|");
|
|
if (split.length <= 2 || !"ID".equals(split[1])) {
|
|
Log.w("Rpc", stringExtra2.length() != 0 ? "Unexpected structured response ".concat(stringExtra2) : new String("Unexpected structured response "));
|
|
return;
|
|
}
|
|
String str = split[2];
|
|
String str2 = split[3];
|
|
if (str2.startsWith(":")) {
|
|
str2 = str2.substring(1);
|
|
}
|
|
rpc.zzh(str, intent2.putExtra("error", str2).getExtras());
|
|
return;
|
|
}
|
|
}
|
|
Log.w("Rpc", "Dropping invalid message");
|
|
}
|
|
|
|
@AnyThread
|
|
private final Task<Bundle> zze(Bundle bundle) {
|
|
final String zzf = zzf();
|
|
final TaskCompletionSource<Bundle> taskCompletionSource = new TaskCompletionSource<>();
|
|
synchronized (this.zze) {
|
|
this.zze.put(zzf, taskCompletionSource);
|
|
}
|
|
Intent intent = new Intent();
|
|
intent.setPackage("com.google.android.gms");
|
|
if (this.zzg.zzb() == 2) {
|
|
intent.setAction("com.google.iid.TOKEN_REQUEST");
|
|
} else {
|
|
intent.setAction("com.google.android.c2dm.intent.REGISTER");
|
|
}
|
|
intent.putExtras(bundle);
|
|
zzg(this.zzf, intent);
|
|
intent.putExtra("kid", ErrorUtils$$ExternalSyntheticOutline0.m(new StringBuilder(String.valueOf(zzf).length() + 5), "|ID|", zzf, "|"));
|
|
if (Log.isLoggable("Rpc", 3)) {
|
|
new StringBuilder(String.valueOf(intent.getExtras()).length() + 8);
|
|
}
|
|
intent.putExtra("google.messenger", this.zzi);
|
|
if (this.zzj != null || this.zzk != null) {
|
|
Message obtain = Message.obtain();
|
|
obtain.obj = intent;
|
|
try {
|
|
Messenger messenger = this.zzj;
|
|
if (messenger != null) {
|
|
messenger.send(obtain);
|
|
} else {
|
|
this.zzk.zzb(obtain);
|
|
}
|
|
} catch (RemoteException unused) {
|
|
Log.isLoggable("Rpc", 3);
|
|
}
|
|
final ScheduledFuture<?> schedule = this.zzh.schedule(new Runnable() { // from class: com.google.android.gms.cloudmessaging.zzy
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
if (TaskCompletionSource.this.trySetException(new IOException("TIMEOUT"))) {
|
|
Log.w("Rpc", "No response");
|
|
}
|
|
}
|
|
}, 30L, TimeUnit.SECONDS);
|
|
taskCompletionSource.getTask().addOnCompleteListener(zzc, new OnCompleteListener() { // from class: com.google.android.gms.cloudmessaging.zzw
|
|
@Override // com.google.android.gms.tasks.OnCompleteListener
|
|
public final void onComplete(Task task) {
|
|
Rpc.this.zzd(zzf, schedule, task);
|
|
}
|
|
});
|
|
return taskCompletionSource.getTask();
|
|
}
|
|
int zzb2 = this.zzg.zzb();
|
|
Context context = this.zzf;
|
|
if (zzb2 == 2) {
|
|
context.sendBroadcast(intent);
|
|
} else {
|
|
context.startService(intent);
|
|
}
|
|
final ScheduledFuture schedule2 = this.zzh.schedule(new Runnable() { // from class: com.google.android.gms.cloudmessaging.zzy
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
if (TaskCompletionSource.this.trySetException(new IOException("TIMEOUT"))) {
|
|
Log.w("Rpc", "No response");
|
|
}
|
|
}
|
|
}, 30L, TimeUnit.SECONDS);
|
|
taskCompletionSource.getTask().addOnCompleteListener(zzc, new OnCompleteListener() { // from class: com.google.android.gms.cloudmessaging.zzw
|
|
@Override // com.google.android.gms.tasks.OnCompleteListener
|
|
public final void onComplete(Task task) {
|
|
Rpc.this.zzd(zzf, schedule2, task);
|
|
}
|
|
});
|
|
return taskCompletionSource.getTask();
|
|
}
|
|
|
|
private static synchronized String zzf() {
|
|
String num;
|
|
synchronized (Rpc.class) {
|
|
int i = zza;
|
|
zza = i + 1;
|
|
num = Integer.toString(i);
|
|
}
|
|
return num;
|
|
}
|
|
|
|
private static synchronized void zzg(Context context, Intent intent) {
|
|
synchronized (Rpc.class) {
|
|
try {
|
|
if (zzb == null) {
|
|
Intent intent2 = new Intent();
|
|
intent2.setPackage("com.google.example.invalidpackage");
|
|
zzb = com.google.android.gms.internal.cloudmessaging.zza.zza(context, 0, intent2, com.google.android.gms.internal.cloudmessaging.zza.zza);
|
|
}
|
|
intent.putExtra("app", zzb);
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
}
|
|
}
|
|
|
|
private final void zzh(String str, @Nullable Bundle bundle) {
|
|
synchronized (this.zze) {
|
|
try {
|
|
TaskCompletionSource<Bundle> remove = this.zze.remove(str);
|
|
if (remove != null) {
|
|
remove.setResult(bundle);
|
|
} else {
|
|
String valueOf = String.valueOf(str);
|
|
Log.w("Rpc", valueOf.length() != 0 ? "Missing callback for ".concat(valueOf) : new String("Missing callback for "));
|
|
}
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
}
|
|
}
|
|
|
|
private static boolean zzi(Bundle bundle) {
|
|
return bundle != null && bundle.containsKey("google.messenger");
|
|
}
|
|
|
|
@NonNull
|
|
public Task<Bundle> send(@NonNull final Bundle bundle) {
|
|
return this.zzg.zza() < 12000000 ? this.zzg.zzb() != 0 ? zze(bundle).continueWithTask(zzc, new Continuation() { // from class: com.google.android.gms.cloudmessaging.zzu
|
|
@Override // com.google.android.gms.tasks.Continuation
|
|
public final Object then(Task task) {
|
|
return Rpc.this.zzb(bundle, task);
|
|
}
|
|
}) : Tasks.forException(new IOException("MISSING_INSTANCEID_SERVICE")) : zzs.zzb(this.zzf).zzd(1, bundle).continueWith(zzc, new Continuation() { // from class: com.google.android.gms.cloudmessaging.zzv
|
|
@Override // com.google.android.gms.tasks.Continuation
|
|
public final Object then(Task task) {
|
|
if (task.isSuccessful()) {
|
|
return (Bundle) task.getResult();
|
|
}
|
|
if (Log.isLoggable("Rpc", 3)) {
|
|
new StringBuilder(String.valueOf(task.getException()).length() + 22);
|
|
}
|
|
Buffer$$ExternalSyntheticBUOutline0.m("SERVICE_NOT_AVAILABLE", task.getException());
|
|
return null;
|
|
}
|
|
});
|
|
}
|
|
|
|
@NonNull
|
|
public final /* synthetic */ Task zzb(@NonNull Bundle bundle, @NonNull Task task) throws Exception {
|
|
return (task.isSuccessful() && zzi((Bundle) task.getResult())) ? zze(bundle).onSuccessTask(zzc, new SuccessContinuation() { // from class: com.google.android.gms.cloudmessaging.zzx
|
|
@Override // com.google.android.gms.tasks.SuccessContinuation
|
|
public final Task then(Object obj) {
|
|
return Rpc.zza((Bundle) obj);
|
|
}
|
|
}) : task;
|
|
}
|
|
|
|
public final /* synthetic */ void zzd(@NonNull String str, @NonNull ScheduledFuture scheduledFuture, @NonNull Task task) {
|
|
synchronized (this.zze) {
|
|
this.zze.remove(str);
|
|
}
|
|
scheduledFuture.cancel(false);
|
|
}
|
|
}
|