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

Commit 35d361e8 authored by Yining Liu's avatar Yining Liu
Browse files

Check minimalism flag before monitoring settings value

Move the notification minimalism flag checking logic before observing
the settings value.

Test: manual
Bug: 330387368
Flag: com.android.server.notification.notification_minimalism
Change-Id: I313f1f1bd405d2dd42404626bc6b5202eed4e424
parent 99f0ef67
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -51,7 +51,6 @@ import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map

/**
@@ -132,9 +131,6 @@ constructor(
    }

    private fun minimalismFeatureSettingEnabled(): Flow<Boolean> {
        if (!NotificationMinimalism.isEnabled) {
            return flowOf(false)
        }
        return seenNotificationsInteractor.isLockScreenNotificationMinimalismEnabled()
    }

+28 −20
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onStart
@@ -131,9 +132,15 @@ constructor(
            .conflate()

    fun isLockScreenNotificationMinimalismEnabled(): Flow<Boolean> =
        if (!NotificationMinimalism.isEnabled) {
            flowOf(false)
        } else {
            secureSettings
                // emit whenever the setting has changed
            .observerFlow(UserHandle.USER_ALL, Settings.Secure.LOCK_SCREEN_NOTIFICATION_MINIMALISM)
                .observerFlow(
                    UserHandle.USER_ALL,
                    Settings.Secure.LOCK_SCREEN_NOTIFICATION_MINIMALISM,
                )
                // perform a query immediately
                .onStart { emit(Unit) }
                // for each change, lookup the new value
@@ -148,7 +155,8 @@ constructor(
                .distinctUntilChanged()
                // perform lookups on the bg thread pool
                .flowOn(bgDispatcher)
            // only track the most recent emission, if events are happening faster than they can be
            // consumed
                // only track the most recent emission, if events are happening faster than they can
                // be consumed
                .conflate()
        }
}