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 vconf_ignore_key_changed(VCONFKEY_TELEPHONY_SVC_ROAM, CellularNetworkValueCallback);
271 if (m_networkRegist == REGIST_CELLULAR) {
272 connection_unset_ip_address_changed_cb(m_connectionHandle);
273 m_networkRegist = REGIST_NOT;
274 } else if (m_networkRegist== REGIST_ALL) {
275 m_networkRegist = REGIST_WIFI;
279 case WATCH_TYPE_STORAGE:
280 if ((m_EventMgrPtr->getEventStorageList()).size() == 1) {
281 if (m_storageTimer) {
282 ecore_timer_freeze(m_storageTimer);
283 ecore_timer_del(m_storageTimer);
284 m_storageTimer = NULL;
289 if ((m_EventMgrPtr->getEventCpuList()).size() == 1) {
291 ecore_timer_freeze(m_cpuTimer);
292 ecore_timer_del(m_cpuTimer);
297 case WATCH_TYPE_DEVICE_ORIENTATION:
298 if ((m_EventMgrPtr->getEventDeviceOrientationList()).size() == 1) {
299 int state = sf_unregister_event(m_sensorHandle, ACCELEROMETER_EVENT_ROTATION_CHECK);
301 LoggerD("sf_unregister_event fail to gather data\n");
305 case WATCH_TYPE_LOCALE:
306 if ((m_EventMgrPtr->getEventLocaleList()).size() == 1) {
307 if (runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_LANGUAGE) != RUNTIME_INFO_ERROR_NONE) {
308 LoggerE("regist failed");
309 Throw(WrtDeviceApis::Commons::Exception);
311 if (runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_REGION) != RUNTIME_INFO_ERROR_NONE) {
312 LoggerE("regist failed");
313 Throw(WrtDeviceApis::Commons::Exception);
317 case WATCH_TYPE_PERIPHERAL:
318 if ((m_EventMgrPtr->getEventPeripheralList()).size() == 1) {
319 vconf_ignore_key_changed(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, PeripheralValueCallback);
320 vconf_ignore_key_changed(VCONFKEY_SYSMAN_HDMI, PeripheralValueCallback);
323 case WATCH_TYPE_UNKNOWN:
324 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
327 m_EventMgrPtr->removeEvent(id, watchType);
331 BasePropertyPtr Systeminfo::getBasePropertyPtr(JSContextRef context, JSValueRef property)
333 Converter converter(context);
334 std::string l_property = converter.toString(property);
335 mapProperties::iterator it = (*m_Property).find(l_property);
336 if (it == (*m_Property).end()) {
337 LoggerE("not existing property");
338 Throw(WrtDeviceApis::Commons::ConversionException);
339 return BasePropertyPtr(NULL);
345 void Systeminfo::getWatchValue(const int watchType)
347 LoggerD(" watch type : " << watchType);
349 if (watchType == WATCH_TYPE_BATTERY) {
350 EventBatteryList eventList = m_EventMgrPtr->getEventBatteryList();
351 for (EventBatteryList::iterator it = eventList.begin(); it != eventList.end(); it++) {
352 (*it)->getWatchValue();
354 } else if (watchType == WATCH_TYPE_DISPLAY) {
355 EventDisplayList eventList = m_EventMgrPtr->getEventDisplayList();
356 for (EventDisplayList::iterator it = eventList.begin(); it != eventList.end(); it++) {
357 (*it)->getWatchValue();
359 } else if (watchType == WATCH_TYPE_NETWORK) {
360 EventNetworkList eventList = m_EventMgrPtr->getEventNetworkList();
361 for (EventNetworkList::iterator it = eventList.begin(); it != eventList.end(); it++) {
362 (*it)->getWatchValue();
364 } else if (watchType == WATCH_TYPE_NETWORK_ALL) {
365 EventWifiNetworkList eventListWifi = m_EventMgrPtr->getEventWifiNetworkList();
366 EventWifiNetworkList eventListCellular = m_EventMgrPtr->getEventCellularNetworkList();
367 if (eventListWifi.size() > 0) {
368 for (EventWifiNetworkList::iterator it = eventListWifi.begin(); it != eventListWifi.end(); it++) {
369 (*it)->getWatchValue();
372 if (eventListCellular.size() > 0) {
373 for (EventCellularNetworkList::iterator it = eventListCellular.begin(); it != eventListCellular.end(); it++) {
374 (*it)->getWatchValue();
377 } else if (watchType == WATCH_TYPE_CPU) {
378 EventCpuList eventList = m_EventMgrPtr->getEventCpuList();
379 for (EventCpuList::iterator it = eventList.begin(); it != eventList.end(); it++) {
380 (*it)->getWatchValue();
382 } else if (watchType == WATCH_TYPE_STORAGE) {
383 EventStorageList eventList = m_EventMgrPtr->getEventStorageList();
384 for (EventStorageList::iterator it = eventList.begin(); it != eventList.end(); it++) {
387 int usbhostState = 0;
388 if(vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &sdcardState) == 0) {
389 if(sdcardState == VCONFKEY_SYSMAN_MMC_MOUNTED) {
393 if(vconf_get_int(VCONFKEY_SYSMAN_USB_HOST_STATUS, &usbhostState) == 0) {
394 if(usbhostState == VCONFKEY_SYSMAN_USB_HOST_CONNECTED) {
398 LoggerD("storage cnt : " << storageCnt);
399 (*it)->getWatchValue(storageCnt);
401 }else if (watchType == WATCH_TYPE_DEVICE_ORIENTATION) {
402 EventDeviceOrientationList eventList = m_EventMgrPtr->getEventDeviceOrientationList();
403 for (EventDeviceOrientationList::iterator it = eventList.begin(); it != eventList.end(); it++) {
404 (*it)->getWatchValue();
406 } else if (watchType == WATCH_TYPE_LOCALE) {
407 EventLocaleList eventList = m_EventMgrPtr->getEventLocaleList();
408 for (EventLocaleList::iterator it = eventList.begin(); it != eventList.end(); it++) {
409 (*it)->getWatchValue();
411 } else if (watchType == WATCH_TYPE_PERIPHERAL) {
412 EventPeripheralList eventList = m_EventMgrPtr->getEventPeripheralList();
413 for (EventPeripheralList::iterator it = eventList.begin(); it != eventList.end(); it++) {
414 (*it)->getWatchValue();
416 } else if (watchType == WATCH_TYPE_CELLULARNETWORK) {
417 EventWifiNetworkList eventListCellular = m_EventMgrPtr->getEventCellularNetworkList();
418 if (eventListCellular.size() > 0) {
419 for (EventCellularNetworkList::iterator it = eventListCellular.begin(); it != eventListCellular.end(); it++) {
420 (*it)->getWatchValue();
426 connection_h Systeminfo::getConnectionHandle()
428 return m_connectionHandle;
431 JSValueRef Systeminfo::getCpuValue(JSContextRef context)
434 Converter converter(context);
436 CpuPropertiesPtr cpuPtr(new CpuProperties());
438 long long usr = 0, nice = 0, system = 0, idle = 0, cpuUsage = 0, diffIdle = 0, total = 0;
440 fp = fopen("/proc/stat", "r");
442 return JSValueMakeNull(context);
445 if (fscanf(fp, "%*s %lld %lld %lld %lld", &usr, &system, &nice, &idle) > 0) {
446 total = usr + nice + system + idle - m_cpuInfo.usr - m_cpuInfo.nice - m_cpuInfo.system - m_cpuInfo.idle;
447 diffIdle = idle-m_cpuInfo.idle;
448 if ((total > 0LL) && (diffIdle > 0LL)) {
449 cpuUsage = diffIdle * 100LL / total;
450 cpuPtr->load = (double)cpuUsage / 100.0;
452 m_cpuInfo.system = system;
453 m_cpuInfo.nice = nice;
454 m_cpuInfo.idle = idle;
455 LoggerD("cpu load : " << cpuPtr->load);
460 return JSCpuInfo::createJSObject(context, cpuPtr);
463 void Systeminfo::OnRequestReceived(const EventGetSysteminfoPtr& event)
466 event->processGetValue((void *)m_connectionHandle);
469 void Systeminfo::OnRequestReceived(const EventWatchSysteminfoPtr& event)
471 WatchOption watchOption = event->getWatchOption();
473 event->switchToManualAnswer();
474 event->setCancelAllowed(true);
476 switch(event->getWatchType()) {
477 case WATCH_TYPE_BATTERY:
478 if ((m_EventMgrPtr->getEventBatteryList()).size() == 1) {
479 vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, BatteryValueCallback, (void *)this);
480 vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, BatteryValueCallback, (void *)this);
483 case WATCH_TYPE_DISPLAY:
484 if ((m_EventMgrPtr->getEventDisplayList()).size() == 1) {
485 vconf_notify_key_changed(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, DisplayValueCallback, (void *)this);
488 case WATCH_TYPE_NETWORK:
489 if ((m_EventMgrPtr->getEventNetworkList()).size() == 1) {
490 connection_set_type_changed_cb(m_connectionHandle, NetworkTypeValueCallback, (void *)this);
493 case WATCH_TYPE_WIFINETWORK:
494 if ((m_EventMgrPtr->getEventWifiNetworkList()).size() == 1) {
495 if (m_networkRegist == REGIST_NOT) {
496 connection_set_ip_address_changed_cb(m_connectionHandle, NetworkValueCallback, (void *)this);
497 m_networkRegist = REGIST_WIFI;
498 } else if (m_networkRegist== REGIST_CELLULAR) {
499 m_networkRegist = REGIST_ALL;
503 case WATCH_TYPE_CELLULARNETWORK:
504 if ((m_EventMgrPtr->getEventCellularNetworkList()).size() == 1) {
505 vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, CellularNetworkValueCallback, (void *)this);
506 vconf_notify_key_changed(VCONFKEY_TELEPHONY_CELLID, CellularNetworkValueCallback, (void *)this);
507 vconf_notify_key_changed(VCONFKEY_TELEPHONY_LAC, CellularNetworkValueCallback, (void *)this);
508 vconf_notify_key_changed(VCONFKEY_TELEPHONY_SVC_ROAM, CellularNetworkValueCallback, (void *)this);
509 if (m_networkRegist == REGIST_NOT) {
510 connection_set_ip_address_changed_cb(m_connectionHandle, NetworkValueCallback, (void *)this);
511 m_networkRegist = REGIST_CELLULAR;
512 } else if (m_networkRegist== REGIST_WIFI) {
513 m_networkRegist = REGIST_ALL;
517 case WATCH_TYPE_STORAGE:
518 if ((m_EventMgrPtr->getEventStorageList()).size() == 1) {
519 if (!m_storageTimer) {
520 m_storageTimer = ecore_timer_add(1, StorageValueCallback, this);
521 ecore_timer_thaw(m_storageTimer);
526 if ((m_EventMgrPtr->getEventCpuList()).size() == 1) {
528 m_cpuTimer = ecore_timer_add(1, CpuValueCallback, this);
529 ecore_timer_thaw(m_cpuTimer);
533 case WATCH_TYPE_DEVICE_ORIENTATION:
534 LoggerD("regist sensor");
535 if ((m_EventMgrPtr->getEventDeviceOrientationList()).size() == 1) {
536 int state = sf_register_event(m_sensorHandle, ACCELEROMETER_EVENT_ROTATION_CHECK, NULL, OrientationValueCallback, (void *)this);
538 LoggerD("sensor_register_cb fail to gather data");
539 } else if (state == 0) {
540 LoggerD("sensor_register_cb success to gather data");
543 LoggerD("already regist");
546 case WATCH_TYPE_LOCALE:
547 if ((m_EventMgrPtr->getEventLocaleList()).size() == 1) {
548 if (runtime_info_set_changed_cb(RUNTIME_INFO_KEY_REGION, localeChangedCallback, (void *)this) != RUNTIME_INFO_ERROR_NONE) {
549 LoggerE("regist failed");
550 Throw(WrtDeviceApis::Commons::Exception);
552 if (runtime_info_set_changed_cb(RUNTIME_INFO_KEY_LANGUAGE, localeChangedCallback, (void *)this) != RUNTIME_INFO_ERROR_NONE) {
553 LoggerE("regist failed");
554 Throw(WrtDeviceApis::Commons::Exception);
558 case WATCH_TYPE_PERIPHERAL:
559 if ((m_EventMgrPtr->getEventPeripheralList()).size() == 1) {
560 vconf_notify_key_changed(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, PeripheralValueCallback, (void *)this);
561 vconf_notify_key_changed(VCONFKEY_SYSMAN_HDMI, PeripheralValueCallback, (void *)this);
565 event->processGetValue();
569 ////////////////////////////////////////////////////////////////////////////////////////
571 Systeminfo::EventMgr::EventMgr()
575 Systeminfo::EventMgr::~EventMgr()
579 void Systeminfo::EventMgr::clearAllEvent()
581 DPL::Mutex::ScopedLock lock(&m_synchro);
583 while (!m_eventBatteryList.empty()) {
584 EventWatchSysteminfoPtr event = m_eventBatteryList.front();
585 LoggerD("removing EventId=" << event->getId());
587 m_eventBatteryList.pop_front();
589 while (!m_eventDisplayList.empty()) {
590 EventWatchSysteminfoPtr event = m_eventDisplayList.front();
591 LoggerD("removing EventId=" << event->getId());
593 m_eventDisplayList.pop_front();
595 while (!m_eventWifiNetworkList.empty()) {
596 EventWatchSysteminfoPtr event = m_eventWifiNetworkList.front();
597 LoggerD("removing EventId=" << event->getId());
599 m_eventWifiNetworkList.pop_front();
601 while (!m_eventCelluarNetworkList.empty()) {
602 EventWatchSysteminfoPtr event = m_eventCelluarNetworkList.front();
603 LoggerD("removing EventId=" << event->getId());
605 m_eventCelluarNetworkList.pop_front();
607 while (!m_eventStorageList.empty()) {
608 EventWatchSysteminfoPtr event = m_eventStorageList.front();
609 LoggerD("removing EventId=" << event->getId());
611 m_eventStorageList.pop_front();
613 while (!m_eventCpuList.empty()) {
614 EventWatchSysteminfoPtr event = m_eventCpuList.front();
615 LoggerD("removing EventId=" << event->getId());
617 m_eventCpuList.pop_front();
619 while (!m_eventSimList.empty()) {
620 EventWatchSysteminfoPtr event = m_eventSimList.front();
621 LoggerD("removing EventId=" << event->getId());
623 m_eventSimList.pop_front();
625 while (!m_eventDeviceOrientationList.empty()) {
626 EventWatchSysteminfoPtr event = m_eventDeviceOrientationList.front();
627 LoggerD("removing EventId=" << event->getId());
629 m_eventDeviceOrientationList.pop_front();
631 while (!m_eventLocaleList.empty()) {
632 EventWatchSysteminfoPtr event = m_eventLocaleList.front();
633 LoggerD("removing EventId=" << event->getId());
635 m_eventLocaleList.pop_front();
637 while (!m_eventPeripheralList.empty()) {
638 EventWatchSysteminfoPtr event = m_eventPeripheralList.front();
639 LoggerD("removing EventId=" << event->getId());
641 m_eventPeripheralList.pop_front();
645 void Systeminfo::EventMgr::addEvent(const EventWatchSysteminfoPtr& arg, const int watchType)
647 DPL::Mutex::ScopedLock lock(&m_synchro);
649 if (watchType == WATCH_TYPE_BATTERY){
650 m_eventBatteryList.push_back(arg);
651 LoggerD("Event Battery list size=" << m_eventBatteryList.size());
652 } else if (watchType == WATCH_TYPE_DISPLAY) {
653 m_eventDisplayList.push_back(arg);
654 LoggerD("Event display list size=" << m_eventDisplayList.size());
655 } else if (watchType == WATCH_TYPE_WIFINETWORK) {
656 m_eventWifiNetworkList.push_back(arg);
657 LoggerD("Event wifi network list size=" << m_eventWifiNetworkList.size());
658 } else if (watchType == WATCH_TYPE_CELLULARNETWORK) {
659 m_eventCelluarNetworkList.push_back(arg);
660 LoggerD("Event cellular network list size=" << m_eventCelluarNetworkList.size());
661 } else if (watchType == WATCH_TYPE_STORAGE) {
662 m_eventStorageList.push_back(arg);
663 LoggerD("Event storage list size=" << m_eventStorageList.size());
664 } else if (watchType == WATCH_TYPE_CPU) {
665 m_eventCpuList.push_back(arg);
666 LoggerD("Event cpu list size=" << m_eventCpuList.size());
667 } else if (watchType == WATCH_TYPE_SIM) {
668 m_eventSimList.push_back(arg);
669 LoggerD("Event sim list size=" << m_eventSimList.size());
670 } else if (watchType == WATCH_TYPE_DEVICE_ORIENTATION) {
671 m_eventDeviceOrientationList.push_back(arg);
672 LoggerD("Event device orientation list size=" << m_eventDeviceOrientationList.size());
673 } else if (watchType == WATCH_TYPE_NETWORK) {
674 m_eventNetworkList.push_back(arg);
675 LoggerD("Event network list size=" << m_eventNetworkList.size());
676 } else if (watchType == WATCH_TYPE_LOCALE) {
677 m_eventLocaleList.push_back(arg);
678 LoggerD("Event Locale list size=" << m_eventLocaleList.size());
679 } else if (watchType == WATCH_TYPE_PERIPHERAL) {
680 m_eventPeripheralList.push_back(arg);
681 LoggerD("Event peripheral list size=" << m_eventPeripheralList.size());
685 void Systeminfo::EventMgr::removeEvent(WatchId id, const int watchType)
687 DPL::Mutex::ScopedLock lock(&m_synchro);
688 LoggerD("Event id : " << id);
690 EventWatchSysteminfoPtr event(NULL);
692 LoggerD("trying to delete event, id=" << id);
694 if (watchType == WATCH_TYPE_BATTERY) {
695 for (EventBatteryList::iterator it = m_eventBatteryList.begin(); it != m_eventBatteryList.end(); it++) {
696 if (id == (*it)->getId()) {
702 LoggerE("event id not in the list, nothing to do");
706 LoggerD("event Battery list size=" << m_eventBatteryList.size());
707 m_eventBatteryList.remove(event);
708 LoggerD( "event removed, event Battery list size=" << m_eventBatteryList.size());
709 } else if (watchType == WATCH_TYPE_DISPLAY) {
710 for (EventDisplayList::iterator it = m_eventDisplayList.begin(); it != m_eventDisplayList.end(); it++) {
711 if (id == (*it)->getId()) {
717 LoggerE("event id not in the list, nothing to do");
721 LoggerD("event display list size=" << m_eventDisplayList.size());
722 m_eventDisplayList.remove(event);
723 LoggerD( "event removed, event display list size=" << m_eventDisplayList.size());
724 } else if (watchType == WATCH_TYPE_WIFINETWORK) {
725 for (EventWifiNetworkList::iterator it = m_eventWifiNetworkList.begin(); it != m_eventWifiNetworkList.end(); it++) {
726 if (id == (*it)->getId()) {
732 LoggerE("event id not in the list, nothing to do");
736 LoggerD("event wifi network list size=" << m_eventWifiNetworkList.size());
737 m_eventWifiNetworkList.remove(event);
738 LoggerD( "event removed, event wifi network list size=" << m_eventCelluarNetworkList.size());
739 } else if (watchType == WATCH_TYPE_CELLULARNETWORK) {
740 for (EventCellularNetworkList::iterator it = m_eventCelluarNetworkList.begin(); it != m_eventCelluarNetworkList.end(); it++) {
741 if (id == (*it)->getId()) {
747 LoggerE("event id not in the list, nothing to do");
751 LoggerD("event cellular network list size=" << m_eventCelluarNetworkList.size());
752 m_eventCelluarNetworkList.remove(event);
753 LoggerD( "event removed, event cellular network list size=" << m_eventCelluarNetworkList.size());
754 } else if (watchType == WATCH_TYPE_STORAGE) {
755 for (EventStorageList::iterator it = m_eventStorageList.begin(); it != m_eventStorageList.end(); it++) {
756 if (id == (*it)->getId()) {
762 LoggerE("event id not in the list, nothing to do");
766 LoggerD("event storage list size=" << m_eventStorageList.size());
767 m_eventStorageList.remove(event);
768 LoggerD( "event removed, event storage list size=" << m_eventStorageList.size());
769 } else if (watchType == WATCH_TYPE_CPU) {
770 for (EventCpuList::iterator it = m_eventCpuList.begin(); it != m_eventCpuList.end(); it++) {
771 if (id == (*it)->getId()) {
777 LoggerE("event id not in the list, nothing to do");
781 LoggerD("event cpu list size=" << m_eventCpuList.size());
782 m_eventCpuList.remove(event);
783 LoggerD( "event removed, event cpu list size=" << m_eventCpuList.size());
784 } else if (watchType == WATCH_TYPE_SIM) {
785 for (EventSimList::iterator it = m_eventSimList.begin(); it != m_eventSimList.end(); it++) {
786 if (id == (*it)->getId()) {
792 LoggerE("event id not in the list, nothing to do");
796 LoggerD("event sim list size=" << m_eventSimList.size());
797 m_eventSimList.remove(event);
798 LoggerD( "event removed, event sim list size=" << m_eventSimList.size());
799 } else if (watchType == WATCH_TYPE_DEVICE_ORIENTATION) {
800 for (EventDeviceOrientationList::iterator it = m_eventDeviceOrientationList.begin(); it != m_eventDeviceOrientationList.end(); it++) {
801 if (id == (*it)->getId()) {
807 LoggerE("event id not in the list, nothing to do");
811 LoggerD("event device orientation list size=" << m_eventDeviceOrientationList.size());
812 m_eventDeviceOrientationList.remove(event);
813 LoggerD( "event removed, event device orientation list size=" << m_eventDeviceOrientationList.size());
814 } else if (watchType == WATCH_TYPE_NETWORK) {
815 for (EventNetworkList::iterator it = m_eventNetworkList.begin(); it != m_eventNetworkList.end(); it++) {
816 if (id == (*it)->getId()) {
822 LoggerE("event id not in the list, nothing to do");
826 LoggerD("event network list size=" << m_eventNetworkList.size());
827 m_eventNetworkList.remove(event);
828 LoggerD( "event removed, event network list size=" << m_eventNetworkList.size());
829 } else if (watchType == WATCH_TYPE_LOCALE) {
830 for (EventLocaleList::iterator it = m_eventLocaleList.begin(); it != m_eventLocaleList.end(); it++) {
831 if (id == (*it)->getId()) {
837 LoggerE("event id not in the list, nothing to do");
841 LoggerD("event Locale list size=" << m_eventLocaleList.size());
842 m_eventLocaleList.remove(event);
843 LoggerD( "event removed, event Locale list size=" << m_eventLocaleList.size());
844 } else if (watchType == WATCH_TYPE_PERIPHERAL) {
845 for (EventPeripheralList::iterator it = m_eventPeripheralList.begin(); it != m_eventPeripheralList.end(); it++) {
846 if (id == (*it)->getId()) {
852 LoggerE("event id not in the list, nothing to do");
856 LoggerD("event peripheral list size=" << m_eventPeripheralList.size());
857 m_eventPeripheralList.remove(event);
858 LoggerD( "event removed, event peripheral list size=" << m_eventPeripheralList.size());
862 const int Systeminfo::EventMgr::getWatchType(const long id)
864 DPL::Mutex::ScopedLock lock(&m_synchro);
866 EventWatchSysteminfoPtr event(NULL);
868 for (EventBatteryList::iterator it = m_eventBatteryList.begin(); it != m_eventBatteryList.end(); it++) {
869 if (id == (*it)->getId()) {
875 for (EventDisplayList::iterator it = m_eventDisplayList.begin(); it != m_eventDisplayList.end(); it++) {
876 if (id == (*it)->getId()) {
882 for (EventWifiNetworkList::iterator it = m_eventWifiNetworkList.begin(); it != m_eventWifiNetworkList.end(); it++) {
883 if (id == (*it)->getId()) {
889 for (EventCellularNetworkList::iterator it = m_eventCelluarNetworkList.begin(); it != m_eventCelluarNetworkList.end(); it++) {
890 if (id == (*it)->getId()) {
896 for (EventStorageList::iterator it = m_eventStorageList.begin(); it != m_eventStorageList.end(); it++) {
897 if (id == (*it)->getId()) {
903 for (EventCpuList::iterator it = m_eventCpuList.begin(); it != m_eventCpuList.end(); it++) {
904 if (id == (*it)->getId()) {
910 for (EventSimList::iterator it = m_eventSimList.begin(); it != m_eventSimList.end(); it++) {
911 if (id == (*it)->getId()) {
917 for (EventDeviceOrientationList::iterator it = m_eventDeviceOrientationList.begin(); it != m_eventDeviceOrientationList.end(); it++) {
918 if (id == (*it)->getId()) {
924 for (EventNetworkList::iterator it = m_eventNetworkList.begin(); it != m_eventNetworkList.end(); it++) {
925 if (id == (*it)->getId()) {
931 for (EventSimList::iterator it = m_eventSimList.begin(); it != m_eventSimList.end(); it++) {
932 if (id == (*it)->getId()) {
938 for (EventLocaleList::iterator it = m_eventLocaleList.begin(); it != m_eventLocaleList.end(); it++) {
939 if (id == (*it)->getId()) {
945 for (EventPeripheralList::iterator it = m_eventPeripheralList.begin(); it != m_eventPeripheralList.end(); it++) {
946 if (id == (*it)->getId()) {
953 LoggerE("event id not in the list, nothing to do");
954 return WATCH_TYPE_UNKNOWN;
957 return event->getWatchType();
960 EventBatteryList Systeminfo::EventMgr::getEventBatteryList()
962 return m_eventBatteryList;
965 EventDisplayList Systeminfo::EventMgr::getEventDisplayList()
967 return m_eventDisplayList;
970 EventNetworkList Systeminfo::EventMgr::getEventNetworkList()
972 return m_eventNetworkList;
975 EventWifiNetworkList Systeminfo::EventMgr::getEventWifiNetworkList()
977 return m_eventWifiNetworkList;
980 EventCellularNetworkList Systeminfo::EventMgr::getEventCellularNetworkList()
982 return m_eventCelluarNetworkList;
985 EventStorageList Systeminfo::EventMgr::getEventStorageList()
987 return m_eventStorageList;
990 EventCpuList Systeminfo::EventMgr::getEventCpuList()
992 return m_eventCpuList;
995 EventDeviceOrientationList Systeminfo::EventMgr::getEventDeviceOrientationList()
997 return m_eventDeviceOrientationList;
1000 EventSimList Systeminfo::EventMgr::getEventSimList()
1002 return m_eventSimList;
1005 EventLocaleList Systeminfo::EventMgr::getEventLocaleList()
1007 return m_eventLocaleList;
1010 EventPeripheralList Systeminfo::EventMgr::getEventPeripheralList()
1012 return m_eventPeripheralList;
1015 ////////////////////////////////////////////////////////////////////////////////////////
1017 PROPERTY_GET_SYSTEMINFO_DEFINITION(Battery) {
1018 BatteryPropertiesPtr BatteryPtr(new BatteryProperties());
1022 if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, &value) != 0) {
1023 return JSValueMakeNull(context);
1025 BatteryPtr->level = (double)(value)/CPU_POWER_DEVICE_VALUE;
1028 if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &value2) != 0) {
1029 return JSValueMakeNull(context);
1031 BatteryPtr->isCharging = (value2 == 0) ? false : true;
1034 return JSBatteryInfo::createJSObject(context, BatteryPtr);
1037 PROPERTY_GET_SYSTEMINFO_DEFINITION(Cpu) {
1038 Converter converter(context);
1040 CpuPropertiesPtr cpuPtr(new CpuProperties());
1042 long long usr = 0, nice = 0, system = 0, idle = 0, total = 0, cpuUsage = 0;
1044 fp = fopen("/proc/stat", "r");
1046 return JSValueMakeNull(context);
1049 if (fscanf(fp, "%*s %lld %lld %lld %lld", &usr, &system, &nice, &idle) > 0) {
1050 total = usr + nice + system + idle;
1051 if ((total > 0LL) && (idle > 0LL)) {
1052 cpuUsage = idle * 100LL / total;
1053 cpuPtr->load = (double)cpuUsage / 100.0;
1054 LoggerD("cpu load : " << cpuPtr->load);
1059 return JSCpuInfo::createJSObject(context, cpuPtr);
1062 PROPERTY_GET_SYSTEMINFO_DEFINITION(Storage) {
1063 Converter converter(context);
1068 StoragePropertiesPtr internal(new StorageProperties());
1069 StoragePropertiesPtr mmc(new StorageProperties());
1070 StoragePropertiesPtr usbhost(new StorageProperties());
1071 std::vector <JSObjectRef> storagelist;
1073 if (statfs(STORAGE_INTERNAL_PATH, &fs) < 0) {
1074 return JSValueMakeNull(context);
1077 internal->type = "INTERNAL";
1078 internal->capacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_blocks;
1079 internal->availableCapacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_bavail;
1080 internal->isRemoveable = false;
1081 internal->isRemovable = false;
1082 storagelist.push_back(JSStorageInfo::createJSObject(context, internal));
1085 if(vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &sdcardState) == 0){
1086 if(sdcardState == VCONFKEY_SYSMAN_MMC_MOUNTED){
1088 if (statfs(STORAGE_SDCARD_PATH, &fs) < 0) {
1089 return JSValueMakeNull(context);
1092 mmc->capacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_blocks;
1093 mmc->availableCapacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_bavail;
1094 mmc->isRemoveable = true;
1095 mmc->isRemovable = true;
1096 storagelist.push_back(JSStorageInfo::createJSObject(context, mmc));
1100 if(vconf_get_int(VCONFKEY_SYSMAN_USB_HOST_STATUS, &usbhostState) == 0) {
1101 if(usbhostState == VCONFKEY_SYSMAN_USB_HOST_CONNECTED) {
1103 if (statfs(STORAGE_USBHOST_PATH, &fs) < 0) {
1104 return JSValueMakeNull(context);
1106 usbhost->type = "USB_HOST";
1107 usbhost->capacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_blocks;
1108 usbhost->availableCapacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_bavail;
1109 usbhost->isRemoveable = true;
1110 usbhost->isRemovable = true;
1111 storagelist.push_back(JSStorageInfo::createJSObject(context, usbhost));
1115 return JSObjectMakeArray(context, storageCnt, storagelist.data(), NULL);
1118 PROPERTY_GET_SYSTEMINFO_DEFINITION(Display) {
1119 Converter converter(context);
1121 DisplayPropertiesPtr display(new DisplayProperties());
1122 int brightness=0, dotsPerInchX=0, dotsPerInchY=0, physicalW=0, physicalH=0, resolutionW=0, resolutionH=0;
1124 if(vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, &brightness) == 0) {
1125 display->brightness = (double)(brightness)/DISPLAY_BRIGHTNESS_DIVIDE_VALUE;
1126 LoggerD("brightness : " << display->brightness);
1129 if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_WIDTH, &resolutionW) == SYSTEM_INFO_ERROR_NONE) {
1130 display->resolutionWidth = resolutionW;
1131 LoggerD("resolutionWidth : " << display->resolutionWidth);
1133 if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_HEIGHT, &resolutionH) == SYSTEM_INFO_ERROR_NONE) {
1134 display->resolutionHeight = resolutionH;
1135 LoggerD("resolutionHeight : " << display->resolutionHeight);
1137 if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_DPI, &dotsPerInchX) == SYSTEM_INFO_ERROR_NONE) {
1138 display->dotsPerInchWidth = dotsPerInchX;
1139 LoggerD("dotsPerInchWidth : " << display->dotsPerInchWidth);
1141 if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_DPI, &dotsPerInchY) == SYSTEM_INFO_ERROR_NONE) {
1142 display->dotsPerInchHeight = dotsPerInchY;
1143 LoggerD("dotsPerInchHeight : " << display->dotsPerInchHeight);
1145 if (system_info_get_value_int(SYSTEM_INFO_KEY_PHYSICAL_SCREEN_HEIGHT, &physicalH) == SYSTEM_INFO_ERROR_NONE) {
1146 display->physicalHeight = physicalH;
1147 LoggerD("physicalHeight : " << display->physicalHeight);
1149 if (system_info_get_value_int(SYSTEM_INFO_KEY_PHYSICAL_SCREEN_WIDTH, &physicalW) == SYSTEM_INFO_ERROR_NONE) {
1150 display->physicalWidth = physicalW;
1151 LoggerD("physicalWidth : " << display->physicalWidth);
1154 return JSDisplayInfo::createJSObject(context, display);
1157 PROPERTY_GET_SYSTEMINFO_DEFINITION(Network) {
1159 Converter converter(context);
1160 NetworkPropertiesPtr Network(new NetworkProperties());
1161 connection_h connectionHandle = (connection_h)handle;
1162 connection_type_e connectionType;
1163 int networkType = 0;
1165 if (connection_get_type(connectionHandle, &connectionType) != CONNECTION_ERROR_NONE) {
1166 LoggerD("get connection type is failed");
1167 return JSNetworkInfo::createJSObject(context, Network);
1170 if (connectionType == CONNECTION_TYPE_WIFI) {
1171 LoggerD("wifi network");
1172 Network->networkType= "WIFI";
1173 } else if (connectionType == CONNECTION_TYPE_CELLULAR) {
1174 if (vconf_get_int(VCONFKEY_TELEPHONY_SVCTYPE, &networkType) == 0) {
1175 if (networkType < VCONFKEY_TELEPHONY_SVCTYPE_2G) {
1176 Network->networkType= "NONE";
1177 } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_2G) {
1178 Network->networkType= "2G";
1179 } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_2G || networkType == VCONFKEY_TELEPHONY_SVCTYPE_2_5G_EDGE) {
1180 Network->networkType= "2.5";
1181 } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_3G || networkType == VCONFKEY_TELEPHONY_SVCTYPE_HSDPA) {
1182 Network->networkType= "3G";
1183 } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_LTE) {
1184 Network->networkType= "4G";
1186 Network->networkType= "NONE";
1190 Network->networkType= "NONE";
1193 return JSNetworkInfo::createJSObject(context, Network);
1196 PROPERTY_GET_SYSTEMINFO_DEFINITION(WifiNetwork) {
1197 Converter converter(context);
1198 WifiNetworkPropertiesPtr wifiNetwork(new WifiNetworkProperties());
1199 connection_h connectionHandle = (connection_h)handle;
1200 connection_type_e connectionType;
1201 connection_profile_h profileHandle = NULL;
1202 connection_address_family_e addressFamily = CONNECTION_ADDRESS_FAMILY_IPV4;
1203 char* ipAddr = NULL;
1207 if (connection_get_type(connectionHandle, &connectionType) != CONNECTION_ERROR_NONE) {
1208 return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1211 if (connectionType == CONNECTION_TYPE_WIFI) {
1212 wifiNetwork->status = "ON";
1214 wifiNetwork->status = "OFF";
1215 return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1218 if (connection_get_current_profile(connectionHandle, &profileHandle) != CONNECTION_ERROR_NONE) {
1219 return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1222 if (connection_profile_get_wifi_essid(profileHandle, &essid) == CONNECTION_ERROR_NONE) {
1223 wifiNetwork->ssid = essid;
1227 if (connection_profile_get_ip_address(profileHandle, addressFamily, &ipAddr) == CONNECTION_ERROR_NONE) {
1228 wifiNetwork->ipAddress = ipAddr;
1232 if (connection_profile_get_wifi_rssi(profileHandle, &rssi) == CONNECTION_ERROR_NONE) {
1233 wifiNetwork->signalStrength = (double) rssi/WIFI_SIGNAL_STRENGTH_DIVIDE_VALUE;
1236 return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1239 PROPERTY_GET_SYSTEMINFO_DEFINITION(CellularNetwork) {
1240 Converter converter(context);
1241 CellularNetworkPropertiesPtr cellularNetwork(new CellularNetworkProperties());
1242 connection_h connectionHandle = (connection_h)handle;
1243 connection_type_e connectionType;
1244 connection_profile_h profileHandle = NULL;
1245 connection_address_family_e addressFamily = CONNECTION_ADDRESS_FAMILY_IPV4;
1246 char* ipAddr = NULL;
1248 int plmn = 0, cellId = 0, lac = 0, isRoaming = 0, isFlightMode = 0;
1250 TIME_TRACER_ITEM_BEGIN("(cellular)mcc", 0);
1251 if (vconf_get_int(VCONFKEY_TELEPHONY_PLMN, &plmn) == 0) {
1252 cellularNetwork->mcc = plmn / 100;
1253 cellularNetwork->mnc = plmn % 100;
1255 TIME_TRACER_ITEM_END("(cellular)mcc", 0);
1257 TIME_TRACER_ITEM_BEGIN("(cellular)cellId", 0);
1258 if (vconf_get_int(VCONFKEY_TELEPHONY_CELLID, &cellId) == 0) {
1259 cellularNetwork->cellId = cellId;
1261 TIME_TRACER_ITEM_END("(cellular)cellId", 0);
1263 TIME_TRACER_ITEM_BEGIN("(cellular)lac", 0);
1264 if (vconf_get_int(VCONFKEY_TELEPHONY_LAC, &lac) == 0) {
1265 cellularNetwork->lac = lac;
1267 TIME_TRACER_ITEM_END("(cellular)lac", 0);
1269 TIME_TRACER_ITEM_BEGIN("(cellular)isRoaming", 0);
1270 if (vconf_get_int(VCONFKEY_TELEPHONY_SVC_ROAM, &isRoaming) == 0) {
1272 cellularNetwork->isRoaming = true;
1274 cellularNetwork->isRoaming = false;
1277 TIME_TRACER_ITEM_END("(cellular)isRoaming", 0);
1279 TIME_TRACER_ITEM_BEGIN("(cellular)isFlightMode", 0);
1280 if (vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &isFlightMode) == 0) {
1282 cellularNetwork->isFlightMode = true;
1284 cellularNetwork->isFlightMode = false;
1287 TIME_TRACER_ITEM_END("(cellular)isFlightMode", 0);
1289 if (connection_get_type(connectionHandle, &connectionType) != CONNECTION_ERROR_NONE) {
1290 return JSCellularNetworkInfo::createJSObject(context, cellularNetwork);
1293 if (connectionType == CONNECTION_TYPE_CELLULAR) {
1294 cellularNetwork->status = "ON";
1295 if (connection_get_current_profile(connectionHandle, &profileHandle) == CONNECTION_ERROR_NONE) {
1296 TIME_TRACER_ITEM_BEGIN("(cellular)apn", 0);
1297 if (connection_profile_get_cellular_apn(profileHandle, &apn) == CONNECTION_ERROR_NONE) {
1298 cellularNetwork->apn = apn;
1301 TIME_TRACER_ITEM_END("(cellular)apn", 0);
1303 TIME_TRACER_ITEM_BEGIN("(cellular)ipAddress", 0);
1304 if (connection_profile_get_ip_address(profileHandle, addressFamily, &ipAddr) == CONNECTION_ERROR_NONE) {
1305 cellularNetwork->ipAddress = ipAddr;
1308 TIME_TRACER_ITEM_END("(cellular)ipAddress", 0);
1309 connection_profile_destroy(profileHandle);
1312 cellularNetwork->status = "OFF";
1313 if (connection_get_default_cellular_service_profile(connectionHandle, CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET, &profileHandle) == CONNECTION_ERROR_NONE) {
1314 TIME_TRACER_ITEM_BEGIN("(cellular)apn", 0);
1315 if (connection_profile_get_cellular_apn(profileHandle, &apn) == CONNECTION_ERROR_NONE) {
1316 cellularNetwork->apn = apn;
1319 TIME_TRACER_ITEM_END("(cellular)apn", 0);
1320 connection_profile_destroy(profileHandle);
1324 return JSCellularNetworkInfo::createJSObject(context, cellularNetwork);
1327 PROPERTY_GET_SYSTEMINFO_DEFINITION(SIM) {
1328 Converter converter(context);
1329 SIMPropertiesPtr SIM(new SIMProperties());
1330 return JSSIMInfo::createJSObject(context, SIM);
1333 PROPERTY_GET_SYSTEMINFO_DEFINITION(DeviceOrientation) {
1335 Converter converter(context);
1336 DeviceOrientationPropertiesPtr deviceOrientation(new DeviceOrientationProperties());
1338 unsigned long rotation = 0;
1339 int handleOrientaion = 0;
1341 handleOrientaion = sf_connect(ACCELEROMETER_SENSOR);
1342 LoggerD("handleOrientaion : " << handleOrientaion);
1343 if (handleOrientaion < 0) {
1344 LoggerD ("sensor attach fail");
1345 return JSDeviceOrientationInfo::createJSObject(context, deviceOrientation);
1347 int state = sf_start(handleOrientaion, 0);
1349 LoggerD("start failed");
1352 int ret_val = sf_check_rotation(&rotation);
1354 LoggerD("sf_check_rotation fail to gather data\n");
1357 LoggerD(" rotation value = " << rotation);
1361 case ROTATION_EVENT_0:
1362 LoggerD("my_callback_func received data (PORTRAIT_TOP|HEAD_CENTER)\n");
1363 deviceOrientation->status = "PORTRAIT_PRIMARY";
1365 case ROTATION_EVENT_90:
1366 LoggerD("my_callback_func received data (LANDSCAPE|HEAD_RIGHT)\n");
1367 deviceOrientation->status = "LANDSCAPE_PRIMARY";
1369 case ROTATION_EVENT_180:
1370 LoggerD("my_callback_func received data (PORTRAIT_BTM|HEAD_CENTER)\n");
1371 deviceOrientation->status = "PORTRAIT_SECONDARY";
1373 case ROTATION_EVENT_270:
1374 LoggerD("my_callback_func received data (LANDSCAPE|HEAD_LEFT)\n");
1375 deviceOrientation->status = "LANDSCAPE_SECONDARY";
1378 LoggerD(" received data unexpected\n");
1382 state = sf_stop(handleOrientaion);
1383 LoggerD("handleOrientaion 1 state = " << state);
1385 state = sf_disconnect(handleOrientaion);
1386 LoggerD("handleOrientaion state =" << state);
1388 return JSDeviceOrientationInfo::createJSObject(context, deviceOrientation);
1391 PROPERTY_GET_SYSTEMINFO_DEFINITION(Build) {
1393 Converter converter(context);
1394 BuildPropertiesPtr Build(new BuildProperties());
1397 char* manufacturer = NULL;
1398 char* buildVersion = NULL;
1400 if (system_info_get_value_string(SYSTEM_INFO_KEY_MODEL, &model) == SYSTEM_INFO_ERROR_NONE) {
1401 if (model != NULL) {
1402 LoggerD("model : " << model);
1403 Build->model = model;
1408 if (system_info_get_value_string(SYSTEM_INFO_KEY_MANUFACTURER, &manufacturer) == SYSTEM_INFO_ERROR_NONE) {
1409 if (manufacturer != NULL) {
1410 LoggerD("manufacturer : " << manufacturer);
1411 Build->manufacturer = manufacturer;
1416 if (system_info_get_value_string(SYSTEM_INFO_KEY_BUILD_STRING, &buildVersion) == SYSTEM_INFO_ERROR_NONE) {
1417 if (buildVersion != NULL) {
1418 LoggerD("buildVersion : " << buildVersion);
1419 Build->buildVersion = buildVersion;
1424 return JSBuildInfo::createJSObject(context, Build);
1427 PROPERTY_GET_SYSTEMINFO_DEFINITION(Locale) {
1429 Converter converter(context);
1430 LocalePropertiesPtr Locale(new LocaleProperties());
1432 char* country = NULL;
1433 char* language = NULL;
1435 if (runtime_info_get_value_string(RUNTIME_INFO_KEY_LANGUAGE, &language) == RUNTIME_INFO_ERROR_NONE) {
1436 if (language != NULL) {
1437 LoggerD("language : " << language);
1438 Locale->language = language;
1443 if (runtime_info_get_value_string(RUNTIME_INFO_KEY_REGION, &country) == RUNTIME_INFO_ERROR_NONE) {
1444 if (country != NULL) {
1445 LoggerD("country : " << country);
1447 char* countryTemp = NULL;
1448 token = strtok(country, ".");
1449 if (token != NULL) {
1450 countryTemp = strdup(token);
1451 if (countryTemp != NULL) {
1452 Locale->country = countryTemp;
1460 return JSLocaleInfo::createJSObject(context, Locale);
1463 PROPERTY_GET_SYSTEMINFO_DEFINITION(Peripheral) {
1464 Converter converter(context);
1465 PeripheralPropertiesPtr peripheral(new PeripheralProperties());
1466 int hdmiStatus = 0, wirelessDisplayStatus = 0 ;
1468 if (vconf_get_int(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, &wirelessDisplayStatus) == 0) {
1469 switch(wirelessDisplayStatus) {
1470 case VCONFKEY_MIRACAST_WFD_SOURCE_ON:
1471 peripheral->isVideoOutputOn = true;
1474 LoggerD("VideOutput status is off");
1479 if (vconf_get_int(VCONFKEY_SYSMAN_HDMI, &hdmiStatus) == 0) {
1480 switch(hdmiStatus) {
1481 case VCONFKEY_SYSMAN_HDMI_CONNECTED:
1482 peripheral->isVideoOutputOn = true;
1485 LoggerD("VideOutput status is off");
1490 return JSPeripheralInfo::createJSObject(context, peripheral);