revent 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
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java b/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java
index 2a4bb60..7148351 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java
@@ -127,12 +127,12 @@
@Override
public void onTuningChanged(String key, String newValue) {
if (ALLOW_FANCY_ANIMATION.equals(key)) {
- mAllowFancy = newValue == null || Integer.parseInt(newValue) != 0;
+ mAllowFancy = TunerService.parseIntegerSwitch(newValue, true);
if (!mAllowFancy) {
clearAnimationState();
}
} 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)) {
mNumQuickTiles = mQuickQsPanel.getNumQuickTiles(mQs.getContext());
clearAnimationState();
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
index 3fc258b..bdc73d9 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
@@ -191,7 +191,7 @@
}
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) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/Clock.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/Clock.java
index 9aa8044..24f7804a 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/Clock.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/Clock.java
@@ -233,7 +233,7 @@
@Override
public void onTuningChanged(String key, String newValue) {
if (CLOCK_SECONDS.equals(key)) {
- mShowSeconds = newValue != null && Integer.parseInt(newValue) != 0;
+ mShowSeconds = TunerService.parseIntegerSwitch(newValue, false);
updateShowSeconds();
} else {
setClockVisibleByUser(!StatusBarIconController.getIconBlacklist(newValue)
diff --git a/packages/SystemUI/src/com/android/systemui/tuner/TunerService.java b/packages/SystemUI/src/com/android/systemui/tuner/TunerService.java
index 3a9d1c7..35ade2c 100644
--- a/packages/SystemUI/src/com/android/systemui/tuner/TunerService.java
+++ b/packages/SystemUI/src/com/android/systemui/tuner/TunerService.java
@@ -109,4 +109,12 @@
});
dialog.show();
}
+
+ public static boolean parseIntegerSwitch(String value, boolean defaultValue) {
+ try {
+ return value != null ? Integer.parseInt(value) != 0 : defaultValue;
+ } catch (NumberFormatException e) {
+ return defaultValue;
+ }
+ }
}
diff --git a/packages/SystemUI/src/com/android/systemui/tuner/TunerSwitch.java b/packages/SystemUI/src/com/android/systemui/tuner/TunerSwitch.java
index f53d516..89049f8 100644
--- a/packages/SystemUI/src/com/android/systemui/tuner/TunerSwitch.java
+++ b/packages/SystemUI/src/com/android/systemui/tuner/TunerSwitch.java
@@ -38,7 +38,7 @@
@Override
public void onTuningChanged(String key, String newValue) {
- setChecked(newValue != null ? Integer.parseInt(newValue) != 0 : mDefault);
+ setChecked(TunerService.parseIntegerSwitch(newValue, mDefault));
}
@Override
diff --git a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogComponent.java b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogComponent.java
index dd55264..d089b2f 100644
--- a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogComponent.java
+++ b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogComponent.java
@@ -108,28 +108,23 @@
@Override
public void onTuningChanged(String key, String newValue) {
+ boolean volumeDownToEnterSilent = mVolumePolicy.volumeDownToEnterSilent;
+ boolean volumeUpToExitSilent = mVolumePolicy.volumeUpToExitSilent;
+ boolean doNotDisturbWhenSilent = mVolumePolicy.doNotDisturbWhenSilent;
+
if (VOLUME_DOWN_SILENT.equals(key)) {
- final boolean volumeDownToEnterSilent = newValue != null
- ? Integer.parseInt(newValue) != 0
- : DEFAULT_VOLUME_DOWN_TO_ENTER_SILENT;
- setVolumePolicy(volumeDownToEnterSilent,
- mVolumePolicy.volumeUpToExitSilent, mVolumePolicy.doNotDisturbWhenSilent,
- mVolumePolicy.vibrateToSilentDebounce);
+ volumeDownToEnterSilent =
+ TunerService.parseIntegerSwitch(newValue, DEFAULT_VOLUME_DOWN_TO_ENTER_SILENT);
} else if (VOLUME_UP_SILENT.equals(key)) {
- final boolean volumeUpToExitSilent = newValue != null
- ? Integer.parseInt(newValue) != 0
- : DEFAULT_VOLUME_UP_TO_EXIT_SILENT;
- setVolumePolicy(mVolumePolicy.volumeDownToEnterSilent,
- volumeUpToExitSilent, mVolumePolicy.doNotDisturbWhenSilent,
- mVolumePolicy.vibrateToSilentDebounce);
+ volumeUpToExitSilent =
+ TunerService.parseIntegerSwitch(newValue, DEFAULT_VOLUME_UP_TO_EXIT_SILENT);
} else if (VOLUME_SILENT_DO_NOT_DISTURB.equals(key)) {
- final boolean doNotDisturbWhenSilent = newValue != null
- ? Integer.parseInt(newValue) != 0
- : DEFAULT_DO_NOT_DISTURB_WHEN_SILENT;
- setVolumePolicy(mVolumePolicy.volumeDownToEnterSilent,
- mVolumePolicy.volumeUpToExitSilent, doNotDisturbWhenSilent,
- mVolumePolicy.vibrateToSilentDebounce);
+ doNotDisturbWhenSilent =
+ TunerService.parseIntegerSwitch(newValue, DEFAULT_DO_NOT_DISTURB_WHEN_SILENT);
}
+
+ setVolumePolicy(volumeDownToEnterSilent, volumeUpToExitSilent, doNotDisturbWhenSilent,
+ mVolumePolicy.vibrateToSilentDebounce);
}
private void setVolumePolicy(boolean volumeDownToEnterSilent, boolean volumeUpToExitSilent,