Skip to content

Start the call service without the microphone type when it isn't allowed - #2250

Draft
mpretty-cyro wants to merge 2 commits into
devfrom
fix/call-service-microphone-type
Draft

mpretty-cyro wants to merge 2 commits into
devfrom
fix/call-service-microphone-type

Conversation

@mpretty-cyro

@mpretty-cyro mpretty-cyro commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Contributor checklist

  • I have tested my contribution on these devices:
  • Compiled only; not exercised on a device (see Testing below)
  • My contribution is fully baked and ready to be merged as is
  • I ensure that all the open issues my contribution fixes are mentioned in the commit message of my first commit using the Fixes #1234 syntax

Description

Crash cluster: SecurityException from Service.startForeground in CallForegroundService.startForeground
(onStartCommand). The service always asked for phoneCall|microphone; Android 14+ refuses the microphone type without
RECORD_AUDIO, or when started from the background, and only IllegalStateException was caught.

The microphone type is now included only when RECORD_AUDIO is granted, and a SecurityException falls back to the phone-call
type alone. The exception message in the reports is empty, so which of the two conditions applies isn't known; this covers both.

A refusal is handled differently depending on whether the service is already running:

  • Already running: a restart such as TYPE_ESTABLISHED, when the call connects while the app is in the background, keeps the types the service already has, and only its notification is updated. Falling back to phone-call only here would have dropped the microphone type for the rest of the call.
  • First start: it runs as phone-call only, and the next start while the app is visible asks for the microphone again.

That a refused restart leaves the existing types in place comes from reading the platform's behaviour; it isn't tested.

Testing: compiled. Not exercised on a device; it needs an incoming call.

CallForegroundService always started with the phone-call and microphone
types. Android 14+ throws SecurityException for the microphone type
when RECORD_AUDIO isn't granted or the service starts from the
background, and only IllegalStateException was caught, so the app
crashed. Include the microphone type only with the permission, and fall
back to the phone-call type alone if the system still refuses it.

@mpretty-cyro mpretty-cyro left a comment •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

.

Falling back to phone-call only on a restart, such as when a call
connects in the background, would drop the microphone type for the rest
of the call. A running service now keeps its types and only its
notification is updated.

@mpretty-cyro mpretty-cyro left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

lgtm

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.

1 participant