mirror of
https://gitee.com/openharmony/distributeddatamgr_datamgr_service
synced 2024-11-27 00:51:12 +00:00
drag cross device 0629
Signed-off-by: genglingxia <genglingxia3@huawei.com>
This commit is contained in:
parent
2d96872289
commit
d522979710
@ -75,7 +75,8 @@
|
||||
"relational_store",
|
||||
"safwk",
|
||||
"samgr",
|
||||
"udmf"
|
||||
"udmf",
|
||||
"app_file_service"
|
||||
],
|
||||
"third_party": [
|
||||
"cjson",
|
||||
|
@ -32,6 +32,8 @@ ipc_core_path = "//foundation/communication/ipc/interfaces/innerkits/ipc_core"
|
||||
|
||||
device_manager_path = "//foundation/distributedhardware/device_manager"
|
||||
|
||||
file_service_path = "//foundation/filemanagement/app_file_service"
|
||||
|
||||
data_service_path = "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice"
|
||||
|
||||
udmf_path = "//foundation/distributeddatamgr/udmf"
|
||||
|
@ -128,6 +128,7 @@ ohos_shared_library("distributeddatasvc") {
|
||||
"huks:libhukssdk",
|
||||
"ipc:ipc_core",
|
||||
"kv_store:distributeddata_inner",
|
||||
"app_file_service:remote_file_share_native",
|
||||
"relational_store:native_rdb",
|
||||
]
|
||||
subsystem_name = "distributeddatamgr"
|
||||
|
@ -31,6 +31,7 @@ config("module_public_config") {
|
||||
"${data_service_path}/service/udmf/store",
|
||||
"${data_service_path}/service/udmf",
|
||||
"${kv_store_path}/frameworks/common",
|
||||
"${file_service_path}/interfaces/innerkits/remote_file_share/native",
|
||||
]
|
||||
}
|
||||
|
||||
@ -54,12 +55,16 @@ ohos_shared_library("udmf_server") {
|
||||
|
||||
configs = [ ":module_public_config" ]
|
||||
|
||||
deps = [ "${data_service_path}/framework:distributeddatasvcfwk" ]
|
||||
deps = [ "${data_service_path}/framework:distributeddatasvcfwk",
|
||||
"${data_service_path}/adapter:distributeddata_adapter",
|
||||
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:zuri",
|
||||
"ability_runtime:uri_permission_mgr",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"app_file_service:remote_file_share_native",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "log_print.h"
|
||||
#include "preprocess_utils.h"
|
||||
#include "uri_permission_manager.h"
|
||||
#include "remote_file_share.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UDMF {
|
||||
@ -43,6 +44,14 @@ DataManager &DataManager::GetInstance()
|
||||
return instance;
|
||||
}
|
||||
|
||||
bool DataManager::IsFileType(UDType udType){
|
||||
if (udType == UDType::FILE || udType == UDType::IMAGE || udType == UDType::VIDEO || udType == UDType::AUDIO
|
||||
|| udType == UDType::FOLDER) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t DataManager::SaveData(CustomOption &option, UnifiedData &unifiedData, std::string &key)
|
||||
{
|
||||
if (unifiedData.IsEmpty()) {
|
||||
@ -60,11 +69,24 @@ int32_t DataManager::SaveData(CustomOption &option, UnifiedData &unifiedData, st
|
||||
ZLOGE("Imputation failed");
|
||||
return E_UNKNOWN;
|
||||
}
|
||||
for (auto &record : unifiedData.GetRecords()) {
|
||||
std::string uid = PreProcessUtils::IdGenerator();
|
||||
record->SetUid(uid);
|
||||
int32_t userId = PreProcessUtils::GetHapUidByToken(option.tokenId);
|
||||
for (const auto &record : unifiedData.GetRecords())
|
||||
{
|
||||
auto type = record->GetType();
|
||||
if (IsFileType(type)) {
|
||||
auto file = static_cast<File *>(record.get());
|
||||
std::string remoteUri = AppFileService::GetDfsUriFromLocal(file->GetUri(), userId);
|
||||
if(remoteUri.empty()) {
|
||||
ZLOGW("Get remoteUri failed, uri: %{public}s, remoteUri: %{public}s.", file->GetUri().c_str(), remoteUri.c_str());
|
||||
return E_UNKNOWN;
|
||||
}
|
||||
file->SetRemoteUri(remoteUri);
|
||||
}
|
||||
|
||||
record->SetUid(PreProcessUtils::GetInstance().IdGenerator());
|
||||
}
|
||||
|
||||
|
||||
std::string intention = unifiedData.GetRuntime()->key.intention;
|
||||
auto store = storeCache_.GetStore(intention);
|
||||
if (store == nullptr) {
|
||||
@ -121,10 +143,16 @@ int32_t DataManager::RetrieveData(const QueryOption &query, UnifiedData &unified
|
||||
for (auto record : records) {
|
||||
auto type = record->GetType();
|
||||
std::string uri = "";
|
||||
if (type == UDType::FILE || type == UDType::IMAGE || type == UDType::VIDEO || type == UDType::AUDIO
|
||||
|| type == UDType::FOLDER) {
|
||||
if (IsFileType(type)) {
|
||||
auto file = static_cast<File *>(record.get());
|
||||
uri = file->GetUri();
|
||||
|
||||
std::string localDeviceId=PreProcessUtils::GetLocalDeviceId();
|
||||
ZLOGE("DataManager::RetrieveData, localDeviceId=%{public}s, remoteDeviceId=%{public}s,uri=%{public}s,remoteUri=%{public}s.", localDeviceId.c_str(), (runtime->deviceId).c_str(),file->GetUri().c_str(),file->GetRemoteUri().c_str());
|
||||
if (localDeviceId != runtime->deviceId) {
|
||||
uri = file->GetRemoteUri();
|
||||
file->SetUri(uri); // cross dev, need dis path.
|
||||
}
|
||||
}
|
||||
if (!uri.empty() && (UriPermissionManager::GetInstance().GrantUriPermission(uri, bundleName) != E_OK)) {
|
||||
return E_NO_PERMISSION;
|
||||
|
@ -45,6 +45,7 @@ public:
|
||||
|
||||
private:
|
||||
DataManager();
|
||||
bool IsFileType(UDType udType);
|
||||
int32_t QueryDataCommon(const QueryOption &query, std::vector<UnifiedData> &dataSet, std::shared_ptr<Store> &store);
|
||||
StoreCache storeCache_;
|
||||
std::map<std::string, std::string> authorizationMap_;
|
||||
|
@ -16,11 +16,12 @@
|
||||
#include "preprocess_utils.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "log_print.h"
|
||||
#include "error_code.h"
|
||||
#include "accesstoken_kit.h"
|
||||
#include "bundlemgr/bundle_mgr_client_impl.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "device_manager_adapter.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UDMF {
|
||||
@ -44,10 +45,23 @@ int32_t PreProcessUtils::RuntimeDataImputation(UnifiedData &data, CustomOption &
|
||||
runtime.createTime = GetTimeStamp();
|
||||
runtime.sourcePackage = bundleName;
|
||||
runtime.createPackage = bundleName;
|
||||
runtime.deviceId = GetLocalDeviceId();
|
||||
data.SetRuntime(runtime);
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
std::string PreProcessUtils::GetLocalDeviceId()
|
||||
{
|
||||
auto info = DistributedData::DeviceManagerAdapter::GetInstance().GetLocalDevice();
|
||||
|
||||
std::string encryptedUuid;
|
||||
encryptedUuid = DistributedData::DeviceManagerAdapter::GetInstance().CalcClientUuid(" ", info.uuid);
|
||||
|
||||
ZLOGI("[LocalDevice] uuid:%{public}s, encryptedUuid:%{public}s, name:%{public}s, type:%{public}d",
|
||||
info.uuid.c_str(), encryptedUuid.c_str(), info.deviceName.c_str(), info.deviceType); // if log uuid, need tb be anonymous;
|
||||
return encryptedUuid;
|
||||
}
|
||||
|
||||
std::string PreProcessUtils::IdGenerator()
|
||||
{
|
||||
std::random_device randomDevice;
|
||||
@ -71,6 +85,16 @@ time_t PreProcessUtils::GetTimeStamp()
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
int32_t PreProcessUtils::GetHapUidByToken(uint32_t tokenId) const
|
||||
{
|
||||
HapTokenInfo tokenInfo;
|
||||
auto result = Security::AccessToken::AccessTokenKit::GetHapTokenInfo(tokenId, tokenInfo);
|
||||
if (result != Security::AccessToken::AccessTokenKitRet::RET_SUCCESS) {
|
||||
ZLOGE("token:0x%{public}x, result:%{public}d", tokenId, result);
|
||||
return -1;
|
||||
}
|
||||
return tokenInfo.userID;
|
||||
}
|
||||
bool PreProcessUtils::GetHapBundleNameByToken(int tokenId, std::string &bundleName)
|
||||
{
|
||||
Security::AccessToken::HapTokenInfo hapInfo;
|
||||
|
@ -30,8 +30,10 @@ public:
|
||||
static int32_t RuntimeDataImputation(UnifiedData &data, CustomOption &option);
|
||||
static std::string IdGenerator();
|
||||
static time_t GetTimeStamp();
|
||||
static int32_t GetHapUidByToken(uint32_t tokenId);
|
||||
static bool GetHapBundleNameByToken(int tokenId, std::string &bundleName);
|
||||
static bool GetNativeProcessNameByToken(int tokenId, std::string &processName);
|
||||
static std::string GetLocalDeviceId(); // uuid
|
||||
};
|
||||
} // namespace UDMF
|
||||
} // namespace OHOS
|
||||
|
Loading…
Reference in New Issue
Block a user