diff options
author | deymo@chromium.org <deymo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-03 11:06:24 +0000 |
---|---|---|
committer | deymo@chromium.org <deymo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-03 11:06:24 +0000 |
commit | 628f210c7de23b47ad12c9e0564a2d52a1bd85ba (patch) | |
tree | 596abde395a2daba30e2b48376f04690a62034b5 /device | |
parent | 0627ed0d1afc0b633dff311abd92d4e1248ac1b5 (diff) | |
download | chromium_src-628f210c7de23b47ad12c9e0564a2d52a1bd85ba.zip chromium_src-628f210c7de23b47ad12c9e0564a2d52a1bd85ba.tar.gz chromium_src-628f210c7de23b47ad12c9e0564a2d52a1bd85ba.tar.bz2 |
Bluetooth: Check IsPaired() before IsConnected() to avoid false connections
Bluetooth devices can be connected to the adapter for several reasons.
One of the reasons is that the user is activelly using the device, so
the device is paired/trusted, connected and also connected to a given
profile. But that's not the only one, since a Bluetooth device is allowed
by the spec to connect to any other device or adapter to do some basic
operations like requesting the SDP records. Because of this, IsConnected()
can be true in situations where the user didn't inted a connection.
If IsPaired() is true, the value of IsConnected() almost implies that the
device is connected to the applications (but we can't be sure about that).
If IsPaired() is false, the device is neither paired nor trusted, and the
value of IsConnected() is mostly irrelevant, since the device is for sure
not connected to any application.
This fix adds a comments explaining this behavior to the common
BluetoothDevice interface and also corrects some ussages of IsConnected()
where that value was used even when IsPaired() is false.
BUG=237285
TEST=Manual test.
Manual test procedure:
1. Go to the settings page: chrome://settings
2. Scan for new devices, select the "Motorola KZ450" Keyboard.
3. Attempt a connect to it. A passkey number should be shown on the screen.
4. Click on "cancel" on that pairing dialog.
5. Immediately after, try to add a new device again.
6. In the "add Bluetooth device" dialog, click on the "Motorola KZ450" keyboard.
7. The "connect" button should be enabled. Click it.
8. The keyboard should ask again for a passkey/pincode to type.
Review URL: https://chromiumcodereview.appspot.com/14569023
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@198083 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'device')
4 files changed, 9 insertions, 4 deletions
diff --git a/device/bluetooth/bluetooth_adapter_experimental_chromeos.cc b/device/bluetooth/bluetooth_adapter_experimental_chromeos.cc index 6a282f3..6f3a185c 100644 --- a/device/bluetooth/bluetooth_adapter_experimental_chromeos.cc +++ b/device/bluetooth/bluetooth_adapter_experimental_chromeos.cc @@ -261,7 +261,7 @@ void BluetoothAdapterExperimentalChromeOS::DevicePropertyChanged( for (DevicesMap::iterator iter = devices_.begin(); iter != devices_.end(); ++iter) { - if (iter->second->IsConnected()) + if (iter->second->IsPaired() && iter->second->IsConnected()) ++count; } diff --git a/device/bluetooth/bluetooth_device.h b/device/bluetooth/bluetooth_device.h index e442080..c1655ed 100644 --- a/device/bluetooth/bluetooth_device.h +++ b/device/bluetooth/bluetooth_device.h @@ -204,6 +204,11 @@ class BluetoothDevice { virtual bool IsPaired() const = 0; // Indicates whether the device is currently connected to the adapter. + // Note that if IsConnected() is true, does not imply that the device is + // connected to any application or service. If the device is not paired, it + // could be still connected to the adapter for other reason, for example, to + // request the adapter's SDP records. The same holds for paired devices, since + // they could be connected to the adapter but not to an application. virtual bool IsConnected() const = 0; // Indicates whether the paired device accepts connections initiated from the diff --git a/device/bluetooth/bluetooth_device_chromeos.cc b/device/bluetooth/bluetooth_device_chromeos.cc index 4f3b5ae..06ffc79 100644 --- a/device/bluetooth/bluetooth_device_chromeos.cc +++ b/device/bluetooth/bluetooth_device_chromeos.cc @@ -175,8 +175,8 @@ void BluetoothDeviceChromeOS::Connect( weak_ptr_factory_.GetWeakPtr(), error_callback); - if (IsPaired() || IsConnected()) { - // Connection to already paired or connected device. + if (IsPaired()) { + // Connection to already paired device. ConnectApplications(wrapped_callback, wrapped_error_callback); } else if (!pairing_delegate || !IsPairable()) { diff --git a/device/bluetooth/bluetooth_device_experimental_chromeos.cc b/device/bluetooth/bluetooth_device_experimental_chromeos.cc index 92b4d94..5e775d1 100644 --- a/device/bluetooth/bluetooth_device_experimental_chromeos.cc +++ b/device/bluetooth/bluetooth_device_experimental_chromeos.cc @@ -235,7 +235,7 @@ void BluetoothDeviceExperimentalChromeOS::Connect( VLOG(1) << object_path_.value() << ": Connecting, " << num_connecting_calls_ << " in progress"; - if (IsPaired() || IsConnected() || !pairing_delegate || !IsPairable()) { + if (IsPaired() || !pairing_delegate || !IsPairable()) { // No need to pair, or unable to, skip straight to connection. ConnectInternal(callback, error_callback); } else { |