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");
}
}
}
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;
}
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;
}
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);
}
}
}
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);
}
Aggregations