From d3e4441be8c9fa9e6892e8a07fe63abb5955db0f Mon Sep 17 00:00:00 2001 From: Maria Guseva Date: Sun, 22 May 2016 16:01:45 +0300 Subject: [PATCH] SRADA-216: Extracted general functionality from Toolbar.onAppSelected() method. Exctracted funtionality is not related to the Toolbar and is supposed to be used in both CLI and GUI modes. The extracted methods are moved to PackageInfo class as funtionality relates to processing of PackageInfo instances. * PackageInfo.getProcessInformation(), .getBinaryInformation() - new methods. Change-Id: I8ce9f33448679956226697bc669f7bc0ed4d045f --- .../tizen/dynamicanalyzer/project/PackageInfo.java | 89 ++++++++++++++++++++++ .../tizen/dynamicanalyzer/ui/toolbar/Toolbar.java | 63 +-------------- 2 files changed, 91 insertions(+), 61 deletions(-) diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/PackageInfo.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/PackageInfo.java index adad3bd..937a347 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/PackageInfo.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/PackageInfo.java @@ -27,6 +27,16 @@ package org.tizen.dynamicanalyzer.project; import java.util.ArrayList; import java.util.List; +import java.util.Map; + +import org.tizen.dynamicanalyzer.common.AnalyzerConstants; +import org.tizen.dynamicanalyzer.common.DAResult; +import org.tizen.dynamicanalyzer.common.DAResult.ErrorCode; +import org.tizen.dynamicanalyzer.communicator.DACommunicator; +import org.tizen.dynamicanalyzer.communicator.UnsupportedProtocolException; +import org.tizen.dynamicanalyzer.handlers.UIActionHolder; +import org.tizen.dynamicanalyzer.nl.UserErrorWarningLabels; +import org.tizen.dynamicanalyzer.util.Logger; public class PackageInfo { public static final String PKGTYPE = "pkg_type"; @@ -125,4 +135,83 @@ public class PackageInfo { public void setPossibleToTrace(boolean isPossibleToTrace) { this.isPossibleToTrace = isPossibleToTrace; } + + /** + * Get process information and set flag if it's possible to be traced. + * + * @return list of paths to binaries for running processes + */ + public List getProcessInformation() { + List binPaths = new ArrayList(); + String packageID = getPackageId(); + if (AnalyzerConstants.RUNNING_PROCESS.equals(packageID)) { + Map selProcess = getMainApp() + .getRunningProcesses(); + if (selProcess == null) { + Logger.warning("There is no selected process"); + setPossibleToTrace(false); + } else { + for (Map.Entry entry : selProcess.entrySet()) { + binPaths.add(entry.getValue()); + } + setPossibleToTrace(true); + } + } else if (AnalyzerConstants.WITHOUT_EXECUTABLE.equals(packageID)) { + // do not send binary info message for system wide trace + // do nothing + } else if (AnalyzerConstants.COMMON_EXECUTABLE.equals(packageID)) { + String executablePath = getMainApp().getExecBinaryPath(); + if (null == executablePath || executablePath.isEmpty()) { + Logger.warning("There is no application in selected package"); + setPossibleToTrace(false); + } else { + binPaths.add(executablePath); + setPossibleToTrace(true); + } + } else { // normal application or common executable + List apps = getAppInfos(); + if (null == apps) { + Logger.warning("There is no application in selected package"); + setPossibleToTrace(false); + } else { + for (AppInfo app : apps) { + binPaths.add(app.getExecBinaryPath()); + } + setPossibleToTrace(true); + } + } + return binPaths; + } + + /** + * Get binary information of given applications and set flag if it's + * possible to be traced. + * + * @param binPaths list of paths to binaries to be checked + */ + public void getBinaryInformation(List binPaths) { + if (!binPaths.isEmpty()) { + DAResult hr = new DAResult(ErrorCode.ERR_BIN_INFO_GET_FAIL); + try { + hr = DACommunicator.getBinaryInformation(binPaths); + } catch (InterruptedException e) { + Logger.warning("Interrupted during getting binary information about application binary"); + } catch (UnsupportedProtocolException e) { + Logger.warning("Message to get binary information is not supported by communicator"); + } + + if (hr.equals(ErrorCode.ERR_BY_SECURITY)) { + UIActionHolder.getUIAction().showWarning( + UserErrorWarningLabels.ERROR_APP_SELECT_BY_SECURITY); + Logger.warning("Failed to get binary info by security reason"); + setPossibleToTrace(false); + } else if (!hr.isSuccess()) { + UIActionHolder.getUIAction().showWarning(hr); + Logger.warning("Failed to get binary info : " + hr.getMessage()); + setPossibleToTrace(false); + } else { + setPossibleToTrace(true); + } + } + } } diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/Toolbar.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/Toolbar.java index fbf733a..0137378 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/Toolbar.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/Toolbar.java @@ -1323,68 +1323,9 @@ public enum Toolbar { progressDlg.setValues("Getting process information", 30); if (pkg != null) { - List binPaths = new ArrayList(); - - String packageID = pkg.getPackageId(); - if (AnalyzerConstants.RUNNING_PROCESS.equals(packageID)) { - Map selProcess = pkg.getMainApp().getRunningProcesses(); - if (selProcess == null) { - Logger.warning("There is no selected process"); - pkg.setPossibleToTrace(false); - } else { - for (Map.Entry entry : selProcess.entrySet()) { - binPaths.add(entry.getValue()); - } - pkg.setPossibleToTrace(true); - } - } else if (AnalyzerConstants.WITHOUT_EXECUTABLE.equals(packageID)) { - // do not send binary info message for system wide trace - // do nothing - } else if (AnalyzerConstants.COMMON_EXECUTABLE.equals(packageID)) { - String executablePath = pkg.getMainApp().getExecBinaryPath(); - if (null == executablePath || executablePath.isEmpty()) { - Logger.warning("There is no application in selected package"); - pkg.setPossibleToTrace(false); - } else { - binPaths.add(executablePath); - pkg.setPossibleToTrace(true); - } - } else { // normal application or common executable - List apps = pkg.getAppInfos(); - if (null == apps) { - Logger.warning("There is no application in selected package"); - pkg.setPossibleToTrace(false); - } else { - for (AppInfo app : apps) { - binPaths.add(app.getExecBinaryPath()); - } - pkg.setPossibleToTrace(true); - } - } - + List binPaths = pkg.getProcessInformation(); progressDlg.setValues("Getting binary from device", 70); - if (!binPaths.isEmpty()) { - DAResult hr = new DAResult(ErrorCode.ERR_BIN_INFO_GET_FAIL); - try { - hr = DACommunicator.getBinaryInformation(binPaths); - } catch (InterruptedException e) { - Logger.warning("Interrupted during getting binary information about application binary"); - } catch (UnsupportedProtocolException e) { - Logger.warning("Message to get binary information is not supported by communicator"); - } - - if (hr.equals(ErrorCode.ERR_BY_SECURITY)) { - UIActionHolder.getUIAction().showWarning(UserErrorWarningLabels.ERROR_APP_SELECT_BY_SECURITY); - Logger.warning("Failed to get binary info by security reason"); - pkg.setPossibleToTrace(false); - } else if (!hr.isSuccess()) { - UIActionHolder.getUIAction().showWarning(hr); - Logger.warning("Failed to get binary info : " + hr.getMessage()); - pkg.setPossibleToTrace(false); - } else { - pkg.setPossibleToTrace(true); - } - } + pkg.getBinaryInformation(binPaths); } progressDlg.setValues("Done", 100); if (progressDlg != null) { -- 2.7.4