Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8766c398 authored by Dan Sandler's avatar Dan Sandler Committed by Daniel Sandler
Browse files

Make color matrix parsing more robust.

Bug: 26880793
Change-Id: I95e1b24ed949c6b341ecee7de5732a286c674824
parent 590f3de1
Loading
Loading
Loading
Loading
+14 −4
Original line number Original line Diff line number Diff line
@@ -110,18 +110,28 @@ class DisplayAdjustmentUtils {
        String matrix = Settings.Secure.getStringForUser(cr,
        String matrix = Settings.Secure.getStringForUser(cr,
                Settings.Secure.ACCESSIBILITY_DISPLAY_COLOR_MATRIX, userId);
                Settings.Secure.ACCESSIBILITY_DISPLAY_COLOR_MATRIX, userId);
        if (matrix != null) {
        if (matrix != null) {
            colorMatrix = multiply(colorMatrix, getMatrix(matrix));
            final float[] userMatrix = get4x4Matrix(matrix);
            if (userMatrix != null) {
                colorMatrix = multiply(colorMatrix, userMatrix);
            }
        }
        }


        setColorTransform(colorMatrix);
        setColorTransform(colorMatrix);
    }
    }


    private static float[] getMatrix(String matrix) {
    private static float[] get4x4Matrix(String matrix) {
        String[] strValues = matrix.split(",");
        String[] strValues = matrix.split(",");
        if (strValues.length != 16) {
            return null;
        }
        float[] values = new float[strValues.length];
        float[] values = new float[strValues.length];
        try {
            for (int i = 0; i < values.length; i++) {
            for (int i = 0; i < values.length; i++) {
                values[i] = Float.parseFloat(strValues[i]);
                values[i] = Float.parseFloat(strValues[i]);
            }
            }
        } catch (java.lang.NumberFormatException ex) {
            return null;
        }
        return values;
        return values;
    }
    }