Пример #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);
     }
   }
 }
Пример #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;
     }
   }
 }
Пример #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);
    }
  }
Пример #4
0
 public static WifiHotspotState fromWifiApState(final int pWifiApState)
     throws WifiUtilsException {
   if (SystemUtils.isAndroidVersionOrHigher(Build.VERSION_CODES.ICE_CREAM_SANDWICH)) {
     switch (pWifiApState) {
       case 10:
         return DISABLING;
       case 11:
         return DISABLED;
       case 12:
         return ENABLING;
       case 13:
         return ENABLED;
       case 14:
         return FAILED;
       default:
         throw new WifiUtilsException("TODO...");
     }
   } else {
     switch (pWifiApState) {
       case 0:
         return DISABLING;
       case 1:
         return DISABLED;
       case 2:
         return ENABLING;
       case 3:
         return ENABLED;
       case 4:
         return FAILED;
       default:
         if (pWifiApState >= 10) {
           return WifiHotspotState.fromWifiApState(pWifiApState - 10);
         } else {
           throw new WifiUtilsException("TODO...");
         }
     }
   }
 }
Пример #5
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);
    }
  }