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

[FIREBASE CLOUD MESSAGEING ]: Issue: Conflict Between ABTO SIP SDK Method Channel and Firebase Background Message Handling #13543

Open
1 task done
dmsherazi opened this issue Oct 23, 2024 · 11 comments
Labels
blocked: customer-response Waiting for customer response, e.g. more information was requested. platform: android Issues / PRs which are specifically for Android. plugin: messaging resolution: needs-repro This issue could not be reproduced or needs an up to date reproduction on latest FlutterFire plugin. type: bug Something isn't working

Comments

@dmsherazi
Copy link

Is there an existing issue for this?

  • I have searched the existing issues.

Which plugins are affected?

Messaging

Which platforms are affected?

Android

Description

I am using the ABTO SIP SDK in my Flutter app, and I've implemented a SipChannel using MethodChannel for communication between Flutter and native code.

class SipChannel extends ValueNotifier<void> {
  static const CHANNEL_NAME = "com.voip.sdk.channel";

  MethodChannel? platform;
  Object? arguments;
  String methodName = "";

  SipChannel() : super('') {
    platform = const MethodChannel(CHANNEL_NAME);
    platform?.setMethodCallHandler(handleMethod);
  }

  Future<dynamic> handleMethod(MethodCall call) async {
    debugPrint("SipChannel handleMethod " + call.arguments.toString());
    methodName = call.method;
    arguments = call.arguments;
    notifyListeners();
  }
}

However, when I enable Firebase background message handling with the following line:

FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
the method channel's handleMethod is not triggered for SIP registration events, even though the native side logs the events as expected.

For example, in SipWrapper.java, the logs indicate that the events are occurring, but the method channel call does not reach the Flutter side:

phone.setRegistrationStateListener(new OnRegistrationListener() {
    @Override
    public void onRegistered(long p0) {
        Log.d("DEBUG_SIP_WRAPPER", "onRegistered");
        channel.invokeMethod(RESULT_REGISTERED, null);
    }

    @Override
    public void onUnRegistered(long p0) {
        Log.d("DEBUG_SIP_WRAPPER", "onUnRegistered");
        channel.invokeMethod(RESULT_UNREGISTERED, null);
    }

    @Override
    public void onRegistrationFailed(long p0, int p1, String p2) {
        if (p1 == 100) return;
        Log.d("DEBUG_SIP_WRAPPER", "onRegistrationFailed: " + p0 + ", " + p1 + ", " + p2);
        channel.invokeMethod(RESULT_REG_FAILED, null);
    }
});

If I comment out the Firebase background message handler line, the method channel works as expected, and the SIP SDK events are passed correctly to Flutter.

Expected Behavior:
The handleMethod should be invoked even when Firebase background message handling is enabled.

Actual Behavior:
When Firebase background message handling is enabled, handleMethod is not triggered, even though native logs indicate that the SIP registration events are occurring.

Reproducing the issue

Steps to Reproduce:

  • Enable Firebase background message handling in the app using:
    FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);

  • Set up the MethodChannel in Flutter as shown in the code above.

  • Register the SIP SDK and observe that handleMethod is not triggered despite native logs confirming the events.

  • Comment out the Firebase background message handler line and observe that the method channel works as expected.

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.24.3, on macOS 15.0.1 24A348 darwin-arm64, locale en-OM)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 16.0)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.1)
[✓] Connected device (5 available)
[✓] Network resources

Firebase Core version

2.24.2

Flutter Version

3.24.3

Relevant Log Output

No response

Flutter dependencies

Expand Flutter dependencies snippet
Replace this line with the contents of your `flutter pub deps -- --style=compact`.

Additional context and comments

No response

@dmsherazi dmsherazi added Needs Attention This issue needs maintainer attention. type: bug Something isn't working labels Oct 23, 2024
@SelaseKay SelaseKay added plugin: messaging platform: android Issues / PRs which are specifically for Android. labels Oct 23, 2024
@SelaseKay
Copy link
Contributor

Hi @dmsherazi, thanks for the report. What version of firebase_messaging are you using?

@SelaseKay SelaseKay added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed Needs Attention This issue needs maintainer attention. labels Oct 23, 2024
@dmsherazi
Copy link
Author

dmsherazi commented Oct 23, 2024

SipWrapper.java.txt
sip_wrapper.dart.txt

Hi @dmsherazi, thanks for the report. What version of firebase_messaging are you using?

I update to latest versions but still having the issue . I will attach the relevant SIpwarapper files here as well. Its worth noting that the issue affects the android app and not the iOS app generated by flutter

  firebase_messaging: ^15.1.3
  firebase_core: ^3.6.0
  firebase_analytics: ^11.3.3
 flutter pub deps -- --style=compact
Dart SDK 3.5.3
Flutter SDK 3.24.3

dependencies:
- abto_voip_sdk 0.0.1 [flutter]
- cached_network_image 3.4.1 [cached_network_image_platform_interface cached_network_image_web flutter flutter_cache_manager octo_image]
- carousel_slider 5.0.0 [flutter]
- circular_menu 2.0.1 [flutter]
- contacts_service 0.6.3 [flutter collection quiver]
- cupertino_icons 1.0.8
- curved_nav_bar 0.0.2 [flutter]
- dio 5.7.0 [async http_parser meta path dio_web_adapter]
- firebase_analytics 11.3.3 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter]
- firebase_core 3.6.0 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_messaging 15.1.3 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta]
- flex_color_picker 2.6.1 [flex_seed_scheme flutter]
- flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine]
- flutter_contacts 1.1.9+2 [flutter]
- flutter_keyboard_visibility 6.0.0 [meta flutter_keyboard_visibility_platform_interface flutter_keyboard_visibility_linux flutter_keyboard_visibility_macos flutter_keyboard_visibility_web flutter_keyboard_visibility_windows flutter]
- flutter_local_notifications 17.2.3 [clock flutter flutter_local_notifications_linux flutter_local_notifications_platform_interface timezone]
- flutter_slidable 3.1.1 [flutter]
- flutter_speed_dial 7.0.0 [flutter]
- flutter_staggered_animations 1.1.1 [flutter]
- fluttertoast 8.2.8 [flutter flutter_web_plugins web]
- font_awesome_flutter 10.7.0 [flutter]
- get 4.6.6 [flutter]
- gradient_widgets 0.6.0 [flutter]
- hive 2.2.3 [meta crypto]
- hive_flutter 1.1.0 [flutter hive path_provider path]
- http 1.2.2 [async http_parser meta web]
- image_picker 1.1.2 [flutter image_picker_android image_picker_for_web image_picker_ios image_picker_linux image_picker_macos image_picker_platform_interface image_picker_windows]
- just_the_tooltip 0.0.12 [flutter]
- logger 2.4.0
- lottie 3.1.2 [archive flutter http path vector_math]
- mime 1.0.6
- mobile_scanner 5.2.3 [flutter flutter_web_plugins plugin_platform_interface web]
- mqtt_client 10.2.0 [typed_data event_bus path universal_html crypto meta]
- numberpicker 2.1.2 [flutter infinite_listview]
- numeric_keyboard 1.1.0 [flutter]
- overlay_support 2.1.0 [flutter async]
- package_info_plus 8.1.0 [ffi flutter flutter_web_plugins http meta path package_info_plus_platform_interface web win32 clock]
- path_provider 2.1.4 [flutter path_provider_android path_provider_foundation path_provider_linux path_provider_platform_interface path_provider_windows]
- permission_handler 11.3.1 [flutter meta permission_handler_android permission_handler_apple permission_handler_html permission_handler_windows permission_handler_platform_interface]
- phone_numbers_parser 8.3.0 [meta]
- photo_view 0.14.0 [flutter]
- pin_code_fields 8.0.1 [flutter]
- provider 6.1.2 [collection flutter nested]
- receive_sharing_intent 1.8.1 [flutter plugin_platform_interface]
- responsive_framework 0.2.0 [flutter collection]
- rxdart 0.27.7
- salomon_bottom_bar 3.3.2 [flutter]
- shared_preferences 2.3.2 [flutter shared_preferences_android shared_preferences_foundation shared_preferences_linux shared_preferences_platform_interface shared_preferences_web shared_preferences_windows]
- sleek_circular_slider 2.0.1 [flutter]
- smooth_page_indicator 1.2.0+3 [flutter]
- sms_autofill 2.4.0 [pin_input_text_field flutter]
- spannable_grid 0.3.0 [flutter]
- sqflite 2.4.0 [flutter sqflite_android sqflite_darwin sqflite_platform_interface sqflite_common path]
- syncfusion_flutter_sliders 25.2.7 [flutter intl syncfusion_flutter_core]
- time_picker_widget 1.0.0+10 [flutter]
- top_snackbar_flutter 3.1.0 [flutter]
- url_launcher 6.3.1 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows]
- vector_math 2.1.4

dev dependencies:
- flutter_lints 5.0.0 [lints]
- flutter_test 0.0.0 [flutter test_api matcher path fake_async clock stack_trace vector_math leak_tracker_flutter_testing async boolean_selector characters collection leak_tracker leak_tracker_testing material_color_utilities meta source_span stream_channel string_scanner term_glyph vm_service]

transitive dependencies:
- _flutterfire_internals 1.3.44 [collection firebase_core firebase_core_platform_interface flutter meta]
- archive 3.6.1 [crypto path]
- args 2.5.0
- async 2.11.0 [collection meta]
- boolean_selector 2.1.1 [source_span string_scanner]
- cached_network_image_platform_interface 4.1.1 [flutter flutter_cache_manager]
- cached_network_image_web 1.3.1 [cached_network_image_platform_interface flutter flutter_cache_manager web]
- characters 1.3.0
- charcode 1.3.1
- clock 1.1.1
- collection 1.18.0
- cross_file 0.3.4+2 [meta web]
- crypto 3.0.5 [typed_data]
- csslib 1.0.0 [source_span]
- dbus 0.7.10 [args ffi meta xml]
- dio_web_adapter 2.0.0 [dio http_parser meta web]
- event_bus 2.0.1
- fake_async 1.3.1 [clock collection]
- ffi 2.1.3
- file 7.0.0 [meta path]
- file_selector_linux 0.9.2+1 [cross_file file_selector_platform_interface flutter]
- file_selector_macos 0.9.4+1 [cross_file file_selector_platform_interface flutter]
- file_selector_platform_interface 2.6.2 [cross_file flutter http plugin_platform_interface]
- file_selector_windows 0.9.3+3 [cross_file file_selector_platform_interface flutter]
- firebase_analytics_platform_interface 4.2.5 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_analytics_web 0.5.10+2 [_flutterfire_internals firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins]
- firebase_core_platform_interface 5.3.0 [collection flutter flutter_test meta plugin_platform_interface]
- firebase_core_web 2.18.1 [firebase_core_platform_interface flutter flutter_web_plugins meta web]
- firebase_messaging_platform_interface 4.5.46 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_web 3.9.2 [_flutterfire_internals firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins meta web]
- fixnum 1.1.0
- flex_seed_scheme 1.5.0 [collection flutter meta]
- flutter_cache_manager 3.4.1 [clock collection file flutter http path path_provider rxdart sqflite uuid]
- flutter_keyboard_visibility_linux 1.0.0 [flutter_keyboard_visibility_platform_interface flutter]
- flutter_keyboard_visibility_macos 1.0.0 [flutter_keyboard_visibility_platform_interface flutter]
- flutter_keyboard_visibility_platform_interface 2.0.0 [flutter meta plugin_platform_interface]
- flutter_keyboard_visibility_web 2.0.0 [flutter_keyboard_visibility_platform_interface flutter_web_plugins flutter]
- flutter_keyboard_visibility_windows 1.0.0 [flutter_keyboard_visibility_platform_interface flutter]
- flutter_local_notifications_linux 4.0.1 [dbus ffi flutter flutter_local_notifications_platform_interface path xdg_directories]
- flutter_local_notifications_platform_interface 7.2.0 [flutter plugin_platform_interface]
- flutter_plugin_android_lifecycle 2.0.22 [flutter]
- flutter_web_plugins 0.0.0 [flutter characters collection material_color_utilities meta vector_math]
- html 0.15.4 [csslib source_span]
- http_parser 4.0.2 [collection source_span string_scanner typed_data]
- image_picker_android 0.8.12+13 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface]
- image_picker_for_web 3.0.6 [flutter flutter_web_plugins image_picker_platform_interface mime web]
- image_picker_ios 0.8.12 [flutter image_picker_platform_interface]
- image_picker_linux 0.2.1+1 [file_selector_linux file_selector_platform_interface flutter image_picker_platform_interface]
- image_picker_macos 0.2.1+1 [file_selector_macos file_selector_platform_interface flutter image_picker_platform_interface]
- image_picker_platform_interface 2.10.0 [cross_file flutter http plugin_platform_interface]
- image_picker_windows 0.2.1+1 [file_selector_platform_interface file_selector_windows flutter image_picker_platform_interface]
- infinite_listview 1.1.0 [flutter]
- intl 0.19.0 [clock meta path]
- leak_tracker 10.0.5 [clock collection meta path vm_service]
- leak_tracker_flutter_testing 3.0.5 [flutter leak_tracker leak_tracker_testing matcher meta]
- leak_tracker_testing 3.0.1 [leak_tracker matcher meta]
- lints 5.0.0
- matcher 0.12.16+1 [async meta stack_trace term_glyph test_api]
- material_color_utilities 0.11.1 [collection]
- meta 1.15.0
- nested 1.0.0 [flutter]
- octo_image 2.1.0 [flutter]
- package_info_plus_platform_interface 3.0.1 [flutter meta plugin_platform_interface]
- path 1.9.0
- path_provider_android 2.2.10 [flutter path_provider_platform_interface]
- path_provider_foundation 2.4.0 [flutter path_provider_platform_interface]
- path_provider_linux 2.2.1 [ffi flutter path path_provider_platform_interface xdg_directories]
- path_provider_platform_interface 2.1.2 [flutter platform plugin_platform_interface]
- path_provider_windows 2.3.0 [ffi flutter path path_provider_platform_interface]
- permission_handler_android 12.0.12 [flutter permission_handler_platform_interface]
- permission_handler_apple 9.4.5 [flutter permission_handler_platform_interface]
- permission_handler_html 0.1.3+2 [flutter flutter_web_plugins permission_handler_platform_interface web]
- permission_handler_platform_interface 4.2.3 [flutter meta plugin_platform_interface]
- permission_handler_windows 0.2.1 [flutter permission_handler_platform_interface]
- petitparser 6.0.2 [meta]
- pin_input_text_field 4.5.2 [flutter]
- platform 3.1.5
- plugin_platform_interface 2.1.8 [meta]
- quiver 3.2.2 [matcher]
- shared_preferences_android 2.3.2 [flutter shared_preferences_platform_interface]
- shared_preferences_foundation 2.5.2 [flutter shared_preferences_platform_interface]
- shared_preferences_linux 2.4.1 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface]
- shared_preferences_platform_interface 2.4.1 [flutter plugin_platform_interface]
- shared_preferences_web 2.4.2 [flutter flutter_web_plugins shared_preferences_platform_interface web]
- shared_preferences_windows 2.4.1 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface]
- sky_engine 0.0.99
- source_span 1.10.0 [collection path term_glyph]
- sprintf 7.0.0
- sqflite_android 2.4.0 [flutter sqflite_common path sqflite_platform_interface]
- sqflite_common 2.5.4+5 [synchronized path meta]
- sqflite_darwin 2.4.1-1 [flutter sqflite_platform_interface meta sqflite_common path]
- sqflite_platform_interface 2.4.0 [flutter platform sqflite_common plugin_platform_interface meta]
- stack_trace 1.11.1 [path]
- stream_channel 2.1.2 [async]
- string_scanner 1.2.0 [source_span]
- syncfusion_flutter_core 25.2.7 [vector_math flutter]
- synchronized 3.3.0+3
- term_glyph 1.2.1
- test_api 0.7.2 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph]
- timezone 0.9.4 [path]
- typed_data 1.3.2 [collection]
- universal_html 2.2.4 [async csslib charcode collection html meta source_span typed_data universal_io]
- universal_io 2.2.2 [collection meta typed_data]
- url_launcher_android 6.3.10 [flutter url_launcher_platform_interface]
- url_launcher_ios 6.3.1 [flutter url_launcher_platform_interface]
- url_launcher_linux 3.2.0 [flutter url_launcher_platform_interface]
- url_launcher_macos 3.2.1 [flutter url_launcher_platform_interface]
- url_launcher_platform_interface 2.3.2 [flutter plugin_platform_interface]
- url_launcher_web 2.3.3 [flutter flutter_web_plugins url_launcher_platform_interface web]
- url_launcher_windows 3.1.2 [flutter url_launcher_platform_interface]
- uuid 4.5.1 [crypto sprintf meta fixnum]
- vm_service 14.2.5
- web 1.1.0
- win32 5.5.4 [ffi]
- xdg_directories 1.0.4 [meta path]
- xml 6.5.0 [collection meta petitparser

@google-oss-bot google-oss-bot added Needs Attention This issue needs maintainer attention. and removed blocked: customer-response Waiting for customer response, e.g. more information was requested. labels Oct 23, 2024
@dmsherazi
Copy link
Author

I tried to get some help from chatgpt and here is what it says

To debug and resolve the issue where your SIP SDK's Java code (SipWrapper.java) is unable to send listener events back to Flutter when Firebase background messaging is enabled, I'll analyze the interaction between the Dart and Java files you've provided. I'll look at potential conflicts or limitations in using method channels with Firebase messaging in the background.

I'll start by checking the contents of the SipWrapper.java and sip_wrapper.dart files to identify any possible causes. Let me review them.

From the content of your Java and Dart files, here's what I see:

Java (SipWrapper.java):

The SIP registration event listeners (OnRegistrationListener) are properly set up to log events like onRegistered, onUnregistered, and onRegistrationFailed to the native Android logs.
Each event calls the method channel to invoke the corresponding result back to Flutter using channel.invokeMethod().
Dart (sip_wrapper.dart):

The Dart code defines a SipWrapper class with various listeners (e.g., onRegistered, onUnregistered, onRegistrationFailed). These listeners are supposed to receive callbacks from the native code via the platform channel.
Problem:
When FirebaseMessaging.onBackgroundMessage is enabled, Firebase Messaging takes control of the background thread, which can block method channels. Since the SIP SDK events are being sent through method channels, this might explain why the native Java code logs the events (e.g., onRegistered), but they are not being delivered to the Dart side.

@SelaseKay
Copy link
Contributor

SelaseKay commented Oct 24, 2024

Kindly provide a complete minimal repo reproducing this issue.

@SelaseKay SelaseKay added the blocked: customer-response Waiting for customer response, e.g. more information was requested. label Oct 24, 2024
@usama-sherazi
Copy link

usama-sherazi commented Oct 24, 2024

I’ve attached a link of git file containing an example app where I’m experiencing the same issue with Firebase. Please open the LINK file and run the example app in abto_sdk (https://github.com/usama-sherazi/Example/tree/master/example) app to replicate the problem.

@usama-sherazi
Copy link

@SelaseKay Hi , did you get time to check the issue?

@SelaseKay
Copy link
Contributor

Hi @usama-sherazi, I've checked out the repo. I'm unable to register into the app. Can you provide some assistance?

@babayanta1994
Copy link

I also have the same problem please help me solve this

@babayanta1994
Copy link

Hi @usama-sherazi, I've checked out the repo. I'm unable to register into the app. Can you provide some assistance?

you can use any sip credentials from your working sip server (for example asterisk)

@usama-sherazi
Copy link

usama-sherazi commented Nov 3, 2024

user is 123
password xxx123
and the domain koffice.zapto.org

if you disable the line for background firebase messaging callback , you can register

@russellwheatley
Copy link
Member

If you want @SelaseKay to look into this, I suggest making a repo with the bare minimum code to reproduce this. The only thing that should need to be changed is the google-service.json file for firebase configuration. Other than that, it should be a case of commenting in/commenting out the background message handler to reproduce.

@russellwheatley russellwheatley added resolution: needs-repro This issue could not be reproduced or needs an up to date reproduction on latest FlutterFire plugin. and removed Needs Attention This issue needs maintainer attention. labels Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked: customer-response Waiting for customer response, e.g. more information was requested. platform: android Issues / PRs which are specifically for Android. plugin: messaging resolution: needs-repro This issue could not be reproduced or needs an up to date reproduction on latest FlutterFire plugin. type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants