183 lines
7.8 KiB
Java
183 lines
7.8 KiB
Java
package com.facebook.appevents;
|
|
|
|
import android.content.Intent;
|
|
import android.os.Bundle;
|
|
import android.util.Log;
|
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
|
import com.facebook.AccessToken;
|
|
import com.facebook.FacebookRequestError;
|
|
import com.facebook.FacebookSdk;
|
|
import com.facebook.GraphRequest;
|
|
import com.facebook.GraphResponse;
|
|
import com.facebook.LoggingBehavior;
|
|
import com.facebook.appevents.AppEventsLogger;
|
|
import com.facebook.internal.FetchedAppSettings;
|
|
import com.facebook.internal.FetchedAppSettingsManager;
|
|
import com.facebook.internal.Logger;
|
|
import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
import java.util.Set;
|
|
import java.util.concurrent.Executors;
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
import java.util.concurrent.ScheduledFuture;
|
|
import java.util.concurrent.TimeUnit;
|
|
import org.json.JSONArray;
|
|
import org.json.JSONException;
|
|
import org.json.JSONObject;
|
|
|
|
/* loaded from: classes.dex */
|
|
class AppEventQueue {
|
|
private static final String a = "com.facebook.appevents.AppEventQueue";
|
|
private static ScheduledFuture d;
|
|
private static volatile AppEventCollection b = new AppEventCollection();
|
|
private static final ScheduledExecutorService c = Executors.newSingleThreadScheduledExecutor();
|
|
private static final Runnable e = new Runnable() { // from class: com.facebook.appevents.AppEventQueue.1
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
ScheduledFuture unused = AppEventQueue.d = null;
|
|
if (AppEventsLogger.c() != AppEventsLogger.FlushBehavior.EXPLICIT_ONLY) {
|
|
AppEventQueue.b(FlushReason.TIMER);
|
|
}
|
|
}
|
|
};
|
|
|
|
public static Set<AccessTokenAppIdPair> e() {
|
|
return b.b();
|
|
}
|
|
|
|
public static void f() {
|
|
c.execute(new Runnable() { // from class: com.facebook.appevents.AppEventQueue.2
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
AppEventStore.a(AppEventQueue.b);
|
|
AppEventCollection unused = AppEventQueue.b = new AppEventCollection();
|
|
}
|
|
});
|
|
}
|
|
|
|
static void b(FlushReason flushReason) {
|
|
b.a(AppEventStore.a());
|
|
try {
|
|
FlushStatistics a2 = a(flushReason, b);
|
|
if (a2 != null) {
|
|
Intent intent = new Intent("com.facebook.sdk.APP_EVENTS_FLUSHED");
|
|
intent.putExtra("com.facebook.sdk.APP_EVENTS_NUM_EVENTS_FLUSHED", a2.a);
|
|
intent.putExtra("com.facebook.sdk.APP_EVENTS_FLUSH_RESULT", a2.b);
|
|
LocalBroadcastManager.a(FacebookSdk.b()).a(intent);
|
|
}
|
|
} catch (Exception e2) {
|
|
Log.w(a, "Caught unexpected exception while flushing app events: ", e2);
|
|
}
|
|
}
|
|
|
|
public static void a(final FlushReason flushReason) {
|
|
c.execute(new Runnable() { // from class: com.facebook.appevents.AppEventQueue.3
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
AppEventQueue.b(FlushReason.this);
|
|
}
|
|
});
|
|
}
|
|
|
|
public static void a(final AccessTokenAppIdPair accessTokenAppIdPair, final AppEvent appEvent) {
|
|
c.execute(new Runnable() { // from class: com.facebook.appevents.AppEventQueue.4
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
AppEventQueue.b.a(AccessTokenAppIdPair.this, appEvent);
|
|
if (AppEventsLogger.c() != AppEventsLogger.FlushBehavior.EXPLICIT_ONLY && AppEventQueue.b.a() > 100) {
|
|
AppEventQueue.b(FlushReason.EVENT_THRESHOLD);
|
|
} else if (AppEventQueue.d == null) {
|
|
ScheduledFuture unused = AppEventQueue.d = AppEventQueue.c.schedule(AppEventQueue.e, 15L, TimeUnit.SECONDS);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
private static FlushStatistics a(FlushReason flushReason, AppEventCollection appEventCollection) {
|
|
FlushStatistics flushStatistics = new FlushStatistics();
|
|
boolean a2 = FacebookSdk.a(FacebookSdk.b());
|
|
ArrayList arrayList = new ArrayList();
|
|
for (AccessTokenAppIdPair accessTokenAppIdPair : appEventCollection.b()) {
|
|
GraphRequest a3 = a(accessTokenAppIdPair, appEventCollection.a(accessTokenAppIdPair), a2, flushStatistics);
|
|
if (a3 != null) {
|
|
arrayList.add(a3);
|
|
}
|
|
}
|
|
if (arrayList.size() <= 0) {
|
|
return null;
|
|
}
|
|
Logger.a(LoggingBehavior.APP_EVENTS, a, "Flushing %d events due to %s.", Integer.valueOf(flushStatistics.a), flushReason.toString());
|
|
Iterator it = arrayList.iterator();
|
|
while (it.hasNext()) {
|
|
((GraphRequest) it.next()).a();
|
|
}
|
|
return flushStatistics;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public static void b(final AccessTokenAppIdPair accessTokenAppIdPair, GraphRequest graphRequest, GraphResponse graphResponse, final SessionEventsState sessionEventsState, FlushStatistics flushStatistics) {
|
|
String str;
|
|
String str2;
|
|
FacebookRequestError a2 = graphResponse.a();
|
|
FlushResult flushResult = FlushResult.SUCCESS;
|
|
if (a2 == null) {
|
|
str = "Success";
|
|
} else if (a2.getErrorCode() == -1) {
|
|
flushResult = FlushResult.NO_CONNECTIVITY;
|
|
str = "Failed: No Connectivity";
|
|
} else {
|
|
str = String.format("Failed:\n Response: %s\n Error %s", graphResponse.toString(), a2.toString());
|
|
flushResult = FlushResult.SERVER_ERROR;
|
|
}
|
|
if (FacebookSdk.a(LoggingBehavior.APP_EVENTS)) {
|
|
try {
|
|
str2 = new JSONArray((String) graphRequest.j()).toString(2);
|
|
} catch (JSONException unused) {
|
|
str2 = "<Can't encode events for debug logging>";
|
|
}
|
|
Logger.a(LoggingBehavior.APP_EVENTS, a, "Flush completed\nParams: %s\n Result: %s\n Events JSON: %s", graphRequest.e().toString(), str, str2);
|
|
}
|
|
sessionEventsState.a(a2 != null);
|
|
if (flushResult == FlushResult.NO_CONNECTIVITY) {
|
|
FacebookSdk.h().execute(new Runnable() { // from class: com.facebook.appevents.AppEventQueue.6
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
AppEventStore.a(AccessTokenAppIdPair.this, sessionEventsState);
|
|
}
|
|
});
|
|
}
|
|
if (flushResult == FlushResult.SUCCESS || flushStatistics.b == FlushResult.NO_CONNECTIVITY) {
|
|
return;
|
|
}
|
|
flushStatistics.b = flushResult;
|
|
}
|
|
|
|
private static GraphRequest a(final AccessTokenAppIdPair accessTokenAppIdPair, final SessionEventsState sessionEventsState, boolean z, final FlushStatistics flushStatistics) {
|
|
String b2 = accessTokenAppIdPair.b();
|
|
FetchedAppSettings a2 = FetchedAppSettingsManager.a(b2, false);
|
|
final GraphRequest a3 = GraphRequest.a((AccessToken) null, String.format("%s/activities", b2), (JSONObject) null, (GraphRequest.Callback) null);
|
|
Bundle h = a3.h();
|
|
if (h == null) {
|
|
h = new Bundle();
|
|
}
|
|
h.putString(AccessToken.ACCESS_TOKEN_KEY, accessTokenAppIdPair.a());
|
|
String d2 = AppEventsLogger.d();
|
|
if (d2 != null) {
|
|
h.putString("device_token", d2);
|
|
}
|
|
a3.a(h);
|
|
int a4 = sessionEventsState.a(a3, FacebookSdk.b(), a2 != null ? a2.g() : false, z);
|
|
if (a4 == 0) {
|
|
return null;
|
|
}
|
|
flushStatistics.a += a4;
|
|
a3.a(new GraphRequest.Callback() { // from class: com.facebook.appevents.AppEventQueue.5
|
|
@Override // com.facebook.GraphRequest.Callback
|
|
public void a(GraphResponse graphResponse) {
|
|
AppEventQueue.b(AccessTokenAppIdPair.this, a3, graphResponse, sessionEventsState, flushStatistics);
|
|
}
|
|
});
|
|
return a3;
|
|
}
|
|
}
|