From 0d76fc5bd467180fa526d2ba8674e19777b4fd72 Mon Sep 17 00:00:00 2001 From: lidanyang Date: Wed, 24 Jul 2024 19:11:27 +0800 Subject: [PATCH 01/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] =?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/26] =?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/26] =?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/26] =?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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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 123673ea7b36fb620072ed04eb720c993b68b909 Mon Sep 17 00:00:00 2001 From: xieluyao Date: Fri, 16 Aug 2024 16:24:57 +0800 Subject: [PATCH 26/26] update Signed-off-by: xieluyao --- test/unittest/updater_binary/BUILD.gn | 6 +----- .../updater_binary/update_partitions_unittest.cpp | 6 ++---- test/unittest/updater_binary/updater_binary_unittest.cpp | 2 ++ test/unittest/updater_ui_test/BUILD.gn | 8 +------- .../updater_ui_test/view/ui_graphic_engine_unittest.cpp | 1 - test/unittest/utils/utils_unittest.cpp | 2 -- updater_default_cfg.gni | 2 +- utils/utils.cpp | 7 ++++--- 8 files changed, 11 insertions(+), 23 deletions(-) diff --git a/test/unittest/updater_binary/BUILD.gn b/test/unittest/updater_binary/BUILD.gn index 443aa650..9df5834b 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", ] @@ -33,7 +32,6 @@ ohos_unittest("binary_unittest") { "${updater_path}/services/updater_binary/update_image_patch.cpp", "${updater_path}/services/updater_binary/update_partitions.cpp", "${updater_path}/services/updater_binary/update_processor.cpp", - "${updater_path}/utils/utils.cpp", ] include_dirs = [ @@ -48,7 +46,6 @@ ohos_unittest("binary_unittest") { "${updater_path}/services/include", "${updater_path}/utils/include", "${updater_path}/utils/json", - "${updater_path}/services/package/pkg_algorithm", "${updater_path}/services/include/applypatch", "${updater_path}/services/script/script_manager", "${updater_path}/services/script/script_interpreter", @@ -78,10 +75,9 @@ ohos_unittest("binary_unittest") { "googletest:gtest_main", "hilog:libhilog", "init:libbegetutil_static", - "init:libfsmanager_static_real", "lz4:liblz4_static", "openssl:libcrypto_shared", - "openssl:libssl_shared", + "openssl:libssl_static", "zlib:libz", ] install_enable = true diff --git a/test/unittest/updater_binary/update_partitions_unittest.cpp b/test/unittest/updater_binary/update_partitions_unittest.cpp index 157c727c..504ded8a 100755 --- a/test/unittest/updater_binary/update_partitions_unittest.cpp +++ b/test/unittest/updater_binary/update_partitions_unittest.cpp @@ -61,8 +61,7 @@ HWTEST_F(UpdatePartitionsUnitTest, UpdatePartitions_Unitest01, TestSize.Level1) int ret = pkgManager->LoadPackage(packagePath, GetTestCertName(), components); cout << "load package's ret:" << ret << endl; UpdaterEnv* env = new UpdaterEnv(pkgManager, nullptr, false); - Hpackage::HashDataVerifier scriptVerifier {pkgManager}; - ScriptManager* scriptManager = ScriptManager::GetScriptManager(env, &scriptVerifier); + ScriptManager* scriptManager = ScriptManager::GetScriptManager(env); for (int32_t i = 0; i < ScriptManager::MAX_PRIORITY; i++) { ret = scriptManager->ExecuteScript(i); cout << " execute ret:" << ret << endl; @@ -85,8 +84,7 @@ HWTEST_F(UpdatePartitionsUnitTest, UpdatePartitions_Unitest02, TestSize.Level1) int ret = pkgManager->LoadPackage(packagePath, GetTestCertName(), components); cout << "load package's ret:" << ret << endl; UpdaterEnv* env = new UpdaterEnv(pkgManager, nullptr, false); - Hpackage::HashDataVerifier scriptVerifier {pkgManager}; - ScriptManager* scriptManager = ScriptManager::GetScriptManager(env, &scriptVerifier); + ScriptManager* scriptManager = ScriptManager::GetScriptManager(env); for (int32_t i = 0; i < ScriptManager::MAX_PRIORITY; i++) { ret = scriptManager->ExecuteScript(i); cout << " execute ret:" << ret << endl; diff --git a/test/unittest/updater_binary/updater_binary_unittest.cpp b/test/unittest/updater_binary/updater_binary_unittest.cpp index efb2d882..6ddcb012 100755 --- a/test/unittest/updater_binary/updater_binary_unittest.cpp +++ b/test/unittest/updater_binary/updater_binary_unittest.cpp @@ -26,12 +26,14 @@ #include "script_utils.h" #include "unittest_comm.h" #include "update_processor.h" +#include "utils.h" using namespace std; using namespace Hpackage; using namespace Uscript; using namespace Updater; using namespace testing::ext; +using namespace Updater::Utils; namespace { class UpdaterBinaryUnittest : public ::testing::Test { diff --git a/test/unittest/updater_ui_test/BUILD.gn b/test/unittest/updater_ui_test/BUILD.gn index 559ed68f..a05ba1f7 100644 --- a/test/unittest/updater_ui_test/BUILD.gn +++ b/test/unittest/updater_ui_test/BUILD.gn @@ -33,10 +33,6 @@ ohos_unittest("ui_unittest") { ] sources = [ "control/ui_control_unittest.cpp", - "driver/fbdev_driver_unittest.cpp", - "driver/keys_input_device_unittest.cpp", - "driver/pointers_input_device_unittest.cpp", - "driver/ui_rotation_unittest.cpp", "lang/ui_language_unittest.cpp", "strategy/ui_strategy_unittest.cpp", "view/ui_component_unittest.cpp", @@ -51,8 +47,6 @@ ohos_unittest("ui_unittest") { "${updater_path}/services/ui/driver/drm_driver.cpp", "${updater_path}/services/ui/driver/fbdev_driver.cpp", "${updater_path}/services/ui/driver/graphic_engine.cpp", - "${updater_path}/services/ui/driver/keys_input_device.cpp", - "${updater_path}/services/ui/driver/pointers_input_device.cpp", "${updater_path}/services/ui/driver/surface_dev.cpp", "${updater_path}/services/ui/driver/ui_rotation.cpp", "${updater_path}/services/ui/language/language_ui.cpp", @@ -92,6 +86,7 @@ ohos_unittest("ui_unittest") { "${updater_path}/interfaces/kits/packages:libpackageExt", "${updater_path}/services/log:libupdaterlog", "${updater_path}/utils:libutils", + "//third_party/libdrm:libdrm", ] configs = [ "${updater_path}/test/unittest:utest_config" ] external_deps = [ @@ -102,7 +97,6 @@ ohos_unittest("ui_unittest") { "googletest:gmock_main", "googletest:gtest_main", "hilog:libhilog", - "libdrm:libdrm", "libpng:libpng", "ui_lite:libupdater_layout", ] diff --git a/test/unittest/updater_ui_test/view/ui_graphic_engine_unittest.cpp b/test/unittest/updater_ui_test/view/ui_graphic_engine_unittest.cpp index bff8b9f6..893b43f5 100644 --- a/test/unittest/updater_ui_test/view/ui_graphic_engine_unittest.cpp +++ b/test/unittest/updater_ui_test/view/ui_graphic_engine_unittest.cpp @@ -46,7 +46,6 @@ public: HWTEST_F(UpdaterUiGraphicEngineUnitTest, test_ui_graphic_engine_test01, TestSize.Level0) { - UiRotation::GetInstance().SetDegree(UI_ROTATION_DEGREE::UI_ROTATION_0); GraphicEngine::GetInstance().Init(WHITE_BGCOLOR, OHOS::ColorMode::ARGB8888, FONT_PATH); uint16_t height = OHOS::Screen::GetInstance().GetHeight(); uint16_t width = OHOS::Screen::GetInstance().GetWidth(); diff --git a/test/unittest/utils/utils_unittest.cpp b/test/unittest/utils/utils_unittest.cpp index 70330e5b..89b974b4 100755 --- a/test/unittest/utils/utils_unittest.cpp +++ b/test/unittest/utils/utils_unittest.cpp @@ -183,7 +183,5 @@ HWTEST_F(UtilsUnitTest, TrimUpdateMode, TestSize.Level0) EXPECT_EQ(Utils::TrimUpdateMode(sdcardMode), "sdcard_update"); const std::string intralMode = "--sdcard_intral_update"; EXPECT_EQ(Utils::TrimUpdateMode(intralMode), "sdcard_intral_update"); - const std::string emptyStr = ""; - EXPECT_EQ(Utils::TrimUpdateMode(emptyStr), ""); } } // updater_ut diff --git a/updater_default_cfg.gni b/updater_default_cfg.gni index 2f8f2101..ca51e0ec 100644 --- a/updater_default_cfg.gni +++ b/updater_default_cfg.gni @@ -13,7 +13,7 @@ import("//build/ohos.gni") -init_feature_ab_partition = false +enable_ohos_startup_init_feature_ab_partition = false declare_args() { updater_cfg_file = "" updater_ui_support = true diff --git a/utils/utils.cpp b/utils/utils.cpp index e5b50430..73b81e33 100644 --- a/utils/utils.cpp +++ b/utils/utils.cpp @@ -899,16 +899,17 @@ void SetFileAttributes(const std::string& file, uid_t owner, gid_t group, mode_t RestoreconRecurse(file.c_str()); #endif // WITH_SELINUX if (chown(file.c_str(), USER_ROOT_AUTHORITY, GROUP_ROOT_AUTHORITY) != 0) { - LOG(ERROR) << "Chown failed: " << file << " " << USER_ROOT_AUTHORITY << "," << GROUP_ROOT_AUTHORITY; + LOG(WARNING) << "Chown failed: " << file << " " << USER_ROOT_AUTHORITY << "," << GROUP_ROOT_AUTHORITY; } if (chmod(file.c_str(), mode) != EOK) { - LOG(ERROR) << "chmod failed: " << file << " " << mode; + LOG(WARNING) << "Chmod failed: " << file << " " << mode; } if (chown(file.c_str(), owner, group) != 0) { - LOG(ERROR) << "Chown failed: " << file << " " << owner << "," << group; + LOG(WARNING) << "Chown failed: " << file << " " << owner << "," << group; } } #endif + } // Utils void __attribute__((weak)) InitLogger(const std::string &tag) { -- Gitee