Wednesday, October 19, 2011

Adding User or Group to Android

Today I had a requirement to add a group(GID) to android system.

I found out that android system has hardcoded GID's for few Groups which is defined during the build time.

Step1: vim $(Android_root_folder)/system/core/include/private/android_filesystem_config.h

Add the below line for "lp" group creation

eg: #define AID_LP 3006

static struct android_id_info android_ids[]={
{"lp", AID_LP, },
};

Step2: Build the android source code.

Step3: Test whether group is created on some file eg: chown root.lp <file_name>

Step4: ls -l on the files you chowned, you can see group gets added successfully.


Note: Like linux you cant find /etc/passwd or /etc/group files in case of android. All the group additions are hardcoded.

I am yet to figure out how we can add users to the groups.


6 comments:

  1. have you found a way to add application to existing group using adb shell?

    ReplyDelete
    Replies
    1. Do you want to change the application to different user/group which is already present in android?

      #chown .

      Note: You cannot assign any custom group which is not present in android other than editing android_filesystem_config.h

      But changing application to different group creates problem during launching time. Usually when an application is installed by package manager it will choose a predefined UID and GID similar to UID which is stored in /data/system/packages.list. Application launcher will assign that value to any application which is launched.

      Delete
  2. I want to add my application (app_35 , uid 10032) to Internet group (AID_INET 3003). Can this be performed using chown?
    I can use manifest to do it. But I want to do it work using a program or through a shell interface.

    ReplyDelete
    Replies
    1. 1. Internet Group is an supplementary GID, which cant be added to any application using adb shell.
      2. Actually when an application is installed, its assigned with UID, GID and GIDS{ }, your internet group falls into GIDS which cant be added via chown.
      3. If you really need your application to have internet group there is way, for that you need to edit dalvik_system_Zygote.cpp file which is present in your android source code

      Delete
  3. 1. Internet Group is an supplementary GID, which cant be added to any application using adb shell.
    2. Actually when an application is installed, its assigned with UID, GID and GIDS{ }, your internet group falls into GIDS which cant be added via chown.
    3. If you really need your application to have internet group there is way, for that you need to edit dalvik_system_Zygote.cpp file which is present in your android source code.

    ReplyDelete
  4. I will try it and let you know how it goes. I have a followup question. When a application is granted Internet permission what is he API that gets called to add application to internet group

    ReplyDelete