From 44cf697fd30320e14cbd3551be0bc8554eef87bd Mon Sep 17 00:00:00 2001 From: Lukasz Bardeli Date: Fri, 17 May 2019 13:34:35 +0200 Subject: [PATCH] [SystemInfo] Add SERVICE_COUNTRY property 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 --- src/systeminfo/systeminfo-utils.cpp | 14 ++++++ src/systeminfo/systeminfo-utils.h | 1 + src/systeminfo/systeminfo_api.js | 31 ++++++++++++- src/systeminfo/systeminfo_manager.cc | 44 +++++++++++++++++++ src/systeminfo/systeminfo_manager.h | 2 + .../systeminfo_properties_manager.cc | 17 +++++++ .../systeminfo_properties_manager.h | 1 + 7 files changed, 109 insertions(+), 1 deletion(-) diff --git a/src/systeminfo/systeminfo-utils.cpp b/src/systeminfo/systeminfo-utils.cpp index a7e9c43a..3487de82 100644 --- a/src/systeminfo/systeminfo-utils.cpp +++ b/src/systeminfo/systeminfo-utils.cpp @@ -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(); diff --git a/src/systeminfo/systeminfo-utils.h b/src/systeminfo/systeminfo-utils.h index 2541e088..7f56f26e 100644 --- a/src/systeminfo/systeminfo-utils.h +++ b/src/systeminfo/systeminfo-utils.h @@ -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); diff --git a/src/systeminfo/systeminfo_api.js b/src/systeminfo/systeminfo_api.js index b0628978..6c79cbdd 100644 --- a/src/systeminfo/systeminfo_api.js +++ b/src/systeminfo/systeminfo_api.js @@ -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' } }; diff --git a/src/systeminfo/systeminfo_manager.cc b/src/systeminfo/systeminfo_manager.cc index 7c301fee..f8832577 100644 --- a/src/systeminfo/systeminfo_manager.cc +++ b/src/systeminfo/systeminfo_manager.cc @@ -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(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", diff --git a/src/systeminfo/systeminfo_manager.h b/src/systeminfo/systeminfo_manager.h index 5650b4a1..614b498c 100644 --- a/src/systeminfo/systeminfo_manager.h +++ b/src/systeminfo/systeminfo_manager.h @@ -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_; diff --git a/src/systeminfo/systeminfo_properties_manager.cc b/src/systeminfo/systeminfo_properties_manager.cc index 4b46b1b6..de0449d1 100644 --- a/src/systeminfo/systeminfo_properties_manager.cc +++ b/src/systeminfo/systeminfo_properties_manager.cc @@ -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 diff --git a/src/systeminfo/systeminfo_properties_manager.h b/src/systeminfo/systeminfo_properties_manager.h index 2637d1ab..c8e83557 100644 --- a/src/systeminfo/systeminfo_properties_manager.h +++ b/src/systeminfo/systeminfo_properties_manager.h @@ -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); -- 2.34.1