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.
20 #include "MsgException.h"
21 #include "MsgGconfWrapper.h"
24 #include "SmsPluginTransport.h"
25 #include "SmsPluginSimMsg.h"
26 #include "SmsPluginStorage.h"
27 #include "SmsPluginSetting.h"
28 #include "SmsPluginCallback.h"
29 #include "SmsPluginEventHandler.h"
30 #include "SmsPluginUAManager.h"
31 #include "SmsPluginMain.h"
32 #include "SmsPluginDSHandler.h"
36 #include <tapi_common.h>
38 #include <TapiUtility.h>
40 #include <ITapiNetText.h>
43 #define BUS_NAME "org.tizen.system.deviced"
44 #define PATH_NAME "/Org/Tizen/System/DeviceD/Lowmem"
45 #define INTERFACE_NAME BUS_NAME".lowmem"
46 #define MEMBER_NAME "Full"
48 GDBusConnection *gdbus_conn = NULL;
49 GDBusProxy *gdbus_proxy = NULL;
52 bool isMemAvailable = true;
58 void MsgResourceMonitorInit(void);
59 void MsgResourceMonitorDeinit(void);
61 /*==================================================================================================
62 FUNCTION IMPLEMENTATION
63 ==================================================================================================*/
65 msg_error_t MsgPlgCreateHandle(MSG_PLUGIN_HANDLER_S *pPluginHandle)
67 if (pPluginHandle == NULL) {
68 MSG_DEBUG("SMS plugin: create handler error ");
69 return MSG_ERR_NULL_POINTER;
71 pPluginHandle->pfInitialize = SmsPlgInitialize;
72 pPluginHandle->pfFinalize = SmsPlgFinalize;
73 pPluginHandle->pfRegisterListener = SmsPlgRegisterListener;
74 pPluginHandle->pfSubmitRequest = SmsPlgSubmitRequest;
75 pPluginHandle->pfSaveSimMessage = SmsPlgSaveSimMessage;
76 pPluginHandle->pfDeleteSimMessage = SmsPlgDeleteSimMessage;
77 pPluginHandle->pfSetReadStatus = SmsPlgSetReadStatus;
78 pPluginHandle->pfSetMemoryStatus = SmsPlgSetMemoryStatus;
79 pPluginHandle->pfSetConfigData = SmsPlgSetConfigData;
80 pPluginHandle->pfGetConfigData = SmsPlgGetConfigData;
81 pPluginHandle->pfAddMessage = SmsPlgAddMessage;
82 pPluginHandle->pfGetDefaultNetworkSimId = SmsPlgGetDefaultNetworkSimId;
84 MSG_DEBUG("SMS plugin: create handler OK");
85 MSG_DEBUG("SMS plugin %p", pPluginHandle);
92 msg_error_t MsgPlgDestroyHandle(MSG_PLUGIN_HANDLER_S *pPluginHandle)
94 if (pPluginHandle != NULL) {
99 MSG_DEBUG("SMS plugin: destory handler OK");
105 msg_error_t SmsPlgInitialize()
111 for (int i = 0; i < 100; i++) {
112 if (MsgSettingGetBool(VCONFKEY_TELEPHONY_READY, &bReady) != MSG_SUCCESS)
113 MSG_INFO("MsgSettingGetBool() is failed");
115 MSG_DEBUG("Get VCONFKEY_TELEPHONY_READY [%d].", bReady ? 1 : 0);
124 MSG_ERR("Fail to wait telephony init complete.");
125 return MSG_ERR_PLUGIN_TAPIINIT;
129 char keyName[MAX_VCONFKEY_NAME_LEN];
131 SmsPluginDSHandler::instance()->initTelHandle();
132 simCnt = SmsPluginDSHandler::instance()->getTelHandleCount();
134 MSG_DEBUG("simCnt [%d]", simCnt);
136 for (int i = 1; i <= simCnt; i++) {
137 memset(keyName, 0x00, sizeof(keyName));
138 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_CHANGED, i);
139 MSG_DEBUG("set MSG_SIM_CHANGED to MSG_SIM_STATUS_NOT_FOUND.");
140 if (MsgSettingSetInt(keyName, MSG_SIM_STATUS_NOT_FOUND) != MSG_SUCCESS)
141 MSG_DEBUG("MsgSettingSetInt is failed!!");
144 SmsPluginCallback::instance()->registerEvent();
146 for (int i = 1; i <= simCnt; ++i) {
148 handle = SmsPluginDSHandler::instance()->getTelHandle(i);
149 SmsPluginSetting::instance()->setSimChangeStatus(handle, true);
152 /* set resource monitor */
153 MsgResourceMonitorInit();
161 msg_error_t SmsPlgFinalize()
165 MsgResourceMonitorDeinit();
167 SmsPluginCallback::instance()->deRegisterEvent();
169 SmsPluginDSHandler::instance()->deinitTelHandle();
177 msg_error_t SmsPlgRegisterListener(MSG_PLUGIN_LISTENER_S *pListener)
181 SmsPluginEventHandler::instance()->registerListener(pListener);
189 msg_error_t SmsPlgSubmitRequest(MSG_REQUEST_INFO_S *pReqInfo)
191 msg_error_t err = MSG_SUCCESS;
193 /* Add Submit SMS into DB */
194 if (pReqInfo->msgInfo.msgId == 0) {
195 if (pReqInfo->msgInfo.msgPort.valid == false) {
196 err = SmsPluginStorage::instance()->checkMessage(&(pReqInfo->msgInfo));
198 if (err != MSG_SUCCESS) {
199 MSG_DEBUG("######## checkMessage Fail !! [err=%d]", err);
200 return MSG_ERR_PLUGIN_STORAGE;
203 err = SmsPluginStorage::instance()->addSmsMessage(&(pReqInfo->msgInfo));
204 if (err != MSG_SUCCESS) {
205 MSG_DEBUG("######## addSmsMessage Fail !! [err=%d]", err);
206 return MSG_ERR_PLUGIN_STORAGE;
209 if (SmsPluginStorage::instance()->addSmsSendOption(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo)) != MSG_SUCCESS) {
210 MSG_DEBUG("######## addSmsSendOption Fail !!");
211 return MSG_ERR_PLUGIN_STORAGE;
216 /* Check SIM is present or not */
217 char keyName[MAX_VCONFKEY_NAME_LEN] = {0, };
218 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_CHANGED, pReqInfo->msgInfo.sim_idx);
220 if (MsgSettingGetInt(keyName, &tmpValue) != MSG_SUCCESS) {
221 MSG_INFO("MsgSettingGetInt() is failed");
223 MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)tmpValue;
225 if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
226 MSG_DEBUG("SIM is not present..");
228 /* Update Msg Status */
229 if (pReqInfo->msgInfo.msgPort.valid == false)
230 SmsPluginStorage::instance()->updateSentMsg(&(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
232 return MSG_ERR_NO_SIM;
235 SMS_REQUEST_INFO_S *request = NULL;
237 request = (SMS_REQUEST_INFO_S *)calloc(1, sizeof(SMS_REQUEST_INFO_S));
239 if (request != NULL) {
240 request->reqId = pReqInfo->reqId;
242 memcpy(&(request->msgInfo), &(pReqInfo->msgInfo), sizeof(MSG_MESSAGE_INFO_S));
243 memcpy(&(request->sendOptInfo), &(pReqInfo->sendOptInfo), sizeof(MSG_SENDINGOPT_INFO_S));
245 /* Add Request into Queue and Start UA Manger */
246 SmsPluginUAManager::instance()->addReqEntity(request);
256 msg_error_t SmsPlgSaveSimMessage(const MSG_MESSAGE_INFO_S *pMsgInfo, SMS_SIM_ID_LIST_S *pSimIdList)
258 /* Check SIM is present or not */
259 char keyName[MAX_VCONFKEY_NAME_LEN];
260 memset(keyName, 0x00, sizeof(keyName));
261 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_CHANGED, pMsgInfo->sim_idx);
263 if (MsgSettingGetInt(keyName, &tmpValue) != MSG_SUCCESS) {
264 MSG_INFO("MsgSettingGetInt() is failed");
266 MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)tmpValue;
268 if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
269 MSG_DEBUG("SIM is not present..");
270 return MSG_ERR_NO_SIM;
273 msg_error_t err = MSG_SUCCESS;
276 err = SmsPluginSimMsg::instance()->saveSimMessage(pMsgInfo, pSimIdList);
277 } catch (MsgException& e) {
278 MSG_FATAL("%s", e.what());
279 return MSG_ERR_PLUGIN_STORAGE;
280 } catch (exception& e) {
281 MSG_FATAL("%s", e.what());
282 return MSG_ERR_PLUGIN_STORAGE;
289 msg_error_t SmsPlgDeleteSimMessage(msg_sim_slot_id_t sim_idx, msg_sim_id_t SimMsgId)
291 /* Check SIM is present or not */
292 char keyName[MAX_VCONFKEY_NAME_LEN] = {0, };
293 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_CHANGED, sim_idx);
295 if (MsgSettingGetInt(keyName, &tmpValue) != MSG_SUCCESS) {
296 MSG_INFO("MsgSettingGetInt() is failed");
298 MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)tmpValue;
300 if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
301 MSG_DEBUG("SIM is not present..");
302 return MSG_ERR_NO_SIM;
306 SmsPluginSimMsg::instance()->deleteSimMessage(sim_idx, SimMsgId);
307 } catch (MsgException& e) {
308 MSG_FATAL("%s", e.what());
309 return MSG_ERR_PLUGIN_STORAGE;
310 } catch (exception& e) {
311 MSG_FATAL("%s", e.what());
312 return MSG_ERR_PLUGIN_STORAGE;
319 msg_error_t SmsPlgSetReadStatus(msg_sim_slot_id_t sim_idx, msg_sim_id_t SimMsgId)
321 /* Check SIM is present or not */
322 char keyName[MAX_VCONFKEY_NAME_LEN] = {0, };
323 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_CHANGED, sim_idx);
325 if (MsgSettingGetInt(keyName, &tmpValue) != MSG_SUCCESS) {
326 MSG_INFO("MsgSettingGetInt() is failed");
328 MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)tmpValue;
330 if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
331 MSG_DEBUG("SIM is not present..");
332 return MSG_ERR_NO_SIM;
336 SmsPluginSimMsg::instance()->setReadStatus(sim_idx, SimMsgId);
337 } catch (MsgException& e) {
338 MSG_FATAL("%s", e.what());
339 return MSG_ERR_PLUGIN_STORAGE;
340 } catch (exception& e) {
341 MSG_FATAL("%s", e.what());
342 return MSG_ERR_PLUGIN_STORAGE;
349 msg_error_t SmsPlgSetMemoryStatus(msg_sim_slot_id_t simIndex, msg_error_t Error)
351 /* Check SIM is present or not */
352 char keyName[MAX_VCONFKEY_NAME_LEN];
354 memset(keyName, 0x00, sizeof(keyName));
355 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_CHANGED, simIndex);
357 if (MsgSettingGetInt(keyName, &tmpValue) != MSG_SUCCESS) {
358 MSG_INFO("MsgSettingGetInt() is failed");
360 MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)tmpValue;
362 if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
363 MSG_DEBUG("SIM is not present..");
364 return MSG_ERR_NO_SIM;
367 int tapiRet = TAPI_API_SUCCESS;
368 int status = TAPI_NETTEXT_PDA_MEMORY_STATUS_AVAILABLE;
370 if (Error == MSG_ERR_SIM_STORAGE_FULL || Error == MSG_ERR_MESSAGE_COUNT_FULL)
371 status = TAPI_NETTEXT_PDA_MEMORY_STATUS_FULL;
373 MSG_DEBUG("Set Status : [%d]", status);
375 TapiHandle *handle = SmsPluginDSHandler::instance()->getTelHandle(simIndex);
377 tapiRet = tel_set_sms_memory_status(handle, status, TapiEventMemoryStatus, NULL);
379 if (tapiRet == TAPI_API_SUCCESS)
380 MSG_DEBUG("######## tel_set_sms_memory_status() Success !!! #######");
382 MSG_DEBUG("######## tel_set_sms_memory_status() Success !!! return : [%d] #######", tapiRet);
388 msg_error_t SmsPlgSetConfigData(const MSG_SETTING_S *pSetting)
391 SmsPluginSetting::instance()->setConfigData(pSetting);
392 } catch (MsgException& e) {
393 MSG_FATAL("%s", e.what());
394 return MSG_ERR_PLUGIN_SETTING;
395 } catch (exception& e) {
396 MSG_FATAL("%s", e.what());
397 return MSG_ERR_PLUGIN_SETTING;
404 msg_error_t SmsPlgGetConfigData(MSG_SETTING_S *pSetting)
407 SmsPluginSetting::instance()->getConfigData(pSetting);
408 } catch (MsgException& e) {
409 MSG_FATAL("%s", e.what());
410 return MSG_ERR_PLUGIN_SETTING;
411 } catch (exception& e) {
412 MSG_FATAL("%s", e.what());
413 return MSG_ERR_PLUGIN_SETTING;
420 msg_error_t SmsPlgAddMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendOptInfo, char* pFileData)
422 int *simIdList = (int*)pFileData;
424 SmsPluginStorage::instance()->addSmsSendOption(pMsgInfo, pSendOptInfo);
426 SmsPluginStorage::instance()->addSimMessage(pMsgInfo, simIdList);
427 } catch (MsgException& e) {
428 MSG_FATAL("%s", e.what());
429 return MSG_ERR_PLUGIN_SETTING;
430 } catch (exception& e) {
431 MSG_FATAL("%s", e.what());
432 return MSG_ERR_PLUGIN_SETTING;
439 msg_error_t SmsPlgGetDefaultNetworkSimId(int *simId)
442 SmsPluginDSHandler::instance()->getDefaultNetworkSimId(simId);
443 } catch (MsgException& e) {
444 MSG_FATAL("%s", e.what());
445 return MSG_ERR_PLUGIN_SETTING;
446 } catch (exception& e) {
447 MSG_FATAL("%s", e.what());
448 return MSG_ERR_PLUGIN_SETTING;
455 static void on_change_received(GDBusConnection *connection, const gchar *sender_name,
456 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
457 GVariant *parameters, gpointer user_data)
459 MSG_DEBUG("signal_name = [%s]", signal_name);
461 if (g_strcmp0(signal_name, MEMBER_NAME) == 0) {
463 g_variant_get(parameters, "(i)", &memStatus);
464 MSG_DEBUG("memStatus = [%d]", memStatus);
465 if (memStatus == 0) {
466 int sim_count = SmsPluginDSHandler::instance()->getTelHandleCount();
468 for (int i = 0; i < sim_count; i++) {
469 SmsPlgSetMemoryStatus(i, MSG_SUCCESS);
475 void MsgResourceMonitorInit(void)
479 GError *error = NULL;
482 g_object_unref(gdbus_conn);
486 gdbus_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
488 MSG_FATAL("g_bus_get_sync() failed : %s", error->message);
495 g_object_unref(gdbus_proxy);
499 gdbus_proxy = g_dbus_proxy_new_sync(gdbus_conn, G_DBUS_PROXY_FLAGS_NONE,
500 NULL, BUS_NAME, PATH_NAME, INTERFACE_NAME, NULL, &error);
502 MSG_FATAL("g_dbus_proxy_new_sync() failed : %s", error->message);
508 subs_id = g_dbus_connection_signal_subscribe(gdbus_conn, NULL,
509 INTERFACE_NAME, MEMBER_NAME, PATH_NAME,
510 NULL, G_DBUS_SIGNAL_FLAGS_NONE,
518 g_object_unref(gdbus_conn);
523 g_object_unref(gdbus_proxy);
532 void MsgResourceMonitorDeinit(void)
537 g_dbus_connection_signal_unsubscribe(gdbus_conn, subs_id);
542 g_object_unref(gdbus_conn);
547 g_object_unref(gdbus_proxy);