1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef LOCATION_LBS_CONTEXTHUB_NANOAPPS_NEARBY_FILTER_H_ 18 #define LOCATION_LBS_CONTEXTHUB_NANOAPPS_NEARBY_FILTER_H_ 19 20 #include "location/lbs/contexthub/nanoapps/nearby/proto/ble_filter.nanopb.h" 21 #include "third_party/contexthub/chre/util/include/chre/util/dynamic_vector.h" 22 23 namespace nearby { 24 25 // Filter monitors BLE events and notifies host when an event matches the host 26 // interest. 27 class Filter { 28 friend class FilterTest; 29 30 public: 31 // Updates filters with new rules. Returns false if message cannot be decoded 32 // as nearby_Filters. 33 bool Update(const uint8_t *message, uint32_t message_size); 34 // Returns true when filters are cleared. IsEmpty()35 bool IsEmpty() { 36 return ble_filters_.filter_count == 0; 37 } 38 39 // Matches a BLE advertisement report against BLE Filters. 40 // Returns matched result in filter_results, which includes a BleFilterResult 41 // when an advertisement matches a Filter. 42 // Fast Pair filter result is returned separately in fp_filter_results. 43 void MatchBle(const chreBleAdvertisingReport &report, 44 chre::DynamicVector<nearby_BleFilterResult> *filter_results, 45 chre::DynamicVector<nearby_BleFilterResult> *fp_filter_results); 46 47 private: 48 nearby_BleFilters ble_filters_ = nearby_BleFilters_init_zero; 49 // BLE Scan interval. Default to 1 minute. 50 uint64_t scan_interval_ms_ = 60 * 1000; 51 }; 52 53 } // namespace nearby 54 55 #endif // LOCATION_LBS_CONTEXTHUB_NANOAPPS_NEARBY_FILTER_H_ 56