From b52700e5cd68315bdbd1289dfc7970b98ec325ac Mon Sep 17 00:00:00 2001 From: chensihan Date: Fri, 15 Nov 2024 17:07:54 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=9B=9E=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chensihan --- .../backup_kit_inner/src/service_proxy.cpp | 6 ++---- .../backup_sa/src/module_ipc/service_stub.cpp | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/frameworks/native/backup_kit_inner/src/service_proxy.cpp b/frameworks/native/backup_kit_inner/src/service_proxy.cpp index ebf80bf70..e05fb5138 100644 --- a/frameworks/native/backup_kit_inner/src/service_proxy.cpp +++ b/frameworks/native/backup_kit_inner/src/service_proxy.cpp @@ -201,14 +201,13 @@ ErrCode ServiceProxy::AppDone(ErrCode errCode) MessageParcel reply; MessageOption option; - option.SetFlags(MessageOption::TF_ASYNC); int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_DONE), 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(); } - return ret; + return reply.ReadInt32(); } ErrCode ServiceProxy::ServiceResultReport(const std::string restoreRetInfo, @@ -231,7 +230,6 @@ ErrCode ServiceProxy::ServiceResultReport(const std::string restoreRetInfo, } MessageParcel reply; MessageOption option; - option.SetFlags(MessageOption::TF_ASYNC); int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_RESULT_REPORT), data, reply, option); @@ -239,7 +237,7 @@ ErrCode ServiceProxy::ServiceResultReport(const std::string restoreRetInfo, string str = "Failed to send out the request because of " + to_string(ret); return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); } - return ret; + return reply.ReadInt32(); } ErrCode ServiceProxy::GetFileHandle(const string &bundleName, const string &fileName) diff --git a/services/backup_sa/src/module_ipc/service_stub.cpp b/services/backup_sa/src/module_ipc/service_stub.cpp index 1efd2af05..20dedbbba 100644 --- a/services/backup_sa/src/module_ipc/service_stub.cpp +++ b/services/backup_sa/src/module_ipc/service_stub.cpp @@ -236,7 +236,13 @@ int32_t ServiceStub::CmdAppDone(MessageParcel &data, MessageParcel &reply) if (!data.ReadInt32(errCode)) { return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive errCode"); } - return AppDone(errCode); + int res = AppDone(errCode); + if (!reply.WriteInt32(res)) { + stringstream ss; + ss << "Failed to send the result " << res; + return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); + } + return BError(BError::Codes::OK); } int32_t ServiceStub::CmdResultReport(MessageParcel &data, MessageParcel &reply) @@ -254,7 +260,13 @@ int32_t ServiceStub::CmdResultReport(MessageParcel &data, MessageParcel &reply) if (!data.ReadInt32(errCode)) { return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive errCode"); } - return ServiceResultReport(restoreRetInfo, secenrioInfo, errCode); + int res = ServiceResultReport(restoreRetInfo, secenrioInfo, errCode); + if (!reply.WriteInt32(res)) { + stringstream ss; + ss << "Failed to send the result " << res; + return BError(BError::Codes::SA_BROKEN_IPC, ss.str()); + } + return BError(BError::Codes::OK); } int32_t ServiceStub::CmdGetFileHandle(MessageParcel &data, MessageParcel &reply) -- Gitee From eb78d00a79a22119f168df79cd1e24df9c692f2f Mon Sep 17 00:00:00 2001 From: chensihan Date: Fri, 15 Nov 2024 09:09:52 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chensihan --- .../native/backup_ext/src/ext_backup_js.cpp | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/frameworks/native/backup_ext/src/ext_backup_js.cpp b/frameworks/native/backup_ext/src/ext_backup_js.cpp index 8df524290..d6293eaa8 100644 --- a/frameworks/native/backup_ext/src/ext_backup_js.cpp +++ b/frameworks/native/backup_ext/src/ext_backup_js.cpp @@ -48,7 +48,7 @@ namespace OHOS::FileManagement::Backup { using namespace std; constexpr size_t ARGC_ONE = 1; static std::mutex g_extBackupValidLock; -static bool g_isExtBackupValid = true; +static int32_t g_extBackupCount = 0; static string GetSrcPath(const AppExecFwk::AbilityInfo &info) { @@ -107,8 +107,8 @@ static napi_status DealNapiException(napi_env env, napi_value &exception, std::s static napi_value PromiseCallback(napi_env env, napi_callback_info info) { std::lock_guard lock(g_extBackupValidLock); - if (!g_isExtBackupValid) { - HILOGE("ExtBackup is invalid"); + if (g_extBackupCount <= 0) { + HILOGE("ExtBackup is invalid, count=%{public}d", g_extBackupCount); return nullptr; } HILOGI("Promise callback."); @@ -149,8 +149,8 @@ static napi_value PromiseCatchCallback(napi_env env, napi_callback_info info) return nullptr; } std::lock_guard lock(g_extBackupValidLock); - if (!g_isExtBackupValid) { - HILOGE("ExtBackup is invalid"); + if (g_extBackupCount <= 0) { + HILOGE("ExtBackup is invalid, count=%{public}d", g_extBackupCount); data = nullptr; return nullptr; } @@ -163,8 +163,8 @@ static napi_value PromiseCatchCallback(napi_env env, napi_callback_info info) static napi_value PromiseCallbackEx(napi_env env, napi_callback_info info) { std::lock_guard lock(g_extBackupValidLock); - if (!g_isExtBackupValid) { - HILOGE("ExtBackup is invalid"); + if (g_extBackupCount <= 0) { + HILOGE("ExtBackup is invalid, count=%{public}d", g_extBackupCount); return nullptr; } HILOGI("PromiseEx callback."); @@ -205,8 +205,8 @@ static napi_value PromiseCatchCallbackEx(napi_env env, napi_callback_info info) return nullptr; } std::lock_guard lock(g_extBackupValidLock); - if (!g_isExtBackupValid) { - HILOGE("ExtBackup is invalid"); + if (g_extBackupCount <= 0) { + HILOGE("ExtBackup is invalid, count=%{public}d", g_extBackupCount); data = nullptr; return nullptr; } @@ -454,16 +454,17 @@ napi_value AttachBackupExtensionContext(napi_env env, void *value, void *) ExtBackupJs::ExtBackupJs(AbilityRuntime::JsRuntime &jsRuntime) : jsRuntime_(jsRuntime) { - g_isExtBackupValid = true; - HILOGI("ExtBackupJs::ExtBackupJs."); + std::lock_guard lock(g_extBackupValidLock); + g_extBackupCount += 1; + HILOGI("ExtBackupJs::ExtBackupJs, count=%{public}d.", g_extBackupCount); } ExtBackupJs::~ExtBackupJs() { jsRuntime_.FreeNativeReference(std::move(jsObj_)); std::lock_guard lock(g_extBackupValidLock); - g_isExtBackupValid = false; - HILOGI("ExtBackupJs::~ExtBackupJs."); + g_extBackupCount -= 1; + HILOGI("ExtBackupJs::~ExtBackupJs, count=%{public}d.", g_extBackupCount); } void ExtBackupJs::ExportJsContext(void) -- Gitee