repeatingAfterBonding

open suspend override fun <T> repeatingAfterBonding(request: suspend () -> T): T

Executes a GATT request, and repeats it once if the system did not, after bonding that was started because the link had to be authenticated or encrypted.

Android 8+ holds the request, bonds and completes it. Older versions do not. On Android 6.0.1 (Samsung Galaxy Folder, confirmed with an HCI log) the request is silently dropped: the peripheral returns Insufficient Authentication, the phone bonds, and the app is never notified about the result, nor is the request sent again. Other devices were reported to return the error to the app. Both cases are handled here: the request is repeated once when bonding completes before the request did, or when the request failed with Insufficient Authentication or Insufficient Encryption and bonding succeeded.

The request is not repeated if the phone was bonded before it, as the error is not caused by the lack of the bond. If bonding fails, the original error is thrown, or, when the system does not report the result of the request, it never completes.