diff --git a/services/backup_sa/BUILD.gn b/services/backup_sa/BUILD.gn index 027216afec711a3d02b3a8d4491d79a0f572ddbd..21b78cac54a155c8a4adf4ea2f63b8250d0b7591 100644 --- a/services/backup_sa/BUILD.gn +++ b/services/backup_sa/BUILD.gn @@ -36,6 +36,7 @@ ohos_shared_library("backup_sa") { "src/module_ipc/service_incremental_reverse_proxy.cpp", "src/module_ipc/service_reverse_proxy.cpp", "src/module_ipc/service_stub.cpp", + "src/module_ipc/sub_service.cpp", "src/module_ipc/svc_backup_connection.cpp", "src/module_ipc/svc_extension_incremental_proxy.cpp", "src/module_ipc/svc_extension_proxy.cpp", diff --git a/services/backup_sa/src/module_external/bms_adapter.cpp b/services/backup_sa/src/module_external/bms_adapter.cpp index f6e9fe5f10dc6652b141e93474700a828dab2315..66b775c401cfe6afe883ce73f90e8fef320f8061 100644 --- a/services/backup_sa/src/module_external/bms_adapter.cpp +++ b/services/backup_sa/src/module_external/bms_adapter.cpp @@ -133,7 +133,7 @@ vector BundleMgrAdapter::GetBundleInfos(const vecto GetAllowAndExtName(extensionInfos); int64_t dataSize = 0; if (allToBackup) { - dataSize = GetBundleStats(installedBundle.name, userId); + dataSize = GetBundleStats(bundleName, userId); } bundleInfos.emplace_back(BJsonEntityCaps::BundleInfo {installedBundle.name, installedBundle.appIndex, installedBundle.versionCode, @@ -191,8 +191,18 @@ static bool CreateIPCInteractionFiles(int32_t userId, const string &bundleName, const vector &includes, const vector &excludes) { // backup_sa bundle path - string backupSaBundleDir = BConstants::BACKUP_PATH_PREFIX + to_string(userId) + BConstants::BACKUP_PATH_SURFFIX + - bundleName + BConstants::FILE_SEPARATOR_CHAR; + BJsonUtil::BundleDetailInfo bundleDetail = BJsonUtil::ParseBundleNameIndexStr(bundleName); + string backupSaBundleDir; + if (bundleDetail.bundleIndex > 0) { + std::string bundleNameIndex = "+clone-" + std::to_string(bundleDetail.bundleIndex) + "+" + + bundleDetail.bundleName; + backupSaBundleDir = BConstants::BACKUP_PATH_PREFIX + to_string(userId) + BConstants::BACKUP_PATH_SURFFIX + + bundleNameIndex + BConstants::FILE_SEPARATOR_CHAR; + } else { + backupSaBundleDir = BConstants::BACKUP_PATH_PREFIX + to_string(userId) + BConstants::BACKUP_PATH_SURFFIX + + bundleDetail.bundleName + BConstants::FILE_SEPARATOR_CHAR; + } + HILOGI("bundleInteraction dir is:%{public}s", backupSaBundleDir.c_str()); if (access(backupSaBundleDir.data(), F_OK) != 0) { int32_t err = mkdir(backupSaBundleDir.data(), S_IRWXU | S_IRWXG); if (err != 0 && errno != EEXIST) { @@ -279,7 +289,6 @@ vector BundleMgrAdapter::GetBundleInfosForIncrement auto bms = GetBundleManager(); for (auto const &bundleNameTime : incrementalDataList) { auto bundleName = bundleNameTime.bundleName; - HILOGD("Begin get bundleName:%{private}s", bundleName.c_str()); AppExecFwk::BundleInfo installedBundle; std::vector extensionInfos; bool getBundleSuccess = GetCurBundleExtenionInfo(installedBundle, bundleName, extensionInfos, bms, userId); @@ -289,7 +298,7 @@ vector BundleMgrAdapter::GetBundleInfosForIncrement } struct BJsonEntityCaps::BundleBackupConfigPara backupPara; if (!GetBackupExtConfig(extensionInfos, backupPara)) { - HILOGE("No backup extension ability found"); + HILOGE("No backup extension ability found, bundleName:%{public}s", bundleName.c_str()); continue; } if (!CreateIPCInteractionFiles(userId, bundleName, bundleNameTime.lastIncrementalTime, backupPara.includes, @@ -303,7 +312,13 @@ vector BundleMgrAdapter::GetBundleInfosForIncrement backupPara.extensionName, backupPara.restoreDeps, backupPara.supportScene, backupPara.extraInfo}); - bundleNames.emplace_back(bundleName); + if (installedBundle.appIndex > 0) { + std::string bundleNameIndex = "+clone-" + std::to_string(installedBundle.appIndex) + "+" + + installedBundle.name; + bundleNames.emplace_back(bundleNameIndex); + } else { + bundleNames.emplace_back(bundleName); + } incrementalBackTimes.emplace_back(bundleNameTime.lastIncrementalTime); } vector newBundleInfos {}; @@ -311,7 +326,6 @@ vector BundleMgrAdapter::GetBundleInfosForIncrement HILOGE("Failed to get bundleStats result"); return {}; } - HILOGI("BundleMgrAdapter GetBundleInfosForIncremental end "); return newBundleInfos; } @@ -378,6 +392,12 @@ vector BundleMgrAdapter::GetFullBundleInfos(int32_t HILOGI("Unsupported applications, name : %{public}s", installedBundle.name.data()); continue; } + if (installedBundle.appIndex > 0) { + std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(installedBundle.name, + installedBundle.appIndex); + bundleNames.emplace_back(bundleNameIndexInfo); + continue; + } auto [allToBackup, fullBackupOnly, extName, restoreDeps, supportScene, extraInfo] = GetAllowAndExtName(installedBundle.extensionInfos); if (!allToBackup) { @@ -491,8 +511,6 @@ bool BundleMgrAdapter::GetCurBundleExtenionInfo(AppExecFwk::BundleInfo &installe HILOGE("Unsupported applications, name : %{public}s", installedBundle.name.data()); return false; } - HILOGI("bundleName:%{public}s, hapMoudleInfos size:%{public}zu", bundleName.c_str(), - installedBundle.hapModuleInfos.size()); std::vector hapModuleInfos = installedBundle.hapModuleInfos; for (auto &hapModuleInfo : hapModuleInfos) { extensionInfos.insert(extensionInfos.end(), hapModuleInfo.extensionInfos.begin(), @@ -506,8 +524,14 @@ bool BundleMgrAdapter::IsUser0BundleName(std::string bundleName, int32_t userId) { auto bms = GetBundleManager(); AppExecFwk::BundleInfo installedBundle; - if (!bms->GetBundleInfo(bundleName, AppExecFwk::GET_BUNDLE_WITH_EXTENSION_INFO, installedBundle, userId)) { - HILOGI("GetBundleInfo failed, bundleName:%{public}s", bundleName.c_str()); + BJsonUtil::BundleDetailInfo bundleDetailInfo = BJsonUtil::ParseBundleNameIndexStr(bundleName); + int32_t flags = static_cast(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE) | + static_cast(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY) | + static_cast(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA); + ErrCode ret = bms->GetCloneBundleInfo(bundleDetailInfo.bundleName, flags, bundleDetailInfo.bundleIndex, + installedBundle, userId); + if (ret != ERR_OK) { + HILOGE("bundleName:%{public}s, ret:%{public}d, GetBundle Failed from BMS", bundleName.c_str(), ret); return false; } if (installedBundle.applicationInfo.singleton == true) { diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 8f61c5d1d026b92f542418d818fe54a866d73e84..33f21beda963a0d560f5a81a0267d0a7b8264098 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -75,8 +75,6 @@ REGISTER_SYSTEM_ABILITY_BY_ID(Service, FILEMANAGEMENT_BACKUP_SERVICE_SA_ID, fals namespace { constexpr int32_t DEBUG_ID = 100; -constexpr int32_t INDEX = 3; -constexpr int32_t MS_1000 = 1000; const static string BROADCAST_TYPE = "broadcast"; const std::string FILE_BACKUP_EVENTS = "FILE_BACKUP_EVENTS"; const static string UNICAST_TYPE = "unicast"; @@ -414,8 +412,9 @@ static vector GetRestoreBundleNames(UniqueFd fd, restoreBundleInfos.emplace_back(info); continue; } - auto it = find_if(bundleInfos.begin(), bundleInfos.end(), - [&restoreInfo](const auto &obj) { return obj.name == restoreInfo.name; }); + auto it = find_if(bundleInfos.begin(), bundleInfos.end(), [&restoreInfo](const auto &obj) { + return obj.name == restoreInfo.name && obj.appIndex == restoreInfo.appIndex; + }); if (it == bundleInfos.end()) { HILOGE("Bundle not need restore, bundleName is %{public}s.", restoreInfo.name.c_str()); continue; @@ -502,36 +501,6 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const vector &restoreBundleInfos, - std::vector &restoreBundleNames, RestoreTypeEnum restoreType) -{ - HILOGI("Start"); - for (auto restoreInfo : restoreBundleInfos) { - auto it = find_if(restoreBundleNames.begin(), restoreBundleNames.end(), - [&restoreInfo](const auto &bundleName) { return bundleName == restoreInfo.name; }); - if (it == restoreBundleNames.end()) { - throw BError(BError::Codes::SA_BUNDLE_INFO_EMPTY, "Can't find bundle name"); - } - HILOGI("bundleName: %{public}s, extensionName: %{public}s", restoreInfo.name.c_str(), - restoreInfo.extensionName.c_str()); - if ((restoreInfo.allToBackup == false && !SpecialVersion(restoreInfo.versionName)) || - (restoreInfo.extensionName.empty() && !SAUtils::IsSABundleName(restoreInfo.name))) { - OnBundleStarted(BError(BError::Codes::SA_FORBID_BACKUP_RESTORE), session_, restoreInfo.name); - session_->RemoveExtInfo(restoreInfo.name); - continue; - } - session_->SetBundleRestoreType(restoreInfo.name, restoreType); - session_->SetBundleVersionCode(restoreInfo.name, restoreInfo.versionCode); - session_->SetBundleVersionName(restoreInfo.name, restoreInfo.versionName); - session_->SetBundleDataSize(restoreInfo.name, restoreInfo.spaceOccupied); - session_->SetBackupExtName(restoreInfo.name, restoreInfo.extensionName); - if (BundleMgrAdapter::IsUser0BundleName(restoreInfo.name, session_->GetSessionUserId())) { - SendUserIdToApp(restoreInfo.name, session_->GetSessionUserId()); - } - } - HILOGI("End"); -} - ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const vector &bundleNames, RestoreTypeEnum restoreType, @@ -576,82 +545,6 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, } } -void Service::SetCurrentSessProperties(std::vector &restoreBundleInfos, - std::vector &restoreBundleNames, - std::map> &bundleNameDetailMap, - std::map &isClearDataFlags, RestoreTypeEnum restoreType) -{ - HILOGI("Start"); - for (auto restoreInfo : restoreBundleInfos) { - auto it = find_if(restoreBundleNames.begin(), restoreBundleNames.end(), - [&restoreInfo](const auto &bundleName) { - std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(restoreInfo.name, - restoreInfo.appIndex); - return bundleName == bundleNameIndexInfo; - }); - if (it == restoreBundleNames.end()) { - throw BError(BError::Codes::SA_BUNDLE_INFO_EMPTY, "Can't find bundle name"); - } - HILOGD("bundleName: %{public}s, extensionName: %{public}s", restoreInfo.name.c_str(), - restoreInfo.extensionName.c_str()); - std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(restoreInfo.name, restoreInfo.appIndex); - if ((restoreInfo.allToBackup == false && !SpecialVersion(restoreInfo.versionName)) || - (restoreInfo.extensionName.empty() && !SAUtils::IsSABundleName(restoreInfo.name))) { - OnBundleStarted(BError(BError::Codes::SA_FORBID_BACKUP_RESTORE), session_, restoreInfo.name); - session_->RemoveExtInfo(bundleNameIndexInfo); - continue; - } - session_->SetBundleRestoreType(bundleNameIndexInfo, restoreType); - session_->SetBundleVersionCode(bundleNameIndexInfo, restoreInfo.versionCode); - session_->SetBundleVersionName(bundleNameIndexInfo, restoreInfo.versionName); - session_->SetBundleDataSize(bundleNameIndexInfo, restoreInfo.spaceOccupied); - session_->SetBackupExtName(bundleNameIndexInfo, restoreInfo.extensionName); - auto iter = isClearDataFlags.find(bundleNameIndexInfo); - if (iter != isClearDataFlags.end()) { - session_->SetClearDataFlag(bundleNameIndexInfo, iter->second); - } - BJsonUtil::BundleDetailInfo broadCastInfo; - BJsonUtil::BundleDetailInfo uniCastInfo; - bool broadCastRet = BJsonUtil::FindBundleInfoByName(bundleNameDetailMap, bundleNameIndexInfo, BROADCAST_TYPE, - broadCastInfo); - if (broadCastRet) { - bool notifyRet = - DelayedSingleton::GetInstance()->NotifyBundleDetail(broadCastInfo); - HILOGI("Publish event end, notify result is:%{public}d", notifyRet); - } - bool uniCastRet = BJsonUtil::FindBundleInfoByName(bundleNameDetailMap, bundleNameIndexInfo, UNICAST_TYPE, - uniCastInfo); - if (uniCastRet) { - HILOGI("current bundle, unicast info:%{public}s", GetAnonyString(uniCastInfo.detail).c_str()); - session_->SetBackupExtInfo(bundleNameIndexInfo, uniCastInfo.detail); - } - } - HILOGI("End"); -} - -void Service::SetCurrentSessProperties(BJsonEntityCaps::BundleInfo &info, - std::map &isClearDataFlags) -{ - if (session_ == nullptr) { - return; - } - session_->SetBundleDataSize(info.name, info.spaceOccupied); - session_->SetBackupExtName(info.name, info.extensionName); - auto iter = isClearDataFlags.find(info.name); - if (iter != isClearDataFlags.end()) { - session_->SetClearDataFlag(info.name, iter->second); - } -} - -vector Service::MakeDetailList(const vector &bundleNames) -{ - vector bundleDetails {}; - for (auto bundleName : bundleNames) { - bundleDetails.emplace_back(BIncrementalData {bundleName, 0}); - } - return bundleDetails; -} - ErrCode Service::AppendBundlesBackupSession(const vector &bundleNames) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -666,14 +559,15 @@ ErrCode Service::AppendBundlesBackupSession(const vector &bundleName auto backupInfos = BundleMgrAdapter::GetBundleInfosForAppend(bundleDetails, session_->GetSessionUserId()); session_->AppendBundles(bundleNames); for (auto info : backupInfos) { - HILOGI("Current backupInfo bundleName:%{public}s, extName:%{public}s", info.name.c_str(), - info.extensionName.c_str()); - session_->SetBundleDataSize(info.name, info.spaceOccupied); - session_->SetBackupExtName(info.name, info.extensionName); + HILOGI("Current backupInfo bundleName:%{public}s, extName:%{public}s, appIndex:%{public}d", + info.name.c_str(), info.extensionName.c_str(), info.appIndex); + std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(info.name, info.appIndex); + session_->SetBundleDataSize(bundleNameIndexInfo, info.spaceOccupied); + session_->SetBackupExtName(bundleNameIndexInfo, info.extensionName); if (info.allToBackup == false) { session_->GetServiceReverseProxy()->BackupOnBundleStarted( - BError(BError::Codes::SA_FORBID_BACKUP_RESTORE), info.name); - session_->RemoveExtInfo(info.name); + BError(BError::Codes::SA_FORBID_BACKUP_RESTORE), bundleNameIndexInfo); + session_->RemoveExtInfo(bundleNameIndexInfo); } } SetCurrentBackupSessProperties(bundleNames, session_->GetSessionUserId()); @@ -751,248 +645,121 @@ ErrCode Service::AppendBundlesDetailsBackupSession(const vector &bun } } -ErrCode Service::Finish() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - try { - VerifyCaller(session_->GetScenario()); - session_->Finish(); - OnAllBundlesFinished(BError(BError::Codes::OK)); - return BError(BError::Codes::OK); - } catch (const BError &e) { - ReleaseOnException(); - HILOGE("Failde to Finish"); - return e.GetCode(); - } -} - -ErrCode Service::PublishFile(const BFileInfo &fileInfo) +void Service::SetCurrentSessProperties(std::vector &restoreBundleInfos, + std::vector &restoreBundleNames, RestoreTypeEnum restoreType) { - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - try { - VerifyCaller(IServiceReverse::Scenario::RESTORE); - if (!fileInfo.fileName.empty()) { - HILOGE("Forbit to use publishFile with fileName for App"); - return EPERM; - } - auto backUpConnection = session_->GetExtConnection(fileInfo.owner); - if (backUpConnection == nullptr) { - HILOGE("PublishFile error, backUpConnection is empty"); - return BError(BError::Codes::SA_INVAL_ARG); + HILOGI("Start"); + for (auto restoreInfo : restoreBundleInfos) { + auto it = find_if(restoreBundleNames.begin(), restoreBundleNames.end(), [&restoreInfo](const auto &bundleName) { + std::string bundleNameIndex = BJsonUtil::BuildBundleNameIndexInfo(restoreInfo.name, restoreInfo.appIndex); + return bundleName == bundleNameIndex; + }); + if (it == restoreBundleNames.end()) { + throw BError(BError::Codes::SA_BUNDLE_INFO_EMPTY, "Can't find bundle name"); } - auto proxy = backUpConnection->GetBackupExtProxy(); - if (!proxy) { - HILOGE("PublishFile error, Extension backup Proxy is empty"); - return BError(BError::Codes::SA_INVAL_ARG); + HILOGI("bundleName: %{public}s, extensionName: %{public}s", restoreInfo.name.c_str(), + restoreInfo.extensionName.c_str()); + std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(restoreInfo.name, restoreInfo.appIndex); + if ((restoreInfo.allToBackup == false && !SpecialVersion(restoreInfo.versionName)) || + (restoreInfo.extensionName.empty() && !SAUtils::IsSABundleName(restoreInfo.name))) { + OnBundleStarted(BError(BError::Codes::SA_FORBID_BACKUP_RESTORE), session_,bundleNameIndexInfo; + session_->RemoveExtInfo(bundleNameIndexInfo); + continue; } - ErrCode res = proxy->PublishFile(fileInfo.fileName); - if (res) { - HILOGE("Failed to publish file for backup extension"); + session_->SetBundleRestoreType(bundleNameIndexInfo, restoreType); + session_->SetBundleVersionCode(bundleNameIndexInfo, restoreInfo.versionCode); + session_->SetBundleVersionName(bundleNameIndexInfo, restoreInfo.versionName); + session_->SetBundleDataSize(bundleNameIndexInfo, restoreInfo.spaceOccupied); + session_->SetBackupExtName(bundleNameIndexInfo, restoreInfo.extensionName); + if (BundleMgrAdapter::IsUser0BundleName(bundleNameIndexInfo, session_->GetSessionUserId())) { + SendUserIdToApp(bundleNameIndexInfo, session_->GetSessionUserId()); } - return res; - } catch (const BError &e) { - return e.GetCode(); - } catch (const exception &e) { - HILOGI("Catched an unexpected low-level exception %{public}s", e.what()); - return EPERM; - } catch (...) { - HILOGI("Unexpected exception"); - return EPERM; } + HILOGI("End"); } -ErrCode Service::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCode) +void Service::SetCurrentSessProperties(std::vector &restoreBundleInfos, + std::vector &restoreBundleNames, + std::map> &bundleNameDetailMap, + std::map &isClearDataFlags, RestoreTypeEnum restoreType) { - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - try { - string callerName = VerifyCallerAndGetCallerName(); - if (fileName.find('/') != string::npos) { - throw BError(BError::Codes::SA_INVAL_ARG, "Filename is not valid"); + HILOGI("Start"); + for (auto restoreInfo : restoreBundleInfos) { + auto it = find_if(restoreBundleNames.begin(), restoreBundleNames.end(), + [&restoreInfo](const auto &bundleName) { + std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(restoreInfo.name, + restoreInfo.appIndex); + return bundleName == bundleNameIndexInfo; + }); + if (it == restoreBundleNames.end()) { + throw BError(BError::Codes::SA_BUNDLE_INFO_EMPTY, "Can't find bundle name"); } - if (fileName == BConstants::EXT_BACKUP_MANAGE) { - fd = session_->OnBundleExtManageInfo(callerName, move(fd)); + HILOGD("bundleName: %{public}s, extensionName: %{public}s", restoreInfo.name.c_str(), + restoreInfo.extensionName.c_str()); + std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(restoreInfo.name, restoreInfo.appIndex); + if ((restoreInfo.allToBackup == false && !SpecialVersion(restoreInfo.versionName)) || + (restoreInfo.extensionName.empty() && !SAUtils::IsSABundleName(restoreInfo.name))) { + OnBundleStarted(BError(BError::Codes::SA_FORBID_BACKUP_RESTORE), session_, restoreInfo.name); + session_->RemoveExtInfo(bundleNameIndexInfo); + continue; } - session_->GetServiceReverseProxy()->BackupOnFileReady(callerName, fileName, move(fd), errCode); - AuditLog auditLog = { false, "Backup File Ready", "ADD", "DataClone", 1, "SUCCESS", "AppFileReady", - callerName, GetAnonyPath(fileName) }; - HiAudit::GetInstance(true).Write(auditLog); - 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); - } - // 通知extension清空缓存 - proxy->HandleClear(); - // 清除Timer - session_->StopFwkTimer(callerName); - session_->StopExtTimer(callerName); - // 通知TOOL 备份完成 - session_->GetServiceReverseProxy()->BackupOnBundleFinished(BError(BError::Codes::OK), callerName); - // 断开extension - backUpConnection->DisconnectBackupExtAbility(); - ClearSessionAndSchedInfo(callerName); + session_->SetBundleRestoreType(bundleNameIndexInfo, restoreType); + session_->SetBundleVersionCode(bundleNameIndexInfo, restoreInfo.versionCode); + session_->SetBundleVersionName(bundleNameIndexInfo, restoreInfo.versionName); + session_->SetBundleDataSize(bundleNameIndexInfo, restoreInfo.spaceOccupied); + session_->SetBackupExtName(bundleNameIndexInfo, restoreInfo.extensionName); + auto iter = isClearDataFlags.find(bundleNameIndexInfo); + if (iter != isClearDataFlags.end()) { + session_->SetClearDataFlag(bundleNameIndexInfo, iter->second); } - OnAllBundlesFinished(BError(BError::Codes::OK)); - return BError(BError::Codes::OK); - } catch (const BError &e) { - return e.GetCode(); // 任意异常产生,终止监听该任务 - } catch (const exception &e) { - HILOGI("Catched an unexpected low-level exception %{public}s", e.what()); - return EPERM; - } catch (...) { - HILOGI("Unexpected exception"); - return EPERM; - } -} - -ErrCode Service::AppDone(ErrCode errCode) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - try { - if (session_ == nullptr) { - HILOGE("App finish error, session info is empty"); - return BError(BError::Codes::SA_INVAL_ARG); + BJsonUtil::BundleDetailInfo broadCastInfo; + BJsonUtil::BundleDetailInfo uniCastInfo; + bool broadCastRet = BJsonUtil::FindBundleInfoByName(bundleNameDetailMap, bundleNameIndexInfo, BROADCAST_TYPE, + broadCastInfo); + if (broadCastRet) { + bool notifyRet = + DelayedSingleton::GetInstance()->NotifyBundleDetail(broadCastInfo); + HILOGI("Publish event end, notify result is:%{public}d", notifyRet); } - string callerName = VerifyCallerAndGetCallerName(); - HILOGI("Begin, callerName is: %{public}s, errCode: %{public}d", callerName.c_str(), errCode); - if (session_->OnBundleFileReady(callerName) || errCode != BError(BError::Codes::OK)) { - auto backUpConnection = session_->GetExtConnection(callerName); - if (backUpConnection == nullptr) { - HILOGE("App finish error, backUpConnection is empty"); - return BError(BError::Codes::SA_INVAL_ARG); - } - auto proxy = backUpConnection->GetBackupExtProxy(); - if (!proxy) { - throw 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); + bool uniCastRet = BJsonUtil::FindBundleInfoByName(bundleNameDetailMap, bundleNameIndexInfo, UNICAST_TYPE, + uniCastInfo); + if (uniCastRet) { + HILOGI("current bundle, unicast info:%{public}s", GetAnonyString(uniCastInfo.detail).c_str()); + session_->SetBackupExtInfo(bundleNameIndexInfo, uniCastInfo.detail); } - OnAllBundlesFinished(BError(BError::Codes::OK)); - return BError(BError::Codes::OK); - } catch (const BError &e) { - ReleaseOnException(); - HILOGE("AppDone error, err code is: %{public}d", e.GetCode()); - return e.GetCode(); // 任意异常产生,终止监听该任务 - } catch (const exception &e) { - ReleaseOnException(); - HILOGI("Catched an unexpected low-level exception %{public}s", e.what()); - return EPERM; - } catch (...) { - HILOGI("Unexpected exception"); - return EPERM; } + HILOGI("End"); } -ErrCode Service::ServiceResultReport(const std::string restoreRetInfo, - BackupRestoreScenario sennario, ErrCode errCode) +void Service::SetCurrentSessProperties(BJsonEntityCaps::BundleInfo &info, + std::map &isClearDataFlags) { - string callerName = ""; - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - try { - callerName = VerifyCallerAndGetCallerName(); - if (sennario == BackupRestoreScenario::FULL_RESTORE) { - session_->GetServiceReverseProxy()->RestoreOnResultReport(restoreRetInfo, callerName, errCode); - NotifyCloneBundleFinish(callerName, sennario); - } else if (sennario == BackupRestoreScenario::INCREMENTAL_RESTORE) { - session_->GetServiceReverseProxy()->IncrementalRestoreOnResultReport(restoreRetInfo, callerName, errCode); - NotifyCloneBundleFinish(callerName, sennario); - } else if (sennario == BackupRestoreScenario::FULL_BACKUP) { - session_->GetServiceReverseProxy()->BackupOnResultReport(restoreRetInfo, callerName); - } else if (sennario == BackupRestoreScenario::INCREMENTAL_BACKUP) { - session_->GetServiceReverseProxy()->IncrementalBackupOnResultReport(restoreRetInfo, callerName); - } - return BError(BError::Codes::OK); - } catch (const BError &e) { - NotifyCloneBundleFinish(callerName, sennario); - return e.GetCode(); // 任意异常产生,终止监听该任务 - } catch (const exception &e) { - NotifyCloneBundleFinish(callerName, sennario); - HILOGI("Catched an unexpected low-level exception %{public}s", e.what()); - return EPERM; - } catch (...) { - NotifyCloneBundleFinish(callerName, sennario); - HILOGI("Unexpected exception"); - return EPERM; + if (session_ == nullptr) { + return; + } + session_->SetBundleDataSize(info.name, info.spaceOccupied); + session_->SetBackupExtName(info.name, info.extensionName); + auto iter = isClearDataFlags.find(info.name); + if (iter != isClearDataFlags.end()) { + session_->SetClearDataFlag(info.name, iter->second); } } -ErrCode Service::SAResultReport(const std::string bundleName, const std::string restoreRetInfo, - const ErrCode errCode, const BackupRestoreScenario sennario) -{ - if (sennario == BackupRestoreScenario::FULL_RESTORE) { - session_->GetServiceReverseProxy()->RestoreOnResultReport(restoreRetInfo, bundleName); - } else if (sennario == BackupRestoreScenario::INCREMENTAL_RESTORE) { - session_->GetServiceReverseProxy()->IncrementalRestoreOnResultReport(restoreRetInfo, bundleName); - } else if (sennario == BackupRestoreScenario::FULL_BACKUP) { - session_->GetServiceReverseProxy()->BackupOnResultReport(restoreRetInfo, bundleName); - session_->GetServiceReverseProxy()->BackupOnBundleFinished(errCode, bundleName); - } else if (sennario == BackupRestoreScenario::INCREMENTAL_BACKUP) { - session_->GetServiceReverseProxy()->IncrementalBackupOnResultReport(restoreRetInfo, bundleName); - } - return SADone(errCode, bundleName); -} - -void Service::NotifyCloneBundleFinish(std::string bundleName, const BackupRestoreScenario sennario) +ErrCode Service::Finish() { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { - if (sennario != BackupRestoreScenario::FULL_RESTORE && - sennario != BackupRestoreScenario::INCREMENTAL_RESTORE) { - return; - } - if (session_->OnBundleFileReady(bundleName)) { - auto backUpConnection = session_->GetExtConnection(bundleName); - if (backUpConnection == nullptr) { - throw BError(BError::Codes::SA_INVAL_ARG, "backUpConnection is empty"); - } - auto proxy = backUpConnection->GetBackupExtProxy(); - if (!proxy) { - throw BError(BError::Codes::SA_INVAL_ARG, "Extension backup Proxy is empty"); - } - proxy->HandleClear(); - session_->StopFwkTimer(bundleName); - session_->StopExtTimer(bundleName); - backUpConnection->DisconnectBackupExtAbility(); - ClearSessionAndSchedInfo(bundleName); - } - SendEndAppGalleryNotify(bundleName); + VerifyCaller(session_->GetScenario()); + session_->Finish(); OnAllBundlesFinished(BError(BError::Codes::OK)); - } catch (...) { - HILOGI("Unexpected exception"); + return BError(BError::Codes::OK); + } catch (const BError &e) { ReleaseOnException(); + HILOGE("Failde to Finish"); + return e.GetCode(); } } -void Service::SetWant(AAFwk::Want &want, const BundleName &bundleName, const BConstants::ExtensionAction &action) -{ - BJsonUtil::BundleDetailInfo bundleDetail = BJsonUtil::ParseBundleNameIndexStr(bundleName); - string backupExtName = session_->GetBackupExtName(bundleName); /* new device app ext name */ - HILOGI("BackupExtName: %{public}s, bundleName: %{public}s", backupExtName.data(), bundleName.data()); - string versionName = session_->GetBundleVersionName(bundleName); /* old device app version name */ - int64_t versionCode = session_->GetBundleVersionCode(bundleName); /* old device app version code */ - RestoreTypeEnum restoreType = session_->GetBundleRestoreType(bundleName); /* app restore type */ - string bundleExtInfo = session_->GetBackupExtInfo(bundleName); - HILOGI("BundleExtInfo is:%{public}s", GetAnonyString(bundleExtInfo).c_str()); - want.SetElementName(bundleDetail.bundleName, backupExtName); - want.SetParam(BConstants::EXTENSION_ACTION_PARA, static_cast(action)); - want.SetParam(BConstants::EXTENSION_VERSION_CODE_PARA, static_cast(versionCode)); - want.SetParam(BConstants::EXTENSION_RESTORE_TYPE_PARA, static_cast(restoreType)); - want.SetParam(BConstants::EXTENSION_VERSION_NAME_PARA, versionName); - want.SetParam(BConstants::EXTENSION_RESTORE_EXT_INFO_PARA, bundleExtInfo); - want.SetParam(BConstants::EXTENSION_BACKUP_EXT_INFO_PARA, bundleExtInfo); - want.SetParam(BConstants::EXTENSION_APP_CLONE_INDEX_PARA, bundleDetail.bundleIndex); -} - ErrCode Service::LaunchBackupExtension(const BundleName &bundleName) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -1095,157 +862,37 @@ ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) } catch (const BError &e) { return e.GetCode(); } catch (const exception &e) { - HILOGI("Catched an unexpected low-level exception %{public}s", e.what()); - return EPERM; - } catch (...) { - HILOGI("Unexpected exception"); - return EPERM; - } -} - -void Service::OnBackupExtensionDied(const string &&bundleName) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - int32_t errCode = BError(BError::Codes::EXT_ABILITY_DIED).GetCode(); - AppRadar::Info info (bundleName, "", ""); - if (session_->GetScenario() == IServiceReverse::Scenario::BACKUP) { - AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::OnBackupExtensionDied", GetUserIdDefault(), - BizStageBackup::BIZ_STAGE_EXTENSION_ABNORMAL_EXIT, errCode); - } else if (session_->GetScenario() == IServiceReverse::Scenario::RESTORE) { - AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::OnBackupExtensionDied", GetUserIdDefault(), - BizStageRestore::BIZ_STAGE_EXTENSION_ABNORMAL_EXIT, errCode); - } - try { - string callName = move(bundleName); - HILOGE("Backup <%{public}s> Extension Process Died", callName.c_str()); - session_->VerifyBundleName(callName); - // 重新连接清理缓存 - HILOGI("Clear backup extension data, bundleName: %{public}s", callName.c_str()); - ExtConnectDied(callName); - } catch (...) { - HILOGE("Unexpected exception, bundleName: %{public}s", bundleName.c_str()); - ExtConnectDied(bundleName); - return; - } -} - -void Service::ExtConnectDied(const string &callName) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - try { - HILOGI("Begin, bundleName: %{public}s", callName.c_str()); - /* Clear Timer */ - session_->StopFwkTimer(callName); - session_->StopExtTimer(callName); - auto backUpConnection = session_->GetExtConnection(callName); - if (backUpConnection != nullptr && backUpConnection->IsExtAbilityConnected()) { - backUpConnection->DisconnectBackupExtAbility(); - } - session_->SetServiceSchedAction(callName, BConstants::ServiceSchedAction::CLEAN); - auto ret = LaunchBackupExtension(callName); - if (ret) { - /* Clear Session before notice client finish event */ - ClearSessionAndSchedInfo(callName); - } - /* Notice Client Ext Ability Process Died */ - NoticeClientFinish(callName, BError(BError::Codes::EXT_ABILITY_DIED)); - } catch (...) { - HILOGE("Unexpected exception, bundleName: %{public}s", callName.c_str()); - ClearSessionAndSchedInfo(callName); - NoticeClientFinish(callName, BError(BError::Codes::EXT_ABILITY_DIED)); - return; - } -} - -void Service::ExtStart(const string &bundleName) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - try { - HILOGE("begin ExtStart, bundle name:%{public}s", bundleName.data()); - if (SAUtils::IsSABundleName(bundleName)) { - BackupSA(bundleName); - return; - } - 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"); - } - if (scenario == IServiceReverse::Scenario::BACKUP) { - auto ret = proxy->HandleBackup(session_->GetClearDataFlag(bundleName)); - session_->GetServiceReverseProxy()->BackupOnBundleStarted(ret, bundleName); - if (ret) { - ClearSessionAndSchedInfo(bundleName); - NoticeClientFinish(bundleName, BError(BError::Codes::SA_INVAL_ARG)); - } - return; - } - if (scenario != IServiceReverse::Scenario::RESTORE) { - throw BError(BError::Codes::SA_INVAL_ARG, "Failed to scenario"); - } - auto ret = proxy->HandleRestore(session_->GetClearDataFlag(bundleName)); - session_->GetServiceReverseProxy()->RestoreOnBundleStarted(ret, bundleName); - auto fileNameVec = session_->GetExtFileNameRequest(bundleName); - for (auto &fileName : fileNameVec) { - int32_t errCode = 0; - UniqueFd fd = proxy->GetFileHandle(fileName, errCode); - session_->GetServiceReverseProxy()->RestoreOnFileReady(bundleName, fileName, move(fd), errCode); - } - return; + HILOGI("Catched an unexpected low-level exception %{public}s", e.what()); + return EPERM; } catch (...) { - HILOGI("Unexpected exception, bundleName: %{public}s", bundleName.c_str()); - ClearSessionAndSchedInfo(bundleName); - NoticeClientFinish(bundleName, BError(BError::Codes::SA_INVAL_ARG)); - return; + HILOGI("Unexpected exception"); + return EPERM; } } -int Service::Dump(int fd, const vector &args) +void Service::OnBackupExtensionDied(const string &&bundleName) { - if (fd < 0) { - HILOGI("HiDumper handle invalid"); - return -1; + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + int32_t errCode = BError(BError::Codes::EXT_ABILITY_DIED).GetCode(); + AppRadar::Info info (bundleName, "", ""); + if (session_->GetScenario() == IServiceReverse::Scenario::BACKUP) { + AppRadar::GetInstance().RecordBackupFuncRes(info, "Service::OnBackupExtensionDied", GetUserIdDefault(), + BizStageBackup::BIZ_STAGE_EXTENSION_ABNORMAL_EXIT, errCode); + } else if (session_->GetScenario() == IServiceReverse::Scenario::RESTORE) { + AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::OnBackupExtensionDied", GetUserIdDefault(), + BizStageRestore::BIZ_STAGE_EXTENSION_ABNORMAL_EXIT, errCode); } - - session_->DumpInfo(fd, args); - return 0; -} - -void Service::ReportOnExtConnectFailed(const IServiceReverse::Scenario scenario, - const std::string &bundleName, const ErrCode ret) -{ try { - if (session_ == nullptr) { - HILOGE("Report extConnectfailed error, session info is empty"); - return; - } - if (scenario == IServiceReverse::Scenario::BACKUP && session_->GetIsIncrementalBackup()) { - session_->GetServiceReverseProxy()->IncrementalBackupOnBundleStarted(ret, bundleName); - } else if (scenario == IServiceReverse::Scenario::RESTORE && - BackupPara().GetBackupOverrideIncrementalRestore() && - session_->ValidRestoreDataType(RestoreTypeEnum::RESTORE_DATA_WAIT_SEND)) { - session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleStarted(ret, bundleName); - - DisposeErr disposeErr = AppGalleryDisposeProxy::GetInstance()->EndRestore(bundleName); - HILOGI("ExtConnectFailed EndRestore, code=%{public}d, bundleName=%{public}s", disposeErr, - bundleName.c_str()); - } else if (scenario == IServiceReverse::Scenario::BACKUP) { - session_->GetServiceReverseProxy()->BackupOnBundleStarted(ret, bundleName); - } else if (scenario == IServiceReverse::Scenario::RESTORE) { - session_->GetServiceReverseProxy()->RestoreOnBundleStarted(ret, bundleName); - DisposeErr disposeErr = AppGalleryDisposeProxy::GetInstance()->EndRestore(bundleName); - HILOGI("ExtConnectFailed EndRestore, code=%{public}d, bundleName=%{public}s", disposeErr, - bundleName.c_str()); - } + string callName = move(bundleName); + HILOGE("Backup <%{public}s> Extension Process Died", callName.c_str()); + session_->VerifyBundleName(callName); + // 重新连接清理缓存 + HILOGI("Clear backup extension data, bundleName: %{public}s", callName.c_str()); + ExtConnectDied(callName); } catch (...) { - HILOGE("Report extConnectfailed error"); + HILOGE("Unexpected exception, bundleName: %{public}s", bundleName.c_str()); + ExtConnectDied(bundleName); + return; } } @@ -1279,68 +926,6 @@ void Service::ExtConnectFailed(const string &bundleName, ErrCode ret) } } -void Service::NoticeClientFinish(const string &bundleName, ErrCode errCode) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGI("begin %{public}s", bundleName.c_str()); - try { - auto scenario = session_->GetScenario(); - if (scenario == IServiceReverse::Scenario::BACKUP && session_->GetIsIncrementalBackup()) { - session_->GetServiceReverseProxy()->IncrementalBackupOnBundleFinished(errCode, bundleName); - } else if (scenario == IServiceReverse::Scenario::RESTORE && - BackupPara().GetBackupOverrideIncrementalRestore() && - session_->ValidRestoreDataType(RestoreTypeEnum::RESTORE_DATA_WAIT_SEND)) { - session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleFinished(errCode, bundleName); - } else if (scenario == IServiceReverse::Scenario::BACKUP) { - session_->GetServiceReverseProxy()->BackupOnBundleFinished(errCode, bundleName); - } else if (scenario == IServiceReverse::Scenario::RESTORE) { - session_->GetServiceReverseProxy()->RestoreOnBundleFinished(errCode, bundleName); - }; - /* If all bundle ext process finish, notice client. */ - OnAllBundlesFinished(BError(BError::Codes::OK)); - } catch(const BError &e) { - ReleaseOnException(); - } catch (...) { - ReleaseOnException(); - HILOGI("Unexpected exception"); - return; - } -} - -void Service::ExtConnectDone(string bundleName) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - try { - HILOGE("begin %{public}s", bundleName.data()); - auto timeoutCallback = TimeOutCallback(wptr(this), bundleName); - auto scenario = session_->GetScenario(); - if (scenario == IServiceReverse::Scenario::BACKUP) { - session_->StartExtTimer(bundleName, timeoutCallback); - } else if (scenario == IServiceReverse::Scenario::RESTORE) { - session_->StartFwkTimer(bundleName, timeoutCallback); - } - - BConstants::ServiceSchedAction curSchedAction = session_->GetServiceSchedAction(bundleName); - if (curSchedAction == BConstants::ServiceSchedAction::CLEAN) { - sched_->Sched(bundleName); - return; - } - if (curSchedAction == BConstants::ServiceSchedAction::START && - clearRecorder_->FindClearBundleRecord(bundleName)) { - session_->SetServiceSchedAction(bundleName, BConstants::ServiceSchedAction::CLEAN); - } else { - session_->SetServiceSchedAction(bundleName, BConstants::ServiceSchedAction::RUNNING); - AddClearBundleRecord(bundleName); - } - sched_->Sched(bundleName); - } catch (...) { - HILOGE("Unexpected exception, bundleName: %{public}s", bundleName.c_str()); - ClearSessionAndSchedInfo(bundleName); - NoticeClientFinish(bundleName, BError(BError::Codes::SDK_INVAL_ARG)); - return; - } -} - void Service::ClearSessionAndSchedInfo(const string &bundleName) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -1712,77 +1297,6 @@ ErrCode Service::GetBackupInfoCmdHandle(BundleName &bundleName, std::string &res return BError(BError::Codes::OK); } -ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) -{ - try { - HILOGI("Service::GetBackupInfo begin."); - if (session_ == nullptr || isOccupyingSession_.load()) { - HILOGE("Get BackupInfo error, session is empty."); - return BError(BError::Codes::SA_INVAL_ARG); - } - if (session_->GetImpl().clientToken) { - return BError(BError::Codes::SA_REFUSED_ACT, "Already have an active session"); - } - session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); - auto ret = GetBackupInfoCmdHandle(bundleName, result); - HILOGI("Service::GetBackupInfo end. result: %s", result.c_str()); - session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); - return ret; - } catch (...) { - session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); - HILOGI("Unexpected exception"); - return EPERM; - } -} - -ErrCode Service::StartExtTimer(bool &isExtStart) -{ - try { - HILOGI("Service::StartExtTimer begin."); - string bundleName = VerifyCallerAndGetCallerName(); - if (session_ == nullptr) { - HILOGE("StartExtTimer error, session_ is nullptr."); - isExtStart = false; - return BError(BError::Codes::SA_INVAL_ARG); - } - session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); - auto timeoutCallback = TimeOutCallback(wptr(this), bundleName); - session_->StopFwkTimer(bundleName); - isExtStart = session_->StartExtTimer(bundleName, timeoutCallback); - session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); - return BError(BError::Codes::OK); - } catch (...) { - isExtStart = false; - session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); - HILOGI("Unexpected exception"); - return EPERM; - } -} - -ErrCode Service::StartFwkTimer(bool &isFwkStart) -{ - try { - HILOGI("Service::StartFwkTimer begin."); - string bundleName = VerifyCallerAndGetCallerName(); - if (session_ == nullptr) { - HILOGE("StartFwkTimer error, session_ is nullptr."); - isFwkStart = false; - return BError(BError::Codes::SA_INVAL_ARG); - } - session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); - auto timeoutCallback = TimeOutCallback(wptr(this), bundleName); - session_->StopExtTimer(bundleName); - isFwkStart = session_->StartFwkTimer(bundleName, timeoutCallback); - session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); - return BError(BError::Codes::OK); - } catch (...) { - isFwkStart = false; - session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); - HILOGI("Unexpected exception"); - return EPERM; - } -} - ErrCode Service::AppendBundlesClearSession(const std::vector &bundleNames) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -1818,239 +1332,6 @@ ErrCode Service::AppendBundlesClearSession(const std::vector &bundle } } -ErrCode Service::UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) -{ - try { - HILOGI("Service::UpdateTimer begin."); - if (session_ == nullptr || isOccupyingSession_.load()) { - HILOGE("Update Timer error, session is empty."); - result = false; - return BError(BError::Codes::SA_INVAL_ARG); - } - session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); - VerifyCaller(); - auto timeoutCallback = TimeOutCallback(wptr(this), bundleName); - result = session_->UpdateTimer(bundleName, timeout, timeoutCallback); - session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); - return BError(BError::Codes::OK); - } catch (...) { - result = false; - session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); - HILOGI("Unexpected exception"); - return EPERM; - } -} - -ErrCode Service::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) -{ - try { - HILOGI("Begin, bundle name:%{public}s, sendRate is:%{public}d", bundleName.c_str(), sendRate); - if (session_ == nullptr || isOccupyingSession_.load()) { - HILOGE("Update Send Rate error, session is empty."); - result = false; - return BError(BError::Codes::SA_INVAL_ARG); - } - session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); - VerifyCaller(); - IServiceReverse::Scenario scenario = session_ -> GetScenario(); - if (scenario != IServiceReverse::Scenario::BACKUP) { - HILOGE("This method is applicable to the backup scenario"); - result = false; - session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); - return BError(BError::Codes::SA_INVAL_ARG); - } - auto backupConnection = session_->GetExtConnection(bundleName); - auto proxy = backupConnection->GetBackupExtProxy(); - if (!proxy) { - throw BError(BError::Codes::SA_INVAL_ARG, "Extension backup Proxy is empty"); - } - auto ret = proxy->UpdateFdSendRate(bundleName, sendRate); - if (ret != NO_ERROR) { - result = false; - session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); - return BError(BError::Codes::EXT_BROKEN_IPC); - } - result = true; - session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); - return BError(BError::Codes::OK); - } catch (...) { - result = false; - session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); - HILOGI("Unexpected exception"); - return EPERM; - } -} - -AAFwk::Want Service::CreateConnectWant (BundleName &bundleName) -{ - BConstants::ExtensionAction action = BConstants::ExtensionAction::BACKUP; - AAFwk::Want want; - string backupExtName = BundleMgrAdapter::GetExtName(bundleName, session_->GetSessionUserId()); - want.SetElementName(bundleName, backupExtName); - want.SetParam(BConstants::EXTENSION_ACTION_PARA, static_cast(action)); - return want; -} - -ErrCode Service::BackupSA(std::string bundleName) -{ - HILOGI("BackupSA begin %{public}s", bundleName.c_str()); - IServiceReverse::Scenario scenario = session_->GetScenario(); - auto backUpConnection = session_->GetSAExtConnection(bundleName); - std::shared_ptr saConnection = backUpConnection.lock(); - if (saConnection == nullptr) { - HILOGE("lock sa connection ptr is nullptr"); - return BError(BError::Codes::SA_INVAL_ARG); - } - if (scenario == IServiceReverse::Scenario::BACKUP) { - auto ret = saConnection->CallBackupSA(); - session_->GetServiceReverseProxy()->BackupOnBundleStarted(ret, bundleName); - if (ret) { - HILOGI("BackupSA ret is %{public}d", ret); - ClearSessionAndSchedInfo(bundleName); - NoticeClientFinish(bundleName, BError(BError::Codes::EXT_ABILITY_DIED)); - return BError(ret); - } - } else if (scenario == IServiceReverse::Scenario::RESTORE) { - session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleStarted(BError(BError::Codes::OK), bundleName); - } - return BError(BError::Codes::OK); -} - -void Service::OnSABackup(const std::string &bundleName, const int &fd, const std::string &result, - const ErrCode &errCode) -{ - auto task = [bundleName, fd, result, errCode, this]() { - HILOGI("OnSABackup bundleName: %{public}s, fd: %{public}d, result: %{public}s, err: %{public}d", - bundleName.c_str(), fd, result.c_str(), errCode); - session_->GetServiceReverseProxy()->BackupOnFileReady(bundleName, "", move(fd), errCode); - SAResultReport(bundleName, result, errCode, BackupRestoreScenario::FULL_BACKUP); - }; - threadPool_.AddTask([task]() { - try { - task(); - } catch (...) { - HILOGE("Failed to add task to thread pool"); - } - }); -} - -void Service::OnSARestore(const std::string &bundleName, const std::string &result, const ErrCode &errCode) -{ - auto task = [bundleName, result, errCode, this]() { - HILOGI("OnSARestore bundleName: %{public}s, result: %{public}s, err: %{public}d", - bundleName.c_str(), result.c_str(), errCode); - SAResultReport(bundleName, result, errCode, BackupRestoreScenario::INCREMENTAL_RESTORE); - }; - threadPool_.AddTask([task]() { - try { - task(); - } catch (...) { - HILOGE("Failed to add task to thread pool"); - } - }); -} - -ErrCode Service::SADone(ErrCode errCode, std::string bundleName) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - try { - if (session_->OnBundleFileReady(bundleName)) { - auto backupConnection = session_->GetSAExtConnection(bundleName); - std::shared_ptr saConnection = backupConnection.lock(); - if (saConnection == nullptr) { - HILOGE("lock sa connection ptr is nullptr"); - return BError(BError::Codes::SA_INVAL_ARG); - } - session_->StopFwkTimer(bundleName); - session_->StopExtTimer(bundleName); - saConnection->DisconnectBackupSAExt(); - ClearSessionAndSchedInfo(bundleName); - } - OnAllBundlesFinished(BError(BError::Codes::OK)); - return BError(BError::Codes::OK); - } catch (const BError &e) { - ReleaseOnException(); - return e.GetCode(); // 任意异常产生,终止监听该任务 - } catch (const exception &e) { - ReleaseOnException(); - HILOGE("Catched an unexpected low-level exception %{public}s", e.what()); - return EPERM; - } catch(...) { - ReleaseOnException(); - HILOGE("Unexpected exception"); - return EPERM; - } -} - -void Service::NotifyCallerCurAppDone(ErrCode errCode, const std::string &callerName) -{ - IServiceReverse::Scenario scenario = session_->GetScenario(); - if (scenario == IServiceReverse::Scenario::BACKUP) { - HILOGI("will notify clone data, scenario is Backup"); - session_->GetServiceReverseProxy()->BackupOnBundleFinished(errCode, callerName); - auto now = std::chrono::system_clock::now(); - auto time = std::chrono::system_clock::to_time_t(now); - auto ms = std::chrono::duration_cast(now.time_since_epoch()); - std::stringstream strTime; - strTime << (std::put_time(std::localtime(&time), "%Y-%m-%d %H:%M:%S:")) << (std::setfill('0')) - << (std::setw(INDEX)) << (ms.count() % MS_1000); - HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, - FILE_BACKUP_EVENTS, - OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "PROC_NAME", "ohos.appfileservice", - "BUNDLENAME", callerName, - "PID", getpid(), - "TIME", strTime.str() - ); - } else if (scenario == IServiceReverse::Scenario::RESTORE) { - HILOGI("will notify clone data, scenario is Restore"); - session_->GetServiceReverseProxy()->RestoreOnBundleFinished(errCode, callerName); - } -} - -ErrCode Service::ReportAppProcessInfo(const std::string processInfo, BackupRestoreScenario sennario) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - try { - string bundleName = VerifyCallerAndGetCallerName(); - if (sennario == BackupRestoreScenario::FULL_RESTORE) { - session_->GetServiceReverseProxy()->RestoreOnProcessInfo(bundleName, processInfo); - } else if (sennario == BackupRestoreScenario::INCREMENTAL_RESTORE) { - session_->GetServiceReverseProxy()->IncrementalRestoreOnProcessInfo(bundleName, processInfo); - } else if (sennario == BackupRestoreScenario::FULL_BACKUP) { - session_->GetServiceReverseProxy()->BackupOnProcessInfo(bundleName, processInfo); - } else if (sennario == BackupRestoreScenario::INCREMENTAL_BACKUP) { - session_->GetServiceReverseProxy()->IncrementalBackupOnProcessInfo(bundleName, processInfo); - } - return BError(BError::Codes::OK); - } catch (const BError &e) { - return e.GetCode(); // 任意异常产生,终止监听该任务 - } catch (const exception &e) { - HILOGI("Catched an unexpected low-level exception %{public}s", e.what()); - return EPERM; - } -} - -std::function Service::TimeOutCallback(wptr ptr, std::string bundleName) -{ - return [ptr, bundleName, this]() { - HILOGI("begin timeoutCallback bundleName = %{public}s", bundleName.c_str()); - auto thisPtr = ptr.promote(); - if (!thisPtr) { - HILOGE("ServicePtr is nullptr."); - return; - } - try { - DoTimeout(thisPtr, bundleName); - } catch (...) { - HILOGE("Unexpected exception, bundleName: %{public}s", bundleName.c_str()); - thisPtr->ClearSessionAndSchedInfo(bundleName); - thisPtr->NoticeClientFinish(bundleName, BError(BError::Codes::EXT_ABILITY_TIMEOUT)); - } - }; -} - void Service::DoTimeout(wptr ptr, std::string bundleName) { auto thisPtr = ptr.promote(); @@ -2097,40 +1378,4 @@ void Service::DoTimeout(wptr ptr, std::string bundleName) thisPtr->NoticeClientFinish(bundleName, BError(BError::Codes::EXT_ABILITY_TIMEOUT)); } } - -void Service::AddClearBundleRecord(const std::string &bundleName) -{ - // 添加清理记录 - if (!clearRecorder_->InsertClearBundleRecord(bundleName)) { - HILOGE("Failed to add clear bundle record, bundleName=%{public}s", bundleName.c_str()); - return; - } - HILOGI("Add clear bundle record OK, bundleName=%{public}s", bundleName.c_str()); -} - -void Service::DelClearBundleRecord(const std::vector &bundleNames) -{ - // 删除清理记录 - for (const auto &it : bundleNames) { - if (!clearRecorder_->DeleteClearBundleRecord(it)) { - HILOGE("Failed to delete clear bundle record, bundleName=%{public}s", it.c_str()); - continue; - } - HILOGI("Delete clear bundle record OK, bundleName=%{public}s", it.c_str()); - } -} - -void Service::ReleaseOnException() -{ - try { - if (session_->IsOnAllBundlesFinished()) { - IServiceReverse::Scenario scenario = session_->GetScenario(); - if (isInRelease_.load() && (scenario == IServiceReverse::Scenario::RESTORE)) { - SessionDeactive(); - } - } - } catch (...) { - HILOGE("Unexpected exception"); - } -} } // namespace OHOS::FileManagement::Backup diff --git a/services/backup_sa/src/module_ipc/sub_service.cpp b/services/backup_sa/src/module_ipc/sub_service.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a99e1e53971200e5f6adf9a7d6b4f441931af6ab --- /dev/null +++ b/services/backup_sa/src/module_ipc/sub_service.cpp @@ -0,0 +1,839 @@ +/* + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * 注意: + * - 注意点1:本文件原则上只处理与IPC无关的业务逻辑 + * - 注意点2:This document, in principle, captures all exceptions. + * Prevent exceptions from spreading to insecure modules. + */ +#include "module_ipc/service.h" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include "ability_manager_client.h" +#include "accesstoken_kit.h" +#include "b_anony/b_anony.h" +#include "b_error/b_error.h" +#include "b_error/b_excep_utils.h" +#include "b_file_info.h" +#include "b_hiaudit/hi_audit.h" +#include "b_json/b_json_cached_entity.h" +#include "b_jsonutil/b_jsonutil.h" +#include "b_ohos/startup/backup_para.h" +#include "b_process/b_multiuser.h" +#include "b_radar/b_radar.h" +#include "b_resources/b_constants.h" +#include "b_sa/b_sa_utils.h" +#include "bundle_mgr_client.h" +#include "filemgmt_libhilog.h" +#include "hisysevent.h" +#include "hitrace_meter.h" +#include "ipc_skeleton.h" +#include "access_token.h" +#include "tokenid_kit.h" +#include "module_app_gallery/app_gallery_dispose_proxy.h" +#include "module_external/bms_adapter.h" +#include "module_external/sms_adapter.h" +#include "module_ipc/svc_backup_connection.h" +#include "module_ipc/svc_restore_deps_manager.h" +#include "module_notify/notify_work_service.h" +#include "parameter.h" +#include "parameters.h" +#include "system_ability_definition.h" + +namespace OHOS::FileManagement::Backup { +using namespace std; + +REGISTER_SYSTEM_ABILITY_BY_ID(Service, FILEMANAGEMENT_BACKUP_SERVICE_SA_ID, false); + +namespace { +constexpr int32_t INDEX_THREE = 3; +constexpr int32_t MS_1000 = 1000; +const std::string FILE_BACKUP_RESTORE_EVENTS = "FILE_BACKUP_EVENTS"; +} // namespace + +ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) +{ + try { + HILOGI("Service::GetBackupInfo begin."); + if (session_ == nullptr || isOccupyingSession_.load()) { + HILOGE("Get BackupInfo error, session is empty."); + return BError(BError::Codes::SA_INVAL_ARG); + } + if (session_->GetImpl().clientToken) { + return BError(BError::Codes::SA_REFUSED_ACT, "Already have an active session"); + } + session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); + auto ret = GetBackupInfoCmdHandle(bundleName, result); + HILOGI("Service::GetBackupInfo end. result: %s", result.c_str()); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return ret; + } catch (...) { + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + HILOGI("Unexpected exception"); + return EPERM; + } +} + +ErrCode Service::StartExtTimer(bool &isExtStart) +{ + try { + HILOGI("Service::StartExtTimer begin."); + string bundleName = VerifyCallerAndGetCallerName(); + if (session_ == nullptr) { + HILOGE("StartExtTimer error, session_ is nullptr."); + isExtStart = false; + return BError(BError::Codes::SA_INVAL_ARG); + } + session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); + auto timeoutCallback = TimeOutCallback(wptr(this), bundleName); + session_->StopFwkTimer(bundleName); + isExtStart = session_->StartExtTimer(bundleName, timeoutCallback); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return BError(BError::Codes::OK); + } catch (...) { + isExtStart = false; + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + HILOGI("Unexpected exception"); + return EPERM; + } +} + +ErrCode Service::StartFwkTimer(bool &isFwkStart) +{ + try { + HILOGI("Service::StartFwkTimer begin."); + string bundleName = VerifyCallerAndGetCallerName(); + if (session_ == nullptr) { + HILOGE("StartFwkTimer error, session_ is nullptr."); + isFwkStart = false; + return BError(BError::Codes::SA_INVAL_ARG); + } + session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); + auto timeoutCallback = TimeOutCallback(wptr(this), bundleName); + session_->StopExtTimer(bundleName); + isFwkStart = session_->StartFwkTimer(bundleName, timeoutCallback); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return BError(BError::Codes::OK); + } catch (...) { + isFwkStart = false; + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + HILOGI("Unexpected exception"); + return EPERM; + } +} + +ErrCode Service::UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) +{ + try { + HILOGI("Service::UpdateTimer begin."); + if (session_ == nullptr || isOccupyingSession_.load()) { + HILOGE("Update Timer error, session is empty."); + result = false; + return BError(BError::Codes::SA_INVAL_ARG); + } + session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); + VerifyCaller(); + auto timeoutCallback = TimeOutCallback(wptr(this), bundleName); + result = session_->UpdateTimer(bundleName, timeout, timeoutCallback); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return BError(BError::Codes::OK); + } catch (...) { + result = false; + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + HILOGI("Unexpected exception"); + return EPERM; + } +} + +ErrCode Service::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) +{ + try { + HILOGI("Begin, bundle name:%{public}s, sendRate is:%{public}d", bundleName.c_str(), sendRate); + if (session_ == nullptr || isOccupyingSession_.load()) { + HILOGE("Update Send Rate error, session is empty."); + result = false; + return BError(BError::Codes::SA_INVAL_ARG); + } + session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); + VerifyCaller(); + IServiceReverse::Scenario scenario = session_ -> GetScenario(); + if (scenario != IServiceReverse::Scenario::BACKUP) { + HILOGE("This method is applicable to the backup scenario"); + result = false; + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto backupConnection = session_->GetExtConnection(bundleName); + auto proxy = backupConnection->GetBackupExtProxy(); + if (!proxy) { + throw BError(BError::Codes::SA_INVAL_ARG, "Extension backup Proxy is empty"); + } + auto ret = proxy->UpdateFdSendRate(bundleName, sendRate); + if (ret != NO_ERROR) { + result = false; + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return BError(BError::Codes::EXT_BROKEN_IPC); + } + result = true; + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return BError(BError::Codes::OK); + } catch (...) { + result = false; + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + HILOGI("Unexpected exception"); + return EPERM; + } +} + +AAFwk::Want Service::CreateConnectWant (BundleName &bundleName) +{ + BConstants::ExtensionAction action = BConstants::ExtensionAction::BACKUP; + AAFwk::Want want; + string backupExtName = BundleMgrAdapter::GetExtName(bundleName, session_->GetSessionUserId()); + want.SetElementName(bundleName, backupExtName); + want.SetParam(BConstants::EXTENSION_ACTION_PARA, static_cast(action)); + return want; +} + +ErrCode Service::BackupSA(std::string bundleName) +{ + HILOGI("BackupSA begin %{public}s", bundleName.c_str()); + IServiceReverse::Scenario scenario = session_->GetScenario(); + auto backUpConnection = session_->GetSAExtConnection(bundleName); + std::shared_ptr saConnection = backUpConnection.lock(); + if (saConnection == nullptr) { + HILOGE("lock sa connection ptr is nullptr"); + return BError(BError::Codes::SA_INVAL_ARG); + } + if (scenario == IServiceReverse::Scenario::BACKUP) { + auto ret = saConnection->CallBackupSA(); + session_->GetServiceReverseProxy()->BackupOnBundleStarted(ret, bundleName); + if (ret) { + HILOGI("BackupSA ret is %{public}d", ret); + ClearSessionAndSchedInfo(bundleName); + NoticeClientFinish(bundleName, BError(BError::Codes::EXT_ABILITY_DIED)); + return BError(ret); + } + } else if (scenario == IServiceReverse::Scenario::RESTORE) { + session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleStarted(BError(BError::Codes::OK), bundleName); + } + return BError(BError::Codes::OK); +} + +void Service::OnSABackup(const std::string &bundleName, const int &fd, const std::string &result, + const ErrCode &errCode) +{ + auto task = [bundleName, fd, result, errCode, this]() { + HILOGI("OnSABackup bundleName: %{public}s, fd: %{public}d, result: %{public}s, err: %{public}d", + bundleName.c_str(), fd, result.c_str(), errCode); + session_->GetServiceReverseProxy()->BackupOnFileReady(bundleName, "", move(fd), errCode); + SAResultReport(bundleName, result, errCode, BackupRestoreScenario::FULL_BACKUP); + }; + threadPool_.AddTask([task]() { + try { + task(); + } catch (...) { + HILOGE("Failed to add task to thread pool"); + } + }); +} + +void Service::OnSARestore(const std::string &bundleName, const std::string &result, const ErrCode &errCode) +{ + auto task = [bundleName, result, errCode, this]() { + HILOGI("OnSARestore bundleName: %{public}s, result: %{public}s, err: %{public}d", + bundleName.c_str(), result.c_str(), errCode); + SAResultReport(bundleName, result, errCode, BackupRestoreScenario::INCREMENTAL_RESTORE); + }; + threadPool_.AddTask([task]() { + try { + task(); + } catch (...) { + HILOGE("Failed to add task to thread pool"); + } + }); +} + +ErrCode Service::SADone(ErrCode errCode, std::string bundleName) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + try { + if (session_->OnBundleFileReady(bundleName)) { + auto backupConnection = session_->GetSAExtConnection(bundleName); + std::shared_ptr saConnection = backupConnection.lock(); + if (saConnection == nullptr) { + HILOGE("lock sa connection ptr is nullptr"); + return BError(BError::Codes::SA_INVAL_ARG); + } + session_->StopFwkTimer(bundleName); + session_->StopExtTimer(bundleName); + saConnection->DisconnectBackupSAExt(); + ClearSessionAndSchedInfo(bundleName); + } + OnAllBundlesFinished(BError(BError::Codes::OK)); + return BError(BError::Codes::OK); + } catch (const BError &e) { + ReleaseOnException(); + return e.GetCode(); // 任意异常产生,终止监听该任务 + } catch (const exception &e) { + ReleaseOnException(); + HILOGE("Catched an unexpected low-level exception %{public}s", e.what()); + return EPERM; + } catch(...) { + ReleaseOnException(); + HILOGE("Unexpected exception"); + return EPERM; + } +} + +void Service::NotifyCallerCurAppDone(ErrCode errCode, const std::string &callerName) +{ + IServiceReverse::Scenario scenario = session_->GetScenario(); + if (scenario == IServiceReverse::Scenario::BACKUP) { + HILOGI("will notify clone data, scenario is Backup"); + session_->GetServiceReverseProxy()->BackupOnBundleFinished(errCode, callerName); + auto now = std::chrono::system_clock::now(); + auto time = std::chrono::system_clock::to_time_t(now); + auto ms = std::chrono::duration_cast(now.time_since_epoch()); + std::stringstream strTime; + strTime << (std::put_time(std::localtime(&time), "%Y-%m-%d %H:%M:%S:")) << (std::setfill('0')) + << (std::setw(INDEX_THREE)) << (ms.count() % MS_1000); + HiSysEventWrite( + OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, + FILE_BACKUP_RESTORE_EVENTS, + OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + "PROC_NAME", "ohos.appfileservice", + "BUNDLENAME", callerName, + "PID", getpid(), + "TIME", strTime.str() + ); + } else if (scenario == IServiceReverse::Scenario::RESTORE) { + HILOGI("will notify clone data, scenario is Restore"); + session_->GetServiceReverseProxy()->RestoreOnBundleFinished(errCode, callerName); + } +} + +ErrCode Service::ReportAppProcessInfo(const std::string processInfo, BackupRestoreScenario sennario) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + try { + string bundleName = VerifyCallerAndGetCallerName(); + if (sennario == BackupRestoreScenario::FULL_RESTORE) { + session_->GetServiceReverseProxy()->RestoreOnProcessInfo(bundleName, processInfo); + } else if (sennario == BackupRestoreScenario::INCREMENTAL_RESTORE) { + session_->GetServiceReverseProxy()->IncrementalRestoreOnProcessInfo(bundleName, processInfo); + } else if (sennario == BackupRestoreScenario::FULL_BACKUP) { + session_->GetServiceReverseProxy()->BackupOnProcessInfo(bundleName, processInfo); + } else if (sennario == BackupRestoreScenario::INCREMENTAL_BACKUP) { + session_->GetServiceReverseProxy()->IncrementalBackupOnProcessInfo(bundleName, processInfo); + } + return BError(BError::Codes::OK); + } catch (const BError &e) { + return e.GetCode(); // 任意异常产生,终止监听该任务 + } catch (const exception &e) { + HILOGI("Catched an unexpected low-level exception %{public}s", e.what()); + return EPERM; + } +} + +std::function Service::TimeOutCallback(wptr ptr, std::string bundleName) +{ + return [ptr, bundleName, this]() { + HILOGI("begin timeoutCallback bundleName = %{public}s", bundleName.c_str()); + auto thisPtr = ptr.promote(); + if (!thisPtr) { + HILOGE("ServicePtr is nullptr."); + return; + } + try { + DoTimeout(thisPtr, bundleName); + } catch (...) { + HILOGE("Unexpected exception, bundleName: %{public}s", bundleName.c_str()); + thisPtr->ClearSessionAndSchedInfo(bundleName); + thisPtr->NoticeClientFinish(bundleName, BError(BError::Codes::EXT_ABILITY_TIMEOUT)); + } + }; +} + +void Service::AddClearBundleRecord(const std::string &bundleName) +{ + // 添加清理记录 + if (!clearRecorder_->InsertClearBundleRecord(bundleName)) { + HILOGE("Failed to add clear bundle record, bundleName=%{public}s", bundleName.c_str()); + return; + } + HILOGI("Add clear bundle record OK, bundleName=%{public}s", bundleName.c_str()); +} + +void Service::DelClearBundleRecord(const std::vector &bundleNames) +{ + // 删除清理记录 + for (const auto &it : bundleNames) { + if (!clearRecorder_->DeleteClearBundleRecord(it)) { + HILOGE("Failed to delete clear bundle record, bundleName=%{public}s", it.c_str()); + continue; + } + HILOGI("Delete clear bundle record OK, bundleName=%{public}s", it.c_str()); + } +} + +void Service::ReleaseOnException() +{ + try { + if (session_->IsOnAllBundlesFinished()) { + IServiceReverse::Scenario scenario = session_->GetScenario(); + if (isInRelease_.load() && (scenario == IServiceReverse::Scenario::RESTORE)) { + SessionDeactive(); + } + } + } catch (...) { + HILOGE("Unexpected exception"); + } +} + +vector Service::MakeDetailList(const vector &bundleNames) +{ + vector bundleDetails {}; + for (auto bundleName : bundleNames) { + bundleDetails.emplace_back(BIncrementalData {bundleName, 0}); + } + return bundleDetails; +} + +void Service::SetWant(AAFwk::Want &want, const BundleName &bundleName, const BConstants::ExtensionAction &action) +{ + BJsonUtil::BundleDetailInfo bundleDetail = BJsonUtil::ParseBundleNameIndexStr(bundleName); + string backupExtName = session_->GetBackupExtName(bundleName); /* new device app ext name */ + HILOGI("BackupExtName: %{public}s, bundleName: %{public}s", backupExtName.data(), bundleName.data()); + string versionName = session_->GetBundleVersionName(bundleName); /* old device app version name */ + int64_t versionCode = session_->GetBundleVersionCode(bundleName); /* old device app version code */ + RestoreTypeEnum restoreType = session_->GetBundleRestoreType(bundleName); /* app restore type */ + string bundleExtInfo = session_->GetBackupExtInfo(bundleName); + HILOGI("BundleExtInfo is:%{public}s", GetAnonyString(bundleExtInfo).c_str()); + want.SetElementName(bundleDetail.bundleName, backupExtName); + want.SetParam(BConstants::EXTENSION_ACTION_PARA, static_cast(action)); + want.SetParam(BConstants::EXTENSION_VERSION_CODE_PARA, static_cast(versionCode)); + want.SetParam(BConstants::EXTENSION_RESTORE_TYPE_PARA, static_cast(restoreType)); + want.SetParam(BConstants::EXTENSION_VERSION_NAME_PARA, versionName); + want.SetParam(BConstants::EXTENSION_RESTORE_EXT_INFO_PARA, bundleExtInfo); + want.SetParam(BConstants::EXTENSION_BACKUP_EXT_INFO_PARA, bundleExtInfo); + want.SetParam(BConstants::EXTENSION_APP_CLONE_INDEX_PARA, bundleDetail.bundleIndex); +} + +void Service::ExtConnectDied(const string &callName) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + try { + HILOGI("Begin, bundleName: %{public}s", callName.c_str()); + /* Clear Timer */ + session_->StopFwkTimer(callName); + session_->StopExtTimer(callName); + auto backUpConnection = session_->GetExtConnection(callName); + if (backUpConnection != nullptr && backUpConnection->IsExtAbilityConnected()) { + backUpConnection->DisconnectBackupExtAbility(); + } + session_->SetServiceSchedAction(callName, BConstants::ServiceSchedAction::CLEAN); + auto ret = LaunchBackupExtension(callName); + if (ret) { + /* Clear Session before notice client finish event */ + ClearSessionAndSchedInfo(callName); + } + /* Notice Client Ext Ability Process Died */ + NoticeClientFinish(callName, BError(BError::Codes::EXT_ABILITY_DIED)); + } catch (...) { + HILOGE("Unexpected exception, bundleName: %{public}s", callName.c_str()); + ClearSessionAndSchedInfo(callName); + NoticeClientFinish(callName, BError(BError::Codes::EXT_ABILITY_DIED)); + return; + } +} + +void Service::ExtStart(const string &bundleName) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + try { + HILOGE("begin ExtStart, bundle name:%{public}s", bundleName.data()); + if (SAUtils::IsSABundleName(bundleName)) { + BackupSA(bundleName); + return; + } + 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"); + } + if (scenario == IServiceReverse::Scenario::BACKUP) { + auto ret = proxy->HandleBackup(session_->GetClearDataFlag(bundleName)); + session_->GetServiceReverseProxy()->BackupOnBundleStarted(ret, bundleName); + if (ret) { + ClearSessionAndSchedInfo(bundleName); + NoticeClientFinish(bundleName, BError(BError::Codes::SA_INVAL_ARG)); + } + return; + } + if (scenario != IServiceReverse::Scenario::RESTORE) { + throw BError(BError::Codes::SA_INVAL_ARG, "Failed to scenario"); + } + auto ret = proxy->HandleRestore(session_->GetClearDataFlag(bundleName)); + session_->GetServiceReverseProxy()->RestoreOnBundleStarted(ret, bundleName); + auto fileNameVec = session_->GetExtFileNameRequest(bundleName); + for (auto &fileName : fileNameVec) { + int32_t errCode = 0; + UniqueFd fd = proxy->GetFileHandle(fileName, errCode); + session_->GetServiceReverseProxy()->RestoreOnFileReady(bundleName, fileName, move(fd), errCode); + } + return; + } catch (...) { + HILOGI("Unexpected exception, bundleName: %{public}s", bundleName.c_str()); + ClearSessionAndSchedInfo(bundleName); + NoticeClientFinish(bundleName, BError(BError::Codes::SA_INVAL_ARG)); + return; + } +} + +ErrCode Service::PublishFile(const BFileInfo &fileInfo) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + try { + VerifyCaller(IServiceReverse::Scenario::RESTORE); + if (!fileInfo.fileName.empty()) { + HILOGE("Forbit to use publishFile with fileName for App"); + return EPERM; + } + auto backUpConnection = session_->GetExtConnection(fileInfo.owner); + if (backUpConnection == nullptr) { + HILOGE("PublishFile error, backUpConnection is empty"); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto proxy = backUpConnection->GetBackupExtProxy(); + if (!proxy) { + HILOGE("PublishFile error, Extension backup Proxy is empty"); + return BError(BError::Codes::SA_INVAL_ARG); + } + ErrCode res = proxy->PublishFile(fileInfo.fileName); + if (res) { + HILOGE("Failed to publish file for backup extension"); + } + return res; + } catch (const BError &e) { + return e.GetCode(); + } catch (const exception &e) { + HILOGI("Catched an unexpected low-level exception %{public}s", e.what()); + return EPERM; + } catch (...) { + HILOGI("Unexpected exception"); + return EPERM; + } +} + +ErrCode Service::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCode) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + try { + string callerName = VerifyCallerAndGetCallerName(); + if (fileName.find('/') != string::npos) { + throw BError(BError::Codes::SA_INVAL_ARG, "Filename is not valid"); + } + if (fileName == BConstants::EXT_BACKUP_MANAGE) { + fd = session_->OnBundleExtManageInfo(callerName, move(fd)); + } + session_->GetServiceReverseProxy()->BackupOnFileReady(callerName, fileName, move(fd), errCode); + AuditLog auditLog = { false, "Backup File Ready", "ADD", "DataClone", 1, "SUCCESS", "AppFileReady", + callerName, GetAnonyPath(fileName) }; + HiAudit::GetInstance(true).Write(auditLog); + 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); + } + // 通知extension清空缓存 + proxy->HandleClear(); + // 清除Timer + session_->StopFwkTimer(callerName); + session_->StopExtTimer(callerName); + // 通知TOOL 备份完成 + session_->GetServiceReverseProxy()->BackupOnBundleFinished(BError(BError::Codes::OK), callerName); + // 断开extension + backUpConnection->DisconnectBackupExtAbility(); + ClearSessionAndSchedInfo(callerName); + } + OnAllBundlesFinished(BError(BError::Codes::OK)); + return BError(BError::Codes::OK); + } catch (const BError &e) { + return e.GetCode(); // 任意异常产生,终止监听该任务 + } catch (const exception &e) { + HILOGI("Catched an unexpected low-level exception %{public}s", e.what()); + return EPERM; + } catch (...) { + HILOGI("Unexpected exception"); + return EPERM; + } +} + +ErrCode Service::AppDone(ErrCode errCode) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + try { + if (session_ == nullptr) { + HILOGE("App finish error, session info is empty"); + return BError(BError::Codes::SA_INVAL_ARG); + } + string callerName = VerifyCallerAndGetCallerName(); + HILOGI("Begin, callerName is: %{public}s, errCode: %{public}d", callerName.c_str(), errCode); + if (session_->OnBundleFileReady(callerName) || errCode != BError(BError::Codes::OK)) { + auto backUpConnection = session_->GetExtConnection(callerName); + if (backUpConnection == nullptr) { + HILOGE("App finish error, backUpConnection is empty"); + return BError(BError::Codes::SA_INVAL_ARG); + } + auto proxy = backUpConnection->GetBackupExtProxy(); + if (!proxy) { + throw 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); + } + OnAllBundlesFinished(BError(BError::Codes::OK)); + return BError(BError::Codes::OK); + } catch (const BError &e) { + ReleaseOnException(); + HILOGE("AppDone error, err code is: %{public}d", e.GetCode()); + return e.GetCode(); // 任意异常产生,终止监听该任务 + } catch (const exception &e) { + ReleaseOnException(); + HILOGI("Catched an unexpected low-level exception %{public}s", e.what()); + return EPERM; + } catch (...) { + HILOGI("Unexpected exception"); + return EPERM; + } +} + +ErrCode Service::ServiceResultReport(const std::string restoreRetInfo, + BackupRestoreScenario sennario, ErrCode errCode) +{ + string callerName = ""; + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + try { + callerName = VerifyCallerAndGetCallerName(); + if (sennario == BackupRestoreScenario::FULL_RESTORE) { + session_->GetServiceReverseProxy()->RestoreOnResultReport(restoreRetInfo, callerName, errCode); + NotifyCloneBundleFinish(callerName, sennario); + } else if (sennario == BackupRestoreScenario::INCREMENTAL_RESTORE) { + session_->GetServiceReverseProxy()->IncrementalRestoreOnResultReport(restoreRetInfo, callerName, errCode); + NotifyCloneBundleFinish(callerName, sennario); + } else if (sennario == BackupRestoreScenario::FULL_BACKUP) { + session_->GetServiceReverseProxy()->BackupOnResultReport(restoreRetInfo, callerName); + } else if (sennario == BackupRestoreScenario::INCREMENTAL_BACKUP) { + session_->GetServiceReverseProxy()->IncrementalBackupOnResultReport(restoreRetInfo, callerName); + } + return BError(BError::Codes::OK); + } catch (const BError &e) { + NotifyCloneBundleFinish(callerName, sennario); + return e.GetCode(); // 任意异常产生,终止监听该任务 + } catch (const exception &e) { + NotifyCloneBundleFinish(callerName, sennario); + HILOGI("Catched an unexpected low-level exception %{public}s", e.what()); + return EPERM; + } catch (...) { + NotifyCloneBundleFinish(callerName, sennario); + HILOGI("Unexpected exception"); + return EPERM; + } +} + +ErrCode Service::SAResultReport(const std::string bundleName, const std::string restoreRetInfo, + const ErrCode errCode, const BackupRestoreScenario sennario) +{ + if (sennario == BackupRestoreScenario::FULL_RESTORE) { + session_->GetServiceReverseProxy()->RestoreOnResultReport(restoreRetInfo, bundleName); + } else if (sennario == BackupRestoreScenario::INCREMENTAL_RESTORE) { + session_->GetServiceReverseProxy()->IncrementalRestoreOnResultReport(restoreRetInfo, bundleName); + } else if (sennario == BackupRestoreScenario::FULL_BACKUP) { + session_->GetServiceReverseProxy()->BackupOnResultReport(restoreRetInfo, bundleName); + session_->GetServiceReverseProxy()->BackupOnBundleFinished(errCode, bundleName); + } else if (sennario == BackupRestoreScenario::INCREMENTAL_BACKUP) { + session_->GetServiceReverseProxy()->IncrementalBackupOnResultReport(restoreRetInfo, bundleName); + } + return SADone(errCode, bundleName); +} + +void Service::NotifyCloneBundleFinish(std::string bundleName, const BackupRestoreScenario sennario) +{ + try { + if (sennario != BackupRestoreScenario::FULL_RESTORE && + sennario != BackupRestoreScenario::INCREMENTAL_RESTORE) { + return; + } + if (session_->OnBundleFileReady(bundleName)) { + auto backUpConnection = session_->GetExtConnection(bundleName); + if (backUpConnection == nullptr) { + throw BError(BError::Codes::SA_INVAL_ARG, "backUpConnection is empty"); + } + auto proxy = backUpConnection->GetBackupExtProxy(); + if (!proxy) { + throw BError(BError::Codes::SA_INVAL_ARG, "Extension backup Proxy is empty"); + } + proxy->HandleClear(); + session_->StopFwkTimer(bundleName); + session_->StopExtTimer(bundleName); + backUpConnection->DisconnectBackupExtAbility(); + ClearSessionAndSchedInfo(bundleName); + } + SendEndAppGalleryNotify(bundleName); + OnAllBundlesFinished(BError(BError::Codes::OK)); + } catch (...) { + HILOGI("Unexpected exception"); + ReleaseOnException(); + } +} + +int Service::Dump(int fd, const vector &args) +{ + if (fd < 0) { + HILOGI("HiDumper handle invalid"); + return -1; + } + + session_->DumpInfo(fd, args); + return 0; +} + +void Service::ReportOnExtConnectFailed(const IServiceReverse::Scenario scenario, + const std::string &bundleName, const ErrCode ret) +{ + try { + if (session_ == nullptr) { + HILOGE("Report extConnectfailed error, session info is empty"); + return; + } + if (scenario == IServiceReverse::Scenario::BACKUP && session_->GetIsIncrementalBackup()) { + session_->GetServiceReverseProxy()->IncrementalBackupOnBundleStarted(ret, bundleName); + } else if (scenario == IServiceReverse::Scenario::RESTORE && + BackupPara().GetBackupOverrideIncrementalRestore() && + session_->ValidRestoreDataType(RestoreTypeEnum::RESTORE_DATA_WAIT_SEND)) { + session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleStarted(ret, bundleName); + + DisposeErr disposeErr = AppGalleryDisposeProxy::GetInstance()->EndRestore(bundleName); + HILOGI("ExtConnectFailed EndRestore, code=%{public}d, bundleName=%{public}s", disposeErr, + bundleName.c_str()); + } else if (scenario == IServiceReverse::Scenario::BACKUP) { + session_->GetServiceReverseProxy()->BackupOnBundleStarted(ret, bundleName); + } else if (scenario == IServiceReverse::Scenario::RESTORE) { + session_->GetServiceReverseProxy()->RestoreOnBundleStarted(ret, bundleName); + DisposeErr disposeErr = AppGalleryDisposeProxy::GetInstance()->EndRestore(bundleName); + HILOGI("ExtConnectFailed EndRestore, code=%{public}d, bundleName=%{public}s", disposeErr, + bundleName.c_str()); + } + } catch (...) { + HILOGE("Report extConnectfailed error"); + } +} + +void Service::NoticeClientFinish(const string &bundleName, ErrCode errCode) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("begin %{public}s", bundleName.c_str()); + try { + auto scenario = session_->GetScenario(); + if (scenario == IServiceReverse::Scenario::BACKUP && session_->GetIsIncrementalBackup()) { + session_->GetServiceReverseProxy()->IncrementalBackupOnBundleFinished(errCode, bundleName); + } else if (scenario == IServiceReverse::Scenario::RESTORE && + BackupPara().GetBackupOverrideIncrementalRestore() && + session_->ValidRestoreDataType(RestoreTypeEnum::RESTORE_DATA_WAIT_SEND)) { + session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleFinished(errCode, bundleName); + } else if (scenario == IServiceReverse::Scenario::BACKUP) { + session_->GetServiceReverseProxy()->BackupOnBundleFinished(errCode, bundleName); + } else if (scenario == IServiceReverse::Scenario::RESTORE) { + session_->GetServiceReverseProxy()->RestoreOnBundleFinished(errCode, bundleName); + }; + /* If all bundle ext process finish, notice client. */ + OnAllBundlesFinished(BError(BError::Codes::OK)); + } catch(const BError &e) { + ReleaseOnException(); + } catch (...) { + ReleaseOnException(); + HILOGI("Unexpected exception"); + return; + } +} + +void Service::ExtConnectDone(string bundleName) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + try { + HILOGE("begin %{public}s", bundleName.data()); + auto timeoutCallback = TimeOutCallback(wptr(this), bundleName); + auto scenario = session_->GetScenario(); + if (scenario == IServiceReverse::Scenario::BACKUP) { + session_->StartExtTimer(bundleName, timeoutCallback); + } else if (scenario == IServiceReverse::Scenario::RESTORE) { + session_->StartFwkTimer(bundleName, timeoutCallback); + } + + BConstants::ServiceSchedAction curSchedAction = session_->GetServiceSchedAction(bundleName); + if (curSchedAction == BConstants::ServiceSchedAction::CLEAN) { + sched_->Sched(bundleName); + return; + } + if (curSchedAction == BConstants::ServiceSchedAction::START && + clearRecorder_->FindClearBundleRecord(bundleName)) { + session_->SetServiceSchedAction(bundleName, BConstants::ServiceSchedAction::CLEAN); + } else { + session_->SetServiceSchedAction(bundleName, BConstants::ServiceSchedAction::RUNNING); + AddClearBundleRecord(bundleName); + } + sched_->Sched(bundleName); + } catch (...) { + HILOGE("Unexpected exception, bundleName: %{public}s", bundleName.c_str()); + ClearSessionAndSchedInfo(bundleName); + NoticeClientFinish(bundleName, BError(BError::Codes::SDK_INVAL_ARG)); + return; + } +} +} // namespace OHOS::FileManagement::Backup diff --git a/tests/unittests/backup_sa/module_ipc/BUILD.gn b/tests/unittests/backup_sa/module_ipc/BUILD.gn index 7a6c75f82e82639468cdddf428615dd6a41552ba..a71ade0a8d704fdfcde0a21453326ba4a86f8833 100644 --- a/tests/unittests/backup_sa/module_ipc/BUILD.gn +++ b/tests/unittests/backup_sa/module_ipc/BUILD.gn @@ -170,6 +170,7 @@ ohos_unittest("backup_service_throw_test") { "${path_backup}/services/backup_sa/src/module_ipc/sa_backup_connection.cpp", "${path_backup}/services/backup_sa/src/module_ipc/service.cpp", "${path_backup}/services/backup_sa/src/module_ipc/service_incremental.cpp", + "${path_backup}/services/backup_sa/src/module_ipc/sub_service.cpp", "${path_backup}/services/backup_sa/src/module_ipc/svc_restore_deps_manager.cpp", "${path_backup}/services/backup_sa/src/module_notify/notify_work_service.cpp", "service_throw_test.cpp", @@ -354,6 +355,7 @@ ohos_unittest("backup_restore_deps_manager_test") { "${path_backup}/services/backup_sa/src/module_ipc/sa_backup_connection.cpp", "${path_backup}/services/backup_sa/src/module_ipc/service.cpp", "${path_backup}/services/backup_sa/src/module_ipc/service_incremental.cpp", + "${path_backup}/services/backup_sa/src/module_ipc/sub_service.cpp", "${path_backup}/services/backup_sa/src/module_ipc/svc_restore_deps_manager.cpp", "${path_backup}/services/backup_sa/src/module_notify/notify_work_service.cpp", "svc_restore_deps_manager_test.cpp", diff --git a/tests/unittests/backup_sa/module_ipc/service_other_test.cpp b/tests/unittests/backup_sa/module_ipc/service_other_test.cpp index 9b8fc031e48cccd41d8834bd63fd83adff7c9f1f..497fb97d53bf1eff74e4bd30b8515474b2240a82 100644 --- a/tests/unittests/backup_sa/module_ipc/service_other_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_other_test.cpp @@ -30,6 +30,7 @@ #include "module_ipc/service.h" #include "service.cpp" +#in namespace OHOS::FileManagement::Backup { using namespace std; diff --git a/tests/unittests/backup_sa/module_ipc/service_test.cpp b/tests/unittests/backup_sa/module_ipc/service_test.cpp index c1d2d468aed6f959a0d00b2f79d4708a3af8f0d2..a0b52e0889d85c935b3af2b321b0b7cd3b0aff02 100644 --- a/tests/unittests/backup_sa/module_ipc/service_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_test.cpp @@ -22,6 +22,7 @@ #include "module_ipc/service.h" #include "service.cpp" #include "service_reverse_mock.h" +#include "sub_service.cpp" #include "test_manager.h" namespace OHOS::FileManagement::Backup {