@@ -803,7 +803,7 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
803803
804804 notificationManager.notify(1 , updatedNotification)
805805 notificationManager.cancel(2 )
806- } else {
806+ } else if ( ! socket.isConnected && isConnectedLocally) {
807807 showSocketConnectionFailureNotification(" Socket created, but not connected. Is the Bluetooth process hooked?" )
808808 }
809809 }
@@ -1256,11 +1256,6 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
12561256 sharedPreferences.edit {
12571257 putString(" mac_address" , macAddress)
12581258 }
1259- updateNotificationContent(
1260- true ,
1261- config.deviceName,
1262- batteryNotification.getBattery()
1263- )
12641259 }
12651260 } else if (intent?.action == AirPodsNotifications .AIRPODS_DISCONNECTED ) {
12661261 device = null
@@ -1444,7 +1439,13 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
14441439 withTimeout(5000L ) {
14451440 try {
14461441 socket.connect()
1442+ isConnectedLocally = true
14471443 this @AirPodsService.device = device
1444+ updateNotificationContent(
1445+ true ,
1446+ config.deviceName,
1447+ batteryNotification.getBattery()
1448+ )
14481449 } catch (e: Exception ) {
14491450 showSocketConnectionFailureNotification(" Socket created, but not connected. Is the Bluetooth process hooked?" )
14501451 throw e
@@ -1455,7 +1456,6 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
14551456 }
14561457 }
14571458 this @AirPodsService.device = device
1458- isConnectedLocally = true
14591459 socket.let { it ->
14601460 it.outputStream.write(Enums .HANDSHAKE .value)
14611461 it.outputStream.flush()
@@ -1734,11 +1734,7 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
17341734 showSocketConnectionFailureNotification(" Failed to establish connection: ${e.message} " )
17351735 isConnectedLocally = false
17361736 this @AirPodsService.device = device
1737- updateNotificationContent(
1738- true ,
1739- config.deviceName,
1740- null
1741- )
1737+ updateNotificationContent(false )
17421738 }
17431739 }
17441740 }
@@ -1798,7 +1794,7 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
17981794 CrossDevice .sendRemotePacket(CrossDevicePackets .AIRPODS_DATA_HEADER .packet + packet)
17991795 return
18001796 }
1801- if (this ::socket.isInitialized && socket.isConnected && socket.outputStream != null ) {
1797+ if (this ::socket.isInitialized && socket.isConnected && socket.outputStream != null && isConnectedLocally ) {
18021798 socket.outputStream?.write(packet)
18031799 socket.outputStream?.flush()
18041800 } else {
0 commit comments