Fix for system info collector.
authorDmytro Lomtiev <d.lomtev@samsung.com>
Mon, 26 Mar 2018 07:58:42 +0000 (10:58 +0300)
committerDmytro Lomtiev <d.lomtev@samsung.com>
Mon, 26 Mar 2018 12:03:26 +0000 (15:03 +0300)
device-agent/communication/src/sysinfo.cpp

index 9ee0369..3a101ab 100644 (file)
 namespace
 {
 
+const std::string UNDEFINED_VAL{"undefined"};
+
 /**
  * @brief getStringSystemProperty returns system property as std::string
  * @param prop the requested system property key
  * @return requested system property on success and "undefined" otherwise
  */
-std::string getStringSystemProperty(system_info_key_e prop)
+bool getStringSystemProperty(system_info_key_e prop, std::string& property)
 {
-    std::string property{"undefined"};
     char* val;
 
     if (0 == system_info_get_value_string(prop, &val)) {
         property.assign(val);
         free(val);
+        return true;
     }
 
-    return property;
+    return false;
 }
 
 /**
@@ -39,17 +41,17 @@ std::string getStringSystemProperty(system_info_key_e prop)
  * @param prop the requested platform property key
  * @return requested platform property on success and "undefined" otherwise
  */
-std::string getStringPlatformProperty(const char* prop)
+bool getStringPlatformProperty(const char* prop, std::string& property)
 {
-    std::string property{"undefined"};
     char* val;
 
     if (0 == system_info_get_platform_string(prop, &val)) {
         property.assign(val);
         free(val);
+        return true;
     }
 
-    return property;
+    return false;
 }
 
 }
@@ -59,27 +61,51 @@ namespace NetworkManager
 
 std::string SysInfo::model()
 {
-    return getStringSystemProperty(SYSTEM_INFO_KEY_MODEL);
+    std::string prop;
+    if (!getStringSystemProperty(SYSTEM_INFO_KEY_MODEL, prop)
+            && !getStringPlatformProperty("tizen.org/system/model_name", prop)) {
+        prop = UNDEFINED_VAL;
+    }
+    return prop;
 }
 
 std::string SysInfo::type()
 {
-    return getStringPlatformProperty("com.samsung/build_config/product_type");
+    std::string prop;
+    if (!getStringPlatformProperty("com.samsung/build_config/product_type", prop)
+            && !getStringPlatformProperty("tizen.org/feature/profile", prop)) {
+        prop = UNDEFINED_VAL;
+    }
+    return prop;
 }
 
 std::string SysInfo::osVersion()
 {
-    return getStringPlatformProperty("tizen.org/feature/platform.version");
+    std::string prop;
+    if (!getStringPlatformProperty("tizen.org/feature/platform.version", prop)) {
+        prop = UNDEFINED_VAL;
+    }
+    return prop;
 }
 
 std::string SysInfo::osName()
 {
-    return getStringSystemProperty(SYSTEM_INFO_KEY_PLATFORM_NAME);
+    std::string prop;
+    if (!getStringSystemProperty(SYSTEM_INFO_KEY_PLATFORM_NAME, prop)
+            && !getStringPlatformProperty("tizen.org/system/platform.name", prop)) {
+        prop = UNDEFINED_VAL;
+    }
+    return prop;
 }
 
 std::string SysInfo::swVersion()
 {
-    return getStringSystemProperty(SYSTEM_INFO_KEY_TIZEN_VERSION);
+    std::string prop;
+    if (!getStringSystemProperty(SYSTEM_INFO_KEY_TIZEN_VERSION, prop)
+            && !getStringPlatformProperty("tizen.org/system/build.string", prop)) {
+        prop = UNDEFINED_VAL;
+    }
+    return prop;
 }
 
 }