diff --git a/services/diffpatch/patch/image_patch.cpp b/services/diffpatch/patch/image_patch.cpp index 7c313929c4a547536b507265e6db080fdf467052..6e77cd8111fe0ae8d5f8af2ad42f75ff344fcb17 100644 --- a/services/diffpatch/patch/image_patch.cpp +++ b/services/diffpatch/patch/image_patch.cpp @@ -44,7 +44,8 @@ int32_t NormalImagePatch::ApplyImagePatch(const PatchParam ¶m, size_t &start offset += sizeof(int64_t); size_t patchOffset = static_cast(ReadLE(param.patch + offset)); offset += sizeof(int64_t); - if (srcStart + srcLen > param.oldSize) { + if (srcStart > param.oldSize || param.oldSize - srcStart < srcLen || + patchOffset > param.patchSzie) { PATCH_LOGE("error, srcStart: %zu srcLen: %zu , param.oldSize: %zu, patchOffset: %zu", srcStart, srcLen, param.oldSize, patchOffset); return -1; @@ -96,8 +97,10 @@ int32_t CompressedImagePatch::StartReadHeader(const PatchParam ¶m, PatchHead } PATCH_LOGI("ApplyImagePatch srcStart %zu srcLen %zu patchOffset: %zu expandedLen:%zu %zu", header.srcStart, header.srcLength, header.patchOffset, header.expandedLen, header.targetSize); - if (header.srcStart + header.srcLength > param.oldSize) { - PATCH_LOGE("Failed to check patch"); + if (header.srcStart > param.oldsize || param.oldSize - header.srcStart < header.srcLength || + header.patchOffset > param.patchSize) { + PATCH_LOGE("Failed to check patch, srcStart: %zu , param.oldSize: %zu, patchOffset: %zu", + header.srcStart, header.srcLength, param.oldSize, header.patchOffset); return -1; } return 0; diff --git a/services/etc/updater_normal.cfg b/services/etc/updater_normal.cfg index 3400b8413d8848c706b56d51fb25837897639dd7..26ec19b70a9e822a0a5404d946e0f70ebcb4c0e3 100644 --- a/services/etc/updater_normal.cfg +++ b/services/etc/updater_normal.cfg @@ -14,6 +14,7 @@ "path" : ["/system/bin/write_updater", "updater_para"], "uid" : "update", "gid" : ["update", "system", "root"], + "once" : 1, "secon" : "u:r:write_updater:s0" } ] 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..5c6360723e278ec1daddc2ac47958192ca29db4c 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; + VerifyOtaPackage(const std::string &devPath, unit64_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..2a52d127c2126d2ad0fc61d4a83e71381cb36535 100644 --- a/services/package/pkg_manager/pkg_managerImpl.cpp +++ b/services/package/pkg_manager/pkg_managerImpl.cpp @@ -987,6 +987,57 @@ int32_t PkgManagerImpl::VerifyAccPackage(const std::string &packagePath, const s return PKG_SUCCESS; } +int32_t PkgManagerlmpl::VerifyOtaPakcage(const std::string &devPath,unit64_t offset, size_t size) +{ +#ifndef DIFF_PATCH_SDK + constexpr size_t pageSize = 4096; + size_t offsetAlogned = (offset / pageSize) * pageSize; + if (size == 0 || size + offset < offsetAligend || offset < offsetAligend){ + PKG_LOGE("invaild param %zu %" PRlu64 "%zu", size, offset, offsetAligned); + return PKG_INVAILD_PARAM; + } + char devRealPath[PATH_MAX + 1] = {}; + if (realpath(devPath.c_str(),devRealPath) == nullptr) { + PKG_LOGE("realPath is nullptr, err %s", strerror(erron)); + 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_INVAILD_FILE; + } + ON_SCOPE_EXIT(closePath) { + close(fd) + } + unit8_t *pMap = static_cast(mmap64(unllptr, size + offset - offsetAligned, PROT_READ, MAP_PRIVATE, + fd, offsetAligned)); + if (pMap == MAP_FAILD) { + PKG_LOGE("mmap64 %s fail, %s %zu %" PRlu64, devRealPath, strrerror(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 = CreatPkgStream(pkgStream, devRealPath, buffer); + if (ret != PKG_SUCCCESS) { + PKG_LOGE("create pakage 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..0cdeb2537742bd6823c76afa45dcfa3f9010bfa5 100644 --- a/services/package/pkg_manager/pkg_manager_impl.h +++ b/services/package/pkg_manager/pkg_manager_impl.h @@ -77,6 +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, unit64_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..9675fe2f00f9496e4852f348cf2148e7dcc92c24 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, unit32_t len) { uint32_t number = 0; + + partitionInfo_.clear(); + if (!ParseGptHeaderByEmmc(emmcPtnDataInfo_.data, len)) { + LOG(ERROR) << "Primary signatrue invaild"; + rerurn 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.wirteMode = "WIRTE_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 2lba 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..8f9ccded8a2ed7a18e4dc4e66679755eaa000a24 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, unit32_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..f504ef298924d244a3897e40095fe61fe329e7d7 100644 --- a/services/sdcard_update/sdcard_update.cpp +++ b/services/sdcard_update/sdcard_update.cpp @@ -98,6 +98,11 @@ UpdaterStatus CheckSdcardPkgs(UpdaterParams &upParams) LOG(INFO) << "get sd card from dev succeed, skip get package from sd card"; return UPDATE_SUCCESS; } + if (GetSdcardInternalPkgs(upParam == 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 +130,9 @@ UpdaterStatus CheckSdcardPkgs(UpdaterParams &upParams) } return UPDATE_SUCCESS; } + __attribute__((weak)) UpdaterStatusGetSdcardInternalPkgs(UpdaterParams &upParams) + { + LOG(INFO) << "not implemented ger normal updater 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..faced61b3ac47f342ae2746cf91ee979bc5f924c 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..44f33650cb48feaca71fe39f1b8ed95c74a5e1df 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 unit8_t colorMaxSize = 255; + int reset = Utils::String2Int(hexColor.substr(startPos, width)); + if (reset < 0 || reset > static_cast(colorMaxSize)) { + LOG(ERROR) << "String2Int error, rest =" << 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 cb0bb70ad42d8bb5045a3efcb2b3a4ffdef2352a..18d82359560bfe396a64040eba0b35a661d21af5 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_INTAL_MODE) || + Utils::CheckUpdateMode(Updater::ACTORY_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."; @@ -438,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..54357b6073079d08ad0f8a9040141896d69a8f42 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 = CaculateBlockSha(devPath, shaInfo.targetParis); + if (tgtResultSha.empty()) { + LOG(WARRING) << 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 && isTargetDiff(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..05a9767035d03cec4cb8fe9278a6227202cf0e76 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_image_patch.cpp b/services/updater_binary/update_image_patch.cpp index a10acd9db82b859beeae17aa5e6af0e6fd624734..172451b8ed5884b2483aa27d19389a0959221a0d 100644 --- a/services/updater_binary/update_image_patch.cpp +++ b/services/updater_binary/update_image_patch.cpp @@ -266,6 +266,10 @@ int32_t USInstrImageShaCheck::CheckHash(const CheckPara ¶) LOG(ERROR) << "PatchMapFile error"; return USCRIPT_ERROR_EXECUTE; } + if (!std:all_of(para.srcSize.begin(), para.srcSize.end(), ::isdigit)) { + LOG(ERROR) << "para size error" << para.srcSize; + return USCRIPT_ERROR_EXECUTE; + } size_t length = std::stoul(para.srcSize); UpdatePatch::BlockBuffer data = { mapBuffer.memory, length }; std::string resultSha = UpdatePatch::GeneraterBufferHash(data); diff --git a/services/updater_binary/update_processor.cpp b/services/updater_binary/update_processor.cpp index 5045e2df3a7a94f6f7e1b96f8c42b270ac160d15..238b4abb481e55bb7ee2982f5bd4352af7388ede 100644 --- a/services/updater_binary/update_processor.cpp +++ b/services/updater_binary/update_processor.cpp @@ -83,7 +83,7 @@ const std::vector UpdaterEnv::GetInstructionNames() const static std::vector updaterCmds = { "sha_check", "first_block_check", "block_update", "raw_image_write", "update_partitions", "image_patch", - "image_sha_check", "pkg_extract", "update_from_bin" + "image_sha_check", "pkg_extract", "pkg_extract_no_ret", "update_from_bin" }; return updaterCmds; } @@ -107,6 +107,8 @@ int32_t UpdaterInstructionFactory::CreateInstructionInstance(UScriptInstructionP instr = new USInstrImageShaCheck(); } else if (name == "pkg_extract") { instr = new UScriptInstructionPkgExtract(); + } else if (name == "pkg_extract_no_ret") { + instr = new UScriptInstructionPkgExtractRetSuc(); } else if (name == "update_from_bin") { instr = new UScriptInstructionBinFlowWrite(); } @@ -292,6 +294,15 @@ int32_t UScriptInstructionPkgExtract::Execute(Uscript::UScriptEnv &env, Uscript: return ret; } +int32_t UScriptInstructionPkgExtractRetSuc:Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context) +{ + int32_t ret = UScriptInstructionPkgExtract::Execute(env context); + if (ret != USCRIPT_SUCCESS) { + LOG(ERROR) << "Error to extract file, ret = " << ret; + } + return USCRIPT_SUCCESS; +} + int32_t UScriptInstructionUpdateFromBin::Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context) { std::string upgradeFileName; diff --git a/services/updater_binary/update_processor.h b/services/updater_binary/update_processor.h index 47d5d02b48d64394b28e8b9c3aee15de85b32b00..85a8965712fecbcda15a5e2e6b6d04f95bea28e3 100644 --- a/services/updater_binary/update_processor.h +++ b/services/updater_binary/update_processor.h @@ -85,6 +85,13 @@ public: int32_t Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context) override; }; +class UScriptInstructionUpdateFromBin : public UScriptInstructionPkgExtract { +public: + UScriptInstructionPkgExtractRetSuc() {} + ~UScriptInstructionPkgExtractRetSuc() override {} + int32_t Excute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context) override; +}; + class UScriptInstructionUpdateFromBin : public Uscript::UScriptInstruction { public: UScriptInstructionUpdateFromBin() {} diff --git a/services/updater_main.cpp b/services/updater_main.cpp index 4c4ccb62b37cb06cffd8aa89c55e0f1ac56952c3..40d2fb69b013ecf0f1d4dfa0dfcc04667ff17294 100644 --- a/services/updater_main.cpp +++ b/services/updater_main.cpp @@ -75,6 +75,7 @@ constexpr struct option OPTIONS[] = { { "UPDATE:SD", no_argument, nullptr, 0 }, { "UPDATE:SDFROMDEV", no_argument, nullptr, 0 }, { "sdcard_intral_update", optional_argument, nullptr, 0}, + { "wipe_data_factory_lowlevel", no_argument, nullptr, 0}, { nullptr, 0, nullptr, 0 }, }; constexpr float VERIFY_PERCENT = 0.05; @@ -679,6 +680,11 @@ std::unordered_map> InitOptionsFuncTab(char* (void)UPDATER_UI_INSTANCE.SetMode(UPDATERMODE_REBOOTFACTORYRST); upParams.factoryResetMode = "menu_wipe_data"; }}, + {"wipe_data_factory_lowlever", [&]() -> void + { + (void)UPDATER_UI_INSTANCE.SetMode(UPDATERMODE_REBOOTFACTORYRST); + upParams.factoryResetMode = "user_wipe_data"; + }} {"upgraded_pkg_num", [&]() -> void { upParams.pkgLocation = static_cast(atoi(optarg)); @@ -791,7 +797,7 @@ __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; } @@ -830,8 +836,6 @@ int UpdaterMain(int argc, char **argv) UPDATER_UI_INSTANCE.ShowLogRes( status == UPDATE_CORRUPT ? TR(LOGRES_VERIFY_FAILED) : TR(LOGRES_UPDATE_FAILED)); UPDATER_UI_INSTANCE.ShowFailedPage(); - Utils::UsSleep(5 * DISPLAY_TIME); // 5 : 5s - UPDATER_UI_INSTANCE.ShowMainpage(); } else if (upParams.factoryResetMode == "user_wipe_data" || upParams.factoryResetMode == "menu_wipe_data" || upParams.factoryResetMode == "factory_wipe_data") { UPDATER_UI_INSTANCE.ShowFailedPage(); diff --git a/services/updater_main.h b/services/updater_main.h index f0019166fe3a2c8e61904e321d5532a3bbcc637d..e612012cd1579205d36b8152db079040f8cd0299 100644 --- a/services/updater_main.h +++ b/services/updater_main.h @@ -25,6 +25,7 @@ namespace Updater { enum FactoryResetMode { USER_WIPE_DATA = 0, FACTORY_WIPE_DATA, + INVALID_MODE, MENU_WIPE_DATA, }; diff --git a/services/updater_ui.cpp b/services/updater_ui.cpp index c1fa1cbc0b4d39644fc0c0fbdaa367d83ad06f09..6803235642a2d7e7f1543801da193d7f313271b2 100644 --- a/services/updater_ui.cpp +++ b/services/updater_ui.cpp @@ -23,11 +23,11 @@ #include "updater_main.h" #include "updater_ui_facade.h" #include "utils.h" +#include "updater_ui_stub.h" namespace Updater { namespace { constexpr uint32_t DISPLAY_TIME = 1 * 1000 * 1000; /* 1s */ -constexpr uint32_t FAIL_DELAY = 5 * 1000 * 1000; constexpr uint32_t SUCCESS_DELAY = 3 * 1000 * 1000; constexpr int CALLBACK_DELAY = 20 * 1000; /* 20ms */ @@ -100,19 +100,18 @@ DEFINE_ASYN_CALLBACK(OnLabelSDCardEvt) DEFINE_ASYN_CALLBACK(OnLabelSDCardNoDelayEvt) { - LOG(INFO) << "On Label SDCard"; + LOG(INFO) << "On Label SDCard No Delay"; if (!GetFacade().SetMode(UPDATERMODE_SDCARD)) { return; } Utils::UsSleep(CALLBACK_DELAY); UpdaterParams upParams; upParams.updateMode = SDCARD_UPDATE; + UPDATER_UI_INSTANCE.ShowProgressPage(); 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); - GetFacade().ShowMainpage(); return; } GetFacade().ShowLogRes(TR(LABEL_UPD_OK_DONE)); 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/fuzztest/applypatch_fuzzer/applypatch_fuzzer.cpp b/test/fuzztest/applypatch_fuzzer/applypatch_fuzzer.cpp index dbd74df59d33af72992cb6f48da72e1f8938b919..ac60819486eabddd202461eedd0db3536a02ff10 100644 --- a/test/fuzztest/applypatch_fuzzer/applypatch_fuzzer.cpp +++ b/test/fuzztest/applypatch_fuzzer/applypatch_fuzzer.cpp @@ -21,15 +21,46 @@ #include #include #include +#include +#include +#include "log/log.h" using namespace Updater; namespace OHOS { + bool WriteDataToFile(const char* data, size_t size, const char* filePath) + { + std::ofstream ofs(filePath, std::ios::app | std::ios::binary); + if (!ofs.is_oper()) { + LOG(ERROR) << "open" << filePath << " failed"; + return false; + } + ofs.write(data, size); + ofs.close(); + return true; + } + void FuzzApplyPatch(const uint8_t* data, size_t size) { - const std::string filePath = "/data/fuzz/test/MountForPath_fuzzer.fstable"; - ApplyPatch(filePath, filePath, std::string(reinterpret_cast(data), size)); - ApplyPatch(filePath, std::string(reinterpret_cast(data), size), filePath); - ApplyPatch(std::string(reinterpret_cast(data), size), filePath, filePath); + bool ret =true; + const int magicNumberSize = 4; + const char* bspatchPath = "/data/applyPatchfuzzerBspatch"; + const char* imgpatchPath = "/data/applyPatchfuzzerImagpatch"; + const char* oldFilePath = "/data/applyPatchfuzzerOldFile"; + const char* newFilePath = "/data/applyPatchfuzzerNewFile"; + ret &= WriteDataToFile("BSDIFF40", magicNumSize, bspatchPath); + ret &= WriteDataToFile(reinterpret_cast(data), size, bspatchPath); + ret &= WriteDataToFile("PKGDIFF0", magicNumsize, imgpatchPth); + ret &= WriteDataToFile(reinterpret_cast(data), size, imgpatchPath); + ret &= WriteDataToFile(reinterpret_cast(data), size, oldpatchPath); + if (!ret) { + LOG(ERROR) << "create file failed"; + return; + } + ApplyPatch(bspatchPath, oldFilePath, newFilePath); + ApplyPatch(imgpatchPath,oldFilePath, newFilePath); + if (remove(bspatchPath) != 0 || remove(imgpatchPath) != 0 || remove(oldFilePath)) { + LOG(WARRING) << "Failde to delete file"; + } } } @@ -40,4 +71,3 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) OHOS::FuzzApplyPatch(data, size); return 0; } - diff --git a/test/unittest/flashd_test/flashd_unittest.cpp b/test/unittest/flashd_test/flashd_unittest.cpp index 465869fc2f6a3ffb5ad2ca8addf3ff28b6896987..b1111095ac3bfc3c35a8182d788d1549364b48bd 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..a79f92945bd7cdf336355002a4bc77de4f167f42 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) diff --git a/test/unittest/updater_binary/BUILD.gn b/test/unittest/updater_binary/BUILD.gn index 9df5834b1fc1262dcf94eeede51266203581e585..7aa7c82d7594c860e342703483e4b32c333d1fe1 100644 --- a/test/unittest/updater_binary/BUILD.gn +++ b/test/unittest/updater_binary/BUILD.gn @@ -23,6 +23,7 @@ ohos_unittest("binary_unittest") { sources = [ "update_image_block_test.cpp", "update_image_patch_unittest.cpp", + "update_partition_unittest.cpp", "update_processor_unittest.cpp", ] @@ -46,6 +47,7 @@ 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", diff --git a/test/unittest/updater_binary/update_partitions_unittest.cpp b/test/unittest/updater_binary/update_partitions_unittest.cpp index 504ded8a79d23671c6f80e1486751e6963f15e1c..369798367f8d1487a86647ad504b0d5e3582ecc8 100755 --- a/test/unittest/updater_binary/update_partitions_unittest.cpp +++ b/test/unittest/updater_binary/update_partitions_unittest.cpp @@ -61,7 +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); - ScriptManager* scriptManager = ScriptManager::GetScriptManager(env); + ScriptManager* scriptManager = ScriptManager::GetScriptManager(env, &scriptVerifier); for (int32_t i = 0; i < ScriptManager::MAX_PRIORITY; i++) { ret = scriptManager->ExecuteScript(i); cout << " execute ret:" << ret << endl; @@ -84,7 +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); - ScriptManager* scriptManager = ScriptManager::GetScriptManager(env); + ScriptManager* scriptManager = ScriptManager::GetScriptManager(env, &scriptVerifier); 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 6ddcb012a23769c4ff6bb91012b555f8ee07fa56..efb2d88236fac96927e6a6fe76bf2c4fd7c3147a 100755 --- a/test/unittest/updater_binary/updater_binary_unittest.cpp +++ b/test/unittest/updater_binary/updater_binary_unittest.cpp @@ -26,14 +26,12 @@ #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_test/updater_unittest.cpp b/test/unittest/updater_test/updater_unittest.cpp index 9e8f0c5e2f4bdbd36a186857054ef4bf48c76246..20ddcd35b581c7f23aa17fc265fa2d8deefe568b 100755 --- a/test/unittest/updater_test/updater_unittest.cpp +++ b/test/unittest/updater_test/updater_unittest.cpp @@ -71,28 +71,27 @@ HWTEST_F(UpdaterUnitTest, updater_StartUpdaterProc, TestSize.Level1) { std::string packagePath = "/data/updater/updater/updater_without_updater_binary.zip"; PkgManager::PkgManagerPtr pkgManager = PkgManager::CreatePackageInstance(); - int maxTemperature; UpdaterStatus status; - status = StartUpdaterProc(pkgManager, packagePath, 0, maxTemperature); + status = StartUpdaterProc(pkgManager, packagePath, 0); EXPECT_EQ(status, UPDATE_CORRUPT); packagePath = "/data/updater/updater/updater_with_incorrect_binary.zip"; - status = StartUpdaterProc(pkgManager, packagePath, 0, maxTemperature); + status = StartUpdaterProc(pkgManager, packagePath, 0); EXPECT_EQ(status, UPDATE_CORRUPT); packagePath = "/data/updater/updater/updater.zip"; std::vector components; int32_t ret = pkgManager->LoadPackage(packagePath, GetTestCertName(), components); EXPECT_EQ(ret, 0); - status = StartUpdaterProc(pkgManager, packagePath, 0, maxTemperature); + status = StartUpdaterProc(pkgManager, packagePath, 0); EXPECT_EQ(status, UPDATE_SUCCESS); // retrycount is greater than 0. - status = StartUpdaterProc(pkgManager, packagePath, 1, maxTemperature); + status = StartUpdaterProc(pkgManager, packagePath, 1); EXPECT_EQ(status, UPDATE_RETRY); packagePath = "/data/updater/updater/updater_binary_abnormal.zip"; - status = StartUpdaterProc(pkgManager, packagePath, 1, maxTemperature); + status = StartUpdaterProc(pkgManager, packagePath, 1); PkgManager::ReleasePackageInstance(pkgManager); EXPECT_EQ(status, UPDATE_ERROR); } diff --git a/test/unittest/updater_ui_test/BUILD.gn b/test/unittest/updater_ui_test/BUILD.gn index 8307b03e032dbf4084f5f47f9006748bc0d032fc..6e96ca68c63cf4ed36415fa27c95003952cce017 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", "lang/ui_language_unittest.cpp", "strategy/ui_strategy_unittest.cpp", "view/ui_component_unittest.cpp", @@ -42,6 +43,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", @@ -84,6 +86,7 @@ ohos_unittest("ui_unittest") { "${updater_path}/interfaces/kits/packages:libpackageExt", "${updater_path}/services/log:libupdaterlog", "${updater_path}/utils:libutils", + "//third_party/services/ui/control/event_listener.cpp", ] configs = [ "${updater_path}/test/unittest:utest_config" ] external_deps = [ diff --git a/test/unittest/updaterkits_test/updaterkits_unittest.cpp b/test/unittest/updaterkits_test/updaterkits_unittest.cpp index bd29f57c21fd67a189aca53ca75dee4e02b8309c..0ac3b7e3a86b3b13a20a27dae895cea15eec0998 100755 --- a/test/unittest/updaterkits_test/updaterkits_unittest.cpp +++ b/test/unittest/updaterkits_test/updaterkits_unittest.cpp @@ -40,7 +40,7 @@ HWTEST_F(UpdaterKitsUnitTest, updater_kits_test01, TestSize.Level1) { const std::vector packageName1 = {""}; int ret = RebootAndInstallUpgradePackage(MISC_FILE, packageName1); - EXPECT_EQ(ret, 2); // 2 : path not exit + EXPECT_EQ(ret, 1); const std::vector packageName2 = {"/data/updater/updater/updater_without_updater_binary.zip"}; auto fp = std::unique_ptr(fopen(MISC_FILE.c_str(), "wb+"), fclose); diff --git a/updater_default_cfg.gni b/updater_default_cfg.gni index ca51e0ec908b33e6190197e2898577a56a17f929..2f8f2101ab1e41f6054839b551aeca236f017ae7 100644 --- a/updater_default_cfg.gni +++ b/updater_default_cfg.gni @@ -13,7 +13,7 @@ import("//build/ohos.gni") -enable_ohos_startup_init_feature_ab_partition = false +init_feature_ab_partition = false declare_args() { updater_cfg_file = "" updater_ui_support = true diff --git a/utils/include/utils.h b/utils/include/utils.h index 018d8d08e520570f5304a124fb7e736c2803726b..7c7756ebbcd5beac55296a67b65ca346ecfd0222 100644 --- a/utils/include/utils.h +++ b/utils/include/utils.h @@ -40,6 +40,8 @@ constexpr const char* ON_SERVER = "ON_SERVER"; template T String2Int(const std::string &str, int base = N_HEX) { + static_assert(std::is_same_v || std::is_same_v || std::is_same_v, + "type should be int or size_t or unsigned long long int"); char *end = nullptr; if (str.empty()) { errno = EINVAL; @@ -48,7 +50,15 @@ T String2Int(const std::string &str, int base = N_HEX) if (((str[0] == '0') && (str[1] == 'x')) || (str[1] == 'X')) { base = N_HEX; } - T result = strtoull(str.c_str(), &end, base); + T result = 0; + if constexpr (std::is_same_v) { + result = strtol(str.c_str(), &end, base); + else if constexpr (std::is_same_v || std::is_same_v) { + result = strtoull(str.c_str(), &end, base); + } else { + errno = EINVAL; + } + } return result; } int32_t DeleteFile(const std::string& filename); diff --git a/utils/utils.cpp b/utils/utils.cpp index b41c3c48ec20f45c470b10b0170d472a7b734b9b..4f33a23c5c3afc8ec637c375f34441f04977b864 100644 --- a/utils/utils.cpp +++ b/utils/utils.cpp @@ -290,12 +290,14 @@ bool WriteFully(int fd, const uint8_t *data, size_t size) do { written = write(fd, data, rest); } while (written < 0 && errno == EINTR); - if (written < 0) { return false; } data += written; rest -= static_cast(written); + if (rest != 0) { + LOG(INFO) << "totalSize = " << size << ", rest = " << rest; + } } return true; }