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

Incoming call does not show the dialog #592

Closed amritashan closed 4 months ago

amritashan commented 4 months ago

Description

The voice-android-quickstart app does not show an incoming call dialog.

Steps to Reproduce

  1. Clone the latest code (commit b8bc933b740c9bace75469521b7a5958c2a13445 at the time of writing)
  2. Paste your access token in VoiceActivity.java
  3. Place your google-services.json file in the app root.
  4. Run/Debug the app on an emulator. I did it on Pixel 3a API 34 Extension Level 7 x86_64 (also tried a physical Pixel 8 Pro)
  5. Keep the quickstart app in the foreground and from another device place a call to this quickstart app

Expected Behavior

You should receive:

  1. A push notification from Firebase for the incoming call
  2. A dialog in the app showing the incoming call (as mentioned in the Readme - step 8)

Actual Behavior

Only a push notification is received

Reproduces How Often

100%

Versions

All relevant version information for the issue.

Voice Android SDK

6.5.0

OS Version

Android 14

Device Model

Pixel 3a, Pixel 8 Pro

amritashan commented 4 months ago

I changed the method VoiceFirebaseMessagingService.handleInvite() to add a sendBroadcast() and it works now:

    private void handleInvite(CallInvite callInvite, int notificationId) {
        Intent intent = new Intent(this, IncomingCallNotificationService.class);
        intent.setAction(Constants.ACTION_INCOMING_CALL);
        intent.putExtra(Constants.INCOMING_CALL_NOTIFICATION_ID, notificationId);
        intent.putExtra(Constants.INCOMING_CALL_INVITE, callInvite);

        startService(intent);

        Log.d(TAG, "Sending broadcast for incoming call");
        LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
    }

However, that raises more questions for me (sorry I am a newbie)

Why does handleCanceledCallInvite() not require a similar sendBroadcast() call and yet the ACTION_CANCEL_CALL intent is received in the VoiceBroadcastReceiver, but the ACTION_INCOMING_CALL is not without the broadcast? Is some other part of the code supposed to send a broadcast for the incoming call?

If this fix is right, i would be happy to send a pull request, but this solution is confusing.

amritashan commented 4 months ago

After a little more research, I made a few more changes:

  1. LocalBroadcastManager.getInstance(this).sendBroadcast(intent); need not be called in VoiceFirebaseMessagingService.
  2. Since startService(intent) already sends the intent to IncomingCallNotificationService, the broadcast needs to be done from IncomingCallNotificationService.handleIncomingCall()

So, here are the changes, I would do:

VoiceFirebaseMessagingService.handleInvite()

IncomingCallNotificationService.onStartCommand()

                case Constants.ACTION_INCOMING_CALL:
                    handleIncomingCall(intent);
                    break;

IncomingCallNotificationService.handleIncomingCall()

private void handleIncomingCall(Intent intent) {
        CallInvite incomingCallInvite = intent.getParcelableExtra(Constants.INCOMING_CALL_INVITE);
        int notificationId = intent.getIntExtra(Constants.INCOMING_CALL_NOTIFICATION_ID, 0);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            setCallInProgressNotification(incomingCallInvite, notificationId);
        }

        Log.d(TAG, "Sending broadcast for incoming call");
        LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
    }
afalls-twilio commented 4 months ago

amritashan Thank you for filing this and discovering the issue. We have reported it with our team and it will be getting looked into.

ocarevs commented 4 months ago

@amritashan We've merged the fix now incoming call dialog should show as expected.