425 lines
22 KiB
Java
425 lines
22 KiB
Java
package com.google.firebase.installations;
|
|
|
|
import android.text.TextUtils;
|
|
import com.google.android.gms.common.internal.Preconditions;
|
|
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.FirebaseApp;
|
|
import com.google.firebase.heartbeatinfo.HeartBeatInfo;
|
|
import com.google.firebase.inject.Provider;
|
|
import com.google.firebase.installations.FirebaseInstallationsException;
|
|
import com.google.firebase.installations.internal.FidListener;
|
|
import com.google.firebase.installations.local.IidStore;
|
|
import com.google.firebase.installations.local.PersistedInstallation;
|
|
import com.google.firebase.installations.local.PersistedInstallationEntry;
|
|
import com.google.firebase.installations.remote.FirebaseInstallationServiceClient;
|
|
import com.google.firebase.installations.remote.InstallationResponse;
|
|
import com.google.firebase.installations.remote.TokenResult;
|
|
import com.google.firebase.platforminfo.UserAgentPublisher;
|
|
import java.util.ArrayList;
|
|
import java.util.HashSet;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.Set;
|
|
import java.util.concurrent.ExecutorService;
|
|
import java.util.concurrent.LinkedBlockingQueue;
|
|
import java.util.concurrent.ThreadFactory;
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class FirebaseInstallations implements FirebaseInstallationsApi {
|
|
private final ExecutorService backgroundExecutor;
|
|
private String cachedFid;
|
|
private final RandomFidGenerator fidGenerator;
|
|
private Set<FidListener> fidListeners;
|
|
private final FirebaseApp firebaseApp;
|
|
private final IidStore iidStore;
|
|
private final List<StateListener> listeners;
|
|
private final Object lock;
|
|
private final ExecutorService networkExecutor;
|
|
private final PersistedInstallation persistedInstallation;
|
|
private final FirebaseInstallationServiceClient serviceClient;
|
|
private final Utils utils;
|
|
private static final Object lockGenerateFid = new Object();
|
|
private static final ThreadFactory THREAD_FACTORY = new ThreadFactory() { // from class: com.google.firebase.installations.FirebaseInstallations.1
|
|
private final AtomicInteger mCount = new AtomicInteger(1);
|
|
|
|
@Override // java.util.concurrent.ThreadFactory
|
|
public Thread newThread(Runnable runnable) {
|
|
return new Thread(runnable, String.format("firebase-installations-executor-%d", Integer.valueOf(this.mCount.getAndIncrement())));
|
|
}
|
|
};
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public FirebaseInstallations(FirebaseApp firebaseApp, Provider<UserAgentPublisher> provider, Provider<HeartBeatInfo> provider2) {
|
|
this(new ThreadPoolExecutor(0, 1, 30L, TimeUnit.SECONDS, new LinkedBlockingQueue(), THREAD_FACTORY), firebaseApp, new FirebaseInstallationServiceClient(firebaseApp.getApplicationContext(), provider, provider2), new PersistedInstallation(firebaseApp), Utils.getInstance(), new IidStore(firebaseApp), new RandomFidGenerator());
|
|
}
|
|
|
|
FirebaseInstallations(ExecutorService executorService, FirebaseApp firebaseApp, FirebaseInstallationServiceClient firebaseInstallationServiceClient, PersistedInstallation persistedInstallation, Utils utils, IidStore iidStore, RandomFidGenerator randomFidGenerator) {
|
|
this.lock = new Object();
|
|
this.fidListeners = new HashSet();
|
|
this.listeners = new ArrayList();
|
|
this.firebaseApp = firebaseApp;
|
|
this.serviceClient = firebaseInstallationServiceClient;
|
|
this.persistedInstallation = persistedInstallation;
|
|
this.utils = utils;
|
|
this.iidStore = iidStore;
|
|
this.fidGenerator = randomFidGenerator;
|
|
this.backgroundExecutor = executorService;
|
|
this.networkExecutor = new ThreadPoolExecutor(0, 1, 30L, TimeUnit.SECONDS, new LinkedBlockingQueue(), THREAD_FACTORY);
|
|
}
|
|
|
|
private void preConditionChecks() {
|
|
Preconditions.checkNotEmpty(getApplicationId(), "Please set your Application ID. A valid Firebase App ID is required to communicate with Firebase server APIs: It identifies your application with Firebase.Please refer to https://firebase.google.com/support/privacy/init-options.");
|
|
Preconditions.checkNotEmpty(getProjectIdentifier(), "Please set your Project ID. A valid Firebase Project ID is required to communicate with Firebase server APIs: It identifies your application with Firebase.Please refer to https://firebase.google.com/support/privacy/init-options.");
|
|
Preconditions.checkNotEmpty(getApiKey(), "Please set a valid API key. A Firebase API key is required to communicate with Firebase server APIs: It authenticates your project with Google.Please refer to https://firebase.google.com/support/privacy/init-options.");
|
|
Preconditions.checkArgument(Utils.isValidAppIdFormat(getApplicationId()), "Please set your Application ID. A valid Firebase App ID is required to communicate with Firebase server APIs: It identifies your application with Firebase.Please refer to https://firebase.google.com/support/privacy/init-options.");
|
|
Preconditions.checkArgument(Utils.isValidApiKeyFormat(getApiKey()), "Please set a valid API key. A Firebase API key is required to communicate with Firebase server APIs: It authenticates your project with Google.Please refer to https://firebase.google.com/support/privacy/init-options.");
|
|
}
|
|
|
|
String getProjectIdentifier() {
|
|
return this.firebaseApp.getOptions().getProjectId();
|
|
}
|
|
|
|
public static FirebaseInstallations getInstance() {
|
|
return getInstance(FirebaseApp.getInstance());
|
|
}
|
|
|
|
public static FirebaseInstallations getInstance(FirebaseApp firebaseApp) {
|
|
Preconditions.checkArgument(firebaseApp != null, "Null is not a valid value of FirebaseApp.");
|
|
return (FirebaseInstallations) firebaseApp.get(FirebaseInstallationsApi.class);
|
|
}
|
|
|
|
String getApplicationId() {
|
|
return this.firebaseApp.getOptions().getApplicationId();
|
|
}
|
|
|
|
String getApiKey() {
|
|
return this.firebaseApp.getOptions().getApiKey();
|
|
}
|
|
|
|
@Override // com.google.firebase.installations.FirebaseInstallationsApi
|
|
public Task<String> getId() {
|
|
preConditionChecks();
|
|
String cacheFid = getCacheFid();
|
|
if (cacheFid != null) {
|
|
return Tasks.forResult(cacheFid);
|
|
}
|
|
Task<String> addGetIdListener = addGetIdListener();
|
|
this.backgroundExecutor.execute(new Runnable(this) { // from class: com.google.firebase.installations.FirebaseInstallations$$ExternalSyntheticLambda3
|
|
public final FirebaseInstallations f$0;
|
|
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
this.f$0.m262x9bfaa81c();
|
|
}
|
|
|
|
{
|
|
this.f$0 = this;
|
|
}
|
|
});
|
|
return addGetIdListener;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* renamed from: lambda$getId$0$com-google-firebase-installations-FirebaseInstallations, reason: not valid java name */
|
|
public /* synthetic */ void m262x9bfaa81c() {
|
|
m263x4bb3eea9(false);
|
|
}
|
|
|
|
@Override // com.google.firebase.installations.FirebaseInstallationsApi
|
|
public Task<InstallationTokenResult> getToken(final boolean z) {
|
|
preConditionChecks();
|
|
Task<InstallationTokenResult> addGetAuthTokenListener = addGetAuthTokenListener();
|
|
this.backgroundExecutor.execute(new Runnable(this, z) { // from class: com.google.firebase.installations.FirebaseInstallations$$ExternalSyntheticLambda2
|
|
public final FirebaseInstallations f$0;
|
|
public final boolean f$1;
|
|
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
this.f$0.m263x4bb3eea9(this.f$1);
|
|
}
|
|
|
|
{
|
|
this.f$0 = this;
|
|
this.f$1 = z;
|
|
}
|
|
});
|
|
return addGetAuthTokenListener;
|
|
}
|
|
|
|
private Task<String> addGetIdListener() {
|
|
TaskCompletionSource taskCompletionSource = new TaskCompletionSource();
|
|
addStateListeners(new GetIdListener(taskCompletionSource));
|
|
return taskCompletionSource.getTask();
|
|
}
|
|
|
|
private Task<InstallationTokenResult> addGetAuthTokenListener() {
|
|
TaskCompletionSource taskCompletionSource = new TaskCompletionSource();
|
|
addStateListeners(new GetAuthTokenListener(this.utils, taskCompletionSource));
|
|
return taskCompletionSource.getTask();
|
|
}
|
|
|
|
private void addStateListeners(StateListener stateListener) {
|
|
synchronized (this.lock) {
|
|
this.listeners.add(stateListener);
|
|
}
|
|
}
|
|
|
|
private void triggerOnStateReached(PersistedInstallationEntry persistedInstallationEntry) {
|
|
synchronized (this.lock) {
|
|
Iterator<StateListener> it = this.listeners.iterator();
|
|
while (it.hasNext()) {
|
|
if (it.next().onStateReached(persistedInstallationEntry)) {
|
|
it.remove();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void triggerOnException(Exception exc) {
|
|
synchronized (this.lock) {
|
|
Iterator<StateListener> it = this.listeners.iterator();
|
|
while (it.hasNext()) {
|
|
if (it.next().onException(exc)) {
|
|
it.remove();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void updateCacheFid(String str) {
|
|
synchronized (this) {
|
|
this.cachedFid = str;
|
|
}
|
|
}
|
|
|
|
private String getCacheFid() {
|
|
String str;
|
|
synchronized (this) {
|
|
str = this.cachedFid;
|
|
}
|
|
return str;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
/* renamed from: doRegistrationOrRefresh, reason: merged with bridge method [inline-methods] */
|
|
public final void m263x4bb3eea9(final boolean z) {
|
|
PersistedInstallationEntry prefsWithGeneratedIdMultiProcessSafe = getPrefsWithGeneratedIdMultiProcessSafe();
|
|
if (z) {
|
|
prefsWithGeneratedIdMultiProcessSafe = prefsWithGeneratedIdMultiProcessSafe.withClearedAuthToken();
|
|
}
|
|
triggerOnStateReached(prefsWithGeneratedIdMultiProcessSafe);
|
|
this.networkExecutor.execute(new Runnable(this, z) { // from class: com.google.firebase.installations.FirebaseInstallations$$ExternalSyntheticLambda0
|
|
public final FirebaseInstallations f$0;
|
|
public final boolean f$1;
|
|
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
this.f$0.m261x349c6181(this.f$1);
|
|
}
|
|
|
|
{
|
|
this.f$0 = this;
|
|
this.f$1 = z;
|
|
}
|
|
});
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
/* JADX WARN: Removed duplicated region for block: B:17:0x0032 */
|
|
/* JADX WARN: Removed duplicated region for block: B:20:0x003f */
|
|
/* JADX WARN: Removed duplicated region for block: B:22:0x004a */
|
|
/* renamed from: doNetworkCallIfNecessary, reason: merged with bridge method [inline-methods] */
|
|
/*
|
|
Code decompiled incorrectly, please refer to instructions dump.
|
|
To view partially-correct add '--show-bad-code' argument
|
|
*/
|
|
public void m261x349c6181(boolean r3) {
|
|
/*
|
|
r2 = this;
|
|
com.google.firebase.installations.local.PersistedInstallationEntry r0 = r2.getMultiProcessSafePrefs()
|
|
boolean r1 = r0.isErrored() // Catch: com.google.firebase.installations.FirebaseInstallationsException -> L5f
|
|
if (r1 != 0) goto L22
|
|
boolean r1 = r0.isUnregistered() // Catch: com.google.firebase.installations.FirebaseInstallationsException -> L5f
|
|
if (r1 == 0) goto L11
|
|
goto L22
|
|
L11:
|
|
if (r3 != 0) goto L1d
|
|
com.google.firebase.installations.Utils r3 = r2.utils // Catch: com.google.firebase.installations.FirebaseInstallationsException -> L5f
|
|
boolean r3 = r3.isAuthTokenExpired(r0) // Catch: com.google.firebase.installations.FirebaseInstallationsException -> L5f
|
|
if (r3 == 0) goto L1c
|
|
goto L1d
|
|
L1c:
|
|
return
|
|
L1d:
|
|
com.google.firebase.installations.local.PersistedInstallationEntry r3 = r2.fetchAuthTokenFromServer(r0) // Catch: com.google.firebase.installations.FirebaseInstallationsException -> L5f
|
|
goto L26
|
|
L22:
|
|
com.google.firebase.installations.local.PersistedInstallationEntry r3 = r2.registerFidWithServer(r0) // Catch: com.google.firebase.installations.FirebaseInstallationsException -> L5f
|
|
L26:
|
|
r2.insertOrUpdatePrefs(r3)
|
|
r2.updateFidListener(r0, r3)
|
|
boolean r0 = r3.isRegistered()
|
|
if (r0 == 0) goto L39
|
|
java.lang.String r0 = r3.getFirebaseInstallationId()
|
|
r2.updateCacheFid(r0)
|
|
L39:
|
|
boolean r0 = r3.isErrored()
|
|
if (r0 == 0) goto L4a
|
|
com.google.firebase.installations.FirebaseInstallationsException r3 = new com.google.firebase.installations.FirebaseInstallationsException
|
|
com.google.firebase.installations.FirebaseInstallationsException$Status r0 = com.google.firebase.installations.FirebaseInstallationsException.Status.BAD_CONFIG
|
|
r3.<init>(r0)
|
|
r2.triggerOnException(r3)
|
|
return
|
|
L4a:
|
|
boolean r0 = r3.isNotGenerated()
|
|
if (r0 == 0) goto L5b
|
|
java.io.IOException r3 = new java.io.IOException
|
|
java.lang.String r0 = "Installation ID could not be validated with the Firebase servers (maybe it was deleted). Firebase Installations will need to create a new Installation ID and auth token. Please retry your last request."
|
|
r3.<init>(r0)
|
|
r2.triggerOnException(r3)
|
|
return
|
|
L5b:
|
|
r2.triggerOnStateReached(r3)
|
|
return
|
|
L5f:
|
|
r3 = move-exception
|
|
r2.triggerOnException(r3)
|
|
return
|
|
*/
|
|
throw new UnsupportedOperationException("Method not decompiled: com.google.firebase.installations.FirebaseInstallations.m261x349c6181(boolean):void");
|
|
}
|
|
|
|
private void updateFidListener(PersistedInstallationEntry persistedInstallationEntry, PersistedInstallationEntry persistedInstallationEntry2) {
|
|
synchronized (this) {
|
|
if (this.fidListeners.size() != 0 && !persistedInstallationEntry.getFirebaseInstallationId().equals(persistedInstallationEntry2.getFirebaseInstallationId())) {
|
|
Iterator<FidListener> it = this.fidListeners.iterator();
|
|
while (it.hasNext()) {
|
|
it.next().onFidChanged(persistedInstallationEntry2.getFirebaseInstallationId());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void insertOrUpdatePrefs(PersistedInstallationEntry persistedInstallationEntry) {
|
|
synchronized (lockGenerateFid) {
|
|
CrossProcessLock acquire = CrossProcessLock.acquire(this.firebaseApp.getApplicationContext(), "generatefid.lock");
|
|
try {
|
|
this.persistedInstallation.insertOrUpdatePersistedInstallationEntry(persistedInstallationEntry);
|
|
} finally {
|
|
if (acquire != null) {
|
|
acquire.releaseAndClose();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private PersistedInstallationEntry getPrefsWithGeneratedIdMultiProcessSafe() {
|
|
PersistedInstallationEntry readPersistedInstallationEntryValue;
|
|
synchronized (lockGenerateFid) {
|
|
CrossProcessLock acquire = CrossProcessLock.acquire(this.firebaseApp.getApplicationContext(), "generatefid.lock");
|
|
try {
|
|
readPersistedInstallationEntryValue = this.persistedInstallation.readPersistedInstallationEntryValue();
|
|
if (readPersistedInstallationEntryValue.isNotGenerated()) {
|
|
readPersistedInstallationEntryValue = this.persistedInstallation.insertOrUpdatePersistedInstallationEntry(readPersistedInstallationEntryValue.withUnregisteredFid(readExistingIidOrCreateFid(readPersistedInstallationEntryValue)));
|
|
}
|
|
} finally {
|
|
if (acquire != null) {
|
|
acquire.releaseAndClose();
|
|
}
|
|
}
|
|
}
|
|
return readPersistedInstallationEntryValue;
|
|
}
|
|
|
|
private String readExistingIidOrCreateFid(PersistedInstallationEntry persistedInstallationEntry) {
|
|
if ((!this.firebaseApp.getName().equals("CHIME_ANDROID_SDK") && !this.firebaseApp.isDefaultApp()) || !persistedInstallationEntry.shouldAttemptMigration()) {
|
|
return this.fidGenerator.createRandomFid();
|
|
}
|
|
String readIid = this.iidStore.readIid();
|
|
return TextUtils.isEmpty(readIid) ? this.fidGenerator.createRandomFid() : readIid;
|
|
}
|
|
|
|
private PersistedInstallationEntry registerFidWithServer(PersistedInstallationEntry persistedInstallationEntry) throws FirebaseInstallationsException {
|
|
InstallationResponse createFirebaseInstallation = this.serviceClient.createFirebaseInstallation(getApiKey(), persistedInstallationEntry.getFirebaseInstallationId(), getProjectIdentifier(), getApplicationId(), (persistedInstallationEntry.getFirebaseInstallationId() == null || persistedInstallationEntry.getFirebaseInstallationId().length() != 11) ? null : this.iidStore.readToken());
|
|
int i = AnonymousClass3.$SwitchMap$com$google$firebase$installations$remote$InstallationResponse$ResponseCode[createFirebaseInstallation.getResponseCode().ordinal()];
|
|
if (i == 1) {
|
|
return persistedInstallationEntry.withRegisteredFid(createFirebaseInstallation.getFid(), createFirebaseInstallation.getRefreshToken(), this.utils.currentTimeInSecs(), createFirebaseInstallation.getAuthToken().getToken(), createFirebaseInstallation.getAuthToken().getTokenExpirationTimestamp());
|
|
}
|
|
if (i == 2) {
|
|
return persistedInstallationEntry.withFisError("BAD CONFIG");
|
|
}
|
|
throw new FirebaseInstallationsException("Firebase Installations Service is unavailable. Please try again later.", FirebaseInstallationsException.Status.UNAVAILABLE);
|
|
}
|
|
|
|
private PersistedInstallationEntry fetchAuthTokenFromServer(PersistedInstallationEntry persistedInstallationEntry) throws FirebaseInstallationsException {
|
|
TokenResult generateAuthToken = this.serviceClient.generateAuthToken(getApiKey(), persistedInstallationEntry.getFirebaseInstallationId(), getProjectIdentifier(), persistedInstallationEntry.getRefreshToken());
|
|
int i = AnonymousClass3.$SwitchMap$com$google$firebase$installations$remote$TokenResult$ResponseCode[generateAuthToken.getResponseCode().ordinal()];
|
|
if (i == 1) {
|
|
return persistedInstallationEntry.withAuthToken(generateAuthToken.getToken(), generateAuthToken.getTokenExpirationTimestamp(), this.utils.currentTimeInSecs());
|
|
}
|
|
if (i == 2) {
|
|
return persistedInstallationEntry.withFisError("BAD CONFIG");
|
|
}
|
|
if (i == 3) {
|
|
updateCacheFid(null);
|
|
return persistedInstallationEntry.withNoGeneratedFid();
|
|
}
|
|
throw new FirebaseInstallationsException("Firebase Installations Service is unavailable. Please try again later.", FirebaseInstallationsException.Status.UNAVAILABLE);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* renamed from: com.google.firebase.installations.FirebaseInstallations$3, reason: invalid class name */
|
|
/* loaded from: classes2.dex */
|
|
public static /* synthetic */ class AnonymousClass3 {
|
|
static final int[] $SwitchMap$com$google$firebase$installations$remote$InstallationResponse$ResponseCode;
|
|
static final int[] $SwitchMap$com$google$firebase$installations$remote$TokenResult$ResponseCode;
|
|
|
|
static {
|
|
int[] iArr = new int[TokenResult.ResponseCode.values().length];
|
|
$SwitchMap$com$google$firebase$installations$remote$TokenResult$ResponseCode = iArr;
|
|
try {
|
|
iArr[TokenResult.ResponseCode.OK.ordinal()] = 1;
|
|
} catch (NoSuchFieldError unused) {
|
|
}
|
|
try {
|
|
$SwitchMap$com$google$firebase$installations$remote$TokenResult$ResponseCode[TokenResult.ResponseCode.BAD_CONFIG.ordinal()] = 2;
|
|
} catch (NoSuchFieldError unused2) {
|
|
}
|
|
try {
|
|
$SwitchMap$com$google$firebase$installations$remote$TokenResult$ResponseCode[TokenResult.ResponseCode.AUTH_ERROR.ordinal()] = 3;
|
|
} catch (NoSuchFieldError unused3) {
|
|
}
|
|
int[] iArr2 = new int[InstallationResponse.ResponseCode.values().length];
|
|
$SwitchMap$com$google$firebase$installations$remote$InstallationResponse$ResponseCode = iArr2;
|
|
try {
|
|
iArr2[InstallationResponse.ResponseCode.OK.ordinal()] = 1;
|
|
} catch (NoSuchFieldError unused4) {
|
|
}
|
|
try {
|
|
$SwitchMap$com$google$firebase$installations$remote$InstallationResponse$ResponseCode[InstallationResponse.ResponseCode.BAD_CONFIG.ordinal()] = 2;
|
|
} catch (NoSuchFieldError unused5) {
|
|
}
|
|
}
|
|
}
|
|
|
|
private PersistedInstallationEntry getMultiProcessSafePrefs() {
|
|
PersistedInstallationEntry readPersistedInstallationEntryValue;
|
|
synchronized (lockGenerateFid) {
|
|
CrossProcessLock acquire = CrossProcessLock.acquire(this.firebaseApp.getApplicationContext(), "generatefid.lock");
|
|
try {
|
|
readPersistedInstallationEntryValue = this.persistedInstallation.readPersistedInstallationEntryValue();
|
|
} finally {
|
|
if (acquire != null) {
|
|
acquire.releaseAndClose();
|
|
}
|
|
}
|
|
}
|
|
return readPersistedInstallationEntryValue;
|
|
}
|
|
}
|