- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
165 lines
7.0 KiB
Java
165 lines
7.0 KiB
Java
package com.google.firebase.crashlytics.internal.common;
|
|
|
|
import android.content.Context;
|
|
import android.content.SharedPreferences;
|
|
import android.content.pm.ApplicationInfo;
|
|
import android.content.pm.PackageManager;
|
|
import android.os.Bundle;
|
|
import com.google.android.gms.tasks.Task;
|
|
import com.google.android.gms.tasks.TaskCompletionSource;
|
|
import com.google.firebase.FirebaseApp;
|
|
import com.google.firebase.crashlytics.internal.Logger;
|
|
import java.util.concurrent.Executor;
|
|
|
|
/* loaded from: classes3.dex */
|
|
public class DataCollectionArbiter {
|
|
public Boolean crashlyticsDataCollectionEnabled;
|
|
public TaskCompletionSource dataCollectionEnabledTask;
|
|
public final TaskCompletionSource dataCollectionExplicitlyApproved;
|
|
public final FirebaseApp firebaseApp;
|
|
public boolean setInManifest;
|
|
public final SharedPreferences sharedPreferences;
|
|
public final Object taskLock;
|
|
public boolean taskResolved;
|
|
|
|
public DataCollectionArbiter(FirebaseApp firebaseApp) {
|
|
Object obj = new Object();
|
|
this.taskLock = obj;
|
|
this.dataCollectionEnabledTask = new TaskCompletionSource();
|
|
this.taskResolved = false;
|
|
this.setInManifest = false;
|
|
this.dataCollectionExplicitlyApproved = new TaskCompletionSource();
|
|
Context applicationContext = firebaseApp.getApplicationContext();
|
|
this.firebaseApp = firebaseApp;
|
|
this.sharedPreferences = CommonUtils.getSharedPrefs(applicationContext);
|
|
Boolean dataCollectionValueFromSharedPreferences = getDataCollectionValueFromSharedPreferences();
|
|
this.crashlyticsDataCollectionEnabled = dataCollectionValueFromSharedPreferences == null ? getDataCollectionValueFromManifest(applicationContext) : dataCollectionValueFromSharedPreferences;
|
|
synchronized (obj) {
|
|
try {
|
|
if (isAutomaticDataCollectionEnabled()) {
|
|
this.dataCollectionEnabledTask.trySetResult(null);
|
|
this.taskResolved = true;
|
|
}
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
}
|
|
}
|
|
|
|
public synchronized boolean isAutomaticDataCollectionEnabled() {
|
|
boolean isFirebaseDataCollectionDefaultEnabled;
|
|
try {
|
|
Boolean bool = this.crashlyticsDataCollectionEnabled;
|
|
if (bool != null) {
|
|
isFirebaseDataCollectionDefaultEnabled = bool.booleanValue();
|
|
} else {
|
|
isFirebaseDataCollectionDefaultEnabled = isFirebaseDataCollectionDefaultEnabled();
|
|
}
|
|
logDataCollectionState(isFirebaseDataCollectionDefaultEnabled);
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
return isFirebaseDataCollectionDefaultEnabled;
|
|
}
|
|
|
|
public final boolean isFirebaseDataCollectionDefaultEnabled() {
|
|
try {
|
|
return this.firebaseApp.isDataCollectionDefaultEnabled();
|
|
} catch (IllegalStateException unused) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public synchronized void setCrashlyticsDataCollectionEnabled(Boolean bool) {
|
|
if (bool != null) {
|
|
try {
|
|
this.setInManifest = false;
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
}
|
|
this.crashlyticsDataCollectionEnabled = bool != null ? bool : getDataCollectionValueFromManifest(this.firebaseApp.getApplicationContext());
|
|
storeDataCollectionValueInSharedPreferences(this.sharedPreferences, bool);
|
|
synchronized (this.taskLock) {
|
|
try {
|
|
if (isAutomaticDataCollectionEnabled()) {
|
|
if (!this.taskResolved) {
|
|
this.dataCollectionEnabledTask.trySetResult(null);
|
|
this.taskResolved = true;
|
|
}
|
|
} else if (this.taskResolved) {
|
|
this.dataCollectionEnabledTask = new TaskCompletionSource();
|
|
this.taskResolved = false;
|
|
}
|
|
} finally {
|
|
}
|
|
}
|
|
}
|
|
|
|
public Task waitForAutomaticDataCollectionEnabled() {
|
|
Task task;
|
|
synchronized (this.taskLock) {
|
|
task = this.dataCollectionEnabledTask.getTask();
|
|
}
|
|
return task;
|
|
}
|
|
|
|
public Task waitForDataCollectionPermission(Executor executor) {
|
|
return Utils.race(executor, this.dataCollectionExplicitlyApproved.getTask(), waitForAutomaticDataCollectionEnabled());
|
|
}
|
|
|
|
public void grantDataCollectionPermission(boolean z) {
|
|
if (!z) {
|
|
throw new IllegalStateException("An invalid data collection token was used.");
|
|
}
|
|
this.dataCollectionExplicitlyApproved.trySetResult(null);
|
|
}
|
|
|
|
public final void logDataCollectionState(boolean z) {
|
|
Logger.getLogger().d(String.format("Crashlytics automatic data collection %s by %s.", z ? "ENABLED" : "DISABLED", this.crashlyticsDataCollectionEnabled == null ? "global Firebase setting" : this.setInManifest ? "firebase_crashlytics_collection_enabled manifest flag" : "API"));
|
|
}
|
|
|
|
public final Boolean getDataCollectionValueFromSharedPreferences() {
|
|
if (!this.sharedPreferences.contains("firebase_crashlytics_collection_enabled")) {
|
|
return null;
|
|
}
|
|
this.setInManifest = false;
|
|
return Boolean.valueOf(this.sharedPreferences.getBoolean("firebase_crashlytics_collection_enabled", true));
|
|
}
|
|
|
|
public final Boolean getDataCollectionValueFromManifest(Context context) {
|
|
Boolean readCrashlyticsDataCollectionEnabledFromManifest = readCrashlyticsDataCollectionEnabledFromManifest(context);
|
|
if (readCrashlyticsDataCollectionEnabledFromManifest == null) {
|
|
this.setInManifest = false;
|
|
return null;
|
|
}
|
|
this.setInManifest = true;
|
|
return Boolean.valueOf(Boolean.TRUE.equals(readCrashlyticsDataCollectionEnabledFromManifest));
|
|
}
|
|
|
|
public static Boolean readCrashlyticsDataCollectionEnabledFromManifest(Context context) {
|
|
ApplicationInfo applicationInfo;
|
|
Bundle bundle;
|
|
try {
|
|
PackageManager packageManager = context.getPackageManager();
|
|
if (packageManager == null || (applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 128)) == null || (bundle = applicationInfo.metaData) == null || !bundle.containsKey("firebase_crashlytics_collection_enabled")) {
|
|
return null;
|
|
}
|
|
return Boolean.valueOf(applicationInfo.metaData.getBoolean("firebase_crashlytics_collection_enabled"));
|
|
} catch (PackageManager.NameNotFoundException e) {
|
|
Logger.getLogger().e("Could not read data collection permission from manifest", e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static void storeDataCollectionValueInSharedPreferences(SharedPreferences sharedPreferences, Boolean bool) {
|
|
SharedPreferences.Editor edit = sharedPreferences.edit();
|
|
if (bool != null) {
|
|
edit.putBoolean("firebase_crashlytics_collection_enabled", bool.booleanValue());
|
|
} else {
|
|
edit.remove("firebase_crashlytics_collection_enabled");
|
|
}
|
|
edit.apply();
|
|
}
|
|
}
|