Ejemplo n.º 1
0
 private static void checkCodePathSupport() throws DeviceNotSupportedException {
   if (SystemUtils.isAndroidVersionOrLower(Build.VERSION_CODES.FROYO)) {
     try {
       System.loadLibrary("andengine");
     } catch (final UnsatisfiedLinkError e) {
       throw new DeviceNotSupportedException(DeviceNotSupportedCause.CODEPATH_INCOMPLETE, e);
     }
   }
 }
Ejemplo n.º 2
0
 /**
  * The check currently performed is not sufficient, as some carriers disabled this feature
  * manually!
  */
 public static boolean isWifiHotspotSupported(final Context pContext) {
   if (SystemUtils.isAndroidVersionOrLower(Build.VERSION_CODES.ECLAIR_MR1)) {
     return false;
   } else {
     final WifiManager wifiManager = WifiUtils.getWifiManager(pContext);
     try {
       final Method WifiManager_isWifiApEnabled =
           wifiManager.getClass().getMethod("isWifiApEnabled");
       return WifiManager_isWifiApEnabled != null;
     } catch (final Throwable t) {
       return false;
     }
   }
 }
Ejemplo n.º 3
0
  /**
   * @return prefers to return an IPv4 address if found, otherwise an IPv6 address.
   * @throws org.andengine.util.WifiUtils.WifiUtilsException
   */
  @TargetApi(Build.VERSION_CODES.GINGERBREAD)
  public static byte[] getWifiHotspotIPAddressRaw() throws WifiUtilsException {
    try {
      byte[] ipv6Address = null;

      final Enumeration<NetworkInterface> networkInterfaceEnumeration =
          NetworkInterface.getNetworkInterfaces();
      while (networkInterfaceEnumeration.hasMoreElements()) {
        final NetworkInterface networkInterface = networkInterfaceEnumeration.nextElement();
        if (SystemUtils.isAndroidVersionOrLower(Build.VERSION_CODES.FROYO)
            || !networkInterface.isLoopback()) {
          final String networkInterfaceName = networkInterface.getName();

          if (ArrayUtils.contains(WifiUtils.HOTSPOT_NETWORKINTERFACE_NAMES, networkInterfaceName)) {
            final Enumeration<InetAddress> inetAddressEnumeration =
                networkInterface.getInetAddresses();
            while (inetAddressEnumeration.hasMoreElements()) {
              final InetAddress inetAddress = inetAddressEnumeration.nextElement();
              if (!inetAddress.isLoopbackAddress()) {
                final byte[] ipAddress = inetAddress.getAddress();
                if (ipAddress.length == IPUtils.IPV4_LENGTH) {
                  return ipAddress;
                } else {
                  ipv6Address = ipAddress;
                }
              }
            }
          }
        }
      }

      if (ipv6Address != null) {
        return ipv6Address;
      } else {
        throw new WifiUtilsException(
            "No IP bound to '" + Arrays.toString(WifiUtils.HOTSPOT_NETWORKINTERFACE_NAMES) + "'!");
      }
    } catch (final SocketException e) {
      throw new WifiUtilsException("Unexpected error!", e);
    }
  }
Ejemplo n.º 4
0
  @TargetApi(Build.VERSION_CODES.GINGERBREAD)
  public static byte[] getEmulatorIPAddressRaw() throws WifiUtilsException {
    try {
      byte[] ipv6Address = null;

      final Enumeration<NetworkInterface> networkInterfaceEnumeration =
          NetworkInterface.getNetworkInterfaces();
      while (networkInterfaceEnumeration.hasMoreElements()) {
        final NetworkInterface networkInterface = networkInterfaceEnumeration.nextElement();
        if (SystemUtils.isAndroidVersionOrLower(Build.VERSION_CODES.FROYO)
            || !networkInterface.isLoopback()) {
          final Enumeration<InetAddress> inetAddressEnumeration =
              networkInterface.getInetAddresses();
          while (inetAddressEnumeration.hasMoreElements()) {
            final InetAddress inetAddress = inetAddressEnumeration.nextElement();
            if (!inetAddress.isLoopbackAddress()) {
              final byte[] ipAddress = inetAddress.getAddress();
              if (ipAddress.length == IPUtils.IPV4_LENGTH) {
                return ipAddress;
              } else {
                ipv6Address = ipAddress;
              }
            }
          }
        }
      }

      if (ipv6Address != null) {
        return ipv6Address;
      } else {
        throw new WifiUtilsException("No IP found that is not bound to localhost!");
      }
    } catch (final SocketException e) {
      throw new WifiUtilsException("Unexpected error!", e);
    }
  }