mirror of
https://github.com/AU-COVIDSafe/mobile-ios.git
synced 2025-04-16 19:55:01 +00:00
Clean up Central's scannedPeripherals dict.
When COVIDSafe removed the timer code, it also removed the reset of this dictionary, so currently it grows and grows in size. It probably doesn't get large enough to cause real problems (e.g. the OS killing the app), but for completeness also reset it on a memory warning. By my scrap paper calculations, a group of 50 people (with identifiers changing every 15m) will get it to ~200kb in 2 hours, so potentially over days it could cause issues currently.
This commit is contained in:
parent
2063cea613
commit
17f4b7e1be
1 changed files with 18 additions and 0 deletions
|
@ -29,6 +29,7 @@ class CentralController: NSObject {
|
||||||
private var central: CBCentralManager?
|
private var central: CBCentralManager?
|
||||||
private var recoveredPeripherals: [CBPeripheral] = []
|
private var recoveredPeripherals: [CBPeripheral] = []
|
||||||
private var queue: DispatchQueue
|
private var queue: DispatchQueue
|
||||||
|
private var lastCleanedScannedPeripherals = Date()
|
||||||
|
|
||||||
// This dict is to keep track of discovered android devices, so that i do not connect to the same android device multiple times within the same BluetraceConfig.CentralScanInterval
|
// This dict is to keep track of discovered android devices, so that i do not connect to the same android device multiple times within the same BluetraceConfig.CentralScanInterval
|
||||||
private var discoveredAndroidPeriManufacturerToUUIDMap = [Data: UUID]()
|
private var discoveredAndroidPeriManufacturerToUUIDMap = [Data: UUID]()
|
||||||
|
@ -42,6 +43,12 @@ class CentralController: NSObject {
|
||||||
public init(queue: DispatchQueue) {
|
public init(queue: DispatchQueue) {
|
||||||
self.queue = queue
|
self.queue = queue
|
||||||
super.init()
|
super.init()
|
||||||
|
NotificationCenter.default.addObserver(
|
||||||
|
forName: UIApplication.didReceiveMemoryWarningNotification,
|
||||||
|
object: nil,
|
||||||
|
queue: .main) { [weak self] notification in
|
||||||
|
self?.cleanupScannedPeripherals()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func turnOn() {
|
func turnOn() {
|
||||||
|
@ -94,6 +101,14 @@ class CentralController: NSObject {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fileprivate func cleanupScannedPeripherals() {
|
||||||
|
scannedPeripherals = scannedPeripherals.filter { scan in
|
||||||
|
guard let encounterTime = scan.value.encounter.timestamp else { return true }
|
||||||
|
return abs(encounterTime.timeIntervalSinceNow) < BluetraceConfig.CentralScanInterval
|
||||||
|
}
|
||||||
|
lastCleanedScannedPeripherals = Date()
|
||||||
|
}
|
||||||
|
|
||||||
public func getState() -> CBManagerState? {
|
public func getState() -> CBManagerState? {
|
||||||
return central?.state
|
return central?.state
|
||||||
}
|
}
|
||||||
|
@ -181,6 +196,9 @@ extension CentralController: CBCentralManagerDelegate {
|
||||||
"advertisments": advertisementData as AnyObject] as AnyObject
|
"advertisments": advertisementData as AnyObject] as AnyObject
|
||||||
|
|
||||||
DLog("\(debugLogs)")
|
DLog("\(debugLogs)")
|
||||||
|
if (abs(lastCleanedScannedPeripherals.timeIntervalSince(Date())) > BluetraceConfig.CentralScanInterval) {
|
||||||
|
cleanupScannedPeripherals()
|
||||||
|
}
|
||||||
var initialEncounter = EncounterRecord(rssi: RSSI.doubleValue, txPower: advertisementData[CBAdvertisementDataTxPowerLevelKey] as? Double)
|
var initialEncounter = EncounterRecord(rssi: RSSI.doubleValue, txPower: advertisementData[CBAdvertisementDataTxPowerLevelKey] as? Double)
|
||||||
initialEncounter.timestamp = nil
|
initialEncounter.timestamp = nil
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue