Update change log and spec for wrt-plugins-tizen_0.4.49
[framework/web/wrt-plugins-tizen.git] / src / Systeminfo / Systeminfo.cpp
index eeb804f..8f49a1c 100755 (executable)
 #include <CommonsJavaScript/Converter.h>
 #include <CommonsJavaScript/PrivateObject.h>
 #include <TimeTracer.h>
-#include <tapi_common.h>
-#include <ITapiModem.h>
-#include <sim.h>
 #include "Systeminfo.h"
 #include <Logger.h>
 
 using namespace WrtDeviceApis::CommonsJavaScript;
 using namespace WrtDeviceApis::Commons;
-
+#define SIM_VALUE_MAX    4
 
 namespace DeviceAPI {
 namespace Systeminfo {
@@ -65,6 +62,14 @@ void DisplayValueCallback(keynode_t *node, void* event_ptr)
     }
 }
 
+void OrientationValueVconfCallback(keynode_t *node, void *event_ptr)
+{
+    LoggerD("enter");
+    if(event_ptr) {
+        ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_DEVICE_ORIENTATION);
+    }    
+}
+
 void NetworkTypeValueCallback(connection_type_e type, void* event_ptr)
 {
     if(event_ptr) {
@@ -97,7 +102,6 @@ static Eina_Bool CpuValueCallback(void* event_ptr)
 
 void OrientationValueCallback(unsigned int event_type, sensor_event_data_t *event , void *event_ptr)
 {
-    LoggerD("enter");
     if(event_ptr) {
         ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_DEVICE_ORIENTATION);
     }
@@ -105,10 +109,111 @@ void OrientationValueCallback(unsigned int event_type, sensor_event_data_t *even
 
 void localeChangedCallback(runtime_info_key_e key, void* event_ptr)
 {
-    LoggerD("enter");
     if(event_ptr) {
         ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_LOCALE);
-    }    
+    }
+}
+
+void SimCphsValueCallback(TapiHandle *handle, int result, void *data, void *user_data)
+{
+       TelSimAccessResult_t access_rt = (TelSimAccessResult_t)result;
+       TelSimCphsNetName_t *cphsInfo = (TelSimCphsNetName_t *)data;
+
+    LoggerD("access_rt : " << access_rt);
+
+    if (user_data != NULL){
+        SysteminfoAsyncPendingEvent *pendingEvent = (SysteminfoAsyncPendingEvent *)user_data;
+        Systeminfo *systeminfo = (Systeminfo *)pendingEvent->getThisObject();
+        EventGetSysteminfoPtr event = pendingEvent->getEvent();
+
+        if (access_rt == TAPI_SIM_ACCESS_SUCCESS) {
+            if (cphsInfo->full_name) {
+            systeminfo->setSimValue(SIM_CPHS_VALUE, (char *)cphsInfo->full_name, event);
+            } else if (cphsInfo->short_name) {
+                systeminfo->setSimValue(SIM_CPHS_VALUE, (char *)cphsInfo->short_name, event);
+            } else {
+                systeminfo->setSimValue(SIM_CPHS_VALUE, NULL, event);                    
+            }
+        } else {
+            systeminfo->setSimValue(SIM_CPHS_VALUE, NULL, event);        
+        }
+
+        delete pendingEvent;
+        pendingEvent = NULL;
+        user_data = NULL;
+    }
+}
+
+void SimMsisdnValueCallback(TapiHandle *handle, int result, void *data, void *user_data)
+{
+       TelSimAccessResult_t access_rt = (TelSimAccessResult_t)result;
+       TelSimMsisdnList_t *msisdnInfo = (TelSimMsisdnList_t *)data;
+
+    LoggerD("access_rt : " << access_rt);
+
+    if (user_data != NULL){
+        SysteminfoAsyncPendingEvent *pendingEvent = (SysteminfoAsyncPendingEvent *)user_data;
+        Systeminfo *systeminfo = (Systeminfo *)pendingEvent->getThisObject();
+        EventGetSysteminfoPtr event = pendingEvent->getEvent();
+
+        if (access_rt == TAPI_SIM_ACCESS_SUCCESS) {
+            systeminfo->setSimValue(SIM_MSISDN_VALUE, (char *)msisdnInfo->list[0].num, event);
+        } else {
+            systeminfo->setSimValue(SIM_MSISDN_VALUE, NULL, event);        
+        }
+
+        delete pendingEvent;
+        pendingEvent = NULL;
+        user_data = NULL;
+    }
+}
+
+void SimIccidValueCallback(TapiHandle *handle, int result, void *data, void *user_data)
+{
+    TelSimAccessResult_t access_rt = (TelSimAccessResult_t)result;
+       TelSimIccIdInfo_t *iccidInfo = (TelSimIccIdInfo_t *)data;
+
+    LoggerD("access_rt : " << access_rt);
+
+    if (user_data != NULL){
+        SysteminfoAsyncPendingEvent *pendingEvent = (SysteminfoAsyncPendingEvent *)user_data;
+        Systeminfo *systeminfo = (Systeminfo *)pendingEvent->getThisObject();
+        EventGetSysteminfoPtr event = pendingEvent->getEvent();
+
+        if (access_rt == TAPI_SIM_ACCESS_SUCCESS) {
+            systeminfo->setSimValue(SIM_ICCID_VALUE, (char *)iccidInfo->icc_num, event);
+        } else {
+            systeminfo->setSimValue(SIM_ICCID_VALUE, NULL, event);        
+        }
+
+        delete pendingEvent;
+        pendingEvent = NULL;
+        user_data = NULL;
+    }
+}
+
+void SimSpnValueCallback(TapiHandle *handle, int result, void *data, void *user_data)
+{
+    TelSimAccessResult_t access_rt = (TelSimAccessResult_t)result;
+    TelSimSpn_t *spnInfo = (TelSimSpn_t *)data;
+
+    LoggerD("access_rt : " << access_rt);
+
+    if (user_data != NULL){
+        SysteminfoAsyncPendingEvent *pendingEvent = (SysteminfoAsyncPendingEvent *)user_data;
+        Systeminfo *systeminfo = (Systeminfo *)pendingEvent->getThisObject();
+        EventGetSysteminfoPtr event = pendingEvent->getEvent();
+        
+        if (access_rt == TAPI_SIM_ACCESS_SUCCESS) {
+            systeminfo->setSimValue(SIM_SPN_VALUE, (char *)spnInfo->spn, event);
+        } else {
+            systeminfo->setSimValue(SIM_ICCID_VALUE, NULL, event);        
+        }
+
+        delete pendingEvent;
+        pendingEvent = NULL;
+        user_data = NULL;
+    }
 }
 
 }
@@ -175,6 +280,11 @@ Systeminfo::Systeminfo() : m_networkRegist(REGIST_NOT),
             LoggerD("failed");
         }
     }
+
+    m_tapiHandle = tel_init(0);
+    if (m_tapiHandle == NULL) {
+        LoggerE ("tel init fail");
+    }
 }
 
 Systeminfo::~Systeminfo()
@@ -199,6 +309,10 @@ Systeminfo::~Systeminfo()
         LoggerD("Network Client deregistration failed");
     }
 
+    if (m_tapiHandle != NULL) {
+        tel_deinit(m_tapiHandle);
+    }
+
        state = sf_stop(m_sensorHandle);
        LoggerD("handle 1  state = " << state);
 
@@ -215,6 +329,7 @@ DeviceCapabilitiesPropertiesPtr Systeminfo::getCapabilities()
 
 void Systeminfo::get(const EventGetSysteminfoPtr& event)
 {
+    event->setTapiHandle((void*)m_tapiHandle);
     EventRequestReceiver<EventGetSysteminfo>::PostRequest(event);
 }
 
@@ -227,6 +342,7 @@ void Systeminfo::watch(const EventWatchSysteminfoPtr& event)
     }
 
     event->setSysteminfoPtr(this);
+    event->setTapiHandle((void*)m_tapiHandle);
     m_EventMgrPtr->addEvent(event, event->getWatchType());
 
     EventRequestReceiver<EventWatchSysteminfo>::PostRequest(event);
@@ -299,6 +415,7 @@ void Systeminfo::clearWatch(const long id)
                 break;
             case WATCH_TYPE_DEVICE_ORIENTATION:
                 if ((m_EventMgrPtr->getEventDeviceOrientationList()).size() == 1) {
+                    vconf_ignore_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, OrientationValueVconfCallback);
                     int state = sf_unregister_event(m_sensorHandle, ACCELEROMETER_EVENT_ROTATION_CHECK);
                     if (state < 0) {
                         LoggerD("sf_unregister_event fail to gather data\n");
@@ -457,10 +574,93 @@ JSValueRef Systeminfo::getCpuValue(JSContextRef context)
     return JSCpuInfo::createJSObject(context, cpuPtr);
 }
 
+void Systeminfo::setSimValue(const int simAttribute, char* value, const EventGetSysteminfoPtr &event)
+{
+    int ret = 0;
+    if (!value) {
+        ret = event->addSimValueCnt();
+    } else {
+        ret = event->setSimValue(simAttribute, value);
+    }
+
+    if (ret == SIM_VALUE_MAX) {
+        event->makeSimObject();
+        EventRequestReceiver<EventGetSysteminfo>::ManualAnswer(event);
+    }
+}
+
 void Systeminfo::OnRequestReceived(const EventGetSysteminfoPtr& event)
 {
     LoggerD("enter");
-    event->processGetValue((void *)m_connectionHandle);
+
+    if (strcmp(event->getProperty(), (const char*)"SIM") == 0) {
+        int cardChanged = 0;
+        TelSimCardStatus_t simCardState;
+        TelSimImsiInfo_t imsi;
+        char* simState = NULL;
+
+        event->switchToManualAnswer();
+        event->setCancelAllowed(true);        
+        
+        if (tel_get_sim_init_info(m_tapiHandle, &simCardState, &cardChanged) == TAPI_API_SUCCESS) {
+            switch(simCardState) {
+                case TAPI_SIM_STATUS_CARD_NOT_PRESENT :
+                case TAPI_SIM_STATUS_CARD_REMOVED : 
+                    simState = strdup("ABSENT");
+                    break;
+                case TAPI_SIM_STATUS_SIM_INITIALIZING :
+                    simState = strdup("INITIALIZING");
+                    break;
+                case TAPI_SIM_STATUS_SIM_INIT_COMPLETED :
+                    simState = strdup("READY");
+                    break;
+                case TAPI_SIM_STATUS_SIM_PIN_REQUIRED :
+                    simState = strdup("PIN_REQUIRED");
+                    break;
+                case TAPI_SIM_STATUS_SIM_PUK_REQUIRED :
+                    simState = strdup("PUK_REQUIRED");
+                    break;
+                case TAPI_SIM_STATUS_SIM_LOCK_REQUIRED :
+                case TAPI_SIM_STATUS_CARD_BLOCKED :
+                    simState = strdup("SIM_LOCKED");
+                    break;
+                case TAPI_SIM_STATUS_SIM_NCK_REQUIRED :
+                case TAPI_SIM_STATUS_SIM_NSCK_REQUIRED :
+                    simState = strdup("NETWORK_LOCKED");
+                    break;
+                default:
+                    simState = strdup("UNKNOWN");
+                    break;
+            }
+            LoggerD("simState : " << simState);
+            event->setSimState(simState);
+            if (simState)
+                free(simState);
+            if(strcmp(simState, "READY") == 0) {
+                if (tel_get_sim_imsi(m_tapiHandle, &imsi) == TAPI_API_SUCCESS) {
+                    LoggerD("mcc : " << imsi.szMcc << \r" mnc : " << imsi.szMnc << " msin : " << imsi.szMsin);
+                    event->setSimImsi(imsi.szMcc, imsi.szMnc, imsi.szMsin);
+                } else {
+                    LoggerE("get fail sim imsi");
+                }
+                SysteminfoAsyncPendingEvent *cphsPendingEvent = new SysteminfoAsyncPendingEvent((void *)this, event);
+                tel_get_sim_cphs_netname(m_tapiHandle, SimCphsValueCallback, cphsPendingEvent);
+                SysteminfoAsyncPendingEvent *msisdnPendingEvent = new SysteminfoAsyncPendingEvent((void *)this, event);
+                tel_get_sim_msisdn(m_tapiHandle, SimMsisdnValueCallback, msisdnPendingEvent);
+                SysteminfoAsyncPendingEvent *iccidPendingEvent = new SysteminfoAsyncPendingEvent((void *)this, event);
+                tel_get_sim_iccid(m_tapiHandle, SimIccidValueCallback, iccidPendingEvent);
+                SysteminfoAsyncPendingEvent *spnPendingEvent = new SysteminfoAsyncPendingEvent((void *)this, event);
+                tel_get_sim_spn(m_tapiHandle, SimSpnValueCallback, spnPendingEvent);
+            } else {
+                event->makeSimObject();
+                EventRequestReceiver<EventGetSysteminfo>::ManualAnswer(event);
+            }
+        } else {
+            LoggerE("get fail sim state");
+        }
+    } else {
+        event->processGetValue((void *)m_connectionHandle);
+    }
 }
 
 void Systeminfo::OnRequestReceived(const EventWatchSysteminfoPtr& event)
@@ -530,6 +730,7 @@ void Systeminfo::OnRequestReceived(const EventWatchSysteminfoPtr& event)
         case WATCH_TYPE_DEVICE_ORIENTATION:
             LoggerD("regist sensor");
             if ((m_EventMgrPtr->getEventDeviceOrientationList()).size() == 1) {
+                vconf_notify_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, OrientationValueVconfCallback, (void *)this);
                 int state = sf_register_event(m_sensorHandle, ACCELEROMETER_EVENT_ROTATION_CHECK, NULL, OrientationValueCallback, (void *)this);
                 if (state < 0) {
                     LoggerD("sensor_register_cb fail to gather data");
@@ -1062,7 +1263,6 @@ PROPERTY_GET_SYSTEMINFO_DEFINITION(Storage) {
     struct statfs fs;
     
     if (statfs(STORAGE_INTERNAL_PATH, &fs) < 0) {
-        // make exception
         return JSValueMakeNull(context);
     }
     StoragePropertiesPtr storagePtr(new StorageProperties());
@@ -1095,36 +1295,38 @@ PROPERTY_GET_SYSTEMINFO_DEFINITION(Display) {
     Converter converter(context);
 
     DisplayPropertiesPtr display(new DisplayProperties());
-    int brightness=0, dotsPerInchX=0, dotsPerInchY=0, physicalW=0, physicalH=0, resolutionW=0, resolutionH=0;
+    int brightness=0, dotsPerInch=0, physicalW=0, physicalH=0;
+    bool screenSizeSmall = false, screenSizeBig = false;
 
     if(vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, &brightness) == 0) {
         display->brightness = (double)(brightness)/DISPLAY_BRIGHTNESS_DIVIDE_VALUE;
-        LoggerD("brightness : " << display->brightness);
     }
 
-    if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_WIDTH, &resolutionW) == SYSTEM_INFO_ERROR_NONE) {
-        display->resolutionWidth = resolutionW;
-        LoggerD("resolutionWidth : " << display->resolutionWidth);
-    }
-    if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_HEIGHT, &resolutionH) == SYSTEM_INFO_ERROR_NONE) {
-        display->resolutionHeight = resolutionH;
-        LoggerD("resolutionHeight : " << display->resolutionHeight);
+    if(system_info_get_platform_bool("tizen.org/feature/screen.size.normal.480.800", &screenSizeSmall) == SYSTEM_INFO_ERROR_NONE) {
+        if (screenSizeSmall) {
+            display->resolutionWidth = 480;
+            display->resolutionHeight = 800;
+        } else {
+            if (system_info_get_platform_bool("tizen.org/feature/screen.size.normal.720.1280", &screenSizeBig) == SYSTEM_INFO_ERROR_NONE) {
+                if (screenSizeBig) {
+                    display->resolutionWidth = 720;
+                    display->resolutionHeight = 1280;
+                }
+            }
+        }
     }
-    if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_DPI, &dotsPerInchX) == SYSTEM_INFO_ERROR_NONE) {
-        display->dotsPerInchWidth = dotsPerInchX;
-        LoggerD("dotsPerInchWidth : " << display->dotsPerInchWidth);
+
+    if(system_info_get_platform_int("tizen.org/feature/screen.dpi", &dotsPerInch) == SYSTEM_INFO_ERROR_NONE) {
+        display->dotsPerInchWidth = dotsPerInch;
+        display->dotsPerInchHeight = dotsPerInch;        
     }
-    if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_DPI, &dotsPerInchY) == SYSTEM_INFO_ERROR_NONE) {
-        display->dotsPerInchHeight = dotsPerInchY;
-        LoggerD("dotsPerInchHeight : " << display->dotsPerInchHeight);
+
+    if(system_info_get_value_int(SYSTEM_INFO_KEY_PHYSICAL_SCREEN_WIDTH, &physicalW) == SYSTEM_INFO_ERROR_NONE) {
+        display->physicalWidth = physicalW;
     }
-    if (system_info_get_value_int(SYSTEM_INFO_KEY_PHYSICAL_SCREEN_HEIGHT, &physicalH) == SYSTEM_INFO_ERROR_NONE) {
+
+    if(system_info_get_value_int(SYSTEM_INFO_KEY_PHYSICAL_SCREEN_HEIGHT, &physicalH) == SYSTEM_INFO_ERROR_NONE) {
         display->physicalHeight = physicalH;
-        LoggerD("physicalHeight : " << display->physicalHeight);
-    }
-    if (system_info_get_value_int(SYSTEM_INFO_KEY_PHYSICAL_SCREEN_WIDTH, &physicalW) == SYSTEM_INFO_ERROR_NONE) {
-        display->physicalWidth = physicalW;
-        LoggerD("physicalWidth : " << display->physicalWidth);
     }
 
     return JSDisplayInfo::createJSObject(context, display);
@@ -1223,7 +1425,6 @@ PROPERTY_GET_SYSTEMINFO_DEFINITION(CellularNetwork) {
     char* apn = NULL;
     char* imei = NULL;
     int plmn = 0, cellId = 0, lac = 0, isRoaming = 0, isFlightMode = 0;
-    TapiHandle *tapiHandle = NULL;    
 
     TIME_TRACER_ITEM_BEGIN("(cellular)mcc", 0);
     if (vconf_get_int(VCONFKEY_TELEPHONY_PLMN, &plmn) == 0) {
@@ -1298,20 +1499,15 @@ PROPERTY_GET_SYSTEMINFO_DEFINITION(CellularNetwork) {
             connection_profile_destroy(profileHandle);
         }
     }
-  
-    tapiHandle = tel_init(0);
+   
+    imei = tel_get_misc_me_imei_sync((TapiHandle*)tapiHandle);
     
-    if (tapiHandle != NULL) {
-        imei = tel_get_misc_me_imei_sync(tapiHandle);
-        
-        if (imei == NULL) {
-            tel_deinit(tapiHandle);
-            return JSCellularNetworkInfo::createJSObject(context, cellularNetwork);
-        }
-        
+    if (imei != NULL) {
+        LoggerD("imei : " << imei);
         cellularNetwork->imei = imei;
         free(imei);
-        tel_deinit(tapiHandle);
+    } else {
+        LoggerD("get fail imei");
     }
 
     return JSCellularNetworkInfo::createJSObject(context, cellularNetwork);
@@ -1321,98 +1517,6 @@ PROPERTY_GET_SYSTEMINFO_DEFINITION(SIM) {
     Converter converter(context);
     SIMPropertiesPtr SIM(new SIMProperties());
 
-    sim_state_e state;
-    char* fullName = NULL;
-    char* shortName = NULL;
-    char* msisdn = NULL;
-    char* iccId = NULL;
-    char* mcc = NULL;
-    char* mnc = NULL;
-    char* msin = NULL;
-    char* spn = NULL;
-    int ret = SIM_ERROR_NONE;    
-
-    ret = sim_get_state(&state);
-    if (ret == SIM_ERROR_NONE) {
-        if (state == SIM_STATE_UNAVAILABLE) {
-            SIM->state = "ABSENT";
-        } else if (state == SIM_STATE_LOCKED) {
-            SIM->state = "PIN_REQUIRED";
-        } else if (state == SIM_STATE_AVAILABLE) {
-            SIM->state = "READY";
-        } else if (state == SIM_STATE_UNKNOWN) {
-            SIM->state = "INITIALIZING";
-        }
-    }
-
-    ret = sim_get_cphs_operator_name(&fullName, &shortName);
-    if (ret == SIM_ERROR_NONE) {
-        if (fullName) {
-            SIM->operatorName = fullName;
-            LoggerD("operatorName : " << SIM->operatorName);
-            free(fullName);
-        } else if (shortName) {
-            SIM->operatorName = shortName;
-            LoggerD("operatorName : " << SIM->operatorName);
-            free(shortName);
-        }
-    }
-
-
-    ret = sim_get_subscriber_number(&msisdn);
-    if (ret == SIM_ERROR_NONE) {
-        if (msisdn) {
-            SIM->msisdn = msisdn;
-            LoggerD("msisdn : " << SIM->msisdn);
-            free(msisdn);
-        }
-    }
-
-    ret = sim_get_icc_id(&iccId);
-    if (ret == SIM_ERROR_NONE) {
-        if (iccId) {
-            SIM->iccid = iccId;
-            LoggerD("iccid : " << SIM->iccid);
-            free(iccId);
-        }
-    }
-
-    ret = sim_get_mcc(&mcc);
-    if (ret == SIM_ERROR_NONE) {
-        if (mcc) {
-            SIM->mcc = atoi(mcc);
-            LoggerD("mcc : " << SIM->mcc);
-            free(mcc);
-        }
-    }
-
-    ret = sim_get_mnc(&mnc);
-    if (ret == SIM_ERROR_NONE) {
-        if (mnc) {
-            SIM->mnc = atoi(mnc);
-            LoggerD("mnc : " << SIM->mnc);
-            free(mnc);
-        }
-    }
-
-    ret = sim_get_msin(&msin);
-    if (ret == SIM_ERROR_NONE) {
-        if (msin) {
-            SIM->msin = msin;
-            LoggerD("msin : " << SIM->msin);
-            free(msin);
-        }
-    }
-
-    ret = sim_get_spn(&spn);
-    if (ret == SIM_ERROR_NONE) {
-        if (spn) {
-            SIM->spn = spn;
-            LoggerD("spn : " << SIM->spn);
-            free(spn);
-        }
-    }
-
     return JSSIMInfo::createJSObject(context, SIM);
 }
 
@@ -1423,6 +1527,15 @@ PROPERTY_GET_SYSTEMINFO_DEFINITION(DeviceOrientation) {
 
     unsigned long rotation = 0;
     int handleOrientaion = 0;
+    int isAutoRotation = 0;
+
+    if (vconf_get_bool(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &isAutoRotation) == 0) {
+        if (isAutoRotation) {
+            deviceOrientation->isAutoRotation = true;
+        } else {
+            deviceOrientation->isAutoRotation = false;
+        }
+    }
 
     handleOrientaion = sf_connect(ACCELEROMETER_SENSOR);
     LoggerD("handleOrientaion : " << handleOrientaion);
@@ -1483,7 +1596,7 @@ PROPERTY_GET_SYSTEMINFO_DEFINITION(Build) {
     char* manufacturer = NULL;
     char* buildVersion = NULL;
 
-    if (system_info_get_value_string(SYSTEM_INFO_KEY_MODEL, &model) == SYSTEM_INFO_ERROR_NONE) {
+    if(system_info_get_platform_string("tizen.org/system/model_name", &model) == SYSTEM_INFO_ERROR_NONE) {
         if (model != NULL) {
             LoggerD("model : " << model);
             Build->model = model;