YoussefHenna / expo-enode-link-sdk

An Expo Module integration for Enode's Link SDK
MIT License
8 stars 2 forks source link

Bluetooth permission problems with old Android devices #13

Closed SonjaNueAmperias closed 8 months ago

SonjaNueAmperias commented 8 months ago

Hey, I have issues with older Android devices. I am currently testing on two devices:

This expo module works fine with new Android devices and all iOS devices, but with the two devices I listed above, I have problems with the bluetooth permissions. I believe that the problem comes from the fact that new permission handling for bluetooth was introduced with Android API level 31.

How the error happens:

Android 6 I open the app and get the URL to link the electric car from our BE. When I try to open the URL with ExpoEnodeLinkSDK.show(...) the app first requests the permission for the location and afterwards crashes. The terminal prints the following error:

Your app just crashed. See the error below.
java.lang.RuntimeException: Unable to resume activity {com.eon.home.eu/com.eon.home.eu.MainActivity}: java.lang.reflect.InvocationTargetException
  android.app.ActivityThread.performResumeActivity(ActivityThread.java:3154)
  android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3185)
  android.app.ActivityThread$H.handleMessage(ActivityThread.java:1423)
  android.os.Handler.dispatchMessage(Handler.java:102)
  android.os.Looper.loop(Looper.java:150)
  android.app.ActivityThread.main(ActivityThread.java:5643)
  java.lang.reflect.Method.invoke(Native Method)
  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799)
  com.android.internal.os.ZygoteInit.main(ZygoteInit.java:689)
Caused by java.lang.reflect.InvocationTargetException
  java.lang.reflect.Method.invoke(Native Method)
  expo.modules.ReactActivityDelegateWrapper.invokeDelegateMethod(ReactActivityDelegateWrapper.kt:285)
  expo.modules.ReactActivityDelegateWrapper.onResume(ReactActivityDelegateWrapper.kt:163)
  com.facebook.react.ReactActivity.onResume(ReactActivity.java:58)
  android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1266)
  android.app.Activity.performResume(Activity.java:6451)
  android.app.ActivityThread.performResumeActivity(ActivityThread.java:3144)
  android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3185)
  android.app.ActivityThread$H.handleMessage(ActivityThread.java:1423)
  android.os.Handler.dispatchMessage(Handler.java:102)
  android.os.Looper.loop(Looper.java:150)
  android.app.ActivityThread.main(ActivityThread.java:5643)
  java.lang.reflect.Method.invoke(Native Method)
  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799)
  com.android.internal.os.ZygoteInit.main(ZygoteInit.java:689)
Caused by java.lang.IllegalArgumentException: Unknown permission: android.permission.BLUETOOTH_SCAN
  android.os.Parcel.readException(Parcel.java:1606)
  android.os.Parcel.readException(Parcel.java:1555)
  android.content.pm.IPackageManager$Stub$Proxy.shouldShowRequestPermissionRationale(IPackageManager.java:2699)
  android.app.ApplicationPackageManager.shouldShowRequestPermissionRationale(ApplicationPackageManager.java:539)
  android.app.Activity.shouldShowRequestPermissionRationale(Activity.java:3970)
  androidx.core.app.ActivityCompat$Api23Impl.shouldShowRequestPermissionRationale(ActivityCompat.java:943)
  androidx.core.app.ActivityCompat.shouldShowRequestPermissionRationale(ActivityCompat.java:601)
  expo.modules.adapters.react.permissions.PermissionsService.canAskAgain(PermissionsService.kt:201)
  expo.modules.adapters.react.permissions.PermissionsService.getPermissionResponseFromNativeResponse(PermissionsService.kt:222)
  expo.modules.adapters.react.permissions.PermissionsService.parseNativeResult(PermissionsService.kt:208)
  expo.modules.adapters.react.permissions.PermissionsService.createListenerWithPendingPermissionsRequest$lambda$22(PermissionsService.kt:271)
  expo.modules.adapters.react.permissions.PermissionsService.$r8$lambda$hmbyKVSQEVIO5W4sPAkDecGzoKE(PermissionsService.kt)
  expo.modules.adapters.react.permissions.PermissionsService$$ExternalSyntheticLambda0.onRequestPermissionsResult(D8$$SyntheticClass)
  com.facebook.react.ReactActivityDelegate$2.invoke(ReactActivityDelegate.java:201)
  com.facebook.react.ReactActivityDelegate.onResume(ReactActivityDelegate.java:126)
  java.lang.reflect.Method.invoke(Native Method)
  expo.modules.ReactActivityDelegateWrapper.invokeDelegateMethod(ReactActivityDelegateWrapper.kt:285)
  expo.modules.ReactActivityDelegateWrapper.onResume(ReactActivityDelegateWrapper.kt:163)
  com.facebook.react.ReactActivity.onResume(ReactActivity.java:58)
  android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1266)
  android.app.Activity.performResume(Activity.java:6451)
  android.app.ActivityThread.performResumeActivity(ActivityThread.java:3144)
  android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3185)
  android.app.ActivityThread$H.handleMessage(ActivityThread.java:1423)
  android.os.Handler.dispatchMessage(Handler.java:102)
  android.os.Looper.loop(Looper.java:150)
  android.app.ActivityThread.main(ActivityThread.java:5643)
  java.lang.reflect.Method.invoke(Native Method)
  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799)
  com.android.internal.os.ZygoteInit.main(ZygoteInit.java:689)

Android 10 I open the app and get the URL to link the electric car from our BE. When I try to open the URL with ExpoEnodeLinkSDK.show(...) the app first requests the permission for the location and afterwards doesn't show the link UI flow, but I get the following code and errorMessage in the result listener ExpoEnodeLinkSDK.listenToResult((code, errorMessage) => {...} .

code:  permissionError
errorMessage:  One or more of the required permissions are missing or not granted (ACCESS_FINE_LOCATION, BLUETOOTH_SCAN, BLUETOOTH_CONNECT)

For this device / Android version the app doesn't crash.

Other observations

Differences I noticed for newer and older Android versions: When I go to app permissions in the system preferences for newer devices I see "Nearby devices" listed as permission. For older devices this permission does not appear (see screenshots)

Device with Android API level 33

device_api_33

Device with Android API level 23

device_api_33



Any ideas? I've been stuck with this for a week. I tried to add the permissions to app.json and app.config.ts and also tried to request the permission with PermissionsAndroid.request(...) before the linking process, but I couldn't get it to work.

Does anyone have the same problems? It would be great if someone could help me. Thank you very much :)

YoussefHenna commented 8 months ago

Hey, thanks for the detailed bug report! I admit that I did not properly test this out on older devices. I'm sure permissions need to be handled differently in that case, I'll look into it and try to address the issue soon.

YoussefHenna commented 8 months ago

@SonjaNueAmperias I just released v0.4.3. Please try that out and let me know if that works.

SonjaNueAmperias commented 8 months ago

@YoussefHenna, thank you so much for your fast response and the fast solution. For the Android 10 device the new version is working perfectly fine 🎉.

Unfortunately, it still does not work on the Android 6 device. However, the behavior has changed. The app no longer crashes. Instead, the In-App-Browser opens showing a blanc screen (see screenshot). When I copy the URL from the In-App-Browser and paste it into the chrome app, I can go through the linking flow. Then after I get redirected to the app I get the following errorMessage and code.

code: unknownError
errorMessage: null
Android 6 device showing blanc In-App-Browser

Do you have any idea where the problem is coming from? As the error only occurs on the very old device, I don't know how important it is to investigate this error any further. I will test other old Android versions with the help of the emulator and will let you know if I notice anything.

Thank you so much for you help!

YoussefHenna commented 8 months ago

Hmm. This package only launches the Enode link SDK, so this issue might be an underlying issue with the Enode SDK itself rather than something going on with this expo implementation of it. It's possible that it does not support older android versions, I'd say you can contact them through here: https://developers.enode.com/support, they're a supportive team and tend to help out when asked.

Testing out other devices is also a good idea, please let me know how that goes!