Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 89ae7f71 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[Catalyst] Default value is written to datastore unexpectedly" into main

parents a595edaa d3e4bb5c
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -74,8 +74,14 @@ interface BooleanValuePreferenceBinding : PreferenceBinding {
    override fun bind(preference: Preference, metadata: PreferenceMetadata) {
        super.bind(preference, metadata)
        (preference as TwoStatePreference).apply {
            // MUST suppress persistent when initializing the checked state:
            //   1. default value is written to datastore if not set (b/396260949)
            //   2. avoid redundant read to the datastore
            val suppressPersistent = isPersistent
            if (suppressPersistent) isPersistent = false
            // "false" is kind of placeholder, metadata datastore should provide the default value
            isChecked = preferenceDataStore!!.getBoolean(key, false)
            if (suppressPersistent) isPersistent = true
        }
    }
}