Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/flipcash/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
<application
android:name="com.flipcash.app.FlipcashApp"
android:allowBackup="true"
android:fullBackupContent="@xml/backup_rules"
android:dataExtractionRules="@xml/data_extraction_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
Expand Down
12 changes: 12 additions & 0 deletions apps/flipcash/app/src/main/res/xml/backup_rules.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
<exclude
domain="file"
path="datastore/beta-flags.preferences_pb" />
<exclude
domain="file"
path="datastore/user-flag-overrides.preferences_pb" />
<exclude
domain="file"
path="datastore/release-stage.preferences_pb" />
</full-backup-content>
25 changes: 25 additions & 0 deletions apps/flipcash/app/src/main/res/xml/data_extraction_rules.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<data-extraction-rules>
<cloud-backup>
<exclude
domain="file"
path="datastore/beta-flags.preferences_pb" />
<exclude
domain="file"
path="datastore/user-flag-overrides.preferences_pb" />
<exclude
domain="file"
path="datastore/release-stage.preferences_pb" />
</cloud-backup>
<device-transfer>
<exclude
domain="file"
path="datastore/beta-flags.preferences_pb" />
<exclude
domain="file"
path="datastore/user-flag-overrides.preferences_pb" />
<exclude
domain="file"
path="datastore/release-stage.preferences_pb" />
</device-transfer>
</data-extraction-rules>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.flipcash.app.updates.resolveStage
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.map
import kotlinx.serialization.json.Json
import java.io.File
import okhttp3.OkHttpClient
import okhttp3.Request
import timber.log.Timber
Expand All @@ -31,6 +32,14 @@ internal class GooglePlayReleaseStageProvider(private val context: Context) : Re
private set

override suspend fun loadCachedStage(versionCode: Int): ReleaseStage? {
// Clear cached manifest restored from backup on fresh install.
val marker = File(context.noBackupFilesDir, "release-stage-initialized")
if (!marker.exists()) {
context.releaseStageDataStore.edit { it.clear() }
marker.createNewFile()
return null
}

val cached = context.releaseStageDataStore.data
.map { prefs -> prefs[MANIFEST_KEY] }
.firstOrNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import java.io.File
import javax.inject.Inject

internal class InternalFeatureFlagController @Inject constructor(
Expand Down Expand Up @@ -49,6 +50,15 @@ internal class InternalFeatureFlagController @Inject constructor(
FeatureFlag.entries
.filter { it.launched }
.onEach { reset(it) }

// Clear beta flags restored from backup on fresh install.
// noBackupFilesDir is never included in Auto Backup, so the marker
// file won't exist after a restore — triggering a full reset.
val marker = File(context.noBackupFilesDir, "beta-flags-initialized")
if (!marker.exists()) {
reset()
marker.createNewFile()
}
}

override fun enableBetaFeatures() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.flipcash.services.models.UserFlags
import com.flipcash.services.user.UserManager
import com.getcode.opencode.model.financial.Fiat
import dagger.hilt.android.qualifiers.ApplicationContext
import java.io.File
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.flow.SharingStarted
Expand Down Expand Up @@ -58,6 +59,16 @@ class UserFlagsCoordinator @Inject constructor(

private val scope = CoroutineScope(SupervisorJob() + dispatchers.IO)

init {
// Delete the backing file before DataStore reads it to avoid a race
// where stale overrides restored from backup are briefly visible.
val marker = File(context.noBackupFilesDir, "user-flag-overrides-initialized")
if (!marker.exists()) {
context.preferencesDataStoreFile("user-flag-overrides").delete()
marker.createNewFile()
}
}

private val dataStore = PreferenceDataStoreFactory.create(
corruptionHandler = ReplaceFileCorruptionHandler { emptyPreferences() },
scope = scope,
Expand Down
Loading