LE (3/3): Add application ID to connection callback
Bug: 8589393
Change-Id: Iff14aa568bac4d62920bc35ec1545384e200b53a
diff --git a/android/app/jni/com_android_bluetooth_gatt.cpp b/android/app/jni/com_android_bluetooth_gatt.cpp
index 0c3dbb3..207e643 100644
--- a/android/app/jni/com_android_bluetooth_gatt.cpp
+++ b/android/app/jni/com_android_bluetooth_gatt.cpp
@@ -454,7 +454,7 @@
checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__);
}
-void btgatts_connection_cb(int conn_id, int connected, bt_bdaddr_t *bda)
+void btgatts_connection_cb(int conn_id, int server_if, int connected, bt_bdaddr_t *bda)
{
CHECK_CALLBACK_ENV
@@ -465,7 +465,7 @@
jstring address = sCallbackEnv->NewStringUTF(c_address);
sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onClientConnected,
- address, connected, conn_id);
+ address, connected, conn_id, server_if);
sCallbackEnv->DeleteLocalRef(address);
checkAndClearExceptionFromCallback(sCallbackEnv, __FUNCTION__);
}
@@ -657,7 +657,7 @@
// Server callbacks
method_onServerRegistered = env->GetMethodID(clazz, "onServerRegistered", "(IIJJ)V");
- method_onClientConnected = env->GetMethodID(clazz, "onClientConnected", "(Ljava/lang/String;ZI)V");
+ method_onClientConnected = env->GetMethodID(clazz, "onClientConnected", "(Ljava/lang/String;ZII)V");
method_onServiceAdded = env->GetMethodID(clazz, "onServiceAdded", "(IIIIJJI)V");
method_onIncludedServiceAdded = env->GetMethodID(clazz, "onIncludedServiceAdded", "(IIII)V");
method_onCharacteristicAdded = env->GetMethodID(clazz, "onCharacteristicAdded", "(IIJJII)V");
diff --git a/android/app/src/com/android/bluetooth/gatt/GattService.java b/android/app/src/com/android/bluetooth/gatt/GattService.java
index 4e58c46..ffadecc 100644
--- a/android/app/src/com/android/bluetooth/gatt/GattService.java
+++ b/android/app/src/com/android/bluetooth/gatt/GattService.java
@@ -1141,22 +1141,22 @@
mHandleMap.deleteService(serverIf, srvcHandle);
}
- void onClientConnected(String address, boolean connected, int connId)
+ void onClientConnected(String address, boolean connected, int connId, int serverIf)
throws RemoteException {
if (DBG) Log.d(TAG, "onConnected() connId=" + connId
+ ", address=" + address + ", connected=" + connected);
- Iterator<ServerMap.App> i = mServerMap.mApps.iterator();
- while(i.hasNext()) {
- ServerMap.App entry = i.next();
- if (connected) {
- mServerMap.addConnection(entry.id, connId, address);
- } else {
- mServerMap.removeConnection(entry.id, connId);
- }
- entry.callback.onServerConnectionState((byte)0, entry.id, connected, address);
+ ServerMap.App app = mServerMap.getById(serverIf);
+ if (app == null) return;
+
+ if (connected) {
+ mServerMap.addConnection(serverIf, connId, address);
+ } else {
+ mServerMap.removeConnection(serverIf, connId);
}
+
+ app.callback.onServerConnectionState((byte)0, serverIf, connected, address);
}
void onAttributeRead(String address, int connId, int transId,