Search in sources :

Example 41 with WifiManager

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

Example 42 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 43 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 44 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 45 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)169 WifiInfo (android.net.wifi.WifiInfo)53 WifiConfiguration (android.net.wifi.WifiConfiguration)42 IOException (java.io.IOException)24 IntentFilter (android.content.IntentFilter)13 WifiEnterpriseConfig (android.net.wifi.WifiEnterpriseConfig)10 Context (android.content.Context)9 ConnectivityManager (android.net.ConnectivityManager)8 NetworkInfo (android.net.NetworkInfo)8 Test (org.junit.Test)8 Intent (android.content.Intent)7 File (java.io.File)6 SAXException (org.xml.sax.SAXException)6 SharedPreferences (android.content.SharedPreferences)5 PowerManager (android.os.PowerManager)5 TelephonyManager (android.telephony.TelephonyManager)5 X509Certificate (java.security.cert.X509Certificate)5 BufferedReader (java.io.BufferedReader)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 FileReader (java.io.FileReader)4