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;
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 NetworkTypeValueCallback(connection_type_e type, void* event_ptr)
68 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_NETWORK);
72 void NetworkValueCallback(const char* ipv4_address, const char* ipv6_address, void* event_ptr)
75 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_NETWORK_ALL);
79 static Eina_Bool StorageValueCallback(void* event_ptr)
82 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_STORAGE);
84 return ECORE_CALLBACK_RENEW;
87 static Eina_Bool CpuValueCallback(void* event_ptr)
90 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_CPU);
92 return ECORE_CALLBACK_RENEW;
95 void OrientationValueCallback(unsigned int event_type, sensor_event_data_t *event , void *event_ptr)
99 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_DEVICE_ORIENTATION);
103 void localeChangedCallback(runtime_info_key_e key, void* event_ptr)
107 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_LOCALE);
113 #define STORAGE_INTERNAL_PATH "/opt/usr/media"
114 #define STORAGE_SDCARD_PATH "/opt/storage/sdcard"
115 #define STORAGE_USBHOST_PATH "/opt/storage/usb"
116 #define DISPLAY_BRIGHTNESS_DIVIDE_VALUE 100
117 #define WIFI_SIGNAL_STRENGTH_DIVIDE_VALUE 100
118 #define CPU_POWER_DEVICE_VALUE 100
120 #define RADIAN_VALUE (57.2957)
123 STORAGE_TYPE_UNKNOWN = 0,
124 STORAGE_TYPE_INTERNAL = 1,
125 STORAGE_TYPE_MMC = 2,
126 STORAGE_TYPE_USBHOST = 3
129 Systeminfo::OptionalProperty Systeminfo::m_Property;
131 Systeminfo::Systeminfo() : m_networkRegist(REGIST_NOT),
132 m_storageTimer(NULL),
135 m_connectionHandle(NULL)
137 EventMgrPtr eventMgrPtr(new EventMgr());
138 m_EventMgrPtr = eventMgrPtr;
139 if (m_Property.IsNull()) {
140 mapProperties properties;
141 properties["BATTERY"] = BasePropertyPtr(new Battery());
142 m_Property = properties;
143 (*m_Property)["CPU"] = BasePropertyPtr(new Cpu());
144 (*m_Property)["STORAGE"] = BasePropertyPtr(new Storage());
145 (*m_Property)["DISPLAY"] = BasePropertyPtr(new Display());
146 (*m_Property)["NETWORK"] = BasePropertyPtr(new Network());
147 (*m_Property)["WIFI_NETWORK"] = BasePropertyPtr(new WifiNetwork());
148 (*m_Property)["CELLULAR_NETWORK"] = BasePropertyPtr(new CellularNetwork());
149 (*m_Property)["SIM"] = BasePropertyPtr(new SIM());
150 (*m_Property)["DEVICE_ORIENTATION"] = BasePropertyPtr(new DeviceOrientation());
151 (*m_Property)["BUILD"] = BasePropertyPtr(new Build());
152 (*m_Property)["LOCALE"] = BasePropertyPtr(new Locale());
153 (*m_Property)["PERIPHERAL"] = BasePropertyPtr(new Peripheral());
156 int ret = connection_create(&m_connectionHandle);
158 if (CONNECTION_ERROR_NONE == ret) {
159 LoggerD("Network Client registration success");
161 LoggerD("Network Client registration success");
162 m_connectionHandle = NULL;
165 m_sensorHandle = sf_connect(ACCELEROMETER_SENSOR);
166 if (m_sensorHandle < 0) {
167 LoggerD ("sensor attach fail");
169 LoggerD("m_sensorHandle : " << m_sensorHandle);
170 int state = sf_start(m_sensorHandle, 0);
177 Systeminfo::~Systeminfo()
180 if (m_storageTimer) {
181 ecore_timer_freeze(m_storageTimer);
182 ecore_timer_del(m_storageTimer);
183 m_storageTimer = NULL;
186 ecore_timer_freeze(m_cpuTimer);
187 ecore_timer_del(m_cpuTimer);
190 m_EventMgrPtr->clearAllEvent();
192 if(m_connectionHandle != NULL) {
193 LoggerD("Network Client deregistration success");
194 connection_destroy(m_connectionHandle);
196 LoggerD("Network Client deregistration failed");
199 state = sf_stop(m_sensorHandle);
200 LoggerD("handle 1 state = " << state);
202 state = sf_disconnect(m_sensorHandle);
203 LoggerD("handle state =" << state);
206 DeviceCapabilitiesPropertiesPtr Systeminfo::getCapabilities()
209 DeviceCapabilitiesPropertiesPtr deviceCapabilities(new DeviceCapabilitiesProperties());
210 return deviceCapabilities;
213 void Systeminfo::get(const EventGetSysteminfoPtr& event)
215 EventRequestReceiver<EventGetSysteminfo>::PostRequest(event);
218 void Systeminfo::watch(const EventWatchSysteminfoPtr& event)
220 if(event->getWatchType() == WATCH_TYPE_UNKNOWN) {
221 LoggerD("watch method is not supported");
226 event->setSysteminfoPtr(this);
227 m_EventMgrPtr->addEvent(event, event->getWatchType());
229 EventRequestReceiver<EventWatchSysteminfo>::PostRequest(event);
232 void Systeminfo::clearWatch(const long id)
235 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
237 int watchType = m_EventMgrPtr->getWatchType(id);
239 case WATCH_TYPE_BATTERY:
240 if ((m_EventMgrPtr->getEventBatteryList()).size() == 1) {
241 vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, BatteryValueCallback);
242 vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, BatteryValueCallback);
245 case WATCH_TYPE_DISPLAY:
246 if ((m_EventMgrPtr->getEventDisplayList()).size() == 1) {
247 vconf_ignore_key_changed(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, DisplayValueCallback);
250 case WATCH_TYPE_NETWORK:
251 if ((m_EventMgrPtr->getEventNetworkList()).size() == 1) {
252 connection_unset_type_changed_cb(m_connectionHandle);
255 case WATCH_TYPE_WIFINETWORK:
256 if ((m_EventMgrPtr->getEventWifiNetworkList()).size() == 1) {
257 if (m_networkRegist == REGIST_WIFI) {
258 connection_unset_ip_address_changed_cb(m_connectionHandle);
259 m_networkRegist = REGIST_NOT;
260 } else if (m_networkRegist== REGIST_ALL) {
261 m_networkRegist = REGIST_CELLULAR;
265 case WATCH_TYPE_CELLULARNETWORK:
266 if ((m_EventMgrPtr->getEventCellularNetworkList()).size() == 1) {
267 vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, CellularNetworkValueCallback);
268 vconf_ignore_key_changed(VCONFKEY_TELEPHONY_CELLID, CellularNetworkValueCallback);
269 vconf_ignore_key_changed(VCONFKEY_TELEPHONY_LAC, CellularNetworkValueCallback);
270 if (m_networkRegist == REGIST_CELLULAR) {
271 connection_unset_ip_address_changed_cb(m_connectionHandle);
272 m_networkRegist = REGIST_NOT;
273 } else if (m_networkRegist== REGIST_ALL) {
274 m_networkRegist = REGIST_WIFI;
278 case WATCH_TYPE_STORAGE:
279 if ((m_EventMgrPtr->getEventStorageList()).size() == 1) {
280 if (m_storageTimer) {
281 ecore_timer_freeze(m_storageTimer);
282 ecore_timer_del(m_storageTimer);
283 m_storageTimer = NULL;
288 if ((m_EventMgrPtr->getEventCpuList()).size() == 1) {
290 ecore_timer_freeze(m_cpuTimer);
291 ecore_timer_del(m_cpuTimer);
296 case WATCH_TYPE_DEVICE_ORIENTATION:
297 if ((m_EventMgrPtr->getEventDeviceOrientationList()).size() == 1) {
298 int state = sf_unregister_event(m_sensorHandle, ACCELEROMETER_EVENT_ROTATION_CHECK);
300 LoggerD("sf_unregister_event fail to gather data\n");
304 case WATCH_TYPE_LOCALE:
305 if ((m_EventMgrPtr->getEventLocaleList()).size() == 1) {
306 if (runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_LANGUAGE) != RUNTIME_INFO_ERROR_NONE) {
307 LoggerE("regist failed");
308 Throw(WrtDeviceApis::Commons::Exception);
310 if (runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_REGION) != RUNTIME_INFO_ERROR_NONE) {
311 LoggerE("regist failed");
312 Throw(WrtDeviceApis::Commons::Exception);
316 case WATCH_TYPE_PERIPHERAL:
317 if ((m_EventMgrPtr->getEventPeripheralList()).size() == 1) {
318 vconf_ignore_key_changed(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, PeripheralValueCallback);
319 vconf_ignore_key_changed(VCONFKEY_SYSMAN_HDMI, PeripheralValueCallback);
322 case WATCH_TYPE_UNKNOWN:
323 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
326 m_EventMgrPtr->removeEvent(id, watchType);
330 BasePropertyPtr Systeminfo::getBasePropertyPtr(JSContextRef context, JSValueRef property)
332 Converter converter(context);
333 std::string l_property = converter.toString(property);
334 mapProperties::iterator it = (*m_Property).find(l_property);
335 if (it == (*m_Property).end()) {
336 LoggerE("not existing property");
337 Throw(WrtDeviceApis::Commons::ConversionException);
338 return BasePropertyPtr(NULL);
344 void Systeminfo::getWatchValue(const int watchType)
346 LoggerD(" watch type : " << watchType);
348 if (watchType == WATCH_TYPE_BATTERY) {
349 EventBatteryList eventList = m_EventMgrPtr->getEventBatteryList();
350 for (EventBatteryList::iterator it = eventList.begin(); it != eventList.end(); it++) {
351 (*it)->getWatchValue();
353 } else if (watchType == WATCH_TYPE_DISPLAY) {
354 EventDisplayList eventList = m_EventMgrPtr->getEventDisplayList();
355 for (EventDisplayList::iterator it = eventList.begin(); it != eventList.end(); it++) {
356 (*it)->getWatchValue();
358 } else if (watchType == WATCH_TYPE_NETWORK) {
359 EventNetworkList eventList = m_EventMgrPtr->getEventNetworkList();
360 for (EventNetworkList::iterator it = eventList.begin(); it != eventList.end(); it++) {
361 (*it)->getWatchValue();
363 } else if (watchType == WATCH_TYPE_NETWORK_ALL) {
364 EventWifiNetworkList eventListWifi = m_EventMgrPtr->getEventWifiNetworkList();
365 EventWifiNetworkList eventListCellular = m_EventMgrPtr->getEventCellularNetworkList();
366 if (eventListWifi.size() > 0) {
367 for (EventWifiNetworkList::iterator it = eventListWifi.begin(); it != eventListWifi.end(); it++) {
368 (*it)->getWatchValue();
371 if (eventListCellular.size() > 0) {
372 for (EventCellularNetworkList::iterator it = eventListCellular.begin(); it != eventListCellular.end(); it++) {
373 (*it)->getWatchValue();
376 } else if (watchType == WATCH_TYPE_CPU) {
377 EventCpuList eventList = m_EventMgrPtr->getEventCpuList();
378 for (EventCpuList::iterator it = eventList.begin(); it != eventList.end(); it++) {
379 (*it)->getWatchValue();
381 } else if (watchType == WATCH_TYPE_STORAGE) {
382 EventStorageList eventList = m_EventMgrPtr->getEventStorageList();
383 for (EventStorageList::iterator it = eventList.begin(); it != eventList.end(); it++) {
386 int usbhostState = 0;
387 if(vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &sdcardState) == 0) {
388 if(sdcardState == VCONFKEY_SYSMAN_MMC_MOUNTED) {
392 if(vconf_get_int(VCONFKEY_SYSMAN_USB_HOST_STATUS, &usbhostState) == 0) {
393 if(usbhostState == VCONFKEY_SYSMAN_USB_HOST_CONNECTED) {
397 LoggerD("storage cnt : " << storageCnt);
398 (*it)->getWatchValue(storageCnt);
400 }else if (watchType == WATCH_TYPE_DEVICE_ORIENTATION) {
401 EventDeviceOrientationList eventList = m_EventMgrPtr->getEventDeviceOrientationList();
402 for (EventDeviceOrientationList::iterator it = eventList.begin(); it != eventList.end(); it++) {
403 (*it)->getWatchValue();
405 } else if (watchType == WATCH_TYPE_LOCALE) {
406 EventLocaleList eventList = m_EventMgrPtr->getEventLocaleList();
407 for (EventLocaleList::iterator it = eventList.begin(); it != eventList.end(); it++) {
408 (*it)->getWatchValue();
410 } else if (watchType == WATCH_TYPE_PERIPHERAL) {
411 EventPeripheralList eventList = m_EventMgrPtr->getEventPeripheralList();
412 for (EventPeripheralList::iterator it = eventList.begin(); it != eventList.end(); it++) {
413 (*it)->getWatchValue();
415 } else if (watchType == WATCH_TYPE_CELLULARNETWORK) {
416 EventWifiNetworkList eventListCellular = m_EventMgrPtr->getEventCellularNetworkList();
417 if (eventListCellular.size() > 0) {
418 for (EventCellularNetworkList::iterator it = eventListCellular.begin(); it != eventListCellular.end(); it++) {
419 (*it)->getWatchValue();
425 connection_h Systeminfo::getConnectionHandle()
427 return m_connectionHandle;
430 JSValueRef Systeminfo::getCpuValue(JSContextRef context)
433 Converter converter(context);
435 CpuPropertiesPtr cpuPtr(new CpuProperties());
437 long long usr = 0, nice = 0, system = 0, idle = 0, cpuUsage = 0, diffIdle = 0, total = 0;
439 fp = fopen("/proc/stat", "r");
441 return JSValueMakeNull(context);
444 if (fscanf(fp, "%*s %lld %lld %lld %lld", &usr, &system, &nice, &idle) > 0) {
445 total = usr + nice + system + idle - m_cpuInfo.usr - m_cpuInfo.nice - m_cpuInfo.system - m_cpuInfo.idle;
446 diffIdle = idle-m_cpuInfo.idle;
447 if ((total > 0LL) && (diffIdle > 0LL)) {
448 cpuUsage = diffIdle * 100LL / total;
449 cpuPtr->load = (double)cpuUsage / 100.0;
451 m_cpuInfo.system = system;
452 m_cpuInfo.nice = nice;
453 m_cpuInfo.idle = idle;
454 LoggerD("cpu load : " << cpuPtr->load);
459 return JSCpuInfo::createJSObject(context, cpuPtr);
462 void Systeminfo::OnRequestReceived(const EventGetSysteminfoPtr& event)
465 event->processGetValue((void *)m_connectionHandle);
468 void Systeminfo::OnRequestReceived(const EventWatchSysteminfoPtr& event)
470 WatchOption watchOption = event->getWatchOption();
472 event->switchToManualAnswer();
473 event->setCancelAllowed(true);
475 switch(event->getWatchType()) {
476 case WATCH_TYPE_BATTERY:
477 if ((m_EventMgrPtr->getEventBatteryList()).size() == 1) {
478 vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, BatteryValueCallback, (void *)this);
479 vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, BatteryValueCallback, (void *)this);
482 case WATCH_TYPE_DISPLAY:
483 if ((m_EventMgrPtr->getEventDisplayList()).size() == 1) {
484 vconf_notify_key_changed(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, DisplayValueCallback, (void *)this);
487 case WATCH_TYPE_NETWORK:
488 if ((m_EventMgrPtr->getEventNetworkList()).size() == 1) {
489 connection_set_type_changed_cb(m_connectionHandle, NetworkTypeValueCallback, (void *)this);
492 case WATCH_TYPE_WIFINETWORK:
493 if ((m_EventMgrPtr->getEventWifiNetworkList()).size() == 1) {
494 if (m_networkRegist == REGIST_NOT) {
495 connection_set_ip_address_changed_cb(m_connectionHandle, NetworkValueCallback, (void *)this);
496 m_networkRegist = REGIST_WIFI;
497 } else if (m_networkRegist== REGIST_CELLULAR) {
498 m_networkRegist = REGIST_ALL;
502 case WATCH_TYPE_CELLULARNETWORK:
503 if ((m_EventMgrPtr->getEventCellularNetworkList()).size() == 1) {
504 vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, CellularNetworkValueCallback, (void *)this);
505 vconf_notify_key_changed(VCONFKEY_TELEPHONY_CELLID, CellularNetworkValueCallback, (void *)this);
506 vconf_notify_key_changed(VCONFKEY_TELEPHONY_LAC, CellularNetworkValueCallback, (void *)this);
507 if (m_networkRegist == REGIST_NOT) {
508 connection_set_ip_address_changed_cb(m_connectionHandle, NetworkValueCallback, (void *)this);
509 m_networkRegist = REGIST_CELLULAR;
510 } else if (m_networkRegist== REGIST_WIFI) {
511 m_networkRegist = REGIST_ALL;
515 case WATCH_TYPE_STORAGE:
516 if ((m_EventMgrPtr->getEventStorageList()).size() == 1) {
517 if (!m_storageTimer) {
518 m_storageTimer = ecore_timer_add(1, StorageValueCallback, this);
519 ecore_timer_thaw(m_storageTimer);
524 if ((m_EventMgrPtr->getEventCpuList()).size() == 1) {
526 m_cpuTimer = ecore_timer_add(1, CpuValueCallback, this);
527 ecore_timer_thaw(m_cpuTimer);
531 case WATCH_TYPE_DEVICE_ORIENTATION:
532 LoggerD("regist sensor");
533 if ((m_EventMgrPtr->getEventDeviceOrientationList()).size() == 1) {
534 int state = sf_register_event(m_sensorHandle, ACCELEROMETER_EVENT_ROTATION_CHECK, NULL, OrientationValueCallback, (void *)this);
536 LoggerD("sensor_register_cb fail to gather data");
537 } else if (state == 0) {
538 LoggerD("sensor_register_cb success to gather data");
541 LoggerD("already regist");
544 case WATCH_TYPE_LOCALE:
545 if ((m_EventMgrPtr->getEventLocaleList()).size() == 1) {
546 if (runtime_info_set_changed_cb(RUNTIME_INFO_KEY_REGION, localeChangedCallback, (void *)this) != RUNTIME_INFO_ERROR_NONE) {
547 LoggerE("regist failed");
548 Throw(WrtDeviceApis::Commons::Exception);
550 if (runtime_info_set_changed_cb(RUNTIME_INFO_KEY_LANGUAGE, localeChangedCallback, (void *)this) != RUNTIME_INFO_ERROR_NONE) {
551 LoggerE("regist failed");
552 Throw(WrtDeviceApis::Commons::Exception);
556 case WATCH_TYPE_PERIPHERAL:
557 if ((m_EventMgrPtr->getEventPeripheralList()).size() == 1) {
558 vconf_notify_key_changed(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, PeripheralValueCallback, (void *)this);
559 vconf_notify_key_changed(VCONFKEY_SYSMAN_HDMI, PeripheralValueCallback, (void *)this);
563 event->processGetValue();
567 ////////////////////////////////////////////////////////////////////////////////////////
569 Systeminfo::EventMgr::EventMgr()
573 Systeminfo::EventMgr::~EventMgr()
577 void Systeminfo::EventMgr::clearAllEvent()
579 DPL::Mutex::ScopedLock lock(&m_synchro);
581 while (!m_eventBatteryList.empty()) {
582 EventWatchSysteminfoPtr event = m_eventBatteryList.front();
583 LoggerD("removing EventId=" << event->getId());
585 m_eventBatteryList.pop_front();
587 while (!m_eventDisplayList.empty()) {
588 EventWatchSysteminfoPtr event = m_eventDisplayList.front();
589 LoggerD("removing EventId=" << event->getId());
591 m_eventDisplayList.pop_front();
593 while (!m_eventWifiNetworkList.empty()) {
594 EventWatchSysteminfoPtr event = m_eventWifiNetworkList.front();
595 LoggerD("removing EventId=" << event->getId());
597 m_eventWifiNetworkList.pop_front();
599 while (!m_eventCelluarNetworkList.empty()) {
600 EventWatchSysteminfoPtr event = m_eventCelluarNetworkList.front();
601 LoggerD("removing EventId=" << event->getId());
603 m_eventCelluarNetworkList.pop_front();
605 while (!m_eventStorageList.empty()) {
606 EventWatchSysteminfoPtr event = m_eventStorageList.front();
607 LoggerD("removing EventId=" << event->getId());
609 m_eventStorageList.pop_front();
611 while (!m_eventCpuList.empty()) {
612 EventWatchSysteminfoPtr event = m_eventCpuList.front();
613 LoggerD("removing EventId=" << event->getId());
615 m_eventCpuList.pop_front();
617 while (!m_eventSimList.empty()) {
618 EventWatchSysteminfoPtr event = m_eventSimList.front();
619 LoggerD("removing EventId=" << event->getId());
621 m_eventSimList.pop_front();
623 while (!m_eventDeviceOrientationList.empty()) {
624 EventWatchSysteminfoPtr event = m_eventDeviceOrientationList.front();
625 LoggerD("removing EventId=" << event->getId());
627 m_eventDeviceOrientationList.pop_front();
629 while (!m_eventLocaleList.empty()) {
630 EventWatchSysteminfoPtr event = m_eventLocaleList.front();
631 LoggerD("removing EventId=" << event->getId());
633 m_eventLocaleList.pop_front();
635 while (!m_eventPeripheralList.empty()) {
636 EventWatchSysteminfoPtr event = m_eventPeripheralList.front();
637 LoggerD("removing EventId=" << event->getId());
639 m_eventPeripheralList.pop_front();
643 void Systeminfo::EventMgr::addEvent(const EventWatchSysteminfoPtr& arg, const int watchType)
645 DPL::Mutex::ScopedLock lock(&m_synchro);
647 if (watchType == WATCH_TYPE_BATTERY){
648 m_eventBatteryList.push_back(arg);
649 LoggerD("Event Battery list size=" << m_eventBatteryList.size());
650 } else if (watchType == WATCH_TYPE_DISPLAY) {
651 m_eventDisplayList.push_back(arg);
652 LoggerD("Event display list size=" << m_eventDisplayList.size());
653 } else if (watchType == WATCH_TYPE_WIFINETWORK) {
654 m_eventWifiNetworkList.push_back(arg);
655 LoggerD("Event wifi network list size=" << m_eventWifiNetworkList.size());
656 } else if (watchType == WATCH_TYPE_CELLULARNETWORK) {
657 m_eventCelluarNetworkList.push_back(arg);
658 LoggerD("Event cellular network list size=" << m_eventCelluarNetworkList.size());
659 } else if (watchType == WATCH_TYPE_STORAGE) {
660 m_eventStorageList.push_back(arg);
661 LoggerD("Event storage list size=" << m_eventStorageList.size());
662 } else if (watchType == WATCH_TYPE_CPU) {
663 m_eventCpuList.push_back(arg);
664 LoggerD("Event cpu list size=" << m_eventCpuList.size());
665 } else if (watchType == WATCH_TYPE_SIM) {
666 m_eventSimList.push_back(arg);
667 LoggerD("Event sim list size=" << m_eventSimList.size());
668 } else if (watchType == WATCH_TYPE_DEVICE_ORIENTATION) {
669 m_eventDeviceOrientationList.push_back(arg);
670 LoggerD("Event device orientation list size=" << m_eventDeviceOrientationList.size());
671 } else if (watchType == WATCH_TYPE_NETWORK) {
672 m_eventNetworkList.push_back(arg);
673 LoggerD("Event network list size=" << m_eventNetworkList.size());
674 } else if (watchType == WATCH_TYPE_LOCALE) {
675 m_eventLocaleList.push_back(arg);
676 LoggerD("Event Locale list size=" << m_eventLocaleList.size());
677 } else if (watchType == WATCH_TYPE_PERIPHERAL) {
678 m_eventPeripheralList.push_back(arg);
679 LoggerD("Event peripheral list size=" << m_eventPeripheralList.size());
683 void Systeminfo::EventMgr::removeEvent(WatchId id, const int watchType)
685 DPL::Mutex::ScopedLock lock(&m_synchro);
686 LoggerD("Event id : " << id);
688 EventWatchSysteminfoPtr event(NULL);
690 LoggerD("trying to delete event, id=" << id);
692 if (watchType == WATCH_TYPE_BATTERY) {
693 for (EventBatteryList::iterator it = m_eventBatteryList.begin(); it != m_eventBatteryList.end(); it++) {
694 if (id == (*it)->getId()) {
700 LoggerE("event id not in the list, nothing to do");
704 LoggerD("event Battery list size=" << m_eventBatteryList.size());
705 m_eventBatteryList.remove(event);
706 LoggerD( "event removed, event Battery list size=" << m_eventBatteryList.size());
707 } else if (watchType == WATCH_TYPE_DISPLAY) {
708 for (EventDisplayList::iterator it = m_eventDisplayList.begin(); it != m_eventDisplayList.end(); it++) {
709 if (id == (*it)->getId()) {
715 LoggerE("event id not in the list, nothing to do");
719 LoggerD("event display list size=" << m_eventDisplayList.size());
720 m_eventDisplayList.remove(event);
721 LoggerD( "event removed, event display list size=" << m_eventDisplayList.size());
722 } else if (watchType == WATCH_TYPE_WIFINETWORK) {
723 for (EventWifiNetworkList::iterator it = m_eventWifiNetworkList.begin(); it != m_eventWifiNetworkList.end(); it++) {
724 if (id == (*it)->getId()) {
730 LoggerE("event id not in the list, nothing to do");
734 LoggerD("event wifi network list size=" << m_eventWifiNetworkList.size());
735 m_eventWifiNetworkList.remove(event);
736 LoggerD( "event removed, event wifi network list size=" << m_eventCelluarNetworkList.size());
737 } else if (watchType == WATCH_TYPE_CELLULARNETWORK) {
738 for (EventCellularNetworkList::iterator it = m_eventCelluarNetworkList.begin(); it != m_eventCelluarNetworkList.end(); it++) {
739 if (id == (*it)->getId()) {
745 LoggerE("event id not in the list, nothing to do");
749 LoggerD("event cellular network list size=" << m_eventCelluarNetworkList.size());
750 m_eventCelluarNetworkList.remove(event);
751 LoggerD( "event removed, event cellular network list size=" << m_eventCelluarNetworkList.size());
752 } else if (watchType == WATCH_TYPE_STORAGE) {
753 for (EventStorageList::iterator it = m_eventStorageList.begin(); it != m_eventStorageList.end(); it++) {
754 if (id == (*it)->getId()) {
760 LoggerE("event id not in the list, nothing to do");
764 LoggerD("event storage list size=" << m_eventStorageList.size());
765 m_eventStorageList.remove(event);
766 LoggerD( "event removed, event storage list size=" << m_eventStorageList.size());
767 } else if (watchType == WATCH_TYPE_CPU) {
768 for (EventCpuList::iterator it = m_eventCpuList.begin(); it != m_eventCpuList.end(); it++) {
769 if (id == (*it)->getId()) {
775 LoggerE("event id not in the list, nothing to do");
779 LoggerD("event cpu list size=" << m_eventCpuList.size());
780 m_eventCpuList.remove(event);
781 LoggerD( "event removed, event cpu list size=" << m_eventCpuList.size());
782 } else if (watchType == WATCH_TYPE_SIM) {
783 for (EventSimList::iterator it = m_eventSimList.begin(); it != m_eventSimList.end(); it++) {
784 if (id == (*it)->getId()) {
790 LoggerE("event id not in the list, nothing to do");
794 LoggerD("event sim list size=" << m_eventSimList.size());
795 m_eventSimList.remove(event);
796 LoggerD( "event removed, event sim list size=" << m_eventSimList.size());
797 } else if (watchType == WATCH_TYPE_DEVICE_ORIENTATION) {
798 for (EventDeviceOrientationList::iterator it = m_eventDeviceOrientationList.begin(); it != m_eventDeviceOrientationList.end(); it++) {
799 if (id == (*it)->getId()) {
805 LoggerE("event id not in the list, nothing to do");
809 LoggerD("event device orientation list size=" << m_eventDeviceOrientationList.size());
810 m_eventDeviceOrientationList.remove(event);
811 LoggerD( "event removed, event device orientation list size=" << m_eventDeviceOrientationList.size());
812 } else if (watchType == WATCH_TYPE_NETWORK) {
813 for (EventNetworkList::iterator it = m_eventNetworkList.begin(); it != m_eventNetworkList.end(); it++) {
814 if (id == (*it)->getId()) {
820 LoggerE("event id not in the list, nothing to do");
824 LoggerD("event network list size=" << m_eventNetworkList.size());
825 m_eventNetworkList.remove(event);
826 LoggerD( "event removed, event network list size=" << m_eventNetworkList.size());
827 } else if (watchType == WATCH_TYPE_LOCALE) {
828 for (EventLocaleList::iterator it = m_eventLocaleList.begin(); it != m_eventLocaleList.end(); it++) {
829 if (id == (*it)->getId()) {
835 LoggerE("event id not in the list, nothing to do");
839 LoggerD("event Locale list size=" << m_eventLocaleList.size());
840 m_eventLocaleList.remove(event);
841 LoggerD( "event removed, event Locale list size=" << m_eventLocaleList.size());
842 } else if (watchType == WATCH_TYPE_PERIPHERAL) {
843 for (EventPeripheralList::iterator it = m_eventPeripheralList.begin(); it != m_eventPeripheralList.end(); it++) {
844 if (id == (*it)->getId()) {
850 LoggerE("event id not in the list, nothing to do");
854 LoggerD("event peripheral list size=" << m_eventPeripheralList.size());
855 m_eventPeripheralList.remove(event);
856 LoggerD( "event removed, event peripheral list size=" << m_eventPeripheralList.size());
860 const int Systeminfo::EventMgr::getWatchType(const long id)
862 DPL::Mutex::ScopedLock lock(&m_synchro);
864 EventWatchSysteminfoPtr event(NULL);
866 for (EventBatteryList::iterator it = m_eventBatteryList.begin(); it != m_eventBatteryList.end(); it++) {
867 if (id == (*it)->getId()) {
873 for (EventDisplayList::iterator it = m_eventDisplayList.begin(); it != m_eventDisplayList.end(); it++) {
874 if (id == (*it)->getId()) {
880 for (EventWifiNetworkList::iterator it = m_eventWifiNetworkList.begin(); it != m_eventWifiNetworkList.end(); it++) {
881 if (id == (*it)->getId()) {
887 for (EventCellularNetworkList::iterator it = m_eventCelluarNetworkList.begin(); it != m_eventCelluarNetworkList.end(); it++) {
888 if (id == (*it)->getId()) {
894 for (EventStorageList::iterator it = m_eventStorageList.begin(); it != m_eventStorageList.end(); it++) {
895 if (id == (*it)->getId()) {
901 for (EventCpuList::iterator it = m_eventCpuList.begin(); it != m_eventCpuList.end(); it++) {
902 if (id == (*it)->getId()) {
908 for (EventSimList::iterator it = m_eventSimList.begin(); it != m_eventSimList.end(); it++) {
909 if (id == (*it)->getId()) {
915 for (EventDeviceOrientationList::iterator it = m_eventDeviceOrientationList.begin(); it != m_eventDeviceOrientationList.end(); it++) {
916 if (id == (*it)->getId()) {
922 for (EventNetworkList::iterator it = m_eventNetworkList.begin(); it != m_eventNetworkList.end(); it++) {
923 if (id == (*it)->getId()) {
929 for (EventSimList::iterator it = m_eventSimList.begin(); it != m_eventSimList.end(); it++) {
930 if (id == (*it)->getId()) {
936 for (EventLocaleList::iterator it = m_eventLocaleList.begin(); it != m_eventLocaleList.end(); it++) {
937 if (id == (*it)->getId()) {
943 for (EventPeripheralList::iterator it = m_eventPeripheralList.begin(); it != m_eventPeripheralList.end(); it++) {
944 if (id == (*it)->getId()) {
951 LoggerE("event id not in the list, nothing to do");
952 return WATCH_TYPE_UNKNOWN;
955 return event->getWatchType();
958 EventBatteryList Systeminfo::EventMgr::getEventBatteryList()
960 return m_eventBatteryList;
963 EventDisplayList Systeminfo::EventMgr::getEventDisplayList()
965 return m_eventDisplayList;
968 EventNetworkList Systeminfo::EventMgr::getEventNetworkList()
970 return m_eventNetworkList;
973 EventWifiNetworkList Systeminfo::EventMgr::getEventWifiNetworkList()
975 return m_eventWifiNetworkList;
978 EventCellularNetworkList Systeminfo::EventMgr::getEventCellularNetworkList()
980 return m_eventCelluarNetworkList;
983 EventStorageList Systeminfo::EventMgr::getEventStorageList()
985 return m_eventStorageList;
988 EventCpuList Systeminfo::EventMgr::getEventCpuList()
990 return m_eventCpuList;
993 EventDeviceOrientationList Systeminfo::EventMgr::getEventDeviceOrientationList()
995 return m_eventDeviceOrientationList;
998 EventSimList Systeminfo::EventMgr::getEventSimList()
1000 return m_eventSimList;
1003 EventLocaleList Systeminfo::EventMgr::getEventLocaleList()
1005 return m_eventLocaleList;
1008 EventPeripheralList Systeminfo::EventMgr::getEventPeripheralList()
1010 return m_eventPeripheralList;
1013 ////////////////////////////////////////////////////////////////////////////////////////
1015 PROPERTY_GET_SYSTEMINFO_DEFINITION(Battery) {
1016 BatteryPropertiesPtr BatteryPtr(new BatteryProperties());
1020 if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, &value) != 0) {
1021 return JSValueMakeNull(context);
1023 BatteryPtr->level = (double)(value)/CPU_POWER_DEVICE_VALUE;
1026 if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &value2) != 0) {
1027 return JSValueMakeNull(context);
1029 BatteryPtr->isCharging = (value2 == 0) ? false : true;
1032 return JSBatteryInfo::createJSObject(context, BatteryPtr);
1035 PROPERTY_GET_SYSTEMINFO_DEFINITION(Cpu) {
1036 Converter converter(context);
1038 CpuPropertiesPtr cpuPtr(new CpuProperties());
1040 long long usr = 0, nice = 0, system = 0, idle = 0, total = 0, cpuUsage = 0;
1042 fp = fopen("/proc/stat", "r");
1044 return JSValueMakeNull(context);
1047 if (fscanf(fp, "%*s %lld %lld %lld %lld", &usr, &system, &nice, &idle) > 0) {
1048 total = usr + nice + system + idle;
1049 if ((total > 0LL) && (idle > 0LL)) {
1050 cpuUsage = idle * 100LL / total;
1051 cpuPtr->load = (double)cpuUsage / 100.0;
1052 LoggerD("cpu load : " << cpuPtr->load);
1057 return JSCpuInfo::createJSObject(context, cpuPtr);
1060 PROPERTY_GET_SYSTEMINFO_DEFINITION(Storage) {
1061 Converter converter(context);
1066 StoragePropertiesPtr internal(new StorageProperties());
1067 StoragePropertiesPtr mmc(new StorageProperties());
1068 StoragePropertiesPtr usbhost(new StorageProperties());
1069 std::vector <JSObjectRef> storagelist;
1071 if (statfs(STORAGE_INTERNAL_PATH, &fs) < 0) {
1072 return JSValueMakeNull(context);
1075 internal->type = "INTERNAL";
1076 internal->capacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_blocks;
1077 internal->availableCapacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_bavail;
1078 internal->isRemoveable = false;
1079 internal->isRemovable = false;
1080 storagelist.push_back(JSStorageInfo::createJSObject(context, internal));
1083 if(vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &sdcardState) == 0){
1084 if(sdcardState == VCONFKEY_SYSMAN_MMC_MOUNTED){
1086 if (statfs(STORAGE_SDCARD_PATH, &fs) < 0) {
1087 return JSValueMakeNull(context);
1090 mmc->capacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_blocks;
1091 mmc->availableCapacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_bavail;
1092 mmc->isRemoveable = true;
1093 mmc->isRemovable = true;
1094 storagelist.push_back(JSStorageInfo::createJSObject(context, mmc));
1098 if(vconf_get_int(VCONFKEY_SYSMAN_USB_HOST_STATUS, &usbhostState) == 0) {
1099 if(usbhostState == VCONFKEY_SYSMAN_USB_HOST_CONNECTED) {
1101 if (statfs(STORAGE_USBHOST_PATH, &fs) < 0) {
1102 return JSValueMakeNull(context);
1104 usbhost->type = "USB_HOST";
1105 usbhost->capacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_blocks;
1106 usbhost->availableCapacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_bavail;
1107 usbhost->isRemoveable = true;
1108 usbhost->isRemovable = true;
1109 storagelist.push_back(JSStorageInfo::createJSObject(context, usbhost));
1113 return JSObjectMakeArray(context, storageCnt, storagelist.data(), NULL);
1116 PROPERTY_GET_SYSTEMINFO_DEFINITION(Display) {
1117 Converter converter(context);
1119 DisplayPropertiesPtr display(new DisplayProperties());
1120 int brightness=0, dotsPerInchX=0, dotsPerInchY=0, physicalW=0, physicalH=0, resolutionW=0, resolutionH=0;
1122 if(vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, &brightness) == 0) {
1123 display->brightness = (double)(brightness)/DISPLAY_BRIGHTNESS_DIVIDE_VALUE;
1124 LoggerD("brightness : " << display->brightness);
1127 if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_WIDTH, &resolutionW) == SYSTEM_INFO_ERROR_NONE) {
1128 display->resolutionWidth = resolutionW;
1129 LoggerD("resolutionWidth : " << display->resolutionWidth);
1131 if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_HEIGHT, &resolutionH) == SYSTEM_INFO_ERROR_NONE) {
1132 display->resolutionHeight = resolutionH;
1133 LoggerD("resolutionHeight : " << display->resolutionHeight);
1135 if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_DPI, &dotsPerInchX) == SYSTEM_INFO_ERROR_NONE) {
1136 display->dotsPerInchWidth = dotsPerInchX;
1137 LoggerD("dotsPerInchWidth : " << display->dotsPerInchWidth);
1139 if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_DPI, &dotsPerInchY) == SYSTEM_INFO_ERROR_NONE) {
1140 display->dotsPerInchHeight = dotsPerInchY;
1141 LoggerD("dotsPerInchHeight : " << display->dotsPerInchHeight);
1143 if (system_info_get_value_int(SYSTEM_INFO_KEY_PHYSICAL_SCREEN_HEIGHT, &physicalH) == SYSTEM_INFO_ERROR_NONE) {
1144 display->physicalHeight = physicalH;
1145 LoggerD("physicalHeight : " << display->physicalHeight);
1147 if (system_info_get_value_int(SYSTEM_INFO_KEY_PHYSICAL_SCREEN_WIDTH, &physicalW) == SYSTEM_INFO_ERROR_NONE) {
1148 display->physicalWidth = physicalW;
1149 LoggerD("physicalWidth : " << display->physicalWidth);
1152 return JSDisplayInfo::createJSObject(context, display);
1155 PROPERTY_GET_SYSTEMINFO_DEFINITION(Network) {
1157 Converter converter(context);
1158 NetworkPropertiesPtr Network(new NetworkProperties());
1159 connection_h connectionHandle = (connection_h)handle;
1160 connection_type_e connectionType;
1161 int networkType = 0;
1163 if (connection_get_type(connectionHandle, &connectionType) != CONNECTION_ERROR_NONE) {
1164 LoggerD("get connection type is failed");
1165 return JSNetworkInfo::createJSObject(context, Network);
1168 if (connectionType == CONNECTION_TYPE_WIFI) {
1169 LoggerD("wifi network");
1170 Network->networkType= "WIFI";
1171 } else if (connectionType == CONNECTION_TYPE_CELLULAR) {
1172 if (vconf_get_int(VCONFKEY_TELEPHONY_SVCTYPE, &networkType) == 0) {
1173 if (networkType < VCONFKEY_TELEPHONY_SVCTYPE_2G) {
1174 Network->networkType= "NONE";
1175 } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_2G) {
1176 Network->networkType= "2G";
1177 } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_2G || networkType == VCONFKEY_TELEPHONY_SVCTYPE_2_5G_EDGE) {
1178 Network->networkType= "2.5";
1179 } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_3G || networkType == VCONFKEY_TELEPHONY_SVCTYPE_HSDPA) {
1180 Network->networkType= "3G";
1181 } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_LTE) {
1182 Network->networkType= "4G";
1184 Network->networkType= "NONE";
1188 Network->networkType= "NONE";
1191 return JSNetworkInfo::createJSObject(context, Network);
1194 PROPERTY_GET_SYSTEMINFO_DEFINITION(WifiNetwork) {
1195 Converter converter(context);
1196 WifiNetworkPropertiesPtr wifiNetwork(new WifiNetworkProperties());
1197 connection_h connectionHandle = (connection_h)handle;
1198 connection_type_e connectionType;
1199 connection_profile_h profileHandle = NULL;
1200 connection_address_family_e addressFamily = CONNECTION_ADDRESS_FAMILY_IPV4;
1201 char* ipAddr = NULL;
1205 if (connection_get_type(connectionHandle, &connectionType) != CONNECTION_ERROR_NONE) {
1206 return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1209 if (connectionType == CONNECTION_TYPE_WIFI) {
1210 wifiNetwork->status = "ON";
1212 wifiNetwork->status = "OFF";
1213 return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1216 if (connection_get_current_profile(connectionHandle, &profileHandle) != CONNECTION_ERROR_NONE) {
1217 return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1220 if (connection_profile_get_wifi_essid(profileHandle, &essid) == CONNECTION_ERROR_NONE) {
1221 wifiNetwork->ssid = essid;
1225 if (connection_profile_get_ip_address(profileHandle, addressFamily, &ipAddr) == CONNECTION_ERROR_NONE) {
1226 wifiNetwork->ipAddress = ipAddr;
1230 if (connection_profile_get_wifi_rssi(profileHandle, &rssi) == CONNECTION_ERROR_NONE) {
1231 wifiNetwork->signalStrength = (double) rssi/WIFI_SIGNAL_STRENGTH_DIVIDE_VALUE;
1234 return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1237 PROPERTY_GET_SYSTEMINFO_DEFINITION(CellularNetwork) {
1238 Converter converter(context);
1239 CellularNetworkPropertiesPtr cellularNetwork(new CellularNetworkProperties());
1240 connection_h connectionHandle = (connection_h)handle;
1241 connection_type_e connectionType;
1242 connection_profile_h profileHandle = NULL;
1243 connection_address_family_e addressFamily = CONNECTION_ADDRESS_FAMILY_IPV4;
1244 char* ipAddr = NULL;
1247 int plmn = 0, cellId = 0, lac = 0, isRoaming = 0, isFlightMode = 0;
1249 TIME_TRACER_ITEM_BEGIN("(cellular)mcc", 0);
1250 if (vconf_get_int(VCONFKEY_TELEPHONY_PLMN, &plmn) == 0) {
1251 cellularNetwork->mcc = plmn / 100;
1252 cellularNetwork->mnc = plmn % 100;
1254 TIME_TRACER_ITEM_END("(cellular)mcc", 0);
1256 TIME_TRACER_ITEM_BEGIN("(cellular)cellId", 0);
1257 if (vconf_get_int(VCONFKEY_TELEPHONY_CELLID, &cellId) == 0) {
1258 cellularNetwork->cellId = cellId;
1260 TIME_TRACER_ITEM_END("(cellular)cellId", 0);
1262 TIME_TRACER_ITEM_BEGIN("(cellular)lac", 0);
1263 if (vconf_get_int(VCONFKEY_TELEPHONY_LAC, &lac) == 0) {
1264 cellularNetwork->lac = lac;
1266 TIME_TRACER_ITEM_END("(cellular)lac", 0);
1268 TIME_TRACER_ITEM_BEGIN("(cellular)isRoaming", 0);
1269 if (vconf_get_int(VCONFKEY_TELEPHONY_SVC_ROAM, &isRoaming) == 0) {
1271 cellularNetwork->isRoaming = true;
1273 cellularNetwork->isRoaming = false;
1276 TIME_TRACER_ITEM_END("(cellular)isRoaming", 0);
1278 TIME_TRACER_ITEM_BEGIN("(cellular)isFlightMode", 0);
1279 if (vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &isFlightMode) == 0) {
1281 cellularNetwork->isFlightMode = true;
1283 cellularNetwork->isFlightMode = false;
1286 TIME_TRACER_ITEM_END("(cellular)isFlightMode", 0);
1288 if (connection_get_type(connectionHandle, &connectionType) != CONNECTION_ERROR_NONE) {
1289 return JSCellularNetworkInfo::createJSObject(context, cellularNetwork);
1292 if (connectionType == CONNECTION_TYPE_CELLULAR) {
1293 cellularNetwork->status = "ON";
1294 if (connection_get_current_profile(connectionHandle, &profileHandle) == CONNECTION_ERROR_NONE) {
1295 TIME_TRACER_ITEM_BEGIN("(cellular)apn", 0);
1296 if (connection_profile_get_cellular_apn(profileHandle, &apn) == CONNECTION_ERROR_NONE) {
1297 cellularNetwork->apn = apn;
1300 TIME_TRACER_ITEM_END("(cellular)apn", 0);
1302 TIME_TRACER_ITEM_BEGIN("(cellular)ipAddress", 0);
1303 if (connection_profile_get_ip_address(profileHandle, addressFamily, &ipAddr) == CONNECTION_ERROR_NONE) {
1304 cellularNetwork->ipAddress = ipAddr;
1307 TIME_TRACER_ITEM_END("(cellular)ipAddress", 0);
1308 connection_profile_destroy(profileHandle);
1311 cellularNetwork->status = "OFF";
1312 if (connection_get_default_cellular_service_profile(connectionHandle, CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET, &profileHandle) == CONNECTION_ERROR_NONE) {
1313 TIME_TRACER_ITEM_BEGIN("(cellular)apn", 0);
1314 if (connection_profile_get_cellular_apn(profileHandle, &apn) == CONNECTION_ERROR_NONE) {
1315 cellularNetwork->apn = apn;
1318 TIME_TRACER_ITEM_END("(cellular)apn", 0);
1319 connection_profile_destroy(profileHandle);
1323 TIME_TRACER_ITEM_BEGIN("(cellular)imei", 0);
1324 if (system_info_get_value_string(SYSTEM_INFO_KEY_MOBILE_DEVICE_ID, &imei) == SYSTEM_INFO_ERROR_NONE) {
1326 LoggerD("imei : " << imei);
1327 cellularNetwork->imei = imei;
1331 TIME_TRACER_ITEM_END("(cellular)imei", 0);
1333 return JSCellularNetworkInfo::createJSObject(context, cellularNetwork);
1336 PROPERTY_GET_SYSTEMINFO_DEFINITION(SIM) {
1337 Converter converter(context);
1338 SIMPropertiesPtr SIM(new SIMProperties());
1339 return JSSIMInfo::createJSObject(context, SIM);
1342 PROPERTY_GET_SYSTEMINFO_DEFINITION(DeviceOrientation) {
1344 Converter converter(context);
1345 DeviceOrientationPropertiesPtr deviceOrientation(new DeviceOrientationProperties());
1347 unsigned long rotation = 0;
1348 int handleOrientaion = 0;
1350 handleOrientaion = sf_connect(ACCELEROMETER_SENSOR);
1351 LoggerD("handleOrientaion : " << handleOrientaion);
1352 if (handleOrientaion < 0) {
1353 LoggerD ("sensor attach fail");
1354 return JSDeviceOrientationInfo::createJSObject(context, deviceOrientation);
1356 int state = sf_start(handleOrientaion, 0);
1358 LoggerD("start failed");
1361 int ret_val = sf_check_rotation(&rotation);
1363 LoggerD("sf_check_rotation fail to gather data\n");
1366 LoggerD(" rotation value = " << rotation);
1370 case ROTATION_EVENT_0:
1371 LoggerD("my_callback_func received data (PORTRAIT_TOP|HEAD_CENTER)\n");
1372 deviceOrientation->status = "PORTRAIT_PRIMARY";
1374 case ROTATION_EVENT_90:
1375 LoggerD("my_callback_func received data (LANDSCAPE|HEAD_RIGHT)\n");
1376 deviceOrientation->status = "LANDSCAPE_PRIMARY";
1378 case ROTATION_EVENT_180:
1379 LoggerD("my_callback_func received data (PORTRAIT_BTM|HEAD_CENTER)\n");
1380 deviceOrientation->status = "PORTRAIT_SECONDARY";
1382 case ROTATION_EVENT_270:
1383 LoggerD("my_callback_func received data (LANDSCAPE|HEAD_LEFT)\n");
1384 deviceOrientation->status = "LANDSCAPE_SECONDARY";
1387 LoggerD(" received data unexpected\n");
1391 state = sf_stop(handleOrientaion);
1392 LoggerD("handleOrientaion 1 state = " << state);
1394 state = sf_disconnect(handleOrientaion);
1395 LoggerD("handleOrientaion state =" << state);
1397 return JSDeviceOrientationInfo::createJSObject(context, deviceOrientation);
1400 PROPERTY_GET_SYSTEMINFO_DEFINITION(Build) {
1402 Converter converter(context);
1403 BuildPropertiesPtr Build(new BuildProperties());
1406 char* manufacturer = NULL;
1407 char* buildVersion = NULL;
1409 if (system_info_get_value_string(SYSTEM_INFO_KEY_MODEL, &model) == SYSTEM_INFO_ERROR_NONE) {
1410 if (model != NULL) {
1411 LoggerD("model : " << model);
1412 Build->model = model;
1417 if (system_info_get_value_string(SYSTEM_INFO_KEY_MANUFACTURER, &manufacturer) == SYSTEM_INFO_ERROR_NONE) {
1418 if (manufacturer != NULL) {
1419 LoggerD("manufacturer : " << manufacturer);
1420 Build->manufacturer = manufacturer;
1425 if (system_info_get_value_string(SYSTEM_INFO_KEY_BUILD_STRING, &buildVersion) == SYSTEM_INFO_ERROR_NONE) {
1426 if (buildVersion != NULL) {
1427 LoggerD("buildVersion : " << buildVersion);
1428 Build->buildVersion = buildVersion;
1433 return JSBuildInfo::createJSObject(context, Build);
1436 PROPERTY_GET_SYSTEMINFO_DEFINITION(Locale) {
1438 Converter converter(context);
1439 LocalePropertiesPtr Locale(new LocaleProperties());
1441 char* country = NULL;
1442 char* language = NULL;
1444 if (runtime_info_get_value_string(RUNTIME_INFO_KEY_LANGUAGE, &language) == RUNTIME_INFO_ERROR_NONE) {
1445 if (language != NULL) {
1446 LoggerD("language : " << language);
1447 Locale->language = language;
1452 if (runtime_info_get_value_string(RUNTIME_INFO_KEY_REGION, &country) == RUNTIME_INFO_ERROR_NONE) {
1453 if (country != NULL) {
1454 LoggerD("country : " << country);
1456 char* countryTemp = NULL;
1457 token = strtok(country, ".");
1458 if (token != NULL) {
1459 countryTemp = strdup(token);
1460 if (countryTemp != NULL) {
1461 Locale->country = countryTemp;
1469 return JSLocaleInfo::createJSObject(context, Locale);
1472 PROPERTY_GET_SYSTEMINFO_DEFINITION(Peripheral) {
1473 Converter converter(context);
1474 PeripheralPropertiesPtr peripheral(new PeripheralProperties());
1475 int hdmiStatus = 0, wirelessDisplayStatus = 0 ;
1477 if (vconf_get_int(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, &wirelessDisplayStatus) == 0) {
1478 switch(wirelessDisplayStatus) {
1479 case VCONFKEY_MIRACAST_WFD_SOURCE_ON:
1480 peripheral->isVideoOutputOn = true;
1483 LoggerD("VideOutput status is off");
1488 if (vconf_get_int(VCONFKEY_SYSMAN_HDMI, &hdmiStatus) == 0) {
1489 switch(hdmiStatus) {
1490 case VCONFKEY_SYSMAN_HDMI_CONNECTED:
1491 peripheral->isVideoOutputOn = true;
1494 LoggerD("VideOutput status is off");
1499 return JSPeripheralInfo::createJSObject(context, peripheral);