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

Commit dfddf66d authored by Andre Eisenbach's avatar Andre Eisenbach Committed by Zhihai Xu
Browse files

LE: Add API to configure MTU for a given connection (4/4)

bug:13571470
Change-Id: I4faf13f3daa535337b721a8b48e92334ed0ecb7c
parent 4a146469
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -159,6 +159,7 @@ static jmethodID method_onGetIncludedService;
static jmethodID method_onRegisterForNotifications;
static jmethodID method_onReadRemoteRssi;
static jmethodID method_onAdvertiseCallback;
static jmethodID method_onConfigureMTU;

/**
 * Server callback methods
@@ -430,6 +431,14 @@ void btgattc_advertise_cb(int status, int client_if)
    checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__);
}

void btgattc_configure_mtu_cb(int conn_id, int status, int mtu)
{
    CHECK_CALLBACK_ENV
    sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onConfigureMTU,
                                 conn_id, status, mtu);
    checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__);
}

static const btgatt_client_callbacks_t sGattClientCallbacks = {
    btgattc_register_app_cb,
    btgattc_scan_result_cb,
@@ -448,7 +457,8 @@ static const btgatt_client_callbacks_t sGattClientCallbacks = {
    btgattc_write_descriptor_cb,
    btgattc_execute_write_cb,
    btgattc_remote_rssi_cb,
    btgattc_advertise_cb
    btgattc_advertise_cb,
    btgattc_configure_mtu_cb,
};


@@ -663,6 +673,7 @@ static void classInitNative(JNIEnv* env, jclass clazz) {
    method_onGetIncludedService = env->GetMethodID(clazz, "onGetIncludedService", "(IIIIJJIIJJ)V");
    method_onRegisterForNotifications = env->GetMethodID(clazz, "onRegisterForNotifications", "(IIIIIJJIJJ)V");
    method_onReadRemoteRssi = env->GetMethodID(clazz, "onReadRemoteRssi", "(ILjava/lang/String;II)V");
    method_onConfigureMTU = env->GetMethodID(clazz, "onConfigureMTU", "(III)V");

     // Server callbacks

@@ -1090,6 +1101,13 @@ static void gattSetAdvDataNative(JNIEnv *env, jobject object, jint client_if, jb
}


static void gattClientConfigureMTUNative(JNIEnv *env, jobject object,
        jint conn_id, jint mtu)
{
    if (!sGattIf) return;
    sGattIf->client->configure_mtu(conn_id, mtu);
}

/**
 * Native server functions
 */
@@ -1303,6 +1321,7 @@ static JNINativeMethod sMethods[] = {
    {"gattClientRegisterForNotificationsNative", "(ILjava/lang/String;IIJJIJJZ)V", (void *) gattClientRegisterForNotificationsNative},
    {"gattClientReadRemoteRssiNative", "(ILjava/lang/String;)V", (void *) gattClientReadRemoteRssiNative},
    {"gattAdvertiseNative", "(IZ)V", (void *) gattAdvertiseNative},
    {"gattClientConfigureMTUNative", "(II)V", (void *) gattClientConfigureMTUNative},

    {"gattServerRegisterAppNative", "(JJ)V", (void *) gattServerRegisterAppNative},
    {"gattServerUnregisterAppNative", "(I)V", (void *) gattServerUnregisterAppNative},
+32 −0
Original line number Diff line number Diff line
@@ -415,6 +415,12 @@ public class GattService extends ProfileService {
            service.readRemoteRssi(clientIf, address);
        }

        public void configureMTU(int clientIf, String address, int mtu) {
            GattService service = getService();
            if (service == null) return;
            service.configureMTU(clientIf, address, mtu);
        }

        public void registerServer(ParcelUuid uuid, IBluetoothGattServerCallback callback) {
            GattService service = getService();
            if (service == null) return;
@@ -968,6 +974,18 @@ public class GattService extends ProfileService {
        app.callback.onAdvertiseStateChange(mAdvertisingState, status);
    }

    void onConfigureMTU(int connId, int status, int mtu) throws RemoteException {
        String address = mClientMap.addressByConnId(connId);

        if (DBG) Log.d(TAG, "onConfigureMTU() address=" + address + ", status="
            + status + ", mtu=" + mtu);

        ClientMap.App app = mClientMap.getByConnId(connId);
        if (app != null) {
            app.callback.onConfigureMTU(address, mtu, status);
        }
    }

    /**************************************************************************
     * GATT Service functions - Shared CLIENT/SERVER
     *************************************************************************/
@@ -1384,6 +1402,18 @@ public class GattService extends ProfileService {
        gattClientReadRemoteRssiNative(clientIf, address);
    }

    void configureMTU(int clientIf, String address, int mtu) {
        enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");

        if (DBG) Log.d(TAG, "configureMTU() - address=" + address + " mtu=" + mtu);
        Integer connId = mClientMap.connIdByAddress(clientIf, address);
        if (connId != null) {
            gattClientConfigureMTUNative(connId, mtu);
        } else {
            Log.e(TAG, "configureMTU() - No connection for " + address + "...");
        }
    }

    /**************************************************************************
     * Callback functions - SERVER
     *************************************************************************/
@@ -2051,6 +2081,8 @@ public class GattService extends ProfileService {

    private native void gattAdvertiseNative(int client_if, boolean start);

    private native void gattClientConfigureMTUNative(int conn_id, int mtu);

    private native void gattSetAdvDataNative(int serverIf, boolean setScanRsp, boolean inclName,
            boolean inclTxPower, int minInterval, int maxInterval,
            int appearance, byte[] manufacturerData, byte[] serviceData, byte[] serviceUuid);