meshenger-app / meshenger-android

P2P Voice/Video phone App for local networks.
GNU General Public License v3.0
691 stars 108 forks source link

Microphone does not work when switching to other applications during a call #160

Open MageDelfador opened 2 months ago

MageDelfador commented 2 months ago

In Android 14, there is no permission to record audio in the background, and meshenger switching to the background can't record. But the camera can work fine in the background.

mwarning commented 2 months ago

Interesting, I do not know how to fix this.

iddq commented 2 months ago

Samsung?

Please try to add this to manifest:

android:foregroundServiceType="camera|microphone"

mwarning commented 2 months ago

@iddq that might work. I have added it without being able to test it for now.

iddq commented 2 months ago

So I have two Android 13 devices, Samsung and Xiaomi. I also experience the above problem, but only on Samsung.

https://developer.android.com/about/versions/11/privacy/foreground-services

MageDelfador commented 2 months ago

I tested the latest code and it crashed.

logs ```java java.lang.RuntimeException: Unable to start service d.d.meshenger.MainService@6a6479 with Intent { act=START_FOREGROUND_ACTION cmp=d.d.meshenger/.MainService }: java.lang.SecurityException: Starting FGS with type microphone callerApp=ProcessRecord{880c753 8467:d.d.meshenger/u0a430} 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 at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5046) at android.app.ActivityThread.-$$Nest$mhandleServiceArgs(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2418) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:224) at android.os.Looper.loop(Looper.java:318) at android.app.ActivityThread.main(ActivityThread.java:8671) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:561) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1013) Caused by: java.lang.SecurityException: Starting FGS with type microphone callerApp=ProcessRecord{880c753 8467:d.d.meshenger/u0a430} 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 at android.os.Parcel.createExceptionOrNull(Parcel.java:3057) at android.os.Parcel.createException(Parcel.java:3041) at android.os.Parcel.readException(Parcel.java:3024) at android.os.Parcel.readException(Parcel.java:2966) at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:7269) at android.app.Service.startForeground(Service.java:862) at d.d.meshenger.MainService.onStartCommand(MainService.kt:190) at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5028) ... 9 more Caused by: android.os.RemoteException: Remote stack trace: at com.android.server.am.ActiveServices.validateForegroundServiceType(ActiveServices.java:2807) at com.android.server.am.ActiveServices.setServiceForegroundInnerLocked(ActiveServices.java:2518) at com.android.server.am.ActiveServices.setServiceForegroundLocked(ActiveServices.java:1809) at com.android.server.am.ActivityManagerService.setServiceForeground(ActivityManagerService.java:14032) at android.app.IActivityManager$Stub.onTransact$setServiceForeground$(IActivityManager.java:12675) ```

My device is Xiaomi.

mwarning commented 2 months ago

I am able to reproduce the error now.

iddq commented 2 months ago

tested on samsung android 13 and it is working now. the microphone access is still working while meshenger is not in foreground.

mwarning commented 2 months ago

i can reproduce the crash for Android 14. I think the foreground service type is not accurate. The service is not meant to record audio or to use the camera. That would be the job of the CallAcivity.

iddq commented 2 months ago

Does this error occur during a video call? I only use it with audio. How to reproduce the issue?

MageDelfador commented 2 months ago

Does this error occur during a video call? I only use it with audio. How to reproduce the issue?

Crash on startup, only on Android 14.

iddq commented 2 months ago

The error message clearly states that in addition to the FOREGROUND_SERVICE_MICROPHONE permission, other permissions such as RECORD_AUDIO are also required. At runtime, you need to check for the presence of the RECORD_AUDIO permission and request it from the user if necessary.

mwarning commented 1 month ago

hm, I do not have much time atm. to debug this and provide a solution. Let's hope we can get this fixed in the next release.