From a2249dc07a1382cfafb228f2148efe0cd1a20891 Mon Sep 17 00:00:00 2001 From: Edwin Wu Date: Tue, 10 Mar 2026 17:54:49 -0700 Subject: [PATCH] Unpublish existing L2CAP channel before starting a new server. PiperOrigin-RevId: 881707142 --- .../implementation/apple/Mediums/BLE/GNCBLEL2CAPServer.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/platform/implementation/apple/Mediums/BLE/GNCBLEL2CAPServer.m b/internal/platform/implementation/apple/Mediums/BLE/GNCBLEL2CAPServer.m index e33f458a..1c53b894 100644 --- a/internal/platform/implementation/apple/Mediums/BLE/GNCBLEL2CAPServer.m +++ b/internal/platform/implementation/apple/Mediums/BLE/GNCBLEL2CAPServer.m @@ -86,6 +86,10 @@ static char *const kGNCBLEL2CAPServerQueueLabel = "com.google.nearby.GNCBLEL2CAP _peripheralManager.peripheralDelegate = self; } + if (_PSM > 0) { + GNCLoggerInfo((@"[NEARBY] Unpublish L2CAP channel with PSM: %@"), @(_PSM)); + [_peripheralManager unpublishL2CAPChannel:_PSM]; + } if (_peripheralManager.state == CBManagerStatePoweredOn) { // Bluetooth link is already encrypted, however encryption is not required here to avoid getting // insufficient authentication errors due to initialization order.