utils: bdaddr: skip setting bdaddr for 5.4 kernel version am: a565a8f7a8 am: 5b08acec95

Original change: https://android-review.googlesource.com/c/device/linaro/dragonboard/+/2894624

Change-Id: Icb17757a8d2657c4677de5ff0aef4347517f98de
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/sepolicy/set_bdaddr.te b/sepolicy/set_bdaddr.te
index c7fa166..1540d47 100644
--- a/sepolicy/set_bdaddr.te
+++ b/sepolicy/set_bdaddr.te
@@ -4,6 +4,7 @@
 
 # audit2allow
 allow set_bdaddr proc_cmdline:file { open read };
+allow set_bdaddr proc_version:file { open read getattr };
 allow set_bdaddr proc_bootconfig:file { open read };
 allow set_bdaddr rootfs:dir { open read };
 allow set_bdaddr self:bluetooth_socket { bind create read write };
diff --git a/shared/utils/bdaddr/set_bdaddr.sh b/shared/utils/bdaddr/set_bdaddr.sh
index e59fa39..2e4ff48 100644
--- a/shared/utils/bdaddr/set_bdaddr.sh
+++ b/shared/utils/bdaddr/set_bdaddr.sh
@@ -26,6 +26,19 @@
 # Format the output in xx:xx:xx:xx:xx:xx format for the
 # "bdaddr" command to work.
 
+if /vendor/bin/grep -o 'Linux version 5.4.' /proc/version; then
+    # for 5.4 kernels, setting the bdaddr would cause
+    # bluetooth::StackManager::StartUp crash like reported here:
+    #     https://issuetracker.google.com/issues/318404233
+    # so skipping it here.
+    # It's possible to not integrate this script at building time,
+    # but that way would make 5.4 and other kernel versions use different
+    # super.img files, for development convenience doing the check
+    # at runtime here, so that only boot.img/vendor_boot.img are
+    # necessary for different versions
+    exit 0
+fi
+
 BTADDR=`/vendor/bin/cat /proc/cmdline | /vendor/bin/grep -o serialno.* |\
 	/vendor/bin/cut -f2 -d'=' | /vendor/bin/awk '{printf("c0%010s\n", $1)}' |\
 	/vendor/bin/sed 's/\(..\)/\1:/g' | /vendor/bin/sed '$s/:$//'`