最右.apk(点击下载) / AMSDevReporter.java


package com.alibaba.sdk.android.utils;

import android.content.Context;
import android.net.TrafficStats;
import android.os.Build;
import com.meituan.robust.Constants;
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 org.json.JSONException;
import org.json.JSONObject;

public class AMSDevReporter {
    private static String TAG = "AMSDevReporter";

    /* renamed from: a  reason: collision with root package name */
    private static Context f15796a;

    /* renamed from: a  reason: collision with other field name */
    private static ConcurrentHashMap<AMSSdkTypeEnum, AMSReportStatusEnum> f44a = new ConcurrentHashMap<>();

    /* renamed from: a  reason: collision with other field name */
    private static final ExecutorService f45a = b03.i(new a(), "​com.alibaba.sdk.android.utils.AMSDevReporter");

    /* renamed from: a  reason: collision with other field name */
    private static boolean f46a = false;

    public enum AMSReportStatusEnum {
        UNREPORTED,
        REPORTED
    }

    public enum AMSSdkExtInfoKeyEnum {
        AMS_EXTINFO_KEY_VERSION("SdkVersion"),
        AMS_EXTINFO_KEY_PACKAGE("PackageName");
        
        private String description;

        private AMSSdkExtInfoKeyEnum(String str) {
            this.description = str;
        }

        public String toString() {
            return this.description;
        }
    }

    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;
        }
    }

    static {
        for (AMSSdkTypeEnum aMSSdkTypeEnum : AMSSdkTypeEnum.values()) {
            f44a.put(aMSSdkTypeEnum, AMSReportStatusEnum.UNREPORTED);
        }
    }

    public static void asyncReport(Context context, AMSSdkTypeEnum aMSSdkTypeEnum) {
        asyncReport(context, aMSSdkTypeEnum, null);
    }

    public static AMSReportStatusEnum getReportStatus(AMSSdkTypeEnum aMSSdkTypeEnum) {
        return f44a.get(aMSSdkTypeEnum);
    }

    public static void setLogEnabled(boolean z) {
        d.setLogEnabled(z);
    }

    public static void asyncReport(Context context, final AMSSdkTypeEnum aMSSdkTypeEnum, final Map<String, Object> map) {
        if (context == null) {
            d.c(TAG, "Context is null, return.");
            return;
        }
        f15796a = context;
        String str = TAG;
        d.b(str, "Add [" + aMSSdkTypeEnum.toString() + "] to report queue.");
        f46a = false;
        f45a.execute(new Runnable() {
            /* class com.alibaba.sdk.android.utils.AMSDevReporter.AnonymousClass1 */

            public void run() {
                if (AMSDevReporter.f46a) {
                    d.c(AMSDevReporter.TAG, "Unable to execute remain task in queue, return.");
                    return;
                }
                String str = AMSDevReporter.TAG;
                d.b(str, "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 (f44a.get(aMSSdkTypeEnum) != AMSReportStatusEnum.UNREPORTED) {
            String str = TAG;
            d.b(str, Constants.ARRAY_TYPE + aMSSdkTypeEnum2 + "] already reported, return.");
            return;
        }
        int i = 0;
        int i2 = 5;
        while (true) {
            String str2 = TAG;
            StringBuilder sb = new StringBuilder();
            sb.append("Report [");
            sb.append(aMSSdkTypeEnum2);
            sb.append("], times: [");
            i++;
            sb.append(i);
            sb.append("].");
            d.b(str2, sb.toString());
            if (!m24a(aMSSdkTypeEnum, map)) {
                if (i > 10) {
                    String str3 = TAG;
                    d.c(str3, "Report [" + aMSSdkTypeEnum2 + "] stat failed, exceed max retry times, return.");
                    f44a.put(aMSSdkTypeEnum, AMSReportStatusEnum.UNREPORTED);
                    f46a = true;
                    break;
                }
                String str4 = TAG;
                d.b(str4, "Report [" + aMSSdkTypeEnum2 + "] failed, wait for [" + i2 + "] seconds.");
                e.a((double) i2);
                i2 *= 2;
                if (i2 >= 60) {
                    i2 = 60;
                }
            } else {
                String str5 = TAG;
                d.b(str5, "Report [" + aMSSdkTypeEnum2 + "] stat success.");
                f44a.put(aMSSdkTypeEnum, AMSReportStatusEnum.REPORTED);
                break;
            }
        }
        if (f46a) {
            String str6 = TAG;
            d.c(str6, "Report [" + aMSSdkTypeEnum2 + "] failed, clear remain report in queue.");
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:62:0x01bd  */
    /* JADX WARNING: Removed duplicated region for block: B:64:0x01c2  */
    /* JADX WARNING: Removed duplicated region for block: B:67:0x01ca  */
    /* JADX WARNING: Removed duplicated region for block: B:72:0x01d7  */
    /* JADX WARNING: Removed duplicated region for block: B:74:0x01dc A[SYNTHETIC, Splitter:B:74:0x01dc] */
    /* JADX WARNING: Removed duplicated region for block: B:79:0x01e4 A[Catch:{ IOException -> 0x01e0 }] */
    /* renamed from: a  reason: collision with other method in class */
    private static boolean m24a(AMSSdkTypeEnum aMSSdkTypeEnum, Map<String, Object> map) {
        DataInputStream dataInputStream;
        Throwable th;
        OutputStream outputStream;
        Exception e;
        HttpURLConnection httpURLConnection = null;
        DataInputStream dataInputStream2 = null;
        httpURLConnection = null;
        try {
            if (Build.VERSION.SDK_INT >= 14) {
                TrafficStats.setThreadStatsTag(40965);
            }
            String utdid = UTDevice.getUtdid(f15796a);
            d.b(TAG, "stat: " + utdid);
            String a2 = a(aMSSdkTypeEnum, utdid, map);
            String str = "23356390Raw" + e.a(a2);
            String b2 = e.b("16594f72217bece5a457b4803a48f2da" + e.a(str) + "16594f72217bece5a457b4803a48f2da");
            StringBuilder sb = new StringBuilder();
            sb.append("https://adash.man.aliyuncs.com/man/api?ak=23356390&s=");
            sb.append(b2);
            HttpURLConnection httpURLConnection2 = (HttpURLConnection) new URL(sb.toString()).openConnection();
            try {
                httpURLConnection2.setDoOutput(true);
                httpURLConnection2.setUseCaches(false);
                httpURLConnection2.setConnectTimeout(15000);
                String str2 = "===" + System.currentTimeMillis() + "===";
                httpURLConnection2.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 = httpURLConnection2.getOutputStream();
                try {
                    outputStream.write(str3.getBytes());
                    int responseCode = httpURLConnection2.getResponseCode();
                    if (responseCode == 200) {
                        DataInputStream dataInputStream3 = new DataInputStream(httpURLConnection2.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));
                            }
                            d.a(TAG, "Get MAN response: " + sb2.toString());
                            try {
                                if (((String) new JSONObject(sb2.toString()).get("success")).equals("success")) {
                                    if (httpURLConnection2 != null) {
                                        httpURLConnection2.disconnect();
                                    }
                                    if (outputStream != null) {
                                        try {
                                            outputStream.close();
                                        } catch (IOException e2) {
                                            d.a(TAG, e2);
                                        }
                                    }
                                    dataInputStream3.close();
                                    return true;
                                }
                            } catch (JSONException e3) {
                                d.a(TAG, e3);
                            }
                            dataInputStream2 = dataInputStream3;
                        } catch (Exception e4) {
                            httpURLConnection = httpURLConnection2;
                            dataInputStream = dataInputStream3;
                            e = e4;
                            try {
                                d.a(TAG, e);
                                if (httpURLConnection != null) {
                                }
                                if (outputStream != null) {
                                }
                                if (dataInputStream != null) {
                                }
                                return false;
                            } catch (Throwable th2) {
                                th = th2;
                                if (httpURLConnection != null) {
                                    httpURLConnection.disconnect();
                                }
                                if (outputStream != null) {
                                    try {
                                        outputStream.close();
                                    } catch (IOException e5) {
                                        d.a(TAG, e5);
                                        throw th;
                                    }
                                }
                                if (dataInputStream != null) {
                                    dataInputStream.close();
                                }
                                throw th;
                            }
                        } catch (Throwable th3) {
                            httpURLConnection = httpURLConnection2;
                            dataInputStream = dataInputStream3;
                            th = th3;
                            if (httpURLConnection != null) {
                            }
                            if (outputStream != null) {
                            }
                            if (dataInputStream != null) {
                            }
                            throw th;
                        }
                    } else {
                        d.c(TAG, "MAN API error, response code: " + responseCode);
                    }
                    if (httpURLConnection2 != null) {
                        httpURLConnection2.disconnect();
                    }
                    if (outputStream != null) {
                        try {
                            outputStream.close();
                        } catch (IOException e6) {
                            d.a(TAG, e6);
                        }
                    }
                    if (dataInputStream2 != null) {
                        dataInputStream2.close();
                    }
                } catch (Exception e7) {
                    e = e7;
                    httpURLConnection = httpURLConnection2;
                    dataInputStream = null;
                    d.a(TAG, e);
                    if (httpURLConnection != null) {
                    }
                    if (outputStream != null) {
                    }
                    if (dataInputStream != null) {
                    }
                    return false;
                } catch (Throwable th4) {
                    th = th4;
                    httpURLConnection = httpURLConnection2;
                    dataInputStream = null;
                    if (httpURLConnection != null) {
                    }
                    if (outputStream != null) {
                    }
                    if (dataInputStream != null) {
                    }
                    throw th;
                }
            } catch (Exception e8) {
                e = e8;
                outputStream = null;
                httpURLConnection = httpURLConnection2;
                dataInputStream = null;
                d.a(TAG, e);
                if (httpURLConnection != null) {
                    httpURLConnection.disconnect();
                }
                if (outputStream != null) {
                    outputStream.close();
                }
                if (dataInputStream != null) {
                    dataInputStream.close();
                }
                return false;
            } catch (Throwable th5) {
                th = th5;
                outputStream = null;
                httpURLConnection = httpURLConnection2;
                dataInputStream = null;
                if (httpURLConnection != null) {
                }
                if (outputStream != null) {
                }
                if (dataInputStream != null) {
                }
                throw th;
            }
        } catch (Exception e9) {
            e = e9;
            dataInputStream = null;
            outputStream = null;
            d.a(TAG, e);
            if (httpURLConnection != null) {
            }
            if (outputStream != null) {
            }
            if (dataInputStream != null) {
            }
            return false;
        } catch (Throwable th6) {
            th = th6;
            dataInputStream = null;
            outputStream = null;
            if (httpURLConnection != null) {
            }
            if (outputStream != 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 (!e.m29a(str2)) {
                sb.append("-");
                sb.append(str2);
            }
            String str3 = (String) map.get(AMSSdkExtInfoKeyEnum.AMS_EXTINFO_KEY_PACKAGE.toString());
            if (!e.m29a(str3)) {
                sb.append("-");
                sb.append(str3);
            }
        }
        return sb.toString();
    }
}