TheParasiteProject / packages_apps_BtHelper

Bluetooth Devices Helper for AOSP
GNU General Public License v3.0
5 stars 5 forks source link

Implement more functions for AirPods by communcating to them like an apple device #1

Open kavishdevar opened 1 month ago

kavishdevar commented 1 month ago

https://github.com/Project-PixelStar/packages_apps_BtHelper/issues/1

Hey!

I've managed to reverse engineer airpods functionalities and how they work on apple devices. Currently there's a bug in the AOSP bluetooth stack that doesn't allow it to work though.

Apple uses the L2CAP protocol to communicate with the airpods, they use the PSM 4097 or 0x1001. But the problem with using this is that in flouride, it sends the airpods a packet to check for extended flow control, and wait for the device to respond. But the airpods don't respond to anything until a specific handshake packet is sent first. So android just doesn't continue with the connection.. I commented out the lines in the bluetooth stack and replaced the libbluetooth_jni.so (Ask me more about it), and voilà! It worked.. Instead of relying on the advertisements, the btservices can now communicate with the airpods just like an apple device would!! ear-detection, accurate battery percentages, setting anc modes, controlling what the button does, accessiblity settings, controlling adaptive transparency strength (new on app2) can be implemented easily!

But the only problem is that I can build the BtServices app, but it being a soong-built app, takes a long time to build.. and isn't ideal for experimenting. But, I might end up making some changes and making a PR, no promises though.

someone5678 commented 1 month ago

Thank you so much for issue! I'll check it later!

someone5678 commented 1 month ago

Okay, so, I also tried to implement these features before but failed. So if you don't mind, could you please explain me more about

commented out the lines in the bluetooth stack and replaced the libbluetooth_jni.so (Ask me more about it),

this section? Thanks!!

kavishdevar commented 1 month ago

i've commented this line

and this check performed for extended flow control too.

This fixes the issue where android can't open l2c connections with airpods. Then i built the libbluetooth_jni.so using make libbluetooth_jni and replaced it in the lib directories using a script in post-fs-data (KSU) that creates an overlayfs for /apex/com.android.btservices and /apex/com.android.btservices@350090000. But this renders bluetooth unsable probably because of some signature verification, so i made a module that adds the library in /system/lib64. (finally worked!).

you can also check this commit - https://github.com/kavishdevar/packages_modules_Bluetooth/commit/81afc3f

also, i'm a noob at platform developement, but i can try writing java code, only if there is a quicker way to build apks without using mmm . or make BtHelper?

kavishdevar commented 1 month ago

this of course is a temporary fix, maybe the send function shouldn't block if it is sending this particular packet, and should return false if no response is received from the peer. i really want to create an issue on android, but i am too lazy/busy with school!

If you'd like to implement the actual airpods functions, checkout my very quick and dirty code for linux at https://github.com/kavishdevar/aln (check my main start-daemon script there, it has battery and ear detection parsing, and the enums for other stuff like setting anc), and https://github.com/steam3d/MagicPodsCore/ either the decky branch (originally written in c, probably has more stuff implemented) or the main branch (a rewrite in python)

someone5678 commented 1 month ago

Thanks! I'm currently in build and testing stage!

someone5678 commented 1 month ago

make BtHelper

Yes.. On AOSP, make <module-name> is only way to build that module only... You can pass -j argument though like m -j$(nproc) BtHelper

kavishdevar commented 1 month ago

Thanks! I'm currently in build and testing stage!

Please share the apk once built, if you can :)

kavishdevar commented 1 month ago

make BtHelper

Yes.. On AOSP, make <module-name> is only way to build that module only... You can pass -j argument though like m -j$(nproc) BtHelper

I already use the job argument, but, my pc is under-speced, takes at least 20 minutes to build.. :(

I'll try on my dad's pc later.

kavishdevar commented 1 month ago

I've opened an issue on issuetracker, please upvote :)

https://issuetracker.google.com/issues/371713238

kavishdevar commented 1 month ago

hey! what's the best ide to develop this app? and are you planning to implement everything, if so, then please lemme know, i can help with the l2c packets and all!

someone5678 commented 1 month ago

hey! what's the best ide to develop this app? and are you planning to implement everything, if so, then please lemme know, i can help with the l2c packets and all!

Probably Android Studio! But as this is system app, requires some modification just like LineageOS' Updater app does. e.g.) LineageOS updater

And yes. I'm planning to implement like what I saw in those Decky loader plugin does (ANC, etc.)

If you don't mind, I'll really appreciate your help!!

Currently, I'm testing your changes and some modification! Feel free to pr or issue anytime!

kavishdevar commented 1 month ago

well, i am not planning to pr just because my pc is too slow to build and test, but if i can use gradle, then, absolutely in for this!

If you don't mind, I'll really appreciate your help!!

I absolutely do not :D, if you need, I can list out all the AAP (Apple Accessory Protocol) packets sent/received.. (you can also check my aln repo instead, but it might be a pain to navigate through)

btw, we can use IM platform if you'd prefer that over gh issues for quick chats

someone5678 commented 1 month ago

well, i am not planning to pr just because my pc is too slow to build and test, but if i can use gradle, then, absolutely in for this!

If you don't mind, I'll really appreciate your help!!

I absolutely do not :D, if you need, I can list out all the AAP (Apple Accessory Protocol) packets sent/received.. (you can also check my aln repo instead, but it might be a pain to navigate through)

btw, we can use IM platform if you'd prefer that over gh issues for quick chats

Okay thanks!!

As a quick check, your aln repo definitely helps my dev for BtHelper. XD

For IM, I only have telegram account eh...

kavishdevar commented 1 month ago

Also, here's a list of features i've implemented (should add this to my repo too 😅)

kavishdevar commented 1 month ago

As a quick check, your aln repo definitely helps my dev for BtHelper. XD

Glad my repo is useful for someone other than me :]

For IM, I only have telegram account eh...

i do have telegram too, username removed for privacy