- 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
195 lines
7.9 KiB
Java
195 lines
7.9 KiB
Java
package com.singular.sdk.internal;
|
|
|
|
import com.google.firebase.perf.network.FirebasePerfUrlConnection;
|
|
import com.ironsource.nb;
|
|
import com.ironsource.v8;
|
|
import com.singular.sdk.internal.Api;
|
|
import com.unity3d.ads.metadata.InAppPurchaseMetaData;
|
|
import java.io.BufferedReader;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.InputStreamReader;
|
|
import java.io.OutputStreamWriter;
|
|
import java.net.HttpURLConnection;
|
|
import java.net.URL;
|
|
import java.net.URLConnection;
|
|
import java.net.URLEncoder;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.TreeMap;
|
|
import java.util.zip.GZIPInputStream;
|
|
import javax.net.ssl.HttpsURLConnection;
|
|
import org.json.JSONException;
|
|
import org.json.JSONObject;
|
|
|
|
/* loaded from: classes4.dex */
|
|
public abstract class SingularRequestHandler {
|
|
public static final SingularLog logger = SingularLog.getLogger(SingularRequestHandler.class.getSimpleName());
|
|
public static int counter = 0;
|
|
public static final String[] POST_PAYLOAD_PARAMS_KEYS = {"e", "global_properties"};
|
|
|
|
public static boolean makeRequest(SingularInstance singularInstance, String str, Map map, long j, Api.OnApiCallback onApiCallback) {
|
|
long currentTimeMillis = Utils.getCurrentTimeMillis();
|
|
int i = counter + 1;
|
|
counter = i;
|
|
SingularLog singularLog = logger;
|
|
singularLog.debug("---------------------------> /%d", Integer.valueOf(i));
|
|
singularLog.debug("url = %s", str);
|
|
singularLog.debug("params = %s", map);
|
|
HttpURLConnection buildRequest = buildRequest(singularInstance, str, map, j);
|
|
try {
|
|
try {
|
|
return sendRequest(singularInstance, onApiCallback, currentTimeMillis, i, buildRequest);
|
|
} catch (IOException e) {
|
|
throw e;
|
|
}
|
|
} finally {
|
|
if (buildRequest != null) {
|
|
buildRequest.disconnect();
|
|
}
|
|
}
|
|
}
|
|
|
|
public static HttpURLConnection buildRequest(SingularInstance singularInstance, String str, Map map, long j) {
|
|
HttpURLConnection httpConnection;
|
|
Map postPayloadParams = getPostPayloadParams(map);
|
|
String str2 = str + "?" + appendHash(getQueryString(singularInstance, map, j), singularInstance.getSingularConfig().secret);
|
|
URL url = new URL(str2);
|
|
if (url.getProtocol().equalsIgnoreCase("https")) {
|
|
httpConnection = getHttpsConnection(url);
|
|
} else {
|
|
httpConnection = getHttpConnection(url);
|
|
}
|
|
setDefaultConnectionProperties(httpConnection);
|
|
setPayloadForRequest(httpConnection, postPayloadParams, singularInstance.getSingularConfig().secret);
|
|
logger.debug("__API__ %s %s", httpConnection.getRequestMethod(), str2);
|
|
return httpConnection;
|
|
}
|
|
|
|
public static boolean sendRequest(SingularInstance singularInstance, Api.OnApiCallback onApiCallback, long j, int i, HttpURLConnection httpURLConnection) {
|
|
httpURLConnection.connect();
|
|
int responseCode = httpURLConnection.getResponseCode();
|
|
String readResponse = readResponse(httpURLConnection);
|
|
httpURLConnection.disconnect();
|
|
long currentTimeMillis = Utils.getCurrentTimeMillis() - j;
|
|
SingularLog singularLog = logger;
|
|
singularLog.debug("%d %s", Integer.valueOf(responseCode), readResponse);
|
|
singularLog.debug("<--------------------------- /%d - took %dms", Integer.valueOf(i), Long.valueOf(currentTimeMillis));
|
|
return onApiCallback.handle(singularInstance, responseCode, readResponse);
|
|
}
|
|
|
|
public static String readResponse(HttpURLConnection httpURLConnection) {
|
|
InputStreamReader inputStreamReader;
|
|
StringBuffer stringBuffer = new StringBuffer();
|
|
InputStream inputStream = httpURLConnection.getInputStream();
|
|
if (httpURLConnection.getContentEncoding() != null && httpURLConnection.getContentEncoding().equals("gzip")) {
|
|
inputStreamReader = new InputStreamReader(new GZIPInputStream(inputStream));
|
|
} else {
|
|
inputStreamReader = new InputStreamReader(inputStream);
|
|
}
|
|
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
|
|
while (true) {
|
|
String readLine = bufferedReader.readLine();
|
|
if (readLine != null) {
|
|
stringBuffer.append(readLine);
|
|
} else {
|
|
return stringBuffer.toString();
|
|
}
|
|
}
|
|
}
|
|
|
|
public static Map getPostPayloadParams(Map map) {
|
|
HashMap hashMap = new HashMap();
|
|
for (String str : POST_PAYLOAD_PARAMS_KEYS) {
|
|
if (map.containsKey(str)) {
|
|
hashMap.put(str, map.get(str));
|
|
map.remove(str);
|
|
}
|
|
}
|
|
return hashMap;
|
|
}
|
|
|
|
public static void setPayloadForRequest(HttpURLConnection httpURLConnection, Map map, String str) {
|
|
if (httpURLConnection == null) {
|
|
return;
|
|
}
|
|
try {
|
|
JSONObject jSONObject = new JSONObject();
|
|
if (map != null && map.size() > 0) {
|
|
String jSONObject2 = new JSONObject(map).toString();
|
|
String sha1Hash = Utils.sha1Hash(jSONObject2, str);
|
|
jSONObject.put("payload", jSONObject2);
|
|
jSONObject.put(InAppPurchaseMetaData.KEY_SIGNATURE, sha1Hash);
|
|
}
|
|
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(httpURLConnection.getOutputStream(), "UTF-8");
|
|
outputStreamWriter.write(jSONObject.toString());
|
|
outputStreamWriter.close();
|
|
} catch (IOException e) {
|
|
e = e;
|
|
e.printStackTrace();
|
|
} catch (JSONException e2) {
|
|
e = e2;
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
public static void setDefaultConnectionProperties(HttpURLConnection httpURLConnection) {
|
|
httpURLConnection.setConnectTimeout(10000);
|
|
httpURLConnection.setReadTimeout(10000);
|
|
httpURLConnection.setRequestMethod("POST");
|
|
httpURLConnection.setDoInput(true);
|
|
httpURLConnection.setUseCaches(false);
|
|
httpURLConnection.setRequestProperty("User-Agent", Constants.HTTP_USER_AGENT);
|
|
httpURLConnection.setRequestProperty("Content-Type", nb.L);
|
|
}
|
|
|
|
public static String getQueryString(SingularInstance singularInstance, Map map, long j) {
|
|
StringBuilder sb = new StringBuilder();
|
|
if (map == null) {
|
|
map = new HashMap();
|
|
}
|
|
TreeMap treeMap = new TreeMap(map);
|
|
treeMap.put("rt", "json");
|
|
treeMap.put("lag", String.valueOf(Utils.lagSince(j)));
|
|
treeMap.put("c", Utils.getConnectionType(singularInstance.getContext()));
|
|
for (Map.Entry entry : treeMap.entrySet()) {
|
|
String encode = URLEncoder.encode((String) entry.getKey(), "UTF-8");
|
|
String str = (String) entry.getValue();
|
|
String encode2 = str != null ? URLEncoder.encode(str, "UTF-8") : "";
|
|
if (sb.length() > 0) {
|
|
sb.append(v8.i.c);
|
|
}
|
|
sb.append(encode);
|
|
sb.append(v8.i.b);
|
|
sb.append(encode2);
|
|
}
|
|
return sb.toString();
|
|
}
|
|
|
|
public static String appendHash(String str, String str2) {
|
|
if (str == null) {
|
|
return "";
|
|
}
|
|
String sha1Hash = Utils.sha1Hash(String.format("?%s", str), str2);
|
|
logger.debug("hash = %s", sha1Hash);
|
|
if (Utils.isEmptyOrNull(sha1Hash)) {
|
|
return str;
|
|
}
|
|
return str + "&h=" + sha1Hash;
|
|
}
|
|
|
|
public static HttpURLConnection getHttpConnection(URL url) {
|
|
if (url != null) {
|
|
return (HttpURLConnection) ((URLConnection) FirebasePerfUrlConnection.instrument(url.openConnection()));
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static HttpURLConnection getHttpsConnection(URL url) {
|
|
if (url == null) {
|
|
return null;
|
|
}
|
|
return (HttpsURLConnection) ((URLConnection) FirebasePerfUrlConnection.instrument(url.openConnection()));
|
|
}
|
|
}
|