diff --git a/BUILD.gn b/BUILD.gn index ac948c97d5f4803f8fc62fe764ced458deba90d8..4c82fe12f6cd6f6dbd2ebb29dfc9c73f0d6e1e38 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.cpp b/services/factory_reset/factory_reset.cpp index 570690c9d1aa88f8f9dd50dac44bac0ce1485433..88c6ebc7932a632973a595cc3c9ad020e42b9915 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,27 +47,35 @@ 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) { + 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) { + resetStatus = 1; + LOG(ERROR) << "CommonResetPostFunc_ fail"; + 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() @@ -122,15 +131,12 @@ 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; } -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) diff --git a/services/factory_reset/factory_reset.h b/services/factory_reset/factory_reset.h index 192df9cc06fb933ecd1103f282abeb60ac733858..053631f8bcb696d47f1e4063e33345c27bc9521e 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_; diff --git a/services/include/applypatch/transfer_manager.h b/services/include/applypatch/transfer_manager.h index 65b0510188ee1f9ace2208b328eee777815459f7..3956e7ca5bc79183d8dd262999c4fd3fb424bd9a 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/include/package/pkg_manager.h b/services/include/package/pkg_manager.h index a455c619bfd6bdf1460fbbe12a55a6526661c30c..4420287b3e572e4de9fd56d1c8eaf2602f7a99cc 100644 --- a/services/include/package/pkg_manager.h +++ b/services/include/package/pkg_manager.h @@ -260,6 +260,8 @@ public: 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; + virtual int32_t VerifyOtaPackage(const std::string &packagePath) = 0; virtual int32_t VerifyBinFile(const std::string &packagePath, const std::string &keyPath, diff --git a/services/include/updater/updater.h b/services/include/updater/updater.h index a51a294ec3421619727a8248ebb4f71ce02d1c63..7c3fd9fa8b7369302de9aff1b6a9c6bd6eb4acbb 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/include/updater/updater_const.h b/services/include/updater/updater_const.h index 9466c8bd030a7c5d1e4e7df692e23c30109bd7e6..672f638388dc91b2074ff44b267b6e4de4c86afe 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_UPDATE_FROM_DATA = "sdUpdateFromData"; #ifndef UPDATER_UT constexpr const char *SDCARD_CARD_PATH = "/sdcard/updater"; diff --git a/services/package/pkg_manager/pkg_managerImpl.cpp b/services/package/pkg_manager/pkg_managerImpl.cpp index 817c0b002ab932f70fffb736db505cb87b2c1c21..32a73b417e8485c0fa43e40c90bbb940a15c90a7 100644 --- a/services/package/pkg_manager/pkg_managerImpl.cpp +++ b/services/package/pkg_manager/pkg_managerImpl.cpp @@ -15,8 +15,10 @@ #include "pkg_manager_impl.h" #include #include +#include #include #include +#include #include #include #include @@ -30,6 +32,7 @@ #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" @@ -987,6 +990,57 @@ int32_t PkgManagerImpl::VerifyAccPackage(const std::string &packagePath, const s return PKG_SUCCESS; } +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) { + PKG_LOGE("invalid param %zu %" PRIu64 " %zu", size, offset, offsetAligned); + return PKG_INVALID_PARAM; + } + 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); + if (fd < 0) { + PKG_LOGE("open %s fail, %s", devRealPath, 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, devRealPath, 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, devRealPath, buffer); + if (ret != PKG_SUCCESS) { + PKG_LOGE("create package stream fail %s %s", devRealPath, strerror(errno)); + return ret; + } + ON_SCOPE_EXIT(closeStream) { + ClosePkgStream(pkgStream); + }; + PkgVerifyUtil verifyUtil {}; + ret = verifyUtil.VerifyPackageSign(pkgStream); + if (ret != PKG_SUCCESS) { + PKG_LOGE("verify pkcs7 signature failed."); + return ret; + } +#endif + return PKG_SUCCESS; +} + int32_t PkgManagerImpl::VerifyOtaPackage(const std::string &packagePath) { PkgStreamPtr pkgStream = nullptr; diff --git a/services/package/pkg_manager/pkg_manager_impl.h b/services/package/pkg_manager/pkg_manager_impl.h index 9cab6bd7707abc4c9a2b84ee498358f0f92a86c8..fa421d5393c831cb327aadc4f7d4cd55a922a5bd 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; diff --git a/services/ptable_parse/emmc_ptable.cpp b/services/ptable_parse/emmc_ptable.cpp index 8bce4a2a05592d29f370903c42fe68ea15b0c32d..4c398ee62927476f4557eb0cef805d0672542c47 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 fcec50f73188981cc2de4d0f004e10c7d5c98865..60963db15c05ab57b6a7aa45dc184fa9781c0aed 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 ef0d4766d73d4642ce729a187c47f3141f9b4efd..f13bf526e67039730474d2b04670c7bcc933db58 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 (GetSdcardInternalPkgs(upParams) == UPDATE_SUCCESS) { + LOG(INFO) << "get sdcard internal 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 GetSdcardInternalPkgs(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 5e607594216f6640d668bcc38cead7fa69a3fdc5..9f238b0375ad9bb6e5bd4dbf4546b4256634d464 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 GetSdcardInternalPkgs(UpdaterParams &upParams); #ifdef __cplusplus #if __cplusplus } diff --git a/services/ui/control/event_listener.cpp b/services/ui/control/event_listener.cpp index 93f6c92de11baa90daddfd1f5318bfa2cfabc19f..14974a9381a38b1f4197bbc6996fb7211f1886e5 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/services/ui/view/view_api.cpp b/services/ui/view/view_api.cpp index c8bf1d481e59be13432e20958344a1fde28fa01a..fb870502480b22618e0b4899009e3b4d723bddd3 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 > static_cast(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/services/updater.cpp b/services/updater.cpp index 36f90f3fbadff6212942b83c52f46e72164280d7..b70463019b32fb1c5a6b014f5d4097d7867f943a 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) { + 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); return UPDATE_ERROR; @@ -278,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."; @@ -402,8 +402,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; } @@ -433,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/services/updater_binary/update_image_block.cpp b/services/updater_binary/update_image_block.cpp index 21926f8e4e6f67fd7b1d30646528408936a60af0..16a30ff0df8e4d4e4b0f4b2e5adde09b8080bb2f 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; @@ -471,21 +472,26 @@ 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; + LOG(ERROR) << "resultSha: " << resultSha << ", shaInfo.contrastSha: " << shaInfo.contrastSha; PrintAbnormalBlockHash(devPath, shaInfo.blockPairs); UPDATER_LAST_WORD(devPath.substr(devPath.find_last_of("/") + 1), USCRIPT_ERROR_EXECUTE); env.PostMessage(UPDATER_RETRY_TAG, VERIFY_FAILED_REBOOT); diff --git a/services/updater_binary/update_image_block.h b/services/updater_binary/update_image_block.h index 2006b5ae328e5c19ded8c7809312687d83ec5fc4..fe2e39bd5950742640efa54da2a3fd6c62ead45f 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); }; } diff --git a/services/updater_binary/update_processor.cpp b/services/updater_binary/update_processor.cpp index 71242e1540b0598235737a7fb81d6576db8bce86..5045e2df3a7a94f6f7e1b96f8c42b270ac160d15 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,49 +461,47 @@ 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([&] { + (void)fprintf(pipeWrite.get(), "subProcessResult:%d\n", ret); + (void)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) { + (void)fprintf(pipeWrite.get(), "%s:%s\n", cmd, content); + (void)fflush(pipeWrite.get()); } }); PkgManager::ReleasePackageInstance(pkgManager); #ifndef UPDATER_UT - fclose(pipeWrite); - pipeWrite = nullptr; if (ret == 0) { SetActiveSlot(); } diff --git a/services/updater_main.cpp b/services/updater_main.cpp index b0d12d7da6668b69012280e030260c24c97d1dd2..33643e2d96942d5453fa865965d1793703725638 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 !!! } @@ -793,7 +791,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_UPDATE_FROM_DATA) { Utils::UpdaterDoReboot("updater", "--user_wipe_data"); return; } diff --git a/services/updater_main.h b/services/updater_main.h index f0019166fe3a2c8e61904e321d5532a3bbcc637d..29e0e41e6bc6644d1af4adc2428f75d5b8f84481 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_MODE, }; int UpdaterMain(int argc, char **argv); diff --git a/services/updater_ui.cpp b/services/updater_ui.cpp index bc0819327a708a9eb35d661f21f1d477d9aa1fc8..c1fa1cbc0b4d39644fc0c0fbdaa367d83ad06f09 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); diff --git a/test/fuzztest/UpdaterStartUpdaterProc_fuzzer/UpdaterStartUpdaterProc_fuzzer.cpp b/test/fuzztest/UpdaterStartUpdaterProc_fuzzer/UpdaterStartUpdaterProc_fuzzer.cpp index d59dcd28b0b8e7d36fad9e9c714dc5d2c5a95de8..1a3120b2cf9fd97113b3f1bcfc8ae522a60ce3fa 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/factory_reset_test/BUILD.gn b/test/unittest/factory_reset_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..ea3120e981c2604fceb7067ce4119f0808e39963 --- /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 0000000000000000000000000000000000000000..8a00103076fe30e781a08560812b5f434415b057 --- /dev/null +++ b/test/unittest/factory_reset_test/factory_reset_unittest.cpp @@ -0,0 +1,102 @@ +/* + * 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 +#define private public +#include "factory_reset.h" +#undef private + +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_MODE, "/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 diff --git a/test/unittest/flashd_test/flashd_unittest.cpp b/test/unittest/flashd_test/flashd_unittest.cpp index 3d46a2fda070218ce9021e3d5a71894b2454c56a..d5f92db84a2db6f3a46f2563cbecdfa1f4311cd1 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"; diff --git a/test/unittest/script/script_unittest.h b/test/unittest/script/script_unittest.h index 34a70a48c8d8b1740b7a812ddac5f7ec95d3e942..c5001bdf81051d960b8b95d11a7d560124c676c5 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 { diff --git a/test/unittest/service_test/updater_service_unittest.cpp b/test/unittest/service_test/updater_service_unittest.cpp index 9921041470cc7d7785b9f658643a90577bbe8d2b..5b868efc7e12d686ec58ea46536187226c5ae2fc 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/test_data/ohos_test.xml b/test/unittest/test_data/ohos_test.xml index 9389c6f674117588ed65a57310907d9d999d956a..65bfbb0db66fb398b44c0f795a21ced6cc28d2b0 100644 --- a/test/unittest/test_data/ohos_test.xml +++ b/test/unittest/test_data/ohos_test.xml @@ -203,6 +203,8 @@