Android Open Source - Android-Wireless Wifi A P






From Project

Back to project page Android-Wireless.

License

The source code is released under:

MIT License

If you think the Android project Android-Wireless listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.Nimble.WifiAP;
/*from w ww. j  ava 2 s  .c o m*/
import generics.Methods;
import android.content.Context;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.util.Log;

/**
 * A Class for generating a new wifi ap network.
 *  @author Michael Leith
 */
public class WifiAP {
  
  /** Set the wifi authorisation status.
   *@param config
   *@param status the authorization algorithm to be used. Possible values below:
   *@value WifiConfiguration.AuthAlgorithm.LEAP,
   *@value WifiConfiguration.AuthAlgorithm.OPEN, 
   *@value WifiConfiguration.AuthAlgorithm.SHARED
   */
  static public final void setWifiAuthorisationStatus(WifiConfiguration config, int status) 
  { config.allowedAuthAlgorithms.set(status); }

  /** Set the networks name (SSID)
   * 
   * @param config
   * @param name
   */
  static public final void setWifiApName(WifiConfiguration config, String name)
  { config.SSID = name; }

  /** Should allow for network blocking. Not tested.
   * 
   * @param config
   * @param status
   */
  static public final void NetworkAccessStatus(WifiConfiguration config, boolean status)
  { config.status = status ? WifiConfiguration.Status.ENABLED : WifiConfiguration.Status.DISABLED; }


  
  /**
   * Explain later, gtg :P
   * @param manager
   * @param config
   * @param state
   * @return True if successfull.
   */
  static final public boolean setWifiApEnabled(WifiManager manager, WifiConfiguration config, boolean state)
  {
    try{
      return (Methods.getMethodByName(manager, "setWifiApEnabled").invoke(manager, config, state) != null);
    }
    catch( Exception e)
    {
      Log.e("setWifiApEnabled", e.getMessage());
      return false;
    }
  }
  
  /**
   * Explain later, gtg :P
   * @param manager
   * @param config
   * @return True if successful
   */
  static final public boolean setWifiApConfig(WifiManager manager, WifiConfiguration config)
  {
    try{
      return(Methods.getMethodByName(manager, "setWifiApConfiguration").invoke(manager, config) != null);
    }
    catch (Exception e)
    {
      Log.e("setWifiApConfig", e.getMessage());
      return false;
    }
  }
  
  /** 
   * 
   * @param manager
   * @return An instance of the method "getWifiApConfiguration"
   */
  static final public WifiConfiguration getWifiConfig(WifiManager manager)
  {
    try{
      return (WifiConfiguration) Methods.getMethodByName(manager, "getWifiApConfiguration").
          invoke(manager, (Object[]) null);
    }
    catch (Exception e)
    {
      Log.e("getWifiConfig", e.getMessage());
      return null;
    }
  }
  
  /** 
   * Generates default network settings -> SSID = "TextNetwork", AuthAlgorithm = OPEN.
   * Disables WiFi, bluetooth, data.
   * @param manager
   * @param context
   */
  static public final WifiConfiguration generateDefaultWifiApNetworkSettings(WifiManager manager, Context context)
  {
    HardwareStateManager.disableAll(manager, context); 
    //setWifiState(manager, false);
    
    WifiConfiguration config = getWifiConfig(manager);
    setWifiApName(config, "TestNetwork");
    setWifiAuthorisationStatus(config, WifiConfiguration.AuthAlgorithm.OPEN); //For WPA/WPA2
    return config;
  }
}




Java Source Code List

com.Nimble.Server.ServerActivity.java
com.Nimble.Server.Server.java
com.Nimble.Server.Sockets.java
com.Nimble.WifiAP.ClientInfo.java
com.Nimble.WifiAP.ClientScanner.java
com.Nimble.WifiAP.HardwareStateManager.java
com.Nimble.WifiAP.MainWiFiAPActivity.java
com.Nimble.WifiAP.WifiAP.java
com.Nimble.WifiAP.scanActivity.java
generics.Methods.java
generics.testingSuite.java