Пример #1
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;
  }
Пример #2
0
  public String getDeviceInfo(
      String sTestType, String sTestName, String sUsername, String sMarketId) {

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

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

    device_id = telephonyManager.getDeviceId();
    cell_info = telephonyManager.getCallState();
    phone_type = telephonyManager.getPhoneType();
    phone_number = "";

    phone_number = telephonyManager.getLine1Number();
    if (phone_number == null) phone_number = "";
    if (phone_number.equals("")) phone_number = telephonyManager.getSubscriberId();
    phone_model = android.os.Build.MODEL;
    phone_model = XMLUtils.clean(phone_model);
    manufacturer = android.os.Build.MANUFACTURER;
    manufacturer = XMLUtils.clean(manufacturer);
    version = android.os.Build.VERSION.RELEASE;

    // 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;
    	}

    }*/

    strBuffer.append(DEVICEINFO_START);
    strBuffer.append(METADATA_START);
    strBuffer.append(TIMESTAMP_START);
    strBuffer.append(TimeUtil.getCurrentTime());
    strBuffer.append(TIMESTAMP_END);
    strBuffer.append(IMEI_START);
    strBuffer.append(device_id);
    strBuffer.append(IMEI_END);
    strBuffer.append(TESTTYPE_START);
    strBuffer.append(sTestType);
    strBuffer.append(TESTTYPE_END);
    strBuffer.append(TEST_NAME_START);
    strBuffer.append(sTestName);
    strBuffer.append(TEST_NAME_END);
    strBuffer.append(USERNAME_NAME_START);
    strBuffer.append(sUsername);
    strBuffer.append(USERNAME_NAME_END);
    strBuffer.append(MARKET_ID_START);
    strBuffer.append(sMarketId);
    strBuffer.append(MARKET_ID_END);
    strBuffer.append(METADATA_END);

    strBuffer.append(DEVICE_START);

    strBuffer.append(IMEI_START);
    if (device_id != null) strBuffer.append(device_id);

    strBuffer.append(IMEI_END);

    strBuffer.append(PHONE_NUMBER_START);
    if (phone_number != null) strBuffer.append(phone_number);
    strBuffer.append(PHONE_NUMBER_END);

    strBuffer.append(PHONE_TYPE_START);
    strBuffer.append(getPhoneTypeString(phone_type));
    strBuffer.append(PHONE_TYPE_END);

    strBuffer.append(PHONE_MODEL_START);
    if (phone_model != null) strBuffer.append(phone_model);
    strBuffer.append(PHONE_MODEL_END);

    strBuffer.append(MANUFACTURER_START);
    if (manufacturer != null) strBuffer.append(manufacturer);
    strBuffer.append(MANUFACTURER_END);

    strBuffer.append(VERSION_START);
    if (version != null) strBuffer.append(version);
    strBuffer.append(VERSION_END);

    strBuffer.append(DEVICE_END);

    xmlFile = strBuffer.toString();

    return xmlFile;
  }