Tizen 2.0 Release
[framework/system/oma-dm-agent.git] / src / agent / dm-engine / lawmo / lawmo_engine.c
1 /*
2  * oma-dm-agent
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Apache License, Version 2.0 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 /*sync-agent*/
19 #include <sync_agent.h>
20
21 /*common*/
22 #include "common/dm_common.h"
23 #include "common/util/util.h"
24 #include "dm-engine/lawmo/lawmo_engine.h"
25 #include "dm-engine/dm_common_engine.h"
26 #include "mo-handler/dm_mo_common.h"
27 #include "mo-handler/dm_mo_handler.h"
28
29 #ifndef OMADM_AGENT_LOG
30 #undef LOG_TAG
31 #define LOG_TAG "LAWMO_ENGINE"
32 #endif
33
34 static DM_ERROR _lawmo_fullylock(LAWMO_Result_code * lawmo_return);
35 static DM_ERROR _lawmo_partiallylock(LAWMO_Result_code * lawmo_return);
36 static DM_ERROR _lawmo_unlock(LAWMO_Result_code * lawmo_return);
37 static DM_ERROR _lawmo_factoryreset(LAWMO_Result_code * lawmo_return);
38 static DM_ERROR _lawmo_wipe(LAWMO_Result_code * lawmo_return);
39 static DM_ERROR _vendor_dependency_lawmo_operation(char *full_path, LAWMO_Result_code * lawmo_return, int check_operation);
40
41 DM_ERROR lawmo_exec(char *full_path, char *correlator, LAWMO_Result_code * lawmo_return, int check_operation)
42 {
43
44         _DEBUG_INFO(" start\n");
45         DM_ERROR ret = DM_OK;
46
47         retvm_if((full_path) == NULL, COMMON_ERR_IS_NULL, "full_path is NULL!!");
48
49         char *result_mo_type = NULL;
50         /*LAWMO_State lawmo_state ; */
51
52         ret = get_mo_operationtype(full_path, &result_mo_type);
53         //ret = get_mo_root_path(full_path, &result_mo_type);
54         if (ret != DM_OK)
55                 goto error;
56
57         if (strcmp(result_mo_type, DM_LAWMO_OPERATIONS_FULLYLOCK_OP) == 0) {
58                 if (check_operation == NON_CHECK_OPERATION) {   //async
59                         ret = _lawmo_fullylock(lawmo_return);
60                         if (ret != DM_OK)
61                                 goto error;
62                         if ((*lawmo_return) == OPERATION_SUCCEEDED) {
63                                 ret = set_current_lawmo_state(full_path, FULLY_LOCKED);
64                                 if (ret != DM_OK)
65                                         goto error;
66                         }
67                 }
68         } else if (strcmp(result_mo_type, DM_LAWMO_OPERATIONS_PARTIALLYLOCK_OP) == 0) {
69                 if (check_operation == NON_CHECK_OPERATION) {   //async
70                         ret = _lawmo_partiallylock(lawmo_return);
71                         if (ret != DM_OK)
72                                 goto error;
73                         if ((*lawmo_return) == OPERATION_SUCCEEDED) {
74                                 ret = set_current_lawmo_state(full_path, PARTIALLY_LOCKED);
75                                 if (ret != DM_OK)
76                                         goto error;
77                         }
78                 }
79         } else if (strcmp(result_mo_type, DM_LAWMO_OPERATIONS_UNLOCK_OP) == 0) {
80                 if (check_operation == NON_CHECK_OPERATION) {   //async
81                         ret = _lawmo_unlock(lawmo_return);
82                         if (ret != DM_OK)
83                                 goto error;
84                         if ((*lawmo_return) == OPERATION_SUCCEEDED) {
85                                 ret = set_current_lawmo_state(full_path, UNLOCKED);
86                                 if (ret != DM_OK)
87                                         goto error;
88                         }
89                 }
90         } else if (strcmp(result_mo_type, DM_LAWMO_OPERATIONS_FACTORYRESET_OP) == 0) {
91                 if (check_operation == NON_CHECK_OPERATION) {   //async
92                         ret = _lawmo_factoryreset(lawmo_return);
93                         if (ret != DM_OK)
94                                 goto error;
95                 }
96         } else if (strcmp(result_mo_type, DM_LAWMO_OPERATIONS_WIPE_OP) == 0) {
97                 if (check_operation == NON_CHECK_OPERATION) {   //async
98                         ret = _lawmo_wipe(lawmo_return);
99                         if (ret != DM_OK)
100                                 goto error;
101                 }
102         } else {
103                 //1 : this is just available operation
104                 ret = _vendor_dependency_lawmo_operation(full_path, lawmo_return, check_operation);
105                 //*lawmo_return = 1200;
106                 if (ret != DM_OK)
107                         goto error;
108
109         }
110
111         str_free(&result_mo_type);
112         _DEBUG_INFO(" end\n");
113         return ret;
114  error:
115         str_free(&result_mo_type);
116         _DEBUG_INFO(" end error : %d \n", ret);
117         return ret;
118 }
119
120 /*this is oma dm spec function but this is not used slp phone.*/
121 static DM_ERROR _lawmo_fullylock(LAWMO_Result_code * lawmo_return)
122 {
123         _INNER_FUNC_ENTER;
124
125         DM_ERROR ret = DM_OK;
126
127 /*      (*lawmo_return) = OPERATION_SUCCEEDED;
128
129         sync_agent_dev_return_e error = 0;
130         //error = sync_agent_execute_dev_function(2, "full_lock", 0);
131
132         if(error == 1 ) {
133                 (*lawmo_return) = OPERATION_SUCCEEDED;
134         } else {
135                 (*lawmo_return) = FULLY_LOCK_DEVICE_FAILED;
136                 ret = FULLY_LOCK_DEVICE_FAILED;
137                 goto error;
138         }*/
139         /*this is oma dm spec function but this is not used slp phone. */
140         /*not use this function so fail return */
141         (*lawmo_return) = FULLY_LOCK_DEVICE_FAILED;
142         ret = FULLY_LOCK_DEVICE_FAILED;
143
144         _INNER_FUNC_EXIT;
145         return ret;
146
147 }
148
149 /*this is oma dm spec function but this is not used slp phone.*/
150 static DM_ERROR _lawmo_partiallylock(LAWMO_Result_code * lawmo_return)
151 {
152         _INNER_FUNC_ENTER;
153
154         DM_ERROR ret = DM_OK;
155
156 /*      (*lawmo_return) = OPERATION_SUCCEEDED;
157
158         sync_agent_dev_return_e error =0;
159         //error = sync_agent_execute_dev_function(2, "partial_lock", 0);
160
161         if(error == 1 ) {
162                 (*lawmo_return) = OPERATION_SUCCEEDED;
163         } else {
164                 (*lawmo_return) = PARTIALLY_LOCK_DEVICE_FAILED;
165                 ret = PARTIALLY_LOCK_DEVICE_FAILED;
166                 goto error;
167         }*/
168
169         /*not use this function so fail return */
170         (*lawmo_return) = PARTIALLY_LOCK_DEVICE_FAILED;
171         ret = PARTIALLY_LOCK_DEVICE_FAILED;
172
173         _INNER_FUNC_EXIT;
174         return ret;
175
176 }
177
178 /*this is oma dm spec function but this is not used slp phone.*/
179 static DM_ERROR _lawmo_unlock(LAWMO_Result_code * lawmo_return)
180 {
181         _INNER_FUNC_ENTER;
182         DM_ERROR ret = DM_OK;
183
184 /*      (*lawmo_return) = OPERATION_SUCCEEDED;
185
186         sync_agent_dev_return_e error = 0;
187         //error = sync_agent_execute_dev_function(2, "unlock", 0);
188
189         if(error == 1) {
190                 (*lawmo_return) = OPERATION_SUCCEEDED;
191         } else {
192                 (*lawmo_return) = UNLOCK_DEVICE_FAILED;
193                 ret = UNLOCK_DEVICE_FAILED;
194                 goto error;
195         }*/
196
197         /*not use this function so fail return */
198         (*lawmo_return) = UNLOCK_DEVICE_FAILED;
199         ret = UNLOCK_DEVICE_FAILED;
200
201         _INNER_FUNC_EXIT;
202         return ret;
203
204 }
205
206 /*this is oma dm spec function but this is not used slp phone.*/
207 static DM_ERROR _lawmo_factoryreset(LAWMO_Result_code * lawmo_return)
208 {
209         _INNER_FUNC_ENTER;
210         DM_ERROR ret = DM_OK;
211
212 /*      (*lawmo_return) = OPERATION_SUCCEEDED;
213
214         sync_agent_dev_return_e error = 0;
215         //error = sync_agent_execute_dev_function(2, "factory_reset", 0);
216
217         if(error == 1) {
218                 (*lawmo_return) = OPERATION_SUCCEEDED;
219         } else {
220                 (*lawmo_return) = WIPE_DEVICES_DATA_FAILED;
221                 ret = WIPE_DEVICES_DATA_FAILED;
222                 goto error;
223         }*/
224
225         /*not use this function so fail return */
226         (*lawmo_return) = WIPE_DEVICES_DATA_FAILED;
227         ret = WIPE_DEVICES_DATA_FAILED;
228
229         _INNER_FUNC_EXIT;
230         return ret;
231
232 }
233
234 /*this is oma dm spec function but this is not used slp phone.*/
235 static DM_ERROR _lawmo_wipe(LAWMO_Result_code * lawmo_return)
236 {
237         _INNER_FUNC_ENTER;
238         DM_ERROR ret = DM_OK;
239
240         /*(*lawmo_return) = OPERATION_SUCCEEDED;
241            sync_agent_dev_return_e error = 0;
242            //error = sync_agent_execute_dev_function(2, "factory_reset", 0);
243
244            if(error == 1) {
245            (*lawmo_return) = OPERATION_SUCCEEDED;
246            } else {
247            (*lawmo_return) = WIPE_DEVICES_DATA_FAILED;
248            ret = WIPE_DEVICES_DATA_FAILED;
249            goto error;
250            } */
251
252         /*not use this function so fail return */
253         (*lawmo_return) = WIPE_DEVICES_DATA_FAILED;
254         ret = WIPE_DEVICES_DATA_FAILED;
255
256         _INNER_FUNC_EXIT;
257         return ret;
258
259 }
260
261 static DM_ERROR _vendor_dependency_lawmo_operation(char *full_path, LAWMO_Result_code * lawmo_return, int check_operation)
262 {
263         _INNER_FUNC_ENTER;
264
265         DM_ERROR ret = DM_OK;
266         sync_agent_dm_mo_error_e ext_return;
267         ext_return = sync_agent_execute_mo_ext(full_path, (int *)lawmo_return, check_operation);
268         _DEBUG_TRACE("ext_return : %d", ext_return);
269         if (ext_return != SYNC_AGENT_DM_MO_SUCCESS) {
270                 ret = DM_ERR_COMMAND_FAILED;
271                 goto error;
272         }
273
274         _INNER_FUNC_EXIT;
275         return ret;
276  error:
277         _DEBUG_TRACE(" end error : %d \n", ret);
278         _INNER_FUNC_EXIT;
279         return ret;
280 }
281
282 DM_ERROR get_current_lawmo_state(char *full_path, char **lawmo_state_data)
283 {
284         _INNER_FUNC_ENTER;
285         DM_ERROR ret = DM_OK;
286
287         retvm_if((full_path) == NULL, COMMON_ERR_IS_NULL, "full_path is NULL!!");
288
289         char *lawmo_root = NULL;
290         char *lawmo_state_url = NULL;
291         //ret = get_mo_servicetype(full_path, &lawmo_root);
292         ret = get_mo_root_path(full_path, &lawmo_root);
293         if (ret != DM_OK) {
294                 ret = COMMON_ERR_INTERNAL_NOT_DEFINED;
295                 goto error;
296         }
297         lawmo_state_url = g_strdup_printf("%s%s", lawmo_root, DM_LAWMO_STATE_OP);
298
299         ret = get_mo_data(lawmo_state_url, lawmo_state_data);
300         if (ret != DM_OK) {
301                 ret = COMMON_ERR_GET_TYPE_NOT_FOUND;
302                 goto error;
303         }
304
305         str_free(&lawmo_state_url);
306         _INNER_FUNC_EXIT;
307         return ret;
308  error:
309         str_free(&lawmo_state_url);
310         _DEBUG_INFO(" end error : %d\n", ret);
311         _INNER_FUNC_EXIT;
312         return ret;
313 }
314
315 DM_ERROR set_current_lawmo_state(char *full_path, LAWMO_State lawmo_state)
316 {
317         _INNER_FUNC_ENTER;
318
319         DM_ERROR ret = DM_OK;
320
321         retvm_if((full_path) == NULL, COMMON_ERR_IS_NULL, "full_path is NULL!!");
322
323         char *lawmo_root = NULL;
324         char *lawmo_state_url = NULL;
325         char *lawmo_state_data = NULL;
326
327         //ret = get_mo_servicetype(full_path, &lawmo_root);
328         ret = get_mo_root_path(full_path, &lawmo_root);
329         if (ret != DM_OK) {
330                 goto error;
331         }
332
333         lawmo_state_url = g_strdup_printf("%s%s", lawmo_root, DM_LAWMO_STATE_OP);
334         lawmo_state_data = g_strdup_printf("%d", lawmo_state);
335
336         _DEBUG_INFO(" fumo_state : %d\n", lawmo_state);
337         ret = replace_mo_data(lawmo_state_url, lawmo_state_data);
338         if (ret != DM_OK)
339                 goto error;
340
341         str_free(&lawmo_state_url);
342         str_free(&lawmo_state_data);
343         _INNER_FUNC_EXIT;
344         return ret;
345
346  error:
347         str_free(&lawmo_state_url);
348         str_free(&lawmo_state_data);
349         _DEBUG_INFO(" end error : %d\n", ret);
350         _INNER_FUNC_EXIT;
351         return ret;
352 }