package cn.jiguang.ai; import android.content.Context; import android.os.Build; import android.text.TextUtils; import android.util.Base64; import cn.jiguang.ad.a; import cn.jiguang.f.i; import cn.jiguang.net.DefaultHostVerifier; import cn.jiguang.net.HttpUtils; import cn.jiguang.net.SSLTrustManager; import cn.jiguang.o.f; import cn.jiguang.o.h; import cn.jiguang.v.d; import com.facebook.stetho.common.Utf8Charset; import com.facebook.stetho.server.http.HttpHeaders; 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 f802a = ""; 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("0"); } sb.append(Integer.toHexString(i)); } return sb.toString(); } catch (Throwable th) { a.d("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:110:0x02c9, code lost: if (r2 == null) goto L_0x0381; */ /* JADX WARNING: Code restructure failed: missing block: B:119:0x0305, code lost: if (r2 == null) goto L_0x0381; */ /* JADX WARNING: Code restructure failed: missing block: B:128:0x0341, code lost: if (r2 == null) goto L_0x0381; */ /* JADX WARNING: Code restructure failed: missing block: B:137:0x037c, code lost: if (r2 == null) goto L_0x0381; */ /* JADX WARNING: Code restructure failed: missing block: B:138:0x037e, code lost: r2.disconnect(); */ /* JADX WARNING: Code restructure failed: missing block: B:48:0x01ab, code lost: r1 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:49:0x01ac, code lost: cn.jiguang.ad.a.d("JWakeConfigHelper", "set ssl config error:" + r1.getMessage()); */ /* JADX WARNING: Code restructure failed: missing block: B:88:0x0272, code lost: r1 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:89:0x0273, code lost: r2 = r13; r13 = r1; */ /* JADX WARNING: Code restructure failed: missing block: B:92:0x027c, code lost: r1 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:93:0x027d, code lost: r2 = r13; r13 = r1; r1 = null; */ /* JADX WARNING: Code restructure failed: missing block: B:94:0x0281, code lost: r1 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:95:0x0282, code lost: r2 = r13; r13 = r1; r1 = null; */ /* JADX WARNING: Code restructure failed: missing block: B:96:0x0287, code lost: r1 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:97:0x0288, code lost: r2 = r13; r13 = r1; r1 = null; */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Removed duplicated region for block: B:106:0x02ad A[SYNTHETIC, Splitter:B:106:0x02ad] */ /* JADX WARNING: Removed duplicated region for block: B:115:0x02e9 A[SYNTHETIC, Splitter:B:115:0x02e9] */ /* JADX WARNING: Removed duplicated region for block: B:124:0x0325 A[SYNTHETIC, Splitter:B:124:0x0325] */ /* JADX WARNING: Removed duplicated region for block: B:133:0x0360 A[SYNTHETIC, Splitter:B:133:0x0360] */ /* JADX WARNING: Removed duplicated region for block: B:143:0x0386 A[SYNTHETIC, Splitter:B:143:0x0386] */ /* JADX WARNING: Removed duplicated region for block: B:148:0x03a4 */ /* JADX WARNING: Removed duplicated region for block: B:88:0x0272 A[ExcHandler: all (r1v35 'th' java.lang.Throwable A[CUSTOM_DECLARE]), Splitter:B:37:0x0144] */ /* JADX WARNING: Removed duplicated region for block: B:92:0x027c A[ExcHandler: JSONException (r1v31 'e' org.json.JSONException A[CUSTOM_DECLARE]), Splitter:B:37:0x0144] */ /* JADX WARNING: Removed duplicated region for block: B:94:0x0281 A[ExcHandler: IOException (r1v29 'e' java.io.IOException A[CUSTOM_DECLARE]), Splitter:B:37:0x0144] */ /* JADX WARNING: Removed duplicated region for block: B:96:0x0287 A[ExcHandler: UnsupportedEncodingException (r1v27 'e' java.io.UnsupportedEncodingException A[CUSTOM_DECLARE]), Splitter:B:37:0x0144] */ public static JSONObject a(Context context) { Throwable th; HttpURLConnection httpURLConnection; InputStream inputStream; UnsupportedEncodingException e; IOException e2; JSONException e3; Throwable th2; String str; InputStream inputStream2 = null; try { if (!cn.jiguang.d.b.a(context)) { a.d("JWakeConfigHelper", "request wakeConfig failed because is not validRegistered"); return null; } String a2 = cn.jiguang.am.a.a(context); if (TextUtils.isEmpty(a2)) { a.d("JWakeConfigHelper", "request wakeConfig failed because can't get appKey"); return null; } long d = cn.jiguang.d.a.d(context); if (d == 0) { a.d("JWakeConfigHelper", "request wakeConfig failed because can't get uid"); return null; } String f = cn.jiguang.d.a.f(context); if (TextUtils.isEmpty(f)) { a.d("JWakeConfigHelper", "request wakeConfig failed because need register first"); return null; } f.c(context, "JWakeConfigHelper"); String str2 = "https://bjuser.jpush.cn/v1/appawake/status"; if (h.f958a && !TextUtils.isEmpty(f802a)) { a.a("JWakeConfigHelper", "use test url:" + f802a); str2 = f802a; } HashMap hashMap = new HashMap(); HashMap hashMap2 = new HashMap(); String str3 = Build.MANUFACTURER; String str4 = Build.MODEL; hashMap2.put("appkey", a2); hashMap2.put("uid", String.valueOf(d)); if (!TextUtils.isEmpty(str3)) { hashMap2.put("manufacturer", str3); } if (!TextUtils.isEmpty(str4)) { hashMap2.put("model", str4); } String a3 = HttpUtils.a(str2, hashMap2); a.a("JWakeConfigHelper", "url:" + a3); hashMap.put(HttpHeaders.CONTENT_TYPE, "text/plain"); hashMap.put("Accept", "application/json"); hashMap.put("X-Http-Platform", "android"); hashMap.put("X-Http-Appkey", a2); String a4 = a("".getBytes(Utf8Charset.NAME)); String e4 = i.e(d + i.e(f) + a4); if (TextUtils.isEmpty(e4)) { return null; } String encodeToString = Base64.encodeToString((d + ":" + e4).getBytes(), 10); if (TextUtils.isEmpty(encodeToString)) { return null; } hashMap.put("Authorization", "Basic " + encodeToString); hashMap.put("Charset", Utf8Charset.NAME); HttpURLConnection b = HttpUtils.b(context, a3); try { b.setConnectTimeout(30000); b.setReadTimeout(30000); for (Map.Entry entry : hashMap.entrySet()) { b.setRequestProperty((String) entry.getKey(), (String) entry.getValue()); } if (b instanceof HttpsURLConnection) { SSLContext instance = SSLContext.getInstance("TLS"); instance.init(null, new TrustManager[]{new SSLTrustManager("-----BEGIN CERTIFICATE-----\nMIIETzCCAzegAwIBAgIDAjpvMA0GCSqGSIb3DQEBCwUAMEIxCzAJBgNVBAYTAlVT\nMRYwFAYDVQQKEw1HZW9UcnVzdCBJbmMuMRswGQYDVQQDExJHZW9UcnVzdCBHbG9i\nYWwgQ0EwHhcNMTMxMTA1MjEzNjUwWhcNMjIwNTIwMjEzNjUwWjBEMQswCQYDVQQG\nEwJVUzEWMBQGA1UEChMNR2VvVHJ1c3QgSW5jLjEdMBsGA1UEAxMUR2VvVHJ1c3Qg\nU1NMIENBIC0gRzMwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDjvn4K\nhqPPa209K6GXrUkkTdd3uTR5CKWeop7eRxKSPX7qGYax6E89X/fQp3eaWx8KA7UZ\nU9ulIZRpY51qTJEMEEe+EfpshiW3qwRoQjgJZfAU2hme+msLq2LvjafvY3AjqK+B\n89FuiGdT7BKkKXWKp/JXPaKDmJfyCn3U50NuMHhiIllZuHEnRaoPZsZVP/oyFysx\nj0ag+mkUfJ2fWuLrM04QprPtd2PYw5703d95mnrU7t7dmszDt6ldzBE6B7tvl6QB\nI0eVH6N3+liSxsfQvc+TGEK3fveeZerVO8rtrMVwof7UEJrwEgRErBpbeFBFV0xv\nvYDLgVwts7x2oR5lAgMBAAGjggFKMIIBRjAfBgNVHSMEGDAWgBTAephojYn7qwVk\nDBF9qn1luMrMTjAdBgNVHQ4EFgQU0m/3lvSFP3I8MH0j2oV4m6N8WnwwEgYDVR0T\nAQH/BAgwBgEB/wIBADAOBgNVHQ8BAf8EBAMCAQYwNgYDVR0fBC8wLTAroCmgJ4Yl\naHR0cDovL2cxLnN5bWNiLmNvbS9jcmxzL2d0Z2xvYmFsLmNybDAvBggrBgEFBQcB\nAQQjMCEwHwYIKwYBBQUHMAGGE2h0dHA6Ly9nMi5zeW1jYi5jb20wTAYDVR0gBEUw\nQzBBBgpghkgBhvhFAQc2MDMwMQYIKwYBBQUHAgEWJWh0dHA6Ly93d3cuZ2VvdHJ1\nc3QuY29tL3Jlc291cmNlcy9jcHMwKQYDVR0RBCIwIKQeMBwxGjAYBgNVBAMTEVN5\nbWFudGVjUEtJLTEtNTM5MA0GCSqGSIb3DQEBCwUAA4IBAQCg1Pcs+3QLf2TxzUNq\nn2JTHAJ8mJCi7k9o1CAacxI+d7NQ63K87oi+fxfqd4+DYZVPhKHLMk9sIb7SaZZ9\nY73cK6gf0BOEcP72NZWJ+aZ3sEbIu7cT9clgadZM/tKO79NgwYCA4ef7i28heUrg\n3Kkbwbf7w0lZXLV3B0TUl/xJAIlvBk4BcBmsLxHA4uYPL4ZLjXvDuacu9PGsFj45\nSVGeF0tPEDpbpaiSb/361gsDTUdWVxnzy2v189bPsPX1oxHSIFMTNDcFLENaY9+N\nQNaFHlHpURceA1bJ8TCt55sRornQMYGbaLHZ6PPmlH7HrhMvh+3QJbBo+d4IWvMp\nzNSS\n-----END CERTIFICATE-----")}, new SecureRandom()); ((HttpsURLConnection) b).setSSLSocketFactory(instance.getSocketFactory()); ((HttpsURLConnection) b).setHostnameVerifier(new DefaultHostVerifier(b.getURL().getHost())); } if (b.getResponseCode() == 200) { inputStream = b.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 e5) { httpURLConnection = b; e = e5; a.d("JWakeConfigHelper", "request wakeConfig exception:" + e.getMessage()); if (inputStream != null) { try { inputStream.close(); } catch (Exception e6) { a.d("JWakeConfigHelper", "request wakeConfig exception:" + e6.getMessage()); } } } catch (IOException e7) { httpURLConnection = b; e2 = e7; a.d("JWakeConfigHelper", "request wakeConfig exception:" + e2.getMessage()); if (inputStream != null) { try { inputStream.close(); } catch (Exception e8) { a.d("JWakeConfigHelper", "request wakeConfig exception:" + e8.getMessage()); } } } catch (JSONException e9) { httpURLConnection = b; e3 = e9; a.d("JWakeConfigHelper", "request wakeConfig exception:" + e3.getMessage()); if (inputStream != null) { try { inputStream.close(); } catch (Exception e10) { a.d("JWakeConfigHelper", "request wakeConfig exception:" + e10.getMessage()); } } } catch (Throwable th3) { httpURLConnection = b; th = th3; inputStream2 = inputStream; if (inputStream2 != null) { } if (httpURLConnection != null) { } throw th; } } else { inputStream = null; str = null; } if (!TextUtils.isEmpty(str)) { a.a("JWakeConfigHelper", "request wakeConfig success,response body:" + str); JSONObject jSONObject = new JSONObject(str); if (inputStream != null) { try { inputStream.close(); } catch (Exception e11) { a.d("JWakeConfigHelper", "request wakeConfig exception:" + e11.getMessage()); } } if (b != null) { b.disconnect(); } return jSONObject; } if (inputStream != null) { try { inputStream.close(); } catch (Exception e12) { a.d("JWakeConfigHelper", "request wakeConfig exception:" + e12.getMessage()); } } if (b != null) { b.disconnect(); } return null; } catch (UnsupportedEncodingException e13) { } catch (IOException e14) { } catch (JSONException e15) { } catch (Throwable th4) { } } catch (UnsupportedEncodingException e16) { e = e16; inputStream = null; httpURLConnection = null; a.d("JWakeConfigHelper", "request wakeConfig exception:" + e.getMessage()); if (inputStream != null) { } } catch (IOException e17) { e2 = e17; inputStream = null; httpURLConnection = null; a.d("JWakeConfigHelper", "request wakeConfig exception:" + e2.getMessage()); if (inputStream != null) { } } catch (JSONException e18) { e3 = e18; inputStream = null; httpURLConnection = null; a.d("JWakeConfigHelper", "request wakeConfig exception:" + e3.getMessage()); if (inputStream != null) { } } catch (Throwable th5) { th = th5; httpURLConnection = null; if (inputStream2 != null) { } if (httpURLConnection != null) { } throw th; } } public static void a(Context context, JSONObject jSONObject) { if (jSONObject != null) { a.a("JWakeConfigHelper", "write wakeConfigJson:" + jSONObject); d.a(context, "bwc.catch", jSONObject); } } /* JADX WARNING: Removed duplicated region for block: B:31:0x007d A[Catch:{ JSONException -> 0x00ca }] */ /* JADX WARNING: Removed duplicated region for block: B:37:0x00b5 A[Catch:{ JSONException -> 0x00ca }] */ public static cn.jiguang.ah.a b(Context context, JSONObject jSONObject) { int optInt; String optString; cn.jiguang.ah.a aVar = new cn.jiguang.ah.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; } if (optInt2 != 0) { if (optInt2 != 1) { if (optInt2 == 2) { aVar.c = false; } else { String optString2 = jSONObject.optString("errmsg"); a.d("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.f799a = !"disable".equals(jSONObject.optString("app_wakeup_config", "enable")); aVar.b = !"disable".equals(jSONObject.optString("app_wakeuped_config", "enable")); 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.f799a = !"disable".equals(jSONObject.optString("app_wakeup_config", "enable")); aVar.b = !"disable".equals(jSONObject.optString("app_wakeuped_config", "enable")); 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.f799a = !"disable".equals(jSONObject.optString("app_wakeup_config", "enable")); aVar.b = !"disable".equals(jSONObject.optString("app_wakeuped_config", "enable")); 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.d("JWakeConfigHelper", "parseWakeConfig exception:" + e.toString()); } } }