From 81ffd9712c09e733e919ea4716a81f3d915868a2 Mon Sep 17 00:00:00 2001 From: "yaoruozi1@huawei.com" Date: Fri, 21 Jun 2024 21:20:19 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0FD=E9=80=9F=E7=8E=87?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yaoruozi1@huawei.com --- .../native/backup_ext/include/ext_extension.h | 6 ++ .../backup_ext/include/ext_extension_stub.h | 1 + .../native/backup_ext/src/ext_extension.cpp | 12 ++++ .../backup_ext/src/ext_extension_stub.cpp | 20 ++++++ .../backup_kit_inner/src/service_proxy.cpp | 28 ++++++++ .../backup_kit_inner/impl/i_extension.h | 1 + .../impl/i_extension_ipc_interface_code.h | 1 + .../native/backup_kit_inner/impl/i_service.h | 1 + .../impl/i_service_ipc_interface_code.h | 1 + .../backup_kit_inner/impl/service_proxy.h | 1 + interfaces/kits/js/backup/prop_n_exporter.cpp | 1 + .../kits/js/backup/prop_n_operation.cpp | 66 +++++++++++++++++++ interfaces/kits/js/backup/prop_n_operation.h | 2 + .../backup_sa/include/module_ipc/service.h | 1 + .../include/module_ipc/service_stub.h | 1 + .../include/module_ipc/svc_extension_proxy.h | 1 + services/backup_sa/src/module_ipc/service.cpp | 16 +++++ .../src/module_ipc/svc_extension_proxy.cpp | 27 ++++++++ utils/include/b_resources/b_constants.h | 4 ++ 19 files changed, 191 insertions(+) diff --git a/frameworks/native/backup_ext/include/ext_extension.h b/frameworks/native/backup_ext/include/ext_extension.h index 8bb86740b..43e09fdbb 100644 --- a/frameworks/native/backup_ext/include/ext_extension.h +++ b/frameworks/native/backup_ext/include/ext_extension.h @@ -49,6 +49,7 @@ public: ErrCode IncrementalOnBackup() override; std::tuple GetIncrementalBackupFileHandle() override; ErrCode GetBackupInfo(std::string &result) override; + ErrCode UpdateFdSendRate(std::string &bundleName, int sendRate) override; void AsyncTaskRestoreForUpgrade(void); void ExtClear(void); @@ -189,6 +190,11 @@ private: std::shared_ptr extension_; std::string backupInfo_; OHOS::ThreadPool threadPool_; + std::mutex updateSendRateLock_; + std::atomic needUpdateSendRate_ {false}; + std::atomic isMinSendRate_ {false}; + std::string bundleName_; + int sendRate_; }; } // namespace OHOS::FileManagement::Backup diff --git a/frameworks/native/backup_ext/include/ext_extension_stub.h b/frameworks/native/backup_ext/include/ext_extension_stub.h index 55bb9ba6b..86949011a 100644 --- a/frameworks/native/backup_ext/include/ext_extension_stub.h +++ b/frameworks/native/backup_ext/include/ext_extension_stub.h @@ -42,6 +42,7 @@ private: ErrCode CmdIncrementalOnBackup(MessageParcel &data, MessageParcel &reply); ErrCode CmdGetIncrementalBackupFileHandle(MessageParcel &data, MessageParcel &reply); ErrCode CmdGetBackupInfo(MessageParcel &data, MessageParcel &reply); + ErrCode CmdUpdateFdSendRate(MessageParcel &data, MessageParcel &reply); private: using ExtensionInterface = int32_t (ExtExtensionStub::*)(MessageParcel &data, MessageParcel &reply); diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 9142a1ec7..dceac0998 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -1721,6 +1721,18 @@ ErrCode BackupExtExtension::GetBackupInfo(std::string &result) return ERR_OK; } +ErrCode BackupExtExtension::UpdateFdSendRate(std::string &bundleName, int sendRate) +{ + std::lock_guard lock(updateSendRateLock_); + VerifyCaller(); + needUpdateSendRate_.store(true); + bundleName_ = bundleName; + sendRate_ = sendRate; + HILOGI("Update SendRate Success, bundleName:%{public}s, sendRate:%{public}d", bundleName.c_str(), sendRate) + return ERR_OK; +} + + std::function BackupExtExtension::RestoreResultCallbackEx(wptr obj) { HILOGI("Begin get callbackEx"); diff --git a/frameworks/native/backup_ext/src/ext_extension_stub.cpp b/frameworks/native/backup_ext/src/ext_extension_stub.cpp index 9b9623cd0..b9f048747 100644 --- a/frameworks/native/backup_ext/src/ext_extension_stub.cpp +++ b/frameworks/native/backup_ext/src/ext_extension_stub.cpp @@ -49,6 +49,8 @@ ExtExtensionStub::ExtExtensionStub() &ExtExtensionStub::CmdGetBackupInfo; opToInterfaceMap_[static_cast(IExtensionInterfaceCode::CMD_INCREMENTAL_ON_BACKUP)] = &ExtExtensionStub::CmdIncrementalOnBackup; + opToInterfaceMap_[static_cast(IExtensionInterfaceCode::CMD_UPDATE_FD_SENDRATE)] = + &ExtExtensionStub::CmdUpdateFdSendRate; } int32_t ExtExtensionStub::OnRemoteRequest(uint32_t code, @@ -219,4 +221,22 @@ ErrCode ExtExtensionStub::CmdGetBackupInfo(MessageParcel &data, MessageParcel &r } return BError(BError::Codes::OK); } + +ErrCode ExtExtensionStub::CmdUpdateFdSendRate(MessageParcel &data, MessageParcel &reply) +{ + HILOGD("CmdUpdateFdSendRate Begin"); + std::string bundleName; + if (!data.ReadString(bundleName)) { + return BError(BError::Codes::EXT_INVAL_ARG), "Failed to receive bundleName").GetCode(); + } + int sendRate; + if (!data.ReadInt(sendRate)) { + return BError(BError::Codes::EXT_INVAL_ARG), "Failed to receive sendRate").GetCode(); + } + int ret = UpdateSendRate(bundleName, sendRate); + if (reply.WriteInt32(ret)) { + return BError(BError::Codes::EXT_BROKEN_IPC), "Failed to send out the ret").GetCode(); + } + return BError(BError::Codes::OK); +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/frameworks/native/backup_kit_inner/src/service_proxy.cpp b/frameworks/native/backup_kit_inner/src/service_proxy.cpp index e4a1ffec4..f4283d7ef 100644 --- a/frameworks/native/backup_kit_inner/src/service_proxy.cpp +++ b/frameworks/native/backup_kit_inner/src/service_proxy.cpp @@ -550,4 +550,32 @@ ErrCode ServiceProxy::UpdateTimer(BundleName &bundleName, uint32_t timeOut, bool HILOGI("ServiceProxy UpdateTimer end. result = %d", result); return BError(BError::Codes::OK, "success"); } + +ErrCode ServiceProxy::UpdateSendRate(std::string &bundleName, int sendRate, bool &result) +{ + HILOGD("ServiceProxy UpdateSendRate Begin."); + BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); + MessageParcel data; + if (!data.WriteInterfaceToken(GetDescriptor())) { + return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); + } + if (!data.WriteString(bundleName)) { + return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleName").GetCode(); + } + if (!data.WriteInt(sendRate)) { + return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send sendRate").GetCode(); + } + MessageParcel reply; + MessageOption option; + option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); + int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_UPDATE_SENDRATE), + data, reply, option); + if (ret != NO_ERROR) { + string str = "Failed to send out the request because of " + to_string(ret); + return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); + } + reply.ReadBool(result); + HILOGI("ServiceProxy UpdateTimer end. result = %d", result); + return BError(BError::Codes::OK, "success"); +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/i_extension.h b/interfaces/inner_api/native/backup_kit_inner/impl/i_extension.h index 888c524f0..6f91321f2 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/i_extension.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/i_extension.h @@ -39,6 +39,7 @@ public: virtual ErrCode IncrementalOnBackup() = 0; virtual std::tuple GetIncrementalBackupFileHandle() = 0; virtual ErrCode GetBackupInfo(std::string &result) = 0; + virtual ErrCode UpdateFdSendRate(std::string &bundleName, int sendRate) = 0; }; } // namespace OHOS::FileManagement::Backup diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/i_extension_ipc_interface_code.h b/interfaces/inner_api/native/backup_kit_inner/impl/i_extension_ipc_interface_code.h index cb3fa21a3..15478e015 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/i_extension_ipc_interface_code.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/i_extension_ipc_interface_code.h @@ -30,6 +30,7 @@ enum class IExtensionInterfaceCode { CMD_GET_INCREMENTAL_BACKUP_FILE_HANDLE, CMD_GET_BACKUP_INFO, CMD_INCREMENTAL_ON_BACKUP, + CMD_UPDATE_FD_SENDRATE, }; } // namespace OHOS::FileManagement::Backup diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/i_service.h b/interfaces/inner_api/native/backup_kit_inner/impl/i_service.h index 4ae73c77d..4818953e2 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/i_service.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/i_service.h @@ -84,6 +84,7 @@ public: virtual ErrCode GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) = 0; virtual ErrCode GetBackupInfo(BundleName &bundleName, std::string &result) = 0; virtual ErrCode UpdateTimer(BundleName &bundleName, uint32_t timeOut, bool &result) = 0; + virtual ErrCode UpdateSendRate(std::string &bundleName, int sendRate, bool &result) = 0; DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Filemanagement.Backup.IService") }; diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/i_service_ipc_interface_code.h b/interfaces/inner_api/native/backup_kit_inner/impl/i_service_ipc_interface_code.h index c18df5154..1de4b9c45 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/i_service_ipc_interface_code.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/i_service_ipc_interface_code.h @@ -45,6 +45,7 @@ enum class IServiceInterfaceCode { SERVICE_CMD_GET_INCREMENTAL_FILE_NAME, SERVICE_CMD_GET_BACKUP_INFO, SERVICE_CMD_UPDATE_TIMER, + SERVICE_CMD_UPDATE_SENDRATE, SERVICE_CMD_GET_APP_LOCAL_LIST_AND_DO_INCREMENTAL_BACKUP, }; } // namespace OHOS::FileManagement::Backup diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h b/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h index f124c06fd..9c488f38c 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h @@ -66,6 +66,7 @@ public: ErrCode GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) override; ErrCode GetBackupInfo(BundleName &bundleName, std::string &result) override; ErrCode UpdateTimer(BundleName &bundleName, uint32_t timeOut, bool &result) override; + ErrCode UpdateSendRate(std::string &bundleName, int sendRate, bool &result) override; public: explicit ServiceProxy(const sptr &impl) : IRemoteProxy(impl) {} diff --git a/interfaces/kits/js/backup/prop_n_exporter.cpp b/interfaces/kits/js/backup/prop_n_exporter.cpp index 5c1a9e2b1..cbec6854a 100644 --- a/interfaces/kits/js/backup/prop_n_exporter.cpp +++ b/interfaces/kits/js/backup/prop_n_exporter.cpp @@ -26,6 +26,7 @@ bool PropNExporter::Export() NVal::DeclareNapiFunction("getLocalCapabilities", PropNOperation::Async), NVal::DeclareNapiFunction("getBackupInfo", PropNOperation::DoGetBackupInfo), NVal::DeclareNapiFunction("updateTimer", PropNOperation::DoUpdateTimer), + NVal::DeclareNapiFunction("updateSendRate", PropNOperation::DoUpdateSendRate), }); } diff --git a/interfaces/kits/js/backup/prop_n_operation.cpp b/interfaces/kits/js/backup/prop_n_operation.cpp index b0ed09334..66c37cf54 100644 --- a/interfaces/kits/js/backup/prop_n_operation.cpp +++ b/interfaces/kits/js/backup/prop_n_operation.cpp @@ -256,6 +256,23 @@ bool PropNOperation::UpdateTimer(std::string &bundleName, uint32_t timeOut) return result; } +bool PropNOperation::UpdateSendRate(std::string &bundleName, int sendRate) +{ + bool result = false; + ServiceProxy::InvaildInstance(); + auto proxy = ServiceProxy::GetInstance(); + if (!proxy) { + HILOGE("called UpdateSendRate,failed to get proxy"); + return result; + } + ErrCode errCode = proxy->UpdateSendRate(bundleName, sendRate, result); + if (errCode != 0) { + HILOGE("Proxy execute UpdateSendRate faild."); + return result; + } + return result; +} + napi_value PropNOperation::DoUpdateTimer(napi_env env, napi_callback_info info) { HILOGD("called DoUpdateTimer begin"); @@ -303,4 +320,53 @@ napi_value PropNOperation::DoUpdateTimer(napi_env env, napi_callback_info info) HILOGI("DoUpdateTimer success with result: %{public}d", result); return nResult; } + +napi_value PropNOperation::DoUpdateSendRate(napi_env env, napi_callback_info info) +{ + HILOGD("called DoUpdateSendRate begin"); + if (!CheckPermission("ohos.permission.BACKUP")) { + HILOGE("has not permission!"); + NError(E_PERMISSION).ThrowErr(env); + return nullptr; + } + if (!IsSystemApp()) { + HILOGE("System App check fail!"); + NError(E_PERMISSION_SYS).ThrowErr(env); + return nullptr; + } + NFuncArg funcArg(env, info); + if (!funcArg.InitArgs(NARG_CNT::ONE, NARG_CNT::TWO)) { + HILOGE("Number of arguments unmatched."); + NError(E_PARAMS).ThrowErr(env); + return nullptr; + } + NVal jsBundleStr(env, funcArg[NARG_POS::FIRST]); + auto [succStr, bundle, sizeStr] = jsBundleStr.ToUTF8String(); + if (!succStr) { + HILOGE("First argument is not string."); + NError(E_PARAMS).ThrowErr(env); + return nullptr; + } + NVal jsBundleInt(env, funcArg[NARG_POS::SECOND]); + auto [succInt, sendRate] = jsBundleInt.ToInt(); + if (!succInt || sendRate < 0) { + HILOGE("Second argument is invalid."); + NError(E_PARAMS).ThrowErr(env); + return nullptr; + } + std::string bundleName = bundle.get(); + int sendRate = static_cast(sendRate); + if (sendRate > MAX_FD_SEND_RATE) { + sendRate = MAX_FD_SEND_RATE; + } + bool result = UpdateSendRate(bundleName, sendRate); + napi_value nResult; + napi_status status = napi_get_boolean(env, result, &hao); + if (status != napi_ok) { + HILOGE("napi_get_boolean faild."); + return nullptr; + } + HILOGI("DoUpdateSendRate success with result: %{public}d", result); + return nResult; +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/interfaces/kits/js/backup/prop_n_operation.h b/interfaces/kits/js/backup/prop_n_operation.h index d7b9b6ec5..2f40f0c9b 100644 --- a/interfaces/kits/js/backup/prop_n_operation.h +++ b/interfaces/kits/js/backup/prop_n_operation.h @@ -24,8 +24,10 @@ public: static napi_value Async(napi_env env, napi_callback_info info); static napi_value DoGetBackupInfo(napi_env env, napi_callback_info info); static napi_value DoUpdateTimer(napi_env env, napi_callback_info info); + static napi_value DoUpdateSendRate(napi_env env, napi_callback_info info); private: static bool UpdateTimer(std::string &bundleName, uint32_t timeOut); + static bool UpdateSendRate(std::string &bundleName, int sendRate); }; const std::string PROCEDURE_LOCALCAPABILITIES_NAME = "getLocalCapalities"; diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index 7708dd867..fc3253aa1 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -74,6 +74,7 @@ public: ErrCode GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) override; ErrCode GetBackupInfo(BundleName &bundleName, std::string &result) override; ErrCode UpdateTimer(BundleName &bundleName, uint32_t timeOut, bool &result) override; + ErrCode UpdateSendRate(BundleName &bundleName, int sendRate, bool &result) override; ErrCode SAResultReport(const std::string bundleName, const std::string resultInfo, const ErrCode errCode, const BackupRestoreScenario sennario); diff --git a/services/backup_sa/include/module_ipc/service_stub.h b/services/backup_sa/include/module_ipc/service_stub.h index c60e4d02d..bd40fdd1e 100644 --- a/services/backup_sa/include/module_ipc/service_stub.h +++ b/services/backup_sa/include/module_ipc/service_stub.h @@ -61,6 +61,7 @@ private: int32_t CmdGetIncrementalFileHandle(MessageParcel &data, MessageParcel &reply); int32_t CmdGetBackupInfo(MessageParcel &data, MessageParcel &reply); int32_t CmdUpdateTimer(MessageParcel &data, MessageParcel &reply); + int32_t CmdUpdateSendRate(MessageParcel &data, MessageParcel &reply); void ServiceStubSupplement(); void ServiceStubSuppAppendBundles(); diff --git a/services/backup_sa/include/module_ipc/svc_extension_proxy.h b/services/backup_sa/include/module_ipc/svc_extension_proxy.h index 6c675114d..18ce52639 100644 --- a/services/backup_sa/include/module_ipc/svc_extension_proxy.h +++ b/services/backup_sa/include/module_ipc/svc_extension_proxy.h @@ -34,6 +34,7 @@ public: ErrCode IncrementalOnBackup() override; std::tuple GetIncrementalBackupFileHandle() override; ErrCode GetBackupInfo(std::string &result) override; + ErrCode UpdateFdSendRate(std::string &bundleName, int sendRate) override; public: explicit SvcExtensionProxy(const sptr &remote) : IRemoteProxy(remote) {} diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 617e05f93..691c7aa15 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -1288,6 +1288,22 @@ ErrCode Service::UpdateTimer(BundleName &bundleName, uint32_t timeOut, bool &res } } +ErrCode Service::UpdateSendRate(std::string bundleName, int sendRate, bool &result) +{ + IServiceReverse::Scenario scenario = session_ -> GetScenario(); + if (scenario != IServiceReverse::Scenario::BACKUP) { + HILOGE("This method is applicable to the backup scenario"); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto backupConnection = session_->GetExtConnection(bundleName); + auto proxy = backupConnection->GetBackupExtProxy(); + if (!proxy) { + throw BError(BError::Codes::SA_INVAL_ARG, "Extension backup Proxy is empty"); + } + auto ret = proxy->UpdateFdSendRate(bundleName, sendRate); + return ret; +} + AAFwk::Want Service::CreateConnectWant (BundleName &bundleName) { BConstants::ExtensionAction action = BConstants::ExtensionAction::BACKUP; diff --git a/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp b/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp index 2afa454c9..6fd1d4426 100644 --- a/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp +++ b/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp @@ -177,4 +177,31 @@ ErrCode SvcExtensionProxy::GetBackupInfo(std::string &result) HILOGI("SvcExtensionProxy::GetBackupInfo end. result: %s", result.c_str()); return ret; } + +ErrCode SvcExtensionProxy::UpdateFdSendRate(std::string &bundleName, int sendRate) +{ + HILOGD("SvcExtensionProxy::UpdateFdSendRate begin."); + BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); + MessageParcel data; + data.WriteInterfaceToken(GetDescriptor()); + + MessageParcel reply; + MessageOption option; + int32_t ret = + Remote()->SendRequest(static_cast(IExtensionInterfaceCode::CMD_UPDATE_FD_SENDRATE), data, reply, option); + if (ret != NO_ERROR) { + HILOGE("Received error %{public}d when doing IPC", ret); + return ErrCode(ret); + } + if (!reply.ReadInt32(ret)) { + HILOGE("fail to ReadInt32 ret"); + return ErrCode(ret); + } + if (ret != NO_ERROR) { + HILOGE("ret is not NO_ERROR. ret = %d", ret); + return ErrCode(ret); + } + HILOGI("SvcExtensionProxy::UpdateFdSendRate end. result: %s", result.c_str()); + return ret; +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/utils/include/b_resources/b_constants.h b/utils/include/b_resources/b_constants.h index fa2bc5741..86e93de49 100644 --- a/utils/include/b_resources/b_constants.h +++ b/utils/include/b_resources/b_constants.h @@ -72,6 +72,10 @@ constexpr int BACKUP_VFS_CACHE_PRESSURE = 10000; // 备份过程修改参数 constexpr int32_t INVALID_FD_NUM = -1; +constexpr int MAX_FD_SEND_RATE = 900; // 允许应用申请的最大FD数量 +constexpr int MIN_FD_SEND_RATE = 0; // 允许应用申请的最小FD数量 +constexpr int DEFAULT_FD_SEND_RATE = 0; // 允许应用申请的最小FD数量 + // backup.para内配置项的名称,该配置项值为true时可在不更新hap包的情况下,可以读取包管理元数据配置文件的内容 static inline std::string BACKUP_DEBUG_OVERRIDE_EXTENSION_CONFIG_KEY = "backup.debug.overrideExtensionConfig"; -- Gitee From e63e40271e0be47cd6e8c4421a16b7b7bbb1885c Mon Sep 17 00:00:00 2001 From: "yaoruozi1@huawei.com" Date: Tue, 25 Jun 2024 20:07:44 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0FD=E5=8F=8D=E5=8E=8B?= =?UTF-8?q?=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yaoruozi1@huawei.com --- .../native/backup_ext/include/ext_extension.h | 16 +++-- .../native/backup_ext/src/ext_extension.cpp | 67 +++++++++++++++---- .../backup_ext/src/ext_extension_stub.cpp | 14 ++-- .../backup_kit_inner/src/service_proxy.cpp | 6 +- .../backup_kit_inner/impl/i_extension.h | 2 +- .../native/backup_kit_inner/impl/i_service.h | 2 +- .../backup_kit_inner/impl/service_proxy.h | 2 +- .../kits/js/backup/prop_n_operation.cpp | 20 +++--- interfaces/kits/js/backup/prop_n_operation.h | 2 +- .../backup_sa/include/module_ipc/service.h | 2 +- .../include/module_ipc/svc_extension_proxy.h | 2 +- services/backup_sa/src/module_ipc/service.cpp | 10 ++- .../backup_sa/src/module_ipc/service_stub.cpp | 26 +++++++ .../src/module_ipc/svc_extension_proxy.cpp | 22 +++--- .../backup_kit_inner/service_proxy_mock.cpp | 5 ++ tests/mock/module_ipc/service_mock.cpp | 5 ++ tests/mock/module_ipc/service_stub_mock.cpp | 29 +++++++- .../module_ipc/svc_extension_proxy_mock.cpp | 5 ++ .../backup_impl/include/ext_extension_mock.h | 5 ++ .../backup_impl/include/i_service_mock.h | 5 ++ .../backup_impl/service_proxy_test.cpp | 23 +++++++ .../backup_ext/ext_extension_stub_test.cpp | 39 +++++++++++ .../module_ipc/service_stub_test.cpp | 1 + .../backup_sa/session/service_proxy_mock.cpp | 5 ++ utils/include/b_resources/b_constants.h | 4 +- 25 files changed, 260 insertions(+), 59 deletions(-) diff --git a/frameworks/native/backup_ext/include/ext_extension.h b/frameworks/native/backup_ext/include/ext_extension.h index 42d851d9e..7ab213b55 100644 --- a/frameworks/native/backup_ext/include/ext_extension.h +++ b/frameworks/native/backup_ext/include/ext_extension.h @@ -16,6 +16,7 @@ #ifndef OHOS_FILEMGMT_BACKUP_BACKUP_EXT_EXTENSION_H #define OHOS_FILEMGMT_BACKUP_BACKUP_EXT_EXTENSION_H +#include #include #include #include @@ -29,6 +30,7 @@ #include "ext_backup_js.h" #include "ext_extension_stub.h" #include "i_service.h" +#include "tar_file.h" #include "thread_pool.h" #include "unique_fd.h" @@ -49,7 +51,7 @@ public: ErrCode IncrementalOnBackup() override; std::tuple GetIncrementalBackupFileHandle() override; ErrCode GetBackupInfo(std::string &result) override; - ErrCode UpdateFdSendRate(std::string &bundleName, int sendRate) override; + ErrCode UpdateFdSendRate(std::string &bundleName, int32_t sendRate) override; void AsyncTaskRestoreForUpgrade(void); void ExtClear(void); @@ -150,6 +152,10 @@ private: void AsyncTaskDoIncrementalBackup(UniqueFd incrementalFd, UniqueFd manifestFd); void AsyncTaskOnIncrementalBackup(); + ErrCode IncrementalBigFileReady(const TarMap &pkgInfo, const map &bigInfos, + sptr proxy); + ErrCode BigFileReady(sptr proxy); + void WaitToSendFd(std::chrono::system_clock::time_point startTime, int fdSendNumWaitToSendFdWaitToSendF); /** * @brief extension incremental backup restore is done @@ -167,7 +173,7 @@ private: /** * @brief get callbackEx for execute onRestore with string param - * + * * @param errCode */ std::function IncRestoreResultCallbackEx(wptr obj); @@ -192,9 +198,11 @@ private: OHOS::ThreadPool threadPool_; std::mutex updateSendRateLock_; std::atomic needUpdateSendRate_ {false}; - std::atomic isMinSendRate_ {false}; + std::atomic isStopSendFd_ {false}; + std::condition_variable startSendFdRateCon_; + std::mutex startSendMutex_; std::string bundleName_; - int sendRate_; + int32_t sendRate_; }; } // namespace OHOS::FileManagement::Backup diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 65ea8ebd1..265622532 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -68,7 +69,8 @@ using namespace std; namespace { const int64_t DEFAULT_SLICE_SIZE = 100 * 1024 * 1024; // 分片文件大小为100M const uint32_t MAX_FILE_COUNT = 6000; // 单个tar包最多包含6000个文件 -} // namespace +const uint32_t MAX_FD_GROUP_USE_TIME = 1000; // 每组打开最大时间1000ms +} static std::set GetIdxFileData() { @@ -340,7 +342,7 @@ static ErrCode IndexFileReady(const TarMap &pkgInfo, sptr proxy) return ret; } -static ErrCode BigFileReady(sptr proxy) +ErrCode BackupExtExtension::BigFileReady(sptr proxy) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); UniqueFd fd(open(INDEX_FILE_BACKUP.data(), O_RDONLY)); @@ -351,12 +353,15 @@ static ErrCode BigFileReady(sptr proxy) BJsonCachedEntity cachedEntity(move(fd)); auto cache = cachedEntity.Structuralize(); auto pkgInfo = cache.GetExtManageInfo(); - HILOGI("BigFileReady: pkgInfo file size is: %{public}zu", pkgInfo.size()); + HILOGI("BigFileReady Begin: pkgInfo file size is: %{public}zu", pkgInfo.size()); ErrCode ret {ERR_OK}; + auto startTime = std::chrono::system_clock::now(); + int fdNum = 0; for (auto &item : pkgInfo) { if (item.hashName.empty() || item.fileName.empty()) { continue; } + WaitToSendFd(startTime, fdNum); int32_t errCode = ERR_OK; UniqueFd fd(open(item.fileName.data(), O_RDONLY)); if (fd < 0) { @@ -370,7 +375,9 @@ static ErrCode BigFileReady(sptr proxy) } else { HILOGW("Current file execute app file ready interface failed, ret is:%{public}d", ret); } + fdNum++; } + HILOGI("BigFileReady End"); return ret; } @@ -1444,32 +1451,31 @@ static ErrCode IncrementalTarFileReady(const TarMap &bigFileInfo, /** * 增量大文件和简报信息回传 */ -static ErrCode IncrementalBigFileReady(const TarMap &pkgInfo, - const map &bigInfos, - sptr proxy) +ErrCode BackupExtExtension::IncrementalBigFileReady(const TarMap &pkgInfo, + const map &bigInfos, sptr proxy) { ErrCode ret {ERR_OK}; - HILOGI("Begin, pkgInfo size:%{public}zu", pkgInfo.size()); + HILOGI("IncrementalBigFileReady Begin, pkgInfo size:%{public}zu", pkgInfo.size()); + auto startTime = std::chrono::system_clock::now(); + int fdNum = 0; for (auto &item : pkgInfo) { if (item.first.empty()) { continue; } auto [path, sta, isBeforeTar] = item.second; - int32_t errCode = ERR_OK; + WaitToSendFd(startTime, fdNum); UniqueFd fd(open(path.data(), O_RDONLY)); if (fd < 0) { HILOGE("IncrementalBigFileReady open file failed, file name is %{public}s, err = %{public}d", path.c_str(), errno); errCode = BError::GetCodeByErrno(errno); } - struct ReportFileInfo info = bigInfos.find(path)->second; string file = GetReportFileName(string(INDEX_FILE_INCREMENTAL_BACKUP).append(item.first)); map bigInfo; bigInfo.try_emplace(path, info); WriteFile(file, bigInfo); - ret = proxy->AppIncrementalFileReady(item.first, std::move(fd), UniqueFd(open(file.data(), O_RDONLY)), errCode); if (SUCCEEDED(ret)) { HILOGI("IncrementalBigFileReady: The application is packaged successfully, package name is %{public}s", @@ -1478,7 +1484,9 @@ static ErrCode IncrementalBigFileReady(const TarMap &pkgInfo, } else { HILOGE("IncrementalBigFileReady interface fails to be invoked: %{public}d", ret); } + fdNum++; } + HILOGI("IncrementalBigFileReady End"); return ret; } @@ -1721,18 +1729,23 @@ ErrCode BackupExtExtension::GetBackupInfo(std::string &result) return ERR_OK; } -ErrCode BackupExtExtension::UpdateFdSendRate(std::string &bundleName, int sendRate) +ErrCode BackupExtExtension::UpdateFdSendRate(std::string &bundleName, int32_t sendRate) { std::lock_guard lock(updateSendRateLock_); + HILOGI("Update SendRate, bundleName:%{public}s, sendRate:%{public}d", bundleName.c_str(), sendRate); VerifyCaller(); needUpdateSendRate_.store(true); bundleName_ = bundleName; sendRate_ = sendRate; - HILOGI("Update SendRate Success, bundleName:%{public}s, sendRate:%{public}d", bundleName.c_str(), sendRate) + if (sendRate == 0) { + isStopSendFd_.store(true); + } else { + isStopSendFd_.store(false); + startSendFdRateCon_.notify_one(); + } return ERR_OK; } - std::function BackupExtExtension::RestoreResultCallbackEx(wptr obj) { HILOGI("Begin get callbackEx"); @@ -1835,4 +1848,32 @@ std::function BackupExtExtension::HandleTaskBa } }; } + +void BackupExtExtension::WaitToSendFd(std::chrono::system_clock::time_point startTime, int fdSendNum) +{ + HILOGI("WaitToSendFd Begin"); + if (!needUpdateSendRate_.load()) { + sendRate_ = BConstants::DEFAULT_FD_SEND_RATE; + } + if (isStopSendFd_.load()) { + std::unique_lock lock(startSendMutex_); + startSendFdRateCon_.wait(lock, [this] { return !isStopSendFd_.load(); }); + } + if (fdSendNum == sendRate_) { + HILOGI("current time fd num is max rate, bundle name:%{public}s, rate:%{public}d", bundleName_.c_str(), + sendRate_); + auto curTime = std::chrono::system_clock::now(); + auto useTimeMs = std::chrono::duration_cast(curTime - startTime); + if (useTimeMs < MAX_FD_GROUP_USE_TIME) { + int32_t sleepTime = MAX_FD_GROUP_USE_TIME - useTimeMs; + HILOGI("will wait time:%{public}d", sleepTime); + std::this_thread::sleep_for(std::chrono::milliseconds(sleepTime)); + } else { + HILOGW("current fd send num exceeds one second"); + } + fdSendNum = 0; + startTime = std::chrono::system_clock::now(); + } + HILOGI("WaitToSendFd End"); +} } // namespace OHOS::FileManagement::Backup diff --git a/frameworks/native/backup_ext/src/ext_extension_stub.cpp b/frameworks/native/backup_ext/src/ext_extension_stub.cpp index b9f048747..6930c2982 100644 --- a/frameworks/native/backup_ext/src/ext_extension_stub.cpp +++ b/frameworks/native/backup_ext/src/ext_extension_stub.cpp @@ -227,15 +227,15 @@ ErrCode ExtExtensionStub::CmdUpdateFdSendRate(MessageParcel &data, MessageParcel HILOGD("CmdUpdateFdSendRate Begin"); std::string bundleName; if (!data.ReadString(bundleName)) { - return BError(BError::Codes::EXT_INVAL_ARG), "Failed to receive bundleName").GetCode(); + return BError(BError::Codes::EXT_INVAL_ARG, "Failed to receive bundleName").GetCode(); } - int sendRate; - if (!data.ReadInt(sendRate)) { - return BError(BError::Codes::EXT_INVAL_ARG), "Failed to receive sendRate").GetCode(); + int32_t sendRate; + if (!data.ReadInt32(sendRate)) { + return BError(BError::Codes::EXT_INVAL_ARG, "Failed to receive sendRate").GetCode(); } - int ret = UpdateSendRate(bundleName, sendRate); - if (reply.WriteInt32(ret)) { - return BError(BError::Codes::EXT_BROKEN_IPC), "Failed to send out the ret").GetCode(); + int ret = UpdateFdSendRate(bundleName, sendRate); + if (!reply.WriteInt32(ret)) { + return BError(BError::Codes::EXT_BROKEN_IPC, "Failed to send out the ret").GetCode(); } return BError(BError::Codes::OK); } diff --git a/frameworks/native/backup_kit_inner/src/service_proxy.cpp b/frameworks/native/backup_kit_inner/src/service_proxy.cpp index f4283d7ef..8598aa939 100644 --- a/frameworks/native/backup_kit_inner/src/service_proxy.cpp +++ b/frameworks/native/backup_kit_inner/src/service_proxy.cpp @@ -551,7 +551,7 @@ ErrCode ServiceProxy::UpdateTimer(BundleName &bundleName, uint32_t timeOut, bool return BError(BError::Codes::OK, "success"); } -ErrCode ServiceProxy::UpdateSendRate(std::string &bundleName, int sendRate, bool &result) +ErrCode ServiceProxy::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) { HILOGD("ServiceProxy UpdateSendRate Begin."); BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); @@ -562,7 +562,7 @@ ErrCode ServiceProxy::UpdateSendRate(std::string &bundleName, int sendRate, bool if (!data.WriteString(bundleName)) { return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleName").GetCode(); } - if (!data.WriteInt(sendRate)) { + if (!data.WriteInt32(sendRate)) { return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send sendRate").GetCode(); } MessageParcel reply; @@ -575,7 +575,7 @@ ErrCode ServiceProxy::UpdateSendRate(std::string &bundleName, int sendRate, bool return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); } reply.ReadBool(result); - HILOGI("ServiceProxy UpdateTimer end. result = %d", result); + HILOGI("ServiceProxy UpdateSendRate end. ret = %{public}d", ret); return BError(BError::Codes::OK, "success"); } } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/i_extension.h b/interfaces/inner_api/native/backup_kit_inner/impl/i_extension.h index 6f91321f2..364214d2d 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/i_extension.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/i_extension.h @@ -39,7 +39,7 @@ public: virtual ErrCode IncrementalOnBackup() = 0; virtual std::tuple GetIncrementalBackupFileHandle() = 0; virtual ErrCode GetBackupInfo(std::string &result) = 0; - virtual ErrCode UpdateFdSendRate(std::string &bundleName, int sendRate) = 0; + virtual ErrCode UpdateFdSendRate(std::string &bundleName, int32_t sendRate) = 0; }; } // namespace OHOS::FileManagement::Backup diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/i_service.h b/interfaces/inner_api/native/backup_kit_inner/impl/i_service.h index 4818953e2..fe5b0a2ee 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/i_service.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/i_service.h @@ -84,7 +84,7 @@ public: virtual ErrCode GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) = 0; virtual ErrCode GetBackupInfo(BundleName &bundleName, std::string &result) = 0; virtual ErrCode UpdateTimer(BundleName &bundleName, uint32_t timeOut, bool &result) = 0; - virtual ErrCode UpdateSendRate(std::string &bundleName, int sendRate, bool &result) = 0; + virtual ErrCode UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) = 0; DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Filemanagement.Backup.IService") }; diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h b/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h index 9c488f38c..8591c7e41 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h @@ -66,7 +66,7 @@ public: ErrCode GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) override; ErrCode GetBackupInfo(BundleName &bundleName, std::string &result) override; ErrCode UpdateTimer(BundleName &bundleName, uint32_t timeOut, bool &result) override; - ErrCode UpdateSendRate(std::string &bundleName, int sendRate, bool &result) override; + ErrCode UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) override; public: explicit ServiceProxy(const sptr &impl) : IRemoteProxy(impl) {} diff --git a/interfaces/kits/js/backup/prop_n_operation.cpp b/interfaces/kits/js/backup/prop_n_operation.cpp index 66c37cf54..12e520d37 100644 --- a/interfaces/kits/js/backup/prop_n_operation.cpp +++ b/interfaces/kits/js/backup/prop_n_operation.cpp @@ -256,7 +256,7 @@ bool PropNOperation::UpdateTimer(std::string &bundleName, uint32_t timeOut) return result; } -bool PropNOperation::UpdateSendRate(std::string &bundleName, int sendRate) +bool PropNOperation::UpdateSendRate(std::string &bundleName, int32_t sendRate) { bool result = false; ServiceProxy::InvaildInstance(); @@ -267,7 +267,7 @@ bool PropNOperation::UpdateSendRate(std::string &bundleName, int sendRate) } ErrCode errCode = proxy->UpdateSendRate(bundleName, sendRate, result); if (errCode != 0) { - HILOGE("Proxy execute UpdateSendRate faild."); + HILOGE("Proxy execute UpdateSendRate failed. errCode:%{public}d", errCode); return result; } return result; @@ -348,22 +348,22 @@ napi_value PropNOperation::DoUpdateSendRate(napi_env env, napi_callback_info inf return nullptr; } NVal jsBundleInt(env, funcArg[NARG_POS::SECOND]); - auto [succInt, sendRate] = jsBundleInt.ToInt(); - if (!succInt || sendRate < 0) { + auto [succInt, jsRate] = jsBundleInt.ToInt32(); + if (!succInt || jsRate < 0) { HILOGE("Second argument is invalid."); NError(E_PARAMS).ThrowErr(env); return nullptr; } std::string bundleName = bundle.get(); - int sendRate = static_cast(sendRate); - if (sendRate > MAX_FD_SEND_RATE) { - sendRate = MAX_FD_SEND_RATE; + int32_t sendFdRate = static_cast(jsRate); + if (sendFdRate > BConstants::MAX_FD_SEND_RATE) { + sendFdRate = BConstants::MAX_FD_SEND_RATE; } - bool result = UpdateSendRate(bundleName, sendRate); + bool result = UpdateSendRate(bundleName, sendFdRate); napi_value nResult; - napi_status status = napi_get_boolean(env, result, &hao); + napi_status status = napi_get_boolean(env, result, &nResult); if (status != napi_ok) { - HILOGE("napi_get_boolean faild."); + HILOGE("napi_get_boolean failed."); return nullptr; } HILOGI("DoUpdateSendRate success with result: %{public}d", result); diff --git a/interfaces/kits/js/backup/prop_n_operation.h b/interfaces/kits/js/backup/prop_n_operation.h index 2f40f0c9b..b6d746f00 100644 --- a/interfaces/kits/js/backup/prop_n_operation.h +++ b/interfaces/kits/js/backup/prop_n_operation.h @@ -27,7 +27,7 @@ public: static napi_value DoUpdateSendRate(napi_env env, napi_callback_info info); private: static bool UpdateTimer(std::string &bundleName, uint32_t timeOut); - static bool UpdateSendRate(std::string &bundleName, int sendRate); + static bool UpdateSendRate(std::string &bundleName, int32_t sendRate); }; const std::string PROCEDURE_LOCALCAPABILITIES_NAME = "getLocalCapalities"; diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index fc3253aa1..a4af2a949 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -74,7 +74,7 @@ public: ErrCode GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) override; ErrCode GetBackupInfo(BundleName &bundleName, std::string &result) override; ErrCode UpdateTimer(BundleName &bundleName, uint32_t timeOut, bool &result) override; - ErrCode UpdateSendRate(BundleName &bundleName, int sendRate, bool &result) override; + ErrCode UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) override; ErrCode SAResultReport(const std::string bundleName, const std::string resultInfo, const ErrCode errCode, const BackupRestoreScenario sennario); diff --git a/services/backup_sa/include/module_ipc/svc_extension_proxy.h b/services/backup_sa/include/module_ipc/svc_extension_proxy.h index 18ce52639..e817810ae 100644 --- a/services/backup_sa/include/module_ipc/svc_extension_proxy.h +++ b/services/backup_sa/include/module_ipc/svc_extension_proxy.h @@ -34,7 +34,7 @@ public: ErrCode IncrementalOnBackup() override; std::tuple GetIncrementalBackupFileHandle() override; ErrCode GetBackupInfo(std::string &result) override; - ErrCode UpdateFdSendRate(std::string &bundleName, int sendRate) override; + ErrCode UpdateFdSendRate(std::string &bundleName, int32_t sendRate) override; public: explicit SvcExtensionProxy(const sptr &remote) : IRemoteProxy(remote) {} diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 691c7aa15..6d9aa12ea 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -1288,8 +1288,9 @@ ErrCode Service::UpdateTimer(BundleName &bundleName, uint32_t timeOut, bool &res } } -ErrCode Service::UpdateSendRate(std::string bundleName, int sendRate, bool &result) +ErrCode Service::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) { + HILOGI("Begin, bundle name:%{public}s, sendRate is:%{public}d", bundleName.c_str(), sendRate); IServiceReverse::Scenario scenario = session_ -> GetScenario(); if (scenario != IServiceReverse::Scenario::BACKUP) { HILOGE("This method is applicable to the backup scenario"); @@ -1301,7 +1302,12 @@ ErrCode Service::UpdateSendRate(std::string bundleName, int sendRate, bool &resu throw BError(BError::Codes::SA_INVAL_ARG, "Extension backup Proxy is empty"); } auto ret = proxy->UpdateFdSendRate(bundleName, sendRate); - return ret; + if (ret != NO_ERROR) { + result = false; + return BError(BError::Codes::EXT_BROKEN_IPC); + } + result = true; + return BError(BError::Codes::OK); } AAFwk::Want Service::CreateConnectWant (BundleName &bundleName) diff --git a/services/backup_sa/src/module_ipc/service_stub.cpp b/services/backup_sa/src/module_ipc/service_stub.cpp index 7a43ba573..8cc66d5a4 100644 --- a/services/backup_sa/src/module_ipc/service_stub.cpp +++ b/services/backup_sa/src/module_ipc/service_stub.cpp @@ -38,6 +38,8 @@ void ServiceStub::ServiceStubSupplement() { opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_UPDATE_TIMER)] = &ServiceStub::CmdUpdateTimer; + opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_UPDATE_SENDRATE)] = + &ServiceStub::CmdUpdateSendRate; opToInterfaceMap_[static_cast( IServiceInterfaceCode::SERVICE_CMD_GET_APP_LOCAL_LIST_AND_DO_INCREMENTAL_BACKUP)] = &ServiceStub::CmdGetAppLocalListAndDoIncrementalBackup; @@ -416,6 +418,30 @@ int32_t ServiceStub::CmdUpdateTimer(MessageParcel &data, MessageParcel &reply) return BError(BError::Codes::OK); } +int32_t ServiceStub::CmdUpdateSendRate(MessageParcel &data, MessageParcel &reply) +{ + HILOGI("ServiceStub::CmdUpdateSendRate Begin."); + int ret = ERR_OK; + string bundleName; + if (!data.ReadString(bundleName)) { + return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive bundleName")); + } + int32_t sendRate; + if (!data.ReadInt32(sendRate)) { + return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive sendRate")); + } + bool result; + ret = UpdateSendRate(bundleName, sendRate, result); + if (ret != ERR_OK) { + return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to call UpdateSendRate")); + } + if (!reply.WriteBool(result)) { + return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result")); + } + HILOGI("ServiceStub::CmdUpdateSendRate end."); + return BError(BError::Codes::OK); +} + int32_t ServiceStub::CmdRelease(MessageParcel &data, MessageParcel &reply) { int res = Release(); diff --git a/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp b/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp index 6fd1d4426..f153b5cdf 100644 --- a/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp +++ b/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp @@ -178,30 +178,34 @@ ErrCode SvcExtensionProxy::GetBackupInfo(std::string &result) return ret; } -ErrCode SvcExtensionProxy::UpdateFdSendRate(std::string &bundleName, int sendRate) +ErrCode SvcExtensionProxy::UpdateFdSendRate(std::string &bundleName, int32_t sendRate) { HILOGD("SvcExtensionProxy::UpdateFdSendRate begin."); BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); MessageParcel data; data.WriteInterfaceToken(GetDescriptor()); - + if (!data.WriteString(bundleName)) { + BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleName"); + return ErrCode(EPERM); + } + if (!data.WriteInt32(sendRate)) { + BError(BError::Codes::SDK_INVAL_ARG, "Failed to send sendRate"); + return ErrCode(EPERM); + } MessageParcel reply; MessageOption option; int32_t ret = - Remote()->SendRequest(static_cast(IExtensionInterfaceCode::CMD_UPDATE_FD_SENDRATE), data, reply, option); + Remote()->SendRequest(static_cast(IExtensionInterfaceCode::CMD_UPDATE_FD_SENDRATE), data, reply, + option); if (ret != NO_ERROR) { HILOGE("Received error %{public}d when doing IPC", ret); return ErrCode(ret); } if (!reply.ReadInt32(ret)) { - HILOGE("fail to ReadInt32 ret"); - return ErrCode(ret); - } - if (ret != NO_ERROR) { - HILOGE("ret is not NO_ERROR. ret = %d", ret); + HILOGE("fail to read ret, ret is %{public}d", ret); return ErrCode(ret); } - HILOGI("SvcExtensionProxy::UpdateFdSendRate end. result: %s", result.c_str()); + HILOGI("SvcExtensionProxy::UpdateFdSendRate end."); return ret; } } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/mock/backup_kit_inner/service_proxy_mock.cpp b/tests/mock/backup_kit_inner/service_proxy_mock.cpp index df2f0000d..34ad31691 100644 --- a/tests/mock/backup_kit_inner/service_proxy_mock.cpp +++ b/tests/mock/backup_kit_inner/service_proxy_mock.cpp @@ -181,6 +181,11 @@ ErrCode ServiceProxy::UpdateTimer(BundleName &bundleName, uint32_t timeOut, bool return BError(BError::Codes::OK); } +ErrCode ServiceProxy::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) +{ + return BError(BError::Codes::OK); +} + sptr ServiceProxy::GetInstance() { if (!GetMockGetInstance()) { diff --git a/tests/mock/module_ipc/service_mock.cpp b/tests/mock/module_ipc/service_mock.cpp index a5e6ba7fa..1fe163cd8 100644 --- a/tests/mock/module_ipc/service_mock.cpp +++ b/tests/mock/module_ipc/service_mock.cpp @@ -220,6 +220,11 @@ ErrCode Service::UpdateTimer(BundleName &bundleName, uint32_t timeOut, bool &res return BError(BError::Codes::OK); } +ErrCode Service::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) +{ + return BError(BError::Codes::OK); +} + void Service::OnSABackup(const std::string &bundleName, const int &fd, const std::string &result, diff --git a/tests/mock/module_ipc/service_stub_mock.cpp b/tests/mock/module_ipc/service_stub_mock.cpp index fcb4aeb89..d0c82253a 100644 --- a/tests/mock/module_ipc/service_stub_mock.cpp +++ b/tests/mock/module_ipc/service_stub_mock.cpp @@ -67,13 +67,20 @@ ServiceStub::ServiceStub() &ServiceStub::CmdAppIncrementalFileReady; opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_INCREMENTAL_FILE_NAME)] = &ServiceStub::CmdGetIncrementalFileHandle; + ServiceStubSupplement(); + opToInterfaceMap_[static_cast( + IServiceInterfaceCode::SERVICE_CMD_GET_APP_LOCAL_LIST_AND_DO_INCREMENTAL_BACKUP)] = + &ServiceStub::CmdGetAppLocalListAndDoIncrementalBackup; +} + +void ServiceStub::ServiceStubSupplement() +{ opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_BACKUP_INFO)] = &ServiceStub::CmdGetBackupInfo; opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_UPDATE_TIMER)] = &ServiceStub::CmdUpdateTimer; - opToInterfaceMap_[static_cast( - IServiceInterfaceCode::SERVICE_CMD_GET_APP_LOCAL_LIST_AND_DO_INCREMENTAL_BACKUP)] = - &ServiceStub::CmdGetAppLocalListAndDoIncrementalBackup; + opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_UPDATE_SENDRATE)] = + &ServiceStub::CmdUpdateSendRate; } int32_t ServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) @@ -240,6 +247,22 @@ int32_t ServiceStub::CmdUpdateTimer(MessageParcel &data, MessageParcel &reply) return BError(BError::Codes::OK); } +int32_t ServiceStub::CmdUpdateSendRate(MessageParcel &data, MessageParcel &reply) +{ + int ret = ERR_OK; + string bundleName; + if (!data.ReadString(bundleName)) { + return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive bundleName")); + } + int32_t sendRate; + if (!data.ReadInt32(sendRate)) { + return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive sendRate")); + } + bool result; + ret = UpdateSendRate(bundleName, sendRate, result); + return BError(BError::Codes::OK); +} + int32_t ServiceStub::CmdRelease(MessageParcel &data, MessageParcel &reply) { int res = Release(); diff --git a/tests/mock/module_ipc/svc_extension_proxy_mock.cpp b/tests/mock/module_ipc/svc_extension_proxy_mock.cpp index 2bff08af7..bd20c461f 100644 --- a/tests/mock/module_ipc/svc_extension_proxy_mock.cpp +++ b/tests/mock/module_ipc/svc_extension_proxy_mock.cpp @@ -68,6 +68,11 @@ ErrCode SvcExtensionProxy::IncrementalOnBackup() return 0; } +ErrCode SvcExtensionProxy::UpdateFdSendRate(std::string &bundleName, int32_t sendRate) +{ + return 0; +} + tuple SvcExtensionProxy::GetIncrementalBackupFileHandle() { return {UniqueFd(-1), UniqueFd(-1)}; diff --git a/tests/unittests/backup_api/backup_impl/include/ext_extension_mock.h b/tests/unittests/backup_api/backup_impl/include/ext_extension_mock.h index bfa10b88c..7484d1b8c 100644 --- a/tests/unittests/backup_api/backup_impl/include/ext_extension_mock.h +++ b/tests/unittests/backup_api/backup_impl/include/ext_extension_mock.h @@ -134,6 +134,11 @@ public: return BError(BError::Codes::OK); }; + ErrCode UpdateFdSendRate(std::string &bundleName, int32_t sendRate) override + { + return BError(BError::Codes::OK); + }; + private: int32_t nHandleBackupNum_ = 0; }; diff --git a/tests/unittests/backup_api/backup_impl/include/i_service_mock.h b/tests/unittests/backup_api/backup_impl/include/i_service_mock.h index 3f1cb8c09..f32448ade 100644 --- a/tests/unittests/backup_api/backup_impl/include/i_service_mock.h +++ b/tests/unittests/backup_api/backup_impl/include/i_service_mock.h @@ -142,6 +142,11 @@ public: return BError(BError::Codes::OK); } + ErrCode UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) override + { + return BError(BError::Codes::OK); + } + ErrCode Release() override { return BError(BError::Codes::OK); diff --git a/tests/unittests/backup_api/backup_impl/service_proxy_test.cpp b/tests/unittests/backup_api/backup_impl/service_proxy_test.cpp index 9e005df20..eb1776ccc 100644 --- a/tests/unittests/backup_api/backup_impl/service_proxy_test.cpp +++ b/tests/unittests/backup_api/backup_impl/service_proxy_test.cpp @@ -789,6 +789,29 @@ HWTEST_F(ServiceProxyTest, SUB_Service_proxy_UpdateTimer_0100, testing::ext::Tes GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_UpdateTimer_0100"; } +/** + * @tc.number: SUB_Service_proxy_UpdateSendRate_0100 + * @tc.name: SUB_Service_proxy_UpdateSendRate_0100 + * @tc.desc: 测试 UpdateSendRate 获取应用信息接口调用成功和失败 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceProxyTest, SUB_Service_proxy_UpdateSendRate_0100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_UpdateSendRate_0100"; + EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) + .Times(1) + .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); + bool result; + std::string bundleName = "com.example.app2backup"; + int32_t sendRate = 300; + int32_t ret = proxy_->UpdateSendRate(bundleName, sendRate, result); + EXPECT_EQ(ret, BError(BError::Codes::OK)); + GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_UpdateSendRate_0100"; +} + /** * @tc.number: SUB_Service_proxy_GetAppLocalListAndDoIncrementalBackup_0100 * @tc.name: SUB_Service_proxy_GetAppLocalListAndDoIncrementalBackup_0100 diff --git a/tests/unittests/backup_ext/ext_extension_stub_test.cpp b/tests/unittests/backup_ext/ext_extension_stub_test.cpp index d552622ee..d20424054 100644 --- a/tests/unittests/backup_ext/ext_extension_stub_test.cpp +++ b/tests/unittests/backup_ext/ext_extension_stub_test.cpp @@ -37,6 +37,7 @@ public: MOCK_METHOD(ErrCode, IncrementalOnBackup, ()); MOCK_METHOD((std::tuple), GetIncrementalBackupFileHandle, ()); MOCK_METHOD(ErrCode, GetBackupInfo, (std::string &result)); + MOCK_METHOD(ErrCode, UpdateFdSendRate, (std::string &bundleName, int32_t sendRate)); }; class ExtExtensionStubTest : public testing::Test { @@ -502,4 +503,42 @@ HWTEST_F(ExtExtensionStubTest, SUB_backup_ext_ExtExtensionStub_CmdGetBackupInfo_ } GTEST_LOG_(INFO) << "ExtExtensionStubTest-end SUB_backup_ext_ExtExtensionStub_CmdGetBackupInfo_0100"; } + +/** + * @tc.number: SUB_backup_ext_ExtExtensionStub_CmdUpdateSendRate_0100 + * @tc.name: SUB_backup_ext_ExtExtensionStub_CmdUpdateSendRate_0100 + * @tc.desc: 测试 CmdUpdateSendRate 各个分支成功与失败 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: issuesI9QWK5 + */ +HWTEST_F(ExtExtensionStubTest, SUB_backup_ext_ExtExtensionStub_CmdUpdateSendRate_0100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ExtExtensionStubTest-begin SUB_backup_ext_ExtExtensionStub_CmdUpdateSendRate_0100"; + try { + MessageParcel data; + MessageParcel reply; + EXPECT_CALL(*stub, UpdateFdSendRate(_, _)).WillOnce(Return(0)); + EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(false)); + auto err = stub->CmdUpdateFdSendRate(data, reply); + EXPECT_EQ(err, BError(BError::Codes::EXT_BROKEN_IPC)); + + EXPECT_CALL(*stub, UpdateFdSendRate(_, _)).WillOnce(Return(0)); + EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); + EXPECT_CALL(*messageParcelMock, WriteString(_)).WillOnce(Return(false)); + err = stub->CmdUpdateFdSendRate(data, reply); + EXPECT_EQ(err, BError(BError::Codes::EXT_BROKEN_IPC)); + + EXPECT_CALL(*stub, UpdateFdSendRate(_, _)).WillOnce(Return(0)); + EXPECT_CALL(*messageParcelMock, WriteInt32(_)).WillOnce(Return(true)); + EXPECT_CALL(*messageParcelMock, WriteString(_)).WillOnce(Return(true)); + err = stub->CmdUpdateFdSendRate(data, reply); + EXPECT_EQ(err, BError(BError::Codes::OK)); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ExtExtensionStubTest-an exception occurred by CmdUpdateSendRate."; + } + GTEST_LOG_(INFO) << "ExtExtensionStubTest-end SUB_backup_ext_ExtExtensionStub_CmdUpdateSendRate_0100"; +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp b/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp index 901c640d4..71765843c 100644 --- a/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp @@ -79,6 +79,7 @@ public: MOCK_METHOD2(GetIncrementalFileHandle, ErrCode(const std::string &bundleName, const std::string &fileName)); MOCK_METHOD2(GetBackupInfo, ErrCode(string &bundleName, string &result)); MOCK_METHOD3(UpdateTimer, ErrCode(BundleName &bundleName, uint32_t timeOut, bool &result)); + MOCK_METHOD3(UpdateSendRate, ErrCode(std::string &bundleName, int32_t sendRate, bool &result)); }; class ServiceStubTest : public testing::Test { diff --git a/tests/unittests/backup_sa/session/service_proxy_mock.cpp b/tests/unittests/backup_sa/session/service_proxy_mock.cpp index aef139357..a3dd9c9b3 100644 --- a/tests/unittests/backup_sa/session/service_proxy_mock.cpp +++ b/tests/unittests/backup_sa/session/service_proxy_mock.cpp @@ -160,6 +160,11 @@ ErrCode ServiceProxy::UpdateTimer(BundleName &bundleName, uint32_t timeOut, bool return BError(BError::Codes::OK); } +ErrCode ServiceProxy::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) +{ + return BError(BError::Codes::OK); +} + sptr ServiceProxy::GetInstance() { return serviceProxy_; diff --git a/utils/include/b_resources/b_constants.h b/utils/include/b_resources/b_constants.h index 86e93de49..70803e082 100644 --- a/utils/include/b_resources/b_constants.h +++ b/utils/include/b_resources/b_constants.h @@ -72,9 +72,9 @@ constexpr int BACKUP_VFS_CACHE_PRESSURE = 10000; // 备份过程修改参数 constexpr int32_t INVALID_FD_NUM = -1; -constexpr int MAX_FD_SEND_RATE = 900; // 允许应用申请的最大FD数量 +constexpr int MAX_FD_SEND_RATE = 800; // 允许应用申请的最大FD数量 constexpr int MIN_FD_SEND_RATE = 0; // 允许应用申请的最小FD数量 -constexpr int DEFAULT_FD_SEND_RATE = 0; // 允许应用申请的最小FD数量 +constexpr int DEFAULT_FD_SEND_RATE = 60; // 框架默认的FD数量 // backup.para内配置项的名称,该配置项值为true时可在不更新hap包的情况下,可以读取包管理元数据配置文件的内容 static inline std::string BACKUP_DEBUG_OVERRIDE_EXTENSION_CONFIG_KEY = "backup.debug.overrideExtensionConfig"; -- Gitee