2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
21 #include <Commons/Exception.h>
22 #include <CommonsJavaScript/Converter.h>
23 #include <CommonsJavaScript/PrivateObject.h>
24 #include <TimeTracer.h>
25 #include <tapi_common.h>
26 #include <ITapiModem.h>
28 #include "Systeminfo.h"
31 using namespace WrtDeviceApis::CommonsJavaScript;
32 using namespace WrtDeviceApis::Commons;
36 namespace Systeminfo {
40 void BatteryValueCallback(keynode_t *node, void *event_ptr)
43 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_BATTERY);
47 void PeripheralValueCallback(keynode_t *node, void *event_ptr)
50 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_PERIPHERAL);
54 void CellularNetworkValueCallback(keynode_t *node, void *event_ptr)
57 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_CELLULARNETWORK);
61 void DisplayValueCallback(keynode_t *node, void* event_ptr)
64 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_DISPLAY);
68 void OrientationValueVconfCallback(keynode_t *node, void *event_ptr)
72 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_DEVICE_ORIENTATION);
76 void NetworkTypeValueCallback(connection_type_e type, void* event_ptr)
79 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_NETWORK);
83 void NetworkValueCallback(const char* ipv4_address, const char* ipv6_address, void* event_ptr)
86 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_NETWORK_ALL);
90 static Eina_Bool StorageValueCallback(void* event_ptr)
93 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_STORAGE);
95 return ECORE_CALLBACK_RENEW;
98 static Eina_Bool CpuValueCallback(void* event_ptr)
101 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_CPU);
103 return ECORE_CALLBACK_RENEW;
106 void OrientationValueCallback(unsigned int event_type, sensor_event_data_t *event , void *event_ptr)
109 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_DEVICE_ORIENTATION);
113 void localeChangedCallback(runtime_info_key_e key, void* event_ptr)
116 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_LOCALE);
122 #define STORAGE_INTERNAL_PATH "/opt/usr/media"
123 #define STORAGE_SDCARD_PATH "/opt/storage/sdcard"
124 #define STORAGE_USBHOST_PATH "/opt/storage/usb"
125 #define DISPLAY_BRIGHTNESS_DIVIDE_VALUE 100
126 #define WIFI_SIGNAL_STRENGTH_DIVIDE_VALUE 100
127 #define CPU_POWER_DEVICE_VALUE 100
129 #define RADIAN_VALUE (57.2957)
132 STORAGE_TYPE_UNKNOWN = 0,
133 STORAGE_TYPE_INTERNAL = 1,
134 STORAGE_TYPE_MMC = 2,
135 STORAGE_TYPE_USBHOST = 3
138 Systeminfo::OptionalProperty Systeminfo::m_Property;
140 Systeminfo::Systeminfo() : m_networkRegist(REGIST_NOT),
141 m_storageTimer(NULL),
144 m_connectionHandle(NULL)
146 EventMgrPtr eventMgrPtr(new EventMgr());
147 m_EventMgrPtr = eventMgrPtr;
148 if (m_Property.IsNull()) {
149 mapProperties properties;
150 properties["BATTERY"] = BasePropertyPtr(new Battery());
151 m_Property = properties;
152 (*m_Property)["CPU"] = BasePropertyPtr(new Cpu());
153 (*m_Property)["STORAGE"] = BasePropertyPtr(new Storage());
154 (*m_Property)["DISPLAY"] = BasePropertyPtr(new Display());
155 (*m_Property)["NETWORK"] = BasePropertyPtr(new Network());
156 (*m_Property)["WIFI_NETWORK"] = BasePropertyPtr(new WifiNetwork());
157 (*m_Property)["CELLULAR_NETWORK"] = BasePropertyPtr(new CellularNetwork());
158 (*m_Property)["SIM"] = BasePropertyPtr(new SIM());
159 (*m_Property)["DEVICE_ORIENTATION"] = BasePropertyPtr(new DeviceOrientation());
160 (*m_Property)["BUILD"] = BasePropertyPtr(new Build());
161 (*m_Property)["LOCALE"] = BasePropertyPtr(new Locale());
162 (*m_Property)["PERIPHERAL"] = BasePropertyPtr(new Peripheral());
165 int ret = connection_create(&m_connectionHandle);
167 if (CONNECTION_ERROR_NONE == ret) {
168 LoggerD("Network Client registration success");
170 LoggerD("Network Client registration success");
171 m_connectionHandle = NULL;
174 m_sensorHandle = sf_connect(ACCELEROMETER_SENSOR);
175 if (m_sensorHandle < 0) {
176 LoggerD ("sensor attach fail");
178 LoggerD("m_sensorHandle : " << m_sensorHandle);
179 int state = sf_start(m_sensorHandle, 0);
186 Systeminfo::~Systeminfo()
189 if (m_storageTimer) {
190 ecore_timer_freeze(m_storageTimer);
191 ecore_timer_del(m_storageTimer);
192 m_storageTimer = NULL;
195 ecore_timer_freeze(m_cpuTimer);
196 ecore_timer_del(m_cpuTimer);
199 m_EventMgrPtr->clearAllEvent();
201 if(m_connectionHandle != NULL) {
202 LoggerD("Network Client deregistration success");
203 connection_destroy(m_connectionHandle);
205 LoggerD("Network Client deregistration failed");
208 state = sf_stop(m_sensorHandle);
209 LoggerD("handle 1 state = " << state);
211 state = sf_disconnect(m_sensorHandle);
212 LoggerD("handle state =" << state);
215 DeviceCapabilitiesPropertiesPtr Systeminfo::getCapabilities()
218 DeviceCapabilitiesPropertiesPtr deviceCapabilities(new DeviceCapabilitiesProperties());
219 return deviceCapabilities;
222 void Systeminfo::get(const EventGetSysteminfoPtr& event)
224 EventRequestReceiver<EventGetSysteminfo>::PostRequest(event);
227 void Systeminfo::watch(const EventWatchSysteminfoPtr& event)
229 if(event->getWatchType() == WATCH_TYPE_UNKNOWN) {
230 LoggerD("watch method is not supported");
235 event->setSysteminfoPtr(this);
236 m_EventMgrPtr->addEvent(event, event->getWatchType());
238 EventRequestReceiver<EventWatchSysteminfo>::PostRequest(event);
241 void Systeminfo::clearWatch(const long id)
244 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
246 int watchType = m_EventMgrPtr->getWatchType(id);
248 case WATCH_TYPE_BATTERY:
249 if ((m_EventMgrPtr->getEventBatteryList()).size() == 1) {
250 vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, BatteryValueCallback);
251 vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, BatteryValueCallback);
254 case WATCH_TYPE_DISPLAY:
255 if ((m_EventMgrPtr->getEventDisplayList()).size() == 1) {
256 vconf_ignore_key_changed(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, DisplayValueCallback);
259 case WATCH_TYPE_NETWORK:
260 if ((m_EventMgrPtr->getEventNetworkList()).size() == 1) {
261 connection_unset_type_changed_cb(m_connectionHandle);
264 case WATCH_TYPE_WIFINETWORK:
265 if ((m_EventMgrPtr->getEventWifiNetworkList()).size() == 1) {
266 if (m_networkRegist == REGIST_WIFI) {
267 connection_unset_ip_address_changed_cb(m_connectionHandle);
268 m_networkRegist = REGIST_NOT;
269 } else if (m_networkRegist== REGIST_ALL) {
270 m_networkRegist = REGIST_CELLULAR;
274 case WATCH_TYPE_CELLULARNETWORK:
275 if ((m_EventMgrPtr->getEventCellularNetworkList()).size() == 1) {
276 vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, CellularNetworkValueCallback);
277 vconf_ignore_key_changed(VCONFKEY_TELEPHONY_CELLID, CellularNetworkValueCallback);
278 vconf_ignore_key_changed(VCONFKEY_TELEPHONY_LAC, CellularNetworkValueCallback);
279 vconf_ignore_key_changed(VCONFKEY_TELEPHONY_SVC_ROAM, CellularNetworkValueCallback);
280 if (m_networkRegist == REGIST_CELLULAR) {
281 connection_unset_ip_address_changed_cb(m_connectionHandle);
282 m_networkRegist = REGIST_NOT;
283 } else if (m_networkRegist== REGIST_ALL) {
284 m_networkRegist = REGIST_WIFI;
288 case WATCH_TYPE_STORAGE:
289 if ((m_EventMgrPtr->getEventStorageList()).size() == 1) {
290 if (m_storageTimer) {
291 ecore_timer_freeze(m_storageTimer);
292 ecore_timer_del(m_storageTimer);
293 m_storageTimer = NULL;
298 if ((m_EventMgrPtr->getEventCpuList()).size() == 1) {
300 ecore_timer_freeze(m_cpuTimer);
301 ecore_timer_del(m_cpuTimer);
306 case WATCH_TYPE_DEVICE_ORIENTATION:
307 if ((m_EventMgrPtr->getEventDeviceOrientationList()).size() == 1) {
308 vconf_ignore_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, OrientationValueVconfCallback);
309 int state = sf_unregister_event(m_sensorHandle, ACCELEROMETER_EVENT_ROTATION_CHECK);
311 LoggerD("sf_unregister_event fail to gather data\n");
315 case WATCH_TYPE_LOCALE:
316 if ((m_EventMgrPtr->getEventLocaleList()).size() == 1) {
317 if (runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_LANGUAGE) != RUNTIME_INFO_ERROR_NONE) {
318 LoggerE("regist failed");
319 Throw(WrtDeviceApis::Commons::Exception);
321 if (runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_REGION) != RUNTIME_INFO_ERROR_NONE) {
322 LoggerE("regist failed");
323 Throw(WrtDeviceApis::Commons::Exception);
327 case WATCH_TYPE_PERIPHERAL:
328 if ((m_EventMgrPtr->getEventPeripheralList()).size() == 1) {
329 vconf_ignore_key_changed(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, PeripheralValueCallback);
330 vconf_ignore_key_changed(VCONFKEY_SYSMAN_HDMI, PeripheralValueCallback);
333 case WATCH_TYPE_UNKNOWN:
334 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
337 m_EventMgrPtr->removeEvent(id, watchType);
341 BasePropertyPtr Systeminfo::getBasePropertyPtr(JSContextRef context, JSValueRef property)
343 Converter converter(context);
344 std::string l_property = converter.toString(property);
345 mapProperties::iterator it = (*m_Property).find(l_property);
346 if (it == (*m_Property).end()) {
347 LoggerE("not existing property");
348 Throw(WrtDeviceApis::Commons::ConversionException);
349 return BasePropertyPtr(NULL);
355 void Systeminfo::getWatchValue(const int watchType)
357 LoggerD(" watch type : " << watchType);
359 if (watchType == WATCH_TYPE_BATTERY) {
360 EventBatteryList eventList = m_EventMgrPtr->getEventBatteryList();
361 for (EventBatteryList::iterator it = eventList.begin(); it != eventList.end(); it++) {
362 (*it)->getWatchValue();
364 } else if (watchType == WATCH_TYPE_DISPLAY) {
365 EventDisplayList eventList = m_EventMgrPtr->getEventDisplayList();
366 for (EventDisplayList::iterator it = eventList.begin(); it != eventList.end(); it++) {
367 (*it)->getWatchValue();
369 } else if (watchType == WATCH_TYPE_NETWORK) {
370 EventNetworkList eventList = m_EventMgrPtr->getEventNetworkList();
371 for (EventNetworkList::iterator it = eventList.begin(); it != eventList.end(); it++) {
372 (*it)->getWatchValue();
374 } else if (watchType == WATCH_TYPE_NETWORK_ALL) {
375 EventWifiNetworkList eventListWifi = m_EventMgrPtr->getEventWifiNetworkList();
376 EventWifiNetworkList eventListCellular = m_EventMgrPtr->getEventCellularNetworkList();
377 if (eventListWifi.size() > 0) {
378 for (EventWifiNetworkList::iterator it = eventListWifi.begin(); it != eventListWifi.end(); it++) {
379 (*it)->getWatchValue();
382 if (eventListCellular.size() > 0) {
383 for (EventCellularNetworkList::iterator it = eventListCellular.begin(); it != eventListCellular.end(); it++) {
384 (*it)->getWatchValue();
387 } else if (watchType == WATCH_TYPE_CPU) {
388 EventCpuList eventList = m_EventMgrPtr->getEventCpuList();
389 for (EventCpuList::iterator it = eventList.begin(); it != eventList.end(); it++) {
390 (*it)->getWatchValue();
392 } else if (watchType == WATCH_TYPE_STORAGE) {
393 EventStorageList eventList = m_EventMgrPtr->getEventStorageList();
394 for (EventStorageList::iterator it = eventList.begin(); it != eventList.end(); it++) {
397 if(vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &sdcardState) == 0) {
398 if(sdcardState == VCONFKEY_SYSMAN_MMC_MOUNTED) {
402 LoggerD("storage cnt : " << storageCnt);
403 (*it)->getWatchValue(storageCnt);
405 }else if (watchType == WATCH_TYPE_DEVICE_ORIENTATION) {
406 EventDeviceOrientationList eventList = m_EventMgrPtr->getEventDeviceOrientationList();
407 for (EventDeviceOrientationList::iterator it = eventList.begin(); it != eventList.end(); it++) {
408 (*it)->getWatchValue();
410 } else if (watchType == WATCH_TYPE_LOCALE) {
411 EventLocaleList eventList = m_EventMgrPtr->getEventLocaleList();
412 for (EventLocaleList::iterator it = eventList.begin(); it != eventList.end(); it++) {
413 (*it)->getWatchValue();
415 } else if (watchType == WATCH_TYPE_PERIPHERAL) {
416 EventPeripheralList eventList = m_EventMgrPtr->getEventPeripheralList();
417 for (EventPeripheralList::iterator it = eventList.begin(); it != eventList.end(); it++) {
418 (*it)->getWatchValue();
420 } else if (watchType == WATCH_TYPE_CELLULARNETWORK) {
421 EventWifiNetworkList eventListCellular = m_EventMgrPtr->getEventCellularNetworkList();
422 if (eventListCellular.size() > 0) {
423 for (EventCellularNetworkList::iterator it = eventListCellular.begin(); it != eventListCellular.end(); it++) {
424 (*it)->getWatchValue();
430 connection_h Systeminfo::getConnectionHandle()
432 return m_connectionHandle;
435 JSValueRef Systeminfo::getCpuValue(JSContextRef context)
438 Converter converter(context);
440 CpuPropertiesPtr cpuPtr(new CpuProperties());
442 long long usr = 0, nice = 0, system = 0, idle = 0, cpuUsage = 0, diffIdle = 0, total = 0;
444 fp = fopen("/proc/stat", "r");
446 return JSValueMakeNull(context);
449 if (fscanf(fp, "%*s %lld %lld %lld %lld", &usr, &system, &nice, &idle) > 0) {
450 total = usr + nice + system + idle - m_cpuInfo.usr - m_cpuInfo.nice - m_cpuInfo.system - m_cpuInfo.idle;
451 diffIdle = idle-m_cpuInfo.idle;
452 if ((total > 0LL) && (diffIdle > 0LL)) {
453 cpuUsage = diffIdle * 100LL / total;
454 cpuPtr->load = (double)cpuUsage / 100.0;
456 m_cpuInfo.system = system;
457 m_cpuInfo.nice = nice;
458 m_cpuInfo.idle = idle;
459 LoggerD("cpu load : " << cpuPtr->load);
464 return JSCpuInfo::createJSObject(context, cpuPtr);
467 void Systeminfo::OnRequestReceived(const EventGetSysteminfoPtr& event)
470 event->processGetValue((void *)m_connectionHandle);
473 void Systeminfo::OnRequestReceived(const EventWatchSysteminfoPtr& event)
475 WatchOption watchOption = event->getWatchOption();
477 event->switchToManualAnswer();
478 event->setCancelAllowed(true);
480 switch(event->getWatchType()) {
481 case WATCH_TYPE_BATTERY:
482 if ((m_EventMgrPtr->getEventBatteryList()).size() == 1) {
483 vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, BatteryValueCallback, (void *)this);
484 vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, BatteryValueCallback, (void *)this);
487 case WATCH_TYPE_DISPLAY:
488 if ((m_EventMgrPtr->getEventDisplayList()).size() == 1) {
489 vconf_notify_key_changed(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, DisplayValueCallback, (void *)this);
492 case WATCH_TYPE_NETWORK:
493 if ((m_EventMgrPtr->getEventNetworkList()).size() == 1) {
494 connection_set_type_changed_cb(m_connectionHandle, NetworkTypeValueCallback, (void *)this);
497 case WATCH_TYPE_WIFINETWORK:
498 if ((m_EventMgrPtr->getEventWifiNetworkList()).size() == 1) {
499 if (m_networkRegist == REGIST_NOT) {
500 connection_set_ip_address_changed_cb(m_connectionHandle, NetworkValueCallback, (void *)this);
501 m_networkRegist = REGIST_WIFI;
502 } else if (m_networkRegist== REGIST_CELLULAR) {
503 m_networkRegist = REGIST_ALL;
507 case WATCH_TYPE_CELLULARNETWORK:
508 if ((m_EventMgrPtr->getEventCellularNetworkList()).size() == 1) {
509 vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, CellularNetworkValueCallback, (void *)this);
510 vconf_notify_key_changed(VCONFKEY_TELEPHONY_CELLID, CellularNetworkValueCallback, (void *)this);
511 vconf_notify_key_changed(VCONFKEY_TELEPHONY_LAC, CellularNetworkValueCallback, (void *)this);
512 vconf_notify_key_changed(VCONFKEY_TELEPHONY_SVC_ROAM, CellularNetworkValueCallback, (void *)this);
513 if (m_networkRegist == REGIST_NOT) {
514 connection_set_ip_address_changed_cb(m_connectionHandle, NetworkValueCallback, (void *)this);
515 m_networkRegist = REGIST_CELLULAR;
516 } else if (m_networkRegist== REGIST_WIFI) {
517 m_networkRegist = REGIST_ALL;
521 case WATCH_TYPE_STORAGE:
522 if ((m_EventMgrPtr->getEventStorageList()).size() == 1) {
523 if (!m_storageTimer) {
524 m_storageTimer = ecore_timer_add(1, StorageValueCallback, this);
525 ecore_timer_thaw(m_storageTimer);
530 if ((m_EventMgrPtr->getEventCpuList()).size() == 1) {
532 m_cpuTimer = ecore_timer_add(1, CpuValueCallback, this);
533 ecore_timer_thaw(m_cpuTimer);
537 case WATCH_TYPE_DEVICE_ORIENTATION:
538 LoggerD("regist sensor");
539 if ((m_EventMgrPtr->getEventDeviceOrientationList()).size() == 1) {
540 vconf_notify_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, OrientationValueVconfCallback, (void *)this);
541 int state = sf_register_event(m_sensorHandle, ACCELEROMETER_EVENT_ROTATION_CHECK, NULL, OrientationValueCallback, (void *)this);
543 LoggerD("sensor_register_cb fail to gather data");
544 } else if (state == 0) {
545 LoggerD("sensor_register_cb success to gather data");
548 LoggerD("already regist");
551 case WATCH_TYPE_LOCALE:
552 if ((m_EventMgrPtr->getEventLocaleList()).size() == 1) {
553 if (runtime_info_set_changed_cb(RUNTIME_INFO_KEY_REGION, localeChangedCallback, (void *)this) != RUNTIME_INFO_ERROR_NONE) {
554 LoggerE("regist failed");
555 Throw(WrtDeviceApis::Commons::Exception);
557 if (runtime_info_set_changed_cb(RUNTIME_INFO_KEY_LANGUAGE, localeChangedCallback, (void *)this) != RUNTIME_INFO_ERROR_NONE) {
558 LoggerE("regist failed");
559 Throw(WrtDeviceApis::Commons::Exception);
563 case WATCH_TYPE_PERIPHERAL:
564 if ((m_EventMgrPtr->getEventPeripheralList()).size() == 1) {
565 vconf_notify_key_changed(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, PeripheralValueCallback, (void *)this);
566 vconf_notify_key_changed(VCONFKEY_SYSMAN_HDMI, PeripheralValueCallback, (void *)this);
570 event->processGetValue();
574 ////////////////////////////////////////////////////////////////////////////////////////
576 Systeminfo::EventMgr::EventMgr()
580 Systeminfo::EventMgr::~EventMgr()
584 void Systeminfo::EventMgr::clearAllEvent()
586 DPL::Mutex::ScopedLock lock(&m_synchro);
588 while (!m_eventBatteryList.empty()) {
589 EventWatchSysteminfoPtr event = m_eventBatteryList.front();
590 LoggerD("removing EventId=" << event->getId());
592 m_eventBatteryList.pop_front();
594 while (!m_eventDisplayList.empty()) {
595 EventWatchSysteminfoPtr event = m_eventDisplayList.front();
596 LoggerD("removing EventId=" << event->getId());
598 m_eventDisplayList.pop_front();
600 while (!m_eventWifiNetworkList.empty()) {
601 EventWatchSysteminfoPtr event = m_eventWifiNetworkList.front();
602 LoggerD("removing EventId=" << event->getId());
604 m_eventWifiNetworkList.pop_front();
606 while (!m_eventCelluarNetworkList.empty()) {
607 EventWatchSysteminfoPtr event = m_eventCelluarNetworkList.front();
608 LoggerD("removing EventId=" << event->getId());
610 m_eventCelluarNetworkList.pop_front();
612 while (!m_eventStorageList.empty()) {
613 EventWatchSysteminfoPtr event = m_eventStorageList.front();
614 LoggerD("removing EventId=" << event->getId());
616 m_eventStorageList.pop_front();
618 while (!m_eventCpuList.empty()) {
619 EventWatchSysteminfoPtr event = m_eventCpuList.front();
620 LoggerD("removing EventId=" << event->getId());
622 m_eventCpuList.pop_front();
624 while (!m_eventSimList.empty()) {
625 EventWatchSysteminfoPtr event = m_eventSimList.front();
626 LoggerD("removing EventId=" << event->getId());
628 m_eventSimList.pop_front();
630 while (!m_eventDeviceOrientationList.empty()) {
631 EventWatchSysteminfoPtr event = m_eventDeviceOrientationList.front();
632 LoggerD("removing EventId=" << event->getId());
634 m_eventDeviceOrientationList.pop_front();
636 while (!m_eventLocaleList.empty()) {
637 EventWatchSysteminfoPtr event = m_eventLocaleList.front();
638 LoggerD("removing EventId=" << event->getId());
640 m_eventLocaleList.pop_front();
642 while (!m_eventPeripheralList.empty()) {
643 EventWatchSysteminfoPtr event = m_eventPeripheralList.front();
644 LoggerD("removing EventId=" << event->getId());
646 m_eventPeripheralList.pop_front();
650 void Systeminfo::EventMgr::addEvent(const EventWatchSysteminfoPtr& arg, const int watchType)
652 DPL::Mutex::ScopedLock lock(&m_synchro);
654 if (watchType == WATCH_TYPE_BATTERY){
655 m_eventBatteryList.push_back(arg);
656 LoggerD("Event Battery list size=" << m_eventBatteryList.size());
657 } else if (watchType == WATCH_TYPE_DISPLAY) {
658 m_eventDisplayList.push_back(arg);
659 LoggerD("Event display list size=" << m_eventDisplayList.size());
660 } else if (watchType == WATCH_TYPE_WIFINETWORK) {
661 m_eventWifiNetworkList.push_back(arg);
662 LoggerD("Event wifi network list size=" << m_eventWifiNetworkList.size());
663 } else if (watchType == WATCH_TYPE_CELLULARNETWORK) {
664 m_eventCelluarNetworkList.push_back(arg);
665 LoggerD("Event cellular network list size=" << m_eventCelluarNetworkList.size());
666 } else if (watchType == WATCH_TYPE_STORAGE) {
667 m_eventStorageList.push_back(arg);
668 LoggerD("Event storage list size=" << m_eventStorageList.size());
669 } else if (watchType == WATCH_TYPE_CPU) {
670 m_eventCpuList.push_back(arg);
671 LoggerD("Event cpu list size=" << m_eventCpuList.size());
672 } else if (watchType == WATCH_TYPE_SIM) {
673 m_eventSimList.push_back(arg);
674 LoggerD("Event sim list size=" << m_eventSimList.size());
675 } else if (watchType == WATCH_TYPE_DEVICE_ORIENTATION) {
676 m_eventDeviceOrientationList.push_back(arg);
677 LoggerD("Event device orientation list size=" << m_eventDeviceOrientationList.size());
678 } else if (watchType == WATCH_TYPE_NETWORK) {
679 m_eventNetworkList.push_back(arg);
680 LoggerD("Event network list size=" << m_eventNetworkList.size());
681 } else if (watchType == WATCH_TYPE_LOCALE) {
682 m_eventLocaleList.push_back(arg);
683 LoggerD("Event Locale list size=" << m_eventLocaleList.size());
684 } else if (watchType == WATCH_TYPE_PERIPHERAL) {
685 m_eventPeripheralList.push_back(arg);
686 LoggerD("Event peripheral list size=" << m_eventPeripheralList.size());
690 void Systeminfo::EventMgr::removeEvent(WatchId id, const int watchType)
692 DPL::Mutex::ScopedLock lock(&m_synchro);
693 LoggerD("Event id : " << id);
695 EventWatchSysteminfoPtr event(NULL);
697 LoggerD("trying to delete event, id=" << id);
699 if (watchType == WATCH_TYPE_BATTERY) {
700 for (EventBatteryList::iterator it = m_eventBatteryList.begin(); it != m_eventBatteryList.end(); it++) {
701 if (id == (*it)->getId()) {
707 LoggerE("event id not in the list, nothing to do");
711 LoggerD("event Battery list size=" << m_eventBatteryList.size());
712 m_eventBatteryList.remove(event);
713 LoggerD( "event removed, event Battery list size=" << m_eventBatteryList.size());
714 } else if (watchType == WATCH_TYPE_DISPLAY) {
715 for (EventDisplayList::iterator it = m_eventDisplayList.begin(); it != m_eventDisplayList.end(); it++) {
716 if (id == (*it)->getId()) {
722 LoggerE("event id not in the list, nothing to do");
726 LoggerD("event display list size=" << m_eventDisplayList.size());
727 m_eventDisplayList.remove(event);
728 LoggerD( "event removed, event display list size=" << m_eventDisplayList.size());
729 } else if (watchType == WATCH_TYPE_WIFINETWORK) {
730 for (EventWifiNetworkList::iterator it = m_eventWifiNetworkList.begin(); it != m_eventWifiNetworkList.end(); it++) {
731 if (id == (*it)->getId()) {
737 LoggerE("event id not in the list, nothing to do");
741 LoggerD("event wifi network list size=" << m_eventWifiNetworkList.size());
742 m_eventWifiNetworkList.remove(event);
743 LoggerD( "event removed, event wifi network list size=" << m_eventCelluarNetworkList.size());
744 } else if (watchType == WATCH_TYPE_CELLULARNETWORK) {
745 for (EventCellularNetworkList::iterator it = m_eventCelluarNetworkList.begin(); it != m_eventCelluarNetworkList.end(); it++) {
746 if (id == (*it)->getId()) {
752 LoggerE("event id not in the list, nothing to do");
756 LoggerD("event cellular network list size=" << m_eventCelluarNetworkList.size());
757 m_eventCelluarNetworkList.remove(event);
758 LoggerD( "event removed, event cellular network list size=" << m_eventCelluarNetworkList.size());
759 } else if (watchType == WATCH_TYPE_STORAGE) {
760 for (EventStorageList::iterator it = m_eventStorageList.begin(); it != m_eventStorageList.end(); it++) {
761 if (id == (*it)->getId()) {
767 LoggerE("event id not in the list, nothing to do");
771 LoggerD("event storage list size=" << m_eventStorageList.size());
772 m_eventStorageList.remove(event);
773 LoggerD( "event removed, event storage list size=" << m_eventStorageList.size());
774 } else if (watchType == WATCH_TYPE_CPU) {
775 for (EventCpuList::iterator it = m_eventCpuList.begin(); it != m_eventCpuList.end(); it++) {
776 if (id == (*it)->getId()) {
782 LoggerE("event id not in the list, nothing to do");
786 LoggerD("event cpu list size=" << m_eventCpuList.size());
787 m_eventCpuList.remove(event);
788 LoggerD( "event removed, event cpu list size=" << m_eventCpuList.size());
789 } else if (watchType == WATCH_TYPE_SIM) {
790 for (EventSimList::iterator it = m_eventSimList.begin(); it != m_eventSimList.end(); it++) {
791 if (id == (*it)->getId()) {
797 LoggerE("event id not in the list, nothing to do");
801 LoggerD("event sim list size=" << m_eventSimList.size());
802 m_eventSimList.remove(event);
803 LoggerD( "event removed, event sim list size=" << m_eventSimList.size());
804 } else if (watchType == WATCH_TYPE_DEVICE_ORIENTATION) {
805 for (EventDeviceOrientationList::iterator it = m_eventDeviceOrientationList.begin(); it != m_eventDeviceOrientationList.end(); it++) {
806 if (id == (*it)->getId()) {
812 LoggerE("event id not in the list, nothing to do");
816 LoggerD("event device orientation list size=" << m_eventDeviceOrientationList.size());
817 m_eventDeviceOrientationList.remove(event);
818 LoggerD( "event removed, event device orientation list size=" << m_eventDeviceOrientationList.size());
819 } else if (watchType == WATCH_TYPE_NETWORK) {
820 for (EventNetworkList::iterator it = m_eventNetworkList.begin(); it != m_eventNetworkList.end(); it++) {
821 if (id == (*it)->getId()) {
827 LoggerE("event id not in the list, nothing to do");
831 LoggerD("event network list size=" << m_eventNetworkList.size());
832 m_eventNetworkList.remove(event);
833 LoggerD( "event removed, event network list size=" << m_eventNetworkList.size());
834 } else if (watchType == WATCH_TYPE_LOCALE) {
835 for (EventLocaleList::iterator it = m_eventLocaleList.begin(); it != m_eventLocaleList.end(); it++) {
836 if (id == (*it)->getId()) {
842 LoggerE("event id not in the list, nothing to do");
846 LoggerD("event Locale list size=" << m_eventLocaleList.size());
847 m_eventLocaleList.remove(event);
848 LoggerD( "event removed, event Locale list size=" << m_eventLocaleList.size());
849 } else if (watchType == WATCH_TYPE_PERIPHERAL) {
850 for (EventPeripheralList::iterator it = m_eventPeripheralList.begin(); it != m_eventPeripheralList.end(); it++) {
851 if (id == (*it)->getId()) {
857 LoggerE("event id not in the list, nothing to do");
861 LoggerD("event peripheral list size=" << m_eventPeripheralList.size());
862 m_eventPeripheralList.remove(event);
863 LoggerD( "event removed, event peripheral list size=" << m_eventPeripheralList.size());
867 const int Systeminfo::EventMgr::getWatchType(const long id)
869 DPL::Mutex::ScopedLock lock(&m_synchro);
871 EventWatchSysteminfoPtr event(NULL);
873 for (EventBatteryList::iterator it = m_eventBatteryList.begin(); it != m_eventBatteryList.end(); it++) {
874 if (id == (*it)->getId()) {
880 for (EventDisplayList::iterator it = m_eventDisplayList.begin(); it != m_eventDisplayList.end(); it++) {
881 if (id == (*it)->getId()) {
887 for (EventWifiNetworkList::iterator it = m_eventWifiNetworkList.begin(); it != m_eventWifiNetworkList.end(); it++) {
888 if (id == (*it)->getId()) {
894 for (EventCellularNetworkList::iterator it = m_eventCelluarNetworkList.begin(); it != m_eventCelluarNetworkList.end(); it++) {
895 if (id == (*it)->getId()) {
901 for (EventStorageList::iterator it = m_eventStorageList.begin(); it != m_eventStorageList.end(); it++) {
902 if (id == (*it)->getId()) {
908 for (EventCpuList::iterator it = m_eventCpuList.begin(); it != m_eventCpuList.end(); it++) {
909 if (id == (*it)->getId()) {
915 for (EventSimList::iterator it = m_eventSimList.begin(); it != m_eventSimList.end(); it++) {
916 if (id == (*it)->getId()) {
922 for (EventDeviceOrientationList::iterator it = m_eventDeviceOrientationList.begin(); it != m_eventDeviceOrientationList.end(); it++) {
923 if (id == (*it)->getId()) {
929 for (EventNetworkList::iterator it = m_eventNetworkList.begin(); it != m_eventNetworkList.end(); it++) {
930 if (id == (*it)->getId()) {
936 for (EventSimList::iterator it = m_eventSimList.begin(); it != m_eventSimList.end(); it++) {
937 if (id == (*it)->getId()) {
943 for (EventLocaleList::iterator it = m_eventLocaleList.begin(); it != m_eventLocaleList.end(); it++) {
944 if (id == (*it)->getId()) {
950 for (EventPeripheralList::iterator it = m_eventPeripheralList.begin(); it != m_eventPeripheralList.end(); it++) {
951 if (id == (*it)->getId()) {
958 LoggerE("event id not in the list, nothing to do");
959 return WATCH_TYPE_UNKNOWN;
962 return event->getWatchType();
965 EventBatteryList Systeminfo::EventMgr::getEventBatteryList()
967 return m_eventBatteryList;
970 EventDisplayList Systeminfo::EventMgr::getEventDisplayList()
972 return m_eventDisplayList;
975 EventNetworkList Systeminfo::EventMgr::getEventNetworkList()
977 return m_eventNetworkList;
980 EventWifiNetworkList Systeminfo::EventMgr::getEventWifiNetworkList()
982 return m_eventWifiNetworkList;
985 EventCellularNetworkList Systeminfo::EventMgr::getEventCellularNetworkList()
987 return m_eventCelluarNetworkList;
990 EventStorageList Systeminfo::EventMgr::getEventStorageList()
992 return m_eventStorageList;
995 EventCpuList Systeminfo::EventMgr::getEventCpuList()
997 return m_eventCpuList;
1000 EventDeviceOrientationList Systeminfo::EventMgr::getEventDeviceOrientationList()
1002 return m_eventDeviceOrientationList;
1005 EventSimList Systeminfo::EventMgr::getEventSimList()
1007 return m_eventSimList;
1010 EventLocaleList Systeminfo::EventMgr::getEventLocaleList()
1012 return m_eventLocaleList;
1015 EventPeripheralList Systeminfo::EventMgr::getEventPeripheralList()
1017 return m_eventPeripheralList;
1020 ////////////////////////////////////////////////////////////////////////////////////////
1022 PROPERTY_GET_SYSTEMINFO_DEFINITION(Battery) {
1023 BatteryPropertiesPtr BatteryPtr(new BatteryProperties());
1027 if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, &value) != 0) {
1028 return JSValueMakeNull(context);
1030 BatteryPtr->level = (double)(value)/CPU_POWER_DEVICE_VALUE;
1033 if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &value2) != 0) {
1034 return JSValueMakeNull(context);
1036 BatteryPtr->isCharging = (value2 == 0) ? false : true;
1039 return JSBatteryInfo::createJSObject(context, BatteryPtr);
1042 PROPERTY_GET_SYSTEMINFO_DEFINITION(Cpu) {
1043 Converter converter(context);
1045 CpuPropertiesPtr cpuPtr(new CpuProperties());
1047 long long usr = 0, nice = 0, system = 0, idle = 0, total = 0, cpuUsage = 0;
1049 fp = fopen("/proc/stat", "r");
1051 return JSValueMakeNull(context);
1054 if (fscanf(fp, "%*s %lld %lld %lld %lld", &usr, &system, &nice, &idle) > 0) {
1055 total = usr + nice + system + idle;
1056 if ((total > 0LL) && (idle > 0LL)) {
1057 cpuUsage = idle * 100LL / total;
1058 cpuPtr->load = (double)cpuUsage / 100.0;
1059 LoggerD("cpu load : " << cpuPtr->load);
1064 return JSCpuInfo::createJSObject(context, cpuPtr);
1067 PROPERTY_GET_SYSTEMINFO_DEFINITION(Storage) {
1068 Converter converter(context);
1072 if (statfs(STORAGE_INTERNAL_PATH, &fs) < 0) {
1074 return JSValueMakeNull(context);
1076 StoragePropertiesPtr storagePtr(new StorageProperties());
1077 storagePtr->units[0].type = "INTERNAL";
1078 storagePtr->units[0].capacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_blocks;
1079 storagePtr->units[0].availableCapacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_bavail;
1080 storagePtr->units[0].isRemoveable = false;
1081 storagePtr->units[0].isRemovable = false;
1082 storagePtr->cnt = 1;
1083 LoggerD("type : " << storagePtr->units[0].type);
1084 if(vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &sdcardState) == 0) {
1085 if(sdcardState == VCONFKEY_SYSMAN_MMC_MOUNTED){
1086 if (statfs(STORAGE_SDCARD_PATH, &fs) < 0) {
1087 return JSValueMakeNull(context);
1089 storagePtr->units[1].type = "MMC";
1090 storagePtr->units[1].capacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_blocks;
1091 storagePtr->units[1].availableCapacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_bavail;
1092 storagePtr->units[1].isRemoveable = false;
1093 storagePtr->units[1].isRemovable = false;
1094 storagePtr->cnt = 2;
1095 LoggerD("type : " << storagePtr->units[1].type);
1098 return JSStorageInfo::createJSObject(context, storagePtr);
1102 PROPERTY_GET_SYSTEMINFO_DEFINITION(Display) {
1103 Converter converter(context);
1105 DisplayPropertiesPtr display(new DisplayProperties());
1106 int brightness=0, dotsPerInchX=0, dotsPerInchY=0, physicalW=0, physicalH=0, resolutionW=0, resolutionH=0;
1108 if(vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, &brightness) == 0) {
1109 display->brightness = (double)(brightness)/DISPLAY_BRIGHTNESS_DIVIDE_VALUE;
1110 LoggerD("brightness : " << display->brightness);
1113 if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_WIDTH, &resolutionW) == SYSTEM_INFO_ERROR_NONE) {
1114 display->resolutionWidth = resolutionW;
1115 LoggerD("resolutionWidth : " << display->resolutionWidth);
1117 if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_HEIGHT, &resolutionH) == SYSTEM_INFO_ERROR_NONE) {
1118 display->resolutionHeight = resolutionH;
1119 LoggerD("resolutionHeight : " << display->resolutionHeight);
1121 if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_DPI, &dotsPerInchX) == SYSTEM_INFO_ERROR_NONE) {
1122 display->dotsPerInchWidth = dotsPerInchX;
1123 LoggerD("dotsPerInchWidth : " << display->dotsPerInchWidth);
1125 if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_DPI, &dotsPerInchY) == SYSTEM_INFO_ERROR_NONE) {
1126 display->dotsPerInchHeight = dotsPerInchY;
1127 LoggerD("dotsPerInchHeight : " << display->dotsPerInchHeight);
1129 if (system_info_get_value_int(SYSTEM_INFO_KEY_PHYSICAL_SCREEN_HEIGHT, &physicalH) == SYSTEM_INFO_ERROR_NONE) {
1130 display->physicalHeight = physicalH;
1131 LoggerD("physicalHeight : " << display->physicalHeight);
1133 if (system_info_get_value_int(SYSTEM_INFO_KEY_PHYSICAL_SCREEN_WIDTH, &physicalW) == SYSTEM_INFO_ERROR_NONE) {
1134 display->physicalWidth = physicalW;
1135 LoggerD("physicalWidth : " << display->physicalWidth);
1138 return JSDisplayInfo::createJSObject(context, display);
1141 PROPERTY_GET_SYSTEMINFO_DEFINITION(Network) {
1143 Converter converter(context);
1144 NetworkPropertiesPtr Network(new NetworkProperties());
1145 connection_h connectionHandle = (connection_h)handle;
1146 connection_type_e connectionType;
1147 int networkType = 0;
1149 if (connection_get_type(connectionHandle, &connectionType) != CONNECTION_ERROR_NONE) {
1150 LoggerD("get connection type is failed");
1151 return JSNetworkInfo::createJSObject(context, Network);
1154 if (connectionType == CONNECTION_TYPE_WIFI) {
1155 LoggerD("wifi network");
1156 Network->networkType= "WIFI";
1157 } else if (connectionType == CONNECTION_TYPE_CELLULAR) {
1158 if (vconf_get_int(VCONFKEY_TELEPHONY_SVCTYPE, &networkType) == 0) {
1159 if (networkType < VCONFKEY_TELEPHONY_SVCTYPE_2G) {
1160 Network->networkType= "NONE";
1161 } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_2G) {
1162 Network->networkType= "2G";
1163 } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_2G || networkType == VCONFKEY_TELEPHONY_SVCTYPE_2_5G_EDGE) {
1164 Network->networkType= "2.5";
1165 } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_3G || networkType == VCONFKEY_TELEPHONY_SVCTYPE_HSDPA) {
1166 Network->networkType= "3G";
1167 } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_LTE) {
1168 Network->networkType= "4G";
1170 Network->networkType= "NONE";
1174 Network->networkType= "NONE";
1177 return JSNetworkInfo::createJSObject(context, Network);
1180 PROPERTY_GET_SYSTEMINFO_DEFINITION(WifiNetwork) {
1181 Converter converter(context);
1182 WifiNetworkPropertiesPtr wifiNetwork(new WifiNetworkProperties());
1183 connection_h connectionHandle = (connection_h)handle;
1184 connection_type_e connectionType;
1185 connection_profile_h profileHandle = NULL;
1186 connection_address_family_e addressFamily = CONNECTION_ADDRESS_FAMILY_IPV4;
1187 char* ipAddr = NULL;
1191 if (connection_get_type(connectionHandle, &connectionType) != CONNECTION_ERROR_NONE) {
1192 return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1195 if (connectionType == CONNECTION_TYPE_WIFI) {
1196 wifiNetwork->status = "ON";
1198 wifiNetwork->status = "OFF";
1199 return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1202 if (connection_get_current_profile(connectionHandle, &profileHandle) != CONNECTION_ERROR_NONE) {
1203 return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1206 if (connection_profile_get_wifi_essid(profileHandle, &essid) == CONNECTION_ERROR_NONE) {
1207 wifiNetwork->ssid = essid;
1211 if (connection_profile_get_ip_address(profileHandle, addressFamily, &ipAddr) == CONNECTION_ERROR_NONE) {
1212 wifiNetwork->ipAddress = ipAddr;
1216 if (connection_profile_get_wifi_rssi(profileHandle, &rssi) == CONNECTION_ERROR_NONE) {
1217 wifiNetwork->signalStrength = (double) rssi/WIFI_SIGNAL_STRENGTH_DIVIDE_VALUE;
1220 return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1223 PROPERTY_GET_SYSTEMINFO_DEFINITION(CellularNetwork) {
1224 Converter converter(context);
1225 CellularNetworkPropertiesPtr cellularNetwork(new CellularNetworkProperties());
1226 connection_h connectionHandle = (connection_h)handle;
1227 connection_type_e connectionType;
1228 connection_profile_h profileHandle = NULL;
1229 connection_address_family_e addressFamily = CONNECTION_ADDRESS_FAMILY_IPV4;
1230 char* ipAddr = NULL;
1233 int plmn = 0, cellId = 0, lac = 0, isRoaming = 0, isFlightMode = 0;
1234 TapiHandle *tapiHandle = NULL;
1236 TIME_TRACER_ITEM_BEGIN("(cellular)mcc", 0);
1237 if (vconf_get_int(VCONFKEY_TELEPHONY_PLMN, &plmn) == 0) {
1238 cellularNetwork->mcc = plmn / 100;
1239 cellularNetwork->mnc = plmn % 100;
1241 TIME_TRACER_ITEM_END("(cellular)mcc", 0);
1243 TIME_TRACER_ITEM_BEGIN("(cellular)cellId", 0);
1244 if (vconf_get_int(VCONFKEY_TELEPHONY_CELLID, &cellId) == 0) {
1245 cellularNetwork->cellId = cellId;
1247 TIME_TRACER_ITEM_END("(cellular)cellId", 0);
1249 TIME_TRACER_ITEM_BEGIN("(cellular)lac", 0);
1250 if (vconf_get_int(VCONFKEY_TELEPHONY_LAC, &lac) == 0) {
1251 cellularNetwork->lac = lac;
1253 TIME_TRACER_ITEM_END("(cellular)lac", 0);
1255 TIME_TRACER_ITEM_BEGIN("(cellular)isRoaming", 0);
1256 if (vconf_get_int(VCONFKEY_TELEPHONY_SVC_ROAM, &isRoaming) == 0) {
1258 cellularNetwork->isRoaming = true;
1260 cellularNetwork->isRoaming = false;
1263 TIME_TRACER_ITEM_END("(cellular)isRoaming", 0);
1265 TIME_TRACER_ITEM_BEGIN("(cellular)isFlightMode", 0);
1266 if (vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &isFlightMode) == 0) {
1268 cellularNetwork->isFlightMode = true;
1270 cellularNetwork->isFlightMode = false;
1273 TIME_TRACER_ITEM_END("(cellular)isFlightMode", 0);
1275 if (connection_get_type(connectionHandle, &connectionType) != CONNECTION_ERROR_NONE) {
1276 return JSCellularNetworkInfo::createJSObject(context, cellularNetwork);
1279 if (connectionType == CONNECTION_TYPE_CELLULAR) {
1280 cellularNetwork->status = "ON";
1281 if (connection_get_current_profile(connectionHandle, &profileHandle) == CONNECTION_ERROR_NONE) {
1282 TIME_TRACER_ITEM_BEGIN("(cellular)apn", 0);
1283 if (connection_profile_get_cellular_apn(profileHandle, &apn) == CONNECTION_ERROR_NONE) {
1284 cellularNetwork->apn = apn;
1287 TIME_TRACER_ITEM_END("(cellular)apn", 0);
1289 TIME_TRACER_ITEM_BEGIN("(cellular)ipAddress", 0);
1290 if (connection_profile_get_ip_address(profileHandle, addressFamily, &ipAddr) == CONNECTION_ERROR_NONE) {
1291 cellularNetwork->ipAddress = ipAddr;
1294 TIME_TRACER_ITEM_END("(cellular)ipAddress", 0);
1295 connection_profile_destroy(profileHandle);
1298 cellularNetwork->status = "OFF";
1299 if (connection_get_default_cellular_service_profile(connectionHandle, CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET, &profileHandle) == CONNECTION_ERROR_NONE) {
1300 TIME_TRACER_ITEM_BEGIN("(cellular)apn", 0);
1301 if (connection_profile_get_cellular_apn(profileHandle, &apn) == CONNECTION_ERROR_NONE) {
1302 cellularNetwork->apn = apn;
1305 TIME_TRACER_ITEM_END("(cellular)apn", 0);
1306 connection_profile_destroy(profileHandle);
1310 tapiHandle = tel_init(0);
1312 if (tapiHandle != NULL) {
1313 imei = tel_get_misc_me_imei_sync(tapiHandle);
1316 tel_deinit(tapiHandle);
1317 return JSCellularNetworkInfo::createJSObject(context, cellularNetwork);
1320 cellularNetwork->imei = imei;
1322 tel_deinit(tapiHandle);
1325 return JSCellularNetworkInfo::createJSObject(context, cellularNetwork);
1328 PROPERTY_GET_SYSTEMINFO_DEFINITION(SIM) {
1329 Converter converter(context);
1330 SIMPropertiesPtr SIM(new SIMProperties());
1333 char* fullName = NULL;
1334 char* shortName = NULL;
1335 char* msisdn = NULL;
1341 int ret = SIM_ERROR_NONE;
1343 ret = sim_get_state(&state);
1344 if (ret == SIM_ERROR_NONE) {
1345 if (state == SIM_STATE_UNAVAILABLE) {
1346 SIM->state = "ABSENT";
1347 } else if (state == SIM_STATE_LOCKED) {
1348 SIM->state = "PIN_REQUIRED";
1349 } else if (state == SIM_STATE_AVAILABLE) {
1350 SIM->state = "READY";
1351 } else if (state == SIM_STATE_UNKNOWN) {
1352 SIM->state = "INITIALIZING";
1356 ret = sim_get_cphs_operator_name(&fullName, &shortName);
1357 if (ret == SIM_ERROR_NONE) {
1359 SIM->operatorName = fullName;
1360 LoggerD("operatorName : " << SIM->operatorName);
1362 } else if (shortName) {
1363 SIM->operatorName = shortName;
1364 LoggerD("operatorName : " << SIM->operatorName);
1370 ret = sim_get_subscriber_number(&msisdn);
1371 if (ret == SIM_ERROR_NONE) {
1373 SIM->msisdn = msisdn;
1374 LoggerD("msisdn : " << SIM->msisdn);
1379 ret = sim_get_icc_id(&iccId);
1380 if (ret == SIM_ERROR_NONE) {
1383 LoggerD("iccid : " << SIM->iccid);
1388 ret = sim_get_mcc(&mcc);
1389 if (ret == SIM_ERROR_NONE) {
1391 SIM->mcc = atoi(mcc);
1392 LoggerD("mcc : " << SIM->mcc);
1397 ret = sim_get_mnc(&mnc);
1398 if (ret == SIM_ERROR_NONE) {
1400 SIM->mnc = atoi(mnc);
1401 LoggerD("mnc : " << SIM->mnc);
1406 ret = sim_get_msin(&msin);
1407 if (ret == SIM_ERROR_NONE) {
1410 LoggerD("msin : " << SIM->msin);
1415 ret = sim_get_spn(&spn);
1416 if (ret == SIM_ERROR_NONE) {
1419 LoggerD("spn : " << SIM->spn);
1424 return JSSIMInfo::createJSObject(context, SIM);
1427 PROPERTY_GET_SYSTEMINFO_DEFINITION(DeviceOrientation) {
1429 Converter converter(context);
1430 DeviceOrientationPropertiesPtr deviceOrientation(new DeviceOrientationProperties());
1432 unsigned long rotation = 0;
1433 int handleOrientaion = 0;
1434 int isAutoRotation = 0;
1436 if (vconf_get_bool(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &isAutoRotation) == 0) {
1437 if (isAutoRotation) {
1438 deviceOrientation->isAutoRotation = true;
1440 deviceOrientation->isAutoRotation = false;
1444 handleOrientaion = sf_connect(ACCELEROMETER_SENSOR);
1445 LoggerD("handleOrientaion : " << handleOrientaion);
1446 if (handleOrientaion < 0) {
1447 LoggerD ("sensor attach fail");
1448 return JSDeviceOrientationInfo::createJSObject(context, deviceOrientation);
1450 int state = sf_start(handleOrientaion, 0);
1452 LoggerD("start failed");
1455 int ret_val = sf_check_rotation(&rotation);
1457 LoggerD("sf_check_rotation fail to gather data\n");
1460 LoggerD(" rotation value = " << rotation);
1464 case ROTATION_EVENT_0:
1465 LoggerD("my_callback_func received data (PORTRAIT_TOP|HEAD_CENTER)\n");
1466 deviceOrientation->status = "PORTRAIT_PRIMARY";
1468 case ROTATION_EVENT_90:
1469 LoggerD("my_callback_func received data (LANDSCAPE|HEAD_RIGHT)\n");
1470 deviceOrientation->status = "LANDSCAPE_PRIMARY";
1472 case ROTATION_EVENT_180:
1473 LoggerD("my_callback_func received data (PORTRAIT_BTM|HEAD_CENTER)\n");
1474 deviceOrientation->status = "PORTRAIT_SECONDARY";
1476 case ROTATION_EVENT_270:
1477 LoggerD("my_callback_func received data (LANDSCAPE|HEAD_LEFT)\n");
1478 deviceOrientation->status = "LANDSCAPE_SECONDARY";
1481 LoggerD(" received data unexpected\n");
1485 state = sf_stop(handleOrientaion);
1486 LoggerD("handleOrientaion 1 state = " << state);
1488 state = sf_disconnect(handleOrientaion);
1489 LoggerD("handleOrientaion state =" << state);
1491 return JSDeviceOrientationInfo::createJSObject(context, deviceOrientation);
1494 PROPERTY_GET_SYSTEMINFO_DEFINITION(Build) {
1496 Converter converter(context);
1497 BuildPropertiesPtr Build(new BuildProperties());
1500 char* manufacturer = NULL;
1501 char* buildVersion = NULL;
1503 if (system_info_get_value_string(SYSTEM_INFO_KEY_MODEL, &model) == SYSTEM_INFO_ERROR_NONE) {
1504 if (model != NULL) {
1505 LoggerD("model : " << model);
1506 Build->model = model;
1511 if (system_info_get_value_string(SYSTEM_INFO_KEY_MANUFACTURER, &manufacturer) == SYSTEM_INFO_ERROR_NONE) {
1512 if (manufacturer != NULL) {
1513 LoggerD("manufacturer : " << manufacturer);
1514 Build->manufacturer = manufacturer;
1519 if (system_info_get_value_string(SYSTEM_INFO_KEY_BUILD_STRING, &buildVersion) == SYSTEM_INFO_ERROR_NONE) {
1520 if (buildVersion != NULL) {
1521 LoggerD("buildVersion : " << buildVersion);
1522 Build->buildVersion = buildVersion;
1527 return JSBuildInfo::createJSObject(context, Build);
1530 PROPERTY_GET_SYSTEMINFO_DEFINITION(Locale) {
1532 Converter converter(context);
1533 LocalePropertiesPtr Locale(new LocaleProperties());
1535 char* country = NULL;
1536 char* language = NULL;
1538 if (runtime_info_get_value_string(RUNTIME_INFO_KEY_LANGUAGE, &language) == RUNTIME_INFO_ERROR_NONE) {
1539 if (language != NULL) {
1540 LoggerD("language : " << language);
1541 Locale->language = language;
1546 if (runtime_info_get_value_string(RUNTIME_INFO_KEY_REGION, &country) == RUNTIME_INFO_ERROR_NONE) {
1547 if (country != NULL) {
1548 LoggerD("country : " << country);
1550 char* countryTemp = NULL;
1551 token = strtok(country, ".");
1552 if (token != NULL) {
1553 countryTemp = strdup(token);
1554 if (countryTemp != NULL) {
1555 Locale->country = countryTemp;
1563 return JSLocaleInfo::createJSObject(context, Locale);
1566 PROPERTY_GET_SYSTEMINFO_DEFINITION(Peripheral) {
1567 Converter converter(context);
1568 PeripheralPropertiesPtr peripheral(new PeripheralProperties());
1569 int hdmiStatus = 0, wirelessDisplayStatus = 0 ;
1571 if (vconf_get_int(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, &wirelessDisplayStatus) == 0) {
1572 switch(wirelessDisplayStatus) {
1573 case VCONFKEY_MIRACAST_WFD_SOURCE_ON:
1574 peripheral->isVideoOutputOn = true;
1577 LoggerD("VideOutput status is off");
1582 if (vconf_get_int(VCONFKEY_SYSMAN_HDMI, &hdmiStatus) == 0) {
1583 switch(hdmiStatus) {
1584 case VCONFKEY_SYSMAN_HDMI_CONNECTED:
1585 peripheral->isVideoOutputOn = true;
1588 LoggerD("VideOutput status is off");
1593 return JSPeripheralInfo::createJSObject(context, peripheral);