137 lines
4.3 KiB
Java
137 lines
4.3 KiB
Java
package com.google.firebase.iid;
|
|
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.pm.PackageInfo;
|
|
import android.content.pm.PackageManager;
|
|
import android.content.pm.ResolveInfo;
|
|
import android.util.Base64;
|
|
import android.util.Log;
|
|
import com.google.android.gms.common.util.PlatformVersion;
|
|
import com.google.firebase.FirebaseApp;
|
|
import java.security.KeyPair;
|
|
import java.security.MessageDigest;
|
|
import java.security.NoSuchAlgorithmException;
|
|
import java.util.List;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class zzan {
|
|
private final Context a;
|
|
private String b;
|
|
private String c;
|
|
private int d;
|
|
private int e = 0;
|
|
|
|
public zzan(Context context) {
|
|
this.a = context;
|
|
}
|
|
|
|
private final synchronized void e() {
|
|
PackageInfo a = a(this.a.getPackageName());
|
|
if (a != null) {
|
|
this.b = Integer.toString(a.versionCode);
|
|
this.c = a.versionName;
|
|
}
|
|
}
|
|
|
|
public final synchronized int a() {
|
|
if (this.e != 0) {
|
|
return this.e;
|
|
}
|
|
PackageManager packageManager = this.a.getPackageManager();
|
|
if (packageManager.checkPermission("com.google.android.c2dm.permission.SEND", "com.google.android.gms") == -1) {
|
|
Log.e("FirebaseInstanceId", "Google Play services missing or without correct permission.");
|
|
return 0;
|
|
}
|
|
if (!PlatformVersion.i()) {
|
|
Intent intent = new Intent("com.google.android.c2dm.intent.REGISTER");
|
|
intent.setPackage("com.google.android.gms");
|
|
List<ResolveInfo> queryIntentServices = packageManager.queryIntentServices(intent, 0);
|
|
if (queryIntentServices != null && queryIntentServices.size() > 0) {
|
|
this.e = 1;
|
|
return this.e;
|
|
}
|
|
}
|
|
Intent intent2 = new Intent("com.google.iid.TOKEN_REQUEST");
|
|
intent2.setPackage("com.google.android.gms");
|
|
List<ResolveInfo> queryBroadcastReceivers = packageManager.queryBroadcastReceivers(intent2, 0);
|
|
if (queryBroadcastReceivers != null && queryBroadcastReceivers.size() > 0) {
|
|
this.e = 2;
|
|
return this.e;
|
|
}
|
|
Log.w("FirebaseInstanceId", "Failed to resolve IID implementation package, falling back");
|
|
if (PlatformVersion.i()) {
|
|
this.e = 2;
|
|
} else {
|
|
this.e = 1;
|
|
}
|
|
return this.e;
|
|
}
|
|
|
|
public final synchronized String b() {
|
|
if (this.b == null) {
|
|
e();
|
|
}
|
|
return this.b;
|
|
}
|
|
|
|
public final synchronized String c() {
|
|
if (this.c == null) {
|
|
e();
|
|
}
|
|
return this.c;
|
|
}
|
|
|
|
public final synchronized int d() {
|
|
PackageInfo a;
|
|
if (this.d == 0 && (a = a("com.google.android.gms")) != null) {
|
|
this.d = a.versionCode;
|
|
}
|
|
return this.d;
|
|
}
|
|
|
|
public static String a(FirebaseApp firebaseApp) {
|
|
String b = firebaseApp.c().b();
|
|
if (b != null) {
|
|
return b;
|
|
}
|
|
String a = firebaseApp.c().a();
|
|
if (!a.startsWith("1:")) {
|
|
return a;
|
|
}
|
|
String[] split = a.split(":");
|
|
if (split.length < 2) {
|
|
return null;
|
|
}
|
|
String str = split[1];
|
|
if (str.isEmpty()) {
|
|
return null;
|
|
}
|
|
return str;
|
|
}
|
|
|
|
public static String a(KeyPair keyPair) {
|
|
try {
|
|
byte[] digest = MessageDigest.getInstance("SHA1").digest(keyPair.getPublic().getEncoded());
|
|
digest[0] = (byte) ((digest[0] & 15) + 112);
|
|
return Base64.encodeToString(digest, 0, 8, 11);
|
|
} catch (NoSuchAlgorithmException unused) {
|
|
Log.w("FirebaseInstanceId", "Unexpected error, device missing required algorithms");
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private final PackageInfo a(String str) {
|
|
try {
|
|
return this.a.getPackageManager().getPackageInfo(str, 0);
|
|
} catch (PackageManager.NameNotFoundException e) {
|
|
String valueOf = String.valueOf(e);
|
|
StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 23);
|
|
sb.append("Failed to find package ");
|
|
sb.append(valueOf);
|
|
Log.w("FirebaseInstanceId", sb.toString());
|
|
return null;
|
|
}
|
|
}
|
|
}
|