Merge "revent NFE in SystemUI when parsing invalid int (2)"

am: a5f53a59c7

Change-Id: I1b0b6e8c7c01cf02426d1cbeec9196b285d6283a
This commit is contained in:
Evan Laird
2019-03-16 08:52:16 -07:00
committed by android-build-merger
6 changed files with 26 additions and 23 deletions

View File

@@ -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();

View File

@@ -191,7 +191,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) {

View File

@@ -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 { } else {
setClockVisibleByUser(!StatusBarIconController.getIconBlacklist(newValue) setClockVisibleByUser(!StatusBarIconController.getIconBlacklist(newValue)

View File

@@ -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;
}
}
} }

View File

@@ -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

View File

@@ -108,28 +108,23 @@ public class VolumeDialogComponent implements VolumeComponent, TunerService.Tuna
@Override @Override
public void onTuningChanged(String key, String newValue) { 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)) { if (VOLUME_DOWN_SILENT.equals(key)) {
final boolean volumeDownToEnterSilent = newValue != null volumeDownToEnterSilent =
? Integer.parseInt(newValue) != 0 TunerService.parseIntegerSwitch(newValue, DEFAULT_VOLUME_DOWN_TO_ENTER_SILENT);
: DEFAULT_VOLUME_DOWN_TO_ENTER_SILENT;
setVolumePolicy(volumeDownToEnterSilent,
mVolumePolicy.volumeUpToExitSilent, mVolumePolicy.doNotDisturbWhenSilent,
mVolumePolicy.vibrateToSilentDebounce);
} else if (VOLUME_UP_SILENT.equals(key)) { } else if (VOLUME_UP_SILENT.equals(key)) {
final boolean volumeUpToExitSilent = newValue != null volumeUpToExitSilent =
? Integer.parseInt(newValue) != 0 TunerService.parseIntegerSwitch(newValue, DEFAULT_VOLUME_UP_TO_EXIT_SILENT);
: DEFAULT_VOLUME_UP_TO_EXIT_SILENT;
setVolumePolicy(mVolumePolicy.volumeDownToEnterSilent,
volumeUpToExitSilent, mVolumePolicy.doNotDisturbWhenSilent,
mVolumePolicy.vibrateToSilentDebounce);
} else if (VOLUME_SILENT_DO_NOT_DISTURB.equals(key)) { } else if (VOLUME_SILENT_DO_NOT_DISTURB.equals(key)) {
final boolean doNotDisturbWhenSilent = newValue != null doNotDisturbWhenSilent =
? Integer.parseInt(newValue) != 0 TunerService.parseIntegerSwitch(newValue, DEFAULT_DO_NOT_DISTURB_WHEN_SILENT);
: DEFAULT_DO_NOT_DISTURB_WHEN_SILENT;
setVolumePolicy(mVolumePolicy.volumeDownToEnterSilent,
mVolumePolicy.volumeUpToExitSilent, doNotDisturbWhenSilent,
mVolumePolicy.vibrateToSilentDebounce);
} }
setVolumePolicy(volumeDownToEnterSilent, volumeUpToExitSilent, doNotDisturbWhenSilent,
mVolumePolicy.vibrateToSilentDebounce);
} }
private void setVolumePolicy(boolean volumeDownToEnterSilent, boolean volumeUpToExitSilent, private void setVolumePolicy(boolean volumeDownToEnterSilent, boolean volumeUpToExitSilent,