summaryrefslogtreecommitdiff
path: root/osi
AgeCommit message (Collapse)AuthorFilesLines
2016-05-25Improve config file sync during configuration save.Jacky Cheung1-8/+57
Add fsync() calls to force sync to disk while saving configuration file. It is necessary to do a sync on the temp file before rename, and to sync again on its parent directory to ensure both the file content and the directory are up-to-date. Bug: 27354612 Change-Id: I3a862ad59c8ae5beb8ea2c727eb5f275a2d5823e (cherry picked from commit 95dbe03a693f4a920204b8c6acbba5269915a59f)
2016-05-13Add config logging, make parsing stricter, and move syncAjay Panicker1-5/+11
The functions that parse the config file will report failure if the config file is improperly formatted or is missing the necessary Adapter section. Also moved sync to sync the filesystem after the config file is saved. Bug: 27354612 Change-Id: Ia75ff628d83bdc933c4bc16761d6c55eef19b757
2016-05-12Restart failed system calls interrupted with errno of EINTRPavlin Radoslavov7-30/+57
In number of places we don't handle properly system calls failures when the errno is EINTR (i.e., the system call was interrupted by a signal). In all our use cases, the system calls should be restarted. The handling of the following system calls (as used in the code) has been updated/fixed: poll, send, recv, sendmsg, nanosleep, epoll_wait read - mostly (e.g., socket-like fds) write - mostly (e.g., socket-like fds) select, accept, connect Bug: 28471477 Bug: 28658141 Change-Id: I03e6f0f67e33876780fb6d02c33eb84547ba8f95
2016-05-04Fixed test_periodic_unregister_processing_queue unit testPavlin Radoslavov1-1/+0
Removed a copy-and-paste check in the test_periodic_unregister_processing_queue unit test. The removed check adds little value - it has time-dependency, and is not robust. Bug: 26982349 Change-Id: I4adb948713b9946b5eb821d6fe52b7ada1400182
2016-05-03Update alarm_unregister_processing_queue() to cancel scheduled alarmsPavlin Radoslavov3-8/+147
Update the alarm_unregister_processing_queue() implementation so it cancels all alarms that are scheduled on the corresponding queue. This fixes a race condition during Bluetooth shutdown: if an alarm expires right after an alarm processing queue is invalidated, the alarm processing would try to use the invalidated queue. Added the corresponding unit tests. Also, added a missing call to alarm_unregister_processing_queue(). Bug: 26982349 Change-Id: I09a111e8080b6dbc354dffa03a487f7a8c578ce6
2016-05-02Fix test_set_zero_periodic unit test failurePavlin Radoslavov1-1/+0
Removed an "EXPECT_EQ(cb_counter, 0)" statement right after a timer of value 0 is scheduled. The EXPECT_EQ statement shouldn't be there, because by the time it is reached, the callback might have been called already. Change-Id: I61fbec96c436787321c6b36006a2bc1c0e627667
2016-04-25Fix a race condition during alarm_cleanup()Pavlin Radoslavov2-4/+6
Fix a race condition inside function alarm_cleanup() that could be triggered during shutdown. Also, fix few other issues: * Add missing "timer_delete(akeup_timer)" statement inside alarm_cleanup() * Fix the argument when calling "timer_delete(timer)" * Call "semaphore_free(alarm_expired)" inside alarm_cleanup() after the corresponding "timer" and "wakeup_timer" have been deleted. * Fix the argument type when calling eventfd_read() inside semaphore_wait() Bug: 26982349 Change-Id: I2b00cd7ee7f56f755775f8e7b370006e31c6eb08
2016-04-23Merge "Fix a Floating point exception for periodic timers" into nyc-devTreeHugger Robot2-2/+22
2016-04-22Fix a Floating point exception for periodic timersPavlin Radoslavov2-2/+22
Fix a Floating point exception for periodic timers that are scheduled with interval of 0ms, and add a corresponding unit test. Also, fix a typo when printing "Action counts" statistics. Bug: 28278593 Change-Id: Ic381efc573ed9954c36980c26a89318d2de40b29
2016-04-22Add missing mutex lock/unlock inside alarm_cleanup()Pavlin Radoslavov1-0/+3
Bug: 26982349 Change-Id: I32f4e6450491adcc1e12e71fb8bb582d6397a91a
2016-04-05Fix memory leak when saving paired devicesMarie Janssen3-4/+5
Followup from r.android.com/210955 Minor style fixes for osi/config also included. Bug: 26071376 Change-Id: I26563b75a59a6f0ae074676754889cb988a69358
2016-04-05btif: Don't persist remote devices to the configMarie Janssen3-0/+45
We don't need to persist the unpaired devices to NVRAM so skip saving them. This fixes a regression in a previous patch where the most recent instead of the least recent devices would be removed, making some devices unpairable in extremely busy environments. Bug: 26071376 Change-Id: If7ee9d960f70c836bf08b78da5f3fc852ba60a85
2016-03-25Don't clear the btsnoop log ringbuffer on compress.Sharvil Nanavati3-15/+17
Change-Id: I0bf4279104e87b151553eba913491d934f3cde41
2016-03-25osi: add osi_rand()Marie Janssen5-0/+100
Provide a replacement for rand() which has a better random source. Change-Id: I38a8c74d86b89ec160b43b0f648f53b463be89bb
2016-03-25Enable debug logs for bluetooth process threads, modulesSrinu Jella1-0/+3
Use case: Debug enhancement for bluetooth threads, modules - Most of the bluetooth process threads,modules uses APIs provided from the OSI layer. - This patch enables the debug logs to know when the thread, module is created and exited. - This would be useful while debugging the ON/OFF, ANR issues. Bug: 27852645 Change-Id: I17f4f583d2c431725a8c44c586b29980b4bdab3f
2016-03-25Move properties get/set code to osiJakub Pawlowski6-3/+136
Currently we use Android-specific property_get and property_set through the code. This patch adds osi_property_get and osi_property_set that is encapsulating all external dependencies. This is step further for errorless compilation on linux. Bug: 27324453 Change-Id: I97c34344617a5855b683328bcd196a21a2fae6f9
2016-03-25Update build files for Fluoride on LinuxJakub Pawlowski1-3/+8
uprev build/secondary/third_party/**/BUILD.gn" Other BUILD.gn files were updated to match current state of project. Change-Id: Ie895d25680d510f5e69e6f15553311f6671cdce3
2016-03-25Add Linux-specific version of metrics.Jakub Pawlowski2-0/+61
This patch adds empty metrics implementation for Linux in order to fix build errors. Bug: 27324453 Change-Id: I2f45db6147689bf295176b7ad30a613a7f5a8d9f
2016-03-23Tell the build system this is a host module.Ying Wang1-0/+1
We need to tell the build system this is a host module before calling local-generated-sources-dir. Change-Id: Ie36ad938c0c7124865148f20fcb70d5187f158b8 (cherry-pick from commit df515a46dd4fe27040c39d35b14b3e071319156d)
2016-03-17Log error code on wakelock acquisition/release failureAndre Eisenbach1-9/+17
Bug: 27721443 Change-Id: I8ac9e738d916bfdcf125e33c0e09f90cc8d26d55
2016-03-14Free allocation tracker hash map entries to reduce memory pressureSrinu Jella1-0/+5
Use case: A2DP playback becomes choppy after long hours of testing. Steps: 1. installed 3rd party app that performs recurring LE scans. 2. Leave phone to run overnight. 3. After 24h+, connect a Bluetooth headset and music is very choppy. Root cause: The memory allocation tracker has support for double free check where it stores all allocations in hash map but it never get removed to track double free issue, A2DP memory allocation is taking more time and leading to choppyness. Fix: Free the hash map entry to avoid memory leak from allocation tracker. Bug: 27621407 Change-Id: If57bd0b89c1d9b99c4f066c537a9e0fa49bc093f
2016-02-24Protect metrics API from race conditionsAjay Panicker1-7/+18
Bug: 27315491 Change-Id: If57f7c23c94890e5f1cf196d2ec7a2a667b48cec
2016-02-24Alarm Dump output cleanupAjay Panicker1-13/+18
Before: Alarm : btm_ble.adv_raddr_timer (SINGLE) Action counts (sched/resched/exec/cancel) : 1 / 0 / 0 / 0 Deviation counts (overdue/premature) : 0 / 0 Time in ms (since creation/interval/remaining) : 17824 / 900000 / 882176 Callback execution time in ms (total/max/ave) : 0 / 0 / 0 Overdue scheduling time in ms (total/max/ave) : 0 / 0 / 0 Premature scheduling time in ms (total/max/ave) : 0 / 0 / 0 After: Alarm : btm_ble.adv_raddr_timer (SINGLE) Action counts (sched/resched/exec/cancel : 1 / 0 / 0 / 0 Deviation counts (overdue/premature) : 0 / 0 Time in ms (since creation/interval/remaining) : 88268 / 900000 / 811732 Callback execution time in ms (total/max/avg) : 0 / 0 / 0 Overdue scheduling time in ms (total/max/avg) : 0 / 0 / 0 Premature scheduling time in ms (total/max/avg): 0 / 0 / 0 Bug: 27294154 Change-Id: I0e318ef570a591626fbc6443feace1cc99c06baf
2016-02-23Make wakelock compile on LinuxJakub Pawlowski1-0/+2
This patch adds some missing header files that prevented wakelocks from compiling on linux. Bug: 27324453 Change-Id: Ifabf3350fe840524cf7e1ec7aa2825acb4399c81
2016-02-18Write Protobuf in Base64Ajay Panicker2-5/+9
Change-Id: I3868365e7fd166517b13ff03a15d629271bd47b4
2016-02-18Add support for collecting A2DP Protobuf metricsPavlin Radoslavov2-5/+69
* Add new function metrics_a2dp_session() to connect A2DP metrics into Protobuf * Add new function btif_update_a2dp_metrics() that is called when the metrics should be callected * Add few more statistics to the BTIF media stats. Change-Id: I5862ac82e55b3546dc1fbde0c78cb4683e40d19e
2016-02-18Fix C/C++ compiler generated warningsPavlin Radoslavov3-41/+41
* Remove unused functions: -Wno-unused-function * Fix logical operations that are missing parentheses: -Wno-logical-not-parentheses, -Wno-parentheses * Add missing braces in initializers: -Wno-missing-braces * Remove unused variables: -Wno-unused-variable * Fix printf()-like formatting issues: -Wno-format * Avoid using unitialized variables: -Wno-maybe-uninitialized, -Wno-uninitialized * Fix a bug inside bta_gattc_get_gatt_db_impl() when the processed GATT DB attribute type is unknown. * Fix warnings about missing field initializers: -Wno-missing-field-initializers * Re-implement macro COMPILE_ASSERT(COND) to fix a compilation warning: -Wno-non-literal-null-conversion * Fix sign mismatch comparison warnings: -Wno-sign-compare * Fix warnings related to enum conversion: -Wno-enum-conversion * Fix warnings related to incompatible pointer types: -Wno-incompatible-pointer-types * Fix warnings related to enum conversion: -Wno-enum-conversion Bug: 26879229 Change-Id: I522931fe156aeab23ae841051a9e25ceab00b1c2
2016-02-18Cleanup C and C++ compiler flagsPavlin Radoslavov1-18/+40
Cleanup the setting of C and C++ compiler flags: * (Almost) all compiler flags are set uniformly in the system/bt/Android.mk file. * Enable by default breaking the compilation if there is a compilation warning: -Werror * Enable most compilation warnings: -Wall -Wextra * Renamed Android.mk related flags: - bdroid_C_INCLUDES -> bluetooth_C_INCLUDES - bdroid_CFLAGS -> bluetooth_CFLAGS * Introduce variables for C-only and C++ only compiler: - bluetooth_CFLAGS: common C and C++ compiler flags - bluetooth_CONLYFLAGS: C only compiler flags - bluetooth_CPPFLAGS: C++ only compiler flags * Disable warnings for existing issues - to be removed as issues are resolved * Add a workaround for libchrome and -DNDEBUG usage. Bug: 26879229 Change-Id: Ie7595965ca0c8ead0e95e983e76c327e7891b2c3
2016-02-18Removed checks for NULL returns after osi_calloc() / osi_malloc()Pavlin Radoslavov13-90/+8
Removed explicit checks for NULL pointer returns after calls to osi_calloc() and osi_malloc(), because those are not needed. If the memory allocation fails, osi_calloc() and osi_malloc() will trigger an assert. Bug: 27048759 Change-Id: I2791eb2f69c08f991f8fcdef10e101a41568cd95
2016-02-18osi: Don't use -std=c99 to compileMarie Janssen1-3/+1
Using -std=c99 to compile breaks when we are using C++ files, which metrics uses for protobufs. Bug: 27077250 Change-Id: Ie94e3ea5d8b219671329108e7795cdc02ecc38b4
2016-02-18Replaced osi_getbuf()/osi_freebuf() with osi_malloc()/osi_free()Pavlin Radoslavov2-54/+0
Removed the alternative buffer allocation osi_getbuf() / osi_freebuf() and use instead osi_malloc() / osi_free(). Correspondingly, replaced usage of osi_freebuf_and_reset() with osi_free_and_reset(). Bug: 24914560 Change-Id: I7a9599ba7fa900321f087da684428133eb0ddd6b
2016-02-18Removed function osi_get_buf_size()Pavlin Radoslavov2-12/+1
Refactored code that uses function osi_get_buf_size(), and removed the need for that function. Bug: 24914560 Change-Id: I0d002635024a9703acb78f47735aafc957a2b761
2016-02-18Add list_back_node method to osi listJakub Pawlowski2-0/+11
Change-Id: I919ce97373701cbdea03b8228b3a90263d7ef180
2016-02-12osi: add metrics APIMarie Janssen5-4/+475
Add a metrics API, which supports creating events which are eventually passed up to the clearcut logging to track pairings and other events. Connect this to the dumpsys call when it is called. Change-Id: Idcf75541fd18b0413cc843d6c7e23a5f08a634a5
2016-02-04Refactor usage of osi_free() and osi_freebuf()Pavlin Radoslavov4-14/+38
* Allow to call osi_freebuf(ptr) on NULL pointers. This simplifies the code: a notable number of "if (foo != NULL)" checks are removed. * Add new function osi_free_and_reset(p_ptr) that frees the buffer, and explicitly resets the pointer to NULL. This prevents unintended usage of free memory. * Add corresponding function osi_freebuf_and_reset(p_ptr) * Minor cleanup around usages of osi_free() and osi_freebuf() Also: * Removed unused function btif_gattc_cleanup() * Replaced usage of the following functions with osi_freebuf_and_reset() - mca_free_buf() - utl_freebuf() - btif_hl_free_buf() * Replaced usage of rc_supported_event_free() with osi_freebuf() * Replaced usage of btif_hl_get_buf() with osi_getbuf() * Eliminate some of the osi_get_buf_size() calls Bug: 22948224 Change-Id: Ife860658b26274da6f228d7353cb0f1531587337
2016-02-04osi: add native wakelocks to metricsMarie Janssen1-32/+31
Metrics were only being counted for callout wakelocks. Move metrics collection to the wrapping functions to account more centrally. Change-Id: I772198c3ae05bcb83965420931ddee87b1996b6b
2016-02-01Make list_foreach() even more usefulJakub Pawlowski3-14/+20
- Changed |callback| return type to list_node_t to be able to interrupt iteration (to find specific elements for example). Change-Id: I00eb83725d03e6f1aec239ae11eb19cf59af35a9
2016-01-27Allow alarm_cancel() on NULL timersPavlin Radoslavov1-1/+2
Remove an assert that prevents using alarm_cancel() with NULL timers. Bug: 26831803 Change-Id: Ifd1476272b13a3f7fd5a0dbb57ee867cbfe2c2bb
2016-01-22Add extra log if timer_create(CLOCK_BOOTTIME_ALARM) failsPavlin Radoslavov1-0/+4
Add explicit log messages if timer_create(CLOCK_BOOTTIME_ALARM) fails. The most likely reason is the kernel doesn't have the appropriate patches. Bug: 25739638 Change-Id: Icbeaa965d729ba11dfb7cfbb6185b1655b3c6de4
2016-01-22A workaround for kernels missing CLOCK_BOOTTIME_ALARMPavlin Radoslavov2-2/+11
If the kernel doesn't have support for CLOCK_BOOTTIME_ALARM, then timer_create(CLOCK_BOOTTIME_ALARM) will fail. Added #ifdef KERNEL_MISSING_CLOCK_BOOTTIME_ALARM guard to get around the issue. Platforms that don't have CLOCK_BOOTTIME_ALARM should have the following lines in the device's "bdroid_buildcfg.h" file: /* Defined if the kernel does not have support for CLOCK_BOOTTIME_ALARM */ #define KERNEL_MISSING_CLOCK_BOOTTIME_ALARM TRUE Bug: 26611369 Change-Id: I455dbbc20f43b21a83998cd60cac8dea0a73080d
2016-01-21Refactor the Bluetooth timersPavlin Radoslavov9-266/+556
* Updated the alarm API: - Existing API alarm_new() is modified to take an alarm name as an argument. - New API alarm_new_periodic() is used to create a periodic alarm. - Added new API alarm_is_scheduled() to test whether an alarm is scheduled. - Existing API alarm_set_periodic() is removed: a periodic alarm is created by alarm_new_periodic(). - Added new API alarm_set_on_queue() to set an alarm whose callback is executed on a specific queue. - Added new API alarm_register_processing_queue() and alarm_unregister_processing_queue() to register/unregister a queue and the corresponding thread for alarm processing. - Added corresponding unit tests. * Updated the alarm internals: - Added alarm_info_t for collecting alarm-related information and statistics. - Collect and store alarm-related statistics into alarm_info_t per alarm. - Include the alarm-related statistics and info into the native dumpsys output for Bluetooth. - Once an alarm expires, the alarm execution is scheduled for processing on another internal alarm-specific thread, not on the thread that is maintaining the alarms. - Implemented callback execution ordering guarantee among timers on the same thread with exactly same timeout values. * Refactor some of the usage of alarm_set() and simplify the code by using alarm_set_on_queue() instead. * Removed the non_repeating timers wrapper, and use directly the alarm mechanism / API. * Refactored all timer_entry_t timers and replaced them with alarm_t timers: - Replaced the btu_start_timer() / btu_stop_timer() / btu_start_quick_timer() / btu_stop_quick_timer() / btu_oneshot_alarm() mechanism with alarm_set_on_queue() and alarm_cancel() - Removed the whole mechanism around the BTU_TTYPE_* timers. * Fixed a bug when processing the GATT indication confirmation timer expiration (timer tGATT_TCB.conf_timer: b/26610829). * Renamed and/or split misc. timeout functions, fields, and timers * Renamed time-related constants and changed the values from seconds to milliseconds * Replaced timer tAVDT_CCB.timer_entry with three mutually exclusive timers: idle_ccb_timer, ret_ccb_timer, rsp_ccb_timer The reason we are using three timers, is because in the original code function avdt_ccb_chk_timer() used the timer type in its logic: it would stop the timer only if the type is "idle". * Removed btm_ble_timeout() and replaced it with multiple timeout callback functions (per timer) * Fix the actual value of the global constant BT_1SEC_TIMEOUT and rename it to BT_1SEC_TIMEOUT_MS * Removed btu_cb and associated timers and events, because they are never used. * Removed unused timers, functions, struct and declarations that are not used / needed. Bug: 26611369 Bug: 26610829 Change-Id: I812c8c31710a5daefc58b01fcf35c353768f390f
2016-01-21Add support for native kernel and callout wakelocksPavlin Radoslavov6-120/+447
* Moved wakelock-related code to osi/src/wakelock.c The API is in osi/include/wakelock.h * Use wakelock_set_os_callouts() to specify native kernel or callout-based wakelock. On Android, wakelock_set_os_callouts() is called to set the bt_os_callouts_t callbacks into the Java layer. * Renamed alarm_set_wake_lock_paths() to wakelock_set_paths() Also, added Bluetooth Wakelock Statistics to the bugreport. Sample output: $ adb shell dumpsys bluetooth_manager ... Bluetooth Wakelock Statistics: Wakelock is acquired : false Wakelock acquired/released count : 5 / 5 Wakelock acquired/released errors : 0 / 0 Wakelock last acquired time (ms) : 1524 Wakelock acquired time min/max/avg (ms) : 1511 / 8104 / 3167 Wakelock total acquired time (ms) : 15836 Bluetooth total run time (ms) : 44123 Bug: 26645431 Change-Id: I42bfb7db5b016719faea39e47ebc77c3ad02467b
2016-01-15Make list_foreach() more usefulAndre Eisenbach3-5/+77
- Changed |callback| return type to bool to be able to interrupt iteration (to find specific elements for example). - Added new |extra| parameter for |callback| so a pointer can be passed in to receive output values or to pass in criteria etc. - Also added unit tests. Change-Id: Id1ddcbabf55292f701d0277f2a1e9ec261b9fbde
2016-01-11Assert on memory allocation failureAndre Eisenbach1-10/+12
This CL is a pre-cursor to cleaning up repeated memory allocation code full of null-pointer checks. In the vast majority of cases in the Bluetooth stack, a failed allocation is not recoverable and results in undefined behaviour. By asserting, we can ensure we have a shot at catching and fixing any issues not caused by OOM conditions. Bug: 26494317 Change-Id: I53dff98c596068211934a1808f90de2d4484f952
2015-12-29Fix flaky AlarmTest.test_set_long_*Marie Janssen1-3/+3
The "long" tests need some leeway for the timer to be checked because sometimes it takes ~1-2ms to check timers for wakelock scheduling. Bug: 26140385 Change-Id: I362166f1d93a811f3933776294775b594226ab30
2015-12-22Remove "block" parameter from eager_reader_read()Andre Eisenbach3-9/+7
Setting this parameter to true did not work and did not behave as expected. The functionality provided by this parameter is also not necessary, thus removing code. Change-Id: I29e60da4adf1d1fc84d8ec9a590de89e94bb7900
2015-12-22Properly reset NONBLOCK flag in semaphore_try_wait()Andre Eisenbach4-4/+92
Without this fix, calling semaphore_try_wait() on a semaphore that wasn't currently set, would leave the NONBLOCK flag on the file descriptor as a side-effect. Also added a unit test for semaphores, including a test specifically for this condition. Change-Id: I0ea37bb68b14c76febaab25b3aee1bb4f5acee8c
2015-12-10Fix the fixed_queue_try_remove_from_queue() internalsPavlin Radoslavov4-41/+324
Calling fixed_queue_try_remove_from_queue() should update queue->dequeue_sem and queue->enqueue_sem as appropriate. Also: * Removed function fixed_queue_init() because it is not used * Added fixed_queue_test.cpp unit tests for fixed_queue * Updated some of the fixed_queue API description Bug: 25973053 Change-Id: I3a0931f34fed34a2d60f82904601ef4157ee8ff9
2015-12-09osi: Remove error_fclose goto and redundant fflush.Alain Vongsouvanh1-11/+7
Change-Id: I327f9ce696bb68eb3b89b4a8b15dba189e027970
2015-12-02tests: don't use bt_os_callouts for wakelocksMarie Janssen6-53/+136
Introduces alarm_set_wake_lock_paths so wake lock paths can be changed for testing, and adds AlarmTestHarness::WakeLockHeld to test whether a wake lock is currently held. Bug: 25387683 Change-Id: I9a41ae8266e252a3d436f8d41ea3f9e7ecb45cdc