From: Piotr Kosko Date: Thu, 27 Aug 2015 14:45:51 +0000 (+0200) Subject: [Systeminfo] Module reorganization, next part X-Git-Tag: submit/tizen/20151026.073646^2^2~129^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=05632dd3340393101810a308767137f146cb01d1;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Systeminfo] Module reorganization, next part [Feature] Implementation of getters was changed to use specialized classes. Listeners implementation was temporarly disabled. [Verification] Code compiles without errors. Getters checked in chrome console and work fine. Change-Id: I63cc9c21d0be1057375f349edf44b24b6cc4024a Signed-off-by: Piotr Kosko --- diff --git a/src/systeminfo/systeminfo-utils.cpp b/src/systeminfo/systeminfo-utils.cpp index 7aef3f58..1a348044 100644 --- a/src/systeminfo/systeminfo-utils.cpp +++ b/src/systeminfo/systeminfo-utils.cpp @@ -57,7 +57,6 @@ const int MEMORY_TO_BYTE = 1024; const int BASE_GATHERING_INTERVAL = 100; const double DISPLAY_INCH_TO_MILLIMETER = 2.54; -const int kTapiMaxHandle = 2; const int kDefaultPropertyCount = 1; } // namespace @@ -138,15 +137,6 @@ const int kWifiSignalStrengthDivideValue = 100; const unsigned short kMccDivider = 100; const char* kConnectionOff = "OFF"; const char* kConnectionOn = "ON"; -//Sim -const char* kSimStatusAbsent = "ABSENT"; -const char* kSimStatusInitializing = "INITIALIZING"; -const char* kSimStatusReady = "READY"; -const char* kSimStatusPinRequired = "PIN_REQUIRED"; -const char* kSimStatusPukRequired = "PUK_REQUIRED"; -const char* kSimStatusSimLocked = "SIM_LOCKED"; -const char* kSimStatusNetworkLocked = "NETWORK_LOCKED"; -const char* kSimStatusUnknown = "UNKNOWN"; static std::string parseWifiNetworkError(int error) { switch (error) { @@ -172,252 +162,6 @@ static std::string parseWifiNetworkError(int error) { } -/////////////////////////// SimDetailsManager //////////////////////////////// - -class SimDetailsManager { - private: - unsigned short mcc_; - unsigned short mnc_; - std::string operator_name_; - std::string msin_; - std::string state_; - std::string msisdn_; - std::string iccid_; - std::string spn_; - - picojson::object* sim_result_obj_; - unsigned short to_process_; - std::mutex sim_to_process_mutex_; - std::mutex sim_info_mutex_; - long sim_count_; - - void ResetSimHolder(picojson::object* out); - void FetchSimState(TapiHandle *tapi_handle); - PlatformResult FetchSimSyncProps(TapiHandle *tapi_handle); - void ReturnSimToJS(); - - public: - SimDetailsManager(); - - PlatformResult GatherSimInformation(TapiHandle* handle, picojson::object* out); - long GetSimCount(TapiHandle **tapi_handle); - void TryReturn(); - - void set_operator_name(const std::string& name) - { - std::lock_guard lock(sim_to_process_mutex_); - operator_name_ = name; - --to_process_; - LoggerD("Operator name: %s", operator_name_.c_str()); - }; - void set_msisdn(const std::string& msisdn) - { - std::lock_guard lock(sim_to_process_mutex_); - this->msisdn_ = msisdn; - --to_process_; - LoggerD("MSISDN number: %s", this->msisdn_.c_str()); - }; - void set_spn(const std::string& spn) - { - std::lock_guard lock(sim_to_process_mutex_); - this->spn_ = spn; - --to_process_; - LoggerD("SPN value: %s", this->spn_.c_str()); - }; -}; - -SimDetailsManager::SimDetailsManager(): - mcc_(0), - mnc_(0), - operator_name_(""), - msin_(""), - state_(""), - msisdn_(""), - iccid_(""), - spn_(""), - sim_result_obj_(nullptr), - to_process_(0), - sim_count_(0) -{ -} - -PlatformResult SimDetailsManager::GatherSimInformation(TapiHandle* handle, picojson::object* out) -{ - std::lock_guard first_lock_sim(sim_info_mutex_); - ResetSimHolder(out); - - FetchSimState(handle); - if (kSimStatusReady == state_) { - PlatformResult ret = FetchSimSyncProps(handle); - if (ret.IsError()) { - return ret; - } - { - //All props should be fetched synchronously, but sync function does not work - std::lock_guard lock_to_process(sim_to_process_mutex_); - //would be deleted on } ending bracket - int result = tel_get_sim_cphs_netname(handle, SimCphsValueCallback, nullptr); - if (TAPI_API_SUCCESS == result) { - ++to_process_; - } else { - LoggerE("Failed getting cphs netname: %d", result); - } - - result = tel_get_sim_msisdn(handle, SimMsisdnValueCallback, nullptr); - if (TAPI_API_SUCCESS == result) { - ++to_process_; - } else { - LoggerE("Failed getting msisdn: %d", result); - } - - result = tel_get_sim_spn(handle, SimSpnValueCallback, nullptr); - if (TAPI_API_SUCCESS == result) { - ++to_process_; - } else { - LoggerE("Failed getting spn: %d", result); - } - } - //prevent returning not filled result - std::lock_guard lock_sim(sim_info_mutex_); - //result will come from callbacks - return PlatformResult(ErrorCode::NO_ERROR); - } - //if sim state is not READY return default values and don't wait for callbacks - TryReturn(); - return PlatformResult(ErrorCode::NO_ERROR); -} - -void SimDetailsManager::FetchSimState(TapiHandle *tapi_handle) -{ - LoggerD("Entered"); - if (nullptr == tapi_handle) { - LoggerE("Tapi handle is null"); - state_ = kSimStatusUnknown; - } else { - int card_changed = 0; - TelSimCardStatus_t sim_card_state; - int error = tel_get_sim_init_info(tapi_handle, &sim_card_state, &card_changed); - if (TAPI_API_SUCCESS == error) { - switch (sim_card_state) { - case TAPI_SIM_STATUS_CARD_NOT_PRESENT: - case TAPI_SIM_STATUS_CARD_REMOVED: - state_ = kSimStatusAbsent; - break; - case TAPI_SIM_STATUS_SIM_INITIALIZING: - state_ = kSimStatusInitializing; - break; - case TAPI_SIM_STATUS_SIM_INIT_COMPLETED: - state_ = kSimStatusReady; - break; - case TAPI_SIM_STATUS_SIM_PIN_REQUIRED: - state_ = kSimStatusPinRequired; - break; - case TAPI_SIM_STATUS_SIM_PUK_REQUIRED: - state_ = kSimStatusPukRequired; - break; - case TAPI_SIM_STATUS_SIM_LOCK_REQUIRED: - case TAPI_SIM_STATUS_CARD_BLOCKED: - state_ = kSimStatusSimLocked; - break; - case TAPI_SIM_STATUS_SIM_NCK_REQUIRED: - case TAPI_SIM_STATUS_SIM_NSCK_REQUIRED: - state_ = kSimStatusNetworkLocked; - break; - default: - state_ = kSimStatusUnknown; - break; - } - } - } -} - -PlatformResult SimDetailsManager::FetchSimSyncProps(TapiHandle *tapi_handle) -{ - LoggerD("Entered"); - TelSimImsiInfo_t imsi; - int error = tel_get_sim_imsi(tapi_handle, &imsi); - if (TAPI_API_SUCCESS == error) { - LoggerD("mcc: %s, mnc: %s, msin: %s", imsi.szMcc, imsi.szMnc, imsi.szMsin); - mcc_ = std::stoul(imsi.szMcc); - mnc_ = std::stoul(imsi.szMnc); - msin_ = imsi.szMsin; - } - else { - LoggerE("Failed to get sim imsi: %d", error); - return PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to get sim imsi"); - } - - //TODO add code for iccid value fetching, when proper API would be ready - iccid_ = ""; - return PlatformResult(ErrorCode::NO_ERROR); -} - -void SimDetailsManager::ResetSimHolder(picojson::object* out){ - sim_result_obj_ = out; - to_process_ = 0; - mcc_ = 0; - mnc_ = 0; - operator_name_ = ""; - msin_ = ""; - state_ = ""; - msisdn_ = ""; - iccid_ = ""; - spn_ = ""; -} - -void SimDetailsManager::ReturnSimToJS(){ - LoggerD("Entered"); - if (nullptr != sim_result_obj_) { - sim_result_obj_->insert(std::make_pair("state", picojson::value(state_))); - sim_result_obj_->insert(std::make_pair("operatorName", picojson::value(operator_name_))); - sim_result_obj_->insert(std::make_pair("msisdn", picojson::value(msisdn_))); - sim_result_obj_->insert(std::make_pair("iccid", picojson::value(iccid_))); - sim_result_obj_->insert(std::make_pair("mcc", picojson::value(std::to_string(mcc_)))); - sim_result_obj_->insert(std::make_pair("mnc", picojson::value(std::to_string(mnc_)))); - sim_result_obj_->insert(std::make_pair("msin", picojson::value(msin_))); - sim_result_obj_->insert(std::make_pair("spn", picojson::value(spn_))); - //everything returned, clear pointer - sim_result_obj_ = nullptr; - } else { - LoggerE("No sim returned JSON object pointer is null"); - } -} - -long SimDetailsManager::GetSimCount(TapiHandle **tapi_handle){ - if (0 != sim_count_){ - LoggerD("Sim counted already"); - } else { - LoggerD("Gathering sim count"); - char **cp_list = tel_get_cp_name_list(); - if (cp_list != NULL) { - while (cp_list[sim_count_]) { - tapi_handle[sim_count_] = tel_init(cp_list[sim_count_]); - if (tapi_handle[sim_count_] == NULL) { - LoggerE("Failed to connect with tapi, handle is null"); - break; - } - sim_count_++; - LoggerD("%d modem: %s", sim_count_, cp_list[sim_count_]); - } - } else { - LoggerE("Failed to get cp list"); - sim_count_ = kTapiMaxHandle; - } - g_strfreev(cp_list); - } - return sim_count_; -} - -void SimDetailsManager::TryReturn(){ - if (0 == to_process_){ - LoggerD("Returning property to JS"); - ReturnSimToJS(); - sim_info_mutex_.unlock(); - } else { - LoggerD("Not ready yet - waiting"); - } -} - /////////////////////////// SystemInfoListeners //////////////////////////////// class SystemInfoListeners { @@ -963,36 +707,6 @@ PlatformResult CheckIfEthernetNetworkSupported() return PlatformResult(ErrorCode::NO_ERROR); } -common::PlatformResult CheckTelephonySupport() { - bool supported = false; - PlatformResult ret = SystemInfoDeviceCapability::GetValueBool( - "tizen.org/feature/network.telephony", &supported); - if (ret.IsError()) { - return ret; - } - if (!supported) { - LoggerD("Telephony is not supported on this device"); - return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, - "Telephony is not supported on this device"); - } - return PlatformResult(ErrorCode::NO_ERROR); -} - -common::PlatformResult CheckCameraFlashSupport() { - bool supported = false; - PlatformResult ret = SystemInfoDeviceCapability::GetValueBool( - "tizen.org/feature/camera.back.flash", &supported); - if (ret.IsError()) { - return ret; - } - if (!supported) { - LoggerD("Back-facing camera with a flash is not supported on this device"); - return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, - "Back-facing camera with a flash is not supported on this device"); - } - return PlatformResult(ErrorCode::NO_ERROR); -} - PlatformResult SystemInfoListeners::RegisterEthernetNetworkListener(const SysteminfoUtilsCallback& callback, SysteminfoInstance& instance) { @@ -1038,7 +752,7 @@ PlatformResult SystemInfoListeners::RegisterCellularNetworkListener(const System SysteminfoInstance& instance) { LoggerD("Entered"); - PlatformResult ret = CheckTelephonySupport(); + PlatformResult ret = SysteminfoUtils::CheckTelephonySupport(); if (ret.IsError()) { return ret; } @@ -1218,52 +932,52 @@ void SystemInfoListeners::OnCpuChangedCallback(void* event_ptr) { LoggerD(""); picojson::value result = picojson::value(picojson::object()); - PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdCpu, false, result); - if (ret.IsSuccess()) { - if (m_cpu_load == m_last_cpu_load) { - return; - } - if (nullptr != m_cpu_listener) { - SysteminfoInstance* instance = static_cast(event_ptr); - m_last_cpu_load = m_cpu_load; - m_cpu_listener(*instance); - } - } +// PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdCpu, false, result); +// if (ret.IsSuccess()) { +// if (m_cpu_load == m_last_cpu_load) { +// return; +// } +// if (nullptr != m_cpu_listener) { +// SysteminfoInstance* instance = static_cast(event_ptr); +// m_last_cpu_load = m_cpu_load; +// m_cpu_listener(*instance); +// } +// } } void SystemInfoListeners::OnStorageChangedCallback(void* event_ptr) { LoggerD(""); picojson::value result = picojson::value(picojson::object()); - PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdStorage, false, result); - if (ret.IsSuccess()) { - if (m_available_capacity_internal == m_last_available_capacity_internal) { - return; - } - - if (nullptr != m_storage_listener) { - SysteminfoInstance* instance = static_cast(event_ptr); - m_last_available_capacity_internal = m_available_capacity_internal; - m_storage_listener(*instance); - } - } +// PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdStorage, false, result); +// if (ret.IsSuccess()) { +// if (m_available_capacity_internal == m_last_available_capacity_internal) { +// return; +// } +// +// if (nullptr != m_storage_listener) { +// SysteminfoInstance* instance = static_cast(event_ptr); +// m_last_available_capacity_internal = m_available_capacity_internal; +// m_storage_listener(*instance); +// } +// } } void SystemInfoListeners::OnMmcChangedCallback(keynode_t* /*node*/, void* event_ptr) { LoggerD(""); picojson::value result = picojson::value(picojson::object()); - PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdStorage, false, result); - if (ret.IsSuccess()) { - if (m_available_capacity_mmc == m_last_available_capacity_mmc) { - return; - } - if (nullptr != m_storage_listener) { - SysteminfoInstance* instance = static_cast(event_ptr); - m_last_available_capacity_mmc = m_available_capacity_mmc; - m_storage_listener(*instance); - } - } +// PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdStorage, false, result); +// if (ret.IsSuccess()) { +// if (m_available_capacity_mmc == m_last_available_capacity_mmc) { +// return; +// } +// if (nullptr != m_storage_listener) { +// SysteminfoInstance* instance = static_cast(event_ptr); +// m_last_available_capacity_mmc = m_available_capacity_mmc; +// m_storage_listener(*instance); +// } +// } } @@ -1588,703 +1302,215 @@ void OnWifiLevelChangedCb (wifi_rssi_level_e rssi_level, void *user_data) } /////////////////////////// SysteminfoUtils //////////////////////////////// - -static PlatformResult GetRuntimeInfoString(system_settings_key_e key, std::string& platform_string) { - char* platform_c_string; - int err = system_settings_get_value_string(key, &platform_c_string); - if (SYSTEM_SETTINGS_ERROR_NONE == err) { - if (nullptr != platform_c_string) { - platform_string = platform_c_string; - free(platform_c_string); - return PlatformResult(ErrorCode::NO_ERROR); - } - } - const std::string error_msg = "Error when retrieving system setting information: " - + std::to_string(err); - LoggerE("%s", error_msg.c_str()); - return PlatformResult(ErrorCode::UNKNOWN_ERR, error_msg); -} - -PlatformResult GetVconfInt(const char *key, int &value) { - if (0 == vconf_get_int(key, &value)) { - LoggerD("value[%s]: %d", key, value); - return PlatformResult(ErrorCode::NO_ERROR); - } - const std::string error_msg = "Could not get " + std::string(key); - LoggerD("%s",error_msg.c_str()); - return PlatformResult(ErrorCode::UNKNOWN_ERR, error_msg); +PlatformResult SysteminfoUtils::RegisterBatteryListener(const SysteminfoUtilsCallback& callback, + SysteminfoInstance& instance) +{ + return system_info_listeners.RegisterBatteryListener(callback, instance); } -PlatformResult SysteminfoUtils::GetTotalMemory(long long& result) +PlatformResult SysteminfoUtils::UnregisterBatteryListener() { - LoggerD("Entered"); - - unsigned int value = 0; + return system_info_listeners.UnregisterBatteryListener(); +} - int ret = device_memory_get_total(&value); - if (ret != DEVICE_ERROR_NONE) { - std::string log_msg = "Failed to get total memory: " + std::to_string(ret); - LoggerE("%s", log_msg.c_str()); - return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); - } - result = static_cast(value*MEMORY_TO_BYTE); - return PlatformResult(ErrorCode::NO_ERROR); +PlatformResult SysteminfoUtils::RegisterCpuListener(const SysteminfoUtilsCallback& callback, + SysteminfoInstance& instance) +{ + return system_info_listeners.RegisterCpuListener(callback, instance); } -PlatformResult SysteminfoUtils::GetAvailableMemory(long long& result) +PlatformResult SysteminfoUtils::UnregisterCpuListener() { - LoggerD("Entered"); - - unsigned int value = 0; + return system_info_listeners.UnregisterCpuListener(); +} - int ret = device_memory_get_available(&value); - if (ret != DEVICE_ERROR_NONE) { - std::string log_msg = "Failed to get total memory: " + std::to_string(ret); - LoggerE("%s", log_msg.c_str()); - return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); - } - result = static_cast(value*MEMORY_TO_BYTE); - return PlatformResult(ErrorCode::NO_ERROR); +PlatformResult SysteminfoUtils::RegisterStorageListener(const SysteminfoUtilsCallback& callback, + SysteminfoInstance& instance) +{ + return system_info_listeners.RegisterStorageListener(callback, instance); } -PlatformResult SysteminfoUtils::GetCount(const std::string& property, unsigned long& count) +PlatformResult SysteminfoUtils::UnregisterStorageListener() { - LoggerD("Enter"); - - if ("BATTERY" == property || "CPU" == property || "STORAGE" == property || - "DISPLAY" == property || "DEVICE_ORIENTATION" == property || - "BUILD" == property || "LOCALE" == property || "NETWORK" == property || - "WIFI_NETWORK" == property || "PERIPHERAL" == property || - "MEMORY" == property) { - count = kDefaultPropertyCount; - } else if ("CELLULAR_NETWORK" == property) { - PlatformResult ret = CheckTelephonySupport(); - if (ret.IsError()) { - count = 0; - } else { - count = sim_mgr.GetSimCount(system_info_listeners.GetTapiHandles()); - } - } else if ("SIM" == property) { - PlatformResult ret = CheckTelephonySupport(); - if (ret.IsError()) { - count = 0; - } else { - count = sim_mgr.GetSimCount(system_info_listeners.GetTapiHandles()); - } - } else if ("CAMERA_FLASH" == property) { - count = system_info_listeners.GetCameraTypesCount(); - } else if ("ETHERNET_NETWORK" == property) { - PlatformResult ret = CheckIfEthernetNetworkSupported(); - if (ret.IsError()) count = 0; - else count = kDefaultPropertyCount; - } else { - LoggerD("Property with given id is not supported"); - return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, "Property with given id is not supported"); - } - return PlatformResult(ErrorCode::NO_ERROR); + return system_info_listeners.UnregisterStorageListener(); } -PlatformResult SysteminfoUtils::ReportProperty(const std::string& property, int index, - picojson::object& res_obj) { - if ("BATTERY" == property){ - return ReportBattery(res_obj); - } else if ("CPU" == property) { - return ReportCpu(res_obj); - } else if ("STORAGE" == property) { - return ReportStorage(res_obj); - } else if ("DISPLAY" == property) { - return ReportDisplay(res_obj); - } else if ("DEVICE_ORIENTATION" == property) { - return ReportDeviceOrientation(res_obj); - } else if ("BUILD" == property) { - return ReportBuild(res_obj); - } else if ("LOCALE" == property) { - return ReportLocale(res_obj); - } else if ("NETWORK" == property) { - return ReportNetwork(res_obj); - } else if ("WIFI_NETWORK" == property) { - return ReportWifiNetwork(res_obj); - } else if ("ETHERNET_NETWORK" == property) { - return ReportEthernetNetwork(res_obj); - } else if ("CELLULAR_NETWORK" == property) { - return ReportCellularNetwork(res_obj, index); - } else if ("SIM" == property) { - return ReportSim(res_obj, index); - } else if ("PERIPHERAL" == property) { - return ReportPeripheral(res_obj); - } else if ("MEMORY" == property) { - return ReportMemory(res_obj); - } else if ("CAMERA_FLASH" == property) { - return ReportCameraFlash(res_obj, index); - } - LoggerD("Property with given id is not supported"); - return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, "Property with given id is not supported"); -} - -PlatformResult SysteminfoUtils::GetPropertyValue(const std::string& property, bool is_array_type, - picojson::value& res) -{ - LoggerD("Entered getPropertyValue"); - - if (!is_array_type) { - picojson::object& res_obj = res.get(); - return ReportProperty(property, 0, res_obj); - } else { - picojson::object& array_result_obj = res.get(); - picojson::array& array = array_result_obj.insert( - std::make_pair("array", picojson::value(picojson::array()))). - first->second.get(); - - unsigned long property_count = 0; - PlatformResult ret = SysteminfoUtils::GetCount(property, property_count); - if (ret.IsError()){ - return ret; - } - - LoggerD("property name: %s", property.c_str()); - LoggerD("available property count: %d", property_count); - for (size_t i = 0; i < property_count; i++) { - picojson::value result = picojson::value(picojson::object()); - picojson::object& result_obj = result.get(); - - ret = ReportProperty(property, i, result_obj); - if (ret.IsError()){ - return ret; - } - array.push_back(result); - } - if (property_count == 0) { - return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, "Property with given id is not supported"); - } - } - - return PlatformResult(ErrorCode::NO_ERROR); +PlatformResult SysteminfoUtils::RegisterDisplayListener(const SysteminfoUtilsCallback& callback, + SysteminfoInstance& instance) +{ + return system_info_listeners.RegisterDisplayListener(callback, instance); } -PlatformResult SysteminfoUtils::ReportBattery(picojson::object& out) { - int value = 0; - int ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, &value); - if (kVconfErrorNone != ret) { - std::string log_msg = "Platform error while getting battery detail: "; - LoggerE("%s%d", log_msg.c_str(), ret); - return PlatformResult(ErrorCode::UNKNOWN_ERR, (log_msg + std::to_string(ret))); - } +PlatformResult SysteminfoUtils::UnregisterDisplayListener() +{ + return system_info_listeners.UnregisterDisplayListener(); +} - out.insert(std::make_pair("level", picojson::value(static_cast(value)/kRemainingBatteryChargeMax))); - value = 0; - ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &value); - if (kVconfErrorNone != ret) { - std::string log_msg = "Platform error while getting battery charging: "; - LoggerE("%s%d",log_msg.c_str(), ret); - return PlatformResult(ErrorCode::UNKNOWN_ERR, (log_msg + std::to_string(ret))); - } - out.insert(std::make_pair("isCharging", picojson::value(0 != value))); - return PlatformResult(ErrorCode::NO_ERROR); +PlatformResult SysteminfoUtils::RegisterDeviceOrientationListener(const SysteminfoUtilsCallback& callback, + SysteminfoInstance& instance) +{ + return system_info_listeners.RegisterDeviceOrientationListener(callback, instance); } -//TODO maybe make two functions later onGSourceFunc -PlatformResult SysteminfoUtils::ReportCpu(picojson::object& out) { - LoggerD("Entered"); - static CpuInfo cpu_info; - FILE *fp = nullptr; - fp = fopen("/proc/stat", "r"); - if (nullptr == fp) { - std::string error_msg("Can not open /proc/stat for reading"); - LoggerE( "%s", error_msg.c_str() ); - return PlatformResult(ErrorCode::UNKNOWN_ERR, error_msg); - } - - long long usr = 0; - long long system = 0; - long long nice = 0; - long long idle = 0; - double load = 0; - - int read_ret = fscanf( fp, "%*s %lld %lld %lld %lld", &usr, &system, &nice, &idle); - fclose(fp); - - if (4 == read_ret) { - long long total = usr + nice + system + idle - cpu_info.usr - cpu_info.nice - - cpu_info.system - cpu_info.idle; - long long diff_idle = idle - cpu_info.idle; - if (( total > 0LL ) && ( diff_idle > 0LL )) { - load = static_cast< double >( diff_idle ) * 100LL / total; - cpu_info.usr = usr; - cpu_info.system = system; - cpu_info.nice = nice; - cpu_info.idle = idle; - cpu_info.load = load; - } else { - LoggerW("Cannot calculate cpu load, previous value returned"); - load = cpu_info.load; - } - } else { - std::string error_msg( "Could not read /proc/stat" ); - LoggerE( "%s", error_msg.c_str() ); - return PlatformResult(ErrorCode::UNKNOWN_ERR, error_msg); - } - system_info_listeners.SetCpuInfoLoad(cpu_info.load); +PlatformResult SysteminfoUtils::UnregisterDeviceOrientationListener() +{ + return system_info_listeners.UnregisterDeviceOrientationListener(); +} - load = 100 - load; - LoggerD("Cpu load : %f", load ); - out.insert(std::make_pair("load", picojson::value(load / 100.0))); - return PlatformResult(ErrorCode::NO_ERROR); +PlatformResult SysteminfoUtils::RegisterLocaleListener(const SysteminfoUtilsCallback& callback, + SysteminfoInstance& instance) +{ + return system_info_listeners.RegisterLocaleListener(callback, instance); } -PlatformResult SysteminfoUtils::ReportDisplay(picojson::object& out) { - int screenWidth = 0; - int screenHeight = 0; - int dotsPerInchWidth = 0; - int dotsPerInchHeight = 0; - double physicalWidth = 0; - double physicalHeight = 0; - double scaledBrightness; - - // FETCH RESOLUTION - if (SYSTEM_INFO_ERROR_NONE != system_info_get_platform_int( - "tizen.org/feature/screen.width", &screenWidth)) { - LoggerE("Cannot get value of screen width"); - return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get value of screen width"); - } - if (SYSTEM_INFO_ERROR_NONE != system_info_get_platform_int( - "tizen.org/feature/screen.height", &screenHeight)) { - LoggerE("Cannot get value of screen height"); - return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get value of screen height"); - } - - //FETCH DOTS PER INCH - int dots_per_inch=0; - if (SYSTEM_INFO_ERROR_NONE == system_info_get_platform_int( - "tizen.org/feature/screen.dpi", &dots_per_inch)) { - dotsPerInchWidth = dots_per_inch; - dotsPerInchHeight = dots_per_inch; - } else { - LoggerE("Cannot get 'tizen.org/feature/screen.dpi' value"); - return PlatformResult(ErrorCode::UNKNOWN_ERR, - "Cannot get 'tizen.org/feature/screen.dpi' value"); - } +PlatformResult SysteminfoUtils::UnregisterLocaleListener() +{ + return system_info_listeners.UnregisterLocaleListener(); +} - //FETCH PHYSICAL WIDTH - if (dotsPerInchWidth != 0 && screenWidth != 0) { - physicalWidth = (screenWidth / dotsPerInchWidth) * DISPLAY_INCH_TO_MILLIMETER; - } else { - std::string log_msg = "Failed to get physical screen width value"; - LoggerE("%s, screenWidth : %d, dotsPerInchWidth: %d", log_msg.c_str(), - screenWidth, dotsPerInchWidth); - } +PlatformResult SysteminfoUtils::RegisterNetworkListener(const SysteminfoUtilsCallback& callback, + SysteminfoInstance& instance) +{ + return system_info_listeners.RegisterNetworkListener(callback, instance); +} - //FETCH PHYSICAL HEIGHT - if (dotsPerInchHeight != 0 && screenHeight != 0) { - physicalHeight = (screenHeight / dotsPerInchHeight) * DISPLAY_INCH_TO_MILLIMETER; - } else { - std::string log_msg = "Failed to get physical screen height value"; - LoggerE("%s, screenHeight : %d, dotsPerInchHeight: %d", log_msg.c_str(), - screenHeight, dotsPerInchHeight); - } +PlatformResult SysteminfoUtils::UnregisterNetworkListener() +{ + return system_info_listeners.UnregisterNetworkListener(); +} - //FETCH BRIGHTNESS - int brightness; - if (kVconfErrorNone == vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, &brightness)) { - scaledBrightness = static_cast(brightness)/kDisplayBrightnessDivideValue; - } else { - LoggerE("Cannot get brightness value of display"); - return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get brightness value of display"); - } +PlatformResult SysteminfoUtils::RegisterWifiNetworkListener(const SysteminfoUtilsCallback& callback, + SysteminfoInstance& instance) +{ + return system_info_listeners.RegisterWifiNetworkListener(callback, instance); +} - out.insert(std::make_pair("resolutionWidth", picojson::value(std::to_string(screenWidth)))); - out.insert(std::make_pair("resolutionHeight", picojson::value(std::to_string(screenHeight)))); - out.insert(std::make_pair("dotsPerInchWidth", picojson::value(std::to_string(dotsPerInchWidth)))); - out.insert(std::make_pair("dotsPerInchHeight", picojson::value(std::to_string(dotsPerInchHeight)))); - out.insert(std::make_pair("physicalWidth", picojson::value(std::to_string(physicalWidth)))); - out.insert(std::make_pair("physicalHeight", picojson::value(std::to_string(physicalHeight)))); - out.insert(std::make_pair("brightness", picojson::value(scaledBrightness))); - return PlatformResult(ErrorCode::NO_ERROR); +PlatformResult SysteminfoUtils::UnregisterWifiNetworkListener() +{ + return system_info_listeners.UnregisterWifiNetworkListener(); } -static PlatformResult FetchIsAutoRotation(bool* result) +PlatformResult SysteminfoUtils::RegisterEthernetNetworkListener(const SysteminfoUtilsCallback& callback, + SysteminfoInstance& instance) { LoggerD("Entered"); - int is_auto_rotation = 0; + return system_info_listeners.RegisterEthernetNetworkListener(callback, instance); +} - if ( 0 == vconf_get_bool( - VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &is_auto_rotation)) { - if (is_auto_rotation) { - *result = true; - } else { - *result = false; - } - return PlatformResult(ErrorCode::NO_ERROR); - } - else { - LoggerE("VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL check failed"); - return PlatformResult(ErrorCode::UNKNOWN_ERR, - "VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL check failed"); - } -} - -static PlatformResult FetchStatus(std::string* result) +PlatformResult SysteminfoUtils::UnregisterEthernetNetworkListener() { LoggerD("Entered"); - int rotation = 0; - std::string status = kOrientationPortraitPrimary; - - sensor_data_t data; - bool ret = sensord_get_data(system_info_listeners.GetSensorHandle(), - AUTO_ROTATION_BASE_DATA_SET, &data); - if (ret) { - LoggerD("size of the data value array:%d", data.value_count); - if (data.value_count > 0 ) { - rotation = data.values[0]; - LoggerD("rotation is: %d", rotation); - } else { - LoggerE("Failed to get data : the size of array is 0. Default rotation would be returned."); - } - } else { - LoggerE("Failed to get data(sensord_get_data). Default rotation would be returned."); - } - - - switch (rotation) { - case AUTO_ROTATION_DEGREE_UNKNOWN: - case AUTO_ROTATION_DEGREE_0: - LoggerD("AUTO_ROTATION_DEGREE_0"); - status = kOrientationPortraitPrimary; - break; - case AUTO_ROTATION_DEGREE_90: - LoggerD("AUTO_ROTATION_DEGREE_90"); - status = kOrientationLandscapePrimary; - break; - case AUTO_ROTATION_DEGREE_180: - LoggerD("AUTO_ROTATION_DEGREE_180"); - status = kOrientationPortraitSecondary; - break; - case AUTO_ROTATION_DEGREE_270: - LoggerD("AUTO_ROTATION_DEGREE_270"); - status = kOrientationLandscapeSecondary; - break; - default: - LoggerE("Received unexpected data: %u", rotation); - return PlatformResult(ErrorCode::UNKNOWN_ERR, "Received unexpected data"); - } - *result = status; - return PlatformResult(ErrorCode::NO_ERROR); + return system_info_listeners.UnregisterEthernetNetworkListener(); } -PlatformResult SysteminfoUtils::ReportDeviceOrientation(picojson::object& out) { - bool is_auto_rotation = false; - std::string status = ""; - - PlatformResult ret = FetchIsAutoRotation(&is_auto_rotation); - if (ret.IsError()) return ret; - - ret = FetchStatus(&status); - if (ret.IsError()) return ret; - - out.insert(std::make_pair("isAutoRotation", picojson::value(is_auto_rotation))); - out.insert(std::make_pair("status", picojson::value(status))); - return PlatformResult(ErrorCode::NO_ERROR); +PlatformResult SysteminfoUtils::RegisterCellularNetworkListener(const SysteminfoUtilsCallback& callback, + SysteminfoInstance& instance) +{ + return system_info_listeners.RegisterCellularNetworkListener(callback, instance); } -PlatformResult SysteminfoUtils::ReportBuild(picojson::object& out) { - std::string model = ""; - PlatformResult ret = SystemInfoDeviceCapability::GetValueString( - "tizen.org/system/model_name", &model); - if (ret.IsError()) { - return ret; - } - std::string manufacturer = ""; - ret = SystemInfoDeviceCapability::GetValueString( - "tizen.org/system/manufacturer", &manufacturer); - if (ret.IsError()) { - return ret; - } - std::string buildVersion = ""; - ret = SystemInfoDeviceCapability::GetValueString( - "tizen.org/system/build.string", &buildVersion); - if (ret.IsError()) { - return ret; - } - - out.insert(std::make_pair("model", picojson::value(model))); - out.insert(std::make_pair("manufacturer", picojson::value(manufacturer))); - out.insert(std::make_pair("buildVersion", picojson::value(buildVersion))); - return PlatformResult(ErrorCode::NO_ERROR); +PlatformResult SysteminfoUtils::UnregisterCellularNetworkListener() +{ + return system_info_listeners.UnregisterCellularNetworkListener(); } -PlatformResult SysteminfoUtils::ReportLocale(picojson::object& out) { - std::string str_language = ""; - PlatformResult ret = GetRuntimeInfoString(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, str_language); - if (ret.IsError()) { - return ret; - } +PlatformResult SysteminfoUtils::RegisterPeripheralListener(const SysteminfoUtilsCallback& callback, + SysteminfoInstance& instance) +{ + return system_info_listeners.RegisterPeripheralListener(callback, instance); +} - std::string str_country = ""; - ret = GetRuntimeInfoString(SYSTEM_SETTINGS_KEY_LOCALE_COUNTRY, str_country); - if (ret.IsError()) { - return ret; - } +PlatformResult SysteminfoUtils::UnregisterPeripheralListener() +{ + return system_info_listeners.UnregisterPeripheralListener(); +} - out.insert(std::make_pair("language", picojson::value(str_language))); - out.insert(std::make_pair("country", picojson::value(str_country))); - return PlatformResult(ErrorCode::NO_ERROR); +PlatformResult SysteminfoUtils::RegisterMemoryListener(const SysteminfoUtilsCallback& callback, + SysteminfoInstance& instance) +{ + return system_info_listeners.RegisterMemoryListener(callback, instance); } -static PlatformResult GetNetworkTypeString(NetworkType type, std::string& type_string) -{ - switch (type) { - case kNone: - type_string = kNetworkTypeNone; - break; - case kType2G: - type_string = kNetworkType2G; - break; - case kType2_5G: - type_string = kNetworkType2_5G; - break; - case kType3G: - type_string = kNetworkType3G; - break; - case kType4G: - type_string = kNetworkType4G; - break; - case kWifi: - type_string = kNetworkTypeWifi; - break; - case kEthernet: - type_string = kNetworkTypeEthernet; - break; - case kUnknown: - type_string = kNetworkTypeUnknown; - break; - default: - LoggerE("Incorrect type: %d", type); - return PlatformResult(ErrorCode::TYPE_MISMATCH_ERR, "Incorrect type"); - } - return PlatformResult(ErrorCode::NO_ERROR); +PlatformResult SysteminfoUtils::UnregisterMemoryListener() +{ + return system_info_listeners.UnregisterMemoryListener(); } -PlatformResult SysteminfoUtils::ReportNetwork(picojson::object& out) { - connection_h connection_handle = nullptr; - connection_type_e connection_type = CONNECTION_TYPE_DISCONNECTED; - int networkType = 0; - NetworkType type = kNone; +PlatformResult SysteminfoUtils::RegisterCameraFlashListener(const SysteminfoUtilsCallback& callback, + SysteminfoInstance& instance) +{ + return system_info_listeners.RegisterCameraFlashListener(callback, instance); +} - //connection must be created in every call, in other case error occurs - int error = connection_create(&connection_handle); - if (CONNECTION_ERROR_NONE != error) { - std::string log_msg = "Cannot create connection: " + std::to_string(error); - LoggerE("%s", log_msg.c_str()); - return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); - } - std::unique_ptr::type, int(*)(connection_h)> - connection_handle_ptr(connection_handle, &connection_destroy); - // automatically release the memory +PlatformResult SysteminfoUtils::UnregisterCameraFlashListener() +{ + return system_info_listeners.UnregisterCameraFlashListener(); +} - error = connection_get_type(connection_handle, &connection_type); - if (CONNECTION_ERROR_NONE != error) { - std::string log_msg = "Cannot get connection type: " + std::to_string(error); - LoggerE("%s", log_msg.c_str()); - return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); +PlatformResult SysteminfoUtils::GetVconfInt(const char *key, int *value) { + if (0 == vconf_get_int(key, value)) { + LoggerD("value[%s]: %d", key, *value); + return PlatformResult(ErrorCode::NO_ERROR); } + const std::string error_msg = "Could not get " + std::string(key); + LoggerD("%s",error_msg.c_str()); + return PlatformResult(ErrorCode::UNKNOWN_ERR, error_msg); +} - switch (connection_type) { - case CONNECTION_TYPE_DISCONNECTED : - type = kNone; - break; - case CONNECTION_TYPE_WIFI : - type = kWifi; - break; - case CONNECTION_TYPE_CELLULAR : - if (vconf_get_int(VCONFKEY_TELEPHONY_SVCTYPE, &networkType) == 0) { - if (networkType < VCONFKEY_TELEPHONY_SVCTYPE_2G) { - type = kNone; - } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_2G) { - type = kType2G; - } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_2G - || networkType == VCONFKEY_TELEPHONY_SVCTYPE_2_5G_EDGE) { - type = kType2_5G; - } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_3G - || networkType == VCONFKEY_TELEPHONY_SVCTYPE_HSDPA) { - type = kType3G; - } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_LTE) { - type = kType4G; - } else { - type = kNone; - } - } - break; - case CONNECTION_TYPE_ETHERNET : - type = kEthernet; - break; - default: - LoggerE("Incorrect type: %d", connection_type); - return PlatformResult(ErrorCode::UNKNOWN_ERR, "Incorrect type"); - } - std::string type_str = ""; - PlatformResult ret = GetNetworkTypeString(type, type_str); - if(ret.IsError()) { - return ret; +PlatformResult SysteminfoUtils::GetRuntimeInfoString(system_settings_key_e key, std::string* platform_string) { + char* platform_c_string; + int err = system_settings_get_value_string(key, &platform_c_string); + if (SYSTEM_SETTINGS_ERROR_NONE == err) { + if (nullptr != platform_c_string) { + *platform_string = platform_c_string; + free(platform_c_string); + return PlatformResult(ErrorCode::NO_ERROR); + } } - out.insert(std::make_pair("networkType", picojson::value(type_str))); - return PlatformResult(ErrorCode::NO_ERROR); + const std::string error_msg = "Error when retrieving system setting information: " + + std::to_string(err); + LoggerE("%s", error_msg.c_str()); + return PlatformResult(ErrorCode::UNKNOWN_ERR, error_msg); } -static PlatformResult GetIps(wifi_ap_h wifi_ap_handle, std::string* ip_addr_str, - std::string* ipv6_addr_str){ - //getting ipv4 address - char* ip_addr = nullptr; - int error = wifi_ap_get_ip_address(wifi_ap_handle, - WIFI_ADDRESS_FAMILY_IPV4, - &ip_addr); - if (WIFI_ERROR_NONE != error) { - LoggerE("Failed to get ip address: %d", error); - return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get ip address"); +PlatformResult SysteminfoUtils::CheckTelephonySupport() { + bool supported = false; + PlatformResult ret = SystemInfoDeviceCapability::GetValueBool( + "tizen.org/feature/network.telephony", &supported); + if (ret.IsError()) { + return ret; } - *ip_addr_str = ip_addr; - free(ip_addr); - - //getting ipv6 address - ip_addr = nullptr; - error = wifi_ap_get_ip_address(wifi_ap_handle, - WIFI_ADDRESS_FAMILY_IPV6, - &ip_addr); - if (WIFI_ERROR_NONE != error) { - LoggerE("Failed to get ipv6 address: %d", error); - return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get ipv6 address"); + if (!supported) { + LoggerD("Telephony is not supported on this device"); + return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, + "Telephony is not supported on this device"); } - *ipv6_addr_str = ip_addr; - free(ip_addr); return PlatformResult(ErrorCode::NO_ERROR); } -PlatformResult SysteminfoUtils::ReportWifiNetwork(picojson::object& out) { - LoggerD("Entered"); - - bool result_status = false; - std::string result_ssid; - std::string result_ip_address; - std::string result_ipv6_address; - std::string result_mac_address; - double result_signal_strength = 0; - - // wifi_initialize() must be called in each thread - int error = wifi_initialize(); - if (WIFI_ERROR_NONE != error) { - std::string log_msg = "Initialize failed: " + parseWifiNetworkError(error); - LoggerE("%s", log_msg.c_str()); - return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); - } else { - LoggerD("WIFI initializatino succeed"); +PlatformResult SysteminfoUtils::CheckCameraFlashSupport() { + bool supported = false; + PlatformResult ret = SystemInfoDeviceCapability::GetValueBool( + "tizen.org/feature/camera.back.flash", &supported); + if (ret.IsError()) { + return ret; } - SCOPE_EXIT { - wifi_deinitialize(); - }; - - wifi_ap_h wifi_ap_handle = nullptr; - error = wifi_get_connected_ap(&wifi_ap_handle); - if (WIFI_ERROR_NONE != error) { - LoggerD("Error while wifi_get_connnected_ap: %s", parseWifiNetworkError(error).c_str()); - // in case of no connection, ignore error and leave status as false - if (WIFI_ERROR_NO_CONNECTION != error) { - std::string log_msg = "Cannot get connected access point handle: " + parseWifiNetworkError(error); - LoggerE("%s", log_msg.c_str()); - return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); - } - } else { - //if getting connected AP succeed, set status on true - result_status = true; - } - - if (result_status) { - std::unique_ptr::type, int(*)(wifi_ap_h)> - wifi_ap_handle_ptr(wifi_ap_handle, &wifi_ap_destroy); - // automatically release the memory - - //gathering mac address - char* mac = nullptr; - error = wifi_get_mac_address(&mac); - if (WIFI_ERROR_NONE == error && nullptr != mac) { - SLoggerD("MAC address fetched: %s", mac); - result_mac_address = mac; - free(mac); - } else { - std::string log_msg = "Failed to get mac address: " + parseWifiNetworkError(error); - LoggerE("%s", log_msg.c_str()); - return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); - } - - //refreshing access point information - error = wifi_ap_refresh(wifi_ap_handle); - if (WIFI_ERROR_NONE != error) { - std::string log_msg = "Failed to refresh access point information: " + parseWifiNetworkError(error); - LoggerE("%s", log_msg.c_str()); - return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); - } - - //gathering ssid - char* essid = nullptr; - error = wifi_ap_get_essid(wifi_ap_handle, &essid); - if (WIFI_ERROR_NONE == error) { - result_ssid = essid; - free(essid); - } else { - std::string log_msg = "Failed to get network ssid: " + parseWifiNetworkError(error); - LoggerE("%s", log_msg.c_str()); - return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); - } - - //gathering ips - PlatformResult ret = GetIps(wifi_ap_handle, &result_ip_address, &result_ipv6_address); - if (ret.IsError()) { - return ret; - } - - //gathering strength - wifi_rssi_level_e rssi_level = system_info_listeners.GetWifiLevel(); - // this mean that level was not initialized or wifi not connected - if (WIFI_RSSI_LEVEL_0 == rssi_level) { - // so try to gather rssi level with dedicated function - int rssi = 0; - error = wifi_ap_get_rssi(wifi_ap_handle, &rssi); - if (WIFI_ERROR_NONE == error) { - result_signal_strength = ((double) abs(rssi))/kWifiSignalStrengthDivideValue; - } else { - std::string log_msg = "Failed to get signal strength: " + parseWifiNetworkError(error); - LoggerE("%s", log_msg.c_str()); - return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); - } - } else { - result_signal_strength = ((double) rssi_level)/WIFI_RSSI_LEVEL_4; - } + if (!supported) { + LoggerD("Back-facing camera with a flash is not supported on this device"); + return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, + "Back-facing camera with a flash is not supported on this device"); } - //building result object - out.insert(std::make_pair("status", picojson::value(result_status ? kWifiStatusOn : kWifiStatusOff))); - out.insert(std::make_pair("ssid", picojson::value(result_ssid))); - out.insert(std::make_pair("ipAddress", picojson::value(result_ip_address))); - out.insert(std::make_pair("ipv6Address", picojson::value(result_ipv6_address))); - out.insert(std::make_pair("macAddress", picojson::value(result_mac_address))); - out.insert(std::make_pair("signalStrength", picojson::value(std::to_string(result_signal_strength)))); - return PlatformResult(ErrorCode::NO_ERROR); } -PlatformResult SysteminfoUtils::ReportEthernetNetwork(picojson::object& out) { +PlatformResult SysteminfoUtils::CheckIfEthernetNetworkSupported() +{ LoggerD("Entered"); - - std::string result_cable; - std::string result_status; - std::string result_ip_address; - std::string result_ipv6_address; - std::string result_mac_address; - connection_h connection_handle = nullptr; connection_ethernet_state_e connection_state = CONNECTION_ETHERNET_STATE_DEACTIVATED; - connection_type_e connection_type = CONNECTION_TYPE_DISCONNECTED; - connection_profile_h profile_handle = nullptr; - // connection must be created in every call, in other case error occurs int error = connection_create(&connection_handle); if (CONNECTION_ERROR_NONE != error) { std::string log_msg = "Cannot create connection: " + std::to_string(error); @@ -2292,620 +1518,50 @@ PlatformResult SysteminfoUtils::ReportEthernetNetwork(picojson::object& out) { return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); } std::unique_ptr::type, int (*)(connection_h)> connection_handle_ptr( - connection_handle, &connection_destroy); // automatically release the memory + connection_handle, &connection_destroy); // automatically release the memory error = connection_get_ethernet_state(connection_handle, &connection_state); - if (CONNECTION_ERROR_NONE != error) { - if (CONNECTION_ERROR_NOT_SUPPORTED == error) { - std::string log_msg = "Cannot get ethernet connection state: Not supported"; - LoggerE("%s", log_msg.c_str()); - return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, log_msg); - } - std::string log_msg = "Cannot get ethernet connection state: " + std::to_string(error); - LoggerE("%s", log_msg.c_str()); - return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); - } - - switch (connection_state) { - case CONNECTION_ETHERNET_STATE_DEACTIVATED: - result_status = "DEACTIVATED"; - break; - - case CONNECTION_ETHERNET_STATE_DISCONNECTED: - result_status = "DISCONNECTED"; - break; - - case CONNECTION_ETHERNET_STATE_CONNECTED: - result_status = "CONNECTED"; - break; - - default: - result_status = "UNKNOWN"; - break; - } - - connection_ethernet_cable_state_e cable_state = CONNECTION_ETHERNET_CABLE_DETACHED; - error = connection_get_ethernet_cable_state(connection_handle, &cable_state); - if (CONNECTION_ERROR_NONE != error) { - std::string log_msg = "Cannot get ethernet cable state: " + std::to_string(error); - LoggerE("%s", log_msg.c_str()); - return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); - } - - switch (cable_state) { - case CONNECTION_ETHERNET_CABLE_DETACHED: - result_cable = "DETACHED"; - break; - - case CONNECTION_ETHERNET_CABLE_ATTACHED: - result_cable = "ATTACHED"; - break; - - default: - result_cable = "UNKNOWN"; - break; - } - - char* mac = nullptr; - error = connection_get_mac_address(connection_handle, CONNECTION_TYPE_ETHERNET, &mac); - if (CONNECTION_ERROR_NONE == error && nullptr != mac) { - SLoggerD("MAC address fetched: %s", mac); - result_mac_address = mac; - free(mac); - } else { - std::string log_msg = "Failed to get mac address: " + std::to_string(error); - LoggerE("%s", log_msg.c_str()); - return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); - } - - error = connection_get_type(connection_handle, &connection_type); - if (CONNECTION_ERROR_NONE != error) { - std::string log_msg = "Cannot get connection type: " + std::to_string(error); + if (CONNECTION_ERROR_NOT_SUPPORTED == error) { + std::string log_msg = "Cannot get ethernet connection state: Not supported"; LoggerE("%s", log_msg.c_str()); - return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); - } - - if (CONNECTION_TYPE_ETHERNET == connection_type) { - //gathering profile - error = connection_get_current_profile(connection_handle, &profile_handle); - if (CONNECTION_ERROR_NONE != error) { - std::string log_msg = "Cannot get connection profile: " + std::to_string(error); - LoggerE("%s", log_msg.c_str()); - return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); - } - std::unique_ptr::type, - int (*)(connection_profile_h)> profile_handle_ptr( - profile_handle, &connection_profile_destroy); // automatically release the memory - - //gathering ips - PlatformResult ret = GetIps(profile_handle, &result_ip_address, &result_ipv6_address); - if (ret.IsError()) { - return ret; - } - } else { - LoggerD("Connection type = %d. ETHERNET is disabled", connection_type); + return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, log_msg); } - - out.insert(std::make_pair("cable", picojson::value(result_cable))); - out.insert(std::make_pair("status", picojson::value(result_status))); - out.insert(std::make_pair("ipAddress", picojson::value(result_ip_address))); - out.insert(std::make_pair("ipv6Address", picojson::value(result_ipv6_address))); - out.insert(std::make_pair("macAddress", picojson::value(result_mac_address))); - 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) +PlatformResult SysteminfoUtils::GetTotalMemory(long long* result) { 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); - LoggerE("%s", error_msg.c_str()); - return PlatformResult(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); - LoggerE("%s", error_msg.c_str()); - return PlatformResult(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); - LoggerE("%s", error_msg.c_str()); - return PlatformResult(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); - LoggerE("%s", error_msg.c_str()); - return PlatformResult(ErrorCode::UNKNOWN_ERR, error_msg); - } - *result_is_roaming = (0 != result_value) ? true : false; - - if (0 != vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &result_value)) { - LoggerE("Cannot get is_flight_mode value"); - return PlatformResult(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) -{ - LoggerD("Entered"); - connection_type_e connection_type = CONNECTION_TYPE_DISCONNECTED; - connection_profile_h profile_handle = nullptr; - connection_h connection_handle = nullptr; + unsigned int value = 0; - //connection must be created in every call, in other case error occurs - int error = connection_create(&connection_handle); - if (CONNECTION_ERROR_NONE != error) { - std::string log_msg = "Cannot create connection: " + std::to_string(error); + int ret = device_memory_get_total(&value); + if (ret != DEVICE_ERROR_NONE) { + std::string log_msg = "Failed to get total memory: " + std::to_string(ret); LoggerE("%s", log_msg.c_str()); return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); } - std::unique_ptr::type, int(*)(connection_h)> - connection_handle_ptr(connection_handle, &connection_destroy); - // automatically release the memory - - error = connection_get_type(connection_handle, &connection_type); - if (CONNECTION_ERROR_NONE != error) { - LoggerE("Failed to get connection type: %d", error); - return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get connection type"); - } - - char* apn = nullptr; - if (CONNECTION_TYPE_CELLULAR == connection_type) { - *result_status = kConnectionOn; - - error = connection_get_current_profile(connection_handle, - &profile_handle); - std::unique_ptr - ::type, int(*)(connection_profile_h)> - profile_handle_ptr(profile_handle, &connection_profile_destroy); - // automatically release the memory - if (CONNECTION_ERROR_NONE != error) { - LoggerE("Failed to get profile: %d", error); - return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get profile"); - } - - error = connection_profile_get_cellular_apn(profile_handle, &apn); - if (CONNECTION_ERROR_NONE != error) { - LoggerE("Failed to get apn name: %d", error); - return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get apn name"); - } - *result_apn = apn; - free(apn); - - PlatformResult ret = GetIps(profile_handle, result_ip_address, result_ipv6_address); - if (ret.IsError()) { - return ret; - } - } else { - *result_status = kConnectionOff; - - //According to previous implementation in case of error - //don't throw exception here - error = connection_get_default_cellular_service_profile( - connection_handle, - CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET, - &profile_handle); - std::unique_ptr - ::type, int(*)(connection_profile_h)> - profile_handle_ptr(profile_handle, &connection_profile_destroy); - // automatically release the memory - if (CONNECTION_ERROR_NONE == error) { - error = connection_profile_get_cellular_apn(profile_handle, &apn); - if (CONNECTION_ERROR_NONE == error) { - *result_apn = apn; - free(apn); - } else { - LoggerE("Failed to get default apn name: %d. Failing silently", - error); - } - } else { - LoggerE("Failed to get default profile: %d. Failing silently", - error); - } - } - 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 = ""; - } + *result = static_cast(value*MEMORY_TO_BYTE); return PlatformResult(ErrorCode::NO_ERROR); } -PlatformResult SysteminfoUtils::ReportCellularNetwork(picojson::object& out, unsigned long count) { - PlatformResult ret = CheckTelephonySupport(); - if (ret.IsError()) { - return ret; - } - std::string result_status; - std::string result_apn; - std::string result_ip_address; - std::string result_ipv6_address; - 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; - - //gathering vconf-based values - ret = FetchBasicSimProperties(system_info_listeners.GetTapiHandles()[count], &result_mcc, - &result_mnc, &result_cell_id, &result_lac, - &result_is_roaming, &result_is_flight_mode); - if (ret.IsError()) { - return ret; - } - //gathering connection informations - ret = FetchConnection(system_info_listeners.GetTapiHandles()[count], - &result_status, &result_apn, &result_ip_address, &result_ipv6_address, &result_imei); - if (ret.IsError()) { - return ret; - } - - out.insert(std::make_pair("status", picojson::value(result_status))); - out.insert(std::make_pair("apn", picojson::value(result_apn))); - out.insert(std::make_pair("ipAddress", picojson::value(result_ip_address))); - out.insert(std::make_pair("ipv6Address", picojson::value(result_ipv6_address))); - out.insert(std::make_pair("mcc", picojson::value(std::to_string(result_mcc)))); - out.insert(std::make_pair("mnc", picojson::value(std::to_string(result_mnc)))); - out.insert(std::make_pair("cellId", picojson::value(std::to_string(result_cell_id)))); - out.insert(std::make_pair("lac", picojson::value(std::to_string(result_lac)))); - out.insert(std::make_pair("isRoaming", picojson::value(result_is_roaming))); - out.insert(std::make_pair("isFligthMode", picojson::value(result_is_flight_mode))); - out.insert(std::make_pair("imei", picojson::value(result_imei))); - return PlatformResult(ErrorCode::NO_ERROR); -} - -void SimCphsValueCallback(TapiHandle */*handle*/, int result, void *data, void */*user_data*/) -{ - LoggerD("Entered"); - TelSimAccessResult_t access_rt = static_cast(result); - TelSimCphsNetName_t *cphs_info = static_cast(data); - - std::string result_operator; - if (TAPI_SIM_ACCESS_SUCCESS == access_rt) { - std::stringstream s; - s << cphs_info->full_name; - if (s.str().empty()) { - s << cphs_info->short_name; - } - result_operator = s.str(); - } else { - LoggerW("Failed to retrieve cphs_info: %d", access_rt); - } - sim_mgr.set_operator_name(result_operator); - sim_mgr.TryReturn(); -} - -void SimMsisdnValueCallback(TapiHandle */*handle*/, int result, void *data, void */*user_data*/) -{ - LoggerD("Entered"); - TelSimAccessResult_t access_rt = static_cast(result); - TelSimMsisdnList_t *msisdn_info = static_cast(data); - - std::string result_msisdn; - if (TAPI_SIM_ACCESS_SUCCESS == access_rt) { - if (msisdn_info->count > 0) { - if (strlen(msisdn_info->list[0].num) > 0) { - result_msisdn = msisdn_info->list[0].num; - } else { - LoggerW("MSISDN number empty"); - } - } else { - LoggerW("msisdn_info list empty"); - } - } else { - LoggerW("Failed to retrieve msisdn_: %d", access_rt); - } - - sim_mgr.set_msisdn(result_msisdn); - sim_mgr.TryReturn(); -} - -void SimSpnValueCallback(TapiHandle */*handle*/, int result, void *data, void */*user_data*/) +PlatformResult SysteminfoUtils::GetAvailableMemory(long long* result) { LoggerD("Entered"); - TelSimAccessResult_t access_rt = static_cast(result); - TelSimSpn_t *spn_info = static_cast(data); - - std::string result_spn; - if (TAPI_SIM_ACCESS_SUCCESS == access_rt) { - result_spn = (char *)spn_info->spn; - } else { - LoggerW("Failed to retrieve spn_: %d", access_rt); - } - - sim_mgr.set_spn(result_spn); - sim_mgr.TryReturn(); -} - -PlatformResult SysteminfoUtils::ReportSim(picojson::object& out, unsigned long count) { - PlatformResult ret = CheckTelephonySupport(); - if (ret.IsError()) { - return ret; - } - return sim_mgr.GatherSimInformation( - system_info_listeners.GetTapiHandles()[count], &out); -} - -PlatformResult SysteminfoUtils::ReportPeripheral(picojson::object& out) { - -/* int wireless_display_status = 0; - PlatformResult ret = GetVconfInt(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, wireless_display_status); - if (ret.IsSuccess()) { - if (VCONFKEY_MIRACAST_WFD_SOURCE_ON == wireless_display_status) { - out.insert(std::make_pair(kVideoOutputString, picojson::value(true))); - return PlatformResult(ErrorCode::NO_ERROR); - } - }*/ - int hdmi_status = 0; - PlatformResult ret = GetVconfInt(VCONFKEY_SYSMAN_HDMI, hdmi_status); - if (ret.IsSuccess()) { - if (VCONFKEY_SYSMAN_HDMI_CONNECTED == hdmi_status) { - out.insert(std::make_pair(kVideoOutputString, picojson::value(true))); - return PlatformResult(ErrorCode::NO_ERROR); - } - } - - out.insert(std::make_pair(kVideoOutputString, picojson::value(false))); - return PlatformResult(ErrorCode::NO_ERROR); -} - -PlatformResult SysteminfoUtils::ReportMemory(picojson::object& out) { - std::string state = MEMORY_STATE_NORMAL; - int status = 0; - PlatformResult ret = GetVconfInt(VCONFKEY_SYSMAN_LOW_MEMORY, status); - if (ret.IsSuccess()) { - switch (status) { - case VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING: - case VCONFKEY_SYSMAN_LOW_MEMORY_HARD_WARNING: - state = MEMORY_STATE_WARNING; - break; - case VCONFKEY_SYSMAN_LOW_MEMORY_NORMAL: - default: - state = MEMORY_STATE_NORMAL; - } - } - - out.insert(std::make_pair("state", picojson::value(state))); - return PlatformResult(ErrorCode::NO_ERROR); -} - -static void CreateStorageInfo(const std::string& type, struct statfs& fs, picojson::object* out) { - out->insert(std::make_pair("type", picojson::value(type))); - out->insert(std::make_pair("capacity", picojson::value(std::to_string( - static_cast(fs.f_bsize) * - static_cast(fs.f_blocks))))); - out->insert(std::make_pair("availableCapacity", picojson::value(std::to_string( - static_cast(fs.f_bsize) * - static_cast(fs.f_bavail))))); - bool isRemovable = (type == kTypeInternal) ? false : true; - out->insert(std::make_pair("isRemovable", picojson::value(isRemovable))); -} - -PlatformResult SysteminfoUtils::ReportStorage(picojson::object& out) { - int sdcardState = 0; - struct statfs fs; - - picojson::value result = picojson::value(picojson::array()); - - picojson::array& array = result.get(); - array.push_back(picojson::value(picojson::object())); - picojson::object& internal_obj = array.back().get(); - - if (statfs(kStorageInternalPath, &fs) < 0) { - LoggerE("There are no storage units detected"); - return PlatformResult(ErrorCode::UNKNOWN_ERR, "There are no storage units detected"); - } - CreateStorageInfo(kTypeInternal, fs, &internal_obj); - system_info_listeners.SetAvailableCapacityInternal(fs.f_bavail); - if (0 == vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &sdcardState)) { - if (VCONFKEY_SYSMAN_MMC_MOUNTED == sdcardState){ - if (statfs(kStorageSdcardPath, &fs) < 0) { - LoggerE("MMC mounted, but not accessible"); - return PlatformResult(ErrorCode::UNKNOWN_ERR, "MMC mounted, but not accessible"); - } - array.push_back(picojson::value(picojson::object())); - picojson::object& external_obj = array.back().get(); - CreateStorageInfo(kTypeMmc, fs, &external_obj); - system_info_listeners.SetAvailableCapacityMmc(fs.f_bavail); - } - } - - out.insert(std::make_pair("storages", picojson::value(result))); - return PlatformResult(ErrorCode::NO_ERROR); -} -PlatformResult SysteminfoUtils::ReportCameraFlash(picojson::object& out, - unsigned long index) { + unsigned int value = 0; - if (index < system_info_listeners.GetCameraTypesCount()) { - std::string camera = system_info_listeners.GetCameraTypes(index); - out.insert(std::make_pair("camera", picojson::value(camera))); - } else { - return PlatformResult( - ErrorCode::NOT_SUPPORTED_ERR, - "Camera is not supported on this device"); + int ret = device_memory_get_available(&value); + if (ret != DEVICE_ERROR_NONE) { + std::string log_msg = "Failed to get total memory: " + std::to_string(ret); + LoggerE("%s", log_msg.c_str()); + return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); } + *result = static_cast(value*MEMORY_TO_BYTE); return PlatformResult(ErrorCode::NO_ERROR); } -PlatformResult SysteminfoUtils::RegisterBatteryListener(const SysteminfoUtilsCallback& callback, - SysteminfoInstance& instance) -{ - return system_info_listeners.RegisterBatteryListener(callback, instance); -} - -PlatformResult SysteminfoUtils::UnregisterBatteryListener() -{ - return system_info_listeners.UnregisterBatteryListener(); -} - - -PlatformResult SysteminfoUtils::RegisterCpuListener(const SysteminfoUtilsCallback& callback, - SysteminfoInstance& instance) -{ - return system_info_listeners.RegisterCpuListener(callback, instance); -} - -PlatformResult SysteminfoUtils::UnregisterCpuListener() -{ - return system_info_listeners.UnregisterCpuListener(); -} - - -PlatformResult SysteminfoUtils::RegisterStorageListener(const SysteminfoUtilsCallback& callback, - SysteminfoInstance& instance) -{ - return system_info_listeners.RegisterStorageListener(callback, instance); -} - -PlatformResult SysteminfoUtils::UnregisterStorageListener() -{ - return system_info_listeners.UnregisterStorageListener(); -} - -PlatformResult SysteminfoUtils::RegisterDisplayListener(const SysteminfoUtilsCallback& callback, - SysteminfoInstance& instance) -{ - return system_info_listeners.RegisterDisplayListener(callback, instance); -} - -PlatformResult SysteminfoUtils::UnregisterDisplayListener() -{ - return system_info_listeners.UnregisterDisplayListener(); -} - -PlatformResult SysteminfoUtils::RegisterDeviceOrientationListener(const SysteminfoUtilsCallback& callback, - SysteminfoInstance& instance) -{ - return system_info_listeners.RegisterDeviceOrientationListener(callback, instance); -} - -PlatformResult SysteminfoUtils::UnregisterDeviceOrientationListener() -{ - return system_info_listeners.UnregisterDeviceOrientationListener(); -} - -PlatformResult SysteminfoUtils::RegisterLocaleListener(const SysteminfoUtilsCallback& callback, - SysteminfoInstance& instance) -{ - return system_info_listeners.RegisterLocaleListener(callback, instance); -} - -PlatformResult SysteminfoUtils::UnregisterLocaleListener() -{ - return system_info_listeners.UnregisterLocaleListener(); -} - -PlatformResult SysteminfoUtils::RegisterNetworkListener(const SysteminfoUtilsCallback& callback, - SysteminfoInstance& instance) -{ - return system_info_listeners.RegisterNetworkListener(callback, instance); -} - -PlatformResult SysteminfoUtils::UnregisterNetworkListener() -{ - return system_info_listeners.UnregisterNetworkListener(); -} - -PlatformResult SysteminfoUtils::RegisterWifiNetworkListener(const SysteminfoUtilsCallback& callback, - SysteminfoInstance& instance) -{ - return system_info_listeners.RegisterWifiNetworkListener(callback, instance); -} - -PlatformResult SysteminfoUtils::UnregisterWifiNetworkListener() -{ - return system_info_listeners.UnregisterWifiNetworkListener(); -} - -PlatformResult SysteminfoUtils::RegisterEthernetNetworkListener(const SysteminfoUtilsCallback& callback, - SysteminfoInstance& instance) -{ - LoggerD("Entered"); - return system_info_listeners.RegisterEthernetNetworkListener(callback, instance); -} - -PlatformResult SysteminfoUtils::UnregisterEthernetNetworkListener() -{ - LoggerD("Entered"); - return system_info_listeners.UnregisterEthernetNetworkListener(); -} - -PlatformResult SysteminfoUtils::RegisterCellularNetworkListener(const SysteminfoUtilsCallback& callback, - SysteminfoInstance& instance) -{ - return system_info_listeners.RegisterCellularNetworkListener(callback, instance); -} - -PlatformResult SysteminfoUtils::UnregisterCellularNetworkListener() -{ - return system_info_listeners.UnregisterCellularNetworkListener(); -} - -PlatformResult SysteminfoUtils::RegisterPeripheralListener(const SysteminfoUtilsCallback& callback, - SysteminfoInstance& instance) -{ - return system_info_listeners.RegisterPeripheralListener(callback, instance); -} - -PlatformResult SysteminfoUtils::UnregisterPeripheralListener() -{ - return system_info_listeners.UnregisterPeripheralListener(); -} - -PlatformResult SysteminfoUtils::RegisterMemoryListener(const SysteminfoUtilsCallback& callback, - SysteminfoInstance& instance) -{ - return system_info_listeners.RegisterMemoryListener(callback, instance); -} - -PlatformResult SysteminfoUtils::UnregisterMemoryListener() -{ - return system_info_listeners.UnregisterMemoryListener(); -} - -PlatformResult SysteminfoUtils::RegisterCameraFlashListener(const SysteminfoUtilsCallback& callback, - SysteminfoInstance& instance) -{ - return system_info_listeners.RegisterCameraFlashListener(callback, instance); -} - -PlatformResult SysteminfoUtils::UnregisterCameraFlashListener() -{ - return system_info_listeners.UnregisterCameraFlashListener(); -} - } // namespace systeminfo } // namespace webapi diff --git a/src/systeminfo/systeminfo-utils.h b/src/systeminfo/systeminfo-utils.h index 19060b8f..2f7a034d 100644 --- a/src/systeminfo/systeminfo-utils.h +++ b/src/systeminfo/systeminfo-utils.h @@ -19,6 +19,7 @@ #include #include +#include #include "common/picojson.h" #include "common/platform_result.h" #include "systeminfo/systeminfo_device_capability.h" @@ -40,11 +41,14 @@ typedef std::function SysteminfoUtilsCallbac class SysteminfoUtils { public: - static common::PlatformResult GetTotalMemory(long long& result); - static common::PlatformResult GetAvailableMemory(long long& result); - static common::PlatformResult GetCount(const std::string& property, unsigned long& ret); - static common::PlatformResult GetPropertyValue( - const std::string& prop, bool is_array_type, picojson::value& res); + static common::PlatformResult GetVconfInt(const char *key, int *value); + static common::PlatformResult GetRuntimeInfoString(system_settings_key_e key, + std::string* platform_string); + static common::PlatformResult CheckTelephonySupport(); + static common::PlatformResult CheckCameraFlashSupport(); + static common::PlatformResult CheckIfEthernetNetworkSupported(); + static common::PlatformResult GetTotalMemory(long long* result); + static common::PlatformResult GetAvailableMemory(long long* result); static common::PlatformResult RegisterBatteryListener(const SysteminfoUtilsCallback& callback, SysteminfoInstance& instance); @@ -87,26 +91,6 @@ class SysteminfoUtils { static common::PlatformResult UnregisterCameraFlashListener(); private: - static common::PlatformResult ReportProperty(const std::string& property, int index, - picojson::object& res_obj); - static common::PlatformResult ReportBattery(picojson::object& out); - static common::PlatformResult ReportCpu(picojson::object& out); - - static common::PlatformResult ReportDisplay(picojson::object& out); - static common::PlatformResult ReportDeviceOrientation(picojson::object& out); - - static common::PlatformResult ReportBuild(picojson::object& out); - static common::PlatformResult ReportLocale(picojson::object& out); - static common::PlatformResult ReportNetwork(picojson::object& out); - static common::PlatformResult ReportWifiNetwork(picojson::object& out); - static common::PlatformResult ReportEthernetNetwork(picojson::object& out); - static common::PlatformResult ReportCellularNetwork(picojson::object& out, unsigned long count); - static common::PlatformResult ReportSim(picojson::object& out, unsigned long count); - static common::PlatformResult ReportPeripheral(picojson::object& out); - static common::PlatformResult ReportMemory(picojson::object& out); - static common::PlatformResult ReportCameraFlash(picojson::object& out, unsigned long count); - - static common::PlatformResult ReportStorage(picojson::object& out); }; typedef unsigned char byte; diff --git a/src/systeminfo/systeminfo.gyp b/src/systeminfo/systeminfo.gyp index a4ffa45d..0180fc70 100644 --- a/src/systeminfo/systeminfo.gyp +++ b/src/systeminfo/systeminfo.gyp @@ -23,6 +23,8 @@ 'systeminfo_device_capability.h', 'systeminfo_properties_manager.cc', 'systeminfo_properties_manager.h', + 'systeminfo_sim_details_manager.cc', + 'systeminfo_sim_details_manager.h', ], 'includes': [ '../common/pkg-config.gypi', diff --git a/src/systeminfo/systeminfo_instance.cc b/src/systeminfo/systeminfo_instance.cc index b5a7a62a..f6541e1f 100644 --- a/src/systeminfo/systeminfo_instance.cc +++ b/src/systeminfo/systeminfo_instance.cc @@ -31,8 +31,9 @@ namespace extension { namespace systeminfo { -using namespace common; -using namespace extension::systeminfo; +using common::PlatformResult; +using common::ErrorCode; +using common::TypeMismatchException; //Callback functions declarations static void OnBatteryChangedCallback(SysteminfoInstance& instance); @@ -178,33 +179,7 @@ void SysteminfoInstance::GetPropertyValue(const picojson::value& args, picojson: void SysteminfoInstance::GetPropertyValueArray(const picojson::value& args, picojson::object& out) { LoggerD("Enter"); - CHECK_EXIST(args, "callbackId", out) - CHECK_EXIST(args, "property", out) - const double callback_id = args.get("callbackId").get(); - const std::string& prop_id = args.get("property").get(); - LoggerD("Getting property arrray with id: %s ", prop_id.c_str()); - - auto get = [this, prop_id, callback_id](const std::shared_ptr& response) -> void { - LoggerD("Getting"); - picojson::value result = picojson::value(picojson::object()); - PlatformResult ret = SysteminfoUtils::GetPropertyValue(prop_id, true, result); - if (ret.IsError()) { - LoggerE("Failed: GetPropertyValue()"); - ReportError(ret,&(response->get())); - return; - } - ReportSuccess(result, response->get()); - }; - - auto get_response = [this, callback_id](const std::shared_ptr& response) -> void { - LoggerD("Getting response"); - picojson::object& obj = response->get(); - obj.insert(std::make_pair("callbackId", picojson::value(callback_id))); - Instance::PostMessage(this, response->serialize().c_str()); - }; - - TaskQueue::GetInstance().Queue - (get, get_response, std::shared_ptr(new picojson::value(picojson::object()))); + manager_.GetPropertyValueArray(args, &out); } void SysteminfoInstance::AddPropertyValueChangeListener(const picojson::value& args, picojson::object& out) { @@ -261,66 +236,6 @@ void SysteminfoInstance::AddPropertyValueChangeListener(const picojson::value& a ReportError(ret, &out); } -void SysteminfoInstance::GetTotalMemory(const picojson::value& args, picojson::object& out) { - LoggerD("Enter"); - picojson::value result = picojson::value(picojson::object()); - picojson::object& result_obj = result.get(); - - long long return_value = 0; - PlatformResult ret = SysteminfoUtils::GetTotalMemory(return_value); - if (ret.IsError()) { - LoggerD("Error"); - ReportError(ret, &out); - return; - } - result_obj.insert(std::make_pair("totalMemory", - picojson::value(static_cast(return_value)))); - - ReportSuccess(result, out); - LoggerD("Success"); -} - -void SysteminfoInstance::GetAvailableMemory(const picojson::value& args, picojson::object& out) { - LoggerD("Enter"); - picojson::value result = picojson::value(picojson::object()); - picojson::object& result_obj = result.get(); - - long long return_value = 0; - PlatformResult ret = SysteminfoUtils::GetAvailableMemory(return_value); - if (ret.IsError()) { - LoggerD("Error"); - ReportError(ret, &out); - return; - } - result_obj.insert(std::make_pair("availableMemory", - picojson::value(static_cast(return_value)))); - - ReportSuccess(result, out); - LoggerD("Success"); -} - -void SysteminfoInstance::GetCount(const picojson::value& args, picojson::object& out) { - - LoggerD("Enter"); - CHECK_EXIST(args, "property", out) - const std::string& property = args.get("property").get(); - LoggerD("Getting count of property with id: %s ", property.c_str()); - - picojson::value result = picojson::value(picojson::object()); - picojson::object& result_obj = result.get(); - unsigned long count = 0; - PlatformResult ret = SysteminfoUtils::GetCount(property, count); - if (ret.IsError()) { - LoggerE("Failed: GetCount()"); - ReportError(ret, &out); - return; - } - result_obj.insert(std::make_pair("count", picojson::value(static_cast(count)))); - - ReportSuccess(result, out); - LoggerD("Success"); -} - void SysteminfoInstance::RemovePropertyValueChangeListener(const picojson::value& args, picojson::object& out) { LoggerD("Enter"); @@ -375,9 +290,20 @@ void SysteminfoInstance::RemovePropertyValueChangeListener(const picojson::value ReportError(ret, &out); } -static void ReportSuccess(const picojson::value& result, picojson::object& out) { - out.insert(std::make_pair("status", picojson::value("success"))); - out.insert(std::make_pair("result", picojson::value(result))); +void SysteminfoInstance::GetTotalMemory(const picojson::value& args, picojson::object& out) { + LoggerD("Enter"); + manager_.GetTotalMemory(args, &out); +} + +void SysteminfoInstance::GetAvailableMemory(const picojson::value& args, picojson::object& out) { + LoggerD("Enter"); + manager_.GetAvailableMemory(args, &out); +} + +void SysteminfoInstance::GetCount(const picojson::value& args, picojson::object& out) { + + LoggerD("Enter"); + manager_.GetCount(args, &out); } void SysteminfoInstance::SetBrightness(const picojson::value& args, picojson::object& out) { @@ -437,11 +363,11 @@ void OnBatteryChangedCallback(SysteminfoInstance& instance) response->get()[kListenerIdString] = picojson::value(kListenerConstValue); picojson::value result = picojson::value(picojson::object()); - PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdBattery, true, result); - if (ret.IsSuccess()) { - ReportSuccess(result,response->get()); - Instance::PostMessage(&instance, response->serialize().c_str()); - } +// PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdBattery, true, result); +// if (ret.IsSuccess()) { +// ReportSuccess(result,response->get()); +// Instance::PostMessage(&instance, response->serialize().c_str()); +// } } void OnCpuChangedCallback(SysteminfoInstance& instance) @@ -453,11 +379,11 @@ void OnCpuChangedCallback(SysteminfoInstance& instance) response->get()[kListenerIdString] = picojson::value(kListenerConstValue); picojson::value result = picojson::value(picojson::object()); - PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdCpu, true, result); - if (ret.IsSuccess()) { - ReportSuccess(result,response->get()); - Instance::PostMessage(&instance, response->serialize().c_str()); - } +// PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdCpu, true, result); +// if (ret.IsSuccess()) { +// ReportSuccess(result,response->get()); +// Instance::PostMessage(&instance, response->serialize().c_str()); +// } } void OnStorageChangedCallback(SysteminfoInstance& instance) @@ -469,11 +395,11 @@ void OnStorageChangedCallback(SysteminfoInstance& instance) response->get()[kListenerIdString] = picojson::value(kListenerConstValue); picojson::value result = picojson::value(picojson::object()); - PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdStorage, true, result); - if (ret.IsSuccess()) { - ReportSuccess(result,response->get()); - Instance::PostMessage(&instance, response->serialize().c_str()); - } +// PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdStorage, true, result); +// if (ret.IsSuccess()) { +// ReportSuccess(result,response->get()); +// Instance::PostMessage(&instance, response->serialize().c_str()); +// } } void OnDisplayChangedCallback(SysteminfoInstance& instance) @@ -485,11 +411,11 @@ void OnDisplayChangedCallback(SysteminfoInstance& instance) response->get()[kListenerIdString] = picojson::value(kListenerConstValue); picojson::value result = picojson::value(picojson::object()); - PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdDisplay, true, result); - if (ret.IsSuccess()) { - ReportSuccess(result,response->get()); - Instance::PostMessage(&instance, response->serialize().c_str()); - } +// PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdDisplay, true, result); +// if (ret.IsSuccess()) { +// ReportSuccess(result,response->get()); +// Instance::PostMessage(&instance, response->serialize().c_str()); +// } } void OnDeviceOrientationChangedCallback(SysteminfoInstance& instance) @@ -501,11 +427,11 @@ void OnDeviceOrientationChangedCallback(SysteminfoInstance& instance) response->get()[kListenerIdString] = picojson::value(kListenerConstValue); picojson::value result = picojson::value(picojson::object()); - PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdDeviceOrientation, true, result); - if (ret.IsSuccess()) { - ReportSuccess(result,response->get()); - Instance::PostMessage(&instance, response->serialize().c_str()); - } +// PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdDeviceOrientation, true, result); +// if (ret.IsSuccess()) { +// ReportSuccess(result,response->get()); +// Instance::PostMessage(&instance, response->serialize().c_str()); +// } } void OnLocaleChangedCallback(SysteminfoInstance& instance) @@ -517,11 +443,11 @@ void OnLocaleChangedCallback(SysteminfoInstance& instance) response->get()[kListenerIdString] = picojson::value(kListenerConstValue); picojson::value result = picojson::value(picojson::object()); - PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdLocale, true, result); - if (ret.IsSuccess()) { - ReportSuccess(result,response->get()); - Instance::PostMessage(&instance, response->serialize().c_str()); - } +// PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdLocale, true, result); +// if (ret.IsSuccess()) { +// ReportSuccess(result,response->get()); +// Instance::PostMessage(&instance, response->serialize().c_str()); +// } } void OnNetworkChangedCallback(SysteminfoInstance& instance) @@ -533,11 +459,11 @@ void OnNetworkChangedCallback(SysteminfoInstance& instance) response->get()[kListenerIdString] = picojson::value(kListenerConstValue); picojson::value result = picojson::value(picojson::object()); - PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdNetwork, true, result); - if (ret.IsSuccess()) { - ReportSuccess(result,response->get()); - Instance::PostMessage(&instance, response->serialize().c_str()); - } +// PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdNetwork, true, result); +// if (ret.IsSuccess()) { +// ReportSuccess(result,response->get()); +// Instance::PostMessage(&instance, response->serialize().c_str()); +// } } void OnWifiNetworkChangedCallback(SysteminfoInstance& instance) @@ -549,11 +475,11 @@ void OnWifiNetworkChangedCallback(SysteminfoInstance& instance) response->get()[kListenerIdString] = picojson::value(kListenerConstValue); picojson::value result = picojson::value(picojson::object()); - PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdWifiNetwork, true, result); - if (ret.IsSuccess()) { - ReportSuccess(result,response->get()); - Instance::PostMessage(&instance, response->serialize().c_str()); - } +// PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdWifiNetwork, true, result); +// if (ret.IsSuccess()) { +// ReportSuccess(result,response->get()); +// Instance::PostMessage(&instance, response->serialize().c_str()); +// } } void OnEthernetNetworkChangedCallback(SysteminfoInstance& instance) @@ -565,11 +491,11 @@ void OnEthernetNetworkChangedCallback(SysteminfoInstance& instance) response->get()[kListenerIdString] = picojson::value(kListenerConstValue); picojson::value result = picojson::value(picojson::object()); - PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdEthernetNetwork, true, result); - if (ret.IsSuccess()) { - ReportSuccess(result,response->get()); - Instance::PostMessage(&instance, response->serialize().c_str()); - } +// PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdEthernetNetwork, true, result); +// if (ret.IsSuccess()) { +// ReportSuccess(result,response->get()); +// Instance::PostMessage(&instance, response->serialize().c_str()); +// } } void OnCellularNetworkChangedCallback(SysteminfoInstance& instance) @@ -581,11 +507,11 @@ void OnCellularNetworkChangedCallback(SysteminfoInstance& instance) response->get()[kListenerIdString] = picojson::value(kListenerConstValue); picojson::value result = picojson::value(picojson::object()); - PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdCellularNetwork, true, result); - if (ret.IsSuccess()) { - ReportSuccess(result,response->get()); - Instance::PostMessage(&instance, response->serialize().c_str()); - } +// PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdCellularNetwork, true, result); +// if (ret.IsSuccess()) { +// ReportSuccess(result,response->get()); +// Instance::PostMessage(&instance, response->serialize().c_str()); +// } } void OnPeripheralChangedCallback(SysteminfoInstance& instance) @@ -597,11 +523,11 @@ void OnPeripheralChangedCallback(SysteminfoInstance& instance) response->get()[kListenerIdString] = picojson::value(kListenerConstValue); picojson::value result = picojson::value(picojson::object()); - PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdPeripheral, true, result); - if (ret.IsSuccess()) { - ReportSuccess(result,response->get()); - Instance::PostMessage(&instance, response->serialize().c_str()); - } +// PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdPeripheral, true, result); +// if (ret.IsSuccess()) { +// ReportSuccess(result,response->get()); +// Instance::PostMessage(&instance, response->serialize().c_str()); +// } } void OnMemoryChangedCallback(SysteminfoInstance& instance) @@ -613,11 +539,11 @@ void OnMemoryChangedCallback(SysteminfoInstance& instance) response->get()[kListenerIdString] = picojson::value(kListenerConstValue); picojson::value result = picojson::value(picojson::object()); - PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdMemory, true, result); - if (ret.IsSuccess()) { - ReportSuccess(result,response->get()); - Instance::PostMessage(&instance, response->serialize().c_str()); - } +// PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdMemory, true, result); +// if (ret.IsSuccess()) { +// ReportSuccess(result,response->get()); +// Instance::PostMessage(&instance, response->serialize().c_str()); +// } } void OnBrigthnessChangedCallback(SysteminfoInstance &instance) @@ -629,11 +555,11 @@ void OnBrigthnessChangedCallback(SysteminfoInstance &instance) response->get()[kListenerIdString] = picojson::value(kListenerConstValue); picojson::value result = picojson::value(picojson::object()); - PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdCameraFlash, true, result); - if (ret.IsSuccess()) { - ReportSuccess(result,response->get()); - Instance::PostMessage(&instance, response->serialize().c_str()); - } +// PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdCameraFlash, true, result); +// if (ret.IsSuccess()) { +// ReportSuccess(result,response->get()); +// Instance::PostMessage(&instance, response->serialize().c_str()); +// } } } // namespace systeminfo diff --git a/src/systeminfo/systeminfo_manager.cc b/src/systeminfo/systeminfo_manager.cc index 020fa125..307f2b9e 100644 --- a/src/systeminfo/systeminfo_manager.cc +++ b/src/systeminfo/systeminfo_manager.cc @@ -19,8 +19,12 @@ #include #include +#include +#include + #include "systeminfo/systeminfo_instance.h" #include "systeminfo/systeminfo_device_capability.h" +#include "systeminfo/systeminfo-utils.h" #include "common/logger.h" #include "common/converter.h" #include "common/task-queue.h" @@ -37,6 +41,8 @@ namespace extension { namespace systeminfo { namespace { +const int kDefaultPropertyCount = 1; + #define CHECK_EXIST(args, name, out) \ if (!args.contains(name)) {\ ReportError(TypeMismatchException(name" is required argument"), *out);\ @@ -86,11 +92,51 @@ namespace { } //namespace SysteminfoManager::SysteminfoManager(SysteminfoInstance* instance) - : instance_(instance){ + : instance_(instance), + prop_manager_(*this), + sensor_handle_(-1), + wifi_level_(WIFI_RSSI_LEVEL_0), + cpu_load_(0), + available_capacity_internal_(0), + available_capacity_mmc_(0), + sim_count_(0), + tapi_handles_{nullptr} { + LoggerD("Entered"); + int error = wifi_initialize(); + if (WIFI_ERROR_NONE != error) { + std::string log_msg = "Initialize failed: " + std::string(get_error_message(error)); + LoggerE("%s", log_msg.c_str()); + } else { + LoggerD("WIFI initialization succeed"); + } + + //TODO +// error = wifi_set_rssi_level_changed_cb(OnWifiLevelChangedCb, nullptr); +// if (WIFI_ERROR_NONE != error) { +// std::string log_msg = "Setting wifi listener failed: " + parseWifiNetworkError(error); +// LoggerE("%s", log_msg.c_str()); +// } else { +// LoggerD("Setting wifi listener succeed"); +// } + InitCameraTypes(); } SysteminfoManager::~SysteminfoManager() { LoggerD("Enter"); + DisconnectSensor(sensor_handle_); + + + unsigned int i = 0; + while(tapi_handles_[i]) { + tel_deinit(tapi_handles_[i]); + i++; + } +//TODO +// if (nullptr != m_connection_handle) { +// connection_destroy(m_connection_handle); +// } + + wifi_deinitialize(); } void SysteminfoManager::GetCapabilities(const picojson::value& args, picojson::object* out) { @@ -233,27 +279,87 @@ void SysteminfoManager::GetPropertyValueArray(const picojson::value& args, picoj const std::string& prop_id = args.get("property").get(); LoggerD("Getting property arrray with id: %s ", prop_id.c_str()); -// auto get = [this, prop_id, callback_id](const std::shared_ptr& response) -> void { -// LoggerD("Getting"); -// picojson::value result = picojson::value(picojson::object()); -// PlatformResult ret = SysteminfoUtils::GetPropertyValue(prop_id, true, result); -// if (ret.IsError()) { -// LoggerE("Failed: GetPropertyValue()"); -// ReportError(ret,&(response->get())); -// return; -// } -// ReportSuccess(result, response->get()); -// }; -// -// auto get_response = [this, callback_id](const std::shared_ptr& response) -> void { -// LoggerD("Getting response"); -// picojson::object& obj = response->get(); -// obj.insert(std::make_pair("callbackId", picojson::value(callback_id))); -// PostMessage(response->serialize().c_str()); -// }; -// -// TaskQueue::GetInstance().Queue -// (get, get_response, std::shared_ptr(new picojson::value(picojson::object()))); + auto get = [this, prop_id, callback_id](const std::shared_ptr& response) -> void { + LoggerD("Getting"); + picojson::value result = picojson::value(picojson::object()); + + PlatformResult ret = prop_manager_.GetPropertyValue(prop_id, true, &result); + if (ret.IsError()) { + LoggerE("Failed: GetPropertyValue()"); + ReportError(ret,&(response->get())); + return; + } + ReportSuccess(result, response->get()); + }; + + auto get_response = [this, callback_id](const std::shared_ptr& response) -> void { + LoggerD("Getting response"); + picojson::object& obj = response->get(); + obj.insert(std::make_pair("callbackId", picojson::value(callback_id))); + Instance::PostMessage(instance_, response->serialize().c_str()); + }; + + TaskQueue::GetInstance().Queue + (get, get_response, std::shared_ptr(new picojson::value(picojson::object()))); +} + +void SysteminfoManager::GetTotalMemory(const picojson::value& args, picojson::object* out) { + LoggerD("Enter"); + picojson::value result = picojson::value(picojson::object()); + picojson::object& result_obj = result.get(); + + long long return_value = 0; + PlatformResult ret = SysteminfoUtils::GetTotalMemory(&return_value); + if (ret.IsError()) { + LoggerD("Error"); + ReportError(ret, out); + return; + } + result_obj.insert(std::make_pair("totalMemory", + picojson::value(static_cast(return_value)))); + + ReportSuccess(result, *out); + LoggerD("Success"); +} + +void SysteminfoManager::GetAvailableMemory(const picojson::value& args, picojson::object* out) { + LoggerD("Enter"); + picojson::value result = picojson::value(picojson::object()); + picojson::object& result_obj = result.get(); + + long long return_value = 0; + PlatformResult ret = SysteminfoUtils::GetAvailableMemory(&return_value); + if (ret.IsError()) { + LoggerD("Error"); + ReportError(ret, out); + return; + } + result_obj.insert(std::make_pair("availableMemory", + picojson::value(static_cast(return_value)))); + + ReportSuccess(result, *out); + LoggerD("Success"); +} + +void SysteminfoManager::GetCount(const picojson::value& args, picojson::object* out) { + LoggerD("Enter"); + CHECK_EXIST(args, "property", out) + const std::string& property = args.get("property").get(); + LoggerD("Getting count of property with id: %s ", property.c_str()); + + picojson::value result = picojson::value(picojson::object()); + picojson::object& result_obj = result.get(); + unsigned long count = 0; + PlatformResult ret = GetPropertyCount(property, &count); + if (ret.IsError()) { + LoggerE("Failed: GetCount()"); + ReportError(ret, out); + return; + } + result_obj.insert(std::make_pair("count", picojson::value(static_cast(count)))); + + ReportSuccess(result, *out); + LoggerD("Success"); } void SysteminfoManager::AddPropertyValueChangeListener(const picojson::value& args, picojson::object* out) { @@ -310,66 +416,6 @@ void SysteminfoManager::AddPropertyValueChangeListener(const picojson::value& ar // ReportError(ret, &out); } -void SysteminfoManager::GetTotalMemory(const picojson::value& args, picojson::object* out) { - LoggerD("Enter"); - picojson::value result = picojson::value(picojson::object()); - picojson::object& result_obj = result.get(); - - long long return_value = 0; -// PlatformResult ret = SysteminfoUtils::GetTotalMemory(return_value); -// if (ret.IsError()) { -// LoggerD("Error"); -// ReportError(ret, &out); -// return; -// } -// result_obj.insert(std::make_pair("totalMemory", -// picojson::value(static_cast(return_value)))); -// -// ReportSuccess(result, out); -// LoggerD("Success"); -} - -void SysteminfoManager::GetAvailableMemory(const picojson::value& args, picojson::object* out) { - LoggerD("Enter"); - picojson::value result = picojson::value(picojson::object()); - picojson::object& result_obj = result.get(); - - long long return_value = 0; -// PlatformResult ret = SysteminfoUtils::GetAvailableMemory(return_value); -// if (ret.IsError()) { -// LoggerD("Error"); -// ReportError(ret, &out); -// return; -// } -// result_obj.insert(std::make_pair("availableMemory", -// picojson::value(static_cast(return_value)))); -// -// ReportSuccess(result, out); -// LoggerD("Success"); -} - -void SysteminfoManager::GetCount(const picojson::value& args, picojson::object* out) { - - LoggerD("Enter"); - CHECK_EXIST(args, "property", out) - const std::string& property = args.get("property").get(); - LoggerD("Getting count of property with id: %s ", property.c_str()); - - picojson::value result = picojson::value(picojson::object()); - picojson::object& result_obj = result.get(); - unsigned long count = 0; -// PlatformResult ret = SysteminfoUtils::GetCount(property, count); -// if (ret.IsError()) { -// LoggerE("Failed: GetCount()"); -// ReportError(ret, &out); -// return; -// } -// result_obj.insert(std::make_pair("count", picojson::value(static_cast(count)))); -// -// ReportSuccess(result, out); -// LoggerD("Success"); -} - void SysteminfoManager::RemovePropertyValueChangeListener(const picojson::value& args, picojson::object* out) { LoggerD("Enter"); @@ -430,39 +476,218 @@ void SysteminfoManager::SetBrightness(const picojson::value& args, picojson::obj CHECK_EXIST(args, "brightness", out) const double brightness = args.get("brightness").get(); -// int result = device_flash_set_brightness(brightness); -// if (result != DEVICE_ERROR_NONE) { -// LoggerE("Error occured"); -// ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Error occured"), &out); -// return; -// } -// ReportSuccess(out); + int result = device_flash_set_brightness(brightness); + if (result != DEVICE_ERROR_NONE) { + LoggerE("Error occured"); + ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Error occured"), out); + return; + } + ReportSuccess(*out); } void SysteminfoManager::GetBrightness(const picojson::value& args, picojson::object* out) { LoggerD("entered"); int brightness = 0; -// int result = device_flash_get_brightness(&brightness); -// if (result != DEVICE_ERROR_NONE) { -// LoggerE("Error occured"); -// ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Error occured"), &out); -// return; -// } -// ReportSuccess(picojson::value(std::to_string(brightness)), out); + int result = device_flash_get_brightness(&brightness); + if (result != DEVICE_ERROR_NONE) { + LoggerE("Error occured"); + ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Error occured"), out); + return; + } + ReportSuccess(picojson::value(std::to_string(brightness)), *out); } void SysteminfoManager::GetMaxBrightness(const picojson::value& args, picojson::object* out) { LoggerD("entered"); int brightness = 0; -// int result = device_flash_get_max_brightness(&brightness); -// if (result != DEVICE_ERROR_NONE) { -// LoggerE("Error occured"); -// ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Not supported property"), &out); -// return; -// } -// ReportSuccess(picojson::value(std::to_string(brightness)), out); + int result = device_flash_get_max_brightness(&brightness); + if (result != DEVICE_ERROR_NONE) { + LoggerE("Error occured"); + ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Not supported property"), out); + return; + } + ReportSuccess(picojson::value(std::to_string(brightness)), *out); +} + +PlatformResult SysteminfoManager::GetPropertyCount(const std::string& property, + unsigned long* count) +{ + LoggerD("Enter"); + + if ("BATTERY" == property || "CPU" == property || "STORAGE" == property || + "DISPLAY" == property || "DEVICE_ORIENTATION" == property || + "BUILD" == property || "LOCALE" == property || "NETWORK" == property || + "WIFI_NETWORK" == property || "PERIPHERAL" == property || + "MEMORY" == property) { + *count = kDefaultPropertyCount; + } else if ("CELLULAR_NETWORK" == property) { + PlatformResult ret = SysteminfoUtils::CheckTelephonySupport(); + if (ret.IsError()) { + *count = 0; + } else { + *count = GetSimCount(); + } + } else if ("SIM" == property) { + PlatformResult ret = SysteminfoUtils::CheckTelephonySupport(); + if (ret.IsError()) { + *count = 0; + } else { + *count = GetSimCount(); + } + } else if ("CAMERA_FLASH" == property) { + *count = GetCameraTypesCount(); + } else if ("ETHERNET_NETWORK" == property) { + PlatformResult ret = SysteminfoUtils::CheckIfEthernetNetworkSupported(); + if (ret.IsError()) { + *count = 0; + } else { + *count = kDefaultPropertyCount; + } + } else { + LoggerD("Property with given id is not supported"); + return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, "Property with given id is not supported"); + } + return PlatformResult(ErrorCode::NO_ERROR); +} + +wifi_rssi_level_e SysteminfoManager::GetWifiLevel() { + LoggerD("Enter"); + return wifi_level_; +} + +int SysteminfoManager::GetSensorHandle() { + LoggerD("Enter"); + if (sensor_handle_ < 0) { + LoggerD("Connecting to sensor"); + ConnectSensor(&sensor_handle_); + } else { + LoggerD("Sensor already connected"); + } + return sensor_handle_; +} + +PlatformResult SysteminfoManager::ConnectSensor(int* result) { + LoggerD("Entered"); + sensor_t sensor = sensord_get_sensor(AUTO_ROTATION_SENSOR); + int handle_orientation = sensord_connect(sensor); + if (handle_orientation < 0) { + std::string log_msg = "Failed to connect auto rotation sensor"; + LoggerE("%s", log_msg.c_str()); + return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); + } + bool ret = sensord_start(handle_orientation, 0); + if(!ret) { + sensord_disconnect(handle_orientation); + std::string log_msg = "Failed to start auto rotation sensor"; + LoggerE("%s", log_msg.c_str()); + return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); + } + LoggerD("Sensor starts successfully = %d", handle_orientation); + *result = handle_orientation; + return PlatformResult(ErrorCode::NO_ERROR); +} + +void SysteminfoManager::DisconnectSensor(int handle_orientation) { + LoggerD("Enter"); + if (handle_orientation >= 0) { + LoggerD("Entered"); + bool state = sensord_stop(handle_orientation); + LoggerD("sensord_stop() returned state = %d", state); + state = sensord_disconnect(handle_orientation); + LoggerD("sensord_disconnect() returned state %d", state); + } else { + LoggerD("sensor already disconnected - no action needed"); + } +} + +void SysteminfoManager::SetCpuInfoLoad(double load) { + LoggerD("Enter"); + cpu_load_ = load; +} + +void SysteminfoManager::SetAvailableCapacityInternal(unsigned long long capacity) { + LoggerD("Enter"); + available_capacity_internal_ = capacity; +} + +void SysteminfoManager::SetAvailableCapacityMmc(unsigned long long capacity) { + LoggerD("Enter"); + available_capacity_mmc_ = capacity; +} + +int SysteminfoManager::GetSimCount() { + LoggerD("Entered"); + InitTapiHandles(); + return sim_count_; +} + +void SysteminfoManager::InitTapiHandles() { + LoggerD("Entered"); + 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; + } + sim_count_++; + LoggerD("%d modem: %s", sim_count_, cp_list[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_; +} + +void SysteminfoManager::InitCameraTypes() { + LoggerD("Enter"); + bool supported = false; + PlatformResult ret = SystemInfoDeviceCapability::GetValueBool( + "tizen.org/feature/camera.back.flash", &supported); + if (ret.IsSuccess()) { + if (supported) { + camera_types_.push_back("BACK"); + } + } + ret = SystemInfoDeviceCapability::GetValueBool( + "tizen.org/feature/camera.front.flash", &supported); + if (ret.IsSuccess()) { + if (supported) { + camera_types_.push_back("FRONT"); + } + } +} + +std::string SysteminfoManager::GetCameraTypes(int index) { + LoggerD("Enter"); + if (index >= camera_types_.size()) { + return ""; + } + return camera_types_[index]; +} + +int SysteminfoManager::GetCameraTypesCount() { + LoggerD("Enter"); + return camera_types_.size(); } } // namespace systeminfo diff --git a/src/systeminfo/systeminfo_manager.h b/src/systeminfo/systeminfo_manager.h index a7b721b3..63601374 100644 --- a/src/systeminfo/systeminfo_manager.h +++ b/src/systeminfo/systeminfo_manager.h @@ -17,6 +17,8 @@ #ifndef WEBAPI_PLUGINS_SYSTEMINFO_SYSTEMINFO_MANAGER_H__ #define WEBAPI_PLUGINS_SYSTEMINFO_SYSTEMINFO_MANAGER_H__ +#include + #include "common/picojson.h" #include "common/platform_result.h" #include "systeminfo/systeminfo_properties_manager.h" @@ -24,6 +26,8 @@ namespace extension { namespace systeminfo { +const int kTapiMaxHandle = 2; + class SysteminfoInstance; class SysteminfoManager { @@ -44,10 +48,38 @@ class SysteminfoManager { void GetAvailableMemory(const picojson::value& args, picojson::object* out); void GetCount(const picojson::value& args, picojson::object* out); + common::PlatformResult GetPropertyCount(const std::string& property, unsigned long* count); + wifi_rssi_level_e GetWifiLevel(); + int GetSensorHandle(); + TapiHandle* GetTapiHandle(); + TapiHandle** GetTapiHandles(); + + void SetCpuInfoLoad(double load); + void SetAvailableCapacityInternal(unsigned long long capacity); + void SetAvailableCapacityMmc(unsigned long long capacity); + std::string GetCameraTypes(int index); + int GetCameraTypesCount(); private: + common::PlatformResult ConnectSensor(int* result); + void DisconnectSensor(int handle_orientation); + void InitTapiHandles(); + void InitCameraTypes(); + int GetSimCount(); + SysteminfoInstance* instance_; - SystemInfoPropertiesManager prop_manager_; + SysteminfoPropertiesManager prop_manager_; + + //! Sensor handle for DeviceOrientation purposes + int sensor_handle_; + + std::vector camera_types_; + wifi_rssi_level_e wifi_level_; + double cpu_load_; + unsigned long long available_capacity_internal_; + unsigned long long available_capacity_mmc_; + int sim_count_; + TapiHandle *tapi_handles_[kTapiMaxHandle+1]; }; } // namespace systeminfo } // namespace webapi diff --git a/src/systeminfo/systeminfo_properties_manager.cc b/src/systeminfo/systeminfo_properties_manager.cc index 05979407..cb7de050 100644 --- a/src/systeminfo/systeminfo_properties_manager.cc +++ b/src/systeminfo/systeminfo_properties_manager.cc @@ -16,8 +16,20 @@ #include "systeminfo/systeminfo_properties_manager.h" +#include + #include #include +#include +#include +#include +#include +#include + +#include "systeminfo/systeminfo_manager.h" +#include "systeminfo/systeminfo_device_capability.h" +#include "common/scope_exit.h" +#include "systeminfo/systeminfo-utils.h" namespace extension { namespace systeminfo { @@ -26,7 +38,9 @@ using common::PlatformResult; using common::ErrorCode; namespace { -const std::string kPropertyIdCpu = "CPU"; +const std::string kMemoryStateNormal = "NORMAL"; +const std::string kMemoryStateWarinig = "WARNING"; +const double kDisplayInchToMillimeter = 2.54; //Battery const double kRemainingBatteryChargeMax = 100.0; const int kVconfErrorNone = 0; @@ -47,7 +61,6 @@ const std::string kTypeUnknown = "UNKNOWN"; const std::string kTypeInternal = "INTERNAL"; const std::string kTypeUsbHost = "USB_HOST"; const std::string kTypeMmc = "MMC"; -const double kPropertyWatcherTime = 1; //Network enum NetworkType { kNone, @@ -76,27 +89,20 @@ const int kWifiSignalStrengthDivideValue = 100; const unsigned short kMccDivider = 100; const char* kConnectionOff = "OFF"; const char* kConnectionOn = "ON"; -//Sim -const char* kSimStatusAbsent = "ABSENT"; -const char* kSimStatusInitializing = "INITIALIZING"; -const char* kSimStatusReady = "READY"; -const char* kSimStatusPinRequired = "PIN_REQUIRED"; -const char* kSimStatusPukRequired = "PUK_REQUIRED"; -const char* kSimStatusSimLocked = "SIM_LOCKED"; -const char* kSimStatusNetworkLocked = "NETWORK_LOCKED"; -const char* kSimStatusUnknown = "UNKNOWN"; } -SystemInfoPropertiesManager::SystemInfoPropertiesManager() { +SysteminfoPropertiesManager::SysteminfoPropertiesManager(SysteminfoManager& manager) + : manager_(manager) { LoggerD("Entered"); } -SystemInfoPropertiesManager::~SystemInfoPropertiesManager() { +SysteminfoPropertiesManager::~SysteminfoPropertiesManager() { LoggerD("Entered"); } -PlatformResult SystemInfoPropertiesManager::GetPropertyValue(const std::string& property, bool is_array_type, - picojson::value* res) { +PlatformResult SysteminfoPropertiesManager::GetPropertyValue(const std::string& property, + bool is_array_type, picojson::value* res) +{ LoggerD("Entered getPropertyValue"); if (!is_array_type) { @@ -109,72 +115,72 @@ PlatformResult SystemInfoPropertiesManager::GetPropertyValue(const std::string& first->second.get(); unsigned long property_count = 0; - PlatformResult ret(ErrorCode::NO_ERROR); -// PlatformResult ret = SysteminfoUtils::GetCount(property, property_count); -// if (ret.IsError()){ -// return ret; -// } - + PlatformResult ret = manager_.GetPropertyCount(property, &property_count); + if (ret.IsError()){ + LoggerD("Property is not available"); + return ret; + } LoggerD("property name: %s", property.c_str()); -// LoggerD("available property count: %d", property_count); -// for (size_t i = 0; i < property_count; i++) { - size_t i = 0; + LoggerD("available property count: %d", property_count); + + for (size_t i = 0; i < property_count; i++) { picojson::value result = picojson::value(picojson::object()); picojson::object& result_obj = result.get(); - ret = ReportProperty(property, i, &result_obj); + PlatformResult ret = ReportProperty(property, i, &result_obj); if (ret.IsError()){ return ret; } array.push_back(result); -// } -// if (property_count == 0) { -// return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, "Property with given id is not supported"); -// } + } + if (property_count == 0) { + return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, "Property with given id is not supported"); + } } return PlatformResult(ErrorCode::NO_ERROR); } -PlatformResult SystemInfoPropertiesManager::ReportProperty(const std::string& property, int index, +PlatformResult SysteminfoPropertiesManager::ReportProperty(const std::string& property, int index, picojson::object* res_obj) { LoggerD("Entered"); if ("BATTERY" == property){ return ReportBattery(res_obj); } else if ("CPU" == property) { -// return ReportCpu(res_obj); + return ReportCpu(res_obj); } else if ("STORAGE" == property) { -// return ReportStorage(res_obj); + return ReportStorage(res_obj); } else if ("DISPLAY" == property) { -// return ReportDisplay(res_obj); + return ReportDisplay(res_obj); } else if ("DEVICE_ORIENTATION" == property) { -// return ReportDeviceOrientation(res_obj); + return ReportDeviceOrientation(res_obj); } else if ("BUILD" == property) { -// return ReportBuild(res_obj); + return ReportBuild(res_obj); } else if ("LOCALE" == property) { -// return ReportLocale(res_obj); + return ReportLocale(res_obj); } else if ("NETWORK" == property) { -// return ReportNetwork(res_obj); + return ReportNetwork(res_obj); } else if ("WIFI_NETWORK" == property) { -// return ReportWifiNetwork(res_obj); + return ReportWifiNetwork(res_obj); } else if ("ETHERNET_NETWORK" == property) { -// return ReportEthernetNetwork(res_obj); + return ReportEthernetNetwork(res_obj); } else if ("CELLULAR_NETWORK" == property) { -// return ReportCellularNetwork(res_obj, index); + return ReportCellularNetwork(res_obj, index); } else if ("SIM" == property) { -// return ReportSim(res_obj, index); + return ReportSim(res_obj, index); } else if ("PERIPHERAL" == property) { -// return ReportPeripheral(res_obj); + return ReportPeripheral(res_obj); } else if ("MEMORY" == property) { -// return ReportMemory(res_obj); + return ReportMemory(res_obj); } else if ("CAMERA_FLASH" == property) { -// return ReportCameraFlash(res_obj); + return ReportCameraFlash(res_obj, index); } LoggerD("Property with given id is not supported"); return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, "Property with given id is not supported"); } -PlatformResult SystemInfoPropertiesManager::ReportBattery(picojson::object* out) { +/// BATTERY +PlatformResult SysteminfoPropertiesManager::ReportBattery(picojson::object* out) { int value = 0; int ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, &value); if (kVconfErrorNone != ret) { @@ -194,975 +200,936 @@ PlatformResult SystemInfoPropertiesManager::ReportBattery(picojson::object* out) out->insert(std::make_pair("isCharging", picojson::value(0 != value))); return PlatformResult(ErrorCode::NO_ERROR); } -//TODO maybe make two functions later onGSourceFunc -//PlatformResult SystemInfoPropertiesManager::ReportCpu(picojson::object* out) { -// LoggerD("Entered"); -// static CpuInfo cpu_info; -// FILE *fp = nullptr; -// fp = fopen("/proc/stat", "r"); -// if (nullptr == fp) { -// std::string error_msg("Can not open /proc/stat for reading"); -// LoggerE( "%s", error_msg.c_str() ); -// return PlatformResult(ErrorCode::UNKNOWN_ERR, error_msg); -// } -// -// long long usr = 0; -// long long system = 0; -// long long nice = 0; -// long long idle = 0; -// double load = 0; -// -// int read_ret = fscanf( fp, "%*s %lld %lld %lld %lld", &usr, &system, &nice, &idle); -// fclose(fp); -// -// if (4 == read_ret) { -// long long total = usr + nice + system + idle - cpu_info.usr - cpu_info.nice - -// cpu_info.system - cpu_info.idle; -// long long diff_idle = idle - cpu_info.idle; -// if (( total > 0LL ) && ( diff_idle > 0LL )) { -// load = static_cast< double >( diff_idle ) * 100LL / total; -// cpu_info.usr = usr; -// cpu_info.system = system; -// cpu_info.nice = nice; -// cpu_info.idle = idle; -// cpu_info.load = load; -// } else { -// LoggerW("Cannot calculate cpu load, previous value returned"); -// load = cpu_info.load; -// } -// } else { -// std::string error_msg( "Could not read /proc/stat" ); -// LoggerE( "%s", error_msg.c_str() ); -// return PlatformResult(ErrorCode::UNKNOWN_ERR, error_msg); -// } -// -// system_info_listeners.SetCpuInfoLoad(cpu_info.load); -// -// load = 100 - load; -// LoggerD("Cpu load : %f", load ); -// out.insert(std::make_pair("load", picojson::value(load / 100.0))); -// return PlatformResult(ErrorCode::NO_ERROR); -//} -// -//PlatformResult SystemInfoPropertiesManager::ReportDisplay(picojson::object* out) { -// int screenWidth = 0; -// int screenHeight = 0; -// int dotsPerInchWidth = 0; -// int dotsPerInchHeight = 0; -// double physicalWidth = 0; -// double physicalHeight = 0; -// double scaledBrightness; -// -// // FETCH RESOLUTION -// if (SYSTEM_INFO_ERROR_NONE != system_info_get_platform_int( -// "tizen.org/feature/screen.width", &screenWidth)) { -// LoggerE("Cannot get value of screen width"); -// return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get value of screen width"); -// } -// if (SYSTEM_INFO_ERROR_NONE != system_info_get_platform_int( -// "tizen.org/feature/screen.height", &screenHeight)) { -// LoggerE("Cannot get value of screen height"); -// return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get value of screen height"); -// } -// -// //FETCH DOTS PER INCH -// int dots_per_inch=0; -// if (SYSTEM_INFO_ERROR_NONE == system_info_get_platform_int( -// "tizen.org/feature/screen.dpi", &dots_per_inch)) { -// dotsPerInchWidth = dots_per_inch; -// dotsPerInchHeight = dots_per_inch; -// } else { -// LoggerE("Cannot get 'tizen.org/feature/screen.dpi' value"); -// return PlatformResult(ErrorCode::UNKNOWN_ERR, -// "Cannot get 'tizen.org/feature/screen.dpi' value"); -// } -// -// //FETCH PHYSICAL WIDTH -// if (dotsPerInchWidth != 0 && screenWidth != 0) { -// physicalWidth = (screenWidth / dotsPerInchWidth) * DISPLAY_INCH_TO_MILLIMETER; -// } else { -// std::string log_msg = "Failed to get physical screen width value"; -// LoggerE("%s, screenWidth : %d, dotsPerInchWidth: %d", log_msg.c_str(), -// screenWidth, dotsPerInchWidth); -// } -// -// //FETCH PHYSICAL HEIGHT -// if (dotsPerInchHeight != 0 && screenHeight != 0) { -// physicalHeight = (screenHeight / dotsPerInchHeight) * DISPLAY_INCH_TO_MILLIMETER; -// } else { -// std::string log_msg = "Failed to get physical screen height value"; -// LoggerE("%s, screenHeight : %d, dotsPerInchHeight: %d", log_msg.c_str(), -// screenHeight, dotsPerInchHeight); -// } -// -// //FETCH BRIGHTNESS -// int brightness; -// if (kVconfErrorNone == vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, &brightness)) { -// scaledBrightness = static_cast(brightness)/kDisplayBrightnessDivideValue; -// } else { -// LoggerE("Cannot get brightness value of display"); -// return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get brightness value of display"); -// } -// -// out.insert(std::make_pair("resolutionWidth", picojson::value(std::to_string(screenWidth)))); -// out.insert(std::make_pair("resolutionHeight", picojson::value(std::to_string(screenHeight)))); -// out.insert(std::make_pair("dotsPerInchWidth", picojson::value(std::to_string(dotsPerInchWidth)))); -// out.insert(std::make_pair("dotsPerInchHeight", picojson::value(std::to_string(dotsPerInchHeight)))); -// out.insert(std::make_pair("physicalWidth", picojson::value(std::to_string(physicalWidth)))); -// out.insert(std::make_pair("physicalHeight", picojson::value(std::to_string(physicalHeight)))); -// out.insert(std::make_pair("brightness", picojson::value(scaledBrightness))); -// return PlatformResult(ErrorCode::NO_ERROR); -//} -// -//static PlatformResult FetchIsAutoRotation(bool* result) -//{ -// LoggerD("Entered"); -// int is_auto_rotation = 0; -// -// if ( 0 == vconf_get_bool( -// VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &is_auto_rotation)) { -// if (is_auto_rotation) { -// *result = true; -// } else { -// *result = false; -// } -// return PlatformResult(ErrorCode::NO_ERROR); -// } -// else { -// LoggerE("VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL check failed"); -// return PlatformResult(ErrorCode::UNKNOWN_ERR, -// "VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL check failed"); -// } -//} -// -//static PlatformResult FetchStatus(std::string* result) -//{ -// LoggerD("Entered"); -// int rotation = 0; -// std::string status = kOrientationPortraitPrimary; -// -// sensor_data_t data; -// bool ret = sensord_get_data(system_info_listeners.GetSensorHandle(), -// AUTO_ROTATION_BASE_DATA_SET, &data); -// if (ret) { -// LoggerD("size of the data value array:%d", data.value_count); -// if (data.value_count > 0 ) { -// rotation = data.values[0]; -// LoggerD("rotation is: %d", rotation); -// } else { -// LoggerE("Failed to get data : the size of array is 0. Default rotation would be returned."); -// } -// } else { -// LoggerE("Failed to get data(sensord_get_data). Default rotation would be returned."); -// } -// -// -// switch (rotation) { -// case AUTO_ROTATION_DEGREE_UNKNOWN: -// case AUTO_ROTATION_DEGREE_0: -// LoggerD("AUTO_ROTATION_DEGREE_0"); -// status = kOrientationPortraitPrimary; -// break; -// case AUTO_ROTATION_DEGREE_90: -// LoggerD("AUTO_ROTATION_DEGREE_90"); -// status = kOrientationLandscapePrimary; -// break; -// case AUTO_ROTATION_DEGREE_180: -// LoggerD("AUTO_ROTATION_DEGREE_180"); -// status = kOrientationPortraitSecondary; -// break; -// case AUTO_ROTATION_DEGREE_270: -// LoggerD("AUTO_ROTATION_DEGREE_270"); -// status = kOrientationLandscapeSecondary; -// break; -// default: -// LoggerE("Received unexpected data: %u", rotation); -// return PlatformResult(ErrorCode::UNKNOWN_ERR, "Received unexpected data"); -// } -// *result = status; -// return PlatformResult(ErrorCode::NO_ERROR); -//} - -//PlatformResult SystemInfoPropertiesManager::ReportDeviceOrientation(picojson::object* out) { -// bool is_auto_rotation = false; -// std::string status = ""; -// -// PlatformResult ret = FetchIsAutoRotation(&is_auto_rotation); -// if (ret.IsError()) return ret; -// -// ret = FetchStatus(&status); -// if (ret.IsError()) return ret; -// -// out.insert(std::make_pair("isAutoRotation", picojson::value(is_auto_rotation))); -// out.insert(std::make_pair("status", picojson::value(status))); -// return PlatformResult(ErrorCode::NO_ERROR); -//} -// -//PlatformResult SystemInfoPropertiesManager::ReportBuild(picojson::object* out) { -// std::string model = ""; -// PlatformResult ret = SystemInfoDeviceCapability::GetValueString( -// "tizen.org/system/model_name", &model); -// if (ret.IsError()) { -// return ret; -// } -// std::string manufacturer = ""; -// ret = SystemInfoDeviceCapability::GetValueString( -// "tizen.org/system/manufacturer", &manufacturer); -// if (ret.IsError()) { -// return ret; -// } -// std::string buildVersion = ""; -// ret = SystemInfoDeviceCapability::GetValueString( -// "tizen.org/system/build.string", &buildVersion); -// if (ret.IsError()) { -// return ret; -// } -// -// out.insert(std::make_pair("model", picojson::value(model))); -// out.insert(std::make_pair("manufacturer", picojson::value(manufacturer))); -// out.insert(std::make_pair("buildVersion", picojson::value(buildVersion))); -// return PlatformResult(ErrorCode::NO_ERROR); -//} -// -//PlatformResult SystemInfoPropertiesManager::ReportLocale(picojson::object* out) { -// std::string str_language = ""; -// PlatformResult ret = GetRuntimeInfoString(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, str_language); -// if (ret.IsError()) { -// return ret; -// } -// -// std::string str_country = ""; -// ret = GetRuntimeInfoString(SYSTEM_SETTINGS_KEY_LOCALE_COUNTRY, str_country); -// if (ret.IsError()) { -// return ret; -// } -// -// out.insert(std::make_pair("language", picojson::value(str_language))); -// out.insert(std::make_pair("country", picojson::value(str_country))); -// return PlatformResult(ErrorCode::NO_ERROR); -//} -// -//static PlatformResult GetNetworkTypeString(NetworkType type, std::string& type_string) -//{ -// switch (type) { -// case kNone: -// type_string = kNetworkTypeNone; -// break; -// case kType2G: -// type_string = kNetworkType2G; -// break; -// case kType2_5G: -// type_string = kNetworkType2_5G; -// break; -// case kType3G: -// type_string = kNetworkType3G; -// break; -// case kType4G: -// type_string = kNetworkType4G; -// break; -// case kWifi: -// type_string = kNetworkTypeWifi; -// break; -// case kEthernet: -// type_string = kNetworkTypeEthernet; -// break; -// case kUnknown: -// type_string = kNetworkTypeUnknown; -// break; -// default: -// LoggerE("Incorrect type: %d", type); -// return PlatformResult(ErrorCode::TYPE_MISMATCH_ERR, "Incorrect type"); -// } -// return PlatformResult(ErrorCode::NO_ERROR); -//} -// -//PlatformResult SystemInfoPropertiesManager::ReportNetwork(picojson::object* out) { -// connection_h connection_handle = nullptr; -// connection_type_e connection_type = CONNECTION_TYPE_DISCONNECTED; -// int networkType = 0; -// NetworkType type = kNone; -// -// //connection must be created in every call, in other case error occurs -// int error = connection_create(&connection_handle); -// if (CONNECTION_ERROR_NONE != error) { -// std::string log_msg = "Cannot create connection: " + std::to_string(error); -// LoggerE("%s", log_msg.c_str()); -// return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); -// } -// std::unique_ptr::type, int(*)(connection_h)> -// connection_handle_ptr(connection_handle, &connection_destroy); -// // automatically release the memory -// -// error = connection_get_type(connection_handle, &connection_type); -// if (CONNECTION_ERROR_NONE != error) { -// std::string log_msg = "Cannot get connection type: " + std::to_string(error); -// LoggerE("%s", log_msg.c_str()); -// return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); -// } -// -// switch (connection_type) { -// case CONNECTION_TYPE_DISCONNECTED : -// type = kNone; -// break; -// case CONNECTION_TYPE_WIFI : -// type = kWifi; -// break; -// case CONNECTION_TYPE_CELLULAR : -// if (vconf_get_int(VCONFKEY_TELEPHONY_SVCTYPE, &networkType) == 0) { -// if (networkType < VCONFKEY_TELEPHONY_SVCTYPE_2G) { -// type = kNone; -// } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_2G) { -// type = kType2G; -// } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_2G -// || networkType == VCONFKEY_TELEPHONY_SVCTYPE_2_5G_EDGE) { -// type = kType2_5G; -// } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_3G -// || networkType == VCONFKEY_TELEPHONY_SVCTYPE_HSDPA) { -// type = kType3G; -// } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_LTE) { -// type = kType4G; -// } else { -// type = kNone; -// } -// } -// break; -// case CONNECTION_TYPE_ETHERNET : -// type = kEthernet; -// break; -// default: -// LoggerE("Incorrect type: %d", connection_type); -// return PlatformResult(ErrorCode::UNKNOWN_ERR, "Incorrect type"); -// } -// std::string type_str = ""; -// PlatformResult ret = GetNetworkTypeString(type, type_str); -// if(ret.IsError()) { -// return ret; -// } -// out.insert(std::make_pair("networkType", picojson::value(type_str))); -// return PlatformResult(ErrorCode::NO_ERROR); -//} -// -//static PlatformResult GetIps(wifi_ap_h wifi_ap_handle, std::string* ip_addr_str, -// std::string* ipv6_addr_str){ -// //getting ipv4 address -// char* ip_addr = nullptr; -// int error = wifi_ap_get_ip_address(wifi_ap_handle, -// WIFI_ADDRESS_FAMILY_IPV4, -// &ip_addr); -// if (WIFI_ERROR_NONE != error) { -// LoggerE("Failed to get ip address: %d", error); -// return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get ip address"); -// } -// *ip_addr_str = ip_addr; -// free(ip_addr); -// -// //getting ipv6 address -// ip_addr = nullptr; -// error = wifi_ap_get_ip_address(wifi_ap_handle, -// WIFI_ADDRESS_FAMILY_IPV6, -// &ip_addr); -// if (WIFI_ERROR_NONE != error) { -// LoggerE("Failed to get ipv6 address: %d", error); -// return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get ipv6 address"); -// } -// *ipv6_addr_str = ip_addr; -// free(ip_addr); -// return PlatformResult(ErrorCode::NO_ERROR); -//} -// -//PlatformResult SystemInfoPropertiesManager::ReportWifiNetwork(picojson::object* out) { -// LoggerD("Entered"); -// -// bool result_status = false; -// std::string result_ssid; -// std::string result_ip_address; -// std::string result_ipv6_address; -// std::string result_mac_address; -// double result_signal_strength = 0; -// -// // wifi_initialize() must be called in each thread -// int error = wifi_initialize(); -// if (WIFI_ERROR_NONE != error) { -// std::string log_msg = "Initialize failed: " + parseWifiNetworkError(error); -// LoggerE("%s", log_msg.c_str()); -// return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); -// } else { -// LoggerD("WIFI initializatino succeed"); -// } -// SCOPE_EXIT { -// wifi_deinitialize(); -// }; -// -// wifi_ap_h wifi_ap_handle = nullptr; -// error = wifi_get_connected_ap(&wifi_ap_handle); -// if (WIFI_ERROR_NONE != error) { -// LoggerD("Error while wifi_get_connnected_ap: %s", parseWifiNetworkError(error).c_str()); -// // in case of no connection, ignore error and leave status as false -// if (WIFI_ERROR_NO_CONNECTION != error) { -// std::string log_msg = "Cannot get connected access point handle: " + parseWifiNetworkError(error); -// LoggerE("%s", log_msg.c_str()); -// return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); -// } -// } else { -// //if getting connected AP succeed, set status on true -// result_status = true; -// } -// -// if (result_status) { -// std::unique_ptr::type, int(*)(wifi_ap_h)> -// wifi_ap_handle_ptr(wifi_ap_handle, &wifi_ap_destroy); -// // automatically release the memory -// -// //gathering mac address -// char* mac = nullptr; -// error = wifi_get_mac_address(&mac); -// if (WIFI_ERROR_NONE == error && nullptr != mac) { -// SLoggerD("MAC address fetched: %s", mac); -// result_mac_address = mac; -// free(mac); -// } else { -// std::string log_msg = "Failed to get mac address: " + parseWifiNetworkError(error); -// LoggerE("%s", log_msg.c_str()); -// return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); -// } -// -// //refreshing access point information -// error = wifi_ap_refresh(wifi_ap_handle); -// if (WIFI_ERROR_NONE != error) { -// std::string log_msg = "Failed to refresh access point information: " + parseWifiNetworkError(error); -// LoggerE("%s", log_msg.c_str()); -// return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); -// } -// -// //gathering ssid -// char* essid = nullptr; -// error = wifi_ap_get_essid(wifi_ap_handle, &essid); -// if (WIFI_ERROR_NONE == error) { -// result_ssid = essid; -// free(essid); -// } else { -// std::string log_msg = "Failed to get network ssid: " + parseWifiNetworkError(error); -// LoggerE("%s", log_msg.c_str()); -// return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); -// } -// -// //gathering ips -// PlatformResult ret = GetIps(wifi_ap_handle, &result_ip_address, &result_ipv6_address); -// if (ret.IsError()) { -// return ret; -// } -// -// //gathering strength -// wifi_rssi_level_e rssi_level = system_info_listeners.GetWifiLevel(); -// // this mean that level was not initialized or wifi not connected -// if (WIFI_RSSI_LEVEL_0 == rssi_level) { -// // so try to gather rssi level with dedicated function -// int rssi = 0; -// error = wifi_ap_get_rssi(wifi_ap_handle, &rssi); -// if (WIFI_ERROR_NONE == error) { -// result_signal_strength = ((double) abs(rssi))/kWifiSignalStrengthDivideValue; -// } else { -// std::string log_msg = "Failed to get signal strength: " + parseWifiNetworkError(error); -// LoggerE("%s", log_msg.c_str()); -// return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); -// } -// } else { -// result_signal_strength = ((double) rssi_level)/WIFI_RSSI_LEVEL_4; -// } -// } -// //building result object -// out.insert(std::make_pair("status", picojson::value(result_status ? kWifiStatusOn : kWifiStatusOff))); -// out.insert(std::make_pair("ssid", picojson::value(result_ssid))); -// out.insert(std::make_pair("ipAddress", picojson::value(result_ip_address))); -// out.insert(std::make_pair("ipv6Address", picojson::value(result_ipv6_address))); -// out.insert(std::make_pair("macAddress", picojson::value(result_mac_address))); -// out.insert(std::make_pair("signalStrength", picojson::value(std::to_string(result_signal_strength)))); -// -// return PlatformResult(ErrorCode::NO_ERROR); -//} -// -//PlatformResult SystemInfoPropertiesManager::ReportEthernetNetwork(picojson::object* out) { -// LoggerD("Entered"); -// -// std::string result_cable; -// std::string result_status; -// std::string result_ip_address; -// std::string result_ipv6_address; -// std::string result_mac_address; -// -// connection_h connection_handle = nullptr; -// connection_ethernet_state_e connection_state = CONNECTION_ETHERNET_STATE_DEACTIVATED; -// connection_type_e connection_type = CONNECTION_TYPE_DISCONNECTED; -// connection_profile_h profile_handle = nullptr; -// -// // connection must be created in every call, in other case error occurs -// int error = connection_create(&connection_handle); -// if (CONNECTION_ERROR_NONE != error) { -// std::string log_msg = "Cannot create connection: " + std::to_string(error); -// LoggerE("%s", log_msg.c_str()); -// return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); -// } -// std::unique_ptr::type, int (*)(connection_h)> connection_handle_ptr( -// connection_handle, &connection_destroy); // automatically release the memory -// -// error = connection_get_ethernet_state(connection_handle, &connection_state); -// if (CONNECTION_ERROR_NONE != error) { -// if (CONNECTION_ERROR_NOT_SUPPORTED == error) { -// std::string log_msg = "Cannot get ethernet connection state: Not supported"; -// LoggerE("%s", log_msg.c_str()); -// return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, log_msg); -// } -// std::string log_msg = "Cannot get ethernet connection state: " + std::to_string(error); -// LoggerE("%s", log_msg.c_str()); -// return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); -// } -// -// switch (connection_state) { -// case CONNECTION_ETHERNET_STATE_DEACTIVATED: -// result_status = "DEACTIVATED"; -// break; -// -// case CONNECTION_ETHERNET_STATE_DISCONNECTED: -// result_status = "DISCONNECTED"; -// break; -// -// case CONNECTION_ETHERNET_STATE_CONNECTED: -// result_status = "CONNECTED"; -// break; -// -// default: -// result_status = "UNKNOWN"; -// break; -// } -// -// connection_ethernet_cable_state_e cable_state = CONNECTION_ETHERNET_CABLE_DETACHED; -// error = connection_get_ethernet_cable_state(connection_handle, &cable_state); -// if (CONNECTION_ERROR_NONE != error) { -// std::string log_msg = "Cannot get ethernet cable state: " + std::to_string(error); -// LoggerE("%s", log_msg.c_str()); -// return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); -// } -// -// switch (cable_state) { -// case CONNECTION_ETHERNET_CABLE_DETACHED: -// result_cable = "DETACHED"; -// break; -// -// case CONNECTION_ETHERNET_CABLE_ATTACHED: -// result_cable = "ATTACHED"; -// break; -// -// default: -// result_cable = "UNKNOWN"; -// break; -// } -// -// char* mac = nullptr; -// error = connection_get_mac_address(connection_handle, CONNECTION_TYPE_ETHERNET, &mac); -// if (CONNECTION_ERROR_NONE == error && nullptr != mac) { -// SLoggerD("MAC address fetched: %s", mac); -// result_mac_address = mac; -// free(mac); -// } else { -// std::string log_msg = "Failed to get mac address: " + std::to_string(error); -// LoggerE("%s", log_msg.c_str()); -// return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); -// } -// -// error = connection_get_type(connection_handle, &connection_type); -// if (CONNECTION_ERROR_NONE != error) { -// std::string log_msg = "Cannot get connection type: " + std::to_string(error); -// LoggerE("%s", log_msg.c_str()); -// return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); -// } -// -// if (CONNECTION_TYPE_ETHERNET == connection_type) { -// //gathering profile -// error = connection_get_current_profile(connection_handle, &profile_handle); -// if (CONNECTION_ERROR_NONE != error) { -// std::string log_msg = "Cannot get connection profile: " + std::to_string(error); -// LoggerE("%s", log_msg.c_str()); -// return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); -// } -// std::unique_ptr::type, -// int (*)(connection_profile_h)> profile_handle_ptr( -// profile_handle, &connection_profile_destroy); // automatically release the memory -// -// //gathering ips -// PlatformResult ret = GetIps(profile_handle, &result_ip_address, &result_ipv6_address); -// if (ret.IsError()) { -// return ret; -// } -// } else { -// LoggerD("Connection type = %d. ETHERNET is disabled", connection_type); -// } -// -// out.insert(std::make_pair("cable", picojson::value(result_cable))); -// out.insert(std::make_pair("status", picojson::value(result_status))); -// out.insert(std::make_pair("ipAddress", picojson::value(result_ip_address))); -// out.insert(std::make_pair("ipv6Address", picojson::value(result_ipv6_address))); -// out.insert(std::make_pair("macAddress", picojson::value(result_mac_address))); -// -// 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); -// LoggerE("%s", error_msg.c_str()); -// return PlatformResult(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); -// LoggerE("%s", error_msg.c_str()); -// return PlatformResult(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); -// LoggerE("%s", error_msg.c_str()); -// return PlatformResult(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); -// LoggerE("%s", error_msg.c_str()); -// return PlatformResult(ErrorCode::UNKNOWN_ERR, error_msg); -// } -// *result_is_roaming = (0 != result_value) ? true : false; -// -// if (0 != vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &result_value)) { -// LoggerE("Cannot get is_flight_mode value"); -// return PlatformResult(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) -//{ -// LoggerD("Entered"); -// connection_type_e connection_type = CONNECTION_TYPE_DISCONNECTED; -// connection_profile_h profile_handle = nullptr; -// connection_h connection_handle = nullptr; -// -// //connection must be created in every call, in other case error occurs -// int error = connection_create(&connection_handle); -// if (CONNECTION_ERROR_NONE != error) { -// std::string log_msg = "Cannot create connection: " + std::to_string(error); -// LoggerE("%s", log_msg.c_str()); -// return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); -// } -// std::unique_ptr::type, int(*)(connection_h)> -// connection_handle_ptr(connection_handle, &connection_destroy); -// // automatically release the memory -// -// error = connection_get_type(connection_handle, &connection_type); -// if (CONNECTION_ERROR_NONE != error) { -// LoggerE("Failed to get connection type: %d", error); -// return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get connection type"); -// } -// -// char* apn = nullptr; -// if (CONNECTION_TYPE_CELLULAR == connection_type) { -// *result_status = kConnectionOn; -// -// error = connection_get_current_profile(connection_handle, -// &profile_handle); -// std::unique_ptr -// ::type, int(*)(connection_profile_h)> -// profile_handle_ptr(profile_handle, &connection_profile_destroy); -// // automatically release the memory -// if (CONNECTION_ERROR_NONE != error) { -// LoggerE("Failed to get profile: %d", error); -// return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get profile"); -// } -// -// error = connection_profile_get_cellular_apn(profile_handle, &apn); -// if (CONNECTION_ERROR_NONE != error) { -// LoggerE("Failed to get apn name: %d", error); -// return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get apn name"); -// } -// *result_apn = apn; -// free(apn); -// -// PlatformResult ret = GetIps(profile_handle, result_ip_address, result_ipv6_address); -// if (ret.IsError()) { -// return ret; -// } -// } else { -// *result_status = kConnectionOff; -// -// //According to previous implementation in case of error -// //don't throw exception here -// error = connection_get_default_cellular_service_profile( -// connection_handle, -// CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET, -// &profile_handle); -// std::unique_ptr -// ::type, int(*)(connection_profile_h)> -// profile_handle_ptr(profile_handle, &connection_profile_destroy); -// // automatically release the memory -// if (CONNECTION_ERROR_NONE == error) { -// error = connection_profile_get_cellular_apn(profile_handle, &apn); -// if (CONNECTION_ERROR_NONE == error) { -// *result_apn = apn; -// free(apn); -// } else { -// LoggerE("Failed to get default apn name: %d. Failing silently", -// error); -// } -// } else { -// LoggerE("Failed to get default profile: %d. Failing silently", -// error); -// } -// } -// -// 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); -//} -// -//PlatformResult SystemInfoPropertiesManager::ReportCellularNetwork(picojson::object* out, unsigned long count) { -// PlatformResult ret = CheckTelephonySupport(); -// if (ret.IsError()) { -// return ret; -// } -// std::string result_status; -// std::string result_apn; -// std::string result_ip_address; -// std::string result_ipv6_address; -// 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; -// -// //gathering vconf-based values -// ret = FetchBasicSimProperties(system_info_listeners.GetTapiHandles()[count], &result_mcc, -// &result_mnc, &result_cell_id, &result_lac, -// &result_is_roaming, &result_is_flight_mode); -// if (ret.IsError()) { -// return ret; -// } -// //gathering connection informations -// ret = FetchConnection(system_info_listeners.GetTapiHandles()[count], -// &result_status, &result_apn, &result_ip_address, &result_ipv6_address, &result_imei); -// if (ret.IsError()) { -// return ret; -// } -// -// out.insert(std::make_pair("status", picojson::value(result_status))); -// out.insert(std::make_pair("apn", picojson::value(result_apn))); -// out.insert(std::make_pair("ipAddress", picojson::value(result_ip_address))); -// out.insert(std::make_pair("ipv6Address", picojson::value(result_ipv6_address))); -// out.insert(std::make_pair("mcc", picojson::value(std::to_string(result_mcc)))); -// out.insert(std::make_pair("mnc", picojson::value(std::to_string(result_mnc)))); -// out.insert(std::make_pair("cellId", picojson::value(std::to_string(result_cell_id)))); -// out.insert(std::make_pair("lac", picojson::value(std::to_string(result_lac)))); -// out.insert(std::make_pair("isRoaming", picojson::value(result_is_roaming))); -// out.insert(std::make_pair("isFligthMode", picojson::value(result_is_flight_mode))); -// out.insert(std::make_pair("imei", picojson::value(result_imei))); -// return PlatformResult(ErrorCode::NO_ERROR); -//} -// -//void SimCphsValueCallback(TapiHandle */*handle*/, int result, void *data, void */*user_data*/) -//{ -// LoggerD("Entered"); -// TelSimAccessResult_t access_rt = static_cast(result); -// TelSimCphsNetName_t *cphs_info = static_cast(data); -// -// std::string result_operator; -// if (TAPI_SIM_ACCESS_SUCCESS == access_rt) { -// std::stringstream s; -// s << cphs_info->full_name; -// if (s.str().empty()) { -// s << cphs_info->short_name; -// } -// result_operator = s.str(); -// } else { -// LoggerW("Failed to retrieve cphs_info: %d", access_rt); -// } -// sim_mgr.set_operator_name(result_operator); -// sim_mgr.TryReturn(); -//} -// -//void SimMsisdnValueCallback(TapiHandle */*handle*/, int result, void *data, void */*user_data*/) -//{ -// LoggerD("Entered"); -// TelSimAccessResult_t access_rt = static_cast(result); -// TelSimMsisdnList_t *msisdn_info = static_cast(data); -// -// std::string result_msisdn; -// if (TAPI_SIM_ACCESS_SUCCESS == access_rt) { -// if (msisdn_info->count > 0) { -// if (strlen(msisdn_info->list[0].num) > 0) { -// result_msisdn = msisdn_info->list[0].num; -// } else { -// LoggerW("MSISDN number empty"); -// } -// } else { -// LoggerW("msisdn_info list empty"); -// } -// } else { -// LoggerW("Failed to retrieve msisdn_: %d", access_rt); -// } -// -// sim_mgr.set_msisdn(result_msisdn); -// sim_mgr.TryReturn(); -//} -// -//void SimSpnValueCallback(TapiHandle */*handle*/, int result, void *data, void */*user_data*/) -//{ -// LoggerD("Entered"); -// TelSimAccessResult_t access_rt = static_cast(result); -// TelSimSpn_t *spn_info = static_cast(data); -// -// std::string result_spn; -// if (TAPI_SIM_ACCESS_SUCCESS == access_rt) { -// result_spn = (char *)spn_info->spn; -// } else { -// LoggerW("Failed to retrieve spn_: %d", access_rt); -// } -// -// sim_mgr.set_spn(result_spn); -// sim_mgr.TryReturn(); -//} -// -//PlatformResult SystemInfoPropertiesManager::ReportSim(picojson::object* out, unsigned long count) { -// PlatformResult ret = CheckTelephonySupport(); -// if (ret.IsError()) { -// return ret; -// } -// return sim_mgr.GatherSimInformation( -// system_info_listeners.GetTapiHandles()[count], &out); -//} -// -//PlatformResult SystemInfoPropertiesManager::ReportPeripheral(picojson::object* out) { -// -///* int wireless_display_status = 0; -// PlatformResult ret = GetVconfInt(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, wireless_display_status); -// if (ret.IsSuccess()) { -// if (VCONFKEY_MIRACAST_WFD_SOURCE_ON == wireless_display_status) { -// out.insert(std::make_pair(kVideoOutputString, picojson::value(true))); -// return PlatformResult(ErrorCode::NO_ERROR); -// } -// }*/ -// int hdmi_status = 0; -// PlatformResult ret = GetVconfInt(VCONFKEY_SYSMAN_HDMI, hdmi_status); -// if (ret.IsSuccess()) { -// if (VCONFKEY_SYSMAN_HDMI_CONNECTED == hdmi_status) { -// out.insert(std::make_pair(kVideoOutputString, picojson::value(true))); -// return PlatformResult(ErrorCode::NO_ERROR); -// } -// } -// -// out.insert(std::make_pair(kVideoOutputString, picojson::value(false))); -// return PlatformResult(ErrorCode::NO_ERROR); -//} -// -//PlatformResult SystemInfoPropertiesManager::ReportMemory(picojson::object* out) { -// std::string state = MEMORY_STATE_NORMAL; -// int status = 0; -// PlatformResult ret = GetVconfInt(VCONFKEY_SYSMAN_LOW_MEMORY, status); -// if (ret.IsSuccess()) { -// switch (status) { -// case VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING: -// case VCONFKEY_SYSMAN_LOW_MEMORY_HARD_WARNING: -// state = MEMORY_STATE_WARNING; -// break; -// case VCONFKEY_SYSMAN_LOW_MEMORY_NORMAL: -// default: -// state = MEMORY_STATE_NORMAL; -// } -// } -// -// out.insert(std::make_pair("state", picojson::value(state))); -// return PlatformResult(ErrorCode::NO_ERROR); -//} -// -//static void CreateStorageInfo(const std::string& type, struct statfs& fs, picojson::object* out) { -// out->insert(std::make_pair("type", picojson::value(type))); -// out->insert(std::make_pair("capacity", picojson::value(std::to_string( -// static_cast(fs.f_bsize) * -// static_cast(fs.f_blocks))))); -// out->insert(std::make_pair("availableCapacity", picojson::value(std::to_string( -// static_cast(fs.f_bsize) * -// static_cast(fs.f_bavail))))); -// bool isRemovable = (type == kTypeInternal) ? false : true; -// out->insert(std::make_pair("isRemovable", picojson::value(isRemovable))); -//} -// -//PlatformResult SystemInfoPropertiesManager::ReportStorage(picojson::object* out) { -// int sdcardState = 0; -// struct statfs fs; -// -// picojson::value result = picojson::value(picojson::array()); -// -// picojson::array& array = result.get(); -// array.push_back(picojson::value(picojson::object())); -// picojson::object& internal_obj = array.back().get(); -// -// if (statfs(kStorageInternalPath, &fs) < 0) { -// LoggerE("There are no storage units detected"); -// return PlatformResult(ErrorCode::UNKNOWN_ERR, "There are no storage units detected"); -// } -// CreateStorageInfo(kTypeInternal, fs, &internal_obj); -// system_info_listeners.SetAvailableCapacityInternal(fs.f_bavail); -// -// if (0 == vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &sdcardState)) { -// if (VCONFKEY_SYSMAN_MMC_MOUNTED == sdcardState){ -// if (statfs(kStorageSdcardPath, &fs) < 0) { -// LoggerE("MMC mounted, but not accessible"); -// return PlatformResult(ErrorCode::UNKNOWN_ERR, "MMC mounted, but not accessible"); -// } -// array.push_back(picojson::value(picojson::object())); -// picojson::object& external_obj = array.back().get(); -// CreateStorageInfo(kTypeMmc, fs, &external_obj); -// system_info_listeners.SetAvailableCapacityMmc(fs.f_bavail); -// } -// } -// -// out.insert(std::make_pair("storages", picojson::value(result))); -// return PlatformResult(ErrorCode::NO_ERROR); -//} -//PlatformResult SystemInfoPropertiesManager::ReportCameraFlash(picojson::object* out) { -// PlatformResult ret = CheckCameraFlashSupport(); -// if (ret.IsError()) { -// return ret; -// } -// return PlatformResult(ErrorCode::NO_ERROR); -//} + +/// CPU +PlatformResult SysteminfoPropertiesManager::ReportCpu(picojson::object* out) { + LoggerD("Entered"); + static CpuInfo cpu_info; + FILE *fp = nullptr; + fp = fopen("/proc/stat", "r"); + if (nullptr == fp) { + std::string error_msg("Can not open /proc/stat for reading"); + LoggerE( "%s", error_msg.c_str() ); + return PlatformResult(ErrorCode::UNKNOWN_ERR, error_msg); + } + + long long usr = 0; + long long system = 0; + long long nice = 0; + long long idle = 0; + double load = 0; + + int read_ret = fscanf( fp, "%*s %lld %lld %lld %lld", &usr, &system, &nice, &idle); + fclose(fp); + + if (4 == read_ret) { + long long total = usr + nice + system + idle - cpu_info.usr - cpu_info.nice - + cpu_info.system - cpu_info.idle; + long long diff_idle = idle - cpu_info.idle; + if (( total > 0LL ) && ( diff_idle > 0LL )) { + load = static_cast< double >( diff_idle ) * 100LL / total; + cpu_info.usr = usr; + cpu_info.system = system; + cpu_info.nice = nice; + cpu_info.idle = idle; + cpu_info.load = load; + } else { + LoggerW("Cannot calculate cpu load, previous value returned"); + load = cpu_info.load; + } + } else { + std::string error_msg( "Could not read /proc/stat" ); + LoggerE( "%s", error_msg.c_str() ); + return PlatformResult(ErrorCode::UNKNOWN_ERR, error_msg); + } + + manager_.SetCpuInfoLoad(cpu_info.load); + + load = 100 - load; + LoggerD("Cpu load : %f", load ); + out->insert(std::make_pair("load", picojson::value(load / 100.0))); + return PlatformResult(ErrorCode::NO_ERROR); +} + +/// DISPLAY +PlatformResult SysteminfoPropertiesManager::ReportDisplay(picojson::object* out) { + int screenWidth = 0; + int screenHeight = 0; + int dotsPerInchWidth = 0; + int dotsPerInchHeight = 0; + double physicalWidth = 0; + double physicalHeight = 0; + double scaledBrightness; + + // FETCH RESOLUTION + if (SYSTEM_INFO_ERROR_NONE != system_info_get_platform_int( + "tizen.org/feature/screen.width", &screenWidth)) { + LoggerE("Cannot get value of screen width"); + return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get value of screen width"); + } + if (SYSTEM_INFO_ERROR_NONE != system_info_get_platform_int( + "tizen.org/feature/screen.height", &screenHeight)) { + LoggerE("Cannot get value of screen height"); + return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get value of screen height"); + } + + //FETCH DOTS PER INCH + int dots_per_inch=0; + if (SYSTEM_INFO_ERROR_NONE == system_info_get_platform_int( + "tizen.org/feature/screen.dpi", &dots_per_inch)) { + dotsPerInchWidth = dots_per_inch; + dotsPerInchHeight = dots_per_inch; + } else { + LoggerE("Cannot get 'tizen.org/feature/screen.dpi' value"); + return PlatformResult(ErrorCode::UNKNOWN_ERR, + "Cannot get 'tizen.org/feature/screen.dpi' value"); + } + + //FETCH PHYSICAL WIDTH + if (dotsPerInchWidth != 0 && screenWidth != 0) { + physicalWidth = (screenWidth / dotsPerInchWidth) * kDisplayInchToMillimeter; + } else { + std::string log_msg = "Failed to get physical screen width value"; + LoggerE("%s, screenWidth : %d, dotsPerInchWidth: %d", log_msg.c_str(), + screenWidth, dotsPerInchWidth); + } + + //FETCH PHYSICAL HEIGHT + if (dotsPerInchHeight != 0 && screenHeight != 0) { + physicalHeight = (screenHeight / dotsPerInchHeight) * kDisplayInchToMillimeter; + } else { + std::string log_msg = "Failed to get physical screen height value"; + LoggerE("%s, screenHeight : %d, dotsPerInchHeight: %d", log_msg.c_str(), + screenHeight, dotsPerInchHeight); + } + + //FETCH BRIGHTNESS + int brightness; + if (kVconfErrorNone == vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, &brightness)) { + scaledBrightness = static_cast(brightness)/kDisplayBrightnessDivideValue; + } else { + LoggerE("Cannot get brightness value of display"); + return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get brightness value of display"); + } + + out->insert(std::make_pair("resolutionWidth", picojson::value(std::to_string(screenWidth)))); + out->insert(std::make_pair("resolutionHeight", picojson::value(std::to_string(screenHeight)))); + out->insert(std::make_pair("dotsPerInchWidth", picojson::value(std::to_string(dotsPerInchWidth)))); + out->insert(std::make_pair("dotsPerInchHeight", picojson::value(std::to_string(dotsPerInchHeight)))); + out->insert(std::make_pair("physicalWidth", picojson::value(std::to_string(physicalWidth)))); + out->insert(std::make_pair("physicalHeight", picojson::value(std::to_string(physicalHeight)))); + out->insert(std::make_pair("brightness", picojson::value(scaledBrightness))); + return PlatformResult(ErrorCode::NO_ERROR); +} + +/// DEVICE_ORIENTATION +PlatformResult SysteminfoPropertiesManager::FetchIsAutoRotation(bool* result) +{ + LoggerD("Entered"); + int is_auto_rotation = 0; + + if ( 0 == vconf_get_bool( + VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &is_auto_rotation)) { + if (is_auto_rotation) { + *result = true; + } else { + *result = false; + } + return PlatformResult(ErrorCode::NO_ERROR); + } + else { + LoggerE("VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL check failed"); + return PlatformResult(ErrorCode::UNKNOWN_ERR, + "VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL check failed"); + } +} + +PlatformResult SysteminfoPropertiesManager::FetchStatus(std::string* result) +{ + LoggerD("Entered"); + int rotation = 0; + std::string status = kOrientationPortraitPrimary; + + sensor_data_t data; + bool ret = sensord_get_data(manager_.GetSensorHandle(), + AUTO_ROTATION_BASE_DATA_SET, &data); + if (ret) { + LoggerD("size of the data value array:%d", data.value_count); + if (data.value_count > 0 ) { + rotation = data.values[0]; + LoggerD("rotation is: %d", rotation); + } else { + LoggerE("Failed to get data : the size of array is 0. Default rotation would be returned."); + } + } else { + LoggerE("Failed to get data(sensord_get_data). Default rotation would be returned."); + } + + + switch (rotation) { + case AUTO_ROTATION_DEGREE_UNKNOWN: + case AUTO_ROTATION_DEGREE_0: + LoggerD("AUTO_ROTATION_DEGREE_0"); + status = kOrientationPortraitPrimary; + break; + case AUTO_ROTATION_DEGREE_90: + LoggerD("AUTO_ROTATION_DEGREE_90"); + status = kOrientationLandscapePrimary; + break; + case AUTO_ROTATION_DEGREE_180: + LoggerD("AUTO_ROTATION_DEGREE_180"); + status = kOrientationPortraitSecondary; + break; + case AUTO_ROTATION_DEGREE_270: + LoggerD("AUTO_ROTATION_DEGREE_270"); + status = kOrientationLandscapeSecondary; + break; + default: + LoggerE("Received unexpected data: %u", rotation); + return PlatformResult(ErrorCode::UNKNOWN_ERR, "Received unexpected data"); + } + *result = status; + return PlatformResult(ErrorCode::NO_ERROR); +} + +PlatformResult SysteminfoPropertiesManager::ReportDeviceOrientation(picojson::object* out) { + bool is_auto_rotation = false; + std::string status = ""; + + PlatformResult ret = FetchIsAutoRotation(&is_auto_rotation); + if (ret.IsError()) return ret; + + ret = FetchStatus(&status); + if (ret.IsError()) return ret; + + out->insert(std::make_pair("isAutoRotation", picojson::value(is_auto_rotation))); + out->insert(std::make_pair("status", picojson::value(status))); + return PlatformResult(ErrorCode::NO_ERROR); +} + +/// BUILD +PlatformResult SysteminfoPropertiesManager::ReportBuild(picojson::object* out) { + std::string model = ""; + PlatformResult ret = SystemInfoDeviceCapability::GetValueString( + "tizen.org/system/model_name", &model); + if (ret.IsError()) { + return ret; + } + std::string manufacturer = ""; + ret = SystemInfoDeviceCapability::GetValueString( + "tizen.org/system/manufacturer", &manufacturer); + if (ret.IsError()) { + return ret; + } + std::string buildVersion = ""; + ret = SystemInfoDeviceCapability::GetValueString( + "tizen.org/system/build.string", &buildVersion); + if (ret.IsError()) { + return ret; + } + + out->insert(std::make_pair("model", picojson::value(model))); + out->insert(std::make_pair("manufacturer", picojson::value(manufacturer))); + out->insert(std::make_pair("buildVersion", picojson::value(buildVersion))); + return PlatformResult(ErrorCode::NO_ERROR); +} + +/// LOCALE +PlatformResult SysteminfoPropertiesManager::ReportLocale(picojson::object* out) { + std::string str_language = ""; + PlatformResult ret = SysteminfoUtils::GetRuntimeInfoString( + SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &str_language); + if (ret.IsError()) { + return ret; + } + + std::string str_country = ""; + ret = SysteminfoUtils::GetRuntimeInfoString(SYSTEM_SETTINGS_KEY_LOCALE_COUNTRY, &str_country); + if (ret.IsError()) { + return ret; + } + + out->insert(std::make_pair("language", picojson::value(str_language))); + out->insert(std::make_pair("country", picojson::value(str_country))); + return PlatformResult(ErrorCode::NO_ERROR); +} + +/// NETWORK +static PlatformResult GetNetworkTypeString(NetworkType type, std::string& type_string) +{ + switch (type) { + case kNone: + type_string = kNetworkTypeNone; + break; + case kType2G: + type_string = kNetworkType2G; + break; + case kType2_5G: + type_string = kNetworkType2_5G; + break; + case kType3G: + type_string = kNetworkType3G; + break; + case kType4G: + type_string = kNetworkType4G; + break; + case kWifi: + type_string = kNetworkTypeWifi; + break; + case kEthernet: + type_string = kNetworkTypeEthernet; + break; + case kUnknown: + type_string = kNetworkTypeUnknown; + break; + default: + LoggerE("Incorrect type: %d", type); + return PlatformResult(ErrorCode::TYPE_MISMATCH_ERR, "Incorrect type"); + } + return PlatformResult(ErrorCode::NO_ERROR); +} + +PlatformResult SysteminfoPropertiesManager::ReportNetwork(picojson::object* out) { + connection_h connection_handle = nullptr; + connection_type_e connection_type = CONNECTION_TYPE_DISCONNECTED; + int networkType = 0; + NetworkType type = kNone; + + //connection must be created in every call, in other case error occurs + int error = connection_create(&connection_handle); + if (CONNECTION_ERROR_NONE != error) { + std::string log_msg = "Cannot create connection: " + std::to_string(error); + LoggerE("%s", log_msg.c_str()); + return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); + } + std::unique_ptr::type, int(*)(connection_h)> + connection_handle_ptr(connection_handle, &connection_destroy); + // automatically release the memory + + error = connection_get_type(connection_handle, &connection_type); + if (CONNECTION_ERROR_NONE != error) { + std::string log_msg = "Cannot get connection type: " + std::to_string(error); + LoggerE("%s", log_msg.c_str()); + return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); + } + + switch (connection_type) { + case CONNECTION_TYPE_DISCONNECTED : + type = kNone; + break; + case CONNECTION_TYPE_WIFI : + type = kWifi; + break; + case CONNECTION_TYPE_CELLULAR : + if (vconf_get_int(VCONFKEY_TELEPHONY_SVCTYPE, &networkType) == 0) { + if (networkType < VCONFKEY_TELEPHONY_SVCTYPE_2G) { + type = kNone; + } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_2G) { + type = kType2G; + } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_2G + || networkType == VCONFKEY_TELEPHONY_SVCTYPE_2_5G_EDGE) { + type = kType2_5G; + } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_3G + || networkType == VCONFKEY_TELEPHONY_SVCTYPE_HSDPA) { + type = kType3G; + } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_LTE) { + type = kType4G; + } else { + type = kNone; + } + } + break; + case CONNECTION_TYPE_ETHERNET : + type = kEthernet; + break; + default: + LoggerE("Incorrect type: %d", connection_type); + return PlatformResult(ErrorCode::UNKNOWN_ERR, "Incorrect type"); + } + std::string type_str = ""; + PlatformResult ret = GetNetworkTypeString(type, type_str); + if(ret.IsError()) { + return ret; + } + out->insert(std::make_pair("networkType", picojson::value(type_str))); + return PlatformResult(ErrorCode::NO_ERROR); +} + +/// WIFI_NETWORK +static PlatformResult GetIps(wifi_ap_h wifi_ap_handle, std::string* ip_addr_str, + std::string* ipv6_addr_str){ + //getting ipv4 address + char* ip_addr = nullptr; + int error = wifi_ap_get_ip_address(wifi_ap_handle, + WIFI_ADDRESS_FAMILY_IPV4, + &ip_addr); + if (WIFI_ERROR_NONE != error) { + LoggerE("Failed to get ip address: %d", error); + return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get ip address"); + } + *ip_addr_str = ip_addr; + free(ip_addr); + + //getting ipv6 address + ip_addr = nullptr; + error = wifi_ap_get_ip_address(wifi_ap_handle, + WIFI_ADDRESS_FAMILY_IPV6, + &ip_addr); + if (WIFI_ERROR_NONE != error) { + LoggerE("Failed to get ipv6 address: %d", error); + return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get ipv6 address"); + } + *ipv6_addr_str = ip_addr; + free(ip_addr); + return PlatformResult(ErrorCode::NO_ERROR); +} + +PlatformResult SysteminfoPropertiesManager::ReportWifiNetwork(picojson::object* out) { + LoggerD("Entered"); + + bool result_status = false; + std::string result_ssid; + std::string result_ip_address; + std::string result_ipv6_address; + std::string result_mac_address; + double result_signal_strength = 0; + + // wifi_initialize() must be called in each thread + int error = wifi_initialize(); + if (WIFI_ERROR_NONE != error) { + std::string log_msg = "Initialize failed: " + std::string(get_error_message(error)); + LoggerE("%s", log_msg.c_str()); + return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); + } else { + LoggerD("WIFI initializatino succeed"); + } + SCOPE_EXIT { + wifi_deinitialize(); + }; + + wifi_ap_h wifi_ap_handle = nullptr; + error = wifi_get_connected_ap(&wifi_ap_handle); + if (WIFI_ERROR_NONE != error) { + LoggerD("Error while wifi_get_connnected_ap: %s", get_error_message(error)); + // in case of no connection, ignore error and leave status as false + if (WIFI_ERROR_NO_CONNECTION != error) { + std::string log_msg = "Cannot get connected access point handle: " + + std::string(get_error_message(error)); + LoggerE("%s", log_msg.c_str()); + return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); + } + } else { + //if getting connected AP succeed, set status on true + result_status = true; + } + + if (result_status) { + std::unique_ptr::type, int(*)(wifi_ap_h)> + wifi_ap_handle_ptr(wifi_ap_handle, &wifi_ap_destroy); + // automatically release the memory + + //gathering mac address + char* mac = nullptr; + error = wifi_get_mac_address(&mac); + if (WIFI_ERROR_NONE == error && nullptr != mac) { + SLoggerD("MAC address fetched: %s", mac); + result_mac_address = mac; + free(mac); + } else { + std::string log_msg = "Failed to get mac address: " + std::string(get_error_message(error)); + LoggerE("%s", log_msg.c_str()); + return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); + } + + //refreshing access point information + error = wifi_ap_refresh(wifi_ap_handle); + if (WIFI_ERROR_NONE != error) { + std::string log_msg = "Failed to refresh access point information: " + + std::string(get_error_message(error)); + LoggerE("%s", log_msg.c_str()); + return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); + } + + //gathering ssid + char* essid = nullptr; + error = wifi_ap_get_essid(wifi_ap_handle, &essid); + if (WIFI_ERROR_NONE == error) { + result_ssid = essid; + free(essid); + } else { + std::string log_msg = "Failed to get network ssid: " + std::string(get_error_message(error)); + LoggerE("%s", log_msg.c_str()); + return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); + } + + //gathering ips + PlatformResult ret = GetIps(wifi_ap_handle, &result_ip_address, &result_ipv6_address); + if (ret.IsError()) { + return ret; + } + + //gathering strength + wifi_rssi_level_e rssi_level = manager_.GetWifiLevel(); + // this mean that level was not initialized or wifi not connected + if (WIFI_RSSI_LEVEL_0 == rssi_level) { + // so try to gather rssi level with dedicated function + int rssi = 0; + error = wifi_ap_get_rssi(wifi_ap_handle, &rssi); + if (WIFI_ERROR_NONE == error) { + result_signal_strength = ((double) abs(rssi))/kWifiSignalStrengthDivideValue; + } else { + std::string log_msg = "Failed to get signal strength: " + + std::string(get_error_message(error)); + LoggerE("%s", log_msg.c_str()); + return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); + } + } else { + result_signal_strength = ((double) rssi_level)/WIFI_RSSI_LEVEL_4; + } + } + //building result object + out->insert(std::make_pair("status", picojson::value(result_status ? kWifiStatusOn : kWifiStatusOff))); + out->insert(std::make_pair("ssid", picojson::value(result_ssid))); + out->insert(std::make_pair("ipAddress", picojson::value(result_ip_address))); + out->insert(std::make_pair("ipv6Address", picojson::value(result_ipv6_address))); + out->insert(std::make_pair("macAddress", picojson::value(result_mac_address))); + out->insert(std::make_pair("signalStrength", picojson::value(std::to_string(result_signal_strength)))); + + return PlatformResult(ErrorCode::NO_ERROR); +} + +/// ETHERNET_NETWORK +PlatformResult SysteminfoPropertiesManager::ReportEthernetNetwork(picojson::object* out) { + LoggerD("Entered"); + + std::string result_cable; + std::string result_status; + std::string result_ip_address; + std::string result_ipv6_address; + std::string result_mac_address; + + connection_h connection_handle = nullptr; + connection_ethernet_state_e connection_state = CONNECTION_ETHERNET_STATE_DEACTIVATED; + connection_type_e connection_type = CONNECTION_TYPE_DISCONNECTED; + connection_profile_h profile_handle = nullptr; + + // connection must be created in every call, in other case error occurs + int error = connection_create(&connection_handle); + if (CONNECTION_ERROR_NONE != error) { + std::string log_msg = "Cannot create connection: " + std::to_string(error); + LoggerE("%s", log_msg.c_str()); + return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); + } + std::unique_ptr::type, int (*)(connection_h)> connection_handle_ptr( + connection_handle, &connection_destroy); // automatically release the memory + + error = connection_get_ethernet_state(connection_handle, &connection_state); + if (CONNECTION_ERROR_NONE != error) { + if (CONNECTION_ERROR_NOT_SUPPORTED == error) { + std::string log_msg = "Cannot get ethernet connection state: Not supported"; + LoggerE("%s", log_msg.c_str()); + return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, log_msg); + } + std::string log_msg = "Cannot get ethernet connection state: " + std::to_string(error); + LoggerE("%s", log_msg.c_str()); + return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); + } + + switch (connection_state) { + case CONNECTION_ETHERNET_STATE_DEACTIVATED: + result_status = "DEACTIVATED"; + break; + + case CONNECTION_ETHERNET_STATE_DISCONNECTED: + result_status = "DISCONNECTED"; + break; + + case CONNECTION_ETHERNET_STATE_CONNECTED: + result_status = "CONNECTED"; + break; + + default: + result_status = "UNKNOWN"; + break; + } + + connection_ethernet_cable_state_e cable_state = CONNECTION_ETHERNET_CABLE_DETACHED; + error = connection_get_ethernet_cable_state(connection_handle, &cable_state); + if (CONNECTION_ERROR_NONE != error) { + std::string log_msg = "Cannot get ethernet cable state: " + std::to_string(error); + LoggerE("%s", log_msg.c_str()); + return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); + } + + switch (cable_state) { + case CONNECTION_ETHERNET_CABLE_DETACHED: + result_cable = "DETACHED"; + break; + + case CONNECTION_ETHERNET_CABLE_ATTACHED: + result_cable = "ATTACHED"; + break; + + default: + result_cable = "UNKNOWN"; + break; + } + + char* mac = nullptr; + error = connection_get_mac_address(connection_handle, CONNECTION_TYPE_ETHERNET, &mac); + if (CONNECTION_ERROR_NONE == error && nullptr != mac) { + SLoggerD("MAC address fetched: %s", mac); + result_mac_address = mac; + free(mac); + } else { + std::string log_msg = "Failed to get mac address: " + std::to_string(error); + LoggerE("%s", log_msg.c_str()); + return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); + } + + error = connection_get_type(connection_handle, &connection_type); + if (CONNECTION_ERROR_NONE != error) { + std::string log_msg = "Cannot get connection type: " + std::to_string(error); + LoggerE("%s", log_msg.c_str()); + return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); + } + + if (CONNECTION_TYPE_ETHERNET == connection_type) { + //gathering profile + error = connection_get_current_profile(connection_handle, &profile_handle); + if (CONNECTION_ERROR_NONE != error) { + std::string log_msg = "Cannot get connection profile: " + std::to_string(error); + LoggerE("%s", log_msg.c_str()); + return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); + } + std::unique_ptr::type, + int (*)(connection_profile_h)> profile_handle_ptr( + profile_handle, &connection_profile_destroy); // automatically release the memory + + //gathering ips + PlatformResult ret = GetIps(profile_handle, &result_ip_address, &result_ipv6_address); + if (ret.IsError()) { + return ret; + } + } else { + LoggerD("Connection type = %d. ETHERNET is disabled", connection_type); + } + + out->insert(std::make_pair("cable", picojson::value(result_cable))); + out->insert(std::make_pair("status", picojson::value(result_status))); + out->insert(std::make_pair("ipAddress", picojson::value(result_ip_address))); + out->insert(std::make_pair("ipv6Address", picojson::value(result_ipv6_address))); + out->insert(std::make_pair("macAddress", picojson::value(result_mac_address))); + + 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); + LoggerE("%s", error_msg.c_str()); + return PlatformResult(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); + LoggerE("%s", error_msg.c_str()); + return PlatformResult(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); + LoggerE("%s", error_msg.c_str()); + return PlatformResult(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); + LoggerE("%s", error_msg.c_str()); + return PlatformResult(ErrorCode::UNKNOWN_ERR, error_msg); + } + *result_is_roaming = (0 != result_value) ? true : false; + + if (0 != vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &result_value)) { + LoggerE("Cannot get is_flight_mode value"); + return PlatformResult(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) +{ + LoggerD("Entered"); + connection_type_e connection_type = CONNECTION_TYPE_DISCONNECTED; + connection_profile_h profile_handle = nullptr; + connection_h connection_handle = nullptr; + + //connection must be created in every call, in other case error occurs + int error = connection_create(&connection_handle); + if (CONNECTION_ERROR_NONE != error) { + std::string log_msg = "Cannot create connection: " + std::to_string(error); + LoggerE("%s", log_msg.c_str()); + return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); + } + std::unique_ptr::type, int(*)(connection_h)> + connection_handle_ptr(connection_handle, &connection_destroy); + // automatically release the memory + + error = connection_get_type(connection_handle, &connection_type); + if (CONNECTION_ERROR_NONE != error) { + LoggerE("Failed to get connection type: %d", error); + return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get connection type"); + } + + char* apn = nullptr; + if (CONNECTION_TYPE_CELLULAR == connection_type) { + *result_status = kConnectionOn; + + error = connection_get_current_profile(connection_handle, + &profile_handle); + std::unique_ptr + ::type, int(*)(connection_profile_h)> + profile_handle_ptr(profile_handle, &connection_profile_destroy); + // automatically release the memory + if (CONNECTION_ERROR_NONE != error) { + LoggerE("Failed to get profile: %d", error); + return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get profile"); + } + + error = connection_profile_get_cellular_apn(profile_handle, &apn); + if (CONNECTION_ERROR_NONE != error) { + LoggerE("Failed to get apn name: %d", error); + return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get apn name"); + } + *result_apn = apn; + free(apn); + + PlatformResult ret = GetIps(profile_handle, result_ip_address, result_ipv6_address); + if (ret.IsError()) { + return ret; + } + } else { + *result_status = kConnectionOff; + + //According to previous implementation in case of error + //don't throw exception here + error = connection_get_default_cellular_service_profile( + connection_handle, + CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET, + &profile_handle); + std::unique_ptr + ::type, int(*)(connection_profile_h)> + profile_handle_ptr(profile_handle, &connection_profile_destroy); + // automatically release the memory + if (CONNECTION_ERROR_NONE == error) { + error = connection_profile_get_cellular_apn(profile_handle, &apn); + if (CONNECTION_ERROR_NONE == error) { + *result_apn = apn; + free(apn); + } else { + LoggerE("Failed to get default apn name: %d. Failing silently", + error); + } + } else { + LoggerE("Failed to get default profile: %d. Failing silently", + error); + } + } + + 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); +} + +PlatformResult SysteminfoPropertiesManager::ReportCellularNetwork(picojson::object* out, + unsigned long count) { + PlatformResult ret = SysteminfoUtils::CheckTelephonySupport(); + if (ret.IsError()) { + return ret; + } + std::string result_status; + std::string result_apn; + std::string result_ip_address; + std::string result_ipv6_address; + 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; + + //gathering vconf-based values + ret = FetchBasicSimProperties(manager_.GetTapiHandles()[count], &result_mcc, + &result_mnc, &result_cell_id, &result_lac, + &result_is_roaming, &result_is_flight_mode); + 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); + if (ret.IsError()) { + return ret; + } + + out->insert(std::make_pair("status", picojson::value(result_status))); + out->insert(std::make_pair("apn", picojson::value(result_apn))); + out->insert(std::make_pair("ipAddress", picojson::value(result_ip_address))); + out->insert(std::make_pair("ipv6Address", picojson::value(result_ipv6_address))); + out->insert(std::make_pair("mcc", picojson::value(std::to_string(result_mcc)))); + out->insert(std::make_pair("mnc", picojson::value(std::to_string(result_mnc)))); + out->insert(std::make_pair("cellId", picojson::value(std::to_string(result_cell_id)))); + out->insert(std::make_pair("lac", picojson::value(std::to_string(result_lac)))); + out->insert(std::make_pair("isRoaming", picojson::value(result_is_roaming))); + out->insert(std::make_pair("isFligthMode", picojson::value(result_is_flight_mode))); + out->insert(std::make_pair("imei", picojson::value(result_imei))); + return PlatformResult(ErrorCode::NO_ERROR); +} + +/// SIM +PlatformResult SysteminfoPropertiesManager::ReportSim(picojson::object* out, unsigned long count) { + PlatformResult ret = SysteminfoUtils::CheckTelephonySupport(); + if (ret.IsError()) { + return ret; + } + return sim_manager_.GatherSimInformation( + manager_.GetTapiHandles()[count], out); +} + +/// PERIPHERAL +PlatformResult SysteminfoPropertiesManager::ReportPeripheral(picojson::object* out) { + +/* int wireless_display_status = 0; + PlatformResult ret = GetVconfInt(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, &wireless_display_status); + if (ret.IsSuccess()) { + if (VCONFKEY_MIRACAST_WFD_SOURCE_ON == wireless_display_status) { + out.insert(std::make_pair(kVideoOutputString, picojson::value(true))); + return PlatformResult(ErrorCode::NO_ERROR); + } + }*/ + int hdmi_status = 0; + PlatformResult ret = SysteminfoUtils::GetVconfInt(VCONFKEY_SYSMAN_HDMI, &hdmi_status); + if (ret.IsSuccess()) { + if (VCONFKEY_SYSMAN_HDMI_CONNECTED == hdmi_status) { + out->insert(std::make_pair(kVideoOutputString, picojson::value(true))); + return PlatformResult(ErrorCode::NO_ERROR); + } + } + + out->insert(std::make_pair(kVideoOutputString, picojson::value(false))); + return PlatformResult(ErrorCode::NO_ERROR); +} + +/// MEMORY +PlatformResult SysteminfoPropertiesManager::ReportMemory(picojson::object* out) { + std::string state = kMemoryStateNormal; + int status = 0; + PlatformResult ret = SysteminfoUtils::GetVconfInt(VCONFKEY_SYSMAN_LOW_MEMORY, &status); + if (ret.IsSuccess()) { + switch (status) { + case VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING: + case VCONFKEY_SYSMAN_LOW_MEMORY_HARD_WARNING: + state = kMemoryStateWarinig; + break; + case VCONFKEY_SYSMAN_LOW_MEMORY_NORMAL: + default: + state = kMemoryStateNormal; + } + } + + out->insert(std::make_pair("state", picojson::value(state))); + return PlatformResult(ErrorCode::NO_ERROR); +} + +static void CreateStorageInfo(const std::string& type, struct statfs& fs, picojson::object* out) { + out->insert(std::make_pair("type", picojson::value(type))); + out->insert(std::make_pair("capacity", picojson::value(std::to_string( + static_cast(fs.f_bsize) * + static_cast(fs.f_blocks))))); + out->insert(std::make_pair("availableCapacity", picojson::value(std::to_string( + static_cast(fs.f_bsize) * + static_cast(fs.f_bavail))))); + bool isRemovable = (type == kTypeInternal) ? false : true; + out->insert(std::make_pair("isRemovable", picojson::value(isRemovable))); +} + +PlatformResult SysteminfoPropertiesManager::ReportStorage(picojson::object* out) { + int sdcardState = 0; + struct statfs fs; + + picojson::value result = picojson::value(picojson::array()); + + picojson::array& array = result.get(); + array.push_back(picojson::value(picojson::object())); + picojson::object& internal_obj = array.back().get(); + + if (statfs(kStorageInternalPath, &fs) < 0) { + LoggerE("There are no storage units detected"); + return PlatformResult(ErrorCode::UNKNOWN_ERR, "There are no storage units detected"); + } + CreateStorageInfo(kTypeInternal, fs, &internal_obj); + manager_.SetAvailableCapacityInternal(fs.f_bavail); + + if (0 == vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &sdcardState)) { + if (VCONFKEY_SYSMAN_MMC_MOUNTED == sdcardState){ + if (statfs(kStorageSdcardPath, &fs) < 0) { + LoggerE("MMC mounted, but not accessible"); + return PlatformResult(ErrorCode::UNKNOWN_ERR, "MMC mounted, but not accessible"); + } + array.push_back(picojson::value(picojson::object())); + picojson::object& external_obj = array.back().get(); + CreateStorageInfo(kTypeMmc, fs, &external_obj); + manager_.SetAvailableCapacityMmc(fs.f_bavail); + } + } + + out->insert(std::make_pair("storages", picojson::value(result))); + return PlatformResult(ErrorCode::NO_ERROR); +} + +PlatformResult SysteminfoPropertiesManager::ReportCameraFlash(picojson::object* out, + unsigned long index) { + if (index < manager_.GetCameraTypesCount()) { + std::string camera = manager_.GetCameraTypes(index); + out->insert(std::make_pair("camera", picojson::value(camera))); + } else { + return PlatformResult( + ErrorCode::NOT_SUPPORTED_ERR, + "Camera is not supported on this device"); + } + + return PlatformResult(ErrorCode::NO_ERROR); +} } // namespace systeminfo diff --git a/src/systeminfo/systeminfo_properties_manager.h b/src/systeminfo/systeminfo_properties_manager.h index ccd5808b..cb966d88 100644 --- a/src/systeminfo/systeminfo_properties_manager.h +++ b/src/systeminfo/systeminfo_properties_manager.h @@ -20,14 +20,17 @@ #include #include "common/picojson.h" #include "common/platform_result.h" +#include "systeminfo/systeminfo_sim_details_manager.h" namespace extension { namespace systeminfo { -class SystemInfoPropertiesManager { +class SysteminfoManager; + +class SysteminfoPropertiesManager { public: - SystemInfoPropertiesManager(); - ~SystemInfoPropertiesManager(); + SysteminfoPropertiesManager(SysteminfoManager& manager); + ~SysteminfoPropertiesManager(); common::PlatformResult GetPropertyValue( const std::string& prop, bool is_array_type, picojson::value* res); @@ -47,8 +50,15 @@ class SystemInfoPropertiesManager { common::PlatformResult ReportCellularNetwork(picojson::object* out, unsigned long count); common::PlatformResult ReportSim(picojson::object* out, unsigned long count); common::PlatformResult ReportPeripheral(picojson::object* out); - common::PlatformResult ReportCameraFlash(picojson::object* out); + common::PlatformResult ReportCameraFlash(picojson::object* out, unsigned long count); + common::PlatformResult ReportMemory(picojson::object* out); common::PlatformResult ReportStorage(picojson::object* out); + + common::PlatformResult FetchIsAutoRotation(bool* result); + 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 new file mode 100644 index 00000000..5493164f --- /dev/null +++ b/src/systeminfo/systeminfo_sim_details_manager.cc @@ -0,0 +1,293 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "systeminfo/systeminfo_sim_details_manager.h" + +#include "common/logger.h" + +namespace extension { +namespace systeminfo { + +namespace { +//Sim +const char* kSimStatusAbsent = "ABSENT"; +const char* kSimStatusInitializing = "INITIALIZING"; +const char* kSimStatusReady = "READY"; +const char* kSimStatusPinRequired = "PIN_REQUIRED"; +const char* kSimStatusPukRequired = "PUK_REQUIRED"; +const char* kSimStatusSimLocked = "SIM_LOCKED"; +const char* kSimStatusNetworkLocked = "NETWORK_LOCKED"; +const char* kSimStatusUnknown = "UNKNOWN"; + +void SimCphsValueCallback(TapiHandle */*handle*/, int result, void *data, void *user_data) { + LoggerD("Entered"); + SimDetailsManager* sim_mgr = static_cast(user_data); + TelSimAccessResult_t access_rt = static_cast(result); + TelSimCphsNetName_t *cphs_info = static_cast(data); + + std::string result_operator; + if (TAPI_SIM_ACCESS_SUCCESS == access_rt) { + std::stringstream s; + s << cphs_info->full_name; + if (s.str().empty()) { + s << cphs_info->short_name; + } + result_operator = s.str(); + } else { + LoggerW("Failed to retrieve cphs_info: %d", access_rt); + } + sim_mgr->set_operator_name(result_operator); + sim_mgr->TryReturn(); +} + +void SimMsisdnValueCallback(TapiHandle */*handle*/, int result, void *data, void *user_data) { + LoggerD("Entered"); + SimDetailsManager* sim_mgr = static_cast(user_data); + TelSimAccessResult_t access_rt = static_cast(result); + TelSimMsisdnList_t *msisdn_info = static_cast(data); + + std::string result_msisdn; + if (TAPI_SIM_ACCESS_SUCCESS == access_rt) { + if (msisdn_info->count > 0) { + if (strlen(msisdn_info->list[0].num) > 0) { + result_msisdn = msisdn_info->list[0].num; + } else { + LoggerW("MSISDN number empty"); + } + } else { + LoggerW("msisdn_info list empty"); + } + } else { + LoggerW("Failed to retrieve msisdn_: %d", access_rt); + } + + sim_mgr->set_msisdn(result_msisdn); + sim_mgr->TryReturn(); +} + +void SimSpnValueCallback(TapiHandle */*handle*/, int result, void *data, void *user_data) { + LoggerD("Entered"); + SimDetailsManager* sim_mgr = static_cast(user_data); + TelSimAccessResult_t access_rt = static_cast(result); + TelSimSpn_t *spn_info = static_cast(data); + + std::string result_spn; + if (TAPI_SIM_ACCESS_SUCCESS == access_rt) { + result_spn = (char *)spn_info->spn; + } else { + LoggerW("Failed to retrieve spn_: %d", access_rt); + } + + sim_mgr->set_spn(result_spn); + sim_mgr->TryReturn(); +} +} //namespace + +using common::PlatformResult; +using common::ErrorCode; + +SimDetailsManager::SimDetailsManager(): + mcc_(0), + mnc_(0), + operator_name_(""), + msin_(""), + state_(""), + msisdn_(""), + iccid_(""), + spn_(""), + sim_result_obj_(nullptr), + to_process_(0) +{ +} + +PlatformResult SimDetailsManager::GatherSimInformation(TapiHandle* handle, picojson::object* out) { + LoggerD("Entered"); + std::lock_guard first_lock_sim(sim_info_mutex_); + ResetSimHolder(out); + + FetchSimState(handle); + if (kSimStatusReady == state_) { + PlatformResult ret = FetchSimSyncProps(handle); + if (ret.IsError()) { + return ret; + } + { + //All props should be fetched synchronously, but sync function does not work + std::lock_guard lock_to_process(sim_to_process_mutex_); + //would be deleted on } ending bracket + int result = tel_get_sim_cphs_netname(handle, SimCphsValueCallback, this); + if (TAPI_API_SUCCESS == result) { + ++to_process_; + } else { + LoggerE("Failed getting cphs netname: %d", result); + } + + result = tel_get_sim_msisdn(handle, SimMsisdnValueCallback, this); + if (TAPI_API_SUCCESS == result) { + ++to_process_; + } else { + LoggerE("Failed getting msisdn: %d", result); + } + + result = tel_get_sim_spn(handle, SimSpnValueCallback, this); + if (TAPI_API_SUCCESS == result) { + ++to_process_; + } else { + LoggerE("Failed getting spn: %d", result); + } + } + //prevent returning not filled result + std::lock_guard lock_sim(sim_info_mutex_); + //result will come from callbacks + return PlatformResult(ErrorCode::NO_ERROR); + } + //if sim state is not READY return default values and don't wait for callbacks + TryReturn(); + return PlatformResult(ErrorCode::NO_ERROR); +} + +void SimDetailsManager::FetchSimState(TapiHandle *tapi_handle) { + LoggerD("Entered"); + if (nullptr == tapi_handle) { + LoggerE("Tapi handle is null"); + state_ = kSimStatusUnknown; + } else { + int card_changed = 0; + TelSimCardStatus_t sim_card_state; + int error = tel_get_sim_init_info(tapi_handle, &sim_card_state, &card_changed); + if (TAPI_API_SUCCESS == error) { + switch (sim_card_state) { + case TAPI_SIM_STATUS_CARD_NOT_PRESENT: + case TAPI_SIM_STATUS_CARD_REMOVED: + state_ = kSimStatusAbsent; + break; + case TAPI_SIM_STATUS_SIM_INITIALIZING: + state_ = kSimStatusInitializing; + break; + case TAPI_SIM_STATUS_SIM_INIT_COMPLETED: + state_ = kSimStatusReady; + break; + case TAPI_SIM_STATUS_SIM_PIN_REQUIRED: + state_ = kSimStatusPinRequired; + break; + case TAPI_SIM_STATUS_SIM_PUK_REQUIRED: + state_ = kSimStatusPukRequired; + break; + case TAPI_SIM_STATUS_SIM_LOCK_REQUIRED: + case TAPI_SIM_STATUS_CARD_BLOCKED: + state_ = kSimStatusSimLocked; + break; + case TAPI_SIM_STATUS_SIM_NCK_REQUIRED: + case TAPI_SIM_STATUS_SIM_NSCK_REQUIRED: + state_ = kSimStatusNetworkLocked; + break; + default: + state_ = kSimStatusUnknown; + break; + } + } + } +} + +PlatformResult SimDetailsManager::FetchSimSyncProps(TapiHandle *tapi_handle) { + LoggerD("Entered"); + TelSimImsiInfo_t imsi; + int error = tel_get_sim_imsi(tapi_handle, &imsi); + if (TAPI_API_SUCCESS == error) { + LoggerD("mcc: %s, mnc: %s, msin: %s", imsi.szMcc, imsi.szMnc, imsi.szMsin); + mcc_ = std::stoul(imsi.szMcc); + mnc_ = std::stoul(imsi.szMnc); + msin_ = imsi.szMsin; + } + else { + LoggerE("Failed to get sim imsi: %d", error); + return PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to get sim imsi"); + } + + //TODO add code for iccid value fetching, when proper API would be ready + iccid_ = ""; + return PlatformResult(ErrorCode::NO_ERROR); +} + +void SimDetailsManager::ResetSimHolder(picojson::object* out) { + LoggerD("Entered"); + sim_result_obj_ = out; + to_process_ = 0; + mcc_ = 0; + mnc_ = 0; + operator_name_ = ""; + msin_ = ""; + state_ = ""; + msisdn_ = ""; + iccid_ = ""; + spn_ = ""; +} + +void SimDetailsManager::ReturnSimToJS() { + LoggerD("Entered"); + if (nullptr != sim_result_obj_) { + sim_result_obj_->insert(std::make_pair("state", picojson::value(state_))); + sim_result_obj_->insert(std::make_pair("operatorName", picojson::value(operator_name_))); + sim_result_obj_->insert(std::make_pair("msisdn", picojson::value(msisdn_))); + sim_result_obj_->insert(std::make_pair("iccid", picojson::value(iccid_))); + sim_result_obj_->insert(std::make_pair("mcc", picojson::value(std::to_string(mcc_)))); + sim_result_obj_->insert(std::make_pair("mnc", picojson::value(std::to_string(mnc_)))); + sim_result_obj_->insert(std::make_pair("msin", picojson::value(msin_))); + sim_result_obj_->insert(std::make_pair("spn", picojson::value(spn_))); + //everything returned, clear pointer + sim_result_obj_ = nullptr; + } else { + LoggerE("No sim returned JSON object pointer is null"); + } +} + +void SimDetailsManager::TryReturn() { + LoggerD("Entered"); + if (0 == to_process_){ + LoggerD("Returning property to JS"); + ReturnSimToJS(); + sim_info_mutex_.unlock(); + } else { + LoggerD("Not ready yet - waiting"); + } +} + +void SimDetailsManager::set_operator_name(const std::string& name) { + LoggerD("Entered"); + std::lock_guard lock(sim_to_process_mutex_); + operator_name_ = name; + --to_process_; + LoggerD("Operator name: %s", operator_name_.c_str()); +}; + +void SimDetailsManager::set_msisdn(const std::string& msisdn) { + LoggerD("Entered"); + std::lock_guard lock(sim_to_process_mutex_); + this->msisdn_ = msisdn; + --to_process_; + LoggerD("MSISDN number: %s", this->msisdn_.c_str()); +}; + +void SimDetailsManager::set_spn(const std::string& spn) { + LoggerD("Entered"); + std::lock_guard lock(sim_to_process_mutex_); + this->spn_ = spn; + --to_process_; + LoggerD("SPN value: %s", this->spn_.c_str()); +}; + +} // namespace systeminfo +} // namespace webapi diff --git a/src/systeminfo/systeminfo_sim_details_manager.h b/src/systeminfo/systeminfo_sim_details_manager.h new file mode 100644 index 00000000..38def8f0 --- /dev/null +++ b/src/systeminfo/systeminfo_sim_details_manager.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef WEBAPI_PLUGINS_SYSTEMINFO_SYSTEMINFO_SIM_DETAILS_MANAGER_H__ +#define WEBAPI_PLUGINS_SYSTEMINFO_SYSTEMINFO_SIM_DETAILS_MANAGER_H__ + +#include +#include + +#include +#include + +#include "common/picojson.h" +#include "common/platform_result.h" + +namespace extension { +namespace systeminfo { + +class SimDetailsManager { + public: + SimDetailsManager(); + + common::PlatformResult GatherSimInformation(TapiHandle* handle, picojson::object* out); + long GetSimCount(TapiHandle **tapi_handle); + void TryReturn(); + + void set_operator_name(const std::string& name); + void set_msisdn(const std::string& msisdn); + void set_spn(const std::string& spn); + + private: + void ResetSimHolder(picojson::object* out); + void FetchSimState(TapiHandle *tapi_handle); + common::PlatformResult FetchSimSyncProps(TapiHandle *tapi_handle); + void ReturnSimToJS(); + + unsigned short mcc_; + unsigned short mnc_; + std::string operator_name_; + std::string msin_; + std::string state_; + std::string msisdn_; + std::string iccid_; + std::string spn_; + + picojson::object* sim_result_obj_; + unsigned short to_process_; + std::mutex sim_to_process_mutex_; + std::mutex sim_info_mutex_; +}; + +} // namespace systeminfo +} // namespace webapi + +#endif // WEBAPI_PLUGINS_SYSTEMINFO_SYSTEMINFO_SIM_DETAILS_MANAGER_H__