MediaPipeUnityPlugin icon indicating copy to clipboard operation
MediaPipeUnityPlugin copied to clipboard

Some Androids (E.g. HUAWEI) cannot properly wait for camera permissions

Open jsaon-L opened this issue 2 years ago • 13 comments
trafficstars

Plugin Version or Commit ID

v0.10.3

Unity Version

2021.3.4f1

Your Host OS

win11

Target Platform

Android

Target Device

No response

[Windows Only] Visual Studio C++ and Windows SDK Version

No response

[Linux Only] GCC/G++ and GLIBC Version

No response

[Android Only] Android Build Tools and NDK Version

No response

[iOS Only] XCode Version

No response

Build Command

python build.py build --android arm64 --android_ndk_api_level 21 -vv

Bug Description

Open the apk for the first installation,it doesn't work It works the second time you open it I think "Callback RequestUserPermission" should be used

https://docs.unity3d.com/ScriptReference/Android.Permission.RequestUserPermission.html

WebCamSource.cs

#if UNITY_ANDROID
        if (!Permission.HasUserAuthorizedPermission(Permission.Camera))
        {
+         bool permissionResponse = false;
+         var callbacks = new PermissionCallbacks();
+         callbacks.PermissionDenied += (string permissionName) => { permissionResponse = true; };
+         callbacks.PermissionGranted += (string permissionName) => { permissionResponse = true; };
+         callbacks.PermissionDeniedAndDontAskAgain += (string permissionName) => { permissionResponse = true; };

+         Permission.RequestUserPermission(Permission.Camera, callbacks);
+         yield return new WaitUntil(() => permissionResponse);
-         Permission.RequestUserPermission(Permission.Camera);
-         yield return new WaitForSeconds(0.1f);
        }
#elif UNITY_IOS

Steps to Reproduce the Bug

open apk

Log

no log

Screenshot/Video

No response

Additional Context

No response

jsaon-L avatar Jan 12 '23 08:01 jsaon-L

no log

Will you share the Player.log? (e.g. adb -s [device_id] logcat Unity:V native:V tflite:V CRASH:E AndroidRuntime:E "*:S")

homuler avatar Jan 12 '23 12:01 homuler

https://user-images.githubusercontent.com/17309378/212228720-8e3bb10a-4e1a-4129-bde0-a3676a4b2ba2.mp4

log.txt


i add debug log in script "Start RequestUserPermission" "End RequestUserPermission" image

jsaon-L avatar Jan 13 '23 03:01 jsaon-L

Thanks! Does the code you suggested fix this issue on your device?

homuler avatar Jan 13 '23 13:01 homuler

Thanks! Does the code you suggested fix this issue on your device?

The problems in the video don't come up every time, but give me some time and I'll test the code fully

jsaon-L avatar Jan 13 '23 13:01 jsaon-L

I think 0.1sec is simply too short (but waiting for a fixed time is not a good approach).

yield return new WaitForSeconds(0.1f);

homuler avatar Jan 13 '23 14:01 homuler

I think 0.1sec is simply too short (but waiting for a fixed time is not a good approach).

yield return new WaitForSeconds(0.1f);

According to the unity Android Permissions documentation, callback should be used Using callbacks eliminates the need to write a fixed time

jsaon-L avatar Jan 13 '23 14:01 jsaon-L

According to the unity Android Permissions documentation, callback should be used

Will you tell me where they say so?

I'm not sure, but I guess this error is caused because the access to _IsPermitted from the Play method is not guarded with _PermissionLock (and if it's guarded, maybe we can remove the WaitForSeconds). https://github.com/homuler/MediaPipeUnityPlugin/blob/f5d2361f4c7442cfbf174901a165104f7298b587/Assets/MediaPipeUnity/Samples/Common/Scripts/ImageSource/WebCamSource.cs#L197-L200

https://github.com/homuler/MediaPipeUnityPlugin/blob/f5d2361f4c7442cfbf174901a165104f7298b587/Assets/MediaPipeUnity/Samples/Common/Scripts/ImageSource/WebCamSource.cs#L147-L152

homuler avatar Jan 13 '23 14:01 homuler

According to the unity Android Permissions documentation, callback should be used

Will you tell me where they say so?

I'm not sure, but I guess this error is caused because the access to _IsPermitted from the Play method is not guarded with _PermissionLock (and if it's guarded, maybe we can remove the WaitForSeconds).

https://github.com/homuler/MediaPipeUnityPlugin/blob/f5d2361f4c7442cfbf174901a165104f7298b587/Assets/MediaPipeUnity/Samples/Common/Scripts/ImageSource/WebCamSource.cs#L197-L200

https://github.com/homuler/MediaPipeUnityPlugin/blob/f5d2361f4c7442cfbf174901a165104f7298b587/Assets/MediaPipeUnity/Samples/Common/Scripts/ImageSource/WebCamSource.cs#L147-L152

i think "PermissionCallbacks_PermissionDenied" function is call when user click screen, this is doc url https://docs.unity3d.com/ScriptReference/Android.Permission.RequestUserPermission.html image

jsaon-L avatar Jan 13 '23 14:01 jsaon-L

I mean, they say we can use callbacks but don't say we should use callbacks, do they?

homuler avatar Jan 13 '23 15:01 homuler

I mean, they say we can use callbacks but don't say we should use callbacks, do they?

unity Document not say we should use what code

jsaon-L avatar Jan 13 '23 15:01 jsaon-L

@jsaon-L Will you check if #829 fixes this issue?

homuler avatar Jan 15 '23 06:01 homuler

i will test this

jsaon-L avatar Jan 15 '23 06:01 jsaon-L

您会检查#829是否解决此问题吗?

After my testing this submission does not solve this problem

jsaon-L avatar Apr 25 '23 14:04 jsaon-L