@@ -102,22 +102,25 @@ extension AndroidCentral.LowEnergyScanCallback {
102102 }
103103}
104104
105- @JavaClass ( " org.pureswift.bluetooth.BluetoothGattCallback " )
106- class GattCallback : AndroidBluetooth . BluetoothGattCallback {
107-
108- weak var central : AndroidCentral ?
109-
110- @JavaMethod
111- @_nonoverride convenience init ( environment: JNIEnvironment ? = nil )
105+ extension AndroidCentral {
112106
113- convenience init ( central: AndroidCentral , environment: JNIEnvironment ? = nil ) {
114- self . init ( environment: environment)
115- self . central = central
107+ @JavaClass ( " org.pureswift.bluetooth.BluetoothGattCallback " )
108+ class GattCallback : AndroidBluetooth . BluetoothGattCallback {
109+
110+ weak var central : AndroidCentral ?
111+
112+ @JavaMethod
113+ @_nonoverride convenience init ( environment: JNIEnvironment ? = nil )
114+
115+ convenience init ( central: AndroidCentral , environment: JNIEnvironment ? = nil ) {
116+ self . init ( environment: environment)
117+ self . central = central
118+ }
116119 }
117120}
118121
119122@JavaImplementation ( " org.pureswift.bluetooth.BluetoothGattCallback " )
120- extension GattCallback {
123+ extension AndroidCentral . GattCallback {
121124
122125 /**
123126 Callback indicating when GATT client has connected/disconnected to/from a remote GATT server.
@@ -164,22 +167,28 @@ extension GattCallback {
164167 }
165168 }
166169 }
167- /*
170+
168171 @JavaMethod
169172 public func onServicesDiscovered(
170173 gatt: BluetoothGatt ? ,
171174 status: Int32
172175 ) {
173- let log = central?.log
176+ guard let central, let gatt else {
177+ assertionFailure ( )
178+ return
179+ }
180+ let log = central. log
174181 let peripheral = Peripheral ( gatt)
182+ let status = BluetoothGatt . Status ( rawValue: status)
175183 log ? ( " \( type ( of: self ) ) : \( #function) Status: \( status) " )
176184
177185 Task {
178- await central? .storage.update { state in
186+ await central. storage. update { state in
179187 // success discovering
180188 switch status {
181189 case . success:
182- guard let services = state.cache[peripheral]?.update(gatt.services) else {
190+ guard let javaServices = gatt. getServices ( ) ? . toArray ( ) . map ( { $0!. as ( BluetoothGattService . self) ! } ) ,
191+ let services = state. cache [ peripheral] ? . update ( javaServices) else {
183192 assertionFailure ( )
184193 return
185194 }
@@ -191,7 +200,7 @@ extension GattCallback {
191200 }
192201 }
193202 }
194-
203+ /*
195204 @JavaMethod
196205 public func onCharacteristicChanged(
197206 gatt: BluetoothGatt?,
0 commit comments