/* * oma-dm-agent * Copyright (c) 2012 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /*sync-agent*/ #include /*dm-agent*/ #include "common/dm_common.h" #include "common/util/util.h" #include "mo-handler/dm_mo_common.h" #include "mo-handler/dm_mo_handler.h" #include "dm-engine/fumo/fumo_engine.h" #include "dm-engine/dl-manager/fw_downloader.h" #include "dm-engine/dl-manager/dd_object.h" #include "ipc_common.h" #include "ipc_agent.h" #define MAX_FILE_SIZE 52428800 #ifndef OMADM_AGENT_LOG #undef LOG_TAG #define LOG_TAG "FUMO_ENGINE" #endif #define FOTA_LOW_BATTERY_LEVEL 50 static DM_ERROR _firmware_download(char *server_url, MEMORY_TYPE * memory_type, FUMO_Error * fumo_return); static DM_ERROR _firmware_install(char *full_path, MEMORY_TYPE memory_type, FUMO_Error * fumo_return); static DM_ERROR __check_low_battery(); static DM_ERROR __check_memory(long double file_size, MEMORY_TYPE * is_internal_memory); static DM_ERROR ___get_max_file_size(int *max_file_size); static DM_ERROR __check_max_file_size(int file_size); DM_ERROR fumo_engine_state_operation(char *full_path, char *down_server, FUMO_Error * fumo_return) { _EXTERN_FUNC_ENTER; DM_ERROR ret = DM_OK; retvm_if((full_path) == NULL, COMMON_ERR_IS_NULL, "full_path is NULL!!"); retvm_if((down_server) == NULL, COMMON_ERR_IS_NULL, "down_server is NULL!!"); char *result_mo_type = NULL; sync_agent_dev_return_e dci_ret_exec = SYNC_AGENT_DEV_RETURN_SUCCESS; bool cancel_flag = false; MEMORY_TYPE memory_type = MEMORY_INTERNAL; char *fumo_state_data = NULL; FUMO_State fumo_state = UNKNOWN; retvm_if((full_path) == NULL, COMMON_ERR_IS_NULL, "full_path is NULL!!"); ret = get_mo_operationtype(full_path, &result_mo_type); if (ret != DM_OK) goto error; ret = get_current_fumo_state(full_path, &fumo_state_data); if (ret != DM_OK) goto error; if (chartoint(fumo_state_data, (int *)(&fumo_state)) == 0) { _DEBUG_INFO("error char to int value"); ret = COMMON_ERR_IS_NULL; goto error; } _DEBUG_INFO(" -----------------------------------------------------------------------------------------------\n"); _DEBUG_INFO(" get fumo_state in db : %d\n", fumo_state); _DEBUG_INFO(" -----------------------------------------------------------------------------------------------\n"); switch (fumo_state) { case IDLE_START: case DOWNLOAD_PROGRESSING:{ _DEBUG_INFO(" DOWNLOAD_PROGRESSING\n"); fumo_state = DOWNLOAD_PROGRESSING; cancel_flag = sync_agent_check_cancel_flag(); if (cancel_flag != 0) { ret = DM_OK; *fumo_return = FUMO_USER_CANCELLED; fumo_state = DOWNLOAD_FAILED; goto error; } ret = _firmware_download(down_server, &memory_type, fumo_return); if (ret != DM_OK && ret != DM_DOWNLOAD_POPUP && ret != DM_RESUME_IDLE) { fumo_state = DOWNLOAD_FAILED; goto error; } _DEBUG_INFO("fimware donwload success : 200 , cancel : 562, result is : %d\n", ret); cancel_flag = sync_agent_check_cancel_flag(); if (cancel_flag != 0) { ret = DM_OK; *fumo_return = FUMO_USER_CANCELLED; fumo_state = DOWNLOAD_FAILED; goto error; } if (ret == DM_OK) { _DEBUG_INFO("-----------download ok---------------"); fumo_state = DOWNLOAD_COMPLETE; RESUME_STATUS download_clicked = RESUME_STATUS_INSTALL_BEFORE; ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_DOWNLOAD_CLICK, &download_clicked); _DEBUG_INFO("update engine status clolumn download click : %d", ret); ret = DM_OK; } else if (ret == DM_ERR_REMINDER_INTERVAL || ret == DM_DOWNLOAD_POPUP || ret == DM_RESUME_IDLE) { _DEBUG_INFO("-----------download popup---------------"); fumo_state = DOWNLOAD_PROGRESSING; goto returnpart; } else { _DEBUG_INFO("-----------download fail---------------\n"); *fumo_return = FUMO_USER_CANCELLED; fumo_state = DOWNLOAD_FAILED; } ret = set_current_fumo_state(full_path, fumo_state); if (ret != DM_OK) goto error; if (strcmp(result_mo_type, DM_FUMO_DOWNLOAD_OP) == 0) { } else if (strcmp(result_mo_type, DM_FUMO_UPDATE_OP) == 0) { } else if (strcmp(result_mo_type, DM_FUMO_DOWNLOADAND_UPDATE_OP) == 0) { fumo_engine_state_operation(full_path, down_server, fumo_return); _DEBUG_INFO("engine state result : %d", ret); } } break; case DOWNLOAD_FAILED: _DEBUG_INFO(" DOWNLOAD_FAILED\n"); goto error; break; case DOWNLOAD_COMPLETE:{ _DEBUG_INFO(" DOWNLOAD_COMPLETE\n"); if (strcmp(result_mo_type, DM_FUMO_DOWNLOAD_OP) == 0) { } else if ((strcmp(result_mo_type, DM_FUMO_UPDATE_OP)) == 0 || strcmp(result_mo_type, DM_FUMO_DOWNLOADAND_UPDATE_OP) == 0) { fumo_state = READY_TO_UPDATE; ret = set_current_fumo_state(full_path, fumo_state); if (ret != DM_OK) goto error; fumo_engine_state_operation(full_path, down_server, fumo_return); _DEBUG_INFO("engine state result : %d", ret); } } break; case READY_TO_UPDATE:{ cancel_flag = sync_agent_check_cancel_flag(); if (cancel_flag != 0) { ret = DM_OK; *fumo_return = FUMO_USER_CANCELLED; fumo_state = DOWNLOAD_FAILED; goto error; } ret = _firmware_install(full_path, memory_type, fumo_return); if (ret == DM_OK) { /*if install success was rebooted */ _DEBUG_INFO("install fail"); goto error; } else if (ret == COMMON_ERR_IPC || ret == DM_LOW_BATTERY_ERROR) { _DEBUG_INFO("-----------cancel or ipc error---------------"); fumo_state = UPDATE_FAILED_HAVE_DATA; goto returnpart; } else if (ret == DM_ERR_REMINDER_INTERVAL || ret == DM_INSTALL_POPUP || ret == DM_RESUME_IDLE) { _DEBUG_INFO("-----------download popup---------------"); fumo_state = READY_TO_UPDATE; goto returnpart; } else { _DEBUG_INFO("-----------install fail---------------\n"); *fumo_return = FUMO_USER_CANCELLED; fumo_state = UPDATE_FAILED_HAVE_DATA; } } break; case UPDATE_PROGRESSING:{ cancel_flag = sync_agent_check_cancel_flag(); if (cancel_flag != 0) { ret = DM_OK; *fumo_return = FUMO_USER_CANCELLED; fumo_state = DOWNLOAD_FAILED; goto error; } dci_ret_exec = sync_agent_execute_dev_function(2, "fota_result", 1, (int *)fumo_return); //*fumo_return = result; //*fumo_return = 202; _DEBUG_INFO("-----------------firmware update result : %d fumo return : %d------------------", dci_ret_exec, (*fumo_return)); if (dci_ret_exec != SYNC_AGENT_DEV_RETURN_SUCCESS) { fumo_state = UPDATE_FAILED_HAVE_DATA; } else { fumo_state = UPDATE_SUCCESSFUL_HAVE_DATA; } ret = set_current_fumo_state(full_path, fumo_state); if (ret != DM_OK) goto error; ret = fumo_engine_state_operation(full_path, down_server, fumo_return); _DEBUG_INFO("engine state result : %d", ret); } break; case UPDATE_FAILED_HAVE_DATA: case UPDATE_FAILED_NO_DATA:{ delete_fumo_contents(memory_type); fumo_state = IDLE_START; set_current_fumo_state(full_path, fumo_state); /* if(ret != DM_OK) goto error;*/ /*ret = FUMO_UPDATE_FAILED; */ *fumo_return = FUMO_UPDATE_FAILED; _DEBUG_INFO("update fail "); } break; case UPDATE_SUCCESSFUL_HAVE_DATA: case UPDATE_SUCCESSFUL_NO_DATA:{ _DEBUG_INFO("----------------------------------------------------------firmware update success delete files-----------------------------------------------------------"); delete_fumo_contents(memory_type); fumo_state = IDLE_START; set_current_fumo_state(full_path, fumo_state); /* if(ret != DM_OK) goto error;*/ /*ret = FUMO_SUCCESS; */ *fumo_return = FUMO_SUCCESS; _DEBUG_INFO("update success "); } break; default: break; } // str_free(&result_mo_type); _DEBUG_INFO(" end fumo state : %d\n", fumo_state); str_free(&fumo_state_data); _EXTERN_FUNC_EXIT; return ret; returnpart: _DEBUG_INFO("----------------------------------------------------------fumo download, install popup----------------------------------------------------------- %d", fumo_state); set_current_fumo_state(full_path, fumo_state); str_free(&fumo_state_data); str_free(&result_mo_type); _EXTERN_FUNC_EXIT; return ret; error: _DEBUG_INFO("----------------------------------------------------------fumo error-----------------------------------------------------------"); delete_fumo_contents(memory_type); fumo_state = IDLE_START; set_current_fumo_state(full_path, fumo_state); str_free(&fumo_state_data); str_free(&result_mo_type); _DEBUG_INFO(" end error : %d\n", ret); _EXTERN_FUNC_EXIT; return ret; } DM_ERROR fumo_exec(char *full_path, char *correlator, FUMO_Error * fumo_return) { _EXTERN_FUNC_ENTER; DM_ERROR ret = DM_OK; retvm_if((full_path) == NULL, COMMON_ERR_IS_NULL, "full_path is NULL!!"); char *result_mo_type = NULL; ret = get_mo_operationtype(full_path, &result_mo_type); if (ret != DM_OK) goto error; if (result_mo_type == NULL) { _DEBUG_INFO("result_mo_type is null"); ret = COMMON_ERR_IS_NULL; goto error; } if (strcmp(result_mo_type, DM_FUMO_DOWNLOAD_OP) == 0) { ret = firmware_download_opeartion(full_path, fumo_return); if (ret != DM_OK) goto error; } else if (strcmp(result_mo_type, DM_FUMO_UPDATE_OP) == 0) { ret = firmware_update_operation(full_path, fumo_return); if (ret != DM_OK) goto error; } else if (strcmp(result_mo_type, DM_FUMO_DOWNLOADAND_UPDATE_OP) == 0) { ret = firmware_downloadupdate_operation(full_path, fumo_return); if (ret != DM_OK) goto error; } else { ret = vendor_dependency_firmware_operation(full_path, fumo_return); if (ret != DM_OK) goto error; } str_free(&result_mo_type); _DEBUG_INFO(" end : %d", ret); _EXTERN_FUNC_EXIT; return ret; error: str_free(&result_mo_type); _DEBUG_INFO(" end error : %d \n", ret); _EXTERN_FUNC_EXIT; return ret; } static DM_ERROR _firmware_download(char *server_url, MEMORY_TYPE * memory_type, FUMO_Error * fumo_return) { _INNER_FUNC_ENTER; DM_ERROR ret = DM_OK; DM_ERROR download_status = DM_ERR_USER_CANDELLED; DM_ERROR installNofity_ret = DM_OK; bool cancel_flag; int config = -1; char *download_folder = NULL; int file_size = 0; Download_Descriptor *download_descriptor = NULL; engine_status *status = NULL; int noti_res = 0; if (server_url == NULL) { *fumo_return = FUMO_USER_CANCELLED; download_status = DM_ERR_INVALID_DESCRIPTOR; ret = COMMON_ERR_INTERNAL_NOT_DEFINED; goto error; } _DEBUG_TRACE("----------------------------------------------------------------------------------------------------- \n"); _DEBUG_TRACE(" server url : %s \n", server_url); _DEBUG_TRACE("----------------------------------------------------------------------------------------------------- \n"); ret = Get_Engine_Status(FUMO_SERVICE_ENGINE, &status); if (ret != DM_OK || status == NULL) { *fumo_return = FUMO_USER_CANCELLED; download_status = DM_ERR_USER_CANDELLED; goto error; } switch (status->download_click) { case RESUME_STATUS_DONWLOAD_BEFORE: /*before click download popup */ { _DEBUG_TRACE(" user interaction start \n"); cancel_flag = sync_agent_check_cancel_flag(); _DEBUG_TRACE(" cancel_flag : %d \n", cancel_flag); if (cancel_flag != 0) { *fumo_return = FUMO_USER_CANCELLED; download_status = DM_ERR_USER_CANDELLED; ret = DM_OK; goto error; } int noti_res; _DEBUG_TRACE("waiting connect to server success in firmware download\n"); noti_res = noti_download(); _DEBUG_TRACE("download noti response : %d \n ", noti_res); if (noti_res == RESPONSE_TYPE_OK) { ret = DM_DOWNLOAD_POPUP; goto returnpart; } else { _DEBUG_TRACE("------------------------------------------------------downlaod popup noti error--------------------------------------------\n"); // error in noti-process *fumo_return = FUMO_USER_CANCELLED; download_status = DM_ERR_USER_CANDELLED; ret = COMMON_ERR_IPC; goto error; } } break; case RESUME_STATUS_DOWNLOAD: /*after click download popup */ { _DEBUG_TRACE("------------------------------------------------------download button click---------------------------------------------\n"); download_descriptor = (Download_Descriptor *) calloc(1, sizeof(Download_Descriptor) + 1); if (download_descriptor == NULL) { _DEBUG_TRACE("calloc failed !!"); ret = COMMON_ERR_ALLOC; *fumo_return = FUMO_USER_CANCELLED; download_status = DM_ERR_INVALID_DESCRIPTOR; goto error; } ret = get_object_information(server_url, &file_size, &download_descriptor, &download_status); if (ret != DM_OK) { *fumo_return = FUMO_USER_CANCELLED; download_status = DM_ERR_INVALID_DESCRIPTOR; goto error; } _DEBUG_TRACE(" user interaction start \n"); cancel_flag = sync_agent_check_cancel_flag(); _DEBUG_TRACE(" cancel_flag : %d \n", cancel_flag); if (cancel_flag != 0) { *fumo_return = FUMO_USER_CANCELLED; download_status = DM_ERR_USER_CANDELLED; ret = DM_OK; goto error; } /*wifi config */ config = get_wifi_only_config(); /*battery state check */ ret = __check_low_battery(); _DEBUG_TRACE("ret : %d \n", ret); if (ret != DM_OK) { ret = DM_OK; *fumo_return = FUMO_USER_CANCELLED; goto error; } _DEBUG_TRACE("======================================================"); _DEBUG_TRACE("object size %d\n", file_size); _DEBUG_TRACE("======================================================"); ret = __check_memory(file_size, memory_type); if (ret != DM_OK) { noti_res = noti_memory_full((int)file_size); if (noti_res == RESPONSE_TYPE_OK) { _DEBUG_TRACE("memory full popup success"); } else { _DEBUG_TRACE("memory full popup fail"); } download_status = DM_ERR_INSUFFICIENT_MEMORY; *fumo_return = FUMO_USER_CANCELLED; ret = DM_OK; goto error; } if (config == -1) { _DEBUG_TRACE("get wifi only config error"); *fumo_return = FUMO_MALFORMED_OR_BAD_URL; download_status = DM_ERR_USER_CANDELLED; ret = DM_WIFI_ONLY_ERROR; goto error; } else if (config == 0) { _DEBUG_TRACE("wifi config = 0"); int wifi_ret = 0; wifi_ret = get_wifi_state(); _DEBUG_TRACE("wifi mode : %d", wifi_ret); if (wifi_ret != 1) { _DEBUG_TRACE("3g mode"); ret = __check_max_file_size(file_size); if (ret != DM_OK) { _DEBUG_TRACE("get max file size error"); *fumo_return = FUMO_DOWNLOAD_FAILS_DUE_TO_DEVICE_OUT_OF_MEMORY; download_status = DM_ERR_USER_CANDELLED; ret = DM_WIFI_ONLY_ERROR; goto error; } } else { _DEBUG_TRACE("wifi mode"); } } else { _DEBUG_TRACE("wifi config = 1"); _DEBUG_TRACE("wifi only mode"); } ret = get_fota_download_dir((*memory_type), &download_folder); if (ret != DM_OK) { *fumo_return = FUMO_DOWNLOAD_FAILS_DUE_TO_DEVICE_OUT_OF_MEMORY; download_status = DM_ERR_INSUFFICIENT_MEMORY; goto error; } _DEBUG_TRACE(" download ok \n "); char *downloadUrl = NULL; ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_SERVER_URL, downloadUrl); if (ret != DM_OK) { *fumo_return = FUMO_USER_CANCELLED; download_status = DM_ERR_USER_CANDELLED; goto error; } /* remove remind interval */ delete_alarm_item(FUMO_INTERVAL, FUMO_INTERVAL_TYPE); _DEBUG_TRACE(" delete fumo reminder in config db "); //FOTASaveDir //FOTADownDir DOWNLOAD_FILE_STATUS file_status = 0; Data_Resume_Infomation *data_resume_info = NULL; ret = check_file_resume(download_folder, &file_status, download_descriptor, &data_resume_info); if (ret != DM_OK) { *fumo_return = FUMO_MALFORMED_OR_BAD_URL; download_status = DM_ERR_USER_CANDELLED; goto error; } _DEBUG_TRACE(" file_status = %d \n", file_status); /*was maked by sooyi */ if (file_status != EXIST_COMPLETED_FILE) { char *object_path = 0; if (config == -1) { _DEBUG_TRACE("get wifi only config error"); *fumo_return = FUMO_MALFORMED_OR_BAD_URL; download_status = DM_ERR_USER_CANDELLED; ret = DM_WIFI_ONLY_ERROR; goto error; } else { _DEBUG_TRACE("get wifi only config value : %d", config); ret = download_object(download_folder, &object_path, data_resume_info, config, download_descriptor, &download_status); _DEBUG_TRACE("download object : %s", object_path); _DEBUG_TRACE(" download_object result : %d \n", ret); if (ret != DM_OK) { if (ret == DM_WIFI_ONLY_ERROR) { _DEBUG_TRACE("send_DL_Msg() err [%d]\n", ret); /* ipc wifi only pop up */ noti_res = noti_wifi_only_download_fail(); if (noti_res == RESPONSE_TYPE_OK) { _DEBUG_TRACE("send_wifi only fail ipc success"); } else { _DEBUG_TRACE("send_wifi only fail ipc fail"); } } *fumo_return = FUMO_USER_CANCELLED; download_status = DM_ERR_USER_CANDELLED; goto error; } else { //do nothing } installNofity_ret = send_donwload_status(download_status, download_descriptor); _DEBUG_TRACE("send installNotify : %d", installNofity_ret); } } else { _DEBUG_TRACE(" file is exist\n"); } } break; case RESUME_STATUS_DOWNLOAD_LATER: /*later button clicked */ { _DEBUG_TRACE("------------------------------------------------------later button click---------------------------------------------\n"); download_descriptor = (Download_Descriptor *) calloc(1, sizeof(Download_Descriptor) + 1); if (download_descriptor == NULL) { _DEBUG_TRACE("calloc failed !!"); ret = COMMON_ERR_ALLOC; *fumo_return = FUMO_USER_CANCELLED; download_status = DM_ERR_INVALID_DESCRIPTOR; goto error; } ret = get_object_information(server_url, &file_size, &download_descriptor, &download_status); if (ret != DM_OK) { *fumo_return = FUMO_USER_CANCELLED; download_status = DM_ERR_INVALID_DESCRIPTOR; goto error; } installNofity_ret = send_donwload_status(download_status, download_descriptor); _DEBUG_TRACE("send installNotify : %d", installNofity_ret); RESUME_STATUS download_clicked = RESUME_STATUS_DOWNLOAD_IDLE; ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_DOWNLOAD_CLICK, &download_clicked); _DEBUG_TRACE("update engine status clolumn download click : %d", ret); *fumo_return = FUMO_USER_CANCELLED; download_status = DM_ERR_USER_CANDELLED; ret = DM_ERR_REMINDER_INTERVAL; } break; case RESUME_STATUS_DOWNLOAD_IDLE: default: { /*case RESUME_STATUS_IDLE, default */ ret = DM_RESUME_IDLE; goto returnpart; _DEBUG_TRACE("----------------------------------------------------bad flow--------------------------------------------------------------------"); } break; } if (status != NULL) Free_Memory_Engine_Status(&status, 1); if (download_descriptor != NULL) { _DEBUG_TRACE("__free_Download_Descriptor()\n"); free_Download_Descriptor(&download_descriptor); } str_free(&download_folder); _INNER_FUNC_EXIT; return ret; returnpart: if (status != NULL) Free_Memory_Engine_Status(&status, 1); if (download_descriptor != NULL) { _DEBUG_TRACE("__free_Download_Descriptor()\n"); free_Download_Descriptor(&download_descriptor); } str_free(&download_folder); _DEBUG_TRACE(" end error : %d \n", ret); _INNER_FUNC_EXIT; return ret; error: if (status != NULL) Free_Memory_Engine_Status(&status, 1); installNofity_ret = send_donwload_status(download_status, download_descriptor); _DEBUG_INFO("send installNotify : %d", installNofity_ret); if (download_descriptor != NULL) { _DEBUG_INFO("__free_Download_Descriptor()\n"); free_Download_Descriptor(&download_descriptor); } str_free(&download_folder); _DEBUG_INFO(" end error : %d \n", ret); _INNER_FUNC_EXIT; return ret; } static DM_ERROR _firmware_install(char *full_path, MEMORY_TYPE memory_type, FUMO_Error * fumo_return) { _INNER_FUNC_ENTER; DM_ERROR ret = DM_OK; if (full_path == NULL) { *fumo_return = FUMO_USER_CANCELLED; goto error; } sync_agent_dev_return_e dci_ret_flag = SYNC_AGENT_DEV_RETURN_SUCCESS; engine_status *status = NULL; int noti_res = 0; FUMO_State fumo_state = READY_TO_UPDATE; ret = Get_Engine_Status(FUMO_SERVICE_ENGINE, &status); if (ret != DM_OK || status == NULL) { *fumo_return = FUMO_USER_CANCELLED; goto error; } switch (status->download_click) { case RESUME_STATUS_INSTALL_BEFORE: { /** install UI control */ noti_res = noti_install(); if (noti_res == RESPONSE_TYPE_OK) { ret = DM_INSTALL_POPUP; goto returnpart; } else { // error in noti-process ret = COMMON_ERR_IPC; *fumo_return = FUMO_USER_CANCELLED; goto error; } } break; case RESUME_STATUS_INSTALL: { /* battery state check */ ret = __check_low_battery(); if (ret != DM_OK) { ret = DM_LOW_BATTERY_ERROR; *fumo_return = FUMO_USER_CANCELLED; goto error; } _DEBUG_TRACE("------------------fota install ok------------------"); _DEBUG_TRACE(" fota flag api \n"); delete_alarm_item(FUMO_INTERVAL, FUMO_INTERVAL_TYPE); _DEBUG_TRACE(" delete fumo reminder in config db "); fumo_state = UPDATE_PROGRESSING; ret = set_current_fumo_state(full_path, fumo_state); if (ret != DM_OK) { *fumo_return = FUMO_USER_CANCELLED; goto error; } dci_ret_flag = sync_agent_execute_dev_function(2, "fota_flag", 1, memory_type); //dci_ret_flag= SYNC_AGENT_DEV_RETURN_SUCCESS; _DEBUG_TRACE(" fota flag result : %d \n", dci_ret_flag); if (dci_ret_flag != SYNC_AGENT_DEV_RETURN_SUCCESS) { _DEBUG_TRACE(" fota flag fail!!!!!!!!!!!! \n"); *fumo_return = FUMO_FAILED_VALIDATION; ret = set_current_fumo_state(full_path, fumo_state); if (ret != DM_OK) { *fumo_return = FUMO_USER_CANCELLED; goto error; } goto error; } else { //for reboot _DEBUG_TRACE(" -------------------------------------------------------------------- \n"); _DEBUG_TRACE(" fota install to be rebooting l!!!!!!!!!!!! \n"); _DEBUG_TRACE(" -------------------------------------------------------------------- \n"); sleep(1); exit(0); break; } } break; case RESUME_STATUS_INSTALL_LATER: { //cancle to install _DEBUG_TRACE("------------------canceled install------------------"); *fumo_return = FUMO_USER_CANCELLED; RESUME_STATUS download_clicked = RESUME_STATUS_INSTALL_IDLE; ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_DOWNLOAD_CLICK, &download_clicked); _DEBUG_TRACE("update engine status clolumn download click : %d", ret); /*fumo_state = IDLE_START; ret = set_current_fumo_state(full_path, fumo_state); if(ret != DM_OK) goto error; */ ret = DM_ERR_REMINDER_INTERVAL; goto error; } break; case RESUME_STATUS_INSTALL_IDLE: default: { ret = DM_RESUME_IDLE; goto returnpart; _DEBUG_TRACE("----------------------------------------------------install later --------------------------------------------------------------------"); } break; } if (status != NULL) { Free_Memory_Engine_Status(&status, 1); } _INNER_FUNC_EXIT; return ret; returnpart: if (status != NULL) { Free_Memory_Engine_Status(&status, 1); } _DEBUG_INFO(" return part : %d \n", ret); _INNER_FUNC_EXIT; return ret; error: if (status != NULL) { Free_Memory_Engine_Status(&status, 1); } _DEBUG_INFO(" end error : %d \n", ret); _INNER_FUNC_EXIT; return ret; } DM_ERROR firmware_download_opeartion(char *full_path, FUMO_Error * fumo_return) { _EXTERN_FUNC_ENTER; /*call DL module */ _DEBUG_INFO(" start\n"); DM_ERROR ret = DM_OK; if (full_path == NULL) { (*fumo_return) = FUMO_MALFORMED_OR_BAD_URL; goto error; } char *full_path_pkgurl = NULL; full_path_pkgurl = g_strdup_printf("%s%s", full_path, DM_FUMO_DWONLOAD_OP_PKGURL); char *down_server = NULL; ret = get_mo_data(full_path_pkgurl, &down_server); if (ret != DM_OK) { goto error; } if (down_server == NULL) { _DEBUG_INFO("not found download server"); (*fumo_return) = FUMO_MALFORMED_OR_BAD_URL; //ret = goto error; } #ifdef _DM_BUNDANG_TEST /*redirection code */ char *pkg_url = get_new_uri(down_server); ret = fumo_engine_state_operation(full_path, pkg_url, fumo_return); if (ret != DM_OK) goto error; #else ret = fumo_engine_state_operation(full_path, down_server, fumo_return); if (ret != DM_OK) goto error; #endif /* * return server ret */ str_free(&full_path_pkgurl); str_free(&down_server); _EXTERN_FUNC_EXIT; return ret; error: str_free(&full_path_pkgurl); str_free(&down_server); _DEBUG_INFO(" end error : %d \n", ret); _EXTERN_FUNC_EXIT; return ret; } DM_ERROR firmware_update_operation(char *full_path, FUMO_Error * fumo_return) { _EXTERN_FUNC_ENTER; DM_ERROR ret = DM_OK; if (full_path == NULL) { (*fumo_return) = FUMO_MALFORMED_OR_BAD_URL; goto error; } char *full_path_pkgurl = NULL; full_path_pkgurl = g_strdup_printf("%s%s", full_path, DM_FUMO_UPDATE_PKG_OP_DATA); char *down_server = NULL; ret = get_mo_data(full_path_pkgurl, &down_server); if (ret != DM_OK) { goto error; } if (down_server == NULL) { _DEBUG_INFO("not found download server"); (*fumo_return) = FUMO_MALFORMED_OR_BAD_URL; //ret = goto error; } #ifdef _DM_BUNDANG_TEST /*redirection code */ char *pkg_url = get_new_uri(down_server); ret = fumo_engine_state_operation(full_path, pkg_url, fumo_return); if (ret != DM_OK) goto error; #else ret = fumo_engine_state_operation(full_path, down_server, fumo_return); if (ret != DM_OK) goto error; #endif /* * return server ret */ str_free(&full_path_pkgurl); str_free(&down_server); _EXTERN_FUNC_EXIT; return ret; error: str_free(&full_path_pkgurl); str_free(&down_server); _DEBUG_INFO(" end error : %d \n", ret); _EXTERN_FUNC_EXIT; return ret; } DM_ERROR firmware_downloadupdate_operation(char *full_path, FUMO_Error * fumo_return) { _EXTERN_FUNC_ENTER; DM_ERROR ret = DM_OK; if (full_path == NULL) { _DEBUG_INFO(" full path = null\n"); ret = COMMON_ERR_INTERNAL_NOT_DEFINED; (*fumo_return) = FUMO_MALFORMED_OR_BAD_URL; goto error; } char *full_path_pkgurl = NULL; full_path_pkgurl = g_strdup_printf("%s%s", full_path, DM_FUMO_DOWNLOADAND_UPDATE_OP_PKGURL); char *down_server = NULL; ret = get_mo_data(full_path_pkgurl, &down_server); _DEBUG_INFO(" server_url : %s\n", down_server); if (ret != DM_OK) { goto error; } if (down_server == NULL) { _DEBUG_INFO("not found download server"); (*fumo_return) = FUMO_MALFORMED_OR_BAD_URL; //ret = goto error; } #ifdef _DM_BUNDANG_TEST /*redirection code */ char *pkg_url = get_new_uri(down_server); ret = fumo_engine_state_operation(full_path, pkg_url, fumo_return); if (ret != DM_OK) { goto error; } #else ret = fumo_engine_state_operation(full_path, down_server, fumo_return); if (ret != DM_OK) { goto error; } #endif /* * return server ret */ str_free(&full_path_pkgurl); str_free(&down_server); _EXTERN_FUNC_EXIT; return ret; error: str_free(&full_path_pkgurl); str_free(&down_server); _DEBUG_INFO(" end error : %d \n", ret); _EXTERN_FUNC_EXIT; return ret; } DM_ERROR vendor_dependency_firmware_operation(char *full_path, FUMO_Error * fumo_return) { _EXTERN_FUNC_ENTER; DM_ERROR ret = DM_OK; int check_operation = 1; if (full_path == NULL) { ret = DM_ERR_COMMAND_FAILED; *fumo_return = FUMO_USER_CANCELLED; goto error; } sync_agent_dm_mo_error_e ext_return; ext_return = sync_agent_execute_mo_ext(full_path, (int *)fumo_return, check_operation); if (ext_return != SYNC_AGENT_DM_MO_SUCCESS) { ret = DM_ERR_COMMAND_FAILED; *fumo_return = FUMO_USER_CANCELLED; goto error; } _EXTERN_FUNC_EXIT; return ret; error: _DEBUG_INFO(" end error : %d\n", ret); _EXTERN_FUNC_EXIT; return ret; } DM_ERROR get_current_fumo_state(char *full_path, char **fumo_state_data) { _EXTERN_FUNC_ENTER; DM_ERROR ret = DM_OK; retvm_if((full_path) == NULL, COMMON_ERR_IS_NULL, "full_path is NULL!!"); char *fumo_root = NULL; char *fumo_state_url = NULL; //ret = get_mo_servicetype(full_path, &fumo_root); ret = get_mo_root_path(full_path, &fumo_root); if (ret != DM_OK) { ret = COMMON_ERR_INTERNAL_NOT_DEFINED; goto error; } fumo_state_url = g_strdup_printf("%s%s", fumo_root, DM_FUMO_STATE_OP); ret = get_mo_data(fumo_state_url, fumo_state_data); if (ret != DM_OK) { ret = COMMON_ERR_GET_TYPE_NOT_FOUND; goto error; } str_free(&fumo_state_url); _EXTERN_FUNC_EXIT; return ret; error: str_free(&fumo_state_url); _DEBUG_INFO(" end error : %d\n", ret); _EXTERN_FUNC_EXIT; return ret; } DM_ERROR set_current_fumo_state(char *full_path, FUMO_State fumo_state) { _EXTERN_FUNC_ENTER; DM_ERROR ret = DM_OK; retvm_if((full_path) == NULL, COMMON_ERR_IS_NULL, "full_path is NULL!!"); char *fumo_root = NULL; char *fumo_state_url = NULL; char *fumo_state_data = NULL; //ret = get_mo_servicetype(full_path, &fumo_root); ret = get_mo_root_path(full_path, &fumo_root); if (ret != DM_OK) { goto error; } fumo_state_url = g_strdup_printf("%s%s", fumo_root, DM_FUMO_STATE_OP); fumo_state_data = g_strdup_printf("%d", fumo_state); _DEBUG_INFO(" fumo_state : %d\n", fumo_state); //sync_agent_dm_mo_error_e mo_ret = sync_agent_begin_transaction_mo(); ret = replace_mo_data(fumo_state_url, fumo_state_data); //mo_ret = sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_COMMIT); if (ret != DM_OK) goto error; str_free(&fumo_state_url); str_free(&fumo_state_data); _EXTERN_FUNC_EXIT; return ret; error: str_free(&fumo_state_url); str_free(&fumo_state_data); _DEBUG_INFO(" end error : %d\n", ret); _EXTERN_FUNC_EXIT; return ret; } static DM_ERROR __check_low_battery() { _INNER_FUNC_ENTER; DM_ERROR ret = DM_OK; char *battery_level = 0; ret = get_battery_state(&battery_level); if (ret != DM_OK) goto error; int int_battery_level = 0; if (battery_level != NULL) { int err; err = chartoint((battery_level), &int_battery_level); if (err == 1) { _DEBUG_VERBOSE("battery level : %d ", int_battery_level); if (FOTA_LOW_BATTERY_LEVEL > int_battery_level) { int noti_ret = 0; _DEBUG_VERBOSE("batter : %s, low battery : %d", battery_level, FOTA_LOW_BATTERY_LEVEL); noti_ret = noti_low_battery(battery_level); _DEBUG_VERBOSE("noti low battery : %d", noti_ret); goto error; } else { //do nothing } } else { _DEBUG_VERBOSE("battery level is null"); ret = COMMON_ERR_IS_NULL; goto error; } } else { _DEBUG_VERBOSE("battery level is null"); ret = COMMON_ERR_IS_NULL; goto error; } _DEBUG_VERBOSE("end"); return ret; error: _DEBUG_VERBOSE("end error : %d", DM_LOW_BATTERY_ERROR); _INNER_FUNC_EXIT; return DM_LOW_BATTERY_ERROR; } static DM_ERROR __check_memory(long double file_size, MEMORY_TYPE * is_internal_memory) { _INNER_FUNC_ENTER; DM_ERROR ret = DM_OK; int ipc_ret = 0; int existed_sd; long double need_size = file_size * 2; ret = compare_memory_space(FOTA_DELTA_INTERNAL_STORAGE, need_size); if (ret != DM_OK) { ret = existed_sd_card_memory(&existed_sd); if (existed_sd == 0 || ret != DM_OK) { /* ui ->not existed sd card or make folder error */ ipc_ret = noti_over_max_file_size(); if (ipc_ret == RESPONSE_TYPE_OK) { _DEBUG_VERBOSE("file size over the memory"); } else { _DEBUG_VERBOSE("file size over the memory ipc fail"); } _INNER_FUNC_EXIT; return DM_OVER_MEMORY_ERROR; } /* ui -> do u want to use sd_card? */ ipc_ret = noti_memory_full((int)need_size); if (ipc_ret == RESPONSE_TYPE_OK) { //FOTA_DELTA_SD_INTERNAL_STORAGE ret = compare_memory_space(FOTA_DELTA_SD_EXTERNAL_STORAGE, need_size); if (ret == DM_MEMORY_ERROR) { /* ui -> sd_card full */ ipc_ret = noti_over_max_file_size(); if (ipc_ret == RESPONSE_TYPE_OK) { _DEBUG_VERBOSE("file size over the memory"); } else { _DEBUG_VERBOSE("file size over the memory ipc fail"); } _INNER_FUNC_EXIT; return DM_OVER_MEMORY_ERROR; } else { _DEBUG_VERBOSE("save in sd memory card"); } } else { _DEBUG_VERBOSE("memory full ipc fail"); _INNER_FUNC_EXIT; return DM_OVER_MEMORY_ERROR; } /*sd card path */ (*is_internal_memory) = MEMORY_SD_CARD; } else { /*internal memory path */ (*is_internal_memory) = MEMORY_INTERNAL; } _INNER_FUNC_EXIT; return DM_OK; } static DM_ERROR ___get_max_file_size(int *max_file_size) { _INNER_FUNC_ENTER; int err = 0; char *required_contents = NULL; unsigned long size_return = 0; err = sync_agent_is_existing_fs(MAX_DELTA_FILE_SIZE); /*define value when this is file not existed */ if (err == 0) { _DEBUG_VERBOSE("max file size : 50MB"); *max_file_size = MAX_FILE_SIZE; _INNER_FUNC_EXIT; return DM_OK; } /*value when this is file existed */ err = sync_agent_read_whole_file(MAX_DELTA_FILE_SIZE, &required_contents, &size_return); if (err == 1) { _DEBUG_VERBOSE("max file size : %s", required_contents); err = chartoint(required_contents, max_file_size); if (err == 1) { str_free(&required_contents); _INNER_FUNC_EXIT; return DM_OK; } else { _DEBUG_VERBOSE("get max file size error"); _INNER_FUNC_EXIT; return COMMON_ERR_IS_NULL; } } else { _DEBUG_VERBOSE("get max file size error"); _INNER_FUNC_EXIT; return COMMON_ERR_IS_NULL; } _DEBUG_VERBOSE("get max file size error"); _INNER_FUNC_EXIT; return COMMON_ERR_IS_NULL; } static DM_ERROR __check_max_file_size(int file_size) { _INNER_FUNC_ENTER; DM_ERROR ret = DM_OK; int noti_res = 0; int max_file_size = 0; ret = ___get_max_file_size(&max_file_size); if (ret != DM_OK) { _DEBUG_VERBOSE("get max file size error"); ret = DM_WIFI_ONLY_ERROR; goto error; } _DEBUG_VERBOSE("file size = %d, max file size = %d", file_size, max_file_size); /*max_file_size = 0 (0 in file or not existed file) * - can't use this option * - this option is max file size define in file when 3g mode */ if (max_file_size != 0 && file_size > max_file_size) { noti_res = noti_over_max_file_size(); _DEBUG_VERBOSE("noti over max file size : %d", noti_res); _DEBUG_VERBOSE("can't save current_size on 3g mode"); ret = DM_WIFI_ONLY_ERROR; goto error; } else { _DEBUG_VERBOSE("save current size on 3g mode"); } _INNER_FUNC_EXIT; return ret; error: _DEBUG_INFO("end error : %d", ret); _INNER_FUNC_EXIT; return ret; }