Search in sources :

Example 1 with AttenuatorModel

use of com.att.aro.core.peripheral.pojo.AttenuatorModel in project VideoOptimzer by attdevsupport.

the class AttnrRadioGroupPanel method reselectPriorOptions.

public void reselectPriorOptions(AttenuatorModel attenuatorModel, boolean isIOS) {
    DataCollectorType deviceType = deviceInfo.getCollector().getType();
    switch(deviceType) {
        case NON_ROOTED_ANDROID:
        case IOS:
            this.attenuatorModel = attenuatorModel;
            attnrTTPanel.setAttenuatorModel(attenuatorModel);
            attnrLoadPanel.setAttenuatorModel(attenuatorModel);
            if (attenuatorModel.isConstantThrottle() && !attenuatorModel.isFreeThrottle()) {
                sliderBtn.setSelected(true);
                parentPanel.getAttnrHolder().remove(getLoadProfilePanel());
                getLoadProfilePanel().resetComponent();
                parentPanel.getAttnrHolder().add(getThroughputPanel(), BorderLayout.CENTER);
                parentPanel.getAttnrHolder().revalidate();
                parentPanel.getAttnrHolder().repaint();
                attnrTTPanel.reselectPriorOptions(attenuatorModel);
            } else if (!attenuatorModel.isConstantThrottle() && attenuatorModel.isLoadProfile()) {
                loadFileBtn.setSelected(true);
                parentPanel.getAttnrHolder().remove(getThroughputPanel());
                getThroughputPanel().resetComponent();
                parentPanel.getAttnrHolder().add(getLoadProfilePanel());
                parentPanel.getAttnrHolder().revalidate();
                parentPanel.getAttnrHolder().repaint();
                attnrLoadPanel.reselectPriorOptions(attenuatorModel);
            }
            break;
        case ROOTED_ANDROID:
            // reset
            AttenuatorModel attenuatorModelReset = new AttenuatorModel();
            this.attenuatorModel = attenuatorModelReset;
            deviceInfo.setAttenuatorModel(attenuatorModelReset);
            attnrTTPanel.setAttenuatorModel(attenuatorModelReset);
            attnrLoadPanel.setAttenuatorModel(attenuatorModelReset);
            loadFileBtn.setEnabled(false);
            break;
        case DEFAULT:
            defaultBtn.setSelected(true);
            break;
    }
}
Also used : AttenuatorModel(com.att.aro.core.peripheral.pojo.AttenuatorModel) DataCollectorType(com.att.aro.core.datacollector.DataCollectorType)

Example 2 with AttenuatorModel

use of com.att.aro.core.peripheral.pojo.AttenuatorModel 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 3 with AttenuatorModel

use of com.att.aro.core.peripheral.pojo.AttenuatorModel in project VideoOptimzer by attdevsupport.

the class DeviceDialogOptions method getAttnrGroup.

public AttnrPanel getAttnrGroup() {
    if (attnrGroupPanel == null) {
        attenuatorModel = new AttenuatorModel();
        attnrGroupPanel = new AttnrPanel(this, parent, attenuatorModel);
        Border loweredetched = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
        attnrGroupPanel.setBorder(loweredetched);
    }
    return attnrGroupPanel;
}
Also used : AttenuatorModel(com.att.aro.core.peripheral.pojo.AttenuatorModel) Border(javax.swing.border.Border) EtchedBorder(javax.swing.border.EtchedBorder)

Example 4 with AttenuatorModel

use of com.att.aro.core.peripheral.pojo.AttenuatorModel 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);
    }
}
Also used : OutSave(com.att.aro.console.printstreamutils.OutSave) Hashtable(java.util.Hashtable) StatusResult(com.att.aro.core.datacollector.pojo.StatusResult) IDataCollectorManager(com.att.aro.core.datacollector.IDataCollectorManager) AttenuatorModel(com.att.aro.core.peripheral.pojo.AttenuatorModel) IDataCollector(com.att.aro.core.datacollector.IDataCollector) Orientation(com.att.aro.core.video.pojo.Orientation) IFileManager(com.att.aro.core.fileio.IFileManager)

Example 5 with AttenuatorModel

use of com.att.aro.core.peripheral.pojo.AttenuatorModel in project VideoOptimzer by attdevsupport.

the class Application method getAttenuateModel.

/**
 * if the user set throttle number, VO CLI will enable the throttle option
 *
 * @return
 */
private AttenuatorModel getAttenuateModel(Commands cmds) {
    AttenuatorModel model = new AttenuatorModel();
    model.setConstantThrottle(true);
    model.setThrottleUL(getThrottleUL());
    model.setThrottleDL(getThrottleDL());
    if (model.getThrottleDL() > -1) {
        model.setThrottleDLEnable(true);
    }
    if (model.getThrottleUL() > -1) {
        model.setThrottleULEnable(true);
    }
    if (cmds.getAttenuationprofile() != null) {
        if ((model.isThrottleDLEnabled()) || (model.isThrottleULEnabled())) {
            printError(ErrorCodeRegistry.getInvalidProfileThrottleInput());
            System.exit(1);
        } else {
            String localPath = cmds.getAttenuationprofile();
            model.setLoadProfile(true);
            model.setLocalPath(localPath);
            model.setAtnrProfileName(localPath);
        }
    }
    return model;
}
Also used : AttenuatorModel(com.att.aro.core.peripheral.pojo.AttenuatorModel)

Aggregations

AttenuatorModel (com.att.aro.core.peripheral.pojo.AttenuatorModel)5 StatusResult (com.att.aro.core.datacollector.pojo.StatusResult)2 Orientation (com.att.aro.core.video.pojo.Orientation)2 AdbCommandRejectedException (com.android.ddmlib.AdbCommandRejectedException)1 InstallException (com.android.ddmlib.InstallException)1 TimeoutException (com.android.ddmlib.TimeoutException)1 OutSave (com.att.aro.console.printstreamutils.OutSave)1 DataCollectorType (com.att.aro.core.datacollector.DataCollectorType)1 IDataCollector (com.att.aro.core.datacollector.IDataCollector)1 IDataCollectorManager (com.att.aro.core.datacollector.IDataCollectorManager)1 EnvironmentDetails (com.att.aro.core.datacollector.pojo.EnvironmentDetails)1 IFileManager (com.att.aro.core.fileio.IFileManager)1 AROAndroidDevice (com.att.aro.core.mobiledevice.pojo.AROAndroidDevice)1 AttnScriptUtil (com.att.aro.core.util.AttnScriptUtil)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 Hashtable (java.util.Hashtable)1 Border (javax.swing.border.Border)1 EtchedBorder (javax.swing.border.EtchedBorder)1