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

Commit f3241622 authored by cketti's avatar cketti
Browse files

Avoid race condition when selecting a notification sound

parent aa90f436
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -101,8 +101,17 @@ class AccountSettingsFragment : PreferenceFragmentCompat(), ConfirmationDialogFr
        val account = getAccount()
        initializeCryptoSettings(account)

        // Don't update the notification preferences when resuming after the user has selected a new notification sound
        // via NotificationSoundPreference. Otherwise we race the background thread and might read data from the old
        // NotificationChannel, overwriting the notification sound with the previous value.
        notificationSoundPreference?.let { notificationSoundPreference ->
            if (notificationSoundPreference.receivedActivityResultJustNow) {
                notificationSoundPreference.receivedActivityResultJustNow = false
            } else {
                maybeUpdateNotificationPreferences(account)
            }
        }
    }

    override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
        super.onCreateOptionsMenu(menu, inflater)
+2 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ constructor(
    ),
    defStyleRes: Int = 0
) : Preference(context, attrs, defStyleAttr, defStyleRes), PreferenceActivityResultListener {
    var receivedActivityResultJustNow = false

    fun setNotificationSound(sound: Uri?) {
        persistRingtone(sound)
@@ -42,6 +43,7 @@ constructor(
        val uri = data?.getParcelableExtra<Uri>(RingtoneManager.EXTRA_RINGTONE_PICKED_URI)

        if (callChangeListener(uri?.toString().orEmpty())) {
            receivedActivityResultJustNow = true
            persistRingtone(uri)
        }
    }