package com.amap.api.col.p0003s; import android.content.Context; import android.database.Cursor; import android.net.Uri; import android.os.Build; import android.text.TextUtils; import java.net.InetSocketAddress; import java.net.Proxy; import java.net.ProxySelector; import java.net.URI; import java.util.List; import java.util.Locale; /* renamed from: com.amap.api.col.3s.hp reason: invalid package */ /* compiled from: ProxyUtil */ public final class hp { public static Proxy a(Context context) { try { if (Build.VERSION.SDK_INT >= 11) { return a(context, new URI("http://restsdk.amap.com")); } return b(context); } catch (Throwable th) { il.c(th, "pu", "gp"); return null; } } /* JADX WARNING: Code restructure failed: missing block: B:28:0x0074, code lost: if (r10 == -1) goto L_0x0076; */ /* JADX WARNING: Code restructure failed: missing block: B:30:0x0079, code lost: r18 = r10; */ /* JADX WARNING: Code restructure failed: missing block: B:46:0x00ab, code lost: if (r10 == -1) goto L_0x0076; */ /* JADX WARNING: Code restructure failed: missing block: B:84:0x0119, code lost: if (r12 == -1) goto L_0x0138; */ /* JADX WARNING: Removed duplicated region for block: B:104:0x014a A[SYNTHETIC, Splitter:B:104:0x014a] */ /* JADX WARNING: Removed duplicated region for block: B:112:0x0159 A[Catch:{ all -> 0x0155 }] */ /* JADX WARNING: Removed duplicated region for block: B:53:0x00b9 A[SYNTHETIC, Splitter:B:53:0x00b9] */ /* JADX WARNING: Removed duplicated region for block: B:65:0x00d4 A[SYNTHETIC, Splitter:B:65:0x00d4] */ /* JADX WARNING: Removed duplicated region for block: B:74:0x00ef */ /* JADX WARNING: Removed duplicated region for block: B:96:0x013b */ /* JADX WARNING: Removed duplicated region for block: B:98:0x013e A[SYNTHETIC, Splitter:B:98:0x013e] */ private static Proxy b(Context context) { String str; int i; Cursor cursor; SecurityException e; String o; int i2; boolean z; boolean z2; Throwable th; int i3; boolean z3; boolean z4; if (c(context)) { boolean z5 = false; try { cursor = context.getContentResolver().query(Uri.parse("content://telephony/carriers/preferapn"), null, null, null, null); if (cursor != null) { try { if (cursor.moveToFirst()) { String string = cursor.getString(cursor.getColumnIndex("apn")); if (string != null) { string = string.toLowerCase(Locale.US); } if (string != null && string.contains("ctwap")) { String a = a(); i = b(); try { if (TextUtils.isEmpty(a) || a.equals("null")) { str = null; z4 = false; } else { str = a; z4 = true; } if (!z4) { try { str = a("QMTAuMC4wLjIwMA=="); } catch (SecurityException e2) { e = e2; } catch (Throwable th2) { th = th2; try { il.c(th, "pu", "gPx1"); th.printStackTrace(); if (cursor != null) { } if (str != null) { } if (z5) { } return null; } catch (Throwable th3) { il.c(th3, "pu", "gPx2"); } } } } catch (SecurityException e3) { e = e3; str = null; il.c(e, "pu", "ghp"); o = hi.o(context); if (o != null) { } if (cursor != null) { } i = i2; if (str != null) { } if (z5) { } return null; } catch (Throwable th4) { th = th4; str = null; il.c(th, "pu", "gPx1"); th.printStackTrace(); if (cursor != null) { } if (str != null) { } if (z5) { } return null; } } else if (string != null && string.contains("wap")) { String a2 = a(); i = b(); if (TextUtils.isEmpty(a2) || a2.equals("null")) { str = null; z3 = false; } else { str = a2; z3 = true; } if (!z3) { str = a("QMTAuMC4wLjE3Mg=="); } } i3 = 80; if (cursor != null) { try { cursor.close(); } catch (Throwable th5) { il.c(th5, "pu", "gPx2"); } } i = i3; if (str != null) { try { if (str.length() > 0 && i != -1) { z5 = true; } } catch (Throwable th6) { ii.a(th6, "pu", "gp2"); th6.printStackTrace(); } } if (z5) { return new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved(str, i)); } } } catch (SecurityException e4) { e = e4; str = null; i = -1; il.c(e, "pu", "ghp"); o = hi.o(context); if (o != null) { } if (cursor != null) { } i = i2; if (str != null) { } if (z5) { } return null; } catch (Throwable th7) { th = th7; str = null; i = -1; il.c(th, "pu", "gPx1"); th.printStackTrace(); if (cursor != null) { } if (str != null) { } if (z5) { } return null; } } str = null; i3 = -1; if (cursor != null) { } i = i3; } catch (SecurityException e5) { e = e5; cursor = null; str = null; i = -1; il.c(e, "pu", "ghp"); o = hi.o(context); if (o != null) { String lowerCase = o.toLowerCase(Locale.US); String a3 = a(); i2 = b(); if (lowerCase.indexOf("ctwap") != -1) { if (TextUtils.isEmpty(a3) || a3.equals("null")) { z2 = false; } else { str = a3; z2 = true; } if (!z2) { str = a("QMTAuMC4wLjIwMA=="); } } else if (lowerCase.indexOf("wap") != -1) { if (TextUtils.isEmpty(a3) || a3.equals("null")) { z = false; } else { str = a3; z = true; } if (!z) { str = a("QMTAuMC4wLjE3Mg=="); } } i2 = 80; } else { i2 = i; } if (cursor != null) { try { cursor.close(); } catch (Throwable th8) { il.c(th8, "pu", "gPx2"); } } i = i2; if (str != null) { } if (z5) { } return null; } catch (Throwable th9) { th = th9; cursor = null; str = null; i = -1; il.c(th, "pu", "gPx1"); th.printStackTrace(); if (cursor != null) { try { cursor.close(); } catch (Throwable th10) { il.c(th10, "pu", "gPx2"); } } if (str != null) { } if (z5) { } return null; } if (str != null) { } if (z5) { } } return null; throw th; } private static String a(String str) { return hr.c(str); } private static String a() { String str; try { str = android.net.Proxy.getDefaultHost(); } catch (Throwable th) { il.c(th, "pu", "gdh"); str = null; } return str == null ? "null" : str; } private static Proxy a(Context context, URI uri) { Proxy proxy; if (c(context)) { try { List<Proxy> select = ProxySelector.getDefault().select(uri); if (select == null || select.isEmpty() || (proxy = select.get(0)) == null || proxy.type() == Proxy.Type.DIRECT) { return null; } return proxy; } catch (Throwable th) { il.c(th, "pu", "gpsc"); } } return null; } private static boolean c(Context context) { return hi.n(context) == 0; } private static int b() { try { return android.net.Proxy.getDefaultPort(); } catch (Throwable th) { il.c(th, "pu", "gdp"); return -1; } } }