Create utility method for converting sdk_sandbox_uid to app_uid

Method is needed for further use in statsd mapping process.

Bug: 217695033
Test: atest installd_service_test
Change-Id: I508a58da5f8d2e32264002db515425134d18aece
This commit is contained in:
Hanna Nizhnikava 2022-02-22 14:30:15 +00:00 committed by Elliott Hughes
parent 242ed1bb20
commit fb78816593
3 changed files with 29 additions and 0 deletions

View file

@ -31,6 +31,7 @@ extern appid_t multiuser_get_app_id(uid_t uid);
extern uid_t multiuser_get_uid(userid_t user_id, appid_t app_id);
extern uid_t multiuser_get_sdk_sandbox_uid(userid_t user_id, appid_t app_id);
extern uid_t multiuser_convert_sdk_sandbox_to_app_uid(uid_t uid);
extern gid_t multiuser_get_cache_gid(userid_t user_id, appid_t app_id);
extern gid_t multiuser_get_ext_gid(userid_t user_id, appid_t app_id);

View file

@ -38,6 +38,16 @@ uid_t multiuser_get_sdk_sandbox_uid(userid_t user_id, appid_t app_id) {
}
}
uid_t multiuser_convert_sdk_sandbox_to_app_uid(uid_t uid) {
appid_t app_id = multiuser_get_app_id(uid);
int sdk_sandbox_offset = AID_SDK_SANDBOX_PROCESS_START - AID_APP_START;
if (app_id >= AID_SDK_SANDBOX_PROCESS_START && app_id <= AID_SDK_SANDBOX_PROCESS_END) {
return uid - sdk_sandbox_offset;
} else {
return -1;
}
}
gid_t multiuser_get_cache_gid(userid_t user_id, appid_t app_id) {
if (app_id >= AID_APP_START && app_id <= AID_APP_END) {
return multiuser_get_uid(user_id, (app_id - AID_APP_START) + AID_CACHE_GID_START);

View file

@ -47,6 +47,24 @@ TEST(MultiuserTest, TestSdkSandboxUid) {
EXPECT_EQ(ERR_UID, multiuser_get_sdk_sandbox_uid(10, 50000));
}
TEST(MultiuserTest, TestSdkSandboxUidConvertation) {
EXPECT_EQ(ERR_UID, multiuser_convert_sdk_sandbox_to_app_uid(0));
EXPECT_EQ(ERR_UID, multiuser_convert_sdk_sandbox_to_app_uid(1000));
EXPECT_EQ(ERR_UID, multiuser_convert_sdk_sandbox_to_app_uid(10000));
EXPECT_EQ(10000U, multiuser_convert_sdk_sandbox_to_app_uid(20000));
EXPECT_EQ(15000U, multiuser_convert_sdk_sandbox_to_app_uid(25000));
EXPECT_EQ(19999U, multiuser_convert_sdk_sandbox_to_app_uid(29999));
EXPECT_EQ(ERR_UID, multiuser_convert_sdk_sandbox_to_app_uid(50000));
EXPECT_EQ(ERR_UID, multiuser_convert_sdk_sandbox_to_app_uid(1000000));
EXPECT_EQ(ERR_UID, multiuser_convert_sdk_sandbox_to_app_uid(1001000));
EXPECT_EQ(ERR_UID, multiuser_convert_sdk_sandbox_to_app_uid(1010000));
EXPECT_EQ(1010000U, multiuser_convert_sdk_sandbox_to_app_uid(1020000));
EXPECT_EQ(1015000U, multiuser_convert_sdk_sandbox_to_app_uid(1025000));
EXPECT_EQ(1019999U, multiuser_convert_sdk_sandbox_to_app_uid(1029999));
EXPECT_EQ(ERR_UID, multiuser_convert_sdk_sandbox_to_app_uid(1050000));
}
TEST(MultiuserTest, TestSplitUser) {
EXPECT_EQ(0U, multiuser_get_user_id(0));
EXPECT_EQ(0U, multiuser_get_user_id(1000));