#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;
} //namespace
+class SysteminfoManager::TapiManager {
+ public:
+ TapiManager() : initialized_(false) {
+ ScopeLogger();
+ }
+
+ ~TapiManager() {
+ ScopeLogger();
+
+ std::lock_guard<std::mutex> lock(mutex_);
+
+ for (const auto& h : handles_) {
+ tel_deinit(h);
+ }
+
+ handles_.clear();
+ }
+
+ int GetSimCount() {
+ ScopeLogger();
+
+ Initialize();
+
+ std::lock_guard<std::mutex> lock(mutex_);
+
+ return handles_.size();
+ }
+
+ int GetChangedTapiIndex(TapiHandle* tapi) {
+ ScopeLogger();
+
+ Initialize();
+
+ std::lock_guard<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<TapiHandle*> handles_;
+ std::mutex mutex_;
+ SimDetailsManager sim_manager_;
+};
+
SysteminfoManager::SysteminfoManager(SysteminfoInstance* instance)
: instance_(instance),
prop_manager_(*this),
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) {
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_);
}
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);
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()) {
if (ret.IsError()) {
*count = 0;
} else {
- *count = GetSimCount();
+ *count = tapi_manager_->GetSimCount();
}
} else if ("CAMERA_FLASH" == property) {
*count = GetCameraTypesCount();
available_capacity_mmc_ = capacity;
}
-int SysteminfoManager::GetSimCount() {
- LoggerD("Entered");
- InitTapiHandles();
- return sim_count_;
-}
-
-void SysteminfoManager::InitTapiHandles() {
- LoggerD("Entered");
- std::lock_guard<std::mutex> 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() {
#ifndef WEBAPI_PLUGINS_SYSTEMINFO_SYSTEMINFO_MANAGER_H__
#define WEBAPI_PLUGINS_SYSTEMINFO_SYSTEMINFO_MANAGER_H__
+#include <memory>
+#include <mutex>
#include <set>
-#include <wifi.h>
+#include <ITapiModem.h>
#include <net_connection.h>
+#include <wifi.h>
#include "common/picojson.h"
#include "common/platform_result.h"
namespace extension {
namespace systeminfo {
-const int kTapiMaxHandle = 2;
-
class SysteminfoInstance;
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_;};
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();
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<TapiManager> tapi_manager_;
std::set<std::string> registered_listeners_;
const std::string kWifiStatusOff = "OFF";
const int kWifiSignalStrengthDivideValue = 100;
//Cellular Network
-const unsigned short kMccDivider = 100;
const char* kConnectionOff = "OFF";
const char* kConnectionOn = "ON";
}
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<picojson::object>();
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) {
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<unsigned short>(result_value) / kMccDivider;
- *result_mnc = static_cast<unsigned short>(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<unsigned short>(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<unsigned short>(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;
}
}
- 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);
}
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;
}
if (ret.IsError()) {
return ret;
}
- return sim_manager_.GatherSimInformation(
- manager_.GetTapiHandles()[count], out);
+ return manager_.GatherSimInformation(count, out);
}
/// PERIPHERAL
#include <string>
#include "common/picojson.h"
#include "common/platform_result.h"
-#include "systeminfo/systeminfo_sim_details_manager.h"
namespace extension {
namespace systeminfo {
common::PlatformResult FetchStatus(std::string* result);
SysteminfoManager& manager_;
- SimDetailsManager sim_manager_;
};
} // namespace systeminfo
#include "systeminfo/systeminfo_sim_details_manager.h"
+#include <vconf.h>
+
#include "common/logger.h"
namespace extension {
sim_mgr->TryReturn();
}
+const unsigned short kMccDivider = 100;
+
} //namespace
using common::PlatformResult;
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<unsigned short>(result_value) / kMccDivider;
+ *result_mnc = static_cast<unsigned short>(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<unsigned short>(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<unsigned short>(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) {
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);