diff --git a/interfaces/kits/include/updaterkits/updaterkits.h b/interfaces/kits/include/updaterkits/updaterkits.h index 20aa7d23a96eda6cbe80ad7d40f18e57f0744ba2..5d523c2de925e1635bd9ed6e375fd57568a6264e 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, 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 f6272f9fe08a6a10aa8bb3b7b787381c62dff43a..a83e99ca8fa53a5acd41a49ea54f9e7a8a5398e1 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 == nullptr) { + DoReboot("updater:reboot to updater to trigger update"); + } else { + rebootFunc(); + } 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 &rebootFunc) { 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()) {