Skip to content

android: add app shortcut to toggle between two listening modes - #850

Open
LoMiLiMiT wants to merge 4 commits into
librepods-org:mainfrom
LoMiLiMiT:android/listening-mode-shortcut
Open

LoMiLiMiT wants to merge 4 commits into
librepods-org:mainfrom
LoMiLiMiT:android/listening-mode-shortcut

Conversation

@LoMiLiMiT

@LoMiLiMiT LoMiLiMiT commented Oct 19, 2026 •

Copy link
Copy Markdown

What

Adds a "Toggle listening mode" app shortcut that switches between two listening modes without opening the app.

  • A headless ToggleListeningModeActivity sends the listening-mode command and shows a short toast with the new mode. If AirPods aren't connected, it shows "AirPods not connected" instead.
  • A static shortcut (res/xml/shortcuts.xml) is attached to MainActivity.
  • A new "Listening mode shortcut" section in app settings picks the two modes from Transparency, Adaptive and Noise Cancellation. Picking a new mode replaces the least recently picked one, so exactly two are always selected. The default is Noise Cancellation ↔ Transparency.
  • All strings are translatable resources.

Why

Switching modes means opening the app, the QS tile (which cycles through every mode), or a long press on the stem. Most people just flip between two modes. An app shortcut can be triggered from the launcher, Samsung Modes and Routines, Good Lock RegiStar, Tasker and similar tools.

Related: #155 (the same idea for Linux).

Known limitation

Android adds FLAG_ACTIVITY_TASK_ON_HOME to every app shortcut launch. When the toggle is triggered from inside another app (e.g. via a Modes and Routines button action), the user lands on the home screen after it finishes. I tested finish(), moveTaskToBack(true), finishAndRemoveTask() and moving the app's own task to the front; none returns to the previous app, because an app can't see other apps' tasks. I also tried an opt-in launcher alias, but Modes and Routines and RegiStar resolve "Open app" to the main activity, so it didn't help and I removed it again.

Notes

  • Off is not selectable. AirPods refuse Off unless "Off Listening Mode" is enabled, so a pair containing Off made every other press a no-op once that setting was turned off. A stored pair containing anything other than the three selectable modes falls back to the default.
  • The activity is exported="true" so system components can launch it directly. The only thing it can do is switch between the two modes the user chose.
  • The rewrite branch already has an empty shortcuts.xml, so this should port over easily.

Testing

Galaxy S23 Ultra (SM-S918B), One UI 9 / Android 17, no root, AirPods Pro. Launches used the real shortcut flags (0x1000c000) and the toggle's result was compared with the mode the AirPods reported back:

  • toggling Adaptive ↔ Noise Cancellation from a Modes and Routines action and from RegiStar
  • changing the pair in settings
  • with a stored Noise Cancellation + Off pair and Off Listening Mode disabled: before the fix 2/2 presses sent Off and the AirPods stayed in Noise Cancellation; after it 4/4 presses matched

@LoMiLiMiT

Copy link
Copy Markdown
Author

Love that claude added his piece. Overall just created this as I finally got OneUi 9.0 with the bluetooth fix.
The app works really well, the only thing I have been wanting was a shortcut that I can trigger via hold volume down.
Maybe someone else thought of the same and can use it 👍

@LoMiLiMiT
LoMiLiMiT force-pushed the android/listening-mode-shortcut branch from 76961c4 to 7edaa32 Compare October 19, 2026 22:24
Adds a "Toggle listening mode" static app shortcut backed by a headless
activity that switches between two user-selected listening modes. The
two modes are picked in app settings (default: Noise Cancellation and
Transparency).

Because it is a regular app shortcut, it can be used from the launcher,
Samsung Modes and Routines, and button/gesture mapping apps.
App shortcut launches carry FLAG_ACTIVITY_TASK_ON_HOME, so triggering
the toggle shortcut from inside an app (e.g. via Modes and Routines)
drops the user on the home screen when it finishes. No way of finishing
the activity avoids this.

Add a disabled-by-default launcher alias, enabled from a "Show in app
list" setting. Button mapping settings such as Samsung's side key can
launch it directly, which keeps the user in the app they were using.
…oggle"

This reverts commit 1999bd0.

The alias was meant to let button mapping tools launch the toggle
directly, without the TASK_ON_HOME flag that app shortcut launches carry.
In practice, Samsung Modes and Routines and Good Lock RegiStar both
resolve "Open app" to the package's main launcher activity, so picking
the alias opened LibrePods instead of toggling. The only working direct
launch path (the side key long press set via adb settings) is not
something users can configure, so the alias adds a setting that does
nothing for them.
AirPods refuse the Off listening mode unless "Off Listening Mode" is
enabled. With a pair like Noise Cancellation + Off, disabling that
setting left the shortcut sending Off on every other press: the AirPods
stayed in Noise Cancellation while the toast still said "Off".

The shortcut now picks from Transparency, Adaptive and Noise
Cancellation only. A stored pair that contains anything else falls back
to the default pair.

Also sort imports and update the activity comment.
@LoMiLiMiT
LoMiLiMiT force-pushed the android/listening-mode-shortcut branch from 7edaa32 to a13fd13 Compare October 19, 2026 22:27
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