utils: bdaddr: skip setting bdaddr for 5.4 kernel version
The functionality added required for 6.5 with the following commit:
f70f12a826af("utils: bdaddr: Add service to set Bluetooth device (MAC) address")
is causing bluetooth::StackManager::StartUp crash like the following
when running with 5.4 kernel, so disable it for the older kernel:
signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
Abort message: 'assertion 'init_status == std::future_status::ready' failed - Can't start stack, last instance: starting HciHalHidl'
x0 0000000000000000 x1 000000000000069c x2 0000000000000006 x3 0000007719da2920
x4 6539396373721f3c x5 6539396373721f3c x6 6539396373721f3c x7 7f7f7f7f7f7f7f7f
x8 00000000000000f0 x9 00000079d1ec91e0 x10 0000000000000001 x11 00000079d1f13d70
x12 0000007719da17d0 x13 0000000000000074 x14 0000007719da2b50 x15 0000000034155555
x16 00000079d1f7efc8 x17 00000079d1f5c340 x18 00000076ad318080 x19 00000000000000ac
x20 00000000000000b2 x21 0000000000000625 x22 000000000000069c x23 00000000ffffffff
x24 0000007719da3c00 x25 00000076b2c982c0 x26 b40000772f316328 x27 00000076b2c98628
x28 00000000000fc000 x29 0000007719da29a0
lr 00000079d1f04e64 sp 0000007719da2900 pc 00000079d1f04e94 pst 0000000000000000
22 total frames
backtrace:
#00 pc 000000000005ee94 /apex/com.android.runtime/lib64/bionic/libc.so (abort+180) (BuildId: 1ffa09de737610ba7914fa6b86cf1b26)
#01 pc 00000000008f9d3c /apex/com.android.art/lib64/libart.so (art::Runtime::Abort(char const*)+108) (BuildId: 5ddd19adda7ab3940f0f61174e932e91)
#02 pc 0000000000017b70 /apex/com.android.art/lib64/libbase.so (android::base::SetAborter(std::__1::function<void (char const*)>&&)::$_0::__invoke(char const*)+80) (BuildId: e9db07da281f032c2b3d02394cd7bee7)
#03 pc 00000000000070d4 /system/lib64/liblog.so (__android_log_assert+292) (BuildId: dda91191700fd626ee1c85d486d343fd)
#04 pc 0000000000abb138 /apex/com.android.btservices/lib64/libbluetooth_jni.so (bluetooth::StackManager::StartUp(bluetooth::ModuleList*, bluetooth::os::Thread*)+712) (BuildId: 8bdf73ef70163f9dbe5faa8a86571e47)
#05 pc 00000000003f3820 /apex/com.android.btservices/lib64/libbluetooth_jni.so (bluetooth::shim::Stack::Start(bluetooth::ModuleList*)+192) (BuildId: 8bdf73ef70163f9dbe5faa8a86571e47)
#06 pc 00000000003f35f4 /apex/com.android.btservices/lib64/libbluetooth_jni.so (bluetooth::shim::Stack::StartEverything()+980) (BuildId: 8bdf73ef70163f9dbe5faa8a86571e47)
Bug: 318404233
Fixes: f70f12a826af("utils: bdaddr: Add service to set Bluetooth device (MAC) address")
Test: CtsBluetoothTestCases finished in ~6minutes with 8 failures reported for 5.4 kernel
Change-Id: Ibe710aefe0f280fb014fdcd5380c68565e52f936
Signed-off-by: Yongqin Liu <yongqin.liu@linaro.org>
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/:$//'`