Display current IP address in advanced Wifi settings screen
Change-Id: I47c6eece376e712b73add72057462926f7b2349f Signed-off-by: Mike Lockwood <lockwood@android.com>
This commit is contained in:
@@ -823,6 +823,9 @@
|
|||||||
<!-- Wi-Fi settings screen, advanced, title of the item to show the Wi-Fi device's MAC address. -->
|
<!-- Wi-Fi settings screen, advanced, title of the item to show the Wi-Fi device's MAC address. -->
|
||||||
<string name="wifi_advanced_mac_address_title">MAC address</string>
|
<string name="wifi_advanced_mac_address_title">MAC address</string>
|
||||||
|
|
||||||
|
<!-- Wi-Fi settings screen, advanced, title of the item to show the Wi-Fi device's current IP address. -->
|
||||||
|
<string name="wifi_advanced_ip_address_title">IP address</string>
|
||||||
|
|
||||||
<!-- Status message of Wi-Fi when it is scanning -->
|
<!-- Status message of Wi-Fi when it is scanning -->
|
||||||
<string name="fragment_status_scanning">Scanning\u2026</string>
|
<string name="fragment_status_scanning">Scanning\u2026</string>
|
||||||
<!-- Status message of Wi-Fi when it is connecting to a particular network -->
|
<!-- Status message of Wi-Fi when it is connecting to a particular network -->
|
||||||
|
@@ -38,6 +38,11 @@
|
|||||||
android:title="@string/wifi_advanced_mac_address_title"
|
android:title="@string/wifi_advanced_mac_address_title"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<Preference android:key="current_ip_address"
|
||||||
|
style="?android:attr/preferenceInformationStyle"
|
||||||
|
android:title="@string/wifi_advanced_ip_address_title"
|
||||||
|
/>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:title="@string/wifi_ip_settings_titlebar"
|
android:title="@string/wifi_ip_settings_titlebar"
|
||||||
/>
|
/>
|
||||||
|
@@ -39,6 +39,7 @@ public class AdvancedSettings extends PreferenceActivity
|
|||||||
implements Preference.OnPreferenceChangeListener {
|
implements Preference.OnPreferenceChangeListener {
|
||||||
|
|
||||||
private static final String KEY_MAC_ADDRESS = "mac_address";
|
private static final String KEY_MAC_ADDRESS = "mac_address";
|
||||||
|
private static final String KEY_CURRENT_IP_ADDRESS = "current_ip_address";
|
||||||
private static final String KEY_USE_STATIC_IP = "use_static_ip";
|
private static final String KEY_USE_STATIC_IP = "use_static_ip";
|
||||||
private static final String KEY_NUM_CHANNELS = "num_channels";
|
private static final String KEY_NUM_CHANNELS = "num_channels";
|
||||||
private static final String KEY_SLEEP_POLICY = "sleep_policy";
|
private static final String KEY_SLEEP_POLICY = "sleep_policy";
|
||||||
@@ -98,7 +99,7 @@ public class AdvancedSettings extends PreferenceActivity
|
|||||||
*/
|
*/
|
||||||
//initNumChannelsPreference();
|
//initNumChannelsPreference();
|
||||||
initSleepPolicyPreference();
|
initSleepPolicyPreference();
|
||||||
refreshMacAddress();
|
refreshWifiInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initNumChannelsPreference() {
|
private void initNumChannelsPreference() {
|
||||||
@@ -296,7 +297,7 @@ public class AdvancedSettings extends PreferenceActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshMacAddress() {
|
private void refreshWifiInfo() {
|
||||||
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
|
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
|
||||||
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
||||||
|
|
||||||
@@ -304,6 +305,20 @@ public class AdvancedSettings extends PreferenceActivity
|
|||||||
String macAddress = wifiInfo == null ? null : wifiInfo.getMacAddress();
|
String macAddress = wifiInfo == null ? null : wifiInfo.getMacAddress();
|
||||||
wifiMacAddressPref.setSummary(!TextUtils.isEmpty(macAddress) ? macAddress
|
wifiMacAddressPref.setSummary(!TextUtils.isEmpty(macAddress) ? macAddress
|
||||||
: getString(R.string.status_unavailable));
|
: getString(R.string.status_unavailable));
|
||||||
|
|
||||||
|
Preference wifiIpAddressPref = findPreference(KEY_CURRENT_IP_ADDRESS);
|
||||||
|
String ipAddress = null;
|
||||||
|
if (wifiInfo != null) {
|
||||||
|
long addr = wifiInfo.getIpAddress();
|
||||||
|
if (addr != 0) {
|
||||||
|
// handle negative values whe first octet > 127
|
||||||
|
if (addr < 0) addr += 0x100000000L;
|
||||||
|
ipAddress = String.format("%d.%d.%d.%d",
|
||||||
|
addr & 0xFF, (addr >> 8) & 0xFF, (addr >> 16) & 0xFF, (addr >> 24) & 0xFF);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wifiIpAddressPref.setSummary(ipAddress == null ?
|
||||||
|
getString(R.string.status_unavailable) : ipAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user