public boolean stop(String serialNo) { // NOPMD
    /* check adb connection */
    if (!mTestManager.isAdbConnected()) {
      throw new IllegalStateException("ADB is not connected");
    }

    if (!isRunning(serialNo)) {
      mLog.v("Emualtor \"%s\" is not running. Nothing to stop.", serialNo);
      return true;
    }

    /* verify serial represents emulator, and not a real device */
    AndroidDebugBridge adb = mTestManager.getAndroidDebugBridge();
    boolean skipAdbStop = true;
    for (IDevice curDevice : adb.getDevices()) {
      if (curDevice.getSerialNumber().endsWith(serialNo)) {
        if (!curDevice.isEmulator()) {
          throw new IllegalArgumentException("Not an emulator: " + serialNo);
        }
        skipAdbStop = false;
        break;
      }
    }

    if (!skipAdbStop) { // NOPMD
      /* Killing emulator using adb's embedded control over emulator console */
      mLog.v("Killing emulator \"%s\" using adb.", serialNo);
      if (adbStop(serialNo)) {
        if (waitForEmualtorStopped(serialNo, DEFAULT_TIMEOUT)) {
          mLog.v("Emulator \"%s\" is no longer running.", serialNo);
          return true;
        }
      } else {
        mLog.v("Failed to stop emulator \"%s\" using avd.", serialNo);
      }
    } else {
      mLog.w("Emulator \"%s\" is not visible from adb.", serialNo);
    }

    /* Let's kill emulator using emulator console */
    mLog.v("Killing emulator \"%s\" using emulator console.", serialNo);
    if (mConsole.consoleStop(serialNo)) {
      if (waitForEmualtorStopped(serialNo, DEFAULT_TIMEOUT)) {
        mLog.v("Emulator \"%s\" is no longer running.", serialNo);
        return true;
      }
    } else {
      mLog.v("Failed to stop emulator \"%s\" using emulator console.", serialNo);
    }

    mLog.e(null, "I really tried to kill \"%s\" emulator. But failed.", serialNo);
    return false;
  }
 /**
  * Detects if emulator is running using adb.
  *
  * @param serialNo
  * @return true if running, false otherwise.
  */
 public boolean adbIsRunning(String serialNo) {
   AndroidDebugBridge adb = mTestManager.getAndroidDebugBridge();
   for (IDevice device : adb.getDevices()) {
     if (device.getSerialNumber().endsWith(serialNo)) {
       return true;
     }
   }
   return false;
 }
  /** **************************************** */
  public boolean adbStop(String serialNo) {
    ToolsManager toolsManager = mTestManager.getToolsManager();
    AdbTool adbTool = toolsManager.createAdbTool();

    adbTool.addArgument("-s", serialNo, "emu", "kill");
    try {
      Result result = adbTool.execute();
      return result.getExitCode() == 0;
    } catch (Exception ex) {
      mLog.e(ex, "Failed to stop emulator \"%s\" using adb.", serialNo);
      return false;
    }
  }
 public EmulatorStopper(TestManager testManager) {
   mLog = testManager.newPrefixedLogger(EmulatorStopper.class);
   mConsole = new EmulatorConsole(testManager);
   mTestManager = testManager;
 }