Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d7e28911 authored by Sonny Sasaka's avatar Sonny Sasaka
Browse files

Floss: Modify IScannerCallback

IScannerCallback needs a dedicated callback for clients to listen to
when advertisements are in the beginning of RSSI-range instead of every
advertisements received during the range. So this modifies
IScannerCallback methods:
* Add OnAdvertisementFound: beginning of adv in RSSI range
* Add plan to rename OnScanResultLost to OnAdvertisementLost for
  symmetry. Will be in future change since this needs to be coordinated
  with Chrome change.
* Redefine OnScanResult to be explicit that this is triggered on every
  advertisement detected if satisfies the filter and RSSI range.

Bug: 269343922
Tag: #floss
Test: Build Floss on Linux and Chrome OS, run with chrome-btclient.

Change-Id: I0a0c683f48586deb4d2227f1cb011c5ee09e95e6
parent a17741fe
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -86,13 +86,12 @@ struct MsftExtensionManager::impl {
    ASSERT(view.IsValid());

    // The monitor state is 0x00 when the controller stops monitoring the device.
    if (view.GetMonitorState() == 0x00) {
    if (view.GetMonitorState() == 0x00 || view.GetMonitorState() == 0x01) {
      AdvertisingFilterOnFoundOnLostInfo on_found_on_lost_info;
      on_found_on_lost_info.advertiser_address_type = view.GetAddressType();
      on_found_on_lost_info.advertiser_address = view.GetBdAddr();
      on_found_on_lost_info.advertiser_state = view.GetMonitorState();
      scanning_callbacks_->OnTrackAdvFoundLost(on_found_on_lost_info);
    } else if (view.GetMonitorState() == 0x01) {
      // TODO: Bubble up this event via `OnScanResult`.
    } else {
      LOG_WARN("The Microsoft vendor event monitor state is invalid.");
      return;
+6 −0
Original line number Diff line number Diff line
@@ -333,6 +333,12 @@ impl IScannerCallback for ScannerCallback {
        }
    }

    fn on_advertisement_found(&self, scan_result: ScanResult) {
        if self.context.lock().unwrap().active_scanner_ids.len() > 0 {
            print_info!("Advertisement found: {:#?}", scan_result);
        }
    }

    fn on_scan_result_lost(&self, scan_result: ScanResult) {
        if self.context.lock().unwrap().active_scanner_ids.len() > 0 {
            print_info!("Scan result lost: {:#?}", scan_result);
+5 −0
Original line number Diff line number Diff line
@@ -339,6 +339,11 @@ impl IScannerCallback for IScannerCallbackDBus {
        dbus_generated!()
    }

    #[dbus_method("OnAdvertisementFound")]
    fn on_advertisement_found(&self, scan_result: ScanResult) {
        dbus_generated!()
    }

    #[dbus_method("OnScanResultLost")]
    fn on_scan_result_lost(&self, scan_result: ScanResult) {
        dbus_generated!()
+5 −0
Original line number Diff line number Diff line
@@ -294,6 +294,11 @@ impl IScannerCallback for ScannerCallbackDBus {
        dbus_generated!()
    }

    #[dbus_method("OnAdvertisementFound")]
    fn on_advertisement_found(&self, scan_result: ScanResult) {
        dbus_generated!()
    }

    #[dbus_method("OnScanResultLost")]
    fn on_scan_result_lost(&self, scan_result: ScanResult) {
        dbus_generated!()
+18 −5
Original line number Diff line number Diff line
@@ -1059,13 +1059,20 @@ pub trait IScannerCallback: RPCProxy {
    /// When the `register_scanner` request is done.
    fn on_scanner_registered(&self, uuid: Uuid128Bit, scanner_id: u8, status: GattStatus);

    /// When an LE advertisement matching aggregate filters is detected. Since this callback is
    /// shared among all scanner callbacks, clients may receive more advertisements than what is
    /// requested to be filtered in.
    /// When an LE advertisement matching aggregate filters is detected. This callback is shared
    /// among all scanner callbacks and is triggered for *every* advertisement that the controller
    /// receives. For listening to the beginning and end of a specific scanner's advertisements
    /// detected while in RSSI range, use on_advertisement_found and on_scan_result_lost below.
    fn on_scan_result(&self, scan_result: ScanResult);

    /// When an LE advertisement matching aggregate filters is found. The criteria of
    /// how a device is considered found is specified by ScanFilter.
    fn on_advertisement_found(&self, scan_result: ScanResult);

    /// When an LE advertisement matching aggregate filters is no longer detected. The criteria of
    /// how a device is considered lost is specified by ScanFilter.
    // TODO(b/269343922): Rename this to on_advertisement_lost for symmetry with
    // on_advertisement_found.
    fn on_scan_result_lost(&self, scan_result: ScanResult);

    /// When LE Scan module changes suspend mode due to system suspend/resume.
@@ -3882,7 +3889,7 @@ impl BtifGattScannerCallbacks for BluetoothGatt {
            let adv_data =
                [&track_adv_info.adv_packet[..], &track_adv_info.scan_response[..]].concat();

            callback.on_scan_result_lost(ScanResult {
            let scan_result = ScanResult {
                name: adv_parser::extract_name(adv_data.as_slice()),
                address: track_adv_info.advertiser_address.to_string(),
                addr_type: track_adv_info.advertiser_address_type,
@@ -3900,7 +3907,13 @@ impl BtifGattScannerCallbacks for BluetoothGatt {
                service_data: adv_parser::extract_service_data(adv_data.as_slice()),
                manufacturer_data: adv_parser::extract_manufacturer_data(adv_data.as_slice()),
                adv_data,
            });
            };

            if track_adv_info.advertiser_state == 0x01 {
                callback.on_advertisement_found(scan_result);
            } else {
                callback.on_scan_result_lost(scan_result);
            }
        });
    }
}