v3rm0n / intercom_flutter

Flutter wrapper for Intercom libraries
95 stars 141 forks source link

[7.6.0]: Android: Exception After Background Push Received #270

Closed devalp-pro closed 1 year ago

devalp-pro commented 2 years ago

When a new user registers and tries to access the intercom it's registered the first time and displays the chat window perfectly. But, When the user starts sending messages it's worked after that user closes the application. And the user gets notified by the intercom user and a push notification got on clicked push notification application getting crashed. After this crash user never opens messanger screen. The user got this crashed every time.

My Code

Future<void> loginIntercom() async {
    String? isUserLoggedIn = await _localStorage.readSecureData(LocalStorage.keyIsIntercomUserLoggedIn);
    if (isUserLoggedIn == "true") {
      await Intercom.instance.displayMessenger();
    } else {
      try {
        WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
          await _showLoadingDialog();
        });
        final key = utf8.encode(Platform.isAndroid
            ? IntercomConst.instance.androidSecretKey
            : Platform.isIOS
                ? IntercomConst.instance.iOsSecretKey
                : "");
        final bytes = utf8.encode(loggedInUserInfo.value.mail ?? "");

        final hmacSha256 = Hmac(sha256, key);
        final digest = hmacSha256.convert(bytes);
        print("User Hash ==> ${digest.toString()}");
        await Intercom.instance.setUserHash(digest.toString());

        Intercom.instance.loginIdentifiedUser(
            email: loggedInUserInfo.value.mail ?? "",
            statusCallback: IntercomStatusCallback(
              onSuccess: () async {
                await _localStorage.writeSecureData(LocalStorage.keyIsIntercomUserLoggedIn, "true");
                await Intercom.instance.updateUser(userId: loggedInUserInfo.value.id ?? "", name: loggedInUserInfo.value.displayName ?? "");
                Get.back();
                await Intercom.instance.displayMessenger();
              },
              onFailure: (error) {
                Get.back();
                Intercom.instance.logout();
                if (kDebugMode) {
                  print("Intercom Exception ==> $error");
                }
              },
            ));
      } catch (ex) {
        if (kDebugMode) {
          print("Intercom Exception ==> $ex");
        }
        Intercom.instance.logout();
        Get.back();
      }
    }
  }

Exception


D/ConnectivityManager(17921): StackLog: [android.net.ConnectivityManager.sendRequestForNetwork(ConnectivityManager.java:4186)] [android.net.ConnectivityManager.sendRequestForNetwork(ConnectivityManager.java:4228)] [android.net.ConnectivityManager.registerNetworkCallback(ConnectivityManager.java:4610)] [android.net.ConnectivityManager.registerNetworkCallback(ConnectivityManager.java:4580)] [coil.network.RealNetworkObserver.<init>(NetworkObserver.kt:88)] [coil.network.NetworkObserverKt.NetworkObserver(NetworkObserver.kt:33)] [coil.util.SystemCallbacks.<init>(SystemCallbacks.kt:31)] [coil.RealImageLoader.<init>(RealImageLoader.kt:78)] [coil.ImageLoader$Builder.build(ImageLoader.kt:517)] [io.intercom.android.sdk.utilities.IntercomCoilKt.getImageLoader(IntercomCoil.kt:51)] [io.intercom.android.sdk.utilities.IntercomCoilKt.loadIntercomImage(IntercomCoil.kt:19)] [io.intercom.android.sdk.utilities.AvatarUtils.createAvatar(AvatarUtils.java:69)] [io.intercom.android.sdk.utilities.AvatarUtils.loadAvatarIntoView(AvatarUtils.java:58)] [io.intercom.android.sdk.overlay.StackableSnippet.setViewData(StackableSnippet.java:92)] [io.intercom.android.sdk.overlay.StackableSnippet.display(StackableSnippet.java:49)] [io.intercom.android.sdk.overlay.InAppNotificationPresenter.addNewNotifications(InAppNotificationPresenter.java:184)] [io.intercom.android.sdk.overlay.InAppNotificationPresenter.displayNotificationsAfterAttach(InAppNotificationPresenter.java:90)] [io.intercom.android.sdk.overlay.InAppNotificationPresenter$1.run(InAppNotificationPresenter.java:79)] [io.intercom.android.sdk.utilities.ViewUtils$1.onGlobalLayout(ViewUtils.java:30)] [android.view.ViewTreeObserver.dispatchOnGlobalLayout(ViewTreeObserver.java:1080)] [android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:4098)] [android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2924)] [android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:10513)] [android.view.Choreographer$CallbackRecord.run(Choreographer.java:1108)] [android.view.Choreographer.doCallbacks(Choreographer.java:866)] [android.view.Choreographer.doFrame(Choreographer.java:797)] [android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1092)]
D/AndroidRuntime(17921): Shutting down VM
E/AndroidRuntime(17921): FATAL EXCEPTION: main
E/AndroidRuntime(17921): Process: com.alliancetek.dvrc, PID: 17921
E/AndroidRuntime(17921): java.lang.IllegalStateException: ViewTreeLifecycleOwner not found from android.widget.FrameLayout{3a06f66 V.E...... ......ID 0,0-1080,2274 #7f080190 app:id/intercom_overlay_root}
E/AndroidRuntime(17921):    at androidx.compose.ui.platform.WindowRecomposer_androidKt.createLifecycleAwareWindowRecomposer(WindowRecomposer.android.kt:349)
E/AndroidRuntime(17921):    at androidx.compose.ui.platform.WindowRecomposer_androidKt.createLifecycleAwareWindowRecomposer$default(WindowRecomposer.android.kt:324)
E/AndroidRuntime(17921):    at androidx.compose.ui.platform.WindowRecomposerFactory$Companion$LifecycleAware$1.createRecomposer(WindowRecomposer.android.kt:168)
E/AndroidRuntime(17921):    at androidx.compose.ui.platform.WindowRecomposerPolicy.createAndInstallWindowRecomposer$ui_release(WindowRecomposer.android.kt:224)
E/AndroidRuntime(17921):    at androidx.compose.ui.platform.WindowRecomposer_androidKt.getWindowRecomposer(WindowRecomposer.android.kt:299)
E/AndroidRuntime(17921):    at androidx.compose.ui.platform.AbstractComposeView.resolveParentCompositionContext(ComposeView.android.kt:242)
E/AndroidRuntime(17921):    at androidx.compose.ui.platform.AbstractComposeView.ensureCompositionCreated(ComposeView.android.kt:249)
E/AndroidRuntime(17921):    at androidx.compose.ui.platform.AbstractComposeView.createComposition(ComposeView.android.kt:194)
E/AndroidRuntime(17921):    at androidx.compose.ui.platform.ComposeView.setContent(ComposeView.android.kt:420)
E/AndroidRuntime(17921):    at io.intercom.android.sdk.m5.notification.InAppNotificationCardKt.addTicketHeaderToCompose(InAppNotificationCard.kt:55)
E/AndroidRuntime(17921):    at io.intercom.android.sdk.overlay.StackableSnippet.setViewData(StackableSnippet.java:101)
E/AndroidRuntime(17921):    at io.intercom.android.sdk.overlay.StackableSnippet.display(StackableSnippet.java:49)
E/AndroidRuntime(17921):    at io.intercom.android.sdk.overlay.InAppNotificationPresenter.addNewNotifications(InAppNotificationPresenter.java:184)
E/AndroidRuntime(17921):    at io.intercom.android.sdk.overlay.InAppNotificationPresenter.displayNotificationsAfterAttach(InAppNotificationPresenter.java:90)
E/AndroidRuntime(17921):    at io.intercom.android.sdk.overlay.InAppNotificationPresenter$1.run(InAppNotificationPresenter.java:79)
E/AndroidRuntime(17921):    at io.intercom.android.sdk.utilities.ViewUtils$1.onGlobalLayout(ViewUtils.java:30)
E/AndroidRuntime(17921):    at android.view.ViewTreeObserver.dispatchOnGlobalLayout(ViewTreeObserver.java:1080)
E/AndroidRuntime(17921):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:4098)
E/AndroidRuntime(17921):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2924)
E/AndroidRuntime(17921):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:10513)
E/AndroidRuntime(17921):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1108)
E/AndroidRuntime(17921):    at android.view.Choreographer.doCallbacks(Choreographer.java:866)
E/AndroidRuntime(17921):    at android.view.Choreographer.doFrame(Choreographer.java:797)
E/AndroidRuntime(17921):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1092)
E/AndroidRuntime(17921):    at android.os.Handler.handleCallback(Handler.java:938)
E/AndroidRuntime(17921):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(17921):    at android.os.Looper.loopOnce(Looper.java:226)
E/AndroidRuntime(17921):    at android.os.Looper.loop(Looper.java:313)
E/AndroidRuntime(17921):    at android.app.ActivityThread.main(ActivityThread.java:8751)
E/AndroidRuntime(17921):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(17921):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
E/AndroidRuntime(17921):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
I/Process (17921): Sending signal. PID: 17921 SIG: 9
Lost connection to device.
Felipe-N0bre commented 1 year ago

Up

Zazo032 commented 1 year ago

Could you provide the intercom version you're using, the output from flutter doctor and a minimal sample code to try to reproduce it?

deepak786 commented 1 year ago

I tested this with the latest version: intercom_flutter: 7.6.0.

It also crashed when you tap on the notification. Working fine with version intercom_flutter: 7.5.0. Need to report this issue to Intercom.

E/AndroidRuntime( 6131): java.lang.IllegalStateException: ViewTreeLifecycleOwner not found from android.widget.FrameLayout{8e33f2a V.E...... ......ID 0,0-1080,2205 #7f0801aa app:id/intercom_overlay_root}
E/AndroidRuntime( 6131):    at androidx.compose.ui.platform.WindowRecomposer_androidKt.createLifecycleAwareWindowRecomposer(WindowRecomposer.android.kt:349)
E/AndroidRuntime( 6131):    at androidx.compose.ui.platform.WindowRecomposer_androidKt.createLifecycleAwareWindowRecomposer$default(WindowRecomposer.android.kt:324)
E/AndroidRuntime( 6131):    at androidx.compose.ui.platform.WindowRecomposerFactory$Companion$LifecycleAware$1.createRecomposer(WindowRecomposer.android.kt:168)
E/AndroidRuntime( 6131):    at androidx.compose.ui.platform.WindowRecomposerPolicy.createAndInstallWindowRecomposer$ui_release(WindowRecomposer.android.kt:224)
E/AndroidRuntime( 6131):    at androidx.compose.ui.platform.WindowRecomposer_androidKt.getWindowRecomposer(WindowRecomposer.android.kt:299)
E/AndroidRuntime( 6131):    at androidx.compose.ui.platform.AbstractComposeView.resolveParentCompositionContext(ComposeView.android.kt:242)
E/AndroidRuntime( 6131):    at androidx.compose.ui.platform.AbstractComposeView.ensureCompositionCreated(ComposeView.android.kt:249)
E/AndroidRuntime( 6131):    at androidx.compose.ui.platform.AbstractComposeView.createComposition(ComposeView.android.kt:194)
E/AndroidRuntime( 6131):    at androidx.compose.ui.platform.ComposeView.setContent(ComposeView.android.kt:420)
E/AndroidRuntime( 6131):    at io.intercom.android.sdk.m5.notification.InAppNotificationCardKt.addTicketHeaderToCompose(InAppNotificationCard.kt:55)
E/AndroidRuntime( 6131):    at io.intercom.android.sdk.overlay.ChatNotification.populateViewsWithData(ChatNotification.java:111)
E/AndroidRuntime( 6131):    at io.intercom.android.sdk.overlay.ChatNotification.display(ChatNotification.java:71)
E/AndroidRuntime( 6131):    at io.intercom.android.sdk.overlay.InAppNotificationPresenter.addNewNotifications(InAppNotificationPresenter.java:184)
E/AndroidRuntime( 6131):    at io.intercom.android.sdk.overlay.InAppNotificationPresenter.displayNotificationsAfterAttach(InAppNotificationPresenter.java:90)
E/AndroidRuntime( 6131):    at io.intercom.android.sdk.overlay.InAppNotificationPresenter$1.run(InAppNotificationPresenter.java:79)
E/AndroidRuntime( 6131):    at io.intercom.android.sdk.utilities.ViewUtils$1.onGlobalLayout(ViewUtils.java:30)
E/AndroidRuntime( 6131):    at android.view.ViewTreeObserver.dispatchOnGlobalLayout(ViewTreeObserver.java:1061)
E/AndroidRuntime( 6131):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3269)
E/AndroidRuntime( 6131):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2182)
E/AndroidRuntime( 6131):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8730)
E/AndroidRuntime( 6131):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1352)
E/AndroidRuntime( 6131):    at android.view.Choreographer.doCallbacks(Choreographer.java:1149)
E/AndroidRuntime( 6131):    at android.view.Choreographer.doFrame(Choreographer.java:1049)
E/AndroidRuntime( 6131):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1333)
E/AndroidRuntime( 6131):    at android.os.Handler.handleCallback(Handler.java:938)
E/AndroidRuntime( 6131):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 6131):    at android.os.Looper.loop(Looper.java:233)
E/AndroidRuntime( 6131):    at android.app.ActivityThread.main(ActivityThread.java:8010)
E/AndroidRuntime( 6131):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 6131):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631)
E/AndroidRuntime( 6131):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978)
Zazo032 commented 1 year ago

Either there’s a bug in the latest native sdk or there was a change that is currently not handled by the Flutter plugin, I can check tomorrow the native release notes just in case there was something missing

deepak786 commented 1 year ago

Some API methods are deprecated in v14 https://developers.intercom.com/installing-intercom/docs/migrating-to-14-0-0-android. There is no change in the notification setup or handling. https://developers.intercom.com/installing-intercom/docs/push-notifications-android#step-6-using-intercom-with-other-fcm-setups-optional

I have already reported this issue to Intercom.

devalp-pro commented 1 year ago

@deepak786 and @Zazo032 As I checked that Intercom released the 14.0.1 Version Are you guys updating that version and checked this crash was resolved in that version or not?

Checkout intercom github link==> https://github.com/intercom/intercom-android

https://github.com/intercom/intercom-android/blob/master/README.md

deepak786 commented 1 year ago

@devalp-pro Nothing is mentioned there about this bug in version 14.0.1.

deepak786 commented 1 year ago

The same crash appears even with SDK version 14.0.1

devalp-pro commented 1 year ago

Hi @deepak786

Can you check if this Integration it's done in our SDK or not?

Push Notification Apps targeting Android 13 should request a runtime permission to enable notifications. Add the following code to request permission.

registerForActivityResult( ActivityResultContracts.RequestPermission() ) { if (isGranted) { // Permission is granted. Continue the action or workflow in your // app. } else { // Explain to the user that the feature is unavailable because the // features requires a permission that the user has denied. At the // same time, respect the user's decision. Don't link to system // settings in an effort to convince the user to change their // decision. } }

deepak786 commented 1 year ago

Update from Intercom support:

Hi Deepak! I do have something to share but we don't have a fix as yet. The engineer said that he was able to reproduce the crash and that it only happens when Intercom is integrated via the flutter wrapper, not when integrated natively.
As it doesn’t seem like a straightforward fix, we are opening an issue for it and will let you know once we hear back from the team. I'll circle back to you later this week once I know a rough timeframe of how long this will take the team to address 👍
devalp-pro commented 1 year ago

Hi @deepak786 ,

We are testing the intercom on android and iOS. In iOS platform also got problems with notifications.

Testcase for iOS and Android as below

iOS

Android

PieterPicup commented 1 year ago

@deepak786 Thanks for following up with intercom and getting them on the issue. Hopefully they fix it in native soon so you can update.

I have held back on my other android apps updates to 14 for this exact reason. The last time they did a big update they had things breaking after they did a backend change and took forever to fix the native sdk.

saged87 commented 1 year ago

@deepak786 Thanks for following up with intercom and getting them on the issue. Hopefully they fix it in native soon so you can update.

I have held back on my other android apps updates to 14 for this exact reason. The last time they did a big update they had things breaking after they did a backend change and took forever to fix the native sdk.

How can i use older sdk ?

deepak786 commented 1 year ago

@saged87 Use intercom_flutter: 7.5.0

deepak786 commented 1 year ago

I have heard back from Intercom

Me again Deepak! I’ve heard back from our team and can confirm that we’re adding this issue to our backlog to be fixed!
For greater context, our product team prioritizes bugs based on the severity of the issue and how widespread of an experience it is with customers. To provide insight on expectations, issues like this may not be actioned for some months. That timeline is based on the team's current existing log of issues and upcoming feature releases which is subject to change.
Given the long-term nature of the work to be done here, I’m going to close this conversation with you for now, but I will reopen the case and send an update when the team moves forward with a fix 👍
I appreciate you taking the time to surface this issue with our team and you can rest assured I’ll take ownership from here!

This issue is not prioritized. I will suggest everyone report this issue to Intercom including this issue link.

PieterPicup commented 1 year ago

@deepak786 Could you drop us a link to the issue you have with them. Or explain how we could log one ourselves. I have not been able to find how 😵‍💫

orestesgaolin commented 1 year ago

Upgrading manually to 14.0.3 does not fix that

aparnabalasubramanian commented 1 year ago

@deepak786 Just got an update from our product team: image

deepak786 commented 1 year ago

@aparnabalasubramanian Thanks for the update. We are updating the docs regarding this.

orestesgaolin commented 1 year ago

Unfortunately changing to FlutterFragmentActivity breaks different plugin that uses platform views

Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: PlatformException(error, java.lang.IllegalStateException: Trying to create a platform view of unregistered type: cameraView
    at io.flutter.plugin.platform.PlatformViewsController$1.createForPlatformViewLayer(PlatformViewsController.java:175)
    at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:109)
    at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:60)
    at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
    at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
    at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
    at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
    at android.os.Handler.handleCallback(Handler.java:942)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:226)
    at android.os.Looper.loop(Looper.java:313)
    at android.app.ActivityThread.main(ActivityThread.java:8741)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
, null, null). Error thrown Zone error.
       at StandardMethodCodec.decodeEnvelope(message_codecs.dart:653)
       at MethodChannel._invokeMethod(platform_channel.dart:296)
       at ExpensiveAndroidViewController._sendCreateMessage(platform_views.dart:1023)
       at AndroidViewController.create(platform_views.dart:792)
deepak786 commented 1 year ago

Already discussing this with the Intercom support.

deepak786 commented 1 year ago

Update from Intercom Support:

Okay, so I heard back from the team who tell me that as the problem is a Flutter problem and not an Intercom or Android SDK problem, we won't be able to fix this issue.
We don't officially support Flutter but we'll always take a first look to see if there's something we can do. In this case however, it's not something we can fix Deepak.
deepak786 commented 1 year ago

@orestesgaolin By using the FlutterFragmentActivity, Is the crash only with PlatformViews such as a camera, or video_player?

I'm curious to know how developers managed to use the FlutterFragmentActivity along with PlatformViews. Because intercom_flutter is not the package that requires now the FlutterFragmentActvity. The local_auth package also requires to use of FlutterFragmentActivity.

orestesgaolin commented 1 year ago

I'll look into that and will try to give you more insight if FragmentActivity is a problem at all

deepak786 commented 1 year ago

@orestesgaolin

Maybe you need to override the configureFlutterEngine in MainActivity.kt

import io.flutter.embedding.android.FlutterFragmentActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant

class MainActivity: FlutterFragmentActivity() {
    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        GeneratedPluginRegistrant.registerWith(flutterEngine)
    }
}

Please also share the sample to reproduce the above issue.