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.
19 #include <JSTizenExceptionFactory.h>
20 #include <JSTizenException.h>
21 #include <SecurityExceptions.h>
23 #include "JSSIMInfo.h"
24 #include "plugin_config.h"
28 namespace Systeminfo {
29 using namespace WrtDeviceApis::CommonsJavaScript;
30 using namespace WrtDeviceApis::Commons;
31 using namespace DeviceAPI::Common;
34 const char* SIM_STATE_PROPERTY = "state";
35 const char* SIM_OPERATORNAME_PROPERTY = "operatorName";
36 const char* SIM_MSISDN_PROPERTY = "msisdn";
37 const char* SIM_ICCID_PROPERTY = "iccid";
38 const char* SIM_MCC_PROPERTY = "mcc";
39 const char* SIM_MNC_PROPERTY = "mnc";
40 const char* SIM_MSIN_PROPERTY = "msin";
41 const char* SIM_SPN_PROPERTY = "spn";
44 JSClassRef JSSIMInfo::m_classRef = NULL;
46 JSClassDefinition JSSIMInfo::m_classInfo = {
48 kJSClassAttributeNone,
66 JSStaticValue JSSIMInfo::m_properties[] = {
67 { SIM_STATE_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
68 { SIM_OPERATORNAME_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
69 { SIM_MSISDN_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
70 { SIM_ICCID_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
71 { SIM_MCC_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
72 { SIM_MNC_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
73 { SIM_MSIN_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
74 { SIM_SPN_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
78 const JSClassRef JSSIMInfo::getClassRef()
81 m_classRef = JSClassCreate(&m_classInfo);
86 const JSClassDefinition* JSSIMInfo::getClassInfo()
91 void JSSIMInfo::Initialize(JSContextRef context, JSObjectRef object)
95 void JSSIMInfo::Finalize(JSObjectRef object)
98 JSSIMPriv* priv = static_cast<JSSIMPriv*>(JSObjectGetPrivate(object));
99 JSObjectSetPrivate(object, NULL);
100 LoggerD("Deleting SIM Info object");
104 bool JSSIMInfo::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName)
106 return JSUtils::hasProperty(m_properties, propertyName);
109 JSObjectRef JSSIMInfo::createJSObject(JSContextRef context, const SIMPropertiesPtr SIMInfo)
112 JSSIMPriv *priv = new JSSIMPriv(context, SIMInfo);
113 return JSObjectMake(context, getClassRef(), priv);
116 JSValueRef JSSIMInfo::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
119 JSSIMPriv *priv = static_cast<JSSIMPriv*>(JSObjectGetPrivate(object));
120 int ret = SIM_ERROR_NONE;
122 LoggerE("Private object not set.");
123 return JSValueMakeUndefined(context);
128 SIMPropertiesPtr SIMInfo = priv->getObject();
129 Converter convert(context);
130 if (JSStringIsEqualToUTF8CString(propertyName, SIM_STATE_PROPERTY)) {
131 AceSecurityStatus status = SYSTEMINFO_CHECK_ACCESS(SYSTEMINFO_FUNCTION_API_GET_PROPERTY_SIM_VALUE);
132 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
134 ret = sim_get_state(&state);
135 if (ret == SIM_ERROR_NONE) {
136 if (state == SIM_STATE_UNAVAILABLE) {
137 SIMInfo->state = "ABSENT";
138 } else if (state == SIM_STATE_LOCKED) {
139 SIMInfo->state = "PIN_REQUIRED";
140 } else if (state == SIM_STATE_AVAILABLE) {
141 SIMInfo->state = "READY";
142 } else if (state == SIM_STATE_UNKNOWN) {
143 SIMInfo->state = "INITIALIZING";
146 return convert.toJSValueRef(SIMInfo->state);
147 } else if (JSStringIsEqualToUTF8CString(propertyName, SIM_OPERATORNAME_PROPERTY)) {
148 AceSecurityStatus status = SYSTEMINFO_CHECK_ACCESS(SYSTEMINFO_FUNCTION_API_GET_PROPERTY_SIM_VALUE);
149 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
150 char* fullName = NULL;
151 char* shortName = NULL;
152 ret = sim_get_cphs_operator_name(&fullName, &shortName);
153 if (ret == SIM_ERROR_NONE) {
155 SIMInfo->operatorName = fullName;
156 LoggerD("operatorName : " << SIMInfo->operatorName);
158 } else if (shortName) {
159 SIMInfo->operatorName = shortName;
160 LoggerD("operatorName : " << SIMInfo->operatorName);
164 return convert.toJSValueRef(SIMInfo->operatorName);
165 } else if (JSStringIsEqualToUTF8CString(propertyName, SIM_MSISDN_PROPERTY)) {
166 AceSecurityStatus status = SYSTEMINFO_CHECK_ACCESS(SYSTEMINFO_FUNCTION_API_GET_PROPERTY_PARTNER_VALUE);
167 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
169 ret = sim_get_subscriber_number(&msisdn);
170 if (ret == SIM_ERROR_NONE) {
172 SIMInfo->msisdn = msisdn;
173 LoggerD("msisdn : " << SIMInfo->msisdn);
177 return convert.toJSValueRef(SIMInfo->msisdn);
178 } else if (JSStringIsEqualToUTF8CString(propertyName, SIM_ICCID_PROPERTY)) {
179 AceSecurityStatus status = SYSTEMINFO_CHECK_ACCESS(SYSTEMINFO_FUNCTION_API_GET_PROPERTY_SIM_VALUE);
180 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
182 ret = sim_get_icc_id(&iccId);
183 if (ret == SIM_ERROR_NONE) {
185 SIMInfo->iccid = iccId;
186 LoggerD("iccid : " << SIMInfo->iccid);
190 return convert.toJSValueRef(SIMInfo->iccid);
191 } else if (JSStringIsEqualToUTF8CString(propertyName, SIM_MCC_PROPERTY)) {
192 AceSecurityStatus status = SYSTEMINFO_CHECK_ACCESS(SYSTEMINFO_FUNCTION_API_GET_PROPERTY_SIM_VALUE);
193 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
195 ret = sim_get_mcc(&mcc);
196 if (ret == SIM_ERROR_NONE) {
198 SIMInfo->mcc = atoi(mcc);
199 LoggerD("mcc : " << SIMInfo->mcc);
203 return convert.toJSValueRef(SIMInfo->mcc);
204 } else if (JSStringIsEqualToUTF8CString(propertyName, SIM_MNC_PROPERTY)) {
205 AceSecurityStatus status = SYSTEMINFO_CHECK_ACCESS(SYSTEMINFO_FUNCTION_API_GET_PROPERTY_SIM_VALUE);
206 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
208 ret = sim_get_mnc(&mnc);
209 if (ret == SIM_ERROR_NONE) {
211 SIMInfo->mnc = atoi(mnc);
212 LoggerD("mnc : " << SIMInfo->mnc);
216 return convert.toJSValueRef(SIMInfo->mnc);
217 } else if (JSStringIsEqualToUTF8CString(propertyName, SIM_MSIN_PROPERTY)) {
218 AceSecurityStatus status = SYSTEMINFO_CHECK_ACCESS(SYSTEMINFO_FUNCTION_API_GET_PROPERTY_PARTNER_VALUE);
219 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
221 ret = sim_get_msin(&msin);
222 if (ret == SIM_ERROR_NONE) {
224 SIMInfo->msin = msin;
225 LoggerD("msin : " << SIMInfo->msin);
229 return convert.toJSValueRef(SIMInfo->msin);
230 } else if (JSStringIsEqualToUTF8CString(propertyName, SIM_SPN_PROPERTY)) {
231 AceSecurityStatus status = SYSTEMINFO_CHECK_ACCESS(SYSTEMINFO_FUNCTION_API_GET_PROPERTY_SIM_VALUE);
232 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
234 ret = sim_get_spn(&spn);
235 if (ret == SIM_ERROR_NONE) {
238 LoggerD("spn : " << SIMInfo->spn);
242 return convert.toJSValueRef(SIMInfo->spn);
247 LoggerE("Exception: " << _rethrown_exception.GetMessage());
249 return JSValueMakeUndefined(context);