INTERNEL: change the categorization method for app combo list 33/23933/1
authorgreatim <jaewon81.lim@samsung.com>
Fri, 4 Jul 2014 11:27:37 +0000 (20:27 +0900)
committergreatim <jaewon81.lim@samsung.com>
Fri, 4 Jul 2014 11:27:37 +0000 (20:27 +0900)
change the categorizatino method for app list from target, and app combo list

Change-Id: I728ba9659a3b9b01707f8c64cbe6a470ce6d5d94
Signed-off-by: greatim <jaewon81.lim@samsung.com>
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/communicator/DACommunicator.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/communicator/Communicator30.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/ToolbarArea.java

index edf4b15..c6ce613 100644 (file)
@@ -292,10 +292,10 @@ public class DACommunicator {
                                                                                .contains(AppInfo.APPTYPE_WEB) || appInfo
                                                                .getInfo(AppInfo.APPTYPE_INDEX).contains(
                                                                                AppInfo.APPTYPE_CAPP))) {
-//                                             && appInfo.getInfo(AppInfo.MULTIPLE_INDEX).equals(
-//                                                             AppInfo.FLAG_ZERO)
-//                                             && appInfo.getInfo(AppInfo.NODISPLAY_INDEX).equals(
-//                                                             AppInfo.FLAG_ZERO)) {
+                                       // && appInfo.getInfo(AppInfo.MULTIPLE_INDEX).equals(
+                                       // AppInfo.FLAG_ZERO)
+                                       // && appInfo.getInfo(AppInfo.NODISPLAY_INDEX).equals(
+                                       // AppInfo.FLAG_ZERO)) {
                                        String pkgId = appInfo.getInfo(AppInfo.PACKAGE_INDEX);
                                        String appId = appInfo.getInfo(AppInfo.APPID_INDEX);
 
@@ -318,7 +318,18 @@ public class DACommunicator {
                                appInfoHash.remove(appId);
                        }
                }
-               return appInfoList;
+
+               // TODO : reconstruct real app list for app combo
+               // relation between package and app?
+               List<AppInfo> appcomboList = new ArrayList<AppInfo>();
+               for (AppInfo app : appInfoList) {
+                       if (app.getInfo(AppInfo.APPID_INDEX).equals(
+                                       app.getInfo(AppInfo.PACKAGE_INDEX))) {
+                               appcomboList.add(app);
+                       }
+               }
+
+               return appcomboList;
        }
 
        private static boolean isUnittest(String pkgId) {
@@ -524,7 +535,7 @@ public class DACommunicator {
                                        }
                                }
                        }
-                       
+
                        Display.getDefault().syncExec(new Runnable() {
                                @Override
                                public void run() {
@@ -536,7 +547,7 @@ public class DACommunicator {
                @Override
                public void onConnected(IDevice device) {
                        // It called when dynamic-analyzer start, only one time
-                       
+
                        Display.getDefault().syncExec(new Runnable() {
                                @Override
                                public void run() {
@@ -564,7 +575,7 @@ public class DACommunicator {
                                        }
                                });
                        }
-                       
+
                        Display.getDefault().syncExec(new Runnable() {
                                @Override
                                public void run() {
@@ -583,7 +594,7 @@ public class DACommunicator {
                                        ToolbarArea.getInstance().setMainControlEnablement(false);
                                }
                        });
-                       
+
                        DA_LOG.debug("device changed : " + device.getSerialNumber() + "   "
                                        + changeMask);
                        if (1 == changeMask) {
@@ -608,7 +619,7 @@ public class DACommunicator {
                        } else {
                                DA_LOG.debug("device changed type :" + changeMask);
                        }
-                       
+
                        Display.getDefault().syncExec(new Runnable() {
                                @Override
                                public void run() {
@@ -616,7 +627,7 @@ public class DACommunicator {
                                }
                        });
                }
-               
+
        };
 
        public static void updateToolbarDevice() {
index 42ae018..eb89f22 100755 (executable)
@@ -298,8 +298,22 @@ public class Communicator30 extends BaseCommunicator {
                        if (app.getAppId().contains("_AppControl")) {
                                continue;
                        }
+
+                       // TODO : make new protocol field or message for launched app and
+                       // instrucmented app
+                       if (!app.getAppId().equals(app.getPackageId())) {
+                               continue;
+                       }
+
+                       BinaryInfo binInfo = app.getMainBinaryInfo();
+                       if (binInfo.getTempBinaryPath() == null) {
+                               // this means the app binary does not exist in device
+                               continue;
+                       }
+
                        ApplicationInst appInst = new ApplicationInst();
 
+                       // TODO : add more app type or launch type (core app and efl app)
                        String appType = app.getInfo(AppInfo.APPTYPE_INDEX);
                        if (appType.contains(AppInfo.APPTYPE_CPP)) {
                                appInst.setApplicationType(ApplicationInst.APPTYPE_TIZEN);
@@ -307,6 +321,9 @@ public class Communicator30 extends BaseCommunicator {
                        } else if (appType.contains(AppInfo.APPTYPE_WEB)) {
                                appInst.setApplicationType(ApplicationInst.APPTYPE_WEB);
                                appInst.setApplicationId(app.getAppId());
+                       } else if (appType.contains(AppInfo.APPTYPE_CAPP)) {
+                               appInst.setApplicationType(ApplicationInst.APPTYPE_TIZEN);
+                               appInst.setApplicationId(app.getAppId());
                        } else {
                                appInst.setApplicationType(ApplicationInst.APPTYPE_COMMON_EXEC);
                                appInst.setApplicationId(CommonConstants.EMPTY);
@@ -314,7 +331,6 @@ public class Communicator30 extends BaseCommunicator {
 
                        appInst.setExecutablePath(app.getExecPath());
                        DA_LOG.debug("Set execute path : " + app.getExecPath());
-                       BinaryInfo binInfo = app.getMainBinaryInfo();
                        List<AddrSymbolPair> symbols = app.getSymbols(binInfo
                                        .getTempBinaryPath());
                        List<FunctionInst> functionInstList = appInst.getFunctionInstList();
@@ -399,84 +415,80 @@ public class Communicator30 extends BaseCommunicator {
                        index += INT_SIZE;
                        localBinaryPath = ByteUtil.getString(payload, index).trim();
                        index += ByteUtil.getStringLength(payload, index);
-                       String[] splitLocalBinaryPath = localBinaryPath
-                                       .split(CommonConstants.SLASH);
+                       String md5sum = ByteUtil.getString(payload, index);
+                       index += ByteUtil.getStringLength(payload, index);
+
+                       binInfo.setType(binaryType);
+                       binInfo.setMd5sumValue(md5sum);
                        binInfo.setLocalBinaryPath(localBinaryPath);
-                       // init source binary path
-                       binInfo.setTempBinaryPath(localBinaryPath);
-                       if (splitLocalBinaryPath.length == 0
-                                       || splitLocalBinaryPath.length < 3) {
-                               localBinaryPath = PathManager.DA_TEMP_FOLDER_PATH
-                                               + File.separator + getFileName(targetPath);
-                               result = pullTheFile(targetPath, localBinaryPath);
-                               if (result.isSuccess()) {
-                                       binInfo.setTempBinaryPath(localBinaryPath);
-                               }
 
-                               String md5sum = ByteUtil.getString(payload, index);
-                               index += ByteUtil.getStringLength(payload, index);
-                               binInfo.setType(binaryType);
-                               binInfo.setTempBinaryPath(localBinaryPath);
-                               binInfo.setMd5sumValue(md5sum);
-                               continue;
-                       } else {
-                               String md5sum = ByteUtil.getString(payload, index);
-                               index += ByteUtil.getStringLength(payload, index);
-                               binInfo.setType(binaryType);
-                               binInfo.setTempBinaryPath(localBinaryPath);
-                               binInfo.setMd5sumValue(md5sum);
-                       }
+                       String[] splitLocalBinaryPath = localBinaryPath
+                                       .split(CommonConstants.SLASH);
 
-                       // host has no binary file - pull binary file from target
-                       // change binary file path of host
-                       File binFile = new File(localBinaryPath);
-                       if (!binFile.exists()) {
+                       // check local binary path validation
+                       if (splitLocalBinaryPath.length < 3) {
                                localBinaryPath = PathManager.DA_TEMP_FOLDER_PATH
                                                + File.separator + getFileName(targetPath);
                                result = pullTheFile(targetPath, localBinaryPath);
                                if (result.isSuccess()) {
                                        binInfo.setTempBinaryPath(localBinaryPath);
                                }
-                               continue;
-                       }
-
-                       String localHashCode = null;
-                       try {
-                               Runtime rt = Runtime.getRuntime();
-                               Process process = rt.exec(new String[] {
-                                               AnalyzerShellCommands.CMD_MD_5_SUM, localBinaryPath });
-                               process.waitFor();
-                               BufferedReader reader = new BufferedReader(
-                                               new InputStreamReader(process.getInputStream()));
-                               BufferedReader error = new BufferedReader(
-                                               new InputStreamReader(process.getErrorStream()));
-                               String line = reader.readLine();
-                               String errorStr = error.readLine();
-                               if (null == line) {
-                                       DA_LOG.debug("host md5sum get failed : " + errorStr);
-                                       result = HostResult.ERR_BIN_INFO_GET_FAIL;
-                                       continue;
-                               }
-                               String[] splitResult = line.trim().split(CommonConstants.SPACE);
-                               localHashCode = new String(splitResult[0]);
-                       } catch (IOException e) {
-                               e.printStackTrace();
-                               result = HostResult.ERR_BIN_INFO_GET_FAIL;
-                               continue;
-                       } catch (InterruptedException e) {
-                               e.printStackTrace();
-                               return HostResult.ERR_BIN_INFO_GET_FAIL;
-                       }
-
-                       String targetHashCode = binInfo.getMd5sumValue();
-                       if (0 != targetHashCode.compareTo(localHashCode)) {
-                               localBinaryPath = PathManager.DA_TEMP_FOLDER_PATH
-                                               + File.separator + getFileName(targetPath);
-                               result = pullTheFile(targetPath, localBinaryPath);
-                               if (result.isSuccess()) {
-                                       binInfo.setTempBinaryPath(localBinaryPath);
+                       } else {
+                               // host has no binary file - pull binary file from target
+                               // change binary file path of host
+                               File binFile = new File(localBinaryPath);
+                               if (!binFile.exists()) {
+                                       localBinaryPath = PathManager.DA_TEMP_FOLDER_PATH
+                                                       + File.separator + getFileName(targetPath);
+                                       result = pullTheFile(targetPath, localBinaryPath);
+                                       if (result.isSuccess()) {
+                                               binInfo.setTempBinaryPath(localBinaryPath);
+                                       }
+                               } else {
+                                       // if local binary exist already, then check for md5sum
+                                       String localHashCode = null;
+                                       try {
+                                               Runtime rt = Runtime.getRuntime();
+                                               Process process = rt.exec(new String[] {
+                                                               AnalyzerShellCommands.CMD_MD_5_SUM,
+                                                               localBinaryPath });
+                                               process.waitFor();
+                                               BufferedReader reader = new BufferedReader(
+                                                               new InputStreamReader(process.getInputStream()));
+                                               BufferedReader error = new BufferedReader(
+                                                               new InputStreamReader(process.getErrorStream()));
+                                               String line = reader.readLine();
+                                               String errorStr = error.readLine();
+                                               if (null == line) {
+                                                       DA_LOG.debug("host md5sum get failed : " + errorStr);
+                                                       result = HostResult.ERR_BIN_INFO_GET_FAIL;
+                                               } else {
+                                                       String[] splitResult = line.trim().split(
+                                                                       CommonConstants.SPACE);
+                                                       localHashCode = new String(splitResult[0]);
+                                               }
+                                       } catch (IOException e) {
+                                               e.printStackTrace();
+                                               result = HostResult.ERR_BIN_INFO_GET_FAIL;
+                                       } catch (InterruptedException e) {
+                                               e.printStackTrace();
+                                               result = HostResult.ERR_BIN_INFO_GET_FAIL;
+                                       }
+
+                                       if (localHashCode != null) {
+                                               String targetHashCode = binInfo.getMd5sumValue();
+                                               if (0 != targetHashCode.compareTo(localHashCode)) {
+                                                       localBinaryPath = PathManager.DA_TEMP_FOLDER_PATH
+                                                                       + File.separator + getFileName(targetPath);
+                                                       result = pullTheFile(targetPath, localBinaryPath);
+                                                       if (result.isSuccess()) {
+                                                               binInfo.setTempBinaryPath(localBinaryPath);
+                                                       }
+                                               } else {
+                                                       binInfo.setTempBinaryPath(localBinaryPath);
+                                               }
+                                       }
                                }
-                               continue;
                        }
                }
                return result;
@@ -505,7 +517,7 @@ public class Communicator30 extends BaseCommunicator {
 
                SyncResult res = CommunicatorUtils.pull(from, to);
                if (null != res && res.isOk()) {
-                       DA_LOG.debug("binary copy success!!");//$NON-NLS-1$ 
+                       DA_LOG.debug("binary copy success : " + from);//$NON-NLS-1$ 
                } else {
                        DA_LOG.debug("Failed to get " + from); //$NON-NLS-1$ 
                        return HostResult.ERR_BIN_INFO_GET_FAIL;
@@ -634,7 +646,7 @@ public class Communicator30 extends BaseCommunicator {
                                baos.write(cbuf, 0, readsize);
                        } while (readsize == DACommunicator.READ_BUFFER_SIZE * 2);
                        blocked = false;
-                       
+
                        readsize = baos.size();
                        cbuf = baos.toByteArray();
                        if (PRINT_CONTROL_LOG_TOFILE && printWriter != null) {
@@ -802,7 +814,8 @@ public class Communicator30 extends BaseCommunicator {
                return GlobalInformation.getCurrentDeviceInfo().getDataSock();
        }
 
-       private void processTargetInfo(byte[] payload, int index, DeviceStatusInfo tInfo) {
+       private void processTargetInfo(byte[] payload, int index,
+                       DeviceStatusInfo tInfo) {
                long systemMemorySize = 0;
                long storageSize = 0;
                int bluetoothSupport = 0;
@@ -1099,80 +1112,79 @@ public class Communicator30 extends BaseCommunicator {
                        index += INT_SIZE;
                        localBinaryPath = ByteUtil.getString(payload, index).trim();
                        index += ByteUtil.getStringLength(payload, index);
+                       String md5sum = ByteUtil.getString(payload, index);
+                       index += ByteUtil.getStringLength(payload, index);
+
+                       binInfo.setType(binaryType);
+                       binInfo.setMd5sumValue(md5sum);
                        binInfo.setLocalBinaryPath(localBinaryPath);
-                       binInfo.setTempBinaryPath(localBinaryPath);
+
                        String[] splitLocalBinaryPath = localBinaryPath
                                        .split(CommonConstants.SLASH);
-                       if (splitLocalBinaryPath.length <= 0) {
-                               localBinaryPath = PathManager.DA_TEMP_FOLDER_PATH
-                                               + File.separator + getFileName(binPaths.get(i));
-                               result = pullTheFile(binPaths.get(i), localBinaryPath);
-                               if (result.isSuccess()) {
-                                       String md5sum = ByteUtil.getString(payload, index);
-                                       index += ByteUtil.getStringLength(payload, index);
-                                       binInfo.setType(binaryType);
-                                       binInfo.setTempBinaryPath(localBinaryPath);
-                                       binInfo.setMd5sumValue(md5sum);
-                               }
-                               continue;
-                       } else {
-                               String md5sum = ByteUtil.getString(payload, index);
-                               index += ByteUtil.getStringLength(payload, index);
-                               binInfo.setType(binaryType);
-                               binInfo.setTempBinaryPath(localBinaryPath);
-                               binInfo.setMd5sumValue(md5sum);
-                       }
-
-                       // host has no binary file - pull binary file from target
-                       // change binary file path of host
-                       File binFile = new File(localBinaryPath);
-                       if (!binFile.exists()) {
-                               localBinaryPath = PathManager.DA_TEMP_FOLDER_PATH
-                                               + File.separator + getFileName(binPaths.get(i));
-                               result = pullTheFile(binPaths.get(i), localBinaryPath);
-                               if (result.isSuccess()) {
-                                       binInfo.setTempBinaryPath(localBinaryPath);
-                               }
-                               continue;
-                       }
-
-                       String localHashCode = null;
-                       try {
-                               Runtime rt = Runtime.getRuntime();
-                               Process process = rt.exec(new String[] {
-                                               AnalyzerShellCommands.CMD_MD_5_SUM, localBinaryPath });
-                               process.waitFor();
-                               BufferedReader reader = new BufferedReader(
-                                               new InputStreamReader(process.getInputStream()));
-                               BufferedReader error = new BufferedReader(
-                                               new InputStreamReader(process.getErrorStream()));
-                               String line = reader.readLine();
-                               String errorStr = error.readLine();
-                               if (null == line) {
-                                       DA_LOG.error("host md5sum get failed : " + errorStr);
-                                       continue;
-                               }
-                               String[] splitResult = line.trim().split(CommonConstants.SPACE);
-                               localHashCode = new String(splitResult[0]);
-                       } catch (IOException e) {
-                               e.printStackTrace();
-                               continue;
-                       } catch (InterruptedException e) {
-                               e.printStackTrace();
-                               continue;
-                       }
 
-                       String targetHashCode = binInfo.getMd5sumValue();
-                       if (!targetHashCode.equals(localHashCode)) {
+                       // check for local binary path validation
+                       if (splitLocalBinaryPath.length < 3) {
                                localBinaryPath = PathManager.DA_TEMP_FOLDER_PATH
                                                + File.separator + getFileName(binPaths.get(i));
                                result = pullTheFile(binPaths.get(i), localBinaryPath);
                                if (result.isSuccess()) {
                                        binInfo.setTempBinaryPath(localBinaryPath);
                                }
-                               continue;
                        } else {
-                               binInfo.setTempBinaryPath(localBinaryPath);
+                               // host has no binary file - pull binary file from target
+                               // change binary file path of host
+                               File binFile = new File(localBinaryPath);
+                               if (!binFile.exists()) {
+                                       localBinaryPath = PathManager.DA_TEMP_FOLDER_PATH
+                                                       + File.separator + getFileName(binPaths.get(i));
+                                       result = pullTheFile(binPaths.get(i), localBinaryPath);
+                                       if (result.isSuccess()) {
+                                               binInfo.setTempBinaryPath(localBinaryPath);
+                                       }
+                               } else {
+                                       // if local binary exist already, then check for md5sum
+                                       String localHashCode = null;
+                                       try {
+                                               Runtime rt = Runtime.getRuntime();
+                                               Process process = rt.exec(new String[] {
+                                                               AnalyzerShellCommands.CMD_MD_5_SUM,
+                                                               localBinaryPath });
+                                               process.waitFor();
+                                               BufferedReader reader = new BufferedReader(
+                                                               new InputStreamReader(process.getInputStream()));
+                                               BufferedReader error = new BufferedReader(
+                                                               new InputStreamReader(process.getErrorStream()));
+                                               String line = reader.readLine();
+                                               String errorStr = error.readLine();
+                                               if (null == line) {
+                                                       DA_LOG.error("host md5sum get failed : " + errorStr);
+                                               } else {
+                                                       String[] splitResult = line.trim().split(
+                                                                       CommonConstants.SPACE);
+                                                       localHashCode = new String(splitResult[0]);
+                                               }
+                                       } catch (IOException e) {
+                                               e.printStackTrace();
+                                       } catch (InterruptedException e) {
+                                               e.printStackTrace();
+                                       }
+
+                                       if (localHashCode != null) {
+                                               String targetHashCode = binInfo.getMd5sumValue();
+                                               if (!targetHashCode.equals(localHashCode)) {
+                                                       localBinaryPath = PathManager.DA_TEMP_FOLDER_PATH
+                                                                       + File.separator
+                                                                       + getFileName(binPaths.get(i));
+                                                       result = pullTheFile(binPaths.get(i),
+                                                                       localBinaryPath);
+                                                       if (result.isSuccess()) {
+                                                               binInfo.setTempBinaryPath(localBinaryPath);
+                                                       }
+                                               } else {
+                                                       binInfo.setTempBinaryPath(localBinaryPath);
+                                               }
+                                       }
+                               }
                        }
                }
                BinarySettingManager.getInstance().addBinaryInfos(binInfoList);
index 0c5a31a..cef6c09 100755 (executable)
@@ -277,16 +277,8 @@ public class ToolbarArea {
                        @Override
                        public void handleEvent(Event event) {
                                if (!appCombo.isChildShellOpened()) {
-                                       List<AppInfo> apps = DACommunicator.getAppListFromTarget();
-                                       if (null == apps || apps.isEmpty()) {
-                                               return;
-                                       }
                                        String selectedApp = appCombo.getText();
-                                       appCombo.initCombo();
-                                       int size = apps.size();
-                                       for (int i = 0; i < size; i++) {
-                                               appCombo.add(apps.get(i).getInfo(AppInfo.LABEL_INDEX));
-                                       }
+                                       addToAppComboFromTarget();
                                        appCombo.setText(selectedApp);
                                }
                        }
@@ -815,16 +807,9 @@ public class ToolbarArea {
                appCombo.setEnabled(true);
                appCombo.initCombo();
 
-               List<AppInfo> apps = DACommunicator.getAppListFromTarget();
-               int size = 0;
-               if (null != apps) {
-                       size = apps.size();
-               }
+               List<AppInfo> apps = addToAppComboFromTarget();
 
-               for (int i = 0; i < size; i++) {
-                       appCombo.add(apps.get(i).getInfo(AppInfo.LABEL_INDEX));
-               }
-               if (size > 0) {
+               if (apps.size() > 0) {
                        String appName = GlobalInformation.getCurrentDeviceInfo()
                                        .getSelectedAppName();
                        if (null == appName) {
@@ -853,7 +838,6 @@ public class ToolbarArea {
                                }
                        }
                } else {
-                       appCombo.add(CommonConstants.EMPTY);
                        appCombo.select(0);
                        GlobalInformation.setCurrentApplication(null);
                }
@@ -907,37 +891,26 @@ public class ToolbarArea {
                }
        }
 
-       public void setAppComboItems(List<String> items) {
+       private void addToAppCombo(List<AppInfo> apps) {
                appCombo.initCombo();
-               if (null == items) {
-                       return;
-               }
 
-               int itemsSize = items.size();
-               if (0 != itemsSize) {
-                       appCombo.initCombo();
+               if (apps != null) {
+                       int itemsSize = apps.size();
                        for (int i = 0; i < itemsSize; i++) {
-                               appCombo.add(items.get(i));
-                       }
-                       appCombo.select(COMBO_FIRST_INDEX);
-                       AppInfo appInfo = DACommunicator.getPkgInfoByName(items.get(0));
-                       if (null != appInfo) {
-                               GlobalInformation.setCurrentApplication(appInfo);
-                               GlobalInformation.getCurrentDeviceInfo().getCommunicator()
-                                               .onAppSelected(appInfo);
-                               GlobalInformation.getCurrentDeviceInfo().setSelectedAppName(
-                                               appInfo.getInfo(AppInfo.LABEL_INDEX));
-                               appCombo.setToolTipText(appCombo.getItem(0));
-                               setStartButtonState(true);
-                               // startButton.setButtonEnabled(true);
-                       } else {
-                               appCombo.add(CommonConstants.EMPTY);
+                               appCombo.add(apps.get(i).getInfo(AppInfo.LABEL_INDEX));
                        }
                } else {
                        appCombo.add(CommonConstants.EMPTY);
                }
        }
 
+       private List<AppInfo> addToAppComboFromTarget() {
+               List<AppInfo> apps = DACommunicator.getAppListFromTarget();
+               addToAppCombo(apps);
+
+               return apps;
+       }
+
        public void setAppComboText(final String text) {
                AppInfo appInfo = DACommunicator.getPkgInfoByName(text);
                if (null != appInfo) {
@@ -1151,16 +1124,9 @@ public class ToolbarArea {
                        return false;
                }
 
-               List<AppInfo> apps = DACommunicator.getAppListFromTarget();
-               if (null == apps || apps.isEmpty()) {
-                       return false;
-               }
                String selectedApp = appCombo.getText();
-               appCombo.initCombo();
-               size = apps.size();
-               for (int i = 0; i < size; i++) {
-                       appCombo.add(apps.get(i).getInfo(AppInfo.LABEL_INDEX));
-               }
+               addToAppComboFromTarget();
+
                index = appCombo.getItems().indexOf(selectedApp);
                if (index >= 0) {
                        appCombo.setText(selectedApp);