flutter-webrtc / callkeep

iOS CallKit and Android ConnectionService for Flutter
MIT License
131 stars 142 forks source link

startCall() erroring on checkPermission #42

Open cmendes0101 opened 3 years ago

cmendes0101 commented 3 years ago

On Android, when receiving a push notification and answering the call it attempts to run android.content.Context.checkPermission(). This causes a crash due to there not being a usable this._currentActivity with the app initializing from background push.

Steps to reproduce:

  1. Close app, lock screen, and wait 5 minutes (performing sooner seems to work normally)
  2. Initiate callkeep by sending a push notification.
  3. Answer the incoming call
  4. Unhandled Exception will be thrown on startCall() but will display answered call.

All permission has been granted before and initiating from push notification with SIP registration is working correctly.

2020-12-28 16:34:39.001 9712-9712/com.example.app E/MethodChannel#FlutterCallKeep.Method: Failed to handle method call java.lang.NullPointerException: Attempt to invoke virtual method 'int android.content.Context.checkPermission(java.lang.String, int, int)' on a null object reference at androidx.core.content.ContextCompat.checkSelfPermission(ContextCompat.java:535) at io.wazo.callkeep.CallKeepModule.hasPermissions(CallKeepModule.java:613) at io.wazo.callkeep.CallKeepModule.startCall(CallKeepModule.java:281) at io.wazo.callkeep.CallKeepModule.HandleMethodCall(CallKeepModule.java:123) at com.github.cloudwebrtc.flutter_callkeep.FlutterCallkeepPlugin.onMethodCall(FlutterCallkeepPlugin.java:69) at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233) at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85) at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692) at android.os.MessageQueue.nativePollOnce(Native Method) at android.os.MessageQueue.next(MessageQueue.java:335) at android.os.Looper.loop(Looper.java:183) at android.app.ActivityThread.main(ActivityThread.java:7660) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 2020-12-28 16:34:39.005 9712-9760/com.example.app E/flutter: [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: PlatformException(error, Attempt to invoke virtual method 'int android.content.Context.checkPermission(java.lang.String, int, int)' on a null object reference, null, java.lang.NullPointerException: Attempt to invoke virtual method 'int android.content.Context.checkPermission(java.lang.String, int, int)' on a null object reference at androidx.core.content.ContextCompat.checkSelfPermission(ContextCompat.java:535) at io.wazo.callkeep.CallKeepModule.hasPermissions(CallKeepModule.java:613) at io.wazo.callkeep.CallKeepModule.startCall(CallKeepModule.java:281) at io.wazo.callkeep.CallKeepModule.HandleMethodCall(CallKeepModule.java:123) at com.github.cloudwebrtc.flutter_callkeep.FlutterCallkeepPlugin.onMethodCall(FlutterCallkeepPlugin.java:69) at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233) at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85) at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692) at android.os.MessageQueue.nativePollOnce(Native Method) at android.os.MessageQueue.next(MessageQueue.java:335) at android.os.Looper.loop(Looper.java:183) at android.app.ActivityThread.main(ActivityThread.java:7660) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

joaquin03 commented 2 years ago

Hi! Could you solve this? I am having the same issue