Android:在Linux应用程序和Android应用程序之间共享公共文件夹

发布于 2024-12-21 12:27:09 字数 419 浏览 7 评论 0原文

嗨,我是 Android 新手...请对以下问题进行一些说明。

我有一个由 linux 应用程序(用 C 编写)创建的文件,具有 S_IRWXU|S_IRWXG 权限,该文件属于 root 用户和 root 组。

现在我想以不同的用户身份(例如 app_41)作为 Android 应用程序读取/写入该文件。对于 Android 应用程序来说这是不可能的,因为它没有该文件的权限。

实现此目的的最佳方法是什么(不允许“其他”文件/文件夹的权限)?

原因是我有一个用 C 编写的守护进程,它创建和管理命名管道以供其他进程使用。我正在尝试从 Android 应用程序(使用本机代码)写入命名管道,但我没有正确的权限来执行此操作。

如果有人说......“嘿,这很简单......这样做......”,我不会感到惊讶,

谢谢你的帮助!

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!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼趣 2024-12-28 12:27:09

我找到了一个解决方案并且它有效...请让我知道是否有人有更好的解决方案..

对于 Android 应用程序共享 root 进程所拥有的文件,我们需要执行以下操作

  1. 制作 Android 应用程序属于“系统”用户使用

    android:sharedUserId="android.uid.system"
    
  2. 使用

    让其他平台进程(拥有该文件)保留为 root,但将其添加到“system”组, 。

  3. 现在的问题是如何向组“system”添加进程。我们想到的一件事是将进程添加到 init.rc 并使用“group”关键字并启动它。但 Android 不允许这种情况发生。

  4. 要将进程添加到“系统”组,进程必须从进程内部请求组 ID。也就是说,从进程内部使用 setgid(1000) 系统调用将其添加到组“system”。

它效果很好!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文