Commit f8217140 by tonihei Committed by Oliver Woodman

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
parent 316f8a88
......@@ -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() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment