mirror of
https://gitee.com/openharmony/filemanagement_app_file_service
synced 2024-10-06 21:53:56 +00:00
commit
e4d90e4455
@ -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",
|
||||
|
@ -376,7 +376,8 @@ private:
|
||||
void SetCurrentSessProperties(std::vector<BJsonEntityCaps::BundleInfo> &restoreBundleInfos,
|
||||
std::vector<std::string> &restoreBundleNames, RestoreTypeEnum restoreType);
|
||||
|
||||
void SetCurrentSessProperties(BJsonEntityCaps::BundleInfo &info, std::map<std::string, bool> &isClearDataFlags);
|
||||
void SetCurrentSessProperties(BJsonEntityCaps::BundleInfo &info, std::map<std::string, bool> &isClearDataFlags,
|
||||
const std::string &bundleNameIndexInfo);
|
||||
|
||||
/**
|
||||
* @brief add useridinfo to current backup session
|
||||
@ -475,6 +476,14 @@ private:
|
||||
vector<BIncrementalData> MakeDetailList(const vector<BundleName> &bundleNames);
|
||||
|
||||
vector<string> GetBundleNameByDetails(const std::vector<BIncrementalData> &bundlesToBackup);
|
||||
|
||||
void HandleCurGroupBackupInfos(vector<BJsonEntityCaps::BundleInfo> &bundleInfos,
|
||||
std::map<std::string, std::vector<BJsonUtil::BundleDetailInfo>> &bundleNameDetailMap,
|
||||
std::map<std::string, bool> &isClearDataFlags);
|
||||
|
||||
void HandleCurGroupIncBackupInfos(vector<BJsonEntityCaps::BundleInfo> &bundleInfos,
|
||||
std::map<std::string, std::vector<BJsonUtil::BundleDetailInfo>> &bundleNameDetailMap,
|
||||
std::map<std::string, bool> &isClearDataFlags);
|
||||
private:
|
||||
static sptr<Service> instance_;
|
||||
static std::mutex instanceLock_;
|
||||
|
@ -133,7 +133,7 @@ vector<BJsonEntityCaps::BundleInfo> 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<string> &includes, const vector<string> &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<BJsonEntityCaps::BundleInfo> 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<AppExecFwk::ExtensionAbilityInfo> extensionInfos;
|
||||
bool getBundleSuccess = GetCurBundleExtenionInfo(installedBundle, bundleName, extensionInfos, bms, userId);
|
||||
@ -289,7 +298,7 @@ vector<BJsonEntityCaps::BundleInfo> 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<BJsonEntityCaps::BundleInfo> 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<BJsonEntityCaps::BundleInfo> newBundleInfos {};
|
||||
@ -311,7 +326,6 @@ vector<BJsonEntityCaps::BundleInfo> BundleMgrAdapter::GetBundleInfosForIncrement
|
||||
HILOGE("Failed to get bundleStats result");
|
||||
return {};
|
||||
}
|
||||
|
||||
HILOGI("BundleMgrAdapter GetBundleInfosForIncremental end ");
|
||||
return newBundleInfos;
|
||||
}
|
||||
@ -378,6 +392,12 @@ vector<BJsonEntityCaps::BundleInfo> 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<AppExecFwk::HapModuleInfo> 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<int32_t>(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE) |
|
||||
static_cast<int32_t>(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY) |
|
||||
static_cast<int32_t>(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) {
|
||||
|
@ -414,8 +414,9 @@ static vector<BJsonEntityCaps::BundleInfo> 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;
|
||||
@ -507,26 +508,29 @@ void Service::SetCurrentSessProperties(std::vector<BJsonEntityCaps::BundleInfo>
|
||||
{
|
||||
HILOGI("Start");
|
||||
for (auto restoreInfo : restoreBundleInfos) {
|
||||
auto it = find_if(restoreBundleNames.begin(), restoreBundleNames.end(),
|
||||
[&restoreInfo](const auto &bundleName) { return bundleName == restoreInfo.name; });
|
||||
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");
|
||||
}
|
||||
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_, restoreInfo.name);
|
||||
session_->RemoveExtInfo(restoreInfo.name);
|
||||
OnBundleStarted(BError(BError::Codes::SA_FORBID_BACKUP_RESTORE), session_, bundleNameIndexInfo);
|
||||
session_->RemoveExtInfo(bundleNameIndexInfo);
|
||||
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());
|
||||
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());
|
||||
}
|
||||
}
|
||||
HILOGI("End");
|
||||
@ -597,7 +601,7 @@ void Service::SetCurrentSessProperties(std::vector<BJsonEntityCaps::BundleInfo>
|
||||
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);
|
||||
OnBundleStarted(BError(BError::Codes::SA_FORBID_BACKUP_RESTORE), session_, bundleNameIndexInfo);
|
||||
session_->RemoveExtInfo(bundleNameIndexInfo);
|
||||
continue;
|
||||
}
|
||||
@ -630,28 +634,20 @@ void Service::SetCurrentSessProperties(std::vector<BJsonEntityCaps::BundleInfo>
|
||||
}
|
||||
|
||||
void Service::SetCurrentSessProperties(BJsonEntityCaps::BundleInfo &info,
|
||||
std::map<std::string, bool> &isClearDataFlags)
|
||||
std::map<std::string, bool> &isClearDataFlags, const std::string &bundleNameIndexInfo)
|
||||
{
|
||||
if (session_ == nullptr) {
|
||||
HILOGE("Set currrent session properties error, session is empty");
|
||||
return;
|
||||
}
|
||||
session_->SetBundleDataSize(info.name, info.spaceOccupied);
|
||||
session_->SetBackupExtName(info.name, info.extensionName);
|
||||
auto iter = isClearDataFlags.find(info.name);
|
||||
session_->SetBundleDataSize(bundleNameIndexInfo, info.spaceOccupied);
|
||||
session_->SetBackupExtName(bundleNameIndexInfo, info.extensionName);
|
||||
auto iter = isClearDataFlags.find(bundleNameIndexInfo);
|
||||
if (iter != isClearDataFlags.end()) {
|
||||
session_->SetClearDataFlag(info.name, iter->second);
|
||||
session_->SetClearDataFlag(bundleNameIndexInfo, iter->second);
|
||||
}
|
||||
}
|
||||
|
||||
vector<BIncrementalData> Service::MakeDetailList(const vector<BundleName> &bundleNames)
|
||||
{
|
||||
vector<BIncrementalData> bundleDetails {};
|
||||
for (auto bundleName : bundleNames) {
|
||||
bundleDetails.emplace_back(BIncrementalData {bundleName, 0});
|
||||
}
|
||||
return bundleDetails;
|
||||
}
|
||||
|
||||
ErrCode Service::AppendBundlesBackupSession(const vector<BundleName> &bundleNames)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
|
||||
@ -666,14 +662,15 @@ ErrCode Service::AppendBundlesBackupSession(const vector<BundleName> &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());
|
||||
@ -699,7 +696,7 @@ ErrCode Service::AppendBundlesBackupSession(const vector<BundleName> &bundleName
|
||||
}
|
||||
|
||||
ErrCode Service::AppendBundlesDetailsBackupSession(const vector<BundleName> &bundleNames,
|
||||
const vector<std::string> &bundleInfos)
|
||||
const vector<std::string> &bundleInfos)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
|
||||
try {
|
||||
@ -717,19 +714,7 @@ ErrCode Service::AppendBundlesDetailsBackupSession(const vector<BundleName> &bun
|
||||
auto bundleDetails = MakeDetailList(bundleNames);
|
||||
auto backupInfos = BundleMgrAdapter::GetBundleInfosForAppend(bundleDetails, session_->GetSessionUserId());
|
||||
session_->AppendBundles(bundleNames);
|
||||
for (auto info : backupInfos) {
|
||||
SetCurrentSessProperties(info, isClearDataFlags);
|
||||
if (info.allToBackup == false) {
|
||||
session_->GetServiceReverseProxy()->BackupOnBundleStarted(
|
||||
BError(BError::Codes::SA_FORBID_BACKUP_RESTORE), info.name);
|
||||
session_->RemoveExtInfo(info.name);
|
||||
}
|
||||
BJsonUtil::BundleDetailInfo uniCastInfo;
|
||||
if (BJsonUtil::FindBundleInfoByName(bundleNameDetailMap, info.name, UNICAST_TYPE, uniCastInfo)) {
|
||||
HILOGI("current bundle, unicast info:%{public}s", GetAnonyString(uniCastInfo.detail).c_str());
|
||||
session_->SetBackupExtInfo(info.name, uniCastInfo.detail);
|
||||
}
|
||||
}
|
||||
HandleCurGroupBackupInfos(backupInfos, bundleNameDetailMap, isClearDataFlags);
|
||||
OnStartSched();
|
||||
session_->DecreaseSessionCnt(__PRETTY_FUNCTION__);
|
||||
return BError(BError::Codes::OK);
|
||||
@ -738,11 +723,6 @@ ErrCode Service::AppendBundlesDetailsBackupSession(const vector<BundleName> &bun
|
||||
HandleExceptionOnAppendBundles(session_, bundleNames, {});
|
||||
session_->DecreaseSessionCnt(__PRETTY_FUNCTION__);
|
||||
return e.GetCode();
|
||||
} catch (const exception &e) {
|
||||
HILOGE("Catched an unexpected low-level exception %{public}s", e.what());
|
||||
HandleExceptionOnAppendBundles(session_, bundleNames, {});
|
||||
session_->DecreaseSessionCnt(__PRETTY_FUNCTION__);
|
||||
return EPERM;
|
||||
} catch(...) {
|
||||
HILOGE("Unexpected exception");
|
||||
HandleExceptionOnAppendBundles(session_, bundleNames, {});
|
||||
@ -751,146 +731,26 @@ ErrCode Service::AppendBundlesDetailsBackupSession(const vector<BundleName> &bun
|
||||
}
|
||||
}
|
||||
|
||||
ErrCode Service::Finish()
|
||||
void Service::HandleCurGroupBackupInfos(std::vector<BJsonEntityCaps::BundleInfo> &backupInfos,
|
||||
std::map<std::string, std::vector<BJsonUtil::BundleDetailInfo>> &bundleNameDetailMap,
|
||||
std::map<std::string, bool> &isClearDataFlags)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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;
|
||||
for (auto &info : backupInfos) {
|
||||
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);
|
||||
SetCurrentSessProperties(info, isClearDataFlags, bundleNameIndexInfo);
|
||||
if (info.allToBackup == false) {
|
||||
session_->GetServiceReverseProxy()->BackupOnBundleStarted(
|
||||
BError(BError::Codes::SA_FORBID_BACKUP_RESTORE), bundleNameIndexInfo);
|
||||
session_->RemoveExtInfo(bundleNameIndexInfo);
|
||||
}
|
||||
auto backUpConnection = session_->GetExtConnection(fileInfo.owner);
|
||||
if (backUpConnection == nullptr) {
|
||||
HILOGE("PublishFile error, backUpConnection is empty");
|
||||
return BError(BError::Codes::SA_INVAL_ARG);
|
||||
BJsonUtil::BundleDetailInfo uniCastInfo;
|
||||
if (BJsonUtil::FindBundleInfoByName(bundleNameDetailMap, bundleNameIndexInfo, UNICAST_TYPE, uniCastInfo)) {
|
||||
HILOGI("current bundle:%{public}s, unicast info:%{public}s", bundleNameIndexInfo.c_str(),
|
||||
GetAnonyString(uniCastInfo.detail).c_str());
|
||||
session_->SetBackupExtInfo(bundleNameIndexInfo, uniCastInfo.detail);
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -973,71 +833,6 @@ void Service::NotifyCloneBundleFinish(std::string bundleName, const BackupRestor
|
||||
}
|
||||
}
|
||||
|
||||
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<int>(action));
|
||||
want.SetParam(BConstants::EXTENSION_VERSION_CODE_PARA, static_cast<long>(versionCode));
|
||||
want.SetParam(BConstants::EXTENSION_RESTORE_TYPE_PARA, static_cast<int>(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__);
|
||||
try {
|
||||
HILOGI("begin %{public}s", bundleName.data());
|
||||
IServiceReverse::Scenario scenario = session_->GetScenario();
|
||||
BConstants::ExtensionAction action;
|
||||
if (scenario == IServiceReverse::Scenario::BACKUP || scenario == IServiceReverse::Scenario::CLEAN) {
|
||||
action = BConstants::ExtensionAction::BACKUP;
|
||||
} else if (scenario == IServiceReverse::Scenario::RESTORE) {
|
||||
action = BConstants::ExtensionAction::RESTORE;
|
||||
} else {
|
||||
throw BError(BError::Codes::SA_INVAL_ARG, "Failed to scenario");
|
||||
}
|
||||
if (SAUtils::IsSABundleName(bundleName)) {
|
||||
return LaunchBackupSAExtension(bundleName);
|
||||
}
|
||||
AAFwk::Want want;
|
||||
SetWant(want, bundleName, action);
|
||||
auto backUpConnection = session_->GetExtConnection(bundleName);
|
||||
if (backUpConnection == nullptr) {
|
||||
HILOGE("LaunchBackupExtension error, backUpConnection is empty");
|
||||
return BError(BError::Codes::SA_INVAL_ARG);
|
||||
}
|
||||
if (backUpConnection->IsExtAbilityConnected() && !backUpConnection->WaitDisconnectDone()) {
|
||||
HILOGE("LaunchBackupExtension error, WaitDisconnectDone failed");
|
||||
return BError(BError::Codes::SA_INVAL_ARG);
|
||||
}
|
||||
ErrCode ret = backUpConnection->ConnectBackupExtAbility(want, session_->GetSessionUserId());
|
||||
if (ret) {
|
||||
HILOGE("ConnectBackupExtAbility faild, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), ret);
|
||||
return BError(BError::Codes::SA_BOOT_EXT_FAIL);
|
||||
}
|
||||
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::LaunchBackupSAExtension(const BundleName &bundleName)
|
||||
{
|
||||
string extInfo = session_->GetBackupExtInfo(bundleName);
|
||||
|
@ -273,14 +273,15 @@ ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vector<BIncrem
|
||||
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.increSpaceOccupied);
|
||||
session_->SetBackupExtName(info.name, info.extensionName);
|
||||
HILOGI("Current backupInfo bundleName:%{public}s, index:%{public}d, extName:%{public}s", info.name.c_str(),
|
||||
info.appIndex, info.extensionName.c_str());
|
||||
std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(info.name, info.appIndex);
|
||||
session_->SetBundleDataSize(bundleNameIndexInfo, info.increSpaceOccupied);
|
||||
session_->SetBackupExtName(bundleNameIndexInfo, info.extensionName);
|
||||
if (info.allToBackup == false) {
|
||||
session_->GetServiceReverseProxy()->IncrementalBackupOnBundleStarted(
|
||||
BError(BError::Codes::SA_FORBID_BACKUP_RESTORE), info.name);
|
||||
session_->RemoveExtInfo(info.name);
|
||||
BError(BError::Codes::SA_FORBID_BACKUP_RESTORE), bundleNameIndexInfo);
|
||||
session_->RemoveExtInfo(bundleNameIndexInfo);
|
||||
}
|
||||
}
|
||||
for (auto &bundleInfo : bundlesToBackup) {
|
||||
@ -321,20 +322,7 @@ ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vector<BIncrem
|
||||
auto backupInfos = BundleMgrAdapter::GetBundleInfosForAppend(bundlesToBackup,
|
||||
session_->GetSessionUserId());
|
||||
session_->AppendBundles(bundleNames);
|
||||
for (auto info : backupInfos) {
|
||||
SetCurrentSessProperties(info, isClearDataFlags);
|
||||
session_->SetBundleDataSize(info.name, info.increSpaceOccupied);
|
||||
if (info.allToBackup == false) {
|
||||
session_->GetServiceReverseProxy()->IncrementalBackupOnBundleStarted(
|
||||
BError(BError::Codes::SA_FORBID_BACKUP_RESTORE), info.name);
|
||||
session_->RemoveExtInfo(info.name);
|
||||
}
|
||||
BJsonUtil::BundleDetailInfo uniCastInfo;
|
||||
if (BJsonUtil::FindBundleInfoByName(bundleNameDetailMap, info.name, UNICAST_TYPE, uniCastInfo)) {
|
||||
HILOGI("current bundle, unicast info:%{public}s", GetAnonyString(uniCastInfo.detail).c_str());
|
||||
session_->SetBackupExtInfo(info.name, uniCastInfo.detail);
|
||||
}
|
||||
}
|
||||
HandleCurGroupIncBackupInfos(backupInfos, bundleNameDetailMap, isClearDataFlags);
|
||||
for (auto &bundleInfo : bundlesToBackup) {
|
||||
session_->SetIncrementalData(bundleInfo);
|
||||
}
|
||||
@ -352,6 +340,30 @@ ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vector<BIncrem
|
||||
}
|
||||
}
|
||||
|
||||
void Service::HandleCurGroupIncBackupInfos(vector<BJsonEntityCaps::BundleInfo> &backupInfos,
|
||||
std::map<std::string, std::vector<BJsonUtil::BundleDetailInfo>> &bundleNameDetailMap,
|
||||
std::map<std::string, bool> &isClearDataFlags)
|
||||
{
|
||||
for (auto &info : backupInfos) {
|
||||
HILOGI("Current backupInfo bundleName:%{public}s, index:%{public}d, extName:%{public}s", info.name.c_str(),
|
||||
info.appIndex, info.extensionName.c_str());
|
||||
std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(info.name, info.appIndex);
|
||||
SetCurrentSessProperties(info, isClearDataFlags, bundleNameIndexInfo);
|
||||
session_->SetBundleDataSize(bundleNameIndexInfo, info.increSpaceOccupied);
|
||||
if (info.allToBackup == false) {
|
||||
session_->GetServiceReverseProxy()->IncrementalBackupOnBundleStarted(
|
||||
BError(BError::Codes::SA_FORBID_BACKUP_RESTORE), bundleNameIndexInfo);
|
||||
session_->RemoveExtInfo(bundleNameIndexInfo);
|
||||
}
|
||||
BJsonUtil::BundleDetailInfo uniCastInfo;
|
||||
if (BJsonUtil::FindBundleInfoByName(bundleNameDetailMap, bundleNameIndexInfo, UNICAST_TYPE, uniCastInfo)) {
|
||||
HILOGI("current bundle:%{public}s, unicast info:%{public}s", bundleNameIndexInfo.c_str(),
|
||||
GetAnonyString(uniCastInfo.detail).c_str());
|
||||
session_->SetBackupExtInfo(bundleNameIndexInfo, uniCastInfo.detail);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ErrCode Service::PublishIncrementalFile(const BFileInfo &fileInfo)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
|
||||
|
284
services/backup_sa/src/module_ipc/sub_service.cpp
Normal file
284
services/backup_sa/src/module_ipc/sub_service.cpp
Normal file
@ -0,0 +1,284 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "module_ipc/service.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cerrno>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <regex>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <iomanip>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/vfs.h>
|
||||
|
||||
#include <directory_ex.h>
|
||||
|
||||
#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;
|
||||
|
||||
vector<BIncrementalData> Service::MakeDetailList(const vector<BundleName> &bundleNames)
|
||||
{
|
||||
vector<BIncrementalData> bundleDetails {};
|
||||
for (auto bundleName : bundleNames) {
|
||||
bundleDetails.emplace_back(BIncrementalData {bundleName, 0});
|
||||
}
|
||||
return bundleDetails;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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::LaunchBackupExtension(const BundleName &bundleName)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
|
||||
try {
|
||||
HILOGI("begin %{public}s", bundleName.data());
|
||||
IServiceReverse::Scenario scenario = session_->GetScenario();
|
||||
BConstants::ExtensionAction action;
|
||||
if (scenario == IServiceReverse::Scenario::BACKUP || scenario == IServiceReverse::Scenario::CLEAN) {
|
||||
action = BConstants::ExtensionAction::BACKUP;
|
||||
} else if (scenario == IServiceReverse::Scenario::RESTORE) {
|
||||
action = BConstants::ExtensionAction::RESTORE;
|
||||
} else {
|
||||
throw BError(BError::Codes::SA_INVAL_ARG, "Failed to scenario");
|
||||
}
|
||||
if (SAUtils::IsSABundleName(bundleName)) {
|
||||
return LaunchBackupSAExtension(bundleName);
|
||||
}
|
||||
AAFwk::Want want;
|
||||
SetWant(want, bundleName, action);
|
||||
auto backUpConnection = session_->GetExtConnection(bundleName);
|
||||
if (backUpConnection == nullptr) {
|
||||
HILOGE("LaunchBackupExtension error, backUpConnection is empty");
|
||||
return BError(BError::Codes::SA_INVAL_ARG);
|
||||
}
|
||||
if (backUpConnection->IsExtAbilityConnected() && !backUpConnection->WaitDisconnectDone()) {
|
||||
HILOGE("LaunchBackupExtension error, WaitDisconnectDone failed");
|
||||
return BError(BError::Codes::SA_INVAL_ARG);
|
||||
}
|
||||
ErrCode ret = backUpConnection->ConnectBackupExtAbility(want, session_->GetSessionUserId());
|
||||
if (ret) {
|
||||
HILOGE("ConnectBackupExtAbility faild, bundleName:%{public}s, ret:%{public}d", bundleName.c_str(), ret);
|
||||
return BError(BError::Codes::SA_BOOT_EXT_FAIL);
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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<int>(action));
|
||||
want.SetParam(BConstants::EXTENSION_VERSION_CODE_PARA, static_cast<long>(versionCode));
|
||||
want.SetParam(BConstants::EXTENSION_RESTORE_TYPE_PARA, static_cast<int>(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);
|
||||
}
|
||||
}
|
@ -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",
|
||||
|
@ -212,7 +212,8 @@ void Service::SetCurrentSessProperties(std::vector<BJsonEntityCaps::BundleInfo>&
|
||||
void Service::SetCurrentSessProperties(std::vector<BJsonEntityCaps::BundleInfo>&, std::vector<std::string>&,
|
||||
std::map<std::string, std::vector<BJsonUtil::BundleDetailInfo>>&, std::map<std::string, bool>&, RestoreTypeEnum) {}
|
||||
|
||||
void Service::SetCurrentSessProperties(BJsonEntityCaps::BundleInfo&, std::map<std::string, bool>&) {}
|
||||
void Service::SetCurrentSessProperties(BJsonEntityCaps::BundleInfo&, std::map<std::string, bool>&,
|
||||
const std::string&) {}
|
||||
|
||||
void Service::ReleaseOnException() {}
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
|
||||
#include "module_ipc/service.h"
|
||||
#include "service.cpp"
|
||||
#include "sub_service.cpp"
|
||||
|
||||
namespace OHOS::FileManagement::Backup {
|
||||
using namespace std;
|
||||
@ -232,15 +233,15 @@ HWTEST_F(ServiceTest, SUB_Service_SetCurrentSessProperties_0100, TestSize.Level1
|
||||
EXPECT_TRUE(servicePtr_ != nullptr);
|
||||
BJsonEntityCaps::BundleInfo info;
|
||||
std::map<std::string, bool> isClearDataFlags;
|
||||
|
||||
std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(info.name, info.appIndex);
|
||||
servicePtr_->session_ = nullptr;
|
||||
servicePtr_->SetCurrentSessProperties(info, isClearDataFlags);
|
||||
servicePtr_->SetCurrentSessProperties(info, isClearDataFlags, bundleNameIndexInfo);
|
||||
servicePtr_->session_ = sptr<SvcSessionManager>(new SvcSessionManager(wptr(servicePtr_)));
|
||||
servicePtr_->SetCurrentSessProperties(info, isClearDataFlags);
|
||||
servicePtr_->SetCurrentSessProperties(info, isClearDataFlags, bundleNameIndexInfo);
|
||||
|
||||
info = BJsonEntityCaps::BundleInfo{BUNDLE_NAME, 0, {}, {}, 0, 0, true, false, BUNDLE_NAME};
|
||||
isClearDataFlags = {{BUNDLE_NAME, true}};
|
||||
servicePtr_->SetCurrentSessProperties(info, isClearDataFlags);
|
||||
servicePtr_->SetCurrentSessProperties(info, isClearDataFlags, bundleNameIndexInfo);
|
||||
} catch (...) {
|
||||
EXPECT_TRUE(false);
|
||||
GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by SetCurrentSessProperties.";
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user