From 8621e556f451efaae5e5ab024eb91f1a66cb722c Mon Sep 17 00:00:00 2001 From: Samiul Islam Date: Wed, 30 Mar 2022 16:26:45 +0100 Subject: Set correct project id for sdk data directories Sdk data directories should get same project id as the app data. Bug: 224763009 Test: atest SdkSandboxStorageHostTest (ag/17539087) Change-Id: I660a9e06a4bbc8facecb9e258fc0c34f3f5e71ac --- cmds/installd/InstalldNativeService.cpp | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/cmds/installd/InstalldNativeService.cpp b/cmds/installd/InstalldNativeService.cpp index c95ee4109d..d0a93c28a2 100644 --- a/cmds/installd/InstalldNativeService.cpp +++ b/cmds/installd/InstalldNativeService.cpp @@ -634,7 +634,8 @@ static void chown_app_profile_dir(const std::string &packageName, int32_t appId, static binder::Status createAppDataDirs(const std::string& path, int32_t uid, int32_t gid, int32_t* previousUid, int32_t cacheGid, - const std::string& seInfo, mode_t targetMode) { + const std::string& seInfo, mode_t targetMode, + long projectIdApp, long projectIdCache) { struct stat st{}; bool parent_dir_exists = (stat(path.c_str(), &st) == 0); @@ -658,11 +659,9 @@ static binder::Status createAppDataDirs(const std::string& path, int32_t uid, in } // Prepare only the parent app directory - long project_id_app = get_project_id(uid, PROJECT_ID_APP_START); - long project_id_cache_app = get_project_id(uid, PROJECT_ID_APP_CACHE_START); - if (prepare_app_dir(path, targetMode, uid, gid, project_id_app) || - prepare_app_cache_dir(path, "cache", 02771, uid, cacheGid, project_id_cache_app) || - prepare_app_cache_dir(path, "code_cache", 02771, uid, cacheGid, project_id_cache_app)) { + if (prepare_app_dir(path, targetMode, uid, gid, projectIdApp) || + prepare_app_cache_dir(path, "cache", 02771, uid, cacheGid, projectIdCache) || + prepare_app_cache_dir(path, "code_cache", 02771, uid, cacheGid, projectIdCache)) { return error("Failed to prepare " + path); } @@ -718,10 +717,14 @@ binder::Status InstalldNativeService::createAppDataLocked( cacheGid = uid; } + long projectIdApp = get_project_id(uid, PROJECT_ID_APP_START); + long projectIdCache = get_project_id(uid, PROJECT_ID_APP_CACHE_START); + if (flags & FLAG_STORAGE_CE) { auto path = create_data_user_ce_package_path(uuid_, userId, pkgname); - auto status = createAppDataDirs(path, uid, uid, &previousUid, cacheGid, seInfo, targetMode); + auto status = createAppDataDirs(path, uid, uid, &previousUid, cacheGid, seInfo, targetMode, + projectIdApp, projectIdCache); if (!status.isOk()) { return status; } @@ -746,7 +749,8 @@ binder::Status InstalldNativeService::createAppDataLocked( if (flags & FLAG_STORAGE_DE) { auto path = create_data_user_de_package_path(uuid_, userId, pkgname); - auto status = createAppDataDirs(path, uid, uid, &previousUid, cacheGid, seInfo, targetMode); + auto status = createAppDataDirs(path, uid, uid, &previousUid, cacheGid, seInfo, targetMode, + projectIdApp, projectIdCache); if (!status.isOk()) { return status; } @@ -946,8 +950,12 @@ binder::Status InstalldNativeService::reconcileSdkData(const std::optional