Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MageDelfador opened this issue Aug 22, 2024 · 12 comments

Comments

@MageDelfador
Copy link

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
Copy link
Member

Interesting, I do not know how to fix this.

@iddq
Copy link

iddq commented Aug 28, 2024

Samsung?

Please try to add this to manifest:

android:foregroundServiceType="camera|microphone"

@mwarning
Copy link
Member

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

@iddq
Copy link

iddq commented Aug 29, 2024

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
Copy link
Author

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.

@mwarning
Copy link
Member

I am able to reproduce the error now.

@iddq
Copy link

iddq commented Aug 29, 2024

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

@mwarning
Copy link
Member

mwarning commented Aug 29, 2024

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
Copy link

iddq commented Aug 29, 2024

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

@MageDelfador
Copy link
Author

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 referenced this issue Sep 1, 2024
@iddq
Copy link

iddq commented Sep 3, 2024

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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants