From 46ecd0426005534ffb5a0261cf358be1a712b2a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8B=A4=E4=BA=AE?= Date: Fri, 29 Aug 2025 16:32:23 +0800 Subject: [PATCH 1/2] add callback function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 刘勤亮 --- .../kits/include/updaterkits/updaterkits.h | 9 +++++++++ interfaces/kits/updaterkits/updaterkits.cpp | 18 ++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/interfaces/kits/include/updaterkits/updaterkits.h b/interfaces/kits/include/updaterkits/updaterkits.h index 20aa7d23..633ab24c 100755 --- a/interfaces/kits/include/updaterkits/updaterkits.h +++ b/interfaces/kits/include/updaterkits/updaterkits.h @@ -15,7 +15,9 @@ #ifndef UPDATER_KITS_H #define UPDATER_KITS_H #include +#include +using RebootFunType = std::function; constexpr const char *UPGRADE_TYPE_OTA = "ota"; constexpr const char *UPGRADE_TYPE_SD = "sdcard"; constexpr const char *UPGRADE_TYPE_OTA_INTRAL = "ota_intral"; @@ -28,6 +30,13 @@ constexpr const char *UPGRADE_TYPE_SUBPKG_UPDATE = "subpkg_update"; extern int RebootAndInstallUpgradePackage(const std::string &miscFile, const std::vector &packageName, const std::string &upgradeType = UPGRADE_TYPE_OTA); +// Reboot system to updater mode and trigger installing update package. +// @param packageName update package file name. +// @param rebootFunc callback function. +// @return returns true if trigger update package installing success, else returns false. +extern int RebootAndInstallUpgradePackage(const std::string &miscFile, const std::vector &packageName, + const std::string &upgradeType = UPGRADE_TYPE_OTA, const RebootFunType &rebootFunc); + // Reboot system to sdcard update mode and trigger installing update package. // @return returns true if trigger update package installing success, else returns false. extern bool RebootAndInstallSdcardPackage(const std::string &miscFile, const std::vector &packageName); diff --git a/interfaces/kits/updaterkits/updaterkits.cpp b/interfaces/kits/updaterkits/updaterkits.cpp index f6272f9f..afb644a5 100755 --- a/interfaces/kits/updaterkits/updaterkits.cpp +++ b/interfaces/kits/updaterkits/updaterkits.cpp @@ -127,7 +127,7 @@ static std::string ParsePkgPath(const struct UpdateMessage &updateMsg) } static bool WriteToMiscAndResultFileRebootToUpdater(const struct UpdateMessage &updateMsg, - const std::string &upgradeType) + const std::string &upgradeType, const RebootFunType &rebootFunc) { // Write package name to misc, then trigger reboot. const char *bootCmd = "boot_updater"; @@ -146,7 +146,11 @@ static bool WriteToMiscAndResultFileRebootToUpdater(const struct UpdateMessage & // Flag after the misc in written std::string writeMiscAfter = "0x80000008"; WriteUpdaterResultFile(pkgPath, writeMiscAfter); - DoReboot("updater:reboot to updater to trigger update"); + if (rebootFunc) { + rebootFunc() + } else { + DoReboot("updater:reboot to updater to trigger update"); + } while (true) { pause(); } @@ -227,7 +231,7 @@ bool RebootAndInstallSdcardPackage(const std::string &miscFile, const std::vecto } int RebootAndInstallUpgradePackage(const std::string &miscFile, const std::vector &packageName, - const std::string &upgradeType) + const std::string &upgradeType, const RebootFunType &rebootFunType) { if (packageName.size() == 0 && (upgradeType == UPGRADE_TYPE_OTA || upgradeType == UPGRADE_TYPE_OTA_INTRAL)) { LOG(ERROR) << "updaterkits: invalid argument. one of arugments is empty"; @@ -267,7 +271,7 @@ int RebootAndInstallUpgradePackage(const std::string &miscFile, const std::vecto } if (upgradeType == UPGRADE_TYPE_OTA || upgradeType == UPGRADE_TYPE_OTA_INTRAL || upgradeType == UPGRADE_TYPE_SUBPKG_UPDATE) { - WriteToMiscAndResultFileRebootToUpdater(updateMsg, upgradeType); + WriteToMiscAndResultFileRebootToUpdater(updateMsg, upgradeType, rebootFunc); } else { WriteToMiscAndRebootToUpdater(updateMsg); } @@ -276,6 +280,12 @@ int RebootAndInstallUpgradePackage(const std::string &miscFile, const std::vecto return 0; } +int RebootAndInstallUpgradePackage(const std::string &miscFile, const std::vector &packageName, + const std::string &upgradeType) +{ + return RebootAndInstallUpgradePackage(miscFile, packageName, upgradeType, nullptr); +} + bool RebootAndCleanUserData(const std::string &miscFile, const std::string &cmd) { if (miscFile.empty() || cmd.empty()) { -- Gitee From 5a5d6b3139441d55e48b8f57615e02476590fc5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8B=A4=E4=BA=AE?= Date: Fri, 29 Aug 2025 16:32:23 +0800 Subject: [PATCH 2/2] add callback function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 刘勤亮 --- .../kits/include/updaterkits/updaterkits.h | 9 +++++++++ interfaces/kits/updaterkits/updaterkits.cpp | 18 ++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/interfaces/kits/include/updaterkits/updaterkits.h b/interfaces/kits/include/updaterkits/updaterkits.h index 20aa7d23..633ab24c 100755 --- a/interfaces/kits/include/updaterkits/updaterkits.h +++ b/interfaces/kits/include/updaterkits/updaterkits.h @@ -15,7 +15,9 @@ #ifndef UPDATER_KITS_H #define UPDATER_KITS_H #include +#include +using RebootFunType = std::function; constexpr const char *UPGRADE_TYPE_OTA = "ota"; constexpr const char *UPGRADE_TYPE_SD = "sdcard"; constexpr const char *UPGRADE_TYPE_OTA_INTRAL = "ota_intral"; @@ -28,6 +30,13 @@ constexpr const char *UPGRADE_TYPE_SUBPKG_UPDATE = "subpkg_update"; extern int RebootAndInstallUpgradePackage(const std::string &miscFile, const std::vector &packageName, const std::string &upgradeType = UPGRADE_TYPE_OTA); +// Reboot system to updater mode and trigger installing update package. +// @param packageName update package file name. +// @param rebootFunc callback function. +// @return returns true if trigger update package installing success, else returns false. +extern int RebootAndInstallUpgradePackage(const std::string &miscFile, const std::vector &packageName, + const std::string &upgradeType = UPGRADE_TYPE_OTA, const RebootFunType &rebootFunc); + // Reboot system to sdcard update mode and trigger installing update package. // @return returns true if trigger update package installing success, else returns false. extern bool RebootAndInstallSdcardPackage(const std::string &miscFile, const std::vector &packageName); diff --git a/interfaces/kits/updaterkits/updaterkits.cpp b/interfaces/kits/updaterkits/updaterkits.cpp index f6272f9f..afb644a5 100755 --- a/interfaces/kits/updaterkits/updaterkits.cpp +++ b/interfaces/kits/updaterkits/updaterkits.cpp @@ -127,7 +127,7 @@ static std::string ParsePkgPath(const struct UpdateMessage &updateMsg) } static bool WriteToMiscAndResultFileRebootToUpdater(const struct UpdateMessage &updateMsg, - const std::string &upgradeType) + const std::string &upgradeType, const RebootFunType &rebootFunc) { // Write package name to misc, then trigger reboot. const char *bootCmd = "boot_updater"; @@ -146,7 +146,11 @@ static bool WriteToMiscAndResultFileRebootToUpdater(const struct UpdateMessage & // Flag after the misc in written std::string writeMiscAfter = "0x80000008"; WriteUpdaterResultFile(pkgPath, writeMiscAfter); - DoReboot("updater:reboot to updater to trigger update"); + if (rebootFunc) { + rebootFunc() + } else { + DoReboot("updater:reboot to updater to trigger update"); + } while (true) { pause(); } @@ -227,7 +231,7 @@ bool RebootAndInstallSdcardPackage(const std::string &miscFile, const std::vecto } int RebootAndInstallUpgradePackage(const std::string &miscFile, const std::vector &packageName, - const std::string &upgradeType) + const std::string &upgradeType, const RebootFunType &rebootFunType) { if (packageName.size() == 0 && (upgradeType == UPGRADE_TYPE_OTA || upgradeType == UPGRADE_TYPE_OTA_INTRAL)) { LOG(ERROR) << "updaterkits: invalid argument. one of arugments is empty"; @@ -267,7 +271,7 @@ int RebootAndInstallUpgradePackage(const std::string &miscFile, const std::vecto } if (upgradeType == UPGRADE_TYPE_OTA || upgradeType == UPGRADE_TYPE_OTA_INTRAL || upgradeType == UPGRADE_TYPE_SUBPKG_UPDATE) { - WriteToMiscAndResultFileRebootToUpdater(updateMsg, upgradeType); + WriteToMiscAndResultFileRebootToUpdater(updateMsg, upgradeType, rebootFunc); } else { WriteToMiscAndRebootToUpdater(updateMsg); } @@ -276,6 +280,12 @@ int RebootAndInstallUpgradePackage(const std::string &miscFile, const std::vecto return 0; } +int RebootAndInstallUpgradePackage(const std::string &miscFile, const std::vector &packageName, + const std::string &upgradeType) +{ + return RebootAndInstallUpgradePackage(miscFile, packageName, upgradeType, nullptr); +} + bool RebootAndCleanUserData(const std::string &miscFile, const std::string &cmd) { if (miscFile.empty() || cmd.empty()) { -- Gitee