From cb464f67339733795f47f50139d461620a110193 Mon Sep 17 00:00:00 2001 From: g00613291 Date: Thu, 20 Jun 2024 20:46:16 +0800 Subject: [PATCH] onResultReport with bundleName --- .../src/service_incremental_reverse.cpp | 4 +- .../backup_kit_inner/src/service_reverse.cpp | 4 +- .../impl/b_incremental_backup_session.h | 2 +- .../impl/b_incremental_restore_session.h | 2 +- .../b_incremental_session_restore_async.h | 2 +- .../backup_kit_inner/impl/b_session_backup.h | 2 +- .../backup_kit_inner/impl/b_session_restore.h | 2 +- .../impl/b_session_restore_async.h | 2 +- interfaces/kits/js/BUILD.gn | 1 + .../kits/js/backup/general_callbacks.cpp | 105 ++++++++++++++++++ interfaces/kits/js/backup/general_callbacks.h | 15 ++- .../js/backup/session_backup_n_exporter.cpp | 17 ++- .../session_incremental_backup_n_exporter.cpp | 17 ++- .../js/backup/session_restore_n_exporter.cpp | 19 ++-- .../b_session_restore_async_mock.cpp | 4 +- .../tools_op_restore_async_test.cpp | 3 +- .../backup_tool/tools_op_restore_test.cpp | 3 +- tools/backup_tool/src/tools_op_backup.cpp | 6 +- .../src/tools_op_incremental_backup.cpp | 6 +- .../src/tools_op_incremental_restore.cpp | 6 +- .../tools_op_incremental_restore_async.cpp | 6 +- tools/backup_tool/src/tools_op_restore.cpp | 6 +- .../src/tools_op_restore_async.cpp | 6 +- 23 files changed, 188 insertions(+), 52 deletions(-) create mode 100644 interfaces/kits/js/backup/general_callbacks.cpp diff --git a/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp b/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp index fb05fa245..a6d27a66d 100644 --- a/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp +++ b/frameworks/native/backup_kit_inner/src/service_incremental_reverse.cpp @@ -47,7 +47,7 @@ void ServiceReverse::IncrementalBackupOnResultReport(std::string result, std::st HILOGI("Error scenario or callback is nullptr"); return; } - callbacksIncrementalBackup_.onResultReport(result); + callbacksIncrementalBackup_.onResultReport(bundleName, result); } void ServiceReverse::IncrementalBackupOnBundleFinished(int32_t errCode, string bundleName) @@ -116,7 +116,7 @@ void ServiceReverse::IncrementalRestoreOnResultReport(std::string result, std::s HILOGI("Error scenario or callback is nullptr"); return; } - callbacksIncrementalRestore_.onResultReport(result); + callbacksIncrementalRestore_.onResultReport(bundleName, result); if (scenario_ != Scenario::RESTORE || !callbacksIncrementalRestore_.onBundleFinished) { HILOGI("Error scenario or callback is nullptr"); return; diff --git a/frameworks/native/backup_kit_inner/src/service_reverse.cpp b/frameworks/native/backup_kit_inner/src/service_reverse.cpp index 18f0510e9..98942bd6b 100644 --- a/frameworks/native/backup_kit_inner/src/service_reverse.cpp +++ b/frameworks/native/backup_kit_inner/src/service_reverse.cpp @@ -46,7 +46,7 @@ void ServiceReverse::BackupOnResultReport(std::string result, std::string bundle HILOGI("Error scenario or callback is nullptr"); return; } - callbacksBackup_.onResultReport(result); + callbacksBackup_.onResultReport(bundleName, result); } void ServiceReverse::BackupOnBundleFinished(int32_t errCode, string bundleName) @@ -116,7 +116,7 @@ void ServiceReverse::RestoreOnResultReport(string result, std::string bundleName HILOGI("Error scenario or callback is nullptr"); return; } - callbacksRestore_.onResultReport(result); + callbacksRestore_.onResultReport(bundleName, result); if (scenario_ != Scenario::RESTORE || !callbacksRestore_.onBundleFinished) { HILOGI("Error scenario or callback is nullptr"); return; diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_backup_session.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_backup_session.h index 7f3eade3e..f37aa190e 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_backup_session.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_backup_session.h @@ -35,7 +35,7 @@ public: std::function onBundleFinished; // 当某个应用的备份流程结束或意外中止时执行的回调函数 std::function onAllBundlesFinished; // 当整个备份流程结束或意外中止时执行的回调函数 - std::function onResultReport; // 某个应用备份流程中自定义错误信息的上报的回调函数 + std::function onResultReport; // 某个应用备份流程中自定义错误信息的上报的回调函数 std::function onBackupServiceDied; // 当备份服务意外死亡时执行的回调函数 }; diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_restore_session.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_restore_session.h index 6606c8727..54b3a25b1 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_restore_session.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_restore_session.h @@ -35,7 +35,7 @@ public: std::function onBundleFinished; // 当某个应用的恢复流程结束或意外中止时执行的回调函数 std::function onAllBundlesFinished; // 当整个恢复流程结束或意外中止时执行的回调函数 - std::function onResultReport; // 某个应用恢复流程中自定义错误信息的上报的回调函数 + std::function onResultReport; // 某个应用恢复流程中自定义错误信息的上报的回调函数 std::function onBackupServiceDied; // 当备份服务意外死亡时执行的回调函数 }; diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_session_restore_async.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_session_restore_async.h index 3cec4806b..8405b9b88 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_session_restore_async.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_session_restore_async.h @@ -37,7 +37,7 @@ public: std::function onBundleFinished; // 当某个应用的恢复流程结束或意外中止时执行的回调函数 std::function onAllBundlesFinished; // 当整个恢复流程结束或意外中止时执行的回调函数 - std::function onResultReport; // 某个应用恢复流程中自定义错误信息的上报的回调函数 + std::function onResultReport; // 某个应用恢复流程中自定义错误信息的上报的回调函数 std::function onBackupServiceDied; // 当备份服务意外死亡时执行的回调函数 }; diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_backup.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_backup.h index 68f56264e..46a6e24b1 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_backup.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_backup.h @@ -33,7 +33,7 @@ public: std::function onBundleStarted; // 当启动某个应用的备份流程结束时执行的回调函数 std::function onBundleFinished; // 当某个应用的备份流程结束或意外中止时执行的回调函数 std::function onAllBundlesFinished; // 当整个备份流程结束或意外中止时执行的回调函数 - std::function onResultReport; // 某个应用备份流程中自定义错误信息的上报的回调函数 + std::function onResultReport; // 某个应用备份流程中自定义错误信息的上报的回调函数 std::function onBackupServiceDied; // 当备份服务意外死亡时执行的回调函数 }; diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore.h index ae9169474..06e833230 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore.h @@ -33,7 +33,7 @@ public: std::function onBundleStarted; // 当启动某个应用的恢复流程结束时执行的回调函数 std::function onBundleFinished; // 当某个应用的恢复流程结束或意外中止时执行的回调函数 std::function onAllBundlesFinished; // 当整个恢复流程结束或意外中止时执行的回调函数 - std::function onResultReport; // 某个应用恢复流程中自定义错误信息的上报的回调函数 + std::function onResultReport; // 某个应用恢复流程中自定义错误信息的上报的回调函数 std::function onBackupServiceDied; // 当备份服务意外死亡时执行的回调函数 }; diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore_async.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore_async.h index 405b659e8..4d4cdad10 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore_async.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore_async.h @@ -37,7 +37,7 @@ public: std::function onBundleFinished; // 当某个应用的恢复流程结束或意外中止时执行的回调函数 std::function onAllBundlesFinished; // 当整个恢复流程结束或意外中止时执行的回调函数 - std::function onResultReport; // 某个应用恢复流程中自定义错误信息的上报的回调函数 + std::function onResultReport; // 某个应用恢复流程中自定义错误信息的上报的回调函数 std::function onBackupServiceDied; // 当备份服务意外死亡时执行的回调函数 }; diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn index d1c52b8a8..5b556ac03 100644 --- a/interfaces/kits/js/BUILD.gn +++ b/interfaces/kits/js/BUILD.gn @@ -147,6 +147,7 @@ ohos_shared_library("backup") { "${path_backup_js}/backup/session_backup_n_exporter.cpp", "${path_backup_js}/backup/session_incremental_backup_n_exporter.cpp", "${path_backup_js}/backup/session_restore_n_exporter.cpp", + "${path_backup_js}/backup/general_callbacks.cpp", ] deps = [ diff --git a/interfaces/kits/js/backup/general_callbacks.cpp b/interfaces/kits/js/backup/general_callbacks.cpp new file mode 100644 index 000000000..399d64172 --- /dev/null +++ b/interfaces/kits/js/backup/general_callbacks.cpp @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "uv.h" +#include "native_reference.h" +#include "native_value.h" +#include "b_error/b_error.h" +#include "general_callbacks.h" + +namespace OHOS::FileManagement::Backup { +using namespace std; +BackupRestoreCallback::operator bool() const +{ + return bool(cb_); +} + +static void DoCallJsMethod(napi_env env, LibN::NRef cb, InputArgsParser argParser) +{ + HILOGI("Start execute DoCallJsMethod"); + napi_handle_scope scope = nullptr; + napi_open_handle_scope(env, &scope); + if (scope == nullptr) { + HILOGE("scope is nullptr"); + return; + } + vector argv = {}; + if (argParser != nullptr) { + if (!argParser(env, argv)) { + HILOGE("failed to get params."); + napi_close_handle_scope(env, scope); + return; + } + } + napi_value global = nullptr; + napi_get_global(env, &global); + napi_value callback = cb.Deref(env).val_; + napi_value result = nullptr; + napi_status status = napi_call_function(env, global, callback, argv.size(), argv.data(), &result); + if (status != napi_ok) { + HILOGE("Failed to call function for %{public}d.", status); + } + napi_close_handle_scope(env, scope); + HILOGI("End execute DoCallJsMethod"); +} + +void BackupRestoreCallback::CallJsMethod(InputArgsParser argParser) +{ + HILOGI("call BackupRestoreCallback CallJsMethod begin."); + uv_loop_s *loop = nullptr; + napi_status status = napi_get_uv_event_loop(env_, &loop); + if (status != napi_ok) { + HILOGE("failed to get uv event loop."); + return; + } + struct WorkArgs { + BackupRestoreCallback *ptr = nullptr; + InputArgsParser argParser; + }; + auto workArgs = make_unique(); + auto work = std::make_unique(); + if (workArgs == nullptr || work == nullptr) { + HILOGE("failed to new workArgs or uv_work_t."); + return; + } + workArgs->ptr = this; + workArgs->argParser = argParser; + work->data = reinterpret_cast(workArgs.get()); + HILOGI("Will execute current js method"); + int ret = uv_queue_work( + loop, work.get(), [](uv_work_t *work) {}, + [](uv_work_t *work, int status) { + auto workArgs = reinterpret_cast(work->data); + do { + if (workArgs == nullptr) { + HILOGE("failed to get CallJsParam."); + break; + } + DoCallJsMethod(workArgs->ptr->env_, workArgs->ptr->cb_, workArgs->argParser); + } while (false); + delete workArgs; + delete work; + }); + if (ret != 0) { + HILOGE("failed to exec uv_queue_work."); + workArgs.reset(); + work.reset(); + return; + } + workArgs.release(); + work.release(); + HILOGI("call BackupRestoreCallback CallJsMethod end."); +} +} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/interfaces/kits/js/backup/general_callbacks.h b/interfaces/kits/js/backup/general_callbacks.h index d5d0e1a2e..26872d2cc 100644 --- a/interfaces/kits/js/backup/general_callbacks.h +++ b/interfaces/kits/js/backup/general_callbacks.h @@ -22,6 +22,19 @@ #include "filemgmt_libn.h" namespace OHOS::FileManagement::Backup { +using InputArgsParser = std::function &)>; + +class BackupRestoreCallback { +public: + BackupRestoreCallback(napi_env env, LibN::NVal thisPtr, LibN::NVal cb) : env_(env), cb_(cb) {}; + ~BackupRestoreCallback() {}; + void CallJsMethod(InputArgsParser argParser); + explicit operator bool() const; +private: + napi_env env_; + LibN::NRef cb_; +}; + class GeneralCallbacks { public: GeneralCallbacks(const napi_env &env, const LibN::NVal &thisPtr, const LibN::NVal &jsCallbacks) @@ -38,7 +51,7 @@ public: LibN::NAsyncWorkCallback onBundleEnd; LibN::NAsyncWorkCallback onAllBundlesEnd; LibN::NAsyncWorkCallback onBackupServiceDied; - LibN::NAsyncWorkCallback onResultReport; + BackupRestoreCallback onResultReport; }; } // namespace OHOS::FileManagement::Backup #endif // INTERFACES_KITS_JS_SRC_MOD_BACKUP_PROPERTIES_GENERAL_CALLBACKS_H \ No newline at end of file diff --git a/interfaces/kits/js/backup/session_backup_n_exporter.cpp b/interfaces/kits/js/backup/session_backup_n_exporter.cpp index e81151e53..4230594f0 100644 --- a/interfaces/kits/js/backup/session_backup_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_backup_n_exporter.cpp @@ -187,7 +187,7 @@ static void onAllBundlesEnd(weak_ptr pCallbacks, ErrCode err) callbacks->onAllBundlesEnd.ThreadSafeSchedule(cbCompl); } -static void OnResultReport(weak_ptr pCallbacks, const std::string result) +static void OnResultReport(weak_ptr pCallbacks, const std::string bundleName, const std::string result) { HILOGI("callback function onResultReport begin"); if (pCallbacks.expired()) { @@ -203,11 +203,16 @@ static void OnResultReport(weak_ptr pCallbacks, const std::str HILOGI("callback function onResultReport is undefined"); return; } - auto cbCompl = [res {result}](napi_env env, NError err) -> NVal { - NVal str = NVal::CreateUTF8String(env, res); - return str; + auto cbCompl = [bName {bundleName}, res {result}](napi_env env, vector &argv) -> bool { + napi_value napi_bName = nullptr; + napi_create_string_utf8(env, bName.c_str(), bName.size(), &napi_bName); + argv.push_back(napi_bName); + napi_value napi_res = nullptr; + napi_create_string_utf8(env, res.c_str(), res.size(), &napi_res); + argv.push_back(napi_res); + return true; }; - callbacks->onResultReport.ThreadSafeSchedule(cbCompl); + callbacks->onResultReport.CallJsMethod(cbCompl); } static void OnBackupServiceDied(weak_ptr pCallbacks) @@ -258,7 +263,7 @@ napi_value SessionBackupNExporter::Constructor(napi_env env, napi_callback_info .onBundleStarted = bind(onBundleBegin, backupEntity->callbacks, placeholders::_1, placeholders::_2), .onBundleFinished = bind(onBundleEnd, backupEntity->callbacks, placeholders::_1, placeholders::_2), .onAllBundlesFinished = bind(onAllBundlesEnd, backupEntity->callbacks, placeholders::_1), - .onResultReport = bind(OnResultReport, backupEntity->callbacks, placeholders::_1), + .onResultReport = bind(OnResultReport, backupEntity->callbacks, placeholders::_1, placeholders::_2), .onBackupServiceDied = bind(OnBackupServiceDied, backupEntity->callbacks)}); if (!backupEntity->session) { NError(BError(BError::Codes::SDK_INVAL_ARG, "Failed to init backup").GetCode()).ThrowErr(env); diff --git a/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp b/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp index 588373ed3..bdfd00c35 100644 --- a/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_incremental_backup_n_exporter.cpp @@ -193,7 +193,7 @@ static void onAllBundlesEnd(weak_ptr pCallbacks, ErrCode err) callbacks->onAllBundlesEnd.ThreadSafeSchedule(cbCompl); } -static void OnResultReport(weak_ptr pCallbacks, const std::string result) +static void OnResultReport(weak_ptr pCallbacks, const std::string bundleName, const std::string result) { HILOGI("callback function onResultReport begin"); if (pCallbacks.expired()) { @@ -209,11 +209,16 @@ static void OnResultReport(weak_ptr pCallbacks, const std::str HILOGI("callback function onResultReport is undefined"); return; } - auto cbCompl = [res {result}](napi_env env, NError err) -> NVal { - NVal str = NVal::CreateUTF8String(env, res); - return str; + auto cbCompl = [bName {bundleName}, res {result}](napi_env env, vector &argv) -> bool { + napi_value napi_bName = nullptr; + napi_create_string_utf8(env, bName.c_str(), bName.size(), &napi_bName); + argv.push_back(napi_bName); + napi_value napi_res = nullptr; + napi_create_string_utf8(env, res.c_str(), res.size(), &napi_res); + argv.push_back(napi_res); + return true; }; - callbacks->onResultReport.ThreadSafeSchedule(cbCompl); + callbacks->onResultReport.CallJsMethod(cbCompl); } static void OnBackupServiceDied(weak_ptr pCallbacks) @@ -265,7 +270,7 @@ napi_value SessionIncrementalBackupNExporter::Constructor(napi_env env, napi_cal .onBundleStarted = bind(onBundleBegin, backupEntity->callbacks, placeholders::_1, placeholders::_2), .onBundleFinished = bind(onBundleEnd, backupEntity->callbacks, placeholders::_1, placeholders::_2), .onAllBundlesFinished = bind(onAllBundlesEnd, backupEntity->callbacks, placeholders::_1), - .onResultReport = bind(OnResultReport, backupEntity->callbacks, placeholders::_1), + .onResultReport = bind(OnResultReport, backupEntity->callbacks, placeholders::_1, placeholders::_2), .onBackupServiceDied = bind(OnBackupServiceDied, backupEntity->callbacks)}); if (!backupEntity->session) { NError(BError(BError::Codes::SDK_INVAL_ARG, "Failed to init backup").GetCode()).ThrowErr(env); diff --git a/interfaces/kits/js/backup/session_restore_n_exporter.cpp b/interfaces/kits/js/backup/session_restore_n_exporter.cpp index 7d4c83d92..fb7762f40 100644 --- a/interfaces/kits/js/backup/session_restore_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_restore_n_exporter.cpp @@ -262,7 +262,7 @@ static void OnBackupServiceDied(weak_ptr pCallbacks) callbacks->onBackupServiceDied.ThreadSafeSchedule(cbCompl); } -static void OnResultReport(weak_ptr pCallbacks, const std::string result) +static void OnResultReport(weak_ptr pCallbacks, const std::string bundleName, const std::string result) { HILOGD("callback function onResultReport begin."); if (pCallbacks.expired()) { @@ -278,11 +278,16 @@ static void OnResultReport(weak_ptr pCallbacks, const std::str HILOGI("callback function onResultReport is undefined"); return; } - auto cbCompl = [res {result}](napi_env env, NError err) -> NVal { - NVal str = NVal::CreateUTF8String(env, res); - return str; + auto cbCompl = [bName {bundleName}, res {result}](napi_env env, vector &argv) -> bool { + napi_value napi_bName = nullptr; + napi_create_string_utf8(env, bName.c_str(), bName.size(), &napi_bName); + argv.push_back(napi_bName); + napi_value napi_res = nullptr; + napi_create_string_utf8(env, res.c_str(), res.size(), &napi_res); + argv.push_back(napi_res); + return true; }; - callbacks->onResultReport.ThreadSafeSchedule(cbCompl); + callbacks->onResultReport.CallJsMethod(cbCompl); } static bool VerifyAppendBundlesParam(NFuncArg &funcArg, int32_t &fd, std::vector &bundleNames, @@ -403,7 +408,7 @@ napi_value SessionRestoreNExporter::Constructor(napi_env env, napi_callback_info .onBundleStarted = bind(onBundleBegin, restoreEntity->callbacks, placeholders::_1, placeholders::_2), .onBundleFinished = bind(onBundleEnd, restoreEntity->callbacks, placeholders::_1, placeholders::_2), .onAllBundlesFinished = bind(onAllBundlesEnd, restoreEntity->callbacks, placeholders::_1), - .onResultReport = bind(OnResultReport, restoreEntity->callbacks, placeholders::_1), + .onResultReport = bind(OnResultReport, restoreEntity->callbacks, placeholders::_1, placeholders::_2), .onBackupServiceDied = bind(OnBackupServiceDied, restoreEntity->callbacks)}); } else { restoreEntity->sessionSheet = nullptr; @@ -413,7 +418,7 @@ napi_value SessionRestoreNExporter::Constructor(napi_env env, napi_callback_info .onBundleStarted = bind(onBundleBegin, restoreEntity->callbacks, placeholders::_1, placeholders::_2), .onBundleFinished = bind(onBundleEnd, restoreEntity->callbacks, placeholders::_1, placeholders::_2), .onAllBundlesFinished = bind(onAllBundlesEnd, restoreEntity->callbacks, placeholders::_1), - .onResultReport = bind(OnResultReport, restoreEntity->callbacks, placeholders::_1), + .onResultReport = bind(OnResultReport, restoreEntity->callbacks, placeholders::_1, placeholders::_2), .onBackupServiceDied = bind(OnBackupServiceDied, restoreEntity->callbacks)}); } if (!restoreEntity->sessionWhole && !restoreEntity->sessionSheet) { diff --git a/tests/mock/backup_kit_inner/b_session_restore_async_mock.cpp b/tests/mock/backup_kit_inner/b_session_restore_async_mock.cpp index 89d28b3f3..dd71f134c 100644 --- a/tests/mock/backup_kit_inner/b_session_restore_async_mock.cpp +++ b/tests/mock/backup_kit_inner/b_session_restore_async_mock.cpp @@ -87,7 +87,7 @@ ErrCode BSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, vector(); + std::string bundleName = "com.example.app2backup"; std::string resultInfo = "test result info"; - OnResultReport(ctx, resultInfo); + OnResultReport(ctx, bundleName, resultInfo); EXPECT_TRUE(true); } catch (...) { EXPECT_TRUE(false); diff --git a/tests/unittests/backup_tools/backup_tool/tools_op_restore_test.cpp b/tests/unittests/backup_tools/backup_tool/tools_op_restore_test.cpp index a35d51072..3d7220db8 100644 --- a/tests/unittests/backup_tools/backup_tool/tools_op_restore_test.cpp +++ b/tests/unittests/backup_tools/backup_tool/tools_op_restore_test.cpp @@ -446,8 +446,9 @@ HWTEST_F(ToolsOpRestoreTest, tools_op_restore_OOnResultReport_0800, testing::ext GTEST_LOG_(INFO) << "ToolsOpRestoreTest-begin tools_op_restore_OOnResultReport_0800"; try { auto ctx = make_shared(); + std::string bundleName = "com.example.app2backup"; std::string resultInfo = "result info"; - OnResultReport(ctx, resultInfo); + OnResultReport(ctx, bundleName, resultInfo); EXPECT_TRUE(true); } catch (...) { EXPECT_TRUE(false); diff --git a/tools/backup_tool/src/tools_op_backup.cpp b/tools/backup_tool/src/tools_op_backup.cpp index 93959f3be..fcf892a4b 100644 --- a/tools/backup_tool/src/tools_op_backup.cpp +++ b/tools/backup_tool/src/tools_op_backup.cpp @@ -158,9 +158,9 @@ static void OnBundleStarted(shared_ptr ctx, ErrCode err, const BundleNa } } -static void OnResultReport(shared_ptr ctx, const std::string result) +static void OnResultReport(shared_ptr ctx, const std::string bundleName, const std::string result) { - printf("OnResultReport result is = %s\n", result.c_str()); + printf("OnResultReport bundleName = %s, result = %s\n", bundleName.c_str(), result.c_str()); } static void OnBundleFinished(shared_ptr ctx, ErrCode err, const BundleName name) @@ -248,7 +248,7 @@ static int32_t InitPathCapFile(const string &pathCapFile, vector bundleN .onBundleStarted = bind(OnBundleStarted, ctx, placeholders::_1, placeholders::_2), .onBundleFinished = bind(OnBundleFinished, ctx, placeholders::_1, placeholders::_2), .onAllBundlesFinished = bind(OnAllBundlesFinished, ctx, placeholders::_1), - .onResultReport = bind(OnResultReport, ctx, placeholders::_1), + .onResultReport = bind(OnResultReport, ctx, placeholders::_1, placeholders::_2), .onBackupServiceDied = bind(OnBackupServiceDied, ctx)}); if (ctx->session_ == nullptr) { printf("Failed to init backup\n"); diff --git a/tools/backup_tool/src/tools_op_incremental_backup.cpp b/tools/backup_tool/src/tools_op_incremental_backup.cpp index 6b429c0d1..2be218c80 100644 --- a/tools/backup_tool/src/tools_op_incremental_backup.cpp +++ b/tools/backup_tool/src/tools_op_incremental_backup.cpp @@ -213,9 +213,9 @@ static void OnAllBundlesFinished(shared_ptr ctx, ErrCode err) ctx->TryNotify(); } -static void OnResultReport(shared_ptr ctx, const std::string &resultInfo) +static void OnResultReport(shared_ptr ctx, const std::string &bundleName, const std::string &resultInfo) { - printf("OnResultReport, resultInfo = %s\n", resultInfo.c_str()); + printf("OnResultReport bundleName = %s, resultInfo = %s\n", bundleName.c_str(), resultInfo.c_str()); } static void OnBackupServiceDied(shared_ptr ctx) @@ -307,7 +307,7 @@ static int32_t Init(const string &pathCapFile, const vector& bundleNames .onBundleStarted = bind(OnBundleStarted, ctx, placeholders::_1, placeholders::_2), .onBundleFinished = bind(OnBundleFinished, ctx, placeholders::_1, placeholders::_2), .onAllBundlesFinished = bind(OnAllBundlesFinished, ctx, placeholders::_1), - .onResultReport = bind(OnResultReport, ctx, placeholders::_1), + .onResultReport = bind(OnResultReport, ctx, placeholders::_1, placeholders::_2), .onBackupServiceDied = bind(OnBackupServiceDied, ctx)}); if (ctx->session_ == nullptr) { printf("Failed to init backup\n"); diff --git a/tools/backup_tool/src/tools_op_incremental_restore.cpp b/tools/backup_tool/src/tools_op_incremental_restore.cpp index 7eaf331e7..a713c3642 100644 --- a/tools/backup_tool/src/tools_op_incremental_restore.cpp +++ b/tools/backup_tool/src/tools_op_incremental_restore.cpp @@ -214,9 +214,9 @@ static void OnBackupServiceDied(shared_ptr ctx) ctx->TryNotify(true); } -static void OnResultReport(shared_ptr ctx, const std::string &resultInfo) +static void OnResultReport(shared_ptr ctx, const std::string &bundleName, const std::string &resultInfo) { - printf("OnResultReport, detailInfo = %s\n", resultInfo.c_str()); + printf("OnResultReport bundleName = %s, resultInfo = %s\n", bundleName.c_str(), resultInfo.c_str()); } static void RestoreApp(shared_ptr restore) @@ -271,7 +271,7 @@ static int32_t InitRestoreSession(shared_ptr ctx, .onBundleStarted = bind(OnBundleStarted, ctx, placeholders::_1, placeholders::_2), .onBundleFinished = bind(OnBundleFinished, ctx, placeholders::_1, placeholders::_2), .onAllBundlesFinished = bind(OnAllBundlesFinished, ctx, placeholders::_1), - .onResultReport = bind(OnResultReport, ctx, placeholders::_1), + .onResultReport = bind(OnResultReport, ctx, placeholders::_1, placeholders::_2), .onBackupServiceDied = bind(OnBackupServiceDied, ctx)}); if (ctx->session_ == nullptr) { printf("Failed to init restore\n"); diff --git a/tools/backup_tool/src/tools_op_incremental_restore_async.cpp b/tools/backup_tool/src/tools_op_incremental_restore_async.cpp index c7a564630..42b8f7021 100644 --- a/tools/backup_tool/src/tools_op_incremental_restore_async.cpp +++ b/tools/backup_tool/src/tools_op_incremental_restore_async.cpp @@ -240,9 +240,9 @@ static void AdapteCloneOptimize(const string &path) close(cachedEntity.GetFd().Release()); } -static void OnResultReport(shared_ptr ctx, const std::string &resultInfo) +static void OnResultReport(shared_ptr ctx, const std::string &bundleName, const std::string &resultInfo) { - printf("OnResultReport, detailInfo = %s\n", resultInfo.c_str()); + printf("OnResultReport bundleName = %s, resultInfo = %s\n", bundleName.c_str(), resultInfo.c_str()); } static void RestoreApp(shared_ptr restore, vector &bundleNames) @@ -398,7 +398,7 @@ static int32_t InitArg(const string &pathCapFile, .onBundleStarted = bind(OnBundleStarted, ctx, placeholders::_1, placeholders::_2), .onBundleFinished = bind(OnBundleFinished, ctx, placeholders::_1, placeholders::_2), .onAllBundlesFinished = bind(OnAllBundlesFinished, ctx, placeholders::_1), - .onResultReport = bind(OnResultReport, ctx, placeholders::_1), + .onResultReport = bind(OnResultReport, ctx, placeholders::_1, placeholders::_2), .onBackupServiceDied = bind(OnBackupServiceDied, ctx)}); if (ctx->session_ == nullptr) { printf("Failed to init restore\n"); diff --git a/tools/backup_tool/src/tools_op_restore.cpp b/tools/backup_tool/src/tools_op_restore.cpp index ff51241ac..e9c172426 100644 --- a/tools/backup_tool/src/tools_op_restore.cpp +++ b/tools/backup_tool/src/tools_op_restore.cpp @@ -173,9 +173,9 @@ static void OnBundleFinished(shared_ptr ctx, ErrCode err, const BundleN ctx->TryNotify(); } -static void OnResultReport(shared_ptr ctx, const std::string &resultInfo) +static void OnResultReport(shared_ptr ctx, const std::string &bundleName, const std::string &resultInfo) { - printf("OnResultReport, detailInfo = %s\n", resultInfo.c_str()); + printf("OnResultReport bundleName = %s, resultInfo = %s\n", bundleName.c_str(), resultInfo.c_str()); } static void OnAllBundlesFinished(shared_ptr ctx, ErrCode err) @@ -256,7 +256,7 @@ static int32_t InitRestoreSession(shared_ptr ctx) .onBundleStarted = bind(OnBundleStarted, ctx, placeholders::_1, placeholders::_2), .onBundleFinished = bind(OnBundleFinished, ctx, placeholders::_1, placeholders::_2), .onAllBundlesFinished = bind(OnAllBundlesFinished, ctx, placeholders::_1), - .onResultReport = bind(OnResultReport, ctx, placeholders::_1), + .onResultReport = bind(OnResultReport, ctx, placeholders::_1, placeholders::_2), .onBackupServiceDied = bind(OnBackupServiceDied, ctx)}); if (ctx->session_ == nullptr) { printf("Failed to init restore\n"); diff --git a/tools/backup_tool/src/tools_op_restore_async.cpp b/tools/backup_tool/src/tools_op_restore_async.cpp index 2e6679767..b937cec51 100644 --- a/tools/backup_tool/src/tools_op_restore_async.cpp +++ b/tools/backup_tool/src/tools_op_restore_async.cpp @@ -159,9 +159,9 @@ static void OnAllBundlesFinished(shared_ptr ctx, ErrCode err) ctx->TryNotify(true); } -static void OnResultReport(shared_ptr ctx, const std::string &resultInfo) +static void OnResultReport(shared_ptr ctx, const std::string &bundleName, const std::string &resultInfo) { - printf("OnResultReport, detailInfo = %s\n", resultInfo.c_str()); + printf("OnResultReport bundleName = %s, resultInfo = %s\n", bundleName.c_str(), resultInfo.c_str()); } static void OnBackupServiceDied(shared_ptr ctx) @@ -382,7 +382,7 @@ static int32_t InitArg(const string &pathCapFile, .onBundleStarted = bind(OnBundleStarted, ctx, placeholders::_1, placeholders::_2), .onBundleFinished = bind(OnBundleFinished, ctx, placeholders::_1, placeholders::_2), .onAllBundlesFinished = bind(OnAllBundlesFinished, ctx, placeholders::_1), - .onResultReport = bind(OnResultReport, ctx, placeholders::_1), + .onResultReport = bind(OnResultReport, ctx, placeholders::_1, placeholders::_2), .onBackupServiceDied = bind(OnBackupServiceDied, ctx)}); if (ctx->session_ == nullptr) { printf("Failed to init restore\n"); -- Gitee