[Internal: merge oma-dm-agent]
[framework/system/oma-dm-agent.git] / src / agent / dm-engine / fumo / fumo_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 #include <vconf.h>
19
20 /*sync-agent*/
21 #include <sync_agent.h>
22
23 /*dm-agent*/
24 #include "common/dm_common.h"
25 #include "common/util/util.h"
26 #include "mo-handler/dm_mo_common.h"
27 #include "mo-handler/dm_mo_handler.h"
28 #include "dm-engine/fumo/fumo_engine.h"
29 #include "dm-engine/dl-manager/fw_downloader.h"
30 #include "dm-engine/dl-manager/dd_object.h"
31 #include "ipc_common.h"
32 #include "ipc_agent.h"
33
34
35 #define MAX_FILE_SIZE 52428800     /* 50 MB */
36 //#define MAX_FILE_SIZE 2042626048 /* 1948 MB : (2*1024*1024*1024) - (100*1024*1024) */
37
38 #define DD_MULTI_LANGUAGE       "db/SyncML/oma-dm-service/DD-multilanguage"
39 #define DD_OBJECT_SIZE          "db/SyncML/oma-dm-service/DD-objectsize"
40
41 #ifndef OMADM_AGENT_LOG
42 #undef LOG_TAG
43 #define LOG_TAG "FUMO_ENGINE"
44 #endif
45
46 #define FOTA_LOW_BATTERY_LEVEL 50
47
48 static DM_ERROR _firmware_download(char *server_url, MEMORY_TYPE * memory_type, FUMO_Error * fumo_return);
49 static DM_ERROR _firmware_install(char *full_path, MEMORY_TYPE memory_type, FUMO_Error * fumo_return);
50 static DM_ERROR _firmware_update_popup(int result);
51 static DM_ERROR __check_low_battery();
52 static DM_ERROR __check_memory(long double file_size, MEMORY_TYPE * is_internal_memory);
53 static DM_ERROR ___get_max_file_size(int *max_file_size);
54 static DM_ERROR __check_max_file_size(int file_size);
55 static DM_ERROR _checking_rooting_opeartion(char *value);
56
57 DM_ERROR fumo_engine_state_operation(char *full_path, char *down_server, FUMO_Error * fumo_return)
58 {
59         _EXTERN_FUNC_ENTER;
60
61         DM_ERROR ret = DM_OK;
62
63         retvm_if((full_path) == NULL, COMMON_ERR_IS_NULL, "full_path is NULL!!");
64         _DEBUG_INFO("full_path [%s]", full_path);
65         retvm_if((down_server) == NULL, COMMON_ERR_IS_NULL, "down_server is NULL!!");
66         _DEBUG_INFO("down_server [%s]", down_server);
67
68         char *result_mo_type = NULL;
69         sync_agent_dev_return_e dci_ret_exec = SYNC_AGENT_DEV_RETURN_SUCCESS;
70         bool cancel_flag = false;
71         MEMORY_TYPE memory_type = MEMORY_INTERNAL;
72         char *fumo_state_data = NULL;
73         FUMO_State fumo_state = UNKNOWN;
74
75         retvm_if((full_path) == NULL, COMMON_ERR_IS_NULL, "full_path is NULL!!");
76
77         ret = get_mo_operationtype(full_path, &result_mo_type);
78         if (ret != DM_OK)
79                 goto error;
80
81         ret = get_current_fumo_state(full_path, &fumo_state_data);
82         if (ret != DM_OK)
83                 goto error;
84
85         if (chartoint(fumo_state_data, (int *)(&fumo_state)) == 0) {
86                 _DEBUG_INFO("error char to int value");
87                 ret = COMMON_ERR_IS_NULL;
88                 goto error;
89         }
90
91         _DEBUG_INFO(" -----------------------------------------------------------------------------------------------\n");
92         _DEBUG_INFO(" get fumo_state in db : %d\n", fumo_state);
93         _DEBUG_INFO(" -----------------------------------------------------------------------------------------------\n");
94
95         switch (fumo_state) {
96         case IDLE_START:
97         case DOWNLOAD_PROGRESSING:{
98
99                         _DEBUG_INFO(" DOWNLOAD_PROGRESSING\n");
100                         fumo_state = DOWNLOAD_PROGRESSING;
101
102                         cancel_flag = sync_agent_check_cancel_flag();
103                         if (cancel_flag != 0) {
104                                 ret = DM_OK;
105                                 *fumo_return = FUMO_USER_CANCELLED;
106                                 fumo_state = DOWNLOAD_FAILED;
107                                 goto error;
108                         }
109
110                         ret = _firmware_download(down_server, &memory_type, fumo_return);
111                         if (ret != DM_OK && ret != DM_DOWNLOAD_POPUP && ret != DM_RESUME_IDLE) {
112                                 fumo_state = DOWNLOAD_FAILED;
113                                 goto error;
114                         }
115
116                         _DEBUG_INFO("fimware donwload success : 200 , cancel : 562,  result is : %d\n", ret);
117
118                         cancel_flag = sync_agent_check_cancel_flag();
119                         if (cancel_flag != 0) {
120                                 ret = DM_OK;
121                                 *fumo_return = FUMO_USER_CANCELLED;
122                                 fumo_state = DOWNLOAD_FAILED;
123                                 goto error;
124                         }
125
126                         if (ret == DM_OK) {
127                                 _DEBUG_INFO("-----------download ok---------------");
128                                 fumo_state = DOWNLOAD_COMPLETE;
129
130                                 RESUME_STATUS download_clicked = RESUME_STATUS_INSTALL_BEFORE;
131                                 ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_DOWNLOAD_CLICK, &download_clicked);
132                                 _DEBUG_INFO("update engine status clolumn download click : %d", ret);
133                                 ret = DM_OK;
134                         } else if (ret == DM_ERR_REMINDER_INTERVAL || ret == DM_DOWNLOAD_POPUP || ret == DM_RESUME_IDLE) {
135                                 _DEBUG_INFO("-----------download popup---------------");
136                                 fumo_state = DOWNLOAD_PROGRESSING;
137                                 goto returnpart;
138                         } else {
139                                 _DEBUG_INFO("-----------download fail---------------\n");
140                                 *fumo_return = FUMO_USER_CANCELLED;
141                                 fumo_state = DOWNLOAD_FAILED;
142                         }
143
144                         ret = set_current_fumo_state(full_path, fumo_state);
145                         if (ret != DM_OK)
146                                 goto error;
147
148                         if (strcmp(result_mo_type, DM_FUMO_DOWNLOAD_OP) == 0) {
149                         } else if (strcmp(result_mo_type, DM_FUMO_UPDATE_OP) == 0) {
150                         } else if (strcmp(result_mo_type, DM_FUMO_DOWNLOADAND_UPDATE_OP) == 0) {
151                                 fumo_engine_state_operation(full_path, down_server, fumo_return);
152                                 _DEBUG_INFO("engine state result : %d", ret);
153                         }
154                 }
155                 break;
156         case DOWNLOAD_FAILED:
157                 _DEBUG_INFO(" DOWNLOAD_FAILED\n");
158                 goto error;
159
160                 break;
161         case DOWNLOAD_COMPLETE:{
162                         _DEBUG_INFO(" DOWNLOAD_COMPLETE\n");
163
164                         if (strcmp(result_mo_type, DM_FUMO_DOWNLOAD_OP) == 0) {
165                         } else if ((strcmp(result_mo_type, DM_FUMO_UPDATE_OP)) == 0 || strcmp(result_mo_type, DM_FUMO_DOWNLOADAND_UPDATE_OP) == 0) {
166                                 fumo_state = READY_TO_UPDATE;
167                                 ret = set_current_fumo_state(full_path, fumo_state);
168                                 if (ret != DM_OK)
169                                         goto error;
170
171                                 fumo_engine_state_operation(full_path, down_server, fumo_return);
172                                 _DEBUG_INFO("engine state result : %d", ret);
173                         }
174                 }
175                 break;
176         case READY_TO_UPDATE:{
177                         cancel_flag = sync_agent_check_cancel_flag();
178                         if (cancel_flag != 0) {
179                                 ret = DM_OK;
180                                 *fumo_return = FUMO_USER_CANCELLED;
181                                 fumo_state = DOWNLOAD_FAILED;
182                                 goto error;
183                         }
184
185                         ret = _firmware_install(full_path, memory_type, fumo_return);
186
187                         if (ret == DM_OK) {
188                                 /*if install success was rebooted */
189                                 _DEBUG_INFO("install fail");
190                                 goto error;
191                         } else if (ret == COMMON_ERR_IPC || ret == DM_LOW_BATTERY_ERROR) {
192                                 _DEBUG_INFO("-----------cancel or ipc error---------------");
193                                 fumo_state = UPDATE_FAILED_HAVE_DATA;
194                                 goto returnpart;
195                         } else if (ret == DM_ERR_REMINDER_INTERVAL || ret == DM_INSTALL_POPUP || ret == DM_RESUME_IDLE) {
196                                 _DEBUG_INFO("-----------download popup---------------");
197                                 fumo_state = READY_TO_UPDATE;
198                                 goto returnpart;
199                         } else {
200                                 _DEBUG_INFO("-----------install fail---------------\n");
201                                 *fumo_return = FUMO_USER_CANCELLED;
202                                 fumo_state = UPDATE_FAILED_HAVE_DATA;
203                         }
204
205                 }
206                 break;
207         case UPDATE_PROGRESSING:{
208
209                         cancel_flag = sync_agent_check_cancel_flag();
210                         if (cancel_flag != 0) {
211                                 ret = DM_OK;
212                                 *fumo_return = FUMO_USER_CANCELLED;
213                                 fumo_state = DOWNLOAD_FAILED;
214                                 goto error;
215                         }
216
217                         dci_ret_exec = sync_agent_execute_dev_function(2, "fota_result", 1, (int *)fumo_return);
218                         //*fumo_return = result;
219                         //*fumo_return = 202;
220                         _DEBUG_INFO("-----------------firmware update result : %d  fumo return : %d------------------", dci_ret_exec, (*fumo_return));
221                         //if (dci_ret_exec != SYNC_AGENT_DEV_RETURN_SUCCESS) {
222                         if ( (dci_ret_exec != SYNC_AGENT_DEV_RETURN_SUCCESS) || (*fumo_return != 200) ) {
223                                 fumo_state = UPDATE_FAILED_HAVE_DATA;
224                         } else {
225                                 fumo_state = UPDATE_SUCCESSFUL_HAVE_DATA;
226                         }
227
228                         ret = set_current_fumo_state(full_path, fumo_state);
229                         if (ret != DM_OK)
230                                 goto error;
231
232                         ret = fumo_engine_state_operation(full_path, down_server, fumo_return);
233                         _DEBUG_INFO("engine state result : %d", ret);
234                 }
235                 break;
236         case UPDATE_FAILED_HAVE_DATA:
237         case UPDATE_FAILED_NO_DATA:{
238
239                         delete_fumo_contents(memory_type);
240                         fumo_state = IDLE_START;
241                         set_current_fumo_state(full_path, fumo_state);
242 /*              if(ret != DM_OK)
243                         goto error;*/
244
245                         ret = _firmware_update_popup(FUMO_UPDATE_FAILED);
246                         if (ret != DM_OK) {
247                                 _DEBUG_INFO("_firmware_update result popup fail ");
248                         }
249
250                         /*ret = FUMO_UPDATE_FAILED; */
251                         *fumo_return = FUMO_UPDATE_FAILED;
252                         _DEBUG_INFO("update fail ");
253                 }
254                 break;
255         case UPDATE_SUCCESSFUL_HAVE_DATA:
256         case UPDATE_SUCCESSFUL_NO_DATA:{
257
258                         _DEBUG_INFO("----------------------------------------------------------firmware update success delete files-----------------------------------------------------------");
259                         delete_fumo_contents(memory_type);
260                         fumo_state = IDLE_START;
261                         set_current_fumo_state(full_path, fumo_state);
262 /*              if(ret != DM_OK)
263                         goto error;*/
264
265                         ret = _firmware_update_popup(FUMO_SUCCESS);
266                         if (ret != DM_OK) {
267                                 _DEBUG_INFO("_firmware_update result popup fail ");
268                         }
269
270                         /*ret = FUMO_SUCCESS; */
271                         *fumo_return = FUMO_SUCCESS;
272                         _DEBUG_INFO("update success ");
273                 }
274                 break;
275         default:
276                 break;
277         }
278
279         //      str_free(&result_mo_type);
280         _DEBUG_INFO(" end fumo state : %d\n", fumo_state);
281         str_free(&fumo_state_data);
282         str_free(&result_mo_type);
283
284         _EXTERN_FUNC_EXIT;
285         return ret;
286
287  returnpart:
288         _DEBUG_INFO("----------------------------------------------------------fumo download, install popup----------------------------------------------------------- %d", fumo_state);
289
290         set_current_fumo_state(full_path, fumo_state);
291         str_free(&fumo_state_data);
292         str_free(&result_mo_type);
293         _EXTERN_FUNC_EXIT;
294         return ret;
295
296  error:
297         _DEBUG_INFO("----------------------------------------------------------fumo error-----------------------------------------------------------");
298         delete_fumo_contents(memory_type);
299
300         fumo_state = IDLE_START;
301         set_current_fumo_state(full_path, fumo_state);
302         str_free(&fumo_state_data);
303         str_free(&result_mo_type);
304
305         _DEBUG_INFO(" end error : %d\n", ret);
306         _EXTERN_FUNC_EXIT;
307         return ret;
308 }
309
310 DM_ERROR fumo_exec(char *full_path, char *correlator, FUMO_Error * fumo_return)
311 {
312         _EXTERN_FUNC_ENTER;
313
314         DM_ERROR ret = DM_OK;
315
316         retvm_if((full_path) == NULL, COMMON_ERR_IS_NULL, "full_path is NULL!!");
317
318         char *result_mo_type = NULL;
319         ret = get_mo_operationtype(full_path, &result_mo_type);
320         if (ret != DM_OK)
321                 goto error;
322
323         if (result_mo_type == NULL) {
324                 _DEBUG_INFO("result_mo_type is null");
325                 ret = COMMON_ERR_IS_NULL;
326                 goto error;
327         }
328
329         if (strcmp(result_mo_type, DM_FUMO_DOWNLOAD_OP) == 0) {
330                 ret = firmware_download_opeartion(full_path, fumo_return);
331                 if (ret != DM_OK)
332                         goto error;
333         } else if (strcmp(result_mo_type, DM_FUMO_UPDATE_OP) == 0) {
334                 ret = firmware_update_operation(full_path, fumo_return);
335                 if (ret != DM_OK)
336                         goto error;
337         } else if (strcmp(result_mo_type, DM_FUMO_DOWNLOADAND_UPDATE_OP) == 0) {
338                 ret = firmware_downloadupdate_operation(full_path, fumo_return);
339                 if (ret != DM_OK)
340                         goto error;
341         } else {
342                 ret = vendor_dependency_firmware_operation(full_path, fumo_return);
343                 if (ret != DM_OK)
344                         goto error;
345         }
346
347         str_free(&result_mo_type);
348         _DEBUG_INFO(" end : %d", ret);
349         _EXTERN_FUNC_EXIT;
350         return ret;
351  error:
352
353         str_free(&result_mo_type);
354         _DEBUG_INFO(" end error : %d \n", ret);
355         _EXTERN_FUNC_EXIT;
356         return ret;
357 }
358
359 DM_ERROR fumo_replace(char *full_path, char *value, FUMO_Error * fumo_return)
360 {
361         _EXTERN_FUNC_ENTER;
362
363         DM_ERROR ret = DM_OK;
364
365         retvm_if((full_path) == NULL, COMMON_ERR_IS_NULL, "full_path is NULL!!");
366
367         char *result_mo_type = NULL;
368         ret = get_mo_operationtype(full_path, &result_mo_type);
369         if (ret != DM_OK)
370                 goto error;
371
372         if (result_mo_type == NULL) {
373                 _DEBUG_INFO("result_mo_type is null");
374                 ret = COMMON_ERR_IS_NULL;
375                 goto error;
376         } else {
377                 _DEBUG_INFO("result_mo_type [%s]", result_mo_type);
378         }
379
380         if (strcmp(result_mo_type, DM_FUMO_EXT_OP_DOCHECKINGROOTING) == 0) {
381                 ret = _checking_rooting_opeartion(value);
382                 if (ret != DM_OK) {
383                         (*fumo_return) = DM_ERR_COMMAND_NOT_ALLOWED;
384                         goto error;
385                 } else {
386                         (*fumo_return) = DM_OK;
387                 }
388         } else {
389                         goto error;
390         }
391
392         str_free(&result_mo_type);
393         _DEBUG_INFO(" end : %d", ret);
394         _EXTERN_FUNC_EXIT;
395         return ret;
396  error:
397
398         str_free(&result_mo_type);
399         _DEBUG_INFO(" end error : %d \n", ret);
400         _EXTERN_FUNC_EXIT;
401         return ret;
402 }
403
404 static DM_ERROR _firmware_download(char *server_url, MEMORY_TYPE * memory_type, FUMO_Error * fumo_return)
405 {
406         _INNER_FUNC_ENTER;
407
408         DM_ERROR ret = DM_OK;
409
410         DM_ERROR download_status = DM_ERR_USER_CANDELLED;
411         DM_ERROR installNofity_ret = DM_OK;
412         bool cancel_flag;
413         int config = -1;
414
415         char *download_folder = NULL;
416         int file_size = 0;
417         Download_Descriptor *download_descriptor = NULL;
418
419         engine_status *status = NULL;
420         int noti_res = 0;
421
422         if (server_url == NULL) {
423                 *fumo_return = FUMO_USER_CANCELLED;
424                 download_status = DM_ERR_INVALID_DESCRIPTOR;
425                 ret = COMMON_ERR_INTERNAL_NOT_DEFINED;
426                 goto error;
427         }
428
429         _DEBUG_TRACE("----------------------------------------------------------------------------------------------------- \n");
430         _DEBUG_TRACE(" server url : %s \n", server_url);
431         _DEBUG_TRACE("----------------------------------------------------------------------------------------------------- \n");
432
433         ret = Get_Engine_Status(FUMO_SERVICE_ENGINE, &status);
434         _DEBUG_INFO("Get_Engine_Status [%d]", ret);
435         if (ret != DM_OK || status == NULL) {
436                 *fumo_return = FUMO_USER_CANCELLED;
437                 download_status = DM_ERR_USER_CANDELLED;
438                 goto error;
439         }
440
441         _DEBUG_INFO("status->download_click [%d]", status->download_click);
442         switch (status->download_click) {
443         case RESUME_STATUS_DONWLOAD_BEFORE:     /*before click download popup */
444                 {
445                         _DEBUG_TRACE(" user interaction start \n");
446
447                         cancel_flag = sync_agent_check_cancel_flag();
448                         _DEBUG_TRACE(" cancel_flag : %d \n", cancel_flag);
449                         if (cancel_flag != 0) {
450                                 *fumo_return = FUMO_USER_CANCELLED;
451                                 download_status = DM_ERR_USER_CANDELLED;
452                                 ret = DM_OK;
453                                 goto error;
454                         }
455
456                         // DD download - description text
457                         download_descriptor = (Download_Descriptor *) calloc(1, sizeof(Download_Descriptor) + 1);
458                         if (download_descriptor == NULL) {
459                                 _DEBUG_TRACE("calloc failed !!");
460                                 ret = COMMON_ERR_ALLOC;
461                                 *fumo_return = FUMO_USER_CANCELLED;
462                                 download_status = DM_ERR_INVALID_DESCRIPTOR;
463                                 goto error;
464                         }
465
466                         ret = get_object_information(server_url, &file_size, &download_descriptor, &download_status);
467                         if (ret != DM_OK) {
468                                 *fumo_return = FUMO_USER_CANCELLED;
469                                 download_status = DM_ERR_INVALID_DESCRIPTOR;
470                                 goto error;
471                         } else {
472                                 if(download_descriptor->object_description != NULL) {
473                                         _DEBUG_INFO(" dd->object_description = %s \n", download_descriptor->object_description);
474                                         int vconf_result = 0;
475
476                                         vconf_result = vconf_set_str(DD_MULTI_LANGUAGE, download_descriptor->object_description);
477                                         if(vconf_result == 0) {
478                                                 _DEBUG_VERBOSE("vconf_set_str() success %s [%s]!!", DD_MULTI_LANGUAGE, download_descriptor->object_description);
479                                         } else {
480                                                 _DEBUG_VERBOSE("vconf_set_str() %s failed !!", DD_MULTI_LANGUAGE);
481                                         }
482                                 } else {
483                                         _DEBUG_INFO("dd->object_description is NULL");
484                                 }
485
486                                 if(download_descriptor->object_size != 0) {
487                                         _DEBUG_INFO(" dd->object_size = %d \n", download_descriptor->object_size);
488                                         int vconf_result = 0;
489
490                                         vconf_result = vconf_set_int(DD_OBJECT_SIZE, download_descriptor->object_size);
491                                         if(vconf_result == 0) {
492                                                 _DEBUG_VERBOSE("vconf_set_int() success %s [%d]!!", DD_OBJECT_SIZE, download_descriptor->object_size);
493                                         } else {
494                                                 _DEBUG_VERBOSE("vconf_set_int() %s failed !!", DD_OBJECT_SIZE);
495                                         }
496                                 } else {
497                                         _DEBUG_INFO("dd->object_size is NULL");
498                                 }
499                         }
500                         //
501
502
503                         int noti_res;
504                         _DEBUG_TRACE("waiting connect to server success in firmware download\n");
505                         noti_res = noti_download(file_size);
506                         _DEBUG_TRACE("download noti response : %d \n ", noti_res);
507
508                         if (noti_res == RESPONSE_TYPE_OK) {
509                                 ret = DM_DOWNLOAD_POPUP;
510                                 goto returnpart;
511
512                         } else {
513                                 _DEBUG_TRACE("------------------------------------------------------downlaod popup noti error--------------------------------------------\n");
514                                 // error in noti-process
515                                 *fumo_return = FUMO_USER_CANCELLED;
516                                 download_status = DM_ERR_USER_CANDELLED;
517                                 ret = COMMON_ERR_IPC;
518                                 goto error;
519                         }
520                 }
521                 break;
522         case RESUME_STATUS_DOWNLOAD:    /*after click download popup */
523                 {
524                         _DEBUG_TRACE("------------------------------------------------------download button click---------------------------------------------\n");
525
526                         download_descriptor = (Download_Descriptor *) calloc(1, sizeof(Download_Descriptor) + 1);
527                         if (download_descriptor == NULL) {
528                                 _DEBUG_TRACE("calloc failed !!");
529                                 ret = COMMON_ERR_ALLOC;
530                                 *fumo_return = FUMO_USER_CANCELLED;
531                                 download_status = DM_ERR_INVALID_DESCRIPTOR;
532                                 goto error;
533                         }
534
535                         ret = get_object_information(server_url, &file_size, &download_descriptor, &download_status);
536                         if (ret != DM_OK) {
537                                 *fumo_return = FUMO_USER_CANCELLED;
538                                 download_status = DM_ERR_INVALID_DESCRIPTOR;
539                                 goto error;
540                         }
541                         _DEBUG_TRACE(" user interaction start \n");
542
543                         cancel_flag = sync_agent_check_cancel_flag();
544                         _DEBUG_TRACE(" cancel_flag : %d \n", cancel_flag);
545                         if (cancel_flag != 0) {
546                                 *fumo_return = FUMO_USER_CANCELLED;
547                                 download_status = DM_ERR_USER_CANDELLED;
548                                 ret = DM_OK;
549                                 goto error;
550                         }
551
552                         /*wifi config */
553                         config = get_wifi_only_config();
554
555                         /*battery state check */
556                         ret = __check_low_battery();
557                         _DEBUG_TRACE("ret : %d \n", ret);
558                         if (ret != DM_OK) {
559                                 ret = DM_OK;
560                                 *fumo_return = FUMO_USER_CANCELLED;
561                                 goto error;
562                         }
563
564                         _DEBUG_TRACE("======================================================");
565                         _DEBUG_TRACE("object size [%d]\n", file_size);
566                         _DEBUG_TRACE("wifi only config [%d]\n", config);
567                         _DEBUG_TRACE("======================================================");
568
569                         ret = __check_memory(file_size, memory_type);
570                         //ret = DM_OVER_MEMORY_ERROR; // for memory not enough - UI testing
571                         if (ret != DM_OK) {
572                                 noti_res = noti_memory_full((int)file_size);
573                                 if (noti_res == RESPONSE_TYPE_OK) {
574                                         _DEBUG_TRACE("memory full popup success");
575                                 } else {
576                                         _DEBUG_TRACE("memory full popup fail");
577                                 }
578                                 download_status = DM_ERR_INSUFFICIENT_MEMORY;
579                                 *fumo_return = FUMO_USER_CANCELLED;
580                                 //ret = DM_OK;
581                                 goto error;
582                         }
583
584                         if (config == -1) {
585                                 _DEBUG_TRACE("get wifi only config error");
586                                 *fumo_return = FUMO_MALFORMED_OR_BAD_URL;
587                                 download_status = DM_ERR_USER_CANDELLED;
588                                 ret = DM_WIFI_ONLY_ERROR;
589                                 goto error;
590                         } else if (config == 0) {
591                                 _DEBUG_TRACE("wifi config = 0");
592                                 int wifi_ret = 0;
593                                 wifi_ret = get_wifi_state();
594                                 _DEBUG_TRACE("wifi mode : %d", wifi_ret);
595                                 //wifi_ret = 4; // If delta size is big.. for wifi mode test
596                                 //_DEBUG_TRACE("wifi mode : %d", wifi_ret); // If delta size is big.. for wifi mode test
597
598                                 if (wifi_ret != 1) {
599                                         _DEBUG_TRACE("3g mode");
600
601                                         ret = __check_max_file_size(file_size);
602                                         if (ret != DM_OK) {
603                                                 _DEBUG_TRACE("get max file size error");
604                                                 *fumo_return = FUMO_DOWNLOAD_FAILS_DUE_TO_DEVICE_OUT_OF_MEMORY;
605                                                 download_status = DM_ERR_USER_CANDELLED;
606                                                 ret = DM_WIFI_ONLY_ERROR;
607                                                 goto error;
608                                         }
609                                 } else {
610                                         _DEBUG_TRACE("wifi mode");
611                                 }
612                         } else {
613                                 _DEBUG_TRACE("wifi config = 1");
614                                 _DEBUG_TRACE("wifi only mode");
615                         }
616
617                         ret = get_fota_download_dir((*memory_type), &download_folder);
618                         if (ret != DM_OK) {
619                                 *fumo_return = FUMO_DOWNLOAD_FAILS_DUE_TO_DEVICE_OUT_OF_MEMORY;
620                                 download_status = DM_ERR_INSUFFICIENT_MEMORY;
621                                 goto error;
622                         }
623                         _DEBUG_TRACE(" download ok \n ");
624
625                         char *downloadUrl = NULL;
626                         ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_SERVER_URL, downloadUrl);
627                         if (ret != DM_OK) {
628                                 *fumo_return = FUMO_USER_CANCELLED;
629                                 download_status = DM_ERR_USER_CANDELLED;
630                                 goto error;
631                         }
632                         /* remove remind interval */
633                         delete_alarm_item(FUMO_INTERVAL, FUMO_INTERVAL_TYPE);
634                         _DEBUG_TRACE(" delete fumo reminder in config db ");
635
636                         //FOTASaveDir //FOTADownDir
637                         DOWNLOAD_FILE_STATUS file_status = 0;
638                         Data_Resume_Infomation *data_resume_info = NULL;
639                         ret = check_file_resume(download_folder, &file_status, download_descriptor, &data_resume_info);
640                         if (ret != DM_OK) {
641                                 *fumo_return = FUMO_MALFORMED_OR_BAD_URL;
642                                 download_status = DM_ERR_USER_CANDELLED;
643                                 goto error;
644                         }
645
646                         _DEBUG_TRACE(" file_status = %d \n", file_status);
647                         /*was maked by sooyi */
648                         if (file_status != EXIST_COMPLETED_FILE) {
649                                 char *object_path = 0;
650
651                                 if (config == -1) {
652                                         _DEBUG_TRACE("get wifi only config error");
653                                         *fumo_return = FUMO_MALFORMED_OR_BAD_URL;
654                                         download_status = DM_ERR_USER_CANDELLED;
655                                         ret = DM_WIFI_ONLY_ERROR;
656                                         goto error;
657                                 } else {
658                                         _DEBUG_TRACE("get wifi only config value : %d", config);
659
660                                         ret = download_object(download_folder, &object_path, data_resume_info, config, download_descriptor, &download_status);
661                                         _DEBUG_TRACE("download object : %s", object_path);
662                                         _DEBUG_TRACE(" download_object result : %d \n", ret);
663                                         if (ret != DM_OK) {
664                                                 if (ret == DM_WIFI_ONLY_ERROR) {
665                                                         _DEBUG_TRACE("send_DL_Msg() err [%d]\n", ret);
666                                                         /* ipc wifi only pop up */
667                                                         noti_res = noti_wifi_only_download_fail();
668
669                                                         if (noti_res == RESPONSE_TYPE_OK) {
670                                                                 _DEBUG_TRACE("send_wifi only fail ipc success");
671                                                         } else {
672                                                                 _DEBUG_TRACE("send_wifi only fail ipc fail");
673                                                         }
674                                                 }
675                                                 *fumo_return = FUMO_USER_CANCELLED;
676                                                 download_status = DM_ERR_USER_CANDELLED;
677                                                 goto error;
678                                         } else {
679                                                 //do nothing
680                                         }
681
682                                         installNofity_ret = send_donwload_status(download_status, download_descriptor);
683                                         _DEBUG_TRACE("send installNotify : %d", installNofity_ret);
684                                 }
685                         } else {
686                                 _DEBUG_TRACE(" file is exist\n");
687                         }
688                 }
689                 break;
690         case RESUME_STATUS_DOWNLOAD_LATER:      /*later button clicked */
691                 {
692                         _DEBUG_TRACE("------------------------------------------------------later button click---------------------------------------------\n");
693
694                         download_descriptor = (Download_Descriptor *) calloc(1, sizeof(Download_Descriptor) + 1);
695                         if (download_descriptor == NULL) {
696                                 _DEBUG_TRACE("calloc failed !!");
697                                 ret = COMMON_ERR_ALLOC;
698                                 *fumo_return = FUMO_USER_CANCELLED;
699                                 download_status = DM_ERR_INVALID_DESCRIPTOR;
700                                 goto error;
701                         }
702
703                         ret = get_object_information(server_url, &file_size, &download_descriptor, &download_status);
704                         if (ret != DM_OK) {
705                                 *fumo_return = FUMO_USER_CANCELLED;
706                                 download_status = DM_ERR_INVALID_DESCRIPTOR;
707                                 goto error;
708                         }
709
710                         installNofity_ret = send_donwload_status(download_status, download_descriptor);
711                         _DEBUG_TRACE("send installNotify : %d", installNofity_ret);
712
713                         RESUME_STATUS download_clicked = RESUME_STATUS_DOWNLOAD_IDLE;
714                         ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_DOWNLOAD_CLICK, &download_clicked);
715                         _DEBUG_TRACE("update engine status clolumn download click : %d", ret);
716
717                         *fumo_return = FUMO_USER_CANCELLED;
718                         download_status = DM_ERR_USER_CANDELLED;
719                         ret = DM_ERR_REMINDER_INTERVAL;
720                 }
721                 break;
722         case RESUME_STATUS_DOWNLOAD_IDLE:
723         default:
724                 {
725                         /*case RESUME_STATUS_IDLE, default */
726                         ret = DM_RESUME_IDLE;
727                         goto returnpart;
728
729                         _DEBUG_TRACE("----------------------------------------------------bad flow--------------------------------------------------------------------");
730                 }
731
732                 break;
733         }
734
735         if (status != NULL)
736                 Free_Memory_Engine_Status(&status, 1);
737
738         if (download_descriptor != NULL) {
739                 _DEBUG_TRACE("__free_Download_Descriptor()\n");
740                 free_Download_Descriptor(&download_descriptor);
741         }
742         str_free(&download_folder);
743
744         _INNER_FUNC_EXIT;
745
746         return ret;
747
748  returnpart:
749
750         if (status != NULL)
751                 Free_Memory_Engine_Status(&status, 1);
752
753         if (download_descriptor != NULL) {
754                 _DEBUG_TRACE("__free_Download_Descriptor()\n");
755                 free_Download_Descriptor(&download_descriptor);
756         }
757         str_free(&download_folder);
758
759         _DEBUG_TRACE(" end error : %d \n", ret);
760         _INNER_FUNC_EXIT;
761         return ret;
762
763  error:
764
765         if (status != NULL)
766                 Free_Memory_Engine_Status(&status, 1);
767
768         installNofity_ret = send_donwload_status(download_status, download_descriptor);
769         _DEBUG_INFO("send installNotify : %d", installNofity_ret);
770
771         if (download_descriptor != NULL) {
772                 _DEBUG_INFO("__free_Download_Descriptor()\n");
773                 free_Download_Descriptor(&download_descriptor);
774         }
775         str_free(&download_folder);
776
777         _DEBUG_INFO(" end error : %d \n", ret);
778         _INNER_FUNC_EXIT;
779         return ret;
780
781 }
782
783 static DM_ERROR _firmware_install(char *full_path, MEMORY_TYPE memory_type, FUMO_Error * fumo_return)
784 {
785         _INNER_FUNC_ENTER;
786
787         DM_ERROR ret = DM_OK;
788
789         if (full_path == NULL) {
790                 *fumo_return = FUMO_USER_CANCELLED;
791                 goto error;
792         }
793
794         sync_agent_dev_return_e dci_ret_flag = SYNC_AGENT_DEV_RETURN_SUCCESS;
795         engine_status *status = NULL;
796         int noti_res = 0;
797         FUMO_State fumo_state = READY_TO_UPDATE;
798
799         ret = Get_Engine_Status(FUMO_SERVICE_ENGINE, &status);
800         _DEBUG_INFO("Get_Engine_Status [%d]", ret);
801         if (ret != DM_OK || status == NULL) {
802                 *fumo_return = FUMO_USER_CANCELLED;
803                 goto error;
804         }
805
806         _DEBUG_INFO("status->download_click [%d]", status->download_click);
807         switch (status->download_click) {
808         case RESUME_STATUS_INSTALL_BEFORE:
809                 {
810                                 /** install UI control */
811                         noti_res = noti_install();
812                         if (noti_res == RESPONSE_TYPE_OK) {
813                                 ret = DM_INSTALL_POPUP;
814                                 goto returnpart;
815                         } else {
816                                 // error in noti-process
817                                 ret = COMMON_ERR_IPC;
818                                 *fumo_return = FUMO_USER_CANCELLED;
819                                 goto error;
820                         }
821                 }
822                 break;
823         case RESUME_STATUS_INSTALL:
824                 {
825                         /* battery state check */
826                         ret = __check_low_battery();
827                         if (ret != DM_OK) {
828                                 ret = DM_LOW_BATTERY_ERROR;
829                                 *fumo_return = FUMO_USER_CANCELLED;
830                                 goto error;
831                         }
832
833                         _DEBUG_TRACE("------------------fota install ok------------------");
834                         _DEBUG_TRACE(" fota flag api \n");
835                         delete_alarm_item(FUMO_INTERVAL, FUMO_INTERVAL_TYPE);
836                         _DEBUG_TRACE(" delete fumo reminder in config db ");
837
838                         fumo_state = UPDATE_PROGRESSING;
839                         ret = set_current_fumo_state(full_path, fumo_state);
840                         if (ret != DM_OK) {
841                                 *fumo_return = FUMO_USER_CANCELLED;
842                                 goto error;
843                         }
844
845                         dci_ret_flag = sync_agent_execute_dev_function(2, "fota_flag", 1, memory_type);
846                         //dci_ret_flag= SYNC_AGENT_DEV_RETURN_SUCCESS;
847                         _DEBUG_TRACE(" fota flag result : %d \n", dci_ret_flag);
848                         if (dci_ret_flag != SYNC_AGENT_DEV_RETURN_SUCCESS) {
849                                 _DEBUG_TRACE(" fota flag fail!!!!!!!!!!!! \n");
850                                 *fumo_return = FUMO_FAILED_VALIDATION;
851
852                                 ret = set_current_fumo_state(full_path, fumo_state);
853                                 if (ret != DM_OK) {
854                                         *fumo_return = FUMO_USER_CANCELLED;
855                                         goto error;
856                                 }
857
858                                 goto error;
859                         } else {
860                                 //for reboot
861                                 _DEBUG_TRACE(" -------------------------------------------------------------------- \n");
862                                 _DEBUG_TRACE(" fota install to be rebooting l!!!!!!!!!!!! \n");
863                                 _DEBUG_TRACE(" -------------------------------------------------------------------- \n");
864                                 sleep(1);
865                                 exit(0);
866                                 break;
867                         }
868                 }
869                 break;
870         case RESUME_STATUS_INSTALL_LATER:
871                 {
872                         //cancle to install
873                         _DEBUG_TRACE("------------------canceled install------------------");
874
875                         *fumo_return = FUMO_USER_CANCELLED;
876
877                         RESUME_STATUS download_clicked = RESUME_STATUS_INSTALL_IDLE;
878                         ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_DOWNLOAD_CLICK, &download_clicked);
879                         _DEBUG_TRACE("update engine status clolumn download click : %d", ret);
880                         /*fumo_state = IDLE_START;
881                            ret = set_current_fumo_state(full_path, fumo_state);
882                            if(ret != DM_OK)
883                            goto error; */
884                         ret = DM_ERR_REMINDER_INTERVAL;
885                         goto error;
886                 }
887                 break;
888         case RESUME_STATUS_INSTALL_IDLE:
889         default:
890                 {
891                         ret = DM_RESUME_IDLE;
892                         _DEBUG_TRACE("----------------------------------------------------install later --------------------------------------------------------------------");
893                         goto returnpart;
894                 }
895                 break;
896         }
897
898         if (status != NULL) {
899                 Free_Memory_Engine_Status(&status, 1);
900         }
901
902         _INNER_FUNC_EXIT;
903         return ret;
904
905  returnpart:
906
907         if (status != NULL) {
908                 Free_Memory_Engine_Status(&status, 1);
909         }
910         _DEBUG_INFO(" return part : %d \n", ret);
911         _INNER_FUNC_EXIT;
912         return ret;
913
914  error:
915
916         if (status != NULL) {
917                 Free_Memory_Engine_Status(&status, 1);
918         }
919         _DEBUG_INFO(" end error : %d \n", ret);
920         _INNER_FUNC_EXIT;
921         return ret;
922 }
923
924 static DM_ERROR _firmware_update_popup(int result)
925 {
926         _INNER_FUNC_ENTER;
927
928         DM_ERROR ret = DM_OK;
929         _DEBUG_INFO("result [%d]", result);
930         int noti_res = 0;
931         noti_res = noti_update_result(result);
932         if (noti_res == RESPONSE_TYPE_OK) {
933                 ret = DM_OK;
934         } else {
935                 // error in noti-process
936                 ret = COMMON_ERR_IPC;
937         }
938
939         _DEBUG_INFO(" end error : %d \n", ret);
940         _INNER_FUNC_EXIT;
941         return ret;
942 }
943
944 DM_ERROR firmware_download_opeartion(char *full_path, FUMO_Error * fumo_return)
945 {
946         _EXTERN_FUNC_ENTER;
947         /*call DL module */
948         _DEBUG_INFO(" start\n");
949
950         DM_ERROR ret = DM_OK;
951
952         if (full_path == NULL) {
953                 (*fumo_return) = FUMO_MALFORMED_OR_BAD_URL;
954                 goto error;
955         }
956
957         char *full_path_pkgurl = NULL;
958         full_path_pkgurl = g_strdup_printf("%s%s", full_path, DM_FUMO_DWONLOAD_OP_PKGURL);
959
960         char *down_server = NULL;
961         ret = get_mo_data(full_path_pkgurl, &down_server);
962         if (ret != DM_OK) {
963                 goto error;
964         }
965
966         if (down_server == NULL) {
967                 _DEBUG_INFO("not found download server");
968                 (*fumo_return) = FUMO_MALFORMED_OR_BAD_URL;
969                 //ret =
970                 goto error;
971         }
972 #ifdef _DM_BUNDANG_TEST
973         /*redirection code */
974         char *pkg_url = get_new_uri(down_server);
975
976         ret = fumo_engine_state_operation(full_path, pkg_url, fumo_return);
977         if (ret != DM_OK)
978                 goto error;
979 #else
980         ret = fumo_engine_state_operation(full_path, down_server, fumo_return);
981         if (ret != DM_OK)
982                 goto error;
983 #endif
984         /*
985          * return server ret
986          */
987
988         str_free(&full_path_pkgurl);
989         str_free(&down_server);
990
991         _EXTERN_FUNC_EXIT;
992         return ret;
993
994  error:
995         str_free(&full_path_pkgurl);
996         str_free(&down_server);
997
998         _DEBUG_INFO(" end error : %d \n", ret);
999         _EXTERN_FUNC_EXIT;
1000         return ret;
1001 }
1002
1003 DM_ERROR firmware_update_operation(char *full_path, FUMO_Error * fumo_return)
1004 {
1005         _EXTERN_FUNC_ENTER;
1006
1007         DM_ERROR ret = DM_OK;
1008
1009         if (full_path == NULL) {
1010                 (*fumo_return) = FUMO_MALFORMED_OR_BAD_URL;
1011                 goto error;
1012         }
1013
1014         char *full_path_pkgurl = NULL;
1015         full_path_pkgurl = g_strdup_printf("%s%s", full_path, DM_FUMO_UPDATE_PKG_OP_DATA);
1016
1017         char *down_server = NULL;
1018         ret = get_mo_data(full_path_pkgurl, &down_server);
1019         if (ret != DM_OK) {
1020                 goto error;
1021         }
1022
1023         if (down_server == NULL) {
1024                 _DEBUG_INFO("not found download server");
1025                 (*fumo_return) = FUMO_MALFORMED_OR_BAD_URL;
1026                 //ret =
1027                 goto error;
1028         }
1029 #ifdef _DM_BUNDANG_TEST
1030         /*redirection code */
1031         char *pkg_url = get_new_uri(down_server);
1032
1033         ret = fumo_engine_state_operation(full_path, pkg_url, fumo_return);
1034         if (ret != DM_OK)
1035                 goto error;
1036 #else
1037         ret = fumo_engine_state_operation(full_path, down_server, fumo_return);
1038         if (ret != DM_OK)
1039                 goto error;
1040 #endif
1041
1042         /*
1043          * return server ret
1044          */
1045
1046         str_free(&full_path_pkgurl);
1047         str_free(&down_server);
1048
1049         _EXTERN_FUNC_EXIT;
1050         return ret;
1051
1052  error:
1053         str_free(&full_path_pkgurl);
1054         str_free(&down_server);
1055
1056         _DEBUG_INFO(" end error : %d \n", ret);
1057         _EXTERN_FUNC_EXIT;
1058         return ret;
1059 }
1060
1061 DM_ERROR firmware_downloadupdate_operation(char *full_path, FUMO_Error * fumo_return)
1062 {
1063         _EXTERN_FUNC_ENTER;
1064
1065         DM_ERROR ret = DM_OK;
1066
1067         if (full_path == NULL) {
1068                 _DEBUG_INFO(" full path = null\n");
1069                 ret = COMMON_ERR_INTERNAL_NOT_DEFINED;
1070                 (*fumo_return) = FUMO_MALFORMED_OR_BAD_URL;
1071                 goto error;
1072         }
1073
1074         char *full_path_pkgurl = NULL;
1075         full_path_pkgurl = g_strdup_printf("%s%s", full_path, DM_FUMO_DOWNLOADAND_UPDATE_OP_PKGURL);
1076
1077         char *down_server = NULL;
1078         ret = get_mo_data(full_path_pkgurl, &down_server);
1079         _DEBUG_INFO(" server_url : %s\n", down_server);
1080         if (ret != DM_OK) {
1081                 goto error;
1082         }
1083
1084         if (down_server == NULL) {
1085                 _DEBUG_INFO("not found download server");
1086                 (*fumo_return) = FUMO_MALFORMED_OR_BAD_URL;
1087                 //ret =
1088                 goto error;
1089         }
1090 #ifdef _DM_BUNDANG_TEST
1091         /*redirection code */
1092         char *pkg_url = get_new_uri(down_server);
1093
1094         ret = fumo_engine_state_operation(full_path, pkg_url, fumo_return);
1095         if (ret != DM_OK) {
1096                 goto error;
1097         }
1098 #else
1099         ret = fumo_engine_state_operation(full_path, down_server, fumo_return);
1100         if (ret != DM_OK) {
1101                 goto error;
1102         }
1103 #endif
1104         /*
1105          * return server ret
1106          */
1107
1108         str_free(&full_path_pkgurl);
1109         str_free(&down_server);
1110
1111         _EXTERN_FUNC_EXIT;
1112         return ret;
1113
1114  error:
1115         str_free(&full_path_pkgurl);
1116         str_free(&down_server);
1117
1118         _DEBUG_INFO(" end error : %d \n", ret);
1119         _EXTERN_FUNC_EXIT;
1120         return ret;
1121 }
1122
1123 DM_ERROR vendor_dependency_firmware_operation(char *full_path, FUMO_Error * fumo_return)
1124 {
1125         _EXTERN_FUNC_ENTER;
1126
1127         DM_ERROR ret = DM_OK;
1128         int check_operation = 1;
1129
1130         if (full_path == NULL) {
1131                 ret = DM_ERR_COMMAND_FAILED;
1132                 *fumo_return = FUMO_USER_CANCELLED;
1133                 goto error;
1134         }
1135
1136         sync_agent_dm_mo_error_e ext_return;
1137         ext_return = sync_agent_execute_mo_ext(full_path, (int *)fumo_return, check_operation);
1138         if (ext_return != SYNC_AGENT_DM_MO_SUCCESS) {
1139                 ret = DM_ERR_COMMAND_FAILED;
1140                 *fumo_return = FUMO_USER_CANCELLED;
1141                 goto error;
1142         }
1143
1144         _EXTERN_FUNC_EXIT;
1145         return ret;
1146  error:
1147
1148         _DEBUG_INFO(" end error : %d\n", ret);
1149         _EXTERN_FUNC_EXIT;
1150         return ret;
1151 }
1152
1153 DM_ERROR get_current_fumo_state(char *full_path, char **fumo_state_data)
1154 {
1155         _EXTERN_FUNC_ENTER;
1156         DM_ERROR ret = DM_OK;
1157
1158         retvm_if((full_path) == NULL, COMMON_ERR_IS_NULL, "full_path is NULL!!");
1159
1160         char *fumo_root = NULL;
1161         char *fumo_state_url = NULL;
1162
1163         //ret = get_mo_servicetype(full_path, &fumo_root);
1164         ret = get_mo_root_path(full_path, &fumo_root);
1165         if (ret != DM_OK) {
1166                 ret = COMMON_ERR_INTERNAL_NOT_DEFINED;
1167                 goto error;
1168         }
1169         fumo_state_url = g_strdup_printf("%s%s", fumo_root, DM_FUMO_STATE_OP);
1170
1171         ret = get_mo_data(fumo_state_url, fumo_state_data);
1172         if (ret != DM_OK) {
1173                 ret = COMMON_ERR_GET_TYPE_NOT_FOUND;
1174                 goto error;
1175         }
1176
1177         str_free(&fumo_state_url);
1178
1179         _EXTERN_FUNC_EXIT;
1180         return ret;
1181  error:
1182         str_free(&fumo_state_url);
1183
1184         _DEBUG_INFO(" end error : %d\n", ret);
1185         _EXTERN_FUNC_EXIT;
1186         return ret;
1187 }
1188
1189 DM_ERROR set_current_fumo_state(char *full_path, FUMO_State fumo_state)
1190 {
1191         _EXTERN_FUNC_ENTER;
1192
1193         DM_ERROR ret = DM_OK;
1194
1195         retvm_if((full_path) == NULL, COMMON_ERR_IS_NULL, "full_path is NULL!!");
1196
1197         char *fumo_root = NULL;
1198         char *fumo_state_url = NULL;
1199         char *fumo_state_data = NULL;
1200
1201         //ret = get_mo_servicetype(full_path, &fumo_root);
1202         ret = get_mo_root_path(full_path, &fumo_root);
1203         if (ret != DM_OK) {
1204                 goto error;
1205         }
1206
1207         fumo_state_url = g_strdup_printf("%s%s", fumo_root, DM_FUMO_STATE_OP);
1208         fumo_state_data = g_strdup_printf("%d", fumo_state);
1209
1210         _DEBUG_INFO(" fumo_state : %d\n", fumo_state);
1211
1212         //sync_agent_dm_mo_error_e mo_ret  = sync_agent_begin_transaction_mo();
1213         ret = replace_mo_data(fumo_state_url, fumo_state_data);
1214         //mo_ret = sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_COMMIT);
1215         if (ret != DM_OK)
1216                 goto error;
1217
1218         str_free(&fumo_state_url);
1219         str_free(&fumo_state_data);
1220
1221         _EXTERN_FUNC_EXIT;
1222         return ret;
1223
1224  error:
1225         str_free(&fumo_state_url);
1226         str_free(&fumo_state_data);
1227
1228         _DEBUG_INFO(" end error : %d\n", ret);
1229         _EXTERN_FUNC_EXIT;
1230         return ret;
1231 }
1232
1233 static DM_ERROR __check_low_battery()
1234 {
1235         _INNER_FUNC_ENTER;
1236
1237         DM_ERROR ret = DM_OK;
1238         char *battery_level = 0;
1239
1240         ret = get_battery_state(&battery_level);
1241         if (ret != DM_OK)
1242                 goto error;
1243
1244         int int_battery_level = 0;
1245         if (battery_level != NULL) {
1246                 int err;
1247                 err = chartoint((battery_level), &int_battery_level);
1248                 if (err == 1) {
1249                         _DEBUG_VERBOSE("battery level : %d ", int_battery_level);
1250                         if (FOTA_LOW_BATTERY_LEVEL > int_battery_level) {
1251                                 int noti_ret = 0;
1252                                 _DEBUG_VERBOSE("batter : %s, low battery : %d", battery_level, FOTA_LOW_BATTERY_LEVEL);
1253                                 noti_ret = noti_low_battery(battery_level);
1254                                 _DEBUG_VERBOSE("noti low battery : %d", noti_ret);
1255
1256                                 goto error;
1257                         } else {
1258                                 //do nothing
1259                         }
1260                 } else {
1261                         _DEBUG_VERBOSE("battery level is null");
1262                         ret = COMMON_ERR_IS_NULL;
1263                         goto error;
1264                 }
1265         } else {
1266                 _DEBUG_VERBOSE("battery level is null");
1267                 ret = COMMON_ERR_IS_NULL;
1268                 goto error;
1269         }
1270         _DEBUG_VERBOSE("end");
1271         return ret;
1272  error:
1273         _DEBUG_VERBOSE("end error : %d", DM_LOW_BATTERY_ERROR);
1274         _INNER_FUNC_EXIT;
1275         return DM_LOW_BATTERY_ERROR;
1276 }
1277
1278 static DM_ERROR __check_memory(long double file_size, MEMORY_TYPE * is_internal_memory)
1279 {
1280         _INNER_FUNC_ENTER;
1281
1282         DM_ERROR ret = DM_OK;
1283         int ipc_ret = 0;
1284         int existed_sd;
1285 //      long double need_size = file_size * 2.1;
1286         long double need_size = file_size + 1024*1024*3;
1287
1288         ret = compare_memory_space(FOTA_DELTA_INTERNAL_STORAGE, need_size);
1289
1290         if (ret != DM_OK) {
1291                 ret = existed_sd_card_memory(&existed_sd);
1292                 if (existed_sd == 0 || ret != DM_OK) {
1293                         /* ui ->not existed sd card or make folder error */
1294                         ipc_ret = noti_over_max_file_size((int)file_size);
1295                         if (ipc_ret == RESPONSE_TYPE_OK) {
1296                                 _DEBUG_VERBOSE("file size over the memory");
1297                         } else {
1298                                 _DEBUG_VERBOSE("file size over the memory ipc fail");
1299                         }
1300                         _INNER_FUNC_EXIT;
1301                         return DM_OVER_MEMORY_ERROR;
1302                 }
1303
1304                 /* ui -> do u want to use sd_card? */
1305                 ipc_ret = noti_memory_full((int)need_size);
1306                 if (ipc_ret == RESPONSE_TYPE_OK) {
1307
1308                         //FOTA_DELTA_SD_INTERNAL_STORAGE
1309                         ret = compare_memory_space(FOTA_DELTA_SD_EXTERNAL_STORAGE, need_size);
1310                         if (ret == DM_MEMORY_ERROR) {
1311                                 /* ui ->  sd_card full */
1312                                 ipc_ret = noti_over_max_file_size((int)file_size);
1313                                 if (ipc_ret == RESPONSE_TYPE_OK) {
1314                                         _DEBUG_VERBOSE("file size over the memory");
1315                                 } else {
1316                                         _DEBUG_VERBOSE("file size over the memory ipc fail");
1317                                 }
1318                                 _INNER_FUNC_EXIT;
1319                                 return DM_OVER_MEMORY_ERROR;
1320                         } else {
1321                                 _DEBUG_VERBOSE("save in sd memory card");
1322                         }
1323
1324                 } else {
1325                         _DEBUG_VERBOSE("memory full ipc fail");
1326                         _INNER_FUNC_EXIT;
1327                         return DM_OVER_MEMORY_ERROR;
1328                 }
1329                 /*sd card path */
1330                 (*is_internal_memory) = MEMORY_SD_CARD;
1331         } else {
1332
1333                 /*internal memory path */
1334                 (*is_internal_memory) = MEMORY_INTERNAL;
1335         }
1336
1337         _INNER_FUNC_EXIT;
1338         return DM_OK;
1339 }
1340
1341 static DM_ERROR ___get_max_file_size(int *max_file_size)
1342 {
1343         _INNER_FUNC_ENTER;
1344
1345         int err = 0;
1346         char *required_contents = NULL;
1347         unsigned long size_return = 0;
1348
1349         err = sync_agent_is_existing_fs(MAX_DELTA_FILE_SIZE);
1350         /*define value when this is file not existed */
1351         if (err == 0) {
1352                 _DEBUG_INFO("max file size : 50MB");
1353                 *max_file_size = MAX_FILE_SIZE;
1354                 _INNER_FUNC_EXIT;
1355                 return DM_OK;
1356         }
1357
1358         /*value when this is file existed */
1359         err = sync_agent_read_whole_file(MAX_DELTA_FILE_SIZE, &required_contents, &size_return);
1360         if (err == 1) {
1361                 _DEBUG_INFO("max file size : %s", required_contents);
1362
1363                 err = chartoint(required_contents, max_file_size);
1364                 if (err == 1) {
1365                         str_free(&required_contents);
1366                         _INNER_FUNC_EXIT;
1367                         return DM_OK;
1368                 } else {
1369                         _DEBUG_INFO("get max file size error");
1370                         _INNER_FUNC_EXIT;
1371                         return COMMON_ERR_IS_NULL;
1372                 }
1373         } else {
1374                 _DEBUG_INFO("get max file size error");
1375                 _INNER_FUNC_EXIT;
1376                 return COMMON_ERR_IS_NULL;
1377         }
1378         _DEBUG_INFO("get max file size error");
1379
1380         _INNER_FUNC_EXIT;
1381         return COMMON_ERR_IS_NULL;
1382 }
1383
1384 static DM_ERROR __check_max_file_size(int file_size)
1385 {
1386         _INNER_FUNC_ENTER;
1387
1388         DM_ERROR ret = DM_OK;
1389         int noti_res = 0;
1390
1391         int max_file_size = 0;
1392         //file_size = 2042626049; // for testing..
1393         ret = ___get_max_file_size(&max_file_size);
1394         if (ret != DM_OK) {
1395                 _DEBUG_INFO("get max file size error");
1396                 ret = DM_WIFI_ONLY_ERROR;
1397                 goto error;
1398         }
1399         _DEBUG_INFO("file size = %d, max file size = %d", file_size, max_file_size);
1400
1401         /*max_file_size = 0 (0 in file or not existed file)
1402          *  - can't use this option
1403          *  - this option is max file size define in file when 3g mode
1404          */
1405         if (max_file_size != 0 && file_size > max_file_size) {
1406                 noti_res = noti_over_max_file_size(file_size);
1407                 _DEBUG_INFO("noti over max file size : %d", noti_res);
1408
1409                 _DEBUG_INFO("can't save current_size on 3g mode");
1410                 ret = DM_WIFI_ONLY_ERROR;
1411                 goto error;
1412
1413         } else {
1414                 _DEBUG_INFO("save current size on 3g mode");
1415         }
1416
1417         _INNER_FUNC_EXIT;
1418         return ret;
1419
1420  error:
1421
1422         _DEBUG_INFO("end error : %d", ret);
1423         _INNER_FUNC_EXIT;
1424         return ret;
1425 }
1426
1427 static DM_ERROR _checking_rooting_opeartion(char *value)
1428 {
1429         _INNER_FUNC_ENTER;
1430         DM_ERROR ret = DM_OK;
1431
1432         retvm_if((value) == NULL, COMMON_ERR_IS_NULL, "value is NULL!!");
1433         _DEBUG_INFO("value [%s]", value);
1434
1435         if (strcmp(value, "T") == 0) {
1436 //      if (strcmp(value, "F") == 0) { // for testing...
1437
1438                 /* Device rooting check => if rooting status => return DM_ERR_COMMAND_NOT_ALLOWED , if not rooting status => return DM_OK */
1439                 //struct_cordon_status cordon_status;
1440                 //cordon_get_current_root_status(&cordon_status);
1441                 //_DEBUG_INFO("cordon_status.is_device_rooted [%d]", cordon_status.is_device_rooted);
1442                 //if(cordon_status.is_device_rooted == TRUE) {
1443                 //      ret = DM_ERR_COMMAND_NOT_ALLOWED;
1444                 //} else {
1445                         ret = DM_OK; // DM_ERR_COMMAND_NOT_ALLOWED;
1446                 //}
1447         } else {
1448                 ret = DM_OK;
1449         }
1450
1451         _INNER_FUNC_EXIT;
1452         _DEBUG_INFO("end ret : %d", ret);
1453         return ret;
1454 }