Signed-off-by: wenjinchao <wenjinchao@huawei.com>
Change-Id: Ic3dcf7b2e208e183b67048cb654692b3cf9ccf5f
This commit is contained in:
wenjinchao 2024-11-19 15:23:50 +08:00
parent f75358764f
commit 33f160d4f0
2 changed files with 44 additions and 22 deletions

View File

@ -273,27 +273,23 @@ bool UdmfServiceImpl::IsReadAndKeep(const std::vector<Privilege> &privileges, co
int32_t UdmfServiceImpl::ProcessUri(const QueryOption &query, UnifiedData &unifiedData)
{
std::string localDeviceId = PreProcessUtils::GetLocalDeviceId();
auto records = unifiedData.GetRecords();
if (unifiedData.GetRuntime() == nullptr) {
return E_DB_ERROR;
}
std::string sourceDeviceId = unifiedData.GetRuntime()->deviceId;
if (localDeviceId != sourceDeviceId) {
if (!SetRemoteUri(query, records)) {
ZLOGE("when cross devices, remote uri is required!");
return E_ERROR;
}
int32_t verifyRes = VerifyUnifiedData(unifiedData);
if (verifyRes != E_OK) {
ZLOGE("verify unifieddata fail, key=%{public}s, stauts=%{public}d", query.key.c_str(), verifyRes);
return verifyRes;
}
std::string bundleName;
if (!PreProcessUtils::GetHapBundleNameByToken(query.tokenId, bundleName)) {
ZLOGE("GetHapBundleNameByToken fail, key=%{public}s, tokenId=%{private}d.", query.key.c_str(), query.tokenId);
return E_ERROR;
}
std::string sourceDeviceId = unifiedData.GetRuntime()->deviceId;
if (localDeviceId == sourceDeviceId && query.tokenId == unifiedData.GetRuntime()->tokenId) {
ZLOGW("No need to grant uri permissions, queryKey=%{public}s.", query.key.c_str());
return E_OK;
}
std::vector<Uri> allUri;
auto records = unifiedData.GetRecords();
for (auto record : records) {
if (record != nullptr && PreProcessUtils::IsFileType(record->GetType())) {
auto file = static_cast<File *>(record.get());
@ -318,28 +314,53 @@ int32_t UdmfServiceImpl::ProcessUri(const QueryOption &query, UnifiedData &unifi
RadarReporterAdapter::ReportFail(std::string(__FUNCTION__),
BizScene::GET_DATA, GetDataStage::GRANT_URI_PERMISSION, StageRes::FAILED, E_NO_PERMISSION);
ZLOGE("GrantUriPermission fail, bundleName=%{public}s, key=%{public}s.",
bundleName.c_str(), query.key.c_str());
bundleName.c_str(), query.key.c_str());
return E_NO_PERMISSION;
}
return E_OK;
}
bool UdmfServiceImpl::SetRemoteUri(const QueryOption &query, std::vector<std::shared_ptr<UnifiedRecord>> &records)
int32_t UdmfServiceImpl::VerifyUnifiedData(UnifiedData &unifiedData)
{
for (auto record : records) {
if (record != nullptr && PreProcessUtils::IsFileType(record->GetType())) {
auto file = static_cast<File *>(record.get());
std::string remoteUri = file->GetRemoteUri();
if (remoteUri.empty()) {
ZLOGE("Get remoteUri is empyt, key=%{public}s.", query.key.c_str());
return false;
if (unifiedData.GetRuntime() == nullptr) {
ZLOGE("get runtime empty!");
return E_DB_ERROR;
}
std::string localDeviceId = PreProcessUtils::GetLocalDeviceId();
std::string sourceDeviceId = unifiedData.GetRuntime()->deviceId;
if (localDeviceId != sourceDeviceId) {
auto records = unifiedData.GetRecords();
for (auto record : records) {
if (record != nullptr && PreProcessUtils::IsFileType(record->GetType())) {
auto file = static_cast<File *>(record.get());
std::string remoteUri = file->GetRemoteUri();
if (remoteUri.empty()) {
ZLOGE("when cross devices, remote uri is required!");
return E_ERROR;
}
file->SetUri(remoteUri); // cross dev, need dis path.
}
file->SetUri(remoteUri); // cross dev, need dis path.
}
}
return true;
return E_OK;
}
// bool UdmfServiceImpl::SetRemoteUri(std::vector<std::shared_ptr<UnifiedRecord>> &records)
// {
// for (auto record : records) {
// if (record != nullptr && PreProcessUtils::IsFileType(record->GetType())) {
// auto file = static_cast<File *>(record.get());
// std::string remoteUri = file->GetRemoteUri();
// if (remoteUri.empty()) {
// ZLOGE("Get remoteUri is empyt!");
// return false;
// }
// file->SetUri(remoteUri); // cross dev, need dis path.
// }
// }
// return true;
// }
int32_t UdmfServiceImpl::GetBatchData(const QueryOption &query, std::vector<UnifiedData> &unifiedDataSet)
{
ZLOGD("start");

View File

@ -59,9 +59,10 @@ private:
int32_t RetrieveData(const QueryOption &query, UnifiedData &unifiedData);
int32_t QueryDataCommon(const QueryOption &query, std::vector<UnifiedData> &dataSet, std::shared_ptr<Store> &store);
int32_t ProcessUri(const QueryOption &query, UnifiedData &unifiedData);
bool SetRemoteUri(const QueryOption &query, std::vector<std::shared_ptr<UnifiedRecord>> &records);
// bool SetRemoteUri(std::vector<std::shared_ptr<UnifiedRecord>> &records);
bool IsPermissionInCache(const QueryOption &query);
bool IsReadAndKeep(const std::vector<Privilege> &privileges, const QueryOption &query);
int32_t VerifyUnifiedData(UnifiedData &unifiedData);
class Factory {
public: