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.
22 #include <dpl/log/log.h>
24 #include <Commons/Exception.h>
25 #include <CommonsJavaScript/Converter.h>
26 #include <CommonsJavaScript/PrivateObject.h>
27 #include "Systeminfo.h"
29 using namespace WrtDeviceApis::CommonsJavaScript;
30 using namespace WrtDeviceApis::Commons;
34 namespace Systeminfo {
38 void BatteryValueCallback(keynode_t *node, void *event_ptr)
41 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_BATTERY);
45 void PeripheralValueCallback(keynode_t *node, void *event_ptr)
48 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_PERIPHERAL);
52 void DisplayValueCallback(keynode_t *node, void* event_ptr)
55 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_DISPLAY);
59 void NetworkTypeValueCallback(connection_type_e type, void* event_ptr)
62 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_NETWORK);
66 void NetworkValueCallback(const char* ipv4_address, const char* ipv6_address, void* event_ptr)
69 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_NETWORK_ALL);
73 static Eina_Bool StorageValueCallback(void* event_ptr)
76 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_STORAGE);
78 return ECORE_CALLBACK_RENEW;
81 static Eina_Bool CpuValueCallback(void* event_ptr)
84 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_CPU);
86 return ECORE_CALLBACK_RENEW;
89 void OrientationValueCallback(unsigned int event_type, sensor_event_data_t *event , void *event_ptr)
93 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_DEVICE_ORIENTATION);
97 void localeChangedCallback(runtime_info_key_e key, void* event_ptr)
101 ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_LOCALE);
107 #define STORAGE_INTERNAL_PATH "/opt/usr/media"
108 #define STORAGE_SDCARD_PATH "/opt/storage/sdcard"
109 #define STORAGE_USBHOST_PATH "/opt/storage/usb"
110 #define DISPLAY_BRIGHTNESS_DIVIDE_VALUE 100
111 #define WIFI_SIGNAL_STRENGTH_DIVIDE_VALUE 100
112 #define CPU_POWER_DEVICE_VALUE 100
114 #define RADIAN_VALUE (57.2957)
117 STORAGE_TYPE_UNKNOWN = 0,
118 STORAGE_TYPE_INTERNAL = 1,
119 STORAGE_TYPE_MMC = 2,
120 STORAGE_TYPE_USBHOST = 3
123 Systeminfo::OptionalProperty Systeminfo::m_Property;
125 Systeminfo::Systeminfo() : m_networkRegist(REGIST_NOT),
126 m_storageTimer(NULL),
129 m_connectionHandle(NULL)
131 EventMgrPtr eventMgrPtr(new EventMgr());
132 m_EventMgrPtr = eventMgrPtr;
133 if (m_Property.IsNull()) {
134 mapProperties properties;
135 properties["BATTERY"] = BasePropertyPtr(new Battery());
136 m_Property = properties;
137 (*m_Property)["CPU"] = BasePropertyPtr(new Cpu());
138 (*m_Property)["STORAGE"] = BasePropertyPtr(new Storage());
139 (*m_Property)["DISPLAY"] = BasePropertyPtr(new Display());
140 (*m_Property)["NETWORK"] = BasePropertyPtr(new Network());
141 (*m_Property)["WIFI_NETWORK"] = BasePropertyPtr(new WifiNetwork());
142 (*m_Property)["CELLULAR_NETWORK"] = BasePropertyPtr(new CellularNetwork());
143 (*m_Property)["SIM"] = BasePropertyPtr(new SIM());
144 (*m_Property)["DEVICE_ORIENTATION"] = BasePropertyPtr(new DeviceOrientation());
145 (*m_Property)["BUILD"] = BasePropertyPtr(new Build());
146 (*m_Property)["LOCALE"] = BasePropertyPtr(new Locale());
147 (*m_Property)["PERIPHERAL"] = BasePropertyPtr(new Peripheral());
150 int ret = connection_create(&m_connectionHandle);
152 if (CONNECTION_ERROR_NONE == ret) {
153 LogDebug("Network Client registration success");
155 LogDebug("Network Client registration success");
156 m_connectionHandle = NULL;
159 m_sensorHandle = sf_connect(ACCELEROMETER_SENSOR);
160 if (m_sensorHandle < 0) {
161 LogDebug ("sensor attach fail");
163 LogDebug("m_sensorHandle : " << m_sensorHandle);
164 int state = sf_start(m_sensorHandle, 0);
171 Systeminfo::~Systeminfo()
174 if (m_storageTimer) {
175 ecore_timer_freeze(m_storageTimer);
176 ecore_timer_del(m_storageTimer);
177 m_storageTimer = NULL;
180 ecore_timer_freeze(m_cpuTimer);
181 ecore_timer_del(m_cpuTimer);
184 m_EventMgrPtr->clearAllEvent();
186 if(m_connectionHandle != NULL) {
187 LogDebug("Network Client deregistration success");
188 connection_destroy(m_connectionHandle);
190 LogDebug("Network Client deregistration failed");
193 state = sf_stop(m_sensorHandle);
194 LogDebug("handle 1 state = " << state);
196 state = sf_disconnect(m_sensorHandle);
197 LogDebug("handle state =" << state);
200 DeviceCapabilitiesPropertiesPtr Systeminfo::getCapabilities()
203 DeviceCapabilitiesPropertiesPtr deviceCapabilities(new DeviceCapabilitiesProperties());
204 bool bluetooth = false, nfc = false, wifi = false, wifiDirect = false, fmRadio = false, cameraFront = false,
205 cameraFrontFlash = false, cameraBack = false, cameraBackFlash = false, isAccelerometer = false, isGyroscope = false,
206 isMagnetometer = false, isProximity = false, location = false, locationGps = false, locationWps = false,
207 microphone = false, usbHost = false, usbAccessory = false, screenOutputRca = false, screenOutputHdmi = false,
208 sipVoip = false, speechRecognition = false, isBarometer = false;
209 int multiTouchCount = 0;
210 char* inputKeyboard = NULL;
211 char* platformVersion = NULL;
212 char* platformName = NULL;
213 char* platformCoreCpuArch = NULL;
214 char* platformCoreFpuArch = NULL;
216 char* openglesVersion = NULL;
218 if (system_info_get_value_bool(SYSTEM_INFO_KEY_BLUETOOTH_SUPPORTED, &bluetooth) == SYSTEM_INFO_ERROR_NONE) {
219 LogDebug("bluetooth : " << bluetooth);
220 deviceCapabilities->bluetooth = bluetooth;
223 if (system_info_get_value_bool(SYSTEM_INFO_KEY_NFC_SUPPORTED, &nfc) == SYSTEM_INFO_ERROR_NONE) {
224 LogDebug("nfc : " << nfc);
225 deviceCapabilities->nfc = nfc;
227 if (system_info_get_value_int(SYSTEM_INFO_KEY_MULTI_POINT_TOUCH_COUNT, &multiTouchCount) == SYSTEM_INFO_ERROR_NONE) {
228 LogDebug("multiTouchCount : " << multiTouchCount);
229 deviceCapabilities->multiTouchCount = multiTouchCount;
232 if (system_info_get_value_string(SYSTEM_INFO_KEY_KEYBOARD_TYPE, &inputKeyboard) == SYSTEM_INFO_ERROR_NONE) {
233 if (inputKeyboard != NULL) {
234 LogDebug("inputKeyboard : " << inputKeyboard);
235 deviceCapabilities->inputKeyboard = inputKeyboard;
240 if (system_info_get_value_bool(SYSTEM_INFO_KEY_WIFI_SUPPORTED, &wifi) == SYSTEM_INFO_ERROR_NONE) {
241 LogDebug("wifi : " << wifi);
242 deviceCapabilities->wifi = wifi;
245 if (system_info_get_value_bool(SYSTEM_INFO_KEY_WIFI_DIRECT_SUPPORTED, &wifiDirect) == SYSTEM_INFO_ERROR_NONE) {
246 LogDebug("wifiDirect : " << wifiDirect);
247 deviceCapabilities->wifiDirect = wifiDirect;
250 if (system_info_get_value_string(SYSTEM_INFO_KEY_OPENGLES_VERSION, &openglesVersion) == SYSTEM_INFO_ERROR_NONE) {
251 if (openglesVersion!= NULL) {
252 LogDebug("openglesVersion : " << openglesVersion);
253 if (strcmp(openglesVersion, "1.0") == 0) {
254 deviceCapabilities->openglesVersion1_1 = true;
255 deviceCapabilities->openglesVersion2_0 = false;
256 } else if (strcmp(openglesVersion, "2.0") == 0) {
257 deviceCapabilities->openglesVersion1_1 = false;
258 deviceCapabilities->openglesVersion2_0 = true;
259 } else if (strcmp(openglesVersion, "1.0/2.0") == 0) {
260 deviceCapabilities->openglesVersion1_1 = true;
261 deviceCapabilities->openglesVersion2_0 = true;
263 free(openglesVersion);
267 if (system_info_get_value_bool(SYSTEM_INFO_KEY_FMRADIO_SUPPORTED, &fmRadio) == SYSTEM_INFO_ERROR_NONE) {
268 LogDebug("fmRadio : " << fmRadio);
269 deviceCapabilities->fmRadio = fmRadio;
272 if (system_info_get_value_string(SYSTEM_INFO_KEY_TIZEN_VERSION, &platformVersion) == SYSTEM_INFO_ERROR_NONE) {
273 if (platformVersion) {
274 LogDebug("platformVersion : " << platformVersion);
275 deviceCapabilities->platformVersion = platformVersion;
276 free(platformVersion);
280 if (system_info_get_value_string(SYSTEM_INFO_KEY_PLATFORM_NAME, &platformName) == SYSTEM_INFO_ERROR_NONE) {
282 LogDebug("platformName : " << platformName);
283 deviceCapabilities->platformName = platformName;
288 if (system_info_get_value_bool(SYSTEM_INFO_KEY_FRONT_CAMERA_SUPPORTED, &cameraFront) == SYSTEM_INFO_ERROR_NONE) {
289 LogDebug("cameraFront : " << cameraFront);
290 deviceCapabilities->cameraFront = cameraFront;
293 if (system_info_get_value_bool(SYSTEM_INFO_KEY_FRONT_CAMERA_FLASH_SUPPORTED, &cameraFrontFlash) == SYSTEM_INFO_ERROR_NONE) {
294 LogDebug("cameraFrontFlash : " << cameraFrontFlash);
295 deviceCapabilities->cameraFrontFlash = cameraFrontFlash;
298 if (system_info_get_value_bool(SYSTEM_INFO_KEY_BACK_CAMERA_SUPPORTED, &cameraBack) == SYSTEM_INFO_ERROR_NONE) {
299 LogDebug("cameraBack : " << cameraBack);
300 deviceCapabilities->cameraBack = cameraBack;
303 if (system_info_get_value_bool(SYSTEM_INFO_KEY_BACK_CAMERA_FLASH_SUPPORTED, &cameraBackFlash) == SYSTEM_INFO_ERROR_NONE) {
304 LogDebug("cameraBackFlash : " << cameraBackFlash);
305 deviceCapabilities->cameraBackFlash = cameraBackFlash;
308 if (system_info_get_value_bool(SYSTEM_INFO_KEY_CPS_SUPPORTED, &location) == SYSTEM_INFO_ERROR_NONE) {
309 LogDebug("location : " << location);
310 deviceCapabilities->location = location;
313 if (system_info_get_value_bool(SYSTEM_INFO_KEY_GPS_SUPPORTED, &locationGps) == SYSTEM_INFO_ERROR_NONE) {
314 LogDebug("locationGps : " << locationGps);
315 deviceCapabilities->locationGps = locationGps;
318 if (system_info_get_value_bool(SYSTEM_INFO_KEY_WPS_SUPPORTED, &locationWps) == SYSTEM_INFO_ERROR_NONE) {
319 LogDebug("locationWps : " << locationWps);
320 deviceCapabilities->locationWps = locationWps;
323 if (system_info_get_value_bool(SYSTEM_INFO_KEY_MICROPHONE_SUPPORTED, µphone) == SYSTEM_INFO_ERROR_NONE) {
324 LogDebug("microphone : " << microphone);
325 deviceCapabilities->microphone = microphone;
328 if (system_info_get_value_bool(SYSTEM_INFO_KEY_USB_HOST_SUPPORTED, &usbHost) == SYSTEM_INFO_ERROR_NONE) {
329 LogDebug("usbHost : " << usbHost);
330 deviceCapabilities->usbHost = usbHost;
333 if (system_info_get_value_bool(SYSTEM_INFO_KEY_USB_ACCESSORY_SUPPORTED, &usbAccessory) == SYSTEM_INFO_ERROR_NONE) {
334 LogDebug("usbAccessory : " << usbAccessory);
335 deviceCapabilities->usbAccessory = usbAccessory;
338 if (system_info_get_value_bool(SYSTEM_INFO_KEY_RCA_SUPPORTED, &screenOutputRca) == SYSTEM_INFO_ERROR_NONE) {
339 LogDebug("screenOutputRca : " << screenOutputRca);
340 deviceCapabilities->screenOutputRca = screenOutputRca;
343 if (system_info_get_value_bool(SYSTEM_INFO_KEY_HDMI_SUPPORTED, &screenOutputHdmi) == SYSTEM_INFO_ERROR_NONE) {
344 LogDebug("screenOutputHdmi : " << screenOutputHdmi);
345 deviceCapabilities->screenOutputHdmi = screenOutputHdmi;
348 if (system_info_get_value_string(SYSTEM_INFO_KEY_CORE_CPU_ARCH, &platformCoreCpuArch) == SYSTEM_INFO_ERROR_NONE) {
349 if (platformCoreCpuArch) {
350 LogDebug("platformCoreCpuArch : " << platformCoreCpuArch);
351 deviceCapabilities->platformCoreCpuArch = platformCoreCpuArch;
352 free(platformCoreCpuArch);
356 if (system_info_get_value_string(SYSTEM_INFO_KEY_CORE_FPU_ARCH, &platformCoreFpuArch) == SYSTEM_INFO_ERROR_NONE) {
357 if (platformCoreFpuArch) {
358 LogDebug("platformCoreFpuArch : " << platformCoreFpuArch);
359 deviceCapabilities->platformCoreFpuArch = platformCoreFpuArch;
360 free(platformCoreFpuArch);
364 if (system_info_get_value_bool(SYSTEM_INFO_KEY_SIP_VOIP_SUPPORTED, &sipVoip) == SYSTEM_INFO_ERROR_NONE) {
365 LogDebug("sipVoip : " << sipVoip);
366 deviceCapabilities->sipVoip = sipVoip;
369 if (system_info_get_value_string(SYSTEM_INFO_KEY_DEVICE_UUID, &duid) == SYSTEM_INFO_ERROR_NONE) {
371 LogDebug("duid : " << duid);
372 deviceCapabilities->duid = duid;
377 if (system_info_get_value_bool(SYSTEM_INFO_KEY_SPEECH_RECOGNITION_SUPPORTED, &speechRecognition) == SYSTEM_INFO_ERROR_NONE) {
378 LogDebug("speechRecognition : " << speechRecognition);
379 deviceCapabilities->speechRecognition = speechRecognition;
382 if (system_info_get_value_bool(SYSTEM_INFO_KEY_BAROMETER_SENSOR_SUPPORTED, &isBarometer) == SYSTEM_INFO_ERROR_NONE) {
383 LogDebug("barometer : " << isBarometer);
384 deviceCapabilities->barometer = isBarometer;
387 if (sensor_is_supported(SENSOR_ACCELEROMETER, &isAccelerometer) == SENSOR_ERROR_NONE) {
388 LogDebug("accelerometer : " << isAccelerometer);
389 deviceCapabilities->accelerometer = isAccelerometer;
392 if (sensor_is_supported(SENSOR_MAGNETIC, &isMagnetometer) == SENSOR_ERROR_NONE) {
393 LogDebug("magnetometer : " << isMagnetometer);
394 deviceCapabilities->magnetometer = isMagnetometer;
397 if (sensor_is_supported(SENSOR_GYROSCOPE, &isGyroscope) == SENSOR_ERROR_NONE) {
398 LogDebug("gyroscope : " << isGyroscope);
399 deviceCapabilities->gyroscope = isGyroscope;
402 if (sensor_is_supported(SENSOR_PROXIMITY, &isProximity) == SENSOR_ERROR_NONE) {
403 LogDebug("proximity : " << isProximity);
404 deviceCapabilities->proximity = isProximity;
407 std::ifstream file("/usr/etc/system-info.ini");
409 std::string webApiVersionMajor = "";
410 std::string webApiVersionMinor = "";
411 std::string nativeApiVersionMajor = "";
412 std::string nativeApiVersionMinor = "";
415 LogDebug("api/native version info file not found");
417 while ((std::getline(file, line).rdstate() & (std::ifstream::failbit | std::ifstream::eofbit)) == 0) {
418 if (pcrecpp::RE("platform.native.api.version=(\\w+).(\\w+)").PartialMatch(line, &nativeApiVersionMajor, &nativeApiVersionMinor )) {
419 deviceCapabilities->nativeApiVersion = nativeApiVersionMajor;
420 deviceCapabilities->nativeApiVersion += ".";
421 deviceCapabilities->nativeApiVersion += nativeApiVersionMinor;
422 LogDebug("native api version : " << deviceCapabilities->nativeApiVersion);
426 while ((std::getline(file, line).rdstate() & (std::ifstream::failbit | std::ifstream::eofbit)) == 0) {
427 if (pcrecpp::RE("platform.web.api.version=(\\w+).(\\w+)").PartialMatch(line, &webApiVersionMajor, &webApiVersionMinor)) {
428 deviceCapabilities->webApiVersion = webApiVersionMajor;
429 deviceCapabilities->webApiVersion += ".";
430 deviceCapabilities->webApiVersion += webApiVersionMinor;
431 LogDebug("web api version : " << deviceCapabilities->webApiVersion);
438 return deviceCapabilities;
441 void Systeminfo::get(const EventGetSysteminfoPtr& event)
443 EventRequestReceiver<EventGetSysteminfo>::PostRequest(event);
446 void Systeminfo::watch(const EventWatchSysteminfoPtr& event)
448 if(event->getWatchType() == WATCH_TYPE_UNKNOWN) {
449 LogDebug("watch method is not supported");
454 event->setSysteminfoPtr(this);
455 m_EventMgrPtr->addEvent(event, event->getWatchType());
457 EventRequestReceiver<EventWatchSysteminfo>::PostRequest(event);
460 void Systeminfo::clearWatch(const long id)
463 Throw(InvalidArgumentException);
465 int watchType = m_EventMgrPtr->getWatchType(id);
467 case WATCH_TYPE_BATTERY:
468 if ((m_EventMgrPtr->getEventBatteryList()).size() == 1) {
469 vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, BatteryValueCallback);
470 vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, BatteryValueCallback);
473 case WATCH_TYPE_DISPLAY:
474 if ((m_EventMgrPtr->getEventDisplayList()).size() == 1) {
475 vconf_ignore_key_changed(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, DisplayValueCallback);
478 case WATCH_TYPE_NETWORK:
479 if ((m_EventMgrPtr->getEventNetworkList()).size() == 1) {
480 connection_unset_type_changed_cb(m_connectionHandle);
483 case WATCH_TYPE_WIFINETWORK:
484 if ((m_EventMgrPtr->getEventWifiNetworkList()).size() == 1) {
485 if (m_networkRegist == REGIST_WIFI) {
486 connection_unset_ip_address_changed_cb(m_connectionHandle);
487 m_networkRegist = REGIST_NOT;
488 } else if (m_networkRegist== REGIST_ALL) {
489 m_networkRegist = REGIST_CELLULAR;
493 case WATCH_TYPE_CELLULARNETWORK:
494 if ((m_EventMgrPtr->getEventCellularNetworkList()).size() == 1) {
495 if (m_networkRegist == REGIST_CELLULAR) {
496 connection_unset_ip_address_changed_cb(m_connectionHandle);
497 m_networkRegist = REGIST_NOT;
498 } else if (m_networkRegist== REGIST_ALL) {
499 m_networkRegist = REGIST_WIFI;
503 case WATCH_TYPE_STORAGE:
504 if ((m_EventMgrPtr->getEventStorageList()).size() == 1) {
505 if (m_storageTimer) {
506 ecore_timer_freeze(m_storageTimer);
507 ecore_timer_del(m_storageTimer);
508 m_storageTimer = NULL;
513 if ((m_EventMgrPtr->getEventCpuList()).size() == 1) {
515 ecore_timer_freeze(m_cpuTimer);
516 ecore_timer_del(m_cpuTimer);
521 case WATCH_TYPE_DEVICE_ORIENTATION:
522 if ((m_EventMgrPtr->getEventDeviceOrientationList()).size() == 1) {
523 int state = sf_unregister_event(m_sensorHandle, ACCELEROMETER_EVENT_ROTATION_CHECK);
525 LogDebug("sf_unregister_event fail to gather data\n");
529 case WATCH_TYPE_LOCALE:
530 if ((m_EventMgrPtr->getEventLocaleList()).size() == 1) {
531 runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_LANGUAGE);
532 runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_REGION);
535 case WATCH_TYPE_PERIPHERAL:
536 if ((m_EventMgrPtr->getEventPeripheralList()).size() == 1) {
537 vconf_ignore_key_changed(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, PeripheralValueCallback);
538 vconf_ignore_key_changed(VCONFKEY_SYSMAN_HDMI, PeripheralValueCallback);
541 case WATCH_TYPE_UNKNOWN:
542 Throw(InvalidArgumentException);
545 m_EventMgrPtr->removeEvent(id, watchType);
549 BasePropertyPtr Systeminfo::getBasePropertyPtr(JSContextRef context, JSValueRef property)
551 Converter converter(context);
552 std::string l_property = converter.toString(property);
553 mapProperties::iterator it = (*m_Property).find(l_property);
554 if (it == (*m_Property).end()) {
555 LogError("not existing property");
556 Throw(InvalidArgumentException);
557 return BasePropertyPtr(NULL);
563 void Systeminfo::getWatchValue(const int watchType)
565 if (watchType == WATCH_TYPE_BATTERY) {
566 EventBatteryList eventList = m_EventMgrPtr->getEventBatteryList();
567 for (EventBatteryList::iterator it = eventList.begin(); it != eventList.end(); it++) {
568 (*it)->getWatchValue();
570 } else if (watchType == WATCH_TYPE_DISPLAY) {
571 EventDisplayList eventList = m_EventMgrPtr->getEventDisplayList();
572 for (EventDisplayList::iterator it = eventList.begin(); it != eventList.end(); it++) {
573 (*it)->getWatchValue();
575 } else if (watchType == WATCH_TYPE_NETWORK) {
576 EventNetworkList eventList = m_EventMgrPtr->getEventNetworkList();
577 for (EventNetworkList::iterator it = eventList.begin(); it != eventList.end(); it++) {
578 (*it)->getWatchValue();
580 } else if (watchType == WATCH_TYPE_NETWORK_ALL) {
581 EventWifiNetworkList eventListWifi = m_EventMgrPtr->getEventWifiNetworkList();
582 EventWifiNetworkList eventListCellular = m_EventMgrPtr->getEventCellularNetworkList();
583 if (eventListWifi.size() > 0) {
584 for (EventWifiNetworkList::iterator it = eventListWifi.begin(); it != eventListWifi.end(); it++) {
585 (*it)->getWatchValue();
588 if (eventListCellular.size() > 0) {
589 for (EventCellularNetworkList::iterator it = eventListCellular.begin(); it != eventListCellular.end(); it++) {
590 (*it)->getWatchValue();
593 } else if (watchType == WATCH_TYPE_CPU) {
594 EventCpuList eventList = m_EventMgrPtr->getEventCpuList();
595 for (EventCpuList::iterator it = eventList.begin(); it != eventList.end(); it++) {
596 (*it)->getWatchValue();
598 } else if (watchType == WATCH_TYPE_STORAGE) {
599 EventStorageList eventList = m_EventMgrPtr->getEventStorageList();
600 for (EventStorageList::iterator it = eventList.begin(); it != eventList.end(); it++) {
603 int usbhostState = 0;
604 if(vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &sdcardState) == 0) {
605 if(sdcardState == VCONFKEY_SYSMAN_MMC_MOUNTED) {
609 if(vconf_get_int(VCONFKEY_SYSMAN_USB_HOST_STATUS, &usbhostState) == 0) {
610 if(usbhostState == VCONFKEY_SYSMAN_USB_HOST_CONNECTED) {
614 LogDebug("storage cnt : " << storageCnt);
615 (*it)->getWatchValue(storageCnt);
617 }else if (watchType == WATCH_TYPE_DEVICE_ORIENTATION) {
618 EventDeviceOrientationList eventList = m_EventMgrPtr->getEventDeviceOrientationList();
619 for (EventDeviceOrientationList::iterator it = eventList.begin(); it != eventList.end(); it++) {
620 (*it)->getWatchValue();
622 } else if (watchType == WATCH_TYPE_LOCALE) {
623 EventLocaleList eventList = m_EventMgrPtr->getEventLocaleList();
624 for (EventLocaleList::iterator it = eventList.begin(); it != eventList.end(); it++) {
625 (*it)->getWatchValue();
627 } else if (watchType == WATCH_TYPE_PERIPHERAL) {
628 EventPeripheralList eventList = m_EventMgrPtr->getEventPeripheralList();
629 for (EventPeripheralList::iterator it = eventList.begin(); it != eventList.end(); it++) {
630 (*it)->getWatchValue();
635 connection_h Systeminfo::getConnectionHandle()
637 return m_connectionHandle;
640 JSValueRef Systeminfo::getCpuValue(JSContextRef context)
643 Converter converter(context);
645 CpuPropertiesPtr cpuPtr(new CpuProperties());
647 unsigned long long usr = 0, nice = 0, system = 0, idle = 0, cpuUsage = 0, diffIdle = 0, total = 0;
649 fp = fopen("/proc/stat", "r");
651 return JSValueMakeNull(context);
654 if (fscanf(fp, "%*s %lld %lld %lld %lld", &usr, &system, &nice, &idle) > 0) {
655 total = usr + nice + system + idle - m_cpuInfo.usr - m_cpuInfo.nice - m_cpuInfo.system - m_cpuInfo.idle;
656 diffIdle = idle-m_cpuInfo.idle;
657 if ((total > 0) && (diffIdle > 0)) {
658 cpuUsage = diffIdle * 100 / total;
659 cpuPtr->load = (double)cpuUsage / 100.0;
661 m_cpuInfo.system = system;
662 m_cpuInfo.nice = nice;
663 m_cpuInfo.idle = idle;
664 LogDebug("cpu load : " << cpuPtr->load);
669 return JSCpuInfo::createJSObject(context, cpuPtr);
672 void Systeminfo::OnRequestReceived(const EventGetSysteminfoPtr& event)
675 event->processGetValue((void *)m_connectionHandle);
678 void Systeminfo::OnRequestReceived(const EventWatchSysteminfoPtr& event)
680 WatchOption watchOption = event->getWatchOption();
682 event->switchToManualAnswer();
683 event->setCancelAllowed(true);
685 switch(event->getWatchType()) {
686 case WATCH_TYPE_BATTERY:
687 if ((m_EventMgrPtr->getEventBatteryList()).size() == 1) {
688 vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, BatteryValueCallback, (void *)this);
689 vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, BatteryValueCallback, (void *)this);
692 case WATCH_TYPE_DISPLAY:
693 if ((m_EventMgrPtr->getEventDisplayList()).size() == 1) {
694 vconf_notify_key_changed(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, DisplayValueCallback, (void *)this);
697 case WATCH_TYPE_NETWORK:
698 if ((m_EventMgrPtr->getEventNetworkList()).size() == 1) {
699 connection_set_type_changed_cb(m_connectionHandle, NetworkTypeValueCallback, (void *)this);
702 case WATCH_TYPE_WIFINETWORK:
703 if ((m_EventMgrPtr->getEventWifiNetworkList()).size() == 1) {
704 if (m_networkRegist == REGIST_NOT) {
705 connection_set_ip_address_changed_cb(m_connectionHandle, NetworkValueCallback, (void *)this);
706 m_networkRegist = REGIST_WIFI;
707 } else if (m_networkRegist== REGIST_CELLULAR) {
708 m_networkRegist = REGIST_ALL;
712 case WATCH_TYPE_CELLULARNETWORK:
713 if ((m_EventMgrPtr->getEventCellularNetworkList()).size() == 1) {
714 if (m_networkRegist == REGIST_NOT) {
715 connection_set_ip_address_changed_cb(m_connectionHandle, NetworkValueCallback, (void *)this);
716 m_networkRegist = REGIST_CELLULAR;
717 } else if (m_networkRegist== REGIST_WIFI) {
718 m_networkRegist = REGIST_ALL;
722 case WATCH_TYPE_STORAGE:
723 if ((m_EventMgrPtr->getEventStorageList()).size() == 1) {
724 if (!m_storageTimer) {
725 m_storageTimer = ecore_timer_add(1, StorageValueCallback, this);
726 ecore_timer_thaw(m_storageTimer);
731 if ((m_EventMgrPtr->getEventCpuList()).size() == 1) {
733 m_cpuTimer = ecore_timer_add(1, CpuValueCallback, this);
734 ecore_timer_thaw(m_cpuTimer);
738 case WATCH_TYPE_DEVICE_ORIENTATION:
739 LogDebug("regist sensor");
740 if ((m_EventMgrPtr->getEventDeviceOrientationList()).size() == 1) {
741 int state = sf_register_event(m_sensorHandle, ACCELEROMETER_EVENT_ROTATION_CHECK, NULL, OrientationValueCallback, (void *)this);
743 LogDebug("sensor_register_cb fail to gather data");
744 } else if (state == 0) {
745 LogDebug("sensor_register_cb success to gather data");
748 LogDebug("already regist");
751 case WATCH_TYPE_LOCALE:
752 if ((m_EventMgrPtr->getEventLocaleList()).size() == 1) {
753 runtime_info_set_changed_cb(RUNTIME_INFO_KEY_REGION, localeChangedCallback, (void *)this);
754 runtime_info_set_changed_cb(RUNTIME_INFO_KEY_LANGUAGE, localeChangedCallback, (void *)this);
757 case WATCH_TYPE_PERIPHERAL:
758 if ((m_EventMgrPtr->getEventPeripheralList()).size() == 1) {
759 vconf_notify_key_changed(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, PeripheralValueCallback, (void *)this);
760 vconf_notify_key_changed(VCONFKEY_SYSMAN_HDMI, PeripheralValueCallback, (void *)this);
764 event->processGetValue();
768 ////////////////////////////////////////////////////////////////////////////////////////
770 Systeminfo::EventMgr::EventMgr()
774 Systeminfo::EventMgr::~EventMgr()
778 void Systeminfo::EventMgr::clearAllEvent()
780 DPL::Mutex::ScopedLock lock(&m_synchro);
782 while (!m_eventBatteryList.empty()) {
783 EventWatchSysteminfoPtr event = m_eventBatteryList.front();
784 LogDebug("removing EventId=" << event->getId());
786 m_eventBatteryList.pop_front();
788 while (!m_eventDisplayList.empty()) {
789 EventWatchSysteminfoPtr event = m_eventDisplayList.front();
790 LogDebug("removing EventId=" << event->getId());
792 m_eventDisplayList.pop_front();
794 while (!m_eventWifiNetworkList.empty()) {
795 EventWatchSysteminfoPtr event = m_eventWifiNetworkList.front();
796 LogDebug("removing EventId=" << event->getId());
798 m_eventWifiNetworkList.pop_front();
800 while (!m_eventCelluarNetworkList.empty()) {
801 EventWatchSysteminfoPtr event = m_eventCelluarNetworkList.front();
802 LogDebug("removing EventId=" << event->getId());
804 m_eventCelluarNetworkList.pop_front();
806 while (!m_eventStorageList.empty()) {
807 EventWatchSysteminfoPtr event = m_eventStorageList.front();
808 LogDebug("removing EventId=" << event->getId());
810 m_eventStorageList.pop_front();
812 while (!m_eventCpuList.empty()) {
813 EventWatchSysteminfoPtr event = m_eventCpuList.front();
814 LogDebug("removing EventId=" << event->getId());
816 m_eventCpuList.pop_front();
818 while (!m_eventSimList.empty()) {
819 EventWatchSysteminfoPtr event = m_eventSimList.front();
820 LogDebug("removing EventId=" << event->getId());
822 m_eventSimList.pop_front();
824 while (!m_eventDeviceOrientationList.empty()) {
825 EventWatchSysteminfoPtr event = m_eventDeviceOrientationList.front();
826 LogDebug("removing EventId=" << event->getId());
828 m_eventDeviceOrientationList.pop_front();
830 while (!m_eventLocaleList.empty()) {
831 EventWatchSysteminfoPtr event = m_eventLocaleList.front();
832 LogDebug("removing EventId=" << event->getId());
834 m_eventLocaleList.pop_front();
836 while (!m_eventPeripheralList.empty()) {
837 EventWatchSysteminfoPtr event = m_eventPeripheralList.front();
838 LogDebug("removing EventId=" << event->getId());
840 m_eventPeripheralList.pop_front();
844 void Systeminfo::EventMgr::addEvent(const EventWatchSysteminfoPtr& arg, const int watchType)
846 DPL::Mutex::ScopedLock lock(&m_synchro);
848 if (watchType == WATCH_TYPE_BATTERY){
849 m_eventBatteryList.push_back(arg);
850 LogDebug("Event Battery list size=" << m_eventBatteryList.size());
851 } else if (watchType == WATCH_TYPE_DISPLAY) {
852 m_eventDisplayList.push_back(arg);
853 LogDebug("Event display list size=" << m_eventDisplayList.size());
854 } else if (watchType == WATCH_TYPE_WIFINETWORK) {
855 m_eventWifiNetworkList.push_back(arg);
856 LogDebug("Event wifi network list size=" << m_eventWifiNetworkList.size());
857 } else if (watchType == WATCH_TYPE_CELLULARNETWORK) {
858 m_eventCelluarNetworkList.push_back(arg);
859 LogDebug("Event cellular network list size=" << m_eventCelluarNetworkList.size());
860 } else if (watchType == WATCH_TYPE_STORAGE) {
861 m_eventStorageList.push_back(arg);
862 LogDebug("Event storage list size=" << m_eventStorageList.size());
863 } else if (watchType == WATCH_TYPE_CPU) {
864 m_eventCpuList.push_back(arg);
865 LogDebug("Event cpu list size=" << m_eventCpuList.size());
866 } else if (watchType == WATCH_TYPE_SIM) {
867 m_eventSimList.push_back(arg);
868 LogDebug("Event sim list size=" << m_eventSimList.size());
869 } else if (watchType == WATCH_TYPE_DEVICE_ORIENTATION) {
870 m_eventDeviceOrientationList.push_back(arg);
871 LogDebug("Event device orientation list size=" << m_eventDeviceOrientationList.size());
872 } else if (watchType == WATCH_TYPE_NETWORK) {
873 m_eventNetworkList.push_back(arg);
874 LogDebug("Event network list size=" << m_eventNetworkList.size());
875 } else if (watchType == WATCH_TYPE_LOCALE) {
876 m_eventLocaleList.push_back(arg);
877 LogDebug("Event Locale list size=" << m_eventLocaleList.size());
878 } else if (watchType == WATCH_TYPE_PERIPHERAL) {
879 m_eventPeripheralList.push_back(arg);
880 LogDebug("Event peripheral list size=" << m_eventPeripheralList.size());
884 void Systeminfo::EventMgr::removeEvent(WatchId id, const int watchType)
886 DPL::Mutex::ScopedLock lock(&m_synchro);
887 LogDebug("Event id : " << id);
889 EventWatchSysteminfoPtr event(NULL);
891 LogDebug("trying to delete event, id=" << id);
893 if (watchType == WATCH_TYPE_BATTERY) {
894 for (EventBatteryList::iterator it = m_eventBatteryList.begin(); it != m_eventBatteryList.end(); it++) {
895 if (id == (*it)->getId()) {
901 LogError("event id not in the list, nothing to do");
905 LogDebug("event Battery list size=" << m_eventBatteryList.size());
906 m_eventBatteryList.remove(event);
907 LogDebug( "event removed, event Battery list size=" << m_eventBatteryList.size());
908 } else if (watchType == WATCH_TYPE_DISPLAY) {
909 for (EventDisplayList::iterator it = m_eventDisplayList.begin(); it != m_eventDisplayList.end(); it++) {
910 if (id == (*it)->getId()) {
916 LogError("event id not in the list, nothing to do");
920 LogDebug("event display list size=" << m_eventDisplayList.size());
921 m_eventDisplayList.remove(event);
922 LogDebug( "event removed, event display list size=" << m_eventDisplayList.size());
923 } else if (watchType == WATCH_TYPE_WIFINETWORK) {
924 for (EventWifiNetworkList::iterator it = m_eventWifiNetworkList.begin(); it != m_eventWifiNetworkList.end(); it++) {
925 if (id == (*it)->getId()) {
931 LogError("event id not in the list, nothing to do");
935 LogDebug("event wifi network list size=" << m_eventWifiNetworkList.size());
936 m_eventWifiNetworkList.remove(event);
937 LogDebug( "event removed, event wifi network list size=" << m_eventCelluarNetworkList.size());
938 } else if (watchType == WATCH_TYPE_CELLULARNETWORK) {
939 for (EventCellularNetworkList::iterator it = m_eventCelluarNetworkList.begin(); it != m_eventCelluarNetworkList.end(); it++) {
940 if (id == (*it)->getId()) {
946 LogError("event id not in the list, nothing to do");
950 LogDebug("event cellular network list size=" << m_eventCelluarNetworkList.size());
951 m_eventCelluarNetworkList.remove(event);
952 LogDebug( "event removed, event cellular network list size=" << m_eventCelluarNetworkList.size());
953 } else if (watchType == WATCH_TYPE_STORAGE) {
954 for (EventStorageList::iterator it = m_eventStorageList.begin(); it != m_eventStorageList.end(); it++) {
955 if (id == (*it)->getId()) {
961 LogError("event id not in the list, nothing to do");
965 LogDebug("event storage list size=" << m_eventStorageList.size());
966 m_eventStorageList.remove(event);
967 LogDebug( "event removed, event storage list size=" << m_eventStorageList.size());
968 } else if (watchType == WATCH_TYPE_CPU) {
969 for (EventCpuList::iterator it = m_eventCpuList.begin(); it != m_eventCpuList.end(); it++) {
970 if (id == (*it)->getId()) {
976 LogError("event id not in the list, nothing to do");
980 LogDebug("event cpu list size=" << m_eventCpuList.size());
981 m_eventCpuList.remove(event);
982 LogDebug( "event removed, event cpu list size=" << m_eventCpuList.size());
983 } else if (watchType == WATCH_TYPE_SIM) {
984 for (EventSimList::iterator it = m_eventSimList.begin(); it != m_eventSimList.end(); it++) {
985 if (id == (*it)->getId()) {
991 LogError("event id not in the list, nothing to do");
995 LogDebug("event sim list size=" << m_eventSimList.size());
996 m_eventSimList.remove(event);
997 LogDebug( "event removed, event sim list size=" << m_eventSimList.size());
998 } else if (watchType == WATCH_TYPE_DEVICE_ORIENTATION) {
999 for (EventDeviceOrientationList::iterator it = m_eventDeviceOrientationList.begin(); it != m_eventDeviceOrientationList.end(); it++) {
1000 if (id == (*it)->getId()) {
1006 LogError("event id not in the list, nothing to do");
1010 LogDebug("event device orientation list size=" << m_eventDeviceOrientationList.size());
1011 m_eventDeviceOrientationList.remove(event);
1012 LogDebug( "event removed, event device orientation list size=" << m_eventDeviceOrientationList.size());
1013 } else if (watchType == WATCH_TYPE_NETWORK) {
1014 for (EventNetworkList::iterator it = m_eventNetworkList.begin(); it != m_eventNetworkList.end(); it++) {
1015 if (id == (*it)->getId()) {
1021 LogError("event id not in the list, nothing to do");
1025 LogDebug("event network list size=" << m_eventNetworkList.size());
1026 m_eventNetworkList.remove(event);
1027 LogDebug( "event removed, event network list size=" << m_eventNetworkList.size());
1028 } else if (watchType == WATCH_TYPE_LOCALE) {
1029 for (EventLocaleList::iterator it = m_eventLocaleList.begin(); it != m_eventLocaleList.end(); it++) {
1030 if (id == (*it)->getId()) {
1036 LogError("event id not in the list, nothing to do");
1040 LogDebug("event Locale list size=" << m_eventLocaleList.size());
1041 m_eventLocaleList.remove(event);
1042 LogDebug( "event removed, event Locale list size=" << m_eventLocaleList.size());
1043 } else if (watchType == WATCH_TYPE_PERIPHERAL) {
1044 for (EventPeripheralList::iterator it = m_eventPeripheralList.begin(); it != m_eventPeripheralList.end(); it++) {
1045 if (id == (*it)->getId()) {
1051 LogError("event id not in the list, nothing to do");
1055 LogDebug("event peripheral list size=" << m_eventPeripheralList.size());
1056 m_eventPeripheralList.remove(event);
1057 LogDebug( "event removed, event peripheral list size=" << m_eventPeripheralList.size());
1061 const int Systeminfo::EventMgr::getWatchType(const long id)
1063 DPL::Mutex::ScopedLock lock(&m_synchro);
1065 EventWatchSysteminfoPtr event(NULL);
1067 for (EventBatteryList::iterator it = m_eventBatteryList.begin(); it != m_eventBatteryList.end(); it++) {
1068 if (id == (*it)->getId()) {
1074 for (EventDisplayList::iterator it = m_eventDisplayList.begin(); it != m_eventDisplayList.end(); it++) {
1075 if (id == (*it)->getId()) {
1081 for (EventWifiNetworkList::iterator it = m_eventWifiNetworkList.begin(); it != m_eventWifiNetworkList.end(); it++) {
1082 if (id == (*it)->getId()) {
1088 for (EventCellularNetworkList::iterator it = m_eventCelluarNetworkList.begin(); it != m_eventCelluarNetworkList.end(); it++) {
1089 if (id == (*it)->getId()) {
1095 for (EventStorageList::iterator it = m_eventStorageList.begin(); it != m_eventStorageList.end(); it++) {
1096 if (id == (*it)->getId()) {
1102 for (EventCpuList::iterator it = m_eventCpuList.begin(); it != m_eventCpuList.end(); it++) {
1103 if (id == (*it)->getId()) {
1109 for (EventSimList::iterator it = m_eventSimList.begin(); it != m_eventSimList.end(); it++) {
1110 if (id == (*it)->getId()) {
1116 for (EventDeviceOrientationList::iterator it = m_eventDeviceOrientationList.begin(); it != m_eventDeviceOrientationList.end(); it++) {
1117 if (id == (*it)->getId()) {
1123 for (EventNetworkList::iterator it = m_eventNetworkList.begin(); it != m_eventNetworkList.end(); it++) {
1124 if (id == (*it)->getId()) {
1130 for (EventSimList::iterator it = m_eventSimList.begin(); it != m_eventSimList.end(); it++) {
1131 if (id == (*it)->getId()) {
1137 for (EventLocaleList::iterator it = m_eventLocaleList.begin(); it != m_eventLocaleList.end(); it++) {
1138 if (id == (*it)->getId()) {
1144 for (EventPeripheralList::iterator it = m_eventPeripheralList.begin(); it != m_eventPeripheralList.end(); it++) {
1145 if (id == (*it)->getId()) {
1152 LogError("event id not in the list, nothing to do");
1153 return WATCH_TYPE_UNKNOWN;
1156 return event->getWatchType();
1159 EventBatteryList Systeminfo::EventMgr::getEventBatteryList()
1161 return m_eventBatteryList;
1164 EventDisplayList Systeminfo::EventMgr::getEventDisplayList()
1166 return m_eventDisplayList;
1169 EventNetworkList Systeminfo::EventMgr::getEventNetworkList()
1171 return m_eventNetworkList;
1174 EventWifiNetworkList Systeminfo::EventMgr::getEventWifiNetworkList()
1176 return m_eventWifiNetworkList;
1179 EventCellularNetworkList Systeminfo::EventMgr::getEventCellularNetworkList()
1181 return m_eventCelluarNetworkList;
1184 EventStorageList Systeminfo::EventMgr::getEventStorageList()
1186 return m_eventStorageList;
1189 EventCpuList Systeminfo::EventMgr::getEventCpuList()
1191 return m_eventCpuList;
1194 EventDeviceOrientationList Systeminfo::EventMgr::getEventDeviceOrientationList()
1196 return m_eventDeviceOrientationList;
1199 EventSimList Systeminfo::EventMgr::getEventSimList()
1201 return m_eventSimList;
1204 EventLocaleList Systeminfo::EventMgr::getEventLocaleList()
1206 return m_eventLocaleList;
1209 EventPeripheralList Systeminfo::EventMgr::getEventPeripheralList()
1211 return m_eventPeripheralList;
1214 ////////////////////////////////////////////////////////////////////////////////////////
1216 PROPERTY_GET_SYSTEMINFO_DEFINITION(Battery) {
1217 BatteryPropertiesPtr BatteryPtr(new BatteryProperties());
1221 if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, &value) != 0) {
1222 return JSValueMakeNull(context);
1224 BatteryPtr->level = (double)(value)/CPU_POWER_DEVICE_VALUE;
1227 if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &value2) != 0) {
1228 return JSValueMakeNull(context);
1230 BatteryPtr->isCharging = (value2 == 0) ? false : true;
1233 return JSBatteryInfo::createJSObject(context, BatteryPtr);
1236 PROPERTY_GET_SYSTEMINFO_DEFINITION(Cpu) {
1237 Converter converter(context);
1239 CpuPropertiesPtr cpuPtr(new CpuProperties());
1241 unsigned long long usr = 0, nice = 0, system = 0, idle = 0, total = 0, cpuUsage = 0;
1243 fp = fopen("/proc/stat", "r");
1245 return JSValueMakeNull(context);
1248 if (fscanf(fp, "%*s %lld %lld %lld %lld", &usr, &system, &nice, &idle) > 0) {
1249 total = usr + nice + system + idle;
1250 if ((total > 0) && (idle > 0)) {
1251 cpuUsage = idle * 100 / total;
1252 cpuPtr->load = (double)cpuUsage / 100.0;
1253 LogDebug("cpu load : " << cpuPtr->load);
1258 return JSCpuInfo::createJSObject(context, cpuPtr);
1261 PROPERTY_GET_SYSTEMINFO_DEFINITION(Storage) {
1262 Converter converter(context);
1267 StoragePropertiesPtr internal(new StorageProperties());
1268 StoragePropertiesPtr mmc(new StorageProperties());
1269 StoragePropertiesPtr usbhost(new StorageProperties());
1270 std::vector <JSObjectRef> storagelist;
1272 if (statfs(STORAGE_INTERNAL_PATH, &fs) < 0) {
1273 return JSValueMakeNull(context);
1276 internal->type = "INTERNAL";
1277 internal->capacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_blocks;
1278 internal->availableCapacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_bavail;
1279 internal->isRemoveable = false;
1280 internal->isRemovable = false;
1281 storagelist.push_back(JSStorageInfo::createJSObject(context, internal));
1284 if(vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &sdcardState) == 0){
1285 if(sdcardState == VCONFKEY_SYSMAN_MMC_MOUNTED){
1287 if (statfs(STORAGE_SDCARD_PATH, &fs) < 0) {
1288 return JSValueMakeNull(context);
1291 mmc->capacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_blocks;
1292 mmc->availableCapacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_bavail;
1293 mmc->isRemoveable = true;
1294 mmc->isRemovable = true;
1295 storagelist.push_back(JSStorageInfo::createJSObject(context, mmc));
1299 if(vconf_get_int(VCONFKEY_SYSMAN_USB_HOST_STATUS, &usbhostState) == 0) {
1300 if(usbhostState == VCONFKEY_SYSMAN_USB_HOST_CONNECTED) {
1302 if (statfs(STORAGE_USBHOST_PATH, &fs) < 0) {
1303 return JSValueMakeNull(context);
1305 usbhost->type = "USB_HOST";
1306 usbhost->capacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_blocks;
1307 usbhost->availableCapacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_bavail;
1308 usbhost->isRemoveable = true;
1309 usbhost->isRemovable = true;
1310 storagelist.push_back(JSStorageInfo::createJSObject(context, usbhost));
1314 return JSObjectMakeArray(context, storageCnt, storagelist.data(), NULL);
1317 PROPERTY_GET_SYSTEMINFO_DEFINITION(Display) {
1318 Converter converter(context);
1320 DisplayPropertiesPtr display(new DisplayProperties());
1321 int brightness=0, dotsPerInchX=0, dotsPerInchY=0, physicalW=0, physicalH=0, resolutionW=0, resolutionH=0;
1323 if(vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, &brightness) == 0) {
1324 display->brightness = (double)(brightness)/DISPLAY_BRIGHTNESS_DIVIDE_VALUE;
1325 LogDebug("brightness : " << display->brightness);
1328 if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_WIDTH, &resolutionW) == SYSTEM_INFO_ERROR_NONE) {
1329 display->resolutionWidth = resolutionW;
1330 LogDebug("resolutionWidth : " << display->resolutionWidth);
1332 if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_HEIGHT, &resolutionH) == SYSTEM_INFO_ERROR_NONE) {
1333 display->resolutionHeight = resolutionH;
1334 LogDebug("resolutionHeight : " << display->resolutionHeight);
1336 if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_DPI, &dotsPerInchX) == SYSTEM_INFO_ERROR_NONE) {
1337 display->dotsPerInchWidth = dotsPerInchX;
1338 LogDebug("dotsPerInchWidth : " << display->dotsPerInchWidth);
1340 if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_DPI, &dotsPerInchY) == SYSTEM_INFO_ERROR_NONE) {
1341 display->dotsPerInchHeight = dotsPerInchY;
1342 LogDebug("dotsPerInchHeight : " << display->dotsPerInchHeight);
1344 if (system_info_get_value_int(SYSTEM_INFO_KEY_PHYSICAL_SCREEN_HEIGHT, &physicalH) == SYSTEM_INFO_ERROR_NONE) {
1345 display->physicalHeight = physicalH;
1346 LogDebug("physicalHeight : " << display->physicalHeight);
1348 if (system_info_get_value_int(SYSTEM_INFO_KEY_PHYSICAL_SCREEN_WIDTH, &physicalW) == SYSTEM_INFO_ERROR_NONE) {
1349 display->physicalWidth = physicalW;
1350 LogDebug("physicalWidth : " << display->physicalWidth);
1353 return JSDisplayInfo::createJSObject(context, display);
1356 PROPERTY_GET_SYSTEMINFO_DEFINITION(Network) {
1358 Converter converter(context);
1359 NetworkPropertiesPtr Network(new NetworkProperties());
1360 connection_h connectionHandle = (connection_h)handle;
1361 connection_type_e connectionType;
1362 int networkType = 0;
1364 if (connection_get_type(connectionHandle, &connectionType) != CONNECTION_ERROR_NONE) {
1365 LogDebug("get connection type is failed");
1366 return JSNetworkInfo::createJSObject(context, Network);
1369 if (connectionType == CONNECTION_TYPE_WIFI) {
1370 LogDebug("wifi network");
1371 Network->networkType= "WIFI";
1372 } else if (connectionType == CONNECTION_TYPE_CELLULAR) {
1373 if (vconf_get_int(VCONFKEY_TELEPHONY_SVCTYPE, &networkType) == 0) {
1374 if (networkType < VCONFKEY_TELEPHONY_SVCTYPE_2G) {
1375 Network->networkType= "NONE";
1376 } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_2G) {
1377 Network->networkType= "2G";
1378 } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_2G || networkType == VCONFKEY_TELEPHONY_SVCTYPE_2_5G_EDGE) {
1379 Network->networkType= "2.5";
1380 } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_3G || networkType == VCONFKEY_TELEPHONY_SVCTYPE_HSDPA) {
1381 Network->networkType= "3G";
1383 Network->networkType= "NONE";
1387 Network->networkType= "NONE";
1390 return JSNetworkInfo::createJSObject(context, Network);
1393 PROPERTY_GET_SYSTEMINFO_DEFINITION(WifiNetwork) {
1394 Converter converter(context);
1395 WifiNetworkPropertiesPtr wifiNetwork(new WifiNetworkProperties());
1396 connection_h connectionHandle = (connection_h)handle;
1397 connection_type_e connectionType;
1398 connection_profile_h profileHandle = NULL;
1399 connection_address_family_e addressFamily = CONNECTION_ADDRESS_FAMILY_IPV4;
1400 char* ipAddr = NULL;
1404 if (connection_get_type(connectionHandle, &connectionType) != CONNECTION_ERROR_NONE) {
1405 return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1408 if (connectionType == CONNECTION_TYPE_WIFI) {
1409 wifiNetwork->status = "ON";
1411 wifiNetwork->status = "OFF";
1412 return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1415 if (connection_get_current_profile(connectionHandle, &profileHandle) != CONNECTION_ERROR_NONE) {
1416 return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1419 if (connection_profile_get_wifi_essid(profileHandle, &essid) == CONNECTION_ERROR_NONE) {
1420 wifiNetwork->ssid = essid;
1424 if (connection_profile_get_ip_address(profileHandle, addressFamily, &ipAddr) == CONNECTION_ERROR_NONE) {
1425 wifiNetwork->ipAddress = ipAddr;
1429 if (connection_profile_get_wifi_rssi(profileHandle, &rssi) == CONNECTION_ERROR_NONE) {
1430 wifiNetwork->signalStrength = (double) rssi/WIFI_SIGNAL_STRENGTH_DIVIDE_VALUE;
1433 return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1436 PROPERTY_GET_SYSTEMINFO_DEFINITION(CellularNetwork) {
1437 Converter converter(context);
1438 CellularNetworkPropertiesPtr cellularNetwork(new CellularNetworkProperties());
1439 connection_h connectionHandle = (connection_h)handle;
1440 connection_type_e connectionType;
1441 connection_profile_h profileHandle = NULL;
1442 connection_address_family_e addressFamily = CONNECTION_ADDRESS_FAMILY_IPV4;
1443 char* ipAddr = NULL;
1446 int plmn = 0, cellid = 0, lac = 0, isRoaming = 0, isFlightMode = 0;
1448 if (vconf_get_int(VCONFKEY_TELEPHONY_PLMN, &plmn) == 0) {
1449 cellularNetwork->mcc = plmn / 1000;
1450 cellularNetwork->mnc = plmn % 1000;
1453 if (vconf_get_int(VCONFKEY_TELEPHONY_CELLID, &cellid) == 0) {
1454 cellularNetwork->cellId = cellid;
1457 if (vconf_get_int(VCONFKEY_TELEPHONY_LAC, &lac) == 0) {
1458 cellularNetwork->lac = lac;
1461 if (vconf_get_int(VCONFKEY_TELEPHONY_SVC_ROAM, &isRoaming) == 0) {
1463 cellularNetwork->isRoaming = true;
1465 cellularNetwork->isRoaming = false;
1469 if (vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &isFlightMode) == 0) {
1471 cellularNetwork->isFlightMode = true;
1473 cellularNetwork->isFlightMode = false;
1477 if (connection_get_type(connectionHandle, &connectionType) != CONNECTION_ERROR_NONE) {
1478 return JSCellularNetworkInfo::createJSObject(context, cellularNetwork);
1481 if (connectionType == CONNECTION_TYPE_CELLULAR) {
1482 cellularNetwork->status = "ON";
1483 if (connection_get_current_profile(connectionHandle, &profileHandle) == CONNECTION_ERROR_NONE) {
1484 if (connection_profile_get_cellular_apn(profileHandle, &apn) == CONNECTION_ERROR_NONE) {
1485 cellularNetwork->apn = apn;
1489 if (connection_profile_get_ip_address(profileHandle, addressFamily, &ipAddr) == CONNECTION_ERROR_NONE) {
1490 cellularNetwork->ipAddress = ipAddr;
1493 connection_profile_destroy(profileHandle);
1496 cellularNetwork->status = "OFF";
1497 if (connection_get_default_cellular_service_profile(connectionHandle, CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET, &profileHandle) == CONNECTION_ERROR_NONE) {
1498 if (connection_profile_get_cellular_apn(profileHandle, &apn) == CONNECTION_ERROR_NONE) {
1499 cellularNetwork->apn = apn;
1502 connection_profile_destroy(profileHandle);
1506 if (system_info_get_value_string(SYSTEM_INFO_KEY_MOBILE_DEVICE_ID, &imei) == SYSTEM_INFO_ERROR_NONE) {
1508 LogDebug("imei : " << imei);
1509 cellularNetwork->imei = imei;
1514 return JSCellularNetworkInfo::createJSObject(context, cellularNetwork);
1517 PROPERTY_GET_SYSTEMINFO_DEFINITION(SIM) {
1518 Converter converter(context);
1519 SIMPropertiesPtr SIM(new SIMProperties());
1521 char* fullName = NULL;
1522 char* shortName = NULL;
1523 char* msisdn = NULL;
1529 int ret = SIM_ERROR_NONE;
1531 ret = sim_get_cphs_operator_name(&fullName, &shortName);
1532 if (ret == SIM_ERROR_NONE) {
1534 SIM->operatorName = fullName;
1535 LogDebug("operatorName : " << SIM->operatorName);
1537 } else if (shortName) {
1538 SIM->operatorName = shortName;
1539 LogDebug("operatorName : " << SIM->operatorName);
1544 ret = sim_get_subscriber_number(&msisdn);
1545 if (ret == SIM_ERROR_NONE) {
1547 SIM->msisdn = msisdn;
1548 LogDebug("msisdn : " << SIM->msisdn);
1553 ret = sim_get_icc_id(&iccId);
1554 if (ret == SIM_ERROR_NONE) {
1557 LogDebug("iccid : " << SIM->iccid);
1562 ret = sim_get_mcc(&mcc);
1563 if (ret == SIM_ERROR_NONE) {
1565 SIM->mcc = atoi(mcc);
1566 LogDebug("mcc : " << SIM->mcc);
1571 ret = sim_get_mnc(&mnc);
1572 if (ret == SIM_ERROR_NONE) {
1574 SIM->mnc = atoi(mnc);
1575 LogDebug("mnc : " << SIM->mnc);
1580 ret = sim_get_msin(&msin);
1581 if (ret == SIM_ERROR_NONE) {
1584 LogDebug("msin : " << SIM->msin);
1589 ret = sim_get_spn(&spn);
1590 if (ret == SIM_ERROR_NONE) {
1593 LogDebug("spn : " << SIM->spn);
1598 return JSSIMInfo::createJSObject(context, SIM);
1601 PROPERTY_GET_SYSTEMINFO_DEFINITION(DeviceOrientation) {
1603 Converter converter(context);
1604 DeviceOrientationPropertiesPtr deviceOrientation(new DeviceOrientationProperties());
1606 unsigned long rotation = 0;
1607 int handleOrientaion = 0;
1609 handleOrientaion = sf_connect(ACCELEROMETER_SENSOR);
1610 LogDebug("handleOrientaion : " << handleOrientaion);
1611 if (handleOrientaion < 0) {
1612 LogDebug ("sensor attach fail");
1613 return JSDeviceOrientationInfo::createJSObject(context, deviceOrientation);
1615 int state = sf_start(handleOrientaion, 0);
1617 LogDebug("start failed");
1620 int ret_val = sf_check_rotation(&rotation);
1622 LogDebug("sf_check_rotation fail to gather data\n");
1625 LogDebug(" rotation value = " << rotation);
1629 case ROTATION_EVENT_0:
1630 LogDebug("my_callback_func received data (PORTRAIT_TOP|HEAD_CENTER)\n");
1631 deviceOrientation->status = "PORTRAIT_PRIMARY";
1633 case ROTATION_EVENT_90:
1634 LogDebug("my_callback_func received data (LANDSCAPE|HEAD_RIGHT)\n");
1635 deviceOrientation->status = "LANDSCAPE_PRIMARY";
1637 case ROTATION_EVENT_180:
1638 LogDebug("my_callback_func received data (PORTRAIT_BTM|HEAD_CENTER)\n");
1639 deviceOrientation->status = "PORTRAIT_SECONDARY";
1641 case ROTATION_EVENT_270:
1642 LogDebug("my_callback_func received data (LANDSCAPE|HEAD_LEFT)\n");
1643 deviceOrientation->status = "LANDSCAPE_SECONDARY";
1646 LogDebug(" received data unexpected\n");
1650 state = sf_stop(handleOrientaion);
1651 LogDebug("handleOrientaion 1 state = " << state);
1653 state = sf_disconnect(handleOrientaion);
1654 LogDebug("handleOrientaion state =" << state);
1656 return JSDeviceOrientationInfo::createJSObject(context, deviceOrientation);
1659 PROPERTY_GET_SYSTEMINFO_DEFINITION(Build) {
1661 Converter converter(context);
1662 BuildPropertiesPtr Build(new BuildProperties());
1665 char* manufacturer = NULL;
1667 if (system_info_get_value_string(SYSTEM_INFO_KEY_MODEL, &model) == SYSTEM_INFO_ERROR_NONE) {
1668 if (model != NULL) {
1669 LogDebug("model : " << model);
1670 Build->model = model;
1675 if (system_info_get_value_string(SYSTEM_INFO_KEY_MANUFACTURER, &manufacturer) == SYSTEM_INFO_ERROR_NONE) {
1676 if (manufacturer != NULL) {
1677 LogDebug("manufacturer : " << manufacturer);
1678 Build->manufacturer = manufacturer;
1683 return JSBuildInfo::createJSObject(context, Build);
1686 PROPERTY_GET_SYSTEMINFO_DEFINITION(Locale) {
1688 Converter converter(context);
1689 LocalePropertiesPtr Locale(new LocaleProperties());
1691 char* country = NULL;
1692 char* language = NULL;
1694 if (runtime_info_get_value_string(RUNTIME_INFO_KEY_LANGUAGE, &language) == RUNTIME_INFO_ERROR_NONE) {
1695 if (language != NULL) {
1696 LogDebug("language : " << language);
1697 Locale->language = language;
1702 if (runtime_info_get_value_string(RUNTIME_INFO_KEY_REGION, &country) == RUNTIME_INFO_ERROR_NONE) {
1703 LogDebug("country : " << country);
1705 char* countryTemp = NULL;
1706 token = strtok(country, ".");
1707 if (token != NULL) {
1708 countryTemp = strdup(token);
1709 if (countryTemp != NULL) {
1710 Locale->country = countryTemp;
1712 if (countryTemp != NULL) {
1715 if (country != NULL) {
1721 return JSLocaleInfo::createJSObject(context, Locale);
1724 PROPERTY_GET_SYSTEMINFO_DEFINITION(Peripheral) {
1725 Converter converter(context);
1726 PeripheralPropertiesPtr peripheral(new PeripheralProperties());
1727 int hdmiStatus = 0, wirelessDisplayStatus = 0 ;
1729 if (vconf_get_int(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, &wirelessDisplayStatus) == 0) {
1730 switch(wirelessDisplayStatus) {
1731 case VCONFKEY_MIRACAST_WFD_SOURCE_ON:
1732 peripheral->isVideoOutputOn = true;
1735 LogDebug("VideOutput status is off");
1740 if (vconf_get_int(VCONFKEY_SYSMAN_HDMI, &hdmiStatus) == 0) {
1741 switch(hdmiStatus) {
1742 case VCONFKEY_SYSMAN_HDMI_CONNECTED:
1743 peripheral->isVideoOutputOn = true;
1746 LogDebug("VideOutput status is off");
1751 return JSPeripheralInfo::createJSObject(context, peripheral);