Perfume Of Love v2.14.9版本的 MD5 值为:16011aefc5a55805771706ce3b259b4e
以下内容为反编译后的 GAEvents.java 源代码,内容仅作参考
package com.gameanalytics.sdk.events;
import android.util.Base64;
import com.facebook.gamingservices.cloudgaming.internal.SDKConstants;
import com.facebook.internal.security.CertificateUtil;
import com.gameanalytics.sdk.GAAdAction;
import com.gameanalytics.sdk.GAAdError;
import com.gameanalytics.sdk.GAAdType;
import com.gameanalytics.sdk.GAErrorSeverity;
import com.gameanalytics.sdk.GAProgressionStatus;
import com.gameanalytics.sdk.GAResourceFlowType;
import com.gameanalytics.sdk.http.EGAHTTPApiResponse;
import com.gameanalytics.sdk.http.GAHTTPApi;
import com.gameanalytics.sdk.logging.GALogger;
import com.gameanalytics.sdk.state.GAState;
import com.gameanalytics.sdk.store.GAStore;
import com.gameanalytics.sdk.threading.GAThreading;
import com.gameanalytics.sdk.threading.IBlock;
import com.gameanalytics.sdk.utilities.GAUtilities;
import com.gameanalytics.sdk.validators.GAValidator;
import com.gameanalytics.sdk.validators.ValidationResult;
import com.mbridge.msdk.playercommon.exoplayer2.C;
import com.tapjoy.TapjoyConstants;
import com.unity3d.ads.metadata.InAppPurchaseMetaData;
import com.vungle.warren.model.ReportDBAdapter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
public class GAEvents {
private static final String CATEGORY_ADS = "ads";
private static final String CATEGORY_BUSINESS = "business";
private static final String CATEGORY_DESIGN = "design";
private static final String CATEGORY_ERROR = "error";
private static final String CATEGORY_HEALTH = "health";
private static final String CATEGORY_IMPRESSION = "impression";
private static final String CATEGORY_PROGRESSION = "progression";
private static final String CATEGORY_RESOURCE = "resource";
private static final String CATEGORY_SESSION_END = "session_end";
private static final String CATEGORY_SESSION_START = "user";
private static final int MAX_EVENTS_SIZE = 500;
private boolean isRunning;
private boolean keepRunning;
private static final GAEvents INSTANCE = new GAEvents();
private static final IBlock processEventQueueBlock = new IBlock() {
@Override
public String getName() {
return "processEventQueue";
}
@Override
public void execute() {
GAEvents.processEventQueue();
}
};
static int countStart = 0;
static int countEnd = 0;
private GAEvents() {
}
private static GAEvents getInstance() {
return INSTANCE;
}
public static void ensureEventQueueIsRunning() {
getInstance().keepRunning = true;
if (getInstance().isRunning) {
return;
}
getInstance().isRunning = true;
GAThreading.scheduleTimer(8.0d, processEventQueueBlock);
}
public static void stopEventQueue() {
getInstance().keepRunning = false;
}
public static void processEventQueue() {
processEvents("", true);
if (getInstance().keepRunning) {
GAThreading.scheduleTimer(8.0d, processEventQueueBlock);
} else {
getInstance().isRunning = false;
}
}
public static void processEvents(String str, boolean z) {
if (GAState.isEventSubmissionEnabled()) {
try {
String uuid = UUID.randomUUID().toString();
String str2 = "DELETE FROM ga_events WHERE status = '" + uuid + "'";
String str3 = "UPDATE ga_events SET status = 'new' WHERE status = '" + uuid + "';";
if (z) {
cleanupEvents();
fixMissingSessionEndEvents();
}
String str4 = str.length() != 0 ? " AND category='" + str + "' " : "";
String str5 = "UPDATE ga_events SET status = '" + uuid + "' WHERE status = 'new' " + str4 + ";";
JSONArray executeQuerySync = GAStore.executeQuerySync("SELECT event FROM ga_events WHERE status = 'new' " + str4 + ";");
if (executeQuerySync != null && executeQuerySync.length() != 0) {
if (executeQuerySync.length() > 500) {
JSONArray executeQuerySync2 = GAStore.executeQuerySync("SELECT client_ts FROM ga_events WHERE status = 'new' " + str4 + " ORDER BY client_ts ASC LIMIT 0,500;");
if (executeQuerySync2 == null) {
return;
}
String string = ((JSONObject) executeQuerySync2.get(executeQuerySync2.length() - 1)).getString("client_ts");
JSONArray executeQuerySync3 = GAStore.executeQuerySync("SELECT event FROM ga_events WHERE status = 'new' " + str4 + " AND client_ts<='" + string + "';");
if (executeQuerySync3 == null) {
return;
}
str5 = "UPDATE ga_events SET status='" + uuid + "' WHERE status='new' " + str4 + " AND client_ts<='" + string + "';";
executeQuerySync = executeQuerySync3;
}
GALogger.i("Event queue: Sending " + executeQuerySync.length() + " events.");
if (GAStore.executeQuerySync(str5) == null) {
return;
}
ArrayList<JSONObject> arrayList = new ArrayList<>();
for (int i = 0; i < executeQuerySync.length(); i++) {
JSONObject dictionary = GAUtilities.dictionary(((JSONObject) executeQuerySync.get(i)).getString("event"));
if (dictionary.length() != 0) {
if (dictionary.has("client_ts") && !GAValidator.validateClientTs(dictionary.getLong("client_ts"))) {
dictionary.remove("client_ts");
}
arrayList.add(dictionary);
}
}
GAHTTPApi.GAHTTPApiResponseJSONObjectPair sendEventsInArray = GAHTTPApi.getInstance().sendEventsInArray(arrayList);
EGAHTTPApiResponse eGAHTTPApiResponse = sendEventsInArray.response;
JSONObject jSONObject = sendEventsInArray.json;
if (eGAHTTPApiResponse == EGAHTTPApiResponse.Ok) {
GAStore.executeQuerySync(str2);
GALogger.i("Event queue: " + executeQuerySync.length() + " events sent.");
return;
} else if (eGAHTTPApiResponse == EGAHTTPApiResponse.NoResponse) {
GALogger.w("Event queue: Failed to send events to collector - Retrying next time");
GAStore.executeQuerySync(str3);
return;
} else {
if (jSONObject != null) {
Object nextValue = new JSONTokener(jSONObject.toString()).nextValue();
GALogger.d(jSONObject.toString());
if (eGAHTTPApiResponse == EGAHTTPApiResponse.BadRequest && (nextValue instanceof JSONArray)) {
GALogger.w("Event queue: " + executeQuerySync.length() + " events sent. " + jSONObject.length() + " events failed GA server validation.");
} else {
GALogger.w("Event queue: Failed to send events.");
}
} else {
GALogger.w("Event queue: Failed to send events.");
}
GAStore.executeQuerySync(str2);
return;
}
}
GALogger.i("Event queue: No events to send");
updateSessionTime();
} catch (JSONException e) {
e.printStackTrace();
GAHTTPApi.getInstance().sendSdkErrorEvent(EGASdkErrorCategory.Json, EGASdkErrorArea.ProcessEvents, EGASdkErrorAction.JsonError, e.toString(), GAState.getGameKey(), GAState.getSecretKey());
}
}
}
private static void updateSessionTime() throws JSONException {
if (GAState.sessionIsStarted()) {
JSONObject eventAnnotations = GAState.getEventAnnotations();
addDimensionsToEvent(eventAnnotations);
addCustomFieldsToEvent(eventAnnotations, GAState.validateAndCleanCustomFields(GAState.getGlobalCustomEventFields()));
String jSONObject = eventAnnotations.toString();
ArrayList arrayList = new ArrayList();
arrayList.add(eventAnnotations.getString("session_id"));
arrayList.add(String.valueOf(GAState.getSessionStart()));
arrayList.add(jSONObject);
GAStore.executeQuerySync("INSERT OR REPLACE INTO ga_session(session_id, timestamp, event) VALUES(?, ?, ?);", arrayList);
}
}
public static void cleanupEvents() {
GAStore.executeQuerySync("UPDATE ga_events SET status = 'new';");
}
public static void fixMissingSessionEndEvents() throws JSONException {
if (GAState.isEventSubmissionEnabled()) {
ArrayList arrayList = new ArrayList();
arrayList.add(GAState.getSessionId());
JSONArray executeQuerySync = GAStore.executeQuerySync("SELECT timestamp, event FROM ga_session WHERE session_id != ?;", arrayList);
if (executeQuerySync == null || executeQuerySync.length() == 0) {
return;
}
GALogger.i(executeQuerySync.length() + " session(s) located with missing session_end event.");
for (int i = 0; i < executeQuerySync.length(); i++) {
JSONObject jSONObject = executeQuerySync.getJSONObject(i);
JSONObject dictionary = GAUtilities.dictionary(jSONObject.getString("event"));
long j = dictionary.getLong("client_ts");
long optLong = jSONObject.optLong("timestamp", 0L);
long max = Math.max(0L, j - optLong);
GALogger.d("fixMissingSessionEndEvents length calculated: " + max + ", start_ts=" + optLong + ", event_ts=" + j);
StringBuilder sb = new StringBuilder();
sb.append("DebugUser EndEvent (missing): ");
sb.append(countEnd);
GALogger.i(sb.toString());
countEnd = countEnd + 1;
dictionary.put("category", CATEGORY_SESSION_END);
dictionary.put("length", max);
addEventToStore(dictionary);
}
}
}
private static void addEventToStore(JSONObject jSONObject) {
if (GAState.isEventSubmissionEnabled()) {
if (!GAStore.getTableReady()) {
GALogger.w("Could not add event: SDK datastore error");
} else if (!GAState.isInitialized()) {
GALogger.w("Could not add event: SDK is not initialized");
} else {
try {
if (GAStore.isDbTooLargeForEvents() && !GAUtilities.stringMatch(jSONObject.getString("category"), "^(user|session_end|business)$")) {
GALogger.w("Database too large. Event has been blocked.");
GAHTTPApi.getInstance().sendSdkErrorEvent(EGASdkErrorCategory.Database, EGASdkErrorArea.AddEventsToStore, EGASdkErrorAction.DatabaseTooLarge, "", GAState.getGameKey(), GAState.getSecretKey());
return;
}
JSONObject eventAnnotations = GAState.getEventAnnotations();
Iterator<String> keys = jSONObject.keys();
while (keys.hasNext()) {
String next = keys.next();
eventAnnotations.put(next, jSONObject.get(next));
}
String jSONObject2 = eventAnnotations.toString();
GALogger.ii("Event added to queue: " + jSONObject2);
ArrayList arrayList = new ArrayList();
arrayList.add("new");
arrayList.add(eventAnnotations.getString("category"));
arrayList.add(eventAnnotations.getString("session_id"));
arrayList.add(eventAnnotations.getString("client_ts"));
arrayList.add(jSONObject2);
GAStore.executeQuerySync("INSERT INTO ga_events (status, category, session_id, client_ts, event) VALUES(?, ?, ?, ?, ?);", arrayList);
if (jSONObject.getString("category").equals(CATEGORY_SESSION_END)) {
arrayList.clear();
arrayList.add(eventAnnotations.getString("session_id"));
GAStore.executeQuerySync("DELETE FROM ga_session WHERE session_id = ?;", arrayList);
return;
}
updateSessionTime();
} catch (JSONException e) {
GALogger.e("addEventToStore: error using json");
e.printStackTrace();
GAHTTPApi.getInstance().sendSdkErrorEvent(EGASdkErrorCategory.Database, EGASdkErrorArea.AddEventsToStore, EGASdkErrorAction.DatabaseTooLarge, "", GAState.getGameKey(), GAState.getSecretKey());
}
}
}
}
public static void addSessionStartEvent() {
if (GAState.isEventSubmissionEnabled()) {
GALogger.d("DebugUser: Session start: " + countStart);
countStart = countStart + 1;
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put("category", CATEGORY_SESSION_START);
if (GAState.isNewInstall()) {
jSONObject.put("install", true);
GAState.setNewInstall(false);
}
} catch (JSONException e) {
GALogger.e("addSessionStartEvent: error creating json");
e.printStackTrace();
}
GAState.incrementSessionNum();
ArrayList arrayList = new ArrayList();
arrayList.add("session_num");
arrayList.add(String.valueOf(GAState.getSessionNum()));
GAStore.executeQuerySync("INSERT OR REPLACE INTO ga_state (key, value) VALUES(?, ?);", arrayList);
addDimensionsToEvent(jSONObject);
addCustomFieldsToEvent(jSONObject, GAState.validateAndCleanCustomFields(GAState.getGlobalCustomEventFields()));
addEventToStore(jSONObject);
GALogger.i("Add SESSION START event");
processEvents(CATEGORY_SESSION_START, false);
}
}
public static void addSessionEndEvent() {
if (GAState.isEventSubmissionEnabled()) {
GALogger.d("DebugUser: End event:" + countEnd);
countEnd = countEnd + 1;
long clientTsAdjusted = GAState.getClientTsAdjusted() - GAState.getSessionStart();
if (clientTsAdjusted < 0) {
GALogger.w("Session length was calculated to be less then 0. Should not be possible. Resetting to 0.");
clientTsAdjusted = 0;
}
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put("category", CATEGORY_SESSION_END);
jSONObject.put("length", clientTsAdjusted);
} catch (JSONException e) {
GALogger.e("addSessionEndEvent: error creating json");
e.printStackTrace();
GAHTTPApi.getInstance().sendSdkErrorEvent(EGASdkErrorCategory.Json, EGASdkErrorArea.SessionEnd, EGASdkErrorAction.JsonError, e.toString(), GAState.getGameKey(), GAState.getSecretKey());
}
addDimensionsToEvent(jSONObject);
addCustomFieldsToEvent(jSONObject, GAState.validateAndCleanCustomFields(GAState.getGlobalCustomEventFields()));
addEventToStore(jSONObject);
GALogger.i("Add SESSION END event.");
processEvents("", false);
}
}
public static void addHealthEvent(String str) {
if (GAState.isEventSubmissionEnabled()) {
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put("category", "health");
jSONObject.put("fps_data_sketch", str);
} catch (JSONException e) {
GALogger.e("addBusinessEvent: Error creating json");
e.printStackTrace();
GAHTTPApi.getInstance().sendSdkErrorEvent(EGASdkErrorCategory.Json, EGASdkErrorArea.HealthEvent, EGASdkErrorAction.JsonError, e.toString(), GAState.getGameKey(), GAState.getSecretKey());
}
addDimensionsToEvent(jSONObject);
addCustomFieldsToEvent(jSONObject, GAState.validateAndCleanCustomFields(GAState.getGlobalCustomEventFields()));
addEventToStore(jSONObject);
GALogger.i("Add HEALTH event.");
}
}
public static void addBusinessEvent(String str, int i, String str2, String str3, String str4, String str5, String str6, String str7, Map<String, Object> map, boolean z) {
if (GAState.isEventSubmissionEnabled()) {
ValidationResult validateBusinessEvent = GAValidator.validateBusinessEvent(str, i, str4, str2, str3, str5, str6, str7);
if (validateBusinessEvent != null) {
GAHTTPApi.getInstance().sendSdkErrorEvent(validateBusinessEvent.category, validateBusinessEvent.area, validateBusinessEvent.action, validateBusinessEvent.parameter, validateBusinessEvent.reason, GAState.getGameKey(), GAState.getSecretKey());
return;
}
JSONObject jSONObject = new JSONObject();
GAState.incrementTransactionNum();
ArrayList arrayList = new ArrayList();
arrayList.add("transaction_num");
arrayList.add(String.valueOf(GAState.getTransactionNum()));
GAStore.executeQuerySync("INSERT OR REPLACE INTO ga_state (key, value) VALUES(?, ?);", arrayList);
try {
JSONObject jSONObject2 = new JSONObject();
if (str5 != null && str5.length() != 0) {
try {
jSONObject2.put("receipt", Base64.encodeToString(str5.getBytes(C.UTF8_NAME), 0));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
jSONObject2.put(TapjoyConstants.TJC_STORE, str6);
if (str7 != null && str7.length() != 0) {
jSONObject2.put(InAppPurchaseMetaData.KEY_SIGNATURE, str7);
}
}
jSONObject.put("event_id", str2 + CertificateUtil.DELIMITER + str3);
jSONObject.put("category", CATEGORY_BUSINESS);
jSONObject.put("currency", str);
jSONObject.put("amount", i);
jSONObject.put("transaction_num", GAState.getTransactionNum());
if (str4 != null && str4.length() != 0) {
jSONObject.put("cart_type", str4);
}
if (jSONObject2.length() != 0) {
jSONObject.put("receipt_info", jSONObject2);
}
addDimensionsToEvent(jSONObject);
HashMap hashMap = new HashMap((map == null || map.isEmpty()) ? GAState.getGlobalCustomEventFields() : map);
if (z && map != null && !map.isEmpty()) {
for (Map.Entry<String, Object> entry : GAState.getGlobalCustomEventFields().entrySet()) {
if (!hashMap.containsKey(entry.getKey())) {
hashMap.put(entry.getKey(), entry.getValue());
}
}
}
addCustomFieldsToEvent(jSONObject, GAState.validateAndCleanCustomFields(hashMap));
StringBuilder sb = new StringBuilder();
sb.append("Add BUSINESS event: {currency:");
sb.append(str);
sb.append(", amount:");
sb.append(i);
sb.append(", itemType:");
sb.append(str2);
sb.append(", itemId:");
sb.append(str3);
sb.append(", cartType:");
sb.append(str4);
String str8 = "";
if (str5 != null && str5.length() != 0) {
StringBuilder sb2 = new StringBuilder();
sb2.append(", receipt_info: { store: ");
sb2.append(str6);
sb2.append(", receipt: #RECEIPT#");
if (str7 != null && str7.length() != 0) {
str8 = ", signature: " + str7;
}
sb2.append(str8);
sb2.append("}");
str8 = sb2.toString();
}
sb.append(str8);
sb.append("}");
GALogger.i(sb.toString());
addEventToStore(jSONObject);
} catch (JSONException e2) {
GALogger.e("addBusinessEvent: Error creating json");
e2.printStackTrace();
GAHTTPApi.getInstance().sendSdkErrorEvent(EGASdkErrorCategory.Json, EGASdkErrorArea.BusinessEvent, EGASdkErrorAction.JsonError, e2.toString(), GAState.getGameKey(), GAState.getSecretKey());
}
}
}
public static void addResourceEvent(GAResourceFlowType gAResourceFlowType, String str, double d, String str2, String str3, Map<String, Object> map, boolean z) {
if (GAState.isEventSubmissionEnabled()) {
ValidationResult validateResourceEvent = GAValidator.validateResourceEvent(gAResourceFlowType, str, (long) d, str2, str3);
if (validateResourceEvent != null) {
GAHTTPApi.getInstance().sendSdkErrorEvent(validateResourceEvent.category, validateResourceEvent.area, validateResourceEvent.action, validateResourceEvent.parameter, validateResourceEvent.reason, GAState.getGameKey(), GAState.getSecretKey());
return;
}
if (gAResourceFlowType == GAResourceFlowType.Sink) {
d *= -1.0d;
}
try {
JSONObject jSONObject = new JSONObject();
String gAResourceFlowType2 = gAResourceFlowType.toString();
jSONObject.put("event_id", gAResourceFlowType2 + CertificateUtil.DELIMITER + str + CertificateUtil.DELIMITER + str2 + CertificateUtil.DELIMITER + str3);
jSONObject.put("category", CATEGORY_RESOURCE);
jSONObject.put("amount", d);
addDimensionsToEvent(jSONObject);
HashMap hashMap = new HashMap((map == null || map.isEmpty()) ? GAState.getGlobalCustomEventFields() : map);
if (z && map != null && !map.isEmpty()) {
for (Map.Entry<String, Object> entry : GAState.getGlobalCustomEventFields().entrySet()) {
if (!hashMap.containsKey(entry.getKey())) {
hashMap.put(entry.getKey(), entry.getValue());
}
}
}
addCustomFieldsToEvent(jSONObject, GAState.validateAndCleanCustomFields(hashMap));
GALogger.i("Add RESOURCE event: {currency:" + str + ", amount:" + d + ", itemType:" + str2 + ", itemId:" + str3 + "}");
addEventToStore(jSONObject);
} catch (JSONException e) {
GALogger.e("addResourceEvent: Error creating json");
e.printStackTrace();
GAHTTPApi.getInstance().sendSdkErrorEvent(EGASdkErrorCategory.Json, EGASdkErrorArea.ResourceEvent, EGASdkErrorAction.JsonError, e.toString(), GAState.getGameKey(), GAState.getSecretKey());
}
}
}
public static void addProgressionEvent(GAProgressionStatus gAProgressionStatus, String str, String str2, String str3, int i, boolean z, Map<String, Object> map, boolean z2) {
String str4;
if (GAState.isEventSubmissionEnabled()) {
String gAProgressionStatus2 = gAProgressionStatus.toString();
ValidationResult validateProgressionEvent = GAValidator.validateProgressionEvent(gAProgressionStatus, str, str2, str3);
if (validateProgressionEvent != null) {
GAHTTPApi.getInstance().sendSdkErrorEvent(validateProgressionEvent.category, validateProgressionEvent.area, validateProgressionEvent.action, validateProgressionEvent.parameter, validateProgressionEvent.reason, GAState.getGameKey(), GAState.getSecretKey());
return;
}
JSONObject jSONObject = new JSONObject();
if (str2 == null || str2.length() == 0) {
str4 = str;
} else if (str3 == null || str3.length() == 0) {
str4 = str + CertificateUtil.DELIMITER + str2;
} else {
str4 = str + CertificateUtil.DELIMITER + str2 + CertificateUtil.DELIMITER + str3;
}
try {
jSONObject.put("category", CATEGORY_PROGRESSION);
jSONObject.put("event_id", gAProgressionStatus2 + CertificateUtil.DELIMITER + str4);
int i2 = 0;
if (z && gAProgressionStatus != GAProgressionStatus.Start) {
jSONObject.put("score", i);
}
if (gAProgressionStatus == GAProgressionStatus.Fail) {
GAState.incrementProgressionTries(str4);
}
if (gAProgressionStatus == GAProgressionStatus.Complete) {
GAState.incrementProgressionTries(str4);
i2 = GAState.getProgressionTries(str4);
jSONObject.put("attempt_num", i2);
GAState.clearProgressionTries(str4);
}
addDimensionsToEvent(jSONObject);
HashMap hashMap = new HashMap((map == null || map.isEmpty()) ? GAState.getGlobalCustomEventFields() : map);
if (z2 && map != null && !map.isEmpty()) {
for (Map.Entry<String, Object> entry : GAState.getGlobalCustomEventFields().entrySet()) {
if (!hashMap.containsKey(entry.getKey())) {
hashMap.put(entry.getKey(), entry.getValue());
}
}
}
addCustomFieldsToEvent(jSONObject, GAState.validateAndCleanCustomFields(hashMap));
GALogger.i("Add PROGRESSION event: {status:" + gAProgressionStatus2 + ", progression01:" + str + ", progression02:" + str2 + ", progression03:" + str3 + ", score:" + i + ", attempt:" + i2 + "}");
addEventToStore(jSONObject);
} catch (JSONException e) {
GALogger.e("addProgressionEvent: Error creating json");
e.printStackTrace();
GAHTTPApi.getInstance().sendSdkErrorEvent(EGASdkErrorCategory.Json, EGASdkErrorArea.ProgressionEvent, EGASdkErrorAction.JsonError, e.toString(), GAState.getGameKey(), GAState.getSecretKey());
}
}
}
public static void addDesignEvent(String str, double d, boolean z, Map<String, Object> map, boolean z2) {
if (GAState.isEventSubmissionEnabled()) {
ValidationResult validateDesignEvent = GAValidator.validateDesignEvent(str);
if (validateDesignEvent != null) {
GAHTTPApi.getInstance().sendSdkErrorEvent(validateDesignEvent.category, validateDesignEvent.area, validateDesignEvent.action, validateDesignEvent.parameter, validateDesignEvent.reason, GAState.getGameKey(), GAState.getSecretKey());
return;
}
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put("category", CATEGORY_DESIGN);
jSONObject.put("event_id", str);
if (z) {
jSONObject.put("value", d);
}
addDimensionsToEvent(jSONObject);
HashMap hashMap = new HashMap((map == null || map.isEmpty()) ? GAState.getGlobalCustomEventFields() : map);
if (z2 && map != null && !map.isEmpty()) {
for (Map.Entry<String, Object> entry : GAState.getGlobalCustomEventFields().entrySet()) {
if (!hashMap.containsKey(entry.getKey())) {
hashMap.put(entry.getKey(), entry.getValue());
}
}
}
addCustomFieldsToEvent(jSONObject, GAState.validateAndCleanCustomFields(hashMap));
GALogger.i("Add DESIGN event: {eventId:" + str + ", value:" + d + "}");
addEventToStore(jSONObject);
} catch (JSONException e) {
GALogger.e("addDesignEvent: Error creating json");
e.printStackTrace();
GAHTTPApi.getInstance().sendSdkErrorEvent(EGASdkErrorCategory.Json, EGASdkErrorArea.DesignEvent, EGASdkErrorAction.JsonError, e.toString(), GAState.getGameKey(), GAState.getSecretKey());
}
}
}
public static void addErrorEvent(GAErrorSeverity gAErrorSeverity, String str, Map<String, Object> map, boolean z) {
addErrorEvent(gAErrorSeverity, str, map, z, false);
}
public static void addErrorEvent(GAErrorSeverity gAErrorSeverity, String str, Map<String, Object> map, boolean z, boolean z2) {
if (GAState.isEventSubmissionEnabled()) {
String gAErrorSeverity2 = gAErrorSeverity.toString();
ValidationResult validateErrorEvent = GAValidator.validateErrorEvent(gAErrorSeverity, str);
if (validateErrorEvent != null) {
GAHTTPApi.getInstance().sendSdkErrorEvent(validateErrorEvent.category, validateErrorEvent.area, validateErrorEvent.action, validateErrorEvent.parameter, validateErrorEvent.reason, GAState.getGameKey(), GAState.getSecretKey());
return;
}
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put("category", "error");
jSONObject.put(SDKConstants.PARAM_DEBUG_MESSAGE_SEVERITY, gAErrorSeverity2);
jSONObject.put("message", str);
addDimensionsToEvent(jSONObject);
if (!z2) {
HashMap hashMap = new HashMap((map == null || map.isEmpty()) ? GAState.getGlobalCustomEventFields() : map);
if (z && map != null && !map.isEmpty()) {
for (Map.Entry<String, Object> entry : GAState.getGlobalCustomEventFields().entrySet()) {
if (!hashMap.containsKey(entry.getKey())) {
hashMap.put(entry.getKey(), entry.getValue());
}
}
}
addCustomFieldsToEvent(jSONObject, GAState.validateAndCleanCustomFields(hashMap));
}
GALogger.i("Add ERROR event: {severity:" + gAErrorSeverity2 + ", message:" + str + "}");
addEventToStore(jSONObject);
} catch (JSONException e) {
GALogger.e("addErrorEvent: Error creating json");
e.printStackTrace();
GAHTTPApi.getInstance().sendSdkErrorEvent(EGASdkErrorCategory.Json, EGASdkErrorArea.ErrorEvent, EGASdkErrorAction.JsonError, e.toString(), GAState.getGameKey(), GAState.getSecretKey());
}
}
}
public static void addAdEvent(GAAdAction gAAdAction, GAAdType gAAdType, String str, String str2, GAAdError gAAdError, long j, boolean z, Map<String, Object> map, boolean z2) {
if (GAState.isEventSubmissionEnabled()) {
String gAAdAction2 = gAAdAction.toString();
String gAAdType2 = gAAdType.toString();
String gAAdError2 = gAAdError.toString();
ValidationResult validateAdEvent = GAValidator.validateAdEvent(gAAdAction, gAAdType, str, str2);
if (validateAdEvent != null) {
GAHTTPApi.getInstance().sendSdkErrorEvent(validateAdEvent.category, validateAdEvent.area, validateAdEvent.action, validateAdEvent.parameter, validateAdEvent.reason, GAState.getGameKey(), GAState.getSecretKey());
return;
}
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put("category", "ads");
jSONObject.put("ad_sdk_name", str);
jSONObject.put("ad_placement", str2);
jSONObject.put("ad_type", gAAdType2);
jSONObject.put("ad_action", gAAdAction2);
if (gAAdAction == GAAdAction.FailedShow && gAAdError2.length() > 0) {
jSONObject.put("ad_fail_show_reason", gAAdError2);
}
if (z && (gAAdType == GAAdType.RewardedVideo || gAAdType == GAAdType.Video)) {
jSONObject.put(ReportDBAdapter.ReportColumns.COLUMN_AD_DURATION, j);
}
addDimensionsToEvent(jSONObject);
HashMap hashMap = new HashMap((map == null || map.isEmpty()) ? GAState.getGlobalCustomEventFields() : map);
if (z2 && map != null && !map.isEmpty()) {
for (Map.Entry<String, Object> entry : GAState.getGlobalCustomEventFields().entrySet()) {
if (!hashMap.containsKey(entry.getKey())) {
hashMap.put(entry.getKey(), entry.getValue());
}
}
}
addCustomFieldsToEvent(jSONObject, GAState.validateAndCleanCustomFields(hashMap));
StringBuilder sb = new StringBuilder();
sb.append("Add AD event: {ad_sdk_name:");
sb.append(str);
sb.append(", ad_placement:");
sb.append(str2);
sb.append(", ad_type:");
sb.append(gAAdType2);
sb.append(", ad_action:");
sb.append(gAAdAction2);
String str3 = "";
sb.append((gAAdAction != GAAdAction.FailedShow || gAAdError2.length() <= 0) ? "" : ", ad_fail_show_reason:" + gAAdError2);
if (z && (gAAdType == GAAdType.RewardedVideo || gAAdType == GAAdType.Video)) {
str3 = ", ad_duration:" + j;
}
sb.append(str3);
sb.append("}");
GALogger.i(sb.toString());
addEventToStore(jSONObject);
} catch (JSONException e) {
GALogger.e("addAdEvent: Error creating json");
e.printStackTrace();
}
}
}
public static void addImpressionEvent(String str, String str2, JSONObject jSONObject, Map<String, Object> map, boolean z) {
if (GAState.isEventSubmissionEnabled()) {
ValidationResult validateImpressionEvent = GAValidator.validateImpressionEvent(str, str2, jSONObject);
if (validateImpressionEvent != null) {
GAHTTPApi.getInstance().sendSdkErrorEvent(validateImpressionEvent.category, validateImpressionEvent.area, validateImpressionEvent.action, validateImpressionEvent.parameter, validateImpressionEvent.reason, GAState.getGameKey(), GAState.getSecretKey());
return;
}
JSONObject jSONObject2 = new JSONObject();
try {
jSONObject2.put("category", "impression");
jSONObject2.put("ad_network_name", str);
jSONObject2.put("ad_network_version", str2);
if (jSONObject != null && jSONObject.length() > 0) {
jSONObject2.put("impression_data", jSONObject);
}
addDimensionsToEvent(jSONObject2);
HashMap hashMap = new HashMap((map == null || map.isEmpty()) ? GAState.getGlobalCustomEventFields() : map);
if (z && map != null && !map.isEmpty()) {
for (Map.Entry<String, Object> entry : GAState.getGlobalCustomEventFields().entrySet()) {
if (!hashMap.containsKey(entry.getKey())) {
hashMap.put(entry.getKey(), entry.getValue());
}
}
}
addCustomFieldsToEvent(jSONObject2, GAState.validateAndCleanCustomFields(hashMap));
GALogger.i("Add IMPRESSION event: {ad_network_name:" + str + ", ad_network_version:" + str2 + ", impression_data:#impressionData}");
addEventToStore(jSONObject2);
} catch (JSONException e) {
GALogger.e("addImpressionEvent: Error creating json");
e.printStackTrace();
}
}
}
public static void addDimensionsToEvent(JSONObject jSONObject) {
if (jSONObject == null) {
return;
}
try {
if (GAState.getDimension01().length() != 0) {
jSONObject.put("custom_01", GAState.getDimension01());
}
if (GAState.getDimension02().length() != 0) {
jSONObject.put("custom_02", GAState.getDimension02());
}
if (GAState.getDimension03().length() != 0) {
jSONObject.put("custom_03", GAState.getDimension03());
}
} catch (JSONException e) {
GALogger.e("addDimensionsToEvent: Error creating json");
e.printStackTrace();
GAHTTPApi.getInstance().sendSdkErrorEvent(EGASdkErrorCategory.Json, EGASdkErrorArea.AddDimensions, EGASdkErrorAction.JsonError, e.toString(), GAState.getGameKey(), GAState.getSecretKey());
}
}
private static void addCustomFieldsToEvent(JSONObject jSONObject, JSONObject jSONObject2) {
if (jSONObject == null || jSONObject2 == null) {
return;
}
try {
if (jSONObject2.length() > 0) {
jSONObject.put("custom_fields", jSONObject2);
}
} catch (JSONException e) {
GALogger.e("addFieldsToEvent: Error creating json");
e.printStackTrace();
GAHTTPApi.getInstance().sendSdkErrorEvent(EGASdkErrorCategory.Json, EGASdkErrorArea.AddFields, EGASdkErrorAction.JsonError, e.toString(), GAState.getGameKey(), GAState.getSecretKey());
}
}
}