Fix the arbitrary limit numbers and number overflow problem.

Bug: 30560513

Change-Id: Ic36381cbf7e03d21e2ef8f9b7c76268386e5f40e
This commit is contained in:
jackqdyulei
2016-08-09 14:24:48 -07:00
parent be89e726d2
commit f69aa8e6ad

View File

@@ -48,6 +48,7 @@ public class BillingCycleSettings extends DataUsageBase implements
private static final String TAG = "BillingCycleSettings";
private static final boolean LOGD = false;
private static final long MAX_DATA_LIMIT_BYTES = 50000 * GB_IN_BYTES;
private static final String TAG_CONFIRM_LIMIT = "confirmLimit";
private static final String TAG_CYCLE_EDITOR = "cycleEditor";
@@ -228,10 +229,13 @@ public class BillingCycleSettings extends DataUsageBase implements
}
final long bytes = (long) (Float.valueOf(bytesString)
* (spinner.getSelectedItemPosition() == 0 ? MB_IN_BYTES : GB_IN_BYTES));
// to fix the overflow problem
final long correctedBytes = Math.min(MAX_DATA_LIMIT_BYTES, bytes);
if (isLimit) {
editor.setPolicyLimitBytes(template, bytes);
editor.setPolicyLimitBytes(template, correctedBytes);
} else {
editor.setPolicyWarningBytes(template, bytes);
editor.setPolicyWarningBytes(template, correctedBytes);
}
target.updatePrefs();
}