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:
Amith Yamasani
2011-10-17 16:41:00 -07:00
parent 68da83649e
commit 6822b749bb
2 changed files with 26 additions and 5 deletions

View File

@@ -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