mirror of
https://github.com/kavishdevar/librepods.git
synced 2026-01-28 22:01:50 +00:00
android: fix the socket error notification showing up even when it connection suceeds
This commit is contained in:
@@ -803,7 +803,7 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
|||||||
|
|
||||||
notificationManager.notify(1, updatedNotification)
|
notificationManager.notify(1, updatedNotification)
|
||||||
notificationManager.cancel(2)
|
notificationManager.cancel(2)
|
||||||
} else {
|
} else if (!socket.isConnected && isConnectedLocally) {
|
||||||
showSocketConnectionFailureNotification("Socket created, but not connected. Is the Bluetooth process hooked?")
|
showSocketConnectionFailureNotification("Socket created, but not connected. Is the Bluetooth process hooked?")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1256,11 +1256,6 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
|||||||
sharedPreferences.edit {
|
sharedPreferences.edit {
|
||||||
putString("mac_address", macAddress)
|
putString("mac_address", macAddress)
|
||||||
}
|
}
|
||||||
updateNotificationContent(
|
|
||||||
true,
|
|
||||||
config.deviceName,
|
|
||||||
batteryNotification.getBattery()
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
} else if (intent?.action == AirPodsNotifications.AIRPODS_DISCONNECTED) {
|
} else if (intent?.action == AirPodsNotifications.AIRPODS_DISCONNECTED) {
|
||||||
device = null
|
device = null
|
||||||
@@ -1444,7 +1439,13 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
|||||||
withTimeout(5000L) {
|
withTimeout(5000L) {
|
||||||
try {
|
try {
|
||||||
socket.connect()
|
socket.connect()
|
||||||
|
isConnectedLocally = true
|
||||||
this@AirPodsService.device = device
|
this@AirPodsService.device = device
|
||||||
|
updateNotificationContent(
|
||||||
|
true,
|
||||||
|
config.deviceName,
|
||||||
|
batteryNotification.getBattery()
|
||||||
|
)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
showSocketConnectionFailureNotification("Socket created, but not connected. Is the Bluetooth process hooked?")
|
showSocketConnectionFailureNotification("Socket created, but not connected. Is the Bluetooth process hooked?")
|
||||||
throw e
|
throw e
|
||||||
@@ -1455,7 +1456,6 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
this@AirPodsService.device = device
|
this@AirPodsService.device = device
|
||||||
isConnectedLocally = true
|
|
||||||
socket.let { it ->
|
socket.let { it ->
|
||||||
it.outputStream.write(Enums.HANDSHAKE.value)
|
it.outputStream.write(Enums.HANDSHAKE.value)
|
||||||
it.outputStream.flush()
|
it.outputStream.flush()
|
||||||
@@ -1734,11 +1734,7 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
|||||||
showSocketConnectionFailureNotification("Failed to establish connection: ${e.message}")
|
showSocketConnectionFailureNotification("Failed to establish connection: ${e.message}")
|
||||||
isConnectedLocally = false
|
isConnectedLocally = false
|
||||||
this@AirPodsService.device = device
|
this@AirPodsService.device = device
|
||||||
updateNotificationContent(
|
updateNotificationContent(false)
|
||||||
true,
|
|
||||||
config.deviceName,
|
|
||||||
null
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1798,7 +1794,7 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
|
|||||||
CrossDevice.sendRemotePacket(CrossDevicePackets.AIRPODS_DATA_HEADER.packet + packet)
|
CrossDevice.sendRemotePacket(CrossDevicePackets.AIRPODS_DATA_HEADER.packet + packet)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (this::socket.isInitialized && socket.isConnected && socket.outputStream != null) {
|
if (this::socket.isInitialized && socket.isConnected && socket.outputStream != null && isConnectedLocally) {
|
||||||
socket.outputStream?.write(packet)
|
socket.outputStream?.write(packet)
|
||||||
socket.outputStream?.flush()
|
socket.outputStream?.flush()
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user