2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
21 #include <Commons/Exception.h>
22 #include <CommonsJavaScript/Converter.h>
23 #include <CommonsJavaScript/PrivateObject.h>
24 #include <TimeTracer.h>
25 #include "Systeminfo.h"
28 using namespace WrtDeviceApis::CommonsJavaScript;
29 using namespace WrtDeviceApis::Commons;
30 #define SIM_VALUE_MAX 4
33 namespace Systeminfo {
37 void BatteryValueCallback(keynode_t *node, void *event_ptr)
40 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_BATTERY);
44 void PeripheralValueCallback(keynode_t *node, void *event_ptr)
47 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_PERIPHERAL);
51 void CellularNetworkValueCallback(keynode_t *node, void *event_ptr)
54 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_CELLULARNETWORK);
58 void DisplayValueCallback(keynode_t *node, void* event_ptr)
61 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_DISPLAY);
65 void OrientationValueVconfCallback(keynode_t *node, void *event_ptr)
69 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_DEVICE_ORIENTATION);
73 void NetworkTypeValueCallback(connection_type_e type, void* event_ptr)
76 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_NETWORK);
80 void NetworkValueCallback(const char* ipv4_address, const char* ipv6_address, void* event_ptr)
83 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_NETWORK_ALL);
87 static Eina_Bool StorageValueCallback(void* event_ptr)
90 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_STORAGE);
92 return ECORE_CALLBACK_RENEW;
95 static Eina_Bool CpuValueCallback(void* event_ptr)
98 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_CPU);
100 return ECORE_CALLBACK_RENEW;
103 void OrientationValueCallback(unsigned int event_type, sensor_event_data_t *event , void *event_ptr)
106 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_DEVICE_ORIENTATION);
110 void localeChangedCallback(runtime_info_key_e key, void* event_ptr)
113 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_LOCALE);
117 void SimCphsValueCallback(TapiHandle *handle, int result, void *data, void *user_data)
119 TelSimAccessResult_t access_rt = (TelSimAccessResult_t)result;
120 TelSimCphsNetName_t *cphsInfo = (TelSimCphsNetName_t *)data;
122 LoggerD("access_rt : " << access_rt);
124 if (user_data != NULL){
125 SysteminfoAsyncPendingEvent *pendingEvent = (SysteminfoAsyncPendingEvent *)user_data;
126 Systeminfo *systeminfo = (Systeminfo *)pendingEvent->getThisObject();
127 EventGetSysteminfoPtr event = pendingEvent->getEvent();
129 if (access_rt == TAPI_SIM_ACCESS_SUCCESS) {
130 if (cphsInfo->full_name) {
131 systeminfo->setSimValue(SIM_CPHS_VALUE, (char *)cphsInfo->full_name, event);
132 } else if (cphsInfo->short_name) {
133 systeminfo->setSimValue(SIM_CPHS_VALUE, (char *)cphsInfo->short_name, event);
135 systeminfo->setSimValue(SIM_CPHS_VALUE, NULL, event);
138 systeminfo->setSimValue(SIM_CPHS_VALUE, NULL, event);
147 void SimMsisdnValueCallback(TapiHandle *handle, int result, void *data, void *user_data)
149 TelSimAccessResult_t access_rt = (TelSimAccessResult_t)result;
150 TelSimMsisdnList_t *msisdnInfo = (TelSimMsisdnList_t *)data;
152 LoggerD("access_rt : " << access_rt);
154 if (user_data != NULL){
155 SysteminfoAsyncPendingEvent *pendingEvent = (SysteminfoAsyncPendingEvent *)user_data;
156 Systeminfo *systeminfo = (Systeminfo *)pendingEvent->getThisObject();
157 EventGetSysteminfoPtr event = pendingEvent->getEvent();
159 if (access_rt == TAPI_SIM_ACCESS_SUCCESS) {
160 systeminfo->setSimValue(SIM_MSISDN_VALUE, (char *)msisdnInfo->list[0].num, event);
162 systeminfo->setSimValue(SIM_MSISDN_VALUE, NULL, event);
171 void SimIccidValueCallback(TapiHandle *handle, int result, void *data, void *user_data)
173 TelSimAccessResult_t access_rt = (TelSimAccessResult_t)result;
174 TelSimIccIdInfo_t *iccidInfo = (TelSimIccIdInfo_t *)data;
176 LoggerD("access_rt : " << access_rt);
178 if (user_data != NULL){
179 SysteminfoAsyncPendingEvent *pendingEvent = (SysteminfoAsyncPendingEvent *)user_data;
180 Systeminfo *systeminfo = (Systeminfo *)pendingEvent->getThisObject();
181 EventGetSysteminfoPtr event = pendingEvent->getEvent();
183 if (access_rt == TAPI_SIM_ACCESS_SUCCESS) {
184 systeminfo->setSimValue(SIM_ICCID_VALUE, (char *)iccidInfo->icc_num, event);
186 systeminfo->setSimValue(SIM_ICCID_VALUE, NULL, event);
195 void SimSpnValueCallback(TapiHandle *handle, int result, void *data, void *user_data)
197 TelSimAccessResult_t access_rt = (TelSimAccessResult_t)result;
198 TelSimSpn_t *spnInfo = (TelSimSpn_t *)data;
200 LoggerD("access_rt : " << access_rt);
202 if (user_data != NULL){
203 SysteminfoAsyncPendingEvent *pendingEvent = (SysteminfoAsyncPendingEvent *)user_data;
204 Systeminfo *systeminfo = (Systeminfo *)pendingEvent->getThisObject();
205 EventGetSysteminfoPtr event = pendingEvent->getEvent();
207 if (access_rt == TAPI_SIM_ACCESS_SUCCESS) {
208 systeminfo->setSimValue(SIM_SPN_VALUE, (char *)spnInfo->spn, event);
210 systeminfo->setSimValue(SIM_ICCID_VALUE, NULL, event);
221 #define STORAGE_INTERNAL_PATH "/opt/usr/media"
222 #define STORAGE_SDCARD_PATH "/opt/storage/sdcard"
223 #define STORAGE_USBHOST_PATH "/opt/storage/usb"
224 #define DISPLAY_BRIGHTNESS_DIVIDE_VALUE 100
225 #define WIFI_SIGNAL_STRENGTH_DIVIDE_VALUE 100
226 #define CPU_POWER_DEVICE_VALUE 100
228 #define RADIAN_VALUE (57.2957)
231 STORAGE_TYPE_UNKNOWN = 0,
232 STORAGE_TYPE_INTERNAL = 1,
233 STORAGE_TYPE_MMC = 2,
234 STORAGE_TYPE_USBHOST = 3
237 Systeminfo::OptionalProperty Systeminfo::m_Property;
239 Systeminfo::Systeminfo() : m_networkRegist(REGIST_NOT),
240 m_storageTimer(NULL),
243 m_connectionHandle(NULL)
245 EventMgrPtr eventMgrPtr(new EventMgr());
246 m_EventMgrPtr = eventMgrPtr;
247 if (m_Property.IsNull()) {
248 mapProperties properties;
249 properties["BATTERY"] = BasePropertyPtr(new Battery());
250 m_Property = properties;
251 (*m_Property)["CPU"] = BasePropertyPtr(new Cpu());
252 (*m_Property)["STORAGE"] = BasePropertyPtr(new Storage());
253 (*m_Property)["DISPLAY"] = BasePropertyPtr(new Display());
254 (*m_Property)["NETWORK"] = BasePropertyPtr(new Network());
255 (*m_Property)["WIFI_NETWORK"] = BasePropertyPtr(new WifiNetwork());
256 (*m_Property)["CELLULAR_NETWORK"] = BasePropertyPtr(new CellularNetwork());
257 (*m_Property)["SIM"] = BasePropertyPtr(new SIM());
258 (*m_Property)["DEVICE_ORIENTATION"] = BasePropertyPtr(new DeviceOrientation());
259 (*m_Property)["BUILD"] = BasePropertyPtr(new Build());
260 (*m_Property)["LOCALE"] = BasePropertyPtr(new Locale());
261 (*m_Property)["PERIPHERAL"] = BasePropertyPtr(new Peripheral());
264 int ret = connection_create(&m_connectionHandle);
266 if (CONNECTION_ERROR_NONE == ret) {
267 LoggerD("Network Client registration success");
269 LoggerD("Network Client registration success");
270 m_connectionHandle = NULL;
273 m_sensorHandle = sf_connect(ACCELEROMETER_SENSOR);
274 if (m_sensorHandle < 0) {
275 LoggerD ("sensor attach fail");
277 LoggerD("m_sensorHandle : " << m_sensorHandle);
278 int state = sf_start(m_sensorHandle, 0);
284 m_tapiHandle = tel_init(0);
285 if (m_tapiHandle == NULL) {
286 LoggerE ("tel init fail");
290 Systeminfo::~Systeminfo()
293 if (m_storageTimer) {
294 ecore_timer_freeze(m_storageTimer);
295 ecore_timer_del(m_storageTimer);
296 m_storageTimer = NULL;
299 ecore_timer_freeze(m_cpuTimer);
300 ecore_timer_del(m_cpuTimer);
303 m_EventMgrPtr->clearAllEvent();
305 if(m_connectionHandle != NULL) {
306 LoggerD("Network Client deregistration success");
307 connection_destroy(m_connectionHandle);
309 LoggerD("Network Client deregistration failed");
312 if (m_tapiHandle != NULL) {
313 tel_deinit(m_tapiHandle);
316 state = sf_stop(m_sensorHandle);
317 LoggerD("handle 1 state = " << state);
319 state = sf_disconnect(m_sensorHandle);
320 LoggerD("handle state =" << state);
323 DeviceCapabilitiesPropertiesPtr Systeminfo::getCapabilities()
326 DeviceCapabilitiesPropertiesPtr deviceCapabilities(new DeviceCapabilitiesProperties());
327 return deviceCapabilities;
330 void Systeminfo::get(const EventGetSysteminfoPtr& event)
332 event->setTapiHandle((void*)m_tapiHandle);
333 EventRequestReceiver<EventGetSysteminfo>::PostRequest(event);
336 void Systeminfo::watch(const EventWatchSysteminfoPtr& event)
338 if(event->getWatchType() == WATCH_TYPE_UNKNOWN) {
339 LoggerD("watch method is not supported");
344 event->setSysteminfoPtr(this);
345 event->setTapiHandle((void*)m_tapiHandle);
346 m_EventMgrPtr->addEvent(event, event->getWatchType());
348 EventRequestReceiver<EventWatchSysteminfo>::PostRequest(event);
351 void Systeminfo::clearWatch(const long id)
354 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
356 int watchType = m_EventMgrPtr->getWatchType(id);
358 case WATCH_TYPE_BATTERY:
359 if ((m_EventMgrPtr->getEventBatteryList()).size() == 1) {
360 vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, BatteryValueCallback);
361 vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, BatteryValueCallback);
364 case WATCH_TYPE_DISPLAY:
365 if ((m_EventMgrPtr->getEventDisplayList()).size() == 1) {
366 vconf_ignore_key_changed(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, DisplayValueCallback);
369 case WATCH_TYPE_NETWORK:
370 if ((m_EventMgrPtr->getEventNetworkList()).size() == 1) {
371 connection_unset_type_changed_cb(m_connectionHandle);
374 case WATCH_TYPE_WIFINETWORK:
375 if ((m_EventMgrPtr->getEventWifiNetworkList()).size() == 1) {
376 if (m_networkRegist == REGIST_WIFI) {
377 connection_unset_ip_address_changed_cb(m_connectionHandle);
378 m_networkRegist = REGIST_NOT;
379 } else if (m_networkRegist== REGIST_ALL) {
380 m_networkRegist = REGIST_CELLULAR;
384 case WATCH_TYPE_CELLULARNETWORK:
385 if ((m_EventMgrPtr->getEventCellularNetworkList()).size() == 1) {
386 vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, CellularNetworkValueCallback);
387 vconf_ignore_key_changed(VCONFKEY_TELEPHONY_CELLID, CellularNetworkValueCallback);
388 vconf_ignore_key_changed(VCONFKEY_TELEPHONY_LAC, CellularNetworkValueCallback);
389 vconf_ignore_key_changed(VCONFKEY_TELEPHONY_SVC_ROAM, CellularNetworkValueCallback);
390 if (m_networkRegist == REGIST_CELLULAR) {
391 connection_unset_ip_address_changed_cb(m_connectionHandle);
392 m_networkRegist = REGIST_NOT;
393 } else if (m_networkRegist== REGIST_ALL) {
394 m_networkRegist = REGIST_WIFI;
398 case WATCH_TYPE_STORAGE:
399 if ((m_EventMgrPtr->getEventStorageList()).size() == 1) {
400 if (m_storageTimer) {
401 ecore_timer_freeze(m_storageTimer);
402 ecore_timer_del(m_storageTimer);
403 m_storageTimer = NULL;
408 if ((m_EventMgrPtr->getEventCpuList()).size() == 1) {
410 ecore_timer_freeze(m_cpuTimer);
411 ecore_timer_del(m_cpuTimer);
416 case WATCH_TYPE_DEVICE_ORIENTATION:
417 if ((m_EventMgrPtr->getEventDeviceOrientationList()).size() == 1) {
418 vconf_ignore_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, OrientationValueVconfCallback);
419 int state = sf_unregister_event(m_sensorHandle, ACCELEROMETER_EVENT_ROTATION_CHECK);
421 LoggerD("sf_unregister_event fail to gather data\n");
425 case WATCH_TYPE_LOCALE:
426 if ((m_EventMgrPtr->getEventLocaleList()).size() == 1) {
427 if (runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_LANGUAGE) != RUNTIME_INFO_ERROR_NONE) {
428 LoggerE("regist failed");
429 Throw(WrtDeviceApis::Commons::Exception);
431 if (runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_REGION) != RUNTIME_INFO_ERROR_NONE) {
432 LoggerE("regist failed");
433 Throw(WrtDeviceApis::Commons::Exception);
437 case WATCH_TYPE_PERIPHERAL:
438 if ((m_EventMgrPtr->getEventPeripheralList()).size() == 1) {
439 vconf_ignore_key_changed(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, PeripheralValueCallback);
440 vconf_ignore_key_changed(VCONFKEY_SYSMAN_HDMI, PeripheralValueCallback);
443 case WATCH_TYPE_UNKNOWN:
444 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
447 m_EventMgrPtr->removeEvent(id, watchType);
451 BasePropertyPtr Systeminfo::getBasePropertyPtr(JSContextRef context, JSValueRef property)
453 Converter converter(context);
454 std::string l_property = converter.toString(property);
455 mapProperties::iterator it = (*m_Property).find(l_property);
456 if (it == (*m_Property).end()) {
457 LoggerE("not existing property");
458 Throw(WrtDeviceApis::Commons::ConversionException);
459 return BasePropertyPtr(NULL);
465 void Systeminfo::getWatchValue(const int watchType)
467 LoggerD(" watch type : " << watchType);
469 if (watchType == WATCH_TYPE_BATTERY) {
470 EventBatteryList eventList = m_EventMgrPtr->getEventBatteryList();
471 for (EventBatteryList::iterator it = eventList.begin(); it != eventList.end(); it++) {
472 (*it)->getWatchValue();
474 } else if (watchType == WATCH_TYPE_DISPLAY) {
475 EventDisplayList eventList = m_EventMgrPtr->getEventDisplayList();
476 for (EventDisplayList::iterator it = eventList.begin(); it != eventList.end(); it++) {
477 (*it)->getWatchValue();
479 } else if (watchType == WATCH_TYPE_NETWORK) {
480 EventNetworkList eventList = m_EventMgrPtr->getEventNetworkList();
481 for (EventNetworkList::iterator it = eventList.begin(); it != eventList.end(); it++) {
482 (*it)->getWatchValue();
484 } else if (watchType == WATCH_TYPE_NETWORK_ALL) {
485 EventWifiNetworkList eventListWifi = m_EventMgrPtr->getEventWifiNetworkList();
486 EventWifiNetworkList eventListCellular = m_EventMgrPtr->getEventCellularNetworkList();
487 if (eventListWifi.size() > 0) {
488 for (EventWifiNetworkList::iterator it = eventListWifi.begin(); it != eventListWifi.end(); it++) {
489 (*it)->getWatchValue();
492 if (eventListCellular.size() > 0) {
493 for (EventCellularNetworkList::iterator it = eventListCellular.begin(); it != eventListCellular.end(); it++) {
494 (*it)->getWatchValue();
497 } else if (watchType == WATCH_TYPE_CPU) {
498 EventCpuList eventList = m_EventMgrPtr->getEventCpuList();
499 for (EventCpuList::iterator it = eventList.begin(); it != eventList.end(); it++) {
500 (*it)->getWatchValue();
502 } else if (watchType == WATCH_TYPE_STORAGE) {
503 EventStorageList eventList = m_EventMgrPtr->getEventStorageList();
504 for (EventStorageList::iterator it = eventList.begin(); it != eventList.end(); it++) {
507 if(vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &sdcardState) == 0) {
508 if(sdcardState == VCONFKEY_SYSMAN_MMC_MOUNTED) {
512 LoggerD("storage cnt : " << storageCnt);
513 (*it)->getWatchValue(storageCnt);
515 }else if (watchType == WATCH_TYPE_DEVICE_ORIENTATION) {
516 EventDeviceOrientationList eventList = m_EventMgrPtr->getEventDeviceOrientationList();
517 for (EventDeviceOrientationList::iterator it = eventList.begin(); it != eventList.end(); it++) {
518 (*it)->getWatchValue();
520 } else if (watchType == WATCH_TYPE_LOCALE) {
521 EventLocaleList eventList = m_EventMgrPtr->getEventLocaleList();
522 for (EventLocaleList::iterator it = eventList.begin(); it != eventList.end(); it++) {
523 (*it)->getWatchValue();
525 } else if (watchType == WATCH_TYPE_PERIPHERAL) {
526 EventPeripheralList eventList = m_EventMgrPtr->getEventPeripheralList();
527 for (EventPeripheralList::iterator it = eventList.begin(); it != eventList.end(); it++) {
528 (*it)->getWatchValue();
530 } else if (watchType == WATCH_TYPE_CELLULARNETWORK) {
531 EventWifiNetworkList eventListCellular = m_EventMgrPtr->getEventCellularNetworkList();
532 if (eventListCellular.size() > 0) {
533 for (EventCellularNetworkList::iterator it = eventListCellular.begin(); it != eventListCellular.end(); it++) {
534 (*it)->getWatchValue();
540 connection_h Systeminfo::getConnectionHandle()
542 return m_connectionHandle;
545 JSValueRef Systeminfo::getCpuValue(JSContextRef context)
548 Converter converter(context);
550 CpuPropertiesPtr cpuPtr(new CpuProperties());
552 long long usr = 0, nice = 0, system = 0, idle = 0, cpuUsage = 0, diffIdle = 0, total = 0;
554 fp = fopen("/proc/stat", "r");
556 return JSValueMakeNull(context);
559 if (fscanf(fp, "%*s %lld %lld %lld %lld", &usr, &system, &nice, &idle) > 0) {
560 total = usr + nice + system + idle - m_cpuInfo.usr - m_cpuInfo.nice - m_cpuInfo.system - m_cpuInfo.idle;
561 diffIdle = idle-m_cpuInfo.idle;
562 if ((total > 0LL) && (diffIdle > 0LL)) {
563 cpuUsage = diffIdle * 100LL / total;
564 cpuPtr->load = (double)cpuUsage / 100.0;
566 m_cpuInfo.system = system;
567 m_cpuInfo.nice = nice;
568 m_cpuInfo.idle = idle;
569 LoggerD("cpu load : " << cpuPtr->load);
574 return JSCpuInfo::createJSObject(context, cpuPtr);
577 void Systeminfo::setSimValue(const int simAttribute, char* value, const EventGetSysteminfoPtr &event)
581 ret = event->addSimValueCnt();
583 ret = event->setSimValue(simAttribute, value);
586 if (ret == SIM_VALUE_MAX) {
587 event->makeSimObject();
588 EventRequestReceiver<EventGetSysteminfo>::ManualAnswer(event);
592 void Systeminfo::OnRequestReceived(const EventGetSysteminfoPtr& event)
596 if (strcmp(event->getProperty(), (const char*)"SIM") == 0) {
598 TelSimCardStatus_t simCardState;
599 TelSimImsiInfo_t imsi;
600 char* simState = NULL;
602 event->switchToManualAnswer();
603 event->setCancelAllowed(true);
605 if (tel_get_sim_init_info(m_tapiHandle, &simCardState, &cardChanged) == TAPI_API_SUCCESS) {
606 switch(simCardState) {
607 case TAPI_SIM_STATUS_CARD_NOT_PRESENT :
608 case TAPI_SIM_STATUS_CARD_REMOVED :
609 simState = strdup("ABSENT");
611 case TAPI_SIM_STATUS_SIM_INITIALIZING :
612 simState = strdup("INITIALIZING");
614 case TAPI_SIM_STATUS_SIM_INIT_COMPLETED :
615 simState = strdup("READY");
617 case TAPI_SIM_STATUS_SIM_PIN_REQUIRED :
618 simState = strdup("PIN_REQUIRED");
620 case TAPI_SIM_STATUS_SIM_PUK_REQUIRED :
621 simState = strdup("PUK_REQUIRED");
623 case TAPI_SIM_STATUS_SIM_LOCK_REQUIRED :
624 case TAPI_SIM_STATUS_CARD_BLOCKED :
625 simState = strdup("SIM_LOCKED");
627 case TAPI_SIM_STATUS_SIM_NCK_REQUIRED :
628 case TAPI_SIM_STATUS_SIM_NSCK_REQUIRED :
629 simState = strdup("NETWORK_LOCKED");
632 simState = strdup("UNKNOWN");
635 LoggerD("simState : " << simState);
636 event->setSimState(simState);
639 if(strcmp(simState, "READY") == 0) {
640 if (tel_get_sim_imsi(m_tapiHandle, &imsi) == TAPI_API_SUCCESS) {
641 LoggerD("mcc : " << imsi.szMcc <<
\r" mnc : " << imsi.szMnc << " msin : " << imsi.szMsin);
642 event->setSimImsi(imsi.szMcc, imsi.szMnc, imsi.szMsin);
644 LoggerE("get fail sim imsi");
646 SysteminfoAsyncPendingEvent *cphsPendingEvent = new SysteminfoAsyncPendingEvent((void *)this, event);
647 tel_get_sim_cphs_netname(m_tapiHandle, SimCphsValueCallback, cphsPendingEvent);
648 SysteminfoAsyncPendingEvent *msisdnPendingEvent = new SysteminfoAsyncPendingEvent((void *)this, event);
649 tel_get_sim_msisdn(m_tapiHandle, SimMsisdnValueCallback, msisdnPendingEvent);
650 SysteminfoAsyncPendingEvent *iccidPendingEvent = new SysteminfoAsyncPendingEvent((void *)this, event);
651 tel_get_sim_iccid(m_tapiHandle, SimIccidValueCallback, iccidPendingEvent);
652 SysteminfoAsyncPendingEvent *spnPendingEvent = new SysteminfoAsyncPendingEvent((void *)this, event);
653 tel_get_sim_spn(m_tapiHandle, SimSpnValueCallback, spnPendingEvent);
655 event->makeSimObject();
656 EventRequestReceiver<EventGetSysteminfo>::ManualAnswer(event);
659 LoggerE("get fail sim state");
662 event->processGetValue((void *)m_connectionHandle);
666 void Systeminfo::OnRequestReceived(const EventWatchSysteminfoPtr& event)
668 WatchOption watchOption = event->getWatchOption();
670 event->switchToManualAnswer();
671 event->setCancelAllowed(true);
673 switch(event->getWatchType()) {
674 case WATCH_TYPE_BATTERY:
675 if ((m_EventMgrPtr->getEventBatteryList()).size() == 1) {
676 vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, BatteryValueCallback, (void *)this);
677 vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, BatteryValueCallback, (void *)this);
680 case WATCH_TYPE_DISPLAY:
681 if ((m_EventMgrPtr->getEventDisplayList()).size() == 1) {
682 vconf_notify_key_changed(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, DisplayValueCallback, (void *)this);
685 case WATCH_TYPE_NETWORK:
686 if ((m_EventMgrPtr->getEventNetworkList()).size() == 1) {
687 connection_set_type_changed_cb(m_connectionHandle, NetworkTypeValueCallback, (void *)this);
690 case WATCH_TYPE_WIFINETWORK:
691 if ((m_EventMgrPtr->getEventWifiNetworkList()).size() == 1) {
692 if (m_networkRegist == REGIST_NOT) {
693 connection_set_ip_address_changed_cb(m_connectionHandle, NetworkValueCallback, (void *)this);
694 m_networkRegist = REGIST_WIFI;
695 } else if (m_networkRegist== REGIST_CELLULAR) {
696 m_networkRegist = REGIST_ALL;
700 case WATCH_TYPE_CELLULARNETWORK:
701 if ((m_EventMgrPtr->getEventCellularNetworkList()).size() == 1) {
702 vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, CellularNetworkValueCallback, (void *)this);
703 vconf_notify_key_changed(VCONFKEY_TELEPHONY_CELLID, CellularNetworkValueCallback, (void *)this);
704 vconf_notify_key_changed(VCONFKEY_TELEPHONY_LAC, CellularNetworkValueCallback, (void *)this);
705 vconf_notify_key_changed(VCONFKEY_TELEPHONY_SVC_ROAM, CellularNetworkValueCallback, (void *)this);
706 if (m_networkRegist == REGIST_NOT) {
707 connection_set_ip_address_changed_cb(m_connectionHandle, NetworkValueCallback, (void *)this);
708 m_networkRegist = REGIST_CELLULAR;
709 } else if (m_networkRegist== REGIST_WIFI) {
710 m_networkRegist = REGIST_ALL;
714 case WATCH_TYPE_STORAGE:
715 if ((m_EventMgrPtr->getEventStorageList()).size() == 1) {
716 if (!m_storageTimer) {
717 m_storageTimer = ecore_timer_add(1, StorageValueCallback, this);
718 ecore_timer_thaw(m_storageTimer);
723 if ((m_EventMgrPtr->getEventCpuList()).size() == 1) {
725 m_cpuTimer = ecore_timer_add(1, CpuValueCallback, this);
726 ecore_timer_thaw(m_cpuTimer);
730 case WATCH_TYPE_DEVICE_ORIENTATION:
731 LoggerD("regist sensor");
732 if ((m_EventMgrPtr->getEventDeviceOrientationList()).size() == 1) {
733 vconf_notify_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, OrientationValueVconfCallback, (void *)this);
734 int state = sf_register_event(m_sensorHandle, ACCELEROMETER_EVENT_ROTATION_CHECK, NULL, OrientationValueCallback, (void *)this);
736 LoggerD("sensor_register_cb fail to gather data");
737 } else if (state == 0) {
738 LoggerD("sensor_register_cb success to gather data");
741 LoggerD("already regist");
744 case WATCH_TYPE_LOCALE:
745 if ((m_EventMgrPtr->getEventLocaleList()).size() == 1) {
746 if (runtime_info_set_changed_cb(RUNTIME_INFO_KEY_REGION, localeChangedCallback, (void *)this) != RUNTIME_INFO_ERROR_NONE) {
747 LoggerE("regist failed");
748 Throw(WrtDeviceApis::Commons::Exception);
750 if (runtime_info_set_changed_cb(RUNTIME_INFO_KEY_LANGUAGE, localeChangedCallback, (void *)this) != RUNTIME_INFO_ERROR_NONE) {
751 LoggerE("regist failed");
752 Throw(WrtDeviceApis::Commons::Exception);
756 case WATCH_TYPE_PERIPHERAL:
757 if ((m_EventMgrPtr->getEventPeripheralList()).size() == 1) {
758 vconf_notify_key_changed(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, PeripheralValueCallback, (void *)this);
759 vconf_notify_key_changed(VCONFKEY_SYSMAN_HDMI, PeripheralValueCallback, (void *)this);
763 event->processGetValue();
767 ////////////////////////////////////////////////////////////////////////////////////////
769 Systeminfo::EventMgr::EventMgr()
773 Systeminfo::EventMgr::~EventMgr()
777 void Systeminfo::EventMgr::clearAllEvent()
779 DPL::Mutex::ScopedLock lock(&m_synchro);
781 while (!m_eventBatteryList.empty()) {
782 EventWatchSysteminfoPtr event = m_eventBatteryList.front();
783 LoggerD("removing EventId=" << event->getId());
785 m_eventBatteryList.pop_front();
787 while (!m_eventDisplayList.empty()) {
788 EventWatchSysteminfoPtr event = m_eventDisplayList.front();
789 LoggerD("removing EventId=" << event->getId());
791 m_eventDisplayList.pop_front();
793 while (!m_eventWifiNetworkList.empty()) {
794 EventWatchSysteminfoPtr event = m_eventWifiNetworkList.front();
795 LoggerD("removing EventId=" << event->getId());
797 m_eventWifiNetworkList.pop_front();
799 while (!m_eventCelluarNetworkList.empty()) {
800 EventWatchSysteminfoPtr event = m_eventCelluarNetworkList.front();
801 LoggerD("removing EventId=" << event->getId());
803 m_eventCelluarNetworkList.pop_front();
805 while (!m_eventStorageList.empty()) {
806 EventWatchSysteminfoPtr event = m_eventStorageList.front();
807 LoggerD("removing EventId=" << event->getId());
809 m_eventStorageList.pop_front();
811 while (!m_eventCpuList.empty()) {
812 EventWatchSysteminfoPtr event = m_eventCpuList.front();
813 LoggerD("removing EventId=" << event->getId());
815 m_eventCpuList.pop_front();
817 while (!m_eventSimList.empty()) {
818 EventWatchSysteminfoPtr event = m_eventSimList.front();
819 LoggerD("removing EventId=" << event->getId());
821 m_eventSimList.pop_front();
823 while (!m_eventDeviceOrientationList.empty()) {
824 EventWatchSysteminfoPtr event = m_eventDeviceOrientationList.front();
825 LoggerD("removing EventId=" << event->getId());
827 m_eventDeviceOrientationList.pop_front();
829 while (!m_eventLocaleList.empty()) {
830 EventWatchSysteminfoPtr event = m_eventLocaleList.front();
831 LoggerD("removing EventId=" << event->getId());
833 m_eventLocaleList.pop_front();
835 while (!m_eventPeripheralList.empty()) {
836 EventWatchSysteminfoPtr event = m_eventPeripheralList.front();
837 LoggerD("removing EventId=" << event->getId());
839 m_eventPeripheralList.pop_front();
843 void Systeminfo::EventMgr::addEvent(const EventWatchSysteminfoPtr& arg, const int watchType)
845 DPL::Mutex::ScopedLock lock(&m_synchro);
847 if (watchType == WATCH_TYPE_BATTERY){
848 m_eventBatteryList.push_back(arg);
849 LoggerD("Event Battery list size=" << m_eventBatteryList.size());
850 } else if (watchType == WATCH_TYPE_DISPLAY) {
851 m_eventDisplayList.push_back(arg);
852 LoggerD("Event display list size=" << m_eventDisplayList.size());
853 } else if (watchType == WATCH_TYPE_WIFINETWORK) {
854 m_eventWifiNetworkList.push_back(arg);
855 LoggerD("Event wifi network list size=" << m_eventWifiNetworkList.size());
856 } else if (watchType == WATCH_TYPE_CELLULARNETWORK) {
857 m_eventCelluarNetworkList.push_back(arg);
858 LoggerD("Event cellular network list size=" << m_eventCelluarNetworkList.size());
859 } else if (watchType == WATCH_TYPE_STORAGE) {
860 m_eventStorageList.push_back(arg);
861 LoggerD("Event storage list size=" << m_eventStorageList.size());
862 } else if (watchType == WATCH_TYPE_CPU) {
863 m_eventCpuList.push_back(arg);
864 LoggerD("Event cpu list size=" << m_eventCpuList.size());
865 } else if (watchType == WATCH_TYPE_SIM) {
866 m_eventSimList.push_back(arg);
867 LoggerD("Event sim list size=" << m_eventSimList.size());
868 } else if (watchType == WATCH_TYPE_DEVICE_ORIENTATION) {
869 m_eventDeviceOrientationList.push_back(arg);
870 LoggerD("Event device orientation list size=" << m_eventDeviceOrientationList.size());
871 } else if (watchType == WATCH_TYPE_NETWORK) {
872 m_eventNetworkList.push_back(arg);
873 LoggerD("Event network list size=" << m_eventNetworkList.size());
874 } else if (watchType == WATCH_TYPE_LOCALE) {
875 m_eventLocaleList.push_back(arg);
876 LoggerD("Event Locale list size=" << m_eventLocaleList.size());
877 } else if (watchType == WATCH_TYPE_PERIPHERAL) {
878 m_eventPeripheralList.push_back(arg);
879 LoggerD("Event peripheral list size=" << m_eventPeripheralList.size());
883 void Systeminfo::EventMgr::removeEvent(WatchId id, const int watchType)
885 DPL::Mutex::ScopedLock lock(&m_synchro);
886 LoggerD("Event id : " << id);
888 EventWatchSysteminfoPtr event(NULL);
890 LoggerD("trying to delete event, id=" << id);
892 if (watchType == WATCH_TYPE_BATTERY) {
893 for (EventBatteryList::iterator it = m_eventBatteryList.begin(); it != m_eventBatteryList.end(); it++) {
894 if (id == (*it)->getId()) {
900 LoggerE("event id not in the list, nothing to do");
904 LoggerD("event Battery list size=" << m_eventBatteryList.size());
905 m_eventBatteryList.remove(event);
906 LoggerD( "event removed, event Battery list size=" << m_eventBatteryList.size());
907 } else if (watchType == WATCH_TYPE_DISPLAY) {
908 for (EventDisplayList::iterator it = m_eventDisplayList.begin(); it != m_eventDisplayList.end(); it++) {
909 if (id == (*it)->getId()) {
915 LoggerE("event id not in the list, nothing to do");
919 LoggerD("event display list size=" << m_eventDisplayList.size());
920 m_eventDisplayList.remove(event);
921 LoggerD( "event removed, event display list size=" << m_eventDisplayList.size());
922 } else if (watchType == WATCH_TYPE_WIFINETWORK) {
923 for (EventWifiNetworkList::iterator it = m_eventWifiNetworkList.begin(); it != m_eventWifiNetworkList.end(); it++) {
924 if (id == (*it)->getId()) {
930 LoggerE("event id not in the list, nothing to do");
934 LoggerD("event wifi network list size=" << m_eventWifiNetworkList.size());
935 m_eventWifiNetworkList.remove(event);
936 LoggerD( "event removed, event wifi network list size=" << m_eventCelluarNetworkList.size());
937 } else if (watchType == WATCH_TYPE_CELLULARNETWORK) {
938 for (EventCellularNetworkList::iterator it = m_eventCelluarNetworkList.begin(); it != m_eventCelluarNetworkList.end(); it++) {
939 if (id == (*it)->getId()) {
945 LoggerE("event id not in the list, nothing to do");
949 LoggerD("event cellular network list size=" << m_eventCelluarNetworkList.size());
950 m_eventCelluarNetworkList.remove(event);
951 LoggerD( "event removed, event cellular network list size=" << m_eventCelluarNetworkList.size());
952 } else if (watchType == WATCH_TYPE_STORAGE) {
953 for (EventStorageList::iterator it = m_eventStorageList.begin(); it != m_eventStorageList.end(); it++) {
954 if (id == (*it)->getId()) {
960 LoggerE("event id not in the list, nothing to do");
964 LoggerD("event storage list size=" << m_eventStorageList.size());
965 m_eventStorageList.remove(event);
966 LoggerD( "event removed, event storage list size=" << m_eventStorageList.size());
967 } else if (watchType == WATCH_TYPE_CPU) {
968 for (EventCpuList::iterator it = m_eventCpuList.begin(); it != m_eventCpuList.end(); it++) {
969 if (id == (*it)->getId()) {
975 LoggerE("event id not in the list, nothing to do");
979 LoggerD("event cpu list size=" << m_eventCpuList.size());
980 m_eventCpuList.remove(event);
981 LoggerD( "event removed, event cpu list size=" << m_eventCpuList.size());
982 } else if (watchType == WATCH_TYPE_SIM) {
983 for (EventSimList::iterator it = m_eventSimList.begin(); it != m_eventSimList.end(); it++) {
984 if (id == (*it)->getId()) {
990 LoggerE("event id not in the list, nothing to do");
994 LoggerD("event sim list size=" << m_eventSimList.size());
995 m_eventSimList.remove(event);
996 LoggerD( "event removed, event sim list size=" << m_eventSimList.size());
997 } else if (watchType == WATCH_TYPE_DEVICE_ORIENTATION) {
998 for (EventDeviceOrientationList::iterator it = m_eventDeviceOrientationList.begin(); it != m_eventDeviceOrientationList.end(); it++) {
999 if (id == (*it)->getId()) {
1005 LoggerE("event id not in the list, nothing to do");
1009 LoggerD("event device orientation list size=" << m_eventDeviceOrientationList.size());
1010 m_eventDeviceOrientationList.remove(event);
1011 LoggerD( "event removed, event device orientation list size=" << m_eventDeviceOrientationList.size());
1012 } else if (watchType == WATCH_TYPE_NETWORK) {
1013 for (EventNetworkList::iterator it = m_eventNetworkList.begin(); it != m_eventNetworkList.end(); it++) {
1014 if (id == (*it)->getId()) {
1020 LoggerE("event id not in the list, nothing to do");
1024 LoggerD("event network list size=" << m_eventNetworkList.size());
1025 m_eventNetworkList.remove(event);
1026 LoggerD( "event removed, event network list size=" << m_eventNetworkList.size());
1027 } else if (watchType == WATCH_TYPE_LOCALE) {
1028 for (EventLocaleList::iterator it = m_eventLocaleList.begin(); it != m_eventLocaleList.end(); it++) {
1029 if (id == (*it)->getId()) {
1035 LoggerE("event id not in the list, nothing to do");
1039 LoggerD("event Locale list size=" << m_eventLocaleList.size());
1040 m_eventLocaleList.remove(event);
1041 LoggerD( "event removed, event Locale list size=" << m_eventLocaleList.size());
1042 } else if (watchType == WATCH_TYPE_PERIPHERAL) {
1043 for (EventPeripheralList::iterator it = m_eventPeripheralList.begin(); it != m_eventPeripheralList.end(); it++) {
1044 if (id == (*it)->getId()) {
1050 LoggerE("event id not in the list, nothing to do");
1054 LoggerD("event peripheral list size=" << m_eventPeripheralList.size());
1055 m_eventPeripheralList.remove(event);
1056 LoggerD( "event removed, event peripheral list size=" << m_eventPeripheralList.size());
1060 const int Systeminfo::EventMgr::getWatchType(const long id)
1062 DPL::Mutex::ScopedLock lock(&m_synchro);
1064 EventWatchSysteminfoPtr event(NULL);
1066 for (EventBatteryList::iterator it = m_eventBatteryList.begin(); it != m_eventBatteryList.end(); it++) {
1067 if (id == (*it)->getId()) {
1073 for (EventDisplayList::iterator it = m_eventDisplayList.begin(); it != m_eventDisplayList.end(); it++) {
1074 if (id == (*it)->getId()) {
1080 for (EventWifiNetworkList::iterator it = m_eventWifiNetworkList.begin(); it != m_eventWifiNetworkList.end(); it++) {
1081 if (id == (*it)->getId()) {
1087 for (EventCellularNetworkList::iterator it = m_eventCelluarNetworkList.begin(); it != m_eventCelluarNetworkList.end(); it++) {
1088 if (id == (*it)->getId()) {
1094 for (EventStorageList::iterator it = m_eventStorageList.begin(); it != m_eventStorageList.end(); it++) {
1095 if (id == (*it)->getId()) {
1101 for (EventCpuList::iterator it = m_eventCpuList.begin(); it != m_eventCpuList.end(); it++) {
1102 if (id == (*it)->getId()) {
1108 for (EventSimList::iterator it = m_eventSimList.begin(); it != m_eventSimList.end(); it++) {
1109 if (id == (*it)->getId()) {
1115 for (EventDeviceOrientationList::iterator it = m_eventDeviceOrientationList.begin(); it != m_eventDeviceOrientationList.end(); it++) {
1116 if (id == (*it)->getId()) {
1122 for (EventNetworkList::iterator it = m_eventNetworkList.begin(); it != m_eventNetworkList.end(); it++) {
1123 if (id == (*it)->getId()) {
1129 for (EventSimList::iterator it = m_eventSimList.begin(); it != m_eventSimList.end(); it++) {
1130 if (id == (*it)->getId()) {
1136 for (EventLocaleList::iterator it = m_eventLocaleList.begin(); it != m_eventLocaleList.end(); it++) {
1137 if (id == (*it)->getId()) {
1143 for (EventPeripheralList::iterator it = m_eventPeripheralList.begin(); it != m_eventPeripheralList.end(); it++) {
1144 if (id == (*it)->getId()) {
1151 LoggerE("event id not in the list, nothing to do");
1152 return WATCH_TYPE_UNKNOWN;
1155 return event->getWatchType();
1158 EventBatteryList Systeminfo::EventMgr::getEventBatteryList()
1160 return m_eventBatteryList;
1163 EventDisplayList Systeminfo::EventMgr::getEventDisplayList()
1165 return m_eventDisplayList;
1168 EventNetworkList Systeminfo::EventMgr::getEventNetworkList()
1170 return m_eventNetworkList;
1173 EventWifiNetworkList Systeminfo::EventMgr::getEventWifiNetworkList()
1175 return m_eventWifiNetworkList;
1178 EventCellularNetworkList Systeminfo::EventMgr::getEventCellularNetworkList()
1180 return m_eventCelluarNetworkList;
1183 EventStorageList Systeminfo::EventMgr::getEventStorageList()
1185 return m_eventStorageList;
1188 EventCpuList Systeminfo::EventMgr::getEventCpuList()
1190 return m_eventCpuList;
1193 EventDeviceOrientationList Systeminfo::EventMgr::getEventDeviceOrientationList()
1195 return m_eventDeviceOrientationList;
1198 EventSimList Systeminfo::EventMgr::getEventSimList()
1200 return m_eventSimList;
1203 EventLocaleList Systeminfo::EventMgr::getEventLocaleList()
1205 return m_eventLocaleList;
1208 EventPeripheralList Systeminfo::EventMgr::getEventPeripheralList()
1210 return m_eventPeripheralList;
1213 ////////////////////////////////////////////////////////////////////////////////////////
1215 PROPERTY_GET_SYSTEMINFO_DEFINITION(Battery) {
1216 BatteryPropertiesPtr BatteryPtr(new BatteryProperties());
1220 if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, &value) != 0) {
1221 return JSValueMakeNull(context);
1223 BatteryPtr->level = (double)(value)/CPU_POWER_DEVICE_VALUE;
1226 if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &value2) != 0) {
1227 return JSValueMakeNull(context);
1229 BatteryPtr->isCharging = (value2 == 0) ? false : true;
1232 return JSBatteryInfo::createJSObject(context, BatteryPtr);
1235 PROPERTY_GET_SYSTEMINFO_DEFINITION(Cpu) {
1236 Converter converter(context);
1238 CpuPropertiesPtr cpuPtr(new CpuProperties());
1240 long long usr = 0, nice = 0, system = 0, idle = 0, total = 0, cpuUsage = 0;
1242 fp = fopen("/proc/stat", "r");
1244 return JSValueMakeNull(context);
1247 if (fscanf(fp, "%*s %lld %lld %lld %lld", &usr, &system, &nice, &idle) > 0) {
1248 total = usr + nice + system + idle;
1249 if ((total > 0LL) && (idle > 0LL)) {
1250 cpuUsage = idle * 100LL / total;
1251 cpuPtr->load = (double)cpuUsage / 100.0;
1252 LoggerD("cpu load : " << cpuPtr->load);
1257 return JSCpuInfo::createJSObject(context, cpuPtr);
1260 PROPERTY_GET_SYSTEMINFO_DEFINITION(Storage) {
1261 Converter converter(context);
1265 if (statfs(STORAGE_INTERNAL_PATH, &fs) < 0) {
1266 return JSValueMakeNull(context);
1268 StoragePropertiesPtr storagePtr(new StorageProperties());
1269 storagePtr->units[0].type = "INTERNAL";
1270 storagePtr->units[0].capacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_blocks;
1271 storagePtr->units[0].availableCapacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_bavail;
1272 storagePtr->units[0].isRemoveable = false;
1273 storagePtr->units[0].isRemovable = false;
1274 storagePtr->cnt = 1;
1275 LoggerD("type : " << storagePtr->units[0].type);
1276 if(vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &sdcardState) == 0) {
1277 if(sdcardState == VCONFKEY_SYSMAN_MMC_MOUNTED){
1278 if (statfs(STORAGE_SDCARD_PATH, &fs) < 0) {
1279 return JSValueMakeNull(context);
1281 storagePtr->units[1].type = "MMC";
1282 storagePtr->units[1].capacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_blocks;
1283 storagePtr->units[1].availableCapacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_bavail;
1284 storagePtr->units[1].isRemoveable = false;
1285 storagePtr->units[1].isRemovable = false;
1286 storagePtr->cnt = 2;
1287 LoggerD("type : " << storagePtr->units[1].type);
1290 return JSStorageInfo::createJSObject(context, storagePtr);
1294 PROPERTY_GET_SYSTEMINFO_DEFINITION(Display) {
1295 Converter converter(context);
1297 DisplayPropertiesPtr display(new DisplayProperties());
1298 int brightness=0, dotsPerInch=0, physicalW=0, physicalH=0;
1299 bool screenSizeSmall = false, screenSizeBig = false;
1301 if(vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, &brightness) == 0) {
1302 display->brightness = (double)(brightness)/DISPLAY_BRIGHTNESS_DIVIDE_VALUE;
1305 if(system_info_get_platform_bool("tizen.org/feature/screen.size.normal.480.800", &screenSizeSmall) == SYSTEM_INFO_ERROR_NONE) {
1306 if (screenSizeSmall) {
1307 display->resolutionWidth = 480;
1308 display->resolutionHeight = 800;
1310 if (system_info_get_platform_bool("tizen.org/feature/screen.size.normal.720.1280", &screenSizeBig) == SYSTEM_INFO_ERROR_NONE) {
1311 if (screenSizeBig) {
1312 display->resolutionWidth = 720;
1313 display->resolutionHeight = 1280;
1319 if(system_info_get_platform_int("tizen.org/feature/screen.dpi", &dotsPerInch) == SYSTEM_INFO_ERROR_NONE) {
1320 display->dotsPerInchWidth = dotsPerInch;
1321 display->dotsPerInchHeight = dotsPerInch;
1324 if(system_info_get_value_int(SYSTEM_INFO_KEY_PHYSICAL_SCREEN_WIDTH, &physicalW) == SYSTEM_INFO_ERROR_NONE) {
1325 display->physicalWidth = physicalW;
1328 if(system_info_get_value_int(SYSTEM_INFO_KEY_PHYSICAL_SCREEN_HEIGHT, &physicalH) == SYSTEM_INFO_ERROR_NONE) {
1329 display->physicalHeight = physicalH;
1332 return JSDisplayInfo::createJSObject(context, display);
1335 PROPERTY_GET_SYSTEMINFO_DEFINITION(Network) {
1337 Converter converter(context);
1338 NetworkPropertiesPtr Network(new NetworkProperties());
1339 connection_h connectionHandle = (connection_h)handle;
1340 connection_type_e connectionType;
1341 int networkType = 0;
1343 if (connection_get_type(connectionHandle, &connectionType) != CONNECTION_ERROR_NONE) {
1344 LoggerD("get connection type is failed");
1345 return JSNetworkInfo::createJSObject(context, Network);
1348 if (connectionType == CONNECTION_TYPE_WIFI) {
1349 LoggerD("wifi network");
1350 Network->networkType= "WIFI";
1351 } else if (connectionType == CONNECTION_TYPE_CELLULAR) {
1352 if (vconf_get_int(VCONFKEY_TELEPHONY_SVCTYPE, &networkType) == 0) {
1353 if (networkType < VCONFKEY_TELEPHONY_SVCTYPE_2G) {
1354 Network->networkType= "NONE";
1355 } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_2G) {
1356 Network->networkType= "2G";
1357 } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_2G || networkType == VCONFKEY_TELEPHONY_SVCTYPE_2_5G_EDGE) {
1358 Network->networkType= "2.5";
1359 } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_3G || networkType == VCONFKEY_TELEPHONY_SVCTYPE_HSDPA) {
1360 Network->networkType= "3G";
1361 } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_LTE) {
1362 Network->networkType= "4G";
1364 Network->networkType= "NONE";
1368 Network->networkType= "NONE";
1371 return JSNetworkInfo::createJSObject(context, Network);
1374 PROPERTY_GET_SYSTEMINFO_DEFINITION(WifiNetwork) {
1375 Converter converter(context);
1376 WifiNetworkPropertiesPtr wifiNetwork(new WifiNetworkProperties());
1377 connection_h connectionHandle = (connection_h)handle;
1378 connection_type_e connectionType;
1379 connection_profile_h profileHandle = NULL;
1380 connection_address_family_e addressFamily = CONNECTION_ADDRESS_FAMILY_IPV4;
1381 char* ipAddr = NULL;
1385 if (connection_get_type(connectionHandle, &connectionType) != CONNECTION_ERROR_NONE) {
1386 return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1389 if (connectionType == CONNECTION_TYPE_WIFI) {
1390 wifiNetwork->status = "ON";
1392 wifiNetwork->status = "OFF";
1393 return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1396 if (connection_get_current_profile(connectionHandle, &profileHandle) != CONNECTION_ERROR_NONE) {
1397 return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1400 if (connection_profile_get_wifi_essid(profileHandle, &essid) == CONNECTION_ERROR_NONE) {
1401 wifiNetwork->ssid = essid;
1405 if (connection_profile_get_ip_address(profileHandle, addressFamily, &ipAddr) == CONNECTION_ERROR_NONE) {
1406 wifiNetwork->ipAddress = ipAddr;
1410 if (connection_profile_get_wifi_rssi(profileHandle, &rssi) == CONNECTION_ERROR_NONE) {
1411 wifiNetwork->signalStrength = (double) rssi/WIFI_SIGNAL_STRENGTH_DIVIDE_VALUE;
1414 return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1417 PROPERTY_GET_SYSTEMINFO_DEFINITION(CellularNetwork) {
1418 Converter converter(context);
1419 CellularNetworkPropertiesPtr cellularNetwork(new CellularNetworkProperties());
1420 connection_h connectionHandle = (connection_h)handle;
1421 connection_type_e connectionType;
1422 connection_profile_h profileHandle = NULL;
1423 connection_address_family_e addressFamily = CONNECTION_ADDRESS_FAMILY_IPV4;
1424 char* ipAddr = NULL;
1427 int plmn = 0, cellId = 0, lac = 0, isRoaming = 0, isFlightMode = 0;
1429 TIME_TRACER_ITEM_BEGIN("(cellular)mcc", 0);
1430 if (vconf_get_int(VCONFKEY_TELEPHONY_PLMN, &plmn) == 0) {
1431 cellularNetwork->mcc = plmn / 100;
1432 cellularNetwork->mnc = plmn % 100;
1434 TIME_TRACER_ITEM_END("(cellular)mcc", 0);
1436 TIME_TRACER_ITEM_BEGIN("(cellular)cellId", 0);
1437 if (vconf_get_int(VCONFKEY_TELEPHONY_CELLID, &cellId) == 0) {
1438 cellularNetwork->cellId = cellId;
1440 TIME_TRACER_ITEM_END("(cellular)cellId", 0);
1442 TIME_TRACER_ITEM_BEGIN("(cellular)lac", 0);
1443 if (vconf_get_int(VCONFKEY_TELEPHONY_LAC, &lac) == 0) {
1444 cellularNetwork->lac = lac;
1446 TIME_TRACER_ITEM_END("(cellular)lac", 0);
1448 TIME_TRACER_ITEM_BEGIN("(cellular)isRoaming", 0);
1449 if (vconf_get_int(VCONFKEY_TELEPHONY_SVC_ROAM, &isRoaming) == 0) {
1451 cellularNetwork->isRoaming = true;
1453 cellularNetwork->isRoaming = false;
1456 TIME_TRACER_ITEM_END("(cellular)isRoaming", 0);
1458 TIME_TRACER_ITEM_BEGIN("(cellular)isFlightMode", 0);
1459 if (vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &isFlightMode) == 0) {
1461 cellularNetwork->isFlightMode = true;
1463 cellularNetwork->isFlightMode = false;
1466 TIME_TRACER_ITEM_END("(cellular)isFlightMode", 0);
1468 if (connection_get_type(connectionHandle, &connectionType) != CONNECTION_ERROR_NONE) {
1469 return JSCellularNetworkInfo::createJSObject(context, cellularNetwork);
1472 if (connectionType == CONNECTION_TYPE_CELLULAR) {
1473 cellularNetwork->status = "ON";
1474 if (connection_get_current_profile(connectionHandle, &profileHandle) == CONNECTION_ERROR_NONE) {
1475 TIME_TRACER_ITEM_BEGIN("(cellular)apn", 0);
1476 if (connection_profile_get_cellular_apn(profileHandle, &apn) == CONNECTION_ERROR_NONE) {
1477 cellularNetwork->apn = apn;
1480 TIME_TRACER_ITEM_END("(cellular)apn", 0);
1482 TIME_TRACER_ITEM_BEGIN("(cellular)ipAddress", 0);
1483 if (connection_profile_get_ip_address(profileHandle, addressFamily, &ipAddr) == CONNECTION_ERROR_NONE) {
1484 cellularNetwork->ipAddress = ipAddr;
1487 TIME_TRACER_ITEM_END("(cellular)ipAddress", 0);
1488 connection_profile_destroy(profileHandle);
1491 cellularNetwork->status = "OFF";
1492 if (connection_get_default_cellular_service_profile(connectionHandle, CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET, &profileHandle) == CONNECTION_ERROR_NONE) {
1493 TIME_TRACER_ITEM_BEGIN("(cellular)apn", 0);
1494 if (connection_profile_get_cellular_apn(profileHandle, &apn) == CONNECTION_ERROR_NONE) {
1495 cellularNetwork->apn = apn;
1498 TIME_TRACER_ITEM_END("(cellular)apn", 0);
1499 connection_profile_destroy(profileHandle);
1503 imei = tel_get_misc_me_imei_sync((TapiHandle*)tapiHandle);
1506 LoggerD("imei : " << imei);
1507 cellularNetwork->imei = imei;
1510 LoggerD("get fail imei");
1513 return JSCellularNetworkInfo::createJSObject(context, cellularNetwork);
1516 PROPERTY_GET_SYSTEMINFO_DEFINITION(SIM) {
1517 Converter converter(context);
1518 SIMPropertiesPtr SIM(new SIMProperties());
1520 return JSSIMInfo::createJSObject(context, SIM);
1523 PROPERTY_GET_SYSTEMINFO_DEFINITION(DeviceOrientation) {
1525 Converter converter(context);
1526 DeviceOrientationPropertiesPtr deviceOrientation(new DeviceOrientationProperties());
1528 unsigned long rotation = 0;
1529 int handleOrientaion = 0;
1530 int isAutoRotation = 0;
1532 if (vconf_get_bool(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &isAutoRotation) == 0) {
1533 if (isAutoRotation) {
1534 deviceOrientation->isAutoRotation = true;
1536 deviceOrientation->isAutoRotation = false;
1540 handleOrientaion = sf_connect(ACCELEROMETER_SENSOR);
1541 LoggerD("handleOrientaion : " << handleOrientaion);
1542 if (handleOrientaion < 0) {
1543 LoggerD ("sensor attach fail");
1544 return JSDeviceOrientationInfo::createJSObject(context, deviceOrientation);
1546 int state = sf_start(handleOrientaion, 0);
1548 LoggerD("start failed");
1551 int ret_val = sf_check_rotation(&rotation);
1553 LoggerD("sf_check_rotation fail to gather data\n");
1556 LoggerD(" rotation value = " << rotation);
1560 case ROTATION_EVENT_0:
1561 LoggerD("my_callback_func received data (PORTRAIT_TOP|HEAD_CENTER)\n");
1562 deviceOrientation->status = "PORTRAIT_PRIMARY";
1564 case ROTATION_EVENT_90:
1565 LoggerD("my_callback_func received data (LANDSCAPE|HEAD_RIGHT)\n");
1566 deviceOrientation->status = "LANDSCAPE_PRIMARY";
1568 case ROTATION_EVENT_180:
1569 LoggerD("my_callback_func received data (PORTRAIT_BTM|HEAD_CENTER)\n");
1570 deviceOrientation->status = "PORTRAIT_SECONDARY";
1572 case ROTATION_EVENT_270:
1573 LoggerD("my_callback_func received data (LANDSCAPE|HEAD_LEFT)\n");
1574 deviceOrientation->status = "LANDSCAPE_SECONDARY";
1577 LoggerD(" received data unexpected\n");
1581 state = sf_stop(handleOrientaion);
1582 LoggerD("handleOrientaion 1 state = " << state);
1584 state = sf_disconnect(handleOrientaion);
1585 LoggerD("handleOrientaion state =" << state);
1587 return JSDeviceOrientationInfo::createJSObject(context, deviceOrientation);
1590 PROPERTY_GET_SYSTEMINFO_DEFINITION(Build) {
1592 Converter converter(context);
1593 BuildPropertiesPtr Build(new BuildProperties());
1596 char* manufacturer = NULL;
1597 char* buildVersion = NULL;
1599 if(system_info_get_platform_string("tizen.org/system/model_name", &model) == SYSTEM_INFO_ERROR_NONE) {
1600 if (model != NULL) {
1601 LoggerD("model : " << model);
1602 Build->model = model;
1607 if (system_info_get_value_string(SYSTEM_INFO_KEY_MANUFACTURER, &manufacturer) == SYSTEM_INFO_ERROR_NONE) {
1608 if (manufacturer != NULL) {
1609 LoggerD("manufacturer : " << manufacturer);
1610 Build->manufacturer = manufacturer;
1615 if (system_info_get_value_string(SYSTEM_INFO_KEY_BUILD_STRING, &buildVersion) == SYSTEM_INFO_ERROR_NONE) {
1616 if (buildVersion != NULL) {
1617 LoggerD("buildVersion : " << buildVersion);
1618 Build->buildVersion = buildVersion;
1623 return JSBuildInfo::createJSObject(context, Build);
1626 PROPERTY_GET_SYSTEMINFO_DEFINITION(Locale) {
1628 Converter converter(context);
1629 LocalePropertiesPtr Locale(new LocaleProperties());
1631 char* country = NULL;
1632 char* language = NULL;
1634 if (runtime_info_get_value_string(RUNTIME_INFO_KEY_LANGUAGE, &language) == RUNTIME_INFO_ERROR_NONE) {
1635 if (language != NULL) {
1636 LoggerD("language : " << language);
1637 Locale->language = language;
1642 if (runtime_info_get_value_string(RUNTIME_INFO_KEY_REGION, &country) == RUNTIME_INFO_ERROR_NONE) {
1643 if (country != NULL) {
1644 LoggerD("country : " << country);
1646 char* countryTemp = NULL;
1647 token = strtok(country, ".");
1648 if (token != NULL) {
1649 countryTemp = strdup(token);
1650 if (countryTemp != NULL) {
1651 Locale->country = countryTemp;
1659 return JSLocaleInfo::createJSObject(context, Locale);
1662 PROPERTY_GET_SYSTEMINFO_DEFINITION(Peripheral) {
1663 Converter converter(context);
1664 PeripheralPropertiesPtr peripheral(new PeripheralProperties());
1665 int hdmiStatus = 0, wirelessDisplayStatus = 0 ;
1667 if (vconf_get_int(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, &wirelessDisplayStatus) == 0) {
1668 switch(wirelessDisplayStatus) {
1669 case VCONFKEY_MIRACAST_WFD_SOURCE_ON:
1670 peripheral->isVideoOutputOn = true;
1673 LoggerD("VideOutput status is off");
1678 if (vconf_get_int(VCONFKEY_SYSMAN_HDMI, &hdmiStatus) == 0) {
1679 switch(hdmiStatus) {
1680 case VCONFKEY_SYSMAN_HDMI_CONNECTED:
1681 peripheral->isVideoOutputOn = true;
1684 LoggerD("VideOutput status is off");
1689 return JSPeripheralInfo::createJSObject(context, peripheral);