COMMON: modified on-demand install for supporting multi profile. 78/11878/4
authorGun Kim <gune.kim@samsung.com>
Thu, 7 Nov 2013 05:22:24 +0000 (14:22 +0900)
committerGun Kim <gune.kim@samsung.com>
Fri, 8 Nov 2013 10:56:00 +0000 (19:56 +0900)
The ODI installed ODI packages irrespective of target's profile.
This commit fixed it. ODI will install package which match the target's profile.
If you can't find the package matched, ODI will install package which is located in common directory.

Change-Id: I79c99845d906f5cdde0e9b46704be72b8490a107
Signed-off-by: Gun Kim <gune.kim@samsung.com>
org.tizen.common.connection/src/org/tizen/common/connection/debugtools/OnDemandInstall.java
org.tizen.common.sdblib/src/org/tizen/sdblib/SdbHelper.java
org.tizen.common/src/org/tizen/common/core/application/InstallPathConfig.java
org.tizen.common/src/org/tizen/common/core/application/ProfileInfo.java

index d342c3d..af40f7a 100644 (file)
@@ -45,6 +45,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.tizen.common.TizenPlatformConstants;
 import org.tizen.common.core.application.InstallPathConfig;
+import org.tizen.common.core.application.ProfileInfo;
 import org.tizen.common.util.DialogUtil;
 import org.tizen.common.util.FileUtil;
 import org.tizen.common.util.IOUtil;
@@ -440,6 +441,7 @@ public class OnDemandInstall {
         IExtensionRegistry x = RegistryFactory.getRegistry();
         IConfigurationElement[] ces = x.getConfigurationElementsFor(ID_DEBUGTOOLS_EXTENSION);
 
+        ProfileInfo profileInfoForODI = InstallPathConfig.getProfileInfo(device);
         try {
             for ( IConfigurationElement ce : ces ) {
                 if (ce.getName().equals("tools")) {
@@ -456,13 +458,21 @@ public class OnDemandInstall {
                     verbose("a extension ('" + packagename + "') is loaded." );
                     String description = ce.getAttribute("description");
                     DebugTool dt = null;
-                    dt = makeDebugTool(InstallPathConfig.getCommonPlatformPath(), sourcepath, packagename, description);
-                    if ( dt == null ) {
-                        dt = makeDebugTool(InstallPathConfig.getPlatformVersionPath(), sourcepath, packagename, description);
+                    
+                    // First, finds a tool for ODI by using platformInfoForODI.
+                    // If cannot find the tool, finds the tool from common platform directory.
+                    if ( profileInfoForODI != null ) {
+                        dt = makeDebugTool(profileInfoForODI.getLatestPlatformPath(), sourcepath, packagename, description);
                     }
                     if ( dt != null ) {
                         toolLists.add(dt);
                     }
+                    else {
+                        dt = makeDebugTool(InstallPathConfig.getCommonPlatformPath(), sourcepath, packagename, description);
+                        if ( dt != null ) {
+                            toolLists.add(dt);
+                        }
+                    }
                 }
             }
         } catch (Throwable e) {
index 6dea5ce..778176a 100755 (executable)
@@ -516,7 +516,9 @@ public class SdbHelper {
     public static byte[] sendServiceRequest(final SmartDevelopmentBridge sdb, final Device device, final String req)
             throws TimeoutException, SdbCommandRejectedException, IOException {
         SocketChannel sdbChan = null;
-        byte[] msg = new byte[256];
+        // the definition of max sysinfo structure size which is sent from sdbd
+        final int MAX_SYSINFO_SIZE = 512;
+        byte[] msg = new byte[MAX_SYSINFO_SIZE];
         try {
             sdbChan = sdb.openChannel();
             initializeDevice(sdbChan, device.getSerialNumber());
@@ -530,6 +532,8 @@ public class SdbHelper {
                 throw new SdbCommandRejectedException(resp.message);
             }
             read(sdbChan, msg);
+        } catch (EOFException e) {
+            Log.i("sdb", "channel closed as normal, and continuing.....");
         } finally {
             tryClose( sdbChan );
             if (sdbChan != null) {
index bfc9453..7fb1b04 100755 (executable)
@@ -41,6 +41,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Scanner;
+import java.util.Set;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -48,6 +49,7 @@ import org.tizen.common.util.DialogUtil;
 import org.tizen.common.util.HostUtil;
 import org.tizen.common.util.OSChecker;
 import org.tizen.common.util.StringUtil;
+import org.tizen.sdblib.IDevice;
 import org.tizen.sdblib.util.IOUtil;
 
 
@@ -73,8 +75,8 @@ final public class InstallPathConfig {
     private static final String DIR_SDK_DATA = "tizen-sdk-data";
     private static final String DIR_CHECKER = "checker";
     private static final String DIR_DOCUMENTS = "documents";
-    // PLATFORM directory format: <platform><majorNumber>.<minorNumber>
-    private static final String REG_PROFILE = "[a-zA-Z]+";
+    // PLATFORM directory format: <platform>-<majorNumber>.<minorNumber>
+    private static final String REG_PROFILE = "[a-zA-Z\\-]+";
     private static final String REG_VERSION = "(((\\d)|([1-9]\\d{2,}))\\.)((\\d)|([1-9]\\d{2,}))";
     private static final String PLATFORM_SEPARATOR = "-";
     private static final String REG_DIR_PLATFORM = REG_PROFILE + PLATFORM_SEPARATOR + REG_VERSION;
@@ -274,24 +276,37 @@ final public class InstallPathConfig {
      * Returns version of given {@code platform} or null.
      */
     public static String getVersion(String platform) {
-        if ( platform.matches(REG_DIR_PLATFORM) ) {
-            return platform.replaceFirst(REG_PROFILE + PLATFORM_SEPARATOR, "");
-        }
-        else {
-            return null;
+        String[] platformSplit = platform.split(PLATFORM_SEPARATOR);
+        if ( platformSplit.length > 1 ) {
+            if ( platformSplit[platformSplit.length-1].matches(REG_VERSION) ) {
+                return platformSplit[platformSplit.length-1];
+            }
         }
+        
+        return null;
     }
     
     /**
      * Returns profile of given {@code platform} or null.
      */
     public static String getProfile(String platform) {
-        if ( platform.matches(REG_DIR_PLATFORM) ) {
-            return platform.replaceAll( PLATFORM_SEPARATOR + REG_VERSION, "");
+        int index = platform.lastIndexOf(PLATFORM_SEPARATOR);
+        // platform must contain a version
+        // So, "mobile" is not supported
+        if ( index <= 0 ) {
+            return null;
         }
-        else {
+        String profile = platform.substring(0, index);
+        
+        if ( InstallPathConfig.getVersion(platform) == null ) {
             return null;
         }
+
+        if ( profile.matches(REG_PROFILE) ) {
+            return profile;
+        }
+        
+        return null;
     }
 
     /**
@@ -400,6 +415,65 @@ final public class InstallPathConfig {
             return path + File.separator + DIR_SAMPLES;
         }
     }
+    
+    /**
+     * This method returns one of installed profileInfos which matches platformInfo of {@code device}.<br>
+     * If the device's platform information doesn't match installed profiles,<br>
+     * returns one of installed profileInfos that is lower than the device's platform version and version of the most contiguous with platform version.<br>
+     * Nevertheless, if the platformInfo cannot be found,<br>
+     * returns platformInfo that is the highest version in installed profileInfos.<br>
+     * 
+     * Otherwise, returns null.
+     */
+    public static ProfileInfo getProfileInfo(IDevice device) {
+        ProfileInfo devicePlatformInfo = ProfileInfo.getProfileInfo(device);
+        if ( devicePlatformInfo == null ) {
+            return null;
+        }
+        
+        String deviceProfile = devicePlatformInfo.getProfile();
+        String deviceVersion = devicePlatformInfo.getLatestPlatformVersion();
+        double intDeviceVersion = Double.parseDouble(deviceVersion);
+        double tempVersion = -1;
+        double validVersion = -1;
+        double highestVersion = -1;
+        String validPath = "";
+        String highestPath = "";
+        
+        List<ProfileInfo> profileInfoList = InstallPathConfig.getProfileInfos();
+        for ( ProfileInfo profileInfo : profileInfoList ) {
+            if ( deviceProfile.equals(profileInfo.getProfile()) ) {
+                Set<String> versionSet = profileInfo.getVersions();
+                for ( String version : versionSet ) {
+                    if ( deviceVersion.equals(version) ) {
+                        return devicePlatformInfo;
+                    }
+                    else {
+                        tempVersion = Double.parseDouble(version);
+                        if ( intDeviceVersion > tempVersion && validVersion < tempVersion ){
+                            validVersion = tempVersion;
+                            validPath = profileInfo.getPlatformPath(version);
+                        }
+                        
+                        if ( highestVersion < tempVersion ) {
+                            highestVersion = tempVersion;
+                            highestPath = profileInfo.getPlatformPath(version);
+                        }
+                    }
+                }
+                // If the device's platform information doesn't match host's profiles,
+                // returns profileInfo that is lower than the device's platform version and version of the most contiguous with platform version
+                if ( validVersion != -1 ) {
+                    return new ProfileInfo(deviceProfile, String.valueOf(validVersion), validPath);
+                }
+                else {
+                    return new ProfileInfo(deviceProfile, String.valueOf(highestVersion), highestPath);
+                }
+            }
+        }
+        
+        return null;
+    }
 
     public static String getLibraryPath() {
         return getSDKPath() + File.separator + DIR_LIBRARY;
index a21e68f..5107aba 100644 (file)
@@ -30,12 +30,18 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.tizen.sdblib.IDevice;
+import org.tizen.sdblib.PlatformInfo;
+
 /**
  * This class represents information of the platform path.
  * 
  * @author Gun Kim<gune.kim@samsung.com>
  */
 public class ProfileInfo {
+    private static final Logger logger = LoggerFactory.getLogger(ProfileInfo.class);
     private String profile;
     // the versions's key means a profile's version,
     // and its value means path that the version's profile is installed under the path.
@@ -136,4 +142,45 @@ public class ProfileInfo {
     public String toString() {
         return "ProfileInfo [profile=" + profile + ", versions=" + versions +"]";
     }
+    
+    
+    /**
+     * Returns a platform name of the {@code device}.
+     */
+    public static String getPlatformName(IDevice device) {
+        try {
+            return getProfileInfo(device).getLatestPlatformName();
+        } catch (Exception e) {
+            logger.error("cannot get device information - " + device, e);
+            return "";
+        }
+    }
+
+    // TODO: The profile format may be changed by platform's policy.
+    // If it is changed, this code must change.
+    /**
+     * Returns a platform information of the {@link IDevice}.
+     */
+    public static ProfileInfo getProfileInfo(IDevice device) {
+        try {
+            PlatformInfo platformInfo = device.getPlatformInfo();
+            String versionSplit[] = platformInfo.getPlatformVersion().split("\\.");
+            String major = versionSplit[0];
+            String minor = versionSplit[1];
+            String path = null;
+
+            String version = major + "." + minor;
+            String profile = platformInfo.getProfileName().split("-")[0];
+
+            ProfileInfo profileInfo = InstallPathConfig.getProfileInfo(profile);
+            if ( profileInfo != null ) {
+                path = profileInfo.getPlatformPath(version);
+            }
+
+            return new ProfileInfo(profile, version, path);
+        } catch (Exception e) {
+            logger.error("cannot get device information - " + device, e);
+            return null;
+        }
+    }
 }