正在查看: Moneyman v2.316.0.0 应用的 BaseApi.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Moneyman v2.316.0.0 应用的 BaseApi.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.singular.sdk.internal;
import B.g;
import com.singular.sdk.internal.Constants;
import java.io.IOException;
import java.util.HashMap;
import java.util.InvalidPropertiesFormatException;
import java.util.Iterator;
import java.util.Map;
import org.json.JSONException;
import org.json.JSONObject;
abstract class BaseApi extends SingularMap implements Api {
static final String TIMESTAMP_KEY = "__TIMESTAMP__";
static final String TYPE_KEY = "__TYPE__";
private static final SingularLog logger = SingularLog.getLogger("BaseApi");
protected boolean canUseSdidBeforeStartSessionWasSentWithSdid = false;
public BaseApi(String str, long j) {
put(TYPE_KEY, str);
put(TIMESTAMP_KEY, String.valueOf(j));
}
public static BaseApi from(String str) throws IOException, NullPointerException {
if (str == null) {
throw new NullPointerException("api string cannot be null");
}
Map<String, String> fromString = fromString(str);
String str2 = fromString.get(TYPE_KEY);
String str3 = fromString.get(TIMESTAMP_KEY);
long parseLong = !Utils.isEmptyOrNull(str3) ? Long.parseLong(str3) : -1L;
int andIncrementRetryCountForKey = Utils.getAndIncrementRetryCountForKey(SingularInstance.getInstance().getContext(), str3);
if (andIncrementRetryCountForKey > 3) {
fromString.put(Constants.RETRY_COUNT, String.valueOf(andIncrementRetryCountForKey));
}
if (Constants.API_TYPE_CONFIG.equalsIgnoreCase(str2)) {
ApiConfig apiConfig = new ApiConfig(parseLong);
apiConfig.addParams(fromString);
return apiConfig;
}
if (Constants.API_TYPE_EVENT.equalsIgnoreCase(str2)) {
ApiSubmitEvent apiSubmitEvent = new ApiSubmitEvent(parseLong);
apiSubmitEvent.addParams(fromString);
return apiSubmitEvent;
}
if (Constants.API_TYPE_SESSION_START.equalsIgnoreCase(str2)) {
ApiStartSession apiStartSession = new ApiStartSession(parseLong);
apiStartSession.addParams(fromString);
return apiStartSession;
}
if (Constants.API_TYPE_GDPR_CONSENT.equalsIgnoreCase(str2)) {
ApiGDPRConsent apiGDPRConsent = new ApiGDPRConsent(parseLong);
apiGDPRConsent.addParams(fromString);
return apiGDPRConsent;
}
if (Constants.API_TYPE_GDPR_UNDER_13.equalsIgnoreCase(str2)) {
ApiGDPRUnder13 apiGDPRUnder13 = new ApiGDPRUnder13(parseLong);
apiGDPRUnder13.addParams(fromString);
return apiGDPRUnder13;
}
if (!Constants.API_TYPE_CUSTOM_USER_ID.equalsIgnoreCase(str2)) {
throw new InvalidPropertiesFormatException(g.l("Unknown type = ", str2));
}
ApiCustomUserId apiCustomUserId = new ApiCustomUserId(parseLong);
apiCustomUserId.addParams(fromString);
return apiCustomUserId;
}
private static Map<String, String> fromString(String str) throws IOException {
try {
JSONObject jSONObject = new JSONObject(str);
HashMap hashMap = new HashMap();
Iterator<String> keys = jSONObject.keys();
while (keys.hasNext()) {
String next = keys.next();
hashMap.put(next, (String) jSONObject.get(next));
}
return hashMap;
} catch (JSONException e) {
throw new IOException(e);
}
}
private void tryMigrateEventToSdid(SingularInstance singularInstance) {
try {
if (!getParams().containsKey(Constants.RequestParamsKeys.IDENTIFIER_KEYSPACE_KEY)) {
put(Constants.DID_MIGRATE_EVENT_TO_SDID_DEBUG_PARAM, Constants.SdidMigrationStatusCodes.MISSING_PARAMS);
logger.debug("BaseApi: this api has no 'k' param, skipping migration.");
return;
}
if (DeviceIDManager.getInstance().getActualSdid(ConfigManager.getInstance(), singularInstance.getContext()) == null) {
put(Constants.DID_MIGRATE_EVENT_TO_SDID_DEBUG_PARAM, Constants.SdidMigrationStatusCodes.NO_SDID_MODEL_AVAILABLE_YET);
logger.debug("BaseApi: no SDID model available in device id manager, skipping migration.");
return;
}
if (getParams().get(Constants.RequestParamsKeys.IDENTIFIER_KEYSPACE_KEY).equalsIgnoreCase("sdid")) {
put(Constants.DID_MIGRATE_EVENT_TO_SDID_DEBUG_PARAM, Constants.SdidMigrationStatusCodes.ALREADY_SDID);
logger.debug("BaseApi: not migrated, this api already has k=SDID, skipping migration.");
} else if (!this.canUseSdidBeforeStartSessionWasSentWithSdid && !DeviceIDManager.getInstance().didSendStartSessionWithSdid(singularInstance.getContext())) {
put(Constants.DID_MIGRATE_EVENT_TO_SDID_DEBUG_PARAM, Constants.SdidMigrationStatusCodes.DID_NOT_SEND_START_SESSION_WITH_SDID_YET);
logger.debug("BaseApi: no session sent with SDID yet, skipping migration.");
} else {
putAll(new SingularParamsBase().withDeviceInfo(singularInstance, this.canUseSdidBeforeStartSessionWasSentWithSdid));
put(Constants.DID_MIGRATE_EVENT_TO_SDID_DEBUG_PARAM, Constants.SdidMigrationStatusCodes.SUCCESSFULLY_MIGRATED);
logger.debug("BaseApi: migrated api to k=SDID");
}
} catch (Throwable unused) {
put(Constants.DID_MIGRATE_EVENT_TO_SDID_DEBUG_PARAM, Constants.SdidMigrationStatusCodes.CAUGHT_EXCEPTION);
logger.error("BaseApi: failed to migrate event to SDID");
}
}
public void addParams(Map<String, String> map) {
if (map == null) {
return;
}
putAll(map);
}
public Map<String, String> getParams() {
HashMap hashMap = new HashMap(this);
hashMap.remove(TYPE_KEY);
hashMap.remove(TIMESTAMP_KEY);
return hashMap;
}
public long getTimestamp() {
String str = get(TIMESTAMP_KEY);
if (Utils.isEmptyOrNull(str)) {
return -1L;
}
return Long.parseLong(str);
}
public String getType() {
return get(TYPE_KEY);
}
public String getUrl() {
return "https://sdk-api-v1.singular.net/api/v1" + getPath();
}
public boolean isAdmonEvent() {
try {
String str = get(Constants.RequestBody.EXTRA_ATTRIBUTES_KEY);
if (str != null) {
return new JSONObject(str).getBoolean(Constants.ADMON_IS_ADMON_REVENUE);
}
return false;
} catch (Throwable th2) {
logger.debug("Not an admon event: " + th2.getMessage());
return false;
}
}
public boolean makeRequest(SingularInstance singularInstance) throws IOException {
tryMigrateEventToSdid(singularInstance);
return SingularRequestHandler.makeRequest(singularInstance, getUrl(), getParams(), getTimestamp(), getOnApiCallback());
}
public String toJsonAsString() {
return new JSONObject(this).toString();
}
}