2 * Copyright (c) 2014 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.
19 #include "MsgException.h"
20 #include "SmsPluginDSHandler.h"
21 #include "MsgGconfWrapper.h"
24 #include <tapi_common.h>
25 #include <TelNetwork.h>
26 #include <ITapiNetwork.h>
28 #include <telephony_common.h>
29 #include <telephony_sim.h>
32 /*==================================================================================================
33 IMPLEMENTATION OF SmsPluginCbMsgHandler - Member Functions
34 ==================================================================================================*/
35 SmsPluginDSHandler* SmsPluginDSHandler::pInstance = NULL;
38 SmsPluginDSHandler::SmsPluginDSHandler()
41 memset(&handle_list, 0x00, sizeof(handle_list));
45 SmsPluginDSHandler::~SmsPluginDSHandler()
50 SmsPluginDSHandler* SmsPluginDSHandler::instance()
53 pInstance = new SmsPluginDSHandler();
58 int SmsPluginDSHandler::initTelHandle()
61 cp_list = tel_get_cp_name_list();
64 MSG_FATAL("tel_get_cp_name_list returns null");
68 while (cp_list[cnt] && cnt < MAX_TELEPHONY_HANDLE_CNT) {
69 MSG_SEC_INFO("cp_list[%d]:[%s]", cnt, cp_list[cnt]);
70 handle_list.handle[cnt]= tel_init(cp_list[cnt]);
77 handle_list.count = cnt;
81 void SmsPluginDSHandler::deinitTelHandle()
85 for (int i = 0; i < handle_list.count; i++) {
86 ret = tel_deinit(handle_list.handle[i]);
87 MSG_DEBUG("tel_deinit ret=[%d]", ret);
88 handle_list.handle[i] = NULL;
91 handle_list.count = 0;
97 TapiHandle *SmsPluginDSHandler::getTelHandle(int sim_idx)
99 if (sim_idx > 0 && sim_idx < MAX_TELEPHONY_HANDLE_CNT) {
100 return handle_list.handle[sim_idx-1];
103 if (MsgSettingGetInt(VCONFKEY_TELEPHONY_SIM_SLOT, &SIM_Status) != MSG_SUCCESS) {
104 MSG_INFO("MsgSettingGetInt() is failed");
106 if (SIM_Status == 1) {
107 return handle_list.handle[0];
110 if (MsgSettingGetInt(VCONFKEY_TELEPHONY_SIM_SLOT2, &SIM_Status) != MSG_SUCCESS) {
111 MSG_INFO("MsgSettingGetInt() is failed");
113 if (SIM_Status == 1) {
114 return handle_list.handle[1];
118 return handle_list.handle[handle_list.count - 1];
121 int SmsPluginDSHandler::getSimIndex(TapiHandle *handle)
123 for (int index = 0; index < handle_list.count; ++index) {
124 if (handle_list.handle[index] == handle)
131 void SmsPluginDSHandler::getDefaultNetworkSimId(int *simId)
133 TelNetworkDefaultDataSubs_t defaultSimId = TAPI_NETWORK_DEFAULT_DATA_SUBS_UNKNOWN;
135 int tapi_ret = TAPI_API_SUCCESS;
137 if (handle_list.count == 1) {
142 tapi_ret = tel_get_network_default_data_subscription(handle_list.handle[0], &defaultSimId);
144 MSG_INFO("Default network subscription = [SIM %d]", (int)defaultSimId+1);
146 if (tapi_ret != TAPI_API_SUCCESS) {
148 THROW(MsgException::SMS_PLG_ERROR, "######## tel_get_network_default_data_subscription Fail !!! return : %d #######", tapi_ret);
150 *simId = (int)defaultSimId + 1;
155 int SmsPluginDSHandler::getTelHandleCount()
157 return handle_list.count;
160 int SmsPluginDSHandler::getActiveSimCount()
162 int active_count = 0;
163 int sim_status = VCONFKEY_TELEPHONY_SIM_UNKNOWN;
165 if (MsgSettingGetInt(VCONFKEY_TELEPHONY_SIM_SLOT, &sim_status) != MSG_SUCCESS) {
166 MSG_INFO("MsgSettingGetInt() is failed");
168 MSG_DEBUG("sim1 status : %d", sim_status);
169 if (sim_status == VCONFKEY_TELEPHONY_SIM_INSERTED)
172 sim_status = VCONFKEY_TELEPHONY_SIM_UNKNOWN;
173 if (MsgSettingGetInt(VCONFKEY_TELEPHONY_SIM_SLOT2, &sim_status) != MSG_SUCCESS) {
174 MSG_INFO("MsgSettingGetInt() is failed");
176 MSG_DEBUG("sim2 status : %d", sim_status);
177 if (sim_status == VCONFKEY_TELEPHONY_SIM_INSERTED)
180 MSG_DEBUG("active sim count : %d", active_count);
186 int SmsPluginDSHandler::getSubscriberId(unsigned int simIndex, char **subscriber_id)
188 if (simIndex <= 0 || simIndex > (unsigned int)handle_list.count) {
189 MSG_DEBUG("Invalid SIM index");
190 return MSG_ERR_INVALID_PARAMETER;
193 int tel_ret = TELEPHONY_ERROR_NONE;
194 telephony_handle_list_s capi_tel_handle_list;
196 tel_ret = telephony_init(&capi_tel_handle_list);
197 if (tel_ret != TELEPHONY_ERROR_NONE) {
198 MSG_DEBUG("Initialize failed!!!");
199 return MSG_ERR_PLUGIN_TAPIINIT;
202 tel_ret = telephony_sim_get_subscriber_id(capi_tel_handle_list.handle[simIndex-1], subscriber_id);
203 if (tel_ret != TELEPHONY_ERROR_NONE) {
204 MSG_DEBUG("telephony_sim_get_subscriber_id() failed!!! [%d]", tel_ret);
206 MSG_DEBUG("Subscriber ID is [%s]", *subscriber_id);
209 tel_ret = telephony_deinit(&capi_tel_handle_list);
210 if (tel_ret != TELEPHONY_ERROR_NONE) {
211 MSG_DEBUG("Deinitialize failed!!!");