Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Android 12 Telephony Crash

Discussion in 'Android' started by gabebag, May 28, 2022.

  1. gabebag

    gabebag

    Joined:
    Mar 10, 2017
    Posts:
    1
    We have a game that has been working fine for years on Unity 2017, then 2019. Android 12 changed the way Bluetooth permissions are handled, since we use Bluetooth, we've updated to build sdk 31 and set the build target to 31. We added our own Android code to our custom unity wrapper activity to request permissions.

    Somehow, after we request permissions, the app crashes in UnityPlayer, it looks like Unity calls "addPhoneListener()", which in turn calls "TelephonyManager.listen()". I suspect Android 12 has changed an now requires the READ_PHONE_STATE permission for this operation, where as permission wasn't required before.

    I'm not sure why I haven't seen any other devs run into this issue on Android 12. Is there a way to avoid this call, or catch the exception? I'm not sure what triggers it.

    The permission is saved before the crash, so I'm able to run the app a few times, crashing after each permission request, until all permissions are granted. But obviously, can't ship that to our users.

    2022-05-28 09:46:46.513 29106-29106/? A/DEBUG: Abort message: 'JNI DETECTED ERROR IN APPLICATION: JNI CallVoidMethodV called with pending exception java.lang.SecurityException: listen
    at java.lang.Exception android.os.Parcel.createExceptionOrNull(int, java.lang.String) (Parcel.java:2425)
    at java.lang.Exception android.os.Parcel.createException(int, java.lang.String) (Parcel.java:2409)
    at void android.os.Parcel.readException(int, java.lang.String) (Parcel.java:2392)
    at void android.os.Parcel.readException() (Parcel.java:2334)
    at void com.android.internal.telephony.ITelephonyRegistry$Stub$Proxy.listenWithEventList(int, java.lang.String, java.lang.String, com.android.internal.telephony.IPhoneStateListener, int[], boolean) (ITelephonyRegistry.java:1036)
    at void android.telephony.TelephonyRegistryManager.listenFromListener(int, java.lang.String, java.lang.String, android.telephony.PhoneStateListener, int, boolean) (TelephonyRegistryManager.java:250)
    at void android.telephony.TelephonyManager.listen(android.telephony.PhoneStateListener, int) (TelephonyManager.java:6038)
    at void com.unity3d.player.UnityPlayer.addPhoneCallListener() ((null):-1)
    at boolean com.unity3d.player.UnityPlayer.nativeRender() ((null):-2)
    at boolean com.unity3d.player.UnityPlayer.access$300(com.unity3d.player.UnityPlayer) ((null):-1)
    at boolean com.unity3d.player.UnityPlayer$e$1.handleMessage(android.os.Message) ((null):-1)
    at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102)
    at boolean android.os.Looper.loopOnce(android.os.Looper, long, int, long) (Looper.java:226)
    at void android.os.Looper.loop() (Looper.java:329)
    at void com.unity3d.player.UnityPlayer$e.run() ((null):-1)
    Caused by: android.os.RemoteException: Remote stack trace:
    at com.android.internal.telephony.TelephonyPermissions.enforceCarrierPrivilege(TelephonyPermissions.java:634)
    at com.android.internal.telephony.TelephonyPermissions.checkReadPhoneState(TelephonyPermissions.java:149)
    at com.android.internal.telephony.TelephonyPermissions.checkCallingOrSelfReadPhoneState(TelephonyPermissions.java:94)
    at com.android.server.TelephonyRegistry.checkListenerPermission(TelephonyRegistry.java:3095)
    at com.android.server.TelephonyRegistry.listen(TelephonyRegistry.java:1024)

    (Throwable with no stack trace)

    in call to CallVoidMethodV
    from boolean com.unity3d.player.UnityPlayer.nativeRender()'
     
  2. gguolinegames

    gguolinegames

    Joined:
    Mar 7, 2019
    Posts:
    8
    we have exactly same issue!
     
  3. gguolinegames

    gguolinegames

    Joined:
    Mar 7, 2019
    Posts:
    8
    I found this happens often when there is bluetooth speaker available.
    and checking Player->'Mute Other Audio Sources' -> true can prevent crash.
    but I don't want check this option.

    there should be other way to prevent Unity call TelephonyManager.listen
     
  4. windstrike1

    windstrike1

    Joined:
    Feb 14, 2019
    Posts:
    1
    Having this issue as well, crashes with this error showing up in logcat. Android 12 device

    Code (CSharp):
    1. 2022-07-05 19:00:56.657 27698-27698/? A/DEBUG: Abort message: 'JNI DETECTED ERROR IN APPLICATION: JNI CallVoidMethodV called with pending exception java.lang.SecurityException: listen
    2.        at java.lang.Exception android.os.Parcel.createExceptionOrNull(int, java.lang.String) (Parcel.java:2437)
    3.        at java.lang.Exception android.os.Parcel.createException(int, java.lang.String) (Parcel.java:2421)
    4.        at void android.os.Parcel.readException(int, java.lang.String) (Parcel.java:2404)
    5.        at void android.os.Parcel.readException() (Parcel.java:2346)
    6.        at void com.android.internal.telephony.ITelephonyRegistry$Stub$Proxy.listenWithEventList(int, java.lang.String, java.lang.String, com.android.internal.telephony.IPhoneStateListener, int[], boolean) (ITelephonyRegistry.java:1036)
    7.        at void android.telephony.TelephonyRegistryManager.listenFromListener(int, java.lang.String, java.lang.String, android.telephony.PhoneStateListener, int, boolean) (TelephonyRegistryManager.java:250)
    8.        at void android.telephony.TelephonyManager.listen(android.telephony.PhoneStateListener, int) (TelephonyManager.java:6798)
    9.        at void com.unity3d.player.UnityPlayer.addPhoneCallListener() ((null):-1)
    10.        at boolean com.unity3d.player.UnityPlayer.nativeRender() ((null):-2)
    11.        at boolean com.unity3d.player.UnityPlayer.access$300(com.unity3d.player.UnityPlayer) ((null):-1)
    12.        at boolean com.unity3d.player.UnityPlayer$e$1.handleMessage(android.os.Message) ((null):-1)
    13.        at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102)
    14.        at boolean android.os.Looper.loopOnce(android.os.Looper, long, int) (Looper.java:226)
    15.        at void android.os.Looper.loop() (Looper.java:313)
    16.        at void com.unity3d.player.UnityPlayer$e.run() ((null):-1)
    17.     Caused by: android.os.RemoteException: Remote stack trace:
    18.        at com.android.internal.telephony.TelephonyPermissions.enforceCarrierPrivilege(TelephonyPermissions.java:634)
    19.        at com.android.internal.telephony.TelephonyPermissions.checkReadPhoneState(TelephonyPermissions.java:149)
    20.        at com.android.internal.telephony.TelephonyPermissions.checkCallingOrSelfReadPhoneState(TelephonyPermissions.java:94)
    21.        at com.android.server.TelephonyRegistry.checkListenerPermission(TelephonyRegistry.java:3163)
    22.        at com.android.server.TelephonyRegistry.listen(TelephonyRegistry.java:1037)
    (Throwable with no stack trace)

    in call to CallVoidMethodV
    from boolean com.unity3d.player.UnityPlayer.nativeRender()'
     
  5. basti_justdice

    basti_justdice

    Joined:
    Dec 9, 2019
    Posts:
    2
    Same issue here. App build with Unity 2020.3.22f1 and Target API Level 31 kept crashing on Android 12 devices when put to background and pulled back to foreground.

    Changing Target API Level to 30 solved the issue for now.
     
  6. danpoong

    danpoong

    Joined:
    Apr 16, 2019
    Posts:
    1
  7. cihadturhan_unity

    cihadturhan_unity

    Joined:
    Apr 19, 2021
    Posts:
    80
    Anyone tried the update? It seems like a different issue but I'll try updating unity version.
     
    jaesungline likes this.
  8. cihadturhan_unity

    cihadturhan_unity

    Joined:
    Apr 19, 2021
    Posts:
    80
    Update: Seems like updating unity to 2021.3.12f1 resolved the issue.
     
    breban1 likes this.