Initial unified commit for Android 12, syncing up to v400.a

This commit is contained in:
Andy CrossGate Yan
2021-10-20 14:54:55 +00:00
commit 796726eb09
166 changed files with 20826 additions and 0 deletions

View File

@@ -0,0 +1,134 @@
From fd05778417027b87e72374e5ce357537c483f2c1 Mon Sep 17 00:00:00 2001
From: penn5 <penn5@users.noreply.github.com>
Date: Mon, 4 Mar 2019 22:21:07 +0000
Subject: [PATCH 1/5] Add props to control supported features and states (#1)
* Add bitmask for supported fields
Use persist.sys.bt.unsupport.states, defaults to 0, left-aligned.
Huawei suggest to use 000000000000000000000011111
* Add bitmask to LOCAL_SUPPORTED_FEATURES
For Huawei, suggest to use 00000001
Documentation:
- persist.sys.bt.unsupport.features matches the values:
HCI_3_SLOT_PACKETS..HCI_LMP_EXTENDED_SUPPORTED (max 8bits * 8 bytes =
64 bits)
- persist.sys.bt.unsupport.states matches the values:
BTM_BLE_STATE_INVALID..BTM_BLE_STATE_SCAN_ADV (max = 0x3ff, 11 bits)
- persist.sys.bt.unsupport.stdfeatures ( max: 16 bits)
HCI_LE_ENCRYPTION..HCI_LE_PERIODIC_ADVERTISING
Change-Id: I418aa605786153df4fdc544067ece59c12feccbf
---
hci/src/hci_packet_parser.cc | 56 ++++++++++++++++++++++++++++++++++++
1 file changed, 56 insertions(+)
diff --git a/hci/src/hci_packet_parser.cc b/hci/src/hci_packet_parser.cc
index 6bd6a52335..06964c3571 100644
--- a/hci/src/hci_packet_parser.cc
+++ b/hci/src/hci_packet_parser.cc
@@ -27,6 +27,8 @@
#include "hcimsgs.h"
#include "osi/include/log.h"
+#include <cutils/properties.h>
+
static const command_opcode_t NO_OPCODE_CHECKING = 0;
static const allocator_t* buffer_allocator;
@@ -108,6 +110,29 @@ static void parse_read_local_supported_commands_response(
buffer_allocator->free(response);
}
+static void setup_bitmask(uint8_t *v, const char* property) {
+ char str[PROPERTY_VALUE_MAX];
+ int len = property_get(property, str, "");
+ memset(v, 255, 8);
+ for(int i = 0; i<len; i++) {
+ if(str[i] == '1') {
+ v[i/8] &= ~(1 << (i%8));
+ }
+ }
+}
+
+static void filter_supported_feature(uint8_t *v) {
+ static int setup = 0;
+ static uint8_t unsupport_bitmask[8];
+ if(!setup) {
+ setup = 1;
+ setup_bitmask(unsupport_bitmask, "persist.sys.bt.unsupport.features");
+ }
+
+ for(unsigned i=0; i<sizeof(bt_device_features_t); i++)
+ v[i] &= unsupport_bitmask[i];
+}
+
static void parse_read_local_extended_features_response(
BT_HDR* response, uint8_t* page_number_ptr, uint8_t* max_page_number_ptr,
bt_device_features_t* feature_pages, size_t feature_pages_count) {
@@ -123,6 +148,8 @@ static void parse_read_local_extended_features_response(
STREAM_TO_ARRAY(feature_pages[*page_number_ptr].as_array, stream,
(int)sizeof(bt_device_features_t));
+ filter_supported_feature(feature_pages[*page_number_ptr].as_array);
+
buffer_allocator->free(response);
}
@@ -163,6 +190,19 @@ static void parse_ble_read_buffer_size_v2_response(
buffer_allocator->free(response);
}
+
+static void filter_supported_states(uint8_t *v, int size) {
+ static int setup = 0;
+ static uint8_t unsupport_bitmask[8];
+ if(!setup) {
+ setup = 1;
+ setup_bitmask(unsupport_bitmask, "persist.sys.bt.unsupport.states");
+ }
+
+ for(int i=0; i<size && i<8; i++)
+ v[i] &= unsupport_bitmask[i];
+}
+
static void parse_ble_read_supported_states_response(
BT_HDR* response, uint8_t* supported_states, size_t supported_states_size) {
uint8_t* stream =
@@ -171,9 +211,23 @@ static void parse_ble_read_supported_states_response(
CHECK(stream != NULL);
STREAM_TO_ARRAY(supported_states, stream, (int)supported_states_size);
+ filter_supported_states(supported_states, supported_states_size);
+
buffer_allocator->free(response);
}
+static void filter_supported_stdfeatures(uint8_t *v) {
+ static int setup = 0;
+ static uint8_t unsupport_bitmask[8];
+ if(!setup) {
+ setup = 1;
+ setup_bitmask(unsupport_bitmask, "persist.sys.bt.unsupport.stdfeatures");
+ }
+
+ for(unsigned i=0; i<sizeof(bt_device_features_t); i++)
+ v[i] &= unsupport_bitmask[i];
+}
+
static void parse_ble_read_local_supported_features_response(
BT_HDR* response, bt_device_features_t* supported_features) {
uint8_t* stream = read_command_complete_header(
@@ -183,6 +237,8 @@ static void parse_ble_read_local_supported_features_response(
STREAM_TO_ARRAY(supported_features->as_array, stream,
(int)sizeof(bt_device_features_t));
+ filter_supported_stdfeatures(supported_features->as_array);
+
buffer_allocator->free(response);
}
--
2.29.2

View File

@@ -0,0 +1,67 @@
From 08e1bdd47e599f4ac0e556676c934d344a11db0d Mon Sep 17 00:00:00 2001
From: Pierre-Hugues Husson <phh@phh.me>
Date: Mon, 25 May 2020 21:25:12 +0200
Subject: [PATCH 2/5] Add persist.sys.phh.disable_a2dp_offload property to
force a2dp offload
---
btif/src/btif_av.cc | 7 ++++++-
stack/a2dp/a2dp_codec_config.cc | 9 +++++++--
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/btif/src/btif_av.cc b/btif/src/btif_av.cc
index 50717d9eb4..7603ae2626 100644
--- a/btif/src/btif_av.cc
+++ b/btif/src/btif_av.cc
@@ -973,9 +973,14 @@ bt_status_t BtifAvSource::Init(
osi_property_get("ro.bluetooth.a2dp_offload.supported", value_sup, "false");
osi_property_get("persist.bluetooth.a2dp_offload.disabled", value_dis,
"false");
+ char value_phh[PROPERTY_VALUE_MAX] = {'\0'};
+ osi_property_get("persist.sys.phh.disable_a2dp_offload", value_phh, "false");
a2dp_offload_enabled_ =
(strcmp(value_sup, "true") == 0) && (strcmp(value_dis, "false") == 0);
- BTIF_TRACE_DEBUG("a2dp_offload.enable = %d", a2dp_offload_enabled_);
+ if(strcmp(value_phh, "true") == 0)
+ a2dp_offload_enabled_ = false;
+
+ LOG_ERROR("a2dp_offload.enable = %s", a2dp_offload_enabled_ ? "on" : "off");
callbacks_ = callbacks;
if (a2dp_offload_enabled_) {
diff --git a/stack/a2dp/a2dp_codec_config.cc b/stack/a2dp/a2dp_codec_config.cc
index a90c881087..e95d358f67 100644
--- a/stack/a2dp/a2dp_codec_config.cc
+++ b/stack/a2dp/a2dp_codec_config.cc
@@ -571,13 +571,18 @@ bool A2dpCodecs::init() {
char* tok = NULL;
char* tmp_token = NULL;
bool offload_codec_support[BTAV_A2DP_CODEC_INDEX_MAX] = {false};
- char value_sup[PROPERTY_VALUE_MAX], value_dis[PROPERTY_VALUE_MAX];
+ char value_sup[PROPERTY_VALUE_MAX], value_dis[PROPERTY_VALUE_MAX], value_phh[PROPERTY_VALUE_MAX];
osi_property_get("ro.bluetooth.a2dp_offload.supported", value_sup, "false");
osi_property_get("persist.bluetooth.a2dp_offload.disabled", value_dis,
"false");
+ osi_property_get("persist.sys.phh.disable_a2dp_offload", value_phh, "false");
a2dp_offload_status =
(strcmp(value_sup, "true") == 0) && (strcmp(value_dis, "false") == 0);
+ if(strcmp(value_phh, "true") == 0)
+ a2dp_offload_status = false;
+
+ LOG_ERROR("Got a2dp offload status %s", a2dp_offload_status ? "on" : "off");
if (a2dp_offload_status) {
char value_cap[PROPERTY_VALUE_MAX];
@@ -666,7 +671,7 @@ bool A2dpCodecs::init() {
}
}
- return (!ordered_source_codecs_.empty() && !ordered_sink_codecs_.empty());
+ return (!ordered_source_codecs_.empty() && !ordered_sink_codecs_.empty()) && !a2dp_offload_status;
}
A2dpCodecConfig* A2dpCodecs::findSourceCodecConfig(
--
2.29.2

View File

@@ -0,0 +1,31 @@
From 01b912959acd48430696fa7c93ae86271c12c99b Mon Sep 17 00:00:00 2001
From: Pierre-Hugues Husson <phh@phh.me>
Date: Mon, 7 Jun 2021 17:09:13 -0400
Subject: [PATCH 3/5] Add a property to disable eSCO
eSCO is troublesome on some old devices.
It is unknown whether it applies to any Treble device, but investigation
is ongoing, this will help the investigation.
---
hci/src/hci_packet_parser.cc | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/hci/src/hci_packet_parser.cc b/hci/src/hci_packet_parser.cc
index 06964c3571..c65f0c2a03 100644
--- a/hci/src/hci_packet_parser.cc
+++ b/hci/src/hci_packet_parser.cc
@@ -107,6 +107,11 @@ static void parse_read_local_supported_commands_response(
STREAM_TO_ARRAY(supported_commands_ptr, stream,
(int)supported_commands_length);
+ bool disable_eSCO = property_get_bool("persist.sys.bt.disable_esco", false);
+ if(disable_eSCO) {
+ supported_commands_ptr[29] &= ~0x08;
+ }
+
buffer_allocator->free(response);
}
--
2.29.2

View File

@@ -0,0 +1,44 @@
From def975d51460f82a34c78a63ec46b36583f8fa7a Mon Sep 17 00:00:00 2001
From: Alberto Ponces <ponces26@gmail.com>
Date: Thu, 17 Jun 2021 15:48:53 +0100
Subject: [PATCH 4/5] Add option to change eSCO Transport Unit Size
Fixes Bluetooth calls on some Samsung devices if set to 16.
It's still unknown if other Treble devices need other values so it's preferred to leave this able to be configured with another integer.
This applies to mSBC T2, T1 and CVSD codecs
Change-Id: I3e5897c2ce983042b9a4bef9def6744ba4253bcb
---
device/src/esco_parameters.cc | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/device/src/esco_parameters.cc b/device/src/esco_parameters.cc
index e2a6eeccef..c553205906 100644
--- a/device/src/esco_parameters.cc
+++ b/device/src/esco_parameters.cc
@@ -20,7 +20,8 @@
#include "device/include/esco_parameters.h"
-static const enh_esco_params_t default_esco_parameters[ESCO_NUM_CODECS] = {
+#include <cutils/properties.h>
+static enh_esco_params_t default_esco_parameters[ESCO_NUM_CODECS] = {
// CVSD D1
{
.transmit_bandwidth = TXRX_64KBITS_RATE,
@@ -213,5 +214,10 @@ enh_esco_params_t esco_parameters_for_codec(esco_codec_t codec) {
CHECK(codec >= 0) << "codec index " << (int)codec << "< 0";
CHECK(codec < ESCO_NUM_CODECS) << "codec index " << (int)codec << " > "
<< ESCO_NUM_CODECS;
+ int escoTransportUnitSize = property_get_int32("persist.sys.bt.esco_transport_unit_size", 0);
+ if(escoTransportUnitSize) {
+ default_esco_parameters[codec].input_transport_unit_size = escoTransportUnitSize;
+ default_esco_parameters[codec].output_transport_unit_size = escoTransportUnitSize;
+ }
return default_esco_parameters[codec];
}
--
2.29.2

View File

@@ -0,0 +1,98 @@
From 969b5a218adbed842d76b3ff195a3cafbeed7c1d Mon Sep 17 00:00:00 2001
From: Pierre-Hugues Husson <phh@phh.me>
Date: Sun, 17 Oct 2021 17:17:13 -0400
Subject: [PATCH 5/5] Don't abort when failing to get real-time priority
On some devices (like OP6), for unknown reason, trying to go to realtime
fails with EPERM.
There is no good reason to actually require real-time, so don't fail
when we don't get it
This fixes gabeldorsche on OP6
Not yet legacy bluetooth stack
Change-Id: Id25dac186628e933185bdfd640498004459b375a
---
btif/src/btif_a2dp_sink.cc | 2 +-
btif/src/btif_a2dp_source.cc | 2 +-
hci/src/hci_layer.cc | 1 -
osi/src/alarm.cc | 12 +++++++++++-
stack/btu/btu_task.cc | 2 +-
5 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/btif/src/btif_a2dp_sink.cc b/btif/src/btif_a2dp_sink.cc
index fa02a8682d..9610720db5 100644
--- a/btif/src/btif_a2dp_sink.cc
+++ b/btif/src/btif_a2dp_sink.cc
@@ -192,7 +192,7 @@ bool btif_a2dp_sink_init() {
/* Schedule the rest of the operations */
if (!btif_a2dp_sink_cb.worker_thread.EnableRealTimeScheduling()) {
- LOG(FATAL) << __func__
+ LOG(ERROR) << __func__
<< ": Failed to increase A2DP decoder thread priority";
}
btif_a2dp_sink_cb.worker_thread.DoInThread(
diff --git a/btif/src/btif_a2dp_source.cc b/btif/src/btif_a2dp_source.cc
index 19bf998ab2..57b665af7a 100644
--- a/btif/src/btif_a2dp_source.cc
+++ b/btif/src/btif_a2dp_source.cc
@@ -358,7 +358,7 @@ bool btif_a2dp_source_startup(void) {
static void btif_a2dp_source_startup_delayed() {
LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str());
if (!btif_a2dp_source_thread.EnableRealTimeScheduling()) {
- LOG(FATAL) << __func__ << ": unable to enable real time scheduling";
+ LOG(ERROR) << __func__ << ": unable to enable real time scheduling";
}
if (!bluetooth::audio::a2dp::init(&btif_a2dp_source_thread)) {
if (btif_av_is_a2dp_offload_enabled()) {
diff --git a/hci/src/hci_layer.cc b/hci/src/hci_layer.cc
index 1cd3a49a39..860be04460 100644
--- a/hci/src/hci_layer.cc
+++ b/hci/src/hci_layer.cc
@@ -234,7 +234,6 @@ static future_t* hci_module_start_up(void) {
}
if (!hci_thread.EnableRealTimeScheduling()) {
LOG_ERROR("%s unable to make thread RT.", __func__);
- goto error;
}
commands_pending_response = list_new(NULL);
diff --git a/osi/src/alarm.cc b/osi/src/alarm.cc
index 6e5d22f43e..6f6c7a4248 100644
--- a/osi/src/alarm.cc
+++ b/osi/src/alarm.cc
@@ -678,7 +678,17 @@ static bool timer_create_internal(const clockid_t clock_id, timer_t* timer) {
sigevent.sigev_notify = SIGEV_THREAD;
sigevent.sigev_notify_function = (void (*)(union sigval))timer_callback;
sigevent.sigev_notify_attributes = &thread_attr;
- if (timer_create(clock_id, &sigevent, timer) == -1) {
+
+ int ret = timer_create(clock_id, &sigevent, timer);
+ if (ret == -1) {
+ LOG_ERROR("%s failed to create timer with RT err %s... Try again without RT", __func__, strerror(errno));
+ // Recreate timer without RT priority
+ memset(&sigevent, 0, sizeof(sigevent));
+ sigevent.sigev_notify = SIGEV_THREAD;
+ sigevent.sigev_notify_function = (void (*)(union sigval))timer_callback;
+ ret = timer_create(clock_id, &sigevent, timer);
+ }
+ if (ret == -1) {
LOG_ERROR("%s unable to create timer with clock %d: %s", __func__, clock_id,
strerror(errno));
if (clock_id == CLOCK_BOOTTIME_ALARM) {
diff --git a/stack/btu/btu_task.cc b/stack/btu/btu_task.cc
index 5e83e4d07e..33e7264fdb 100644
--- a/stack/btu/btu_task.cc
+++ b/stack/btu/btu_task.cc
@@ -121,7 +121,7 @@ void main_thread_start_up() {
LOG(FATAL) << __func__ << ": unable to start btu message loop thread.";
}
if (!main_thread.EnableRealTimeScheduling()) {
- LOG(FATAL) << __func__ << ": unable to enable real time scheduling";
+ LOG(ERROR) << __func__ << ": unable to enable real time scheduling";
}
}
--
2.29.2