summaryrefslogtreecommitdiff
path: root/slideshow
diff options
context:
space:
mode:
authorJohan Redestig <johan.redestig@sonymobile.com>2015-10-12 10:24:30 +0200
committerJohan Redestig <johan.redestig@sonymobile.com>2015-10-12 10:29:50 +0200
commitc38026b690ba9f4fb088e4e0f85e893a15dc27d4 (patch)
treea12663abbe24e08ce4ad20b9bde44ea907ef1391 /slideshow
parent810ae48efc7e09bd06de0360b939dddb3c7e486a (diff)
downloadextras-c38026b690ba9f4fb088e4e0f85e893a15dc27d4.tar.gz
slideshow: Switch to android::uptimeMillis
time(2) is not guaranteed to always go forward which makes it a bit dangerous to use in loops like slideshow does. switch to uptimeMillis which is based on clock_gettime CLOCK_MONOTONIC which is is safe. Change-Id: Ica1b7ee50df00fcc7bc849d7eaebe64f62434a47
Diffstat (limited to 'slideshow')
-rw-r--r--slideshow/slideshow.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/slideshow/slideshow.cpp b/slideshow/slideshow.cpp
index 86e3c1b6..15824f83 100644
--- a/slideshow/slideshow.cpp
+++ b/slideshow/slideshow.cpp
@@ -20,10 +20,11 @@
#include <time.h>
#include <linux/input.h>
#include <cutils/klog.h>
+#include <utils/SystemClock.h>
#include "minui/minui.h"
#define NEXT_TIMEOUT_MS 5000
-#define LAST_TIMEOUT_S 30
+#define LAST_TIMEOUT_MS 30000
#define LOGE(x...) do { KLOG_ERROR("slideshow", x); } while (0)
@@ -85,7 +86,7 @@ int main(int argc, char **argv)
int input = false;
int opt;
long int timeout = NEXT_TIMEOUT_MS;
- time_t start;
+ int64_t start;
while ((opt = getopt(argc, argv, "t:")) != -1) {
switch (opt) {
@@ -118,7 +119,7 @@ int main(int argc, char **argv)
while (optind < argc - 1) {
draw(argv[optind++]);
- start = time(NULL);
+ start = android::uptimeMillis();
long int timeout_remaining = timeout;
do {
if (ev_wait(timeout_remaining) == 0) {
@@ -129,16 +130,17 @@ int main(int argc, char **argv)
break;
}
}
- timeout_remaining -= (long int)(time(NULL) - start) * 1000;
+ timeout_remaining -= android::uptimeMillis() - start;
} while (timeout_remaining > 0);
};
/* if there was user input while showing the images, display the last
- * image and wait until the power button is pressed or LAST_TIMEOUT_S
+ * image and wait until the power button is pressed or LAST_TIMEOUT_MS
* has elapsed */
if (input) {
- start = time(NULL);
+ start = android::uptimeMillis();
+
draw(argv[optind]);
do {
@@ -146,7 +148,7 @@ int main(int argc, char **argv)
ev_dispatch();
}
- if (time(NULL) - start >= LAST_TIMEOUT_S) {
+ if (android::uptimeMillis() - start >= LAST_TIMEOUT_MS) {
break;
}
} while (key_code != KEY_POWER);