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 <tapi_common.h>
26 #include <ITapiModem.h>
28 #include "Systeminfo.h"
31 using namespace WrtDeviceApis::CommonsJavaScript;
32 using namespace WrtDeviceApis::Commons;
36 namespace Systeminfo {
40 void BatteryValueCallback(keynode_t *node, void *event_ptr)
43 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_BATTERY);
47 void PeripheralValueCallback(keynode_t *node, void *event_ptr)
50 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_PERIPHERAL);
54 void CellularNetworkValueCallback(keynode_t *node, void *event_ptr)
57 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_CELLULARNETWORK);
61 void DisplayValueCallback(keynode_t *node, void* event_ptr)
64 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_DISPLAY);
68 void NetworkTypeValueCallback(connection_type_e type, void* event_ptr)
71 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_NETWORK);
75 void NetworkValueCallback(const char* ipv4_address, const char* ipv6_address, void* event_ptr)
78 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_NETWORK_ALL);
82 static Eina_Bool StorageValueCallback(void* event_ptr)
85 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_STORAGE);
87 return ECORE_CALLBACK_RENEW;
90 static Eina_Bool CpuValueCallback(void* event_ptr)
93 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_CPU);
95 return ECORE_CALLBACK_RENEW;
98 void OrientationValueCallback(unsigned int event_type, sensor_event_data_t *event , void *event_ptr)
102 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_DEVICE_ORIENTATION);
106 void localeChangedCallback(runtime_info_key_e key, void* event_ptr)
110 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_LOCALE);
116 #define STORAGE_INTERNAL_PATH "/opt/usr/media"
117 #define STORAGE_SDCARD_PATH "/opt/storage/sdcard"
118 #define STORAGE_USBHOST_PATH "/opt/storage/usb"
119 #define DISPLAY_BRIGHTNESS_DIVIDE_VALUE 100
120 #define WIFI_SIGNAL_STRENGTH_DIVIDE_VALUE 100
121 #define CPU_POWER_DEVICE_VALUE 100
123 #define RADIAN_VALUE (57.2957)
126 STORAGE_TYPE_UNKNOWN = 0,
127 STORAGE_TYPE_INTERNAL = 1,
128 STORAGE_TYPE_MMC = 2,
129 STORAGE_TYPE_USBHOST = 3
132 Systeminfo::OptionalProperty Systeminfo::m_Property;
134 Systeminfo::Systeminfo() : m_networkRegist(REGIST_NOT),
135 m_storageTimer(NULL),
138 m_connectionHandle(NULL)
140 EventMgrPtr eventMgrPtr(new EventMgr());
141 m_EventMgrPtr = eventMgrPtr;
142 if (m_Property.IsNull()) {
143 mapProperties properties;
144 properties["BATTERY"] = BasePropertyPtr(new Battery());
145 m_Property = properties;
146 (*m_Property)["CPU"] = BasePropertyPtr(new Cpu());
147 (*m_Property)["STORAGE"] = BasePropertyPtr(new Storage());
148 (*m_Property)["DISPLAY"] = BasePropertyPtr(new Display());
149 (*m_Property)["NETWORK"] = BasePropertyPtr(new Network());
150 (*m_Property)["WIFI_NETWORK"] = BasePropertyPtr(new WifiNetwork());
151 (*m_Property)["CELLULAR_NETWORK"] = BasePropertyPtr(new CellularNetwork());
152 (*m_Property)["SIM"] = BasePropertyPtr(new SIM());
153 (*m_Property)["DEVICE_ORIENTATION"] = BasePropertyPtr(new DeviceOrientation());
154 (*m_Property)["BUILD"] = BasePropertyPtr(new Build());
155 (*m_Property)["LOCALE"] = BasePropertyPtr(new Locale());
156 (*m_Property)["PERIPHERAL"] = BasePropertyPtr(new Peripheral());
159 int ret = connection_create(&m_connectionHandle);
161 if (CONNECTION_ERROR_NONE == ret) {
162 LoggerD("Network Client registration success");
164 LoggerD("Network Client registration success");
165 m_connectionHandle = NULL;
168 m_sensorHandle = sf_connect(ACCELEROMETER_SENSOR);
169 if (m_sensorHandle < 0) {
170 LoggerD ("sensor attach fail");
172 LoggerD("m_sensorHandle : " << m_sensorHandle);
173 int state = sf_start(m_sensorHandle, 0);
180 Systeminfo::~Systeminfo()
183 if (m_storageTimer) {
184 ecore_timer_freeze(m_storageTimer);
185 ecore_timer_del(m_storageTimer);
186 m_storageTimer = NULL;
189 ecore_timer_freeze(m_cpuTimer);
190 ecore_timer_del(m_cpuTimer);
193 m_EventMgrPtr->clearAllEvent();
195 if(m_connectionHandle != NULL) {
196 LoggerD("Network Client deregistration success");
197 connection_destroy(m_connectionHandle);
199 LoggerD("Network Client deregistration failed");
202 state = sf_stop(m_sensorHandle);
203 LoggerD("handle 1 state = " << state);
205 state = sf_disconnect(m_sensorHandle);
206 LoggerD("handle state =" << state);
209 DeviceCapabilitiesPropertiesPtr Systeminfo::getCapabilities()
212 DeviceCapabilitiesPropertiesPtr deviceCapabilities(new DeviceCapabilitiesProperties());
213 return deviceCapabilities;
216 void Systeminfo::get(const EventGetSysteminfoPtr& event)
218 EventRequestReceiver<EventGetSysteminfo>::PostRequest(event);
221 void Systeminfo::watch(const EventWatchSysteminfoPtr& event)
223 if(event->getWatchType() == WATCH_TYPE_UNKNOWN) {
224 LoggerD("watch method is not supported");
229 event->setSysteminfoPtr(this);
230 m_EventMgrPtr->addEvent(event, event->getWatchType());
232 EventRequestReceiver<EventWatchSysteminfo>::PostRequest(event);
235 void Systeminfo::clearWatch(const long id)
238 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
240 int watchType = m_EventMgrPtr->getWatchType(id);
242 case WATCH_TYPE_BATTERY:
243 if ((m_EventMgrPtr->getEventBatteryList()).size() == 1) {
244 vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, BatteryValueCallback);
245 vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, BatteryValueCallback);
248 case WATCH_TYPE_DISPLAY:
249 if ((m_EventMgrPtr->getEventDisplayList()).size() == 1) {
250 vconf_ignore_key_changed(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, DisplayValueCallback);
253 case WATCH_TYPE_NETWORK:
254 if ((m_EventMgrPtr->getEventNetworkList()).size() == 1) {
255 connection_unset_type_changed_cb(m_connectionHandle);
258 case WATCH_TYPE_WIFINETWORK:
259 if ((m_EventMgrPtr->getEventWifiNetworkList()).size() == 1) {
260 if (m_networkRegist == REGIST_WIFI) {
261 connection_unset_ip_address_changed_cb(m_connectionHandle);
262 m_networkRegist = REGIST_NOT;
263 } else if (m_networkRegist== REGIST_ALL) {
264 m_networkRegist = REGIST_CELLULAR;
268 case WATCH_TYPE_CELLULARNETWORK:
269 if ((m_EventMgrPtr->getEventCellularNetworkList()).size() == 1) {
270 vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, CellularNetworkValueCallback);
271 vconf_ignore_key_changed(VCONFKEY_TELEPHONY_CELLID, CellularNetworkValueCallback);
272 vconf_ignore_key_changed(VCONFKEY_TELEPHONY_LAC, CellularNetworkValueCallback);
273 vconf_ignore_key_changed(VCONFKEY_TELEPHONY_SVC_ROAM, CellularNetworkValueCallback);
274 if (m_networkRegist == REGIST_CELLULAR) {
275 connection_unset_ip_address_changed_cb(m_connectionHandle);
276 m_networkRegist = REGIST_NOT;
277 } else if (m_networkRegist== REGIST_ALL) {
278 m_networkRegist = REGIST_WIFI;
282 case WATCH_TYPE_STORAGE:
283 if ((m_EventMgrPtr->getEventStorageList()).size() == 1) {
284 if (m_storageTimer) {
285 ecore_timer_freeze(m_storageTimer);
286 ecore_timer_del(m_storageTimer);
287 m_storageTimer = NULL;
292 if ((m_EventMgrPtr->getEventCpuList()).size() == 1) {
294 ecore_timer_freeze(m_cpuTimer);
295 ecore_timer_del(m_cpuTimer);
300 case WATCH_TYPE_DEVICE_ORIENTATION:
301 if ((m_EventMgrPtr->getEventDeviceOrientationList()).size() == 1) {
302 int state = sf_unregister_event(m_sensorHandle, ACCELEROMETER_EVENT_ROTATION_CHECK);
304 LoggerD("sf_unregister_event fail to gather data\n");
308 case WATCH_TYPE_LOCALE:
309 if ((m_EventMgrPtr->getEventLocaleList()).size() == 1) {
310 if (runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_LANGUAGE) != RUNTIME_INFO_ERROR_NONE) {
311 LoggerE("regist failed");
312 Throw(WrtDeviceApis::Commons::Exception);
314 if (runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_REGION) != RUNTIME_INFO_ERROR_NONE) {
315 LoggerE("regist failed");
316 Throw(WrtDeviceApis::Commons::Exception);
320 case WATCH_TYPE_PERIPHERAL:
321 if ((m_EventMgrPtr->getEventPeripheralList()).size() == 1) {
322 vconf_ignore_key_changed(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, PeripheralValueCallback);
323 vconf_ignore_key_changed(VCONFKEY_SYSMAN_HDMI, PeripheralValueCallback);
326 case WATCH_TYPE_UNKNOWN:
327 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
330 m_EventMgrPtr->removeEvent(id, watchType);
334 BasePropertyPtr Systeminfo::getBasePropertyPtr(JSContextRef context, JSValueRef property)
336 Converter converter(context);
337 std::string l_property = converter.toString(property);
338 mapProperties::iterator it = (*m_Property).find(l_property);
339 if (it == (*m_Property).end()) {
340 LoggerE("not existing property");
341 Throw(WrtDeviceApis::Commons::ConversionException);
342 return BasePropertyPtr(NULL);
348 void Systeminfo::getWatchValue(const int watchType)
350 LoggerD(" watch type : " << watchType);
352 if (watchType == WATCH_TYPE_BATTERY) {
353 EventBatteryList eventList = m_EventMgrPtr->getEventBatteryList();
354 for (EventBatteryList::iterator it = eventList.begin(); it != eventList.end(); it++) {
355 (*it)->getWatchValue();
357 } else if (watchType == WATCH_TYPE_DISPLAY) {
358 EventDisplayList eventList = m_EventMgrPtr->getEventDisplayList();
359 for (EventDisplayList::iterator it = eventList.begin(); it != eventList.end(); it++) {
360 (*it)->getWatchValue();
362 } else if (watchType == WATCH_TYPE_NETWORK) {
363 EventNetworkList eventList = m_EventMgrPtr->getEventNetworkList();
364 for (EventNetworkList::iterator it = eventList.begin(); it != eventList.end(); it++) {
365 (*it)->getWatchValue();
367 } else if (watchType == WATCH_TYPE_NETWORK_ALL) {
368 EventWifiNetworkList eventListWifi = m_EventMgrPtr->getEventWifiNetworkList();
369 EventWifiNetworkList eventListCellular = m_EventMgrPtr->getEventCellularNetworkList();
370 if (eventListWifi.size() > 0) {
371 for (EventWifiNetworkList::iterator it = eventListWifi.begin(); it != eventListWifi.end(); it++) {
372 (*it)->getWatchValue();
375 if (eventListCellular.size() > 0) {
376 for (EventCellularNetworkList::iterator it = eventListCellular.begin(); it != eventListCellular.end(); it++) {
377 (*it)->getWatchValue();
380 } else if (watchType == WATCH_TYPE_CPU) {
381 EventCpuList eventList = m_EventMgrPtr->getEventCpuList();
382 for (EventCpuList::iterator it = eventList.begin(); it != eventList.end(); it++) {
383 (*it)->getWatchValue();
385 } else if (watchType == WATCH_TYPE_STORAGE) {
386 EventStorageList eventList = m_EventMgrPtr->getEventStorageList();
387 for (EventStorageList::iterator it = eventList.begin(); it != eventList.end(); it++) {
390 int usbhostState = 0;
391 if(vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &sdcardState) == 0) {
392 if(sdcardState == VCONFKEY_SYSMAN_MMC_MOUNTED) {
396 if(vconf_get_int(VCONFKEY_SYSMAN_USB_HOST_STATUS, &usbhostState) == 0) {
397 if(usbhostState == VCONFKEY_SYSMAN_USB_HOST_CONNECTED) {
401 LoggerD("storage cnt : " << storageCnt);
402 (*it)->getWatchValue(storageCnt);
404 }else if (watchType == WATCH_TYPE_DEVICE_ORIENTATION) {
405 EventDeviceOrientationList eventList = m_EventMgrPtr->getEventDeviceOrientationList();
406 for (EventDeviceOrientationList::iterator it = eventList.begin(); it != eventList.end(); it++) {
407 (*it)->getWatchValue();
409 } else if (watchType == WATCH_TYPE_LOCALE) {
410 EventLocaleList eventList = m_EventMgrPtr->getEventLocaleList();
411 for (EventLocaleList::iterator it = eventList.begin(); it != eventList.end(); it++) {
412 (*it)->getWatchValue();
414 } else if (watchType == WATCH_TYPE_PERIPHERAL) {
415 EventPeripheralList eventList = m_EventMgrPtr->getEventPeripheralList();
416 for (EventPeripheralList::iterator it = eventList.begin(); it != eventList.end(); it++) {
417 (*it)->getWatchValue();
419 } else if (watchType == WATCH_TYPE_CELLULARNETWORK) {
420 EventWifiNetworkList eventListCellular = m_EventMgrPtr->getEventCellularNetworkList();
421 if (eventListCellular.size() > 0) {
422 for (EventCellularNetworkList::iterator it = eventListCellular.begin(); it != eventListCellular.end(); it++) {
423 (*it)->getWatchValue();
429 connection_h Systeminfo::getConnectionHandle()
431 return m_connectionHandle;
434 JSValueRef Systeminfo::getCpuValue(JSContextRef context)
437 Converter converter(context);
439 CpuPropertiesPtr cpuPtr(new CpuProperties());
441 long long usr = 0, nice = 0, system = 0, idle = 0, cpuUsage = 0, diffIdle = 0, total = 0;
443 fp = fopen("/proc/stat", "r");
445 return JSValueMakeNull(context);
448 if (fscanf(fp, "%*s %lld %lld %lld %lld", &usr, &system, &nice, &idle) > 0) {
449 total = usr + nice + system + idle - m_cpuInfo.usr - m_cpuInfo.nice - m_cpuInfo.system - m_cpuInfo.idle;
450 diffIdle = idle-m_cpuInfo.idle;
451 if ((total > 0LL) && (diffIdle > 0LL)) {
452 cpuUsage = diffIdle * 100LL / total;
453 cpuPtr->load = (double)cpuUsage / 100.0;
455 m_cpuInfo.system = system;
456 m_cpuInfo.nice = nice;
457 m_cpuInfo.idle = idle;
458 LoggerD("cpu load : " << cpuPtr->load);
463 return JSCpuInfo::createJSObject(context, cpuPtr);
466 void Systeminfo::OnRequestReceived(const EventGetSysteminfoPtr& event)
469 event->processGetValue((void *)m_connectionHandle);
472 void Systeminfo::OnRequestReceived(const EventWatchSysteminfoPtr& event)
474 WatchOption watchOption = event->getWatchOption();
476 event->switchToManualAnswer();
477 event->setCancelAllowed(true);
479 switch(event->getWatchType()) {
480 case WATCH_TYPE_BATTERY:
481 if ((m_EventMgrPtr->getEventBatteryList()).size() == 1) {
482 vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, BatteryValueCallback, (void *)this);
483 vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, BatteryValueCallback, (void *)this);
486 case WATCH_TYPE_DISPLAY:
487 if ((m_EventMgrPtr->getEventDisplayList()).size() == 1) {
488 vconf_notify_key_changed(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, DisplayValueCallback, (void *)this);
491 case WATCH_TYPE_NETWORK:
492 if ((m_EventMgrPtr->getEventNetworkList()).size() == 1) {
493 connection_set_type_changed_cb(m_connectionHandle, NetworkTypeValueCallback, (void *)this);
496 case WATCH_TYPE_WIFINETWORK:
497 if ((m_EventMgrPtr->getEventWifiNetworkList()).size() == 1) {
498 if (m_networkRegist == REGIST_NOT) {
499 connection_set_ip_address_changed_cb(m_connectionHandle, NetworkValueCallback, (void *)this);
500 m_networkRegist = REGIST_WIFI;
501 } else if (m_networkRegist== REGIST_CELLULAR) {
502 m_networkRegist = REGIST_ALL;
506 case WATCH_TYPE_CELLULARNETWORK:
507 if ((m_EventMgrPtr->getEventCellularNetworkList()).size() == 1) {
508 vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, CellularNetworkValueCallback, (void *)this);
509 vconf_notify_key_changed(VCONFKEY_TELEPHONY_CELLID, CellularNetworkValueCallback, (void *)this);
510 vconf_notify_key_changed(VCONFKEY_TELEPHONY_LAC, CellularNetworkValueCallback, (void *)this);
511 vconf_notify_key_changed(VCONFKEY_TELEPHONY_SVC_ROAM, CellularNetworkValueCallback, (void *)this);
512 if (m_networkRegist == REGIST_NOT) {
513 connection_set_ip_address_changed_cb(m_connectionHandle, NetworkValueCallback, (void *)this);
514 m_networkRegist = REGIST_CELLULAR;
515 } else if (m_networkRegist== REGIST_WIFI) {
516 m_networkRegist = REGIST_ALL;
520 case WATCH_TYPE_STORAGE:
521 if ((m_EventMgrPtr->getEventStorageList()).size() == 1) {
522 if (!m_storageTimer) {
523 m_storageTimer = ecore_timer_add(1, StorageValueCallback, this);
524 ecore_timer_thaw(m_storageTimer);
529 if ((m_EventMgrPtr->getEventCpuList()).size() == 1) {
531 m_cpuTimer = ecore_timer_add(1, CpuValueCallback, this);
532 ecore_timer_thaw(m_cpuTimer);
536 case WATCH_TYPE_DEVICE_ORIENTATION:
537 LoggerD("regist sensor");
538 if ((m_EventMgrPtr->getEventDeviceOrientationList()).size() == 1) {
539 int state = sf_register_event(m_sensorHandle, ACCELEROMETER_EVENT_ROTATION_CHECK, NULL, OrientationValueCallback, (void *)this);
541 LoggerD("sensor_register_cb fail to gather data");
542 } else if (state == 0) {
543 LoggerD("sensor_register_cb success to gather data");
546 LoggerD("already regist");
549 case WATCH_TYPE_LOCALE:
550 if ((m_EventMgrPtr->getEventLocaleList()).size() == 1) {
551 if (runtime_info_set_changed_cb(RUNTIME_INFO_KEY_REGION, localeChangedCallback, (void *)this) != RUNTIME_INFO_ERROR_NONE) {
552 LoggerE("regist failed");
553 Throw(WrtDeviceApis::Commons::Exception);
555 if (runtime_info_set_changed_cb(RUNTIME_INFO_KEY_LANGUAGE, localeChangedCallback, (void *)this) != RUNTIME_INFO_ERROR_NONE) {
556 LoggerE("regist failed");
557 Throw(WrtDeviceApis::Commons::Exception);
561 case WATCH_TYPE_PERIPHERAL:
562 if ((m_EventMgrPtr->getEventPeripheralList()).size() == 1) {
563 vconf_notify_key_changed(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, PeripheralValueCallback, (void *)this);
564 vconf_notify_key_changed(VCONFKEY_SYSMAN_HDMI, PeripheralValueCallback, (void *)this);
568 event->processGetValue();
572 ////////////////////////////////////////////////////////////////////////////////////////
574 Systeminfo::EventMgr::EventMgr()
578 Systeminfo::EventMgr::~EventMgr()
582 void Systeminfo::EventMgr::clearAllEvent()
584 DPL::Mutex::ScopedLock lock(&m_synchro);
586 while (!m_eventBatteryList.empty()) {
587 EventWatchSysteminfoPtr event = m_eventBatteryList.front();
588 LoggerD("removing EventId=" << event->getId());
590 m_eventBatteryList.pop_front();
592 while (!m_eventDisplayList.empty()) {
593 EventWatchSysteminfoPtr event = m_eventDisplayList.front();
594 LoggerD("removing EventId=" << event->getId());
596 m_eventDisplayList.pop_front();
598 while (!m_eventWifiNetworkList.empty()) {
599 EventWatchSysteminfoPtr event = m_eventWifiNetworkList.front();
600 LoggerD("removing EventId=" << event->getId());
602 m_eventWifiNetworkList.pop_front();
604 while (!m_eventCelluarNetworkList.empty()) {
605 EventWatchSysteminfoPtr event = m_eventCelluarNetworkList.front();
606 LoggerD("removing EventId=" << event->getId());
608 m_eventCelluarNetworkList.pop_front();
610 while (!m_eventStorageList.empty()) {
611 EventWatchSysteminfoPtr event = m_eventStorageList.front();
612 LoggerD("removing EventId=" << event->getId());
614 m_eventStorageList.pop_front();
616 while (!m_eventCpuList.empty()) {
617 EventWatchSysteminfoPtr event = m_eventCpuList.front();
618 LoggerD("removing EventId=" << event->getId());
620 m_eventCpuList.pop_front();
622 while (!m_eventSimList.empty()) {
623 EventWatchSysteminfoPtr event = m_eventSimList.front();
624 LoggerD("removing EventId=" << event->getId());
626 m_eventSimList.pop_front();
628 while (!m_eventDeviceOrientationList.empty()) {
629 EventWatchSysteminfoPtr event = m_eventDeviceOrientationList.front();
630 LoggerD("removing EventId=" << event->getId());
632 m_eventDeviceOrientationList.pop_front();
634 while (!m_eventLocaleList.empty()) {
635 EventWatchSysteminfoPtr event = m_eventLocaleList.front();
636 LoggerD("removing EventId=" << event->getId());
638 m_eventLocaleList.pop_front();
640 while (!m_eventPeripheralList.empty()) {
641 EventWatchSysteminfoPtr event = m_eventPeripheralList.front();
642 LoggerD("removing EventId=" << event->getId());
644 m_eventPeripheralList.pop_front();
648 void Systeminfo::EventMgr::addEvent(const EventWatchSysteminfoPtr& arg, const int watchType)
650 DPL::Mutex::ScopedLock lock(&m_synchro);
652 if (watchType == WATCH_TYPE_BATTERY){
653 m_eventBatteryList.push_back(arg);
654 LoggerD("Event Battery list size=" << m_eventBatteryList.size());
655 } else if (watchType == WATCH_TYPE_DISPLAY) {
656 m_eventDisplayList.push_back(arg);
657 LoggerD("Event display list size=" << m_eventDisplayList.size());
658 } else if (watchType == WATCH_TYPE_WIFINETWORK) {
659 m_eventWifiNetworkList.push_back(arg);
660 LoggerD("Event wifi network list size=" << m_eventWifiNetworkList.size());
661 } else if (watchType == WATCH_TYPE_CELLULARNETWORK) {
662 m_eventCelluarNetworkList.push_back(arg);
663 LoggerD("Event cellular network list size=" << m_eventCelluarNetworkList.size());
664 } else if (watchType == WATCH_TYPE_STORAGE) {
665 m_eventStorageList.push_back(arg);
666 LoggerD("Event storage list size=" << m_eventStorageList.size());
667 } else if (watchType == WATCH_TYPE_CPU) {
668 m_eventCpuList.push_back(arg);
669 LoggerD("Event cpu list size=" << m_eventCpuList.size());
670 } else if (watchType == WATCH_TYPE_SIM) {
671 m_eventSimList.push_back(arg);
672 LoggerD("Event sim list size=" << m_eventSimList.size());
673 } else if (watchType == WATCH_TYPE_DEVICE_ORIENTATION) {
674 m_eventDeviceOrientationList.push_back(arg);
675 LoggerD("Event device orientation list size=" << m_eventDeviceOrientationList.size());
676 } else if (watchType == WATCH_TYPE_NETWORK) {
677 m_eventNetworkList.push_back(arg);
678 LoggerD("Event network list size=" << m_eventNetworkList.size());
679 } else if (watchType == WATCH_TYPE_LOCALE) {
680 m_eventLocaleList.push_back(arg);
681 LoggerD("Event Locale list size=" << m_eventLocaleList.size());
682 } else if (watchType == WATCH_TYPE_PERIPHERAL) {
683 m_eventPeripheralList.push_back(arg);
684 LoggerD("Event peripheral list size=" << m_eventPeripheralList.size());
688 void Systeminfo::EventMgr::removeEvent(WatchId id, const int watchType)
690 DPL::Mutex::ScopedLock lock(&m_synchro);
691 LoggerD("Event id : " << id);
693 EventWatchSysteminfoPtr event(NULL);
695 LoggerD("trying to delete event, id=" << id);
697 if (watchType == WATCH_TYPE_BATTERY) {
698 for (EventBatteryList::iterator it = m_eventBatteryList.begin(); it != m_eventBatteryList.end(); it++) {
699 if (id == (*it)->getId()) {
705 LoggerE("event id not in the list, nothing to do");
709 LoggerD("event Battery list size=" << m_eventBatteryList.size());
710 m_eventBatteryList.remove(event);
711 LoggerD( "event removed, event Battery list size=" << m_eventBatteryList.size());
712 } else if (watchType == WATCH_TYPE_DISPLAY) {
713 for (EventDisplayList::iterator it = m_eventDisplayList.begin(); it != m_eventDisplayList.end(); it++) {
714 if (id == (*it)->getId()) {
720 LoggerE("event id not in the list, nothing to do");
724 LoggerD("event display list size=" << m_eventDisplayList.size());
725 m_eventDisplayList.remove(event);
726 LoggerD( "event removed, event display list size=" << m_eventDisplayList.size());
727 } else if (watchType == WATCH_TYPE_WIFINETWORK) {
728 for (EventWifiNetworkList::iterator it = m_eventWifiNetworkList.begin(); it != m_eventWifiNetworkList.end(); it++) {
729 if (id == (*it)->getId()) {
735 LoggerE("event id not in the list, nothing to do");
739 LoggerD("event wifi network list size=" << m_eventWifiNetworkList.size());
740 m_eventWifiNetworkList.remove(event);
741 LoggerD( "event removed, event wifi network list size=" << m_eventCelluarNetworkList.size());
742 } else if (watchType == WATCH_TYPE_CELLULARNETWORK) {
743 for (EventCellularNetworkList::iterator it = m_eventCelluarNetworkList.begin(); it != m_eventCelluarNetworkList.end(); it++) {
744 if (id == (*it)->getId()) {
750 LoggerE("event id not in the list, nothing to do");
754 LoggerD("event cellular network list size=" << m_eventCelluarNetworkList.size());
755 m_eventCelluarNetworkList.remove(event);
756 LoggerD( "event removed, event cellular network list size=" << m_eventCelluarNetworkList.size());
757 } else if (watchType == WATCH_TYPE_STORAGE) {
758 for (EventStorageList::iterator it = m_eventStorageList.begin(); it != m_eventStorageList.end(); it++) {
759 if (id == (*it)->getId()) {
765 LoggerE("event id not in the list, nothing to do");
769 LoggerD("event storage list size=" << m_eventStorageList.size());
770 m_eventStorageList.remove(event);
771 LoggerD( "event removed, event storage list size=" << m_eventStorageList.size());
772 } else if (watchType == WATCH_TYPE_CPU) {
773 for (EventCpuList::iterator it = m_eventCpuList.begin(); it != m_eventCpuList.end(); it++) {
774 if (id == (*it)->getId()) {
780 LoggerE("event id not in the list, nothing to do");
784 LoggerD("event cpu list size=" << m_eventCpuList.size());
785 m_eventCpuList.remove(event);
786 LoggerD( "event removed, event cpu list size=" << m_eventCpuList.size());
787 } else if (watchType == WATCH_TYPE_SIM) {
788 for (EventSimList::iterator it = m_eventSimList.begin(); it != m_eventSimList.end(); it++) {
789 if (id == (*it)->getId()) {
795 LoggerE("event id not in the list, nothing to do");
799 LoggerD("event sim list size=" << m_eventSimList.size());
800 m_eventSimList.remove(event);
801 LoggerD( "event removed, event sim list size=" << m_eventSimList.size());
802 } else if (watchType == WATCH_TYPE_DEVICE_ORIENTATION) {
803 for (EventDeviceOrientationList::iterator it = m_eventDeviceOrientationList.begin(); it != m_eventDeviceOrientationList.end(); it++) {
804 if (id == (*it)->getId()) {
810 LoggerE("event id not in the list, nothing to do");
814 LoggerD("event device orientation list size=" << m_eventDeviceOrientationList.size());
815 m_eventDeviceOrientationList.remove(event);
816 LoggerD( "event removed, event device orientation list size=" << m_eventDeviceOrientationList.size());
817 } else if (watchType == WATCH_TYPE_NETWORK) {
818 for (EventNetworkList::iterator it = m_eventNetworkList.begin(); it != m_eventNetworkList.end(); it++) {
819 if (id == (*it)->getId()) {
825 LoggerE("event id not in the list, nothing to do");
829 LoggerD("event network list size=" << m_eventNetworkList.size());
830 m_eventNetworkList.remove(event);
831 LoggerD( "event removed, event network list size=" << m_eventNetworkList.size());
832 } else if (watchType == WATCH_TYPE_LOCALE) {
833 for (EventLocaleList::iterator it = m_eventLocaleList.begin(); it != m_eventLocaleList.end(); it++) {
834 if (id == (*it)->getId()) {
840 LoggerE("event id not in the list, nothing to do");
844 LoggerD("event Locale list size=" << m_eventLocaleList.size());
845 m_eventLocaleList.remove(event);
846 LoggerD( "event removed, event Locale list size=" << m_eventLocaleList.size());
847 } else if (watchType == WATCH_TYPE_PERIPHERAL) {
848 for (EventPeripheralList::iterator it = m_eventPeripheralList.begin(); it != m_eventPeripheralList.end(); it++) {
849 if (id == (*it)->getId()) {
855 LoggerE("event id not in the list, nothing to do");
859 LoggerD("event peripheral list size=" << m_eventPeripheralList.size());
860 m_eventPeripheralList.remove(event);
861 LoggerD( "event removed, event peripheral list size=" << m_eventPeripheralList.size());
865 const int Systeminfo::EventMgr::getWatchType(const long id)
867 DPL::Mutex::ScopedLock lock(&m_synchro);
869 EventWatchSysteminfoPtr event(NULL);
871 for (EventBatteryList::iterator it = m_eventBatteryList.begin(); it != m_eventBatteryList.end(); it++) {
872 if (id == (*it)->getId()) {
878 for (EventDisplayList::iterator it = m_eventDisplayList.begin(); it != m_eventDisplayList.end(); it++) {
879 if (id == (*it)->getId()) {
885 for (EventWifiNetworkList::iterator it = m_eventWifiNetworkList.begin(); it != m_eventWifiNetworkList.end(); it++) {
886 if (id == (*it)->getId()) {
892 for (EventCellularNetworkList::iterator it = m_eventCelluarNetworkList.begin(); it != m_eventCelluarNetworkList.end(); it++) {
893 if (id == (*it)->getId()) {
899 for (EventStorageList::iterator it = m_eventStorageList.begin(); it != m_eventStorageList.end(); it++) {
900 if (id == (*it)->getId()) {
906 for (EventCpuList::iterator it = m_eventCpuList.begin(); it != m_eventCpuList.end(); it++) {
907 if (id == (*it)->getId()) {
913 for (EventSimList::iterator it = m_eventSimList.begin(); it != m_eventSimList.end(); it++) {
914 if (id == (*it)->getId()) {
920 for (EventDeviceOrientationList::iterator it = m_eventDeviceOrientationList.begin(); it != m_eventDeviceOrientationList.end(); it++) {
921 if (id == (*it)->getId()) {
927 for (EventNetworkList::iterator it = m_eventNetworkList.begin(); it != m_eventNetworkList.end(); it++) {
928 if (id == (*it)->getId()) {
934 for (EventSimList::iterator it = m_eventSimList.begin(); it != m_eventSimList.end(); it++) {
935 if (id == (*it)->getId()) {
941 for (EventLocaleList::iterator it = m_eventLocaleList.begin(); it != m_eventLocaleList.end(); it++) {
942 if (id == (*it)->getId()) {
948 for (EventPeripheralList::iterator it = m_eventPeripheralList.begin(); it != m_eventPeripheralList.end(); it++) {
949 if (id == (*it)->getId()) {
956 LoggerE("event id not in the list, nothing to do");
957 return WATCH_TYPE_UNKNOWN;
960 return event->getWatchType();
963 EventBatteryList Systeminfo::EventMgr::getEventBatteryList()
965 return m_eventBatteryList;
968 EventDisplayList Systeminfo::EventMgr::getEventDisplayList()
970 return m_eventDisplayList;
973 EventNetworkList Systeminfo::EventMgr::getEventNetworkList()
975 return m_eventNetworkList;
978 EventWifiNetworkList Systeminfo::EventMgr::getEventWifiNetworkList()
980 return m_eventWifiNetworkList;
983 EventCellularNetworkList Systeminfo::EventMgr::getEventCellularNetworkList()
985 return m_eventCelluarNetworkList;
988 EventStorageList Systeminfo::EventMgr::getEventStorageList()
990 return m_eventStorageList;
993 EventCpuList Systeminfo::EventMgr::getEventCpuList()
995 return m_eventCpuList;
998 EventDeviceOrientationList Systeminfo::EventMgr::getEventDeviceOrientationList()
1000 return m_eventDeviceOrientationList;
1003 EventSimList Systeminfo::EventMgr::getEventSimList()
1005 return m_eventSimList;
1008 EventLocaleList Systeminfo::EventMgr::getEventLocaleList()
1010 return m_eventLocaleList;
1013 EventPeripheralList Systeminfo::EventMgr::getEventPeripheralList()
1015 return m_eventPeripheralList;
1018 ////////////////////////////////////////////////////////////////////////////////////////
1020 PROPERTY_GET_SYSTEMINFO_DEFINITION(Battery) {
1021 BatteryPropertiesPtr BatteryPtr(new BatteryProperties());
1025 if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, &value) != 0) {
1026 return JSValueMakeNull(context);
1028 BatteryPtr->level = (double)(value)/CPU_POWER_DEVICE_VALUE;
1031 if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &value2) != 0) {
1032 return JSValueMakeNull(context);
1034 BatteryPtr->isCharging = (value2 == 0) ? false : true;
1037 return JSBatteryInfo::createJSObject(context, BatteryPtr);
1040 PROPERTY_GET_SYSTEMINFO_DEFINITION(Cpu) {
1041 Converter converter(context);
1043 CpuPropertiesPtr cpuPtr(new CpuProperties());
1045 long long usr = 0, nice = 0, system = 0, idle = 0, total = 0, cpuUsage = 0;
1047 fp = fopen("/proc/stat", "r");
1049 return JSValueMakeNull(context);
1052 if (fscanf(fp, "%*s %lld %lld %lld %lld", &usr, &system, &nice, &idle) > 0) {
1053 total = usr + nice + system + idle;
1054 if ((total > 0LL) && (idle > 0LL)) {
1055 cpuUsage = idle * 100LL / total;
1056 cpuPtr->load = (double)cpuUsage / 100.0;
1057 LoggerD("cpu load : " << cpuPtr->load);
1062 return JSCpuInfo::createJSObject(context, cpuPtr);
1065 PROPERTY_GET_SYSTEMINFO_DEFINITION(Storage) {
1066 Converter converter(context);
1071 StoragePropertiesPtr internal(new StorageProperties());
1072 StoragePropertiesPtr mmc(new StorageProperties());
1073 StoragePropertiesPtr usbhost(new StorageProperties());
1074 std::vector <JSObjectRef> storagelist;
1076 if (statfs(STORAGE_INTERNAL_PATH, &fs) < 0) {
1077 return JSValueMakeNull(context);
1080 internal->type = "INTERNAL";
1081 internal->capacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_blocks;
1082 internal->availableCapacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_bavail;
1083 internal->isRemoveable = false;
1084 internal->isRemovable = false;
1085 storagelist.push_back(JSStorageInfo::createJSObject(context, internal));
1088 if(vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &sdcardState) == 0){
1089 if(sdcardState == VCONFKEY_SYSMAN_MMC_MOUNTED){
1091 if (statfs(STORAGE_SDCARD_PATH, &fs) < 0) {
1092 return JSValueMakeNull(context);
1095 mmc->capacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_blocks;
1096 mmc->availableCapacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_bavail;
1097 mmc->isRemoveable = true;
1098 mmc->isRemovable = true;
1099 storagelist.push_back(JSStorageInfo::createJSObject(context, mmc));
1103 if(vconf_get_int(VCONFKEY_SYSMAN_USB_HOST_STATUS, &usbhostState) == 0) {
1104 if(usbhostState == VCONFKEY_SYSMAN_USB_HOST_CONNECTED) {
1106 if (statfs(STORAGE_USBHOST_PATH, &fs) < 0) {
1107 return JSValueMakeNull(context);
1109 usbhost->type = "USB_HOST";
1110 usbhost->capacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_blocks;
1111 usbhost->availableCapacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_bavail;
1112 usbhost->isRemoveable = true;
1113 usbhost->isRemovable = true;
1114 storagelist.push_back(JSStorageInfo::createJSObject(context, usbhost));
1118 return JSObjectMakeArray(context, storageCnt, storagelist.data(), NULL);
1121 PROPERTY_GET_SYSTEMINFO_DEFINITION(Display) {
1122 Converter converter(context);
1124 DisplayPropertiesPtr display(new DisplayProperties());
1125 int brightness=0, dotsPerInchX=0, dotsPerInchY=0, physicalW=0, physicalH=0, resolutionW=0, resolutionH=0;
1127 if(vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, &brightness) == 0) {
1128 display->brightness = (double)(brightness)/DISPLAY_BRIGHTNESS_DIVIDE_VALUE;
1129 LoggerD("brightness : " << display->brightness);
1132 if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_WIDTH, &resolutionW) == SYSTEM_INFO_ERROR_NONE) {
1133 display->resolutionWidth = resolutionW;
1134 LoggerD("resolutionWidth : " << display->resolutionWidth);
1136 if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_HEIGHT, &resolutionH) == SYSTEM_INFO_ERROR_NONE) {
1137 display->resolutionHeight = resolutionH;
1138 LoggerD("resolutionHeight : " << display->resolutionHeight);
1140 if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_DPI, &dotsPerInchX) == SYSTEM_INFO_ERROR_NONE) {
1141 display->dotsPerInchWidth = dotsPerInchX;
1142 LoggerD("dotsPerInchWidth : " << display->dotsPerInchWidth);
1144 if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_DPI, &dotsPerInchY) == SYSTEM_INFO_ERROR_NONE) {
1145 display->dotsPerInchHeight = dotsPerInchY;
1146 LoggerD("dotsPerInchHeight : " << display->dotsPerInchHeight);
1148 if (system_info_get_value_int(SYSTEM_INFO_KEY_PHYSICAL_SCREEN_HEIGHT, &physicalH) == SYSTEM_INFO_ERROR_NONE) {
1149 display->physicalHeight = physicalH;
1150 LoggerD("physicalHeight : " << display->physicalHeight);
1152 if (system_info_get_value_int(SYSTEM_INFO_KEY_PHYSICAL_SCREEN_WIDTH, &physicalW) == SYSTEM_INFO_ERROR_NONE) {
1153 display->physicalWidth = physicalW;
1154 LoggerD("physicalWidth : " << display->physicalWidth);
1157 return JSDisplayInfo::createJSObject(context, display);
1160 PROPERTY_GET_SYSTEMINFO_DEFINITION(Network) {
1162 Converter converter(context);
1163 NetworkPropertiesPtr Network(new NetworkProperties());
1164 connection_h connectionHandle = (connection_h)handle;
1165 connection_type_e connectionType;
1166 int networkType = 0;
1168 if (connection_get_type(connectionHandle, &connectionType) != CONNECTION_ERROR_NONE) {
1169 LoggerD("get connection type is failed");
1170 return JSNetworkInfo::createJSObject(context, Network);
1173 if (connectionType == CONNECTION_TYPE_WIFI) {
1174 LoggerD("wifi network");
1175 Network->networkType= "WIFI";
1176 } else if (connectionType == CONNECTION_TYPE_CELLULAR) {
1177 if (vconf_get_int(VCONFKEY_TELEPHONY_SVCTYPE, &networkType) == 0) {
1178 if (networkType < VCONFKEY_TELEPHONY_SVCTYPE_2G) {
1179 Network->networkType= "NONE";
1180 } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_2G) {
1181 Network->networkType= "2G";
1182 } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_2G || networkType == VCONFKEY_TELEPHONY_SVCTYPE_2_5G_EDGE) {
1183 Network->networkType= "2.5";
1184 } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_3G || networkType == VCONFKEY_TELEPHONY_SVCTYPE_HSDPA) {
1185 Network->networkType= "3G";
1186 } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_LTE) {
1187 Network->networkType= "4G";
1189 Network->networkType= "NONE";
1193 Network->networkType= "NONE";
1196 return JSNetworkInfo::createJSObject(context, Network);
1199 PROPERTY_GET_SYSTEMINFO_DEFINITION(WifiNetwork) {
1200 Converter converter(context);
1201 WifiNetworkPropertiesPtr wifiNetwork(new WifiNetworkProperties());
1202 connection_h connectionHandle = (connection_h)handle;
1203 connection_type_e connectionType;
1204 connection_profile_h profileHandle = NULL;
1205 connection_address_family_e addressFamily = CONNECTION_ADDRESS_FAMILY_IPV4;
1206 char* ipAddr = NULL;
1210 if (connection_get_type(connectionHandle, &connectionType) != CONNECTION_ERROR_NONE) {
1211 return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1214 if (connectionType == CONNECTION_TYPE_WIFI) {
1215 wifiNetwork->status = "ON";
1217 wifiNetwork->status = "OFF";
1218 return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1221 if (connection_get_current_profile(connectionHandle, &profileHandle) != CONNECTION_ERROR_NONE) {
1222 return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1225 if (connection_profile_get_wifi_essid(profileHandle, &essid) == CONNECTION_ERROR_NONE) {
1226 wifiNetwork->ssid = essid;
1230 if (connection_profile_get_ip_address(profileHandle, addressFamily, &ipAddr) == CONNECTION_ERROR_NONE) {
1231 wifiNetwork->ipAddress = ipAddr;
1235 if (connection_profile_get_wifi_rssi(profileHandle, &rssi) == CONNECTION_ERROR_NONE) {
1236 wifiNetwork->signalStrength = (double) rssi/WIFI_SIGNAL_STRENGTH_DIVIDE_VALUE;
1239 return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1242 PROPERTY_GET_SYSTEMINFO_DEFINITION(CellularNetwork) {
1243 Converter converter(context);
1244 CellularNetworkPropertiesPtr cellularNetwork(new CellularNetworkProperties());
1245 connection_h connectionHandle = (connection_h)handle;
1246 connection_type_e connectionType;
1247 connection_profile_h profileHandle = NULL;
1248 connection_address_family_e addressFamily = CONNECTION_ADDRESS_FAMILY_IPV4;
1249 char* ipAddr = NULL;
1252 int plmn = 0, cellId = 0, lac = 0, isRoaming = 0, isFlightMode = 0;
1253 TapiHandle *tapiHandle = NULL;
1255 TIME_TRACER_ITEM_BEGIN("(cellular)mcc", 0);
1256 if (vconf_get_int(VCONFKEY_TELEPHONY_PLMN, &plmn) == 0) {
1257 cellularNetwork->mcc = plmn / 100;
1258 cellularNetwork->mnc = plmn % 100;
1260 TIME_TRACER_ITEM_END("(cellular)mcc", 0);
1262 TIME_TRACER_ITEM_BEGIN("(cellular)cellId", 0);
1263 if (vconf_get_int(VCONFKEY_TELEPHONY_CELLID, &cellId) == 0) {
1264 cellularNetwork->cellId = cellId;
1266 TIME_TRACER_ITEM_END("(cellular)cellId", 0);
1268 TIME_TRACER_ITEM_BEGIN("(cellular)lac", 0);
1269 if (vconf_get_int(VCONFKEY_TELEPHONY_LAC, &lac) == 0) {
1270 cellularNetwork->lac = lac;
1272 TIME_TRACER_ITEM_END("(cellular)lac", 0);
1274 TIME_TRACER_ITEM_BEGIN("(cellular)isRoaming", 0);
1275 if (vconf_get_int(VCONFKEY_TELEPHONY_SVC_ROAM, &isRoaming) == 0) {
1277 cellularNetwork->isRoaming = true;
1279 cellularNetwork->isRoaming = false;
1282 TIME_TRACER_ITEM_END("(cellular)isRoaming", 0);
1284 TIME_TRACER_ITEM_BEGIN("(cellular)isFlightMode", 0);
1285 if (vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &isFlightMode) == 0) {
1287 cellularNetwork->isFlightMode = true;
1289 cellularNetwork->isFlightMode = false;
1292 TIME_TRACER_ITEM_END("(cellular)isFlightMode", 0);
1294 if (connection_get_type(connectionHandle, &connectionType) != CONNECTION_ERROR_NONE) {
1295 return JSCellularNetworkInfo::createJSObject(context, cellularNetwork);
1298 if (connectionType == CONNECTION_TYPE_CELLULAR) {
1299 cellularNetwork->status = "ON";
1300 if (connection_get_current_profile(connectionHandle, &profileHandle) == CONNECTION_ERROR_NONE) {
1301 TIME_TRACER_ITEM_BEGIN("(cellular)apn", 0);
1302 if (connection_profile_get_cellular_apn(profileHandle, &apn) == CONNECTION_ERROR_NONE) {
1303 cellularNetwork->apn = apn;
1306 TIME_TRACER_ITEM_END("(cellular)apn", 0);
1308 TIME_TRACER_ITEM_BEGIN("(cellular)ipAddress", 0);
1309 if (connection_profile_get_ip_address(profileHandle, addressFamily, &ipAddr) == CONNECTION_ERROR_NONE) {
1310 cellularNetwork->ipAddress = ipAddr;
1313 TIME_TRACER_ITEM_END("(cellular)ipAddress", 0);
1314 connection_profile_destroy(profileHandle);
1317 cellularNetwork->status = "OFF";
1318 if (connection_get_default_cellular_service_profile(connectionHandle, CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET, &profileHandle) == CONNECTION_ERROR_NONE) {
1319 TIME_TRACER_ITEM_BEGIN("(cellular)apn", 0);
1320 if (connection_profile_get_cellular_apn(profileHandle, &apn) == CONNECTION_ERROR_NONE) {
1321 cellularNetwork->apn = apn;
1324 TIME_TRACER_ITEM_END("(cellular)apn", 0);
1325 connection_profile_destroy(profileHandle);
1329 tapiHandle = tel_init(0);
1331 if (tapiHandle != NULL) {
1332 imei = tel_get_misc_me_imei_sync(tapiHandle);
1335 tel_deinit(tapiHandle);
1336 return JSCellularNetworkInfo::createJSObject(context, cellularNetwork);
1339 cellularNetwork->imei = imei;
1341 tel_deinit(tapiHandle);
1344 return JSCellularNetworkInfo::createJSObject(context, cellularNetwork);
1347 PROPERTY_GET_SYSTEMINFO_DEFINITION(SIM) {
1348 Converter converter(context);
1349 SIMPropertiesPtr SIM(new SIMProperties());
1352 char* fullName = NULL;
1353 char* shortName = NULL;
1354 char* msisdn = NULL;
1360 int ret = SIM_ERROR_NONE;
1362 ret = sim_get_state(&state);
1363 if (ret == SIM_ERROR_NONE) {
1364 if (state == SIM_STATE_UNAVAILABLE) {
1365 SIM->state = "ABSENT";
1366 } else if (state == SIM_STATE_LOCKED) {
1367 SIM->state = "PIN_REQUIRED";
1368 } else if (state == SIM_STATE_AVAILABLE) {
1369 SIM->state = "READY";
1370 } else if (state == SIM_STATE_UNKNOWN) {
1371 SIM->state = "INITIALIZING";
1375 ret = sim_get_cphs_operator_name(&fullName, &shortName);
1376 if (ret == SIM_ERROR_NONE) {
1378 SIM->operatorName = fullName;
1379 LoggerD("operatorName : " << SIM->operatorName);
1381 } else if (shortName) {
1382 SIM->operatorName = shortName;
1383 LoggerD("operatorName : " << SIM->operatorName);
1389 ret = sim_get_subscriber_number(&msisdn);
1390 if (ret == SIM_ERROR_NONE) {
1392 SIM->msisdn = msisdn;
1393 LoggerD("msisdn : " << SIM->msisdn);
1398 ret = sim_get_icc_id(&iccId);
1399 if (ret == SIM_ERROR_NONE) {
1402 LoggerD("iccid : " << SIM->iccid);
1407 ret = sim_get_mcc(&mcc);
1408 if (ret == SIM_ERROR_NONE) {
1410 SIM->mcc = atoi(mcc);
1411 LoggerD("mcc : " << SIM->mcc);
1416 ret = sim_get_mnc(&mnc);
1417 if (ret == SIM_ERROR_NONE) {
1419 SIM->mnc = atoi(mnc);
1420 LoggerD("mnc : " << SIM->mnc);
1425 ret = sim_get_msin(&msin);
1426 if (ret == SIM_ERROR_NONE) {
1429 LoggerD("msin : " << SIM->msin);
1434 ret = sim_get_spn(&spn);
1435 if (ret == SIM_ERROR_NONE) {
1438 LoggerD("spn : " << SIM->spn);
1443 return JSSIMInfo::createJSObject(context, SIM);
1446 PROPERTY_GET_SYSTEMINFO_DEFINITION(DeviceOrientation) {
1448 Converter converter(context);
1449 DeviceOrientationPropertiesPtr deviceOrientation(new DeviceOrientationProperties());
1451 unsigned long rotation = 0;
1452 int handleOrientaion = 0;
1454 handleOrientaion = sf_connect(ACCELEROMETER_SENSOR);
1455 LoggerD("handleOrientaion : " << handleOrientaion);
1456 if (handleOrientaion < 0) {
1457 LoggerD ("sensor attach fail");
1458 return JSDeviceOrientationInfo::createJSObject(context, deviceOrientation);
1460 int state = sf_start(handleOrientaion, 0);
1462 LoggerD("start failed");
1465 int ret_val = sf_check_rotation(&rotation);
1467 LoggerD("sf_check_rotation fail to gather data\n");
1470 LoggerD(" rotation value = " << rotation);
1474 case ROTATION_EVENT_0:
1475 LoggerD("my_callback_func received data (PORTRAIT_TOP|HEAD_CENTER)\n");
1476 deviceOrientation->status = "PORTRAIT_PRIMARY";
1478 case ROTATION_EVENT_90:
1479 LoggerD("my_callback_func received data (LANDSCAPE|HEAD_RIGHT)\n");
1480 deviceOrientation->status = "LANDSCAPE_PRIMARY";
1482 case ROTATION_EVENT_180:
1483 LoggerD("my_callback_func received data (PORTRAIT_BTM|HEAD_CENTER)\n");
1484 deviceOrientation->status = "PORTRAIT_SECONDARY";
1486 case ROTATION_EVENT_270:
1487 LoggerD("my_callback_func received data (LANDSCAPE|HEAD_LEFT)\n");
1488 deviceOrientation->status = "LANDSCAPE_SECONDARY";
1491 LoggerD(" received data unexpected\n");
1495 state = sf_stop(handleOrientaion);
1496 LoggerD("handleOrientaion 1 state = " << state);
1498 state = sf_disconnect(handleOrientaion);
1499 LoggerD("handleOrientaion state =" << state);
1501 return JSDeviceOrientationInfo::createJSObject(context, deviceOrientation);
1504 PROPERTY_GET_SYSTEMINFO_DEFINITION(Build) {
1506 Converter converter(context);
1507 BuildPropertiesPtr Build(new BuildProperties());
1510 char* manufacturer = NULL;
1511 char* buildVersion = NULL;
1513 if (system_info_get_value_string(SYSTEM_INFO_KEY_MODEL, &model) == SYSTEM_INFO_ERROR_NONE) {
1514 if (model != NULL) {
1515 LoggerD("model : " << model);
1516 Build->model = model;
1521 if (system_info_get_value_string(SYSTEM_INFO_KEY_MANUFACTURER, &manufacturer) == SYSTEM_INFO_ERROR_NONE) {
1522 if (manufacturer != NULL) {
1523 LoggerD("manufacturer : " << manufacturer);
1524 Build->manufacturer = manufacturer;
1529 if (system_info_get_value_string(SYSTEM_INFO_KEY_BUILD_STRING, &buildVersion) == SYSTEM_INFO_ERROR_NONE) {
1530 if (buildVersion != NULL) {
1531 LoggerD("buildVersion : " << buildVersion);
1532 Build->buildVersion = buildVersion;
1537 return JSBuildInfo::createJSObject(context, Build);
1540 PROPERTY_GET_SYSTEMINFO_DEFINITION(Locale) {
1542 Converter converter(context);
1543 LocalePropertiesPtr Locale(new LocaleProperties());
1545 char* country = NULL;
1546 char* language = NULL;
1548 if (runtime_info_get_value_string(RUNTIME_INFO_KEY_LANGUAGE, &language) == RUNTIME_INFO_ERROR_NONE) {
1549 if (language != NULL) {
1550 LoggerD("language : " << language);
1551 Locale->language = language;
1556 if (runtime_info_get_value_string(RUNTIME_INFO_KEY_REGION, &country) == RUNTIME_INFO_ERROR_NONE) {
1557 if (country != NULL) {
1558 LoggerD("country : " << country);
1560 char* countryTemp = NULL;
1561 token = strtok(country, ".");
1562 if (token != NULL) {
1563 countryTemp = strdup(token);
1564 if (countryTemp != NULL) {
1565 Locale->country = countryTemp;
1573 return JSLocaleInfo::createJSObject(context, Locale);
1576 PROPERTY_GET_SYSTEMINFO_DEFINITION(Peripheral) {
1577 Converter converter(context);
1578 PeripheralPropertiesPtr peripheral(new PeripheralProperties());
1579 int hdmiStatus = 0, wirelessDisplayStatus = 0 ;
1581 if (vconf_get_int(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, &wirelessDisplayStatus) == 0) {
1582 switch(wirelessDisplayStatus) {
1583 case VCONFKEY_MIRACAST_WFD_SOURCE_ON:
1584 peripheral->isVideoOutputOn = true;
1587 LoggerD("VideOutput status is off");
1592 if (vconf_get_int(VCONFKEY_SYSMAN_HDMI, &hdmiStatus) == 0) {
1593 switch(hdmiStatus) {
1594 case VCONFKEY_SYSMAN_HDMI_CONNECTED:
1595 peripheral->isVideoOutputOn = true;
1598 LoggerD("VideOutput status is off");
1603 return JSPeripheralInfo::createJSObject(context, peripheral);