Fix integer overflow in milliseconds.
This commit is contained in:
parent
517ae884b4
commit
a1ed6eb45b
@ -31,22 +31,22 @@
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/release" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/release/res" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/release/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/release/assets" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/release/aidl" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/release/assets" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/release/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/release/jni" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/release/rs" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
|
||||
|
@ -68,7 +68,6 @@ public class AlarmNotify extends Service {
|
||||
// Allow the user to cancel by selecting the ContentText or ContentTitle
|
||||
notification.setContentIntent(cancellerPendingIntent);
|
||||
|
||||
|
||||
nm.cancel(notifyID);
|
||||
nm.notify(notifyID, notification.build());
|
||||
|
||||
@ -79,9 +78,10 @@ public class AlarmNotify extends Service {
|
||||
// Make progress out of 1000 and not just 100, for greater resolution
|
||||
int max = 1000;
|
||||
// Count in milliseconds for greater progress resolution
|
||||
int milliSecondsLeft = (int) ((AlarmService.graceEndTime - System.currentTimeMillis()));
|
||||
int gracePeriodMilliSeconds = gracePeriod * 60 * 1000;
|
||||
int progress = ((gracePeriodMilliSeconds - milliSecondsLeft) * max) / gracePeriodMilliSeconds;
|
||||
long graceEndTime = AlarmService.graceEndTime;
|
||||
long milliSecondsLeft = ((graceEndTime - System.currentTimeMillis()));
|
||||
long gracePeriodMilliSeconds = gracePeriod * 60 * 1000;
|
||||
int progress = (int) (((gracePeriodMilliSeconds - milliSecondsLeft) * max) / gracePeriodMilliSeconds);
|
||||
|
||||
while (progress < max) {
|
||||
// Stop the thread if the notification is cancelled elsewhere
|
||||
@ -89,8 +89,10 @@ public class AlarmNotify extends Service {
|
||||
return;
|
||||
}
|
||||
// Recalculate milliSecondsLeft so that progress gets updated correctly.
|
||||
milliSecondsLeft = (int) ((AlarmService.graceEndTime - System.currentTimeMillis()));
|
||||
int minutesLeft = (milliSecondsLeft / 1000) / 60;
|
||||
milliSecondsLeft = ((graceEndTime - System.currentTimeMillis()));
|
||||
// Recalculate the progress
|
||||
progress = (int) (((gracePeriodMilliSeconds - milliSecondsLeft) * max) / gracePeriodMilliSeconds);
|
||||
int minutesLeft = (int) ((milliSecondsLeft / 1000) / 60);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 11) {
|
||||
notification.setContentText(String.format(getString(R.string.notificationText), MainActivity.MinutesToGracePeriodStr(minutesLeft)));
|
||||
@ -98,11 +100,8 @@ public class AlarmNotify extends Service {
|
||||
// Update the notification
|
||||
nm.notify(notifyID, notification.build());
|
||||
}
|
||||
// Prepare secondsLeft and progress for the next loop
|
||||
// Recalculate the progress
|
||||
progress = ((gracePeriodMilliSeconds - milliSecondsLeft) * max) / gracePeriodMilliSeconds;
|
||||
//Log.d("AlarmNotify", "milliSecondsLeft is " + milliSecondsLeft + " and progress is " + progress + " (gracePeriodMilliSeconds is " + gracePeriodMilliSeconds + ")");
|
||||
Log.d("AlarmNotify", "progress is " + progress + "; max is " + max);
|
||||
//Log.d("AlarmNotify", "milliSecondsLeft is " + milliSecondsLeft + " and gracePeriodMilliSeconds is " + gracePeriodMilliSeconds);
|
||||
//Log.d("AlarmNotify", "progress is " + progress + "; max is " + max);
|
||||
|
||||
// Sleep until we need to update again
|
||||
try {
|
||||
|
@ -177,6 +177,7 @@ public class AlarmService extends Service {
|
||||
// Change alarm status from ignored to snoozed
|
||||
alarmStatus = ALARM_SNOOZED;
|
||||
} else {
|
||||
Log.d("AlarmService", "Actually, not snoozing!");
|
||||
context.stopService(alarmServiceIntent);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user