Search in sources :

Example 66 with WifiInfo

use of android.net.wifi.WifiInfo in project platform_frameworks_base by android.

the class WifiNetworkAdapter method getActiveWifiConfig.

public WifiConfiguration getActiveWifiConfig() {
    WifiInfo wifiInfo = getConnectionInfo();
    if (wifiInfo == null) {
        return null;
    }
    WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
    for (WifiConfiguration config : wifiManager.getConfiguredNetworks()) {
        if (config.networkId == wifiInfo.getNetworkId()) {
            return config;
        }
    }
    return null;
}
Also used : WifiManager(android.net.wifi.WifiManager) WifiConfiguration(android.net.wifi.WifiConfiguration) WifiInfo(android.net.wifi.WifiInfo)

Example 67 with WifiInfo

use of android.net.wifi.WifiInfo in project platform_frameworks_base by android.

the class OSUManager method wnmRemediate.

// !!! Consistently check passpoint match.
// !!! Convert to a one-thread thread-pool
public void wnmRemediate(long bssid, String url, PasspointMatch match) throws IOException, SAXException {
    WifiConfiguration config = mWifiNetworkAdapter.getActiveWifiConfig();
    HomeSP homeSP = MOManager.buildSP(config.getMoTree());
    if (homeSP == null) {
        throw new IOException("Remediation request for unidentified Passpoint network " + config.networkId);
    }
    Network network = mWifiNetworkAdapter.getCurrentNetwork();
    if (network == null) {
        throw new IOException("Failed to determine current network");
    }
    WifiInfo wifiInfo = mWifiNetworkAdapter.getConnectionInfo();
    if (wifiInfo == null || Utils.parseMac(wifiInfo.getBSSID()) != bssid) {
        throw new IOException("Mismatching BSSID");
    }
    Log.d(TAG, "WNM Remediation on " + network.netId + " FQDN " + homeSP.getFQDN());
    doRemediate(url, network, homeSP, false);
}
Also used : HomeSP(com.android.hotspot2.pps.HomeSP) WifiConfiguration(android.net.wifi.WifiConfiguration) Network(android.net.Network) IOException(java.io.IOException) WifiInfo(android.net.wifi.WifiInfo)

Example 68 with WifiInfo

use of android.net.wifi.WifiInfo in project platform_frameworks_base by android.

the class NetworkControllerWifiTest method setWifiState.

protected void setWifiState(boolean connected, String ssid) {
    Intent i = new Intent(WifiManager.NETWORK_STATE_CHANGED_ACTION);
    NetworkInfo networkInfo = Mockito.mock(NetworkInfo.class);
    Mockito.when(networkInfo.isConnected()).thenReturn(connected);
    WifiInfo wifiInfo = Mockito.mock(WifiInfo.class);
    Mockito.when(wifiInfo.getSSID()).thenReturn(ssid);
    i.putExtra(WifiManager.EXTRA_NETWORK_INFO, networkInfo);
    i.putExtra(WifiManager.EXTRA_WIFI_INFO, wifiInfo);
    mNetworkController.onReceive(mContext, i);
}
Also used : NetworkInfo(android.net.NetworkInfo) Intent(android.content.Intent) WifiInfo(android.net.wifi.WifiInfo)

Example 69 with WifiInfo

use of android.net.wifi.WifiInfo in project android_frameworks_base by DirtyUnicorns.

the class NetworkControllerWifiTest method setWifiState.

protected void setWifiState(boolean connected, String ssid) {
    Intent i = new Intent(WifiManager.NETWORK_STATE_CHANGED_ACTION);
    NetworkInfo networkInfo = Mockito.mock(NetworkInfo.class);
    Mockito.when(networkInfo.isConnected()).thenReturn(connected);
    WifiInfo wifiInfo = Mockito.mock(WifiInfo.class);
    Mockito.when(wifiInfo.getSSID()).thenReturn(ssid);
    i.putExtra(WifiManager.EXTRA_NETWORK_INFO, networkInfo);
    i.putExtra(WifiManager.EXTRA_WIFI_INFO, wifiInfo);
    mNetworkController.onReceive(mContext, i);
}
Also used : NetworkInfo(android.net.NetworkInfo) Intent(android.content.Intent) WifiInfo(android.net.wifi.WifiInfo)

Example 70 with WifiInfo

use of android.net.wifi.WifiInfo in project AntennaPod by AntennaPod.

the class NetworkUtils method autodownloadNetworkAvailable.

/**
	 * Returns true if the device is connected to Wi-Fi and the Wi-Fi filter for
	 * automatic downloads is disabled or the device is connected to a Wi-Fi
	 * network that is on the 'selected networks' list of the Wi-Fi filter for
	 * automatic downloads and false otherwise.
	 * */
public static boolean autodownloadNetworkAvailable() {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    if (networkInfo != null) {
        if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
            Log.d(TAG, "Device is connected to Wi-Fi");
            if (networkInfo.isConnected()) {
                if (!UserPreferences.isEnableAutodownloadWifiFilter()) {
                    Log.d(TAG, "Auto-dl filter is disabled");
                    return true;
                } else {
                    WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
                    WifiInfo wifiInfo = wm.getConnectionInfo();
                    List<String> selectedNetworks = Arrays.asList(UserPreferences.getAutodownloadSelectedNetworks());
                    if (selectedNetworks.contains(Integer.toString(wifiInfo.getNetworkId()))) {
                        Log.d(TAG, "Current network is on the selected networks list");
                        return true;
                    }
                }
            }
        }
    }
    Log.d(TAG, "Network for auto-dl is not available");
    return false;
}
Also used : WifiManager(android.net.wifi.WifiManager) NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager) WifiInfo(android.net.wifi.WifiInfo)

Aggregations

WifiInfo (android.net.wifi.WifiInfo)99 WifiManager (android.net.wifi.WifiManager)53 WifiConfiguration (android.net.wifi.WifiConfiguration)16 NetworkInfo (android.net.NetworkInfo)13 Intent (android.content.Intent)11 IOException (java.io.IOException)8 Test (org.junit.Test)8 Bundle (android.os.Bundle)7 ScanResult (android.net.wifi.ScanResult)6 WifiAssociationTestRunner (com.android.connectivitymanagertest.WifiAssociationTestRunner)6 PendingIntent (android.app.PendingIntent)5 ConnectivityManager (android.net.ConnectivityManager)5 Network (android.net.Network)5 CellIdentityCdma (android.telephony.CellIdentityCdma)5 CellIdentityGsm (android.telephony.CellIdentityGsm)5 CellIdentityLte (android.telephony.CellIdentityLte)5 CellIdentityWcdma (android.telephony.CellIdentityWcdma)5 CellInfo (android.telephony.CellInfo)5 CellInfoCdma (android.telephony.CellInfoCdma)5 CellInfoGsm (android.telephony.CellInfoGsm)5