Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App crashes when incoming call is handled #640

Closed
slavchev opened this issue Dec 8, 2024 · 5 comments
Closed

App crashes when incoming call is handled #640

slavchev opened this issue Dec 8, 2024 · 5 comments

Comments

@slavchev
Copy link

slavchev commented Dec 8, 2024

Description

When app is not running and and incoming call is made the app crashes.

Steps to Reproduce

  1. Start the app
  2. Make an incoming call
  3. Accept the call (working)
  4. Close/kill the app
  5. Make an incoming call
  6. App crashes

Code

Using the app from the current at moment of writing head of master branch 6ae5839

Expected Behavior

App should be able to accept incoming call even when it is not currently running.

Actual Behavior

App crashes when it is not currently running and tries to accept an incoming call.

Reproduces How Often

It is always reproducible.

Twilio Call SID(s)

Call SID CA9e1f665c43423c143d42e50248023478

Logs

---------------------------- PROCESS STARTED (9721) for package com.twilio.voice.quickstart ----------------------------
2024-12-08 15:28:38.789  9721-9750  nativeloader            com.twilio.voice.quickstart          D  Load /data/app/~~yZ4yelBRhCDNpF4a_KjDwA==/com.twilio.voice.quickstart-fIFBuNDXRPQLrIXXc2-jiQ==/base.apk!/lib/arm64-v8a/libtwilio_voice_android_so.so using ns clns-7 from class loader (caller=/data/app/~~yZ4yelBRhCDNpF4a_KjDwA==/com.twilio.voice.quickstart-fIFBuNDXRPQLrIXXc2-jiQ==/base.apk): ok
2024-12-08 15:28:38.808  9721-9721  CompatChangeReporter    com.twilio.voice.quickstart          D  Compat change id reported: 263076149; UID 10320; state: ENABLED
2024-12-08 15:28:38.824  9721-9721  tvo.webrtc.Logging      com.twilio.voice.quickstart          I  WebRtcAudioManagerExternal: Sample rate is set to 48000 Hz
2024-12-08 15:28:38.825  9721-9721  tvo.webrtc.Logging      com.twilio.voice.quickstart          I  WebRtcAudioManagerExternal: Sample rate is set to 48000 Hz
2024-12-08 15:28:38.825  9721-9721  tvo.webrtc.Logging      com.twilio.voice.quickstart          I  JavaAudioDeviceModule: createAudioDeviceModule
2024-12-08 15:28:38.825  9721-9721  tvo.webrtc.Logging      com.twilio.voice.quickstart          I  JavaAudioDeviceModule: HW NS will be used.
2024-12-08 15:28:38.826  9721-9721  tvo.webrtc.Logging      com.twilio.voice.quickstart          I  JavaAudioDeviceModule: HW AEC will be used.
2024-12-08 15:28:38.829  9721-9721  tvo.webrtc.Logging      com.twilio.voice.quickstart          I  WebRtcAudioEffectsExternal: ctor@[name=main, id=2]
2024-12-08 15:28:38.829  9721-9721  tvo.webrtc.Logging      com.twilio.voice.quickstart          I  WebRtcAudioRecordExternal: ctor@[name=main, id=2]
2024-12-08 15:28:38.832  9721-9721  tvo.webrtc.Logging      com.twilio.voice.quickstart          I  WebRtcAudioTrackExternal: ctor@[name=main, id=2]
2024-12-08 15:28:38.839  9721-9782  tvo.webrtc.Logging      com.twilio.voice.quickstart          I  WebRtcAudioRecordExternal: enableBuiltInAEC(true)
2024-12-08 15:28:38.840  9721-9782  tvo.webrtc.Logging      com.twilio.voice.quickstart          I  WebRtcAudioEffectsExternal: setAEC(true)
2024-12-08 15:28:38.841  9721-9782  tvo.webrtc.Logging      com.twilio.voice.quickstart          I  WebRtcAudioRecordExternal: enableBuiltInNS(true)
2024-12-08 15:28:38.841  9721-9782  tvo.webrtc.Logging      com.twilio.voice.quickstart          I  WebRtcAudioEffectsExternal: setNS(true)
2024-12-08 15:28:38.898  9721-9721  CompatChangeReporter    com.twilio.voice.quickstart          D  Compat change id reported: 247079863; UID 10320; state: ENABLED
2024-12-08 15:28:38.915  9721-9721  Twilio:cla...lang.Class com.twilio.voice.quickstart          I  [Platform] {"timestamp_ms":1733664518886,"client_name":"android-66f51abf1c16e9b65bfd4bcd","call_sid":"CA9e1f665c43423c143d42e50248023478","message_sid":"RU89a2f0942d960484dc56c49317472153","sdk_version":"6.7.1","platform":"android","direction":"INCOMING","selected_region":"gll","logger_type":"default","preflight":false}
2024-12-08 15:28:38.984  9721-9815  TrafficStats            com.twilio.voice.quickstart          D  tagSocket(119) with statsTag=0x3e8, statsUid=-1
2024-12-08 15:28:38.996  9721-9721  Twilio:cla...lang.Class com.twilio.voice.quickstart          I  [Platform] {"timestamp_ms":1733664518972,"client_name":"android-66f51abf1c16e9b65bfd4bcd","call_sid":"CA9e1f665c43423c143d42e50248023478","message_sid":"RU89a2f0942d960484dc56c49317472153","sdk_version":"6.7.1","platform":"android","direction":"INCOMING","selected_region":"gll","logger_type":"default","preflight":false}
2024-12-08 15:28:39.046  9721-9845  TrafficStats            com.twilio.voice.quickstart          D  tagSocket(120) with statsTag=0x3e8, statsUid=-1
2024-12-08 15:28:39.054  9721-9721  IncomingCa...ionService com.twilio.voice.quickstart          I  setCallInProgressNotification - app is NOT visible.
2024-12-08 15:28:39.072  9721-9721  AndroidRuntime          com.twilio.voice.quickstart          D  Shutting down VM
2024-12-08 15:28:39.092  9721-9721  AndroidRuntime          com.twilio.voice.quickstart          E  FATAL EXCEPTION: main
                                                                                                    Process: com.twilio.voice.quickstart, PID: 9721
                                                                                                    java.lang.RuntimeException: Unable to start service com.twilio.voice.quickstart.IncomingCallNotificationService@d14746c with Intent { act=ACTION_INCOMING_CALL cmp=com.twilio.voice.quickstart/.IncomingCallNotificationService (has extras) }: java.lang.SecurityException: Starting FGS with type microphone callerApp=ProcessRecord{aa37518 9721:com.twilio.voice.quickstart/u0a320} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_MICROPHONE] any of the permissions allOf=false [android.permission.CAPTURE_AUDIO_HOTWORD, android.permission.CAPTURE_AUDIO_OUTPUT, android.permission.CAPTURE_MEDIA_OUTPUT, android.permission.CAPTURE_TUNER_AUDIO_INPUT, android.permission.CAPTURE_VOICE_COMMUNICATION_OUTPUT, android.permission.RECORD_AUDIO]  and the app must be in the eligible state/exemptions to access the foreground only permission
                                                                                                    	at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5165)
                                                                                                    	at android.app.ActivityThread.-$$Nest$mhandleServiceArgs(Unknown Source:0)
                                                                                                    	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2469)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:107)
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:232)
                                                                                                    	at android.os.Looper.loop(Looper.java:317)
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:8705)
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:886)
                                                                                                    Caused by: java.lang.SecurityException: Starting FGS with type microphone callerApp=ProcessRecord{aa37518 9721:com.twilio.voice.quickstart/u0a320} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_MICROPHONE] any of the permissions allOf=false [android.permission.CAPTURE_AUDIO_HOTWORD, android.permission.CAPTURE_AUDIO_OUTPUT, android.permission.CAPTURE_MEDIA_OUTPUT, android.permission.CAPTURE_TUNER_AUDIO_INPUT, android.permission.CAPTURE_VOICE_COMMUNICATION_OUTPUT, android.permission.RECORD_AUDIO]  and the app must be in the eligible state/exemptions to access the foreground only permission
                                                                                                    	at android.os.Parcel.createExceptionOrNull(Parcel.java:3242)
                                                                                                    	at android.os.Parcel.createException(Parcel.java:3226)
                                                                                                    	at android.os.Parcel.readException(Parcel.java:3209)
                                                                                                    	at android.os.Parcel.readException(Parcel.java:3151)
                                                                                                    	at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:7193)
                                                                                                    	at android.app.Service.startForeground(Service.java:863)
                                                                                                    	at com.twilio.voice.quickstart.IncomingCallNotificationService.startForegroundService(IncomingCallNotificationService.java:245)
                                                                                                    	at com.twilio.voice.quickstart.IncomingCallNotificationService.setCallInProgressNotification(IncomingCallNotificationService.java:239)
                                                                                                    	at com.twilio.voice.quickstart.IncomingCallNotificationService.handleIncomingCall(IncomingCallNotificationService.java:197)
                                                                                                    	at com.twilio.voice.quickstart.IncomingCallNotificationService.onStartCommand(IncomingCallNotificationService.java:66)
                                                                                                    	at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5147)
                                                                                                    	... 9 more
                                                                                                    Caused by: android.os.RemoteException: Remote stack trace:
                                                                                                    	at com.android.server.am.ActiveServices.validateForegroundServiceType(ActiveServices.java:2905)
                                                                                                    	at com.android.server.am.ActiveServices.setServiceForegroundInnerLocked(ActiveServices.java:2589)
                                                                                                    	at com.android.server.am.ActiveServices.setServiceForegroundLocked(ActiveServices.java:1843)
                                                                                                    	at com.android.server.am.ActivityManagerService.setServiceForeground(ActivityManagerService.java:14095)
                                                                                                    	at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:3594)
                                                                                                    
2024-12-08 15:28:39.111  9721-9721  Process                 com.twilio.voice.quickstart          I  Sending signal. PID: 9721 SIG: 9
---------------------------- PROCESS ENDED (9721) for package com.twilio.voice.quickstart ----------------------------
2024-12-08 15:28:40.624  9876-9876  AndroidRuntime          zygote64                             E  FATAL EXCEPTION: main
                                                                                                    Process: com.twilio.voice.quickstart, PID: 9876
                                                                                                    java.lang.RuntimeException: Unable to start service com.twilio.voice.quickstart.IncomingCallNotificationService@2eeaf3f with Intent { act=ACTION_INCOMING_CALL cmp=com.twilio.voice.quickstart/.IncomingCallNotificationService (has extras) }: java.lang.SecurityException: Starting FGS with type microphone callerApp=ProcessRecord{3e159a 9876:com.twilio.voice.quickstart/u0a320} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_MICROPHONE] any of the permissions allOf=false [android.permission.CAPTURE_AUDIO_HOTWORD, android.permission.CAPTURE_AUDIO_OUTPUT, android.permission.CAPTURE_MEDIA_OUTPUT, android.permission.CAPTURE_TUNER_AUDIO_INPUT, android.permission.CAPTURE_VOICE_COMMUNICATION_OUTPUT, android.permission.RECORD_AUDIO]  and the app must be in the eligible state/exemptions to access the foreground only permission
                                                                                                    	at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5165)
                                                                                                    	at android.app.ActivityThread.-$$Nest$mhandleServiceArgs(Unknown Source:0)
                                                                                                    	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2469)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:107)
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:232)
                                                                                                    	at android.os.Looper.loop(Looper.java:317)
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:8705)
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:886)
                                                                                                    Caused by: java.lang.SecurityException: Starting FGS with type microphone callerApp=ProcessRecord{3e159a 9876:com.twilio.voice.quickstart/u0a320} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_MICROPHONE] any of the permissions allOf=false [android.permission.CAPTURE_AUDIO_HOTWORD, android.permission.CAPTURE_AUDIO_OUTPUT, android.permission.CAPTURE_MEDIA_OUTPUT, android.permission.CAPTURE_TUNER_AUDIO_INPUT, android.permission.CAPTURE_VOICE_COMMUNICATION_OUTPUT, android.permission.RECORD_AUDIO]  and the app must be in the eligible state/exemptions to access the foreground only permission
                                                                                                    	at android.os.Parcel.createExceptionOrNull(Parcel.java:3242)
                                                                                                    	at android.os.Parcel.createException(Parcel.java:3226)
                                                                                                    	at android.os.Parcel.readException(Parcel.java:3209)
                                                                                                    	at android.os.Parcel.readException(Parcel.java:3151)
                                                                                                    	at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:7193)
                                                                                                    	at android.app.Service.startForeground(Service.java:863)
                                                                                                    	at com.twilio.voice.quickstart.IncomingCallNotificationService.startForegroundService(IncomingCallNotificationService.java:245)
                                                                                                    	at com.twilio.voice.quickstart.IncomingCallNotificationService.setCallInProgressNotification(IncomingCallNotificationService.java:239)
                                                                                                    	at com.twilio.voice.quickstart.IncomingCallNotificationService.handleIncomingCall(IncomingCallNotificationService.java:197)
                                                                                                    	at com.twilio.voice.quickstart.IncomingCallNotificationService.onStartCommand(IncomingCallNotificationService.java:66)
                                                                                                    	at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5147)
                                                                                                    	... 9 more
                                                                                                    Caused by: android.os.RemoteException: Remote stack trace:
                                                                                                    	at com.android.server.am.ActiveServices.validateForegroundServiceType(ActiveServices.java:2905)
                                                                                                    	at com.android.server.am.ActiveServices.setServiceForegroundInnerLocked(ActiveServices.java:2589)
                                                                                                    	at com.android.server.am.ActiveServices.setServiceForegroundLocked(ActiveServices.java:1843)
                                                                                                    	at com.android.server.am.ActivityManagerService.setServiceForeground(ActivityManagerService.java:14095)
                                                                                                    	at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:3594)
                                                                                                    
---------------------------- PROCESS STARTED (9876) for package com.twilio.voice.quickstart ----------------------------

Additional info

App works fine when targetSdk is 33

'targetSdk' : 34,

Voice Android SDK

Voice Android SDK version 6.7.1

OS Version

Android 15 (Android security update November 5, 2024)

Device Model

Pixel 6 Pro

@ajitfoneapp
Copy link

ajitfoneapp commented Dec 10, 2024

Based on the crash log, it appears that a foreground service type and permission are required when the application is not running in the background.

You need to declare the appropriate foreground service type in the manifest file using:
android:foregroundServiceType="phoneCall"
or based on your service type
android:foregroundServiceType="microphone"

<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE_PHONE_CALL" />

I believe this should resolve the issue.

@afalls-twilio
Copy link
Contributor

afalls-twilio commented Dec 10, 2024

slavchev Thank you for reporting the issue. We fixed this issue several months ago. The changes necessary are here

Also, did you happen to deny microphone permissions before attempting to receive an incoming call?

@slavchev
Copy link
Author

slavchev commented Dec 11, 2024

@afalls-twilio I use the app from the commit I cited in the issue description 6ae5839 I see there are some new commits since yesterday but I don't think they are related to the issue.

Also, did you happen to deny microphone permissions before attempting to receive an incoming call?

That was the first thing to check and the permission is granted. It seems the issue is because the microphone permission is "while-in-use" one. At least this is my understanding after reading https://developer.android.com/develop/background-work/services/fgs/restrictions-bg-start

Here is an excerpt from Android official documentation

Restrictions on starting foreground services that need while-in-use permissions

On Android 14 (API level 34) or higher, there are special situations to be aware of if you're starting
a foreground service that needs while-in-use permissions.

If your app targets Android 14 or higher, the operating system checks when you create a foreground
service to make sure your app has all the appropriate permissions for that service type. For example,
when you create a foreground service of type microphone, the operating system verifies that your app
currently has the RECORD_AUDIO permission. If you don't have that permission, the system throws a SecurityException.

For while-in-use permissions, this causes a potential problem. If your app has a while-in-use permission,
it only has that permission while it's in the foreground. This means if your app is in the background, and it
tries to create a foreground service of type camera, location, or microphone, the system sees that your app
doesn't currently have the required permissions, and it throws a SecurityException.

And it seems that the problem is described in the last sentence. I still reproduce the bug with the current master branch. Can you please confirm it works for you?

@afalls-twilio
Copy link
Contributor

@slavchev yup, was able to reproduce the issue. We will fix the issue, thank you.

@afalls-twilio
Copy link
Contributor

@slavchev This should be fixed with the latest version of the quickstart, just merged in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants