Search in sources :

Example 1 with IAroDevice

use of com.att.aro.core.mobiledevice.pojo.IAroDevice in project VideoOptimzer by attdevsupport.

the class ARODataCollectorMenu method chooseDevice.

private IAroDevice chooseDevice(IAroDevices aroDevices, List<IDataCollector> collectors) {
    ArrayList<IAroDevice> deviceList = aroDevices.getDeviceList();
    IAroDevice device = null;
    int delayTimeDL = 0;
    int throttleDL = 0;
    int throttleUL = 0;
    boolean throttleDLEnable = false;
    boolean throttleULEnable = false;
    boolean profileBoolean = false;
    String traceFolderName = "";
    String profileLocation = "";
    if (((MainFrame) parent).getPreviousOptions() != null) {
        previousOptions = ((MainFrame) parent).getPreviousOptions();
    }
    metaDataModel = new MetaDataModel();
    DataCollectorSelectNStartDialog dialog = new DataCollectorSelectNStartDialog(((MainFrame) parent).getJFrame(), parent, deviceList, traceFolderName, collectors, true, previousOptions, metaDataModel);
    if (dialog.getResponse()) {
        device = dialog.getDevice();
        traceFolderName = dialog.getTraceFolder();
        device.setCollector(dialog.getCollectorOption());
        /*debug purpose*/
        delayTimeDL = dialog.getDeviceOptionPanel().getAttenuatorModel().getDelayDS();
        dialog.getDeviceOptionPanel().getAttenuatorModel().getDelayUS();
        throttleDL = dialog.getDeviceOptionPanel().getAttenuatorModel().getThrottleDL();
        throttleUL = dialog.getDeviceOptionPanel().getAttenuatorModel().getThrottleUL();
        throttleDLEnable = dialog.getDeviceOptionPanel().getAttenuatorModel().isThrottleDLEnabled();
        throttleULEnable = dialog.getDeviceOptionPanel().getAttenuatorModel().isThrottleULEnabled();
        profileLocation = dialog.getDeviceOptionPanel().getAttenuatorModel().getLocalPath();
        profileBoolean = dialog.getDeviceOptionPanel().getAttenuatorModel().isLoadProfile();
        LOG.info("set U delay: " + delayTimeDL + ", set D delay: " + delayTimeDL + ", set U throttle: " + throttleUL + ", set D throttle: " + throttleDL + ", set profile: " + profileBoolean + ", set profileLocation: " + profileLocation);
        if (device.isPlatform(IAroDevice.Platform.iOS)) {
            IDataCollector iosCollector = findIOSCollector(collectors);
            if ((throttleDLEnable || throttleULEnable) && !NetworkUtil.isNetworkUp(SharedNetIF)) {
                MessageDialogFactory.getInstance().showInformationDialog(((MainFrame) parent).getJFrame(), ResourceBundleHelper.getMessageString("dlog.collector.option.attenuator.attenuation.finalwarning"), ResourceBundleHelper.getMessageString("dlog.collector.option.attenuator.attenuation.noshared"));
                return null;
            }
            if (!checkSetSuPassword(iosCollector)) {
                return null;
            } else {
                LOG.info("pw validated");
            }
        }
        String traceFolderPath = (device.getPlatform().equals(IAroDevice.Platform.Android)) ? Util.getAROTraceDirAndroid() + System.getProperty("file.separator") + traceFolderName : Util.getAROTraceDirIOS() + System.getProperty("file.separator") + traceFolderName;
        String currentPath = ((MainFrame) parent).getTracePath();
        if (fileManager.directoryExistAndNotEmpty(traceFolderPath)) {
            int result = folderExistsDialog();
            if (result == JOptionPane.OK_OPTION) {
                if (traceFolderPath.equals(currentPath)) {
                    new MessageDialogFactory().showErrorDialog(null, ResourceBundleHelper.getMessageString("viewer.contentUnwritable"));
                    return null;
                }
                File mountPoint = fileManager.createFile(traceFolderPath, IOSCollectorImpl.IOSAPP_MOUNT);
                if (fileManager.createFile(traceFolderPath, IOSCollectorImpl.IOSAPP_MOUNT).exists() && device.getPlatform().equals(IAroDevice.Platform.iOS)) {
                    IExternalProcessRunner runner = new ExternalProcessRunnerImpl();
                    String results = runner.executeCmd(String.format("umount %s;rmdir %s", mountPoint, mountPoint));
                    if (!results.isEmpty()) {
                        new MessageDialogFactory().showErrorDialog(null, traceFolderPath + "/" + IOSCollectorImpl.IOSAPP_MOUNT + " is BUSY");
                        return null;
                    } else {
                        int count = 0;
                        while (fileManager.directoryExistAndNotEmpty(mountPoint.toString())) {
                            if (++count > 5) {
                                new MessageDialogFactory().showErrorDialog(null, traceFolderPath + "/" + IOSCollectorImpl.IOSAPP_MOUNT + " will not release, please detach the iOS device and delete the foldere manually");
                                return null;
                            }
                            try {
                                Thread.sleep(1000);
                            } catch (InterruptedException e) {
                                Log.error("sleep interrupted");
                            }
                        }
                    }
                }
                fileManager.deleteFolderContents(traceFolderPath);
            } else {
                return null;
            }
        }
        Hashtable<String, Object> extras = prepareStartCollectorExtras(device, traceFolderName, dialog);
        updateMetaData(device, traceFolderName, dialog);
        extras.put("DIALOG_SIZE", dialog.getBaseSize());
        if (dialog.getDeviceOptionPanel().getLabeledExpandedOptionFields().isVisible()) {
            extras.put("MetaDataExpanded", true);
        }
        ((MainFrame) parent).startCollector(device, traceFolderName, extras, metaDataModel);
    } else {
        traceFolderName = null;
    }
    dialog.dispose();
    return device;
}
Also used : MetaDataModel(com.att.aro.core.tracemetadata.pojo.MetaDataModel) MainFrame(com.att.aro.ui.view.MainFrame) IExternalProcessRunner(com.att.aro.core.commandline.IExternalProcessRunner) IAroDevice(com.att.aro.core.mobiledevice.pojo.IAroDevice) DataCollectorSelectNStartDialog(com.att.aro.ui.commonui.DataCollectorSelectNStartDialog) MessageDialogFactory(com.att.aro.ui.commonui.MessageDialogFactory) IDataCollector(com.att.aro.core.datacollector.IDataCollector) File(java.io.File) ExternalProcessRunnerImpl(com.att.aro.core.commandline.impl.ExternalProcessRunnerImpl)

Example 2 with IAroDevice

use of com.att.aro.core.mobiledevice.pojo.IAroDevice in project VideoOptimzer by attdevsupport.

the class DeviceDialogOptions method reselectPriorOptions.

public void reselectPriorOptions(Hashtable<String, Object> previousOptions) {
    if (MapUtils.isNotEmpty(previousOptions) && previousOptions.containsKey("device")) {
        IAroDevice device = (IAroDevice) previousOptions.get("device");
        for (String key : previousOptions.keySet()) {
            switch(key) {
                case "video_option":
                    enableVideoOptions((VideoOption) previousOptions.get(key));
                    break;
                case "videoOrientation":
                    enableVideoOritenation((Orientation) previousOptions.get(key));
                    break;
                case "AttenuatorModel":
                    enableAttenuatorOptions((AttenuatorModel) previousOptions.get("AttenuatorModel"));
                    break;
                case "traceType":
                    traceTypeField.setText((String) previousOptions.get(key));
                    break;
                case "traceDesc":
                    traceDescField.setText((String) previousOptions.get(key));
                    break;
                case "targetedApp":
                    targetedAppField.setText((String) previousOptions.get(key));
                    break;
                case "appProducer":
                    appProducerField.setText((String) previousOptions.get(key));
                    break;
                case "selectedAppName":
                    if (device.getId().equals(selectedDevice.getId())) {
                        appSelector.setSelectedItem((String) previousOptions.get(key));
                    }
                    break;
                case "TraceFolderName":
                    parent.setTraceFolderName((String) previousOptions.get(key));
                    break;
                case "MetaDataExpanded":
                    // trigger metadata Arrow Button display
                    getLabeledExpandedOptionFields().setVisible(true);
                    parent.getExpansionArrowButton().setDirection(SwingConstants.SOUTH);
                    break;
                default:
                    break;
            }
        }
    }
    // handles when Low Res on Android was last trace
    if (labelVideoOrientTitle.isVisible() && btn_lrez.isSelected()) {
        labelVideoOrientTitle.setVisible(false);
    }
}
Also used : IAroDevice(com.att.aro.core.mobiledevice.pojo.IAroDevice)

Example 3 with IAroDevice

use of com.att.aro.core.mobiledevice.pojo.IAroDevice in project VideoOptimzer by attdevsupport.

the class AdbServiceImplTest method installPayloadFile.

// @Test
// public void locate() throws Exception{
// 
// FileListingService fileService = Mockito.mock(FileListingService.class);
// 
// Mockito.when(device.getFileListingService()).thenReturn(fileService);
// 
// FileEntry root = Mockito.mock(FileEntry.class);
// 
// FileEntry entry = adbService.locate(device, root, "path");
// assertTrue(entry == root);
// }
@Test
public void installPayloadFile() throws Exception {
    IAroDevice aroDevice = Mockito.mock(IAroDevice.class);
    Mockito.when(aroDevice.getDevice()).thenReturn(device);
    Mockito.when(extractor.extractFiles(Mockito.anyString(), Mockito.anyString(), Mockito.any(ClassLoader.class))).thenReturn(true);
    Mockito.when(android.pushFile(Mockito.any(IDevice.class), Mockito.anyString(), Mockito.anyString())).thenReturn(true);
    Mockito.when(fileManager.deleteFile(Mockito.anyString())).thenReturn(true);
    boolean success = adbService.installPayloadFile(aroDevice, "local", "file", "remote");
    assertTrue(success);
}
Also used : IAroDevice(com.att.aro.core.mobiledevice.pojo.IAroDevice) IDevice(com.android.ddmlib.IDevice) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) BaseTest(com.att.aro.core.BaseTest) Test(org.junit.Test)

Example 4 with IAroDevice

use of com.att.aro.core.mobiledevice.pojo.IAroDevice 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 5 with IAroDevice

use of com.att.aro.core.mobiledevice.pojo.IAroDevice in project VideoOptimzer by attdevsupport.

the class IOSCollectorImpl method getDevices.

@Override
public IAroDevice[] getDevices(StatusResult status) {
    IAroDevice[] aroDevices = null;
    String[] iosDevices = getDeviceSerialNumber(status);
    if (iosDevices != null && iosDevices.length > 0) {
        aroDevices = new IAroDevice[iosDevices.length];
        int pos = 0;
        for (String udid : iosDevices) {
            if (!udid.isEmpty()) {
                try {
                    aroDevices[pos++] = new IOSDevice(udid);
                } catch (IOException e) {
                    String errorMessage = "Failed to retrieve iOS device data:" + e.getMessage();
                    LOG.error(errorMessage);
                    status.setError(ErrorCodeRegistry.getFailedRetrieveDeviceData(errorMessage));
                }
            }
        }
    }
    return aroDevices;
}
Also used : IAroDevice(com.att.aro.core.mobiledevice.pojo.IAroDevice) IOSDevice(com.att.aro.datacollector.ioscollector.IOSDevice) IOException(java.io.IOException)

Aggregations

IAroDevice (com.att.aro.core.mobiledevice.pojo.IAroDevice)10 IDevice (com.android.ddmlib.IDevice)3 IDataCollector (com.att.aro.core.datacollector.IDataCollector)3 StatusResult (com.att.aro.core.datacollector.pojo.StatusResult)3 IOException (java.io.IOException)3 File (java.io.File)2 AdbCommandRejectedException (com.android.ddmlib.AdbCommandRejectedException)1 InstallException (com.android.ddmlib.InstallException)1 SyncException (com.android.ddmlib.SyncException)1 TimeoutException (com.android.ddmlib.TimeoutException)1 BaseTest (com.att.aro.core.BaseTest)1 IExternalProcessRunner (com.att.aro.core.commandline.IExternalProcessRunner)1 ExternalProcessRunnerImpl (com.att.aro.core.commandline.impl.ExternalProcessRunnerImpl)1 AROAndroidDevice (com.att.aro.core.mobiledevice.pojo.AROAndroidDevice)1 IAroDevices (com.att.aro.core.mobiledevice.pojo.IAroDevices)1 MetaDataModel (com.att.aro.core.tracemetadata.pojo.MetaDataModel)1 VideoOption (com.att.aro.core.video.pojo.VideoOption)1 IOSDevice (com.att.aro.datacollector.ioscollector.IOSDevice)1 DataCollectorSelectNStartDialog (com.att.aro.ui.commonui.DataCollectorSelectNStartDialog)1 MessageDialogFactory (com.att.aro.ui.commonui.MessageDialogFactory)1