Merge "Fix (again) bad scan record data length"
diff --git a/src/com/android/bluetooth/gatt/GattService.java b/src/com/android/bluetooth/gatt/GattService.java
index b1b4f77..8a07143 100644
--- a/src/com/android/bluetooth/gatt/GattService.java
+++ b/src/com/android/bluetooth/gatt/GattService.java
@@ -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);