twilio / voice-quickstart-android

Quickstart app for the Voice Android SDK
https://www.twilio.com/docs/api/voice-sdk/android/getting-started
MIT License
184 stars 140 forks source link

Not able to receive incoming call in OS 12 #513

Closed Vivektilva closed 2 years ago

Vivektilva commented 2 years ago

When we receive call with callInvite.accept(IncomingActivity.this,callListener);

and in listener onConnectFailure is being called when i call above function and callException.getExplanation() = Unable to answer because the call has ended. callException.getMessage() = Call Cancelled.

Note : when I run the same code with OS 11 (targetSdkVersion 30) it is working properly but when I run this code with (targetSdkVersion 31) above erroe comes

I am using 'com.twilio:voice-android:5.6.3'

kbagchiGWC commented 2 years ago

@Vivektilva

Can you provide device logs?

Vivektilva commented 2 years ago

2022-03-24 15:21:31.706 11170-11170/com.callhippo.bueno.callhippo E/Dialer_Fragment: auto_switched_countryname:United States:+18474162145:tech twilio 2022-03-24 15:21:32.861 11170-11170/com.callhippo.bueno.callhippo D/twilio_login: Successfully registered FCM

2022-03-24 15:21:51.421 11170-11170/com.callhippo.bueno.callhippo E/incom_IncomingActivity: Call going to Receive_twilio: 2022-03-24 15:21:51.459 11170-11170/com.callhippo.bueno.callhippo E/twilio_incom_incomingcall: onConnectFailure Unable to answer because the call has ended. 2022-03-24 15:21:51.459 11170-11170/com.callhippo.bueno.callhippo E/twilio_incom_incomingcall: onConnectFailure_code Call Cancelled 2022-03-24 15:21:51.459 11170-11170/com.callhippo.bueno.callhippo E/twilio_incom_incomingcall: onConnectFailure_code1 null

Vivektilva commented 2 years ago

@kbagchiGWC

Vivektilva commented 2 years ago

Description In android OS version 12 , when incoming call notification comes and we receive calls from "ACCEPT" button from the notification , it gets disconnected in a second ,

It happens when we receive calls after 1st attempt , in first attempt , call is being received successfully but once app is closed and we reopen the app and try to get incoming call and click on "accept " , call don't get connected and in listener onConnectFailure event is being called instead of onConnected.

Steps to Reproduce Start the app and register for incoming calls keep app open in foreground or background Receive an incoming call Click on "Accept " button in notification .

Code I don't know which code is relevant to this issue, we got a lot of code that may be related, if you'll ask for specific snippet - I'll be happy to provide 🙏

Expected Behavior Call should get connected and onConnected listener should be called.

Actual Behavior

Listener onConnectFailure is being called and callException.getExplanation() = "Unable to answer because the call has ended."

Reproduces How Often Always

Voice Android SDK 6.0.2

OS Version Android 12 - so far, this only happened with Android 12

Device Model Google Pixel 6 (reproduced with other devices with Android 12 as well)

Attaching twilio debug log . 2022-03-24 18:05:18.010 21169-21169/com.callhippo.bueno.callhippo E/twilio_login: provider_twilio:: 2022-03-24 18:05:29.140 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): API Call create 2022-03-24 18:05:29.140 21169-21169/com.callhippo.bueno.callhippo I/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): Creating peer connection signaling thread ... 2022-03-24 18:05:29.140 21169-21169/com.callhippo.bueno.callhippo I/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): Creating peer connection worker thread ... 2022-03-24 18:05:29.140 21169-21169/com.callhippo.bueno.callhippo I/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): Creating peer connection networking thread ... 2022-03-24 18:05:29.140 21169-21169/com.callhippo.bueno.callhippo I/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): Creating media engine ... 2022-03-24 18:05:29.141 21169-21169/com.callhippo.bueno.callhippo I/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): Done creating media engine. 2022-03-24 18:05:29.141 21169-21169/com.callhippo.bueno.callhippo I/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): Creating peer connection factory ... 2022-03-24 18:05:29.142 21169-21169/com.callhippo.bueno.callhippo I/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): Done creating peer connection factory. 2022-03-24 18:05:29.143 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): API Call handleMessage 2022-03-24 18:05:29.144 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): Selected edge - roaming Selected region - gll 2022-03-24 18:05:29.144 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): Initializing SIP stack ... 2022-03-24 18:05:29.148 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): Adding IPv4/IPv6 TLS transports ... 2022-03-24 18:05:29.148 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): Selected edge - roaming Selected region - gll 2022-03-24 18:05:29.148 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): Selected edge - roaming Selected region - gll 2022-03-24 18:05:29.149 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): Initializing DUM ... 2022-03-24 18:05:29.149 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): Starting SIP stack thread ... 2022-03-24 18:05:29.149 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): Starting DUM thread ... 2022-03-24 18:05:29.150 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): API Call getSignalingThread 2022-03-24 18:05:29.150 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): API Call getNetworkingThread 2022-03-24 18:05:29.150 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): <0xb40000782bdf3190> initializeThreadCheckers 2022-03-24 18:05:29.150 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): <0xb40000782bdf3190> initialize 2022-03-24 18:05:29.150 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): <0xb4000077dbcee390> Starting the Network Manager 2022-03-24 18:05:29.150 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): <0xb4000077bbd115d0> RtcMonitor 2022-03-24 18:05:29.150 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): API Call getFrom 2022-03-24 18:05:29.150 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): listen 2022-03-24 18:05:29.150 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): API Call getFrom 2022-03-24 18:05:29.150 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): API Call getTo 2022-03-24 18:05:29.150 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): API Call getCallSid 2022-03-24 18:05:29.150 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): API Call getFrom 2022-03-24 18:05:29.150 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): API Call getTo 2022-03-24 18:05:29.150 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): API Call getCallSid 2022-03-24 18:05:29.151 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): ListenerImpl 2022-03-24 18:05:29.151 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): Started listen no-op timer for 40000 ms 2022-03-24 18:05:29.151 21169-21777/com.callhippo.bueno.callhippo D/Twilio: [Core](MediaFactoryImpl::signaling 0x0xb40000779bd2b6c0): twilio::voice::AsyncDnsResolver::AsyncDnsResolver(std::weak_ptr) 2022-03-24 18:05:29.151 21169-21777/com.callhippo.bueno.callhippo D/Twilio: [Core](MediaFactoryImpl::signaling 0x0xb40000779bd2b6c0): AsyncDnsResolver resolving hostname = chunderm.gll.twilio.com 2022-03-24 18:05:29.182 21169-21777/com.callhippo.bueno.callhippo D/Twilio: [Core](MediaFactoryImpl::signaling 0x0xb40000779bd2b6c0): AsyncDnsResolver Resolved ip_addr = 54.169.66.211, error = 0 2022-03-24 18:05:29.183 21169-21777/com.callhippo.bueno.callhippo D/Twilio: [Core](MediaFactoryImpl::signaling 0x0xb40000779bd2b6c0): virtual void twilio::voice::SipClient::onResolveResult(twilio::voice::AsyncDnsResolver *, std::string, int) 2022-03-24 18:05:29.183 21169-21777/com.callhippo.bueno.callhippo D/Twilio: [Core](MediaFactoryImpl::signaling 0x0xb40000779bd2b6c0): onResolveResult for listen, hostname = sip:chunderm.gll.twilio.com:443;transport=tls, ip_addr = 54.169.66.211 2022-03-24 18:05:29.183 21169-21777/com.callhippo.bueno.callhippo D/Twilio: [Core](MediaFactoryImpl::signaling 0x0xb40000779bd2b6c0): New SipCall ..., this=0xb40000783be1f530, handle = 1 2022-03-24 18:05:29.183 21169-21777/com.callhippo.bueno.callhippo I/Twilio: [Core](MediaFactoryImpl::signaling 0x0xb40000779bd2b6c0): Setting outbound proxy to: sip:54.169.66.211:443;transport=tls 2022-03-24 18:05:30.085 21169-21784/com.callhippo.bueno.callhippo D/Twilio: Core: mapToSipCall handle id is 1 2022-03-24 18:05:30.085 21169-21784/com.callhippo.bueno.callhippo D/Twilio: Core: casting handle id 1 to SipCall 2022-03-24 18:05:30.086 21169-21784/com.callhippo.bueno.callhippo D/Twilio: Core: onNewSession: SIP/2.0 180 Ringing Via: SIP/2.0/TLS 192.168.1.x;received=106.201.242.4;branch=z9hG4bK-524287-1---6b7b4269e9dbfec9;rport=48890 Record-Route: <sip:172.19.73.x:10193;r2=on;transport=udp;ftag=9ecd2b02;lr> Record-Route: <sip:54.169.66.211:443;r2=on;transport=tls;ftag=9ecd2b02;lr> Contact: To: <sip:chunderm.gll.twilio.com:443;transport=tls>;tag=72038386_c3356d0b_6ea137b7-8d50-427d-b530-15c1e9248de0 From: sip:VoiceSDK@chunderm.gll.twilio.com;tag=9ecd2b02 Call-ID: QnMriJgAhxybQvlnfxCCfA.. CSeq: 1 INVITE Server: Twilio X-Twilio-CallSid: CA14e2787b727948768842533bfcb37e33 X-Twilio-EdgeHost: chunderm0.sg1.twilio.com X-Twilio-EdgeRegion: sg1 X-Twilio-Zone: ASIAPAC_SINGAPORE Content-Length: 0 2022-03-24 18:05:30.086 21169-21784/com.callhippo.bueno.callhippo D/Twilio: Core: onNewCall 2022-03-24 18:05:30.086 21169-21784/com.callhippo.bueno.callhippo D/Twilio: Core: mapToSipCall handle id is 1 2022-03-24 18:05:30.086 21169-21784/com.callhippo.bueno.callhippo D/Twilio: Core: casting handle id 1 to SipCall 2022-03-24 18:05:30.087 21169-21784/com.callhippo.bueno.callhippo D/Twilio: Core: onProvisional: SIP/2.0 180 Ringing Via: SIP/2.0/TLS 192.168.1.x;received=106.201.242.4;branch=z9hG4bK-524287-1---6b7b4269e9dbfec9;rport=48890 Record-Route: <sip:172.19.73.x:10193;r2=on;transport=udp;ftag=9ecd2b02;lr> Record-Route: <sip:54.169.66.211:443;r2=on;transport=tls;ftag=9ecd2b02;lr> Contact: To: <sip:chunderm.gll.twilio.com:443;transport=tls>;tag=72038386_c3356d0b_6ea137b7-8d50-427d-b530-15c1e9248de0 From: sip:VoiceSDK@chunderm.gll.twilio.com;tag=9ecd2b02 Call-ID: QnMriJgAhxybQvlnfxCCfA.. CSeq: 1 INVITE Server: Twilio X-Twilio-CallSid: CA14e2787b727948768842533bfcb37e33 X-Twilio-EdgeHost: chunderm0.sg1.twilio.com X-Twilio-EdgeRegion: sg1 X-Twilio-Zone: ASIAPAC_SINGAPORE Content-Length: 0 2022-03-24 18:05:30.087 21169-21784/com.callhippo.bueno.callhippo D/Twilio: Core: onRinging 2022-03-24 18:05:32.007 21169-21169/com.callhippo.bueno.callhippo E/incom_IncomingActivity: Call going to Receive_twilio: 2022-03-24 18:05:33.690 21169-21169/com.callhippo.bueno.callhippo E/twilio_login: provider_twilio:: 2022-03-24 18:05:53.950 21169-21784/com.callhippo.bueno.callhippo D/Twilio: Core: mapToSipCall handle id is 1 2022-03-24 18:05:53.950 21169-21784/com.callhippo.bueno.callhippo D/Twilio: Core: casting handle id 1 to SipCall 2022-03-24 18:05:53.950 21169-21784/com.callhippo.bueno.callhippo D/Twilio: Core: virtual void twilio::voice::SipCall::onFailure(resip::ClientInviteSessionHandle, const resip::SipMessage &) 2022-03-24 18:05:53.951 21169-21784/com.callhippo.bueno.callhippo D/Twilio: Core: Received incoming SIP message from infra: SIP/2.0 410 Gone Via: SIP/2.0/TLS 192.168.1.x;received=106.201.242.4;branch=z9hG4bK-524287-1---6b7b4269e9dbfec9;rport=48890 Contact: To: <sip:chunderm.gll.twilio.com:443;transport=tls>;tag=72038386_c3356d0b_6ea137b7-8d50-427d-b530-15c1e9248de0 From: sip:VoiceSDK@chunderm.gll.twilio.com;tag=9ecd2b02 Call-ID: QnMriJgAhxybQvlnfxCCfA.. CSeq: 1 INVITE Server: Twilio X-Twilio-CallSid: CA14e2787b727948768842533bfcb37e33 X-Twilio-EdgeHost: chunderm0.sg1.twilio.com X-Twilio-EdgeRegion: sg1 X-Twilio-Zone: ASIAPAC_SINGAPORE Content-Length: 0 2022-03-24 18:05:53.951 21169-21784/com.callhippo.bueno.callhippo D/Twilio: Core: onFailure 2022-03-24 18:05:53.951 21169-21784/com.callhippo.bueno.callhippo D/Twilio: Core: mapToSipCall handle id is 1 2022-03-24 18:05:53.951 21169-21784/com.callhippo.bueno.callhippo D/Twilio: Core: casting handle id 1 to SipCall 2022-03-24 18:05:53.951 21169-21784/com.callhippo.bueno.callhippo D/Twilio: Core: onTerminated: reason 0, this=0xb40000783be1f530 2022-03-24 18:05:53.952 21169-21784/com.callhippo.bueno.callhippo D/Twilio: Core: Received incoming SIP message from infra: SIP/2.0 410 Gone Via: SIP/2.0/TLS 192.168.1.x;received=106.201.242.4;branch=z9hG4bK-524287-1---6b7b4269e9dbfec9;rport=48890 Contact: To: <sip:chunderm.gll.twilio.com:443;transport=tls>;tag=72038386_c3356d0b_6ea137b7-8d50-427d-b530-15c1e9248de0 From: sip:VoiceSDK@chunderm.gll.twilio.com;tag=9ecd2b02 Call-ID: QnMriJgAhxybQvlnfxCCfA.. CSeq: 1 INVITE Server: Twilio X-Twilio-CallSid: CA14e2787b727948768842533bfcb37e33 X-Twilio-EdgeHost: chunderm0.sg1.twilio.com X-Twilio-EdgeRegion: sg1 X-Twilio-Zone: ASIAPAC_SINGAPORE Content-Length: 0 2022-03-24 18:05:53.952 21169-21784/com.callhippo.bueno.callhippo D/Twilio: Core: onTerminated 2022-03-24 18:05:53.953 21169-21777/com.callhippo.bueno.callhippo D/Twilio: [Core](MediaFactoryImpl::signaling 0x0xb40000779bd2b6c0): raiseCancelCallInvite 2022-03-24 18:05:53.953 21169-21784/com.callhippo.bueno.callhippo D/Twilio: Core: ~SipCall(): 0xb40000783be1f530 2022-03-24 18:05:54.014 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): ~CallInviteImpl 2022-03-24 18:05:54.014 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): <0xb40000782bdf3190> willDestroy 2022-03-24 18:05:54.014 21169-21777/com.callhippo.bueno.callhippo D/Twilio: [Core](MediaFactoryImpl::signaling 0x0xb40000779bd2b6c0): Stopping the Network Manager 2022-03-24 18:05:54.014 21169-21777/com.callhippo.bueno.callhippo D/Twilio: [Core](MediaFactoryImpl::signaling 0x0xb40000779bd2b6c0): <0xb4000077dbcee390> ~NetworkMonitor 2022-03-24 18:05:54.014 21169-21777/com.callhippo.bueno.callhippo D/Twilio: [Core](MediaFactoryImpl::signaling 0x0xb40000779bd2b6c0): <0xb4000077bbd115d0> ~RtcMonitor 2022-03-24 18:05:54.015 21169-21777/com.callhippo.bueno.callhippo D/Twilio: [Core](MediaFactoryImpl::signaling 0x0xb40000779bd2b6c0): ~SignalingClient 2022-03-24 18:05:54.015 21169-21777/com.callhippo.bueno.callhippo D/Twilio: [Core](MediaFactoryImpl::signaling 0x0xb40000779bd2b6c0): Shutting down DUM thread ... 2022-03-24 18:05:54.954 21169-21777/com.callhippo.bueno.callhippo D/Twilio: [Core](MediaFactoryImpl::signaling 0x0xb40000779bd2b6c0): Shutting down SIP stack thread ... 2022-03-24 18:05:54.955 21169-21777/com.callhippo.bueno.callhippo D/Twilio: [Core](MediaFactoryImpl::signaling 0x0xb40000779bd2b6c0): Deleting previously cached listen set ids 2022-03-24 18:05:54.955 21169-21777/com.callhippo.bueno.callhippo D/Twilio: [Core](MediaFactoryImpl::signaling 0x0xb40000779bd2b6c0): virtual twilio::voice::AsyncDnsResolver::~AsyncDnsResolver() 2022-03-24 18:05:54.962 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): <0xb40000782bdf3190> Completing pending and in-progress AsyncInvoker calls. 2022-03-24 18:05:54.963 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): API Call getWorkerThread 2022-03-24 18:05:54.963 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): Synchronize the worker thread 2022-03-24 18:05:54.964 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): <0xb40000782bdf3190> ~CallImpl 2022-03-24 18:05:54.964 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): ~ListenerImpl 2022-03-24 18:05:54.964 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): Clearing pending calls from async_invoker. 2022-03-24 18:05:54.964 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): Waiting for any in-progress calls in async_invoker to complete. 2022-03-24 18:05:54.965 21169-21169/com.callhippo.bueno.callhippo D/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): ~CallerInfoImpl 2022-03-24 18:05:54.966 21169-21169/com.callhippo.bueno.callhippo I/Twilio: [Core](Thread 0x0xb4000077ebcdb4f0): ~AudioMediaFactoryImpl

Vivektilva commented 2 years ago

when i try to accept the call using callInvite1.accept(IncomingActivity.this,callListener); I am getting following in twilio debug logs :

com.callhippo.bueno.callhippo D/InternalCall: Attempted to accept CallInvite that was previously accepted,rejected, or cancelled.

kbagchiGWC commented 2 years ago

This is the event we see at the Voice Insights for the call sid CA14e2787b727948768842533bfcb37e33

Screen Shot 2022-03-24 at 4 28 34 PM

Call was received on two devices and then got cancelled (timeout)after ~25 seconds. If attempt to accept was after the call got cancelled - onConnectFailure() is expected.

We looked at the TwiML used for this call:

<Response><Dial callerId="+1xxxxxxxxxx" answerOnBridge="true" action="https://call.callhippo.com/api/v2/smartaction/twilio" timeLimit="5400" timeout="20" record="do-not-record" recordingTrack="both" recordingStatusCallback="https://call.callhippo.com/......">
........

Can you increase the timeout value to a higher value, i.e. 40 and retry?

Vivektilva commented 2 years ago

we fixed above issue , now our endpoint is logged into one device only . While debugging more on this I found that call sid which i am getting in firebase notification for incoming call and call sid on which i try to accept call is different , while i call callinvite.accept() function , previous call's callinvite is going and that is the reason for that error of com.callhippo.bueno.callhippo D/InternalCall: Attempted to accept CallInvite that was previously accepted,rejected, or cancelled.

I am passing call invite from firebase service to incoming call activity via intent , can you please check that code and let me know if i am missing something .

Firebase code

if(remoteMessage.getData().containsKey("twi_account_sid"))
                {
                    Voice.handleMessage(context,data,new MessageListener() {
                        @Override
                        public void onCallInvite(@NonNull CallInvite callInvite) {
                            Log.e(TAG,"onCallInvite:"+callInvite.getCallSid());
                            String from=callInvite.getFrom();
                            Log.e(TAG,"tw_from:"+from);

            sendNotification_ongoing_call_twilio(displayNum,"Incoming call",callInvite);

                        }

                        @Override
                        public void onCancelledCallInvite(@NonNull CancelledCallInvite cancelledCallInvite, @Nullable CallException callException) {
                            Log.e(TAG,"onCancelledCallInvite"+cancelledCallInvite.getCallSid());

                            try
                            {
                                String ac_sid=sharedPreferences.getString("tw_activecall_sid","");
                                Log.e(TAG,"onCancelledCallInvite_activecall"+ac_sid);

                                Log.e(TAG,"call_cancelled_notify");

                                if(ac_sid.equalsIgnoreCase(""))
                                {
                                    Intent intent = new Intent(tw_NOTIFICATION);
                                    intent.putExtra("tw_actionname", "tw_call_cancelled");
                                    sendBroadcast(intent);

                                    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                                    if(notificationManager!=null){notificationManager.cancel(410);}

                                   try{mRingTone_10.stop();}catch(Exception e){}
                                }

                            }
                            catch (Exception e){}

                        }

                    });

                }
            }
            catch (Exception e){}

        }

    void sendNotification_ongoing_call_twilio(String messageBody,String title,CallInvite callInvite)
    {

    Intent intent2 = new Intent(getApplicationContext(),IncomingActivity.class);

        intent2.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent2.putExtra("tw_actionname", "tw_call_incoming_accept");
        intent2.putExtra("tw_callInvite", callInvite);

        intent2.putExtra("Incomingnumber", callNumber);
        intent2.putExtra("Incoming_uid", "");

        intent2.putExtra("is_accept","true");

        Log.e(TAG,"call_accepted_button_clicked0");

        PendingIntent pIntent2 = PendingIntent.getActivity(this, 201, intent2, PendingIntent.FLAG_IMMUTABLE);

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID2, "My Notifications2", NotificationManager.IMPORTANCE_HIGH);

            AudioAttributes attributes = new AudioAttributes.Builder()
                    .setUsage(AudioAttributes.USAGE_NOTIFICATION)
                    .build();

            // Configure the notification channel.
            notificationChannel.setDescription("Call notification");
            notificationChannel.enableLights(true);
            notificationChannel.setLightColor(Color.RED);
            notificationChannel.setVibrationPattern(new long[]{0, 1000, 500, 1000});
            notificationChannel.enableVibration(true);
            notificationManager.createNotificationChannel(notificationChannel);
        }
        Bitmap icon = BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_launcher_v2);
        androidx.core.app.NotificationCompat.Builder builder = new androidx.core.app.NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID2)
//                .setVibrate(new long[]{0, 100, 100, 100, 100, 100})
//                .setSound(uri)
//                .setSound(null)
                .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE))
                .setSmallIcon(R.drawable.usernumber_logo_v2)
                .setContentTitle(title)
                .setContentText(messageBody)
//                .setContentIntent(pIntent)
                .setLargeIcon(icon)
                .setPriority(NotificationCompat.PRIORITY_HIGH)
                .setCategory(NotificationCompat.CATEGORY_CALL)
//                .addAction(R.drawable.icon_call_frwd1, "pick up",
//                        pIntent)
                .addAction(R.color.colorPrimary, "DISMISS", pIntent3)
                .addAction(R.color.colorPrimary, "ACCEPT", pIntent2)
                .setAutoCancel(true)
                .setFullScreenIntent(pIntent,true);
        notificationManager.notify(notification_id, builder.build());

    }
}

On incomingActivity.java i am doing following callInvite1=intentcall.getParcelableExtra("tw_callInvite"); callInvite1.accept(IncomingActivity.this,callListener);

Note : it was working until i set PendingIntent.FLAG_IMMUTABLE , previously it was PendingIntent.FLAG_UPDATE_CURRENT

Vivektilva commented 2 years ago

we fixed above issue , now our endpoint is logged into one device only . While debugging more on this I found that call sid which i am getting in firebase notification for incoming call and call sid on which i try to accept call is different , while i call callinvite.accept() function , previous call's callinvite is going and that is the reason for that error of com.callhippo.bueno.callhippo D/InternalCall: Attempted to accept CallInvite that was previously accepted,rejected, or cancelled.

I am passing call invite from firebase service to incoming call activity via intent , can you please check that code and let me know if i am missing something .

Firebase code

if(remoteMessage.getData().containsKey("twi_account_sid")) { Voice.handleMessage(context,data,new MessageListener() { @Override public void onCallInvite(@NonNull CallInvite callInvite) { Log.e(TAG,"onCallInvite:"+callInvite.getCallSid()); String from=callInvite.getFrom(); Log.e(TAG,"tw_from:"+from);

        sendNotification_ongoing_call_twilio(displayNum,"Incoming call",callInvite);

                    }

                    @Override
                    public void onCancelledCallInvite(@NonNull CancelledCallInvite cancelledCallInvite, @Nullable CallException callException) {
                        Log.e(TAG,"onCancelledCallInvite"+cancelledCallInvite.getCallSid());

                        try
                        {
                            String ac_sid=sharedPreferences.getString("tw_activecall_sid","");
                            Log.e(TAG,"onCancelledCallInvite_activecall"+ac_sid);

                            Log.e(TAG,"call_cancelled_notify");

                            if(ac_sid.equalsIgnoreCase(""))
                            {
                                Intent intent = new Intent(tw_NOTIFICATION);
                                intent.putExtra("tw_actionname", "tw_call_cancelled");
                                sendBroadcast(intent);

                                NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                                if(notificationManager!=null){notificationManager.cancel(410);}

                               try{mRingTone_10.stop();}catch(Exception e){}
                            }

                        }
                        catch (Exception e){}

                    }

                });

            }
        }
        catch (Exception e){}

    }

void sendNotification_ongoing_call_twilio(String messageBody,String title,CallInvite callInvite)
{

Intent intent2 = new Intent(getApplicationContext(),IncomingActivity.class);

    intent2.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent2.putExtra("tw_actionname", "tw_call_incoming_accept");
    intent2.putExtra("tw_callInvite", callInvite);

    intent2.putExtra("Incomingnumber", callNumber);
    intent2.putExtra("Incoming_uid", "");

    intent2.putExtra("is_accept","true");

    Log.e(TAG,"call_accepted_button_clicked0");

    PendingIntent pIntent2 = PendingIntent.getActivity(this, 201, intent2, PendingIntent.FLAG_IMMUTABLE);

NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID2, "My Notifications2", NotificationManager.IMPORTANCE_HIGH);

        AudioAttributes attributes = new AudioAttributes.Builder()
                .setUsage(AudioAttributes.USAGE_NOTIFICATION)
                .build();

        // Configure the notification channel.
        notificationChannel.setDescription("Call notification");
        notificationChannel.enableLights(true);
        notificationChannel.setLightColor(Color.RED);
        notificationChannel.setVibrationPattern(new long[]{0, 1000, 500, 1000});
        notificationChannel.enableVibration(true);
        notificationManager.createNotificationChannel(notificationChannel);
    }
    Bitmap icon = BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_launcher_v2);
    androidx.core.app.NotificationCompat.Builder builder = new androidx.core.app.NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID2)

// .setVibrate(new long[]{0, 100, 100, 100, 100, 100}) // .setSound(uri) // .setSound(null) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE)) .setSmallIcon(R.drawable.usernumber_logo_v2) .setContentTitle(title) .setContentText(messageBody) // .setContentIntent(pIntent) .setLargeIcon(icon) .setPriority(NotificationCompat.PRIORITY_HIGH) .setCategory(NotificationCompat.CATEGORY_CALL) // .addAction(R.drawable.icon_call_frwd1, "pick up", // pIntent) .addAction(R.color.colorPrimary, "DISMISS", pIntent3) .addAction(R.color.colorPrimary, "ACCEPT", pIntent2) .setAutoCancel(true) .setFullScreenIntent(pIntent,true); notificationManager.notify(notification_id, builder.build());

}

}

On incomingActivity.java i am doing following callInvite1=intentcall.getParcelableExtra("tw_callInvite"); callInvite1.accept(IncomingActivity.this,callListener);

Note : it was working until i set PendingIntent.FLAG_IMMUTABLE , previously it was PendingIntent.FLAG_UPDATE_CURRENT

sonubabu7373 commented 2 years ago

https://www.flybuy.com/android-12-pendingintent-mutability-and-geofences refer this, and make FLAG_MUTABLE

kbagchiGWC commented 2 years ago

Closing the issue as it was answered by @sonubabu7373. Thanks.