Search in sources :

Example 1 with UiAutomationConnection

use of android.app.UiAutomationConnection in project android_frameworks_base by ParanoidAndroid.

the class Am method runInstrument.

private void runInstrument() throws Exception {
    String profileFile = null;
    boolean wait = false;
    boolean rawMode = false;
    boolean no_window_animation = false;
    int userId = UserHandle.USER_CURRENT;
    Bundle args = new Bundle();
    String argKey = null, argValue = null;
    IWindowManager wm = IWindowManager.Stub.asInterface(ServiceManager.getService("window"));
    String opt;
    while ((opt = nextOption()) != null) {
        if (opt.equals("-p")) {
            profileFile = nextArgRequired();
        } else if (opt.equals("-w")) {
            wait = true;
        } else if (opt.equals("-r")) {
            rawMode = true;
        } else if (opt.equals("-e")) {
            argKey = nextArgRequired();
            argValue = nextArgRequired();
            args.putString(argKey, argValue);
        } else if (opt.equals("--no_window_animation") || opt.equals("--no-window-animation")) {
            no_window_animation = true;
        } else if (opt.equals("--user")) {
            userId = parseUserArg(nextArgRequired());
        } else {
            System.err.println("Error: Unknown option: " + opt);
            return;
        }
    }
    if (userId == UserHandle.USER_ALL) {
        System.err.println("Error: Can't start instrumentation with user 'all'");
        return;
    }
    String cnArg = nextArgRequired();
    ComponentName cn = ComponentName.unflattenFromString(cnArg);
    if (cn == null)
        throw new IllegalArgumentException("Bad component name: " + cnArg);
    InstrumentationWatcher watcher = null;
    UiAutomationConnection connection = null;
    if (wait) {
        watcher = new InstrumentationWatcher();
        watcher.setRawOutput(rawMode);
        connection = new UiAutomationConnection();
    }
    float[] oldAnims = null;
    if (no_window_animation) {
        oldAnims = wm.getAnimationScales();
        wm.setAnimationScale(0, 0.0f);
        wm.setAnimationScale(1, 0.0f);
    }
    if (!mAm.startInstrumentation(cn, profileFile, 0, args, watcher, connection, userId)) {
        throw new AndroidException("INSTRUMENTATION_FAILED: " + cn.flattenToString());
    }
    if (watcher != null) {
        if (!watcher.waitForFinish()) {
            System.out.println("INSTRUMENTATION_ABORTED: System has crashed.");
        }
    }
    if (oldAnims != null) {
        wm.setAnimationScales(oldAnims);
    }
}
Also used : UiAutomationConnection(android.app.UiAutomationConnection) AndroidException(android.util.AndroidException) IWindowManager(android.view.IWindowManager) Bundle(android.os.Bundle) IInstrumentationWatcher(android.app.IInstrumentationWatcher) ComponentName(android.content.ComponentName)

Example 2 with UiAutomationConnection

use of android.app.UiAutomationConnection in project android_frameworks_base by AOSPA.

the class Am method runInstrument.

private void runInstrument() throws Exception {
    String profileFile = null;
    boolean wait = false;
    boolean rawMode = false;
    boolean no_window_animation = false;
    int userId = UserHandle.USER_CURRENT;
    Bundle args = new Bundle();
    String argKey = null, argValue = null;
    IWindowManager wm = IWindowManager.Stub.asInterface(ServiceManager.getService("window"));
    String abi = null;
    String opt;
    while ((opt = nextOption()) != null) {
        if (opt.equals("-p")) {
            profileFile = nextArgRequired();
        } else if (opt.equals("-w")) {
            wait = true;
        } else if (opt.equals("-r")) {
            rawMode = true;
        } else if (opt.equals("-e")) {
            argKey = nextArgRequired();
            argValue = nextArgRequired();
            args.putString(argKey, argValue);
        } else if (opt.equals("--no_window_animation") || opt.equals("--no-window-animation")) {
            no_window_animation = true;
        } else if (opt.equals("--user")) {
            userId = parseUserArg(nextArgRequired());
        } else if (opt.equals("--abi")) {
            abi = nextArgRequired();
        } else {
            System.err.println("Error: Unknown option: " + opt);
            return;
        }
    }
    if (userId == UserHandle.USER_ALL) {
        System.err.println("Error: Can't start instrumentation with user 'all'");
        return;
    }
    String cnArg = nextArgRequired();
    ComponentName cn;
    if (cnArg.contains("/")) {
        cn = ComponentName.unflattenFromString(cnArg);
        if (cn == null)
            throw new IllegalArgumentException("Bad component name: " + cnArg);
    } else {
        List<InstrumentationInfo> infos = mPm.queryInstrumentation(null, 0).getList();
        final int numInfos = infos == null ? 0 : infos.size();
        List<ComponentName> cns = new ArrayList<>();
        for (int i = 0; i < numInfos; i++) {
            InstrumentationInfo info = infos.get(i);
            ComponentName c = new ComponentName(info.packageName, info.name);
            if (cnArg.equals(info.packageName)) {
                cns.add(c);
            }
        }
        if (cns.size() == 0) {
            throw new IllegalArgumentException("No instrumentation found for: " + cnArg);
        } else if (cns.size() == 1) {
            cn = cns.get(0);
        } else {
            StringBuilder cnsStr = new StringBuilder();
            final int numCns = cns.size();
            for (int i = 0; i < numCns; i++) {
                cnsStr.append(cns.get(i).flattenToString());
                cnsStr.append(", ");
            }
            // Remove last ", "
            cnsStr.setLength(cnsStr.length() - 2);
            throw new IllegalArgumentException("Found multiple instrumentations: " + cnsStr.toString());
        }
    }
    InstrumentationWatcher watcher = null;
    UiAutomationConnection connection = null;
    if (wait) {
        watcher = new InstrumentationWatcher();
        watcher.setRawOutput(rawMode);
        connection = new UiAutomationConnection();
    }
    float[] oldAnims = null;
    if (no_window_animation) {
        oldAnims = wm.getAnimationScales();
        wm.setAnimationScale(0, 0.0f);
        wm.setAnimationScale(1, 0.0f);
    }
    if (abi != null) {
        final String[] supportedAbis = Build.SUPPORTED_ABIS;
        boolean matched = false;
        for (String supportedAbi : supportedAbis) {
            if (supportedAbi.equals(abi)) {
                matched = true;
                break;
            }
        }
        if (!matched) {
            throw new AndroidException("INSTRUMENTATION_FAILED: Unsupported instruction set " + abi);
        }
    }
    if (!mAm.startInstrumentation(cn, profileFile, 0, args, watcher, connection, userId, abi)) {
        throw new AndroidException("INSTRUMENTATION_FAILED: " + cn.flattenToString());
    }
    if (watcher != null) {
        if (!watcher.waitForFinish()) {
            System.out.println("INSTRUMENTATION_ABORTED: System has crashed.");
        }
    }
    if (oldAnims != null) {
        wm.setAnimationScales(oldAnims);
    }
}
Also used : IWindowManager(android.view.IWindowManager) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) IInstrumentationWatcher(android.app.IInstrumentationWatcher) UiAutomationConnection(android.app.UiAutomationConnection) AndroidException(android.util.AndroidException) InstrumentationInfo(android.content.pm.InstrumentationInfo) ComponentName(android.content.ComponentName)

Example 3 with UiAutomationConnection

use of android.app.UiAutomationConnection in project android_frameworks_base by crdroidandroid.

the class Am method runInstrument.

private void runInstrument() throws Exception {
    String profileFile = null;
    boolean wait = false;
    boolean rawMode = false;
    boolean no_window_animation = false;
    int userId = UserHandle.USER_CURRENT;
    Bundle args = new Bundle();
    String argKey = null, argValue = null;
    IWindowManager wm = IWindowManager.Stub.asInterface(ServiceManager.getService("window"));
    String abi = null;
    String opt;
    while ((opt = nextOption()) != null) {
        if (opt.equals("-p")) {
            profileFile = nextArgRequired();
        } else if (opt.equals("-w")) {
            wait = true;
        } else if (opt.equals("-r")) {
            rawMode = true;
        } else if (opt.equals("-e")) {
            argKey = nextArgRequired();
            argValue = nextArgRequired();
            args.putString(argKey, argValue);
        } else if (opt.equals("--no_window_animation") || opt.equals("--no-window-animation")) {
            no_window_animation = true;
        } else if (opt.equals("--user")) {
            userId = parseUserArg(nextArgRequired());
        } else if (opt.equals("--abi")) {
            abi = nextArgRequired();
        } else {
            System.err.println("Error: Unknown option: " + opt);
            return;
        }
    }
    if (userId == UserHandle.USER_ALL) {
        System.err.println("Error: Can't start instrumentation with user 'all'");
        return;
    }
    String cnArg = nextArgRequired();
    ComponentName cn;
    if (cnArg.contains("/")) {
        cn = ComponentName.unflattenFromString(cnArg);
        if (cn == null)
            throw new IllegalArgumentException("Bad component name: " + cnArg);
    } else {
        List<InstrumentationInfo> infos = mPm.queryInstrumentation(null, 0).getList();
        final int numInfos = infos == null ? 0 : infos.size();
        List<ComponentName> cns = new ArrayList<>();
        for (int i = 0; i < numInfos; i++) {
            InstrumentationInfo info = infos.get(i);
            ComponentName c = new ComponentName(info.packageName, info.name);
            if (cnArg.equals(info.packageName)) {
                cns.add(c);
            }
        }
        if (cns.size() == 0) {
            throw new IllegalArgumentException("No instrumentation found for: " + cnArg);
        } else if (cns.size() == 1) {
            cn = cns.get(0);
        } else {
            StringBuilder cnsStr = new StringBuilder();
            final int numCns = cns.size();
            for (int i = 0; i < numCns; i++) {
                cnsStr.append(cns.get(i).flattenToString());
                cnsStr.append(", ");
            }
            // Remove last ", "
            cnsStr.setLength(cnsStr.length() - 2);
            throw new IllegalArgumentException("Found multiple instrumentations: " + cnsStr.toString());
        }
    }
    InstrumentationWatcher watcher = null;
    UiAutomationConnection connection = null;
    if (wait) {
        watcher = new InstrumentationWatcher();
        watcher.setRawOutput(rawMode);
        connection = new UiAutomationConnection();
    }
    float[] oldAnims = null;
    if (no_window_animation) {
        oldAnims = wm.getAnimationScales();
        wm.setAnimationScale(0, 0.0f);
        wm.setAnimationScale(1, 0.0f);
    }
    if (abi != null) {
        final String[] supportedAbis = Build.SUPPORTED_ABIS;
        boolean matched = false;
        for (String supportedAbi : supportedAbis) {
            if (supportedAbi.equals(abi)) {
                matched = true;
                break;
            }
        }
        if (!matched) {
            throw new AndroidException("INSTRUMENTATION_FAILED: Unsupported instruction set " + abi);
        }
    }
    if (!mAm.startInstrumentation(cn, profileFile, 0, args, watcher, connection, userId, abi)) {
        throw new AndroidException("INSTRUMENTATION_FAILED: " + cn.flattenToString());
    }
    if (watcher != null) {
        if (!watcher.waitForFinish()) {
            System.out.println("INSTRUMENTATION_ABORTED: System has crashed.");
        }
    }
    if (oldAnims != null) {
        wm.setAnimationScales(oldAnims);
    }
}
Also used : IWindowManager(android.view.IWindowManager) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) IInstrumentationWatcher(android.app.IInstrumentationWatcher) UiAutomationConnection(android.app.UiAutomationConnection) AndroidException(android.util.AndroidException) InstrumentationInfo(android.content.pm.InstrumentationInfo) ComponentName(android.content.ComponentName)

Example 4 with UiAutomationConnection

use of android.app.UiAutomationConnection in project android_frameworks_base by AOSPA.

the class UiAutomationShellWrapper method connect.

public void connect() {
    if (mHandlerThread.isAlive()) {
        throw new IllegalStateException("Already connected!");
    }
    mHandlerThread.start();
    mUiAutomation = new UiAutomation(mHandlerThread.getLooper(), new UiAutomationConnection());
    mUiAutomation.connect();
}
Also used : UiAutomationConnection(android.app.UiAutomationConnection) UiAutomation(android.app.UiAutomation)

Example 5 with UiAutomationConnection

use of android.app.UiAutomationConnection in project platform_frameworks_base by android.

the class Am method runInstrument.

private void runInstrument() throws Exception {
    String profileFile = null;
    boolean wait = false;
    boolean rawMode = false;
    boolean no_window_animation = false;
    int userId = UserHandle.USER_CURRENT;
    Bundle args = new Bundle();
    String argKey = null, argValue = null;
    IWindowManager wm = IWindowManager.Stub.asInterface(ServiceManager.getService("window"));
    String abi = null;
    String opt;
    while ((opt = nextOption()) != null) {
        if (opt.equals("-p")) {
            profileFile = nextArgRequired();
        } else if (opt.equals("-w")) {
            wait = true;
        } else if (opt.equals("-r")) {
            rawMode = true;
        } else if (opt.equals("-e")) {
            argKey = nextArgRequired();
            argValue = nextArgRequired();
            args.putString(argKey, argValue);
        } else if (opt.equals("--no_window_animation") || opt.equals("--no-window-animation")) {
            no_window_animation = true;
        } else if (opt.equals("--user")) {
            userId = parseUserArg(nextArgRequired());
        } else if (opt.equals("--abi")) {
            abi = nextArgRequired();
        } else {
            System.err.println("Error: Unknown option: " + opt);
            return;
        }
    }
    if (userId == UserHandle.USER_ALL) {
        System.err.println("Error: Can't start instrumentation with user 'all'");
        return;
    }
    String cnArg = nextArgRequired();
    ComponentName cn;
    if (cnArg.contains("/")) {
        cn = ComponentName.unflattenFromString(cnArg);
        if (cn == null)
            throw new IllegalArgumentException("Bad component name: " + cnArg);
    } else {
        List<InstrumentationInfo> infos = mPm.queryInstrumentation(null, 0).getList();
        final int numInfos = infos == null ? 0 : infos.size();
        List<ComponentName> cns = new ArrayList<>();
        for (int i = 0; i < numInfos; i++) {
            InstrumentationInfo info = infos.get(i);
            ComponentName c = new ComponentName(info.packageName, info.name);
            if (cnArg.equals(info.packageName)) {
                cns.add(c);
            }
        }
        if (cns.size() == 0) {
            throw new IllegalArgumentException("No instrumentation found for: " + cnArg);
        } else if (cns.size() == 1) {
            cn = cns.get(0);
        } else {
            StringBuilder cnsStr = new StringBuilder();
            final int numCns = cns.size();
            for (int i = 0; i < numCns; i++) {
                cnsStr.append(cns.get(i).flattenToString());
                cnsStr.append(", ");
            }
            // Remove last ", "
            cnsStr.setLength(cnsStr.length() - 2);
            throw new IllegalArgumentException("Found multiple instrumentations: " + cnsStr.toString());
        }
    }
    InstrumentationWatcher watcher = null;
    UiAutomationConnection connection = null;
    if (wait) {
        watcher = new InstrumentationWatcher();
        watcher.setRawOutput(rawMode);
        connection = new UiAutomationConnection();
    }
    float[] oldAnims = null;
    if (no_window_animation) {
        oldAnims = wm.getAnimationScales();
        wm.setAnimationScale(0, 0.0f);
        wm.setAnimationScale(1, 0.0f);
    }
    if (abi != null) {
        final String[] supportedAbis = Build.SUPPORTED_ABIS;
        boolean matched = false;
        for (String supportedAbi : supportedAbis) {
            if (supportedAbi.equals(abi)) {
                matched = true;
                break;
            }
        }
        if (!matched) {
            throw new AndroidException("INSTRUMENTATION_FAILED: Unsupported instruction set " + abi);
        }
    }
    if (!mAm.startInstrumentation(cn, profileFile, 0, args, watcher, connection, userId, abi)) {
        throw new AndroidException("INSTRUMENTATION_FAILED: " + cn.flattenToString());
    }
    if (watcher != null) {
        if (!watcher.waitForFinish()) {
            System.out.println("INSTRUMENTATION_ABORTED: System has crashed.");
        }
    }
    if (oldAnims != null) {
        wm.setAnimationScales(oldAnims);
    }
}
Also used : IWindowManager(android.view.IWindowManager) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) IInstrumentationWatcher(android.app.IInstrumentationWatcher) UiAutomationConnection(android.app.UiAutomationConnection) AndroidException(android.util.AndroidException) InstrumentationInfo(android.content.pm.InstrumentationInfo) ComponentName(android.content.ComponentName)

Aggregations

UiAutomationConnection (android.app.UiAutomationConnection)11 IInstrumentationWatcher (android.app.IInstrumentationWatcher)6 ComponentName (android.content.ComponentName)6 Bundle (android.os.Bundle)6 AndroidException (android.util.AndroidException)6 IWindowManager (android.view.IWindowManager)6 UiAutomation (android.app.UiAutomation)5 InstrumentationInfo (android.content.pm.InstrumentationInfo)5 ArrayList (java.util.ArrayList)5