OSDN Git Service

android-x86/system-bt.git
7 years agoFix stack crash after bonding
Jakub Pawlowski [Wed, 22 Feb 2017 18:34:45 +0000 (10:34 -0800)]
Fix stack crash after bonding

delayed_auth_timer_ent was freed and re-created during it's execution.
Instead of re-creating, just cancel the timers in smp_cb_cleanup.

Test: manual, bond with HID device on linux
Bug: 34083285
Change-Id: Ie569666846db5dcb2466cff00665b2c1490d7d10

7 years agoUse email address in OWNERS files.
Chih-Hung Hsieh [Tue, 21 Feb 2017 21:48:52 +0000 (13:48 -0800)]
Use email address in OWNERS files.

Bug: 33166666
Test: default build targets
Change-Id: Id2b579215291cb1f6ae03ebc167f07bd59713dc4

7 years agoLinux build fix
Jakub Pawlowski [Mon, 20 Feb 2017 19:15:32 +0000 (20:15 +0100)]
Linux build fix

Test: build on linux
Change-Id: I21d613fb3e914949d3e8e8fcdae60e620e685394

7 years agoCompile audio codec libraries on linux
Jakub Pawlowski [Mon, 20 Feb 2017 19:18:51 +0000 (20:18 +0100)]
Compile audio codec libraries on linux

Test: build on linux
Change-Id: I72c7621fde1f229e3dd2a8cfa0cf0339e601914c

7 years agoMerge changes from topic 'ble_scanner_callbacks'
Jakub Pawlowski [Tue, 21 Feb 2017 18:03:40 +0000 (18:03 +0000)]
Merge changes from topic 'ble_scanner_callbacks'

* changes:
  Use base::Callbacks in BleScannerInterface (2/3)
  Remove unnecessary extern declarations

7 years agoMerge "Clean up some more #defines"
Treehugger Robot [Tue, 21 Feb 2017 16:09:14 +0000 (16:09 +0000)]
Merge "Clean up some more #defines"

7 years agoUse base::Callbacks in BleScannerInterface (2/3)
Jakub Pawlowski [Thu, 16 Feb 2017 19:56:56 +0000 (11:56 -0800)]
Use base::Callbacks in BleScannerInterface (2/3)

The remaining four native callbacks need more internal refactoring
before they can be turned into a callbacks.

Bug: 30622771
Test: sl4a FilteringTest

Change-Id: I8e1532bdfa2b0f22545f095eb427fd5ac1a75b56

7 years agoRemove unnecessary extern declarations
Jakub Pawlowski [Fri, 17 Feb 2017 22:20:40 +0000 (14:20 -0800)]
Remove unnecessary extern declarations

Test: manual
Change-Id: I21bdb5952fff359a9ee7091d740ecac13aad640a

7 years agoFix SIGBUS error in BT stack when pairing with ARM boards
Pulkit Bhuwalka [Sat, 18 Feb 2017 00:25:22 +0000 (16:25 -0800)]
Fix SIGBUS error in BT stack when pairing with ARM boards

This CL fixes the actual crash location on pairing within the code.
https://android-review.googlesource.com/#/c/338167/ fixed the macro.

Bug:35154933
Test: Verified by building and pairing with RPI3/NXP Arm boards.

Change-Id: Ic35f446e53aa724ecab72801b7f89c70fd11ba62

7 years agoThread switching simplification
Jakub Pawlowski [Fri, 17 Feb 2017 20:18:59 +0000 (12:18 -0800)]
Thread switching simplification

* add jni_thread_wrapper
* add FROM_HERE parameter to do_in_jni_thread, this will be used in
later patches to make thread switching logs nice.

Bug: 30622771
Test: manual
Change-Id: I4c8f9e0f32c501a6126fe04f2476ab6453fe637e

7 years agoCheck the return value of the HAL init function
Myles Watson [Fri, 17 Feb 2017 16:30:18 +0000 (08:30 -0800)]
Check the return value of the HAL init function

If the HAL can be opened, but initialization fails, Bluetooth
can not start.

Test: Force an initialization failure, BT dies
Change-Id: I7dd5ed49c9e7873a666dc001e68bdc13660648ba

7 years agoClean up some more #defines
Myles Watson [Thu, 9 Feb 2017 17:38:07 +0000 (09:38 -0800)]
Clean up some more #defines

true -> TRUE
false -> FALSE

Test: builds
Change-Id: I2573b6ab81aa384cc6d20bb8beb84303aba06a66

7 years agoFix HDP select thread id type
Andre Eisenbach [Fri, 17 Feb 2017 02:38:25 +0000 (18:38 -0800)]
Fix HDP select thread id type

Recent changes in libbionic cause pthread_join to SIGABRT if called with
an invalid thread id. The select_thread_id variable in the HDP
sub-system was truncated from long->int causing pthread_join to not find
the correct thread and triggering the error.

Using the correct type for select_thread_id fixes this problem.

Change-Id: Id332fa86cf7f30abd211588d32899d41e157b462
Fixes: 35432169
Test: manual; boot device, turn BT off; ensure it stays off

7 years agoMerge "Add a mutex to guard all btsnoop operations"
Treehugger Robot [Thu, 16 Feb 2017 22:14:23 +0000 (22:14 +0000)]
Merge "Add a mutex to guard all btsnoop operations"

7 years agoMerge changes Idcbbc7eb,I3dc48800
Jakub Pawlowski [Thu, 16 Feb 2017 20:09:52 +0000 (20:09 +0000)]
Merge changes Idcbbc7eb,I3dc48800

* changes:
  Use LE Extended Create Connection when possible
  Add LE Extended Create Connection HCI command

7 years agoAdd a mutex to guard all btsnoop operations
Pavlin Radoslavov [Thu, 16 Feb 2017 19:51:48 +0000 (11:51 -0800)]
Add a mutex to guard all btsnoop operations

After switching to HIDL, capture() can be called by multiple threads.
Capturing a packet and writing to the btsnoop/btsnooz logs
require multiple operations, hence we need a mutex to make those
operations atomic.
Previously, there were occasional btsnoop_hci.log files
with corrupted data as reported by Wireshark.

Test: Manual - captured multiple btsnoops_hci.log files.
Change-Id: Ib89d9156ad7e27a7dee652f71a0cf38c85d4447c

7 years agoUse LE Extended Create Connection when possible
Jakub Pawlowski [Thu, 16 Feb 2017 15:12:22 +0000 (07:12 -0800)]
Use LE Extended Create Connection when possible

Bug: 30622771
Test: manual
Change-Id: Idcbbc7eb6f9b32b2f258d6f8913ead6986510da8

7 years agoAdd LE Extended Create Connection HCI command
Jakub Pawlowski [Wed, 15 Feb 2017 16:35:30 +0000 (08:35 -0800)]
Add LE Extended Create Connection HCI command

Bug: 30622771
Test: manual
Change-Id: I3dc48800bd2dfb2f00c824c89888c9f4e8271497

7 years agoFix advertise data parsing
Jakub Pawlowski [Thu, 16 Feb 2017 17:23:48 +0000 (09:23 -0800)]
Fix advertise data parsing

This patch fixes overflow of position variable, and possible read
outside of vector boundaries when parsing advertise data.

Parsing 1004 bytes of hex "112233112233.." was causing infinite loop.

Bug: 30622771
Test: manual
Change-Id: I0d669f7958de73f5d53350fb293ff27fea172f44

7 years agoHID: Fix scroll issue with Apple Magic Mouse
Hemant Gupta [Tue, 25 Oct 2016 19:17:57 +0000 (12:17 -0700)]
HID: Fix scroll issue with Apple Magic Mouse

Usecase
1) Pair and connect with Apple Magic Mouse
2) Scroll over HID mouse and see if pointer moves up or down
   on DUT.

Observation:
Scroll functionality does not work on DUT and mouse pointer
stays still.

Root Cause:
From kernel 3.18 onwards, UHID flags are updated and following new
flags are added. Support for handling same is missing in user
space hid driver (bta_hh_co.cc)
UHID_GET_REPORT
UHID_GET_REPORT_REPLY
UHID_SET_REPORT
UHID_SET_REPORT_REPLY

Fix:
Add support for set report and get report in HID user
space because of changes in uhid kernel driver with kernel changes
for kernel 3.18. Apple Magic Mouse scroll functionality does not
work without this fix, as Apple Mouse requires set report from
HID host for it to start working properly wrt Scroll functionality.

Bug: 35306202
Change-Id: I90230b76d68e9275dcacd9f46f03e312ddf2fa30

7 years agoAdd a missing NULL pointer check inside bta_av_rcfg_str_ok()
Pavlin Radoslavov [Wed, 15 Feb 2017 01:38:19 +0000 (17:38 -0800)]
Add a missing NULL pointer check inside bta_av_rcfg_str_ok()

Apparently, the p_data argument could be NULL if the reconfig
was triggered by the local device.

Test: Tested with Bluetooth headsets
Bug: 35351216
Change-Id: Ic51d849232944b5978772d222c41f66824e14dd4

7 years agoMerge "Fix SIGBUS error in BT stack when pairing with ARM boards"
Treehugger Robot [Wed, 15 Feb 2017 01:39:00 +0000 (01:39 +0000)]
Merge "Fix SIGBUS error in BT stack when pairing with ARM boards"

7 years agoFix SIGBUS error in BT stack when pairing with ARM boards
Pulkit Bhuwalka [Tue, 14 Feb 2017 01:44:47 +0000 (17:44 -0800)]
Fix SIGBUS error in BT stack when pairing with ARM boards

Bluetooth stack crashes with a SIGBUS memory unaligned error since the
toolchain optimizes memcpy to generate register instructions which are
unaligned in memory. Similar issue was seen earlier in
https://android-review.googlesource.com/#/c/181713/
which was solved by casting pointers to (void *). That fix misses edge
cases where the destination pointer needs to be casted as well.

Change-Id: I23cc16142deaf3dc1fff91588d736abdfcb3bfde
Fixes: 35154933
Test: Verified by building and pairing with RPI3/NXP Arm boards.

7 years agoUpdate the A2DP MTU if the L2CAP MTU changes during codec reconfiguration
Pavlin Radoslavov [Tue, 14 Feb 2017 20:18:44 +0000 (12:18 -0800)]
Update the A2DP MTU if the L2CAP MTU changes during codec reconfiguration

Previously, the MTU was saved inside the AVDTP module after the first
codec setup. However, the MTU wasn't updated after codec reconfiguration.
As a result, if a Sink device uses different (smaller) MTU for
a codec like SBC, then switching fron another codec to SBC will
result in generating SBC frames that are too large to transmit,
and there will be no audio.

Bug: b/35351216
Test: A2DP streaming and codec switch to various Sink devices.
Change-Id: Ieb3caf4ef7a30a7af31ceb2f6132807739829441

7 years agoMerge "Lower the BLE connection supervision timeout to 5s."
Treehugger Robot [Tue, 14 Feb 2017 02:26:15 +0000 (02:26 +0000)]
Merge "Lower the BLE connection supervision timeout to 5s."

7 years agoMerge "Change LE advertisement data length type (uint8_t -> uint16_t)"
Jakub Pawlowski [Tue, 14 Feb 2017 01:34:29 +0000 (01:34 +0000)]
Merge "Change LE advertisement data length type (uint8_t -> uint16_t)"

7 years agoFix comment formatting at the beginning of lines
Myles Watson [Thu, 9 Feb 2017 22:16:52 +0000 (14:16 -0800)]
Fix comment formatting at the beginning of lines

Test: builds
Change-Id: I691a40ad37b0cbe3ce56a09dc986df8857883b23

7 years agoLower the BLE connection supervision timeout to 5s.
Qasim Javed [Mon, 6 Feb 2017 20:16:09 +0000 (12:16 -0800)]
Lower the BLE connection supervision timeout to 5s.

The current default of 20 seconds is too high especially considering
that BLE tries to optimize (re)connection times. A connection
supervision timeout of 20 seconds essentially means that an initiator
of the connection could be in the connecting state for 20 seconds
before giving up on that connection attempt.

Checking other platforms such as iOS for default connection supervision
timeout reveals that they use sub-second (750ms) values.

Change-Id: I6ff7a20ceab0df8986191dd73676cadbe23a175e

7 years agoChange LE advertisement data length type (uint8_t -> uint16_t)
Jakub Pawlowski [Mon, 13 Feb 2017 22:31:52 +0000 (14:31 -0800)]
Change LE advertisement data length type (uint8_t -> uint16_t)

Chained advertisement data can be up to 1650 bytes.

Test: manual
Bug: 30622771
Change-Id: I67af5a8130ac2d3f0dbd8f5e3f28b72b152256c2

7 years agobtif: remove logspam at higher debug levels
Marie Janssen [Wed, 1 Feb 2017 20:50:00 +0000 (12:50 -0800)]
btif: remove logspam at higher debug levels

Some CHECK macros had logs that printed the function name, which
duplicated the logs in the functions outside the checks, producing too
many logs.

Remove some unused macros.

Changes:
02-01 09:34:11.757  1259  1755 D bt_btif : get_folder_items_list_rsp
02-01 09:34:11.757  1259  1755 D bt_btif : get_folder_items_list_rsp: item_cnt: 0 len: 0
to
02-01 09:34:11.757  1259  1755 D bt_btif : get_folder_items_list_rsp: item_cnt: 0 len: 0

and similar.

Test: run logcat, check that we have less duplicated logs
Change-Id: Id6e57f38b34d176ed8be0c3baedfbcf55e61a9a4

7 years agoAllow back-to-back AVDTP API_RECONFIG_EVT events
Pavlin Radoslavov [Sat, 11 Feb 2017 09:20:49 +0000 (01:20 -0800)]
Allow back-to-back AVDTP API_RECONFIG_EVT events

Based on AVDTP Spec 1.3, Section 9.8 StreamChangeParameters, the RECONFIG
procedure (AVDTP_RECONFIGURE_CMD) happens in OPEN state, and there is no
state transition that would prohibit calling the RECONFIG procedure
back-to-back.

Test: A2DP codec reconfiguration and audio play with several Sink devices
Bug: 35284763
Change-Id: Ie4ddca8545e2146fbd863e55713fd2d49994b4b0

7 years agoMerge "osi: Remove unused eager_reader code"
Treehugger Robot [Sat, 11 Feb 2017 04:09:44 +0000 (04:09 +0000)]
Merge "osi: Remove unused eager_reader code"

7 years agoGet rid of btm_ble_send_extended_scan_params
Jakub Pawlowski [Fri, 10 Feb 2017 23:24:00 +0000 (15:24 -0800)]
Get rid of btm_ble_send_extended_scan_params

Bug: 30622771
Test: sl4a FilteringTest
Change-Id: I94e62ca0d785b20f97e3397131b70eac06e15003

7 years agoFix set extended scan params command
Jakub Pawlowski [Fri, 10 Feb 2017 23:17:52 +0000 (15:17 -0800)]
Fix set extended scan params command

scanning_phys is a bitmap, not a count of PHYs. This error was resulting
in invalid HCI command being sent. This had no impact so far, because
only 1M PHY was used.

Bug: 30622771
Test: manual
Change-Id: I2be4f5ddbe0d453dc49cdee4605821b10853d7d8

7 years agoAdd Service Data GAP EIR data type
Bailey Forrest [Fri, 10 Feb 2017 00:49:15 +0000 (16:49 -0800)]
Add Service Data GAP EIR data type

Test: Build
Change-Id: I378883fdeb09fadaac04ace2dc499abd27b7d3ab

7 years agoMerge "Minor fixes"
Treehugger Robot [Fri, 10 Feb 2017 13:48:38 +0000 (13:48 +0000)]
Merge "Minor fixes"

7 years agoMerge "Advertising data handling improvements"
Jakub Pawlowski [Fri, 10 Feb 2017 05:41:05 +0000 (05:41 +0000)]
Merge "Advertising data handling improvements"

7 years agoMerge "Enable DLOG on eng and userdebug builds"
Treehugger Robot [Fri, 10 Feb 2017 03:15:25 +0000 (03:15 +0000)]
Merge "Enable DLOG on eng and userdebug builds"

7 years agoMinor fixes
Bailey Forrest [Fri, 10 Feb 2017 01:26:28 +0000 (17:26 -0800)]
Minor fixes

- Include <mutex> for heart_rate_server
- Remove unnecessary assignment

Test: Build
Change-Id: Ic2368d08789b95e71c083460148c70b9d0ef0b20

7 years agoAdvertising data handling improvements
Jakub Pawlowski [Tue, 7 Feb 2017 20:15:06 +0000 (12:15 -0800)]
Advertising data handling improvements

* use non-hardcoded advertise data size
* use cache for keeping non-complete advertising data, waiting either
for scan scan response, or secondary channel data.

Bug: 30622771
Test: sl4a FilteringTest
Change-Id: I689edcb4aee30361df15340029559cd19dac552b

7 years agoMerge "Remove build variables that are no longer used"
Treehugger Robot [Fri, 10 Feb 2017 00:53:23 +0000 (00:53 +0000)]
Merge "Remove build variables that are no longer used"

7 years agoEnable DLOG on eng and userdebug builds
Jakub Pawlowski [Fri, 10 Feb 2017 00:46:45 +0000 (16:46 -0800)]
Enable DLOG on eng and userdebug builds

Test: manual
Change-Id: I1ff4ad6b2543246351d4d34919ba443e5617a9c0

7 years agoUse same timestamp for on-disk BT Snoop Log and in-memory BT Snooz Log
Jack He [Wed, 8 Feb 2017 01:25:15 +0000 (17:25 -0800)]
Use same timestamp for on-disk BT Snoop Log and in-memory BT Snooz Log

* Logcat uses gettimeofday for its timestamp, the same as on-disk BT
  Snoop log
* Although in-memory BT Snooz Log uses the same method to get time, it
  is calling it separately, resulting in mismatch between timestamps of
  two snoop logs
* This CL let them uses the same timestamp_us value and put the function
  definition to libosi
* Note that preserved on-disk BT Snoop logs timestamp postfix at
      btsnoop_hci_<timestamp>.log
  will be changed to microsecond since epoch at current device timezone
  instead of the shifted BT Snoop timestamp value
* New unit tests for gettimeofday

Bug: 35113514
Test: Make, unit tests, run BT activities and check both snoop logs
Change-Id: I5b3f87bc523b272ced2c69a4595d0e0cbe29bcb3

7 years agoMerge "Guard btsnooz ringbuffer access from multiple threads"
Pavlin Radoslavov [Thu, 9 Feb 2017 22:35:05 +0000 (22:35 +0000)]
Merge "Guard btsnooz ringbuffer access from multiple threads"

7 years agoRemove build variables that are no longer used
Jack He [Thu, 9 Feb 2017 22:29:59 +0000 (14:29 -0800)]
Remove build variables that are no longer used

* Removed BtHcilpIncluded from BOARD_BLUETOOTH_BDROID_HCILP_INCLUDE
* Removed BtHciUseMct from BLUETOOTH_HCI_USE_MCT

Bug: 3520365334951912
Test: Code compilation, no user visible effects
Change-Id: Ifbb0c2165a2b7cb6ec1d5c87a610219dd010206b

7 years agoFix AAC bitrate computation and add missing parameters
Kenmochi, Chisato [Thu, 9 Feb 2017 20:23:47 +0000 (12:23 -0800)]
Fix AAC bitrate computation and add missing parameters

* Compute the AAC codec bitrate based on the MTU and the AAC
  object type such that the AAC frames are not fragmented.
  The spec recommendation is to avoid fragmentation, and
  some sink devices cannot process fragmented frames.

* Setup/assign AACENC_PEAK_BITRATE as the peak bitrate to
  make sure we never go over the MTU frame size.

* Add missing AAC parameter setup for AACENC_AUDIOMUXVER
  and AACENC_SIGNALING_MODE

* Add a fix for selecting the bitrate if the sink device reports
  capability with zero bitrate - for such devices we negotiate
  our bitrate. For the actual AAC codec bitrate we still compute
  it based on the MTU and the AAC object type.

Test: Tested with numerous AAC sink devices
Bug: 34953385
Change-Id: I9ca6353b0e1ee107f1242803de4e82d568a3394b

7 years agoGuard btsnooz ringbuffer access from multiple threads
Andre Eisenbach [Thu, 9 Feb 2017 19:44:04 +0000 (11:44 -0800)]
Guard btsnooz ringbuffer access from multiple threads

Since moving to HIDL, the btsnooz packet ringbuffer can be accessed from
two separate threads. Thus it should be guarded from concurrent access
to avoid pointer corruption.

Bug: 35182804
Test: manual
Change-Id: I3e6e1a869887a7ad5d87d8bb09ed78a22b3383ae

7 years agoosi: Remove unused eager_reader code
Myles Watson [Wed, 8 Feb 2017 23:50:16 +0000 (15:50 -0800)]
osi: Remove unused eager_reader code

Test: Builds
Change-Id: Id5c7a8b9ca59ec90c3d2d0d4935f3f5ff287c433

7 years agoMerge "Use CHECK() to verify that HIDL is installed"
Treehugger Robot [Wed, 8 Feb 2017 14:00:07 +0000 (14:00 +0000)]
Merge "Use CHECK() to verify that HIDL is installed"

7 years agoMerge "Fix the implementation of htonll()"
Treehugger Robot [Wed, 8 Feb 2017 10:50:04 +0000 (10:50 +0000)]
Merge "Fix the implementation of htonll()"

7 years agoFix the implementation of htonll()
Pavlin Radoslavov [Tue, 7 Feb 2017 02:48:18 +0000 (18:48 -0800)]
Fix the implementation of htonll()

Prior the fix, all btsnoop entries had same timestamp.

Bug: 35111777
Test: Examine the btsnoop log file with Wireshark
Change-Id: I9e664475ff5b4ffc543d95b90a47c7f80fdc0370

7 years agoMerge "AVRCT CT: uint8_t is used for 2byte field"
Sanket Agarwal [Tue, 7 Feb 2017 21:49:00 +0000 (21:49 +0000)]
Merge "AVRCT CT: uint8_t is used for 2byte field"

7 years agoUse CHECK() to verify that HIDL is installed
Myles Watson [Tue, 7 Feb 2017 13:14:06 +0000 (05:14 -0800)]
Use CHECK() to verify that HIDL is installed

Test: build, boot test on angler
Change-Id: Ia64dcceedc233ef494ab0fdce7ee649e74fa45a0

7 years agoHF Client: SCO routing with multiple devices
Sanket Agarwal [Tue, 31 Jan 2017 21:43:58 +0000 (13:43 -0800)]
HF Client: SCO routing with multiple devices

For SCO it makes sense only to have one active connection at a time for
any device since simultaneous SCO calls in a single device is
un-reasonable. This change changes the SCO state machine in following
ways:
a) SCO is not setup automatically whenever AG wants, the client for this
BTA layer will have to call connect_audio to start SCO
b) Also when we disconnect SCO for a device, it does not go into a
listen state. We are making sure that the upper layer caller always has
to call connect to accept a connection

Bug: b/34518638
Test: Manual testing w/ multiple active calls and SCO switching

Change-Id: I6e6c4c6e6ee19e44e3ff14499fb99083102bde5a

7 years agoAVRCT CT: uint8_t is used for 2byte field
Sanket Agarwal [Tue, 7 Feb 2017 01:56:29 +0000 (17:56 -0800)]
AVRCT CT: uint8_t is used for 2byte field

This causes the upper stack to report incorrect entries if the value is
large

Bug: b/34682784
Test: Check with a list > 4 items large and packet size big enough to
exceed uint8_t size

Change-Id: I73233a74378d9c091e33f204780a9492505d99b4

7 years agoMerge changes from topic 'bt5_scan_props'
Jakub Pawlowski [Tue, 7 Feb 2017 01:29:25 +0000 (01:29 +0000)]
Merge changes from topic 'bt5_scan_props'

* changes:
  Propagate BT5 specific scan result properties up the stack (2/3)
  Use new event type in BLE scan

7 years agoPropagate BT5 specific scan result properties up the stack (2/3)
Jakub Pawlowski [Fri, 27 Jan 2017 16:06:20 +0000 (08:06 -0800)]
Propagate BT5 specific scan result properties up the stack (2/3)

Bug: 30622771
Test: sl4a FilteringTest
Change-Id: Ib9d18ea3a1fc7d95300415a04b551d66767b04d2

7 years agoUse new event type in BLE scan
Jakub Pawlowski [Fri, 27 Jan 2017 13:53:07 +0000 (05:53 -0800)]
Use new event type in BLE scan

Right now new event_type in scan result is translated to legacy
one and used through whole stack. This patch make use of new event_type
through whole stack instead.

Bug: 30622771
Test: sl4a FilteringTest
Change-Id: I7420c040b8c54fae00262c939bcabc6c6fcb16e6

7 years agoAdd a mechanism to configure the default A2DP codec priorities
Pavlin Radoslavov [Wed, 1 Feb 2017 04:51:06 +0000 (20:51 -0800)]
Add a mechanism to configure the default A2DP codec priorities

Previously, the relative codec priorities were hard-codec internally.
The new mechanism uses the following configurable resources in
packages/apps/Bluetooth/res/values/config.xml to re-assign the
default codec priorities per device, or to explicitly disable a codec.

 - a2dp_source_codec_priority_sbc
 - a2dp_source_codec_priority_aac
 - a2dp_source_codec_priority_aptx
 - a2dp_source_codec_priority_aptx_hd
 - a2dp_source_codec_priority_ldac

Those values are assigned on startup.
Also, they can be changed per device by using an overlay:
device/<VENDOR>/<DEVICE>/overlay/packages/apps/Bluetooth/res/values/config.xml

Test: Manually streaming to a headset
Change-Id: I5312299aea4a11c92fbe999d521adb39346b9866

7 years agoBLE Advertising Manager test improvements
Jakub Pawlowski [Wed, 25 Jan 2017 11:06:49 +0000 (03:06 -0800)]
BLE Advertising Manager test improvements

This patch moves mock verification before call to callback. If for any
reason the callback is not properly initialized, this is usually due to
fact that the call didn't reach the mock. Right now in such cases we get
a crash and stack trace. After this patch we will first get information
about the mock not being called properly, then the crash, which would
make debugging such issues much easier.

Bug: 30622771
Test: manual test
Change-Id: Ia182f2eed384924395e8d6b6a2d3d0abd393a4ee

7 years agoTemporarily disable WBS; to be replaced with eSCO
Andre Eisenbach [Fri, 3 Feb 2017 22:37:44 +0000 (14:37 -0800)]
Temporarily disable WBS; to be replaced with eSCO

HIDL'ized vendor library does not support custom audio parameter
configuration currently. To be replaced with eSCO commands.

Test: manual
Change-Id: I64850a7cbc6a05376f60f669fe43c3955cfcc08c

7 years agoFix a memory leak in the osi allocation tracker
Pavlin Radoslavov [Fri, 3 Feb 2017 03:47:16 +0000 (19:47 -0800)]
Fix a memory leak in the osi allocation tracker

Add a missing free(allocation) inside allocation_tracker_notify_free()
when freeing a memory buffer.

Prior to switching the allocation tracker to use C++ unordered_map,
the "allocation" bin was kept within (and reused) by the older hash_map
mechanism. However, after the switch to the C++ unordered_map this
is no longer the case, hence the memory leak.

Test: watch -n 1 "adb shell dumpsys meminfo -d BT-PID | grep Heap"
Bug: 34785845
Change-Id: I737c901a6452d29d18fd8b847e7d5ea10c5ff485

7 years agoMerge "Use local CCB variable in loop to check GAP CCB pool"
Treehugger Robot [Fri, 3 Feb 2017 02:12:31 +0000 (02:12 +0000)]
Merge "Use local CCB variable in loop to check GAP CCB pool"

7 years agoUse local CCB variable in loop to check GAP CCB pool
Venkata Ramana Rao [Wed, 15 Jun 2016 09:57:12 +0000 (15:27 +0530)]
Use local CCB variable in loop to check GAP CCB pool

CCBs are not being properly cleared due to attempting to clear the wrong
CCB. This is fixed by using a local CCB variable in order to preserve the
CCB being freed.

Test: Send multiple files over OPP
Change-Id: I06a8f237047ffb212118b4239e9856fe5c89acb1

7 years agoInitializing the SDP event message pointer before sending
Manu Viswanadhan [Tue, 7 Jun 2016 10:51:18 +0000 (16:21 +0530)]
Initializing the SDP event message pointer before sending

Use case: Crash while copying SDP results in case of SDP
ServiceSearchAttributeRequest failure

Steps : Repeated connection-disconnection with multiple devices

Failure: Crash while copying SDP results

Root cause: In case of SDP_ServiceSearchAttributeRequest failure,
garbage value sent for discovery result structure due to improper
initialization

Fix: Initialize the discovery result structure to zero before
sending

Test: code compilation.

Change-Id: I46d92d6262bae3b5def5401270465a3a06468c1a

7 years agotest_vendor: Test fixes for AsyncManager
Myles Watson [Thu, 26 Jan 2017 23:09:38 +0000 (15:09 -0800)]
test_vendor: Test fixes for AsyncManager

Test: unit tests pass
Change-Id: I5c3f9f4a1fa86e97fa9e6cc26160fd1e3e854925

7 years agoMerge changes Ie172ca37,Idf714e51
Andre Eisenbach [Thu, 2 Feb 2017 18:00:58 +0000 (18:00 +0000)]
Merge changes Ie172ca37,Idf714e51

* changes:
  Remove LPM code from the stack
  btif: Remove platform-specific address logic

7 years agoMerge "Initial HIDL conversion"
Andre Eisenbach [Thu, 2 Feb 2017 18:00:29 +0000 (18:00 +0000)]
Merge "Initial HIDL conversion"

7 years agoRemove LPM code from the stack
Myles Watson [Mon, 12 Sep 2016 21:39:58 +0000 (14:39 -0700)]
Remove LPM code from the stack

Power management is handled in hardware/interfaces/bluetooth/.

Test: mma -j32
Change-Id: Ie172ca37059768a2cfa0d4b84f34b54624b1fa49

7 years agobtif: Remove platform-specific address logic
Myles Watson [Wed, 21 Dec 2016 23:27:01 +0000 (15:27 -0800)]
btif: Remove platform-specific address logic

This functionality has moved to hardware/interfaces/bluetooth/

Test: Boot and check the address.
Change-Id: Idf714e514314c10dc1659f024ab4cc8570f292b7

7 years agoInitial HIDL conversion
Andre Eisenbach [Fri, 11 Nov 2016 00:11:00 +0000 (16:11 -0800)]
Initial HIDL conversion

Test: Unit tests, VTS test, device sanity
Change-Id: Ia5b2b5fa762d240c0490666d50ea5c878631fcd1

7 years agoHandled invalid MTU Size in L2cap Process Commands
Ajay Kumar [Wed, 12 Mar 2014 13:59:27 +0000 (19:29 +0530)]
Handled invalid MTU Size in L2cap Process Commands

Use case: Execute the L2CAP test suite on Codenomicon tool

(1)From tool Codenomicon Defensics 11 menu Utilities > Bluetooth Scan,
paired Bluetooth between pc and phone.
(2)From Defensics 11 Settings ,choose paired phone Bluetooth to be
Target Bluetooth device address in Basic configuration.
(3)Run the test case " Security - l2cap ".
(4)When run to the number 28, 29 test case,check the phone. BT turn
off and turn on

Failure: BT crash observed due to invalid MTU packets from test tool

Root cause: L2CAP is not validating packets in L2CAP Process Commands

Fix: Fixed by sending reject CMD for invalid commands from tool

Test: code compilation.

Change-Id: I8c503ab77d8fca3728a84c3457d8115e31ee3a13

7 years agoAdd memory allocation statistics to the Bluetooth dumpsys output
Pavlin Radoslavov [Wed, 1 Feb 2017 11:55:33 +0000 (03:55 -0800)]
Add memory allocation statistics to the Bluetooth dumpsys output

The following memory allocation statistics are added to
the "dumpsys bluetooth_manager" output.
Those are tracking the allocations that are using the OSI malloc mechanism:
osi_strdup() / osi_strndup() / osi_malloc() / osi_calloc() / osi_free()

Bluetooth Memory Allocation Statistics:
  Total allocated/free/used counts : 4063 / 3323 / 740
  Total allocated/free/used octets : 922460 / 607941 / 314519

Test: Running "adb shell dumpsys bluetooth_manager"
Change-Id: Ibe1d28ec3a2acfd87cfaa10e5902ef3b596e64a8

7 years agoUpdate the A2DP Codec Config API
Pavlin Radoslavov [Thu, 26 Jan 2017 01:00:23 +0000 (17:00 -0800)]
Update the A2DP Codec Config API

Previously, the JNI upcall would contain only the current codec config.
In the new API, the upcall contains:
 1. The current codec config
 2. The list of codecs containing the local codecs capabilities
 3. The list of codecs containing the selectable codecs capabilities.
    This list is the intersection of the local codecs capabilities
    and the capabilities of the paired device.

Also, updated the codec backend to accomodate the above changes:
 * Update all selectable codecs inside bta_av_co_audio_set_codec()
 * Changed getCodecConfigAndCapabilities() to return current codec
   config, local codecs capabilities, and selectable codecs capabilities.
 * Updated each codec to compute and store a copy of the selectable
   capabilities, and the local capabilities.
 * Updated tA2DP_SBC_CIE to include new field bits_per_sample
   (for consistency with the rest of the codecs).
 * Replaced usage of codec_priority of 0 with BTAV_A2DP_CODEC_PRIORITY_DEFAULT
 * If there is user codec (re)config call, we always send an upcall
   to inform the Java layer about the most recent codec info.
   Thus, the caller would always know whether the request succeeded or failed.

Test: A2DP streaming with headsets and switching the codecs
Change-Id: Ie7a5cd5c2ab01bb8676032be05bc2ad03baa1e3f

7 years agoMerge commit 'ca6d7dcbd49356338eaaa88de87885ecaf218c4d' into master.
Stephen Li [Thu, 26 Jan 2017 23:45:27 +0000 (15:45 -0800)]
Merge commit 'ca6d7dcbd49356338eaaa88de87885ecaf218c4d' into 

This is because patchset 1 of change 328081 got merged in to the branch
and not patchset 2, despite what gerrit UI says. This is a known error
and is being worked on.

Change-Id: If4f6f3d705e93f03d120c6441e16e9b0afc3d9ca

7 years agoMerge "Remove HC_BUFFER_HDR_T"
Treehugger Robot [Thu, 26 Jan 2017 23:22:12 +0000 (23:22 +0000)]
Merge "Remove HC_BUFFER_HDR_T"

7 years agoRemove HC_BUFFER_HDR_T
Andre Eisenbach [Wed, 25 Jan 2017 17:26:41 +0000 (09:26 -0800)]
Remove HC_BUFFER_HDR_T

Test: compiles
Change-Id: Ia5bf3395bd5a18a27168f05a0a2239a37ddb2c2c

7 years agoIntegration of the AAC codec for A2DP source
Pavlin Radoslavov [Wed, 4 Jan 2017 00:53:18 +0000 (16:53 -0800)]
Integration of the AAC codec for A2DP source

Also:
 - Implemented data fragmentation inside bta_av_data_path()
   that is RTP compatible.
 - Do not use the codec_type when composing the RTP payload type
   per RFC 3016, Section 4.2. That value doesn't have actual meaning
   in the context of the Bluetooth supported codecs, and is ambiguous:
   all vendor codecs map to the same value 0xFF.
 - Updated support function A2DP_BitsSet() so it works for
   up to 64-bit integers.
 - Updated a log message inside l2c_data_write() to print
   packet length and peer MTU on error.

Test: A2DP streaming to AAC headsets
Bug: 30958229
Change-Id: I1b530f1c5c495b8231fd68bed788d4567096683d

7 years agoMerge "Update UUIDs immediately on NVRAM"
Treehugger Robot [Wed, 25 Jan 2017 19:55:59 +0000 (19:55 +0000)]
Merge "Update UUIDs immediately on NVRAM"

7 years agoMerge "Corrected default value assignments in Bluetooth A2DP Metrics"
Treehugger Robot [Wed, 25 Jan 2017 19:28:02 +0000 (19:28 +0000)]
Merge "Corrected default value assignments in Bluetooth A2DP Metrics"

7 years agoUpdate UUIDs immediately on NVRAM
Srinu Jella [Mon, 21 Nov 2016 12:56:58 +0000 (18:26 +0530)]
Update UUIDs immediately on NVRAM

As the BTIF config updation have delay in writing items
to the NVRAM, some times there is a chance of not updating
incase of battery removal happens before the actual write onto
NVRAM.

As SDP UUIDs is important data to store, it will update
immediately onto NVRAM.

Test: manual

Change-Id: I6637dc326f3a53211a5bbf988a2dca1020203128

7 years agoRemove HC_BUFFER_HDR_T
Andre Eisenbach [Wed, 25 Jan 2017 17:26:41 +0000 (09:26 -0800)]
Remove HC_BUFFER_HDR_T

Test: compiles
Change-Id: Ia5bf3395bd5a18a27168f05a0a2239a37ddb2c2c

7 years agoHID: Fix forced disconnection flow.
Ivan Podogov [Thu, 19 Jan 2017 17:19:37 +0000 (17:19 +0000)]
HID: Fix forced disconnection flow.

In some cases, we end up in a state where we can neither
connect nor forcefully end connection, and will require disabling
the Bluetooth adapter to fix this state.

When a device is taking too long to connect (or out of range),
the user may want to cancel the connection by calling disconnect
method, which will be ignored in any state other than
BTA_HD_CONN_ST. It is a lot better to immediately cease the
connection process at this point, so:
- BTA_HD_API_DISCONNECT_EVT is now not ignored in BTA_HD_IDLE_ST;
- bta_hd_disconnect_act now reports a correct MAC address during
    disconnection (it used to send 00:00:00:00:00:00 before);
- HidDevDisconnect now allows to forcefully end the connection,
    and does it in exactly the same way we handle the errors.

When L2CAP connection fails, both hidd_l2cif_config_ind and
hidd_l2cif_config_cfm set conn_state to HID_CONN_STATE_UNUSED,
which is immediately overwritten by the hidd_conn_disconnect call
(it will set conn_state to HID_CONN_STATE_DISCONNECTING, because
ctrl_cid != 0 in both cases), thus making any subsequent calls to
connect failing with "already connecting" error. More than that,
all functions send the HID_DHOST_EVT_CLOSE event when failing,
which is, again, ignored in the BTA_HD_IDLE_ST state. So:
- BTA_HD_INT_CLOSE_EVT is now not ignored in BTA_HD_IDLE_ST;
- conn_state is set to HID_CONN_STATE_UNUSED after the call to
    hidd_conn_disconnect, but before sending the close event.

Test: Build, run, connect/disconnect multiple times.
Change-Id: I85bb03f760bb9a6fd4c1b944d515232c1be12300

7 years agoCorrected default value assignments in Bluetooth A2DP Metrics
Jack He [Fri, 20 Jan 2017 19:17:44 +0000 (11:17 -0800)]
Corrected default value assignments in Bluetooth A2DP Metrics

* In certain cases btif_a2dp_source_stop_audio_req() could be called before
  btif_a2dp_source_start_audio_req() is called, resulting in session_start_us
  to be 0. In this case, audio_duration_ms = time_get_os_boottime_us() - 0
  will be a very large number that is not the actual audio duration. This
  CL marks audio_duration_ms as -1 in the above situation so that we can
  differentiate between valid and invalid audio durations
* Set default timer and counter values to 0 when
  tx_queue_dequeue_stats.total_updates > 1
* Move update_scheduling_stats for tx_queue_enqueue_stats to
  btif_a2dp_source_audio_handle_timer as we intend to capture the time
  intervals for enqueue scheduling instead of time intervals between
  frame enqueue (i.e. one scheduling event can enqueue multiple frames)
* Use tx_queue_enqueue_stats for metrics instead of *dequeue* since only
  enqueue is triggered by timer event

Bug: 33694310
Test: Code compilation, BtFunhausMetricsTest
Change-Id: I10984920afd4d77f07a5ac75736f8dcd69b13af8
(cherry picked from commit 5a9925784a4a34811ae29608b67dee4a580c226b)

7 years agoAdd advertising handle zero quirk
Jakub Pawlowski [Mon, 23 Jan 2017 22:03:19 +0000 (14:03 -0800)]
Add advertising handle zero quirk

Some controllers are strict about VSC handle mapping, and don't allow
using zero value.

Test: manual test
Change-Id: Ia2df17af16e0e4da375d6e7d5b5f882ced508ce9

7 years agoFix the GATT server and HOGP disconnect
IHLHO KIM [Fri, 13 Jan 2017 06:27:38 +0000 (06:27 +0000)]
Fix the GATT server and HOGP disconnect

GATT server disconnect and HOGP disconnect are not working after the
following commit: a62adcab30929566b435891611232566bd69204a.

‘BTA_GATTS_CancelOpen’ makes ‘gatt_update_app_hold_link_status’
return FALSE value. As a result, ‘BTA_GATTS_Close’ cannot disconnect
the link. The sequence has to be changed like GATT client.

And the above mentioned fix removed ‘found’ checking routine in
‘gatt_update_app_hold_link_status’.

It makes two app hold links with same gatt_if when HOGP is connected and
background connection is added. But HOGP disconnect removes only one held
link. So HOGP is never disconnected.

The ‘found’ checking routine has to be rolled back.

Test: manual
Change-Id: Ibea825b5cc844195f0cf4a30cbcca831880c9088

7 years agoFix advertising timeout behaviour.
Jakub Pawlowski [Fri, 20 Jan 2017 13:33:38 +0000 (05:33 -0800)]
Fix advertising timeout behaviour.

When advertising is enabled with timeout, enable callback was not
called. Also we were not scheduling the disable operation after the
timeout passes. This patch fixes that. It also make sure that the
timeout callback is called on proper thread.

Bug: 34440704
Test: sl4a ConcurrentBleAdvertising:test_timeout
Change-Id: I233c2692c690f55ef6243325640e48b37818c9d5

7 years agoMerge "Set alarm's queue to NULL on alarm expired"
Treehugger Robot [Fri, 20 Jan 2017 23:36:39 +0000 (23:36 +0000)]
Merge "Set alarm's queue to NULL on alarm expired"

7 years agoMerge "Synchronize hl data operations"
Treehugger Robot [Fri, 20 Jan 2017 23:25:44 +0000 (23:25 +0000)]
Merge "Synchronize hl data operations"

7 years agoUpdate error check for LE read remote feature event
Nagarjuna Kristam [Tue, 13 Dec 2016 09:00:45 +0000 (14:30 +0530)]
Update error check for LE read remote feature event

When a BLE remote read remote feature complete event is received
initial commands flow is proceeding if error code is not connection
failed to establish (0x3E). Instead, the flow should fail on any
error.

Test: Re-connection stress tests with LE device
Change-Id: I4ab80b6601f5f852fcf8da2911807438584fd3f4

7 years agoSet alarm's queue to NULL on alarm expired
Kamal Negi [Mon, 19 Sep 2016 08:46:56 +0000 (14:16 +0530)]
Set alarm's queue to NULL on alarm expired

Use Case: Repeated BT ON/OFF

Failure: ANR due to race condition between random advertisement
address generation completion(adv_raddr_timer) and BT shutdown.

Steps: SNS Stress testing.

Root Cause: Race condition happens between random advertisement
address generation completion(adv_raddr_timer) and BT shutdown.

Fix:  For non-periodic alarms, set alarm's queue to NULL once alarm
expired.

Test: mm -j8

Change-Id: Idf8e2bebdc2ca7621aef06dd5f2075ef2c5fa08c

7 years agoSynchronize hl data operations
Srinu Jella [Wed, 30 Nov 2016 09:55:12 +0000 (15:25 +0530)]
Synchronize hl data operations

Use Case: BT crash seen while transferring data
using HDP APP to remote health device.

Steps:
1. Pair with HDP device
2. Run HDP APP and transfer data to Remote HDP device.

Failure: BT automatically resets and recovers.

Root Cause: Synchronize BITF HL free buffer as simultaneously
free buffer from BTIF and BTU thread lead to sigabort.

Fix: Validate Tx packet before memcpy as it can be free
from different thread.

Test: mm -j8
Change-Id: I566f62ce02c8e95c9f4b8d7155132e4434657f66

7 years agoBluetooth: Handle get RSSI timeout gracefully
Satish Kodishala [Tue, 20 Dec 2016 05:31:07 +0000 (11:01 +0530)]
Bluetooth: Handle get RSSI timeout gracefully

Usecase:
1. Turn ON BT
2. Pair and connect with Headset
3. Play Music over A2DP
4. Make GetRssi timeout
5. Bt app crashes

Failure:
BT app crashes.

Rootcause:
Calling callback with NULL and in callback handling NULL check with assert.

Fix:
Call the callback with error instead of NULL.

Change-Id: I20a9e504a513697945cd76d218ec12a0ef1e3330

7 years agoBTA HF CLIENT: Unset initial SCO value
Sanket Agarwal [Fri, 20 Jan 2017 19:06:41 +0000 (11:06 -0800)]
BTA HF CLIENT: Unset initial SCO value

Initialize the block with invalid SCO state so that while allocating the
if condition does not ignore the block. This was causing the stack to
not initiate a SCO connection to the remote (AG role)

Bug: b/33555377
Test: Check for SCO initialied on audio call
Change-Id: I3f5619c69288483bfa45c2a1adcf22008e353841

7 years agoFix A2DP Metrics Logging Capacity
Jack He [Tue, 17 Jan 2017 23:41:30 +0000 (15:41 -0800)]
Fix A2DP Metrics Logging Capacity

* Set the maximum number of wake events logged to 1000
* Stop logging wake log name as it takes too much memory
* Add counters for each of the repeated values in BluetoothLog so that
  the true number of events can be determined while oldest event get
  dropped
* Log Bluetooth session disconnect reasons using enum instead of string
  in order to save memory usage
* Apply other branch changes to bluetooth.proto on system/bt

Bug: 33694310
Test: Code compilation and unit tests
Change-Id: I2cc6f9304725938b63b211d615eb1941eac60edf
(cherry picked from commit 7ab4b59672013eddcb706e288962ab7309a75628)

7 years agotest_vendor: Remove extra byte in LE Features
Myles Watson [Thu, 19 Jan 2017 21:13:55 +0000 (13:13 -0800)]
test_vendor: Remove extra byte in LE Features

Bug: 34357009
Test: push test-vendor lib as libbt-vendor.so, Bluetooth starts
Change-Id: Id3a5f85f6b3da5a723dba04527db8b66de0e84a8

7 years agoFix bad UUID comparison when adding GATT service
Jakub Pawlowski [Thu, 19 Jan 2017 06:58:53 +0000 (22:58 -0800)]
Fix bad UUID comparison when adding GATT service

This patch fixes bad comparison in add_service_impl. Instead of checking
wether service is one of two excluded services, it was excluding all
services.

Test: sl4a GatReadTest
Bug: 34280184
Change-Id: I3195e94b6fafe4d2e3c61fc7bfd7398c2855b78e

7 years agoMerge "test_vendor: Make tryStartThread return 0 on success"
Treehugger Robot [Thu, 19 Jan 2017 14:26:33 +0000 (14:26 +0000)]
Merge "test_vendor: Make tryStartThread return 0 on success"

7 years agotest_vendor: Make tryStartThread return 0 on success
Jorge E. Moreira [Thu, 19 Jan 2017 00:34:42 +0000 (16:34 -0800)]
test_vendor: Make tryStartThread return 0 on success

Test: Start the test vendor library with no error message
Bug: 34357009
Change-Id: Id2821199ad675e2b95a9f333afa803dcced811a3

7 years agoFix parser for BOARD_BLUETOOTH_BDROID_BUILDCFG_INCLUDE_DIR
Jack He [Thu, 19 Jan 2017 01:14:08 +0000 (17:14 -0800)]
Fix parser for BOARD_BLUETOOTH_BDROID_BUILDCFG_INCLUDE_DIR

* Current parser does not support multi-directory lists, which may cause
  a build failure if BoardConfig.mk defines one.
* This CL splits the list of directories using whitespace and adds them
  individually to the include list

Bug: 34396100
Test: Code compilation, no user visible effect
Change-Id: I59e901d76d1bc20f50b54941a3007c5521ded214