Skip to content

Commit 9fbf803

Browse files
committed
fixup: respect auto-connect preference on Android side [2/2]
1 parent 4941b98 commit 9fbf803

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

app/src/main/java/com/sameerasw/airsync/utils/UDPDiscoveryManager.kt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,12 +463,25 @@ object UDPDiscoveryManager {
463463

464464
val deviceId = DeviceInfoUtil.getDeviceId(context)
465465

466+
val autoConnect = try {
467+
runBlocking { ds.getAutoReconnectEnabled().first() }
468+
} catch (e: Exception) {
469+
true
470+
}
471+
val bleAutoConnect = try {
472+
runBlocking { ds.getBleAutoConnectEnabled().first() }
473+
} catch (e: Exception) {
474+
true
475+
}
476+
466477
val json = JSONObject()
467478
json.put("type", "presence")
468479
json.put("deviceType", "android")
469480
json.put("id", deviceId)
470481
json.put("name", deviceName)
471482
json.put("ips", FilteredIpArray(filteredLocalIps)) // Send FILTERED IPs
483+
json.put("autoConnect", autoConnect)
484+
json.put("bleAutoConnect", bleAutoConnect)
472485
val payload = json.toString()
473486
val data = payload.toByteArray()
474487

@@ -583,12 +596,26 @@ object UDPDiscoveryManager {
583596
if (filteredIps.isEmpty()) return
584597

585598
val deviceId = DeviceInfoUtil.getDeviceId(context)
599+
600+
val autoConnect = try {
601+
runBlocking { ds.getAutoReconnectEnabled().first() }
602+
} catch (e: Exception) {
603+
true
604+
}
605+
val bleAutoConnect = try {
606+
runBlocking { ds.getBleAutoConnectEnabled().first() }
607+
} catch (e: Exception) {
608+
true
609+
}
610+
586611
val json = JSONObject()
587612
json.put("type", "presence")
588613
json.put("deviceType", "android")
589614
json.put("id", deviceId)
590615
json.put("name", deviceName)
591616
json.put("ips", FilteredIpArray(filteredIps))
617+
json.put("autoConnect", autoConnect)
618+
json.put("bleAutoConnect", bleAutoConnect)
592619
val payload = json.toString()
593620

594621
sendUnicast(targetIp, payload)
@@ -623,11 +650,24 @@ object UDPDiscoveryManager {
623650
val deviceName = if (customName.isNotBlank()) customName else android.os.Build.MODEL
624651
val deviceId = DeviceInfoUtil.getDeviceId(context)
625652

653+
val autoConnect = try {
654+
runBlocking { ds.getAutoReconnectEnabled().first() }
655+
} catch (e: Exception) {
656+
true
657+
}
658+
val bleAutoConnect = try {
659+
runBlocking { ds.getBleAutoConnectEnabled().first() }
660+
} catch (e: Exception) {
661+
true
662+
}
663+
626664
val json = JSONObject()
627665
json.put("type", "peerExchange")
628666
json.put("deviceType", "android")
629667
json.put("id", deviceId)
630668
json.put("name", deviceName)
669+
json.put("autoConnect", autoConnect)
670+
json.put("bleAutoConnect", bleAutoConnect)
631671

632672
// Include all IPs based on settings
633673
val ipsToSend = if (expandNetworkingEnabled) allIps else allIps.filter { !it.startsWith("100.") }

app/src/main/java/com/sameerasw/airsync/utils/WakeupHandler.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ object WakeupHandler {
4545
return
4646
}
4747

48+
if (!isManual) {
49+
val isAutoReconnectEnabled = dataStoreManager.getAutoReconnectEnabled().first()
50+
if (!isAutoReconnectEnabled) {
51+
Log.d(TAG, "Ignoring wake-up request because auto-reconnect is disabled in settings")
52+
return
53+
}
54+
}
55+
4856
// Clear manual disconnect flag since this is an external wake-up request
4957
dataStoreManager.setUserManuallyDisconnected(false)
5058

0 commit comments

Comments
 (0)