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

Commit fba9fb80 authored by Ioana Alexandru's avatar Ioana Alexandru
Browse files

Perform NLVM combines on the bg thread

It seems like although the flows themselves don't emit too often (thanks
to distinctUntilChanged), the combines still do quite a bit of work that
should ideally happen in the background. The biggest offender here is
the footer visibility, as it combines a lot of flows that can emit
relatively often.

Also reducing the amount of emissions in the shadeExpansion sub-flows
using distinctUntilChanged. Removed qsExpansion as it's redundant since
we're already checking qsFullScreen, which is only true when qsExpansion
is 1.

Bug: 326018643
Bug: 324483341
Test: v2/android-crystalball-eng/health/microbench/systemui/main/systemui-notification-4-jank-suite
Test: v2/android-crystalball-eng/health/microbench/systemui/systemui-notification-onmeasure-jank-suite
Flag: NONE

Change-Id: Ifc470bd1bbf9142c1114d7bdfb92449be5f754ce
parent 642bdb48
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.statusbar.notification.stack.ui.viewmodel

import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.shade.domain.interactor.ShadeInteractor
import com.android.systemui.statusbar.domain.interactor.RemoteInputInteractor
import com.android.systemui.statusbar.notification.domain.interactor.ActiveNotificationsInteractor
@@ -33,10 +34,12 @@ import com.android.systemui.util.ui.AnimatedValue
import com.android.systemui.util.ui.toAnimatedValueFlow
import java.util.Optional
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
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

@@ -55,6 +58,7 @@ constructor(
    shadeInteractor: ShadeInteractor,
    userSetupInteractor: UserSetupInteractor,
    zenModeInteractor: ZenModeInteractor,
    @Background bgDispatcher: CoroutineDispatcher,
) {
    /**
     * We want the NSSL to be unimportant for accessibility when there are no notifications in it
@@ -72,6 +76,7 @@ constructor(
                ) { hasNotifications, isShowingOnLockscreen ->
                    hasNotifications || !isShowingOnLockscreen
                }
                .flowOn(bgDispatcher)
                .distinctUntilChanged()
        }
    }
@@ -95,6 +100,7 @@ constructor(
                        else -> true
                    }
                }
                .flowOn(bgDispatcher)
                .distinctUntilChanged()
        }
    }
@@ -107,15 +113,13 @@ constructor(
                    activeNotificationsInteractor.areAnyNotificationsPresent,
                    userSetupInteractor.isUserSetUp,
                    notificationStackInteractor.isShowingOnLockscreen,
                    shadeInteractor.qsExpansion,
                    shadeInteractor.isQsFullscreen,
                    remoteInputInteractor.isRemoteInputActive,
                    shadeInteractor.shadeExpansion.map { it == 0f }
                    shadeInteractor.shadeExpansion.map { it == 0f }.distinctUntilChanged(),
                ) {
                    hasNotifications,
                    isUserSetUp,
                    isShowingOnLockscreen,
                    qsExpansion,
                    qsFullScreen,
                    isRemoteInputActive,
                    isShadeClosed ->
@@ -131,7 +135,7 @@ constructor(
                        isShowingOnLockscreen -> VisibilityChange.HIDE_WITHOUT_ANIMATION
                        // Do not show the footer if quick settings are fully expanded (except
                        // for the foldable split shade view). See b/201427195 && b/222699879.
                        qsExpansion == 1f && qsFullScreen -> VisibilityChange.HIDE_WITH_ANIMATION
                        qsFullScreen -> VisibilityChange.HIDE_WITH_ANIMATION
                        // Hide the footer if remote input is active (i.e. user is replying to a
                        // notification). See b/75984847.
                        isRemoteInputActive -> VisibilityChange.HIDE_WITH_ANIMATION
@@ -140,6 +144,7 @@ constructor(
                        else -> VisibilityChange.SHOW_WITH_ANIMATION
                    }
                }
                .flowOn(bgDispatcher)
                .distinctUntilChanged(
                    // Equivalent unless visibility changes
                    areEquivalent = { a: VisibilityChange, b: VisibilityChange ->
+2 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.statusbar.notification.stack.ui.viewmodel

import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.Kosmos.Fixture
import com.android.systemui.kosmos.testDispatcher
import com.android.systemui.shade.domain.interactor.shadeInteractor
import com.android.systemui.statusbar.domain.interactor.remoteInputInteractor
import com.android.systemui.statusbar.notification.domain.interactor.activeNotificationsInteractor
@@ -42,5 +43,6 @@ val Kosmos.notificationListViewModel by Fixture {
        shadeInteractor,
        userSetupInteractor,
        zenModeInteractor,
        testDispatcher,
    )
}