Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fbdd1374 authored by Himanshu Rawat's avatar Himanshu Rawat Committed by Gerrit Code Review
Browse files

Merge "HID host connection state changes and connection policy update to BTIF layer" into main

parents 0fe3744f aa383466
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -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;
@@ -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));
@@ -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},
+13 −9
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.bluetooth.hid;

import android.bluetooth.BluetoothProfile;
import android.util.Log;

import com.android.internal.annotations.GuardedBy;
@@ -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) {
@@ -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;
        }
    }

@@ -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();

@@ -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);

+233 −216
Original line number Diff line number Diff line
@@ -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());
@@ -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) {
@@ -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(
@@ -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))) {
+2 −1
Original line number Diff line number Diff line
@@ -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;
+3 −1
Original line number Diff line number Diff line
@@ -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;

@@ -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);
@@ -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,