[DO NOT MERGE] redbull: Fix race in init.twoshay.sh

Verify that the serial number is available before performing hash.

Bug: 168173860
Signed-off-by: Steve Pfetsch <spfetsch@google.com>
Change-Id: I32a4edb264cfbaeefa65a084f4681b22294e90a6
diff --git a/init.twoshay.sh b/init.twoshay.sh
index 16a3edc..c5af3aa 100755
--- a/init.twoshay.sh
+++ b/init.twoshay.sh
@@ -2,6 +2,19 @@
 
 # Implementation of A/B group selection - See b/161398758
 seedfile=/sys/devices/platform/soc/soc:qcom,dsi-display-primary/panel_info/panel0/serial_number
+
+# Poll the file for up to 30 seconds
+retries=30
+while [[ ! "$(cat $seedfile)" ]]; do
+    retries=$(($retries - 1))
+    if [[ $retries == 0 ]]; then
+        setprop vendor.twoshay.study_group "failed"
+        exit
+    fi
+
+    sleep 1
+done
+
 sum=$(sha1sum $seedfile)
 result=$(expr $((16#${sum:1:1})) % 2)