Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 53d37ba2 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

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
parent 21d3840e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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",
+4 −2
Original line number Diff line number Diff line
@@ -53,9 +53,11 @@ gid_t multiuser_get_ext_cache_gid(userid_t user_id, appid_t app_id) {
    }
}

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;
    }
+9 −3
Original line number Diff line number Diff line
@@ -57,7 +57,10 @@ TEST(MultiuserTest, TestCache) {
    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, TestExtCache) {
}

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));
}