meshenger-android icon indicating copy to clipboard operation
meshenger-android copied to clipboard

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

Open MageDelfador opened this issue 1 year ago • 12 comments

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.

MageDelfador avatar Aug 22 '24 19:08 MageDelfador

Interesting, I do not know how to fix this.

mwarning avatar Aug 22 '24 19:08 mwarning

Samsung?

Please try to add this to manifest:

android:foregroundServiceType="camera|microphone"

iddq avatar Aug 28 '24 19:08 iddq

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

mwarning avatar Aug 28 '24 20:08 mwarning

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

iddq avatar Aug 29 '24 07:08 iddq

I tested the latest code and it crashed.

logs
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.

MageDelfador avatar Aug 29 '24 08:08 MageDelfador

I am able to reproduce the error now.

mwarning avatar Aug 29 '24 15:08 mwarning

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

iddq avatar Aug 29 '24 15:08 iddq

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.

mwarning avatar Aug 29 '24 19:08 mwarning

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

iddq avatar Aug 29 '24 19:08 iddq

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.

MageDelfador avatar Aug 30 '24 06:08 MageDelfador

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.

iddq avatar Sep 03 '24 18:09 iddq

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.

mwarning avatar Sep 15 '24 22:09 mwarning