mirror of
https://gitee.com/openharmony/filemanagement_storage_service
synced 2024-11-23 15:09:48 +00:00
commit
46b4ddb365
@ -69,6 +69,10 @@ public:
|
||||
const std::vector<uint8_t> &secret) = 0;
|
||||
virtual int32_t InactiveUserKey(uint32_t userId) = 0;
|
||||
virtual int32_t UpdateKeyContext(uint32_t userId) = 0;
|
||||
|
||||
// app file share api
|
||||
virtual int32_t CreateShareFile(std::string uri, int32_t tokenID, int32_t flag) = 0;
|
||||
virtual int32_t DeleteShareFile(int32_t tokenId, std::vector<std::string>sharePathList) = 0;
|
||||
|
||||
enum {
|
||||
PREPARE_ADD_USER = 1,
|
||||
@ -105,6 +109,8 @@ public:
|
||||
SET_VOL_DESC,
|
||||
FORMAT,
|
||||
GET_DISK_BY_ID,
|
||||
CREATE_SHARE_FILE,
|
||||
DELETE_SHARE_FILE,
|
||||
};
|
||||
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.StorageManager.IStorageManager");
|
||||
|
@ -102,7 +102,11 @@ ohos_executable("storage_daemon") {
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:base",
|
||||
"ability_base:want",
|
||||
"ability_base:zuri",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"app_file_service:fileshare_native",
|
||||
"c_utils:utils",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"init:libbegetutil",
|
||||
|
@ -46,6 +46,8 @@ public:
|
||||
ACTIVE_USER_KEY,
|
||||
INACTIVE_USER_KEY,
|
||||
UPDATE_KEY_CONTEXT,
|
||||
CREATE_SHARE_FILE,
|
||||
DELETE_SHARE_FILE,
|
||||
};
|
||||
|
||||
enum {
|
||||
@ -82,6 +84,10 @@ public:
|
||||
virtual int32_t InactiveUserKey(uint32_t userId) = 0;
|
||||
virtual int32_t UpdateKeyContext(uint32_t userId) = 0;
|
||||
|
||||
// app file share api
|
||||
virtual int32_t CreateShareFile(std::string uri, int32_t tokenId, int32_t flag) = 0;
|
||||
virtual int32_t DeleteShareFile(int32_t tokenId, std::vector<std::string>sharePathList) = 0;
|
||||
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.StorageDaemon");
|
||||
};
|
||||
} // STORAGE_DAEMON
|
||||
|
@ -53,6 +53,10 @@ public:
|
||||
const std::vector<uint8_t> &secret) override;
|
||||
virtual int32_t InactiveUserKey(uint32_t userId) override;
|
||||
virtual int32_t UpdateKeyContext(uint32_t userId) override;
|
||||
|
||||
// app file share api
|
||||
virtual int32_t CreateShareFile(std::string uri, int32_t tokenId, int32_t flag) override;
|
||||
virtual int32_t DeleteShareFile(int32_t tokenId, std::vector<std::string>sharePathList) override;
|
||||
};
|
||||
} // StorageDaemon
|
||||
} // OHOS
|
||||
|
@ -53,6 +53,10 @@ public:
|
||||
virtual int32_t InactiveUserKey(uint32_t userId) override;
|
||||
virtual int32_t UpdateKeyContext(uint32_t userId) override;
|
||||
|
||||
// app file share api
|
||||
virtual int32_t CreateShareFile(std::string uri, int32_t tokenId, int32_t flag) override;
|
||||
virtual int32_t DeleteShareFile(int32_t tokenId, std::vector<std::string>sharePathList) override;
|
||||
|
||||
private:
|
||||
static inline BrokerDelegator<StorageDaemonProxy> delegator_;
|
||||
int32_t SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
|
||||
|
@ -52,6 +52,10 @@ private:
|
||||
int32_t HandleActiveUserKey(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleInactiveUserKey(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleUpdateKeyContext(MessageParcel &data, MessageParcel &reply);
|
||||
|
||||
// app file share api
|
||||
int32_t HandleCreateShareFile(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleDeleteShareFile(MessageParcel &data, MessageParcel &reply);
|
||||
};
|
||||
} // StorageDaemon
|
||||
} // OHOS
|
||||
|
@ -55,6 +55,8 @@ private:
|
||||
int32_t HmdfsTwiceMount(int32_t userId, std::string relativePath);
|
||||
int32_t HmdfsUMount(int32_t userId);
|
||||
int32_t HmdfsUMount(int32_t userId, std::string relativePath);
|
||||
int32_t SharefsMount(int32_t userId);
|
||||
int32_t SharefsUMount(int32_t userId);
|
||||
int32_t HmdfsTwiceUMount(int32_t userId, std::string relativePath);
|
||||
int32_t LocalMount(int32_t userId);
|
||||
int32_t LocalUMount(int32_t userId);
|
||||
|
@ -33,6 +33,9 @@ struct MountArgument final {
|
||||
|
||||
std::string GetFullSrc() const;
|
||||
std::string GetFullDst() const;
|
||||
std::string GetShareSrc() const;
|
||||
std::string GetShareDst() const;
|
||||
std::string GetUserIdPara() const;
|
||||
std::string GetCommFullPath() const;
|
||||
std::string GetCachePath() const;
|
||||
std::string GetCtrlPath() const;
|
||||
|
@ -17,12 +17,14 @@
|
||||
|
||||
#include "crypto/key_manager.h"
|
||||
#include "disk/disk_manager.h"
|
||||
#include "file_share.h"
|
||||
#include "file_sharing/file_sharing.h"
|
||||
#include "storage_service_errno.h"
|
||||
#include "storage_service_log.h"
|
||||
#include "user/user_manager.h"
|
||||
#include "volume/volume_manager.h"
|
||||
|
||||
|
||||
namespace OHOS {
|
||||
namespace StorageDaemon {
|
||||
int32_t StorageDaemon::Shutdown()
|
||||
@ -152,5 +154,15 @@ int32_t StorageDaemon::UpdateKeyContext(uint32_t userId)
|
||||
{
|
||||
return KeyManager::GetInstance()->UpdateKeyContext(userId);
|
||||
}
|
||||
|
||||
int32_t StorageDaemon::CreateShareFile(std::string uri, int32_t tokenId, int32_t flag)
|
||||
{
|
||||
return AppFileService::FileShare::CreateShareFile(uri, tokenId, flag);
|
||||
}
|
||||
|
||||
int32_t StorageDaemon::DeleteShareFile(int32_t tokenId, std::vector<std::string>sharePathList)
|
||||
{
|
||||
return AppFileService::FileShare::DeleteShareFile(tokenId, sharePathList);
|
||||
}
|
||||
} // StorageDaemon
|
||||
} // OHOS
|
||||
|
@ -461,6 +461,68 @@ int32_t StorageDaemonProxy::UpdateKeyContext(uint32_t userId)
|
||||
return reply.ReadInt32();
|
||||
}
|
||||
|
||||
int32_t StorageDaemonProxy::CreateShareFile(std::string uri, int32_t tokenId, int32_t flag)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
|
||||
if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
|
||||
return E_WRITE_DESCRIPTOR_ERR;
|
||||
}
|
||||
|
||||
if (!data.WriteString(uri)) {
|
||||
return E_WRITE_PARCEL_ERR;
|
||||
}
|
||||
|
||||
if (!data.WriteUint32(tokenId)) {
|
||||
return E_WRITE_PARCEL_ERR;
|
||||
}
|
||||
|
||||
if (!data.WriteUint32(flag)) {
|
||||
return E_WRITE_PARCEL_ERR;
|
||||
}
|
||||
|
||||
int err = SendRequest(CREATE_SHARE_FILE, data, reply, option);
|
||||
if (err != E_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return reply.ReadInt32();
|
||||
}
|
||||
|
||||
int32_t StorageDaemonProxy::DeleteShareFile(int32_t tokenId, std::vector<std::string>sharePathList)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_ASYNC);
|
||||
|
||||
if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
|
||||
return E_WRITE_DESCRIPTOR_ERR;
|
||||
}
|
||||
|
||||
if (!data.WriteUint32(tokenId)) {
|
||||
return E_WRITE_PARCEL_ERR;
|
||||
}
|
||||
|
||||
size_t length = sharePathList.size();
|
||||
if (!data.WriteUint32(length)) {
|
||||
return E_WRITE_PARCEL_ERR;
|
||||
}
|
||||
|
||||
for (auto &sharePath : sharePathList) {
|
||||
if (!data.WriteString(sharePath)) {
|
||||
return E_WRITE_PARCEL_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
int err = SendRequest(DELETE_SHARE_FILE, data, reply, option);
|
||||
if (err != E_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return reply.ReadInt32();
|
||||
}
|
||||
int32_t StorageDaemonProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
|
@ -90,6 +90,12 @@ int32_t StorageDaemonStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
|
||||
case UPDATE_KEY_CONTEXT:
|
||||
err = HandleUpdateKeyContext(data, reply);
|
||||
break;
|
||||
case CREATE_SHARE_FILE:
|
||||
err = HandleCreateShareFile(data, reply);
|
||||
break;
|
||||
case DELETE_SHARE_FILE:
|
||||
err = HandleDeleteShareFile(data, reply);
|
||||
break;
|
||||
default: {
|
||||
LOGI(" use IPCObjectStub default OnRemoteRequest");
|
||||
err = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
@ -335,5 +341,33 @@ int32_t StorageDaemonStub::HandleUpdateKeyContext(MessageParcel &data, MessagePa
|
||||
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t StorageDaemonStub::HandleCreateShareFile(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
std::string uri = data.ReadString();
|
||||
int32_t tokenId = data.ReadInt32();
|
||||
int32_t flag = data.ReadUint32();
|
||||
int err = CreateShareFile(uri, tokenId, flag);
|
||||
if (!reply.WriteInt32(err)) {
|
||||
return E_WRITE_REPLY_ERR;
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t StorageDaemonStub::HandleDeleteShareFile(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
int32_t tokenId = data.ReadInt32();
|
||||
int32_t length = data.ReadInt32();
|
||||
std::vector<std::string> sharePathList;
|
||||
for (int32_t i = 0; i < length; i++) {
|
||||
std::string path = data.ReadString();
|
||||
sharePathList.emplace_back(path);
|
||||
}
|
||||
int err = DeleteShareFile(tokenId, sharePathList);
|
||||
if (!reply.WriteInt32(err)) {
|
||||
return E_WRITE_REPLY_ERR;
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
} // StorageDaemon
|
||||
} // OHOS
|
||||
|
@ -63,7 +63,11 @@ ohos_unittest("storage_daemon_test") {
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:base",
|
||||
"ability_base:want",
|
||||
"ability_base:zuri",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"app_file_service:fileshare_native",
|
||||
"c_utils:utils",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"init:libbegetutil",
|
||||
|
@ -131,6 +131,16 @@ public:
|
||||
{
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
virtual int32_t CreateShareFile(std::string uri, int32_t tokenId, int32_t flag) override
|
||||
{
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
virtual int32_t DeleteShareFile(int32_t tokenId, std::vector<std::string>sharePathList) override
|
||||
{
|
||||
return E_OK;
|
||||
}
|
||||
};
|
||||
} // namespace StorageDaemon
|
||||
} // namespace OHOS
|
||||
|
@ -46,6 +46,8 @@ public:
|
||||
MOCK_METHOD3(ActiveUserKey, int32_t (uint32_t, const std::vector<uint8_t> &, const std::vector<uint8_t> &));
|
||||
MOCK_METHOD1(InactiveUserKey, int32_t (uint32_t));
|
||||
MOCK_METHOD1(UpdateKeyContext, int32_t (uint32_t));
|
||||
MOCK_METHOD3(CreateShareFile, int32_t (std::string, int32_t, int32_t));
|
||||
MOCK_METHOD2(DeleteShareFile, int32_t (int32_t, std::vector<std::string>));
|
||||
};
|
||||
} // namespace StorageDaemon
|
||||
} // namespace OHOS
|
||||
|
@ -5,6 +5,7 @@
|
||||
"start storage_daemon",
|
||||
"mount configfs none /config",
|
||||
"chown foundation system /config/hmdfs",
|
||||
"chown foundation system /config/sharefs",
|
||||
"mkdir /mnt/external 0711 root file_manager"
|
||||
]
|
||||
}
|
||||
|
@ -37,7 +37,8 @@ const std::string HMDFS_SYS_CAP = "const.distributed_file_property.enabled";
|
||||
const int32_t HMDFS_VAL_LEN = 6;
|
||||
const int32_t HMDFS_TRUE_LEN = 5;
|
||||
MountManager::MountManager()
|
||||
: hmdfsDirVec_{{"/data/service/el2/%d/hmdfs", 0711, OID_SYSTEM, OID_SYSTEM},
|
||||
: hmdfsDirVec_{{"/data/service/el2/%d/share", 0711, OID_SYSTEM, OID_SYSTEM},
|
||||
{"/data/service/el2/%d/hmdfs", 0711, OID_SYSTEM, OID_SYSTEM},
|
||||
{"/data/service/el2/%d/hmdfs/account", 0711, OID_SYSTEM, OID_SYSTEM},
|
||||
{"/data/service/el2/%d/hmdfs/account/files", 02771, OID_USER_DATA_RW, OID_USER_DATA_RW},
|
||||
{"/data/service/el2/%d/hmdfs/account/data", 0711, OID_SYSTEM, OID_SYSTEM},
|
||||
@ -50,6 +51,8 @@ MountManager::MountManager()
|
||||
{"/data/service/el2/%d/hmdfs/account/services", 0771, OID_DFS_SHARE, OID_DFS_SHARE}},
|
||||
virtualDir_{{"/storage/media/%d", 0711, OID_USER_DATA_RW, OID_USER_DATA_RW},
|
||||
{"/storage/media/%d/local", 0711, OID_USER_DATA_RW, OID_USER_DATA_RW},
|
||||
{"/mnt/share/", 0711, OID_ROOT, OID_ROOT},
|
||||
{"/mnt/share/%d/", 0711, OID_ROOT, OID_ROOT},
|
||||
{"/mnt/hmdfs/", 0711, OID_ROOT, OID_ROOT},
|
||||
{"/mnt/hmdfs/%d/", 0711, OID_ROOT, OID_ROOT},
|
||||
{"/mnt/hmdfs/%d/account", 0711, OID_ROOT, OID_ROOT},
|
||||
@ -80,6 +83,30 @@ int32_t MountManager::HmdfsTwiceMount(int32_t userId, std::string relativePath)
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t MountManager::SharefsMount(int32_t userId)
|
||||
{
|
||||
Utils::MountArgument sharefsMntArgs(Utils::MountArgumentDescriptors::Alpha(userId, ""));
|
||||
int ret = Mount(sharefsMntArgs.GetShareSrc(), sharefsMntArgs.GetShareDst(), "sharefs",
|
||||
sharefsMntArgs.GetFlags(), sharefsMntArgs.GetUserIdPara().c_str());
|
||||
if (ret != 0 && errno != EEXIST && errno != EBUSY) {
|
||||
LOGE("failed to mount sharefs, err %{public}d", errno);
|
||||
return E_MOUNT;
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t MountManager::SharefsUMount(int32_t userId)
|
||||
{
|
||||
Utils::MountArgument sharefsMntArgs(Utils::MountArgumentDescriptors::Alpha(userId, ""));
|
||||
int32_t ret = UMount2(sharefsMntArgs.GetShareDst().c_str(), MNT_DETACH);
|
||||
if (ret != E_OK) {
|
||||
LOGE("umount sharefs, errno %{public}d, sharefs dst %{public}s", errno,
|
||||
sharefsMntArgs.GetShareDst().c_str());
|
||||
return E_UMOUNT;
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t MountManager::HmdfsMount(int32_t userId, std::string relativePath)
|
||||
{
|
||||
Utils::MountArgument hmdfsMntArgs(Utils::MountArgumentDescriptors::Alpha(userId, relativePath));
|
||||
@ -176,17 +203,28 @@ int32_t MountManager::LocalMount(int32_t userId)
|
||||
|
||||
int32_t MountManager::MountByUser(int32_t userId)
|
||||
{
|
||||
int ret = E_OK;
|
||||
if (CreateVirtualDirs(userId) != E_OK) {
|
||||
LOGE("create hmdfs virtual dir error");
|
||||
return E_PREPARE_DIR;
|
||||
}
|
||||
|
||||
if (!SupportHmdfs()) {
|
||||
return LocalMount(userId);
|
||||
ret = LocalMount(userId);
|
||||
} else {
|
||||
return HmdfsMount(userId);
|
||||
ret = HmdfsMount(userId);
|
||||
}
|
||||
|
||||
if (!ret) {
|
||||
LOGE("hmdfs mount error");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = SharefsMount(userId);
|
||||
if (!ret) {
|
||||
LOGE("sharefs mount error");
|
||||
return ret;
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
@ -201,20 +239,26 @@ int32_t MountManager::UmountByUser(int32_t userId)
|
||||
int32_t count = 0;
|
||||
while (count < UMOUNT_RETRY_TIMES) {
|
||||
int32_t err = E_OK;
|
||||
err = SharefsUMount(userId);
|
||||
if (!SupportHmdfs()) {
|
||||
err = LocalUMount(userId);
|
||||
} else {
|
||||
err = HmdfsUMount(userId);
|
||||
}
|
||||
if (err == E_OK) {
|
||||
break;
|
||||
} else if (errno == EBUSY) {
|
||||
if (errno == EBUSY) {
|
||||
count++;
|
||||
continue;
|
||||
} else {
|
||||
LOGE("failed to umount, errno %{public}d", errno);
|
||||
LOGE("failed to umount hmdfs, errno %{public}d", errno);
|
||||
return E_UMOUNT;
|
||||
}
|
||||
if (err != E_OK && err != EBUSY) {
|
||||
LOGE("failed to umount sharefs, errno %{public}d", errno);
|
||||
return E_UMOUNT;
|
||||
}
|
||||
if (err == E_OK) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return E_OK;
|
||||
|
@ -27,6 +27,8 @@ namespace {
|
||||
static const std::string BASE_MOUNT_POINT = "/mnt/hmdfs/";
|
||||
static const std::string SYSFS_HMDFS_PATH = "/sys/fs/hmdfs/";
|
||||
static const std::string COMM_DATA_POINT = "/storage/media/";
|
||||
static const std::string SHAREFS_DATA_POINT = "/data/service/el2/";
|
||||
static const std::string SHAREFS_BASE_MOUNT_POINT = "/mnt/share/";
|
||||
} // namespace
|
||||
|
||||
string MountArgument::GetFullSrc() const
|
||||
@ -45,6 +47,30 @@ string MountArgument::GetFullDst() const
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
string MountArgument::GetShareSrc() const
|
||||
{
|
||||
stringstream ss;
|
||||
ss << SHAREFS_DATA_POINT << userId_ << "/share";
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
string MountArgument::GetUserIdPara() const
|
||||
{
|
||||
stringstream ss;
|
||||
ss << "user_id=" << userId_;
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
string MountArgument::GetShareDst() const
|
||||
{
|
||||
stringstream ss;
|
||||
ss << SHAREFS_BASE_MOUNT_POINT << userId_;
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
string MountArgument::GetCommFullPath() const
|
||||
{
|
||||
stringstream ss;
|
||||
|
@ -83,6 +83,10 @@ public:
|
||||
const std::vector<uint8_t> &secret) override;
|
||||
int32_t InactiveUserKey(uint32_t userId) override;
|
||||
int32_t UpdateKeyContext(uint32_t userId) override;
|
||||
|
||||
// app file share api
|
||||
int32_t CreateShareFile(std::string uri, int32_t tokenId, int32_t flag) override;
|
||||
int32_t DeleteShareFile(int32_t tokenId, std::vector<std::string>sharePathList) override;
|
||||
private:
|
||||
StorageManager();
|
||||
static sptr<StorageManager> instance_;
|
||||
|
@ -70,6 +70,10 @@ public:
|
||||
int32_t InactiveUserKey(uint32_t userId) override;
|
||||
int32_t UpdateKeyContext(uint32_t userId) override;
|
||||
|
||||
// app file share api
|
||||
int32_t CreateShareFile(std::string uri, int32_t tokenId, int32_t flag) override;
|
||||
int32_t DeleteShareFile(int32_t tokenId, std::vector<std::string>sharePathList) override;
|
||||
|
||||
private:
|
||||
static inline BrokerDelegator<StorageManagerProxy> delegator_;
|
||||
int32_t SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
|
||||
|
@ -62,6 +62,10 @@ private:
|
||||
int32_t HandleActiveUserKey(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleInactiveUserKey(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleUpdateKeyContext(MessageParcel &data, MessageParcel &reply);
|
||||
|
||||
// app file share api
|
||||
int32_t HandleCreateShareFile(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleDeleteShareFile(MessageParcel &data, MessageParcel &reply);
|
||||
};
|
||||
} // StorageManager
|
||||
} // OHOS
|
||||
|
@ -56,6 +56,10 @@ public:
|
||||
int32_t UpdateKeyContext(uint32_t userId);
|
||||
|
||||
int32_t ResetSdProxy();
|
||||
|
||||
// app file share api
|
||||
int32_t CreateShareFile(std::string uri, int32_t tokenId, int32_t flag);
|
||||
int32_t DeleteShareFile(int32_t tokenId, std::vector<std::string> sharePathList);
|
||||
private:
|
||||
sptr<OHOS::StorageDaemon::IStorageDaemon> storageDaemon_;
|
||||
sptr<IRemoteObject::DeathRecipient> deathRecipient_ = nullptr;
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "account_subscriber/account_subscriber.h"
|
||||
#include "crypto/filesystem_crypto.h"
|
||||
#include "disk/disk_manager_service.h"
|
||||
#include "storage_daemon_communication/storage_daemon_communication.h"
|
||||
#include "storage_service_errno.h"
|
||||
#include "storage_service_log.h"
|
||||
#include "system_ability_definition.h"
|
||||
@ -306,5 +307,19 @@ int32_t StorageManager::UpdateKeyContext(uint32_t userId)
|
||||
int32_t err = fsCrypto->UpdateKeyContext(userId);
|
||||
return err;
|
||||
}
|
||||
|
||||
int32_t StorageManager::CreateShareFile(std::string uri, int32_t tokenId, int32_t flag)
|
||||
{
|
||||
std::shared_ptr<StorageDaemonCommunication> sdCommunication;
|
||||
sdCommunication = DelayedSingleton<StorageDaemonCommunication>::GetInstance();
|
||||
return sdCommunication->CreateShareFile(uri, tokenId, flag);
|
||||
}
|
||||
|
||||
int32_t StorageManager::DeleteShareFile(int32_t tokenId, std::vector<std::string> sharePathList)
|
||||
{
|
||||
std::shared_ptr<StorageDaemonCommunication> sdCommunication;
|
||||
sdCommunication = DelayedSingleton<StorageDaemonCommunication>::GetInstance();
|
||||
return sdCommunication->DeleteShareFile(tokenId, sharePathList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -851,6 +851,69 @@ int32_t StorageManagerProxy::GetDiskById(std::string diskId, Disk &disk)
|
||||
return reply.ReadInt32();
|
||||
}
|
||||
|
||||
int32_t StorageManagerProxy::CreateShareFile(std::string uri, int32_t tokenId, int32_t flag)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
|
||||
if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
|
||||
return E_WRITE_DESCRIPTOR_ERR;
|
||||
}
|
||||
|
||||
if (!data.WriteString(uri)) {
|
||||
return E_WRITE_PARCEL_ERR;
|
||||
}
|
||||
|
||||
if (!data.WriteUint32(tokenId)) {
|
||||
return E_WRITE_PARCEL_ERR;
|
||||
}
|
||||
|
||||
if (!data.WriteUint32(flag)) {
|
||||
return E_WRITE_PARCEL_ERR;
|
||||
}
|
||||
|
||||
int err = SendRequest(CREATE_SHARE_FILE, data, reply, option);
|
||||
if (err != E_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return reply.ReadInt32();
|
||||
}
|
||||
|
||||
int32_t StorageManagerProxy::DeleteShareFile(int32_t tokenId, std::vector<std::string>sharePathList)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_ASYNC);
|
||||
|
||||
if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
|
||||
return E_WRITE_DESCRIPTOR_ERR;
|
||||
}
|
||||
|
||||
if (!data.WriteUint32(tokenId)) {
|
||||
return E_WRITE_PARCEL_ERR;
|
||||
}
|
||||
|
||||
size_t length = sharePathList.size();
|
||||
if (!data.WriteUint32(length)) {
|
||||
return E_WRITE_PARCEL_ERR;
|
||||
}
|
||||
|
||||
for (auto &sharePath : sharePathList) {
|
||||
if (!data.WriteString(sharePath)) {
|
||||
return E_WRITE_PARCEL_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
int err = SendRequest(DELETE_SHARE_FILE, data, reply, option);
|
||||
if (err != E_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return reply.ReadInt32();
|
||||
}
|
||||
|
||||
int32_t StorageManagerProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
{
|
||||
|
@ -148,6 +148,12 @@ int32_t StorageManagerStub::OnRemoteRequest(uint32_t code,
|
||||
case UPDATE_KEY_CONTEXT:
|
||||
err = HandleUpdateKeyContext(data, reply);
|
||||
break;
|
||||
case CREATE_SHARE_FILE:
|
||||
err = HandleCreateShareFile(data, reply);
|
||||
break;
|
||||
case DELETE_SHARE_FILE:
|
||||
err = HandleDeleteShareFile(data, reply);
|
||||
break;
|
||||
default: {
|
||||
LOGI("use IPCObjectStub default OnRemoteRequest");
|
||||
err = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
@ -715,5 +721,39 @@ int32_t StorageManagerStub::HandleUpdateKeyContext(MessageParcel &data, MessageP
|
||||
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t StorageManagerStub::HandleCreateShareFile(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
if (!CheckClientPermission(PERMISSION_STORAGE_MANAGER)) {
|
||||
return E_PERMISSION_DENIED;
|
||||
}
|
||||
std::string uri = data.ReadString();
|
||||
int32_t tokenId = data.ReadInt32();
|
||||
int32_t flag = data.ReadUint32();
|
||||
int err = CreateShareFile(uri, tokenId, flag);
|
||||
if (!reply.WriteInt32(err)) {
|
||||
return E_WRITE_REPLY_ERR;
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t StorageManagerStub::HandleDeleteShareFile(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
if (!CheckClientPermission(PERMISSION_STORAGE_MANAGER)) {
|
||||
return E_PERMISSION_DENIED;
|
||||
}
|
||||
int32_t tokenId = data.ReadInt32();
|
||||
int32_t length = data.ReadInt32();
|
||||
std::vector<std::string> sharePathList;
|
||||
for (int32_t i = 0; i < length; i++) {
|
||||
std::string path = data.ReadString();
|
||||
sharePathList.emplace_back(path);
|
||||
}
|
||||
int err = DeleteShareFile(tokenId, sharePathList);
|
||||
if (!reply.WriteInt32(err)) {
|
||||
return E_WRITE_REPLY_ERR;
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
} // StorageManager
|
||||
} // OHOS
|
||||
|
@ -50,6 +50,8 @@ ohos_unittest("storage_manager_proxy_test") {
|
||||
external_deps = [
|
||||
"ability_base:base",
|
||||
"ability_base:want",
|
||||
"ability_base:zuri",
|
||||
"app_file_service:fileshare_native",
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
@ -96,9 +98,13 @@ ohos_unittest("storage_manager_stub_test") {
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:base",
|
||||
"ability_base:want",
|
||||
"ability_base:zuri",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"access_token:libnativetoken",
|
||||
"access_token:libtoken_setproc",
|
||||
"app_file_service:fileshare_native",
|
||||
"c_utils:utils",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"init:libbegetutil",
|
||||
@ -144,7 +150,11 @@ ohos_unittest("storage_manager_stub_nonpermission_test") {
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:base",
|
||||
"ability_base:want",
|
||||
"ability_base:zuri",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"app_file_service:fileshare_native",
|
||||
"c_utils:utils",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"init:libbegetutil",
|
||||
|
@ -210,6 +210,16 @@ public:
|
||||
{
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
virtual int32_t CreateShareFile(std::string uri, int32_t tokenId, int32_t flag) override
|
||||
{
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
virtual int32_t DeleteShareFile(int32_t tokenId, std::vector<std::string>sharePathList) override
|
||||
{
|
||||
return E_OK;
|
||||
}
|
||||
};
|
||||
} // namespace StorageManager
|
||||
} // namespace OHOS
|
||||
|
@ -61,6 +61,8 @@ public:
|
||||
MOCK_METHOD3(ActiveUserKey, int32_t(uint32_t, const std::vector<uint8_t> &, const std::vector<uint8_t> &));
|
||||
MOCK_METHOD1(InactiveUserKey, int32_t(uint32_t));
|
||||
MOCK_METHOD1(UpdateKeyContext, int32_t(uint32_t));
|
||||
MOCK_METHOD3(CreateShareFile, int32_t (std::string, int32_t, int32_t));
|
||||
MOCK_METHOD2(DeleteShareFile, int32_t (int32_t, std::vector<std::string>));
|
||||
};
|
||||
} // namespace StorageManager
|
||||
} // namespace OHOS
|
||||
|
@ -266,5 +266,27 @@ void SdDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
|
||||
{
|
||||
DelayedSingleton<StorageDaemonCommunication>::GetInstance()->ResetSdProxy();
|
||||
}
|
||||
|
||||
int32_t StorageDaemonCommunication::CreateShareFile(std::string uri, int32_t tokenId, int32_t flag)
|
||||
{
|
||||
LOGI("enter");
|
||||
int32_t err = Connect();
|
||||
if (err != E_OK) {
|
||||
LOGE("Connect failed");
|
||||
return err;
|
||||
}
|
||||
return storageDaemon_->CreateShareFile(uri, tokenId, flag);
|
||||
}
|
||||
|
||||
int32_t StorageDaemonCommunication::DeleteShareFile(int32_t tokenId, std::vector<std::string>sharePathList)
|
||||
{
|
||||
LOGI("enter");
|
||||
int32_t err = Connect();
|
||||
if (err != E_OK) {
|
||||
LOGE("Connect failed");
|
||||
return err;
|
||||
}
|
||||
return storageDaemon_->DeleteShareFile(tokenId, sharePathList);
|
||||
}
|
||||
} // namespace StorageManager
|
||||
} // namespace OHOS
|
||||
|
Loading…
Reference in New Issue
Block a user