summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Roland Levillain <rpl@google.com> 2017-03-03 12:30:17 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2017-03-03 12:30:18 +0000
commit3a791cee90451dc32d46f1b0a85fecc6f22f62bf (patch)
tree821a53e5737e341a8e52723bf4edd2598d47f456
parentb7b043a6ee90b8cc35758559b9ae27463d19f5f9 (diff)
parent2aab06beaf4b65ccc7511964bf555f7e169f8374 (diff)
Merge "Fix date on devices in setup-buildbot-device.sh."
-rwxr-xr-xtools/setup-buildbot-device.sh24
1 files changed, 24 insertions, 0 deletions
diff --git a/tools/setup-buildbot-device.sh b/tools/setup-buildbot-device.sh
index 1e9c763534..7eaaaf9cbd 100755
--- a/tools/setup-buildbot-device.sh
+++ b/tools/setup-buildbot-device.sh
@@ -17,9 +17,33 @@
green='\033[0;32m'
nc='\033[0m'
+# Setup as root, as the next buildbot step (device cleanup) requires it.
+# This is also required to set the date, if needed.
+adb root
+adb wait-for-device
+
+echo -e "${green}Date on host${nc}"
+date
+
echo -e "${green}Date on device${nc}"
adb shell date
+host_seconds_since_epoch=$(date -u +%s)
+device_seconds_since_epoch=$(adb shell date -u +%s)
+
+abs_time_difference_in_seconds=$(expr $host_seconds_since_epoch - $device_seconds_since_epoch)
+if [ $abs_time_difference_in_seconds -lt 0 ]; then
+ abs_time_difference_in_seconds=$(expr 0 - $abs_time_difference_in_seconds)
+fi
+
+seconds_per_hour=3600
+
+# Update date on device if the difference with host is more than one hour.
+if [ $abs_time_difference_in_seconds -gt $seconds_per_hour ]; then
+ echo -e "${green}Update date on device${nc}"
+ adb shell date -u @$host_seconds_since_epoch
+fi
+
echo -e "${green}Turn off selinux${nc}"
adb shell setenforce 0
adb shell getenforce