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

#8964 Fix app crash on incoming call when running Android 14+ #8989

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

christianrowlands
Copy link
Contributor

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

I removed the call to start the MicrophoneAccessService on Android 14+.

Motivation and context

This change is in response to this GitHub Issue: #8964

When running on Android 14+, if you have the microphone permission granted to the app, incoming calls while the app is in the background causes the app to crash, and the incoming call to not come through. The Android documentation for that is here: https://developer.android.com/develop/background-work/services/fgs/service-types#microphone

and here: https://developer.android.com/develop/background-work/services/fgs/restrictions-bg-start#wiu-restrictions

Tests

I tested by making a call to a device running Android 14 and my changes while the device is locked, as well as unlocked with the app open.

Tested devices

  • Physical
  • Emulator
  • OS version(s): Android 14

Checklist

Signed-off-by: Christian Rowlands <craxiomdev [at] gmail.com>

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix.
This code has been added in #8914 in order to fix a problem when the app is "backgrounded".

Maybe the service still need to be started, but later?

val intent = Intent(this, MicrophoneAccessService::class.java)
ContextCompat.startForegroundService(this, intent)
// Starting in Android 14, you can't create a microphone foreground service while your app is in
// the background. If we call startForegroundService the app will crash.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but in this block the app is in the foreground (since isAppInForeground() returned true), or am I misreading something?

Copy link
Contributor Author

@christianrowlands christianrowlands Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed that too, but when I added logging it indicated the app is in the foreground. I am guessing this is the case because by the time this code is reached the app has been brought to the foreground with an incoming call UI, but because this was not triggered by a user action, it does not matter if the app is in the foreground. Maybe my comment is not the clearest. The app not only needs to be in the foreground, but it must have gotten there via a user interaction (or another exemption path).

As for my comment about creating the microphone foreground service while your app is in the background, it depends on how the activity was triggered. A user interaction with the foreground such as clicking on a UI button or on a notification will allow the microphone to be accessed. However, if the chain is triggered entirely from the background then the exception will occur.

I believe this approach works because now the app does not use the microphone permission until the "answer" button is clicked, which is a user interaction with the UI.

See the documentation here: https://developer.android.com/develop/background-work/services/fgs/restrictions-bg-start#background-start-restriction-exemptions

And the relevant section:

The user performs an action on a UI element related to your app. For example, they might interact with a bubble, notification, widget, or activity.

@christianrowlands
Copy link
Contributor Author

I think you are right. The service likely still needs to be started, but later. I will see if there is a later point that we can start it (has to be after the user clicks the answer button).

@christianrowlands
Copy link
Contributor Author

@bmarty , I took another stab at this fix. Because the VectorCallActivity is paused and resumed before the incoming call has been answered, my approach is to only start the MicrophoneAccessService if the call has already been answered.

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

Successfully merging this pull request may close these issues.

2 participants