mirror of
https://gitee.com/openharmony/filemanagement_app_file_service
synced 2024-11-23 08:00:16 +00:00
Merge branch 'master' of gitee.com:openharmony/filemanagement_app_file_service into master
Signed-off-by: yaoruozi <15969709967@163.com>
This commit is contained in:
commit
c3e07d2604
@ -118,7 +118,6 @@ private:
|
||||
*
|
||||
* @param restoreRetInfo app processInfo
|
||||
* @param scenario backup or restore
|
||||
* @param errCode errCode
|
||||
*/
|
||||
void ReportAppProcessInfo(const std::string processInfo, BackupRestoreScenario scenario);
|
||||
|
||||
@ -181,47 +180,57 @@ private:
|
||||
void AppIncrementalDone(ErrCode errCode);
|
||||
|
||||
/**
|
||||
* @brief get callbackEx for execute onRestore
|
||||
* @brief start extension timer by ipc
|
||||
*
|
||||
* @param errCode
|
||||
* @param result
|
||||
*/
|
||||
std::function<void(ErrCode, const std::string)> FullRestoreCallbackEx(wptr<BackupExtExtension> obj);
|
||||
void StartExtTimer(bool &isExtStart);
|
||||
|
||||
/**
|
||||
* @brief get callback for execute onRestore
|
||||
* @brief start fwk timer by ipc
|
||||
*
|
||||
* @param errCode
|
||||
*/
|
||||
std::function<void(ErrCode, const std::string)> FullRestoreCallback(wptr<BackupExtExtension> obj);
|
||||
void StartFwkTimer(bool &isFwkStart);
|
||||
|
||||
/**
|
||||
* @brief get callbackEx for execute onRestore with string param
|
||||
* @brief get increCallbackEx for execute onRestore with string param
|
||||
*
|
||||
* @param errCode
|
||||
*/
|
||||
std::function<void(ErrCode, const std::string)> IncRestoreResultCallbackEx(wptr<BackupExtExtension> obj);
|
||||
std::function<void(ErrCode, const std::string)> IncreOnRestoreExCallback(wptr<BackupExtExtension> obj);
|
||||
|
||||
/**
|
||||
* @brief get increCallback for execute onRestore with string param
|
||||
*
|
||||
* @param errCode
|
||||
*/
|
||||
std::function<void(ErrCode, const std::string)> IncreOnRestoreCallback(wptr<BackupExtExtension> obj);
|
||||
|
||||
/**
|
||||
* @brief get callback for execute onRestore with string param
|
||||
*
|
||||
* @param errCode
|
||||
*/
|
||||
std::function<void(ErrCode, const std::string)> IncRestoreResultCallback(wptr<BackupExtExtension> obj);
|
||||
std::function<void(ErrCode, std::string)> OnRestoreCallback(wptr<BackupExtExtension> obj);
|
||||
|
||||
/**
|
||||
* @brief get callbackEx for execute onRestore
|
||||
* @brief get callbackEx for execute onRestore with string param
|
||||
*
|
||||
* @param errCode
|
||||
*/
|
||||
std::function<void(ErrCode, std::string)> IncAppDoneCallbackEx(wptr<BackupExtExtension> obj);
|
||||
std::function<void(ErrCode, std::string)> OnRestoreExCallback(wptr<BackupExtExtension> obj);
|
||||
|
||||
/**
|
||||
* @brief get callbackEx for execute appDone
|
||||
*/
|
||||
std::function<void(ErrCode, std::string)> AppDoneCallbackEx(wptr<BackupExtExtension> obj);
|
||||
std::function<void(ErrCode, const std::string)> HandleBackupEx(wptr<BackupExtExtension> obj);
|
||||
std::function<void(ErrCode, const std::string)> HandleFullBackupCallbackEx(wptr<BackupExtExtension> obj);
|
||||
std::function<void(ErrCode, const std::string)> HandleFullBackupCallback(wptr<BackupExtExtension> obj);
|
||||
|
||||
std::function<void(ErrCode, const std::string)> IncOnBackupExCallback(wptr<BackupExtExtension> obj);
|
||||
std::function<void(ErrCode, const std::string)> IncOnBackupCallback(wptr<BackupExtExtension> obj);
|
||||
|
||||
std::function<void(ErrCode, const std::string)> OnBackupExCallback(wptr<BackupExtExtension> obj);
|
||||
std::function<void(ErrCode, const std::string)> OnBackupCallback(wptr<BackupExtExtension> obj);
|
||||
|
||||
void HandleSpecialVersionRestore();
|
||||
void DeleteBackupIncrementalTars();
|
||||
@ -237,30 +246,18 @@ private:
|
||||
void DealIncreUnPacketResult(const off_t tarFileSize, const std::string &tarFileName,
|
||||
const std::tuple<int, EndFileInfo, ErrFileInfo> &result);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void StartOnProcessTaskThread(BackupRestoreScenario scenario);
|
||||
void StartOnProcessTaskThread(wptr<BackupExtExtension> obj, BackupRestoreScenario scenario);
|
||||
void FinishOnProcessTask();
|
||||
void ExecCallOnProcessTask(wptr<BackupExtExtension> obj, BackupRestoreScenario scenario);
|
||||
void AsyncCallJsOnProcessTask(wptr<BackupExtExtension> obj, BackupRestoreScenario scenario);
|
||||
|
||||
void SyncCallJsOnProcessTask(wptr<BackupExtExtension> obj, BackupRestoreScenario scenario);
|
||||
void StartOnProcessTimeOutTimer(wptr<BackupExtExtension> obj);
|
||||
void CloseOnProcessTimeOutTimer();
|
||||
|
||||
|
||||
|
||||
private:
|
||||
std::shared_mutex lock_;
|
||||
std::shared_ptr<ExtBackup> extension_;
|
||||
std::string backupInfo_;
|
||||
std::string bundleProcessInfo_;
|
||||
OHOS::ThreadPool threadPool_;
|
||||
std::mutex updateSendRateLock_;
|
||||
std::condition_variable startSendFdRateCon_;
|
||||
@ -275,7 +272,6 @@ private:
|
||||
std::map<std::string, std::vector<ErrCode>> errFileInfos_;
|
||||
bool isRpValid_ {false};
|
||||
|
||||
|
||||
std::thread callJsOnProcessThread_;
|
||||
Utils::Timer onProcessTimeoutTimer_ {"onProcessTimeoutTimer_"};
|
||||
uint32_t onProcessTimeoutTimerId_;
|
||||
@ -284,7 +280,6 @@ private:
|
||||
std::condition_variable execOnProcessCon_;
|
||||
std::mutex onProcessLock_;
|
||||
std::atomic<bool> onProcessTimeout_ {false};
|
||||
|
||||
};
|
||||
} // namespace OHOS::FileManagement::Backup
|
||||
|
||||
|
@ -724,7 +724,7 @@ static int DoCallJsMethod(CallJsParam *param)
|
||||
return EINVAL;
|
||||
}
|
||||
napi_value result;
|
||||
HILOGI("Extension start do call current js method");
|
||||
HILOGI("Extension start do call current js method, methodName:%{public}s", param->funcName.c_str());
|
||||
napi_call_function(env, value, method, argv.size(), argv.data(), &result);
|
||||
if (!param->retParser(env, handleEscape.Escape(result))) {
|
||||
HILOGE("Parser js result fail.");
|
||||
@ -865,15 +865,9 @@ ErrCode ExtBackupJs::OnProcess(std::function<void(ErrCode, const std::string)> c
|
||||
onProcessCallback_ = std::make_shared<OnProcessCallBackInfo>(callback);
|
||||
auto retParser = [jsRuntime {&jsRuntime_}, callBackInfo {onProcessCallback_}](napi_env env,
|
||||
napi_value result) -> bool {
|
||||
size_t strLen = 0;
|
||||
napi_status status = napi_get_value_string_utf8(env, result, nullptr, -1, &strLen);
|
||||
if (status != napi_ok) {
|
||||
return false;
|
||||
}
|
||||
size_t bufLen = strLen + 1;
|
||||
unique_ptr<char[]> str = make_unique<char[]>(bufLen);
|
||||
status = napi_get_value_string_utf8(env, result, str.get(), bufLen, &strLen);
|
||||
callBackInfo->onProcessCallback(BError(BError::Codes::OK), str.get());
|
||||
string processStr;
|
||||
DealNapiStrValue(env, result, processStr);
|
||||
callBackInfo->onProcessCallback(BError(BError::Codes::OK), processStr);
|
||||
return true;
|
||||
};
|
||||
auto errCode = CallJsMethod("onProcess", jsRuntime_, jsObj_.get(), {}, retParser);
|
||||
|
@ -785,6 +785,14 @@ void BackupExtExtension::AsyncTaskBackup(const string config)
|
||||
auto ptr = obj.promote();
|
||||
BExcepUltils::BAssert(ptr, BError::Codes::EXT_BROKEN_FRAMEWORK, "Ext extension handle have been released");
|
||||
try {
|
||||
HILOGI("Do backup, start fwk timer begin.");
|
||||
bool isFwkStart;
|
||||
ptr->StartFwkTimer(isFwkStart);
|
||||
if (!isFwkStart) {
|
||||
HILOGE("Do backup, start fwk timer fail.");
|
||||
return;
|
||||
}
|
||||
HILOGI("Do backup, start fwk timer end.");
|
||||
BJsonCachedEntity<BJsonEntityExtensionConfig> cachedEntity(config);
|
||||
auto cache = cachedEntity.Structuralize();
|
||||
auto ret = ptr->DoBackup(cache);
|
||||
@ -1259,15 +1267,21 @@ void BackupExtExtension::AsyncTaskIncreRestoreSpecialVersion()
|
||||
void BackupExtExtension::AsyncTaskRestoreForUpgrade()
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
|
||||
StartOnProcessTaskThread(BackupRestoreScenario::FULL_RESTORE);
|
||||
auto task = [obj {wptr<BackupExtExtension>(this)}]() {
|
||||
auto ptr = obj.promote();
|
||||
BExcepUltils::BAssert(ptr, BError::Codes::EXT_BROKEN_FRAMEWORK, "Ext extension handle have been released");
|
||||
BExcepUltils::BAssert(ptr->extension_, BError::Codes::EXT_INVAL_ARG, "Extension handle have been released");
|
||||
try {
|
||||
auto callBackup = ptr->FullRestoreCallback(obj);
|
||||
auto callBackupEx = ptr->FullRestoreCallbackEx(obj);
|
||||
ptr->CreateExecOnProcessTask(BackupRestoreScenario::FULL_RESTORE);
|
||||
HILOGI("On restore, start ext timer begin.");
|
||||
bool isExtStart;
|
||||
ptr->StartExtTimer(isExtStart);
|
||||
if (!isExtStart) {
|
||||
HILOGE("On restore, start ext timer fail.");
|
||||
return;
|
||||
}
|
||||
ptr->StartOnProcessTaskThread(obj, BackupRestoreScenario::FULL_RESTORE);
|
||||
auto callBackup = ptr->OnRestoreCallback(obj);
|
||||
auto callBackupEx = ptr->OnRestoreExCallback(obj);
|
||||
ErrCode err = ptr->extension_->OnRestore(callBackup, callBackupEx);
|
||||
if (err != ERR_OK) {
|
||||
ptr->AppDone(BError::GetCodeByErrno(err));
|
||||
@ -1303,15 +1317,21 @@ void BackupExtExtension::ExtClear()
|
||||
|
||||
void BackupExtExtension::AsyncTaskIncrementalRestoreForUpgrade()
|
||||
{
|
||||
StartOnProcessTaskThread(BackupRestoreScenario::INCREMENTAL_RESTORE);
|
||||
auto task = [obj {wptr<BackupExtExtension>(this)}]() {
|
||||
auto ptr = obj.promote();
|
||||
BExcepUltils::BAssert(ptr, BError::Codes::EXT_BROKEN_FRAMEWORK, "Ext extension handle have been released");
|
||||
BExcepUltils::BAssert(ptr->extension_, BError::Codes::EXT_INVAL_ARG, "Extension handle have been released");
|
||||
try {
|
||||
auto callBackup = ptr->IncRestoreResultCallback(obj);
|
||||
auto callBackupEx = ptr->IncRestoreResultCallbackEx(obj);
|
||||
ptr->CreateExecOnProcessTask(BackupRestoreScenario::INCREMENTAL_RESTORE);
|
||||
HILOGI("On incrementalRestore, start ext timer begin.");
|
||||
bool isExtStart;
|
||||
ptr->StartExtTimer(isExtStart);
|
||||
if (!isExtStart) {
|
||||
HILOGE("On incrementalRestore, start ext timer fail.");
|
||||
return;
|
||||
}
|
||||
ptr->StartOnProcessTaskThread(obj, BackupRestoreScenario::INCREMENTAL_RESTORE);
|
||||
auto callBackup = ptr->IncreOnRestoreCallback(obj);
|
||||
auto callBackupEx = ptr->IncreOnRestoreExCallback(obj);
|
||||
ErrCode err = ptr->extension_->OnRestore(callBackup, callBackupEx);
|
||||
if (err != ERR_OK) {
|
||||
HILOGE("OnRestore done, err = %{pubilc}d", err);
|
||||
@ -1401,17 +1421,39 @@ void BackupExtExtension::AppResultReport(const std::string restoreRetInfo,
|
||||
}
|
||||
}
|
||||
|
||||
void BackupExtExtension::StartExtTimer(bool &isExtStart)
|
||||
{
|
||||
auto proxy = ServiceProxy::GetInstance();
|
||||
BExcepUltils::BAssert(proxy, BError::Codes::EXT_BROKEN_IPC, "Failed to obtain the ServiceProxy handle");
|
||||
HILOGI("Start ext timer by ipc.");
|
||||
auto ret = proxy->StartExtTimer(isExtStart);
|
||||
if (ret != ERR_OK) {
|
||||
HILOGE("Start ext timer failed, errCode: %{public}d", ret);
|
||||
}
|
||||
}
|
||||
|
||||
void BackupExtExtension::StartFwkTimer(bool &isFwkStart)
|
||||
{
|
||||
auto proxy = ServiceProxy::GetInstance();
|
||||
BExcepUltils::BAssert(proxy, BError::Codes::EXT_BROKEN_IPC, "Failed to obtain the ServiceProxy handle");
|
||||
HILOGI("Start fwk timer by ipc.");
|
||||
auto ret = proxy->StartFwkTimer(isFwkStart);
|
||||
if (ret != ERR_OK) {
|
||||
HILOGE("Start fwk timer failed, errCode: %{public}d", ret);
|
||||
}
|
||||
}
|
||||
|
||||
void BackupExtExtension::AsyncTaskOnBackup()
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
|
||||
StartOnProcessTaskThread(BackupRestoreScenario::FULL_BACKUP);
|
||||
auto task = [obj {wptr<BackupExtExtension>(this)}]() {
|
||||
auto ptr = obj.promote();
|
||||
BExcepUltils::BAssert(ptr, BError::Codes::EXT_BROKEN_FRAMEWORK, "Ext extension handle have been released");
|
||||
BExcepUltils::BAssert(ptr->extension_, BError::Codes::EXT_INVAL_ARG, "Extension handle have been released");
|
||||
try {
|
||||
auto callBackup = ptr->HandleFullBackupCallback(obj);
|
||||
auto callBackupEx = ptr->HandleFullBackupCallbackEx(obj);
|
||||
ptr->StartOnProcessTaskThread(obj, BackupRestoreScenario::FULL_BACKUP);
|
||||
auto callBackup = ptr->OnBackupCallback(obj);
|
||||
auto callBackupEx = ptr->OnBackupExCallback(obj);
|
||||
ErrCode err = ptr->extension_->OnBackup(callBackup, callBackupEx);
|
||||
if (err != ERR_OK) {
|
||||
HILOGE("OnBackup done, err = %{pubilc}d", err);
|
||||
@ -1736,7 +1778,14 @@ ErrCode BackupExtExtension::IncrementalBigFileReady(const TarMap &pkgInfo,
|
||||
|
||||
void BackupExtExtension::AsyncTaskDoIncrementalBackup(UniqueFd incrementalFd, UniqueFd manifestFd)
|
||||
{
|
||||
HILOGI("Start AsyncTaskDoIncrementalBackup");
|
||||
HILOGI("Do IncrementalBackup, start fwk timer begin.");
|
||||
bool isFwkStart;
|
||||
StartFwkTimer(isFwkStart);
|
||||
if (!isFwkStart) {
|
||||
HILOGE("Do IncrementalBackup, start fwk timer fail.");
|
||||
return;
|
||||
}
|
||||
HILOGI("Do IncrementalBackup, start fwk timer end.");
|
||||
int incrementalFdDup = dup(incrementalFd);
|
||||
int manifestFdDup = dup(manifestFd);
|
||||
if (incrementalFdDup < 0) {
|
||||
@ -1782,28 +1831,14 @@ void BackupExtExtension::AsyncTaskDoIncrementalBackup(UniqueFd incrementalFd, Un
|
||||
|
||||
void BackupExtExtension::AsyncTaskOnIncrementalBackup()
|
||||
{
|
||||
StartOnProcessTaskThread(BackupRestoreScenario::INCREMENTAL_BACKUP);
|
||||
auto task = [obj {wptr<BackupExtExtension>(this)}]() {
|
||||
auto callBackup = [obj](ErrCode errCode, std::string errMsg) {
|
||||
HILOGI("App onbackup end");
|
||||
auto proxy = ServiceProxy::GetInstance();
|
||||
if (proxy == nullptr) {
|
||||
throw BError(BError::Codes::EXT_BROKEN_BACKUP_SA, std::generic_category().message(errno));
|
||||
}
|
||||
auto extPtr = obj.promote();
|
||||
if (extPtr == nullptr) {
|
||||
HILOGE("Current extension execute call backup error, extPtr is empty");
|
||||
return;
|
||||
}
|
||||
HILOGI("Start GetAppLocalListAndDoIncrementalBackup");
|
||||
extPtr->FinishOnProcessTask();
|
||||
proxy->GetAppLocalListAndDoIncrementalBackup();
|
||||
};
|
||||
auto ptr = obj.promote();
|
||||
BExcepUltils::BAssert(ptr, BError::Codes::EXT_BROKEN_FRAMEWORK, "Ext extension handle have been released");
|
||||
BExcepUltils::BAssert(ptr->extension_, BError::Codes::EXT_INVAL_ARG, "Extension handle have been released");
|
||||
try {
|
||||
auto callBackupEx = ptr->HandleBackupEx(obj);
|
||||
ptr->StartOnProcessTaskThread(obj, BackupRestoreScenario::INCREMENTAL_BACKUP);
|
||||
auto callBackup = ptr->IncOnBackupCallback(obj);
|
||||
auto callBackupEx = ptr->IncOnBackupExCallback(obj);
|
||||
ErrCode err = ptr->extension_->OnBackup(callBackup, callBackupEx);
|
||||
if (err != ERR_OK) {
|
||||
HILOGE("OnBackup done, err = %{pubilc}d", err);
|
||||
@ -1959,146 +1994,4 @@ int BackupExtExtension::DoIncrementalBackup(const vector<struct ReportFileInfo>
|
||||
smallFiles.size(), allFiles.size());
|
||||
return err;
|
||||
}
|
||||
|
||||
void BackupExtExtension::AppIncrementalDone(ErrCode errCode)
|
||||
{
|
||||
HILOGI("Begin");
|
||||
auto proxy = ServiceProxy::GetInstance();
|
||||
if (proxy == nullptr) {
|
||||
HILOGE("Failed to obtain the ServiceProxy handle");
|
||||
DoClear();
|
||||
return;
|
||||
}
|
||||
auto ret = proxy->AppIncrementalDone(errCode);
|
||||
if (ret != ERR_OK) {
|
||||
HILOGE("Failed to notify the app done. err = %{public}d", ret);
|
||||
}
|
||||
}
|
||||
|
||||
ErrCode BackupExtExtension::GetBackupInfo(std::string &result)
|
||||
{
|
||||
auto obj = wptr<BackupExtExtension>(this);
|
||||
auto ptr = obj.promote();
|
||||
if (ptr == nullptr) {
|
||||
HILOGE("Failed to get ext extension.");
|
||||
return BError(BError::Codes::EXT_INVAL_ARG, "extension getBackupInfo exception").GetCode();
|
||||
}
|
||||
if (ptr->extension_ == nullptr) {
|
||||
HILOGE("Failed to get extension.");
|
||||
return BError(BError::Codes::EXT_INVAL_ARG, "extension getBackupInfo exception").GetCode();
|
||||
}
|
||||
auto callBackup = [ptr](ErrCode errCode, const std::string result) {
|
||||
if (ptr == nullptr) {
|
||||
HILOGE("Failed to get ext extension.");
|
||||
return;
|
||||
}
|
||||
HILOGI("GetBackupInfo callBackup start. result = %{public}s", result.c_str());
|
||||
ptr->backupInfo_ = result;
|
||||
};
|
||||
auto ret = ptr->extension_->GetBackupInfo(callBackup);
|
||||
if (ret != ERR_OK) {
|
||||
HILOGE("Failed to get backupInfo. err = %{public}d", ret);
|
||||
return BError(BError::Codes::EXT_INVAL_ARG, "extension getBackupInfo exception").GetCode();
|
||||
}
|
||||
HILOGD("backupInfo = %s", backupInfo_.c_str());
|
||||
result = backupInfo_;
|
||||
backupInfo_.clear();
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode BackupExtExtension::UpdateFdSendRate(std::string &bundleName, int32_t sendRate)
|
||||
{
|
||||
try {
|
||||
std::lock_guard<std::mutex> lock(updateSendRateLock_);
|
||||
HILOGI("Update SendRate, bundleName:%{public}s, sendRate:%{public}d", bundleName.c_str(), sendRate);
|
||||
VerifyCaller();
|
||||
bundleName_ = bundleName;
|
||||
sendRate_ = sendRate;
|
||||
if (sendRate > 0) {
|
||||
startSendFdRateCon_.notify_one();
|
||||
}
|
||||
return ERR_OK;
|
||||
} catch (...) {
|
||||
HILOGE("Failed to UpdateFdSendRate");
|
||||
return BError(BError::Codes::EXT_BROKEN_IPC).GetCode();
|
||||
}
|
||||
}
|
||||
|
||||
std::function<void(ErrCode, std::string)> BackupExtExtension::AppDoneCallbackEx(wptr<BackupExtExtension> obj)
|
||||
{
|
||||
HILOGI("Begin get callback for appDone");
|
||||
return [obj](ErrCode errCode, std::string errMsg) {
|
||||
HILOGI("begin call callBackupExAppDone");
|
||||
auto extensionPtr = obj.promote();
|
||||
if (extensionPtr == nullptr) {
|
||||
HILOGE("Ext extension handle have been released");
|
||||
return;
|
||||
}
|
||||
extensionPtr->AppDone(errCode);
|
||||
extensionPtr->DoClear();
|
||||
};
|
||||
}
|
||||
|
||||
std::function<void(ErrCode, std::string)> BackupExtExtension::IncRestoreResultCallbackEx(wptr<BackupExtExtension> obj)
|
||||
{
|
||||
HILOGI("Begin get callback for onRestore");
|
||||
return [obj](ErrCode errCode, const std::string restoreRetInfo) {
|
||||
HILOGI("begin call restoreEx");
|
||||
auto extensionPtr = obj.promote();
|
||||
if (extensionPtr == nullptr) {
|
||||
HILOGE("Ext extension handle have been released");
|
||||
return;
|
||||
}
|
||||
if (extensionPtr->extension_ == nullptr) {
|
||||
HILOGE("Extension handle have been released");
|
||||
return;
|
||||
}
|
||||
extensionPtr->extension_->InvokeAppExtMethod(errCode, restoreRetInfo);
|
||||
extensionPtr->FinishOnProcessTask();
|
||||
if (errCode == ERR_OK) {
|
||||
if (restoreRetInfo.size()) {
|
||||
extensionPtr->AppResultReport(restoreRetInfo, BackupRestoreScenario::INCREMENTAL_RESTORE);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (restoreRetInfo.empty()) {
|
||||
extensionPtr->AppIncrementalDone(errCode);
|
||||
extensionPtr->DoClear();
|
||||
} else {
|
||||
std::string errInfo;
|
||||
BJsonUtil::BuildRestoreErrInfo(errInfo, errCode, restoreRetInfo);
|
||||
extensionPtr->AppResultReport(errInfo, BackupRestoreScenario::INCREMENTAL_RESTORE, errCode);
|
||||
extensionPtr->DoClear();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
std::function<void(ErrCode, const std::string)> BackupExtExtension::HandleBackupEx(wptr<BackupExtExtension> obj)
|
||||
{
|
||||
HILOGI("Begin get HandleBackupEx");
|
||||
return [obj](ErrCode errCode, const std::string backupExRetInfo) {
|
||||
auto proxy = ServiceProxy::GetInstance();
|
||||
if (proxy == nullptr) {
|
||||
throw BError(BError::Codes::EXT_BROKEN_BACKUP_SA, std::generic_category().message(errno));
|
||||
}
|
||||
auto extensionPtr = obj.promote();
|
||||
if (extensionPtr == nullptr) {
|
||||
HILOGE("Ext extension handle have been released");
|
||||
return;
|
||||
}
|
||||
if (extensionPtr->extension_ == nullptr) {
|
||||
HILOGE("Extension handle have been released");
|
||||
return;
|
||||
}
|
||||
extensionPtr->extension_->InvokeAppExtMethod(errCode, backupExRetInfo);
|
||||
if (backupExRetInfo.size()) {
|
||||
HILOGI("Start GetAppLocalListAndDoIncrementalBackup");
|
||||
extensionPtr->FinishOnProcessTask();
|
||||
proxy->GetAppLocalListAndDoIncrementalBackup();
|
||||
HILOGI("Will notify backup result report");
|
||||
extensionPtr->AppResultReport(backupExRetInfo, BackupRestoreScenario::INCREMENTAL_BACKUP);
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace OHOS::FileManagement::Backup
|
||||
|
@ -127,8 +127,8 @@ void BackupExtExtension::CheckTmpDirFileInfos(bool isSpecialVersion)
|
||||
struct stat attr;
|
||||
for (auto it : idxFileInfos) {
|
||||
if (it.first.size() >= PATH_MAX || stat(it.first.data(), &attr) == -1) {
|
||||
HILOGE("(Debug) Failed to get stat of %{public}s, errno = %{public}d",
|
||||
GetAnonyPath(it.first).c_str(), errno);
|
||||
HILOGE("(Debug) Failed to get stat of %{public}s, errno = %{public}d", GetAnonyPath(it.first).c_str(),
|
||||
errno);
|
||||
errFiles[it.first].push_back(errno);
|
||||
} else if (it.second != attr.st_size) {
|
||||
HILOGE("(Debug) RecFile:%{public}s size err, recSize: %{public}" PRId64 ", idxSize: %{public}" PRId64 "",
|
||||
@ -136,8 +136,8 @@ void BackupExtExtension::CheckTmpDirFileInfos(bool isSpecialVersion)
|
||||
errFiles[it.first] = std::vector<int>();
|
||||
}
|
||||
}
|
||||
HILOGE("(Debug) Temp file check result: Total file: %{public}zu, err file: %{public}zu",
|
||||
idxFileInfos.size(), errFiles.size());
|
||||
HILOGE("(Debug) Temp file check result: Total file: %{public}zu, err file: %{public}zu", idxFileInfos.size(),
|
||||
errFiles.size());
|
||||
if (!errFiles.empty()) {
|
||||
HILOGE("(Debug) The received file and idx is not same");
|
||||
} else {
|
||||
@ -165,297 +165,104 @@ tuple<bool, vector<string>> BackupExtExtension::CheckRestoreFileInfos()
|
||||
HILOGE("(Debug) errfileInfos file = %{public}s -> %{public}d", GetAnonyPath(it.first).c_str(), codeIt);
|
||||
}
|
||||
}
|
||||
HILOGE("(Debug) End file check result Total file: %{public}zu, err file: %{public}zu",
|
||||
endFileInfos_.size(), errFileInfos_.size());
|
||||
HILOGE("(Debug) End file check result Total file: %{public}zu, err file: %{public}zu", endFileInfos_.size(),
|
||||
errFileInfos_.size());
|
||||
if (errFiles.size()) {
|
||||
return { false, errFiles };
|
||||
}
|
||||
return { true, errFiles };
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
std::function<void(ErrCode, const std::string)> BackupExtExtension::HandleFullBackupCallbackEx(
|
||||
wptr<BackupExtExtension> obj)
|
||||
void BackupExtExtension::AppIncrementalDone(ErrCode errCode)
|
||||
{
|
||||
HILOGI("Begin get HandleFullBackupCallbackEx");
|
||||
return [obj](ErrCode errCode, const std::string backupExRetInfo) {
|
||||
HILOGI("begin call backup");
|
||||
auto extensionPtr = obj.promote();
|
||||
if (extensionPtr == nullptr) {
|
||||
HILOGE("Ext extension handle have been released");
|
||||
HILOGI("Begin");
|
||||
auto proxy = ServiceProxy::GetInstance();
|
||||
if (proxy == nullptr) {
|
||||
HILOGE("Failed to obtain the ServiceProxy handle");
|
||||
DoClear();
|
||||
return;
|
||||
}
|
||||
if (extensionPtr->extension_ == nullptr) {
|
||||
HILOGE("Extension handle have been released");
|
||||
auto ret = proxy->AppIncrementalDone(errCode);
|
||||
if (ret != ERR_OK) {
|
||||
HILOGE("Failed to notify the app done. err = %{public}d", ret);
|
||||
}
|
||||
}
|
||||
|
||||
ErrCode BackupExtExtension::GetBackupInfo(std::string &result)
|
||||
{
|
||||
auto obj = wptr<BackupExtExtension>(this);
|
||||
auto ptr = obj.promote();
|
||||
if (ptr == nullptr) {
|
||||
HILOGE("Failed to get ext extension.");
|
||||
return BError(BError::Codes::EXT_INVAL_ARG, "extension getBackupInfo exception").GetCode();
|
||||
}
|
||||
if (ptr->extension_ == nullptr) {
|
||||
HILOGE("Failed to get extension.");
|
||||
return BError(BError::Codes::EXT_INVAL_ARG, "extension getBackupInfo exception").GetCode();
|
||||
}
|
||||
auto callBackup = [ptr](ErrCode errCode, const std::string result) {
|
||||
if (ptr == nullptr) {
|
||||
HILOGE("Failed to get ext extension.");
|
||||
return;
|
||||
}
|
||||
extensionPtr->extension_->InvokeAppExtMethod(errCode, backupExRetInfo);
|
||||
if (backupExRetInfo.size()) {
|
||||
HILOGI("Will notify backup result report");
|
||||
extensionPtr->FinishOnProcessTask();
|
||||
extensionPtr->AsyncTaskBackup(extensionPtr->extension_->GetUsrConfig());
|
||||
extensionPtr->AppResultReport(backupExRetInfo, BackupRestoreScenario::FULL_BACKUP);
|
||||
}
|
||||
HILOGI("GetBackupInfo callBackup start. result = %{public}s", result.c_str());
|
||||
ptr->backupInfo_ = result;
|
||||
};
|
||||
auto ret = ptr->extension_->GetBackupInfo(callBackup);
|
||||
if (ret != ERR_OK) {
|
||||
HILOGE("Failed to get backupInfo. err = %{public}d", ret);
|
||||
return BError(BError::Codes::EXT_INVAL_ARG, "extension getBackupInfo exception").GetCode();
|
||||
}
|
||||
HILOGD("backupInfo = %s", backupInfo_.c_str());
|
||||
result = backupInfo_;
|
||||
backupInfo_.clear();
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
|
||||
std::function<void(ErrCode, const std::string)> BackupExtExtension::HandleFullBackupCallback(
|
||||
wptr<BackupExtExtension> obj)
|
||||
ErrCode BackupExtExtension::UpdateFdSendRate(std::string &bundleName, int32_t sendRate)
|
||||
{
|
||||
HILOGI("Begin get HandleFullBackupCallbackEx");
|
||||
try {
|
||||
std::lock_guard<std::mutex> lock(updateSendRateLock_);
|
||||
HILOGI("Update SendRate, bundleName:%{public}s, sendRate:%{public}d", bundleName.c_str(), sendRate);
|
||||
VerifyCaller();
|
||||
bundleName_ = bundleName;
|
||||
sendRate_ = sendRate;
|
||||
if (sendRate > 0) {
|
||||
startSendFdRateCon_.notify_one();
|
||||
}
|
||||
return ERR_OK;
|
||||
} catch (...) {
|
||||
HILOGE("Failed to UpdateFdSendRate");
|
||||
return BError(BError::Codes::EXT_BROKEN_IPC).GetCode();
|
||||
}
|
||||
}
|
||||
|
||||
std::function<void(ErrCode, std::string)> BackupExtExtension::OnRestoreCallback(wptr<BackupExtExtension> obj)
|
||||
{
|
||||
HILOGI("Begin get full restore onRestore callback");
|
||||
return [obj](ErrCode errCode, std::string errMsg) {
|
||||
HILOGI("begin call backup");
|
||||
auto extensionPtr = obj.promote();
|
||||
if (extensionPtr == nullptr) {
|
||||
HILOGE("Ext extension handle have been released");
|
||||
return;
|
||||
}
|
||||
if (extensionPtr->extension_ == nullptr) {
|
||||
HILOGE("Extension handle have been released");
|
||||
return;
|
||||
}
|
||||
HILOGI("Current bundle will execute app done");
|
||||
extensionPtr->FinishOnProcessTask();
|
||||
extensionPtr->AsyncTaskBackup(extensionPtr->extension_->GetUsrConfig());
|
||||
if (errMsg.empty()) {
|
||||
extensionPtr->AppDone(errCode);
|
||||
} else {
|
||||
std::string errInfo;
|
||||
BJsonUtil::BuildRestoreErrInfo(errInfo, errCode, errMsg);
|
||||
extensionPtr->AppResultReport(errInfo, BackupRestoreScenario::FULL_RESTORE, errCode);
|
||||
}
|
||||
extensionPtr->DoClear();
|
||||
};
|
||||
}
|
||||
|
||||
std::function<void(ErrCode, std::string)> BackupExtExtension::FullRestoreCallbackEx(wptr<BackupExtExtension> obj)
|
||||
std::function<void(ErrCode, std::string)> BackupExtExtension::OnRestoreExCallback(wptr<BackupExtExtension> obj)
|
||||
{
|
||||
HILOGI("Begin get callbackEx");
|
||||
HILOGI("Begin get full restore onRestoreEx callback");
|
||||
return [obj](ErrCode errCode, const std::string restoreRetInfo) {
|
||||
auto extensionPtr = obj.promote();
|
||||
if (extensionPtr == nullptr) {
|
||||
@ -487,38 +294,65 @@ std::function<void(ErrCode, std::string)> BackupExtExtension::FullRestoreCallbac
|
||||
};
|
||||
}
|
||||
|
||||
std::function<void(ErrCode, std::string)> BackupExtExtension::FullRestoreCallback(wptr<BackupExtExtension> obj)
|
||||
std::function<void(ErrCode, std::string)> BackupExtExtension::AppDoneCallbackEx(wptr<BackupExtExtension> obj)
|
||||
{
|
||||
HILOGI("Begin get callback for appDone");
|
||||
return [obj](ErrCode errCode, std::string errMsg) {
|
||||
HILOGI("begin call callBackupExAppDone");
|
||||
auto extensionPtr = obj.promote();
|
||||
if (extensionPtr == nullptr) {
|
||||
HILOGE("Ext extension handle have been released");
|
||||
return;
|
||||
}
|
||||
HILOGI("Current bundle will execute app done");
|
||||
extensionPtr->FinishOnProcessTask();
|
||||
if (errMsg.empty()) {
|
||||
extensionPtr->AppDone(errCode);
|
||||
} else {
|
||||
std::string errInfo;
|
||||
BJsonUtil::BuildRestoreErrInfo(errInfo, errCode, errMsg);
|
||||
extensionPtr->AppResultReport(errInfo, BackupRestoreScenario::FULL_RESTORE, errCode);
|
||||
}
|
||||
extensionPtr->DoClear();
|
||||
};
|
||||
}
|
||||
|
||||
std::function<void(ErrCode, std::string)> BackupExtExtension::IncRestoreResultCallback(wptr<BackupExtExtension> obj)
|
||||
std::function<void(ErrCode, std::string)> BackupExtExtension::IncreOnRestoreExCallback(wptr<BackupExtExtension> obj)
|
||||
{
|
||||
HILOGI("Begin get callback for increment onRestoreEx");
|
||||
return [obj](ErrCode errCode, const std::string restoreRetInfo) {
|
||||
HILOGI("begin call increment restoreEx");
|
||||
auto extensionPtr = obj.promote();
|
||||
if (extensionPtr == nullptr) {
|
||||
HILOGE("Ext extension handle have been released");
|
||||
return;
|
||||
}
|
||||
if (extensionPtr->extension_ == nullptr) {
|
||||
HILOGE("Extension handle have been released");
|
||||
return;
|
||||
}
|
||||
extensionPtr->FinishOnProcessTask();
|
||||
extensionPtr->extension_->InvokeAppExtMethod(errCode, restoreRetInfo);
|
||||
if (errCode == ERR_OK) {
|
||||
if (restoreRetInfo.size()) {
|
||||
extensionPtr->AppResultReport(restoreRetInfo, BackupRestoreScenario::INCREMENTAL_RESTORE);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (restoreRetInfo.empty()) {
|
||||
extensionPtr->AppIncrementalDone(errCode);
|
||||
extensionPtr->DoClear();
|
||||
} else {
|
||||
std::string errInfo;
|
||||
BJsonUtil::BuildRestoreErrInfo(errInfo, errCode, restoreRetInfo);
|
||||
extensionPtr->AppResultReport(errInfo, BackupRestoreScenario::INCREMENTAL_RESTORE, errCode);
|
||||
extensionPtr->DoClear();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
std::function<void(ErrCode, std::string)> BackupExtExtension::IncreOnRestoreCallback(wptr<BackupExtExtension> obj)
|
||||
{
|
||||
HILOGI("Begin get callback for onRestore");
|
||||
return [obj](ErrCode errCode, std::string errMsg) {
|
||||
auto extensionPtr = obj.promote();
|
||||
if (extensionPtr == nullptr) {
|
||||
HILOGE("Ext extension handle have been released");
|
||||
return;
|
||||
}
|
||||
extensionPtr->FinishOnProcessTask();
|
||||
HILOGI("Current bundle will execute app done");
|
||||
extensionPtr->FinishOnProcessTask();
|
||||
if (errMsg.empty()) {
|
||||
extensionPtr->AppIncrementalDone(errCode);
|
||||
} else {
|
||||
@ -530,6 +364,97 @@ std::function<void(ErrCode, std::string)> BackupExtExtension::IncRestoreResultCa
|
||||
};
|
||||
}
|
||||
|
||||
std::function<void(ErrCode, const std::string)> BackupExtExtension::OnBackupCallback(wptr<BackupExtExtension> obj)
|
||||
{
|
||||
HILOGI("Begin get HandleFullBackupCallbackEx");
|
||||
return [obj](ErrCode errCode, std::string errMsg) {
|
||||
HILOGI("begin call backup");
|
||||
auto extensionPtr = obj.promote();
|
||||
if (extensionPtr == nullptr) {
|
||||
HILOGE("Ext extension handle have been released");
|
||||
return;
|
||||
}
|
||||
if (extensionPtr->extension_ == nullptr) {
|
||||
HILOGE("Extension handle have been released");
|
||||
return;
|
||||
}
|
||||
extensionPtr->FinishOnProcessTask();
|
||||
extensionPtr->AsyncTaskBackup(extensionPtr->extension_->GetUsrConfig());
|
||||
};
|
||||
}
|
||||
|
||||
std::function<void(ErrCode, const std::string)> BackupExtExtension::OnBackupExCallback(wptr<BackupExtExtension> obj)
|
||||
{
|
||||
HILOGI("Begin get HandleFullBackupCallbackEx");
|
||||
return [obj](ErrCode errCode, const std::string backupExRetInfo) {
|
||||
HILOGI("begin call backup");
|
||||
auto extensionPtr = obj.promote();
|
||||
if (extensionPtr == nullptr) {
|
||||
HILOGE("Ext extension handle have been released");
|
||||
return;
|
||||
}
|
||||
if (extensionPtr->extension_ == nullptr) {
|
||||
HILOGE("Extension handle have been released");
|
||||
return;
|
||||
}
|
||||
extensionPtr->extension_->InvokeAppExtMethod(errCode, backupExRetInfo);
|
||||
if (backupExRetInfo.size()) {
|
||||
HILOGI("Will notify backup result report");
|
||||
extensionPtr->FinishOnProcessTask();
|
||||
extensionPtr->AsyncTaskBackup(extensionPtr->extension_->GetUsrConfig());
|
||||
extensionPtr->AppResultReport(backupExRetInfo, BackupRestoreScenario::FULL_BACKUP);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
std::function<void(ErrCode, const std::string)> BackupExtExtension::IncOnBackupCallback(wptr<BackupExtExtension> obj)
|
||||
{
|
||||
HILOGI("Begin get IncOnBackupCallback");
|
||||
return [obj](ErrCode errCode, std::string errMsg) {
|
||||
HILOGI("App onbackup end");
|
||||
auto proxy = ServiceProxy::GetInstance();
|
||||
if (proxy == nullptr) {
|
||||
throw BError(BError::Codes::EXT_BROKEN_BACKUP_SA, std::generic_category().message(errno));
|
||||
}
|
||||
auto extPtr = obj.promote();
|
||||
if (extPtr == nullptr) {
|
||||
HILOGE("Current extension execute call backup error, extPtr is empty");
|
||||
return;
|
||||
}
|
||||
HILOGI("Start GetAppLocalListAndDoIncrementalBackup");
|
||||
extPtr->FinishOnProcessTask();
|
||||
proxy->GetAppLocalListAndDoIncrementalBackup();
|
||||
};
|
||||
}
|
||||
|
||||
std::function<void(ErrCode, const std::string)> BackupExtExtension::IncOnBackupExCallback(wptr<BackupExtExtension> obj)
|
||||
{
|
||||
HILOGI("Begin get HandleIncBackupEx callback");
|
||||
return [obj](ErrCode errCode, const std::string backupExRetInfo) {
|
||||
auto proxy = ServiceProxy::GetInstance();
|
||||
if (proxy == nullptr) {
|
||||
throw BError(BError::Codes::EXT_BROKEN_BACKUP_SA, std::generic_category().message(errno));
|
||||
}
|
||||
auto extensionPtr = obj.promote();
|
||||
if (extensionPtr == nullptr) {
|
||||
HILOGE("Ext extension handle have been released");
|
||||
return;
|
||||
}
|
||||
if (extensionPtr->extension_ == nullptr) {
|
||||
HILOGE("Extension handle have been released");
|
||||
return;
|
||||
}
|
||||
extensionPtr->extension_->InvokeAppExtMethod(errCode, backupExRetInfo);
|
||||
if (backupExRetInfo.size()) {
|
||||
HILOGI("Start GetAppLocalListAndDoIncrementalBackup");
|
||||
extensionPtr->FinishOnProcessTask();
|
||||
proxy->GetAppLocalListAndDoIncrementalBackup();
|
||||
HILOGI("Will notify backup result report");
|
||||
extensionPtr->AppResultReport(backupExRetInfo, BackupRestoreScenario::INCREMENTAL_BACKUP);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void BackupExtExtension::ReportAppProcessInfo(const std::string processInfo, BackupRestoreScenario scenario)
|
||||
{
|
||||
auto proxy = ServiceProxy::GetInstance();
|
||||
@ -544,25 +469,26 @@ void BackupExtExtension::ReportAppProcessInfo(const std::string processInfo, Bac
|
||||
}
|
||||
}
|
||||
|
||||
// 2024-08-18
|
||||
void BackupExtExtension::StartOnProcessTaskThread(BackupRestoreScenario scenario)
|
||||
void BackupExtExtension::StartOnProcessTaskThread(wptr<BackupExtExtension> obj, BackupRestoreScenario scenario)
|
||||
{
|
||||
HILOGI("Begin Create onProcess Task Thread");
|
||||
callJsOnProcessThread_ = std::thread[obj { wptr<BackupExtExtension>(this) }, scenario]() {
|
||||
onProcessTimeoutTimer_.Setup();
|
||||
SyncCallJsOnProcessTask(obj, scenario);
|
||||
StartOnProcessTimeOutTimer(obj);
|
||||
callJsOnProcessThread_ = std::thread([obj, scenario]() {
|
||||
auto extPtr = obj.promote();
|
||||
if (extPtr == nullptr) {
|
||||
HILOGE("Create onProcess Task thread failed, extPtr is empty");
|
||||
return;
|
||||
}
|
||||
extPtr->ExecCallOnProcessTask(obj, scenario);
|
||||
}
|
||||
});
|
||||
HILOGI("End Create onProcess Task End");
|
||||
}
|
||||
|
||||
void BackupExtExtension::ExecCallOnProcessTask(wptr<BackupExtExtension> obj, BackupRestoreScenario scenario)
|
||||
{
|
||||
HILOGI("Begin");
|
||||
onProcessTimeoutTimer_.Setup();
|
||||
AsyncCallJsOnProcessTask(obj, scenario);
|
||||
StartOnProcessTimeOutTimer(obj);
|
||||
while (!stopCallJsOnProcess_.load()) {
|
||||
@ -570,14 +496,15 @@ void BackupExtExtension::ExecCallOnProcessTask(wptr<BackupExtExtension> obj, Bac
|
||||
execOnProcessCon_.wait_for(lock, std::chrono::seconds(BConstants::CALL_APP_ON_PROCESS_TIME_INTERVAL),
|
||||
[this] { return this->stopCallJsOnProcess_.load(); });
|
||||
if (stopCallJsOnProcess_.load()) {
|
||||
HILOGE("Current extension js onProcess finished");
|
||||
HILOGE("Current extension execute js onProcess method finished");
|
||||
return;
|
||||
}
|
||||
if (onProcessTimeout_.load()) {
|
||||
HILOGE("Current extension js onProcess status is timeout");
|
||||
HILOGE("Current extension execute js method onProcess timeout");
|
||||
StartOnProcessTimeOutTimer(obj);
|
||||
continue;
|
||||
}
|
||||
HILOGI("Continue call js method onProcess");
|
||||
AsyncCallJsOnProcessTask(obj, scenario);
|
||||
StartOnProcessTimeOutTimer(obj);
|
||||
}
|
||||
@ -588,8 +515,21 @@ void BackupExtExtension::AsyncCallJsOnProcessTask(wptr<BackupExtExtension> obj,
|
||||
{
|
||||
HILOGI("Begin");
|
||||
auto task = [obj, scenario]() {
|
||||
auto extPtr = obj.promote();
|
||||
if (extPtr == nullptr) {
|
||||
HILOGE("Async Call js onProcess error, extPtr is empty");
|
||||
return;
|
||||
}
|
||||
extPtr->SyncCallJsOnProcessTask(obj, scenario);
|
||||
};
|
||||
threadPool_.AddTask([task]() { task(); });
|
||||
HILOGI("End");
|
||||
}
|
||||
|
||||
void BackupExtExtension::SyncCallJsOnProcessTask(wptr<BackupExtExtension> obj, BackupRestoreScenario scenario)
|
||||
{
|
||||
HILOGI("Begin");
|
||||
auto callBack = [obj, scenario](ErrCode errCode, const std::string processInfo) {
|
||||
// 进入此方法说明onProcess正常1s内响应,则关闭超时的定时器,超时计数减一
|
||||
auto extPtr = obj.promote();
|
||||
if (extPtr == nullptr) {
|
||||
HILOGE("Async call js onPreocess callback failed, exPtr is empty");
|
||||
@ -597,16 +537,20 @@ void BackupExtExtension::AsyncCallJsOnProcessTask(wptr<BackupExtExtension> obj,
|
||||
}
|
||||
extPtr->CloseOnProcessTimeOutTimer();
|
||||
extPtr->onProcessTimeout_.store(false);
|
||||
if (extPtr->onProcessTimeoutCnt_.load() != 0) {
|
||||
if (extPtr->onProcessTimeoutCnt_.load() > 0) {
|
||||
HILOGI("onProcess resturn right result, decrease onProcessTimeoutCnt, cnt is:%{public}d",
|
||||
extPtr->onProcessTimeoutCnt_.load());
|
||||
extPtr->onProcessTimeoutCnt_--;
|
||||
}
|
||||
if (processInfo.size == 0) {
|
||||
if (processInfo.size() == 0) {
|
||||
HILOGE("Current extension has no js method named onProcess.");
|
||||
extPtr->stopCallJsOnProcess_.store(true);
|
||||
extPtr->execOnProcessCon_.notify_one();
|
||||
return;
|
||||
}
|
||||
std::string processInfoJsonStr;
|
||||
BJsonUtil::BuildOnProcessRetInfo(processInfoJsonStr, processInfo);
|
||||
HILOGI("Will notify backup sa process result");
|
||||
extPtr->ReportAppProcessInfo(processInfoJsonStr, scenario);
|
||||
};
|
||||
auto extenionPtr = obj.promote();
|
||||
@ -619,10 +563,6 @@ void BackupExtExtension::AsyncCallJsOnProcessTask(wptr<BackupExtExtension> obj,
|
||||
HILOGE("Call OnProcess Failed, ret:%{public}d", ret);
|
||||
return;
|
||||
}
|
||||
};
|
||||
threadPool_.AddTask([task]() {
|
||||
task();
|
||||
});
|
||||
HILOGI("End");
|
||||
}
|
||||
|
||||
@ -630,6 +570,7 @@ void BackupExtExtension::FinishOnProcessTask()
|
||||
{
|
||||
HILOGI("Begin");
|
||||
stopCallJsOnProcess_.store(true);
|
||||
onProcessTimeoutCnt_ = 0;
|
||||
execOnProcessCon_.notify_one();
|
||||
if (callJsOnProcessThread_.joinable()) {
|
||||
callJsOnProcessThread_.join();
|
||||
@ -660,8 +601,7 @@ void BackupExtExtension::StartOnProcessTimeOutTimer(wptr<BackupExtExtension> obj
|
||||
}
|
||||
extPtr->onProcessTimeoutCnt_++;
|
||||
extPtr->onProcessTimeout_.store(true);
|
||||
HILOGE("Current extension onProcess status is timeout,
|
||||
onProcessTimeoutCnt:%{public}d", extPtr->onProcessTimeoutCnt_);
|
||||
HILOGE("Extension onProcess timeout, onProcessTimeoutCnt:%{public}d", extPtr->onProcessTimeoutCnt_.load());
|
||||
};
|
||||
uint32_t timerId = onProcessTimeoutTimer_.Register(timeoutCallback, BConstants::APP_ON_PROCESS_MAX_TIMEOUT, true);
|
||||
onProcessTimeoutTimerId_ = timerId;
|
||||
@ -674,12 +614,4 @@ void BackupExtExtension::CloseOnProcessTimeOutTimer()
|
||||
onProcessTimeoutTimer_.Unregister(onProcessTimeoutTimerId_);
|
||||
HILOGI("End");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace OHOS::FileManagement::Backup
|
||||
|
@ -612,4 +612,48 @@ ErrCode ServiceProxy::ReportAppProcessInfo(const std::string processInfo, const
|
||||
HILOGI("ServiceProxy NotifyBundleProcessInfo end. ret = %{public}d", ret);
|
||||
return BError(BError::Codes::OK, "success");
|
||||
}
|
||||
|
||||
ErrCode ServiceProxy::StartExtTimer(bool &isExtStart)
|
||||
{
|
||||
HILOGI("ServiceProxy StartExtTimer 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();
|
||||
}
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME);
|
||||
int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(IServiceInterfaceCode::SERVICE_CMD_START_EXT_TIMER),
|
||||
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(isExtStart);
|
||||
HILOGI("ServiceProxy StartExtTimer end. isExtStart = %d", isExtStart);
|
||||
return BError(BError::Codes::OK, "success");
|
||||
}
|
||||
|
||||
ErrCode ServiceProxy::StartFwkTimer(bool &isFwkStart)
|
||||
{
|
||||
HILOGI("ServiceProxy StartFwkTimer 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();
|
||||
}
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME);
|
||||
int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(IServiceInterfaceCode::SERVICE_CMD_START_FWK_TIMER),
|
||||
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(isFwkStart);
|
||||
HILOGI("ServiceProxy StartFwkTimer end. isFwkStart = %d", isFwkStart);
|
||||
return BError(BError::Codes::OK, "success");
|
||||
}
|
||||
} // namespace OHOS::FileManagement::Backup
|
||||
|
@ -37,7 +37,7 @@ public:
|
||||
std::function<void(ErrCode)> onAllBundlesFinished; // 当整个备份流程结束或意外中止时执行的回调函数
|
||||
std::function<void(const std::string, const std::string)> onResultReport; // 某个应用备份流程中自定义错误信息的上报的回调函数
|
||||
std::function<void()> onBackupServiceDied; // 当备份服务意外死亡时执行的回调函数
|
||||
std::function<void(const std::string, const std::string)> onProcess; // 某个应用上报执行进度的的回调函数
|
||||
std::function<void(const std::string, const std::string)> onProcess; // 上报备份恢复过程中的进度和异常
|
||||
};
|
||||
|
||||
public:
|
||||
|
@ -37,7 +37,7 @@ public:
|
||||
std::function<void(ErrCode)> onAllBundlesFinished; // 当整个恢复流程结束或意外中止时执行的回调函数
|
||||
std::function<void(const std::string, const std::string)> onResultReport; // 某个应用恢复流程中自定义错误信息的上报的回调函数
|
||||
std::function<void()> onBackupServiceDied; // 当备份服务意外死亡时执行的回调函数
|
||||
std::function<void(const std::string, const std::string)> onProcess; // 某个应用上报执行进度的的回调函数
|
||||
std::function<void(const std::string, const std::string)> onProcess; // 上报备份恢复过程中的进度和异常
|
||||
};
|
||||
|
||||
public:
|
||||
|
@ -35,7 +35,7 @@ public:
|
||||
std::function<void(ErrCode)> onAllBundlesFinished; // 当整个备份流程结束或意外中止时执行的回调函数
|
||||
std::function<void(const std::string, const std::string)> onResultReport; // 某个应用备份流程中自定义错误信息的上报的回调函数
|
||||
std::function<void()> onBackupServiceDied; // 当备份服务意外死亡时执行的回调函数
|
||||
std::function<void(const std::string, const std::string)> onProcess; // 某个应用上报执行进度的的回调函数
|
||||
std::function<void(const std::string, const std::string)> onProcess; // 上报备份恢复过程中的进度和异常
|
||||
};
|
||||
|
||||
public:
|
||||
|
@ -35,7 +35,7 @@ public:
|
||||
std::function<void(ErrCode)> onAllBundlesFinished; // 当整个恢复流程结束或意外中止时执行的回调函数
|
||||
std::function<void(const std::string, const std::string)> onResultReport; // 某个应用恢复流程中自定义错误信息的上报的回调函数
|
||||
std::function<void()> onBackupServiceDied; // 当备份服务意外死亡时执行的回调函数
|
||||
std::function<void(const std::string, const std::string)> onProcess; // 某个应用上报执行进度的的回调函数
|
||||
std::function<void(const std::string, const std::string)> onProcess; // 上报备份恢复过程中的进度和异常
|
||||
};
|
||||
|
||||
public:
|
||||
|
@ -39,6 +39,7 @@ public:
|
||||
std::function<void(ErrCode)> onAllBundlesFinished; // 当整个恢复流程结束或意外中止时执行的回调函数
|
||||
std::function<void(const std::string, const std::string)> onResultReport; // 某个应用恢复流程中自定义错误信息的上报的回调函数
|
||||
std::function<void()> onBackupServiceDied; // 当备份服务意外死亡时执行的回调函数
|
||||
std::function<void(const std::string, const std::string)> onProcess; // 上报备份恢复过程中的进度和异常
|
||||
};
|
||||
|
||||
struct AppendBundleInfo {
|
||||
|
@ -86,6 +86,8 @@ public:
|
||||
virtual ErrCode UpdateTimer(BundleName &bundleName, uint32_t timeOut, bool &result) = 0;
|
||||
virtual ErrCode UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) = 0;
|
||||
virtual ErrCode ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) = 0;
|
||||
virtual ErrCode StartExtTimer(bool &isExtStart) = 0;
|
||||
virtual ErrCode StartFwkTimer(bool &isFwkStart) = 0;
|
||||
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Filemanagement.Backup.IService")
|
||||
};
|
||||
|
@ -45,6 +45,8 @@ enum class IServiceInterfaceCode {
|
||||
SERVICE_CMD_GET_INCREMENTAL_FILE_NAME,
|
||||
SERVICE_CMD_GET_BACKUP_INFO,
|
||||
SERVICE_CMD_UPDATE_TIMER,
|
||||
SERVICE_CMD_START_EXT_TIMER,
|
||||
SERVICE_CMD_START_FWK_TIMER,
|
||||
SERVICE_CMD_UPDATE_SENDRATE,
|
||||
SERVICE_CMD_GET_APP_LOCAL_LIST_AND_DO_INCREMENTAL_BACKUP,
|
||||
SERVICE_CMD_REPORT_APP_PROCESS_INFO,
|
||||
|
@ -69,6 +69,8 @@ public:
|
||||
ErrCode UpdateTimer(BundleName &bundleName, uint32_t timeOut, bool &result) override;
|
||||
ErrCode UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) override;
|
||||
ErrCode ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) override;
|
||||
ErrCode StartExtTimer(bool &isExtStart) override;
|
||||
ErrCode StartFwkTimer(bool &isFwkStart) override;
|
||||
|
||||
public:
|
||||
explicit ServiceProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IService>(impl) {}
|
||||
|
@ -31,8 +31,6 @@ namespace OHOS::FileManagement::Backup {
|
||||
using namespace std;
|
||||
using namespace LibN;
|
||||
|
||||
const int32_t H_TO_MS = 3600 * 1000;
|
||||
|
||||
static napi_value AsyncCallback(napi_env env, const NFuncArg& funcArg)
|
||||
{
|
||||
HILOGD("called LocalCapabilities::AsyncCallback begin");
|
||||
@ -311,7 +309,7 @@ napi_value PropNOperation::DoUpdateTimer(napi_env env, napi_callback_info info)
|
||||
}
|
||||
NVal jsBundleInt(env, funcArg[NARG_POS::SECOND]);
|
||||
auto [succInt, time] = jsBundleInt.ToInt32();
|
||||
if (!succInt || time <= 0 || time > H_TO_MS) {
|
||||
if (!succInt || time <= 0 || time > static_cast<int32_t>(BConstants::H2MS)) {
|
||||
HILOGE("Second argument is not number.");
|
||||
NError(E_PARAMS).ThrowErr(env);
|
||||
return nullptr;
|
||||
|
@ -386,6 +386,7 @@ static bool VerifyNapiObject(napi_env env, NFuncArg &funcArg)
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool VerifyNarg(napi_env env, NVal &callbacks)
|
||||
{
|
||||
if (!callbacks.TypeIs(napi_object)) {
|
||||
|
@ -78,6 +78,8 @@ public:
|
||||
ErrCode UpdateTimer(BundleName &bundleName, uint32_t timeOut, bool &result) override;
|
||||
ErrCode UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) override;
|
||||
ErrCode ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) override;
|
||||
ErrCode StartExtTimer(bool &isExtStart) override;
|
||||
ErrCode StartFwkTimer(bool &isFwkStart) override;
|
||||
|
||||
ErrCode SAResultReport(const std::string bundleName, const std::string resultInfo,
|
||||
const ErrCode errCode, const BackupRestoreScenario sennario);
|
||||
@ -228,6 +230,14 @@ public:
|
||||
*/
|
||||
std::function<void(const std::string &&)> GetBackupInfoConnectDied(wptr<Service> obj, std::string &bundleName);
|
||||
|
||||
/**
|
||||
* @brief timeout callback
|
||||
*
|
||||
* @param ptr 当前对象
|
||||
* @param bundleName 应用名称
|
||||
*/
|
||||
std::function<void()> TimeOutCallback(wptr<Service> ptr, std::string bundleName);
|
||||
|
||||
public:
|
||||
explicit Service(int32_t saID, bool runOnCreate = false) : SystemAbility(saID, runOnCreate)
|
||||
{
|
||||
|
@ -63,6 +63,8 @@ private:
|
||||
int32_t CmdUpdateTimer(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t CmdUpdateSendRate(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t CmdReportAppProcessInfo(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t CmdStartExtTimer(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t CmdStartFwkTimer(MessageParcel &data, MessageParcel &reply);
|
||||
void ServiceStubSupplement();
|
||||
void ServiceStubSuppAppendBundles();
|
||||
|
||||
|
@ -56,9 +56,12 @@ struct BackupExtInfo {
|
||||
/* Clone App: old device app versionCode */
|
||||
std::string versionName;
|
||||
/* Ext Ability APP process time */
|
||||
uint32_t extTimerId;
|
||||
uint32_t timerId;
|
||||
/* Timer Status: true is start & false is stop */
|
||||
bool timerStatus {false};
|
||||
bool extTimerStatus {false};
|
||||
bool fwkTimerStatus {false};
|
||||
uint32_t timeCount;
|
||||
uint32_t startTime;
|
||||
int64_t dataSize;
|
||||
int64_t lastIncrementalTime;
|
||||
int32_t manifestFd;
|
||||
@ -384,12 +387,39 @@ public:
|
||||
void SetBundleDataSize(const std::string &bundleName, int64_t dataSize);
|
||||
|
||||
/**
|
||||
* @brief 启动应用扩展能力定时器
|
||||
* @brief 启动框架定时器
|
||||
*
|
||||
* @param bundleName 应用名称
|
||||
* @return
|
||||
* @param callback 超时回调
|
||||
* @return bool
|
||||
*/
|
||||
void BundleExtTimerStart(const std::string &bundleName, const Utils::Timer::TimerCallback &callback);
|
||||
bool StartFwkTimer(const std::string &bundleName, const Utils::Timer::TimerCallback &callback);
|
||||
|
||||
/**
|
||||
* @brief 停止框架定时器
|
||||
*
|
||||
* @param bundleName 应用名称
|
||||
* @param callback 超时回调
|
||||
* @return bool
|
||||
*/
|
||||
bool StopFwkTimer(const std::string &bundleName);
|
||||
|
||||
/**
|
||||
* @brief 启动extension定时器
|
||||
*
|
||||
* @param bundleName 应用名称
|
||||
* @param callback 超时回调
|
||||
* @return bool
|
||||
*/
|
||||
bool StartExtTimer(const std::string &bundleName, const Utils::Timer::TimerCallback &callback);
|
||||
|
||||
/**
|
||||
* @brief 停止extension定时器
|
||||
*
|
||||
* @param bundleName 应用名称
|
||||
* @return bool
|
||||
*/
|
||||
bool StopExtTimer(const std::string &bundleName);
|
||||
|
||||
/**
|
||||
* @brief 重新设置定时器
|
||||
@ -402,14 +432,6 @@ public:
|
||||
bool UpdateTimer(const std::string &bundleName, uint32_t timeOut,
|
||||
const Utils::Timer::TimerCallback &callback);
|
||||
|
||||
/**
|
||||
* @brief 取消/暂停应用扩展能力定时器
|
||||
*
|
||||
* @param bundleName 应用名称
|
||||
* @return
|
||||
*/
|
||||
void BundleExtTimerStop(const std::string &bundleName);
|
||||
|
||||
/**
|
||||
* @brief sessionCnt加计数
|
||||
*
|
||||
@ -532,11 +554,11 @@ public:
|
||||
*/
|
||||
explicit SvcSessionManager(wptr<Service> reversePtr) : reversePtr_(reversePtr)
|
||||
{
|
||||
extBundleTimer.Setup();
|
||||
timer_.Setup();
|
||||
}
|
||||
~SvcSessionManager() override
|
||||
{
|
||||
extBundleTimer.Shutdown();
|
||||
timer_.Shutdown();
|
||||
}
|
||||
|
||||
private:
|
||||
@ -545,7 +567,7 @@ private:
|
||||
sptr<SvcDeathRecipient> deathRecipient_;
|
||||
Impl impl_;
|
||||
uint32_t extConnectNum_ {0};
|
||||
Utils::Timer extBundleTimer {"backupBundleExtTimer"};
|
||||
Utils::Timer timer_ {"backupTimer"};
|
||||
std::atomic<int> sessionCnt_ {0};
|
||||
bool unloadSAFlag_ {false};
|
||||
int32_t memoryParaCurSize_ {BConstants::DEFAULT_VFS_CACHE_PRESSURE};
|
||||
|
@ -745,7 +745,8 @@ ErrCode Service::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCo
|
||||
// 通知extension清空缓存
|
||||
proxy->HandleClear();
|
||||
// 清除Timer
|
||||
session_->BundleExtTimerStop(callerName);
|
||||
session_->StopFwkTimer(callerName);
|
||||
session_->StopExtTimer(callerName);
|
||||
// 通知TOOL 备份完成
|
||||
session_->GetServiceReverseProxy()->BackupOnBundleFinished(BError(BError::Codes::OK), callerName);
|
||||
// 断开extension
|
||||
@ -786,7 +787,8 @@ ErrCode Service::AppDone(ErrCode errCode)
|
||||
throw BError(BError::Codes::SA_INVAL_ARG, "Extension backup Proxy is empty");
|
||||
}
|
||||
proxy->HandleClear();
|
||||
session_->BundleExtTimerStop(callerName);
|
||||
session_->StopFwkTimer(callerName);
|
||||
session_->StopExtTimer(callerName);
|
||||
NotifyCallerCurAppDone(errCode, callerName);
|
||||
backUpConnection->DisconnectBackupExtAbility();
|
||||
ClearSessionAndSchedInfo(callerName);
|
||||
@ -863,7 +865,8 @@ void Service::NotifyCloneBundleFinish(std::string bundleName)
|
||||
throw BError(BError::Codes::SA_INVAL_ARG, "Extension backup Proxy is empty");
|
||||
}
|
||||
proxy->HandleClear();
|
||||
session_->BundleExtTimerStop(bundleName);
|
||||
session_->StopFwkTimer(bundleName);
|
||||
session_->StopExtTimer(bundleName);
|
||||
backUpConnection->DisconnectBackupExtAbility();
|
||||
ClearSessionAndSchedInfo(bundleName);
|
||||
}
|
||||
@ -1048,7 +1051,8 @@ void Service::ExtConnectDied(const string &callName)
|
||||
try {
|
||||
HILOGI("Begin, bundleName: %{public}s", callName.c_str());
|
||||
/* Clear Timer */
|
||||
session_->BundleExtTimerStop(callName);
|
||||
session_->StopFwkTimer(callName);
|
||||
session_->StopExtTimer(callName);
|
||||
auto backUpConnection = session_->GetExtConnection(callName);
|
||||
if (backUpConnection != nullptr && backUpConnection->IsExtAbilityConnected()) {
|
||||
backUpConnection->DisconnectBackupExtAbility();
|
||||
@ -1193,44 +1197,15 @@ void Service::NoticeClientFinish(const string &bundleName, ErrCode errCode)
|
||||
void Service::ExtConnectDone(string bundleName)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
|
||||
auto timeoutCallback = [ptr {wptr(this)}, bundleName]() {
|
||||
HILOGI("begin timeoutCallback bundleName = %{public}s", bundleName.c_str());
|
||||
auto thisPtr = ptr.promote();
|
||||
if (!thisPtr) {
|
||||
HILOGE("ServicePtr is nullptr.");
|
||||
return;
|
||||
}
|
||||
auto sessionPtr = ptr->session_;
|
||||
if (sessionPtr == nullptr) {
|
||||
HILOGE("SessionPtr is nullptr.");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (SAUtils::IsSABundleName(bundleName)) {
|
||||
auto sessionConnection = sessionPtr->GetSAExtConnection(bundleName);
|
||||
shared_ptr<SABackupConnection> saConnection = sessionConnection.lock();
|
||||
if (saConnection == nullptr) {
|
||||
HILOGE("lock sa connection ptr is nullptr");
|
||||
return;
|
||||
}
|
||||
sessionPtr->BundleExtTimerStop(bundleName);
|
||||
saConnection->DisconnectBackupSAExt();
|
||||
} else {
|
||||
auto sessionConnection = sessionPtr->GetExtConnection(bundleName);
|
||||
sessionPtr->BundleExtTimerStop(bundleName);
|
||||
sessionConnection->DisconnectBackupExtAbility();
|
||||
}
|
||||
thisPtr->ClearSessionAndSchedInfo(bundleName);
|
||||
thisPtr->NoticeClientFinish(bundleName, BError(BError::Codes::EXT_ABILITY_TIMEOUT));
|
||||
} catch (...) {
|
||||
HILOGE("Unexpected exception, bundleName: %{public}s", bundleName.c_str());
|
||||
thisPtr->ClearSessionAndSchedInfo(bundleName);
|
||||
thisPtr->NoticeClientFinish(bundleName, BError(BError::Codes::EXT_ABILITY_TIMEOUT));
|
||||
}
|
||||
};
|
||||
try {
|
||||
HILOGE("begin %{public}s", bundleName.data());
|
||||
session_->BundleExtTimerStart(bundleName, timeoutCallback);
|
||||
auto timeoutCallback = TimeOutCallback(wptr<Service>(this), bundleName);
|
||||
auto scenario = session_->GetScenario();
|
||||
if (scenario == IServiceReverse::Scenario::BACKUP) {
|
||||
session_->StartExtTimer(bundleName, timeoutCallback);
|
||||
} else if (scenario == IServiceReverse::Scenario::RESTORE) {
|
||||
session_->StartFwkTimer(bundleName, timeoutCallback);
|
||||
}
|
||||
session_->SetServiceSchedAction(bundleName, BConstants::ServiceSchedAction::RUNNING);
|
||||
sched_->Sched(bundleName);
|
||||
} catch (...) {
|
||||
@ -1574,6 +1549,54 @@ ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result)
|
||||
}
|
||||
}
|
||||
|
||||
ErrCode Service::StartExtTimer(bool &isExtStart)
|
||||
{
|
||||
try {
|
||||
HILOGI("Service::StartExtTimer begin.");
|
||||
string bundleName = VerifyCallerAndGetCallerName();
|
||||
if (session_ == nullptr) {
|
||||
HILOGE("StartExtTimer error, session_ is nullptr.");
|
||||
isExtStart = false;
|
||||
return BError(BError::Codes::SA_INVAL_ARG);
|
||||
}
|
||||
session_->IncreaseSessionCnt();
|
||||
auto timeoutCallback = TimeOutCallback(wptr<Service>(this), bundleName);
|
||||
session_->StopFwkTimer(bundleName);
|
||||
isExtStart = session_->StartExtTimer(bundleName, timeoutCallback);
|
||||
session_->DecreaseSessionCnt();
|
||||
return BError(BError::Codes::OK);
|
||||
} catch (...) {
|
||||
isExtStart = false;
|
||||
session_->DecreaseSessionCnt();
|
||||
HILOGI("Unexpected exception");
|
||||
return EPERM;
|
||||
}
|
||||
}
|
||||
|
||||
ErrCode Service::StartFwkTimer(bool &isFwkStart)
|
||||
{
|
||||
try {
|
||||
HILOGI("Service::StartFwkTimer begin.");
|
||||
string bundleName = VerifyCallerAndGetCallerName();
|
||||
if (session_ == nullptr) {
|
||||
HILOGE("StartFwkTimer error, session_ is nullptr.");
|
||||
isFwkStart = false;
|
||||
return BError(BError::Codes::SA_INVAL_ARG);
|
||||
}
|
||||
session_->IncreaseSessionCnt();
|
||||
auto timeoutCallback = TimeOutCallback(wptr<Service>(this), bundleName);
|
||||
session_->StopExtTimer(bundleName);
|
||||
isFwkStart = session_->StartFwkTimer(bundleName, timeoutCallback);
|
||||
session_->DecreaseSessionCnt();
|
||||
return BError(BError::Codes::OK);
|
||||
} catch (...) {
|
||||
isFwkStart = false;
|
||||
session_->DecreaseSessionCnt();
|
||||
HILOGI("Unexpected exception");
|
||||
return EPERM;
|
||||
}
|
||||
}
|
||||
|
||||
ErrCode Service::UpdateTimer(BundleName &bundleName, uint32_t timeOut, bool &result)
|
||||
{
|
||||
auto timeoutCallback = [ptr {wptr(this)}, bundleName]() {
|
||||
@ -1590,7 +1613,8 @@ ErrCode Service::UpdateTimer(BundleName &bundleName, uint32_t timeOut, bool &res
|
||||
}
|
||||
try {
|
||||
auto sessionConnection = sessionPtr->GetExtConnection(bundleName);
|
||||
sessionPtr->BundleExtTimerStop(bundleName);
|
||||
sessionPtr->StopFwkTimer(bundleName);
|
||||
sessionPtr->StopExtTimer(bundleName);
|
||||
sessionConnection->DisconnectBackupExtAbility();
|
||||
thisPtr->ClearSessionAndSchedInfo(bundleName);
|
||||
thisPtr->NoticeClientFinish(bundleName, BError(BError::Codes::EXT_ABILITY_TIMEOUT));
|
||||
@ -1722,7 +1746,8 @@ ErrCode Service::SADone(ErrCode errCode, std::string bundleName)
|
||||
HILOGE("lock sa connection ptr is nullptr");
|
||||
return BError(BError::Codes::SA_INVAL_ARG);
|
||||
}
|
||||
session_->BundleExtTimerStop(bundleName);
|
||||
session_->StopFwkTimer(bundleName);
|
||||
session_->StopExtTimer(bundleName);
|
||||
saConnection->DisconnectBackupSAExt();
|
||||
ClearSessionAndSchedInfo(bundleName);
|
||||
}
|
||||
@ -1788,4 +1813,43 @@ ErrCode Service::ReportAppProcessInfo(const std::string processInfo, BackupResto
|
||||
return EPERM;
|
||||
}
|
||||
}
|
||||
|
||||
std::function<void()> Service::TimeOutCallback(wptr<Service> ptr, std::string bundleName)
|
||||
{
|
||||
return [ptr, bundleName]() {
|
||||
HILOGI("begin timeoutCallback bundleName = %{public}s", bundleName.c_str());
|
||||
auto thisPtr = ptr.promote();
|
||||
if (!thisPtr) {
|
||||
HILOGE("ServicePtr is nullptr.");
|
||||
return;
|
||||
}
|
||||
auto sessionPtr = thisPtr->session_;
|
||||
if (sessionPtr == nullptr) {
|
||||
HILOGE("SessionPtr is nullptr.");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (SAUtils::IsSABundleName(bundleName)) {
|
||||
auto sessionConnection = sessionPtr->GetSAExtConnection(bundleName);
|
||||
shared_ptr<SABackupConnection> saConnection = sessionConnection.lock();
|
||||
if (saConnection == nullptr) {
|
||||
HILOGE("lock sa connection ptr is nullptr");
|
||||
return;
|
||||
}
|
||||
saConnection->DisconnectBackupSAExt();
|
||||
} else {
|
||||
auto sessionConnection = sessionPtr->GetExtConnection(bundleName);
|
||||
sessionConnection->DisconnectBackupExtAbility();
|
||||
}
|
||||
sessionPtr->StopFwkTimer(bundleName);
|
||||
sessionPtr->StopExtTimer(bundleName);
|
||||
thisPtr->ClearSessionAndSchedInfo(bundleName);
|
||||
thisPtr->NoticeClientFinish(bundleName, BError(BError::Codes::EXT_ABILITY_TIMEOUT));
|
||||
} catch (...) {
|
||||
HILOGE("Unexpected exception, bundleName: %{public}s", bundleName.c_str());
|
||||
thisPtr->ClearSessionAndSchedInfo(bundleName);
|
||||
thisPtr->NoticeClientFinish(bundleName, BError(BError::Codes::EXT_ABILITY_TIMEOUT));
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace OHOS::FileManagement::Backup
|
||||
|
@ -413,7 +413,8 @@ ErrCode Service::AppIncrementalFileReady(const std::string &fileName, UniqueFd f
|
||||
// 通知extension清空缓存
|
||||
proxy->HandleClear();
|
||||
// 清除Timer
|
||||
session_->BundleExtTimerStop(callerName);
|
||||
session_->StopFwkTimer(callerName);
|
||||
session_->StopExtTimer(callerName);
|
||||
// 通知TOOL 备份完成
|
||||
HILOGI("reverse: Will notify IncrementalBackupOnBundleFinished");
|
||||
session_->GetServiceReverseProxy()->IncrementalBackupOnBundleFinished(BError(BError::Codes::OK),
|
||||
@ -457,7 +458,8 @@ ErrCode Service::AppIncrementalDone(ErrCode errCode)
|
||||
return BError(BError::Codes::SA_INVAL_ARG, "Extension backup Proxy is empty");
|
||||
}
|
||||
proxy->HandleClear();
|
||||
session_->BundleExtTimerStop(callerName);
|
||||
session_->StopFwkTimer(callerName);
|
||||
session_->StopExtTimer(callerName);
|
||||
NotifyCallerCurAppIncrementDone(errCode, callerName);
|
||||
backUpConnection->DisconnectBackupExtAbility();
|
||||
ClearSessionAndSchedInfo(callerName);
|
||||
|
@ -132,8 +132,8 @@ void ServiceReverseProxy::IncrementalBackupOnProcessInfo(std::string bundleName,
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (int err = Remote()->SendRequest(
|
||||
static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_PROCESS_INFO),
|
||||
data, reply, option);
|
||||
static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_PROCESS_INFO), data,
|
||||
reply, option);
|
||||
err != ERR_OK) {
|
||||
throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
|
||||
}
|
||||
@ -247,8 +247,8 @@ void ServiceReverseProxy::IncrementalRestoreOnProcessInfo(std::string bundleName
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (int err = Remote()->SendRequest(
|
||||
static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_PROCESS_INFO),
|
||||
data, reply, option);
|
||||
static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_PROCESS_INFO), data,
|
||||
reply, option);
|
||||
err != ERR_OK) {
|
||||
throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
|
||||
}
|
||||
|
@ -46,6 +46,10 @@ void ServiceStub::ServiceStubSupplement()
|
||||
opToInterfaceMap_[static_cast<uint32_t>(
|
||||
IServiceInterfaceCode::SERVICE_CMD_REPORT_APP_PROCESS_INFO)] =
|
||||
&ServiceStub::CmdReportAppProcessInfo;
|
||||
opToInterfaceMap_[static_cast<uint32_t>(IServiceInterfaceCode::SERVICE_CMD_START_EXT_TIMER)] =
|
||||
&ServiceStub::CmdStartExtTimer;
|
||||
opToInterfaceMap_[static_cast<uint32_t>(IServiceInterfaceCode::SERVICE_CMD_START_FWK_TIMER)] =
|
||||
&ServiceStub::CmdStartFwkTimer;
|
||||
}
|
||||
|
||||
void ServiceStub::ServiceStubSuppAppendBundles()
|
||||
@ -450,6 +454,38 @@ int32_t ServiceStub::CmdUpdateSendRate(MessageParcel &data, MessageParcel &reply
|
||||
return BError(BError::Codes::OK);
|
||||
}
|
||||
|
||||
int32_t ServiceStub::CmdStartExtTimer(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
HILOGI("ServiceStub::CmdStartExtTimer Begin.");
|
||||
int ret = ERR_OK;
|
||||
bool isExtStart;
|
||||
ret = StartExtTimer(isExtStart);
|
||||
if (ret != ERR_OK) {
|
||||
return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to call UpdateTimer"));
|
||||
}
|
||||
if (!reply.WriteBool(isExtStart)) {
|
||||
return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result"));
|
||||
}
|
||||
HILOGI("ServiceStub::CmdStartExtTimer end.");
|
||||
return BError(BError::Codes::OK);
|
||||
}
|
||||
|
||||
int32_t ServiceStub::CmdStartFwkTimer(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
HILOGI("ServiceStub::CmdStartFwkTimer Begin.");
|
||||
int ret = ERR_OK;
|
||||
bool isFwkStart;
|
||||
ret = StartFwkTimer(isFwkStart);
|
||||
if (ret != ERR_OK) {
|
||||
return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to call UpdateTimer"));
|
||||
}
|
||||
if (!reply.WriteBool(isFwkStart)) {
|
||||
return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result"));
|
||||
}
|
||||
HILOGI("ServiceStub::CmdStartFwkTimer end.");
|
||||
return BError(BError::Codes::OK);
|
||||
}
|
||||
|
||||
int32_t ServiceStub::CmdRelease(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
int res = Release();
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "b_json/b_json_entity_ext_manage.h"
|
||||
#include "b_resources/b_constants.h"
|
||||
#include "b_sa/b_sa_utils.h"
|
||||
#include "b_utils/b_time.h"
|
||||
#include "filemgmt_libhilog.h"
|
||||
#include "module_ipc/service.h"
|
||||
#include "module_ipc/svc_restore_deps_manager.h"
|
||||
@ -684,60 +685,131 @@ uint32_t SvcSessionManager::CalAppProcessTime(const std::string &bundleName)
|
||||
}
|
||||
timeout = timeout < minTimeout ? minTimeout : timeout;
|
||||
resTimeoutMs = (uint32_t)(timeout * invertMillisecond % UINT_MAX); /* conver second to millisecond */
|
||||
HILOGI("Calculate App extension process run timeout=%{public}u(us), bundleName=%{public}s ", resTimeoutMs,
|
||||
HILOGI("Calculate App extension process run timeout=%{public}u(ms), bundleName=%{public}s ", resTimeoutMs,
|
||||
bundleName.c_str());
|
||||
return resTimeoutMs;
|
||||
}
|
||||
|
||||
void SvcSessionManager::BundleExtTimerStart(const std::string &bundleName, const Utils::Timer::TimerCallback &callback)
|
||||
bool SvcSessionManager::StartFwkTimer(const std::string &bundleName, const Utils::Timer::TimerCallback &callback)
|
||||
{
|
||||
unique_lock<shared_mutex> lock(lock_);
|
||||
HILOGI("StartFwkTimer begin bundleName %{public}s", bundleName.c_str());
|
||||
if (!impl_.clientToken) {
|
||||
throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified");
|
||||
HILOGE("No caller token was specified");
|
||||
return false;
|
||||
}
|
||||
auto it = GetBackupExtNameMap(bundleName);
|
||||
if (it->second.fwkTimerStatus == true) {
|
||||
HILOGE("FwkTimer is registered, unregister first.");
|
||||
return false;
|
||||
}
|
||||
uint32_t timeout = CalAppProcessTime(bundleName);
|
||||
|
||||
auto it = GetBackupExtNameMap(bundleName);
|
||||
if (it->second.timerStatus == false) {
|
||||
it->second.timerStatus = true;
|
||||
it->second.extTimerId = extBundleTimer.Register(callback, timeout, true);
|
||||
it->second.fwkTimerStatus = true;
|
||||
it->second.timerId = timer_.Register(callback, timeout, true);
|
||||
HILOGI("StartFwkTimer end bundleName %{public}s", bundleName.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SvcSessionManager::StopFwkTimer(const std::string &bundleName)
|
||||
{
|
||||
unique_lock<shared_mutex> lock(lock_);
|
||||
HILOGI("StopFwkTimer begin bundleName %{public}s", bundleName.c_str());
|
||||
if (!impl_.clientToken) {
|
||||
HILOGE("No caller token was specified");
|
||||
return false;
|
||||
}
|
||||
auto it = GetBackupExtNameMap(bundleName);
|
||||
if (it->second.fwkTimerStatus == false) {
|
||||
HILOGE("FwkTimer is unregistered, register first.");
|
||||
return true;
|
||||
}
|
||||
|
||||
it->second.fwkTimerStatus = false;
|
||||
timer_.Unregister(it->second.timerId);
|
||||
HILOGI("StopFwkTimer end bundleName %{public}s", bundleName.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SvcSessionManager::StartExtTimer(const std::string &bundleName, const Utils::Timer::TimerCallback &callback)
|
||||
{
|
||||
unique_lock<shared_mutex> lock(lock_);
|
||||
HILOGI("StartExtTimer begin bundleName %{public}s", bundleName.c_str());
|
||||
if (!impl_.clientToken) {
|
||||
HILOGE("No caller token was specified");
|
||||
return false;
|
||||
}
|
||||
auto it = GetBackupExtNameMap(bundleName);
|
||||
if (it->second.extTimerStatus == true) {
|
||||
HILOGE("ExtTimer is registered, unregister first.");
|
||||
return false;
|
||||
}
|
||||
uint32_t timeout = it->second.timeCount;
|
||||
timeout = (timeout != 0) ? timeout : CalAppProcessTime(bundleName);
|
||||
it->second.extTimerStatus = true;
|
||||
it->second.startTime = static_cast<uint32_t>(TimeUtils::GetTimeMS());
|
||||
it->second.timeCount = timeout;
|
||||
it->second.timerId = timer_.Register(callback, timeout, true);
|
||||
HILOGI("StartExtTimer end, timeout %{public}u(ms), bundleName %{public}s", timeout, bundleName.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SvcSessionManager::StopExtTimer(const std::string &bundleName)
|
||||
{
|
||||
unique_lock<shared_mutex> lock(lock_);
|
||||
HILOGI("StopExtTimer begin bundleName %{public}s", bundleName.c_str());
|
||||
if (!impl_.clientToken) {
|
||||
HILOGE("No caller token was specified");
|
||||
return false;
|
||||
}
|
||||
auto it = GetBackupExtNameMap(bundleName);
|
||||
if (it->second.extTimerStatus == false) {
|
||||
HILOGE("ExtTimer is unregistered, register first.");
|
||||
return true;
|
||||
}
|
||||
|
||||
it->second.extTimerStatus = false;
|
||||
it->second.startTime = 0;
|
||||
it->second.timeCount = 0;
|
||||
timer_.Unregister(it->second.timerId);
|
||||
HILOGI("StopExtTimer end bundleName %{public}s", bundleName.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SvcSessionManager::UpdateTimer(const std::string &bundleName, uint32_t timeOut,
|
||||
const Utils::Timer::TimerCallback &callback)
|
||||
{
|
||||
unique_lock<shared_mutex> lock(lock_);
|
||||
HILOGI("UpdateTimer begin bundleName %{public}s", bundleName.c_str());
|
||||
if (!impl_.clientToken) {
|
||||
throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified");
|
||||
}
|
||||
|
||||
auto it = GetBackupExtNameMap(bundleName);
|
||||
if (it->second.timerStatus == true) {
|
||||
// 定时器已存在,则先销毁,再重新注册
|
||||
it->second.timerStatus = false;
|
||||
extBundleTimer.Unregister(it->second.extTimerId);
|
||||
HILOGI("UpdateTimer timeout=%{public}u(ms), bundleName=%{public}s ",
|
||||
timeOut, bundleName.c_str());
|
||||
it->second.extTimerId = extBundleTimer.Register(callback, timeOut, true);
|
||||
it->second.timerStatus = true;
|
||||
return true;
|
||||
}
|
||||
HILOGE("No caller token was specified");
|
||||
return false;
|
||||
}
|
||||
|
||||
void SvcSessionManager::BundleExtTimerStop(const std::string &bundleName)
|
||||
{
|
||||
unique_lock<shared_mutex> lock(lock_);
|
||||
if (!impl_.clientToken) {
|
||||
throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified");
|
||||
auto it = GetBackupExtNameMap(bundleName);
|
||||
if (it->second.extTimerStatus == false) {
|
||||
HILOGI("ExtTimer is unregistered, just count. timeout %{public}u(ms), timeCount %{public}u(ms)",
|
||||
timeOut, it->second.timeCount);
|
||||
return true;
|
||||
}
|
||||
|
||||
auto it = GetBackupExtNameMap(bundleName);
|
||||
if (it->second.timerStatus == true) {
|
||||
it->second.timerStatus = false;
|
||||
extBundleTimer.Unregister(it->second.extTimerId);
|
||||
if (it->second.startTime == 0) {
|
||||
HILOGE("ExtTimer is registered, but start time is zero.");
|
||||
return false;
|
||||
}
|
||||
|
||||
it->second.timeCount += timeOut;
|
||||
uint32_t updateTime = static_cast<uint32_t>(TimeUtils::GetTimeMS());
|
||||
uint32_t elapseTime = updateTime - it->second.startTime;
|
||||
uint32_t realTimeout = it->second.timeCount - elapseTime;
|
||||
timer_.Unregister(it->second.timerId);
|
||||
HILOGI("UpdateTimer timeout %{public}u(ms), timeCount %{public}u(ms), elapseTime %{public}u(ms),"
|
||||
"realTimeout %{public}u(ms), bundleName %{public}s ",
|
||||
timeOut, it->second.timeCount, elapseTime, realTimeout, bundleName.c_str());
|
||||
it->second.timerId = timer_.Register(callback, realTimeout, true);
|
||||
it->second.extTimerStatus = true;
|
||||
HILOGI("UpdateTimer end bundleName %{public}s", bundleName.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
void SvcSessionManager::IncreaseSessionCnt()
|
||||
@ -769,9 +841,10 @@ void SvcSessionManager::ClearSessionData()
|
||||
unique_lock<shared_mutex> lock(lock_);
|
||||
for (auto &&it : impl_.backupExtNameMap) {
|
||||
// clear timer
|
||||
if (it.second.timerStatus == true) {
|
||||
it.second.timerStatus = false;
|
||||
extBundleTimer.Unregister(it.second.extTimerId);
|
||||
if (it.second.fwkTimerStatus == true || it.second.extTimerStatus == true) {
|
||||
it.second.fwkTimerStatus = false;
|
||||
it.second.extTimerStatus = false;
|
||||
timer_.Unregister(it.second.timerId);
|
||||
}
|
||||
// disconnect extension
|
||||
if (it.second.schedAction == BConstants::ServiceSchedAction::RUNNING) {
|
||||
|
@ -51,6 +51,7 @@ public:
|
||||
virtual BConstants::ExtensionAction VerifyAndGetAction(const AAFwk::Want &,
|
||||
std::shared_ptr<AppExecFwk::AbilityInfo>) = 0;
|
||||
virtual ErrCode GetParament(const AAFwk::Want &) = 0;
|
||||
virtual ErrCode OnProcess(std::function<void(ErrCode, std::string)> callback) = 0;
|
||||
public:
|
||||
virtual std::unique_ptr<NativeReference> LoadSystemModuleByEngine(napi_env, const std::string&, const napi_value*,
|
||||
size_t) = 0;
|
||||
@ -86,6 +87,7 @@ public:
|
||||
std::function<void(ErrCode, const std::string)>));
|
||||
MOCK_METHOD(ErrCode, OnRestore, (std::function<void(ErrCode, std::string)>));
|
||||
MOCK_METHOD(ErrCode, GetBackupInfo, (std::function<void(ErrCode, std::string)>));
|
||||
MOCK_METHOD(ErrCode, OnProcess, (std::function<void(ErrCode, std::string)>));
|
||||
MOCK_METHOD(bool, WasFromSpecialVersion, ());
|
||||
MOCK_METHOD(bool, SpecialVersionForCloneAndCloud, ());
|
||||
MOCK_METHOD(bool, RestoreDataReady, ());
|
||||
|
@ -133,4 +133,9 @@ ErrCode ExtBackup::InvokeAppExtMethod(ErrCode errCode, const std::string result)
|
||||
{
|
||||
return BExtBackup::extBackup->InvokeAppExtMethod(errCode, result);
|
||||
}
|
||||
|
||||
ErrCode ExtBackup::OnProcess(function<void(ErrCode, std::string)> callback)
|
||||
{
|
||||
return BExtBackup::extBackup->OnProcess(callback);
|
||||
}
|
||||
} // namespace OHOS::FileManagement::Backup
|
||||
|
@ -182,6 +182,15 @@ ErrCode ServiceProxy::UpdateTimer(BundleName &bundleName, uint32_t timeOut, bool
|
||||
return BError(BError::Codes::OK);
|
||||
}
|
||||
|
||||
ErrCode ServiceProxy::StartExtTimer(bool &isExtStart)
|
||||
{
|
||||
return BError(BError::Codes::OK);
|
||||
}
|
||||
ErrCode ServiceProxy::StartFwkTimer(bool &isFwkStart)
|
||||
{
|
||||
return BError(BError::Codes::OK);
|
||||
}
|
||||
|
||||
ErrCode ServiceProxy::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result)
|
||||
{
|
||||
return BError(BError::Codes::OK);
|
||||
|
@ -216,6 +216,16 @@ ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result)
|
||||
return BError(BError::Codes::OK);
|
||||
}
|
||||
|
||||
ErrCode Service::StartExtTimer(bool &isExtStart)
|
||||
{
|
||||
return BError(BError::Codes::OK);
|
||||
}
|
||||
|
||||
ErrCode Service::StartFwkTimer(bool &isFwkStart)
|
||||
{
|
||||
return BError(BError::Codes::OK);
|
||||
}
|
||||
|
||||
ErrCode Service::UpdateTimer(BundleName &bundleName, uint32_t timeOut, bool &result)
|
||||
{
|
||||
return BError(BError::Codes::OK);
|
||||
|
@ -354,8 +354,24 @@ void SvcSessionManager::SetBundleDataSize(const std::string &bundleName, int64_t
|
||||
it->second.dataSize = dataSize;
|
||||
}
|
||||
|
||||
void SvcSessionManager::BundleExtTimerStart(const std::string &bundleName, const Utils::Timer::TimerCallback &callback)
|
||||
bool SvcSessionManager::StartFwkTimer(const std::string &bundleName, const Utils::Timer::TimerCallback &callback)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SvcSessionManager::StopFwkTimer(const std::string &bundleName)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SvcSessionManager::StartExtTimer(const std::string &bundleName, const Utils::Timer::TimerCallback &callback)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SvcSessionManager::StopExtTimer(const std::string &bundleName)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SvcSessionManager::UpdateTimer(const std::string &bundleName, uint32_t timeOut,
|
||||
@ -364,8 +380,6 @@ bool SvcSessionManager::UpdateTimer(const std::string &bundleName, uint32_t time
|
||||
return true;
|
||||
}
|
||||
|
||||
void SvcSessionManager::BundleExtTimerStop(const std::string &bundleName) {}
|
||||
|
||||
void SvcSessionManager::IncreaseSessionCnt() {}
|
||||
|
||||
void SvcSessionManager::DecreaseSessionCnt() {}
|
||||
|
@ -219,9 +219,24 @@ void SvcSessionManager::SetBundleDataSize(const std::string &bundleName, int64_t
|
||||
BackupSvcSessionManager::session->SetBundleDataSize(bundleName, dataSize);
|
||||
}
|
||||
|
||||
void SvcSessionManager::BundleExtTimerStart(const std::string &bundleName, const Utils::Timer::TimerCallback &callback)
|
||||
bool SvcSessionManager::StartFwkTimer(const std::string &bundleName, const Utils::Timer::TimerCallback &callback)
|
||||
{
|
||||
BackupSvcSessionManager::session->BundleExtTimerStart(bundleName, callback);
|
||||
return BackupSvcSessionManager::session->StartFwkTimer(bundleName, callback);
|
||||
}
|
||||
|
||||
bool SvcSessionManager::StopFwkTimer(const std::string &bundleName)
|
||||
{
|
||||
return BackupSvcSessionManager::session->StopFwkTimer(bundleName);
|
||||
}
|
||||
|
||||
bool SvcSessionManager::StartExtTimer(const std::string &bundleName, const Utils::Timer::TimerCallback &callback)
|
||||
{
|
||||
return BackupSvcSessionManager::session->StartExtTimer(bundleName, callback);
|
||||
}
|
||||
|
||||
bool SvcSessionManager::StopExtTimer(const std::string &bundleName)
|
||||
{
|
||||
return BackupSvcSessionManager::session->StopExtTimer(bundleName);
|
||||
}
|
||||
|
||||
bool SvcSessionManager::UpdateTimer(const std::string &bundleName, uint32_t timeOut,
|
||||
@ -230,11 +245,6 @@ bool SvcSessionManager::UpdateTimer(const std::string &bundleName, uint32_t time
|
||||
return BackupSvcSessionManager::session->UpdateTimer(bundleName, timeOut, callback);
|
||||
}
|
||||
|
||||
void SvcSessionManager::BundleExtTimerStop(const std::string &bundleName)
|
||||
{
|
||||
BackupSvcSessionManager::session->BundleExtTimerStop(bundleName);
|
||||
}
|
||||
|
||||
void SvcSessionManager::IncreaseSessionCnt()
|
||||
{
|
||||
BackupSvcSessionManager::session->IncreaseSessionCnt();
|
||||
|
@ -67,9 +67,11 @@ public:
|
||||
virtual void SetBundleVersionName(const std::string &, std::string) = 0;
|
||||
virtual std::string GetBundleVersionName(const std::string &) = 0;
|
||||
virtual void SetBundleDataSize(const std::string &, int64_t) = 0;
|
||||
virtual void BundleExtTimerStart(const std::string &, const Utils::Timer::TimerCallback &) = 0;
|
||||
virtual bool StartFwkTimer(const std::string &, const Utils::Timer::TimerCallback &) = 0;
|
||||
virtual bool StopFwkTimer(const std::string &) = 0;
|
||||
virtual bool StartExtTimer(const std::string &, const Utils::Timer::TimerCallback &) = 0;
|
||||
virtual bool StopExtTimer(const std::string &) = 0;
|
||||
virtual bool UpdateTimer(const std::string &, uint32_t, const Utils::Timer::TimerCallback &) = 0;
|
||||
virtual void BundleExtTimerStop(const std::string &) = 0;
|
||||
virtual void IncreaseSessionCnt() = 0;
|
||||
virtual void DecreaseSessionCnt() = 0;
|
||||
virtual int32_t GetMemParaCurSize() = 0;
|
||||
@ -130,9 +132,11 @@ public:
|
||||
MOCK_METHOD(void, SetBundleVersionName, (const std::string &, std::string));
|
||||
MOCK_METHOD(std::string, GetBundleVersionName, (const std::string &));
|
||||
MOCK_METHOD(void, SetBundleDataSize, (const std::string &, int64_t));
|
||||
MOCK_METHOD(void, BundleExtTimerStart, (const std::string &, const Utils::Timer::TimerCallback &));
|
||||
MOCK_METHOD(bool, StartFwkTimer, (const std::string &, const Utils::Timer::TimerCallback &));
|
||||
MOCK_METHOD(bool, StopFwkTimer, (const std::string &));
|
||||
MOCK_METHOD(bool, StartExtTimer, (const std::string &, const Utils::Timer::TimerCallback &));
|
||||
MOCK_METHOD(bool, StopExtTimer, (const std::string &));
|
||||
MOCK_METHOD(bool, UpdateTimer, (const std::string &, uint32_t, const Utils::Timer::TimerCallback &));
|
||||
MOCK_METHOD(void, BundleExtTimerStop, (const std::string &));
|
||||
MOCK_METHOD(void, IncreaseSessionCnt, ());
|
||||
MOCK_METHOD(void, DecreaseSessionCnt, ());
|
||||
MOCK_METHOD(int32_t, GetMemParaCurSize, ());
|
||||
|
@ -143,6 +143,16 @@ public:
|
||||
return BError(BError::Codes::OK);
|
||||
}
|
||||
|
||||
ErrCode StartExtTimer(bool &isExtStart) override
|
||||
{
|
||||
return BError(BError::Codes::OK);
|
||||
}
|
||||
|
||||
ErrCode StartFwkTimer(bool &isFwkStart) override
|
||||
{
|
||||
return BError(BError::Codes::OK);
|
||||
}
|
||||
|
||||
ErrCode UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) override
|
||||
{
|
||||
return BError(BError::Codes::OK);
|
||||
|
@ -80,6 +80,8 @@ 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_METHOD1(StartExtTimer, ErrCode(bool &isExtStart));
|
||||
MOCK_METHOD1(StartFwkTimer, ErrCode(bool &isFwkStart));
|
||||
MOCK_METHOD3(UpdateSendRate, ErrCode(std::string &bundleName, int32_t sendRate, bool &result));
|
||||
MOCK_METHOD2(ReportAppProcessInfo, ErrCode(const std::string processInfo, BackupRestoreScenario sennario));
|
||||
};
|
||||
|
@ -529,8 +529,9 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_OnBackupExtensionDied_0100, testing
|
||||
EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Invoke([]() {
|
||||
throw BError(BError::Codes::EXT_THROW_EXCEPTION);
|
||||
}));
|
||||
EXPECT_CALL(*sessionMock, BundleExtTimerStop(_)).WillOnce(Invoke([]() {
|
||||
EXPECT_CALL(*sessionMock, StopFwkTimer(_)).WillOnce(Invoke([]() {
|
||||
throw BError(BError::Codes::EXT_THROW_EXCEPTION);
|
||||
return true;
|
||||
}));
|
||||
EXPECT_CALL(*sessionMock, RemoveExtInfo(_)).WillOnce(Invoke([]() {
|
||||
throw BError(BError::Codes::EXT_THROW_EXCEPTION);
|
||||
@ -548,40 +549,6 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_OnBackupExtensionDied_0100, testing
|
||||
GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_OnBackupExtensionDied_0100";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: SUB_Service_throw_ExtConnectDied_0100
|
||||
* @tc.name: SUB_Service_throw_ExtConnectDied_0100
|
||||
* @tc.desc: 测试 ExtConnectDied 接口的 catch 分支
|
||||
* @tc.size: MEDIUM
|
||||
* @tc.type: FUNC
|
||||
* @tc.level Level 1
|
||||
* @tc.require: issuesIAC04T
|
||||
*/
|
||||
HWTEST_F(ServiceThrowTest, SUB_Service_throw_ExtConnectDied_0100, testing::ext::TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "ServiceThrowTest-begin SUB_Service_throw_ExtConnectDied_0100";
|
||||
try {
|
||||
EXPECT_NE(service, nullptr);
|
||||
string callName;
|
||||
EXPECT_CALL(*sessionMock, BundleExtTimerStop(_)).WillOnce(Invoke([]() {
|
||||
throw BError(BError::Codes::EXT_THROW_EXCEPTION);
|
||||
}));
|
||||
EXPECT_CALL(*sessionMock, RemoveExtInfo(_)).WillOnce(Invoke([]() {
|
||||
throw BError(BError::Codes::EXT_THROW_EXCEPTION);
|
||||
}));
|
||||
EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Invoke([]() {
|
||||
throw BError(BError::Codes::EXT_THROW_EXCEPTION);
|
||||
return IServiceReverse::Scenario::UNDEFINED;
|
||||
}));
|
||||
service->ExtConnectDied(callName);
|
||||
EXPECT_TRUE(true);
|
||||
} catch (...) {
|
||||
EXPECT_TRUE(false);
|
||||
GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by ExtConnectDied.";
|
||||
}
|
||||
GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_ExtConnectDied_0100";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: SUB_Service_throw_ExtStart_0100
|
||||
* @tc.name: SUB_Service_throw_ExtStart_0100
|
||||
@ -687,40 +654,6 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_NoticeClientFinish_0100, testing::e
|
||||
GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_NoticeClientFinish_0100";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: SUB_Service_throw_ExtConnectDone_0100
|
||||
* @tc.name: SUB_Service_throw_ExtConnectDone_0100
|
||||
* @tc.desc: 测试 ExtConnectDone 接口的 catch 分支
|
||||
* @tc.size: MEDIUM
|
||||
* @tc.type: FUNC
|
||||
* @tc.level Level 1
|
||||
* @tc.require: issuesIAC04T
|
||||
*/
|
||||
HWTEST_F(ServiceThrowTest, SUB_Service_throw_ExtConnectDone_0100, testing::ext::TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "ServiceThrowTest-begin SUB_Service_throw_ExtConnectDone_0100";
|
||||
try {
|
||||
EXPECT_NE(service, nullptr);
|
||||
string bundleName;
|
||||
EXPECT_CALL(*sessionMock, BundleExtTimerStart(_, _)).WillOnce(Invoke([]() {
|
||||
throw BError(BError::Codes::EXT_THROW_EXCEPTION);
|
||||
}));
|
||||
EXPECT_CALL(*sessionMock, RemoveExtInfo(_)).WillOnce(Invoke([]() {
|
||||
throw BError(BError::Codes::EXT_THROW_EXCEPTION);
|
||||
}));
|
||||
EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Invoke([]() {
|
||||
throw BError(BError::Codes::EXT_THROW_EXCEPTION);
|
||||
return IServiceReverse::Scenario::UNDEFINED;
|
||||
}));
|
||||
service->ExtConnectDone(bundleName);
|
||||
EXPECT_TRUE(true);
|
||||
} catch (...) {
|
||||
EXPECT_TRUE(false);
|
||||
GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by ExtConnectDone.";
|
||||
}
|
||||
GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_ExtConnectDone_0100";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: SUB_Service_throw_ClearSessionAndSchedInfo_0100
|
||||
* @tc.name: SUB_Service_throw_ClearSessionAndSchedInfo_0100
|
||||
|
@ -1704,47 +1704,47 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_SetBundleDataSize_0100, te
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: SUB_backup_sa_session_BundleExtTimerStart_0100
|
||||
* @tc.name: SUB_backup_sa_session_BundleExtTimerStart_0100
|
||||
* @tc.desc: 测试 BundleExtTimerStart
|
||||
* @tc.number: SUB_backup_sa_session_StartFwkTimer_0100
|
||||
* @tc.name: SUB_backup_sa_session_StartFwkTimer_0100
|
||||
* @tc.desc: 测试 StartFwkTimer
|
||||
* @tc.size: MEDIUM
|
||||
* @tc.type: FUNC
|
||||
* @tc.level Level 1
|
||||
* @tc.require: I6F3GV
|
||||
*/
|
||||
HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_BundleExtTimerStart_0100, testing::ext::TestSize.Level1)
|
||||
HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_StartFwkTimer_0100, testing::ext::TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_BundleExtTimerStart_0100";
|
||||
GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_StartFwkTimer_0100";
|
||||
try {
|
||||
auto callback = []() -> void {};
|
||||
try {
|
||||
EXPECT_TRUE(sessionManagerPtr_ != nullptr);
|
||||
sessionManagerPtr_->impl_.clientToken = 0;
|
||||
sessionManagerPtr_->BundleExtTimerStart(BUNDLE_NAME, callback);
|
||||
EXPECT_TRUE(false);
|
||||
} catch (BError &err) {
|
||||
EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG);
|
||||
}
|
||||
auto ret = sessionManagerPtr_->StartFwkTimer(BUNDLE_NAME, callback);
|
||||
EXPECT_FALSE(ret);
|
||||
|
||||
BackupExtInfo info;
|
||||
info.timerStatus = false;
|
||||
info.fwkTimerStatus = false;
|
||||
sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID;
|
||||
sessionManagerPtr_->impl_.backupExtNameMap.clear();
|
||||
sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = info;
|
||||
sessionManagerPtr_->BundleExtTimerStart(BUNDLE_NAME, callback);
|
||||
EXPECT_TRUE(true);
|
||||
ret = sessionManagerPtr_->StartFwkTimer(BUNDLE_NAME, callback);
|
||||
EXPECT_TRUE(ret);
|
||||
ret = sessionManagerPtr_->StopFwkTimer(BUNDLE_NAME);
|
||||
EXPECT_TRUE(ret);
|
||||
|
||||
info.timerStatus = true;
|
||||
info.fwkTimerStatus = true;
|
||||
sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID;
|
||||
sessionManagerPtr_->impl_.backupExtNameMap.clear();
|
||||
sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = info;
|
||||
sessionManagerPtr_->BundleExtTimerStart(BUNDLE_NAME, callback);
|
||||
EXPECT_TRUE(true);
|
||||
ret = sessionManagerPtr_->StartFwkTimer(BUNDLE_NAME, callback);
|
||||
EXPECT_FALSE(ret);
|
||||
ret = sessionManagerPtr_->StopFwkTimer(BUNDLE_NAME);
|
||||
EXPECT_TRUE(ret);
|
||||
} catch (...) {
|
||||
EXPECT_TRUE(false);
|
||||
GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by BundleExtTimerStart.";
|
||||
GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by StartFwkTimer.";
|
||||
}
|
||||
GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_BundleExtTimerStart_0100";
|
||||
GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_StartFwkTimer_0100";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1761,29 +1761,35 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_UpdateTimer_0100, testing:
|
||||
GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_UpdateTimer_0100";
|
||||
try {
|
||||
auto callback = []() -> void {};
|
||||
try {
|
||||
EXPECT_TRUE(sessionManagerPtr_ != nullptr);
|
||||
sessionManagerPtr_->impl_.clientToken = 0;
|
||||
sessionManagerPtr_->UpdateTimer(BUNDLE_NAME, 30, callback);
|
||||
EXPECT_TRUE(false);
|
||||
} catch (BError &err) {
|
||||
EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG);
|
||||
}
|
||||
|
||||
BackupExtInfo info;
|
||||
info.timerStatus = false;
|
||||
sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID;
|
||||
sessionManagerPtr_->impl_.backupExtNameMap.clear();
|
||||
sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = info;
|
||||
auto ret = sessionManagerPtr_->UpdateTimer(BUNDLE_NAME, 30, callback);
|
||||
EXPECT_FALSE(ret);
|
||||
|
||||
info.timerStatus = true;
|
||||
BackupExtInfo info;
|
||||
info.extTimerStatus = false;
|
||||
sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID;
|
||||
sessionManagerPtr_->impl_.backupExtNameMap.clear();
|
||||
sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = info;
|
||||
ret = sessionManagerPtr_->UpdateTimer(BUNDLE_NAME, 30, callback);
|
||||
EXPECT_TRUE(ret);
|
||||
|
||||
sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID;
|
||||
sessionManagerPtr_->impl_.backupExtNameMap.clear();
|
||||
sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = info;
|
||||
ret = sessionManagerPtr_->StartExtTimer(BUNDLE_NAME, callback);
|
||||
EXPECT_TRUE(ret);
|
||||
ret = sessionManagerPtr_->UpdateTimer(BUNDLE_NAME, 30, callback);
|
||||
EXPECT_TRUE(ret);
|
||||
ret = sessionManagerPtr_->StopExtTimer(BUNDLE_NAME);
|
||||
EXPECT_TRUE(ret);
|
||||
|
||||
info.extTimerStatus = true;
|
||||
sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID;
|
||||
sessionManagerPtr_->impl_.backupExtNameMap.clear();
|
||||
sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = info;
|
||||
ret = sessionManagerPtr_->UpdateTimer(BUNDLE_NAME, 30, callback);
|
||||
EXPECT_FALSE(ret);
|
||||
} catch (...) {
|
||||
EXPECT_TRUE(false);
|
||||
GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by UpdateTimer.";
|
||||
@ -1792,46 +1798,42 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_UpdateTimer_0100, testing:
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: SUB_backup_sa_session_BundleExtTimerStop_0100
|
||||
* @tc.name: SUB_backup_sa_session_BundleExtTimerStop_0100
|
||||
* @tc.desc: 测试 BundleExtTimerStop
|
||||
* @tc.number: SUB_backup_sa_session_StopFwkTimer_0100
|
||||
* @tc.name: SUB_backup_sa_session_StopFwkTimer_0100
|
||||
* @tc.desc: 测试 StopFwkTimer
|
||||
* @tc.size: MEDIUM
|
||||
* @tc.type: FUNC
|
||||
* @tc.level Level 1
|
||||
* @tc.require: I6F3GV
|
||||
*/
|
||||
HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_BundleExtTimerStop_0100, testing::ext::TestSize.Level1)
|
||||
HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_StopFwkTimer_0100, testing::ext::TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_BundleExtTimerStop_0100";
|
||||
try {
|
||||
GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_StopFwkTimer_0100";
|
||||
try {
|
||||
EXPECT_TRUE(sessionManagerPtr_ != nullptr);
|
||||
sessionManagerPtr_->impl_.clientToken = 0;
|
||||
sessionManagerPtr_->BundleExtTimerStop(BUNDLE_NAME);
|
||||
EXPECT_TRUE(false);
|
||||
} catch (BError &err) {
|
||||
EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG);
|
||||
}
|
||||
auto ret = sessionManagerPtr_->StopFwkTimer(BUNDLE_NAME);
|
||||
EXPECT_FALSE(ret);
|
||||
|
||||
BackupExtInfo info;
|
||||
info.timerStatus = false;
|
||||
info.fwkTimerStatus = false;
|
||||
sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID;
|
||||
sessionManagerPtr_->impl_.backupExtNameMap.clear();
|
||||
sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = info;
|
||||
sessionManagerPtr_->BundleExtTimerStop(BUNDLE_NAME);
|
||||
EXPECT_TRUE(true);
|
||||
ret = sessionManagerPtr_->StopFwkTimer(BUNDLE_NAME);
|
||||
EXPECT_TRUE(ret);
|
||||
|
||||
info.timerStatus = true;
|
||||
info.fwkTimerStatus = true;
|
||||
sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID;
|
||||
sessionManagerPtr_->impl_.backupExtNameMap.clear();
|
||||
sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = info;
|
||||
sessionManagerPtr_->BundleExtTimerStop(BUNDLE_NAME);
|
||||
EXPECT_TRUE(true);
|
||||
ret = sessionManagerPtr_->StopFwkTimer(BUNDLE_NAME);
|
||||
EXPECT_TRUE(ret);
|
||||
} catch (...) {
|
||||
EXPECT_TRUE(false);
|
||||
GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by BundleExtTimerStop.";
|
||||
GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by StopFwkTimer.";
|
||||
}
|
||||
GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_BundleExtTimerStop_0100";
|
||||
GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_StopFwkTimer_0100";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1848,7 +1850,7 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_ClearSessionData_0100, tes
|
||||
GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_ClearSessionData_0100";
|
||||
try {
|
||||
BackupExtInfo info;
|
||||
info.timerStatus = true;
|
||||
info.fwkTimerStatus = true;
|
||||
info.schedAction = BConstants::ServiceSchedAction::RUNNING;
|
||||
info.backUpConnection = sptr(new SvcBackupConnection(nullptr, nullptr, BUNDLE_NAME));
|
||||
EXPECT_TRUE(sessionManagerPtr_ != nullptr);
|
||||
@ -1857,7 +1859,7 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_ClearSessionData_0100, tes
|
||||
sessionManagerPtr_->ClearSessionData();
|
||||
EXPECT_TRUE(true);
|
||||
|
||||
info.timerStatus = false;
|
||||
info.fwkTimerStatus = false;
|
||||
info.schedAction = BConstants::ServiceSchedAction::WAIT;
|
||||
sessionManagerPtr_->impl_.backupExtNameMap.clear();
|
||||
sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = info;
|
||||
|
@ -162,11 +162,26 @@ ErrCode ServiceProxy::UpdateTimer(BundleName &bundleName, uint32_t timeOut, bool
|
||||
return BError(BError::Codes::OK);
|
||||
}
|
||||
|
||||
ErrCode ServiceProxy::StartExtTimer(bool &isExtStart)
|
||||
{
|
||||
return BError(BError::Codes::OK);
|
||||
}
|
||||
|
||||
ErrCode ServiceProxy::StartFwkTimer(bool &isFwkStart)
|
||||
{
|
||||
return BError(BError::Codes::OK);
|
||||
}
|
||||
|
||||
ErrCode ServiceProxy::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result)
|
||||
{
|
||||
return BError(BError::Codes::OK);
|
||||
}
|
||||
|
||||
ErrCode ServiceProxy::ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario)
|
||||
{
|
||||
return BError(BError::Codes::OK);
|
||||
}
|
||||
|
||||
sptr<IService> ServiceProxy::GetInstance()
|
||||
{
|
||||
return serviceProxy_;
|
||||
|
@ -219,7 +219,7 @@ static void OnResultReport(shared_ptr<SessionRestore> ctx, const std::string &bu
|
||||
printf("OnResultReport bundleName = %s, resultInfo = %s\n", bundleName.c_str(), resultInfo.c_str());
|
||||
}
|
||||
|
||||
static void OnProcess(shared_ptr<Session> ctx, const std::string bundleName, const std::string processInfo)
|
||||
static void OnProcess(shared_ptr<SessionRestore> ctx, const std::string bundleName, const std::string processInfo)
|
||||
{
|
||||
printf("OnProcess bundleName = %s, processInfo = %s\n", bundleName.c_str(), processInfo.c_str());
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ static void OnBackupServiceDied(shared_ptr<SessionAsync> ctx)
|
||||
ctx->TryNotify(true);
|
||||
}
|
||||
|
||||
static void OnProcess(shared_ptr<Session> ctx, const std::string bundleName, const std::string processInfo)
|
||||
static void OnProcess(shared_ptr<SessionAsync> ctx, const std::string bundleName, const std::string processInfo)
|
||||
{
|
||||
printf("OnProcess bundleName = %s, processInfo = %s\n", bundleName.c_str(), processInfo.c_str());
|
||||
}
|
||||
|
@ -77,6 +77,7 @@ ohos_shared_library("backup_utils") {
|
||||
"src/b_sa/b_sa_utils.cpp",
|
||||
"src/b_tarball/b_tarball_cmdline.cpp",
|
||||
"src/b_tarball/b_tarball_factory.cpp",
|
||||
"src/b_utils/b_time.cpp",
|
||||
]
|
||||
|
||||
configs = [ ":utils_private_config" ]
|
||||
|
@ -126,11 +126,6 @@ public:
|
||||
*
|
||||
*/
|
||||
static bool BuildOnProcessRetInfo(std::string &jsonStr, std::string onProcessRet);
|
||||
|
||||
/**
|
||||
* @brief 生成当前时间的时间戳字符串
|
||||
*/
|
||||
static std::string GetCurrentTimeInfo();
|
||||
};
|
||||
} // namespace OHOS::FileManagement::Backup
|
||||
|
||||
|
@ -77,6 +77,7 @@ constexpr int MAX_FD_SEND_RATE = 800; // 允许应用申请的最大FD数量
|
||||
constexpr int MIN_FD_SEND_RATE = 0; // 允许应用申请的最小FD数量
|
||||
constexpr int DEFAULT_FD_SEND_RATE = 60; // 框架默认的FD数量
|
||||
constexpr int32_t PARAM_STARING_MAX_MEMORY = 2 * 1024 * 1024;
|
||||
constexpr uint32_t H2MS = 60 * 60 * 1000;
|
||||
|
||||
constexpr int CALL_APP_ON_PROCESS_TIME_INTERVAL = 5; // 框架每隔5s去调用应用的onProcess
|
||||
constexpr int APP_ON_PROCESS_MAX_TIMEOUT = 1000; // 应用的onProcess接口最大超时时间为1秒
|
||||
|
@ -25,5 +25,5 @@ public:
|
||||
static bool CheckPermission(const std::string &permission);
|
||||
static bool IsSystemApp();
|
||||
};
|
||||
} // namespace OHOS::FileManagement::Backup::BEncryption
|
||||
} // namespace OHOS::FileManagement::Backup::SAUtils
|
||||
#endif // OHOS_FILEMGMT_BACKUP_B_SA_H
|
28
utils/include/b_utils/b_time.h
Normal file
28
utils/include/b_utils/b_time.h
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_FILEMGMT_BACKUP_B_TIME_H
|
||||
#define OHOS_FILEMGMT_BACKUP_B_TIME_H
|
||||
#include <string>
|
||||
|
||||
namespace OHOS::FileManagement::Backup {
|
||||
class TimeUtils {
|
||||
public:
|
||||
static int64_t GetTimeS();
|
||||
static int64_t GetTimeMS();
|
||||
static int64_t GetTimeUS();
|
||||
};
|
||||
} // namespace OHOS::FileManagement::TimeUtils
|
||||
#endif // OHOS_FILEMGMT_BACKUP_B_TIME_H
|
@ -23,7 +23,7 @@
|
||||
|
||||
#include "b_error/b_error.h"
|
||||
#include "filemgmt_libhilog.h"
|
||||
#include "b_jsonutil.h"
|
||||
#include "b_utils/b_time.h"
|
||||
|
||||
namespace OHOS::FileManagement::Backup {
|
||||
using namespace std;
|
||||
@ -250,18 +250,15 @@ bool OHOS::FileManagement::Backup::BJsonUtil::BuildOnProcessRetInfo(std::string
|
||||
if (info == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
cJSON *processInfo = cJSON_CreateObject();
|
||||
if (processInfo == nullptr) {
|
||||
cJSON_Delete(info);
|
||||
return false;
|
||||
}
|
||||
std::string timeInfo = GetCurrentTimeInfo();
|
||||
std::string timeInfo = std::to_string(TimeUtils::GetTimeS());
|
||||
cJSON_AddStringToObject(processInfo, "timeInfo", timeInfo.c_str());
|
||||
cJSON_AddStringToObject(processInfo, "resultInfo", onProcessRet.c_str());
|
||||
|
||||
cJSON_AddItemToObject(info, "processResult", processInfo);
|
||||
|
||||
char *data = cJSON_Print(info);
|
||||
if (data == nullptr) {
|
||||
cJSON_Delete(info);
|
||||
@ -272,13 +269,3 @@ bool OHOS::FileManagement::Backup::BJsonUtil::BuildOnProcessRetInfo(std::string
|
||||
cJSON_free(data);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string OHOS::FileManagement::Backup::BJsonUtil::GetCurrentTimeInfo()
|
||||
{
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto timePoint = std::chrono::system_clock::to_time_t(now);
|
||||
std::stringstream timestream;
|
||||
timestream << std::put_time(std::localtime(&timePoint), "%Y-%m-%d %H:%M:%S");
|
||||
std::string result = timestream.str();
|
||||
return result;
|
||||
}
|
||||
|
40
utils/src/b_utils/b_time.cpp
Normal file
40
utils/src/b_utils/b_time.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 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 "b_utils/b_time.h"
|
||||
#include <chrono>
|
||||
|
||||
namespace OHOS::FileManagement::Backup {
|
||||
int64_t TimeUtils::GetTimeS()
|
||||
{
|
||||
std::chrono::seconds nowS = std::chrono::duration_cast<std::chrono::seconds>(
|
||||
std::chrono::system_clock::now().time_since_epoch());
|
||||
return nowS.count();
|
||||
}
|
||||
|
||||
int64_t TimeUtils::GetTimeMS()
|
||||
{
|
||||
std::chrono::milliseconds nowMs = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::system_clock::now().time_since_epoch());
|
||||
return nowMs.count();
|
||||
}
|
||||
|
||||
int64_t TimeUtils::GetTimeUS()
|
||||
{
|
||||
std::chrono::microseconds nowUs = std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::system_clock::now().time_since_epoch());
|
||||
return nowUs.count();
|
||||
}
|
||||
} // namespace OHOS::FileManagement::Backup
|
Loading…
Reference in New Issue
Block a user