summaryrefslogtreecommitdiffstats
path: root/meta-audio-4a-framework
diff options
context:
space:
mode:
authorStephane Desneux <stephane.desneux@iot.bzh>2018-09-27 17:35:20 +0000
committerStéphane Desneux <stephane.desneux@iot.bzh>2018-09-28 16:03:48 +0000
commitb5df3d646894d0ee798a1949dbda9620131dbb4e (patch)
treeacd60e5633d880f17e9566d41c4265feeb7031e5 /meta-audio-4a-framework
parentb674a03bd441a0c357277b003e88267d45b5dbfe (diff)
4A: delay service startup as a workaround to SPEC-1762/SPEC-1763 (temp workaround)flounder_6.0.0flounder/6.0.06.0.0
This patch introduces a wait loop before starting the 4A binder: * wait for bluetooth module to be loaded * wait for bluetooth controller to be up & running * wait for bluetooth manager to be initialized Then 4A can start with BT-audio support. If no BT controller is detected in 5secondes, the loop exits and 4A doesn't initialize BT-Audio Bug-AGL: SPEC-1762, SPEC-1763 Change-Id: Ibe851dee871d183511c7bca03411b35ed023f422 Signed-off-by: Stephane Desneux <stephane.desneux@iot.bzh>
Diffstat (limited to 'meta-audio-4a-framework')
-rw-r--r--meta-audio-4a-framework/recipes-multimedia/agl-service-audio-4a/agl-service-audio-4a_git.bb14
-rwxr-xr-xmeta-audio-4a-framework/recipes-multimedia/agl-service-audio-4a/files/4a_wait_bt.sh83
2 files changed, 97 insertions, 0 deletions
diff --git a/meta-audio-4a-framework/recipes-multimedia/agl-service-audio-4a/agl-service-audio-4a_git.bb b/meta-audio-4a-framework/recipes-multimedia/agl-service-audio-4a/agl-service-audio-4a_git.bb
index 63d2bdb5..78cb2e7f 100644
--- a/meta-audio-4a-framework/recipes-multimedia/agl-service-audio-4a/agl-service-audio-4a_git.bb
+++ b/meta-audio-4a-framework/recipes-multimedia/agl-service-audio-4a/agl-service-audio-4a_git.bb
@@ -37,8 +37,22 @@ sed -i -e 's|/usr/bin/afb-daemon\>|& --ldpath=/usr/libexec/agl/4a-alsa-core/lib:
# binder name matters: it must match "afbd-4a-*" => the config file (controller json file) that will be searched will be "policy-4a-*.json"
sed -i -e 's|--name afbd-agl-\(.*\)|--name afbd-4a-\1|' $svcfile
+# workaround for SPEC-1762
+sed -i -e 's|/usr/bin/afb-daemon\>|/usr/bin/4a_wait_bt.sh &|' $svcfile
+
echo "-- TMP 4A INSTALL FIX END"
EOF
chmod a+x ${D}/${sysconfdir}/agl-postinsts/99_4A_service_patch.sh
}
+
+##############################################
+# workaround for SPEC-1762/SPEC-1763
+RDEPENDS_${PN} += "bash"
+SRC_URI += "file://4a_wait_bt.sh"
+do_install_append() {
+ install -d ${D}${bindir}
+ install -m 0755 ${WORKDIR}/4a_wait_bt.sh ${D}${bindir}/
+}
+#
+##############################################
diff --git a/meta-audio-4a-framework/recipes-multimedia/agl-service-audio-4a/files/4a_wait_bt.sh b/meta-audio-4a-framework/recipes-multimedia/agl-service-audio-4a/files/4a_wait_bt.sh
new file mode 100755
index 00000000..a1df1ea0
--- /dev/null
+++ b/meta-audio-4a-framework/recipes-multimedia/agl-service-audio-4a/files/4a_wait_bt.sh
@@ -0,0 +1,83 @@
+#!/bin/bash
+
+###############################################################
+# This is a workaround for SPEC-1762/SPEC-1763
+#
+# THIS SCRIPT MUST BE REMOVED ONCE THE ABOVE ISSUES ARE SOLVED
+#
+# Source recipe is:
+#
+# meta-audio-4a-framework/
+# recipes-multimedia/
+# agl-service-audio-4a/
+# agl-service-audio-4a_git.bb
+#
+# Signed-off-by: Stephane Desneux <stephane.desneux@iot.bzh>
+###############################################################
+
+# time from script startup
+LIMIT=20
+ts0=0
+function ts() { echo $(( $(date +%s) - ts0 )); }
+ts0=$(ts)
+function havetime() { [[ $(ts) -le ${1:-$LIMIT} ]] || return 1; }
+
+function waitloop() {
+ # ensure bt modules are loaded (delay: 5s)
+ while havetime 4; do
+ [[ -d /sys/module/bluetooth ]] && {
+ echo "bluetooth kernel module detected"
+ break
+ }
+ echo "waiting for bluetooth kernel module to be up"
+ sleep 0.2
+ done
+ havetime 4 || { echo "TIMEOUT REACHED"; return 1; }
+
+ # check that we have at least one controller
+ HCIDEV=
+ while havetime 8; do
+ echo "detecting hci devices..."
+ for x in $(ls /sys/class/bluetooth/hci* 2>/dev/null); do
+ [[ -z "$HCIDEV" ]] && HCIDEV=$(basename $x)
+ done
+ [[ -n "$HCIDEV" ]] && {
+ echo "found HCI controller: $HCIDEV"
+ break
+ }
+ sleep 0.2
+ done
+ havetime 8 || { echo "TIMEOUT REACHED"; return 1; }
+
+ # wait for controller to be up and running
+ while havetime 15; do
+ state=$(hciconfig $HCIDEV | grep -A 2 ^hci0 | tail -1)
+ [[ $state =~ UP ]] && [[ $state =~ RUNNING ]] && {
+ echo "HCI controller $HCIDEV state: $state"
+ break
+ }
+ echo "HCI controller $HCIDEV state: $state ... waiting for UP RUNNING"
+ sleep 0.2
+ done
+ havetime 15 || { echo "TIMEOUT REACHED"; return 1; }
+ echo "HCI device up and running after $(ts) seconds"
+
+ # wait for bluetooth-service to return something
+ while havetime; do
+ res=$(afb-client-demo -d unix:/run/user/$UID/apis/ws/Bluetooth-Manager power true)
+ [[ "$res" =~ \"response\":(.*)}$ ]] && res=${BASH_REMATCH[1]}
+ [[ "$res" == '{"power":"on"}' ]] && {
+ echo "Bluetooth-Manager/power: $res"
+ break
+ }
+ echo "Bluetooth-Manager/power: not ready yet ($res)"
+ sleep 0.2
+ done
+ echo "Bluetooth-Manager ready after $(ts) seconds"
+
+ echo "4A now starting..."
+}
+
+waitloop 2>&1 | sed 's/^/4AWAITBT /' >&2
+exec "$@"
+