目录:
0 应用层设计相关
一、application Framework
二、Bluetooth server层:服务层 包括两部分--Bluetooth System service(部分)和Bluetooth profile;
2.1 mtk 封装的库(JNI和中间协议)
三、JNI
四、HAL
五、BT stack---- 实现(中间协议+核心协议)。
六、Vendor extension---也就是HCI驱动层的用户空间接口
七 system\bluetoothBluetooth (mtk removed it )
八 内核层
九 驱动层
================================================================
0 应用层设计相关
|
kitkat_ibd\packages\apps\Settings\src\com\android\settings\bluetooth -----android 4.4
|
谷歌原生的profile管理接口。包括opp、hfp、hdp、a2dp、pan,gatt等等, 这里自称为面向应用的profile接口。
|
|
|
|
一、application Framework
这个层的代码主要是利用android.bluetoothAPIS和 bluetooth hardware进行交互。也就是通过BinderIPC机制调用bluetooth进程;
Android原生的BTFramework代码位于framework/base/core/java/android.bluetooth/下。 |
这个目录里的代码更像一个桥梁,里面有供java层使用一些类,也有对应的aidl文件联系C、C++部分的代码,包括opp、hfp、hdp、a2dp、pan,gatt等等 |
MTK厂商客制化的修改代码位于 \mediatek\frameworks-ext\base\core\java\android\bluetooth |
重写了原生部分的BT代码,而且各种profile API:是桥接application和server之间的接口:BluetoothFtp.java /BluetoothHealth.ajva /BluetoothHid.java……. |
两者什么关系?增加了自己的相关profile server桥接接口(与Bluetooth的server层 profile对应的):如下:
LOCAL_SRC_FILES += \
../../mediatek/frameworks-ext/base/core/java/android/bluetooth/IBluetoothBipi.aidl \
../../mediatek/frameworks-ext/base/core/java/android/bluetooth/IBluetoothBipr.aidl\
../../mediatek/frameworks-ext/base/core/java/android/bluetooth/IBluetoothBpp.aidl \
../../mediatek/frameworks-ext/base/core/java/android/bluetooth/IBluetoothDun.aidl \
../../mediatek/frameworks-ext/base/core/java/android/bluetooth/IBluetoothFtpCtrl.aidl\
../../mediatek/frameworks-ext/base/core/java/android/bluetooth/IBluetoothFtpServer.aidl \
../../mediatek/frameworks-ext/base/core/java/android/bluetooth/IBluetoothFtpServerCallback.aidl\
../../mediatek/frameworks-ext/base/core/java/android/bluetooth/IBluetoothProfileManager.aidl\
../../mediatek/frameworks-ext/base/core/java/android/bluetooth/IBluetoothSimap.aidl\
../../mediatek/frameworks-ext/base/core/java/android/bluetooth/IBluetoothSimapCallback.aidl\
../../mediatek/frameworks-ext/base/core/java/com/mediatek/bluetooth/service/IBluetoothPrxm.aidl\
../../mediatek/frameworks-ext/base/core/java/com/mediatek/bluetooth/service/IBluetoothPrxr.aidl\
../../mediatek/frameworks-ext/base/core/java/android/net/INetworkManagementIpv6EventObserver.aidl
如何编译?
通过\frameworks\base的Android,.mk包含include$(LOCAL_PATH)/../../mediatek/frameworks-ext/base/config.mk完成把:mtk客制化增加的framework和原生的BTFramework的整合->生成:framework.jar。
下面仅仅是原生的例子:
比如A2DP的连接:framework/base/core/java/android/bluetooth/BluetoothA2dp.java中的connect(Bluetoothevice)方法。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
public boolean connect(BluetoothDevice device) { if (DBG) log("connect(" + device + ")"); if (mService != null && isEnabled() && isValidDevice(device)) { try { return mService.connect(device); } catch (RemoteException e) { Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); return false; } } if (mService == null) Log.w(TAG, "Proxy not attached to service"); return false; } |
通过Binder IPC通信机制,调用到packages/apps/Bluetooth/src/com.android.bluetooth.a2dp/A2dpService.java下一个内部私有类
A2dpService是一个继承于ProfileService的类,而类ProfileService是继承于Service类的。
private static class BluetoothA2dpBinder extendsIBluetoothA2dp.Stub{}的connect(BluetoothDevice)方法。
1 2 3 4 5 |
public boolean connect(BluetoothDevice device) { A2dpService service = getService(); if (service == null) return false; return service.connect(device); } |
然后调用到A2dpService的connect(BluetoothDevice)方法。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
public boolean connect(BluetoothDevice device) { enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH ADMIN permission");
if (getPriority(device) == BluetoothProfile.PRIORITY_OFF) { return false; }
int connectionState = mStateMachine.getConnectionState(device); if (connectionState == BluetoothProfile.STATE_CONNECTED || connectionState == BluetoothProfile.STATE_CONNECTING) { return false; }
mStateMachine.sendMessage(A2dpStateMachine.CONNECT, device); return true; } |
这个过程就是Bluetooth Application Framework与Bluetooth Process的调用过程。
二、Bluetooth server层:服务层 包括两部分--Bluetooth System service(部分)和Bluetoothprofile;
1.Bluetooth System service<