4

I am developing an application along with a custom Android ROM that requires me to access a certain folder in the Android file system. The application has System privileges and the user System prints following when executing

id

Output:

uid=1000(system) gid=1000(system) groups=1001(radio),1002(bluetooth),1003(graphics),1004(input),1005(audio),1006(camera),1007(log),1008(compass),1009(mount),1010(wifi),1018(usb)

The folder that I need to access is created by another user (an Android application on the Libraries layer) and is limited to a group which I am not part of.

So my questions are: Where in the Android source code would it be suitable to add the user System to the existing group? (Or how is it done with the other groups that System is part of)

GilCol
  • 391
  • 3
  • 14
  • Adding Android users (applications) to groups isn't best done in source code on Android - neither the Android source code, nor any other source code. So I think your question doesn't have an answer. It would be better if you re-phrased your question so it was of the form: "I am trying to accomplish X. How should I best do this?" – AnotherSmellyGeek Dec 28 '16 at 23:10
  • @AnotherSmellyGeek I have added an answer to my own question. – GilCol Jan 16 '17 at 19:14
  • 1
    Yep, that's the correct answer to the question I think you meant to ask :-) – AnotherSmellyGeek Mar 01 '17 at 03:47

1 Answers1

5

I found out that GIDs can be requested during runtime by requesting Android system permissions. The user (as in linux user) that runs the application will temporarily own that permission. Not all permissions grant gids.

Here is an example of platform.xml from the AOSP project source where the system permissions that grant gids are listed and partly mapped (the gid name needs to be mapped to a number as well in android_filesystem_config.h).

https://android.googlesource.com/platform/frameworks/base/+/cd92588/data/etc/platform.xml

E.g. Create a system application and add android.permission.BLUETOOTH to your AndroidManifest.xml. This will result in uid=1000(system) with gid=****(net_bt) in addition to other gids that will most likely be included as default. Requesting android.permission.BLUETOOTH will give you gid net_bt which in turn is mapped to a number in the platform source code (I don't know the default for net_bet which is why I masked it).

I have touched this subject in another post where I explain how to create permissions and gids and how to map them to each other. https://stackoverflow.com/a/39775558/2815572

Community
  • 1
  • 1
GilCol
  • 391
  • 3
  • 14