| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_PAIRING_CHROMEOS_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_PAIRING_CHROMEOS_H_ |
| 6 #define DEVICE_BLUETOOTH_BLUETOOTH_PAIRING_CHROMEOS_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_PAIRING_CHROMEOS_H_ |
| 7 | 7 |
| 8 #include "chromeos/dbus/bluetooth_agent_service_provider.h" | |
| 9 #include "device/bluetooth/bluetooth_device.h" | 8 #include "device/bluetooth/bluetooth_device.h" |
| 9 #include "device/bluetooth/dbus/bluetooth_agent_service_provider.h" |
| 10 | 10 |
| 11 namespace chromeos { | 11 namespace chromeos { |
| 12 | 12 |
| 13 class BluetoothDeviceChromeOS; | 13 class BluetoothDeviceChromeOS; |
| 14 | 14 |
| 15 // The BluetoothPairingChromeOS class encapsulates the logic for an individual | 15 // The BluetoothPairingChromeOS class encapsulates the logic for an individual |
| 16 // device pairing, acting as a bridge between BluetoothAdapterChromeOS which | 16 // device pairing, acting as a bridge between BluetoothAdapterChromeOS which |
| 17 // communicates with the underlying Controller and Host Subsystem, and | 17 // communicates with the underlying Controller and Host Subsystem, and |
| 18 // BluetoothDeviceChromeOS which presents the pairing logic to the application. | 18 // BluetoothDeviceChromeOS which presents the pairing logic to the application. |
| 19 class BluetoothPairingChromeOS { | 19 class BluetoothPairingChromeOS { |
| 20 public: | 20 public: |
| 21 BluetoothPairingChromeOS( | 21 BluetoothPairingChromeOS( |
| 22 BluetoothDeviceChromeOS* device, | 22 BluetoothDeviceChromeOS* device, |
| 23 device::BluetoothDevice::PairingDelegate* pairing_delegate); | 23 device::BluetoothDevice::PairingDelegate* pairing_delegate); |
| 24 ~BluetoothPairingChromeOS(); | 24 ~BluetoothPairingChromeOS(); |
| 25 | 25 |
| 26 // Indicates whether the device is currently pairing and expecting a | 26 // Indicates whether the device is currently pairing and expecting a |
| 27 // Passkey to be returned. | 27 // Passkey to be returned. |
| 28 bool ExpectingPasskey() const; | 28 bool ExpectingPasskey() const; |
| 29 | 29 |
| 30 // Indicates whether the device is currently pairing and expecting | 30 // Indicates whether the device is currently pairing and expecting |
| 31 // confirmation of a displayed passkey. | 31 // confirmation of a displayed passkey. |
| 32 bool ExpectingConfirmation() const; | 32 bool ExpectingConfirmation() const; |
| 33 | 33 |
| 34 // Requests a PIN code for the current device from the current pairing | 34 // Requests a PIN code for the current device from the current pairing |
| 35 // delegate, the SetPinCode(), RejectPairing() and CancelPairing() method | 35 // delegate, the SetPinCode(), RejectPairing() and CancelPairing() method |
| 36 // calls on this object are translated into the appropriate response to | 36 // calls on this object are translated into the appropriate response to |
| 37 // |callback|. | 37 // |callback|. |
| 38 void RequestPinCode( | 38 void RequestPinCode( |
| 39 const BluetoothAgentServiceProvider::Delegate::PinCodeCallback& callback); | 39 const bluez::BluetoothAgentServiceProvider::Delegate::PinCodeCallback& |
| 40 callback); |
| 40 | 41 |
| 41 // Indicates whether the device is currently pairing and expecting a | 42 // Indicates whether the device is currently pairing and expecting a |
| 42 // PIN Code to be returned. | 43 // PIN Code to be returned. |
| 43 bool ExpectingPinCode() const; | 44 bool ExpectingPinCode() const; |
| 44 | 45 |
| 45 // Sends the PIN code |pincode| to the remote device during pairing. | 46 // Sends the PIN code |pincode| to the remote device during pairing. |
| 46 // | 47 // |
| 47 // PIN Codes are generally required for Bluetooth 2.0 and earlier devices | 48 // PIN Codes are generally required for Bluetooth 2.0 and earlier devices |
| 48 // for which there is no automatic pairing or special handling. | 49 // for which there is no automatic pairing or special handling. |
| 49 void SetPinCode(const std::string& pincode); | 50 void SetPinCode(const std::string& pincode); |
| 50 | 51 |
| 51 // Requests a PIN code for the current device be displayed by the current | 52 // Requests a PIN code for the current device be displayed by the current |
| 52 // pairing delegate. No response is expected from the delegate. | 53 // pairing delegate. No response is expected from the delegate. |
| 53 void DisplayPinCode(const std::string& pincode); | 54 void DisplayPinCode(const std::string& pincode); |
| 54 | 55 |
| 55 // Requests a Passkey for the current device from the current pairing | 56 // Requests a Passkey for the current device from the current pairing |
| 56 // delegate, the SetPasskey(), RejectPairing() and CancelPairing() method | 57 // delegate, the SetPasskey(), RejectPairing() and CancelPairing() method |
| 57 // calls on this object are translated into the appropriate response to | 58 // calls on this object are translated into the appropriate response to |
| 58 // |callback|. | 59 // |callback|. |
| 59 void RequestPasskey( | 60 void RequestPasskey( |
| 60 const BluetoothAgentServiceProvider::Delegate::PasskeyCallback& callback); | 61 const bluez::BluetoothAgentServiceProvider::Delegate::PasskeyCallback& |
| 62 callback); |
| 61 | 63 |
| 62 // Sends the Passkey |passkey| to the remote device during pairing. | 64 // Sends the Passkey |passkey| to the remote device during pairing. |
| 63 // | 65 // |
| 64 // Passkeys are generally required for Bluetooth 2.1 and later devices | 66 // Passkeys are generally required for Bluetooth 2.1 and later devices |
| 65 // which cannot provide input or display on their own, and don't accept | 67 // which cannot provide input or display on their own, and don't accept |
| 66 // passkey-less pairing, and are a numeric in the range 0-999999. | 68 // passkey-less pairing, and are a numeric in the range 0-999999. |
| 67 void SetPasskey(uint32 passkey); | 69 void SetPasskey(uint32 passkey); |
| 68 | 70 |
| 69 // Requests a Passkey for the current device be displayed by the current | 71 // Requests a Passkey for the current device be displayed by the current |
| 70 // pairing delegate. No response is expected from the delegate. | 72 // pairing delegate. No response is expected from the delegate. |
| 71 void DisplayPasskey(uint32 passkey); | 73 void DisplayPasskey(uint32 passkey); |
| 72 | 74 |
| 73 // Informs the current pairing delegate that |entered| keys have been | 75 // Informs the current pairing delegate that |entered| keys have been |
| 74 // provided to the remote device since the DisplayPasskey() call. No | 76 // provided to the remote device since the DisplayPasskey() call. No |
| 75 // response is expected from the delegate. | 77 // response is expected from the delegate. |
| 76 void KeysEntered(uint16 entered); | 78 void KeysEntered(uint16 entered); |
| 77 | 79 |
| 78 // Requests confirmation that |passkey| is displayed on the current device | 80 // Requests confirmation that |passkey| is displayed on the current device |
| 79 // from the current pairing delegate. The ConfirmPairing(), RejectPairing() | 81 // from the current pairing delegate. The ConfirmPairing(), RejectPairing() |
| 80 // and CancelPairing() method calls on this object are translated into the | 82 // and CancelPairing() method calls on this object are translated into the |
| 81 // appropriate response to |callback|. | 83 // appropriate response to |callback|. |
| 82 void RequestConfirmation( | 84 void RequestConfirmation(uint32 passkey, |
| 83 uint32 passkey, | 85 const bluez::BluetoothAgentServiceProvider:: |
| 84 const BluetoothAgentServiceProvider::Delegate::ConfirmationCallback& | 86 Delegate::ConfirmationCallback& callback); |
| 85 callback); | |
| 86 | 87 |
| 87 // Requests authorization that the current device be allowed to pair with | 88 // Requests authorization that the current device be allowed to pair with |
| 88 // this device from the current pairing delegate. The ConfirmPairing(), | 89 // this device from the current pairing delegate. The ConfirmPairing(), |
| 89 // RejectPairing() and CancelPairing() method calls on this object are | 90 // RejectPairing() and CancelPairing() method calls on this object are |
| 90 // translated into the appropriate response to |callback|. | 91 // translated into the appropriate response to |callback|. |
| 91 void RequestAuthorization( | 92 void RequestAuthorization(const bluez::BluetoothAgentServiceProvider:: |
| 92 const BluetoothAgentServiceProvider::Delegate::ConfirmationCallback& | 93 Delegate::ConfirmationCallback& callback); |
| 93 callback); | |
| 94 | 94 |
| 95 // Confirms to the remote device during pairing that a passkey provided by | 95 // Confirms to the remote device during pairing that a passkey provided by |
| 96 // the ConfirmPasskey() delegate call is displayed on both devices. | 96 // the ConfirmPasskey() delegate call is displayed on both devices. |
| 97 void ConfirmPairing(); | 97 void ConfirmPairing(); |
| 98 | 98 |
| 99 // Rejects a pairing or connection request from a remote device, returns | 99 // Rejects a pairing or connection request from a remote device, returns |
| 100 // false if there was no way to reject the pairing. | 100 // false if there was no way to reject the pairing. |
| 101 bool RejectPairing(); | 101 bool RejectPairing(); |
| 102 | 102 |
| 103 // Cancels a pairing or connection attempt to a remote device, returns | 103 // Cancels a pairing or connection attempt to a remote device, returns |
| 104 // false if there was no way to cancel the pairing. | 104 // false if there was no way to cancel the pairing. |
| 105 bool CancelPairing(); | 105 bool CancelPairing(); |
| 106 | 106 |
| 107 // Returns the pairing delegate being used by this pairing object. | 107 // Returns the pairing delegate being used by this pairing object. |
| 108 device::BluetoothDevice::PairingDelegate* GetPairingDelegate() const; | 108 device::BluetoothDevice::PairingDelegate* GetPairingDelegate() const; |
| 109 | 109 |
| 110 private: | 110 private: |
| 111 // Internal method to reset the current set of callbacks because a new | 111 // Internal method to reset the current set of callbacks because a new |
| 112 // request has arrived that supersedes them. | 112 // request has arrived that supersedes them. |
| 113 void ResetCallbacks(); | 113 void ResetCallbacks(); |
| 114 | 114 |
| 115 // Internal method to respond to the relevant callback for a RejectPairing | 115 // Internal method to respond to the relevant callback for a RejectPairing |
| 116 // or CancelPairing call. | 116 // or CancelPairing call. |
| 117 bool RunPairingCallbacks( | 117 bool RunPairingCallbacks( |
| 118 BluetoothAgentServiceProvider::Delegate::Status status); | 118 bluez::BluetoothAgentServiceProvider::Delegate::Status status); |
| 119 | 119 |
| 120 // The underlying BluetoothDeviceChromeOS that owns this pairing context. | 120 // The underlying BluetoothDeviceChromeOS that owns this pairing context. |
| 121 BluetoothDeviceChromeOS* device_; | 121 BluetoothDeviceChromeOS* device_; |
| 122 | 122 |
| 123 // UI Pairing Delegate to make method calls on, this must live as long as | 123 // UI Pairing Delegate to make method calls on, this must live as long as |
| 124 // the object capturing the PairingContext. | 124 // the object capturing the PairingContext. |
| 125 device::BluetoothDevice::PairingDelegate* pairing_delegate_; | 125 device::BluetoothDevice::PairingDelegate* pairing_delegate_; |
| 126 | 126 |
| 127 // Flag to indicate whether any pairing delegate method has been called | 127 // Flag to indicate whether any pairing delegate method has been called |
| 128 // during pairing. Used to determine whether we need to log the | 128 // during pairing. Used to determine whether we need to log the |
| 129 // "no pairing interaction" metric. | 129 // "no pairing interaction" metric. |
| 130 bool pairing_delegate_used_; | 130 bool pairing_delegate_used_; |
| 131 | 131 |
| 132 // During pairing these callbacks are set to those provided by method calls | 132 // During pairing these callbacks are set to those provided by method calls |
| 133 // made on the BluetoothAdapterChromeOS instance by its respective | 133 // made on the BluetoothAdapterChromeOS instance by its respective |
| 134 // BluetoothAgentServiceProvider instance, and are called by our own | 134 // bluez::BluetoothAgentServiceProvider instance, and are called by our own |
| 135 // method calls such as SetPinCode() and SetPasskey(). | 135 // method calls such as SetPinCode() and SetPasskey(). |
| 136 BluetoothAgentServiceProvider::Delegate::PinCodeCallback pincode_callback_; | 136 bluez::BluetoothAgentServiceProvider::Delegate::PinCodeCallback |
| 137 BluetoothAgentServiceProvider::Delegate::PasskeyCallback passkey_callback_; | 137 pincode_callback_; |
| 138 BluetoothAgentServiceProvider::Delegate::ConfirmationCallback | 138 bluez::BluetoothAgentServiceProvider::Delegate::PasskeyCallback |
| 139 passkey_callback_; |
| 140 bluez::BluetoothAgentServiceProvider::Delegate::ConfirmationCallback |
| 139 confirmation_callback_; | 141 confirmation_callback_; |
| 140 | 142 |
| 141 DISALLOW_COPY_AND_ASSIGN(BluetoothPairingChromeOS); | 143 DISALLOW_COPY_AND_ASSIGN(BluetoothPairingChromeOS); |
| 142 }; | 144 }; |
| 143 | 145 |
| 144 } // namespace chromeos | 146 } // namespace chromeos |
| 145 | 147 |
| 146 #endif // DEVICE_BLUETOOTH_BLUETOOTH_PAIRING_CHROMEOS_H_ | 148 #endif // DEVICE_BLUETOOTH_BLUETOOTH_PAIRING_CHROMEOS_H_ |
| OLD | NEW |