librepods icon indicating copy to clipboard operation
librepods copied to clipboard

android: privileged (shell) service for protected permissions

Open kavishdevar opened this issue 1 month ago • 2 comments

Why?

  • BluetoothDevice.setMetadata: battery, images. later, appreciated, but not required: fast pair customized field (allows us to provide custom settings in the Bluetooth Device settings page)
  • Route audio through phone speakers when not worn: use BluetoothProfile.setConnectionPolicy or AudioManager, whichever provides a seamless experience (please explain which one is better)

Requirements

  • base: android/rewrite. This will not be backported to v1.
  • Privileged service
    • Users should be able to start without Shizuku by using a computer
    • Shizuku should be available as a fallback
    • optionally, self-start with wireless debugging or root. see KeyMapper or thedjchi’s Shizuku fork
  • Use it in LibrePodsService to
    • set icon metadata (handle resource access, settings app can’t normally access the app’s resources)
    • set battery metadata
    • optionally, provide a Listening Mode control, conversation awareness toggle, and ear detection toggle, in the Bluetooth Device Settings fragment in the native settings app. reference

Don’t use it to give LibrePods CDM association- might go against Play policies.

Compile against a modified SDK source that includes hidden APIs instead of reflection. See anggrayudi/android-hidden-api

Bounty

  • Amount: $100 + $50 for each optional item
  • General instructions:
    • Adhere to the general code style of the app: don’t add any extra stuff that is not currently being used (DI, tests, etc.)
    • Do not vibe code: AI can be used for stuff like doing repetitive work, but don’t use it to add major chunks of code without knowing what’s happening
    • Test on at least one device running Android 17

I may reject submissions that rely excessively on AI-generated code.


Bounty amount can be increased depending on the effort needed, please discuss if that’s the case before proceeding. Payouts will be through Open Collective. Please do not submit an expense unless I’ve asked you to.

kavishdevar avatar Oct 28 '26 11:10 kavishdevar

Hi @kavishdevar,

I would like to implement the privileged shell service for LibrePods on the android/rewrite branch to handle protected Bluetooth metadata operations (BluetoothDevice.setMetadata) and audio routing.

Proposed Architecture (Extending :privileged)

  1. AIDL IPC Interface (ILibrePodsPrivilegedService.aidl):
    • Expose setBluetoothMetadata(String macAddress, int key, byte[] value), getBluetoothMetadata(String macAddress, int key), and setConnectionPolicy(String macAddress, int profile, int policy).
  2. Dual Execution Modes (UID 2000 shell / BLUETOOTH_PRIVILEGED):
    • Standalone ADB / Wireless Debugging Daemon: Extend the existing android/privileged/.../Main.kt (ActivityThread.systemMain().systemContext) into a persistent Binder/LocalSocket server launchable via app_process (with optional auto-starter via Wireless Debugging / root).
    • Shizuku UserService Fallback: Bind the same ILibrePodsPrivilegedService.Stub implementation via Shizuku.bindUserService() when Shizuku is available.
  3. Integration in LibrePodsService.kt:
    • Connect the existing battery/icon metadata blocks (lines 720-760 and setAppleBluetoothMetadata at lines 1440-1502) through a clean PrivilegedServiceHolder singleton (matching XposedServiceHolder.kt) compiled against anggrayudi/android-hidden-api on compileSdk 37.

Happy to take this on if you would like to assign me!

duongynhi000005-oss avatar Oct 28 '26 17:10 duongynhi000005-oss

Hi @kavishdevar, I'd like to pick this up.

I've already built this exact kind of thing: my own app that works like Shizuku, but doesn't need Wi-Fi or wireless debugging at all. It's a root-free privileged service in Kotlin and C++ that starts a shell-level helper through the phone's own adb, exposes privileged calls to the app over a bound Binder service, and reattaches on its own after restarts. Hidden APIs, app_process, Shizuku fallback and Bluetooth metadata are all ground I've covered.

I've gone through the current android/rewrite branch and the :privileged module, and I know where the Shizuku TODOs need to be wired and why the icons don't show in Settings. I have a clear plan for both, plus the speaker routing part.

Proof: https://github.com/kukirin-ui/meridian-showcase

I'll test on a Galaxy S26 (Exynos 2600, Android 17, One UI 9) and can have a first draft PR up within a day. I'd also take the optional Settings page controls. Could you assign it to me?

kukirin-ui avatar Oct 30 '26 15:10 kukirin-ui