- 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
232 lines
10 KiB
Java
232 lines
10 KiB
Java
package com.helpshift.analytics;
|
|
|
|
import com.helpshift.concurrency.HSThreadingService;
|
|
import com.helpshift.log.HSLogger;
|
|
import com.helpshift.network.HSRequestData;
|
|
import com.helpshift.network.HTTPTransport;
|
|
import com.helpshift.network.NetworkConstants;
|
|
import com.helpshift.network.POSTNetwork;
|
|
import com.helpshift.network.exception.HSRootApiException;
|
|
import com.helpshift.platform.Device;
|
|
import com.helpshift.storage.HSPersistentStorage;
|
|
import com.helpshift.user.UserManager;
|
|
import com.helpshift.util.Utils;
|
|
import com.mbridge.msdk.foundation.entity.CampaignEx;
|
|
import com.vungle.ads.internal.signals.SignalManager;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import org.json.JSONArray;
|
|
import org.json.JSONObject;
|
|
|
|
/* loaded from: classes3.dex */
|
|
public class HSAnalyticsEventDM {
|
|
public final HSWebchatAnalyticsManager analyticsManager;
|
|
public final Device device;
|
|
public final HSThreadingService hsServices;
|
|
public final HTTPTransport httpTransport;
|
|
public final HSPersistentStorage persistentStorage;
|
|
public final UserManager userManager;
|
|
|
|
public HSAnalyticsEventDM(Device device, UserManager userManager, HSPersistentStorage hSPersistentStorage, HSWebchatAnalyticsManager hSWebchatAnalyticsManager, HSThreadingService hSThreadingService, HTTPTransport hTTPTransport) {
|
|
this.device = device;
|
|
this.userManager = userManager;
|
|
this.persistentStorage = hSPersistentStorage;
|
|
this.analyticsManager = hSWebchatAnalyticsManager;
|
|
this.hsServices = hSThreadingService;
|
|
this.httpTransport = hTTPTransport;
|
|
}
|
|
|
|
public synchronized void sendAppLaunchEvent() {
|
|
long lastSuccessfulAppLaunchEventSyncTime = this.persistentStorage.getLastSuccessfulAppLaunchEventSyncTime();
|
|
long currentTimeMillis = System.currentTimeMillis();
|
|
addAppLaunchEventToStorage(currentTimeMillis);
|
|
if (currentTimeMillis > SignalManager.TWENTY_FOUR_HOURS_MILLIS + lastSuccessfulAppLaunchEventSyncTime && !Utils.isToday(lastSuccessfulAppLaunchEventSyncTime)) {
|
|
sendAppLaunchEventToServer(currentTimeMillis);
|
|
}
|
|
}
|
|
|
|
public synchronized void sendAllAppLaunchEvents() {
|
|
sendAppLaunchEventToServer(System.currentTimeMillis());
|
|
}
|
|
|
|
public final void sendAppLaunchEventToServer(final long j) {
|
|
final JSONArray consumeStoredAppLaunchEventsJson = consumeStoredAppLaunchEventsJson();
|
|
if (Utils.isEmpty(consumeStoredAppLaunchEventsJson)) {
|
|
return;
|
|
}
|
|
this.hsServices.getNetworkService().submit(new Runnable() { // from class: com.helpshift.analytics.HSAnalyticsEventDM.1
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
try {
|
|
int sendEventsToServer = HSAnalyticsEventDM.this.sendEventsToServer(consumeStoredAppLaunchEventsJson, false);
|
|
if (sendEventsToServer < 200 || sendEventsToServer >= 300) {
|
|
return;
|
|
}
|
|
HSAnalyticsEventDM.this.persistentStorage.setLastAppLaunchEventSyncTime(j);
|
|
} catch (HSRootApiException e) {
|
|
HSLogger.e("analyticsMngr", "Failed to send the app launch events", e);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
public final int sendEventsToServer(JSONArray jSONArray, boolean z) {
|
|
if (Utils.isEmpty(jSONArray)) {
|
|
return 200;
|
|
}
|
|
try {
|
|
HSLogger.d("analyticsMngr", z ? "Syncing failed analytics events" : "Syncing analytics events");
|
|
Map buildEventRequestMap = buildEventRequestMap();
|
|
buildEventRequestMap.put("e", jSONArray.toString());
|
|
int status = new POSTNetwork(this.httpTransport, buildAnalyticsRoute()).makeRequest(new HSRequestData(NetworkConstants.buildHeaderMap(this.device, this.persistentStorage.getPlatformId()), buildEventRequestMap)).getStatus();
|
|
if ((status < 200 || status >= 300) && !z) {
|
|
updateFailedEventsStore(jSONArray);
|
|
}
|
|
return status;
|
|
} catch (HSRootApiException e) {
|
|
HSLogger.e("analyticsMngr", "Failed to send the events", e);
|
|
if (!z) {
|
|
updateFailedEventsStore(jSONArray);
|
|
}
|
|
throw e;
|
|
}
|
|
}
|
|
|
|
public void sendQuitEvent() {
|
|
final JSONArray jSONArray = new JSONArray();
|
|
try {
|
|
JSONObject jSONObject = new JSONObject();
|
|
jSONObject.put("ts", System.currentTimeMillis());
|
|
jSONObject.put("t", CampaignEx.JSON_KEY_AD_Q);
|
|
jSONArray.put(jSONObject);
|
|
this.hsServices.getNetworkService().submit(new Runnable() { // from class: com.helpshift.analytics.HSAnalyticsEventDM.2
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
try {
|
|
HSAnalyticsEventDM.this.sendEventsToServer(jSONArray, false);
|
|
} catch (HSRootApiException e) {
|
|
HSLogger.e("analyticsMngr", "Failed to send quit event", e);
|
|
}
|
|
}
|
|
});
|
|
} catch (Exception e) {
|
|
HSLogger.e("analyticsMngr", "Error in creating quit event", e);
|
|
}
|
|
}
|
|
|
|
public void sendFailedEvents() {
|
|
final JSONArray failedAnalyticsEvents = this.persistentStorage.getFailedAnalyticsEvents();
|
|
if (Utils.isEmpty(failedAnalyticsEvents)) {
|
|
return;
|
|
}
|
|
this.hsServices.getNetworkService().submit(new Runnable() { // from class: com.helpshift.analytics.HSAnalyticsEventDM.3
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
try {
|
|
int sendEventsToServer = HSAnalyticsEventDM.this.sendEventsToServer(failedAnalyticsEvents, true);
|
|
if (sendEventsToServer < 200 || sendEventsToServer >= 300) {
|
|
return;
|
|
}
|
|
HSAnalyticsEventDM.this.persistentStorage.setFailedAnalyticsEvents(new JSONArray());
|
|
} catch (HSRootApiException e) {
|
|
HSLogger.e("analyticsMngr", "Error trying to sync failed events", e);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
public final void updateFailedEventsStore(JSONArray jSONArray) {
|
|
if (Utils.isEmpty(jSONArray)) {
|
|
return;
|
|
}
|
|
JSONArray failedAnalyticsEvents = this.persistentStorage.getFailedAnalyticsEvents();
|
|
if (failedAnalyticsEvents.length() > 1000) {
|
|
JSONArray jSONArray2 = new JSONArray();
|
|
for (int length = jSONArray.length(); length < 1000; length++) {
|
|
jSONArray2.put(failedAnalyticsEvents.get(length));
|
|
}
|
|
failedAnalyticsEvents = jSONArray2;
|
|
}
|
|
for (int i = 0; i < jSONArray.length(); i++) {
|
|
failedAnalyticsEvents.put(jSONArray.get(i));
|
|
}
|
|
this.persistentStorage.setFailedAnalyticsEvents(failedAnalyticsEvents);
|
|
}
|
|
|
|
public final void addAppLaunchEventToStorage(long j) {
|
|
JSONArray consumeStoredAppLaunchEventsJson = consumeStoredAppLaunchEventsJson();
|
|
if (consumeStoredAppLaunchEventsJson.length() >= 1000) {
|
|
this.persistentStorage.storeAppLaunchEvents(consumeStoredAppLaunchEventsJson.toString());
|
|
return;
|
|
}
|
|
try {
|
|
JSONObject jSONObject = new JSONObject();
|
|
jSONObject.put("ts", j);
|
|
jSONObject.put("t", "a");
|
|
consumeStoredAppLaunchEventsJson.put(jSONObject);
|
|
} catch (Exception e) {
|
|
HSLogger.e("analyticsMngr", "Error in adding app launch event to existing array", e);
|
|
}
|
|
this.persistentStorage.storeAppLaunchEvents(consumeStoredAppLaunchEventsJson.toString());
|
|
}
|
|
|
|
public final synchronized JSONArray consumeStoredAppLaunchEventsJson() {
|
|
JSONArray jSONArray;
|
|
JSONArray jSONArray2;
|
|
Exception e;
|
|
String appLaunchEvents;
|
|
jSONArray = new JSONArray();
|
|
try {
|
|
appLaunchEvents = this.persistentStorage.getAppLaunchEvents();
|
|
} catch (Exception e2) {
|
|
jSONArray2 = jSONArray;
|
|
e = e2;
|
|
}
|
|
if (!Utils.isEmpty(appLaunchEvents)) {
|
|
jSONArray2 = new JSONArray(appLaunchEvents);
|
|
try {
|
|
this.persistentStorage.clearAppLaunchEvents();
|
|
} catch (Exception e3) {
|
|
e = e3;
|
|
HSLogger.e("analyticsMngr", "Error in getting stored app launch events", e);
|
|
jSONArray = jSONArray2;
|
|
return jSONArray;
|
|
}
|
|
jSONArray = jSONArray2;
|
|
}
|
|
return jSONArray;
|
|
}
|
|
|
|
public final Map buildEventRequestMap() {
|
|
HashMap hashMap = new HashMap();
|
|
String deviceId = this.device.getDeviceId();
|
|
String activeUserId = this.userManager.getActiveUserId();
|
|
String legacyAnalyticsEventId = getLegacyAnalyticsEventId(activeUserId);
|
|
hashMap.put("did", deviceId);
|
|
if (!Utils.isEmpty(legacyAnalyticsEventId)) {
|
|
deviceId = legacyAnalyticsEventId;
|
|
}
|
|
hashMap.put("id", deviceId);
|
|
hashMap.put("timestamp", String.valueOf(System.currentTimeMillis()));
|
|
if (Utils.isNotEmpty(activeUserId)) {
|
|
hashMap.put("uid", activeUserId);
|
|
}
|
|
String activeUserEmail = this.userManager.getActiveUserEmail();
|
|
if (Utils.isNotEmpty(activeUserEmail)) {
|
|
hashMap.put("email", activeUserEmail);
|
|
}
|
|
hashMap.putAll(this.analyticsManager.getCommonAnalyticsMap());
|
|
hashMap.put("platform-id", this.persistentStorage.getPlatformId());
|
|
return hashMap;
|
|
}
|
|
|
|
public final String getLegacyAnalyticsEventId(String str) {
|
|
String string = this.persistentStorage.getString("legacy_event_ids");
|
|
return (Utils.isEmpty(string) || !Utils.isValidJsonString(string)) ? "" : new JSONObject(string).getString(str);
|
|
}
|
|
|
|
public final String buildAnalyticsRoute() {
|
|
return "https://api." + this.persistentStorage.getHost() + "/events/v1/" + this.persistentStorage.getDomain() + "/websdk/";
|
|
}
|
|
}
|