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; }