Search in sources :

Example 1 with WifiManager

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());
}
Also used : WifiManager(android.net.wifi.WifiManager) ConnectivityManager(android.net.ConnectivityManager) InputMethodManager(android.view.inputmethod.InputMethodManager) ActivityManager(android.app.ActivityManager) WindowManager(android.view.WindowManager) PowerManager(android.os.PowerManager) AudioManager(android.media.AudioManager) StateManager(proton.inject.state.StateManager) TelephonyManager(android.telephony.TelephonyManager) Context(android.content.Context) LocationManager(android.location.LocationManager) ApplicationProvider(proton.inject.provider.ApplicationProvider) NotificationManager(android.app.NotificationManager) HandlerProvider(proton.inject.provider.HandlerProvider) RetainStateListener(proton.inject.state.RetainStateListener) SensorManager(android.hardware.SensorManager) AlarmManager(android.app.AlarmManager) Vibrator(android.os.Vibrator) KeyguardManager(android.app.KeyguardManager) ObserverRegister(proton.inject.observer.ObserverRegister)

Example 2 with WifiManager

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);
}
Also used : WifiManager(android.net.wifi.WifiManager)

Example 3 with WifiManager

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());
}
Also used : WifiManager(android.net.wifi.WifiManager) IntentFilter(android.content.IntentFilter)

Example 4 with WifiManager

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());
}
Also used : WifiManager(android.net.wifi.WifiManager) IntentFilter(android.content.IntentFilter)

Example 5 with WifiManager

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();
}
Also used : WifiManager(android.net.wifi.WifiManager)

Aggregations

WifiManager (android.net.wifi.WifiManager)335 WifiInfo (android.net.wifi.WifiInfo)84 WifiConfiguration (android.net.wifi.WifiConfiguration)76 IOException (java.io.IOException)38 Intent (android.content.Intent)27 SuppressLint (android.annotation.SuppressLint)26 Context (android.content.Context)23 ConnectivityManager (android.net.ConnectivityManager)23 NetworkInfo (android.net.NetworkInfo)21 Test (org.junit.Test)20 AccessPoint (com.android.settingslib.wifi.AccessPoint)17 ArrayList (java.util.ArrayList)17 IntentFilter (android.content.IntentFilter)16 Bundle (android.os.Bundle)16 NetworkPolicyEditor (com.android.settingslib.NetworkPolicyEditor)12 PowerManager (android.os.PowerManager)11 WifiEnterpriseConfig (android.net.wifi.WifiEnterpriseConfig)10 SocketException (java.net.SocketException)10 Activity (android.app.Activity)9 SharedPreferences (android.content.SharedPreferences)9