diff options
| author | 2019-03-16 15:43:04 +0000 | |
|---|---|---|
| committer | 2019-03-16 15:43:04 +0000 | |
| commit | a5f53a59c7110840dae9c31c2539b99b7ff893c5 (patch) | |
| tree | beafb30982ec2d58e63ffb0974b59d442c5e3c16 | |
| parent | 1276a178fd24f42d3c4bcbd44894c2c27ec3b478 (diff) | |
| parent | a2c86e8ae93934bc7af9ad60ce1399bbed19121d (diff) | |
Merge "revent NFE in SystemUI when parsing invalid int (2)"
6 files changed, 26 insertions, 23 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java b/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java index 2a4bb607673e..7148351cef03 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 @@ public class QSAnimator implements Callback, PageListener, Listener, OnLayoutCha @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 3fc258b1e8e9..bdc73d9bf4c4 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 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne } 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 8517d9086fc7..9c2060dfc2c2 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/Clock.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/Clock.java @@ -274,7 +274,7 @@ public class Clock extends TextView implements DemoMode, Tunable, CommandQueue.C @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 3a9d1c7caeb8..35ade2cb5830 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 @@ public abstract class TunerService { }); 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 f53d51690712..89049f8188b8 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 @@ public class TunerSwitch extends SwitchPreference implements Tunable { @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 dd552646955a..d089b2ff5c52 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 @@ public class VolumeDialogComponent implements VolumeComponent, TunerService.Tuna @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, |