diff --git a/frameworks/native/backup_ext/src/ext_backup.cpp b/frameworks/native/backup_ext/src/ext_backup.cpp index 92e37c8b70cca78cc93f9781285974a70d349fb6..e75dcf5f8a792c6627b77713975cc0495c2ed649 100644 --- a/frameworks/native/backup_ext/src/ext_backup.cpp +++ b/frameworks/native/backup_ext/src/ext_backup.cpp @@ -238,6 +238,10 @@ void ExtBackup::OnDisconnect(const AAFwk::Want &want) bool ExtBackup::WasFromSpecialVersion(void) { + if (appVersionStr_.empty()) { + HILOGE("App version name is empty"); + return false; + } std::string appVersionFlag_ = appVersionStr_.substr(0, appVersionStr_.find_first_of(BConstants::VERSION_NAME_SEPARATOR_CHAR)); if (appVersionFlag_ == BConstants::DEFAULT_VERSION_NAME) { @@ -248,6 +252,10 @@ bool ExtBackup::WasFromSpecialVersion(void) bool ExtBackup::SpecialVersionForCloneAndCloud(void) { + if (appVersionStr_.empty()) { + HILOGE("App version name is empty"); + return false; + } std::string appVersionFlag_ = appVersionStr_.substr(0, appVersionStr_.find_first_of(BConstants::VERSION_NAME_SEPARATOR_CHAR)); auto iter = diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index d539c3840f1d3bdcce287459b12b6099e7ada711..fef2dbdbb2055acbcb547e729de987dffac45942 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -574,6 +574,12 @@ private: void SetUserIdAndRestoreType(RestoreTypeEnum restoreType, int32_t userId); ErrCode VerifySendRateParam(); + + ErrCode HandleCurBundleFileReady(const std::string &bundleName, const std::string &fileName, bool isIncBackup); + + ErrCode HandleCurAppDone(ErrCode errCode, const std::string &bundleName, bool isIncBackup); + + void StartCurBundleBackupOrRestore(const std::string &bundleName); private: static sptr instance_; static std::mutex instanceLock_; diff --git a/services/backup_sa/include/module_ipc/svc_session_manager.h b/services/backup_sa/include/module_ipc/svc_session_manager.h index 51b13b07e3dec52b377c4238becdf28126e0390e..e124e9b094f966ec849894de1af27d7dbc591dc0 100644 --- a/services/backup_sa/include/module_ipc/svc_session_manager.h +++ b/services/backup_sa/include/module_ipc/svc_session_manager.h @@ -100,8 +100,8 @@ public: * * @param clientToken 调用者TOKEN * @param scenario 给定场景 - * @throw BError::Codes::SA_REFUSED_ACT 调用者不是会话所有者 - * @throw BError::Codes::SDK_MIXED_SCENARIO 调用者在备份/恢复场景使用了不匹配的函数 + * + * @return ErrCode 错误码 */ ErrCode VerifyCallerAndScenario(uint32_t clientToken, IServiceReverse::Scenario scenario) const; @@ -110,6 +110,8 @@ public: * * @param impl 客户端信息 * @param isOccupyingSession 框架是否自占用session + * + * @return ErrCode 错误码 */ ErrCode Active(Impl newImpl, bool isOccupyingSession = false); @@ -118,6 +120,8 @@ public: * * @param remoteInAction 尝试关闭会话的客户端代理。只有激活会话的客户端代理有权关闭会话 * @param force 强制关闭 + * + * @return ErrCode 错误码 */ ErrCode Deactive(const wptr &remoteInAction, bool force = false); @@ -125,7 +129,7 @@ public: * @brief 检验调用者给定的bundleName是否是有效的 * * @param bundleName 调用者名称 - * @throw BError::Codes::SA_REFUSED_ACT 调用者不是会话所有者 + * @return ErrCode 调用者不是会话所有者 */ ErrCode VerifyBundleName(std::string &bundleName); @@ -560,7 +564,7 @@ private: * @param bundleName 应用名称 * @return std::map::iterator */ - std::map::iterator GetBackupExtNameMap(const std::string &bundleName); + std::tuple::iterator> GetBackupExtNameMap(const std::string &bundleName); /** * @brief 计算出应用程序处理数据可能使用的时间 diff --git a/services/backup_sa/include/module_sched/sched_scheduler.h b/services/backup_sa/include/module_sched/sched_scheduler.h index 74784e47ce593d5ee316ad86c585313c4537b5f2..5d7a8c4ad45bb8c3f6960af53fcd61774c333cf4 100644 --- a/services/backup_sa/include/module_sched/sched_scheduler.h +++ b/services/backup_sa/include/module_sched/sched_scheduler.h @@ -74,6 +74,8 @@ public: void StartTimer(); + void StartExecuteBundleTask(const std::string &bundleName, BConstants::ServiceSchedAction action); + public: explicit SchedScheduler(wptr reversePtr, wptr sessionPtr) : reversePtr_(reversePtr), sessionPtr_(sessionPtr) diff --git a/services/backup_sa/src/module_external/bms_adapter.cpp b/services/backup_sa/src/module_external/bms_adapter.cpp index e8322327c7c8df0e7560336007b8dd6c5d66e646..9a80425a0d9a38973e9d5141cc2b5113a8a94373 100644 --- a/services/backup_sa/src/module_external/bms_adapter.cpp +++ b/services/backup_sa/src/module_external/bms_adapter.cpp @@ -343,7 +343,8 @@ vector BundleMgrAdapter::GetBundleInfosForIncrement HILOGI("Begin get bundle infos"); auto bms = GetBundleManager(); if (!bms->GetBundleInfos(AppExecFwk::GET_BUNDLE_WITH_EXTENSION_INFO, installedBundles, userId)) { - throw BError(BError::Codes::SA_BROKEN_IPC, "Failed to get bundle infos"); + HILOGE("Failed to get bundle infos from bms"); + return {}; } vector bundleNames; @@ -387,12 +388,17 @@ vector BundleMgrAdapter::GetFullBundleInfos(int32_t HILOGI("Begin GetFullBundleInfos"); auto bms = GetBundleManager(); if (!bms->GetBundleInfos(AppExecFwk::GET_BUNDLE_WITH_EXTENSION_INFO, installedBundles, userId)) { - throw BError(BError::Codes::SA_BROKEN_IPC, "Failed to get bundle infos"); + HILOGE("Failed to get bundle infos from bms"); + return {}; } vector bundleNames; vector bundleInfos; HILOGI("End get installedBundles count is:%{public}zu", installedBundles.size()); for (auto const &installedBundle : installedBundles) { + if (installedBundle.name.empty()) { + HILOGE("Current bundle name is invalid"); + continue; + } if (installedBundle.applicationInfo.codePath == HMOS_HAP_CODE_PATH || installedBundle.applicationInfo.codePath == LINUX_HAP_CODE_PATH) { HILOGI("Unsupported applications, name : %{public}s", installedBundle.name.data()); diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 335987159e9409bac0c6eb5ed87bd9907573795c..50ac3c848ae1cd83764ca332fbb6b53c46ae7ad6 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -986,7 +986,7 @@ void Service::NotifyCloneBundleFinish(std::string bundleName, const BackupRestor RemoveExtensionMutex(bundleName); OnAllBundlesFinished(BError(BError::Codes::OK)); } catch (...) { - HILOGI("Unexpected exception"); + HILOGE("Unexpected exception"); ReleaseOnException(); } } @@ -1029,6 +1029,10 @@ ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) return BError(BError::Codes::OK); } auto action = session_->GetServiceSchedAction(bundleName); + if (action == BConstants::ServiceSchedAction::UNKNOWN) { + HILOGE("action is unknown, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } if (action == BConstants::ServiceSchedAction::RUNNING) { auto backUpConnection = session_->GetExtConnection(bundleName); if (backUpConnection == nullptr) { @@ -1070,28 +1074,51 @@ void Service::ExtStart(const string &bundleName) if (IncrementalBackup(bundleName)) { return; } - IServiceReverse::Scenario scenario = session_->GetScenario(); - auto backUpConnection = session_->GetExtConnection(bundleName); - if (backUpConnection == nullptr) { - throw BError(BError::Codes::SA_INVAL_ARG, "ExtStart bundle task error, backUpConnection is empty"); - } - auto proxy = backUpConnection->GetBackupExtProxy(); - if (!proxy) { - throw BError(BError::Codes::SA_INVAL_ARG, "ExtStart bundle task error, Extension backup Proxy is empty"); + StartCurBundleBackupOrRestore(bundleName); + } catch (...) { + HILOGE("Unexpected exception, bundleName: %{public}s", bundleName.c_str()); + ClearSessionAndSchedInfo(bundleName); + NoticeClientFinish(bundleName, BError(BError::Codes::SA_INVAL_ARG)); + } +} + +void Service::StartCurBundleBackupOrRestore(const std::string &bundleName) +{ + HILOGI("Begin handle current bundle full backup or full restore, bundleName:%{public}s", bundleName.c_str()); + IServiceReverse::Scenario scenario = session_->GetScenario(); + auto backUpConnection = session_->GetExtConnection(bundleName); + if (backUpConnection == nullptr) { + HILOGE("Error, backUpConnection is empty, bundle:%{public}s", bundleName.c_str()); + if (scenario == IServiceReverse::Scenario::BACKUP) { + session_->GetServiceReverseProxy()->BackupOnBundleStarted(BError(BError::Codes::SA_INVAL_ARG), + bundleName); + } else if (scenario == IServiceReverse::Scenario::RESTORE) { + session_->GetServiceReverseProxy()->RestoreOnBundleStarted(BError(BError::Codes::SA_INVAL_ARG), + bundleName); } + return; + } + auto proxy = backUpConnection->GetBackupExtProxy(); + if (proxy == nullptr) { + HILOGE("Error, Extension backup Proxy is empty, bundle:%{public}s", bundleName.c_str()); if (scenario == IServiceReverse::Scenario::BACKUP) { - auto ret = proxy->HandleBackup(session_->GetClearDataFlag(bundleName)); - session_->GetServiceReverseProxy()->BackupOnBundleStarted(ret, bundleName); - BundleBeginRadarReport(bundleName, ret, scenario); - if (ret) { - ClearSessionAndSchedInfo(bundleName); - NoticeClientFinish(bundleName, BError(BError::Codes::SA_INVAL_ARG)); - } - return; + session_->GetServiceReverseProxy()->BackupOnBundleStarted(BError(BError::Codes::SA_INVAL_ARG), + bundleName); + } else if (scenario == IServiceReverse::Scenario::RESTORE) { + session_->GetServiceReverseProxy()->RestoreOnBundleStarted(BError(BError::Codes::SA_INVAL_ARG), + bundleName); } - if (scenario != IServiceReverse::Scenario::RESTORE) { - throw BError(BError::Codes::SA_INVAL_ARG, "Failed to scenario"); + return; + } + if (scenario == IServiceReverse::Scenario::BACKUP) { + auto ret = proxy->HandleBackup(session_->GetClearDataFlag(bundleName)); + session_->GetServiceReverseProxy()->BackupOnBundleStarted(ret, bundleName); + BundleBeginRadarReport(bundleName, ret, scenario); + if (ret) { + ClearSessionAndSchedInfo(bundleName); + NoticeClientFinish(bundleName, BError(BError::Codes::SA_INVAL_ARG)); } + } else if (scenario == IServiceReverse::Scenario::RESTORE) { auto ret = proxy->HandleRestore(session_->GetClearDataFlag(bundleName)); session_->GetServiceReverseProxy()->RestoreOnBundleStarted(ret, bundleName); GetOldDeviceBackupVersion(); @@ -1103,11 +1130,8 @@ void Service::ExtStart(const string &bundleName) session_->GetServiceReverseProxy()->RestoreOnFileReady(bundleName, fileName, move(fd), errCode); FileReadyRadarReport(bundleName, fileName, errCode, scenario); } - } catch (...) { - HILOGI("Unexpected exception, bundleName: %{public}s", bundleName.c_str()); - ClearSessionAndSchedInfo(bundleName); - NoticeClientFinish(bundleName, BError(BError::Codes::SA_INVAL_ARG)); } + HILOGI("End handle current bundle full backup or full restore, bundleName:%{public}s", bundleName.c_str()); } int Service::Dump(int fd, const vector &args) @@ -1167,12 +1191,10 @@ void Service::ExtConnectFailed(const string &bundleName, ErrCode ret) NoticeClientFinish(bundleName, BError(BError::Codes::EXT_ABILITY_DIED)); return; } catch (const BError &e) { - return; - } catch (const exception &e) { - HILOGI("Catched an unexpected low-level exception %{public}s", e.what()); + HILOGE("ExtConnectFailed exception, bundleName:%{public}s", bundleName.c_str()); return; } catch (...) { - HILOGI("Unexpected exception"); + HILOGE("Unexpected exception"); return; } } @@ -1193,8 +1215,13 @@ void Service::ExtConnectDone(string bundleName) HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { HILOGE("begin %{public}s", bundleName.data()); - BConstants::ServiceSchedAction curSchedAction = session_->GetServiceSchedAction(bundleName); + if (curSchedAction == BConstants::ServiceSchedAction::UNKNOWN) { + HILOGE("Can not find bundle from this session, bundleName:%{public}s", bundleName.c_str()); + ClearSessionAndSchedInfo(bundleName); + NoticeClientFinish(bundleName, BError(BError::Codes::SA_REFUSED_ACT)); + return; + } if (curSchedAction == BConstants::ServiceSchedAction::CLEAN) { sched_->Sched(bundleName); return; @@ -1234,12 +1261,10 @@ void Service::ClearSessionAndSchedInfo(const string &bundleName) sched_->Sched(); } } catch (const BError &e) { - return; - } catch (const exception &e) { - HILOGI("Catched an unexpected low-level exception %{public}s", e.what()); + HILOGE("ClearSessionAndSchedInfo exception"); return; } catch (...) { - HILOGI("Unexpected exception"); + HILOGE("Unexpected exception"); return; } } @@ -1584,8 +1609,8 @@ ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); return ret; } catch (...) { + HILOGE("Unexpected exception"); session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); - HILOGI("Unexpected exception"); return EPERM; } } @@ -1614,9 +1639,9 @@ ErrCode Service::StartExtTimer(bool &isExtStart) session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); return BError(BError::Codes::OK); } catch (...) { + HILOGE("Unexpected exception"); isExtStart = false; session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); - HILOGI("Unexpected exception"); return EPERM; } } @@ -1645,9 +1670,9 @@ ErrCode Service::StartFwkTimer(bool &isFwkStart) session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); return BError(BError::Codes::OK); } catch (...) { + HILOGE("Unexpected exception"); isFwkStart = false; session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); - HILOGI("Unexpected exception"); return EPERM; } } @@ -1685,15 +1710,10 @@ ErrCode Service::AppendBundlesClearSession(const std::vector &bundle session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); return BError(BError::Codes::OK); } catch (const BError &e) { - HandleExceptionOnAppendBundles(session_, bundleNames, {}); - session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); HILOGE("Failed, errCode = %{public}d", e.GetCode()); - return e.GetCode(); - } catch (const exception &e) { HandleExceptionOnAppendBundles(session_, bundleNames, {}); session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); - HILOGE("Catched an unexpected low-level exception %{public}s", e.what()); - return EPERM; + return e.GetCode(); } catch (...) { HILOGE("Unexpected exception"); HandleExceptionOnAppendBundles(session_, bundleNames, {}); @@ -1714,7 +1734,7 @@ ErrCode Service::UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &res session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); ErrCode ret = VerifyCaller(); if (ret != ERR_OK) { - HILOGE("Update timer failed, verify caller failed"); + HILOGE("Update timer failed, verify caller failed, bundleName:%{public}s", bundleName.c_str()); result = false; session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); return ret; @@ -1724,9 +1744,9 @@ ErrCode Service::UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &res session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); return BError(BError::Codes::OK); } catch (...) { + HILOGE("Unexpected exception"); result = false; session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); - HILOGI("Unexpected exception"); return EPERM; } } @@ -1932,9 +1952,10 @@ ErrCode Service::ReportAppProcessInfo(const std::string processInfo, BackupResto } return BError(BError::Codes::OK); } catch (const BError &e) { - return e.GetCode(); // 任意异常产生,终止监听该任务 + HILOGE("ReportAppProcessInfo exception"); + return e.GetCode(); } catch (const exception &e) { - HILOGI("Catched an unexpected low-level exception %{public}s", e.what()); + HILOGE("Catched an unexpected low-level exception %{public}s", e.what()); return EPERM; } } @@ -2045,15 +2066,12 @@ void Service::DelClearBundleRecord(const std::vector &bundleNames) void Service::ReleaseOnException() { - try { - if (session_->IsOnAllBundlesFinished()) { - IServiceReverse::Scenario scenario = session_->GetScenario(); - if (isInRelease_.load() && (scenario == IServiceReverse::Scenario::RESTORE)) { - SessionDeactive(); - } + if (session_->IsOnAllBundlesFinished()) { + IServiceReverse::Scenario scenario = session_->GetScenario(); + if (isInRelease_.load() && (scenario == IServiceReverse::Scenario::RESTORE)) { + HILOGI("Will execute destory session info"); + SessionDeactive(); } - } catch (...) { - HILOGE("Unexpected exception"); } } diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index 37f3063729ceed88d96430ddf47a8d5d2c882c2a..cc77b39cb23d71ef1260429344db18785d8fbb19 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -183,8 +183,8 @@ UniqueFd Service::GetLocalCapabilitiesIncremental(const std::vectorDecreaseSessionCnt(__PRETTY_FUNCTION__); - HILOGI("Unexpected exception"); return UniqueFd(-EPERM); } } @@ -289,17 +289,15 @@ ErrCode Service::GetAppLocalListAndDoIncrementalBackup() task(); } catch (const BError &e) { HILOGE("GetAppLocalListAndDoIncrementalBackup failed, errCode = %{public}d", e.GetCode()); - } catch (const exception &e) { - HILOGI("Catched an unexpected low-level exception %{public}s", e.what()); } catch (...) { - HILOGI("Unexpected exception"); + HILOGE("Unexpected exception"); } }); session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); return BError(BError::Codes::OK); } catch (const BError &e) { - session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); HILOGE("GetAppLocalListAndDoIncrementalBackup failed, errCode = %{public}d", e.GetCode()); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); return e.GetCode(); } catch (...) { HILOGE("Unexpected exception"); @@ -372,14 +370,14 @@ ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vectorDecreaseSessionCnt(__PRETTY_FUNCTION__); return BError(BError::Codes::OK); } catch (const BError &e) { + HILOGE("Failed, errCode = %{public}d", e.GetCode()); HandleExceptionOnAppendBundles(session_, bundleNames, {}); session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); - HILOGE("Failed, errCode = %{public}d", e.GetCode()); return e.GetCode(); } catch (...) { + HILOGE("Unexpected exception"); HandleExceptionOnAppendBundles(session_, bundleNames, {}); session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); - HILOGI("Unexpected exception"); return EPERM; } } @@ -418,14 +416,14 @@ ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vectorDecreaseSessionCnt(__PRETTY_FUNCTION__); return BError(BError::Codes::OK); } catch (const BError &e) { + HILOGE("Failed, errCode = %{public}d", e.GetCode()); HandleExceptionOnAppendBundles(session_, bundleNames, {}); session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); - HILOGE("Failed, errCode = %{public}d", e.GetCode()); return e.GetCode(); } catch (...) { + HILOGE("Unexpected exception"); HandleExceptionOnAppendBundles(session_, bundleNames, {}); session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); - HILOGI("Unexpected exception"); return EPERM; } } @@ -522,34 +520,20 @@ ErrCode Service::AppIncrementalFileReady(const std::string &bundleName, const st move(manifestFd), errCode); FileReadyRadarReport(bundleName, fileName, errCode, IServiceReverse::Scenario::BACKUP); if (session_->OnBundleFileReady(bundleName, fileName)) { - auto backUpConnection = session_->GetExtConnection(bundleName); - if (backUpConnection == nullptr) { - return BError(BError::Codes::SA_INVAL_ARG, "backup connection is empty"); - } - auto proxy = backUpConnection->GetBackupExtProxy(); - if (!proxy) { - return BError(BError::Codes::SA_INVAL_ARG, "Extension backup Proxy is empty"); + ErrCode ret = HandleCurBundleFileReady(bundleName, fileName, true); + if (ret != ERR_OK) { + HILOGE("Handle current file failed, bundleName:%{public}s, fileName:%{public}s", + bundleName.c_str(), GetAnonyPath(fileName).c_str()); + return ret; } - // 通知extension清空缓存 - proxy->HandleClear(); - // 清除Timer - session_->StopFwkTimer(bundleName); - session_->StopExtTimer(bundleName); - // 通知TOOL 备份完成 - HILOGI("reverse: Will notify IncrementalBackupOnBundleFinished"); - session_->GetServiceReverseProxy()->IncrementalBackupOnBundleFinished(BError(BError::Codes::OK), - bundleName); - BundleEndRadarReport(bundleName, BError(BError::Codes::OK), IServiceReverse::Scenario::BACKUP); - // 断开extension - backUpConnection->DisconnectBackupExtAbility(); - ClearSessionAndSchedInfo(bundleName); } OnAllBundlesFinished(BError(BError::Codes::OK)); return BError(BError::Codes::OK); } catch (const BError &e) { + HILOGE("AppIncrementalFileReady exception"); return e.GetCode(); // 任意异常产生,终止监听该任务 } catch (...) { - HILOGI("Unexpected exception"); + HILOGE("Unexpected exception"); return EPERM; } } @@ -577,32 +561,21 @@ ErrCode Service::AppIncrementalFileReady(const std::string &fileName, UniqueFd f move(manifestFd), errCode); FileReadyRadarReport(callerName, fileName, errCode, IServiceReverse::Scenario::BACKUP); if (session_->OnBundleFileReady(callerName, fileName)) { - auto backUpConnection = session_->GetExtConnection(callerName); - if (backUpConnection == nullptr) { - return BError(BError::Codes::SA_INVAL_ARG, "Extension backup connection is empty"); + ErrCode ret = HandleCurBundleFileReady(callerName, fileName, true); + if (ret != ERR_OK) { + HILOGE("Handle current file failed, bundleName:%{public}s, fileName:%{public}s", + callerName.c_str(), GetAnonyPath(fileName).c_str()); + return ret; } - auto proxy = backUpConnection->GetBackupExtProxy(); - if (!proxy) { - throw BError(BError::Codes::SA_INVAL_ARG, "Extension backup Proxy is empty"); - } - // 通知extension清空缓存 - proxy->HandleClear(); - // 清除Timer - session_->StopFwkTimer(callerName); - session_->StopExtTimer(callerName); - // 通知TOOL 备份完成 - HILOGI("reverse: Will notify IncrementalBackupOnBundleFinished"); - session_->GetServiceReverseProxy()->IncrementalBackupOnBundleFinished(BError(BError::Codes::OK), - callerName); - BundleEndRadarReport(callerName, BError(BError::Codes::OK), IServiceReverse::Scenario::BACKUP); - // 断开extension - backUpConnection->DisconnectBackupExtAbility(); - ClearSessionAndSchedInfo(callerName); } OnAllBundlesFinished(BError(BError::Codes::OK)); return BError(BError::Codes::OK); } catch (const BError &e) { + HILOGE("AppIncrementalFileReady exception"); return e.GetCode(); // 任意异常产生,终止监听该任务 + } catch (...) { + HILOGE("Unexpected exception"); + return EPERM; } } @@ -620,27 +593,20 @@ ErrCode Service::AppIncrementalDone(ErrCode errCode) HILOGE("App incremental done fail, ret:%{public}d", ret); return ret; } - HILOGI("Begin, callerName is %{public}s, errCode is: %{public}d", callerName.c_str(), errCode); + HILOGI("Service AppIncrementalDone start, callerName is %{public}s, errCode is: %{public}d", + callerName.c_str(), errCode); if (session_->OnBundleFileReady(callerName) || errCode != BError(BError::Codes::OK)) { std::shared_ptr mutexPtr = GetExtensionMutex(callerName); if (mutexPtr == nullptr) { - return BError(BError::Codes::SA_INVAL_ARG, "Extension mutex ptr is null."); + HILOGE("extension mutex ptr is nullptr, bundleName:%{public}s", callerName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); } std::lock_guard lock(mutexPtr->callbackMutex); - auto backUpConnection = session_->GetExtConnection(callerName); - if (backUpConnection == nullptr) { - return BError(BError::Codes::SA_INVAL_ARG, "Promote backUpConnection ptr is null."); - } - auto proxy = backUpConnection->GetBackupExtProxy(); - if (!proxy) { - return BError(BError::Codes::SA_INVAL_ARG, "Extension backup Proxy is empty"); + ret = HandleCurAppDone(errCode, callerName, true); + if (ret != ERR_OK) { + HILOGE("Handle current app done error, bundleName:%{public}s", callerName.c_str()); + return ret; } - proxy->HandleClear(); - session_->StopFwkTimer(callerName); - session_->StopExtTimer(callerName); - backUpConnection->DisconnectBackupExtAbility(); - ClearSessionAndSchedInfo(callerName); - NotifyCallerCurAppIncrementDone(errCode, callerName); } RemoveExtensionMutex(callerName); OnAllBundlesFinished(BError(BError::Codes::OK)); @@ -671,6 +637,10 @@ ErrCode Service::GetIncrementalFileHandle(const std::string &bundleName, const s return ret; } auto action = session_->GetServiceSchedAction(bundleName); + if (action == BConstants::ServiceSchedAction::UNKNOWN) { + HILOGE("action is unknown, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } if (action == BConstants::ServiceSchedAction::RUNNING) { auto backUpConnection = session_->GetExtConnection(bundleName); if (backUpConnection == nullptr) { @@ -685,7 +655,8 @@ ErrCode Service::GetIncrementalFileHandle(const std::string &bundleName, const s auto[errCode, fd, reportFd] = proxy->GetIncrementalFileHandle(fileName); auto err = AppIncrementalFileReady(bundleName, fileName, move(fd), move(reportFd), errCode); if (err != ERR_OK) { - HILOGE("Failed to send file handle"); + HILOGE("Failed to send file handle, bundleName:%{public}s, fileName:%{public}s", + bundleName.c_str(), GetAnonyPath(fileName).c_str()); AppRadar::Info info (bundleName, "", ""); AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::GetIncrementalFileHandle", GetUserIdDefault(), BizStageRestore::BIZ_STAGE_GET_FILE_HANDLE_FAIL, err); @@ -696,10 +667,8 @@ ErrCode Service::GetIncrementalFileHandle(const std::string &bundleName, const s } return BError(BError::Codes::OK); } catch (const BError &e) { + HILOGE("GetIncrementalFileHandle exception, bundleName:%{public}s", bundleName.c_str()); return e.GetCode(); - } catch (...) { - HILOGI("Unexpected exception"); - return EPERM; } } @@ -914,6 +883,11 @@ ErrCode Service::Cancel(std::string bundleName, int32_t &result) return BError(BError::Codes::OK); } auto action = session_->GetServiceSchedAction(bundleName); + if (action == BConstants::ServiceSchedAction::UNKNOWN) { + HILOGE("action is unknown, bundleName:%{public}s", bundleName.c_str()); + result = BError::BackupErrorCode::E_CANCEL_NO_TASK; + return BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK); + } auto task = [this, bundleName]() { try { CancelTask(bundleName, wptr(this)); diff --git a/services/backup_sa/src/module_ipc/sub_service.cpp b/services/backup_sa/src/module_ipc/sub_service.cpp index 23e3a9d86e7951be81fa760f9aceb05deae90bf2..71f25b5ac465dea39c82dca2109839c3d265c900 100644 --- a/services/backup_sa/src/module_ipc/sub_service.cpp +++ b/services/backup_sa/src/module_ipc/sub_service.cpp @@ -148,7 +148,7 @@ ErrCode Service::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCo return ret; } if (fileName.find('/') != string::npos) { - HILOGE("AppFileReady error, Filename is not valid, fileName:%{public}s", GetAnonyPath(fileName).c_str()); + HILOGE("AppFileReady error, filename is not valid, fileName:%{public}s", GetAnonyPath(fileName).c_str()); return BError(BError::Codes::SA_INVAL_ARG); } if (fileName == BConstants::EXT_BACKUP_MANAGE) { @@ -157,34 +157,19 @@ ErrCode Service::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCo session_->GetServiceReverseProxy()->BackupOnFileReady(callerName, fileName, move(fd), errCode); FileReadyRadarReport(callerName, fileName, errCode, session_->GetScenario()); if (session_->OnBundleFileReady(callerName, fileName)) { - auto backUpConnection = session_->GetExtConnection(callerName); - if (backUpConnection == nullptr) { - HILOGE("AppFileReady error, backUpConnection is empty"); - return BError(BError::Codes::SA_INVAL_ARG); - } - auto proxy = backUpConnection->GetBackupExtProxy(); - if (!proxy) { - HILOGE("AppFileReady error, Extension backup Proxy is empty"); - return BError(BError::Codes::SA_INVAL_ARG); + ret = HandleCurBundleFileReady(callerName, fileName, false); + if (ret != ERR_OK) { + HILOGE("Handle current bundle file failed, bundleName:%{public}s, fileName:%{public}s", + callerName.c_str(), GetAnonyPath(fileName).c_str()); + return ret; } - // 通知extension清空缓存 - proxy->HandleClear(); - // 清除Timer - session_->StopFwkTimer(callerName); - session_->StopExtTimer(callerName); - // 通知TOOL 备份完成 - session_->GetServiceReverseProxy()->BackupOnBundleFinished(BError(BError::Codes::OK), callerName); - BundleEndRadarReport(callerName, BError(BError::Codes::OK), session_->GetScenario()); - // 断开extension - backUpConnection->DisconnectBackupExtAbility(); - ClearSessionAndSchedInfo(callerName); } OnAllBundlesFinished(BError(BError::Codes::OK)); return BError(BError::Codes::OK); } catch (const BError &e) { return e.GetCode(); // 任意异常产生,终止监听该任务 } catch (...) { - HILOGI("Unexpected exception"); + HILOGE("Unexpected exception"); return EPERM; } } @@ -207,24 +192,15 @@ ErrCode Service::AppDone(ErrCode errCode) if (session_->OnBundleFileReady(callerName) || errCode != BError(BError::Codes::OK)) { std::shared_ptr mutexPtr = GetExtensionMutex(callerName); if (mutexPtr == nullptr) { - HILOGE("extension mutex ptr is nullptr"); + HILOGE("extension mutex ptr is nullptr, bundleName:%{public}s", callerName.c_str()); return BError(BError::Codes::SA_INVAL_ARG); } std::lock_guard lock(mutexPtr->callbackMutex); - auto backUpConnection = session_->GetExtConnection(callerName); - if (backUpConnection == nullptr) { - return BError(BError::Codes::SA_INVAL_ARG, "App finish error, backUpConnection is empty"); + ret = HandleCurAppDone(errCode, callerName, false); + if (ret != ERR_OK) { + HILOGE("Handle current app done error, bundleName:%{public}s", callerName.c_str()); + return ret; } - auto proxy = backUpConnection->GetBackupExtProxy(); - if (!proxy) { - return BError(BError::Codes::SA_INVAL_ARG, "Extension backup Proxy is empty"); - } - proxy->HandleClear(); - session_->StopFwkTimer(callerName); - session_->StopExtTimer(callerName); - backUpConnection->DisconnectBackupExtAbility(); - ClearSessionAndSchedInfo(callerName); - NotifyCallerCurAppDone(errCode, callerName); } RemoveExtensionMutex(callerName); OnAllBundlesFinished(BError(BError::Codes::OK)); @@ -271,6 +247,10 @@ ErrCode Service::LaunchBackupExtension(const BundleName &bundleName) return BError(BError::Codes::SA_INVAL_ARG); } BConstants::ServiceSchedAction bundleAction = session_->GetServiceSchedAction(bundleName); + if (bundleAction == BConstants::ServiceSchedAction::UNKNOWN) { + HILOGE("action is unknown, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } ErrCode ret = backUpConnection->ConnectBackupExtAbility(want, session_->GetSessionUserId(), bundleAction == BConstants::ServiceSchedAction::CLEAN); if (ret != ERR_OK) { @@ -415,9 +395,9 @@ ErrCode Service::StopExtTimer(bool &isExtStop) session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); return BError(BError::Codes::OK); } catch (...) { + HILOGE("Unexpected exception"); isExtStop = false; session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); - HILOGI("Unexpected exception"); return EPERM; } } @@ -528,10 +508,12 @@ void Service::NoticeClientFinish(const string &bundleName, ErrCode errCode) /* If all bundle ext process finish, notice client. */ OnAllBundlesFinished(BError(BError::Codes::OK)); } catch(const BError &e) { + HILOGE("NoticeClientFinish exception, bundleName:%{public}s", bundleName.c_str()); ReleaseOnException(); + return; } catch (...) { + HILOGE("Unexpected exception"); ReleaseOnException(); - HILOGI("Unexpected exception"); return; } } @@ -543,6 +525,7 @@ void Service::OnAllBundlesFinished(ErrCode errCode) if (session_->IsOnAllBundlesFinished()) { IServiceReverse::Scenario scenario = session_->GetScenario(); if (isInRelease_.load() && (scenario == IServiceReverse::Scenario::RESTORE)) { + HILOGI("Will destory session info"); SessionDeactive(); } if (scenario == IServiceReverse::Scenario::BACKUP && session_->GetIsIncrementalBackup()) { @@ -557,6 +540,7 @@ void Service::OnAllBundlesFinished(ErrCode errCode) session_->GetServiceReverseProxy()->RestoreOnAllBundlesFinished(errCode); } if (!BackupPara().GetBackupOverrideBackupSARelease()) { + HILOGI("Will unload backup sa"); sched_->TryUnloadServiceTimer(true); } } @@ -577,4 +561,65 @@ ErrCode Service::VerifySendRateParam() } return BError(BError::Codes::OK); } + +ErrCode Service::HandleCurBundleFileReady(const std::string &bundleName, const std::string &fileName, bool isIncBackup) +{ + auto backUpConnection = session_->GetExtConnection(bundleName); + if (backUpConnection == nullptr) { + HILOGE("AppFileReady error, backUpConnection is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto proxy = backUpConnection->GetBackupExtProxy(); + if (!proxy) { + HILOGE("AppFileReady error, Extension backup Proxy is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + // 通知extension清空缓存 + proxy->HandleClear(); + // 清除Timer + session_->StopFwkTimer(bundleName); + session_->StopExtTimer(bundleName); + // 通知TOOL 备份完成 + if (isIncBackup) { + session_->GetServiceReverseProxy()->IncrementalBackupOnBundleFinished(BError(BError::Codes::OK), + bundleName); + BundleEndRadarReport(bundleName, BError(BError::Codes::OK), IServiceReverse::Scenario::BACKUP); + } else { + session_->GetServiceReverseProxy()->BackupOnBundleFinished(BError(BError::Codes::OK), bundleName); + BundleEndRadarReport(bundleName, BError(BError::Codes::OK), session_->GetScenario()); + } + // 断开extension + backUpConnection->DisconnectBackupExtAbility(); + ClearSessionAndSchedInfo(bundleName); + return BError(BError::Codes::OK); +} + +ErrCode Service::HandleCurAppDone(ErrCode errCode, const std::string &bundleName, bool isIncBackup) +{ + auto backUpConnection = session_->GetExtConnection(bundleName); + if (backUpConnection == nullptr) { + HILOGE("App finish error, backUpConnection is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto proxy = backUpConnection->GetBackupExtProxy(); + if (!proxy) { + HILOGE("App finish error, extension backup Proxy is empty, bundleName:%{public}s", bundleName.c_str()); + return BError(BError::Codes::SA_INVAL_ARG); + } + proxy->HandleClear(); + session_->StopFwkTimer(bundleName); + session_->StopExtTimer(bundleName); + backUpConnection->DisconnectBackupExtAbility(); + ClearSessionAndSchedInfo(bundleName); + if (isIncBackup) { + HILOGI("Incremental backup or restore app done, bundleName:%{public}s, errCode:%{public}d", + bundleName.c_str(), errCode); + NotifyCallerCurAppIncrementDone(errCode, bundleName); + } else { + HILOGI("Full backup or restore app done, bundleName:%{public}s, errCode:%{public}d", + bundleName.c_str(), errCode); + NotifyCallerCurAppDone(errCode, bundleName); + } + return BError(BError::Codes::OK); +} } \ No newline at end of file diff --git a/services/backup_sa/src/module_ipc/svc_session_manager.cpp b/services/backup_sa/src/module_ipc/svc_session_manager.cpp index 8b79408c3648adb0b68d8273dc95f98b445d96ae..7ea412d1b87e7005d17e8be1213802168ae7592d 100644 --- a/services/backup_sa/src/module_ipc/svc_session_manager.cpp +++ b/services/backup_sa/src/module_ipc/svc_session_manager.cpp @@ -184,16 +184,15 @@ bool SvcSessionManager::OnBundleFileReady(const string &bundleName, const string { unique_lock lock(lock_); if (!impl_.clientToken) { - throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); + HILOGE("OnBundleFileReady failed, bundleName:%{public}s, fileName:%{public}s", bundleName.c_str(), + GetAnonyPath(fileName).c_str()); + return false; } - HILOGD("Begin, bundleName name is:%{public}s", bundleName.c_str()); - auto it = impl_.backupExtNameMap.find(bundleName); - if (it == impl_.backupExtNameMap.end()) { - stringstream ss; - ss << "Could not find the " << bundleName << " from current session"; - throw BError(BError::Codes::SA_REFUSED_ACT, ss.str()); + auto [findBundleSuc, it] = GetBackupExtNameMap(bundleName); + if (!findBundleSuc) { + HILOGE("BackupExtNameMap can not find the bundle:%{public}s", bundleName.c_str()); + return false; } - // 判断是否结束 通知EXTENTION清理资源 TOOL应用完成备份 if (impl_.scenario == IServiceReverse::Scenario::RESTORE || SAUtils::IsSABundleName(bundleName)) { it->second.isBundleFinished = true; @@ -208,7 +207,8 @@ bool SvcSessionManager::OnBundleFileReady(const string &bundleName, const string it->second.receExtAppDone = true; } if (it->second.receExtManageJson && it->second.fileNameInfo.empty() && it->second.receExtAppDone) { - HILOGI("The bundle manage json info and file info support current app done"); + HILOGI("The bundle manage json info and file info support current app done, bundle:%{public}s", + bundleName.c_str()); it->second.isBundleFinished = true; return true; } @@ -220,10 +220,12 @@ bool SvcSessionManager::OnBundleFileReady(const string &bundleName, const string UniqueFd SvcSessionManager::OnBundleExtManageInfo(const string &bundleName, UniqueFd fd) { if (!impl_.clientToken) { - throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); + HILOGE("No caller token was specified, bundleName:%{public}s", bundleName.c_str()); + return UniqueFd(-EPERM); } if (impl_.scenario != IServiceReverse::Scenario::BACKUP) { - throw BError(BError::Codes::SA_INVAL_ARG, "Invalid Scenario"); + HILOGE("Invalid Scenario, bundleName:%{public}s", bundleName.c_str()); + return UniqueFd(-EPERM); } BJsonCachedEntity cachedEntity(move(fd)); @@ -231,12 +233,16 @@ UniqueFd SvcSessionManager::OnBundleExtManageInfo(const string &bundleName, Uniq auto info = cache.GetExtManage(); for (auto &fileName : info) { - HILOGE("fileName %{public}s", GetAnonyString(fileName).data()); + HILOGE("fileName %{public}s", GetAnonyPath(fileName).data()); OnBundleFileReady(bundleName, fileName); } unique_lock lock(lock_); - auto it = GetBackupExtNameMap(bundleName); + auto [findBundleSuc, it] = GetBackupExtNameMap(bundleName); + if (!findBundleSuc) { + HILOGE("BackupExtNameMap can not find the bundle:%{public}s", bundleName.c_str()); + return UniqueFd(-EPERM); + } it->second.receExtManageJson = true; return move(cachedEntity.GetFd()); } @@ -247,7 +253,7 @@ void SvcSessionManager::RemoveExtInfo(const string &bundleName) unique_lock lock(lock_); auto it = impl_.backupExtNameMap.find(bundleName); if (it == impl_.backupExtNameMap.end()) { - HILOGI("BackupExtNameMap not contain %{public}s", bundleName.c_str()); + HILOGE("BackupExtNameMap not contain %{public}s", bundleName.c_str()); return; } if (extConnectNum_) { @@ -286,12 +292,18 @@ std::weak_ptr SvcSessionManager::GetSAExtConnection(const Bu HILOGD("svcMrg:GetExt, bundleName:%{public}s", bundleName.c_str()); shared_lock lock(lock_); if (!impl_.clientToken) { - throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); + HILOGE("No caller token was specified, bundleName:%{public}s", bundleName.c_str()); + return std::weak_ptr(); } - auto it = GetBackupExtNameMap(bundleName); + auto [findBundleSuc, it] = GetBackupExtNameMap(bundleName); + if (!findBundleSuc) { + HILOGE("BackupExtNameMap can not find current bundle, bundleName:%{public}s", bundleName.c_str()); + return std::weak_ptr(); + } if (!it->second.saBackupConnection) { - throw BError(BError::Codes::SA_INVAL_ARG, "SA backup connection is empty"); + HILOGE("SA backup connection is empty, bundleName:%{public}s", bundleName.c_str()); + return std::weak_ptr(); } return std::weak_ptr(it->second.saBackupConnection); @@ -416,10 +428,14 @@ void SvcSessionManager::SetExtFileNameRequest(const string &bundleName, const st { unique_lock lock(lock_); if (!impl_.clientToken) { - throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); + HILOGE("No caller token was specified, bundleName:%{public}s", bundleName.c_str()); + return; + } + auto [findBundleSuc, it] = GetBackupExtNameMap(bundleName); + if (!findBundleSuc) { + HILOGE("BackupExtNameMap can not find current bundle, bundleName:%{public}s", bundleName.c_str()); + return; } - - auto it = GetBackupExtNameMap(bundleName); it->second.fileNameInfo.insert(fileName); } @@ -427,27 +443,33 @@ std::set SvcSessionManager::GetExtFileNameRequest(const std::string { unique_lock lock(lock_); if (!impl_.clientToken) { - throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); + HILOGE("No caller token was specified, bundleName:%{public}s", bundleName.c_str()); + return std::set(); } if (impl_.scenario != IServiceReverse::Scenario::RESTORE) { - throw BError(BError::Codes::SA_INVAL_ARG, "Invalid Scenario"); + HILOGE("Invalid Scenario, bundleName:%{public}s", bundleName.c_str()); + return std::set(); + } + auto [findBundleSuc, it] = GetBackupExtNameMap(bundleName); + if (!findBundleSuc) { + HILOGE("BackupExtNameMap can not find bundle %{public}s", bundleName.c_str()); + return std::set(); } - auto it = GetBackupExtNameMap(bundleName); set fileNameInfo = it->second.fileNameInfo; it->second.fileNameInfo.clear(); return fileNameInfo; } -map::iterator SvcSessionManager::GetBackupExtNameMap(const string &bundleName) +std::tuple::iterator> SvcSessionManager::GetBackupExtNameMap( + const string &bundleName) { auto it = impl_.backupExtNameMap.find(bundleName); if (it == impl_.backupExtNameMap.end()) { - stringstream ss; - ss << "Could not find the " << bundleName << " from current session"; - throw BError(BError::Codes::SA_REFUSED_ACT, ss.str()); + HILOGE("Could not find the bundle from current session, bundleName:%{public}s", bundleName.c_str()); + return {false, impl_.backupExtNameMap.end()}; } - return it; + return {true, it}; } bool SvcSessionManager::GetSchedBundleName(string &bundleName) @@ -477,9 +499,14 @@ BConstants::ServiceSchedAction SvcSessionManager::GetServiceSchedAction(const st { shared_lock lock(lock_); if (!impl_.clientToken) { - throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); + HILOGE("No caller token was specified, bundleName:%{public}s", bundleName.c_str()); + return BConstants::ServiceSchedAction::UNKNOWN; + } + auto [findBundleSuc, it] = GetBackupExtNameMap(bundleName); + if (!findBundleSuc) { + HILOGE("BackupExtNameMap can not find bundle %{public}s", bundleName.c_str()); + return BConstants::ServiceSchedAction::UNKNOWN; } - auto it = GetBackupExtNameMap(bundleName); return it->second.schedAction; } @@ -487,10 +514,14 @@ void SvcSessionManager::SetServiceSchedAction(const string &bundleName, BConstan { unique_lock lock(lock_); if (!impl_.clientToken) { + HILOGE("No caller token was specified, bundleName:%{public}s", bundleName.c_str()); throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); } - - auto it = GetBackupExtNameMap(bundleName); + auto [findBundleSuc, it] = GetBackupExtNameMap(bundleName); + if (!findBundleSuc) { + HILOGE("BackupExtNameMap can not find bundle %{public}s", bundleName.c_str()); + throw BError(BError::Codes::SA_REFUSED_ACT, "BackupExtNameMap can not find bundle"); + } it->second.schedAction = action; if (it->second.schedAction == BConstants::ServiceSchedAction::START) { extConnectNum_++; @@ -501,10 +532,15 @@ void SvcSessionManager::SetBackupExtName(const string &bundleName, const string { unique_lock lock(lock_); if (!impl_.clientToken) { - throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); + HILOGE("No caller token was specified, bundleName:%{public}s", bundleName.c_str()); + return; } - auto it = GetBackupExtNameMap(bundleName); + auto [findBundleSuc, it] = GetBackupExtNameMap(bundleName); + if (!findBundleSuc) { + HILOGE("BackupExtNameMap can not find bundle %{public}s", bundleName.c_str()); + return; + } it->second.backupExtName = backupExtName; } @@ -512,10 +548,15 @@ string SvcSessionManager::GetBackupExtName(const string &bundleName) { shared_lock lock(lock_); if (!impl_.clientToken) { - throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); + HILOGE("No caller token was specified, bundleName:%{public}s", bundleName.c_str()); + return ""; } - auto it = GetBackupExtNameMap(bundleName); + auto [findBundleSuc, it] = GetBackupExtNameMap(bundleName); + if (!findBundleSuc) { + HILOGE("BackupExtNameMap can not find bundle %{public}s", bundleName.c_str()); + return ""; + } return it->second.backupExtName; } @@ -523,10 +564,15 @@ void SvcSessionManager::SetBackupExtInfo(const string &bundleName, const string { unique_lock lock(lock_); if (!impl_.clientToken) { - throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); + HILOGE("No caller token was specified, bundleName:%{public}s", bundleName.c_str()); + return; } - auto it = GetBackupExtNameMap(bundleName); + auto [findBundleSuc, it] = GetBackupExtNameMap(bundleName); + if (!findBundleSuc) { + HILOGE("BackupExtNameMap can not find bundle %{public}s", bundleName.c_str()); + return; + } it->second.extInfo = extInfo; } @@ -534,10 +580,15 @@ std::string SvcSessionManager::GetBackupExtInfo(const string &bundleName) { shared_lock lock(lock_); if (!impl_.clientToken) { - throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); + HILOGE("No caller token was specified, bundleName:%{public}s", bundleName.c_str()); + return ""; } - auto it = GetBackupExtNameMap(bundleName); + auto [findBundleSuc, it] = GetBackupExtNameMap(bundleName); + if (!findBundleSuc) { + HILOGE("BackupExtNameMap can not find bundle %{public}s", bundleName.c_str()); + return ""; + } return it->second.extInfo; } @@ -545,7 +596,8 @@ void SvcSessionManager::AppendBundles(const vector &bundleNames) { unique_lock lock(lock_); if (!impl_.clientToken) { - throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); + HILOGE("AppendBundles error, No caller token was specified"); + return; } for (auto &&bundleName : bundleNames) { @@ -553,7 +605,7 @@ void SvcSessionManager::AppendBundles(const vector &bundleNames) BackupExtInfo info {}; auto it = impl_.backupExtNameMap.find(bundleName); if (it != impl_.backupExtNameMap.end()) { - HILOGI("BackupExtNameMap already contain %{public}s", bundleName.c_str()); + HILOGE("BackupExtNameMap already contain %{public}s", bundleName.c_str()); info.backUpConnection = impl_.backupExtNameMap[bundleName].backUpConnection; info.saBackupConnection = impl_.backupExtNameMap[bundleName].saBackupConnection; info.appendNum = impl_.backupExtNameMap[bundleName].appendNum + 1; @@ -603,7 +655,8 @@ bool SvcSessionManager::IsOnAllBundlesFinished() { shared_lock lock(lock_); if (!impl_.clientToken) { - throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); + HILOGE("IsOnAllBundlesFinished error, No caller token was specified"); + return false; } bool isAllBundlesFinished = !impl_.backupExtNameMap.size(); if (impl_.scenario == IServiceReverse::Scenario::RESTORE) { @@ -619,7 +672,8 @@ bool SvcSessionManager::IsOnOnStartSched() HILOGI("Begin"); shared_lock lock(lock_); if (!impl_.clientToken) { - throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); + HILOGE("IsOnOnStartSched error, No caller token was specified"); + return false; } if (impl_.isBackupStart && impl_.backupExtNameMap.size()) { return true; @@ -647,10 +701,15 @@ void SvcSessionManager::SetBundleRestoreType(const std::string &bundleName, Rest { unique_lock lock(lock_); if (!impl_.clientToken) { - throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); + HILOGE("No caller token was specified, bundleName:%{public}s", bundleName.c_str()); + return; } - auto it = GetBackupExtNameMap(bundleName); + auto [findBundleSuc, it] = GetBackupExtNameMap(bundleName); + if (!findBundleSuc) { + HILOGE("BackupExtNameMap can not find bundle %{public}s", bundleName.c_str()); + return; + } it->second.restoreType = restoreType; } @@ -658,10 +717,15 @@ RestoreTypeEnum SvcSessionManager::GetBundleRestoreType(const std::string &bundl { shared_lock lock(lock_); if (!impl_.clientToken) { - throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); + HILOGE("No caller token was specified, bundleName:%{public}s", bundleName.c_str()); + return RestoreTypeEnum::RESTORE_DATA_WAIT_SEND; } - auto it = GetBackupExtNameMap(bundleName); + auto [findBundleSuc, it] = GetBackupExtNameMap(bundleName); + if (!findBundleSuc) { + HILOGE("BackupExtNameMap can not find bundle %{public}s", bundleName.c_str()); + return RestoreTypeEnum::RESTORE_DATA_WAIT_SEND; + } return it->second.restoreType; } @@ -669,10 +733,15 @@ void SvcSessionManager::SetBundleVersionCode(const std::string &bundleName, int6 { unique_lock lock(lock_); if (!impl_.clientToken) { - throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); + HILOGE("No caller token was specified, bundleName:%{public}s", bundleName.c_str()); + return; } - auto it = GetBackupExtNameMap(bundleName); + auto [findBundleSuc, it] = GetBackupExtNameMap(bundleName); + if (!findBundleSuc) { + HILOGE("BackupExtNameMap can not find bundle %{public}s", bundleName.c_str()); + return; + } it->second.versionCode = versionCode; } @@ -680,10 +749,15 @@ int64_t SvcSessionManager::GetBundleVersionCode(const std::string &bundleName) { shared_lock lock(lock_); if (!impl_.clientToken) { - throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); + HILOGE("No caller token was specified, bundleName:%{public}s", bundleName.c_str()); + return 0; } - auto it = GetBackupExtNameMap(bundleName); + auto [findBundleSuc, it] = GetBackupExtNameMap(bundleName); + if (!findBundleSuc) { + HILOGE("BackupExtNameMap can not find bundle %{public}s", bundleName.c_str()); + return 0; + } return it->second.versionCode; } @@ -691,10 +765,15 @@ void SvcSessionManager::SetBundleVersionName(const std::string &bundleName, std: { unique_lock lock(lock_); if (!impl_.clientToken) { - throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); + HILOGE("No caller token was specified, bundleName:%{public}s", bundleName.c_str()); + return; } - auto it = GetBackupExtNameMap(bundleName); + auto [findBundleSuc, it] = GetBackupExtNameMap(bundleName); + if (!findBundleSuc) { + HILOGE("BackupExtNameMap can not find bundle %{public}s", bundleName.c_str()); + return; + } it->second.versionName = versionName; } @@ -702,10 +781,15 @@ std::string SvcSessionManager::GetBundleVersionName(const std::string &bundleNam { shared_lock lock(lock_); if (!impl_.clientToken) { - throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); + HILOGE("No caller token was specified, bundleName:%{public}s", bundleName.c_str()); + return ""; } - auto it = GetBackupExtNameMap(bundleName); + auto [findBundleSuc, it] = GetBackupExtNameMap(bundleName); + if (!findBundleSuc) { + HILOGE("BackupExtNameMap can not find bundle %{public}s", bundleName.c_str()); + return ""; + } return it->second.versionName; } @@ -713,10 +797,15 @@ void SvcSessionManager::SetBundleDataSize(const std::string &bundleName, int64_t { unique_lock lock(lock_); if (!impl_.clientToken) { - throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); + HILOGE("No caller token was specified, bundleName:%{public}s", bundleName.c_str()); + return; } - auto it = GetBackupExtNameMap(bundleName); + auto [findBundleSuc, it] = GetBackupExtNameMap(bundleName); + if (!findBundleSuc) { + HILOGE("BackupExtNameMap can not find bundle %{public}s", bundleName.c_str()); + return; + } it->second.dataSize = dataSize; } @@ -730,15 +819,16 @@ uint32_t SvcSessionManager::CalAppProcessTime(const std::string &bundleName) int64_t timeout; uint32_t resTimeoutMs; - try { - auto it = GetBackupExtNameMap(bundleName); - int64_t appSize = it->second.dataSize; - /* timeout = (AppSize / 3Ms) * 3 + 30 */ - timeout = defaultTimeout + (appSize / processRate) * multiple; - } catch (const BError &e) { - HILOGE("Failed to get app<%{public}s> dataInfo, err=%{public}d", bundleName.c_str(), e.GetCode()); - timeout = defaultTimeout; + auto [findBundleSuc, it] = GetBackupExtNameMap(bundleName); + if (!findBundleSuc) { + HILOGE("CalAppProcessTime failed, BackupExtNameMap can not find bundle %{public}s", bundleName.c_str()); + resTimeoutMs = (uint32_t)(minTimeout * invertMillisecond % UINT_MAX); + HILOGE("Current app will run timeout=%{public}u(ms), bundleName=%{public}s ", resTimeoutMs, bundleName.c_str()); + return resTimeoutMs; } + int64_t appSize = it->second.dataSize; + /* timeout = (AppSize / 3Ms) * 3 + 30 */ + timeout = defaultTimeout + (appSize / processRate) * multiple; 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(ms), bundleName=%{public}s ", resTimeoutMs, @@ -754,7 +844,11 @@ bool SvcSessionManager::StartFwkTimer(const std::string &bundleName, const Utils HILOGE("No caller token was specified"); return false; } - auto it = GetBackupExtNameMap(bundleName); + auto [findBundleSuc, it] = GetBackupExtNameMap(bundleName); + if (!findBundleSuc) { + HILOGE("Start fwk timer failed, BackupExtNameMap can not find bundle %{public}s", bundleName.c_str()); + return false; + } if (it->second.fwkTimerStatus == true) { HILOGE("FwkTimer is registered, unregister first."); return false; @@ -775,7 +869,11 @@ bool SvcSessionManager::StopFwkTimer(const std::string &bundleName) HILOGE("No caller token was specified"); return false; } - auto it = GetBackupExtNameMap(bundleName); + auto [findBundleSuc, it] = GetBackupExtNameMap(bundleName); + if (!findBundleSuc) { + HILOGE("Stop fwk timer failed, BackupExtNameMap can not find bundle %{public}s", bundleName.c_str()); + return false; + } if (it->second.fwkTimerStatus == false) { HILOGE("FwkTimer is unregistered, register first."); return true; @@ -795,7 +893,11 @@ bool SvcSessionManager::StartExtTimer(const std::string &bundleName, const Utils HILOGE("No caller token was specified"); return false; } - auto it = GetBackupExtNameMap(bundleName); + auto [findBundleSuc, it] = GetBackupExtNameMap(bundleName); + if (!findBundleSuc) { + HILOGE("Start extension timer failed, BackupExtNameMap can not find bundle %{public}s", bundleName.c_str()); + return false; + } if (it->second.extTimerStatus == true) { HILOGE("ExtTimer is registered, unregister first."); return false; @@ -816,7 +918,11 @@ bool SvcSessionManager::StopExtTimer(const std::string &bundleName) HILOGE("No caller token was specified"); return false; } - auto it = GetBackupExtNameMap(bundleName); + auto [findBundleSuc, it] = GetBackupExtNameMap(bundleName); + if (!findBundleSuc) { + HILOGE("Stop extension timer failed, BackupExtNameMap can not find bundle %{public}s", bundleName.c_str()); + return false; + } if (it->second.extTimerStatus == false) { HILOGE("ExtTimer is unregistered, register first."); return true; @@ -838,7 +944,11 @@ bool SvcSessionManager::UpdateTimer(const std::string &bundleName, uint32_t time HILOGE("No caller token was specified"); return false; } - auto it = GetBackupExtNameMap(bundleName); + auto [findBundleSuc, it] = GetBackupExtNameMap(bundleName); + if (!findBundleSuc) { + HILOGE("Update timer failed, BackupExtNameMap can not find bundle %{public}s", bundleName.c_str()); + return false; + } it->second.timeout = timeout; if (it->second.extTimerStatus == false) { HILOGI("ExtTimer is unregistered, just store timeout %{public}u(ms)", timeout); @@ -911,7 +1021,8 @@ bool SvcSessionManager::GetIsIncrementalBackup() { unique_lock lock(lock_); if (!impl_.clientToken) { - throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); + HILOGE("GetIsIncrementalBackup error, No caller token was specified"); + return false; } return impl_.isIncrementalBackup; } @@ -920,9 +1031,14 @@ void SvcSessionManager::SetIncrementalData(const BIncrementalData &incrementalDa { unique_lock lock(lock_); if (!impl_.clientToken) { - throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); + HILOGE("SetIncrementalData error, No caller token was specified"); + return; + } + auto [findBundleSuc, it] = GetBackupExtNameMap(incrementalData.bundleName); + if (!findBundleSuc) { + HILOGE("BackupExtNameMap can not find bundle %{public}s", incrementalData.bundleName.c_str()); + return; } - auto it = GetBackupExtNameMap(incrementalData.bundleName); it->second.lastIncrementalTime = incrementalData.lastIncrementalTime; it->second.manifestFd = incrementalData.manifestFd; it->second.backupParameters = incrementalData.backupParameters; @@ -933,9 +1049,14 @@ int32_t SvcSessionManager::GetIncrementalManifestFd(const string &bundleName) { unique_lock lock(lock_); if (!impl_.clientToken) { - throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); + HILOGE("No caller token was specified, bundleName:%{public}s", bundleName.c_str()); + return BConstants::INVALID_FD_NUM; + } + auto [findBundleSuc, it] = GetBackupExtNameMap(bundleName); + if (!findBundleSuc) { + HILOGE("BackupExtNameMap can not find bundle %{public}s", bundleName.c_str()); + return BConstants::INVALID_FD_NUM; } - auto it = GetBackupExtNameMap(bundleName); return it->second.manifestFd; } @@ -943,9 +1064,14 @@ int64_t SvcSessionManager::GetLastIncrementalTime(const string &bundleName) { unique_lock lock(lock_); if (!impl_.clientToken) { - throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); + HILOGE("No caller token was specified, bundleName:%{public}s", bundleName.c_str()); + return 0; + } + auto [findBundleSuc, it] = GetBackupExtNameMap(bundleName); + if (!findBundleSuc) { + HILOGE("BackupExtNameMap can not find bundle %{public}s", bundleName.c_str()); + return 0; } - auto it = GetBackupExtNameMap(bundleName); return it->second.lastIncrementalTime; } @@ -963,19 +1089,30 @@ void SvcSessionManager::SetClearDataFlag(const std::string &bundleName, bool isC { unique_lock lock(lock_); if (!impl_.clientToken) { - throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); + HILOGE("No caller token was specified, bundleName:%{public}s", bundleName.c_str()); + return; + } + auto [findBundleSuc, it] = GetBackupExtNameMap(bundleName); + if (!findBundleSuc) { + HILOGE("BackupExtNameMap can not find bundle %{public}s", bundleName.c_str()); + return; } - auto it = GetBackupExtNameMap(bundleName); it->second.isClearData = isClearData; HILOGI("bundleName:%{public}s, set clear data flag:%{public}d.", bundleName.c_str(), isClearData); } + bool SvcSessionManager::GetClearDataFlag(const std::string &bundleName) { unique_lock lock(lock_); if (!impl_.clientToken) { - throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); + HILOGE("No caller token was specified, bundleName:%{public}s", bundleName.c_str()); + return true; + } + auto [findBundleSuc, it] = GetBackupExtNameMap(bundleName); + if (!findBundleSuc) { + HILOGE("BackupExtNameMap can not find bundle %{public}s", bundleName.c_str()); + return true; } - auto it = GetBackupExtNameMap(bundleName); return it->second.isClearData; } @@ -1039,9 +1176,14 @@ void SvcSessionManager::SetPublishFlag(const std::string &bundleName) { unique_lock lock(lock_); if (!impl_.clientToken) { - throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); + HILOGE("No caller token was specified, bundleName:%{public}s", bundleName.c_str()); + return; + } + auto [findBundleSuc, it] = GetBackupExtNameMap(bundleName); + if (!findBundleSuc) { + HILOGE("BackupExtNameMap can not find bundle %{public}s", bundleName.c_str()); + return; } - auto it = GetBackupExtNameMap(bundleName); it->second.isInPublishFile = true; HILOGE("Set PublishFile success, bundleName = %{public}s", bundleName.c_str()); } @@ -1050,7 +1192,8 @@ void SvcSessionManager::SetOldBackupVersion(const std::string &backupVersion) { unique_lock lock(lock_); if (!impl_.clientToken) { - throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); + HILOGE("Error, No caller token was specified"); + return; } impl_.oldBackupVersion = backupVersion; } @@ -1059,7 +1202,8 @@ std::string SvcSessionManager::GetOldBackupVersion() { shared_lock lock(lock_); if (!impl_.clientToken) { - throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); + HILOGE("Error, No caller token was specified"); + return ""; } return impl_.oldBackupVersion; } @@ -1073,9 +1217,14 @@ void SvcSessionManager::SetIsReadyLaunch(const std::string &bundleName) { unique_lock lock(lock_); if (!impl_.clientToken) { - throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); + HILOGE("No caller token was specified, bundleName:%{public}s", bundleName.c_str()); + return; + } + auto [findBundleSuc, it] = GetBackupExtNameMap(bundleName); + if (!findBundleSuc) { + HILOGE("BackupExtNameMap can not find bundle %{public}s", bundleName.c_str()); + return; } - auto it = GetBackupExtNameMap(bundleName); it->second.isReadyLaunch = true; HILOGE("SetIsReadyLaunch success, bundleName = %{public}s", bundleName.c_str()); } diff --git a/services/backup_sa/src/module_sched/sched_scheduler.cpp b/services/backup_sa/src/module_sched/sched_scheduler.cpp index 4510666123e4d68f077c8d150994828fa08a4947..79bb92040174fc73c0865769391649aa013c41ae 100644 --- a/services/backup_sa/src/module_sched/sched_scheduler.cpp +++ b/services/backup_sa/src/module_sched/sched_scheduler.cpp @@ -80,7 +80,7 @@ void SchedScheduler::Sched(string bundleName) } catch (const exception &e) { HILOGE("%{public}s", e.what()); } catch (...) { - HILOGE(""); + HILOGE("Unexpected exception"); } }; threadPool_.AddTask(callStart); @@ -93,51 +93,16 @@ void SchedScheduler::ExecutingQueueTasks(const string &bundleName) return; } BConstants::ServiceSchedAction action = sessionPtr_->GetServiceSchedAction(bundleName); - if (action == BConstants::ServiceSchedAction::START) { - // register timer for connect extension - auto callStart = [reversePtr {reversePtr_}, bundleName]() { - HILOGE("Extension connect failed = %{public}s", bundleName.data()); - auto ptr = reversePtr.promote(); - if (ptr) { - ptr->ExtConnectFailed(bundleName, BError(BError::Codes::SA_BOOT_EXT_TIMEOUT)); - } - }; - auto iTime = extTime_.Register(callStart, BConstants::EXT_CONNECT_MAX_TIME, true); - unique_lock lock(lock_); - bundleTimeVec_.emplace_back(make_tuple(bundleName, iTime)); - lock.unlock(); - // launch extension - if (reversePtr_ != nullptr) { - ErrCode errCode = reversePtr_->LaunchBackupExtension(bundleName); - if (errCode) { - reversePtr_->ExtConnectFailed(bundleName, errCode); - } - } - } else if (action == BConstants::ServiceSchedAction::RUNNING) { - HILOGI("Current bundle %{public}s process is running", bundleName.data()); - unique_lock lock(lock_); - auto iter = find_if(bundleTimeVec_.begin(), bundleTimeVec_.end(), [&bundleName](auto &obj) { - auto &[bName, iTime] = obj; - return bName == bundleName; - }); - if (iter == bundleTimeVec_.end()) { - throw BError(BError::Codes::SA_INVAL_ARG, "Failed to find timer"); - } - auto &[bName, iTime] = *iter; - // unregister timer - extTime_.Unregister(iTime); - lock.unlock(); - //notify AppGallery to start restore - if (reversePtr_ != nullptr) { - reversePtr_->StartRunningTimer(bundleName); - reversePtr_->SendStartAppGalleryNotify(bundleName); - reversePtr_->ExtStart(bundleName); - } - } else if (action == BConstants::ServiceSchedAction::CLEAN) { - HILOGI("Current bundle %{public}s process is cleaning", bundleName.data()); - ErrCode res = reversePtr_->ClearResidualBundleData(bundleName); - IServiceReverse::Scenario scenario = sessionPtr_->GetScenario(); - ExtDiedClearFailRadarReport(bundleName, scenario, res); + if (action == BConstants::ServiceSchedAction::UNKNOWN) { + HILOGE("Current action is unknown, bundleName:%{public}s", bundleName.c_str()); + return; + } + try { + HILOGI("Start current bundle task, bundleName:%{public}s, action:%{public}d", bundleName.c_str(), action); + StartExecuteBundleTask(bundleName, action); + } catch(...) { + HILOGE("Unexpected exception"); + return; } } @@ -229,4 +194,54 @@ void SchedScheduler::ClearSchedulerData() } bundleTimeVec_.clear(); } -}; // namespace OHOS::FileManagement::Backup + +void SchedScheduler::StartExecuteBundleTask(const std::string &bundleName, BConstants::ServiceSchedAction action) +{ + if (action == BConstants::ServiceSchedAction::START) { + // register timer for connect extension + auto callStart = [reversePtr {reversePtr_}, bundleName]() { + HILOGE("Extension connect failed = %{public}s", bundleName.data()); + auto ptr = reversePtr.promote(); + if (ptr) { + ptr->ExtConnectFailed(bundleName, BError(BError::Codes::SA_BOOT_EXT_TIMEOUT)); + } + }; + auto iTime = extTime_.Register(callStart, BConstants::EXT_CONNECT_MAX_TIME, true); + unique_lock lock(lock_); + bundleTimeVec_.emplace_back(make_tuple(bundleName, iTime)); + lock.unlock(); + // launch extension + if (reversePtr_ != nullptr) { + ErrCode errCode = reversePtr_->LaunchBackupExtension(bundleName); + if (errCode) { + reversePtr_->ExtConnectFailed(bundleName, errCode); + } + } + } else if (action == BConstants::ServiceSchedAction::RUNNING) { + HILOGI("Current bundle %{public}s process is running", bundleName.data()); + unique_lock lock(lock_); + auto iter = find_if(bundleTimeVec_.begin(), bundleTimeVec_.end(), [&bundleName](auto &obj) { + auto &[bName, iTime] = obj; + return bName == bundleName; + }); + if (iter == bundleTimeVec_.end()) { + throw BError(BError::Codes::SA_INVAL_ARG, "Failed to find timer"); + } + auto &[bName, iTime] = *iter; + // unregister timer + extTime_.Unregister(iTime); + lock.unlock(); + //notify AppGallery to start restore + if (reversePtr_ != nullptr) { + reversePtr_->StartRunningTimer(bundleName); + reversePtr_->SendStartAppGalleryNotify(bundleName); + reversePtr_->ExtStart(bundleName); + } + } else if (action == BConstants::ServiceSchedAction::CLEAN) { + HILOGI("Current bundle %{public}s process is cleaning", bundleName.data()); + ErrCode res = reversePtr_->ClearResidualBundleData(bundleName); + IServiceReverse::Scenario scenario = sessionPtr_->GetScenario(); + ExtDiedClearFailRadarReport(bundleName, scenario, res); + } +} +}; // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/mock/module_ipc/service_mock.cpp b/tests/mock/module_ipc/service_mock.cpp index 2661aa56c55ea92463e8978050aa45f2ff03b220..dd09cac5ed021f96acf5f462f852d26e90531f34 100644 --- a/tests/mock/module_ipc/service_mock.cpp +++ b/tests/mock/module_ipc/service_mock.cpp @@ -326,4 +326,6 @@ void Service::HandleNotSupportBundleNames(const vector&, vector& void Service::SetBundleIncDataInfo(const std::vector&, std::vector&) {} void Service::CancelTask(std::string bundleName, wptr ptr) {} + +void SetUserIdAndRestoreType(RestoreTypeEnum restoreType, int32_t userId) {} } // namespace OHOS::FileManagement::Backup diff --git a/tests/mock/module_ipc/src/svc_session_manager_mock.cpp b/tests/mock/module_ipc/src/svc_session_manager_mock.cpp index 8739d1da44b6ba0dc8bf9b91fbeb576878ff05e4..0fed3b03e77a1fb148002309d5b2b8691e58761a 100644 --- a/tests/mock/module_ipc/src/svc_session_manager_mock.cpp +++ b/tests/mock/module_ipc/src/svc_session_manager_mock.cpp @@ -87,7 +87,7 @@ std::set SvcSessionManager::GetExtFileNameRequest(const std::string return BSvcSessionManager::sessionManager->GetExtFileNameRequest(bundleName); } -map::iterator SvcSessionManager::GetBackupExtNameMap(const string &) +std::tuple::iterator> SvcSessionManager::GetBackupExtNameMap(const string &) { return {}; } diff --git a/tests/mock/module_ipc/svc_session_manager_mock.cpp b/tests/mock/module_ipc/svc_session_manager_mock.cpp index bb61902f8218fb905d5e8c708e50d4602da2d1c8..b5e2a1d1aa565cce177a3a5359409cc1c64a6b8c 100644 --- a/tests/mock/module_ipc/svc_session_manager_mock.cpp +++ b/tests/mock/module_ipc/svc_session_manager_mock.cpp @@ -146,11 +146,15 @@ std::set SvcSessionManager::GetExtFileNameRequest(const std::string return fileNameInfo; } -map::iterator SvcSessionManager::GetBackupExtNameMap(const string &bundleName) +std::tuple::iterator> SvcSessionManager::GetBackupExtNameMap( + const string &bundleName) { GTEST_LOG_(INFO) << "GetBackupExtNameMap"; auto it = impl_.backupExtNameMap.find(bundleName); - return it; + if (it == impl_.backupExtNameMap.end()) { + return {false, impl_.backupExtNameMap.end()}; + } + return {true, it}; } bool SvcSessionManager::GetSchedBundleName(string &bundleName) diff --git a/tests/mock/module_ipc/svc_session_manager_throw_mock.cpp b/tests/mock/module_ipc/svc_session_manager_throw_mock.cpp index bfdf4a3d5a1365b0ca21874b482793698ae6af97..f1fcc20680542605418a425591fb436f72ebaf25 100644 --- a/tests/mock/module_ipc/svc_session_manager_throw_mock.cpp +++ b/tests/mock/module_ipc/svc_session_manager_throw_mock.cpp @@ -94,7 +94,8 @@ std::set SvcSessionManager::GetExtFileNameRequest(const std::string return BackupSvcSessionManager::session->GetExtFileNameRequest(bundleName); } -map::iterator SvcSessionManager::GetBackupExtNameMap(const string &bundleName) +std::tuple::iterator> SvcSessionManager::GetBackupExtNameMap( + const string &bundleName) { return BackupSvcSessionManager::session->GetBackupExtNameMap(bundleName); } diff --git a/tests/mock/module_ipc/svc_session_manager_throw_mock.h b/tests/mock/module_ipc/svc_session_manager_throw_mock.h index 2b3154b1aaa89244fe2287cc7ce0329bfa496c6c..081da93b792e1fde9bbf50a4feb0c6f7f045186a 100644 --- a/tests/mock/module_ipc/svc_session_manager_throw_mock.h +++ b/tests/mock/module_ipc/svc_session_manager_throw_mock.h @@ -42,7 +42,8 @@ public: virtual ErrCode InitClient(SvcSessionManager::Impl &) = 0; virtual void SetExtFileNameRequest(const std::string &, const std::string &) = 0; virtual std::set GetExtFileNameRequest(const std::string &) = 0; - virtual std::map::iterator GetBackupExtNameMap(const std::string &) = 0; + virtual std::tuple::iterator> GetBackupExtNameMap( + const std::string &) = 0; virtual bool GetSchedBundleName(std::string &) = 0; virtual BConstants::ServiceSchedAction GetServiceSchedAction(const std::string &) = 0; virtual void SetServiceSchedAction(const std::string &, BConstants::ServiceSchedAction) = 0; @@ -113,7 +114,8 @@ public: MOCK_METHOD(ErrCode, InitClient, (SvcSessionManager::Impl &)); MOCK_METHOD(void, SetExtFileNameRequest, (const std::string &, const std::string &)); MOCK_METHOD(std::set, GetExtFileNameRequest, (const std::string &)); - MOCK_METHOD((std::map::iterator), GetBackupExtNameMap, (const std::string &)); + MOCK_METHOD((std::tuple::iterator>), GetBackupExtNameMap, + (const std::string &)); MOCK_METHOD(bool, GetSchedBundleName, (std::string &)); MOCK_METHOD(BConstants::ServiceSchedAction, GetServiceSchedAction, (const std::string &)); MOCK_METHOD(void, SetServiceSchedAction, (const std::string &, BConstants::ServiceSchedAction)); diff --git a/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp index b8e8e3e0bfa509648af2064c798d0afd28e01594..8cb86458d9bc6826ac1357d691d8135f10149a60 100644 --- a/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp @@ -275,6 +275,18 @@ std::vector Service::GetSupportBackupBundleNames(vectorAppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), errCode); - EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG).GetCode()); + EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)).WillOnce(Return(srProxy)); - EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return()).WillOnce(Return()); + EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return()); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(true)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); @@ -809,16 +821,9 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_AppIncrementalDone_0000, EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(true)); - EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(nullptr)); - ret = service->AppIncrementalDone(errCode); - EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG).GetCode()); - - errCode = BError(BError::Codes::SA_INVAL_ARG).GetCode(); - EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(false)) - .WillOnce(Return(false)).WillOnce(Return(false)); - EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(nullptr)); + EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); ret = service->AppIncrementalDone(errCode); - EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG).GetCode()); + EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "ServiceIncrementalTest-an exception occurred by AppIncrementalDone."; @@ -861,18 +866,8 @@ HWTEST_F(ServiceIncrementalTest, SUB_ServiceIncremental_GetIncrementalFileHandle EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); EXPECT_CALL(*svcProxy, GetIncrementalFileHandle(_)).WillOnce(Return(make_tuple(0, UniqueFd(-1), UniqueFd(-1)))); - ret = service->GetIncrementalFileHandle(bundleName, fileName); - EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); - - EXPECT_CALL(*session, GetServiceSchedAction(_)).WillOnce(Return(BConstants::ServiceSchedAction::RUNNING)); - EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); - EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); - EXPECT_CALL(*session, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::BACKUP)); - EXPECT_CALL(*session, GetServiceReverseProxy()).WillOnce(Return(srProxy)); EXPECT_CALL(*srProxy, IncrementalBackupOnFileReady(_, _, _, _, _)).WillOnce(Return()); - EXPECT_CALL(*svcProxy, GetIncrementalFileHandle(_)).WillOnce(Return(make_tuple(1, UniqueFd(-1), UniqueFd(-1)))); - EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) - .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); + EXPECT_CALL(*session, OnBundleFileReady(_, _)).WillOnce(Return(true)); ret = service->GetIncrementalFileHandle(bundleName, fileName); EXPECT_EQ(ret, BError(BError::Codes::OK).GetCode()); diff --git a/tests/unittests/backup_sa/module_ipc/svc_session_manager_ex_test.cpp b/tests/unittests/backup_sa/module_ipc/svc_session_manager_ex_test.cpp index b8e7eac57c892bd61a123615386bbc3715bcb372..8fb3a0735166d23133184b3f03dfe16d6367c8f3 100644 --- a/tests/unittests/backup_sa/module_ipc/svc_session_manager_ex_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/svc_session_manager_ex_test.cpp @@ -26,14 +26,10 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetLastIncrementalTime_010 { GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_GetLastIncrementalTime_0100"; try { - try { - EXPECT_TRUE(sessionManagerPtr_ != nullptr); - sessionManagerPtr_->impl_.clientToken = 0; - sessionManagerPtr_->GetLastIncrementalTime(BUNDLE_NAME); - EXPECT_TRUE(false); - } catch (BError &err) { - EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG); - } + EXPECT_TRUE(sessionManagerPtr_ != nullptr); + sessionManagerPtr_->impl_.clientToken = 0; + sessionManagerPtr_->GetLastIncrementalTime(BUNDLE_NAME); + EXPECT_TRUE(true); sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; sessionManagerPtr_->impl_.backupExtNameMap.clear(); diff --git a/tests/unittests/backup_sa/module_ipc/svc_session_manager_test.cpp b/tests/unittests/backup_sa/module_ipc/svc_session_manager_test.cpp index ad790f8849e2af8f80d16043851097861ce48423..4e603fb6bd51abd3dd23bc278e6a7b5f83e1d0a1 100644 --- a/tests/unittests/backup_sa/module_ipc/svc_session_manager_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/svc_session_manager_test.cpp @@ -306,49 +306,36 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_getscenario_0100, testing: HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_onBundlefileready_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_onBundlefileready_0100"; - try { - try { - EXPECT_TRUE(sessionManagerPtr_ != nullptr); - sessionManagerPtr_->impl_.clientToken = 0; - sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME); - EXPECT_TRUE(false); - } catch (BError &err) { - EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG); - } + EXPECT_TRUE(sessionManagerPtr_ != nullptr); + sessionManagerPtr_->impl_.clientToken = 0; + bool fileReady = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME); + EXPECT_FALSE(fileReady); - try { - sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->impl_.backupExtNameMap.clear(); - sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME); - EXPECT_TRUE(false); - } catch (BError &err) { - EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_REFUSED_ACT); - } + sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; + sessionManagerPtr_->impl_.backupExtNameMap.clear(); + fileReady = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME); + EXPECT_FALSE(fileReady); - sessionManagerPtr_->impl_.backupExtNameMap.clear(); - sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::RESTORE; - auto ret = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME); - EXPECT_TRUE(ret); + sessionManagerPtr_->impl_.backupExtNameMap.clear(); + sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; + sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; + sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::RESTORE; + fileReady = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME); + EXPECT_TRUE(fileReady); - sessionManagerPtr_->impl_.backupExtNameMap.clear(); - sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->impl_.backupExtNameMap["123"] = {}; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::BACKUP; - ret = sessionManagerPtr_->OnBundleFileReady("123"); - EXPECT_TRUE(ret); + sessionManagerPtr_->impl_.backupExtNameMap.clear(); + sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; + sessionManagerPtr_->impl_.backupExtNameMap["123"] = {}; + sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::BACKUP; + fileReady = sessionManagerPtr_->OnBundleFileReady("123"); + EXPECT_TRUE(fileReady); - sessionManagerPtr_->impl_.backupExtNameMap.clear(); - sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::UNDEFINED; - ret = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME); - EXPECT_FALSE(ret); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by onBundlefileready."; - } + sessionManagerPtr_->impl_.backupExtNameMap.clear(); + sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; + sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; + sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::UNDEFINED; + fileReady = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME); + EXPECT_FALSE(fileReady); GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_onBundlefileready_0100"; } @@ -364,40 +351,35 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_onBundlefileready_0100, te HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_onBundlefileready_0101, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_onBundlefileready_0101"; - try { - EXPECT_TRUE(sessionManagerPtr_ != nullptr); - sessionManagerPtr_->impl_.backupExtNameMap.clear(); - sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::BACKUP; - auto ret = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME, ""); - EXPECT_FALSE(ret); + EXPECT_TRUE(sessionManagerPtr_ != nullptr); + sessionManagerPtr_->impl_.backupExtNameMap.clear(); + sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; + sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; + sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::BACKUP; + bool fileReady = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME, ""); + EXPECT_FALSE(fileReady); - sessionManagerPtr_->impl_.backupExtNameMap.clear(); - sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::BACKUP; - ret = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME, "test"); - EXPECT_FALSE(ret); + sessionManagerPtr_->impl_.backupExtNameMap.clear(); + sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; + sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; + sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::BACKUP; + fileReady = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME, "test"); + EXPECT_FALSE(fileReady); - sessionManagerPtr_->impl_.backupExtNameMap.clear(); - sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::BACKUP; - ret = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME, string(BConstants::EXT_BACKUP_MANAGE)); - EXPECT_FALSE(ret); + sessionManagerPtr_->impl_.backupExtNameMap.clear(); + sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; + sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; + sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::BACKUP; + fileReady = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME, string(BConstants::EXT_BACKUP_MANAGE)); + EXPECT_FALSE(fileReady); - BackupExtInfo info; - info.receExtManageJson = true; - sessionManagerPtr_->impl_.backupExtNameMap.clear(); - sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = info; - ret = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME, ""); - EXPECT_TRUE(ret); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by onBundlefileready."; - } + BackupExtInfo info; + info.receExtManageJson = true; + sessionManagerPtr_->impl_.backupExtNameMap.clear(); + sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; + sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = info; + fileReady = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME, ""); + EXPECT_TRUE(fileReady); GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_onBundlefileready_0101"; } @@ -413,42 +395,29 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_onBundlefileready_0101, te HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_OnBundleExtManageInfo_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_OnBundleExtManageInfo_0100"; - try { - try { - EXPECT_TRUE(sessionManagerPtr_ != nullptr); - sessionManagerPtr_->impl_.clientToken = 0; - sessionManagerPtr_->OnBundleExtManageInfo(BUNDLE_NAME, UniqueFd(-1)); - EXPECT_TRUE(false); - } catch (BError &err) { - EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG); - } - - try { - sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::RESTORE; - sessionManagerPtr_->OnBundleExtManageInfo(BUNDLE_NAME, UniqueFd(-1)); - EXPECT_TRUE(false); - } catch (BError &err) { - EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG); - } + EXPECT_TRUE(sessionManagerPtr_ != nullptr); + sessionManagerPtr_->impl_.clientToken = 0; + auto ret = sessionManagerPtr_->OnBundleExtManageInfo(BUNDLE_NAME, UniqueFd(-1)); + EXPECT_TRUE(move(ret) == -1); - TestManager tm("SvcSessionManagerTest_GetFd_0100"); - string filePath = tm.GetRootDirCurTest().append(MANAGE_JSON); - SaveStringToFile(filePath, R"({"fileName" : "1.tar"})"); - UniqueFd fd(open(filePath.data(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)); - sessionManagerPtr_->OnBundleExtManageInfo(BUNDLE_NAME, move(fd)); - auto ret = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME); - EXPECT_FALSE(ret); - ret = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME, FILE_NAME); - EXPECT_FALSE(ret); - ret = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME, MANAGE_JSON); - EXPECT_FALSE(ret); - ret = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME, FILE_NAME); - EXPECT_TRUE(ret); - } catch (...) { - EXPECT_FALSE(false); - GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by OnBundleExtManageInfo."; - } + sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; + sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::RESTORE; + ret = sessionManagerPtr_->OnBundleExtManageInfo(BUNDLE_NAME, UniqueFd(-1)); + EXPECT_TRUE(move(ret) == -1); + + TestManager tm("SvcSessionManagerTest_GetFd_0100"); + string filePath = tm.GetRootDirCurTest().append(MANAGE_JSON); + SaveStringToFile(filePath, R"({"fileName" : "1.tar"})"); + UniqueFd fd(open(filePath.data(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)); + sessionManagerPtr_->OnBundleExtManageInfo(BUNDLE_NAME, move(fd)); + bool fileReady = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME); + EXPECT_TRUE(fileReady); + fileReady = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME, FILE_NAME); + EXPECT_TRUE(fileReady); + fileReady = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME, MANAGE_JSON); + EXPECT_TRUE(fileReady); + fileReady = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME, FILE_NAME); + EXPECT_TRUE(fileReady); GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_OnBundleExtManageInfo_0100"; } @@ -562,14 +531,10 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetExtFileNameRequest_0100 { GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_GetExtFileNameRequest_0100"; try { - try { - EXPECT_TRUE(sessionManagerPtr_ != nullptr); - sessionManagerPtr_->impl_.clientToken = 0; - sessionManagerPtr_->SetExtFileNameRequest(BUNDLE_NAME, FILE_NAME); - EXPECT_TRUE(false); - } catch (BError &err) { - EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG); - } + EXPECT_TRUE(sessionManagerPtr_ != nullptr); + sessionManagerPtr_->impl_.clientToken = 0; + sessionManagerPtr_->SetExtFileNameRequest(BUNDLE_NAME, FILE_NAME); + EXPECT_TRUE(true); sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; sessionManagerPtr_->impl_.backupExtNameMap.clear(); @@ -596,19 +561,10 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetExtFileNameRequest_0100 HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetExtFileNameRequest_0101, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_GetExtFileNameRequest_0101"; - try { - try { - EXPECT_TRUE(sessionManagerPtr_ != nullptr); - sessionManagerPtr_->impl_.clientToken = 0; - sessionManagerPtr_->GetExtFileNameRequest(BUNDLE_NAME); - EXPECT_TRUE(true); - } catch (BError &err) { - EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG); - } - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by GetExtFileNameRequest."; - } + EXPECT_TRUE(sessionManagerPtr_ != nullptr); + sessionManagerPtr_->impl_.clientToken = 0; + auto fileNameSet = sessionManagerPtr_->GetExtFileNameRequest(BUNDLE_NAME); + EXPECT_TRUE(fileNameSet.empty()); GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_GetExtFileNameRequest_0101"; } @@ -624,20 +580,11 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetExtFileNameRequest_0101 HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetExtFileNameRequest_0102, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_GetExtFileNameRequest_0102"; - try { - try { - EXPECT_TRUE(sessionManagerPtr_ != nullptr); - sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::UNDEFINED; - sessionManagerPtr_->GetExtFileNameRequest(BUNDLE_NAME); - EXPECT_TRUE(true); - } catch (BError &err) { - EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG); - } - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by GetExtFileNameRequest."; - } + EXPECT_TRUE(sessionManagerPtr_ != nullptr); + sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; + sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::UNDEFINED; + auto fileNameSet = sessionManagerPtr_->GetExtFileNameRequest(BUNDLE_NAME); + EXPECT_TRUE(fileNameSet.empty()); GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_GetExtFileNameRequest_0102"; } @@ -653,20 +600,11 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetExtFileNameRequest_0102 HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetExtFileNameRequest_0103, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_GetExtFileNameRequest_0103"; - try { - try { - EXPECT_TRUE(sessionManagerPtr_ != nullptr); - sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::RESTORE; - sessionManagerPtr_->GetExtFileNameRequest(BUNDLE_NAME); - EXPECT_TRUE(true); - } catch (BError &err) { - EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG); - } - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by GetExtFileNameRequest."; - } + EXPECT_TRUE(sessionManagerPtr_ != nullptr); + sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; + sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::RESTORE; + auto fileNameSet = sessionManagerPtr_->GetExtFileNameRequest(BUNDLE_NAME); + EXPECT_FALSE(fileNameSet.empty()); GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_GetExtFileNameRequest_0103"; } @@ -719,44 +657,30 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetExtConnection_0100, tes HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetSAExtConnection_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_GetSAExtConnection_0100"; - try { - try { - EXPECT_TRUE(sessionManagerPtr_ != nullptr); - sessionManagerPtr_->impl_.clientToken = 0; - sessionManagerPtr_->GetSAExtConnection(BUNDLE_NAME); - EXPECT_TRUE(false); - } catch (BError &err) { - EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG); - } + EXPECT_TRUE(sessionManagerPtr_ != nullptr); + sessionManagerPtr_->impl_.clientToken = 0; + auto tempConnPtr = sessionManagerPtr_->GetSAExtConnection(BUNDLE_NAME); + auto backupConnPtr = tempConnPtr.lock(); + EXPECT_TRUE(backupConnPtr == nullptr); - try { - sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->impl_.backupExtNameMap.clear(); - sessionManagerPtr_->GetSAExtConnection(BUNDLE_NAME); - EXPECT_TRUE(false); - } catch (BError &err) { - EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_REFUSED_ACT); - } + sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; + sessionManagerPtr_->impl_.backupExtNameMap.clear(); + tempConnPtr = sessionManagerPtr_->GetSAExtConnection(BUNDLE_NAME); + backupConnPtr = tempConnPtr.lock(); + EXPECT_TRUE(backupConnPtr == nullptr); - try { - sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; - sessionManagerPtr_->GetSAExtConnection(BUNDLE_NAME); - EXPECT_TRUE(false); - } catch (BError &err) { - EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG); - } + sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; + sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; + tempConnPtr = sessionManagerPtr_->GetSAExtConnection(BUNDLE_NAME); + backupConnPtr = tempConnPtr.lock(); + EXPECT_TRUE(backupConnPtr == nullptr); - BackupExtInfo info; - info.saBackupConnection = make_shared(nullptr, nullptr, nullptr, nullptr); - sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = info; - auto ret = sessionManagerPtr_->GetSAExtConnection(BUNDLE_NAME).lock(); - EXPECT_EQ(reinterpret_cast(ret.get()), reinterpret_cast(info.saBackupConnection.get())); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by GetSAExtConnection."; - } + BackupExtInfo info; + info.saBackupConnection = make_shared(nullptr, nullptr, nullptr, nullptr); + sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; + sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = info; + auto ret = sessionManagerPtr_->GetSAExtConnection(BUNDLE_NAME).lock(); + EXPECT_EQ(reinterpret_cast(ret.get()), reinterpret_cast(info.saBackupConnection.get())); GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_GetSAExtConnection_0100"; } @@ -895,37 +819,22 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetServiceSchedAction_0102 HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetServiceSchedAction_0103, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_GetServiceSchedAction_0103"; - try { - string bundleName = ""; - EXPECT_TRUE(sessionManagerPtr_ != nullptr); - auto action = sessionManagerPtr_->GetServiceSchedAction(bundleName); - EXPECT_EQ(action, BConstants::ServiceSchedAction::WAIT); + string bundleName = ""; + EXPECT_TRUE(sessionManagerPtr_ != nullptr); + auto action = sessionManagerPtr_->GetServiceSchedAction(bundleName); + EXPECT_EQ(action, BConstants::ServiceSchedAction::UNKNOWN); - sessionManagerPtr_->SetServiceSchedAction(bundleName, BConstants::ServiceSchedAction::START); - action = sessionManagerPtr_->GetServiceSchedAction(bundleName); - EXPECT_NE(action, BConstants::ServiceSchedAction::START); - GTEST_LOG_(INFO) << "SvcSessionManagerTest-SetServiceSchedAction Branches"; - sessionManagerPtr_->SetServiceSchedAction(bundleName, BConstants::ServiceSchedAction::FINISH); + EXPECT_THROW(sessionManagerPtr_->SetServiceSchedAction(bundleName, BConstants::ServiceSchedAction::START), BError); + action = sessionManagerPtr_->GetServiceSchedAction(bundleName); + EXPECT_EQ(action, BConstants::ServiceSchedAction::UNKNOWN); - try { - sessionManagerPtr_->impl_.clientToken = 0; - sessionManagerPtr_->GetServiceSchedAction(bundleName); - EXPECT_TRUE(false); - } catch (BError &err) { - EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG); - } + sessionManagerPtr_->impl_.clientToken = 0; + action = sessionManagerPtr_->GetServiceSchedAction(bundleName); + EXPECT_TRUE(action == BConstants::ServiceSchedAction::UNKNOWN); - try { - sessionManagerPtr_->impl_.clientToken = 0; - sessionManagerPtr_->SetServiceSchedAction(bundleName, BConstants::ServiceSchedAction::START); - EXPECT_TRUE(false); - } catch (BError &err) { - EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG); - } - } catch (...) { - EXPECT_FALSE(false); - GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by GetServiceSchedAction."; - } + sessionManagerPtr_->impl_.clientToken = 0; + EXPECT_THROW(sessionManagerPtr_->SetServiceSchedAction(bundleName, BConstants::ServiceSchedAction::START), BError); + EXPECT_TRUE(true); GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_GetServiceSchedAction_0103"; } @@ -945,7 +854,7 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetBackupExtName_0100, tes EXPECT_TRUE(sessionManagerPtr_ != nullptr); sessionManagerPtr_->SetBackupExtName(BUNDLE_NAME, BUNDLE_NAME); string extName = sessionManagerPtr_->GetBackupExtName(BUNDLE_NAME); - EXPECT_EQ(extName, BUNDLE_NAME); + EXPECT_EQ(extName, ""); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by GetBackupExtName."; @@ -965,32 +874,19 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetBackupExtName_0100, tes HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetBackupExtName_0101, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_GetBackupExtName_0101"; - try { - string bundleName = ""; - try { - EXPECT_TRUE(sessionManagerPtr_ != nullptr); - sessionManagerPtr_->impl_.clientToken = 0; - sessionManagerPtr_->SetBackupExtName(bundleName, bundleName); - EXPECT_TRUE(false); - } catch (BError &err) { - EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG); - } + string bundleName = ""; + EXPECT_TRUE(sessionManagerPtr_ != nullptr); + sessionManagerPtr_->impl_.clientToken = 0; + sessionManagerPtr_->SetBackupExtName(bundleName, bundleName); + EXPECT_TRUE(true); - try { - sessionManagerPtr_->impl_.clientToken = 0; - sessionManagerPtr_->GetBackupExtName(bundleName); - EXPECT_TRUE(false); - } catch (BError &err) { - EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG); - } + sessionManagerPtr_->impl_.clientToken = 0; + auto backupExtName = sessionManagerPtr_->GetBackupExtName(bundleName); + EXPECT_EQ(backupExtName, ""); - sessionManagerPtr_->SetBackupExtName(bundleName, bundleName); - string extName = sessionManagerPtr_->GetBackupExtName(bundleName); - EXPECT_NE(extName, bundleName); - } catch (...) { - EXPECT_FALSE(false); - GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by GetBackupExtName."; - } + sessionManagerPtr_->SetBackupExtName(bundleName, bundleName); + string extName = sessionManagerPtr_->GetBackupExtName(bundleName); + EXPECT_EQ(extName, ""); GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_GetBackupExtName_0101"; } @@ -1006,27 +902,18 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetBackupExtName_0101, tes HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_SetBackupExtInfo_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_SetBackupExtInfo_0100"; - try { - string bundleName = BUNDLE_NAME; - string extInfo = "test"; - try { - EXPECT_TRUE(sessionManagerPtr_ != nullptr); - sessionManagerPtr_->impl_.clientToken = 0; - sessionManagerPtr_->SetBackupExtInfo(bundleName, extInfo); - EXPECT_TRUE(false); - } catch (BError &err) { - EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG); - } + string bundleName = BUNDLE_NAME; + string extInfo = "test"; + EXPECT_TRUE(sessionManagerPtr_ != nullptr); + sessionManagerPtr_->impl_.clientToken = 0; + sessionManagerPtr_->SetBackupExtInfo(bundleName, extInfo); + EXPECT_TRUE(true); - sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->impl_.backupExtNameMap.clear(); - sessionManagerPtr_->impl_.backupExtNameMap[bundleName] = {}; - sessionManagerPtr_->SetBackupExtInfo(bundleName, extInfo); - EXPECT_EQ(sessionManagerPtr_->impl_.backupExtNameMap.size(), 1); - } catch (...) { - EXPECT_FALSE(false); - GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by SetBackupExtInfo."; - } + sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; + sessionManagerPtr_->impl_.backupExtNameMap.clear(); + sessionManagerPtr_->impl_.backupExtNameMap[bundleName] = {}; + sessionManagerPtr_->SetBackupExtInfo(bundleName, extInfo); + EXPECT_EQ(sessionManagerPtr_->impl_.backupExtNameMap.size(), 1); GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_SetBackupExtInfo_0100"; } @@ -1042,29 +929,20 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_SetBackupExtInfo_0100, tes HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetBackupExtInfo_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_GetBackupExtInfo_0100"; - try { - string bundleName = BUNDLE_NAME; - string extInfo = "test"; - try { - EXPECT_TRUE(sessionManagerPtr_ != nullptr); - sessionManagerPtr_->impl_.clientToken = 0; - sessionManagerPtr_->GetBackupExtInfo(bundleName); - EXPECT_TRUE(false); - } catch (BError &err) { - EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG); - } + string bundleName = BUNDLE_NAME; + string extInfo = "test"; + EXPECT_TRUE(sessionManagerPtr_ != nullptr); + sessionManagerPtr_->impl_.clientToken = 0; + auto extInfoRet = sessionManagerPtr_->GetBackupExtInfo(bundleName); + EXPECT_EQ(extInfoRet, ""); - BackupExtInfo info; - info.extInfo = "test"; - sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->impl_.backupExtNameMap.clear(); - sessionManagerPtr_->impl_.backupExtNameMap[bundleName] = info; - auto ret = sessionManagerPtr_->GetBackupExtInfo(bundleName); - EXPECT_EQ(ret, "test"); - } catch (...) { - EXPECT_FALSE(false); - GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by GetBackupExtInfo."; - } + BackupExtInfo info; + info.extInfo = "test"; + sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; + sessionManagerPtr_->impl_.backupExtNameMap.clear(); + sessionManagerPtr_->impl_.backupExtNameMap[bundleName] = info; + auto ret = sessionManagerPtr_->GetBackupExtInfo(bundleName); + EXPECT_EQ(ret, "test"); GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_GetBackupExtInfo_0100"; } @@ -1082,14 +960,10 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_AppendBundles_0100, testin GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_AppendBundles_0100"; try { vector bundleNames; - try { - EXPECT_TRUE(sessionManagerPtr_ != nullptr); - sessionManagerPtr_->impl_.clientToken = 0; - sessionManagerPtr_->AppendBundles(bundleNames); - EXPECT_TRUE(false); - } catch (BError &err) { - EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG); - } + EXPECT_TRUE(sessionManagerPtr_ != nullptr); + sessionManagerPtr_->impl_.clientToken = 0; + sessionManagerPtr_->AppendBundles(bundleNames); + EXPECT_TRUE(true); bundleNames.clear(); bundleNames.emplace_back("app1"); @@ -1204,12 +1078,12 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_OnBundleFileReady_0200, te EXPECT_TRUE(sessionManagerPtr_ != nullptr); sessionManagerPtr_->Deactive(nullptr, true); Init(IServiceReverse::Scenario::BACKUP); - auto ret = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME, MANAGE_JSON); - EXPECT_FALSE(ret); - ret = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME, FILE_NAME); - EXPECT_FALSE(ret); - ret = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME, FILE_NAME); - EXPECT_FALSE(ret); + bool fileReady = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME, MANAGE_JSON); + EXPECT_FALSE(fileReady); + fileReady = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME, FILE_NAME); + EXPECT_FALSE(fileReady); + fileReady = sessionManagerPtr_->OnBundleFileReady(BUNDLE_NAME, FILE_NAME); + EXPECT_FALSE(fileReady); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by OnBundleFileReady."; @@ -1325,25 +1199,16 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetOldBackupVersion_0100, HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_SetBundleRestoreType_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_SetBundleRestoreType_0100"; - try { - try { - EXPECT_TRUE(sessionManagerPtr_ != nullptr); - sessionManagerPtr_->impl_.clientToken = 0; - sessionManagerPtr_->SetBundleRestoreType(BUNDLE_NAME, RESTORE_DATA_READDY); - EXPECT_TRUE(false); - } catch (BError &err) { - EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG); - } + EXPECT_TRUE(sessionManagerPtr_ != nullptr); + sessionManagerPtr_->impl_.clientToken = 0; + sessionManagerPtr_->SetBundleRestoreType(BUNDLE_NAME, RESTORE_DATA_READDY); + EXPECT_TRUE(true); - sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->impl_.backupExtNameMap.clear(); - sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; - sessionManagerPtr_->SetBundleRestoreType(BUNDLE_NAME, RESTORE_DATA_READDY); - EXPECT_EQ(sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME].restoreType, RESTORE_DATA_READDY); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by SetBundleRestoreType."; - } + sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; + sessionManagerPtr_->impl_.backupExtNameMap.clear(); + sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; + sessionManagerPtr_->SetBundleRestoreType(BUNDLE_NAME, RESTORE_DATA_READDY); + EXPECT_EQ(sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME].restoreType, RESTORE_DATA_READDY); GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_SetBundleRestoreType_0100"; } @@ -1359,25 +1224,17 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_SetBundleRestoreType_0100, HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetBundleRestoreType_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_GetBundleRestoreType_0100"; - try { - try { - EXPECT_TRUE(sessionManagerPtr_ != nullptr); - sessionManagerPtr_->impl_.clientToken = 0; - sessionManagerPtr_->GetBundleRestoreType(BUNDLE_NAME); - EXPECT_TRUE(false); - } catch (BError &err) { - EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG); - } + EXPECT_TRUE(sessionManagerPtr_ != nullptr); + sessionManagerPtr_->impl_.clientToken = 0; + auto restoreType = sessionManagerPtr_->GetBundleRestoreType(BUNDLE_NAME); + EXPECT_TRUE(restoreType == RestoreTypeEnum::RESTORE_DATA_WAIT_SEND); - sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->impl_.backupExtNameMap.clear(); - sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; - sessionManagerPtr_->GetBundleRestoreType(BUNDLE_NAME); - EXPECT_TRUE(true); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by GetBundleRestoreType."; - } + sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; + sessionManagerPtr_->impl_.backupExtNameMap.clear(); + sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; + restoreType = sessionManagerPtr_->GetBundleRestoreType(BUNDLE_NAME); + EXPECT_TRUE(restoreType == RestoreTypeEnum::RESTORE_DATA_WAIT_SEND); + EXPECT_TRUE(true); GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_GetBundleRestoreType_0100"; } @@ -1393,25 +1250,16 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetBundleRestoreType_0100, HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_SetBundleVersionCode_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_SetBundleVersionCode_0100"; - try { - try { - EXPECT_TRUE(sessionManagerPtr_ != nullptr); - sessionManagerPtr_->impl_.clientToken = 0; - sessionManagerPtr_->SetBundleVersionCode(BUNDLE_NAME, 0); - EXPECT_TRUE(false); - } catch (BError &err) { - EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG); - } + EXPECT_TRUE(sessionManagerPtr_ != nullptr); + sessionManagerPtr_->impl_.clientToken = 0; + sessionManagerPtr_->SetBundleVersionCode(BUNDLE_NAME, 0); + EXPECT_TRUE(true); - sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->impl_.backupExtNameMap.clear(); - sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; - sessionManagerPtr_->SetBundleVersionCode(BUNDLE_NAME, 0); - EXPECT_EQ(sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME].versionCode, 0); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by SetBundleVersionCode."; - } + sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; + sessionManagerPtr_->impl_.backupExtNameMap.clear(); + sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; + sessionManagerPtr_->SetBundleVersionCode(BUNDLE_NAME, 0); + EXPECT_EQ(sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME].versionCode, 0); GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_SetBundleVersionCode_0100"; } @@ -1427,25 +1275,16 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_SetBundleVersionCode_0100, HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetBundleVersionCode_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_GetBundleVersionCode_0100"; - try { - try { - EXPECT_TRUE(sessionManagerPtr_ != nullptr); - sessionManagerPtr_->impl_.clientToken = 0; - sessionManagerPtr_->GetBundleVersionCode(BUNDLE_NAME); - EXPECT_TRUE(false); - } catch (BError &err) { - EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG); - } + EXPECT_TRUE(sessionManagerPtr_ != nullptr); + sessionManagerPtr_->impl_.clientToken = 0; + auto versionCode = sessionManagerPtr_->GetBundleVersionCode(BUNDLE_NAME); + EXPECT_TRUE(versionCode == 0); - sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->impl_.backupExtNameMap.clear(); - sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; - sessionManagerPtr_->GetBundleVersionCode(BUNDLE_NAME); - EXPECT_TRUE(true); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by GetBundleVersionCode."; - } + sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; + sessionManagerPtr_->impl_.backupExtNameMap.clear(); + sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; + sessionManagerPtr_->GetBundleVersionCode(BUNDLE_NAME); + EXPECT_TRUE(true); GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_GetBundleVersionCode_0100"; } @@ -1462,14 +1301,10 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_SetBundleVersionName_0100, { GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_SetBundleVersionName_0100"; try { - try { - EXPECT_TRUE(sessionManagerPtr_ != nullptr); - sessionManagerPtr_->impl_.clientToken = 0; - sessionManagerPtr_->SetBundleVersionName(BUNDLE_NAME, "1.0.0"); - EXPECT_TRUE(false); - } catch (BError &err) { - EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG); - } + EXPECT_TRUE(sessionManagerPtr_ != nullptr); + sessionManagerPtr_->impl_.clientToken = 0; + sessionManagerPtr_->SetBundleVersionName(BUNDLE_NAME, "1.0.0"); + EXPECT_TRUE(true); sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; sessionManagerPtr_->impl_.backupExtNameMap.clear(); @@ -1495,25 +1330,16 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_SetBundleVersionName_0100, HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetBundleVersionName_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_GetBundleVersionName_0100"; - try { - try { - EXPECT_TRUE(sessionManagerPtr_ != nullptr); - sessionManagerPtr_->impl_.clientToken = 0; - sessionManagerPtr_->GetBundleVersionName(BUNDLE_NAME); - EXPECT_TRUE(false); - } catch (BError &err) { - EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG); - } + EXPECT_TRUE(sessionManagerPtr_ != nullptr); + sessionManagerPtr_->impl_.clientToken = 0; + auto versionStr = sessionManagerPtr_->GetBundleVersionName(BUNDLE_NAME); + EXPECT_EQ(versionStr, ""); - sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->impl_.backupExtNameMap.clear(); - sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; - sessionManagerPtr_->GetBundleVersionName(BUNDLE_NAME); - EXPECT_TRUE(true); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by GetBundleVersionName."; - } + sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; + sessionManagerPtr_->impl_.backupExtNameMap.clear(); + sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; + versionStr = sessionManagerPtr_->GetBundleVersionName(BUNDLE_NAME); + EXPECT_EQ(versionStr, ""); GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_GetBundleVersionName_0100"; } @@ -1585,29 +1411,20 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_Finish_0100, testing::ext: HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_IsOnAllBundlesFinished_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_IsOnAllBundlesFinished_0100"; - try { - try { - EXPECT_TRUE(sessionManagerPtr_ != nullptr); - sessionManagerPtr_->impl_.clientToken = 0; - sessionManagerPtr_->IsOnAllBundlesFinished(); - EXPECT_TRUE(false); - } catch (BError &err) { - EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG); - } + EXPECT_TRUE(sessionManagerPtr_ != nullptr); + sessionManagerPtr_->impl_.clientToken = 0; + bool ret = sessionManagerPtr_->IsOnAllBundlesFinished(); + EXPECT_FALSE(ret); - sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::RESTORE; - sessionManagerPtr_->IsOnAllBundlesFinished(); - EXPECT_TRUE(true); + sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; + sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::RESTORE; + ret = sessionManagerPtr_->IsOnAllBundlesFinished(); + EXPECT_FALSE(ret); - sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::UNDEFINED; - sessionManagerPtr_->IsOnAllBundlesFinished(); - EXPECT_TRUE(true); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by IsOnAllBundlesFinished."; - } + sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; + sessionManagerPtr_->impl_.scenario = IServiceReverse::Scenario::UNDEFINED; + ret = sessionManagerPtr_->IsOnAllBundlesFinished(); + EXPECT_FALSE(ret); GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_IsOnAllBundlesFinished_0100"; } @@ -1624,18 +1441,14 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_IsOnOnStartSched_0100, tes { GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_IsOnOnStartSched_0100"; try { - try { - EXPECT_TRUE(sessionManagerPtr_ != nullptr); - sessionManagerPtr_->impl_.clientToken = 0; - sessionManagerPtr_->IsOnOnStartSched(); - EXPECT_TRUE(false); - } catch (BError &err) { - EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG); - } + EXPECT_TRUE(sessionManagerPtr_ != nullptr); + sessionManagerPtr_->impl_.clientToken = 0; + auto ret = sessionManagerPtr_->IsOnOnStartSched(); + EXPECT_FALSE(ret); sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; sessionManagerPtr_->impl_.isBackupStart = false; - auto ret = sessionManagerPtr_->IsOnOnStartSched(); + ret = sessionManagerPtr_->IsOnOnStartSched(); sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; sessionManagerPtr_->impl_.isBackupStart = true; @@ -1668,14 +1481,10 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_SetBundleDataSize_0100, te { GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_SetBundleDataSize_0100"; try { - try { - EXPECT_TRUE(sessionManagerPtr_ != nullptr); - sessionManagerPtr_->impl_.clientToken = 0; - sessionManagerPtr_->SetBundleDataSize(BUNDLE_NAME, 0); - EXPECT_TRUE(false); - } catch (BError &err) { - EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG); - } + EXPECT_TRUE(sessionManagerPtr_ != nullptr); + sessionManagerPtr_->impl_.clientToken = 0; + sessionManagerPtr_->SetBundleDataSize(BUNDLE_NAME, 0); + EXPECT_TRUE(true); sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; sessionManagerPtr_->impl_.backupExtNameMap.clear(); @@ -1754,7 +1563,7 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_UpdateTimer_0100, testing: sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; sessionManagerPtr_->impl_.backupExtNameMap.clear(); - EXPECT_THROW(sessionManagerPtr_->UpdateTimer(BUNDLE_NAME, BConstants::TIMEOUT_INVALID, callback), BError); + EXPECT_FALSE(ret); BackupExtInfo info; info.extTimerStatus = false; @@ -1862,23 +1671,14 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_ClearSessionData_0100, tes HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetIsIncrementalBackup_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_GetIsIncrementalBackup_0100"; - try { - try { - EXPECT_TRUE(sessionManagerPtr_ != nullptr); - sessionManagerPtr_->impl_.clientToken = 0; - sessionManagerPtr_->GetIsIncrementalBackup(); - EXPECT_TRUE(false); - } catch (BError &err) { - EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG); - } + EXPECT_TRUE(sessionManagerPtr_ != nullptr); + sessionManagerPtr_->impl_.clientToken = 0; + bool ret = sessionManagerPtr_->GetIsIncrementalBackup(); + EXPECT_FALSE(ret); - sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->GetIsIncrementalBackup(); - EXPECT_TRUE(true); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by GetIsIncrementalBackup."; - } + sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; + ret = sessionManagerPtr_->GetIsIncrementalBackup(); + EXPECT_FALSE(ret); GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_GetIsIncrementalBackup_0100"; } @@ -1896,14 +1696,10 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_SetIncrementalData_0100, t GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_SetIncrementalData_0100"; try { BIncrementalData incrementalData; - try { - EXPECT_TRUE(sessionManagerPtr_ != nullptr); - sessionManagerPtr_->impl_.clientToken = 0; - sessionManagerPtr_->SetIncrementalData(incrementalData); - EXPECT_TRUE(false); - } catch (BError &err) { - EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG); - } + EXPECT_TRUE(sessionManagerPtr_ != nullptr); + sessionManagerPtr_->impl_.clientToken = 0; + sessionManagerPtr_->SetIncrementalData(incrementalData); + EXPECT_TRUE(true); incrementalData.bundleName = BUNDLE_NAME; sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; @@ -1930,25 +1726,16 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_SetIncrementalData_0100, t HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetIncrementalManifestFd_0100, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_GetIncrementalManifestFd_0100"; - try { - try { - EXPECT_TRUE(sessionManagerPtr_ != nullptr); - sessionManagerPtr_->impl_.clientToken = 0; - sessionManagerPtr_->GetIncrementalManifestFd(BUNDLE_NAME); - EXPECT_TRUE(false); - } catch (BError &err) { - EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG); - } + EXPECT_TRUE(sessionManagerPtr_ != nullptr); + sessionManagerPtr_->impl_.clientToken = 0; + auto ret = sessionManagerPtr_->GetIncrementalManifestFd(BUNDLE_NAME); + EXPECT_TRUE(ret == -1); - sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; - sessionManagerPtr_->impl_.backupExtNameMap.clear(); - sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; - sessionManagerPtr_->GetIncrementalManifestFd(BUNDLE_NAME); - EXPECT_TRUE(true); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "SvcSessionManagerTest-an exception occurred by GetIncrementalManifestFd."; - } + sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; + sessionManagerPtr_->impl_.backupExtNameMap.clear(); + sessionManagerPtr_->impl_.backupExtNameMap[BUNDLE_NAME] = {}; + ret = sessionManagerPtr_->GetIncrementalManifestFd(BUNDLE_NAME); + EXPECT_TRUE(ret == 0); GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_session_GetIncrementalManifestFd_0100"; } @@ -2048,14 +1835,10 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_SetClearDataFlag_0100, tes { GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_SetClearDataFlag_0100"; try { - try { - EXPECT_TRUE(sessionManagerPtr_ != nullptr); - sessionManagerPtr_->impl_.clientToken = 0; - sessionManagerPtr_->SetClearDataFlag(BUNDLE_NAME, false); - EXPECT_TRUE(false); - } catch (BError &err) { - EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG); - } + EXPECT_TRUE(sessionManagerPtr_ != nullptr); + sessionManagerPtr_->impl_.clientToken = 0; + sessionManagerPtr_->SetClearDataFlag(BUNDLE_NAME, false); + EXPECT_TRUE(true); sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; sessionManagerPtr_->impl_.backupExtNameMap.clear(); @@ -2085,14 +1868,10 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetClearDataFlag_0100, tes { GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_GetClearDataFlag_0100"; try { - try { - EXPECT_TRUE(sessionManagerPtr_ != nullptr); - sessionManagerPtr_->impl_.clientToken = 0; - sessionManagerPtr_->GetClearDataFlag(BUNDLE_NAME); - EXPECT_TRUE(false); - } catch (BError &err) { - EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG); - } + EXPECT_TRUE(sessionManagerPtr_ != nullptr); + sessionManagerPtr_->impl_.clientToken = 0; + auto ret = sessionManagerPtr_->GetClearDataFlag(BUNDLE_NAME); + EXPECT_TRUE(ret); sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; sessionManagerPtr_->impl_.backupExtNameMap.clear(); @@ -2122,14 +1901,10 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_SetPublishFlag_0100, testi { GTEST_LOG_(INFO) << "SvcSessionManagerTest-begin SUB_backup_sa_session_SetPublishFlag_0100"; try { - try { - EXPECT_TRUE(sessionManagerPtr_ != nullptr); - sessionManagerPtr_->impl_.clientToken = 0; - sessionManagerPtr_->SetPublishFlag(BUNDLE_NAME); - EXPECT_TRUE(false); - } catch (BError &err) { - EXPECT_EQ(err.GetRawCode(), BError::Codes::SA_INVAL_ARG); - } + EXPECT_TRUE(sessionManagerPtr_ != nullptr); + sessionManagerPtr_->impl_.clientToken = 0; + sessionManagerPtr_->SetPublishFlag(BUNDLE_NAME); + EXPECT_TRUE(true); sessionManagerPtr_->impl_.clientToken = CLIENT_TOKEN_ID; sessionManagerPtr_->impl_.backupExtNameMap.clear(); diff --git a/utils/include/b_resources/b_constants.h b/utils/include/b_resources/b_constants.h index 71253a756447a721f3ad000aeb373a83ee6863a9..7ad1b2e2579a410ed6467b02c4d5d16e7a81530c 100644 --- a/utils/include/b_resources/b_constants.h +++ b/utils/include/b_resources/b_constants.h @@ -45,6 +45,7 @@ enum ServiceSchedAction { RUNNING = 2, FINISH = 3, CLEAN = 4, + UNKNOWN = 5, }; constexpr int SPAN_USERID_UID = 200000;