Exemplo n.º 1
0
  void updateSignalStrength() {
    // TODO PhoneStateIntentReceiver is deprecated and PhoneStateListener
    // should probably used instead.

    // 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.getSignalStrengthLevelAsu();

      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));
    }
  }
Exemplo n.º 2
0
  @Override
  protected void onResume() {
    super.onResume();

    if (mPhone != null && !Utils.isWifiOnly(getApplicationContext())) {
      mPhoneStateReceiver.registerIntent();

      updateSignalStrength();
      updateServiceState(mPhone.getServiceState());
      updateDataState();
      mTelephonyManager.listen(
          mPhoneStateListener, PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);
      if (mShowLatestAreaInfo) {
        registerReceiver(
            mAreaInfoReceiver,
            new IntentFilter(CB_AREA_INFO_RECEIVED_ACTION),
            CB_AREA_INFO_SENDER_PERMISSION,
            null);
        // Ask CellBroadcastReceiver to broadcast the latest area info received
        Intent getLatestIntent = new Intent(GET_LATEST_CB_AREA_INFO_ACTION);
        sendBroadcastAsUser(getLatestIntent, UserHandle.ALL, CB_AREA_INFO_SENDER_PERMISSION);
      }
    }
    registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
    mHandler.sendEmptyMessage(EVENT_UPDATE_STATS);
  }
Exemplo n.º 3
0
  @Override
  public void onPause() {
    super.onPause();

    if (mPhone != null && !Utils.isWifiOnly(getApplicationContext())) {
      mPhoneStateReceiver.unregisterIntent();
      mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
    }
    if (mShowLatestAreaInfo) {
      unregisterReceiver(mAreaInfoReceiver);
    }
    unregisterReceiver(mBatteryInfoReceiver);
    mHandler.removeMessages(EVENT_UPDATE_STATS);
  }
Exemplo n.º 4
0
  @Override
  protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    mHandler = new MyHandler(this);

    mTelephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);

    addPreferencesFromResource(R.xml.device_info_status);
    mBatteryLevel = findPreference(KEY_BATTERY_LEVEL);
    mBatteryStatus = findPreference(KEY_BATTERY_STATUS);

    mRes = getResources();
    sUnknown = mRes.getString(R.string.device_info_default);
    if (UserHandle.myUserId() == UserHandle.USER_OWNER) {
      mPhone = PhoneFactory.getDefaultPhone();
    }
    // Note - missing in zaku build, be careful later...
    mSignalStrength = findPreference(KEY_SIGNAL_STRENGTH);
    mUptime = findPreference("up_time");

    if (mPhone == null || Utils.isWifiOnly(getApplicationContext())) {
      for (String key : PHONE_RELATED_ENTRIES) {
        removePreferenceFromScreen(key);
      }
    } else {
      // NOTE "imei" is the "Device ID" since it represents
      //  the IMEI in GSM and the MEID in CDMA
      if (mPhone.getPhoneName().equals("CDMA")) {
        setSummaryText(KEY_MEID_NUMBER, mPhone.getMeid());
        setSummaryText(KEY_MIN_NUMBER, mPhone.getCdmaMin());
        if (getResources().getBoolean(R.bool.config_msid_enable)) {
          findPreference(KEY_MIN_NUMBER).setTitle(R.string.status_msid_number);
        }
        setSummaryText(KEY_PRL_VERSION, mPhone.getCdmaPrlVersion());
        removePreferenceFromScreen(KEY_IMEI_SV);

        if (mPhone.getLteOnCdmaMode() == PhoneConstants.LTE_ON_CDMA_TRUE) {
          // Show ICC ID and IMEI for LTE device
          setSummaryText(KEY_ICC_ID, mPhone.getIccSerialNumber());
          setSummaryText(KEY_IMEI, mPhone.getImei());
        } else {
          // device is not GSM/UMTS, do not display GSM/UMTS features
          // check Null in case no specified preference in overlay xml
          removePreferenceFromScreen(KEY_IMEI);
          removePreferenceFromScreen(KEY_ICC_ID);
        }
      } else {
        setSummaryText(KEY_IMEI, mPhone.getDeviceId());

        setSummaryText(
            KEY_IMEI_SV,
            ((TelephonyManager) getSystemService(TELEPHONY_SERVICE)).getDeviceSoftwareVersion());

        // device is not CDMA, do not display CDMA features
        // check Null in case no specified preference in overlay xml
        removePreferenceFromScreen(KEY_PRL_VERSION);
        removePreferenceFromScreen(KEY_MEID_NUMBER);
        removePreferenceFromScreen(KEY_MIN_NUMBER);
        removePreferenceFromScreen(KEY_ICC_ID);

        // only show area info when SIM country is Brazil
        if ("br".equals(mTelephonyManager.getSimCountryIso())) {
          mShowLatestAreaInfo = true;
        }
      }

      String rawNumber = mPhone.getLine1Number(); // may be null or empty
      String formattedNumber = null;
      if (!TextUtils.isEmpty(rawNumber)) {
        formattedNumber = PhoneNumberUtils.formatNumber(rawNumber);
      }
      // If formattedNumber is null or empty, it'll display as "Unknown".
      setSummaryText(KEY_PHONE_NUMBER, formattedNumber);

      mPhoneStateReceiver = new PhoneStateIntentReceiver(this, mHandler);
      mPhoneStateReceiver.notifySignalStrength(EVENT_SIGNAL_STRENGTH_CHANGED);
      mPhoneStateReceiver.notifyServiceState(EVENT_SERVICE_STATE_CHANGED);

      if (!mShowLatestAreaInfo) {
        removePreferenceFromScreen(KEY_LATEST_AREA_INFO);
      }
    }

    setWimaxStatus();
    setWifiStatus();
    setBtStatus();
    setIpAddressStatus();

    String serial = Build.SERIAL;
    if (serial != null && !serial.equals("")) {
      setSummaryText(KEY_SERIAL_NUMBER, serial);
    } else {
      removePreferenceFromScreen(KEY_SERIAL_NUMBER);
    }
  }