Loading android/app/jni/com_android_bluetooth_hid_host.cpp +5 −4 Original line number Diff line number Diff line Loading @@ -293,7 +293,8 @@ static jboolean connectHidNative(JNIEnv* env, jobject /* object */, static jboolean disconnectHidNative(JNIEnv* env, jobject /* object */, jbyteArray address, jint address_type, jint transport) { jint transport, jboolean reconnect_allowed) { jbyte* addr; jboolean ret = JNI_TRUE; if (!sBluetoothHidInterface) return JNI_FALSE; Loading @@ -305,8 +306,8 @@ static jboolean disconnectHidNative(JNIEnv* env, jobject /* object */, } bt_status_t status = sBluetoothHidInterface->disconnect( (RawAddress*)addr, (tBLE_ADDR_TYPE)address_type, (tBT_TRANSPORT)transport); (RawAddress*)addr, (tBLE_ADDR_TYPE)address_type, (tBT_TRANSPORT)transport, reconnect_allowed); if (status != BT_STATUS_SUCCESS) { log::error("Failed disconnect hid channel, status: {}", bt_status_text(status)); Loading Loading @@ -541,7 +542,7 @@ int register_com_android_bluetooth_hid_host(JNIEnv* env) { {"initializeNative", "()V", (void*)initializeNative}, {"cleanupNative", "()V", (void*)cleanupNative}, {"connectHidNative", "([BII)Z", (void*)connectHidNative}, {"disconnectHidNative", "([BII)Z", (void*)disconnectHidNative}, {"disconnectHidNative", "([BIIZ)Z", (void*)disconnectHidNative}, {"getProtocolModeNative", "([BII)Z", (void*)getProtocolModeNative}, {"virtualUnPlugNative", "([BII)Z", (void*)virtualUnPlugNative}, {"setProtocolModeNative", "([BIIB)Z", (void*)setProtocolModeNative}, Loading android/app/src/com/android/bluetooth/hid/HidHostNativeInterface.java +13 −9 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package com.android.bluetooth.hid; import android.bluetooth.BluetoothProfile; import android.util.Log; import com.android.internal.annotations.GuardedBy; Loading Loading @@ -64,8 +63,9 @@ public class HidHostNativeInterface { return connectHidNative(address, addressType, transport); } boolean disconnectHid(byte[] address, int addressType, int transport) { return disconnectHidNative(address, addressType, transport); boolean disconnectHid( byte[] address, int addressType, int transport, boolean reconnectAllowed) { return disconnectHidNative(address, addressType, transport, reconnectAllowed); } boolean getProtocolMode(byte[] address, int addressType, int transport) { Loading Loading @@ -110,16 +110,18 @@ public class HidHostNativeInterface { private static int convertHalState(int halState) { switch (halState) { case CONN_STATE_CONNECTED: return BluetoothProfile.STATE_CONNECTED; return HidHostService.STATE_CONNECTED; case CONN_STATE_CONNECTING: return BluetoothProfile.STATE_CONNECTING; return HidHostService.STATE_CONNECTING; case CONN_STATE_DISCONNECTED: return BluetoothProfile.STATE_DISCONNECTED; return HidHostService.STATE_DISCONNECTED; case CONN_STATE_DISCONNECTING: return BluetoothProfile.STATE_DISCONNECTING; return HidHostService.STATE_DISCONNECTING; case CONN_STATE_ACCEPTING: return HidHostService.STATE_ACCEPTING; default: Log.e(TAG, "bad hid connection state: " + halState); return BluetoothProfile.STATE_DISCONNECTED; return HidHostService.STATE_DISCONNECTED; } } Loading Loading @@ -170,6 +172,7 @@ public class HidHostNativeInterface { private static final int CONN_STATE_CONNECTING = 1; private static final int CONN_STATE_DISCONNECTED = 2; private static final int CONN_STATE_DISCONNECTING = 3; private static final int CONN_STATE_ACCEPTING = 4; private native void initializeNative(); Loading @@ -177,7 +180,8 @@ public class HidHostNativeInterface { private native boolean connectHidNative(byte[] btAddress, int addressType, int transport); private native boolean disconnectHidNative(byte[] btAddress, int addressType, int transport); private native boolean disconnectHidNative( byte[] btAddress, int addressType, int transport, boolean reconnectAllowed); private native boolean getProtocolModeNative(byte[] btAddress, int addressType, int transport); Loading android/app/src/com/android/bluetooth/hid/HidHostService.java +233 −216 Original line number Diff line number Diff line Loading @@ -88,6 +88,12 @@ public class HidHostService extends ProfileService { private static final int MESSAGE_ON_GET_IDLE_TIME = 15; private static final int MESSAGE_SET_IDLE_TIME = 16; public static final int STATE_DISCONNECTED = BluetoothProfile.STATE_DISCONNECTED; public static final int STATE_CONNECTING = BluetoothProfile.STATE_CONNECTING; public static final int STATE_CONNECTED = BluetoothProfile.STATE_CONNECTED; public static final int STATE_DISCONNECTING = BluetoothProfile.STATE_DISCONNECTING; public static final int STATE_ACCEPTING = BluetoothProfile.STATE_DISCONNECTING + 1; public HidHostService(Context ctx) { super(ctx); mNativeInterface = requireNonNull(HidHostNativeInterface.getInstance()); Loading Loading @@ -181,7 +187,8 @@ public class HidHostService extends ProfileService { sHidHostService = instance; } private final Handler mHandler = new Handler() { private final Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { Loading @@ -206,11 +213,17 @@ public class HidHostService extends ProfileService { break; case MESSAGE_DISCONNECT: { BluetoothDevice device = (BluetoothDevice) msg.obj; boolean reconnectAllowed = false; if (getConnectionPolicy(device) == BluetoothProfile.CONNECTION_POLICY_ALLOWED) { reconnectAllowed = true; } // TODO: b/324094542 Use the preferred transport if (!mNativeInterface.disconnectHid( getByteAddress(device), BluetoothDevice.ADDRESS_TYPE_PUBLIC, BluetoothDevice.TRANSPORT_AUTO)) { BluetoothDevice.TRANSPORT_AUTO, reconnectAllowed)) { broadcastConnectionState( device, BluetoothProfile.STATE_DISCONNECTING); broadcastConnectionState( Loading @@ -235,6 +248,10 @@ public class HidHostService extends ProfileService { + (" newState=" + state) + (" prevState=" + prevState)); } if (state == STATE_ACCEPTING) { // TODO: b/324094542 save the preferred transport state = BluetoothProfile.STATE_DISCONNECTED; } if (state == BluetoothProfile.STATE_CONNECTED && prevState == BluetoothProfile.STATE_DISCONNECTED && (!okToConnect(device))) { Loading system/btif/src/btif_hh.cc +2 −1 Original line number Diff line number Diff line Loading @@ -1382,7 +1382,8 @@ static bt_status_t connect(RawAddress* bd_addr, tBLE_ADDR_TYPE addr_type, * ******************************************************************************/ static bt_status_t disconnect(RawAddress* bd_addr, tBLE_ADDR_TYPE addr_type, tBT_TRANSPORT transport) { tBT_TRANSPORT transport, bool /* reconnect_allowed */) { CHECK_BTHH_INIT(); log::verbose("BTHH"); btif_hh_device_t* p_dev; Loading system/include/hardware/bt_hh.h +3 −1 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ typedef enum { BTHH_CONN_STATE_CONNECTING = 1, BTHH_CONN_STATE_DISCONNECTED = 2, BTHH_CONN_STATE_DISCONNECTING = 3, BTHH_CONN_STATE_ACCEPTING = 4, BTHH_CONN_STATE_UNKNOWN = 0xff, } bthh_connection_state_t; Loading @@ -48,6 +49,7 @@ inline std::string bthh_connection_state_text( CASE_RETURN_TEXT(BTHH_CONN_STATE_CONNECTING); CASE_RETURN_TEXT(BTHH_CONN_STATE_DISCONNECTED); CASE_RETURN_TEXT(BTHH_CONN_STATE_DISCONNECTING); CASE_RETURN_TEXT(BTHH_CONN_STATE_ACCEPTING); CASE_RETURN_TEXT(BTHH_CONN_STATE_UNKNOWN); default: return base::StringPrintf("UNKNOWN[%d]", state); Loading Loading @@ -195,7 +197,7 @@ typedef struct { /** dis-connect from hid device */ bt_status_t (*disconnect)(RawAddress* bd_addr, tBLE_ADDR_TYPE addr_type, tBT_TRANSPORT transport); tBT_TRANSPORT transport, bool reconnect_allowed); /** Virtual UnPlug (VUP) the specified HID device */ bt_status_t (*virtual_unplug)(RawAddress* bd_addr, tBLE_ADDR_TYPE addr_type, Loading Loading
android/app/jni/com_android_bluetooth_hid_host.cpp +5 −4 Original line number Diff line number Diff line Loading @@ -293,7 +293,8 @@ static jboolean connectHidNative(JNIEnv* env, jobject /* object */, static jboolean disconnectHidNative(JNIEnv* env, jobject /* object */, jbyteArray address, jint address_type, jint transport) { jint transport, jboolean reconnect_allowed) { jbyte* addr; jboolean ret = JNI_TRUE; if (!sBluetoothHidInterface) return JNI_FALSE; Loading @@ -305,8 +306,8 @@ static jboolean disconnectHidNative(JNIEnv* env, jobject /* object */, } bt_status_t status = sBluetoothHidInterface->disconnect( (RawAddress*)addr, (tBLE_ADDR_TYPE)address_type, (tBT_TRANSPORT)transport); (RawAddress*)addr, (tBLE_ADDR_TYPE)address_type, (tBT_TRANSPORT)transport, reconnect_allowed); if (status != BT_STATUS_SUCCESS) { log::error("Failed disconnect hid channel, status: {}", bt_status_text(status)); Loading Loading @@ -541,7 +542,7 @@ int register_com_android_bluetooth_hid_host(JNIEnv* env) { {"initializeNative", "()V", (void*)initializeNative}, {"cleanupNative", "()V", (void*)cleanupNative}, {"connectHidNative", "([BII)Z", (void*)connectHidNative}, {"disconnectHidNative", "([BII)Z", (void*)disconnectHidNative}, {"disconnectHidNative", "([BIIZ)Z", (void*)disconnectHidNative}, {"getProtocolModeNative", "([BII)Z", (void*)getProtocolModeNative}, {"virtualUnPlugNative", "([BII)Z", (void*)virtualUnPlugNative}, {"setProtocolModeNative", "([BIIB)Z", (void*)setProtocolModeNative}, Loading
android/app/src/com/android/bluetooth/hid/HidHostNativeInterface.java +13 −9 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package com.android.bluetooth.hid; import android.bluetooth.BluetoothProfile; import android.util.Log; import com.android.internal.annotations.GuardedBy; Loading Loading @@ -64,8 +63,9 @@ public class HidHostNativeInterface { return connectHidNative(address, addressType, transport); } boolean disconnectHid(byte[] address, int addressType, int transport) { return disconnectHidNative(address, addressType, transport); boolean disconnectHid( byte[] address, int addressType, int transport, boolean reconnectAllowed) { return disconnectHidNative(address, addressType, transport, reconnectAllowed); } boolean getProtocolMode(byte[] address, int addressType, int transport) { Loading Loading @@ -110,16 +110,18 @@ public class HidHostNativeInterface { private static int convertHalState(int halState) { switch (halState) { case CONN_STATE_CONNECTED: return BluetoothProfile.STATE_CONNECTED; return HidHostService.STATE_CONNECTED; case CONN_STATE_CONNECTING: return BluetoothProfile.STATE_CONNECTING; return HidHostService.STATE_CONNECTING; case CONN_STATE_DISCONNECTED: return BluetoothProfile.STATE_DISCONNECTED; return HidHostService.STATE_DISCONNECTED; case CONN_STATE_DISCONNECTING: return BluetoothProfile.STATE_DISCONNECTING; return HidHostService.STATE_DISCONNECTING; case CONN_STATE_ACCEPTING: return HidHostService.STATE_ACCEPTING; default: Log.e(TAG, "bad hid connection state: " + halState); return BluetoothProfile.STATE_DISCONNECTED; return HidHostService.STATE_DISCONNECTED; } } Loading Loading @@ -170,6 +172,7 @@ public class HidHostNativeInterface { private static final int CONN_STATE_CONNECTING = 1; private static final int CONN_STATE_DISCONNECTED = 2; private static final int CONN_STATE_DISCONNECTING = 3; private static final int CONN_STATE_ACCEPTING = 4; private native void initializeNative(); Loading @@ -177,7 +180,8 @@ public class HidHostNativeInterface { private native boolean connectHidNative(byte[] btAddress, int addressType, int transport); private native boolean disconnectHidNative(byte[] btAddress, int addressType, int transport); private native boolean disconnectHidNative( byte[] btAddress, int addressType, int transport, boolean reconnectAllowed); private native boolean getProtocolModeNative(byte[] btAddress, int addressType, int transport); Loading
android/app/src/com/android/bluetooth/hid/HidHostService.java +233 −216 Original line number Diff line number Diff line Loading @@ -88,6 +88,12 @@ public class HidHostService extends ProfileService { private static final int MESSAGE_ON_GET_IDLE_TIME = 15; private static final int MESSAGE_SET_IDLE_TIME = 16; public static final int STATE_DISCONNECTED = BluetoothProfile.STATE_DISCONNECTED; public static final int STATE_CONNECTING = BluetoothProfile.STATE_CONNECTING; public static final int STATE_CONNECTED = BluetoothProfile.STATE_CONNECTED; public static final int STATE_DISCONNECTING = BluetoothProfile.STATE_DISCONNECTING; public static final int STATE_ACCEPTING = BluetoothProfile.STATE_DISCONNECTING + 1; public HidHostService(Context ctx) { super(ctx); mNativeInterface = requireNonNull(HidHostNativeInterface.getInstance()); Loading Loading @@ -181,7 +187,8 @@ public class HidHostService extends ProfileService { sHidHostService = instance; } private final Handler mHandler = new Handler() { private final Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { Loading @@ -206,11 +213,17 @@ public class HidHostService extends ProfileService { break; case MESSAGE_DISCONNECT: { BluetoothDevice device = (BluetoothDevice) msg.obj; boolean reconnectAllowed = false; if (getConnectionPolicy(device) == BluetoothProfile.CONNECTION_POLICY_ALLOWED) { reconnectAllowed = true; } // TODO: b/324094542 Use the preferred transport if (!mNativeInterface.disconnectHid( getByteAddress(device), BluetoothDevice.ADDRESS_TYPE_PUBLIC, BluetoothDevice.TRANSPORT_AUTO)) { BluetoothDevice.TRANSPORT_AUTO, reconnectAllowed)) { broadcastConnectionState( device, BluetoothProfile.STATE_DISCONNECTING); broadcastConnectionState( Loading @@ -235,6 +248,10 @@ public class HidHostService extends ProfileService { + (" newState=" + state) + (" prevState=" + prevState)); } if (state == STATE_ACCEPTING) { // TODO: b/324094542 save the preferred transport state = BluetoothProfile.STATE_DISCONNECTED; } if (state == BluetoothProfile.STATE_CONNECTED && prevState == BluetoothProfile.STATE_DISCONNECTED && (!okToConnect(device))) { Loading
system/btif/src/btif_hh.cc +2 −1 Original line number Diff line number Diff line Loading @@ -1382,7 +1382,8 @@ static bt_status_t connect(RawAddress* bd_addr, tBLE_ADDR_TYPE addr_type, * ******************************************************************************/ static bt_status_t disconnect(RawAddress* bd_addr, tBLE_ADDR_TYPE addr_type, tBT_TRANSPORT transport) { tBT_TRANSPORT transport, bool /* reconnect_allowed */) { CHECK_BTHH_INIT(); log::verbose("BTHH"); btif_hh_device_t* p_dev; Loading
system/include/hardware/bt_hh.h +3 −1 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ typedef enum { BTHH_CONN_STATE_CONNECTING = 1, BTHH_CONN_STATE_DISCONNECTED = 2, BTHH_CONN_STATE_DISCONNECTING = 3, BTHH_CONN_STATE_ACCEPTING = 4, BTHH_CONN_STATE_UNKNOWN = 0xff, } bthh_connection_state_t; Loading @@ -48,6 +49,7 @@ inline std::string bthh_connection_state_text( CASE_RETURN_TEXT(BTHH_CONN_STATE_CONNECTING); CASE_RETURN_TEXT(BTHH_CONN_STATE_DISCONNECTED); CASE_RETURN_TEXT(BTHH_CONN_STATE_DISCONNECTING); CASE_RETURN_TEXT(BTHH_CONN_STATE_ACCEPTING); CASE_RETURN_TEXT(BTHH_CONN_STATE_UNKNOWN); default: return base::StringPrintf("UNKNOWN[%d]", state); Loading Loading @@ -195,7 +197,7 @@ typedef struct { /** dis-connect from hid device */ bt_status_t (*disconnect)(RawAddress* bd_addr, tBLE_ADDR_TYPE addr_type, tBT_TRANSPORT transport); tBT_TRANSPORT transport, bool reconnect_allowed); /** Virtual UnPlug (VUP) the specified HID device */ bt_status_t (*virtual_unplug)(RawAddress* bd_addr, tBLE_ADDR_TYPE addr_type, Loading