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