diff options
author | Yanting Yang <yantingyang@google.com> | 2020-11-18 02:53:37 +0800 |
---|---|---|
committer | Yanting Yang <yantingyang@google.com> | 2020-11-18 16:17:54 +0800 |
commit | 18eb9f9f848bd731d2c7ce8a7948ff9fd344869c (patch) | |
tree | 45d5d99f83b9317e722bdfa0ca7b6478a0050470 /shadows | |
parent | e04021d923ccc6ba7600e5c2b12f563e0e488775 (diff) | |
download | robolectric-shadows-18eb9f9f848bd731d2c7ce8a7948ff9fd344869c.tar.gz |
Fix Settings robolectric broken tests
Symptom:
NPE at android.text.style.StyleSpan.apply() because it tries to get
style from a null Typeface object.
Root cause:
It failed to get the Typeface object from Typeface.defaultFromStyle()
in StyleSpan after ag/13051258 since the method is guarded by the
SYSTEM_FONT_MAP_LOCK for thread safe.
Solution:
Shadow the Typeface.defaultFromStyle() and return a Typeface object to
address NPE.
Fixes: 173342054
Test: make RunSettingsRoboTests
Change-Id: Ia2a0c620850d37353521cbc0603a673f65ac0264
Diffstat (limited to 'shadows')
-rw-r--r-- | shadows/framework/src/main/java/org/robolectric/shadows/ShadowTypeface.java | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowTypeface.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowTypeface.java index 343f030e9..e344b5b40 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowTypeface.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowTypeface.java @@ -5,6 +5,7 @@ import static android.os.Build.VERSION_CODES.N_MR1; import static android.os.Build.VERSION_CODES.O; import static android.os.Build.VERSION_CODES.O_MR1; import static android.os.Build.VERSION_CODES.P; +import static android.os.Build.VERSION_CODES.S; import static org.robolectric.RuntimeEnvironment.getApiLevel; import android.annotation.SuppressLint; @@ -131,6 +132,13 @@ public class ShadowTypeface { } // BEGIN-INTERNAL + @Implementation(minSdk = S) + public static Typeface defaultFromStyle(int style) { + return createUnderlyingTypeface(/* familyName= */ null, style); + } + // END-INTERNAL + + // BEGIN-INTERNAL @HiddenApi @Implementation(minSdk = android.os.Build.VERSION_CODES.Q) public static void initSystemDefaultTypefaces(Object systemFontMap, |