diff --git a/interfaces/kits/include/updaterkits/updaterkits.h b/interfaces/kits/include/updaterkits/updaterkits.h index 3c8699880ceb8dd0830623fffaedfd8b4fed5148..6f2b66999f311d50fbc01ae7266620c338dc7bd9 100755 --- a/interfaces/kits/include/updaterkits/updaterkits.h +++ b/interfaces/kits/include/updaterkits/updaterkits.h @@ -23,7 +23,7 @@ constexpr const char *UPGRADE_TYPE_SD_INTRAL = "sdcard_intral"; // Reboot system to updater mode and trigger installing update package. // @param packageName update package file name. // @return returns true if trigger update package installing success, else returns false. -extern bool RebootAndInstallUpgradePackage(const std::string &miscFile, const std::vector &packageName, +extern int RebootAndInstallUpgradePackage(const std::string &miscFile, const std::vector &packageName, const std::string &upgradeType = UPGRADE_TYPE_OTA); // Reboot system to sdcard update mode and trigger installing update package. diff --git a/interfaces/kits/updaterkits/updaterkits.cpp b/interfaces/kits/updaterkits/updaterkits.cpp index 02a6071547dbcc379a421bf085ab59269253e161..c3c0f55cb6143a115f89a52ca05929ffcf6cded9 100755 --- a/interfaces/kits/updaterkits/updaterkits.cpp +++ b/interfaces/kits/updaterkits/updaterkits.cpp @@ -132,12 +132,12 @@ static bool IsPackagePath(const std::string &path) return true; } -static bool AddPkgPath(struct UpdateMessage &msg, size_t updateOffset, const std::vector &packageName) +static int AddPkgPath(struct UpdateMessage &msg, size_t updateOffset, const std::vector &packageName) { for (auto path : packageName) { if (updateOffset > sizeof(msg.update)) { LOG(ERROR) << "updaterkits: updateOffset > msg.update, return false"; - return false; + return 4; // 4 : path is too long } int ret; if (IsPackagePath(path)) { @@ -149,11 +149,11 @@ static bool AddPkgPath(struct UpdateMessage &msg, size_t updateOffset, const std } if (ret < 0) { LOG(ERROR) << "updaterkits: copy updater message failed"; - return false; + return 5; // 5 : The library function is incorrect } updateOffset += static_cast(ret); } - return true; + return 0; } bool RebootAndInstallSdcardPackage(const std::string &miscFile, const std::vector &packageName) @@ -165,7 +165,7 @@ bool RebootAndInstallSdcardPackage(const std::string &miscFile, const std::vecto return false; } - if (packageName.size() != 0 && !AddPkgPath(msg, static_cast(ret), packageName)) { + if (packageName.size() != 0 && AddPkgPath(msg, static_cast(ret), packageName) != 0) { LOG(ERROR) << "get sdcard pkg path fail"; return false; } @@ -175,19 +175,19 @@ bool RebootAndInstallSdcardPackage(const std::string &miscFile, const std::vecto return true; } -bool RebootAndInstallUpgradePackage(const std::string &miscFile, const std::vector &packageName, +int RebootAndInstallUpgradePackage(const std::string &miscFile, const std::vector &packageName, const std::string &upgradeType) { if (packageName.size() == 0 && upgradeType == UPGRADE_TYPE_OTA) { LOG(ERROR) << "updaterkits: invalid argument. one of arugments is empty"; - return false; + return 1; // 1 : Invalid input } for (auto path : packageName) { if (IsPackagePath(path)) { if (access(path.c_str(), R_OK) < 0) { LOG(ERROR) << "updaterkits: " << path << " is not readable"; - return false; + return 2; // 2 : pkg not exist } } } @@ -202,11 +202,11 @@ bool RebootAndInstallUpgradePackage(const std::string &miscFile, const std::vect } if (ret < 0) { LOG(ERROR) << "updaterkits: copy updater message failed"; - return false; + return 3; // 3 : The library function is incorrect } - - if (!AddPkgPath(updateMsg, static_cast(ret), packageName)) { - return false; + int addRet = AddPkgPath(updateMsg, static_cast(ret), packageName); + if (addRet != 0) { + return addRet; } if (upgradeType == UPGRADE_TYPE_OTA) { WriteToMiscAndResultFileRebootToUpdater(updateMsg); @@ -215,7 +215,7 @@ bool RebootAndInstallUpgradePackage(const std::string &miscFile, const std::vect } // Never get here. - return true; + return 0; } bool RebootAndCleanUserData(const std::string &miscFile, const std::string &cmd) diff --git a/services/flashd/daemon/update_commander.cpp b/services/flashd/daemon/update_commander.cpp index ca0f21b8dfc472b0e98eafe122f2a0bd0c6b9690..d8735711b956fd912d170f0d0e18f8f77c48b4d8 100644 --- a/services/flashd/daemon/update_commander.cpp +++ b/services/flashd/daemon/update_commander.cpp @@ -118,7 +118,10 @@ bool UpdateCommander::ExecUpdate() const const std::string miscFile = "/dev/block/by-name/misc"; std::vector filePath; filePath.push_back(filePath_); - return RebootAndInstallUpgradePackage(miscFile, filePath); + if (RebootAndInstallUpgradePackage(miscFile, filePath) == 0) { + return true; + } + return false; } void UpdateCommander::PostCommand() diff --git a/test/unittest/updaterkits_test/updaterkits_unittest.cpp b/test/unittest/updaterkits_test/updaterkits_unittest.cpp index 9d6665c3c59df57e20fc76a1412d90e79c090eed..0ac3b7e3a86b3b13a20a27dae895cea15eec0998 100755 --- a/test/unittest/updaterkits_test/updaterkits_unittest.cpp +++ b/test/unittest/updaterkits_test/updaterkits_unittest.cpp @@ -39,18 +39,18 @@ void UpdaterKitsUnitTest::TearDownTestCase(void) HWTEST_F(UpdaterKitsUnitTest, updater_kits_test01, TestSize.Level1) { const std::vector packageName1 = {""}; - bool ret = RebootAndInstallUpgradePackage(MISC_FILE, packageName1); - EXPECT_EQ(ret, false); + int ret = RebootAndInstallUpgradePackage(MISC_FILE, packageName1); + EXPECT_EQ(ret, 1); const std::vector packageName2 = {"/data/updater/updater/updater_without_updater_binary.zip"}; auto fp = std::unique_ptr(fopen(MISC_FILE.c_str(), "wb+"), fclose); EXPECT_NE(fp, nullptr); ret = RebootAndInstallUpgradePackage(MISC_FILE, packageName2); - EXPECT_EQ(ret, true); + EXPECT_EQ(ret, 0); ret = RebootAndInstallUpgradePackage(MISC_FILE, packageName2, UPGRADE_TYPE_SD); - EXPECT_EQ(ret, true); + EXPECT_EQ(ret, 0); ret = RebootAndInstallUpgradePackage(MISC_FILE, packageName2, UPGRADE_TYPE_SD_INTRAL); - EXPECT_EQ(ret, true); + EXPECT_EQ(ret, 0); unlink(MISC_FILE.c_str()); }