use of com.att.aro.core.datacollector.pojo.StatusResult in project VideoOptimzer by attdevsupport.
the class NorootedAndroidCollectorImpl method pullTrace.
private StatusResult pullTrace(String[] files) {
StatusResult result = new StatusResult();
SyncService service = getSyncService();
if (service == null) {
result.setError(ErrorCodeRegistry.getFailSyncService());
return result;
}
String deviceTracePath = "";
String setCommand = "";
boolean commandFailure = false;
if (Util.isWindowsOS()) {
deviceTracePath = "/sdcard/ARO/";
setCommand = Util.wrapText(adbService.getAdbPath() + " -s " + device.getSerialNumber() + " pull " + deviceTracePath + ". " + Util.wrapText(localTraceFolder + "/ARO"));
commandFailure = runCommand(setCommand);
if (!commandFailure) {
setCommand = Util.wrapText("move " + Util.wrapText(localTraceFolder + "\\ARO\\*") + " " + Util.wrapText(localTraceFolder));
commandFailure = runCommand(setCommand);
}
if (!commandFailure) {
setCommand = Util.wrapText("rd " + Util.wrapText(localTraceFolder + "\\ARO"));
runCommand(setCommand);
}
if (!commandFailure) {
setCommand = Util.wrapText("rmdir /S /Q " + Util.wrapText(localTraceFolder + "\\ARO"));
}
} else {
deviceTracePath = "/sdcard/ARO/";
setCommand = adbService.getAdbPath() + " -s " + device.getSerialNumber() + " pull " + deviceTracePath + ". " + Util.wrapText(localTraceFolder);
commandFailure = runCommand(setCommand);
}
if (commandFailure) {
result.setError(ErrorCodeRegistry.getAdbPullFailure());
} else {
result.setSuccess(true);
}
return result;
}
use of com.att.aro.core.datacollector.pojo.StatusResult in project VideoOptimzer by attdevsupport.
the class NorootedAndroidCollectorImpl method startCollector.
/**
* Start collector in background and returns result which indicates success or error and detail data.
*
* @param folderToSaveTrace
* directory to save trace to
* @param videoOption
* optional flag to capture video of device. default is false
* @param isLiveViewVideo
* ignored here
* @param androidId
* optional id of device to capture. default is the connected device.
* @param extraParams
* optional data to pass to collectors. required by some collectors.
* @return a StatusResult to hold result and success or failure
*/
@Override
public StatusResult startCollector(boolean isCommandLine, String folderToSaveTrace, VideoOption videoOption_deprecated, boolean isLiveViewVideo, String deviceId, Hashtable<String, Object> extraParams, String password) {
LOG.info("startCollector() for non-rooted-android-collector");
if (deviceChangeListener == null) {
initDeviceChangeListener();
}
AttenuatorModel atnr = new AttenuatorModel();
int throttleDL = -1;
int throttleUL = -1;
boolean atnrProfile = false;
String location = "";
String selectedAppName = "";
Orientation videoOrientation = Orientation.PORTRAIT;
if (extraParams != null) {
atnr = (AttenuatorModel) getOrDefault(extraParams, "AttenuatorModel", atnr);
videoOption = (VideoOption) getOrDefault(extraParams, "video_option", VideoOption.NONE);
videoOrientation = (Orientation) getOrDefault(extraParams, "videoOrientation", Orientation.PORTRAIT);
selectedAppName = (String) getOrDefault(extraParams, "selectedAppName", StringUtils.EMPTY);
traceDesc = (String) getOrDefault(extraParams, "traceDesc", StringUtils.EMPTY);
traceType = (String) getOrDefault(extraParams, "traceType", StringUtils.EMPTY);
targetedApp = (String) getOrDefault(extraParams, "targetedApp", StringUtils.EMPTY);
appProducer = (String) getOrDefault(extraParams, "appProducer", StringUtils.EMPTY);
}
int bitRate = videoOption.getBitRate();
String screenSize = videoOption.getScreenSize();
StatusResult result = new StatusResult();
// find the device by the id
result = findDevice(deviceId, result);
if (!result.isSuccess()) {
return result;
}
this.running = isCollectorRunning();
// avoid running it twice
if (this.running) {
LOG.error("unknown collection still running on device");
result.setError(ErrorCodeRegistry.getCollectorAlreadyRunning());
result.setSuccess(false);
return result;
}
if (filemanager.directoryExistAndNotEmpty(folderToSaveTrace)) {
result.setError(ErrorCodeRegistry.getTraceDirExist());
return result;
}
// there might be permission issue to creating dir to save trace
filemanager.mkDir(folderToSaveTrace);
if (!filemanager.directoryExist(folderToSaveTrace)) {
result.setError(ErrorCodeRegistry.getFailedToCreateLocalTraceDirectory());
result.setSuccess(false);
return result;
}
aroDevice = new AROAndroidDevice(device, false);
cleanARO();
if (device.isEmulator()) {
if (!aroDevice.getAbi().equals("x86_64")) {
String message = "Emulator ABI:" + aroDevice.getAbi() + " does not support VPN collection! use an x86_64 instead.";
LOG.error(message);
result.setError(ErrorCodeRegistry.getNotSupported(message));
return result;
}
}
// Is this required?????
LOG.debug("check VPN");
if (isVpnActivated()) {
LOG.error("unknown collection still running on device");
result.setError(ErrorCodeRegistry.getCollectorAlreadyRunning());
result.setSuccess(false);
return result;
}
this.localTraceFolder = folderToSaveTrace;
// there might be an instance of vpn_collector running
// to be sure it is not in memory
this.haltCollectorInDevice();
new LogcatCollector(adbService, device.getSerialNumber()).clearLogcat();
atnrProfile = atnr.isLoadProfile();
if (atnrProfile) {
// default
int apiNumber = AndroidApiLevel.K19.levelNumber();
try {
apiNumber = Integer.parseInt(aroDevice.getApi());
} catch (Exception e) {
LOG.error("unknown device api number");
}
location = (String) atnr.getLocalPath();
AttnScriptUtil util = new AttnScriptUtil(apiNumber);
boolean scriptResult = util.scriptGenerator(location);
if (!scriptResult) {
result.setError(ErrorCodeRegistry.getScriptAdapterError(location));
result.setSuccess(false);
return result;
}
this.attnrScriptRun = true;
} else if (atnr.isConstantThrottle()) {
if (atnr.isThrottleDLEnabled()) {
throttleDL = atnr.getThrottleDL();
}
if (atnr.isThrottleULEnabled()) {
throttleUL = atnr.getThrottleUL();
}
}
if (pushApk(this.device)) {
try {
// This is a temporary fix, the real fix needs to be investigated. Follow up with Bug # ARO22945-1571
Thread.sleep(1000);
} catch (InterruptedException e) {
LOG.error("Something went wrong while trying to install the apk", e);
}
if (apkInstalled && (boolean) getOrDefault(extraParams, "assignPermission", false)) {
applyPermissionsOverADB();
apkInstalled = false;
}
String cmd;
cmd = "am start -n com.att.arocollector/com.att.arocollector.AROCollectorActivity" + // + " --ei delayDL " + delayTimeDL + " --ei delayUL " + delayTimeUL
" --ei throttleDL " + throttleDL + " --ei throttleUL " + throttleUL + (atnrProfile ? (" --ez profile " + atnrProfile + " --es profilename '" + location + "'") : "") + " --es video " + videoOption.toString() + " --ei bitRate " + bitRate + " --es screenSize " + screenSize + " --es videoOrientation " + videoOrientation.toString() + " --es selectedAppName " + (StringUtils.isEmpty(selectedAppName) ? "EMPTY" : selectedAppName) + " --activity-single-top --activity-clear-top";
LOG.info(cmd);
if (!android.runApkInDevice(this.device, cmd)) {
result.setError(ErrorCodeRegistry.getFaildedToRunVpnApk());
result.setSuccess(false);
return result;
}
} else {
result.setError(ErrorCodeRegistry.getFailToInstallAPK());
result.setSuccess(false);
return result;
}
if (!isTrafficCaptureRunning(MILLISECONDSFORTIMEOUT)) {
// timeout while waiting for VPN to activate within 15 seconds
timeOutShutdown();
result.setError(ErrorCodeRegistry.getTimeoutVpnActivation());
result.setSuccess(false);
return result;
} else {
// Write environment details
try {
EnvironmentDetails environmentDetails = new EnvironmentDetails(folderToSaveTrace);
environmentDetails.populateDeviceInfo(aroDevice.getOS(), aroDevice.isRooted(), aroDevice.getPlatform().name());
FileWriter writer = new FileWriter(folderToSaveTrace + "/environment_details.json");
writer.append(new ObjectMapper().writeValueAsString(environmentDetails));
writer.close();
} catch (IOException e) {
LOG.error("Error while writing environment details", e);
}
}
new Thread(() -> {
GoogleAnalyticsUtil.getGoogleAnalyticsInstance().sendAnalyticsEvents(GoogleAnalyticsUtil.getAnalyticsEvents().getNonRootedCollector(), GoogleAnalyticsUtil.getAnalyticsEvents().getStartTrace(), aroDevice != null && aroDevice.getApi() != null ? aroDevice.getApi() : "Unknown");
GoogleAnalyticsUtil.getGoogleAnalyticsInstance().sendAnalyticsEvents(GoogleAnalyticsUtil.getAnalyticsEvents().getNonRootedCollector(), GoogleAnalyticsUtil.getAnalyticsEvents().getVideoCheck(), videoOption != null ? videoOption.name() : "Unknown");
}).start();
if (isAndroidVersionNougatOrHigher(this.device) == true) {
startCpuTraceCapture();
}
if (isVideo()) {
startVideoCapture();
}
startUserInputCapture();
startUiXmlCapture();
if (atnrProfile) {
// wait for vpn collection start
startAttnrProfile(location);
}
result.setSuccess(true);
this.running = true;
LOG.info("Trace collection started for the non-rooted-android-collector");
return result;
}
use of com.att.aro.core.datacollector.pojo.StatusResult in project VideoOptimzer by attdevsupport.
the class NorootedAndroidCollectorImplTest method startCollectorTest.
@Ignore
@Test
public void startCollectorTest() {
// Hashtable extranalParams = Mockito.mock(Hashtable.class);
Hashtable<String, Object> extranalParams = new Hashtable<String, Object>();
Mockito.when(fileManager.directoryExistAndNotEmpty(Mockito.anyString())).thenReturn(true);
StatusResult sResult = null;
sResult = nonRootedAndroidCollector.startCollector(true, "test", VideoOption.NONE, false, "testDeice", extranalParams, null);
assertEquals(402, sResult.getError().getCode());
Mockito.when(fileManager.directoryExistAndNotEmpty(Mockito.anyString())).thenReturn(false);
Mockito.doNothing().when(fileManager).mkDir(Mockito.anyString());
Mockito.when(fileManager.directoryExist(Mockito.anyString())).thenReturn(false);
sResult = nonRootedAndroidCollector.startCollector(true, "test", VideoOption.NONE, false, "testDeice", extranalParams, null);
assertEquals(406, sResult.getError().getCode());
Mockito.when(fileManager.directoryExist(Mockito.anyString())).thenReturn(true);
IDevice aDevice1 = Mockito.mock(IDevice.class);
Mockito.when(aDevice1.getSerialNumber()).thenReturn("device1");
IDevice[] devices = { aDevice1 };
IDevice[] returnDevices = {};
try {
Mockito.when(adbService.getConnectedDevices()).thenReturn(returnDevices);
} catch (Exception exp) {
exp.printStackTrace();
}
sResult = nonRootedAndroidCollector.startCollector(true, "test", VideoOption.NONE, false, "testDeice", extranalParams, null);
assertEquals(403, sResult.getError().getCode());
try {
Mockito.when(adbService.getConnectedDevices()).thenReturn(devices);
} catch (Exception exp) {
exp.printStackTrace();
}
sResult = nonRootedAndroidCollector.startCollector(true, "test", VideoOption.NONE, false, "testDeice", extranalParams, null);
assertEquals(404, sResult.getError().getCode());
Mockito.when(android.removeEmulatorData(Mockito.any(IDevice.class), Mockito.anyString())).thenReturn(true);
Mockito.when(android.makeDirectory(Mockito.any(IDevice.class), Mockito.anyString())).thenReturn(true);
String[] str1 = {};
Mockito.when(android.getShellReturn(Mockito.any(IDevice.class), Mockito.anyString())).thenReturn(str1);
// Mockito.doNothing().when(android).getShellReturn(Mockito.any(IDevice.class), Mockito.anyString());
Mockito.when(fileManager.fileExist(Mockito.anyString())).thenReturn(true);
Mockito.when(android.runApkInDevice(Mockito.any(IDevice.class), Mockito.anyString())).thenReturn(false);
sResult = nonRootedAndroidCollector.startCollector(true, "test", VideoOption.NONE, false, "device1", extranalParams, null);
assertEquals(405, sResult.getError().getCode());
Mockito.when(fileManager.fileExist(Mockito.anyString())).thenReturn(false);
Mockito.when(extractor.extractFiles(Mockito.anyString(), Mockito.anyString(), Mockito.any(ClassLoader.class))).thenReturn(false);
sResult = nonRootedAndroidCollector.startCollector(true, "test", VideoOption.NONE, false, "device1", extranalParams, null);
assertEquals(401, sResult.getError().getCode());
Mockito.when(android.getShellReturn(Mockito.any(IDevice.class), Mockito.anyString())).thenReturn(noVpnCon);
Mockito.when(fileManager.fileExist(Mockito.anyString())).thenReturn(true);
Mockito.when(android.runApkInDevice(Mockito.any(IDevice.class), Mockito.anyString())).thenReturn(true);
// sResult = nonRootedAndroidCollector.startCollector(true, "test", false, "device1", extranalParams, null);
// assertEquals(407, sResult.getError().getCode());
Mockito.when(android.getShellReturn(Mockito.any(IDevice.class), Mockito.anyString())).thenReturn(noVpnCon).thenReturn(vpnActive);
sResult = nonRootedAndroidCollector.startCollector(true, "test", VideoOption.NONE, false, "device1", extranalParams, null);
assertTrue(sResult.isSuccess());
Mockito.when(android.getShellReturn(Mockito.any(IDevice.class), Mockito.anyString())).thenReturn(vpnActive).thenReturn(noVpnCon);
nonRootedAndroidCollector.stopRunning();
Mockito.when(android.getShellReturn(Mockito.any(IDevice.class), Mockito.anyString())).thenReturn(noVpnCon).thenReturn(vpnActive);
sResult = nonRootedAndroidCollector.startCollector(true, "test", VideoOption.NONE, null);
assertTrue(sResult.isSuccess());
nonRootedAndroidCollector.stopRunning();
try {
Mockito.doNothing().when(videoCapture).init(Mockito.any(IDevice.class), Mockito.anyString());
Mockito.doNothing().when(videoCapture).addSubscriber(Mockito.any(IVideoImageSubscriber.class));
Mockito.doNothing().when(threadExecutor).execute(Mockito.any(IVideoCapture.class));
} catch (IOException e) {
e.printStackTrace();
}
Mockito.when(android.getShellReturn(Mockito.any(IDevice.class), Mockito.anyString())).thenReturn(noVpnCon).thenReturn(vpnActive);
sResult = nonRootedAndroidCollector.startCollector(true, "test", VideoOption.LREZ, false, "device1", extranalParams, null);
assertTrue(sResult.isSuccess());
nonRootedAndroidCollector.stopRunning();
try {
Mockito.when(adbService.getConnectedDevices()).thenThrow(new Exception("AndroidDebugBridge failed to start"));
} catch (Exception exp) {
exp.printStackTrace();
}
Mockito.when(android.getShellReturn(Mockito.any(IDevice.class), Mockito.anyString())).thenReturn(noVpnCon).thenReturn(vpnActive);
sResult = nonRootedAndroidCollector.startCollector(true, "test", VideoOption.LREZ, false, "device1", extranalParams, null);
assertEquals(400, sResult.getError().getCode());
}
use of com.att.aro.core.datacollector.pojo.StatusResult in project VideoOptimzer by attdevsupport.
the class NorootedAndroidCollectorImplTest method stopCollector.
@Ignore
@Test
public void stopCollector() {
String[] str1 = {};
Mockito.when(android.getShellReturn(Mockito.any(IDevice.class), Mockito.anyString())).thenReturn(str1);
String[] str2 = { "some ip " };
Mockito.when(android.getShellReturn(Mockito.any(IDevice.class), Mockito.anyString())).thenReturn(str2);
try {
Mockito.doNothing().when(fileManager).saveFile(Mockito.any(InputStream.class), Mockito.anyString());
} catch (IOException IOExp) {
IOExp.printStackTrace();
}
Mockito.doNothing().when(videoCapture).stopRecording();
Mockito.when(android.removeEmulatorData(Mockito.any(IDevice.class), Mockito.anyString())).thenReturn(true);
StatusResult sResult = null;
SyncService sycService = null;
try {
Mockito.when(device.getSyncService()).thenReturn(sycService);
} catch (TimeoutException e1) {
e1.printStackTrace();
} catch (AdbCommandRejectedException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
sResult = nonRootedAndroidCollector.stopCollector();
assertEquals(411, sResult.getError().getCode());
sycService = Mockito.mock(SyncService.class);
try {
Mockito.when(device.getSyncService()).thenReturn(sycService);
} catch (TimeoutException e1) {
e1.printStackTrace();
} catch (AdbCommandRejectedException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
try {
Mockito.doNothing().when(sycService).pullFile(Mockito.anyString(), Mockito.anyString(), Mockito.any(ISyncProgressMonitor.class));
} catch (SyncException e) {
e.printStackTrace();
} catch (TimeoutException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
sResult = nonRootedAndroidCollector.stopCollector();
assertTrue(sResult.isSuccess());
Hashtable<String, Object> extranalParams = new Hashtable<String, Object>();
Mockito.when(fileManager.directoryExistAndNotEmpty(Mockito.anyString())).thenReturn(false);
Mockito.doNothing().when(fileManager).mkDir(Mockito.anyString());
Mockito.when(fileManager.directoryExist(Mockito.anyString())).thenReturn(true);
IDevice aDevice1 = Mockito.mock(IDevice.class);
Mockito.when(aDevice1.getSerialNumber()).thenReturn("device1");
IDevice[] devices = { aDevice1 };
try {
Mockito.when(adbService.getConnectedDevices()).thenReturn(devices);
} catch (Exception exp) {
exp.printStackTrace();
}
Mockito.when(fileManager.fileExist(Mockito.anyString())).thenReturn(true);
Mockito.when(android.runApkInDevice(Mockito.any(IDevice.class), Mockito.anyString())).thenReturn(true);
String[] str3 = { "some ip ", "tun0: ip 10. some" };
Mockito.when(android.getShellReturn(Mockito.any(IDevice.class), Mockito.anyString())).thenReturn(str3);
try {
Mockito.doNothing().when(videoCapture).init(Mockito.any(IDevice.class), Mockito.anyString());
Mockito.doNothing().when(videoCapture).addSubscriber(Mockito.any(IVideoImageSubscriber.class));
Mockito.doNothing().when(threadExecutor).execute(Mockito.any(IVideoCapture.class));
} catch (IOException e) {
e.printStackTrace();
}
nonRootedAndroidCollector.stopRunning();
Mockito.when(android.getShellReturn(Mockito.any(IDevice.class), Mockito.anyString())).thenReturn(noVpnCon).thenReturn(vpnActive);
sResult = nonRootedAndroidCollector.startCollector(true, "test", VideoOption.LREZ, false, "device1", extranalParams, null);
assertTrue(sResult.isSuccess());
Date aDate = new Date();
Mockito.when(videoCapture.getVideoStartTime()).thenReturn(aDate);
sResult = nonRootedAndroidCollector.stopCollector();
assertEquals(411, sResult.getError().getCode());
}
use of com.att.aro.core.datacollector.pojo.StatusResult in project VideoOptimzer by attdevsupport.
the class RootedAndroidCollectorImpl method pullTrace.
/**
* Pulls trace files
*
* @param files
* String array of trace files to pull
* @return StatusResult for success/failure
*/
private StatusResult pullTrace(String[] files) {
StatusResult result = new StatusResult();
SyncService service = null;
try {
service = device.getSyncService();
} catch (TimeoutException e) {
log.error("Timeout error when getting SyncService from device");
} catch (AdbCommandRejectedException e) {
log.error(e.getMessage());
} catch (IOException e) {
log.error("IOException", e);
}
if (service == null) {
result.setError(ErrorCodeRegistry.getFailSyncService());
return result;
}
// first pull the last file to be prepared by AroDataCollector.APK
String alarmInfoStart = "alarm_info_start";
int count = 5;
File traceAlarmInfoStart = new File(this.localTraceFolder + "/" + alarmInfoStart);
while (!(traceAlarmInfoStart.exists() && traceAlarmInfoStart.length() > 0) && count-- > 0) {
try {
log.debug("alarm_info_start was missing or zero length, will sleep then pull again");
Thread.sleep(500);
} catch (InterruptedException e) {
log.error("InterruptedException", e);
}
pullFile(service, alarmInfoStart);
}
// now pull the rest of the trace files
deviceTracePath = "/sdcard/ARO/" + this.traceName + "/";
for (String file : files) {
pullFile(service, file);
}
result.setSuccess(true);
return result;
}
Aggregations