package com.unionpay; import android.app.Activity; import android.app.AlertDialog; import android.app.DownloadManager; import android.content.ActivityNotFoundException; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.Uri; import android.nfc.NfcAdapter; import android.nfc.NfcManager; import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.os.Handler; import android.telephony.TelephonyManager; import android.text.TextUtils; import android.util.Base64; import com.netease.yunxin.base.utils.StringUtils; import com.umeng.analytics.pro.ai; import com.unionpay.a.d; import com.unionpay.utils.UPUtils; import com.unionpay.utils.b; import com.unionpay.utils.f; import com.unionpay.utils.g; import com.unionpay.utils.h; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.util.ArrayList; import java.util.Collections; import java.util.Locale; import java.util.TimeZone; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; /* renamed from: com.unionpay.a reason: case insensitive filesystem */ public class C0441a { private static d A = null; private static Handler B = null; private static String C = "application/vnd.android.package-archive"; private static String D = "[{\"type\":\"app\",\"sort\":100,\"package_info\":[{\"schema\":\"com.unionpay.uppay\",\"version\":\".*\",\"sign\":\"23137B5BE6AEF6682B41E6536F08367E0949A1CC\",\"sort\":101}],\"need_install\":false,\"install_msg\":\"请先安装银联在线支付服务,安装完成后重新发起付款\",\"url\":\"https://mobile.unionpay.com/getclient?platform=android&type=securepayplugin\",\"download_app\":\"UPPayPluginEx.apk\",\"download_title\":\"银联在线支付服务\",\"download_desp\":\"正在下载银联在线支付服务…\",\"md5\":\"D75BB2802E61738A9A03BF014F927D9A\"},{\"type\":\"jar\",\"sort\":200}]"; private static JSONArray E = null; private static IntentFilter F = new IntentFilter("android.intent.action.DOWNLOAD_COMPLETE"); private static BroadcastReceiver G = new C0442b(); private static final Handler.Callback H = new f(); /* renamed from: a reason: collision with root package name */ private static String f14552a = "SpId"; /* renamed from: b reason: collision with root package name */ private static String f14553b = "paydata"; /* renamed from: c reason: collision with root package name */ private static String f14554c = "SysProvide"; /* renamed from: d reason: collision with root package name */ private static String f14555d = "UseTestMode"; /* renamed from: e reason: collision with root package name */ private static String f14556e = "SecurityChipType"; /* renamed from: f reason: collision with root package name */ private static String f14557f = "reqOriginalId"; /* renamed from: g reason: collision with root package name */ private static String f14558g = "wapurl"; /* renamed from: h reason: collision with root package name */ private static String f14559h = "dlgstyle"; private static String i = "com.unionpay.uppay.PayActivity"; private static String j = "ex_mode"; private static String k = "server"; private static String l = "source"; private static String m = "samsung_out"; private static String n = ""; private static boolean o = false; private static int p = 10; private static Context q = null; private static String r = ""; private static String s = null; private static String t = null; private static String u = ""; private static String v = ""; private static boolean w = false; private static String x = ""; private static int y = 0; private static boolean z = false; public static int a(Context context, String str, String str2, String str3, String str4) { return b(context, str, str2, str3, str4, ""); } private static String a(Context context, String str) { try { InputStream open = context.getAssets().open(str); String absolutePath = context.getFilesDir().getAbsolutePath(); if (absolutePath == null) { return ""; } String str2 = absolutePath + File.separator + str; if (!new File(str2).exists()) { FileOutputStream openFileOutput = context.openFileOutput(str, 1); byte[] bArr = new byte[1024]; while (true) { int read = open.read(bArr); if (read <= 0) { break; } openFileOutput.write(bArr, 0, read); } openFileOutput.close(); open.close(); } return str2; } catch (Exception unused) { return ""; } } static String a(Context context, boolean z2) { int i2; NfcAdapter defaultAdapter; String str; JSONObject jSONObject = new JSONObject(); try { i2 = Integer.parseInt(u); } catch (NumberFormatException unused) { i2 = 0; } if (!z2) { try { jSONObject.put("tn", UPUtils.forWap(i2, b.a(r))); } catch (JSONException e2) { e2.printStackTrace(); } } jSONObject.put("imei", ((TelephonyManager) context.getSystemService("phone")).getDeviceId()); jSONObject.put("locale", Locale.getDefault().toString().startsWith("zh") ? "zh_CN" : "en_US"); jSONObject.put("terminal_version", "3.3.2"); jSONObject.put("terminal_resolution", (context.getResources().getDisplayMetrics().widthPixels + "*" + context.getResources().getDisplayMetrics().heightPixels).trim()); jSONObject.put("os_name", "android"); jSONObject.put(ai.y, Build.VERSION.RELEASE.trim()); String trim = Build.MODEL.trim(); if (trim != null) { trim.replace(StringUtils.SPACE, ""); } jSONObject.put("device_model", trim); jSONObject.put("mac", com.unionpay.utils.d.a(context)); try { jSONObject.put("time_zone", TimeZone.getDefault().getDisplayName(false, 0)); } catch (Exception e3) { e3.printStackTrace(); } try { NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo(); if (activeNetworkInfo == null || !activeNetworkInfo.isAvailable()) { str = "disConnect"; } else if (activeNetworkInfo.getType() != 0) { str = activeNetworkInfo.getType() == 1 ? "wifi" : "other"; } else if (activeNetworkInfo.getState() == NetworkInfo.State.CONNECTED) { str = "mobile:" + activeNetworkInfo.getExtraInfo(); } else { str = "mobile"; } jSONObject.put("network_mode", str); } catch (Exception e4) { e4.printStackTrace(); } try { String subscriberId = ((TelephonyManager) context.getSystemService("phone")).getSubscriberId(); if (subscriberId == null) { subscriberId = ""; } jSONObject.put("imsi", subscriberId); } catch (Exception e5) { e5.printStackTrace(); } try { jSONObject.put("baseband_version", com.unionpay.utils.d.a()); } catch (Exception e6) { e6.printStackTrace(); } try { jSONObject.put("root", new File("/system/bin/su").exists() ? "1" : "0"); } catch (Exception e7) { e7.printStackTrace(); } try { StringBuffer stringBuffer = new StringBuffer("000"); if (Build.VERSION.SDK_INT >= 10 && (defaultAdapter = ((NfcManager) context.getSystemService("nfc")).getDefaultAdapter()) != null) { if (defaultAdapter.isEnabled()) { stringBuffer.setCharAt(0, '1'); } else { stringBuffer.setCharAt(0, '2'); } if (Build.VERSION.SDK_INT >= 19 && context.getPackageManager().hasSystemFeature("android.hardware.nfc.hce")) { stringBuffer.setCharAt(1, '1'); } } jSONObject.put("support_map", stringBuffer.toString()); } catch (Exception e8) { e8.printStackTrace(); } if (z2) { try { Class.forName("com.unionpay.uppay.PayActivity"); jSONObject.put("has_sdk", "1"); } catch (ClassNotFoundException unused2) { jSONObject.put("has_sdk", "0"); } } String jSONObject2 = jSONObject.toString(); g.b("uppay", "init: " + jSONObject2); return jSONObject2; } static /* synthetic */ void a(Context context) { try { Intent intent = new Intent("android.settings.APPLICATION_DETAILS_SETTINGS"); intent.setData(Uri.parse("package:com.android.providers.downloads")); context.startActivity(intent); } catch (ActivityNotFoundException e2) { e2.printStackTrace(); context.startActivity(new Intent("android.settings.MANAGE_APPLICATIONS_SETTINGS")); } } public static void a(Context context, Class cls, String str, String str2, String str3, String str4) { a(context, str, str2, str3, str4); } static void a(Context context, String str, String str2, String str3, String str4, String str5) { boolean z2; String a2 = a(context, str2); if (a2 == null || TextUtils.isEmpty(a2)) { z2 = false; } else { Intent intent = new Intent("android.intent.action.VIEW"); intent.setDataAndType(Uri.parse("file:" + a2), "application/vnd.android.package-archive"); context.startActivity(intent); z2 = true; } if (!z2) { v = str5; x = str2; if (!w) { try { context.registerReceiver(G, F); DownloadManager.Request request = new DownloadManager.Request(Uri.parse(str)); request.setMimeType(C); request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, str2); request.setTitle(str3); request.setDescription(str4); request.setNotificationVisibility(1); UPUtils.a(context, ((DownloadManager) context.getSystemService("download")).enqueue(request), "id"); w = true; } catch (Exception e2) { if (e2 instanceof IllegalArgumentException) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(h.a().f15380e); builder.setMessage(h.a().f15382g); builder.setPositiveButton(h.a().f15378c, new j(context)); builder.setNegativeButton(h.a().f15379d, new k(context)); builder.create().show(); return; } context.startActivity(new Intent("android.intent.action.VIEW", Uri.parse(str))); } } } } static /* synthetic */ void a(Context context, JSONArray jSONArray, int i2) { String str; boolean z2; JSONArray jSONArray2 = jSONArray; int i3 = i2; while (jSONArray2 != null && i3 < jSONArray2.length()) { Object a2 = f.a(jSONArray2, i3); if (a2 != null) { JSONObject jSONObject = (JSONObject) a2; String a3 = f.a(jSONObject, "type"); if ("app".equals(a3)) { JSONArray c2 = f.c(jSONObject, "package_info"); String a4 = f.a(jSONObject, "install_msg"); String a5 = f.a(jSONObject, "url"); boolean b2 = f.b(jSONObject, "need_install"); String a6 = f.a(jSONObject, "download_app"); String a7 = f.a(jSONObject, "download_title"); String a8 = f.a(jSONObject, "download_desp"); String a9 = f.a(jSONObject, "md5"); String a10 = f.a(jSONObject, "app_server"); JSONArray b3 = b(c2, "sort"); if (b3 != null && b3.length() > 0) { int length = b3.length(); int i4 = 0; while (true) { if (i4 >= length) { break; } Object a11 = f.a(b3, i4); if (a11 != null) { JSONObject jSONObject2 = (JSONObject) a11; String a12 = f.a(jSONObject2, "schema"); String a13 = f.a(jSONObject2, "sign"); String a14 = f.a(jSONObject2, "version"); if (b.a(context, a12) && a13.equalsIgnoreCase(b.b(context, a12)) && b.c(context, a12).matches(a14)) { Bundle bundle = new Bundle(); a(r, bundle, u); bundle.putString(f14552a, s); bundle.putString(f14554c, t); bundle.putString(f14553b, r); bundle.putString(l, n); bundle.putString(k, a10); bundle.putString(f14556e, null); bundle.putInt(f14557f, 0); Intent intent = new Intent(); intent.putExtras(bundle); intent.setClassName(a12, i); Context context2 = q; if (context2 instanceof Activity) { ((Activity) context2).startActivityForResult(intent, p); } else { intent.addFlags(268435456); q.startActivity(intent); } z2 = true; } } i4++; } } z2 = false; if (z2) { return; } if (b2) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(h.a().f15380e); builder.setMessage(a4); builder.setPositiveButton(h.a().f15378c, new h(context, a5, a6, a7, a8, a9)); builder.setNegativeButton(h.a().f15379d, new i(context)); builder.create().show(); return; } } else { int i5 = 0; if ("wap".equals(a3)) { if (!m.equals(n)) { try { str = (String) jSONObject.get("url"); } catch (Exception unused) { str = ""; } Bundle bundle2 = new Bundle(); a(r, bundle2, u); bundle2.putString(f14552a, s); bundle2.putString(f14554c, t); try { i5 = Integer.parseInt(u); } catch (NumberFormatException unused2) { } bundle2.putString(f14553b, UPUtils.forWap(i5, b.a(r))); bundle2.putString(f14558g, str); Intent intent2 = new Intent(); intent2.putExtras(bundle2); intent2.setClass(q, UPPayWapActivity.class); ((Activity) q).startActivityForResult(intent2, 100); return; } } else if ("jar".equals(a3)) { a(f.a(jSONObject, "app_server")); return; } else { return; } } jSONArray2 = E; i3 = y + 1; y = i3; } else { return; } } } static void a(String str) { Bundle bundle = new Bundle(); a(r, bundle, u); bundle.putString(f14552a, s); bundle.putString(f14554c, t); bundle.putString(f14553b, r); bundle.putString(l, n); bundle.putString(k, str); bundle.putBoolean(f14559h, o); bundle.putInt(f14557f, 2); try { Class<?> cls = Class.forName("com.unionpay.uppay.PayActivity"); Intent intent = new Intent(); intent.putExtras(bundle); intent.setClass(q, cls); if (q instanceof Activity) { ((Activity) q).startActivityForResult(intent, p); return; } intent.addFlags(268435456); q.startActivity(intent); } catch (ClassNotFoundException unused) { } } private static void a(String str, Bundle bundle, String str2) { if (str != null && str.trim().length() > 0) { if (str.trim().charAt(0) != '<') { bundle.putString(j, str2); } else if (str2 == null || !str2.trim().equalsIgnoreCase("00")) { bundle.putBoolean(f14555d, true); } else { bundle.putBoolean(f14555d, false); } } } /* JADX WARNING: Can't wrap try/catch for region: R(9:0|(1:2)(1:3)|4|(6:10|11|12|13|16|(1:18))|19|20|(2:21|22)|25|26) */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Missing exception handler attribute for start block: B:19:0x008a */ /* JADX WARNING: Missing exception handler attribute for start block: B:21:0x0099 */ private static int b(Context context, String str, String str2, String str3, String str4, String str5) { int i2; int i3; q = context; r = str3; s = str; t = str2; u = str4; n = str5; if (!TextUtils.isEmpty(str5)) { o = true; } else { o = false; } y = 0; z = false; System.loadLibrary("entryexpro"); String a2 = UPUtils.a(q, "configs"); String a3 = UPUtils.a(context, "mode"); String a4 = UPUtils.a(context, "or"); if (!TextUtils.isEmpty(a2) && !TextUtils.isEmpty(a3) && !TextUtils.isEmpty(a4)) { JSONObject jSONObject = new JSONObject(a2); String a5 = f.a(jSONObject, "sign"); try { i3 = Integer.parseInt(a3); } catch (NumberFormatException unused) { i3 = 0; } String str6 = new String(Base64.decode(jSONObject.getString("configs"), 2)); if (UPUtils.forConfig(i3, a5).equals(b.a(UPUtils.a(str6 + a4)))) { D = str6; } } E = b(new JSONArray(D), "sort"); try { i2 = Integer.parseInt(u); } catch (NumberFormatException unused2) { i2 = 0; } String forUrl = UPUtils.forUrl(i2); g.b("uppay", "url: " + forUrl); A = new d(forUrl); String a6 = a(context, false); g.b("uppay", "postdata: " + a6); A.a(a6); B = new Handler(H); new g().start(); return 0; } /* access modifiers changed from: private */ public static JSONArray b(JSONArray jSONArray, String str) { ArrayList arrayList = new ArrayList(); for (int i2 = 0; i2 < jSONArray.length(); i2++) { arrayList.add(jSONArray.optJSONObject(i2)); } Collections.sort(arrayList, new l(str)); JSONArray jSONArray2 = new JSONArray(); for (int i3 = 0; i3 < arrayList.size(); i3++) { jSONArray2.put((JSONObject) arrayList.get(i3)); } return jSONArray2; } /* JADX WARNING: Can't wrap try/catch for region: R(8:0|(7:6|7|8|9|10|13|(1:15))|16|17|18|(3:20|(2:22|(3:28|(3:30|(2:32|(2:44|38))(1:50)|39)|49))(1:45)|40)|43|41) */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Missing exception handler attribute for start block: B:16:0x006d */ /* JADX WARNING: Removed duplicated region for block: B:20:0x0079 */ public static boolean b(Context context) { JSONArray b2; int i2; String str = D; String a2 = UPUtils.a(context, "configs"); String a3 = UPUtils.a(context, "mode"); String a4 = UPUtils.a(context, "or"); if (!TextUtils.isEmpty(a2) && !TextUtils.isEmpty(a3) && !TextUtils.isEmpty(a4)) { System.loadLibrary("entryexpro"); JSONObject jSONObject = new JSONObject(a2); String a5 = f.a(jSONObject, "sign"); try { i2 = Integer.parseInt(a3); } catch (NumberFormatException unused) { i2 = 0; } String str2 = new String(Base64.decode(jSONObject.getString("configs"), 2)); if (UPUtils.forConfig(i2, a5).equals(b.a(UPUtils.a(str2 + a4)))) { str = str2; } } JSONArray jSONArray = new JSONArray(str); int length = jSONArray.length(); for (int i3 = 0; i3 < length; i3++) { Object a6 = f.a(jSONArray, i3); if (a6 != null) { JSONObject jSONObject2 = (JSONObject) a6; if ("app".equals(f.a(jSONObject2, "type")) && (b2 = b(f.c(jSONObject2, "package_info"), "sort")) != null && b2.length() > 0) { int length2 = b2.length(); for (int i4 = 0; i4 < length2; i4++) { Object a7 = f.a(b2, i4); if (a7 != null) { JSONObject jSONObject3 = (JSONObject) a7; String a8 = f.a(jSONObject3, "schema"); String a9 = f.a(jSONObject3, "sign"); String a10 = f.a(jSONObject3, "version"); if (b.a(context, a8) && a9.equalsIgnoreCase(b.b(context, a8)) && b.c(context, a8).matches(a10)) { return true; } } } continue; } } } return false; } static /* synthetic */ int o() { int i2 = y + 1; y = i2; return i2; } }