1. 当用户在setting的bluetooth device list中选择了input设备后会触发起所有profile的connect操作,input设备在Setting中叫做HidProfile.java.
值得我们注意的是Android的BluetoothInputDevice是通过getProfileProxy的方法取得的,这点并不同于HFP或HSP.
2. HidProfile通过调用BluetoothInputDevice的connect,如果是有效的设备则BluetoothInputDevice会直接调用bluetoothservice的connectInputDevice函式。
3. 其中bluetoothservice也就是简单的调用了BluetoothInputProfileHandler的connectInputDevice函式。connectInputDevice会向BluetoothDeviceProfileState发送CONNECT_HID_OUTGOING消息。
Framework中包含了很多profilehandler, 这些Handler有个共同的特点是都包含了一个此profile的设备列表。
4. BluetoothDeviceProfileState会切至OutgoingHidstate.此时OutgoingHid将deferMessageCONNECT_HID_OUTGOING消息并且交由BluetoothDeviceProfileState类的processCommand处理,在些它调用了BluetoothService的connectInputDeviceInternal.
5. 在些BluetoothService又去调用了mBluetoothInputProfileHandler的connectInputDeviceInternal,在其中其调用了jni方法BluetoothService的connectInputDeviceNative方法。此时的DBUS调用为异步调用。
6. 当Bluez在Input接口上连接成功后,会调用之前注册的onInputDeviceConnectionResult函数,(onInputDeviceConnectionResult是EventLoop中的函数)。
7. onInputDeviceConnectionResult将解析bluez返回的path,其格式中包含了address,所以androide有替换”_”到”:”. 后呼叫了BluetoothService的handleInputDevicePropertyChange去通过mBluetoothInputProfileHandler更新其中设备的连接状态。