android: permission denied while opening /dev/video4 (webcam) from JNI

3.5k Views Asked by At

I have configured v4l2 on my android device. I plug the webcam and see that /dev/video4 node is created. But when I try to open it from my JNI layer it says "Permission denied"

I have tried the following

1) Change the permission of /dev/video4 so that it is Read-Write for all (0666)

2) Added the android.permission.camera in the android manifest xml (originally /dev/video4 was created by system and camera group had rw access.)

None of them work. Any ideas on how to solve it?

2

There are 2 best solutions below

0
On

This sounds like the same issue I had with SE Linux permissions on Lollipop. See my answer here.

In short, you can:

  • disable SE Linux (until reboot) by running (as root) echo 0 > /sys/fs/selinux/enforce
  • hack your Cyanogenmod build and add allow untrusted_app video_device:chr_file rw_file_perms; to external/sepolicy/untrusted_app.te.
0
On

I faced a similar problem on Android 4.4.2 (Sasmung Galaxy S5 SM-G900F). I found that changing permissions for /dev/video4 did not help. But chown did the trick:

su -c chown 10209:10209 /dev/video4

(here, 10209 was the UID alloated by Android to my app).

PS this did not resolve my major problem: kernel panic when my app was reading video frames from the particular usb camera.