Merge "Remove SAP socket"
diff --git a/jni/com_android_bluetooth_gatt.cpp b/jni/com_android_bluetooth_gatt.cpp
index 30cf32e..bf8d48b 100644
--- a/jni/com_android_bluetooth_gatt.cpp
+++ b/jni/com_android_bluetooth_gatt.cpp
@@ -999,12 +999,13 @@
 
 static void gattClientConnectNative(JNIEnv* env, jobject object, jint clientif,
                                     jstring address, jboolean isDirect,
-                                    jint transport) {
+                                    jint transport, jint initiating_phys) {
   if (!sGattIf) return;
 
   bt_bdaddr_t bda;
   jstr2bdaddr(env, &bda, address);
-  sGattIf->client->connect(clientif, &bda, isDirect, transport);
+  sGattIf->client->connect(clientif, &bda, isDirect, transport,
+                           initiating_phys);
 }
 
 static void gattClientDisconnectNative(JNIEnv* env, jobject object,
@@ -2035,7 +2036,7 @@
      (void*)gattClientRegisterAppNative},
     {"gattClientUnregisterAppNative", "(I)V",
      (void*)gattClientUnregisterAppNative},
-    {"gattClientConnectNative", "(ILjava/lang/String;ZI)V",
+    {"gattClientConnectNative", "(ILjava/lang/String;ZII)V",
      (void*)gattClientConnectNative},
     {"gattClientDisconnectNative", "(ILjava/lang/String;I)V",
      (void*)gattClientDisconnectNative},
diff --git a/src/com/android/bluetooth/gatt/GattService.java b/src/com/android/bluetooth/gatt/GattService.java
index b1b4f77..8a43198 100644
--- a/src/com/android/bluetooth/gatt/GattService.java
+++ b/src/com/android/bluetooth/gatt/GattService.java
@@ -26,8 +26,8 @@
 import android.bluetooth.BluetoothGattService;
 import android.bluetooth.BluetoothProfile;
 import android.bluetooth.IBluetoothGatt;
-import android.bluetooth.IBluetoothGattCallbackExt;
-import android.bluetooth.IBluetoothGattServerCallbackExt;
+import android.bluetooth.IBluetoothGattCallback;
+import android.bluetooth.IBluetoothGattServerCallback;
 import android.bluetooth.le.AdvertiseData;
 import android.bluetooth.le.AdvertisingSetParameters;
 import android.bluetooth.le.IAdvertisingSetCallback;
@@ -114,13 +114,13 @@
     /**
      * List of our registered clients.
      */
-    class ClientMap extends ContextMap<IBluetoothGattCallbackExt> {}
+    class ClientMap extends ContextMap<IBluetoothGattCallback> {}
     ClientMap mClientMap = new ClientMap();
 
     /**
      * List of our registered server apps.
      */
-    class ServerMap extends ContextMap<IBluetoothGattServerCallbackExt> {}
+    class ServerMap extends ContextMap<IBluetoothGattServerCallback> {}
     ServerMap mServerMap = new ServerMap();
 
     /**
@@ -325,7 +325,7 @@
             return service.getDevicesMatchingConnectionStates(states);
         }
 
-        public void registerClient(ParcelUuid uuid, IBluetoothGattCallbackExt callback) {
+        public void registerClient(ParcelUuid uuid, IBluetoothGattCallback callback) {
             GattService service = getService();
             if (service == null) return;
             service.registerClient(uuid.getUuid(), callback);
@@ -477,7 +477,7 @@
             service.connectionParameterUpdate(clientIf, address, connectionPriority);
         }
 
-        public void registerServer(ParcelUuid uuid, IBluetoothGattServerCallbackExt callback) {
+        public void registerServer(ParcelUuid uuid, IBluetoothGattServerCallback callback) {
             GattService service = getService();
             if (service == null) return;
             service.registerServer(uuid.getUuid(), callback);
@@ -688,8 +688,14 @@
             ScanSettings settings = client.settings;
             byte[] scan_record_data;
             // This is for compability with applications that assume fixed size scan data.
-            if (settings.getLegacy() && ((event_type & ET_LEGACY_MASK) == 0)) {
-                scan_record_data = legacy_adv_data;
+            if (settings.getLegacy()) {
+                if ((event_type & ET_LEGACY_MASK) == 0) {
+                    // If this is legacy scan, but nonlegacy result - skip.
+                    continue;
+                } else {
+                    // Some apps are used to fixed-size advertise data.
+                    scan_record_data = legacy_adv_data;
+                }
             } else {
                 scan_record_data = adv_data;
             }
@@ -708,11 +714,6 @@
                 continue;
             }
 
-            // if this is legacy scan, return only legacy scan results
-            if (settings.getLegacy() && ((event_type & ET_LEGACY_MASK) == 0)) {
-                continue;
-            }
-
             try {
                 app.appScanStats.addResult();
                 app.callback.onScanResult(result);
@@ -1550,7 +1551,7 @@
      * GATT Service functions - CLIENT
      *************************************************************************/
 
-    void registerClient(UUID uuid, IBluetoothGattCallbackExt callback) {
+    void registerClient(UUID uuid, IBluetoothGattCallback callback) {
         enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
 
         if (DBG) Log.d(TAG, "registerClient() - UUID=" + uuid);
@@ -1570,9 +1571,10 @@
     void clientConnect(int clientIf, String address, boolean isDirect, int transport, int phy) {
         enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
 
-        if (DBG) Log.d(TAG, "clientConnect() - address=" + address + ", isDirect=" + isDirect);
-        // TODO(jpawlowski): propagate PHY!
-        gattClientConnectNative(clientIf, address, isDirect, transport);
+        if (DBG)
+            Log.d(TAG, "clientConnect() - address=" + address + ", isDirect=" + isDirect + ", phy= "
+                            + phy);
+        gattClientConnectNative(clientIf, address, isDirect, transport, phy);
     }
 
     void clientDisconnect(int clientIf, String address) {
@@ -2067,7 +2069,7 @@
      * GATT Service functions - SERVER
      *************************************************************************/
 
-    void registerServer(UUID uuid, IBluetoothGattServerCallbackExt callback) {
+    void registerServer(UUID uuid, IBluetoothGattServerCallback callback) {
         enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
 
         if (DBG) Log.d(TAG, "registerServer() - UUID=" + uuid);
@@ -2427,8 +2429,8 @@
 
     private native void gattClientUnregisterAppNative(int clientIf);
 
-    private native void gattClientConnectNative(int clientIf, String address,
-            boolean isDirect, int transport);
+    private native void gattClientConnectNative(
+            int clientIf, String address, boolean isDirect, int transport, int initiating_phys);
 
     private native void gattClientDisconnectNative(int clientIf, String address,
             int conn_id);