FORUMS

[GUIDE] How to port Bluez to Kitkat, Lollipop & Marshmallow

1,634 posts
Thanks Meter: 5,409
 
By daniel_hk, Inactive Recognized Contributor on 8th February 2014, 10:24 AM
Post Reply Email Thread
28th February 2014, 06:25 PM |#21  
daniel_hk's Avatar
OP Inactive Recognized Contributor
Flag Hong Kong
Thanks Meter: 5,409
 
Donate to Me
More
Quote:
Originally Posted by 95A31

Sucessfully ported on CyanogenMod 11.0 git (using Bluetooth from AOSP).

HOWTO:
Remove CyanogenMod Bluetooth and grab AOSP version by local_manifest:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<manifest>

  <remote name="kernel"
          fetch="git://git.kernel.org/pub/scm/" />

  <remote name="googlecode"
          fetch="https://code.google.com/" />

  <remove-project name="CyanogenMod/android_external_bluetooth_bluedroid" />
  <project remote="kernel" path="external/bluetooth/bluez" name="bluetooth/bluez" groups="pdk" revision="master" />
  <project remote="kernel" path="external/bluetooth/sbc" name="bluetooth/sbc" groups="pdk" revision="master" />
  <project remote="googlecode" path="external/bluetooth/glib" name="p/aosp-bluez.glib" groups="pdk" revision="master" />
  
  <remove-project name="CyanogenMod/android_packages_apps_Bluetooth" />
  <remove-project name="CyanogenMod/android_packages_apps_BluetoothExt" />  
  <project path="packages/apps/Bluetooth" name="platform/packages/apps/Bluetooth" remote="aosp" revision="refs/tags/android-4.4.2_r1" />
  
  <project path="aosp/packages/apps/Settings" name="platform/packages/apps/Settings" remote="aosp" revision="refs/tags/android-4.4.2_r1" />  
  <project path="aosp/frameworks/base" name="platform/frameworks/base/" remote="aosp" revision="refs/tags/android-4.4.2_r1" />
  <project path="aosp/hardware/libhardware" name="platform/hardware/libhardware/" remote="aosp" revision="refs/tags/android-4.4.2_r1" />

</manifest>
Replace CyanogenMod Bluetooth system with AOSP one:
Code:
rm cm-11.0/hardware/libhardware/include/hardware/bluetooth.h
cp aosp/hardware/libhardware/include/hardware/bluetooth.h cm-11.0/hardware/libhardware/include/hardware/bluetooth.h

rm -rf  cm-11.0/frameworks/base/core/java/android/bluetooth
cp -r aosp/frameworks/base/core/java/android/bluetooth  cm-11.0/frameworks/base/core/java/android

rm  cm-11.0/frameworks/base/services/java/com/android/server/BluetoothManagerService.java
cp aosp/frameworks/base/services/java/com/android/server/BluetoothManagerService.java  cm-11.0/frameworks/base/services/java/com/android/server/BluetoothManagerService.java

rm -rf  cm-11.0/packages/apps/Settings/src/com/android/settings/bluetooth
cp -r aosp/packages/apps/Settings/src/com/android/settings/bluetooth  cm-11.0/packages/apps/Settings/src/com/android/settings
Adapt CyanogenMod with this changes:
Code:
diff --git a/frameworks/base/Android.mk b/frameworks/base/Android.mk
index 91338ef..43a87ef 100644
--- a/frameworks/base/Android.mk
+++ b/frameworks/base/Android.mk
@@ -88,10 +88,8 @@ LOCAL_SRC_FILES += \
 	core/java/android/wipower/IWipower.aidl \
 	core/java/android/wipower/IWipowerManagerCallback.aidl \
 	core/java/android/bluetooth/IBluetooth.aidl \
-	core/java/android/bluetooth/IQBluetooth.aidl \
 	core/java/android/bluetooth/IBluetoothA2dp.aidl \
 	core/java/android/bluetooth/IBluetoothCallback.aidl \
-	core/java/android/bluetooth/IQBluetoothAdapterCallback.aidl \
 	core/java/android/bluetooth/IBluetoothHeadset.aidl \
 	core/java/android/bluetooth/IBluetoothHeadsetPhone.aidl \
 	core/java/android/bluetooth/IBluetoothHealth.aidl \
@@ -100,18 +98,12 @@ LOCAL_SRC_FILES += \
 	core/java/android/bluetooth/IBluetoothPan.aidl \
 	core/java/android/bluetooth/IBluetoothManager.aidl \
 	core/java/android/bluetooth/IBluetoothManagerCallback.aidl \
-	core/java/android/bluetooth/IQBluetoothManagerCallback.aidl \
 	core/java/android/bluetooth/IBluetoothPbap.aidl \
 	core/java/android/bluetooth/IBluetoothMap.aidl \
 	core/java/android/bluetooth/IBluetoothStateChangeCallback.aidl \
-	core/java/android/bluetooth/IBluetoothHandsfreeClient.aidl \
-	core/java/android/bluetooth/IBluetoothHidDevice.aidl \
-	core/java/android/bluetooth/IBluetoothHidDeviceCallback.aidl \
 	core/java/android/bluetooth/IBluetoothGatt.aidl \
 	core/java/android/bluetooth/IBluetoothGattCallback.aidl \
 	core/java/android/bluetooth/IBluetoothGattServerCallback.aidl \
-	core/java/android/bluetooth/IBluetoothSap.aidl \
-	core/java/android/bluetooth/IBluetoothDun.aidl \
 	core/java/android/content/IClipboard.aidl \
 	core/java/android/content/IContentService.aidl \
 	core/java/android/content/IIntentReceiver.aidl \
@@ -407,7 +399,6 @@ aidl_files := \
 	frameworks/base/core/java/com/android/internal/view/IInputMethodClient.aidl \
 	frameworks/base/core/java/com/android/internal/view/IInputMethodManager.aidl \
 	frameworks/base/core/java/com/android/internal/view/IInputMethodSession.aidl \
-        frameworks/base/core/java/android/bluetooth/BluetoothLEServiceUuid.aidl  \
 	frameworks/base/graphics/java/android/graphics/Bitmap.aidl \
 	frameworks/base/graphics/java/android/graphics/Rect.aidl \
 	frameworks/base/graphics/java/android/graphics/Region.aidl \

Nice!

There is another way. I only changed a few files in Bluetooth/jni. No need to change Settings, libhardware and frameworks.
This is my patched Bluetooth packages, Bluetooth.zip
1st March 2014, 06:23 PM |#22  
Senior Member
Thanks Meter: 2,152
 
Donate to Me
More
Quote:
Originally Posted by daniel_hk

Nice!

There is another way. I only changed a few files in Bluetooth/jni. No need to change Settings, libhardware and frameworks.
This is my patched Bluetooth packages, Attachment 2606121

Thanks I will check (I done in this way because I am lazy to fix code so choose brute approach xD)
1st March 2014, 06:45 PM |#23  
daniel_hk's Avatar
OP Inactive Recognized Contributor
Flag Hong Kong
Thanks Meter: 5,409
 
Donate to Me
More
Quote:
Originally Posted by 95A31

Thanks I will check (I done in this way because I am lazy to fix code so choose brute approach xD)

New commits always come. It is better touching the source lesser. Dealing with conflicts are even annoying.

Sent from my Nexus 7 using Tapatalk
3rd March 2014, 12:14 PM |#24  
Senior Member
Flag Athens
Thanks Meter: 1,299
 
More
Quote:
Originally Posted by daniel_hk

Nice!

There is another way. I only changed a few files in Bluetooth/jni. No need to change Settings, libhardware and frameworks.
This is my patched Bluetooth packages, Attachment 2606121

This is aosp bluetooth package? Have you only changed jni files or something from src as well? Because there also changes in abstraction layer in bt service (just an example). Can you provide a diff or a patch?
3rd March 2014, 12:56 PM |#25  
daniel_hk's Avatar
OP Inactive Recognized Contributor
Flag Hong Kong
Thanks Meter: 5,409
 
Donate to Me
More
Quote:
Originally Posted by Andrewasth

This is aosp bluetooth package? Have you only changed jni files or something from src as well? Because there also changes in abstraction layer in bt service (just an example). Can you provide a diff or a patch?

Yeah, this is base on the AOSP Bluetooth package. The one from CM cause crash loop. I start this first and if not working, I would start with the one from CM again. This is a seperate service and is the only change required. Just replace it with the CM package will do.

I followed the build errors and port the call backs required by CM. Only change 2 files in jni and another 2 in btservice. Further patching may requrired but there are only few functions left. Actually I have patched a little bit again for the new CM commits.

If you needed, I can attach the new patch when return home. I might upload it to my github when I have time. For the time being, you may clone the AOSP package to get the diff.

Edit: This is the new Bluetooth.zip. This Bluetooth patch is working on my cm11 and carbon builds since day one.
Good luck!
The Following User Says Thank You to daniel_hk For This Useful Post: [ View ] Gift daniel_hk Ad-Free
3rd March 2014, 01:26 PM |#26  
Senior Member
Flag Athens
Thanks Meter: 1,299
 
More
Quote:
Originally Posted by daniel_hk

Yeah, this is base on the AOSP Bluetooth package. The one from CM cause crash loop. I start this first and if not working, I would start with the one from CM again. This is a seperate service and is the only change required. Just replace it with the CM package will do.

I followed the build errors and port the call backs required by CM. Only change 2 files in jni and another 2 in btservice. Further patching may requrired but there are only few functions left. Actually I have patched a little bit again for the new CM commits.

If you needed, I can attach the new patch when return home. I might upload it to my github when I have time. For the time being, you may clone the AOSP package to get the diff.

I have cloned aosp package but I want to implement it on cm. So I will wait for your patch But it won't work on cm yet right? Implementing your modifications to cm bt package is enough or it needs further modification?
15th March 2014, 11:10 PM |#27  
Senior Member
Thanks Meter: 1,309
 
More
Do you know if there are any major Bluetooth differences between Android 4.3 and Android 4.4? I have an msm7x27a device for which I develop CM10.2, and I was wondering how I could get Bluetooth working. My device's stock ROM is ICS, so I came up with 3 potential solutions to get Bluetooth working on CM10.2 - port the Bluedroid driver and modify the kernel board files as necessary (which is proving to be tricky), port a 3.4 kernel (with help from some devs like TheWhisp who have ported 3.4 kernels for their devices. This one would probably be the hardest to do though), or port Bluez to CM10.2. It would be much appreciated if someone could help me out here. Would I have to change any steps to get this to work on CM10.2?
16th March 2014, 02:03 AM |#28  
daniel_hk's Avatar
OP Inactive Recognized Contributor
Flag Hong Kong
Thanks Meter: 5,409
 
Donate to Me
More
Quote:
Originally Posted by Codename13

Do you know if there are any major Bluetooth differences between Android 4.3 and Android 4.4? I have an msm7x27a device for which I develop CM10.2, and I was wondering how I could get Bluetooth working. My device's stock ROM is ICS, so I came up with 3 potential solutions to get Bluetooth working on CM10.2 - port the Bluedroid driver and modify the kernel board files as necessary (which is proving to be tricky), port a 3.4 kernel (with help from some devs like TheWhisp who have ported 3.4 kernels for their devices. This one would probably be the hardest to do though), or port Bluez to CM10.2. It would be much appreciated if someone could help me out here. Would I have to change any steps to get this to work on CM10.2?

There is already a successful port for msm7x27a on the last page: http://forum.xda-developers.com/show...6&postcount=18
You may ask him for detail.

Good luck!
17th March 2014, 02:01 AM |#29  
Senior Member
Thanks Meter: 1,309
 
More
I started with porting Bluez to CM10.2 by just doing step 1 (1.1 to 1.4) for now, just to see if I could get it to compile. Unfortunately, I'm getting this error
Quote:

external/bluetooth/bluez/android/hal-bluetooth.c:885:2: error: unknown field 'config_hci_snoop_log' specified in initializer
external/bluetooth/bluez/android/hal-bluetooth.c:885:2: warning: excess elements in struct initializer [enabled by default]
external/bluetooth/bluez/android/hal-bluetooth.c:885:2: warning: (near initialization for 'bluetooth_if') [enabled by default]

. I don't really care about the warnings, but how could I solve the error? I didn't change any code in the static 'config_hci_snoop_log', so what's causing the issue? Could the problem be caused as a result of using the latest BlueZ source (5.16)?
17th March 2014, 03:36 AM |#30  
alwaysadeel's Avatar
Senior Member
Thanks Meter: 3,553
 
More
Quote:
Originally Posted by daniel_hk

Yeah, this is base on the AOSP Bluetooth package. The one from CM cause crash loop. I start this first and if not working, I would start with the one from CM again. This is a seperate service and is the only change required. Just replace it with the CM package will do.

I followed the build errors and port the call backs required by CM. Only change 2 files in jni and another 2 in btservice. Further patching may requrired but there are only few functions left. Actually I have patched a little bit again for the new CM commits.

If you needed, I can attach the new patch when return home. I might upload it to my github when I have time. For the time being, you may clone the AOSP package to get the diff.

Edit: This is the new Attachment 2610895. This Bluetooth patch is working on my cm11 and carbon builds since day one.
Good luck!

thnx for ur work.

i used this attachment to build carbon with latest bluez. i wanted to know which files u actually changed. running diff with aosp packages/apps/bluetooth gives a very long file. is it aosp based?

Sent from my Nexus 7
17th March 2014, 04:47 AM |#31  
daniel_hk's Avatar
OP Inactive Recognized Contributor
Flag Hong Kong
Thanks Meter: 5,409
 
Donate to Me
More
Quote:
Originally Posted by Codename13

I started with porting Bluez to CM10.2 by just doing step 1 (1.1 to 1.4) for now, just to see if I could get it to compile. Unfortunately, I'm getting this error . I don't really care about the warnings, but how could I solve the error? I didn't change any code in the static 'config_hci_snoop_log', so what's causing the issue? Could the problem be caused as a result of using the latest BlueZ source (5.16)?

I'm using 5.16 too. The error you got is not related to cm10.2. Check the definition of bt_interface_t (in android/hardware/bluetooth.h), config_hci_snoop_log is missing in the definition. You might have messed up your bluez source. It's there in the original source.

Quote:
Originally Posted by XperiaMT27

thnx for ur work.

i used this attachment to build carbon with latest bluez. i wanted to know which files u actually changed. running diff with aosp packages/apps/bluetooth gives a very long file. is it aosp based?

Sent from my Nexus 7

I started with the aosp packages/apps, only changed a few files. File in jni might change a lot. I have added a few changes since then. Just to pass cm11 build (I use the same codes for carbon too). New Bluetooth.zip

Good luck!
The Following User Says Thank You to daniel_hk For This Useful Post: [ View ] Gift daniel_hk Ad-Free
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes