chenxiaolong / BCR

A Basic Call Recorder for rooted Android devices
GNU General Public License v3.0
1.49k stars 98 forks source link

RecordRulesViewModel: Fix race condition when mutating rules #555

Closed chenxiaolong closed 3 weeks ago

chenxiaolong commented 3 weeks ago

BCR can potentially be unloaded from memory when the user is in Android's contact picker activity. If this happens, when they return, the coroutines in refreshRules() and addContactRule() may execute at the same time. This does not cause crashes due to MutableStateFlow's compare and set behavior, but does cause weird behavior, like the new contact rule being added to an empty list of rules.

Fixes: #554