Apk Done v1.0版本的 MD5 值为:44cfb8e1ce639995aa7f0de6a3a6388b
以下内容为反编译后的 OneSignalRestClient.java 源代码,内容仅作参考
package com.onesignal;
import android.net.TrafficStats;
import android.os.Build;
import com.onesignal.OSThrowable;
import com.onesignal.OneSignal;
import com.yandex.metrica.YandexMetricaDefaultValues;
import java.io.IOException;
import java.io.InputStream;
import java.lang.Thread;
import java.net.ConnectException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.Scanner;
import javax.net.ssl.HttpsURLConnection;
import org.json.JSONObject;
public class OneSignalRestClient {
public static abstract class ResponseHandler {
void onFailure(int i, String str, Throwable th) {
}
void onSuccess(String str) {
}
}
private static int getThreadTimeout(int i) {
return i + 5000;
}
public static void put(final String str, final JSONObject jSONObject, final ResponseHandler responseHandler) {
new Thread(new Runnable() {
@Override
public void run() {
OneSignalRestClient.makeRequest(str, "PUT", jSONObject, responseHandler, 120000, null);
}
}, "OS_REST_ASYNC_PUT").start();
}
public static void post(final String str, final JSONObject jSONObject, final ResponseHandler responseHandler) {
new Thread(new Runnable() {
@Override
public void run() {
OneSignalRestClient.makeRequest(str, "POST", jSONObject, responseHandler, 120000, null);
}
}, "OS_REST_ASYNC_POST").start();
}
public static void get(final String str, final ResponseHandler responseHandler, final String str2) {
new Thread(new Runnable() {
@Override
public void run() {
OneSignalRestClient.makeRequest(str, null, null, responseHandler, 60000, str2);
}
}, "OS_REST_ASYNC_GET").start();
}
public static void getSync(String str, ResponseHandler responseHandler, String str2) {
makeRequest(str, null, null, responseHandler, 60000, str2);
}
public static void putSync(String str, JSONObject jSONObject, ResponseHandler responseHandler) {
makeRequest(str, "PUT", jSONObject, responseHandler, 120000, null);
}
public static void postSync(String str, JSONObject jSONObject, ResponseHandler responseHandler) {
makeRequest(str, "POST", jSONObject, responseHandler, 120000, null);
}
public static void makeRequest(final String str, final String str2, final JSONObject jSONObject, final ResponseHandler responseHandler, final int i, final String str3) {
if (OSUtils.isRunningOnMainThread()) {
throw new OSThrowable.OSMainThreadException("Method: " + str2 + " was called from the Main Thread!");
} else if (str2 == null || !OneSignal.shouldLogUserPrivacyConsentErrorMessageForMethodName(null)) {
final Thread[] threadArr = new Thread[1];
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
threadArr[0] = OneSignalRestClient.startHTTPConnection(str, str2, jSONObject, responseHandler, i, str3);
}
}, "OS_HTTPConnection");
thread.start();
try {
thread.join(getThreadTimeout(i));
if (thread.getState() != Thread.State.TERMINATED) {
thread.interrupt();
}
if (threadArr[0] != null) {
threadArr[0].join();
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static Thread startHTTPConnection(String str, String str2, JSONObject jSONObject, ResponseHandler responseHandler, int i, String str3) {
HttpURLConnection httpURLConnection;
Thread callResponseHandlerOnFailure;
String next;
String headerField;
if (Build.VERSION.SDK_INT >= 26) {
TrafficStats.setThreadStatsTag(YandexMetricaDefaultValues.DEFAULT_MAX_REPORTS_COUNT_UPPER_BOUND);
}
int i2 = -1;
try {
OneSignal.LOG_LEVEL log_level = OneSignal.LOG_LEVEL.DEBUG;
OneSignal.Log(log_level, "OneSignalRestClient: Making request to: https://api.onesignal.com/" + str);
httpURLConnection = newHttpURLConnection(str);
try {
if (Build.VERSION.SDK_INT < 22 && (httpURLConnection instanceof HttpsURLConnection)) {
HttpsURLConnection httpsURLConnection = (HttpsURLConnection) httpURLConnection;
httpsURLConnection.setSSLSocketFactory(new TLS12SocketFactory(httpsURLConnection.getSSLSocketFactory()));
}
httpURLConnection.setUseCaches(false);
httpURLConnection.setConnectTimeout(i);
httpURLConnection.setReadTimeout(i);
httpURLConnection.setRequestProperty("SDK-Version", "onesignal/android/" + OneSignal.getSdkVersionRaw());
httpURLConnection.setRequestProperty("Accept", "application/vnd.onesignal.v1+json");
if (jSONObject != null) {
httpURLConnection.setDoInput(true);
}
if (str2 != null) {
httpURLConnection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
httpURLConnection.setRequestMethod(str2);
httpURLConnection.setDoOutput(true);
}
if (jSONObject != null) {
String unescapedEUIDString = JSONUtils.toUnescapedEUIDString(jSONObject);
OneSignal.LOG_LEVEL log_level2 = OneSignal.LOG_LEVEL.DEBUG;
OneSignal.Log(log_level2, "OneSignalRestClient: " + str2 + " SEND JSON: " + unescapedEUIDString);
byte[] bytes = unescapedEUIDString.getBytes("UTF-8");
httpURLConnection.setFixedLengthStreamingMode(bytes.length);
httpURLConnection.getOutputStream().write(bytes);
}
if (str3 != null) {
String str4 = OneSignalPrefs.PREFS_ONESIGNAL;
String string = OneSignalPrefs.getString(str4, "PREFS_OS_ETAG_PREFIX_" + str3, null);
if (string != null) {
httpURLConnection.setRequestProperty("if-none-match", string);
OneSignal.LOG_LEVEL log_level3 = OneSignal.LOG_LEVEL.DEBUG;
OneSignal.Log(log_level3, "OneSignalRestClient: Adding header if-none-match: " + string);
}
}
i2 = httpURLConnection.getResponseCode();
try {
OneSignal.LOG_LEVEL log_level4 = OneSignal.LOG_LEVEL.VERBOSE;
OneSignal.Log(log_level4, "OneSignalRestClient: After con.getResponseCode to: https://api.onesignal.com/" + str);
String str5 = "GET";
if (i2 == 200 || i2 == 202) {
OneSignal.LOG_LEVEL log_level5 = OneSignal.LOG_LEVEL.DEBUG;
StringBuilder sb = new StringBuilder();
try {
sb.append("OneSignalRestClient: Successfully finished request to: https://api.onesignal.com/");
sb.append(str);
OneSignal.Log(log_level5, sb.toString());
Scanner scanner = new Scanner(httpURLConnection.getInputStream(), "UTF-8");
next = scanner.useDelimiter("\\A").hasNext() ? scanner.next() : "";
scanner.close();
OneSignal.LOG_LEVEL log_level6 = OneSignal.LOG_LEVEL.DEBUG;
StringBuilder sb2 = new StringBuilder();
sb2.append("OneSignalRestClient: ");
if (str2 != null) {
str5 = str2;
}
sb2.append(str5);
sb2.append(" RECEIVED JSON: ");
sb2.append(next);
OneSignal.Log(log_level6, sb2.toString());
if (str3 != null && (headerField = httpURLConnection.getHeaderField("etag")) != null) {
OneSignal.LOG_LEVEL log_level7 = OneSignal.LOG_LEVEL.DEBUG;
OneSignal.Log(log_level7, "OneSignalRestClient: Response has etag of " + headerField + " so caching the response.");
String str6 = OneSignalPrefs.PREFS_ONESIGNAL;
OneSignalPrefs.saveString(str6, "PREFS_OS_ETAG_PREFIX_" + str3, headerField);
String str7 = OneSignalPrefs.PREFS_ONESIGNAL;
OneSignalPrefs.saveString(str7, "PREFS_OS_HTTP_CACHE_PREFIX_" + str3, next);
}
callResponseHandlerOnFailure = callResponseHandlerOnSuccess(responseHandler, next);
} catch (Throwable th) {
th = th;
i2 = i2;
try {
if (!(th instanceof ConnectException) && !(th instanceof UnknownHostException)) {
OneSignal.LOG_LEVEL log_level8 = OneSignal.LOG_LEVEL.WARN;
OneSignal.Log(log_level8, "OneSignalRestClient: " + str2 + " Error thrown from network stack. ", th);
callResponseHandlerOnFailure = callResponseHandlerOnFailure(responseHandler, i2, null, th);
}
OneSignal.LOG_LEVEL log_level9 = OneSignal.LOG_LEVEL.INFO;
OneSignal.Log(log_level9, "OneSignalRestClient: Could not send last request, device is offline. Throwable: " + th.getClass().getName());
callResponseHandlerOnFailure = callResponseHandlerOnFailure(responseHandler, i2, null, th);
} finally {
if (httpURLConnection != null) {
httpURLConnection.disconnect();
}
}
}
} else if (i2 == 304) {
String str8 = OneSignalPrefs.PREFS_ONESIGNAL;
String string2 = OneSignalPrefs.getString(str8, "PREFS_OS_HTTP_CACHE_PREFIX_" + str3, null);
OneSignal.LOG_LEVEL log_level10 = OneSignal.LOG_LEVEL.DEBUG;
StringBuilder sb3 = new StringBuilder();
sb3.append("OneSignalRestClient: ");
if (str2 != null) {
str5 = str2;
}
sb3.append(str5);
sb3.append(" - Using Cached response due to 304: ");
sb3.append(string2);
OneSignal.Log(log_level10, sb3.toString());
callResponseHandlerOnFailure = callResponseHandlerOnSuccess(responseHandler, string2);
} else {
OneSignal.LOG_LEVEL log_level11 = OneSignal.LOG_LEVEL.DEBUG;
OneSignal.Log(log_level11, "OneSignalRestClient: Failed request to: https://api.onesignal.com/" + str);
InputStream errorStream = httpURLConnection.getErrorStream();
if (errorStream == null) {
errorStream = httpURLConnection.getInputStream();
}
if (errorStream != null) {
Scanner scanner2 = new Scanner(errorStream, "UTF-8");
next = scanner2.useDelimiter("\\A").hasNext() ? scanner2.next() : "";
scanner2.close();
OneSignal.LOG_LEVEL log_level12 = OneSignal.LOG_LEVEL.WARN;
OneSignal.Log(log_level12, "OneSignalRestClient: " + str2 + " RECEIVED JSON: " + next);
} else {
OneSignal.LOG_LEVEL log_level13 = OneSignal.LOG_LEVEL.WARN;
OneSignal.Log(log_level13, "OneSignalRestClient: " + str2 + " HTTP Code: " + i2 + " No response body!");
next = null;
}
callResponseHandlerOnFailure = callResponseHandlerOnFailure(responseHandler, i2, next, null);
}
} catch (Throwable th2) {
th = th2;
}
} catch (Throwable th3) {
th = th3;
}
} catch (Throwable th4) {
th = th4;
httpURLConnection = null;
}
}
private static Thread callResponseHandlerOnSuccess(final ResponseHandler responseHandler, final String str) {
if (responseHandler == null) {
return null;
}
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
ResponseHandler.this.onSuccess(str);
}
}, "OS_REST_SUCCESS_CALLBACK");
thread.start();
return thread;
}
private static Thread callResponseHandlerOnFailure(final ResponseHandler responseHandler, final int i, final String str, final Throwable th) {
if (responseHandler == null) {
return null;
}
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
ResponseHandler.this.onFailure(i, str, th);
}
}, "OS_REST_FAILURE_CALLBACK");
thread.start();
return thread;
}
private static HttpURLConnection newHttpURLConnection(String str) throws IOException {
return (HttpURLConnection) new URL("https://api.onesignal.com/" + str).openConnection();
}
}