d4rken-org / capod

A companion app for AirPods on Android.
https://play.google.com/store/apps/details?id=eu.darken.capod
GNU General Public License v3.0
511 stars 43 forks source link

The application is responding to devices that are not mine. #212

Open berrmount opened 3 months ago

berrmount commented 3 months ago

Device: Galaxy S22+ with Airpods 2 The application may not be utilizing the device address or is solely dependent on the device name, "AirPods". I am in a location with a numerous AirPods nearby. It displays other devices that are not owned by the user as "mine", despite the "Show all devices" feature being disabled. Consequently, the auto-play and auto-pause functions are triggered and plays/stops music even when no devices are connected.

d4rken commented 3 months ago

It's not great, but that's the best we can do. CAPod uses a heuristic based on signal strength to determine which are "yours". The Bluetooth address send by the AirPods is randomized and can't be used to determine which are yours. The name is also not part of the BLE broadcast that contains the information like battery status etc.

Just doing the best we can with what is available. Direct access like Apple does it on iPhones, is not possible on Android's Bluetooth stack as far as I know.

berrmount commented 3 months ago

I understand, but there are 2 problems.

  1. My AirPods respond to other AirPods that I do not own when connected to my AirPods.
  2. My AirPods respond to other AirPods even when I am NOT connected to any Bluetooth devices.

Additionally, I use Tasker to play music when connected to my AirPods, and it has worked fine so far using the MAC address to identify the device. Could this method be a potential solution, or I wasn't using this method long enough to encounter the problem you've mentioned?

d4rken commented 3 months ago

Could this method be a potential solution

No

There are two ways AirPods offer information:

  1. Direct Bluetooth connection, this is the one you pair in system settings, you get audio this way. We know which one is yours because it's directly talking to us.
  2. Indirect Bluetooth Broadcasts, no need to pair for this. We don't know which one is yours because it's a random message with a random address that changes every few minutes. We only know how close and how long it was close to us based on signal strength.

The following information like

is not available through method 1 because Android does not support it.

My AirPods respond to other AirPods that I do not own when connected to my AirPods.

Doesn't have a good solution, I already did everything I could think off to reduce false positives

My AirPods respond to other AirPods even when I am NOT connected to any Bluetooth devices.

Here we could maybe change the code so it does not execute any reactions if there are no AirPods connected to your phone :thinking:

d4rken commented 3 months ago

Here we could maybe change the code so it does not execute any reactions if there are no AirPods connected to your phone 🤔

This should already be the case.

We get only continue if there is a headset device connected:

https://github.com/d4rken-org/capod/blob/07a11799b1d88ebe07045fba250795504b69accd/app-common/src/main/java/eu/darken/capod/reaction/core/playpause/PlayPause.kt#L32-L41

https://github.com/d4rken-org/capod/blob/07a11799b1d88ebe07045fba250795504b69accd/app-common/src/main/java/eu/darken/capod/common/bluetooth/BluetoothManager2.kt#L166-L168