From ee0e4286cee3b767a342b4acb0dd988e9a224f2b Mon Sep 17 00:00:00 2001 From: Pawel Andruszkiewicz Date: Thu, 17 Mar 2016 14:58:10 +0100 Subject: [PATCH] [SystemInfo] Access to TAPI handle is protected with mutex. [Verification] TCT pass rate: 100% (297/297/0/0/0) Change-Id: I77608b92627a9f2f0cf85514c94238cc060c87fe Signed-off-by: Pawel Andruszkiewicz --- src/systeminfo/systeminfo_manager.cc | 309 +++++++++++++----- src/systeminfo/systeminfo_manager.h | 29 +- .../systeminfo_properties_manager.cc | 80 +---- .../systeminfo_properties_manager.h | 2 - .../systeminfo_sim_details_manager.cc | 63 ++++ .../systeminfo_sim_details_manager.h | 10 +- 6 files changed, 332 insertions(+), 161 deletions(-) diff --git a/src/systeminfo/systeminfo_manager.cc b/src/systeminfo/systeminfo_manager.cc index 074acbb2..35c2c2f8 100644 --- a/src/systeminfo/systeminfo_manager.cc +++ b/src/systeminfo/systeminfo_manager.cc @@ -32,6 +32,7 @@ #include "systeminfo/systeminfo_instance.h" #include "systeminfo/systeminfo_device_capability.h" +#include "systeminfo/systeminfo_sim_details_manager.h" #include "systeminfo/systeminfo-utils.h" using common::PlatformResult; @@ -231,6 +232,197 @@ static void OnWifiLevelChangedCb (wifi_rssi_level_e rssi_level, void *user_data) } //namespace +class SysteminfoManager::TapiManager { + public: + TapiManager() : initialized_(false) { + ScopeLogger(); + } + + ~TapiManager() { + ScopeLogger(); + + std::lock_guard lock(mutex_); + + for (const auto& h : handles_) { + tel_deinit(h); + } + + handles_.clear(); + } + + int GetSimCount() { + ScopeLogger(); + + Initialize(); + + std::lock_guard lock(mutex_); + + return handles_.size(); + } + + int GetChangedTapiIndex(TapiHandle* tapi) { + ScopeLogger(); + + Initialize(); + + std::lock_guard lock(mutex_); + + const auto it = std::find(handles_.begin(), handles_.end(), tapi); + + if (handles_.end() != it) { + return std::distance(handles_.begin(), it); + } else { + return -1; + } + } + + PlatformResult RegisterCallbacks(void* user_data) { + ScopeLogger(); + + Initialize(); + + std::lock_guard lock(mutex_); + + for (const auto& h : handles_) { + for (const auto& n : kNotifications) { + auto result = SysteminfoUtils::RegisterTapiChangeCallback( + h, n, OnTapiValueChangedCb, user_data); + if (!result) { + return result; + } + } + } + + return PlatformResult{ErrorCode::NO_ERROR}; + } + + PlatformResult UnregisterCallbacks() { + ScopeLogger(); + + Initialize(); + + std::lock_guard lock(mutex_); + + for (const auto& h : handles_) { + for (const auto& n : kNotifications) { + auto result = SysteminfoUtils::UnregisterTapiChangeCallback(h, n); + if (!result) { + return result; + } + } + } + + return PlatformResult{ErrorCode::NO_ERROR}; + } + + PlatformResult GetNetworkType(std::size_t index, int* network_type) { + ScopeLogger(); + + Initialize(); + + std::lock_guard lock(mutex_); + + if (index >= handles_.size()) { + LoggerE("Tried to access disallowed index: %zu", index); + return PlatformResult{ErrorCode::INDEX_SIZE_ERR}; + } + + if (TAPI_API_SUCCESS == tel_get_property_int(handles_[index], + TAPI_PROP_NETWORK_SERVICE_TYPE, + network_type)) { + return PlatformResult{ErrorCode::NO_ERROR}; + } else { + LoggerE("Failed to get network type of index: %zu", index); + return PlatformResult{ErrorCode::UNKNOWN_ERR}; + } + } + + PlatformResult GatherSimInformation(std::size_t index, picojson::object* out) { + ScopeLogger(); + + Initialize(); + + std::lock_guard lock(mutex_); + + if (index >= handles_.size()) { + LoggerE("Tried to access disallowed index: %zu", index); + return PlatformResult{ErrorCode::INDEX_SIZE_ERR}; + } + + return sim_manager_.GatherSimInformation(handles_[index], out); + } + + PlatformResult FetchBasicSimProperties(std::size_t index, + unsigned short* result_mcc, + unsigned short* result_mnc, + unsigned short* result_cell_id, + unsigned short* result_lac, + bool* result_is_roaming, + bool* result_is_flight_mode, + std::string* result_imei) { + ScopeLogger(); + + Initialize(); + + std::lock_guard lock(mutex_); + + if (index >= handles_.size()) { + LoggerE("Tried to access disallowed index: %zu", index); + return PlatformResult{ErrorCode::INDEX_SIZE_ERR}; + } + + return SimDetailsManager::FetchBasicSimProperties(handles_[index], + result_mcc, + result_mnc, + result_cell_id, + result_lac, + result_is_roaming, + result_is_flight_mode, + result_imei); + } + + private: + void Initialize() { + ScopeLogger(); + + std::lock_guard lock(mutex_); + + if (!initialized_) { + char** cp_list = tel_get_cp_name_list(); + + if (nullptr != cp_list) { + int sim_count = 0; + + while (cp_list[sim_count]) { + auto tapi_handle = tel_init(cp_list[sim_count]); + if (nullptr == tapi_handle) { + LoggerE("Failed to connect with TAPI, handle is null"); + break; + } + + LoggerD("%d modem: %s", sim_count, cp_list[sim_count]); + handles_.push_back(tapi_handle); + ++sim_count; + } + + initialized_ = true; + } else { + LoggerE("Failed to get cp list"); + } + + g_strfreev(cp_list); + } + } + + const int kTapiMaxHandle = 2; + const char* kNotifications[3] = { TAPI_PROP_NETWORK_CELLID, TAPI_PROP_NETWORK_LAC, TAPI_PROP_NETWORK_ROAMING_STATUS }; + + bool initialized_; + std::vector handles_; + std::mutex mutex_; + SimDetailsManager sim_manager_; +}; + SysteminfoManager::SysteminfoManager(SysteminfoInstance* instance) : instance_(instance), prop_manager_(*this), @@ -242,8 +434,7 @@ SysteminfoManager::SysteminfoManager(SysteminfoInstance* instance) last_available_capacity_internal_(0), available_capacity_mmc_(0), last_available_capacity_mmc_(0), - sim_count_(0), - tapi_handles_{nullptr}, + tapi_manager_(new TapiManager()), cpu_event_id_(0), storage_event_id_(0), connection_handle_(nullptr) { @@ -285,12 +476,6 @@ SysteminfoManager::~SysteminfoManager() { if (IsListenerRegistered(kPropertyIdMemory)) { UnregisterMemoryListener(); } if (IsListenerRegistered(kPropertyIdCameraFlash)) { UnregisterCameraFlashListener(); } - unsigned int i = 0; - while(tapi_handles_[i]) { - tel_deinit(tapi_handles_[i]); - i++; - } - if (nullptr != connection_handle_) { connection_destroy(connection_handle_); } @@ -951,16 +1136,9 @@ PlatformResult SysteminfoManager::RegisterCellularNetworkListener() { if (!IsListenerRegistered(kPropertyIdCellularNetwork)) { CHECK_LISTENER_ERROR(SysteminfoUtils::RegisterVconfCallback( VCONFKEY_TELEPHONY_FLIGHT_MODE, OnCellularNetworkValueChangedCb, this)) - int sim_count = GetSimCount(); - TapiHandle **tapis = GetTapiHandles(); - for (int i = 0; i < sim_count; ++i) { - CHECK_LISTENER_ERROR(SysteminfoUtils::RegisterTapiChangeCallback( - tapis[i], TAPI_PROP_NETWORK_CELLID, OnTapiValueChangedCb, this)) - CHECK_LISTENER_ERROR(SysteminfoUtils::RegisterTapiChangeCallback( - tapis[i], TAPI_PROP_NETWORK_LAC, OnTapiValueChangedCb, this)) - CHECK_LISTENER_ERROR(SysteminfoUtils::RegisterTapiChangeCallback( - tapis[i], TAPI_PROP_NETWORK_ROAMING_STATUS, OnTapiValueChangedCb, this)) - } + + CHECK_LISTENER_ERROR(tapi_manager_->RegisterCallbacks(this)); + LoggerD("Added callback for CELLULAR_NETWORK"); } return PlatformResult(ErrorCode::NO_ERROR); @@ -974,16 +1152,8 @@ PlatformResult SysteminfoManager::UnregisterCellularNetworkListener() { PlatformResult ret = PlatformResult(ErrorCode::NO_ERROR); CHECK_LISTENER_ERROR(SysteminfoUtils::UnregisterVconfCallback( VCONFKEY_TELEPHONY_FLIGHT_MODE, OnCellularNetworkValueChangedCb)) - int sim_count = GetSimCount(); - TapiHandle **tapis = GetTapiHandles(); - for (int i = 0; i < sim_count; ++i) { - CHECK_LISTENER_ERROR(SysteminfoUtils::UnregisterTapiChangeCallback( - tapis[i], TAPI_PROP_NETWORK_CELLID)) - CHECK_LISTENER_ERROR(SysteminfoUtils::UnregisterTapiChangeCallback( - tapis[i], TAPI_PROP_NETWORK_LAC)) - CHECK_LISTENER_ERROR(SysteminfoUtils::UnregisterTapiChangeCallback( - tapis[i], TAPI_PROP_NETWORK_ROAMING_STATUS)) - } + + CHECK_LISTENER_ERROR(tapi_manager_->UnregisterCallbacks()); } if (IsIpChangeCallbackNotRegistered()) { @@ -1140,7 +1310,7 @@ PlatformResult SysteminfoManager::GetPropertyCount(const std::string& property, if (ret.IsError()) { *count = 0; } else { - *count = GetSimCount(); + *count = tapi_manager_->GetSimCount(); } } else if ("CAMERA_FLASH" == property) { *count = GetCameraTypesCount(); @@ -1228,57 +1398,38 @@ void SysteminfoManager::SetAvailableCapacityMmc(unsigned long long capacity) { available_capacity_mmc_ = capacity; } -int SysteminfoManager::GetSimCount() { - LoggerD("Entered"); - InitTapiHandles(); - return sim_count_; -} - -void SysteminfoManager::InitTapiHandles() { - LoggerD("Entered"); - std::lock_guard lock(tapi_mutex_); - if (nullptr == tapi_handles_[0]){ //check if anything is in table - sim_count_ = 0; - char **cp_list = tel_get_cp_name_list(); - if (nullptr != cp_list) { - while (cp_list[sim_count_]) { - tapi_handles_[sim_count_] = tel_init(cp_list[sim_count_]); - if (nullptr == tapi_handles_[sim_count_]) { - LoggerE("Failed to connect with tapi, handle is null"); - break; - } - LoggerD("%d modem: %s", sim_count_, cp_list[sim_count_]); - sim_count_++; - } - } else { - LoggerE("Failed to get cp list"); - sim_count_ = kTapiMaxHandle; - } - g_strfreev(cp_list); - } -} - -TapiHandle* SysteminfoManager::GetTapiHandle() { - LoggerD("Entered"); - InitTapiHandles(); - return tapi_handles_[0]; -} - -TapiHandle** SysteminfoManager::GetTapiHandles() { - LoggerD("Enter"); - InitTapiHandles(); - return tapi_handles_; -} - int SysteminfoManager::GetChangedTapiIndex(TapiHandle* tapi) { - LoggerD("Enter"); - TapiHandle** handles = GetTapiHandles(); - for (int i = 0; i < sim_count_; ++i) { - if (handles[i] == tapi) { - return i; - } - } - return -1; + ScopeLogger(); + return tapi_manager_->GetChangedTapiIndex(tapi); +} + +PlatformResult SysteminfoManager::GetNetworkType(std::size_t index, int* network_type) { + ScopeLogger(); + return tapi_manager_->GetNetworkType(index, network_type); +} + +PlatformResult SysteminfoManager::GatherSimInformation(std::size_t index, picojson::object* out) { + ScopeLogger(); + return tapi_manager_->GatherSimInformation(index, out); +} + +PlatformResult SysteminfoManager::FetchBasicSimProperties(std::size_t index, + unsigned short* result_mcc, + unsigned short* result_mnc, + unsigned short* result_cell_id, + unsigned short* result_lac, + bool* result_is_roaming, + bool* result_is_flight_mode, + std::string* result_imei) { + ScopeLogger(); + return tapi_manager_->FetchBasicSimProperties(index, + result_mcc, + result_mnc, + result_cell_id, + result_lac, + result_is_roaming, + result_is_flight_mode, + result_imei); } void SysteminfoManager::InitCameraTypes() { diff --git a/src/systeminfo/systeminfo_manager.h b/src/systeminfo/systeminfo_manager.h index cef8872c..5251633c 100644 --- a/src/systeminfo/systeminfo_manager.h +++ b/src/systeminfo/systeminfo_manager.h @@ -17,10 +17,13 @@ #ifndef WEBAPI_PLUGINS_SYSTEMINFO_SYSTEMINFO_MANAGER_H__ #define WEBAPI_PLUGINS_SYSTEMINFO_SYSTEMINFO_MANAGER_H__ +#include +#include #include -#include +#include #include +#include #include "common/picojson.h" #include "common/platform_result.h" @@ -29,8 +32,6 @@ namespace extension { namespace systeminfo { -const int kTapiMaxHandle = 2; - class SysteminfoInstance; class SysteminfoManager { @@ -55,9 +56,19 @@ class SysteminfoManager { wifi_rssi_level_e GetWifiLevel(); void SetWifiLevel(wifi_rssi_level_e level); int GetSensorHandle(); - TapiHandle* GetTapiHandle(); - TapiHandle** GetTapiHandles(); + int GetChangedTapiIndex(TapiHandle* tapi); + common::PlatformResult GetNetworkType(std::size_t index, int* network_type); + common::PlatformResult GatherSimInformation(std::size_t index, picojson::object* out); + common::PlatformResult FetchBasicSimProperties(std::size_t index, + unsigned short* result_mcc, + unsigned short* result_mnc, + unsigned short* result_cell_id, + unsigned short* result_lac, + bool* result_is_roaming, + bool* result_is_flight_mode, + std::string* result_imei); + common::PlatformResult GetConnectionHandle(connection_h& handle); SysteminfoInstance* GetInstance() { return instance_;}; @@ -74,13 +85,13 @@ class SysteminfoManager { void CallCpuListenerCallback(); void CallStorageListenerCallback(); private: + class TapiManager; + void PostListenerResponse(const std::string& property_id, const picojson::value& result, int property_index = 0); common::PlatformResult ConnectSensor(int* result); void DisconnectSensor(int handle_orientation); - void InitTapiHandles(); void InitCameraTypes(); - int GetSimCount(); bool IsIpChangeCallbackNotRegistered(); common::PlatformResult RegisterIpChangeCallback(); @@ -129,9 +140,7 @@ class SysteminfoManager { unsigned long long available_capacity_mmc_; unsigned long long last_available_capacity_mmc_; - int sim_count_; - TapiHandle *tapi_handles_[kTapiMaxHandle+1]; - std::mutex tapi_mutex_; + std::unique_ptr tapi_manager_; std::set registered_listeners_; diff --git a/src/systeminfo/systeminfo_properties_manager.cc b/src/systeminfo/systeminfo_properties_manager.cc index a8c0da2f..163e06a8 100644 --- a/src/systeminfo/systeminfo_properties_manager.cc +++ b/src/systeminfo/systeminfo_properties_manager.cc @@ -91,7 +91,6 @@ const std::string kWifiStatusOn = "ON"; const std::string kWifiStatusOff = "OFF"; const int kWifiSignalStrengthDivideValue = 100; //Cellular Network -const unsigned short kMccDivider = 100; const char* kConnectionOff = "OFF"; const char* kConnectionOn = "ON"; } @@ -128,7 +127,7 @@ PlatformResult SysteminfoPropertiesManager::GetPropertyValue(const std::string& LoggerD("property name: %s", property.c_str()); LoggerD("available property count: %d", property_count); - for (size_t i = 0; i < property_count; i++) { + for (std::size_t i = 0; i < property_count; i++) { picojson::value result = picojson::value(picojson::object()); picojson::object& result_obj = result.get(); @@ -549,8 +548,7 @@ PlatformResult SysteminfoPropertiesManager::ReportNetwork(picojson::object* out, type = kWifi; break; case CONNECTION_TYPE_CELLULAR : - if (TAPI_API_SUCCESS == tel_get_property_int(manager_.GetTapiHandles()[count], - TAPI_PROP_NETWORK_SERVICE_TYPE, &networkType)) { + if (manager_.GetNetworkType(count, &networkType)) { if (networkType < TAPI_NETWORK_SERVICE_TYPE_2G) { type = kNone; } else if (networkType == TAPI_NETWORK_SERVICE_TYPE_2G) { @@ -925,55 +923,10 @@ PlatformResult SysteminfoPropertiesManager::ReportEthernetNetwork(picojson::obje return PlatformResult(ErrorCode::NO_ERROR); } -static PlatformResult FetchBasicSimProperties(TapiHandle *tapi_handle, - unsigned short *result_mcc, - unsigned short *result_mnc, - unsigned short *result_cell_id, - unsigned short *result_lac, - bool *result_is_roaming, - bool *result_is_flight_mode) { - LoggerD("Entered"); - int result_value = 0; - int tapi_res = TAPI_API_SUCCESS; - tapi_res = tel_get_property_int(tapi_handle, TAPI_PROP_NETWORK_PLMN, &result_value); - if (TAPI_API_SUCCESS != tapi_res) { - std::string error_msg = "Cannot get mcc value, error: " + std::to_string(tapi_res); - return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, error_msg); - } - *result_mcc = static_cast(result_value) / kMccDivider; - *result_mnc = static_cast(result_value) % kMccDivider; - - tapi_res = tel_get_property_int(tapi_handle, TAPI_PROP_NETWORK_CELLID, &result_value); - if (TAPI_API_SUCCESS != tapi_res) { - std::string error_msg = "Cannot get cell_id value, error: " + std::to_string(tapi_res); - return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, error_msg); - } - *result_cell_id = static_cast(result_value); - - tapi_res = tel_get_property_int(tapi_handle, TAPI_PROP_NETWORK_LAC, &result_value); - if (TAPI_API_SUCCESS != tapi_res) { - std::string error_msg = "Cannot get lac value, error: " + std::to_string(tapi_res); - return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, error_msg); - } - *result_lac = static_cast(result_value); - - tapi_res = tel_get_property_int(tapi_handle, TAPI_PROP_NETWORK_ROAMING_STATUS, &result_value); - if (TAPI_API_SUCCESS != tapi_res) { - std::string error_msg = "Cannot get is_roaming value, error: " + std::to_string(tapi_res); - return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, error_msg); - } - *result_is_roaming = (0 != result_value) ? true : false; - - if (0 != vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &result_value)) { - return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Cannot get is_flight_mode value"); - } - *result_is_flight_mode = (0 != result_value) ? true : false; - return PlatformResult(ErrorCode::NO_ERROR); -} - -static PlatformResult FetchConnection(TapiHandle *tapi_handle, std::string* result_status, - std::string* result_apn, std::string* result_ip_address, - std::string* result_ipv6_address, std::string* result_imei) { +static PlatformResult FetchConnection(std::string* result_status, + std::string* result_apn, + std::string* result_ip_address, + std::string* result_ipv6_address) { LoggerD("Entered"); connection_type_e connection_type = CONNECTION_TYPE_DISCONNECTED; connection_profile_h profile_handle = nullptr; @@ -1056,15 +1009,6 @@ static PlatformResult FetchConnection(TapiHandle *tapi_handle, std::string* resu } } - char* imei = nullptr; - imei = tel_get_misc_me_imei_sync(tapi_handle); - if (nullptr != imei) { - *result_imei = imei; - free(imei); - } else { - LoggerE("Failed to get imei, nullptr pointer. Setting empty value."); - *result_imei = ""; - } return PlatformResult(ErrorCode::NO_ERROR); } @@ -1088,16 +1032,15 @@ PlatformResult SysteminfoPropertiesManager::ReportCellularNetwork(picojson::obje std::string result_imei; //gathering vconf-based values - ret = FetchBasicSimProperties(manager_.GetTapiHandles()[count], &result_mcc, + ret = manager_.FetchBasicSimProperties(count, &result_mcc, &result_mnc, &result_cell_id, &result_lac, - &result_is_roaming, &result_is_flight_mode); + &result_is_roaming, &result_is_flight_mode, + &result_imei); if (ret.IsError()) { return ret; } //gathering connection informations - ret = FetchConnection(manager_.GetTapiHandles()[count], - &result_status, &result_apn, &result_ip_address, &result_ipv6_address, - &result_imei); + ret = FetchConnection(&result_status, &result_apn, &result_ip_address, &result_ipv6_address); if (ret.IsError()) { return ret; } @@ -1160,8 +1103,7 @@ PlatformResult SysteminfoPropertiesManager::ReportSim(picojson::object* out, uns if (ret.IsError()) { return ret; } - return sim_manager_.GatherSimInformation( - manager_.GetTapiHandles()[count], out); + return manager_.GatherSimInformation(count, out); } /// PERIPHERAL diff --git a/src/systeminfo/systeminfo_properties_manager.h b/src/systeminfo/systeminfo_properties_manager.h index c86f39ec..c18078a7 100644 --- a/src/systeminfo/systeminfo_properties_manager.h +++ b/src/systeminfo/systeminfo_properties_manager.h @@ -20,7 +20,6 @@ #include #include "common/picojson.h" #include "common/platform_result.h" -#include "systeminfo/systeminfo_sim_details_manager.h" namespace extension { namespace systeminfo { @@ -59,7 +58,6 @@ class SysteminfoPropertiesManager { common::PlatformResult FetchStatus(std::string* result); SysteminfoManager& manager_; - SimDetailsManager sim_manager_; }; } // namespace systeminfo diff --git a/src/systeminfo/systeminfo_sim_details_manager.cc b/src/systeminfo/systeminfo_sim_details_manager.cc index c07f7791..dd6ddc38 100644 --- a/src/systeminfo/systeminfo_sim_details_manager.cc +++ b/src/systeminfo/systeminfo_sim_details_manager.cc @@ -16,6 +16,8 @@ #include "systeminfo/systeminfo_sim_details_manager.h" +#include + #include "common/logger.h" namespace extension { @@ -112,6 +114,8 @@ void SimIccidValueCallback(TapiHandle */*handle*/, int result, void *data, void sim_mgr->TryReturn(); } +const unsigned short kMccDivider = 100; + } //namespace using common::PlatformResult; @@ -184,6 +188,65 @@ PlatformResult SimDetailsManager::GatherSimInformation(TapiHandle* handle, picoj return PlatformResult(ErrorCode::NO_ERROR); } +PlatformResult SimDetailsManager::FetchBasicSimProperties(TapiHandle* tapi_handle, + unsigned short* result_mcc, + unsigned short* result_mnc, + unsigned short* result_cell_id, + unsigned short* result_lac, + bool* result_is_roaming, + bool* result_is_flight_mode, + std::string* result_imei) { + ScopeLogger(); + + int result_value = 0; + int tapi_res = TAPI_API_SUCCESS; + tapi_res = tel_get_property_int(tapi_handle, TAPI_PROP_NETWORK_PLMN, &result_value); + if (TAPI_API_SUCCESS != tapi_res) { + std::string error_msg = "Cannot get mcc value, error: " + std::to_string(tapi_res); + return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, error_msg); + } + *result_mcc = static_cast(result_value) / kMccDivider; + *result_mnc = static_cast(result_value) % kMccDivider; + + tapi_res = tel_get_property_int(tapi_handle, TAPI_PROP_NETWORK_CELLID, &result_value); + if (TAPI_API_SUCCESS != tapi_res) { + std::string error_msg = "Cannot get cell_id value, error: " + std::to_string(tapi_res); + return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, error_msg); + } + *result_cell_id = static_cast(result_value); + + tapi_res = tel_get_property_int(tapi_handle, TAPI_PROP_NETWORK_LAC, &result_value); + if (TAPI_API_SUCCESS != tapi_res) { + std::string error_msg = "Cannot get lac value, error: " + std::to_string(tapi_res); + return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, error_msg); + } + *result_lac = static_cast(result_value); + + tapi_res = tel_get_property_int(tapi_handle, TAPI_PROP_NETWORK_ROAMING_STATUS, &result_value); + if (TAPI_API_SUCCESS != tapi_res) { + std::string error_msg = "Cannot get is_roaming value, error: " + std::to_string(tapi_res); + return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, error_msg); + } + *result_is_roaming = (0 != result_value) ? true : false; + + if (0 != vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &result_value)) { + return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Cannot get is_flight_mode value"); + } + *result_is_flight_mode = (0 != result_value) ? true : false; + + char* imei = nullptr; + imei = tel_get_misc_me_imei_sync(tapi_handle); + if (nullptr != imei) { + *result_imei = imei; + free(imei); + } else { + LoggerE("Failed to get imei, nullptr pointer. Setting empty value."); + *result_imei = ""; + } + + return PlatformResult(ErrorCode::NO_ERROR); +} + void SimDetailsManager::FetchSimState(TapiHandle *tapi_handle) { LoggerD("Entered"); if (nullptr == tapi_handle) { diff --git a/src/systeminfo/systeminfo_sim_details_manager.h b/src/systeminfo/systeminfo_sim_details_manager.h index 0b6a4ed9..1553aa8a 100644 --- a/src/systeminfo/systeminfo_sim_details_manager.h +++ b/src/systeminfo/systeminfo_sim_details_manager.h @@ -34,7 +34,15 @@ class SimDetailsManager { SimDetailsManager(); common::PlatformResult GatherSimInformation(TapiHandle* handle, picojson::object* out); - long GetSimCount(TapiHandle **tapi_handle); + static common::PlatformResult FetchBasicSimProperties(TapiHandle* tapi_handle, + unsigned short* result_mcc, + unsigned short* result_mnc, + unsigned short* result_cell_id, + unsigned short* result_lac, + bool* result_is_roaming, + bool* result_is_flight_mode, + std::string* result_imei); + void TryReturn(); void set_operator_name(const std::string& name); -- 2.34.1