Better, consistent definition of AID_SHARED_GID.
AID_SHARED_GID is a GID shared by a specific app across all users on
the same device. Bring the UserHandle and multiuser.c implementations
into agreement, and copy/paste the unit tests that verify that both
behave identically.
This fixes a regression where multiuser_get_shared_gid() was applying
per-user isolation when it shouldn't have.
Test: adb shell /data/nativetest64/libcutils_test/libcutils_test64
Bug: 34151068, 64548938
Change-Id: I491dd79d23a214425a68865d1d0f8269916aad4c
diff --git a/libcutils/Android.bp b/libcutils/Android.bp
index d7413d1..9cba109 100644
--- a/libcutils/Android.bp
+++ b/libcutils/Android.bp
@@ -20,7 +20,7 @@
libcutils_nonwindows_sources = [
"android_get_control_file.cpp",
"fs.cpp",
- "multiuser.c",
+ "multiuser.cpp",
"socket_inaddr_any_server_unix.cpp",
"socket_local_client_unix.cpp",
"socket_local_server_unix.cpp",
diff --git a/libcutils/multiuser.c b/libcutils/multiuser.cpp
similarity index 90%
rename from libcutils/multiuser.c
rename to libcutils/multiuser.cpp
index 61403f4..0fd3d0c 100644
--- a/libcutils/multiuser.c
+++ b/libcutils/multiuser.cpp
@@ -53,9 +53,11 @@
}
}
-gid_t multiuser_get_shared_gid(userid_t user_id, appid_t app_id) {
+gid_t multiuser_get_shared_gid(userid_t, 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_SHARED_GID_START);
+ return (app_id - AID_APP_START) + AID_SHARED_GID_START;
+ } else if (app_id >= AID_ROOT && app_id <= AID_APP_START) {
+ return app_id;
} else {
return -1;
}
diff --git a/libcutils/tests/multiuser_test.cpp b/libcutils/tests/multiuser_test.cpp
index 2f9d854..4b0fd13 100644
--- a/libcutils/tests/multiuser_test.cpp
+++ b/libcutils/tests/multiuser_test.cpp
@@ -57,7 +57,10 @@
EXPECT_EQ(ERR_GID, multiuser_get_cache_gid(0, 1000));
EXPECT_EQ(20000U, multiuser_get_cache_gid(0, 10000));
EXPECT_EQ(ERR_GID, multiuser_get_cache_gid(0, 50000));
+ EXPECT_EQ(ERR_GID, multiuser_get_cache_gid(10, 0));
+ EXPECT_EQ(ERR_GID, multiuser_get_cache_gid(10, 1000));
EXPECT_EQ(1020000U, multiuser_get_cache_gid(10, 10000));
+ EXPECT_EQ(ERR_GID, multiuser_get_cache_gid(10, 50000));
}
TEST(MultiuserTest, TestExt) {
@@ -77,9 +80,12 @@
}
TEST(MultiuserTest, TestShared) {
- EXPECT_EQ(ERR_GID, multiuser_get_shared_gid(0, 0));
- EXPECT_EQ(ERR_GID, multiuser_get_shared_gid(0, 1000));
+ EXPECT_EQ(0U, multiuser_get_shared_gid(0, 0));
+ EXPECT_EQ(1000U, multiuser_get_shared_gid(0, 1000));
EXPECT_EQ(50000U, multiuser_get_shared_gid(0, 10000));
EXPECT_EQ(ERR_GID, multiuser_get_shared_gid(0, 50000));
- EXPECT_EQ(1050000U, multiuser_get_shared_gid(10, 10000));
+ EXPECT_EQ(0U, multiuser_get_shared_gid(10, 0));
+ EXPECT_EQ(1000U, multiuser_get_shared_gid(10, 1000));
+ EXPECT_EQ(50000U, multiuser_get_shared_gid(10, 10000));
+ EXPECT_EQ(ERR_GID, multiuser_get_shared_gid(10, 50000));
}