嘿嘿连载.apk(点击下载) / b.java


package cn.jiguang.aa;

import android.content.Context;
import android.os.Build;
import android.text.TextUtils;
import android.util.Base64;
import cn.jiguang.ai.a;
import cn.jiguang.f.f;
import cn.jiguang.f.h;
import cn.jiguang.net.DefaultHostVerifier;
import cn.jiguang.net.HttpUtils;
import cn.jiguang.net.SSLTrustManager;
import com.liulishuo.filedownloader.services.FileDownloadBroadcastHandler;
import com.meizu.cloud.pushsdk.constants.PushConstants;
import com.xiaomi.mipush.sdk.Constants;
import com.yanzhenjie.kalle.Headers;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.security.MessageDigest;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public final class b {

    /* renamed from: a  reason: collision with root package name */
    public static String f2525a = "";

    private static String a(byte[] bArr) {
        try {
            byte[] digest = MessageDigest.getInstance("MD5").digest(bArr);
            StringBuilder sb = new StringBuilder();
            for (byte b : digest) {
                int i = b & 255;
                if (i < 16) {
                    sb.append(PushConstants.PUSH_TYPE_NOTIFY);
                }
                sb.append(Integer.toHexString(i));
            }
            return sb.toString();
        } catch (Throwable th) {
            a.g("JWakeConfigHelper", "get md5 throwable:" + th.getMessage());
            return "";
        }
    }

    private static List<String> a(JSONObject jSONObject, String str) {
        JSONArray optJSONArray = jSONObject.optJSONArray(str);
        if (optJSONArray == null) {
            return null;
        }
        ArrayList arrayList = new ArrayList();
        for (int i = 0; i < optJSONArray.length(); i++) {
            arrayList.add(optJSONArray.get(i).toString());
        }
        return arrayList;
    }

    /* JADX WARNING: Code restructure failed: missing block: B:109:0x029b, code lost:
        if (r6 == null) goto L_0x030b;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:118:0x02d1, code lost:
        if (r6 == null) goto L_0x030b;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:127:0x0306, code lost:
        if (r6 == null) goto L_0x030b;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:128:0x0308, code lost:
        r6.disconnect();
     */
    /* JADX WARNING: Removed duplicated region for block: B:105:0x0282 A[SYNTHETIC, Splitter:B:105:0x0282] */
    /* JADX WARNING: Removed duplicated region for block: B:114:0x02b8 A[SYNTHETIC, Splitter:B:114:0x02b8] */
    /* JADX WARNING: Removed duplicated region for block: B:123:0x02ed A[SYNTHETIC, Splitter:B:123:0x02ed] */
    /* JADX WARNING: Removed duplicated region for block: B:133:0x0311 A[SYNTHETIC, Splitter:B:133:0x0311] */
    /* JADX WARNING: Removed duplicated region for block: B:138:0x032c  */
    public static JSONObject a(Context context) {
        HttpURLConnection httpURLConnection;
        Throwable th;
        InputStream inputStream;
        UnsupportedEncodingException unsupportedEncodingException;
        IOException iOException;
        JSONException jSONException;
        UnsupportedEncodingException e;
        IOException e2;
        JSONException e3;
        Throwable th2;
        String str;
        InputStream inputStream2 = null;
        try {
            if (!cn.jiguang.sdk.impl.b.h(context)) {
                a.g("JWakeConfigHelper", "request wakeConfig failed because is not validRegistered");
                return null;
            }
            String i = cn.jiguang.sdk.impl.b.i(context);
            if (TextUtils.isEmpty(i)) {
                a.g("JWakeConfigHelper", "request wakeConfig failed because can't get appKey");
                return null;
            }
            long e4 = cn.jiguang.sdk.impl.b.e(context);
            if (e4 == 0) {
                a.g("JWakeConfigHelper", "request wakeConfig failed because can't get uid");
                return null;
            }
            String f = cn.jiguang.sdk.impl.b.f(context);
            if (TextUtils.isEmpty(f)) {
                a.g("JWakeConfigHelper", "request wakeConfig failed because need register first");
                return null;
            }
            String str2 = "https://bjuser.jpush.cn/v1/appawake/status";
            if (h.b && !TextUtils.isEmpty(f2525a)) {
                a.c("JWakeConfigHelper", "use test url:" + f2525a);
                str2 = f2525a;
            }
            HashMap hashMap = new HashMap();
            HashMap hashMap2 = new HashMap();
            String str3 = Build.MANUFACTURER;
            String str4 = Build.MODEL;
            hashMap2.put("appkey", i);
            hashMap2.put("uid", String.valueOf(e4));
            if (!TextUtils.isEmpty(str3)) {
                hashMap2.put("manufacturer", str3);
            }
            if (!TextUtils.isEmpty(str4)) {
                hashMap2.put(FileDownloadBroadcastHandler.KEY_MODEL, str4);
            }
            String urlWithValueEncodeParas = HttpUtils.getUrlWithValueEncodeParas(str2, hashMap2);
            a.c("JWakeConfigHelper", "url:" + urlWithValueEncodeParas);
            hashMap.put("Content-Type", "text/plain");
            hashMap.put("Accept", Headers.VALUE_APPLICATION_JSON);
            hashMap.put("X-Http-Platform", "android");
            hashMap.put("X-Http-Appkey", i);
            String a2 = a("".getBytes("UTF-8"));
            String e5 = cn.jiguang.ap.h.e(e4 + cn.jiguang.ap.h.e(f) + a2);
            if (TextUtils.isEmpty(e5)) {
                return null;
            }
            String encodeToString = Base64.encodeToString((e4 + Constants.COLON_SEPARATOR + e5).getBytes(), 10);
            if (TextUtils.isEmpty(encodeToString)) {
                return null;
            }
            hashMap.put("Authorization", "Basic " + encodeToString);
            hashMap.put("Charset", "UTF-8");
            HttpURLConnection httpURLConnectionWithProxy = HttpUtils.getHttpURLConnectionWithProxy(context, urlWithValueEncodeParas);
            try {
                httpURLConnectionWithProxy.setConnectTimeout(30000);
                httpURLConnectionWithProxy.setReadTimeout(30000);
                for (Map.Entry entry : hashMap.entrySet()) {
                    httpURLConnectionWithProxy.setRequestProperty((String) entry.getKey(), (String) entry.getValue());
                }
                if (httpURLConnectionWithProxy instanceof HttpsURLConnection) {
                    try {
                        SSLContext instance = SSLContext.getInstance("TLS");
                        instance.init(null, new TrustManager[]{new SSLTrustManager("-----BEGIN CERTIFICATE-----\nMIIETzCCAzegAwIBAgIDAjpvMA0GCSqGSIb3DQEBCwUAMEIxCzAJBgNVBAYTAlVT\nMRYwFAYDVQQKEw1HZW9UcnVzdCBJbmMuMRswGQYDVQQDExJHZW9UcnVzdCBHbG9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q\nn2JTHAJ8mJCi7k9o1CAacxI+d7NQ63K87oi+fxfqd4+DYZVPhKHLMk9sIb7SaZZ9\nY73cK6gf0BOEcP72NZWJ+aZ3sEbIu7cT9clgadZM/tKO79NgwYCA4ef7i28heUrg\n3Kkbwbf7w0lZXLV3B0TUl/xJAIlvBk4BcBmsLxHA4uYPL4ZLjXvDuacu9PGsFj45\nSVGeF0tPEDpbpaiSb/361gsDTUdWVxnzy2v189bPsPX1oxHSIFMTNDcFLENaY9+N\nQNaFHlHpURceA1bJ8TCt55sRornQMYGbaLHZ6PPmlH7HrhMvh+3QJbBo+d4IWvMp\nzNSS\n-----END CERTIFICATE-----")}, new SecureRandom());
                        ((HttpsURLConnection) httpURLConnectionWithProxy).setSSLSocketFactory(instance.getSocketFactory());
                        ((HttpsURLConnection) httpURLConnectionWithProxy).setHostnameVerifier(new DefaultHostVerifier(httpURLConnectionWithProxy.getURL().getHost()));
                    } catch (Throwable th3) {
                        a.g("JWakeConfigHelper", "set ssl config error:" + th3.getMessage());
                    }
                }
                if (httpURLConnectionWithProxy.getResponseCode() == 200) {
                    inputStream = httpURLConnectionWithProxy.getInputStream();
                    try {
                        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                        byte[] bArr = new byte[1024];
                        while (true) {
                            int read = inputStream.read(bArr);
                            if (read == -1) {
                                break;
                            }
                            byteArrayOutputStream.write(bArr, 0, read);
                        }
                        str = new String(byteArrayOutputStream.toByteArray());
                    } catch (UnsupportedEncodingException e6) {
                        e = e6;
                        httpURLConnection = httpURLConnectionWithProxy;
                        unsupportedEncodingException = e;
                        a.g("JWakeConfigHelper", "request wakeConfig exception:" + unsupportedEncodingException.getMessage());
                        if (inputStream != null) {
                        }
                    } catch (IOException e7) {
                        e2 = e7;
                        httpURLConnection = httpURLConnectionWithProxy;
                        iOException = e2;
                        a.g("JWakeConfigHelper", "request wakeConfig exception:" + iOException.getMessage());
                        if (inputStream != null) {
                        }
                    } catch (JSONException e8) {
                        e3 = e8;
                        httpURLConnection = httpURLConnectionWithProxy;
                        jSONException = e3;
                        try {
                            a.g("JWakeConfigHelper", "request wakeConfig exception:" + jSONException.getMessage());
                            if (inputStream != null) {
                            }
                        } catch (Throwable th4) {
                            th = th4;
                            inputStream2 = inputStream;
                            if (inputStream2 != null) {
                            }
                            if (httpURLConnection != null) {
                            }
                            throw th;
                        }
                    } catch (Throwable th5) {
                        th2 = th5;
                        httpURLConnection = httpURLConnectionWithProxy;
                        inputStream2 = inputStream;
                        th = th2;
                        if (inputStream2 != null) {
                        }
                        if (httpURLConnection != null) {
                        }
                        throw th;
                    }
                } else {
                    inputStream = null;
                    str = null;
                }
                if (!TextUtils.isEmpty(str)) {
                    a.c("JWakeConfigHelper", "request wakeConfig success,response body:" + str);
                    JSONObject jSONObject = new JSONObject(str);
                    if (inputStream != null) {
                        try {
                            inputStream.close();
                        } catch (Exception e9) {
                            a.g("JWakeConfigHelper", "request wakeConfig exception:" + e9.getMessage());
                        }
                    }
                    if (httpURLConnectionWithProxy != null) {
                        httpURLConnectionWithProxy.disconnect();
                    }
                    return jSONObject;
                }
                if (inputStream != null) {
                    try {
                        inputStream.close();
                    } catch (Exception e10) {
                        a.g("JWakeConfigHelper", "request wakeConfig exception:" + e10.getMessage());
                    }
                }
                if (httpURLConnectionWithProxy != null) {
                    httpURLConnectionWithProxy.disconnect();
                }
                return null;
            } catch (UnsupportedEncodingException e11) {
                e = e11;
                httpURLConnection = httpURLConnectionWithProxy;
                inputStream = null;
                unsupportedEncodingException = e;
                a.g("JWakeConfigHelper", "request wakeConfig exception:" + unsupportedEncodingException.getMessage());
                if (inputStream != null) {
                    try {
                        inputStream.close();
                    } catch (Exception e12) {
                        a.g("JWakeConfigHelper", "request wakeConfig exception:" + e12.getMessage());
                    }
                }
            } catch (IOException e13) {
                e2 = e13;
                httpURLConnection = httpURLConnectionWithProxy;
                inputStream = null;
                iOException = e2;
                a.g("JWakeConfigHelper", "request wakeConfig exception:" + iOException.getMessage());
                if (inputStream != null) {
                    try {
                        inputStream.close();
                    } catch (Exception e14) {
                        a.g("JWakeConfigHelper", "request wakeConfig exception:" + e14.getMessage());
                    }
                }
            } catch (JSONException e15) {
                e3 = e15;
                httpURLConnection = httpURLConnectionWithProxy;
                inputStream = null;
                jSONException = e3;
                a.g("JWakeConfigHelper", "request wakeConfig exception:" + jSONException.getMessage());
                if (inputStream != null) {
                    try {
                        inputStream.close();
                    } catch (Exception e16) {
                        a.g("JWakeConfigHelper", "request wakeConfig exception:" + e16.getMessage());
                    }
                }
            } catch (Throwable th6) {
                th2 = th6;
                httpURLConnection = httpURLConnectionWithProxy;
                th = th2;
                if (inputStream2 != null) {
                    try {
                        inputStream2.close();
                    } catch (Exception e17) {
                        a.g("JWakeConfigHelper", "request wakeConfig exception:" + e17.getMessage());
                    }
                }
                if (httpURLConnection != null) {
                    httpURLConnection.disconnect();
                }
                throw th;
            }
        } catch (UnsupportedEncodingException e18) {
            unsupportedEncodingException = e18;
            inputStream = null;
            httpURLConnection = null;
            a.g("JWakeConfigHelper", "request wakeConfig exception:" + unsupportedEncodingException.getMessage());
            if (inputStream != null) {
            }
        } catch (IOException e19) {
            iOException = e19;
            inputStream = null;
            httpURLConnection = null;
            a.g("JWakeConfigHelper", "request wakeConfig exception:" + iOException.getMessage());
            if (inputStream != null) {
            }
        } catch (JSONException e20) {
            jSONException = e20;
            inputStream = null;
            httpURLConnection = null;
            a.g("JWakeConfigHelper", "request wakeConfig exception:" + jSONException.getMessage());
            if (inputStream != null) {
            }
        } catch (Throwable th7) {
            th = th7;
            httpURLConnection = null;
            if (inputStream2 != null) {
            }
            if (httpURLConnection != null) {
            }
            throw th;
        }
    }

    public static void a(Context context, JSONObject jSONObject) {
        if (jSONObject != null) {
            a.c("JWakeConfigHelper", "write wakeConfigJson:" + jSONObject);
            cn.jiguang.s.b.a(context, "bwc.catch", jSONObject);
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:31:0x0081 A[Catch:{ JSONException -> 0x00c9 }] */
    /* JADX WARNING: Removed duplicated region for block: B:37:0x0095 A[Catch:{ JSONException -> 0x00c9 }] */
    /* JADX WARNING: Removed duplicated region for block: B:38:0x0097 A[Catch:{ JSONException -> 0x00c9 }] */
    /* JADX WARNING: Removed duplicated region for block: B:41:0x00a6 A[Catch:{ JSONException -> 0x00c9 }] */
    /* JADX WARNING: Removed duplicated region for block: B:44:0x00b5 A[Catch:{ JSONException -> 0x00c9 }] */
    public static cn.jiguang.z.a b(Context context, JSONObject jSONObject) {
        int optInt;
        String optString;
        cn.jiguang.z.a aVar = new cn.jiguang.z.a();
        if (jSONObject == null) {
            return aVar;
        }
        try {
            int optInt2 = jSONObject.optInt("app_wakeup_stat", -1);
            if (optInt2 < 0) {
                return aVar;
            }
            int optInt3 = jSONObject.optInt("app_report_app_list_threshold", -1);
            if (optInt3 > 0) {
                f.b(context, "JAppAll", (long) (optInt3 * 1000));
            }
            int optInt4 = jSONObject.optInt("app_wakeup_threshold", -1) * 1000;
            if (optInt4 > 0) {
                aVar.e = (long) optInt4;
            }
            int optInt5 = jSONObject.optInt("app_get_threshold", -1) * 1000;
            if (optInt5 > 0) {
                aVar.f = (long) optInt5;
            }
            int optInt6 = jSONObject.optInt("app_report_threshold", -1) * 1000;
            if (optInt6 > 0) {
                aVar.g = (long) optInt6;
            }
            boolean z = false;
            if (optInt2 != 0) {
                if (optInt2 != 1) {
                    if (optInt2 == 2) {
                        aVar.c = false;
                    } else {
                        String optString2 = jSONObject.optString("errmsg");
                        a.g("JWakeConfigHelper", "parseWakeConfigJson error: " + optString2);
                    }
                    optInt = jSONObject.optInt("app_wakeup_disable", -1);
                    if (optInt != 0) {
                        if (optInt == 1) {
                            aVar.d = false;
                        } else if (optInt == 2) {
                        }
                        aVar.f2707a = !"disable".equals(jSONObject.optString("app_wakeup_config", "enable"));
                        if (!"disable".equals(jSONObject.optString("app_wakeuped_config", "enable"))) {
                            z = true;
                        }
                        aVar.b = z;
                        optString = jSONObject.optString("app_package_config", "disable");
                        if (optString.isEmpty()) {
                            optString = "disable";
                        }
                        aVar.h = optString;
                        aVar.i = a(jSONObject, "app_package_list");
                        aVar.j = a(jSONObject, "app_blacklist");
                        return aVar;
                    }
                    aVar.d = true;
                    aVar.f2707a = !"disable".equals(jSONObject.optString("app_wakeup_config", "enable"));
                    if (!"disable".equals(jSONObject.optString("app_wakeuped_config", "enable"))) {
                    }
                    aVar.b = z;
                    optString = jSONObject.optString("app_package_config", "disable");
                    if (optString.isEmpty()) {
                    }
                    aVar.h = optString;
                    aVar.i = a(jSONObject, "app_package_list");
                    aVar.j = a(jSONObject, "app_blacklist");
                    return aVar;
                }
            }
            aVar.c = true;
            optInt = jSONObject.optInt("app_wakeup_disable", -1);
            if (optInt != 0) {
            }
            aVar.d = true;
            aVar.f2707a = !"disable".equals(jSONObject.optString("app_wakeup_config", "enable"));
            if (!"disable".equals(jSONObject.optString("app_wakeuped_config", "enable"))) {
            }
            aVar.b = z;
            optString = jSONObject.optString("app_package_config", "disable");
            if (optString.isEmpty()) {
            }
            aVar.h = optString;
            aVar.i = a(jSONObject, "app_package_list");
            aVar.j = a(jSONObject, "app_blacklist");
            return aVar;
        } catch (JSONException e) {
            a.g("JWakeConfigHelper", "parseWakeConfig exception:" + e.toString());
        }
    }
}