Bluetooth: Added Shared Preferences to restore tethering preference

Added a Shared Preferences to have the tethering preference persist,
The value is stored while changing the tethering preference by user
and tethering preference will be restored based on the value(last
saved tethering preference) while starting the PAN service.

Change-Id: I468564a51ff17dfdf1b95a532fa429477db0da15
CRs-Fixed: 506194, 532893
(cherry picked from commit c2dd23d9a1b277f2995119ea83d16cf46a2028b9)
(cherry picked from commit c74f8fcab58486d11f82b26a14a68fa0c09e8790)
(cherry picked from commit 10a1a41c6cdabc5f69021f907021f9dc1fcc47a3)
Bluetooth: Update SCO disconnect properly.

This change will allow to update the sco
disconnect event to be broadcasted only
after getting the disconnect confirmation
from the stack.

CRs-Fixed: 532865
Change-Id: If0e2b4b3eaa1c0f2441350a1d0181346f358a03a
(cherry picked from commit 2db056fea7e4f463eac201aa28c344de5b1759e9)
(cherry picked from commit 9cc14d35303f1b51762392cd30ee15fc65d91f62)
(cherry picked from commit 160fe919933a605d8fa10914afd122e68d803152)
Bluetooth: Query BluetoothPhoneService at BT ON.

This will allow the application to have
updated values of call states.

CRs-fixed: 506853
Change-Id: I0b1e9cdfd7ecac05062c82aa563849f49a5ae520
(cherry picked from commit 29099eb7c1f203f2537d7b944279feb0bb0f4788)
(cherry picked from commit 15a56682609df4d6e9376d0518e50b3dbd5602d8)
(cherry picked from commit bacc9984bdfe29e8e5b5e0cb94882e1a9032a043)
Bluetooth: Update the roam status.

This change makes sure that roam status
change is updated to headset immediately
instead of updating at network service state
changed.

CRs-Fixed: 503919
Change-Id: Ia5c68e2158241459f48a1718689361ad0cd6fbf8
(cherry picked from commit 4dd47da4fb0240499ee4bc082e6093ad82376d69)
(cherry picked from commit 5c717f7c8321e85204189920701b729437177574)
(cherry picked from commit 8417d5ce6f598d7af50c4d56fa084de6db0544dd)
Bluetooth: Move A2dp State to Disconnected when BT is Turned OFF

Found one timing issue where the A2dp State is Stuck in Connecting
state If User tries to connect to different headset when device is
already connected to headset and does BT ON -> OFF. This change will
allow the state to move properly when BT is turned off if any device
state was connecting previously.

Change-Id: I17bc620551bf735f39327eff59102c14551bcf26
CRs-Fixed: 532903
(cherry picked from commit 0ce6816d43761b838b65adbf1e636630e1047fcf)
(cherry picked from commit 51c4d0f1df682f3874915f99ef49ec5c3d9e74ed)
(cherry picked from commit 6583fca29318b3c8bc0b16d588fc939ffdde6142)
Bluetooth: Send Response OK to CLCC command

Found one IOT issue where OK response is not sent from DUT for CLCC
AT command which causing the delay while playing the voice mail.

Change-Id: I992d8e36ca888e6f1e3df0241361e7720630391f
CRs-Fixed: 528898
(cherry picked from commit 9a491ace8f205a37fdabcc08778832525730cec9)
(cherry picked from commit 4ffd1d7e68626dc6347ac7828c33f5b750775fac)
(cherry picked from commit b63972dcfbfdeff70baefd71ade256f34dc98727)
Bluetooth: Add trust device feature.

Add set trust feature where the remote device is marked
as a trusted device for subsequent connection.

Change-Id: Iee491db2e5b6090761a4f42467ac36ed53923fc4
CRs-fixed: 523135
(cherry picked from commit 3bb1c5cc7d0ec6c0d922b52eb96c22c80810ece2)
(cherry picked from commit f6e80df6e7f75195d8f877d21cdb9cff218724b8)
(cherry picked from commit 4039700a879872138257ca841a577840fa02e498)
Bluetooth: Clening up BT service in error cases.

If the statemachine didnt get response from stack in
8secs for any reason during BT off time, state machine
restores the BT state to on, which is wrong.
Restoring the BT state by restarting the service.

CRs-fixed: 528656
Change-Id: Iac6b1b4ba8ea0b5bd34bae5d672450e4a93fe658
(cherry picked from commit e6dc9d4bc326c01cc2edacc3150811430633946c)
(cherry picked from commit 7917ad6ed8a3919d110907401fff0f7a4bf6df7b)
(cherry picked from commit f2920dfe189e469061c8941379388905556fda76)
Bluetooth: Update the Bluetooth state in STOP_TIMEOUT case

Bluetooth adapter state is getting updated with turn off
but the same intent is not getting broad casted to the
application, so it hanged in turning off state.

Broadcasting the TRUN_OFF intent in STOP_TIMEOUT case.

CRs-fixed: 534372
Change-Id: I4f05a946e56a87ff62c6e505b6bfbfbfe7c8c951
(cherry picked from commit da24eec61839f23bae7d4dff53053fbf4888189c)
(cherry picked from commit 98eee37d49c214397c2e54e275d83f7feb0abc56)
(cherry picked from commit 1f139390de9d1db63040a21161e76af668cd81d2)
Bluetooth: Allow the HFP app to set features.

This chnage gives the flexibility to the HFP
APP to update the features supported, rather
than using the hardcoded bitmask in BT stack.

CRs-Fixed: 482189
Change-Id: I2eda57795782fbc765c5dafdbc1a68fb2b5543d9
(cherry picked from commit 3905d5b81ed5cefac47dc6b49cdf9cb529a20f55)
(cherry picked from commit dd05fb9127be0f26a0219d3e40f4c1021ef0264d)
(cherry picked from commit 962941e1ceed7f035fe13fcdccc42ad9d1e31d1d)
Bluetooth: Enabling WBS feature in BT app.

Bluetooth HFP statemachine will enable
WBS support based on reading system property.
This will enable Codec negotiation bit mask in
BRSF AT response to claim support of WBS and
codec negotiation.

Change-Id: If2c1bef8b87ce493715518206a4b30a028255dbc
(cherry picked from commit 4a9204ebaf9ac8a49ec53d93df6b3106ac7b51dd)
(cherry picked from commit f57cd1d1e0cad9bf749b1f2d5383c45f850e5b27)
(cherry picked from commit d95bed21572c63aa2aad4a523eab1685b2d980bc)
Bluetooth: HID : Add support for Set Idle and Get Idle commands

This patch adds support for Get Idle and Set Idle command handling
in jni and HidService which will be used to provide interface for
sending thse commands to HID Remote device.

Change-Id: I066d47c022905a39c11d365a9d26d128f94fe2f6
CRs-Fixed: 522511
(cherry picked from commit 186289606b666b894161e749abdc359d2bca2948)
(cherry picked from commit d1d84a3eeac8a7e0fc33f09c3259acf9efcceaa1)
(cherry picked from commit be4c95c535356905e7ff58d612fa1274d81e1960)
Bluetooth: Add support for sending priority to btif layer

This patch adds support for sending remote device priority to HID btif
layer. Now with every change in remote input device priority btif layer
would be informed.

Change-Id: I08935a9d733ccab29173ba41ddab795eccad3f7f
CRs-Fixed: 532234
(cherry picked from commit f470c4da7c22a89b234382e197eef52897ae5154)
(cherry picked from commit e43b8a111d9372ae24279254d6565107bc534b60)
(cherry picked from commit 88a6d3c327aeab2c6094536a63d3ce1249ba5b6b)
Properly update profile connection state.

When DUT is toggled between various paired Headsets Connection
state is not updated properly in some scenarios.This is causing
Bluetooth icon to be in connected state even when no Headsets are
connected.Also make sure connected,connecting,disconnecting devices
count is never negative.

Change-Id: Icb1a7215ff6d9491afbb5f7f203ca0a2c6b7f43a
CRs-Fixed: 532783
(cherry picked from commit 4a434dacc83ece2034d155b2e3adb180419c6d17)
(cherry picked from commit b88ca92f4d7a7500ecae93f0721928f46b96de97)
(cherry picked from commit edf19096b25669c77913595805701146bd922ba9)
Check for A2DP UUIDs supported by remote device

Before sending connect request for A2dp check for roles
supported by remote device and proceed accordingly.

Change-Id: I0200582a69b3d4e9b7f92516ba92f34054a1f4dc
CRs-Fixed: 507306
(cherry picked from commit 5b7325d795331a249a70fdfd20a9f29bed388f1d)
(cherry picked from commit 27f0077dde25b69442aff316e5c60d32f2275a65)
(cherry picked from commit c5b6b44414be53bbb75e064412a7d2d49ffe871f)
Bluetooth:Handling Connect request in AudioOn state.

While in active call, connected to the first BT HS, when we
initiate connection to a second BT HS, connection was not
happening because of which the call audio was routing to the
speaker. Added Connect message handling in the AudioOn state.

Change-Id: I3d9f4265aa2cfddf141ac60f7da82fabfd4bc383
CRs-Fixed: 534731
(cherry picked from commit 2fb952f4a2e5d0cd28457165ec7e5891f116c8a4)
(cherry picked from commit b02dbb50e1aedd2fee5e7e74a458ba6d40314eb9)
(cherry picked from commit e4278411b75c5aa71f4da84e2eb9728f6a89cb5b)
Update UI properly in Connection race Conditions.

Broadcast connection state of incoming device in pending
state and update UI for disconnection of outgoing connection.

Change-Id: Ibd80fc7010613887df74fb1903b16de73c77939a
CRs-Fixed: 531637
(cherry picked from commit 2b2453a294b61eb197cdb35db4121c783cc0cfe5)
(cherry picked from commit 38f11580e11070ad0d40df0774a21b5a8e3eb397)
(cherry picked from commit 997a08a3c98b063ca991656aca434eaf534b872d)
Bluetooth: Proper Connection with multiple Headsets

When paired with multiple Headsets,connecting/disconnecting randomly
between them DUT was connecting HS to one device and A2DP to other device.

Change-Id: Ia6152db3fe56b3ede42460e48fc497a640b2ec2a
CRs-Fixed: 465980
(cherry picked from commit c32e68d2af6bd00ac3e0b64819fca9f2c0ce0ff1)
(cherry picked from commit 4744adb002a1a81887a10a3345be430abad2ae8f)
(cherry picked from commit 7d69d39effd8767b65ed88b0bbd2d858299e3692)
Bluetooth:Send Connection request after Connection Failure.

When one of profile is un-checked from setting sub-menu and initial
connection has failed then try to re-connect selected profile.

Change-Id: I67bf658b5b9ce556fc0d54030989e6033651051b
CRs-Fixed: 543050
(cherry picked from commit 858b3d0bca6a64018cee2715429adbde6bcbd070)
(cherry picked from commit 383bf967e6a8f889f0cf89fdf476c3588cf8beb1)
(cherry picked from commit 9ccd9a603c55e0059c0c2b8561e9fbdca206829f)
Bluetooth: Get Scan mode from storage

After BT is turned ON scan mode is get from storage, which have stored
the previous scan mode state.

CRs-Fixed: 519661
Change-Id: Iaa4bafb32381cd146f5dc6343651df61b7bdb301
(cherry picked from commit def9ca3edf914f4fce75cf11896ac277a9ddf9c1)
(cherry picked from commit 239b7116d98ee028aeac6a1453b0c65b4e8f3750)
(cherry picked from commit a9d26494b6a37b07c17ad972d237e3c746899510)