- Added realracing3-community.apk (71.57 MB) - Removed 32-bit support (armeabi-v7a) - Only includes arm64-v8a libraries - Decompiled source code included - Added README-community.md with analysis
143 lines
5.7 KiB
Java
143 lines
5.7 KiB
Java
package com.singular.sdk.internal;
|
|
|
|
import android.content.Context;
|
|
import java.io.File;
|
|
import org.json.JSONObject;
|
|
|
|
/* loaded from: classes4.dex */
|
|
public class ApiManager {
|
|
public static final SingularLog logger = SingularLog.getLogger(ApiManager.class.getSimpleName());
|
|
public final Context context;
|
|
public Queue queue;
|
|
public SingularWorkerThread worker;
|
|
public final Runnable runnable = new Runnable() { // from class: com.singular.sdk.internal.ApiManager.2
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
if (!SingularInstance.getInstance().isInitialized()) {
|
|
ApiManager.logger.debug("Singular is not initialized!");
|
|
return;
|
|
}
|
|
if (Utils.isConnected(ApiManager.this.context)) {
|
|
try {
|
|
String peek = ApiManager.this.queue.peek();
|
|
if (peek == null) {
|
|
ApiManager.logger.debug("Queue is empty");
|
|
return;
|
|
}
|
|
BaseApi from = BaseApi.from(peek);
|
|
ApiManager.logger.debug("api = %s", from.getClass().getName());
|
|
if (from.makeRequest(SingularInstance.getInstance())) {
|
|
ApiManager.this.queue.remove();
|
|
ApiManager.this.wakeUp();
|
|
return;
|
|
}
|
|
return;
|
|
} catch (Exception e) {
|
|
ApiManager.logger.error("IOException in processing an event: %s", e.getMessage());
|
|
e.printStackTrace();
|
|
return;
|
|
}
|
|
}
|
|
ApiManager.logger.debug("Oops, not connected to internet!");
|
|
}
|
|
};
|
|
public final Runnable migrateEventsFromFileQueue = new Runnable() { // from class: com.singular.sdk.internal.ApiManager.3
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
File file = new File(ApiManager.this.context.getFilesDir(), "api-r.dat");
|
|
ApiManager.logger.debug("Migrate events from QueueFile = %s", "api-r.dat");
|
|
if (!file.exists()) {
|
|
ApiManager.logger.debug("QueueFile does not exist");
|
|
return;
|
|
}
|
|
try {
|
|
FixedSizePersistentQueue create = FixedSizePersistentQueue.create(ApiManager.this.context, "api-r.dat", 10000);
|
|
if (create == null) {
|
|
ApiManager.logger.debug("QueueFile failed to initialize");
|
|
return;
|
|
}
|
|
int i = 0;
|
|
while (!create.isEmpty()) {
|
|
ApiManager.this.queue.add(create.peek());
|
|
create.remove();
|
|
i++;
|
|
}
|
|
ApiManager.logger.debug("Migrated '%d' events", Integer.valueOf(i));
|
|
file.delete();
|
|
ApiManager.logger.debug("QueueFile deleted");
|
|
} catch (RuntimeException e) {
|
|
ApiManager.logger.error("loadFromFileQueue: RuntimeException", e);
|
|
} catch (Exception e2) {
|
|
ApiManager.logger.error("loadFromFileQueue: Exception", e2);
|
|
}
|
|
}
|
|
};
|
|
|
|
public ApiManager(SingularWorkerThread singularWorkerThread, Context context, Queue queue) {
|
|
this.context = context;
|
|
this.queue = queue;
|
|
if (queue == null) {
|
|
return;
|
|
}
|
|
logger.debug("Queue: %s", queue.getClass().getSimpleName());
|
|
if (singularWorkerThread == null) {
|
|
return;
|
|
}
|
|
this.worker = singularWorkerThread;
|
|
singularWorkerThread.start();
|
|
}
|
|
|
|
public void wakeUp() {
|
|
SingularWorkerThread singularWorkerThread = this.worker;
|
|
if (singularWorkerThread == null) {
|
|
return;
|
|
}
|
|
singularWorkerThread.getHandler().removeCallbacksAndMessages(null);
|
|
this.worker.post(this.runnable);
|
|
}
|
|
|
|
public void tryMigrateEventsFromFileQueue() {
|
|
if (this.queue instanceof SQLitePersistentQueue) {
|
|
this.worker.post(this.migrateEventsFromFileQueue);
|
|
}
|
|
}
|
|
|
|
public void tryMigrateEventsFromOldSQLiteQueue() {
|
|
this.worker.post(new Runnable() { // from class: com.singular.sdk.internal.ApiManager.1
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
try {
|
|
new OfflineEventsMigrator(ApiManager.this.context).migrate();
|
|
} catch (RuntimeException e) {
|
|
ApiManager.logger.error("migrateEventsFromOldSQLiteQueue: RuntimeException", e);
|
|
} catch (Exception e2) {
|
|
ApiManager.logger.error("migrateEventsFromOldSQLiteQueue: Exception", e2);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
public void enqueue(BaseApi baseApi) {
|
|
if (baseApi != null) {
|
|
try {
|
|
if (this.queue == null) {
|
|
return;
|
|
}
|
|
if (!(baseApi instanceof ApiGDPRConsent) && !(baseApi instanceof ApiGDPRUnder13)) {
|
|
baseApi.put("event_index", String.valueOf(Utils.getEventIndex(this.context)));
|
|
}
|
|
baseApi.put("singular_install_id", Utils.getSingularId(this.context).toString());
|
|
JSONObject globalPropertiesJSON = SingularInstance.getInstance().getGlobalPropertiesJSON();
|
|
if (globalPropertiesJSON.length() != 0) {
|
|
baseApi.put("global_properties", globalPropertiesJSON.toString());
|
|
}
|
|
this.queue.add(baseApi.toJsonAsString());
|
|
wakeUp();
|
|
} catch (IndexOutOfBoundsException unused) {
|
|
} catch (Exception e) {
|
|
logger.error("error in enqueue()", e);
|
|
}
|
|
}
|
|
}
|
|
}
|