3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #include <sync_agent.h>
22 #include "common/dm_common.h"
23 #include "common/util/util.h"
24 #include "mo-handler/dm_mo_common.h"
25 #include "mo-handler/dm_mo_handler.h"
26 #include "dm-engine/fumo/fumo_engine.h"
27 #include "dm-engine/dl-manager/fw_downloader.h"
28 #include "dm-engine/dl-manager/dd_object.h"
29 #include "ipc_common.h"
30 #include "ipc_agent.h"
32 #define MAX_FILE_SIZE 52428800
34 #ifndef OMADM_AGENT_LOG
36 #define LOG_TAG "FUMO_ENGINE"
39 #define FOTA_LOW_BATTERY_LEVEL 50
41 static DM_ERROR _firmware_download(char *server_url, MEMORY_TYPE * memory_type, FUMO_Error * fumo_return);
42 static DM_ERROR _firmware_install(char *full_path, MEMORY_TYPE memory_type, FUMO_Error * fumo_return);
43 static DM_ERROR __check_low_battery();
44 static DM_ERROR __check_memory(long double file_size, MEMORY_TYPE * is_internal_memory);
45 static DM_ERROR ___get_max_file_size(int *max_file_size);
46 static DM_ERROR __check_max_file_size(int file_size);
48 DM_ERROR fumo_engine_state_operation(char *full_path, char *down_server, FUMO_Error * fumo_return)
54 retvm_if((full_path) == NULL, COMMON_ERR_IS_NULL, "full_path is NULL!!");
55 retvm_if((down_server) == NULL, COMMON_ERR_IS_NULL, "down_server is NULL!!");
57 char *result_mo_type = NULL;
58 sync_agent_dev_return_e dci_ret_exec = SYNC_AGENT_DEV_RETURN_SUCCESS;
59 bool cancel_flag = false;
60 MEMORY_TYPE memory_type = MEMORY_INTERNAL;
61 char *fumo_state_data = NULL;
62 FUMO_State fumo_state = UNKNOWN;
64 retvm_if((full_path) == NULL, COMMON_ERR_IS_NULL, "full_path is NULL!!");
66 ret = get_mo_operationtype(full_path, &result_mo_type);
70 ret = get_current_fumo_state(full_path, &fumo_state_data);
74 if (chartoint(fumo_state_data, (int *)(&fumo_state)) == 0) {
75 _DEBUG_INFO("error char to int value");
76 ret = COMMON_ERR_IS_NULL;
80 _DEBUG_INFO(" -----------------------------------------------------------------------------------------------\n");
81 _DEBUG_INFO(" get fumo_state in db : %d\n", fumo_state);
82 _DEBUG_INFO(" -----------------------------------------------------------------------------------------------\n");
86 case DOWNLOAD_PROGRESSING:{
88 _DEBUG_INFO(" DOWNLOAD_PROGRESSING\n");
89 fumo_state = DOWNLOAD_PROGRESSING;
91 cancel_flag = sync_agent_check_cancel_flag();
92 if (cancel_flag != 0) {
94 *fumo_return = FUMO_USER_CANCELLED;
95 fumo_state = DOWNLOAD_FAILED;
99 ret = _firmware_download(down_server, &memory_type, fumo_return);
100 if (ret != DM_OK && ret != DM_DOWNLOAD_POPUP && ret != DM_RESUME_IDLE) {
101 fumo_state = DOWNLOAD_FAILED;
105 _DEBUG_INFO("fimware donwload success : 200 , cancel : 562, result is : %d\n", ret);
107 cancel_flag = sync_agent_check_cancel_flag();
108 if (cancel_flag != 0) {
110 *fumo_return = FUMO_USER_CANCELLED;
111 fumo_state = DOWNLOAD_FAILED;
116 _DEBUG_INFO("-----------download ok---------------");
117 fumo_state = DOWNLOAD_COMPLETE;
119 RESUME_STATUS download_clicked = RESUME_STATUS_INSTALL_BEFORE;
120 ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_DOWNLOAD_CLICK, &download_clicked);
121 _DEBUG_INFO("update engine status clolumn download click : %d", ret);
123 } else if (ret == DM_ERR_REMINDER_INTERVAL || ret == DM_DOWNLOAD_POPUP || ret == DM_RESUME_IDLE) {
124 _DEBUG_INFO("-----------download popup---------------");
125 fumo_state = DOWNLOAD_PROGRESSING;
128 _DEBUG_INFO("-----------download fail---------------\n");
129 *fumo_return = FUMO_USER_CANCELLED;
130 fumo_state = DOWNLOAD_FAILED;
133 ret = set_current_fumo_state(full_path, fumo_state);
137 if (strcmp(result_mo_type, DM_FUMO_DOWNLOAD_OP) == 0) {
138 } else if (strcmp(result_mo_type, DM_FUMO_UPDATE_OP) == 0) {
139 } else if (strcmp(result_mo_type, DM_FUMO_DOWNLOADAND_UPDATE_OP) == 0) {
140 fumo_engine_state_operation(full_path, down_server, fumo_return);
141 _DEBUG_INFO("engine state result : %d", ret);
145 case DOWNLOAD_FAILED:
146 _DEBUG_INFO(" DOWNLOAD_FAILED\n");
150 case DOWNLOAD_COMPLETE:{
151 _DEBUG_INFO(" DOWNLOAD_COMPLETE\n");
153 if (strcmp(result_mo_type, DM_FUMO_DOWNLOAD_OP) == 0) {
154 } else if ((strcmp(result_mo_type, DM_FUMO_UPDATE_OP)) == 0 || strcmp(result_mo_type, DM_FUMO_DOWNLOADAND_UPDATE_OP) == 0) {
155 fumo_state = READY_TO_UPDATE;
156 ret = set_current_fumo_state(full_path, fumo_state);
160 fumo_engine_state_operation(full_path, down_server, fumo_return);
161 _DEBUG_INFO("engine state result : %d", ret);
165 case READY_TO_UPDATE:{
166 cancel_flag = sync_agent_check_cancel_flag();
167 if (cancel_flag != 0) {
169 *fumo_return = FUMO_USER_CANCELLED;
170 fumo_state = DOWNLOAD_FAILED;
174 ret = _firmware_install(full_path, memory_type, fumo_return);
177 /*if install success was rebooted */
178 _DEBUG_INFO("install fail");
180 } else if (ret == COMMON_ERR_IPC || ret == DM_LOW_BATTERY_ERROR) {
181 _DEBUG_INFO("-----------cancel or ipc error---------------");
182 fumo_state = UPDATE_FAILED_HAVE_DATA;
184 } else if (ret == DM_ERR_REMINDER_INTERVAL || ret == DM_INSTALL_POPUP || ret == DM_RESUME_IDLE) {
185 _DEBUG_INFO("-----------download popup---------------");
186 fumo_state = READY_TO_UPDATE;
189 _DEBUG_INFO("-----------install fail---------------\n");
190 *fumo_return = FUMO_USER_CANCELLED;
191 fumo_state = UPDATE_FAILED_HAVE_DATA;
196 case UPDATE_PROGRESSING:{
198 cancel_flag = sync_agent_check_cancel_flag();
199 if (cancel_flag != 0) {
201 *fumo_return = FUMO_USER_CANCELLED;
202 fumo_state = DOWNLOAD_FAILED;
206 dci_ret_exec = sync_agent_execute_dev_function(2, "fota_result", 1, (int *)fumo_return);
207 //*fumo_return = result;
208 //*fumo_return = 202;
209 _DEBUG_INFO("-----------------firmware update result : %d fumo return : %d------------------", dci_ret_exec, (*fumo_return));
210 if (dci_ret_exec != SYNC_AGENT_DEV_RETURN_SUCCESS) {
211 fumo_state = UPDATE_FAILED_HAVE_DATA;
213 fumo_state = UPDATE_SUCCESSFUL_HAVE_DATA;
216 ret = set_current_fumo_state(full_path, fumo_state);
220 ret = fumo_engine_state_operation(full_path, down_server, fumo_return);
221 _DEBUG_INFO("engine state result : %d", ret);
224 case UPDATE_FAILED_HAVE_DATA:
225 case UPDATE_FAILED_NO_DATA:{
227 delete_fumo_contents(memory_type);
228 fumo_state = IDLE_START;
229 set_current_fumo_state(full_path, fumo_state);
233 /*ret = FUMO_UPDATE_FAILED; */
234 *fumo_return = FUMO_UPDATE_FAILED;
235 _DEBUG_INFO("update fail ");
238 case UPDATE_SUCCESSFUL_HAVE_DATA:
239 case UPDATE_SUCCESSFUL_NO_DATA:{
241 _DEBUG_INFO("----------------------------------------------------------firmware update success delete files-----------------------------------------------------------");
242 delete_fumo_contents(memory_type);
243 fumo_state = IDLE_START;
244 set_current_fumo_state(full_path, fumo_state);
248 /*ret = FUMO_SUCCESS; */
249 *fumo_return = FUMO_SUCCESS;
250 _DEBUG_INFO("update success ");
257 // str_free(&result_mo_type);
258 _DEBUG_INFO(" end fumo state : %d\n", fumo_state);
259 str_free(&fumo_state_data);
265 _DEBUG_INFO("----------------------------------------------------------fumo download, install popup----------------------------------------------------------- %d", fumo_state);
267 set_current_fumo_state(full_path, fumo_state);
268 str_free(&fumo_state_data);
269 str_free(&result_mo_type);
274 _DEBUG_INFO("----------------------------------------------------------fumo error-----------------------------------------------------------");
275 delete_fumo_contents(memory_type);
277 fumo_state = IDLE_START;
278 set_current_fumo_state(full_path, fumo_state);
279 str_free(&fumo_state_data);
280 str_free(&result_mo_type);
282 _DEBUG_INFO(" end error : %d\n", ret);
287 DM_ERROR fumo_exec(char *full_path, char *correlator, FUMO_Error * fumo_return)
291 DM_ERROR ret = DM_OK;
293 retvm_if((full_path) == NULL, COMMON_ERR_IS_NULL, "full_path is NULL!!");
295 char *result_mo_type = NULL;
296 ret = get_mo_operationtype(full_path, &result_mo_type);
300 if (result_mo_type == NULL) {
301 _DEBUG_INFO("result_mo_type is null");
302 ret = COMMON_ERR_IS_NULL;
306 if (strcmp(result_mo_type, DM_FUMO_DOWNLOAD_OP) == 0) {
307 ret = firmware_download_opeartion(full_path, fumo_return);
310 } else if (strcmp(result_mo_type, DM_FUMO_UPDATE_OP) == 0) {
311 ret = firmware_update_operation(full_path, fumo_return);
314 } else if (strcmp(result_mo_type, DM_FUMO_DOWNLOADAND_UPDATE_OP) == 0) {
315 ret = firmware_downloadupdate_operation(full_path, fumo_return);
319 ret = vendor_dependency_firmware_operation(full_path, fumo_return);
324 str_free(&result_mo_type);
325 _DEBUG_INFO(" end : %d", ret);
330 str_free(&result_mo_type);
331 _DEBUG_INFO(" end error : %d \n", ret);
336 static DM_ERROR _firmware_download(char *server_url, MEMORY_TYPE * memory_type, FUMO_Error * fumo_return)
340 DM_ERROR ret = DM_OK;
342 DM_ERROR download_status = DM_ERR_USER_CANDELLED;
343 DM_ERROR installNofity_ret = DM_OK;
347 char *download_folder = NULL;
349 Download_Descriptor *download_descriptor = NULL;
351 engine_status *status = NULL;
354 if (server_url == NULL) {
355 *fumo_return = FUMO_USER_CANCELLED;
356 download_status = DM_ERR_INVALID_DESCRIPTOR;
357 ret = COMMON_ERR_INTERNAL_NOT_DEFINED;
361 _DEBUG_TRACE("----------------------------------------------------------------------------------------------------- \n");
362 _DEBUG_TRACE(" server url : %s \n", server_url);
363 _DEBUG_TRACE("----------------------------------------------------------------------------------------------------- \n");
365 ret = Get_Engine_Status(FUMO_SERVICE_ENGINE, &status);
366 if (ret != DM_OK || status == NULL) {
367 *fumo_return = FUMO_USER_CANCELLED;
368 download_status = DM_ERR_USER_CANDELLED;
372 switch (status->download_click) {
373 case RESUME_STATUS_DONWLOAD_BEFORE: /*before click download popup */
375 _DEBUG_TRACE(" user interaction start \n");
377 cancel_flag = sync_agent_check_cancel_flag();
378 _DEBUG_TRACE(" cancel_flag : %d \n", cancel_flag);
379 if (cancel_flag != 0) {
380 *fumo_return = FUMO_USER_CANCELLED;
381 download_status = DM_ERR_USER_CANDELLED;
387 _DEBUG_TRACE("waiting connect to server success in firmware download\n");
388 noti_res = noti_download();
389 _DEBUG_TRACE("download noti response : %d \n ", noti_res);
391 if (noti_res == RESPONSE_TYPE_OK) {
392 ret = DM_DOWNLOAD_POPUP;
396 _DEBUG_TRACE("------------------------------------------------------downlaod popup noti error--------------------------------------------\n");
397 // error in noti-process
398 *fumo_return = FUMO_USER_CANCELLED;
399 download_status = DM_ERR_USER_CANDELLED;
400 ret = COMMON_ERR_IPC;
405 case RESUME_STATUS_DOWNLOAD: /*after click download popup */
407 _DEBUG_TRACE("------------------------------------------------------download button click---------------------------------------------\n");
409 download_descriptor = (Download_Descriptor *) calloc(1, sizeof(Download_Descriptor) + 1);
410 if (download_descriptor == NULL) {
411 _DEBUG_TRACE("calloc failed !!");
412 ret = COMMON_ERR_ALLOC;
413 *fumo_return = FUMO_USER_CANCELLED;
414 download_status = DM_ERR_INVALID_DESCRIPTOR;
418 ret = get_object_information(server_url, &file_size, &download_descriptor, &download_status);
420 *fumo_return = FUMO_USER_CANCELLED;
421 download_status = DM_ERR_INVALID_DESCRIPTOR;
424 _DEBUG_TRACE(" user interaction start \n");
426 cancel_flag = sync_agent_check_cancel_flag();
427 _DEBUG_TRACE(" cancel_flag : %d \n", cancel_flag);
428 if (cancel_flag != 0) {
429 *fumo_return = FUMO_USER_CANCELLED;
430 download_status = DM_ERR_USER_CANDELLED;
436 config = get_wifi_only_config();
438 /*battery state check */
439 ret = __check_low_battery();
440 _DEBUG_TRACE("ret : %d \n", ret);
443 *fumo_return = FUMO_USER_CANCELLED;
447 _DEBUG_TRACE("======================================================");
448 _DEBUG_TRACE("object size %d\n", file_size);
449 _DEBUG_TRACE("======================================================");
451 ret = __check_memory(file_size, memory_type);
453 noti_res = noti_memory_full((int)file_size);
454 if (noti_res == RESPONSE_TYPE_OK) {
455 _DEBUG_TRACE("memory full popup success");
457 _DEBUG_TRACE("memory full popup fail");
459 download_status = DM_ERR_INSUFFICIENT_MEMORY;
460 *fumo_return = FUMO_USER_CANCELLED;
466 _DEBUG_TRACE("get wifi only config error");
467 *fumo_return = FUMO_MALFORMED_OR_BAD_URL;
468 download_status = DM_ERR_USER_CANDELLED;
469 ret = DM_WIFI_ONLY_ERROR;
471 } else if (config == 0) {
472 _DEBUG_TRACE("wifi config = 0");
474 wifi_ret = get_wifi_state();
475 _DEBUG_TRACE("wifi mode : %d", wifi_ret);
478 _DEBUG_TRACE("3g mode");
480 ret = __check_max_file_size(file_size);
482 _DEBUG_TRACE("get max file size error");
483 *fumo_return = FUMO_DOWNLOAD_FAILS_DUE_TO_DEVICE_OUT_OF_MEMORY;
484 download_status = DM_ERR_USER_CANDELLED;
485 ret = DM_WIFI_ONLY_ERROR;
489 _DEBUG_TRACE("wifi mode");
492 _DEBUG_TRACE("wifi config = 1");
493 _DEBUG_TRACE("wifi only mode");
496 ret = get_fota_download_dir((*memory_type), &download_folder);
498 *fumo_return = FUMO_DOWNLOAD_FAILS_DUE_TO_DEVICE_OUT_OF_MEMORY;
499 download_status = DM_ERR_INSUFFICIENT_MEMORY;
502 _DEBUG_TRACE(" download ok \n ");
504 char *downloadUrl = NULL;
505 ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_SERVER_URL, downloadUrl);
507 *fumo_return = FUMO_USER_CANCELLED;
508 download_status = DM_ERR_USER_CANDELLED;
511 /* remove remind interval */
512 delete_alarm_item(FUMO_INTERVAL, FUMO_INTERVAL_TYPE);
513 _DEBUG_TRACE(" delete fumo reminder in config db ");
515 //FOTASaveDir //FOTADownDir
516 DOWNLOAD_FILE_STATUS file_status = 0;
517 Data_Resume_Infomation *data_resume_info = NULL;
518 ret = check_file_resume(download_folder, &file_status, download_descriptor, &data_resume_info);
520 *fumo_return = FUMO_MALFORMED_OR_BAD_URL;
521 download_status = DM_ERR_USER_CANDELLED;
525 _DEBUG_TRACE(" file_status = %d \n", file_status);
526 /*was maked by sooyi */
527 if (file_status != EXIST_COMPLETED_FILE) {
528 char *object_path = 0;
531 _DEBUG_TRACE("get wifi only config error");
532 *fumo_return = FUMO_MALFORMED_OR_BAD_URL;
533 download_status = DM_ERR_USER_CANDELLED;
534 ret = DM_WIFI_ONLY_ERROR;
537 _DEBUG_TRACE("get wifi only config value : %d", config);
539 ret = download_object(download_folder, &object_path, data_resume_info, config, download_descriptor, &download_status);
540 _DEBUG_TRACE("download object : %s", object_path);
541 _DEBUG_TRACE(" download_object result : %d \n", ret);
543 if (ret == DM_WIFI_ONLY_ERROR) {
544 _DEBUG_TRACE("send_DL_Msg() err [%d]\n", ret);
545 /* ipc wifi only pop up */
546 noti_res = noti_wifi_only_download_fail();
548 if (noti_res == RESPONSE_TYPE_OK) {
549 _DEBUG_TRACE("send_wifi only fail ipc success");
551 _DEBUG_TRACE("send_wifi only fail ipc fail");
554 *fumo_return = FUMO_USER_CANCELLED;
555 download_status = DM_ERR_USER_CANDELLED;
561 installNofity_ret = send_donwload_status(download_status, download_descriptor);
562 _DEBUG_TRACE("send installNotify : %d", installNofity_ret);
565 _DEBUG_TRACE(" file is exist\n");
569 case RESUME_STATUS_DOWNLOAD_LATER: /*later button clicked */
571 _DEBUG_TRACE("------------------------------------------------------later button click---------------------------------------------\n");
573 download_descriptor = (Download_Descriptor *) calloc(1, sizeof(Download_Descriptor) + 1);
574 if (download_descriptor == NULL) {
575 _DEBUG_TRACE("calloc failed !!");
576 ret = COMMON_ERR_ALLOC;
577 *fumo_return = FUMO_USER_CANCELLED;
578 download_status = DM_ERR_INVALID_DESCRIPTOR;
582 ret = get_object_information(server_url, &file_size, &download_descriptor, &download_status);
584 *fumo_return = FUMO_USER_CANCELLED;
585 download_status = DM_ERR_INVALID_DESCRIPTOR;
589 installNofity_ret = send_donwload_status(download_status, download_descriptor);
590 _DEBUG_TRACE("send installNotify : %d", installNofity_ret);
592 RESUME_STATUS download_clicked = RESUME_STATUS_DOWNLOAD_IDLE;
593 ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_DOWNLOAD_CLICK, &download_clicked);
594 _DEBUG_TRACE("update engine status clolumn download click : %d", ret);
596 *fumo_return = FUMO_USER_CANCELLED;
597 download_status = DM_ERR_USER_CANDELLED;
598 ret = DM_ERR_REMINDER_INTERVAL;
601 case RESUME_STATUS_DOWNLOAD_IDLE:
604 /*case RESUME_STATUS_IDLE, default */
605 ret = DM_RESUME_IDLE;
608 _DEBUG_TRACE("----------------------------------------------------bad flow--------------------------------------------------------------------");
615 Free_Memory_Engine_Status(&status, 1);
617 if (download_descriptor != NULL) {
618 _DEBUG_TRACE("__free_Download_Descriptor()\n");
619 free_Download_Descriptor(&download_descriptor);
621 str_free(&download_folder);
630 Free_Memory_Engine_Status(&status, 1);
632 if (download_descriptor != NULL) {
633 _DEBUG_TRACE("__free_Download_Descriptor()\n");
634 free_Download_Descriptor(&download_descriptor);
636 str_free(&download_folder);
638 _DEBUG_TRACE(" end error : %d \n", ret);
645 Free_Memory_Engine_Status(&status, 1);
647 installNofity_ret = send_donwload_status(download_status, download_descriptor);
648 _DEBUG_INFO("send installNotify : %d", installNofity_ret);
650 if (download_descriptor != NULL) {
651 _DEBUG_INFO("__free_Download_Descriptor()\n");
652 free_Download_Descriptor(&download_descriptor);
654 str_free(&download_folder);
656 _DEBUG_INFO(" end error : %d \n", ret);
662 static DM_ERROR _firmware_install(char *full_path, MEMORY_TYPE memory_type, FUMO_Error * fumo_return)
666 DM_ERROR ret = DM_OK;
668 if (full_path == NULL) {
669 *fumo_return = FUMO_USER_CANCELLED;
673 sync_agent_dev_return_e dci_ret_flag = SYNC_AGENT_DEV_RETURN_SUCCESS;
674 engine_status *status = NULL;
676 FUMO_State fumo_state = READY_TO_UPDATE;
678 ret = Get_Engine_Status(FUMO_SERVICE_ENGINE, &status);
679 if (ret != DM_OK || status == NULL) {
680 *fumo_return = FUMO_USER_CANCELLED;
684 switch (status->download_click) {
685 case RESUME_STATUS_INSTALL_BEFORE:
687 /** install UI control */
688 noti_res = noti_install();
689 if (noti_res == RESPONSE_TYPE_OK) {
690 ret = DM_INSTALL_POPUP;
693 // error in noti-process
694 ret = COMMON_ERR_IPC;
695 *fumo_return = FUMO_USER_CANCELLED;
700 case RESUME_STATUS_INSTALL:
702 /* battery state check */
703 ret = __check_low_battery();
705 ret = DM_LOW_BATTERY_ERROR;
706 *fumo_return = FUMO_USER_CANCELLED;
710 _DEBUG_TRACE("------------------fota install ok------------------");
711 _DEBUG_TRACE(" fota flag api \n");
712 delete_alarm_item(FUMO_INTERVAL, FUMO_INTERVAL_TYPE);
713 _DEBUG_TRACE(" delete fumo reminder in config db ");
715 fumo_state = UPDATE_PROGRESSING;
716 ret = set_current_fumo_state(full_path, fumo_state);
718 *fumo_return = FUMO_USER_CANCELLED;
722 dci_ret_flag = sync_agent_execute_dev_function(2, "fota_flag", 1, memory_type);
723 //dci_ret_flag= SYNC_AGENT_DEV_RETURN_SUCCESS;
724 _DEBUG_TRACE(" fota flag result : %d \n", dci_ret_flag);
725 if (dci_ret_flag != SYNC_AGENT_DEV_RETURN_SUCCESS) {
726 _DEBUG_TRACE(" fota flag fail!!!!!!!!!!!! \n");
727 *fumo_return = FUMO_FAILED_VALIDATION;
729 ret = set_current_fumo_state(full_path, fumo_state);
731 *fumo_return = FUMO_USER_CANCELLED;
738 _DEBUG_TRACE(" -------------------------------------------------------------------- \n");
739 _DEBUG_TRACE(" fota install to be rebooting l!!!!!!!!!!!! \n");
740 _DEBUG_TRACE(" -------------------------------------------------------------------- \n");
747 case RESUME_STATUS_INSTALL_LATER:
750 _DEBUG_TRACE("------------------canceled install------------------");
752 *fumo_return = FUMO_USER_CANCELLED;
754 RESUME_STATUS download_clicked = RESUME_STATUS_INSTALL_IDLE;
755 ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_DOWNLOAD_CLICK, &download_clicked);
756 _DEBUG_TRACE("update engine status clolumn download click : %d", ret);
757 /*fumo_state = IDLE_START;
758 ret = set_current_fumo_state(full_path, fumo_state);
761 ret = DM_ERR_REMINDER_INTERVAL;
765 case RESUME_STATUS_INSTALL_IDLE:
768 ret = DM_RESUME_IDLE;
770 _DEBUG_TRACE("----------------------------------------------------install later --------------------------------------------------------------------");
775 if (status != NULL) {
776 Free_Memory_Engine_Status(&status, 1);
784 if (status != NULL) {
785 Free_Memory_Engine_Status(&status, 1);
787 _DEBUG_INFO(" return part : %d \n", ret);
793 if (status != NULL) {
794 Free_Memory_Engine_Status(&status, 1);
796 _DEBUG_INFO(" end error : %d \n", ret);
801 DM_ERROR firmware_download_opeartion(char *full_path, FUMO_Error * fumo_return)
805 _DEBUG_INFO(" start\n");
807 DM_ERROR ret = DM_OK;
809 if (full_path == NULL) {
810 (*fumo_return) = FUMO_MALFORMED_OR_BAD_URL;
814 char *full_path_pkgurl = NULL;
815 full_path_pkgurl = g_strdup_printf("%s%s", full_path, DM_FUMO_DWONLOAD_OP_PKGURL);
817 char *down_server = NULL;
818 ret = get_mo_data(full_path_pkgurl, &down_server);
823 if (down_server == NULL) {
824 _DEBUG_INFO("not found download server");
825 (*fumo_return) = FUMO_MALFORMED_OR_BAD_URL;
829 #ifdef _DM_BUNDANG_TEST
830 /*redirection code */
831 char *pkg_url = get_new_uri(down_server);
833 ret = fumo_engine_state_operation(full_path, pkg_url, fumo_return);
837 ret = fumo_engine_state_operation(full_path, down_server, fumo_return);
845 str_free(&full_path_pkgurl);
846 str_free(&down_server);
852 str_free(&full_path_pkgurl);
853 str_free(&down_server);
855 _DEBUG_INFO(" end error : %d \n", ret);
860 DM_ERROR firmware_update_operation(char *full_path, FUMO_Error * fumo_return)
864 DM_ERROR ret = DM_OK;
866 if (full_path == NULL) {
867 (*fumo_return) = FUMO_MALFORMED_OR_BAD_URL;
871 char *full_path_pkgurl = NULL;
872 full_path_pkgurl = g_strdup_printf("%s%s", full_path, DM_FUMO_UPDATE_PKG_OP_DATA);
874 char *down_server = NULL;
875 ret = get_mo_data(full_path_pkgurl, &down_server);
880 if (down_server == NULL) {
881 _DEBUG_INFO("not found download server");
882 (*fumo_return) = FUMO_MALFORMED_OR_BAD_URL;
886 #ifdef _DM_BUNDANG_TEST
887 /*redirection code */
888 char *pkg_url = get_new_uri(down_server);
890 ret = fumo_engine_state_operation(full_path, pkg_url, fumo_return);
894 ret = fumo_engine_state_operation(full_path, down_server, fumo_return);
903 str_free(&full_path_pkgurl);
904 str_free(&down_server);
910 str_free(&full_path_pkgurl);
911 str_free(&down_server);
913 _DEBUG_INFO(" end error : %d \n", ret);
918 DM_ERROR firmware_downloadupdate_operation(char *full_path, FUMO_Error * fumo_return)
922 DM_ERROR ret = DM_OK;
924 if (full_path == NULL) {
925 _DEBUG_INFO(" full path = null\n");
926 ret = COMMON_ERR_INTERNAL_NOT_DEFINED;
927 (*fumo_return) = FUMO_MALFORMED_OR_BAD_URL;
931 char *full_path_pkgurl = NULL;
932 full_path_pkgurl = g_strdup_printf("%s%s", full_path, DM_FUMO_DOWNLOADAND_UPDATE_OP_PKGURL);
934 char *down_server = NULL;
935 ret = get_mo_data(full_path_pkgurl, &down_server);
936 _DEBUG_INFO(" server_url : %s\n", down_server);
941 if (down_server == NULL) {
942 _DEBUG_INFO("not found download server");
943 (*fumo_return) = FUMO_MALFORMED_OR_BAD_URL;
947 #ifdef _DM_BUNDANG_TEST
948 /*redirection code */
949 char *pkg_url = get_new_uri(down_server);
951 ret = fumo_engine_state_operation(full_path, pkg_url, fumo_return);
956 ret = fumo_engine_state_operation(full_path, down_server, fumo_return);
965 str_free(&full_path_pkgurl);
966 str_free(&down_server);
972 str_free(&full_path_pkgurl);
973 str_free(&down_server);
975 _DEBUG_INFO(" end error : %d \n", ret);
980 DM_ERROR vendor_dependency_firmware_operation(char *full_path, FUMO_Error * fumo_return)
984 DM_ERROR ret = DM_OK;
985 int check_operation = 1;
987 if (full_path == NULL) {
988 ret = DM_ERR_COMMAND_FAILED;
989 *fumo_return = FUMO_USER_CANCELLED;
993 sync_agent_dm_mo_error_e ext_return;
994 ext_return = sync_agent_execute_mo_ext(full_path, (int *)fumo_return, check_operation);
995 if (ext_return != SYNC_AGENT_DM_MO_SUCCESS) {
996 ret = DM_ERR_COMMAND_FAILED;
997 *fumo_return = FUMO_USER_CANCELLED;
1005 _DEBUG_INFO(" end error : %d\n", ret);
1010 DM_ERROR get_current_fumo_state(char *full_path, char **fumo_state_data)
1013 DM_ERROR ret = DM_OK;
1015 retvm_if((full_path) == NULL, COMMON_ERR_IS_NULL, "full_path is NULL!!");
1017 char *fumo_root = NULL;
1018 char *fumo_state_url = NULL;
1020 //ret = get_mo_servicetype(full_path, &fumo_root);
1021 ret = get_mo_root_path(full_path, &fumo_root);
1023 ret = COMMON_ERR_INTERNAL_NOT_DEFINED;
1026 fumo_state_url = g_strdup_printf("%s%s", fumo_root, DM_FUMO_STATE_OP);
1028 ret = get_mo_data(fumo_state_url, fumo_state_data);
1030 ret = COMMON_ERR_GET_TYPE_NOT_FOUND;
1034 str_free(&fumo_state_url);
1039 str_free(&fumo_state_url);
1041 _DEBUG_INFO(" end error : %d\n", ret);
1046 DM_ERROR set_current_fumo_state(char *full_path, FUMO_State fumo_state)
1050 DM_ERROR ret = DM_OK;
1052 retvm_if((full_path) == NULL, COMMON_ERR_IS_NULL, "full_path is NULL!!");
1054 char *fumo_root = NULL;
1055 char *fumo_state_url = NULL;
1056 char *fumo_state_data = NULL;
1058 //ret = get_mo_servicetype(full_path, &fumo_root);
1059 ret = get_mo_root_path(full_path, &fumo_root);
1064 fumo_state_url = g_strdup_printf("%s%s", fumo_root, DM_FUMO_STATE_OP);
1065 fumo_state_data = g_strdup_printf("%d", fumo_state);
1067 _DEBUG_INFO(" fumo_state : %d\n", fumo_state);
1069 //sync_agent_dm_mo_error_e mo_ret = sync_agent_begin_transaction_mo();
1070 ret = replace_mo_data(fumo_state_url, fumo_state_data);
1071 //mo_ret = sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_COMMIT);
1075 str_free(&fumo_state_url);
1076 str_free(&fumo_state_data);
1082 str_free(&fumo_state_url);
1083 str_free(&fumo_state_data);
1085 _DEBUG_INFO(" end error : %d\n", ret);
1090 static DM_ERROR __check_low_battery()
1094 DM_ERROR ret = DM_OK;
1095 char *battery_level = 0;
1097 ret = get_battery_state(&battery_level);
1101 int int_battery_level = 0;
1102 if (battery_level != NULL) {
1104 err = chartoint((battery_level), &int_battery_level);
1106 _DEBUG_VERBOSE("battery level : %d ", int_battery_level);
1107 if (FOTA_LOW_BATTERY_LEVEL > int_battery_level) {
1109 _DEBUG_VERBOSE("batter : %s, low battery : %d", battery_level, FOTA_LOW_BATTERY_LEVEL);
1110 noti_ret = noti_low_battery(battery_level);
1111 _DEBUG_VERBOSE("noti low battery : %d", noti_ret);
1118 _DEBUG_VERBOSE("battery level is null");
1119 ret = COMMON_ERR_IS_NULL;
1123 _DEBUG_VERBOSE("battery level is null");
1124 ret = COMMON_ERR_IS_NULL;
1127 _DEBUG_VERBOSE("end");
1130 _DEBUG_VERBOSE("end error : %d", DM_LOW_BATTERY_ERROR);
1132 return DM_LOW_BATTERY_ERROR;
1135 static DM_ERROR __check_memory(long double file_size, MEMORY_TYPE * is_internal_memory)
1139 DM_ERROR ret = DM_OK;
1142 long double need_size = file_size * 2;
1144 ret = compare_memory_space(FOTA_DELTA_INTERNAL_STORAGE, need_size);
1147 ret = existed_sd_card_memory(&existed_sd);
1148 if (existed_sd == 0 || ret != DM_OK) {
1149 /* ui ->not existed sd card or make folder error */
1150 ipc_ret = noti_over_max_file_size();
1151 if (ipc_ret == RESPONSE_TYPE_OK) {
1152 _DEBUG_VERBOSE("file size over the memory");
1154 _DEBUG_VERBOSE("file size over the memory ipc fail");
1157 return DM_OVER_MEMORY_ERROR;
1160 /* ui -> do u want to use sd_card? */
1161 ipc_ret = noti_memory_full((int)need_size);
1162 if (ipc_ret == RESPONSE_TYPE_OK) {
1164 //FOTA_DELTA_SD_INTERNAL_STORAGE
1165 ret = compare_memory_space(FOTA_DELTA_SD_EXTERNAL_STORAGE, need_size);
1166 if (ret == DM_MEMORY_ERROR) {
1167 /* ui -> sd_card full */
1168 ipc_ret = noti_over_max_file_size();
1169 if (ipc_ret == RESPONSE_TYPE_OK) {
1170 _DEBUG_VERBOSE("file size over the memory");
1172 _DEBUG_VERBOSE("file size over the memory ipc fail");
1175 return DM_OVER_MEMORY_ERROR;
1177 _DEBUG_VERBOSE("save in sd memory card");
1181 _DEBUG_VERBOSE("memory full ipc fail");
1183 return DM_OVER_MEMORY_ERROR;
1186 (*is_internal_memory) = MEMORY_SD_CARD;
1189 /*internal memory path */
1190 (*is_internal_memory) = MEMORY_INTERNAL;
1197 static DM_ERROR ___get_max_file_size(int *max_file_size)
1202 char *required_contents = NULL;
1203 unsigned long size_return = 0;
1205 err = sync_agent_is_existing_fs(MAX_DELTA_FILE_SIZE);
1206 /*define value when this is file not existed */
1208 _DEBUG_VERBOSE("max file size : 50MB");
1209 *max_file_size = MAX_FILE_SIZE;
1214 /*value when this is file existed */
1215 err = sync_agent_read_whole_file(MAX_DELTA_FILE_SIZE, &required_contents, &size_return);
1217 _DEBUG_VERBOSE("max file size : %s", required_contents);
1219 err = chartoint(required_contents, max_file_size);
1221 str_free(&required_contents);
1225 _DEBUG_VERBOSE("get max file size error");
1227 return COMMON_ERR_IS_NULL;
1230 _DEBUG_VERBOSE("get max file size error");
1232 return COMMON_ERR_IS_NULL;
1234 _DEBUG_VERBOSE("get max file size error");
1237 return COMMON_ERR_IS_NULL;
1240 static DM_ERROR __check_max_file_size(int file_size)
1244 DM_ERROR ret = DM_OK;
1247 int max_file_size = 0;
1248 ret = ___get_max_file_size(&max_file_size);
1250 _DEBUG_VERBOSE("get max file size error");
1251 ret = DM_WIFI_ONLY_ERROR;
1254 _DEBUG_VERBOSE("file size = %d, max file size = %d", file_size, max_file_size);
1256 /*max_file_size = 0 (0 in file or not existed file)
1257 * - can't use this option
1258 * - this option is max file size define in file when 3g mode
1260 if (max_file_size != 0 && file_size > max_file_size) {
1261 noti_res = noti_over_max_file_size();
1262 _DEBUG_VERBOSE("noti over max file size : %d", noti_res);
1264 _DEBUG_VERBOSE("can't save current_size on 3g mode");
1265 ret = DM_WIFI_ONLY_ERROR;
1269 _DEBUG_VERBOSE("save current size on 3g mode");
1277 _DEBUG_INFO("end error : %d", ret);