summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTreehugger Robot2017-04-18 17:34:15 -0500
committerGerrit Code Review2017-04-18 17:34:16 -0500
commitedaed3ed7a6034bd0bd07e55585b6c81333b9d3a (patch)
tree0f8c0f7c38682469cd7627594c46604ebcc3b75b
parent0bdf6539d6952425029a7f85d4736a6e6065a728 (diff)
parentfa164739210c1b8188051612b28204373db963fa (diff)
downloadplatform-system-core-edaed3ed7a6034bd0bd07e55585b6c81333b9d3a.tar.gz
platform-system-core-edaed3ed7a6034bd0bd07e55585b6c81333b9d3a.tar.xz
platform-system-core-edaed3ed7a6034bd0bd07e55585b6c81333b9d3a.zip
Merge "Allocate a GID range for external cache files."
-rw-r--r--libcutils/include/cutils/multiuser.h1
-rw-r--r--libcutils/include/private/android_filesystem_config.h3
-rw-r--r--libcutils/multiuser.c8
-rw-r--r--libcutils/tests/multiuser_test.cpp8
4 files changed, 20 insertions, 0 deletions
diff --git a/libcutils/include/cutils/multiuser.h b/libcutils/include/cutils/multiuser.h
index 5bd9c7b82..9a2305c98 100644
--- a/libcutils/include/cutils/multiuser.h
+++ b/libcutils/include/cutils/multiuser.h
@@ -33,6 +33,7 @@ extern uid_t multiuser_get_uid(userid_t user_id, appid_t app_id);
33 33
34extern gid_t multiuser_get_cache_gid(userid_t user_id, appid_t app_id); 34extern gid_t multiuser_get_cache_gid(userid_t user_id, appid_t app_id);
35extern gid_t multiuser_get_ext_gid(userid_t user_id, appid_t app_id); 35extern gid_t multiuser_get_ext_gid(userid_t user_id, appid_t app_id);
36extern gid_t multiuser_get_ext_cache_gid(userid_t user_id, appid_t app_id);
36extern gid_t multiuser_get_shared_gid(userid_t user_id, appid_t app_id); 37extern gid_t multiuser_get_shared_gid(userid_t user_id, appid_t app_id);
37 38
38/* TODO: switch callers over to multiuser_get_shared_gid() */ 39/* TODO: switch callers over to multiuser_get_shared_gid() */
diff --git a/libcutils/include/private/android_filesystem_config.h b/libcutils/include/private/android_filesystem_config.h
index 0037f1519..bbba8536e 100644
--- a/libcutils/include/private/android_filesystem_config.h
+++ b/libcutils/include/private/android_filesystem_config.h
@@ -171,6 +171,9 @@
171#define AID_EXT_GID_START 30000 /* start of gids for apps to mark external data */ 171#define AID_EXT_GID_START 30000 /* start of gids for apps to mark external data */
172#define AID_EXT_GID_END 39999 /* end of gids for apps to mark external data */ 172#define AID_EXT_GID_END 39999 /* end of gids for apps to mark external data */
173 173
174#define AID_EXT_CACHE_GID_START 40000 /* start of gids for apps to mark external cached data */
175#define AID_EXT_CACHE_GID_END 49999 /* end of gids for apps to mark external cached data */
176
174#define AID_SHARED_GID_START 50000 /* start of gids for apps in each user to share */ 177#define AID_SHARED_GID_START 50000 /* start of gids for apps in each user to share */
175#define AID_SHARED_GID_END 59999 /* end of gids for apps in each user to share */ 178#define AID_SHARED_GID_END 59999 /* end of gids for apps in each user to share */
176 179
diff --git a/libcutils/multiuser.c b/libcutils/multiuser.c
index 08d4d6c2e..61403f4f1 100644
--- a/libcutils/multiuser.c
+++ b/libcutils/multiuser.c
@@ -45,6 +45,14 @@ gid_t multiuser_get_ext_gid(userid_t user_id, appid_t app_id) {
45 } 45 }
46} 46}
47 47
48gid_t multiuser_get_ext_cache_gid(userid_t user_id, appid_t app_id) {
49 if (app_id >= AID_APP_START && app_id <= AID_APP_END) {
50 return multiuser_get_uid(user_id, (app_id - AID_APP_START) + AID_EXT_CACHE_GID_START);
51 } else {
52 return -1;
53 }
54}
55
48gid_t multiuser_get_shared_gid(userid_t user_id, appid_t app_id) { 56gid_t multiuser_get_shared_gid(userid_t user_id, appid_t app_id) {
49 if (app_id >= AID_APP_START && app_id <= AID_APP_END) { 57 if (app_id >= AID_APP_START && app_id <= AID_APP_END) {
50 return multiuser_get_uid(user_id, (app_id - AID_APP_START) + AID_SHARED_GID_START); 58 return multiuser_get_uid(user_id, (app_id - AID_APP_START) + AID_SHARED_GID_START);
diff --git a/libcutils/tests/multiuser_test.cpp b/libcutils/tests/multiuser_test.cpp
index ae5c4169c..2f9d854b3 100644
--- a/libcutils/tests/multiuser_test.cpp
+++ b/libcutils/tests/multiuser_test.cpp
@@ -68,6 +68,14 @@ TEST(MultiuserTest, TestExt) {
68 EXPECT_EQ(1030000U, multiuser_get_ext_gid(10, 10000)); 68 EXPECT_EQ(1030000U, multiuser_get_ext_gid(10, 10000));
69} 69}
70 70
71TEST(MultiuserTest, TestExtCache) {
72 EXPECT_EQ(ERR_GID, multiuser_get_ext_cache_gid(0, 0));
73 EXPECT_EQ(ERR_GID, multiuser_get_ext_cache_gid(0, 1000));
74 EXPECT_EQ(40000U, multiuser_get_ext_cache_gid(0, 10000));
75 EXPECT_EQ(ERR_GID, multiuser_get_ext_cache_gid(0, 50000));
76 EXPECT_EQ(1040000U, multiuser_get_ext_cache_gid(10, 10000));
77}
78
71TEST(MultiuserTest, TestShared) { 79TEST(MultiuserTest, TestShared) {
72 EXPECT_EQ(ERR_GID, multiuser_get_shared_gid(0, 0)); 80 EXPECT_EQ(ERR_GID, multiuser_get_shared_gid(0, 0));
73 EXPECT_EQ(ERR_GID, multiuser_get_shared_gid(0, 1000)); 81 EXPECT_EQ(ERR_GID, multiuser_get_shared_gid(0, 1000));