From f8217140d7fc081f062bb8ef6613a11c32c867cb Mon Sep 17 00:00:00 2001 From: tonihei Date: Wed, 1 Jul 2020 10:25:27 +0100 Subject: [PATCH] Add missing null check. The system services may return a null value if the service is not available. Guard against this by falling back to default values. PiperOrigin-RevId: 319187882 --- .../google/android/exoplayer2/ui/SubtitleView.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/SubtitleView.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/SubtitleView.java index e066fa0f8a..72a3a8384e 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/SubtitleView.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/SubtitleView.java @@ -327,23 +327,28 @@ public final class SubtitleView extends FrameLayout implements TextOutput { @RequiresApi(19) private boolean isCaptionManagerEnabled() { + @Nullable CaptioningManager captioningManager = (CaptioningManager) getContext().getSystemService(Context.CAPTIONING_SERVICE); - return captioningManager.isEnabled(); + return captioningManager != null && captioningManager.isEnabled(); } @RequiresApi(19) private float getUserCaptionFontScaleV19() { + @Nullable CaptioningManager captioningManager = (CaptioningManager) getContext().getSystemService(Context.CAPTIONING_SERVICE); - return captioningManager.getFontScale(); + return captioningManager == null ? 1f : captioningManager.getFontScale(); } @RequiresApi(19) private CaptionStyleCompat getUserCaptionStyleV19() { + @Nullable CaptioningManager captioningManager = (CaptioningManager) getContext().getSystemService(Context.CAPTIONING_SERVICE); - return CaptionStyleCompat.createFromCaptionStyle(captioningManager.getUserStyle()); + return captioningManager == null + ? CaptionStyleCompat.DEFAULT + : CaptionStyleCompat.createFromCaptionStyle(captioningManager.getUserStyle()); } private void updateOutput() {