Search in sources :

Example 1 with EnvironmentDetails

use of com.att.aro.core.datacollector.pojo.EnvironmentDetails 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;
}
Also used : EnvironmentDetails(com.att.aro.core.datacollector.pojo.EnvironmentDetails) FileWriter(java.io.FileWriter) AROAndroidDevice(com.att.aro.core.mobiledevice.pojo.AROAndroidDevice) AttenuatorModel(com.att.aro.core.peripheral.pojo.AttenuatorModel) IOException(java.io.IOException) Orientation(com.att.aro.core.video.pojo.Orientation) AttnScriptUtil(com.att.aro.core.util.AttnScriptUtil) AdbCommandRejectedException(com.android.ddmlib.AdbCommandRejectedException) InstallException(com.android.ddmlib.InstallException) TimeoutException(com.android.ddmlib.TimeoutException) IOException(java.io.IOException) StatusResult(com.att.aro.core.datacollector.pojo.StatusResult) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with EnvironmentDetails

use of com.att.aro.core.datacollector.pojo.EnvironmentDetails in project VideoOptimzer by attdevsupport.

the class IOSCollectorImpl method startCollector.

@Override
public StatusResult startCollector(boolean commandLine, String folderToSaveTrace, VideoOption videoOption, boolean liveViewVideo, String udId, Hashtable<String, Object> extraParams, String password) {
    if (extraParams != null) {
        this.videoOption = (VideoOption) extraParams.get("video_option");
        this.attenuatorModel = (AttenuatorModel) extraParams.get("AttenuatorModel");
    }
    hdVideoPulled = true;
    if (password != null && !validPW) {
        setPassword(password);
    }
    isCapturingVideo = isVideo();
    this.udId = udId;
    this.isCommandLine = commandLine;
    if (isCommandLine) {
        isLiveViewVideo = false;
    }
    this.isLiveViewVideo = liveViewVideo;
    StatusResult status = new StatusResult();
    status.setSuccess(true);
    // avoid running it twice
    if (this.running) {
        return status;
    }
    if (filemanager.directoryExistAndNotEmpty(folderToSaveTrace)) {
        status.setError(ErrorCodeRegistry.getTraceDirExist());
        return status;
    }
    // there might be permission issue to creating dir to save trace
    filemanager.mkDir(folderToSaveTrace);
    if (!filemanager.directoryExist(folderToSaveTrace)) {
        status.setError(ErrorCodeRegistry.getFailedToCreateLocalTraceDirectory());
        return status;
    }
    // initialize monitor, xcode and rvi
    status = init(status);
    if (!status.isSuccess()) {
        // an error has occurred in initialization
        LOG.error("Something went wrong while initializing monitor, xcode or rvi");
        return status;
    }
    if (udId == null || udId.length() < 2) {
        // Failed to get Serial Number of Device, connect an IOS device to start.
        LOG.error(defaultBundle.getString("Error.serialnumberconnection"));
        status.setSuccess(false);
        status.setError(ErrorCodeRegistry.getIncorrectSerialNumber());
    }
    if (!status.isSuccess()) {
        // failed to get device s/n
        return status;
    }
    datadir = folderToSaveTrace;
    localTraceFolder = new File(folderToSaveTrace);
    if (!localTraceFolder.exists()) {
        if (!localTraceFolder.mkdirs()) {
            datadir = "";
            // There was an error creating directory:
            LOG.error(defaultBundle.getString("Error.foldernamerequired"));
            status.setSuccess(false);
            status.setError(ErrorCodeRegistry.getMissingFolderName());
            return status;
        }
    }
    // "traffic.pcap";
    final String trafficFilePath = datadir + Util.FILE_SEPARATOR + defaultBundle.getString("datadump.trafficFile");
    // device info
    String deviceDetails = datadir + Util.FILE_SEPARATOR + "device_details";
    status = collectDeviceDetails(status, udId, deviceDetails);
    if (!status.isSuccess()) {
        LOG.error("Something went wrong while fetching the device information");
        // device info error
        return status;
    }
    GoogleAnalyticsUtil.getGoogleAnalyticsInstance().sendAnalyticsEvents(GoogleAnalyticsUtil.getAnalyticsEvents().getIosCollector(), GoogleAnalyticsUtil.getAnalyticsEvents().getStartTrace(), // GA
    deviceinfo != null && deviceinfo.getDeviceVersion() != null ? deviceinfo.getDeviceVersion() : "Unknown");
    if ("".equals(this.sudoPassword) || !validPW) {
        LOG.info(defaultBundle.getString("Error.sudopasswordissue"));
        if (isCommandLine) {
            status.setError(ErrorCodeRegistry.getSudoPasswordIssue());
            return status;
        } else {
            status.setData("requestPassword");
            // bad or missing sudo password
            return status;
        }
    }
    if (saveCollectorOptions == null) {
        saveCollectorOptions = new SaveCollectorOptions();
    }
    status = checkDumpcap(status);
    if (!status.isSuccess()) {
        LOG.error("Something went wrong while setting up dumpcap");
        return status;
    }
    if (isCapturingVideo) {
        status = startVideoCapture(status);
        if (!status.isSuccess()) {
            LOG.error("Something went wrong while starting the video capture");
            return status;
        }
    }
    if (isCapturingVideo && isLiveViewVideo) {
        if (isDeviceConnected) {
            LOG.info("device is connected");
        } else {
            LOG.info("Device not connected");
        }
    }
    try {
        EnvironmentDetails environmentDetails = new EnvironmentDetails(folderToSaveTrace);
        environmentDetails.populateDeviceInfo(deviceinfo.getDeviceVersion(), null, IAroDevice.Platform.iOS.name());
        environmentDetails.populateMacOSDetails(xcode.getXcodeVersion(), dumpcapVersion, getLibimobileDeviceVersion());
        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);
    }
    if ((attenuatorModel.isConstantThrottle() && (attenuatorModel.isThrottleDLEnabled() || attenuatorModel.isThrottleULEnabled()))) {
        // Attenuator or Secure Collection performed here
        rvi = null;
        startAttenuatorCollection(datadir, attenuatorModel, saveCollectorOptions, status, trafficFilePath);
    } else {
        mitmAttenuator = null;
        launchCollection(trafficFilePath, udId, status);
        saveCollectorOptions.recordCollectOptions(datadir, 0, 0, -1, -1, false, "", "PORTRAIT");
    }
    return status;
}
Also used : EnvironmentDetails(com.att.aro.core.datacollector.pojo.EnvironmentDetails) StatusResult(com.att.aro.core.datacollector.pojo.StatusResult) FileWriter(java.io.FileWriter) IOException(java.io.IOException) SaveCollectorOptions(com.att.aro.datacollector.ioscollector.attenuator.SaveCollectorOptions) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

EnvironmentDetails (com.att.aro.core.datacollector.pojo.EnvironmentDetails)2 StatusResult (com.att.aro.core.datacollector.pojo.StatusResult)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 FileWriter (java.io.FileWriter)2 IOException (java.io.IOException)2 AdbCommandRejectedException (com.android.ddmlib.AdbCommandRejectedException)1 InstallException (com.android.ddmlib.InstallException)1 TimeoutException (com.android.ddmlib.TimeoutException)1 AROAndroidDevice (com.att.aro.core.mobiledevice.pojo.AROAndroidDevice)1 AttenuatorModel (com.att.aro.core.peripheral.pojo.AttenuatorModel)1 AttnScriptUtil (com.att.aro.core.util.AttnScriptUtil)1 Orientation (com.att.aro.core.video.pojo.Orientation)1 SaveCollectorOptions (com.att.aro.datacollector.ioscollector.attenuator.SaveCollectorOptions)1 File (java.io.File)1