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");
     }
   }
 }
Example #2
0
 @Override
 public void onCellLocationChanged(CellLocation location) {
   if (phoneType == TelephonyManager.PHONE_TYPE_CDMA) {
     CdmaCellLocation cdma = (CdmaCellLocation) location;
     CellLocationInfo.Params p = new CellLocationInfo.Params(baseStation);
     p.id = cdma.getBaseStationId();
     p.lat = cdma.getBaseStationLatitude();
     p.lon = cdma.getBaseStationLongitude();
     baseStation = new CellLocationInfo(p);
     notifyListeners(EVENT_CELL_LOCATION);
   }
 }
Example #3
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;
  }
  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);
    }
  }