diff options
author | 2024-11-04 10:56:54 -0800 | |
---|---|---|
committer | 2024-11-04 23:42:02 +0000 | |
commit | 605bc9acad352320d59b96d6f60003393a1703c3 (patch) | |
tree | 5ac30d8c7b83385fcbd59dbd1e29881e1779eb8e | |
parent | 342ed20dfd1c8303d499cdee94e25c960a01b14f (diff) |
osi: Use CLOCK_MONOTONIC on platforms that can't wake on BT
Some devices (such as TVs) are not wired up to be
woken by the controller. These devices might run
into unforeseen issues going to sleep with timers
armed. This commit adds a sysprop
(bluetooth.hardware.wakeup_supported) to specify
that the platform is wired up like that, and makes
all alarms on those platforms monotonic, so they
do not count up during suspend.
Bug: 343826774
Test: m -j128 com.android.btservices & QA testing
Flag: EXEMPT, behaviour controlled by sysprop
Change-Id: Ie720ea3c20cba317eb3536c49604c9c8b9c2d80f
29 files changed, 72 insertions, 1 deletions
diff --git a/sysprop/Android.bp b/sysprop/Android.bp index 1b72eb4cb7..e9d820b2f1 100644 --- a/sysprop/Android.bp +++ b/sysprop/Android.bp @@ -12,6 +12,7 @@ sysprop_library { "bta.sysprop", "device_id.sysprop", "gap.sysprop", + "hardware.sysprop", "hfp.sysprop", ], property_owner: "Platform", diff --git a/sysprop/BUILD.gn b/sysprop/BUILD.gn index 407b7a88fc..9cdbf48530 100644 --- a/sysprop/BUILD.gn +++ b/sysprop/BUILD.gn @@ -8,6 +8,7 @@ sysprop("libcom.android.sysprop.bluetooth") { "bta.sysprop", "device_id.sysprop", "gap.sysprop", + "hardware.sysprop", "hfp.sysprop", ] deps = [ "//bt/floss/android-base:android-base" ] diff --git a/sysprop/exported_include/android_bluetooth_sysprop.h b/sysprop/exported_include/android_bluetooth_sysprop.h index 8d5122d8e2..24053123ac 100644 --- a/sysprop/exported_include/android_bluetooth_sysprop.h +++ b/sysprop/exported_include/android_bluetooth_sysprop.h @@ -22,4 +22,5 @@ #include <bta.sysprop.h> #include <device_id.sysprop.h> #include <gap.sysprop.h> +#include <hardware.sysprop.h> #include <hfp.sysprop.h> diff --git a/sysprop/hardware.sysprop b/sysprop/hardware.sysprop new file mode 100644 index 0000000000..07c09134bb --- /dev/null +++ b/sysprop/hardware.sysprop @@ -0,0 +1,10 @@ +module: "android.sysprop.bluetooth.hardware" +owner: Platform + +prop { + api_name: "wakeup_supported" + type: Boolean + scope: Internal + access: Readonly + prop_name: "bluetooth.hardware.wakeup_supported" +} diff --git a/system/audio_hal_interface/Android.bp b/system/audio_hal_interface/Android.bp index 987b859214..f485de80aa 100644 --- a/system/audio_hal_interface/Android.bp +++ b/system/audio_hal_interface/Android.bp @@ -187,6 +187,7 @@ cc_test { "libbluetooth_log", "libbt-common", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libflagtest", "libfmq", "libgmock", @@ -246,6 +247,7 @@ cc_defaults { "libbtif", "libbtif-core", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libcutils", "libevent", "libg722codec", diff --git a/system/audio_hal_interface/fuzzer/Android.bp b/system/audio_hal_interface/fuzzer/Android.bp index 93a734b02f..9a32f910e3 100644 --- a/system/audio_hal_interface/fuzzer/Android.bp +++ b/system/audio_hal_interface/fuzzer/Android.bp @@ -83,6 +83,7 @@ cc_defaults { "libbtif", "libbtif-core", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libcutils", "libevent", "libexpresslog", diff --git a/system/audio_hearing_aid_hw/Android.bp b/system/audio_hearing_aid_hw/Android.bp index 19694cac77..fa17bac274 100644 --- a/system/audio_hearing_aid_hw/Android.bp +++ b/system/audio_hearing_aid_hw/Android.bp @@ -59,6 +59,7 @@ cc_test { static_libs: [ "audio.hearing_aid.default", "libbluetooth_log", + "libcom.android.sysprop.bluetooth.wrapped", "libosi", ], min_sdk_version: "29", diff --git a/system/bta/Android.bp b/system/bta/Android.bp index ad4e798016..8efc0fdba0 100644 --- a/system/bta/Android.bp +++ b/system/bta/Android.bp @@ -447,6 +447,7 @@ cc_test { "libbt-platform-protos-lite", "libbtcore", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libgmock", "libosi", "libstatslog_bt", @@ -563,6 +564,7 @@ cc_test { "libbluetooth_log", "libbt-common", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libcutils", "libgmock", "libosi", @@ -610,6 +612,7 @@ cc_test { "libbluetooth_log", "libbt-common", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libgmock", "libosi", ], @@ -823,6 +826,7 @@ cc_test { "libbt-common", "libbt-platform-protos-lite", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libevent", "libflatbuffers-cpp", "libgmock", @@ -933,6 +937,7 @@ cc_test { "libbt-common", "libbt-platform-protos-lite", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libevent", "libflatbuffers-cpp", "libgmock", @@ -1022,6 +1027,7 @@ cc_test { "libbt-common", "libbt-platform-protos-lite", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libevent", "libflagtest", "libflatbuffers-cpp", diff --git a/system/btcore/Android.bp b/system/btcore/Android.bp index 96da5abf57..dc6df095ad 100644 --- a/system/btcore/Android.bp +++ b/system/btcore/Android.bp @@ -110,6 +110,7 @@ cc_test { "libbluetooth_log", "libbtcore", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libosi", ], host_supported: true, diff --git a/system/btcore/fuzzer/Android.bp b/system/btcore/fuzzer/Android.bp index 746a3b31b5..c930086694 100644 --- a/system/btcore/fuzzer/Android.bp +++ b/system/btcore/fuzzer/Android.bp @@ -38,6 +38,7 @@ cc_defaults { "libbt-common", "libbtcore", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libevent", "liblog", "libmodpb64", diff --git a/system/btif/Android.bp b/system/btif/Android.bp index 4aa018563b..649c08e941 100644 --- a/system/btif/Android.bp +++ b/system/btif/Android.bp @@ -396,6 +396,7 @@ cc_test { "libbluetooth_gd", "libbluetooth_log", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libosi", ], shared_libs: [ @@ -430,6 +431,7 @@ cc_test { "libbluetooth-types", "libbluetooth_log", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libosi", ], shared_libs: [ diff --git a/system/common/Android.bp b/system/common/Android.bp index 3009c77ec0..4bc0bebf2d 100644 --- a/system/common/Android.bp +++ b/system/common/Android.bp @@ -140,6 +140,7 @@ cc_test { "libbluetooth_log", "libbt-common", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libevent", "libgmock", "libosi", @@ -168,6 +169,7 @@ cc_benchmark { "libbluetooth_log", "libbt-common", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libevent", "libosi", ], diff --git a/system/device/Android.bp b/system/device/Android.bp index 4753441a66..1a5d72ae45 100644 --- a/system/device/Android.bp +++ b/system/device/Android.bp @@ -68,6 +68,7 @@ cc_test { "libbtcore", "libbtdevice", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libosi", ], header_libs: ["libbluetooth_headers"], diff --git a/system/device/fuzzer/Android.bp b/system/device/fuzzer/Android.bp index 0b5e6c1296..a466d78d6b 100644 --- a/system/device/fuzzer/Android.bp +++ b/system/device/fuzzer/Android.bp @@ -52,6 +52,7 @@ cc_fuzz { "libbtcore", "libbtdevice", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libgmock", "libosi", ], diff --git a/system/hci/Android.bp b/system/hci/Android.bp index 5e493288a7..e4e0106606 100644 --- a/system/hci/Android.bp +++ b/system/hci/Android.bp @@ -66,6 +66,7 @@ cc_test { "libbluetooth_log", "libbt-hci", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libosi", ], sanitize: { diff --git a/system/osi/Android.bp b/system/osi/Android.bp index aeabc7ad18..4806d61985 100644 --- a/system/osi/Android.bp +++ b/system/osi/Android.bp @@ -92,6 +92,7 @@ cc_library_static { "libaconfig_storage_read_api_cc", "libbluetooth_log", "libbt-platform-protos-lite", + "libcom.android.sysprop.bluetooth.wrapped", "server_configurable_flags", ], } @@ -145,6 +146,7 @@ cc_test { "libbluetooth_log", "libbt-common", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libevent", "libgmock", "libosi", diff --git a/system/osi/BUILD.gn b/system/osi/BUILD.gn index fdd2736fab..ffc3dfcac8 100644 --- a/system/osi/BUILD.gn +++ b/system/osi/BUILD.gn @@ -55,6 +55,7 @@ static_library("osi") { deps = [ "//bt/flags:bluetooth_flags_c_lib", + "//bt/sysprop:libcom.android.sysprop.bluetooth", "//bt/system/common", ] @@ -92,6 +93,7 @@ if (use.test) { ] deps = [ + "//bt/sysprop:libcom.android.sysprop.bluetooth", "//bt/system/osi", ] diff --git a/system/osi/src/alarm.cc b/system/osi/src/alarm.cc index a280442bb0..c1a1b6da10 100644 --- a/system/osi/src/alarm.cc +++ b/system/osi/src/alarm.cc @@ -20,6 +20,7 @@ #include "osi/include/alarm.h" +#include <android_bluetooth_sysprop.h> #include <base/cancelable_callback.h> #include <bluetooth/log.h> #include <fcntl.h> @@ -312,6 +313,13 @@ static bool lazy_initialize(void) { bool timer_initialized = false; bool wakeup_timer_initialized = false; + // some platforms are not wired up to be woken up by the controller. + // on those platforms, if we go to sleep with a timer armed, it will + // continue counting during sleep. to prevent unwanted timer fires on + // those platforms, use CLOCK_MONOTONIC and don't count up during sleep. + bool wakeup_supported = android::sysprop::bluetooth::hardware::wakeup_supported().value_or(true); + clockid_t alarm_clockid = wakeup_supported ? CLOCK_BOOTTIME_ALARM : CLOCK_MONOTONIC; + std::lock_guard<std::mutex> lock(alarms_mutex); alarms = list_new(NULL); @@ -325,7 +333,7 @@ static bool lazy_initialize(void) { } timer_initialized = true; - if (!timer_create_internal(CLOCK_BOOTTIME_ALARM, &wakeup_timer)) { + if (!timer_create_internal(alarm_clockid, &wakeup_timer)) { if (!timer_create_internal(CLOCK_BOOTTIME, &wakeup_timer)) { goto error; } diff --git a/system/osi/test/fuzzers/alarm/Android.bp b/system/osi/test/fuzzers/alarm/Android.bp index e1108e8731..3af1096546 100644 --- a/system/osi/test/fuzzers/alarm/Android.bp +++ b/system/osi/test/fuzzers/alarm/Android.bp @@ -25,6 +25,7 @@ cc_fuzz { "libbluetooth_log", "libbt-common", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libgmock", "libosi", ], diff --git a/system/osi/test/fuzzers/allocator/Android.bp b/system/osi/test/fuzzers/allocator/Android.bp index f4874ff322..36b5ee4ae6 100644 --- a/system/osi/test/fuzzers/allocator/Android.bp +++ b/system/osi/test/fuzzers/allocator/Android.bp @@ -18,6 +18,7 @@ cc_fuzz { "libbase", "libbluetooth_log", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "liblog", "libosi", ], diff --git a/system/osi/test/fuzzers/fixed_queue/Android.bp b/system/osi/test/fuzzers/fixed_queue/Android.bp index 8758597a55..02ad1896bd 100644 --- a/system/osi/test/fuzzers/fixed_queue/Android.bp +++ b/system/osi/test/fuzzers/fixed_queue/Android.bp @@ -22,6 +22,7 @@ cc_fuzz { static_libs: [ "libbluetooth_log", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libosi", ], } diff --git a/system/osi/test/fuzzers/future/Android.bp b/system/osi/test/fuzzers/future/Android.bp index 46673e2659..c96dd2f984 100644 --- a/system/osi/test/fuzzers/future/Android.bp +++ b/system/osi/test/fuzzers/future/Android.bp @@ -22,6 +22,7 @@ cc_fuzz { static_libs: [ "libbluetooth_log", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libosi", ], } diff --git a/system/osi/test/fuzzers/list/Android.bp b/system/osi/test/fuzzers/list/Android.bp index 5c8f15e81e..bc5dd9a66e 100644 --- a/system/osi/test/fuzzers/list/Android.bp +++ b/system/osi/test/fuzzers/list/Android.bp @@ -18,6 +18,7 @@ cc_fuzz { "libbase", "libbluetooth_log", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "liblog", "libosi", ], diff --git a/system/osi/test/fuzzers/ringbuffer/Android.bp b/system/osi/test/fuzzers/ringbuffer/Android.bp index bbba16690f..08d308c70c 100644 --- a/system/osi/test/fuzzers/ringbuffer/Android.bp +++ b/system/osi/test/fuzzers/ringbuffer/Android.bp @@ -18,6 +18,7 @@ cc_fuzz { "libbase", "libbluetooth_log", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "liblog", "libosi", ], diff --git a/system/profile/avrcp/Android.bp b/system/profile/avrcp/Android.bp index 133d2a4712..8db8f11b2a 100644 --- a/system/profile/avrcp/Android.bp +++ b/system/profile/avrcp/Android.bp @@ -81,6 +81,7 @@ cc_test { "libbluetooth_log", "libbtdevice", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libcutils", "libevent", "libgmock", diff --git a/system/stack/Android.bp b/system/stack/Android.bp index cb987debfc..7cffba529f 100644 --- a/system/stack/Android.bp +++ b/system/stack/Android.bp @@ -833,6 +833,7 @@ cc_test { "libbtif", "libbtif-core", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libflags_rust_cpp_bridge", "libfmq", "libg722codec", @@ -934,6 +935,7 @@ cc_test { "libbt-common", "libbt-platform-protos-lite", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libevent", "libgmock", "liblog", @@ -1023,6 +1025,7 @@ cc_test { "libbt-common", "libbt-platform-protos-lite", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libevent", "libgmock", "liblog", @@ -1158,6 +1161,7 @@ cc_test { "libbt-common", "libbt-platform-protos-lite", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libevent", "libgmock", "liblog", @@ -1229,6 +1233,7 @@ cc_test { "libbluetooth_log", "libbt-common", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libevent", "libgmock", "liblog", @@ -1299,6 +1304,7 @@ cc_test { "libbluetooth_log", "libbt-common", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libevent", "libgmock", "liblog", @@ -1408,6 +1414,7 @@ cc_test { "libbt-sbc-decoder", "libbt-sbc-encoder", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libgmock", "liblog", "libopus", @@ -1459,6 +1466,7 @@ cc_test { "libbluetooth_log", "libbt-common", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "liblog", "libosi", ], @@ -1523,6 +1531,7 @@ cc_test { "libbt-common", "libbt-platform-protos-lite", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libevent", "libgmock", "liblog", @@ -1581,6 +1590,7 @@ cc_test { "libbt-common", "libbt-platform-protos-lite", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libgmock", "liblog", "libosi", @@ -1657,6 +1667,7 @@ cc_test { "libbt-common", "libbt-platform-protos-lite", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libevent", "libgmock", "liblog", @@ -1845,6 +1856,7 @@ cc_test { "libbtdevice", "libbte", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libgmock", "liblog", "libosi", @@ -1904,6 +1916,7 @@ cc_test { "libbtdevice", "libbte", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libevent", "libgmock", "liblog", @@ -1980,6 +1993,7 @@ cc_test { "libbt-platform-protos-lite", "libbtdevice", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libevent", "libgmock", "liblog", @@ -2069,6 +2083,7 @@ cc_test { "libbt-platform-protos-lite", "libbtdevice", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libevent", "libflagtest", "libgmock", @@ -2162,6 +2177,7 @@ cc_test { "libbt-platform-protos-lite", "libbtdevice", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libevent", "libgmock", "liblog", @@ -2256,6 +2272,7 @@ cc_test { "libbt-platform-protos-lite", "libbtdevice", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libcutils", "libevent", "libgmock", diff --git a/system/stack/test/fuzzers/Android.bp b/system/stack/test/fuzzers/Android.bp index 3c74de632d..a0b7947b1e 100644 --- a/system/stack/test/fuzzers/Android.bp +++ b/system/stack/test/fuzzers/Android.bp @@ -61,6 +61,7 @@ cc_defaults { "libbte", "libbtif", "libbtif-core", + "libcom.android.sysprop.bluetooth.wrapped", "libexpresslog", "libflags_rust_cpp_bridge", "libg722codec", diff --git a/system/test/headless/Android.bp b/system/test/headless/Android.bp index 846f9ec4cc..118178199a 100644 --- a/system/test/headless/Android.bp +++ b/system/test/headless/Android.bp @@ -105,6 +105,7 @@ cc_binary { "libbtif", "libbtif-core", "libchrome", + "libcom.android.sysprop.bluetooth.wrapped", "libevent", "libflags_rust_cpp_bridge", "libflatbuffers-cpp", diff --git a/system/types/Android.bp b/system/types/Android.bp index 4bff11709b..4201bafca4 100644 --- a/system/types/Android.bp +++ b/system/types/Android.bp @@ -58,6 +58,7 @@ cc_test { "libbase", "libbluetooth-types", "libbluetooth_log", + "libcom.android.sysprop.bluetooth.wrapped", "libosi", // strlcpy ], test_suites: ["general-tests"], |