use of com.att.aro.core.mobiledevice.pojo.AROAndroidDevice in project VideoOptimzer by attdevsupport.
the class RootedAndroidCollectorImpl method startCollector.
/**
* Start the rooted collector both for device and emulator<br>
*
* 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
* this flag is ignored in Android
* @return a StatusResult to hold result and success or failure
*/
@Override
public StatusResult startCollector(boolean isCommandLine, String folderToSaveTrace, VideoOption videoOption_old, boolean isLiveViewVideo, String deviceId, Hashtable<String, Object> extraParams, String password) {
VideoOption m_videoOption = VideoOption.NONE;
if (extraParams != null) {
m_videoOption = (VideoOption) extraParams.get("video_option");
if (m_videoOption == null) {
m_videoOption = VideoOption.NONE;
}
}
log.info("<" + Util.getMethod() + "> startCollector() for rooted-android-collector");
StatusResult result = new StatusResult();
// avoid running it twice
if (this.running) {
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());
return result;
}
// check for any connected device
IDevice[] devlist = null;
try {
devlist = adbservice.getConnectedDevices();
} catch (Exception e1) {
if (e1.getMessage().contains("AndroidDebugBridge failed to start")) {
result.setError(ErrorCodeRegistry.getAndroidBridgeFailedToStart());
return result;
}
log.error("Exception :", e1);
}
if (devlist == null || devlist.length < 1) {
result.setError(ErrorCodeRegistry.getNoDeviceConnected());
return result;
}
device = null;
if (deviceId == null) {
device = devlist[0];
} else {
for (IDevice dev : devlist) {
if (deviceId.equals(dev.getSerialNumber())) {
device = dev;
break;
}
}
if (device == null) {
result.setError(ErrorCodeRegistry.getDeviceIdNotFound());
return result;
}
}
if (!device.getState().equals(DeviceState.ONLINE)) {
log.error("Android device is not online.");
result.setError(ErrorCodeRegistry.getDeviceNotOnline());
return result;
}
if (device.isEmulator()) {
IAroDevice aroDevice = new AROAndroidDevice(device, false);
if (!aroDevice.getAbi().contains("arm")) {
String message = "Emulator ABI:" + aroDevice.getAbi() + " does not support VPN collection! Use an armeabi instead.";
log.error(message);
result.setError(ErrorCodeRegistry.getNotSupported(message));
return result;
}
}
aroDevice = new AROAndroidDevice(device, true);
// device must be rooted to work
try {
if (androidDev.isAndroidRooted(device)) {
log.debug("device is detected to be rooted");
} else {
result.setError(ErrorCodeRegistry.getRootedStatus());
return result;
}
} catch (Exception exception) {
log.error("Failed to root test device ", exception);
result.setError(ErrorCodeRegistry.getProblemAccessingDevice(exception.getMessage()));
return result;
}
try {
device.createForward(TCPDUMP_PORT, TCPDUMP_PORT);
} catch (TimeoutException e) {
log.error("Timeout when creating port forwading: " + e.getMessage());
} catch (AdbCommandRejectedException e) {
log.error(e.getMessage());
} catch (IOException e) {
log.error(e.getMessage());
}
// check for running collector first => both tcpdump and ARO android app
if (android.checkTcpDumpRunning(device)) {
result.setError(ErrorCodeRegistry.getCollectorAlreadyRunning());
return result;
}
String tracename = folderToSaveTrace.substring(folderToSaveTrace.lastIndexOf(Util.FILE_SEPARATOR) + 1);
this.traceName = tracename;
this.localTraceFolder = folderToSaveTrace;
// delete all previous ARO traces on device or emulator /sdcard/ARO
android.removeEmulatorData(device, "/sdcard/ARO");
android.makeAROTraceDirectory(device, tracename);
this.videoOption = m_videoOption;
// check SELinux mode: true if SELinux-Enforced, false if permissive
try {
seLinuxEnforced = androidDev.isSeLinuxEnforced(device);
} catch (Exception e) {
// Failed to detect so assume not enforced
log.info("Failed to detect SELinux mode:" + e.getMessage());
seLinuxEnforced = false;
}
if (device.isEmulator()) {
// run collector inside Emulator
result = launchCollectorInEmulator(device, tracename, m_videoOption, extraParams);
} else {
GoogleAnalyticsUtil.getGoogleAnalyticsInstance().sendAnalyticsEvents(GoogleAnalyticsUtil.getAnalyticsEvents().getRootedCollector(), // GA Request
GoogleAnalyticsUtil.getAnalyticsEvents().getStartTrace());
// run collector inside Android device
result = launchCollectorInDevice(device, tracename, m_videoOption, extraParams);
}
if (result.isSuccess()) {
this.running = isTrafficCaptureRunning(getMilliSecondsForTimeout());
if (this.running) {
log.info("collector is running successfully");
} else {
timeOutShutdown();
haltCollectorInDevice();
log.info("collector timeout, traffic capture not started in time");
result.setSuccess(false);
result.setError(ErrorCodeRegistry.getCollectorTimeout());
result.setData("installed but traffic capture failed to start before timeout");
return result;
}
}
if (isVideo()) {
GoogleAnalyticsUtil.getGoogleAnalyticsInstance().sendAnalyticsEvents(GoogleAnalyticsUtil.getAnalyticsEvents().getRootedCollector(), // GA Request
GoogleAnalyticsUtil.getAnalyticsEvents().getVideoCheck());
startVideoCapture();
}
return result;
}
use of com.att.aro.core.mobiledevice.pojo.AROAndroidDevice in project VideoOptimzer by attdevsupport.
the class DataCollectorSelectNStartDialog method startButtonActionListener.
private ActionListener startButtonActionListener() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
LOG.debug("Button.start");
String traceFolderName = traceFolderNameField.getText();
AttnrRadioGroupPanel radioGP = getDeviceOptionPanel().getAttnrGroup().getAttnrRadioGP();
if (radioGP.getSliderBtn().isSelected()) {
boolean isAttenuateSelected = radioGP.getThroughputPanel().getDownloadCheckBox().isSelected() || radioGP.getThroughputPanel().getUploadCheckBox().isSelected();
if (!isAttenuateSelected) {
LOG.info("need to set at least one DL or UL for the throttle");
proceed = false;
showAttenuationError();
return;
}
}
boolean secureOrAttnEnabled = deviceOptionPanel.getAttnrGroup().getAttnrRadioGP().getSliderBtn().isSelected();
if (deviceTablePanel.getSelection().isPlatform(Platform.iOS)) {
if (deviceTablePanel.getSelection().getProductName() == null || deviceTablePanel.getSelection().getModel() == null) {
JOptionPane.showMessageDialog(DataCollectorSelectNStartDialog.this, ResourceBundleHelper.getMessageString("Error.app.nolibimobiledevice"), MessageFormat.format(ResourceBundleHelper.getMessageString("Error.app.noprerequisitelib"), ApplicationConfig.getInstance().getAppShortName()), JOptionPane.ERROR_MESSAGE);
return;
}
if (secureOrAttnEnabled && (!deviceOptionPanel.isSharedNetworkActive())) {
new IOSStepsDialog(DataCollectorSelectNStartDialog.this);
return;
}
}
// don't allow whitespace
traceFolderName = traceFolderName.replaceAll("\\s", "");
if (!traceFolderName.isEmpty()) {
proceed = true;
if (traceFolderNameField.getText() != null) {
if (isContainsSpecialCharacterorSpace(traceFolderNameField.getText())) {
JOptionPane.showMessageDialog(getCollectorDialogComponent(), ResourceBundleHelper.getMessageString("Error.specialchar"), MessageFormat.format(ResourceBundleHelper.getMessageString("aro.title.short"), ApplicationConfig.getInstance().getAppShortName()), JOptionPane.ERROR_MESSAGE);
return;
} else if (traceFolderNameField.getText().toString().length() > TRACE_FOLDER_ALLOWED_LENGTH) {
JOptionPane.showMessageDialog(getCollectorDialogComponent(), ResourceBundleHelper.getMessageString("Error.tracefolderlength"), MessageFormat.format(ResourceBundleHelper.getMessageString("aro.title.short"), ApplicationConfig.getInstance().getAppShortName()), JOptionPane.ERROR_MESSAGE);
return;
} else {
DataCollectorSelectNStartDialog.this.dispose();
}
}
} else {
LOG.info("traceFolderName is blank");
proceed = false;
JOptionPane.showMessageDialog(getCollectorDialogComponent(), ResourceBundleHelper.getMessageString("Error.tracefolderempty"), MessageFormat.format(ResourceBundleHelper.getMessageString("aro.title.short"), ApplicationConfig.getInstance().getAppShortName()), JOptionPane.ERROR_MESSAGE);
traceFolderNameField.requestFocus();
}
if (deviceTablePanel.getSelection().isPlatform(Platform.Android) && !((AROAndroidDevice) deviceTablePanel.getSelection()).isAPKInstalled()) {
if (MessageDialogFactory.showConfirmDialog(getCollectorDialogComponent(), ResourceBundleHelper.getMessageString("Message.permissions.warning"), MessageFormat.format(ResourceBundleHelper.getMessageString("aro.title.short"), ApplicationConfig.getInstance().getAppShortName()), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
((MainFrame) getMainframeParent()).setAutoAssignPermissions(true);
} else {
((MainFrame) getMainframeParent()).setAutoAssignPermissions(false);
}
}
}
};
}
use of com.att.aro.core.mobiledevice.pojo.AROAndroidDevice 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;
}
Aggregations