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

Commit 62cb1d82 authored by Avish Shah's avatar Avish Shah Committed by android-build-merger
Browse files

Merge "Bluetooth 5: Update LE2M implementation through DM (1/3)"

am: 79ba291e

Change-Id: I90046b5f37d866ce0c047ac38e48b954e980a3b2
parents 88beda21 79ba291e
Loading
Loading
Loading
Loading
+42 −22
Original line number Diff line number Diff line
@@ -848,7 +848,7 @@ static void classInitNative(JNIEnv* env, jclass clazz) {
  method_onGetGattDb =
      env->GetMethodID(clazz, "onGetGattDb", "(ILjava/util/ArrayList;)V");
  method_onClientPhyRead =
      env->GetMethodID(clazz, "onClientPhyRead", "(IIII)V");
      env->GetMethodID(clazz, "onClientPhyRead", "(ILjava/lang/String;III)V");
  method_onClientPhyUpdate =
      env->GetMethodID(clazz, "onClientPhyUpdate", "(IIII)V");
  method_onClientConnUpdate =
@@ -884,7 +884,7 @@ static void classInitNative(JNIEnv* env, jclass clazz) {
      env->GetMethodID(clazz, "onServerCongestion", "(IZ)V");
  method_onServerMtuChanged = env->GetMethodID(clazz, "onMtuChanged", "(II)V");
  method_onServerPhyRead =
      env->GetMethodID(clazz, "onServerPhyRead", "(IIII)V");
      env->GetMethodID(clazz, "onServerPhyRead", "(ILjava/lang/String;III)V");
  method_onServerPhyUpdate =
      env->GetMethodID(clazz, "onServerPhyUpdate", "(IIII)V");
  method_onServerConnUpdate =
@@ -1027,26 +1027,35 @@ static void gattClientDisconnectNative(JNIEnv* env, jobject object,
}

static void gattClientSetPreferredPhyNative(JNIEnv* env, jobject object,
                                            jint clientIf, jint conn_id,
                                            jint clientIf, jstring address,
                                            jint tx_phy, jint rx_phy,
                                            jint phy_options) {
  if (!sGattIf) return;
  sGattIf->client->set_preferred_phy(conn_id, tx_phy, rx_phy, phy_options);
  bt_bdaddr_t bda;
  jstr2bdaddr(env, &bda, address);
  sGattIf->client->set_preferred_phy(bda, tx_phy, rx_phy, phy_options);
}

static void readClientPhyCb(int conn_id, uint8_t tx_phy, uint8_t rx_phy,
                            uint8_t status) {
static void readClientPhyCb(uint8_t clientIf, bt_bdaddr_t bda, uint8_t tx_phy,
                            uint8_t rx_phy, uint8_t status) {
  CallbackEnv sCallbackEnv(__func__);
  if (!sCallbackEnv.valid()) return;

  sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onClientPhyRead, conn_id,
                               tx_phy, rx_phy, status);
  ScopedLocalRef<jstring> address(sCallbackEnv.get(),
                                  bdaddr2newjstr(sCallbackEnv.get(), &bda));

  sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onClientPhyRead, clientIf,
                               address.get(), tx_phy, rx_phy, status);
}

static void gattClientReadPhyNative(JNIEnv* env, jobject object, jint clientIf,
                                    jint conn_id) {
                                    jstring address) {
  if (!sGattIf) return;
  sGattIf->client->read_phy(conn_id, base::Bind(readClientPhyCb, conn_id));

  bt_bdaddr_t bda;
  jstr2bdaddr(env, &bda, address);

  sGattIf->client->read_phy(bda, base::Bind(&readClientPhyCb, clientIf, bda));
}

static void gattClientRefreshNative(JNIEnv* env, jobject object, jint clientIf,
@@ -1055,6 +1064,7 @@ static void gattClientRefreshNative(JNIEnv* env, jobject object, jint clientIf,

  bt_bdaddr_t bda;
  jstr2bdaddr(env, &bda, address);

  sGattIf->client->refresh(clientIf, &bda);
}

@@ -1535,26 +1545,34 @@ static void gattServerDisconnectNative(JNIEnv* env, jobject object,
}

static void gattServerSetPreferredPhyNative(JNIEnv* env, jobject object,
                                            jint serverIf, jint conn_id,
                                            jint serverIf, jstring address,
                                            jint tx_phy, jint rx_phy,
                                            jint phy_options) {
  if (!sGattIf) return;
  sGattIf->server->set_preferred_phy(conn_id, tx_phy, rx_phy, phy_options);
  bt_bdaddr_t bda;
  jstr2bdaddr(env, &bda, address);
  sGattIf->server->set_preferred_phy(bda, tx_phy, rx_phy, phy_options);
}

static void readServerPhyCb(int conn_id, uint8_t tx_phy, uint8_t rx_phy,
                            uint8_t status) {
static void readServerPhyCb(uint8_t serverIf, bt_bdaddr_t bda, uint8_t tx_phy,
                            uint8_t rx_phy, uint8_t status) {
  CallbackEnv sCallbackEnv(__func__);
  if (!sCallbackEnv.valid()) return;

  sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onServerPhyRead, conn_id,
                               tx_phy, rx_phy, status);
  ScopedLocalRef<jstring> address(sCallbackEnv.get(),
                                  bdaddr2newjstr(sCallbackEnv.get(), &bda));

  sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onServerPhyRead, serverIf,
                               address.get(), tx_phy, rx_phy, status);
}

static void gattServerReadPhyNative(JNIEnv* env, jobject object, jint serverIf,
                                    jint conn_id) {
                                    jstring address) {
  if (!sGattIf) return;
  sGattIf->server->read_phy(conn_id, base::Bind(readServerPhyCb, conn_id));

  bt_bdaddr_t bda;
  jstr2bdaddr(env, &bda, address);
  sGattIf->server->read_phy(bda, base::Bind(&readServerPhyCb, serverIf, bda));
}

static void gattServerAddServiceNative(JNIEnv* env, jobject object,
@@ -2176,9 +2194,10 @@ static JNINativeMethod sMethods[] = {
     (void*)gattClientConnectNative},
    {"gattClientDisconnectNative", "(ILjava/lang/String;I)V",
     (void*)gattClientDisconnectNative},
    {"gattClientSetPreferredPhyNative", "(IIIII)V",
    {"gattClientSetPreferredPhyNative", "(ILjava/lang/String;III)V",
     (void*)gattClientSetPreferredPhyNative},
    {"gattClientReadPhyNative", "(II)V", (void*)gattClientReadPhyNative},
    {"gattClientReadPhyNative", "(ILjava/lang/String;)V",
     (void*)gattClientReadPhyNative},
    {"gattClientRefreshNative", "(ILjava/lang/String;)V",
     (void*)gattClientRefreshNative},
    {"gattClientSearchServiceNative", "(IZJJ)V",
@@ -2214,9 +2233,10 @@ static JNINativeMethod sMethods[] = {
     (void*)gattServerConnectNative},
    {"gattServerDisconnectNative", "(ILjava/lang/String;I)V",
     (void*)gattServerDisconnectNative},
    {"gattServerSetPreferredPhyNative", "(IIIII)V",
    {"gattServerSetPreferredPhyNative", "(ILjava/lang/String;III)V",
     (void*)gattServerSetPreferredPhyNative},
    {"gattServerReadPhyNative", "(II)V", (void*)gattServerReadPhyNative},
    {"gattServerReadPhyNative", "(ILjava/lang/String;)V",
     (void*)gattServerReadPhyNative},
    {"gattServerAddServiceNative", "(ILjava/util/List;)V",
     (void*)gattServerAddServiceNative},
    {"gattServerStopServiceNative", "(II)V",
+26 −16
Original line number Diff line number Diff line
@@ -854,11 +854,17 @@ public class GattService extends ProfileService {
        app.callback.onPhyUpdate(address, txPhy, rxPhy, status);
    }

    void onClientPhyRead(int connId, int txPhy, int rxPhy, int status) throws RemoteException {
        if (DBG) Log.d(TAG, "onClientPhyRead() - connId=" + connId + ", status=" + status);
    void onClientPhyRead(int clientIf, String address, int txPhy, int rxPhy, int status)
            throws RemoteException {
        if (DBG)
            Log.d(TAG, "onClientPhyRead() - address=" + address + ", status=" + status
                            + ", clientIf=" + clientIf);

        String address = mClientMap.addressByConnId(connId);
        if (address == null) return;
        Integer connId = mClientMap.connIdByAddress(clientIf, address);
        if (connId == null) {
            Log.d(TAG, "onClientPhyRead() - no connection to " + address);
            return;
        }

        ClientMap.App app = mClientMap.getByConnId(connId);
        if (app == null) return;
@@ -891,11 +897,15 @@ public class GattService extends ProfileService {
        app.callback.onPhyUpdate(address, txPhy, rxPhy, status);
    }

    void onServerPhyRead(int connId, int txPhy, int rxPhy, int status) throws RemoteException {
        if (DBG) Log.d(TAG, "onServerPhyRead() - connId=" + connId + ", status=" + status);
    void onServerPhyRead(int serverIf, String address, int txPhy, int rxPhy, int status)
            throws RemoteException {
        if (DBG) Log.d(TAG, "onServerPhyRead() - address=" + address + ", status=" + status);

        String address = mServerMap.addressByConnId(connId);
        if (address == null) return;
        Integer connId = mServerMap.connIdByAddress(serverIf, address);
        if (connId == null) {
            Log.d(TAG, "onServerPhyRead() - no connection to " + address);
            return;
        }

        ServerMap.App app = mServerMap.getByConnId(connId);
        if (app == null) return;
@@ -1631,7 +1641,7 @@ public class GattService extends ProfileService {
        }

        if (DBG) Log.d(TAG, "clientSetPreferredPhy() - address=" + address + ", connId=" + connId);
        gattClientSetPreferredPhyNative(clientIf, connId, txPhy, rxPhy, phyOptions);
        gattClientSetPreferredPhyNative(clientIf, address, txPhy, rxPhy, phyOptions);
    }

    void clientReadPhy(int clientIf, String address) {
@@ -1644,7 +1654,7 @@ public class GattService extends ProfileService {
        }

        if (DBG) Log.d(TAG, "clientReadPhy() - address=" + address + ", connId=" + connId);
        gattClientReadPhyNative(clientIf, connId);
        gattClientReadPhyNative(clientIf, address);
    }

    int numHwTrackFiltersAvailable() {
@@ -2182,7 +2192,7 @@ public class GattService extends ProfileService {
        }

        if (DBG) Log.d(TAG, "serverSetPreferredPhy() - address=" + address + ", connId=" + connId);
        gattServerSetPreferredPhyNative(serverIf, connId, txPhy, rxPhy, phyOptions);
        gattServerSetPreferredPhyNative(serverIf, address, txPhy, rxPhy, phyOptions);
    }

    void serverReadPhy(int serverIf, String address) {
@@ -2195,7 +2205,7 @@ public class GattService extends ProfileService {
        }

        if (DBG) Log.d(TAG, "serverReadPhy() - address=" + address + ", connId=" + connId);
        gattServerReadPhyNative(serverIf, connId);
        gattServerReadPhyNative(serverIf, address);
    }

    void addService(int serverIf, BluetoothGattService service) {
@@ -2503,9 +2513,9 @@ public class GattService extends ProfileService {
            int conn_id);

    private native void gattClientSetPreferredPhyNative(
            int clientIf, int conn_id, int tx_phy, int rx_phy, int phy_options);
            int clientIf, String address, int tx_phy, int rx_phy, int phy_options);

    private native void gattClientReadPhyNative(int clientIf, int conn_id);
    private native void gattClientReadPhyNative(int clientIf, String address);

    private native void gattClientRefreshNative(int clientIf, String address);

@@ -2555,9 +2565,9 @@ public class GattService extends ProfileService {
                                              int conn_id);

    private native void gattServerSetPreferredPhyNative(
            int clientIf, int conn_id, int tx_phy, int rx_phy, int phy_options);
            int clientIf, String address, int tx_phy, int rx_phy, int phy_options);

    private native void gattServerReadPhyNative(int clientIf, int conn_id);
    private native void gattServerReadPhyNative(int clientIf, String address);

    private native void gattServerAddServiceNative(int server_if, List<GattDbElement> service);