Merge "Expose connection update callback (3/4)"
diff --git a/jni/com_android_bluetooth_gatt.cpp b/jni/com_android_bluetooth_gatt.cpp
index 90c3835..30cf32e 100644
--- a/jni/com_android_bluetooth_gatt.cpp
+++ b/jni/com_android_bluetooth_gatt.cpp
@@ -163,6 +163,7 @@
 static jmethodID method_onGetGattDb;
 static jmethodID method_onClientPhyUpdate;
 static jmethodID method_onClientPhyRead;
+static jmethodID method_onClientConnUpdate;
 
 /**
  * Server callback methods
@@ -183,6 +184,7 @@
 static jmethodID method_onServerMtuChanged;
 static jmethodID method_onServerPhyUpdate;
 static jmethodID method_onServerPhyRead;
+static jmethodID method_onServerConnUpdate;
 
 /**
  * Advertiser callback methods
@@ -523,11 +525,19 @@
   CallbackEnv sCallbackEnv(__func__);
   if (!sCallbackEnv.valid()) return;
 
-  info("ASDFASDFADSFDSAFDS");
   sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onClientPhyUpdate, conn_id,
                                tx_phy, rx_phy, status);
 }
 
+void btgattc_conn_updated_cb(int conn_id, uint16_t interval, uint16_t latency,
+                             uint16_t timeout, uint8_t status) {
+  CallbackEnv sCallbackEnv(__func__);
+  if (!sCallbackEnv.valid()) return;
+
+  sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onClientConnUpdate,
+                               conn_id, interval, latency, timeout, status);
+}
+
 static const btgatt_scanner_callbacks_t sGattScannerCallbacks = {
     btgattc_scan_result_cb,
     btgattc_batchscan_reports_cb,
@@ -553,7 +563,8 @@
     btgattc_get_gatt_db_cb,
     NULL, /* services_removed_cb */
     NULL, /* services_added_cb */
-    btgattc_phy_updated_cb};
+    btgattc_phy_updated_cb,
+    btgattc_conn_updated_cb};
 
 /**
  * BTA server callbacks
@@ -726,6 +737,15 @@
                                tx_phy, rx_phy, status);
 }
 
+void btgatts_conn_updated_cb(int conn_id, uint16_t interval, uint16_t latency,
+                             uint16_t timeout, uint8_t status) {
+  CallbackEnv sCallbackEnv(__func__);
+  if (!sCallbackEnv.valid()) return;
+
+  sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onServerConnUpdate,
+                               conn_id, interval, latency, timeout, status);
+}
+
 static const btgatt_server_callbacks_t sGattServerCallbacks = {
     btgatts_register_app_cb,
     btgatts_connection_cb,
@@ -741,7 +761,8 @@
     btgatts_indication_sent_cb,
     btgatts_congestion_cb,
     btgatts_mtu_changed_cb,
-    btgatts_phy_updated_cb};
+    btgatts_phy_updated_cb,
+    btgatts_conn_updated_cb};
 
 /**
  * GATT callbacks
@@ -821,6 +842,8 @@
       env->GetMethodID(clazz, "onClientPhyRead", "(IIII)V");
   method_onClientPhyUpdate =
       env->GetMethodID(clazz, "onClientPhyUpdate", "(IIII)V");
+  method_onClientConnUpdate =
+      env->GetMethodID(clazz, "onClientConnUpdate", "(IIIII)V");
 
   // Server callbacks
 
@@ -855,6 +878,8 @@
       env->GetMethodID(clazz, "onServerPhyRead", "(IIII)V");
   method_onServerPhyUpdate =
       env->GetMethodID(clazz, "onServerPhyUpdate", "(IIII)V");
+  method_onServerConnUpdate =
+      env->GetMethodID(clazz, "onServerConnUpdate", "(IIIII)V");
 
   info("classInitNative: Success!");
 }
diff --git a/src/com/android/bluetooth/gatt/GattService.java b/src/com/android/bluetooth/gatt/GattService.java
index 701d9d4..b1b4f77 100644
--- a/src/com/android/bluetooth/gatt/GattService.java
+++ b/src/com/android/bluetooth/gatt/GattService.java
@@ -833,6 +833,19 @@
         app.callback.onPhyRead(address, txPhy, rxPhy, status);
     }
 
+    void onClientConnUpdate(int connId, int interval, int latency, int timeout, int status)
+            throws RemoteException {
+        if (DBG) Log.d(TAG, "onClientConnUpdate() - connId=" + connId + ", status=" + status);
+
+        String address = mClientMap.addressByConnId(connId);
+        if (address == null) return;
+
+        ClientMap.App app = mClientMap.getByConnId(connId);
+        if (app == null) return;
+
+        app.callback.onConnectionUpdated(address, interval, latency, timeout, status);
+    }
+
     void onServerPhyUpdate(int connId, int txPhy, int rxPhy, int status) throws RemoteException {
         if (DBG) Log.d(TAG, "onServerPhyUpdate() - connId=" + connId + ", status=" + status);
 
@@ -857,6 +870,19 @@
         app.callback.onPhyRead(address, txPhy, rxPhy, status);
     }
 
+    void onServerConnUpdate(int connId, int interval, int latency, int timeout, int status)
+            throws RemoteException {
+        if (DBG) Log.d(TAG, "onServerConnUpdate() - connId=" + connId + ", status=" + status);
+
+        String address = mServerMap.addressByConnId(connId);
+        if (address == null) return;
+
+        ServerMap.App app = mServerMap.getByConnId(connId);
+        if (app == null) return;
+
+        app.callback.onConnectionUpdated(address, interval, latency, timeout, status);
+    }
+
     void onSearchCompleted(int connId, int status) throws RemoteException {
         if (DBG) Log.d(TAG, "onSearchCompleted() - connId=" + connId+ ", status=" + status);
         // Gatt DB is ready!