From a623a48ca8f8fd4ecd3d45596e03049afdc1191f Mon Sep 17 00:00:00 2001 From: gsl_1234 Date: Sat, 13 Jan 2024 16:03:56 +0800 Subject: [PATCH] create bundle dir in grade scenario Signed-off-by: gsl_1234 --- services/storage_daemon/BUILD.gn | 1 + services/storage_daemon/include/user/user_manager.h | 1 + services/storage_daemon/ipc/src/storage_daemon.cpp | 8 ++++++++ services/storage_daemon/ipc/test/BUILD.gn | 2 ++ services/storage_daemon/user/src/user_manager.cpp | 9 +++++++++ services/storage_daemon/user/test/BUILD.gn | 1 + test/fuzztest/storagedaemon_fuzzer/BUILD.gn | 1 + .../storagedaemoncreatesharefile_fuzzer/BUILD.gn | 1 + .../storagedaemondeletesharefile_fuzzer/BUILD.gn | 1 + 9 files changed, 25 insertions(+) diff --git a/services/storage_daemon/BUILD.gn b/services/storage_daemon/BUILD.gn index 85c8f272..d8865408 100644 --- a/services/storage_daemon/BUILD.gn +++ b/services/storage_daemon/BUILD.gn @@ -114,6 +114,7 @@ ohos_executable("storage_daemon") { "ability_base:want", "ability_base:zuri", "app_file_service:fileshare_native", + "bundle_framework:appexecfwk_core", "c_utils:utils", "hilog:libhilog", "init:libbegetutil", diff --git a/services/storage_daemon/include/user/user_manager.h b/services/storage_daemon/include/user/user_manager.h index 773aafff..eab3d428 100644 --- a/services/storage_daemon/include/user/user_manager.h +++ b/services/storage_daemon/include/user/user_manager.h @@ -35,6 +35,7 @@ public: int32_t DestroyUserDirs(int32_t userId, uint32_t flags); int32_t StartUser(int32_t userId); int32_t StopUser(int32_t userId); + void CreateBundleDataDir(uint32_t userId); private: int32_t PrepareDirsFromIdAndLevel(int32_t userId, const std::string &level); diff --git a/services/storage_daemon/ipc/src/storage_daemon.cpp b/services/storage_daemon/ipc/src/storage_daemon.cpp index fbaabcf3..12c26231 100644 --- a/services/storage_daemon/ipc/src/storage_daemon.cpp +++ b/services/storage_daemon/ipc/src/storage_daemon.cpp @@ -194,6 +194,9 @@ int32_t StorageDaemon::RestoreUserOneKey(int32_t userId, KeyType type) return ret; } (void)remove(elNeedRestorePath.c_str()); + if (type == EL4_KEY) { + UserManager::GetInstance()->CreateBundleDataDir(userId); + } LOGI("restore User %{public}u el%{public}u success", userId, type); } return E_OK; @@ -460,6 +463,7 @@ int32_t StorageDaemon::ActiveUserKey(uint32_t userId, { #ifdef USER_CRYPTO_MANAGER LOGI("userId %{public}u, tok empty %{public}d sec empty %{public}d", userId, token.empty(), secret.empty()); + bool updateFlag = false; int ret = KeyManager::GetInstance()->ActiveCeSceSeceUserKey(userId, EL2_KEY, token, secret); if (ret != E_OK) { #ifdef USER_CRYPTO_MIGRATE_KEY @@ -467,6 +471,7 @@ int32_t StorageDaemon::ActiveUserKey(uint32_t userId, userId, token.empty(), secret.empty()); std::string el2NeedRestorePath = GetNeedRestoreFilePath(userId, USER_EL2_DIR); if (std::filesystem::exists(el2NeedRestorePath) && (!token.empty() || !secret.empty())) { + updateFlag = true; ret = PrepareUserDirsAndUpdateUserAuth(userId, EL2_KEY, token, secret); } #endif @@ -489,6 +494,9 @@ int32_t StorageDaemon::ActiveUserKey(uint32_t userId, return ret; } + if (updateFlag) { + UserManager::GetInstance()->CreateBundleDataDir(userId); + } return ret; #else return E_OK; diff --git a/services/storage_daemon/ipc/test/BUILD.gn b/services/storage_daemon/ipc/test/BUILD.gn index c2bc48ff..4e2c0b72 100644 --- a/services/storage_daemon/ipc/test/BUILD.gn +++ b/services/storage_daemon/ipc/test/BUILD.gn @@ -72,6 +72,7 @@ ohos_unittest("storage_daemon_test") { "ability_base:zuri", "access_token:libaccesstoken_sdk", "app_file_service:fileshare_native", + "bundle_framework:appexecfwk_core", "c_utils:utils", "dfs_service:cloud_daemon_kit_inner", "hilog:libhilog", @@ -151,6 +152,7 @@ ohos_unittest("storage_daemon_stub_test") { external_deps = [ "access_token:libaccesstoken_sdk", + "bundle_framework:appexecfwk_core", "c_utils:utils", "hilog:libhilog", "huks:libhukssdk", diff --git a/services/storage_daemon/user/src/user_manager.cpp b/services/storage_daemon/user/src/user_manager.cpp index 82d513a6..169f568a 100644 --- a/services/storage_daemon/user/src/user_manager.cpp +++ b/services/storage_daemon/user/src/user_manager.cpp @@ -15,6 +15,7 @@ #include "user/user_manager.h" #include +#include "bundle_mgr_client.h" #ifdef USER_CRYPTO_MANAGER #include "crypto/key_manager.h" #endif @@ -367,5 +368,13 @@ int32_t UserManager::CheckUserIdRange(int32_t userId) } return E_OK; } + +void UserManager::CreateBundleDataDir(uint32_t userId) +{ + OHOS::AppExecFwk::BundleMgrClient client; + LOGI("CreateBundleDataDir start: userId %{public}u", userId); + auto ret = client.CreateBundleDataDir(userId); + LOGI("CreateBundleDataDir end: userId %{public}u, ret %{public}d", userId, ret); +} } // namespace StorageDaemon } // namespace OHOS diff --git a/services/storage_daemon/user/test/BUILD.gn b/services/storage_daemon/user/test/BUILD.gn index dbc0c229..ac9d0da0 100644 --- a/services/storage_daemon/user/test/BUILD.gn +++ b/services/storage_daemon/user/test/BUILD.gn @@ -50,6 +50,7 @@ ohos_unittest("user_manager_test") { ] external_deps = [ + "bundle_framework:appexecfwk_core", "c_utils:utils", "hilog:libhilog", "huks:libhukssdk", diff --git a/test/fuzztest/storagedaemon_fuzzer/BUILD.gn b/test/fuzztest/storagedaemon_fuzzer/BUILD.gn index 9818c145..8d146f30 100644 --- a/test/fuzztest/storagedaemon_fuzzer/BUILD.gn +++ b/test/fuzztest/storagedaemon_fuzzer/BUILD.gn @@ -51,6 +51,7 @@ ohos_fuzztest("StorageDaemonFuzzTest") { external_deps = [ "ability_runtime:abilitykit_native", "app_file_service:fileshare_native", + "bundle_framework:appexecfwk_core", "c_utils:utils", "hilog:libhilog", "init:libbegetutil", diff --git a/test/fuzztest/storagedaemoncreatesharefile_fuzzer/BUILD.gn b/test/fuzztest/storagedaemoncreatesharefile_fuzzer/BUILD.gn index 0a958fea..a8fbabb8 100644 --- a/test/fuzztest/storagedaemoncreatesharefile_fuzzer/BUILD.gn +++ b/test/fuzztest/storagedaemoncreatesharefile_fuzzer/BUILD.gn @@ -53,6 +53,7 @@ ohos_fuzztest("StorageDaemonCreateShareFileFuzzTest") { external_deps = [ "ability_runtime:abilitykit_native", "app_file_service:fileshare_native", + "bundle_framework:appexecfwk_core", "c_utils:utils", "hilog:libhilog", "init:libbegetutil", diff --git a/test/fuzztest/storagedaemondeletesharefile_fuzzer/BUILD.gn b/test/fuzztest/storagedaemondeletesharefile_fuzzer/BUILD.gn index 9e7e41a5..fb7d3b60 100644 --- a/test/fuzztest/storagedaemondeletesharefile_fuzzer/BUILD.gn +++ b/test/fuzztest/storagedaemondeletesharefile_fuzzer/BUILD.gn @@ -53,6 +53,7 @@ ohos_fuzztest("StorageDaemonDeleteShareFileFuzzTest") { external_deps = [ "ability_runtime:abilitykit_native", "app_file_service:fileshare_native", + "bundle_framework:appexecfwk_core", "c_utils:utils", "hilog:libhilog", "init:libbegetutil",