FileDocCategorySizeDatePackage
Status.javaAPI DocAndroid 1.5 API13807Wed May 06 22:42:48 BST 2009com.android.settings.deviceinfo

Status

public class Status extends android.preference.PreferenceActivity
Display the following information # Phone Number # Network # Roaming # IMEI # Network type # Signal Strength # Battery Strength : TODO # Uptime # Awake Time # XMPP/buzz/tickle status : TODO

Fields Summary
private static final String
KEY_WIFI_MAC_ADDRESS
private static final String
KEY_BT_ADDRESS
private static final int
EVENT_SIGNAL_STRENGTH_CHANGED
private static final int
EVENT_SERVICE_STATE_CHANGED
private static final int
EVENT_UPDATE_STATS
private android.telephony.TelephonyManager
mTelephonyManager
private com.android.internal.telephony.Phone
mPhone
private com.android.internal.telephony.PhoneStateIntentReceiver
mPhoneStateReceiver
private android.content.res.Resources
mRes
private android.preference.Preference
mSignalStrength
private android.preference.Preference
mUptime
private static String
sUnknown
private android.preference.Preference
mBatteryStatus
private android.preference.Preference
mBatteryLevel
private android.os.Handler
mHandler
private android.content.BroadcastReceiver
mBatteryInfoReceiver
private android.telephony.PhoneStateListener
mPhoneStateListener
Constructors Summary
Methods Summary
private java.lang.Stringconvert(long t)

        int s = (int)(t % 60);
        int m = (int)((t / 60) % 60);
        int h = (int)((t / 3600));

        return h + ":" + pad(m) + ":" + pad(s);
    
protected voidonCreate(android.os.Bundle icicle)

    
    
        
        super.onCreate(icicle);

        mHandler = new MyHandler(this);
        
        mTelephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);

        addPreferencesFromResource(R.xml.device_info_status);
        mBatteryLevel = findPreference("battery_level");
        mBatteryStatus = findPreference("battery_status");
        
        mRes = getResources();
        if (sUnknown == null) {
            sUnknown = mRes.getString(R.string.device_info_default);
        }
        
        mPhone = PhoneFactory.getDefaultPhone();
        // Note - missing in zaku build, be careful later...
        mSignalStrength = findPreference("signal_strength");			
        mUptime = findPreference("up_time");
        
        setSummaryText("imei", mPhone.getDeviceId());
        setSummaryText("imei_sv",
                ((TelephonyManager) getSystemService(TELEPHONY_SERVICE))
                        .getDeviceSoftwareVersion());
        setSummaryText("number", mPhone.getLine1Number());

        mPhoneStateReceiver = new PhoneStateIntentReceiver(this, mHandler);
        mPhoneStateReceiver.notifySignalStrength(EVENT_SIGNAL_STRENGTH_CHANGED);
        mPhoneStateReceiver.notifyServiceState(EVENT_SERVICE_STATE_CHANGED);
        
        setWifiStatus();
        setBtStatus();
    
public voidonPause()

        super.onPause();

        mPhoneStateReceiver.unregisterIntent();
        mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
        unregisterReceiver(mBatteryInfoReceiver);
        mHandler.removeMessages(EVENT_UPDATE_STATS);
    
protected voidonResume()

        super.onResume();

        mPhoneStateReceiver.registerIntent();
        registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
        
        updateSignalStrength();
        updateServiceState(mPhone.getServiceState());
        updateDataState();
        
        mTelephonyManager.listen(mPhoneStateListener,
                  PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);

        mHandler.sendEmptyMessage(EVENT_UPDATE_STATS);
    
private java.lang.Stringpad(int n)

        if (n >= 10) {
            return String.valueOf(n);
        } else {
            return "0" + String.valueOf(n);
        }
    
private voidsetBtStatus()

        BluetoothDevice bluetooth = (BluetoothDevice) getSystemService(BLUETOOTH_SERVICE);
        Preference btAddressPref = findPreference(KEY_BT_ADDRESS);

        if (bluetooth == null) {
            // device not BT capable
            getPreferenceScreen().removePreference(btAddressPref);
        } else {
            String address = bluetooth.isEnabled() ? bluetooth.getAddress() : null;
            btAddressPref.setSummary(!TextUtils.isEmpty(address) ? address
                    : getString(R.string.status_unavailable));
        }
    
private voidsetSummary(java.lang.String preference, java.lang.String property, java.lang.String alt)

param
preference The key for the Preference item
param
property The system property to fetch
param
alt The default value, if the property doesn't exist

        try {
            findPreference(preference).setSummary(
                    SystemProperties.get(property, alt));
        } catch (RuntimeException e) {
            
        }
    
private voidsetSummaryText(java.lang.String preference, java.lang.String text)

            if (TextUtils.isEmpty(text)) {
               text = sUnknown;
             }
             // some preferences may be missing
             if (findPreference(preference) != null) {
                 findPreference(preference).setSummary(text);
             }
    
private voidsetWifiStatus()

        WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();

        Preference wifiMacAddressPref = findPreference(KEY_WIFI_MAC_ADDRESS);
        String macAddress = wifiInfo == null ? null : wifiInfo.getMacAddress();
        wifiMacAddressPref.setSummary(!TextUtils.isEmpty(macAddress) ? macAddress 
                : getString(R.string.status_unavailable));
    
private voidupdateDataState()

        int state = mTelephonyManager.getDataState();
        String display = mRes.getString(R.string.radioInfo_unknown);

        switch (state) {
            case TelephonyManager.DATA_CONNECTED:
                display = mRes.getString(R.string.radioInfo_data_connected);
                break;
            case TelephonyManager.DATA_SUSPENDED:
                display = mRes.getString(R.string.radioInfo_data_suspended);
                break;
            case TelephonyManager.DATA_CONNECTING:
                display = mRes.getString(R.string.radioInfo_data_connecting);
                break;
            case TelephonyManager.DATA_DISCONNECTED:
                display = mRes.getString(R.string.radioInfo_data_disconnected);
                break;
        }
        
        setSummaryText("data_state", display);
    
private voidupdateNetworkType()

        // Whether EDGE, UMTS, etc...
        setSummary("network_type", TelephonyProperties.PROPERTY_DATA_NETWORK_TYPE, sUnknown);
    
private voidupdateServiceState(android.telephony.ServiceState serviceState)

        int state = serviceState.getState();
        String display = mRes.getString(R.string.radioInfo_unknown);
        
        switch (state) {
            case ServiceState.STATE_IN_SERVICE:
                display = mRes.getString(R.string.radioInfo_service_in);
                break;
            case ServiceState.STATE_OUT_OF_SERVICE:
            case ServiceState.STATE_EMERGENCY_ONLY:
                display = mRes.getString(R.string.radioInfo_service_out);
                break;
            case ServiceState.STATE_POWER_OFF:
                display = mRes.getString(R.string.radioInfo_service_off);
                break;
        }
        
        setSummaryText("service_state", display);
        
        if (serviceState.getRoaming()) {
            setSummaryText("roaming_state", mRes.getString(R.string.radioInfo_roaming_in));
        } else {
            setSummaryText("roaming_state", mRes.getString(R.string.radioInfo_roaming_not));
        }
        setSummaryText("operator_name", serviceState.getOperatorAlphaLong());
    
voidupdateSignalStrength()

        // not loaded in some versions of the code (e.g., zaku)
        if (mSignalStrength != null) {
            int state =
                    mPhoneStateReceiver.getServiceState().getState();
            Resources r = getResources();

            if ((ServiceState.STATE_OUT_OF_SERVICE == state) ||
                    (ServiceState.STATE_POWER_OFF == state)) {
                mSignalStrength.setSummary("0");
            }

            int signalDbm = mPhoneStateReceiver.getSignalStrengthDbm();

            if (-1 == signalDbm) signalDbm = 0;

            int signalAsu = mPhoneStateReceiver.getSignalStrength();

            if (-1 == signalAsu) signalAsu = 0;

            mSignalStrength.setSummary(String.valueOf(signalDbm) + " "
                        + r.getString(R.string.radioInfo_display_dbm) + "   "
                        + String.valueOf(signalAsu) + " "
                        + r.getString(R.string.radioInfo_display_asu));
        }
    
voidupdateTimes()

        long at = SystemClock.uptimeMillis() / 1000;
        long ut = SystemClock.elapsedRealtime() / 1000;
        long st = ut - at;

        if (ut == 0) {
            ut = 1;
        }

        mUptime.setSummary(convert(ut));