質問

Hi I'm a newbie for Android... Please throw some light on the following issue..

I have a file created by a linux application (written in C) with S_IRWXU|S_IRWXG permission and the file belongs to root user and root group.

Now I'd like to read/write to this file as an Android application as a different user (say app_41). It is not possible for the android application because it has no permission for the file.

What is the best way to implement this (without allowing "others" permission to the file/folder)?

The reason is that I have a daemon written in C that creates and manages named pipes for other process use. I'm trying to write to the named pipe from Android application (using native code) and I don't have the right permission to do it.

I won't be surprised, if someone says... "Hey it is very simple.. do this..."

Thanks for your help!!

役に立ちましたか?

解決

I figured out a solution and it works... Please let me know if anyone has any better solution..

For an android application to share a file owened by a root process, we need to do the following

  1. Make the Android application to belong to "system" user using

    android:sharedUserId="android.uid.system"
    
  2. Let the other platform process (owning the file) remain as root, but add it to the group "system".

  3. Now the question is how do I add a process to the group "system".. One quick thing that comes to our mind is to add the process to init.rc and use the "group" keyword and start it. But Android doesn't allow it to happen.

  4. To add the process to group "system" the process has to request the groupid from inside the process. That is, use the setgid(1000) system call from inside the process to add it to the group "system"..

And it works great!

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top