mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Bluetooth Permission API integration
This commit is contained in:
parent
f3ddee5dbc
commit
5287cd3bea
17 changed files with 550 additions and 45 deletions
|
@ -256,6 +256,9 @@ impl BluetoothManager {
|
|||
BluetoothRequest::GetAvailability(sender) => {
|
||||
let _ = sender.send(self.get_availability());
|
||||
},
|
||||
BluetoothRequest::MatchesFilter(id, filters, sender) => {
|
||||
let _ = sender.send(self.device_matches_filter(&id, &filters));
|
||||
},
|
||||
BluetoothRequest::Exit => {
|
||||
break
|
||||
},
|
||||
|
@ -425,6 +428,17 @@ impl BluetoothManager {
|
|||
self.cached_devices.contains_key(device_id) && self.address_to_id.values().any(|v| v == device_id)
|
||||
}
|
||||
|
||||
fn device_matches_filter(&mut self,
|
||||
device_id: &str,
|
||||
filters: &BluetoothScanfilterSequence)
|
||||
-> BluetoothResult<bool> {
|
||||
let mut adapter = try!(self.get_adapter());
|
||||
match self.get_device(&mut adapter, device_id) {
|
||||
Some(ref device) => Ok(matches_filters(device, filters)),
|
||||
None => Ok(false),
|
||||
}
|
||||
}
|
||||
|
||||
// Service
|
||||
|
||||
fn get_and_cache_gatt_services(&mut self,
|
||||
|
@ -561,6 +575,9 @@ impl BluetoothManager {
|
|||
-> BluetoothResponseResult {
|
||||
// Step 6.
|
||||
let mut adapter = try!(self.get_adapter());
|
||||
|
||||
// Step 7.
|
||||
// Note: There are no requiredServiceUUIDS, we scan for all devices.
|
||||
if let Ok(ref session) = adapter.create_discovery_session() {
|
||||
if session.start_discovery().is_ok() {
|
||||
if !is_mock_adapter(&adapter) {
|
||||
|
@ -570,8 +587,6 @@ impl BluetoothManager {
|
|||
let _ = session.stop_discovery();
|
||||
}
|
||||
|
||||
// Step 7.
|
||||
// Note: There are no requiredServiceUUIDS, we scan for all devices.
|
||||
let mut matched_devices = self.get_and_cache_devices(&mut adapter);
|
||||
|
||||
// Step 8.
|
||||
|
@ -582,8 +597,6 @@ impl BluetoothManager {
|
|||
}
|
||||
|
||||
// Step 9.
|
||||
// TODO: After the permission API implementation
|
||||
// https://w3c.github.io/permissions/#prompt-the-user-to-choose
|
||||
if let Some(address) = self.select_device(matched_devices, &adapter) {
|
||||
let device_id = match self.address_to_id.get(&address) {
|
||||
Some(id) => id.clone(),
|
||||
|
@ -602,7 +615,7 @@ impl BluetoothManager {
|
|||
return Ok(BluetoothResponse::RequestDevice(message));
|
||||
}
|
||||
}
|
||||
// TODO: Step 10 - 11: Implement the permission API.
|
||||
// Step 10.
|
||||
return Err(BluetoothError::NotFound);
|
||||
// Step 12: Missing, because it is optional.
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue