From 0b791dce8a641c34aa26ffd5dd39947e3c75048d Mon Sep 17 00:00:00 2001 From: "yaoruozi1@huawei.com" Date: Mon, 1 Apr 2024 16:21:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=87=E4=BB=BD=E6=81=A2=E5=A4=8D=E6=A1=86?= =?UTF-8?q?=E6=9E=B6bugfix?= 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_backup.h | 3 +- .../native/backup_ext/include/ext_backup_js.h | 3 +- .../native/backup_ext/src/ext_backup.cpp | 3 +- .../native/backup_ext/src/ext_backup_js.cpp | 39 ++++++++----------- .../native/backup_ext/src/ext_extension.cpp | 26 +------------ .../backup_ext/backup_extension_ability.js | 4 -- 6 files changed, 22 insertions(+), 56 deletions(-) diff --git a/frameworks/native/backup_ext/include/ext_backup.h b/frameworks/native/backup_ext/include/ext_backup.h index d9dd12aef..4127402b0 100644 --- a/frameworks/native/backup_ext/include/ext_backup.h +++ b/frameworks/native/backup_ext/include/ext_backup.h @@ -130,8 +130,7 @@ public: /** * @brief Called do restore. */ - virtual ErrCode OnRestore(std::function callbackEx, - std::function callback); + virtual ErrCode OnRestore(std::function callback); /** * @brief Called do GetBackupInfo. diff --git a/frameworks/native/backup_ext/include/ext_backup_js.h b/frameworks/native/backup_ext/include/ext_backup_js.h index c159507fa..185e0aa0c 100644 --- a/frameworks/native/backup_ext/include/ext_backup_js.h +++ b/frameworks/native/backup_ext/include/ext_backup_js.h @@ -98,8 +98,7 @@ public: * @param callbackEx The callbackEx. * @param callback The callBack. */ - ErrCode OnRestore(std::function callbackEx, - std::function callback) override; + ErrCode OnRestore(std::function callback) override; /** * @brief get app backup detail * diff --git a/frameworks/native/backup_ext/src/ext_backup.cpp b/frameworks/native/backup_ext/src/ext_backup.cpp index f49be75fe..0ffd1dd00 100644 --- a/frameworks/native/backup_ext/src/ext_backup.cpp +++ b/frameworks/native/backup_ext/src/ext_backup.cpp @@ -250,8 +250,7 @@ ErrCode ExtBackup::OnBackup(function callback) return ERR_OK; } -ErrCode ExtBackup::OnRestore(std::function callbackEx, - function callback) +ErrCode ExtBackup::OnRestore(function callback) { HILOGI("BackupExtensionAbility(base) OnRestore."); return ERR_OK; diff --git a/frameworks/native/backup_ext/src/ext_backup_js.cpp b/frameworks/native/backup_ext/src/ext_backup_js.cpp index 5437943f6..17ae9d302 100644 --- a/frameworks/native/backup_ext/src/ext_backup_js.cpp +++ b/frameworks/native/backup_ext/src/ext_backup_js.cpp @@ -44,9 +44,6 @@ #include "filemgmt_libhilog.h" namespace OHOS::FileManagement::Backup { -namespace { - const static uint32_t WAIT_ONRESTORE_EX_TIMEOUT = 10; -} using namespace std; static string GetSrcPath(const AppExecFwk::AbilityInfo &info) @@ -261,39 +258,37 @@ ErrCode ExtBackupJs::OnBackup(function callback) return errCode; } -ErrCode ExtBackupJs::OnRestore(std::function callbackEx, - function callback) +ErrCode ExtBackupJs::OnRestore(function callback) { HILOGI("BackupExtensionAbility(JS) OnRestore."); BExcepUltils::BAssert(jsObj_, BError::Codes::EXT_BROKEN_FRAMEWORK, "The app does not provide the onRestore interface."); - atoRet_.store(false); - callbackInfoEx_ = std::make_shared(callbackEx); + + auto argParser = [appVersionCode(appVersionCode_), + appVersionStr(appVersionStr_)](napi_env env, vector &argv) -> bool { + napi_value objValue = nullptr; + napi_create_object(env, &objValue); + napi_set_named_property(env, objValue, "code", AbilityRuntime::CreateJsValue(env, appVersionCode)); + napi_set_named_property(env, objValue, "name", AbilityRuntime::CreateJsValue(env, appVersionStr.c_str())); + argv.push_back(objValue); + return true; + }; callbackInfo_ = std::make_shared(callback); - auto retParser = ParseOnRestoreExRet(); - HILOGI("Start execute call Js onRestoreEx method"); - std::unique_lock lock(extJsRetMutex_); - int32_t errCode = CallJsMethod("onRestoreEx", jsRuntime_, jsObj_.get(), ParseRestoreExInfo(), retParser); - extJsRetCon_.wait_for(lock, std::chrono::seconds(WAIT_ONRESTORE_EX_TIMEOUT)); - - auto retParserBase = [jsRuntime {&jsRuntime_}, callbackInfoEx {callbackInfoEx_}, callbackInfo {callbackInfo_}] - (napi_env env, napi_value result) -> bool { + auto retParser = [jsRuntime {&jsRuntime_}, callbackInfo {callbackInfo_}](napi_env env, + napi_value result) -> bool { if (!CheckPromise(env, result)) { - HILOGI("Will callBack onRestore"); callbackInfo->callback(); return true; } HILOGI("CheckPromise(JS) OnRestore ok."); return CallPromise(*jsRuntime, result, callbackInfo.get()); }; - if (atoRet_.load()) { - errCode = CallJsMethod("onRestore", jsRuntime_, jsObj_.get(), ParseRestoreInfo(), retParserBase); - } + + auto errCode = CallJsMethod("onRestore", jsRuntime_, jsObj_.get(), argParser, retParser); if (errCode != ERR_OK) { - HILOGE("exe js method onRestore error,errCode: %{public}d", errCode); - return errCode; + HILOGE("CallJsMethod error, code:%{public}d.", errCode); } - return ERR_OK; + return errCode; } ErrCode ExtBackupJs::GetBackupInfo(std::function callback) diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index f3cc2c8bd..ae1e9c0a5 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -1028,17 +1028,6 @@ void BackupExtExtension::AsyncTaskRestoreForUpgrade() HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); auto task = [obj {wptr(this)}]() { auto ptr = obj.promote(); - auto callBackupEx = [obj](const std::string &restoreRetInfo) { - HILOGI("begin call restoreEx"); - auto extensionPtr = obj.promote(); - BExcepUltils::BAssert(extensionPtr, BError::Codes::EXT_BROKEN_FRAMEWORK, - "Ext extension handle have been already released"); - if (restoreRetInfo.size()) { - extensionPtr->AppResultReport(restoreRetInfo); - } - extensionPtr->AppDone(BError(BError::Codes::OK)); - extensionPtr->DoClear(); - }; auto callBackup = [obj]() { HILOGI("begin call restore"); auto extensionPtr = obj.promote(); @@ -1053,7 +1042,7 @@ void BackupExtExtension::AsyncTaskRestoreForUpgrade() "Ext extension handle have been already released"); BExcepUltils::BAssert(ptr->extension_, BError::Codes::EXT_INVAL_ARG, "extension handle have been already released"); - ptr->extension_->OnRestore(callBackupEx, callBackup); + ptr->extension_->OnRestore(callBackup); } catch (const BError &e) { ptr->AppDone(e.GetCode()); } catch (const exception &e) { @@ -1087,17 +1076,6 @@ void BackupExtExtension::AsyncTaskIncrementalRestoreForUpgrade() { auto task = [obj {wptr(this)}]() { auto ptr = obj.promote(); - auto callBackupEx = [obj](const std::string &restoreRetInfo) { - HILOGI("begin call restore"); - auto extensionPtr = obj.promote(); - BExcepUltils::BAssert(extensionPtr, BError::Codes::EXT_BROKEN_FRAMEWORK, - "Ext extension handle have been already released"); - if (restoreRetInfo.size()) { - extensionPtr->AppResultReport(restoreRetInfo); - } - extensionPtr->AppIncrementalDone(BError(BError::Codes::OK)); - extensionPtr->DoClear(); - }; auto callBackup = [obj]() { HILOGI("begin call restore"); auto extensionPtr = obj.promote(); @@ -1112,7 +1090,7 @@ void BackupExtExtension::AsyncTaskIncrementalRestoreForUpgrade() "Ext extension handle have been already released"); BExcepUltils::BAssert(ptr->extension_, BError::Codes::EXT_INVAL_ARG, "extension handle have been already released"); - ptr->extension_->OnRestore(callBackupEx, callBackup); + ptr->extension_->OnRestore(callBackup); } catch (const BError &e) { ptr->AppIncrementalDone(e.GetCode()); } catch (const exception &e) { diff --git a/interfaces/api/js/napi/backup_ext/backup_extension_ability.js b/interfaces/api/js/napi/backup_ext/backup_extension_ability.js index 1b64f900b..ba0f1c360 100644 --- a/interfaces/api/js/napi/backup_ext/backup_extension_ability.js +++ b/interfaces/api/js/napi/backup_ext/backup_extension_ability.js @@ -25,10 +25,6 @@ class BackupExtensionAbility { getBackupInfo() { console.log() } - - onRestoreEx(versionBackupedBundle, restoreInfo) { - console.log() - } } export default BackupExtensionAbility \ No newline at end of file -- Gitee