package com.nirvana.tools.core; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.Build; import android.provider.Settings; import android.telephony.TelephonyManager; import android.util.Log; import java.lang.reflect.Method; import java.net.Inet4Address; import java.net.InetAddress; import java.net.NetworkInterface; import java.util.Enumeration; public class NetworkUtils { public static String getLocalIPAddress() { 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) { Log.e("NetworkUtils", e.getMessage()); return ""; } } public static boolean hasSimCard(Context context) { return ((TelephonyManager) context.getSystemService("phone")).getSimState() == 5; } /* JADX WARNING: Removed duplicated region for block: B:7:0x0014 A[RETURN, SYNTHETIC] */ public static boolean isAirModeEnable(Context context) { try { if (Build.VERSION.SDK_INT < 17) { return Settings.System.getInt(context.getContentResolver(), "airplane_mode_on", 0) == 1; } if (Settings.Global.getInt(context.getContentResolver(), "airplane_mode_on", 0) != 1) { return false; } } catch (Throwable th) { Log.e("NetworkUtils", th.getMessage()); return false; } } public static boolean isMobileNetConnected(Context context) { NetworkInfo networkInfo; return context != null && (networkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getNetworkInfo(0)) != null && networkInfo.isAvailable() && networkInfo.isConnected(); } public static boolean isMobileNetworkOpen(Context context) { if (!hasSimCard(context) || isAirModeEnable(context)) { return false; } if (isMobileNetConnected(context)) { return true; } try { Method declaredMethod = ConnectivityManager.class.getDeclaredMethod("getMobileDataEnabled", new Class[0]); declaredMethod.setAccessible(true); return ((Boolean) declaredMethod.invoke((ConnectivityManager) context.getApplicationContext().getSystemService("connectivity"), new Object[0])).booleanValue(); } catch (Exception e) { Log.e("NetworkUtils", e.getMessage()); return true; } } }