use of com.att.aro.core.video.pojo.Orientation 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.video.pojo.Orientation in project VideoOptimzer by attdevsupport.
the class Application method runDataCollector.
/**
* Launches a DataCollection. Provides an input prompt for the user to stop the
* collection by typing "stop"
*
* <pre>
* Note:
* Do not exit collection by pressing a ctrl-c
* Doing so will exit ARO.Console but will not stop the trace on the device.
* </pre>
*
* @param context
* @param cmds
*/
// ignoring incorrect eclipse warning
@SuppressWarnings("null")
void runDataCollector(ApplicationContext context, Commands cmds) {
if (cmds.getOutput() != null) {
// LOGGER.info("runDataCollector");
IDataCollectorManager colmg = context.getBean(IDataCollectorManager.class);
colmg.getAvailableCollectors(context);
IDataCollector collector = null;
switch(cmds.getStartcollector()) {
case "rooted_android":
collector = colmg.getRootedDataCollector();
break;
case "vpn_android":
collector = colmg.getNorootedDataCollector();
break;
case "ios":
collector = colmg.getIOSCollector();
if (cmds.getSudo().isEmpty() || !collector.setPassword(cmds.getSudo())) {
printError(ErrorCodeRegistry.getInvalidPasswordError());
System.exit(1);
}
if ("hd".equals(cmds.getVideo()) || "sd".equals(cmds.getVideo())) {
printError(ErrorCodeRegistry.getInvalidiOSArgs());
System.exit(1);
}
break;
default:
printError(ErrorCodeRegistry.getCollectorNotfound());
System.exit(1);
break;
}
StatusResult result = null;
if (collector == null) {
printError(ErrorCodeRegistry.getCollectorNotfound());
System.exit(1);
}
if (cmds.getOverwrite().equalsIgnoreCase("yes")) {
String traceName = cmds.getOutput();
IFileManager filemanager = context.getBean(IFileManager.class);
filemanager.directoryDeleteInnerFiles(traceName);
}
OutSave outSave = prepareSystemOut();
AttenuatorModel model = getAttenuateModel(cmds);
// If the user want to collect regular iOS collection, they can proceed
if (DataCollectorType.IOS.equals(collector.getType()) && (model.isThrottleDLEnabled() || model.isThrottleULEnabled())) {
if (isIOSAttenuationConfirmed() && NetworkUtil.isNetworkUp("bridge100")) {
model.setConstantThrottle(true);
println("Collection proceeded.");
} else {
System.exit(1);
}
}
videoOption = configureVideoOption(cmds.getVideo());
try {
Hashtable<String, Object> extras = new Hashtable<String, Object>();
Orientation videoOrientation = getOrientation(cmds.getVideoOrientation());
extras.put("video_option", getVideoOption());
extras.put("videoOrientation", videoOrientation == null ? Orientation.PORTRAIT : videoOrientation);
extras.put("AttenuatorModel", model);
extras.put("assignPermission", false);
result = runCommand(cmds, collector, cmds.getSudo(), extras);
} finally {
restoreSystemOut(outSave);
}
if (result.getError() != null) {
outln("Caught an error:");
printError(result.getError());
} else {
outSave = prepareSystemOut();
try {
String input = "";
print("Data collector is running, enter stop to save trace and quit program");
print(">");
do {
input = readInput();
} while (!input.contains("stop"));
} finally {
restoreSystemOut(outSave);
}
println("stopping collector...");
try {
if (collector != null)
collector.stopCollector();
} finally {
restoreSystemOut(outSave);
}
println("collector stopped, trace saved to: " + cmds.getOutput());
cleanUp(context);
println("VO exited");
System.exit(0);
}
} else {
println("No output tracefolder was entered\n");
usageHelp();
System.exit(1);
}
}
Aggregations