diff --git a/frameworks/native/backup_ext/include/ext_backup.h b/frameworks/native/backup_ext/include/ext_backup.h index d9dd12aefd8ac75e4868deb7bf9ed5b2ea508440..4127402b0701f3d1a2d6bc95dfce19ab5d114f59 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 c159507fa218edb4ad2b73bddc14983d7086f409..185e0aa0c2b08fca8f3fd2f977a8e41e69a472a2 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 f49be75fe5999aad627b1c5269dd2adfcb156bb7..0ffd1dd0041e465902be3119481df94f92a6bd4c 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 5437943f6338c9026f1aa5a50d5e2fd4c11958e6..17ae9d30219006077d3d7fb3f41f1a525bc8eccd 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 f3cc2c8bdee3f7a5a8b8f738b10788cdb61be5d5..ae1e9c0a513e3af56c68dff037f77d3e41195621 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 1b64f900bec981ad8962ca5396eacf4fbb9b1eea..ba0f1c360f39328ef5e160bab97a8ed6e1b5cd4d 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