summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2016-08-27 15:33:16 -0700
committerSunny Goyal <sunnygoyal@google.com>2016-09-02 18:28:20 +0000
commit6f2bb1ada5a68da74ad29d135fa32ec45b234dba (patch)
treee7f1e5c931cf7c5f9fac07ff88af32d58b0bbe51 /src
parentdef6e474dad311224b97ae66f62c3313c6542955 (diff)
downloadandroid_packages_apps_Trebuchet-6f2bb1ada5a68da74ad29d135fa32ec45b234dba.tar.gz
android_packages_apps_Trebuchet-6f2bb1ada5a68da74ad29d135fa32ec45b234dba.tar.bz2
android_packages_apps_Trebuchet-6f2bb1ada5a68da74ad29d135fa32ec45b234dba.zip
Bug fix in Alarm where it was not getting called correctly if the
new timeout was set that was smaller than the previously set timeout > Using uptimeMillis in Alarm to avoid errors due to system time changes > Adding an extra check in Wait in case Thread.sleep eats up all the timeout Change-Id: Id1fac5e8fdb81a0c3c7a6a5e50586b2a2f180d06 (cherry picked from commit a2125e1d102034e1d638b5d1e973b5b77cfe1efd)
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher3/Alarm.java15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/com/android/launcher3/Alarm.java b/src/com/android/launcher3/Alarm.java
index e9f1fd963..d5b434c64 100644
--- a/src/com/android/launcher3/Alarm.java
+++ b/src/com/android/launcher3/Alarm.java
@@ -17,6 +17,7 @@
package com.android.launcher3;
import android.os.Handler;
+import android.os.SystemClock;
public class Alarm implements Runnable{
// if we reach this time and the alarm hasn't been cancelled, call the listener
@@ -41,9 +42,16 @@ public class Alarm implements Runnable{
// Sets the alarm to go off in a certain number of milliseconds. If the alarm is already set,
// it's overwritten and only the new alarm setting is used
public void setAlarm(long millisecondsInFuture) {
- long currentTime = System.currentTimeMillis();
+ long currentTime = SystemClock.uptimeMillis();
mAlarmPending = true;
+ long oldTriggerTime = mAlarmTriggerTime;
mAlarmTriggerTime = currentTime + millisecondsInFuture;
+
+ // If the previous alarm was set for a longer duration, cancel it.
+ if (mWaitingForCallback && oldTriggerTime > mAlarmTriggerTime) {
+ mHandler.removeCallbacks(this);
+ mWaitingForCallback = false;
+ }
if (!mWaitingForCallback) {
mHandler.postDelayed(this, mAlarmTriggerTime - currentTime);
mWaitingForCallback = true;
@@ -51,15 +59,14 @@ public class Alarm implements Runnable{
}
public void cancelAlarm() {
- mAlarmTriggerTime = 0;
mAlarmPending = false;
}
// this is called when our timer runs out
public void run() {
mWaitingForCallback = false;
- if (mAlarmTriggerTime != 0) {
- long currentTime = System.currentTimeMillis();
+ if (mAlarmPending) {
+ long currentTime = SystemClock.uptimeMillis();
if (mAlarmTriggerTime > currentTime) {
// We still need to wait some time to trigger spring loaded mode--
// post a new callback