From f9d96368a7a56ea2e53bc2fdede538f793c43e53 Mon Sep 17 00:00:00 2001 From: Rayllll Date: Tue, 7 Jan 2025 22:49:41 +0800 Subject: [PATCH 01/14] Signed-off-by: Rayllll notify update --- bundle.json | 3 +- interfaces/kits/updaterkits/updaterkits.cpp | 38 ++++++++++++- services/include/updater/updater.h | 8 +++ services/main.cpp | 7 +++ services/updater_main.cpp | 59 ++++++++++++++++++--- services/updater_main.h | 1 + services/updater_ui.cpp | 10 ++-- updater_default_cfg.gni | 1 + utils/BUILD.gn | 5 +- utils/write_updater.cpp | 30 +++++++++++ 10 files changed, 145 insertions(+), 17 deletions(-) diff --git a/bundle.json b/bundle.json index ff01e2df..44fa70af 100644 --- a/bundle.json +++ b/bundle.json @@ -40,7 +40,8 @@ "syscap": [], "features": [ "updater_ui_support", - "updater_cfg_file" + "updater_cfg_file", + "updater_dcc_support" ], "adapted_system_type": [ "standard" ], "rom": "", diff --git a/interfaces/kits/updaterkits/updaterkits.cpp b/interfaces/kits/updaterkits/updaterkits.cpp index cefbd0e5..e4f13e48 100755 --- a/interfaces/kits/updaterkits/updaterkits.cpp +++ b/interfaces/kits/updaterkits/updaterkits.cpp @@ -14,6 +14,7 @@ */ #include "updaterkits/updaterkits.h" +#include #include #include #include @@ -28,6 +29,36 @@ using namespace Updater; using Updater::Utils::SplitString; +constexpr const char *HANDLE_MISC_LIB = "libupdater_handle_misc.z.so"; +constexpr const char *HANDLE_MISC_INFO = "HandleUpdateMiscInfo"; +constexpr const char *HANDLE_MISC_LIB_PATH = "/system/lib64/libupdater_handle_misc.z.so"; + +static void Handledlopen(const struct UpdateMessage &updateMsg, const std::string &upgradeType) +{ + if (!Utils::IsFileExist(HANDLE_MISC_LIB_PATH)) { + LOG(WARNING) << "libupdater_handle_misc.z.so is not exist"; + return; + } + auto handleMiscLib = dlopen(HANDLE_MISC_LIB, RTLD_LAZY); + if (handleMiscLib == nullptr) { + LOG(ERROR) << "dlopen libupdater_handle_misc fail"; + return; + } + auto getFunc = + (bool(*)(const struct UpdateMessage &, const std::string &))dlsym(handleMiscLib, HANDLE_MISC_INFO); + if (getFunc == nullptr) { + LOG(ERROR) << "getFunc is nullptr"; + dlclose(handleMiscLib); + return; + } + bool ret = getFunc(updateMsg, upgradeType); + dlclose(handleMiscLib); + handleMiscLib = nullptr; + if (!ret) { + LOG(ERROR) << "handle misc info fail"; + } +} + static bool WriteToMiscAndRebootToUpdater(const struct UpdateMessage &updateMsg) { // Write package name to misc, then trigger reboot. @@ -38,6 +69,7 @@ static bool WriteToMiscAndRebootToUpdater(const struct UpdateMessage &updateMsg) return false; } #ifndef UPDATER_UT + Handledlopen(updateMsg, ""); WriteUpdaterMiscMsg(updateMsg); DoReboot("updater:reboot to updater to trigger update"); while (true) { @@ -96,7 +128,8 @@ static std::string ParsePkgPath(const struct UpdateMessage &updateMsg) return pkgPath; } -static bool WriteToMiscAndResultFileRebootToUpdater(const struct UpdateMessage &updateMsg) +static bool WriteToMiscAndResultFileRebootToUpdater(const struct UpdateMessage &updateMsg, + const std::string &upgradeType) { // Write package name to misc, then trigger reboot. const char *bootCmd = "boot_updater"; @@ -110,6 +143,7 @@ static bool WriteToMiscAndResultFileRebootToUpdater(const struct UpdateMessage & std::string writeMiscBefore = "0x80000000"; WriteUpdaterResultFile(pkgPath, writeMiscBefore); #ifndef UPDATER_UT + Handledlopen(updateMsg, upgradeType); WriteUpdaterMiscMsg(updateMsg); // Flag after the misc in written std::string writeMiscAfter = "0x80000008"; @@ -211,7 +245,7 @@ int RebootAndInstallUpgradePackage(const std::string &miscFile, const std::vecto return addRet; } if (upgradeType == UPGRADE_TYPE_OTA) { - WriteToMiscAndResultFileRebootToUpdater(updateMsg); + WriteToMiscAndResultFileRebootToUpdater(updateMsg, upgradeType); } else { WriteToMiscAndRebootToUpdater(updateMsg); } diff --git a/services/include/updater/updater.h b/services/include/updater/updater.h index a0e3a915..057b3264 100644 --- a/services/include/updater/updater.h +++ b/services/include/updater/updater.h @@ -41,6 +41,14 @@ enum PackageUpdateMode { UNKNOWN_UPDATE, }; +enum NotifyAction { + SEND_PACKAGE = 0, + SET_INSTALL_STATUS, + GET_INSTALL_STATUS, + SET_UPDATE_STATUS, + GET_UPDATE_STATUS +} + struct UpdaterParams { bool forceUpdate = false; bool forceReboot = false; diff --git a/services/main.cpp b/services/main.cpp index 055a3098..d053ab7d 100644 --- a/services/main.cpp +++ b/services/main.cpp @@ -22,6 +22,11 @@ using namespace Updater; +__attribute__((weak)) void CheckConnect() +{ + return; +} + int main(int argc, char **argv) { // prepare modes vector by macro DEFINE_MODE which subscribe UPDATER_MAIN_PRE_EVENT event @@ -33,6 +38,8 @@ int main(int argc, char **argv) LOG(WARNING) << "read misc message failed"; } + CheckConnect(); + // select modes by bootMode.cond which would check misc message auto bootMode = SelectMode(boot).value_or(BOOT_MODE(Updater, "updater.hdc.configfs")); diff --git a/services/updater_main.cpp b/services/updater_main.cpp index 4e3f573a..04a8cad6 100644 --- a/services/updater_main.cpp +++ b/services/updater_main.cpp @@ -168,6 +168,18 @@ __attribute__((weak)) void UpdaterVerifyFailEntry(bool verifyret) return; } +__attribute__((weak)) UpdaterStatus NotifyActionResult(UpdaterParams &upParams, + UpdaterStatus &status, NotifyAction notifyAction) +{ + return UPDATE_SUCCESS; +} + +__attribute__((weak)) void NotifyReboot(const std::string& rebootTarget, + const std::string &rebootReason, const std::string &extData) +{ + Updater::Utils::UpdaterDoReboot(rebootTarget, rebootReason, extData); +} + static UpdaterStatus VerifyPackages(UpdaterParams &upParams) { UPDATER_INIT_RECORD; @@ -378,6 +390,28 @@ static int CheckMountData() return UPDATE_ERROR; } +static UpdaterStatus CheckVerifyPackages(UpdaterParams &upParams) +{ + // verify packages first + UpdaterStatus status = VerifyPackages(upParams); + if (NotifyActionResult(upParams, status, SET_INSTALL_STATUS) != UPDATE_SUCCESS) { + LOG(ERROR) << "set status fail"; + return UPDATE_CORRUPT; + } + if (status != UPDATE_SUCCESS) { + return UPDATE_CORRUPT; + } + if (NotifyActionResult(upParams, status, SEND_PACKAGE) != UPDATE_SUCCESS) { + LOG(ERROR) << "send package fail"; + return UPDATE_CORRUPT; + } + if (NotifyActionResult(upParams, status, GET_INSTALL_STATUS) != UPDATE_SUCCESS) { + LOG(ERROR) << "get status fail"; + return UPDATE_CORRUPT; + } + return UPDATE_SUCCESS; +} + static UpdaterStatus PreUpdatePackages(UpdaterParams &upParams) { UPDATER_INIT_RECORD; @@ -400,9 +434,9 @@ static UpdaterStatus PreUpdatePackages(UpdaterParams &upParams) return UPDATE_SUCCESS; } - // verify packages first - if (VerifyPackages(upParams) != UPDATE_SUCCESS) { - return UPDATE_CORRUPT; // verify package failed must return UPDATE_CORRUPT, ux need it !!! + if (CheckVerifyPackages(upParams) != UPDATE_SUCCESS) { + LOG(ERROR) << "verify packages fail"; + return UPDATE_CORRUPT; } // Only handle UPATE_ERROR and UPDATE_SUCCESS here.Let package verify handle others. @@ -496,6 +530,10 @@ UpdaterStatus DoUpdatePackages(UpdaterParams &upParams) UPDATER_UI_INSTANCE.GetCurrentPercent() : (updateStartPosition * FULL_PERCENT_PROGRESS); upParams.callbackProgress(value); status = DoInstallPackages(upParams, pkgStartPosition); + if (NotifyAction(upParams, status, SET_UPDATE_STATUS) != UPDATE_SUCCESS) { + LOG(ERROR) << "set status fail"; + return UPDATE_CORRUPT; + } if (status != UPDATE_SUCCESS) { UPDATER_LAST_WORD(status, "DoInstallPackages failed"); return status; @@ -503,6 +541,10 @@ UpdaterStatus DoUpdatePackages(UpdaterParams &upParams) if (upParams.forceUpdate) { UPDATER_UI_INSTANCE.ShowLogRes(TR(LABEL_UPD_OK_SHUTDOWN)); } + if (NotifyAction(upParams, status, GET_UPDATE_STATUS) != UPDATE_SUCCESS) { + LOG(ERROR) << "get status fail"; + return UPDATE_CORRUPT; + } UPDATER_UI_INSTANCE.ShowSuccessPage(); return status; } @@ -556,8 +598,9 @@ static UpdaterStatus PreSdcardUpdatePackages(UpdaterParams &upParams) return UPDATE_SKIP; } - if (VerifyPackages(upParams) != UPDATE_SUCCESS) { - return UPDATE_CORRUPT; // verify package failed must return UPDATE_CORRUPT, ux need it !!! + if (CheckVerifyPackages(upParams) != UPDATE_SUCCESS) { + LOG(ERROR) << "verify packages fail"; + return UPDATE_CORRUPT; } #ifdef UPDATER_USE_PTABLE if (!PtablePreProcess::GetInstance().DoPtableProcess(upParams)) { @@ -844,7 +887,7 @@ void RebootAfterUpdateSuccess(const UpdaterParams &upParams) if (IsNeedWipe() || upParams.sdExtMode == SDCARD_UPDATE_FROM_DEV || upParams.sdExtMode == SDCARD_UPDATE_FROM_DATA) { - Utils::UpdaterDoReboot("updater", "Updater wipe data after upgrade success", "--user_wipe_data"); + NotifyReboot("updater", "Updater wipe data after upgrade success", "--user_wipe_data"); return; } if (upParams.factoryResetMode == "factory_wipe_data") { @@ -855,7 +898,7 @@ void RebootAfterUpdateSuccess(const UpdaterParams &upParams) upParams.forceUpdate || upParams.factoryResetMode == "factory_wipe_data" || upParams.factoryResetMode == "menu_wipe_data" ? Utils::DoShutdown("Updater update success go shut down") : - Utils::UpdaterDoReboot("", "Updater update success"); + NotifyReboot("", "Updater update success"); } int UpdaterMain(int argc, char **argv) @@ -882,7 +925,7 @@ int UpdaterMain(int argc, char **argv) if (upParams.forceReboot) { Utils::UsSleep(5 * DISPLAY_TIME); // 5 : 5s PostUpdater(true); - Utils::UpdaterDoReboot("", "Updater night update fail"); + NotifyReboot("", "Updater night update fail"); return 0; } } else if (mode == SDCARD_UPDATE) { diff --git a/services/updater_main.h b/services/updater_main.h index 699df7ee..ccf74b1c 100644 --- a/services/updater_main.h +++ b/services/updater_main.h @@ -70,6 +70,7 @@ int32_t VerifySpecialPkgs([[maybe_unused]]UpdaterParams &upParams); void UpdaterVerifyFailEntry(bool verifyret); bool IsSpareBoardBoot(void); bool IsNeedWipe(); +void NotifyReboot(const std::string& rebootTarget, const std::string &rebootReason, const std::string &extData = ""); #ifdef __cplusplus #if __cplusplus } diff --git a/services/updater_ui.cpp b/services/updater_ui.cpp index 44fe7c85..2419da8a 100644 --- a/services/updater_ui.cpp +++ b/services/updater_ui.cpp @@ -70,7 +70,7 @@ DEFINE_ASYN_CALLBACK(OnRebootEvt) LOG(INFO) << "On Label Reboot"; GraphicEngine::GetInstance().StopEngine(); PostUpdater(false); - Utils::UpdaterDoReboot("", "Updater reboot btn event"); + NotifyReboot("", "Updater reboot btn event"); } DEFINE_SYNC_CALLBACK(OnLabelResetEvt) @@ -100,7 +100,7 @@ DEFINE_ASYN_CALLBACK(OnLabelSDCardEvt) return; } PostUpdater(true); - Utils::UpdaterDoReboot("", "Updater sdcard update success reboot"); + NotifyReboot("", "Updater sdcard update success reboot"); } DEFINE_ASYN_CALLBACK(OnLabelSDCardNoDelayEvt) @@ -123,7 +123,7 @@ DEFINE_ASYN_CALLBACK(OnLabelSDCardNoDelayEvt) GetFacade().ShowSuccessPage(); Utils::UsSleep(SUCCESS_DELAY); PostUpdater(true); - Utils::UpdaterDoReboot("", "Updater sdcard update success reboot"); + NotifyReboot("", "Updater sdcard update success reboot"); } DEFINE_ASYN_CALLBACK(OnLabelSDUpdateResEvt) @@ -153,7 +153,7 @@ DEFINE_ASYN_CALLBACK(OnLabelSDUpdateResEvt) GetFacade().ShowSuccessPage(); Utils::UsSleep(SUCCESS_DELAY); PostUpdater(true); - Utils::UpdaterDoReboot("", "Updater sdcard update success reboot"); + NotifyReboot("", "Updater sdcard update success reboot"); } DEFINE_SYNC_CALLBACK(OnLabelCancelEvt) @@ -208,7 +208,7 @@ DEFINE_ASYN_CALLBACK(OnConfirmRstEvt) GetFacade().ShowSuccessPage(); PostUpdater(true); Utils::UsSleep(SUCCESS_DELAY); - Utils::UpdaterDoReboot("", "Updater factory reset success"); + NotifyReboot("", "Updater factory reset success"); } } diff --git a/updater_default_cfg.gni b/updater_default_cfg.gni index 4f84e9f2..99a241be 100644 --- a/updater_default_cfg.gni +++ b/updater_default_cfg.gni @@ -21,6 +21,7 @@ declare_args() { updater_ui_support = false } updater_hdc_depend = true + updater_dcc_support = false updater_absolutely_path = "//base/update/updater" hdc_base = "//developtools/hdc" updater_sign_on_server = false diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 50511168..bc62b46c 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -137,7 +137,10 @@ ohos_executable("write_updater") { "${updater_path}/services/include/", ] - deps = [ "${updater_path}/interfaces/kits/misc_info:libmiscinfo" ] + deps = [ + "${updater_path}/interfaces/kits/misc_info:libmiscinfo", + "${updater_path}/utils:libutils" + ] external_deps = [ "bounds_checking_function:libsec_static", "init:libbegetutil_static", diff --git a/utils/write_updater.cpp b/utils/write_updater.cpp index c5703b1a..426a7e79 100644 --- a/utils/write_updater.cpp +++ b/utils/write_updater.cpp @@ -12,16 +12,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include #include "fs_manager/mount.h" #include "misc_info/misc_info.h" #include "securec.h" #include "updater/updater_const.h" #include "parameter.h" +#include "utils.h" +#include "utils_fs.h" using namespace std; using namespace Updater; +constexpr const char *HANDLE_MISC_LIB = "libupdater_handle_misc.z.so"; +constexpr const char *NOTIFY_MISC_INFO = "NotifyWriteMiscInfo"; +constexpr const char *HANDLE_MISC_LIB_PATH = "/system/lib64/libupdater_handle_misc.z.so"; + static void PrintPrompts() { cout << "Please input correct command, examples :" << endl; @@ -66,6 +73,28 @@ static int WriteUpdaterPara(int argc, UpdaterPara ¶) return 0; } +static void HandleMiscInfo(int argc, char **argv) +{ + if (!Utils::IsFileExist(HANDLE_MISC_LIB_PATH)) { + cout << "libupdater_handle_misc.z.so is not exist"; + return; + } + auto handleMiscLib = dlopen(HANDLE_MISC_LIB, RTLD_LAZY); + if (handleMiscLib == nullptr) { + cout << "dlopen libupdater_handle_misc fail"; + return; + } + auto getFunc = (bool(*)(int argc, char **argv))dlsym(handleMiscLib, NOTIFY_MISC_INFO); + if (getFunc == nullptr) { + cout << "getFunc is nullptr"; + dlclose(handleMiscLib); + return; + } + getFunc(updateMsg, upgradeType); + dlclose(handleMiscLib); + handleMiscLib = nullptr; +} + int main(int argc, char **argv) { if (argc == 1) { @@ -111,5 +140,6 @@ int main(int argc, char **argv) cout << "WriteUpdaterMessage failed!" << endl; return -1; } + HandleMiscInfo(argc, argv); return 0; } -- Gitee From 0d3de234a8046524550672b37c1e090ca62a35ee Mon Sep 17 00:00:00 2001 From: Rayllll Date: Tue, 7 Jan 2025 22:49:41 +0800 Subject: [PATCH 02/14] Signed-off-by: Rayllll notify update Signed-off-by: Rayllll --- bundle.json | 3 +- interfaces/kits/updaterkits/updaterkits.cpp | 38 ++++++++++++- services/include/updater/updater.h | 8 +++ services/main.cpp | 7 +++ services/updater_main.cpp | 59 ++++++++++++++++++--- services/updater_main.h | 1 + services/updater_ui.cpp | 11 ++-- updater_default_cfg.gni | 1 + utils/BUILD.gn | 5 +- utils/write_updater.cpp | 30 +++++++++++ 10 files changed, 146 insertions(+), 17 deletions(-) diff --git a/bundle.json b/bundle.json index ff01e2df..44fa70af 100644 --- a/bundle.json +++ b/bundle.json @@ -40,7 +40,8 @@ "syscap": [], "features": [ "updater_ui_support", - "updater_cfg_file" + "updater_cfg_file", + "updater_dcc_support" ], "adapted_system_type": [ "standard" ], "rom": "", diff --git a/interfaces/kits/updaterkits/updaterkits.cpp b/interfaces/kits/updaterkits/updaterkits.cpp index cefbd0e5..e4f13e48 100755 --- a/interfaces/kits/updaterkits/updaterkits.cpp +++ b/interfaces/kits/updaterkits/updaterkits.cpp @@ -14,6 +14,7 @@ */ #include "updaterkits/updaterkits.h" +#include #include #include #include @@ -28,6 +29,36 @@ using namespace Updater; using Updater::Utils::SplitString; +constexpr const char *HANDLE_MISC_LIB = "libupdater_handle_misc.z.so"; +constexpr const char *HANDLE_MISC_INFO = "HandleUpdateMiscInfo"; +constexpr const char *HANDLE_MISC_LIB_PATH = "/system/lib64/libupdater_handle_misc.z.so"; + +static void Handledlopen(const struct UpdateMessage &updateMsg, const std::string &upgradeType) +{ + if (!Utils::IsFileExist(HANDLE_MISC_LIB_PATH)) { + LOG(WARNING) << "libupdater_handle_misc.z.so is not exist"; + return; + } + auto handleMiscLib = dlopen(HANDLE_MISC_LIB, RTLD_LAZY); + if (handleMiscLib == nullptr) { + LOG(ERROR) << "dlopen libupdater_handle_misc fail"; + return; + } + auto getFunc = + (bool(*)(const struct UpdateMessage &, const std::string &))dlsym(handleMiscLib, HANDLE_MISC_INFO); + if (getFunc == nullptr) { + LOG(ERROR) << "getFunc is nullptr"; + dlclose(handleMiscLib); + return; + } + bool ret = getFunc(updateMsg, upgradeType); + dlclose(handleMiscLib); + handleMiscLib = nullptr; + if (!ret) { + LOG(ERROR) << "handle misc info fail"; + } +} + static bool WriteToMiscAndRebootToUpdater(const struct UpdateMessage &updateMsg) { // Write package name to misc, then trigger reboot. @@ -38,6 +69,7 @@ static bool WriteToMiscAndRebootToUpdater(const struct UpdateMessage &updateMsg) return false; } #ifndef UPDATER_UT + Handledlopen(updateMsg, ""); WriteUpdaterMiscMsg(updateMsg); DoReboot("updater:reboot to updater to trigger update"); while (true) { @@ -96,7 +128,8 @@ static std::string ParsePkgPath(const struct UpdateMessage &updateMsg) return pkgPath; } -static bool WriteToMiscAndResultFileRebootToUpdater(const struct UpdateMessage &updateMsg) +static bool WriteToMiscAndResultFileRebootToUpdater(const struct UpdateMessage &updateMsg, + const std::string &upgradeType) { // Write package name to misc, then trigger reboot. const char *bootCmd = "boot_updater"; @@ -110,6 +143,7 @@ static bool WriteToMiscAndResultFileRebootToUpdater(const struct UpdateMessage & std::string writeMiscBefore = "0x80000000"; WriteUpdaterResultFile(pkgPath, writeMiscBefore); #ifndef UPDATER_UT + Handledlopen(updateMsg, upgradeType); WriteUpdaterMiscMsg(updateMsg); // Flag after the misc in written std::string writeMiscAfter = "0x80000008"; @@ -211,7 +245,7 @@ int RebootAndInstallUpgradePackage(const std::string &miscFile, const std::vecto return addRet; } if (upgradeType == UPGRADE_TYPE_OTA) { - WriteToMiscAndResultFileRebootToUpdater(updateMsg); + WriteToMiscAndResultFileRebootToUpdater(updateMsg, upgradeType); } else { WriteToMiscAndRebootToUpdater(updateMsg); } diff --git a/services/include/updater/updater.h b/services/include/updater/updater.h index a0e3a915..057b3264 100644 --- a/services/include/updater/updater.h +++ b/services/include/updater/updater.h @@ -41,6 +41,14 @@ enum PackageUpdateMode { UNKNOWN_UPDATE, }; +enum NotifyAction { + SEND_PACKAGE = 0, + SET_INSTALL_STATUS, + GET_INSTALL_STATUS, + SET_UPDATE_STATUS, + GET_UPDATE_STATUS +} + struct UpdaterParams { bool forceUpdate = false; bool forceReboot = false; diff --git a/services/main.cpp b/services/main.cpp index 055a3098..d053ab7d 100644 --- a/services/main.cpp +++ b/services/main.cpp @@ -22,6 +22,11 @@ using namespace Updater; +__attribute__((weak)) void CheckConnect() +{ + return; +} + int main(int argc, char **argv) { // prepare modes vector by macro DEFINE_MODE which subscribe UPDATER_MAIN_PRE_EVENT event @@ -33,6 +38,8 @@ int main(int argc, char **argv) LOG(WARNING) << "read misc message failed"; } + CheckConnect(); + // select modes by bootMode.cond which would check misc message auto bootMode = SelectMode(boot).value_or(BOOT_MODE(Updater, "updater.hdc.configfs")); diff --git a/services/updater_main.cpp b/services/updater_main.cpp index 4e3f573a..e62ac0a4 100644 --- a/services/updater_main.cpp +++ b/services/updater_main.cpp @@ -168,6 +168,18 @@ __attribute__((weak)) void UpdaterVerifyFailEntry(bool verifyret) return; } +__attribute__((weak)) UpdaterStatus NotifyActionResult(UpdaterParams &upParams, + UpdaterStatus &status, NotifyAction notifyAction) +{ + return UPDATE_SUCCESS; +} + +__attribute__((weak)) void NotifyReboot(const std::string& rebootTarget, + const std::string &rebootReason, const std::string &extData) +{ + Updater::Utils::UpdaterDoReboot(rebootTarget, rebootReason, extData); +} + static UpdaterStatus VerifyPackages(UpdaterParams &upParams) { UPDATER_INIT_RECORD; @@ -378,6 +390,28 @@ static int CheckMountData() return UPDATE_ERROR; } +static UpdaterStatus CheckVerifyPackages(UpdaterParams &upParams) +{ + // verify packages first + UpdaterStatus status = VerifyPackages(upParams); + if (NotifyActionResult(upParams, status, SET_INSTALL_STATUS) != UPDATE_SUCCESS) { + LOG(ERROR) << "set status fail"; + return UPDATE_CORRUPT; + } + if (status != UPDATE_SUCCESS) { + return UPDATE_CORRUPT; + } + if (NotifyActionResult(upParams, status, SEND_PACKAGE) != UPDATE_SUCCESS) { + LOG(ERROR) << "send package fail"; + return UPDATE_CORRUPT; + } + if (NotifyActionResult(upParams, status, GET_INSTALL_STATUS) != UPDATE_SUCCESS) { + LOG(ERROR) << "get status fail"; + return UPDATE_CORRUPT; + } + return UPDATE_SUCCESS; +} + static UpdaterStatus PreUpdatePackages(UpdaterParams &upParams) { UPDATER_INIT_RECORD; @@ -400,9 +434,9 @@ static UpdaterStatus PreUpdatePackages(UpdaterParams &upParams) return UPDATE_SUCCESS; } - // verify packages first - if (VerifyPackages(upParams) != UPDATE_SUCCESS) { - return UPDATE_CORRUPT; // verify package failed must return UPDATE_CORRUPT, ux need it !!! + if (CheckVerifyPackages(upParams) != UPDATE_SUCCESS) { + LOG(ERROR) << "verify packages fail"; + return UPDATE_CORRUPT; } // Only handle UPATE_ERROR and UPDATE_SUCCESS here.Let package verify handle others. @@ -496,6 +530,10 @@ UpdaterStatus DoUpdatePackages(UpdaterParams &upParams) UPDATER_UI_INSTANCE.GetCurrentPercent() : (updateStartPosition * FULL_PERCENT_PROGRESS); upParams.callbackProgress(value); status = DoInstallPackages(upParams, pkgStartPosition); + if (NotifyActionResult(upParams, status, SET_UPDATE_STATUS) != UPDATE_SUCCESS) { + LOG(ERROR) << "set status fail"; + return UPDATE_CORRUPT; + } if (status != UPDATE_SUCCESS) { UPDATER_LAST_WORD(status, "DoInstallPackages failed"); return status; @@ -503,6 +541,10 @@ UpdaterStatus DoUpdatePackages(UpdaterParams &upParams) if (upParams.forceUpdate) { UPDATER_UI_INSTANCE.ShowLogRes(TR(LABEL_UPD_OK_SHUTDOWN)); } + if (NotifyActionResult(upParams, status, GET_UPDATE_STATUS) != UPDATE_SUCCESS) { + LOG(ERROR) << "get status fail"; + return UPDATE_CORRUPT; + } UPDATER_UI_INSTANCE.ShowSuccessPage(); return status; } @@ -556,8 +598,9 @@ static UpdaterStatus PreSdcardUpdatePackages(UpdaterParams &upParams) return UPDATE_SKIP; } - if (VerifyPackages(upParams) != UPDATE_SUCCESS) { - return UPDATE_CORRUPT; // verify package failed must return UPDATE_CORRUPT, ux need it !!! + if (CheckVerifyPackages(upParams) != UPDATE_SUCCESS) { + LOG(ERROR) << "verify packages fail"; + return UPDATE_CORRUPT; } #ifdef UPDATER_USE_PTABLE if (!PtablePreProcess::GetInstance().DoPtableProcess(upParams)) { @@ -844,7 +887,7 @@ void RebootAfterUpdateSuccess(const UpdaterParams &upParams) if (IsNeedWipe() || upParams.sdExtMode == SDCARD_UPDATE_FROM_DEV || upParams.sdExtMode == SDCARD_UPDATE_FROM_DATA) { - Utils::UpdaterDoReboot("updater", "Updater wipe data after upgrade success", "--user_wipe_data"); + NotifyReboot("updater", "Updater wipe data after upgrade success", "--user_wipe_data"); return; } if (upParams.factoryResetMode == "factory_wipe_data") { @@ -855,7 +898,7 @@ void RebootAfterUpdateSuccess(const UpdaterParams &upParams) upParams.forceUpdate || upParams.factoryResetMode == "factory_wipe_data" || upParams.factoryResetMode == "menu_wipe_data" ? Utils::DoShutdown("Updater update success go shut down") : - Utils::UpdaterDoReboot("", "Updater update success"); + NotifyReboot("", "Updater update success"); } int UpdaterMain(int argc, char **argv) @@ -882,7 +925,7 @@ int UpdaterMain(int argc, char **argv) if (upParams.forceReboot) { Utils::UsSleep(5 * DISPLAY_TIME); // 5 : 5s PostUpdater(true); - Utils::UpdaterDoReboot("", "Updater night update fail"); + NotifyReboot("", "Updater night update fail"); return 0; } } else if (mode == SDCARD_UPDATE) { diff --git a/services/updater_main.h b/services/updater_main.h index 699df7ee..ccf74b1c 100644 --- a/services/updater_main.h +++ b/services/updater_main.h @@ -70,6 +70,7 @@ int32_t VerifySpecialPkgs([[maybe_unused]]UpdaterParams &upParams); void UpdaterVerifyFailEntry(bool verifyret); bool IsSpareBoardBoot(void); bool IsNeedWipe(); +void NotifyReboot(const std::string& rebootTarget, const std::string &rebootReason, const std::string &extData = ""); #ifdef __cplusplus #if __cplusplus } diff --git a/services/updater_ui.cpp b/services/updater_ui.cpp index 44fe7c85..ce20ea0e 100644 --- a/services/updater_ui.cpp +++ b/services/updater_ui.cpp @@ -26,6 +26,7 @@ #include "updater/updater_const.h" #include "utils.h" #include "updater_ui_stub.h" +#include "updater_main.h" namespace Updater { namespace { @@ -70,7 +71,7 @@ DEFINE_ASYN_CALLBACK(OnRebootEvt) LOG(INFO) << "On Label Reboot"; GraphicEngine::GetInstance().StopEngine(); PostUpdater(false); - Utils::UpdaterDoReboot("", "Updater reboot btn event"); + NotifyReboot("", "Updater reboot btn event"); } DEFINE_SYNC_CALLBACK(OnLabelResetEvt) @@ -100,7 +101,7 @@ DEFINE_ASYN_CALLBACK(OnLabelSDCardEvt) return; } PostUpdater(true); - Utils::UpdaterDoReboot("", "Updater sdcard update success reboot"); + NotifyReboot("", "Updater sdcard update success reboot"); } DEFINE_ASYN_CALLBACK(OnLabelSDCardNoDelayEvt) @@ -123,7 +124,7 @@ DEFINE_ASYN_CALLBACK(OnLabelSDCardNoDelayEvt) GetFacade().ShowSuccessPage(); Utils::UsSleep(SUCCESS_DELAY); PostUpdater(true); - Utils::UpdaterDoReboot("", "Updater sdcard update success reboot"); + NotifyReboot("", "Updater sdcard update success reboot"); } DEFINE_ASYN_CALLBACK(OnLabelSDUpdateResEvt) @@ -153,7 +154,7 @@ DEFINE_ASYN_CALLBACK(OnLabelSDUpdateResEvt) GetFacade().ShowSuccessPage(); Utils::UsSleep(SUCCESS_DELAY); PostUpdater(true); - Utils::UpdaterDoReboot("", "Updater sdcard update success reboot"); + NotifyReboot("", "Updater sdcard update success reboot"); } DEFINE_SYNC_CALLBACK(OnLabelCancelEvt) @@ -208,7 +209,7 @@ DEFINE_ASYN_CALLBACK(OnConfirmRstEvt) GetFacade().ShowSuccessPage(); PostUpdater(true); Utils::UsSleep(SUCCESS_DELAY); - Utils::UpdaterDoReboot("", "Updater factory reset success"); + NotifyReboot("", "Updater factory reset success"); } } diff --git a/updater_default_cfg.gni b/updater_default_cfg.gni index 4f84e9f2..99a241be 100644 --- a/updater_default_cfg.gni +++ b/updater_default_cfg.gni @@ -21,6 +21,7 @@ declare_args() { updater_ui_support = false } updater_hdc_depend = true + updater_dcc_support = false updater_absolutely_path = "//base/update/updater" hdc_base = "//developtools/hdc" updater_sign_on_server = false diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 50511168..bc62b46c 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -137,7 +137,10 @@ ohos_executable("write_updater") { "${updater_path}/services/include/", ] - deps = [ "${updater_path}/interfaces/kits/misc_info:libmiscinfo" ] + deps = [ + "${updater_path}/interfaces/kits/misc_info:libmiscinfo", + "${updater_path}/utils:libutils" + ] external_deps = [ "bounds_checking_function:libsec_static", "init:libbegetutil_static", diff --git a/utils/write_updater.cpp b/utils/write_updater.cpp index c5703b1a..426a7e79 100644 --- a/utils/write_updater.cpp +++ b/utils/write_updater.cpp @@ -12,16 +12,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include #include "fs_manager/mount.h" #include "misc_info/misc_info.h" #include "securec.h" #include "updater/updater_const.h" #include "parameter.h" +#include "utils.h" +#include "utils_fs.h" using namespace std; using namespace Updater; +constexpr const char *HANDLE_MISC_LIB = "libupdater_handle_misc.z.so"; +constexpr const char *NOTIFY_MISC_INFO = "NotifyWriteMiscInfo"; +constexpr const char *HANDLE_MISC_LIB_PATH = "/system/lib64/libupdater_handle_misc.z.so"; + static void PrintPrompts() { cout << "Please input correct command, examples :" << endl; @@ -66,6 +73,28 @@ static int WriteUpdaterPara(int argc, UpdaterPara ¶) return 0; } +static void HandleMiscInfo(int argc, char **argv) +{ + if (!Utils::IsFileExist(HANDLE_MISC_LIB_PATH)) { + cout << "libupdater_handle_misc.z.so is not exist"; + return; + } + auto handleMiscLib = dlopen(HANDLE_MISC_LIB, RTLD_LAZY); + if (handleMiscLib == nullptr) { + cout << "dlopen libupdater_handle_misc fail"; + return; + } + auto getFunc = (bool(*)(int argc, char **argv))dlsym(handleMiscLib, NOTIFY_MISC_INFO); + if (getFunc == nullptr) { + cout << "getFunc is nullptr"; + dlclose(handleMiscLib); + return; + } + getFunc(updateMsg, upgradeType); + dlclose(handleMiscLib); + handleMiscLib = nullptr; +} + int main(int argc, char **argv) { if (argc == 1) { @@ -111,5 +140,6 @@ int main(int argc, char **argv) cout << "WriteUpdaterMessage failed!" << endl; return -1; } + HandleMiscInfo(argc, argv); return 0; } -- Gitee From 44250e74c999d9281b2763fdea533fbdc5c938eb Mon Sep 17 00:00:00 2001 From: Rayllll Date: Wed, 8 Jan 2025 01:44:42 +0000 Subject: [PATCH 03/14] update utils/write_updater.cpp. Signed-off-by: Rayllll --- utils/write_updater.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/write_updater.cpp b/utils/write_updater.cpp index 426a7e79..ec50852b 100644 --- a/utils/write_updater.cpp +++ b/utils/write_updater.cpp @@ -84,13 +84,13 @@ static void HandleMiscInfo(int argc, char **argv) cout << "dlopen libupdater_handle_misc fail"; return; } - auto getFunc = (bool(*)(int argc, char **argv))dlsym(handleMiscLib, NOTIFY_MISC_INFO); + auto getFunc = (bool(*)(int, char **))dlsym(handleMiscLib, NOTIFY_MISC_INFO); if (getFunc == nullptr) { cout << "getFunc is nullptr"; dlclose(handleMiscLib); return; } - getFunc(updateMsg, upgradeType); + getFunc(argc, argv); dlclose(handleMiscLib); handleMiscLib = nullptr; } -- Gitee From 9100f98eed4d51e8adb05c8a1f7b05fdae7215da Mon Sep 17 00:00:00 2001 From: Rayllll Date: Wed, 8 Jan 2025 02:20:18 +0000 Subject: [PATCH 04/14] update utils/BUILD.gn. Signed-off-by: Rayllll --- utils/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/BUILD.gn b/utils/BUILD.gn index bc62b46c..119c908f 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -139,7 +139,7 @@ ohos_executable("write_updater") { deps = [ "${updater_path}/interfaces/kits/misc_info:libmiscinfo", - "${updater_path}/utils:libutils" + "${updater_path}/utils:libutils", ] external_deps = [ "bounds_checking_function:libsec_static", -- Gitee From b0f8ef39f44a0c94055dc42276d97c04bef2b433 Mon Sep 17 00:00:00 2001 From: Rayllll Date: Wed, 8 Jan 2025 03:33:56 +0000 Subject: [PATCH 05/14] update services/include/updater/updater.h. Signed-off-by: Rayllll --- services/include/updater/updater.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/include/updater/updater.h b/services/include/updater/updater.h index 057b3264..44e118a2 100644 --- a/services/include/updater/updater.h +++ b/services/include/updater/updater.h @@ -47,7 +47,7 @@ enum NotifyAction { GET_INSTALL_STATUS, SET_UPDATE_STATUS, GET_UPDATE_STATUS -} +}; struct UpdaterParams { bool forceUpdate = false; -- Gitee From cef8f42122e901a3e9762b34126f9441e418cbbe Mon Sep 17 00:00:00 2001 From: Rayllll Date: Wed, 8 Jan 2025 04:16:26 +0000 Subject: [PATCH 06/14] update interfaces/kits/updaterkits/updaterkits.cpp. Signed-off-by: Rayllll --- interfaces/kits/updaterkits/updaterkits.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/interfaces/kits/updaterkits/updaterkits.cpp b/interfaces/kits/updaterkits/updaterkits.cpp index e4f13e48..06e360f5 100755 --- a/interfaces/kits/updaterkits/updaterkits.cpp +++ b/interfaces/kits/updaterkits/updaterkits.cpp @@ -29,6 +29,7 @@ using namespace Updater; using Updater::Utils::SplitString; +#ifndef UPDATER_UT constexpr const char *HANDLE_MISC_LIB = "libupdater_handle_misc.z.so"; constexpr const char *HANDLE_MISC_INFO = "HandleUpdateMiscInfo"; constexpr const char *HANDLE_MISC_LIB_PATH = "/system/lib64/libupdater_handle_misc.z.so"; @@ -58,6 +59,7 @@ static void Handledlopen(const struct UpdateMessage &updateMsg, const std::strin LOG(ERROR) << "handle misc info fail"; } } +#endif static bool WriteToMiscAndRebootToUpdater(const struct UpdateMessage &updateMsg) { -- Gitee From 2ce3987f0068d474669e36e127f8030b40b762e2 Mon Sep 17 00:00:00 2001 From: Rayllll Date: Wed, 8 Jan 2025 07:40:07 +0000 Subject: [PATCH 07/14] update interfaces/kits/updaterkits/updaterkits.cpp. Signed-off-by: Rayllll --- interfaces/kits/updaterkits/updaterkits.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/kits/updaterkits/updaterkits.cpp b/interfaces/kits/updaterkits/updaterkits.cpp index 06e360f5..2da4cbdf 100755 --- a/interfaces/kits/updaterkits/updaterkits.cpp +++ b/interfaces/kits/updaterkits/updaterkits.cpp @@ -46,13 +46,13 @@ static void Handledlopen(const struct UpdateMessage &updateMsg, const std::strin return; } auto getFunc = - (bool(*)(const struct UpdateMessage &, const std::string &))dlsym(handleMiscLib, HANDLE_MISC_INFO); + (bool(*)(const std::string &, const std::string &))dlsym(handleMiscLib, HANDLE_MISC_INFO); if (getFunc == nullptr) { LOG(ERROR) << "getFunc is nullptr"; dlclose(handleMiscLib); return; } - bool ret = getFunc(updateMsg, upgradeType); + bool ret = getFunc(updateMsg.update, upgradeType); dlclose(handleMiscLib); handleMiscLib = nullptr; if (!ret) { -- Gitee From 99e5397c952cf24b6c91082e09cd689a3bd4983a Mon Sep 17 00:00:00 2001 From: Rayllll Date: Wed, 8 Jan 2025 12:49:20 +0000 Subject: [PATCH 08/14] update utils/write_updater.cpp. Signed-off-by: Rayllll --- utils/write_updater.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/write_updater.cpp b/utils/write_updater.cpp index ec50852b..ad3ca1d3 100644 --- a/utils/write_updater.cpp +++ b/utils/write_updater.cpp @@ -84,7 +84,7 @@ static void HandleMiscInfo(int argc, char **argv) cout << "dlopen libupdater_handle_misc fail"; return; } - auto getFunc = (bool(*)(int, char **))dlsym(handleMiscLib, NOTIFY_MISC_INFO); + auto getFunc = (void(*)(int, char **))dlsym(handleMiscLib, NOTIFY_MISC_INFO); if (getFunc == nullptr) { cout << "getFunc is nullptr"; dlclose(handleMiscLib); -- Gitee From e693e2afcf78c97385373959a85ecdfc4cc8d9aa Mon Sep 17 00:00:00 2001 From: Rayllll Date: Wed, 8 Jan 2025 12:53:26 +0000 Subject: [PATCH 09/14] update interfaces/kits/updaterkits/updaterkits.cpp. Signed-off-by: Rayllll --- interfaces/kits/updaterkits/updaterkits.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/interfaces/kits/updaterkits/updaterkits.cpp b/interfaces/kits/updaterkits/updaterkits.cpp index 2da4cbdf..9c1c364d 100755 --- a/interfaces/kits/updaterkits/updaterkits.cpp +++ b/interfaces/kits/updaterkits/updaterkits.cpp @@ -46,18 +46,15 @@ static void Handledlopen(const struct UpdateMessage &updateMsg, const std::strin return; } auto getFunc = - (bool(*)(const std::string &, const std::string &))dlsym(handleMiscLib, HANDLE_MISC_INFO); + (void(*)(const std::string &, const std::string &))dlsym(handleMiscLib, HANDLE_MISC_INFO); if (getFunc == nullptr) { LOG(ERROR) << "getFunc is nullptr"; dlclose(handleMiscLib); return; } - bool ret = getFunc(updateMsg.update, upgradeType); + getFunc(updateMsg.update, upgradeType); dlclose(handleMiscLib); handleMiscLib = nullptr; - if (!ret) { - LOG(ERROR) << "handle misc info fail"; - } } #endif -- Gitee From 1f1acacd87a6eda3c837f637756bba1de4c7b5e8 Mon Sep 17 00:00:00 2001 From: Rayllll Date: Wed, 8 Jan 2025 12:53:26 +0000 Subject: [PATCH 10/14] update interfaces/kits/updaterkits/updaterkits.cpp. Signed-off-by: Rayllll --- interfaces/kits/updaterkits/updaterkits.cpp | 21 +++++------- utils/include/utils_fs.h | 3 ++ utils/utils_fs.cpp | 38 +++++++++++++++++++++ utils/write_updater.cpp | 13 ++++--- 4 files changed, 55 insertions(+), 20 deletions(-) diff --git a/interfaces/kits/updaterkits/updaterkits.cpp b/interfaces/kits/updaterkits/updaterkits.cpp index 2da4cbdf..6f4e43e4 100755 --- a/interfaces/kits/updaterkits/updaterkits.cpp +++ b/interfaces/kits/updaterkits/updaterkits.cpp @@ -40,24 +40,19 @@ static void Handledlopen(const struct UpdateMessage &updateMsg, const std::strin LOG(WARNING) << "libupdater_handle_misc.z.so is not exist"; return; } - auto handleMiscLib = dlopen(HANDLE_MISC_LIB, RTLD_LAZY); - if (handleMiscLib == nullptr) { - LOG(ERROR) << "dlopen libupdater_handle_misc fail"; + auto handle = Utils::LoadLibrary(HANDLE_MISC_LIB); + if (handle == nullptr) { + cout << "load libupdater_handle_misc fail"; return; } - auto getFunc = - (bool(*)(const std::string &, const std::string &))dlsym(handleMiscLib, HANDLE_MISC_INFO); + auto getFunc = (void(*)(const std::string &, const std::string &))Utils::GetFunction(handle, HANDLE_MISC_INFO); if (getFunc == nullptr) { - LOG(ERROR) << "getFunc is nullptr"; - dlclose(handleMiscLib); + cout << "getFunc is nullptr"; + Utils::CloseLibradry(handle); return; } - bool ret = getFunc(updateMsg.update, upgradeType); - dlclose(handleMiscLib); - handleMiscLib = nullptr; - if (!ret) { - LOG(ERROR) << "handle misc info fail"; - } + getFunc(updateMsg.update, upgradeType); + Utils::CloseLibradry(handle); } #endif diff --git a/utils/include/utils_fs.h b/utils/include/utils_fs.h index a257f81b..c8e90485 100644 --- a/utils/include/utils_fs.h +++ b/utils/include/utils_fs.h @@ -29,6 +29,9 @@ int64_t GetFilesFromDirectory(const std::string &path, std::vector bool RemoveDir(const std::string &path); bool IsFileExist(const std::string &path); bool IsDirExist(const std::string &path); +void* LoadLibrary(const std::string &libName); +void CloseLibradry(void* handle); +void* GetFunction(void* handle, const std::string &funcName); } // Utils } // Updater #endif // UTILS_FS_H \ No newline at end of file diff --git a/utils/utils_fs.cpp b/utils/utils_fs.cpp index eb023c28..14181cb3 100644 --- a/utils/utils_fs.cpp +++ b/utils/utils_fs.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -148,5 +149,42 @@ bool IsDirExist(const std::string &path) } return false; } + +void* LoadLibrary(const std::string &libName) +{ + if (libName.empty()) { + LOG(ERROR) << "lib name is empty"; + return nullptr; + } + void* handle = dlopen(libName.c_str(), RTLD_LAZY); + if (handle == nullptr) { + LOG(ERROR) << "dlopen fail, lib name = " << libName; + return nullptr; + } + return handle; +} + +void CloseLibradry(void* handle) +{ + if (handle == nullptr) { + LOG(ERROR) << "handle is nulptr"; + return; + } + dlclose(handle); + handle = nullptr; +} + +void* GetFunction(void* handle, const std::string &funcName) +{ + if (handle == nullptr) { + LOG(ERROR) << "handle is nullptr"; + return nullptr; + } + if (funcName.empty()) { + LOG(ERROR) << "func name is empty"; + return nullptr; + } + return dlsym(handle, funcName.c_str()); +} } // Utils } // updater diff --git a/utils/write_updater.cpp b/utils/write_updater.cpp index ad3ca1d3..e1913c95 100644 --- a/utils/write_updater.cpp +++ b/utils/write_updater.cpp @@ -79,20 +79,19 @@ static void HandleMiscInfo(int argc, char **argv) cout << "libupdater_handle_misc.z.so is not exist"; return; } - auto handleMiscLib = dlopen(HANDLE_MISC_LIB, RTLD_LAZY); - if (handleMiscLib == nullptr) { - cout << "dlopen libupdater_handle_misc fail"; + auto handle = Utils::LoadLibrary(HANDLE_MISC_LIB); + if (handle == nullptr) { + cout << "load libupdater_handle_misc fail"; return; } - auto getFunc = (void(*)(int, char **))dlsym(handleMiscLib, NOTIFY_MISC_INFO); + auto getFunc = (void(*)(int, char **))Utils::GetFunction(handle, NOTIFY_MISC_INFO); if (getFunc == nullptr) { cout << "getFunc is nullptr"; - dlclose(handleMiscLib); + Utils::CloseLibradry(handle); return; } getFunc(argc, argv); - dlclose(handleMiscLib); - handleMiscLib = nullptr; + Utils::CloseLibradry(handle); } int main(int argc, char **argv) -- Gitee From c9e1ba0defa96868765c2681c088eababe3d32ca Mon Sep 17 00:00:00 2001 From: Rayllll Date: Thu, 9 Jan 2025 02:36:40 +0000 Subject: [PATCH 11/14] update interfaces/kits/updaterkits/updaterkits.cpp. Signed-off-by: Rayllll --- interfaces/kits/updaterkits/updaterkits.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/kits/updaterkits/updaterkits.cpp b/interfaces/kits/updaterkits/updaterkits.cpp index 6f4e43e4..5fc15581 100755 --- a/interfaces/kits/updaterkits/updaterkits.cpp +++ b/interfaces/kits/updaterkits/updaterkits.cpp @@ -42,12 +42,12 @@ static void Handledlopen(const struct UpdateMessage &updateMsg, const std::strin } auto handle = Utils::LoadLibrary(HANDLE_MISC_LIB); if (handle == nullptr) { - cout << "load libupdater_handle_misc fail"; + LOG(ERROR) << "load libupdater_handle_misc fail"; return; } auto getFunc = (void(*)(const std::string &, const std::string &))Utils::GetFunction(handle, HANDLE_MISC_INFO); if (getFunc == nullptr) { - cout << "getFunc is nullptr"; + LOG(ERROR) << "getFunc is nullptr"; Utils::CloseLibradry(handle); return; } -- Gitee From c9c105479ec64b772559ac006a88574c5fc722c2 Mon Sep 17 00:00:00 2001 From: Rayllll Date: Thu, 9 Jan 2025 02:37:19 +0000 Subject: [PATCH 12/14] update bundle.json. Signed-off-by: Rayllll --- bundle.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bundle.json b/bundle.json index 44fa70af..ff01e2df 100644 --- a/bundle.json +++ b/bundle.json @@ -40,8 +40,7 @@ "syscap": [], "features": [ "updater_ui_support", - "updater_cfg_file", - "updater_dcc_support" + "updater_cfg_file" ], "adapted_system_type": [ "standard" ], "rom": "", -- Gitee From ffa3196afc4ef9f439b97c218dfc8fe6d72ba717 Mon Sep 17 00:00:00 2001 From: Rayllll Date: Thu, 9 Jan 2025 02:37:19 +0000 Subject: [PATCH 13/14] update bundle.json. Signed-off-by: Rayllll --- bundle.json | 3 +-- interfaces/kits/updaterkits/updaterkits.cpp | 4 ++-- utils/include/utils_fs.h | 2 +- utils/utils_fs.cpp | 4 ++-- utils/write_updater.cpp | 4 ++-- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/bundle.json b/bundle.json index 44fa70af..ff01e2df 100644 --- a/bundle.json +++ b/bundle.json @@ -40,8 +40,7 @@ "syscap": [], "features": [ "updater_ui_support", - "updater_cfg_file", - "updater_dcc_support" + "updater_cfg_file" ], "adapted_system_type": [ "standard" ], "rom": "", diff --git a/interfaces/kits/updaterkits/updaterkits.cpp b/interfaces/kits/updaterkits/updaterkits.cpp index 5fc15581..7d1597eb 100755 --- a/interfaces/kits/updaterkits/updaterkits.cpp +++ b/interfaces/kits/updaterkits/updaterkits.cpp @@ -48,11 +48,11 @@ static void Handledlopen(const struct UpdateMessage &updateMsg, const std::strin auto getFunc = (void(*)(const std::string &, const std::string &))Utils::GetFunction(handle, HANDLE_MISC_INFO); if (getFunc == nullptr) { LOG(ERROR) << "getFunc is nullptr"; - Utils::CloseLibradry(handle); + Utils::CloseLibrary(handle); return; } getFunc(updateMsg.update, upgradeType); - Utils::CloseLibradry(handle); + Utils::CloseLibrary(handle); } #endif diff --git a/utils/include/utils_fs.h b/utils/include/utils_fs.h index c8e90485..6a7fc094 100644 --- a/utils/include/utils_fs.h +++ b/utils/include/utils_fs.h @@ -30,7 +30,7 @@ bool RemoveDir(const std::string &path); bool IsFileExist(const std::string &path); bool IsDirExist(const std::string &path); void* LoadLibrary(const std::string &libName); -void CloseLibradry(void* handle); +void CloseLibrary(void* handle); void* GetFunction(void* handle, const std::string &funcName); } // Utils } // Updater diff --git a/utils/utils_fs.cpp b/utils/utils_fs.cpp index 14181cb3..f96b9ee4 100644 --- a/utils/utils_fs.cpp +++ b/utils/utils_fs.cpp @@ -158,13 +158,13 @@ void* LoadLibrary(const std::string &libName) } void* handle = dlopen(libName.c_str(), RTLD_LAZY); if (handle == nullptr) { - LOG(ERROR) << "dlopen fail, lib name = " << libName; + LOG(ERROR) << "dlopen fail, lib name = " << libName << "; dlerror = " << dlerror(); return nullptr; } return handle; } -void CloseLibradry(void* handle) +void CloseLibrary(void* handle) { if (handle == nullptr) { LOG(ERROR) << "handle is nulptr"; diff --git a/utils/write_updater.cpp b/utils/write_updater.cpp index e1913c95..3bcb7fec 100644 --- a/utils/write_updater.cpp +++ b/utils/write_updater.cpp @@ -87,11 +87,11 @@ static void HandleMiscInfo(int argc, char **argv) auto getFunc = (void(*)(int, char **))Utils::GetFunction(handle, NOTIFY_MISC_INFO); if (getFunc == nullptr) { cout << "getFunc is nullptr"; - Utils::CloseLibradry(handle); + Utils::CloseLibrary(handle); return; } getFunc(argc, argv); - Utils::CloseLibradry(handle); + Utils::CloseLibrary(handle); } int main(int argc, char **argv) -- Gitee From 2e60036552e146d0899c9e3538b4c0496cf150bf Mon Sep 17 00:00:00 2001 From: Rayllll Date: Thu, 9 Jan 2025 06:23:47 +0000 Subject: [PATCH 14/14] update interfaces/kits/updaterkits/updaterkits.cpp. Signed-off-by: Rayllll --- interfaces/kits/updaterkits/updaterkits.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interfaces/kits/updaterkits/updaterkits.cpp b/interfaces/kits/updaterkits/updaterkits.cpp index 7d1597eb..decb893a 100755 --- a/interfaces/kits/updaterkits/updaterkits.cpp +++ b/interfaces/kits/updaterkits/updaterkits.cpp @@ -34,7 +34,7 @@ constexpr const char *HANDLE_MISC_LIB = "libupdater_handle_misc.z.so"; constexpr const char *HANDLE_MISC_INFO = "HandleUpdateMiscInfo"; constexpr const char *HANDLE_MISC_LIB_PATH = "/system/lib64/libupdater_handle_misc.z.so"; -static void Handledlopen(const struct UpdateMessage &updateMsg, const std::string &upgradeType) +static void HandleMiscMsg(const struct UpdateMessage &updateMsg, const std::string &upgradeType) { if (!Utils::IsFileExist(HANDLE_MISC_LIB_PATH)) { LOG(WARNING) << "libupdater_handle_misc.z.so is not exist"; @@ -66,7 +66,7 @@ static bool WriteToMiscAndRebootToUpdater(const struct UpdateMessage &updateMsg) return false; } #ifndef UPDATER_UT - Handledlopen(updateMsg, ""); + HandleMiscMsg(updateMsg, ""); WriteUpdaterMiscMsg(updateMsg); DoReboot("updater:reboot to updater to trigger update"); while (true) { @@ -140,7 +140,7 @@ static bool WriteToMiscAndResultFileRebootToUpdater(const struct UpdateMessage & std::string writeMiscBefore = "0x80000000"; WriteUpdaterResultFile(pkgPath, writeMiscBefore); #ifndef UPDATER_UT - Handledlopen(updateMsg, upgradeType); + HandleMiscMsg(updateMsg, upgradeType); WriteUpdaterMiscMsg(updateMsg); // Flag after the misc in written std::string writeMiscAfter = "0x80000008"; -- Gitee