Skip to content

Commit

Permalink
Merge pull request #426 from NordicSemiconductor/workaround/setting-p…
Browse files Browse the repository at this point in the history
…referred-phy

Reading PHY if no callback for setting preferred one
  • Loading branch information
philips77 authored Sep 29, 2022
2 parents f73171c + 46d1781 commit 0a691f8
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions ble/src/main/java/no/nordicsemi/android/ble/BleManagerHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -3501,8 +3501,24 @@ private synchronized void nextRequest(final boolean force) {
//noinspection ConstantConditions
final PhyRequest pr = (PhyRequest) request;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
result = internalSetPreferredPhy(pr.getPreferredTxPhy(),
pr.getPreferredRxPhy(), pr.getPreferredPhyOptions());
result = internalSetPreferredPhy(
pr.getPreferredTxPhy(),
pr.getPreferredRxPhy(),
pr.getPreferredPhyOptions()
);
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.TIRAMISU) {
// There seems to be a bug on Android 13, where there is no callback
// for setPreferredPhy(...). onPhyUpdate(...) should be called, but it is not.
// See: https://github.com/NordicSemiconductor/Android-BLE-Library/issues/414
// However, the operation seems to complete successfully.
// As a workaround, let's read the PHYs and notify the user.
handler.postDelayed(() -> {
if (!pr.finished) {
log(Log.WARN, () -> "Callback not received in 1000 ms");
internalReadPhy();
}
}, 1000);
}
} else {
result = connected;
if (result) {
Expand Down

0 comments on commit 0a691f8

Please sign in to comment.