tap: fix bridge network setting
authorMunkyu Im <munkyu.im@samsung.com>
Thu, 17 Dec 2015 04:03:57 +0000 (13:03 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Mon, 21 Dec 2015 07:59:07 +0000 (16:59 +0900)
- change the way to configure TCP/IP
- fix inifinite while loop
- add logs
- change getting registry value

Change-Id: I0d494566c49723e053501644680d10cc69dd9ab4
Signed-off-by: Munkyu Im <munkyu.im@samsung.com>
resource/strings/messages.properties
src/org/tizen/emulator/manager/tool/TapUtil.java
src/org/tizen/emulator/manager/vms/helper/HelperClass.java

index 31ab50c..091ce66 100644 (file)
@@ -64,7 +64,7 @@ QemuImgProc.FormatError.1=Base image path :
 QemuImgProc.Qemu-imgError.0=Error while running 'qemu-img'. Exit value : 
 QemuImgProc.Qemu-imgError.1=You can get more information in log file (
 TapUtil.CreatedTapDevice.0=Tap device created : 
-TapUtil.CreatedTapDevice.1=Do you want to see the guide for bridge network ?
+TapUtil.CreatedTapDevice.1=Do you want to see the guide for bridge network?
 TapUtil.CreateTapDevice.0=Creating tap device.
 TapUtil.CreateTapDevice.1=This will take minutes..
 TapUtil.FailedCreateTapDevice.0=Failed to create tap device.
index 657b247..1d154a2 100644 (file)
@@ -42,6 +42,7 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.Enumeration;
 import java.util.List;
+import java.util.TreeMap;
 import java.util.regex.Pattern;
 
 import org.eclipse.swt.SWT;
@@ -70,6 +71,21 @@ import com.sun.jna.platform.win32.WinReg.HKEYByReference;
 public class TapUtil {
 
        public static String BRIDGE_NAME = "bridge1"; //$NON-NLS-1$
+       static String BRIDGE_OPTION = "--bridge"; //$NON-NLS-1$
+       static String NETSH = "netsh.exe"; //$NON-NLS-1$
+       private static int isDhcp = 0;
+       private static int WAIT_TIME = 2000;
+
+       public static String getCheckNetPath() {
+               String checkNet;
+               if (EmulatorManager.isWin()) {
+                       checkNet = "check-net.exe"; //$NON-NLS-1$
+               } else {
+                       checkNet = "check-net"; //$NON-NLS-1$
+               }
+               return FilePathResources.getEmulatorCheckToolPath() + File.separator + checkNet;
+       }
+
        public static String getDevconPath(String platformVersion) {
                return FilePathResources.getPlatformEmulatorBinPath(platformVersion)
                                + File.separator + "devcon.exe"; //$NON-NLS-1$
@@ -296,7 +312,7 @@ public class TapUtil {
                                                                                                + "\\" + subKey + "\\" + key, //$NON-NLS-1$ //$NON-NLS-2$
                                                                                                value);
                                                                if (tapName != null) {
-                                                                       EMLogger.getLogger().warning(
+                                                                       EMLogger.getLogger().info(
                                                                                        "tapname added: " + tapName); //$NON-NLS-1$
                                                                        tapNameList.add(tapName);
                                                                }
@@ -330,14 +346,19 @@ public class TapUtil {
                        regKey = Advapi32Util.registryGetKey(root, topKey, WinNT.KEY_READ);
                        String[] subKeys = Advapi32Util.registryGetKeys(regKey.getValue());
                        for (String subKey : subKeys) {
-                               String compId = Advapi32Util.registryGetStringValue(root,
-                                               topKey + "\\" + subKey, value1); //$NON-NLS-1$
-                               String tapId = Advapi32Util.registryGetStringValue(root, topKey
-                                               + "\\" + subKey, value2); //$NON-NLS-1$
-                               if (compId != null && tapId != null) {
-                                       if (compId.startsWith("tap")) { //$NON-NLS-1$
-                                               tapIdList.add(tapId);
+                               try {
+                                       String compId = Advapi32Util.registryGetStringValue(root,
+                                                       topKey + "\\" + subKey, value1); //$NON-NLS-1$
+                                       String tapId = Advapi32Util.registryGetStringValue(root,
+                                                       topKey + "\\" + subKey, value2); //$NON-NLS-1$
+                                       if (compId != null && tapId != null) {
+                                               if (compId.toLowerCase().startsWith("tap")) { //$NON-NLS-1$
+                                                       EMLogger.getLogger().info("tapId added: " + tapId);
+                                                       tapIdList.add(tapId);
+                                               }
                                        }
+                               } catch (Win32Exception e) {
+                                       EMLogger.getLogger().info(e.getMessage());
                                }
                        }
 
@@ -395,7 +416,7 @@ public class TapUtil {
                                        topKey = "SYSTEM\\CurrentControlSet\\services\\Bridge\\Linkage"; //$NON-NLS-1$
                                }
                                value = "Route"; //$NON-NLS-1$
-                               String valueArr[] = Advapi32Util.registryGetStringArray(root,
+                               String valueArr[] = registryGetStringArray(root,
                                                topKey, value);
                                for (String str : valueArr) {
                                        if (str.replace("\"", "").equals(foundTapId)) { //$NON-NLS-1$ //$NON-NLS-2$
@@ -424,6 +445,38 @@ public class TapUtil {
                return result;
        }
 
+       private static String[] registryGetStringArray(HKEY hKey, String value) {
+               return registryGetStringArray(hKey, null, value);
+       }
+
+       private static String[] registryGetStringArray(HKEY hKey, String path,
+                       String value) {
+               TreeMap<String, Object> values = null;
+               if (path == null) {
+                       values = Advapi32Util.registryGetValues(hKey);
+               } else {
+                       values = Advapi32Util.registryGetValues(hKey, path);
+               }
+               String[] resultArr = null;
+               for (String val : values.keySet()) {
+                       if (val.equals(value)) {
+                               Object obj = values.get(val);
+                               if (obj instanceof String[]) {
+                                       resultArr = (String[]) obj;
+                                       break;
+                               }
+                       }
+               }
+               EMLogger.getLogger().fine("Data in Registry " + path + ", " + value);
+               if (resultArr == null) {
+                       return new String[0];
+               }
+               for (String str : resultArr) {
+                       EMLogger.getLogger().fine(str);
+               }
+               return resultArr;
+       }
+
        public static String getNetmaskFromTap(String tapName) {
                String netMask = ""; //$NON-NLS-1$
                if (EmulatorManager.isLinux()) {
@@ -435,7 +488,7 @@ public class TapUtil {
                        HKEY key = getBridgeTcpipKey();
                        if (key != null) {
                                try {
-                                       String data[] = Advapi32Util.registryGetStringArray(key,
+                                       String data[] = registryGetStringArray(key,
                                                        "SubnetMask"); //$NON-NLS-1$
                                        if (data.length > 0) {
                                                netMask = data[0];
@@ -452,7 +505,7 @@ public class TapUtil {
                                key = getInterfaceTcpipKey(getBridgeId());
                                if (key != null) {
                                        try {
-                                               String data[] = Advapi32Util.registryGetStringArray(
+                                               String data[] = registryGetStringArray(
                                                                key, "SubnetMask"); //$NON-NLS-1$
                                                if (data.length > 0) {
                                                        netMask = data[0];
@@ -558,123 +611,136 @@ public class TapUtil {
        private static void setWinbridgeNetwork(String interfaceClassID)
                        throws VMWorkerException {
                HKEY interfaceKey = getInterfaceTcpipKey(interfaceClassID);
-               // HKEY bridgeKey = getInterfaceTcpipKey(getBridgeId());
-               System.out.println("interfaceKey: " + interfaceClassID); //$NON-NLS-1$
-               System.out.println("bridgeKey: " + getBridgeId()); //$NON-NLS-1$
+               EMLogger.getLogger().info("interfaceID: " + interfaceClassID); //$NON-NLS-1$
+               EMLogger.getLogger().info("bridgeID: " + getBridgeId()); //$NON-NLS-1$
                String dns = null;
                String ip = null;
                String gateway = null;
                String netmask = null;
                if (interfaceKey != null) {
                        try {
-                               String ips[] = Advapi32Util.registryGetStringArray(
-                                               interfaceKey, "IPAddress"); //$NON-NLS-1$
-                               if (ips.length > 0) {
-                                       ip = ips[0];
-                               }
-
-                               String gateways[] = Advapi32Util.registryGetStringArray(
-                                               interfaceKey, "DefaultGateway"); //$NON-NLS-1$
-                               if (gateways.length > 0) {
-                                       gateway = gateways[0];
-                               }
-
-                               String netmasks[] = Advapi32Util.registryGetStringArray(
-                                               interfaceKey, "SubnetMask"); //$NON-NLS-1$
-                               if (netmasks.length > 0) {
-                                       netmask = netmasks[0];
+                               isDhcp = Advapi32Util.registryGetIntValue(interfaceKey,
+                                               "EnableDHCP");
+                               EMLogger.getLogger().info("DHCP: " + isDhcp); //$NON-NLS-1$
+                               if (isDhcp == 0) {
+                                       /* get original network interface's TCP/IP configuration */
+                                       String ips[] = registryGetStringArray(interfaceKey,
+                                                       "IPAddress"); //$NON-NLS-1$
+                                       if (ips.length > 0) {
+                                               ip = ips[0];
+                                       }
+                                       EMLogger.getLogger().info("ip: " + ip);
+                                       String gateways[] = registryGetStringArray(interfaceKey,
+                                                       "DefaultGateway"); //$NON-NLS-1$
+                                       if (gateways.length > 0) {
+                                               gateway = gateways[0];
+                                       }
+                                       EMLogger.getLogger().info("gateway: " + gateway);
+                                       String netmasks[] = registryGetStringArray(interfaceKey,
+                                                       "SubnetMask"); //$NON-NLS-1$
+                                       if (netmasks.length > 0) {
+                                               netmask = netmasks[0];
+                                       }
+                                       EMLogger.getLogger().info("netmask: " + netmask);
                                }
-
                                String val = Advapi32Util.registryGetStringValue(interfaceKey,
                                                "NameServer"); //$NON-NLS-1$
-
                                String[] arr = val.split(","); //$NON-NLS-1$
                                if (arr.length > 0) {
                                        dns = arr[0];
                                }
+                               EMLogger.getLogger().info("NameServer: " + dns);
+
+                               List<String> cmd;
+                               ProcessResult res;
+                               String bridgeName = getBridgeNameFromClassID(getBridgeId());
+                               EMLogger.getLogger().info("Bridge Name: " + bridgeName);
+                               /* set bridge network interface's TCP/IP configuration */
+                               if (isDhcp == 0) {
+                                       if (ip != null && !ip.isEmpty()) {
+                                               String interfaceName = getBridgeNameFromClassID(interfaceClassID);
+                                               cmd = Arrays
+                                                               .asList(NETSH, "interface", //$NON-NLS-1$ //$NON-NLS-2$
+                                                                               "ipv4", "delete", "address", interfaceName, "addr=" + ip, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+                                                                               "gateway=all"); //$NON-NLS-1$
+                                               res = HelperClass.runProcess(cmd);
+                                               if (res.isSuccess() == false) {
+                                                       EMLogger.getLogger()
+                                                                       .warning(res.getResultMessage());
+                                               }
 
-                               String interfaceName = getBridgeNameFromClassID(interfaceClassID);
-                               List<String> cmd = Arrays.asList("netsh.exe", "interface", //$NON-NLS-1$ //$NON-NLS-2$
-                                               "ip", "delete", "address", interfaceName, "addr=" + ip, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-                                               "gateway=all"); //$NON-NLS-1$
-                               ProcessResult res = HelperClass.runProcess(cmd);
-                               if (res.isSuccess() == false) {
-                                       throw new VMWorkerException(res.getResultMessage());
-                               }
-
-                               String bridgeKey = "HKLM\\SYSTEM\\CurrentControlSet\\services\\Tcpip\\Parameters\\Interfaces\\" //$NON-NLS-1$
-                                               + getBridgeId();
-                               // TOOD: Advapi32Util.registrySetStringValue(...) not work
-                               cmd = Arrays.asList("reg.exe", "add", bridgeKey, "/f", "/v", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-                                               "EnableDHCP", "/t", "REG_DWORD", "/d", "0"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
-                               res = HelperClass.runProcess(cmd);
-                               if (res.isSuccess() == false) {
-                                       throw new VMWorkerException(res.getResultMessage());
-                               }
-
-                               cmd = Arrays.asList("reg.exe", "add", bridgeKey, "/f", "/v", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-                                               "IPAddress", "/t", "REG_MULTI_SZ", "/d", ip); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-                               res = HelperClass.runProcess(cmd);
-                               if (res.isSuccess() == false) {
-                                       throw new VMWorkerException(res.getResultMessage());
-                               }
-
-                               cmd = Arrays.asList("reg.exe", "add", bridgeKey, "/f", "/v", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-                                               "SubnetMask", "/t", "REG_MULTI_SZ", "/d", netmask); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-                               res = HelperClass.runProcess(cmd);
-                               if (res.isSuccess() == false) {
-                                       throw new VMWorkerException(res.getResultMessage());
-                               }
-
-                               cmd = Arrays.asList("reg.exe", "add", bridgeKey, "/f", "/v", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-                                               "DefaultGateway", "/t", "REG_MULTI_SZ", "/d", gateway); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-                               res = HelperClass.runProcess(cmd);
-                               if (res.isSuccess() == false) {
-                                       throw new VMWorkerException(res.getResultMessage());
-                               }
-
-                               cmd = Arrays
-                                               .asList("reg.exe", "add", bridgeKey, "/f", "/v", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-                                                               "DefaultGatewayMetric", "/t", "REG_MULTI_SZ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-                                                               "/d", "1"); //$NON-NLS-1$ //$NON-NLS-2$
-                               res = HelperClass.runProcess(cmd);
-                               if (res.isSuccess() == false) {
-                                       throw new VMWorkerException(res.getResultMessage());
+                                               if ((netmask != null && !netmask.isEmpty())
+                                                               && (gateway != null && !gateway.isEmpty())) {
+                                                       cmd = Arrays
+                                                                       .asList(NETSH, "-c", "int", "ipv4", "set", "address", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+                                                                                       "\"" + "name=" + bridgeName + "\"", "source=static", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+                                                                                       "address=" + ip, "mask=" + netmask, "gateway=" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+                                                                                                       + gateway, "gwmetric=0");
+                                                       res = HelperClass.runProcess(cmd);
+                                                       if (res.isSuccess() == false) {
+                                                               EMLogger.getLogger().warning(
+                                                                               "Failed to configure TCP/IP: "
+                                                                                               + res.getResultMessage());
+                                                       }
+                                               }
+                                       }
+                               } else if (isDhcp == 1) {
+                                       cmd = Arrays.asList(
+                                                       NETSH, "-c", "int", "ipv4", "set", "address", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+                                                       "\"" + "name=" + bridgeName + "\"", "dhcp"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+                                       res = HelperClass.runProcess(cmd);
+                                       if (res.isSuccess() == false) {
+                                               EMLogger.getLogger().warning(
+                                                               "Failed to enable DHCP: "
+                                                                               + res.getResultMessage());
+                                       }
+                               } else {
+                                       EMLogger.getLogger().warning(
+                                                       "dhcp value is wring:" + isDhcp);
                                }
-
-                               cmd = Arrays.asList("reg.exe", "add", bridgeKey, "/f", "/v", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-                                               "NameServer", "/t", "REG_SZ", "/d", dns); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-                               res = HelperClass.runProcess(cmd);
-                               if (res.isSuccess() == false) {
-                                       throw new VMWorkerException(res.getResultMessage());
+                               if (dns != null && !dns.isEmpty()) {
+                                       cmd = Arrays.asList(
+                                                       NETSH, "interface", "ipv4", "set", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+                                                       "dnsservers", "\"" + "name=" + bridgeName + "\"", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+                                                       "static", dns, "primary"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+                                       res = HelperClass.runProcess(cmd);
+                                       if (res.isSuccess() == false) {
+                                               EMLogger.getLogger().warning(
+                                                               "Failed to set DNS server: "
+                                                                               + res.getResultMessage());
+                                       }
                                }
                        } catch (Win32Exception e) {
                                EMLogger.getLogger().warning(e.getMessage());
                        } finally {
                                Advapi32Util.registryCloseKey(interfaceKey);
                        }
+               } else {
+                       EMLogger.getLogger().warning("interface key is null");
                }
-
        }
 
        private static String getBridgeId() {
                String bridgeId = null;
                if (EmulatorManager.isWin()) {
-                       HKEY root = WinReg.HKEY_LOCAL_MACHINE;
-                       String topKey = "SYSTEM\\CurrentControlSet\\services\\BridgeMP"; //$NON-NLS-1$
-                       String value = "Device"; //$NON-NLS-1$
-                       try {
-                               String data = Advapi32Util.registryGetStringValue(root, topKey,
-                                               value);
-                               if (data != null) {
-                                       String arr[] = data.split("\\\\"); //$NON-NLS-1$
-                                       bridgeId = arr[arr.length - 1];
+                       List<String> cmd = Arrays.asList(getCheckNetPath(), BRIDGE_OPTION); //$NON-NLS-1$
+                       ProcessResult res = HelperClass.runProcess(cmd);
+                       boolean isCommandSuccess = false;
+                       if (res.isSuccess()) {
+                               for (String str : res.getStdOutMsg()) {
+                                       if (str.startsWith("ClassID:")) { //$NON-NLS-1$
+                                               String arr[] = str.split(": "); //$NON-NLS-1$
+                                               bridgeId = arr[arr.length - 1];
+                                               break;
+                                       }
                                }
-                       } catch (Win32Exception e) {
-                               EMLogger.getLogger().warning(
-                                               "Failed to getBridgeId(): " + e.getMessage()); //$NON-NLS-1$
+                       } else if (!res.isSuccess() || !isCommandSuccess) {
+                               EMLogger.getLogger().warning(res.getResultMessage());
                        }
+               } else {
+                       EMLogger.getLogger().warning("OS is not Windows!");
                }
+               EMLogger.getLogger().info("bridgeId: " + bridgeId);
                return bridgeId;
        }
 
@@ -692,7 +758,7 @@ public class TapUtil {
                        HKEY key = getBridgeTcpipKey();
                        if (key != null) {
                                try {
-                                       String data[] = Advapi32Util.registryGetStringArray(key,
+                                       String data[] = registryGetStringArray(key,
                                                        "DefaultGateway"); //$NON-NLS-1$
                                        if (data.length > 0) {
                                                gateway = data[0];
@@ -709,7 +775,7 @@ public class TapUtil {
                                key = getInterfaceTcpipKey(getBridgeId());
                                if (key != null) {
                                        try {
-                                               String data[] = Advapi32Util.registryGetStringArray(
+                                               String data[] = registryGetStringArray(
                                                                key, "DefaultGateway"); //$NON-NLS-1$
                                                if (data.length > 0) {
                                                        gateway = data[0];
@@ -744,7 +810,6 @@ public class TapUtil {
                return gateway;
        }
 
-
        private static Boolean MANUAL_BRIDGE = null;
        public static void showGuideForMac() {
                // check version
@@ -1232,10 +1297,8 @@ public class TapUtil {
        }
 
        public static boolean isWinBridgeExist() {
-               String proxyCommand = "check-net.exe"; //$NON-NLS-1$
                boolean isExist = false;
-               List<String> cmd = Arrays.asList(FilePathResources.getEmulatorCheckToolPath()
-                               + File.separator + proxyCommand, "--bridge"); //$NON-NLS-1$
+               List<String> cmd = Arrays.asList(getCheckNetPath(), BRIDGE_OPTION); //$NON-NLS-1$
                ProcessResult res = HelperClass.runProcess(cmd);
                boolean isCommandSuccess = false;
                if (res.isSuccess()) {
@@ -1421,9 +1484,9 @@ public class TapUtil {
                                                if (!res.isSuccess()) {
                                                        throw new VMWorkerException(res.getResultMessage());
                                                }
-                                               EMLogger.getLogger().info("set bridge's IP"); //$NON-NLS-1$
-                                               setWinbridgeNetwork(getClassIDFromPnpInstanceID(CompatibleIDs));
                                        }
+                                       EMLogger.getLogger().info("set bridge's IP"); //$NON-NLS-1$
+                                       setWinbridgeNetwork(getClassIDFromPnpInstanceID(CompatibleIDs));
                                }
 
                                // Get tap list before create new tap.
@@ -1441,7 +1504,11 @@ public class TapUtil {
                                if (!res.isSuccess()) {
                                        throw new VMWorkerException(res.getResultMessage());
                                }
-
+                               //FIXME: to wait for re-naming tap name(work around)
+                               if (EmulatorManager.isWin8AndAbove()) {
+                                       EMLogger.getLogger().info("wait for renaming tap name");
+                                       Thread.sleep(WAIT_TIME);
+                               }
                                // Get tap list and find new one.
                                EMLogger.getLogger().info("Get tap list and find new one."); //$NON-NLS-1$
                                List<String> after = TapUtil.getTapList();
@@ -1460,7 +1527,7 @@ public class TapUtil {
 
                                // Rename new tap to tapX
                                EMLogger.getLogger().info("Rename new tap to tapX."); //$NON-NLS-1$
-                               cmd = Arrays.asList("netsh", "interface", "set", "interface", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+                               cmd = Arrays.asList(NETSH, "interface", "set", "interface", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                                                "name=" + newOne, "newname=" + tapName); //$NON-NLS-1$ //$NON-NLS-2$
                                res = HelperClass.runProcess(cmd);
                                if (!res.isSuccess()) {
@@ -1487,37 +1554,35 @@ public class TapUtil {
                                        if (!res.isSuccess()) {
                                                throw new VMWorkerException(res.getResultMessage());
                                        }
-
-                                       EMLogger.getLogger().info(
-                                                       "wait while finishing bridged network setting"); //$NON-NLS-1$
-                                       String proxyCommand = "check-net.exe"; //$NON-NLS-1$
-                                       cmd = Arrays.asList(FilePathResources.getEmulatorCheckToolPath()
-                                                       + File.separator + proxyCommand, "--bridge"); //$NON-NLS-1$
-                                       res = HelperClass.runProcess(cmd);
-                                       while (!res.getStdOutMsg().isEmpty()) {
-                                               boolean isCommandSuccess = false;
-                                               String ipAddr = null;
-                                               if (res.isSuccess()) {
-                                                       for (String str : res.getStdOutMsg()) {
-                                                               if (str.startsWith("IP Address:")) { //$NON-NLS-1$
-                                                                       isCommandSuccess = true;
-                                                                       ipAddr = str.split("IP Address: ")[1] //$NON-NLS-1$
-                                                                                       .trim();
-                                                                       EMLogger.getLogger().info(
-                                                                                       "bridge IP address: " + ipAddr); //$NON-NLS-1$
-                                                                       break;
+                                       if (isDhcp == 0) {
+                                               EMLogger.getLogger().info(
+                                                               "wait while finishing bridged network setting"); //$NON-NLS-1$
+                                               cmd = Arrays.asList(getCheckNetPath(), BRIDGE_OPTION); //$NON-NLS-1$
+                                               res = HelperClass.runProcess(cmd);
+                                               while (!res.getStdOutMsg().isEmpty()) {
+                                                       boolean isCommandSuccess = false;
+                                                       String ipAddr = null;
+                                                       if (res.isSuccess()) {
+                                                               for (String str : res.getStdOutMsg()) {
+                                                                       if (str.startsWith("IP Address:")) { //$NON-NLS-1$
+                                                                               isCommandSuccess = true;
+                                                                               ipAddr = str.split("IP Address: ")[1] //$NON-NLS-1$
+                                                                                               .trim();
+                                                                               EMLogger.getLogger().info(
+                                                                                               "bridge IP address: " + ipAddr); //$NON-NLS-1$
+                                                                               break;
+                                                                       }
                                                                }
+                                                       } else if (!res.isSuccess() || !isCommandSuccess) {
+                                                               EMLogger.getLogger().warning(
+                                                                               res.getResultMessage());
                                                        }
-                                               } else if (!res.isSuccess() || !isCommandSuccess) {
-                                                       EMLogger.getLogger()
-                                                                       .warning(res.getResultMessage());
-                                               }
-                                               if (ipAddr != null) {
-                                                       break;
+                                                       if (ipAddr != null) {
+                                                               break;
+                                                       }
+                                                       res = HelperClass.runProcess(cmd);
                                                }
-                                               res = HelperClass.runProcess(cmd);
                                        }
-
                                        // shows success message
                                        final MessageDialog messageDialog = new MessageDialog();
                                        if (isTapExist) {
@@ -1537,10 +1602,8 @@ public class TapUtil {
                                                        @Override
                                                        public void run() {
                                                                int res = resultDialog
-                                                                               .openSelectionDialog(Messages.getString("TapUtil.CreatedTapDevice.0") //$NON-NLS-1$
+                                                                               .openSelectionDialog(Messages.getString("TapUtil.CreatedTapDevice.0" + tapName) //$NON-NLS-1$
                                                                                                + StringResources.NEW_LINE
-                                                                                               + Messages.getString("TapUtil.CreatedTapDevice.1") //$NON-NLS-1$
-                                                                                               + tapName + StringResources.NEW_LINE
                                                                                                + Messages.getString("TapUtil.CreatedTapDevice.1")); //$NON-NLS-1$
                                                                if (res == SWT.OK) {
                                                                        // Show bridge guide dialog
@@ -1550,8 +1613,7 @@ public class TapUtil {
                                                });
 
                                        } else {
-                                               throw new VMWorkerException("Tap is not exist : " //$NON-NLS-1$
-                                                               + tapName);
+                                               throw new VMWorkerException("Tap is not exist : " + tapName);//$NON-NLS-1$
                                        }
                                }
                        } catch (VMWorkerException e) {
@@ -1569,6 +1631,8 @@ public class TapUtil {
                                        }
                                });
 
+                       } catch (InterruptedException e) {
+                               EMLogger.getLogger().warning(e.getMessage());
                        } finally {
                                Display.getDefault().asyncExec(new Runnable() {
                                        @Override
index 9c22856..34730ec 100644 (file)
@@ -249,7 +249,7 @@ public class HelperClass {
                        pb.directory(directory);
                }
 
-               EMLogger.getLogger().log(Level.INFO, "Try to run external process: " + cmd.get(0)); //$NON-NLS-1$
+               EMLogger.getLogger().log(Level.INFO, "Try to run external process: " + cmd); //$NON-NLS-1$
                EMLogger.getLogger().log(Level.INFO, " -- Working dir : " + workingDirPath);
 
                try {