Bluetooth profile移植(键盘,鼠标)

Android bluetooth 现状

      截止到android2.2,Android只实现了Handset/Handfree和A2DP/AVRCP等Profile,而其它常用的 Profile如HID/DUN/SPP/OPP/FTP/PAN等却没有实现。Android的Handset/Handfree的实现方式和A2DP/AVRCP的方式有很大的不同,Handset/Handfree是直接在bluez的RFCOMM Socket上开发的,没有利用bluez的audio plugin,而A2DP/AVRCP是在bluez的audio plugin基础上开发的,所以大大降低了实现的难度。

HID 库编译

  HID要用到bluez的input plugin,Android已经把它编译进去了。目录在system/lib/bluez-plugin/input.so下。

HID JNI层

     参照frameworks/base/core/jni/android_server_BluetoothA2dpService.cpp,自己写一个 HID用的的.cpp文件,其中跟A2DP一样利用DBUS调用input.so库的CreateDevice/Connect/Disconnect等函数,具体源码在external/bluez/utils/input/manager.c和external/bluez/utils/input /device.c中。

HID Java框架层

    参照frameworks/base/core/java/android/server/BluetoothA2dpService.java和 frameworks/base/core/java/android/bluetooth/BluetoothA2dp.java及 frameworks/base/core/java/android/bluetooth/IBluetoothA2dp.aidl,自己分别写两个 JAVA类及AIDL接口。如下:HID AIDL接口

package android.bluetooth;

import android.bluetooth.BluetoothDevice;

/**
* System private API for Bluetooth HID service
*
* {@hide}
*/
interface IBluetoothHid {
boolean connectInputDevice(in BluetoothDevice device);
boolean disconnectInputDevice(in BluetoothDevice device);
BluetoothDevice[] getConnectedInputs(); // change to Set<> once AIDL supports
BluetoothDevice[] getNonDisconnectedInputs(); // change to Set<> once AIDL supports
int getInputState(in BluetoothDevice device);
boolean setInputPriority(in BluetoothDevice device, int priority);
int getInputPriority(in BluetoothDevice device);
}

余下的就是在packages/apps/Settings/src/com/android/settings/bluetooth目录下的各个文件的修改了,搜一下A2DP,只要是A2DP要修改的地方照葫芦画瓢添加修改就是了。

打开kernel uinput接口

    打开.config配置文件,设置CONFIG_INPUT_UINPUT=y。如果实现蓝牙鼠标和键盘profile成功,会生成类似/dev/input/mouse1和/dev/input/event5虚拟接口。

实现键盘和鼠标事件处理

    在android的事件处理机制中实现鼠标按键事件和移动事件。键盘默认已经实现。





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值