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

Commit 6e87d62c authored by Andre Eisenbach's avatar Andre Eisenbach Committed by Android Git Automerger
Browse files

am 9cc4edd2: am 3e86a83a: LE: Add connection parameter update request API (3/4)

* commit '9cc4edd2':
  LE: Add connection parameter update request API (3/4)
parents 7704aec2 9cc4edd2
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -1432,6 +1432,15 @@ static void gattClientConfigureMTUNative(JNIEnv *env, jobject object,
    sGattIf->client->configure_mtu(conn_id, mtu);
}

static void gattConnectionParameterUpdateNative(JNIEnv *env, jobject object, jint client_if,
        jstring address, jint min_interval, jint max_interval, jint latency, jint timeout)
{
    if (!sGattIf) return;
    bt_bdaddr_t bda;
    jstr2bdaddr(env, &bda, address);
    sGattIf->client->conn_parameter_update(&bda, min_interval, max_interval, latency, timeout);
}

static void gattClientEnableAdvNative(JNIEnv* env, jobject object, jint client_if,
       jint min_interval, jint max_interval, jint adv_type, jint chnl_map, jint tx_power)
{
@@ -1743,6 +1752,7 @@ static JNINativeMethod sMethods[] = {
    {"gattClientReadRemoteRssiNative", "(ILjava/lang/String;)V", (void *) gattClientReadRemoteRssiNative},
    {"gattAdvertiseNative", "(IZ)V", (void *) gattAdvertiseNative},
    {"gattClientConfigureMTUNative", "(II)V", (void *) gattClientConfigureMTUNative},
    {"gattConnectionParameterUpdateNative", "(ILjava/lang/String;IIII)V", (void *) gattConnectionParameterUpdateNative},
    {"gattServerRegisterAppNative", "(JJ)V", (void *) gattServerRegisterAppNative},
    {"gattServerUnregisterAppNative", "(I)V", (void *) gattServerUnregisterAppNative},
    {"gattServerConnectNative", "(ILjava/lang/String;ZI)V", (void *) gattServerConnectNative},
+44 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.bluetooth.gatt;
import android.app.Service;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothUuid;
import android.bluetooth.IBluetoothGatt;
@@ -441,6 +442,13 @@ public class GattService extends ProfileService {
            service.configureMTU(clientIf, address, mtu);
        }

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

        public void registerServer(ParcelUuid uuid, IBluetoothGattServerCallback callback) {
            GattService service = getService();
            if (service == null) return;
@@ -1594,6 +1602,39 @@ public class GattService extends ProfileService {
        }
    }

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

        // Default spec recommended interval is 30->50 ms
        int minInterval = 24; // 24 * 1.25ms = 30ms
        int maxInterval = 40; // 40 * 1.25ms = 50ms

        // Slave latency
        int latency = 0;

        // Link supervision timeout is measured in N * 10ms
        int timeout = 2000; // 20s

        switch (connectionPriority)
        {
            case BluetoothGatt.GATT_CONNECTION_HIGH_PRIORITY:
                minInterval = 6; // 7.5ms
                maxInterval = 8; // 10ms
                break;

            case BluetoothGatt.GATT_CONNECTION_LOW_POWER:
                minInterval = 80; // 100ms
                maxInterval = 100; // 125ms
                latency = 2;
                break;
        }

        if (DBG) Log.d(TAG, "connectionParameterUpdate() - address=" + address
            + "params=" + connectionPriority + " interval=" + minInterval + "/" + maxInterval);
        gattConnectionParameterUpdateNative(clientIf, address, minInterval, maxInterval,
                                            latency, timeout);
    }

    /**************************************************************************
     * Callback functions - SERVER
     *************************************************************************/
@@ -2270,6 +2311,9 @@ public class GattService extends ProfileService {

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

    private native void gattConnectionParameterUpdateNative(int client_if, String address,
            int minInterval, int maxInterval, int latency, int timeout);

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