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