Closed jasaw closed 4 months ago
the delay should be configurable, i think.
In FlutterBluePlus.setOptions
Updated the PR. Delay is configurable, defaults to 2s.
thanks for the PR and being receptive to changes
thinking about the api more
it should probably be better as an argument to the disconnect function
and called androidDelay
thoughts?
it should probably be better as an argument to the disconnect function
I imagine most people wouldn't mess with the default 2s delay unless they want to go through vigorous testing themselves, so hiding it in FlutterBluePlus.setOptions
makes more sense.
appreciate your thoughts
I think with a good a good function comment it will be clear why it is there.
but yes, i think it is better as a disconnect argument.
our api already has precendent for this (see requestMtu)
Yup, done, moved to disconnect argument. 👍
looks good. I'd call it
_ensureAndroidDisconnectionDelay
I'd also simplify this comment since we already have the comment elsewhere
// record connection time
if (Platform.isAndroid) {
FlutterBluePlus._connectTimestamp[remoteId] = DateTime.now();
}
Also I dont think we need this code. seems unecessary to remove it I think, and makes things more complicated
if (Platform.isAndroid) {
// Disconnected, remove connect timestamp
FlutterBluePlus._connectTimestamp.remove(remoteId);
}
also "workaround a race condition that leaves connection stranded."
id clarify what "leaves connection stranded." means
"that causes android to silently ignore the disconnection request"?
also, im still not convinced we need both this 2-second delay change + the other PR.
The other PR seems sufficient. Why is it not sufficient?
_ensureAndroidDisconnectionDelay
Done
simplify this comment since we already have the comment elsewhere
Done
Also I dont think we need this code. seems unecessary to remove it I think, and makes things more complicated
I don't like ever growing memory usage. Yes it's just a small amount of memory, but my app is designed to run for at least 3 months without interruption or restart, and it scans and makes Bluetooth connection while running, all without human intervention. This ever growing memory usage is just going to look exactly like a memory leak when I profile the memory usage.
id clarify what "leaves connection stranded." means
Done.
also, im still not convinced we need both this 2-second delay change + the other PR. The other PR seems sufficient. Why is it not sufficient?
This 2-second delay is to workaround an Android bug that establishes connection even though gatt has been disconnected and closed. On successful connection, FBP's gatt callback function is not called, so we end up with a connection that cannot be killed because there is no gatt. Race condition is between connect and disconnect calls. The connect call merely places the connect request into a queue, so no attempt to establish a connection yet.
The other PR fixes the Android bug that ignores disconnect, but still FBP's gatt callback is still called, so we have the gatt, we can disconnect. Race condition is between disconnect call and Android stack establishing connection.
merged
4015129121bfcb22f68ffbda758e34225e29f9d8
1.32.10
Addresses issue #927. This workaround enforces a 2 second delay between connect and disconnect. Android bug report: https://issuetracker.google.com/issues/37121040