2 * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include "MsgCppTypes.h"
22 #include "MsgException.h"
23 #include "MsgGconfWrapper.h"
24 #include "MsgNotificationWrapper.h"
26 #include "MsgSoundPlayer.h"
27 #include "MsgContact.h"
28 #include "MsgUtilStorage.h"
29 #include "MsgTextConvert.h"
31 #include "SmsCdmaPluginParamCodec.h"
32 #include "SmsCdmaPluginCallback.h"
33 #include "SmsCdmaPluginEventHandler.h"
34 #include "SmsCdmaPluginMain.h"
35 #include "SmsCdmaPluginSetting.h"
40 #include <tapi_common.h>
42 #include <TapiUtility.h>
43 #include <ITapiNetText.h>
45 #include <ITapiModem.h>
48 extern struct tapi_handle *pTapiHandle;
50 /*==================================================================================================
51 IMPLEMENTATION OF SmsPluginSetting - Member Functions
52 ==================================================================================================*/
53 SmsPluginSetting* SmsPluginSetting::pInstance = NULL;
56 SmsPluginSetting::SmsPluginSetting()
58 /* Initialize member variables */
59 memset(&cbOpt, 0x00, sizeof(MSG_CBMSG_OPT_S));
60 memset(&meImei, 0x00, sizeof(meImei));
63 bUpdateVoicemailByMdn = false;
67 SmsPluginSetting::~SmsPluginSetting()
72 SmsPluginSetting* SmsPluginSetting::instance()
75 pInstance = new SmsPluginSetting();
81 void* SmsPluginSetting::initSimInfo(void *data)
85 int tapiRet = TAPI_API_SUCCESS;
89 memset(imsi, 0x00, sizeof(imsi));
92 TelSimImsiInfo_t imsiInfo;
93 memset(&imsiInfo, 0x00, sizeof(TelSimImsiInfo_t));
95 tapiRet = tel_get_sim_imsi(pTapiHandle, &imsiInfo);
97 if (tapiRet == TAPI_API_SUCCESS) {
98 MSG_SEC_DEBUG("tel_get_sim_imsi() Success - MCC [%s], MNC [%s], MSIN [%s]", imsiInfo.szMcc, imsiInfo.szMnc, imsiInfo.szMsin);
99 snprintf(imsi, sizeof(imsi), "%03d%03d%s", atoi(imsiInfo.szMcc), atoi(imsiInfo.szMnc), imsiInfo.szMsin);
100 MSG_SEC_DEBUG("IMSI [%s]", imsi);
102 MSG_DEBUG("tel_get_sim_imsi() Error![%d]", tapiRet);
105 MsgSettingSetString(MSG_SIM_IMSI, imsi);
107 instance()->updateSimStatus();
114 void SmsPluginSetting::updateSimStatus()
119 MSG_DEBUG("pTapiHandle is NULL.");
124 int tapiRet = TAPI_API_SUCCESS;
126 tapiRet = tel_check_sms_device_status(pTapiHandle, &status);
128 if (tapiRet != TAPI_API_SUCCESS) {
129 MSG_DEBUG("tel_check_sms_device_status() Error! [%d], Status [%d]", tapiRet, status);
133 if (status == 1 || status == 2) {
134 MSG_DEBUG("Device Is Ready, status = %d", status);
135 SmsPluginEventHandler::instance()->setNeedInitConfig(false);
136 } else if (status == 0) {
137 MSG_DEBUG("Device Is Not Ready.. Waiting For Ready Callback");
139 if (SmsPluginEventHandler::instance()->getDeviceStatus() == true) {
140 MSG_DEBUG("Device Is Ready");
142 MSG_DEBUG("Device Is Not Ready.");
147 /* init config data. */
156 void SmsPluginSetting::setSimChangeStatus()
162 if (pthread_create(&thd, NULL, &initSimInfo, NULL) < 0) {
163 MSG_DEBUG("pthread_create() error");
172 void SmsPluginSetting::initConfigData()
176 msg_error_t err = MSG_SUCCESS;
177 char keyName[MAX_VCONFKEY_NAME_LEN];
180 /*==================== CB configuration ====================*/
182 if (simStatus != MSG_SIM_STATUS_NOT_FOUND) {
183 MSG_DEBUG("simStatus == [%d]", simStatus);
185 MSG_CBMSG_OPT_S cbMsgOpt = {0, };
187 if (getCbConfig(&cbMsgOpt) == true) {
188 err = addCbOpt(&cbMsgOpt);
190 if (err == MSG_SUCCESS) {
191 MSG_DEBUG("######## Add CB Option Success !!! #######");
192 MSG_SETTING_S cbSetting;
193 cbSetting.type = MSG_CBMSG_OPT;
194 getCbOpt(&cbSetting);
195 setCbConfig(&(cbSetting.option.cbMsgOpt));
197 MSG_DEBUG("######## Add CB Option Fail !!! return : %d #######", err);
200 MSG_DEBUG("######## getCbConfig Fail !!! #######");
203 /*==================== MSISDN update ====================*/
204 if (getMsisdnInfo() == true) {
205 MSG_DEBUG("######## getMsisdnInfo Success !!! #######");
207 MSG_DEBUG("######## getMsisdnInfo Fail !!! #######");
210 /*==================== Default Voice mail Setting ====================*/
211 MSG_DEBUG("Voicemail Default Number is NULL");
212 memset(keyName, 0x00, sizeof(keyName));
213 snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_NUMBER, sim_idx);
214 if (MsgSettingSetString(keyName, VOICEMAIL_DEFAULT_NUMBER) != MSG_SUCCESS)
215 MSG_DEBUG("Error to set config data [%s]", keyName);
217 memset(keyName, 0x00, sizeof(keyName));
218 snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_NUMBER, sim_idx);
220 memset(keyName, 0x00, sizeof(keyName));
221 snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_ALPHA_ID, sim_idx);
222 if (MsgSettingSetString(keyName, VOICEMAIL_DEFAULT_ALPHA_ID) != MSG_SUCCESS)
223 MSG_DEBUG("Error to set config data [%s]", keyName);
229 void SmsPluginSetting::SimRefreshCb()
233 if (pthread_create(&thd, NULL, &init_config_data, NULL) < 0) {
234 MSG_DEBUG("pthread_create() error");
241 void* SmsPluginSetting::init_config_data(void *data)
243 instance()->initConfigData();
248 void SmsPluginSetting::setConfigData(const MSG_SETTING_S *pSetting)
250 MSG_DEBUG("Setting Type : [%d]", pSetting->type);
252 switch (pSetting->type) {
254 case MSG_SMS_SENDOPT :
255 setNetworkMode(&pSetting->option.smsSendOpt);
258 setParamList(&pSetting->option.smscList);
261 case MSG_VOICEMAIL_OPT:
262 setVoiceMailInfo(&pSetting->option.voiceMailOpt);
266 setCbConfig(&pSetting->option.cbMsgOpt);
269 THROW(MsgException::SMS_PLG_ERROR, "The Setting type is not supported. [%d]", pSetting->type);
275 void SmsPluginSetting::getConfigData(MSG_SETTING_S *pSetting)
277 MSG_DEBUG("Setting Type : [%d]", pSetting->type);
279 switch (pSetting->type) {
282 getParamList(&pSetting->option.smscList);
286 getCbConfig(&pSetting->option.cbMsgOpt);
290 THROW(MsgException::SMS_PLG_ERROR, "The Setting type is not supported. [%d]", pSetting->type);
296 msg_error_t SmsPluginSetting::addCbOpt(MSG_CBMSG_OPT_S *pCbOpt)
298 msg_error_t err = MSG_SUCCESS;
300 /* MSG_DEBUG("Receive [%d], Max SIM Count [%d]", pCbOpt->bReceive, pCbOpt->maxSimCnt); */
302 MSG_DEBUG("Receive [%d], Channel Count [%d]", pCbOpt->bReceive, pCbOpt->channelData.channelCnt);
304 for (int i = 0; i < pCbOpt->channelData.channelCnt; i++) {
305 MSG_DEBUG("Channel Category [%d], Channel Language [%d]", pCbOpt->channelData.channelInfo[i].ctg, pCbOpt->channelData.channelInfo[i].lang);
309 /* Set Setting Data into Vconf */
310 if (MsgSettingSetBool(CB_RECEIVE, pCbOpt->bReceive) != MSG_SUCCESS) {
311 MSG_DEBUG("Error to set config data [%s]", CB_RECEIVE);
312 return MSG_ERR_SET_SETTING;
317 if (MsgSettingSetInt(CB_MAX_SIM_COUNT, pCbOpt->maxSimCnt) != MSG_SUCCESS) {
318 MSG_DEBUG("Error to set config data [%s]", CB_MAX_SIM_COUNT);
319 return MSG_ERR_SET_SETTING;
324 MsgDbHandler dbHandle;
325 err = MsgStoAddCBChannelInfo(&dbHandle, &pCbOpt->channelData);
326 if (err != MSG_SUCCESS) {
327 MSG_DEBUG("MsgStoGetCBChannelInfo is failed [%d]", err);
328 return MSG_ERR_SET_SETTING;
336 void SmsPluginSetting::getCbOpt(MSG_SETTING_S *pSetting)
338 msg_error_t err = MSG_SUCCESS;
339 MsgDbHandler dbHandle;
341 memset(&(pSetting->option.cbMsgOpt), 0x00, sizeof(MSG_CBMSG_OPT_S));
343 if (MsgSettingGetBool(CB_RECEIVE, &pSetting->option.cbMsgOpt.bReceive) != MSG_SUCCESS)
344 MSG_INFO("MsgSettingGetBool() is failed");
346 err = MsgStoGetCBChannelInfo(&dbHandle, &pSetting->option.cbMsgOpt.channelData);
347 MSG_DEBUG("MsgStoAddCBChannelInfo : err=[%d]", err);
352 for (int i = MSG_CBLANG_TYPE_ALL; i < MSG_CBLANG_TYPE_MAX; i++) {
353 memset(keyName, 0x00, sizeof(keyName));
354 snprintf(keyName, sizeof(keyName), "%s/%d", CB_LANGUAGE, i);
356 if (MsgSettingGetBool(keyName, &pSetting->option.cbMsgOpt.bLanguage[i]) != MSG_SUCCESS)
357 MSG_INFO("MsgSettingGetBool() is failed");
363 void SmsPluginSetting::setVoiceMailInfo(const MSG_VOICEMAIL_OPT_S *pVoiceOpt)
365 bUpdateVoicemailByMdn = false;
371 bool SmsPluginSetting::setCbConfig(const MSG_CBMSG_OPT_S *pCbOpt)
373 int ret = TAPI_API_SUCCESS;
376 TelSmsCbConfig_t cbConfig = {};
378 cbConfig.CBEnabled = (int)pCbOpt->bReceive;
379 cbConfig.Net3gppType = TAPI_NETTEXT_NETTYPE_3GPP2;
380 /* cbConfig.MsgIdMaxCount = pCbOpt->maxSimCnt; */
381 cbConfig.MsgIdRangeCount = pCbOpt->channelData.channelCnt;
383 for (int i = 0; i < cbConfig.MsgIdRangeCount; i++) {
384 cbConfig.MsgIDs[i].Net3gpp2.Selected = (unsigned short)pCbOpt->channelData.channelInfo[i].bActivate;
385 cbConfig.MsgIDs[i].Net3gpp2.CBCategory = (unsigned short)pCbOpt->channelData.channelInfo[i].ctg;
386 cbConfig.MsgIDs[i].Net3gpp2.CBLanguage = (unsigned short)pCbOpt->channelData.channelInfo[i].lang;
388 MSG_DEBUG("Category: %d, Language: %d", cbConfig.MsgIDs[i].Net3gpp2.CBCategory, cbConfig.MsgIDs[i].Net3gpp2.CBLanguage);
390 MSG_DEBUG("CBEnabled: %d, range_count: %d", cbConfig.CBEnabled, cbConfig.MsgIdRangeCount);
392 ret = tel_set_sms_cb_config(pTapiHandle, &cbConfig, TapiEventSetConfigData, NULL);
394 if (ret == TAPI_API_SUCCESS) {
395 MSG_DEBUG("######## tel_set_sms_cb_config() Success !!! #######");
397 MSG_DEBUG("######## tel_set_sms_cb_config() Fail !!! return : %d #######", ret);
402 if (getResultFromSim() == true) {
403 MSG_DEBUG("######## Set Cb Config was Successful !!! #######");
405 MSG_DEBUG("######## Set Cb Config was Failed !!! #######");
414 bool SmsPluginSetting::getCbConfig(MSG_CBMSG_OPT_S *pCbOpt)
416 int ret = TAPI_API_SUCCESS;
418 ret = tel_get_sms_cb_config(pTapiHandle, TapiEventGetCBConfig, NULL);
420 if (ret == TAPI_API_SUCCESS) {
421 MSG_DEBUG("######## tel_get_sms_cb_config() Success !!! #######");
423 MSG_DEBUG("######## tel_get_sms_cb_config() Fail !!! return : %d #######", ret);
427 if (getCbConfigEvent(pCbOpt) == true) {
428 MSG_DEBUG("######## Get Cb Config was Successful !!! #######");
430 MSG_DEBUG("######## Get Cb Config was Failed !!! #######");
438 void SmsPluginSetting::getMeImei(char *pImei)
441 int ret = TAPI_API_SUCCESS;
442 ret = tel_get_misc_me_imei(pTapiHandle, TapiEventGetMeImei, NULL);
444 if (ret == TAPI_API_SUCCESS) {
445 MSG_SEC_DEBUG("######## tel_get_misc_me_imei() Success !!! #######");
447 if (getResultImei(pImei) == true) {
448 MSG_SEC_DEBUG("######## Get ME IMEI was Successful !!! #######");
450 MSG_SEC_DEBUG("######## Get ME IMEI was Failed !!! #######");
453 MSG_SEC_DEBUG("######## tel_get_misc_me_imei() Fail !!! return : %d #######", ret);
458 bool SmsPluginSetting::getUpdateVoicemailByMdn()
460 return bUpdateVoicemailByMdn;
463 void SmsPluginSetting::setCbConfigEvent(const MSG_CBMSG_OPT_S *pCbOpt, bool bSuccess)
467 bTapiResult = bSuccess;
469 memset(&cbOpt, 0x00, sizeof(MSG_CBMSG_OPT_S));
471 if (bTapiResult == true) {
472 MSG_DEBUG("Success to get cb config data");
474 memcpy(&cbOpt, pCbOpt, sizeof(MSG_CBMSG_OPT_S));
483 bool SmsPluginSetting::getCbConfigEvent(MSG_CBMSG_OPT_S *pCbOpt)
490 ret = cv.timedwait(mx.pMutex(), 25);
494 if (ret == ETIMEDOUT) {
495 MSG_DEBUG("WARNING: TAPI callback TIME-OUT");
499 memset(pCbOpt, 0x00, sizeof(MSG_CBMSG_OPT_S));
501 if (bTapiResult == true) {
502 memcpy(pCbOpt, &cbOpt, sizeof(MSG_CBMSG_OPT_S));
509 void SmsPluginSetting::setResultImei(bool bResult, char *pImei)
513 bTapiResult = bResult;
515 memset(&meImei, 0x00, sizeof(meImei));
517 if (bTapiResult == true && pImei) {
518 snprintf(meImei, sizeof(meImei), "%s", pImei);
527 bool SmsPluginSetting::getResultImei(char *pImei)
533 ret = cv.timedwait(mx.pMutex(), 25);
537 if (ret == ETIMEDOUT) {
538 MSG_DEBUG("WARNING: TAPI callback TIME-OUT");
542 if (bTapiResult == true && pImei) {
543 snprintf(pImei, sizeof(meImei), "%s", meImei);
550 void SmsPluginSetting::setResultFromEvent(bool bResult)
554 bTapiResult = bResult;
562 void SmsPluginSetting::setMwiInfo(MSG_SUB_TYPE_T type, int count)
564 MSG_DEBUG("SET MWI INFO, type=[%d]", type);
565 MSG_DEBUG("SET MWI INFO, count=[%d]", count);
567 if (MsgSettingSetInt(VOICEMAIL_COUNT, count) != MSG_SUCCESS)
568 MSG_DEBUG("MsgSettingSetInt is failed!!");
571 MsgStoClearUniquenessTable();
575 if (type == MSG_MWI_VOICE_SMS)
576 MsgCleanAndResetNotification(MSG_NOTI_TYPE_VOICE_1);
577 else if (type == MSG_MWI_VOICE2_SMS)
578 MsgCleanAndResetNotification(MSG_NOTI_TYPE_VOICE_2);
581 if (bMbdnEnable == false) {
582 MSG_DEBUG("MBDN service is disable.");
590 bool SmsPluginSetting::getMsisdnInfo(void)
592 int ret = TAPI_API_SUCCESS;
594 ret = tel_get_sim_msisdn(pTapiHandle, TapiEventGetMsisdnInfo, NULL);
596 if (ret == TAPI_API_SUCCESS) {
597 MSG_DEBUG("######## tel_get_sim_msisdn() Success !!! #######");
599 MSG_DEBUG("######## tel_get_sim_msisdn() Fail !!! return : %d #######", ret);
603 if (getResultFromSim() == true) {
604 MSG_DEBUG("######## Get Sim msisdn was Successful !!! #######");
606 MSG_DEBUG("######## Get Sim msisdn was Failed !!! #######");
614 void SmsPluginSetting::setResultFromSim(bool bResult)
618 bTapiResult = bResult;
626 bool SmsPluginSetting::getResultFromSim()
632 ret = cv.timedwait(mx.pMutex(), 25);
636 if (ret == ETIMEDOUT) {
637 MSG_DEBUG("WARNING: TAPI callback TIME-OUT");