SyncFreshStartResetter.kt

1.7 KB · raw

1package com.peachpasswords.sync23import android.content.Context4import dagger.hilt.android.qualifiers.ApplicationContext5import javax.inject.Inject6import javax.inject.Singleton78/**9 * Clears every piece of state that can make a destroyed vault still look10 * paired. The Pro license deliberately lives outside this boundary.11 */12@Singleton13class SyncFreshStartResetter @Inject constructor(14    @ApplicationContext private val context: Context,15    private val devices: PairedDeviceStore,16    private val pendingDevices: PendingVouchedDeviceStore,17    private val alerts: SyncAlertStore,18    private val outcomes: SyncOutcomeStore,19    private val relaySettings: RelaySettingsStore,20    private val backgroundSync: BackgroundSyncPreference,21) {22    fun reset() {23        resetSyncStateForFreshStart(24            stopService = { PeachSyncService.stop(context) },25            clearDevices = devices::clear,26            clearPendingDevices = pendingDevices::clear,27            clearAlerts = alerts::clear,28            clearOutcomes = outcomes::reset,29            clearRelaySettings = relaySettings::reset,30            clearBackgroundPreference = backgroundSync::reset,31            clearLocalIdentity = { clearDeviceIdentity(context) },32        )33    }34}3536internal fun resetSyncStateForFreshStart(37    stopService: () -> Unit,38    clearDevices: () -> Unit,39    clearPendingDevices: () -> Unit,40    clearAlerts: () -> Unit,41    clearOutcomes: () -> Unit,42    clearRelaySettings: () -> Unit,43    clearBackgroundPreference: () -> Unit,44    clearLocalIdentity: () -> Unit,45) {46    stopService()47    clearDevices()48    clearPendingDevices()49    clearAlerts()50    clearOutcomes()51    clearRelaySettings()52    clearBackgroundPreference()53    clearLocalIdentity()54}