package com.baidu.liantian.utility; import android.app.Application; import android.content.BroadcastReceiver; import android.content.ContentProviderClient; import android.content.ContentResolver; import android.content.Context; import android.content.IntentFilter; import android.content.pm.ProviderInfo; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.Process; import android.text.TextUtils; import android.util.Base64; import com.baidu.liantian.LiantianProvider; import com.baidu.liantian.LiantianReceiver; import com.baidu.liantian.b; import com.baidu.liantian.core.c; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import kotlin.UByte; import org.json.JSONObject; /* compiled from: CommonMethods */ public final class a { public static String a = null; public static String b = null; public static String c = "11"; public static String d = "3ae74ab08362c350a7167c2fb02fef54"; public static JSONObject e = null; private static String f = ""; private static String g = ""; private static int h = -1; private static int i = -1; private static int j = -1; public static void a() { com.baidu.liantian.a.c(); } public static String a(Class<?> cls) { try { if (cls.getCanonicalName().equals(Integer.TYPE.getCanonicalName())) { return Integer.class.getCanonicalName(); } if (cls.getCanonicalName().equals(Boolean.TYPE.getCanonicalName())) { return Boolean.class.getCanonicalName(); } if (cls.getCanonicalName().equals(Character.TYPE.getCanonicalName())) { return Character.class.getCanonicalName(); } if (cls.getCanonicalName().equals(Byte.TYPE.getCanonicalName())) { return Byte.class.getCanonicalName(); } if (cls.getCanonicalName().equals(Short.TYPE.getCanonicalName())) { return Short.class.getCanonicalName(); } if (cls.getCanonicalName().equals(Long.TYPE.getCanonicalName())) { return Long.class.getCanonicalName(); } if (cls.getCanonicalName().equals(Float.TYPE.getCanonicalName())) { return Float.class.getCanonicalName(); } if (cls.getCanonicalName().equals(Double.TYPE.getCanonicalName())) { return Double.class.getCanonicalName(); } return null; } catch (Throwable unused) { com.baidu.liantian.a.c(); return null; } } public static Class<?> a(String str) { try { if (str.contains(Integer.class.getCanonicalName())) { return Integer.TYPE; } if (str.contains(Boolean.class.getCanonicalName())) { return Boolean.TYPE; } if (str.contains(Character.class.getCanonicalName())) { return Character.TYPE; } if (str.contains(Byte.class.getCanonicalName())) { return Byte.TYPE; } if (str.contains(Short.class.getCanonicalName())) { return Short.TYPE; } if (str.contains(Long.class.getCanonicalName())) { return Long.TYPE; } if (str.contains(Float.class.getCanonicalName())) { return Float.TYPE; } if (str.contains(Double.class.getCanonicalName())) { return Double.TYPE; } return null; } catch (Throwable unused) { com.baidu.liantian.a.c(); return null; } } private static int h(Context context) { try { String b2 = b(context); if (TextUtils.isEmpty(g)) { g = b(Process.myPid()); } if (TextUtils.isEmpty(g)) { return 0; } return !TextUtils.isEmpty(b2) ? b2.equals(g) ? 1 : 2 : context.getPackageName().equals(g) ? 3 : 4; } catch (Throwable unused) { com.baidu.liantian.a.c(); return 0; } } public static int a(Context context) { int h2; try { if (LiantianProvider.a() || (h2 = h(context)) == 1) { return 1; } if (h2 != 2 && LiantianProvider.a()) { return 1; } return 0; } catch (Throwable unused) { com.baidu.liantian.a.c(); return -1; } } public static String b(Context context) { try { if (TextUtils.isEmpty(f)) { if (i != 1) { try { ProviderInfo resolveContentProvider = context.getPackageManager().resolveContentProvider(context.getPackageName() + ".liantian.ac.provider", 0); if (!(resolveContentProvider == null || resolveContentProvider.multiprocess)) { f = resolveContentProvider.processName; } } catch (Throwable unused) { com.baidu.liantian.a.c(); } i = 1; return f; } } return f; } catch (Throwable unused2) { com.baidu.liantian.a.c(); } } public static boolean b(String str) { try { if (TextUtils.isEmpty(g)) { g = b(Process.myPid()); } if (!str.equals(g)) { return true; } return false; } catch (Throwable unused) { com.baidu.liantian.a.c(); return false; } } public static Object a(Object obj, String str, Class<?>[] clsArr, Object... objArr) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { if (obj == null || TextUtils.isEmpty(str)) { com.baidu.liantian.a.a(); throw new NoSuchMethodException("object=" + obj + ", methodName=" + str); } else if (clsArr == null || objArr == null || clsArr.length == objArr.length) { Method[] declaredMethods = obj.getClass().getDeclaredMethods(); Method method = null; int length = declaredMethods.length; int i2 = 0; while (true) { if (i2 >= length) { break; } Method method2 = declaredMethods[i2]; if (a(method2, str, clsArr)) { method = method2; break; } i2++; } if (method != null) { return method.invoke(obj, objArr); } com.baidu.liantian.a.a(); throw new NoSuchMethodException("cannot find method in target methodName=" + str); } else { com.baidu.liantian.a.a(); throw new NoSuchMethodException("paramTypes or args fail"); } } private static boolean a(Method method, String str, Class<?>[] clsArr) { if (!str.equals(method.getName())) { return false; } com.baidu.liantian.a.a(); Class<?>[] parameterTypes = method.getParameterTypes(); if ((parameterTypes == null || parameterTypes.length == 0) && (clsArr == null || clsArr.length == 0)) { com.baidu.liantian.a.a(); return true; } else if ((clsArr == null || clsArr.length == 0) && parameterTypes != null && parameterTypes.length > 0) { com.baidu.liantian.a.a(); return false; } else if ((parameterTypes == null || parameterTypes.length == 0) && clsArr != null && clsArr.length > 0) { com.baidu.liantian.a.a(); return false; } else if (parameterTypes == null || clsArr == null) { return false; } else { if (parameterTypes.length != clsArr.length) { com.baidu.liantian.a.a(); return false; } for (int i2 = 0; i2 < parameterTypes.length; i2++) { if (parameterTypes[i2] != clsArr[i2]) { com.baidu.liantian.a.a(); return false; } } com.baidu.liantian.a.a(); return true; } } public static boolean c(Context context) { NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo(); if (activeNetworkInfo != null && 1 == activeNetworkInfo.getType()) { return true; } return false; } public static boolean d(Context context) { try { NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo(); if (activeNetworkInfo == null) { return false; } return activeNetworkInfo.isConnected(); } catch (Throwable unused) { com.baidu.liantian.a.c(); return false; } } public static String[] e(Context context) { String[] split; String[] split2; String str = a; String str2 = b; if (TextUtils.isEmpty(str) || TextUtils.isEmpty(str2)) { if (TextUtils.isEmpty(str) || TextUtils.isEmpty(str2)) { String string = new b(context).a.getString("svi_n", ""); if (!TextUtils.isEmpty(string) && (split2 = string.split("-")) != null && split2.length == 2) { com.baidu.liantian.a.a(); return split2; } } if (TextUtils.isEmpty(str) || TextUtils.isEmpty(str2)) { String string2 = new b(context).a.getString("svi", ""); if (!TextUtils.isEmpty(string2) && (split = string2.split("-")) != null && split.length == 2) { com.baidu.liantian.a.a(); return split; } } if (TextUtils.isEmpty(str) || TextUtils.isEmpty(str2)) { com.baidu.liantian.a.a(); str = c; str2 = d; } return new String[]{str, str2}; } com.baidu.liantian.a.a(); return new String[]{str, str2}; } private static boolean i(Context context) { try { if (j < 0 && context != null) { try { String packageName = context.getPackageName(); Field field = Class.forName(packageName + ".BuildConfig").getField("DEBUG"); field.setAccessible(true); j = field.getBoolean(null) ? 1 : 0; } catch (Throwable unused) { if (context.getApplicationInfo() != null) { if ((context.getApplicationInfo().flags & 2) != 0) { j = 1; } else { j = 0; } } } } return j == 1; } catch (Throwable unused2) { com.baidu.liantian.a.c(); } } public static void f(Context context) throws UnsupportedOperationException { if (i(context)) { StringBuilder sb = new StringBuilder("SDK Self Check: "); int length = sb.length(); try { System.loadLibrary("liantian"); } catch (Throwable unused) { sb.append("LoadLibrary Error,"); } try { Class.forName("com.baidu.liantian.ac.F").getDeclaredMethod("getInstance", new Class[0]); } catch (Exception unused2) { sb.append("Proguard Error,"); } try { boolean z = context.getPackageManager().resolveContentProvider(context.getPackageName() + ".liantian.ac.provider", 0).multiprocess; } catch (Throwable unused3) { sb.append("Provider Error,"); } if (sb.length() > length) { throw new UnsupportedOperationException(sb.toString()); } } } private static String b(int i2) { String str; String str2 = null; try { if (Build.VERSION.SDK_INT >= 28) { str = Application.getProcessName(); try { if (!TextUtils.isEmpty(str)) { return str.trim(); } } catch (Throwable unused) { str2 = str; com.baidu.liantian.a.c(); return str2; } } else { str = null; } try { Method declaredMethod = Class.forName("android.app.ActivityThread", false, Application.class.getClassLoader()).getDeclaredMethod("currentProcessName", new Class[0]); declaredMethod.setAccessible(true); Object invoke = declaredMethod.invoke(null, new Object[0]); if (invoke instanceof String) { str = (String) invoke; } if (!TextUtils.isEmpty(str)) { return str.trim(); } str2 = d(String.format("/proc/%d/cmdline", Integer.valueOf(i2))); if (!TextUtils.isEmpty(str2)) { return str2.trim(); } return str2; } catch (Throwable unused2) { com.baidu.liantian.a.c(); } } catch (Throwable unused3) { com.baidu.liantian.a.c(); return str2; } } /* JADX WARNING: Can't wrap try/catch for region: R(4:11|12|(2:14|15)|16) */ /* JADX WARNING: Code restructure failed: missing block: B:12:?, code lost: com.baidu.liantian.a.c(); */ /* JADX WARNING: Code restructure failed: missing block: B:13:0x0012, code lost: if (r1 != null) goto L_0x0014; */ /* JADX WARNING: Code restructure failed: missing block: B:15:?, code lost: r1.close(); */ /* JADX WARNING: Code restructure failed: missing block: B:16:0x0017, code lost: return null; */ /* JADX WARNING: Code restructure failed: missing block: B:18:0x0018, code lost: r2 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:19:0x0019, code lost: if (r1 != null) goto L_0x001b; */ /* JADX WARNING: Code restructure failed: missing block: B:21:?, code lost: r1.close(); */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Missing exception handler attribute for start block: B:11:0x000f */ private static String d(String str) { FileInputStream fileInputStream; try { fileInputStream = new FileInputStream(str); String a2 = a(fileInputStream); try { fileInputStream.close(); } catch (Throwable unused) { } return a2; } catch (Throwable unused2) { fileInputStream = null; } throw th; } public static boolean a(int i2) { return c.a == i2; } private static String a(InputStream inputStream) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8")); StringBuilder sb = new StringBuilder(); boolean z = true; while (true) { String readLine = bufferedReader.readLine(); if (readLine == null) { return sb.toString(); } if (!z) { sb.append('\n'); } else { z = false; } sb.append(readLine); } } public static String a(byte[] bArr) { String str = ""; for (byte b2 : bArr) { String hexString = Integer.toHexString(b2 & UByte.MAX_VALUE); if (hexString.length() == 1) { hexString = "0" + hexString; } str = str + hexString.toUpperCase(); } return str; } public static boolean a(Context context, BroadcastReceiver broadcastReceiver, IntentFilter intentFilter) { try { context.registerReceiver(broadcastReceiver, intentFilter, context.getPackageName() + ".permission.liantian.RECEIVE", null); return true; } catch (Throwable unused) { com.baidu.liantian.a.c(); return false; } } public static void g(Context context) { try { LiantianReceiver liantianReceiver = new LiantianReceiver(); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction("com.baidu.action.Liantian.VIEW"); intentFilter.addCategory("com.baidu.category.liantian"); intentFilter.addCategory("android.intent.category.DEFAULT"); context.registerReceiver(liantianReceiver, intentFilter, context.getPackageName() + ".permission.liantian.RECEIVE", null); } catch (Throwable unused) { com.baidu.liantian.a.c(); } } public static void a(Context context, String str, int i2) { if (i2 >= 0) { try { File file = new File(context.getFilesDir(), ".tmp_liantian_st"); if (!file.exists()) { file.mkdir(); } File file2 = new File(file, str); if (i2 > 0) { if (file2.exists()) { file2.delete(); } } else if (i2 == 0 && !file2.exists()) { file2.createNewFile(); } } catch (Throwable unused) { com.baidu.liantian.a.c(); } } } public static boolean a(Context context, String str) { try { File file = new File(context.getFilesDir(), ".tmp_liantian_st"); if (!file.exists()) { file.mkdir(); } if (!new File(file, str).exists()) { return true; } return false; } catch (Throwable unused) { com.baidu.liantian.a.c(); return false; } } public static String c(String str) { try { String str2 = new String(d.b(b.a.getBytes(), Base64.decode(str, 10)), "UTF-8"); return !TextUtils.isEmpty(str2) ? str2 : ""; } catch (Throwable unused) { com.baidu.liantian.a.c(); return ""; } } /* JADX WARNING: Code restructure failed: missing block: B:17:?, code lost: com.baidu.liantian.a.c(); */ /* JADX WARNING: Code restructure failed: missing block: B:20:0x0048, code lost: return null; */ /* JADX WARNING: Code restructure failed: missing block: B:21:0x0049, code lost: r5 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:22:0x004a, code lost: if (r4 != null) goto L_0x004c; */ /* JADX WARNING: Code restructure failed: missing block: B:23:0x004c, code lost: r4.release(); */ /* JADX WARNING: Code restructure failed: missing block: B:24:0x004f, code lost: throw r5; */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Missing exception handler attribute for start block: B:16:0x0040 */ public static Bundle a(Context context, String str, Bundle bundle) { ContentProviderClient contentProviderClient; if (Build.VERSION.SDK_INT < 11) { return null; } try { ContentResolver contentResolver = context.getApplicationContext().getContentResolver(); Uri parse = Uri.parse("content://" + context.getPackageName() + ".liantian.ac.provider"); if (Build.VERSION.SDK_INT < 17) { return contentResolver.call(parse, str, (String) null, bundle); } try { contentProviderClient = contentResolver.acquireUnstableContentProviderClient(parse); Bundle call = contentProviderClient.call(str, null, bundle); if (contentProviderClient != null) { contentProviderClient.release(); } return call; } catch (Throwable unused) { contentProviderClient = null; } } catch (Throwable unused2) { com.baidu.liantian.a.c(); return null; } } /* JADX WARNING: Can't wrap try/catch for region: R(4:16|17|(2:19|20)|23) */ /* JADX WARNING: Code restructure failed: missing block: B:17:?, code lost: com.baidu.liantian.a.c(); */ /* JADX WARNING: Code restructure failed: missing block: B:23:0x002a, code lost: return false; */ /* JADX WARNING: Code restructure failed: missing block: B:24:0x002b, code lost: r2 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:25:0x002c, code lost: if (r1 != null) goto L_0x002e; */ /* JADX WARNING: Code restructure failed: missing block: B:27:?, code lost: r1.close(); */ /* JADX WARNING: Code restructure failed: missing block: B:28:0x0032, code lost: com.baidu.liantian.a.c(); */ /* JADX WARNING: Code restructure failed: missing block: B:30:0x0035, code lost: throw r2; */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Missing exception handler attribute for start block: B:16:0x001e */ public static boolean a(Context context, byte[] bArr, File file) { FileOutputStream fileOutputStream; if (!(context == null || bArr == null)) { try { if (bArr.length > 0) { fileOutputStream = new FileOutputStream(file); fileOutputStream.write(bArr); fileOutputStream.flush(); try { fileOutputStream.close(); return true; } catch (IOException unused) { com.baidu.liantian.a.c(); return true; } } } catch (Throwable unused2) { fileOutputStream = null; } } return false; } }