package com.aliyun.clientinforeport.core; import com.aliyun.clientinforeport.AlivcEventPublicParam; import com.aliyun.clientinforeport.util.RLog; import com.mbridge.msdk.playercommon.exoplayer2.C; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import java.util.Map; import org.json.JSONObject; public class LogSender { public static final String KEY_APPLICATION_ID = "app_id"; public static final String KEY_APPLICATION_NAME = "app_n"; public static final String KEY_APPLICATION_VERSION = "app_v"; public static final String KEY_APP_VERSION = "av"; public static final String KEY_ARGS = "args"; public static final String KEY_BUSINESS_ID = "bi"; public static final String KEY_CDN_IP = "cdn_ip"; public static final String KEY_CONNECTION = "co"; public static final String KEY_DEVICE_BRAND = "db"; public static final String KEY_DEVICE_MANUFACTURER = "dma"; public static final String KEY_DEVICE_MODEL = "dm"; public static final String KEY_EVENT = "e"; public static final String KEY_HOSTNAME = "hn"; public static final String KEY_LOG_LEVEL = "ll"; public static final String KEY_LOG_VERSION = "lv"; public static final String KEY_MODULE = "md"; public static final String KEY_OPERATION_SYSTEM = "os"; public static final String KEY_OSVERSION = "ov"; public static final String KEY_PRODUCT = "pd"; public static final String KEY_REFER = "r"; public static final String KEY_REQUEST_ID = "ri"; public static final String KEY_SUB_MODULE = "sm"; public static final String KEY_TERMINAL_TYPE = "tt"; public static final String KEY_TIME = "t"; public static final String KEY_TRACE_ID = "ti"; public static final String KEY_USER_AGENT = "uat"; public static final String KEY_UUID = "uuid"; public static final String KEY_VIDEO_TYPE = "vt"; public static final String KEY_VIDEO_URL = "vu"; private static final String TAG = "LogSender"; private static String logPushUrl = "http://videocloud.cn-hangzhou.log.aliyuncs.com/logstores/"; private static boolean sendEnable = true; private static String trackVersion = "/track?APIVersion=0.6.0"; /* JADX WARNING: Can't wrap try/catch for region: R(8:17|(2:19|20)|21|22|23|24|(1:27)|28) */ /* JADX WARNING: Can't wrap try/catch for region: R(8:29|(2:31|32)|33|34|35|36|(1:39)|40) */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Missing exception handler attribute for start block: B:21:0x0047 */ /* JADX WARNING: Missing exception handler attribute for start block: B:23:0x004a */ /* JADX WARNING: Missing exception handler attribute for start block: B:33:0x0071 */ /* JADX WARNING: Missing exception handler attribute for start block: B:35:0x0074 */ /* JADX WARNING: Removed duplicated region for block: B:27:0x0051 */ /* JADX WARNING: Removed duplicated region for block: B:39:0x007b */ /* JADX WARNING: Removed duplicated region for block: B:61:0x00b5 A[SYNTHETIC, Splitter:B:61:0x00b5] */ /* JADX WARNING: Removed duplicated region for block: B:65:0x00bc A[SYNTHETIC, Splitter:B:65:0x00bc] */ /* JADX WARNING: Removed duplicated region for block: B:69:0x00c3 A[SYNTHETIC, Splitter:B:69:0x00c3] */ /* JADX WARNING: Removed duplicated region for block: B:73:0x00ca */ /* JADX WARNING: Removed duplicated region for block: B:77:0x00d1 A[SYNTHETIC, Splitter:B:77:0x00d1] */ /* JADX WARNING: Removed duplicated region for block: B:81:0x00d8 A[SYNTHETIC, Splitter:B:81:0x00d8] */ /* JADX WARNING: Removed duplicated region for block: B:85:0x00df A[SYNTHETIC, Splitter:B:85:0x00df] */ /* JADX WARNING: Removed duplicated region for block: B:89:0x00e6 */ private static String doHttpGet(String str) { HttpURLConnection httpURLConnection; BufferedReader bufferedReader; InputStreamReader inputStreamReader; InputStream inputStream; Throwable th; Exception e2; try { httpURLConnection = (HttpURLConnection) new URL(str).openConnection(); try { httpURLConnection.setRequestMethod("GET"); httpURLConnection.setConnectTimeout(10000); httpURLConnection.setReadTimeout(10000); inputStream = httpURLConnection.getInputStream(); try { inputStreamReader = new InputStreamReader(inputStream); } catch (Exception e3) { bufferedReader = null; e2 = e3; inputStreamReader = null; try { String message = e2.getMessage(); if (inputStream != null) { } if (inputStreamReader != null) { } if (bufferedReader != null) { } if (httpURLConnection != null) { } return message; } catch (Throwable th2) { th = th2; if (inputStream != null) { try { inputStream.close(); } catch (IOException unused) { } } if (inputStreamReader != null) { try { inputStreamReader.close(); } catch (IOException unused2) { } } if (bufferedReader != null) { try { bufferedReader.close(); } catch (IOException unused3) { } } if (httpURLConnection != null) { httpURLConnection.disconnect(); } throw th; } } catch (Throwable th3) { bufferedReader = null; th = th3; inputStreamReader = null; if (inputStream != null) { } if (inputStreamReader != null) { } if (bufferedReader != null) { } if (httpURLConnection != null) { } throw th; } } catch (Exception e4) { inputStreamReader = null; bufferedReader = null; e2 = e4; inputStream = null; String message2 = e2.getMessage(); if (inputStream != null) { } if (inputStreamReader != null) { } if (bufferedReader != null) { } if (httpURLConnection != null) { } return message2; } catch (Throwable th4) { inputStreamReader = null; bufferedReader = null; th = th4; inputStream = null; if (inputStream != null) { } if (inputStreamReader != null) { } if (bufferedReader != null) { } if (httpURLConnection != null) { } throw th; } try { bufferedReader = new BufferedReader(inputStreamReader); try { StringBuilder sb = new StringBuilder(); while (true) { String readLine = bufferedReader.readLine(); if (readLine == null) { break; } sb.append(readLine); } int responseCode = httpURLConnection.getResponseCode(); if (responseCode == 200) { String sb2 = sb.toString(); if (inputStream != null) { inputStream.close(); } inputStreamReader.close(); bufferedReader.close(); if (httpURLConnection != null) { httpURLConnection.disconnect(); } return sb2; } JSONObject jSONObject = new JSONObject(); jSONObject.put("StatusCode", responseCode); jSONObject.put("ResponseStr", sb.toString()); String jSONObject2 = jSONObject.toString(); if (inputStream != null) { inputStream.close(); } inputStreamReader.close(); bufferedReader.close(); if (httpURLConnection != null) { httpURLConnection.disconnect(); } return jSONObject2; } catch (Exception e5) { e2 = e5; String message22 = e2.getMessage(); if (inputStream != null) { try { inputStream.close(); } catch (IOException unused4) { } } if (inputStreamReader != null) { try { inputStreamReader.close(); } catch (IOException unused5) { } } if (bufferedReader != null) { try { bufferedReader.close(); } catch (IOException unused6) { } } if (httpURLConnection != null) { httpURLConnection.disconnect(); } return message22; } } catch (Exception e6) { bufferedReader = null; e2 = e6; String message222 = e2.getMessage(); if (inputStream != null) { } if (inputStreamReader != null) { } if (bufferedReader != null) { } if (httpURLConnection != null) { } return message222; } catch (Throwable th5) { bufferedReader = null; th = th5; if (inputStream != null) { } if (inputStreamReader != null) { } if (bufferedReader != null) { } if (httpURLConnection != null) { } throw th; } } catch (Exception e7) { inputStream = null; inputStreamReader = null; bufferedReader = null; e2 = e7; httpURLConnection = null; String message2222 = e2.getMessage(); if (inputStream != null) { } if (inputStreamReader != null) { } if (bufferedReader != null) { } if (httpURLConnection != null) { } return message2222; } catch (Throwable th6) { inputStream = null; inputStreamReader = null; bufferedReader = null; th = th6; httpURLConnection = null; if (inputStream != null) { } if (inputStreamReader != null) { } if (bufferedReader != null) { } if (httpURLConnection != null) { } throw th; } } private static String formatEventArgs(Map<String, String> map) { if (map != null && map.size() > 0) { StringBuilder sb = new StringBuilder(); for (Map.Entry<String, String> entry : map.entrySet()) { sb.append(entry.getKey()); sb.append("="); sb.append(entry.getValue()); sb.append("&"); } sb.deleteCharAt(sb.lastIndexOf("&")); try { return URLEncoder.encode(sb.toString(), C.UTF8_NAME); } catch (UnsupportedEncodingException e2) { RLog.e(TAG, e2.toString()); } } return ""; } private static String formatFinalUrl(String str, AlivcEventPublicParam alivcEventPublicParam, int i2, String str2) { StringBuilder sb = new StringBuilder(str); sb.append("&"); sb.append("t"); sb.append("="); sb.append(alivcEventPublicParam.getTime()); sb.append("&"); sb.append(KEY_LOG_LEVEL); sb.append("="); sb.append(alivcEventPublicParam.getLogLevel()); sb.append("&"); sb.append(KEY_LOG_VERSION); sb.append("="); sb.append(alivcEventPublicParam.getLogVersion()); sb.append("&"); sb.append(KEY_PRODUCT); sb.append("="); sb.append(alivcEventPublicParam.getProduct()); sb.append("&"); sb.append(KEY_MODULE); sb.append("="); sb.append(alivcEventPublicParam.getModule()); sb.append("&"); sb.append(KEY_SUB_MODULE); sb.append("="); sb.append(alivcEventPublicParam.getSubModule()); sb.append("&"); sb.append(KEY_TRACE_ID); sb.append("="); sb.append(alivcEventPublicParam.getTraceId()); sb.append("&"); sb.append(KEY_HOSTNAME); sb.append("="); sb.append(alivcEventPublicParam.getHostName()); sb.append("&"); sb.append(KEY_BUSINESS_ID); sb.append("="); sb.append(alivcEventPublicParam.getBusinessId()); sb.append("&"); sb.append(KEY_REQUEST_ID); sb.append("="); sb.append(alivcEventPublicParam.getRequestId()); sb.append("&"); sb.append("e"); sb.append("="); sb.append(i2); sb.append("&"); sb.append(KEY_ARGS); sb.append("="); sb.append(str2); sb.append("&"); sb.append(KEY_VIDEO_TYPE); sb.append("="); sb.append(alivcEventPublicParam.getVideoType()); sb.append("&"); sb.append("tt"); sb.append("="); sb.append(alivcEventPublicParam.getTerminalType()); sb.append("&"); sb.append("dm"); sb.append("="); sb.append(alivcEventPublicParam.getDeviceModel()); sb.append("&"); sb.append(KEY_DEVICE_BRAND); sb.append("="); sb.append(alivcEventPublicParam.getDeviceBrand()); sb.append("&"); sb.append(KEY_DEVICE_MANUFACTURER); sb.append("="); sb.append(alivcEventPublicParam.getDeviceManufacture()); sb.append("&"); sb.append(KEY_OPERATION_SYSTEM); sb.append("="); sb.append(alivcEventPublicParam.getOperationSystem()); sb.append("&"); sb.append(KEY_OSVERSION); sb.append("="); sb.append(alivcEventPublicParam.getOsVersion()); sb.append("&"); sb.append(KEY_APP_VERSION); sb.append("="); sb.append(alivcEventPublicParam.getAppVersion()); sb.append("&"); sb.append(KEY_UUID); sb.append("="); sb.append(alivcEventPublicParam.getUuid()); sb.append("&"); sb.append(KEY_VIDEO_URL); sb.append("="); sb.append(alivcEventPublicParam.getVideoUrl()); sb.append("&"); sb.append(KEY_CONNECTION); sb.append("="); sb.append(alivcEventPublicParam.getConnection()); sb.append("&"); sb.append(KEY_USER_AGENT); sb.append("="); sb.append(alivcEventPublicParam.getUserAgent()); sb.append("&"); sb.append("app_id"); sb.append("="); sb.append(alivcEventPublicParam.getApplicationId()); sb.append("&"); sb.append(KEY_APPLICATION_NAME); sb.append("="); sb.append(alivcEventPublicParam.getApplicationName()); sb.append("&"); sb.append(KEY_APPLICATION_VERSION); sb.append("="); sb.append(alivcEventPublicParam.getApplicationVersion()); sb.append("&"); sb.append(KEY_CDN_IP); sb.append("="); sb.append(alivcEventPublicParam.getCdnIp()); sb.append("&"); sb.append("r"); sb.append("="); sb.append(alivcEventPublicParam.getReferer()); sb.append("&"); sb.deleteCharAt(sb.lastIndexOf("&")); return sb.toString(); } public static void sendActually(AlivcEventPublicParam alivcEventPublicParam, int i2, Map<String, String> map) { if (!sendEnable) { RLog.d(TAG, "sendEnable : " + sendEnable); } else if (alivcEventPublicParam != null) { PublicParamChecker.checkParam(alivcEventPublicParam, i2); String formatFinalUrl = formatFinalUrl(logPushUrl + alivcEventPublicParam.getLogStore() + trackVersion, alivcEventPublicParam, i2, formatEventArgs(map)); StringBuilder sb = new StringBuilder(); sb.append("logFinalUrl "); sb.append(formatFinalUrl); RLog.d(TAG, sb.toString()); RLog.d(TAG, "requestId = " + alivcEventPublicParam.getRequestId()); try { String doHttpGet = doHttpGet(formatFinalUrl); RLog.i(TAG, "onResponse " + doHttpGet); } catch (Exception e2) { RLog.e(TAG, e2.getMessage()); } } else { throw new IllegalAccessError("report log's publicparam can NOT be null!"); } } public static void setEnable(boolean z) { sendEnable = z; } }