Search in sources :

Example 1 with VideoOption

use of com.att.aro.core.video.pojo.VideoOption 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;
}
Also used : IAroDevice(com.att.aro.core.mobiledevice.pojo.IAroDevice) StatusResult(com.att.aro.core.datacollector.pojo.StatusResult) VideoOption(com.att.aro.core.video.pojo.VideoOption) AdbCommandRejectedException(com.android.ddmlib.AdbCommandRejectedException) IDevice(com.android.ddmlib.IDevice) AROAndroidDevice(com.att.aro.core.mobiledevice.pojo.AROAndroidDevice) IOException(java.io.IOException) TimeoutException(com.android.ddmlib.TimeoutException) AdbCommandRejectedException(com.android.ddmlib.AdbCommandRejectedException) IOException(java.io.IOException) SyncException(com.android.ddmlib.SyncException) InstallException(com.android.ddmlib.InstallException) TimeoutException(com.android.ddmlib.TimeoutException)

Example 2 with VideoOption

use of com.att.aro.core.video.pojo.VideoOption in project VideoOptimzer by attdevsupport.

the class Application method configureVideoOption.

private VideoOption configureVideoOption(String videoOption) {
    VideoOption option = VideoOption.NONE;
    switch(videoOption) {
        case "yes":
        case "slow":
            option = VideoOption.LREZ;
            break;
        case "hd":
            option = VideoOption.HDEF;
            break;
        case "sd":
            option = VideoOption.SDEF;
            break;
        case "no":
            option = VideoOption.NONE;
            break;
        default:
            break;
    }
    boolean isRootedColl = "rooted_android".equals(cmds.getStartcollector());
    if (isRootedColl && (option == VideoOption.SDEF || option == VideoOption.HDEF)) {
        println("HD/SD Video is not supported on rooted collector: Setting video to low resolution");
        return VideoOption.LREZ;
    }
    return option;
}
Also used : VideoOption(com.att.aro.core.video.pojo.VideoOption)

Aggregations

VideoOption (com.att.aro.core.video.pojo.VideoOption)2 AdbCommandRejectedException (com.android.ddmlib.AdbCommandRejectedException)1 IDevice (com.android.ddmlib.IDevice)1 InstallException (com.android.ddmlib.InstallException)1 SyncException (com.android.ddmlib.SyncException)1 TimeoutException (com.android.ddmlib.TimeoutException)1 StatusResult (com.att.aro.core.datacollector.pojo.StatusResult)1 AROAndroidDevice (com.att.aro.core.mobiledevice.pojo.AROAndroidDevice)1 IAroDevice (com.att.aro.core.mobiledevice.pojo.IAroDevice)1 IOException (java.io.IOException)1