From 762a05f0574529fc768bd433128f636e9bc47f0c Mon Sep 17 00:00:00 2001 From: HsingYuan Lo Date: Wed, 23 Sep 2020 17:43:38 +0800 Subject: [PATCH] Expose service changed event to application (2/3) Handle service changed event from GattService Bug: 154056389 Tag: #feature Test: test service changed scenario Change-Id: If56dcbd7cf17b23c88cceb9c67c5d75b21320965 --- .../java/android/bluetooth/BluetoothGatt.java | 25 +++++++++++++++++++ .../bluetooth/BluetoothGattCallback.java | 13 ++++++++++ 2 files changed, 38 insertions(+) diff --git a/core/java/android/bluetooth/BluetoothGatt.java b/core/java/android/bluetooth/BluetoothGatt.java index c58b5d218e747..6d22eb93fd02b 100644 --- a/core/java/android/bluetooth/BluetoothGatt.java +++ b/core/java/android/bluetooth/BluetoothGatt.java @@ -688,6 +688,31 @@ public final class BluetoothGatt implements BluetoothProfile { } }); } + + /** + * Callback invoked when service changed event is received + * @hide + */ + @Override + public void onServiceChanged(String address) { + if (DBG) { + Log.d(TAG, "onServiceChanged() - Device=" + address); + } + + if (!address.equals(mDevice.getAddress())) { + return; + } + + runOrQueueCallback(new Runnable() { + @Override + public void run() { + final BluetoothGattCallback callback = mCallback; + if (callback != null) { + callback.onServiceChanged(BluetoothGatt.this); + } + } + }); + } }; /*package*/ BluetoothGatt(IBluetoothGatt iGatt, BluetoothDevice device, diff --git a/core/java/android/bluetooth/BluetoothGattCallback.java b/core/java/android/bluetooth/BluetoothGattCallback.java index f718c0b57c1b8..9f6b8287e791c 100644 --- a/core/java/android/bluetooth/BluetoothGattCallback.java +++ b/core/java/android/bluetooth/BluetoothGattCallback.java @@ -194,4 +194,17 @@ public abstract class BluetoothGattCallback { public void onConnectionUpdated(BluetoothGatt gatt, int interval, int latency, int timeout, int status) { } + + /** + * Callback indicating service changed event is received + * + *

Receiving this event means that the GATT database is out of sync with + * the remote device. {@link BluetoothGatt#discoverServices} should be + * called to re-discover the services. + * + * @param gatt GATT client involved + * @hide + */ + public void onServiceChanged(BluetoothGatt gatt) { + } }