use of android.net.wifi.WifiManager in project AndroidTraining by mixi-inc.
the class DefaultModule method configure.
@SuppressWarnings("unchecked")
protected void configure() {
bind(Application.class).toProvider(ApplicationProvider.class).in(ApplicationScoped.class);
bind(Context.class).toProvider(ContextProvider.class);
bind(Handler.class).toProvider(HandlerProvider.class).in(ApplicationScoped.class);
bind(ActivityManager.class).toProvider(new SystemServiceProvider<ActivityManager>(Context.ACTIVITY_SERVICE));
bind(AlarmManager.class).toProvider(new SystemServiceProvider<AlarmManager>(Context.ALARM_SERVICE));
bind(AudioManager.class).toProvider(new SystemServiceProvider<AudioManager>(Context.AUDIO_SERVICE));
bind(ConnectivityManager.class).toProvider(new SystemServiceProvider<ConnectivityManager>(Context.CONNECTIVITY_SERVICE));
bind(InputMethodManager.class).toProvider(new SystemServiceProvider<InputMethodManager>(Context.INPUT_METHOD_SERVICE));
bind(KeyguardManager.class).toProvider(new SystemServiceProvider<KeyguardManager>(Context.KEYGUARD_SERVICE));
bind(LocationManager.class).toProvider(new SystemServiceProvider<LocationManager>(Context.LOCATION_SERVICE));
bind(NotificationManager.class).toProvider(new SystemServiceProvider<NotificationManager>(Context.NOTIFICATION_SERVICE));
bind(PowerManager.class).toProvider(new SystemServiceProvider<PowerManager>(Context.POWER_SERVICE));
bind(SensorManager.class).toProvider(new SystemServiceProvider<SensorManager>(Context.SENSOR_SERVICE));
bind(TelephonyManager.class).toProvider(new SystemServiceProvider<TelephonyManager>(Context.TELEPHONY_SERVICE));
bind(Vibrator.class).toProvider(new SystemServiceProvider<Vibrator>(Context.VIBRATOR_SERVICE));
bind(WifiManager.class).toProvider(new SystemServiceProvider<WifiManager>(Context.WIFI_SERVICE));
bind(WindowManager.class).toProvider(new SystemServiceProvider<WindowManager>(Context.WINDOW_SERVICE));
bind(mAccountManagerClass).toProvider(AccountManagerProvider.class);
bind(ObserverManager.class);
bindProviderListener(new ObserverRegister());
bind(StateManager.class).in(ApplicationScoped.class);
bind(StateEventObserver.class);
bindFieldListener(RetainState.class, new RetainStateListener());
}
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