private void addCellSpecFromCellLocation(
     Collection<CellSpec> cellSpecs, int mcc, int mnc, CellLocation cellLocation) {
   if (cellLocation instanceof GsmCellLocation) {
     GsmCellLocation gsmCellLocation = (GsmCellLocation) cellLocation;
     int cid = gsmCellLocation.getCid();
     int lac = gsmCellLocation.getLac();
     int psc = gsmCellLocation.getPsc();
     if (psc == -1) {
       cellSpecs.add(new CellSpec(Radio.GSM, mcc, mnc, lac, cid));
     } else {
       CellSpec cellSpec = new CellSpec(Radio.UMTS, mcc, mnc, lac, cid);
       cellSpec.setPsc(psc);
       cellSpecs.add(cellSpec);
     }
   } else if (cellLocation instanceof CdmaCellLocation) {
     CdmaCellLocation cdmaCellLocation = (CdmaCellLocation) cellLocation;
     int sid = cdmaCellLocation.getSystemId(); // as mnc
     int nid = cdmaCellLocation.getNetworkId(); // as lac
     int bid = cdmaCellLocation.getBaseStationId(); // as cid
     cellSpecs.add(new CellSpec(Radio.CDMA, mcc, sid, nid, bid));
   } else {
     if (MainService.DEBUG) {
       Log.d(TAG, "Not connected to network or using LTE, which is not supported for SDK <= 16");
     }
   }
 }
  // Button
  public void onBdoneCellTowerTrigger(View view) {
    TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    GsmCellLocation loc = (GsmCellLocation) tm.getCellLocation();
    Integer in = loc.getCid();
    String s = in.toString();
    // int doseNotHavewNetwork = 555;
    //  doseNotHavewNetwork = TelephonyManager.NETWORK_TYPE_UNKNOWN;

    // True if the phone is not connected to some type of network i.e. has signal
    //  if(doseNotHavewNetwork == 1){
    //      Toast.makeText(this, "Please make sure that phone has connected to carrier
    // service.",Toast.LENGTH_LONG).show();
    //  }
    if (s.equals("")) {
      Globals.p.setW_cellTower("555");
      Intent i = new Intent(this, WhenToDo.class);
      startActivity(i);
    } else {
      Globals.p.setW_cellTower(s);
      //   Toast.makeText(this, TelephonyManager.NETWORK_TYPE_UNKNOWN,Toast.LENGTH_LONG).show();

      Intent i = new Intent(this, WhenToDo.class);
      startActivity(i);
    }
  }
 @Override
 public void onCellLocationChanged(CellLocation location) {
   super.onCellLocationChanged(location);
   if (location instanceof GsmCellLocation) {
     db = new DatabaseHandler(getApplicationContext());
     GsmCellLocation gcLoc = (GsmCellLocation) location;
     String cellid = String.valueOf(gcLoc.getCid()); // Cell ID
     String lac = String.valueOf(gcLoc.getLac()); // Location Area Code
     // TextView txtCid = (TextView)findViewById(R.id.cellIdTextView);
     String cellId = cellid + ":" + lac;
     String locationName = db.getLocation(cellId);
     GlobalValuesNStatus.getInstance().currentCellId = cellId;
     GlobalValuesNStatus.getInstance().currentCellLocation = locationName;
     // final TiTiGlobal globalVariable = (TiTiGlobal)(getApplicationContext());
     // globalVariable.setCurrentCellId(cellId);
     NotificationHelper notificationHelper = new NotificationHelper(getApplicationContext());
     if (locationName.isEmpty()) {
       Intent intent2 = new Intent(getApplicationContext(), LearnLocations.class);
       intent2.putExtra("cellId", cellId);
       notificationHelper.createNotification(
           "TiTi@" + "Unknown Location", cellId, 2324, intent2, true, true, "s2");
     } else {
       notificationHelper.createNotification(
           "TiTi@" + locationName,
           cellId,
           2324,
           new Intent(getApplicationContext(), MainActivity.class),
           false,
           true,
           "s2");
     }
   }
 }
 // Get the Signal strength from the provider, each time there is an update
 @Override
 public void onSignalStrengthsChanged(SignalStrength signalStrength) {
   super.onSignalStrengthsChanged(signalStrength);
   sigLevel = signalStrength.getGsmSignalStrength();
   GsmCellLocation gsmInfo = (GsmCellLocation) phoneStateManager.getCellLocation();
   cellID = gsmInfo.getCid() / 10; // cut off sector ID
   postSignalLocation();
 }
  private void sendLog() {
    if (mKaaStarted) {

      mSentLogCount++;
      mLastLogTime = System.currentTimeMillis();

      /*
       * Create an instance of a cell monitor log record and populate it with the latest values.
       */
      CellMonitorLog cellMonitorLog = new CellMonitorLog();
      cellMonitorLog.setLogTime(mLastLogTime);
      String networkOperator = mTelephonyManager.getNetworkOperator();
      if (networkOperator == null || networkOperator.isEmpty()) {
        cellMonitorLog.setNetworkOperatorCode(UNDEFINED);
      } else {
        cellMonitorLog.setNetworkOperatorCode(
            Integer.valueOf(mTelephonyManager.getNetworkOperator()));
      }
      cellMonitorLog.setNetworkOperatorName(mTelephonyManager.getNetworkOperatorName());

      int cid = UNDEFINED;
      int lac = UNDEFINED;

      if (mCellLocation != null && mCellLocation instanceof GsmCellLocation) {
        GsmCellLocation gsmCellLocation = (GsmCellLocation) mCellLocation;
        cid = gsmCellLocation.getCid();
        lac = gsmCellLocation.getLac();
      }

      cellMonitorLog.setGsmCellId(cid);
      cellMonitorLog.setGsmLac(lac);

      int gsmSignalStrength = UNDEFINED;

      if (mSignalStrength != null) {
        gsmSignalStrength = mSignalStrength.getGsmSignalStrength();
      }
      cellMonitorLog.setSignalStrength(gsmSignalStrength);

      org.kaaproject.kaa.demo.cellmonitor.Location phoneLocation =
          new org.kaaproject.kaa.demo.cellmonitor.Location();
      if (mGpsLocation != null) {
        phoneLocation.setLatitude(mGpsLocation.getLatitude());
        phoneLocation.setLongitude(mGpsLocation.getLongitude());
      }
      cellMonitorLog.setPhoneGpsLocation(phoneLocation);

      /*
       * Pass a cell monitor log record to the Kaa client. The Kaa client will upload
       * the log record according to the defined log upload strategy.
       */
      mClient.addLogRecord(cellMonitorLog);

      mEventBus.post(new LogSent());
    }
  }
 @Override
 public void onLocationChanged(Location location) {
   if (location != null) {
     x = location.getLatitude();
     y = location.getLongitude();
     GsmCellLocation gsmInfo = (GsmCellLocation) phoneStateManager.getCellLocation();
     cellID = gsmInfo.getCid() / 10; // cut off sector ID
     postSignalLocation();
   }
 }
  public ArrayList<CellIDInfo> getCellIDInfo(Context context) {
    manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    listener = new PhoneStateListener();
    manager.listen(listener, 0);
    ArrayList<CellIDInfo> CellID = new ArrayList<CellIDInfo>();
    CellIDInfo currentCell = new CellIDInfo();

    int type = manager.getNetworkType();
    if (type == TelephonyManager.NETWORK_TYPE_GPRS
        || type == TelephonyManager.NETWORK_TYPE_EDGE
        || type == TelephonyManager.NETWORK_TYPE_HSDPA) {
      gsm = ((GsmCellLocation) manager.getCellLocation());
      if (gsm == null) return null;
      lac = gsm.getLac();
      mcc = manager.getNetworkOperator().substring(0, 3);
      mnc = manager.getNetworkOperator().substring(3, 5);

      currentCell.cellId = gsm.getCid();
      currentCell.mobileCountryCode = mcc;
      currentCell.mobileNetworkCode = mnc;
      currentCell.locationAreaCode = lac;
      currentCell.radioType = "gsm";
      CellID.add(currentCell);

      List<NeighboringCellInfo> list = manager.getNeighboringCellInfo();
      int size = list.size();
      for (int i = 0; i < size; i++) {
        CellIDInfo info = new CellIDInfo();
        info.cellId = list.get(i).getCid();
        info.mobileCountryCode = mcc;
        info.mobileCountryCode = mnc;
        info.locationAreaCode = lac;
        CellID.add(info);
      }
      return CellID;

    } else if (type == TelephonyManager.NETWORK_TYPE_CDMA
        || type == TelephonyManager.NETWORK_TYPE_1xRTT) {
      cdma = ((CdmaCellLocation) manager.getCellLocation());
      if (cdma == null) return null;

      if ("460".equals(manager.getSimOperator().substring(0, 3))) return null;
    }
    return null;
  }
Exemple #8
0
 @Override
 public String getLogValue() {
   GsmCellLocation gcl = ((GsmCellLocation) m_telManager.getCellLocation());
   String rstr =
       ""
           + getNetworkTypeStr(m_telManager.getNetworkType())
           + " "
           + getDataStateStr(m_telManager.getDataState())
           + " "
           + getDataActivityStr(m_telManager.getDataActivity())
           + " "
           + m_ss
           + " "
           + gcl.getCid()
           + " "
           + gcl.getLac(); // FIXME GSM_ONLY method, get cell_id and Location_area_code
   return rstr;
 }
Exemple #9
0
  public String getListenerInfo() {

    pref = new Preferences(context);
    strBuffer = new StringBuffer();

    SignalStrengh objSS = pref.getSignalStrengthObj();

    TelephonyManager telephonyManager =
        (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    cell_info = telephonyManager.getCallState();
    network_operator = telephonyManager.getNetworkOperator();

    network_operator_name = telephonyManager.getNetworkOperatorName();
    network_operator_name = XMLUtils.clean(network_operator_name);

    network_type = telephonyManager.getNetworkType();

    datastate = telephonyManager.getDataState();
    dataactivity = telephonyManager.getDataActivity();

    batteryPercentage = pref.getBatteryLevel();

    String networkOperator = telephonyManager.getNetworkOperator();
    try {
      mcc = networkOperator.substring(0, 3);
      mnc = networkOperator.substring(3);
    } catch (Exception e) {

    }

    // wifi state
    ConnectivityManager c_m =
        (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo mobile_info = c_m.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    NetworkInfo wifi_info = c_m.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

    if (mobile_info != null) network_state = "" + mobile_info.getState();

    if (wifi_info != null) wifi_state = "" + wifi_info.getState();

    if (telephonyManager.isNetworkRoaming()) roaming = true;

    if (telephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) { // GSM
      // Network

      GsmCellLocation cell_loc = (GsmCellLocation) telephonyManager.getCellLocation();
      if (cell_loc != null) {
        cid = cell_loc.getCid();
        lac = cell_loc.getLac();
      }
    } else if (telephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA) { // CDMA
      // Network
      CdmaCellLocation cell_loc = (CdmaCellLocation) telephonyManager.getCellLocation();
      if (cell_loc != null) {
        // cid = cell_loc.
        cid = cell_loc.getBaseStationId();
        L.log("CDMA Base Stattion Id: " + cid);
        // cid = 0;
        lac = 0;
      }
    }

    /*
    code added by ankit for tac & pci to get values 12/07/16
     */
    try {
      final TelephonyManager tm =
          (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
      for (final CellInfo info : tm.getAllCellInfo()) {
        if (info instanceof CellInfoGsm) {
          final CellSignalStrengthGsm gsm = ((CellInfoGsm) info).getCellSignalStrength();
          // tac = 11450;
          // pci = 50;

        } else if (info instanceof CellInfoCdma) {
          final CellSignalStrengthCdma cdma = ((CellInfoCdma) info).getCellSignalStrength();

        } else if (info instanceof CellInfoLte) {
          final CellSignalStrengthLte lte = ((CellInfoLte) info).getCellSignalStrength();

          // tac = ((CellInfoLte) info).getCellIdentity().getTac();
          // pci = ((CellInfoLte) info).getCellIdentity().getPci();
          // New code added by ankit on 02/07/2016
          CellIdentityLte identity = ((CellInfoLte) info).getCellIdentity();
          tac = identity.getTac();
          pci = identity.getPci();
        } else {
          throw new Exception("Unknown type of cell signal!");
        }
      }
    } catch (Exception e) {
      // Log.e(TAG, "Unable to obtain cell signal information", e);
    }

    /*
     * GsmCellLocation cell_loc = (GsmCellLocation) telephonyManager
     * .getCellLocation(); if (cell_loc != null) { cid = cell_loc.getCid();
     * lac = cell_loc.getLac(); }
     */

    strBuffer.append(DATA_START);

    strBuffer.append(TIMESTAMP_START);
    strBuffer.append(TimeUtil.getCurrentTime());
    strBuffer.append(TIMESTAMP_END);

    strBuffer.append(NETWORK_INFO_START);

    strBuffer.append(NETWORK_OPERATOR_START);
    if (network_operator != null) strBuffer.append(network_operator);
    strBuffer.append(NETWORK_OPERATOR_END);

    strBuffer.append(NETWORK_OPERATOR_NAME_START);
    if (network_operator_name != null) strBuffer.append(network_operator_name);
    strBuffer.append(NETWORK_OPERATOR_NAME_END);

    strBuffer.append(NETWORK_TYPE_START);

    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo objWifiInfo = wifiManager.getConnectionInfo();
    L.debug("BSSID: " + objWifiInfo.getBSSID());
    L.debug("RSSI: " + objWifiInfo.getRssi());
    L.debug("LINK SPEED: " + objWifiInfo.getLinkSpeed());

    if (wifi_state != null && wifi_state.equals("CONNECTED")) strBuffer.append("wifi");
    else strBuffer.append(getNetworkTypeString(network_type));

    strBuffer.append(NETWORK_TYPE_END);

    strBuffer.append(DATA_STATE_START);
    strBuffer.append(getDataStateString(datastate));
    strBuffer.append(DATA_STATE_END);

    strBuffer.append(DATA_ACTIVITY_START);
    strBuffer.append(getDataActivityString(dataactivity));
    strBuffer.append(DATA_ACTIVITY_END);

    strBuffer.append(WIFI_STATE_START);
    if (wifi_state != null) strBuffer.append(wifi_state);
    strBuffer.append(WIFI_STATE_END);

    strBuffer.append(ROAMING_START);
    strBuffer.append(roaming);
    strBuffer.append(ROAMING_END);

    strBuffer.append(MCC_START);
    strBuffer.append(mcc);
    strBuffer.append(MCC_END);

    strBuffer.append(MNC_START);
    strBuffer.append(mnc);
    strBuffer.append(MNC_END);
    strBuffer.append(NETWORK_INFO_END);

    strBuffer.append(SIGNAL_STRENGTH_START);
    strBuffer.append(GSM_SIGNAL_STRENGTH_START);
    strBuffer.append(objSS.GSMSignalStrength);
    strBuffer.append(GSM_SIGNAL_STRENGTH_END);

    strBuffer.append(CDMA_DBM_START);
    strBuffer.append(objSS.CDMADbm);
    strBuffer.append(CDMA_DBM_END);

    strBuffer.append(CDMA_ECIO_START);
    strBuffer.append(objSS.CDMAEcio);
    strBuffer.append(CDMA_ECIO_END);

    strBuffer.append(EVDO_DBM_START);
    strBuffer.append(objSS.EvdoDbm);
    strBuffer.append(EVDO_DBM_END);

    strBuffer.append(EVDO_ECIO_START);
    strBuffer.append(objSS.EvdoEcio);
    strBuffer.append(EVDO_ECIO_END);

    strBuffer.append(EVDO_SNR_START);
    strBuffer.append(objSS.EvdoSnr);
    strBuffer.append(EVDO_SNR_END);

    strBuffer.append(GSM_START);
    strBuffer.append(objSS.blisGSM);
    strBuffer.append(GSM_END);

    strBuffer.append(GSM_BITRATE_ERROR_START);
    strBuffer.append(objSS.GSMBitRateError);
    strBuffer.append(GSM_BITRATE_ERROR_END);

    //
    strBuffer.append(LTE_SIGNAL_STRENGTH_START);
    strBuffer.append(objSS.LteSignalStrength);
    strBuffer.append(LTE_SIGNAL_STRENGTH_END);

    strBuffer.append(LTE_RSRP_START);
    strBuffer.append(objSS.LteRsrp);
    strBuffer.append(LTE_RSRP_END);

    strBuffer.append(LTE_RSRQ_START);
    strBuffer.append(objSS.LteRsrq);
    strBuffer.append(LTE_RSRQ_END);

    strBuffer.append(LTE_RSSNR_START);
    strBuffer.append(objSS.LteRssnr);
    strBuffer.append(LTE_RSSNR_END);

    strBuffer.append(LTE_CQI_START);
    strBuffer.append(objSS.LteCqi);
    strBuffer.append(LTE_CQI_END);

    strBuffer.append(SIGNAL_STRENGTH_END);

    // Change required here for LTE Network operator
    /** Get from signal SignalStrengthListener LAC - TAC CID - PCI */
    strBuffer.append(CELL_LOCATION_START);
    strBuffer.append(CID_START);
    strBuffer.append(cid);
    strBuffer.append(CID_END);

    strBuffer.append(LAC_START);
    strBuffer.append(lac);
    strBuffer.append(LAC_END);

    strBuffer.append(LTE_TAC_START);
    strBuffer.append(tac);
    strBuffer.append(LTE_TAC_END);

    strBuffer.append(LTE_PCI_START);
    strBuffer.append(pci);
    strBuffer.append(LTE_PCI_END);

    strBuffer.append(CELL_LOCATION_END);

    /** */
    strBuffer.append(NEIGHBORING_CELL_INFO_START);

    StringBuffer sNeightboringCellInfos = new StringBuffer();
    List<NeighboringCellInfo> neighbor_cell_infos = telephonyManager.getNeighboringCellInfo();

    for (int i = 0; i < neighbor_cell_infos.size(); i++) {
      sNeightboringCellInfos.append(NEIGHBORING_INFO_START);
      NeighboringCellInfo nci = neighbor_cell_infos.get(i);
      sNeightboringCellInfos.append(CID_START);
      sNeightboringCellInfos.append(nci.getCid());
      sNeightboringCellInfos.append(CID_END);

      sNeightboringCellInfos.append(LAC_START);
      sNeightboringCellInfos.append(nci.getLac());
      sNeightboringCellInfos.append(LAC_END);

      sNeightboringCellInfos.append(NET_TYPE_START);
      sNeightboringCellInfos.append(nci.getNetworkType());
      sNeightboringCellInfos.append(NET_TYPE_END);

      sNeightboringCellInfos.append(PSC_START);
      sNeightboringCellInfos.append(nci.getPsc());
      sNeightboringCellInfos.append(PSC_END);

      sNeightboringCellInfos.append(RSSI_START);
      sNeightboringCellInfos.append(nci.getRssi());
      sNeightboringCellInfos.append(RSSI_END);
      sNeightboringCellInfos.append(NEIGHBORING_INFO_END);
    }

    strBuffer.append(sNeightboringCellInfos);
    strBuffer.append(NEIGHBORING_CELL_INFO_END);

    strBuffer.append(BATTERY_LEVEL_START);
    strBuffer.append(batteryPercentage);
    strBuffer.append(BATTERY_LEVEL_END);

    strBuffer.append(NETWORK_MANUALLYSET_START);
    manuallyset = isSpoofLocation();
    strBuffer.append(manuallyset);
    strBuffer.append(NETWORK_MANUALLYSET_END);

    strBuffer.append(GEO_LOCATION_START);
    strBuffer.append(GEO_LAT_START);
    strBuffer.append(pref.getLatitude());
    strBuffer.append(GEO_LAT_END);

    strBuffer.append(GEO_LAN_START);
    strBuffer.append(pref.getLongitude());
    strBuffer.append(GEO_LAN_END);

    strBuffer.append(GEO_LOCATION_END);

    // ============================================================
    /** Added on 15th Dec 2014. Asper Mathew's request Added by: Bhagya */
    strBuffer.append(WIFI_INFO_START);
    strBuffer.append(BSSID_START);
    if (objWifiInfo.getBSSID() != null) strBuffer.append(objWifiInfo.getBSSID());
    else strBuffer.append("NA");
    strBuffer.append(BSSID_END);

    strBuffer.append(WIFI_RSSI_START);
    strBuffer.append(objWifiInfo.getRssi());
    strBuffer.append(WIFI_RSSI_END);

    strBuffer.append(WIFI_LINK_SPEED_START);
    strBuffer.append(objWifiInfo.getLinkSpeed());
    strBuffer.append(WIFI_LINK_SPEED_END);

    strBuffer.append(WIFI_INFO_END);

    // ============================================================

    strBuffer.append(DATA_END);

    xmlFile = strBuffer.toString();

    return xmlFile;
  }
  protected void handleBroadcastSms(AsyncResult ar) {
    try {
      byte[][] pdus = null;
      byte[] receivedPdu = (byte[]) ar.result;

      if (Config.LOGD) {
        for (int i = 0; i < receivedPdu.length; i += 8) {
          StringBuilder sb = new StringBuilder("SMS CB pdu data: ");
          for (int j = i; j < i + 8 && j < receivedPdu.length; j++) {
            int b = receivedPdu[j] & 0xff;
            if (b < 0x10) {
              sb.append("0");
            }
            sb.append(Integer.toHexString(b)).append(" ");
          }
          Log.d(TAG, sb.toString());
        }
      }

      SmsCbHeader header = new SmsCbHeader(receivedPdu);
      String plmn = SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC);
      GsmCellLocation cellLocation = (GsmCellLocation) mGsmPhone.getCellLocation();
      int lac = cellLocation.getLac();
      int cid = cellLocation.getCid();

      if (header.nrOfPages > 1) {
        // Multi-page message
        SmsCbConcatInfo concatInfo = new SmsCbConcatInfo(header, plmn, lac, cid);

        // Try to find other pages of the same message
        pdus = mSmsCbPageMap.get(concatInfo);

        if (pdus == null) {
          // This it the first page of this message, make room for all
          // pages and keep until complete
          pdus = new byte[header.nrOfPages][];

          mSmsCbPageMap.put(concatInfo, pdus);
        }

        // Page parameter is one-based
        pdus[header.pageIndex - 1] = receivedPdu;

        for (int i = 0; i < pdus.length; i++) {
          if (pdus[i] == null) {
            // Still missing pages, exit
            return;
          }
        }

        // Message complete, remove and dispatch
        mSmsCbPageMap.remove(concatInfo);
      } else {
        // Single page message
        pdus = new byte[1][];
        pdus[0] = receivedPdu;
      }

      dispatchBroadcastPdus(pdus);

      // Remove messages that are out of scope to prevent the map from
      // growing indefinitely, containing incomplete messages that were
      // never assembled
      Iterator<SmsCbConcatInfo> iter = mSmsCbPageMap.keySet().iterator();

      while (iter.hasNext()) {
        SmsCbConcatInfo info = iter.next();

        if (!info.matchesLocation(plmn, lac, cid)) {
          iter.remove();
        }
      }
    } catch (RuntimeException e) {
      Log.e(TAG, "Error in decoding SMS CB pdu", e);
    }
  }
  public void handleMessage(Message msg) {
    AsyncResult ar;

    switch (msg.what) {
      case EVENT_POLL_CALLS_RESULT:
        ar = (AsyncResult) msg.obj;

        if (msg == lastRelevantPoll) {
          if (DBG_POLL) log("handle EVENT_POLL_CALL_RESULT: set needsPoll=F");
          needsPoll = false;
          lastRelevantPoll = null;
          handlePollCalls((AsyncResult) msg.obj);
        }
        break;

      case EVENT_OPERATION_COMPLETE:
        ar = (AsyncResult) msg.obj;
        operationComplete();
        break;

      case EVENT_SWITCH_RESULT:
      case EVENT_CONFERENCE_RESULT:
      case EVENT_SEPARATE_RESULT:
      case EVENT_ECT_RESULT:
        ar = (AsyncResult) msg.obj;
        if (ar.exception != null) {
          phone.notifySuppServiceFailed(getFailedService(msg.what));
        }
        operationComplete();
        break;

      case EVENT_GET_LAST_CALL_FAIL_CAUSE:
        int causeCode;
        ar = (AsyncResult) msg.obj;

        operationComplete();

        if (ar.exception != null) {
          // An exception occurred...just treat the disconnect
          // cause as "normal"
          causeCode = CallFailCause.NORMAL_CLEARING;
          Rlog.i(LOG_TAG, "Exception during getLastCallFailCause, assuming normal disconnect");
        } else {
          causeCode = ((int[]) ar.result)[0];
        }
        // Log the causeCode if its not normal
        if (causeCode == CallFailCause.NO_CIRCUIT_AVAIL
            || causeCode == CallFailCause.TEMPORARY_FAILURE
            || causeCode == CallFailCause.SWITCHING_CONGESTION
            || causeCode == CallFailCause.CHANNEL_NOT_AVAIL
            || causeCode == CallFailCause.QOS_NOT_AVAIL
            || causeCode == CallFailCause.BEARER_NOT_AVAIL
            || causeCode == CallFailCause.ERROR_UNSPECIFIED) {
          GsmCellLocation loc = ((GsmCellLocation) phone.getCellLocation());
          EventLog.writeEvent(
              EventLogTags.CALL_DROP,
              causeCode,
              loc != null ? loc.getCid() : -1,
              TelephonyManager.getDefault().getNetworkType());
        }

        for (int i = 0, s = droppedDuringPoll.size(); i < s; i++) {
          GsmConnection conn = droppedDuringPoll.get(i);

          conn.onRemoteDisconnect(causeCode);
        }

        updatePhoneState();

        phone.notifyPreciseCallStateChanged();
        droppedDuringPoll.clear();
        break;

      case EVENT_REPOLL_AFTER_DELAY:
      case EVENT_CALL_STATE_CHANGE:
        pollCallsWhenSafe();
        break;

      case EVENT_RADIO_AVAILABLE:
        handleRadioAvailable();
        break;

      case EVENT_RADIO_NOT_AVAILABLE:
        handleRadioNotAvailable();
        break;
    }
  }
  private void populateInfo() {
    String value;
    if (MainService.isExecuting()) {
      value = getString(R.string.executing_now);
    } else {
      if (SK2AppSettings.getInstance().isServiceActivated()) {
        value = getString(R.string.yes);
      } else {
        value = getString(R.string.no);
      }
    }
    ((TextView) findViewById(R.id.tv_service_activated_value)).setText(value);
    if (SK2AppSettings.getInstance().isServiceEnabled()) {
      value = getString(R.string.enabled);
    } else {
      value = getString(R.string.disabled);
    }
    ((TextView) findViewById(R.id.tv_service_autotesting_value)).setText(value);
    ((TextView) findViewById(R.id.tv_service_status_value))
        .setText(getString(SK2AppSettings.getSK2AppSettingsInstance().getState().sId));

    String versionName = "";
    try {
      versionName = this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionName;
    } catch (NameNotFoundException e) {
      SKLogger.e(this, "Error in getting app version name.", e);
    }

    ((TextView) findViewById(R.id.version)).setText(versionName);

    ScheduleConfig config = CachingStorage.getInstance().loadScheduleConfig();
    String schedule_version = config == null ? "" : config.getConfigVersion();
    ((TextView) findViewById(R.id.schedule_version)).setText(schedule_version);

    String nextTestScheduled = "";
    if (MainService.isExecuting()) {
      nextTestScheduled = getString(R.string.executing_now);
    } else {
      long nextRunTime = SK2AppSettings.getInstance().getNextRunTime();
      if (nextRunTime == SKConstants.NO_NEXT_RUN_TIME) {
        nextTestScheduled = getString(R.string.none);
      } else {
        nextTestScheduled = new SKDateFormat(this).UITime(nextRunTime);
      }
    }
    ((TextView) findViewById(R.id.tv_scheduledFor_value)).setText(nextTestScheduled);

    PhoneIdentityData phoneData = new PhoneIdentityDataCollector(this).collect();
    if (!SK2AppSettings.getSK2AppSettingsInstance().anonymous) {
      ((TextView) findViewById(R.id.tv_imei_value)).setText(phoneData.imei + "");
      ((TextView) findViewById(R.id.tv_imsi_value)).setText(phoneData.imsi + "");
      ((TextView) findViewById(R.id.tv_unitId_value))
          .setText(SK2AppSettings.getInstance().getUnitId());
    }

    value = phoneData.manufacturer + "\n\r" + phoneData.model;
    ((TextView) findViewById(R.id.tv_phone_value)).setText(value);
    value = phoneData.osType + " v" + phoneData.osVersion;
    ((TextView) findViewById(R.id.tv_os_value)).setText(value);

    NetworkData networkData = new NetworkDataCollector(this).collect();
    value = DCSConvertorUtil.convertPhoneType(networkData.phoneType);
    ((TextView) findViewById(R.id.tv_phone_type_value)).setText(value);
    value = getString(DCSConvertorUtil.networkTypeToStringId(networkData.networkType));
    ((TextView) findViewById(R.id.tv_network_type_value)).setText(value);
    value = networkData.networkOperatorCode + "/" + networkData.networkOperatorName;
    ((TextView) findViewById(R.id.tv_network_operator_value)).setText(value);
    if (networkData.isRoaming) {
      value = getString(R.string.yes);
    } else {
      value = getString(R.string.no);
    }
    ((TextView) findViewById(R.id.tv_roaming_value)).setText(value);

    Location loc1 =
        ((LocationManager) getSystemService(LOCATION_SERVICE))
            .getLastKnownLocation(LocationManager.GPS_PROVIDER);
    Location loc2 =
        ((LocationManager) getSystemService(LOCATION_SERVICE))
            .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
    Location loc = null;
    if (loc1 != null && loc2 != null) {
      loc = loc1.getTime() > loc2.getTime() ? loc1 : loc2;
    } else {
      loc = loc1 == null ? loc2 : loc1;
    }
    if (loc != null) {
      ((TextView) findViewById(R.id.tv_loc_date_value))
          .setText(new SKDateFormat(this).UITime(loc.getTime()));
      ((TextView) findViewById(R.id.tv_loc_provider_value)).setText(loc.getProvider());
      ((TextView) findViewById(R.id.tv_loc_long_value))
          .setText(String.format("%1.5f", loc.getLongitude()));
      ((TextView) findViewById(R.id.tv_loc_lat_value))
          .setText(String.format("%1.5f", loc.getLatitude()));
      ((TextView) findViewById(R.id.tv_loc_acc_value)).setText(loc.getAccuracy() + " m");
    }

    // Cells
    CellTowersData cellData = new CellTowersDataCollector(this).collect();
    if (cellData.cellLocation instanceof GsmCellLocation) {
      GsmCellLocation gsmLocation = (GsmCellLocation) cellData.cellLocation;
      ((TextView) findViewById(R.id.tv_cell_tower_type_value)).setText("GSM");
      ((TextView) findViewById(R.id.tv_cell_id_value)).setText("" + gsmLocation.getCid());
      ((TextView) findViewById(R.id.tv_area_code_value)).setText("" + gsmLocation.getLac());
    } else if (cellData.cellLocation instanceof CdmaCellLocation) {
      ((TextView) findViewById(R.id.tv_cell_tower_type_value)).setText("CDMA");
      //			CdmaCellLocation cdmaLocation = (CdmaCellLocation) cellLocation;
      //			builder.append(CDMA);
      //			builder.append(time/1000);
      //			builder.append(cdmaLocation.getBaseStationId());
      //			builder.append(cdmaLocation.getBaseStationLatitude());
      //			builder.append(cdmaLocation.getBaseStationLongitude());
      //			builder.append(cdmaLocation.getNetworkId());
      //			builder.append(cdmaLocation.getSystemId());
    }

    if (cellData.signal.isGsm()) {
      int signalStrength = SKGsmSignalStrength.getGsmSignalStrength(cellData.signal);
      value = DCSConvertorUtil.convertGsmSignalStrength(signalStrength);
    } else {
      value = cellData.signal.getCdmaDbm() + " dBm";
    }

    ((TextView) findViewById(R.id.tv_signal_value)).setText(value);
    // Note: neighbors might be NULL...
    if (cellData.getNeighbors() != null) {
      for (NeighboringCellInfo info : cellData.getNeighbors()) {
        appendNeighborCellInfo(info);
      }
    }

    Util.initializeFonts(this);
    Util.overrideFonts(this, findViewById(android.R.id.content));
  }
  public void getLocationByBase() {

    telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    try {

      int type = telephonyManager.getNetworkType();
      int lac = 0;
      int ci = 0;
      if (type == TelephonyManager.PHONE_TYPE_GSM) {
        Log.e("LocatteMySeleftService", "GSM");
        GsmCellLocation location = (GsmCellLocation) telephonyManager.getCellLocation();
        lac = location.getLac();
        ci = location.getCid();

        int mcc = Integer.valueOf(telephonyManager.getNetworkOperator().substring(0, 3));
        int mnc = Integer.valueOf(telephonyManager.getNetworkOperator().substring(3, 5));

        JSONObject holder = new JSONObject();
        holder.put("version", "1.1.0");
        holder.put("host", "maps.google.com");
        holder.put("request_address", true);
        JSONArray array = new JSONArray();
        JSONObject data = new JSONObject();
        data.put("cell_id", ci);
        data.put("location_area_code", lac);
        data.put("mobile_country_code", mcc);
        data.put("mobile_network_code", mnc);
        array.put(data);
        holder.put("cell_towers", array);
        DefaultHttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost("http://www.google.com/loc/json");
        StringEntity se = new StringEntity(holder.toString());
        post.setEntity(se);
        org.apache.http.HttpResponse resp = client.execute(post);
        HttpEntity entity = resp.getEntity();
        BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));
        StringBuffer sb = new StringBuffer();
        String result = br.readLine();
        while (result != null) {
          sb.append(result);
          result = br.readLine();
        }
        JSONObject jsonObject = new JSONObject(sb.toString());

        JSONObject jsonObject1 = new JSONObject(jsonObject.getString("location"));

        getAddress(jsonObject1.getString("latitude"), jsonObject1.getString("longitude"));
      } else if (type == TelephonyManager.PHONE_TYPE_CDMA
          || type == TelephonyManager.NETWORK_TYPE_EVDO_A
          || type == TelephonyManager.NETWORK_TYPE_1xRTT) {
        Log.e("LocatteMySeleftService", "CDMA");
        CdmaCellLocation cdmaCellLocation = (CdmaCellLocation) telephonyManager.getCellLocation();
        lac = cdmaCellLocation.getNetworkId();
        ci = cdmaCellLocation.getBaseStationId();
        int sid = cdmaCellLocation.getSystemId();

        int mcc = Integer.valueOf(telephonyManager.getNetworkOperator().substring(0, 3));

        JSONObject holder = new JSONObject();
        holder.put("version", "1.1.0");
        holder.put("host", "maps.google.com");
        holder.put("request_address", true);
        holder.put("radio_type", "cdma");
        JSONArray array = new JSONArray();
        JSONObject data = new JSONObject();
        data.put("cell_id", ci);
        data.put("location_area_code", lac);
        data.put("mobile_country_code", mcc);
        data.put("mobile_network_code", sid);
        data.put("address_language", "zh_CN");
        data.put("age", 0);
        array.put(data);
        holder.put("cell_towers", array);
        Log.e("LocateMySelftService", holder.toString());
        DefaultHttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost("http://www.google.com/loc/json");
        StringEntity se = new StringEntity(holder.toString());
        post.setEntity(se);
        org.apache.http.HttpResponse resp = client.execute(post);
        HttpEntity entity = resp.getEntity();
        BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));
        StringBuffer sb = new StringBuffer();
        String result = br.readLine();
        while (result != null) {
          sb.append(result);
          result = br.readLine();
        }
        Log.e("LocateMySelftService", sb.toString());
        JSONObject jsonObject = new JSONObject(sb.toString());

        JSONObject jsonObject1 = new JSONObject(jsonObject.getString("location"));

        getAddress(jsonObject1.getString("latitude"), jsonObject1.getString("longitude"));
      } else {
        handler.sendEmptyMessage(MESSAGE_FAILED_USING_BASE);
      }
    } catch (Exception e) {
      handler.sendEmptyMessage(MESSAGE_FAILED_USING_BASE);
    }
  }