Enable the three Android BLE connection flags by default
This commit is contained in:
1 parent
5ea845e801
commit
44ac46b09e
2 files changed
+15
-6
No files matched your search
@@ -48,14 +48,14 @@ class ConfigProvider(private val context: Context) {
|
||||
private val configFiles = ConfigFileStore { level, message -> LogManager.addLog(level, "CFG", message) }
|
||||
private val bleFlags = intPreferencesKey("bluetooth_flags")
|
||||
val bluetoothSettings: Flow<Int> = context.dataStore.data.map { preferences ->
|
||||
val flags = preferences[bleFlags] ?: 0
|
||||
val flags = preferences[bleFlags] ?: DEFAULT_BLE_FLAGS
|
||||
if (flags !in 0..7) LogManager.addLog("WARN", "discovery", "Invalid stored BLE flags=$flags; disabling Bluetooth")
|
||||
flags.takeIf { it in 0..7 } ?: 0
|
||||
}.distinctUntilChanged()
|
||||
suspend fun setBleFlag(bit: Int, enabled: Boolean) {
|
||||
require(bit in setOf(1, 2, 4))
|
||||
context.dataStore.edit {
|
||||
val flags = (it[bleFlags] ?: 0).takeIf { value -> value in 0..7 } ?: 0
|
||||
val flags = (it[bleFlags] ?: DEFAULT_BLE_FLAGS).takeIf { value -> value in 0..7 } ?: 0
|
||||
it[bleFlags] = if (enabled) flags or bit else flags and bit.inv()
|
||||
}
|
||||
LogManager.addLog("INFO", "discovery", "BLE setting bit=$bit enabled=$enabled")
|
||||
@@ -534,6 +534,7 @@ class ConfigProvider(private val context: Context) {
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val DEFAULT_BLE_FLAGS = 7 // Использование BLE, реклама и входящие подключения; приглашения задаются отдельно.
|
||||
private val ipv6FlagsWarning = java.util.concurrent.atomic.AtomicBoolean(false)
|
||||
/** Accept only global unicast (2000::/3) and unique local (fc00::/7) IPv6. */
|
||||
fun isUsableV6(addr: Inet6Address): Boolean {
|
||||
|
||||
+12
-4
@@ -103,14 +103,22 @@ fun BluetoothSettingsTab() {
|
||||
})
|
||||
}
|
||||
listOf(2 to R.string.ble_advertise, 4 to R.string.ble_incoming).forEach { (bit, label) ->
|
||||
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {
|
||||
Text(stringResource(label), Modifier.weight(1f))
|
||||
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically) {
|
||||
Column(Modifier.weight(1f)) {
|
||||
Text(stringResource(label))
|
||||
if (bit == 4) Text(stringResource(R.string.ble_incoming_hint), style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
}
|
||||
Switch(enabled = confirmedFlags != null, checked = flags and bit != 0,
|
||||
onCheckedChange = { save(bit, it) })
|
||||
}
|
||||
}
|
||||
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {
|
||||
Text(stringResource(R.string.ble_invites_enabled), Modifier.weight(1f))
|
||||
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically) {
|
||||
Column(Modifier.weight(1f)) {
|
||||
Text(stringResource(R.string.ble_invites_enabled))
|
||||
Text(stringResource(R.string.ble_invites_hint), style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
}
|
||||
Switch(enabled = receiveInvites != null, checked = receiveInvites == true, onCheckedChange = { enabled ->
|
||||
provider.changes.submit("Bluetooth invitations") {
|
||||
val value = if (enabled) "1" else "0"
|
||||
|
||||
Reference in new issue
Block a user