From 4f6c41cc4c523dc949b7eee3e01a70e1ff5f819b Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 15 Oct 2024 11:47:22 +0800 Subject: [PATCH 1/4] add reboot reason Signed-off-by: unknown --- interfaces/kits/updaterkits/updaterkits.cpp | 4 ++-- services/flashd/daemon/system_depend.cpp | 2 +- services/hwfault_retry/hwfault_retry.cpp | 2 +- services/updater_binary/update_partitions.cpp | 2 +- services/updater_main.cpp | 7 ++++--- services/updater_ui.cpp | 12 ++++++------ utils/include/utils.h | 5 +++-- utils/updater_reboot.cpp | 9 +++++---- utils/utils.cpp | 11 +++++------ 9 files changed, 28 insertions(+), 26 deletions(-) diff --git a/interfaces/kits/updaterkits/updaterkits.cpp b/interfaces/kits/updaterkits/updaterkits.cpp index fcb68064..617a4ea6 100755 --- a/interfaces/kits/updaterkits/updaterkits.cpp +++ b/interfaces/kits/updaterkits/updaterkits.cpp @@ -39,7 +39,7 @@ static bool WriteToMiscAndRebootToUpdater(const struct UpdateMessage &updateMsg) } #ifndef UPDATER_UT WriteUpdaterMiscMsg(updateMsg); - DoReboot("updater"); + DoReboot("updater", "reboot to updater to trigger update"); while (true) { pause(); } @@ -114,7 +114,7 @@ static bool WriteToMiscAndResultFileRebootToUpdater(const struct UpdateMessage & // Flag after the misc in written std::string writeMiscAfter = "0x80000008"; WriteUpdaterResultFile(pkgPath, writeMiscAfter); - DoReboot("updater"); + DoReboot("updater", "reboot to updater to trigger update"); while (true) { pause(); } diff --git a/services/flashd/daemon/system_depend.cpp b/services/flashd/daemon/system_depend.cpp index c2355097..c8d702ec 100644 --- a/services/flashd/daemon/system_depend.cpp +++ b/services/flashd/daemon/system_depend.cpp @@ -54,7 +54,7 @@ namespace SystemDepend { { FLASHD_LOGE("Flashd RebootDevice cmd is %s", cmd.c_str()); Updater::PostUpdater(true); - Updater::Utils::UpdaterDoReboot(""); + Updater::Utils::UpdaterDoReboot("", "Updater flashd reboot command"); return true; } } diff --git a/services/hwfault_retry/hwfault_retry.cpp b/services/hwfault_retry/hwfault_retry.cpp index 01325c3a..d83a536b 100644 --- a/services/hwfault_retry/hwfault_retry.cpp +++ b/services/hwfault_retry/hwfault_retry.cpp @@ -79,7 +79,7 @@ void HwFaultRetry::RebootRetry() PostUpdater(false); sync(); #ifndef UPDATER_UT - DoReboot("updater"); + DoReboot("updater", "Updater fault retry %d times" % retryCount_); while (true) { pause(); } diff --git a/services/updater_binary/update_partitions.cpp b/services/updater_binary/update_partitions.cpp index 09f8bf1a..0eff03f3 100644 --- a/services/updater_binary/update_partitions.cpp +++ b/services/updater_binary/update_partitions.cpp @@ -140,7 +140,7 @@ int UpdatePartitions::DoNewPartitions(PartitonList &newPartList) } else if (ret > 1) { LOG(INFO) << "do_partitions success reboot"; #ifndef UPDATER_UT - Utils::UpdaterDoReboot("updater"); + Utils::UpdaterDoReboot("updater", "Updater finish do new partitions"); #endif } return ret; diff --git a/services/updater_main.cpp b/services/updater_main.cpp index 84a837db..08c7c7a4 100644 --- a/services/updater_main.cpp +++ b/services/updater_main.cpp @@ -800,7 +800,7 @@ void RebootAfterUpdateSuccess(const UpdaterParams &upParams) if (IsNeedWipe() || upParams.sdExtMode == SDCARD_UPDATE_FROM_DEV || upParams.sdExtMode == SDCARD_UPDATE_FROM_DATA) { - Utils::UpdaterDoReboot("updater", "--user_wipe_data"); + Utils::UpdaterDoReboot("updater", "Updater wipe data after upgrade success", "--user_wipe_data"); return; } if (upParams.factoryResetMode == "factory_wipe_data") { @@ -809,7 +809,8 @@ void RebootAfterUpdateSuccess(const UpdaterParams &upParams) Utils::UsSleep(120 * DISPLAY_TIME); // 120 : 120s } upParams.forceUpdate || upParams.factoryResetMode == "factory_wipe_data" ? - Utils::DoShutdown() : Utils::UpdaterDoReboot(""); + Utils::DoShutdown("Updater update success go shut down") : + Utils::UpdaterDoReboot("", "Updater update success"); } int UpdaterMain(int argc, char **argv) @@ -836,7 +837,7 @@ int UpdaterMain(int argc, char **argv) if (upParams.forceReboot) { Utils::UsSleep(5 * DISPLAY_TIME); // 5 : 5s PostUpdater(true); - Utils::UpdaterDoReboot(""); + Utils::UpdaterDoReboot("", "Updater night update fail"); return 0; } } else if (mode == SDCARD_UPDATE) { diff --git a/services/updater_ui.cpp b/services/updater_ui.cpp index 90162af4..0b8f06f7 100644 --- a/services/updater_ui.cpp +++ b/services/updater_ui.cpp @@ -68,7 +68,7 @@ DEFINE_ASYN_CALLBACK(OnRebootEvt) LOG(INFO) << "On Label Reboot"; GraphicEngine::GetInstance().StopEngine(); PostUpdater(false); - Utils::UpdaterDoReboot(""); + Utils::UpdaterDoReboot("", "Updater reboot btn event"); } DEFINE_SYNC_CALLBACK(OnLabelResetEvt) @@ -98,7 +98,7 @@ DEFINE_ASYN_CALLBACK(OnLabelSDCardEvt) return; } PostUpdater(true); - Utils::UpdaterDoReboot(""); + Utils::UpdaterDoReboot("", "Updater sdcard update success reboot"); } DEFINE_ASYN_CALLBACK(OnLabelSDCardNoDelayEvt) @@ -121,7 +121,7 @@ DEFINE_ASYN_CALLBACK(OnLabelSDCardNoDelayEvt) GetFacade().ShowSuccessPage(); Utils::UsSleep(SUCCESS_DELAY); PostUpdater(true); - Utils::UpdaterDoReboot(""); + Utils::UpdaterDoReboot("", "Updater sdcard update success reboot"); } DEFINE_ASYN_CALLBACK(OnLabelSDUpdateResEvt) @@ -151,7 +151,7 @@ DEFINE_ASYN_CALLBACK(OnLabelSDUpdateResEvt) GetFacade().ShowSuccessPage(); Utils::UsSleep(SUCCESS_DELAY); PostUpdater(true); - Utils::UpdaterDoReboot(""); + Utils::UpdaterDoReboot("", "Updater sdcard update success reboot"); } DEFINE_SYNC_CALLBACK(OnLabelCancelEvt) @@ -206,7 +206,7 @@ DEFINE_ASYN_CALLBACK(OnConfirmRstEvt) GetFacade().ShowSuccessPage(); PostUpdater(true); Utils::UsSleep(SUCCESS_DELAY); - Utils::UpdaterDoReboot(""); + Utils::UpdaterDoReboot("", "Updater factory reset success"); } } @@ -214,7 +214,7 @@ DEFINE_ASYN_CALLBACK(OnMenuShutdownEvt) { LOG(DEBUG) << "shutdown"; GraphicEngine::GetInstance().StopEngine(); - Utils::DoShutdown(); + Utils::DoShutdown("Updater shutdown btn event"); } DEFINE_ASYN_CALLBACK(OnMenuClearCacheEvt) diff --git a/utils/include/utils.h b/utils/include/utils.h index 96194820..f97f8eda 100644 --- a/utils/include/utils.h +++ b/utils/include/utils.h @@ -64,8 +64,9 @@ int32_t DeleteFile(const std::string& filename); std::vector SplitString(const std::string &str, const std::string del = " \t"); std::string Trim(const std::string &str); std::string ConvertSha256Hex(const uint8_t* shaDigest, size_t length); -void UpdaterDoReboot(const std::string& rebootTarget, const std::string& extData = ""); -void DoShutdown(); +void UpdaterDoReboot(const std::string& rebootTarget, const std::string &rebootReason, + const std::string& extData = ""); +void DoShutdown(const std::string &shutdownReason); std::string GetCertName(); bool WriteFully(int fd, const uint8_t *data, size_t size); bool ReadFully(int fd, void* data, size_t size); diff --git a/utils/updater_reboot.cpp b/utils/updater_reboot.cpp index 16311183..7b1d40a0 100644 --- a/utils/updater_reboot.cpp +++ b/utils/updater_reboot.cpp @@ -27,15 +27,16 @@ int main(int argc, char **argv) } if (argc == 1) { Updater::LOG(Updater::INFO) << "Updater::Utils::UpdaterDoReboot nullptr"; - Updater::Utils::UpdaterDoReboot(""); + Updater::Utils::UpdaterDoReboot("", "Updater reboot param is null"); } else { std::string updaterStr = "updater"; if (!memcmp(argv[1], updaterStr.c_str(), updaterStr.length())) { - Updater::Utils::UpdaterDoReboot(argv[1]); + Updater::Utils::UpdaterDoReboot(argv[1], "Updater command reboot to updater"); } else if (strcmp(argv[1], "flashd") == 0) { - Updater::Utils::UpdaterDoReboot(argv[1]); + Updater::Utils::UpdaterDoReboot(argv[1], "Updater command reboot to flashd"); } else if (strncmp(argv[1], "flashd:", strlen("flashd:")) == 0) { - Updater::Utils::UpdaterDoReboot("flashd", argv[1] + strlen("flashd:")); + Updater::Utils::UpdaterDoReboot("flashd", "Updater command reboot to flashd", + argv[1] + strlen("flashd:")); } else { Updater::LOG(Updater::INFO) << "param must be updater/flashd!"; } diff --git a/utils/utils.cpp b/utils/utils.cpp index 7337f1e9..4a9b8c93 100644 --- a/utils/utils.cpp +++ b/utils/utils.cpp @@ -40,7 +40,6 @@ #include "parameter.h" #include "securec.h" #include "updater/updater_const.h" -#include "scope_guard.h" namespace Updater { using namespace Hpackage; @@ -50,7 +49,6 @@ constexpr uint8_t SHIFT_RIGHT_FOUR_BITS = 4; constexpr int MAX_TIME_SIZE = 20; constexpr size_t PARAM_SIZE = 32; constexpr const char *PREFIX_PARTITION_NODE = "/dev/block/by-name/"; -constexpr mode_t DEFAULT_DIR_MODE = 0775; namespace { void UpdateInfoInMisc(const std::string headInfo, const std::optional message, bool isRemove) @@ -224,9 +222,10 @@ bool SetRebootMisc(const std::string& rebootTarget, const std::string &extData, return true; } -void UpdaterDoReboot(const std::string& rebootTarget, const std::string &extData) +void UpdaterDoReboot(const std::string& rebootTarget, const std::string &rebootReason, const std::string &extData) { LOG(INFO) << ", rebootTarget: " << rebootTarget; + LOG(INFO) << ", rebootReason: " << rebootReason; LoadFstab(); struct UpdateMessage msg = {}; if (rebootTarget.empty()) { @@ -246,7 +245,7 @@ void UpdaterDoReboot(const std::string& rebootTarget, const std::string &extData } sync(); #ifndef UPDATER_UT - DoReboot(rebootTarget.c_str()); + DoRebootExt(rebootTarget.c_str(), rebootReason.c_str()); while (true) { pause(); } @@ -255,7 +254,7 @@ void UpdaterDoReboot(const std::string& rebootTarget, const std::string &extData #endif } -void DoShutdown() +void DoShutdown(const std::string &shutdownReason) { UpdateMessage msg = {}; if (!WriteUpdaterMiscMsg(msg)) { @@ -263,7 +262,7 @@ void DoShutdown() return; } sync(); - DoReboot("shutdown"); + DoRebootExt("shutdown", shutdownReason.c_str()); } std::string GetCertName() -- Gitee From 25efda238f68fd05a85136d95cdc0d83d4732c6c Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 15 Oct 2024 13:55:33 +0800 Subject: [PATCH 2/4] add reboot reason Signed-off-by: unknown --- interfaces/kits/updaterkits/updaterkits.cpp | 4 ++-- services/hwfault_retry/hwfault_retry.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/interfaces/kits/updaterkits/updaterkits.cpp b/interfaces/kits/updaterkits/updaterkits.cpp index 617a4ea6..81f0085e 100755 --- a/interfaces/kits/updaterkits/updaterkits.cpp +++ b/interfaces/kits/updaterkits/updaterkits.cpp @@ -39,7 +39,7 @@ static bool WriteToMiscAndRebootToUpdater(const struct UpdateMessage &updateMsg) } #ifndef UPDATER_UT WriteUpdaterMiscMsg(updateMsg); - DoReboot("updater", "reboot to updater to trigger update"); + DoReboot("updater:reboot to updater to trigger update"); while (true) { pause(); } @@ -114,7 +114,7 @@ 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"); + DoReboot("updater:reboot to updater to trigger update"); while (true) { pause(); } diff --git a/services/hwfault_retry/hwfault_retry.cpp b/services/hwfault_retry/hwfault_retry.cpp index d83a536b..80dd3a10 100644 --- a/services/hwfault_retry/hwfault_retry.cpp +++ b/services/hwfault_retry/hwfault_retry.cpp @@ -79,7 +79,7 @@ void HwFaultRetry::RebootRetry() PostUpdater(false); sync(); #ifndef UPDATER_UT - DoReboot("updater", "Updater fault retry %d times" % retryCount_); + DoReboot("updater:Updater fault retry %d times" % retryCount_); while (true) { pause(); } -- Gitee From 35c0a19a9c05db8736d9ac5cfc8ed9e5da7531e2 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 15 Oct 2024 13:55:33 +0800 Subject: [PATCH 3/4] add reboot reason Signed-off-by: unknown --- interfaces/kits/updaterkits/updaterkits.cpp | 4 ++-- services/hwfault_retry/hwfault_retry.cpp | 2 +- utils/utils.cpp | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/interfaces/kits/updaterkits/updaterkits.cpp b/interfaces/kits/updaterkits/updaterkits.cpp index 617a4ea6..81f0085e 100755 --- a/interfaces/kits/updaterkits/updaterkits.cpp +++ b/interfaces/kits/updaterkits/updaterkits.cpp @@ -39,7 +39,7 @@ static bool WriteToMiscAndRebootToUpdater(const struct UpdateMessage &updateMsg) } #ifndef UPDATER_UT WriteUpdaterMiscMsg(updateMsg); - DoReboot("updater", "reboot to updater to trigger update"); + DoReboot("updater:reboot to updater to trigger update"); while (true) { pause(); } @@ -114,7 +114,7 @@ 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"); + DoReboot("updater:reboot to updater to trigger update"); while (true) { pause(); } diff --git a/services/hwfault_retry/hwfault_retry.cpp b/services/hwfault_retry/hwfault_retry.cpp index d83a536b..80dd3a10 100644 --- a/services/hwfault_retry/hwfault_retry.cpp +++ b/services/hwfault_retry/hwfault_retry.cpp @@ -79,7 +79,7 @@ void HwFaultRetry::RebootRetry() PostUpdater(false); sync(); #ifndef UPDATER_UT - DoReboot("updater", "Updater fault retry %d times" % retryCount_); + DoReboot("updater:Updater fault retry %d times" % retryCount_); while (true) { pause(); } diff --git a/utils/utils.cpp b/utils/utils.cpp index 4a9b8c93..eb145b1e 100644 --- a/utils/utils.cpp +++ b/utils/utils.cpp @@ -40,6 +40,7 @@ #include "parameter.h" #include "securec.h" #include "updater/updater_const.h" +#include "scope_guard.h" namespace Updater { using namespace Hpackage; @@ -49,6 +50,7 @@ constexpr uint8_t SHIFT_RIGHT_FOUR_BITS = 4; constexpr int MAX_TIME_SIZE = 20; constexpr size_t PARAM_SIZE = 32; constexpr const char *PREFIX_PARTITION_NODE = "/dev/block/by-name/"; +constexpr mode_t DEFAULT_DIR_MODE = 0775; namespace { void UpdateInfoInMisc(const std::string headInfo, const std::optional message, bool isRemove) -- Gitee From ec0ca11adc0b13134293d811317b1448a93a6010 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 18 Oct 2024 16:19:54 +0800 Subject: [PATCH 4/4] fix Signed-off-by: unknown --- utils/updater_reboot.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/utils/updater_reboot.cpp b/utils/updater_reboot.cpp index 7b1d40a0..026ada98 100644 --- a/utils/updater_reboot.cpp +++ b/utils/updater_reboot.cpp @@ -27,15 +27,15 @@ int main(int argc, char **argv) } if (argc == 1) { Updater::LOG(Updater::INFO) << "Updater::Utils::UpdaterDoReboot nullptr"; - Updater::Utils::UpdaterDoReboot("", "Updater reboot param is null"); + Updater::Utils::UpdaterDoReboot("", "Updater_reboot default reboot"); } else { std::string updaterStr = "updater"; if (!memcmp(argv[1], updaterStr.c_str(), updaterStr.length())) { - Updater::Utils::UpdaterDoReboot(argv[1], "Updater command reboot to updater"); + Updater::Utils::UpdaterDoReboot(argv[1], "Updater_reboot command reboot to updater"); } else if (strcmp(argv[1], "flashd") == 0) { - Updater::Utils::UpdaterDoReboot(argv[1], "Updater command reboot to flashd"); + Updater::Utils::UpdaterDoReboot(argv[1], "Updater_reboot command reboot to flashd"); } else if (strncmp(argv[1], "flashd:", strlen("flashd:")) == 0) { - Updater::Utils::UpdaterDoReboot("flashd", "Updater command reboot to flashd", + Updater::Utils::UpdaterDoReboot("flashd", "Updater_reboot command reboot to flashd", argv[1] + strlen("flashd:")); } else { Updater::LOG(Updater::INFO) << "param must be updater/flashd!"; -- Gitee