Android NDK open()设备权限被拒绝 [英] Android NDK open() device permission denied

查看:952
本文介绍了Android NDK open()设备权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个本地电话中,我尝试进入open("/dev/video4", O_RDWR),但出现errno EACCES 13权限被拒绝".

In a native call, I'm trying to open("/dev/video4", O_RDWR) but I get errno EACCES 13 "permission denied".

如果我在同一Android主机上的可执行文件中运行相同的代码*,与我在上面运行的已安装应用程序的相同UID一样,则可以正常运行. (*较小的差异,例如main()而不是Java_com_test_testOpen())

If I run the same code* in an executable, on the same Android host, as the same UID of the installed app I'm running above, it works fine. (* minor differences like main() instead of Java_com_test_testOpen())

我已经尝试过chmod 666 /dev/video4并仍然获得EACCES,这尤其奇怪.

I've tried chmod 666 /dev/video4 and still get EACCES, which is especially strange.

为什么相同主机上的相同代码作为相同用户在通过JNI调用时给出EACCESS,而在通过被称为独立可执行文件?

Why does the same code, on the same host, as the same user, give EACCESS when called via JNI, and success when called as standalone executable?

测试设备已植根并运行Cyanogenmod 12.1(API 22),我的目标是在植根的设备上> = API 21(5.0棒棒糖).感谢您的帮助.

The test device is rooted and running Cyanogenmod 12.1 (API 22) and I'm targeting >= API 21 (5.0 Lollipop) on rooted devices. Thanks for your help.

推荐答案

由于我使用其他一些小技巧构建了Cyanogenmod 12.1(API 22),因此我可以使用以下小技巧在我的应用程序中获得/dev/video*的权限:

Since I'm building Cyanogenmod 12.1 (API 22) with other minor hacks I was able to get permissions for /dev/video* in my app by using the following hacks:

  1. 对于标准Linux权限,android.permission.CAMERA似乎不再允许访问/dev/video*,即使它们由system:camera拥有.相反,我编辑了device/samsung/klte-common/rootdir/etc/ueventd.qcom.rc并将/dev/video*行更改为0666.
  2. 为了获得SE Linux权限,我在external/sepolicy/untrusted_app.te中添加了allow untrusted_app video_device:chr_file rw_file_perms;行.
  1. For standard Linux permissions, android.permission.CAMERA no longer seems to allow access to /dev/video* even though they're owned by system:camera. Instead, I edited device/samsung/klte-common/rootdir/etc/ueventd.qcom.rc and changed the /dev/video* line to 0666.
  2. For SE Linux permissions, I added the line allow untrusted_app video_device:chr_file rw_file_perms; to external/sepolicy/untrusted_app.te.

重建并安装映像后,我的JNI库可以访问/dev/video*,并且我的客户端很高兴!

After rebuilding and installing the image, my JNI lib is able to access /dev/video* and my client is happy!

这篇关于Android NDK open()设备权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆