From 4df8784a12470651bc1451148decb4ed133a8bf1 Mon Sep 17 00:00:00 2001 From: Munkyu Im Date: Wed, 8 Apr 2015 21:23:29 +0900 Subject: [PATCH] net: Support bridged network on windows and ubuntu Support automation on ubuntu Support semi automation on windows 7 Change querying bridge device Change UX TODO: Windows 8 automation Change-Id: I7111eaf681f29dc4e160490e2899aef862203d1f Signed-off-by: Munkyu Im --- .../tizen/emulator/manager/EmulatorManager.java | 8 + .../org/tizen/emulator/manager/tool/TapUtil.java | 721 ++++++++++++++++----- .../item/property/NetConnectTypeViewItem.java | 5 +- .../item/property/NetIPInfoTextSubViewItem.java | 20 +- .../detail/item/property/NetTapDeviceViewItem.java | 99 +-- .../item/property/NetTapDeviceViewItemWin.java | 290 +++++++++ .../manager/ui/dialog/TapDeviceDialogForLinux.java | 466 +------------ .../manager/ui/dialog/TapDeviceDialogForMac.java | 247 +------ .../manager/ui/dialog/TapDeviceDialogForWin.java | 170 +++-- .../manager/mobile/ui/detail/ItemListFactory.java | 6 + .../emulator/manager/mobile/vms/Launcher.java | 63 +- .../emulator/manager/wearable/vms/Launcher.java | 93 +-- 12 files changed, 1115 insertions(+), 1073 deletions(-) create mode 100644 common-project/src/org/tizen/emulator/manager/ui/detail/item/property/NetTapDeviceViewItemWin.java diff --git a/common-project/src/org/tizen/emulator/manager/EmulatorManager.java b/common-project/src/org/tizen/emulator/manager/EmulatorManager.java index 3240853..9a077ec 100755 --- a/common-project/src/org/tizen/emulator/manager/EmulatorManager.java +++ b/common-project/src/org/tizen/emulator/manager/EmulatorManager.java @@ -77,6 +77,7 @@ public class EmulatorManager { private static RandomAccessFile randomAccessFile; private static boolean isMac = false; private static boolean isWin = false; + private static boolean isWin8 = false; private static boolean isLinux = false; static { @@ -84,6 +85,9 @@ public class EmulatorManager { isLinux = true; } else if (System.getProperty("os.name").toLowerCase().indexOf("win") > -1) { isWin = true; + if (System.getProperty("os.name").startsWith("Windows 8")) { + isWin8 = true; + } } else if (System.getProperty("os.name").toLowerCase().indexOf("mac") > -1) { isMac = true; } @@ -127,6 +131,10 @@ public class EmulatorManager { return isWin; } + public static boolean isWin8() { + return isWin8; + } + public static boolean isLinux() { return isLinux; } diff --git a/common-project/src/org/tizen/emulator/manager/tool/TapUtil.java b/common-project/src/org/tizen/emulator/manager/tool/TapUtil.java index dc0a732..81d9c9c 100644 --- a/common-project/src/org/tizen/emulator/manager/tool/TapUtil.java +++ b/common-project/src/org/tizen/emulator/manager/tool/TapUtil.java @@ -1,8 +1,9 @@ /* Emulator Manager * - * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (C) 2011 - 2015 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: + * Munkyu Im * Minkee Lee * SeokYeon Hwang * Sangho Park @@ -61,8 +62,9 @@ import com.sun.jna.platform.win32.WinReg.HKEY; import com.sun.jna.platform.win32.WinReg.HKEYByReference; public class TapUtil { - - public static String getBridgeFromDevice(String device) throws VMWorkerException { + private static String devconPath = FilePathResources.getBinPath() + File.separator + "devcon.exe"; + public static String getBridgeFromDevice(String device) + throws VMWorkerException { String result = null; if (EmulatorManager.isLinux()) { @@ -97,7 +99,8 @@ public class TapUtil { return result; } - public static List getDefaultGateway(String ifName) throws VMWorkerException { + public static List getDefaultGateway(String ifName) + throws VMWorkerException { List result = new ArrayList(); if (EmulatorManager.isLinux()) { @@ -116,7 +119,8 @@ public class TapUtil { } else { if (arr.length >= 5) { - if (arr[0].equals("default") && arr[4].equals(ifName)) { + if (arr[0].equals("default") + && arr[4].equals(ifName)) { result.add(arr[2]); } } @@ -153,8 +157,8 @@ public class TapUtil { } - public static List getTapList() { - List list = new ArrayList(); + public static ArrayList getTapList() { + ArrayList list = new ArrayList(); // Get tap device list from Host OS. if (EmulatorManager.isLinux()) { @@ -178,8 +182,8 @@ public class TapUtil { return list; } - private static List getTapListForMac() { - List result = new ArrayList(); + private static ArrayList getTapListForMac() { + ArrayList result = new ArrayList(); result.add("auto"); return result; } @@ -193,7 +197,10 @@ public class TapUtil { List cmd = Arrays.asList("ip", "tuntap"); ProcessResult res = HelperClass.runProcess(cmd); if (res.isSuccess() == false) { - EMLogger.getLogger().warning("Get tap list fail. Command returns fail:" + "cmd : " + cmd.toString() + ", return : " + res.getExitValue()); + EMLogger.getLogger().warning( + "Get tap list fail. Command returns fail:" + "cmd : " + + cmd.toString() + ", return : " + + res.getExitValue()); } else { for (String line : res.getStdOutMsg()) { String arr[] = line.split(":"); @@ -213,16 +220,20 @@ public class TapUtil { private static List getTapListForWin() { List result = new ArrayList(); List cmd = new ArrayList(); - ProcessBuilder pb = new ProcessBuilder(new String[] { "openvpn", "--show-adapters" }); + ProcessBuilder pb = new ProcessBuilder(new String[] { "openvpn", + "--show-adapters" }); int exitValue = 0; Process process; try { process = pb.start(); - List stdOut = ProcessOutputReader.readStdOut(process, cmd.toString()); + List stdOut = ProcessOutputReader.readStdOut(process, + cmd.toString()); exitValue = process.waitFor(); if (exitValue != 0) { - EMLogger.getLogger().warning("Get tap list fail. Command returns fail:" + "cmd : " + cmd.toString() + ", return : " + exitValue); + EMLogger.getLogger().warning( + "Get tap list fail. Command returns fail:" + "cmd : " + + cmd.toString() + ", return : " + exitValue); } else { for (String line : stdOut) { if (line.contains("'")) { @@ -235,20 +246,22 @@ public class TapUtil { } } catch (IOException e) { - EMLogger.getLogger().warning("Get tap list fail. " + e.getMessage()); + EMLogger.getLogger() + .warning("Get tap list fail. " + e.getMessage()); e.printStackTrace(); } catch (InterruptedException e) { - EMLogger.getLogger().warning("Get tap list fail. " + e.getMessage()); + EMLogger.getLogger() + .warning("Get tap list fail. " + e.getMessage()); e.printStackTrace(); } return result; } - private static List getTapListForWin2() { - List tapNameList = new ArrayList(); - List tapIdList = getTapIdList(); + private static ArrayList getTapListForWin2() { + ArrayList tapNameList = new ArrayList(); + ArrayList tapIdList = getTapIdList(); HKEY root = WinReg.HKEY_LOCAL_MACHINE; String topKey = "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}"; String key = "Connection"; @@ -260,12 +273,17 @@ public class TapUtil { for (String subKey : subKeys) { for (String tapId : tapIdList) { if (subKey.equals(tapId)) { - String[] subKeys2 = Advapi32Util.registryGetKeys(root, topKey + "\\" + subKey); + String[] subKeys2 = Advapi32Util.registryGetKeys(root, + topKey + "\\" + subKey); for (String subKey2 : subKeys2) { if (subKey2.equals(key)) { - String tapName = Advapi32Util.registryGetStringValue(root, topKey + "\\" + subKey + "\\" + key, value); + String tapName = Advapi32Util + .registryGetStringValue(root, topKey + + "\\" + subKey + "\\" + key, + value); if (tapName != null) { - EMLogger.getLogger().warning("tapname added: " + tapName); + EMLogger.getLogger().warning( + "tapname added: " + tapName); tapNameList.add(tapName); } } @@ -275,7 +293,7 @@ public class TapUtil { } } catch (Win32Exception e) { - + EMLogger.getLogger().info(e.getMessage()); } finally { if (regKey != null) { Advapi32Util.registryCloseKey(regKey.getValue()); @@ -285,9 +303,9 @@ public class TapUtil { return tapNameList; } - private static List getTapIdList() { + private static ArrayList getTapIdList() { - List tapIdList = new ArrayList(); + ArrayList tapIdList = new ArrayList(); HKEY root = WinReg.HKEY_LOCAL_MACHINE; String topKey = "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}"; @@ -298,8 +316,10 @@ 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); - String tapId = Advapi32Util.registryGetStringValue(root, topKey + "\\" + subKey, value2); + String compId = Advapi32Util.registryGetStringValue(root, + topKey + "\\" + subKey, value1); + String tapId = Advapi32Util.registryGetStringValue(root, topKey + + "\\" + subKey, value2); if (compId != null && tapId != null) { if (compId.startsWith("tap")) { tapIdList.add(tapId); @@ -308,7 +328,7 @@ public class TapUtil { } } catch (Win32Exception e) { - + EMLogger.getLogger().info(e.getMessage()); } finally { if (regKey != null) { Advapi32Util.registryCloseKey(regKey.getValue()); @@ -329,15 +349,21 @@ public class TapUtil { String value = "Name"; HKEYByReference regKey = null; try { - regKey = Advapi32Util.registryGetKey(root, topKey, WinNT.KEY_READ); - String[] subKeys = Advapi32Util.registryGetKeys(regKey.getValue()); + regKey = Advapi32Util.registryGetKey(root, topKey, + WinNT.KEY_READ); + String[] subKeys = Advapi32Util.registryGetKeys(regKey + .getValue()); for (String subKey : subKeys) { for (String tapId : tapIdList) { if (subKey.equals(tapId)) { - String[] subKeys2 = Advapi32Util.registryGetKeys(root, topKey + "\\" + subKey); + String[] subKeys2 = Advapi32Util.registryGetKeys( + root, topKey + "\\" + subKey); for (String subKey2 : subKeys2) { if (subKey2.equals(key)) { - String name = Advapi32Util.registryGetStringValue(root, topKey + "\\" + subKey + "\\" + key, value); + String name = Advapi32Util + .registryGetStringValue(root, + topKey + "\\" + subKey + + "\\" + key, value); if (name != null) { if (name.equals(tapName)) { foundTapId = tapId; @@ -349,13 +375,14 @@ public class TapUtil { } } EMLogger.getLogger().warning("found tapid: " + foundTapId); - if (System.getProperty("os.name").startsWith("Windows 8")) { + if (EmulatorManager.isWin8()) { topKey = "SYSTEM\\CurrentControlSet\\services\\NdisImPlatform\\Linkage"; } else { topKey = "SYSTEM\\CurrentControlSet\\services\\Bridge\\Linkage"; } value = "Route"; - String valueArr[] = Advapi32Util.registryGetStringArray(root, topKey, value); + String valueArr[] = Advapi32Util.registryGetStringArray(root, + topKey, value); for (String str : valueArr) { if (str.replace("\"", "").equals(foundTapId)) { result = true; @@ -364,7 +391,9 @@ public class TapUtil { } } catch (Win32Exception e) { - EMLogger.getLogger().warning("Failed to check if tap exists in bridge or not" + e.getMessage()); + EMLogger.getLogger().warning( + "Failed to check if tap exists in bridge or not" + + e.getMessage()); } finally { if (regKey != null) { Advapi32Util.registryCloseKey(regKey.getValue()); @@ -396,7 +425,8 @@ public class TapUtil { HKEY key = getBridgeTcpipKey(); if (key != null) { try { - String data[] = Advapi32Util.registryGetStringArray(key, "SubnetMask"); + String data[] = Advapi32Util.registryGetStringArray(key, + "SubnetMask"); if (data.length > 0) { netMask = data[0]; } @@ -412,7 +442,8 @@ public class TapUtil { key = getInterfaceTcpipKey(getBridgeId()); if (key != null) { try { - String data[] = Advapi32Util.registryGetStringArray(key, "SubnetMask"); + String data[] = Advapi32Util.registryGetStringArray( + key, "SubnetMask"); if (data.length > 0) { netMask = data[0]; } @@ -424,7 +455,8 @@ public class TapUtil { } } } else if (EmulatorManager.isMac()) { - List cmd = Arrays.asList("/bin/sh", "-c", "ifconfig en0 | grep \"inet \" | awk '{print $4}'"); + List cmd = Arrays.asList("/bin/sh", "-c", + "ifconfig en0 | grep \"inet \" | awk '{print $4}'"); ProcessResult res = HelperClass.runProcess(cmd); boolean isCommandSuccess = false; if (res.isSuccess()) { @@ -436,14 +468,18 @@ public class TapUtil { } if (netMask.length() == 0) { isCommandSuccess = false; - cmd = Arrays.asList("/bin/sh", "-c", "ifconfig bridge1 | grep \"inet \" | awk '{print $4}'"); + cmd = Arrays + .asList("/bin/sh", "-c", + "ifconfig bridge1 | grep \"inet \" | awk '{print $4}'"); res = HelperClass.runProcess(cmd); if (res.isSuccess()) { for (String str : res.getStdOutMsg()) { isCommandSuccess = true; - long ipAddress = Long.parseLong(str.substring(2), 16); + long ipAddress = Long.parseLong(str.substring(2), + 16); netMask = longToIpAddress(ipAddress); - EMLogger.getLogger().info("netmask bridge1: " + netMask); + EMLogger.getLogger().info( + "netmask bridge1: " + netMask); } } } @@ -478,24 +514,10 @@ public class TapUtil { } HKEY root = WinReg.HKEY_LOCAL_MACHINE; - String topKey = "SYSTEM\\CurrentControlSet\\services"; - HKEYByReference regKey = null; - try { - regKey = Advapi32Util.registryGetKey(root, topKey, WinNT.KEY_READ); - String[] subKeys = Advapi32Util.registryGetKeys(regKey.getValue()); - for (String subKey : subKeys) { - if (subKey.equals(bridgeId)) { - resultKey = Advapi32Util.registryGetKey(root, topKey + "\\" + subKey + "\\Parameters\\Tcpip", WinNT.KEY_READ).getValue(); - break; - } - } - } catch (Win32Exception e) { - EMLogger.getLogger().warning(e.getMessage()); - } finally { - if (regKey != null) { - Advapi32Util.registryCloseKey(regKey.getValue()); - } - } + String topKey = "SYSTEM\\CurrentControlSet\\services\\Tcpip\\Parameters\\Interfaces"; + + resultKey = Advapi32Util.registryGetKey(root, topKey + "\\" + bridgeId, + WinNT.KEY_READ).getValue(); return resultKey; } @@ -506,10 +528,12 @@ public class TapUtil { HKEY resultKey = null; HKEY root = WinReg.HKEY_LOCAL_MACHINE; - String topKey = "SYSTEM\\CurrentControlSet\\services\\Tcpip\\Parameters\\Interfaces" + "\\" + ifId; + String topKey = "SYSTEM\\CurrentControlSet\\services\\Tcpip\\Parameters\\Interfaces" + + "\\" + ifId; try { - resultKey = Advapi32Util.registryGetKey(root, topKey, WinNT.KEY_READ).getValue(); + resultKey = Advapi32Util.registryGetKey(root, topKey, + WinNT.KEY_READ).getValue(); } catch (Win32Exception e) { EMLogger.getLogger().warning(e.getMessage()); @@ -517,6 +541,108 @@ public class TapUtil { return resultKey; } + private static void setWinbridgeNetwork(String interfaceClassID) + throws VMWorkerException { + HKEY interfaceKey = getInterfaceTcpipKey(interfaceClassID); + // HKEY bridgeKey = getInterfaceTcpipKey(getBridgeId()); + System.out.println("interfaceKey: " + interfaceClassID); + System.out.println("bridgeKey: " + getBridgeId()); + String dns = null; + String ip = null; + String gateway = null; + String netmask = null; + if (interfaceKey != null) { + try { + String ips[] = Advapi32Util.registryGetStringArray( + interfaceKey, "IPAddress"); + if (ips.length > 0) { + ip = ips[0]; + } + + String gateways[] = Advapi32Util.registryGetStringArray( + interfaceKey, "DefaultGateway"); + if (gateways.length > 0) { + gateway = gateways[0]; + } + + String netmasks[] = Advapi32Util.registryGetStringArray( + interfaceKey, "SubnetMask"); + if (netmasks.length > 0) { + netmask = netmasks[0]; + } + + String val = Advapi32Util.registryGetStringValue(interfaceKey, + "NameServer"); + + String[] arr = val.split(","); + if (arr.length > 0) { + dns = arr[0]; + } + + String interfaceName = getBridgeNameFromClassID(interfaceClassID); + List cmd = Arrays.asList("netsh.exe", "interface", + "ip", "delete", "address", interfaceName, "addr=" + ip, + "gateway=all"); + ProcessResult res = HelperClass.runProcess(cmd); + if (res.isSuccess() == false) { + throw new VMWorkerException(res.getResultMessage()); + } + + String bridgeKey = "HKLM\\SYSTEM\\CurrentControlSet\\services\\Tcpip\\Parameters\\Interfaces\\" + + getBridgeId(); + // TOOD: Advapi32Util.registrySetStringValue(...) not work + cmd = Arrays.asList("reg.exe", "add", bridgeKey, "/f", "/v", + "EnableDHCP", "/t", "REG_DWORD", "/d", "0"); + res = HelperClass.runProcess(cmd); + if (res.isSuccess() == false) { + throw new VMWorkerException(res.getResultMessage()); + } + + cmd = Arrays.asList("reg.exe", "add", bridgeKey, "/f", "/v", + "IPAddress", "/t", "REG_MULTI_SZ", "/d", ip); + res = HelperClass.runProcess(cmd); + if (res.isSuccess() == false) { + throw new VMWorkerException(res.getResultMessage()); + } + + cmd = Arrays.asList("reg.exe", "add", bridgeKey, "/f", "/v", + "SubnetMask", "/t", "REG_MULTI_SZ", "/d", netmask); + res = HelperClass.runProcess(cmd); + if (res.isSuccess() == false) { + throw new VMWorkerException(res.getResultMessage()); + } + + cmd = Arrays.asList("reg.exe", "add", bridgeKey, "/f", "/v", + "DefaultGateway", "/t", "REG_MULTI_SZ", "/d", gateway); + res = HelperClass.runProcess(cmd); + if (res.isSuccess() == false) { + throw new VMWorkerException(res.getResultMessage()); + } + + cmd = Arrays + .asList("reg.exe", "add", bridgeKey, "/f", "/v", + "DefaultGatewayMetric", "/t", "REG_MULTI_SZ", + "/d", "1"); + res = HelperClass.runProcess(cmd); + if (res.isSuccess() == false) { + throw new VMWorkerException(res.getResultMessage()); + } + + cmd = Arrays.asList("reg.exe", "add", bridgeKey, "/f", "/v", + "NameServer", "/t", "REG_SZ", "/d", dns); + res = HelperClass.runProcess(cmd); + if (res.isSuccess() == false) { + throw new VMWorkerException(res.getResultMessage()); + } + } catch (Win32Exception e) { + EMLogger.getLogger().warning(e.getMessage()); + } finally { + Advapi32Util.registryCloseKey(interfaceKey); + } + } + + } + private static String getBridgeId() { String bridgeId = null; if (EmulatorManager.isWin()) { @@ -524,13 +650,15 @@ public class TapUtil { String topKey = "SYSTEM\\CurrentControlSet\\services\\BridgeMP"; String value = "Device"; try { - String data = Advapi32Util.registryGetStringValue(root, topKey, value); + String data = Advapi32Util.registryGetStringValue(root, topKey, + value); if (data != null) { String arr[] = data.split("\\\\"); bridgeId = arr[arr.length - 1]; } } catch (Win32Exception e) { - EMLogger.getLogger().warning("Failed to getBridgeId(): " + e.getMessage()); + EMLogger.getLogger().warning( + "Failed to getBridgeId(): " + e.getMessage()); } } return bridgeId; @@ -550,7 +678,8 @@ public class TapUtil { HKEY key = getBridgeTcpipKey(); if (key != null) { try { - String data[] = Advapi32Util.registryGetStringArray(key, "DefaultGateway"); + String data[] = Advapi32Util.registryGetStringArray(key, + "DefaultGateway"); if (data.length > 0) { gateway = data[0]; } @@ -566,7 +695,8 @@ public class TapUtil { key = getInterfaceTcpipKey(getBridgeId()); if (key != null) { try { - String data[] = Advapi32Util.registryGetStringArray(key, "DefaultGateway"); + String data[] = Advapi32Util.registryGetStringArray( + key, "DefaultGateway"); if (data.length > 0) { gateway = data[0]; } @@ -578,7 +708,8 @@ public class TapUtil { } } } else if (EmulatorManager.isMac()) { - List cmd = Arrays.asList("/bin/sh", "-c", "netstat -rn | grep ^default | awk '{print $2}'"); + List cmd = Arrays.asList("/bin/sh", "-c", + "netstat -rn | grep ^default | awk '{print $2}'"); ProcessResult res = HelperClass.runProcess(cmd); boolean isCommandSuccess = false; if (res.isSuccess()) { @@ -609,7 +740,10 @@ public class TapUtil { private static String getDnsForMac(String tapName) { String dnsServer = ""; - List cmd = Arrays.asList("/bin/sh", "-c", "/usr/sbin/scutil --dns | grep nameserver\\[[0]*\\] | awk '{print $3}' | head -n 1"); + List cmd = Arrays + .asList("/bin/sh", + "-c", + "/usr/sbin/scutil --dns | grep nameserver\\[[0]*\\] | awk '{print $3}' | head -n 1"); ProcessResult res = HelperClass.runProcess(cmd); boolean isCommandSuccess = false; if (res.isSuccess()) { @@ -641,7 +775,8 @@ public class TapUtil { List cmd = Arrays.asList("nm-tool", brName); ProcessResult res = HelperClass.runProcess(cmd); if (!res.isSuccess()) { - EMLogger.getLogger().warning("Get dns failed. " + res.getResultMessage()); + EMLogger.getLogger().warning( + "Get dns failed. " + res.getResultMessage()); return ""; } @@ -662,7 +797,8 @@ public class TapUtil { HKEY key = getInterfaceTcpipKey(getBridgeId()); if (key != null) { try { - String val = Advapi32Util.registryGetStringValue(key, "NameServer"); + String val = Advapi32Util.registryGetStringValue(key, + "NameServer"); String[] arr = val.split(","); if (arr.length > 0) { dns = arr[0]; @@ -687,7 +823,8 @@ public class TapUtil { while (interfaces.hasMoreElements()) { NetworkInterface current = interfaces.nextElement(); if (current.getName().equals(ifName)) { - for (InterfaceAddress addr : current.getInterfaceAddresses()) { + for (InterfaceAddress addr : current + .getInterfaceAddresses()) { if (addr.getAddress() instanceof Inet4Address) { return addr; } @@ -778,11 +915,14 @@ public class TapUtil { return isNotExist; } - public static void createTapDevice(String tapName, ComboViewItem comboViewItem) { + public static void createTapDevice(String tapName, String ifName, + ComboViewItem comboViewItem) { if (EmulatorManager.isWin()) { MessageDialog msgDialog = new MessageDialog(); - msgDialog.openNoButtonInfoDialog("Creating tap device.\nThis will take few seconds.."); - TapCreateWorker worker = new TapCreateWorker(tapName, msgDialog, comboViewItem); + msgDialog + .openNoButtonInfoDialog("Creating tap device.\nThis will take minutes.."); + TapCreateWorker worker = new TapCreateWorker(tapName, ifName, + msgDialog, comboViewItem); worker.start(); } @@ -796,35 +936,34 @@ public class TapUtil { if (ifAddr != null) ipAddr = ifAddr.getAddress().getHostAddress(); } catch (VMWorkerException e) { - EMLogger.getLogger().warning((new StringBuilder()).append("Failed to get bridge ip address. ").append(e.getMessage()).toString()); + EMLogger.getLogger().warning( + (new StringBuilder()) + .append("Failed to get bridge ip address. ") + .append(e.getMessage()).toString()); } else if (EmulatorManager.isWin() && isTapInBridge(tapName)) { - String proxyCommand = "check-net.exe"; - List cmd = Arrays.asList(FilePathResources.getBinPath() + File.separator + proxyCommand, "--bridge"); - ProcessResult res = HelperClass.runProcess(cmd); - boolean isCommandSuccess = false; - if (res.isSuccess()) { - for (String str : res.getStdOutMsg()) { - if (str.startsWith("IP Address:")) { - isCommandSuccess = true; - ipAddr = str.split("IP Address: ")[1].trim(); - EMLogger.getLogger().info("bridge IP address: " + ipAddr); - if (ipAddr.equals("0.0.0.0")) { - return null; - } + HKEY key = getInterfaceTcpipKey(getBridgeId()); + if (key != null) { + try { + String data[] = Advapi32Util.registryGetStringArray(key, + "IPAddress"); + if (data.length > 0) { + ipAddr = data[0]; } - } - } else if (!res.isSuccess() || !isCommandSuccess) { - EMLogger.getLogger().warning(res.getResultMessage()); + } catch (Win32Exception e) { + EMLogger.getLogger().warning(e.getMessage()); + } finally { + Advapi32Util.registryCloseKey(key); + } } if (ipAddr == null) { EMLogger.getLogger().warning("Can't find host bridge IP"); - EMLogger.getLogger().warning("check-net result : " + res.getResultMessage()); } } else if (EmulatorManager.isMac()) { - List cmd = Arrays.asList("/bin/sh", "-c", "ifconfig en0 | grep \"inet \" | awk '{print $2}'"); + List cmd = Arrays.asList("/bin/sh", "-c", + "ifconfig en0 | grep \"inet \" | awk '{print $2}'"); ProcessResult res = HelperClass.runProcess(cmd); boolean isCommandSuccess = false; if (res.isSuccess()) { @@ -835,13 +974,16 @@ public class TapUtil { } if (ipAddr.length() == 0) { isCommandSuccess = false; - cmd = Arrays.asList("/bin/sh", "-c", "ifconfig bridge1 | grep \"inet \" | awk '{print $2}'"); + cmd = Arrays + .asList("/bin/sh", "-c", + "ifconfig bridge1 | grep \"inet \" | awk '{print $2}'"); res = HelperClass.runProcess(cmd); if (res.isSuccess()) { for (String str : res.getStdOutMsg()) { isCommandSuccess = true; ipAddr = str.trim(); - EMLogger.getLogger().info("host IP bridge1: " + ipAddr); + EMLogger.getLogger().info( + "host IP bridge1: " + ipAddr); } } } @@ -892,108 +1034,345 @@ public class TapUtil { return newName; } -} -class TapCreateWorker extends Thread { + public static boolean isWinBridgeExist() { + String proxyCommand = "check-net.exe"; + boolean isExist = false; + List cmd = Arrays.asList(FilePathResources.getBinPath() + + File.separator + proxyCommand, "--bridge"); + ProcessResult res = HelperClass.runProcess(cmd); + boolean isCommandSuccess = false; + if (res.isSuccess()) { + for (String str : res.getStdOutMsg()) { + if (str.startsWith("Adapter Desc:")) { + isExist = true; + isCommandSuccess = true; + break; + } + } + } else if (!res.isSuccess() || !isCommandSuccess) { + EMLogger.getLogger().warning(res.getResultMessage()); + } + return isExist; + } + + public static String getClassIDFromPnpInstanceID(String name) { + HKEY root = WinReg.HKEY_LOCAL_MACHINE; + String topKey = "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}"; + String key = "Connection"; + String value = "PnpInstanceID"; + HKEYByReference regKey = null; + try { + regKey = Advapi32Util.registryGetKey(root, topKey, WinNT.KEY_READ); + String[] subKeys = Advapi32Util.registryGetKeys(regKey.getValue()); + for (String subKey : subKeys) { + String[] subKeys2 = Advapi32Util.registryGetKeys(root, topKey + + "\\" + subKey); + for (String subKey2 : subKeys2) { + if (subKey2.equals(key)) { + if (Advapi32Util.registryValueExists(root, topKey + + "\\" + subKey + "\\" + key, value) == false) { + continue; + } + String pnpInstanceID = Advapi32Util + .registryGetStringValue(root, topKey + "\\" + + subKey + "\\" + key, value); + if (pnpInstanceID.equals(name)) { + return subKey; + } + } + } + } - final MessageDialog dialog; - final String tapName; - final ComboViewItem comboViewItem; // for refresh combo-list + } catch (Win32Exception e) { + EMLogger.getLogger().info(e.getMessage()); + } finally { + if (regKey != null) { + Advapi32Util.registryCloseKey(regKey.getValue()); + } + } - public TapCreateWorker(String tapName, MessageDialog dialog, ComboViewItem comboViewItem) { - this.dialog = dialog; - this.tapName = tapName; - this.comboViewItem = comboViewItem; + return null; } - @Override - public void run() { - // Create tap device - // - Create tap device and rename(user input name) because - // windows OS generate device name automatically. - // - For rename, inquire tap list before and after create and - // compare both to find what is new one. + public static String getBridgeNameFromClassID(String classID) { + HKEY root = WinReg.HKEY_LOCAL_MACHINE; + String topKey = "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\" + + classID + "\\Connection"; + String value = "Name"; + HKEYByReference regKey = null; try { - // 1. Get tap list before create new tap. - List before = TapUtil.getTapList(); - try { // TODO for test - Thread.sleep(2000); - } catch (InterruptedException e) { - e.printStackTrace(); - } + regKey = Advapi32Util.registryGetKey(root, topKey, WinNT.KEY_READ); - // 2. Create tap - List cmd = Arrays.asList("devcon", "install", - "OemWin2k.inf", "Tap0901"); - ProcessResult res = HelperClass.runProcess(cmd); + return Advapi32Util.registryGetStringValue(root, topKey, value); - if (!res.isSuccess()) { - throw new VMWorkerException(res.getResultMessage()); + } catch (Win32Exception e) { + EMLogger.getLogger().info(e.getMessage()); + } finally { + if (regKey != null) { + Advapi32Util.registryCloseKey(regKey.getValue()); } + } - // 3. Get tap list and find new one. - List after = TapUtil.getTapList(); - String newOne = null; - for (String str : after) { - if (!before.contains(str)) { - newOne = str; - break; + return null; + } + + public static String getPnpInstanceIDFromName(String name) { + HKEY root = WinReg.HKEY_LOCAL_MACHINE; + String topKey = "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}"; + String key = "Connection"; + String value = "Name"; + String pnpInstanceID = "PnpInstanceID"; + HKEYByReference regKey = null; + try { + regKey = Advapi32Util.registryGetKey(root, topKey, WinNT.KEY_READ); + String[] subKeys = Advapi32Util.registryGetKeys(regKey.getValue()); + for (String subKey : subKeys) { + String[] subKeys2 = Advapi32Util.registryGetKeys(root, topKey + + "\\" + subKey); + for (String subKey2 : subKeys2) { + if (subKey2.equals(key)) { + String tapName = Advapi32Util.registryGetStringValue( + root, topKey + "\\" + subKey + "\\" + key, + value); + if (tapName.equals(name)) { + return Advapi32Util.registryGetStringValue(root, + topKey + "\\" + subKey + "\\" + key, + pnpInstanceID); + } + } } } - if (newOne == null) { - throw new VMWorkerException("Tap create fail. Cannot find new tap device."); + } catch (Win32Exception e) { + EMLogger.getLogger().info(e.getMessage()); + } finally { + if (regKey != null) { + Advapi32Util.registryCloseKey(regKey.getValue()); } + } - // 4. Rename - cmd = Arrays.asList("netsh", "interface", "set", "interface", "name=" + newOne, "newname=" + tapName); - res = HelperClass.runProcess(cmd); - if (!res.isSuccess()) { - throw new VMWorkerException(res.getResultMessage()); - } + return null; + } - // 5. Check tap create in success. - boolean isTapExist = false; - for (String str : TapUtil.getTapList()) { - if (str.equals(tapName)) { - isTapExist = true; - } - } + static class TapCreateWorker extends Thread { - final MessageDialog resultDialog = new MessageDialog(); - if (isTapExist) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - int res = resultDialog.openSelectionDialog("Tap device created : " + tapName + "\nDo you want to see the guide for bridge network ?"); - if (res == SWT.OK) { - // Show bridge guide dialog - TapGuideDialogForWin.open(); + final MessageDialog dialog; + final String tapName; + final String ifName; + final ComboViewItem comboViewItem; // for refresh combo-list + + public TapCreateWorker(String tapName, String ifName, + MessageDialog dialog, ComboViewItem comboViewItem) { + this.dialog = dialog; + this.tapName = tapName; + this.ifName = ifName; + this.comboViewItem = comboViewItem; + } + + @Override + public void run() { + // Create tap device + // - Create tap device and rename(user input name) because + // windows OS generate device name automatically. + // - For rename, inquire tap list before and after create and + // compare both to find what is new one. + List cmd; + ProcessResult res; + try { + if (!EmulatorManager.isWin8()) { + EMLogger.getLogger().info( + "get CompatibleIDs from pci network device"); + cmd = Arrays.asList(devconPath, "find", "=net", + "@pci*"); + res = HelperClass.runProcess(cmd); + boolean isCommandSuccess = false; + String CompatibleIDs = null; + if (res.isSuccess()) { + for (String str : res.getStdOutMsg()) { + if (str.endsWith(ifName)) { + isCommandSuccess = true; + CompatibleIDs = str.split(":")[0].trim(); + EMLogger.getLogger().info( + "CompatibleIDs: " + CompatibleIDs); + break; + } } + } else if (!res.isSuccess() || !isCommandSuccess) { + EMLogger.getLogger().warning(res.getResultMessage()); } - }); - } else { - throw new VMWorkerException("Tap is not exist : " + tapName); - } + if (isWinBridgeExist() == false) { + // Create Bridge device and set IP + EMLogger.getLogger().info("create bridge"); + cmd = Arrays + .asList(devconPath, + "install", + "c:\\windows\\inf\\netbrdgm.inf", + "ms_bridgemp"); + res = HelperClass.runProcess(cmd); + if (!res.isSuccess()) { + throw new VMWorkerException(res.getResultMessage()); + } - } catch (VMWorkerException e) { - EMLogger.getLogger().warning("Failed to create tap device."); - EMLogger.getLogger().warning(e.getMessage()); - final String msg = e.getMessage(); - Display.getDefault().asyncExec(new Runnable() { - public void run() { - new MessageDialog().openWarningDialog("\nFailed to create tap device.\n\n" + msg); + EMLogger.getLogger().info("bind interface to bridge"); + cmd = Arrays.asList(FilePathResources.getBinPath() + + File.separator + "bindbridge.exe", + "ms_bridge", CompatibleIDs, "bind"); + res = HelperClass.runProcess(cmd); + if (!res.isSuccess()) { + throw new VMWorkerException("Fail to Create Bridge" + + res.getResultMessage()); + } + EMLogger.getLogger().info("set bridge's IP"); + setWinbridgeNetwork(getClassIDFromPnpInstanceID(CompatibleIDs)); + } } - }); - } finally { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - dialog.close(); - comboViewItem.resetCombo(); + // Get tap list before create new tap. + EMLogger.getLogger() + .info("Get tap list before create new tap."); + List before = TapUtil.getTapList(); + + // Create new tap + EMLogger.getLogger().info("Create new tap."); + cmd = Arrays.asList(devconPath, "install", + FilePathResources.getBinPath() + File.separator + + "OemWin2k.inf", "Tap0901"); + res = HelperClass.runProcess(cmd); + + if (!res.isSuccess()) { + throw new VMWorkerException(res.getResultMessage()); } - }); - } + // Get tap list and find new one. + EMLogger.getLogger().info("Get tap list and find new one."); + List after = TapUtil.getTapList(); + String newOne = null; + for (String str : after) { + if (!before.contains(str)) { + newOne = str; + break; + } + } + + if (newOne == null) { + throw new VMWorkerException( + "Tap create fail. Cannot find new tap device."); + } + + // Rename new tap to tapX + EMLogger.getLogger().info("Rename new tap to tapX."); + cmd = Arrays.asList("netsh", "interface", "set", "interface", + "name=" + newOne, "newname=" + tapName); + res = HelperClass.runProcess(cmd); + if (!res.isSuccess()) { + throw new VMWorkerException(res.getResultMessage()); + } + + // Check tap create in success. + EMLogger.getLogger().info("Check tap create in success."); + boolean isTapExist = false; + for (String str : TapUtil.getTapList()) { + if (str.equals(tapName)) { + isTapExist = true; + } + } + + if (!EmulatorManager.isWin8()) { + EMLogger.getLogger().info("bind host network to bridge"); + String tapPnpInstanceID = getPnpInstanceIDFromName(tapName); + + cmd = Arrays.asList(FilePathResources.getBinPath() + + File.separator + "bindbridge.exe", "ms_bridge", + tapPnpInstanceID, "bind"); + res = HelperClass.runProcess(cmd); + if (!res.isSuccess()) { + throw new VMWorkerException(res.getResultMessage()); + } + + EMLogger.getLogger().info( + "wait while finishing bridged network setting"); + String proxyCommand = "check-net.exe"; + cmd = Arrays.asList(FilePathResources.getBinPath() + + File.separator + proxyCommand, "--bridge"); + 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:")) { + isCommandSuccess = true; + ipAddr = str.split("IP Address: ")[1] + .trim(); + EMLogger.getLogger().info( + "bridge IP address: " + ipAddr); + break; + } + } + } else if (!res.isSuccess() || !isCommandSuccess) { + EMLogger.getLogger() + .warning(res.getResultMessage()); + } + if (ipAddr != null) { + break; + } + res = HelperClass.runProcess(cmd); + } + + // shows success message + final MessageDialog messageDialog = new MessageDialog(); + if (isTapExist) { + Display.getDefault().asyncExec(new Runnable() { + public void run() { + messageDialog + .openInfoDialog("Tap device created : " + + tapName); + } + }); + } + } else { + final MessageDialog resultDialog = new MessageDialog(); + if (isTapExist) { + Display.getDefault().asyncExec(new Runnable() { + public void run() { + int res = resultDialog + .openSelectionDialog("Tap device created : " + + tapName + + "\nDo you want to see the guide for bridge network ?"); + if (res == SWT.OK) { + // Show bridge guide dialog + TapGuideDialogForWin.open(); + } + } + }); + + } else { + throw new VMWorkerException("Tap is not exist : " + + tapName); + } + } + } catch (VMWorkerException e) { + EMLogger.getLogger().warning("Failed to create tap device."); + EMLogger.getLogger().warning(e.getMessage()); + final String msg = e.getMessage(); + Display.getDefault().asyncExec(new Runnable() { + public void run() { + new MessageDialog() + .openWarningDialog("\nFailed to create tap device.\n\n" + + msg); + } + }); + + } finally { + Display.getDefault().asyncExec(new Runnable() { + public void run() { + dialog.close(); + comboViewItem.resetCombo(); + } + }); + } + } } } diff --git a/common-project/src/org/tizen/emulator/manager/ui/detail/item/property/NetConnectTypeViewItem.java b/common-project/src/org/tizen/emulator/manager/ui/detail/item/property/NetConnectTypeViewItem.java index 61c21f1..3422714 100644 --- a/common-project/src/org/tizen/emulator/manager/ui/detail/item/property/NetConnectTypeViewItem.java +++ b/common-project/src/org/tizen/emulator/manager/ui/detail/item/property/NetConnectTypeViewItem.java @@ -31,7 +31,6 @@ package org.tizen.emulator.manager.ui.detail.item.property; import org.eclipse.swt.events.SelectionEvent; - import org.eclipse.swt.events.SelectionListener; import org.tizen.emulator.manager.ui.detail.item.AdvancedViewItem; import org.tizen.emulator.manager.ui.detail.item.CommonItemListFactory; @@ -60,6 +59,10 @@ public class NetConnectTypeViewItem extends ComboViewItem { item = lineLabelViewItem .getItem(CommonItemListFactory.ITEM_NET_TAP_DEVICE); + if (item != null && item instanceof NetTapDeviceViewItemWin) { + ((NetTapDeviceViewItemWin) item).resetCombo(newValue); + } + if (item != null && item instanceof NetTapDeviceViewItem) { ((NetTapDeviceViewItem) item).resetCombo(newValue); } diff --git a/common-project/src/org/tizen/emulator/manager/ui/detail/item/property/NetIPInfoTextSubViewItem.java b/common-project/src/org/tizen/emulator/manager/ui/detail/item/property/NetIPInfoTextSubViewItem.java index 82fc430..5ee4394 100644 --- a/common-project/src/org/tizen/emulator/manager/ui/detail/item/property/NetIPInfoTextSubViewItem.java +++ b/common-project/src/org/tizen/emulator/manager/ui/detail/item/property/NetIPInfoTextSubViewItem.java @@ -38,6 +38,7 @@ import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.widgets.Composite; +import org.tizen.emulator.manager.EmulatorManager; import org.tizen.emulator.manager.tool.TapUtil; import org.tizen.emulator.manager.ui.detail.item.AdvancedViewItem; import org.tizen.emulator.manager.ui.detail.item.CommonItemListFactory; @@ -78,7 +79,7 @@ public class NetIPInfoTextSubViewItem extends TextSubViewItem { private boolean useDHCP() { if (parentItem instanceof NetIPInfoViewItem) { - NetIPInfoViewItem netItem = (NetIPInfoViewItem)parentItem; + NetIPInfoViewItem netItem = (NetIPInfoViewItem) parentItem; if (netItem.useDHCP()) { return true; } @@ -120,8 +121,14 @@ public class NetIPInfoTextSubViewItem extends TextSubViewItem { String tapName = null; AdvancedViewItem item = parentItem.getLineLabelViewItem() .getItem(CommonItemListFactory.ITEM_NET_TAP_DEVICE); - if (item instanceof NetTapDeviceViewItem) - tapName = ((NetTapDeviceViewItem) item).getValue(); + if (!EmulatorManager.isWin()) { + if (item instanceof NetTapDeviceViewItem) + tapName = ((NetTapDeviceViewItem) item).getValue(); + } else { + if (item instanceof NetTapDeviceViewItemWin) + tapName = ((NetTapDeviceViewItemWin) item) + .getValue(); + } // Set subnet, gateway if empty. if (tapName != null || tapName.isEmpty()) { @@ -152,12 +159,13 @@ public class NetIPInfoTextSubViewItem extends TextSubViewItem { item = parentItem.getLineLabelViewItem().getItem( CommonItemListFactory.ITEM_NET_DNS); if (item instanceof NetDnsViewItem) { - NetDnsViewItem netDnsItem = (NetDnsViewItem)item; + NetDnsViewItem netDnsItem = (NetDnsViewItem) item; String dns = TapUtil.getDnsFromTap(tapName); if (dns == null || dns.isEmpty()) { netDnsItem.setDns(""); - } else if (netDnsItem.getDns() == null || netDnsItem.getDns().isEmpty()) { + } else if (netDnsItem.getDns() == null + || netDnsItem.getDns().isEmpty()) { netDnsItem.setDns(dns); } } @@ -209,7 +217,7 @@ public class NetIPInfoTextSubViewItem extends TextSubViewItem { } public ItemState checkValue() { - String msg = TapUtil.checkIPString(text.isEnabled(), newValue, title); + String msg = TapUtil.checkIPString(text.isEnabled(), newValue, title); if (msg.isEmpty()) { itemState.setNormal(); } else { diff --git a/common-project/src/org/tizen/emulator/manager/ui/detail/item/property/NetTapDeviceViewItem.java b/common-project/src/org/tizen/emulator/manager/ui/detail/item/property/NetTapDeviceViewItem.java index e1ae7ba..08adadc 100644 --- a/common-project/src/org/tizen/emulator/manager/ui/detail/item/property/NetTapDeviceViewItem.java +++ b/common-project/src/org/tizen/emulator/manager/ui/detail/item/property/NetTapDeviceViewItem.java @@ -38,9 +38,8 @@ import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.FormAttachment; import org.eclipse.swt.layout.FormData; import org.eclipse.swt.layout.FormLayout; -import org.eclipse.swt.widgets.Button; import org.tizen.emulator.manager.EmulatorManager; -import org.tizen.emulator.manager.resources.FontResources; +import org.tizen.emulator.manager.logging.EMLogger; import org.tizen.emulator.manager.resources.ImageResources; import org.tizen.emulator.manager.resources.PatchImageResources; import org.tizen.emulator.manager.tool.TapUtil; @@ -56,13 +55,11 @@ import org.tizen.emulator.manager.ui.dialog.TapDeviceDialogForWin; import org.tizen.emulator.manager.ui.widgets.ImageCombo; import org.tizen.emulator.manager.ui.widgets.WSTATE; import org.tizen.emulator.manager.vms.VMPropertyValue; -import org.tizen.emulator.manager.vms.helper.HelperClass; import org.tizen.emulator.manager.vms.xml.template.Item; import org.tizen.emulator.manager.vms.xml.template.Option; public class NetTapDeviceViewItem extends ComboViewItem { - Button createButton; protected static int BUTTON_WIDTH = 48; protected static int BUTTON_HEIGHT = 20; protected static int COMBOBOX_WIDTH_MODIFY = 123; @@ -85,12 +82,12 @@ public class NetTapDeviceViewItem extends ComboViewItem { public void drawModify() { if (INPUTBOX_ON_IMAGE == null) { INPUTBOX_ON_IMAGE = PatchImageResources - .getInputBoxON(COMBOBOX_WIDTH_MODIFY); + .getInputBoxON(COMBOBOX_WIDTH); } if (INPUTBOX_OFF_IMAGE == null) { INPUTBOX_OFF_IMAGE = PatchImageResources - .getInputBoxOff(COMBOBOX_WIDTH_MODIFY); + .getInputBoxOff(COMBOBOX_WIDTH); } combo = new ImageCombo(compList.get(0), SWT.NONE); @@ -104,11 +101,6 @@ public class NetTapDeviceViewItem extends ComboViewItem { combo.setItemHeight(INPUTBOX_ON_IMAGE.getImageData().height); combo.setLayout(new FormLayout()); - createButton = new Button(compList.get(0), SWT.NORMAL); - createButton.setText("..."); - createButton.setFont(FontResources.COMBO_BUTTON_FONT.getFont()); - createButton.setToolTipText("setting"); - FormData data = new FormData(); data.left = new FormAttachment(0, INPUTBOX_OFFSET); data.top = new FormAttachment(0, INPUTBOX_TOP_GAP); @@ -116,13 +108,6 @@ public class NetTapDeviceViewItem extends ComboViewItem { data.height = INPUTBOX_ON_IMAGE.getImageData().height; combo.setLayoutData(data); - data = new FormData(); - data.left = new FormAttachment(combo, 5); - data.top = new FormAttachment(0, 3); - data.width = BUTTON_WIDTH; - data.height = BUTTON_HEIGHT; - createButton.setLayoutData(data); - // make combobox list addWidgetListener(); @@ -130,52 +115,9 @@ public class NetTapDeviceViewItem extends ComboViewItem { } @Override - protected void addWidgetListener() { - combo.addSelectionListener(new SelectionListener() { - @Override - public void widgetSelected(SelectionEvent e) { - newValue = combo.getText(); - - // Set netmask, gateway - resetAddress(); - - if (!isCreateMode()) { - // getListener().ChangeValue(getThis()); - getListener().changeModifyConfirmButton(getThis()); - } - } - - @Override - public void widgetDefaultSelected(SelectionEvent e) { - } - }); - - createButton.addSelectionListener(new SelectionListener() { - - @Override - public void widgetSelected(SelectionEvent arg0) { - if (EmulatorManager.isLinux()) { - TapDeviceDialogForLinux.open(); - } else if (EmulatorManager.isWin()) { - TapDeviceDialogForWin.open(thisItem); - } else if (EmulatorManager.isMac()) { - TapDeviceDialogForMac.open(); - } - resetCombo(NetConnectTypeViewItem.VALUE_BRIDGE); - } - - @Override - public void widgetDefaultSelected(SelectionEvent arg0) { - } - - }); - } - - @Override public boolean settingModifyItem(VMPropertyValue value) { oldValue = newValue = value.getAdvancedOptionValue(name); // text.setText(newValue); - AdvancedViewItem item = lineLabelViewItem .getItem(CommonItemListFactory.ITEM_NET_CONNECT_TYPE); if (item != null && item instanceof NetConnectTypeViewItem) { @@ -184,7 +126,7 @@ public class NetTapDeviceViewItem extends ComboViewItem { if (connectType.equals("Bridge") && !oldValue.equals(newValue)) { resetAddress(); (new MessageDialog()).openWarningDialog((new StringBuilder()) - .append("Tap device (").append(oldValue) + .append("Base Network (").append(oldValue) .append(") is removed or unavailable.") .append("\nCheck tap configuration.").toString()); } @@ -196,6 +138,28 @@ public class NetTapDeviceViewItem extends ComboViewItem { } @Override + protected void addWidgetListener() { + combo.addSelectionListener(new SelectionListener() { + @Override + public void widgetSelected(SelectionEvent e) { + newValue = combo.getText(); + + // Set netmask, gateway + resetAddress(); + + if (!isCreateMode()) { + // getListener().ChangeValue(getThis()); + getListener().changeModifyConfirmButton(getThis()); + } + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + }); + } + + @Override public void resetCombo() { String connectType = isBridge ? NetConnectTypeViewItem.VALUE_BRIDGE : NetConnectTypeViewItem.VALUE_NAT; @@ -212,12 +176,19 @@ public class NetTapDeviceViewItem extends ComboViewItem { // Enable if "Bridge" if (connectType.equals(NetConnectTypeViewItem.VALUE_BRIDGE)) { isBridge = true; - comboOptions = TapUtil.getTapList(); + if (EmulatorManager.isLinux()) { + comboOptions = TapDeviceDialogForLinux.getInterfaceList(); + } else if (EmulatorManager.isMac()) { + comboOptions = TapDeviceDialogForMac.getInterfaceList(); + } else if (EmulatorManager.isWin()) { + comboOptions = TapDeviceDialogForWin.getInterfaceList(); + } newValue = oldValue; // restore // make combo box list if (comboOptions != null) { for (String option : comboOptions) { + EMLogger.getLogger().info("add option: " + option); combo.add(option); } } @@ -242,7 +213,6 @@ public class NetTapDeviceViewItem extends ComboViewItem { } newValue = combo.getText(); combo.setEnabled(true); - createButton.setEnabled(true); // Disable if "NAT" } else { @@ -251,7 +221,6 @@ public class NetTapDeviceViewItem extends ComboViewItem { newValue = ""; combo.setText(newValue); combo.setEnabled(false); - createButton.setEnabled(false); } if (EmulatorManager.isMac()) { diff --git a/common-project/src/org/tizen/emulator/manager/ui/detail/item/property/NetTapDeviceViewItemWin.java b/common-project/src/org/tizen/emulator/manager/ui/detail/item/property/NetTapDeviceViewItemWin.java new file mode 100644 index 0000000..e01365b --- /dev/null +++ b/common-project/src/org/tizen/emulator/manager/ui/detail/item/property/NetTapDeviceViewItemWin.java @@ -0,0 +1,290 @@ +/* + * Emulator Manager + * + * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Munkyu Im + * Minkee Lee + * JiHye Kim + * SeokYeon Hwang + * YeongKyoon Lee + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +package org.tizen.emulator.manager.ui.detail.item.property; + +import java.util.List; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.tizen.emulator.manager.EmulatorManager; +import org.tizen.emulator.manager.resources.FontResources; +import org.tizen.emulator.manager.resources.ImageResources; +import org.tizen.emulator.manager.resources.PatchImageResources; +import org.tizen.emulator.manager.tool.TapUtil; +import org.tizen.emulator.manager.ui.detail.item.AdvancedViewItem; +import org.tizen.emulator.manager.ui.detail.item.CommonItemListFactory; +import org.tizen.emulator.manager.ui.detail.item.ItemState; +import org.tizen.emulator.manager.ui.detail.item.LineLabelViewItem; +import org.tizen.emulator.manager.ui.detail.item.template.ComboViewItem; +import org.tizen.emulator.manager.ui.dialog.MessageDialog; +import org.tizen.emulator.manager.ui.dialog.TapDeviceDialogForWin; +import org.tizen.emulator.manager.ui.widgets.ImageCombo; +import org.tizen.emulator.manager.ui.widgets.WSTATE; +import org.tizen.emulator.manager.vms.VMPropertyValue; +import org.tizen.emulator.manager.vms.xml.template.Item; +import org.tizen.emulator.manager.vms.xml.template.Option; + +public class NetTapDeviceViewItemWin extends ComboViewItem { + + Button createButton; + protected static int BUTTON_WIDTH = 48; + protected static int BUTTON_HEIGHT = 20; + protected static int COMBOBOX_WIDTH_MODIFY = 123; + + boolean isBridge = false; + NetTapDeviceViewItemWin thisItem; + + public NetTapDeviceViewItemWin(Item template, + LineLabelViewItem lineLabelViewItem) { + super(template, lineLabelViewItem); + lineLabelViewItem.addItem(name, this); + } + + @Override + protected void parseOption(List