2 * Copyright 2012-2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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 "MsgUtilFile.h"
21 #include "MsgContact.h"
22 #include "MsgUtilStorage.h"
23 #include "MsgGconfWrapper.h"
24 #include "MsgSqliteWrapper.h"
25 #include "MsgPluginManager.h"
26 #include "MsgStorageHandler.h"
31 /*==================================================================================================
33 ==================================================================================================*/
34 extern MsgDbHandler dbHandle;
37 /*==================================================================================================
38 FUNCTION IMPLEMENTATION
39 ==================================================================================================*/
40 msg_error_t MsgInitSimMessage(MSG_SIM_STATUS_T SimStatus)
42 MSG_DEBUG("Start SIM Message Initialization");
44 msg_error_t err = MSG_SUCCESS;
46 // Set SIM count of vconf to 0
47 if (MsgSettingSetInt(SIM_USED_COUNT, 0) != MSG_SUCCESS) {
48 MSG_DEBUG("Error to set config data [%s]", SIM_USED_COUNT);
51 if (MsgSettingSetInt(SIM_TOTAL_COUNT, 0) != MSG_SUCCESS) {
52 MSG_DEBUG("Error to set config data [%s]", SIM_TOTAL_COUNT);
55 if (SimStatus != MSG_SIM_STATUS_NOT_FOUND) {
56 MSG_MAIN_TYPE_T mainType = MSG_SMS_TYPE;
57 MsgPlugin* plg = MsgPluginManager::instance()->getPlugin(mainType);
60 MSG_DEBUG("No plugin for %d type", mainType);
61 return MSG_ERR_INVALID_PLUGIN_HANDLE;
65 MSG_DEBUG(" ** SIM is available - status : [%d] ** ", SimStatus);
67 err = plg->initSimMessage();
74 msg_error_t MsgStoClearSimMessageInDB()
76 msg_error_t err = MSG_SUCCESS;
78 char sqlQuery[MAX_QUERY_LEN+1];
80 queue<msg_thread_id_t> threadList;
82 // Get Address ID of SIM Message
83 memset(sqlQuery, 0x00, sizeof(sqlQuery));
85 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT DISTINCT(CONV_ID) FROM %s WHERE STORAGE_ID = %d",
86 MSGFW_MESSAGE_TABLE_NAME, MSG_STORAGE_SIM);
90 err = dbHandle.getTable(sqlQuery, &rowCnt);
92 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
93 MSG_DEBUG("sql query is %s.", sqlQuery);
100 dbHandle.freeTable();
104 for (int i = 1; i <= rowCnt; i++)
106 MSG_DEBUG("thread ID : %d", dbHandle.getColumnToInt(i));
107 threadList.push((msg_thread_id_t)dbHandle.getColumnToInt(i));
110 dbHandle.freeTable();
112 const char* tableList[] = {MSGFW_SMS_SENDOPT_TABLE_NAME, MSGFW_SIM_MSG_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME};
114 int listCnt = sizeof(tableList)/sizeof(char*);
116 dbHandle.beginTrans();
118 for (int i = 0; i < listCnt; i++)
120 memset(sqlQuery, 0x00, sizeof(sqlQuery));
122 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID IN \
123 (SELECT MSG_ID FROM %s WHERE STORAGE_ID = %d);",
124 tableList[i], MSGFW_MESSAGE_TABLE_NAME, MSG_STORAGE_SIM);
126 // Delete SIM Message in tables
127 if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
128 dbHandle.endTrans(false);
129 return MSG_ERR_DB_EXEC;
133 // Clear Conversation table
134 if (MsgStoClearConversationTable(&dbHandle) != MSG_SUCCESS) {
135 dbHandle.endTrans(false);
136 return MSG_ERR_DB_EXEC;
140 while (!threadList.empty())
142 err = MsgStoUpdateConversation(&dbHandle, threadList.front());
146 if (err != MSG_SUCCESS) {
147 dbHandle.endTrans(false);
152 dbHandle.endTrans(true);