summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-04-22 01:37:39 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-04-22 01:37:39 +0000
commitfc93b1ed9b5eb8964e0cf4f1527ea46fdce9da3a (patch)
treed1c41e86fd928997fb5848f8c54b4789f9eff549
parentbe1c38a3d848bb1a4f40c8ed1b9ea97b9c79ae88 (diff)
parentdfd75611b414c02f18a8e67a403661871afb3ef1 (diff)
downloadbase-fc93b1ed9b5eb8964e0cf4f1527ea46fdce9da3a.tar.gz
Merge cherrypicks of ['googleplex-android-review.googlesource.com/22338474', 'googleplex-android-review.googlesource.com/22757815', 'googleplex-android-review.googlesource.com/22775991'] into tm-qpr3-release.
Change-Id: Icd14eaa30d62f3e86455adeb13a2cf933a69a150
-rw-r--r--packages/SystemUI/animation/src/com/android/systemui/animation/FontInterpolator.kt16
-rw-r--r--packages/SystemUI/animation/src/com/android/systemui/animation/TextAnimator.kt12
-rw-r--r--packages/SystemUI/res/values/dimens.xml2
-rw-r--r--packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityContainerControllerTest.java20
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/animation/FontInterpolatorTest.kt25
5 files changed, 53 insertions, 22 deletions
diff --git a/packages/SystemUI/animation/src/com/android/systemui/animation/FontInterpolator.kt b/packages/SystemUI/animation/src/com/android/systemui/animation/FontInterpolator.kt
index f0a82113c3a3..83e44b69812b 100644
--- a/packages/SystemUI/animation/src/com/android/systemui/animation/FontInterpolator.kt
+++ b/packages/SystemUI/animation/src/com/android/systemui/animation/FontInterpolator.kt
@@ -18,8 +18,10 @@ package com.android.systemui.animation
import android.graphics.fonts.Font
import android.graphics.fonts.FontVariationAxis
+import android.util.LruCache
import android.util.MathUtils
import android.util.MathUtils.abs
+import androidx.annotation.VisibleForTesting
import java.lang.Float.max
import java.lang.Float.min
@@ -34,6 +36,10 @@ private const val FONT_ITALIC_MIN = 0f
private const val FONT_ITALIC_ANIMATION_STEP = 0.1f
private const val FONT_ITALIC_DEFAULT_VALUE = 0f
+// Benchmarked via Perfetto, difference between 10 and 50 entries is about 0.3ms in
+// frame draw time on a Pixel 6.
+@VisibleForTesting const val FONT_CACHE_MAX_ENTRIES = 10
+
/** Provide interpolation of two fonts by adjusting font variation settings. */
class FontInterpolator {
@@ -81,8 +87,8 @@ class FontInterpolator {
// Font interpolator has two level caches: one for input and one for font with different
// variation settings. No synchronization is needed since FontInterpolator is not designed to be
// thread-safe and can be used only on UI thread.
- private val interpCache = hashMapOf<InterpKey, Font>()
- private val verFontCache = hashMapOf<VarFontKey, Font>()
+ private val interpCache = LruCache<InterpKey, Font>(FONT_CACHE_MAX_ENTRIES)
+ private val verFontCache = LruCache<VarFontKey, Font>(FONT_CACHE_MAX_ENTRIES)
// Mutable keys for recycling.
private val tmpInterpKey = InterpKey(null, null, 0f)
@@ -152,7 +158,7 @@ class FontInterpolator {
tmpVarFontKey.set(start, newAxes)
val axesCachedFont = verFontCache[tmpVarFontKey]
if (axesCachedFont != null) {
- interpCache[InterpKey(start, end, progress)] = axesCachedFont
+ interpCache.put(InterpKey(start, end, progress), axesCachedFont)
return axesCachedFont
}
@@ -160,8 +166,8 @@ class FontInterpolator {
// Font.Builder#build won't throw IOException since creating fonts from existing fonts will
// not do any IO work.
val newFont = Font.Builder(start).setFontVariationSettings(newAxes.toTypedArray()).build()
- interpCache[InterpKey(start, end, progress)] = newFont
- verFontCache[VarFontKey(start, newAxes)] = newFont
+ interpCache.put(InterpKey(start, end, progress), newFont)
+ verFontCache.put(VarFontKey(start, newAxes), newFont)
return newFont
}
diff --git a/packages/SystemUI/animation/src/com/android/systemui/animation/TextAnimator.kt b/packages/SystemUI/animation/src/com/android/systemui/animation/TextAnimator.kt
index 9e9929e79d47..3ee97be360f0 100644
--- a/packages/SystemUI/animation/src/com/android/systemui/animation/TextAnimator.kt
+++ b/packages/SystemUI/animation/src/com/android/systemui/animation/TextAnimator.kt
@@ -24,8 +24,10 @@ import android.graphics.Canvas
import android.graphics.Typeface
import android.graphics.fonts.Font
import android.text.Layout
+import android.util.LruCache
private const val DEFAULT_ANIMATION_DURATION: Long = 300
+private const val TYPEFACE_CACHE_MAX_ENTRIES = 5
typealias GlyphCallback = (TextAnimator.PositionedGlyph, Float) -> Unit
/**
@@ -114,7 +116,7 @@ class TextAnimator(layout: Layout, private val invalidateCallback: () -> Unit) {
private val fontVariationUtils = FontVariationUtils()
- private val typefaceCache = HashMap<String, Typeface?>()
+ private val typefaceCache = LruCache<String, Typeface>(TYPEFACE_CACHE_MAX_ENTRIES)
fun updateLayout(layout: Layout) {
textInterpolator.layout = layout
@@ -218,12 +220,12 @@ class TextAnimator(layout: Layout, private val invalidateCallback: () -> Unit) {
}
if (!fvar.isNullOrBlank()) {
- textInterpolator.targetPaint.typeface =
- typefaceCache.getOrElse(fvar) {
- textInterpolator.targetPaint.fontVariationSettings = fvar
+ textInterpolator.targetPaint.typeface = typefaceCache.get(fvar) ?: run {
+ textInterpolator.targetPaint.fontVariationSettings = fvar
+ textInterpolator.targetPaint.typeface?.also {
typefaceCache.put(fvar, textInterpolator.targetPaint.typeface)
- textInterpolator.targetPaint.typeface
}
+ }
}
if (color != null) {
diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml
index 3faacf2882ad..adc4c555dfac 100644
--- a/packages/SystemUI/res/values/dimens.xml
+++ b/packages/SystemUI/res/values/dimens.xml
@@ -396,7 +396,7 @@
<dimen name="navigation_key_width">70dp</dimen>
<!-- The width/height of the icon of a navigation button -->
- <dimen name="navigation_icon_size">32dp</dimen>
+ <dimen name="navigation_icon_size">24dp</dimen>
<!-- The padding on the side of the navigation bar. Must be greater than or equal to
navigation_extra_key_width -->
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityContainerControllerTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityContainerControllerTest.java
index d49275862757..3b3df239b8ea 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityContainerControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityContainerControllerTest.java
@@ -163,8 +163,6 @@ public class KeyguardSecurityContainerControllerTest extends SysuiTestCase {
@Captor
private ArgumentCaptor<KeyguardSecurityContainer.SwipeListener> mSwipeListenerArgumentCaptor;
- private Configuration mConfiguration;
-
private KeyguardSecurityContainerController mKeyguardSecurityContainerController;
private KeyguardPasswordViewController mKeyguardPasswordViewController;
private KeyguardPasswordView mKeyguardPasswordView;
@@ -172,12 +170,12 @@ public class KeyguardSecurityContainerControllerTest extends SysuiTestCase {
@Before
public void setup() {
- mConfiguration = new Configuration();
- mConfiguration.setToDefaults(); // Defaults to ORIENTATION_UNDEFINED.
mTestableResources = mContext.getOrCreateTestableResources();
+ mTestableResources.getResources().getConfiguration().orientation =
+ Configuration.ORIENTATION_UNDEFINED;
when(mView.getContext()).thenReturn(mContext);
- when(mView.getResources()).thenReturn(mContext.getResources());
+ when(mView.getResources()).thenReturn(mTestableResources.getResources());
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(/* width= */ 0, /* height= */
0);
lp.gravity = 0;
@@ -254,6 +252,8 @@ public class KeyguardSecurityContainerControllerTest extends SysuiTestCase {
@Test
public void onResourcesUpdate_callsThroughOnRotationChange() {
+ clearInvocations(mView);
+
// Rotation is the same, shouldn't cause an update
mKeyguardSecurityContainerController.updateResources();
verify(mView, never()).initMode(eq(MODE_DEFAULT), eq(mGlobalSettings), eq(mFalsingManager),
@@ -579,12 +579,12 @@ public class KeyguardSecurityContainerControllerTest extends SysuiTestCase {
// Set initial gravity
mTestableResources.addOverride(R.integer.keyguard_host_view_gravity,
Gravity.CENTER);
+ mTestableResources.addOverride(
+ R.bool.can_use_one_handed_bouncer, false);
// Kick off the initial pass...
mKeyguardSecurityContainerController.onInit();
- verify(mView).setLayoutParams(argThat(
- (ArgumentMatcher<FrameLayout.LayoutParams>) argument ->
- argument.gravity == Gravity.CENTER));
+ verify(mView).setLayoutParams(any());
clearInvocations(mView);
// Now simulate a config change
@@ -592,9 +592,7 @@ public class KeyguardSecurityContainerControllerTest extends SysuiTestCase {
Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
mKeyguardSecurityContainerController.updateResources();
- verify(mView).setLayoutParams(argThat(
- (ArgumentMatcher<FrameLayout.LayoutParams>) argument ->
- argument.gravity == (Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM)));
+ verify(mView).setLayoutParams(any());
}
@Test
diff --git a/packages/SystemUI/tests/src/com/android/systemui/animation/FontInterpolatorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/animation/FontInterpolatorTest.kt
index 8a5c5b58d058..57a355f4e127 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/animation/FontInterpolatorTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/animation/FontInterpolatorTest.kt
@@ -106,4 +106,29 @@ class FontInterpolatorTest : SysuiTestCase() {
val reversedFont = interp.lerp(endFont, startFont, 0.5f)
assertThat(resultFont).isSameInstanceAs(reversedFont)
}
+
+ @Test
+ fun testCacheMaxSize() {
+ val interp = FontInterpolator()
+
+ val startFont = Font.Builder(sFont)
+ .setFontVariationSettings("'wght' 100")
+ .build()
+ val endFont = Font.Builder(sFont)
+ .setFontVariationSettings("'wght' 1")
+ .build()
+ val resultFont = interp.lerp(startFont, endFont, 0.5f)
+ for (i in 0..FONT_CACHE_MAX_ENTRIES + 1) {
+ val f1 = Font.Builder(sFont)
+ .setFontVariationSettings("'wght' ${i * 100}")
+ .build()
+ val f2 = Font.Builder(sFont)
+ .setFontVariationSettings("'wght' $i")
+ .build()
+ interp.lerp(f1, f2, 0.5f)
+ }
+
+ val cachedFont = interp.lerp(startFont, endFont, 0.5f)
+ assertThat(resultFont).isNotSameInstanceAs(cachedFont)
+ }
}