RelaySettingsStore.kt

1.3 KB · raw

1package com.peachpasswords.sync23import android.content.Context4import dagger.hilt.android.qualifiers.ApplicationContext5import javax.inject.Inject6import javax.inject.Singleton78/**9 * Whether this device relays sync traffic for other paired devices.10 *11 * Decided 2026-07-24 (`PEACH_SYNC_RELAY_DESIGN.md` §5): on by default. Two12 * laptops cannot sync with each other at all unless some native device relays,13 * so a phone that had to be configured first would leave that path silently14 * broken for everyone who never opened Settings.15 *16 * Plain SharedPreferences rather than the encrypted store: this is a boolean17 * about this handset's role, not a secret, and it must not travel to other18 * devices the way a vault setting would.19 */20@Singleton21class RelaySettingsStore @Inject constructor(22    @ApplicationContext context: Context,23) : RelayPolicy {24    private val prefs = context.getSharedPreferences(PREFS_FILE, Context.MODE_PRIVATE)2526    override fun isRelayEnabled(): Boolean = prefs.getBoolean(KEY_ENABLED, true)2728    fun setRelayEnabled(enabled: Boolean) {29        prefs.edit().putBoolean(KEY_ENABLED, enabled).apply()30    }3132    private companion object {33        const val PREFS_FILE = "peach_relay_settings"34        const val KEY_ENABLED = "relay_enabled"35    }36}