From 3b4ead5ae457c99087eec83176746c9def18a932 Mon Sep 17 00:00:00 2001 From: Agi Sferro Date: Thu, 30 Jul 2020 16:48:32 +0000 Subject: [PATCH] Bug 1656078 - Handle negative FONT_SCALE values. r=owlish Differential Revision: https://phabricator.services.mozilla.com/D85337 --- .../geckoview/GeckoFontScaleListener.java | 4 ++++ .../geckoview/GeckoRuntimeSettings.java | 22 +++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoFontScaleListener.java b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoFontScaleListener.java index 4c26bf7dd6f1..5704ec6d3225 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoFontScaleListener.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoFontScaleListener.java @@ -156,6 +156,10 @@ import android.util.Log; if (!stopping) { // Either we were enabled, or else the system font scale changed. fontScale = Settings.System.getFloat(contentResolver, Settings.System.FONT_SCALE, DEFAULT_FONT_SCALE); + // Older Android versions don't sanitize the FONT_SCALE value. See Bug 1656078. + if (fontScale < 0) { + fontScale = DEFAULT_FONT_SCALE; + } } else { // We were turned off. fontScale = mPrevGeckoFontScale; } diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntimeSettings.java b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntimeSettings.java index 9d05b0b10e68..59ee4e9ca66e 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntimeSettings.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntimeSettings.java @@ -23,6 +23,7 @@ import android.support.annotation.IntDef; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.text.TextUtils; +import android.util.Log; import org.mozilla.gecko.EventDispatcher; import org.mozilla.gecko.GeckoSystemStateListener; @@ -30,6 +31,8 @@ import org.mozilla.gecko.util.GeckoBundle; @AnyThread public final class GeckoRuntimeSettings extends RuntimeSettings { + private static final String LOGTAG = "GeckoRuntimeSettings"; + /** * Settings builder used to construct the settings object. */ @@ -917,13 +920,24 @@ public final class GeckoRuntimeSettings extends RuntimeSettings { return setFontSizeFactorInternal(fontSizeFactor); } - /* package */ @NonNull GeckoRuntimeSettings setFontSizeFactorInternal( - final float fontSizeFactor) { + private final static float DEFAULT_FONT_SIZE_FACTOR = 1f; + + private float sanitizeFontSizeFactor(final float fontSizeFactor) { if (fontSizeFactor < 0) { - throw new IllegalArgumentException("fontSizeFactor cannot be < 0"); + if (BuildConfig.DEBUG) { + throw new IllegalArgumentException("fontSizeFactor cannot be < 0"); + } else { + Log.e(LOGTAG, "fontSizeFactor cannot be < 0"); + return DEFAULT_FONT_SIZE_FACTOR; + } } - final int fontSizePercentage = Math.round(fontSizeFactor * 100); + return fontSizeFactor; + } + + /* package */ @NonNull GeckoRuntimeSettings setFontSizeFactorInternal( + final float fontSizeFactor) { + final int fontSizePercentage = Math.round(sanitizeFontSizeFactor(fontSizeFactor) * 100); mFontSizeFactor.commit(fontSizePercentage); if (getFontInflationEnabled()) { final int scaledFontInflation = Math.round(FONT_INFLATION_BASE_VALUE * fontSizeFactor);