Search in sources :

Example 1 with AndroidException

use of android.util.AndroidException 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 AndroidException

use of android.util.AndroidException in project android_frameworks_base by ParanoidAndroid.

the class Am method runProfile.

private void runProfile() throws Exception {
    String profileFile = null;
    boolean start = false;
    boolean wall = false;
    int userId = UserHandle.USER_CURRENT;
    int profileType = 0;
    String process = null;
    String cmd = nextArgRequired();
    if ("start".equals(cmd)) {
        start = true;
        String opt;
        while ((opt = nextOption()) != null) {
            if (opt.equals("--user")) {
                userId = parseUserArg(nextArgRequired());
            } else if (opt.equals("--wall")) {
                wall = true;
            } else {
                System.err.println("Error: Unknown option: " + opt);
                return;
            }
        }
        process = nextArgRequired();
    } else if ("stop".equals(cmd)) {
        String opt;
        while ((opt = nextOption()) != null) {
            if (opt.equals("--user")) {
                userId = parseUserArg(nextArgRequired());
            } else {
                System.err.println("Error: Unknown option: " + opt);
                return;
            }
        }
        process = nextArg();
    } else {
        // Compatibility with old syntax: process is specified first.
        process = cmd;
        cmd = nextArgRequired();
        if ("start".equals(cmd)) {
            start = true;
        } else if (!"stop".equals(cmd)) {
            throw new IllegalArgumentException("Profile command " + process + " not valid");
        }
    }
    if (userId == UserHandle.USER_ALL) {
        System.err.println("Error: Can't profile with user 'all'");
        return;
    }
    ParcelFileDescriptor fd = null;
    if (start) {
        profileFile = nextArgRequired();
        try {
            fd = ParcelFileDescriptor.open(new File(profileFile), ParcelFileDescriptor.MODE_CREATE | ParcelFileDescriptor.MODE_TRUNCATE | ParcelFileDescriptor.MODE_READ_WRITE);
        } catch (FileNotFoundException e) {
            System.err.println("Error: Unable to open file: " + profileFile);
            return;
        }
    }
    try {
        if (wall) {
            // XXX doesn't work -- this needs to be set before booting.
            String props = SystemProperties.get("dalvik.vm.extra-opts");
            if (props == null || !props.contains("-Xprofile:wallclock")) {
                props = props + " -Xprofile:wallclock";
            //SystemProperties.set("dalvik.vm.extra-opts", props);
            }
        } else if (start) {
        //removeWallOption();
        }
        if (!mAm.profileControl(process, userId, start, profileFile, fd, profileType)) {
            wall = false;
            throw new AndroidException("PROFILE FAILED on process " + process);
        }
    } finally {
        if (!wall) {
        //removeWallOption();
        }
    }
}
Also used : AndroidException(android.util.AndroidException) ParcelFileDescriptor(android.os.ParcelFileDescriptor) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File)

Example 3 with AndroidException

use of android.util.AndroidException in project android_frameworks_base by ResurrectionRemix.

the class Am method runTraceIpcStop.

private void runTraceIpcStop() throws Exception {
    String opt;
    String filename = null;
    while ((opt = nextOption()) != null) {
        if (opt.equals("--dump-file")) {
            filename = nextArgRequired();
        } else {
            System.err.println("Error: Unknown option: " + opt);
            return;
        }
    }
    if (filename == null) {
        System.err.println("Error: Specify filename to dump logs to.");
        return;
    }
    ParcelFileDescriptor fd = null;
    try {
        File file = new File(filename);
        file.delete();
        fd = openForSystemServer(file, ParcelFileDescriptor.MODE_CREATE | ParcelFileDescriptor.MODE_TRUNCATE | ParcelFileDescriptor.MODE_WRITE_ONLY);
    } catch (FileNotFoundException e) {
        System.err.println("Error: Unable to open file: " + filename);
        System.err.println("Consider using a file under /data/local/tmp/");
        return;
    }
    ;
    if (!mAm.stopBinderTrackingAndDump(fd)) {
        throw new AndroidException("STOP TRACE FAILED.");
    }
    System.out.println("Stopped IPC tracing. Dumping logs to: " + filename);
}
Also used : AndroidException(android.util.AndroidException) ParcelFileDescriptor(android.os.ParcelFileDescriptor) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File)

Example 4 with AndroidException

use of android.util.AndroidException in project android_frameworks_base by ResurrectionRemix.

the class Am method runSupportsMultiwindow.

private void runSupportsMultiwindow() throws Exception {
    // system resources does not contain all the device configuration, construct it manually.
    Configuration config = mAm.getConfiguration();
    if (config == null) {
        throw new AndroidException("Activity manager has no configuration");
    }
    final DisplayMetrics metrics = new DisplayMetrics();
    metrics.setToDefaults();
    Resources res = new Resources(AssetManager.getSystem(), metrics, config);
    System.out.println(res.getBoolean(com.android.internal.R.bool.config_supportsMultiWindow));
}
Also used : AndroidException(android.util.AndroidException) Configuration(android.content.res.Configuration) Resources(android.content.res.Resources) DisplayMetrics(android.util.DisplayMetrics)

Example 5 with AndroidException

use of android.util.AndroidException in project android_frameworks_base by DirtyUnicorns.

the class Am method runSupportsMultiwindow.

private void runSupportsMultiwindow() throws Exception {
    // system resources does not contain all the device configuration, construct it manually.
    Configuration config = mAm.getConfiguration();
    if (config == null) {
        throw new AndroidException("Activity manager has no configuration");
    }
    final DisplayMetrics metrics = new DisplayMetrics();
    metrics.setToDefaults();
    Resources res = new Resources(AssetManager.getSystem(), metrics, config);
    System.out.println(res.getBoolean(com.android.internal.R.bool.config_supportsMultiWindow));
}
Also used : AndroidException(android.util.AndroidException) Configuration(android.content.res.Configuration) Resources(android.content.res.Resources) DisplayMetrics(android.util.DisplayMetrics)

Aggregations

AndroidException (android.util.AndroidException)27 ParcelFileDescriptor (android.os.ParcelFileDescriptor)17 File (java.io.File)17 FileNotFoundException (java.io.FileNotFoundException)17 IInstrumentationWatcher (android.app.IInstrumentationWatcher)6 UiAutomationConnection (android.app.UiAutomationConnection)6 ComponentName (android.content.ComponentName)6 Bundle (android.os.Bundle)6 IWindowManager (android.view.IWindowManager)6 ProfilerInfo (android.app.ProfilerInfo)5 InstrumentationInfo (android.content.pm.InstrumentationInfo)5 ArrayList (java.util.ArrayList)5 Configuration (android.content.res.Configuration)4 Resources (android.content.res.Resources)4 DisplayMetrics (android.util.DisplayMetrics)4