jimu-decompiled/sources/com/facebook/appevents/AppEventsLogger.java
2025-05-13 19:24:51 +02:00

182 lines
6.0 KiB
Java

package com.facebook.appevents;
import android.app.Application;
import android.content.Context;
import android.os.Bundle;
import com.facebook.AccessToken;
import com.facebook.FacebookException;
import com.facebook.FacebookSdk;
import com.facebook.LoggingBehavior;
import com.facebook.appevents.internal.ActivityLifecycleTracker;
import com.facebook.internal.FetchedAppSettingsManager;
import com.facebook.internal.Logger;
import com.facebook.internal.Utility;
import com.facebook.internal.Validate;
import java.util.HashSet;
import java.util.Iterator;
import java.util.UUID;
import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.json.JSONException;
/* loaded from: classes.dex */
public class AppEventsLogger {
private static ScheduledThreadPoolExecutor c;
private static FlushBehavior d = FlushBehavior.AUTO;
private static Object e = new Object();
private static String f;
private static boolean g;
private static String h;
private final String a;
private final AccessTokenAppIdPair b;
public enum FlushBehavior {
AUTO,
EXPLICIT_ONLY
}
private AppEventsLogger(Context context, String str, AccessToken accessToken) {
this(Utility.b(context), str, accessToken);
}
public static void a(Application application, String str) {
if (!FacebookSdk.o()) {
throw new FacebookException("The Facebook sdk must be initialized before calling activateApp");
}
AnalyticsUserIDStore.d();
if (str == null) {
str = FacebookSdk.c();
}
FacebookSdk.b(application, str);
ActivityLifecycleTracker.a(application, str);
}
public static AppEventsLogger b(Context context) {
return new AppEventsLogger(context, (String) null, (AccessToken) null);
}
public static FlushBehavior c() {
FlushBehavior flushBehavior;
synchronized (e) {
flushBehavior = d;
}
return flushBehavior;
}
static String d() {
String str;
synchronized (e) {
str = h;
}
return str;
}
public static String e() {
return AnalyticsUserIDStore.b();
}
private static void f() {
synchronized (e) {
if (c != null) {
return;
}
c = new ScheduledThreadPoolExecutor(1);
c.scheduleAtFixedRate(new Runnable() { // from class: com.facebook.appevents.AppEventsLogger.4
@Override // java.lang.Runnable
public void run() {
HashSet hashSet = new HashSet();
Iterator<AccessTokenAppIdPair> it = AppEventQueue.e().iterator();
while (it.hasNext()) {
hashSet.add(it.next().b());
}
Iterator it2 = hashSet.iterator();
while (it2.hasNext()) {
FetchedAppSettingsManager.a((String) it2.next(), true);
}
}
}, 0L, 86400L, TimeUnit.SECONDS);
}
}
public static void g() {
AppEventQueue.f();
}
static Executor b() {
if (c == null) {
f();
}
return c;
}
protected AppEventsLogger(String str, String str2, AccessToken accessToken) {
Validate.c();
this.a = str;
accessToken = accessToken == null ? AccessToken.getCurrentAccessToken() : accessToken;
if (accessToken != null && (str2 == null || str2.equals(accessToken.getApplicationId()))) {
this.b = new AccessTokenAppIdPair(accessToken);
} else {
this.b = new AccessTokenAppIdPair(null, str2 == null ? Utility.c(FacebookSdk.b()) : str2);
}
f();
}
public static AppEventsLogger a(Context context, String str) {
return new AppEventsLogger(context, str, (AccessToken) null);
}
public void a(String str, Bundle bundle) {
a(str, null, bundle, false, ActivityLifecycleTracker.h());
}
public void a(String str, double d2, Bundle bundle) {
a(str, Double.valueOf(d2), bundle, false, ActivityLifecycleTracker.h());
}
public void a() {
AppEventQueue.a(FlushReason.EXPLICIT);
}
public void a(String str, Double d2, Bundle bundle) {
a(str, d2, bundle, true, ActivityLifecycleTracker.h());
}
private void a(String str, Double d2, Bundle bundle, boolean z, UUID uuid) {
try {
a(FacebookSdk.b(), new AppEvent(this.a, str, d2, bundle, z, uuid), this.b);
} catch (FacebookException e2) {
Logger.a(LoggingBehavior.APP_EVENTS, "AppEvents", "Invalid app event: %s", e2.toString());
} catch (JSONException e3) {
Logger.a(LoggingBehavior.APP_EVENTS, "AppEvents", "JSON encoding for app event failed: '%s'", e3.toString());
}
}
private static void a(Context context, AppEvent appEvent, AccessTokenAppIdPair accessTokenAppIdPair) {
AppEventQueue.a(accessTokenAppIdPair, appEvent);
if (appEvent.a() || g) {
return;
}
if (appEvent.c() == "fb_mobile_activate_app") {
g = true;
} else {
Logger.a(LoggingBehavior.APP_EVENTS, "AppEvents", "Warning: Please call AppEventsLogger.activateApp(...)from the long-lived activity's onResume() methodbefore logging other app events.");
}
}
public static String a(Context context) {
if (f == null) {
synchronized (e) {
if (f == null) {
f = context.getSharedPreferences("com.facebook.sdk.appEventPreferences", 0).getString("anonymousAppDeviceGUID", null);
if (f == null) {
f = "XZ" + UUID.randomUUID().toString();
context.getSharedPreferences("com.facebook.sdk.appEventPreferences", 0).edit().putString("anonymousAppDeviceGUID", f).apply();
}
}
}
}
return f;
}
}