}
});
}
+
+ public void setEnabled(boolean enabled) {
+ this.text.setEnabled(enabled);
+ }
public void setText(String text) {
this.text.setText(text);
public static final String LOCAL_HOST = "127.0.0.1"; //$NON-NLS-1$
+ public static final int IPv4_OCTET_NUMBER = 4;
+ public static final int MAX_OCTET_NUMBER = 255;
+ public static final int MIN_PORT_NUMBER = 1;
+ public static final int MAX_PORT_NUMBER = 65535;
+
/* extensions */
public static final String EXTENSION_LOG_CENTER = ".logc"; //$NON-NLS-1$
public static final String EXTENSION_LEAK_CHECK = ".leak"; //$NON-NLS-1$
package org.tizen.dynamicanalyzer.util;
+import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
+import java.util.List;
public class CommonUtil {
private static final String OS = getOS();
private static String pid = null;
- public static int executeCommand(String[] cmds) {
- int retValue = 0;
+ public static boolean executeCommand(String cmd, List<String> stdoutput, List<String> stderror) {
+ boolean bret = false;
Process process = null;
- if (null == cmds || cmds.length == 0) {
- retValue = -1;
- } else {
+ BufferedReader reader = null;
+ BufferedReader error = null;
+
+ if (cmd != null && !cmd.isEmpty()) {
try {
- process = Runtime.getRuntime().exec(cmds);
+ process = Runtime.getRuntime().exec(cmd);
if (process != null) {
process.waitFor();
- retValue = process.exitValue();
+ reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
+ error = new BufferedReader(new InputStreamReader(process.getErrorStream()));
+
+ String line = null;
+ if (stdoutput != null) {
+ while (null != (line = reader.readLine())) {
+ stdoutput.add(line);
+ }
+ }
+
+ if (stderror != null) {
+ while (null != (line = error.readLine())) {
+ stderror.add(line);
+ }
+ }
+
+ bret = true;
}
} catch (IOException e) {
e.printStackTrace();
if (process != null) {
process.destroy();
}
+ tryClose(reader, error);
+ }
+ }
+
+ return bret;
+ }
+
+ public static boolean executeCommand(String[] cmds) {
+ return executeCommand(cmds, null, null);
+ }
+
+ public static boolean executeCommand(String[] cmds, List<String> stdoutput,
+ List<String> stderror) {
+ if (cmds != null && cmds.length != 0) {
+ StringBuffer command = new StringBuffer();
+ for (int i = 0; i < cmds.length; i++) {
+ command.append(cmds[i]);
+ if (i != cmds.length - 1) {
+ command.append(" ");
+ }
}
+
+ return executeCommand(command.toString(), stdoutput, stderror);
}
- return retValue;
+ return false;
}
public static void tryClose(final Object... closeables) {
return pid;
}
+
+ public static String getNormalizedFilename(String original) {
+ // replace prohibited character to underbar
+ String result = original.replace('/', '_');
+ result = result.replace('\\', '_');
+ result = result.replace('?', '_');
+ result = result.replace('*', '_');
+ result = result.replace(':', '_');
+ result = result.replace('|', '_');
+ result = result.replace('\"', '_');
+ result = result.replace('<', '_');
+ result = result.replace('>', '_');
+
+ return result;
+ }
}
public final static String COMMON_EXECUTABLE = "_Common executable_";//$NON-NLS-1$
public final static String COMMON_EXECUTABLE_LABEL = "[Common executable]";//$NON-NLS-1$
+ public final static String REMOTE_DEVICE = "[Remote Device]";//$NON-NLS-1$
+
+ public final static int DEFAULT_DEVICE_PORT = 26101;
+
// file constants
public final static int F_SETLKW = 7;
Logger.debug("auto start : " + appid);
DeviceInfo device = DACommunicator.getDeviceByName(deviceName);
Global.setCurrentDeviceInfo(device);
+ DACommunicator.updateAppListFromTarget();
PackageInfo pkgInfo = DACommunicator.getPkgInfoByMainAppID(appid);
if (null == pkgInfo) {
public static long getReadelfSize() {
long ret = -1;
getUploadDataResult().clear();
- execShellCommand(AnalyzerShellCommands.CMD_UPLOAD_FILE_LIST,
- new MultiLineReceiver() {
- @Override
- public void processNewLines(String[] lines) {
- for (int i = 0; i < lines.length; i++) {
- getUploadDataResult().add(lines[i]);
- }
- }
- });
+ execShellCommand(AnalyzerShellCommands.CMD_UPLOAD_FILE_LIST, new MultiLineReceiver() {
+ @Override
+ public void processNewLines(String[] lines) {
+ for (int i = 0; i < lines.length; i++) {
+ getUploadDataResult().add(lines[i]);
+ }
+ }
+ });
if (getUploadDataResult().isEmpty()) {
return ret;
}
} else {
readelf += CommonConstants.X86_ARCH;
}
- String source = readelf + File.separator
- + AnalyzerConstants.READELF_BIN;
+ String source = readelf + File.separator + AnalyzerConstants.READELF_BIN;
File file = new File(source);
if (file.exists()) {
readelfSize = file.length();
return HostResult.ERR_FILE_IS_NOT_EXISTS;
}
- result = uploadFile(Global.getCurrentDeviceInfo()
- .getIDevice(), source, PathConstants.DA_REMOTE_PATH
- + AnalyzerConstants.READELF_BIN);
+ result = uploadFile(Global.getCurrentDeviceInfo().getIDevice(), source,
+ PathConstants.DA_REMOTE_PATH + AnalyzerConstants.READELF_BIN);
if (!result.isSuccess()) {
return result;
}
}
public static boolean isCurrentDeviceArmArch() {
- execHostCommand(AnalyzerShellCommands.CMD_IS_ARM_ARCH,
- new MultiLineReceiver() {
- @Override
- public void processNewLines(String[] lines) {
- if (lines[0].contains(CommonConstants.ARM_ARCH)) {
- isArch = true;
- } else {
- isArch = false;
- }
- }
- });
+ execHostCommand(AnalyzerShellCommands.CMD_IS_ARM_ARCH, new MultiLineReceiver() {
+ @Override
+ public void processNewLines(String[] lines) {
+ if (lines[0].contains(CommonConstants.ARM_ARCH)) {
+ isArch = true;
+ } else {
+ isArch = false;
+ }
+ }
+ });
return isArch;
}
execShellCommand(command, NullOutputReceiver.getInstance());
}
- public static void execShellCommand(String command,
- IShellOutputReceiver receiver) {
+ public static void execShellCommand(String command, IShellOutputReceiver receiver) {
DeviceInfo currentDevice = Global.getCurrentDeviceInfo();
if (null != currentDevice && isOnline(currentDevice.getIDevice())) {
try {
- currentDevice.getIDevice().executeShellCommand(command,
- receiver);
+ currentDevice.getIDevice().executeShellCommand(command, receiver);
} catch (TimeoutException e) {
e.printStackTrace();
} catch (SdbCommandRejectedException e) {
}
public static void execShellCommand(IDevice device, String command,
- IShellOutputReceiver receiver) throws TimeoutException,
- SdbCommandRejectedException, ShellCommandUnresponsiveException,
- IOException {
+ IShellOutputReceiver receiver) throws TimeoutException, SdbCommandRejectedException,
+ ShellCommandUnresponsiveException, IOException {
if (null != device && isOnline(device)) {
device.executeShellCommand(command, receiver);
}
}
- private static HostResult uploadFile(IDevice device, String source,
- String targetPath) {
+ private static HostResult uploadFile(IDevice device, String source, String targetPath) {
HostResult ret = HostResult.SUCCESS;
SyncResult result = push(device, source, targetPath);
if (null == result || !result.isOk()) {
}
public static SyncResult push(IDevice device, String local, String remote) {
- return push(device, local, remote,
- NullSyncProgressMonitor.getInstance());
+ return push(device, local, remote, NullSyncProgressMonitor.getInstance());
}
- public static SyncResult push(IDevice currentDevice, String local,
- String remote, ISyncProgressMonitor monitor) {
+ public static SyncResult push(IDevice currentDevice, String local, String remote,
+ ISyncProgressMonitor monitor) {
SyncResult result = null;
if (null != currentDevice && isOnline(currentDevice)) {
try {
return pull(remote, local, NullSyncProgressMonitor.getInstance());
}
- public static SyncResult pull(String remote, String local,
- ISyncProgressMonitor monitor) {
+ public static SyncResult pull(String remote, String local, ISyncProgressMonitor monitor) {
SyncResult result = null;
DeviceInfo currentDevice = Global.getCurrentDeviceInfo();
if (null != currentDevice && isOnline(currentDevice.getIDevice())) {
FileOutputStream fileOut = null;
try {
fileOut = new FileOutputStream(local);
- SyncService service = currentDevice.getIDevice()
- .getSyncService();
+ SyncService service = currentDevice.getIDevice().getSyncService();
if (null != service) {
- result = service.doPull(currentDevice.getIDevice()
- .getFileEntry(remote), fileOut, monitor, -1);
+ result = service.doPull(currentDevice.getIDevice().getFileEntry(remote),
+ fileOut, monitor, -1);
}
} catch (TimeoutException e) {
e.printStackTrace();
}
public static SyncResult pull(IDevice device, String local, String remote) {
- return pull(device, local, remote,
- NullSyncProgressMonitor.getInstance());
+ return pull(device, local, remote, NullSyncProgressMonitor.getInstance());
}
public static SyncResult pull(IDevice device, String remote, String local,
fileOut = new FileOutputStream(local);
SyncService service = device.getSyncService();
if (null != service) {
- result = service.doPull(device.getFileEntry(remote),
- fileOut, monitor, -1);
+ result = service.doPull(device.getFileEntry(remote), fileOut, monitor, -1);
}
} catch (TimeoutException e) {
e.printStackTrace();
long start = System.currentTimeMillis();
while ((System.currentTimeMillis() - start) < PORT_WAIT_TIME) {
try {
- execShellCommand(device,
- AnalyzerShellCommands.CMD_CAT_PORT_FILE,
+ execShellCommand(device, AnalyzerShellCommands.CMD_CAT_PORT_FILE,
new MultiLineReceiver() {
@Override
public void processNewLines(String[] lines) {
System.out.print("=");
}
}
-
+
Thread.sleep(50);
} catch (InterruptedException e) {
System.out.print("\n");
break;
}
}
-
+
System.out.print("\n");
- if(remotePort < 0) {
+ if (remotePort < 0) {
Logger.debug("!!port get failed!!");
} else {
Logger.debug("!!port get success!! : " + remotePort);
}
-
+
return remotePort;
}
if (null != currentDevice && isOnline(currentDevice.getIDevice())) {
try {
currentDevice.getIDevice().executeShellCommand(
- AnalyzerShellCommands.CMD_REMOVE
- + CommonConstants.SPACE + path,
+ AnalyzerShellCommands.CMD_REMOVE + CommonConstants.SPACE + path,
NullOutputReceiver.getInstance());
} catch (TimeoutException e) {
e.printStackTrace();
}
}
- public static void execHostCommand(String command,
- IShellOutputReceiver receiver) {
+ public static void execHostCommand(String command, IShellOutputReceiver receiver) {
DeviceInfo currentDevice = Global.getCurrentDeviceInfo();
if (null != currentDevice && isOnline(currentDevice.getIDevice())) {
try {
- currentDevice.getIDevice()
- .executeHostCommand(command, receiver);
+ currentDevice.getIDevice().executeHostCommand(command, receiver);
} catch (IOException e) {
e.printStackTrace();
}
}
}
- public static void execHostCommand(IDevice device, String command,
- IShellOutputReceiver receiver) {
+ public static void execHostCommand(IDevice device, String command, IShellOutputReceiver receiver) {
if (null != device && isOnline(device)) {
try {
device.executeHostCommand(command, receiver);
}
public static List<String> getApiMap(IDevice device) {
- String apiFilePath = PathManager.DA_TEMP_FOLDER_PATH + File.separator
- + device.getSerialNumber() + CommonConstants.UNDERBAR
- + AnalyzerConstants.API_NAME_FILE_NAME;
try {
device.becomeSuperUser(true);
} catch (TimeoutException e) {
e.printStackTrace();
}
- SyncResult res = CommunicatorUtils.pull(device,
- PathConstants.DA_API_MAP_PATH, apiFilePath);
+ String nDeviceName = CommonUtil.getNormalizedFilename(device.getSerialNumber());
+ String apiFilePath = PathManager.DA_TEMP_FOLDER_PATH + File.separator + nDeviceName
+ + CommonConstants.UNDERBAR + AnalyzerConstants.API_NAME_FILE_NAME;
+
+ SyncResult res = CommunicatorUtils.pull(device, PathConstants.DA_API_MAP_PATH, apiFilePath);
if (null != res && res.isOk()) {
Logger.debug("api map copying success!!");//$NON-NLS-1$
} else {
Logger.debug("file open failed...");
return null;
}
-
+
FileInputStream fis = null;
InputStreamReader isr = null;
BufferedReader reader = null;
String input = null;
while (null != (input = reader.readLine())) {
- String[] splitLine = input.trim().split(CommonConstants.SPACE,
- 2);
+ String[] splitLine = input.trim().split(CommonConstants.SPACE, 2);
apiMap.add(new String(splitLine[1]));
}
public static boolean isTargetEmulator() {
DeviceInfo device = Global.getCurrentDeviceInfo();
if (device != null) {
- if (device.getIDevice().getSerialNumber().contains(CommonConstants.EMULATOR)) {
- return true;
- }
+ return device.isEmulator();
}
return false;
}
updateToolbarDevice();
}
}
- if (null != Global.getCurrentDeviceInfo()
- && null != Global.getCurrentApplication()) {
+ if (null != Global.getCurrentDeviceInfo() && null != Global.getCurrentApplication()) {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
updateToolbarDevice();
}
}
- if (null != Global.getCurrentDeviceInfo()
- && null != Global.getCurrentApplication()) {
+ if (null != Global.getCurrentDeviceInfo() && null != Global.getCurrentApplication()) {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
public static String RANGE_PAGE;
public static String SNAPSHOT_ENABLE;
+
+ // string for dialog by toolbar combobox
+ public static String SELECT_PROCESS;
+ public static String REMOTE_DEVICE;
+ public static String IP;
+ public static String PORT;
+ public static String CONNECT;
+ public static String CONNECTING;
// tooltip text
public static String ABOUT;
RANGE_PAGE=Range page
SNAPSHOT_ENABLE=Take snapshot
+#String for dialog by toolbar combobox
+SELECT_PROCESS=Select Process
+REMOTE_DEVICE=Connect Remote Device
+IP=IP address
+PORT=Port number
+CONNECT=Connect
+CONNECTING=Connecting
+
#Setting menu
ABOUT=About Tizen Dynamic Analyzer [F1]
SETTING=Settings [F2]
setAppName(Global.getCurrentApplication().getMainApp().getLabel());
setPackageID(Global.getCurrentApplication().getPackageId());
- DeviceInfo deviceName = Global.getCurrentDeviceInfo();
+ DeviceInfo device = Global.getCurrentDeviceInfo();
+ String deviceSerial = null;
+ if (device != null) {
+ deviceSerial = device.getIDevice().getSerialNumber();
+ }
- if (null != deviceName && null != deviceName.getIDevice().getSerialNumber()
- && !deviceName.getIDevice().getSerialNumber().isEmpty()) {
- setDevice(Global.getCurrentDeviceInfo().getIDevice().getSerialNumber());
+ if (null != deviceSerial && !deviceSerial.isEmpty()) {
+ setDevice(deviceSerial);
} else {
setDevice(CommonConstants.SPACE);
}
import org.eclipse.swt.widgets.Shell;
import org.tizen.dynamicanalyzer.appearance.DesignConstants;
import org.tizen.dynamicanalyzer.common.Global;
+import org.tizen.dynamicanalyzer.nl.AnalyzerLabels;
import org.tizen.dynamicanalyzer.nl.WidgetLabels;
import org.tizen.dynamicanalyzer.resources.ColorResources;
import org.tizen.dynamicanalyzer.widgets.button.DACustomButton;
shell.setLayout(new FormLayout());
shell.setSize(446, 600);
shell.setBackground(ColorResources.DIALOG_BG_UPPER);
- shell.setText("Select process");
+ shell.setText(AnalyzerLabels.SELECT_PROCESS);
explorer = new ProcessExplorer(shell);
FormData data = new FormData();
--- /dev/null
+package org.tizen.dynamicanalyzer.ui.toolbar;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.tizen.dynamicanalyzer.appearance.DesignConstants;
+import org.tizen.dynamicanalyzer.common.AnalyzerConstants;
+import org.tizen.dynamicanalyzer.constant.CommonConstants;
+import org.tizen.dynamicanalyzer.nl.AnalyzerLabels;
+import org.tizen.dynamicanalyzer.nl.WidgetLabels;
+import org.tizen.dynamicanalyzer.resources.ColorResources;
+import org.tizen.dynamicanalyzer.widgets.animation.DAAnimationIcon;
+import org.tizen.dynamicanalyzer.widgets.button.DACustomButton;
+import org.tizen.dynamicanalyzer.widgets.button.DACustomButtonClickEventListener;
+import org.tizen.dynamicanalyzer.widgets.da.base.DAButton;
+import org.tizen.dynamicanalyzer.widgets.da.base.DAMessageBox;
+import org.tizen.dynamicanalyzer.widgets.da.base.DAText;
+import org.tizen.dynamicanalyzer.widgets.helper.ImageResources;
+
+public class RemoteDeviceDialog extends DAMessageBox {
+ private static final long THREAD_JOIN_WAITTIME = 1000;
+
+ private RemoteDeviceDialog self = null;
+
+ private DAText ipTextbox = null;
+ private DAText portTextbox = null;
+
+ private List<Image> progressImage = new ArrayList<Image>();
+ private DAAnimationIcon progressIcon = null;
+ private Label progressLabel = null;
+
+ private DACustomButton connectButton = null;
+ private DACustomButton cancelButton = null;
+
+ private String address = null;
+ private Thread managerThread = null;
+
+ public RemoteDeviceDialog(Shell parentShell) {
+ super(parentShell);
+
+ self = this;
+
+ shell.setLayout(new FormLayout());
+ shell.setSize(400, 192);
+ shell.setBackground(ColorResources.DIALOG_BG_UPPER);
+ shell.setText(AnalyzerLabels.REMOTE_DEVICE);
+
+ // IP label and textbox
+ Label ipText = new Label(shell, SWT.TRANSPARENT);
+ FormData data = new FormData();
+ data.top = new FormAttachment(0, 12);
+ data.left = new FormAttachment(0, 15);
+ data.height = 20;
+ data.width = 100;
+ ipText.setLayoutData(data);
+ ipText.setBackground(ColorResources.DIALOG_BG_UPPER);
+ ipText.setAlignment(SWT.LEFT);
+ ipText.setForeground(ColorResources.BLACK);
+ ipText.setText(AnalyzerLabels.IP);
+
+ ipTextbox = new DAText(shell, SWT.SINGLE);
+ data = new FormData();
+ data.top = new FormAttachment(0, 12);
+ data.left = new FormAttachment(ipText, 12);
+ data.height = 20;
+ data.width = 250;
+ ipTextbox.setLayoutData(data);
+ ipTextbox.setBackground(ColorResources.VIEW_BG_COLOR);
+ ipTextbox.getControl().addKeyListener(ipTextboxListener);
+
+ // Port label and textbox
+ Label portText = new Label(shell, SWT.TRANSPARENT);
+ data = new FormData();
+ data.top = new FormAttachment(ipText, 12);
+ data.left = new FormAttachment(0, 15);
+ data.height = 20;
+ data.width = 100;
+ portText.setLayoutData(data);
+ portText.setBackground(ColorResources.DIALOG_BG_UPPER);
+ portText.setAlignment(SWT.LEFT);
+ portText.setForeground(ColorResources.BLACK);
+ portText.setText(AnalyzerLabels.PORT);
+
+ portTextbox = new DAText(shell, SWT.SINGLE);
+ data = new FormData();
+ data.top = new FormAttachment(ipText, 12);
+ data.left = new FormAttachment(portText, 12);
+ data.height = 20;
+ data.width = 250;
+ portTextbox.setLayoutData(data);
+ portTextbox.setBackground(ColorResources.VIEW_BG_COLOR);
+ portTextbox.getControl().addKeyListener(portTextboxListener);
+
+ // progress Icon and text
+ progressImage.add(ImageResources.STOP_PROGRESS_LOADING_01);
+ progressImage.add(ImageResources.STOP_PROGRESS_LOADING_02);
+ progressImage.add(ImageResources.STOP_PROGRESS_LOADING_03);
+ progressImage.add(ImageResources.STOP_PROGRESS_LOADING_04);
+ progressImage.add(ImageResources.STOP_PROGRESS_LOADING_05);
+ progressImage.add(ImageResources.STOP_PROGRESS_LOADING_06);
+ progressImage.add(ImageResources.STOP_PROGRESS_LOADING_07);
+ progressImage.add(ImageResources.STOP_PROGRESS_LOADING_08);
+
+ progressIcon = new DAAnimationIcon(shell, SWT.NONE, progressImage);
+ data = new FormData();
+ data.top = new FormAttachment(portText, 16);
+ data.left = new FormAttachment(30, 10);
+ data.height = 24;
+ data.width = 24;
+ progressIcon.setLayoutData(data);
+ progressIcon.setVisible(false);
+
+ progressLabel = new Label(shell, SWT.TRANSPARENT);
+ data = new FormData();
+ data.top = new FormAttachment(portText, 20);
+ data.left = new FormAttachment(progressIcon, 12);
+ data.height = 20;
+ data.width = 150;
+ progressLabel.setLayoutData(data);
+ progressLabel.setBackground(ColorResources.DIALOG_BG_UPPER);
+ progressLabel.setAlignment(SWT.LEFT);
+ progressLabel.setForeground(ColorResources.BLACK);
+ progressLabel.setText(AnalyzerLabels.CONNECTING);
+ progressLabel.setVisible(false);
+
+ // connect and cancel button
+ Composite buttonComp = new Composite(shell, SWT.NONE);
+ buttonComp.setLayout(new FormLayout());
+ buttonComp.setBackground(ColorResources.DIALOG_BG_LOWER);
+
+ buttonComp.addPaintListener(new PaintListener() {
+
+ @Override
+ public void paintControl(PaintEvent e) {
+ Composite comp = (Composite) e.widget;
+ Rectangle rect = comp.getClientArea();
+ e.gc.setForeground(ColorResources.DIALOG_SUNKEN_1);
+ e.gc.drawLine(rect.x, rect.y, rect.x + rect.width, rect.y);
+ e.gc.setForeground(ColorResources.DIALOG_SUNKEN_2);
+ e.gc.drawLine(rect.x, rect.y + 1, rect.x + rect.width, rect.y + 1);
+ }
+ });
+
+ FormData compData = new FormData();
+ compData.top = new FormAttachment(100, -50);
+ compData.left = new FormAttachment(0, 0);
+ compData.right = new FormAttachment(100, 0);
+ compData.bottom = new FormAttachment(100, 0);
+ buttonComp.setLayoutData(compData);
+
+ connectButton = new DAButton(buttonComp, SWT.NONE);
+ data = new FormData();
+ data.top = new FormAttachment(0, 11);
+ data.left = new FormAttachment(50, -DesignConstants.DA_BUTTON_WIDTH - 4);
+ data.height = DesignConstants.DA_BUTTON_HEIGHT;
+ data.width = DesignConstants.DA_BUTTON_WIDTH;
+ connectButton.setLayoutData(data);
+ connectButton.setText(AnalyzerLabels.CONNECT);
+ connectButton.addClickListener(connectButtonListener);
+ connectButton.setButtonEnabled(false);
+
+ cancelButton = new DAButton(buttonComp, SWT.NONE);
+ data = new FormData();
+ data.top = new FormAttachment(0, 11);
+ data.left = new FormAttachment(50, 4);
+ data.height = DesignConstants.DA_BUTTON_HEIGHT;
+ data.width = DesignConstants.DA_BUTTON_WIDTH;
+ cancelButton.setLayoutData(data);
+ cancelButton.setText(WidgetLabels.CANCEL);
+ cancelButton.addClickListener(cancelButtonListener);
+ }
+
+ private DACustomButtonClickEventListener connectButtonListener = new DACustomButtonClickEventListener() {
+
+ @Override
+ public void handleClickEvent(DACustomButton button) {
+ String ip = ipTextbox.getText();
+ String port = portTextbox.getText();
+
+ if (ip.isEmpty()) {
+ return;
+ }
+
+ if (port.isEmpty()) {
+ port = String.valueOf(AnalyzerConstants.DEFAULT_DEVICE_PORT);
+ }
+
+ address = ip + ":" + port;
+
+ // show progress and try to connect
+ connectButton.setButtonEnabled(false);
+ ipTextbox.setEnabled(false);
+ portTextbox.setEnabled(false);
+
+ progressIcon.setVisible(true);
+ progressLabel.setVisible(true);
+ progressIcon.start();
+
+ // start RemoteDeviceManager
+ Thread managerThread = new Thread(new RemoteDeviceManager(self));
+ managerThread.start();
+ }
+ };
+
+ private DACustomButtonClickEventListener cancelButtonListener = new DACustomButtonClickEventListener() {
+
+ @Override
+ public void handleClickEvent(DACustomButton button) {
+ address = null;
+
+ if (managerThread != null && managerThread.isAlive()) {
+ managerThread.interrupt();
+ try {
+ managerThread.join(THREAD_JOIN_WAITTIME);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ managerThread = null;
+
+ setConnectionResult(false);
+ } else {
+ shell.close();
+ }
+ }
+ };
+
+ private KeyListener ipTextboxListener = new KeyListener() {
+
+ @Override
+ public void keyReleased(KeyEvent e) {
+ if (!checkValidIP(ipTextbox.getText())) {
+ connectButton.setButtonEnabled(false);
+ } else {
+ connectButton.setButtonEnabled(true);
+ }
+ }
+
+ @Override
+ public void keyPressed(KeyEvent e) {
+
+ }
+ };
+
+ private KeyListener portTextboxListener = new KeyListener() {
+
+ @Override
+ public void keyReleased(KeyEvent e) {
+ if (!checkValidPort(portTextbox.getText())) {
+ connectButton.setButtonEnabled(false);
+ } else {
+ connectButton.setButtonEnabled(true);
+ }
+ }
+
+ @Override
+ public void keyPressed(KeyEvent e) {
+
+ }
+ };
+
+ private boolean checkValidIP(String ipaddr) {
+ String[] splitstr = ipaddr.split("\\.");
+ if (splitstr == null || splitstr.length != CommonConstants.IPv4_OCTET_NUMBER) {
+ return false;
+ }
+
+ for (int i = 0; i < CommonConstants.IPv4_OCTET_NUMBER; i++) {
+ int classnum = Integer.parseInt(splitstr[i]);
+ if (classnum < 0 || classnum > CommonConstants.MAX_OCTET_NUMBER) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ private boolean checkValidPort(String port) {
+ if (port.isEmpty()) {
+ return true;
+ }
+
+ int portnum = Integer.parseInt(port);
+
+ if (portnum < CommonConstants.MIN_PORT_NUMBER || portnum > CommonConstants.MAX_PORT_NUMBER) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ public String getAddress() {
+ return address;
+ }
+
+ public void setConnectionResult(boolean bresult) {
+ if (bresult) {
+ // if succeeded to connect remote device
+ result = AnalyzerConstants.SUCCESS;
+ shell.close();
+ } else {
+ // if failed to connect remote device
+ address = null;
+
+ progressIcon.setVisible(false);
+ progressLabel.setVisible(false);
+
+ connectButton.setButtonEnabled(true);
+ ipTextbox.setEnabled(true);
+ portTextbox.setEnabled(true);
+ }
+ }
+}
--- /dev/null
+package org.tizen.dynamicanalyzer.ui.toolbar;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.swt.widgets.Display;
+import org.tizen.dynamicanalyzer.common.path.PathManager;
+import org.tizen.dynamicanalyzer.util.CommonUtil;
+
+public class RemoteDeviceManager implements Runnable {
+ private static final String CMD_SDB_CONNECT = PathManager.SDB_PATH + " connect ";
+ private static final String CMD_SDB_DEVICE = PathManager.SDB_PATH + " devices";
+ private static final String CONNECTED_STR1 = "connected";
+ private static final String CONNECTED_STR2 = "already";
+
+ private static final long SLEEPTIME = 50;
+ private static final long MAX_WAITTIME = 5000;
+
+ private RemoteDeviceDialog parentDialog = null;
+
+ public RemoteDeviceManager(RemoteDeviceDialog dialog) {
+ parentDialog = dialog;
+ }
+
+ @Override
+ public void run() {
+ boolean bret = false;
+
+ // execute sdb connect command
+ String address = parentDialog.getAddress();
+ if (address != null) {
+ String cmd = CMD_SDB_CONNECT + address;
+
+ List<String> outputlines = new ArrayList<String>();
+ if (CommonUtil.executeCommand(cmd, outputlines, null) && !outputlines.isEmpty()) {
+ for (String line : outputlines) {
+ if (line.startsWith(CONNECTED_STR1) || line.contains(CONNECTED_STR2)) {
+ bret = true;
+ break;
+ }
+ }
+ }
+
+ // wait for device is online
+ if (bret) {
+ bret = false;
+ cmd = CMD_SDB_DEVICE;
+ long starttime = System.currentTimeMillis();
+ do {
+ outputlines.clear();
+ if (CommonUtil.executeCommand(cmd, outputlines, null) && !outputlines.isEmpty()) {
+ for (String line : outputlines) {
+ if (line.startsWith(address)) {
+ if (line.contains("device")) {
+ bret = true;
+ break;
+ }
+ }
+ }
+ }
+
+ try {
+ Thread.sleep(SLEEPTIME);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ break;
+ }
+ } while (System.currentTimeMillis() < starttime + MAX_WAITTIME);
+ }
+ }
+
+ final boolean fret = bret;
+ // set result to dialog
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ parentDialog.setConnectionResult(fret);
+ }
+ });
+ }
+}
DeviceInfo oldDevInfo = Global.getCurrentDeviceInfo();
if (oldDevInfo != null)
oldDeviceName = oldDevInfo.getIDevice().getSerialNumber();
- String serial = combo.getText();
+ final String serial = combo.getText();
- if (serial != null && !serial.equals(oldDeviceName)) {
- Global.setCurrentDeviceInfo(DACommunicator.setSelectedDeviceBySerial(serial));
- if (null != serial && !serial.isEmpty()) {
+ if (serial == null || serial.isEmpty()) {
+ Global.setCurrentDeviceInfo(null);
+ } else {
+ if (serial.equals(AnalyzerConstants.REMOTE_DEVICE)) {
+ final String oldDevName = oldDeviceName;
+
+ Display.getDefault().asyncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ String newDevice = null;
+ Shell shell = WorkbenchUtil.getWorkbenchWindow().getShell();
+ RemoteDeviceDialog pdialog = new RemoteDeviceDialog(shell);
+ pdialog.open();
+ String address = pdialog.getAddress();
+ if (address != null && !address.isEmpty()) {
+ newDevice = address;
+ } else {
+ newDevice = null;
+ }
+
+ if (newDevice == null) {
+ if (oldDevName == null)
+ deviceCombo.setText(CommonConstants.EMPTY);
+ else
+ deviceCombo.setText(oldDevName);
+ } else {
+ deviceCombo.setText(newDevice);
+ }
+
+ if (newDevice != null && !newDevice.isEmpty()) {
+ DACommunicator.setSelectedDeviceBySerial(serial);
+ initAppCombo();
+ setRepalyButtonEnable(true);
+ }
+ }
+ });
+
+ } else if (!serial.equals(oldDeviceName)) {
+ DACommunicator.setSelectedDeviceBySerial(serial);
initAppCombo();
+ setRepalyButtonEnable(true);
}
- setRepalyButtonEnable(true);
}
}
});
setToolbarStartStopState(true);
- if (null == DACommunicator.getDevices() || DACommunicator.getDevices().isEmpty()) {
- deviceCombo.setEnabled(false);
- }
+ // commented because REMOVE_DEVICE is added
+ // if (null == DACommunicator.getDevices() || DACommunicator.getDevices().isEmpty()) {
+ // deviceCombo.setEnabled(false);
+ // }
if (!deviceCombo.isEnabled() || null == Global.getCurrentDeviceInfo()) {
appCombo.setEnabled(false);
setToolbarStartStopState(true);
- if (null == DACommunicator.getDevices() || DACommunicator.getDevices().isEmpty()) {
- deviceCombo.setEnabled(false);
- }
+ // commented because REMOVE_DEVICE is added
+ // if (null == DACommunicator.getDevices() || DACommunicator.getDevices().isEmpty())
+ // {
+ // deviceCombo.setEnabled(false);
+ // }
if (!deviceCombo.isEnabled() || null == Global.getCurrentDeviceInfo()) {
appCombo.setEnabled(false);
deviceCombo.initCombo();
if (null == items || items.isEmpty()) {
deviceCombo.add(CommonConstants.EMPTY);
+ deviceCombo.add(AnalyzerConstants.REMOTE_DEVICE);
deviceCombo.select(0);
appCombo.initCombo();
appCombo.setEnabled(false);
selIndex = i;
}
}
+ deviceCombo.add(AnalyzerConstants.REMOTE_DEVICE);
deviceCombo.select(selIndex);
Global.setCurrentDeviceInfo(DACommunicator.getDeviceByName(items.get(selIndex)));
}
List<PackageInfo> pkgList = new ArrayList<PackageInfo>();
-
+
// TODO : reconstruct real app list for app combo
// relation between package and app?
for (Map.Entry<String, PackageInfo> entry : pkgInfos.entrySet()) {
});
addToAppCombo(pkgList);
-
+
return true;
}
for (int i = 0; i < size; i++) {
deviceCombo.add(devices.get(i).getIDevice().getSerialNumber());
}
+ deviceCombo.add(AnalyzerConstants.REMOTE_DEVICE);
+
int index = deviceCombo.getItems().indexOf(selectedDevice);
if (index >= 0) {
deviceCombo.setText(selectedDevice);
package org.tizen.dynamicanalyzer.utils;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
String[] command = new String[] { toolPath, RpmUtil.getDebugInfoOption(), "-d",
targetpath, rpmpath };
- BufferedReader reader = null;
- BufferedReader error = null;
-
- try {
- Runtime rt = Runtime.getRuntime();
- Process process = rt.exec(command);
- process.waitFor();
- reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
-
- String line = null;
- int lineCount = 0;
- while (null != (line = reader.readLine())) {
- lineCount++;
- if (lineCount == 1) {
- Logger.debug("CHANGE DIR : " + line);
- } else {
- Logger.debug("EXTRACE RPM : " + line);
+ List<String> outputlines = new ArrayList<String>();
+ List<String> errorlines = new ArrayList<String>();
+ if (CommonUtil.executeCommand(command, outputlines, errorlines)) {
+ int linecount = outputlines.size();
+ if (linecount < 2) {
+ Logger.debug("debug info file extract failed...");
+ if (errorlines.size() != 0) {
+ Logger.debug(errorlines.get(0));
}
- }
-
- if (lineCount < 2) {
- error = new BufferedReader(new InputStreamReader(process.getErrorStream()));
- String errorStr = error.readLine();
- Logger.debug("debug info file extract failed... : " + errorStr);
} else {
bret = true;
}
- } catch (IOException e) {
- e.printStackTrace();
- } catch (InterruptedException e) {
- e.printStackTrace();
- } finally {
- CommonUtil.tryClose(reader, error);
}
}
if (null != rpmpath) {
String toolPath = PathManager.getDebugInfoScript();
String[] command = new String[] { toolPath, RpmUtil.getDebugInfoOption(), "-l", rpmpath };
- BufferedReader reader = null;
- try {
- Runtime rt = Runtime.getRuntime();
- Process process = rt.exec(command);
- process.waitFor();
- reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
+ List<String> outputlines = new ArrayList<String>();
+
+ if (CommonUtil.executeCommand(command, outputlines, null)) {
ret = new ArrayList<String>();
- String line = null;
- while (null != (line = reader.readLine())) {
+ for (String line : outputlines) {
if (line.startsWith("./")) {
line = line.substring(1);
ret.add(line);
}
}
- } catch (IOException e) {
- e.printStackTrace();
- } catch (InterruptedException e) {
- e.printStackTrace();
- } finally {
- CommonUtil.tryClose(reader);
}
}