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

Commit dadefdad authored by Andre Eisenbach's avatar Andre Eisenbach Committed by Andre Eisenbach
Browse files

LE: Add notification sent and congestion callbacks (3/4)

This change introduces two new callbacks for applications to better
handle LE notification flow control and transport congestion. The
notification callback is invoked when the remote platform confirms an
indication or when a local notification has been passed to the
controller. No new notifications should be sent until a callback is
received.

Congestion callbacks are triggered when a GATT operation cannot be sent
to the local Bluetooth controller. Repeatedly calling
writeCharacteristic() for example will eventually trigger a congestion
callback. Applications cannot send additional data until a further
callback is received, indicating that the congestion has cleared up.

Also made server callbacks "oneway" in the AIDL definition file.

Change-Id: I7fa3324712205c79efce58e5e3df8b80a265a442
parent 7ca6c1a0
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -2079,12 +2079,15 @@ public final class BluetoothAdapter {
        public void onMultiAdvertiseCallback(int status) {
            // no op
        }
        /**
         * Callback reporting LE ATT MTU.
         * @hide
         */

        @Override
        public void onConfigureMTU(String address, int mtu, int status) {
            // no op
        }

        @Override
        public void onConnectionCongested(String address, boolean congested) {
            // no op
        }
    }
}
+18 −0
Original line number Diff line number Diff line
@@ -85,6 +85,9 @@ public final class BluetoothGatt implements BluetoothProfile {
    /** A write operation exceeds the maximum length of the attribute */
    public static final int GATT_INVALID_ATTRIBUTE_LENGTH = 0xd;

    /** A remote device connection is congested. */
    public static final int GATT_CONNECTION_CONGESTED = 0x8f;

    /** A GATT operation failed, errors other than the above */
    public static final int GATT_FAILURE = 0x101;

@@ -607,6 +610,21 @@ public final class BluetoothGatt implements BluetoothProfile {
                    Log.w(TAG, "Unhandled exception in callback", ex);
                }
            }

            /**
             * Callback indicating the remote device connection is congested.
             * @hide
             */
            public void onConnectionCongested(String address, boolean congested) {
                if (DBG) Log.d(TAG, "onConnectionCongested() - Device=" + address
                        + " congested=" + congested);
                if (!address.equals(mDevice.getAddress())) return;
                try {
                    mCallback.onConnectionCongested(BluetoothGatt.this, congested);
                } catch (Exception ex) {
                    Log.w(TAG, "Unhandled exception in callback", ex);
                }
            }
        };

    /*package*/ BluetoothGatt(Context context, IBluetoothGatt iGatt, BluetoothDevice device,
+15 −0
Original line number Diff line number Diff line
@@ -153,4 +153,19 @@ public abstract class BluetoothGattCallback {
     */
    public void onConfigureMTU(BluetoothGatt gatt, int mtu, int status) {
    }

    /**
     * Callback indicating that a remote device connection congestestion status has changed.
     *
     * An application should refrain from sending additional data to a remote device when
     * a callback is received with the congested flag set to true. Once the congestion status
     * is cleared up, the application will receive an additional callback with the congested
     * flag set to false.
     *
     * @param gatt The GATT client associated with the remote device
     * @param congested true, if the connection is currently congested
     * @hide
     */
    public void onConnectionCongested(BluetoothGatt gatt, boolean congested) {
    }
}
+36 −0
Original line number Diff line number Diff line
@@ -265,6 +265,42 @@ public final class BluetoothGattServer implements BluetoothProfile {
                    Log.w(TAG, "Unhandled exception in callback", ex);
                }
            }

            /**
             * A notification/indication has been sent.
             * @hide
             */
            public void onNotificationSent(String address, int status) {
                if (DBG) Log.d(TAG, "onNotificationSent() - "
                    + "device=" + address + ", status=" + status);

                BluetoothDevice device = mAdapter.getRemoteDevice(address);
                if (device == null) return;

                try {
                    mCallback.onNotificationSent(device, status);
                } catch (Exception ex) {
                    Log.w(TAG, "Unhandled exception: " + ex);
                }
            }

            /**
             * Callback indicating the remote device connection is congested.
             * @hide
             */
            public void onConnectionCongested(String address, boolean congested) {
                if (DBG) Log.d(TAG, "onConnectionCongested() - Device=" + address
                        + " congested=" + congested);

                BluetoothDevice device = mAdapter.getRemoteDevice(address);
                if (device == null) return;

                try {
                    mCallback.onConnectionCongested(device, congested);
                } catch (Exception ex) {
                    Log.w(TAG, "Unhandled exception in callback", ex);
                }
            }
        };

    /**
+30 −0
Original line number Diff line number Diff line
@@ -131,4 +131,34 @@ public abstract class BluetoothGattServerCallback {
     */
    public void onExecuteWrite(BluetoothDevice device, int requestId, boolean execute) {
    }

    /**
     * Callback invoked when a notification or indication has been sent to
     * a remote device.
     *
     * <p>When multiple notifications are to be sent, an application must
     * wait for this callback to be received before sending additional
     * notifications.
     *
     * @param device The remote device the notification has been sent to
     * @param status 0 if the operation was successful
     * @hide
     */
    public void onNotificationSent(BluetoothDevice device, int status) {
    }

    /**
     * Callback indicating that a remote device connection congestestion status has changed.
     *
     * An application should refrain from sending additional data (notifications, indications
     * etc.) to a remote device when a callback is received with the congested flag set
     * to true. Once the congestion status is cleared up, the application will receive an
     * additional callback with the congested flag set to false.
     *
     * @param device The remote device that triggered the congestion state change
     * @param congested true, if the connection is currently congested
     * @hide
     */
    public void onConnectionCongested(BluetoothDevice device, boolean congested) {
    }
}
Loading