[CrOS Tether] Filter BLE discovery to LE devices only.

Instant Tethering only uses BLE connections. This filter was not
previously used due to a potential workaround which had been resolved
(see https://crbug.com/759090).

TBR=khorimoto@google.com

(cherry picked from commit a29a5d737d9d8a2aa4c1241c01d7157bb61d3ec2)

Bug: 759091, 672263
Change-Id: I161efd638f683d21596e445a5f1db2f90a838e75
Reviewed-on: https://chromium-review.googlesource.com/919426
Reviewed-by: Rahul Chaturvedi <rkc@chromium.org>
Commit-Queue: Kyle Horimoto <khorimoto@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#537140}
Reviewed-on: https://chromium-review.googlesource.com/927342
Reviewed-by: Kyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/branch-heads/3325@{#513}
Cr-Branched-From: bc084a8b5afa3744a74927344e304c02ae54189f-refs/heads/master@{#530369}
diff --git a/chromeos/components/tether/ble_synchronizer.cc b/chromeos/components/tether/ble_synchronizer.cc
index b5cb3de..9e8c719 100644
--- a/chromeos/components/tether/ble_synchronizer.cc
+++ b/chromeos/components/tether/ble_synchronizer.cc
@@ -87,13 +87,9 @@
           current_command_->start_discovery_args.get();
       DCHECK(start_discovery_args);
 
-      // Note: Ideally, we would use a filter for only LE devices here. However,
-      // using a filter here triggers a bug in some kernel implementations which
-      // causes LE scanning to toggle rapidly on and off. This can cause race
-      // conditions which result in Bluetooth bugs. See crbug.com/759090.
-      // TODO(mcchou): Once these issues have been resolved, add the filter
-      // back. See crbug.com/759091.
-      bluetooth_adapter_->StartDiscoverySession(
+      bluetooth_adapter_->StartDiscoverySessionWithFilter(
+          std::make_unique<device::BluetoothDiscoveryFilter>(
+              device::BLUETOOTH_TRANSPORT_LE),
           base::Bind(&BleSynchronizer::OnDiscoverySessionStarted,
                      weak_ptr_factory_.GetWeakPtr()),
           base::Bind(&BleSynchronizer::OnErrorStartingDiscoverySession,
diff --git a/chromeos/components/tether/ble_synchronizer_unittest.cc b/chromeos/components/tether/ble_synchronizer_unittest.cc
index 12ecb70..3dc00fb 100644
--- a/chromeos/components/tether/ble_synchronizer_unittest.cc
+++ b/chromeos/components/tether/ble_synchronizer_unittest.cc
@@ -92,6 +92,10 @@
 
   MOCK_METHOD1(RegisterAdvertisementWithArgsStruct,
                void(RegisterAdvertisementArgs*));
+  MOCK_METHOD3(StartDiscoverySessionWithFilterRaw,
+               void(device::BluetoothDiscoveryFilter*,
+                    const device::BluetoothAdapter::DiscoverySessionCallback&,
+                    const device::BluetoothAdapter::ErrorCallback&));
 
   void RegisterAdvertisement(
       std::unique_ptr<device::BluetoothAdvertisement::Data> advertisement_data,
@@ -102,6 +106,14 @@
         *advertisement_data->service_uuids(), callback, error_callback));
   }
 
+  void StartDiscoverySessionWithFilter(
+      std::unique_ptr<device::BluetoothDiscoveryFilter> discovery_filter,
+      const device::BluetoothAdapter::DiscoverySessionCallback& callback,
+      const device::BluetoothAdapter::ErrorCallback& error_callback) override {
+    StartDiscoverySessionWithFilterRaw(discovery_filter.get(), callback,
+                                       error_callback);
+  }
+
  protected:
   ~MockBluetoothAdapterWithAdvertisements() override = default;
 };
@@ -208,7 +220,7 @@
     ON_CALL(*mock_adapter_, RegisterAdvertisementWithArgsStruct(_))
         .WillByDefault(
             Invoke(this, &BleSynchronizerTest::OnAdapterRegisterAdvertisement));
-    ON_CALL(*mock_adapter_, StartDiscoverySession(_, _))
+    ON_CALL(*mock_adapter_, StartDiscoverySessionWithFilterRaw(_, _, _))
         .WillByDefault(
             Invoke(this, &BleSynchronizerTest::OnAdapterStartDiscoverySession));
 
@@ -234,8 +246,11 @@
   }
 
   void OnAdapterStartDiscoverySession(
+      device::BluetoothDiscoveryFilter* discovery_filter,
       const device::BluetoothAdapter::DiscoverySessionCallback& callback,
       const device::BluetoothAdapter::ErrorCallback& error_callback) {
+    EXPECT_EQ(device::BluetoothTransport::BLUETOOTH_TRANSPORT_LE,
+              discovery_filter->GetTransport());
     start_discovery_args_list_.emplace_back(base::WrapUnique(
         new StartDiscoverySessionArgs(callback, error_callback)));
   }