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

389 lines
13 KiB
Java

package com.google.firebase.iid;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Build;
import android.os.Looper;
import android.util.Log;
import androidx.annotation.Keep;
import com.google.android.gms.common.util.concurrent.NamedThreadFactory;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.android.gms.tasks.TaskCompletionSource;
import com.google.android.gms.tasks.Tasks;
import com.google.firebase.DataCollectionDefaultChange;
import com.google.firebase.FirebaseApp;
import com.google.firebase.events.Event;
import com.google.firebase.events.EventHandler;
import com.google.firebase.events.Subscriber;
import com.google.firebase.iid.FirebaseInstanceId;
import com.ubtrobot.jimu.robotapi.PeripheralType;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
/* loaded from: classes.dex */
public class FirebaseInstanceId {
private static final long i = TimeUnit.HOURS.toSeconds(8);
private static zzaw j;
private static ScheduledThreadPoolExecutor k;
private final Executor a;
private final FirebaseApp b;
private final zzan c;
private MessagingChannel d;
private final zzaq e;
private final zzba f;
private boolean g;
private final zza h;
/* JADX INFO: Access modifiers changed from: private */
class zza {
private EventHandler<DataCollectionDefaultChange> b;
private final boolean a = c();
private Boolean c = b();
zza(Subscriber subscriber) {
if (this.c == null && this.a) {
this.b = new EventHandler(this) { // from class: com.google.firebase.iid.zzq
private final FirebaseInstanceId.zza a;
{
this.a = this;
}
@Override // com.google.firebase.events.EventHandler
public final void a(Event event) {
FirebaseInstanceId.zza zzaVar = this.a;
synchronized (zzaVar) {
if (zzaVar.a()) {
FirebaseInstanceId.this.l();
}
}
}
};
subscriber.a(DataCollectionDefaultChange.class, this.b);
}
}
private final Boolean b() {
ApplicationInfo applicationInfo;
Context a = FirebaseInstanceId.this.b.a();
SharedPreferences sharedPreferences = a.getSharedPreferences("com.google.firebase.messaging", 0);
if (sharedPreferences.contains("auto_init")) {
return Boolean.valueOf(sharedPreferences.getBoolean("auto_init", false));
}
try {
PackageManager packageManager = a.getPackageManager();
if (packageManager == null || (applicationInfo = packageManager.getApplicationInfo(a.getPackageName(), PeripheralType.SERVO)) == null || applicationInfo.metaData == null || !applicationInfo.metaData.containsKey("firebase_messaging_auto_init_enabled")) {
return null;
}
return Boolean.valueOf(applicationInfo.metaData.getBoolean("firebase_messaging_auto_init_enabled"));
} catch (PackageManager.NameNotFoundException unused) {
return null;
}
}
private final boolean c() {
try {
Class.forName("com.google.firebase.messaging.FirebaseMessaging");
return true;
} catch (ClassNotFoundException unused) {
Context a = FirebaseInstanceId.this.b.a();
Intent intent = new Intent("com.google.firebase.MESSAGING_EVENT");
intent.setPackage(a.getPackageName());
ResolveInfo resolveService = a.getPackageManager().resolveService(intent, 0);
return (resolveService == null || resolveService.serviceInfo == null) ? false : true;
}
}
final synchronized boolean a() {
if (this.c != null) {
return this.c.booleanValue();
}
return this.a && FirebaseInstanceId.this.b.d();
}
}
FirebaseInstanceId(FirebaseApp firebaseApp, Subscriber subscriber) {
this(firebaseApp, new zzan(firebaseApp.a()), zzi.b(), zzi.b(), subscriber);
}
@Keep
public static synchronized FirebaseInstanceId getInstance(FirebaseApp firebaseApp) {
FirebaseInstanceId firebaseInstanceId;
synchronized (FirebaseInstanceId.class) {
firebaseInstanceId = (FirebaseInstanceId) firebaseApp.a(FirebaseInstanceId.class);
}
return firebaseInstanceId;
}
public static FirebaseInstanceId j() {
return getInstance(FirebaseApp.f());
}
private final synchronized void k() {
if (!this.g) {
a(0L);
}
}
/* JADX INFO: Access modifiers changed from: private */
public final void l() {
zzax c = c();
if (!g() || c == null || c.a(this.c.b()) || this.f.a()) {
k();
}
}
private static String m() {
return zzan.a(j.b("").a());
}
static boolean n() {
if (Log.isLoggable("FirebaseInstanceId", 3)) {
return true;
}
return Build.VERSION.SDK_INT == 23 && Log.isLoggable("FirebaseInstanceId", 3);
}
final synchronized void a(boolean z) {
this.g = z;
}
final FirebaseApp b() {
return this.b;
}
final zzax c() {
return c(zzan.a(this.b), "*");
}
final String d() throws IOException {
return a(zzan.a(this.b), "*");
}
final synchronized void e() {
j.b();
if (this.h.a()) {
k();
}
}
final boolean f() {
return this.d.b();
}
final boolean g() {
return this.d.a();
}
final void h() throws IOException {
a(this.d.a(m(), zzax.a(c())));
}
final void i() {
j.c("");
k();
}
private final Task<InstanceIdResult> b(final String str, final String str2) {
final String c = c(str2);
final TaskCompletionSource taskCompletionSource = new TaskCompletionSource();
this.a.execute(new Runnable(this, str, str2, taskCompletionSource, c) { // from class: com.google.firebase.iid.zzn
private final FirebaseInstanceId a;
private final String b;
private final String c;
private final TaskCompletionSource d;
private final String e;
{
this.a = this;
this.b = str;
this.c = str2;
this.d = taskCompletionSource;
this.e = c;
}
@Override // java.lang.Runnable
public final void run() {
this.a.a(this.b, this.c, this.d, this.e);
}
});
return taskCompletionSource.a();
}
private static zzax c(String str, String str2) {
return j.a("", str, str2);
}
private static String c(String str) {
return (str.isEmpty() || str.equalsIgnoreCase("fcm") || str.equalsIgnoreCase("gcm")) ? "*" : str;
}
final synchronized void a(long j2) {
a(new zzay(this, this.c, this.f, Math.min(Math.max(30L, j2 << 1), i)), j2);
this.g = true;
}
private FirebaseInstanceId(FirebaseApp firebaseApp, zzan zzanVar, Executor executor, Executor executor2, Subscriber subscriber) {
this.g = false;
if (zzan.a(firebaseApp) != null) {
synchronized (FirebaseInstanceId.class) {
if (j == null) {
j = new zzaw(firebaseApp.a());
}
}
this.b = firebaseApp;
this.c = zzanVar;
if (this.d == null) {
MessagingChannel messagingChannel = (MessagingChannel) firebaseApp.a(MessagingChannel.class);
if (messagingChannel != null && messagingChannel.b()) {
this.d = messagingChannel;
} else {
this.d = new zzr(firebaseApp, zzanVar, executor);
}
}
this.d = this.d;
this.a = executor2;
this.f = new zzba(j);
this.h = new zza(subscriber);
this.e = new zzaq(executor);
if (this.h.a()) {
l();
return;
}
return;
}
throw new IllegalStateException("FirebaseInstanceId failed to initialize, FirebaseApp is missing project ID");
}
final void b(String str) throws IOException {
zzax c = c();
if (c != null && !c.a(this.c.b())) {
a(this.d.a(m(), c.a, str));
return;
}
throw new IOException("token not available");
}
static void a(Runnable runnable, long j2) {
synchronized (FirebaseInstanceId.class) {
if (k == null) {
k = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory("FirebaseInstanceId"));
}
k.schedule(runnable, j2, TimeUnit.SECONDS);
}
}
public String a() {
l();
return m();
}
public String a(String str, String str2) throws IOException {
if (Looper.getMainLooper() != Looper.myLooper()) {
return ((InstanceIdResult) a(b(str, str2))).a();
}
throw new IOException("MAIN_THREAD");
}
private final <T> T a(Task<T> task) throws IOException {
try {
return (T) Tasks.a(task, 30000L, TimeUnit.MILLISECONDS);
} catch (InterruptedException | TimeoutException unused) {
throw new IOException("SERVICE_NOT_AVAILABLE");
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof IOException) {
if ("INSTANCE_ID_RESET".equals(cause.getMessage())) {
e();
}
throw ((IOException) cause);
}
if (cause instanceof RuntimeException) {
throw ((RuntimeException) cause);
}
throw new IOException(e);
}
}
final void a(String str) throws IOException {
zzax c = c();
if (c != null && !c.a(this.c.b())) {
a(this.d.b(m(), c.a, str));
return;
}
throw new IOException("token not available");
}
final /* synthetic */ void a(final String str, String str2, final TaskCompletionSource taskCompletionSource, final String str3) {
final String m = m();
zzax c = c(str, str2);
if (c != null && !c.a(this.c.b())) {
taskCompletionSource.a((TaskCompletionSource) new zzx(m, c.a));
} else {
final String a = zzax.a(c);
this.e.a(str, str3, new zzas(this, m, a, str, str3) { // from class: com.google.firebase.iid.zzo
private final FirebaseInstanceId a;
private final String b;
private final String c;
private final String d;
private final String e;
{
this.a = this;
this.b = m;
this.c = a;
this.d = str;
this.e = str3;
}
@Override // com.google.firebase.iid.zzas
public final Task a() {
return this.a.a(this.b, this.c, this.d, this.e);
}
}).a(this.a, new OnCompleteListener(this, str, str3, taskCompletionSource, m) { // from class: com.google.firebase.iid.zzp
private final FirebaseInstanceId a;
private final String b;
private final String c;
private final TaskCompletionSource d;
private final String e;
{
this.a = this;
this.b = str;
this.c = str3;
this.d = taskCompletionSource;
this.e = m;
}
@Override // com.google.android.gms.tasks.OnCompleteListener
public final void a(Task task) {
this.a.a(this.b, this.c, this.d, this.e, task);
}
});
}
}
final /* synthetic */ void a(String str, String str2, TaskCompletionSource taskCompletionSource, String str3, Task task) {
if (task.e()) {
String str4 = (String) task.b();
j.a("", str, str2, str4, this.c.b());
taskCompletionSource.a((TaskCompletionSource) new zzx(str3, str4));
return;
}
taskCompletionSource.a(task.a());
}
final /* synthetic */ Task a(String str, String str2, String str3, String str4) {
return this.d.a(str, str2, str3, str4);
}
}