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 if (m_networkRegist == REGIST_CELLULAR) {
269 connection_unset_ip_address_changed_cb(m_connectionHandle);
270 m_networkRegist = REGIST_NOT;
271 } else if (m_networkRegist== REGIST_ALL) {
272 m_networkRegist = REGIST_WIFI;
276 case WATCH_TYPE_STORAGE:
277 if ((m_EventMgrPtr->getEventStorageList()).size() == 1) {
278 if (m_storageTimer) {
279 ecore_timer_freeze(m_storageTimer);
280 ecore_timer_del(m_storageTimer);
281 m_storageTimer = NULL;
286 if ((m_EventMgrPtr->getEventCpuList()).size() == 1) {
288 ecore_timer_freeze(m_cpuTimer);
289 ecore_timer_del(m_cpuTimer);
294 case WATCH_TYPE_DEVICE_ORIENTATION:
295 if ((m_EventMgrPtr->getEventDeviceOrientationList()).size() == 1) {
296 int state = sf_unregister_event(m_sensorHandle, ACCELEROMETER_EVENT_ROTATION_CHECK);
298 LoggerD("sf_unregister_event fail to gather data\n");
302 case WATCH_TYPE_LOCALE:
303 if ((m_EventMgrPtr->getEventLocaleList()).size() == 1) {
304 if (runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_LANGUAGE) != RUNTIME_INFO_ERROR_NONE) {
305 LoggerE("regist failed");
306 Throw(WrtDeviceApis::Commons::Exception);
308 if (runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_REGION) != RUNTIME_INFO_ERROR_NONE) {
309 LoggerE("regist failed");
310 Throw(WrtDeviceApis::Commons::Exception);
314 case WATCH_TYPE_PERIPHERAL:
315 if ((m_EventMgrPtr->getEventPeripheralList()).size() == 1) {
316 vconf_ignore_key_changed(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, PeripheralValueCallback);
317 vconf_ignore_key_changed(VCONFKEY_SYSMAN_HDMI, PeripheralValueCallback);
320 case WATCH_TYPE_UNKNOWN:
321 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
324 m_EventMgrPtr->removeEvent(id, watchType);
328 BasePropertyPtr Systeminfo::getBasePropertyPtr(JSContextRef context, JSValueRef property)
330 Converter converter(context);
331 std::string l_property = converter.toString(property);
332 mapProperties::iterator it = (*m_Property).find(l_property);
333 if (it == (*m_Property).end()) {
334 LoggerE("not existing property");
335 Throw(WrtDeviceApis::Commons::ConversionException);
336 return BasePropertyPtr(NULL);
342 void Systeminfo::getWatchValue(const int watchType)
344 if (watchType == WATCH_TYPE_BATTERY) {
345 EventBatteryList eventList = m_EventMgrPtr->getEventBatteryList();
346 for (EventBatteryList::iterator it = eventList.begin(); it != eventList.end(); it++) {
347 (*it)->getWatchValue();
349 } else if (watchType == WATCH_TYPE_DISPLAY) {
350 EventDisplayList eventList = m_EventMgrPtr->getEventDisplayList();
351 for (EventDisplayList::iterator it = eventList.begin(); it != eventList.end(); it++) {
352 (*it)->getWatchValue();
354 } else if (watchType == WATCH_TYPE_NETWORK) {
355 EventNetworkList eventList = m_EventMgrPtr->getEventNetworkList();
356 for (EventNetworkList::iterator it = eventList.begin(); it != eventList.end(); it++) {
357 (*it)->getWatchValue();
359 } else if (watchType == WATCH_TYPE_NETWORK_ALL) {
360 EventWifiNetworkList eventListWifi = m_EventMgrPtr->getEventWifiNetworkList();
361 EventWifiNetworkList eventListCellular = m_EventMgrPtr->getEventCellularNetworkList();
362 if (eventListWifi.size() > 0) {
363 for (EventWifiNetworkList::iterator it = eventListWifi.begin(); it != eventListWifi.end(); it++) {
364 (*it)->getWatchValue();
367 if (eventListCellular.size() > 0) {
368 for (EventCellularNetworkList::iterator it = eventListCellular.begin(); it != eventListCellular.end(); it++) {
369 (*it)->getWatchValue();
372 } else if (watchType == WATCH_TYPE_CPU) {
373 EventCpuList eventList = m_EventMgrPtr->getEventCpuList();
374 for (EventCpuList::iterator it = eventList.begin(); it != eventList.end(); it++) {
375 (*it)->getWatchValue();
377 } else if (watchType == WATCH_TYPE_STORAGE) {
378 EventStorageList eventList = m_EventMgrPtr->getEventStorageList();
379 for (EventStorageList::iterator it = eventList.begin(); it != eventList.end(); it++) {
382 int usbhostState = 0;
383 if(vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &sdcardState) == 0) {
384 if(sdcardState == VCONFKEY_SYSMAN_MMC_MOUNTED) {
388 if(vconf_get_int(VCONFKEY_SYSMAN_USB_HOST_STATUS, &usbhostState) == 0) {
389 if(usbhostState == VCONFKEY_SYSMAN_USB_HOST_CONNECTED) {
393 LoggerD("storage cnt : " << storageCnt);
394 (*it)->getWatchValue(storageCnt);
396 }else if (watchType == WATCH_TYPE_DEVICE_ORIENTATION) {
397 EventDeviceOrientationList eventList = m_EventMgrPtr->getEventDeviceOrientationList();
398 for (EventDeviceOrientationList::iterator it = eventList.begin(); it != eventList.end(); it++) {
399 (*it)->getWatchValue();
401 } else if (watchType == WATCH_TYPE_LOCALE) {
402 EventLocaleList eventList = m_EventMgrPtr->getEventLocaleList();
403 for (EventLocaleList::iterator it = eventList.begin(); it != eventList.end(); it++) {
404 (*it)->getWatchValue();
406 } else if (watchType == WATCH_TYPE_PERIPHERAL) {
407 EventPeripheralList eventList = m_EventMgrPtr->getEventPeripheralList();
408 for (EventPeripheralList::iterator it = eventList.begin(); it != eventList.end(); it++) {
409 (*it)->getWatchValue();
411 } else if (watchType == WATCH_TYPE_CELLULARNETWORK) {
412 EventWifiNetworkList eventListCellular = m_EventMgrPtr->getEventCellularNetworkList();
413 if (eventListCellular.size() > 0) {
414 for (EventCellularNetworkList::iterator it = eventListCellular.begin(); it != eventListCellular.end(); it++) {
415 (*it)->getWatchValue();
421 connection_h Systeminfo::getConnectionHandle()
423 return m_connectionHandle;
426 JSValueRef Systeminfo::getCpuValue(JSContextRef context)
429 Converter converter(context);
431 CpuPropertiesPtr cpuPtr(new CpuProperties());
433 long long usr = 0, nice = 0, system = 0, idle = 0, cpuUsage = 0, diffIdle = 0, total = 0;
435 fp = fopen("/proc/stat", "r");
437 return JSValueMakeNull(context);
440 if (fscanf(fp, "%*s %lld %lld %lld %lld", &usr, &system, &nice, &idle) > 0) {
441 total = usr + nice + system + idle - m_cpuInfo.usr - m_cpuInfo.nice - m_cpuInfo.system - m_cpuInfo.idle;
442 diffIdle = idle-m_cpuInfo.idle;
443 if ((total > 0LL) && (diffIdle > 0LL)) {
444 cpuUsage = diffIdle * 100LL / total;
445 cpuPtr->load = (double)cpuUsage / 100.0;
447 m_cpuInfo.system = system;
448 m_cpuInfo.nice = nice;
449 m_cpuInfo.idle = idle;
450 LoggerD("cpu load : " << cpuPtr->load);
455 return JSCpuInfo::createJSObject(context, cpuPtr);
458 void Systeminfo::OnRequestReceived(const EventGetSysteminfoPtr& event)
461 event->processGetValue((void *)m_connectionHandle);
464 void Systeminfo::OnRequestReceived(const EventWatchSysteminfoPtr& event)
466 WatchOption watchOption = event->getWatchOption();
468 event->switchToManualAnswer();
469 event->setCancelAllowed(true);
471 switch(event->getWatchType()) {
472 case WATCH_TYPE_BATTERY:
473 if ((m_EventMgrPtr->getEventBatteryList()).size() == 1) {
474 vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, BatteryValueCallback, (void *)this);
475 vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, BatteryValueCallback, (void *)this);
478 case WATCH_TYPE_DISPLAY:
479 if ((m_EventMgrPtr->getEventDisplayList()).size() == 1) {
480 vconf_notify_key_changed(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, DisplayValueCallback, (void *)this);
483 case WATCH_TYPE_NETWORK:
484 if ((m_EventMgrPtr->getEventNetworkList()).size() == 1) {
485 connection_set_type_changed_cb(m_connectionHandle, NetworkTypeValueCallback, (void *)this);
488 case WATCH_TYPE_WIFINETWORK:
489 if ((m_EventMgrPtr->getEventWifiNetworkList()).size() == 1) {
490 if (m_networkRegist == REGIST_NOT) {
491 connection_set_ip_address_changed_cb(m_connectionHandle, NetworkValueCallback, (void *)this);
492 m_networkRegist = REGIST_WIFI;
493 } else if (m_networkRegist== REGIST_CELLULAR) {
494 m_networkRegist = REGIST_ALL;
498 case WATCH_TYPE_CELLULARNETWORK:
499 if ((m_EventMgrPtr->getEventCellularNetworkList()).size() == 1) {
500 vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, CellularNetworkValueCallback, (void *)this);
501 if (m_networkRegist == REGIST_NOT) {
502 connection_set_ip_address_changed_cb(m_connectionHandle, NetworkValueCallback, (void *)this);
503 m_networkRegist = REGIST_CELLULAR;
504 } else if (m_networkRegist== REGIST_WIFI) {
505 m_networkRegist = REGIST_ALL;
509 case WATCH_TYPE_STORAGE:
510 if ((m_EventMgrPtr->getEventStorageList()).size() == 1) {
511 if (!m_storageTimer) {
512 m_storageTimer = ecore_timer_add(1, StorageValueCallback, this);
513 ecore_timer_thaw(m_storageTimer);
518 if ((m_EventMgrPtr->getEventCpuList()).size() == 1) {
520 m_cpuTimer = ecore_timer_add(1, CpuValueCallback, this);
521 ecore_timer_thaw(m_cpuTimer);
525 case WATCH_TYPE_DEVICE_ORIENTATION:
526 LoggerD("regist sensor");
527 if ((m_EventMgrPtr->getEventDeviceOrientationList()).size() == 1) {
528 int state = sf_register_event(m_sensorHandle, ACCELEROMETER_EVENT_ROTATION_CHECK, NULL, OrientationValueCallback, (void *)this);
530 LoggerD("sensor_register_cb fail to gather data");
531 } else if (state == 0) {
532 LoggerD("sensor_register_cb success to gather data");
535 LoggerD("already regist");
538 case WATCH_TYPE_LOCALE:
539 if ((m_EventMgrPtr->getEventLocaleList()).size() == 1) {
540 if (runtime_info_set_changed_cb(RUNTIME_INFO_KEY_REGION, localeChangedCallback, (void *)this) != RUNTIME_INFO_ERROR_NONE) {
541 LoggerE("regist failed");
542 Throw(WrtDeviceApis::Commons::Exception);
544 if (runtime_info_set_changed_cb(RUNTIME_INFO_KEY_LANGUAGE, localeChangedCallback, (void *)this) != RUNTIME_INFO_ERROR_NONE) {
545 LoggerE("regist failed");
546 Throw(WrtDeviceApis::Commons::Exception);
550 case WATCH_TYPE_PERIPHERAL:
551 if ((m_EventMgrPtr->getEventPeripheralList()).size() == 1) {
552 vconf_notify_key_changed(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, PeripheralValueCallback, (void *)this);
553 vconf_notify_key_changed(VCONFKEY_SYSMAN_HDMI, PeripheralValueCallback, (void *)this);
557 event->processGetValue();
561 ////////////////////////////////////////////////////////////////////////////////////////
563 Systeminfo::EventMgr::EventMgr()
567 Systeminfo::EventMgr::~EventMgr()
571 void Systeminfo::EventMgr::clearAllEvent()
573 DPL::Mutex::ScopedLock lock(&m_synchro);
575 while (!m_eventBatteryList.empty()) {
576 EventWatchSysteminfoPtr event = m_eventBatteryList.front();
577 LoggerD("removing EventId=" << event->getId());
579 m_eventBatteryList.pop_front();
581 while (!m_eventDisplayList.empty()) {
582 EventWatchSysteminfoPtr event = m_eventDisplayList.front();
583 LoggerD("removing EventId=" << event->getId());
585 m_eventDisplayList.pop_front();
587 while (!m_eventWifiNetworkList.empty()) {
588 EventWatchSysteminfoPtr event = m_eventWifiNetworkList.front();
589 LoggerD("removing EventId=" << event->getId());
591 m_eventWifiNetworkList.pop_front();
593 while (!m_eventCelluarNetworkList.empty()) {
594 EventWatchSysteminfoPtr event = m_eventCelluarNetworkList.front();
595 LoggerD("removing EventId=" << event->getId());
597 m_eventCelluarNetworkList.pop_front();
599 while (!m_eventStorageList.empty()) {
600 EventWatchSysteminfoPtr event = m_eventStorageList.front();
601 LoggerD("removing EventId=" << event->getId());
603 m_eventStorageList.pop_front();
605 while (!m_eventCpuList.empty()) {
606 EventWatchSysteminfoPtr event = m_eventCpuList.front();
607 LoggerD("removing EventId=" << event->getId());
609 m_eventCpuList.pop_front();
611 while (!m_eventSimList.empty()) {
612 EventWatchSysteminfoPtr event = m_eventSimList.front();
613 LoggerD("removing EventId=" << event->getId());
615 m_eventSimList.pop_front();
617 while (!m_eventDeviceOrientationList.empty()) {
618 EventWatchSysteminfoPtr event = m_eventDeviceOrientationList.front();
619 LoggerD("removing EventId=" << event->getId());
621 m_eventDeviceOrientationList.pop_front();
623 while (!m_eventLocaleList.empty()) {
624 EventWatchSysteminfoPtr event = m_eventLocaleList.front();
625 LoggerD("removing EventId=" << event->getId());
627 m_eventLocaleList.pop_front();
629 while (!m_eventPeripheralList.empty()) {
630 EventWatchSysteminfoPtr event = m_eventPeripheralList.front();
631 LoggerD("removing EventId=" << event->getId());
633 m_eventPeripheralList.pop_front();
637 void Systeminfo::EventMgr::addEvent(const EventWatchSysteminfoPtr& arg, const int watchType)
639 DPL::Mutex::ScopedLock lock(&m_synchro);
641 if (watchType == WATCH_TYPE_BATTERY){
642 m_eventBatteryList.push_back(arg);
643 LoggerD("Event Battery list size=" << m_eventBatteryList.size());
644 } else if (watchType == WATCH_TYPE_DISPLAY) {
645 m_eventDisplayList.push_back(arg);
646 LoggerD("Event display list size=" << m_eventDisplayList.size());
647 } else if (watchType == WATCH_TYPE_WIFINETWORK) {
648 m_eventWifiNetworkList.push_back(arg);
649 LoggerD("Event wifi network list size=" << m_eventWifiNetworkList.size());
650 } else if (watchType == WATCH_TYPE_CELLULARNETWORK) {
651 m_eventCelluarNetworkList.push_back(arg);
652 LoggerD("Event cellular network list size=" << m_eventCelluarNetworkList.size());
653 } else if (watchType == WATCH_TYPE_STORAGE) {
654 m_eventStorageList.push_back(arg);
655 LoggerD("Event storage list size=" << m_eventStorageList.size());
656 } else if (watchType == WATCH_TYPE_CPU) {
657 m_eventCpuList.push_back(arg);
658 LoggerD("Event cpu list size=" << m_eventCpuList.size());
659 } else if (watchType == WATCH_TYPE_SIM) {
660 m_eventSimList.push_back(arg);
661 LoggerD("Event sim list size=" << m_eventSimList.size());
662 } else if (watchType == WATCH_TYPE_DEVICE_ORIENTATION) {
663 m_eventDeviceOrientationList.push_back(arg);
664 LoggerD("Event device orientation list size=" << m_eventDeviceOrientationList.size());
665 } else if (watchType == WATCH_TYPE_NETWORK) {
666 m_eventNetworkList.push_back(arg);
667 LoggerD("Event network list size=" << m_eventNetworkList.size());
668 } else if (watchType == WATCH_TYPE_LOCALE) {
669 m_eventLocaleList.push_back(arg);
670 LoggerD("Event Locale list size=" << m_eventLocaleList.size());
671 } else if (watchType == WATCH_TYPE_PERIPHERAL) {
672 m_eventPeripheralList.push_back(arg);
673 LoggerD("Event peripheral list size=" << m_eventPeripheralList.size());
677 void Systeminfo::EventMgr::removeEvent(WatchId id, const int watchType)
679 DPL::Mutex::ScopedLock lock(&m_synchro);
680 LoggerD("Event id : " << id);
682 EventWatchSysteminfoPtr event(NULL);
684 LoggerD("trying to delete event, id=" << id);
686 if (watchType == WATCH_TYPE_BATTERY) {
687 for (EventBatteryList::iterator it = m_eventBatteryList.begin(); it != m_eventBatteryList.end(); it++) {
688 if (id == (*it)->getId()) {
694 LoggerE("event id not in the list, nothing to do");
698 LoggerD("event Battery list size=" << m_eventBatteryList.size());
699 m_eventBatteryList.remove(event);
700 LoggerD( "event removed, event Battery list size=" << m_eventBatteryList.size());
701 } else if (watchType == WATCH_TYPE_DISPLAY) {
702 for (EventDisplayList::iterator it = m_eventDisplayList.begin(); it != m_eventDisplayList.end(); it++) {
703 if (id == (*it)->getId()) {
709 LoggerE("event id not in the list, nothing to do");
713 LoggerD("event display list size=" << m_eventDisplayList.size());
714 m_eventDisplayList.remove(event);
715 LoggerD( "event removed, event display list size=" << m_eventDisplayList.size());
716 } else if (watchType == WATCH_TYPE_WIFINETWORK) {
717 for (EventWifiNetworkList::iterator it = m_eventWifiNetworkList.begin(); it != m_eventWifiNetworkList.end(); it++) {
718 if (id == (*it)->getId()) {
724 LoggerE("event id not in the list, nothing to do");
728 LoggerD("event wifi network list size=" << m_eventWifiNetworkList.size());
729 m_eventWifiNetworkList.remove(event);
730 LoggerD( "event removed, event wifi network list size=" << m_eventCelluarNetworkList.size());
731 } else if (watchType == WATCH_TYPE_CELLULARNETWORK) {
732 for (EventCellularNetworkList::iterator it = m_eventCelluarNetworkList.begin(); it != m_eventCelluarNetworkList.end(); it++) {
733 if (id == (*it)->getId()) {
739 LoggerE("event id not in the list, nothing to do");
743 LoggerD("event cellular network list size=" << m_eventCelluarNetworkList.size());
744 m_eventCelluarNetworkList.remove(event);
745 LoggerD( "event removed, event cellular network list size=" << m_eventCelluarNetworkList.size());
746 } else if (watchType == WATCH_TYPE_STORAGE) {
747 for (EventStorageList::iterator it = m_eventStorageList.begin(); it != m_eventStorageList.end(); it++) {
748 if (id == (*it)->getId()) {
754 LoggerE("event id not in the list, nothing to do");
758 LoggerD("event storage list size=" << m_eventStorageList.size());
759 m_eventStorageList.remove(event);
760 LoggerD( "event removed, event storage list size=" << m_eventStorageList.size());
761 } else if (watchType == WATCH_TYPE_CPU) {
762 for (EventCpuList::iterator it = m_eventCpuList.begin(); it != m_eventCpuList.end(); it++) {
763 if (id == (*it)->getId()) {
769 LoggerE("event id not in the list, nothing to do");
773 LoggerD("event cpu list size=" << m_eventCpuList.size());
774 m_eventCpuList.remove(event);
775 LoggerD( "event removed, event cpu list size=" << m_eventCpuList.size());
776 } else if (watchType == WATCH_TYPE_SIM) {
777 for (EventSimList::iterator it = m_eventSimList.begin(); it != m_eventSimList.end(); it++) {
778 if (id == (*it)->getId()) {
784 LoggerE("event id not in the list, nothing to do");
788 LoggerD("event sim list size=" << m_eventSimList.size());
789 m_eventSimList.remove(event);
790 LoggerD( "event removed, event sim list size=" << m_eventSimList.size());
791 } else if (watchType == WATCH_TYPE_DEVICE_ORIENTATION) {
792 for (EventDeviceOrientationList::iterator it = m_eventDeviceOrientationList.begin(); it != m_eventDeviceOrientationList.end(); it++) {
793 if (id == (*it)->getId()) {
799 LoggerE("event id not in the list, nothing to do");
803 LoggerD("event device orientation list size=" << m_eventDeviceOrientationList.size());
804 m_eventDeviceOrientationList.remove(event);
805 LoggerD( "event removed, event device orientation list size=" << m_eventDeviceOrientationList.size());
806 } else if (watchType == WATCH_TYPE_NETWORK) {
807 for (EventNetworkList::iterator it = m_eventNetworkList.begin(); it != m_eventNetworkList.end(); it++) {
808 if (id == (*it)->getId()) {
814 LoggerE("event id not in the list, nothing to do");
818 LoggerD("event network list size=" << m_eventNetworkList.size());
819 m_eventNetworkList.remove(event);
820 LoggerD( "event removed, event network list size=" << m_eventNetworkList.size());
821 } else if (watchType == WATCH_TYPE_LOCALE) {
822 for (EventLocaleList::iterator it = m_eventLocaleList.begin(); it != m_eventLocaleList.end(); it++) {
823 if (id == (*it)->getId()) {
829 LoggerE("event id not in the list, nothing to do");
833 LoggerD("event Locale list size=" << m_eventLocaleList.size());
834 m_eventLocaleList.remove(event);
835 LoggerD( "event removed, event Locale list size=" << m_eventLocaleList.size());
836 } else if (watchType == WATCH_TYPE_PERIPHERAL) {
837 for (EventPeripheralList::iterator it = m_eventPeripheralList.begin(); it != m_eventPeripheralList.end(); it++) {
838 if (id == (*it)->getId()) {
844 LoggerE("event id not in the list, nothing to do");
848 LoggerD("event peripheral list size=" << m_eventPeripheralList.size());
849 m_eventPeripheralList.remove(event);
850 LoggerD( "event removed, event peripheral list size=" << m_eventPeripheralList.size());
854 const int Systeminfo::EventMgr::getWatchType(const long id)
856 DPL::Mutex::ScopedLock lock(&m_synchro);
858 EventWatchSysteminfoPtr event(NULL);
860 for (EventBatteryList::iterator it = m_eventBatteryList.begin(); it != m_eventBatteryList.end(); it++) {
861 if (id == (*it)->getId()) {
867 for (EventDisplayList::iterator it = m_eventDisplayList.begin(); it != m_eventDisplayList.end(); it++) {
868 if (id == (*it)->getId()) {
874 for (EventWifiNetworkList::iterator it = m_eventWifiNetworkList.begin(); it != m_eventWifiNetworkList.end(); it++) {
875 if (id == (*it)->getId()) {
881 for (EventCellularNetworkList::iterator it = m_eventCelluarNetworkList.begin(); it != m_eventCelluarNetworkList.end(); it++) {
882 if (id == (*it)->getId()) {
888 for (EventStorageList::iterator it = m_eventStorageList.begin(); it != m_eventStorageList.end(); it++) {
889 if (id == (*it)->getId()) {
895 for (EventCpuList::iterator it = m_eventCpuList.begin(); it != m_eventCpuList.end(); it++) {
896 if (id == (*it)->getId()) {
902 for (EventSimList::iterator it = m_eventSimList.begin(); it != m_eventSimList.end(); it++) {
903 if (id == (*it)->getId()) {
909 for (EventDeviceOrientationList::iterator it = m_eventDeviceOrientationList.begin(); it != m_eventDeviceOrientationList.end(); it++) {
910 if (id == (*it)->getId()) {
916 for (EventNetworkList::iterator it = m_eventNetworkList.begin(); it != m_eventNetworkList.end(); it++) {
917 if (id == (*it)->getId()) {
923 for (EventSimList::iterator it = m_eventSimList.begin(); it != m_eventSimList.end(); it++) {
924 if (id == (*it)->getId()) {
930 for (EventLocaleList::iterator it = m_eventLocaleList.begin(); it != m_eventLocaleList.end(); it++) {
931 if (id == (*it)->getId()) {
937 for (EventPeripheralList::iterator it = m_eventPeripheralList.begin(); it != m_eventPeripheralList.end(); it++) {
938 if (id == (*it)->getId()) {
945 LoggerE("event id not in the list, nothing to do");
946 return WATCH_TYPE_UNKNOWN;
949 return event->getWatchType();
952 EventBatteryList Systeminfo::EventMgr::getEventBatteryList()
954 return m_eventBatteryList;
957 EventDisplayList Systeminfo::EventMgr::getEventDisplayList()
959 return m_eventDisplayList;
962 EventNetworkList Systeminfo::EventMgr::getEventNetworkList()
964 return m_eventNetworkList;
967 EventWifiNetworkList Systeminfo::EventMgr::getEventWifiNetworkList()
969 return m_eventWifiNetworkList;
972 EventCellularNetworkList Systeminfo::EventMgr::getEventCellularNetworkList()
974 return m_eventCelluarNetworkList;
977 EventStorageList Systeminfo::EventMgr::getEventStorageList()
979 return m_eventStorageList;
982 EventCpuList Systeminfo::EventMgr::getEventCpuList()
984 return m_eventCpuList;
987 EventDeviceOrientationList Systeminfo::EventMgr::getEventDeviceOrientationList()
989 return m_eventDeviceOrientationList;
992 EventSimList Systeminfo::EventMgr::getEventSimList()
994 return m_eventSimList;
997 EventLocaleList Systeminfo::EventMgr::getEventLocaleList()
999 return m_eventLocaleList;
1002 EventPeripheralList Systeminfo::EventMgr::getEventPeripheralList()
1004 return m_eventPeripheralList;
1007 ////////////////////////////////////////////////////////////////////////////////////////
1009 PROPERTY_GET_SYSTEMINFO_DEFINITION(Battery) {
1010 BatteryPropertiesPtr BatteryPtr(new BatteryProperties());
1014 if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, &value) != 0) {
1015 return JSValueMakeNull(context);
1017 BatteryPtr->level = (double)(value)/CPU_POWER_DEVICE_VALUE;
1020 if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &value2) != 0) {
1021 return JSValueMakeNull(context);
1023 BatteryPtr->isCharging = (value2 == 0) ? false : true;
1026 return JSBatteryInfo::createJSObject(context, BatteryPtr);
1029 PROPERTY_GET_SYSTEMINFO_DEFINITION(Cpu) {
1030 Converter converter(context);
1032 CpuPropertiesPtr cpuPtr(new CpuProperties());
1034 long long usr = 0, nice = 0, system = 0, idle = 0, total = 0, cpuUsage = 0;
1036 fp = fopen("/proc/stat", "r");
1038 return JSValueMakeNull(context);
1041 if (fscanf(fp, "%*s %lld %lld %lld %lld", &usr, &system, &nice, &idle) > 0) {
1042 total = usr + nice + system + idle;
1043 if ((total > 0LL) && (idle > 0LL)) {
1044 cpuUsage = idle * 100LL / total;
1045 cpuPtr->load = (double)cpuUsage / 100.0;
1046 LoggerD("cpu load : " << cpuPtr->load);
1051 return JSCpuInfo::createJSObject(context, cpuPtr);
1054 PROPERTY_GET_SYSTEMINFO_DEFINITION(Storage) {
1055 Converter converter(context);
1060 StoragePropertiesPtr internal(new StorageProperties());
1061 StoragePropertiesPtr mmc(new StorageProperties());
1062 StoragePropertiesPtr usbhost(new StorageProperties());
1063 std::vector <JSObjectRef> storagelist;
1065 if (statfs(STORAGE_INTERNAL_PATH, &fs) < 0) {
1066 return JSValueMakeNull(context);
1069 internal->type = "INTERNAL";
1070 internal->capacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_blocks;
1071 internal->availableCapacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_bavail;
1072 internal->isRemoveable = false;
1073 internal->isRemovable = false;
1074 storagelist.push_back(JSStorageInfo::createJSObject(context, internal));
1077 if(vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &sdcardState) == 0){
1078 if(sdcardState == VCONFKEY_SYSMAN_MMC_MOUNTED){
1080 if (statfs(STORAGE_SDCARD_PATH, &fs) < 0) {
1081 return JSValueMakeNull(context);
1084 mmc->capacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_blocks;
1085 mmc->availableCapacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_bavail;
1086 mmc->isRemoveable = true;
1087 mmc->isRemovable = true;
1088 storagelist.push_back(JSStorageInfo::createJSObject(context, mmc));
1092 if(vconf_get_int(VCONFKEY_SYSMAN_USB_HOST_STATUS, &usbhostState) == 0) {
1093 if(usbhostState == VCONFKEY_SYSMAN_USB_HOST_CONNECTED) {
1095 if (statfs(STORAGE_USBHOST_PATH, &fs) < 0) {
1096 return JSValueMakeNull(context);
1098 usbhost->type = "USB_HOST";
1099 usbhost->capacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_blocks;
1100 usbhost->availableCapacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_bavail;
1101 usbhost->isRemoveable = true;
1102 usbhost->isRemovable = true;
1103 storagelist.push_back(JSStorageInfo::createJSObject(context, usbhost));
1107 return JSObjectMakeArray(context, storageCnt, storagelist.data(), NULL);
1110 PROPERTY_GET_SYSTEMINFO_DEFINITION(Display) {
1111 Converter converter(context);
1113 DisplayPropertiesPtr display(new DisplayProperties());
1114 int brightness=0, dotsPerInchX=0, dotsPerInchY=0, physicalW=0, physicalH=0, resolutionW=0, resolutionH=0;
1116 if(vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, &brightness) == 0) {
1117 display->brightness = (double)(brightness)/DISPLAY_BRIGHTNESS_DIVIDE_VALUE;
1118 LoggerD("brightness : " << display->brightness);
1121 if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_WIDTH, &resolutionW) == SYSTEM_INFO_ERROR_NONE) {
1122 display->resolutionWidth = resolutionW;
1123 LoggerD("resolutionWidth : " << display->resolutionWidth);
1125 if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_HEIGHT, &resolutionH) == SYSTEM_INFO_ERROR_NONE) {
1126 display->resolutionHeight = resolutionH;
1127 LoggerD("resolutionHeight : " << display->resolutionHeight);
1129 if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_DPI, &dotsPerInchX) == SYSTEM_INFO_ERROR_NONE) {
1130 display->dotsPerInchWidth = dotsPerInchX;
1131 LoggerD("dotsPerInchWidth : " << display->dotsPerInchWidth);
1133 if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_DPI, &dotsPerInchY) == SYSTEM_INFO_ERROR_NONE) {
1134 display->dotsPerInchHeight = dotsPerInchY;
1135 LoggerD("dotsPerInchHeight : " << display->dotsPerInchHeight);
1137 if (system_info_get_value_int(SYSTEM_INFO_KEY_PHYSICAL_SCREEN_HEIGHT, &physicalH) == SYSTEM_INFO_ERROR_NONE) {
1138 display->physicalHeight = physicalH;
1139 LoggerD("physicalHeight : " << display->physicalHeight);
1141 if (system_info_get_value_int(SYSTEM_INFO_KEY_PHYSICAL_SCREEN_WIDTH, &physicalW) == SYSTEM_INFO_ERROR_NONE) {
1142 display->physicalWidth = physicalW;
1143 LoggerD("physicalWidth : " << display->physicalWidth);
1146 return JSDisplayInfo::createJSObject(context, display);
1149 PROPERTY_GET_SYSTEMINFO_DEFINITION(Network) {
1151 Converter converter(context);
1152 NetworkPropertiesPtr Network(new NetworkProperties());
1153 connection_h connectionHandle = (connection_h)handle;
1154 connection_type_e connectionType;
1155 int networkType = 0;
1157 if (connection_get_type(connectionHandle, &connectionType) != CONNECTION_ERROR_NONE) {
1158 LoggerD("get connection type is failed");
1159 return JSNetworkInfo::createJSObject(context, Network);
1162 if (connectionType == CONNECTION_TYPE_WIFI) {
1163 LoggerD("wifi network");
1164 Network->networkType= "WIFI";
1165 } else if (connectionType == CONNECTION_TYPE_CELLULAR) {
1166 if (vconf_get_int(VCONFKEY_TELEPHONY_SVCTYPE, &networkType) == 0) {
1167 if (networkType < VCONFKEY_TELEPHONY_SVCTYPE_2G) {
1168 Network->networkType= "NONE";
1169 } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_2G) {
1170 Network->networkType= "2G";
1171 } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_2G || networkType == VCONFKEY_TELEPHONY_SVCTYPE_2_5G_EDGE) {
1172 Network->networkType= "2.5";
1173 } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_3G || networkType == VCONFKEY_TELEPHONY_SVCTYPE_HSDPA) {
1174 Network->networkType= "3G";
1175 } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_LTE) {
1176 Network->networkType= "4G";
1178 Network->networkType= "NONE";
1182 Network->networkType= "NONE";
1185 return JSNetworkInfo::createJSObject(context, Network);
1188 PROPERTY_GET_SYSTEMINFO_DEFINITION(WifiNetwork) {
1189 Converter converter(context);
1190 WifiNetworkPropertiesPtr wifiNetwork(new WifiNetworkProperties());
1191 connection_h connectionHandle = (connection_h)handle;
1192 connection_type_e connectionType;
1193 connection_profile_h profileHandle = NULL;
1194 connection_address_family_e addressFamily = CONNECTION_ADDRESS_FAMILY_IPV4;
1195 char* ipAddr = NULL;
1199 if (connection_get_type(connectionHandle, &connectionType) != CONNECTION_ERROR_NONE) {
1200 return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1203 if (connectionType == CONNECTION_TYPE_WIFI) {
1204 wifiNetwork->status = "ON";
1206 wifiNetwork->status = "OFF";
1207 return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1210 if (connection_get_current_profile(connectionHandle, &profileHandle) != CONNECTION_ERROR_NONE) {
1211 return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1214 if (connection_profile_get_wifi_essid(profileHandle, &essid) == CONNECTION_ERROR_NONE) {
1215 wifiNetwork->ssid = essid;
1219 if (connection_profile_get_ip_address(profileHandle, addressFamily, &ipAddr) == CONNECTION_ERROR_NONE) {
1220 wifiNetwork->ipAddress = ipAddr;
1224 if (connection_profile_get_wifi_rssi(profileHandle, &rssi) == CONNECTION_ERROR_NONE) {
1225 wifiNetwork->signalStrength = (double) rssi/WIFI_SIGNAL_STRENGTH_DIVIDE_VALUE;
1228 return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1231 PROPERTY_GET_SYSTEMINFO_DEFINITION(CellularNetwork) {
1232 Converter converter(context);
1233 CellularNetworkPropertiesPtr cellularNetwork(new CellularNetworkProperties());
1234 connection_h connectionHandle = (connection_h)handle;
1235 connection_type_e connectionType;
1236 connection_profile_h profileHandle = NULL;
1237 connection_address_family_e addressFamily = CONNECTION_ADDRESS_FAMILY_IPV4;
1238 char* ipAddr = NULL;
1241 int plmn = 0, cellId = 0, lac = 0, isRoaming = 0, isFlightMode = 0;
1243 TIME_TRACER_ITEM_BEGIN("(cellular)mcc", 0);
1244 if (vconf_get_int(VCONFKEY_TELEPHONY_PLMN, &plmn) == 0) {
1245 cellularNetwork->mcc = plmn / 100;
1246 cellularNetwork->mnc = plmn % 100;
1248 TIME_TRACER_ITEM_END("(cellular)mcc", 0);
1250 TIME_TRACER_ITEM_BEGIN("(cellular)cellId", 0);
1251 if (vconf_get_int(VCONFKEY_TELEPHONY_CELLID, &cellId) == 0) {
1252 cellularNetwork->cellId = cellId;
1254 TIME_TRACER_ITEM_END("(cellular)cellId", 0);
1256 TIME_TRACER_ITEM_BEGIN("(cellular)lac", 0);
1257 if (vconf_get_int(VCONFKEY_TELEPHONY_LAC, &lac) == 0) {
1258 cellularNetwork->lac = lac;
1260 TIME_TRACER_ITEM_END("(cellular)lac", 0);
1262 TIME_TRACER_ITEM_BEGIN("(cellular)isRoaming", 0);
1263 if (vconf_get_int(VCONFKEY_TELEPHONY_SVC_ROAM, &isRoaming) == 0) {
1265 cellularNetwork->isRoaming = true;
1267 cellularNetwork->isRoaming = false;
1270 TIME_TRACER_ITEM_END("(cellular)isRoaming", 0);
1272 TIME_TRACER_ITEM_BEGIN("(cellular)isFlightMode", 0);
1273 if (vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &isFlightMode) == 0) {
1275 cellularNetwork->isFlightMode = true;
1277 cellularNetwork->isFlightMode = false;
1280 TIME_TRACER_ITEM_END("(cellular)isFlightMode", 0);
1282 if (connection_get_type(connectionHandle, &connectionType) != CONNECTION_ERROR_NONE) {
1283 return JSCellularNetworkInfo::createJSObject(context, cellularNetwork);
1286 if (connectionType == CONNECTION_TYPE_CELLULAR) {
1287 cellularNetwork->status = "ON";
1288 if (connection_get_current_profile(connectionHandle, &profileHandle) == CONNECTION_ERROR_NONE) {
1289 TIME_TRACER_ITEM_BEGIN("(cellular)apn", 0);
1290 if (connection_profile_get_cellular_apn(profileHandle, &apn) == CONNECTION_ERROR_NONE) {
1291 cellularNetwork->apn = apn;
1294 TIME_TRACER_ITEM_END("(cellular)apn", 0);
1296 TIME_TRACER_ITEM_BEGIN("(cellular)ipAddress", 0);
1297 if (connection_profile_get_ip_address(profileHandle, addressFamily, &ipAddr) == CONNECTION_ERROR_NONE) {
1298 cellularNetwork->ipAddress = ipAddr;
1301 TIME_TRACER_ITEM_END("(cellular)ipAddress", 0);
1302 connection_profile_destroy(profileHandle);
1305 cellularNetwork->status = "OFF";
1306 if (connection_get_default_cellular_service_profile(connectionHandle, CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET, &profileHandle) == CONNECTION_ERROR_NONE) {
1307 TIME_TRACER_ITEM_BEGIN("(cellular)apn", 0);
1308 if (connection_profile_get_cellular_apn(profileHandle, &apn) == CONNECTION_ERROR_NONE) {
1309 cellularNetwork->apn = apn;
1312 TIME_TRACER_ITEM_END("(cellular)apn", 0);
1313 connection_profile_destroy(profileHandle);
1317 TIME_TRACER_ITEM_BEGIN("(cellular)imei", 0);
1318 if (system_info_get_value_string(SYSTEM_INFO_KEY_MOBILE_DEVICE_ID, &imei) == SYSTEM_INFO_ERROR_NONE) {
1320 LoggerD("imei : " << imei);
1321 cellularNetwork->imei = imei;
1325 TIME_TRACER_ITEM_END("(cellular)imei", 0);
1327 return JSCellularNetworkInfo::createJSObject(context, cellularNetwork);
1330 PROPERTY_GET_SYSTEMINFO_DEFINITION(SIM) {
1331 Converter converter(context);
1332 SIMPropertiesPtr SIM(new SIMProperties());
1333 return JSSIMInfo::createJSObject(context, SIM);
1336 PROPERTY_GET_SYSTEMINFO_DEFINITION(DeviceOrientation) {
1338 Converter converter(context);
1339 DeviceOrientationPropertiesPtr deviceOrientation(new DeviceOrientationProperties());
1341 unsigned long rotation = 0;
1342 int handleOrientaion = 0;
1344 handleOrientaion = sf_connect(ACCELEROMETER_SENSOR);
1345 LoggerD("handleOrientaion : " << handleOrientaion);
1346 if (handleOrientaion < 0) {
1347 LoggerD ("sensor attach fail");
1348 return JSDeviceOrientationInfo::createJSObject(context, deviceOrientation);
1350 int state = sf_start(handleOrientaion, 0);
1352 LoggerD("start failed");
1355 int ret_val = sf_check_rotation(&rotation);
1357 LoggerD("sf_check_rotation fail to gather data\n");
1360 LoggerD(" rotation value = " << rotation);
1364 case ROTATION_EVENT_0:
1365 LoggerD("my_callback_func received data (PORTRAIT_TOP|HEAD_CENTER)\n");
1366 deviceOrientation->status = "PORTRAIT_PRIMARY";
1368 case ROTATION_EVENT_90:
1369 LoggerD("my_callback_func received data (LANDSCAPE|HEAD_RIGHT)\n");
1370 deviceOrientation->status = "LANDSCAPE_PRIMARY";
1372 case ROTATION_EVENT_180:
1373 LoggerD("my_callback_func received data (PORTRAIT_BTM|HEAD_CENTER)\n");
1374 deviceOrientation->status = "PORTRAIT_SECONDARY";
1376 case ROTATION_EVENT_270:
1377 LoggerD("my_callback_func received data (LANDSCAPE|HEAD_LEFT)\n");
1378 deviceOrientation->status = "LANDSCAPE_SECONDARY";
1381 LoggerD(" received data unexpected\n");
1385 state = sf_stop(handleOrientaion);
1386 LoggerD("handleOrientaion 1 state = " << state);
1388 state = sf_disconnect(handleOrientaion);
1389 LoggerD("handleOrientaion state =" << state);
1391 return JSDeviceOrientationInfo::createJSObject(context, deviceOrientation);
1394 PROPERTY_GET_SYSTEMINFO_DEFINITION(Build) {
1396 Converter converter(context);
1397 BuildPropertiesPtr Build(new BuildProperties());
1400 char* manufacturer = NULL;
1402 if (system_info_get_value_string(SYSTEM_INFO_KEY_MODEL, &model) == SYSTEM_INFO_ERROR_NONE) {
1403 if (model != NULL) {
1404 LoggerD("model : " << model);
1405 Build->model = model;
1410 if (system_info_get_value_string(SYSTEM_INFO_KEY_MANUFACTURER, &manufacturer) == SYSTEM_INFO_ERROR_NONE) {
1411 if (manufacturer != NULL) {
1412 LoggerD("manufacturer : " << manufacturer);
1413 Build->manufacturer = manufacturer;
1418 return JSBuildInfo::createJSObject(context, Build);
1421 PROPERTY_GET_SYSTEMINFO_DEFINITION(Locale) {
1423 Converter converter(context);
1424 LocalePropertiesPtr Locale(new LocaleProperties());
1426 char* country = NULL;
1427 char* language = NULL;
1429 if (runtime_info_get_value_string(RUNTIME_INFO_KEY_LANGUAGE, &language) == RUNTIME_INFO_ERROR_NONE) {
1430 if (language != NULL) {
1431 LoggerD("language : " << language);
1432 Locale->language = language;
1437 if (runtime_info_get_value_string(RUNTIME_INFO_KEY_REGION, &country) == RUNTIME_INFO_ERROR_NONE) {
1438 LoggerD("country : " << country);
1440 char* countryTemp = NULL;
1441 token = strtok(country, ".");
1442 if (token != NULL) {
1443 countryTemp = strdup(token);
1444 if (countryTemp != NULL) {
1445 Locale->country = countryTemp;
1447 if (countryTemp != NULL) {
1450 if (country != NULL) {
1456 return JSLocaleInfo::createJSObject(context, Locale);
1459 PROPERTY_GET_SYSTEMINFO_DEFINITION(Peripheral) {
1460 Converter converter(context);
1461 PeripheralPropertiesPtr peripheral(new PeripheralProperties());
1462 int hdmiStatus = 0, wirelessDisplayStatus = 0 ;
1464 if (vconf_get_int(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, &wirelessDisplayStatus) == 0) {
1465 switch(wirelessDisplayStatus) {
1466 case VCONFKEY_MIRACAST_WFD_SOURCE_ON:
1467 peripheral->isVideoOutputOn = true;
1470 LoggerD("VideOutput status is off");
1475 if (vconf_get_int(VCONFKEY_SYSMAN_HDMI, &hdmiStatus) == 0) {
1476 switch(hdmiStatus) {
1477 case VCONFKEY_SYSMAN_HDMI_CONNECTED:
1478 peripheral->isVideoOutputOn = true;
1481 LoggerD("VideOutput status is off");
1486 return JSPeripheralInfo::createJSObject(context, peripheral);