QuickBlox / quickblox-flutter-sdk

quickblox-flutter-sdk
Other
8 stars 0 forks source link

WebRTC.init() Error on android 14 #80

Closed nawafM94 closed 4 months ago

nawafM94 commented 4 months ago

Hi, I have an error when init WebRTC on Android 14 It requires the mic permission. I need to init WebRTC to prepare for incoming call listeners, so I can't request the mic at the start of the app. this error happens in Android 14 only

quickblox_sdk: ^0.14.2

here is the error message tree (error trigger when calling "QB.webrtc.init()"):

E/AndroidRuntime(28084): java.lang.RuntimeException: Unable to start service com.quickblox.quickblox_sdk.webrtc.WebRTCCallService@bbd45a with Intent { cmp=com.saatco.murshadik/com.quickblox.quickblox_sdk.webrtc.WebRTCCallService }: java.lang.SecurityException: Starting FGS with type microphone callerApp=ProcessRecord{4216b2a 28084:com.saatco.murshadik/u0a204} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_MICROPHONE] any of the permissions allOf=false [android.permission.CAPTURE_AUDIO_HOTWORD, android.permission.CAPTURE_AUDIO_OUTPUT, android.permission.CAPTURE_MEDIA_OUTPUT, android.permission.CAPTURE_TUNER_AUDIO_INPUT, android.permission.CAPTURE_VOICE_COMMUNICATION_OUTPUT, android.permission.RECORD_AUDIO] and the app must be in the eligible state/exemptions to access the foreground only permission E/AndroidRuntime(28084): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4839) E/AndroidRuntime(28084): at android.app.ActivityThread.-$$Nest$mhandleServiceArgs(Unknown Source:0) E/AndroidRuntime(28084): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2289) E/AndroidRuntime(28084): at android.os.Handler.dispatchMessage(Handler.java:106) E/AndroidRuntime(28084): at android.os.Looper.loopOnce(Looper.java:205) E/AndroidRuntime(28084): at android.os.Looper.loop(Looper.java:294) E/AndroidRuntime(28084): at android.app.ActivityThread.main(ActivityThread.java:8177) E/AndroidRuntime(28084): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(28084): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552) E/AndroidRuntime(28084): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971) E/AndroidRuntime(28084): Caused by: java.lang.SecurityException: Starting FGS with type microphone callerApp=ProcessRecord{4216b2a 28084:com.saatco.murshadik/u0a204} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_MICROPHONE] any of the permissions allOf=false [android.permission.CAPTURE_AUDIO_HOTWORD, android.permission.CAPTURE_AUDIO_OUTPUT, android.permission.CAPTURE_MEDIA_OUTPUT, android.permission.CAPTURE_TUNER_AUDIO_INPUT, android.permission.CAPTURE_VOICE_COMMUNICATION_OUTPUT, android.permission.RECORD_AUDIO] and the app must be in the eligible state/exemptions to access the foreground only permission E/AndroidRuntime(28084): at android.os.Parcel.createExceptionOrNull(Parcel.java:3057) E/AndroidRuntime(28084): at android.os.Parcel.createException(Parcel.java:3041) E/AndroidRuntime(28084): at android.os.Parcel.readException(Parcel.java:3024) E/AndroidRuntime(28084): at android.os.Parcel.readException(Parcel.java:2966) E/AndroidRuntime(28084): at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:6761) E/AndroidRuntime(28084): at android.app.Service.startForeground(Service.java:862) E/AndroidRuntime(28084): at com.quickblox.quickblox_sdk.webrtc.WebRTCCallService.onStartCommand(WebRTCCallService.java:139) E/AndroidRuntime(28084): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4821) E/AndroidRuntime(28084): ... 9 more E/AndroidRuntime(28084): Caused by: android.os.RemoteException: Remote stack trace: E/AndroidRuntime(28084): at com.android.server.am.ActiveServices.validateForegroundServiceType(ActiveServices.java:2611) E/AndroidRuntime(28084): at com.android.server.am.ActiveServices.setServiceForegroundInnerLocked(ActiveServices.java:2322) E/AndroidRuntime(28084): at com.android.server.am.ActiveServices.setServiceForegroundLocked(ActiveServices.java:1679) E/AndroidRuntime(28084): at com.android.server.am.ActivityManagerService.setServiceForeground(ActivityManagerService.java:13281) E/AndroidRuntime(28084): at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:3385)

vdovbnya-qb commented 4 months ago

Hello @ameen95195 Thank you for providing information. For Android 14, it must specify the appropriate foreground service. More detailed information can be found at this link.

The QuickBlox Flutter SDK sets the microphone and camera types for the call foreground service. The QB.webrtc.init() method starts the call foreground service, so camera and microphone runtime permissions, must be granted before calling the QB.webrtc.init() method.

To request runtime permissions you can use the third-party library permission_handler. An example of requesting runtime permissions for a camera and microphone using the permission_handler library:

  Future<bool> checkPermissionsForCall() async {
    bool cameraDenied = await Permission.camera.status.isDenied;
    bool microphoneDenied = await Permission.microphone.status.isDenied;

    bool isAllPermissionsGranted = true;

    if (cameraDenied || microphoneDenied) {
      Map<Permission, PermissionStatus> statuses = await [Permission.camera, Permission.microphone].request();

      statuses.forEach((key, value) {
        if (value == PermissionStatus.denied || value == PermissionStatus.permanentlyDenied) {
          isAllPermissionsGranted = false;
          return;
        }
      });
    }

    return isAllPermissionsGranted;
  }
nawafM94 commented 4 months ago

Hi @vdovbnya-qb thank you for your answer, I appreciate it. The problem was solved when I updated the QB SDK to

quickblox_sdk: ^0.15.0-rc.1

My app behavior is not allowing me to request camera and mic permissions at the start until it receives a call or starts a call

kirillTolmachev commented 4 months ago

Hi @ameen95195 The version 0.15.0-rc.1 is a release candidate but is not a successful release. Please don't forget to update to version 0.15.0 when it will be released.

nawafM94 commented 4 months ago

@kirillTolmachev Thank you very much, I will.