package cn.jiguang.f; import android.annotation.SuppressLint; import android.app.Activity; import android.app.ActivityManager; import android.app.AppOpsManager; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.ContentProvider; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.ComponentInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.ProviderInfo; import android.content.pm.ResolveInfo; import android.content.pm.Signature; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.wifi.WifiManager; import android.os.Build; import android.os.Environment; import android.os.Handler; import android.os.Looper; import android.os.Process; import android.provider.Settings; import android.telephony.TelephonyManager; import android.text.TextUtils; import android.util.DisplayMetrics; import android.widget.Toast; import androidx.core.app.NotificationCompat; import cn.jiguang.aq.c; import cn.jiguang.bd.b; import cn.jiguang.internal.JConstants; import cn.jpush.android.service.PushReceiver; import java.io.ByteArrayInputStream; import java.lang.reflect.Method; import java.net.Inet4Address; import java.net.InetAddress; import java.net.NetworkInterface; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; import java.util.ArrayList; import java.util.Enumeration; import java.util.Iterator; import java.util.List; import java.util.Locale; import javax.security.auth.x500.X500Principal; public class a { private static String a = null; private static String b = ""; private static int c; public static ComponentInfo a(Context context, String str, Class<?> cls) { ComponentInfo[] componentInfoArr; if (context == null || TextUtils.isEmpty(str) || cls == null) { c.g("AndroidUtil", "Action - hasComponent, invalide param, context:" + context + ",packageName:" + str + ",cls:" + cls); return null; } try { int i = Service.class.isAssignableFrom(cls) ? 4 : BroadcastReceiver.class.isAssignableFrom(cls) ? 2 : Activity.class.isAssignableFrom(cls) ? 1 : ContentProvider.class.isAssignableFrom(cls) ? 8 : 0; PackageInfo packageInfo = context.getPackageManager().getPackageInfo(str, i); if (i == 4) { componentInfoArr = packageInfo.services; } else if (i != 8) { switch (i) { case 1: componentInfoArr = packageInfo.activities; break; case 2: componentInfoArr = packageInfo.receivers; break; default: componentInfoArr = null; break; } } else { componentInfoArr = packageInfo.providers; } if (componentInfoArr == null) { return null; } for (ComponentInfo componentInfo : componentInfoArr) { try { if (cls.isAssignableFrom(Class.forName(componentInfo.name))) { return componentInfo; } } catch (Throwable unused) { } } return null; } catch (Throwable th) { c.h("AndroidUtil", "hasComponent error:" + th); } } public static ProviderInfo a(Context context, String str, String str2) { if (context != null && !TextUtils.isEmpty(str) && !TextUtils.isEmpty(str2)) { try { PackageInfo packageInfo = context.getPackageManager().getPackageInfo(str, 8); if (packageInfo.providers != null) { if (packageInfo.providers.length != 0) { ProviderInfo[] providerInfoArr = packageInfo.providers; for (ProviderInfo providerInfo : providerInfoArr) { if (str2.equals(providerInfo.authority)) { return providerInfo; } } } } } catch (Throwable unused) { } } return null; } public static String a(Context context) { if (!TextUtils.isEmpty(a)) { return a; } try { Context appContext = JConstants.getAppContext(context); ActivityManager activityManager = null; if (appContext != null) { activityManager = (ActivityManager) appContext.getSystemService("activity"); } if (activityManager != null) { int myPid = Process.myPid(); Iterator<ActivityManager.RunningAppProcessInfo> it = activityManager.getRunningAppProcesses().iterator(); while (true) { if (!it.hasNext()) { break; } ActivityManager.RunningAppProcessInfo next = it.next(); if (next.pid == myPid) { a = next.processName; break; } } } } catch (Throwable th) { c.h("AndroidUtil", "#unexcepted - getCurProcessName failed:" + th.getMessage()); } return a; } public static String a(Context context, String str) { try { return context.getPackageManager().getServiceInfo(new ComponentName(context.getPackageName(), str), 128).processName; } catch (Throwable unused) { return ""; } } public static List<String> a(Context context, Intent intent, String str) { ArrayList arrayList = new ArrayList(); try { List<ResolveInfo> queryIntentServices = context.getPackageManager().queryIntentServices(intent, 0); PackageManager packageManager = context.getPackageManager(); for (ResolveInfo resolveInfo : queryIntentServices) { if (resolveInfo.serviceInfo != null) { String str2 = resolveInfo.serviceInfo.name; if (!TextUtils.isEmpty(str2)) { boolean z = true; if (!TextUtils.isEmpty(str) && packageManager.checkPermission(str, resolveInfo.activityInfo.packageName) != 0) { z = false; } if (z) { arrayList.add(str2); } } } } } catch (Throwable unused) { } return arrayList; } public static List<String> a(Context context, List<String> list) { if (list == null || list.size() == 0) { return null; } ArrayList arrayList = new ArrayList(); for (String str : list) { if (!c(context, str)) { arrayList.add(str); } } return arrayList; } public static void a(Context context, Intent intent) { try { context.sendBroadcast(intent); } catch (Throwable unused) { b(context, intent); } } public static void a(Context context, String str, int i) { int i2; Notification notification; if (!g(context)) { c.c("AndroidUtil", "not debuggable"); } else if (!a(context, PushReceiver.class)) { d(context, str); } else { c.c("AndroidUtil", "action:showPermanentNotification"); Intent intent = new Intent(context, PushReceiver.class); intent.setAction("noti_open_proxy"); intent.addCategory(context.getPackageName()); intent.putExtra("debug_notification", true); intent.putExtra("toastText", str); intent.putExtra("type", i); PendingIntent broadcast = PendingIntent.getBroadcast(context, 0, intent, 134217728); NotificationManager notificationManager = (NotificationManager) context.getSystemService("notification"); try { i2 = context.getPackageManager().getApplicationInfo(context.getApplicationContext().getPackageName(), 0).icon; } catch (Throwable th) { c.d("AndroidUtil", "failed to get application info and icon.", th); i2 = 17301586; } long currentTimeMillis = System.currentTimeMillis(); if (Build.VERSION.SDK_INT >= 11) { Notification.Builder when = new Notification.Builder(context.getApplicationContext()).setContentTitle("Jiguang提示:包名和AppKey不匹配").setContentText("请到 Portal 上获取您的包名和AppKey并更新AndroidManifest相应字段").setContentIntent(broadcast).setSmallIcon(i2).setTicker(str).setWhen(currentTimeMillis); if (Build.VERSION.SDK_INT >= 26) { if (notificationManager.getNotificationChannel("JPush_Notification") == null) { notificationManager.createNotificationChannel(new NotificationChannel("JPush_Notification", "JPush_Notification", 3)); } when.setChannelId("JPush_Notification"); } notification = when.getNotification(); notification.flags = 34; } else { Notification notification2 = new Notification(i2, str, currentTimeMillis); notification2.flags = 34; try { e.a(notification2, "setLatestEventInfo", new Object[]{context, "Jiguang提示:包名和AppKey不匹配", "请到 Portal 上获取您的包名和AppKey并更新AndroidManifest相应字段", broadcast}, new Class[]{Context.class, CharSequence.class, CharSequence.class, PendingIntent.class}); } catch (Exception unused) { } notification = notification2; } c = 10000; notificationManager.notify(c, notification); } } public static boolean a() { boolean z; try { z = Environment.getExternalStorageState().equals("mounted"); } catch (Throwable th) { c.g("AndroidUtil", "isSdcardExist exception: " + th); z = false; } if (!z) { c.c("AndroidUtil", "SDCard is not mounted"); } return z; } public static boolean a(Context context, Class<?> cls) { try { boolean z = !context.getPackageManager().queryBroadcastReceivers(new Intent(context, cls), 0).isEmpty(); if (z) { return z; } try { return a(context, context.getPackageName(), cls) != null; } catch (Throwable unused) { return z; } } catch (Throwable unused2) { } } public static ProviderInfo b(Context context, String str, Class<? extends ContentProvider> cls) { try { return context.getPackageManager().getProviderInfo(new ComponentName(str, cls.getName()), 65536); } catch (Throwable unused) { return null; } } /* JADX WARNING: Removed duplicated region for block: B:10:? A[RETURN, SYNTHETIC] */ /* JADX WARNING: Removed duplicated region for block: B:8:0x0014 */ public static String b() { String str; try { str = Environment.getExternalStorageDirectory().getPath(); } catch (ArrayIndexOutOfBoundsException e) { e.printStackTrace(); } catch (Exception unused) { } if (!TextUtils.isEmpty(str)) { return str; } return str + "/data/"; str = null; if (!TextUtils.isEmpty(str)) { } } public static String b(Context context) { if (!TextUtils.isEmpty(b)) { return b; } b = context.getPackageName(); return b; } public static String b(Context context, String str) { try { return context.getPackageManager().getReceiverInfo(new ComponentName(context.getPackageName(), str), 128).processName; } catch (Throwable unused) { return ""; } } public static String b(Context context, String str, String str2) { try { return (String) e.a(context.getClassLoader().loadClass("android.os.SystemProperties"), "get", new Object[]{str, str2}, new Class[]{String.class, String.class}); } catch (IllegalArgumentException e) { throw e; } catch (Exception unused) { return ""; } } private static List<String> b(Context context, Intent intent, String str) { ArrayList arrayList = new ArrayList(); try { List<ResolveInfo> queryBroadcastReceivers = context.getPackageManager().queryBroadcastReceivers(intent, 0); PackageManager packageManager = context.getPackageManager(); for (ResolveInfo resolveInfo : queryBroadcastReceivers) { if (resolveInfo.activityInfo != null) { String str2 = resolveInfo.activityInfo.name; if (!TextUtils.isEmpty(str2)) { boolean z = true; if (!TextUtils.isEmpty(str) && packageManager.checkPermission(str, resolveInfo.activityInfo.packageName) != 0) { z = false; } if (z) { arrayList.add(str2); } } } } } catch (Throwable unused) { } return arrayList; } public static void b(Context context, Intent intent) { try { List<String> b2 = b(context, intent, (String) null); if (b2 == null || b2.isEmpty()) { c.h("AndroidUtil", "sendBroadcast failed again: receiver not found, action:" + intent.getAction()); return; } for (String str : b2) { try { Intent intent2 = (Intent) intent.clone(); intent2.setComponent(new ComponentName(context.getPackageName(), str)); context.sendBroadcast(intent2); } catch (Exception e) { c.h("AndroidUtil", "sendBroadcast failed again:" + e.getMessage() + ", action:" + intent.getAction()); } } } catch (Throwable th) { c.h("AndroidUtil", "tryAgainSendBrocast failed:" + th.getMessage()); } } public static int c(Context context) { if (context == null) { return -1; } IntentFilter intentFilter = new IntentFilter("android.intent.action.BATTERY_CHANGED"); Intent intent = null; try { intent = context.registerReceiver(null, intentFilter, context.getPackageName() + cn.jiguang.a.a.a, null); } catch (SecurityException unused) { c.g("AndroidUtil", "getChargedStatus SecurityException"); } catch (Exception e) { c.g("AndroidUtil", "getChargedStatus unkown exception:" + e.getMessage()); } if (intent == null) { return -1; } int intExtra = intent.getIntExtra(NotificationCompat.CATEGORY_STATUS, -1); if (!(intExtra == 2 || intExtra == 5)) { return -1; } return intent.getIntExtra("plugged", -1); } public static String c() { try { Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces(); while (networkInterfaces.hasMoreElements()) { Enumeration<InetAddress> inetAddresses = networkInterfaces.nextElement().getInetAddresses(); while (true) { if (inetAddresses.hasMoreElements()) { InetAddress nextElement = inetAddresses.nextElement(); if (!nextElement.isLoopbackAddress() && (nextElement instanceof Inet4Address)) { return nextElement.getHostAddress(); } } } } return ""; } catch (Exception e) { c.g("AndroidUtil", "getPhoneIp:"); e.printStackTrace(); return ""; } } public static boolean c(Context context, String str) { try { boolean z = true; if (Build.VERSION.SDK_INT >= 23) { if (context.getApplicationInfo().targetSdkVersion < 23) { String permissionToOp = AppOpsManager.permissionToOp(str); if (permissionToOp != null) { if (((AppOpsManager) context.getSystemService("appops")).noteProxyOpNoThrow(permissionToOp, context.getPackageName()) != 0) { z = false; } } return z; } else if (context.checkSelfPermission(str) != 0) { return false; } } return true; } catch (Throwable th) { c.g("AndroidUtil", "checkPermission error:" + th.getMessage()); return false; } } public static void d(final Context context, final String str) { new Handler(Looper.getMainLooper()).post(new b("AndroidUtils#ShowToast") { /* class cn.jiguang.f.a.AnonymousClass1 */ @Override // cn.jiguang.bd.b public void a() { try { Toast.makeText(context, str, 0).show(); } catch (Throwable unused) { } } }); } public static boolean d(Context context) { NetworkInfo activeNetworkInfo; try { return c(context, "android.permission.ACCESS_NETWORK_STATE") && (activeNetworkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo()) != null && activeNetworkInfo.isConnected(); } catch (Throwable th) { th.printStackTrace(); } return false; } @SuppressLint({"MissingPermission"}) public static String e(Context context, String str) { String str2 = null; try { if (JConstants.isAndroidQ(context, false, "do not getImei")) { return ""; } if (c(context, "android.permission.READ_PHONE_STATE")) { str2 = ((TelephonyManager) context.getSystemService("phone")).getDeviceId(); } return f.h(str2) ? str2 : str; } catch (Exception e) { c.i("AndroidUtil", e.getMessage()); } } public static boolean e(Context context) { String str = context.getApplicationInfo().sourceDir; if (f.a(str)) { c.i("AndroidUtil", "Unexpected: cannot get pk installed path"); return false; } c.c("AndroidUtil", "Current pk installed path: " + str); if (str.startsWith("/system/app/")) { return true; } if (str.startsWith("/data/app/")) { return false; } c.e("AndroidUtil", "NOTE: the pk does not installed in system/data. "); return false; } public static String f(Context context) { DisplayMetrics displayMetrics; if (context == null || context.getResources() == null || (displayMetrics = context.getResources().getDisplayMetrics()) == null) { return "0*0"; } int i = displayMetrics.widthPixels; int i2 = displayMetrics.heightPixels; return i + "*" + i2; } @SuppressLint({"MissingPermission"}) public static String f(Context context, String str) { try { return JConstants.isAndroidQ(context, false, "do not getImsi") ? "" : c(context, "android.permission.READ_PHONE_STATE") ? ((TelephonyManager) context.getSystemService("phone")).getSubscriberId() : str; } catch (Throwable th) { c.g("AndroidUtil", "getImsi failed:" + th.getMessage()); return str; } } public static String g(Context context, String str) { if (!cn.jiguang.d.a.l(context)) { c.c("AndroidUtil", "[getWifiMac] lbs disabled"); return str; } String k = k(context); String l = !f.i(k) ? l(context) : k; if (!f.i(l)) { l = str; } c.c("AndroidUtil", "getWifiMac:" + l); return l; } public static boolean g(Context context) { try { boolean z = (context.getApplicationInfo().flags & 2) != 0; c.c("AndroidUtil", "isDebug:" + z); if (JConstants.INTERNAL_USE && JConstants.DEBUG_MODE) { return z; } X500Principal x500Principal = new X500Principal("CN=Android Debug,O=Android,C=US"); String[] strArr = {"CN=Android Debug", "O=Android", "C=US"}; Signature[] signatureArr = context.getPackageManager().getPackageInfo(context.getPackageName(), 64).signatures; CertificateFactory instance = CertificateFactory.getInstance("X.509"); boolean z2 = false; for (Signature signature : signatureArr) { try { X509Certificate x509Certificate = (X509Certificate) instance.generateCertificate(new ByteArrayInputStream(signature.toByteArray())); z2 = x509Certificate.getSubjectX500Principal().equals(x500Principal); c.c("AndroidUtil", "debuggable :" + z2); if (z2) { return z2; } String str = null; try { str = x509Certificate.getSubjectX500Principal().getName(); } catch (Exception unused) { } c.c("AndroidUtil", "certName:" + str); if (str != null && str.contains(strArr[0]) && str.contains(strArr[1]) && str.contains(strArr[2])) { return true; } } catch (Throwable unused2) { return z2; } } return z2; } catch (Throwable unused3) { return false; } } public static void h(Context context) { try { if (c != 0) { ((NotificationManager) context.getSystemService("notification")).cancel(c); } } catch (Throwable th) { c.g("AndroidUtil", "[canclePermanentNotification] failed:" + th.getMessage()); } } public static boolean h(Context context, String str) { if (f.a(str)) { return false; } try { return context.getPackageManager().getPackageInfo(str, 0) != null; } catch (Throwable unused) { } } public static String i(Context context) { String str = ""; try { str = Settings.Secure.getString(context.getContentResolver(), "android_id"); } catch (Throwable unused) { } return f.h(str) ? str : ""; } public static boolean i(Context context, String str) { if (context == null || TextUtils.isEmpty(str)) { throw new IllegalArgumentException("empty params"); } try { context.getPackageManager().getPermissionInfo(str, 128); return true; } catch (Throwable th) { c.h("AndroidUtil", "hasPermissionDefined error:" + th.getMessage()); return false; } } public static String j(Context context) { try { String g = g(context, ""); if (g != null) { if (!g.equals("")) { c.e("AndroidUtil", "MAC addr info---- " + g); return f.d(g.toLowerCase() + Build.MODEL); } } return null; } catch (Exception e) { c.c("AndroidUtil", "", e); return null; } } @SuppressLint({"MissingPermission"}) public static String k(Context context) { String str = ""; if (Build.VERSION.SDK_INT >= 23 || !c(context, "android.permission.ACCESS_WIFI_STATE")) { return str; } try { str = ((WifiManager) context.getApplicationContext().getSystemService("wifi")).getConnectionInfo().getMacAddress(); c.c("AndroidUtil", "mac address from WifiManager:" + str); return str; } catch (Exception e) { c.a("AndroidUtil", "get mac from wifiManager failed ", e); return str; } } /* JADX WARNING: Removed duplicated region for block: B:30:0x00af */ /* JADX WARNING: Removed duplicated region for block: B:39:? A[RETURN, SYNTHETIC] */ public static String l(Context context) { boolean z; Exception e; byte[] hardwareAddress; String str = ""; try { z = c(context, "android.permission.ACCESS_WIFI_STATE") ? ((WifiManager) context.getApplicationContext().getSystemService("wifi")).isWifiEnabled() : false; try { Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces(); while (true) { if (!networkInterfaces.hasMoreElements()) { break; } NetworkInterface nextElement = networkInterfaces.nextElement(); if ("wlan0".equalsIgnoreCase(nextElement.getName()) && (hardwareAddress = nextElement.getHardwareAddress()) != null) { if (hardwareAddress.length != 0) { StringBuilder sb = new StringBuilder(); for (byte b2 : hardwareAddress) { sb.append(String.format(Locale.ENGLISH, "%02x:", Byte.valueOf(b2))); } if (sb.length() > 0) { sb.deleteCharAt(sb.length() - 1); } str = sb.toString(); c.c("AndroidUtil", "mac address from NetworkInterface:" + str); } } } } catch (Exception e2) { e = e2; c.g("AndroidUtil", "get mac from NetworkInterface failed:" + e.getMessage()); if (z) { } } } catch (Exception e3) { e = e3; z = false; c.g("AndroidUtil", "get mac from NetworkInterface failed:" + e.getMessage()); if (z) { } } if (z) { return str; } c.c("AndroidUtil", "mac address is dropped, which is " + str); return ""; } public static boolean m(Context context) { String b2 = b(context, "ro.product.brand", ""); c.c("AndroidUtil", "brand = " + b2); String b3 = b(context, "ro.miui.ui.version.name", ""); if (TextUtils.isEmpty(b2) || !"Xiaomi".equals(b2) || TextUtils.isEmpty(b3)) { return true; } String b4 = b(context, "ro.build.version.incremental", ""); if (TextUtils.isEmpty(b4) || !b4.startsWith("V7.1")) { return true; } c.g("AndroidUtil", "7.1 will not get wifi list"); return false; } public static String n(Context context) { try { NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo(); if (activeNetworkInfo == null) { return "Unknown"; } String typeName = activeNetworkInfo.getTypeName(); String subtypeName = activeNetworkInfo.getSubtypeName(); if (typeName == null) { return "Unknown"; } if (f.a(subtypeName)) { return typeName; } return typeName + "," + subtypeName; } catch (Exception e) { e.printStackTrace(); return "Unknown"; } } public static String o(Context context) { String bssid; try { WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService("wifi"); return (wifiManager == null || !c(context, "android.permission.ACCESS_WIFI_STATE") || (bssid = wifiManager.getConnectionInfo().getBSSID()) == null || bssid.startsWith("02:00:00:")) ? "" : bssid; } catch (Throwable unused) { return ""; } } /* JADX WARNING: Removed duplicated region for block: B:20:0x0098 */ public static String p(Context context) { Throwable th; Object invoke; String str = null; int i = -1; if (context != null) { try { Object systemService = context.getApplicationContext().getSystemService("country_detector"); if (systemService != null) { Method declaredMethod = systemService.getClass().getDeclaredMethod("detectCountry", new Class[0]); if (!(declaredMethod == null || (invoke = declaredMethod.invoke(systemService, new Object[0])) == null)) { String str2 = (String) invoke.getClass().getDeclaredMethod("getCountryIso", new Class[0]).invoke(invoke, new Object[0]); try { i = ((Integer) invoke.getClass().getDeclaredMethod("getSource", new Class[0]).invoke(invoke, new Object[0])).intValue(); str = str2; } catch (Throwable th2) { th = th2; str = str2; c.i("AndroidUtil", "getCountryCode failed, error :" + th); c.c("AndroidUtil", "get CountCode = " + str + " source = " + i); if (i != 0) { } } } } else { c.c("AndroidUtil", "country_detector is null"); } } catch (Throwable th3) { th = th3; c.i("AndroidUtil", "getCountryCode failed, error :" + th); c.c("AndroidUtil", "get CountCode = " + str + " source = " + i); if (i != 0) { } } } c.c("AndroidUtil", "get CountCode = " + str + " source = " + i); return (i != 0 || i == 1) ? str : ""; } }