use of android.net.wifi.WifiManager in project FileExplorer by MiCode.
the class FTPServerService method getWifiIp.
/**
* Gets the IP address of the wifi connection.
*
* @return The integer IP address if wifi enabled, or null if not.
*/
public static InetAddress getWifiIp() {
Context myContext = Globals.getContext();
if (myContext == null) {
throw new NullPointerException("Global context is null");
}
WifiManager wifiMgr = (WifiManager) myContext.getSystemService(Context.WIFI_SERVICE);
if (isWifiEnabled()) {
int ipAsInt = wifiMgr.getConnectionInfo().getIpAddress();
if (ipAsInt == 0) {
return null;
} else {
return Util.intToInet(ipAsInt);
}
} else {
return null;
}
}
use of android.net.wifi.WifiManager in project android_frameworks_base by ParanoidAndroid.
the class WifiAssociationTestRunner method setFrequencyBand.
private void setFrequencyBand(String band) {
WifiManager mWifiManager = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
if (band.equals("2.4")) {
Log.v(TAG, "set frequency band to 2.4");
mBand = WifiManager.WIFI_FREQUENCY_BAND_2GHZ;
} else if (band.equals("5.0")) {
Log.v(TAG, "set frequency band to 5.0");
mBand = WifiManager.WIFI_FREQUENCY_BAND_5GHZ;
} else if (band.equals("auto")) {
Log.v(TAG, "set frequency band to auto");
mBand = WifiManager.WIFI_FREQUENCY_BAND_AUTO;
} else {
Assert.fail("invalid frequency band");
}
int currentFreq = mWifiManager.getFrequencyBand();
if (mBand == currentFreq) {
Log.v(TAG, "frequency band has been set");
return;
}
mWifiManager.setFrequencyBand(mBand, true);
}
use of android.net.wifi.WifiManager in project android_frameworks_base by ParanoidAndroid.
the class DownloadManagerBaseTest method setWiFiStateOn.
/**
* Enables or disables WiFi.
*
* Note: Needs the following permissions:
* android.permission.ACCESS_WIFI_STATE
* android.permission.CHANGE_WIFI_STATE
* @param enable true if it should be enabled, false if it should be disabled
*/
protected void setWiFiStateOn(boolean enable) throws Exception {
Log.i(LOG_TAG, "Setting WiFi State to: " + enable);
WifiManager manager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
manager.setWifiEnabled(enable);
String timeoutMessage = "Timed out waiting for Wifi to be " + (enable ? "enabled!" : "disabled!");
WiFiChangedReceiver receiver = new WiFiChangedReceiver(mContext);
mContext.registerReceiver(receiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
synchronized (receiver) {
long timeoutTime = SystemClock.elapsedRealtime() + DEFAULT_MAX_WAIT_TIME;
boolean timedOut = false;
while (receiver.getWiFiIsOn() != enable && !timedOut) {
try {
receiver.wait(DEFAULT_WAIT_POLL_TIME);
if (SystemClock.elapsedRealtime() > timeoutTime) {
timedOut = true;
}
} catch (InterruptedException e) {
// ignore InterruptedExceptions
}
}
if (timedOut) {
fail(timeoutMessage);
}
}
assertEquals(enable, receiver.getWiFiIsOn());
}
use of android.net.wifi.WifiManager in project android_frameworks_base by ParanoidAndroid.
the class DownloadManagerBaseTest method setWiFiStateOn.
/**
* Enables or disables WiFi.
*
* Note: Needs the following permissions:
* android.permission.ACCESS_WIFI_STATE
* android.permission.CHANGE_WIFI_STATE
* @param enable true if it should be enabled, false if it should be disabled
*/
protected void setWiFiStateOn(boolean enable) throws Exception {
Log.i(LOG_TAG, "Setting WiFi State to: " + enable);
WifiManager manager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
manager.setWifiEnabled(enable);
String timeoutMessage = "Timed out waiting for Wifi to be " + (enable ? "enabled!" : "disabled!");
WiFiChangedReceiver receiver = new WiFiChangedReceiver(mContext);
mContext.registerReceiver(receiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
synchronized (receiver) {
long timeoutTime = SystemClock.elapsedRealtime() + DEFAULT_MAX_WAIT_TIME;
boolean timedOut = false;
while (receiver.getWiFiIsOn() != enable && !timedOut) {
try {
receiver.wait(DEFAULT_WAIT_POLL_TIME);
if (SystemClock.elapsedRealtime() > timeoutTime) {
timedOut = true;
}
} catch (InterruptedException e) {
// ignore InterruptedExceptions
}
}
if (timedOut) {
fail(timeoutMessage);
}
}
assertEquals(enable, receiver.getWiFiIsOn());
}
use of android.net.wifi.WifiManager in project android_frameworks_base by ParanoidAndroid.
the class SettingsBackupAgent method onCreate.
@Override
public void onCreate() {
if (DEBUG_BACKUP)
Log.d(TAG, "onCreate() invoked");
mSettingsHelper = new SettingsHelper(this);
super.onCreate();
WifiManager mWfm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
if (mWfm != null)
mWifiConfigFile = mWfm.getConfigFile();
}
Aggregations