Merge "Restore trimMemory behaviour from T" into udc-qpr-dev

This commit is contained in:
Jernej Virag
2023-07-24 13:18:35 +00:00
committed by Android (Google) Code Review
2 changed files with 29 additions and 31 deletions

View File

@@ -61,28 +61,23 @@ 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) || applicationScope.launch(bgDispatcher) {
featureFlags.isEnabled(Flags.TRIM_FONT_CACHES_AT_UNLOCK)) // We need to wait for the AoD transition (and animation) to complete.
) { // This means we're waiting for isDreaming (== implies isDoze) and dozeAmount == 1f
return // signal. This is to make sure we don't clear font caches during animation which
} // would jank and leave stale data in memory.
val isDozingFully =
applicationScope.launch(bgDispatcher) { keyguardInteractor.dozeAmount.map { it == 1f }.distinctUntilChanged()
// We need to wait for the AoD transition (and animation) to complete. combine(
// This means we're waiting for isDreaming (== implies isDoze) and dozeAmount == 1f keyguardInteractor.wakefulnessModel.map { it.state },
// signal. This is to make sure we don't clear font caches during animation which keyguardInteractor.isDreaming,
// would jank and leave stale data in memory. isDozingFully,
val isDozingFully = ::Triple
keyguardInteractor.dozeAmount.map { it == 1f }.distinctUntilChanged() )
combine( .distinctUntilChanged()
keyguardInteractor.wakefulnessModel.map { it.state }, .collect { onWakefulnessUpdated(it.first, it.second, it.third) }
keyguardInteractor.isDreaming, }
isDozingFully,
::Triple
)
.distinctUntilChanged()
.collect { onWakefulnessUpdated(it.first, it.second, it.third) }
} }
applicationScope.launch(bgDispatcher) { applicationScope.launch(bgDispatcher) {
@@ -97,17 +92,16 @@ 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)
globalWindowManager.trimCaches(HardwareRenderer.CACHE_TRIM_FONT) 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)
}
} }
@WorkerThread @WorkerThread

View File

@@ -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())
} }
} }