Bug 1656078 - Handle negative FONT_SCALE values. r=owlish

Differential Revision: https://phabricator.services.mozilla.com/D85337
This commit is contained in:
Agi Sferro 2020-07-30 16:48:32 +00:00
Родитель b7916828ff
Коммит 3b4ead5ae4
2 изменённых файлов: 22 добавлений и 4 удалений

Просмотреть файл

@ -156,6 +156,10 @@ import android.util.Log;
if (!stopping) { // Either we were enabled, or else the system font scale changed. 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); 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. } else { // We were turned off.
fontScale = mPrevGeckoFontScale; fontScale = mPrevGeckoFontScale;
} }

Просмотреть файл

@ -23,6 +23,7 @@ import android.support.annotation.IntDef;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import org.mozilla.gecko.EventDispatcher; import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.GeckoSystemStateListener; import org.mozilla.gecko.GeckoSystemStateListener;
@ -30,6 +31,8 @@ import org.mozilla.gecko.util.GeckoBundle;
@AnyThread @AnyThread
public final class GeckoRuntimeSettings extends RuntimeSettings { public final class GeckoRuntimeSettings extends RuntimeSettings {
private static final String LOGTAG = "GeckoRuntimeSettings";
/** /**
* Settings builder used to construct the settings object. * Settings builder used to construct the settings object.
*/ */
@ -917,13 +920,24 @@ public final class GeckoRuntimeSettings extends RuntimeSettings {
return setFontSizeFactorInternal(fontSizeFactor); return setFontSizeFactorInternal(fontSizeFactor);
} }
/* package */ @NonNull GeckoRuntimeSettings setFontSizeFactorInternal( private final static float DEFAULT_FONT_SIZE_FACTOR = 1f;
final float fontSizeFactor) {
private float sanitizeFontSizeFactor(final float fontSizeFactor) {
if (fontSizeFactor < 0) { 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); mFontSizeFactor.commit(fontSizePercentage);
if (getFontInflationEnabled()) { if (getFontInflationEnabled()) {
final int scaledFontInflation = Math.round(FONT_INFLATION_BASE_VALUE * fontSizeFactor); final int scaledFontInflation = Math.round(FONT_INFLATION_BASE_VALUE * fontSizeFactor);