mirror of
https://gitee.com/openharmony/filemanagement_storage_service
synced 2024-11-26 16:53:57 +00:00
This commit is contained in:
parent
2663d4e1dc
commit
54b8ec0f4d
@ -39,6 +39,7 @@ public:
|
||||
virtual int32_t RemoveUser(int32_t userId, uint32_t flags) = 0;
|
||||
virtual int32_t PrepareStartUser(int32_t userId) = 0;
|
||||
virtual int32_t StopUser(int32_t userId) = 0;
|
||||
virtual int32_t CompleteAddUser(int32_t userId) = 0;
|
||||
virtual int32_t GetFreeSizeOfVolume(std::string volumeUuid, int64_t &freeSize) = 0;
|
||||
virtual int32_t GetTotalSizeOfVolume(std::string volumeUuid, int64_t &totalSize) = 0;
|
||||
virtual int32_t GetBundleStats(std::string pkgName, BundleStats &bundleStats, int32_t appIndex = 0) = 0;
|
||||
|
@ -39,6 +39,7 @@ namespace StorageManager {
|
||||
REMOVE_USER,
|
||||
PREPARE_START_USER,
|
||||
STOP_USER,
|
||||
COMPLETE_ADD_USER,
|
||||
GET_TOTAL,
|
||||
GET_FREE,
|
||||
GET_BUNDLE_STATUS,
|
||||
|
@ -31,6 +31,7 @@ public:
|
||||
int32_t RemoveUser(int32_t userId, uint32_t flags) override;
|
||||
int32_t PrepareStartUser(int32_t userId) override;
|
||||
int32_t StopUser(int32_t userId) override;
|
||||
int32_t CompleteAddUser(int32_t userId) override;
|
||||
int32_t GetFreeSizeOfVolume(std::string volumeUuid, int64_t &freeSize) override;
|
||||
int32_t GetTotalSizeOfVolume(std::string volumeUuid, int64_t &totalSize) override;
|
||||
int32_t GetBundleStats(std::string pkgName, BundleStats &bundleStats, int32_t appIndex) override;
|
||||
|
@ -44,6 +44,7 @@ public:
|
||||
virtual int32_t StopUser(int32_t userId) = 0;
|
||||
virtual int32_t PrepareUserDirs(int32_t userId, uint32_t flags) = 0;
|
||||
virtual int32_t DestroyUserDirs(int32_t userId, uint32_t flags) = 0;
|
||||
virtual int32_t CompleteAddUser(int32_t userId) = 0;
|
||||
|
||||
// fscrypt api
|
||||
virtual int32_t InitGlobalKey(void) = 0;
|
||||
|
@ -48,6 +48,7 @@ public:
|
||||
virtual int32_t StopUser(int32_t userId) override;
|
||||
virtual int32_t PrepareUserDirs(int32_t userId, uint32_t flags) override;
|
||||
virtual int32_t DestroyUserDirs(int32_t userId, uint32_t flags) override;
|
||||
virtual int32_t CompleteAddUser(int32_t userId) override;
|
||||
|
||||
// fscrypt api, add fs mutex in KeyManager
|
||||
virtual int32_t InitGlobalKey(void) override;
|
||||
|
@ -34,6 +34,7 @@ namespace StorageDaemon {
|
||||
DESTROY_USER_DIRS,
|
||||
START_USER,
|
||||
STOP_USER,
|
||||
COMPLETE_ADD_USER,
|
||||
INIT_GLOBAL_KEY,
|
||||
INIT_GLOBAL_USER_KEYS,
|
||||
CREATE_USER_KEYS,
|
||||
|
@ -37,6 +37,7 @@ public:
|
||||
virtual int32_t StopUser(int32_t userId) override;
|
||||
virtual int32_t PrepareUserDirs(int32_t userId, uint32_t flags) override;
|
||||
virtual int32_t DestroyUserDirs(int32_t userId, uint32_t flags) override;
|
||||
virtual int32_t CompleteAddUser(int32_t userId) override;
|
||||
|
||||
// fscrypt api
|
||||
virtual int32_t InitGlobalKey(void) override;
|
||||
|
@ -50,6 +50,7 @@ private:
|
||||
int32_t HandleStopUser(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandlePrepareUserDirs(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleDestroyUserDirs(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleCompleteAddUser(MessageParcel &data, MessageParcel &reply);
|
||||
|
||||
// fscrypt api
|
||||
int32_t HandleInitGlobalKey(MessageParcel &data, MessageParcel &reply);
|
||||
|
@ -356,6 +356,12 @@ int32_t StorageDaemon::StopUser(int32_t userId)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t StorageDaemon::CompleteAddUser(int32_t userId)
|
||||
{
|
||||
LOGI("CompleteAddUser enter.");
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t StorageDaemon::InitGlobalKey(void)
|
||||
{
|
||||
#ifdef USER_CRYPTO_MANAGER
|
||||
|
@ -274,6 +274,28 @@ int32_t StorageDaemonProxy::StopUser(int32_t userId)
|
||||
return reply.ReadUint32();
|
||||
}
|
||||
|
||||
int32_t StorageDaemonProxy::CompleteAddUser(int32_t userId)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
|
||||
if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
|
||||
return E_WRITE_DESCRIPTOR_ERR;
|
||||
}
|
||||
|
||||
if (!data.WriteInt32(userId)) {
|
||||
return E_WRITE_PARCEL_ERR;
|
||||
}
|
||||
|
||||
int32_t err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::COMPLETE_ADD_USER), data, reply, option);
|
||||
if (err != E_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return reply.ReadUint32();
|
||||
}
|
||||
|
||||
int32_t StorageDaemonProxy::InitGlobalKey(void)
|
||||
{
|
||||
MessageParcel data;
|
||||
|
@ -115,6 +115,7 @@ int32_t StorageDaemonStub::OnRemoteRequest(uint32_t code,
|
||||
case static_cast<uint32_t>(StorageDaemonInterfaceCode::DESTROY_USER_DIRS):
|
||||
case static_cast<uint32_t>(StorageDaemonInterfaceCode::START_USER):
|
||||
case static_cast<uint32_t>(StorageDaemonInterfaceCode::STOP_USER):
|
||||
case static_cast<uint32_t>(StorageDaemonInterfaceCode::COMPLETE_ADD_USER):
|
||||
case static_cast<uint32_t>(StorageDaemonInterfaceCode::INIT_GLOBAL_KEY):
|
||||
case static_cast<uint32_t>(StorageDaemonInterfaceCode::INIT_GLOBAL_USER_KEYS):
|
||||
case static_cast<uint32_t>(StorageDaemonInterfaceCode::CREATE_USER_KEYS):
|
||||
@ -178,6 +179,8 @@ int32_t StorageDaemonStub::OnRemoteRequestForUser(uint32_t code, MessageParcel &
|
||||
return HandleStartUser(data, reply);
|
||||
case static_cast<uint32_t>(StorageDaemonInterfaceCode::STOP_USER):
|
||||
return HandleStopUser(data, reply);
|
||||
case static_cast<uint32_t>(StorageDaemonInterfaceCode::COMPLETE_ADD_USER):
|
||||
return HandleCompleteAddUser(data, reply);
|
||||
case static_cast<uint32_t>(StorageDaemonInterfaceCode::INIT_GLOBAL_KEY):
|
||||
return HandleInitGlobalKey(data, reply);
|
||||
case static_cast<uint32_t>(StorageDaemonInterfaceCode::INIT_GLOBAL_USER_KEYS):
|
||||
@ -368,6 +371,18 @@ int32_t StorageDaemonStub::HandleStopUser(MessageParcel &data, MessageParcel &re
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t StorageDaemonStub::HandleCompleteAddUser(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
int32_t userId = data.ReadInt32();
|
||||
|
||||
int32_t err = CompleteAddUser(userId);
|
||||
if (!reply.WriteInt32(err)) {
|
||||
return E_WRITE_REPLY_ERR;
|
||||
}
|
||||
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t StorageDaemonStub::HandleInitGlobalKey(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
int err = InitGlobalKey();
|
||||
|
@ -161,6 +161,29 @@ HWTEST_F(StorageDaemonProxyTest, StorageDaemonProxyTest_StopUser_001, TestSize.L
|
||||
GTEST_LOG_(INFO) << "StorageDaemonProxyTest_StopUser_001 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: StorageDaemonProxyTest_StopUser_001
|
||||
* @tc.desc: Verify the StopUser function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000GK4HB
|
||||
*/
|
||||
HWTEST_F(StorageDaemonProxyTest, StorageDaemonProxyTest_CompleteAddUser_001, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "StorageDaemonProxyTest_CompleteAddUser_001 start";
|
||||
|
||||
EXPECT_CALL(*mock_, SendRequest(testing::_, testing::_, testing::_, testing::_))
|
||||
.Times(1)
|
||||
.WillOnce(testing::Invoke(mock_.GetRefPtr(), &StorageDaemonServiceMock::InvokeSendRequest));
|
||||
|
||||
ASSERT_TRUE(proxy_ != nullptr);
|
||||
int32_t ret = proxy_->CompleteAddUser(USER_ID1);
|
||||
ASSERT_TRUE(ret == E_OK);
|
||||
ASSERT_TRUE(mock_ != nullptr);
|
||||
ASSERT_TRUE(static_cast<int32_t>(StorageDaemonInterfaceCode::COMPLETE_ADD_USER) == mock_->code_);
|
||||
|
||||
GTEST_LOG_(INFO) << "StorageDaemonProxyTest_CompleteAddUser_001 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: StorageDaemonProxyTest_Mount_001
|
||||
* @tc.desc: Verify the Mount function.
|
||||
|
@ -79,6 +79,11 @@ public:
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
virtual int32_t CompleteAddUser(int32_t userId) override
|
||||
{
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
virtual int32_t MountDfsDocs(int32_t userId, const std::string &relativePath,
|
||||
const std::string &networkId, const std::string &deviceId) override
|
||||
{
|
||||
|
@ -34,6 +34,7 @@ public:
|
||||
|
||||
MOCK_METHOD1(StartUser, int32_t(int32_t));
|
||||
MOCK_METHOD1(StopUser, int32_t(int32_t));
|
||||
MOCK_METHOD1(CompleteAddUser, int32_t(int32_t));
|
||||
MOCK_METHOD2(PrepareUserDirs, int32_t(int32_t, uint32_t));
|
||||
MOCK_METHOD2(DestroyUserDirs, int32_t(int32_t, uint32_t));
|
||||
|
||||
|
@ -35,6 +35,7 @@ public:
|
||||
int32_t RemoveUser(int32_t userId, uint32_t flags) override;
|
||||
int32_t PrepareStartUser(int32_t userId) override;
|
||||
int32_t StopUser(int32_t userId) override;
|
||||
int32_t CompleteAddUser(int32_t userId) override;
|
||||
|
||||
int32_t GetFreeSizeOfVolume(std::string volumeUuid, int64_t &freeSize) override;
|
||||
int32_t GetTotalSizeOfVolume(std::string volumeUuid, int64_t &totalSize) override;
|
||||
|
@ -36,6 +36,7 @@ private:
|
||||
int32_t HandleRemoveUser(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandlePrepareStartUser(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleStopUser(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleCompleteAddUser(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleGetTotal(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleGetFree(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleGetBundleStatus(MessageParcel &data, MessageParcel &reply);
|
||||
|
@ -33,6 +33,7 @@ public:
|
||||
int32_t RemoveUser(int32_t userId, uint32_t flags);
|
||||
int32_t PrepareStartUser(int32_t userId);
|
||||
int32_t StopUser(int32_t userId);
|
||||
int32_t CompleteAddUser(int32_t userId);
|
||||
|
||||
int32_t Mount(std::string volumeId, int32_t flag);
|
||||
int32_t Unmount(std::string volumeId);
|
||||
|
@ -29,6 +29,7 @@ public:
|
||||
int32_t RemoveUser(int32_t userId, uint32_t flags);
|
||||
int32_t PrepareStartUser(int32_t userId);
|
||||
int32_t StopUser(int32_t userId);
|
||||
int32_t CompleteAddUser(int32_t userId);
|
||||
|
||||
private:
|
||||
int32_t CheckUserIdRange(int32_t userId);
|
||||
|
@ -122,6 +122,29 @@ int32_t StorageManagerProxy::StopUser(int32_t userId)
|
||||
return reply.ReadUint32();
|
||||
}
|
||||
|
||||
int32_t StorageManagerProxy::CompleteAddUser(int32_t userId)
|
||||
{
|
||||
LOGI("StorageManagerProxy::CompleteAddUser, userId:%{public}d", userId);
|
||||
HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
|
||||
LOGE("StorageManagerProxy::CompleteAddUser, WriteInterfaceToken failed");
|
||||
return E_WRITE_DESCRIPTOR_ERR;
|
||||
}
|
||||
if (!data.WriteInt32(userId)) {
|
||||
LOGE("StorageManagerProxy::CompleteAddUser, WriteInt32 failed");
|
||||
return E_WRITE_PARCEL_ERR;
|
||||
}
|
||||
int32_t err = SendRequest(
|
||||
static_cast<int32_t>(StorageManagerInterfaceCode::COMPLETE_ADD_USER), data, reply, option);
|
||||
if (err != E_OK) {
|
||||
return err;
|
||||
}
|
||||
return reply.ReadUint32();
|
||||
}
|
||||
|
||||
int32_t StorageManagerProxy::GenerateUserKeys(uint32_t userId, uint32_t flags)
|
||||
{
|
||||
LOGI("user ID: %{public}u, flags: %{public}u", userId, flags);
|
||||
|
@ -109,6 +109,14 @@ int32_t StorageManager::StopUser(int32_t userId)
|
||||
return err;
|
||||
}
|
||||
|
||||
int32_t StorageManager::CompleteAddUser(int32_t userId)
|
||||
{
|
||||
LOGI("StorageManger::CompleteAddUser start, userId: %{public}d", userId);
|
||||
std::shared_ptr<MultiUserManagerService> userManager = DelayedSingleton<MultiUserManagerService>::GetInstance();
|
||||
int32_t err = userManager->CompleteAddUser(userId);
|
||||
return err;
|
||||
}
|
||||
|
||||
int32_t StorageManager::GetFreeSizeOfVolume(std::string volumeUuid, int64_t &freeSize)
|
||||
{
|
||||
#ifdef STORAGE_STATISTICS_MANAGER
|
||||
|
@ -195,6 +195,8 @@ int32_t StorageManagerStub::OnRemoteRequest(uint32_t code,
|
||||
return HandlePrepareStartUser(data, reply);
|
||||
case static_cast<uint32_t>(StorageManagerInterfaceCode::STOP_USER):
|
||||
return HandleStopUser(data, reply);
|
||||
case static_cast<uint32_t>(StorageManagerInterfaceCode::COMPLETE_ADD_USER):
|
||||
return HandleCompleteAddUser(data, reply);
|
||||
case static_cast<uint32_t>(StorageManagerInterfaceCode::GET_TOTAL):
|
||||
return HandleGetTotal(data, reply);
|
||||
case static_cast<uint32_t>(StorageManagerInterfaceCode::GET_FREE):
|
||||
@ -349,6 +351,21 @@ int32_t StorageManagerStub::HandleStopUser(MessageParcel &data, MessageParcel &r
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t StorageManagerStub::HandleCompleteAddUser(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
if (!CheckClientPermission(PERMISSION_STORAGE_MANAGER)) {
|
||||
return E_PERMISSION_DENIED;
|
||||
}
|
||||
int32_t userId = data.ReadInt32();
|
||||
LOGI("StorageManagerStub::HandleCompleteAddUser, userId:%{public}d", userId);
|
||||
int err = CompleteAddUser(userId);
|
||||
if (!reply.WriteUint32(err)) {
|
||||
LOGE("StorageManagerStub::HandleCompleteAddUser call CompleteAddUser failed");
|
||||
return E_WRITE_REPLY_ERR;
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t StorageManagerStub::HandleGetTotal(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
if (!CheckClientPermission(PERMISSION_STORAGE_MANAGER)) {
|
||||
|
@ -409,6 +409,30 @@ HWTEST_F(StorageManagerProxyTest, Storage_manager_proxy_StopUser_0003, testing::
|
||||
GTEST_LOG_(INFO) << "StorageManagerProxyTest-end Storage_manager_proxy_StopUser_0003";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: SUB_STORAGE_Storage_manager_proxy_CompleteAddUser_0001
|
||||
* @tc.name: Storage_manager_proxy_CompleteAddUser_0001
|
||||
* @tc.desc: Test function of CompleteAddUser interface.
|
||||
* @tc.size: MEDIUM
|
||||
* @tc.type: FUNC
|
||||
* @tc.level Level 1
|
||||
* @tc.require: AR000GK4HB
|
||||
*/
|
||||
HWTEST_F(StorageManagerProxyTest, Storage_manager_proxy_CompleteAddUser_0001, testing::ext::TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "StorageManagerProxyTest-begin Storage_manager_proxy_CompleteAddUser_0001";
|
||||
int32_t userId = 109;
|
||||
auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
ASSERT_TRUE(samgr != nullptr) << "Storage_manager_proxy_CompleteAddUser_0001 fail to get GetSystemAbilityManager";
|
||||
auto remote = samgr->GetSystemAbility(STORAGE_MANAGER_MANAGER_ID);
|
||||
ASSERT_TRUE(remote != nullptr) << "GetSystemAbility failed";
|
||||
auto proxy = iface_cast<IStorageManager>(remote);
|
||||
ASSERT_TRUE(proxy != nullptr) << "fail to get proxy";
|
||||
int32_t result = proxy->CompleteAddUser(userId);
|
||||
EXPECT_NE(result, E_OK);
|
||||
GTEST_LOG_(INFO) << "StorageManagerProxyTest-end Storage_manager_proxy_CompleteAddUser_0001";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: SUB_STORAGE_Storage_manager_proxy_GetFreeSizeOfVolume_0000
|
||||
* @tc.name: Storage_manager_proxy_GetFreeSizeOfVolume_0000
|
||||
|
@ -55,6 +55,11 @@ public:
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
virtual int32_t CompleteAddUser(int32_t userId) override
|
||||
{
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
virtual int32_t GetFreeSizeOfVolume(std::string volumeUuid, int64_t &freeSize) override
|
||||
{
|
||||
return E_OK;
|
||||
|
@ -27,6 +27,7 @@ public:
|
||||
MOCK_METHOD2(RemoveUser, int32_t(int32_t, uint32_t));
|
||||
MOCK_METHOD1(PrepareStartUser, int32_t(int32_t));
|
||||
MOCK_METHOD1(StopUser, int32_t(int32_t));
|
||||
MOCK_METHOD1(CompleteAddUser, int32_t(int32_t));
|
||||
|
||||
MOCK_METHOD2(GetFreeSizeOfVolume, int32_t(std::string, int64_t &));
|
||||
MOCK_METHOD2(GetTotalSizeOfVolume, int32_t(std::string, int64_t &));
|
||||
|
@ -133,6 +133,21 @@ int32_t StorageDaemonCommunication::StopUser(int32_t userId)
|
||||
return storageDaemon_->StopUser(userId);
|
||||
}
|
||||
|
||||
int32_t StorageDaemonCommunication::CompleteAddUser(int32_t userId)
|
||||
{
|
||||
LOGI("StorageDaemonCommunication::CompleteAddUser start");
|
||||
int32_t err = Connect();
|
||||
if (err != E_OK) {
|
||||
LOGE("StorageDaemonCommunication::CompleteAddUser connect failed");
|
||||
return err;
|
||||
}
|
||||
if (storageDaemon_ == nullptr) {
|
||||
LOGE("StorageDaemonCommunication::CompleteAddUser service nullptr");
|
||||
return E_SERVICE_IS_NULLPTR;
|
||||
}
|
||||
return storageDaemon_->CompleteAddUser(userId);
|
||||
}
|
||||
|
||||
int32_t StorageDaemonCommunication::Mount(std::string volumeId, int32_t flag)
|
||||
{
|
||||
LOGI("StorageDaemonCommunication::mount start");
|
||||
|
@ -96,5 +96,19 @@ int32_t MultiUserManagerService::StopUser(int32_t userId)
|
||||
err = sdCommunication->StopUser(userId);
|
||||
return err;
|
||||
}
|
||||
|
||||
int32_t MultiUserManagerService::CompleteAddUser(int32_t userId)
|
||||
{
|
||||
LOGI("MultiUserManagerService::CompleteAddUser, userId:%{public}d", userId);
|
||||
int32_t err = CheckUserIdRange(userId);
|
||||
if (err != E_OK) {
|
||||
LOGE("MultiUserManagerService::CompleteAddUser userId %{public}d out of range", userId);
|
||||
return err;
|
||||
}
|
||||
std::shared_ptr<StorageDaemonCommunication> sdCommunication = nullptr;
|
||||
sdCommunication = DelayedSingleton<StorageDaemonCommunication>::GetInstance();
|
||||
err = sdCommunication->CompleteAddUser(userId);
|
||||
return err;
|
||||
}
|
||||
} // StorageManager
|
||||
} // OHOS
|
||||
|
@ -52,6 +52,11 @@ public:
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t CompleteAddUser(int32_t userId) override
|
||||
{
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t GetFreeSizeOfVolume(std::string volumeUuid, int64_t &freeSize) override
|
||||
{
|
||||
return E_OK;
|
||||
|
Loading…
Reference in New Issue
Block a user