diff options
author | Jernej Virag <jernej@google.com> | 2023-07-13 16:59:29 +0200 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-09-15 21:18:31 +0000 |
commit | 1bb0a89babb30de149570ec97972d62f106ab5e0 (patch) | |
tree | 1c869f32ec9eef1944eee6c54c6efd53a926756e | |
parent | d45fe1600110fd3653196483fed77b828daa3cf0 (diff) | |
download | base-1bb0a89babb30de149570ec97972d62f106ab5e0.tar.gz |
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
Bug: 293929945
Test: Updated unit tests
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:4bc215c4101b9504c244356ad0264ea1f4912bbd)
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:16a1cf9e654bcaf3618213df7b9e82db3bdb5d40)
Merged-In: I677855fff144a53d212b65575111491c78803817
Change-Id: I677855fff144a53d212b65575111491c78803817
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/keyguard/ResourceTrimmer.kt | 54 | ||||
-rw-r--r-- | packages/SystemUI/tests/src/com/android/systemui/keyguard/ResourceTrimmerTest.kt | 6 |
2 files changed, 29 insertions, 31 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ResourceTrimmer.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ResourceTrimmer.kt index 1978b3d048b7..039460d8fdae 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ResourceTrimmer.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ResourceTrimmer.kt @@ -61,28 +61,23 @@ constructor( override fun start() { Log.d(LOG_TAG, "Resource trimmer registered.") - if ( - !(featureFlags.isEnabled(Flags.TRIM_RESOURCES_WITH_BACKGROUND_TRIM_AT_LOCK) || - featureFlags.isEnabled(Flags.TRIM_FONT_CACHES_AT_UNLOCK)) - ) { - return - } - - applicationScope.launch(bgDispatcher) { - // We need to wait for the AoD transition (and animation) to complete. - // This means we're waiting for isDreaming (== implies isDoze) and dozeAmount == 1f - // 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 = - keyguardInteractor.dozeAmount.map { it == 1f }.distinctUntilChanged() - combine( - keyguardInteractor.wakefulnessModel.map { it.state }, - keyguardInteractor.isDreaming, - isDozingFully, - ::Triple - ) - .distinctUntilChanged() - .collect { onWakefulnessUpdated(it.first, it.second, it.third) } + if (featureFlags.isEnabled(Flags.TRIM_RESOURCES_WITH_BACKGROUND_TRIM_AT_LOCK)) { + applicationScope.launch(bgDispatcher) { + // We need to wait for the AoD transition (and animation) to complete. + // This means we're waiting for isDreaming (== implies isDoze) and dozeAmount == 1f + // 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 = + keyguardInteractor.dozeAmount.map { it == 1f }.distinctUntilChanged() + combine( + keyguardInteractor.wakefulnessModel.map { it.state }, + keyguardInteractor.isDreaming, + isDozingFully, + ::Triple + ) + .distinctUntilChanged() + .collect { onWakefulnessUpdated(it.first, it.second, it.third) } + } } applicationScope.launch(bgDispatcher) { @@ -97,17 +92,16 @@ constructor( @WorkerThread 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 // lockscreen elements, especially clocks. + Log.d(LOG_TAG, "Sending 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 diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/ResourceTrimmerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/ResourceTrimmerTest.kt index 644736899b6c..c175ec3a96ff 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/ResourceTrimmerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/ResourceTrimmerTest.kt @@ -18,6 +18,7 @@ import com.android.systemui.keyguard.shared.model.TransitionStep import com.android.systemui.keyguard.shared.model.WakeSleepReason import com.android.systemui.keyguard.shared.model.WakefulnessModel import com.android.systemui.keyguard.shared.model.WakefulnessState +import com.android.systemui.util.mockito.any import com.android.systemui.utils.GlobalWindowManager import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.TestScope @@ -227,6 +228,9 @@ class ResourceTrimmerTest : SysuiTestCase() { keyguardTransitionRepository.sendTransitionStep( 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()) } } |