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