зеркало из https://github.com/mozilla/gecko-dev.git
servo: Merge #14468 - Move allowedService and blocklist checks into caching functions (from szeged:blocklist-allowed-services); r=jdm
<!-- Please describe your changes on the following line: --> Move allowedService and blocklist checks into caching functions in `bluetooth/lib.rs`, to avoid caching not allowed services and blocklisted services, characteristics and descriptors. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] There are tests for these changes <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 55248aeb2b890a13f7d021ad4e37662d57135945
This commit is contained in:
Родитель
db21c41983
Коммит
adb19135b6
|
@ -424,10 +424,15 @@ impl BluetoothManager {
|
||||||
adapter: &mut BluetoothAdapter,
|
adapter: &mut BluetoothAdapter,
|
||||||
device_id: &str)
|
device_id: &str)
|
||||||
-> Vec<BluetoothGATTService> {
|
-> Vec<BluetoothGATTService> {
|
||||||
let services = match self.get_device(adapter, device_id) {
|
let mut services = match self.get_device(adapter, device_id) {
|
||||||
Some(d) => d.get_gatt_services().unwrap_or(vec!()),
|
Some(d) => d.get_gatt_services().unwrap_or(vec!()),
|
||||||
None => vec!(),
|
None => vec!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
services.retain(|s| !uuid_is_blocklisted(&s.get_uuid().unwrap_or(String::new()), Blocklist::All) &&
|
||||||
|
self.allowed_services
|
||||||
|
.get(device_id)
|
||||||
|
.map_or(false, |uuids| uuids.contains(&s.get_uuid().unwrap_or(String::new()))));
|
||||||
for service in &services {
|
for service in &services {
|
||||||
self.cached_services.insert(service.get_id(), service.clone());
|
self.cached_services.insert(service.get_id(), service.clone());
|
||||||
self.service_to_device.insert(service.get_id(), device_id.to_owned());
|
self.service_to_device.insert(service.get_id(), device_id.to_owned());
|
||||||
|
@ -461,11 +466,12 @@ impl BluetoothManager {
|
||||||
adapter: &mut BluetoothAdapter,
|
adapter: &mut BluetoothAdapter,
|
||||||
service_id: &str)
|
service_id: &str)
|
||||||
-> Vec<BluetoothGATTCharacteristic> {
|
-> Vec<BluetoothGATTCharacteristic> {
|
||||||
let characteristics = match self.get_gatt_service(adapter, service_id) {
|
let mut characteristics = match self.get_gatt_service(adapter, service_id) {
|
||||||
Some(s) => s.get_gatt_characteristics().unwrap_or(vec!()),
|
Some(s) => s.get_gatt_characteristics().unwrap_or(vec!()),
|
||||||
None => vec!(),
|
None => vec!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
characteristics.retain(|c| !uuid_is_blocklisted(&c.get_uuid().unwrap_or(String::new()), Blocklist::All));
|
||||||
for characteristic in &characteristics {
|
for characteristic in &characteristics {
|
||||||
self.cached_characteristics.insert(characteristic.get_id(), characteristic.clone());
|
self.cached_characteristics.insert(characteristic.get_id(), characteristic.clone());
|
||||||
self.characteristic_to_service.insert(characteristic.get_id(), service_id.to_owned());
|
self.characteristic_to_service.insert(characteristic.get_id(), service_id.to_owned());
|
||||||
|
@ -524,11 +530,12 @@ impl BluetoothManager {
|
||||||
adapter: &mut BluetoothAdapter,
|
adapter: &mut BluetoothAdapter,
|
||||||
characteristic_id: &str)
|
characteristic_id: &str)
|
||||||
-> Vec<BluetoothGATTDescriptor> {
|
-> Vec<BluetoothGATTDescriptor> {
|
||||||
let descriptors = match self.get_gatt_characteristic(adapter, characteristic_id) {
|
let mut descriptors = match self.get_gatt_characteristic(adapter, characteristic_id) {
|
||||||
Some(c) => c.get_gatt_descriptors().unwrap_or(vec!()),
|
Some(c) => c.get_gatt_descriptors().unwrap_or(vec!()),
|
||||||
None => vec!(),
|
None => vec!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
descriptors.retain(|d| !uuid_is_blocklisted(&d.get_uuid().unwrap_or(String::new()), Blocklist::All));
|
||||||
for descriptor in &descriptors {
|
for descriptor in &descriptors {
|
||||||
self.cached_descriptors.insert(descriptor.get_id(), descriptor.clone());
|
self.cached_descriptors.insert(descriptor.get_id(), descriptor.clone());
|
||||||
self.descriptor_to_characteristic.insert(descriptor.get_id(), characteristic_id.to_owned());
|
self.descriptor_to_characteristic.insert(descriptor.get_id(), characteristic_id.to_owned());
|
||||||
|
@ -743,10 +750,6 @@ impl BluetoothManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
services_vec.retain(|s| !uuid_is_blocklisted(&s.uuid, Blocklist::All) &&
|
|
||||||
self.allowed_services
|
|
||||||
.get(&device_id)
|
|
||||||
.map_or(false, |uuids| uuids.contains(&s.uuid)));
|
|
||||||
|
|
||||||
// Step 7.
|
// Step 7.
|
||||||
if services_vec.is_empty() {
|
if services_vec.is_empty() {
|
||||||
|
@ -919,7 +922,6 @@ impl BluetoothManager {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
characteristics_vec.retain(|c| !uuid_is_blocklisted(&c.uuid, Blocklist::All));
|
|
||||||
|
|
||||||
// Step 7.
|
// Step 7.
|
||||||
if characteristics_vec.is_empty() {
|
if characteristics_vec.is_empty() {
|
||||||
|
@ -987,7 +989,6 @@ impl BluetoothManager {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
descriptors_vec.retain(|d| !uuid_is_blocklisted(&d.uuid, Blocklist::All));
|
|
||||||
|
|
||||||
// Step 7.
|
// Step 7.
|
||||||
if descriptors_vec.is_empty() {
|
if descriptors_vec.is_empty() {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче