Conditional compilation for 48KHz sample rate

PS2:
https://github.com/CyanogenMod/android_external_bluetooth_bluedroid/commit/2cbe5233895e03255d655044897b9a27fcfc4e51
All QC devices using the CodeAurora drivers should be using a 48KHz
samplerate for A2DP.

Change-Id: I0a439973605369509efd06486181007978627414
Add I2S-PCM slave mode for SCO

 * M7 needs us to configure I2SPCM for SCO and set the voice mode.

Change-Id: Ia46e74a42c869bd08c257d6463d2ddc515609a19
libbt-hci: include bdroid_buildcfg.h from device repo

This lets device repos override some constants with their bdroid_buildcfg.h if
necessary.

This fixes Bluetooth issues (namely tethering) on endeavoru where
BTHC_USERIAL_READ_MEM_SIZE needs to be set to a higher value.

Change-Id: I8955963cdb2b34f1ba63f8160861699f7284814f
a2dp hw: adding a2dp tuning through bdroid_buildcfg.h

This adds possibility to configure a2dp tuning on an
arbitrary sysfs path and arbitrary ON/OFF values.
It's activated when a2dp is being used, and
deactivates when a2dp is stopped.
This way a device can either use an a2dp_tuning sysfs file
or cpu scaling min freq sysfs path with a target
min_freq value for elevation.

Here are two example of the two strategies of usage for
this:
bdroid_buildcfg.h - sysfs tuning file
 #define A2DP_HW_SYSFS_TUNER "/sys/devices/platform/tegra_uart.2/a2dp_tuning"
 #define A2DP_HW_SYSFS_TUNER_OFF "0"
 #define A2DP_HW_SYSFS_TUNER_ON "1"

bdroid_buildcfg.h - scaling min freq file
 #define A2DP_HW_SYSFS_TUNER "/sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq"
 #define A2DP_HW_SYSFS_TUNER_OFF "0"
 #define A2DP_HW_SYSFS_TUNER_ON "204000"

Change-Id: I2cd94e626eb2a6d04a6e52ddac94fa5773eb09d8
Merge "Conditional compilation for 48KHz sample rate" into android-4.4
Merge "a2dp hw: adding a2dp tuning through bdroid_buildcfg.h" into android-4.4
Merge "Add I2S-PCM slave mode for SCO" into android-4.4
Merge tag 'android-4.4.1_r1' into HEAD

Android 4.4.1 Release 1
Bluetooth: Fix losing HF connection to car-kit after 5 seconds

This patch adresses a change in bluetooth which causes a possible
loss of connection within 5 seconds after connecting.  This new
behavior appeared with android 4.2 (4.1.2 worked fine in this regard).

I traced down the disconnects to an BTA_AG_SVC_TOUT_EVT via a timer
that checks if a service connection was made within a few seconds.
Essentially bta_ag_svc_conn_open() was not called on AT+CMER because
android thought the car kit supported 3WAY but the car kit did not
set the 3WAY flag via AT commands and did not send AT+CHLD either.
Android otoh used the flag obtained by SDP and expected 3WAY behavior
and eventually disconnected when AT+CHLD did not arrive.

This may be a bordeline case, because in the Bluetooth Specification
(page 20), assuming service level initialization via SDP is only
mentioned on the HF side while there is no such mention (but could
probably be implied) on page 21 for the AG.

Fact is however, that the use of SDP features value for peer_features
is new since Android 4.2 and breaks existing good behavior on a BMW
2005/E46 car kit (navi professional). This kit never asks for AT+CHLD
and never via AT commands suggests it supports 3WAY (although it seems
to have the flag set via SDP).

Also, having essential behavior (like making the connection or not)
depend on circumstances that may be prone to race conditions, may be
a good reason to not use the SDP flag also (or at least masking out
the 3WAY bit when using it).

(An alternative approach could be to hook into bta_ag_timer_cback() and
when the timer exipres, but when also AT+CMER has been seen meanwhile,
to continue and assume a service level connection without 3WAY,
i.e. clearing the 3-way flags but calling bta_ag_svc_conn_open() anyway.)

Change-Id: I95dcdc5f46e7af723a655afd3d707764603c96c3
Signed-off-by: Markus Schmidt <shimodax@gmail.com>
DO NOT MERGE LE: Add service UUIDs and data to advertising data

Add support for UUIDs and custom service data in the advertising and
scan response records.

Cherry picking ble advertising changes from master to KLP MR2.
b/13137996

Change-Id: I6470427ad194871488cc90f3ab384b9ecf326b15
DO NOT MERGE Bluetooth: Cleanup bt_config.xml during BLE Scan

BLE Scan needs to clean up the bt_config.xml periodically so that
new entries could be added to bt_config.xml. Also, there is no
need to add BLE Random bd_addr to the bt_config.xml

Change-Id: I00ba2e50dd39a021099052cb569786f6cb2cc8b9

b/12912008
(cherry picked from commit 377cb1407ee6ee1ff91b15bfa7052abed1023d18)

Change-Id: I3fa0286c96782822a8fdac14b05bbb6f98636e50
DO NOT MERGE need to increase maximum number HID report for HOGP

The Mat mouse have more than 10 report (11),
which exceed our limitation

bug:12214036
Change-Id: Id578bf7959f73dc3bd57664eccf49ab5580ec76b
DO NOT MERGE read report array out of boundary for BLE HID device.

report array out of boundary when read HID report reference
descriptor for BLE HID device.

bug:12208657
Change-Id: Ic60fd7555045f367b4fcd606510f52f60e36995e
DO NOT MERGE Can only support two HID report instance for BLE HID.

The follwoing code cause this problem:
BTA_HH_LE_RPT_INST_ID_MAP(s,c)=(UINT8)(((s)<<4)||(c))
The code use || instead of |, this cause we can only generate
two instance HID report 0 and 1(false and true).

bug:12213520
Change-Id: If6b7cfd9633255401aef12aafd918ee147f256b6
DO NOT MERGE the HID device state is out of sync after upair.

the HID device state is out of sync between java layer and bluedroid stack after upair.
This will cause the HID device can't be connected after repair.
YOu can find the following error message
E/HidService( 1452): Hid Device not disconnected: 00:15:9E:20:29:41

bug:11718702
Change-Id: I271bb77a2cc205c5a0ef396db86b87902d29966b
DO NOT MERGE fix a potential native crash during bluetooth sutdown

When bluetooth is initialized which call gki_buffer_init,
the buffer pool is allocated by GKI_os_malloc which is
to call libc malloc function.
When bluetooth is cleanup which call GKI_shutdown,
the buffer pool will be  freed by GKI_os_free
which is to call libc free function.
So if we access the buffer, after the whole buffer pool is freed,
we will get this native crash.
if we call cleanup during bluetooth disabling:
the state is still BTIF_CORE_STATE_DISABLING,
then GKI_shutdown will call before bte_main_disable
( bt_hc_if->cleanup();), which is  before userial thread exit.
Then we may trigger this native crash.

bug:11793775
Change-Id: Ic8ced12848d25f918a28f4d5ba29b803d6ac5bd7
DO NOT MERGE BLE Secuity manager state machine generate wrong pairing success event.

 we call smp_proc_release_delay to setup a timer.
We will send a pair failure message to uplayer after the time expired.
Right before the time expire, the l2cap connection is disconnected
from remote device, we receive L2C_DISC, which will call smp_delay_terminate,
 smp_delay_terminate will send a pair success message to uplayer.
The fix is not to change the status if the remote device disconnect the link

bug:11716967
Change-Id: I8ca63599a170ec86913785aafea552301cec37df
DO NOT MERGE Remove the device from le backgrond connection whitelist when it's unpaired

this is due to we didn't remove the device from the white list before unpair
Which cause a fake pair request from remote device triggered
right after the acl is disconnected.
The fix is to remove the BLE device from whitelist before unpair.
Also fix a problem return wrong device handle from bta_hh_le_add_device.

if bta_hh_le_add_device is called right after reboot, before we connect HID device.
This is normally true for a previous paired device, which we saved in the nvram.
The wrong device handle will cause the removing HID device from while list failed
after unpair the HID device.

bug:11676338
Change-Id: Id5b45b2829da9a990dfd1dbae0c15764b16c2bfb
DO NOT MERGE BLE HID device connection failure due to security error.

When HID BLE device start encryption, if some other GATT application
already start encryption(but not finished yet) by calling
gatt_security_check_start. The HID BLE device will be failed to start
encryption, which will cause it to disconnect the BLE HID connection.
The solution is to check whether we already started the encryption
, If the encryption is already started, wait until the encryption
finished, then continue to start security check for BLE HID device.
add encrytion complete event to notify all GATT client encryption done.
filter the event just for BTA HH LE GATT client.

bug:11636246
Change-Id: If58e57c623cc8cfa05208587b010bec68c71306c
DO NOT MERGE sometime the BLE connection parameter isnot updated for the first time

When we receive the BLE connection parameter update
from remote device after smp_send_pair_req before
start BLE service discovery(bta_gattc_set_discover_st).
We will miss update this BLE connection parameter.
The reason is we call
L2CA_EnableUpdateBleConnParams(p_cb->pairing_bda, FALSE);
in smp_send_pair_req ,We change the state to UPD_DISABLED.

When we receive the new BLE connection parameter from
remote device, we will update the state to UPD_PENDING,
which will update the new connection parameter
when enable the connection parameter update.

when we start BLE service discovery
we call L2CA_EnableUpdateBleConnParams(p_srcb->server_bda, FALSE);
in bta_gattc_set_discover_st, We will update the state back to
 UPD_DISABLED, which will cause we miss updating
the new connection parameter when enable the connection parameter update.

The fix is don't change the state to UPD_DISABLED
when the state is UPD_PENDING for disabling.

bug:11727252
Change-Id: I953b9ca669e3460e18b340e7779cc54e03d6305b