[Internal: merge oma-dm-agent]
[framework/system/oma-dm-agent.git] / src / agent / framework / task / oma_dm_task_spec.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 /*dm-agent*/
22 #include "common/dm_common.h"
23 #include "common/util/util.h"
24 #include "framework/task/oma_dm_task_spec.h"
25 #include "framework/task/oma_dm_task_request.h"
26 #include "framework/san-parser/pm_sanparser.h"
27 #include "framework/ui-event-handler/ipc_agent.h"
28 #include "framework/platform-event-handler/dm_platform_event_handler.h"
29 #include "dm-engine/dm_common_engine.h"
30 #include "dm-engine/bootstrap/factory_bootstrap.h"
31 #include "dm-engine/fumo/fumo_engine.h"
32 #include "dm-engine/lawmo/lawmo_engine.h"
33
34 #ifndef OMADM_AGENT_LOG
35 #undef LOG_TAG
36 #define LOG_TAG "TASK_SPEC"
37 #endif
38
39 static sync_agent_ec_task_error_e _start_dm_init_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array);
40 static sync_agent_ec_task_error_e _start_dm_reset_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array);
41 static sync_agent_ec_task_error_e _start_bootstrap_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array);
42 static sync_agent_ec_task_error_e _start_dm_fumo_common_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array);
43 static sync_agent_ec_task_error_e _start_dm_fumo_ui_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array);
44 static sync_agent_ec_task_error_e _start_dm_lawmo_common_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array);
45 static sync_agent_ec_task_error_e _start_genericAlert_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array);
46 static sync_agent_ec_task_error_e _start_fumo_serviceEngine_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array);
47 static sync_agent_ec_task_error_e _start_lawmo_serviceEngine_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array);
48 static sync_agent_ec_task_error_e _start_fumo_schedule_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array);
49
50 sync_agent_ec_task_spec_s *make_dm_init_task_spec()
51 {
52         _EXTERN_FUNC_ENTER;
53
54         sync_agent_ec_param_spec_s *pParam_spec1 = sync_agent_alloc_param_spec_int("dm_init_start", false, true, false, 0, 0, false, 0, false, 0, 0);
55         sync_agent_ec_param_spec_s *param_spec_array[1] = { pParam_spec1 };
56
57         sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("dm_init",
58                                                                                   _start_dm_init_process, NULL, NULL,
59                                                                                   1, param_spec_array);
60
61         sync_agent_unref_param_spec(pParam_spec1);
62
63         _EXTERN_FUNC_EXIT;
64         return pTask_spec;
65
66 }
67
68 static sync_agent_ec_task_error_e _start_dm_init_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array)
69 {
70         _INNER_FUNC_ENTER;
71
72         DM_ERROR ret = DM_OK;
73         sync_agent_open_mo();
74         ret = DB_Open();
75         _DEBUG_TRACE("status db : %d", ret);
76         ret = sync_agent_open_agent();
77         _DEBUG_TRACE("status db : %d", ret);
78
79         sync_agent_ec_task_error_e err = SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS;
80         ENGINE_STATUS value = DM_IDLE;
81         engine_status *status = NULL;
82
83         int is_exist = IsExist_Engine_id(IDLE_ENGINE);
84         if (is_exist == 0)
85                 goto error;
86
87         ret = Get_Engine_Status(IDLE_ENGINE, &status);
88         if (ret != DM_OK) {
89                 _DEBUG_TRACE("status is null");
90                 goto error;
91         }
92         if (status != NULL) {
93
94                 _DEBUG_TRACE("STATUS VALUE : %d ", status->engine_status);
95                 value = status->engine_status;
96
97                 if (value == DM_BEFORE_BOOTSTRAP) {
98                         ret = bootstrap_task_request();
99                 } else {
100                         init_Dm_Engine();
101                         ret = auto_operate_service_engine();
102                 }
103
104                 sync_agent_set_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &value);
105
106                 sync_agent_close_mo();
107                 ret = sync_agent_close_agent();
108                 _DEBUG_TRACE("close db agent : %d", ret);
109                 DB_Close();
110
111                 Free_Memory_Engine_Status(&status, 1);
112
113         } else {
114                 _DEBUG_TRACE("status is null");
115         }
116
117         _INNER_FUNC_EXIT;
118         return err;
119
120  error:
121
122         sync_agent_set_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &value);
123         err = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED;
124
125         sync_agent_close_mo();
126         ret = sync_agent_close_agent();
127         _DEBUG_TRACE("close db agent : %d", ret);
128         DB_Close();
129
130         if (status != NULL)
131                 Free_Memory_Engine_Status(&status, 1);
132
133         _INNER_FUNC_EXIT;
134         return err;
135 }
136
137 sync_agent_ec_task_spec_s *make_dm_reset_task_spec()
138 {
139         _EXTERN_FUNC_ENTER;
140
141         sync_agent_ec_param_spec_s *pParam_spec1 = sync_agent_alloc_param_spec_int("dm_reset_start", false, true, false, 0, 0, false, 0, false, 0, 0);
142         sync_agent_ec_param_spec_s *param_spec_array[1] = { pParam_spec1 };
143
144         sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("dm_reset",
145                                                                                   _start_dm_reset_process, NULL, NULL,
146                                                                                   1, param_spec_array);
147
148         sync_agent_unref_param_spec(pParam_spec1);
149
150         _EXTERN_FUNC_EXIT;
151         return pTask_spec;
152
153 }
154
155 static sync_agent_ec_task_error_e _start_dm_reset_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array)
156 {
157
158         _INNER_FUNC_ENTER;
159
160         DM_ERROR ret = DM_OK;
161         ret = DB_Open();
162         ret = sync_agent_open_agent();
163
164         sync_agent_ec_task_error_e err = SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS;
165
166         //ret = reset_dm();
167         if (ret != DM_OK)
168                 goto error;
169
170         sync_agent_set_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &ret);
171
172         ret = sync_agent_close_agent();
173         DB_Close();
174
175         _INNER_FUNC_EXIT;
176         return err;
177
178  error:
179
180         sync_agent_set_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &ret);
181         err = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED;
182
183         ret = sync_agent_close_agent();
184         DB_Close();
185         _INNER_FUNC_EXIT;
186         return err;
187
188 }
189
190 sync_agent_ec_task_spec_s *make_bootstrap_task_spec()
191 {
192         _EXTERN_FUNC_ENTER;
193
194         sync_agent_ec_param_spec_s *pParam_spec1 = sync_agent_alloc_param_spec_int("bootstrap_start", true, false, false, 0, 0, false, 0, false, 0, 0);
195         sync_agent_ec_param_spec_s *pParam_spec2 = sync_agent_alloc_param_spec_int("bootstrap_result", false, true, false, 0, 0, false, 0, false, 0, 0);
196
197         sync_agent_ec_param_spec_s *param_spec_array[2] = { pParam_spec1, pParam_spec2 };
198
199         sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("dm_bootstrap_task",
200                                                                                   _start_bootstrap_process, NULL, NULL,
201                                                                                   2, param_spec_array);
202
203         sync_agent_unref_param_spec(pParam_spec1);
204         sync_agent_unref_param_spec(pParam_spec2);
205
206         _EXTERN_FUNC_EXIT;
207         return pTask_spec;
208 }
209
210 static sync_agent_ec_task_error_e _start_bootstrap_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array)
211 {
212         _INNER_FUNC_ENTER;
213
214         DM_ERROR ret = DM_OK;
215         sync_agent_open_mo();
216         _DEBUG_TRACE(" Done Open Mo DB\n");
217         ret = DB_Open();
218
219         sync_agent_ec_task_error_e err = SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS;
220
221         /*
222          *  factory bootstrap  0
223          *  server init bootstrap 1
224          *  smart card bootstrap 2
225          */
226
227         int bootstrapType = 0;
228         sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &bootstrapType);
229         int i = 0;
230         int max_try = 3;
231
232         ret = reset_dm();
233         _DEBUG_TRACE("reset dm db : %d", ret);
234
235         for (i = 0; i < max_try; ++i) {
236                 switch (bootstrapType) {
237                 case 0:
238                         ret = factory_bootstrap(NO_ENGINE_TYPE);
239                         _DEBUG_TRACE("factory bootstrap : %d", ret);
240                         if (ret != DM_OK) {
241                                 ret = reset_dm();
242                                 _DEBUG_TRACE("reset dm db : %d", ret);
243                                 ret = DM_ERR_BOOTSTRAP;
244                                 continue;
245                         } else {
246                                 i = max_try;
247                                 break;
248                         }
249                         break;
250                 default:
251                         ret = DM_ERR_BOOTSTRAP;
252                         goto error;
253                         break;
254                 }
255         }
256
257         sync_agent_set_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, (void *)(&ret));
258         _DEBUG_TRACE("end");
259
260         DB_Close();
261         sync_agent_close_mo();
262         _DEBUG_TRACE(" Done Close Mo DB\n");
263         _INNER_FUNC_EXIT;
264         return err;
265
266  error:
267
268         sync_agent_set_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, (void *)(&ret));
269         err = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED;
270         _DEBUG_TRACE("error");
271
272         DB_Close();
273         sync_agent_close_mo();
274         _DEBUG_TRACE("Done Close Mo DB\n");
275         _INNER_FUNC_EXIT;
276         return err;
277 }
278
279 sync_agent_ec_task_spec_s *make_dm_fumo_common_process_task_spec()
280 {
281         _EXTERN_FUNC_ENTER;
282
283         sync_agent_ec_param_spec_s *pParam_spec1 = sync_agent_alloc_param_spec_structure("eventData", NULL, event_data_free, true, false, false, 0, false, 0, false, 0);
284         sync_agent_ec_param_spec_s *pParam_spec2 = sync_agent_alloc_param_spec_int("common_fumo_dm_result", false, true, false, 0, 0, false, 0, false, 0, 0);
285
286         sync_agent_ec_param_spec_s *param_spec_array[2] = { pParam_spec1, pParam_spec2 };
287
288         sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("common_fumo_dm",
289                                                                                   _start_dm_fumo_common_process, NULL, NULL,
290                                                                                   2, param_spec_array);
291
292         sync_agent_unref_param_spec(pParam_spec1);
293         sync_agent_unref_param_spec(pParam_spec2);
294
295         _EXTERN_FUNC_EXIT;
296         return pTask_spec;
297
298 }
299
300 static sync_agent_ec_task_error_e _start_dm_fumo_common_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array)
301 {
302         _INNER_FUNC_ENTER;
303
304         _DEBUG_TRACE(" Done Open Mo DB\n");
305
306         DM_ERROR ret = DM_OK;
307         ret = DB_Open();
308         ret = sync_agent_open_agent();
309         sync_agent_open_mo();
310         sync_agent_ec_task_error_e err = SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS;
311
312         /* todo
313          * telephony vconf status get
314          * if connecting call status
315          * add quick panel
316          * goto error;
317          */
318         int roaming_state = -1;
319         int call_state = -1;
320         int wifi_state = -1;
321         Event_Contents *pEvent_data = NULL;
322         int task_id;
323
324         get_roaming_state(&roaming_state);
325         get_wifi_connected_state(&wifi_state);
326         get_call_sate(&call_state);
327         /*
328         if (roaming_state == -1 || call_state == -1) {
329                 _DEBUG_TRACE("NOT ROAMING OR CALL STATUS  roaming state : %d , call state : %d", roaming_state, call_state);
330                 ret = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED;
331                 goto error;
332         }
333         */
334         if (call_state == -1) {
335                 _DEBUG_TRACE("CALL STATUS  call state : %d", call_state);
336                 ret = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED;
337                 goto error;
338         }
339         if ( (roaming_state == -1) && (wifi_state == -1) ) {
340                 _DEBUG_TRACE("NOT ROAMING AND WiFi Status  roaming state : %d , WiFi state : %d", roaming_state, wifi_state);
341                 ret = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED;
342                 goto error;
343         }
344
345         task_id = sync_agent_get_self_request_id();
346         _DEBUG_TRACE("task id ============================================ %d", task_id);
347
348         sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &pEvent_data);
349         if (pEvent_data == NULL) {
350                 _DEBUG_TRACE("-------------------------------------NOT EVENT IDLE---------------------------------------");
351                 goto error;
352         }
353
354         if (pEvent_data->server_id == NULL) {
355                 _DEBUG_TRACE("server id null");
356                 ret = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED;
357                 goto error;
358         }
359
360         if (pEvent_data != NULL) {
361                 _DEBUG_TRACE("mode = %d", pEvent_data->type);
362                 _DEBUG_TRACE("server id  = %s", pEvent_data->server_id);
363                 _DEBUG_TRACE("session id= %s", pEvent_data->session_id);
364                 _DEBUG_TRACE("noti type id= %d", pEvent_data->noti_type);
365                 _DEBUG_TRACE("ui mode id= %s", pEvent_data->ui_mode);
366         }
367
368         if (pEvent_data->ui_mode != NULL) {
369                 //for using fumo ui
370                 //add_config_db_using_ui( task_id, pEvent_data->ui_mode);
371
372                 int is_exist = 0;
373                 is_exist = IsExist_Engine_id(FUMO_SERVICE_ENGINE);
374                 _DEBUG_INFO("IsExist_Engine_id(FUMO_SERVICE_ENGINE)  [%d]", is_exist);
375
376                 if (is_exist == 0) {
377                         engine_status status;
378                         memset(&status, 0x00, sizeof(engine_status));
379                         status.engine_id = FUMO_SERVICE_ENGINE;
380                         status.engine_status = DM_SERVICE_UNKNOWN;
381                         //status.server_id = strdup(pEvent_data->server_id);
382                         status.server_id = pEvent_data->server_id;
383                         status.server_url = 0;
384                         status.correlator = 0;
385                         status.mo_path = 0;
386                         status.result_status = DM_OK;
387                         //status.ui_mode = strdup(pEvent_data->ui_mode);
388                         status.ui_mode = pEvent_data->ui_mode;
389                         status.task_id = task_id;
390                         status.ui_noti_type = get_default_noti_type(pEvent_data->ui_mode, pEvent_data->noti_type);      //0;
391
392                         status.download_click = RESUME_STATUS_DONWLOAD_BEFORE;
393                         _DEBUG_TRACE("status noti ui type : %d", status.ui_noti_type);
394                         DB_Begin_Transaction();
395
396                         ret = Add_Engine_Status(&status);
397                         _DEBUG_TRACE(" -------------------------------------add engine status : %d -------------------------------------\n", ret);
398                         DB_End_Transaction(TRANSACTION_COMMIT_);
399
400                         //str_free(&(status.server_id));
401                         //str_free(&(status.ui_mode));
402
403                 } else {
404                         engine_status *status;
405                         ret = Get_Engine_Status(FUMO_SERVICE_ENGINE, &status);
406                         if (status != NULL) {
407                                 _DEBUG_TRACE(" -------------------------------------update engine status  -------------------------------------\n");
408                                 status->ui_mode = strdup(pEvent_data->ui_mode);
409                                 status->task_id = task_id;
410                                 status->ui_noti_type = get_default_noti_type(pEvent_data->ui_mode, pEvent_data->noti_type);     //0;
411                                 //status->download_click = RESUME_STATUS_DONWLOAD_BEFORE; // 959 error fix about "download done -> softwareupdate retry clicked". ??? 
412
413                                 DB_Begin_Transaction();
414                                 ret = Update_Engine_Status(status);
415                                 _DEBUG_TRACE(" update engine status : %d \n", ret);
416                                 _DEBUG_TRACE(" status->download_click [%d] ", status->download_click);
417                                 DB_End_Transaction(TRANSACTION_COMMIT_);
418
419                                 if (status != NULL)
420                                         Free_Memory_Engine_Status(&status, 1);
421
422                         }
423                 }
424
425                 int noti_ret = noti_start(pEvent_data->ui_mode);
426                 _DEBUG_TRACE("noti start : %d", noti_ret);
427
428         } else {
429                 _DEBUG_TRACE("ui mode null");
430         }
431
432         ENGINE_STATUS value = 0;
433         engine_status *status = NULL;
434         ret = Get_Engine_Status(IDLE_ENGINE, &status);
435         if (status != NULL) {
436                 _DEBUG_TRACE("STATUS VALUE : %d ", status->engine_status);
437                 value = status->engine_status;
438
439                 if (value != DM_BEFORE_BOOTSTRAP) {
440                         _DEBUG_INFO("status->ui_noti_type [%d] pEvent_data->noti_type [%d]", status->ui_noti_type, pEvent_data->noti_type);
441                         if(pEvent_data->noti_type == NOTI_TYPE_POLLINTERACTION) {
442                         } else {
443                                 ret = dm_common_start(pEvent_data);
444                         }
445                 } else {
446                         //do popup ui
447                         //retry factorybootstrap
448                 }
449
450                 Free_Memory_Engine_Status(&status, 1);
451         } else {
452                 ret = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED;
453         }
454
455         _DEBUG_TRACE("end  ret :%d ", ret);
456         if (ret != DM_OK)
457                 goto error;
458
459         sync_agent_set_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, (void *)(&ret));
460
461         event_data_free((void *)pEvent_data);
462         ret = sync_agent_close_agent();
463         DB_Close();
464         sync_agent_close_mo();
465         _DEBUG_TRACE("Done Close Mo DB\n");
466         _INNER_FUNC_EXIT;
467         return err;
468
469  error:
470         _DEBUG_ERROR("error : %d", ret);
471
472         sync_agent_set_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, (void *)(&ret));
473
474         event_data_free((void *)pEvent_data);
475         ret = sync_agent_close_agent();
476         DB_Close();
477         sync_agent_close_mo();
478         err = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED;
479         _DEBUG_ERROR("Done Close Mo DB\n");
480         _INNER_FUNC_EXIT;
481         return err;
482 }
483
484 sync_agent_ec_task_spec_s *make_dm_fumo_ui_process_task_spec()
485 {
486         _EXTERN_FUNC_ENTER;
487
488         sync_agent_ec_param_spec_s *pParam_spec1 = sync_agent_alloc_param_spec_structure("eventData", NULL, event_data_free, true, false, false, 0, false, 0, false, 0);
489         sync_agent_ec_param_spec_s *pParam_spec2 = sync_agent_alloc_param_spec_int("ui_fumo_dm_result", false, true, false, 0, 0, false, 0, false, 0, 0);
490
491         sync_agent_ec_param_spec_s *param_spec_array[2] = { pParam_spec1, pParam_spec2 };
492
493         sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("ui_fumo_dm",
494                                                                                   _start_dm_fumo_ui_process, NULL, NULL,
495                                                                                   2, param_spec_array);
496
497         sync_agent_unref_param_spec(pParam_spec1);
498         sync_agent_unref_param_spec(pParam_spec2);
499
500         _EXTERN_FUNC_EXIT;
501         return pTask_spec;
502
503 }
504
505 static sync_agent_ec_task_error_e _start_dm_fumo_ui_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array)
506 {
507         _INNER_FUNC_ENTER;
508
509         DM_ERROR ret = DM_OK;
510         sync_agent_ec_task_error_e err = SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS;
511         ret = DB_Open();
512         /* todo
513          * telephony vconf status get
514          * if connecting call status
515          *
516          * add quick panel
517          *
518          * goto error;
519          */
520
521         int task_id;
522         task_id = sync_agent_get_self_request_id();
523         _DEBUG_TRACE("task id ============================================ %d", task_id);
524
525         Event_Contents *pEvent_data = NULL;
526         sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &pEvent_data);
527         if (pEvent_data == NULL || (pEvent_data->session_id) == NULL || (pEvent_data->server_id) == NULL) {
528                 _DEBUG_TRACE("-------------------------------------NOT EVENT IDLE---------------------------------------");
529                 ret = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED;
530                 goto error;
531         }
532
533         _DEBUG_TRACE("-----------------------------------%s---------------------------------------", pEvent_data->session_id);
534         _DEBUG_TRACE("-----------------------------------%s---------------------------------------", pEvent_data->server_id);
535         _DEBUG_TRACE("noti type id= %d", pEvent_data->noti_type);
536         _DEBUG_TRACE("session id= %s", pEvent_data->session_id);
537
538         _DEBUG_TRACE("server id= %s", pEvent_data->server_id);
539         ENGINE_STATUS value = 0;
540         engine_status *status = NULL;
541         ret = Get_Engine_Status(IDLE_ENGINE, &status);
542         if (status != NULL) {
543                 _DEBUG_TRACE("STATUS VALUE : %d ", status->engine_status);
544                 value = status->engine_status;
545
546                 if (value != DM_BEFORE_BOOTSTRAP) {
547                         ret = launch_om_dm_fumo_noti_ui(pEvent_data->noti_type, pEvent_data->session_id, pEvent_data->server_id);
548                         if (ret == 0) {
549                                 _DEBUG_TRACE("ui launch fail");
550                         }
551                 } else {
552                         //do popup ui
553                         //retry factorybootstrap
554                 }
555
556                 Free_Memory_Engine_Status(&status, 1);
557         }
558
559         _DEBUG_TRACE("end  ret :%d ", ret);
560         if (ret != 1)
561                 goto error;
562
563         sync_agent_set_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, (void *)(&ret));
564
565         DB_Close();
566         event_data_free((void *)pEvent_data);
567         _DEBUG_TRACE("Done Close Mo DB\n");
568         _INNER_FUNC_EXIT;
569         return err;
570
571  error:
572         //err = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED;
573         _DEBUG_TRACE("error");
574
575         sync_agent_set_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, (void *)(&ret));
576
577         DB_Close();
578         event_data_free((void *)pEvent_data);
579         _DEBUG_TRACE("Done Close Mo DB\n");
580         _INNER_FUNC_EXIT;
581         return err;
582 }
583
584 sync_agent_ec_task_spec_s *make_dm_lawmo_common_process_task_spec()
585 {
586         _EXTERN_FUNC_ENTER;
587
588         sync_agent_ec_param_spec_s *pParam_spec1 = sync_agent_alloc_param_spec_structure("eventData", NULL, event_data_free, true, false, false, 0, false, 0, false, 0);
589         sync_agent_ec_param_spec_s *pParam_spec2 = sync_agent_alloc_param_spec_int("common_lawmo_dm_result", false, true, false, 0, 0, false, 0, false, 0, 0);
590
591         sync_agent_ec_param_spec_s *param_spec_array[2] = { pParam_spec1, pParam_spec2 };
592
593         sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("common_lawmo_dm",
594                                                                                   _start_dm_lawmo_common_process, NULL, NULL,
595                                                                                   2, param_spec_array);
596
597         sync_agent_unref_param_spec(pParam_spec1);
598         sync_agent_unref_param_spec(pParam_spec2);
599
600         _EXTERN_FUNC_EXIT;
601         return pTask_spec;
602 }
603
604 static sync_agent_ec_task_error_e _start_dm_lawmo_common_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array)
605 {
606         _INNER_FUNC_ENTER;
607
608         sync_agent_open_mo();
609         _DEBUG_TRACE(" Done Open Mo DB\n");
610
611         DM_ERROR ret = DM_OK;
612         ret = DB_Open();
613         ret = sync_agent_open_agent();
614         sync_agent_ec_task_error_e err = SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS;
615
616 /*      int task_id;
617         task_id = sync_agent_get_self_request_id();*/
618
619         Event_Contents *pEvent_data = NULL;
620         sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &pEvent_data);
621         if (pEvent_data == NULL) {
622                 _DEBUG_TRACE("-------------------------------------NOT EVENT IDLE---------------------------------------");
623                 goto error;
624         }
625
626         if (pEvent_data != NULL) {
627                 _DEBUG_TRACE("mode = %d", pEvent_data->type);
628                 _DEBUG_TRACE("server id  = %s", pEvent_data->server_id);
629                 _DEBUG_TRACE("session id= %s", pEvent_data->session_id);
630                 _DEBUG_TRACE("noti type id= %d", pEvent_data->noti_type);
631                 _DEBUG_TRACE("ui mode id= %s", pEvent_data->ui_mode);
632         }
633
634         ENGINE_STATUS value = 0;
635         engine_status *status = NULL;
636         ret = Get_Engine_Status(IDLE_ENGINE, &status);
637         if (status != NULL) {
638                 _DEBUG_TRACE("STATUS VALUE : %d ", status->engine_status);
639                 value = status->engine_status;
640
641                 if (value != DM_BEFORE_BOOTSTRAP) {
642                         ret = dm_common_start(pEvent_data);
643                 } else {
644                         //do popup ui
645                         //retry factorybootstrap
646                 }
647
648                 Free_Memory_Engine_Status(&status, 1);
649         }
650 /*      //for using ui
651         if(engine_type == SAMSUNG_FUMO_TYPE)
652                 delete_config_db_using_ui( task_id);*/
653
654         _DEBUG_TRACE("end  ret :%d ", ret);
655         if (ret != DM_OK)
656                 goto error;
657
658         sync_agent_set_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, (void *)(&ret));
659
660         event_data_free((void *)pEvent_data);
661         ret = sync_agent_close_agent();
662         DB_Close();
663         sync_agent_close_mo();
664         _DEBUG_TRACE("Done Close Mo DB\n");
665         _INNER_FUNC_EXIT;
666         return err;
667
668  error:
669
670         _DEBUG_TRACE("error");
671
672         sync_agent_set_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, (void *)(&ret));
673         event_data_free((void *)pEvent_data);
674         ret = sync_agent_close_agent();
675         DB_Close();
676         sync_agent_close_mo();
677         _DEBUG_TRACE("Done Close Mo DB\n");
678         _INNER_FUNC_EXIT;
679         return err;
680 }
681
682 sync_agent_ec_task_spec_s *make_genericAlert_process_task_spec()
683 {
684         _EXTERN_FUNC_ENTER;
685
686         sync_agent_ec_param_spec_s *pParam_spec1 = sync_agent_alloc_param_spec_int("genericAlert_result", false, true, false, 0, 0, false, 0, false, 0, 0);
687         sync_agent_ec_param_spec_s *param_spec_array[1] = { pParam_spec1 };
688
689         sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("dm_genericAlert_task",
690                                                                                   _start_genericAlert_process, NULL, NULL,
691                                                                                   1, param_spec_array);
692
693         sync_agent_unref_param_spec(pParam_spec1);
694
695         _EXTERN_FUNC_EXIT;
696         return pTask_spec;
697
698 }
699
700 static sync_agent_ec_task_error_e _start_genericAlert_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array)
701 {
702         _INNER_FUNC_ENTER;
703
704         sync_agent_open_mo();
705         _DEBUG_TRACE(" Done Open Mo DB\n");
706
707         DM_ERROR ret = DM_OK;
708         ret = DB_Open();
709         ret = sync_agent_open_agent();
710         sync_agent_ec_task_error_e err = SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS;
711
712         /*ENGINE_ID service_engine_id = GENERICALERT;
713            engine_status *service_status= NULL;
714            char* server_id = NULL;
715            int result = DM_OK;
716
717            if( IsExist_Engine_id(service_engine_id) == 1) {
718            ret = Get_Engine_Status(SERVICE_ENGINE, &service_status);
719            if(ret != DM_OK)
720            goto error;
721
722            server_id = strdup(service_status->server_id);
723            result = service_status->engine_status;
724            ret = Free_Memory_Engine_Status(&service_status, 1);
725
726            ret = genericalert_operation(result, server_id);
727
728            } else {
729            //do nothting
730            } */
731
732         sync_agent_set_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, (void *)(&ret));
733         _DEBUG_TRACE("end");
734
735         ret = sync_agent_close_agent();
736         DB_Close();
737         sync_agent_close_mo();
738         _DEBUG_TRACE("Done Close Mo DB\n");
739         _INNER_FUNC_EXIT;
740         return err;
741
742 /*error:
743         err = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED;
744         _DEBUG_TRACE("error");
745
746         DB_Close();
747         sync_agent_close_mo();
748         _DEBUG_TRACE( "Done Close Mo DB\n");
749         return err;*/
750 }
751
752 sync_agent_ec_task_spec_s *make_fumo_serviceEngine_process_task_spec()
753 {
754         _EXTERN_FUNC_ENTER;
755
756         sync_agent_ec_param_spec_s *pParam_spec1 = sync_agent_alloc_param_spec_int("fumo_service_engine_result", false, true, false, 0, 0, false, 0, false, 0, 0);
757         sync_agent_ec_param_spec_s *param_spec_array[1] = { pParam_spec1 };
758
759         sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("dm_fumo_service_engine_task",
760                                                                                   _start_fumo_serviceEngine_process, NULL, NULL,
761                                                                                   1, param_spec_array);
762
763         sync_agent_unref_param_spec(pParam_spec1);
764
765         _EXTERN_FUNC_EXIT;
766         return pTask_spec;
767
768 }
769
770 static sync_agent_ec_task_error_e _start_fumo_serviceEngine_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array)
771 {
772         _INNER_FUNC_ENTER;
773
774         DM_ERROR ret = DM_OK;
775         DM_ERROR service_ret = DM_OK;
776
777         sync_agent_open_mo();
778         ret = DB_Open();
779         _DEBUG_TRACE("status db open : %d", ret);
780         ret = sync_agent_open_agent();
781         _DEBUG_TRACE("daci db open : %d", ret);
782
783         sync_agent_ec_task_error_e err = SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS;
784
785         int roaming_state = -1;
786         int call_state = -1;
787         int wifi_state = -1;
788         get_roaming_state(&roaming_state);
789         get_wifi_connected_state(&wifi_state);
790         get_call_sate(&call_state);
791         /*
792         if (roaming_state == -1 || call_state == -1) {
793                 _DEBUG_TRACE("NOT ROAMING OR CALL STATUS  roaming state : %d , call state : %d", roaming_state, call_state);
794                 ret = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED;
795                 goto error;
796         }
797         */
798         if (call_state == -1) {
799                 _DEBUG_TRACE("CALL STATUS  call state : %d", call_state);
800                 ret = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED;
801                 goto error;
802         }
803         if ( (roaming_state == -1) && (wifi_state == -1) ) {
804                 _DEBUG_TRACE("NOT ROAMING AND WiFi Status  roaming state : %d , WiFi state : %d", roaming_state, wifi_state);
805                 ret = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED;
806                 goto error;
807         }
808
809
810         int task_id;
811         task_id = sync_agent_get_self_request_id();
812         ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_TASK_ID, &task_id);
813         _DEBUG_TRACE("update engine status : %d", ret);
814         _DEBUG_TRACE("------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
815         _DEBUG_TRACE("task id : %d", task_id);
816         _DEBUG_TRACE("------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
817         ret = service_engine_start(FUMO_SERVICE_ENGINE, &service_ret);
818         if (ret != DM_OK)
819                 goto error;
820
821         sync_agent_set_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, (void *)(&ret));
822
823         _DEBUG_TRACE("end");
824
825         ret = sync_agent_close_agent();
826         DB_Close();
827         sync_agent_close_mo();
828         _DEBUG_TRACE("Done Close Mo DB\n");
829         _INNER_FUNC_EXIT;
830         return err;
831
832  error:
833         err = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED;
834         _DEBUG_TRACE("error");
835
836         sync_agent_set_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, (void *)(&ret));
837
838         ret = sync_agent_close_agent();
839         DB_Close();
840         sync_agent_close_mo();
841         _DEBUG_TRACE("Done Close Mo DB\n");
842         _INNER_FUNC_EXIT;
843         return err;
844 }
845
846 sync_agent_ec_task_spec_s *make_lawmo_serviceEngine_process_task_spec()
847 {
848         _EXTERN_FUNC_ENTER;
849
850         sync_agent_ec_param_spec_s *pParam_spec1 = sync_agent_alloc_param_spec_int("lawmo_service_engine_result", false, true, false, 0, 0, false, 0, false, 0, 0);
851         sync_agent_ec_param_spec_s *param_spec_array[1] = { pParam_spec1 };
852
853         sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("dm_lawmo_service_engine_task",
854                                                                                   _start_lawmo_serviceEngine_process, NULL, NULL,
855                                                                                   1, param_spec_array);
856
857         sync_agent_unref_param_spec(pParam_spec1);
858
859         _EXTERN_FUNC_EXIT;
860         return pTask_spec;
861
862 }
863
864 static sync_agent_ec_task_error_e _start_lawmo_serviceEngine_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array)
865 {
866         _INNER_FUNC_ENTER;
867
868         DM_ERROR ret = DM_OK;
869         DM_ERROR service_ret = DM_OK;
870
871         sync_agent_open_mo();
872         ret = DB_Open();
873         ret = sync_agent_open_agent();
874
875         sync_agent_ec_task_error_e err = SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS;
876
877         ret = service_engine_start(LAWMO_SERVICE_ENGINE, &service_ret);
878         if (ret != DM_OK)
879                 goto error;
880
881         sync_agent_set_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, (void *)(&ret));
882
883         _DEBUG_TRACE("end");
884
885         ret = sync_agent_close_agent();
886         DB_Close();
887         sync_agent_close_mo();
888         _DEBUG_TRACE("Done Close Mo DB\n");
889         _INNER_FUNC_EXIT;
890         return err;
891
892  error:
893         err = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED;
894
895         sync_agent_set_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, (void *)(&ret));
896         _DEBUG_TRACE("error");
897
898         ret = sync_agent_close_agent();
899         DB_Close();
900         sync_agent_close_mo();
901         _DEBUG_TRACE("Done Close Mo DB\n");
902         _INNER_FUNC_EXIT;
903         return err;
904 }
905
906 sync_agent_ec_task_spec_s *make_fumo_schedule_process_task_spec()
907 {
908         _EXTERN_FUNC_ENTER;
909
910         sync_agent_ec_param_spec_s *pParam_spec1 = sync_agent_alloc_param_spec_int("fumo_schdule_start", true, false, false, 0, 0, false, 0, false, 0, 0);
911         sync_agent_ec_param_spec_s *pParam_spec2 = sync_agent_alloc_param_spec_int("fumo_schdule_result", false, true, false, 0, 0, false, 0, false, 0, 0);
912
913         sync_agent_ec_param_spec_s *param_spec_array[2] = { pParam_spec1, pParam_spec2 };
914
915         sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("dm_fumo_schdule_task",
916                                                                                   _start_fumo_schedule_process, NULL, NULL,
917                                                                                   2, param_spec_array);
918
919         sync_agent_unref_param_spec(pParam_spec1);
920         sync_agent_unref_param_spec(pParam_spec2);
921
922         _EXTERN_FUNC_EXIT;
923         return pTask_spec;
924 }
925
926 static sync_agent_ec_task_error_e _start_fumo_schedule_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array)
927 {
928         _INNER_FUNC_ENTER;
929
930         DM_ERROR ret = DM_OK;
931         int da_err = 0;
932         da_err = sync_agent_open_agent();
933         _DEBUG_TRACE("db open result : %d", da_err);
934
935         sync_agent_ec_task_error_e err = SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS;
936
937         Reminder_Interval reminder_interval_type = 0;
938         sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &reminder_interval_type);
939
940         delete_alarm_item(FUMO_INTERVAL, FUMO_INTERVAL_TYPE);
941
942         ret = add_alarm_item(reminder_interval_type, FUMO_INTERVAL, FUMO_INTERVAL_TYPE);
943         if (ret != DM_OK)
944                 goto error;
945
946         _DEBUG_TRACE("end");
947         if (ret != DM_OK) {
948                 _DEBUG_TRACE("schedule fail");
949                 goto error;
950         }
951
952         sync_agent_set_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, (void *)(&ret));
953
954         da_err = sync_agent_close_agent();
955         _DEBUG_TRACE("db close result : %d", da_err);
956         _INNER_FUNC_EXIT;
957         return err;
958
959  error:
960         err = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED;
961         _DEBUG_TRACE("error");
962
963         sync_agent_set_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, (void *)(&ret));
964
965         da_err = sync_agent_close_agent();
966         _DEBUG_TRACE("Done Close Mo DB\n");
967         _INNER_FUNC_EXIT;
968         return err;
969 }