package com.alibaba.sdk.android.utils; import android.content.Context; import android.net.TrafficStats; import android.os.Build; import com.umeng.message.proguard.l; import com.ut.device.UTDevice; import java.io.DataInputStream; import java.io.IOException; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import org.json.JSONException; import org.json.JSONObject; public class AMSDevReporter { /* renamed from: a reason: collision with root package name */ private static Context f3049a; /* renamed from: a reason: collision with other field name */ private static c f12a = new c("AMSDevReporter"); /* renamed from: a reason: collision with other field name */ private static ConcurrentHashMap<AMSSdkTypeEnum, AMSReportStatusEnum> f13a = new ConcurrentHashMap<>(); /* renamed from: a reason: collision with other field name */ private static final ExecutorService f14a = Executors.newSingleThreadExecutor(new a()); /* renamed from: a reason: collision with other field name */ private static boolean f15a = false; public enum AMSReportStatusEnum { UNREPORTED, REPORTED } public enum AMSSdkTypeEnum { AMS_MAN("MAN"), AMS_HTTPDNS("HTTPDNS"), AMS_MPUSH("MPUSH"), AMS_MAC("MAC"), AMS_API("API"), AMS_HOTFIX("HOTFIX"), AMS_FEEDBACK("FEEDBACK"), AMS_IM("IM"); private String description; private AMSSdkTypeEnum(String str) { this.description = str; } public String toString() { return this.description; } } public enum AMSSdkExtInfoKeyEnum { AMS_EXTINFO_KEY_VERSION(l.j), AMS_EXTINFO_KEY_PACKAGE("PackageName"); private String description; private AMSSdkExtInfoKeyEnum(String str) { this.description = str; } public String toString() { return this.description; } } static { for (AMSSdkTypeEnum aMSSdkTypeEnum : AMSSdkTypeEnum.values()) { f13a.put(aMSSdkTypeEnum, AMSReportStatusEnum.UNREPORTED); } } public static void setLogEnabled(boolean z) { f12a.setLogEnabled(z); } public static AMSReportStatusEnum getReportStatus(AMSSdkTypeEnum aMSSdkTypeEnum) { return f13a.get(aMSSdkTypeEnum); } public static void asyncReport(Context context, AMSSdkTypeEnum aMSSdkTypeEnum) { asyncReport(context, aMSSdkTypeEnum, null); } public static void asyncReport(Context context, final AMSSdkTypeEnum aMSSdkTypeEnum, final Map<String, Object> map) { if (context == null) { f12a.c("Context is null, return."); return; } f3049a = context; c cVar = f12a; cVar.b("Add [" + aMSSdkTypeEnum.toString() + "] to report queue."); f15a = false; f14a.execute(new Runnable() { /* class com.alibaba.sdk.android.utils.AMSDevReporter.AnonymousClass1 */ public void run() { if (AMSDevReporter.f15a) { AMSDevReporter.f12a.c("Unable to execute remain task in queue, return."); return; } c cVar = AMSDevReporter.f12a; cVar.b("Get [" + aMSSdkTypeEnum.toString() + "] from report queue."); AMSDevReporter.a(aMSSdkTypeEnum, map); } }); } /* access modifiers changed from: private */ public static void a(AMSSdkTypeEnum aMSSdkTypeEnum, Map<String, Object> map) { String aMSSdkTypeEnum2 = aMSSdkTypeEnum.toString(); if (f13a.get(aMSSdkTypeEnum) != AMSReportStatusEnum.UNREPORTED) { c cVar = f12a; cVar.b("[" + aMSSdkTypeEnum2 + "] already reported, return."); return; } int i = 0; int i2 = 5; while (true) { c cVar2 = f12a; StringBuilder sb = new StringBuilder(); sb.append("Report ["); sb.append(aMSSdkTypeEnum2); sb.append("], times: ["); i++; sb.append(i); sb.append("]."); cVar2.b(sb.toString()); if (!m55a(aMSSdkTypeEnum, map)) { if (i > 10) { c cVar3 = f12a; cVar3.c("Report [" + aMSSdkTypeEnum2 + "] stat failed, exceed max retry times, return."); f13a.put(aMSSdkTypeEnum, AMSReportStatusEnum.UNREPORTED); f15a = true; break; } c cVar4 = f12a; cVar4.b("Report [" + aMSSdkTypeEnum2 + "] failed, wait for [" + i2 + "] seconds."); d.a((double) i2); i2 *= 2; if (i2 >= 60) { i2 = 60; } } else { c cVar5 = f12a; cVar5.b("Report [" + aMSSdkTypeEnum2 + "] stat success."); f13a.put(aMSSdkTypeEnum, AMSReportStatusEnum.REPORTED); break; } } if (f15a) { c cVar6 = f12a; cVar6.c("Report [" + aMSSdkTypeEnum2 + "] failed, clear remain report in queue."); } } /* JADX WARNING: Removed duplicated region for block: B:61:0x01ba */ /* JADX WARNING: Removed duplicated region for block: B:63:0x01bf */ /* JADX WARNING: Removed duplicated region for block: B:66:0x01c7 */ /* JADX WARNING: Removed duplicated region for block: B:73:0x01d7 */ /* JADX WARNING: Removed duplicated region for block: B:75:0x01dc A[SYNTHETIC, Splitter:B:75:0x01dc] */ /* JADX WARNING: Removed duplicated region for block: B:80:0x01e4 A[Catch:{ IOException -> 0x01e0 }] */ /* renamed from: a reason: collision with other method in class */ private static boolean m55a(AMSSdkTypeEnum aMSSdkTypeEnum, Map<String, Object> map) { HttpURLConnection httpURLConnection; Throwable th; DataInputStream dataInputStream; OutputStream outputStream; DataInputStream dataInputStream2; Exception e; DataInputStream dataInputStream3; HttpURLConnection httpURLConnection2 = null; r4 = null; OutputStream outputStream2 = null; try { if (Build.VERSION.SDK_INT >= 14) { TrafficStats.setThreadStatsTag(40965); } String utdid = UTDevice.getUtdid(f3049a); f12a.b("stat: " + utdid); String a2 = a(aMSSdkTypeEnum, utdid, map); String str = "23356390Raw" + d.a(a2); String b2 = d.b("16594f72217bece5a457b4803a48f2da" + d.a(str) + "16594f72217bece5a457b4803a48f2da"); StringBuilder sb = new StringBuilder(); sb.append("http://adash.man.aliyuncs.com:80/man/api?ak=23356390&s="); sb.append(b2); httpURLConnection = (HttpURLConnection) new URL(sb.toString()).openConnection(); try { httpURLConnection.setDoOutput(true); httpURLConnection.setUseCaches(false); httpURLConnection.setConnectTimeout(15000); String str2 = "===" + System.currentTimeMillis() + "==="; httpURLConnection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + str2); String str3 = "--" + str2 + "\r\nContent-Disposition: form-data; name=\"" + "Raw" + "\"\r\nContent-Type: text/plain; charset=UTF-8\r\n\r\n" + a2 + "\r\n--" + str2 + "--\r\n"; outputStream = httpURLConnection.getOutputStream(); try { outputStream.write(str3.getBytes()); int responseCode = httpURLConnection.getResponseCode(); if (responseCode == 200) { dataInputStream3 = new DataInputStream(httpURLConnection.getInputStream()); try { StringBuilder sb2 = new StringBuilder(); byte[] bArr = new byte[1024]; while (true) { int read = dataInputStream3.read(bArr); if (read == -1) { break; } sb2.append(new String(bArr, 0, read)); } f12a.a("Get MAN response: " + sb2.toString()); try { if (((String) new JSONObject(sb2.toString()).get("success")).equals("success")) { if (httpURLConnection != null) { httpURLConnection.disconnect(); } if (outputStream != null) { try { outputStream.close(); } catch (IOException e2) { f12a.a(e2); } } dataInputStream3.close(); return true; } } catch (JSONException e3) { f12a.a(e3); } } catch (Exception e4) { httpURLConnection2 = httpURLConnection; dataInputStream2 = dataInputStream3; e = e4; try { f12a.a(e); if (httpURLConnection2 != null) { httpURLConnection2.disconnect(); } if (outputStream != null) { outputStream.close(); } if (dataInputStream2 != null) { dataInputStream2.close(); } return false; } catch (Throwable th2) { th = th2; dataInputStream = dataInputStream2; httpURLConnection = httpURLConnection2; outputStream2 = outputStream; if (httpURLConnection != null) { httpURLConnection.disconnect(); } if (outputStream2 != null) { try { outputStream2.close(); } catch (IOException e5) { f12a.a(e5); throw th; } } if (dataInputStream != null) { dataInputStream.close(); } throw th; } } catch (Throwable th3) { outputStream2 = outputStream; dataInputStream = dataInputStream3; th = th3; if (httpURLConnection != null) { } if (outputStream2 != null) { } if (dataInputStream != null) { } throw th; } } else { f12a.c("MAN API error, response code: " + responseCode); dataInputStream3 = null; } if (httpURLConnection != null) { httpURLConnection.disconnect(); } if (outputStream != null) { try { outputStream.close(); } catch (IOException e6) { f12a.a(e6); } } if (dataInputStream3 != null) { dataInputStream3.close(); } } catch (Exception e7) { e = e7; httpURLConnection2 = httpURLConnection; dataInputStream2 = null; f12a.a(e); if (httpURLConnection2 != null) { } if (outputStream != null) { } if (dataInputStream2 != null) { } return false; } catch (Throwable th4) { th = th4; dataInputStream = null; outputStream2 = outputStream; if (httpURLConnection != null) { } if (outputStream2 != null) { } if (dataInputStream != null) { } throw th; } } catch (Exception e8) { e = e8; outputStream = null; httpURLConnection2 = httpURLConnection; dataInputStream2 = null; f12a.a(e); if (httpURLConnection2 != null) { } if (outputStream != null) { } if (dataInputStream2 != null) { } return false; } catch (Throwable th5) { th = th5; dataInputStream = null; if (httpURLConnection != null) { } if (outputStream2 != null) { } if (dataInputStream != null) { } throw th; } } catch (Exception e9) { e = e9; dataInputStream2 = null; outputStream = null; f12a.a(e); if (httpURLConnection2 != null) { } if (outputStream != null) { } if (dataInputStream2 != null) { } return false; } catch (Throwable th6) { th = th6; httpURLConnection = null; dataInputStream = null; if (httpURLConnection != null) { } if (outputStream2 != null) { } if (dataInputStream != null) { } throw th; } return false; } private static String a(AMSSdkTypeEnum aMSSdkTypeEnum, String str, Map<String, Object> map) { StringBuilder sb = new StringBuilder(); sb.append(aMSSdkTypeEnum); sb.append("-"); sb.append(str); if (map != null) { String str2 = (String) map.get(AMSSdkExtInfoKeyEnum.AMS_EXTINFO_KEY_VERSION.toString()); if (!d.m56a(str2)) { sb.append("-"); sb.append(str2); } String str3 = (String) map.get(AMSSdkExtInfoKeyEnum.AMS_EXTINFO_KEY_PACKAGE.toString()); if (!d.m56a(str3)) { sb.append("-"); sb.append(str3); } } return sb.toString(); } }