3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <sync_agent.h>
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"
29 #ifndef OMADM_AGENT_LOG
31 #define LOG_TAG "LAWMO_ENGINE"
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);
41 DM_ERROR lawmo_exec(char *full_path, char *correlator, LAWMO_Result_code * lawmo_return, int check_operation)
44 _DEBUG_INFO(" start\n");
47 retvm_if((full_path) == NULL, COMMON_ERR_IS_NULL, "full_path is NULL!!");
49 char *result_mo_type = NULL;
50 /*LAWMO_State lawmo_state ; */
52 ret = get_mo_operationtype(full_path, &result_mo_type);
53 //ret = get_mo_root_path(full_path, &result_mo_type);
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);
62 if ((*lawmo_return) == OPERATION_SUCCEEDED) {
63 ret = set_current_lawmo_state(full_path, FULLY_LOCKED);
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);
73 if ((*lawmo_return) == OPERATION_SUCCEEDED) {
74 ret = set_current_lawmo_state(full_path, PARTIALLY_LOCKED);
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);
84 if ((*lawmo_return) == OPERATION_SUCCEEDED) {
85 ret = set_current_lawmo_state(full_path, UNLOCKED);
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);
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);
103 //1 : this is just available operation
104 ret = _vendor_dependency_lawmo_operation(full_path, lawmo_return, check_operation);
105 //*lawmo_return = 1200;
111 str_free(&result_mo_type);
112 _DEBUG_INFO(" end\n");
115 str_free(&result_mo_type);
116 _DEBUG_INFO(" end error : %d \n", ret);
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)
125 DM_ERROR ret = DM_OK;
127 /* (*lawmo_return) = OPERATION_SUCCEEDED;
129 sync_agent_dev_return_e error = 0;
130 //error = sync_agent_execute_dev_function(2, "full_lock", 0);
133 (*lawmo_return) = OPERATION_SUCCEEDED;
135 (*lawmo_return) = FULLY_LOCK_DEVICE_FAILED;
136 ret = FULLY_LOCK_DEVICE_FAILED;
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;
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)
154 DM_ERROR ret = DM_OK;
156 /* (*lawmo_return) = OPERATION_SUCCEEDED;
158 sync_agent_dev_return_e error =0;
159 //error = sync_agent_execute_dev_function(2, "partial_lock", 0);
162 (*lawmo_return) = OPERATION_SUCCEEDED;
164 (*lawmo_return) = PARTIALLY_LOCK_DEVICE_FAILED;
165 ret = PARTIALLY_LOCK_DEVICE_FAILED;
169 /*not use this function so fail return */
170 (*lawmo_return) = PARTIALLY_LOCK_DEVICE_FAILED;
171 ret = PARTIALLY_LOCK_DEVICE_FAILED;
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)
182 DM_ERROR ret = DM_OK;
184 /* (*lawmo_return) = OPERATION_SUCCEEDED;
186 sync_agent_dev_return_e error = 0;
187 //error = sync_agent_execute_dev_function(2, "unlock", 0);
190 (*lawmo_return) = OPERATION_SUCCEEDED;
192 (*lawmo_return) = UNLOCK_DEVICE_FAILED;
193 ret = UNLOCK_DEVICE_FAILED;
197 /*not use this function so fail return */
198 (*lawmo_return) = UNLOCK_DEVICE_FAILED;
199 ret = UNLOCK_DEVICE_FAILED;
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)
210 DM_ERROR ret = DM_OK;
212 /* (*lawmo_return) = OPERATION_SUCCEEDED;
214 sync_agent_dev_return_e error = 0;
215 //error = sync_agent_execute_dev_function(2, "factory_reset", 0);
218 (*lawmo_return) = OPERATION_SUCCEEDED;
220 (*lawmo_return) = WIPE_DEVICES_DATA_FAILED;
221 ret = WIPE_DEVICES_DATA_FAILED;
225 /*not use this function so fail return */
226 (*lawmo_return) = WIPE_DEVICES_DATA_FAILED;
227 ret = WIPE_DEVICES_DATA_FAILED;
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)
238 DM_ERROR ret = DM_OK;
240 /*(*lawmo_return) = OPERATION_SUCCEEDED;
241 sync_agent_dev_return_e error = 0;
242 //error = sync_agent_execute_dev_function(2, "factory_reset", 0);
245 (*lawmo_return) = OPERATION_SUCCEEDED;
247 (*lawmo_return) = WIPE_DEVICES_DATA_FAILED;
248 ret = WIPE_DEVICES_DATA_FAILED;
252 /*not use this function so fail return */
253 (*lawmo_return) = WIPE_DEVICES_DATA_FAILED;
254 ret = WIPE_DEVICES_DATA_FAILED;
261 static DM_ERROR _vendor_dependency_lawmo_operation(char *full_path, LAWMO_Result_code * lawmo_return, int check_operation)
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;
277 _DEBUG_TRACE(" end error : %d \n", ret);
282 DM_ERROR get_current_lawmo_state(char *full_path, char **lawmo_state_data)
285 DM_ERROR ret = DM_OK;
287 retvm_if((full_path) == NULL, COMMON_ERR_IS_NULL, "full_path is NULL!!");
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);
294 ret = COMMON_ERR_INTERNAL_NOT_DEFINED;
297 lawmo_state_url = g_strdup_printf("%s%s", lawmo_root, DM_LAWMO_STATE_OP);
299 ret = get_mo_data(lawmo_state_url, lawmo_state_data);
301 ret = COMMON_ERR_GET_TYPE_NOT_FOUND;
305 str_free(&lawmo_state_url);
309 str_free(&lawmo_state_url);
310 _DEBUG_INFO(" end error : %d\n", ret);
315 DM_ERROR set_current_lawmo_state(char *full_path, LAWMO_State lawmo_state)
319 DM_ERROR ret = DM_OK;
321 retvm_if((full_path) == NULL, COMMON_ERR_IS_NULL, "full_path is NULL!!");
323 char *lawmo_root = NULL;
324 char *lawmo_state_url = NULL;
325 char *lawmo_state_data = NULL;
327 //ret = get_mo_servicetype(full_path, &lawmo_root);
328 ret = get_mo_root_path(full_path, &lawmo_root);
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);
336 _DEBUG_INFO(" fumo_state : %d\n", lawmo_state);
337 ret = replace_mo_data(lawmo_state_url, lawmo_state_data);
341 str_free(&lawmo_state_url);
342 str_free(&lawmo_state_data);
347 str_free(&lawmo_state_url);
348 str_free(&lawmo_state_data);
349 _DEBUG_INFO(" end error : %d\n", ret);