diff --git a/interfaces/innerkits/storage_manager/native/istorage_manager.h b/interfaces/innerkits/storage_manager/native/istorage_manager.h index 950083bd..3e8d9437 100644 --- a/interfaces/innerkits/storage_manager/native/istorage_manager.h +++ b/interfaces/innerkits/storage_manager/native/istorage_manager.h @@ -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; diff --git a/interfaces/innerkits/storage_manager/native/storage_manager_ipc_interface_code.h b/interfaces/innerkits/storage_manager/native/storage_manager_ipc_interface_code.h index 59e58629..969a19ba 100644 --- a/interfaces/innerkits/storage_manager/native/storage_manager_ipc_interface_code.h +++ b/interfaces/innerkits/storage_manager/native/storage_manager_ipc_interface_code.h @@ -39,6 +39,7 @@ namespace StorageManager { REMOVE_USER, PREPARE_START_USER, STOP_USER, + COMPLETE_ADD_USER, GET_TOTAL, GET_FREE, GET_BUNDLE_STATUS, diff --git a/interfaces/innerkits/storage_manager/native/storage_manager_proxy.h b/interfaces/innerkits/storage_manager/native/storage_manager_proxy.h index e2419f31..dbe3399a 100644 --- a/interfaces/innerkits/storage_manager/native/storage_manager_proxy.h +++ b/interfaces/innerkits/storage_manager/native/storage_manager_proxy.h @@ -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; diff --git a/services/storage_daemon/include/ipc/istorage_daemon.h b/services/storage_daemon/include/ipc/istorage_daemon.h index 0458b08f..cb7f28d0 100644 --- a/services/storage_daemon/include/ipc/istorage_daemon.h +++ b/services/storage_daemon/include/ipc/istorage_daemon.h @@ -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; diff --git a/services/storage_daemon/include/ipc/storage_daemon.h b/services/storage_daemon/include/ipc/storage_daemon.h index 493bb711..34cfbd45 100644 --- a/services/storage_daemon/include/ipc/storage_daemon.h +++ b/services/storage_daemon/include/ipc/storage_daemon.h @@ -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; diff --git a/services/storage_daemon/include/ipc/storage_daemon_ipc_interface_code.h b/services/storage_daemon/include/ipc/storage_daemon_ipc_interface_code.h index d8fa4c88..530d0b99 100644 --- a/services/storage_daemon/include/ipc/storage_daemon_ipc_interface_code.h +++ b/services/storage_daemon/include/ipc/storage_daemon_ipc_interface_code.h @@ -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, diff --git a/services/storage_daemon/include/ipc/storage_daemon_proxy.h b/services/storage_daemon/include/ipc/storage_daemon_proxy.h index 35ac1609..9f92f94c 100644 --- a/services/storage_daemon/include/ipc/storage_daemon_proxy.h +++ b/services/storage_daemon/include/ipc/storage_daemon_proxy.h @@ -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; diff --git a/services/storage_daemon/include/ipc/storage_daemon_stub.h b/services/storage_daemon/include/ipc/storage_daemon_stub.h index d02d9b8c..b9427492 100644 --- a/services/storage_daemon/include/ipc/storage_daemon_stub.h +++ b/services/storage_daemon/include/ipc/storage_daemon_stub.h @@ -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); diff --git a/services/storage_daemon/ipc/src/storage_daemon.cpp b/services/storage_daemon/ipc/src/storage_daemon.cpp index 09a35e5b..af4e1a38 100644 --- a/services/storage_daemon/ipc/src/storage_daemon.cpp +++ b/services/storage_daemon/ipc/src/storage_daemon.cpp @@ -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 diff --git a/services/storage_daemon/ipc/src/storage_daemon_proxy.cpp b/services/storage_daemon/ipc/src/storage_daemon_proxy.cpp index 4dbaeaed..94879c49 100644 --- a/services/storage_daemon/ipc/src/storage_daemon_proxy.cpp +++ b/services/storage_daemon/ipc/src/storage_daemon_proxy.cpp @@ -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(StorageDaemonInterfaceCode::COMPLETE_ADD_USER), data, reply, option); + if (err != E_OK) { + return err; + } + + return reply.ReadUint32(); +} + int32_t StorageDaemonProxy::InitGlobalKey(void) { MessageParcel data; diff --git a/services/storage_daemon/ipc/src/storage_daemon_stub.cpp b/services/storage_daemon/ipc/src/storage_daemon_stub.cpp index 06404db9..26c056d1 100644 --- a/services/storage_daemon/ipc/src/storage_daemon_stub.cpp +++ b/services/storage_daemon/ipc/src/storage_daemon_stub.cpp @@ -121,6 +121,7 @@ int32_t StorageDaemonStub::OnRemoteRequest(uint32_t code, case static_cast(StorageDaemonInterfaceCode::DESTROY_USER_DIRS): case static_cast(StorageDaemonInterfaceCode::START_USER): case static_cast(StorageDaemonInterfaceCode::STOP_USER): + case static_cast(StorageDaemonInterfaceCode::COMPLETE_ADD_USER): case static_cast(StorageDaemonInterfaceCode::INIT_GLOBAL_KEY): case static_cast(StorageDaemonInterfaceCode::INIT_GLOBAL_USER_KEYS): case static_cast(StorageDaemonInterfaceCode::CREATE_USER_KEYS): @@ -185,6 +186,8 @@ int32_t StorageDaemonStub::OnRemoteRequestForUser(uint32_t code, MessageParcel & return HandleStartUser(data, reply); case static_cast(StorageDaemonInterfaceCode::STOP_USER): return HandleStopUser(data, reply); + case static_cast(StorageDaemonInterfaceCode::COMPLETE_ADD_USER): + return HandleCompleteAddUser(data, reply); case static_cast(StorageDaemonInterfaceCode::INIT_GLOBAL_KEY): return HandleInitGlobalKey(data, reply); case static_cast(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(); diff --git a/services/storage_daemon/ipc/test/storage_daemon_proxy_test.cpp b/services/storage_daemon/ipc/test/storage_daemon_proxy_test.cpp index cf44536f..b3d7ec98 100644 --- a/services/storage_daemon/ipc/test/storage_daemon_proxy_test.cpp +++ b/services/storage_daemon/ipc/test/storage_daemon_proxy_test.cpp @@ -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(StorageDaemonInterfaceCode::COMPLETE_ADD_USER) == mock_->code_); + + GTEST_LOG_(INFO) << "StorageDaemonProxyTest_CompleteAddUser_001 end"; +} + /** * @tc.name: StorageDaemonProxyTest_Mount_001 * @tc.desc: Verify the Mount function. diff --git a/services/storage_daemon/ipc/test/storage_daemon_service_mock.h b/services/storage_daemon/ipc/test/storage_daemon_service_mock.h index 3f067d02..3956c50c 100644 --- a/services/storage_daemon/ipc/test/storage_daemon_service_mock.h +++ b/services/storage_daemon/ipc/test/storage_daemon_service_mock.h @@ -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 { diff --git a/services/storage_daemon/ipc/test/storage_daemon_stub_mock.h b/services/storage_daemon/ipc/test/storage_daemon_stub_mock.h index 21c03b9c..30513392 100644 --- a/services/storage_daemon/ipc/test/storage_daemon_stub_mock.h +++ b/services/storage_daemon/ipc/test/storage_daemon_stub_mock.h @@ -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)); diff --git a/services/storage_manager/include/ipc/storage_manager.h b/services/storage_manager/include/ipc/storage_manager.h index ddf7a427..a703f225 100644 --- a/services/storage_manager/include/ipc/storage_manager.h +++ b/services/storage_manager/include/ipc/storage_manager.h @@ -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; diff --git a/services/storage_manager/include/ipc/storage_manager_stub.h b/services/storage_manager/include/ipc/storage_manager_stub.h index 26b5c34b..d579f916 100644 --- a/services/storage_manager/include/ipc/storage_manager_stub.h +++ b/services/storage_manager/include/ipc/storage_manager_stub.h @@ -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); diff --git a/services/storage_manager/include/storage_daemon_communication/storage_daemon_communication.h b/services/storage_manager/include/storage_daemon_communication/storage_daemon_communication.h index b118bd8e..fd50fbea 100644 --- a/services/storage_manager/include/storage_daemon_communication/storage_daemon_communication.h +++ b/services/storage_manager/include/storage_daemon_communication/storage_daemon_communication.h @@ -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); diff --git a/services/storage_manager/include/user/multi_user_manager_service.h b/services/storage_manager/include/user/multi_user_manager_service.h index 065b89f6..88348b40 100644 --- a/services/storage_manager/include/user/multi_user_manager_service.h +++ b/services/storage_manager/include/user/multi_user_manager_service.h @@ -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); diff --git a/services/storage_manager/innerkits_impl/src/storage_manager_proxy.cpp b/services/storage_manager/innerkits_impl/src/storage_manager_proxy.cpp index 5d8c8e0d..426c139e 100644 --- a/services/storage_manager/innerkits_impl/src/storage_manager_proxy.cpp +++ b/services/storage_manager/innerkits_impl/src/storage_manager_proxy.cpp @@ -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(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); diff --git a/services/storage_manager/ipc/src/storage_manager.cpp b/services/storage_manager/ipc/src/storage_manager.cpp index 3338a4d8..087cb412 100644 --- a/services/storage_manager/ipc/src/storage_manager.cpp +++ b/services/storage_manager/ipc/src/storage_manager.cpp @@ -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 userManager = DelayedSingleton::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 diff --git a/services/storage_manager/ipc/src/storage_manager_stub.cpp b/services/storage_manager/ipc/src/storage_manager_stub.cpp index 34c19403..2d05be75 100644 --- a/services/storage_manager/ipc/src/storage_manager_stub.cpp +++ b/services/storage_manager/ipc/src/storage_manager_stub.cpp @@ -201,6 +201,8 @@ int32_t StorageManagerStub::OnRemoteRequest(uint32_t code, return HandlePrepareStartUser(data, reply); case static_cast(StorageManagerInterfaceCode::STOP_USER): return HandleStopUser(data, reply); + case static_cast(StorageManagerInterfaceCode::COMPLETE_ADD_USER): + return HandleCompleteAddUser(data, reply); case static_cast(StorageManagerInterfaceCode::GET_TOTAL): return HandleGetTotal(data, reply); case static_cast(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)) { diff --git a/services/storage_manager/ipc/test/storage_manager_proxy_test.cpp b/services/storage_manager/ipc/test/storage_manager_proxy_test.cpp index b503a20f..da815853 100644 --- a/services/storage_manager/ipc/test/storage_manager_proxy_test.cpp +++ b/services/storage_manager/ipc/test/storage_manager_proxy_test.cpp @@ -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(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 diff --git a/services/storage_manager/ipc/test/storage_manager_service_mock.h b/services/storage_manager/ipc/test/storage_manager_service_mock.h index 81eeb263..3dc10e83 100644 --- a/services/storage_manager/ipc/test/storage_manager_service_mock.h +++ b/services/storage_manager/ipc/test/storage_manager_service_mock.h @@ -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; diff --git a/services/storage_manager/ipc/test/storage_manager_stub_mock.h b/services/storage_manager/ipc/test/storage_manager_stub_mock.h index 561131ff..aed07852 100644 --- a/services/storage_manager/ipc/test/storage_manager_stub_mock.h +++ b/services/storage_manager/ipc/test/storage_manager_stub_mock.h @@ -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 &)); diff --git a/services/storage_manager/storage_daemon_communication/src/storage_daemon_communication.cpp b/services/storage_manager/storage_daemon_communication/src/storage_daemon_communication.cpp index 3eadf036..09049982 100644 --- a/services/storage_manager/storage_daemon_communication/src/storage_daemon_communication.cpp +++ b/services/storage_manager/storage_daemon_communication/src/storage_daemon_communication.cpp @@ -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"); diff --git a/services/storage_manager/user/src/multi_user_manager_service.cpp b/services/storage_manager/user/src/multi_user_manager_service.cpp index 6dda95b8..98458573 100644 --- a/services/storage_manager/user/src/multi_user_manager_service.cpp +++ b/services/storage_manager/user/src/multi_user_manager_service.cpp @@ -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 sdCommunication = nullptr; + sdCommunication = DelayedSingleton::GetInstance(); + err = sdCommunication->CompleteAddUser(userId); + return err; +} } // StorageManager } // OHOS diff --git a/test/fuzztest/storagemanagerproxy_fuzzer/storagemanagerproxymock.h b/test/fuzztest/storagemanagerproxy_fuzzer/storagemanagerproxymock.h index 0ccc3e92..6350f05d 100644 --- a/test/fuzztest/storagemanagerproxy_fuzzer/storagemanagerproxymock.h +++ b/test/fuzztest/storagemanagerproxy_fuzzer/storagemanagerproxymock.h @@ -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;