Search in sources :

Example 11 with StatusResult

use of com.att.aro.core.datacollector.pojo.StatusResult 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 12 with StatusResult

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

the class RootedAndroidCollectorImpl method launchCollectorInEmulator.

StatusResult launchCollectorInEmulator(IDevice device, String tracename, VideoOption videoOption, Hashtable<String, Object> extraParams) {
    StatusResult result = new StatusResult();
    // just in case tcpdump was not shutdown propertly
    android.stopTcpDump(device);
    // check if device got some space to collect trace > 5 Mb
    if (!android.isSDCardEnoughSpace(device, 5120)) {
        result.setError(ErrorCodeRegistry.getDeviceHasNoSpace());
        return result;
    }
    String tcpdumpBinary = seLinuxEnforced ? "tcpdump_pie" : "tcpdump";
    String tcpdumpLocationOnDevice = "/data/data/com.att.android.arodatacollector/" + tcpdumpBinary;
    if (!installPayloadFile(device, localTraceFolder, tcpdumpBinary, tcpdumpLocationOnDevice)) {
        result.setError(ErrorCodeRegistry.getFailToInstallTcpdump());
        return result;
    }
    // set execute permission for tcpdump on remote device
    if (!android.setExecutePermission(device, tcpdumpLocationOnDevice)) {
        result.setError(ErrorCodeRegistry.getTcpdumpPermissionIssue());
        return result;
    }
    installPayloadFile(device, localTraceFolder, "key.db", "/data/data/com.att.android.arodatacollector/key.db");
    // launch tcpdump in background since it is a blocking operation
    runTcpdumpInBackground(device, tracename);
    result.setSuccess(true);
    return result;
}
Also used : StatusResult(com.att.aro.core.datacollector.pojo.StatusResult)

Example 13 with StatusResult

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

the class RootedAndroidCollectorImpl method stopCollector.

@Override
public StatusResult stopCollector() {
    log.info(Util.getMethod() + " stopCollector() for rooted-android-collector");
    StatusResult result = new StatusResult();
    this.running = false;
    if (device == null) {
        return result;
    }
    if (device.isEmulator()) {
        GoogleAnalyticsUtil.getGoogleAnalyticsInstance().sendAnalyticsEvents(GoogleAnalyticsUtil.getAnalyticsEvents().getEmulator(), // GA Request
        GoogleAnalyticsUtil.getAnalyticsEvents().getEndTrace());
        android.stopTcpDump(device);
        while (android.isTraceRunning()) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                break;
            }
        }
        result = pullTraceFromEmulator();
    } else {
        GoogleAnalyticsUtil.getGoogleAnalyticsInstance().sendAnalyticsEvents(GoogleAnalyticsUtil.getAnalyticsEvents().getRootedCollector(), // GA Request
        GoogleAnalyticsUtil.getAnalyticsEvents().getEndTrace());
        stopCollectorInDevice();
        result = pullTrace(DEVICECOLLECTORFILENAMES);
    }
    if (isVideo()) {
        stopCaptureVideo();
    }
    return result;
}
Also used : StatusResult(com.att.aro.core.datacollector.pojo.StatusResult)

Example 14 with StatusResult

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

the class IOSCollectorImpl method stopCollector.

@Override
public StatusResult stopCollector() {
    StatusResult status = new StatusResult();
    GoogleAnalyticsUtil.getGoogleAnalyticsInstance().sendAnalyticsEvents(GoogleAnalyticsUtil.getAnalyticsEvents().getIosCollector(), // GA Request
    GoogleAnalyticsUtil.getAnalyticsEvents().getEndTrace());
    this.hdVideoPulled = true;
    this.stopWorkers();
    if (datadir.length() > 1) {
        File folder = new File(datadir);
        if (folder.exists()) {
            // if video data is zero, java media player will throw exception
            if (videofile != null && videofile.exists() && videofile.length() < 2) {
                videofile.delete();
                LOG.info("deleted empty video file");
            }
            // now check for pcap existence otherwise there will be popup error.
            File pcapfile = new File(datadir + Util.FILE_SEPARATOR + defaultBundle.getString("datadump.trafficFile"));
            status.setSuccess(pcapfile.exists());
            if (this.videoOption.equals(VideoOption.HDEF)) {
                // hd video trace only
                pullFromDevice();
            }
        }
    }
    return status;
}
Also used : StatusResult(com.att.aro.core.datacollector.pojo.StatusResult) File(java.io.File)

Example 15 with StatusResult

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

the class VideoCaptureMacOS method doWork.

/**
 * <pre>
 * Synchronous operation that launches ScreenshotManger then receives screenshot JPEGs.
 * BufferedImage JPEGs are used to create video.
 * This method should never be called directly, use run() instead.
 */
public void doWork() {
    stop = false;
    hasQuit = false;
    LOG.info("Init Screencapture...");
    LOG.info("Working folder: " + this.workingFolder);
    smanage = new ScreenshotManager(this.workingFolder, this.udid);
    smanage.start();
    LOG.info("Started ScreenshotManager...");
    int timeoutcounter = 0;
    while (!smanage.isReady()) {
        try {
            LOG.info("Waiting for ScreenshotManager to be ready");
            Thread.sleep(200);
            timeoutcounter++;
        } catch (InterruptedException e) {
            LOG.debug("InterruptedException:", e);
        }
        if (timeoutcounter > 30) {
            // give it 6 seconds to start up
            LOG.info("Timeout on screenshotmanager");
            break;
        }
    }
    LOG.info("ScreenshotManager is ready: " + smanage.isReady());
    Date lastFrameTime = this.videoStartTime = new Date();
    while (!stop) {
        try {
            // ImageHelper.getImageFromByte(data);
            BufferedImage image = smanage.getImage();
            if (image != null) {
                Date timestamp = new Date();
                int duration = Math.round((float) (timestamp.getTime() - lastFrameTime.getTime()) * videowriter.getTimeUnits() / 1000f);
                if (duration > 0) {
                    videowriter.writeFrame(image, duration);
                    lastFrameTime = timestamp;
                    callSubscriber(image);
                }
            } else if (!stop && (!ImageHelper.isImageDecoderStatus())) {
                stopCapture();
                statusResult = new StatusResult();
                statusResult.setSuccess(false);
                statusResult.setError(ErrorCodeRegistry.getImageDecoderError(defaultBundle.getString("Error.imagedecoder")));
                LOG.error("Failed to get screenshot image, ImageDecoder error");
                break;
            } else if (!stop) {
                stop = !smanage.isReady();
                LOG.info("Failed to get screenshot image, pause for 1/2 second");
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    LOG.debug("InterruptedException:", e);
                }
            }
        } catch (IOException e) {
            LOG.debug("IOException:", e);
            break;
        }
    }
    try {
        videowriter.close();
        if (smanage != null) {
            smanage.shutDown();
        }
    } catch (IOException ioExp) {
        LOG.warn("Exception closing video output stream", ioExp);
    }
    hasQuit = true;
    // signal waiter to stop waiting
    stop = false;
    LOG.info("stopped screencapture");
}
Also used : StatusResult(com.att.aro.core.datacollector.pojo.StatusResult) IOException(java.io.IOException) Date(java.util.Date) BufferedImage(java.awt.image.BufferedImage)

Aggregations

StatusResult (com.att.aro.core.datacollector.pojo.StatusResult)42 IOException (java.io.IOException)28 Test (org.junit.Test)20 AdbCommandRejectedException (com.android.ddmlib.AdbCommandRejectedException)19 TimeoutException (com.android.ddmlib.TimeoutException)19 IDevice (com.android.ddmlib.IDevice)17 Ignore (org.junit.Ignore)13 File (java.io.File)8 Date (java.util.Date)7 SyncService (com.android.ddmlib.SyncService)5 InstallException (com.android.ddmlib.InstallException)3 SyncException (com.android.ddmlib.SyncException)3 IAroDevice (com.att.aro.core.mobiledevice.pojo.IAroDevice)3 FileWriter (java.io.FileWriter)3 Hashtable (java.util.Hashtable)3 IDataCollector (com.att.aro.core.datacollector.IDataCollector)2 IVideoImageSubscriber (com.att.aro.core.datacollector.IVideoImageSubscriber)2 EnvironmentDetails (com.att.aro.core.datacollector.pojo.EnvironmentDetails)2 IFileManager (com.att.aro.core.fileio.IFileManager)2 AROAndroidDevice (com.att.aro.core.mobiledevice.pojo.AROAndroidDevice)2