Loading system/btif/Android.bp +17 −17 Original line number Diff line number Diff line Loading @@ -24,8 +24,8 @@ btifCommonIncludes = [ "packages/modules/Bluetooth/system/utils/include", "packages/modules/Bluetooth/system/include", "system/libhwbinder/include", "system/security/keystore/include", "hardware/interfaces/keymaster/4.0/support/include", //"system/security/keystore/include", //"hardware/interfaces/keymaster/4.0/support/include", ] // libbtif static library for target Loading Loading @@ -73,7 +73,7 @@ cc_library_static { "src/btif_hf_client.cc", "src/btif_hh.cc", "src/btif_hd.cc", "src/btif_keystore.cc", //"src/btif_keystore.cc", "src/btif_mce.cc", "src/btif_pan.cc", "src/btif_profile_queue.cc", Loading Loading @@ -107,12 +107,12 @@ cc_library_static { "libhidlbase", "libutils", "libcrypto", "android.hardware.keymaster@4.0", "android.hardware.keymaster@3.0", "libkeymaster4support", "libkeystore_aidl", "libkeystore_binder", "libkeystore_parcelables", //"android.hardware.keymaster@4.0", //"android.hardware.keymaster@3.0", //"libkeymaster4support", //"libkeystore_aidl", //"libkeystore_binder", //"libkeystore_parcelables", ], whole_static_libs: [ "avrcp-target-service", Loading @@ -135,7 +135,7 @@ cc_test { include_dirs: btifCommonIncludes, srcs: [ "test/btif_storage_test.cc", "test/btif_keystore_test.cc" //"test/btif_keystore_test.cc" ], header_libs: ["libbluetooth_headers"], shared_libs: [ Loading @@ -150,13 +150,13 @@ cc_test { "libprocessgroup", "libutils", "libcrypto", "android.hardware.keymaster@4.0", "android.hardware.keymaster@3.0", "libkeymaster4support", "libkeystore_aidl", "libkeystore_binder", "libkeystore_parcelables", "libbinder", //"android.hardware.keymaster@4.0", //"android.hardware.keymaster@3.0", //"libkeymaster4support", //"libkeystore_aidl", //"libkeystore_binder", //"libkeystore_parcelables", //"libbinder", ], static_libs: [ "libbt-bta", Loading system/btif/co/bta_av_co.cc +43 −46 Original line number Diff line number Diff line Loading @@ -1005,6 +1005,11 @@ tA2DP_STATUS BtaAvCo::ProcessSourceGetConfig( memcpy(p_codec_info, p_peer->codec_config, AVDT_CODEC_SIZE); } // report this peer selectable codecs after retrieved all its capabilities. LOG(INFO) << __func__ << ": retrieved " << +p_peer->num_rx_sinks << " capabilities from peer " << p_peer->addr; ReportSourceCodecState(p_peer); return A2DP_SUCCESS; } Loading Loading @@ -1402,8 +1407,7 @@ void BtaAvCo::UpdateMtu(tBTA_AV_HNDL bta_av_handle, } bool BtaAvCo::SetActivePeer(const RawAddress& peer_address) { APPL_TRACE_DEBUG("%s: peer_address=%s", __func__, peer_address.ToString().c_str()); VLOG(1) << __func__ << ": peer_address=" << peer_address; std::lock_guard<std::recursive_mutex> lock(codec_lock_); Loading @@ -1422,8 +1426,8 @@ bool BtaAvCo::SetActivePeer(const RawAddress& peer_address) { active_peer_ = p_peer; memcpy(codec_config_, active_peer_->codec_config, AVDT_CODEC_SIZE); APPL_TRACE_DEBUG("%s: codec = %s", __func__, A2DP_CodecInfoString(codec_config_).c_str()); LOG(INFO) << __func__ << ": codec = " << A2DP_CodecInfoString(codec_config_); // report the selected codec configuration of this new active peer. ReportSourceCodecState(active_peer_); return true; } Loading Loading @@ -1476,12 +1480,12 @@ bool BtaAvCo::SetCodecUserConfig( bool config_updated = false; bool success = true; VLOG(1) << __func__ << ": peer_address=" << peer_address.ToString() << " codec_user_config=" << codec_user_config.ToString(); VLOG(1) << __func__ << ": peer_address=" << peer_address << " codec_user_config={" << codec_user_config.ToString() << "}"; BtaAvCoPeer* p_peer = FindPeer(peer_address); if (p_peer == nullptr) { LOG(ERROR) << __func__ << ": cannot find peer " << peer_address.ToString() LOG(ERROR) << __func__ << ": cannot find peer " << peer_address << " to configure"; success = false; goto done; Loading @@ -1490,7 +1494,7 @@ bool BtaAvCo::SetCodecUserConfig( // Don't call BTA_AvReconfig() prior to retrieving all peer's capabilities if ((p_peer->num_rx_sinks != p_peer->num_sinks) && (p_peer->num_sup_sinks != BTA_AV_CO_NUM_ELEMENTS(p_peer->sinks))) { LOG(WARNING) << __func__ << ": peer " << p_peer->addr.ToString() LOG(WARNING) << __func__ << ": peer " << p_peer->addr << " : not all peer's capabilities have been retrieved"; success = false; goto done; Loading @@ -1504,7 +1508,7 @@ bool BtaAvCo::SetCodecUserConfig( p_sink = p_peer->p_sink; } if (p_sink == nullptr) { LOG(ERROR) << __func__ << ": peer " << p_peer->addr.ToString() LOG(ERROR) << __func__ << ": peer " << p_peer->addr << " : cannot find peer SEP to configure for codec type " << codec_user_config.codec_type; success = false; Loading @@ -1529,7 +1533,7 @@ bool BtaAvCo::SetCodecUserConfig( p_sink = SelectSourceCodec(p_peer); if (p_sink == nullptr) { LOG(ERROR) << __func__ << ": peer " << p_peer->addr.ToString() LOG(ERROR) << __func__ << ": peer " << p_peer->addr << " : cannot set up codec for the peer SINK"; success = false; goto done; Loading @@ -1543,12 +1547,16 @@ bool BtaAvCo::SetCodecUserConfig( } done: // NOTE: We unconditionally send the upcall even if there is no change // or the user config failed. Thus, the caller would always know whether the // request succeeded or failed. // We send the upcall if there is no change or the user config failed for // current active peer, so the caller would know it failed. If there is no // error, the new selected codec configuration would be sent after we are // ready to start a new session with the audio HAL. // For none active peer, we unconditionally send the upcall, so the caller // would always know the result. // NOTE: Currently, the input is restarted by sending an upcall // and informing the Media Framework about the change. if (p_peer != nullptr) { if (p_peer != nullptr && (!restart_output || !success || p_peer != active_peer_)) { return ReportSourceCodecState(p_peer); } Loading @@ -1574,7 +1582,7 @@ bool BtaAvCo::SetCodecAudioConfig( // Don't call BTA_AvReconfig() prior to retrieving all peer's capabilities if ((p_peer->num_rx_sinks != p_peer->num_sinks) && (p_peer->num_sup_sinks != BTA_AV_CO_NUM_ELEMENTS(p_peer->sinks))) { LOG(WARNING) << __func__ << ": peer " << p_peer->addr.ToString() LOG(WARNING) << __func__ << ": peer " << p_peer->addr << " : not all peer's capabilities have been retrieved"; return false; } Loading @@ -1582,7 +1590,7 @@ bool BtaAvCo::SetCodecAudioConfig( // Use the current sink codec const BtaAvCoSep* p_sink = p_peer->p_sink; if (p_sink == nullptr) { LOG(ERROR) << __func__ << ": peer " << p_peer->addr.ToString() LOG(ERROR) << __func__ << ": peer " << p_peer->addr << " : cannot find peer SEP to configure"; return false; } Loading Loading @@ -1613,7 +1621,7 @@ bool BtaAvCo::SetCodecAudioConfig( if (config_updated) { // NOTE: Currently, the input is restarted by sending an upcall // and informing the Media Framework about the change. // and informing the Media Framework about the change of selected codec. return ReportSourceCodecState(p_peer); } Loading @@ -1625,22 +1633,19 @@ bool BtaAvCo::ReportSourceCodecState(BtaAvCoPeer* p_peer) { std::vector<btav_a2dp_codec_config_t> codecs_local_capabilities; std::vector<btav_a2dp_codec_config_t> codecs_selectable_capabilities; APPL_TRACE_DEBUG("%s: peer_address=%s", __func__, p_peer->addr.ToString().c_str()); VLOG(1) << __func__ << ": peer_address=" << p_peer->addr; A2dpCodecs* codecs = p_peer->GetCodecs(); CHECK(codecs != nullptr); if (!codecs->getCodecConfigAndCapabilities(&codec_config, &codecs_local_capabilities, &codecs_selectable_capabilities)) { APPL_TRACE_WARNING( "%s: Peer %s : error reporting audio source codec state: " "cannot get codec config and capabilities", __func__, p_peer->addr.ToString().c_str()); LOG(WARNING) << __func__ << ": Peer " << p_peer->addr << " : error reporting audio source codec state: cannot get " "codec config and capabilities"; return false; } APPL_TRACE_DEBUG("%s: peer %s codec_config=%s", __func__, p_peer->addr.ToString().c_str(), codec_config.ToString().c_str()); LOG(INFO) << __func__ << ": peer " << p_peer->addr << " codec_config={" << codec_config.ToString() << "}"; btif_av_report_source_codec_state(p_peer->addr, codec_config, codecs_local_capabilities, codecs_selectable_capabilities); Loading Loading @@ -1747,19 +1752,14 @@ const BtaAvCoSep* BtaAvCo::SelectSourceCodec(BtaAvCoPeer* p_peer) { // Select the codec for (const auto& iter : p_peer->GetCodecs()->orderedSourceCodecs()) { APPL_TRACE_DEBUG("%s: trying codec %s", __func__, iter->name().c_str()); VLOG(1) << __func__ << ": trying codec " << iter->name(); p_sink = AttemptSourceCodecSelection(*iter, p_peer); if (p_sink != nullptr) { APPL_TRACE_DEBUG("%s: selected codec %s", __func__, iter->name().c_str()); VLOG(1) << __func__ << ": selected codec " << iter->name(); break; } APPL_TRACE_DEBUG("%s: cannot use codec %s", __func__, iter->name().c_str()); VLOG(1) << __func__ << ": cannot use codec " << iter->name(); } // NOTE: Unconditionally dispatch the event to make sure a callback with // the most recent codec info is generated. ReportSourceCodecState(p_peer); return p_sink; } Loading Loading @@ -1999,10 +1999,8 @@ bool BtaAvCo::SetCodecOtaConfig(BtaAvCoPeer* p_peer, bool restart_output = false; bool config_updated = false; APPL_TRACE_DEBUG("%s: peer_address=%s", __func__, p_peer->addr.ToString().c_str()); APPL_TRACE_DEBUG("%s: codec: %s", __func__, A2DP_CodecInfoString(p_ota_codec_config).c_str()); LOG(INFO) << __func__ << ": peer_address=" << p_peer->addr << ", codec: " << A2DP_CodecInfoString(p_ota_codec_config); *p_restart_output = false; Loading @@ -2013,8 +2011,8 @@ bool BtaAvCo::SetCodecOtaConfig(BtaAvCoPeer* p_peer, // There are no peer SEPs if we didn't do the discovery procedure yet. // We have all the information we need from the peer, so we can // proceed with the OTA codec configuration. APPL_TRACE_ERROR("%s: peer %s : cannot find peer SEP to configure", __func__, p_peer->addr.ToString().c_str()); LOG(ERROR) << __func__ << ": peer " << p_peer->addr << " : cannot find peer SEP to configure"; return false; } Loading @@ -2023,15 +2021,14 @@ bool BtaAvCo::SetCodecOtaConfig(BtaAvCoPeer* p_peer, if (!p_peer->GetCodecs()->setCodecOtaConfig( p_ota_codec_config, &peer_params, result_codec_config, &restart_input, &restart_output, &config_updated)) { APPL_TRACE_ERROR("%s: peer %s : cannot set OTA config", __func__, p_peer->addr.ToString().c_str()); LOG(ERROR) << __func__ << ": peer " << p_peer->addr << " : cannot set OTA config"; return false; } if (restart_output) { APPL_TRACE_DEBUG("%s: restart output", __func__); APPL_TRACE_DEBUG("%s: codec: %s", __func__, A2DP_CodecInfoString(result_codec_config).c_str()); VLOG(1) << __func__ << ": restart output for codec: " << A2DP_CodecInfoString(result_codec_config); *p_restart_output = true; p_peer->p_sink = p_sink; Loading @@ -2041,7 +2038,7 @@ bool BtaAvCo::SetCodecOtaConfig(BtaAvCoPeer* p_peer, if (restart_input || config_updated) { // NOTE: Currently, the input is restarted by sending an upcall // and informing the Media Framework about the change. // and informing the Media Framework about the change of selected codec. ReportSourceCodecState(p_peer); } Loading system/btif/src/btif_config.cc +23 −19 Original line number Diff line number Diff line Loading @@ -38,7 +38,7 @@ #include "btif_api.h" #include "btif_common.h" #include "btif_config_transcode.h" #include "btif_keystore.h" //#include "btif_keystore.h" #include "btif_util.h" #include "common/address_obfuscator.h" #include "osi/include/alarm.h" Loading @@ -58,15 +58,15 @@ #define DISABLED "disabled" static const char* TIME_STRING_FORMAT = "%Y-%m-%d %H:%M:%S"; constexpr int kBufferSize = 400 * 10; // initial file is ~400B // constexpr int kBufferSize = 400 * 10; // initial file is ~400B static bool use_key_attestation() { /*static bool use_key_attestation() { return getuid() == AID_BLUETOOTH && is_single_user_mode(); } }*/ #define BT_CONFIG_METRICS_SECTION "Metrics" #define BT_CONFIG_METRICS_SALT_256BIT "Salt256Bit" using bluetooth::BtifKeystore; // using bluetooth::BtifKeystore; using bluetooth::common::AddressObfuscator; // TODO(armansito): Find a better way than searching by a hardcoded path. Loading @@ -93,9 +93,10 @@ static void btif_config_remove_restricted(config_t* config); static std::unique_ptr<config_t> btif_config_open(const char* filename, const char* checksum_filename); // Key attestation static std::string hash_file(const char* filename); static std::string read_checksum_file(const char* filename); static void write_checksum_file(const char* filename, const std::string& hash); // static std::string hash_file(const char* filename); // static std::string read_checksum_file(const char* filename); // static void write_checksum_file(const char* filename, const std::string& // hash); static enum ConfigSource { NOT_LOADED, Loading Loading @@ -176,7 +177,7 @@ static std::recursive_mutex config_lock; // protects operations on |config|. static std::unique_ptr<config_t> config; static alarm_t* config_timer; static BtifKeystore btif_keystore(new keystore::KeystoreClientImpl); // static BtifKeystore btif_keystore(new keystore::KeystoreClientImpl); // Module lifecycle functions Loading @@ -184,6 +185,9 @@ static future_t* init(void) { std::unique_lock<std::recursive_mutex> lock(config_lock); if (is_factory_reset()) delete_config_files(); /*if (is_factory_reset() || (use_key_attestation() && !btif_keystore.DoesKeyExist())) delete_config_files();*/ std::string file_source; Loading Loading @@ -262,7 +266,7 @@ error: } static std::unique_ptr<config_t> btif_config_open(const char* filename, const char* checksum_filename) { // START KEY ATTESTATION /*// START KEY ATTESTATION // Get hash of current file std::string current_hash = hash_file(filename); // Get stored hash Loading @@ -278,7 +282,7 @@ static std::unique_ptr<config_t> btif_config_open(const char* filename, const ch if (current_hash != stored_hash) { return nullptr; } // END KEY ATTESTATION // END KEY ATTESTATION*/ std::unique_ptr<config_t> config = config_new(filename); if (!config) return nullptr; Loading Loading @@ -512,11 +516,11 @@ bool btif_config_clear(void) { bool ret = config_save(*config, CONFIG_FILE_PATH); btif_config_source = RESET; // Save encrypted hash /*// Save encrypted hash std::string current_hash = hash_file(CONFIG_FILE_PATH); if (!current_hash.empty()) { write_checksum_file(CONFIG_FILE_CHECKSUM_PATH, current_hash); } }*/ return ret; } Loading @@ -539,11 +543,11 @@ static void btif_config_write(UNUSED_ATTR uint16_t event, std::unique_ptr<config_t> config_paired = config_new_clone(*config); btif_config_remove_unpaired(config_paired.get()); config_save(*config_paired, CONFIG_FILE_PATH); // Save hash /*// Save hash std::string current_hash = hash_file(CONFIG_FILE_PATH); if (!current_hash.empty()) { write_checksum_file(CONFIG_FILE_CHECKSUM_PATH, current_hash); } }*/ } static void btif_config_remove_unpaired(config_t* conf) { Loading Loading @@ -635,12 +639,12 @@ static bool is_factory_reset(void) { static void delete_config_files(void) { remove(CONFIG_FILE_PATH); remove(CONFIG_BACKUP_PATH); remove(CONFIG_FILE_CHECKSUM_PATH); remove(CONFIG_BACKUP_CHECKSUM_PATH); // remove(CONFIG_FILE_CHECKSUM_PATH); // remove(CONFIG_BACKUP_CHECKSUM_PATH); osi_property_set("persist.bluetooth.factoryreset", "false"); } static std::string hash_file(const char* filename) { /*static std::string hash_file(const char* filename) { if (!use_key_attestation()) { LOG(INFO) << __func__ << ": Disabled for multi-user"; return DISABLED; Loading Loading @@ -696,4 +700,4 @@ static void write_checksum_file(const char* checksum_filename, << __func__ << ": Failed encrypting checksum"; CHECK(checksum_save(encrypted_checksum, checksum_filename)) << __func__ << ": Failed to save checksum!"; } }*/ system/gd/Android.bp +21 −2 Original line number Diff line number Diff line Loading @@ -363,7 +363,7 @@ genrule { tools: [ "bluetooth_packetgen", ], cmd: "$(location bluetooth_packetgen) --include=packages/modules/Bluetooth/system/gd --out=$(genDir) $(in)", cmd: "$(location bluetooth_packetgen) --include=packages/modules/Bluetooth/system/gd --out=$(genDir) --num_shards=5 $(in)", srcs: [ "hci/hci_packets.pdl", "l2cap/l2cap_packets.pdl", Loading @@ -371,8 +371,23 @@ genrule { ], out: [ "hci/hci_packets_python3.cc", "hci/hci_packets_python3_shard_0.cc", "hci/hci_packets_python3_shard_1.cc", "hci/hci_packets_python3_shard_2.cc", "hci/hci_packets_python3_shard_3.cc", "hci/hci_packets_python3_shard_4.cc", "l2cap/l2cap_packets_python3.cc", "l2cap/l2cap_packets_python3_shard_0.cc", "l2cap/l2cap_packets_python3_shard_1.cc", "l2cap/l2cap_packets_python3_shard_2.cc", "l2cap/l2cap_packets_python3_shard_3.cc", "l2cap/l2cap_packets_python3_shard_4.cc", "security/smp_packets_python3.cc", "security/smp_packets_python3_shard_0.cc", "security/smp_packets_python3_shard_1.cc", "security/smp_packets_python3_shard_2.cc", "security/smp_packets_python3_shard_3.cc", "security/smp_packets_python3_shard_4.cc", ], } Loading Loading @@ -590,7 +605,11 @@ cc_defaults { linux_glibc_x86_64: { include_dirs: ["external/python/cpython3/android/linux_x86_64/pyconfig"], cflags: ["-DSOABI=\"cpython-38android-x86_64-linux-gnu\""], suffix: ".cpython-38android-x86_64-linux-gnu", // Commenting out the Linux suffix so that cpython-38-x86_64-linux-gnu // Python 3.8 can also import the untagged .so library per PEP 3149 // Keep this change until Android py3-cmd can run ACTS, gRPC and can // Export Python native symbols such as PyType_Type // suffix: ".cpython-38android-x86_64-linux-gnu", }, windows: { enabled: false, Loading system/gd/cert/bluetooth_packets_python3_setup.py 0 → 100644 +75 −0 Original line number Diff line number Diff line #!/usr/bin/env python3 # # Copyright 2019 - The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Usage: # 1. Run envsetup and lunch first in an Android checkout # 2. Make target bluetooth_packets_python3 that will generate C++ sources for the # Extension # 3. Build only: # python3 bluetooth_packets_python3_setup.py build_ext # Then Find the .so file in build/lib.linux-x86_64-3.X # 4. Install: # python3 bluetooth_packets_python3_setup.py install --user import os import glob from setuptools import setup, Extension ANDROID_BUILD_TOP = os.getenv("ANDROID_BUILD_TOP") PYBIND11_INCLUDE_DIR = os.path.join(ANDROID_BUILD_TOP, "external/python/pybind11/include") GD_DIR = os.path.join(ANDROID_BUILD_TOP, "packages/modules/Bluetooth/system/gd") BT_PACKETS_GEN_DIR = os.path.join(ANDROID_BUILD_TOP, "out/soong/.intermediates/packages/modules/Bluetooth/system/gd/BluetoothGeneratedPackets_h/gen") BT_PACKETS_PY3_GEN_DIR = os.path.join(ANDROID_BUILD_TOP, "out/soong/.intermediates/packages/modules/Bluetooth/system/gd/BluetoothGeneratedPackets_python3_cc/gen") BT_PACKETS_BASE_SRCS = [ os.path.join(GD_DIR, "l2cap/fcs.cc"), os.path.join(GD_DIR, "packet/bit_inserter.cc"), os.path.join(GD_DIR, "packet/byte_inserter.cc"), os.path.join(GD_DIR, "packet/byte_observer.cc"), os.path.join(GD_DIR, "packet/iterator.cc"), os.path.join(GD_DIR, "packet/fragmenting_inserter.cc"), os.path.join(GD_DIR, "packet/packet_view.cc"), os.path.join(GD_DIR, "packet/raw_builder.cc"), os.path.join(GD_DIR, "packet/view.cc"), ] BT_PACKETS_PY3_SRCs = \ [os.path.join(GD_DIR, "packet/python3_module.cc")] \ + glob.glob(os.path.join(BT_PACKETS_PY3_GEN_DIR, "hci", "*.cc")) \ + glob.glob(os.path.join(BT_PACKETS_PY3_GEN_DIR, "l2cap", "*.cc")) \ + glob.glob(os.path.join(BT_PACKETS_PY3_GEN_DIR, "security", "*.cc")) bluetooth_packets_python3_module = Extension('bluetooth_packets_python3', sources=BT_PACKETS_BASE_SRCS + BT_PACKETS_PY3_SRCs, include_dirs=[GD_DIR, BT_PACKETS_GEN_DIR, BT_PACKETS_PY3_GEN_DIR, PYBIND11_INCLUDE_DIR], extra_compile_args=['-std=c++17'] ) setup(name='bluetooth_packets_python3', version='1.0', author="Android Open Source Project", description="""Bluetooth Packet Library""", ext_modules=[bluetooth_packets_python3_module], py_modules=["bluetooth_packets_python3"], ) Loading
system/btif/Android.bp +17 −17 Original line number Diff line number Diff line Loading @@ -24,8 +24,8 @@ btifCommonIncludes = [ "packages/modules/Bluetooth/system/utils/include", "packages/modules/Bluetooth/system/include", "system/libhwbinder/include", "system/security/keystore/include", "hardware/interfaces/keymaster/4.0/support/include", //"system/security/keystore/include", //"hardware/interfaces/keymaster/4.0/support/include", ] // libbtif static library for target Loading Loading @@ -73,7 +73,7 @@ cc_library_static { "src/btif_hf_client.cc", "src/btif_hh.cc", "src/btif_hd.cc", "src/btif_keystore.cc", //"src/btif_keystore.cc", "src/btif_mce.cc", "src/btif_pan.cc", "src/btif_profile_queue.cc", Loading Loading @@ -107,12 +107,12 @@ cc_library_static { "libhidlbase", "libutils", "libcrypto", "android.hardware.keymaster@4.0", "android.hardware.keymaster@3.0", "libkeymaster4support", "libkeystore_aidl", "libkeystore_binder", "libkeystore_parcelables", //"android.hardware.keymaster@4.0", //"android.hardware.keymaster@3.0", //"libkeymaster4support", //"libkeystore_aidl", //"libkeystore_binder", //"libkeystore_parcelables", ], whole_static_libs: [ "avrcp-target-service", Loading @@ -135,7 +135,7 @@ cc_test { include_dirs: btifCommonIncludes, srcs: [ "test/btif_storage_test.cc", "test/btif_keystore_test.cc" //"test/btif_keystore_test.cc" ], header_libs: ["libbluetooth_headers"], shared_libs: [ Loading @@ -150,13 +150,13 @@ cc_test { "libprocessgroup", "libutils", "libcrypto", "android.hardware.keymaster@4.0", "android.hardware.keymaster@3.0", "libkeymaster4support", "libkeystore_aidl", "libkeystore_binder", "libkeystore_parcelables", "libbinder", //"android.hardware.keymaster@4.0", //"android.hardware.keymaster@3.0", //"libkeymaster4support", //"libkeystore_aidl", //"libkeystore_binder", //"libkeystore_parcelables", //"libbinder", ], static_libs: [ "libbt-bta", Loading
system/btif/co/bta_av_co.cc +43 −46 Original line number Diff line number Diff line Loading @@ -1005,6 +1005,11 @@ tA2DP_STATUS BtaAvCo::ProcessSourceGetConfig( memcpy(p_codec_info, p_peer->codec_config, AVDT_CODEC_SIZE); } // report this peer selectable codecs after retrieved all its capabilities. LOG(INFO) << __func__ << ": retrieved " << +p_peer->num_rx_sinks << " capabilities from peer " << p_peer->addr; ReportSourceCodecState(p_peer); return A2DP_SUCCESS; } Loading Loading @@ -1402,8 +1407,7 @@ void BtaAvCo::UpdateMtu(tBTA_AV_HNDL bta_av_handle, } bool BtaAvCo::SetActivePeer(const RawAddress& peer_address) { APPL_TRACE_DEBUG("%s: peer_address=%s", __func__, peer_address.ToString().c_str()); VLOG(1) << __func__ << ": peer_address=" << peer_address; std::lock_guard<std::recursive_mutex> lock(codec_lock_); Loading @@ -1422,8 +1426,8 @@ bool BtaAvCo::SetActivePeer(const RawAddress& peer_address) { active_peer_ = p_peer; memcpy(codec_config_, active_peer_->codec_config, AVDT_CODEC_SIZE); APPL_TRACE_DEBUG("%s: codec = %s", __func__, A2DP_CodecInfoString(codec_config_).c_str()); LOG(INFO) << __func__ << ": codec = " << A2DP_CodecInfoString(codec_config_); // report the selected codec configuration of this new active peer. ReportSourceCodecState(active_peer_); return true; } Loading Loading @@ -1476,12 +1480,12 @@ bool BtaAvCo::SetCodecUserConfig( bool config_updated = false; bool success = true; VLOG(1) << __func__ << ": peer_address=" << peer_address.ToString() << " codec_user_config=" << codec_user_config.ToString(); VLOG(1) << __func__ << ": peer_address=" << peer_address << " codec_user_config={" << codec_user_config.ToString() << "}"; BtaAvCoPeer* p_peer = FindPeer(peer_address); if (p_peer == nullptr) { LOG(ERROR) << __func__ << ": cannot find peer " << peer_address.ToString() LOG(ERROR) << __func__ << ": cannot find peer " << peer_address << " to configure"; success = false; goto done; Loading @@ -1490,7 +1494,7 @@ bool BtaAvCo::SetCodecUserConfig( // Don't call BTA_AvReconfig() prior to retrieving all peer's capabilities if ((p_peer->num_rx_sinks != p_peer->num_sinks) && (p_peer->num_sup_sinks != BTA_AV_CO_NUM_ELEMENTS(p_peer->sinks))) { LOG(WARNING) << __func__ << ": peer " << p_peer->addr.ToString() LOG(WARNING) << __func__ << ": peer " << p_peer->addr << " : not all peer's capabilities have been retrieved"; success = false; goto done; Loading @@ -1504,7 +1508,7 @@ bool BtaAvCo::SetCodecUserConfig( p_sink = p_peer->p_sink; } if (p_sink == nullptr) { LOG(ERROR) << __func__ << ": peer " << p_peer->addr.ToString() LOG(ERROR) << __func__ << ": peer " << p_peer->addr << " : cannot find peer SEP to configure for codec type " << codec_user_config.codec_type; success = false; Loading @@ -1529,7 +1533,7 @@ bool BtaAvCo::SetCodecUserConfig( p_sink = SelectSourceCodec(p_peer); if (p_sink == nullptr) { LOG(ERROR) << __func__ << ": peer " << p_peer->addr.ToString() LOG(ERROR) << __func__ << ": peer " << p_peer->addr << " : cannot set up codec for the peer SINK"; success = false; goto done; Loading @@ -1543,12 +1547,16 @@ bool BtaAvCo::SetCodecUserConfig( } done: // NOTE: We unconditionally send the upcall even if there is no change // or the user config failed. Thus, the caller would always know whether the // request succeeded or failed. // We send the upcall if there is no change or the user config failed for // current active peer, so the caller would know it failed. If there is no // error, the new selected codec configuration would be sent after we are // ready to start a new session with the audio HAL. // For none active peer, we unconditionally send the upcall, so the caller // would always know the result. // NOTE: Currently, the input is restarted by sending an upcall // and informing the Media Framework about the change. if (p_peer != nullptr) { if (p_peer != nullptr && (!restart_output || !success || p_peer != active_peer_)) { return ReportSourceCodecState(p_peer); } Loading @@ -1574,7 +1582,7 @@ bool BtaAvCo::SetCodecAudioConfig( // Don't call BTA_AvReconfig() prior to retrieving all peer's capabilities if ((p_peer->num_rx_sinks != p_peer->num_sinks) && (p_peer->num_sup_sinks != BTA_AV_CO_NUM_ELEMENTS(p_peer->sinks))) { LOG(WARNING) << __func__ << ": peer " << p_peer->addr.ToString() LOG(WARNING) << __func__ << ": peer " << p_peer->addr << " : not all peer's capabilities have been retrieved"; return false; } Loading @@ -1582,7 +1590,7 @@ bool BtaAvCo::SetCodecAudioConfig( // Use the current sink codec const BtaAvCoSep* p_sink = p_peer->p_sink; if (p_sink == nullptr) { LOG(ERROR) << __func__ << ": peer " << p_peer->addr.ToString() LOG(ERROR) << __func__ << ": peer " << p_peer->addr << " : cannot find peer SEP to configure"; return false; } Loading Loading @@ -1613,7 +1621,7 @@ bool BtaAvCo::SetCodecAudioConfig( if (config_updated) { // NOTE: Currently, the input is restarted by sending an upcall // and informing the Media Framework about the change. // and informing the Media Framework about the change of selected codec. return ReportSourceCodecState(p_peer); } Loading @@ -1625,22 +1633,19 @@ bool BtaAvCo::ReportSourceCodecState(BtaAvCoPeer* p_peer) { std::vector<btav_a2dp_codec_config_t> codecs_local_capabilities; std::vector<btav_a2dp_codec_config_t> codecs_selectable_capabilities; APPL_TRACE_DEBUG("%s: peer_address=%s", __func__, p_peer->addr.ToString().c_str()); VLOG(1) << __func__ << ": peer_address=" << p_peer->addr; A2dpCodecs* codecs = p_peer->GetCodecs(); CHECK(codecs != nullptr); if (!codecs->getCodecConfigAndCapabilities(&codec_config, &codecs_local_capabilities, &codecs_selectable_capabilities)) { APPL_TRACE_WARNING( "%s: Peer %s : error reporting audio source codec state: " "cannot get codec config and capabilities", __func__, p_peer->addr.ToString().c_str()); LOG(WARNING) << __func__ << ": Peer " << p_peer->addr << " : error reporting audio source codec state: cannot get " "codec config and capabilities"; return false; } APPL_TRACE_DEBUG("%s: peer %s codec_config=%s", __func__, p_peer->addr.ToString().c_str(), codec_config.ToString().c_str()); LOG(INFO) << __func__ << ": peer " << p_peer->addr << " codec_config={" << codec_config.ToString() << "}"; btif_av_report_source_codec_state(p_peer->addr, codec_config, codecs_local_capabilities, codecs_selectable_capabilities); Loading Loading @@ -1747,19 +1752,14 @@ const BtaAvCoSep* BtaAvCo::SelectSourceCodec(BtaAvCoPeer* p_peer) { // Select the codec for (const auto& iter : p_peer->GetCodecs()->orderedSourceCodecs()) { APPL_TRACE_DEBUG("%s: trying codec %s", __func__, iter->name().c_str()); VLOG(1) << __func__ << ": trying codec " << iter->name(); p_sink = AttemptSourceCodecSelection(*iter, p_peer); if (p_sink != nullptr) { APPL_TRACE_DEBUG("%s: selected codec %s", __func__, iter->name().c_str()); VLOG(1) << __func__ << ": selected codec " << iter->name(); break; } APPL_TRACE_DEBUG("%s: cannot use codec %s", __func__, iter->name().c_str()); VLOG(1) << __func__ << ": cannot use codec " << iter->name(); } // NOTE: Unconditionally dispatch the event to make sure a callback with // the most recent codec info is generated. ReportSourceCodecState(p_peer); return p_sink; } Loading Loading @@ -1999,10 +1999,8 @@ bool BtaAvCo::SetCodecOtaConfig(BtaAvCoPeer* p_peer, bool restart_output = false; bool config_updated = false; APPL_TRACE_DEBUG("%s: peer_address=%s", __func__, p_peer->addr.ToString().c_str()); APPL_TRACE_DEBUG("%s: codec: %s", __func__, A2DP_CodecInfoString(p_ota_codec_config).c_str()); LOG(INFO) << __func__ << ": peer_address=" << p_peer->addr << ", codec: " << A2DP_CodecInfoString(p_ota_codec_config); *p_restart_output = false; Loading @@ -2013,8 +2011,8 @@ bool BtaAvCo::SetCodecOtaConfig(BtaAvCoPeer* p_peer, // There are no peer SEPs if we didn't do the discovery procedure yet. // We have all the information we need from the peer, so we can // proceed with the OTA codec configuration. APPL_TRACE_ERROR("%s: peer %s : cannot find peer SEP to configure", __func__, p_peer->addr.ToString().c_str()); LOG(ERROR) << __func__ << ": peer " << p_peer->addr << " : cannot find peer SEP to configure"; return false; } Loading @@ -2023,15 +2021,14 @@ bool BtaAvCo::SetCodecOtaConfig(BtaAvCoPeer* p_peer, if (!p_peer->GetCodecs()->setCodecOtaConfig( p_ota_codec_config, &peer_params, result_codec_config, &restart_input, &restart_output, &config_updated)) { APPL_TRACE_ERROR("%s: peer %s : cannot set OTA config", __func__, p_peer->addr.ToString().c_str()); LOG(ERROR) << __func__ << ": peer " << p_peer->addr << " : cannot set OTA config"; return false; } if (restart_output) { APPL_TRACE_DEBUG("%s: restart output", __func__); APPL_TRACE_DEBUG("%s: codec: %s", __func__, A2DP_CodecInfoString(result_codec_config).c_str()); VLOG(1) << __func__ << ": restart output for codec: " << A2DP_CodecInfoString(result_codec_config); *p_restart_output = true; p_peer->p_sink = p_sink; Loading @@ -2041,7 +2038,7 @@ bool BtaAvCo::SetCodecOtaConfig(BtaAvCoPeer* p_peer, if (restart_input || config_updated) { // NOTE: Currently, the input is restarted by sending an upcall // and informing the Media Framework about the change. // and informing the Media Framework about the change of selected codec. ReportSourceCodecState(p_peer); } Loading
system/btif/src/btif_config.cc +23 −19 Original line number Diff line number Diff line Loading @@ -38,7 +38,7 @@ #include "btif_api.h" #include "btif_common.h" #include "btif_config_transcode.h" #include "btif_keystore.h" //#include "btif_keystore.h" #include "btif_util.h" #include "common/address_obfuscator.h" #include "osi/include/alarm.h" Loading @@ -58,15 +58,15 @@ #define DISABLED "disabled" static const char* TIME_STRING_FORMAT = "%Y-%m-%d %H:%M:%S"; constexpr int kBufferSize = 400 * 10; // initial file is ~400B // constexpr int kBufferSize = 400 * 10; // initial file is ~400B static bool use_key_attestation() { /*static bool use_key_attestation() { return getuid() == AID_BLUETOOTH && is_single_user_mode(); } }*/ #define BT_CONFIG_METRICS_SECTION "Metrics" #define BT_CONFIG_METRICS_SALT_256BIT "Salt256Bit" using bluetooth::BtifKeystore; // using bluetooth::BtifKeystore; using bluetooth::common::AddressObfuscator; // TODO(armansito): Find a better way than searching by a hardcoded path. Loading @@ -93,9 +93,10 @@ static void btif_config_remove_restricted(config_t* config); static std::unique_ptr<config_t> btif_config_open(const char* filename, const char* checksum_filename); // Key attestation static std::string hash_file(const char* filename); static std::string read_checksum_file(const char* filename); static void write_checksum_file(const char* filename, const std::string& hash); // static std::string hash_file(const char* filename); // static std::string read_checksum_file(const char* filename); // static void write_checksum_file(const char* filename, const std::string& // hash); static enum ConfigSource { NOT_LOADED, Loading Loading @@ -176,7 +177,7 @@ static std::recursive_mutex config_lock; // protects operations on |config|. static std::unique_ptr<config_t> config; static alarm_t* config_timer; static BtifKeystore btif_keystore(new keystore::KeystoreClientImpl); // static BtifKeystore btif_keystore(new keystore::KeystoreClientImpl); // Module lifecycle functions Loading @@ -184,6 +185,9 @@ static future_t* init(void) { std::unique_lock<std::recursive_mutex> lock(config_lock); if (is_factory_reset()) delete_config_files(); /*if (is_factory_reset() || (use_key_attestation() && !btif_keystore.DoesKeyExist())) delete_config_files();*/ std::string file_source; Loading Loading @@ -262,7 +266,7 @@ error: } static std::unique_ptr<config_t> btif_config_open(const char* filename, const char* checksum_filename) { // START KEY ATTESTATION /*// START KEY ATTESTATION // Get hash of current file std::string current_hash = hash_file(filename); // Get stored hash Loading @@ -278,7 +282,7 @@ static std::unique_ptr<config_t> btif_config_open(const char* filename, const ch if (current_hash != stored_hash) { return nullptr; } // END KEY ATTESTATION // END KEY ATTESTATION*/ std::unique_ptr<config_t> config = config_new(filename); if (!config) return nullptr; Loading Loading @@ -512,11 +516,11 @@ bool btif_config_clear(void) { bool ret = config_save(*config, CONFIG_FILE_PATH); btif_config_source = RESET; // Save encrypted hash /*// Save encrypted hash std::string current_hash = hash_file(CONFIG_FILE_PATH); if (!current_hash.empty()) { write_checksum_file(CONFIG_FILE_CHECKSUM_PATH, current_hash); } }*/ return ret; } Loading @@ -539,11 +543,11 @@ static void btif_config_write(UNUSED_ATTR uint16_t event, std::unique_ptr<config_t> config_paired = config_new_clone(*config); btif_config_remove_unpaired(config_paired.get()); config_save(*config_paired, CONFIG_FILE_PATH); // Save hash /*// Save hash std::string current_hash = hash_file(CONFIG_FILE_PATH); if (!current_hash.empty()) { write_checksum_file(CONFIG_FILE_CHECKSUM_PATH, current_hash); } }*/ } static void btif_config_remove_unpaired(config_t* conf) { Loading Loading @@ -635,12 +639,12 @@ static bool is_factory_reset(void) { static void delete_config_files(void) { remove(CONFIG_FILE_PATH); remove(CONFIG_BACKUP_PATH); remove(CONFIG_FILE_CHECKSUM_PATH); remove(CONFIG_BACKUP_CHECKSUM_PATH); // remove(CONFIG_FILE_CHECKSUM_PATH); // remove(CONFIG_BACKUP_CHECKSUM_PATH); osi_property_set("persist.bluetooth.factoryreset", "false"); } static std::string hash_file(const char* filename) { /*static std::string hash_file(const char* filename) { if (!use_key_attestation()) { LOG(INFO) << __func__ << ": Disabled for multi-user"; return DISABLED; Loading Loading @@ -696,4 +700,4 @@ static void write_checksum_file(const char* checksum_filename, << __func__ << ": Failed encrypting checksum"; CHECK(checksum_save(encrypted_checksum, checksum_filename)) << __func__ << ": Failed to save checksum!"; } }*/
system/gd/Android.bp +21 −2 Original line number Diff line number Diff line Loading @@ -363,7 +363,7 @@ genrule { tools: [ "bluetooth_packetgen", ], cmd: "$(location bluetooth_packetgen) --include=packages/modules/Bluetooth/system/gd --out=$(genDir) $(in)", cmd: "$(location bluetooth_packetgen) --include=packages/modules/Bluetooth/system/gd --out=$(genDir) --num_shards=5 $(in)", srcs: [ "hci/hci_packets.pdl", "l2cap/l2cap_packets.pdl", Loading @@ -371,8 +371,23 @@ genrule { ], out: [ "hci/hci_packets_python3.cc", "hci/hci_packets_python3_shard_0.cc", "hci/hci_packets_python3_shard_1.cc", "hci/hci_packets_python3_shard_2.cc", "hci/hci_packets_python3_shard_3.cc", "hci/hci_packets_python3_shard_4.cc", "l2cap/l2cap_packets_python3.cc", "l2cap/l2cap_packets_python3_shard_0.cc", "l2cap/l2cap_packets_python3_shard_1.cc", "l2cap/l2cap_packets_python3_shard_2.cc", "l2cap/l2cap_packets_python3_shard_3.cc", "l2cap/l2cap_packets_python3_shard_4.cc", "security/smp_packets_python3.cc", "security/smp_packets_python3_shard_0.cc", "security/smp_packets_python3_shard_1.cc", "security/smp_packets_python3_shard_2.cc", "security/smp_packets_python3_shard_3.cc", "security/smp_packets_python3_shard_4.cc", ], } Loading Loading @@ -590,7 +605,11 @@ cc_defaults { linux_glibc_x86_64: { include_dirs: ["external/python/cpython3/android/linux_x86_64/pyconfig"], cflags: ["-DSOABI=\"cpython-38android-x86_64-linux-gnu\""], suffix: ".cpython-38android-x86_64-linux-gnu", // Commenting out the Linux suffix so that cpython-38-x86_64-linux-gnu // Python 3.8 can also import the untagged .so library per PEP 3149 // Keep this change until Android py3-cmd can run ACTS, gRPC and can // Export Python native symbols such as PyType_Type // suffix: ".cpython-38android-x86_64-linux-gnu", }, windows: { enabled: false, Loading
system/gd/cert/bluetooth_packets_python3_setup.py 0 → 100644 +75 −0 Original line number Diff line number Diff line #!/usr/bin/env python3 # # Copyright 2019 - The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Usage: # 1. Run envsetup and lunch first in an Android checkout # 2. Make target bluetooth_packets_python3 that will generate C++ sources for the # Extension # 3. Build only: # python3 bluetooth_packets_python3_setup.py build_ext # Then Find the .so file in build/lib.linux-x86_64-3.X # 4. Install: # python3 bluetooth_packets_python3_setup.py install --user import os import glob from setuptools import setup, Extension ANDROID_BUILD_TOP = os.getenv("ANDROID_BUILD_TOP") PYBIND11_INCLUDE_DIR = os.path.join(ANDROID_BUILD_TOP, "external/python/pybind11/include") GD_DIR = os.path.join(ANDROID_BUILD_TOP, "packages/modules/Bluetooth/system/gd") BT_PACKETS_GEN_DIR = os.path.join(ANDROID_BUILD_TOP, "out/soong/.intermediates/packages/modules/Bluetooth/system/gd/BluetoothGeneratedPackets_h/gen") BT_PACKETS_PY3_GEN_DIR = os.path.join(ANDROID_BUILD_TOP, "out/soong/.intermediates/packages/modules/Bluetooth/system/gd/BluetoothGeneratedPackets_python3_cc/gen") BT_PACKETS_BASE_SRCS = [ os.path.join(GD_DIR, "l2cap/fcs.cc"), os.path.join(GD_DIR, "packet/bit_inserter.cc"), os.path.join(GD_DIR, "packet/byte_inserter.cc"), os.path.join(GD_DIR, "packet/byte_observer.cc"), os.path.join(GD_DIR, "packet/iterator.cc"), os.path.join(GD_DIR, "packet/fragmenting_inserter.cc"), os.path.join(GD_DIR, "packet/packet_view.cc"), os.path.join(GD_DIR, "packet/raw_builder.cc"), os.path.join(GD_DIR, "packet/view.cc"), ] BT_PACKETS_PY3_SRCs = \ [os.path.join(GD_DIR, "packet/python3_module.cc")] \ + glob.glob(os.path.join(BT_PACKETS_PY3_GEN_DIR, "hci", "*.cc")) \ + glob.glob(os.path.join(BT_PACKETS_PY3_GEN_DIR, "l2cap", "*.cc")) \ + glob.glob(os.path.join(BT_PACKETS_PY3_GEN_DIR, "security", "*.cc")) bluetooth_packets_python3_module = Extension('bluetooth_packets_python3', sources=BT_PACKETS_BASE_SRCS + BT_PACKETS_PY3_SRCs, include_dirs=[GD_DIR, BT_PACKETS_GEN_DIR, BT_PACKETS_PY3_GEN_DIR, PYBIND11_INCLUDE_DIR], extra_compile_args=['-std=c++17'] ) setup(name='bluetooth_packets_python3', version='1.0', author="Android Open Source Project", description="""Bluetooth Packet Library""", ext_modules=[bluetooth_packets_python3_module], py_modules=["bluetooth_packets_python3"], )