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()'
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
Having this issue as well, crashes with this error showing up in logcat. Android 12 device Code (CSharp): 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 at java.lang.Exception android.os.Parcel.createExceptionOrNull(int, java.lang.String) (Parcel.java:2437) at java.lang.Exception android.os.Parcel.createException(int, java.lang.String) (Parcel.java:2421) at void android.os.Parcel.readException(int, java.lang.String) (Parcel.java:2404) at void android.os.Parcel.readException() (Parcel.java:2346) 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:6798) 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) (Looper.java:226) at void android.os.Looper.loop() (Looper.java:313) 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:3163) 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()'
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.