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