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