2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "systeminfo-utils.h"
18 #include "systeminfo/systeminfo_instance.h"
25 #include <system_settings.h>
26 #include <system_info.h>
27 #include <sys/statfs.h>
30 #include <vconf-internal-keys.h>
31 #include <net_connection.h>
32 #include <tapi_common.h>
33 #include <ITapiModem.h>
36 #include <device/callback.h>
37 #include <device/device-error.h>
38 #include <sensor_internal.h>
41 #include "common/logger.h"
42 #include "common/platform_exception.h"
43 #include "common/dbus_operation.h"
44 #include "common/scope_exit.h"
46 // TODO:: hardcoded value, only for IsBluetoothAlwaysOn
47 #define PROFILE_MOBILE 1
50 namespace systeminfo {
54 const std::string MEMORY_STATE_NORMAL = "NORMAL";
55 const std::string MEMORY_STATE_WARNING = "WARNING";
56 const int MEMORY_TO_BYTE = 1024;
57 const int BASE_GATHERING_INTERVAL = 100;
58 const double DISPLAY_INCH_TO_MILLIMETER = 2.54;
60 const int kTapiMaxHandle = 2;
61 const int kDefaultPropertyCount = 1;
65 using namespace common;
67 //Callback functions declarations
68 static void OnBatteryChangedCb(keynode_t* node, void* event_ptr);
69 static gboolean OnCpuChangedCb(gpointer event_ptr);
70 static gboolean OnStorageChangedCb(gpointer event_ptr);
71 static void OnMmcChangedCb(keynode_t* node, void* event_ptr);
72 static void OnDisplayChangedCb(keynode_t* node, void* event_ptr);
73 static void OnDeviceAutoRotationChangedCb(keynode_t* node, void* event_ptr);
74 static void OnDeviceOrientationChangedCb(sensor_t sensor, unsigned int event_type,
75 sensor_data_t *data, void *user_data);
76 static void OnLocaleChangedCb(system_settings_key_e key, void* event_ptr);
77 static void OnNetworkChangedCb(connection_type_e type, void* event_ptr);
78 static void OnNetworkValueChangedCb(const char* ipv4_address,
79 const char* ipv6_address, void* event_ptr);
80 static void OnCellularNetworkValueChangedCb(keynode_t *node, void *event_ptr);
81 static void OnPeripheralChangedCb(keynode_t* node, void* event_ptr);
82 static void OnMemoryChangedCb(keynode_t* node, void* event_ptr);
83 static void OnBrightnessChangedCb(device_callback_e type, void *value, void *user_data);
84 static void OnWifiLevelChangedCb (wifi_rssi_level_e rssi_level, void *user_data);
86 static void SimCphsValueCallback(TapiHandle *handle, int result, void *data, void *user_data);
87 static void SimMsisdnValueCallback(TapiHandle *handle, int result, void *data, void *user_data);
88 static void SimSpnValueCallback(TapiHandle *handle, int result, void *data, void *user_data);
92 const char* kPlatformFull = "mobile-full";
93 const char* kPlatformMobile = "mobile-web";
94 const char* kPlatformWearable = "wearable";
96 const char* kProfileFull = "MOBILE_FULL";
97 const char* kProfileMobile = "MOBILE_WEB";
98 const char* kProfileWearable = "WEARABLE";
100 const char* kOpenglesTextureDelimiter = "/";
101 const char* kOpenglesTextureUtc = "utc";
102 const char* kOpenglesTexturePtc = "ptc";
103 const char* kOpenglesTextureEtc = "etc";
104 const char* kOpenglesTexture3dc = "3dc";
105 const char* kOpenglesTextureAtc = "atc";
106 const char* kOpenglesTexturePvrtc = "pvrtc";
108 const char* kPlatformCoreDelimiter = " | ";
109 const char* kPlatformCoreArmv6 = "armv6";
110 const char* kPlatformCoreArmv7 = "armv7";
111 const char* kPlatformCoreX86 = "x86";
113 const char* kPlatformCoreSse2 = "sse2";
114 const char* kPlatformCoreSse3 = "sse3";
115 const char* kPlatformCoreSsse3 = "ssse3";
116 const char* kPlatformCoreVfpv2 = "vfpv2";
117 const char* kPlatformCoreVfpv3 = "vfpv3";
118 const std::string kPropertyIdCpu = "CPU";
120 const double kRemainingBatteryChargeMax = 100.0;
121 const int kVconfErrorNone = 0;
123 const double kDisplayBrightnessDivideValue = 100;
125 const std::string kOrientationPortraitPrimary = "PORTRAIT_PRIMARY";
126 const std::string kOrientationPortraitSecondary = "PORTRAIT_SECONDARY";
127 const std::string kOrientationLandscapePrimary = "LANDSCAPE_PRIMARY";
128 const std::string kOrientationLandscapeSecondary = "LANDSCAPE_SECONDARY";
130 const std::string kVideoOutputString = "isVideoOutputOn";
132 const char* kStorageInternalPath = "/opt/usr/media";
133 const char* kStorageSdcardPath = "/opt/storage/sdcard";
134 const std::string kPropertyIdStorage = "STORAGE";
135 const std::string kTypeUnknown = "UNKNOWN";
136 const std::string kTypeInternal = "INTERNAL";
137 const std::string kTypeUsbHost = "USB_HOST";
138 const std::string kTypeMmc = "MMC";
139 const double kPropertyWatcherTime = 1;
152 const char* kNetworkTypeNone = "NONE";
153 const char* kNetworkType2G = "2G";
154 const char* kNetworkType2_5G = "2.5G";
155 const char* kNetworkType3G = "3G";
156 const char* kNetworkType4G = "4G";
157 const char* kNetworkTypeWifi = "WIFI";
158 const char* kNetworkTypeEthernet = "ETHERNET";
159 const char* kNetworkTypeUnknown = "UNKNOWN";
161 const std::string kWifiStatusOn = "ON";
162 const std::string kWifiStatusOff = "OFF";
163 const int kWifiSignalStrengthDivideValue = 100;
165 const unsigned short kMccDivider = 100;
166 const char* kConnectionOff = "OFF";
167 const char* kConnectionOn = "ON";
169 const char* kSimStatusAbsent = "ABSENT";
170 const char* kSimStatusInitializing = "INITIALIZING";
171 const char* kSimStatusReady = "READY";
172 const char* kSimStatusPinRequired = "PIN_REQUIRED";
173 const char* kSimStatusPukRequired = "PUK_REQUIRED";
174 const char* kSimStatusSimLocked = "SIM_LOCKED";
175 const char* kSimStatusNetworkLocked = "NETWORK_LOCKED";
176 const char* kSimStatusUnknown = "UNKNOWN";
178 ///*for getCapability*/
181 const char* kTizenFeatureBluetoothAlwaysOn = "http://tizen.org/capability/network.bluetooth.always_on"; //TODO mobile/wearable: false, tv: true
182 const char* kTizenFeatureOpenglesTextureFormat = "http://tizen.org/feature/opengles.texture_format";
183 const char* kTizenFeatureCoreApiVersion = "http://tizen.org/feature/platform.core.api.version";
184 const char* kTizenFeaturePlatfromCoreCpuArch = "http://tizen.org/feature/platform.core.cpu.arch";
185 const char* kTizenFeaturePlatfromCoreFpuArch = "http://tizen.org/feature/platform.core.fpu.arch";
187 const char* kTizenFeatureProfile = "http://tizen.org/feature/profile";
189 const char* kTizenFeatureScreen = "http://tizen.org/feature/screen";
191 const char* kTizenFeatureCpuFrequency = "http://tizen.org/feature/platform.core.cpu.frequency";
193 const char* kTizenFeaturePlatformNativeApiVersion = "tizen.org/feature/platform.native.api.version";
194 const char* kTizenFeaturePlatformNativeOspCompatible = "tizen.org/feature/platform.native.osp_compatible";
195 const char* kTizenFeaturePlatformVersionName = "http://tizen.org/feature/platform.version.name";
197 static std::string parseWifiNetworkError(int error) {
199 case WIFI_ERROR_NONE : return "WIFI_ERROR_NONE";
200 case WIFI_ERROR_INVALID_PARAMETER : return "WIFI_ERROR_INVALID_PARAMETER";
201 case WIFI_ERROR_OUT_OF_MEMORY : return "WIFI_ERROR_OUT_OF_MEMORY";
202 case WIFI_ERROR_INVALID_OPERATION : return "WIFI_ERROR_INVALID_OPERATION";
203 case WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED : return "WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED";
204 case WIFI_ERROR_OPERATION_FAILED : return "WIFI_ERROR_OPERATION_FAILED";
205 case WIFI_ERROR_NO_CONNECTION : return "WIFI_ERROR_NO_CONNECTION";
206 case WIFI_ERROR_NOW_IN_PROGRESS : return "WIFI_ERROR_NOW_IN_PROGRESS";
207 case WIFI_ERROR_ALREADY_EXISTS : return "WIFI_ERROR_ALREADY_EXISTS";
208 case WIFI_ERROR_OPERATION_ABORTED : return "WIFI_ERROR_OPERATION_ABORTED";
209 case WIFI_ERROR_DHCP_FAILED : return "WIFI_ERROR_DHCP_FAILED";
210 case WIFI_ERROR_INVALID_KEY : return "WIFI_ERROR_INVALID_KEY";
211 case WIFI_ERROR_NO_REPLY : return "WIFI_ERROR_NO_REPLY";
212 case WIFI_ERROR_SECURITY_RESTRICTED : return "WIFI_ERROR_SECURITY_RESTRICTED";
213 case WIFI_ERROR_PERMISSION_DENIED : return "WIFI_ERROR_PERMISSION_DENIED";
214 case WIFI_ERROR_NOT_SUPPORTED : return "WIFI_ERROR_NOT_SUPPORTED";
215 default : return "Unknown Wi-Fi error";
221 /////////////////////////// SimDetailsManager ////////////////////////////////
223 class SimDetailsManager {
227 std::string operator_name_;
234 picojson::object* sim_result_obj_;
235 unsigned short to_process_;
236 std::mutex sim_to_process_mutex_;
237 std::mutex sim_info_mutex_;
240 void ResetSimHolder(picojson::object* out);
241 void FetchSimState(TapiHandle *tapi_handle);
242 PlatformResult FetchSimSyncProps(TapiHandle *tapi_handle);
243 void ReturnSimToJS();
248 PlatformResult GatherSimInformation(TapiHandle* handle, picojson::object* out);
249 long GetSimCount(TapiHandle **tapi_handle);
252 void set_operator_name(const std::string& name)
254 std::lock_guard<std::mutex> lock(sim_to_process_mutex_);
255 operator_name_ = name;
257 LoggerD("Operator name: %s", operator_name_.c_str());
259 void set_msisdn(const std::string& msisdn)
261 std::lock_guard<std::mutex> lock(sim_to_process_mutex_);
262 this->msisdn_ = msisdn;
264 LoggerD("MSISDN number: %s", this->msisdn_.c_str());
266 void set_spn(const std::string& spn)
268 std::lock_guard<std::mutex> lock(sim_to_process_mutex_);
271 LoggerD("SPN value: %s", this->spn_.c_str());
275 SimDetailsManager::SimDetailsManager():
284 sim_result_obj_(nullptr),
290 PlatformResult SimDetailsManager::GatherSimInformation(TapiHandle* handle, picojson::object* out)
292 std::lock_guard<std::mutex> first_lock_sim(sim_info_mutex_);
295 FetchSimState(handle);
296 if (kSimStatusReady == state_) {
297 PlatformResult ret = FetchSimSyncProps(handle);
302 //All props should be fetched synchronously, but sync function does not work
303 std::lock_guard<std::mutex> lock_to_process(sim_to_process_mutex_);
304 //would be deleted on } ending bracket
305 int result = tel_get_sim_cphs_netname(handle, SimCphsValueCallback, nullptr);
306 if (TAPI_API_SUCCESS == result) {
309 LoggerE("Failed getting cphs netname: %d", result);
312 result = tel_get_sim_msisdn(handle, SimMsisdnValueCallback, nullptr);
313 if (TAPI_API_SUCCESS == result) {
316 LoggerE("Failed getting msisdn: %d", result);
319 result = tel_get_sim_spn(handle, SimSpnValueCallback, nullptr);
320 if (TAPI_API_SUCCESS == result) {
323 LoggerE("Failed getting spn: %d", result);
326 //prevent returning not filled result
327 std::lock_guard<std::mutex> lock_sim(sim_info_mutex_);
328 //result will come from callbacks
329 return PlatformResult(ErrorCode::NO_ERROR);
331 //if sim state is not READY return default values and don't wait for callbacks
333 return PlatformResult(ErrorCode::NO_ERROR);
336 void SimDetailsManager::FetchSimState(TapiHandle *tapi_handle)
339 if (nullptr == tapi_handle) {
340 LoggerE("Tapi handle is null");
341 state_ = kSimStatusUnknown;
343 int card_changed = 0;
344 TelSimCardStatus_t sim_card_state;
345 int error = tel_get_sim_init_info(tapi_handle, &sim_card_state, &card_changed);
346 if (TAPI_API_SUCCESS == error) {
347 switch (sim_card_state) {
348 case TAPI_SIM_STATUS_CARD_NOT_PRESENT:
349 case TAPI_SIM_STATUS_CARD_REMOVED:
350 state_ = kSimStatusAbsent;
352 case TAPI_SIM_STATUS_SIM_INITIALIZING:
353 state_ = kSimStatusInitializing;
355 case TAPI_SIM_STATUS_SIM_INIT_COMPLETED:
356 state_ = kSimStatusReady;
358 case TAPI_SIM_STATUS_SIM_PIN_REQUIRED:
359 state_ = kSimStatusPinRequired;
361 case TAPI_SIM_STATUS_SIM_PUK_REQUIRED:
362 state_ = kSimStatusPukRequired;
364 case TAPI_SIM_STATUS_SIM_LOCK_REQUIRED:
365 case TAPI_SIM_STATUS_CARD_BLOCKED:
366 state_ = kSimStatusSimLocked;
368 case TAPI_SIM_STATUS_SIM_NCK_REQUIRED:
369 case TAPI_SIM_STATUS_SIM_NSCK_REQUIRED:
370 state_ = kSimStatusNetworkLocked;
373 state_ = kSimStatusUnknown;
380 PlatformResult SimDetailsManager::FetchSimSyncProps(TapiHandle *tapi_handle)
383 TelSimImsiInfo_t imsi;
384 int error = tel_get_sim_imsi(tapi_handle, &imsi);
385 if (TAPI_API_SUCCESS == error) {
386 LoggerD("mcc: %s, mnc: %s, msin: %s", imsi.szMcc, imsi.szMnc, imsi.szMsin);
387 mcc_ = std::stoul(imsi.szMcc);
388 mnc_ = std::stoul(imsi.szMnc);
392 LoggerE("Failed to get sim imsi: %d", error);
393 return PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to get sim imsi");
396 //TODO add code for iccid value fetching, when proper API would be ready
398 return PlatformResult(ErrorCode::NO_ERROR);
401 void SimDetailsManager::ResetSimHolder(picojson::object* out){
402 sim_result_obj_ = out;
414 void SimDetailsManager::ReturnSimToJS(){
416 if (nullptr != sim_result_obj_) {
417 sim_result_obj_->insert(std::make_pair("state", picojson::value(state_)));
418 sim_result_obj_->insert(std::make_pair("operatorName", picojson::value(operator_name_)));
419 sim_result_obj_->insert(std::make_pair("msisdn", picojson::value(msisdn_)));
420 sim_result_obj_->insert(std::make_pair("iccid", picojson::value(iccid_)));
421 sim_result_obj_->insert(std::make_pair("mcc", picojson::value(std::to_string(mcc_))));
422 sim_result_obj_->insert(std::make_pair("mnc", picojson::value(std::to_string(mnc_))));
423 sim_result_obj_->insert(std::make_pair("msin", picojson::value(msin_)));
424 sim_result_obj_->insert(std::make_pair("spn", picojson::value(spn_)));
425 //everything returned, clear pointer
426 sim_result_obj_ = nullptr;
428 LoggerE("No sim returned JSON object pointer is null");
432 long SimDetailsManager::GetSimCount(TapiHandle **tapi_handle){
433 if (0 != sim_count_){
434 LoggerD("Sim counted already");
436 LoggerD("Gathering sim count");
437 char **cp_list = tel_get_cp_name_list();
438 if (cp_list != NULL) {
439 while (cp_list[sim_count_]) {
440 tapi_handle[sim_count_] = tel_init(cp_list[sim_count_]);
441 if (tapi_handle[sim_count_] == NULL) {
442 LoggerE("Failed to connect with tapi, handle is null");
446 LoggerD("%d modem: %s", sim_count_, cp_list[sim_count_]);
449 LoggerE("Failed to get cp list");
450 sim_count_ = kTapiMaxHandle;
457 void SimDetailsManager::TryReturn(){
458 if (0 == to_process_){
459 LoggerD("Returning property to JS");
461 sim_info_mutex_.unlock();
463 LoggerD("Not ready yet - waiting");
467 /////////////////////////// SystemInfoListeners ////////////////////////////////
469 class SystemInfoListeners {
471 SystemInfoListeners();
472 ~SystemInfoListeners();
474 PlatformResult RegisterBatteryListener(const SysteminfoUtilsCallback& callback,
475 SysteminfoInstance& instance);
476 PlatformResult UnregisterBatteryListener();
477 PlatformResult RegisterCpuListener(const SysteminfoUtilsCallback& callback,
478 SysteminfoInstance& instance);
479 PlatformResult UnregisterCpuListener();
480 PlatformResult RegisterStorageListener(const SysteminfoUtilsCallback& callback,
481 SysteminfoInstance& instance);
482 PlatformResult UnregisterStorageListener();
483 PlatformResult RegisterDisplayListener(const SysteminfoUtilsCallback& callback,
484 SysteminfoInstance& instance);
485 PlatformResult UnregisterDisplayListener();
486 PlatformResult RegisterDeviceOrientationListener(const SysteminfoUtilsCallback& callback,
487 SysteminfoInstance& instance);
488 PlatformResult UnregisterDeviceOrientationListener();
489 PlatformResult RegisterLocaleListener(const SysteminfoUtilsCallback& callback,
490 SysteminfoInstance& instance);
491 PlatformResult UnregisterLocaleListener();
492 PlatformResult RegisterNetworkListener(const SysteminfoUtilsCallback& callback,
493 SysteminfoInstance& instance);
494 PlatformResult UnregisterNetworkListener();
495 PlatformResult RegisterWifiNetworkListener(const SysteminfoUtilsCallback& callback,
496 SysteminfoInstance& instance);
497 PlatformResult UnregisterWifiNetworkListener();
498 PlatformResult RegisterEthernetNetworkListener(const SysteminfoUtilsCallback& callback,
499 SysteminfoInstance& instance);
500 PlatformResult UnregisterEthernetNetworkListener();
501 PlatformResult RegisterCellularNetworkListener(const SysteminfoUtilsCallback& callback,
502 SysteminfoInstance& instance);
503 PlatformResult UnregisterCellularNetworkListener();
504 PlatformResult RegisterPeripheralListener(const SysteminfoUtilsCallback& callback,
505 SysteminfoInstance& instance);
506 PlatformResult UnregisterPeripheralListener();
507 PlatformResult RegisterMemoryListener(const SysteminfoUtilsCallback& callback,
508 SysteminfoInstance& instance);
509 PlatformResult UnregisterMemoryListener();
510 PlatformResult RegisterCameraFlashListener(const SysteminfoUtilsCallback& callback,
511 SysteminfoInstance& instance);
512 PlatformResult UnregisterCameraFlashListener();
514 void SetCpuInfoLoad(double load);
515 void SetAvailableCapacityInternal(unsigned long long capacity);
516 void SetAvailableCapacityMmc(unsigned long long capacity);
518 void OnBatteryChangedCallback(keynode_t* node, void* event_ptr);
519 void OnCpuChangedCallback(void* event_ptr);
520 void OnStorageChangedCallback(void* event_ptr);
521 void OnMmcChangedCallback(keynode_t* node, void* event_ptr);
522 void OnDisplayChangedCallback(keynode_t* node, void* event_ptr);
523 void OnDeviceAutoRotationChangedCallback(keynode_t* node, void* event_ptr);
524 void OnDeviceOrientationChangedCallback(sensor_t sensor, unsigned int event_type,
525 sensor_data_t *data, void *user_data);
526 void OnLocaleChangedCallback(system_settings_key_e key, void* event_ptr);
527 void OnNetworkChangedCallback(connection_type_e type, void* event_ptr);
528 void OnNetworkValueCallback(const char* ipv4_address,
529 const char* ipv6_address, void* event_ptr);
530 void OnCellularNetworkValueCallback(keynode_t *node, void *event_ptr);
531 void OnPeripheralChangedCallback(keynode_t* node, void* event_ptr);
532 void OnMemoryChangedCallback(keynode_t* node, void* event_ptr);
533 void OnBrightnessChangedCallback(device_callback_e type, void* value, void* user_data);
535 TapiHandle* GetTapiHandle();
536 TapiHandle** GetTapiHandles();
537 PlatformResult GetConnectionHandle(connection_h&);
538 int GetSensorHandle();
539 PlatformResult ConnectSensor(int* result);
540 void DisconnectSensor(int handle_orientation);
541 wifi_rssi_level_e GetWifiLevel();
542 void SetWifiLevel(wifi_rssi_level_e level);
543 std::string GetCameraTypes(int index);
544 int GetCameraTypesCount();
546 static PlatformResult RegisterVconfCallback(const char *in_key, vconf_callback_fn cb,
547 SysteminfoInstance& instance);
548 static PlatformResult UnregisterVconfCallback(const char *in_key, vconf_callback_fn cb);
549 PlatformResult RegisterIpChangeCallback(SysteminfoInstance& instance);
550 PlatformResult UnregisterIpChangeCallback();
551 bool IsIpChangeCallbackInvalid();
552 void InitTapiHandles();
553 void InitCameraTypes();
555 guint m_cpu_event_id;
556 guint m_storage_event_id;
559 double m_last_cpu_load;
560 unsigned long long m_available_capacity_internal;
561 unsigned long long m_available_capacity_mmc;
562 unsigned long long m_last_available_capacity_internal;
563 unsigned long long m_last_available_capacity_mmc;
564 wifi_rssi_level_e m_wifi_level;
566 SysteminfoUtilsCallback m_battery_listener;
567 SysteminfoUtilsCallback m_cpu_listener;
568 SysteminfoUtilsCallback m_storage_listener;
569 SysteminfoUtilsCallback m_display_listener;
570 SysteminfoUtilsCallback m_device_orientation_listener;
571 SysteminfoUtilsCallback m_locale_listener;
572 SysteminfoUtilsCallback m_network_listener;
573 SysteminfoUtilsCallback m_wifi_network_listener;
574 SysteminfoUtilsCallback m_ethernet_network_listener;
575 SysteminfoUtilsCallback m_cellular_network_listener;
576 SysteminfoUtilsCallback m_peripheral_listener;
577 SysteminfoUtilsCallback m_memory_listener;
578 SysteminfoUtilsCallback m_camera_flash_listener;
580 TapiHandle *m_tapi_handles[kTapiMaxHandle+1];
581 //for ip change callback
582 connection_h m_connection_handle;
583 //! Sensor handle for DeviceOrientation purposes
585 std::vector<std::string> m_camera_types;
587 SystemInfoListeners::SystemInfoListeners():
589 m_storage_event_id(0),
592 m_available_capacity_internal(0),
593 m_available_capacity_mmc(0),
594 m_last_available_capacity_internal(0),
595 m_last_available_capacity_mmc(0),
596 m_wifi_level(WIFI_RSSI_LEVEL_0),
597 m_battery_listener(nullptr),
598 m_cpu_listener(nullptr),
599 m_storage_listener(nullptr),
600 m_display_listener(nullptr),
601 m_device_orientation_listener(nullptr),
602 m_locale_listener(nullptr),
603 m_network_listener(nullptr),
604 m_wifi_network_listener(nullptr),
605 m_ethernet_network_listener(nullptr),
606 m_cellular_network_listener(nullptr),
607 m_peripheral_listener(nullptr),
608 m_memory_listener(nullptr),
609 m_camera_flash_listener(nullptr),
610 m_tapi_handles{nullptr},
611 m_connection_handle(nullptr),
615 int error = wifi_initialize();
616 if (WIFI_ERROR_NONE != error) {
617 std::string log_msg = "Initialize failed: " + parseWifiNetworkError(error);
618 LoggerE("%s", log_msg.c_str());
620 LoggerD("WIFI initialization succeed");
623 error = wifi_set_rssi_level_changed_cb(OnWifiLevelChangedCb, nullptr);
624 if (WIFI_ERROR_NONE != error) {
625 std::string log_msg = "Setting wifi listener failed: " + parseWifiNetworkError(error);
626 LoggerE("%s", log_msg.c_str());
628 LoggerD("Setting wifi listener succeed");
633 SystemInfoListeners::~SystemInfoListeners(){
635 UnregisterBatteryListener();
636 UnregisterCpuListener();
637 UnregisterStorageListener();
638 UnregisterDisplayListener();
639 UnregisterDeviceOrientationListener();
640 UnregisterLocaleListener();
641 UnregisterNetworkListener();
642 UnregisterWifiNetworkListener();
643 UnregisterCellularNetworkListener();
644 UnregisterPeripheralListener();
645 UnregisterMemoryListener();
647 DisconnectSensor(m_sensor_handle);
650 while(m_tapi_handles[i]) {
651 tel_deinit(m_tapi_handles[i]);
654 if (nullptr != m_connection_handle) {
655 connection_destroy(m_connection_handle);
661 #define CHECK_LISTENER_ERROR(method) \
663 if (ret.IsError()) { \
667 int SystemInfoListeners::GetSensorHandle() {
668 if (m_sensor_handle < 0) {
669 LoggerD("Connecting to sensor");
670 ConnectSensor(&m_sensor_handle);
672 LoggerD("Sensor already connected");
674 return m_sensor_handle;
677 PlatformResult SystemInfoListeners::ConnectSensor(int* result) {
679 sensor_t sensor = sensord_get_sensor(AUTO_ROTATION_SENSOR);
680 int handle_orientation = sensord_connect(sensor);
681 if (handle_orientation < 0) {
682 std::string log_msg = "Failed to connect auto rotation sensor";
683 LoggerE("%s", log_msg.c_str());
684 return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg);
686 bool ret = sensord_start(handle_orientation, 0);
688 sensord_disconnect(handle_orientation);
689 std::string log_msg = "Failed to start auto rotation sensor";
690 LoggerE("%s", log_msg.c_str());
691 return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg);
693 LoggerD("Sensor starts successfully = %d", handle_orientation);
694 *result = handle_orientation;
695 return PlatformResult(ErrorCode::NO_ERROR);
698 void SystemInfoListeners::DisconnectSensor(int handle_orientation)
700 if (handle_orientation >= 0) {
702 bool state = sensord_stop(handle_orientation);
703 LoggerD("sensord_stop() returned state = %d", state);
704 state = sensord_disconnect(handle_orientation);
705 LoggerD("sensord_disconnect() returned state %d", state);
707 LoggerD("sensor already disconnected - no action needed");
711 wifi_rssi_level_e SystemInfoListeners::GetWifiLevel()
716 void SystemInfoListeners::SetWifiLevel(wifi_rssi_level_e level)
718 m_wifi_level = level;
721 std::string SystemInfoListeners::GetCameraTypes(int index) {
722 if (index >= m_camera_types.size()) {
725 return m_camera_types[index];
728 int SystemInfoListeners::GetCameraTypesCount() {
729 return m_camera_types.size();
732 PlatformResult SystemInfoListeners::RegisterBatteryListener(
733 const SysteminfoUtilsCallback& callback, SysteminfoInstance& instance) {
735 if (nullptr == m_battery_listener) {
736 PlatformResult ret = PlatformResult(ErrorCode::NO_ERROR);
737 CHECK_LISTENER_ERROR(
738 RegisterVconfCallback(VCONFKEY_SYSMAN_BATTERY_CAPACITY, OnBatteryChangedCb, instance))
739 CHECK_LISTENER_ERROR(
740 RegisterVconfCallback(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, OnBatteryChangedCb, instance))
741 LoggerD("Added callback for BATTERY");
742 m_battery_listener = callback;
744 return PlatformResult(ErrorCode::NO_ERROR);
747 PlatformResult SystemInfoListeners::UnregisterBatteryListener()
749 if (nullptr != m_battery_listener) {
750 PlatformResult ret = PlatformResult(ErrorCode::NO_ERROR);
751 CHECK_LISTENER_ERROR(
752 UnregisterVconfCallback(VCONFKEY_SYSMAN_BATTERY_CAPACITY, OnBatteryChangedCb))
753 CHECK_LISTENER_ERROR(
754 UnregisterVconfCallback(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, OnBatteryChangedCb))
755 LoggerD("Removed callback for BATTERY");
756 m_battery_listener = nullptr;
758 return PlatformResult(ErrorCode::NO_ERROR);
761 PlatformResult SystemInfoListeners::RegisterCpuListener(const SysteminfoUtilsCallback& callback,
762 SysteminfoInstance& instance)
764 if (nullptr == m_cpu_listener) {
765 m_cpu_event_id = g_timeout_add_seconds(kPropertyWatcherTime, OnCpuChangedCb, static_cast<void*>(&instance));
766 LoggerD("Added callback for CPU");
767 m_cpu_listener = callback;
769 return PlatformResult(ErrorCode::NO_ERROR);
772 PlatformResult SystemInfoListeners::UnregisterCpuListener()
774 if (nullptr != m_cpu_listener) {
775 g_source_remove(m_cpu_event_id);
777 LoggerD("Removed callback for CPU");
778 m_cpu_listener = nullptr;
780 return PlatformResult(ErrorCode::NO_ERROR);
783 PlatformResult SystemInfoListeners::RegisterStorageListener(const SysteminfoUtilsCallback& callback,
784 SysteminfoInstance& instance)
786 if (nullptr == m_storage_listener) {
787 PlatformResult ret = PlatformResult(ErrorCode::NO_ERROR);
788 CHECK_LISTENER_ERROR(
789 RegisterVconfCallback(VCONFKEY_SYSMAN_MMC_STATUS, OnMmcChangedCb, instance))
791 m_storage_event_id = g_timeout_add_seconds(kPropertyWatcherTime, OnStorageChangedCb, static_cast<void*>(&instance));
792 LoggerD("Added callback for STORAGE");
793 m_storage_listener = callback;
795 return PlatformResult(ErrorCode::NO_ERROR);
798 PlatformResult SystemInfoListeners::UnregisterStorageListener()
800 if (nullptr != m_storage_listener) {
801 PlatformResult ret = PlatformResult(ErrorCode::NO_ERROR);
802 CHECK_LISTENER_ERROR(
803 UnregisterVconfCallback(VCONFKEY_SYSMAN_MMC_STATUS, OnMmcChangedCb))
805 g_source_remove(m_storage_event_id);
806 m_storage_event_id = 0;
807 LoggerD("Removed callback for STORAGE");
808 m_storage_listener = nullptr;
810 return PlatformResult(ErrorCode::NO_ERROR);
813 PlatformResult SystemInfoListeners::RegisterDisplayListener(const SysteminfoUtilsCallback& callback,
814 SysteminfoInstance& instance)
816 if (nullptr == m_display_listener) {
817 PlatformResult ret = PlatformResult(ErrorCode::NO_ERROR);
818 CHECK_LISTENER_ERROR(
819 RegisterVconfCallback(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, OnDisplayChangedCb, instance))
820 LoggerD("Added callback for DISPLAY");
821 m_display_listener = callback;
823 return PlatformResult(ErrorCode::NO_ERROR);
826 PlatformResult SystemInfoListeners::UnregisterDisplayListener()
828 if (nullptr != m_display_listener) {
829 PlatformResult ret = PlatformResult(ErrorCode::NO_ERROR);
830 CHECK_LISTENER_ERROR(
831 UnregisterVconfCallback(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, OnDisplayChangedCb))
832 LoggerD("Removed callback for DISPLAY");
833 m_display_listener = nullptr;
835 return PlatformResult(ErrorCode::NO_ERROR);
838 PlatformResult SystemInfoListeners::RegisterDeviceOrientationListener(const SysteminfoUtilsCallback& callback,
839 SysteminfoInstance& instance)
841 if (nullptr == m_device_orientation_listener) {
842 PlatformResult ret = PlatformResult(ErrorCode::NO_ERROR);
843 CHECK_LISTENER_ERROR(
844 RegisterVconfCallback(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, OnDeviceAutoRotationChangedCb, instance))
846 bool sensor_ret = sensord_register_event(GetSensorHandle(), AUTO_ROTATION_EVENT_CHANGE_STATE,
847 BASE_GATHERING_INTERVAL, 0,
848 OnDeviceOrientationChangedCb, static_cast<void*>(&instance));
850 LoggerE("Failed to register orientation change event listener");
851 return PlatformResult(ErrorCode::UNKNOWN_ERR,
852 "Failed to register orientation change event listener");
855 LoggerD("Added callback for DEVICE_ORIENTATION");
856 m_device_orientation_listener = callback;
858 return PlatformResult(ErrorCode::NO_ERROR);
861 PlatformResult SystemInfoListeners::UnregisterDeviceOrientationListener()
863 if (nullptr != m_device_orientation_listener) {
864 PlatformResult ret = PlatformResult(ErrorCode::NO_ERROR);
865 CHECK_LISTENER_ERROR(
866 UnregisterVconfCallback(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, OnDeviceAutoRotationChangedCb))
867 bool sensor_ret = sensord_unregister_event(GetSensorHandle(), AUTO_ROTATION_EVENT_CHANGE_STATE);
869 LoggerE("Failed to unregister orientation change event listener");
870 return PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to unregister"
871 " orientation change event listener");
874 LoggerD("Removed callback for DEVICE_ORIENTATION");
875 m_device_orientation_listener = nullptr;
877 return PlatformResult(ErrorCode::NO_ERROR);
880 PlatformResult SystemInfoListeners::RegisterLocaleListener(const SysteminfoUtilsCallback& callback,
881 SysteminfoInstance& instance)
883 if (nullptr == m_locale_listener) {
884 if (SYSTEM_SETTINGS_ERROR_NONE !=
885 system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_LOCALE_COUNTRY,
886 OnLocaleChangedCb, static_cast<void*>(&instance)) ) {
887 LoggerE("Country change callback registration failed");
888 return PlatformResult(ErrorCode::UNKNOWN_ERR, "Country change callback registration failed");
890 if (SYSTEM_SETTINGS_ERROR_NONE !=
891 system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE,
892 OnLocaleChangedCb, static_cast<void*>(&instance)) ) {
893 LoggerE("Language change callback registration failed");
894 return PlatformResult(ErrorCode::UNKNOWN_ERR, "Language change callback registration failed");
896 LoggerD("Added callback for LOCALE");
897 m_locale_listener = callback;
899 return PlatformResult(ErrorCode::NO_ERROR);
902 PlatformResult SystemInfoListeners::UnregisterLocaleListener()
904 if (nullptr != m_locale_listener) {
905 if (SYSTEM_SETTINGS_ERROR_NONE !=
906 system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE) ) {
907 LoggerE("Unregistration of language change callback failed");
909 if (SYSTEM_SETTINGS_ERROR_NONE !=
910 system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_LOCALE_COUNTRY) ) {
911 LoggerE("Unregistration of country change callback failed");
913 LoggerD("Removed callback for LOCALE");
914 m_locale_listener = nullptr;
916 return PlatformResult(ErrorCode::NO_ERROR);
919 PlatformResult SystemInfoListeners::RegisterNetworkListener(const SysteminfoUtilsCallback& callback,
920 SysteminfoInstance& instance)
922 if (nullptr == m_network_listener) {
924 PlatformResult ret(ErrorCode::NO_ERROR);
925 CHECK_LISTENER_ERROR(GetConnectionHandle(handle))
926 if (CONNECTION_ERROR_NONE !=
927 connection_set_type_changed_cb(handle, OnNetworkChangedCb, static_cast<void*>(&instance))) {
928 return PlatformResult(ErrorCode::UNKNOWN_ERR, "Registration of listener failed");
930 LoggerD("Added callback for NETWORK");
931 m_network_listener = callback;
933 return PlatformResult(ErrorCode::NO_ERROR);
936 PlatformResult SystemInfoListeners::UnregisterNetworkListener()
938 if (nullptr != m_network_listener) {
940 PlatformResult ret(ErrorCode::NO_ERROR);
941 CHECK_LISTENER_ERROR(GetConnectionHandle(handle))
942 if (CONNECTION_ERROR_NONE != connection_unset_type_changed_cb(handle)) {
943 return PlatformResult(ErrorCode::UNKNOWN_ERR, "Unregistration of listener failed");
945 LoggerD("Removed callback for NETWORK");
946 m_network_listener = nullptr;
948 return PlatformResult(ErrorCode::NO_ERROR);
951 PlatformResult SystemInfoListeners::RegisterWifiNetworkListener(const SysteminfoUtilsCallback& callback,
952 SysteminfoInstance& instance)
956 if (IsIpChangeCallbackInvalid()) {
957 PlatformResult ret = PlatformResult(ErrorCode::NO_ERROR);
958 CHECK_LISTENER_ERROR(RegisterIpChangeCallback(instance));
959 LoggerD("Registered IP change listener");
961 LoggerD("No need to register IP listener on platform, already registered");
964 if (nullptr == m_wifi_network_listener) {
965 LoggerD("Added callback for WIFI_NETWORK");
966 m_wifi_network_listener = callback;
968 return PlatformResult(ErrorCode::NO_ERROR);
971 PlatformResult SystemInfoListeners::UnregisterWifiNetworkListener()
975 m_wifi_network_listener = nullptr;
977 if (IsIpChangeCallbackInvalid()) {
978 PlatformResult ret = PlatformResult(ErrorCode::NO_ERROR);
979 CHECK_LISTENER_ERROR(UnregisterIpChangeCallback());
980 LoggerD("Removed IP change listener");
982 LoggerD("Removed callback for WIFI_NETWORK, but IP change listener still works");
985 return PlatformResult(ErrorCode::NO_ERROR);
988 PlatformResult CheckIfEthernetNetworkSupported()
991 connection_h connection_handle = nullptr;
992 connection_ethernet_state_e connection_state = CONNECTION_ETHERNET_STATE_DEACTIVATED;
994 int error = connection_create(&connection_handle);
995 if (CONNECTION_ERROR_NONE != error) {
996 std::string log_msg = "Cannot create connection: " + std::to_string(error);
997 LoggerE("%s", log_msg.c_str());
998 return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg);
1000 std::unique_ptr<std::remove_pointer<connection_h>::type, int (*)(connection_h)> connection_handle_ptr(
1001 connection_handle, &connection_destroy); // automatically release the memory
1003 error = connection_get_ethernet_state(connection_handle, &connection_state);
1004 if (CONNECTION_ERROR_NOT_SUPPORTED == error) {
1005 std::string log_msg = "Cannot get ethernet connection state: Not supported";
1006 LoggerE("%s", log_msg.c_str());
1007 return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, log_msg);
1009 return PlatformResult(ErrorCode::NO_ERROR);
1012 common::PlatformResult CheckTelephonySupport() {
1013 bool supported = false;
1014 PlatformResult ret = SystemInfoDeviceCapability::GetValueBool(
1015 "tizen.org/feature/network.telephony", &supported);
1016 if (ret.IsError()) {
1020 LoggerD("Telephony is not supported on this device");
1021 return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR,
1022 "Telephony is not supported on this device");
1024 return PlatformResult(ErrorCode::NO_ERROR);
1027 common::PlatformResult CheckCameraFlashSupport() {
1028 bool supported = false;
1029 PlatformResult ret = SystemInfoDeviceCapability::GetValueBool(
1030 "tizen.org/feature/camera.back.flash", &supported);
1031 if (ret.IsError()) {
1035 LoggerD("Back-facing camera with a flash is not supported on this device");
1036 return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR,
1037 "Back-facing camera with a flash is not supported on this device");
1039 return PlatformResult(ErrorCode::NO_ERROR);
1042 PlatformResult SystemInfoListeners::RegisterEthernetNetworkListener(const SysteminfoUtilsCallback& callback,
1043 SysteminfoInstance& instance)
1046 PlatformResult ret = CheckIfEthernetNetworkSupported();
1051 if (IsIpChangeCallbackInvalid()) {
1052 PlatformResult ret = PlatformResult(ErrorCode::NO_ERROR);
1053 CHECK_LISTENER_ERROR(RegisterIpChangeCallback(instance));
1054 LoggerD("Registered IP change listener");
1056 LoggerD("No need to register IP listener on platform, already registered");
1059 if (nullptr == m_ethernet_network_listener) {
1060 LoggerD("Added callback for ETHERNET_NETWORK");
1061 m_ethernet_network_listener = callback;
1063 return PlatformResult(ErrorCode::NO_ERROR);
1066 PlatformResult SystemInfoListeners::UnregisterEthernetNetworkListener()
1070 m_ethernet_network_listener = nullptr;
1072 if (IsIpChangeCallbackInvalid()) {
1073 PlatformResult ret = PlatformResult(ErrorCode::NO_ERROR);
1074 CHECK_LISTENER_ERROR(UnregisterIpChangeCallback());
1075 LoggerD("Removed IP change listener");
1077 LoggerD("Removed callback for ETHERNET_NETWORK, but IP change listener still works");
1080 return PlatformResult(ErrorCode::NO_ERROR);
1083 PlatformResult SystemInfoListeners::RegisterCellularNetworkListener(const SysteminfoUtilsCallback& callback,
1084 SysteminfoInstance& instance)
1087 PlatformResult ret = CheckTelephonySupport();
1088 if (ret.IsError()) {
1092 if (IsIpChangeCallbackInvalid()) {
1093 CHECK_LISTENER_ERROR(RegisterIpChangeCallback(instance));
1094 LoggerD("Registered IP change listener");
1096 LoggerD("No need to register IP listener on platform, already registered");
1099 if (nullptr == m_cellular_network_listener) {
1100 CHECK_LISTENER_ERROR(RegisterVconfCallback(VCONFKEY_TELEPHONY_FLIGHT_MODE,
1101 OnCellularNetworkValueChangedCb, instance))
1102 CHECK_LISTENER_ERROR(RegisterVconfCallback(VCONFKEY_TELEPHONY_CELLID,
1103 OnCellularNetworkValueChangedCb, instance))
1104 CHECK_LISTENER_ERROR(RegisterVconfCallback(VCONFKEY_TELEPHONY_LAC,
1105 OnCellularNetworkValueChangedCb, instance))
1106 CHECK_LISTENER_ERROR(RegisterVconfCallback(VCONFKEY_TELEPHONY_SVC_ROAM,
1107 OnCellularNetworkValueChangedCb, instance))
1108 LoggerD("Added callback for CELLULAR_NETWORK");
1109 m_cellular_network_listener = callback;
1111 return PlatformResult(ErrorCode::NO_ERROR);
1114 PlatformResult SystemInfoListeners::UnregisterCellularNetworkListener()
1118 if (nullptr != m_cellular_network_listener) {
1119 PlatformResult ret = PlatformResult(ErrorCode::NO_ERROR);
1120 CHECK_LISTENER_ERROR(UnregisterVconfCallback(VCONFKEY_TELEPHONY_FLIGHT_MODE,
1121 OnCellularNetworkValueChangedCb))
1122 CHECK_LISTENER_ERROR(UnregisterVconfCallback(VCONFKEY_TELEPHONY_CELLID,
1123 OnCellularNetworkValueChangedCb))
1124 CHECK_LISTENER_ERROR(UnregisterVconfCallback(VCONFKEY_TELEPHONY_LAC,
1125 OnCellularNetworkValueChangedCb))
1126 CHECK_LISTENER_ERROR(UnregisterVconfCallback(VCONFKEY_TELEPHONY_SVC_ROAM,
1127 OnCellularNetworkValueChangedCb))
1129 m_cellular_network_listener = nullptr;
1131 if (IsIpChangeCallbackInvalid()) {
1132 PlatformResult ret = PlatformResult(ErrorCode::NO_ERROR);
1133 CHECK_LISTENER_ERROR(UnregisterIpChangeCallback());
1134 LoggerD("Removed IP change listener");
1136 LoggerD("Removed callback for CELLULAR_NETWORK, but IP change listener still works");
1139 return PlatformResult(ErrorCode::NO_ERROR);
1142 PlatformResult SystemInfoListeners::RegisterPeripheralListener(const SysteminfoUtilsCallback& callback,
1143 SysteminfoInstance& instance)
1145 if (nullptr == m_peripheral_listener) {
1146 PlatformResult ret = PlatformResult(ErrorCode::NO_ERROR);
1148 /* if (-1 != vconf_get_int(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, &value)) {
1149 CHECK_LISTENER_ERROR(RegisterVconfCallback(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS,
1150 OnPeripheralChangedCb, instance))
1152 if (-1 != vconf_get_int(VCONFKEY_SYSMAN_HDMI, &value)) {
1153 CHECK_LISTENER_ERROR(RegisterVconfCallback(VCONFKEY_SYSMAN_HDMI,
1154 OnPeripheralChangedCb, instance))
1157 LoggerD("Added callback for PERIPHERAL");
1158 m_peripheral_listener = callback;
1160 return PlatformResult(ErrorCode::NO_ERROR);
1163 PlatformResult SystemInfoListeners::UnregisterPeripheralListener()
1165 if (nullptr != m_peripheral_listener) {
1166 PlatformResult ret = PlatformResult(ErrorCode::NO_ERROR);
1168 /* if (-1 != vconf_get_int(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, &value)) {
1169 CHECK_LISTENER_ERROR(UnregisterVconfCallback(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS,
1170 OnPeripheralChangedCb))
1172 if (-1 != vconf_get_int(VCONFKEY_SYSMAN_HDMI, &value)) {
1173 CHECK_LISTENER_ERROR(UnregisterVconfCallback(VCONFKEY_SYSMAN_HDMI,
1174 OnPeripheralChangedCb))
1177 LoggerD("Removed callback for PERIPHERAL");
1178 m_peripheral_listener = nullptr;
1180 return PlatformResult(ErrorCode::NO_ERROR);
1183 PlatformResult SystemInfoListeners::RegisterMemoryListener(const SysteminfoUtilsCallback& callback,
1184 SysteminfoInstance& instance)
1186 if (nullptr == m_memory_listener) {
1187 PlatformResult ret = PlatformResult(ErrorCode::NO_ERROR);
1189 if (-1 != vconf_get_int(VCONFKEY_SYSMAN_LOW_MEMORY, &value)) {
1190 CHECK_LISTENER_ERROR(RegisterVconfCallback(VCONFKEY_SYSMAN_LOW_MEMORY, OnMemoryChangedCb, instance))
1192 LoggerD("Added callback for MEMORY");
1193 m_memory_listener = callback;
1195 return PlatformResult(ErrorCode::NO_ERROR);
1198 PlatformResult SystemInfoListeners::UnregisterMemoryListener()
1200 if (nullptr != m_memory_listener) {
1201 PlatformResult ret = PlatformResult(ErrorCode::NO_ERROR);
1203 if (-1 != vconf_get_int(VCONFKEY_SYSMAN_LOW_MEMORY, &value)) {
1204 CHECK_LISTENER_ERROR(UnregisterVconfCallback(VCONFKEY_SYSMAN_LOW_MEMORY, OnMemoryChangedCb))
1206 LoggerD("Removed callback for MEMORY");
1207 m_memory_listener = nullptr;
1209 return PlatformResult(ErrorCode::NO_ERROR);
1212 PlatformResult SystemInfoListeners::RegisterCameraFlashListener(const SysteminfoUtilsCallback& callback,
1213 SysteminfoInstance& instance)
1215 if (nullptr == m_camera_flash_listener) {
1216 if (DEVICE_ERROR_NONE != device_add_callback(DEVICE_CALLBACK_FLASH_BRIGHTNESS,
1217 OnBrightnessChangedCb, static_cast<void*>(&instance))) {
1218 return PlatformResult(ErrorCode::UNKNOWN_ERR);
1220 m_camera_flash_listener = callback;
1222 return PlatformResult(ErrorCode::NO_ERROR);
1225 PlatformResult SystemInfoListeners::UnregisterCameraFlashListener()
1227 if (nullptr != m_camera_flash_listener) {
1228 PlatformResult ret = PlatformResult(ErrorCode::NO_ERROR);
1229 if (DEVICE_ERROR_NONE != device_remove_callback(DEVICE_CALLBACK_FLASH_BRIGHTNESS,
1230 OnBrightnessChangedCb)) {
1231 return PlatformResult(ErrorCode::UNKNOWN_ERR);
1233 LoggerD("Removed callback for camera_flash");
1234 m_camera_flash_listener = nullptr;
1236 return PlatformResult(ErrorCode::NO_ERROR);
1240 void SystemInfoListeners::SetCpuInfoLoad(double load)
1245 void SystemInfoListeners::SetAvailableCapacityInternal(unsigned long long capacity)
1247 m_available_capacity_internal = capacity;
1250 void SystemInfoListeners::SetAvailableCapacityMmc(unsigned long long capacity)
1252 m_available_capacity_mmc = capacity;
1255 void SystemInfoListeners::OnBatteryChangedCallback(keynode_t* /*node*/, void* event_ptr)
1257 if (nullptr != m_battery_listener) {
1258 SysteminfoInstance* instance = static_cast<SysteminfoInstance*>(event_ptr);
1259 m_battery_listener(*instance);
1263 void SystemInfoListeners::OnCpuChangedCallback(void* event_ptr)
1266 picojson::value result = picojson::value(picojson::object());
1267 PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdCpu, false, result);
1268 if (ret.IsSuccess()) {
1269 if (m_cpu_load == m_last_cpu_load) {
1272 if (nullptr != m_cpu_listener) {
1273 SysteminfoInstance* instance = static_cast<SysteminfoInstance*>(event_ptr);
1274 m_last_cpu_load = m_cpu_load;
1275 m_cpu_listener(*instance);
1280 void SystemInfoListeners::OnStorageChangedCallback(void* event_ptr)
1283 picojson::value result = picojson::value(picojson::object());
1284 PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdStorage, false, result);
1285 if (ret.IsSuccess()) {
1286 if (m_available_capacity_internal == m_last_available_capacity_internal) {
1290 if (nullptr != m_storage_listener) {
1291 SysteminfoInstance* instance = static_cast<SysteminfoInstance*>(event_ptr);
1292 m_last_available_capacity_internal = m_available_capacity_internal;
1293 m_storage_listener(*instance);
1298 void SystemInfoListeners::OnMmcChangedCallback(keynode_t* /*node*/, void* event_ptr)
1301 picojson::value result = picojson::value(picojson::object());
1302 PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdStorage, false, result);
1303 if (ret.IsSuccess()) {
1304 if (m_available_capacity_mmc == m_last_available_capacity_mmc) {
1307 if (nullptr != m_storage_listener) {
1308 SysteminfoInstance* instance = static_cast<SysteminfoInstance*>(event_ptr);
1309 m_last_available_capacity_mmc = m_available_capacity_mmc;
1310 m_storage_listener(*instance);
1316 void SystemInfoListeners::OnDisplayChangedCallback(keynode_t* /*node*/, void* event_ptr)
1318 if (nullptr != m_display_listener) {
1319 SysteminfoInstance* instance = static_cast<SysteminfoInstance*>(event_ptr);
1320 m_display_listener(*instance);
1324 void SystemInfoListeners::OnDeviceAutoRotationChangedCallback(keynode_t* /*node*/, void* event_ptr)
1326 if (nullptr != m_device_orientation_listener) {
1327 SysteminfoInstance* instance = static_cast<SysteminfoInstance*>(event_ptr);
1328 m_device_orientation_listener(*instance);
1332 void SystemInfoListeners::OnDeviceOrientationChangedCallback(sensor_t sensor, unsigned int event_type,
1333 sensor_data_t *data, void *user_data)
1335 if (nullptr != m_device_orientation_listener) {
1336 SysteminfoInstance* instance = static_cast<SysteminfoInstance*>(user_data);
1337 m_device_orientation_listener(*instance);
1341 void SystemInfoListeners::OnLocaleChangedCallback(system_settings_key_e /*key*/, void* event_ptr)
1343 if (nullptr != m_locale_listener) {
1344 SysteminfoInstance* instance = static_cast<SysteminfoInstance*>(event_ptr);
1345 m_locale_listener(*instance);
1349 void SystemInfoListeners::OnNetworkChangedCallback(connection_type_e /*type*/, void* event_ptr)
1351 if (nullptr != m_network_listener) {
1352 SysteminfoInstance* instance = static_cast<SysteminfoInstance*>(event_ptr);
1353 m_network_listener(*instance);
1357 void SystemInfoListeners::OnNetworkValueCallback(const char* /*ipv4_address*/,
1358 const char* /*ipv6_address*/, void* event_ptr)
1362 SysteminfoInstance* instance = static_cast<SysteminfoInstance*>(event_ptr);
1363 if (nullptr != m_wifi_network_listener) {
1364 m_wifi_network_listener(*instance);
1366 if (nullptr != m_ethernet_network_listener) {
1367 m_ethernet_network_listener(*instance);
1369 if (nullptr != m_cellular_network_listener) {
1370 m_cellular_network_listener(*instance);
1374 void SystemInfoListeners::OnCellularNetworkValueCallback(keynode_t */*node*/, void *event_ptr)
1376 if (nullptr != m_cellular_network_listener) {
1377 SysteminfoInstance* instance = static_cast<SysteminfoInstance*>(event_ptr);
1378 m_cellular_network_listener(*instance);
1382 void SystemInfoListeners::OnPeripheralChangedCallback(keynode_t* /*node*/, void* event_ptr)
1384 if (nullptr != m_peripheral_listener) {
1385 SysteminfoInstance* instance = static_cast<SysteminfoInstance*>(event_ptr);
1386 m_peripheral_listener(*instance);
1390 void SystemInfoListeners::OnMemoryChangedCallback(keynode_t* /*node*/, void* event_ptr)
1392 if (nullptr != m_memory_listener) {
1393 SysteminfoInstance* instance = static_cast<SysteminfoInstance*>(event_ptr);
1394 m_memory_listener(*instance);
1398 void SystemInfoListeners::OnBrightnessChangedCallback(device_callback_e type, void* value, void* user_data)
1400 if (nullptr != m_camera_flash_listener) {
1401 SysteminfoInstance* instance = static_cast<SysteminfoInstance*>(user_data);
1402 m_camera_flash_listener(*instance);
1406 void SystemInfoListeners::InitTapiHandles()
1410 if (nullptr == m_tapi_handles[0]){ //check if anything is in table
1411 char **cp_list = tel_get_cp_name_list();
1412 if (nullptr != cp_list) {
1413 while (cp_list[sim_count]) {
1414 m_tapi_handles[sim_count] = tel_init(cp_list[sim_count]);
1415 if (nullptr == m_tapi_handles[sim_count]) {
1416 LoggerE("Failed to connect with tapi, handle is null");
1420 LoggerD("%d modem: %s", sim_count, cp_list[sim_count]);
1423 LoggerE("Failed to get cp list");
1424 sim_count = kTapiMaxHandle;
1426 g_strfreev(cp_list);
1430 void SystemInfoListeners::InitCameraTypes() {
1431 bool supported = false;
1432 PlatformResult ret = SystemInfoDeviceCapability::GetValueBool(
1433 "tizen.org/feature/camera.back.flash", &supported);
1434 if (ret.IsSuccess()) {
1436 m_camera_types.push_back("BACK");
1439 ret = SystemInfoDeviceCapability::GetValueBool(
1440 "tizen.org/feature/camera.front.flash", &supported);
1441 if (ret.IsSuccess()) {
1443 m_camera_types.push_back("FRONT");
1448 TapiHandle* SystemInfoListeners::GetTapiHandle() {
1452 return m_tapi_handles[0];
1455 TapiHandle** SystemInfoListeners::GetTapiHandles()
1458 return m_tapi_handles;
1461 PlatformResult SystemInfoListeners::GetConnectionHandle(connection_h& handle)
1463 if (nullptr == m_connection_handle) {
1464 int error = connection_create(&m_connection_handle);
1465 if (CONNECTION_ERROR_NONE != error) {
1466 LoggerE("Failed to create connection: %d", error);
1467 return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot create connection");
1470 handle = m_connection_handle;
1471 return PlatformResult(ErrorCode::NO_ERROR);
1474 //////////////// Private ////////////////////
1476 PlatformResult SystemInfoListeners::RegisterVconfCallback(const char *in_key, vconf_callback_fn cb,
1477 SysteminfoInstance& instance)
1479 if (0 != vconf_notify_key_changed(in_key, cb, static_cast<void*>(&instance))) {
1480 LoggerE("Failed to register vconf callback: %s", in_key);
1481 return PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to register vconf callback");
1483 return PlatformResult(ErrorCode::NO_ERROR);
1486 PlatformResult SystemInfoListeners::UnregisterVconfCallback(const char *in_key, vconf_callback_fn cb)
1488 if (0 != vconf_ignore_key_changed(in_key, cb)) {
1489 LoggerE("Failed to unregister vconf callback: %s", in_key);
1490 return PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to unregister vconf callback");
1492 return PlatformResult(ErrorCode::NO_ERROR);
1495 PlatformResult SystemInfoListeners::RegisterIpChangeCallback(SysteminfoInstance& instance)
1497 LoggerD("Registering connection callback");
1498 connection_h handle;
1499 PlatformResult ret(ErrorCode::NO_ERROR);
1500 CHECK_LISTENER_ERROR(GetConnectionHandle(handle))
1501 int error = connection_set_ip_address_changed_cb(handle,
1502 OnNetworkValueChangedCb,
1503 static_cast<void*>(&instance));
1504 if (CONNECTION_ERROR_NONE != error) {
1505 LoggerE("Failed to register ip change callback: %d", error);
1506 return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot register ip change callback");
1508 return PlatformResult(ErrorCode::NO_ERROR);
1511 PlatformResult SystemInfoListeners::UnregisterIpChangeCallback()
1513 LoggerD("Unregistering connection callback");
1514 connection_h handle;
1515 PlatformResult ret(ErrorCode::NO_ERROR);
1516 CHECK_LISTENER_ERROR(GetConnectionHandle(handle))
1517 int error = connection_unset_ip_address_changed_cb(handle);
1518 if (CONNECTION_ERROR_NONE != error) {
1519 LoggerE("Failed to unregister ip change callback: %d", error);
1520 return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot unregister ip change callback");
1522 return PlatformResult(ErrorCode::NO_ERROR);
1525 bool SystemInfoListeners::IsIpChangeCallbackInvalid() {
1527 return (nullptr == m_wifi_network_listener &&
1528 nullptr == m_ethernet_network_listener &&
1529 nullptr == m_cellular_network_listener);
1532 /////////////////////////// system_info_listeners object ////////////////////////
1534 static SystemInfoListeners system_info_listeners;
1536 //global sim manager - needed for async gathering informations
1537 static SimDetailsManager sim_mgr;
1539 /////////////////// Callbacks ///////////////////////////////////////////////////
1541 void OnBatteryChangedCb(keynode_t* node, void* event_ptr)
1544 system_info_listeners.OnBatteryChangedCallback(node, event_ptr);
1547 gboolean OnCpuChangedCb(gpointer event_ptr)
1550 system_info_listeners.OnCpuChangedCallback(event_ptr);
1551 return G_SOURCE_CONTINUE;
1553 gboolean OnStorageChangedCb(gpointer event_ptr)
1556 system_info_listeners.OnStorageChangedCallback(event_ptr);
1557 return G_SOURCE_CONTINUE;
1559 void OnMmcChangedCb(keynode_t* node, void* event_ptr)
1562 system_info_listeners.OnMmcChangedCallback(node, event_ptr);
1565 void OnDisplayChangedCb(keynode_t* node, void* event_ptr)
1568 system_info_listeners.OnDisplayChangedCallback(node, event_ptr);
1571 void OnDeviceAutoRotationChangedCb(keynode_t* node, void* event_ptr)
1574 system_info_listeners.OnDeviceAutoRotationChangedCallback(node, event_ptr);
1577 void OnDeviceOrientationChangedCb(sensor_t sensor, unsigned int event_type,
1578 sensor_data_t *data, void *user_data)
1581 system_info_listeners.OnDeviceOrientationChangedCallback(sensor, event_type, data, user_data);
1584 void OnLocaleChangedCb(system_settings_key_e key, void* event_ptr)
1587 system_info_listeners.OnLocaleChangedCallback(key, event_ptr);
1590 void OnNetworkChangedCb(connection_type_e type, void* event_ptr)
1593 system_info_listeners.OnNetworkChangedCallback(type, event_ptr);
1596 void OnNetworkValueChangedCb(const char* ipv4_address,
1597 const char* ipv6_address, void* event_ptr)
1600 system_info_listeners.OnNetworkValueCallback(ipv4_address, ipv6_address, event_ptr);
1603 void OnCellularNetworkValueChangedCb(keynode_t *node, void *event_ptr)
1606 system_info_listeners.OnCellularNetworkValueCallback(node, event_ptr);
1609 void OnPeripheralChangedCb(keynode_t* node, void* event_ptr)
1612 system_info_listeners.OnPeripheralChangedCallback(node, event_ptr);
1615 void OnMemoryChangedCb(keynode_t* node, void* event_ptr)
1618 system_info_listeners.OnMemoryChangedCallback(node, event_ptr);
1621 void OnBrightnessChangedCb(device_callback_e type, void* value, void* user_data)
1624 if (type == DEVICE_CALLBACK_FLASH_BRIGHTNESS) {
1625 system_info_listeners.OnBrightnessChangedCallback(type, value, user_data);
1629 void OnWifiLevelChangedCb (wifi_rssi_level_e rssi_level, void *user_data)
1632 LoggerD("Level %d", rssi_level);
1633 system_info_listeners.SetWifiLevel(rssi_level);
1636 /////////////////////////// SysteminfoUtils ////////////////////////////////
1638 PlatformResult SystemInfoDeviceCapability::GetValueBool(const char *key, bool* value) {
1639 bool platform_result = false;
1640 int ret = system_info_get_platform_bool(key, &platform_result);
1641 if (SYSTEM_INFO_ERROR_NONE != ret) {
1642 ret = system_info_get_custom_bool(key, &platform_result);
1643 if (SYSTEM_INFO_ERROR_NONE != ret) {
1644 std::string log_msg = "Platform error while getting bool value: ";
1645 log_msg += std::string(key) + " " + std::to_string(ret);
1646 LoggerE("%s", log_msg.c_str());
1647 return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg);
1651 *value = platform_result;
1652 LoggerD("value[%s]: %s", key, value ? "true" : "false");
1653 return PlatformResult(ErrorCode::NO_ERROR);
1656 PlatformResult SystemInfoDeviceCapability::GetValueInt(const char *key, int* value) {
1657 int platform_result = 0;
1658 int ret = system_info_get_platform_int(key, &platform_result);
1659 if (SYSTEM_INFO_ERROR_NONE != ret) {
1660 ret = system_info_get_custom_int(key, &platform_result);
1661 if (SYSTEM_INFO_ERROR_NONE != ret) {
1662 std::string log_msg = "Platform error while getting int value: ";
1663 log_msg += std::string(key) + " " + std::to_string(ret);
1664 LoggerE("%s", log_msg.c_str());
1665 return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg);
1669 *value = platform_result;
1670 LoggerD("value[%s]: %d", key, value);
1671 return PlatformResult(ErrorCode::NO_ERROR);
1674 PlatformResult SystemInfoDeviceCapability::GetValueString(const char *key, std::string* str_value) {
1675 char* value = nullptr;
1677 int ret = system_info_get_platform_string(key, &value);
1678 if (SYSTEM_INFO_ERROR_NONE != ret) {
1679 ret = system_info_get_custom_string(key, &value);
1680 if (SYSTEM_INFO_ERROR_NONE != ret) {
1681 std::string log_msg = "Platform error while getting string value: ";
1682 log_msg += std::string(key) + " " + std::to_string(ret);
1683 LoggerE("%s", log_msg.c_str());
1684 return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg);
1688 if (value != nullptr) {
1694 LoggerD("value[%s]: %s", key, str_value->c_str());
1695 return PlatformResult(ErrorCode::NO_ERROR);
1698 static PlatformResult GetRuntimeInfoString(system_settings_key_e key, std::string& platform_string) {
1699 char* platform_c_string;
1700 int err = system_settings_get_value_string(key, &platform_c_string);
1701 if (SYSTEM_SETTINGS_ERROR_NONE == err) {
1702 if (nullptr != platform_c_string) {
1703 platform_string = platform_c_string;
1704 free(platform_c_string);
1705 return PlatformResult(ErrorCode::NO_ERROR);
1708 const std::string error_msg = "Error when retrieving system setting information: "
1709 + std::to_string(err);
1710 LoggerE("%s", error_msg.c_str());
1711 return PlatformResult(ErrorCode::UNKNOWN_ERR, error_msg);
1714 PlatformResult GetVconfInt(const char *key, int &value) {
1715 if (0 == vconf_get_int(key, &value)) {
1716 LoggerD("value[%s]: %d", key, value);
1717 return PlatformResult(ErrorCode::NO_ERROR);
1719 const std::string error_msg = "Could not get " + std::string(key);
1720 LoggerD("%s",error_msg.c_str());
1721 return PlatformResult(ErrorCode::UNKNOWN_ERR, error_msg);
1724 PlatformResult SysteminfoUtils::GetTotalMemory(long long& result)
1728 unsigned int value = 0;
1730 int ret = device_memory_get_total(&value);
1731 if (ret != DEVICE_ERROR_NONE) {
1732 std::string log_msg = "Failed to get total memory: " + std::to_string(ret);
1733 LoggerE("%s", log_msg.c_str());
1734 return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg);
1737 result = static_cast<long long>(value*MEMORY_TO_BYTE);
1738 return PlatformResult(ErrorCode::NO_ERROR);
1741 PlatformResult SysteminfoUtils::GetAvailableMemory(long long& result)
1745 unsigned int value = 0;
1747 int ret = device_memory_get_available(&value);
1748 if (ret != DEVICE_ERROR_NONE) {
1749 std::string log_msg = "Failed to get total memory: " + std::to_string(ret);
1750 LoggerE("%s", log_msg.c_str());
1751 return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg);
1754 result = static_cast<long long>(value*MEMORY_TO_BYTE);
1755 return PlatformResult(ErrorCode::NO_ERROR);
1758 PlatformResult SysteminfoUtils::GetCount(const std::string& property, unsigned long& count)
1762 if ("BATTERY" == property || "CPU" == property || "STORAGE" == property ||
1763 "DISPLAY" == property || "DEVICE_ORIENTATION" == property ||
1764 "BUILD" == property || "LOCALE" == property || "NETWORK" == property ||
1765 "WIFI_NETWORK" == property || "PERIPHERAL" == property ||
1766 "MEMORY" == property) {
1767 count = kDefaultPropertyCount;
1768 } else if ("CELLULAR_NETWORK" == property) {
1769 PlatformResult ret = CheckTelephonySupport();
1770 if (ret.IsError()) {
1773 count = sim_mgr.GetSimCount(system_info_listeners.GetTapiHandles());
1775 } else if ("SIM" == property) {
1776 PlatformResult ret = CheckTelephonySupport();
1777 if (ret.IsError()) {
1780 count = sim_mgr.GetSimCount(system_info_listeners.GetTapiHandles());
1782 } else if ("CAMERA_FLASH" == property) {
1783 count = system_info_listeners.GetCameraTypesCount();
1784 } else if ("ETHERNET_NETWORK" == property) {
1785 PlatformResult ret = CheckIfEthernetNetworkSupported();
1786 if (ret.IsError()) count = 0;
1787 else count = kDefaultPropertyCount;
1789 LoggerD("Property with given id is not supported");
1790 return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, "Property with given id is not supported");
1792 return PlatformResult(ErrorCode::NO_ERROR);
1795 PlatformResult SysteminfoUtils::ReportProperty(const std::string& property, int index,
1796 picojson::object& res_obj) {
1797 if ("BATTERY" == property){
1798 return ReportBattery(res_obj);
1799 } else if ("CPU" == property) {
1800 return ReportCpu(res_obj);
1801 } else if ("STORAGE" == property) {
1802 return ReportStorage(res_obj);
1803 } else if ("DISPLAY" == property) {
1804 return ReportDisplay(res_obj);
1805 } else if ("DEVICE_ORIENTATION" == property) {
1806 return ReportDeviceOrientation(res_obj);
1807 } else if ("BUILD" == property) {
1808 return ReportBuild(res_obj);
1809 } else if ("LOCALE" == property) {
1810 return ReportLocale(res_obj);
1811 } else if ("NETWORK" == property) {
1812 return ReportNetwork(res_obj);
1813 } else if ("WIFI_NETWORK" == property) {
1814 return ReportWifiNetwork(res_obj);
1815 } else if ("ETHERNET_NETWORK" == property) {
1816 return ReportEthernetNetwork(res_obj);
1817 } else if ("CELLULAR_NETWORK" == property) {
1818 return ReportCellularNetwork(res_obj, index);
1819 } else if ("SIM" == property) {
1820 return ReportSim(res_obj, index);
1821 } else if ("PERIPHERAL" == property) {
1822 return ReportPeripheral(res_obj);
1823 } else if ("MEMORY" == property) {
1824 return ReportMemory(res_obj);
1825 } else if ("CAMERA_FLASH" == property) {
1826 return ReportCameraFlash(res_obj, index);
1828 LoggerD("Property with given id is not supported");
1829 return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, "Property with given id is not supported");
1832 PlatformResult SysteminfoUtils::GetPropertyValue(const std::string& property, bool is_array_type,
1833 picojson::value& res)
1835 LoggerD("Entered getPropertyValue");
1837 if (!is_array_type) {
1838 picojson::object& res_obj = res.get<picojson::object>();
1839 return ReportProperty(property, 0, res_obj);
1841 picojson::object& array_result_obj = res.get<picojson::object>();
1842 picojson::array& array = array_result_obj.insert(
1843 std::make_pair("array", picojson::value(picojson::array()))).
1844 first->second.get<picojson::array>();
1846 unsigned long property_count = 0;
1847 PlatformResult ret = SysteminfoUtils::GetCount(property, property_count);
1852 LoggerD("property name: %s", property.c_str());
1853 LoggerD("available property count: %d", property_count);
1854 for (size_t i = 0; i < property_count; i++) {
1855 picojson::value result = picojson::value(picojson::object());
1856 picojson::object& result_obj = result.get<picojson::object>();
1858 ret = ReportProperty(property, i, result_obj);
1862 array.push_back(result);
1864 if (property_count == 0) {
1865 return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, "Property with given id is not supported");
1869 return PlatformResult(ErrorCode::NO_ERROR);
1872 PlatformResult SysteminfoUtils::ReportBattery(picojson::object& out) {
1874 int ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, &value);
1875 if (kVconfErrorNone != ret) {
1876 std::string log_msg = "Platform error while getting battery detail: ";
1877 LoggerE("%s%d", log_msg.c_str(), ret);
1878 return PlatformResult(ErrorCode::UNKNOWN_ERR, (log_msg + std::to_string(ret)));
1881 out.insert(std::make_pair("level", picojson::value(static_cast<double>(value)/kRemainingBatteryChargeMax)));
1883 ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &value);
1884 if (kVconfErrorNone != ret) {
1885 std::string log_msg = "Platform error while getting battery charging: ";
1886 LoggerE("%s%d",log_msg.c_str(), ret);
1887 return PlatformResult(ErrorCode::UNKNOWN_ERR, (log_msg + std::to_string(ret)));
1889 out.insert(std::make_pair("isCharging", picojson::value(0 != value)));
1890 return PlatformResult(ErrorCode::NO_ERROR);
1892 //TODO maybe make two functions later onGSourceFunc
1893 PlatformResult SysteminfoUtils::ReportCpu(picojson::object& out) {
1895 static CpuInfo cpu_info;
1897 fp = fopen("/proc/stat", "r");
1898 if (nullptr == fp) {
1899 std::string error_msg("Can not open /proc/stat for reading");
1900 LoggerE( "%s", error_msg.c_str() );
1901 return PlatformResult(ErrorCode::UNKNOWN_ERR, error_msg);
1905 long long system = 0;
1910 int read_ret = fscanf( fp, "%*s %lld %lld %lld %lld", &usr, &system, &nice, &idle);
1913 if (4 == read_ret) {
1914 long long total = usr + nice + system + idle - cpu_info.usr - cpu_info.nice -
1915 cpu_info.system - cpu_info.idle;
1916 long long diff_idle = idle - cpu_info.idle;
1917 if (( total > 0LL ) && ( diff_idle > 0LL )) {
1918 load = static_cast< double >( diff_idle ) * 100LL / total;
1920 cpu_info.system = system;
1921 cpu_info.nice = nice;
1922 cpu_info.idle = idle;
1923 cpu_info.load = load;
1925 LoggerW("Cannot calculate cpu load, previous value returned");
1926 load = cpu_info.load;
1929 std::string error_msg( "Could not read /proc/stat" );
1930 LoggerE( "%s", error_msg.c_str() );
1931 return PlatformResult(ErrorCode::UNKNOWN_ERR, error_msg);
1934 system_info_listeners.SetCpuInfoLoad(cpu_info.load);
1937 LoggerD("Cpu load : %f", load );
1938 out.insert(std::make_pair("load", picojson::value(load / 100.0)));
1939 return PlatformResult(ErrorCode::NO_ERROR);
1942 PlatformResult SysteminfoUtils::ReportDisplay(picojson::object& out) {
1943 int screenWidth = 0;
1944 int screenHeight = 0;
1945 int dotsPerInchWidth = 0;
1946 int dotsPerInchHeight = 0;
1947 double physicalWidth = 0;
1948 double physicalHeight = 0;
1949 double scaledBrightness;
1952 if (SYSTEM_INFO_ERROR_NONE != system_info_get_platform_int(
1953 "tizen.org/feature/screen.width", &screenWidth)) {
1954 LoggerE("Cannot get value of screen width");
1955 return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get value of screen width");
1957 if (SYSTEM_INFO_ERROR_NONE != system_info_get_platform_int(
1958 "tizen.org/feature/screen.height", &screenHeight)) {
1959 LoggerE("Cannot get value of screen height");
1960 return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get value of screen height");
1963 //FETCH DOTS PER INCH
1964 int dots_per_inch=0;
1965 if (SYSTEM_INFO_ERROR_NONE == system_info_get_platform_int(
1966 "tizen.org/feature/screen.dpi", &dots_per_inch)) {
1967 dotsPerInchWidth = dots_per_inch;
1968 dotsPerInchHeight = dots_per_inch;
1970 LoggerE("Cannot get 'tizen.org/feature/screen.dpi' value");
1971 return PlatformResult(ErrorCode::UNKNOWN_ERR,
1972 "Cannot get 'tizen.org/feature/screen.dpi' value");
1975 //FETCH PHYSICAL WIDTH
1976 if (dotsPerInchWidth != 0 && screenWidth != 0) {
1977 physicalWidth = (screenWidth / dotsPerInchWidth) * DISPLAY_INCH_TO_MILLIMETER;
1979 std::string log_msg = "Failed to get physical screen width value";
1980 LoggerE("%s, screenWidth : %d, dotsPerInchWidth: %d", log_msg.c_str(),
1981 screenWidth, dotsPerInchWidth);
1984 //FETCH PHYSICAL HEIGHT
1985 if (dotsPerInchHeight != 0 && screenHeight != 0) {
1986 physicalHeight = (screenHeight / dotsPerInchHeight) * DISPLAY_INCH_TO_MILLIMETER;
1988 std::string log_msg = "Failed to get physical screen height value";
1989 LoggerE("%s, screenHeight : %d, dotsPerInchHeight: %d", log_msg.c_str(),
1990 screenHeight, dotsPerInchHeight);
1995 if (kVconfErrorNone == vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, &brightness)) {
1996 scaledBrightness = static_cast<double>(brightness)/kDisplayBrightnessDivideValue;
1998 LoggerE("Cannot get brightness value of display");
1999 return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get brightness value of display");
2002 out.insert(std::make_pair("resolutionWidth", picojson::value(std::to_string(screenWidth))));
2003 out.insert(std::make_pair("resolutionHeight", picojson::value(std::to_string(screenHeight))));
2004 out.insert(std::make_pair("dotsPerInchWidth", picojson::value(std::to_string(dotsPerInchWidth))));
2005 out.insert(std::make_pair("dotsPerInchHeight", picojson::value(std::to_string(dotsPerInchHeight))));
2006 out.insert(std::make_pair("physicalWidth", picojson::value(std::to_string(physicalWidth))));
2007 out.insert(std::make_pair("physicalHeight", picojson::value(std::to_string(physicalHeight))));
2008 out.insert(std::make_pair("brightness", picojson::value(scaledBrightness)));
2009 return PlatformResult(ErrorCode::NO_ERROR);
2012 static PlatformResult FetchIsAutoRotation(bool* result)
2015 int is_auto_rotation = 0;
2017 if ( 0 == vconf_get_bool(
2018 VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &is_auto_rotation)) {
2019 if (is_auto_rotation) {
2024 return PlatformResult(ErrorCode::NO_ERROR);
2027 LoggerE("VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL check failed");
2028 return PlatformResult(ErrorCode::UNKNOWN_ERR,
2029 "VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL check failed");
2033 static PlatformResult FetchStatus(std::string* result)
2037 std::string status = kOrientationPortraitPrimary;
2040 bool ret = sensord_get_data(system_info_listeners.GetSensorHandle(),
2041 AUTO_ROTATION_BASE_DATA_SET, &data);
2043 LoggerD("size of the data value array:%d", data.value_count);
2044 if (data.value_count > 0 ) {
2045 rotation = data.values[0];
2046 LoggerD("rotation is: %d", rotation);
2048 LoggerE("Failed to get data : the size of array is 0. Default rotation would be returned.");
2051 LoggerE("Failed to get data(sensord_get_data). Default rotation would be returned.");
2056 case AUTO_ROTATION_DEGREE_UNKNOWN:
2057 case AUTO_ROTATION_DEGREE_0:
2058 LoggerD("AUTO_ROTATION_DEGREE_0");
2059 status = kOrientationPortraitPrimary;
2061 case AUTO_ROTATION_DEGREE_90:
2062 LoggerD("AUTO_ROTATION_DEGREE_90");
2063 status = kOrientationLandscapePrimary;
2065 case AUTO_ROTATION_DEGREE_180:
2066 LoggerD("AUTO_ROTATION_DEGREE_180");
2067 status = kOrientationPortraitSecondary;
2069 case AUTO_ROTATION_DEGREE_270:
2070 LoggerD("AUTO_ROTATION_DEGREE_270");
2071 status = kOrientationLandscapeSecondary;
2074 LoggerE("Received unexpected data: %u", rotation);
2075 return PlatformResult(ErrorCode::UNKNOWN_ERR, "Received unexpected data");
2078 return PlatformResult(ErrorCode::NO_ERROR);
2081 PlatformResult SysteminfoUtils::ReportDeviceOrientation(picojson::object& out) {
2082 bool is_auto_rotation = false;
2083 std::string status = "";
2085 PlatformResult ret = FetchIsAutoRotation(&is_auto_rotation);
2086 if (ret.IsError()) return ret;
2088 ret = FetchStatus(&status);
2089 if (ret.IsError()) return ret;
2091 out.insert(std::make_pair("isAutoRotation", picojson::value(is_auto_rotation)));
2092 out.insert(std::make_pair("status", picojson::value(status)));
2093 return PlatformResult(ErrorCode::NO_ERROR);
2096 PlatformResult SysteminfoUtils::ReportBuild(picojson::object& out) {
2097 std::string model = "";
2098 PlatformResult ret = SystemInfoDeviceCapability::GetValueString(
2099 "tizen.org/system/model_name", &model);
2100 if (ret.IsError()) {
2103 std::string manufacturer = "";
2104 ret = SystemInfoDeviceCapability::GetValueString(
2105 "tizen.org/system/manufacturer", &manufacturer);
2106 if (ret.IsError()) {
2109 std::string buildVersion = "";
2110 ret = SystemInfoDeviceCapability::GetValueString(
2111 "tizen.org/system/build.string", &buildVersion);
2112 if (ret.IsError()) {
2116 out.insert(std::make_pair("model", picojson::value(model)));
2117 out.insert(std::make_pair("manufacturer", picojson::value(manufacturer)));
2118 out.insert(std::make_pair("buildVersion", picojson::value(buildVersion)));
2119 return PlatformResult(ErrorCode::NO_ERROR);
2122 PlatformResult SysteminfoUtils::ReportLocale(picojson::object& out) {
2123 std::string str_language = "";
2124 PlatformResult ret = GetRuntimeInfoString(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, str_language);
2125 if (ret.IsError()) {
2129 std::string str_country = "";
2130 ret = GetRuntimeInfoString(SYSTEM_SETTINGS_KEY_LOCALE_COUNTRY, str_country);
2131 if (ret.IsError()) {
2135 out.insert(std::make_pair("language", picojson::value(str_language)));
2136 out.insert(std::make_pair("country", picojson::value(str_country)));
2137 return PlatformResult(ErrorCode::NO_ERROR);
2140 static PlatformResult GetNetworkTypeString(NetworkType type, std::string& type_string)
2144 type_string = kNetworkTypeNone;
2147 type_string = kNetworkType2G;
2150 type_string = kNetworkType2_5G;
2153 type_string = kNetworkType3G;
2156 type_string = kNetworkType4G;
2159 type_string = kNetworkTypeWifi;
2162 type_string = kNetworkTypeEthernet;
2165 type_string = kNetworkTypeUnknown;
2168 LoggerE("Incorrect type: %d", type);
2169 return PlatformResult(ErrorCode::TYPE_MISMATCH_ERR, "Incorrect type");
2171 return PlatformResult(ErrorCode::NO_ERROR);
2174 PlatformResult SysteminfoUtils::ReportNetwork(picojson::object& out) {
2175 connection_h connection_handle = nullptr;
2176 connection_type_e connection_type = CONNECTION_TYPE_DISCONNECTED;
2177 int networkType = 0;
2178 NetworkType type = kNone;
2180 //connection must be created in every call, in other case error occurs
2181 int error = connection_create(&connection_handle);
2182 if (CONNECTION_ERROR_NONE != error) {
2183 std::string log_msg = "Cannot create connection: " + std::to_string(error);
2184 LoggerE("%s", log_msg.c_str());
2185 return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg);
2187 std::unique_ptr<std::remove_pointer<connection_h>::type, int(*)(connection_h)>
2188 connection_handle_ptr(connection_handle, &connection_destroy);
2189 // automatically release the memory
2191 error = connection_get_type(connection_handle, &connection_type);
2192 if (CONNECTION_ERROR_NONE != error) {
2193 std::string log_msg = "Cannot get connection type: " + std::to_string(error);
2194 LoggerE("%s", log_msg.c_str());
2195 return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg);
2198 switch (connection_type) {
2199 case CONNECTION_TYPE_DISCONNECTED :
2202 case CONNECTION_TYPE_WIFI :
2205 case CONNECTION_TYPE_CELLULAR :
2206 if (vconf_get_int(VCONFKEY_TELEPHONY_SVCTYPE, &networkType) == 0) {
2207 if (networkType < VCONFKEY_TELEPHONY_SVCTYPE_2G) {
2209 } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_2G) {
2211 } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_2G
2212 || networkType == VCONFKEY_TELEPHONY_SVCTYPE_2_5G_EDGE) {
2214 } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_3G
2215 || networkType == VCONFKEY_TELEPHONY_SVCTYPE_HSDPA) {
2217 } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_LTE) {
2224 case CONNECTION_TYPE_ETHERNET :
2228 LoggerE("Incorrect type: %d", connection_type);
2229 return PlatformResult(ErrorCode::UNKNOWN_ERR, "Incorrect type");
2231 std::string type_str = "";
2232 PlatformResult ret = GetNetworkTypeString(type, type_str);
2236 out.insert(std::make_pair("networkType", picojson::value(type_str)));
2237 return PlatformResult(ErrorCode::NO_ERROR);
2240 static PlatformResult GetIps(wifi_ap_h wifi_ap_handle, std::string* ip_addr_str,
2241 std::string* ipv6_addr_str){
2242 //getting ipv4 address
2243 char* ip_addr = nullptr;
2244 int error = wifi_ap_get_ip_address(wifi_ap_handle,
2245 WIFI_ADDRESS_FAMILY_IPV4,
2247 if (WIFI_ERROR_NONE != error) {
2248 LoggerE("Failed to get ip address: %d", error);
2249 return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get ip address");
2251 *ip_addr_str = ip_addr;
2254 //getting ipv6 address
2256 error = wifi_ap_get_ip_address(wifi_ap_handle,
2257 WIFI_ADDRESS_FAMILY_IPV6,
2259 if (WIFI_ERROR_NONE != error) {
2260 LoggerE("Failed to get ipv6 address: %d", error);
2261 return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get ipv6 address");
2263 *ipv6_addr_str = ip_addr;
2265 return PlatformResult(ErrorCode::NO_ERROR);
2268 PlatformResult SysteminfoUtils::ReportWifiNetwork(picojson::object& out) {
2271 bool result_status = false;
2272 std::string result_ssid;
2273 std::string result_ip_address;
2274 std::string result_ipv6_address;
2275 std::string result_mac_address;
2276 double result_signal_strength = 0;
2278 // wifi_initialize() must be called in each thread
2279 int error = wifi_initialize();
2280 if (WIFI_ERROR_NONE != error) {
2281 std::string log_msg = "Initialize failed: " + parseWifiNetworkError(error);
2282 LoggerE("%s", log_msg.c_str());
2283 return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg);
2285 LoggerD("WIFI initializatino succeed");
2288 wifi_deinitialize();
2291 wifi_ap_h wifi_ap_handle = nullptr;
2292 error = wifi_get_connected_ap(&wifi_ap_handle);
2293 if (WIFI_ERROR_NONE != error) {
2294 LoggerD("Error while wifi_get_connnected_ap: %s", parseWifiNetworkError(error).c_str());
2295 // in case of no connection, ignore error and leave status as false
2296 if (WIFI_ERROR_NO_CONNECTION != error) {
2297 std::string log_msg = "Cannot get connected access point handle: " + parseWifiNetworkError(error);
2298 LoggerE("%s", log_msg.c_str());
2299 return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg);
2302 //if getting connected AP succeed, set status on true
2303 result_status = true;
2306 if (result_status) {
2307 std::unique_ptr<std::remove_pointer<wifi_ap_h>::type, int(*)(wifi_ap_h)>
2308 wifi_ap_handle_ptr(wifi_ap_handle, &wifi_ap_destroy);
2309 // automatically release the memory
2311 //gathering mac address
2312 char* mac = nullptr;
2313 error = wifi_get_mac_address(&mac);
2314 if (WIFI_ERROR_NONE == error && nullptr != mac) {
2315 SLoggerD("MAC address fetched: %s", mac);
2316 result_mac_address = mac;
2319 std::string log_msg = "Failed to get mac address: " + parseWifiNetworkError(error);
2320 LoggerE("%s", log_msg.c_str());
2321 return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg);
2324 //refreshing access point information
2325 error = wifi_ap_refresh(wifi_ap_handle);
2326 if (WIFI_ERROR_NONE != error) {
2327 std::string log_msg = "Failed to refresh access point information: " + parseWifiNetworkError(error);
2328 LoggerE("%s", log_msg.c_str());
2329 return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg);
2333 char* essid = nullptr;
2334 error = wifi_ap_get_essid(wifi_ap_handle, &essid);
2335 if (WIFI_ERROR_NONE == error) {
2336 result_ssid = essid;
2339 std::string log_msg = "Failed to get network ssid: " + parseWifiNetworkError(error);
2340 LoggerE("%s", log_msg.c_str());
2341 return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg);
2345 PlatformResult ret = GetIps(wifi_ap_handle, &result_ip_address, &result_ipv6_address);
2346 if (ret.IsError()) {
2350 //gathering strength
2351 wifi_rssi_level_e rssi_level = system_info_listeners.GetWifiLevel();
2352 // this mean that level was not initialized or wifi not connected
2353 if (WIFI_RSSI_LEVEL_0 == rssi_level) {
2354 // so try to gather rssi level with dedicated function
2356 error = wifi_ap_get_rssi(wifi_ap_handle, &rssi);
2357 if (WIFI_ERROR_NONE == error) {
2358 result_signal_strength = ((double) abs(rssi))/kWifiSignalStrengthDivideValue;
2360 std::string log_msg = "Failed to get signal strength: " + parseWifiNetworkError(error);
2361 LoggerE("%s", log_msg.c_str());
2362 return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg);
2365 result_signal_strength = ((double) rssi_level)/WIFI_RSSI_LEVEL_4;
2368 //building result object
2369 out.insert(std::make_pair("status", picojson::value(result_status ? kWifiStatusOn : kWifiStatusOff)));
2370 out.insert(std::make_pair("ssid", picojson::value(result_ssid)));
2371 out.insert(std::make_pair("ipAddress", picojson::value(result_ip_address)));
2372 out.insert(std::make_pair("ipv6Address", picojson::value(result_ipv6_address)));
2373 out.insert(std::make_pair("macAddress", picojson::value(result_mac_address)));
2374 out.insert(std::make_pair("signalStrength", picojson::value(std::to_string(result_signal_strength))));
2376 return PlatformResult(ErrorCode::NO_ERROR);
2379 PlatformResult SysteminfoUtils::ReportEthernetNetwork(picojson::object& out) {
2382 std::string result_cable;
2383 std::string result_status;
2384 std::string result_ip_address;
2385 std::string result_ipv6_address;
2386 std::string result_mac_address;
2388 connection_h connection_handle = nullptr;
2389 connection_ethernet_state_e connection_state = CONNECTION_ETHERNET_STATE_DEACTIVATED;
2390 connection_type_e connection_type = CONNECTION_TYPE_DISCONNECTED;
2391 connection_profile_h profile_handle = nullptr;
2393 // connection must be created in every call, in other case error occurs
2394 int error = connection_create(&connection_handle);
2395 if (CONNECTION_ERROR_NONE != error) {
2396 std::string log_msg = "Cannot create connection: " + std::to_string(error);
2397 LoggerE("%s", log_msg.c_str());
2398 return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg);
2400 std::unique_ptr<std::remove_pointer<connection_h>::type, int (*)(connection_h)> connection_handle_ptr(
2401 connection_handle, &connection_destroy); // automatically release the memory
2403 error = connection_get_ethernet_state(connection_handle, &connection_state);
2404 if (CONNECTION_ERROR_NONE != error) {
2405 if (CONNECTION_ERROR_NOT_SUPPORTED == error) {
2406 std::string log_msg = "Cannot get ethernet connection state: Not supported";
2407 LoggerE("%s", log_msg.c_str());
2408 return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, log_msg);
2410 std::string log_msg = "Cannot get ethernet connection state: " + std::to_string(error);
2411 LoggerE("%s", log_msg.c_str());
2412 return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg);
2415 switch (connection_state) {
2416 case CONNECTION_ETHERNET_STATE_DEACTIVATED:
2417 result_status = "DEACTIVATED";
2420 case CONNECTION_ETHERNET_STATE_DISCONNECTED:
2421 result_status = "DISCONNECTED";
2424 case CONNECTION_ETHERNET_STATE_CONNECTED:
2425 result_status = "CONNECTED";
2429 result_status = "UNKNOWN";
2433 connection_ethernet_cable_state_e cable_state = CONNECTION_ETHERNET_CABLE_DETACHED;
2434 error = connection_get_ethernet_cable_state(connection_handle, &cable_state);
2435 if (CONNECTION_ERROR_NONE != error) {
2436 std::string log_msg = "Cannot get ethernet cable state: " + std::to_string(error);
2437 LoggerE("%s", log_msg.c_str());
2438 return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg);
2441 switch (cable_state) {
2442 case CONNECTION_ETHERNET_CABLE_DETACHED:
2443 result_cable = "DETACHED";
2446 case CONNECTION_ETHERNET_CABLE_ATTACHED:
2447 result_cable = "ATTACHED";
2451 result_cable = "UNKNOWN";
2455 char* mac = nullptr;
2456 error = connection_get_mac_address(connection_handle, CONNECTION_TYPE_ETHERNET, &mac);
2457 if (CONNECTION_ERROR_NONE == error && nullptr != mac) {
2458 SLoggerD("MAC address fetched: %s", mac);
2459 result_mac_address = mac;
2462 std::string log_msg = "Failed to get mac address: " + std::to_string(error);
2463 LoggerE("%s", log_msg.c_str());
2464 return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg);
2467 error = connection_get_type(connection_handle, &connection_type);
2468 if (CONNECTION_ERROR_NONE != error) {
2469 std::string log_msg = "Cannot get connection type: " + std::to_string(error);
2470 LoggerE("%s", log_msg.c_str());
2471 return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg);
2474 if (CONNECTION_TYPE_ETHERNET == connection_type) {
2476 error = connection_get_current_profile(connection_handle, &profile_handle);
2477 if (CONNECTION_ERROR_NONE != error) {
2478 std::string log_msg = "Cannot get connection profile: " + std::to_string(error);
2479 LoggerE("%s", log_msg.c_str());
2480 return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg);
2482 std::unique_ptr<std::remove_pointer<connection_profile_h>::type,
2483 int (*)(connection_profile_h)> profile_handle_ptr(
2484 profile_handle, &connection_profile_destroy); // automatically release the memory
2487 PlatformResult ret = GetIps(profile_handle, &result_ip_address, &result_ipv6_address);
2488 if (ret.IsError()) {
2492 LoggerD("Connection type = %d. ETHERNET is disabled", connection_type);
2495 out.insert(std::make_pair("cable", picojson::value(result_cable)));
2496 out.insert(std::make_pair("status", picojson::value(result_status)));
2497 out.insert(std::make_pair("ipAddress", picojson::value(result_ip_address)));
2498 out.insert(std::make_pair("ipv6Address", picojson::value(result_ipv6_address)));
2499 out.insert(std::make_pair("macAddress", picojson::value(result_mac_address)));
2501 return PlatformResult(ErrorCode::NO_ERROR);
2504 static PlatformResult FetchBasicSimProperties(TapiHandle *tapi_handle,
2505 unsigned short *result_mcc,
2506 unsigned short *result_mnc,
2507 unsigned short *result_cell_id,
2508 unsigned short *result_lac,
2509 bool *result_is_roaming,
2510 bool *result_is_flight_mode)
2513 int result_value = 0;
2514 int tapi_res = TAPI_API_SUCCESS;
2515 tapi_res = tel_get_property_int(tapi_handle, TAPI_PROP_NETWORK_PLMN, &result_value);
2516 if (TAPI_API_SUCCESS != tapi_res) {
2517 std::string error_msg = "Cannot get mcc value, error: " + std::to_string(tapi_res);
2518 LoggerE("%s", error_msg.c_str());
2519 return PlatformResult(ErrorCode::UNKNOWN_ERR, error_msg);
2521 *result_mcc = static_cast<unsigned short>(result_value) / kMccDivider;
2522 *result_mnc = static_cast<unsigned short>(result_value) % kMccDivider;
2524 tapi_res = tel_get_property_int(tapi_handle, TAPI_PROP_NETWORK_CELLID, &result_value);
2525 if (TAPI_API_SUCCESS != tapi_res) {
2526 std::string error_msg = "Cannot get cell_id value, error: " + std::to_string(tapi_res);
2527 LoggerE("%s", error_msg.c_str());
2528 return PlatformResult(ErrorCode::UNKNOWN_ERR, error_msg);
2530 *result_cell_id = static_cast<unsigned short>(result_value);
2532 tapi_res = tel_get_property_int(tapi_handle, TAPI_PROP_NETWORK_LAC, &result_value);
2533 if (TAPI_API_SUCCESS != tapi_res) {
2534 std::string error_msg = "Cannot get lac value, error: " + std::to_string(tapi_res);
2535 LoggerE("%s", error_msg.c_str());
2536 return PlatformResult(ErrorCode::UNKNOWN_ERR, error_msg);
2538 *result_lac = static_cast<unsigned short>(result_value);
2540 tapi_res = tel_get_property_int(tapi_handle, TAPI_PROP_NETWORK_ROAMING_STATUS, &result_value);
2541 if (TAPI_API_SUCCESS != tapi_res) {
2542 std::string error_msg = "Cannot get is_roaming value, error: " + std::to_string(tapi_res);
2543 LoggerE("%s", error_msg.c_str());
2544 return PlatformResult(ErrorCode::UNKNOWN_ERR, error_msg);
2546 *result_is_roaming = (0 != result_value) ? true : false;
2548 if (0 != vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &result_value)) {
2549 LoggerE("Cannot get is_flight_mode value");
2550 return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get is_flight_mode value");
2552 *result_is_flight_mode = (0 != result_value) ? true : false;
2553 return PlatformResult(ErrorCode::NO_ERROR);
2556 static PlatformResult FetchConnection(TapiHandle *tapi_handle, std::string* result_status,
2557 std::string* result_apn, std::string* result_ip_address,
2558 std::string* result_ipv6_address, std::string* result_imei)
2561 connection_type_e connection_type = CONNECTION_TYPE_DISCONNECTED;
2562 connection_profile_h profile_handle = nullptr;
2563 connection_h connection_handle = nullptr;
2565 //connection must be created in every call, in other case error occurs
2566 int error = connection_create(&connection_handle);
2567 if (CONNECTION_ERROR_NONE != error) {
2568 std::string log_msg = "Cannot create connection: " + std::to_string(error);
2569 LoggerE("%s", log_msg.c_str());
2570 return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg);
2572 std::unique_ptr<std::remove_pointer<connection_h>::type, int(*)(connection_h)>
2573 connection_handle_ptr(connection_handle, &connection_destroy);
2574 // automatically release the memory
2576 error = connection_get_type(connection_handle, &connection_type);
2577 if (CONNECTION_ERROR_NONE != error) {
2578 LoggerE("Failed to get connection type: %d", error);
2579 return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get connection type");
2582 char* apn = nullptr;
2583 if (CONNECTION_TYPE_CELLULAR == connection_type) {
2584 *result_status = kConnectionOn;
2586 error = connection_get_current_profile(connection_handle,
2589 <std::remove_pointer<connection_profile_h>::type, int(*)(connection_profile_h)>
2590 profile_handle_ptr(profile_handle, &connection_profile_destroy);
2591 // automatically release the memory
2592 if (CONNECTION_ERROR_NONE != error) {
2593 LoggerE("Failed to get profile: %d", error);
2594 return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get profile");
2597 error = connection_profile_get_cellular_apn(profile_handle, &apn);
2598 if (CONNECTION_ERROR_NONE != error) {
2599 LoggerE("Failed to get apn name: %d", error);
2600 return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get apn name");
2605 PlatformResult ret = GetIps(profile_handle, result_ip_address, result_ipv6_address);
2606 if (ret.IsError()) {
2610 *result_status = kConnectionOff;
2612 //According to previous implementation in case of error
2613 //don't throw exception here
2614 error = connection_get_default_cellular_service_profile(
2616 CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET,
2619 <std::remove_pointer<connection_profile_h>::type, int(*)(connection_profile_h)>
2620 profile_handle_ptr(profile_handle, &connection_profile_destroy);
2621 // automatically release the memory
2622 if (CONNECTION_ERROR_NONE == error) {
2623 error = connection_profile_get_cellular_apn(profile_handle, &apn);
2624 if (CONNECTION_ERROR_NONE == error) {
2628 LoggerE("Failed to get default apn name: %d. Failing silently",
2632 LoggerE("Failed to get default profile: %d. Failing silently",
2637 char* imei = nullptr;
2638 imei = tel_get_misc_me_imei_sync(tapi_handle);
2639 if (nullptr != imei) {
2640 *result_imei = imei;
2643 LoggerE("Failed to get imei, nullptr pointer. Setting empty value.");
2646 return PlatformResult(ErrorCode::NO_ERROR);
2649 PlatformResult SysteminfoUtils::ReportCellularNetwork(picojson::object& out, unsigned long count) {
2650 PlatformResult ret = CheckTelephonySupport();
2651 if (ret.IsError()) {
2654 std::string result_status;
2655 std::string result_apn;
2656 std::string result_ip_address;
2657 std::string result_ipv6_address;
2658 unsigned short result_mcc;
2659 unsigned short result_mnc;
2660 unsigned short result_cell_id;
2661 unsigned short result_lac;
2662 bool result_is_roaming;
2663 bool result_is_flight_mode;
2664 std::string result_imei;
2666 //gathering vconf-based values
2667 ret = FetchBasicSimProperties(system_info_listeners.GetTapiHandles()[count], &result_mcc,
2668 &result_mnc, &result_cell_id, &result_lac,
2669 &result_is_roaming, &result_is_flight_mode);
2670 if (ret.IsError()) {
2673 //gathering connection informations
2674 ret = FetchConnection(system_info_listeners.GetTapiHandles()[count],
2675 &result_status, &result_apn, &result_ip_address, &result_ipv6_address, &result_imei);
2676 if (ret.IsError()) {
2680 out.insert(std::make_pair("status", picojson::value(result_status)));
2681 out.insert(std::make_pair("apn", picojson::value(result_apn)));
2682 out.insert(std::make_pair("ipAddress", picojson::value(result_ip_address)));
2683 out.insert(std::make_pair("ipv6Address", picojson::value(result_ipv6_address)));
2684 out.insert(std::make_pair("mcc", picojson::value(std::to_string(result_mcc))));
2685 out.insert(std::make_pair("mnc", picojson::value(std::to_string(result_mnc))));
2686 out.insert(std::make_pair("cellId", picojson::value(std::to_string(result_cell_id))));
2687 out.insert(std::make_pair("lac", picojson::value(std::to_string(result_lac))));
2688 out.insert(std::make_pair("isRoaming", picojson::value(result_is_roaming)));
2689 out.insert(std::make_pair("isFligthMode", picojson::value(result_is_flight_mode)));
2690 out.insert(std::make_pair("imei", picojson::value(result_imei)));
2691 return PlatformResult(ErrorCode::NO_ERROR);
2694 void SimCphsValueCallback(TapiHandle */*handle*/, int result, void *data, void */*user_data*/)
2697 TelSimAccessResult_t access_rt = static_cast<TelSimAccessResult_t>(result);
2698 TelSimCphsNetName_t *cphs_info = static_cast<TelSimCphsNetName_t*>(data);
2700 std::string result_operator;
2701 if (TAPI_SIM_ACCESS_SUCCESS == access_rt) {
2702 std::stringstream s;
2703 s << cphs_info->full_name;
2704 if (s.str().empty()) {
2705 s << cphs_info->short_name;
2707 result_operator = s.str();
2709 LoggerW("Failed to retrieve cphs_info: %d", access_rt);
2711 sim_mgr.set_operator_name(result_operator);
2712 sim_mgr.TryReturn();
2715 void SimMsisdnValueCallback(TapiHandle */*handle*/, int result, void *data, void */*user_data*/)
2718 TelSimAccessResult_t access_rt = static_cast<TelSimAccessResult_t>(result);
2719 TelSimMsisdnList_t *msisdn_info = static_cast<TelSimMsisdnList_t*>(data);
2721 std::string result_msisdn;
2722 if (TAPI_SIM_ACCESS_SUCCESS == access_rt) {
2723 if (msisdn_info->count > 0) {
2724 if (strlen(msisdn_info->list[0].num) > 0) {
2725 result_msisdn = msisdn_info->list[0].num;
2727 LoggerW("MSISDN number empty");
2730 LoggerW("msisdn_info list empty");
2733 LoggerW("Failed to retrieve msisdn_: %d", access_rt);
2736 sim_mgr.set_msisdn(result_msisdn);
2737 sim_mgr.TryReturn();
2740 void SimSpnValueCallback(TapiHandle */*handle*/, int result, void *data, void */*user_data*/)
2743 TelSimAccessResult_t access_rt = static_cast<TelSimAccessResult_t>(result);
2744 TelSimSpn_t *spn_info = static_cast<TelSimSpn_t*>(data);
2746 std::string result_spn;
2747 if (TAPI_SIM_ACCESS_SUCCESS == access_rt) {
2748 result_spn = (char *)spn_info->spn;
2750 LoggerW("Failed to retrieve spn_: %d", access_rt);
2753 sim_mgr.set_spn(result_spn);
2754 sim_mgr.TryReturn();
2757 PlatformResult SysteminfoUtils::ReportSim(picojson::object& out, unsigned long count) {
2758 PlatformResult ret = CheckTelephonySupport();
2759 if (ret.IsError()) {
2762 return sim_mgr.GatherSimInformation(
2763 system_info_listeners.GetTapiHandles()[count], &out);
2766 PlatformResult SysteminfoUtils::ReportPeripheral(picojson::object& out) {
2768 /* int wireless_display_status = 0;
2769 PlatformResult ret = GetVconfInt(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, wireless_display_status);
2770 if (ret.IsSuccess()) {
2771 if (VCONFKEY_MIRACAST_WFD_SOURCE_ON == wireless_display_status) {
2772 out.insert(std::make_pair(kVideoOutputString, picojson::value(true)));
2773 return PlatformResult(ErrorCode::NO_ERROR);
2776 int hdmi_status = 0;
2777 PlatformResult ret = GetVconfInt(VCONFKEY_SYSMAN_HDMI, hdmi_status);
2778 if (ret.IsSuccess()) {
2779 if (VCONFKEY_SYSMAN_HDMI_CONNECTED == hdmi_status) {
2780 out.insert(std::make_pair(kVideoOutputString, picojson::value(true)));
2781 return PlatformResult(ErrorCode::NO_ERROR);
2785 out.insert(std::make_pair(kVideoOutputString, picojson::value(false)));
2786 return PlatformResult(ErrorCode::NO_ERROR);
2789 PlatformResult SysteminfoUtils::ReportMemory(picojson::object& out) {
2790 std::string state = MEMORY_STATE_NORMAL;
2792 PlatformResult ret = GetVconfInt(VCONFKEY_SYSMAN_LOW_MEMORY, status);
2793 if (ret.IsSuccess()) {
2795 case VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING:
2796 case VCONFKEY_SYSMAN_LOW_MEMORY_HARD_WARNING:
2797 state = MEMORY_STATE_WARNING;
2799 case VCONFKEY_SYSMAN_LOW_MEMORY_NORMAL:
2801 state = MEMORY_STATE_NORMAL;
2805 out.insert(std::make_pair("state", picojson::value(state)));
2806 return PlatformResult(ErrorCode::NO_ERROR);
2809 static void CreateStorageInfo(const std::string& type, struct statfs& fs, picojson::object* out) {
2810 out->insert(std::make_pair("type", picojson::value(type)));
2811 out->insert(std::make_pair("capacity", picojson::value(std::to_string(
2812 static_cast<unsigned long long>(fs.f_bsize) *
2813 static_cast<unsigned long long>(fs.f_blocks)))));
2814 out->insert(std::make_pair("availableCapacity", picojson::value(std::to_string(
2815 static_cast<unsigned long long>(fs.f_bsize) *
2816 static_cast<unsigned long long>(fs.f_bavail)))));
2817 bool isRemovable = (type == kTypeInternal) ? false : true;
2818 out->insert(std::make_pair("isRemovable", picojson::value(isRemovable)));
2821 PlatformResult SysteminfoUtils::ReportStorage(picojson::object& out) {
2822 int sdcardState = 0;
2825 picojson::value result = picojson::value(picojson::array());
2827 picojson::array& array = result.get<picojson::array>();
2828 array.push_back(picojson::value(picojson::object()));
2829 picojson::object& internal_obj = array.back().get<picojson::object>();
2831 if (statfs(kStorageInternalPath, &fs) < 0) {
2832 LoggerE("There are no storage units detected");
2833 return PlatformResult(ErrorCode::UNKNOWN_ERR, "There are no storage units detected");
2835 CreateStorageInfo(kTypeInternal, fs, &internal_obj);
2836 system_info_listeners.SetAvailableCapacityInternal(fs.f_bavail);
2838 if (0 == vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &sdcardState)) {
2839 if (VCONFKEY_SYSMAN_MMC_MOUNTED == sdcardState){
2840 if (statfs(kStorageSdcardPath, &fs) < 0) {
2841 LoggerE("MMC mounted, but not accessible");
2842 return PlatformResult(ErrorCode::UNKNOWN_ERR, "MMC mounted, but not accessible");
2844 array.push_back(picojson::value(picojson::object()));
2845 picojson::object& external_obj = array.back().get<picojson::object>();
2846 CreateStorageInfo(kTypeMmc, fs, &external_obj);
2847 system_info_listeners.SetAvailableCapacityMmc(fs.f_bavail);
2851 out.insert(std::make_pair("storages", picojson::value(result)));
2852 return PlatformResult(ErrorCode::NO_ERROR);
2854 PlatformResult SysteminfoUtils::ReportCameraFlash(picojson::object& out,
2855 unsigned long index) {
2857 if (index < system_info_listeners.GetCameraTypesCount()) {
2858 std::string camera = system_info_listeners.GetCameraTypes(index);
2859 out.insert(std::make_pair("camera", picojson::value(camera)));
2861 return PlatformResult(
2862 ErrorCode::NOT_SUPPORTED_ERR,
2863 "Camera is not supported on this device");
2866 return PlatformResult(ErrorCode::NO_ERROR);
2869 PlatformResult SysteminfoUtils::RegisterBatteryListener(const SysteminfoUtilsCallback& callback,
2870 SysteminfoInstance& instance)
2872 return system_info_listeners.RegisterBatteryListener(callback, instance);
2875 PlatformResult SysteminfoUtils::UnregisterBatteryListener()
2877 return system_info_listeners.UnregisterBatteryListener();
2881 PlatformResult SysteminfoUtils::RegisterCpuListener(const SysteminfoUtilsCallback& callback,
2882 SysteminfoInstance& instance)
2884 return system_info_listeners.RegisterCpuListener(callback, instance);
2887 PlatformResult SysteminfoUtils::UnregisterCpuListener()
2889 return system_info_listeners.UnregisterCpuListener();
2893 PlatformResult SysteminfoUtils::RegisterStorageListener(const SysteminfoUtilsCallback& callback,
2894 SysteminfoInstance& instance)
2896 return system_info_listeners.RegisterStorageListener(callback, instance);
2899 PlatformResult SysteminfoUtils::UnregisterStorageListener()
2901 return system_info_listeners.UnregisterStorageListener();
2904 PlatformResult SysteminfoUtils::RegisterDisplayListener(const SysteminfoUtilsCallback& callback,
2905 SysteminfoInstance& instance)
2907 return system_info_listeners.RegisterDisplayListener(callback, instance);
2910 PlatformResult SysteminfoUtils::UnregisterDisplayListener()
2912 return system_info_listeners.UnregisterDisplayListener();
2915 PlatformResult SysteminfoUtils::RegisterDeviceOrientationListener(const SysteminfoUtilsCallback& callback,
2916 SysteminfoInstance& instance)
2918 return system_info_listeners.RegisterDeviceOrientationListener(callback, instance);
2921 PlatformResult SysteminfoUtils::UnregisterDeviceOrientationListener()
2923 return system_info_listeners.UnregisterDeviceOrientationListener();
2926 PlatformResult SysteminfoUtils::RegisterLocaleListener(const SysteminfoUtilsCallback& callback,
2927 SysteminfoInstance& instance)
2929 return system_info_listeners.RegisterLocaleListener(callback, instance);
2932 PlatformResult SysteminfoUtils::UnregisterLocaleListener()
2934 return system_info_listeners.UnregisterLocaleListener();
2937 PlatformResult SysteminfoUtils::RegisterNetworkListener(const SysteminfoUtilsCallback& callback,
2938 SysteminfoInstance& instance)
2940 return system_info_listeners.RegisterNetworkListener(callback, instance);
2943 PlatformResult SysteminfoUtils::UnregisterNetworkListener()
2945 return system_info_listeners.UnregisterNetworkListener();
2948 PlatformResult SysteminfoUtils::RegisterWifiNetworkListener(const SysteminfoUtilsCallback& callback,
2949 SysteminfoInstance& instance)
2951 return system_info_listeners.RegisterWifiNetworkListener(callback, instance);
2954 PlatformResult SysteminfoUtils::UnregisterWifiNetworkListener()
2956 return system_info_listeners.UnregisterWifiNetworkListener();
2959 PlatformResult SysteminfoUtils::RegisterEthernetNetworkListener(const SysteminfoUtilsCallback& callback,
2960 SysteminfoInstance& instance)
2963 return system_info_listeners.RegisterEthernetNetworkListener(callback, instance);
2966 PlatformResult SysteminfoUtils::UnregisterEthernetNetworkListener()
2969 return system_info_listeners.UnregisterEthernetNetworkListener();
2972 PlatformResult SysteminfoUtils::RegisterCellularNetworkListener(const SysteminfoUtilsCallback& callback,
2973 SysteminfoInstance& instance)
2975 return system_info_listeners.RegisterCellularNetworkListener(callback, instance);
2978 PlatformResult SysteminfoUtils::UnregisterCellularNetworkListener()
2980 return system_info_listeners.UnregisterCellularNetworkListener();
2983 PlatformResult SysteminfoUtils::RegisterPeripheralListener(const SysteminfoUtilsCallback& callback,
2984 SysteminfoInstance& instance)
2986 return system_info_listeners.RegisterPeripheralListener(callback, instance);
2989 PlatformResult SysteminfoUtils::UnregisterPeripheralListener()
2991 return system_info_listeners.UnregisterPeripheralListener();
2994 PlatformResult SysteminfoUtils::RegisterMemoryListener(const SysteminfoUtilsCallback& callback,
2995 SysteminfoInstance& instance)
2997 return system_info_listeners.RegisterMemoryListener(callback, instance);
3000 PlatformResult SysteminfoUtils::UnregisterMemoryListener()
3002 return system_info_listeners.UnregisterMemoryListener();
3005 PlatformResult SysteminfoUtils::RegisterCameraFlashListener(const SysteminfoUtilsCallback& callback,
3006 SysteminfoInstance& instance)
3008 return system_info_listeners.RegisterCameraFlashListener(callback, instance);
3011 PlatformResult SysteminfoUtils::UnregisterCameraFlashListener()
3013 return system_info_listeners.UnregisterCameraFlashListener();
3017 static PlatformResult CheckStringCapability(const std::string& key, std::string* value, bool* fetched)
3019 LoggerD("Entered CheckStringCapability");
3021 if (kTizenFeatureOpenglesTextureFormat == key) {
3022 PlatformResult ret = SystemInfoDeviceCapability::GetOpenglesTextureFormat(value);
3023 if (ret.IsError()) {
3026 } else if (kTizenFeatureCoreApiVersion == key) {
3028 } else if (key == kTizenFeaturePlatfromCoreCpuArch) {
3029 PlatformResult ret = SystemInfoDeviceCapability::GetPlatfomCoreCpuArch(value);
3030 if (ret.IsError()) {
3033 } else if (kTizenFeaturePlatfromCoreFpuArch == key) {
3034 PlatformResult ret = SystemInfoDeviceCapability::GetPlatfomCoreFpuArch(value);
3035 if (ret.IsError()) {
3038 } else if (kTizenFeatureProfile == key) {
3039 PlatformResult ret = SystemInfoDeviceCapability::GetProfile(value);
3040 if (ret.IsError()) {
3043 } else if (kTizenFeaturePlatformNativeApiVersion == key) {
3044 PlatformResult ret = SystemInfoDeviceCapability::GetNativeAPIVersion(value);
3045 if (ret.IsError()) {
3048 } else if (kTizenFeaturePlatformVersionName == key) {
3049 PlatformResult ret = SystemInfoDeviceCapability::GetPlatformVersionName(value);
3050 if (ret.IsError()) {
3054 PlatformResult ret = SystemInfoDeviceCapability::GetValueString(key.substr(strlen("http://")).c_str(), value);
3056 return PlatformResult(ErrorCode::NO_ERROR);
3060 return PlatformResult(ErrorCode::NO_ERROR);
3063 static PlatformResult CheckBoolCapability(const std::string& key, bool* bool_value, bool* fetched)
3065 LoggerD("Entered CheckBoolCapability");
3067 if(kTizenFeatureBluetoothAlwaysOn == key) {
3068 *bool_value = SystemInfoDeviceCapability::IsBluetoothAlwaysOn();
3070 } else if (kTizenFeatureScreen == key) {
3071 *bool_value = SystemInfoDeviceCapability::IsScreen();
3073 } else if (kTizenFeaturePlatformNativeOspCompatible == key) {
3074 PlatformResult ret = SystemInfoDeviceCapability::IsNativeOspCompatible(bool_value);
3075 if (ret.IsError()) {
3080 PlatformResult ret = SystemInfoDeviceCapability::GetValueBool(
3081 key.substr(strlen("http://")).c_str(), bool_value);
3082 if (ret.IsSuccess()) {
3086 return PlatformResult(ErrorCode::NO_ERROR);
3089 static PlatformResult CheckIntCapability(const std::string& key, std::string* value,
3092 LoggerD("Entered CheckIntCapability");
3094 if (key == kTizenFeatureCpuFrequency) {
3095 PlatformResult ret = SystemInfoDeviceCapability::GetPlatformCoreCpuFrequency(&result);
3096 if (ret.IsError()) {
3101 PlatformResult ret = SystemInfoDeviceCapability::GetValueInt(
3102 key.substr(strlen("http://")).c_str(), &result);
3103 if (ret.IsError()) {
3105 return PlatformResult(ErrorCode::NO_ERROR);
3108 *value = std::to_string(result);
3110 return PlatformResult(ErrorCode::NO_ERROR);
3113 /////////////////////// SystemInfoDeviceCapability //////////////////////////////////////
3114 PlatformResult SystemInfoDeviceCapability::GetCapability(const std::string& key,
3115 picojson::value& result)
3118 picojson::object& result_obj = result.get<picojson::object>();
3120 std::string value = "";
3121 std::string type = "";
3122 bool bool_value = false ;
3123 bool is_fetched = false;
3125 PlatformResult ret = CheckBoolCapability(key, &bool_value, &is_fetched);
3126 if (ret.IsError()) {
3132 ret = CheckIntCapability(key, &value, &is_fetched);
3133 if (ret.IsError()) {
3139 ret = CheckStringCapability(key, &value, &is_fetched);
3140 if (ret.IsError()) {
3149 if (type == "bool") {
3150 result_obj.insert(std::make_pair("value", picojson::value(bool_value)));
3151 } else if (type == "string" || type == "int") {
3152 result_obj.insert(std::make_pair("value", picojson::value(value)));
3154 LoggerD("Value for given key was not found");
3155 return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, "Value for given key was not found");
3157 result_obj.insert(std::make_pair("type", picojson::value(type)));
3159 return PlatformResult(ErrorCode::NO_ERROR);
3162 PlatformResult SystemInfoDeviceCapability::IsInputKeyboardLayout(bool* result) {
3163 std::string input_keyboard_layout = "";
3164 PlatformResult ret = GetValueString("tizen.org/feature/input.keyboard.layout",
3165 &input_keyboard_layout);
3166 if (ret.IsError()) {
3169 bool input_keyboard = false;
3170 ret = GetValueBool("tizen.org/feature/input.keyboard", &input_keyboard);
3171 if (ret.IsError()) {
3175 // according to SystemInfo-DeviceCapabilities-dependency-table
3176 // inputKeyboard inputKeyboardLayout
3182 *result = input_keyboard ? !(input_keyboard_layout.empty()) : false;
3183 return PlatformResult(ErrorCode::NO_ERROR);
3186 PlatformResult SystemInfoDeviceCapability::GetOpenglesTextureFormat(std::string* result) {
3187 bool bool_result = false;
3188 PlatformResult ret = GetValueBool("tizen.org/feature/opengles", &bool_result);
3190 // this exception is converted to "Undefined" value in JS layer
3191 std::string log_msg = "OpenGL-ES is not supported";
3192 LoggerE("%s", log_msg.c_str());
3193 return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, log_msg);
3195 std::string texture_format = "";
3197 ret = GetValueBool("tizen.org/feature/opengles.texture_format.utc", &bool_result);
3198 if (ret.IsError()) {
3202 texture_format += kOpenglesTextureUtc;
3205 ret = GetValueBool("tizen.org/feature/opengles.texture_format.ptc", &bool_result);
3206 if (ret.IsError()) {
3210 if (!texture_format.empty()) {
3211 texture_format += kOpenglesTextureDelimiter;
3213 texture_format += kOpenglesTexturePtc;
3216 ret = GetValueBool("tizen.org/feature/opengles.texture_format.etc", &bool_result);
3217 if (ret.IsError()) {
3221 if (!texture_format.empty()) {
3222 texture_format += kOpenglesTextureDelimiter;
3224 texture_format += kOpenglesTextureEtc;
3227 ret = GetValueBool("tizen.org/feature/opengles.texture_format.3dc", &bool_result);
3228 if (ret.IsError()) {
3232 if (!texture_format.empty()) {
3233 texture_format += kOpenglesTextureDelimiter;
3235 texture_format += kOpenglesTexture3dc;
3238 ret = GetValueBool("tizen.org/feature/opengles.texture_format.atc", &bool_result);
3239 if (ret.IsError()) {
3243 if (!texture_format.empty()) {
3244 texture_format += kOpenglesTextureDelimiter;
3246 texture_format += kOpenglesTextureAtc;
3249 ret = GetValueBool("tizen.org/feature/opengles.texture_format.pvrtc", &bool_result);
3250 if (ret.IsError()) {
3254 if (!texture_format.empty()) {
3255 texture_format += kOpenglesTextureDelimiter;
3257 texture_format += kOpenglesTexturePvrtc;
3260 if (texture_format.empty()) {
3261 // this exception is converted to "Undefined" value in JS layer
3262 std::string log_msg = "Platform error while getting OpenGL-ES texture format";
3263 LoggerE("%s", log_msg.c_str());
3264 return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg);
3266 *result = texture_format;
3267 return PlatformResult(ErrorCode::NO_ERROR);
3270 PlatformResult SystemInfoDeviceCapability::GetPlatfomCoreCpuArch(std::string* return_value) {
3272 bool bool_result = false;
3273 PlatformResult ret = GetValueBool("tizen.org/feature/platform.core.cpu.arch.armv6", &bool_result);
3274 if (ret.IsError()) {
3278 result = kPlatformCoreArmv6;
3281 ret = GetValueBool("tizen.org/feature/platform.core.cpu.arch.armv7", &bool_result);
3282 if (ret.IsError()) {
3286 if (!result.empty()) {
3287 result += kPlatformCoreDelimiter;
3289 result += kPlatformCoreArmv7;
3292 ret = GetValueBool("tizen.org/feature/platform.core.cpu.arch.x86", &bool_result);
3293 if (ret.IsError()) {
3297 if (!result.empty()) {
3298 result += kPlatformCoreDelimiter;
3300 result += kPlatformCoreX86;
3303 if (result.empty()) {
3304 LoggerE("Platform error while retrieving platformCoreCpuArch: result is empty");
3305 return PlatformResult(ErrorCode::UNKNOWN_ERR, "platformCoreCpuArch result is empty");
3307 *return_value = result;
3308 return PlatformResult(ErrorCode::NO_ERROR);
3311 PlatformResult SystemInfoDeviceCapability::GetPlatfomCoreFpuArch(std::string* return_value) {
3313 bool bool_result = false;
3314 PlatformResult ret = GetValueBool("tizen.org/feature/platform.core.fpu.arch.sse2", &bool_result);
3315 if (ret.IsError()) {
3319 result = kPlatformCoreSse2;
3322 ret = GetValueBool("tizen.org/feature/platform.core.fpu.arch.sse3", &bool_result);
3323 if (ret.IsError()) {
3327 if (!result.empty()) {
3328 result += kPlatformCoreDelimiter;
3330 result += kPlatformCoreSse3;
3333 ret = GetValueBool("tizen.org/feature/platform.core.fpu.arch.ssse3", &bool_result);
3334 if (ret.IsError()) {
3338 if (!result.empty()) {
3339 result += kPlatformCoreDelimiter;
3341 result += kPlatformCoreSsse3;
3344 ret = GetValueBool("tizen.org/feature/platform.core.fpu.arch.vfpv2", &bool_result);
3345 if (ret.IsError()) {
3349 if (!result.empty()) {
3350 result += kPlatformCoreDelimiter;
3352 result += kPlatformCoreVfpv2;
3355 ret = GetValueBool("tizen.org/feature/platform.core.fpu.arch.vfpv3", &bool_result);
3356 if (ret.IsError()) {
3360 if (!result.empty()) {
3361 result += kPlatformCoreDelimiter;
3363 result += kPlatformCoreVfpv3;
3365 if (result.empty()) {
3366 LoggerE("Platform error while retrieving platformCoreFpuArch: result is empty");
3367 return PlatformResult(ErrorCode::UNKNOWN_ERR, "platformCoreFpuArch result is empty");
3369 *return_value = result;
3370 return PlatformResult(ErrorCode::NO_ERROR);
3373 PlatformResult SystemInfoDeviceCapability::GetProfile(std::string* return_value) {
3374 std::string profile = "";
3375 PlatformResult ret = GetValueString("tizen.org/feature/profile", &profile);
3376 if (ret.IsError()) {
3380 *return_value = kProfileFull;
3381 if ( kPlatformFull == profile ) {
3382 *return_value = kProfileFull;
3383 } else if ( kPlatformMobile == profile ) {
3384 *return_value = kProfileMobile;
3385 } else if ( kPlatformWearable == profile ) {
3386 *return_value = kProfileWearable;
3388 return PlatformResult(ErrorCode::NO_ERROR);
3391 bool SystemInfoDeviceCapability::IsBluetoothAlwaysOn() {
3392 #ifdef PROFILE_MOBILE_FULL
3394 #elif PROFILE_MOBILE
3396 #elif PROFILE_WEARABLE
3405 bool SystemInfoDeviceCapability::IsScreen()
3411 PlatformResult SystemInfoDeviceCapability::GetPlatformCoreCpuFrequency(int* return_value)
3416 std::string file_name;
3418 #ifdef TIZEN_IS_EMULATOR
3419 file_name = "/proc/cpuinfo";
3421 file_name = "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq";
3424 std::ifstream cpuinfo_freq(file_name);
3425 if (!cpuinfo_freq.is_open()) {
3426 LoggerE("Failed to get cpu frequency");
3427 return PlatformResult(ErrorCode::UNKNOWN_ERR, "Unable to open file");
3430 #ifdef TIZEN_IS_EMULATOR
3431 //get frequency value from cpuinfo file
3432 //example entry for frequency looks like below
3433 //cpu MHz : 3392.046
3436 getline(cpuinfo_freq, freq);
3437 found = freq.find("cpu MHz");
3438 } while (std::string::npos == found && !cpuinfo_freq.eof());
3440 found = freq.find(":");
3441 if (std::string::npos != found) {
3442 *return_value = std::stoi(freq.substr(found + 2));
3445 getline(cpuinfo_freq, freq);
3446 *return_value = std::stoi(freq) / 1000; // unit: MHz
3449 cpuinfo_freq.close();
3450 LoggerD("cpu frequency : %d", *return_value);
3452 return PlatformResult(ErrorCode::NO_ERROR);
3455 PlatformResult SystemInfoDeviceCapability::IsNativeOspCompatible(bool* result)
3458 #ifdef PROFILE_WEARABLE
3460 return PlatformResult(ErrorCode::NO_ERROR);
3462 return GetValueBool(kTizenFeaturePlatformNativeOspCompatible, result);
3466 PlatformResult SystemInfoDeviceCapability::GetNativeAPIVersion(std::string* return_value)
3469 #ifdef PROFILE_WEARABLE
3471 return PlatformResult(ErrorCode::NO_ERROR);
3473 return GetValueString(kTizenFeaturePlatformNativeApiVersion, return_value);
3477 PlatformResult SystemInfoDeviceCapability::GetPlatformVersionName(std::string* result)
3481 //Because of lack of 'http://tizen.org/feature/platform.version.name'
3482 //key on platform we use 'http://tizen.org/system/platform.name'.
3483 return GetValueString("tizen.org/system/platform.name", result);
3486 } // namespace systeminfo
3487 } // namespace webapi