[SystemInfo] Add SERVICE_COUNTRY property 23/206323/3
authorLukasz Bardeli <l.bardeli@samsung.com>
Fri, 17 May 2019 11:34:35 +0000 (13:34 +0200)
committerLukasz Bardeli <l.bardeli@samsung.com>
Fri, 17 May 2019 11:34:35 +0000 (13:34 +0200)
ACR: http://suprem.sec.samsung.net/jira/browse/TWDAPI-223

[Verification] Code compiles without error. Tested in chrome console.

Change-Id: I449c57fdf6ba1ef884f766a397e950a1c0fdb4cd
Signed-off-by: Lukasz Bardeli <l.bardeli@samsung.com>
src/systeminfo/systeminfo-utils.cpp
src/systeminfo/systeminfo-utils.h
src/systeminfo/systeminfo_api.js
src/systeminfo/systeminfo_manager.cc
src/systeminfo/systeminfo_manager.h
src/systeminfo/systeminfo_properties_manager.cc
src/systeminfo/systeminfo_properties_manager.h

index a7e9c43..3487de8 100644 (file)
@@ -135,6 +135,20 @@ PlatformResult SysteminfoUtils::GetTotalMemory(long long *result) {
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
+PlatformResult SysteminfoUtils::GetServiceCountry(std::string *result) {
+  ScopeLogger();
+
+  char *country_code;
+  country_code = vconf_get_str("db/comss/countrycode");
+  if (nullptr != country_code) {
+    *result = country_code;
+    free(country_code);
+
+    return PlatformResult(ErrorCode::NO_ERROR);
+  }
+  return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, "Property SERVICE_COUNTRY is Not Supported");
+}
+
 PlatformResult SysteminfoUtils::GetAvailableMemory(long long *result) {
   ScopeLogger();
 
index 2541e08..7f56f26 100644 (file)
@@ -47,6 +47,7 @@ class SysteminfoUtils {
   static common::PlatformResult CheckCameraFlashSupport();
   static common::PlatformResult CheckIfEthernetNetworkSupported();
   static common::PlatformResult GetTotalMemory(long long *result);
+  static common::PlatformResult GetServiceCountry(std::string *result);
   static common::PlatformResult GetAvailableMemory(long long *result);
   static common::PlatformResult RegisterVconfCallback(const char *in_key, vconf_callback_fn cb,
                                                       void *event_ptr);
index b062897..6c79cbd 100644 (file)
@@ -43,7 +43,8 @@ var SystemInfoPropertyId = {
         PERIPHERAL : 'PERIPHERAL',
         MEMORY : 'MEMORY',
         CAMERA_FLASH : 'CAMERA_FLASH',
-        ADS : 'ADS'
+        ADS : 'ADS',
+        SERVICE_COUNTRY : 'SERVICE_COUNTRY'
 };
 
 var SystemInfoPropertyIdToFeature = {
@@ -743,6 +744,12 @@ function SystemInfoADS(data) {
     });
 }
 
+function SystemInfoServiceCountry(data) {
+    Object.defineProperties(this, {
+        serviceCountry : {value: data.serviceCountry, writable: false, enumerable: true},
+    });
+}
+
 SystemInfoCameraFlash.prototype.setBrightness = function(brightness) {
   var args = validator_.validateArgs(arguments, [
     {name: 'brightness', type: types_.DOUBLE}
@@ -903,6 +910,7 @@ var _simStr = SystemInfoPropertyId.SIM;
 var _peripheralStr = SystemInfoPropertyId.PERIPHERAL;
 var _memoryStr = SystemInfoPropertyId.MEMORY;
 var _cameraFlashStr = SystemInfoPropertyId.CAMERA_FLASH;
+var _serviceCountryStr = SystemInfoPropertyId.SERVICE_COUNTRY;
 
 var _nextId = 0;
 
@@ -1169,6 +1177,21 @@ function  _systeminfoCameraFlashListenerCallback(eventObj) {
     }
 }
 
+function  _systeminfoServiceCountryListenerCallback(eventObj) {
+    var property = _serviceCountryStr;
+    var callbacks = _propertyContainer[property].callbacks;
+
+    for (var watchId in callbacks) {
+        if (callbacks.hasOwnProperty(watchId)) {
+            var listener = callbacks[watchId];
+            var propObj = !listener.isArrayType ?
+                    _createProperty(property, eventObj.result.array[0]) :
+                        _createPropertyArray(property, eventObj.result);
+            callbacks[watchId].callback(propObj);
+        }
+    }
+}
+
 var _propertyContainer = {
         'BATTERY' : {
             callbacks : {},
@@ -1271,6 +1294,12 @@ var _propertyContainer = {
           constructor : SystemInfoADS,
           broadcastFunction : function(){},
           signalLabel : ''
+        },
+        'SERVICE_COUNTRY' : {
+            callbacks : {},
+            constructor : SystemInfoServiceCountry,
+            broadcastFunction : _systeminfoServiceCountryListenerCallback,
+            signalLabel : 'SystemInfoServiceCountryChangeBroadcast'
         }
 };
 
index 7c301fe..f883257 100644 (file)
@@ -75,6 +75,7 @@ const std::string kPropertyIdSim = "SIM";
 const std::string kPropertyIdPeripheral = "PERIPHERAL";
 const std::string kPropertyIdMemory = "MEMORY";
 const std::string kPropertyIdCameraFlash = "CAMERA_FLASH";
+const std::string kPropertyIdServiceCountry = "SERVICE_COUNTRY";
 
 #define CHECK_EXIST(args, name, out)                                              \
   if (!args.contains(name)) {                                                     \
@@ -225,6 +226,13 @@ static void OnWifiLevelChangedCb(wifi_manager_rssi_level_e rssi_level, void* use
   manager->SetWifiLevel(rssi_level);
 }
 
+static void OnServiceCountryChangedCb(keynode_t* key, void* user_data) {
+  ScopeLogger();
+  SysteminfoManager* manager = static_cast<SysteminfoManager*>(user_data);
+
+  manager->CallListenerCallback(kPropertyIdServiceCountry);
+}
+
 }  // namespace
 
 class SysteminfoManager::TapiManager {
@@ -816,6 +824,8 @@ void SysteminfoManager::AddPropertyValueChangeListener(const picojson::value& ar
       ret = RegisterMemoryListener();
     } else if (property_name == kPropertyIdCameraFlash) {
       ret = RegisterCameraFlashListener();
+    } else if (property_name == kPropertyIdServiceCountry) {
+      ret = RegisterServiceCountryListener();
     } else {
       ret = LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Not supported property");
     }
@@ -880,6 +890,8 @@ void SysteminfoManager::RemovePropertyValueChangeListener(const picojson::value&
       ret = UnregisterMemoryListener();
     } else if (property_name == kPropertyIdCameraFlash) {
       ret = UnregisterCameraFlashListener();
+    } else if (property_name == kPropertyIdServiceCountry) {
+      ret = UnregisterServiceCountryListener();
     } else {
       ret = LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Not supported property");
     }
@@ -1314,6 +1326,30 @@ PlatformResult SysteminfoManager::UnregisterCameraFlashListener() {
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
+PlatformResult SysteminfoManager::RegisterServiceCountryListener() {
+  ScopeLogger();
+
+  int ret = vconf_notify_key_changed("db/comss/countrycode", OnServiceCountryChangedCb, this);
+  if (0 != ret) {
+    return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR,
+                              "SERVICE_COUNTRY is not supported property.",
+                              ("vconf_notify_key_changed error"));
+  }
+
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult SysteminfoManager::UnregisterServiceCountryListener() {
+  ScopeLogger();
+  int ret = vconf_ignore_key_changed("db/comss/countrycode", OnServiceCountryChangedCb);
+  if (0 != ret) {
+    return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR,
+                              "SERVICE_COUNTRY is not supported property.",
+                              ("vconf_ignore_key_changed error"));
+  }
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
 void SysteminfoManager::SetBrightness(const picojson::value& args, picojson::object* out) {
   ScopeLogger();
 
@@ -1383,6 +1419,14 @@ PlatformResult SysteminfoManager::GetPropertyCount(const std::string& property,
     } else {
       *count = kDefaultPropertyCount;
     }
+  } else if (kPropertyIdServiceCountry == property) {
+    std::string tmp;
+    PlatformResult ret = SysteminfoUtils::GetServiceCountry(&tmp);
+    if (ret.IsError()) {
+      *count = 0;
+    } else {
+      *count = 1;
+    }
   } else {
     return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR,
                               "Property with given id is not supported",
index 5650b4a..614b498 100644 (file)
@@ -125,6 +125,8 @@ class SysteminfoManager {
   common::PlatformResult UnregisterMemoryListener();
   common::PlatformResult RegisterCameraFlashListener();
   common::PlatformResult UnregisterCameraFlashListener();
+  common::PlatformResult RegisterServiceCountryListener();
+  common::PlatformResult UnregisterServiceCountryListener();
 
   SysteminfoInstance* instance_;
   SysteminfoPropertiesManager prop_manager_;
index 4b46b1b..de0449d 100644 (file)
@@ -189,6 +189,8 @@ PlatformResult SysteminfoPropertiesManager::ReportProperty(const std::string& pr
     return ReportCameraFlash(res_obj, index);
   } else if ("ADS" == property) {
     return ReportAds(res_obj);
+  } else if ("SERVICE_COUNTRY" == property) {
+    return ReportServiceCountry(res_obj);
   }
   return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR,
                             "Property with given id is not supported");
@@ -1271,5 +1273,20 @@ PlatformResult SysteminfoPropertiesManager::ReportAds(picojson::object* out) {
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
+PlatformResult SysteminfoPropertiesManager::ReportServiceCountry(picojson::object* out) {
+  ScopeLogger();
+
+  std::string service_country;
+  PlatformResult ret = SysteminfoUtils::GetServiceCountry(&service_country);
+
+  if (ret.IsError()) {
+    return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR);
+  }
+
+  out->insert(std::make_pair("serviceCountry", picojson::value(service_country)));
+
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
 }  // namespace systeminfo
 }  // namespace webapi
index 2637d1a..c8e8355 100644 (file)
@@ -54,6 +54,7 @@ class SysteminfoPropertiesManager {
   common::PlatformResult ReportMemory(picojson::object* out);
   common::PlatformResult ReportStorage(picojson::object* out);
   common::PlatformResult ReportAds(picojson::object* out);
+  common::PlatformResult ReportServiceCountry(picojson::object* out);
 
   common::PlatformResult FetchIsAutoRotation(bool* result);
   common::PlatformResult FetchStatus(std::string* result);