From db640a9648d7833eb0f9745b091c91e7f3768803 Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Wed, 10 Aug 2016 02:06:40 -0700 Subject: [PATCH] livedisplay: Float-to-string conversions considered harmful * Force US locale when doing internal flattening of HSIC objects into strings. This would crash in the validator if the user's local uses commands instead of dots to format floats. Change-Id: I08f44238a486308a483205b97632114d2f7a77f1 --- sdk/src/java/cyanogenmod/hardware/HSIC.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/sdk/src/java/cyanogenmod/hardware/HSIC.java b/sdk/src/java/cyanogenmod/hardware/HSIC.java index cd4f3ce..df6cb5f 100644 --- a/sdk/src/java/cyanogenmod/hardware/HSIC.java +++ b/sdk/src/java/cyanogenmod/hardware/HSIC.java @@ -18,9 +18,10 @@ package cyanogenmod.hardware; import android.graphics.Color; import android.os.Parcel; import android.os.Parcelable; - import android.text.TextUtils; +import java.util.Locale; + public class HSIC implements Parcelable { private final float mHue; @@ -59,7 +60,7 @@ public class HSIC implements Parcelable { } public String flatten() { - return String.format("%f|%f|%f|%f|%f", mHue, mSaturation, + return String.format(Locale.US, "%f|%f|%f|%f|%f", mHue, mSaturation, mIntensity, mContrast, mSaturationThreshold); } @@ -68,9 +69,9 @@ public class HSIC implements Parcelable { if (unflat.length != 4 && unflat.length != 5) { throw new NumberFormatException("Failed to unflatten HSIC values: " + flat); } - return new HSIC(Float.valueOf(unflat[0]), Float.valueOf(unflat[1]), - Float.valueOf(unflat[2]), Float.valueOf(unflat[3]), - unflat.length == 5 ? Float.valueOf(unflat[4]) : 0.0f); + return new HSIC(Float.parseFloat(unflat[0]), Float.parseFloat(unflat[1]), + Float.parseFloat(unflat[2]), Float.parseFloat(unflat[3]), + unflat.length == 5 ? Float.parseFloat(unflat[4]) : 0.0f); } public int[] toRGB() { @@ -93,7 +94,7 @@ public class HSIC implements Parcelable { @Override public String toString() { - return String.format("HSIC={ hue=%f saturation=%f intensity=%f " + + return String.format(Locale.US, "HSIC={ hue=%f saturation=%f intensity=%f " + "contrast=%f saturationThreshold=%f }", mHue, mSaturation, mIntensity, mContrast, mSaturationThreshold); }