discord-jadx/app/src/main/java/c/i/a/f/d/b.java

136 lines
5.1 KiB
Java

package c.i.a.f.d;
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.RemoteException;
import android.util.Log;
import androidx.annotation.AnyThread;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.collection.SimpleArrayMap;
import c.d.b.a.a;
import c.i.a.f.n.b0;
import c.i.a.f.n.q;
import com.google.android.gms.cloudmessaging.zza;
import com.google.android.gms.tasks.Task;
import com.google.android.gms.tasks.TaskCompletionSource;
import java.util.Objects;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/* compiled from: com.google.android.gms:play-services-cloud-messaging@@16.0.0 */
public class b {
public static int a;
public static PendingIntent b;
/* renamed from: c reason: collision with root package name */
public final SimpleArrayMap<String, TaskCompletionSource<Bundle>> f1024c = new SimpleArrayMap<>();
public final Context d;
public final r e;
public final ScheduledExecutorService f;
public Messenger g;
public Messenger h;
public zza i;
public b(@NonNull Context context) {
this.d = context;
this.e = new r(context);
this.g = new Messenger(new y(this, Looper.getMainLooper()));
ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1);
scheduledThreadPoolExecutor.setKeepAliveTime(60, TimeUnit.SECONDS);
scheduledThreadPoolExecutor.allowCoreThreadTimeOut(true);
this.f = scheduledThreadPoolExecutor;
}
public final void a(String str, @Nullable Bundle bundle) {
synchronized (this.f1024c) {
TaskCompletionSource<Bundle> remove = this.f1024c.remove(str);
if (remove == null) {
String valueOf = String.valueOf(str);
Log.w("Rpc", valueOf.length() != 0 ? "Missing callback for ".concat(valueOf) : new String("Missing callback for "));
return;
}
remove.a.t(bundle);
}
}
@AnyThread
public final Task<Bundle> b(Bundle bundle) {
String num;
synchronized (b.class) {
int i = a;
a = i + 1;
num = Integer.toString(i);
}
TaskCompletionSource<Bundle> taskCompletionSource = new TaskCompletionSource<>();
synchronized (this.f1024c) {
this.f1024c.put(num, taskCompletionSource);
}
Intent intent = new Intent();
intent.setPackage("com.google.android.gms");
if (this.e.a() == 2) {
intent.setAction("com.google.iid.TOKEN_REQUEST");
} else {
intent.setAction("com.google.android.c2dm.intent.REGISTER");
}
intent.putExtras(bundle);
Context context = this.d;
synchronized (b.class) {
if (b == null) {
Intent intent2 = new Intent();
intent2.setPackage("com.google.example.invalidpackage");
b = PendingIntent.getBroadcast(context, 0, intent2, 0);
}
intent.putExtra("app", b);
}
intent.putExtra("kid", a.f(a.b(num, 5), "|ID|", num, "|"));
if (Log.isLoggable("Rpc", 3)) {
String valueOf = String.valueOf(intent.getExtras());
StringBuilder sb = new StringBuilder(valueOf.length() + 8);
sb.append("Sending ");
sb.append(valueOf);
Log.d("Rpc", sb.toString());
}
intent.putExtra("google.messenger", this.g);
if (!(this.h == null && this.i == null)) {
Message obtain = Message.obtain();
obtain.obj = intent;
try {
Messenger messenger = this.h;
if (messenger != null) {
messenger.send(obtain);
} else {
Messenger messenger2 = this.i.i;
Objects.requireNonNull(messenger2);
messenger2.send(obtain);
}
} catch (RemoteException unused) {
if (Log.isLoggable("Rpc", 3)) {
Log.d("Rpc", "Messenger failed, fallback to startService");
}
}
ScheduledFuture<?> schedule = this.f.schedule(new u(taskCompletionSource), 30, TimeUnit.SECONDS);
b0<Bundle> b0Var = taskCompletionSource.a;
b0Var.b.b(new q(z.i, new x(this, num, schedule)));
b0Var.w();
return taskCompletionSource.a;
}
if (this.e.a() == 2) {
this.d.sendBroadcast(intent);
} else {
this.d.startService(intent);
}
ScheduledFuture<?> schedule = this.f.schedule(new u(taskCompletionSource), 30, TimeUnit.SECONDS);
b0<Bundle> b0Var = taskCompletionSource.a;
b0Var.b.b(new q(z.i, new x(this, num, schedule)));
b0Var.w();
return taskCompletionSource.a;
}
}