/* * Copyright (C) 2014 MediaTek Inc. * Modification based on code covered by the mentioned copyright * and/or permission notice(s). */ #include #include #include #include #include #include #include #include "mt_recovery.h" #include "mt_partition.h" #include "install.h" /* (MUST SYNC) Android default variables from recovery.cpp */ static const char *MT_UPDATE_STAGE_FILE = "/cache/recovery/last_mtupdate_stage"; const char *MOTA_RESULT_FILE = "/data/data/com.mediatek.systemupdate/files/updateResult"; static const char *mdconfig = "md1_ccb_cap_gear"; static const char *new_value = ""; extern "C" {int sysenv_set_in_user(const char* name, const char* value, int area);} bool remove_mota_file(const char *file_name) { int ret = 0; //LOG_INFO("[%s] %s\n", __func__, file_name); ret = unlink(file_name); if (ret == 0) { return true; } if (ret < 0 && errno == ENOENT) { return true; } return false; } void write_result_file(const char *file_name, int result) { if (INSTALL_SUCCESS == result) { set_ota_result(1); } else { set_ota_result(0); } } void mt_reset_mtupdate_stage(void) { if ((unlink(MT_UPDATE_STAGE_FILE) < 0) && (errno != ENOENT)) printf("unlink %s failed: %s\n", MT_UPDATE_STAGE_FILE, strerror(errno)); } int mt_main_write_result(int &status, const char *update_package) { if (update_package) { if ((status == INSTALL_SUCCESS) && update_package) { fprintf(stdout, "write result : remove_mota_file\n"); remove_mota_file(update_package); } write_result_file(MOTA_RESULT_FILE, status); } return 0; } bool mt_wipe_data(void) { bool success = false; // Erase md config in lk_env if (!sysenv_set_in_user(mdconfig, new_value, 0)) success = true; else success = false; printf("mt_wipe_data %s.\n", success ? "complete" : "failed"); return success; }