// Path: src/com/thoughtworks/calabash/android/Utils.java
// public static String runCommand(String[] command, String onExceptionMessage) throws CalabashException {
//     int exitCode;
//     try {
//         Process process = executeCommand(command);
//         exitCode = process.waitFor();
//         String error = toString(process.getErrorStream());
//         String output = toString(process.getInputStream());
//         CalabashLogger.info(output);
// 
//         if (exitCode == 0) {
//             return output;
//         } else {
//             CalabashLogger.error("Executing command failed");
//             CalabashLogger.info(output);
//             CalabashLogger.error(error);
//             throw new CalabashException(onExceptionMessage);
//         }
//     } catch (Exception e) {
//         throw new CalabashException(onExceptionMessage);
//     }
// }


import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import static com.thoughtworks.calabash.android.Utils.runCommand;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
        return tempAndroidPath;
    }

    public static void goToActivity(AndroidApplication application, final String activityName) throws CalabashException, OperationTimedoutException {
        application.query("* marked:'" + activityName + "'").touch();
        application.waitForActivity(activityMap.get(activityName), 6);
    }

    public static AndroidApplication installAppOnEmulator(String serial, String packageName, File androidApkPath) throws CalabashException {
        AndroidConfiguration configuration = new AndroidConfiguration();
        configuration.setLogsDirectory(new File("logs"));
        configuration.setSerial(serial);
        return installAppOnEmulator(serial, packageName, androidApkPath, configuration);
    }

    public static AndroidApplication installAppOnEmulator(String serial, String packageName, File androidApkPath, AndroidConfiguration configuration) throws CalabashException {
        uninstall(packageName, serial);
        configuration.setPauseTime(4000);
        AndroidRunner androidRunner = new AndroidRunner(androidApkPath.getAbsolutePath(), configuration);
        androidRunner.setup();
        AndroidApplication application = androidRunner.start();
        assertTrue(isAppInstalled(packageName, serial));
        assertTrue(isMainActivity(application, activityMap.get(ACTIVITY_MAIN)));
        return application;
    }

    public static void uninstall(String packageName, String serial) throws CalabashException {

        String[] command = {TestUtils.getAdbPath(), "-s", serial, "uninstall", packageName};
        try {
// Path: src/com/thoughtworks/calabash/android/Utils.java
// public static String runCommand(String[] command, String onExceptionMessage) throws CalabashException {
//     int exitCode;
//     try {
//         Process process = executeCommand(command);
//         exitCode = process.waitFor();
//         String error = toString(process.getErrorStream());
//         String output = toString(process.getInputStream());
//         CalabashLogger.info(output);
// 
//         if (exitCode == 0) {
//             return output;
//         } else {
//             CalabashLogger.error("Executing command failed");
//             CalabashLogger.info(output);
//             CalabashLogger.error(error);
//             throw new CalabashException(onExceptionMessage);
//         }
//     } catch (Exception e) {
//         throw new CalabashException(onExceptionMessage);
//     }
// }


// Path: tests/com/thoughtworks/calabash/android/TestUtils.java
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import static com.thoughtworks.calabash.android.Utils.runCommand;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

        return tempAndroidPath;
    }

    public static void goToActivity(AndroidApplication application, final String activityName) throws CalabashException, OperationTimedoutException {
        application.query("* marked:'" + activityName + "'").touch();
        application.waitForActivity(activityMap.get(activityName), 6);
    }

    public static AndroidApplication installAppOnEmulator(String serial, String packageName, File androidApkPath) throws CalabashException {
        AndroidConfiguration configuration = new AndroidConfiguration();
        configuration.setLogsDirectory(new File("logs"));
        configuration.setSerial(serial);
        return installAppOnEmulator(serial, packageName, androidApkPath, configuration);
    }

    public static AndroidApplication installAppOnEmulator(String serial, String packageName, File androidApkPath, AndroidConfiguration configuration) throws CalabashException {
        uninstall(packageName, serial);
        configuration.setPauseTime(4000);
        AndroidRunner androidRunner = new AndroidRunner(androidApkPath.getAbsolutePath(), configuration);
        androidRunner.setup();
        AndroidApplication application = androidRunner.start();
        assertTrue(isAppInstalled(packageName, serial));
        assertTrue(isMainActivity(application, activityMap.get(ACTIVITY_MAIN)));
        return application;
    }

    public static void uninstall(String packageName, String serial) throws CalabashException {

        String[] command = {TestUtils.getAdbPath(), "-s", serial, "uninstall", packageName};
        try {
            runCommand(command);