Search in sources :

Example 91 with WifiInfo

use of android.net.wifi.WifiInfo in project dobby-android by InceptAi.

the class WifiAnalyzer method processNetworkStateChangedIntent.

private void processNetworkStateChangedIntent(Intent intent) {
    final NetworkInfo networkInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
    if (networkInfo != null) {
        NetworkInfo.DetailedState detailedWifiState = networkInfo.getDetailedState();
        updateWifiStatsDetailedState(detailedWifiState);
    }
    boolean wasConnected = wifiConnected;
    wifiConnected = networkInfo != null && networkInfo.isConnected();
    //If no longer connected, clear the connection info
    if (!wifiConnected) {
        wifiState.clearWifiConnectionInfo();
    }
    // If we just connected, grab the initial signal strength and SSID
    if (wifiConnected && !wasConnected) {
        postToEventBus(DobbyEvent.EventType.WIFI_CONNECTED);
        // try getting it out of the intent first
        WifiInfo info = (WifiInfo) intent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO);
        updateWifiStatsWithWifiInfo(info);
        DhcpInfo dhcpInfo = getDhcpInfo();
        if (dhcpInfo != null && dhcpInfo.ipAddress != 0) {
            eventBus.postEvent(new DobbyEvent(DobbyEvent.EventType.DHCP_INFO_AVAILABLE));
        }
    } else if (!wifiConnected && wasConnected) {
        postToEventBus(DobbyEvent.EventType.WIFI_NOT_CONNECTED);
    } else {
        if (wifiConnected) {
            if (!publishedWifiState) {
                postToEventBus(DobbyEvent.EventType.WIFI_CONNECTED);
            }
            DobbyLog.v("No change in wifi state -- we were connected and are connected");
        } else {
            //So that we publish this event at least once
            if (!publishedWifiState) {
                postToEventBus(DobbyEvent.EventType.WIFI_NOT_CONNECTED);
            }
            DobbyLog.v("No change in wifi state -- we were NOT connected and are still NOT connected");
        }
    }
}
Also used : NetworkInfo(android.net.NetworkInfo) DhcpInfo(android.net.DhcpInfo) DobbyEvent(com.inceptai.dobby.eventbus.DobbyEvent) WifiInfo(android.net.wifi.WifiInfo) DobbyWifiInfo(com.inceptai.dobby.model.DobbyWifiInfo)

Example 92 with WifiInfo

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

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 93 with WifiInfo

use of android.net.wifi.WifiInfo in project LshUtils by SenhLinsh.

the class LshPhoneUtils method getIp.

/**
     * 获取ip地址
     */
public static String getIp() {
    Context context = LshApplicationUtils.getContext().getApplicationContext();
    //获取wifi服务
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    // 获取IP
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    int ipAddress = wifiInfo.getIpAddress();
    String ip = intToIp(ipAddress);
    String no_ip = "";
    if (no_ip.equals(ip)) {
        ip = "0.0.0.0";
    }
    return ip;
}
Also used : Context(android.content.Context) WifiManager(android.net.wifi.WifiManager) WifiInfo(android.net.wifi.WifiInfo)

Example 94 with WifiInfo

use of android.net.wifi.WifiInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ConfigureWifiSettings method refreshWifiInfo.

private void refreshWifiInfo() {
    final Context context = getActivity();
    WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
    Preference wifiMacAddressPref = findPreference(KEY_MAC_ADDRESS);
    String macAddress = wifiInfo == null ? null : wifiInfo.getMacAddress();
    wifiMacAddressPref.setSummary(!TextUtils.isEmpty(macAddress) ? macAddress : context.getString(R.string.status_unavailable));
    wifiMacAddressPref.setSelectable(false);
    Preference wifiIpAddressPref = findPreference(KEY_CURRENT_IP_ADDRESS);
    String ipAddress = Utils.getWifiIpAddresses(context);
    wifiIpAddressPref.setSummary(ipAddress == null ? context.getString(R.string.status_unavailable) : ipAddress);
    wifiIpAddressPref.setSelectable(false);
    // Wifi extension requirement
    Preference wifiGatewayPref = findPreference(KEY_CURRENT_GATEWAY);
    String gateway = null;
    Preference wifiNetmaskPref = findPreference(KEY_CURRENT_NETMASK);
    String netmask = null;
    if (getResources().getBoolean(R.bool.config_netinfo)) {
        DhcpInfo dhcpInfo = mWifiManager.getDhcpInfo();
        if (wifiInfo != null) {
            if (dhcpInfo != null) {
                gateway = Formatter.formatIpAddress(dhcpInfo.gateway);
                netmask = Formatter.formatIpAddress(dhcpInfo.netmask);
            }
        }
        if (wifiGatewayPref != null) {
            wifiGatewayPref.setSummary((gateway == null || dhcpInfo.gateway == 0) ? getString(R.string.status_unavailable) : gateway);
        }
        if (wifiNetmaskPref != null) {
            wifiNetmaskPref.setSummary((netmask == null || dhcpInfo.netmask == 0) ? getString(R.string.status_unavailable) : netmask);
        }
    } else {
        if (wifiGatewayPref != null) {
            getPreferenceScreen().removePreference(wifiGatewayPref);
        }
        if (wifiNetmaskPref != null) {
            getPreferenceScreen().removePreference(wifiNetmaskPref);
        }
    }
}
Also used : Context(android.content.Context) ListPreference(android.support.v7.preference.ListPreference) Preference(android.support.v7.preference.Preference) AppListSwitchPreference(com.android.settings.AppListSwitchPreference) SwitchPreference(android.support.v14.preference.SwitchPreference) DhcpInfo(android.net.DhcpInfo) WifiInfo(android.net.wifi.WifiInfo)

Example 95 with WifiInfo

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

the class WifiAssociationTest method testWifiAssociation.

/**
     * Test that the wifi can associate with a given access point.
     */
@LargeTest
public void testWifiAssociation() {
    WifiAssociationTestRunner runner = (WifiAssociationTestRunner) getInstrumentation();
    Bundle arguments = runner.getArguments();
    String ssid = arguments.getString("ssid");
    assertNotNull("ssid is empty", ssid);
    String securityTypeStr = arguments.getString("security-type");
    assertNotNull("security-type is empty", securityTypeStr);
    SecurityType securityType = SecurityType.valueOf(securityTypeStr);
    String password = arguments.getString("password");
    String freqStr = arguments.getString("frequency-band");
    if (freqStr != null) {
        setFrequencyBand(freqStr);
    }
    assertTrue("enable Wifi failed", enableWifi());
    WifiInfo wi = mWifiManager.getConnectionInfo();
    logv("%s", wi);
    assertNotNull("no active wifi info", wi);
    WifiConfiguration config = getConfig(ssid, securityType, password);
    logv("Network config: %s", config.toString());
    connectToWifi(config);
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration) Bundle(android.os.Bundle) WifiAssociationTestRunner(com.android.connectivitymanagertest.WifiAssociationTestRunner) WifiInfo(android.net.wifi.WifiInfo) LargeTest(android.test.suitebuilder.annotation.LargeTest)

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