Peter-St / Android-UVC-Camera

GNU Lesser General Public License v2.1
136 stars 25 forks source link

remove user's home directory path from version-controlled files #29

Closed takashikumagai closed 2 years ago

takashikumagai commented 2 years ago

I found that some files contain the path of the user's home directory and this requires each user to edit those files manually. So I made changes to put the user home directory out of the version-controlled files. This would allow each user who clones the repo to build the project without editing files locally. I confirmed that the build passes on Linux and Windows.

takashikumagai commented 2 years ago

I just realized that after my change I get an error saying "permission denied for device" on a toast at runtime, even when I grant the app permission to access the camera. The app displays "Permission Granted!" on a toast in the first activity, but gives the error in the second activity. The app itself installs and starts fine (I copied app-debug.apk to my phone). This does not happen without my change so it must be something to do with my change.

Peter-St commented 2 years ago

Hello takashikumagai,

I appreciate your changes to this repo.

Due to the error you get, I'm wondering too, why the camera permissions changed.

1) Is the camera permission realy denied ? Have you tried to run the buttons and which output they give.

2) Eventually try to debug the phone for Android Studio. You have to connect your phone over Wifi ADB and then you can connect your camera to your phone and debug it over Android Studio.

3) Eventually try to undo the changes to the point it works / not works and report the failing commit.

So far,

Peter

takashikumagai commented 2 years ago

Thank you. I got to work now but I intend to try those (1. - 3.) in a couple of days. I'll get back to you later.

takashikumagai commented 2 years ago

So I reverted so that everything matches up with the current master of your repo but permission denied toast still persists, which does not quite make sense. To go over the steps that I took,

(I uninstalled the existing app first before executing the following steps.)

  1. Built the .apk file from source code 8ebd3a3 (my forked repo) on Android Studio.

  2. After installing the app via app-debug.apk file and opening it, I tap the 'SET UP THE CAMERA DEVICE' button and the app asks this:

  1. So I tap 'Allow'. Then the app shows the 'Permission Granted!' on the toast. So far so good.
  1. After I tap the 'SET UP THE CAMERA DEVICE' button another 2 times, the app asks this:
  1. I tap the 'Allow' again, then tap the 'SET UP THE CAMERA DEVICE' button yet again. This is when the app transitions to the next activity and 'device permission denied' is shown on the toast:

Here is the logcat output at the moment when the 'device permission denied' toast is displayed:

05-13 02:00:54.507   547   661 I hwcomposer: [HWC] (0) displayGetActiveConfig config:0  
05-13 02:00:54.512  1242  1371 D PrizePhoneWidowManager: SystemGesturesPointerEventListener swip =0
05-13 02:00:54.526   586  1912 I BufferQueueProducer: [humer.uvc_camera/humer.UvcCamera.SetUpTheUsbDeviceUvc#0](this:0x709dbf5000,id:4066,api:1,p:22898,c:586) queueBuffer: fps=0.43 dur=4687.59 max=4650.77 min=36.81
05-13 02:00:54.540   547   661 I hwcomposer: [HWCDisplay] [Display_0 (type:1)] fps:30.047941,dur:1164.81,max:539.61,min:14.86  
05-13 02:00:54.623 22898 22898 I UVC_Camera_Set_Up: searchTheCamera pressed;
05-13 02:00:54.520  1242  1371 I chatty  : uid=1000(system) InputReader identical 1 line
05-13 02:00:54.537  1242  1371 D PrizePhoneWidowManager: SystemGesturesPointerEventListener swip =0
05-13 02:00:54.624  1242  1888 I UsbUserSettingsManager: Camera permission required for USB video class devices
05-13 02:00:54.624 22898 22898 I UVC_Camera_Set_Up: Camera has no Usb permissions, try to request... 
05-13 02:00:54.635 22898 22898 I UVC_Camera_Set_Up: (on receive) String action = humer.uvc_camera.USB_PERMISSION
05-13 02:00:54.636 22898 22898 I UVC_Camera_Set_Up: (On receive) permission denied for device 
05-13 02:00:54.649 22898 22898 D ViewRootImpl[Toast]: hardware acceleration = true , fakeHwAccelerated = false, sRendererDisabled = false, forceHwAccelerated = false, sSystemRendererDisabled = false
05-13 02:00:54.627  1242  1888 I chatty  : uid=1000(system) Binder:1242_9 identical 1 line
05-13 02:00:54.627  1242  1888 I UsbUserSettingsManager: Camera permission required for USB video class devices
05-13 02:00:54.651  1242  1888 E WindowManager: App trying to use insecure INPUT_FEATURE_NO_INPUT_CHANNEL flag. Ignoring
05-13 02:00:54.656 22898 22898 I InputTransport: Create ARC handle: 0x736ce15960
05-13 02:00:54.662   586  1281 I BufferQueue: [unnamed-586-4068](this:0x70b8f77800,id:4068,api:0,p:-1,c:-1) BufferQueue core=(586:/system/bin/surfaceflinger)
05-13 02:00:54.662   586  1281 I BufferQueueConsumer: [unnamed-586-4068](this:0x70b8f77800,id:4068,api:0,p:-1,c:586) connect(C): consumer=(586:/system/bin/surfaceflinger) controlledByApp=false
05-13 02:00:54.662   586  1281 I BufferQueueConsumer: [unnamed-586-4068](this:0x70b8f77800,id:4068,api:0,p:-1,c:586) setConsumerName: unnamed-586-4068
05-13 02:00:54.662   586  1281 I BufferQueueConsumer: [Toast#0](this:0x70b8f77800,id:4068,api:0,p:-1,c:586) setConsumerName: Toast#0
05-13 02:00:54.662   586  1281 I BufferQueueConsumer: [Toast#0](this:0x70b8f77800,id:4068,api:0,p:-1,c:586) setDefaultBufferSize: width=690 height=147
05-13 02:00:54.667 22898 22919 D Surface : Surface::connect(this=0x73115b0000,api=1)
05-13 02:00:54.668   586  1912 I BufferQueueProducer: [Toast#0](this:0x70b8f77800,id:4068,api:1,p:22898,c:586) connect(P): api=1 producer=(22898:humer.uvc_camera) producerControlledByApp=false
05-13 02:00:54.668 22898 22919 D mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000
05-13 02:00:54.669 22898 22919 D Surface : Surface::setBufferCount(this=0x73115b0000,bufferCount=3)
05-13 02:00:54.669 22898 22919 D Surface : Surface::allocateBuffers(this=0x73115b0000)
05-13 02:00:55.235   775   775 I thermal_repeater: [recvMdThermalInfo] ret=31, strLen=127,  0, 32767, -127, 9500, 32767, 0
05-13 02:00:55.307   547   682 I hwcomposer: [DPY] receive refesh frquest from driver: type[4]  
05-13 02:00:55.307   547   682 I hwcomposer: [HWC] fire a callback of refresh to SF  
05-13 02:00:55.334   586   586 I BufferQueueProducer: [FramebufferSurface](this:0x70a11f8800,id:0,api:1,p:586,c:586) queueBuffer: fps=0.75 dur=1335.17 max=1335.17 min=1335.17

Does any of these look familiar?

Peter-St commented 2 years ago

Hello ,

plz try out the following repo:

https://github.com/saki4510t/UVCPermissionTest

Look if you can get the usb permissions.

You should get the usb permissions with compile sdk level 28 and 30.

Level 29 fails automatically.

Perhaps try out to compile on level 31 to receive the permissions.

I resently changed to sdk version from 27 to 30 for uploading the app to the play store. Perhaps the permission issue comes from this update.

Peter

takashikumagai commented 2 years ago

Thank you so much for assisting me with this. I built and tried app-APKIxx-debug.apk files on my phone (Android 10). I tested SDK levels 27, 28, 30, and 31. It seems I can't get the necessary permission in any of these versions (all versions install and behave the same way). As for sdk 30 and 31, I added these in productFlavors block in build.gradle:

        API30 {
            dimension "UVCPermissionTest"
            def ver = 30
            targetSdkVersion ver

            versionName "${versionNameString}_${ver}"
            applicationId "com.serenegiant.uvcpermissiontest.api${ver}"
            manifestPlaceholders = [app_name:"UVCPermissionTest_API${ver}"]
        }
        API31 {
            dimension "UVCPermissionTest"
            def ver = 31
            targetSdkVersion ver

            versionName "${versionNameString}_${ver}"
            applicationId "com.serenegiant.uvcpermissiontest.api${ver}"
            manifestPlaceholders = [app_name:"UVCPermissionTest_API${ver}"]
        }

So after I install and open the app, it first asks permission like this, similar to your Android-UVC-Camera app.

When I tap Allow, it momentarily displays 'Permission Granted' at the bottom of the screen

But as you can see, the Result: section says

hasPermission=false

Let me know if there are other things I should check. Also, please don't feel too pressured to investigate this; I saw the app built from the code cloned from your repo play video. So it has got to do with my forked repo. But I certainly reverted everything at this point, so I'm seriously wondering what I'm missing.

Peter-St commented 2 years ago

Hello takashikumagai,

Try to build the repo on sdk 27

The Popup screen "Allow UVCPermissionTest to..." is for the internal camera of your Phone. With SDK 28 the usb permission and the CAMERA permission were linked together. (you could only get USB Permission with granted Camera Permission)

You need to get a seperat USB permission popup screen to grant the usb permissions.

I was able to get the permissions with sdk 30 with this app. But you should at least get the usb permissions with sdk 27.

So far,

Peter

takashikumagai commented 2 years ago

The Popup screen "Allow UVCPermissionTest to..." is for the internal camera of your Phone. With SDK 28 the usb permission and the CAMERA permission were linked together. (you could only get USB Permission with granted Camera Permission)

You need to get a seperat USB permission popup screen to grant the usb permissions.

That's definitely a useful piece of information, thanks. I'll try your app and the UVCPermissionTest app with SDK 27 again with that in mind.

Peter-St commented 2 years ago

Hello takashikumagai,

I have merged your pull request any way and it works fine with my devices.

Did you solve your permission issue?

Hint: With SDK Verison 30 I still have to grant the Camera Permissions to get the Usb Permissions

Thx, Peter

takashikumagai commented 2 years ago

Sorry that I've been unresponsive for quite some time. You are right; I rebuilt everything using SDK 27 (i.e. built the apk file with both compileSdkVersion and targetSdkVersion set to 27) and ran the app. Then the app asks these when it is run for the first time.

A. Allow UVC_Camera to take pictures and record video? B. Allow UVC_Camera to access photos and media on your device? C. Allow UVC_Camera to access (USB camera product name)?

and if I answer yes to them, I can get to the activity for video streaming without any permission errors (I'm not seeing the video but I can look into this later)

But when I do the same with SDK 30, 31, or 32, the app only asks A and B, and I get the 'permission denied for device' error.

Peter-St commented 2 years ago

Hi,

can you plz tell you device (and Manufaktur) and which Android you are running.

Have you another android device you can run with my app?

I will tell this to Google directly, because they told me, this behavour should be solved ....

Thx,

Peter

takashikumagai commented 2 years ago

My phone is G90 PRO by BLU, and it's Android 10. I have another phone running Android 8.1 (Moto G5 Plus, XT1685) so I tried the same thing on it. Interestingly, on this older phone, the app built with SDK 27 and 32 both asked for separate permissions for camera and USB. So it seems like it's my Android 10 phone that's having issues with the app built with SDK 30 or higher.