add CompleteAddUser

Signed-off-by: hwwuhaobo <wuhaobo2@huawei.com>
This commit is contained in:
hwwuhaobo 2024-08-21 15:58:10 +08:00
parent 35cc36bcde
commit 35b0a1bd05
27 changed files with 211 additions and 1 deletions

View File

@ -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;

View File

@ -39,6 +39,7 @@ namespace StorageManager {
REMOVE_USER,
PREPARE_START_USER,
STOP_USER,
COMPLETE_ADD_USER,
GET_TOTAL,
GET_FREE,
GET_BUNDLE_STATUS,

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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,

View File

@ -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;

View File

@ -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);

View File

@ -256,7 +256,9 @@ int32_t StorageDaemon::RestoreOneUserKey(int32_t userId, KeyType type)
PrepareUeceDir(userId);
}
if (userId < StorageService::START_APP_CLONE_USER_ID || userId > StorageService::MAX_APP_CLONE_USER_ID) {
(void)remove(elNeedRestorePath.c_str());
if (type != EL1_KEY) {
(void)remove(elNeedRestorePath.c_str());
}
}
if (type == EL4_KEY) {
UserManager::GetInstance()->CreateBundleDataDir(userId);
@ -356,6 +358,21 @@ int32_t StorageDaemon::StopUser(int32_t userId)
return ret;
}
int32_t StorageDaemon::CompleteAddUser(int32_t userId)
{
#ifdef USER_CRYPTO_MIGRATE_KEY
std::string elNeedRestorePath = GetNeedRestoreFilePathByType(userId, EL1_KEY);
if (elNeedRestorePath.empty() || !std::filesystem::exists(elNeedRestorePath)) {
return E_OK;
}
(void)remove(elNeedRestorePath.c_str());
LOGE("CompleteAddUser remove el1 needRestore");
StorageService::StorageRadar::GetInstance().RecordFuctionResult(
"CompleteAddUser", BizScene::USER_MOUNT_MANAGER, BizStage::BIZ_STAGE_STOP_USER, "EL1", E_OK);
#endif
return E_OK;
}
int32_t StorageDaemon::InitGlobalKey(void)
{
#ifdef USER_CRYPTO_MANAGER

View File

@ -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;

View File

@ -121,6 +121,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):
@ -185,6 +186,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):
@ -377,6 +380,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();

View File

@ -162,6 +162,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.

View File

@ -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
{

View File

@ -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));

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -109,6 +109,17 @@ 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);
if (err != E_USERID_RANGE) {
ResetUserEventRecord(userId);
}
return err;
}
int32_t StorageManager::GetFreeSizeOfVolume(std::string volumeUuid, int64_t &freeSize)
{
#ifdef STORAGE_STATISTICS_MANAGER

View File

@ -201,6 +201,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):
@ -357,6 +359,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)) {

View File

@ -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

View File

@ -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;

View File

@ -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 &));

View File

@ -129,6 +129,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");

View File

@ -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

View File

@ -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;