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

Commit 4bc215c4 authored by Jernej Virag's avatar Jernej Virag
Browse files

Restore trimMemory behaviour from T

When we moved trimming code to ResourceTrimmer in I84637049a106a94bf9f06c5261c2941b55db4ba0, we also moved trimMemory(ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) which happens after unlock from StatusBarKeyguardViewManager to the ResourceTrimmer behind a TRIM_FONT_CACHES_AT_UNLOCK flag.

Now that we've disabled TRIM_FONT_CACHES_AT_UNLOCK, this also disabled the trimMemory call we were doing since way before Android U.

To full restore pre-U trim font behaviour, this call should not be flag guarded behind the font caching flag.

Bug: 275486055
Bug: 290898642
Test: Updated unit tests
Change-Id: I677855fff144a53d212b65575111491c78803817
parent 6366a8dc
Loading
Loading
Loading
Loading
+24 −30
Original line number Original line Diff line number Diff line
@@ -61,13 +61,7 @@ constructor(


    override fun start() {
    override fun start() {
        Log.d(LOG_TAG, "Resource trimmer registered.")
        Log.d(LOG_TAG, "Resource trimmer registered.")
        if (
        if (featureFlags.isEnabled(Flags.TRIM_RESOURCES_WITH_BACKGROUND_TRIM_AT_LOCK)) {
            !(featureFlags.isEnabled(Flags.TRIM_RESOURCES_WITH_BACKGROUND_TRIM_AT_LOCK) ||
                featureFlags.isEnabled(Flags.TRIM_FONT_CACHES_AT_UNLOCK))
        ) {
            return
        }

            applicationScope.launch(bgDispatcher) {
            applicationScope.launch(bgDispatcher) {
                // We need to wait for the AoD transition (and animation) to complete.
                // We need to wait for the AoD transition (and animation) to complete.
                // This means we're waiting for isDreaming (== implies isDoze) and dozeAmount == 1f
                // This means we're waiting for isDreaming (== implies isDoze) and dozeAmount == 1f
@@ -84,6 +78,7 @@ constructor(
                    .distinctUntilChanged()
                    .distinctUntilChanged()
                    .collect { onWakefulnessUpdated(it.first, it.second, it.third) }
                    .collect { onWakefulnessUpdated(it.first, it.second, it.third) }
            }
            }
        }


        applicationScope.launch(bgDispatcher) {
        applicationScope.launch(bgDispatcher) {
            // We drop 1 to avoid triggering on initial collect().
            // We drop 1 to avoid triggering on initial collect().
@@ -97,18 +92,17 @@ constructor(


    @WorkerThread
    @WorkerThread
    private fun onKeyguardGone() {
    private fun onKeyguardGone() {
        if (!featureFlags.isEnabled(Flags.TRIM_FONT_CACHES_AT_UNLOCK)) {
            return
        }

        if (DEBUG) {
            Log.d(LOG_TAG, "Trimming font caches since keyguard went away.")
        }
        // We want to clear temporary caches we've created while rendering and animating
        // We want to clear temporary caches we've created while rendering and animating
        // lockscreen elements, especially clocks.
        // lockscreen elements, especially clocks.
        Log.d(LOG_TAG, "Sending TRIM_MEMORY_UI_HIDDEN.")
        globalWindowManager.trimMemory(ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN)
        globalWindowManager.trimMemory(ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN)
        if (featureFlags.isEnabled(Flags.TRIM_FONT_CACHES_AT_UNLOCK)) {
            if (DEBUG) {
                Log.d(LOG_TAG, "Trimming font caches since keyguard went away.")
            }
            globalWindowManager.trimCaches(HardwareRenderer.CACHE_TRIM_FONT)
            globalWindowManager.trimCaches(HardwareRenderer.CACHE_TRIM_FONT)
        }
        }
    }


    @WorkerThread
    @WorkerThread
    private fun onWakefulnessUpdated(
    private fun onWakefulnessUpdated(
+5 −1
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@ import com.android.systemui.keyguard.shared.model.TransitionStep
import com.android.systemui.keyguard.shared.model.WakeSleepReason
import com.android.systemui.keyguard.shared.model.WakeSleepReason
import com.android.systemui.keyguard.shared.model.WakefulnessModel
import com.android.systemui.keyguard.shared.model.WakefulnessModel
import com.android.systemui.keyguard.shared.model.WakefulnessState
import com.android.systemui.keyguard.shared.model.WakefulnessState
import com.android.systemui.util.mockito.any
import com.android.systemui.utils.GlobalWindowManager
import com.android.systemui.utils.GlobalWindowManager
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.TestScope
@@ -225,6 +226,9 @@ class ResourceTrimmerTest : SysuiTestCase() {
            keyguardTransitionRepository.sendTransitionStep(
            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(KeyguardState.LOCKSCREEN, KeyguardState.GONE)
                TransitionStep(KeyguardState.LOCKSCREEN, KeyguardState.GONE)
            )
            )
            verifyNoMoreInteractions(globalWindowManager)
            // Memory hidden should still be called.
            verify(globalWindowManager, times(1))
                .trimMemory(ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN)
            verify(globalWindowManager, times(0)).trimCaches(any())
        }
        }
}
}