Update change log and spec for wrt-plugins-tizen_0.4.44
[framework/web/wrt-plugins-tizen.git] / src / Systeminfo / Systeminfo.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 #include <stddef.h>
19 #include <cassert>
20 #include <math.h>
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>
27 #include <sim.h>
28 #include "Systeminfo.h"
29 #include <Logger.h>
30
31 using namespace WrtDeviceApis::CommonsJavaScript;
32 using namespace WrtDeviceApis::Commons;
33
34
35 namespace DeviceAPI {
36 namespace Systeminfo {
37
38 namespace {
39
40 void BatteryValueCallback(keynode_t *node, void *event_ptr)
41 {
42     if(event_ptr) {
43         ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_BATTERY);
44     }
45 }
46
47 void PeripheralValueCallback(keynode_t *node, void *event_ptr)
48 {
49     if(event_ptr) {
50         ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_PERIPHERAL);
51     }
52 }
53
54 void CellularNetworkValueCallback(keynode_t *node, void *event_ptr)
55 {
56     if(event_ptr) {
57         ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_CELLULARNETWORK);
58     }
59 }
60
61 void DisplayValueCallback(keynode_t *node, void* event_ptr)
62 {
63     if(event_ptr) {
64         ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_DISPLAY);
65     }
66 }
67
68 void OrientationValueVconfCallback(keynode_t *node, void *event_ptr)
69 {
70     LoggerD("enter");
71     if(event_ptr) {
72         ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_DEVICE_ORIENTATION);
73     }    
74 }
75
76 void NetworkTypeValueCallback(connection_type_e type, void* event_ptr)
77 {
78     if(event_ptr) {
79         ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_NETWORK);
80     }
81 }
82
83 void NetworkValueCallback(const char* ipv4_address, const char* ipv6_address, void* event_ptr)
84 {
85     if(event_ptr) {
86         ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_NETWORK_ALL);
87     }
88 }
89
90 static Eina_Bool StorageValueCallback(void* event_ptr)
91 {
92     if(event_ptr) {
93         ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_STORAGE);
94     }
95     return ECORE_CALLBACK_RENEW;
96 }
97
98 static Eina_Bool CpuValueCallback(void* event_ptr)
99 {
100     if(event_ptr) {
101         ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_CPU);
102     }
103     return ECORE_CALLBACK_RENEW;
104 }
105
106 void OrientationValueCallback(unsigned int event_type, sensor_event_data_t *event , void *event_ptr)
107 {
108     if(event_ptr) {
109         ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_DEVICE_ORIENTATION);
110     }
111 }
112
113 void localeChangedCallback(runtime_info_key_e key, void* event_ptr)
114 {
115     if(event_ptr) {
116         ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_LOCALE);
117     }    
118 }
119
120 }
121
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
128
129 #define RADIAN_VALUE (57.2957)
130
131 enum {
132     STORAGE_TYPE_UNKNOWN = 0,
133     STORAGE_TYPE_INTERNAL = 1,
134     STORAGE_TYPE_MMC = 2,
135     STORAGE_TYPE_USBHOST = 3
136 };
137
138 Systeminfo::OptionalProperty Systeminfo::m_Property;
139
140 Systeminfo::Systeminfo() : m_networkRegist(REGIST_NOT),
141                         m_storageTimer(NULL),
142                         m_cpuTimer(NULL),
143                         m_sensorHandle(0),
144                         m_connectionHandle(NULL)
145 {
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());
163     }
164
165     int ret = connection_create(&m_connectionHandle);
166
167         if (CONNECTION_ERROR_NONE == ret) {
168                 LoggerD("Network Client registration success");
169         } else {
170                 LoggerD("Network Client registration success");
171         m_connectionHandle = NULL;
172     }
173
174     m_sensorHandle = sf_connect(ACCELEROMETER_SENSOR);
175     if (m_sensorHandle < 0) {
176         LoggerD ("sensor attach fail");
177     } else {
178         LoggerD("m_sensorHandle : " << m_sensorHandle);
179         int state = sf_start(m_sensorHandle, 0);
180         if(state < 0) {
181             LoggerD("failed");
182         }
183     }
184 }
185
186 Systeminfo::~Systeminfo()
187 {
188         int state = 0;
189     if (m_storageTimer) {
190         ecore_timer_freeze(m_storageTimer);
191         ecore_timer_del(m_storageTimer);
192         m_storageTimer = NULL;
193     }
194     if (m_cpuTimer) {
195         ecore_timer_freeze(m_cpuTimer);
196         ecore_timer_del(m_cpuTimer);
197         m_cpuTimer = NULL;
198     }
199     m_EventMgrPtr->clearAllEvent();
200
201     if(m_connectionHandle != NULL) {
202         LoggerD("Network Client deregistration success");
203         connection_destroy(m_connectionHandle);
204     } else {
205         LoggerD("Network Client deregistration failed");
206     }
207
208         state = sf_stop(m_sensorHandle);
209         LoggerD("handle 1  state = " << state);
210
211         state = sf_disconnect(m_sensorHandle);
212         LoggerD("handle  state =" << state);
213 }
214
215 DeviceCapabilitiesPropertiesPtr Systeminfo::getCapabilities()
216 {
217     LoggerD("enter");
218     DeviceCapabilitiesPropertiesPtr deviceCapabilities(new DeviceCapabilitiesProperties());
219     return deviceCapabilities;
220 }
221
222 void Systeminfo::get(const EventGetSysteminfoPtr& event)
223 {
224     EventRequestReceiver<EventGetSysteminfo>::PostRequest(event);
225 }
226
227 void Systeminfo::watch(const EventWatchSysteminfoPtr& event)
228 {
229     if(event->getWatchType() == WATCH_TYPE_UNKNOWN) {
230         LoggerD("watch method is not supported");
231         event->setId(-1);
232         return;
233     }
234
235     event->setSysteminfoPtr(this);
236     m_EventMgrPtr->addEvent(event, event->getWatchType());
237
238     EventRequestReceiver<EventWatchSysteminfo>::PostRequest(event);
239 }
240
241 void Systeminfo::clearWatch(const long id)
242 {
243     if (id < 1) {
244         Throw(WrtDeviceApis::Commons::InvalidArgumentException);
245     } else {
246         int watchType = m_EventMgrPtr->getWatchType(id);
247         switch(watchType) {
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);
252                 }
253                 break;
254             case WATCH_TYPE_DISPLAY:
255                 if ((m_EventMgrPtr->getEventDisplayList()).size() == 1) {
256                     vconf_ignore_key_changed(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, DisplayValueCallback);
257                 }
258                 break;
259             case WATCH_TYPE_NETWORK:
260                 if ((m_EventMgrPtr->getEventNetworkList()).size() == 1) {
261                     connection_unset_type_changed_cb(m_connectionHandle);
262                 }
263                 break;
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;
271                     }
272                 }
273                 break;
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;
285                     }
286                 }
287                 break;
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;
294                     }
295                 }
296                 break;
297             case WATCH_TYPE_CPU:
298                 if ((m_EventMgrPtr->getEventCpuList()).size() == 1) {
299                     if (m_cpuTimer) {
300                         ecore_timer_freeze(m_cpuTimer);
301                         ecore_timer_del(m_cpuTimer);
302                         m_cpuTimer = NULL;
303                     }
304                 }
305                 break;
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);
310                     if (state < 0) {
311                         LoggerD("sf_unregister_event fail to gather data\n");
312                     }
313                 }
314                 break;
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);
320                     }
321                     if (runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_REGION) != RUNTIME_INFO_ERROR_NONE) {
322                         LoggerE("regist failed");
323                         Throw(WrtDeviceApis::Commons::Exception);
324                     }
325                 }
326                 break;
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);
331                 }
332                 break;
333             case WATCH_TYPE_UNKNOWN:
334                 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
335                 break;
336         }
337         m_EventMgrPtr->removeEvent(id, watchType);
338     }
339 }
340
341 BasePropertyPtr Systeminfo::getBasePropertyPtr(JSContextRef context, JSValueRef property)
342 {
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);
350     }
351
352     return it->second;
353 }
354
355 void Systeminfo::getWatchValue(const int watchType)
356 {
357     LoggerD(" watch type : " << watchType);
358
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();
363             }
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();
368         }
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();
373         }
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();
380             }
381         }
382         if (eventListCellular.size() > 0) {
383             for (EventCellularNetworkList::iterator it = eventListCellular.begin(); it != eventListCellular.end(); it++) {
384                 (*it)->getWatchValue();
385             }
386         }
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();
391         }
392     } else if (watchType == WATCH_TYPE_STORAGE) {
393         EventStorageList eventList = m_EventMgrPtr->getEventStorageList();
394         for (EventStorageList::iterator it = eventList.begin(); it != eventList.end(); it++) {
395         int storageCnt = 1;
396         int sdcardState = 0;
397         if(vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &sdcardState) == 0) {
398             if(sdcardState == VCONFKEY_SYSMAN_MMC_MOUNTED) {
399                 storageCnt++;
400             }
401         }
402         LoggerD("storage cnt : " << storageCnt);
403             (*it)->getWatchValue(storageCnt);
404         }
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();
409         }
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();
414         }
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();
419         }
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();
425             }
426         }
427     }
428 }
429
430 connection_h Systeminfo::getConnectionHandle()
431 {
432     return m_connectionHandle;
433 }
434
435 JSValueRef Systeminfo::getCpuValue(JSContextRef context)
436 {
437     LoggerD("enter");
438     Converter converter(context);
439
440     CpuPropertiesPtr cpuPtr(new CpuProperties());
441     FILE *fp = NULL;
442     long long usr = 0, nice = 0, system = 0, idle = 0, cpuUsage = 0, diffIdle = 0, total = 0;
443
444     fp = fopen("/proc/stat", "r");
445     if(fp == NULL) {
446         return JSValueMakeNull(context);
447     }
448     
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;
455         m_cpuInfo.usr = usr;
456         m_cpuInfo.system = system;
457         m_cpuInfo.nice = nice;
458         m_cpuInfo.idle = idle;        
459             LoggerD("cpu load : " << cpuPtr->load);
460         }
461     }
462
463     fclose(fp);
464     return JSCpuInfo::createJSObject(context, cpuPtr);
465 }
466
467 void Systeminfo::OnRequestReceived(const EventGetSysteminfoPtr& event)
468 {
469     LoggerD("enter");
470     event->processGetValue((void *)m_connectionHandle);
471 }
472
473 void Systeminfo::OnRequestReceived(const EventWatchSysteminfoPtr& event)
474 {
475     WatchOption watchOption = event->getWatchOption();
476
477     event->switchToManualAnswer();
478     event->setCancelAllowed(true);
479
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);
485             }
486             break;
487         case WATCH_TYPE_DISPLAY:
488             if ((m_EventMgrPtr->getEventDisplayList()).size() == 1) {
489                 vconf_notify_key_changed(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, DisplayValueCallback, (void *)this);
490             }
491             break;
492         case WATCH_TYPE_NETWORK:
493             if ((m_EventMgrPtr->getEventNetworkList()).size() == 1) {
494                 connection_set_type_changed_cb(m_connectionHandle, NetworkTypeValueCallback, (void *)this);
495             }
496             break;
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;
504                 }
505             }
506             break;
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;
518                 }
519             }
520             break;
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);
526                 }
527             }
528             break;
529         case WATCH_TYPE_CPU:
530             if ((m_EventMgrPtr->getEventCpuList()).size() == 1) {
531                 if (!m_cpuTimer) {
532                     m_cpuTimer = ecore_timer_add(1, CpuValueCallback, this);
533                     ecore_timer_thaw(m_cpuTimer);
534                 }
535             }
536             break;
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);
542                 if (state < 0) {
543                     LoggerD("sensor_register_cb fail to gather data");
544                 } else if (state == 0) {
545                     LoggerD("sensor_register_cb success to gather data");
546                 }
547             } else {
548                 LoggerD("already regist");
549             }
550             break;
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);
556                 }
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);
560                 }
561             }
562             break;
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);
567             }
568             break;
569     }
570     event->processGetValue();
571     event->setTimer();
572 }
573
574 ////////////////////////////////////////////////////////////////////////////////////////
575
576 Systeminfo::EventMgr::EventMgr()
577 {
578 }
579
580 Systeminfo::EventMgr::~EventMgr()
581 {
582 }
583
584 void Systeminfo::EventMgr::clearAllEvent()
585 {
586     DPL::Mutex::ScopedLock lock(&m_synchro);
587
588     while (!m_eventBatteryList.empty()) {
589         EventWatchSysteminfoPtr event = m_eventBatteryList.front();
590         LoggerD("removing EventId=" << event->getId());
591         event->clearWatch();
592         m_eventBatteryList.pop_front();
593     }
594     while (!m_eventDisplayList.empty()) {
595         EventWatchSysteminfoPtr event = m_eventDisplayList.front();
596         LoggerD("removing EventId=" << event->getId());
597         event->clearWatch();
598         m_eventDisplayList.pop_front();
599     }
600     while (!m_eventWifiNetworkList.empty()) {
601         EventWatchSysteminfoPtr event = m_eventWifiNetworkList.front();
602         LoggerD("removing EventId=" << event->getId());
603         event->clearWatch();
604         m_eventWifiNetworkList.pop_front();
605     }
606     while (!m_eventCelluarNetworkList.empty()) {
607         EventWatchSysteminfoPtr event = m_eventCelluarNetworkList.front();
608         LoggerD("removing EventId=" << event->getId());
609         event->clearWatch();
610         m_eventCelluarNetworkList.pop_front();
611     }
612     while (!m_eventStorageList.empty()) {
613         EventWatchSysteminfoPtr event = m_eventStorageList.front();
614         LoggerD("removing EventId=" << event->getId());
615         event->clearWatch();
616         m_eventStorageList.pop_front();
617     }
618     while (!m_eventCpuList.empty()) {
619         EventWatchSysteminfoPtr event = m_eventCpuList.front();
620         LoggerD("removing EventId=" << event->getId());
621         event->clearWatch();
622         m_eventCpuList.pop_front();
623     }
624     while (!m_eventSimList.empty()) {
625         EventWatchSysteminfoPtr event = m_eventSimList.front();
626         LoggerD("removing EventId=" << event->getId());
627         event->clearWatch();
628         m_eventSimList.pop_front();
629     }
630     while (!m_eventDeviceOrientationList.empty()) {
631         EventWatchSysteminfoPtr event = m_eventDeviceOrientationList.front();
632         LoggerD("removing EventId=" << event->getId());
633         event->clearWatch();
634         m_eventDeviceOrientationList.pop_front();
635     }
636     while (!m_eventLocaleList.empty()) {
637         EventWatchSysteminfoPtr event = m_eventLocaleList.front();
638         LoggerD("removing EventId=" << event->getId());
639         event->clearWatch();
640         m_eventLocaleList.pop_front();
641     }
642     while (!m_eventPeripheralList.empty()) {
643         EventWatchSysteminfoPtr event = m_eventPeripheralList.front();
644         LoggerD("removing EventId=" << event->getId());
645         event->clearWatch();
646         m_eventPeripheralList.pop_front();
647     }
648 }
649
650 void Systeminfo::EventMgr::addEvent(const EventWatchSysteminfoPtr& arg, const int watchType)
651 {
652     DPL::Mutex::ScopedLock lock(&m_synchro);
653
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());
687     }
688 }
689
690 void Systeminfo::EventMgr::removeEvent(WatchId id, const int watchType)
691 {
692     DPL::Mutex::ScopedLock lock(&m_synchro);
693     LoggerD("Event id : " << id);
694
695     EventWatchSysteminfoPtr event(NULL);
696
697     LoggerD("trying to delete event, id=" << id);
698
699     if (watchType == WATCH_TYPE_BATTERY) {
700         for (EventBatteryList::iterator it = m_eventBatteryList.begin(); it != m_eventBatteryList.end(); it++) {
701             if (id == (*it)->getId()) {
702                 event = *it;
703                 break;
704             }
705         }
706         if (!event) {
707             LoggerE("event id not in the list, nothing to do");
708             return;
709         }
710
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()) {
717                 event = *it;
718                 break;
719             }
720         }
721         if (!event) {
722             LoggerE("event id not in the list, nothing to do");
723             return;
724         }
725
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()) {
732             event = *it;
733             break;
734         }
735     }
736     if (!event) {
737         LoggerE("event id not in the list, nothing to do");
738         return;
739     }
740
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()) {
747                 event = *it;
748                 break;
749             }
750         }
751         if (!event) {
752             LoggerE("event id not in the list, nothing to do");
753             return;
754         }
755
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()) {
762                 event = *it;
763                 break;
764             }
765         }
766         if (!event) {
767             LoggerE("event id not in the list, nothing to do");
768             return;
769         }
770
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()) {
777                 event = *it;
778                 break;
779             }
780         }
781         if (!event) {
782             LoggerE("event id not in the list, nothing to do");
783             return;
784         }
785
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()) {
792                 event = *it;
793                 break;
794             }
795         }
796         if (!event) {
797             LoggerE("event id not in the list, nothing to do");
798             return;
799         }
800
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()) {
807                 event = *it;
808                 break;
809             }
810         }
811         if (!event) {
812             LoggerE("event id not in the list, nothing to do");
813             return;
814         }
815
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()) {
822                 event = *it;
823                 break;
824             }
825         }
826         if (!event) {
827             LoggerE("event id not in the list, nothing to do");
828             return;
829         }
830
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()) {
837                 event = *it;
838                 break;
839             }
840         }
841         if (!event) {
842             LoggerE("event id not in the list, nothing to do");
843             return;
844         }
845
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()) {
852                 event = *it;
853                 break;
854             }
855         }
856         if (!event) {
857             LoggerE("event id not in the list, nothing to do");
858             return;
859         }
860
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());
864     }
865 }
866
867 const int Systeminfo::EventMgr::getWatchType(const long id)
868 {
869     DPL::Mutex::ScopedLock lock(&m_synchro);
870
871     EventWatchSysteminfoPtr event(NULL);
872
873     for (EventBatteryList::iterator it = m_eventBatteryList.begin(); it != m_eventBatteryList.end(); it++) {
874         if (id == (*it)->getId()) {
875             event = *it;
876             break;
877         }
878     }
879
880     for (EventDisplayList::iterator it = m_eventDisplayList.begin(); it != m_eventDisplayList.end(); it++) {
881         if (id == (*it)->getId()) {
882             event = *it;
883             break;
884         }
885     }
886
887     for (EventWifiNetworkList::iterator it = m_eventWifiNetworkList.begin(); it != m_eventWifiNetworkList.end(); it++) {
888         if (id == (*it)->getId()) {
889             event = *it;
890             break;
891         }
892     }
893
894     for (EventCellularNetworkList::iterator it = m_eventCelluarNetworkList.begin(); it != m_eventCelluarNetworkList.end(); it++) {
895         if (id == (*it)->getId()) {
896             event = *it;
897             break;
898         }
899     }
900
901     for (EventStorageList::iterator it = m_eventStorageList.begin(); it != m_eventStorageList.end(); it++) {
902         if (id == (*it)->getId()) {
903             event = *it;
904             break;
905         }
906     }
907
908     for (EventCpuList::iterator it = m_eventCpuList.begin(); it != m_eventCpuList.end(); it++) {
909         if (id == (*it)->getId()) {
910             event = *it;
911             break;
912         }
913     }
914
915     for (EventSimList::iterator it = m_eventSimList.begin(); it != m_eventSimList.end(); it++) {
916         if (id == (*it)->getId()) {
917             event = *it;
918             break;
919         }
920     }
921
922     for (EventDeviceOrientationList::iterator it = m_eventDeviceOrientationList.begin(); it != m_eventDeviceOrientationList.end(); it++) {
923         if (id == (*it)->getId()) {
924             event = *it;
925             break;
926         }
927     }
928
929     for (EventNetworkList::iterator it = m_eventNetworkList.begin(); it != m_eventNetworkList.end(); it++) {
930         if (id == (*it)->getId()) {
931             event = *it;
932             break;
933         }
934     }
935
936     for (EventSimList::iterator it = m_eventSimList.begin(); it != m_eventSimList.end(); it++) {
937         if (id == (*it)->getId()) {
938             event = *it;
939             break;
940         }
941     }
942
943     for (EventLocaleList::iterator it = m_eventLocaleList.begin(); it != m_eventLocaleList.end(); it++) {
944         if (id == (*it)->getId()) {
945             event = *it;
946             break;
947         }
948     }
949
950     for (EventPeripheralList::iterator it = m_eventPeripheralList.begin(); it != m_eventPeripheralList.end(); it++) {
951         if (id == (*it)->getId()) {
952             event = *it;
953             break;
954         }
955     }
956
957     if (!event) {
958         LoggerE("event id not in the list, nothing to do");
959         return WATCH_TYPE_UNKNOWN;
960     }
961
962     return event->getWatchType();
963 }
964
965 EventBatteryList Systeminfo::EventMgr::getEventBatteryList()
966 {
967     return m_eventBatteryList;
968 }
969
970 EventDisplayList Systeminfo::EventMgr::getEventDisplayList()
971 {
972     return m_eventDisplayList;
973 }
974
975 EventNetworkList Systeminfo::EventMgr::getEventNetworkList()
976 {
977     return m_eventNetworkList;
978 }
979
980 EventWifiNetworkList Systeminfo::EventMgr::getEventWifiNetworkList()
981 {
982     return m_eventWifiNetworkList;
983 }
984
985 EventCellularNetworkList Systeminfo::EventMgr::getEventCellularNetworkList()
986 {
987     return m_eventCelluarNetworkList;
988 }
989
990 EventStorageList Systeminfo::EventMgr::getEventStorageList()
991 {
992     return m_eventStorageList;
993 }
994
995 EventCpuList Systeminfo::EventMgr::getEventCpuList()
996 {
997     return m_eventCpuList;
998 }
999
1000 EventDeviceOrientationList Systeminfo::EventMgr::getEventDeviceOrientationList()
1001 {
1002     return m_eventDeviceOrientationList;
1003 }
1004
1005 EventSimList Systeminfo::EventMgr::getEventSimList()
1006 {
1007     return m_eventSimList;
1008 }
1009
1010 EventLocaleList Systeminfo::EventMgr::getEventLocaleList()
1011 {
1012     return m_eventLocaleList;
1013 }
1014
1015 EventPeripheralList Systeminfo::EventMgr::getEventPeripheralList()
1016 {
1017     return m_eventPeripheralList;
1018 }
1019
1020 ////////////////////////////////////////////////////////////////////////////////////////
1021
1022 PROPERTY_GET_SYSTEMINFO_DEFINITION(Battery) {
1023     BatteryPropertiesPtr BatteryPtr(new BatteryProperties());
1024     int value=0;
1025     int value2=0;
1026
1027     if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, &value) != 0) {
1028         return JSValueMakeNull(context);
1029     } else {
1030         BatteryPtr->level = (double)(value)/CPU_POWER_DEVICE_VALUE;
1031     }
1032
1033     if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &value2) != 0) {
1034         return JSValueMakeNull(context);
1035     } else {
1036         BatteryPtr->isCharging = (value2 == 0) ? false : true;
1037     }
1038
1039     return JSBatteryInfo::createJSObject(context, BatteryPtr);
1040 }
1041
1042 PROPERTY_GET_SYSTEMINFO_DEFINITION(Cpu) {
1043     Converter converter(context);
1044
1045     CpuPropertiesPtr cpuPtr(new CpuProperties());
1046     FILE *fp = NULL;
1047     long long usr = 0, nice = 0, system = 0, idle = 0, total = 0, cpuUsage = 0;
1048
1049     fp = fopen("/proc/stat", "r");
1050     if(fp == NULL) {
1051         return JSValueMakeNull(context);
1052     }
1053     
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);
1060         }
1061     }
1062
1063     fclose(fp);
1064     return JSCpuInfo::createJSObject(context, cpuPtr);
1065 }
1066
1067 PROPERTY_GET_SYSTEMINFO_DEFINITION(Storage) {
1068     Converter converter(context);
1069     int sdcardState=0;
1070     struct statfs fs;
1071     
1072     if (statfs(STORAGE_INTERNAL_PATH, &fs) < 0) {
1073         // make exception
1074         return JSValueMakeNull(context);
1075     }
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);
1088             }
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);            
1096         }
1097     }
1098     return JSStorageInfo::createJSObject(context, storagePtr);  
1099
1100 }
1101
1102 PROPERTY_GET_SYSTEMINFO_DEFINITION(Display) {
1103     Converter converter(context);
1104
1105     DisplayPropertiesPtr display(new DisplayProperties());
1106     int brightness=0, dotsPerInchX=0, dotsPerInchY=0, physicalW=0, physicalH=0, resolutionW=0, resolutionH=0;
1107
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);
1111     }
1112
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);
1116     }
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);
1120     }
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);
1124     }
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);
1128     }
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);
1132     }
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);
1136     }
1137
1138     return JSDisplayInfo::createJSObject(context, display);
1139 }
1140
1141 PROPERTY_GET_SYSTEMINFO_DEFINITION(Network) {
1142     LoggerD("enter");
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;
1148
1149     if (connection_get_type(connectionHandle, &connectionType) != CONNECTION_ERROR_NONE) {
1150         LoggerD("get connection type is failed");
1151         return JSNetworkInfo::createJSObject(context, Network);
1152     }
1153
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";
1169             } else {
1170                 Network->networkType= "NONE";
1171             }
1172         }
1173     } else {
1174         Network->networkType= "NONE";
1175     }
1176
1177     return JSNetworkInfo::createJSObject(context, Network);
1178 }
1179
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;
1188     char* essid = NULL;
1189     int rssi = 0;
1190
1191     if (connection_get_type(connectionHandle, &connectionType) != CONNECTION_ERROR_NONE) {
1192         return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1193     }
1194
1195     if (connectionType == CONNECTION_TYPE_WIFI) {
1196         wifiNetwork->status = "ON";
1197     } else {
1198         wifiNetwork->status = "OFF";
1199         return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1200     }
1201
1202     if (connection_get_current_profile(connectionHandle, &profileHandle) != CONNECTION_ERROR_NONE) {
1203         return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1204     }
1205
1206     if (connection_profile_get_wifi_essid(profileHandle, &essid) == CONNECTION_ERROR_NONE) {
1207         wifiNetwork->ssid = essid;
1208         free(essid);
1209     }
1210
1211     if (connection_profile_get_ip_address(profileHandle, addressFamily, &ipAddr) == CONNECTION_ERROR_NONE) {
1212         wifiNetwork->ipAddress = ipAddr;
1213         free(ipAddr);
1214     }
1215
1216     if (connection_profile_get_wifi_rssi(profileHandle, &rssi) == CONNECTION_ERROR_NONE) {
1217         wifiNetwork->signalStrength = (double) rssi/WIFI_SIGNAL_STRENGTH_DIVIDE_VALUE;
1218     }
1219
1220     return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1221 }
1222
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;
1231     char* apn = NULL;
1232     char* imei = NULL;
1233     int plmn = 0, cellId = 0, lac = 0, isRoaming = 0, isFlightMode = 0;
1234     TapiHandle *tapiHandle = NULL;    
1235
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;
1240     }
1241     TIME_TRACER_ITEM_END("(cellular)mcc", 0);
1242
1243     TIME_TRACER_ITEM_BEGIN("(cellular)cellId", 0);
1244     if (vconf_get_int(VCONFKEY_TELEPHONY_CELLID, &cellId) == 0) {
1245         cellularNetwork->cellId = cellId;
1246     }
1247     TIME_TRACER_ITEM_END("(cellular)cellId", 0);
1248
1249     TIME_TRACER_ITEM_BEGIN("(cellular)lac", 0);
1250     if (vconf_get_int(VCONFKEY_TELEPHONY_LAC, &lac) == 0) {
1251         cellularNetwork->lac = lac;
1252     }
1253     TIME_TRACER_ITEM_END("(cellular)lac", 0);
1254
1255     TIME_TRACER_ITEM_BEGIN("(cellular)isRoaming", 0);
1256     if (vconf_get_int(VCONFKEY_TELEPHONY_SVC_ROAM, &isRoaming) == 0) {
1257         if (isRoaming) {
1258             cellularNetwork->isRoaming = true;
1259         } else {
1260             cellularNetwork->isRoaming = false;
1261         }
1262     }
1263     TIME_TRACER_ITEM_END("(cellular)isRoaming", 0);
1264
1265         TIME_TRACER_ITEM_BEGIN("(cellular)isFlightMode", 0);
1266     if (vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &isFlightMode) == 0) {
1267         if (isFlightMode) {
1268             cellularNetwork->isFlightMode = true;
1269         } else {
1270             cellularNetwork->isFlightMode = false;
1271         }
1272     }
1273         TIME_TRACER_ITEM_END("(cellular)isFlightMode", 0);
1274
1275     if (connection_get_type(connectionHandle, &connectionType) != CONNECTION_ERROR_NONE) {
1276         return JSCellularNetworkInfo::createJSObject(context, cellularNetwork);
1277     }
1278
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;
1285                 free(apn);
1286             }
1287                         TIME_TRACER_ITEM_END("(cellular)apn", 0);
1288
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;
1292                 free(ipAddr);
1293             }
1294                         TIME_TRACER_ITEM_END("(cellular)ipAddress", 0);
1295             connection_profile_destroy(profileHandle);
1296         }
1297     } else {
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;
1303                 free(apn);
1304             }
1305                         TIME_TRACER_ITEM_END("(cellular)apn", 0);
1306             connection_profile_destroy(profileHandle);
1307         }
1308     }
1309   
1310     tapiHandle = tel_init(0);
1311     
1312     if (tapiHandle != NULL) {
1313         imei = tel_get_misc_me_imei_sync(tapiHandle);
1314         
1315         if (imei == NULL) {
1316             tel_deinit(tapiHandle);
1317             return JSCellularNetworkInfo::createJSObject(context, cellularNetwork);
1318         }
1319         
1320         cellularNetwork->imei = imei;
1321         free(imei);
1322         tel_deinit(tapiHandle);
1323     }
1324
1325     return JSCellularNetworkInfo::createJSObject(context, cellularNetwork);
1326 }
1327
1328 PROPERTY_GET_SYSTEMINFO_DEFINITION(SIM) {
1329     Converter converter(context);
1330     SIMPropertiesPtr SIM(new SIMProperties());
1331
1332     sim_state_e state;
1333     char* fullName = NULL;
1334     char* shortName = NULL;
1335     char* msisdn = NULL;
1336     char* iccId = NULL;
1337     char* mcc = NULL;
1338     char* mnc = NULL;
1339     char* msin = NULL;
1340     char* spn = NULL;
1341     int ret = SIM_ERROR_NONE;    
1342
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";
1353         }
1354     }
1355
1356     ret = sim_get_cphs_operator_name(&fullName, &shortName);
1357     if (ret == SIM_ERROR_NONE) {
1358         if (fullName) {
1359             SIM->operatorName = fullName;
1360             LoggerD("operatorName : " << SIM->operatorName);
1361             free(fullName);
1362         } else if (shortName) {
1363             SIM->operatorName = shortName;
1364             LoggerD("operatorName : " << SIM->operatorName);
1365             free(shortName);
1366         }
1367     }
1368
1369
1370     ret = sim_get_subscriber_number(&msisdn);
1371     if (ret == SIM_ERROR_NONE) {
1372         if (msisdn) {
1373             SIM->msisdn = msisdn;
1374             LoggerD("msisdn : " << SIM->msisdn);
1375             free(msisdn);
1376         }
1377     }
1378
1379     ret = sim_get_icc_id(&iccId);
1380     if (ret == SIM_ERROR_NONE) {
1381         if (iccId) {
1382             SIM->iccid = iccId;
1383             LoggerD("iccid : " << SIM->iccid);
1384             free(iccId);
1385         }
1386     }
1387
1388     ret = sim_get_mcc(&mcc);
1389     if (ret == SIM_ERROR_NONE) {
1390         if (mcc) {
1391             SIM->mcc = atoi(mcc);
1392             LoggerD("mcc : " << SIM->mcc);
1393             free(mcc);
1394         }
1395     }
1396
1397     ret = sim_get_mnc(&mnc);
1398     if (ret == SIM_ERROR_NONE) {
1399         if (mnc) {
1400             SIM->mnc = atoi(mnc);
1401             LoggerD("mnc : " << SIM->mnc);
1402             free(mnc);
1403         }
1404     }
1405
1406     ret = sim_get_msin(&msin);
1407     if (ret == SIM_ERROR_NONE) {
1408         if (msin) {
1409             SIM->msin = msin;
1410             LoggerD("msin : " << SIM->msin);
1411             free(msin);
1412         }
1413     }
1414
1415     ret = sim_get_spn(&spn);
1416     if (ret == SIM_ERROR_NONE) {
1417         if (spn) {
1418             SIM->spn = spn;
1419             LoggerD("spn : " << SIM->spn);
1420             free(spn);
1421         }
1422     }
1423
1424     return JSSIMInfo::createJSObject(context, SIM);
1425 }
1426
1427 PROPERTY_GET_SYSTEMINFO_DEFINITION(DeviceOrientation) {
1428     LoggerD("enter");
1429     Converter converter(context);
1430     DeviceOrientationPropertiesPtr deviceOrientation(new DeviceOrientationProperties());
1431
1432     unsigned long rotation = 0;
1433     int handleOrientaion = 0;
1434     int isAutoRotation = 0;
1435
1436     if (vconf_get_bool(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &isAutoRotation) == 0) {
1437         if (isAutoRotation) {
1438             deviceOrientation->isAutoRotation = true;
1439         } else {
1440             deviceOrientation->isAutoRotation = false;
1441         }
1442     }
1443
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);
1449     }
1450     int state = sf_start(handleOrientaion, 0);
1451     if(state < 0) {
1452         LoggerD("start failed");
1453     }
1454
1455     int ret_val = sf_check_rotation(&rotation);
1456     if (ret_val < 0) {
1457         LoggerD("sf_check_rotation fail to gather data\n");
1458     }
1459
1460     LoggerD(" rotation value = " << rotation);
1461
1462     switch (rotation) {
1463         case 0:
1464         case ROTATION_EVENT_0:
1465             LoggerD("my_callback_func received data (PORTRAIT_TOP|HEAD_CENTER)\n");
1466             deviceOrientation->status = "PORTRAIT_PRIMARY";
1467             break;
1468         case ROTATION_EVENT_90:
1469             LoggerD("my_callback_func received data (LANDSCAPE|HEAD_RIGHT)\n");
1470             deviceOrientation->status = "LANDSCAPE_PRIMARY";
1471             break;
1472         case ROTATION_EVENT_180:
1473             LoggerD("my_callback_func received data (PORTRAIT_BTM|HEAD_CENTER)\n");
1474             deviceOrientation->status = "PORTRAIT_SECONDARY";
1475             break;
1476         case ROTATION_EVENT_270:
1477             LoggerD("my_callback_func received data (LANDSCAPE|HEAD_LEFT)\n");
1478             deviceOrientation->status = "LANDSCAPE_SECONDARY";
1479             break;
1480         default:
1481             LoggerD(" received data unexpected\n");
1482             break;
1483     }
1484
1485         state = sf_stop(handleOrientaion);
1486         LoggerD("handleOrientaion 1  state = " << state);
1487
1488         state = sf_disconnect(handleOrientaion);
1489         LoggerD("handleOrientaion  state =" << state);
1490
1491     return JSDeviceOrientationInfo::createJSObject(context, deviceOrientation);
1492 }
1493
1494 PROPERTY_GET_SYSTEMINFO_DEFINITION(Build) {
1495     LoggerD("enter");
1496     Converter converter(context);
1497     BuildPropertiesPtr Build(new BuildProperties());
1498
1499     char* model = NULL;
1500     char* manufacturer = NULL;
1501     char* buildVersion = NULL;
1502
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;
1507             free(model);
1508         }
1509     }
1510
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;
1515             free(manufacturer);
1516         }
1517     }
1518
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;
1523             free(buildVersion);
1524         }
1525     }
1526
1527     return JSBuildInfo::createJSObject(context, Build);
1528 }
1529
1530 PROPERTY_GET_SYSTEMINFO_DEFINITION(Locale) {
1531     LoggerD("enter");
1532     Converter converter(context);
1533     LocalePropertiesPtr Locale(new LocaleProperties());
1534
1535     char* country = NULL;
1536     char* language = NULL;
1537
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;
1542             free(language);
1543         }
1544     }
1545
1546     if (runtime_info_get_value_string(RUNTIME_INFO_KEY_REGION, &country) == RUNTIME_INFO_ERROR_NONE) {
1547         if (country != NULL) {
1548             LoggerD("country : " << country);
1549             char* token = NULL;
1550             char* countryTemp = NULL;
1551             token = strtok(country, ".");
1552             if (token != NULL) {
1553                 countryTemp = strdup(token);
1554                 if (countryTemp != NULL) {
1555                     Locale->country = countryTemp;
1556                     free(countryTemp);
1557                 }
1558             }            
1559             free(country);            
1560         }
1561     }
1562
1563     return JSLocaleInfo::createJSObject(context, Locale);
1564 }
1565
1566 PROPERTY_GET_SYSTEMINFO_DEFINITION(Peripheral) {
1567     Converter converter(context);
1568     PeripheralPropertiesPtr peripheral(new PeripheralProperties());
1569     int hdmiStatus = 0, wirelessDisplayStatus = 0 ;
1570
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;
1575                 break;
1576             default:
1577                 LoggerD("VideOutput status is off");
1578                 break;
1579         }
1580     }
1581
1582     if (vconf_get_int(VCONFKEY_SYSMAN_HDMI, &hdmiStatus) == 0) {
1583         switch(hdmiStatus) {
1584             case VCONFKEY_SYSMAN_HDMI_CONNECTED:
1585                 peripheral->isVideoOutputOn = true;
1586                 break;
1587             default:
1588                 LoggerD("VideOutput status is off");
1589                 break;
1590         }
1591     }
1592
1593     return JSPeripheralInfo::createJSObject(context, peripheral);
1594 }
1595
1596 }
1597 }