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
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index ac6cb64..f28500e 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -306,6 +306,23 @@
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