Exemplo n.º 1
0
    private Message doUpload(String sLogcatFilePath, String sDevInfoXMLFilePath) {

      Message msg = new Message();
      Bundle bndle = new Bundle();

      String sResponseCode = "", sResponseDesc = "";

      try {
        APIManager apiClient = new APIManager(activity);

        String sIMEI = new DeviceUtil(activity).getIMEI();
        Preferences pref = new Preferences(activity);
        String sUsername = pref.getUsername();
        String sPwd = pref.getPassword();
        APIManager.Status status = APIManager.Status.NONE;

        if (Validator.isEmpty(sLogcatFilePath)) {
          status = apiClient.processUploadSingle(sDevInfoXMLFilePath);
        } else {
          status =
              apiClient.processUpload(sUsername, sPwd, sIMEI, sLogcatFilePath, sDevInfoXMLFilePath);
        }

        if (status == APIManager.Status.ERROR) {
          sResponseCode = ResponseCodes.FAILURE;
          sResponseDesc = apiClient.getErrorMessage();
        } else {
          String sResponse = apiClient.getResponse();
          L.debug("Upload Response :: " + sResponse);
          if (sResponse != null
              && sResponse.trim().equalsIgnoreCase(ResponseCodes.SUCCESS_UPLOAD)) {
            sResponseCode = ResponseCodes.SUCCESS;
            sResponseDesc = "Result uploaded!";
          } else {
            sResponseCode = ResponseCodes.FAILURE;
            sResponseDesc = sResponse;
          }
        }
      } catch (Exception e) {
        e.printStackTrace();
        sResponseCode = ResponseCodes.FAILURE;
        sResponseDesc = Messages.err(e);
      }
      if (Constants.DELETE_FILES_AFTER_UPLOAD)
        if (sResponseCode.equals(ResponseCodes.SUCCESS)) {
          // Delete log files
          FileUtil.delete(sDevInfoXMLFilePath);
          FileUtil.delete(sLogcatFilePath);
        }
      bndle.putString(StringUtils.CODE, sResponseCode);
      bndle.putString(StringUtils.DESC, sResponseDesc);
      msg.setData(bndle);
      return msg;
    }
Exemplo n.º 2
0
        @Override
        public void handleMessage(Message msg) {
          if (!pref.isTestCanceled() && pref.isTestRunning()) {
            L.debug("DownloadAndUploadCompletedHandler...");
            pref.setFTPTestRunningState(false);

            // testconfig.getTestName()

            new ResultUploader(
                context,
                pref.getValue(Preferences.KEY_TEST_NAME, "")
                    + StringUtils.TEST_CYCLE_APPEND_FILE
                    + testconfig.getTestCycle(),
                StringUtils.TEST_TYPE_CODE_FTP,
                settings.getFTPDeviceInfoPath(),
                settings.getFTPLogcatPath()) {
              public void resultUploaded(String code, String desc) {
                doResultUploaded(code, desc);
              };
            };
          }
        }
Exemplo n.º 3
0
        @Override
        public void handleMessage(Message msg) {

          // ###################
          String sResponseCode = msg.getData().getString(StringUtils.CODE);
          String sResponseDesc = msg.getData().getString(StringUtils.DESC);

          clearFTPFiles();

          if (sResponseCode.equals(ResponseCodes.SUCCESS)) {
            L.debug("File download and upload success");
          } else {
            L.debug(sResponseDesc);

            if (!pref.isTestCanceled() && pref.isTestRunning()) {
              L.debug("RunnableFailed...");
              pref.setFTPTestRunningState(false);

              /*
               * NotificationUtil.showFinishedNotification( context,
               * StringUtils.TEST_TYPE_CODE_FTP, testconfig.getTestName()
               * + "_" + testconfig.getTestCycle(),
               * Messages.FTP_DOWNLOAD_FAILED);
               */

              NotificationUtil.showFinishedNotification(
                  context,
                  StringUtils.TEST_TYPE_CODE_FTP,
                  pref.getValue(Preferences.KEY_TEST_NAME, "") + "_" + testconfig.getTestCycle(),
                  Messages.FTP_DOWNLOAD_FAILED);

              DeviceUtil.updateTestScreen();
              doResultUploaded(sResponseCode, sResponseDesc);
            }
          }
        }
Exemplo n.º 4
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;
  }
Exemplo n.º 5
0
  public void startTest() {

    deviceOSVersion = android.os.Build.VERSION.SDK_INT;
    L.debug("DEVICE OS VERSION: " + deviceOSVersion);

    FTPTestConfigObj = testconfig.getFTPTestConfig();

    /*
     *
     * String sTestName = testconfig.getTestName() +
     * StringUtils.TEST_CYCLE_APPEND_FILE + testconfig.getTestCycle();
     */

    String sTestName =
        pref.getValue(Preferences.KEY_TEST_NAME, "")
            + StringUtils.TEST_CYCLE_APPEND_FILE
            + testconfig.getTestCycle();

    pref.setFTPTestRunningState(true);

    DeviceUtil dv = new DeviceUtil(context);

    String sDeviceInfoXML =
        dv.getDeviceInfo(
            StringUtils.FILE_CODE_TEST_TYPE_FTP,
            sTestName,
            pref.getUsername(),
            pref.getValue(Preferences.KEY_SELECTED_MARKET_PLACE_ID, ""));
    L.debug(sDeviceInfoXML);

    String sCurrTime = TimeUtil.getCurrentTimeFilename();

    FileUtil.CURRENT_FTP_TESTTIME = sCurrTime;
    String path = FileUtil.FTP_LOG_DIR + "deviceinfo" + "_" + sTestName + "_" + sCurrTime + ".xml";
    File fle = new File(path);
    if (fle.exists()) {
      fle.delete();
    }
    String dev_info_path = FileUtil.writeToXMLFile(path, sDeviceInfoXML);
    L.debug("Device info initial data written into " + dev_info_path);

    pref.putValue(Preferences.KEY_CURRENT_FTP_DEV_INFO_PATH, dev_info_path);

    String logcat_path =
        FileUtil.FTP_LOG_DIR
            + StringUtils.FILE_CODE_TEST_TYPE_FTP
            + "_"
            + dv.getIMEI()
            + "_"
            + sTestName
            + "_"
            + sCurrTime
            + ".txt";

    L.debug("!!! logcat_path !!!!: " + logcat_path);

    File log_fle = new File(logcat_path);

    try {
      log_fle.createNewFile();
    } catch (IOException e) {
    }
    pref.putValue(Preferences.KEY_CURRENT_FTP_LOGCAT_PATH, log_fle.getAbsolutePath());
    try {
      Airometric app = (Airometric) context.getApplication();
      app.startListeners(dev_info_path);
    } catch (Exception e) {
      e.printStackTrace();
    }
    NotificationUtil.cancelNotification(context, StringUtils.TEST_TYPE_CODE_FTP);

    uploadTask = new StartTestTask();
    uploadTask.execute();
    Constants.CurrentTask = uploadTask;

    NotificationUtil.showRunningNotification(context, StringUtils.TEST_TYPE_CODE_FTP);
    context.showActivity(TestTypeActivity.class);
  }
Exemplo n.º 6
0
  protected void doDownloadAndUpload() {
    context.print("doDownloadAndUpload()...");
    Message msg = new Message();
    Bundle bndle = new Bundle();

    String sResponseCode = "", sResponseDesc = "";
    try {

      ftp = new FTP(handler);
      if (ftp.ftpConnect(sHostURL, sUsername, sPassword, port)) {

        timer = new Timer();
        uid = android.os.Process.myUid();
        if (Constants.OS_VERSION_JELLY_BEAN_MR2 <= deviceOSVersion) {
          StartRXBytes = DeviceUtil.getStats(uid).getReceiveCount();
          // StartRXBytes = TrafficStats.getUidRxBytes(uid);
          StartRXSegments = TrafficStats.getUidTcpRxSegments(uid);
        } else {
          StartRXBytes = TrafficStats.getUidTcpRxBytes(uid);
          StartRXSegments = TrafficStats.getUidTcpRxSegments(uid);
        }
        context.debug(
            "Initial RX bytes - " + StartRXBytes + ", Initial RX Segments - " + StartRXSegments);
        downloadTimerTask = new DownloadTimeTask();
        timer.schedule(downloadTimerTask, 0, Constants.FTP_LOG_INTERVAL * 1000);

        // Download

        if (ftp.ftpDownload(sDownloadSrcFilePath, sDownloadDestFilePath)) {
          context.print("File downloaded");
          sResponseCode = ResponseCodes.SUCCESS;
          timer.cancel();

          try {

            timer = new Timer();
            /*
            Constants.OS_VERSION_JELLY_BEAN_MR2 == deviceOSVersion
            		|| Constants.OS_VERSION_KIT_KAT == deviceOSVersion || Constants.OS_VERSION_LOLLIPOP == deviceOSVersion
            		|| Constants.OS_VERSION_LOLLIPOP_MR2 == deviceOSVersion || Constants.OS_VERSION_MARSHMALLOW == deviceOSVersion*/

            if (Constants.OS_VERSION_JELLY_BEAN_MR2 <= deviceOSVersion) {
              StartTXBytes = TrafficStats.getUidTxBytes(uid);
              StartTXSegments = TrafficStats.getUidTcpTxSegments(uid);
            } else {
              StartTXBytes = TrafficStats.getUidTcpTxBytes(uid);
              StartTXSegments = TrafficStats.getUidTcpTxSegments(uid);
            }

            context.debug(
                "Initial TX bytes - "
                    + StartTXBytes
                    + ", Initial TX segments - "
                    + StartTXSegments);
            uploadTimerTask = new UploadTimeTask();
            timer.schedule(uploadTimerTask, 0, Constants.FTP_LOG_INTERVAL * 1000);

            L.debug("Upload Section- src file path: " + sUploadSrcFilePath);
            L.debug("Upload Section- dest file path: " + sUploadDestDirPath);

            // Upload

            if (ftp.ftpUpload(
                sUploadSrcFilePath, new File(sUploadSrcFilePath).getName(), sUploadDestDirPath)) {
              context.print("File uploaded");
              sResponseCode = ResponseCodes.SUCCESS;
              L.debug("********* FTP UPLOADING SUCCESS **********");
            } else {
              context.print("File upload failed - " + ftp.getServerError());
              sResponseCode = StringUtils.ERROR_CODE;
              sResponseDesc = Messages.FTP_UPLOAD_FAILED + "(" + ftp.getServerError() + ")";
            }
          } catch (Exception e) {
            e.printStackTrace();
            sResponseCode = StringUtils.ERROR_CODE;
            sResponseDesc = Messages.FTP_UPLOAD_FAILED + "(" + Messages.err(e) + ")";
          }

        } else {
          context.print("File download failed - " + ftp.getServerError());
          sResponseCode = StringUtils.ERROR_CODE;
          sResponseDesc = Messages.FTP_DOWNLOAD_FAILED;
        }
        timer.cancel();
      } else {
        sResponseCode = StringUtils.ERROR_CODE;
        sResponseDesc = Messages.FTP_LOGIN_FAILED;
      }
      try {
        if (ftp.getClient().isConnected()) ftp.ftpDisconnect();
      } catch (Exception e) {

      }
    } catch (Exception e) {
      e.printStackTrace();
      sResponseCode = StringUtils.ERROR_CODE;
      sResponseDesc = Messages.err(e);
    }

    bndle.putString(StringUtils.CODE, sResponseCode);
    bndle.putString(StringUtils.DESC, sResponseDesc);
    msg.setData(bndle);
    if (!pref.isTestCanceled() && pref.isTestRunning()) DownloadAndUploadHandler.sendMessage(msg);
  }