diff --git a/bundle.json b/bundle.json index 68550561898528ea6cdce996e53df83b534c4595..b6cf4ecef4cd642a2e7815af2cb8791f7077b84f 100644 --- a/bundle.json +++ b/bundle.json @@ -50,7 +50,7 @@ "init", "hdc", "drivers_interface_input", - "drivers_interface_partitionslot", + "drivers_peripheral_partitionslot", "c_utils", "hilog", "selinux_adapter", diff --git a/interfaces/kits/slot_info/BUILD.gn b/interfaces/kits/slot_info/BUILD.gn index 98db2059161ca9414e15416c8ad7c98e60b2def6..3aff7f72cd498f275a04b8e0b00a800329d9bbb4 100644 --- a/interfaces/kits/slot_info/BUILD.gn +++ b/interfaces/kits/slot_info/BUILD.gn @@ -29,7 +29,7 @@ ohos_static_library("libslotinfo") { defines = [ "UPDATER_AB_SUPPORT" ] external_deps = [ "c_utils:utils", - "drivers_interface_partitionslot:libpartitionslot_proxy_1.0", + "drivers_peripheral_partitionslot:libpartition_slot_manager", "hilog:libhilog_base", "init:libbegetutil_static", ] diff --git a/interfaces/kits/slot_info/slot_info.cpp b/interfaces/kits/slot_info/slot_info.cpp index 0948b5f59e0d5b65534fa8ddb67921120979ab19..e6f2787dcd01ac11f55d9d30b7cadbf5ab21eb1f 100644 --- a/interfaces/kits/slot_info/slot_info.cpp +++ b/interfaces/kits/slot_info/slot_info.cpp @@ -17,8 +17,7 @@ #include "log/log.h" #ifdef UPDATER_AB_SUPPORT -#include "v1_0/ipartition_slot.h" -using namespace OHOS::HDI::Partitionslot::V1_0; +#include "partitionslot_manager.h" #endif namespace Updater { @@ -37,15 +36,10 @@ void SetActiveSlot() #else void GetPartitionSuffix(std::string &suffix) { - sptr partitionslot = - OHOS::HDI::Partitionslot::V1_0::IPartitionSlot::Get(true); - if (partitionslot == nullptr) { - LOG(ERROR) << "partitionslot ptr is nullptr"; - return; - } + OHOS::HDI::Partitionslot::V1_0::PartitionSlotManager psMgr; int32_t curSlot = -1; int32_t numOfSlots = 0; - int32_t ret = partitionslot->GetCurrentSlot(curSlot, numOfSlots); + int32_t ret = psMgr.GetCurrentSlot(curSlot, numOfSlots); LOG(INFO) << "Get slot info, curSlot: " << curSlot << "numOfSlots :" << numOfSlots; if (ret != 0 || curSlot <= 0 || curSlot > 2 || numOfSlots != 2) { // 2: max slot num suffix = ""; @@ -53,7 +47,7 @@ void GetPartitionSuffix(std::string &suffix) } int32_t updateSlot = curSlot == 1 ? 2 : 1; - ret = partitionslot->GetSlotSuffix(updateSlot, suffix); + ret = psMgr.GetSlotSuffix(updateSlot, suffix); if (ret != 0) { LOG(ERROR) << "Get slot suffix error, partitionPath: " << suffix; suffix = ""; @@ -62,22 +56,17 @@ void GetPartitionSuffix(std::string &suffix) void GetActivePartitionSuffix(std::string &suffix) { - sptr partitionslot = - OHOS::HDI::Partitionslot::V1_0::IPartitionSlot::Get(true); - if (partitionslot == nullptr) { - LOG(ERROR) << "partitionslot ptr is nullptr"; - return; - } + OHOS::HDI::Partitionslot::V1_0::PartitionSlotManager psMgr; int32_t curSlot = -1; int32_t numOfSlots = 0; - int32_t ret = partitionslot->GetCurrentSlot(curSlot, numOfSlots); + int32_t ret = psMgr.GetCurrentSlot(curSlot, numOfSlots); LOG(INFO) << "Get slot info, curSlot: " << curSlot << "numOfSlots :" << numOfSlots; if (ret != 0 || curSlot <= 0 || curSlot > 2 || numOfSlots != 2) { // 2: max slot num suffix = ""; return; } - ret = partitionslot->GetSlotSuffix(curSlot, suffix); + ret = psMgr.GetSlotSuffix(curSlot, suffix); if (ret != 0) { LOG(ERROR) << "Get slot suffix error, partitionPath: " << suffix; suffix = ""; @@ -86,22 +75,17 @@ void GetActivePartitionSuffix(std::string &suffix) void SetActiveSlot() { - sptr partitionslot = - OHOS::HDI::Partitionslot::V1_0::IPartitionSlot::Get(true); - if (partitionslot == nullptr) { - LOG(ERROR) << "partitionslot ptr is nullptr"; - return; - } + OHOS::HDI::Partitionslot::V1_0::PartitionSlotManager psMgr; int32_t curSlot = -1; int32_t numOfSlots = 0; - int32_t ret = partitionslot->GetCurrentSlot(curSlot, numOfSlots); + int32_t ret = psMgr.GetCurrentSlot(curSlot, numOfSlots); LOG(INFO) << "Get slot info, curSlot: " << curSlot << "numOfSlots :" << numOfSlots; if (ret != 0 || curSlot <= 0 || curSlot > 2 || numOfSlots != 2) { // 2: max slot num return; } int32_t activeSlot = curSlot == 1 ? 2 : 1; - ret = partitionslot->SetActiveSlot(activeSlot); + ret = psMgr.SetActiveSlot(activeSlot); if (ret != 0) { LOG(ERROR) << "Set active slot error, slot: " << activeSlot; } diff --git a/services/BUILD.gn b/services/BUILD.gn index f1c260f5391422ab84ef6d0e5fb9c02234288ef6..694a757cdfd4a61c8b819583d3fa3a09d4baf416 100755 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -99,6 +99,7 @@ ohos_static_library("libupdater_static") { "openssl:libcrypto_shared", "openssl:libssl_shared", "zlib:libz", + "drivers_peripheral_partitionslot:libpartition_slot_manager", ] if (updater_ui_support) { external_deps += [ "drivers_interface_input:libinput_proxy_1.0" ] @@ -177,6 +178,7 @@ ohos_static_library("libupdater") { "openssl:libcrypto_shared", "openssl:libssl_shared", "zlib:libz", + "drivers_peripheral_partitionslot:libpartition_slot_manager", ] # add updater custom library diff --git a/services/applypatch/command_process.cpp b/services/applypatch/command_process.cpp index dba56dfb263ef573976010eee12ba0d2e159394a..2ebf2af4a8c6a08f265c75407415ec7a8166a5f9 100644 --- a/services/applypatch/command_process.cpp +++ b/services/applypatch/command_process.cpp @@ -247,7 +247,7 @@ CommandResult DiffAndMoveCommandFn::Execute(const Command ¶ms) offset = Utils::String2Int(params.GetArgumentByPos(pos++), Utils::N_DEC); } size_t patchLength = Utils::String2Int(params.GetArgumentByPos(pos++), Utils::N_DEC); - if (params.GetTransferParams()->isUpdaterMode) { + if (Utils::IsUpdaterMode()) { uint8_t *patchBuffer = params.GetTransferParams()->dataBuffer + offset; ret = WriteDiffToBlock(params, buffer, patchBuffer, patchLength, targetBlock); } else { diff --git a/services/flow_update/update_bin/component_processor.cpp b/services/flow_update/update_bin/component_processor.cpp index f2cfccc1e23acf10b895b821511ca44879814699..2794d04edf11747793de2df121200696ca916d2a 100644 --- a/services/flow_update/update_bin/component_processor.cpp +++ b/services/flow_update/update_bin/component_processor.cpp @@ -259,8 +259,7 @@ int RawImgProcessor::GetWritePathAndOffset(const std::string &partitionName, std #ifndef UPDATER_UT if (partitionName != "/userdata") { - std::string suffix = ""; - GetPartitionSuffix(suffix); + std::string suffix = Utils::GetUpdateSuffix(); writePath += suffix; } LOG(INFO) << "write partition path: " << writePath; diff --git a/services/include/updater/updater.h b/services/include/updater/updater.h index bcdf5f3776c76b7bdb603af1f836e83665f77507..ab6f212c75ab011c3ef1571893890d7aeedc0dd1 100644 --- a/services/include/updater/updater.h +++ b/services/include/updater/updater.h @@ -97,8 +97,12 @@ void ProgressSmoothHandler(int beginProgress, int endProgress, UpdaterStatus SetUpdateSlotParam(UpdaterParams &upParams, bool isUpdateCurrSlot); +UpdaterStatus SetUpdateSuffixParam(); + UpdaterStatus ClearUpdateSlotParam(); +UpdaterStatus ClearUpdateSuffixParam(); + UpdaterStatus DoInstallUpdaterPackage(Hpackage::PkgManager::PkgManagerPtr pkgManager, UpdaterParams &upParams, PackageUpdateMode updateMode); diff --git a/services/stream_update/bin_chunk_update.cpp b/services/stream_update/bin_chunk_update.cpp index a9140fd93e0e05da3c3a37b68efc246c1f1e09d2..23a5faa259a969543c7a9801b426b4da00f6753f 100755 --- a/services/stream_update/bin_chunk_update.cpp +++ b/services/stream_update/bin_chunk_update.cpp @@ -214,15 +214,11 @@ UpdateResultCode BinChunkUpdate::UpdateBinHash(uint8_t *data, uint32_t &len) return STREAM_UPDATE_FAILURE; } - //切换ab分区 - #ifndef UPDATER_UT - SetActiveSlot(); - #else int result = remove("/data/updater/test.txt"); if (result != 0) { LOG(ERROR) << "Failed to remove /data/updater/test.txt, error: " << strerror(errno); } - #endif + LOG(DEBUG) << "BinChunkUpdate::UpdateBinHash exit"; return STREAM_UPDATE_COMPLETE; } @@ -518,10 +514,9 @@ bool BinChunkUpdate::OpenDevPath() targetPath = devPath; if (updateInfo_.curPartition != "/userdata") { - std::string suffix = ""; - GetPartitionSuffix(suffix); + std::string suffix = Utils::GetUpdateSuffix(); targetPath += suffix; - GetActivePartitionSuffix(suffix); + suffix = Utils::GetUpdateActiveSuffix(); srcPath += suffix; } @@ -761,8 +756,7 @@ std::string BinChunkUpdate::ComputeFileHash(const std::string &partitionName, #ifndef UPDATER_UT std::string devPath = GetBlockDeviceByMountPoint(partitionName); if (partitionName != "/userdata") { - std::string suffix = ""; - GetPartitionSuffix(suffix); + std::string suffix = Utils::GetUpdateSuffix(); devPath += suffix; } #else diff --git a/services/updater.cpp b/services/updater.cpp index f0fba5394728cd52468f34bf156e7a73bd1283cf..48500398c4d0cb343c906ea4427f015bcc21bc1e 100644 --- a/services/updater.cpp +++ b/services/updater.cpp @@ -52,6 +52,7 @@ #include "updater_ui_stub.h" #include "utils.h" #include "write_state/write_state.h" +#include "slot_info/slot_info.h" namespace Updater { using Updater::Utils::SplitString; @@ -323,7 +324,18 @@ UpdaterStatus SetUpdateSlotParam(UpdaterParams &upParams, bool isUpdateCurrSlot) } return UPDATE_SUCCESS; } - + +UpdaterStatus SetUpdateSuffixParam() +{ + std::string updateSuffix = ""; + GetPartitionSuffix(updateSuffix); + if (!Utils::SetUpdateSuffix(updateSuffix)) { + LOG(ERROR) << "set update.part.suffix fail"; + return UPDATE_ERROR; + } + return UPDATE_SUCCESS; +} + UpdaterStatus ClearUpdateSlotParam() { if (!Utils::IsVabDevice()) { @@ -337,6 +349,16 @@ UpdaterStatus ClearUpdateSlotParam() return UPDATE_SUCCESS; } +UpdaterStatus ClearUpdateSuffixParam() +{ + std::string updateSuffix = " "; + if (!Utils::SetUpdateSuffix(updateSuffix)) { + LOG(ERROR) << "clear update.part.suffix fail"; + return UPDATE_ERROR; + } + return UPDATE_SUCCESS; +} + UpdaterStatus DoInstallUpdaterBinfile(PkgManager::PkgManagerPtr pkgManager, UpdaterParams &upParams, PackageUpdateMode updateMode) { diff --git a/services/updater_binary/BUILD.gn b/services/updater_binary/BUILD.gn index e196cd239de036fca9d1ea4efc93d35232cfdfd5..afbb7c39d87c31fe2523e297dd7dce28fc190cac 100644 --- a/services/updater_binary/BUILD.gn +++ b/services/updater_binary/BUILD.gn @@ -58,7 +58,6 @@ ohos_static_library("libupdater_binary") { deps = [ "${updater_path}/interfaces/kits/misc_info:libmiscinfo", - "${updater_path}/interfaces/kits/slot_info:libslotinfo", "${updater_path}/services/applypatch:libapplypatch", "${updater_path}/services/diffpatch/patch:libpatch", "${updater_path}/services/flow_update/update_bin:libBinFlowUpdate", diff --git a/services/updater_binary/update_image_block.cpp b/services/updater_binary/update_image_block.cpp index 95a6048fcd6fb514d8a814864602d64516987ab0..a37187bf24502677ddd7f589c4d303ef426fc44c 100644 --- a/services/updater_binary/update_image_block.cpp +++ b/services/updater_binary/update_image_block.cpp @@ -181,8 +181,7 @@ static int32_t GetUpdateBlockInfo(struct UpdateBlockInfo &infos, Uscript::UScrip infos.devPath = GetBlockDeviceByMountPoint(infos.partitionName); #ifndef UPDATER_UT if (infos.partitionName != "/userdata") { - std::string suffix = ""; - GetPartitionSuffix(suffix); + std::string suffix = Utils::GetUpdateSuffix(); infos.devPath += suffix; } #else @@ -498,8 +497,7 @@ int32_t UScriptInstructionBlockCheck::Execute(Uscript::UScriptEnv &env, Uscript: auto devPath = GetBlockDeviceByMountPoint(partitionName); #ifndef UPDATER_UT if (partitionName != "/userdata") { - std::string suffix = ""; - GetPartitionSuffix(suffix); + std::string suffix = Utils::GetUpdateSuffix(); devPath += suffix; } #else @@ -767,8 +765,7 @@ int32_t UScriptInstructionShaCheck::Execute(Uscript::UScriptEnv &env, Uscript::U } #ifndef UPDATER_UT if (partitionName != "/userdata") { - std::string suffix = ""; - GetPartitionSuffix(suffix); + std::string suffix = Utils::GetUpdateSuffix(); devPath += suffix; } LOG(INFO) << "write partition path: " << devPath; diff --git a/services/updater_binary/update_image_patch.cpp b/services/updater_binary/update_image_patch.cpp index ec3b3c58496b4fe11ad57b95805e37ed5dec2126..8e74f466011c34cc288be42f9bfb3211863b0af6 100644 --- a/services/updater_binary/update_image_patch.cpp +++ b/services/updater_binary/update_image_patch.cpp @@ -73,8 +73,7 @@ int32_t USInstrImagePatch::GetParam(Uscript::UScriptContext &context, ImagePatch para.devPath = GetBlockDeviceByMountPoint(para.partName); #ifndef UPDATER_UT if (para.partName != "/userdata") { - std::string suffix = ""; - GetPartitionSuffix(suffix); + std::string suffix = Utils::GetUpdateSuffix(); para.devPath += suffix; } #else @@ -264,8 +263,7 @@ int32_t USInstrImageShaCheck::GetParam(Uscript::UScriptContext &context, CheckPa para.devPath = GetBlockDeviceByMountPoint(para.partName); #ifndef UPDATER_UT if (para.partName != "/userdata") { - std::string suffix = ""; - GetPartitionSuffix(suffix); + std::string suffix = Utils::GetUpdateSuffix(); para.devPath += suffix; } #else diff --git a/services/updater_binary/update_processor.cpp b/services/updater_binary/update_processor.cpp index 78a1732597899883131ba71743a6ac634c61fd43..e38ee4abdae4016e339b7b1245e9349328233879 100644 --- a/services/updater_binary/update_processor.cpp +++ b/services/updater_binary/update_processor.cpp @@ -460,8 +460,7 @@ int UScriptInstructionRawImageWrite::GetWritePathAndOffset(const std::string &pa #ifndef UPDATER_UT if (partitionName != "/userdata") { - std::string suffix = ""; - GetPartitionSuffix(suffix); + std::string suffix = Utils::GetUpdateSuffix(); writePath += suffix; } LOG(INFO) << "write partition path: " << writePath; diff --git a/services/updater_main.cpp b/services/updater_main.cpp index d30ad7279262c4aa7aee80bd84d14f8e6aa0295e..168ba17277886409ef31d0af97ef7c01009b35a5 100644 --- a/services/updater_main.cpp +++ b/services/updater_main.cpp @@ -662,6 +662,21 @@ static UpdaterStatus VerifyCommonFiles(UpdaterParams &upParams) return UPDATE_SUCCESS; } +static UpdaterStatus SetUpdateParam(UpdaterParams &upParams, bool isUpdateCurrSlot) +{ + // set update slot + if (SetUpdateSlotParam(upParams, false) != UPDATE_SUCCESS) { + LOG(ERROR) << "SetUpdateSlotParam failed"; + return UPDATE_ERROR; + } + // set update suffix + if (SetUpdateSuffixParam() != UPDATE_SUCCESS) { + LOG(ERROR) << "SetUpdateSuffixParam failed"; + return UPDATE_ERROR; + } + return UPDATE_SUCCESS; +} + static UpdaterStatus PreUpdatePackages(UpdaterParams &upParams) { UPDATER_INIT_RECORD; @@ -685,8 +700,8 @@ static UpdaterStatus PreUpdatePackages(UpdaterParams &upParams) (void)DeleteFile(resultPath); LOG(INFO) << "delete last upgrade file"; } - if (SetUpdateSlotParam(upParams, false) != UPDATE_SUCCESS) { - LOG(ERROR) << "SetUpdateSlotParam failed"; + if (SetUpdateParam(upParams, false) != UPDATE_SUCCESS) { + LOG(ERROR) << "SetUpdateParam failed"; return UPDATE_ERROR; } // verify package first @@ -918,6 +933,7 @@ static void PostUpdate(UpdaterParams &upParams, UpdaterStatus &status, status = CheckAndSetSlot(upParams); } ClearUpdateSlotParam(); + ClearUpdateSuffixParam(); ShowSuccessUi(upParams, status); bool updateResult = (status == UPDATE_SUCCESS); @@ -976,8 +992,8 @@ static UpdaterStatus PreSdcardUpdatePackages(UpdaterParams &upParams) LOG(ERROR) << "Battery is not sufficient for install package."; return UPDATE_SKIP; } - if (SetUpdateSlotParam(upParams, true) != UPDATE_SUCCESS) { - LOG(ERROR) << "SetUpdateSlotParam failed"; + if (SetUpdateParam(upParams, true) != UPDATE_SUCCESS) { + LOG(ERROR) << "SetUpdateParam failed"; return UPDATE_ERROR; } UpdaterStatus status = VerifyPackages(upParams); @@ -996,6 +1012,7 @@ static UpdaterStatus PreSdcardUpdatePackages(UpdaterParams &upParams) static void PostSdcardUpdatePackages(UpdaterParams &upParams, UpdaterStatus &status) { ClearUpdateSlotParam(); + ClearUpdateSuffixParam(); if (Utils::CheckUpdateMode(Updater::SDCARD_INTRAL_MODE)) { PostUpdatePackages(upParams, status); } else if (status == UPDATE_SUCCESS) { diff --git a/test/unittest/service_test/BUILD.gn b/test/unittest/service_test/BUILD.gn index cdbdf00f508db489ad1c1c07d45f1b87452e0ec8..d3588b1a5f18951ebf3475c9a3b9f142e55de99f 100644 --- a/test/unittest/service_test/BUILD.gn +++ b/test/unittest/service_test/BUILD.gn @@ -53,6 +53,7 @@ ohos_unittest("updater_service_unittest") { deps = [ "${updater_path}/interfaces/kits/misc_info:libmiscinfo", + "${updater_path}/interfaces/kits/slot_info:libslotinfo", "${updater_path}/interfaces/kits/packages:libpackageExt", "${updater_path}/services/applypatch:libapplypatch", "${updater_path}/services/diffpatch/patch:libpatch", diff --git a/updater_default_cfg.gni b/updater_default_cfg.gni index 7c87383b5c82a527c3efac50245a48eddacbc39c..130b14a9e20ef570ca0943defc87b9f53e6b3d13 100644 --- a/updater_default_cfg.gni +++ b/updater_default_cfg.gni @@ -13,7 +13,7 @@ import("//build/ohos.gni") -init_feature_ab_partition = false +init_feature_ab_partition = true declare_args() { updater_cfg_file = "" updater_ui_support = true diff --git a/utils/include/utils.h b/utils/include/utils.h index 7cefae4d3efbce8df5a2deb76b98bf8288f08cd1..c8f93d68d2ccc912d8161fd1817b81282efd9df2 100644 --- a/utils/include/utils.h +++ b/utils/include/utils.h @@ -117,7 +117,10 @@ bool ConvertToDouble(const std::string &str, double &value); bool ConvertToFloat(const std::string &str, float &value); bool IsVabDevice(); bool SetUpdateSlot(int updateSlot); +bool SetUpdateSuffix(std::string stringsuffix); int GetUpdateSlot(); +std::string GetUpdateSuffix(); +std::string GetUpdateActiveSuffix(); #ifndef __WIN32 void SetFileAttributes(const std::string& file, uid_t owner, gid_t group, mode_t mode); #endif diff --git a/utils/utils.cpp b/utils/utils.cpp index 4c81481c836aa1b33587c9db6fe6fb605ddd58fb..069c83edfb88fceda1b24ea4daaf5567279ca8a5 100644 --- a/utils/utils.cpp +++ b/utils/utils.cpp @@ -1111,7 +1111,30 @@ bool SetUpdateSlot(int setSlot) } return false; } - + +bool SetUpdateSuffix(std::string stringsuffix) +{ + if (stringsuffix.empty()) { + LOG(ERROR) << "suffix is empty"; + return false; + } + int tryNum = 3; + while (tryNum-- > 0) { + if (SetParameter("update.part.suffix", stringsuffix.c_str()) != 0) { + LOG(ERROR) << "set update.part.suffix fail"; + continue; + } + if (strcmp(GetUpdateSuffix().c_str(), stringsuffix.c_str()) == 0) { + LOG(INFO) << "set update.part.suffix is " << stringsuffix; + return true; + } + if (tryNum != 0) { + sleep(1); + } + } + return false; +} + int GetUpdateSlot() { if (!IsVabDevice()) { @@ -1130,6 +1153,36 @@ int GetUpdateSlot() return updateSlot; } +std::string GetUpdateSuffix() +{ + char paramValue[PARAM_SIZE + 1] = {0}; + if (GetParameter("update.part.suffix", "", paramValue, sizeof(paramValue) - 1) <= 0) { + LOG(ERROR) << "get update.part.suffix failed"; + return std::string(paramValue); + } + LOG(INFO) << "GetUpdateSuffix = " << paramValue; + return std::string(paramValue); +} + +std::string GetUpdateActiveSuffix() +{ + char paramValue[PARAM_SIZE + 1] = {0}; + if (GetParameter("update.part.suffix", "", paramValue, sizeof(paramValue) - 1) <= 0) { + LOG(ERROR) << "get update.part.suffix failed"; + return std::string(paramValue); + } + if (strcmp(paramValue, "_a") == 0) { + strncpy_s(paramValue, sizeof(paramValue), "_b", sizeof("_b")); + } else if (strcmp(paramValue, "_b") == 0) { + strncpy_s(paramValue, sizeof(paramValue), "_a", sizeof("_a")); + } else { + LOG(ERROR) << "Unexpected suffix value: " << paramValue; + return std::string(paramValue); + } + LOG(INFO) << "GetUpdateActiveSuffix = " << paramValue; + return std::string(paramValue); +} + #ifndef __WIN32 void SetFileAttributes(const std::string& file, uid_t owner, gid_t group, mode_t mode) {