Fixes how we read the current WiFi network IP address.

The old logic could read the current IP address only when the network has the
Internet access.

Bug: 31934577
Test: Manual inspection
Test: make RunSettingsRoboTests -j40

Change-Id: I46fe6f6fb4322e8245d3ac66ac6530228c226d16
This commit is contained in:
Jaewoong Jung
2016-10-13 14:21:52 -07:00
parent ab50807d1e
commit c260e6dc87
2 changed files with 79 additions and 3 deletions

View File

@@ -47,7 +47,9 @@ import android.graphics.BitmapFactory;
import android.hardware.fingerprint.FingerprintManager;
import android.net.ConnectivityManager;
import android.net.LinkProperties;
import android.net.Network;
import android.net.Uri;
import android.net.wifi.WifiManager;
import android.os.BatteryManager;
import android.os.Bundle;
import android.os.IBinder;
@@ -235,10 +237,15 @@ public final class Utils extends com.android.settingslib.Utils {
* @return the formatted and newline-separated IP addresses, or null if none.
*/
public static String getWifiIpAddresses(Context context) {
ConnectivityManager cm = (ConnectivityManager)
WifiManager wifiManager = context.getSystemService(WifiManager.class);
Network currentNetwork = wifiManager.getCurrentNetwork();
if (currentNetwork != null) {
ConnectivityManager cm = (ConnectivityManager)
context.getSystemService(Context.CONNECTIVITY_SERVICE);
LinkProperties prop = cm.getLinkProperties(ConnectivityManager.TYPE_WIFI);
return formatIpAddresses(prop);
LinkProperties prop = cm.getLinkProperties(currentNetwork);
return formatIpAddresses(prop);
}
return null;
}
/**