From 0d76fc5bd467180fa526d2ba8674e19777b4fd72 Mon Sep 17 00:00:00 2001 From: lidanyang Date: Wed, 24 Jul 2024 19:11:27 +0800 Subject: [PATCH 01/52] add package verify Signed-off-by: lidanyang --- services/include/package/pkg_manager.h | 4 ++ .../package/pkg_manager/pkg_managerImpl.cpp | 47 +++++++++++++++++++ test/unittest/script/script_unittest.h | 4 ++ 3 files changed, 55 insertions(+) diff --git a/services/include/package/pkg_manager.h b/services/include/package/pkg_manager.h index a455c619..db276550 100644 --- a/services/include/package/pkg_manager.h +++ b/services/include/package/pkg_manager.h @@ -258,7 +258,11 @@ public: virtual int32_t LoadPackage(const std::string &packagePath, const std::string &keyPath, std::vector &fileIds) = 0; +<<<<<<< Updated upstream virtual int32_t VerifyAccPackage(const std::string &packagePath, const std::string &keyPath) = 0; +======= + virtual int32_t VerifyOtaPackage(const std::string &devPath, uint64_t offset, size_t size) = 0; +>>>>>>> Stashed changes virtual int32_t VerifyOtaPackage(const std::string &packagePath) = 0; diff --git a/services/package/pkg_manager/pkg_managerImpl.cpp b/services/package/pkg_manager/pkg_managerImpl.cpp index 817c0b00..c4468a40 100644 --- a/services/package/pkg_manager/pkg_managerImpl.cpp +++ b/services/package/pkg_manager/pkg_managerImpl.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -24,12 +25,14 @@ #include #include #include "dump.h" +#include "inttypes.h" #include "pkg_gzipfile.h" #include "pkg_lz4file.h" #include "pkg_manager.h" #include "pkg_upgradefile.h" #include "pkg_verify_util.h" #include "pkg_zipfile.h" +#include "scope_guard.h" #include "securec.h" #include "updater/updater_const.h" #include "utils.h" @@ -962,6 +965,7 @@ void PkgManagerImpl::PostDecodeProgress(int type, size_t writeDataLen, const voi } } +<<<<<<< Updated upstream int32_t PkgManagerImpl::VerifyAccPackage(const std::string &packagePath, const std::string &keyPath) { PkgStreamPtr pkgStream = nullptr; @@ -984,6 +988,49 @@ int32_t PkgManagerImpl::VerifyAccPackage(const std::string &packagePath, const s } ClosePkgStream(pkgStream); +======= +int32_t PkgManagerImpl::VerifyOtaPackage(const std::string &devPath, uint64_t offset, size_t size) +{ + constexpr size_t pageSize = 4096; + size_t offsetAligned = (offset / pageSize) * pageSize; + if (size == 0 || size + offset < offsetAligned || offset < offsetAligned) { + PKG_LOGE("invalid param %zu %" PRIu64 " %zu", size, offset, offsetAligned); + return PKG_INVALID_PARAM; + } + int fd = open(devPath.c_str(), O_RDONLY | O_LARGEFILE); + if (fd < 0) { + PKG_LOGE("open %s fail, %s", devPath.c_str(), strerror(errno)); + return PKG_INVALID_FILE; + } + ON_SCOPE_EXIT(closePath) { + close(fd); + }; + uint8_t *pMap = static_cast(mmap64(nullptr, size + offset - offsetAligned, PROT_READ, MAP_PRIVATE, + fd, offsetAligned)); + if (pMap == MAP_FAILED) { + PKG_LOGE("mmap64 %s fail, %s %zu %" PRIu64, devPath.c_str(), strerror(errno), size, offset); + return PKG_NONE_MEMORY; + } + ON_SCOPE_EXIT(unmapMem) { + munmap(pMap, size + offset - offsetAligned); + }; + PkgBuffer buffer(pMap + (offset - offsetAligned), size); + PkgStreamPtr pkgStream = nullptr; + int32_t ret = CreatePkgStream(pkgStream, devPath, buffer); + if (ret != PKG_SUCCESS) { + PKG_LOGE("create package stream fail %s %s", devPath.c_str(), strerror(errno)); + return ret; + } + ON_SCOPE_EXIT(closeStream) { + ClosePkgStream(pkgStream); + }; + PkgVerifyUtil verifyUtil {}; + ret = verifyUtil.VerifyPackageSigne(pkgStream); + if (ret != PKG_SUCCESS) { + PKG_LOGE("verify pkcs7 signature failed."); + return ret; + } +>>>>>>> Stashed changes return PKG_SUCCESS; } diff --git a/test/unittest/script/script_unittest.h b/test/unittest/script/script_unittest.h index 34a70a48..c5001bdf 100644 --- a/test/unittest/script/script_unittest.h +++ b/test/unittest/script/script_unittest.h @@ -51,6 +51,10 @@ public: { return PKG_SUCCESS; } + int32_t VerifyOtaPackage(const std::string &devPath, uint64_t offset, size_t size) override + { + return PKG_SUCCESS; + } int32_t VerifyBinFile(const std::string &packagePath, const std::string &keyPath, const std::string &version, const PkgBuffer &digest) override { -- Gitee From dd93a3255368c2e5bb80ba0d099d8d6dda8da4ac Mon Sep 17 00:00:00 2001 From: lidanyang Date: Wed, 24 Jul 2024 19:14:41 +0800 Subject: [PATCH 02/52] fix Signed-off-by: lidanyang --- services/include/package/pkg_manager.h | 4 +--- services/package/pkg_manager/pkg_managerImpl.cpp | 6 +++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/services/include/package/pkg_manager.h b/services/include/package/pkg_manager.h index db276550..4420287b 100644 --- a/services/include/package/pkg_manager.h +++ b/services/include/package/pkg_manager.h @@ -258,11 +258,9 @@ public: virtual int32_t LoadPackage(const std::string &packagePath, const std::string &keyPath, std::vector &fileIds) = 0; -<<<<<<< Updated upstream virtual int32_t VerifyAccPackage(const std::string &packagePath, const std::string &keyPath) = 0; -======= + virtual int32_t VerifyOtaPackage(const std::string &devPath, uint64_t offset, size_t size) = 0; ->>>>>>> Stashed changes virtual int32_t VerifyOtaPackage(const std::string &packagePath) = 0; diff --git a/services/package/pkg_manager/pkg_managerImpl.cpp b/services/package/pkg_manager/pkg_managerImpl.cpp index c4468a40..cb0eefef 100644 --- a/services/package/pkg_manager/pkg_managerImpl.cpp +++ b/services/package/pkg_manager/pkg_managerImpl.cpp @@ -965,7 +965,6 @@ void PkgManagerImpl::PostDecodeProgress(int type, size_t writeDataLen, const voi } } -<<<<<<< Updated upstream int32_t PkgManagerImpl::VerifyAccPackage(const std::string &packagePath, const std::string &keyPath) { PkgStreamPtr pkgStream = nullptr; @@ -988,7 +987,9 @@ int32_t PkgManagerImpl::VerifyAccPackage(const std::string &packagePath, const s } ClosePkgStream(pkgStream); -======= + return PKG_SUCCESS; +} + int32_t PkgManagerImpl::VerifyOtaPackage(const std::string &devPath, uint64_t offset, size_t size) { constexpr size_t pageSize = 4096; @@ -1030,7 +1031,6 @@ int32_t PkgManagerImpl::VerifyOtaPackage(const std::string &devPath, uint64_t of PKG_LOGE("verify pkcs7 signature failed."); return ret; } ->>>>>>> Stashed changes return PKG_SUCCESS; } -- Gitee From 0565720c3fe69882225a901e2890e388fc43606a Mon Sep 17 00:00:00 2001 From: lidanyang Date: Wed, 24 Jul 2024 19:18:38 +0800 Subject: [PATCH 03/52] fix Signed-off-by: lidanyang --- services/package/pkg_manager/pkg_managerImpl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/package/pkg_manager/pkg_managerImpl.cpp b/services/package/pkg_manager/pkg_managerImpl.cpp index cb0eefef..704a0e46 100644 --- a/services/package/pkg_manager/pkg_managerImpl.cpp +++ b/services/package/pkg_manager/pkg_managerImpl.cpp @@ -15,6 +15,7 @@ #include "pkg_manager_impl.h" #include #include +#include #include #include #include @@ -25,7 +26,6 @@ #include #include #include "dump.h" -#include "inttypes.h" #include "pkg_gzipfile.h" #include "pkg_lz4file.h" #include "pkg_manager.h" -- Gitee From 7819e29c3b4d6183a881f1d658736a4a4d38f1ab Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 26 Jul 2024 19:49:29 +0800 Subject: [PATCH 04/52] add ut Signed-off-by: unknown --- .../updater_ui_env_unittest.cpp | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 test/unittest/updater_ui_test/updater_ui_env_unittest.cpp diff --git a/test/unittest/updater_ui_test/updater_ui_env_unittest.cpp b/test/unittest/updater_ui_test/updater_ui_env_unittest.cpp new file mode 100644 index 00000000..ee8cce9e --- /dev/null +++ b/test/unittest/updater_ui_test/updater_ui_env_unittest.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include "updater_ui_env.h" +#include +#include +#include +#include +#include +#include "callback_manager.h" +#include "common/graphic_startup.h" +#include "common/screen.h" +#include "components/root_view.h" +#include "graphic_engine.h" +#include "input_event.h" +#include "language/language_ui.h" +#include "log/log.h" +#include "page/page_manager.h" +#include "updater_ui_config.h" + +using namespace testing::ext; +using namespace Updater; + +namespace UpdaterUt { +class UpdaterUiEnvUnitTest : public testing::Test { +public: + static void SetUpTestCase(void) {} + static void TearDownTestCase(void) {} + void SetUp() override {} + void TearDown() override {} +}; + +constexpr std::pair MY_BRIGHTNESS_FILE = + std::pair { "/data/updater/ui/brightness", "/data/updater/ui/max_brightness" }; + +HWTEST_F(UpdaterUiEnvUnitTest, test_updater_ui_env_bright_init, TestSize.Level0) +{ + EXPECT_FALSE(UpdaterUiEnv::InitBrightness("/fakebrightness", "/fakemaxbrightness")); + EXPECT_FALSE(UpdaterUiEnv::InitBrightness(MY_BRIGHTNESS_FILE.first, "/fakemaxbrightness")); + EXPECT_TRUE(UpdaterUiEnv::InitBrightness(MY_BRIGHTNESS_FILE.first, MY_BRIGHTNESS_FILE.second)); +} +} \ No newline at end of file -- Gitee From a337a4641c5b550a5963bab2b7f521fe879b5324 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 26 Jul 2024 19:49:29 +0800 Subject: [PATCH 05/52] add ut Signed-off-by: unknown --- .../updater_ui_env_unittest.cpp | 55 +++++++++++++ .../updater_ui_facade_unittest.cpp | 78 +++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 test/unittest/updater_ui_test/updater_ui_env_unittest.cpp create mode 100644 test/unittest/updater_ui_test/updater_ui_facade_unittest.cpp diff --git a/test/unittest/updater_ui_test/updater_ui_env_unittest.cpp b/test/unittest/updater_ui_test/updater_ui_env_unittest.cpp new file mode 100644 index 00000000..ee8cce9e --- /dev/null +++ b/test/unittest/updater_ui_test/updater_ui_env_unittest.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include "updater_ui_env.h" +#include +#include +#include +#include +#include +#include "callback_manager.h" +#include "common/graphic_startup.h" +#include "common/screen.h" +#include "components/root_view.h" +#include "graphic_engine.h" +#include "input_event.h" +#include "language/language_ui.h" +#include "log/log.h" +#include "page/page_manager.h" +#include "updater_ui_config.h" + +using namespace testing::ext; +using namespace Updater; + +namespace UpdaterUt { +class UpdaterUiEnvUnitTest : public testing::Test { +public: + static void SetUpTestCase(void) {} + static void TearDownTestCase(void) {} + void SetUp() override {} + void TearDown() override {} +}; + +constexpr std::pair MY_BRIGHTNESS_FILE = + std::pair { "/data/updater/ui/brightness", "/data/updater/ui/max_brightness" }; + +HWTEST_F(UpdaterUiEnvUnitTest, test_updater_ui_env_bright_init, TestSize.Level0) +{ + EXPECT_FALSE(UpdaterUiEnv::InitBrightness("/fakebrightness", "/fakemaxbrightness")); + EXPECT_FALSE(UpdaterUiEnv::InitBrightness(MY_BRIGHTNESS_FILE.first, "/fakemaxbrightness")); + EXPECT_TRUE(UpdaterUiEnv::InitBrightness(MY_BRIGHTNESS_FILE.first, MY_BRIGHTNESS_FILE.second)); +} +} \ No newline at end of file diff --git a/test/unittest/updater_ui_test/updater_ui_facade_unittest.cpp b/test/unittest/updater_ui_test/updater_ui_facade_unittest.cpp new file mode 100644 index 00000000..69dc7a48 --- /dev/null +++ b/test/unittest/updater_ui_test/updater_ui_facade_unittest.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include "component/text_label_adapter.h" +#include "updater_event.h" +#include "updater_ui_config.h" +#include "updater_ui_env.h" +#include "updater_ui_tools.h" + +using namespace testing::ext; +using namespace Updater; + +#define UPDATER_UI_INSTANCE UpdaterUiFacade::GetInstance() + +namespace UpdaterUt { +class UpdaterUiFacadeUnitTest : public testing::Test { +public: + static void SetUpTestCase(void) {} + static void TearDownTestCase(void) {} + void SetUp() override {} + void TearDown() override {} +}; + +HWTEST_F(UpdaterUiFacadeUnitTest, test_updater_ui_facade_set_mode, Test.Level0) +{ + std::string mode = "abc"; + EXPECT_TRUE(UPDATER_UI_INSTANCE.SetMode("")); + EXPECT_TRUE(UPDATER_UI_INSTANCE.SetMode(mode)); + EXPECT_EQ(UPDATER_UI_INSTANCE.GetMode(), mode); +} + +HWTEST_F(UpdaterUiFacadeUnitTest, test_updater_ui_facade_show_funcs, Test.Level0) +{ + std::string log = "log"; + UPDATER_UI_INSTANCE.ShowLog(log); + UPDATER_UI_INSTANCE.ShowLogRes(log); + UPDATER_UI_INSTANCE.ShowUpdInfo(log); + UPDATER_UI_INSTANCE.ClearText(); + UPDATER_UI_INSTANCE.ClearLog(); + UPDATER_UI_INSTANCE.ShowProgress(0.0); + UPDATER_UI_INSTANCE.ShowProgressPage(); + UPDATER_UI_INSTANCE.ShowSuccessPage(); + UPDATER_UI_INSTANCE.ShowFailedPage(); + UPDATER_UI_INSTANCE.ShowFactoryConfirmPage(); + UPDATER_UI_INSTANCE.ShowMainpage(); + UPDATER_UI_INSTANCE.ShowProgressWarning(false); + EXPECT_FALSE(UPDATER_UI_INSTANCE.IsInProgress()); + EXPECT_TRUE(UPDATER_UI_INSTANCE.SetMode("ota")); + UPDATER_UI_INSTANCE.ShowLog(log); + UPDATER_UI_INSTANCE.ShowLog(log, true); + UPDATER_UI_INSTANCE.ShowLogRes(log); + UPDATER_UI_INSTANCE.ShowUpdInfo(log); + UPDATER_UI_INSTANCE.ClearText(); + UPDATER_UI_INSTANCE.ClearLog(); + UPDATER_UI_INSTANCE.ShowProgress(0.0); + UPDATER_UI_INSTANCE.ShowProgressPage(); + UPDATER_UI_INSTANCE.ShowSuccessPage(); + UPDATER_UI_INSTANCE.ShowFailedPage(); + UPDATER_UI_INSTANCE.ShowFactoryConfirmPage(); + UPDATER_UI_INSTANCE.ShowMainpage(); + UPDATER_UI_INSTANCE.ShowProgressWarning(false); + EXPECT_TRUE(UPDATER_UI_INSTANCE.IsInProgress()); +} +} \ No newline at end of file -- Gitee From d8bbe8344b5b270d502e27e96f87f9d25ff93367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=87=AF?= Date: Thu, 1 Aug 2024 03:14:35 +0000 Subject: [PATCH 06/52] update services/factory_reset/factory_reset.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陈凯 --- services/factory_reset/factory_reset.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/services/factory_reset/factory_reset.cpp b/services/factory_reset/factory_reset.cpp index 570690c9..9451018a 100644 --- a/services/factory_reset/factory_reset.cpp +++ b/services/factory_reset/factory_reset.cpp @@ -46,27 +46,27 @@ int FactoryResetProcess::FactoryResetFunc(FactoryResetMode mode, const std::stri LOG(ERROR) << "Invalid factory reset tag: " << mode; return 1; } - if (CommonResetPreFunc_ == nullptr || - CommonResetPreFunc_(mode == MENU_WIPE_DATA || mode == FACTORY_WIPE_DATA) != 0) { - LOG(ERROR) << "Failed to erase the security status"; - return -1; - } if (iter->second(path) != 0) { LOG(ERROR) << "Do factory reset failed! tag: " << mode; return 1; } + if (CommonResetPostFunc_ == nullptr || + CommonResetPostFunc_(mode == MENU_WIPE_DATA || mode == FACTORY_WIPE_DATA) != 0) { + LOG(ERROR) << "Failed to erase the security status"; + return -1; + } return 0; } -static int CommonResetPre(bool flag) +static int CommonResetPost(bool flag) { - LOG(INFO) << "CommonResetPre"; + LOG(INFO) << "CommonResetPost"; return 0; } -void FactoryResetProcess::RegisterCommonResetPreFunc(CommonResetPreFunc ptr) +void FactoryResetProcess::RegisterCommonResetPostFunc(CommonResetPostFunc ptr) { - CommonResetPreFunc_ = std::move(ptr); + CommonResetPostFunc_ = std::move(ptr); } static int FactoryResetPre() @@ -128,9 +128,9 @@ int FactoryResetProcess::DoFactoryReset(const std::string &path) return resetStatus; } -extern "C" __attribute__((constructor)) void RegisterCommonResetPreFunc(void) +extern "C" __attribute__((constructor)) void RegisterCommonResetPostFunc(void) { - FactoryResetProcess::GetInstance().RegisterCommonResetPreFunc(CommonResetPre); + FactoryResetProcess::GetInstance().RegisterCommonResetPostFunc(CommonResetPost); } extern "C" __attribute__((constructor)) void RegisterFactoryResetPreFunc(void) -- Gitee From 771b6c411a4de1738e3b5f0d64678b9a8c9030c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=87=AF?= Date: Thu, 1 Aug 2024 03:15:45 +0000 Subject: [PATCH 07/52] update services/factory_reset/factory_reset.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陈凯 --- services/factory_reset/factory_reset.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/factory_reset/factory_reset.h b/services/factory_reset/factory_reset.h index 192df9cc..053631f8 100644 --- a/services/factory_reset/factory_reset.h +++ b/services/factory_reset/factory_reset.h @@ -22,7 +22,7 @@ #include "updater_main.h" namespace Updater { -using CommonResetPreFunc = std::function; +using CommonResetPostFunc = std::function; using FactoryResetPreFunc = std::function; using FactoryResetPostFunc = std::function; class FactoryResetProcess { @@ -33,13 +33,13 @@ public: static FactoryResetProcess &GetInstance(); using ResetFunc = std::function; - void RegisterCommonResetPreFunc(CommonResetPreFunc ptr); + void RegisterCommonResetPostFunc(CommonResetPostFunc ptr); void RegisterFactoryResetPreFunc(FactoryResetPreFunc ptr); void RegisterFactoryResetPostFunc(FactoryResetPostFunc ptr); int FactoryResetFunc(FactoryResetMode mode, const std::string &path); private: - CommonResetPreFunc CommonResetPreFunc_ = nullptr; + CommonResetPostFunc CommonResetPostFunc_ = nullptr; FactoryResetPreFunc FactoryResetPreFunc_ = nullptr; FactoryResetPostFunc FactoryResetPostFunc_ = nullptr; std::unordered_map resetTab_; -- Gitee From 1e36903e39953eedc8a1241607bab12f043a1e23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=87=AF?= Date: Fri, 2 Aug 2024 03:19:44 +0000 Subject: [PATCH 08/52] update services/factory_reset/factory_reset.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陈凯 --- services/factory_reset/factory_reset.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/services/factory_reset/factory_reset.cpp b/services/factory_reset/factory_reset.cpp index 9451018a..88c6ebc7 100644 --- a/services/factory_reset/factory_reset.cpp +++ b/services/factory_reset/factory_reset.cpp @@ -17,6 +17,7 @@ #include "log/dump.h" #include "log/log.h" #include "fs_manager/mount.h" +#include "scope_guard.h" namespace Updater { FactoryResetProcess &FactoryResetProcess::GetInstance() @@ -46,13 +47,21 @@ int FactoryResetProcess::FactoryResetFunc(FactoryResetMode mode, const std::stri LOG(ERROR) << "Invalid factory reset tag: " << mode; return 1; } - if (iter->second(path) != 0) { + int resetStatus = iter->second(path); + ON_SCOPE_EXIT(factoryResetPost) { + if (mode == FACTORY_WIPE_DATA && + (FactoryResetPostFunc_ == nullptr || FactoryResetPostFunc_(resetStatus) != 0)) { + LOG(ERROR) << "FactoryResetPostFunc_ fail"; + } + }; + if (resetStatus != 0) { LOG(ERROR) << "Do factory reset failed! tag: " << mode; return 1; } if (CommonResetPostFunc_ == nullptr || CommonResetPostFunc_(mode == MENU_WIPE_DATA || mode == FACTORY_WIPE_DATA) != 0) { - LOG(ERROR) << "Failed to erase the security status"; + resetStatus = 1; + LOG(ERROR) << "CommonResetPostFunc_ fail"; return -1; } return 0; @@ -122,9 +131,6 @@ int FactoryResetProcess::DoFactoryReset(const std::string &path) } LOG(INFO) << "Factory level FactoryReset status:" << resetStatus; - if (FactoryResetPostFunc_ == nullptr || FactoryResetPostFunc_(resetStatus) != 0) { - LOG(ERROR) << "FactoryResetPostFunc_ fail"; - } return resetStatus; } -- Gitee From b042089fc7bb6c4b71c17a83363c91fdc60c0dd5 Mon Sep 17 00:00:00 2001 From: LeonShu Date: Mon, 5 Aug 2024 10:07:15 +0800 Subject: [PATCH 09/52] Signed-off-by: LeonShu --- test/unittest/updater_ui_test/BUILD.gn | 2 + .../control/ui_control_unittest.cpp | 71 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 test/unittest/updater_ui_test/control/ui_control_unittest.cpp diff --git a/test/unittest/updater_ui_test/BUILD.gn b/test/unittest/updater_ui_test/BUILD.gn index 1471027f..559ed68f 100644 --- a/test/unittest/updater_ui_test/BUILD.gn +++ b/test/unittest/updater_ui_test/BUILD.gn @@ -32,6 +32,7 @@ ohos_unittest("ui_unittest") { "ENABLE_VECTOR_FONT = 1", ] sources = [ + "control/ui_control_unittest.cpp", "driver/fbdev_driver_unittest.cpp", "driver/keys_input_device_unittest.cpp", "driver/pointers_input_device_unittest.cpp", @@ -46,6 +47,7 @@ ohos_unittest("ui_unittest") { "view/ui_view_proxy_unittest.cpp", ] sources += [ + "${updater_path}/services/ui/control/event_listener.cpp", "${updater_path}/services/ui/driver/drm_driver.cpp", "${updater_path}/services/ui/driver/fbdev_driver.cpp", "${updater_path}/services/ui/driver/graphic_engine.cpp", diff --git a/test/unittest/updater_ui_test/control/ui_control_unittest.cpp b/test/unittest/updater_ui_test/control/ui_control_unittest.cpp new file mode 100644 index 00000000..e3a08fd8 --- /dev/null +++ b/test/unittest/updater_ui_test/control/ui_control_unittest.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include "event_listener.h" +#include +#include "dock/input_device.h" + +using namespace testing::ext; +using namespace Updater; + +namespace { +class UpdaterUiControlUnittest : public testing::Test { +public: + KeyListener *keyListener; + OHOS::UIView *view; + + static void SetUpTestCase(void) {} + static void TearDownTestCase(void) {} + void SetUp() override + { + keyListener = new KeyListener(); + view = new OHOS::UIView(); + } + void TearDown() override + { + delete keyListener; + delete view; + } +}; + +HWTEST_F(UpdaterUiControlUnittest, OnKeyAct01, TestSize.Level0) +{ + OHOS::KeyEvent *event = new OHOS::KeyEvent(KEY_POWER, OHOS::InputDevice::STATE_PRESS); + bool ret = keyListenet->OnKeyAct(*view, *event); + EXPECT_EQ(ret true); +} + +HWTEST_F(UpdaterUiControlUnittest, OnKeyAct02, TestSize.Level0) +{ + OHOS::KeyEvent *event = new OHOS::KeyEvent(KEY_VOLUMEUP, OHOS::InputDevice::STATE_PRESS); + bool ret = keyListenet->OnKeyAct(*view, *event); + EXPECT_EQ(ret true); +} + +HWTEST_F(UpdaterUiControlUnittest, OnKeyAct03, TestSize.Level0) +{ + OHOS::KeyEvent *event = new OHOS::KeyEvent(KEY_VOLUMEDOWN, OHOS::InputDevice::STATE_PRESS); + bool ret = keyListenet->OnKeyAct(*view, *event); + EXPECT_EQ(ret true); +} + +HWTEST_F(UpdaterUiControlUnittest, OnKeyAct04, TestSize.Level0) +{ + OHOS::KeyEvent *event = new OHOS::KeyEvent(100, OHOS::InputDevice::STATE_PRESS); + bool ret = keyListenet->OnKeyAct(*view, *event); + EXPECT_EQ(ret true); +} +} \ No newline at end of file -- Gitee From 60236aa8dd8bda54f373e1b17556aa18e6120130 Mon Sep 17 00:00:00 2001 From: LeonShu Date: Mon, 5 Aug 2024 10:29:55 +0800 Subject: [PATCH 10/52] Signed-off-by: LeonShu --- .../updater_ui_test/control/ui_control_unittest.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/unittest/updater_ui_test/control/ui_control_unittest.cpp b/test/unittest/updater_ui_test/control/ui_control_unittest.cpp index e3a08fd8..c2506d8e 100644 --- a/test/unittest/updater_ui_test/control/ui_control_unittest.cpp +++ b/test/unittest/updater_ui_test/control/ui_control_unittest.cpp @@ -37,35 +37,37 @@ public: void TearDown() override { delete keyListener; + keyListener = nullptr; delete view; + view = nullptr; } }; HWTEST_F(UpdaterUiControlUnittest, OnKeyAct01, TestSize.Level0) { OHOS::KeyEvent *event = new OHOS::KeyEvent(KEY_POWER, OHOS::InputDevice::STATE_PRESS); - bool ret = keyListenet->OnKeyAct(*view, *event); + bool ret = keyListener->OnKeyAct(*view, *event); EXPECT_EQ(ret true); } HWTEST_F(UpdaterUiControlUnittest, OnKeyAct02, TestSize.Level0) { OHOS::KeyEvent *event = new OHOS::KeyEvent(KEY_VOLUMEUP, OHOS::InputDevice::STATE_PRESS); - bool ret = keyListenet->OnKeyAct(*view, *event); + bool ret = keyListener->OnKeyAct(*view, *event); EXPECT_EQ(ret true); } HWTEST_F(UpdaterUiControlUnittest, OnKeyAct03, TestSize.Level0) { OHOS::KeyEvent *event = new OHOS::KeyEvent(KEY_VOLUMEDOWN, OHOS::InputDevice::STATE_PRESS); - bool ret = keyListenet->OnKeyAct(*view, *event); + bool ret = keyListener->OnKeyAct(*view, *event); EXPECT_EQ(ret true); } HWTEST_F(UpdaterUiControlUnittest, OnKeyAct04, TestSize.Level0) { OHOS::KeyEvent *event = new OHOS::KeyEvent(100, OHOS::InputDevice::STATE_PRESS); - bool ret = keyListenet->OnKeyAct(*view, *event); + bool ret = keyListener->OnKeyAct(*view, *event); EXPECT_EQ(ret true); } } \ No newline at end of file -- Gitee From ec89fa428439228984939024f8476b02fe3c301e Mon Sep 17 00:00:00 2001 From: LeonShu Date: Mon, 5 Aug 2024 10:42:58 +0800 Subject: [PATCH 11/52] Signed-off-by: LeonShu --- .../updater_ui_test/control/ui_control_unittest.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/unittest/updater_ui_test/control/ui_control_unittest.cpp b/test/unittest/updater_ui_test/control/ui_control_unittest.cpp index c2506d8e..becf17c8 100644 --- a/test/unittest/updater_ui_test/control/ui_control_unittest.cpp +++ b/test/unittest/updater_ui_test/control/ui_control_unittest.cpp @@ -47,27 +47,27 @@ HWTEST_F(UpdaterUiControlUnittest, OnKeyAct01, TestSize.Level0) { OHOS::KeyEvent *event = new OHOS::KeyEvent(KEY_POWER, OHOS::InputDevice::STATE_PRESS); bool ret = keyListener->OnKeyAct(*view, *event); - EXPECT_EQ(ret true); + EXPECT_EQ(ret, true); } HWTEST_F(UpdaterUiControlUnittest, OnKeyAct02, TestSize.Level0) { OHOS::KeyEvent *event = new OHOS::KeyEvent(KEY_VOLUMEUP, OHOS::InputDevice::STATE_PRESS); bool ret = keyListener->OnKeyAct(*view, *event); - EXPECT_EQ(ret true); + EXPECT_EQ(ret, true); } HWTEST_F(UpdaterUiControlUnittest, OnKeyAct03, TestSize.Level0) { OHOS::KeyEvent *event = new OHOS::KeyEvent(KEY_VOLUMEDOWN, OHOS::InputDevice::STATE_PRESS); bool ret = keyListener->OnKeyAct(*view, *event); - EXPECT_EQ(ret true); + EXPECT_EQ(ret, true); } HWTEST_F(UpdaterUiControlUnittest, OnKeyAct04, TestSize.Level0) { OHOS::KeyEvent *event = new OHOS::KeyEvent(100, OHOS::InputDevice::STATE_PRESS); bool ret = keyListener->OnKeyAct(*view, *event); - EXPECT_EQ(ret true); + EXPECT_EQ(ret, true); } } \ No newline at end of file -- Gitee From f92ba76ecab5d90a944db72617e39a24f281acf2 Mon Sep 17 00:00:00 2001 From: LeonShu Date: Mon, 5 Aug 2024 11:26:42 +0800 Subject: [PATCH 12/52] Signed-off-by: LeonShu --- .../control/ui_control_unittest.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/unittest/updater_ui_test/control/ui_control_unittest.cpp b/test/unittest/updater_ui_test/control/ui_control_unittest.cpp index becf17c8..91ee8883 100644 --- a/test/unittest/updater_ui_test/control/ui_control_unittest.cpp +++ b/test/unittest/updater_ui_test/control/ui_control_unittest.cpp @@ -48,6 +48,10 @@ HWTEST_F(UpdaterUiControlUnittest, OnKeyAct01, TestSize.Level0) OHOS::KeyEvent *event = new OHOS::KeyEvent(KEY_POWER, OHOS::InputDevice::STATE_PRESS); bool ret = keyListener->OnKeyAct(*view, *event); EXPECT_EQ(ret, true); + if (event != nullptr) { + delete event; + event = nullptr; + } } HWTEST_F(UpdaterUiControlUnittest, OnKeyAct02, TestSize.Level0) @@ -55,6 +59,10 @@ HWTEST_F(UpdaterUiControlUnittest, OnKeyAct02, TestSize.Level0) OHOS::KeyEvent *event = new OHOS::KeyEvent(KEY_VOLUMEUP, OHOS::InputDevice::STATE_PRESS); bool ret = keyListener->OnKeyAct(*view, *event); EXPECT_EQ(ret, true); + if (event != nullptr) { + delete event; + event = nullptr; + } } HWTEST_F(UpdaterUiControlUnittest, OnKeyAct03, TestSize.Level0) @@ -62,6 +70,10 @@ HWTEST_F(UpdaterUiControlUnittest, OnKeyAct03, TestSize.Level0) OHOS::KeyEvent *event = new OHOS::KeyEvent(KEY_VOLUMEDOWN, OHOS::InputDevice::STATE_PRESS); bool ret = keyListener->OnKeyAct(*view, *event); EXPECT_EQ(ret, true); + if (event != nullptr) { + delete event; + event = nullptr; + } } HWTEST_F(UpdaterUiControlUnittest, OnKeyAct04, TestSize.Level0) @@ -69,5 +81,9 @@ HWTEST_F(UpdaterUiControlUnittest, OnKeyAct04, TestSize.Level0) OHOS::KeyEvent *event = new OHOS::KeyEvent(100, OHOS::InputDevice::STATE_PRESS); bool ret = keyListener->OnKeyAct(*view, *event); EXPECT_EQ(ret, true); + if (event != nullptr) { + delete event; + event = nullptr; + } } } \ No newline at end of file -- Gitee From 9a70573a4f96d6dabca24bd621837e7c870d1b95 Mon Sep 17 00:00:00 2001 From: LeonShu Date: Tue, 6 Aug 2024 09:43:05 +0800 Subject: [PATCH 13/52] Signed-off-by: LeonShu --- BUILD.gn | 1 + services/factory_reset/factory_reset.h | 2 + services/updater_main.h | 1 + test/unittest/factory_reset_test/BUILD.gn | 50 +++++++++ .../factory_reset_unittest.cpp | 100 ++++++++++++++++++ 5 files changed, 154 insertions(+) create mode 100644 test/unittest/factory_reset_test/BUILD.gn create mode 100644 test/unittest/factory_reset_test/factory_reset_unittest.cpp diff --git a/BUILD.gn b/BUILD.gn index ac948c97..4c82fe12 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -43,6 +43,7 @@ group("unittest") { "test/unittest:updater_unittest", "test/unittest/applypatch_test:applypatch_unittest", "test/unittest/common/ring_buffer:ring_buffer_test", + "test/unittest/factory_reset_test:factory_reset_unittest", "test/unittest/flashd_test:flashd_unittest", "test/unittest/flashd_test:flashd_utils_unittest", "test/unittest/flow_update/update_bin:bin_flow_update_test", diff --git a/services/factory_reset/factory_reset.h b/services/factory_reset/factory_reset.h index 053631f8..9892d0ac 100644 --- a/services/factory_reset/factory_reset.h +++ b/services/factory_reset/factory_reset.h @@ -38,7 +38,9 @@ public: void RegisterFactoryResetPostFunc(FactoryResetPostFunc ptr); int FactoryResetFunc(FactoryResetMode mode, const std::string &path); +#ifndef UPDATER_UT private: +#endif CommonResetPostFunc CommonResetPostFunc_ = nullptr; FactoryResetPreFunc FactoryResetPreFunc_ = nullptr; FactoryResetPostFunc FactoryResetPostFunc_ = nullptr; diff --git a/services/updater_main.h b/services/updater_main.h index f0019166..6ff76fe1 100644 --- a/services/updater_main.h +++ b/services/updater_main.h @@ -26,6 +26,7 @@ enum FactoryResetMode { USER_WIPE_DATA = 0, FACTORY_WIPE_DATA, MENU_WIPE_DATA, + INVALID, }; int UpdaterMain(int argc, char **argv); diff --git a/test/unittest/factory_reset_test/BUILD.gn b/test/unittest/factory_reset_test/BUILD.gn new file mode 100644 index 00000000..ea3120e9 --- /dev/null +++ b/test/unittest/factory_reset_test/BUILD.gn @@ -0,0 +1,50 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//base/update/updater/updater_default_cfg.gni") +import("//build/test.gni") + +updater_path = rebase_path("${updater_absolutely_path}", ".") + +MODULE_OUTPUT_PATH = "updater/updater_test" + +ohos_unittest("factory_reset_unittest") { + defines = [ "UPDATER_UT" ] + testonly = true + module_out_path = MODULE_OUTPUT_PATH + sources = [ + "${updater_path}/services/factory_reset/factory_reset.cpp", + "factory_reset_unittest.cpp", + ] + + include_dirs = [ + "${updater_path}/utils/include", + "${updater_path}/services", + "${updater_path}/services/include", + "${updater_path}/services/include/package", + "${updater_path}/services/factory_reset/", + "${updater_path}/interfaces/kits/include/", + "${updater_path}/services/common", + ] + + deps = [ + "${updater_path}/services/fs_manager:libfsmanager", + "${updater_path}/services/log:libupdaterlog", + "${updater_path}/utils:libutils", + ] + + external_deps = [ "init:libbegetutil_static" ] + configs = [ "${updater_path}/test/unittest:utest_config" ] + install_enable = true + part_name = "updater" +} diff --git a/test/unittest/factory_reset_test/factory_reset_unittest.cpp b/test/unittest/factory_reset_test/factory_reset_unittest.cpp new file mode 100644 index 00000000..8f0c5adc --- /dev/null +++ b/test/unittest/factory_reset_test/factory_reset_unittest.cpp @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "factory_reset.h" + +using namespace Updater; +using namespace testing::ext; + +namespace { +class FactoryResetUnitTest : public testing::Test { +public: + FactoryResetUnitTest() + { + std::cout<<"FactoryResetUnitTest()"; + } + ~FactoryResetUnitTest() {} + FactoryResetProcess* factoryResetProcess; + std::unordered_map resetTab_; + std::function CommonResetPostFunc_; + + static void SetUpTestCase(void) {} + static void TearDownTestCase(void) {} + void SetUp() + { + factoryResetProcess = new FactoryResetProcess(); + factoryResetProcess->resetTab_ = resetTab_; + factoryResetProcess->CommonResetPostFunc_ = CommonResetPostFunc_; + } + void TearDown() + { + delete factoryResetProcess; + factoryResetProcess = nullptr; + } + void TestBody() {} +}; + +HWTEST_F(FactoryResetUnitTest, FactoryResetFunc01, TestSize.Level0) +{ + int ret = factoryResetProcess->GetInstance().FactoryResetFunc(FactoryResetMode::INVALID, "/data"); + EXPECT_EQ(ret, 1); +} + +HWTEST_F(FactoryResetUnitTest, FactoryResetFunc02, TestSize.Level0) +{ + resetTab_[FactoryResetMode::USER_WIPE_DATA] = [](const std::string &) { return 0; }; + int ret = factoryResetProcess->GetInstance().FactoryResetFunc(FactoryResetMode::USER_WIPE_DATA, "/data"); + EXPECT_EQ(ret, 1); +} + +HWTEST_F(FactoryResetUnitTest, FactoryResetFunc03, TestSize.Level0) +{ + CommonResetPostFunc_ = [](bool) { return 0; }; + resetTab_[FactoryResetMode::USER_WIPE_DATA] = [](const std::string &) { return 0; }; + int ret = factoryResetProcess->GetInstance().FactoryResetFunc(FactoryResetMode::USER_WIPE_DATA, "/data"); + EXPECT_EQ(ret, 1); +} + +HWTEST_F(FactoryResetUnitTest, FactoryResetFunc04, TestSize.Level0) +{ + resetTab_[FactoryResetMode::FACTORY_WIPE_DATA] = [](const std::string &) { return 0; }; + int ret = factoryResetProcess->GetInstance().FactoryResetFunc(FactoryResetMode::FACTORY_WIPE_DATA, "/data"); + EXPECT_EQ(ret, 1); +} + +HWTEST_F(FactoryResetUnitTest, FactoryResetFunc05, TestSize.Level0) +{ + CommonResetPostFunc_ = [](bool) { return 0; }; + resetTab_[FactoryResetMode::FACTORY_WIPE_DATA] = [](const std::string &) { return 0; }; + int ret = factoryResetProcess->GetInstance().FactoryResetFunc(FactoryResetMode::FACTORY_WIPE_DATA, "/data"); + EXPECT_EQ(ret, 1); +} + +HWTEST_F(FactoryResetUnitTest, FactoryResetFunc06, TestSize.Level0) +{ + resetTab_[FactoryResetMode::MENU_WIPE_DATA] = [](const std::string &) { return 0; }; + int ret = factoryResetProcess->GetInstance().FactoryResetFunc(FactoryResetMode::MENU_WIPE_DATA, "/data"); + EXPECT_EQ(ret, 1); +} + +HWTEST_F(FactoryResetUnitTest, FactoryResetFunc07, TestSize.Level0) +{ + CommonResetPostFunc_ = [](bool) { return 0; }; + resetTab_[FactoryResetMode::MENU_WIPE_DATA] = [](const std::string &) { return 0; }; + int ret = factoryResetProcess->GetInstance().FactoryResetFunc(FactoryResetMode::MENU_WIPE_DATA, "/data"); + EXPECT_EQ(ret, 1); +} +} \ No newline at end of file -- Gitee From 95e4e256f8107c9dc3b3bf868ad527035975d24b Mon Sep 17 00:00:00 2001 From: LeonShu Date: Tue, 6 Aug 2024 09:45:11 +0800 Subject: [PATCH 14/52] Signed-off-by: LeonShu --- test/unittest/updater_binary/update_partitions_unittest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/updater_binary/update_partitions_unittest.cpp b/test/unittest/updater_binary/update_partitions_unittest.cpp index 335dc230..157c727c 100755 --- a/test/unittest/updater_binary/update_partitions_unittest.cpp +++ b/test/unittest/updater_binary/update_partitions_unittest.cpp @@ -97,6 +97,6 @@ HWTEST_F(UpdatePartitionsUnitTest, UpdatePartitions_Unitest02, TestSize.Level1) delete env; ScriptManager::ReleaseScriptManager(); PkgManager::ReleasePackageInstance(pkgManager); - EXPECT_EQ(partRet, USCRIPT_ERROR_EXECUTE); + EXPECT_EQ(partRet, USCRIPT_SUCCESS); } } // namespace updater_ut -- Gitee From b994b2bc54f584955c5175949f72c50a4cc9739b Mon Sep 17 00:00:00 2001 From: LeonShu Date: Tue, 6 Aug 2024 11:26:42 +0800 Subject: [PATCH 15/52] Signed-off-by: LeonShu --- services/updater_main.h | 2 +- test/unittest/factory_reset_test/factory_reset_unittest.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/updater_main.h b/services/updater_main.h index 6ff76fe1..29e0e41e 100644 --- a/services/updater_main.h +++ b/services/updater_main.h @@ -26,7 +26,7 @@ enum FactoryResetMode { USER_WIPE_DATA = 0, FACTORY_WIPE_DATA, MENU_WIPE_DATA, - INVALID, + INVALID_MODE, }; int UpdaterMain(int argc, char **argv); diff --git a/test/unittest/factory_reset_test/factory_reset_unittest.cpp b/test/unittest/factory_reset_test/factory_reset_unittest.cpp index 8f0c5adc..25bb4e3d 100644 --- a/test/unittest/factory_reset_test/factory_reset_unittest.cpp +++ b/test/unittest/factory_reset_test/factory_reset_unittest.cpp @@ -49,7 +49,7 @@ public: HWTEST_F(FactoryResetUnitTest, FactoryResetFunc01, TestSize.Level0) { - int ret = factoryResetProcess->GetInstance().FactoryResetFunc(FactoryResetMode::INVALID, "/data"); + int ret = factoryResetProcess->GetInstance().FactoryResetFunc(FactoryResetMode::INVALID_MODE, "/data"); EXPECT_EQ(ret, 1); } -- Gitee From 0109f9e7e101092d5e1bfdb802395e4a0e437227 Mon Sep 17 00:00:00 2001 From: liaoxianyi Date: Wed, 7 Aug 2024 06:59:46 +0000 Subject: [PATCH 16/52] =?UTF-8?q?sd=E5=8D=A1=E5=8D=87=E7=BA=A7=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liaoxianyi --- services/include/updater/updater_const.h | 2 ++ services/sdcard_update/sdcard_update.cpp | 12 ++++++++++++ services/sdcard_update/sdcard_update.h | 1 + services/updater.cpp | 3 ++- services/updater_main.cpp | 4 +++- 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/services/include/updater/updater_const.h b/services/include/updater/updater_const.h index 9466c8bd..981a8991 100644 --- a/services/include/updater/updater_const.h +++ b/services/include/updater/updater_const.h @@ -51,11 +51,13 @@ constexpr const char *OTA_MODE = "update_package"; constexpr const char *USB_MODE = "usb_update"; constexpr const char *SDCARD_INTRAL_MODE = "sdcard_intral_update"; constexpr const char *UPDATRE_SCRIPT_ZIP = "/etc/updater_script.zip"; +constexpr const char *FACTORY_INTERNAL_MODE = "factory_internal_update"; // sd update ext mode constexpr const char *SDCARD_NORMAL_UPDATE = "sdUpdate"; constexpr const char *SDCARD_UPDATE_FROM_DEV = "sdUpdateFromDev"; constexpr const char *SDCARD_MAINIMG = "mainUpdate"; +constexpr const char *SDCARD_FACTORY_INTERNAL_MODE = "FactoryInternalUpdate"; #ifndef UPDATER_UT constexpr const char *SDCARD_CARD_PATH = "/sdcard/updater"; diff --git a/services/sdcard_update/sdcard_update.cpp b/services/sdcard_update/sdcard_update.cpp index ef0d4766..bc57796d 100644 --- a/services/sdcard_update/sdcard_update.cpp +++ b/services/sdcard_update/sdcard_update.cpp @@ -98,6 +98,12 @@ UpdaterStatus CheckSdcardPkgs(UpdaterParams &upParams) LOG(INFO) << "get sd card from dev succeed, skip get package from sd card"; return UPDATE_SUCCESS; } + + if (upParams.sdExtMode == SDCARD_NORMAL_UPDATE && GetFactoryInternalPkgs(upParams) == UPDATE_SUCCESS) { + LOG(INFO) << "get factory internal sdcard pkgs succeed"; + return UPDATE_SUCCESS; + } + std::string mountPoint = std::string(SDCARD_PATH); std::vector sdcardStr = GetBlockDevicesByMountPoint(mountPoint); if (sdcardStr.empty()) { @@ -125,4 +131,10 @@ UpdaterStatus CheckSdcardPkgs(UpdaterParams &upParams) } return UPDATE_SUCCESS; } + +__attribute__((weak)) UpdaterStatus GetFactoryInternalPkgs(UpdaterParams &upParams) +{ + LOG(INFO) << "not implemented get normal update sdcard pkgs"; + return UPDATE_ERROR; +} } // Updater diff --git a/services/sdcard_update/sdcard_update.h b/services/sdcard_update/sdcard_update.h index 5e607594..84f7622d 100644 --- a/services/sdcard_update/sdcard_update.h +++ b/services/sdcard_update/sdcard_update.h @@ -29,6 +29,7 @@ extern "C" { #endif UpdaterStatus GetSdcardPkgsPath(UpdaterParams &upParams); UpdaterStatus GetSdcardPkgsFromDev(UpdaterParams &upParams); +UpdaterStatus GetFactoryInternalPkgs(UpdaterParams &upParams); #ifdef __cplusplus #if __cplusplus } diff --git a/services/updater.cpp b/services/updater.cpp index 36f90f3f..5ad56223 100644 --- a/services/updater.cpp +++ b/services/updater.cpp @@ -258,7 +258,8 @@ UpdaterStatus DoInstallUpdaterPackage(PkgManager::PkgManagerPtr pkgManager, Upda } if (SetupPartitions(updateMode != SDCARD_UPDATE || upParams.sdExtMode == SDCARD_UPDATE_FROM_DEV || - Utils::CheckUpdateMode(Updater::SDCARD_INTRAL_MODE)) != 0) { + Utils::CheckUpdateMode(Updater::SDCARD_INTRAL_MODE) || + Utils::CheckUpdateMode(Updater::FACTORY_INTERNAL_MODE)) != 0) { UPDATER_UI_INSTANCE.ShowUpdInfo(TR(UPD_SETPART_FAIL), true); UPDATER_LAST_WORD(UPDATE_ERROR); return UPDATE_ERROR; diff --git a/services/updater_main.cpp b/services/updater_main.cpp index b0d12d7d..61a3b810 100644 --- a/services/updater_main.cpp +++ b/services/updater_main.cpp @@ -793,7 +793,9 @@ __attribute__((weak)) bool IsNeedWipe() void RebootAfterUpdateSuccess(const UpdaterParams &upParams) { - if (IsNeedWipe() || upParams.sdExtMode == SDCARD_UPDATE_FROM_DEV) { + if (IsNeedWipe() || + upParams.sdExtMode == SDCARD_UPDATE_FROM_DEV || + upParams.sdExtMode == SDCARD_FACTORY_INTERNAL_MODE) { Utils::UpdaterDoReboot("updater", "--user_wipe_data"); return; } -- Gitee From 179de4c8d289ed9c9b2b783ccf906917db72e12f Mon Sep 17 00:00:00 2001 From: bluesky_wang Date: Wed, 7 Aug 2024 17:51:37 +0800 Subject: [PATCH 17/52] =?UTF-8?q?Description:EMMC=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E5=8D=87=E7=BA=A7=E4=BC=98=E5=8C=96=20IssueNo:https://gitee.co?= =?UTF-8?q?m/openharmony/update=5Fupdater/issues/IAHM5N=20Binary=20Source:?= =?UTF-8?q?No=20Signed-off-by:bluesky=5Fwang=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/include/updater/updater_const.h | 2 +- services/ptable_parse/emmc_ptable.cpp | 32 +++++++++++++----------- services/ptable_parse/emmc_ptable.h | 4 +-- services/sdcard_update/sdcard_update.cpp | 6 ++--- services/sdcard_update/sdcard_update.h | 2 +- services/updater.cpp | 2 +- services/updater_main.cpp | 2 +- 7 files changed, 27 insertions(+), 23 deletions(-) diff --git a/services/include/updater/updater_const.h b/services/include/updater/updater_const.h index 981a8991..672f6383 100644 --- a/services/include/updater/updater_const.h +++ b/services/include/updater/updater_const.h @@ -57,7 +57,7 @@ constexpr const char *FACTORY_INTERNAL_MODE = "factory_internal_update"; constexpr const char *SDCARD_NORMAL_UPDATE = "sdUpdate"; constexpr const char *SDCARD_UPDATE_FROM_DEV = "sdUpdateFromDev"; constexpr const char *SDCARD_MAINIMG = "mainUpdate"; -constexpr const char *SDCARD_FACTORY_INTERNAL_MODE = "FactoryInternalUpdate"; +constexpr const char *SDCARD_UPDATE_FROM_DATA = "sdUpdateFromData"; #ifndef UPDATER_UT constexpr const char *SDCARD_CARD_PATH = "/sdcard/updater"; diff --git a/services/ptable_parse/emmc_ptable.cpp b/services/ptable_parse/emmc_ptable.cpp index 8bce4a2a..4c398ee6 100644 --- a/services/ptable_parse/emmc_ptable.cpp +++ b/services/ptable_parse/emmc_ptable.cpp @@ -123,7 +123,7 @@ bool EmmcPtable::ParsePartitionFromBuffer(uint8_t *ptbImgBuffer, const uint32_t bool EmmcPtable::ParseGptHeaderByEmmc(uint8_t *gptImage, const uint32_t len) { GPTHeaderInfo gptHeaderInfo; - uint32_t blockSize = ptableData_.blockSize; // 4096 + uint32_t blockSize = EMMC_BLOCK_SIZE; (void)memset_s(&gptHeaderInfo, sizeof(GPTHeaderInfo), 0, sizeof(GPTHeaderInfo)); if (!GetPartitionGptHeaderInfo(gptImage + blockSize, blockSize, gptHeaderInfo)) { LOG(ERROR) << "GetPartitionGptHeaderInfo fail"; @@ -138,9 +138,15 @@ bool EmmcPtable::ParseGptHeaderByEmmc(uint8_t *gptImage, const uint32_t len) return PartitionCheckGptHeader(gptImage, len, lbaNum, blockSize, gptHeaderInfo); } -bool EmmcPtable::EmmcReadGpt(uint8_t *ptableData) +bool EmmcPtable::EmmcReadGpt(uint8_t *ptableData, uint32_t len) { uint32_t number = 0; + + partitionInfo_.clear(); + if (!ParseGptHeaderByEmmc(emmcPtnDataInfo_.data, len)) { + LOG(ERROR) << "Primary signature invalid"; + return false; + } for (uint32_t i = 0; i < MAX_PARTITION_NUM; i++) { uint8_t *startLbaOffset = ptableData + GPT_PARTITION_START_LBA_OFFSET; uint8_t *endLbaOffset = ptableData + GPT_PARTITION_START_LBA_OFFSET + GPT_PARTITION_END_LBA_OFFSET; @@ -159,6 +165,8 @@ bool EmmcPtable::EmmcReadGpt(uint8_t *ptableData) LOG(ERROR) << "memcpy guid fail"; } newPtnInfo.startAddr = startLba * LBA_LENGTH; + newPtnInfo.writePath = MMC_BLOCK_DEV_NAME; + newPtnInfo.writeMode = "WRITE_RAW"; /* General algorithm : calculate partition size by lba */ newPtnInfo.partitionSize = (endLba - startLba + 1) * LBA_LENGTH; ptableData += GPT_PARTITION_INFO_LENGTH; @@ -176,7 +184,7 @@ bool EmmcPtable::UpdateCommInitializeGptPartition(uint8_t *gptImage, const uint3 return false; } uint32_t imgBlockSize = ptableData_.lbaLen; // 512 - uint32_t deviceBlockSize = ptableData_.blockSize; // 4096 + uint32_t deviceBlockSize = EMMC_BLOCK_SIZE; uint8_t *gptHeaderStart = gptImage + imgBlockSize; uint8_t *ptableData = gptImage + PROTECTIVE_MBR_SIZE + LBA_LENGTH; /* skip MBR and gpt header */ @@ -204,14 +212,10 @@ bool EmmcPtable::UpdateCommInitializeGptPartition(uint8_t *gptImage, const uint3 return false; } emmcPtnDataInfo_.writeDataLen = len; - if (!ParseGptHeaderByEmmc(emmcPtnDataInfo_.data, len)) { - LOG(ERROR) << "Primary signature invalid"; - return false; - } EmmcPatchGptHeader(emmcPtnDataInfo_, deviceBlockSize); emmcPtnDataInfo_.isGptVaild = true; - return EmmcReadGpt(ptableData); + return EmmcReadGpt(emmcPtnDataInfo_.data + 2 * deviceBlockSize, len); // 2: skip 2 lba length to set gpt entry } bool EmmcPtable::ReadEmmcGptImageToRam() @@ -224,7 +228,7 @@ bool EmmcPtable::ReadEmmcGptImageToRam() int32_t imgLen = GPT_PARTITION_SIZE; auto buf = std::make_unique(imgLen); uint8_t *buffer = buf.get(); - uint32_t deviceBlockSize = ptableData_.blockSize; // 4096 + uint32_t deviceBlockSize = EMMC_BLOCK_SIZE; if (buffer == nullptr) { LOG(ERROR) << "new buffer failed!"; return false; @@ -251,7 +255,7 @@ bool EmmcPtable::ReadEmmcGptImageToRam() emmcPtnDataInfo_.isGptVaild = true; uint8_t *ptableData = buffer + 2 * deviceBlockSize; /* skip MBR and gpt header */ - return EmmcReadGpt(ptableData); + return EmmcReadGpt(ptableData, imgLen); } bool EmmcPtable::LoadPtableFromDevice() @@ -282,7 +286,7 @@ bool EmmcPtable::GetPtableImageBuffer(uint8_t *imageBuf, const uint32_t imgBufSi bool EmmcPtable::EditPartitionBuf(uint8_t *imageBuf, uint64_t imgBufSize, std::vector &modifyList) { - if (imageBuf == nullptr || imgBufSize == 0 || modifyList.empty() == 0) { + if (imageBuf == nullptr || imgBufSize == 0 || modifyList.empty()) { LOG(ERROR) << "input invalid"; return false; } @@ -291,9 +295,9 @@ bool EmmcPtable::EditPartitionBuf(uint8_t *imageBuf, uint64_t imgBufSize, std::v uint8_t *gptHeader = gptImage + imgBlockSize; uint32_t maxPtnCnt = GET_LWORD_FROM_BYTE(&gptHeader[PARTITION_COUNT_OFFSET]); uint32_t ptnEntrySize = GET_LWORD_FROM_BYTE(&gptHeader[PENTRY_SIZE_OFFSET]); - uint32_t gptHeaderLen = EMMC_BLOCK_SIZE; - uint32_t gptSize = static_cast(maxPtnCnt) * ptnEntrySize + imgBlockSize + gptHeaderLen; - uint32_t devDensity = GetDeviceCapacity(); + uint64_t gptHeaderLen = EMMC_BLOCK_SIZE; + uint64_t gptSize = static_cast(maxPtnCnt) * ptnEntrySize + imgBlockSize + gptHeaderLen; + uint64_t devDensity = GetDeviceCapacity(); if (devDensity == 0) { LOG(ERROR) << "get emmc capacity fail"; return false; diff --git a/services/ptable_parse/emmc_ptable.h b/services/ptable_parse/emmc_ptable.h index fcec50f7..60963db1 100644 --- a/services/ptable_parse/emmc_ptable.h +++ b/services/ptable_parse/emmc_ptable.h @@ -42,7 +42,7 @@ private: static constexpr uint32_t LBA_LENGTH = 512; static constexpr uint32_t GPT_PARTITION_INFO_LENGTH = 128; static constexpr uint32_t PROTECTIVE_MBR_SIZE = 512; - static constexpr uint32_t MIN_EMMC_WRITE_SIZE = 4096; + static constexpr uint32_t MIN_EMMC_WRITE_SIZE = 512; static constexpr uint32_t EMMC_BLOCK_SIZE = 512; struct EmmcPartitionDataInfo { @@ -53,7 +53,7 @@ private: struct EmmcPartitionDataInfo emmcPtnDataInfo_; - bool EmmcReadGpt(uint8_t *ptableData); + bool EmmcReadGpt(uint8_t *ptableData, uint32_t len); bool UpdateCommInitializeGptPartition(uint8_t *gptImage, const uint32_t len); bool ReadEmmcGptImageToRam(); uint64_t GetDeviceCapacity(); diff --git a/services/sdcard_update/sdcard_update.cpp b/services/sdcard_update/sdcard_update.cpp index bc57796d..f13bf526 100644 --- a/services/sdcard_update/sdcard_update.cpp +++ b/services/sdcard_update/sdcard_update.cpp @@ -99,8 +99,8 @@ UpdaterStatus CheckSdcardPkgs(UpdaterParams &upParams) return UPDATE_SUCCESS; } - if (upParams.sdExtMode == SDCARD_NORMAL_UPDATE && GetFactoryInternalPkgs(upParams) == UPDATE_SUCCESS) { - LOG(INFO) << "get factory internal sdcard pkgs succeed"; + if (GetSdcardInternalPkgs(upParams) == UPDATE_SUCCESS) { + LOG(INFO) << "get sdcard internal pkgs succeed"; return UPDATE_SUCCESS; } @@ -132,7 +132,7 @@ UpdaterStatus CheckSdcardPkgs(UpdaterParams &upParams) return UPDATE_SUCCESS; } -__attribute__((weak)) UpdaterStatus GetFactoryInternalPkgs(UpdaterParams &upParams) +__attribute__((weak)) UpdaterStatus GetSdcardInternalPkgs(UpdaterParams &upParams) { LOG(INFO) << "not implemented get normal update sdcard pkgs"; return UPDATE_ERROR; diff --git a/services/sdcard_update/sdcard_update.h b/services/sdcard_update/sdcard_update.h index 84f7622d..9f238b03 100644 --- a/services/sdcard_update/sdcard_update.h +++ b/services/sdcard_update/sdcard_update.h @@ -29,7 +29,7 @@ extern "C" { #endif UpdaterStatus GetSdcardPkgsPath(UpdaterParams &upParams); UpdaterStatus GetSdcardPkgsFromDev(UpdaterParams &upParams); -UpdaterStatus GetFactoryInternalPkgs(UpdaterParams &upParams); +UpdaterStatus GetSdcardInternalPkgs(UpdaterParams &upParams); #ifdef __cplusplus #if __cplusplus } diff --git a/services/updater.cpp b/services/updater.cpp index 5ad56223..2bf70ddd 100644 --- a/services/updater.cpp +++ b/services/updater.cpp @@ -258,7 +258,7 @@ UpdaterStatus DoInstallUpdaterPackage(PkgManager::PkgManagerPtr pkgManager, Upda } if (SetupPartitions(updateMode != SDCARD_UPDATE || upParams.sdExtMode == SDCARD_UPDATE_FROM_DEV || - Utils::CheckUpdateMode(Updater::SDCARD_INTRAL_MODE) || + upParams.sdExtMode == SDCARD_UPDATE_FROM_DATA || Utils::CheckUpdateMode(Updater::SDCARD_INTRAL_MODE) || Utils::CheckUpdateMode(Updater::FACTORY_INTERNAL_MODE)) != 0) { UPDATER_UI_INSTANCE.ShowUpdInfo(TR(UPD_SETPART_FAIL), true); UPDATER_LAST_WORD(UPDATE_ERROR); diff --git a/services/updater_main.cpp b/services/updater_main.cpp index 61a3b810..a3e85267 100644 --- a/services/updater_main.cpp +++ b/services/updater_main.cpp @@ -795,7 +795,7 @@ void RebootAfterUpdateSuccess(const UpdaterParams &upParams) { if (IsNeedWipe() || upParams.sdExtMode == SDCARD_UPDATE_FROM_DEV || - upParams.sdExtMode == SDCARD_FACTORY_INTERNAL_MODE) { + upParams.sdExtMode == SDCARD_UPDATE_FROM_DATA) { Utils::UpdaterDoReboot("updater", "--user_wipe_data"); return; } -- Gitee From 3e38d5f3a2049b1e33d0ddfdc6fedc2cc4844649 Mon Sep 17 00:00:00 2001 From: like2001 Date: Fri, 9 Aug 2024 17:15:10 +0800 Subject: [PATCH 18/52] =?UTF-8?q?=E5=B7=AE=E5=88=86=E5=8D=87=E7=BA=A7?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: like2001 --- .../updater_binary/update_image_block.cpp | 20 +++++++++++-------- services/updater_binary/update_image_block.h | 1 + 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/services/updater_binary/update_image_block.cpp b/services/updater_binary/update_image_block.cpp index 4530b324..2bbcfcb5 100644 --- a/services/updater_binary/update_image_block.cpp +++ b/services/updater_binary/update_image_block.cpp @@ -471,19 +471,23 @@ int32_t UScriptInstructionBlockCheck::Execute(Uscript::UScriptEnv &env, Uscript: return USCRIPT_SUCCESS; } +bool UScriptInstructionShaCheck::IsTargetShaDiff(const std::string &devPath, const ShaInfo &shaInfo) +{ + std::string tgtResultSha = CalculateBlockSha(devPath, shaInfo.targetPairs); + if (tgtResultSha.empty()) { + LOG(WARNING) << "target sha is empty"; + return true; + } + LOG(INFO) << "tgtResultSha: " << tgtResultSha << " shaInfo.targetSha: " << shaInfo.targetSha; + return (tgtResultSha != shaInfo.targetSha); +} + int UScriptInstructionShaCheck::ExecReadShaInfo(Uscript::UScriptEnv &env, const std::string &devPath, const ShaInfo &shaInfo) { UPDATER_INIT_RECORD; std::string resultSha = CalculateBlockSha(devPath, shaInfo.blockPairs); - std::string tgtResultSha = CalculateBlockSha(devPath, shaInfo.targetPairs); - if (resultSha.empty() && tgtResultSha.empty()) { - LOG(ERROR) << "All sha is empty"; - return USCRIPT_ERROR_EXECUTE; - } - - bool isTargetDiff = tgtResultSha.empty() ? true : (tgtResultSha != shaInfo.targetSha); - if (resultSha != shaInfo.contrastSha && isTargetDiff) { + if (resultSha != shaInfo.contrastSha && IsTargetShaDiff()) { LOG(ERROR) << "Different sha256, cannot continue"; LOG(ERROR) << "blockPairs:" << shaInfo.blockPairs; PrintAbnormalBlockHash(devPath, shaInfo.blockPairs); diff --git a/services/updater_binary/update_image_block.h b/services/updater_binary/update_image_block.h index 2006b5ae..fe2e39bd 100644 --- a/services/updater_binary/update_image_block.h +++ b/services/updater_binary/update_image_block.h @@ -53,6 +53,7 @@ private: void PrintAbnormalBlockHash(const std::string &devPath, const std::string &blockPairs); std::string CalculateBlockSha(const std::string &devPath, const std::string &blockPairs); int32_t SetShaInfo(Uscript::UScriptContext &context, ShaInfo &shaInfo); + bool IsTargetShaDiff(const std::string &devPath, const ShaInfo &shaInfo); }; } -- Gitee From f354ab55223f06a90035be58de00c3bb567ea66f Mon Sep 17 00:00:00 2001 From: like2001 Date: Fri, 9 Aug 2024 17:15:10 +0800 Subject: [PATCH 19/52] =?UTF-8?q?=E5=B7=AE=E5=88=86=E5=8D=87=E7=BA=A7?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: like2001 --- .../updater_binary/update_image_block.cpp | 20 +++++++++++-------- services/updater_binary/update_image_block.h | 1 + 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/services/updater_binary/update_image_block.cpp b/services/updater_binary/update_image_block.cpp index 4530b324..5b902dd2 100644 --- a/services/updater_binary/update_image_block.cpp +++ b/services/updater_binary/update_image_block.cpp @@ -471,19 +471,23 @@ int32_t UScriptInstructionBlockCheck::Execute(Uscript::UScriptEnv &env, Uscript: return USCRIPT_SUCCESS; } +bool UScriptInstructionShaCheck::IsTargetShaDiff(const std::string &devPath, const ShaInfo &shaInfo) +{ + std::string tgtResultSha = CalculateBlockSha(devPath, shaInfo.targetPairs); + if (tgtResultSha.empty()) { + LOG(WARNING) << "target sha is empty"; + return true; + } + LOG(INFO) << "tgtResultSha: " << tgtResultSha << " shaInfo.targetSha: " << shaInfo.targetSha; + return (tgtResultSha != shaInfo.targetSha); +} + int UScriptInstructionShaCheck::ExecReadShaInfo(Uscript::UScriptEnv &env, const std::string &devPath, const ShaInfo &shaInfo) { UPDATER_INIT_RECORD; std::string resultSha = CalculateBlockSha(devPath, shaInfo.blockPairs); - std::string tgtResultSha = CalculateBlockSha(devPath, shaInfo.targetPairs); - if (resultSha.empty() && tgtResultSha.empty()) { - LOG(ERROR) << "All sha is empty"; - return USCRIPT_ERROR_EXECUTE; - } - - bool isTargetDiff = tgtResultSha.empty() ? true : (tgtResultSha != shaInfo.targetSha); - if (resultSha != shaInfo.contrastSha && isTargetDiff) { + if (resultSha != shaInfo.contrastSha && IsTargetShaDiff(devPath, shaInfo)) { LOG(ERROR) << "Different sha256, cannot continue"; LOG(ERROR) << "blockPairs:" << shaInfo.blockPairs; PrintAbnormalBlockHash(devPath, shaInfo.blockPairs); diff --git a/services/updater_binary/update_image_block.h b/services/updater_binary/update_image_block.h index 2006b5ae..fe2e39bd 100644 --- a/services/updater_binary/update_image_block.h +++ b/services/updater_binary/update_image_block.h @@ -53,6 +53,7 @@ private: void PrintAbnormalBlockHash(const std::string &devPath, const std::string &blockPairs); std::string CalculateBlockSha(const std::string &devPath, const std::string &blockPairs); int32_t SetShaInfo(Uscript::UScriptContext &context, ShaInfo &shaInfo); + bool IsTargetShaDiff(const std::string &devPath, const ShaInfo &shaInfo); }; } -- Gitee From f12c0c53bc8810e29ccb305923cff5b59c8a1b44 Mon Sep 17 00:00:00 2001 From: chenzihan Date: Mon, 12 Aug 2024 14:58:09 +0800 Subject: [PATCH 20/52] Signed-off-by: chenzihan fix:clear misc after sdcard updater failed --- services/updater_ui.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/updater_ui.cpp b/services/updater_ui.cpp index bc081932..c1fa1cbc 100644 --- a/services/updater_ui.cpp +++ b/services/updater_ui.cpp @@ -108,6 +108,7 @@ DEFINE_ASYN_CALLBACK(OnLabelSDCardNoDelayEvt) UpdaterParams upParams; upParams.updateMode = SDCARD_UPDATE; if (auto res = UpdaterFromSdcard(upParams); res != UPDATE_SUCCESS) { + Utils::RemoveUpdateInfoFromMisc("sdcard_update"); GetFacade().ShowLogRes(res == UPDATE_CORRUPT ? TR(LOGRES_VERIFY_FAILED) : TR(LOGRES_UPDATE_FAILED)); GetFacade().ShowFailedPage(); Utils::UsSleep(FAIL_DELAY); -- Gitee From fd0de0aeed3d435cfd8fa4bfc74122365c0427ce Mon Sep 17 00:00:00 2001 From: LeonShu Date: Mon, 12 Aug 2024 20:01:19 +0800 Subject: [PATCH 21/52] for ut test Signed-off-by: LeonShu --- test/unittest/updater_binary/BUILD.gn | 1 - test/unittest/updater_ui_test/control/ui_control_unittest.cpp | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/test/unittest/updater_binary/BUILD.gn b/test/unittest/updater_binary/BUILD.gn index afeb7670..17d11ad6 100644 --- a/test/unittest/updater_binary/BUILD.gn +++ b/test/unittest/updater_binary/BUILD.gn @@ -23,7 +23,6 @@ ohos_unittest("binary_unittest") { sources = [ "update_image_block_test.cpp", "update_image_patch_unittest.cpp", - "update_partitions_unittest.cpp", "update_processor_unittest.cpp", "updater_binary_unittest.cpp", ] diff --git a/test/unittest/updater_ui_test/control/ui_control_unittest.cpp b/test/unittest/updater_ui_test/control/ui_control_unittest.cpp index 91ee8883..6bd81473 100644 --- a/test/unittest/updater_ui_test/control/ui_control_unittest.cpp +++ b/test/unittest/updater_ui_test/control/ui_control_unittest.cpp @@ -47,7 +47,7 @@ HWTEST_F(UpdaterUiControlUnittest, OnKeyAct01, TestSize.Level0) { OHOS::KeyEvent *event = new OHOS::KeyEvent(KEY_POWER, OHOS::InputDevice::STATE_PRESS); bool ret = keyListener->OnKeyAct(*view, *event); - EXPECT_EQ(ret, true); + EXPECT_EQ(ret, false); if (event != nullptr) { delete event; event = nullptr; @@ -58,7 +58,7 @@ HWTEST_F(UpdaterUiControlUnittest, OnKeyAct02, TestSize.Level0) { OHOS::KeyEvent *event = new OHOS::KeyEvent(KEY_VOLUMEUP, OHOS::InputDevice::STATE_PRESS); bool ret = keyListener->OnKeyAct(*view, *event); - EXPECT_EQ(ret, true); + EXPECT_EQ(ret, false); if (event != nullptr) { delete event; event = nullptr; -- Gitee From c04af828a7e012e93d0a04a5382f4dc0a7edabc0 Mon Sep 17 00:00:00 2001 From: LeonShu Date: Tue, 13 Aug 2024 05:55:41 +0000 Subject: [PATCH 22/52] update test/unittest/updater_binary/BUILD.gn. Signed-off-by: LeonShu --- test/unittest/updater_binary/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/updater_binary/BUILD.gn b/test/unittest/updater_binary/BUILD.gn index 17d11ad6..443aa650 100644 --- a/test/unittest/updater_binary/BUILD.gn +++ b/test/unittest/updater_binary/BUILD.gn @@ -23,8 +23,8 @@ ohos_unittest("binary_unittest") { sources = [ "update_image_block_test.cpp", "update_image_patch_unittest.cpp", + "update_partitions_unittest.cpp", "update_processor_unittest.cpp", - "updater_binary_unittest.cpp", ] sources += [ -- Gitee From 2fdb971699ff57165e7fb4c04370ad617b3c7c80 Mon Sep 17 00:00:00 2001 From: lidanyang Date: Wed, 14 Aug 2024 14:49:28 +0800 Subject: [PATCH 23/52] fix typo Signed-off-by: lidanyang --- services/package/pkg_manager/pkg_managerImpl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/package/pkg_manager/pkg_managerImpl.cpp b/services/package/pkg_manager/pkg_managerImpl.cpp index 704a0e46..cfc3602e 100644 --- a/services/package/pkg_manager/pkg_managerImpl.cpp +++ b/services/package/pkg_manager/pkg_managerImpl.cpp @@ -1026,7 +1026,7 @@ int32_t PkgManagerImpl::VerifyOtaPackage(const std::string &devPath, uint64_t of ClosePkgStream(pkgStream); }; PkgVerifyUtil verifyUtil {}; - ret = verifyUtil.VerifyPackageSigne(pkgStream); + ret = verifyUtil.VerifyPackageSign(pkgStream); if (ret != PKG_SUCCESS) { PKG_LOGE("verify pkcs7 signature failed."); return ret; -- Gitee From efd84e7a984ea331deba8ae18e12f7d69d3c43fd Mon Sep 17 00:00:00 2001 From: lidanyang Date: Wed, 14 Aug 2024 15:10:43 +0800 Subject: [PATCH 24/52] fix error Signed-off-by: lidanyang --- services/package/pkg_manager/pkg_manager_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/package/pkg_manager/pkg_manager_impl.h b/services/package/pkg_manager/pkg_manager_impl.h index 9cab6bd7..fa421d53 100644 --- a/services/package/pkg_manager/pkg_manager_impl.h +++ b/services/package/pkg_manager/pkg_manager_impl.h @@ -77,7 +77,7 @@ public: uint64_t fileLen, Updater::RingBuffer *buffer) override; int32_t VerifyAccPackage(const std::string &packagePath, const std::string &keyPath) override; int32_t VerifyOtaPackage(const std::string &packagePath) override; - + int32_t VerifyOtaPackage(const std::string &devPath, uint64_t offset, size_t size) override; int32_t VerifyBinFile(const std::string &packagePath, const std::string &keyPath, const std::string &version, const PkgBuffer &digest) override; -- Gitee From e8cb5ff2d6b7c27ade56b8b3410a94bf61a370cf Mon Sep 17 00:00:00 2001 From: lidanyang Date: Wed, 14 Aug 2024 18:46:01 +0800 Subject: [PATCH 25/52] fix sdk Signed-off-by: lidanyang --- services/package/pkg_manager/pkg_managerImpl.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/package/pkg_manager/pkg_managerImpl.cpp b/services/package/pkg_manager/pkg_managerImpl.cpp index cfc3602e..8c0ade32 100644 --- a/services/package/pkg_manager/pkg_managerImpl.cpp +++ b/services/package/pkg_manager/pkg_managerImpl.cpp @@ -992,6 +992,7 @@ int32_t PkgManagerImpl::VerifyAccPackage(const std::string &packagePath, const s int32_t PkgManagerImpl::VerifyOtaPackage(const std::string &devPath, uint64_t offset, size_t size) { +#ifndef DIFF_PATCH_SDK constexpr size_t pageSize = 4096; size_t offsetAligned = (offset / pageSize) * pageSize; if (size == 0 || size + offset < offsetAligned || offset < offsetAligned) { @@ -1031,6 +1032,7 @@ int32_t PkgManagerImpl::VerifyOtaPackage(const std::string &devPath, uint64_t of PKG_LOGE("verify pkcs7 signature failed."); return ret; } +#endif return PKG_SUCCESS; } -- Gitee From 0c94e0e485d02969696e75cf73d84077fc0f6270 Mon Sep 17 00:00:00 2001 From: richard Date: Thu, 15 Aug 2024 08:05:19 +0000 Subject: [PATCH 26/52] add update process log Signed-off-by: richard --- services/updater.cpp | 5 +++++ services/updater_binary/update_processor.cpp | 2 ++ 2 files changed, 7 insertions(+) diff --git a/services/updater.cpp b/services/updater.cpp index 2bf70ddd..42e9f08e 100644 --- a/services/updater.cpp +++ b/services/updater.cpp @@ -403,8 +403,13 @@ UpdaterStatus HandlePipeMsg(UpdaterParams &upParams, int pipeRead, bool &retryUp if (pch != nullptr) { *pch = '\0'; } + if(strstr(buffer, "subProcessResult") != nullptr) { + LOG(INFO) << "subProcessResult: " << buffer; + break; + } HandleChildOutput(buffer, MAX_BUFFER_SIZE, retryUpdate, upParams); } + LOG(INFO) << "HandlePipeMsg end"; fclose(fromChild); return UPDATE_SUCCESS; } diff --git a/services/updater_binary/update_processor.cpp b/services/updater_binary/update_processor.cpp index 71242e15..79cf2df5 100644 --- a/services/updater_binary/update_processor.cpp +++ b/services/updater_binary/update_processor.cpp @@ -501,6 +501,8 @@ int ProcessUpdater(bool retry, int pipeFd, const std::string &packagePath, const }); PkgManager::ReleasePackageInstance(pkgManager); #ifndef UPDATER_UT + fprintf(pipeWrite, "subProcessResult:%d\n", ret); + fflush(pipeWrite); fclose(pipeWrite); pipeWrite = nullptr; if (ret == 0) { -- Gitee From c94404bdf0ebe9e703b3da131eaac3f3c0e219be Mon Sep 17 00:00:00 2001 From: richard Date: Thu, 15 Aug 2024 08:33:36 +0000 Subject: [PATCH 27/52] add Signed-off-by: richard --- services/updater.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/updater.cpp b/services/updater.cpp index 42e9f08e..cc31e308 100644 --- a/services/updater.cpp +++ b/services/updater.cpp @@ -403,7 +403,7 @@ UpdaterStatus HandlePipeMsg(UpdaterParams &upParams, int pipeRead, bool &retryUp if (pch != nullptr) { *pch = '\0'; } - if(strstr(buffer, "subProcessResult") != nullptr) { + if (strstr(buffer, "subProcessResult") != nullptr) { LOG(INFO) << "subProcessResult: " << buffer; break; } -- Gitee From 74b8bdda9e5d85a9338f365c27f295d8ae8463e0 Mon Sep 17 00:00:00 2001 From: richard Date: Fri, 16 Aug 2024 03:51:38 +0000 Subject: [PATCH 28/52] add Signed-off-by: richard --- services/updater_binary/update_processor.cpp | 31 ++++++++------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/services/updater_binary/update_processor.cpp b/services/updater_binary/update_processor.cpp index 79cf2df5..833c6520 100644 --- a/services/updater_binary/update_processor.cpp +++ b/services/updater_binary/update_processor.cpp @@ -38,6 +38,7 @@ #include "updater_main.h" #include "updater/updater_const.h" #include "update_bin/bin_process.h" +#include "scope_guard.h" using namespace Uscript; using namespace Hpackage; @@ -460,51 +461,45 @@ int ProcessUpdater(bool retry, int pipeFd, const std::string &packagePath, const UPDATER_INIT_RECORD; UpdaterInit::GetInstance().InvokeEvent(UPDATER_BINARY_INIT_EVENT); Dump::GetInstance().RegisterDump("DumpHelperLog", std::make_unique()); - FILE *pipeWrite = fdopen(pipeFd, "w"); + std::unique_ptr pipeWrite(fdopen(pipeFd, "w"), fclose); if (pipeWrite == nullptr) { LOG(ERROR) << "Fail to fdopen, err: " << strerror(errno); UPDATER_LAST_WORD(EXIT_INVALID_ARGS); return EXIT_INVALID_ARGS; } + int ret = -1; + Detail::ScopeGuard guard([&] { + fprintf(pipeWrite.get(), "subProcessResult:%d\n", ret); + fflush(pipeWrite.get()); + }); // line buffered, make sure parent read per line. - setlinebuf(pipeWrite); + setlinebuf(pipeWrite.get()); PkgManager::PkgManagerPtr pkgManager = PkgManager::CreatePackageInstance(); if (pkgManager == nullptr) { LOG(ERROR) << "pkgManager is nullptr"; - fclose(pipeWrite); - pipeWrite = nullptr; - UPDATER_LAST_WORD(EXIT_INVALID_ARGS); return EXIT_INVALID_ARGS; } std::vector components; - int32_t ret = pkgManager->LoadPackage(packagePath, keyPath, components); + ret = pkgManager->LoadPackage(packagePath, keyPath, components); if (ret != PKG_SUCCESS) { LOG(ERROR) << "Fail to load package"; - fclose(pipeWrite); - pipeWrite = nullptr; PkgManager::ReleasePackageInstance(pkgManager); - UPDATER_LAST_WORD(EXIT_INVALID_ARGS); return EXIT_INVALID_ARGS; } #ifdef UPDATER_USE_PTABLE - DevicePtable& devicePtb = DevicePtable::GetInstance(); - devicePtb.LoadPartitionInfo(); + DevicePtable::GetInstance().LoadPartitionInfo(); #endif ret = Updater::ExecUpdate(pkgManager, retry, packagePath, [&pipeWrite](const char *cmd, const char *content) { - if (pipeWrite != nullptr) { - fprintf(pipeWrite, "%s:%s\n", cmd, content); - fflush(pipeWrite); + if (pipeWrite.get() != nullptr) { + fprintf(pipeWrite.get(), "%s:%s\n", cmd, content); + fflush(pipeWrite.get()); } }); PkgManager::ReleasePackageInstance(pkgManager); #ifndef UPDATER_UT - fprintf(pipeWrite, "subProcessResult:%d\n", ret); - fflush(pipeWrite); - fclose(pipeWrite); - pipeWrite = nullptr; if (ret == 0) { SetActiveSlot(); } -- Gitee From ced926f92217a83d6f9fffd65e6f10f725c652f3 Mon Sep 17 00:00:00 2001 From: richard Date: Fri, 16 Aug 2024 03:52:35 +0000 Subject: [PATCH 29/52] add Signed-off-by: richard --- services/updater_binary/update_processor.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/updater_binary/update_processor.cpp b/services/updater_binary/update_processor.cpp index 833c6520..e4a54275 100644 --- a/services/updater_binary/update_processor.cpp +++ b/services/updater_binary/update_processor.cpp @@ -469,8 +469,8 @@ int ProcessUpdater(bool retry, int pipeFd, const std::string &packagePath, const } int ret = -1; Detail::ScopeGuard guard([&] { - fprintf(pipeWrite.get(), "subProcessResult:%d\n", ret); - fflush(pipeWrite.get()); + (void)fprintf(pipeWrite.get(), "subProcessResult:%d\n", ret); + (void)fflush(pipeWrite.get()); }); // line buffered, make sure parent read per line. setlinebuf(pipeWrite.get()); @@ -494,8 +494,8 @@ int ProcessUpdater(bool retry, int pipeFd, const std::string &packagePath, const ret = Updater::ExecUpdate(pkgManager, retry, packagePath, [&pipeWrite](const char *cmd, const char *content) { if (pipeWrite.get() != nullptr) { - fprintf(pipeWrite.get(), "%s:%s\n", cmd, content); - fflush(pipeWrite.get()); + (void)fprintf(pipeWrite.get(), "%s:%s\n", cmd, content); + (void)fflush(pipeWrite.get()); } }); PkgManager::ReleasePackageInstance(pkgManager); -- Gitee From e5ca1a0dd5c3e867db8f4155d6177a7e424d1417 Mon Sep 17 00:00:00 2001 From: richard Date: Fri, 16 Aug 2024 06:23:21 +0000 Subject: [PATCH 30/52] add Signed-off-by: richard --- services/updater_binary/update_processor.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/updater_binary/update_processor.cpp b/services/updater_binary/update_processor.cpp index e4a54275..5045e2df 100644 --- a/services/updater_binary/update_processor.cpp +++ b/services/updater_binary/update_processor.cpp @@ -477,6 +477,7 @@ int ProcessUpdater(bool retry, int pipeFd, const std::string &packagePath, const PkgManager::PkgManagerPtr pkgManager = PkgManager::CreatePackageInstance(); if (pkgManager == nullptr) { LOG(ERROR) << "pkgManager is nullptr"; + UPDATER_LAST_WORD(EXIT_INVALID_ARGS); return EXIT_INVALID_ARGS; } @@ -485,6 +486,7 @@ int ProcessUpdater(bool retry, int pipeFd, const std::string &packagePath, const if (ret != PKG_SUCCESS) { LOG(ERROR) << "Fail to load package"; PkgManager::ReleasePackageInstance(pkgManager); + UPDATER_LAST_WORD(EXIT_INVALID_ARGS); return EXIT_INVALID_ARGS; } #ifdef UPDATER_USE_PTABLE -- Gitee From 983fe409e4d160f1499d6eba5400b8cd1ec969d4 Mon Sep 17 00:00:00 2001 From: chenzihan Date: Fri, 16 Aug 2024 15:01:07 +0800 Subject: [PATCH 31/52] Signed-off-by: chenzihan fix:add CompressFiles --- utils/include/utils.h | 1 + utils/utils.cpp | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/utils/include/utils.h b/utils/include/utils.h index 4de915bf..59bba7ca 100644 --- a/utils/include/utils.h +++ b/utils/include/utils.h @@ -65,6 +65,7 @@ bool CopyFile(const std::string &src, const std::string &dest, bool isAppend = f bool WriteStringToFile(int fd, const std::string& content); std::string GetLocalBoardId(); bool CopyUpdaterLogs(const std::string &sLog, const std::string &dLog); +void CompressFiles(std::vector &files, std::vector &zipFile); void CompressLogs(const std::string &name); bool CheckResultFail(); void WriteDumpResult(const std::string &result, const std::string &fileName); diff --git a/utils/utils.cpp b/utils/utils.cpp index e5b50430..2c40bab3 100644 --- a/utils/utils.cpp +++ b/utils/utils.cpp @@ -413,6 +413,29 @@ int32_t CreateCompressLogFile(const std::string &pkgName, std::vector &files, std::vector &zipFile) +{ + (void)DeleteFile(zipFile); + std::vector> zipFiles {}; + for (auto path : files) { + ZipFileInfo file; + file.fileInfo.identity = path.substr(logName.find_last_of("/") + 1);; + file.fileInfo.packMethod = PKG_COMPRESS_METHOD_ZIP; + file.fileInfo.digestMethod = PKG_DIGEST_TYPE_CRC; + files.push_back(std::pair(path, file)); + } + + int32_t ret = CreateCompressLogFile(zipFile, zipFiles); + if (ret != 0) { + LOG(WARNING) << "CompressFiles failed: " << zipFile; + return; + } + mode_t mode = 0660; +#ifndef __WIN32 + SetFileAttributes(pkgName, USER_UPDATE_AUTHORITY, GROUP_SYS_AUTHORITY, mode); +#endif +} + void CompressLogs(const std::string &logName) { std::vector> files; -- Gitee From 1f14d089452f55ee4d6a814ef7cf33ada42490f2 Mon Sep 17 00:00:00 2001 From: chenzihan Date: Fri, 16 Aug 2024 16:40:56 +0800 Subject: [PATCH 32/52] Signed-off-by: chenzihan fix:add CompressFiles --- utils/include/utils.h | 2 +- utils/utils.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/include/utils.h b/utils/include/utils.h index 59bba7ca..018d8d08 100644 --- a/utils/include/utils.h +++ b/utils/include/utils.h @@ -65,7 +65,7 @@ bool CopyFile(const std::string &src, const std::string &dest, bool isAppend = f bool WriteStringToFile(int fd, const std::string& content); std::string GetLocalBoardId(); bool CopyUpdaterLogs(const std::string &sLog, const std::string &dLog); -void CompressFiles(std::vector &files, std::vector &zipFile); +void CompressFiles(std::vector &files, const std::string &zipFile); void CompressLogs(const std::string &name); bool CheckResultFail(); void WriteDumpResult(const std::string &result, const std::string &fileName); diff --git a/utils/utils.cpp b/utils/utils.cpp index 2c40bab3..3db5fd29 100644 --- a/utils/utils.cpp +++ b/utils/utils.cpp @@ -413,7 +413,7 @@ int32_t CreateCompressLogFile(const std::string &pkgName, std::vector &files, std::vector &zipFile) +void CompressFiles(std::vector &files, const std::string &zipFile) { (void)DeleteFile(zipFile); std::vector> zipFiles {}; -- Gitee From c08cb318b2320027e35eb6e66730d02c64118b7b Mon Sep 17 00:00:00 2001 From: chenzihan Date: Fri, 16 Aug 2024 17:28:09 +0800 Subject: [PATCH 33/52] Signed-off-by: chenzihan fix:add CompressFiles --- utils/utils.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/utils.cpp b/utils/utils.cpp index 3db5fd29..9761eccc 100644 --- a/utils/utils.cpp +++ b/utils/utils.cpp @@ -419,10 +419,10 @@ void CompressFiles(std::vector &files, const std::string &zipFile) std::vector> zipFiles {}; for (auto path : files) { ZipFileInfo file; - file.fileInfo.identity = path.substr(logName.find_last_of("/") + 1);; + file.fileInfo.identity = path.substr(path.find_last_of("/") + 1);; file.fileInfo.packMethod = PKG_COMPRESS_METHOD_ZIP; file.fileInfo.digestMethod = PKG_DIGEST_TYPE_CRC; - files.push_back(std::pair(path, file)); + zipFiles.push_back(std::pair(path, file)); } int32_t ret = CreateCompressLogFile(zipFile, zipFiles); @@ -432,7 +432,7 @@ void CompressFiles(std::vector &files, const std::string &zipFile) } mode_t mode = 0660; #ifndef __WIN32 - SetFileAttributes(pkgName, USER_UPDATE_AUTHORITY, GROUP_SYS_AUTHORITY, mode); + SetFileAttributes(zipFile, USER_UPDATE_AUTHORITY, GROUP_SYS_AUTHORITY, mode); #endif } -- Gitee From a536761369f000dda2b832b6e59e9721da84abd6 Mon Sep 17 00:00:00 2001 From: lizhao Date: Fri, 16 Aug 2024 18:51:56 +0800 Subject: [PATCH 34/52] add devPath into TransferParams --- services/include/applypatch/transfer_manager.h | 1 + services/updater_binary/update_image_block.cpp | 9 +++++---- utils/utils.cpp | 4 +++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/services/include/applypatch/transfer_manager.h b/services/include/applypatch/transfer_manager.h index 65b05101..3956e7ca 100644 --- a/services/include/applypatch/transfer_manager.h +++ b/services/include/applypatch/transfer_manager.h @@ -51,6 +51,7 @@ struct TransferParams { std::string storeBase; std::string freeStash; std::string retryFile; + std::string devPath; uint8_t *patchDataBuffer; size_t patchDataSize; }; diff --git a/services/updater_binary/update_image_block.cpp b/services/updater_binary/update_image_block.cpp index 811229d5..16a30ff0 100644 --- a/services/updater_binary/update_image_block.cpp +++ b/services/updater_binary/update_image_block.cpp @@ -186,13 +186,14 @@ static int32_t GetUpdateBlockInfo(struct UpdateBlockInfo &infos, Uscript::UScrip } static int32_t ExecuteTransferCommand(int fd, const std::vector &lines, TransferManagerPtr tm, - Uscript::UScriptContext &context, const std::string &partitionName) + Uscript::UScriptContext &context, const UpdateBlockInfo &infos) { auto transferParams = tm->GetTransferParams(); auto writerThreadInfo = transferParams->writerThreadInfo.get(); - transferParams->storeBase = std::string("/data/updater") + partitionName + "_tmp"; - transferParams->retryFile = std::string("/data/updater") + partitionName + "_retry"; + transferParams->storeBase = std::string("/data/updater") + infos.partitionName + "_tmp"; + transferParams->retryFile = std::string("/data/updater") + infos.partitionName + "_retry"; + transferParams->devPath = infos.devPath; LOG(INFO) << "Store base path is " << transferParams->storeBase; int32_t ret = Store::CreateNewSpace(transferParams->storeBase, !transferParams->env->IsRetry()); if (ret == -1) { @@ -289,7 +290,7 @@ static int32_t DoExecuteUpdateBlock(const UpdateBlockInfo &infos, TransferManage env->GetPkgManager()->ClosePkgStream(outStream); return USCRIPT_ERROR_EXECUTE; } - int32_t ret = ExecuteTransferCommand(fd, lines, tm, context, infos.partitionName); + int32_t ret = ExecuteTransferCommand(fd, lines, tm, context, infos); fsync(fd); close(fd); fd = -1; diff --git a/utils/utils.cpp b/utils/utils.cpp index e5b50430..ba36343d 100644 --- a/utils/utils.cpp +++ b/utils/utils.cpp @@ -290,12 +290,14 @@ bool WriteFully(int fd, const uint8_t *data, size_t size) do { written = write(fd, data, rest); } while (written < 0 && errno == EINTR); - if (written < 0) { return false; } data += written; rest -= static_cast(written); + if (rest != 0) { + LOG(ERROR) << "totalSize = " << size << ", rest = " << rest; + } } return true; } -- Gitee From 8a45bd80d654c2a2c1db542710cc9b2a3fbedd86 Mon Sep 17 00:00:00 2001 From: chenzihan Date: Fri, 16 Aug 2024 20:29:49 +0800 Subject: [PATCH 35/52] Signed-off-by: chenzihan fix:add CompressFiles --- utils/utils.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/utils.cpp b/utils/utils.cpp index 9761eccc..d5d6b6ab 100644 --- a/utils/utils.cpp +++ b/utils/utils.cpp @@ -418,8 +418,8 @@ void CompressFiles(std::vector &files, const std::string &zipFile) (void)DeleteFile(zipFile); std::vector> zipFiles {}; for (auto path : files) { - ZipFileInfo file; - file.fileInfo.identity = path.substr(path.find_last_of("/") + 1);; + ZipFileInfo file {}; + file.fileInfo.identity = path.substr(path.find_last_of("/") + 1); file.fileInfo.packMethod = PKG_COMPRESS_METHOD_ZIP; file.fileInfo.digestMethod = PKG_DIGEST_TYPE_CRC; zipFiles.push_back(std::pair(path, file)); -- Gitee From f950898492a1c527894c8c54d8a810972348f8a0 Mon Sep 17 00:00:00 2001 From: lizhao Date: Fri, 16 Aug 2024 20:57:32 +0800 Subject: [PATCH 36/52] fix log level --- utils/utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/utils.cpp b/utils/utils.cpp index ba36343d..16f38857 100644 --- a/utils/utils.cpp +++ b/utils/utils.cpp @@ -296,7 +296,7 @@ bool WriteFully(int fd, const uint8_t *data, size_t size) data += written; rest -= static_cast(written); if (rest != 0) { - LOG(ERROR) << "totalSize = " << size << ", rest = " << rest; + LOG(INFO) << "totalSize = " << size << ", rest = " << rest; } } return true; -- Gitee From 129959da9f45181d4e4f38cf72c0aa702e7e1dff Mon Sep 17 00:00:00 2001 From: LeonShu Date: Mon, 19 Aug 2024 14:42:01 +0800 Subject: [PATCH 37/52] codex for string to int Signed-off-by: LeonShu --- services/ui/view/view_api.cpp | 8 +++++++- utils/include/utils.h | 11 ++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/services/ui/view/view_api.cpp b/services/ui/view/view_api.cpp index c8bf1d48..b7596fc8 100644 --- a/services/ui/view/view_api.cpp +++ b/services/ui/view/view_api.cpp @@ -72,7 +72,13 @@ OHOS::ColorType StrToColor(const std::string &hexColor) std::size_t startPos = 1uL; auto getNextField = [&startPos, &hexColor] () { constexpr std::size_t width = 2uL; - uint8_t ret = (startPos > hexColor.size()) ? 0 : Utils::String2Int(hexColor.substr(startPos, width)); + constexpr uint8_t colorMaxSize = 255; + int reset = Utils::String2Int(hexColor.substr(startPos, width)); + if (reset < 0 || reset > colorMaxSize) { + LOG(ERROR) << "String2Int error, reset = " << reset; + return colorMaxSize; + } + uint8_t ret = (startPos > hexColor.size()) ? 0 : static_cast(reset); startPos += width; return ret; }; diff --git a/utils/include/utils.h b/utils/include/utils.h index 018d8d08..73c656f7 100644 --- a/utils/include/utils.h +++ b/utils/include/utils.h @@ -40,6 +40,8 @@ constexpr const char* ON_SERVER = "ON_SERVER"; template T String2Int(const std::string &str, int base = N_HEX) { + static_assert(std::is_same_v || std::is_same_v || std::is_same_v, + "type should be int or size_t or unsigned long long int"); char *end = nullptr; if (str.empty()) { errno = EINVAL; @@ -48,7 +50,14 @@ T String2Int(const std::string &str, int base = N_HEX) if (((str[0] == '0') && (str[1] == 'x')) || (str[1] == 'X')) { base = N_HEX; } - T result = strtoull(str.c_str(), &end, base); + T result = 0; + if constexpr (std::is_same_v) { + result = strtol(str.c_str(), &end, base); + } else if constexpr (std::is_same_v || std::is_same_v) { + result = strtoull(str.c_str(), &end, base); + } else { + errno = EINVAL; + } return result; } int32_t DeleteFile(const std::string& filename); -- Gitee From cb2925993109518776b34cec667e5b4408f81085 Mon Sep 17 00:00:00 2001 From: LeonShu Date: Mon, 19 Aug 2024 15:16:00 +0800 Subject: [PATCH 38/52] codex for real path Signed-off-by: LeonShu --- services/package/pkg_manager/pkg_managerImpl.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/services/package/pkg_manager/pkg_managerImpl.cpp b/services/package/pkg_manager/pkg_managerImpl.cpp index 8c0ade32..9cd7111e 100644 --- a/services/package/pkg_manager/pkg_managerImpl.cpp +++ b/services/package/pkg_manager/pkg_managerImpl.cpp @@ -999,9 +999,15 @@ int32_t PkgManagerImpl::VerifyOtaPackage(const std::string &devPath, uint64_t of PKG_LOGE("invalid param %zu %" PRIu64 " %zu", size, offset, offsetAligned); return PKG_INVALID_PARAM; } - int fd = open(devPath.c_str(), O_RDONLY | O_LARGEFILE); + char *realPath = realpath(devPath.c_str(), nullptr); + if (realpath == nullptr) { + PKG_LOGE("realPath %s is nullptr, err %s", realPath.c_str(), strerror(errno)); + return PKG_INVALID_PARAM; + } + int fd = open(realPath.c_str(), O_RDONLY | O_LARGEFILE); + free(realPath); if (fd < 0) { - PKG_LOGE("open %s fail, %s", devPath.c_str(), strerror(errno)); + PKG_LOGE("open %s fail, %s", realPath.c_str(), strerror(errno)); return PKG_INVALID_FILE; } ON_SCOPE_EXIT(closePath) { @@ -1010,7 +1016,7 @@ int32_t PkgManagerImpl::VerifyOtaPackage(const std::string &devPath, uint64_t of uint8_t *pMap = static_cast(mmap64(nullptr, size + offset - offsetAligned, PROT_READ, MAP_PRIVATE, fd, offsetAligned)); if (pMap == MAP_FAILED) { - PKG_LOGE("mmap64 %s fail, %s %zu %" PRIu64, devPath.c_str(), strerror(errno), size, offset); + PKG_LOGE("mmap64 %s fail, %s %zu %" PRIu64, realPath.c_str(), strerror(errno), size, offset); return PKG_NONE_MEMORY; } ON_SCOPE_EXIT(unmapMem) { @@ -1018,9 +1024,9 @@ int32_t PkgManagerImpl::VerifyOtaPackage(const std::string &devPath, uint64_t of }; PkgBuffer buffer(pMap + (offset - offsetAligned), size); PkgStreamPtr pkgStream = nullptr; - int32_t ret = CreatePkgStream(pkgStream, devPath, buffer); + int32_t ret = CreatePkgStream(pkgStream, realPath, buffer); if (ret != PKG_SUCCESS) { - PKG_LOGE("create package stream fail %s %s", devPath.c_str(), strerror(errno)); + PKG_LOGE("create package stream fail %s %s", realPath.c_str(), strerror(errno)); return ret; } ON_SCOPE_EXIT(closeStream) { -- Gitee From b97ae0505bc98adf440a3911e8ef94e81e9a13a7 Mon Sep 17 00:00:00 2001 From: LeonShu Date: Mon, 19 Aug 2024 07:22:53 +0000 Subject: [PATCH 39/52] update services/package/pkg_manager/pkg_managerImpl.cpp. Signed-off-by: LeonShu --- services/package/pkg_manager/pkg_managerImpl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/package/pkg_manager/pkg_managerImpl.cpp b/services/package/pkg_manager/pkg_managerImpl.cpp index 9cd7111e..fac161f0 100644 --- a/services/package/pkg_manager/pkg_managerImpl.cpp +++ b/services/package/pkg_manager/pkg_managerImpl.cpp @@ -1000,7 +1000,7 @@ int32_t PkgManagerImpl::VerifyOtaPackage(const std::string &devPath, uint64_t of return PKG_INVALID_PARAM; } char *realPath = realpath(devPath.c_str(), nullptr); - if (realpath == nullptr) { + if (realPath == nullptr) { PKG_LOGE("realPath %s is nullptr, err %s", realPath.c_str(), strerror(errno)); return PKG_INVALID_PARAM; } -- Gitee From f6da323c32b95f5df886eed39c2f881b5373ba06 Mon Sep 17 00:00:00 2001 From: LeonShu Date: Mon, 19 Aug 2024 07:44:23 +0000 Subject: [PATCH 40/52] update services/package/pkg_manager/pkg_managerImpl.cpp. Signed-off-by: LeonShu --- services/package/pkg_manager/pkg_managerImpl.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/services/package/pkg_manager/pkg_managerImpl.cpp b/services/package/pkg_manager/pkg_managerImpl.cpp index fac161f0..d1872323 100644 --- a/services/package/pkg_manager/pkg_managerImpl.cpp +++ b/services/package/pkg_manager/pkg_managerImpl.cpp @@ -999,15 +999,15 @@ int32_t PkgManagerImpl::VerifyOtaPackage(const std::string &devPath, uint64_t of PKG_LOGE("invalid param %zu %" PRIu64 " %zu", size, offset, offsetAligned); return PKG_INVALID_PARAM; } - char *realPath = realpath(devPath.c_str(), nullptr); - if (realPath == nullptr) { + char devRealPath[PATH_MAX + 1] = { '\0' }; + if (realpath(devPath.c_str(), devRealPath) == nullptr) { PKG_LOGE("realPath %s is nullptr, err %s", realPath.c_str(), strerror(errno)); return PKG_INVALID_PARAM; } - int fd = open(realPath.c_str(), O_RDONLY | O_LARGEFILE); - free(realPath); + int fd = open(devRealPath, O_RDONLY | O_LARGEFILE); + free(devRealPath); if (fd < 0) { - PKG_LOGE("open %s fail, %s", realPath.c_str(), strerror(errno)); + PKG_LOGE("open %s fail, %s", devRealPath, strerror(errno)); return PKG_INVALID_FILE; } ON_SCOPE_EXIT(closePath) { @@ -1016,7 +1016,7 @@ int32_t PkgManagerImpl::VerifyOtaPackage(const std::string &devPath, uint64_t of uint8_t *pMap = static_cast(mmap64(nullptr, size + offset - offsetAligned, PROT_READ, MAP_PRIVATE, fd, offsetAligned)); if (pMap == MAP_FAILED) { - PKG_LOGE("mmap64 %s fail, %s %zu %" PRIu64, realPath.c_str(), strerror(errno), size, offset); + PKG_LOGE("mmap64 %s fail, %s %zu %" PRIu64, devRealPath, strerror(errno), size, offset); return PKG_NONE_MEMORY; } ON_SCOPE_EXIT(unmapMem) { @@ -1024,9 +1024,9 @@ int32_t PkgManagerImpl::VerifyOtaPackage(const std::string &devPath, uint64_t of }; PkgBuffer buffer(pMap + (offset - offsetAligned), size); PkgStreamPtr pkgStream = nullptr; - int32_t ret = CreatePkgStream(pkgStream, realPath, buffer); + int32_t ret = CreatePkgStream(pkgStream, devRealPath, buffer); if (ret != PKG_SUCCESS) { - PKG_LOGE("create package stream fail %s %s", realPath.c_str(), strerror(errno)); + PKG_LOGE("create package stream fail %s %s", devRealPath, strerror(errno)); return ret; } ON_SCOPE_EXIT(closeStream) { -- Gitee From abebf78a7b5fb1f4a901d4b9b705ba788608093e Mon Sep 17 00:00:00 2001 From: LeonShu Date: Mon, 19 Aug 2024 08:19:12 +0000 Subject: [PATCH 41/52] update services/package/pkg_manager/pkg_managerImpl.cpp. Signed-off-by: LeonShu --- services/package/pkg_manager/pkg_managerImpl.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/package/pkg_manager/pkg_managerImpl.cpp b/services/package/pkg_manager/pkg_managerImpl.cpp index d1872323..3a768d17 100644 --- a/services/package/pkg_manager/pkg_managerImpl.cpp +++ b/services/package/pkg_manager/pkg_managerImpl.cpp @@ -999,9 +999,9 @@ int32_t PkgManagerImpl::VerifyOtaPackage(const std::string &devPath, uint64_t of PKG_LOGE("invalid param %zu %" PRIu64 " %zu", size, offset, offsetAligned); return PKG_INVALID_PARAM; } - char devRealPath[PATH_MAX + 1] = { '\0' }; - if (realpath(devPath.c_str(), devRealPath) == nullptr) { - PKG_LOGE("realPath %s is nullptr, err %s", realPath.c_str(), strerror(errno)); + char *devRealPath = realpath(devPath.c_str(), nullptr); + if (devRealPath == nullptr) { + PKG_LOGE("realPath %s is nullptr, err %s", devRealPath, strerror(errno)); return PKG_INVALID_PARAM; } int fd = open(devRealPath, O_RDONLY | O_LARGEFILE); -- Gitee From 869c12db36070e2f234efa53c72087ff5a3c7185 Mon Sep 17 00:00:00 2001 From: LeonShu Date: Mon, 19 Aug 2024 08:34:22 +0000 Subject: [PATCH 42/52] update services/ui/view/view_api.cpp. Signed-off-by: LeonShu --- services/ui/view/view_api.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/ui/view/view_api.cpp b/services/ui/view/view_api.cpp index b7596fc8..fb870502 100644 --- a/services/ui/view/view_api.cpp +++ b/services/ui/view/view_api.cpp @@ -74,7 +74,7 @@ OHOS::ColorType StrToColor(const std::string &hexColor) constexpr std::size_t width = 2uL; constexpr uint8_t colorMaxSize = 255; int reset = Utils::String2Int(hexColor.substr(startPos, width)); - if (reset < 0 || reset > colorMaxSize) { + if (reset < 0 || reset > static_cast(colorMaxSize)) { LOG(ERROR) << "String2Int error, reset = " << reset; return colorMaxSize; } -- Gitee From a60a05527255c93aea5b0617e60f66f9cede01bd Mon Sep 17 00:00:00 2001 From: LeonShu Date: Mon, 19 Aug 2024 09:15:29 +0000 Subject: [PATCH 43/52] update services/package/pkg_manager/pkg_managerImpl.cpp. Signed-off-by: LeonShu --- services/package/pkg_manager/pkg_managerImpl.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/services/package/pkg_manager/pkg_managerImpl.cpp b/services/package/pkg_manager/pkg_managerImpl.cpp index 3a768d17..32a73b41 100644 --- a/services/package/pkg_manager/pkg_managerImpl.cpp +++ b/services/package/pkg_manager/pkg_managerImpl.cpp @@ -999,13 +999,12 @@ int32_t PkgManagerImpl::VerifyOtaPackage(const std::string &devPath, uint64_t of PKG_LOGE("invalid param %zu %" PRIu64 " %zu", size, offset, offsetAligned); return PKG_INVALID_PARAM; } - char *devRealPath = realpath(devPath.c_str(), nullptr); - if (devRealPath == nullptr) { - PKG_LOGE("realPath %s is nullptr, err %s", devRealPath, strerror(errno)); + char devRealPath[PATH_MAX + 1] = {}; + if (realpath(devPath.c_str(), devRealPath) == nullptr) { + PKG_LOGE("realPath is nullptr, err %s", strerror(errno)); return PKG_INVALID_PARAM; } int fd = open(devRealPath, O_RDONLY | O_LARGEFILE); - free(devRealPath); if (fd < 0) { PKG_LOGE("open %s fail, %s", devRealPath, strerror(errno)); return PKG_INVALID_FILE; -- Gitee From e631596854e18ebebd341cc8503ebcee71b30531 Mon Sep 17 00:00:00 2001 From: wangjiadong Date: Tue, 20 Aug 2024 17:07:26 +0800 Subject: [PATCH 44/52] Signed-off-by: wangjiadong deleat unused BI --- services/updater_main.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/services/updater_main.cpp b/services/updater_main.cpp index a3e85267..33643e2d 100644 --- a/services/updater_main.cpp +++ b/services/updater_main.cpp @@ -126,7 +126,6 @@ static UpdaterStatus UpdatePreCheck(UpdaterParams &upParams, const std::string p UPDATER_INIT_RECORD; int32_t ret = PreProcess::GetInstance().DoUpdateAuth(pkgPath); if (ret != 0) { - UPDATER_LAST_WORD("auth", ret); return UPDATE_ERROR; } @@ -199,13 +198,13 @@ static UpdaterStatus VerifyPackages(UpdaterParams &upParams) UPDATER_UI_INSTANCE.ShowUpdInfo(TR(UPD_VERIFYPKGFAIL), true); auto endTime = std::chrono::system_clock::now(); upParams.installTime[i] = endTime - startTime; - UPDATER_LAST_WORD(verifyret); return UPDATE_CORRUPT; } auto endTime = std::chrono::system_clock::now(); upParams.installTime[i] = endTime - startTime; } if (VerifySpecialPkgs(upParams) != PKG_SUCCESS) { + UPDATER_LAST_WORD(UPDATE_CORRUPT); return UPDATE_CORRUPT; } ProgressSmoothHandler(UPDATER_UI_INSTANCE.GetCurrentPercent(), @@ -375,7 +374,6 @@ static UpdaterStatus PreUpdatePackages(UpdaterParams &upParams) // verify packages first if (VerifyPackages(upParams) != UPDATE_SUCCESS) { - UPDATER_LAST_WORD(UPDATE_CORRUPT); return UPDATE_CORRUPT; // verify package failed must return UPDATE_CORRUPT, ux need it !!! } -- Gitee From ba8eea8e3af61deb025c68d1c2e21b69580c75a1 Mon Sep 17 00:00:00 2001 From: LeonShu Date: Tue, 20 Aug 2024 18:51:06 +0800 Subject: [PATCH 45/52] for updater UT test Signed-off-by: LeonShu --- services/factory_reset/factory_reset.h | 2 -- services/ui/control/event_listener.cpp | 2 ++ test/unittest/factory_reset_test/factory_reset_unittest.cpp | 2 ++ .../updater_ui_test/control/ui_control_unittest.cpp | 6 +++--- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/services/factory_reset/factory_reset.h b/services/factory_reset/factory_reset.h index 9892d0ac..053631f8 100644 --- a/services/factory_reset/factory_reset.h +++ b/services/factory_reset/factory_reset.h @@ -38,9 +38,7 @@ public: void RegisterFactoryResetPostFunc(FactoryResetPostFunc ptr); int FactoryResetFunc(FactoryResetMode mode, const std::string &path); -#ifndef UPDATER_UT private: -#endif CommonResetPostFunc CommonResetPostFunc_ = nullptr; FactoryResetPreFunc FactoryResetPreFunc_ = nullptr; FactoryResetPostFunc FactoryResetPostFunc_ = nullptr; diff --git a/services/ui/control/event_listener.cpp b/services/ui/control/event_listener.cpp index 93f6c92d..14974a93 100644 --- a/services/ui/control/event_listener.cpp +++ b/services/ui/control/event_listener.cpp @@ -154,6 +154,7 @@ bool KeyListener::OnKeyAct(OHOS::UIView &view, const OHOS::KeyEvent &event) bool KeyListener::ProcessPowerKey(OHOS::UIView &view, const OHOS::KeyEvent &event) { +#ifndef UPDATER_UT OHOS::UIView *pView = OHOS::FocusManager::GetInstance()->GetFocusedView(); if (pView == nullptr) { LOG(ERROR) << "focused view is nullptr"; @@ -170,6 +171,7 @@ bool KeyListener::ProcessPowerKey(OHOS::UIView &view, const OHOS::KeyEvent &even LOG(DEBUG) << "OnPress"; pView->OnClickEvent(OHOS::Point { centerX, centerY }); } +#endif return true; } diff --git a/test/unittest/factory_reset_test/factory_reset_unittest.cpp b/test/unittest/factory_reset_test/factory_reset_unittest.cpp index 25bb4e3d..8a001030 100644 --- a/test/unittest/factory_reset_test/factory_reset_unittest.cpp +++ b/test/unittest/factory_reset_test/factory_reset_unittest.cpp @@ -14,7 +14,9 @@ */ #include +#define private public #include "factory_reset.h" +#undef private using namespace Updater; using namespace testing::ext; diff --git a/test/unittest/updater_ui_test/control/ui_control_unittest.cpp b/test/unittest/updater_ui_test/control/ui_control_unittest.cpp index 6bd81473..f57a51d4 100644 --- a/test/unittest/updater_ui_test/control/ui_control_unittest.cpp +++ b/test/unittest/updater_ui_test/control/ui_control_unittest.cpp @@ -47,7 +47,7 @@ HWTEST_F(UpdaterUiControlUnittest, OnKeyAct01, TestSize.Level0) { OHOS::KeyEvent *event = new OHOS::KeyEvent(KEY_POWER, OHOS::InputDevice::STATE_PRESS); bool ret = keyListener->OnKeyAct(*view, *event); - EXPECT_EQ(ret, false); + EXPECT_EQ(ret, true); if (event != nullptr) { delete event; event = nullptr; @@ -58,7 +58,7 @@ HWTEST_F(UpdaterUiControlUnittest, OnKeyAct02, TestSize.Level0) { OHOS::KeyEvent *event = new OHOS::KeyEvent(KEY_VOLUMEUP, OHOS::InputDevice::STATE_PRESS); bool ret = keyListener->OnKeyAct(*view, *event); - EXPECT_EQ(ret, false); + EXPECT_EQ(ret, true); if (event != nullptr) { delete event; event = nullptr; @@ -80,7 +80,7 @@ HWTEST_F(UpdaterUiControlUnittest, OnKeyAct04, TestSize.Level0) { OHOS::KeyEvent *event = new OHOS::KeyEvent(100, OHOS::InputDevice::STATE_PRESS); bool ret = keyListener->OnKeyAct(*view, *event); - EXPECT_EQ(ret, true); + EXPECT_EQ(ret, false); if (event != nullptr) { delete event; event = nullptr; -- Gitee From 2723a7c02116474aa070d46e1708ebb1b5b8ff99 Mon Sep 17 00:00:00 2001 From: the_big_blue_devil Date: Tue, 20 Aug 2024 21:22:30 +0800 Subject: [PATCH 46/52] Signed-off-by:hanqiaosheng --- test/unittest/flashd_test/flashd_unittest.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/unittest/flashd_test/flashd_unittest.cpp b/test/unittest/flashd_test/flashd_unittest.cpp index 3d46a2fd..d5f92db8 100644 --- a/test/unittest/flashd_test/flashd_unittest.cpp +++ b/test/unittest/flashd_test/flashd_unittest.cpp @@ -249,11 +249,6 @@ std::unique_ptr GetTestWriter() return std::make_unique(); } -HWTEST_F(FLashServiceUnitTest, FlashdRegisterWriter, TestSize.Level1) -{ - FlashdImageWriter::GetInstance().RegisterUserWriter(IsTestImg, GetTestWriter); -} - HWTEST_F(FLashServiceUnitTest, PartitionDoErase, TestSize.Level1) { std::string partitionName = "test"; -- Gitee From 0439d5478cc97dd79dfd1db06945f70f466b8b9f Mon Sep 17 00:00:00 2001 From: the_big_blue_devil Date: Thu, 22 Aug 2024 17:25:57 +0800 Subject: [PATCH 47/52] Signed-off-by:hanqiaosheng --- services/include/updater/updater.h | 2 +- services/updater.cpp | 5 ++--- .../UpdaterStartUpdaterProc_fuzzer.cpp | 3 +-- .../service_test/updater_service_unittest.cpp | 7 +++---- test/unittest/updater_test/updater_unittest.cpp | 11 +++++------ 5 files changed, 12 insertions(+), 16 deletions(-) diff --git a/services/include/updater/updater.h b/services/include/updater/updater.h index a51a294e..7c3fd9fa 100644 --- a/services/include/updater/updater.h +++ b/services/include/updater/updater.h @@ -81,7 +81,7 @@ UpdaterStatus DoInstallUpdaterPackage(Hpackage::PkgManager::PkgManagerPtr pkgMan UpdaterParams &upParams, PackageUpdateMode updateMode); UpdaterStatus StartUpdaterProc(Hpackage::PkgManager::PkgManagerPtr pkgManager, - UpdaterParams &upParams, int &maxTemperature); + UpdaterParams &upParams); int GetUpdatePackageInfo(Hpackage::PkgManager::PkgManagerPtr pkgManager, const std::string& path); diff --git a/services/updater.cpp b/services/updater.cpp index cc31e308..b7046301 100644 --- a/services/updater.cpp +++ b/services/updater.cpp @@ -279,8 +279,7 @@ UpdaterStatus DoInstallUpdaterPackage(PkgManager::PkgManagerPtr pkgManager, Upda } g_tmpProgressValue = 0; - int maxTemperature; - UpdaterStatus updateRet = StartUpdaterProc(pkgManager, upParams, maxTemperature); + UpdaterStatus updateRet = StartUpdaterProc(pkgManager, upParams); if (updateRet != UPDATE_SUCCESS) { UPDATER_UI_INSTANCE.ShowUpdInfo(TR(UPD_INSTALL_FAIL)); LOG(ERROR) << "Install package failed."; @@ -439,7 +438,7 @@ UpdaterStatus CheckProcStatus(pid_t pid, bool retryUpdate) return UPDATE_SUCCESS; } -UpdaterStatus StartUpdaterProc(PkgManager::PkgManagerPtr pkgManager, UpdaterParams &upParams, int &maxTemperature) +UpdaterStatus StartUpdaterProc(PkgManager::PkgManagerPtr pkgManager, UpdaterParams &upParams) { UPDATER_INIT_RECORD; int pfd[DEFAULT_PIPE_NUM]; /* communication between parent and child */ diff --git a/test/fuzztest/UpdaterStartUpdaterProc_fuzzer/UpdaterStartUpdaterProc_fuzzer.cpp b/test/fuzztest/UpdaterStartUpdaterProc_fuzzer/UpdaterStartUpdaterProc_fuzzer.cpp index d59dcd28..1a3120b2 100644 --- a/test/fuzztest/UpdaterStartUpdaterProc_fuzzer/UpdaterStartUpdaterProc_fuzzer.cpp +++ b/test/fuzztest/UpdaterStartUpdaterProc_fuzzer/UpdaterStartUpdaterProc_fuzzer.cpp @@ -160,14 +160,13 @@ static int StartUpdaterProcFun(const std::string &patch) { UpdaterStatus status; std::vector components; - int maxTemperature; PkgManager::PkgManagerPtr pkgManager = PkgManager::CreatePackageInstance(); pkgManager->LoadPackage(patch, GetTestCertName(), components); UpdaterParams upParams; upParams.updatePackage.push_back(patch); upParams.retryCount = 0; - status = StartUpdaterProc(pkgManager, upParams, maxTemperature); + status = StartUpdaterProc(pkgManager, upParams); LOG(INFO) << "[fuzz] status " << status; PkgManager::ReleasePackageInstance(pkgManager); return status; diff --git a/test/unittest/service_test/updater_service_unittest.cpp b/test/unittest/service_test/updater_service_unittest.cpp index 99210414..5b868efc 100644 --- a/test/unittest/service_test/updater_service_unittest.cpp +++ b/test/unittest/service_test/updater_service_unittest.cpp @@ -316,9 +316,8 @@ HWTEST_F(UpdaterUtilUnitTest, StartUpdaterProcTest, TestSize.Level1) { Hpackage::PkgManager::PkgManagerPtr pkgManager = Hpackage::PkgManager::CreatePackageInstance(); UpdaterParams upParams; - int maxTemperature = 0; - EXPECT_EQ(StartUpdaterProc(nullptr, upParams, maxTemperature), UPDATE_CORRUPT); - EXPECT_EQ(StartUpdaterProc(pkgManager, upParams, maxTemperature), UPDATE_ERROR); + EXPECT_EQ(StartUpdaterProc(nullptr, upParams), UPDATE_CORRUPT); + EXPECT_EQ(StartUpdaterProc(pkgManager, upParams), UPDATE_ERROR); } HWTEST_F(UpdaterUtilUnitTest, CheckPathNeedMountSD, TestSize.Level0) @@ -333,4 +332,4 @@ HWTEST_F(UpdaterUtilUnitTest, CheckPathNeedMountSD, TestSize.Level0) upParams.updatePackage.push_back("/data/sdcard/updater_full.zip"); EXPECT_EQ(CheckPathNeedMountSD(upParams), false); } -} \ No newline at end of file +} diff --git a/test/unittest/updater_test/updater_unittest.cpp b/test/unittest/updater_test/updater_unittest.cpp index 9e8f0c5e..20ddcd35 100755 --- a/test/unittest/updater_test/updater_unittest.cpp +++ b/test/unittest/updater_test/updater_unittest.cpp @@ -71,28 +71,27 @@ HWTEST_F(UpdaterUnitTest, updater_StartUpdaterProc, TestSize.Level1) { std::string packagePath = "/data/updater/updater/updater_without_updater_binary.zip"; PkgManager::PkgManagerPtr pkgManager = PkgManager::CreatePackageInstance(); - int maxTemperature; UpdaterStatus status; - status = StartUpdaterProc(pkgManager, packagePath, 0, maxTemperature); + status = StartUpdaterProc(pkgManager, packagePath, 0); EXPECT_EQ(status, UPDATE_CORRUPT); packagePath = "/data/updater/updater/updater_with_incorrect_binary.zip"; - status = StartUpdaterProc(pkgManager, packagePath, 0, maxTemperature); + status = StartUpdaterProc(pkgManager, packagePath, 0); EXPECT_EQ(status, UPDATE_CORRUPT); packagePath = "/data/updater/updater/updater.zip"; std::vector components; int32_t ret = pkgManager->LoadPackage(packagePath, GetTestCertName(), components); EXPECT_EQ(ret, 0); - status = StartUpdaterProc(pkgManager, packagePath, 0, maxTemperature); + status = StartUpdaterProc(pkgManager, packagePath, 0); EXPECT_EQ(status, UPDATE_SUCCESS); // retrycount is greater than 0. - status = StartUpdaterProc(pkgManager, packagePath, 1, maxTemperature); + status = StartUpdaterProc(pkgManager, packagePath, 1); EXPECT_EQ(status, UPDATE_RETRY); packagePath = "/data/updater/updater/updater_binary_abnormal.zip"; - status = StartUpdaterProc(pkgManager, packagePath, 1, maxTemperature); + status = StartUpdaterProc(pkgManager, packagePath, 1); PkgManager::ReleasePackageInstance(pkgManager); EXPECT_EQ(status, UPDATE_ERROR); } -- Gitee From 85435ece7277938ca7bc4ad7fb694fb955a300cf Mon Sep 17 00:00:00 2001 From: richard Date: Fri, 23 Aug 2024 08:59:26 +0000 Subject: [PATCH 48/52] add Signed-off-by: richard --- services/updater_binary/update_processor.cpp | 51 +++++++++++++------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/services/updater_binary/update_processor.cpp b/services/updater_binary/update_processor.cpp index 5045e2df..41f35c59 100644 --- a/services/updater_binary/update_processor.cpp +++ b/services/updater_binary/update_processor.cpp @@ -456,12 +456,36 @@ int UScriptInstructionRawImageWrite::GetWritePathAndOffset(const std::string &pa return USCRIPT_SUCCESS; } +static PkgManager::PkgManagerPtr LoadPackage(const std::string &packagePath, const std::string &keyPath) +{ + if (packagePath.empty() || keyPath.empty()) { + LOG(ERROR) << "pkgManager path is null"; + return nullptr; + } + PkgManager::PkgManagerPtr pkgManager = PkgManager::CreatePackageInstance(); + if (pkgManager == nullptr) { + LOG(ERROR) << "pkgManager is nullptr"; + UPDATER_LAST_WORD(EXIT_INVALID_ARGS); + return nullptr; + } + + std::vector components; + if (pkgManager->LoadPackage(packagePath, keyPath, components) != PKG_SUCCESS) { + LOG(ERROR) << "Fail to load package"; + PkgManager::ReleasePackageInstance(pkgManager); + UPDATER_LAST_WORD(EXIT_INVALID_ARGS); + return nullptr; + } + + return pkgManager; +} + int ProcessUpdater(bool retry, int pipeFd, const std::string &packagePath, const std::string &keyPath) { UPDATER_INIT_RECORD; UpdaterInit::GetInstance().InvokeEvent(UPDATER_BINARY_INIT_EVENT); Dump::GetInstance().RegisterDump("DumpHelperLog", std::make_unique()); - std::unique_ptr pipeWrite(fdopen(pipeFd, "w"), fclose); + FILE *pipeWrite = fdopen(pipeFd, "w"); if (pipeWrite == nullptr) { LOG(ERROR) << "Fail to fdopen, err: " << strerror(errno); UPDATER_LAST_WORD(EXIT_INVALID_ARGS); @@ -469,35 +493,28 @@ int ProcessUpdater(bool retry, int pipeFd, const std::string &packagePath, const } int ret = -1; Detail::ScopeGuard guard([&] { - (void)fprintf(pipeWrite.get(), "subProcessResult:%d\n", ret); - (void)fflush(pipeWrite.get()); + (void)fprintf(pipeWrite, "subProcessResult:%d\n", ret); + (void)fflush(pipeWrite); + fclose(pipeWrite); + pipeWrite = nullptr; }); // line buffered, make sure parent read per line. - setlinebuf(pipeWrite.get()); - PkgManager::PkgManagerPtr pkgManager = PkgManager::CreatePackageInstance(); + setlinebuf(pipeWrite); + PkgManager::PkgManagerPtr pkgManager = LoadPackage(packagePath, keyPath); if (pkgManager == nullptr) { - LOG(ERROR) << "pkgManager is nullptr"; UPDATER_LAST_WORD(EXIT_INVALID_ARGS); return EXIT_INVALID_ARGS; } - std::vector components; - ret = pkgManager->LoadPackage(packagePath, keyPath, components); - if (ret != PKG_SUCCESS) { - LOG(ERROR) << "Fail to load package"; - PkgManager::ReleasePackageInstance(pkgManager); - UPDATER_LAST_WORD(EXIT_INVALID_ARGS); - return EXIT_INVALID_ARGS; - } #ifdef UPDATER_USE_PTABLE DevicePtable::GetInstance().LoadPartitionInfo(); #endif ret = Updater::ExecUpdate(pkgManager, retry, packagePath, [&pipeWrite](const char *cmd, const char *content) { - if (pipeWrite.get() != nullptr) { - (void)fprintf(pipeWrite.get(), "%s:%s\n", cmd, content); - (void)fflush(pipeWrite.get()); + if (pipeWrite != nullptr) { + (void)fprintf(pipeWrite, "%s:%s\n", cmd, content); + (void)fflush(pipeWrite); } }); PkgManager::ReleasePackageInstance(pkgManager); -- Gitee From d13256eb191b844f5a3d92c4e64585e9eef5fd04 Mon Sep 17 00:00:00 2001 From: richard Date: Sat, 24 Aug 2024 03:15:33 +0000 Subject: [PATCH 49/52] add Signed-off-by: richard --- services/updater_binary/update_processor.cpp | 51 +++++++------------ .../update_image_block_test.cpp | 8 ++- .../update_processor_unittest.cpp | 6 +++ 3 files changed, 30 insertions(+), 35 deletions(-) diff --git a/services/updater_binary/update_processor.cpp b/services/updater_binary/update_processor.cpp index 41f35c59..5045e2df 100644 --- a/services/updater_binary/update_processor.cpp +++ b/services/updater_binary/update_processor.cpp @@ -456,36 +456,12 @@ int UScriptInstructionRawImageWrite::GetWritePathAndOffset(const std::string &pa return USCRIPT_SUCCESS; } -static PkgManager::PkgManagerPtr LoadPackage(const std::string &packagePath, const std::string &keyPath) -{ - if (packagePath.empty() || keyPath.empty()) { - LOG(ERROR) << "pkgManager path is null"; - return nullptr; - } - PkgManager::PkgManagerPtr pkgManager = PkgManager::CreatePackageInstance(); - if (pkgManager == nullptr) { - LOG(ERROR) << "pkgManager is nullptr"; - UPDATER_LAST_WORD(EXIT_INVALID_ARGS); - return nullptr; - } - - std::vector components; - if (pkgManager->LoadPackage(packagePath, keyPath, components) != PKG_SUCCESS) { - LOG(ERROR) << "Fail to load package"; - PkgManager::ReleasePackageInstance(pkgManager); - UPDATER_LAST_WORD(EXIT_INVALID_ARGS); - return nullptr; - } - - return pkgManager; -} - int ProcessUpdater(bool retry, int pipeFd, const std::string &packagePath, const std::string &keyPath) { UPDATER_INIT_RECORD; UpdaterInit::GetInstance().InvokeEvent(UPDATER_BINARY_INIT_EVENT); Dump::GetInstance().RegisterDump("DumpHelperLog", std::make_unique()); - FILE *pipeWrite = fdopen(pipeFd, "w"); + std::unique_ptr pipeWrite(fdopen(pipeFd, "w"), fclose); if (pipeWrite == nullptr) { LOG(ERROR) << "Fail to fdopen, err: " << strerror(errno); UPDATER_LAST_WORD(EXIT_INVALID_ARGS); @@ -493,28 +469,35 @@ int ProcessUpdater(bool retry, int pipeFd, const std::string &packagePath, const } int ret = -1; Detail::ScopeGuard guard([&] { - (void)fprintf(pipeWrite, "subProcessResult:%d\n", ret); - (void)fflush(pipeWrite); - fclose(pipeWrite); - pipeWrite = nullptr; + (void)fprintf(pipeWrite.get(), "subProcessResult:%d\n", ret); + (void)fflush(pipeWrite.get()); }); // line buffered, make sure parent read per line. - setlinebuf(pipeWrite); - PkgManager::PkgManagerPtr pkgManager = LoadPackage(packagePath, keyPath); + setlinebuf(pipeWrite.get()); + PkgManager::PkgManagerPtr pkgManager = PkgManager::CreatePackageInstance(); if (pkgManager == nullptr) { + LOG(ERROR) << "pkgManager is nullptr"; UPDATER_LAST_WORD(EXIT_INVALID_ARGS); return EXIT_INVALID_ARGS; } + std::vector components; + ret = pkgManager->LoadPackage(packagePath, keyPath, components); + if (ret != PKG_SUCCESS) { + LOG(ERROR) << "Fail to load package"; + PkgManager::ReleasePackageInstance(pkgManager); + UPDATER_LAST_WORD(EXIT_INVALID_ARGS); + return EXIT_INVALID_ARGS; + } #ifdef UPDATER_USE_PTABLE DevicePtable::GetInstance().LoadPartitionInfo(); #endif ret = Updater::ExecUpdate(pkgManager, retry, packagePath, [&pipeWrite](const char *cmd, const char *content) { - if (pipeWrite != nullptr) { - (void)fprintf(pipeWrite, "%s:%s\n", cmd, content); - (void)fflush(pipeWrite); + if (pipeWrite.get() != nullptr) { + (void)fprintf(pipeWrite.get(), "%s:%s\n", cmd, content); + (void)fflush(pipeWrite.get()); } }); PkgManager::ReleasePackageInstance(pkgManager); diff --git a/test/unittest/updater_binary/update_image_block_test.cpp b/test/unittest/updater_binary/update_image_block_test.cpp index f7fb6226..05618757 100755 --- a/test/unittest/updater_binary/update_image_block_test.cpp +++ b/test/unittest/updater_binary/update_image_block_test.cpp @@ -38,7 +38,7 @@ #include "update_processor.h" #include "utils.h" -using namespace Updater; +using namespace Updater; using namespace testing::ext; using namespace Uscript; using namespace std; @@ -61,6 +61,8 @@ void UpdateImageBlockTest::TearDown() HWTEST_F(UpdateImageBlockTest, update_image_block_test_001, TestSize.Level1) { const string packagePath = "/data/updater/updater/updater_write_miscblock_img.zip"; + int fd = open("/dev/null", O_RDWR); + dup2(fd, STDOUT_FILENO); int32_t ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); EXPECT_EQ(ret, 0); } @@ -69,6 +71,8 @@ HWTEST_F(UpdateImageBlockTest, update_image_block_test_001, TestSize.Level1) HWTEST_F(UpdateImageBlockTest, update_image_block_test_002, TestSize.Level1) { const string packagePath = "/data/updater/updater/updater_write_diff_miscblock_img.zip"; + int fd = open("/dev/null", O_RDWR); + dup2(fd, STDOUT_FILENO); int32_t ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); EXPECT_EQ(ret, 0); } @@ -77,6 +81,8 @@ HWTEST_F(UpdateImageBlockTest, update_image_block_test_002, TestSize.Level1) HWTEST_F(UpdateImageBlockTest, update_image_block_test_003, TestSize.Level1) { const string packagePath = "/data/updater/updater/updater_write_diff_miscblock_img.zip"; + int fd = open("/dev/null", O_RDWR); + dup2(fd, STDOUT_FILENO); int32_t ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); EXPECT_EQ(ret, USCRIPT_INVALID_PARAM); } diff --git a/test/unittest/updater_binary/update_processor_unittest.cpp b/test/unittest/updater_binary/update_processor_unittest.cpp index 8e79bd75..33a0ef62 100755 --- a/test/unittest/updater_binary/update_processor_unittest.cpp +++ b/test/unittest/updater_binary/update_processor_unittest.cpp @@ -72,6 +72,8 @@ void UpdateProcessorUnitTest::TearDownTestCase(void) {} HWTEST_F(UpdateProcessorUnitTest, UpdateProcessor_001, TestSize.Level1) { const string packagePath = "/data/updater/updater/updater_write_misc_img.zip"; + int fd = open("/dev/null", O_RDWR); + dup2(fd, STDOUT_FILENO); int32_t ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); EXPECT_EQ(ret, 0); } @@ -85,6 +87,8 @@ HWTEST_F(UpdateProcessorUnitTest, UpdateProcessor_002, TestSize.Level1) EXPECT_EQ(ret, 0); const string packagePath = "/data/updater/updater/updater_write_diff_misc_img.zip"; + int fd = open("/dev/null", O_RDWR); + dup2(fd, STDOUT_FILENO); ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); EXPECT_EQ(ret, 0); } @@ -98,6 +102,8 @@ HWTEST_F(UpdateProcessorUnitTest, UpdateProcessor_003, TestSize.Level1) EXPECT_EQ(ret, 0); const string packagePath = "/data/updater/updater/updater_write_diff_misc_img.zip"; + int fd = open("/dev/null", O_RDWR); + dup2(fd, STDOUT_FILENO); ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); EXPECT_EQ(ret, USCRIPT_INVALID_PARAM); } -- Gitee From bc7a718a0e93416617b4f054a1476c5a1ad92fb0 Mon Sep 17 00:00:00 2001 From: richard Date: Sat, 24 Aug 2024 04:01:15 +0000 Subject: [PATCH 50/52] add Signed-off-by: richard --- test/unittest/updater_binary/update_image_block_test.cpp | 3 +++ test/unittest/updater_binary/update_processor_unittest.cpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/test/unittest/updater_binary/update_image_block_test.cpp b/test/unittest/updater_binary/update_image_block_test.cpp index 05618757..b00ac8c1 100755 --- a/test/unittest/updater_binary/update_image_block_test.cpp +++ b/test/unittest/updater_binary/update_image_block_test.cpp @@ -64,6 +64,7 @@ HWTEST_F(UpdateImageBlockTest, update_image_block_test_001, TestSize.Level1) int fd = open("/dev/null", O_RDWR); dup2(fd, STDOUT_FILENO); int32_t ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); + close(fd); EXPECT_EQ(ret, 0); } @@ -74,6 +75,7 @@ HWTEST_F(UpdateImageBlockTest, update_image_block_test_002, TestSize.Level1) int fd = open("/dev/null", O_RDWR); dup2(fd, STDOUT_FILENO); int32_t ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); + close(fd); EXPECT_EQ(ret, 0); } @@ -84,6 +86,7 @@ HWTEST_F(UpdateImageBlockTest, update_image_block_test_003, TestSize.Level1) int fd = open("/dev/null", O_RDWR); dup2(fd, STDOUT_FILENO); int32_t ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); + close(fd); EXPECT_EQ(ret, USCRIPT_INVALID_PARAM); } } diff --git a/test/unittest/updater_binary/update_processor_unittest.cpp b/test/unittest/updater_binary/update_processor_unittest.cpp index 33a0ef62..39cb050e 100755 --- a/test/unittest/updater_binary/update_processor_unittest.cpp +++ b/test/unittest/updater_binary/update_processor_unittest.cpp @@ -75,6 +75,7 @@ HWTEST_F(UpdateProcessorUnitTest, UpdateProcessor_001, TestSize.Level1) int fd = open("/dev/null", O_RDWR); dup2(fd, STDOUT_FILENO); int32_t ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); + close(fd); EXPECT_EQ(ret, 0); } @@ -90,6 +91,7 @@ HWTEST_F(UpdateProcessorUnitTest, UpdateProcessor_002, TestSize.Level1) int fd = open("/dev/null", O_RDWR); dup2(fd, STDOUT_FILENO); ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); + close(fd); EXPECT_EQ(ret, 0); } @@ -105,6 +107,7 @@ HWTEST_F(UpdateProcessorUnitTest, UpdateProcessor_003, TestSize.Level1) int fd = open("/dev/null", O_RDWR); dup2(fd, STDOUT_FILENO); ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); + close(fd); EXPECT_EQ(ret, USCRIPT_INVALID_PARAM); } -- Gitee From ee9539ee63a870af61569aeb82ae35e12016b4ad Mon Sep 17 00:00:00 2001 From: richard Date: Sat, 24 Aug 2024 04:16:43 +0000 Subject: [PATCH 51/52] add Signed-off-by: richard --- test/unittest/updater_binary/update_image_block_test.cpp | 6 +++--- test/unittest/updater_binary/update_processor_unittest.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/unittest/updater_binary/update_image_block_test.cpp b/test/unittest/updater_binary/update_image_block_test.cpp index b00ac8c1..f91641f8 100755 --- a/test/unittest/updater_binary/update_image_block_test.cpp +++ b/test/unittest/updater_binary/update_image_block_test.cpp @@ -63,8 +63,8 @@ HWTEST_F(UpdateImageBlockTest, update_image_block_test_001, TestSize.Level1) const string packagePath = "/data/updater/updater/updater_write_miscblock_img.zip"; int fd = open("/dev/null", O_RDWR); dup2(fd, STDOUT_FILENO); - int32_t ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); close(fd); + int32_t ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); EXPECT_EQ(ret, 0); } @@ -74,8 +74,8 @@ HWTEST_F(UpdateImageBlockTest, update_image_block_test_002, TestSize.Level1) const string packagePath = "/data/updater/updater/updater_write_diff_miscblock_img.zip"; int fd = open("/dev/null", O_RDWR); dup2(fd, STDOUT_FILENO); - int32_t ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); close(fd); + int32_t ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); EXPECT_EQ(ret, 0); } @@ -85,8 +85,8 @@ HWTEST_F(UpdateImageBlockTest, update_image_block_test_003, TestSize.Level1) const string packagePath = "/data/updater/updater/updater_write_diff_miscblock_img.zip"; int fd = open("/dev/null", O_RDWR); dup2(fd, STDOUT_FILENO); - int32_t ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); close(fd); + int32_t ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); EXPECT_EQ(ret, USCRIPT_INVALID_PARAM); } } diff --git a/test/unittest/updater_binary/update_processor_unittest.cpp b/test/unittest/updater_binary/update_processor_unittest.cpp index 39cb050e..b7424a3a 100755 --- a/test/unittest/updater_binary/update_processor_unittest.cpp +++ b/test/unittest/updater_binary/update_processor_unittest.cpp @@ -74,8 +74,8 @@ HWTEST_F(UpdateProcessorUnitTest, UpdateProcessor_001, TestSize.Level1) const string packagePath = "/data/updater/updater/updater_write_misc_img.zip"; int fd = open("/dev/null", O_RDWR); dup2(fd, STDOUT_FILENO); - int32_t ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); close(fd); + int32_t ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); EXPECT_EQ(ret, 0); } @@ -90,8 +90,8 @@ HWTEST_F(UpdateProcessorUnitTest, UpdateProcessor_002, TestSize.Level1) const string packagePath = "/data/updater/updater/updater_write_diff_misc_img.zip"; int fd = open("/dev/null", O_RDWR); dup2(fd, STDOUT_FILENO); - ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); close(fd); + ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); EXPECT_EQ(ret, 0); } @@ -106,8 +106,8 @@ HWTEST_F(UpdateProcessorUnitTest, UpdateProcessor_003, TestSize.Level1) const string packagePath = "/data/updater/updater/updater_write_diff_misc_img.zip"; int fd = open("/dev/null", O_RDWR); dup2(fd, STDOUT_FILENO); - ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); close(fd); + ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); EXPECT_EQ(ret, USCRIPT_INVALID_PARAM); } -- Gitee From 97ec8e6489c2bc8d8ef2b0e860a6198d105cd80e Mon Sep 17 00:00:00 2001 From: richard Date: Sat, 24 Aug 2024 04:23:11 +0000 Subject: [PATCH 52/52] ass Signed-off-by: richard --- test/unittest/updater_binary/update_image_block_test.cpp | 6 +++--- test/unittest/updater_binary/update_processor_unittest.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/unittest/updater_binary/update_image_block_test.cpp b/test/unittest/updater_binary/update_image_block_test.cpp index f91641f8..b00ac8c1 100755 --- a/test/unittest/updater_binary/update_image_block_test.cpp +++ b/test/unittest/updater_binary/update_image_block_test.cpp @@ -63,8 +63,8 @@ HWTEST_F(UpdateImageBlockTest, update_image_block_test_001, TestSize.Level1) const string packagePath = "/data/updater/updater/updater_write_miscblock_img.zip"; int fd = open("/dev/null", O_RDWR); dup2(fd, STDOUT_FILENO); - close(fd); int32_t ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); + close(fd); EXPECT_EQ(ret, 0); } @@ -74,8 +74,8 @@ HWTEST_F(UpdateImageBlockTest, update_image_block_test_002, TestSize.Level1) const string packagePath = "/data/updater/updater/updater_write_diff_miscblock_img.zip"; int fd = open("/dev/null", O_RDWR); dup2(fd, STDOUT_FILENO); - close(fd); int32_t ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); + close(fd); EXPECT_EQ(ret, 0); } @@ -85,8 +85,8 @@ HWTEST_F(UpdateImageBlockTest, update_image_block_test_003, TestSize.Level1) const string packagePath = "/data/updater/updater/updater_write_diff_miscblock_img.zip"; int fd = open("/dev/null", O_RDWR); dup2(fd, STDOUT_FILENO); - close(fd); int32_t ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); + close(fd); EXPECT_EQ(ret, USCRIPT_INVALID_PARAM); } } diff --git a/test/unittest/updater_binary/update_processor_unittest.cpp b/test/unittest/updater_binary/update_processor_unittest.cpp index b7424a3a..39cb050e 100755 --- a/test/unittest/updater_binary/update_processor_unittest.cpp +++ b/test/unittest/updater_binary/update_processor_unittest.cpp @@ -74,8 +74,8 @@ HWTEST_F(UpdateProcessorUnitTest, UpdateProcessor_001, TestSize.Level1) const string packagePath = "/data/updater/updater/updater_write_misc_img.zip"; int fd = open("/dev/null", O_RDWR); dup2(fd, STDOUT_FILENO); - close(fd); int32_t ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); + close(fd); EXPECT_EQ(ret, 0); } @@ -90,8 +90,8 @@ HWTEST_F(UpdateProcessorUnitTest, UpdateProcessor_002, TestSize.Level1) const string packagePath = "/data/updater/updater/updater_write_diff_misc_img.zip"; int fd = open("/dev/null", O_RDWR); dup2(fd, STDOUT_FILENO); - close(fd); ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); + close(fd); EXPECT_EQ(ret, 0); } @@ -106,8 +106,8 @@ HWTEST_F(UpdateProcessorUnitTest, UpdateProcessor_003, TestSize.Level1) const string packagePath = "/data/updater/updater/updater_write_diff_misc_img.zip"; int fd = open("/dev/null", O_RDWR); dup2(fd, STDOUT_FILENO); - close(fd); ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); + close(fd); EXPECT_EQ(ret, USCRIPT_INVALID_PARAM); } -- Gitee