Skip to content

Commit f80536b

Browse files
committed
fix: prevent beta flags from restoring on fresh install
Exclude the beta-flags DataStore from Android Auto Backup and reset non-persistent beta flags when a fresh install or backup restore is detected using a noBackupFilesDir marker file. Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 81cbd0c commit f80536b

4 files changed

Lines changed: 31 additions & 0 deletions

File tree

apps/flipcash/app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
<application
4444
android:name="com.flipcash.app.FlipcashApp"
4545
android:allowBackup="true"
46+
android:fullBackupContent="@xml/backup_rules"
47+
android:dataExtractionRules="@xml/data_extraction_rules"
4648
android:icon="@mipmap/ic_launcher"
4749
android:label="@string/app_name"
4850
android:largeHeap="true"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<full-backup-content>
3+
<exclude
4+
domain="file"
5+
path="datastore/beta-flags.preferences_pb" />
6+
</full-backup-content>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<data-extraction-rules>
3+
<cloud-backup>
4+
<exclude
5+
domain="file"
6+
path="datastore/beta-flags.preferences_pb" />
7+
</cloud-backup>
8+
<device-transfer>
9+
<exclude
10+
domain="file"
11+
path="datastore/beta-flags.preferences_pb" />
12+
</device-transfer>
13+
</data-extraction-rules>

apps/flipcash/shared/featureflags/src/main/kotlin/com/flipcash/app/featureflags/internal/InternalFeatureFlagController.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import kotlinx.coroutines.flow.map
2121
import kotlinx.coroutines.flow.onEach
2222
import kotlinx.coroutines.flow.stateIn
2323
import kotlinx.coroutines.launch
24+
import java.io.File
2425
import javax.inject.Inject
2526

2627
internal class InternalFeatureFlagController @Inject constructor(
@@ -49,6 +50,15 @@ internal class InternalFeatureFlagController @Inject constructor(
4950
FeatureFlag.entries
5051
.filter { it.launched }
5152
.onEach { reset(it) }
53+
54+
// Clear beta flags restored from backup on fresh install.
55+
// noBackupFilesDir is never included in Auto Backup, so the marker
56+
// file won't exist after a restore — triggering a full reset.
57+
val marker = File(context.noBackupFilesDir, "beta-flags-initialized")
58+
if (!marker.exists()) {
59+
reset()
60+
marker.createNewFile()
61+
}
5262
}
5363

5464
override fun enableBetaFeatures() {

0 commit comments

Comments
 (0)