Android Open Source - Android-Wireless Hardware State Manager






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 w  w  . j a v  a  2 s  .  c  om*/
import android.bluetooth.BluetoothAdapter;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.provider.Settings;
import android.util.Log;

public class HardwareStateManager 
{
  private static boolean initialWiFi = false, initialBluetooth = false; //2G and 4G???
  /**
   * Change the current state of the wifi connection.
   * @param manager
   * @param state true turns wifi on, false turns it off.
   */
  static public final void setWifiState(WifiManager manager, boolean state)
  {
    if( manager.isWifiEnabled() == !state)
    {
      initialWiFi = !state;
      manager.setWifiEnabled(state);
    }
  }
  
  static public final void setBluetoothState(boolean state)
  {
    BluetoothAdapter adaptor = BluetoothAdapter.getDefaultAdapter();
    if (adaptor == null) { return; } //No bluetooth support

    initialBluetooth = adaptor.isEnabled();
    if(state)
      adaptor.enable();
    else
      adaptor.disable();
    Log.e("bluetooth", Boolean.toString(getInitialBluetoothState()));
  }
  
  static public final void setDataState(Context context)
  {
    try
    {  
      Intent intent=new Intent(Settings.ACTION_DATA_ROAMING_SETTINGS);
      ComponentName cn = new ComponentName("com.android.phone","com.android.phone.Settings");
      intent.setComponent(cn);
      context.startActivity(intent);
    }
    catch(Exception e)
    {
      Log.e("Data", "Not found");
    }
  }
  
  static public final boolean getInitialWiFiState() { return initialWiFi; }
  
  
  static public final boolean getInitialBluetoothState() { return initialBluetooth; }
  
  static public final void disableAll(WifiManager manager, Context context)
  {
    setBluetoothState(false);
    setWifiState(manager, false);
    setDataState(context); // Make optional.
  }
  
  /**
   * Disables WifiAp. Restores the phones settings prior to the app starting.
   * @param manager
   */
  static public final void restore(WifiManager manager, Context context)
  {
    WifiAP.setWifiApEnabled(manager, null, false);
    
    if(getInitialWiFiState())
       manager.setWifiEnabled(true);
    Log.e("bluetooth", Boolean.toString(getInitialBluetoothState()));
    if(getInitialBluetoothState())
      BluetoothAdapter.getDefaultAdapter().enable();
  }
}




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