react-native-callkeep icon indicating copy to clipboard operation
react-native-callkeep copied to clipboard

Microphone issues on locked screen or background for Android device with version 14.

Open CClaudiu26 opened this issue 1 year ago • 1 comments

Bug report

  • [ ] I've checked the example to reproduce the issue.

  • Reproduced on:

  • [X] Android

Description

Is anyone having issue with microphone when the screen is locked or the app is in background? I didn't have any problem with android 13, but after the update to 14 I had this issue.

Versions

- React Native:  0.73.6
- Android: 14
- Phone model:  Google pixel 6

Logs

Paste here

CClaudiu26 avatar Aug 09 '24 18:08 CClaudiu26

Same issue on Xiaomi here as well as Motorola Moto G84

LukakHR avatar Aug 28 '24 12:08 LukakHR

This is a valid issue. Microphone doesn't work when the phone is locked or the app is in the background. It only works when the app is back in the foreground.

This is related to https://developer.android.com/develop/background-work/services/fg-service-types#microphone from sdk 34.

The main issue seems to be that we are starting the VoiceConnectionService foreground service too early here https://github.com/react-native-webrtc/react-native-callkeep/blob/master/android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java#L209

I think we should start this foreground service when the call is answered, somewhere here https://github.com/react-native-webrtc/react-native-callkeep/blob/master/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java#L464

What happens right now is that this foregroundservice https://github.com/react-native-webrtc/react-native-callkeep/blob/master/android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java#L209 fails silently if you dont have microphone permission already.

The only way around this atm is to request for the microphone permission upfront before you receive a call. This can be bad for UX.

Please if you have some time you can share how this call https://github.com/react-native-webrtc/react-native-callkeep/blob/master/android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java#L209 can be delayed/recalled onanswer of the call. @manuquentin

I can then make a PR for this

nero2009 avatar Sep 02 '24 15:09 nero2009

@nero2009 for some of my users the issue seems to be happening even if they have allowed microphone permissions before the call has been initialized so this might not be the only issue

LukakHR avatar Sep 02 '24 21:09 LukakHR

This may be related to the additional permissions required for Android 14 to add foreground service type: https://developer.android.com/about/versions/14/changes/fgs-types-required.

In short, add following permissions to the AndroidManifest.xml:

<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA" />

I've made doc change in this PR: https://github.com/react-native-webrtc/react-native-callkeep/pull/806.

wkwiatek avatar Sep 10 '24 10:09 wkwiatek

I've merged #806. Thanks @wkwiatek for your work on investigating it.

manuquentin avatar Sep 11 '24 14:09 manuquentin

Not sure if this fixes this issue.

Last time I checked https://github.com/react-native-webrtc/react-native-callkeep/blob/master/android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java#L348 still fails cos we need the RECORD_AUDIO runtime permission before we can start that foreground service.

Ideally we should start that foreground service when the call is answer not when the call is received. I could be wrong tho.

nero2009 avatar Sep 11 '24 15:09 nero2009

You can always start you own foreground service using this https://rn-foreground.vercel.app/ or implement yours and expose via native modules

nero2009 avatar Oct 01 '24 09:10 nero2009