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
This commit is contained in:
tonihei 2020-07-01 10:25:27 +01:00 committed by Oliver Woodman
parent 316f8a88cd
commit f8217140d7

View File

@ -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() {