From 702287e09ba593735c4815ea32ecd8b55e314135 Mon Sep 17 00:00:00 2001 From: Nirothipan Date: Tue, 20 Jun 2017 11:01:27 +0530 Subject: [PATCH] Adding kill-server method --- .../org.carbon.android.emulator/TryIt.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.emulator/src/main/java/org.carbon.android.emulator/TryIt.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.emulator/src/main/java/org.carbon.android.emulator/TryIt.java index e3e100c4d..440308b9e 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.emulator/src/main/java/org.carbon.android.emulator/TryIt.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.emulator/src/main/java/org.carbon.android.emulator/TryIt.java @@ -744,11 +744,32 @@ public class TryIt { default: qemuSystemFileLocation += osSuffix + "-x86_64" + File.separator + "qemu-system-i386"; } + killServer(); + setExecutePermission(qemuSystemFileLocation); ExecutorService service = Executors.newSingleThreadExecutor(); service.execute(new TryItEmulator(deviceId, emulatorLocation)); } + /** + * This method ensures device properly starts. + */ + private void killServer() { + ProcessBuilder processBuilderKillServer = new ProcessBuilder(adbLocation, "kill-server"); + Process processKillServer = null; + + try { + processKillServer = processBuilderKillServer.start(); + } catch (IOException ignored) { + // process works if restarted + } + try { + processKillServer.waitFor(); + } catch (InterruptedException ignored) { + // can be continued + } + } + /** * This method halts the system the cache.img file is created for the particular AVD started. *