Skip to content

fix: route short-press volume to active stream during calls#375

Open
howdoiusekeyboard wants to merge 1 commit intosameerasw:developfrom
howdoiusekeyboard:fix/button-remap-call-stream-routing
Open

fix: route short-press volume to active stream during calls#375
howdoiusekeyboard wants to merge 1 commit intosameerasw:developfrom
howdoiusekeyboard:fix/button-remap-call-stream-routing

Conversation

@howdoiusekeyboard
Copy link
Copy Markdown

Problem

With Button Remap enabled and a mapping on Vol+ / Vol-, a single short press always changed media volume — even during a phone call. This overrode Android's default stream routing (STREAM_VOICE_CALL during calls, STREAM_RING while ringing, etc.).

Cause

The accessibility service path consumes the volume DOWN event via FLAG_REQUEST_FILTER_KEY_EVENTS and re-simulates default volume behaviour on UP if no long-press fired. Three call sites in that re-simulation hardcoded STREAM_MUSIC, so every short press always adjusted media volume regardless of what stream Android would have picked.

Fix

Replace the hardcoded adjustStreamVolume(STREAM_MUSIC, …) with adjustSuggestedStreamVolume(direction, USE_DEFAULT_STREAM_TYPE, FLAG_SHOW_UI) at the three sites. This is the documented Android API for "do exactly what hardware volume keys would normally do" — the system itself picks STREAM_VOICE_CALL during calls, STREAM_RING while ringing, STREAM_MUSIC while music plays, and falls back to the suggestion when nothing is active. Ref: AudioManager.adjustSuggestedStreamVolume.

Sites changed

  • app/src/main/java/com/sameerasw/essentials/services/handlers/ButtonRemapHandler.kt:153 — accessibility-service path, screen-on
  • app/src/main/java/com/sameerasw/essentials/services/InputEventListenerService.kt:171 — Shizuku /dev/input path, torch-on branch
  • app/src/main/java/com/sameerasw/essentials/services/InputEventListenerService.kt:199 — Shizuku /dev/input path, torch-off branch

Intentionally untouched

toggleMediaVolume() at ButtonRemapHandler.kt:244,251 keeps STREAM_MUSIC. That helper backs the user-selected Toggle media volume mapping action, which by design must act on media volume regardless of active stream.

Out of scope

The ~500 ms perceived latency on short-press is structural to the consume-then-replay design (DOWN is consumed, only UP-before-timeout re-simulates) and is not what this PR addresses. Worth a separate UX pass.

Verification

  • ./gradlew assembleDebug — green; no new warnings on the edited lines.
  • Grep sweep: zero adjustStreamVolume calls remain in the re-simulation paths; three adjustSuggestedStreamVolume calls at the edited lines.
  • On-device matrix to exercise after merge: idle → ringtone slider; music playing → music slider; cellular call (screen on / proximity off) → in-call slider; VoIP (Signal, Meet) → communication slider; long-press → mapped action still fires, slider stays put.

Diff: 6 changed lines across two files.

When Button Remap consumes the volume DOWN event via
FLAG_REQUEST_FILTER_KEY_EVENTS and re-simulates short-press behaviour on
UP, three call sites passed STREAM_MUSIC explicitly, which overrode
Android's default stream routing during calls, ringing, and other
active-stream contexts.

Switch each site to adjustSuggestedStreamVolume with
USE_DEFAULT_STREAM_TYPE — the documented API for "do what hardware
volume keys would normally do". The system then routes to
STREAM_VOICE_CALL during calls, STREAM_RING while ringing, STREAM_MUSIC
while music plays, and falls back to the suggested type when nothing is
active.

Sites changed:
  - ButtonRemapHandler.kt:153                accessibility-service path
  - InputEventListenerService.kt:171        Shizuku /dev/input, torch on
  - InputEventListenerService.kt:199        Shizuku /dev/input, torch off

The toggleMediaVolume() helper at ButtonRemapHandler.kt:244,251 stays on
STREAM_MUSIC by design — it backs the user-selected "Toggle media volume"
mapping action.

The ~500ms perceived latency that comes from the consume-then-replay
design is structural to short-press handling and is not addressed here.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants