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

Commit 1a9c57c3 authored by Henrik Baard's avatar Henrik Baard Committed by Luca Stefani
Browse files

Prevent NFE in SystemUI when parsing invalid int (2)

A user can change various tunable settings setting via adb.

If the value set is not an integer, SystemUI will end up in an exception
loop.

Test: No crash when running:
      adb exec-out settings put secure sysui_qs_move_whole_rows a
      adb exec-out settings put secure qs_show_brightness a
      adb exec-out settings put secure clock_seconds a
      adb exec-out settings put secure sysui_volume_down_silent a
      adb exec-out settings put secure sysui_volume_up_silent a
      adb exec-out settings put secure sysui_do_not_disturb a
Change-Id: If9c565cbdd44db25ba7fce381c98aa0ab735bfc4
parent 93cae807
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -127,12 +127,12 @@ public class QSAnimator implements Callback, PageListener, Listener, OnLayoutCha
    @Override
    @Override
    public void onTuningChanged(String key, String newValue) {
    public void onTuningChanged(String key, String newValue) {
        if (ALLOW_FANCY_ANIMATION.equals(key)) {
        if (ALLOW_FANCY_ANIMATION.equals(key)) {
            mAllowFancy = newValue == null || Integer.parseInt(newValue) != 0;
            mAllowFancy = TunerService.parseIntegerSwitch(newValue, true);
            if (!mAllowFancy) {
            if (!mAllowFancy) {
                clearAnimationState();
                clearAnimationState();
            }
            }
        } else if (MOVE_FULL_ROWS.equals(key)) {
        } else if (MOVE_FULL_ROWS.equals(key)) {
            mFullRows = newValue == null || Integer.parseInt(newValue) != 0;
            mFullRows = TunerService.parseIntegerSwitch(newValue, true);
        } else if (QuickQSPanel.NUM_QUICK_TILES.equals(key)) {
        } else if (QuickQSPanel.NUM_QUICK_TILES.equals(key)) {
            mNumQuickTiles = mQuickQsPanel.getNumQuickTiles(mQs.getContext());
            mNumQuickTiles = mQuickQsPanel.getNumQuickTiles(mQs.getContext());
            clearAnimationState();
            clearAnimationState();
+1 −1
Original line number Original line Diff line number Diff line
@@ -207,7 +207,7 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
    }
    }


    private void updateViewVisibilityForTuningValue(View view, @Nullable String newValue) {
    private void updateViewVisibilityForTuningValue(View view, @Nullable String newValue) {
        view.setVisibility(newValue == null || Integer.parseInt(newValue) != 0 ? VISIBLE : GONE);
        view.setVisibility(TunerService.parseIntegerSwitch(newValue, true) ? VISIBLE : GONE);
    }
    }


    public void openDetails(String subPanel) {
    public void openDetails(String subPanel) {
+1 −1
Original line number Original line Diff line number Diff line
@@ -274,7 +274,7 @@ public class Clock extends TextView implements DemoMode, Tunable, CommandQueue.C
    @Override
    @Override
    public void onTuningChanged(String key, String newValue) {
    public void onTuningChanged(String key, String newValue) {
        if (CLOCK_SECONDS.equals(key)) {
        if (CLOCK_SECONDS.equals(key)) {
            mShowSeconds = newValue != null && Integer.parseInt(newValue) != 0;
            mShowSeconds = TunerService.parseIntegerSwitch(newValue, false);
            updateShowSeconds();
            updateShowSeconds();
        } else if (CLOCK_STYLE.equals(key)) {
        } else if (CLOCK_STYLE.equals(key)) {
            mAmPmStyle = newValue == null ? AM_PM_STYLE_GONE : Integer.valueOf(newValue);
            mAmPmStyle = newValue == null ? AM_PM_STYLE_GONE : Integer.valueOf(newValue);
+8 −0
Original line number Original line Diff line number Diff line
@@ -109,4 +109,12 @@ public abstract class TunerService {
        });
        });
        dialog.show();
        dialog.show();
    }
    }

    public static boolean parseIntegerSwitch(String value, boolean defaultValue) {
        try {
            return value != null ? Integer.parseInt(value) != 0 : defaultValue;
        } catch (NumberFormatException e) {
            return defaultValue;
        }
    }
}
}
+1 −1
Original line number Original line Diff line number Diff line
@@ -38,7 +38,7 @@ public class TunerSwitch extends SwitchPreference implements Tunable {


    @Override
    @Override
    public void onTuningChanged(String key, String newValue) {
    public void onTuningChanged(String key, String newValue) {
        setChecked(newValue != null ? Integer.parseInt(newValue) != 0 : mDefault);
        setChecked(TunerService.parseIntegerSwitch(newValue, mDefault));
    }
    }


    @Override
    @Override
Loading