Cache preferences and services in status dialog.
Currently, the status dialog fetches the preferences and system services that it uses to display connectivity information (e.g., IP and MAC addresses) only when the dialog is first opened. This is fine because the connectivity information is only filled in once and never updated. In order to have this information update dynamically (like the rest of the dialog), fetch and cache these objects in onCreate. The next change will actually make this information update on network changes. Bug: 10232006 Change-Id: Ib4072674543e517cf6935e3e03f35090e728090a
This commit is contained in:
@@ -345,9 +345,7 @@ public class Utils {
|
|||||||
* @param context the application context
|
* @param context the application context
|
||||||
* @return the formatted and newline-separated IP addresses, or null if none.
|
* @return the formatted and newline-separated IP addresses, or null if none.
|
||||||
*/
|
*/
|
||||||
public static String getDefaultIpAddresses(Context context) {
|
public static String getDefaultIpAddresses(ConnectivityManager cm) {
|
||||||
ConnectivityManager cm = (ConnectivityManager)
|
|
||||||
context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
||||||
LinkProperties prop = cm.getActiveLinkProperties();
|
LinkProperties prop = cm.getActiveLinkProperties();
|
||||||
return formatIpAddresses(prop);
|
return formatIpAddresses(prop);
|
||||||
}
|
}
|
||||||
|
@@ -129,18 +129,26 @@ public class Status extends PreferenceActivity {
|
|||||||
|
|
||||||
private static final int EVENT_UPDATE_STATS = 500;
|
private static final int EVENT_UPDATE_STATS = 500;
|
||||||
|
|
||||||
|
private ConnectivityManager mCM;
|
||||||
private TelephonyManager mTelephonyManager;
|
private TelephonyManager mTelephonyManager;
|
||||||
|
private WifiManager mWifiManager;
|
||||||
|
|
||||||
private Phone mPhone = null;
|
private Phone mPhone = null;
|
||||||
private PhoneStateIntentReceiver mPhoneStateReceiver;
|
private PhoneStateIntentReceiver mPhoneStateReceiver;
|
||||||
private Resources mRes;
|
private Resources mRes;
|
||||||
private Preference mSignalStrength;
|
|
||||||
private Preference mUptime;
|
|
||||||
private boolean mShowLatestAreaInfo;
|
private boolean mShowLatestAreaInfo;
|
||||||
|
|
||||||
private String sUnknown;
|
private String mUnknown;
|
||||||
|
private String mUnavailable;
|
||||||
|
|
||||||
|
private Preference mSignalStrength;
|
||||||
|
private Preference mUptime;
|
||||||
private Preference mBatteryStatus;
|
private Preference mBatteryStatus;
|
||||||
private Preference mBatteryLevel;
|
private Preference mBatteryLevel;
|
||||||
|
private Preference mBtAddress;
|
||||||
|
private Preference mIpAddress;
|
||||||
|
private Preference mWifiMacAddress;
|
||||||
|
private Preference mWimaxMacAddress;
|
||||||
|
|
||||||
private Handler mHandler;
|
private Handler mHandler;
|
||||||
|
|
||||||
@@ -214,20 +222,36 @@ public class Status extends PreferenceActivity {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private boolean hasBluetooth() {
|
||||||
|
return BluetoothAdapter.getDefaultAdapter() != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasWimax() {
|
||||||
|
return mCM.getNetworkInfo(ConnectivityManager.TYPE_WIMAX) != null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle icicle) {
|
protected void onCreate(Bundle icicle) {
|
||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
|
|
||||||
mHandler = new MyHandler(this);
|
mHandler = new MyHandler(this);
|
||||||
|
|
||||||
|
mCM = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
|
||||||
mTelephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
|
mTelephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
|
||||||
|
mWifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
|
||||||
|
|
||||||
addPreferencesFromResource(R.xml.device_info_status);
|
addPreferencesFromResource(R.xml.device_info_status);
|
||||||
mBatteryLevel = findPreference(KEY_BATTERY_LEVEL);
|
mBatteryLevel = findPreference(KEY_BATTERY_LEVEL);
|
||||||
mBatteryStatus = findPreference(KEY_BATTERY_STATUS);
|
mBatteryStatus = findPreference(KEY_BATTERY_STATUS);
|
||||||
|
mBtAddress = findPreference(KEY_BT_ADDRESS);
|
||||||
|
mWifiMacAddress = findPreference(KEY_WIFI_MAC_ADDRESS);
|
||||||
|
mWimaxMacAddress = findPreference(KEY_WIMAX_MAC_ADDRESS);
|
||||||
|
mIpAddress = findPreference(KEY_IP_ADDRESS);
|
||||||
|
|
||||||
mRes = getResources();
|
mRes = getResources();
|
||||||
sUnknown = mRes.getString(R.string.device_info_default);
|
mUnknown = mRes.getString(R.string.device_info_default);
|
||||||
|
mUnavailable = mRes.getString(R.string.status_unavailable);
|
||||||
|
|
||||||
if (UserHandle.myUserId() == UserHandle.USER_OWNER) {
|
if (UserHandle.myUserId() == UserHandle.USER_OWNER) {
|
||||||
mPhone = PhoneFactory.getDefaultPhone();
|
mPhone = PhoneFactory.getDefaultPhone();
|
||||||
}
|
}
|
||||||
@@ -298,10 +322,17 @@ public class Status extends PreferenceActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setWimaxStatus();
|
if (!hasBluetooth()) {
|
||||||
setWifiStatus();
|
getPreferenceScreen().removePreference(mBtAddress);
|
||||||
setBtStatus();
|
mBtAddress = null;
|
||||||
setIpAddressStatus();
|
}
|
||||||
|
|
||||||
|
if (!hasWimax()) {
|
||||||
|
getPreferenceScreen().removePreference(mWimaxMacAddress);
|
||||||
|
mWimaxMacAddress = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateConnectivity();
|
||||||
|
|
||||||
String serial = Build.SERIAL;
|
String serial = Build.SERIAL;
|
||||||
if (serial != null && !serial.equals("")) {
|
if (serial != null && !serial.equals("")) {
|
||||||
@@ -399,7 +430,7 @@ public class Status extends PreferenceActivity {
|
|||||||
|
|
||||||
private void setSummaryText(String preference, String text) {
|
private void setSummaryText(String preference, String text) {
|
||||||
if (TextUtils.isEmpty(text)) {
|
if (TextUtils.isEmpty(text)) {
|
||||||
text = sUnknown;
|
text = mUnknown;
|
||||||
}
|
}
|
||||||
// some preferences may be missing
|
// some preferences may be missing
|
||||||
if (findPreference(preference) != null) {
|
if (findPreference(preference) != null) {
|
||||||
@@ -502,54 +533,46 @@ public class Status extends PreferenceActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setWimaxStatus() {
|
private void setWimaxStatus() {
|
||||||
ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
|
if (mWimaxMacAddress != null) {
|
||||||
NetworkInfo ni = cm.getNetworkInfo(ConnectivityManager.TYPE_WIMAX);
|
String macAddress = SystemProperties.get("net.wimax.mac.address", mUnavailable);
|
||||||
|
mWimaxMacAddress.setSummary(macAddress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (ni == null) {
|
|
||||||
PreferenceScreen root = getPreferenceScreen();
|
|
||||||
Preference ps = (Preference) findPreference(KEY_WIMAX_MAC_ADDRESS);
|
|
||||||
if (ps != null) root.removePreference(ps);
|
|
||||||
} else {
|
|
||||||
Preference wimaxMacAddressPref = findPreference(KEY_WIMAX_MAC_ADDRESS);
|
|
||||||
String macAddress = SystemProperties.get("net.wimax.mac.address",
|
|
||||||
getString(R.string.status_unavailable));
|
|
||||||
wimaxMacAddressPref.setSummary(macAddress);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void setWifiStatus() {
|
private void setWifiStatus() {
|
||||||
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
|
WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
|
||||||
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
|
||||||
|
|
||||||
Preference wifiMacAddressPref = findPreference(KEY_WIFI_MAC_ADDRESS);
|
|
||||||
|
|
||||||
String macAddress = wifiInfo == null ? null : wifiInfo.getMacAddress();
|
String macAddress = wifiInfo == null ? null : wifiInfo.getMacAddress();
|
||||||
wifiMacAddressPref.setSummary(!TextUtils.isEmpty(macAddress) ? macAddress
|
mWifiMacAddress.setSummary(!TextUtils.isEmpty(macAddress) ? macAddress : mUnavailable);
|
||||||
: getString(R.string.status_unavailable));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setIpAddressStatus() {
|
private void setIpAddressStatus() {
|
||||||
Preference ipAddressPref = findPreference(KEY_IP_ADDRESS);
|
String ipAddress = Utils.getDefaultIpAddresses(this.mCM);
|
||||||
String ipAddress = Utils.getDefaultIpAddresses(this);
|
|
||||||
if (ipAddress != null) {
|
if (ipAddress != null) {
|
||||||
ipAddressPref.setSummary(ipAddress);
|
mIpAddress.setSummary(ipAddress);
|
||||||
} else {
|
} else {
|
||||||
ipAddressPref.setSummary(getString(R.string.status_unavailable));
|
mIpAddress.setSummary(mUnavailable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setBtStatus() {
|
private void setBtStatus() {
|
||||||
BluetoothAdapter bluetooth = BluetoothAdapter.getDefaultAdapter();
|
BluetoothAdapter bluetooth = BluetoothAdapter.getDefaultAdapter();
|
||||||
Preference btAddressPref = findPreference(KEY_BT_ADDRESS);
|
if (bluetooth != null && mBtAddress != null) {
|
||||||
|
|
||||||
if (bluetooth == null) {
|
|
||||||
// device not BT capable
|
|
||||||
getPreferenceScreen().removePreference(btAddressPref);
|
|
||||||
} else {
|
|
||||||
String address = bluetooth.isEnabled() ? bluetooth.getAddress() : null;
|
String address = bluetooth.isEnabled() ? bluetooth.getAddress() : null;
|
||||||
btAddressPref.setSummary(!TextUtils.isEmpty(address) ? address
|
if (!TextUtils.isEmpty(address)) {
|
||||||
: getString(R.string.status_unavailable));
|
// Convert the address to lowercase for consistency with the wifi MAC address.
|
||||||
|
mBtAddress.setSummary(address.toLowerCase());
|
||||||
|
} else {
|
||||||
|
mBtAddress.setSummary(mUnavailable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateConnectivity() {
|
||||||
|
setWimaxStatus();
|
||||||
|
setWifiStatus();
|
||||||
|
setBtStatus();
|
||||||
|
setIpAddressStatus();
|
||||||
|
}
|
||||||
|
|
||||||
void updateTimes() {
|
void updateTimes() {
|
||||||
long at = SystemClock.uptimeMillis() / 1000;
|
long at = SystemClock.uptimeMillis() / 1000;
|
||||||
|
Reference in New Issue
Block a user