3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
21 #include <sync_agent.h>
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"
35 #define MAX_FILE_SIZE 52428800 /* 50 MB */
36 //#define MAX_FILE_SIZE 2042626048 /* 1948 MB : (2*1024*1024*1024) - (100*1024*1024) */
38 #define DD_MULTI_LANGUAGE "db/SyncML/oma-dm-service/DD-multilanguage"
39 #define DD_OBJECT_SIZE "db/SyncML/oma-dm-service/DD-objectsize"
41 #ifndef OMADM_AGENT_LOG
43 #define LOG_TAG "FUMO_ENGINE"
46 #define FOTA_LOW_BATTERY_LEVEL 50
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);
57 DM_ERROR fumo_engine_state_operation(char *full_path, char *down_server, FUMO_Error * fumo_return)
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);
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;
75 retvm_if((full_path) == NULL, COMMON_ERR_IS_NULL, "full_path is NULL!!");
77 ret = get_mo_operationtype(full_path, &result_mo_type);
81 ret = get_current_fumo_state(full_path, &fumo_state_data);
85 if (chartoint(fumo_state_data, (int *)(&fumo_state)) == 0) {
86 _DEBUG_INFO("error char to int value");
87 ret = COMMON_ERR_IS_NULL;
91 _DEBUG_INFO(" -----------------------------------------------------------------------------------------------\n");
92 _DEBUG_INFO(" get fumo_state in db : %d\n", fumo_state);
93 _DEBUG_INFO(" -----------------------------------------------------------------------------------------------\n");
97 case DOWNLOAD_PROGRESSING:{
99 _DEBUG_INFO(" DOWNLOAD_PROGRESSING\n");
100 fumo_state = DOWNLOAD_PROGRESSING;
102 cancel_flag = sync_agent_check_cancel_flag();
103 if (cancel_flag != 0) {
105 *fumo_return = FUMO_USER_CANCELLED;
106 fumo_state = DOWNLOAD_FAILED;
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;
116 _DEBUG_INFO("fimware donwload success : 200 , cancel : 562, result is : %d\n", ret);
118 cancel_flag = sync_agent_check_cancel_flag();
119 if (cancel_flag != 0) {
121 *fumo_return = FUMO_USER_CANCELLED;
122 fumo_state = DOWNLOAD_FAILED;
127 _DEBUG_INFO("-----------download ok---------------");
128 fumo_state = DOWNLOAD_COMPLETE;
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);
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;
139 _DEBUG_INFO("-----------download fail---------------\n");
140 *fumo_return = FUMO_USER_CANCELLED;
141 fumo_state = DOWNLOAD_FAILED;
144 ret = set_current_fumo_state(full_path, fumo_state);
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);
156 case DOWNLOAD_FAILED:
157 _DEBUG_INFO(" DOWNLOAD_FAILED\n");
161 case DOWNLOAD_COMPLETE:{
162 _DEBUG_INFO(" DOWNLOAD_COMPLETE\n");
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);
171 fumo_engine_state_operation(full_path, down_server, fumo_return);
172 _DEBUG_INFO("engine state result : %d", ret);
176 case READY_TO_UPDATE:{
177 cancel_flag = sync_agent_check_cancel_flag();
178 if (cancel_flag != 0) {
180 *fumo_return = FUMO_USER_CANCELLED;
181 fumo_state = DOWNLOAD_FAILED;
185 ret = _firmware_install(full_path, memory_type, fumo_return);
188 /*if install success was rebooted */
189 _DEBUG_INFO("install fail");
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;
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;
200 _DEBUG_INFO("-----------install fail---------------\n");
201 *fumo_return = FUMO_USER_CANCELLED;
202 fumo_state = UPDATE_FAILED_HAVE_DATA;
207 case UPDATE_PROGRESSING:{
209 cancel_flag = sync_agent_check_cancel_flag();
210 if (cancel_flag != 0) {
212 *fumo_return = FUMO_USER_CANCELLED;
213 fumo_state = DOWNLOAD_FAILED;
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;
225 fumo_state = UPDATE_SUCCESSFUL_HAVE_DATA;
228 ret = set_current_fumo_state(full_path, fumo_state);
232 ret = fumo_engine_state_operation(full_path, down_server, fumo_return);
233 _DEBUG_INFO("engine state result : %d", ret);
236 case UPDATE_FAILED_HAVE_DATA:
237 case UPDATE_FAILED_NO_DATA:{
239 delete_fumo_contents(memory_type);
240 fumo_state = IDLE_START;
241 set_current_fumo_state(full_path, fumo_state);
245 ret = _firmware_update_popup(FUMO_UPDATE_FAILED);
247 _DEBUG_INFO("_firmware_update result popup fail ");
250 /*ret = FUMO_UPDATE_FAILED; */
251 *fumo_return = FUMO_UPDATE_FAILED;
252 _DEBUG_INFO("update fail ");
255 case UPDATE_SUCCESSFUL_HAVE_DATA:
256 case UPDATE_SUCCESSFUL_NO_DATA:{
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);
265 ret = _firmware_update_popup(FUMO_SUCCESS);
267 _DEBUG_INFO("_firmware_update result popup fail ");
270 /*ret = FUMO_SUCCESS; */
271 *fumo_return = FUMO_SUCCESS;
272 _DEBUG_INFO("update success ");
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);
288 _DEBUG_INFO("----------------------------------------------------------fumo download, install popup----------------------------------------------------------- %d", fumo_state);
290 set_current_fumo_state(full_path, fumo_state);
291 str_free(&fumo_state_data);
292 str_free(&result_mo_type);
297 _DEBUG_INFO("----------------------------------------------------------fumo error-----------------------------------------------------------");
298 delete_fumo_contents(memory_type);
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);
305 _DEBUG_INFO(" end error : %d\n", ret);
310 DM_ERROR fumo_exec(char *full_path, char *correlator, FUMO_Error * fumo_return)
314 DM_ERROR ret = DM_OK;
316 retvm_if((full_path) == NULL, COMMON_ERR_IS_NULL, "full_path is NULL!!");
318 char *result_mo_type = NULL;
319 ret = get_mo_operationtype(full_path, &result_mo_type);
323 if (result_mo_type == NULL) {
324 _DEBUG_INFO("result_mo_type is null");
325 ret = COMMON_ERR_IS_NULL;
329 if (strcmp(result_mo_type, DM_FUMO_DOWNLOAD_OP) == 0) {
330 ret = firmware_download_opeartion(full_path, fumo_return);
333 } else if (strcmp(result_mo_type, DM_FUMO_UPDATE_OP) == 0) {
334 ret = firmware_update_operation(full_path, fumo_return);
337 } else if (strcmp(result_mo_type, DM_FUMO_DOWNLOADAND_UPDATE_OP) == 0) {
338 ret = firmware_downloadupdate_operation(full_path, fumo_return);
342 ret = vendor_dependency_firmware_operation(full_path, fumo_return);
347 str_free(&result_mo_type);
348 _DEBUG_INFO(" end : %d", ret);
353 str_free(&result_mo_type);
354 _DEBUG_INFO(" end error : %d \n", ret);
359 DM_ERROR fumo_replace(char *full_path, char *value, FUMO_Error * fumo_return)
363 DM_ERROR ret = DM_OK;
365 retvm_if((full_path) == NULL, COMMON_ERR_IS_NULL, "full_path is NULL!!");
367 char *result_mo_type = NULL;
368 ret = get_mo_operationtype(full_path, &result_mo_type);
372 if (result_mo_type == NULL) {
373 _DEBUG_INFO("result_mo_type is null");
374 ret = COMMON_ERR_IS_NULL;
377 _DEBUG_INFO("result_mo_type [%s]", result_mo_type);
380 if (strcmp(result_mo_type, DM_FUMO_EXT_OP_DOCHECKINGROOTING) == 0) {
381 ret = _checking_rooting_opeartion(value);
383 (*fumo_return) = DM_ERR_COMMAND_NOT_ALLOWED;
386 (*fumo_return) = DM_OK;
392 str_free(&result_mo_type);
393 _DEBUG_INFO(" end : %d", ret);
398 str_free(&result_mo_type);
399 _DEBUG_INFO(" end error : %d \n", ret);
404 static DM_ERROR _firmware_download(char *server_url, MEMORY_TYPE * memory_type, FUMO_Error * fumo_return)
408 DM_ERROR ret = DM_OK;
410 DM_ERROR download_status = DM_ERR_USER_CANDELLED;
411 DM_ERROR installNofity_ret = DM_OK;
415 char *download_folder = NULL;
417 Download_Descriptor *download_descriptor = NULL;
419 engine_status *status = NULL;
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;
429 _DEBUG_TRACE("----------------------------------------------------------------------------------------------------- \n");
430 _DEBUG_TRACE(" server url : %s \n", server_url);
431 _DEBUG_TRACE("----------------------------------------------------------------------------------------------------- \n");
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;
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 */
445 _DEBUG_TRACE(" user interaction start \n");
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;
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;
466 ret = get_object_information(server_url, &file_size, &download_descriptor, &download_status);
468 *fumo_return = FUMO_USER_CANCELLED;
469 download_status = DM_ERR_INVALID_DESCRIPTOR;
472 if(download_descriptor->object_description != NULL) {
473 _DEBUG_INFO(" dd->object_description = %s \n", download_descriptor->object_description);
474 int vconf_result = 0;
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);
480 _DEBUG_VERBOSE("vconf_set_str() %s failed !!", DD_MULTI_LANGUAGE);
483 _DEBUG_INFO("dd->object_description is NULL");
486 if(download_descriptor->object_size != 0) {
487 _DEBUG_INFO(" dd->object_size = %d \n", download_descriptor->object_size);
488 int vconf_result = 0;
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);
494 _DEBUG_VERBOSE("vconf_set_int() %s failed !!", DD_OBJECT_SIZE);
497 _DEBUG_INFO("dd->object_size is NULL");
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);
508 if (noti_res == RESPONSE_TYPE_OK) {
509 ret = DM_DOWNLOAD_POPUP;
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;
522 case RESUME_STATUS_DOWNLOAD: /*after click download popup */
524 _DEBUG_TRACE("------------------------------------------------------download button click---------------------------------------------\n");
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;
535 ret = get_object_information(server_url, &file_size, &download_descriptor, &download_status);
537 *fumo_return = FUMO_USER_CANCELLED;
538 download_status = DM_ERR_INVALID_DESCRIPTOR;
541 _DEBUG_TRACE(" user interaction start \n");
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;
553 config = get_wifi_only_config();
555 /*battery state check */
556 ret = __check_low_battery();
557 _DEBUG_TRACE("ret : %d \n", ret);
560 *fumo_return = FUMO_USER_CANCELLED;
564 _DEBUG_TRACE("======================================================");
565 _DEBUG_TRACE("object size [%d]\n", file_size);
566 _DEBUG_TRACE("wifi only config [%d]\n", config);
567 _DEBUG_TRACE("======================================================");
569 ret = __check_memory(file_size, memory_type);
570 //ret = DM_OVER_MEMORY_ERROR; // for memory not enough - UI testing
572 noti_res = noti_memory_full((int)file_size);
573 if (noti_res == RESPONSE_TYPE_OK) {
574 _DEBUG_TRACE("memory full popup success");
576 _DEBUG_TRACE("memory full popup fail");
578 download_status = DM_ERR_INSUFFICIENT_MEMORY;
579 *fumo_return = FUMO_USER_CANCELLED;
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;
590 } else if (config == 0) {
591 _DEBUG_TRACE("wifi config = 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
599 _DEBUG_TRACE("3g mode");
601 ret = __check_max_file_size(file_size);
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;
610 _DEBUG_TRACE("wifi mode");
613 _DEBUG_TRACE("wifi config = 1");
614 _DEBUG_TRACE("wifi only mode");
617 ret = get_fota_download_dir((*memory_type), &download_folder);
619 *fumo_return = FUMO_DOWNLOAD_FAILS_DUE_TO_DEVICE_OUT_OF_MEMORY;
620 download_status = DM_ERR_INSUFFICIENT_MEMORY;
623 _DEBUG_TRACE(" download ok \n ");
625 char *downloadUrl = NULL;
626 ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_SERVER_URL, downloadUrl);
628 *fumo_return = FUMO_USER_CANCELLED;
629 download_status = DM_ERR_USER_CANDELLED;
632 /* remove remind interval */
633 delete_alarm_item(FUMO_INTERVAL, FUMO_INTERVAL_TYPE);
634 _DEBUG_TRACE(" delete fumo reminder in config db ");
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);
641 *fumo_return = FUMO_MALFORMED_OR_BAD_URL;
642 download_status = DM_ERR_USER_CANDELLED;
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;
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;
658 _DEBUG_TRACE("get wifi only config value : %d", config);
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);
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();
669 if (noti_res == RESPONSE_TYPE_OK) {
670 _DEBUG_TRACE("send_wifi only fail ipc success");
672 _DEBUG_TRACE("send_wifi only fail ipc fail");
675 *fumo_return = FUMO_USER_CANCELLED;
676 download_status = DM_ERR_USER_CANDELLED;
682 installNofity_ret = send_donwload_status(download_status, download_descriptor);
683 _DEBUG_TRACE("send installNotify : %d", installNofity_ret);
686 _DEBUG_TRACE(" file is exist\n");
690 case RESUME_STATUS_DOWNLOAD_LATER: /*later button clicked */
692 _DEBUG_TRACE("------------------------------------------------------later button click---------------------------------------------\n");
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;
703 ret = get_object_information(server_url, &file_size, &download_descriptor, &download_status);
705 *fumo_return = FUMO_USER_CANCELLED;
706 download_status = DM_ERR_INVALID_DESCRIPTOR;
710 installNofity_ret = send_donwload_status(download_status, download_descriptor);
711 _DEBUG_TRACE("send installNotify : %d", installNofity_ret);
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);
717 *fumo_return = FUMO_USER_CANCELLED;
718 download_status = DM_ERR_USER_CANDELLED;
719 ret = DM_ERR_REMINDER_INTERVAL;
722 case RESUME_STATUS_DOWNLOAD_IDLE:
725 /*case RESUME_STATUS_IDLE, default */
726 ret = DM_RESUME_IDLE;
729 _DEBUG_TRACE("----------------------------------------------------bad flow--------------------------------------------------------------------");
736 Free_Memory_Engine_Status(&status, 1);
738 if (download_descriptor != NULL) {
739 _DEBUG_TRACE("__free_Download_Descriptor()\n");
740 free_Download_Descriptor(&download_descriptor);
742 str_free(&download_folder);
751 Free_Memory_Engine_Status(&status, 1);
753 if (download_descriptor != NULL) {
754 _DEBUG_TRACE("__free_Download_Descriptor()\n");
755 free_Download_Descriptor(&download_descriptor);
757 str_free(&download_folder);
759 _DEBUG_TRACE(" end error : %d \n", ret);
766 Free_Memory_Engine_Status(&status, 1);
768 installNofity_ret = send_donwload_status(download_status, download_descriptor);
769 _DEBUG_INFO("send installNotify : %d", installNofity_ret);
771 if (download_descriptor != NULL) {
772 _DEBUG_INFO("__free_Download_Descriptor()\n");
773 free_Download_Descriptor(&download_descriptor);
775 str_free(&download_folder);
777 _DEBUG_INFO(" end error : %d \n", ret);
783 static DM_ERROR _firmware_install(char *full_path, MEMORY_TYPE memory_type, FUMO_Error * fumo_return)
787 DM_ERROR ret = DM_OK;
789 if (full_path == NULL) {
790 *fumo_return = FUMO_USER_CANCELLED;
794 sync_agent_dev_return_e dci_ret_flag = SYNC_AGENT_DEV_RETURN_SUCCESS;
795 engine_status *status = NULL;
797 FUMO_State fumo_state = READY_TO_UPDATE;
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;
806 _DEBUG_INFO("status->download_click [%d]", status->download_click);
807 switch (status->download_click) {
808 case RESUME_STATUS_INSTALL_BEFORE:
810 /** install UI control */
811 noti_res = noti_install();
812 if (noti_res == RESPONSE_TYPE_OK) {
813 ret = DM_INSTALL_POPUP;
816 // error in noti-process
817 ret = COMMON_ERR_IPC;
818 *fumo_return = FUMO_USER_CANCELLED;
823 case RESUME_STATUS_INSTALL:
825 /* battery state check */
826 ret = __check_low_battery();
828 ret = DM_LOW_BATTERY_ERROR;
829 *fumo_return = FUMO_USER_CANCELLED;
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 ");
838 fumo_state = UPDATE_PROGRESSING;
839 ret = set_current_fumo_state(full_path, fumo_state);
841 *fumo_return = FUMO_USER_CANCELLED;
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;
852 ret = set_current_fumo_state(full_path, fumo_state);
854 *fumo_return = FUMO_USER_CANCELLED;
861 _DEBUG_TRACE(" -------------------------------------------------------------------- \n");
862 _DEBUG_TRACE(" fota install to be rebooting l!!!!!!!!!!!! \n");
863 _DEBUG_TRACE(" -------------------------------------------------------------------- \n");
870 case RESUME_STATUS_INSTALL_LATER:
873 _DEBUG_TRACE("------------------canceled install------------------");
875 *fumo_return = FUMO_USER_CANCELLED;
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);
884 ret = DM_ERR_REMINDER_INTERVAL;
888 case RESUME_STATUS_INSTALL_IDLE:
891 ret = DM_RESUME_IDLE;
892 _DEBUG_TRACE("----------------------------------------------------install later --------------------------------------------------------------------");
898 if (status != NULL) {
899 Free_Memory_Engine_Status(&status, 1);
907 if (status != NULL) {
908 Free_Memory_Engine_Status(&status, 1);
910 _DEBUG_INFO(" return part : %d \n", ret);
916 if (status != NULL) {
917 Free_Memory_Engine_Status(&status, 1);
919 _DEBUG_INFO(" end error : %d \n", ret);
924 static DM_ERROR _firmware_update_popup(int result)
928 DM_ERROR ret = DM_OK;
929 _DEBUG_INFO("result [%d]", result);
931 noti_res = noti_update_result(result);
932 if (noti_res == RESPONSE_TYPE_OK) {
935 // error in noti-process
936 ret = COMMON_ERR_IPC;
939 _DEBUG_INFO(" end error : %d \n", ret);
944 DM_ERROR firmware_download_opeartion(char *full_path, FUMO_Error * fumo_return)
948 _DEBUG_INFO(" start\n");
950 DM_ERROR ret = DM_OK;
952 if (full_path == NULL) {
953 (*fumo_return) = FUMO_MALFORMED_OR_BAD_URL;
957 char *full_path_pkgurl = NULL;
958 full_path_pkgurl = g_strdup_printf("%s%s", full_path, DM_FUMO_DWONLOAD_OP_PKGURL);
960 char *down_server = NULL;
961 ret = get_mo_data(full_path_pkgurl, &down_server);
966 if (down_server == NULL) {
967 _DEBUG_INFO("not found download server");
968 (*fumo_return) = FUMO_MALFORMED_OR_BAD_URL;
972 #ifdef _DM_BUNDANG_TEST
973 /*redirection code */
974 char *pkg_url = get_new_uri(down_server);
976 ret = fumo_engine_state_operation(full_path, pkg_url, fumo_return);
980 ret = fumo_engine_state_operation(full_path, down_server, fumo_return);
988 str_free(&full_path_pkgurl);
989 str_free(&down_server);
995 str_free(&full_path_pkgurl);
996 str_free(&down_server);
998 _DEBUG_INFO(" end error : %d \n", ret);
1003 DM_ERROR firmware_update_operation(char *full_path, FUMO_Error * fumo_return)
1007 DM_ERROR ret = DM_OK;
1009 if (full_path == NULL) {
1010 (*fumo_return) = FUMO_MALFORMED_OR_BAD_URL;
1014 char *full_path_pkgurl = NULL;
1015 full_path_pkgurl = g_strdup_printf("%s%s", full_path, DM_FUMO_UPDATE_PKG_OP_DATA);
1017 char *down_server = NULL;
1018 ret = get_mo_data(full_path_pkgurl, &down_server);
1023 if (down_server == NULL) {
1024 _DEBUG_INFO("not found download server");
1025 (*fumo_return) = FUMO_MALFORMED_OR_BAD_URL;
1029 #ifdef _DM_BUNDANG_TEST
1030 /*redirection code */
1031 char *pkg_url = get_new_uri(down_server);
1033 ret = fumo_engine_state_operation(full_path, pkg_url, fumo_return);
1037 ret = fumo_engine_state_operation(full_path, down_server, fumo_return);
1046 str_free(&full_path_pkgurl);
1047 str_free(&down_server);
1053 str_free(&full_path_pkgurl);
1054 str_free(&down_server);
1056 _DEBUG_INFO(" end error : %d \n", ret);
1061 DM_ERROR firmware_downloadupdate_operation(char *full_path, FUMO_Error * fumo_return)
1065 DM_ERROR ret = DM_OK;
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;
1074 char *full_path_pkgurl = NULL;
1075 full_path_pkgurl = g_strdup_printf("%s%s", full_path, DM_FUMO_DOWNLOADAND_UPDATE_OP_PKGURL);
1077 char *down_server = NULL;
1078 ret = get_mo_data(full_path_pkgurl, &down_server);
1079 _DEBUG_INFO(" server_url : %s\n", down_server);
1084 if (down_server == NULL) {
1085 _DEBUG_INFO("not found download server");
1086 (*fumo_return) = FUMO_MALFORMED_OR_BAD_URL;
1090 #ifdef _DM_BUNDANG_TEST
1091 /*redirection code */
1092 char *pkg_url = get_new_uri(down_server);
1094 ret = fumo_engine_state_operation(full_path, pkg_url, fumo_return);
1099 ret = fumo_engine_state_operation(full_path, down_server, fumo_return);
1108 str_free(&full_path_pkgurl);
1109 str_free(&down_server);
1115 str_free(&full_path_pkgurl);
1116 str_free(&down_server);
1118 _DEBUG_INFO(" end error : %d \n", ret);
1123 DM_ERROR vendor_dependency_firmware_operation(char *full_path, FUMO_Error * fumo_return)
1127 DM_ERROR ret = DM_OK;
1128 int check_operation = 1;
1130 if (full_path == NULL) {
1131 ret = DM_ERR_COMMAND_FAILED;
1132 *fumo_return = FUMO_USER_CANCELLED;
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;
1148 _DEBUG_INFO(" end error : %d\n", ret);
1153 DM_ERROR get_current_fumo_state(char *full_path, char **fumo_state_data)
1156 DM_ERROR ret = DM_OK;
1158 retvm_if((full_path) == NULL, COMMON_ERR_IS_NULL, "full_path is NULL!!");
1160 char *fumo_root = NULL;
1161 char *fumo_state_url = NULL;
1163 //ret = get_mo_servicetype(full_path, &fumo_root);
1164 ret = get_mo_root_path(full_path, &fumo_root);
1166 ret = COMMON_ERR_INTERNAL_NOT_DEFINED;
1169 fumo_state_url = g_strdup_printf("%s%s", fumo_root, DM_FUMO_STATE_OP);
1171 ret = get_mo_data(fumo_state_url, fumo_state_data);
1173 ret = COMMON_ERR_GET_TYPE_NOT_FOUND;
1177 str_free(&fumo_state_url);
1182 str_free(&fumo_state_url);
1184 _DEBUG_INFO(" end error : %d\n", ret);
1189 DM_ERROR set_current_fumo_state(char *full_path, FUMO_State fumo_state)
1193 DM_ERROR ret = DM_OK;
1195 retvm_if((full_path) == NULL, COMMON_ERR_IS_NULL, "full_path is NULL!!");
1197 char *fumo_root = NULL;
1198 char *fumo_state_url = NULL;
1199 char *fumo_state_data = NULL;
1201 //ret = get_mo_servicetype(full_path, &fumo_root);
1202 ret = get_mo_root_path(full_path, &fumo_root);
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);
1210 _DEBUG_INFO(" fumo_state : %d\n", fumo_state);
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);
1218 str_free(&fumo_state_url);
1219 str_free(&fumo_state_data);
1225 str_free(&fumo_state_url);
1226 str_free(&fumo_state_data);
1228 _DEBUG_INFO(" end error : %d\n", ret);
1233 static DM_ERROR __check_low_battery()
1237 DM_ERROR ret = DM_OK;
1238 char *battery_level = 0;
1240 ret = get_battery_state(&battery_level);
1244 int int_battery_level = 0;
1245 if (battery_level != NULL) {
1247 err = chartoint((battery_level), &int_battery_level);
1249 _DEBUG_VERBOSE("battery level : %d ", int_battery_level);
1250 if (FOTA_LOW_BATTERY_LEVEL > int_battery_level) {
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);
1261 _DEBUG_VERBOSE("battery level is null");
1262 ret = COMMON_ERR_IS_NULL;
1266 _DEBUG_VERBOSE("battery level is null");
1267 ret = COMMON_ERR_IS_NULL;
1270 _DEBUG_VERBOSE("end");
1273 _DEBUG_VERBOSE("end error : %d", DM_LOW_BATTERY_ERROR);
1275 return DM_LOW_BATTERY_ERROR;
1278 static DM_ERROR __check_memory(long double file_size, MEMORY_TYPE * is_internal_memory)
1282 DM_ERROR ret = DM_OK;
1285 // long double need_size = file_size * 2.1;
1286 long double need_size = file_size + 1024*1024*3;
1288 ret = compare_memory_space(FOTA_DELTA_INTERNAL_STORAGE, need_size);
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");
1298 _DEBUG_VERBOSE("file size over the memory ipc fail");
1301 return DM_OVER_MEMORY_ERROR;
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) {
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");
1316 _DEBUG_VERBOSE("file size over the memory ipc fail");
1319 return DM_OVER_MEMORY_ERROR;
1321 _DEBUG_VERBOSE("save in sd memory card");
1325 _DEBUG_VERBOSE("memory full ipc fail");
1327 return DM_OVER_MEMORY_ERROR;
1330 (*is_internal_memory) = MEMORY_SD_CARD;
1333 /*internal memory path */
1334 (*is_internal_memory) = MEMORY_INTERNAL;
1341 static DM_ERROR ___get_max_file_size(int *max_file_size)
1346 char *required_contents = NULL;
1347 unsigned long size_return = 0;
1349 err = sync_agent_is_existing_fs(MAX_DELTA_FILE_SIZE);
1350 /*define value when this is file not existed */
1352 _DEBUG_INFO("max file size : 50MB");
1353 *max_file_size = MAX_FILE_SIZE;
1358 /*value when this is file existed */
1359 err = sync_agent_read_whole_file(MAX_DELTA_FILE_SIZE, &required_contents, &size_return);
1361 _DEBUG_INFO("max file size : %s", required_contents);
1363 err = chartoint(required_contents, max_file_size);
1365 str_free(&required_contents);
1369 _DEBUG_INFO("get max file size error");
1371 return COMMON_ERR_IS_NULL;
1374 _DEBUG_INFO("get max file size error");
1376 return COMMON_ERR_IS_NULL;
1378 _DEBUG_INFO("get max file size error");
1381 return COMMON_ERR_IS_NULL;
1384 static DM_ERROR __check_max_file_size(int file_size)
1388 DM_ERROR ret = DM_OK;
1391 int max_file_size = 0;
1392 //file_size = 2042626049; // for testing..
1393 ret = ___get_max_file_size(&max_file_size);
1395 _DEBUG_INFO("get max file size error");
1396 ret = DM_WIFI_ONLY_ERROR;
1399 _DEBUG_INFO("file size = %d, max file size = %d", file_size, max_file_size);
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
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);
1409 _DEBUG_INFO("can't save current_size on 3g mode");
1410 ret = DM_WIFI_ONLY_ERROR;
1414 _DEBUG_INFO("save current size on 3g mode");
1422 _DEBUG_INFO("end error : %d", ret);
1427 static DM_ERROR _checking_rooting_opeartion(char *value)
1430 DM_ERROR ret = DM_OK;
1432 retvm_if((value) == NULL, COMMON_ERR_IS_NULL, "value is NULL!!");
1433 _DEBUG_INFO("value [%s]", value);
1435 if (strcmp(value, "T") == 0) {
1436 // if (strcmp(value, "F") == 0) { // for testing...
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;
1445 ret = DM_OK; // DM_ERR_COMMAND_NOT_ALLOWED;
1452 _DEBUG_INFO("end ret : %d", ret);