Show IP address of current active link instead of just the WiFi IP address.
Bug: 5359194 Show "Unavailable" only if there's no active link. Change-Id: I82ba6bda3a08ea84080a8d8cda331f22d7c7a2bd
This commit is contained in:
@@ -306,6 +306,23 @@ public class Utils {
|
||||
ConnectivityManager cm = (ConnectivityManager)
|
||||
context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
LinkProperties prop = cm.getLinkProperties(ConnectivityManager.TYPE_WIFI);
|
||||
return formatIpAddresses(prop);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default link's IP addresses, if any, taking into account IPv4 and IPv6 style
|
||||
* addresses.
|
||||
* @param context the application context
|
||||
* @return the formatted and comma-separated IP addresses, or null if none.
|
||||
*/
|
||||
public static String getDefaultIpAddresses(Context context) {
|
||||
ConnectivityManager cm = (ConnectivityManager)
|
||||
context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
LinkProperties prop = cm.getActiveLinkProperties();
|
||||
return formatIpAddresses(prop);
|
||||
}
|
||||
|
||||
private static String formatIpAddresses(LinkProperties prop) {
|
||||
if (prop == null) return null;
|
||||
Iterator<InetAddress> iter = prop.getAddresses().iterator();
|
||||
// If there are no entries, return null
|
||||
|
@@ -78,7 +78,7 @@ public class Status extends PreferenceActivity {
|
||||
private static final String KEY_SIGNAL_STRENGTH = "signal_strength";
|
||||
private static final String KEY_BATTERY_STATUS = "battery_status";
|
||||
private static final String KEY_BATTERY_LEVEL = "battery_level";
|
||||
private static final String KEY_WIFI_IP_ADDRESS = "wifi_ip_address";
|
||||
private static final String KEY_IP_ADDRESS = "wifi_ip_address";
|
||||
private static final String KEY_WIFI_MAC_ADDRESS = "wifi_mac_address";
|
||||
private static final String KEY_BT_ADDRESS = "bt_address";
|
||||
private static final String KEY_SERIAL_NUMBER = "serial_number";
|
||||
@@ -250,6 +250,7 @@ public class Status extends PreferenceActivity {
|
||||
|
||||
setWifiStatus();
|
||||
setBtStatus();
|
||||
setIpAddressStatus();
|
||||
|
||||
String serial = Build.SERIAL;
|
||||
if (serial != null && !serial.equals("")) {
|
||||
@@ -413,16 +414,19 @@ public class Status extends PreferenceActivity {
|
||||
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
||||
|
||||
Preference wifiMacAddressPref = findPreference(KEY_WIFI_MAC_ADDRESS);
|
||||
|
||||
String macAddress = wifiInfo == null ? null : wifiInfo.getMacAddress();
|
||||
wifiMacAddressPref.setSummary(!TextUtils.isEmpty(macAddress) ? macAddress
|
||||
: getString(R.string.status_unavailable));
|
||||
}
|
||||
|
||||
Preference wifiIpAddressPref = findPreference(KEY_WIFI_IP_ADDRESS);
|
||||
String ipAddress = Utils.getWifiIpAddresses(this);
|
||||
private void setIpAddressStatus() {
|
||||
Preference ipAddressPref = findPreference(KEY_IP_ADDRESS);
|
||||
String ipAddress = Utils.getDefaultIpAddresses(this);
|
||||
if (ipAddress != null) {
|
||||
wifiIpAddressPref.setSummary(ipAddress);
|
||||
ipAddressPref.setSummary(ipAddress);
|
||||
} else {
|
||||
wifiIpAddressPref.setSummary(getString(R.string.status_unavailable));
|
||||
ipAddressPref.setSummary(getString(R.string.status_unavailable));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user