3

I am trying to access a USB Webcam from Android ndk.

The Android system has the V4L Kernel modules, so I thought it would be best to use the V4L libraries. They are bundeled in the ndk so it was not a big deal to include them into my project.

My problem is the following:

I need to open /dev/video4 and send the ioctl to that file descriptor, but I do not have the rights to access /dev/video4. I thought about three things:

1) Why do I lack permissions on /dev/video4? My app uses the android.permission.CAMERA permission, so the user that runs the app should be in the camera group, and the camera group has r+w permissions on /dev/video4, so why can't I open it?

2) I tried to get the file descriptor from java side, that is possible with the UsbManager class, but that file descriptor points do /dev/bus/usb/001/004. Is there a way to request permission for /dev/video4 from Java side? Or can I include a userspace V4L library and pass the pointer to the generic USB device in /dev/bus/usb/001/004?

3) Does the android version of OpenCV come with V4L support? Can I use it to preview the camera without having to access /dev/video4?

Has anybody tried something like this before?

Also, I know there are libraries out there that use libusb and libuvc to interface the camera (such as https://github.com/saki4510t/UVCCamera), but this library is very unsatble and does not provide satisfying results.

BT9
  • 87
  • 1
  • 11

2 Answers2

2

I arrived here because I came to the same conclusions as you did. I have no further suggestion to offer. Did you find anything else after all these years?

All I can add is the following:

  • Access to /dev/videoX file descriptors is further limited by SELinux.
  • android.permission.CAMERA does not do what you think it does. All these permission/feature settings, in manifest, enable access to application framework services, nothing to do with Linux group permissions or SELinux.
  • Camera2 framework enumerates front and rear cameras only, so not usable for usb cameras, at least not out of the box.
  • Although V4L2 drivers are present in Android, 'uvcvideo' driver is not by default. You'll have to build a custom kernel.
  • The UVCCamera project you pointed out makes use of UsbManager (with a user-space uvc parser). That's how it overcomes the permissions issue. That seems to be the only way, but this implementation is fragile and seems to have a problem with bulk mode.

it's a shame that we can't just use V4L2 + uvcvideo driver.

ioannis
  • 21
  • 3
  • hi. afaik the android permissions add the app's user to a certain linux-group, and the app inherits this groups permissions, but you are right, I have read reports that even a custom kernel that adds the right group does not give permission to open /dev/videoX. The uvcvideo driver seems to be present on the Samsung Galaxy S5 and it works pretty good if access to /dev/videoX is achieved with root-permissions (except for https://code.google.com/p/android/issues/detail?id=159529). This is what I am doing now. – BT9 Oct 02 '16 at 09:47
1

Having permission CAMERA doesn't actually mean you're in any particular Linux user group. It just means you have the permission for Android OS permission checks.

In general, applications don't get direct access to kernel driver interfaces. It's a big security issue, because the drivers are often not hardened against malicious applications.

The only current solution that can work with non-rooted devices is the UVCCamera project or others like it, that build a whole UVC interface on top of the Android public USB APIs.

In addition, some Android devices do actually support webcams through the standard camera APIs, but this is not yet a feature in baseline Android.

Eddy Talvala
  • 17,243
  • 2
  • 42
  • 47
  • hello i am getting same problem i am using UVC library, but it is working fine in my devices when i send apk to client then his camera is not showing anything ,please help.. – Aditay Kaushal May 25 '17 at 11:29