wrt-plugins-tizen_0.4.23
[framework/web/wrt-plugins-tizen.git] / src / Systeminfo / JSSIMInfo.cpp
index 7092ab9..8b6e534 100755 (executable)
 //
 
 #include <memory>
-#include <dpl/log/log.h>
 #include <JSTizenExceptionFactory.h>
 #include <JSTizenException.h>
 #include <SecurityExceptions.h>
 #include <sim.h>
 #include "JSSIMInfo.h"
 #include "plugin_config.h"
+#include <Logger.h>
 
 namespace DeviceAPI {
 namespace Systeminfo {
@@ -31,6 +31,7 @@ using namespace WrtDeviceApis::Commons;
 using namespace DeviceAPI::Common;
 
 namespace {
+const char* SIM_STATE_PROPERTY = "state";
 const char* SIM_OPERATORNAME_PROPERTY = "operatorName";
 const char* SIM_MSISDN_PROPERTY = "msisdn";
 const char* SIM_ICCID_PROPERTY = "iccid";
@@ -63,6 +64,7 @@ JSClassDefinition JSSIMInfo::m_classInfo = {
 };
 
 JSStaticValue JSSIMInfo::m_properties[] = {
+    { SIM_STATE_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
     { SIM_OPERATORNAME_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
     { SIM_MSISDN_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
     { SIM_ICCID_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },        
@@ -92,10 +94,10 @@ void JSSIMInfo::Initialize(JSContextRef context, JSObjectRef object)
 
 void JSSIMInfo::Finalize(JSObjectRef object)
 {
-    LogDebug("Entered");
+    LoggerD("Entered");
     JSSIMPriv* priv = static_cast<JSSIMPriv*>(JSObjectGetPrivate(object));
     JSObjectSetPrivate(object, NULL);
-    LogDebug("Deleting SIM Info object");
+    LoggerD("Deleting SIM Info object");
     delete priv;
 }
 
@@ -106,18 +108,18 @@ bool JSSIMInfo::hasProperty(JSContextRef context, JSObjectRef object, JSStringRe
 
 JSObjectRef JSSIMInfo::createJSObject(JSContextRef context, const SIMPropertiesPtr SIMInfo)
 {
-    LogDebug("Enter");
+    LoggerD("Enter");
     JSSIMPriv *priv = new JSSIMPriv(context, SIMInfo);
     return JSObjectMake(context, getClassRef(), priv);
 }
 
 JSValueRef JSSIMInfo::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
 {
-    LogDebug("Enter");
+    LoggerD("Enter");
     JSSIMPriv *priv = static_cast<JSSIMPriv*>(JSObjectGetPrivate(object));
     int ret = SIM_ERROR_NONE;
     if (NULL == priv) {
-        LogError("Private object not set.");
+        LoggerE("Private object not set.");
         return JSValueMakeUndefined(context);
     }
 
@@ -125,8 +127,24 @@ JSValueRef JSSIMInfo::getProperty(JSContextRef context, JSObjectRef object, JSSt
     {
         SIMPropertiesPtr SIMInfo = priv->getObject();
         Converter convert(context);
-
-        if (JSStringIsEqualToUTF8CString(propertyName, SIM_OPERATORNAME_PROPERTY)) {
+        if (JSStringIsEqualToUTF8CString(propertyName, SIM_STATE_PROPERTY)) {
+            AceSecurityStatus status = SYSTEMINFO_CHECK_ACCESS(SYSTEMINFO_FUNCTION_API_GET_PROPERTY_SIM_VALUE);
+            TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+            sim_state_e state;
+            ret = sim_get_state(&state);
+            if (ret == SIM_ERROR_NONE) {
+                if (state == SIM_STATE_UNAVAILABLE) {
+                    SIMInfo->state = "ABSENT";
+                } else if (state == SIM_STATE_LOCKED) {
+                   SIMInfo->state = "PIN_REQUIRED";
+                } else if (state == SIM_STATE_AVAILABLE) {
+                   SIMInfo->state = "READY";
+                } else if (state == SIM_STATE_UNKNOWN) {
+                   SIMInfo->state = "INITIALIZING";
+                }
+            }
+            return convert.toJSValueRef(SIMInfo->state);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, SIM_OPERATORNAME_PROPERTY)) {
             AceSecurityStatus status = SYSTEMINFO_CHECK_ACCESS(SYSTEMINFO_FUNCTION_API_GET_PROPERTY_SIM_VALUE);
             TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
             char* fullName = NULL;
@@ -135,11 +153,11 @@ JSValueRef JSSIMInfo::getProperty(JSContextRef context, JSObjectRef object, JSSt
             if (ret == SIM_ERROR_NONE) {
                 if (fullName) {
                     SIMInfo->operatorName = fullName;
-                    LogDebug("operatorName : " << SIMInfo->operatorName);
+                    LoggerD("operatorName : " << SIMInfo->operatorName);
                     free(fullName);
                 } else if (shortName) {
                     SIMInfo->operatorName = shortName;
-                    LogDebug("operatorName : " << SIMInfo->operatorName);
+                    LoggerD("operatorName : " << SIMInfo->operatorName);
                     free(shortName);
                 }
             }
@@ -152,7 +170,7 @@ JSValueRef JSSIMInfo::getProperty(JSContextRef context, JSObjectRef object, JSSt
             if (ret == SIM_ERROR_NONE) {
                 if (msisdn) {
                     SIMInfo->msisdn = msisdn;
-                    LogDebug("msisdn : " << SIMInfo->msisdn);
+                    LoggerD("msisdn : " << SIMInfo->msisdn);
                     free(msisdn);
                 }
             }
@@ -165,7 +183,7 @@ JSValueRef JSSIMInfo::getProperty(JSContextRef context, JSObjectRef object, JSSt
             if (ret == SIM_ERROR_NONE) {
                 if (iccId) {
                     SIMInfo->iccid = iccId;
-                    LogDebug("iccid : " << SIMInfo->iccid);
+                    LoggerD("iccid : " << SIMInfo->iccid);
                     free(iccId);
                 }
             }
@@ -178,7 +196,7 @@ JSValueRef JSSIMInfo::getProperty(JSContextRef context, JSObjectRef object, JSSt
             if (ret == SIM_ERROR_NONE) {
                 if (mcc) {
                     SIMInfo->mcc = atoi(mcc);
-                    LogDebug("mcc : " << SIMInfo->mcc);
+                    LoggerD("mcc : " << SIMInfo->mcc);
                     free(mcc);
                 }
             }
@@ -191,7 +209,7 @@ JSValueRef JSSIMInfo::getProperty(JSContextRef context, JSObjectRef object, JSSt
             if (ret == SIM_ERROR_NONE) {
                 if (mnc) {
                     SIMInfo->mnc = atoi(mnc);
-                    LogDebug("mnc : " << SIMInfo->mnc);
+                    LoggerD("mnc : " << SIMInfo->mnc);
                     free(mnc);
                 }
             }
@@ -204,7 +222,7 @@ JSValueRef JSSIMInfo::getProperty(JSContextRef context, JSObjectRef object, JSSt
             if (ret == SIM_ERROR_NONE) {
                 if (msin) {
                     SIMInfo->msin = msin;
-                    LogDebug("msin : " << SIMInfo->msin);
+                    LoggerD("msin : " << SIMInfo->msin);
                     free(msin);
                 }
             }
@@ -217,7 +235,7 @@ JSValueRef JSSIMInfo::getProperty(JSContextRef context, JSObjectRef object, JSSt
             if (ret == SIM_ERROR_NONE) {
                 if (spn) {
                     SIMInfo->spn = spn;
-                    LogDebug("spn : " << SIMInfo->spn);
+                    LoggerD("spn : " << SIMInfo->spn);
                     free(spn);
                 }
             }
@@ -226,7 +244,7 @@ JSValueRef JSSIMInfo::getProperty(JSContextRef context, JSObjectRef object, JSSt
     }
     Catch(Exception)
     {
-        LogError("Exception: " << _rethrown_exception.GetMessage());
+        LoggerE("Exception: " << _rethrown_exception.GetMessage());
     }
     return JSValueMakeUndefined(context);
 }