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 "MsgUtilStorage.h"
21 #include "MsgGconfWrapper.h"
22 #include "MsgException.h"
25 bool bUnknownAutoReject = false;
29 /*==================================================================================================
30 FUNCTION IMPLEMENTATION
31 ==================================================================================================*/
33 msg_error_t MsgSettingSetString(const char *pKey, const char *pSetValue)
35 if (pKey == NULL || pSetValue == NULL) {
36 MSG_DEBUG("IN Parameter is NULL");
37 return MSG_ERR_NULL_POINTER;
40 if (vconf_set_str(pKey, pSetValue) != 0) {
41 int vconf_err = vconf_get_ext_errno();
42 MSG_DEBUG("Fail to vconf_set_str with [%s], err=[%d]", pKey, vconf_err);
43 return MSG_ERR_SET_SETTING;
50 msg_error_t MsgSettingSetInt(const char *pKey, int nSetValue)
53 MSG_DEBUG("IN Parameter is NULL");
54 return MSG_ERR_NULL_POINTER;
57 if (vconf_set_int(pKey, nSetValue) != 0) {
58 int vconf_err = vconf_get_ext_errno();
59 MSG_DEBUG("Fail to vconf_set_int with [%s], err=[%d]", pKey, vconf_err);
60 return MSG_ERR_SET_SETTING;
67 msg_error_t MsgSettingSetBool(const char *pKey, bool bSetValue)
70 MSG_DEBUG("IN Parameter is NULL");
71 return MSG_ERR_NULL_POINTER;
74 if (vconf_set_bool(pKey, bSetValue) != 0) {
75 int vconf_err = vconf_get_ext_errno();
76 MSG_DEBUG("Fail to vconf_set_bool with [%s], err=[%d]", pKey, vconf_err);
77 return MSG_ERR_SET_SETTING;
84 msg_error_t MsgSettingGetString(const char *pKey, char **pVal)
87 MSG_DEBUG("IN Parameter is NULL");
88 return MSG_ERR_NULL_POINTER;
91 msg_error_t retVal = MSG_SUCCESS;
94 param = vconf_get_str(pKey);
96 int vconf_err = vconf_get_ext_errno();
97 MSG_DEBUG("Fail to vconf_get_str with [%s], err=[%d]", pKey, vconf_err);
98 if (vconf_err == VCONF_ERROR_FILE_PERM)
99 retVal = MSG_ERR_PERMISSION_DENIED;
101 retVal = MSG_ERR_UNKNOWN;
110 msg_error_t MsgSettingGetInt(const char *pKey, int *pVal)
113 MSG_DEBUG("IN Parameter is NULL");
117 msg_error_t retVal = MSG_SUCCESS;
120 if (vconf_get_int(pKey, ¶m) != 0) {
121 int vconf_err = vconf_get_ext_errno();
122 MSG_DEBUG("Fail to vconf_get_int with [%s], err=[%d]", pKey, vconf_err);
123 if (vconf_err == VCONF_ERROR_FILE_PERM)
124 retVal = MSG_ERR_PERMISSION_DENIED;
126 retVal = MSG_ERR_UNKNOWN;
135 msg_error_t MsgSettingGetBool(const char *pKey, bool *pVal)
138 MSG_DEBUG("IN Parameter is NULL");
142 msg_error_t retVal = MSG_SUCCESS;
145 if (vconf_get_bool(pKey, ¶m) != 0) {
146 int vconf_err = vconf_get_ext_errno();
147 MSG_DEBUG("Fail to vconf_get_bool with [%s], err=[%d]", pKey, vconf_err);
148 if (vconf_err == VCONF_ERROR_FILE_PERM)
149 retVal = MSG_ERR_PERMISSION_DENIED;
151 retVal = MSG_ERR_UNKNOWN;
160 msg_error_t MsgSettingHandleNewMsg(int SmsCnt, int MmsCnt)
164 MSG_DEBUG("smsCnt = %d, mmsCnt = %d ##", SmsCnt, MmsCnt);
166 /* Set Msg Count into VConf */
167 if (MsgSettingSetIndicator(SmsCnt, MmsCnt) != MSG_SUCCESS) {
168 MSG_DEBUG("MsgSettingSetIndicator() FAILED");
169 return MSG_ERR_SET_SETTING;
173 if (SmsCnt == 0 && MmsCnt == 0) {
174 MSG_DEBUG("No New Message.");
176 MSG_DEBUG("New Message.");
178 bool bNotification = true;
180 if (MsgSettingGetBool(MSG_SETTING_NOTIFICATION, &bNotification) != MSG_SUCCESS) {
181 MSG_DEBUG("MsgSettingGetBool is failed.");
195 msg_error_t MsgSettingSetIndicator(int SmsCnt, int MmsCnt)
197 if (MsgSettingSetInt(VCONFKEY_MESSAGE_RECV_SMS_STATE, SmsCnt) != 0)
198 return MSG_ERR_SET_SETTING;
199 if (MsgSettingSetInt(VCONFKEY_MESSAGE_RECV_MMS_STATE, MmsCnt) != 0)
200 return MSG_ERR_SET_SETTING;
206 int MsgSettingGetAutoReject()
211 bool MsgSettingGetUnknownAutoReject()
213 return bUnknownAutoReject;
216 msg_error_t MsgSettingRegVconfCBCommon(const char *pKey, _vconf_change_cb pCb)
218 msg_error_t err = MSG_SUCCESS;
220 if (vconf_notify_key_changed(pKey, pCb, NULL) != 0) {
221 int vconf_err = vconf_get_ext_errno();
222 MSG_DEBUG("Fail to vconf_notify_key_changed with [%s], err=[%d]", pKey, vconf_err);
223 if (vconf_err == VCONF_ERROR_FILE_PERM)
224 err = MSG_ERR_PERMISSION_DENIED;
226 err = MSG_ERR_UNKNOWN;
228 MSG_DEBUG("Success to regist vconf CB with [%s]", pKey);
234 msg_error_t MsgSettingRemoveVconfCBCommon(const char *pKey, _vconf_change_cb pCb)
236 msg_error_t err = MSG_SUCCESS;
238 if (vconf_ignore_key_changed(pKey, pCb) != 0) {
239 int vconf_err = vconf_get_ext_errno();
240 MSG_DEBUG("Fail to vconf_ignore_key_changed [%s], err=[%d]", pKey, vconf_err);
241 if (vconf_err == VCONF_ERROR_FILE_PERM)
242 err = MSG_ERR_PERMISSION_DENIED;
244 err = MSG_ERR_UNKNOWN;
246 MSG_DEBUG("Success to remove vconf CB with [%s]", pKey);