Increase memory limit
[platform/core/messaging/msg-service.git] / framework / MsgDPMUtils.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15 */
16
17 /*==================================================================================================
18                                          INCLUDE FILES
19 ==================================================================================================*/
20 #include "MsgDebug.h"
21 #include "MsgStorageHandler.h"
22 #include "MsgUtilFunction.h"
23 #include "MsgDPMUtils.h"
24
25 #include <dpm/restriction.h>
26
27 device_policy_manager_h dpm_handle = NULL;
28 int dpm_sms_callback_id = 0;
29 int dpm_mms_callback_id = 0;
30
31 /*==================================================================================================
32                                      FUNCTION IMPLEMENTATION
33 ==================================================================================================*/
34
35 static void dpm_sms_policy_changed_callback(const char* name, const char* object, void *user_data)
36 {
37         MSG_INFO("dpm_sms_policy_changed_callback called. name [%s] object [%s]", name, object);
38
39         int ret = 0;
40         int state = 0;
41
42         ret = dpm_restriction_get_messaging_state(dpm_handle, "sim1", &state);
43         if (ret != DPM_ERROR_NONE) {
44                 MSG_ERR("dpm_restriction_get_messaging_state failed [%d]", ret);
45                 return;
46         }
47
48         msg_set_dpm_policy(MSG_SMS_TYPE, state);
49
50         if (state == 1) {
51                 MsgStoUpdateDPMRestrictedStatus(MSG_SMS_TYPE);
52                 /* temporal */
53                 MsgStoUpdateDPMRestrictedStatus(MSG_MMS_TYPE);
54         }
55 }
56
57 #if 0
58 static void dpm_mms_policy_changed_callback(const char* name, const char* object, void *user_data)
59 {
60         MSG_INFO("dpm_mms_policy_changed_callback called. name [%s] object [%s]", name, object);
61
62         int ret = 0;
63         int state = 0;
64
65         ret = dpm_restriction_get_messaging_state(dpm_handle, &dpm_policy_enable[MSG_MMS_TYPE]);
66         if (ret != DPM_ERROR_NONE) {
67                 MSG_ERR("dpm_restriction_get_messaging_state failed [%d]", ret);
68                 return;
69         }
70
71         msg_set_dpm_policy(MSG_MMS_TYPE, state);
72
73         if (state == 1)
74                 MsgStoUpdateDPMRestrictedStatus(MSG_MMS_TYPE);
75 }
76 #endif
77
78 void __get_dpm_policy()
79 {
80         int ret = 0;
81         int state = 0;
82
83         ret = dpm_restriction_get_messaging_state(dpm_handle, "sim1", &state);
84         if (ret != DPM_ERROR_NONE) {
85                 MSG_ERR("dpm_restriction_get_messaging_state failed [%d]", ret);
86                 return;
87         }
88
89         MSG_DEBUG("sms policy [%d]", state);
90         msg_set_dpm_policy(MSG_SMS_TYPE, state);
91 //      MSG_DEBUG("mms policy [%d]", dpm_policy_enable[MSG_MMS_TYPE]);
92
93         ret = dpm_add_policy_changed_cb(dpm_handle, "messaging", dpm_sms_policy_changed_callback, NULL, &dpm_sms_callback_id);
94         if (ret != DPM_ERROR_NONE) {
95                 MSG_ERR("dpm_add_policy_changed_cb failed [%d]", ret);
96                 return;
97         }
98 }
99
100 void msg_init_dpm_policy()
101 {
102         MSG_BEGIN();
103
104         int cnt = 5;
105         while (cnt--) {
106                 dpm_handle = dpm_manager_create();
107                 if (dpm_handle == NULL) {
108                         MSG_ERR("dpm_manager_create() failed");
109                 } else {
110                         MSG_DEBUG("dpm_manager_create() success");
111                         __get_dpm_policy();
112                         break;
113                 }
114
115                 sleep(1);
116         }
117
118         MSG_END();
119 }
120
121
122 void msg_deinit_dpm_policy()
123 {
124         if (dpm_sms_callback_id)
125                 dpm_remove_policy_changed_cb(dpm_handle, dpm_sms_callback_id);
126
127         if (dpm_mms_callback_id)
128                 dpm_remove_policy_changed_cb(dpm_handle, dpm_mms_callback_id);
129
130         if (dpm_handle)
131                 dpm_manager_destroy(dpm_handle);
132 }