1. 程式人生 > >android5.1藍芽反向控制(Avrcp協議)流程

android5.1藍芽反向控制(Avrcp協議)流程

  private BluetoothAvrcpController mAvrcpController;
  List<BluetoothDevice> devices = mAvrcpController.getConnectedDevices(); 
  for(BluetoothDevice device : devices)
  {
    mAvrcpController.sendPassThroughCmd(device, 68, BluetoothAvrcp.PASSTHROUGH_STATE_PRESS);
    mAvrcpController.sendPassThroughCmd(device, 68, BluetoothAvrcp.PASSTHROUGH_STATE_RELEASE);
  }
2.frameworks/base/core/java/android/bluetooth/BluetoothAvrcpController.java
  public void sendPassThroughCmd(BluetoothDevice device, int keyCode, int keyState)
  {
    mService.sendPassThroughCmd(device, keyCode, keyState);  
  }
3.packages/apps/Bluetooth/src/com/android/bluetooth/avrcp/AvrcpControllerService.java
     private native boolean sendPassThroughCommandNative(byte[] address, int keyCode, int keyState);
  (1)public void sendPassThroughCmd(BluetoothDevice device, int keyCode, int keyState)
     {
      Message msg = mHandler.obtainMessage(MESSAGE_SEND_PASS_THROUGH_CMD, keyCode, keyState, device);
      mHandler.sendMessage(msg);
     }
  (2)private final class AvrcpMessageHandler extends Handler
     {
        public void handleMessage(Message msg)
        {
         switch (msg.what)
         {                                                                                                                                                                                
           case MESSAGE_SEND_PASS_THROUGH_CMD:                                                                                                                                                                
               if (DBG) Log.v(TAG, "MESSAGE_SEND_PASS_THROUGH_CMD");                                                                                                                                          
               BluetoothDevice device = (BluetoothDevice)msg.obj;                                                                                                                                             
               sendPassThroughCommandNative(getByteAddress(device), msg.arg1, msg.arg2);                                                                                                                      
               break;                                                                                                                                                                                         
         }
     }
4.packages/apps/Bluetooth/jni/com_android_bluetooth_avrcp_controller.cpp
  static jboolean sendPassThroughCommandNative(JNIEnv *env, jobject object, jbyteArray address, jint key_code, jint key_state)
  {
    sBluetoothAvrcpInterface->send_pass_through_cmd((bt_bdaddr_t *)addr,uint8_t)key_code, (uint8_t)key_state))!= BT_STATUS_SUCCESS);
  } 
5.external/bluetooth/bluedroid/btif/src/btif_rc.c
  static bt_status_t send_passthrough_cmd(bt_bdaddr_t *bd_addr, uint8_t key_code, uint8_t key_state)
  {
    bt_status_t tran_status = get_transaction(&p_transaction); 
    BTA_AvRemoteCmd();
  }