-plugin-project/wearable-plugin/bin
-plugin-project/mobile-plugin/em-plugin.jar
about.properties
common-project/bin
-plugin-project/mobile-plugin/bin
+plugin-project/
common-project/lib
-plugin-project/mobile-plugin/lib
common-project/build
-plugin-project/mobile-plugin/build
emulator-manager.jar
emulator-manager.exe
common-project/emulator-manager.jar
common-project/emulator-manager.exe
common-project/about.properties
common-project/em-plugins
-plugin-project/mobile-plugin/mobile-plugin.jar
swt.jar
jsch-0.1.50.jar
common-project/swt.jar
package org.tizen.emulator.manager.tool;
+import java.io.File;
import java.io.IOException;
import java.net.Inet4Address;
import java.net.InterfaceAddress;
import org.eclipse.swt.widgets.Display;
import org.tizen.emulator.manager.EmulatorManager;
import org.tizen.emulator.manager.logging.EMLogger;
+import org.tizen.emulator.manager.resources.FilePathResources;
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.TapGuideDialogForWin;
.append(e.getMessage()).toString());
}
else if (EmulatorManager.isWin() && isTapInBridge(tapName)) {
- HKEY key = getBridgeTcpipKey();
- if (key != null) {
- try {
- String data[] = Advapi32Util.registryGetStringArray(key, "IPAddress");
- if (data.length > 0) {
- ipAddr = data[0];
+ String proxyCommand = "check-net.exe";
+ List<String> 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;
+ }
}
-
- } catch (Win32Exception e) {
- EMLogger.getLogger().warning(e.getMessage());
- } finally {
- Advapi32Util.registryCloseKey(key);
}
+
+ } else if (!res.isSuccess() || !isCommandSuccess) {
+ EMLogger.getLogger().warning(res.getResultMessage());
}
if (ipAddr == null) {
- key = getInterfaceTcpipKey(getBridgeId());
- if (key != null) {
- try {
- String data[] = Advapi32Util.registryGetStringArray(key, "IPAddress");
- if (data.length > 0) {
- ipAddr = data[0];
- }
- } catch (Win32Exception e) {
- EMLogger.getLogger().warning(e.getMessage());
- } finally {
- Advapi32Util.registryCloseKey(key);
- }
- }
+ EMLogger.getLogger().warning("Can't find host bridge IP");
+ EMLogger.getLogger().warning(
+ "check-net result : " + res.getResultMessage());
}
}
return ipAddr;
--- /dev/null
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * MunKyu Im <munkyu.im@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * 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.mobile.vms;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.tizen.emulator.manager.EmulatorManager;
+import org.tizen.emulator.manager.EmulatorManager.ManagerModeType;
+import org.tizen.emulator.manager.console.RemoteManager;
+import org.tizen.emulator.manager.logging.EMLogger;
+import org.tizen.emulator.manager.mobile.ui.detail.ItemListFactory;
+import org.tizen.emulator.manager.resources.FilePathResources;
+import org.tizen.emulator.manager.resources.StringResources;
+import org.tizen.emulator.manager.tool.CheckVirtualization;
+import org.tizen.emulator.manager.tool.PortHelper;
+import org.tizen.emulator.manager.tool.SettingInfoFile;
+import org.tizen.emulator.manager.tool.TapUtil;
+import org.tizen.emulator.manager.ui.detail.item.CommonItemListFactory;
+import org.tizen.emulator.manager.ui.detail.item.property.NetIPInfoViewItem;
+import org.tizen.emulator.manager.ui.detail.item.property.NetProxyViewItem;
+import org.tizen.emulator.manager.ui.dialog.IPAddressInputDialog;
+import org.tizen.emulator.manager.ui.dialog.MessageDialog;
+import org.tizen.emulator.manager.vms.EmulatorVMList;
+import org.tizen.emulator.manager.vms.ILauncher;
+import org.tizen.emulator.manager.vms.VMProperty;
+import org.tizen.emulator.manager.vms.helper.CheckingRunningEmulator;
+import org.tizen.emulator.manager.vms.helper.HelperClass;
+import org.tizen.emulator.manager.vms.helper.MonitoringEmulator;
+import org.tizen.emulator.manager.vms.helper.ProcessResult;
+import org.tizen.emulator.manager.vms.helper.VMLauncherException;
+import org.tizen.emulator.manager.vms.xml.CpuType;
+import org.tizen.emulator.manager.vms.helper.VMWorkerException;
+import org.tizen.emulator.manager.vms.xml.OptionType;
+import org.tizen.emulator.manager.vms.xml.TouchType;
+
+public class Launcher implements ILauncher {
+ private boolean isConsole = false;
+ private String binPath = null;
+ private static Launcher launcher;
+
+
+ // Option names in vm_config.xml
+ // Add if need.
+ public static final String OPT_DEVICE = "device";
+ public static final String OPT_NFC = "nfc";
+ public static final String OPT_BATTERY = "battery";
+ public static final String OPT_CAMERA = "camera";
+ public static final String OPT_HWKEY = "hwkey";
+ public static final String OPT_SWAP = "swap";
+ public static final String OPT_CODEC = "codec";
+
+ public static final String OPT_JACK = "jack";
+ public static final String OPT_EARJACK = "earjack";
+ public static final String OPT_USB = "usb";
+ public static final String OPT_CHARGER = "charger";
+
+ public static final String OPT_SENSOR = "sensor";
+ public static final String OPT_ACCEL = "accel";
+ public static final String OPT_GYRO = "gyro";
+ public static final String OPT_GEO = "geo";
+ public static final String OPT_LIGHT = "light";
+ public static final String OPT_PROXI = "proxi";
+ public static final String OPT_HAPTIC = "haptic";
+ public static final String OPT_PRESS = "press"; // pressure
+ public static final String OPT_UV = "uv"; // ultra violet
+ public static final String OPT_HRM = "hrm"; // heartbeat rate meter
+
+ public static final String OPT_EXPERIMENTAL = ItemListFactory.ITEM_EXPERIMENTAL;
+ public static final String OPT_QT_ENABLE = "qtEnable";
+
+
+ // Network option.
+ public static final String OPT_NET_CONNECT_TYPE = CommonItemListFactory.ITEM_NET_CONNECT_TYPE;
+ public static final String OPT_NET_TAP_DEVICE = CommonItemListFactory.ITEM_NET_TAP_DEVICE;
+ public static final String OPT_NET_IP_INFO = CommonItemListFactory.ITEM_NET_IP_INFO;
+ public static final String OPT_NET_IPADDR = NetIPInfoViewItem.ITEM_IP;
+ public static final String OPT_NET_SUBNET = NetIPInfoViewItem.ITEM_SUBNET;
+ public static final String OPT_NET_GATEWAY = NetIPInfoViewItem.ITEM_GATEWAY;
+ public static final String OPT_NET_DNS = CommonItemListFactory.ITEM_NET_DNS;
+ public static final String OPT_NET_MAC = CommonItemListFactory.ITEM_NET_MAC;
+ public static final String OPT_NET_PROXY = CommonItemListFactory.ITEM_NET_PROXY;
+ public static final String OPT_NET_DHCP = NetIPInfoViewItem.ITEM_USE_DHCP;
+
+
+ public static Launcher getInstance() {
+ if (launcher == null) {
+ launcher = new Launcher();
+ }
+ return launcher;
+ }
+
+ private Launcher() {
+ isConsole = EmulatorManager.isConsoleMode();
+ }
+
+
+ @Override
+ public List<String> getLaunchCommand(VMProperty property, String path) throws VMLauncherException {
+ String binary;
+ String hwVirtualization = "";
+ int portNo;
+ boolean useBridgeNet = property.getPropertyValue()
+ .getAdvancedOptionValue(OPT_NET_CONNECT_TYPE).equals("Bridge") &&
+ (EmulatorManager.isLinux() || EmulatorManager.isWin());
+
+ if (useBridgeNet) {
+ String tapName = property.getPropertyValue()
+ .getAdvancedOptionValue(OPT_NET_TAP_DEVICE);
+ if (TapUtil.nameNotExist(tapName))
+ throw new VMLauncherException((new StringBuilder())
+ .append("Tap device is not exist : ").append(tapName)
+ .append("\nCheck VM's tap configuration.").toString());
+ if (isTapUsing(tapName))
+ throw new VMLauncherException(
+ (new StringBuilder())
+ .append("Tap device(")
+ .append(tapName)
+ .append(") is being used by other VM.")
+ .append("\nPlease select another tap device for current VM.")
+ .toString());
+ String ipAddr = property.getPropertyValue()
+ .getAdvancedOptionSubValue(OPT_NET_IP_INFO, "ipAddr");
+ if (isIpAddrUsing(ipAddr))
+ throw new VMLauncherException((new StringBuilder())
+ .append("VM's ip address(").append(ipAddr)
+ .append(") is being used by other VM.")
+ .append("\nPlease modify current VM's ip address.")
+ .toString());
+ try {
+ if (!TapUtil.isTapInBridge(tapName)) {
+ MessageDialog dialog = new MessageDialog();
+ int res = dialog
+ .openWarningAndSelectionDialog("\nTap device is not connected with Bridge." +
+ "\nGuest network would work as NAT." +
+ "\nKeep launching ?");
+ if (res != SWT.OK) {
+ throw new VMLauncherException("User canceled.");
+ }
+ useBridgeNet = false;
+ }
+
+ } catch (VMWorkerException e) {
+ throw new VMLauncherException(e.getMessage());
+ }
+ }
+
+ /* check available port number */
+ portNo = new PortHelper().getPortNo();
+ if(portNo == -1) {
+ String error = "Can not execute emulator."
+ + StringResources.NEW_LINE
+ + "All available ports are in use.";
+ throw new VMLauncherException(error);
+ }
+
+ if (property.getArch().toString().equals("x86")) {
+ if (EmulatorManager.isWin()) {
+ binary = "emulator-x86.exe";
+ } else {
+ binary = "emulator-x86";
+ }
+ } else {
+ if (EmulatorManager.isWin()) {
+ binary = "emulator-arm.exe";
+ } else {
+ binary = "emulator-arm";
+ }
+ }
+
+ // check disk image
+ File child = new File(property.getConfiguration().getBaseInformation().getDiskImage().getCurrentDiskImage().getValue());
+ File base = new File(property.getConfiguration().getBaseInformation().getDiskImage().getBaseDiskImage().getValue());
+ if (!child.exists()) {
+ throw new VMLauncherException("Child disk image does not exist."
+ + StringResources.NEW_LINE + child.getAbsolutePath()
+ , true);
+ }
+ if (!base.exists()) {
+ throw new VMLauncherException("Base disk image does not exist."
+ + StringResources.NEW_LINE + base.getAbsolutePath()
+ , true);
+ }
+
+ if (property.getConfiguration().getUsability().isHwVirtualization() && CheckVirtualization.getInstance().isSupportVirtualization()) {
+ hwVirtualization = CheckVirtualization.getInstance().getVirtualizationEnableCommnad();
+ } else {
+ hwVirtualization = CheckVirtualization.getInstance().getVirtualizationDisableCommnad();
+ }
+
+ List<String> cmd = new ArrayList<String>();
+ int width = property.getConfiguration().getDevice().getDisplay().getResolution().getWidth();
+ int height = property.getConfiguration().getDevice().getDisplay().getResolution().getHeight();
+ String skinPath = null;
+ if (property.getConfiguration().getDevice().getDisplay().getSkinPath() != null) {
+ skinPath = property.getConfiguration().getDevice().getDisplay().getSkinPath().getPath();
+ if (skinPath != null && skinPath.isEmpty()) {
+ skinPath = null;
+ }
+ }
+ String fileshare = property.getConfiguration().getUsability().getFileSharing().getPath();
+ String osVersion = System.getProperty("os.version");
+ boolean isFileshare = true;
+ if (fileshare == null) {
+ isFileshare = false;
+ }
+
+ /* get MAC address of host set as guest MAC address */
+ String macAddr = useBridgeNet ? property.getPropertyValue()
+ .getAdvancedOptionValue(OPT_NET_MAC) : SettingInfoFile
+ .getMACaddr();
+
+ if(macAddr.isEmpty()) {
+ macAddr = "52:54:00:12:34:56";
+ EMLogger.getLogger().log(Level.INFO, String.format("MAC set as default = %s", macAddr));
+ }
+
+ if (path == null || path.isEmpty()) {
+ cmd.add(FilePathResources.getBinPath() + File.separator + binary);
+ } else {
+ this.binPath = path;
+ cmd.add(binPath + File.separator + binary);
+ }
+
+ cmd.add("--skin-args");
+ cmd.add("width=" + width);
+ cmd.add("height=" + height);
+ if (skinPath != null) {
+ cmd.add("skin.path=" + skinPath);
+ }
+
+ if (RemoteManager.getSpiceMode()) {
+ cmd.add("hb.ignore=true");
+ }
+
+ cmd.add("--qemu-args");
+
+ // x86 part of cmd
+ if (property.getArch().toString().equals("x86")) {
+ cmd.add("-drive");
+ cmd.add("file=" + property.getConfiguration().getBaseInformation().getDiskImage().getCurrentDiskImage().getValue()+ ",if=virtio,index=1");
+ cmd.add( "-boot");
+ cmd.add("c");
+ cmd.add("-append");
+ String kernelOption = "console=ttyS0 video=LVDS-1:"
+ + width
+ + "x"
+ + height
+ + "-32@60"
+ + " dpi=" + property.getConfiguration().getDevice().getDisplay().getDensity().getValue() * 10
+ + getIP(useBridgeNet, property)
+ + " vm_name=" + property.getConfiguration().getBaseInformation().getName();
+ String hostIp = "10.0.2.2";
+ if (useBridgeNet) {
+ String bridgeIp = TapUtil.getBridgeIpAddr(property
+ .getPropertyValue().getAdvancedOptionValue(
+ OPT_NET_TAP_DEVICE));
+ if (bridgeIp == null) {
+ MessageDialog dialog = new MessageDialog();
+ int res = dialog.openInfoDialog(
+ "\nCannot find host(bridge) IP address."
+ + "\nTo use bridge network, host IP is required."
+ + "\nPlease input manually.");
+ if (res != SWT.OK) {
+ throw new VMLauncherException("User canceled.");
+ }
+
+ // Input host IP address.
+ String ip = IPAddressInputDialog.open("Input host's IP address");
+ if (ip == null) {
+ throw new VMLauncherException("User canceled.");
+
+ } else {
+ hostIp = ip;
+ }
+
+ } else {
+ hostIp = bridgeIp;
+ }
+ }
+ kernelOption += " host_ip=" + hostIp;
+
+ // Set proxy.
+ if (EmulatorManager.isLinux() || EmulatorManager.isWin()) {
+ String proxyConfig = null;
+ String proxyMode = property.getPropertyValue().
+ getAdvancedOptionSubValue(OPT_NET_PROXY, NetProxyViewItem.ITEM_PROXY_MODE);
+ if (proxyMode.equals(NetProxyViewItem.MODE_AUTO)) {
+ proxyConfig = getHostProxy();
+
+ } else if (proxyMode.equals(NetProxyViewItem.MODE_MANUAL)) {
+ proxyConfig = "http_proxy=" + property.getPropertyValue().
+ getAdvancedOptionSubValue(OPT_NET_PROXY, NetProxyViewItem.ITEM_HTTP_PROXY)
+ + " https_proxy=" + property.getPropertyValue().
+ getAdvancedOptionSubValue(OPT_NET_PROXY, NetProxyViewItem.ITEM_HTTPS_PROXY)
+ + " ftp_proxy=" + property.getPropertyValue().
+ getAdvancedOptionSubValue(OPT_NET_PROXY, NetProxyViewItem.ITEM_FTP_PROXY)
+ + " socks_proxy=" + property.getPropertyValue().
+ getAdvancedOptionSubValue(OPT_NET_PROXY, NetProxyViewItem.ITEM_SOCKS_PROXY);
+ }
+
+ if (proxyConfig != null) {
+ kernelOption += (" " + proxyConfig);
+ }
+ }
+
+ /* set virtio-9p string in case of using directory share [kernel option] */
+ if(isFileshare) {
+ kernelOption += " virtio-9p";
+ }
+
+ /*
+ if(property.getPropertyValue().skin != null && property.getPropertyValue().skin.getButtonType() == SKIN_BUTTON_TYPE.THREE_BUTTON_TYPE) {
+ kernelOption += " platform_feature=3btn";
+ } else {
+ kernelOption += " platform_feature=1btn";
+ }
+ */
+
+ cmd.add(kernelOption);
+
+ /* use fileshare [non-kernel option] */
+ if(isFileshare) {
+ cmd.add("-virtfs");
+ cmd.add("local,path=" + property.getConfiguration().getUsability().getFileSharing().getPath() +",security_model=none,mount_tag=fileshare");
+ }
+
+ cmd.add("-serial");
+ cmd.add("file:" + FilePathResources.getTizenVmsPath() + File.separator + property.getName() + File.separator + "logs" + File.separator + "emulator.klog");
+ CpuType cpuOption = property.getConfiguration().getDevice().getCPU();
+ if (cpuOption != null) {
+ cmd.add("-smp");
+ cmd.add(String.valueOf(cpuOption.getValue().getValue()));
+ }
+ cmd.add("-m");
+ cmd.add(String.valueOf(property.getConfiguration().getDevice().getRAM().getSize().getValue()));
+ cmd.add("-M");
+ cmd.add("maru-x86-machine");
+ cmd.add("-net");
+ cmd.add("nic,model=virtio,macaddr=" + macAddr);
+ cmd.add("-soundhw");
+ cmd.add("all");
+ cmd.add("-usb");
+ cmd.add("-vga");
+ cmd.add("none");
+ cmd.add("-enable-vigs");
+ cmd.add("-L");
+ cmd.add(FilePathResources.getBiosPath());
+ cmd.add("-kernel");
+ cmd.add(FilePathResources.getKernelPath() + File.separator+ "bzImage." + property.getArch().toString());
+ cmd.add("-net");
+ if (useBridgeNet) {
+ String tapName = property.getPropertyValue()
+ .getAdvancedOptionValue(OPT_NET_TAP_DEVICE);
+ if (TapUtil.nameNotExist(tapName)) {
+ throw new VMLauncherException("Tap device is not exist : "
+ + tapName + "\nCheck VM's tap configuration.");
+ }
+ cmd.add("tap,ifname=" + tapName + ",script=no,downscript=no");
+ } else {
+ cmd.add("user,dhcpstart=10.0.2.16");
+ }
+ cmd.add("-rtc");
+ cmd.add("base=utc");
+ if (property.getConfiguration().getBaseInformation().getDiskImage().getSwapDiskImage() != null
+ && checkOnOff(property.getPropertyValue().getAdvancedOptionSubValue(OPT_DEVICE, OPT_SWAP))) {
+ cmd.add("-drive");
+ cmd.add("file=" + property.getConfiguration().getBaseInformation().getDiskImage().getSwapDiskImage().getValue() + ",if=virtio,index=2");
+ }
+
+ /* append HW virtualization option if supports */
+ if (hwVirtualization != null) {
+ cmd.add(hwVirtualization);
+ }
+
+ // add hw gl acceleration
+ if (property.getConfiguration().getUsability().isHwGLAcceleration()
+ && CheckVirtualization.getInstance().isSupportGPU()) {
+// cmd.add(CheckVirtualization.getInstance().getGPU_enable_command());
+ cmd.add("-vigs-backend");
+ cmd.add("gl");
+ cmd.add("-enable-yagl");
+ cmd.add("-yagl-backend");
+ cmd.add("vigs");
+ } else {
+ cmd.add("-vigs-backend");
+ cmd.add("sw");
+ }
+
+ // for suspend
+ if (EmulatorManager.getManagerMode() == ManagerModeType.INHOUSE_MODE
+ && property.getConfiguration().getUsability().isSupoortSuspend()) {
+ cmd.add("-enable-suspend");
+ }
+
+ // for bootup status
+ cmd.add("-device");
+ cmd.add("virtio-esm-pci");
+
+ // for host keyboard
+ cmd.add("-device");
+ cmd.add("virtio-keyboard-pci");
+
+ // for ecp
+ cmd.add("-device");
+ cmd.add("virtio-evdi-pci,profile=" + property.getPropertyValue().profile
+ + "-" + property.getPropertyValue().version);
+
+ // for brightness
+ cmd.add("-device");
+ cmd.add("maru-brightness");
+
+ // for vmodem
+ cmd.add("-device");
+ cmd.add("virtio-vmodem-pci");
+
+ // for hardware key
+ if (checkOnOff(property.getPropertyValue().getAdvancedOptionValue(OPT_HWKEY))) {
+ cmd.add("-device");
+ cmd.add("virtio-hwkey-pci");
+ }
+
+ // for codec
+ if (checkOnOff(property.getPropertyValue().getAdvancedOptionValue(OPT_CODEC))) {
+ cmd.add("-device");
+ cmd.add("codec-pci");
+ }
+
+ // for nfc
+ if (checkOnOff(property.getPropertyValue().getAdvancedOptionSubValue(OPT_DEVICE, OPT_NFC))) {
+ cmd.add("-device");
+ cmd.add("virtio-nfc-pci");
+ }
+
+ // for battery
+ cmd.add("-device");
+ cmd.add("virtio-power-pci");
+ /*if (checkOnOff(property.getPropertyValue().getAdvancedOptionSubValue(OPT_DEVICE, OPT_BATTERY))) {
+ cmd.add("-device");
+ cmd.add("virtio-power-pci");
+ }*/
+
+ // for camera
+ if (checkOnOff(property.getPropertyValue().getAdvancedOptionSubValue(OPT_DEVICE, OPT_CAMERA))) {
+ cmd.add("-device");
+ cmd.add("maru-camera");
+ }
+
+ cmd.add("-device");
+ TouchType touchType = property.getConfiguration().getDevice().getTouch();
+ if (touchType != null) {
+ cmd.add("virtio-touchscreen-pci,max_point=" + touchType.getMaxTouchPoint());
+ } else {
+ cmd.add("virtio-touchscreen-pci");
+ }
+
+ // for sensor (accel, geo, gyro, light, proxi, haptic, pressure, ultra violet, heart rate meter)
+ OptionType sensor = property.getPropertyValue().getAdvancedOption(OPT_SENSOR);
+ if (sensor != null) {
+ cmd.add("-device");
+
+ StringBuilder sb = new StringBuilder();
+ if (checkOnOff(property.getPropertyValue().getAdvancedOptionSubValue(OPT_SENSOR, OPT_ACCEL))) {
+ if(!sb.toString().isEmpty()) {
+ sb.append("&");
+ }
+ sb.append("accel");
+ }
+ if (checkOnOff(property.getPropertyValue().getAdvancedOptionSubValue(OPT_SENSOR, OPT_GEO))) {
+ if(!sb.toString().isEmpty()) {
+ sb.append("&");
+ }
+ sb.append("geo");
+ }
+ if (checkOnOff(property.getPropertyValue().getAdvancedOptionSubValue(OPT_SENSOR, OPT_GYRO))) {
+ if(!sb.toString().isEmpty()) {
+ sb.append("&");
+ }
+ sb.append("gyro");
+ }
+ if (checkOnOff(property.getPropertyValue().getAdvancedOptionSubValue(OPT_SENSOR, OPT_LIGHT))) {
+ if(!sb.toString().isEmpty()) {
+ sb.append("&");
+ }
+ sb.append("light");
+ }
+ if (checkOnOff(property.getPropertyValue().getAdvancedOptionSubValue(OPT_SENSOR, OPT_PROXI))) {
+ if(!sb.toString().isEmpty()) {
+ sb.append("&");
+ }
+ sb.append("proxi");
+ }
+ if (checkOnOff(property.getPropertyValue().getAdvancedOptionSubValue(OPT_SENSOR, OPT_HAPTIC))) {
+ if(!sb.toString().isEmpty()) {
+ sb.append("&");
+ }
+ sb.append("haptic");
+ }
+ if (checkOnOff(property.getPropertyValue().getAdvancedOptionSubValue(OPT_SENSOR, OPT_PRESS))) {
+ if(!sb.toString().isEmpty()) {
+ sb.append("&");
+ }
+ sb.append("press");
+ }
+ if (checkOnOff(property.getPropertyValue().getAdvancedOptionSubValue(OPT_SENSOR, OPT_UV))) {
+ if(!sb.toString().isEmpty()) {
+ sb.append("&");
+ }
+ sb.append("uv");
+ }
+ if (checkOnOff(property.getPropertyValue().getAdvancedOptionSubValue(OPT_SENSOR, OPT_HRM))) {
+ if(!sb.toString().isEmpty()) {
+ sb.append("&");
+ }
+ sb.append("hrm");
+ }
+
+ if (sb.toString().isEmpty()) {
+ cmd.add("virtio-sensor-pci");
+ } else {
+ sb.insert(0, "virtio-sensor-pci,sensors=");
+ cmd.add(sb.toString());
+ }
+ }
+
+ // for jacks (enabled charger, earjack and usb)
+ cmd.add("-device");
+ cmd.add("virtio-jack-pci,jacks=earjack&charger&usb");
+ /* OptionType jacks = property.getPropertyValue().getAdvancedOption(OPT_JACK);
+ if (jacks != null) {
+ cmd.add("-device");
+
+ StringBuilder sb = new StringBuilder();
+ if (checkOnOff(property.getPropertyValue().getAdvancedOptionSubValue(OPT_JACK, OPT_EARJACK))) {
+ if(!sb.toString().isEmpty()) {
+ sb.append("&");
+ }
+ sb.append("earjack");
+ }
+ if (checkOnOff(property.getPropertyValue().getAdvancedOptionSubValue(OPT_JACK, OPT_CHARGER))) {
+ if(!sb.toString().isEmpty()) {
+ sb.append("&");
+ }
+ sb.append("charger");
+ }
+ if (checkOnOff(property.getPropertyValue().getAdvancedOptionSubValue(OPT_JACK, OPT_USB))) {
+ if(!sb.toString().isEmpty()) {
+ sb.append("&");
+ }
+ sb.append("usb");
+ }
+
+ if (sb.toString().isEmpty()) {
+ cmd.add("virtio-jack-pci");
+ } else {
+ sb.insert(0, "virtio-jack-pci,jacks=");
+ cmd.add(sb.toString());
+ }
+ } */
+ }
+
+ /* append user added options if exists */
+ String advancedOptions = property.getConfiguration().getUsability().getAdvancedOptions();
+ if (advancedOptions != null) {
+ String[] arrOptions = advancedOptions.split(" ");
+ for (String option : arrOptions) {
+ cmd.add(option);
+ }
+ }
+
+ /* spice options */
+ if (RemoteManager.getSpiceMode()
+ || CheckingRunningEmulator.isRemote(property)) {
+ cmd.add("-spice");
+ cmd.add("disable-ticketing");
+ cmd.add("-device");
+ cmd.add("virtio-serial-pci,id=virtio-serial0,max_ports=16,bus=pci.0");
+ cmd.add("-chardev");
+ cmd.add("spicevmc,id=vdagent,name=vdagent");
+ cmd.add("-device");
+ cmd.add("virtserialport,nr=1,bus=virtio-serial0.0,chardev=vdagent,name=com.redhat.spice.0");
+ }
+
+ //for qt enable
+ if (checkOnOff(property.getPropertyValue().getAdvancedOptionSubValue(
+ OPT_EXPERIMENTAL, OPT_QT_ENABLE))) {
+ if (EmulatorManager.getManagerMode() == ManagerModeType.INHOUSE_MODE) {
+ cmd.add("-display");
+ if (EmulatorManager.isMac()) {
+ cmd.add("maru_qt,rendering=offscreen");
+ } else {
+ cmd.add("maru_qt,rendering=onscreen");
+ }
+ }
+ }
+
+ EMLogger.getLogger().log(Level.INFO, "Starting Emulator Command : ");
+ String temp = cmd.get(0) + " ";
+ for (String s : cmd.subList(1, cmd.size())) {
+ temp += ("\"" + s + "\" ");
+ }
+ EMLogger.getLogger().log(Level.INFO, temp);
+ System.out.println("cmd : " + cmd);
+ return cmd;
+ }
+
+ @Override
+ public boolean launch(VMProperty property) throws VMLauncherException {
+ return launch(property, false);
+ }
+
+ @Override
+ public boolean launch(VMProperty property, boolean wait) throws VMLauncherException {
+ List<String> cmd;
+
+ cmd = getLaunchCommand(property, null);
+
+ if (cmd == null) {
+ return false;
+ }
+
+ CheckingRunningEmulator.addEmulator(property);
+ MonitoringEmulator monitor = new MonitoringEmulator(property);
+ Process process = launch(cmd);
+ if (process != null) {
+ monitor.setProcess(process);
+ monitor.start();
+ if (wait) {
+ try {
+ monitor.join();
+ } catch (InterruptedException e) {
+ EMLogger.getLogger().warning(e.getMessage());
+ }
+ if (monitor.isSuccess()) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ return true;
+ } else {
+ CheckingRunningEmulator.removeEmulator(property, false);
+ monitor.interrupt();
+ return false;
+ }
+ }
+
+ @Override
+ public Process launch(List<String> cmd) {
+ ProcessBuilder pb = new ProcessBuilder(cmd);
+ Map<String, String> env = pb.environment();
+ if (EmulatorManager.isLinux()) {
+ String value = env.get("LD_LIBRARY_PATH");
+ env.put("LD_LIBRARY_PATH", ((value == null) ? "" : value + ":") + FilePathResources.getBinPath() + ":" + FilePathResources.getRemotePath() + File.separator + "lib:");
+ EMLogger.getLogger().log(Level.INFO, "LD_LIBRARY_PATH=" + env.get("LD_LIBRARY_PATH"));
+ }
+ env.put("GL_VERSION", "2");
+ EMLogger.getLogger().log(Level.INFO, "GL_VERSION: " + env.get("GL_VERSION"));
+
+ if (this.binPath == null || this.binPath.isEmpty()) {
+ pb.directory(new File(FilePathResources.getBinPath()));
+ } else {
+ pb.directory(new File(this.binPath));
+ }
+
+ Process process = null;
+ try {
+ process = pb.start();
+ } catch (IOException e) {
+ if (!isConsole) {
+ MessageDialog msg = new MessageDialog(new Shell(Display.getCurrent()));
+ msg.openWarningDialog("Failed to launch" + StringResources.NEW_LINE + e.getMessage());
+ }
+ EMLogger.getLogger().log(Level.WARNING, "Failed to launch." + StringResources.NEW_LINE + e.getMessage());
+ }
+
+ return process;
+ }
+
+
+ private boolean checkOnOff(String value) {
+ if (value.toLowerCase().equals("on")) {
+ return true;
+ } else if (value.toLowerCase().equals("off")) {
+ return false;
+ } else if (value.isEmpty()){
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ private boolean checkOn(String value) {
+ if (value.toLowerCase().equals("on")) {
+ return true;
+ }
+ return false;
+ }
+
+
+ @Override
+ public void sendRemoteLog(String msg) {
+ EMLogger.getLogger().info("Launcher log : " + msg);
+ }
+
+ private static boolean isTapUsing(String tapName) {
+ boolean isUsing = false;
+// VMProperty arr[] = (VMProperty[]) EmulatorVMList.getInstance()
+// .getProperties();
+// int len$ = arr$.length;
+// for (int i$ = 0; i$ < len$; i$++) {
+ for (VMProperty prop : EmulatorVMList.getInstance().getProperties()) {
+ if (!prop.isRunning()) {
+ continue;
+ }
+ String name = prop.getPropertyValue().getAdvancedOptionValue(
+ OPT_NET_TAP_DEVICE);
+ if (tapName.equals(name)) {
+ isUsing = true;
+ break;
+ }
+ }
+
+ return isUsing;
+ }
+
+ private static boolean isIpAddrUsing(String ipAddr) {
+ boolean isUsing = false;
+
+ for (VMProperty prop : EmulatorVMList.getInstance().getProperties()) {
+ if (!prop.isRunning()) {
+ continue;
+ }
+ String ip = prop.getPropertyValue().getAdvancedOptionSubValue(
+ OPT_NET_IP_INFO, "ipAddr");
+ if (!ipAddr.equals(ip)) {
+ continue;
+ }
+ isUsing = true;
+ break;
+ }
+
+ return isUsing;
+ }
+
+ private String getIP(boolean useBridgeNet, VMProperty prop) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(" ip=");
+ if (useBridgeNet) {
+ String useDHCP = prop.getPropertyValue().getAdvancedOptionSubValue(
+ OPT_NET_IP_INFO, OPT_NET_DHCP);
+ if (checkOn(useDHCP)) {
+ return "";
+ }
+
+ sb.append(prop.getPropertyValue().getAdvancedOptionSubValue(
+ OPT_NET_IP_INFO, OPT_NET_IPADDR));
+ sb.append("::");
+ sb.append(prop.getPropertyValue().getAdvancedOptionSubValue(
+ OPT_NET_IP_INFO, OPT_NET_GATEWAY));
+ sb.append(":");
+ sb.append(prop.getPropertyValue().getAdvancedOptionSubValue(
+ OPT_NET_IP_INFO, OPT_NET_SUBNET));
+ sb.append("::eth0:none:");
+ sb.append(prop.getPropertyValue().getAdvancedOptionValue(
+ OPT_NET_DNS));
+
+ } else { // NAT (default)
+ sb.append("10.0.2.16::10.0.2.2:255.255.255.0::eth0:none:10.0.2.3");
+ }
+ return sb.toString();
+ }
+
+ private String getHostProxy() throws VMLauncherException{
+ String result = null;
+ String proxyCommand = "check-net";
+ if (EmulatorManager.isWin()) {
+ proxyCommand = "check-net.exe";
+ }
+
+ List<String> cmd = Arrays.asList(FilePathResources.getBinPath() + File.separator + proxyCommand, "--proxy");
+ ProcessResult res = HelperClass.runProcess(cmd);
+ boolean isCommandSuccess = false;
+ if (res.isSuccess()) {
+ for (String str : res.getStdOutMsg()) {
+ if (str.startsWith("MODE:")) {
+ isCommandSuccess = true;
+ }
+ if (str.startsWith("http_proxy")) {
+ result = str;
+ }
+ }
+
+ } else if (!res.isSuccess() || !isCommandSuccess) {
+ EMLogger.getLogger().warning(res.getResultMessage());
+ int dialogRes = new MessageDialog().openWarningAndSelectionDialog
+ ("Failed to get host proxy setting."
+ + "\n" + res.getResultMessage()
+ + "\nContinue launching anyway ?");
+ if (dialogRes != SWT.OK) {
+ throw new VMLauncherException("User canceled launching VM.");
+ }
+ }
+
+ if (result == null) {
+ EMLogger.getLogger().warning("Can't find host proxy setting.");
+ EMLogger.getLogger().warning("check-net result : " + res.getResultMessage());
+ }
+
+ return result;
+ }
+}
--- /dev/null
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * MunKyu Im <munkyu.im@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * 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.wearable.vms;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.tizen.emulator.manager.EmulatorManager;
+import org.tizen.emulator.manager.EmulatorManager.ManagerModeType;
+import org.tizen.emulator.manager.console.RemoteManager;
+import org.tizen.emulator.manager.logging.EMLogger;
+import org.tizen.emulator.manager.wearable.ui.detail.ItemListFactory;
+import org.tizen.emulator.manager.resources.FilePathResources;
+import org.tizen.emulator.manager.resources.StringResources;
+import org.tizen.emulator.manager.tool.CheckVirtualization;
+import org.tizen.emulator.manager.tool.PortHelper;
+import org.tizen.emulator.manager.tool.SettingInfoFile;
+import org.tizen.emulator.manager.tool.TapUtil;
+import org.tizen.emulator.manager.ui.detail.item.CommonItemListFactory;
+import org.tizen.emulator.manager.ui.detail.item.property.NetIPInfoViewItem;
+import org.tizen.emulator.manager.ui.detail.item.property.NetProxyViewItem;
+import org.tizen.emulator.manager.ui.dialog.IPAddressInputDialog;
+import org.tizen.emulator.manager.ui.dialog.MessageDialog;
+import org.tizen.emulator.manager.vms.EmulatorVMList;
+import org.tizen.emulator.manager.vms.ILauncher;
+import org.tizen.emulator.manager.vms.VMProperty;
+import org.tizen.emulator.manager.vms.helper.CheckingRunningEmulator;
+import org.tizen.emulator.manager.vms.helper.HelperClass;
+import org.tizen.emulator.manager.vms.helper.MonitoringEmulator;
+import org.tizen.emulator.manager.vms.helper.ProcessResult;
+import org.tizen.emulator.manager.vms.helper.VMLauncherException;
+import org.tizen.emulator.manager.vms.xml.CpuType;
+import org.tizen.emulator.manager.vms.xml.OptionType;
+import org.tizen.emulator.manager.vms.helper.VMWorkerException;
+import org.tizen.emulator.manager.vms.xml.TouchType;
+
+public class Launcher implements ILauncher {
+ private boolean isConsole = false;
+ private String binPath = null;
+ private static Launcher launcher;
+
+
+ // Option names in vm_config.xml
+ // Add if need.
+ public static final String OPT_DEVICE = "device";
+ public static final String OPT_NFC = "nfc";
+ public static final String OPT_BATTERY = "battery";
+ public static final String OPT_CAMERA = "camera";
+ public static final String OPT_HWKEY = "hwkey";
+ public static final String OPT_SWAP = "swap";
+ public static final String OPT_CODEC = "codec";
+
+ public static final String OPT_JACK = "jack";
+ public static final String OPT_USB = "usb";
+ public static final String OPT_CHARGER = "charger";
+
+ public static final String OPT_SENSOR = "sensor";
+ public static final String OPT_ACCEL = "accel";
+ public static final String OPT_GYRO = "gyro";
+ public static final String OPT_GEO = "geo";
+ public static final String OPT_LIGHT = "light";
+ public static final String OPT_PROXI = "proxi";
+ public static final String OPT_HAPTIC = "haptic";
+ public static final String OPT_PRESS = "press"; // pressure
+ public static final String OPT_UV = "uv"; // ultra violet
+ public static final String OPT_HRM = "hrm"; // heartbeat rate meter
+
+ public static final String OPT_EXPERIMENTAL = ItemListFactory.ITEM_EXPERIMENTAL;
+ public static final String OPT_QT_ENABLE = "qtEnable";
+
+ // Network option.
+ public static final String OPT_NET_CONNECT_TYPE = CommonItemListFactory.ITEM_NET_CONNECT_TYPE;
+ public static final String OPT_NET_TAP_DEVICE = CommonItemListFactory.ITEM_NET_TAP_DEVICE;
+ public static final String OPT_NET_IP_INFO = CommonItemListFactory.ITEM_NET_IP_INFO;
+ public static final String OPT_NET_IPADDR = NetIPInfoViewItem.ITEM_IP;
+ public static final String OPT_NET_SUBNET = NetIPInfoViewItem.ITEM_SUBNET;
+ public static final String OPT_NET_GATEWAY = NetIPInfoViewItem.ITEM_GATEWAY;
+ public static final String OPT_NET_DNS = CommonItemListFactory.ITEM_NET_DNS;
+ public static final String OPT_NET_MAC = CommonItemListFactory.ITEM_NET_MAC;
+ public static final String OPT_NET_PROXY = CommonItemListFactory.ITEM_NET_PROXY;
+ public static final String OPT_NET_DHCP = NetIPInfoViewItem.ITEM_USE_DHCP;
+
+ public static Launcher getInstance() {
+ if (launcher == null) {
+ launcher = new Launcher();
+ }
+ return launcher;
+ }
+
+ public Launcher() {
+ isConsole = EmulatorManager.isConsoleMode();
+ }
+
+ @Override
+ public List<String> getLaunchCommand(VMProperty property, String path)
+ throws VMLauncherException {
+ String binary;
+ String hwVirtualization = "";
+ int portNo;
+ boolean useBridgeNet = property.getPropertyValue()
+ .getAdvancedOptionValue(OPT_NET_CONNECT_TYPE).equals("Bridge") &&
+ (EmulatorManager.isLinux() || EmulatorManager.isWin());
+
+ if (useBridgeNet) {
+ String tapName = property.getPropertyValue()
+ .getAdvancedOptionValue(OPT_NET_TAP_DEVICE);
+ if (TapUtil.nameNotExist(tapName))
+ throw new VMLauncherException((new StringBuilder())
+ .append("Tap device is not exist : ").append(tapName)
+ .append("\nCheck VM's tap configuration.").toString());
+ if (isTapUsing(tapName))
+ throw new VMLauncherException(
+ (new StringBuilder())
+ .append("Tap device(")
+ .append(tapName)
+ .append(") is being used by other VM.")
+ .append("\nPlease select another tap device for current VM.")
+ .toString());
+ String ipAddr = property.getPropertyValue()
+ .getAdvancedOptionSubValue(OPT_NET_IP_INFO, "ipAddr");
+ if (isIpAddrUsing(ipAddr))
+ throw new VMLauncherException((new StringBuilder())
+ .append("VM's ip address(").append(ipAddr)
+ .append(") is being used by other VM.")
+ .append("\nPlease modify current VM's ip address.")
+ .toString());
+ try {
+ if (!TapUtil.isTapInBridge(tapName)) {
+ MessageDialog dialog = new MessageDialog();
+ int res = dialog
+ .openWarningAndSelectionDialog("\nTap device is not connected with Bridge." +
+ "\nGuest network would work as NAT." +
+ "\nKeep launching ?");
+ if (res != SWT.OK) {
+ throw new VMLauncherException("User canceled.");
+ }
+ useBridgeNet = false;
+ }
+
+ } catch (VMWorkerException e) {
+ throw new VMLauncherException(e.getMessage());
+ }
+ }
+ /* check available port number */
+ portNo = new PortHelper().getPortNo();
+ if(portNo == -1) {
+ String error = "Can not execute emulator."
+ + StringResources.NEW_LINE
+ + "All available ports are in use.";
+ throw new VMLauncherException(error);
+ }
+
+ if (property.getArch().toString().equals("x86")) {
+ if (EmulatorManager.isWin()) {
+ binary = "emulator-x86.exe";
+ } else {
+ binary = "emulator-x86";
+ }
+ } else {
+ if (EmulatorManager.isWin()) {
+ binary = "emulator-arm.exe";
+ } else {
+ binary = "emulator-arm";
+ }
+ }
+
+ // check disk image
+ File child = new File(property.getConfiguration().getBaseInformation().getDiskImage().getCurrentDiskImage().getValue());
+ File base = new File(property.getConfiguration().getBaseInformation().getDiskImage().getBaseDiskImage().getValue());
+ if (!child.exists()) {
+ throw new VMLauncherException("Child disk image does not exist."
+ + StringResources.NEW_LINE + child.getAbsolutePath()
+ , true);
+ }
+ if (!base.exists()) {
+ throw new VMLauncherException("Base disk image does not exist."
+ + StringResources.NEW_LINE + base.getAbsolutePath()
+ , true);
+ }
+ if (property.getConfiguration().getUsability().isHwVirtualization() && CheckVirtualization.getInstance().isSupportVirtualization()) {
+ hwVirtualization = CheckVirtualization.getInstance().getVirtualizationEnableCommnad();
+ } else {
+ hwVirtualization = CheckVirtualization.getInstance().getVirtualizationDisableCommnad();
+ }
+
+ List<String> cmd = new ArrayList<String>();
+ int width = property.getConfiguration().getDevice().getDisplay().getResolution().getWidth();
+ int height = property.getConfiguration().getDevice().getDisplay().getResolution().getHeight();
+ String skinPath = null;
+ if (property.getConfiguration().getDevice().getDisplay().getSkinPath() != null) {
+ skinPath = property.getConfiguration().getDevice().getDisplay().getSkinPath().getPath();
+ if (skinPath != null && skinPath.isEmpty()) {
+ skinPath = null;
+ }
+ }
+ String fileshare = property.getConfiguration().getUsability().getFileSharing().getPath();
+ String osVersion = System.getProperty("os.version");
+ boolean isFileshare = true;
+ if (fileshare == null) {
+ isFileshare = false;
+ }
+
+ /* get MAC address of host set as guest MAC address */
+ String macAddr = useBridgeNet ? property.getPropertyValue()
+ .getAdvancedOptionValue(OPT_NET_MAC) : SettingInfoFile
+ .getMACaddr();
+
+ if(macAddr.isEmpty()) {
+ macAddr = "52:54:00:12:34:56";
+ EMLogger.getLogger().log(Level.INFO, String.format("MAC set as default = %s", macAddr));
+ }
+
+ if (path == null || path.isEmpty()) {
+ cmd.add(FilePathResources.getBinPath() + File.separator + binary);
+ } else {
+ this.binPath = path;
+ cmd.add(binPath + File.separator + binary);
+ }
+
+ cmd.add("--skin-args");
+ cmd.add("width=" + width);
+ cmd.add("height=" + height);
+ if (skinPath != null) {
+ cmd.add("skin.path=" + skinPath);
+ }
+
+ if (RemoteManager.getSpiceMode()) {
+ cmd.add("hb.ignore=true");
+ }
+
+ cmd.add("--qemu-args");
+ // x86 part of cmd
+ if (property.getArch().toString().equals("x86")) {
+ cmd.add("-drive");
+ cmd.add("file=" + property.getConfiguration().getBaseInformation().getDiskImage().getCurrentDiskImage().getValue()+ ",if=virtio,index=1");
+ cmd.add( "-boot");
+ cmd.add("c");
+ cmd.add("-append");
+
+ String kernelOption = "console=ttyS0 video=LVDS-1:"
+ + width
+ + "x"
+ + height
+ + "-32@60"
+ + " dpi=" + property.getConfiguration().getDevice().getDisplay().getDensity().getValue() * 10
+ + " ip=10.0.2.16::10.0.2.2:255.255.255.0::eth0:none"
+ + " vm_name=" + property.getConfiguration().getBaseInformation().getName();
+ String hostIp = "10.0.2.2";
+ if (useBridgeNet) {
+ String bridgeIp = TapUtil.getBridgeIpAddr(property
+ .getPropertyValue().getAdvancedOptionValue(
+ OPT_NET_TAP_DEVICE));
+ if (bridgeIp == null) {
+ MessageDialog dialog = new MessageDialog();
+ int res = dialog.openInfoDialog(
+ "\nCannot find host(bridge) IP address."
+ + "\nTo use bridge network, host IP is required."
+ + "\nPlease input manually.");
+ if (res != SWT.OK) {
+ throw new VMLauncherException("User canceled.");
+ }
+
+ // Input host IP address.
+ String ip = IPAddressInputDialog.open("Input host's IP address");
+ if (ip == null) {
+ throw new VMLauncherException("User canceled.");
+
+ } else {
+ hostIp = ip;
+ }
+
+ } else {
+ hostIp = bridgeIp;
+ }
+ }
+ kernelOption += " host_ip=" + hostIp;
+
+ // Set proxy.
+ if (EmulatorManager.isLinux() || EmulatorManager.isWin()) {
+ String proxyConfig = null;
+ String proxyMode = property.getPropertyValue().
+ getAdvancedOptionSubValue(OPT_NET_PROXY, NetProxyViewItem.ITEM_PROXY_MODE);
+ if (proxyMode.equals(NetProxyViewItem.MODE_AUTO)) {
+ proxyConfig = getHostProxy();
+
+ } else if (proxyMode.equals(NetProxyViewItem.MODE_MANUAL)) {
+ proxyConfig = "http_proxy=" + property.getPropertyValue().
+ getAdvancedOptionSubValue(OPT_NET_PROXY, NetProxyViewItem.ITEM_HTTP_PROXY)
+ + " https_proxy=" + property.getPropertyValue().
+ getAdvancedOptionSubValue(OPT_NET_PROXY, NetProxyViewItem.ITEM_HTTPS_PROXY)
+ + " ftp_proxy=" + property.getPropertyValue().
+ getAdvancedOptionSubValue(OPT_NET_PROXY, NetProxyViewItem.ITEM_FTP_PROXY)
+ + " socks_proxy=" + property.getPropertyValue().
+ getAdvancedOptionSubValue(OPT_NET_PROXY, NetProxyViewItem.ITEM_SOCKS_PROXY);
+ }
+
+ if (proxyConfig != null) {
+ kernelOption += (" " + proxyConfig);
+ }
+ }
+
+ /* set virtio-9p string in case of using directory share [kernel option] */
+ if(isFileshare) {
+ kernelOption += " virtio-9p";
+ }
+ /*
+ if(property.getPropertyValue().skin != null && property.getPropertyValue().skin.getButtonType() == SKIN_BUTTON_TYPE.THREE_BUTTON_TYPE) {
+ kernelOption += " platform_feature=3btn";
+ } else {
+ kernelOption += " platform_feature=1btn";
+ }
+ */
+
+ cmd.add(kernelOption);
+
+ /* use fileshare [non-kernel option] */
+ if(isFileshare) {
+ cmd.add("-virtfs");
+ cmd.add("local,path=" + property.getConfiguration().getUsability().getFileSharing().getPath() +",security_model=none,mount_tag=fileshare");
+ }
+
+ cmd.add("-serial");
+ cmd.add("file:" + FilePathResources.getTizenVmsPath() + File.separator + property.getName() + File.separator + "logs" + File.separator + "emulator.klog");
+ CpuType cpuOption = property.getConfiguration().getDevice().getCPU();
+ if (cpuOption != null) {
+ cmd.add("-smp");
+ cmd.add(String.valueOf(cpuOption.getValue().getValue()));
+ }
+ cmd.add("-m");
+ cmd.add(String.valueOf(property.getConfiguration().getDevice().getRAM().getSize().getValue()));
+ cmd.add("-M");
+ cmd.add("maru-x86-machine");
+ cmd.add("-net");
+ cmd.add("nic,model=virtio,macaddr=" + macAddr);
+ cmd.add("-soundhw");
+ cmd.add("all");
+ cmd.add("-usb");
+ cmd.add("-vga");
+ cmd.add("none");
+ cmd.add("-enable-vigs");
+ cmd.add("-L");
+ cmd.add(FilePathResources.getBiosPath());
+ cmd.add("-kernel");
+ cmd.add(FilePathResources.getKernelPath() + File.separator+ "bzImage." + property.getArch().toString());
+ cmd.add("-net");
+ if (useBridgeNet) {
+ String tapName = property.getPropertyValue()
+ .getAdvancedOptionValue(OPT_NET_TAP_DEVICE);
+ if (TapUtil.nameNotExist(tapName)) {
+ throw new VMLauncherException("Tap device is not exist : "
+ + tapName + "\nCheck VM's tap configuration.");
+ }
+ cmd.add("tap,ifname=" + tapName + ",script=no,downscript=no");
+ } else {
+ cmd.add("user,dhcpstart=10.0.2.16");
+ }
+ cmd.add("-rtc");
+ cmd.add("base=utc");
+ if (property.getConfiguration().getBaseInformation().getDiskImage().getSwapDiskImage() != null) {
+ cmd.add("-drive");
+ cmd.add("file=" + property.getConfiguration().getBaseInformation().getDiskImage().getSwapDiskImage().getValue() + ",if=virtio,index=2");
+ }
+
+ /* append HW virtualization option if supports */
+ if (hwVirtualization != null) {
+ cmd.add(hwVirtualization);
+ }
+
+ // add hw gl acceleration
+ if (property.getConfiguration().getUsability().isHwGLAcceleration()
+ && CheckVirtualization.getInstance().isSupportGPU()) {
+ //cmd.add(CheckVirtualization.getInstance().getGPU_enable_command());
+ cmd.add("-vigs-backend");
+ cmd.add("gl");
+ cmd.add("-enable-yagl");
+ cmd.add("-yagl-backend");
+ cmd.add("vigs");
+ } else {
+ cmd.add("-vigs-backend");
+ cmd.add("sw");
+ }
+
+ // for bootup status
+ cmd.add("-device");
+ cmd.add("virtio-esm-pci");
+
+ // for brightness
+ cmd.add("-device");
+ cmd.add("maru-brightness");
+
+ // for vmodem
+ cmd.add("-device");
+ cmd.add("virtio-vmodem-pci");
+
+ // for hardware key
+ if (checkOnOff(property.getPropertyValue().getAdvancedOptionValue(OPT_HWKEY))) {
+ cmd.add("-device");
+ cmd.add("virtio-hwkey-pci");
+ }
+
+ // for codec
+ if (checkOnOff(property.getPropertyValue().getAdvancedOptionValue(OPT_CODEC))) {
+ cmd.add("-device");
+ cmd.add("codec-pci");
+ }
+
+ // for ecp
+ cmd.add("-device");
+ cmd.add("virtio-evdi-pci,profile=" + property.getPropertyValue().profile
+ + "-" + property.getPropertyValue().version);
+
+ // for camera
+ if (checkOnOff(property.getPropertyValue().getAdvancedOptionSubValue(OPT_DEVICE, OPT_CAMERA))) {
+ cmd.add("-device");
+ cmd.add("maru-camera");
+ }
+
+ // for battery
+ cmd.add("-device");
+ cmd.add("virtio-power-pci");
+
+ // for nfc
+ if (checkOnOff(property.getPropertyValue().getAdvancedOptionSubValue(OPT_DEVICE, OPT_NFC))) {
+ cmd.add("-device");
+ cmd.add("virtio-nfc-pci");
+ }
+
+ // for sensor (accel, geo, gyro, light, proxi, haptic, pressure, ultra violet, heart rate meter)
+ OptionType sensor = property.getPropertyValue().getAdvancedOption(OPT_SENSOR);
+ if (sensor != null) {
+ cmd.add("-device");
+
+ StringBuilder sb = new StringBuilder();
+ if (checkOnOff(property.getPropertyValue().getAdvancedOptionSubValue(OPT_SENSOR, OPT_ACCEL))) {
+ if(!sb.toString().isEmpty()) {
+ sb.append("&");
+ }
+ sb.append("accel");
+ }
+ if (checkOnOff(property.getPropertyValue().getAdvancedOptionSubValue(OPT_SENSOR, OPT_GEO))) {
+ if(!sb.toString().isEmpty()) {
+ sb.append("&");
+ }
+ sb.append("geo");
+ }
+ if (checkOnOff(property.getPropertyValue().getAdvancedOptionSubValue(OPT_SENSOR, OPT_GYRO))) {
+ if(!sb.toString().isEmpty()) {
+ sb.append("&");
+ }
+ sb.append("gyro");
+ }
+ if (checkOnOff(property.getPropertyValue().getAdvancedOptionSubValue(OPT_SENSOR, OPT_LIGHT))) {
+ if(!sb.toString().isEmpty()) {
+ sb.append("&");
+ }
+ sb.append("light");
+ }
+ if (checkOnOff(property.getPropertyValue().getAdvancedOptionSubValue(OPT_SENSOR, OPT_PROXI))) {
+ if(!sb.toString().isEmpty()) {
+ sb.append("&");
+ }
+ sb.append("proxi");
+ }
+ if (checkOnOff(property.getPropertyValue().getAdvancedOptionSubValue(OPT_SENSOR, OPT_HAPTIC))) {
+ if(!sb.toString().isEmpty()) {
+ sb.append("&");
+ }
+ sb.append("haptic");
+ }
+ if (checkOnOff(property.getPropertyValue().getAdvancedOptionSubValue(OPT_SENSOR, OPT_PRESS))) {
+ if(!sb.toString().isEmpty()) {
+ sb.append("&");
+ }
+ sb.append("press");
+ }
+ if (checkOnOff(property.getPropertyValue().getAdvancedOptionSubValue(OPT_SENSOR, OPT_UV))) {
+ if(!sb.toString().isEmpty()) {
+ sb.append("&");
+ }
+ sb.append("uv");
+ }
+ if (checkOnOff(property.getPropertyValue().getAdvancedOptionSubValue(OPT_SENSOR, OPT_HRM))) {
+ if(!sb.toString().isEmpty()) {
+ sb.append("&");
+ }
+ sb.append("hrm");
+ }
+
+ if (sb.toString().isEmpty()) {
+ cmd.add("virtio-sensor-pci");
+ } else {
+ sb.insert(0, "virtio-sensor-pci,sensors=");
+ cmd.add(sb.toString());
+ }
+ }
+
+ // for jacks (enabled charger, and usb)
+ cmd.add("-device");
+ cmd.add("virtio-jack-pci,jacks=charger&usb");
+ /* OptionType jacks = property.getPropertyValue().getAdvancedOption(OPT_JACK);
+ if (jacks != null) {
+ cmd.add("-device");
+
+ StringBuilder sb = new StringBuilder();
+ if (checkOnOff(property.getPropertyValue().getAdvancedOptionSubValue(OPT_JACK, OPT_CHARGER))) {
+ if(!sb.toString().isEmpty()) {
+ sb.append("&");
+ }
+ sb.append("charger");
+ }
+ if (checkOnOff(property.getPropertyValue().getAdvancedOptionSubValue(OPT_JACK, OPT_USB))) {
+ if(!sb.toString().isEmpty()) {
+ sb.append("&");
+ }
+ sb.append("usb");
+ }
+
+ if (sb.toString().isEmpty()) {
+ cmd.add("virtio-jack-pci");
+ } else {
+ sb.insert(0, "virtio-jack-pci,jacks=");
+ cmd.add(sb.toString());
+ }
+ } */
+
+
+ cmd.add("-device");
+ TouchType touchType = property.getConfiguration().getDevice().getTouch();
+ if (touchType != null) {
+ cmd.add("virtio-touchscreen-pci,max_point=" + touchType.getMaxTouchPoint());
+ } else {
+ cmd.add("virtio-touchscreen-pci");
+ }
+
+ } else { // ARM part of cmd
+ cmd.add("-drive");
+ cmd.add("file=" + property.getConfiguration().getBaseInformation().getDiskImage().getCurrentDiskImage().getValue()+ ",id=virtio-blk,if=none");
+ cmd.add( "-device");
+ cmd.add("virtio-blk,drive=virtio-blk,transport=virtio-mmio.0");
+ cmd.add("-netdev");
+ cmd.add("user,id=virtio-net");
+ cmd.add("-device");
+ cmd.add("virtio-net,netdev=virtio-net,transport=virtio-mmio.1");
+ cmd.add("-append");
+ cmd.add("yagl=1 console=ttySAC2,115200 video=s3cfb:"
+ + width
+ + "x"
+ + height
+ + "-24"
+ + " dpi=" + property.getConfiguration().getDevice().getDisplay().getDensity().getValue() * 10
+ + " rootwait root=/dev/vda rw rootfstype=ext4"
+ + " ip=10.0.2.16::10.0.2.2:255.255.255.0::eth0:none"
+ + " vm_name=" + property.getConfiguration().getBaseInformation().getName()
+ + " virtio_mmio.device=4K@0x10AD0000:423 virtio_mmio.device=4K@0x10AC0000:422");
+ cmd.add("-serial");
+ cmd.add(EmulatorManager.isLinux() ? "/dev/null" : "none");
+ cmd.add("-serial");
+ cmd.add(EmulatorManager.isLinux() ? "/dev/null" : "none");
+ cmd.add("-serial");
+ cmd.add("file:" + FilePathResources.getTizenVmsPath() + File.separator + property.getName() + File.separator + "logs" + File.separator + "emulator.klog");
+ cmd.add("-m");
+ cmd.add(String.valueOf(property.getConfiguration().getDevice().getRAM().getSize().getValue()));
+ cmd.add("-M");
+ cmd.add("maru-arm-machine");
+ cmd.add("-soundhw");
+ cmd.add("all");
+ cmd.add("-usb");
+ cmd.add("-usbdevice");
+ cmd.add("maru-touchscreen");
+ cmd.add("-kernel");
+ cmd.add(FilePathResources.getKernelPath() + File.separator+ "bzImage." + property.getArch().toString());
+ }
+
+ //}
+
+ /* append user added options if exists */
+ String advancedOptions = property.getConfiguration().getUsability().getAdvancedOptions();
+ if (advancedOptions != null) {
+ String[] arrOptions = advancedOptions.split(" ");
+ for (String option : arrOptions) {
+ cmd.add(option);
+ }
+ }
+
+ /* spice options */
+ if (RemoteManager.getSpiceMode()) {
+ cmd.add("-spice");
+ cmd.add("disable-ticketing");
+ cmd.add("-device");
+ cmd.add("virtio-serial-pci,id=virtio-serial0,max_ports=16,bus=pci.0");
+ cmd.add("-chardev");
+ cmd.add("spicevmc,id=vdagent,name=vdagent");
+ cmd.add("-device");
+ cmd.add("virtserialport,nr=1,bus=virtio-serial0.0,chardev=vdagent,name=com.redhat.spice.0");
+ }
+
+ //for qt enable
+ if (checkOnOff(property.getPropertyValue().getAdvancedOptionSubValue(
+ OPT_EXPERIMENTAL, OPT_QT_ENABLE))) {
+ if (EmulatorManager.getManagerMode() == ManagerModeType.INHOUSE_MODE) {
+ cmd.add("-display");
+ if (EmulatorManager.isMac()) {
+ cmd.add("maru_qt,rendering=offscreen");
+ } else {
+ cmd.add("maru_qt,rendering=onscreen");
+ }
+ }
+ }
+
+ EMLogger.getLogger().log(Level.INFO, "Starting Emulator Command : ");
+ String temp = cmd.get(0) + " ";
+ for (String s : cmd.subList(1, cmd.size())) {
+ temp += ("\"" + s + "\" ");
+ }
+ EMLogger.getLogger().log(Level.INFO, temp);
+ System.out.println("cmd : " + cmd);
+ return cmd;
+ }
+
+ @Override
+ public boolean launch(VMProperty property) throws VMLauncherException {
+ return launch(property, false);
+ }
+
+ @Override
+ public boolean launch(VMProperty property, boolean wait) throws VMLauncherException {
+ List<String> cmd;
+
+ cmd = getLaunchCommand(property, null);
+
+ if (cmd == null) {
+ return false;
+ }
+
+ CheckingRunningEmulator.addEmulator(property);
+ MonitoringEmulator monitor = new MonitoringEmulator(property);
+ Process process = launch(cmd);
+ if (process != null) {
+ monitor.setProcess(process);
+ monitor.start();
+ if (wait) {
+ try {
+ monitor.join();
+ } catch (InterruptedException e) {
+ EMLogger.getLogger().warning(e.getMessage());
+ }
+ if (monitor.isSuccess()) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ return true;
+ } else {
+ CheckingRunningEmulator.removeEmulator(property, false);
+ monitor.interrupt();
+ return false;
+ }
+ }
+
+ @Override
+ public Process launch(List<String> cmd) {
+ ProcessBuilder pb = new ProcessBuilder(cmd);
+ Map<String, String> env = pb.environment();
+ if (EmulatorManager.isLinux()) {
+ String value = env.get("LD_LIBRARY_PATH");
+ env.put("LD_LIBRARY_PATH", ((value == null) ? "" : value + ":") + FilePathResources.getBinPath() + ":" + FilePathResources.getRemotePath() + File.separator + "lib:");
+ EMLogger.getLogger().log(Level.INFO, "LD_LIBRARY_PATH=" + env.get("LD_LIBRARY_PATH"));
+ }
+ env.put("GL_VERSION", "2");
+ EMLogger.getLogger().log(Level.INFO, "GL_VERSION: " + env.get("GL_VERSION"));
+
+ if (this.binPath == null || this.binPath.isEmpty()) {
+ pb.directory(new File(FilePathResources.getBinPath()));
+ } else {
+ pb.directory(new File(this.binPath));
+ }
+
+ Process process = null;
+ try {
+ process = pb.start();
+ } catch (IOException e) {
+ if (!isConsole) {
+ MessageDialog msg = new MessageDialog(new Shell(Display.getCurrent()));
+ msg.openWarningDialog("Failed to launch" + StringResources.NEW_LINE + e.getMessage());
+ }
+ EMLogger.getLogger().log(Level.WARNING, "Failed to launch." + StringResources.NEW_LINE + e.getMessage());
+ }
+
+ return process;
+ }
+
+ private boolean checkOnOff(String value) {
+ if (value.toLowerCase().equals("on")) {
+ return true;
+ } else if (value.toLowerCase().equals("off")) {
+ return false;
+ } else if (value.isEmpty()){
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ private boolean checkOn(String value) {
+ if (value.toLowerCase().equals("on")) {
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public void sendRemoteLog(String msg) {
+ EMLogger.getLogger().info("Launcher log : " + msg);
+ }
+
+ private static boolean isTapUsing(String tapName) {
+ boolean isUsing = false;
+// VMProperty arr[] = (VMProperty[]) EmulatorVMList.getInstance()
+// .getProperties();
+// int len$ = arr$.length;
+// for (int i$ = 0; i$ < len$; i$++) {
+ for (VMProperty prop : EmulatorVMList.getInstance().getProperties()) {
+ if (!prop.isRunning()) {
+ continue;
+ }
+ String name = prop.getPropertyValue().getAdvancedOptionValue(
+ OPT_NET_TAP_DEVICE);
+ if (tapName.equals(name)) {
+ isUsing = true;
+ break;
+ }
+ }
+
+ return isUsing;
+ }
+
+ private static boolean isIpAddrUsing(String ipAddr) {
+ boolean isUsing = false;
+
+ for (VMProperty prop : EmulatorVMList.getInstance().getProperties()) {
+ if (!prop.isRunning()) {
+ continue;
+ }
+ String ip = prop.getPropertyValue().getAdvancedOptionSubValue(
+ OPT_NET_IP_INFO, "ipAddr");
+ if (!ipAddr.equals(ip)) {
+ continue;
+ }
+ isUsing = true;
+ break;
+ }
+
+ return isUsing;
+ }
+
+ private String getIP(boolean useBridgeNet, VMProperty prop) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(" ip=");
+ if (useBridgeNet) {
+ String useDHCP = prop.getPropertyValue().getAdvancedOptionSubValue(
+ OPT_NET_IP_INFO, OPT_NET_DHCP);
+ if (checkOn(useDHCP)) {
+ return "";
+ }
+
+ sb.append(prop.getPropertyValue().getAdvancedOptionSubValue(
+ OPT_NET_IP_INFO, OPT_NET_IPADDR));
+ sb.append("::");
+ sb.append(prop.getPropertyValue().getAdvancedOptionSubValue(
+ OPT_NET_IP_INFO, OPT_NET_GATEWAY));
+ sb.append(":");
+ sb.append(prop.getPropertyValue().getAdvancedOptionSubValue(
+ OPT_NET_IP_INFO, OPT_NET_SUBNET));
+ sb.append("::eth0:none:");
+ sb.append(prop.getPropertyValue().getAdvancedOptionValue(
+ OPT_NET_DNS));
+
+ } else { // NAT (default)
+ sb.append("10.0.2.16::10.0.2.2:255.255.255.0::eth0:none:10.0.2.3");
+ }
+ return sb.toString();
+ }
+
+ private String getHostProxy() throws VMLauncherException{
+ String result = null;
+ String proxyCommand = "check-net";
+ if (EmulatorManager.isWin()) {
+ proxyCommand = "check-net.exe";
+ }
+
+ List<String> cmd = Arrays.asList(FilePathResources.getBinPath() + File.separator + proxyCommand, "--proxy");
+ ProcessResult res = HelperClass.runProcess(cmd);
+ boolean isCommandSuccess = false;
+ if (res.isSuccess()) {
+ for (String str : res.getStdOutMsg()) {
+ if (str.startsWith("MODE:")) {
+ isCommandSuccess = true;
+ }
+ if (str.startsWith("http_proxy")) {
+ result = str;
+ }
+ }
+
+ } else if (!res.isSuccess() || !isCommandSuccess) {
+ EMLogger.getLogger().warning(res.getResultMessage());
+ int dialogRes = new MessageDialog().openWarningAndSelectionDialog
+ ("Failed to get host proxy setting."
+ + "\n" + res.getResultMessage()
+ + "\nContinue launching anyway ?");
+ if (dialogRes != SWT.OK) {
+ throw new VMLauncherException("User canceled launching VM.");
+ }
+ }
+
+ if (result == null) {
+ EMLogger.getLogger().warning("Can't find host proxy setting.");
+ EMLogger.getLogger().warning("check-net result : " + res.getResultMessage());
+ }
+
+ return result;
+ }
+
+}