mirror of
https://gitee.com/openharmony/distributeddatamgr_datamgr_service
synced 2024-11-27 00:51:12 +00:00
!1239 普通文件uri跨设备拖拽
Merge pull request !1239 from 耿凌霞/drag_cross_dev0629
This commit is contained in:
commit
b3c800599f
@ -74,7 +74,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"
|
||||
|
@ -27,6 +27,9 @@ 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/native/remote_file_share/include",
|
||||
"${device_manager_path}/interfaces/inner_kits/native_cpp/include",
|
||||
"${data_service_path}/adapter/include/communicator",
|
||||
]
|
||||
}
|
||||
|
||||
@ -50,12 +53,16 @@ ohos_shared_library("udmf_server") {
|
||||
|
||||
configs = [ ":module_public_config" ]
|
||||
|
||||
deps = [ "${data_service_path}/framework:distributeddatasvcfwk" ]
|
||||
deps = [
|
||||
"${data_service_path}/adapter:distributeddata_adapter",
|
||||
"${data_service_path}/framework:distributeddatasvcfwk",
|
||||
]
|
||||
|
||||
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",
|
||||
"hilog:libhilog",
|
||||
|
@ -22,9 +22,12 @@
|
||||
#include "log_print.h"
|
||||
#include "preprocess_utils.h"
|
||||
#include "uri_permission_manager.h"
|
||||
#include "remote_file_share.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UDMF {
|
||||
using namespace OHOS::AppFileService;
|
||||
|
||||
const std::string MSDP_PROCESS_NAME = "msdp_sa";
|
||||
const std::string DATA_PREFIX = "udmf://";
|
||||
DataManager::DataManager()
|
||||
@ -43,6 +46,12 @@ DataManager &DataManager::GetInstance()
|
||||
return instance;
|
||||
}
|
||||
|
||||
bool DataManager::IsFileType(UDType udType)
|
||||
{
|
||||
return (udType == UDType::FILE || udType == UDType::IMAGE || udType == UDType::VIDEO || udType == UDType::AUDIO
|
||||
|| udType == UDType::FOLDER);
|
||||
}
|
||||
|
||||
int32_t DataManager::SaveData(CustomOption &option, UnifiedData &unifiedData, std::string &key)
|
||||
{
|
||||
if (unifiedData.IsEmpty()) {
|
||||
@ -60,9 +69,21 @@ 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());
|
||||
struct ModuleRemoteFileShare::HmdfsUriInfo dfsUriInfo;
|
||||
int ret = ModuleRemoteFileShare::RemoteFileShare::GetDfsUriFromLocal(file->GetUri(), userId, dfsUriInfo);
|
||||
if (ret != 0 || dfsUriInfo.uriStr.empty()) {
|
||||
ZLOGE("Get remoteUri failed, ret = %{public}d, userId: %{public}d.", ret, userId);
|
||||
return E_FS_ERROR;
|
||||
}
|
||||
file->SetRemoteUri(dfsUriInfo.uriStr);
|
||||
}
|
||||
|
||||
record->SetUid(PreProcessUtils::IdGenerator());
|
||||
}
|
||||
|
||||
std::string intention = unifiedData.GetRuntime()->key.intention;
|
||||
@ -117,15 +138,10 @@ int32_t DataManager::RetrieveData(const QueryOption &query, UnifiedData &unified
|
||||
return E_ERROR;
|
||||
}
|
||||
if (runtime->createPackage != bundleName) {
|
||||
std::string localDeviceId = PreProcessUtils::GetLocalDeviceId();
|
||||
auto records = unifiedData.GetRecords();
|
||||
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) {
|
||||
auto file = static_cast<File *>(record.get());
|
||||
uri = file->GetUri();
|
||||
}
|
||||
std::string uri = ConvertUri(record, localDeviceId, runtime->deviceId);
|
||||
if (!uri.empty() && (UriPermissionManager::GetInstance().GrantUriPermission(uri, bundleName) != E_OK)) {
|
||||
return E_NO_PERMISSION;
|
||||
}
|
||||
@ -137,6 +153,20 @@ int32_t DataManager::RetrieveData(const QueryOption &query, UnifiedData &unified
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
std::string DataManager::ConvertUri(std::shared_ptr<UnifiedRecord> record, const std::string &localDevId,
|
||||
const std::string &remoteDevId)
|
||||
{
|
||||
std::string uri;
|
||||
if (record != nullptr && IsFileType(record->GetType())) {
|
||||
auto file = static_cast<File *>(record.get());
|
||||
uri = file->GetUri();
|
||||
if (localDevId != remoteDevId) {
|
||||
uri = file->GetRemoteUri();
|
||||
file->SetUri(uri); // cross dev, need dis path.
|
||||
}
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
int32_t DataManager::RetrieveBatchData(const QueryOption &query, std::vector<UnifiedData> &unifiedDataSet)
|
||||
{
|
||||
|
@ -45,7 +45,10 @@ public:
|
||||
|
||||
private:
|
||||
DataManager();
|
||||
bool IsFileType(UDType udType);
|
||||
int32_t QueryDataCommon(const QueryOption &query, std::vector<UnifiedData> &dataSet, std::shared_ptr<Store> &store);
|
||||
std::string ConvertUri(std::shared_ptr<UnifiedRecord> record, const std::string &localDevId,
|
||||
const std::string &remoteDevId);
|
||||
StoreCache storeCache_;
|
||||
std::map<std::string, std::string> authorizationMap_;
|
||||
};
|
||||
|
@ -13,14 +13,17 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "preprocess_utils"
|
||||
|
||||
#include "preprocess_utils.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "error_code.h"
|
||||
#include "accesstoken_kit.h"
|
||||
#include "bundlemgr/bundle_mgr_client_impl.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "device_manager_adapter.h"
|
||||
#include "log_print.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UDMF {
|
||||
@ -44,10 +47,17 @@ 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();
|
||||
return DistributedData::DeviceManagerAdapter::GetInstance().CalcClientUuid(" ", info.uuid);
|
||||
}
|
||||
|
||||
std::string PreProcessUtils::IdGenerator()
|
||||
{
|
||||
std::random_device randomDevice;
|
||||
@ -71,6 +81,17 @@ time_t PreProcessUtils::GetTimeStamp()
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
int32_t PreProcessUtils::GetHapUidByToken(uint32_t tokenId)
|
||||
{
|
||||
Security::AccessToken::HapTokenInfo tokenInfo;
|
||||
auto result = Security::AccessToken::AccessTokenKit::GetHapTokenInfo(tokenId, tokenInfo);
|
||||
if (result != Security::AccessToken::AccessTokenKitRet::RET_SUCCESS) {
|
||||
ZLOGE("GetHapUidByToken failed, result = %{public}d.", result);
|
||||
return E_ERROR;
|
||||
}
|
||||
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