summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TEST_MAPPING3
-rw-r--r--android/app/Android.bp2
-rw-r--r--android/app/src/com/android/bluetooth/a2dp/A2dpService.java11
-rw-r--r--android/app/src/com/android/bluetooth/a2dp/A2dpStateMachine.java2
-rw-r--r--android/app/src/com/android/bluetooth/bass_client/BassClientService.java16
-rw-r--r--android/app/src/com/android/bluetooth/bass_client/BassClientStateMachine.java22
-rw-r--r--android/app/src/com/android/bluetooth/bass_client/BassObjectsFactory.java7
-rw-r--r--android/app/src/com/android/bluetooth/btservice/AdapterService.java1
-rw-r--r--android/app/src/com/android/bluetooth/hearingaid/HearingAidService.java12
-rw-r--r--android/app/src/com/android/bluetooth/hfp/HeadsetService.java52
-rw-r--r--android/app/src/com/android/bluetooth/hfp/HeadsetStateMachine.java4
-rw-r--r--android/app/src/com/android/bluetooth/le_audio/LeAudioNativeInterface.java11
-rw-r--r--android/app/tests/robotests/src/com/android/bluetooth/opp/OppSendFileInfoTest.java12
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/a2dp/A2dpCodecConfigTest.java8
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/a2dp/A2dpServiceBinderTest.java6
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/a2dp/A2dpServiceTest.java16
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/a2dp/A2dpStateMachineTest.java8
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/a2dpsink/A2dpSinkServiceBinderTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/a2dpsink/A2dpSinkServiceTest.java6
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/a2dpsink/A2dpSinkStateMachineTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/a2dpsink/A2dpSinkStreamHandlerTest.java6
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/audio_util/BrowsablePlayerConnectorTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/audio_util/BrowserPlayerWrapperTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/audio_util/ImageTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/audio_util/MediaPlayerListTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/audio_util/MediaPlayerWrapperTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/audio_util/MetadataTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/avrcp/AvrcpVolumeManagerTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpBipClientTest.java6
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerServiceBinderTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerServiceTest.java6
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerStateMachineTest.java6
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpCoverArtProviderTest.java6
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpPlayerTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/bas/BatteryServiceBinderTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/bass_client/BassClientServiceTest.java28
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/bass_client/BassClientStateMachineTest.java22
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/bass_client/BleBroadcastAssistantBinderTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/btservice/ActiveDeviceManagerTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterPropertiesTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceBinderTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceFactoryResetTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceRestartTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceTest.java6
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/btservice/AudioRoutingManagerTest.java8
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/btservice/BondStateMachineTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/btservice/CompanionManagerTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/btservice/DataMigrationTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/btservice/MetricsLoggerTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/btservice/PhonePolicyTest.java6
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/btservice/ProfileServiceTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/btservice/RemoteDevicesTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/btservice/SilenceDeviceManagerTest.java8
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/btservice/bluetoothKeystore/BluetoothKeystoreServiceTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/btservice/storage/DatabaseManagerTest.java6
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/content_profiles/ContentProfileErrorReportUtilsTest.java1
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/csip/BluetoothCsisBinderTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/csip/CsipSetCoordinatorServiceTest.java8
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/csip/CsipSetCoordinatorStateMachineTest.java11
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/gatt/AdvertiseManagerTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/gatt/AppAdvertiseStatsTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/gatt/ContextMapTest.java6
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/gatt/DistanceMeasurementManagerTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/gatt/DistanceMeasurementTrackerTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/gatt/GattDebugUtilsTest.java12
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/gatt/GattServiceBinderTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/gatt/GattServiceTest.java6
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/hap/HapClientNativeInterfaceTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/hap/HapClientStateMachineTest.java11
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/hap/HapClientTest.java8
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/hearingaid/HearingAidNativeInterfaceTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/hearingaid/HearingAidServiceTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/hearingaid/HearingAidStateMachineTest.java8
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/hfp/AtPhonebookTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/hfp/BluetoothHeadsetBinderTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/hfp/HeadsetPhoneStateTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/hfp/HeadsetServiceAndStateMachineTest.java123
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/hfp/HeadsetServiceTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/hfp/HeadsetStateMachineTest.java29
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/hfpclient/HeadsetClientServiceBinderTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/hfpclient/HeadsetClientServiceTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachineTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/hfpclient/HfpNativeInterfaceTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/hfpclient/VendorCommandResponseProcessorTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/hfpclient/connserv/HeadsetClientServiceInterfaceTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/hfpclient/connserv/HfpClientConnectionServiceTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/hfpclient/connserv/HfpClientDeviceBlockTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/hid/BluetoothHidDeviceBinderTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/hid/HidDeviceNativeInterfaceTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/hid/HidDeviceTest.java8
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/hid/HidHostServiceBinderTest.java6
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/hid/HidHostServiceTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/le_audio/ContentControlIdKeeperTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioBinderTest.java6
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioBroadcastServiceTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioBroadcasterNativeInterfaceTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioNativeInterfaceTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioServiceTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioStateMachineTest.java8
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioTmapGattServerTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/le_scan/AppScanStatsTest.java6
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/le_scan/PeriodicScanManagerTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/le_scan/ScanManagerTest.java6
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapContentObserverTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapContentTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapConvoContactElementTest.java14
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapMasInstanceTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapObexServerTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapServiceBinderTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapServiceTest.java6
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapSmsPduTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/map/SmsMmsContactsTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/mapapi/BluetoothMapEmailProviderTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/mapapi/BluetoothMapIMProviderTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientContentTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientServiceBinderTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientServiceTest.java6
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientStateMachineTest.java6
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/mapclient/MnsObexServerTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/mcp/McpServiceTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/mcp/MediaControlGattServiceTest.java6
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/mcp/MediaControlProfileTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppBtEnableActivityTest.java2
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppBtEnablingActivityTest.java6
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppHandoverReceiverTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppLauncherActivityTest.java6
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppManagerTest.java2
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppNotificationTest.java6
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppObexClientSessionTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppObexServerSessionTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppPreferenceTest.java2
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppReceiverTest.java6
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppSendFileInfoTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppServiceCleanupTest.java6
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppServiceTest.java6
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppTransferActivityTest.java6
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppTransferHistoryTest.java6
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppTransferTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppUtilityTest.java14
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/opp/IncomingFileConfirmActivityTest.java6
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/pan/BluetoothTetheringNetworkFactoryTest.java12
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/pan/PanServiceBinderTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/pan/PanServiceTest.java6
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapAuthenticatorTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapCallLogComposerTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapConfigTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapObexServerTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapServiceBinderTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapServiceTest.java6
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapSimVcardManagerTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapUtilsTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapVcardManagerNestedClassesTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapVcardManagerTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/pbap/HandlerForStringBufferTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/pbap/PbapStateMachineTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/pbapclient/BluetoothPbapRequestTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/pbapclient/CallLogPullRequestTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/pbapclient/PbapClientConnectionHandlerTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/pbapclient/PbapClientServiceTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/pbapclient/PbapClientStateMachineTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/sap/SapRilReceiverHidlTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/sap/SapRilReceiverTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/sap/SapServerTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/sap/SapServiceTest.java8
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/sdp/DipTest.java8
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/tbs/TbsGattTest.java6
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/tbs/TbsGenericTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/telephony/BluetoothInCallServiceTest.java6
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/telephony/CallInfoTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/vc/VolumeControlNativeInterfaceTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/vc/VolumeControlServiceTest.java7
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/vc/VolumeControlStateMachineTest.java8
-rw-r--r--flags/gap.aconfig7
-rw-r--r--flags/map.aconfig8
-rw-r--r--floss/pandora/server/hid.py10
-rw-r--r--floss/pandora/server/host.py55
-rw-r--r--floss/pandora/server/security.py31
-rw-r--r--framework/api/system-current.txt2
-rw-r--r--framework/java/android/bluetooth/BluetoothAdapter.java6
-rw-r--r--framework/java/android/bluetooth/BluetoothLeAudio.java2
-rw-r--r--framework/java/android/bluetooth/BluetoothVolumeControl.java203
-rw-r--r--service/Android.bp2
-rw-r--r--service/src/com/android/server/bluetooth/BluetoothAirplaneModeListener.java4
-rw-r--r--service/src/com/android/server/bluetooth/BluetoothManagerService.java16
-rw-r--r--service/src/com/android/server/bluetooth/BluetoothServiceBinder.java6
-rw-r--r--service/src/com/android/server/bluetooth/BluetoothShellCommand.java5
-rw-r--r--service/tests/src/com/android/server/bluetooth/BluetoothManagerServiceTest.java1
-rw-r--r--service/tests/src/com/android/server/bluetooth/BluetoothShellCommandTest.java6
-rw-r--r--sysprop/Android.bp1
-rw-r--r--sysprop/device_id.sysprop26
-rw-r--r--sysprop/exported_include/android_bluetooth_sysprop.h1
-rw-r--r--system/audio_hal_interface/a2dp_encoding_host.cc16
-rw-r--r--system/audio_hal_interface/aidl/a2dp_encoding_aidl.cc16
-rw-r--r--system/audio_hal_interface/hidl/a2dp_encoding_hidl.cc18
-rw-r--r--system/bta/Android.bp79
-rw-r--r--system/bta/ag/bta_ag_act.cc4
-rw-r--r--system/bta/ag/bta_ag_cmd.cc32
-rw-r--r--system/bta/ag/bta_ag_sco.cc16
-rw-r--r--system/bta/av/bta_av_main.cc2
-rw-r--r--system/bta/dm/bta_dm_act.cc4
-rw-r--r--system/bta/dm/bta_dm_cfg.cc10
-rw-r--r--system/bta/dm/bta_dm_int.h2
-rw-r--r--system/bta/dm/bta_dm_pm.cc17
-rw-r--r--system/bta/hearing_aid/hearing_aid_audio_source.cc2
-rw-r--r--system/bta/include/bta_api.h2
-rw-r--r--system/bta/include/bta_api_data_types.h6
-rw-r--r--system/bta/include/bta_jv_api.h24
-rw-r--r--system/bta/include/bta_sec_api.h6
-rw-r--r--system/bta/jv/bta_jv_act.cc255
-rw-r--r--system/bta/jv/bta_jv_api.cc119
-rw-r--r--system/bta/jv/bta_jv_int.h17
-rw-r--r--system/bta/le_audio/broadcaster/broadcaster.cc25
-rw-r--r--system/bta/le_audio/broadcaster/mock_ble_advertising_manager.cc45
-rw-r--r--system/bta/le_audio/broadcaster/state_machine_test.cc2
-rw-r--r--system/bta/le_audio/client.cc35
-rw-r--r--system/bta/le_audio/client_parser.cc55
-rw-r--r--system/bta/le_audio/client_parser.h2
-rw-r--r--system/bta/le_audio/client_parser_test.cc143
-rw-r--r--system/bta/le_audio/codec_manager.cc87
-rw-r--r--system/bta/le_audio/codec_manager.h4
-rw-r--r--system/bta/le_audio/devices.cc38
-rw-r--r--system/bta/le_audio/devices_test.cc52
-rw-r--r--system/bta/le_audio/le_audio_types.cc68
-rw-r--r--system/bta/le_audio/le_audio_types.h95
-rw-r--r--system/bta/le_audio/le_audio_types_test.cc243
-rw-r--r--system/bta/le_audio/le_audio_utils.cc15
-rw-r--r--system/bta/le_audio/le_audio_utils.h1
-rw-r--r--system/bta/le_audio/mock_codec_manager.cc4
-rw-r--r--system/bta/le_audio/mock_codec_manager.h2
-rw-r--r--system/bta/le_audio/state_machine.cc2
-rw-r--r--system/bta/le_audio/state_machine_test.cc38
-rw-r--r--system/bta/le_audio/storage_helper.cc15
-rw-r--r--system/bta/test/bta_jv_test.cc350
-rw-r--r--system/btif/Android.bp11
-rw-r--r--system/btif/avrcp/avrcp_service.cc40
-rw-r--r--system/btif/co/bta_av_co.cc184
-rw-r--r--system/btif/include/bta_av_co.h29
-rw-r--r--system/btif/include/btif_a2dp.h17
-rw-r--r--system/btif/include/btif_a2dp_sink.h8
-rw-r--r--system/btif/include/btif_av.h55
-rw-r--r--system/btif/include/btif_av_co.h14
-rw-r--r--system/btif/include/btif_bqr.h10
-rw-r--r--system/btif/include/btif_common.h28
-rw-r--r--system/btif/include/btif_hd.h6
-rw-r--r--system/btif/include/btif_hh.h6
-rw-r--r--system/btif/src/bluetooth.cc74
-rw-r--r--system/btif/src/btif_a2dp.cc119
-rw-r--r--system/btif/src/btif_a2dp_control.cc101
-rw-r--r--system/btif/src/btif_a2dp_sink.cc170
-rw-r--r--system/btif/src/btif_a2dp_source.cc237
-rw-r--r--system/btif/src/btif_av.cc1402
-rw-r--r--system/btif/src/btif_avrcp_audio_track.cc58
-rw-r--r--system/btif/src/btif_bqr.cc161
-rw-r--r--system/btif/src/btif_config.cc22
-rw-r--r--system/btif/src/btif_config_cache.cc28
-rw-r--r--system/btif/src/btif_core.cc79
-rw-r--r--system/btif/src/btif_csis_client.cc32
-rw-r--r--system/btif/src/btif_dm.cc564
-rw-r--r--system/btif/src/btif_gatt_client.cc49
-rw-r--r--system/btif/src/btif_gatt_server.cc26
-rw-r--r--system/btif/src/btif_gatt_test.cc89
-rw-r--r--system/btif/src/btif_gatt_util.cc14
-rw-r--r--system/btif/src/btif_hd.cc90
-rw-r--r--system/btif/src/btif_hf.cc317
-rw-r--r--system/btif/src/btif_hf_client.cc106
-rw-r--r--system/btif/src/btif_hh.cc429
-rw-r--r--system/btif/src/btif_iot_config.cc10
-rw-r--r--system/btif/src/btif_jni_task.cc6
-rw-r--r--system/btif/src/btif_keystore.cc19
-rw-r--r--system/btif/src/btif_le_audio.cc76
-rw-r--r--system/btif/src/btif_pan.cc108
-rw-r--r--system/btif/src/btif_profile_queue.cc27
-rw-r--r--system/btif/src/btif_profile_storage.cc56
-rw-r--r--system/btif/src/btif_rc.cc895
-rw-r--r--system/btif/src/btif_sdp.cc12
-rw-r--r--system/btif/src/btif_sdp_server.cc86
-rw-r--r--system/btif/src/btif_sock.cc51
-rw-r--r--system/btif/src/btif_sock_l2cap.cc114
-rw-r--r--system/btif/src/btif_sock_rfc.cc202
-rw-r--r--system/btif/src/btif_sock_sco.cc33
-rw-r--r--system/btif/src/btif_sock_sdp.cc103
-rw-r--r--system/btif/src/btif_sock_thread.cc75
-rw-r--r--system/btif/src/btif_sock_util.cc21
-rw-r--r--system/btif/src/btif_storage.cc101
-rw-r--r--system/btif/src/btif_vc.cc80
-rw-r--r--system/btif/src/stack_manager.cc43
-rw-r--r--system/btif/test/btif_rc_test.cc18
-rw-r--r--system/gd/storage/storage_module.cc12
-rw-r--r--system/include/hardware/bluetooth.h16
-rw-r--r--system/include/hardware/bt_av.h5
-rw-r--r--system/include/hardware/bt_hd.h10
-rw-r--r--system/include/hardware/bt_hf.h13
-rw-r--r--system/include/hardware/bt_hh.h10
-rw-r--r--system/include/hardware/bt_rc.h18
-rw-r--r--system/include/hardware/bt_sdp.h10
-rw-r--r--system/include/hardware/bt_sock.h10
-rw-r--r--system/internal_include/bt_target.h47
-rw-r--r--system/log/src/vlog_android.cc11
-rw-r--r--system/log/src/vlog_test.cc57
-rw-r--r--system/stack/Android.bp17
-rw-r--r--system/stack/a2dp/a2dp_aac_encoder_linux.cc2
-rw-r--r--system/stack/avct/avct_lcb_act.cc6
-rw-r--r--system/stack/btm/btm_inq.cc40
-rw-r--r--system/stack/btm/btm_sco_hfp_hal.cc4
-rw-r--r--system/stack/btm/btm_sco_hfp_hal.h4
-rw-r--r--system/stack/btm/btm_sco_hfp_hal_linux.cc71
-rw-r--r--system/stack/btm/btm_sec.cc8
-rw-r--r--system/stack/btm/neighbor_inquiry.h2
-rw-r--r--system/stack/gatt/gatt_main.cc4
-rw-r--r--system/stack/include/btm_sec_api_types.h2
-rw-r--r--system/stack/include/security_client_callbacks.h3
-rw-r--r--system/stack/l2cap/l2c_link.cc70
-rw-r--r--system/stack/mmc/codec_server/BUILD.gn1
-rw-r--r--system/stack/rfcomm/port_rfc.cc14
-rw-r--r--system/stack/rfcomm/rfc_port_if.cc8
-rw-r--r--system/stack/test/sdp/stack_sdp_db_test.cc198
-rw-r--r--system/test/mock/mock_bta_jv_api.cc32
-rw-r--r--system/test/mock/mock_btif_av.cc64
-rw-r--r--system/test/mock/mock_btif_av.h145
-rw-r--r--system/test/mock/mock_main_shim_le_advertising_manager.cc37
-rw-r--r--system/test/mock/mock_main_shim_le_advertising_manager.h (renamed from system/bta/le_audio/broadcaster/mock_ble_advertising_manager.h)0
-rw-r--r--system/test/mock/mock_stack_btm_inq.cc5
-rw-r--r--system/test/mock/mock_stack_btm_inq.h9
-rw-r--r--system/test/mock/mock_stack_btm_sco_hfp_hal.cc4
-rw-r--r--system/test/mock/mock_stack_btm_sco_hfp_hal.h8
-rw-r--r--system/test/mock/mock_stack_gatt_main.cc10
-rw-r--r--system/test/suite/Android.bp9
-rwxr-xr-xsystem/test/tool/mockcify.pl13
-rw-r--r--tools/rootcanal/model/controller/dual_mode_controller.cc12
330 files changed, 6840 insertions, 4700 deletions
diff --git a/TEST_MAPPING b/TEST_MAPPING
index adf5edc13b..8d987ee18a 100644
--- a/TEST_MAPPING
+++ b/TEST_MAPPING
@@ -332,6 +332,9 @@
"name": "CtsStrictJavaPackagesTestCases"
},
{
+ "name": "net_test_bta_jv"
+ },
+ {
"name": "asrc_resampler_test"
}
]
diff --git a/android/app/Android.bp b/android/app/Android.bp
index 095fbf0372..b1d8643cbb 100644
--- a/android/app/Android.bp
+++ b/android/app/Android.bp
@@ -289,11 +289,11 @@ android_app {
javacflags: ["-Aroom.schemaLocation=packages/modules/Bluetooth/android/app/tests/unit/src/com/android/bluetooth/btservice/storage/schemas"],
lint: {
+ // TODO(b/318814235): Add back ObsoleteSdkInt to this list.
error_checks: [
"ExtraText",
"MissingClass",
"NewApi",
- "ObsoleteSdkInt",
"Recycle",
"RtlHardcoded",
"UseSparseArrays",
diff --git a/android/app/src/com/android/bluetooth/a2dp/A2dpService.java b/android/app/src/com/android/bluetooth/a2dp/A2dpService.java
index f22be4abae..c8fb190ab8 100644
--- a/android/app/src/com/android/bluetooth/a2dp/A2dpService.java
+++ b/android/app/src/com/android/bluetooth/a2dp/A2dpService.java
@@ -1367,12 +1367,15 @@ public class A2dpService extends ProfileService {
if (Utils.isInstrumentationTestMode()) {
return mService;
}
- if (!Utils.checkServiceAvailable(mService, TAG)
- || !Utils.checkCallerIsSystemOrActiveOrManagedUser(mService, TAG)
- || !Utils.checkConnectPermissionForDataDelivery(mService, source, TAG)) {
+ A2dpService currService = mService;
+
+ if (currService == null
+ || !Utils.checkServiceAvailable(currService, TAG)
+ || !Utils.checkCallerIsSystemOrActiveOrManagedUser(currService, TAG)
+ || !Utils.checkConnectPermissionForDataDelivery(currService, source, TAG)) {
return null;
}
- return mService;
+ return currService;
}
BluetoothA2dpBinder(A2dpService svc) {
diff --git a/android/app/src/com/android/bluetooth/a2dp/A2dpStateMachine.java b/android/app/src/com/android/bluetooth/a2dp/A2dpStateMachine.java
index f4ba3785a8..7fc29d188f 100644
--- a/android/app/src/com/android/bluetooth/a2dp/A2dpStateMachine.java
+++ b/android/app/src/com/android/bluetooth/a2dp/A2dpStateMachine.java
@@ -728,7 +728,7 @@ final class A2dpStateMachine extends StateMachine {
mA2dpService.codecConfigUpdated(mDevice, mCodecStatus, sameAudioFeedingParameters);
}
- // This method does not check for error conditon (newState == prevState)
+ // This method does not check for error condition (newState == prevState)
private void broadcastConnectionState(int newState, int prevState) {
log("Connection state " + mDevice + ": " + profileStateToString(prevState)
+ "->" + profileStateToString(newState));
diff --git a/android/app/src/com/android/bluetooth/bass_client/BassClientService.java b/android/app/src/com/android/bluetooth/bass_client/BassClientService.java
index 5f726c294a..13538d4192 100644
--- a/android/app/src/com/android/bluetooth/bass_client/BassClientService.java
+++ b/android/app/src/com/android/bluetooth/bass_client/BassClientService.java
@@ -54,8 +54,7 @@ import com.android.bluetooth.btservice.ProfileService;
import com.android.bluetooth.btservice.ServiceFactory;
import com.android.bluetooth.btservice.storage.DatabaseManager;
import com.android.bluetooth.csip.CsipSetCoordinatorService;
-import com.android.bluetooth.flags.FeatureFlags;
-import com.android.bluetooth.flags.FeatureFlagsImpl;
+import com.android.bluetooth.flags.Flags;
import com.android.bluetooth.le_audio.LeAudioService;
import com.android.internal.annotations.VisibleForTesting;
@@ -108,7 +107,6 @@ public class BassClientService extends ProfileService {
private final Map<BluetoothDevice, List<Integer>> mGroupManagedSources =
new ConcurrentHashMap<>();
private final Map<BluetoothDevice, List<Integer>> mActiveSourceMap = new ConcurrentHashMap<>();
- private final FeatureFlags mFeatureFlags;
private final Map<BluetoothDevice, BluetoothLeBroadcastMetadata> mBroadcastMetadataMap =
new ConcurrentHashMap<>();
private final LinkedList<BluetoothDevice> mPausedBroadcastSinks = new LinkedList<>();
@@ -152,13 +150,6 @@ public class BassClientService extends ProfileService {
public BassClientService(Context ctx) {
super(ctx);
- mFeatureFlags = new FeatureFlagsImpl();
- }
-
- @VisibleForTesting
- BassClientService(Context ctx, FeatureFlags featureFlags) {
- super(ctx);
- mFeatureFlags = featureFlags;
}
public static boolean isEnabled() {
@@ -876,8 +867,7 @@ public class BassClientService extends ProfileService {
device,
this,
mAdapterService,
- mStateMachinesThread.getLooper(),
- mFeatureFlags);
+ mStateMachinesThread.getLooper());
if (stateMachine != null) {
mStateMachines.put(device, stateMachine);
}
@@ -1898,7 +1888,7 @@ public class BassClientService extends ProfileService {
}
private boolean isAllowedToAddSource() {
- if (mFeatureFlags.leaudioBroadcastAudioHandoverPolicies()) {
+ if (Flags.leaudioBroadcastAudioHandoverPolicies()) {
/* Check if should wait for status update */
if (mUnicastSourceStreamStatus.isEmpty()) {
/* Assistant was not active, inform about activation */
diff --git a/android/app/src/com/android/bluetooth/bass_client/BassClientStateMachine.java b/android/app/src/com/android/bluetooth/bass_client/BassClientStateMachine.java
index 890f72d061..1f583bbd52 100644
--- a/android/app/src/com/android/bluetooth/bass_client/BassClientStateMachine.java
+++ b/android/app/src/com/android/bluetooth/bass_client/BassClientStateMachine.java
@@ -53,7 +53,7 @@ import com.android.bluetooth.BluetoothMethodProxy;
import com.android.bluetooth.Utils;
import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.ProfileService;
-import com.android.bluetooth.flags.FeatureFlags;
+import com.android.bluetooth.flags.Flags;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.State;
import com.android.internal.util.StateMachine;
@@ -70,7 +70,6 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Objects;
import java.util.Scanner;
import java.util.UUID;
import java.util.stream.IntStream;
@@ -128,7 +127,6 @@ public class BassClientStateMachine extends StateMachine {
private final Connected mConnected = new Connected();
private final Connecting mConnecting = new Connecting();
private final ConnectedProcessing mConnectedProcessing = new ConnectedProcessing();
- private final FeatureFlags mFeatureFlags;
private final List<Pair<ScanResult, Integer>> mSourceSyncRequestsQueue =
new ArrayList<Pair<ScanResult, Integer>>();
@@ -186,14 +184,12 @@ public class BassClientStateMachine extends StateMachine {
BassClientService svc,
AdapterService adapterService,
Looper looper,
- int connectTimeoutMs,
- FeatureFlags featureFlags) {
+ int connectTimeoutMs) {
super(TAG + "(" + device.toString() + ")", looper);
mDevice = device;
mService = svc;
mAdapterService = adapterService;
mConnectTimeoutMs = connectTimeoutMs;
- mFeatureFlags = Objects.requireNonNull(featureFlags, "Feature Flags cannot be null");
addState(mDisconnected);
addState(mConnected);
addState(mConnecting);
@@ -214,8 +210,7 @@ public class BassClientStateMachine extends StateMachine {
BluetoothDevice device,
BassClientService svc,
AdapterService adapterService,
- Looper looper,
- FeatureFlags featureFlags) {
+ Looper looper) {
Log.d(TAG, "make for device " + device);
if (!BassClientPeriodicAdvertisingManager
@@ -226,12 +221,7 @@ public class BassClientStateMachine extends StateMachine {
BassClientStateMachine BassclientSm =
new BassClientStateMachine(
- device,
- svc,
- adapterService,
- looper,
- BassConstants.CONNECT_TIMEOUT_MS,
- featureFlags);
+ device, svc, adapterService, looper, BassConstants.CONNECT_TIMEOUT_MS);
BassclientSm.start();
return BassclientSm;
}
@@ -646,7 +636,7 @@ public class BassClientStateMachine extends StateMachine {
}
}
metaData.setEncrypted(encrypted);
- if (mFeatureFlags.leaudioBroadcastMonitorSourceSyncStatus()) {
+ if (Flags.leaudioBroadcastMonitorSourceSyncStatus()) {
// update the rssi value
ScanResult scanRes = mService.getCachedBroadcast(result.getBroadcastId());
if (scanRes != null) {
@@ -1185,7 +1175,7 @@ public class BassClientStateMachine extends StateMachine {
@Override
public void onSyncLost(int syncHandle) {
log("OnSyncLost" + syncHandle);
- if (mFeatureFlags.leaudioBroadcastMonitorSourceSyncStatus()) {
+ if (Flags.leaudioBroadcastMonitorSourceSyncStatus()) {
int broadcastId = mService.getBroadcastIdForSyncHandle(syncHandle);
if (broadcastId != BassConstants.INVALID_BROADCAST_ID) {
log("Notify broadcast source lost, broadcast id: " + broadcastId);
diff --git a/android/app/src/com/android/bluetooth/bass_client/BassObjectsFactory.java b/android/app/src/com/android/bluetooth/bass_client/BassObjectsFactory.java
index 16f1d9918b..8f17ff6f6b 100644
--- a/android/app/src/com/android/bluetooth/bass_client/BassObjectsFactory.java
+++ b/android/app/src/com/android/bluetooth/bass_client/BassObjectsFactory.java
@@ -23,7 +23,6 @@ import android.util.Log;
import com.android.bluetooth.Utils;
import com.android.bluetooth.btservice.AdapterService;
-import com.android.bluetooth.flags.FeatureFlags;
import com.android.internal.annotations.VisibleForTesting;
/**
@@ -70,16 +69,14 @@ public class BassObjectsFactory {
* @param device the remote device associated with this state machine
* @param svc the bass client service
* @param looper the thread that the state machine is supposed to run on
- * @param featureFlags feature flag from bass client service
* @return a state machine that is initialized and started, ready to go
*/
public BassClientStateMachine makeStateMachine(
BluetoothDevice device,
BassClientService svc,
AdapterService adapterService,
- Looper looper,
- FeatureFlags featureFlags) {
- return BassClientStateMachine.make(device, svc, adapterService, looper, featureFlags);
+ Looper looper) {
+ return BassClientStateMachine.make(device, svc, adapterService, looper);
}
/**
diff --git a/android/app/src/com/android/bluetooth/btservice/AdapterService.java b/android/app/src/com/android/bluetooth/btservice/AdapterService.java
index f4a74f359d..7a2db1bac1 100644
--- a/android/app/src/com/android/bluetooth/btservice/AdapterService.java
+++ b/android/app/src/com/android/bluetooth/btservice/AdapterService.java
@@ -1279,6 +1279,7 @@ public class AdapterService extends Service {
errorLog(
"Cannot switch buffer size. The number of A2DP active devices is "
+ activeDevices.size());
+ return;
}
// Send intent to fastpair
diff --git a/android/app/src/com/android/bluetooth/hearingaid/HearingAidService.java b/android/app/src/com/android/bluetooth/hearingaid/HearingAidService.java
index 5937b07dd6..3d85f02dd2 100644
--- a/android/app/src/com/android/bluetooth/hearingaid/HearingAidService.java
+++ b/android/app/src/com/android/bluetooth/hearingaid/HearingAidService.java
@@ -954,15 +954,17 @@ public class HearingAidService extends ProfileService {
@RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
private HearingAidService getService(AttributionSource source) {
+ // Cache mService because it can change while getService is called b/327929337
+ HearingAidService service = mService;
if (mIsTesting) {
- return mService;
+ return service;
}
- if (!Utils.checkServiceAvailable(mService, TAG)
- || !Utils.checkCallerIsSystemOrActiveOrManagedUser(mService, TAG)
- || !Utils.checkConnectPermissionForDataDelivery(mService, source, TAG)) {
+ if (!Utils.checkServiceAvailable(service, TAG)
+ || !Utils.checkCallerIsSystemOrActiveOrManagedUser(service, TAG)
+ || !Utils.checkConnectPermissionForDataDelivery(service, source, TAG)) {
return null;
}
- return mService;
+ return service;
}
BluetoothHearingAidBinder(HearingAidService svc) {
diff --git a/android/app/src/com/android/bluetooth/hfp/HeadsetService.java b/android/app/src/com/android/bluetooth/hfp/HeadsetService.java
index d6354ddd0b..985ac9de81 100644
--- a/android/app/src/com/android/bluetooth/hfp/HeadsetService.java
+++ b/android/app/src/com/android/bluetooth/hfp/HeadsetService.java
@@ -37,6 +37,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.media.AudioDeviceInfo;
import android.media.AudioManager;
import android.net.Uri;
import android.os.BatteryManager;
@@ -74,6 +75,8 @@ import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
+import java.util.Optional;
+import java.util.concurrent.FutureTask;
/**
* Provides Bluetooth Headset and Handsfree profile, as a service in the Bluetooth application.
@@ -1179,6 +1182,30 @@ public class HeadsetService extends ProfileService {
} else {
stateMachine.sendMessage(HeadsetStateMachine.VOICE_RECOGNITION_START, device);
}
+ if (Flags.isScoManagedByAudio()) {
+ // when isScoManagedByAudio is on, tell AudioManager to connect SCO
+ AudioManager am = mSystemInterface.getAudioManager();
+ BluetoothDevice finalDevice = device;
+ Optional<AudioDeviceInfo> audioDeviceInfo =
+ am.getAvailableCommunicationDevices().stream()
+ .filter(
+ x ->
+ x.getType() == AudioDeviceInfo.TYPE_BLUETOOTH_SCO
+ && x.getAddress()
+ .equals(finalDevice.getAddress()))
+ .findFirst();
+ if (audioDeviceInfo.isPresent()) {
+ am.setCommunicationDevice(audioDeviceInfo.get());
+ Log.i(TAG, "Audio Manager will initiate the SCO connection");
+ return true;
+ }
+ Log.w(
+ TAG,
+ "Cannot find audioDeviceInfo that matches device="
+ + device
+ + " to create the SCO");
+ return false;
+ }
stateMachine.sendMessage(HeadsetStateMachine.CONNECT_AUDIO, device);
}
return true;
@@ -1209,6 +1236,10 @@ public class HeadsetService extends ProfileService {
}
mVoiceRecognitionStarted = false;
stateMachine.sendMessage(HeadsetStateMachine.VOICE_RECOGNITION_STOP, device);
+ if (Flags.isScoManagedByAudio()) {
+ mSystemInterface.getAudioManager().clearCommunicationDevice();
+ return true;
+ }
stateMachine.sendMessage(HeadsetStateMachine.DISCONNECT_AUDIO, device);
}
return true;
@@ -1859,7 +1890,8 @@ public class HeadsetService extends ProfileService {
mSystemInterface.getHeadsetPhoneState().setCallState(callState);
// Suspend A2DP when call about is about to become active
if (mActiveDevice != null && callState != HeadsetHalConstants.CALL_STATE_DISCONNECTED
- && !mSystemInterface.isCallIdle() && isCallIdleBefore) {
+ && !mSystemInterface.isCallIdle() && isCallIdleBefore
+ && !Flags.isScoManagedByAudio()) {
mSystemInterface.getAudioManager().setA2dpSuspended(true);
if (isAtLeastU()) {
mSystemInterface.getAudioManager().setLeAudioSuspended(true);
@@ -1869,9 +1901,25 @@ public class HeadsetService extends ProfileService {
doForEachConnectedStateMachine(
stateMachine -> stateMachine.sendMessage(HeadsetStateMachine.CALL_STATE_CHANGED,
new HeadsetCallState(numActive, numHeld, callState, number, type, name)));
+ if (Flags.isScoManagedByAudio()) {
+ if (mActiveDevice == null) {
+ Log.i(TAG, "HeadsetService's active device is null");
+ } else {
+ // wait until mActiveDevice's state machine processed CALL_STATE_CHANGED message,
+ // then Audio Framework starts the SCO connection
+ FutureTask task = new FutureTask(() -> {}, null);
+ mStateMachines.get(mActiveDevice).getHandler().post(task);
+ try {
+ task.get();
+ } catch (Exception e) {
+ Log.e(TAG,
+ "Exception when waiting for CALL_STATE_CHANGED message" + e.toString());
+ }
+ }
+ }
getStateMachinesThreadHandler().post(() -> {
if (callState == HeadsetHalConstants.CALL_STATE_IDLE
- && mSystemInterface.isCallIdle() && !isAudioOn()) {
+ && mSystemInterface.isCallIdle() && !isAudioOn() && !Flags.isScoManagedByAudio()) {
// Resume A2DP when call ended and SCO is not connected
mSystemInterface.getAudioManager().setA2dpSuspended(false);
if (isAtLeastU()) {
diff --git a/android/app/src/com/android/bluetooth/hfp/HeadsetStateMachine.java b/android/app/src/com/android/bluetooth/hfp/HeadsetStateMachine.java
index 38db4dc656..7bb103f81f 100644
--- a/android/app/src/com/android/bluetooth/hfp/HeadsetStateMachine.java
+++ b/android/app/src/com/android/bluetooth/hfp/HeadsetStateMachine.java
@@ -1689,6 +1689,10 @@ public class HeadsetStateMachine extends StateMachine {
}
private void setAudioParameters() {
+ if (Flags.isScoManagedByAudio()) {
+ Log.i(TAG, "isScoManagedByAudio enabled, do not setAudioParameters");
+ return;
+ }
AudioManager am = mSystemInterface.getAudioManager();
Log.i(
TAG,
diff --git a/android/app/src/com/android/bluetooth/le_audio/LeAudioNativeInterface.java b/android/app/src/com/android/bluetooth/le_audio/LeAudioNativeInterface.java
index 95a6b8bce8..4c0b7ddd88 100644
--- a/android/app/src/com/android/bluetooth/le_audio/LeAudioNativeInterface.java
+++ b/android/app/src/com/android/bluetooth/le_audio/LeAudioNativeInterface.java
@@ -408,17 +408,6 @@ public class LeAudioNativeInterface {
}
/**
- * Confirm streaming request by other profile if there were such request
- */
- public void confirmUnicastStreamRequest() {
- if (DBG) {
- Log.d(TAG, "confirmUnicastStreamRequest");
- }
-
- confirmUnicastStreamRequestNative();
- }
-
- /**
* Sends the audio preferences for the groupId to the native stack.
*
* @param groupId is the groupId corresponding to the preferences
diff --git a/android/app/tests/robotests/src/com/android/bluetooth/opp/OppSendFileInfoTest.java b/android/app/tests/robotests/src/com/android/bluetooth/opp/OppSendFileInfoTest.java
index 22a4284ae1..ea712ef84c 100644
--- a/android/app/tests/robotests/src/com/android/bluetooth/opp/OppSendFileInfoTest.java
+++ b/android/app/tests/robotests/src/com/android/bluetooth/opp/OppSendFileInfoTest.java
@@ -26,11 +26,12 @@ import android.content.ContentResolver;
import android.content.Context;
import android.net.Uri;
-import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import org.robolectric.RobolectricTestRunner;
import java.io.FileInputStream;
@@ -43,15 +44,12 @@ public class OppSendFileInfoTest {
private static final int TEST_FILE_SIZE = 10;
private static final int MAXIMUM_FILE_SIZE = 0xFFFFFFFF;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private Context mContext;
@Mock private ContentResolver mContentResolver;
@Mock private FileInputStream mFileInputStream;
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- }
-
/**
* Test a BluetoothOppSendFileInfo generated from a local file (MIME type: text/plain,
* size: #TEST_FILE_SIZE).
diff --git a/android/app/tests/unit/src/com/android/bluetooth/a2dp/A2dpCodecConfigTest.java b/android/app/tests/unit/src/com/android/bluetooth/a2dp/A2dpCodecConfigTest.java
index 52f2736345..97cf8e0f86 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/a2dp/A2dpCodecConfigTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/a2dp/A2dpCodecConfigTest.java
@@ -34,10 +34,12 @@ import com.android.bluetooth.R;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.Arrays;
@@ -49,6 +51,8 @@ public class A2dpCodecConfigTest {
private BluetoothDevice mTestDevice;
private A2dpCodecConfig mA2dpCodecConfig;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private Context mMockContext;
@Mock private Resources mMockResources;
@Mock private A2dpNativeInterface mA2dpNativeInterface;
@@ -159,8 +163,6 @@ public class A2dpCodecConfigTest {
@Before
public void setUp() throws Exception {
- // Set up mocks and test assets
- MockitoAnnotations.initMocks(this);
mTargetContext = InstrumentationRegistry.getTargetContext();
when(mMockContext.getResources()).thenReturn(mMockResources);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/a2dp/A2dpServiceBinderTest.java b/android/app/tests/unit/src/com/android/bluetooth/a2dp/A2dpServiceBinderTest.java
index 58655f6a2c..cc7a361d3b 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/a2dp/A2dpServiceBinderTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/a2dp/A2dpServiceBinderTest.java
@@ -45,7 +45,8 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.List;
@@ -56,6 +57,8 @@ public class A2dpServiceBinderTest {
@Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private A2dpService mA2dpService;
@Mock private AudioRoutingManager mAudioRoutingManager;
@Mock private PackageManager mPackageManager;
@@ -64,7 +67,6 @@ public class A2dpServiceBinderTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
doReturn(mAudioRoutingManager).when(mA2dpService).getActiveDeviceManager();
doReturn(mPackageManager).when(mA2dpService).getPackageManager();
ApplicationInfo appInfo = new ApplicationInfo();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/a2dp/A2dpServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/a2dp/A2dpServiceTest.java
index faa2833dfc..21d4645798 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/a2dp/A2dpServiceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/a2dp/A2dpServiceTest.java
@@ -50,13 +50,15 @@ import org.hamcrest.core.AllOf;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
import org.mockito.hamcrest.MockitoHamcrest;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.time.Duration;
import java.util.Arrays;
@@ -72,6 +74,8 @@ public class A2dpServiceTest {
private static final BluetoothDevice sTestDevice =
sAdapter.getRemoteDevice("00:01:02:03:04:05");
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private A2dpNativeInterface mMockNativeInterface;
@Mock private ActiveDeviceManager mActiveDeviceManager;
@Mock private AdapterService mAdapterService;
@@ -84,8 +88,6 @@ public class A2dpServiceTest {
@Before
public void setUp() throws Exception {
- // Set up mocks and test assets
- MockitoAnnotations.initMocks(this);
mInOrder = inOrder(mAdapterService);
TestUtils.mockGetSystemService(
@@ -122,8 +124,12 @@ public class A2dpServiceTest {
}
@After
- public void tearDown() throws Exception {
- mA2dpService.stop();
+ public void tearDown() {
+ // A2dpService handler is running on main looper. Calling `stop` remove the messages but
+ // assume it is already on the correct thread.
+ // Calling it from another thread may lead to having messages still being processed and
+ // executed after tearDown is called.
+ InstrumentationRegistry.getInstrumentation().runOnMainSync(mA2dpService::stop);
}
@SafeVarargs
diff --git a/android/app/tests/unit/src/com/android/bluetooth/a2dp/A2dpStateMachineTest.java b/android/app/tests/unit/src/com/android/bluetooth/a2dp/A2dpStateMachineTest.java
index 0c6fdc6936..98cee48f89 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/a2dp/A2dpStateMachineTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/a2dp/A2dpStateMachineTest.java
@@ -42,11 +42,13 @@ import org.hamcrest.core.IsInstanceOf;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.Arrays;
@@ -64,6 +66,8 @@ public class A2dpStateMachineTest {
private BluetoothCodecConfig mCodecConfigAac;
private BluetoothCodecConfig mCodecConfigOpus;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private ActiveDeviceManager mActiveDeviceManager;
@Mock private SilenceDeviceManager mSilenceDeviceManager;
@@ -73,8 +77,6 @@ public class A2dpStateMachineTest {
@Before
public void setUp() throws Exception {
mTargetContext = InstrumentationRegistry.getTargetContext();
- // Set up mocks and test assets
- MockitoAnnotations.initMocks(this);
doReturn(mActiveDeviceManager).when(mAdapterService).getActiveDeviceManager();
doReturn(mSilenceDeviceManager).when(mAdapterService).getSilenceDeviceManager();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/a2dpsink/A2dpSinkServiceBinderTest.java b/android/app/tests/unit/src/com/android/bluetooth/a2dpsink/A2dpSinkServiceBinderTest.java
index 0d1650ee00..23641be621 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/a2dpsink/A2dpSinkServiceBinderTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/a2dpsink/A2dpSinkServiceBinderTest.java
@@ -29,20 +29,23 @@ import com.android.bluetooth.x.com.android.modules.utils.SynchronousResultReceiv
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.List;
public class A2dpSinkServiceBinderTest {
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private A2dpSinkService mService;
private A2dpSinkService.A2dpSinkServiceBinder mBinder;
private BluetoothAdapter mAdapter;
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mAdapter = BluetoothAdapter.getDefaultAdapter();
mBinder = new A2dpSinkService.A2dpSinkServiceBinder(mService);
}
diff --git a/android/app/tests/unit/src/com/android/bluetooth/a2dpsink/A2dpSinkServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/a2dpsink/A2dpSinkServiceTest.java
index 6f546daa9d..d19e6aa5a9 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/a2dpsink/A2dpSinkServiceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/a2dpsink/A2dpSinkServiceTest.java
@@ -43,7 +43,8 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.ArrayList;
import java.util.List;
@@ -57,6 +58,8 @@ public class A2dpSinkServiceTest {
@Rule public final ServiceTestRule mServiceRule = new ServiceTestRule();
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private DatabaseManager mDatabaseManager;
@Mock private A2dpSinkNativeInterface mNativeInterface;
@@ -76,7 +79,6 @@ public class A2dpSinkServiceTest {
@Before
public void setUp() throws Exception {
mTargetContext = InstrumentationRegistry.getTargetContext();
- MockitoAnnotations.initMocks(this);
mLooper = new TestLooper();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/a2dpsink/A2dpSinkStateMachineTest.java b/android/app/tests/unit/src/com/android/bluetooth/a2dpsink/A2dpSinkStateMachineTest.java
index 03d95a3a77..aac7f7f675 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/a2dpsink/A2dpSinkStateMachineTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/a2dpsink/A2dpSinkStateMachineTest.java
@@ -38,16 +38,20 @@ import com.android.bluetooth.TestUtils;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@RunWith(AndroidJUnit4.class)
public class A2dpSinkStateMachineTest {
private static final String DEVICE_ADDRESS = "11:11:11:11:11:11";
private static final int UNHANDLED_MESSAGE = 9999;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private A2dpSinkService mService;
@Mock private A2dpSinkNativeInterface mNativeInterface;
@@ -60,7 +64,6 @@ public class A2dpSinkStateMachineTest {
@Before
public void setUp() throws Exception {
mTargetContext = InstrumentationRegistry.getTargetContext();
- MockitoAnnotations.initMocks(this);
mLooper = new TestLooper();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/a2dpsink/A2dpSinkStreamHandlerTest.java b/android/app/tests/unit/src/com/android/bluetooth/a2dpsink/A2dpSinkStreamHandlerTest.java
index 4b25bbba1d..fe49e05bf6 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/a2dpsink/A2dpSinkStreamHandlerTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/a2dpsink/A2dpSinkStreamHandlerTest.java
@@ -45,7 +45,8 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@MediumTest
@RunWith(AndroidJUnit4.class)
@@ -56,6 +57,8 @@ public class A2dpSinkStreamHandlerTest {
private A2dpSinkStreamHandler mStreamHandler;
private Context mTargetContext;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private A2dpSinkService mMockA2dpSink;
@Mock private A2dpSinkNativeInterface mMockNativeInterface;
@@ -76,7 +79,6 @@ public class A2dpSinkStreamHandlerTest {
@Before
public void setUp() throws Exception {
mTargetContext = InstrumentationRegistry.getTargetContext();
- MockitoAnnotations.initMocks(this);
// Mock the looper
if (Looper.myLooper() == null) {
Looper.prepare();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/audio_util/BrowsablePlayerConnectorTest.java b/android/app/tests/unit/src/com/android/bluetooth/audio_util/BrowsablePlayerConnectorTest.java
index 5d4f49d98c..c2426563b5 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/audio_util/BrowsablePlayerConnectorTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/audio_util/BrowsablePlayerConnectorTest.java
@@ -33,10 +33,12 @@ import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.ArrayList;
import java.util.Collections;
@@ -51,11 +53,12 @@ public final class BrowsablePlayerConnectorTest {
Context mContext;
TestLooper mTestLooper;
List<ResolveInfo> mPlayerList;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock MediaBrowser mMediaBrowser;
MediaBrowser.ConnectionCallback mConnectionCallback;
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
mContext = InstrumentationRegistry.getTargetContext();
mTestLooper = new TestLooper();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/audio_util/BrowserPlayerWrapperTest.java b/android/app/tests/unit/src/com/android/bluetooth/audio_util/BrowserPlayerWrapperTest.java
index c5d6fd22d2..dcf1b069d9 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/audio_util/BrowserPlayerWrapperTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/audio_util/BrowserPlayerWrapperTest.java
@@ -44,12 +44,14 @@ import com.android.bluetooth.TestUtils;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.io.InputStream;
import java.util.ArrayList;
@@ -64,6 +66,8 @@ public class BrowserPlayerWrapperTest {
@Captor ArgumentCaptor<MediaController.Callback> mControllerCb;
@Captor ArgumentCaptor<Handler> mTimeoutHandler;
@Captor ArgumentCaptor<List<ListItem>> mWrapperBrowseCb;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock MediaBrowser mMockBrowser;
@Mock BrowsedPlayerWrapper.ConnectionCallback mConnCb;
@Mock BrowsedPlayerWrapper.BrowseCallback mBrowseCb;
@@ -91,7 +95,6 @@ public class BrowserPlayerWrapperTest {
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
mTargetContext = InstrumentationRegistry.getTargetContext();
mTestResources = TestUtils.getTestApplicationResources(mTargetContext);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/audio_util/ImageTest.java b/android/app/tests/unit/src/com/android/bluetooth/audio_util/ImageTest.java
index 7e2106b5eb..4d7d339d86 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/audio_util/ImageTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/audio_util/ImageTest.java
@@ -41,10 +41,12 @@ import com.android.bluetooth.TestUtils;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.io.InputStream;
@@ -52,6 +54,8 @@ import java.io.InputStream;
public class ImageTest {
private Context mTargetContext;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
private @Mock Context mMockContext;
private @Mock Resources mMockResources;
private Resources mTestResources;
@@ -78,7 +82,6 @@ public class ImageTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mTargetContext = InstrumentationRegistry.getTargetContext();
mTestResources = TestUtils.getTestApplicationResources(mTargetContext);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/audio_util/MediaPlayerListTest.java b/android/app/tests/unit/src/com/android/bluetooth/audio_util/MediaPlayerListTest.java
index 353e6badba..6b7af24254 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/audio_util/MediaPlayerListTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/audio_util/MediaPlayerListTest.java
@@ -33,12 +33,14 @@ import androidx.test.runner.AndroidJUnit4;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.ArrayList;
@@ -50,6 +52,8 @@ public class MediaPlayerListTest {
private @Captor ArgumentCaptor<AudioManager.AudioPlaybackCallback> mAudioCb;
private @Captor ArgumentCaptor<MediaPlayerWrapper.Callback> mPlayerWrapperCb;
private @Captor ArgumentCaptor<MediaData> mMediaUpdateData;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
private @Mock Context mMockContext;
private @Mock MediaPlayerList.MediaUpdateCallback mMediaUpdateCallback;
private @Mock MediaController mMockController;
@@ -70,7 +74,6 @@ public class MediaPlayerListTest {
}
Assert.assertNotNull(Looper.myLooper());
- MockitoAnnotations.initMocks(this);
AudioManager mockAudioManager = mock(AudioManager.class);
when(mMockContext.getSystemService(Context.AUDIO_SERVICE)).thenReturn(mockAudioManager);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/audio_util/MediaPlayerWrapperTest.java b/android/app/tests/unit/src/com/android/bluetooth/audio_util/MediaPlayerWrapperTest.java
index 9ed1fa0c96..4503968683 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/audio_util/MediaPlayerWrapperTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/audio_util/MediaPlayerWrapperTest.java
@@ -41,12 +41,14 @@ import com.android.bluetooth.TestUtils;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.io.InputStream;
import java.util.ArrayList;
@@ -68,6 +70,8 @@ public class MediaPlayerWrapperTest {
@Captor ArgumentCaptor<MediaController.Callback> mControllerCbs;
@Captor ArgumentCaptor<MediaData> mMediaUpdateData;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock Log.TerribleFailureHandler mFailHandler;
@Mock MediaController mMockController;
@Mock MediaPlayerWrapper.Callback mTestCbs;
@@ -89,7 +93,6 @@ public class MediaPlayerWrapperTest {
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
mTestResources = TestUtils.getTestApplicationResources(
InstrumentationRegistry.getTargetContext());
diff --git a/android/app/tests/unit/src/com/android/bluetooth/audio_util/MetadataTest.java b/android/app/tests/unit/src/com/android/bluetooth/audio_util/MetadataTest.java
index f36b13bf20..8b8940815e 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/audio_util/MetadataTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/audio_util/MetadataTest.java
@@ -44,10 +44,12 @@ import com.android.bluetooth.TestUtils;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.io.InputStream;
@@ -55,6 +57,8 @@ import java.io.InputStream;
public class MetadataTest {
private Context mTargetContext;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
private @Mock Context mMockContext;
private @Mock Resources mMockResources;
private Resources mTestResources;
@@ -88,7 +92,6 @@ public class MetadataTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mTargetContext = InstrumentationRegistry.getTargetContext();
mTestResources = TestUtils.getTestApplicationResources(mTargetContext);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/avrcp/AvrcpVolumeManagerTest.java b/android/app/tests/unit/src/com/android/bluetooth/avrcp/AvrcpVolumeManagerTest.java
index 0a187f294b..d79e16ff18 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/avrcp/AvrcpVolumeManagerTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/avrcp/AvrcpVolumeManagerTest.java
@@ -37,11 +37,13 @@ import androidx.test.runner.AndroidJUnit4;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@SmallTest
@RunWith(AndroidJUnit4.class)
@@ -49,6 +51,8 @@ public class AvrcpVolumeManagerTest {
private static final String REMOTE_DEVICE_ADDRESS = "00:01:02:03:04:05";
private static final int TEST_DEVICE_MAX_VOUME = 25;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
AvrcpNativeInterface mNativeInterface;
@@ -61,7 +65,6 @@ public class AvrcpVolumeManagerTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mContext = InstrumentationRegistry.getTargetContext();
when(mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC))
.thenReturn(TEST_DEVICE_MAX_VOUME);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpBipClientTest.java b/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpBipClientTest.java
index e3dd565833..ee6481b197 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpBipClientTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpBipClientTest.java
@@ -40,7 +40,8 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@SmallTest
@RunWith(AndroidJUnit4.class)
@@ -50,6 +51,8 @@ public class AvrcpBipClientTest {
@Rule
public final ServiceTestRule mBluetoothBrowserMediaServiceTestRule = new ServiceTestRule();
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private AvrcpControllerNativeInterface mNativeInterface;
@@ -62,7 +65,6 @@ public class AvrcpBipClientTest {
@Before
public void setUp() throws Exception {
Context targetContext = InstrumentationRegistry.getTargetContext();
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
AvrcpControllerNativeInterface.setInstance(mNativeInterface);
mService = new AvrcpControllerService(targetContext, mNativeInterface);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerServiceBinderTest.java b/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerServiceBinderTest.java
index c30d989a13..97117a2f85 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerServiceBinderTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerServiceBinderTest.java
@@ -28,16 +28,20 @@ import androidx.test.runner.AndroidJUnit4;
import com.android.bluetooth.x.com.android.modules.utils.SynchronousResultReceiver;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@SmallTest
@RunWith(AndroidJUnit4.class)
public class AvrcpControllerServiceBinderTest {
private static final String REMOTE_DEVICE_ADDRESS = "00:00:00:00:00:00";
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private AvrcpControllerService mService;
@@ -47,7 +51,6 @@ public class AvrcpControllerServiceBinderTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mRemoteDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(REMOTE_DEVICE_ADDRESS);
mBinder = new AvrcpControllerService.AvrcpControllerServiceBinder(mService);
}
diff --git a/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerServiceTest.java
index 19b8f6c95e..f74372bca1 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerServiceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerServiceTest.java
@@ -49,7 +49,8 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.ArrayList;
import java.util.Arrays;
@@ -67,6 +68,8 @@ public class AvrcpControllerServiceTest {
@Rule
public final ServiceTestRule mBluetoothBrowserMediaServiceTestRule = new ServiceTestRule();
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private AvrcpControllerStateMachine mStateMachine;
@Mock private AvrcpControllerNativeInterface mNativeInterface;
@@ -76,7 +79,6 @@ public class AvrcpControllerServiceTest {
@Before
public void setUp() throws Exception {
Context targetContext = InstrumentationRegistry.getTargetContext();
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
AvrcpControllerNativeInterface.setInstance(mNativeInterface);
mService = new AvrcpControllerService(targetContext, mNativeInterface);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerStateMachineTest.java b/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerStateMachineTest.java
index d01d565524..e8181d283f 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerStateMachineTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerStateMachineTest.java
@@ -56,7 +56,8 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.ArrayList;
import java.util.List;
@@ -74,6 +75,8 @@ public class AvrcpControllerStateMachineTest {
@Rule public final ServiceTestRule mAvrcpServiceRule = new ServiceTestRule();
@Rule public final ServiceTestRule mA2dpServiceRule = new ServiceTestRule();
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mA2dpAdapterService;
@Mock private AdapterService mAvrcpAdapterService;
@Mock private A2dpSinkService mA2dpSinkService;
@@ -97,7 +100,6 @@ public class AvrcpControllerStateMachineTest {
}
Assert.assertNotNull(Looper.myLooper());
- MockitoAnnotations.initMocks(this);
// Start a real A2dpSinkService so we can replace the static instance with our mock
doReturn(mDatabaseManager).when(mA2dpAdapterService).getDatabase();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpCoverArtProviderTest.java b/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpCoverArtProviderTest.java
index d55695d949..ddddbd08fe 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpCoverArtProviderTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpCoverArtProviderTest.java
@@ -38,7 +38,8 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.io.FileNotFoundException;
@@ -55,13 +56,14 @@ public class AvrcpCoverArtProviderTest {
@Rule
public final ServiceTestRule mServiceRule = new ServiceTestRule();
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private Uri mUri;
@Mock private AdapterService mAdapterService;
@Mock private AvrcpControllerNativeInterface mNativeInterface;
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
AvrcpControllerNativeInterface.setInstance(mNativeInterface);
mAdapter = BluetoothAdapter.getDefaultAdapter();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpPlayerTest.java b/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpPlayerTest.java
index 30e9c62132..4f6b44d55a 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpPlayerTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpPlayerTest.java
@@ -26,9 +26,11 @@ import android.net.Uri;
import android.support.v4.media.session.PlaybackStateCompat;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
public class AvrcpPlayerTest {
private static final int TEST_PLAYER_ID = 1;
@@ -44,12 +46,13 @@ public class AvrcpPlayerTest {
private BluetoothAdapter mAdapter;
private BluetoothDevice mTestDevice = null;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private PlayerApplicationSettings mPlayerApplicationSettings;
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
mAdapter = BluetoothAdapter.getDefaultAdapter();
mTestDevice = mAdapter.getRemoteDevice(mTestAddress);
}
diff --git a/android/app/tests/unit/src/com/android/bluetooth/bas/BatteryServiceBinderTest.java b/android/app/tests/unit/src/com/android/bluetooth/bas/BatteryServiceBinderTest.java
index 91b6af8ad1..cdc9de99f0 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/bas/BatteryServiceBinderTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/bas/BatteryServiceBinderTest.java
@@ -28,13 +28,17 @@ import com.android.bluetooth.x.com.android.modules.utils.SynchronousResultReceiv
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.List;
public class BatteryServiceBinderTest {
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private BatteryService mService;
private BatteryService.BluetoothBatteryBinder mBinder;
@@ -42,7 +46,6 @@ public class BatteryServiceBinderTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mAdapter = BluetoothAdapter.getDefaultAdapter();
mBinder = new BatteryService.BluetoothBatteryBinder(mService);
}
diff --git a/android/app/tests/unit/src/com/android/bluetooth/bass_client/BassClientServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/bass_client/BassClientServiceTest.java
index ca5c6e527d..a4b11d38e5 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/bass_client/BassClientServiceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/bass_client/BassClientServiceTest.java
@@ -68,20 +68,21 @@ import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.ServiceFactory;
import com.android.bluetooth.btservice.storage.DatabaseManager;
import com.android.bluetooth.csip.CsipSetCoordinatorService;
-import com.android.bluetooth.flags.FakeFeatureFlagsImpl;
import com.android.bluetooth.flags.Flags;
import com.android.bluetooth.le_audio.LeAudioService;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.ArrayList;
import java.util.Arrays;
@@ -139,9 +140,10 @@ public class BassClientServiceTest {
private BluetoothDevice mCurrentDevice;
private BluetoothDevice mCurrentDevice1;
private BassIntentReceiver mBassIntentReceiver;
- private FakeFeatureFlagsImpl mFakeFlagsImpl;
@Spy private BassObjectsFactory mObjectsFactory = BassObjectsFactory.getInstance();
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private DatabaseManager mDatabaseManager;
@Mock private BluetoothLeScannerWrapper mBluetoothLeScannerWrapper;
@@ -202,7 +204,6 @@ public class BassClientServiceTest {
}
mTargetContext = InstrumentationRegistry.getTargetContext();
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
BassObjectsFactory.setInstanceForTesting(mObjectsFactory);
@@ -240,14 +241,11 @@ public class BassClientServiceTest {
return stateMachine;
})
.when(mObjectsFactory)
- .makeStateMachine(any(), any(), any(), any(), any());
+ .makeStateMachine(any(), any(), any(), any());
doReturn(mBluetoothLeScannerWrapper).when(mObjectsFactory)
.getBluetoothLeScannerWrapper(any());
- mFakeFlagsImpl = new FakeFeatureFlagsImpl();
- mFakeFlagsImpl.setFlag(Flags.FLAG_LEAUDIO_BROADCAST_AUDIO_HANDOVER_POLICIES, false);
-
- mBassClientService = new BassClientService(mTargetContext, mFakeFlagsImpl);
+ mBassClientService = new BassClientService(mTargetContext);
mBassClientService.start();
mBassClientService.setAvailable(true);
@@ -355,7 +353,6 @@ public class BassClientServiceTest {
eq(mCurrentDevice),
eq(mBassClientService),
eq(mAdapterService),
- any(),
any());
BassClientStateMachine stateMachine = mStateMachines.get(mCurrentDevice);
assertThat(stateMachine).isNotNull();
@@ -499,10 +496,21 @@ public class BassClientServiceTest {
-1));
}
+ private void handleHandoverSupport() {
+ if (Flags.leaudioBroadcastAudioHandoverPolicies()) {
+ /* Unicast finished streaming */
+ mBassClientService.handleUnicastSourceStreamStatusChange(
+ 2 /* STATUS_LOCAL_STREAM_SUSPENDED */);
+ }
+ }
+
private void verifyAddSourceForGroup(BluetoothLeBroadcastMetadata meta) {
// Add broadcast source
mBassClientService.addSource(mCurrentDevice, meta, true);
+ /* In case if device supporth handover, Source stream status needs to be updated */
+ handleHandoverSupport();
+
// Verify all group members getting ADD_BCAST_SOURCE message
assertThat(mStateMachines.size()).isEqualTo(2);
for (BassClientStateMachine sm: mStateMachines.values()) {
diff --git a/android/app/tests/unit/src/com/android/bluetooth/bass_client/BassClientStateMachineTest.java b/android/app/tests/unit/src/com/android/bluetooth/bass_client/BassClientStateMachineTest.java
index 2c41a652c8..9b47a1095a 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/bass_client/BassClientStateMachineTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/bass_client/BassClientStateMachineTest.java
@@ -83,6 +83,7 @@ import android.os.Bundle;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
+import android.platform.test.flag.junit.SetFlagsRule;
import androidx.test.InstrumentationRegistry;
import androidx.test.filters.MediumTest;
@@ -91,8 +92,6 @@ import com.android.bluetooth.BluetoothMethodProxy;
import com.android.bluetooth.TestUtils;
import com.android.bluetooth.Utils;
import com.android.bluetooth.btservice.AdapterService;
-import com.android.bluetooth.flags.FakeFeatureFlagsImpl;
-import com.android.bluetooth.flags.FeatureFlags;
import com.android.bluetooth.flags.Flags;
import org.hamcrest.core.IsInstanceOf;
@@ -120,6 +119,8 @@ public class BassClientStateMachineTest {
@Rule
public final MockitoRule mockito = MockitoJUnit.rule();
+ @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
+
private static final int CONNECTION_TIMEOUT_MS = 1_000;
private static final int TIMEOUT_MS = 2_000;
private static final int WAIT_MS = 1_200;
@@ -132,7 +133,6 @@ public class BassClientStateMachineTest {
private BluetoothDevice mTestDevice;
private BluetoothDevice mSourceTestDevice;
private BluetoothDevice mEmptyTestDevice;
- private FakeFeatureFlagsImpl mFakeFlagsImpl;
@Mock private AdapterService mAdapterService;
@Mock private BassClientService mBassClientService;
@@ -150,9 +150,6 @@ public class BassClientStateMachineTest {
TestUtils.setAdapterService(mAdapterService);
- mFakeFlagsImpl = new FakeFeatureFlagsImpl();
- mFakeFlagsImpl.setFlag(Flags.FLAG_LEAUDIO_BROADCAST_MONITOR_SOURCE_SYNC_STATUS, false);
- mFakeFlagsImpl.setFlag(Flags.FLAG_LEAUDIO_BROADCAST_AUDIO_HANDOVER_POLICIES, false);
BluetoothMethodProxy.setInstanceForTesting(mMethodProxy);
doNothing().when(mMethodProxy).periodicAdvertisingManagerTransferSync(
any(), any(), anyInt(), anyInt());
@@ -183,9 +180,7 @@ public class BassClientStateMachineTest {
mBassClientService,
mAdapterService,
mHandlerThread.getLooper(),
- CONNECTION_TIMEOUT_MS,
- mFakeFlagsImpl);
- assertThat(mBassClientStateMachine).isNotNull();
+ CONNECTION_TIMEOUT_MS);
mBassClientStateMachine.start();
}
@@ -1941,7 +1936,7 @@ public class BassClientStateMachineTest {
@Test
public void periodicAdvertisingCallbackOnSyncLost_notifySourceLost() {
- mFakeFlagsImpl.setFlag(Flags.FLAG_LEAUDIO_BROADCAST_MONITOR_SOURCE_SYNC_STATUS, true);
+ mSetFlagsRule.enableFlags(Flags.FLAG_LEAUDIO_BROADCAST_MONITOR_SOURCE_SYNC_STATUS);
PeriodicAdvertisingCallback cb = mBassClientStateMachine.mLocalPeriodicAdvCallback;
BassClientService.Callbacks callbacks = Mockito.mock(BassClientService.Callbacks.class);
int syncHandle = 1;
@@ -1955,7 +1950,7 @@ public class BassClientStateMachineTest {
@Test
public void periodicAdvertisingCallbackOnBigInfoAdvertisingReport_updateRssi() {
- mFakeFlagsImpl.setFlag(Flags.FLAG_LEAUDIO_BROADCAST_MONITOR_SOURCE_SYNC_STATUS, true);
+ mSetFlagsRule.enableFlags(Flags.FLAG_LEAUDIO_BROADCAST_MONITOR_SOURCE_SYNC_STATUS);
PeriodicAdvertisingCallback cb = mBassClientStateMachine.mLocalPeriodicAdvCallback;
BassClientService.Callbacks callbacks = Mockito.mock(BassClientService.Callbacks.class);
int testRssi = -40;
@@ -2178,9 +2173,8 @@ public class BassClientStateMachineTest {
BassClientService service,
AdapterService adapterService,
Looper looper,
- int connectTimeout,
- FeatureFlags featureFlags) {
- super(device, service, adapterService, looper, connectTimeout, featureFlags);
+ int connectTimeout) {
+ super(device, service, adapterService, looper, connectTimeout);
}
@Override
diff --git a/android/app/tests/unit/src/com/android/bluetooth/bass_client/BleBroadcastAssistantBinderTest.java b/android/app/tests/unit/src/com/android/bluetooth/bass_client/BleBroadcastAssistantBinderTest.java
index 678b6b1a02..0f7034a075 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/bass_client/BleBroadcastAssistantBinderTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/bass_client/BleBroadcastAssistantBinderTest.java
@@ -34,12 +34,14 @@ import android.bluetooth.le.ScanFilter;
import com.android.bluetooth.TestUtils;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.Collections;
import java.util.List;
@@ -47,6 +49,8 @@ import java.util.List;
@RunWith(JUnit4.class)
public class BleBroadcastAssistantBinderTest {
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private BassClientService mService;
private BassClientService.BluetoothLeBroadcastAssistantBinder mBinder;
@@ -54,7 +58,6 @@ public class BleBroadcastAssistantBinderTest {
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
mBinder = new BassClientService.BluetoothLeBroadcastAssistantBinder(mService);
mAdapter = BluetoothAdapter.getDefaultAdapter();
}
diff --git a/android/app/tests/unit/src/com/android/bluetooth/btservice/ActiveDeviceManagerTest.java b/android/app/tests/unit/src/com/android/bluetooth/btservice/ActiveDeviceManagerTest.java
index 7cc9aecb6c..b344a37fb6 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/btservice/ActiveDeviceManagerTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/btservice/ActiveDeviceManagerTest.java
@@ -67,8 +67,9 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.ArrayList;
import java.util.List;
@@ -100,6 +101,8 @@ public class ActiveDeviceManagerTest {
private TestLooper mTestLooper;
@Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private ServiceFactory mServiceFactory;
@Mock private A2dpService mA2dpService;
@@ -111,8 +114,6 @@ public class ActiveDeviceManagerTest {
@Before
public void setUp() throws Exception {
- // Set up mocks and test assets
- MockitoAnnotations.initMocks(this);
mTestLooper = new TestLooper();
BluetoothMethodProxy.setInstanceForTesting(mMethodProxy);
doReturn(mTestLooper.getLooper()).when(mMethodProxy).handlerThreadGetLooper(any());
diff --git a/android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterPropertiesTest.java b/android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterPropertiesTest.java
index 436151b46d..2b7283ed34 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterPropertiesTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterPropertiesTest.java
@@ -36,11 +36,13 @@ import androidx.test.runner.AndroidJUnit4;
import com.android.bluetooth.Utils;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@MediumTest
@RunWith(AndroidJUnit4.class)
@@ -54,6 +56,8 @@ public class AdapterPropertiesTest {
private HandlerThread mHandlerThread;
private Context mTargetContext;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private AdapterNativeInterface mNativeInterface;
@@ -61,7 +65,6 @@ public class AdapterPropertiesTest {
public void setUp() throws Exception {
mTargetContext = InstrumentationRegistry.getTargetContext();
- MockitoAnnotations.initMocks(this);
doReturn(mNativeInterface).when(mAdapterService).getNative();
mHandlerThread = new HandlerThread("RemoteDevicesTestHandlerThread");
mHandlerThread.start();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceBinderTest.java b/android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceBinderTest.java
index 68ac543169..729ae74b79 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceBinderTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceBinderTest.java
@@ -31,14 +31,18 @@ import com.android.bluetooth.x.com.android.modules.utils.SynchronousResultReceiv
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.io.FileDescriptor;
public class AdapterServiceBinderTest {
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mService;
@Mock private AdapterProperties mAdapterProperties;
@@ -47,7 +51,6 @@ public class AdapterServiceBinderTest {
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
mService.mAdapterProperties = mAdapterProperties;
doReturn(true).when(mService).isAvailable();
doNothing().when(mService).enforceCallingOrSelfPermission(any(), any());
diff --git a/android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceFactoryResetTest.java b/android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceFactoryResetTest.java
index 099c29970a..898e6fd791 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceFactoryResetTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceFactoryResetTest.java
@@ -71,10 +71,12 @@ import com.android.internal.app.IBatteryStats;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.HashMap;
import java.util.List;
@@ -86,6 +88,8 @@ public class AdapterServiceFactoryResetTest {
private AdapterService mAdapterService;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
private @Mock Context mMockContext;
private @Mock ApplicationInfo mMockApplicationInfo;
private @Mock Resources mMockResources;
@@ -143,7 +147,6 @@ public class AdapterServiceFactoryResetTest {
@Before
public void setUp() throws PackageManager.NameNotFoundException {
Log.e(TAG, "setUp()");
- MockitoAnnotations.initMocks(this);
mLooper = new TestLooper();
Handler handler = new Handler(mLooper.getLooper());
diff --git a/android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceRestartTest.java b/android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceRestartTest.java
index 12dac99161..93a6688fe4 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceRestartTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceRestartTest.java
@@ -66,10 +66,12 @@ import com.android.internal.app.IBatteryStats;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.HashMap;
@@ -80,6 +82,8 @@ public class AdapterServiceRestartTest {
private AdapterService mAdapterService;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
private @Mock Context mMockContext;
private @Mock ApplicationInfo mMockApplicationInfo;
private @Mock Resources mMockResources;
@@ -124,7 +128,6 @@ public class AdapterServiceRestartTest {
@Before
public void setUp() throws PackageManager.NameNotFoundException {
Log.e(TAG, "setUp()");
- MockitoAnnotations.initMocks(this);
mLooper = new TestLooper();
Handler handler = new Handler(mLooper.getLooper());
diff --git a/android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceTest.java
index cc84dbc68f..1e1fcc8447 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceTest.java
@@ -90,7 +90,8 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -115,6 +116,8 @@ public class AdapterServiceTest {
private AdapterService mAdapterService;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
private @Mock Context mMockContext;
private @Mock ApplicationInfo mMockApplicationInfo;
private @Mock Resources mMockResources;
@@ -186,7 +189,6 @@ public class AdapterServiceTest {
@Before
public void setUp() throws PackageManager.NameNotFoundException {
Log.e(TAG, "setUp()");
- MockitoAnnotations.initMocks(this);
mLooper = new TestLooper();
Handler handler = new Handler(mLooper.getLooper());
diff --git a/android/app/tests/unit/src/com/android/bluetooth/btservice/AudioRoutingManagerTest.java b/android/app/tests/unit/src/com/android/bluetooth/btservice/AudioRoutingManagerTest.java
index d294c33e77..f4da3aa7e1 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/btservice/AudioRoutingManagerTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/btservice/AudioRoutingManagerTest.java
@@ -56,12 +56,14 @@ import com.android.bluetooth.le_audio.LeAudioService;
import org.junit.After;
import org.junit.Assume;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.ArrayList;
import java.util.Collections;
@@ -91,6 +93,8 @@ public class AudioRoutingManagerTest {
private TestDatabaseManager mDatabaseManager;
private TestLooper mTestLooper;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private ServiceFactory mServiceFactory;
@Mock private A2dpService mA2dpService;
@@ -102,8 +106,6 @@ public class AudioRoutingManagerTest {
@Before
public void setUp() throws Exception {
- // Set up mocks and test assets
- MockitoAnnotations.initMocks(this);
mTestLooper = new TestLooper();
BluetoothMethodProxy.setInstanceForTesting(mMethodProxy);
doReturn(mTestLooper.getLooper()).when(mMethodProxy).handlerThreadGetLooper(any());
diff --git a/android/app/tests/unit/src/com/android/bluetooth/btservice/BondStateMachineTest.java b/android/app/tests/unit/src/com/android/bluetooth/btservice/BondStateMachineTest.java
index 91aee3700e..4e571d24e9 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/btservice/BondStateMachineTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/btservice/BondStateMachineTest.java
@@ -40,11 +40,13 @@ import com.android.bluetooth.Utils;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@MediumTest
@RunWith(AndroidJUnit4.class)
@@ -69,13 +71,14 @@ public class BondStateMachineTest {
private RemoteDevices.DeviceProperties mDeviceProperties;
private int mVerifyCount = 0;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private AdapterNativeInterface mNativeInterface;
@Before
public void setUp() throws Exception {
mTargetContext = InstrumentationRegistry.getTargetContext();
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
doReturn(mNativeInterface).when(mAdapterService).getNative();
mHandlerThread = new HandlerThread("BondStateMachineTestHandlerThread");
diff --git a/android/app/tests/unit/src/com/android/bluetooth/btservice/CompanionManagerTest.java b/android/app/tests/unit/src/com/android/bluetooth/btservice/CompanionManagerTest.java
index f2f091fa43..3e9f37b74c 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/btservice/CompanionManagerTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/btservice/CompanionManagerTest.java
@@ -32,10 +32,12 @@ import com.android.bluetooth.TestUtils;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@MediumTest
@RunWith(AndroidJUnit4.class)
@@ -49,6 +51,8 @@ public class CompanionManagerTest {
private HandlerThread mHandlerThread;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private AdapterService mAdapterService;
@Mock
@@ -58,7 +62,6 @@ public class CompanionManagerTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mTargetContext = InstrumentationRegistry.getTargetContext();
// Prepare the TestUtils
TestUtils.setAdapterService(mAdapterService);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/btservice/DataMigrationTest.java b/android/app/tests/unit/src/com/android/bluetooth/btservice/DataMigrationTest.java
index ea39f2871d..f1de518872 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/btservice/DataMigrationTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/btservice/DataMigrationTest.java
@@ -50,10 +50,12 @@ import com.android.bluetooth.opp.BluetoothShare;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.ArrayList;
import java.util.Arrays;
@@ -73,11 +75,12 @@ public class DataMigrationTest {
private Context mTargetContext;
private SharedPreferences mPrefs;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private Context mMockContext;
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mTargetContext = InstrumentationRegistry.getTargetContext();
mTargetContext.deleteSharedPreferences(TEST_PREF);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/btservice/MetricsLoggerTest.java b/android/app/tests/unit/src/com/android/bluetooth/btservice/MetricsLoggerTest.java
index b642319699..273ac96b22 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/btservice/MetricsLoggerTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/btservice/MetricsLoggerTest.java
@@ -31,10 +31,12 @@ import com.google.common.hash.Funnels;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -50,6 +52,8 @@ public class MetricsLoggerTest {
private static final String TEST_BLOOMFILTER_NAME = "TestBloomfilter";
private TestableMetricsLogger mTestableMetricsLogger;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private AdapterService mMockAdapterService;
@@ -80,7 +84,6 @@ public class MetricsLoggerTest {
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
// Dump metrics to clean up internal states
MetricsLogger.dumpProto(BluetoothLog.newBuilder());
mTestableMetricsLogger = new TestableMetricsLogger();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/btservice/PhonePolicyTest.java b/android/app/tests/unit/src/com/android/bluetooth/btservice/PhonePolicyTest.java
index f08886106a..f0cf9e32c6 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/btservice/PhonePolicyTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/btservice/PhonePolicyTest.java
@@ -50,7 +50,8 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.ArrayList;
import java.util.Collections;
@@ -72,6 +73,8 @@ public class PhonePolicyTest {
private PhonePolicy mPhonePolicy;
private boolean mOriginalDualModeState;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private ServiceFactory mServiceFactory;
@Mock private HeadsetService mHeadsetService;
@@ -81,7 +84,6 @@ public class PhonePolicyTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
// Stub A2DP and HFP
when(mHeadsetService.connect(any(BluetoothDevice.class))).thenReturn(true);
when(mA2dpService.connect(any(BluetoothDevice.class))).thenReturn(true);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/btservice/ProfileServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/btservice/ProfileServiceTest.java
index 660fdb78dc..fb8e0ba914 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/btservice/ProfileServiceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/btservice/ProfileServiceTest.java
@@ -47,12 +47,14 @@ import com.android.bluetooth.vc.VolumeControlNativeInterface;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
@@ -69,6 +71,8 @@ public class ProfileServiceTest {
private AdapterService mAdapterService =
new AdapterService(InstrumentationRegistry.getTargetContext());
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private DatabaseManager mDatabaseManager;
private int[] mProfiles;
@@ -132,7 +136,6 @@ public class ProfileServiceTest {
}
Assert.assertNotNull(Looper.myLooper());
- MockitoAnnotations.initMocks(this);
doReturn(mDatabaseManager).when(mAdapterService).getDatabase();
doNothing().when(mAdapterService).addProfile(any());
diff --git a/android/app/tests/unit/src/com/android/bluetooth/btservice/RemoteDevicesTest.java b/android/app/tests/unit/src/com/android/bluetooth/btservice/RemoteDevicesTest.java
index 54d3e7bf10..5cbd92d4b3 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/btservice/RemoteDevicesTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/btservice/RemoteDevicesTest.java
@@ -31,11 +31,13 @@ import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.ArrayList;
@@ -54,13 +56,14 @@ public class RemoteDevicesTest {
private Context mTargetContext;
private BluetoothManager mBluetoothManager;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Before
public void setUp() {
mTargetContext = InstrumentationRegistry.getTargetContext();
- MockitoAnnotations.initMocks(this);
mDevice1 = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(TEST_BT_ADDR_1);
mHandlerThread = new HandlerThread("RemoteDevicesTestHandlerThread");
mHandlerThread.start();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/btservice/SilenceDeviceManagerTest.java b/android/app/tests/unit/src/com/android/bluetooth/btservice/SilenceDeviceManagerTest.java
index 23aac3991c..36be66af70 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/btservice/SilenceDeviceManagerTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/btservice/SilenceDeviceManagerTest.java
@@ -41,11 +41,13 @@ import com.android.bluetooth.hfp.HeadsetService;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@MediumTest
@RunWith(AndroidJUnit4.class)
@@ -59,6 +61,8 @@ public class SilenceDeviceManagerTest {
private static final String TEST_BT_ADDR = "11:22:33:44:55:66";
private int mVerifyCount = 0;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private ServiceFactory mServiceFactory;
@Mock private A2dpService mA2dpService;
@@ -69,8 +73,6 @@ public class SilenceDeviceManagerTest {
public void setUp() throws Exception {
mContext = InstrumentationRegistry.getTargetContext();
- // Set up mocks and test assets
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
when(mServiceFactory.getA2dpService()).thenReturn(mA2dpService);
when(mServiceFactory.getHeadsetService()).thenReturn(mHeadsetService);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/btservice/bluetoothKeystore/BluetoothKeystoreServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/btservice/bluetoothKeystore/BluetoothKeystoreServiceTest.java
index 1e78e0c86b..ae60fb4d7e 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/btservice/bluetoothKeystore/BluetoothKeystoreServiceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/btservice/bluetoothKeystore/BluetoothKeystoreServiceTest.java
@@ -24,11 +24,13 @@ import org.junit.After;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.io.IOException;
import java.nio.file.Files;
@@ -44,6 +46,8 @@ public final class BluetoothKeystoreServiceTest {
private static final String TAG = "BluetoothKeystoreServiceTest";
private BluetoothKeystoreService mBluetoothKeystoreService;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private BluetoothKeystoreNativeInterface mMockNativeInterface;
// Please also check bt_stack string configuration if you want to change the content.
@@ -123,7 +127,6 @@ public final class BluetoothKeystoreServiceTest {
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
Assume.assumeTrue("Ignore test when the user is not primary.", isPrimaryUser());
mBluetoothKeystoreService = new BluetoothKeystoreService(mMockNativeInterface, true);
Assert.assertNotNull(mBluetoothKeystoreService);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/btservice/storage/DatabaseManagerTest.java b/android/app/tests/unit/src/com/android/bluetooth/btservice/storage/DatabaseManagerTest.java
index 679850bed7..94c1993b40 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/btservice/storage/DatabaseManagerTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/btservice/storage/DatabaseManagerTest.java
@@ -61,7 +61,8 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import org.mockito.stubbing.Answer;
import java.io.IOException;
@@ -74,6 +75,8 @@ import java.util.concurrent.TimeUnit;
@RunWith(AndroidJUnit4.class)
public final class DatabaseManagerTest {
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
private MetadataDatabase mDatabase;
@@ -103,7 +106,6 @@ public final class DatabaseManagerTest {
new FrameworkSQLiteOpenHelperFactory());
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
mTestDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(TEST_BT_ADDR);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/content_profiles/ContentProfileErrorReportUtilsTest.java b/android/app/tests/unit/src/com/android/bluetooth/content_profiles/ContentProfileErrorReportUtilsTest.java
index bdfe10d5dc..dc4e6dc5e8 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/content_profiles/ContentProfileErrorReportUtilsTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/content_profiles/ContentProfileErrorReportUtilsTest.java
@@ -22,7 +22,6 @@ import android.os.SystemClock;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
-import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/android/app/tests/unit/src/com/android/bluetooth/csip/BluetoothCsisBinderTest.java b/android/app/tests/unit/src/com/android/bluetooth/csip/BluetoothCsisBinderTest.java
index 9b9b0b9d4e..460d9df200 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/csip/BluetoothCsisBinderTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/csip/BluetoothCsisBinderTest.java
@@ -29,13 +29,17 @@ import android.os.ParcelUuid;
import com.android.bluetooth.x.com.android.modules.utils.SynchronousResultReceiver;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
public class BluetoothCsisBinderTest {
private static final String TEST_DEVICE_ADDRESS = "00:00:00:00:00:00";
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private CsipSetCoordinatorService mService;
@@ -46,7 +50,6 @@ public class BluetoothCsisBinderTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mBinder = new CsipSetCoordinatorService.BluetoothCsisBinder(mService);
mAttributionSource = new AttributionSource.Builder(1).build();
mTestDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(TEST_DEVICE_ADDRESS);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/csip/CsipSetCoordinatorServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/csip/CsipSetCoordinatorServiceTest.java
index 7c3bd07096..d212f044b0 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/csip/CsipSetCoordinatorServiceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/csip/CsipSetCoordinatorServiceTest.java
@@ -43,11 +43,13 @@ import com.android.bluetooth.le_audio.LeAudioService;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.HashMap;
import java.util.List;
@@ -72,6 +74,8 @@ public class CsipSetCoordinatorServiceTest {
private CsipSetCoordinatorStateMachine mCsipSetCoordinatorStateMachine;
private static final int TIMEOUT_MS = 1000;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private LeAudioService mLeAudioService;
@Spy
@@ -92,8 +96,6 @@ public class CsipSetCoordinatorServiceTest {
}
Assert.assertNotNull(Looper.myLooper());
- // Set up mocks and test assets
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
doReturn(mDatabaseManager).when(mAdapterService).getDatabase();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/csip/CsipSetCoordinatorStateMachineTest.java b/android/app/tests/unit/src/com/android/bluetooth/csip/CsipSetCoordinatorStateMachineTest.java
index 0c09204d33..230bf6c33d 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/csip/CsipSetCoordinatorStateMachineTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/csip/CsipSetCoordinatorStateMachineTest.java
@@ -33,17 +33,22 @@ import android.content.Intent;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
+
import androidx.test.filters.MediumTest;
import androidx.test.runner.AndroidJUnit4;
+
import com.android.bluetooth.TestUtils;
import com.android.bluetooth.btservice.AdapterService;
+
import org.hamcrest.core.IsInstanceOf;
import org.junit.*;
+import org.junit.Rule;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@MediumTest
@RunWith(AndroidJUnit4.class)
@@ -56,6 +61,8 @@ public class CsipSetCoordinatorStateMachineTest {
private CsipSetCoordinatorStateMachineWrapper mStateMachine;
private static final int TIMEOUT_MS = 1000;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private CsipSetCoordinatorService mService;
@Mock private CsipSetCoordinatorNativeInterface mNativeInterface;
@@ -66,8 +73,6 @@ public class CsipSetCoordinatorStateMachineTest {
System.setProperty("dexmaker.share_classloader", "true");
}
- // Set up mocks and test assets
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
mAdapter = BluetoothAdapter.getDefaultAdapter();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/gatt/AdvertiseManagerTest.java b/android/app/tests/unit/src/com/android/bluetooth/gatt/AdvertiseManagerTest.java
index c7bf403325..9c884df9ad 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/gatt/AdvertiseManagerTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/gatt/AdvertiseManagerTest.java
@@ -37,10 +37,12 @@ import com.android.bluetooth.btservice.AdapterService;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
/**
* Test cases for {@link AdvertiseManager}.
@@ -49,6 +51,8 @@ import org.mockito.MockitoAnnotations;
@RunWith(AndroidJUnit4.class)
public class AdvertiseManagerTest {
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private AdapterService mAdapterService;
@@ -71,7 +75,6 @@ public class AdvertiseManagerTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/gatt/AppAdvertiseStatsTest.java b/android/app/tests/unit/src/com/android/bluetooth/gatt/AppAdvertiseStatsTest.java
index 6b054f3b7e..66d0750116 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/gatt/AppAdvertiseStatsTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/gatt/AppAdvertiseStatsTest.java
@@ -34,11 +34,13 @@ import com.android.bluetooth.btservice.MetricsLogger;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
/**
* Test cases for {@link AppAdvertiseStats}.
@@ -47,6 +49,8 @@ import org.mockito.MockitoAnnotations;
@RunWith(AndroidJUnit4.class)
public class AppAdvertiseStatsTest {
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private ContextMap map;
@@ -58,7 +62,6 @@ public class AppAdvertiseStatsTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
MetricsLogger.setInstanceForTesting(mMetricsLogger);
}
diff --git a/android/app/tests/unit/src/com/android/bluetooth/gatt/ContextMapTest.java b/android/app/tests/unit/src/com/android/bluetooth/gatt/ContextMapTest.java
index cb2f44be7d..d29e96d781 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/gatt/ContextMapTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/gatt/ContextMapTest.java
@@ -43,8 +43,9 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.UUID;
@@ -59,6 +60,8 @@ public class ContextMapTest {
@Rule
public final ServiceTestRule mServiceRule = new ServiceTestRule();
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private AppAdvertiseStats appAdvertiseStats;
@Mock private GattService mMockGatt;
@@ -70,7 +73,6 @@ public class ContextMapTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
BluetoothMethodProxy.setInstanceForTesting(mMapMethodProxy);
TestUtils.setAdapterService(mAdapterService);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/gatt/DistanceMeasurementManagerTest.java b/android/app/tests/unit/src/com/android/bluetooth/gatt/DistanceMeasurementManagerTest.java
index 5d1eea0ade..077d2b9f4b 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/gatt/DistanceMeasurementManagerTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/gatt/DistanceMeasurementManagerTest.java
@@ -40,11 +40,13 @@ import com.android.bluetooth.btservice.AdapterService;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.UUID;
@@ -54,6 +56,8 @@ import java.util.UUID;
@SmallTest
@RunWith(AndroidJUnit4.class)
public class DistanceMeasurementManagerTest {
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private DistanceMeasurementNativeInterface mDistanceMeasurementNativeInterface;
@Mock private AdapterService mAdapterService;
@Mock private IDistanceMeasurementCallback mCallback;
@@ -66,7 +70,6 @@ public class DistanceMeasurementManagerTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
doReturn(IDENTITY_ADDRESS).when(mAdapterService).getIdentityAddress(IDENTITY_ADDRESS);
DistanceMeasurementNativeInterface.setInstance(mDistanceMeasurementNativeInterface);
mDistanceMeasurementManager = new DistanceMeasurementManager(mAdapterService);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/gatt/DistanceMeasurementTrackerTest.java b/android/app/tests/unit/src/com/android/bluetooth/gatt/DistanceMeasurementTrackerTest.java
index d3e562207d..603b20fe45 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/gatt/DistanceMeasurementTrackerTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/gatt/DistanceMeasurementTrackerTest.java
@@ -34,10 +34,12 @@ import androidx.test.runner.AndroidJUnit4;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.UUID;
@@ -47,6 +49,8 @@ import java.util.UUID;
@SmallTest
@RunWith(AndroidJUnit4.class)
public class DistanceMeasurementTrackerTest {
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private DistanceMeasurementManager mDistanceMeasurementManager;
@Mock private IDistanceMeasurementCallback mCallback;
private DistanceMeasurementTracker mTracker;
@@ -61,7 +65,6 @@ public class DistanceMeasurementTrackerTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mUuid = UUID.randomUUID();
mDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(IDENTITY_ADDRESS);
mParams = new DistanceMeasurementParams.Builder(mDevice)
diff --git a/android/app/tests/unit/src/com/android/bluetooth/gatt/GattDebugUtilsTest.java b/android/app/tests/unit/src/com/android/bluetooth/gatt/GattDebugUtilsTest.java
index ab83f1d6e4..8d7f4aafe7 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/gatt/GattDebugUtilsTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/gatt/GattDebugUtilsTest.java
@@ -25,11 +25,12 @@ import android.content.Intent;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
-import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
/**
* Test cases for {@link GattDebugUtils}.
@@ -38,14 +39,11 @@ import org.mockito.MockitoAnnotations;
@RunWith(AndroidJUnit4.class)
public class GattDebugUtilsTest {
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private GattService mService;
- @Before
- public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
- }
-
@Test
public void handleDebugAction() {
Intent intent = new Intent(GattDebugUtils.ACTION_GATT_TEST_USAGE);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/gatt/GattServiceBinderTest.java b/android/app/tests/unit/src/com/android/bluetooth/gatt/GattServiceBinderTest.java
index 54d77a8d23..0bec207562 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/gatt/GattServiceBinderTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/gatt/GattServiceBinderTest.java
@@ -50,10 +50,12 @@ import com.android.bluetooth.le_scan.TransitionalScanHelper;
import com.android.bluetooth.x.com.android.modules.utils.SynchronousResultReceiver;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.ArrayList;
import java.util.List;
@@ -65,6 +67,8 @@ public class GattServiceBinderTest {
private static final String REMOTE_DEVICE_ADDRESS = "00:00:00:00:00:00";
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private GattService mService;
@Mock private TransitionalScanHelper mScanHelper;
@@ -82,7 +86,6 @@ public class GattServiceBinderTest {
Intent intent = new Intent();
mPendingIntent = PendingIntent.getBroadcast(mContext, 0, intent,
PendingIntent.FLAG_IMMUTABLE);
- MockitoAnnotations.initMocks(this);
when(mService.isAvailable()).thenReturn(true);
when(mService.getTransitionalScanHelper()).thenReturn(mScanHelper);
mBinder = new GattService.BluetoothGattBinder(mService);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/gatt/GattServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/gatt/GattServiceTest.java
index f9527cbb83..50083b6d96 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/gatt/GattServiceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/gatt/GattServiceTest.java
@@ -59,7 +59,8 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.ArrayList;
import java.util.HashMap;
@@ -82,6 +83,8 @@ public class GattServiceTest {
private static final int TIMEOUT_MS = 5_000;
private Context mTargetContext;
private GattService mService;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private GattService.ClientMap mClientMap;
@Mock private TransitionalScanHelper.ScannerMap mScannerMap;
@@ -113,7 +116,6 @@ public class GattServiceTest {
public void setUp() throws Exception {
mTargetContext = InstrumentationRegistry.getTargetContext();
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
GattObjectsFactory.setInstanceForTesting(mFactory);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/hap/HapClientNativeInterfaceTest.java b/android/app/tests/unit/src/com/android/bluetooth/hap/HapClientNativeInterfaceTest.java
index 1d4ecbe2e7..1229c97080 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/hap/HapClientNativeInterfaceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/hap/HapClientNativeInterfaceTest.java
@@ -26,14 +26,18 @@ import android.bluetooth.BluetoothProfile;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
public class HapClientNativeInterfaceTest {
private static final byte[] TEST_DEVICE_ADDRESS =
new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
HapClientService mService;
@@ -41,7 +45,6 @@ public class HapClientNativeInterfaceTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
when(mService.isAvailable()).thenReturn(true);
HapClientService.setHapClient(mService);
mNativeInterface = HapClientNativeInterface.getInstance();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/hap/HapClientStateMachineTest.java b/android/app/tests/unit/src/com/android/bluetooth/hap/HapClientStateMachineTest.java
index 8e1024dbdb..4c878d896f 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/hap/HapClientStateMachineTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/hap/HapClientStateMachineTest.java
@@ -31,20 +31,25 @@ import android.bluetooth.BluetoothProfile;
import android.content.Intent;
import android.os.HandlerThread;
import android.os.Message;
+
import androidx.test.filters.MediumTest;
import androidx.test.runner.AndroidJUnit4;
+
import com.android.bluetooth.TestUtils;
import com.android.bluetooth.btservice.AdapterService;
+
import org.hamcrest.core.IsInstanceOf;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@MediumTest
@RunWith(AndroidJUnit4.class)
@@ -56,6 +61,8 @@ public class HapClientStateMachineTest {
private static final int TIMEOUT_MS = 1000;
boolean mIsAdapterServiceSet;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private AdapterService mAdapterService;
@Mock
@@ -65,8 +72,6 @@ public class HapClientStateMachineTest {
@Before
public void setUp() throws Exception {
- // Set up mocks and test assets
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
mIsAdapterServiceSet = true;
diff --git a/android/app/tests/unit/src/com/android/bluetooth/hap/HapClientTest.java b/android/app/tests/unit/src/com/android/bluetooth/hap/HapClientTest.java
index 8fc9fbe179..fc24a7ec05 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/hap/HapClientTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/hap/HapClientTest.java
@@ -71,13 +71,15 @@ import com.android.bluetooth.x.com.android.modules.utils.SynchronousResultReceiv
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.time.Duration;
import java.util.ArrayList;
@@ -102,6 +104,8 @@ public class HapClientTest {
private HapClientService.BluetoothHapClientBinder mServiceBinder;
private AttributionSource mAttributionSource;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private DatabaseManager mDatabaseManager;
@Mock private HapClientNativeInterface mNativeInterface;
@@ -116,8 +120,6 @@ public class HapClientTest {
System.setProperty("dexmaker.share_classloader", "true");
}
- // Set up mocks and test assets
- MockitoAnnotations.initMocks(this);
HapClientStateMachine.sConnectTimeoutMs = TIMEOUT_MS;
diff --git a/android/app/tests/unit/src/com/android/bluetooth/hearingaid/HearingAidNativeInterfaceTest.java b/android/app/tests/unit/src/com/android/bluetooth/hearingaid/HearingAidNativeInterfaceTest.java
index 27e1c152f2..c730910e33 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/hearingaid/HearingAidNativeInterfaceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/hearingaid/HearingAidNativeInterfaceTest.java
@@ -32,14 +32,18 @@ import com.android.bluetooth.Utils;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
public class HearingAidNativeInterfaceTest {
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private HearingAidService mService;
private HearingAidNativeInterface mNativeInterface;
@@ -47,7 +51,6 @@ public class HearingAidNativeInterfaceTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
when(mService.isAvailable()).thenReturn(true);
HearingAidService.setHearingAidService(mService);
mNativeInterface = HearingAidNativeInterface.getInstance();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/hearingaid/HearingAidServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/hearingaid/HearingAidServiceTest.java
index f690d6502c..f7580331ab 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/hearingaid/HearingAidServiceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/hearingaid/HearingAidServiceTest.java
@@ -66,8 +66,9 @@ import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
import org.mockito.hamcrest.MockitoHamcrest;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.time.Duration;
import java.util.HashMap;
@@ -91,6 +92,8 @@ public class HearingAidServiceTest {
private HearingAidService.BluetoothHearingAidBinder mServiceBinder;
private HashMap<BluetoothDevice, LinkedBlockingQueue<Intent>> mDeviceQueueMap;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private ActiveDeviceManager mActiveDeviceManager;
@Mock private AudioRoutingManager mAudioRoutingManager;
@@ -103,8 +106,6 @@ public class HearingAidServiceTest {
@Before
public void setUp() throws Exception {
- // Set up mocks and test assets
- MockitoAnnotations.initMocks(this);
mInOrder = inOrder(mContext);
TestUtils.mockGetSystemService(
diff --git a/android/app/tests/unit/src/com/android/bluetooth/hearingaid/HearingAidStateMachineTest.java b/android/app/tests/unit/src/com/android/bluetooth/hearingaid/HearingAidStateMachineTest.java
index e5ed3151fc..f35f6b3435 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/hearingaid/HearingAidStateMachineTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/hearingaid/HearingAidStateMachineTest.java
@@ -37,11 +37,13 @@ import org.hamcrest.core.IsInstanceOf;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@MediumTest
@RunWith(AndroidJUnit4.class)
@@ -53,6 +55,8 @@ public class HearingAidStateMachineTest {
private BluetoothDevice mTestDevice;
private static final int TIMEOUT_MS = 1000;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private HearingAidService mHearingAidService;
@Mock private HearingAidNativeInterface mHearingAidNativeInterface;
@@ -60,8 +64,6 @@ public class HearingAidStateMachineTest {
@Before
public void setUp() throws Exception {
mTargetContext = InstrumentationRegistry.getTargetContext();
- // Set up mocks and test assets
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
mAdapter = BluetoothAdapter.getDefaultAdapter();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/hfp/AtPhonebookTest.java b/android/app/tests/unit/src/com/android/bluetooth/hfp/AtPhonebookTest.java
index 131c886c52..1ca0830d79 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/hfp/AtPhonebookTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/hfp/AtPhonebookTest.java
@@ -46,11 +46,13 @@ import com.android.internal.telephony.GsmAlphabet;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@RunWith(AndroidJUnit4.class)
public class AtPhonebookTest {
@@ -59,6 +61,8 @@ public class AtPhonebookTest {
private BluetoothAdapter mAdapter;
private BluetoothDevice mTestDevice;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private HeadsetNativeInterface mNativeInterface;
@@ -69,7 +73,6 @@ public class AtPhonebookTest {
@Before
public void setUp() throws Exception {
mTargetContext = InstrumentationRegistry.getTargetContext();
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
BluetoothMethodProxy.setInstanceForTesting(mHfpMethodProxy);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/hfp/BluetoothHeadsetBinderTest.java b/android/app/tests/unit/src/com/android/bluetooth/hfp/BluetoothHeadsetBinderTest.java
index 61e488ebd8..215991d285 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/hfp/BluetoothHeadsetBinderTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/hfp/BluetoothHeadsetBinderTest.java
@@ -26,13 +26,17 @@ import android.content.AttributionSource;
import com.android.bluetooth.x.com.android.modules.utils.SynchronousResultReceiver;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
public class BluetoothHeadsetBinderTest {
private static final String TEST_DEVICE_ADDRESS = "00:00:00:00:00:00";
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private HeadsetService mService;
@@ -43,7 +47,6 @@ public class BluetoothHeadsetBinderTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mBinder = new HeadsetService.BluetoothHeadsetBinder(mService);
mAttributionSource = new AttributionSource.Builder(1).build();
mTestDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(TEST_DEVICE_ADDRESS);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/hfp/HeadsetPhoneStateTest.java b/android/app/tests/unit/src/com/android/bluetooth/hfp/HeadsetPhoneStateTest.java
index b83c7e3b40..d14650c3fc 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/hfp/HeadsetPhoneStateTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/hfp/HeadsetPhoneStateTest.java
@@ -39,10 +39,12 @@ import com.android.internal.telephony.ISub;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.HashMap;
@@ -52,6 +54,8 @@ import java.util.HashMap;
@MediumTest
@RunWith(AndroidJUnit4.class)
public class HeadsetPhoneStateTest {
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private ISub mISub;
@Mock private IBinder mISubBinder;
@Mock private HeadsetService mHeadsetService;
@@ -69,7 +73,6 @@ public class HeadsetPhoneStateTest {
Looper.prepare();
}
IpcDataCache.disableForTestMode();
- MockitoAnnotations.initMocks(this);
SubscriptionManager.disableCaching();
TelephonyManager.disableServiceHandleCaching();
// Mock SubscriptionManager.getDefaultSubscriptionId() to return a valid value
diff --git a/android/app/tests/unit/src/com/android/bluetooth/hfp/HeadsetServiceAndStateMachineTest.java b/android/app/tests/unit/src/com/android/bluetooth/hfp/HeadsetServiceAndStateMachineTest.java
index 86d5bacd70..5c097e9756 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/hfp/HeadsetServiceAndStateMachineTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/hfp/HeadsetServiceAndStateMachineTest.java
@@ -41,7 +41,9 @@ import android.os.Looper;
import android.os.ParcelUuid;
import android.os.PowerManager;
import android.os.RemoteException;
+import android.platform.test.flag.junit.SetFlagsRule;
import android.telecom.PhoneAccount;
+import android.util.Log;
import androidx.test.InstrumentationRegistry;
import androidx.test.espresso.intent.Intents;
@@ -55,18 +57,21 @@ import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.RemoteDevices;
import com.android.bluetooth.btservice.SilenceDeviceManager;
import com.android.bluetooth.btservice.storage.DatabaseManager;
+import com.android.bluetooth.flags.Flags;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.lang.reflect.Method;
import java.util.Collections;
@@ -92,7 +97,7 @@ public class HeadsetServiceAndStateMachineTest {
private static final String TEST_PHONE_NUMBER = "1234567890";
private static final String TEST_CALLER_ID = "Test Name";
-
+ @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
private Context mTargetContext;
private HeadsetService mHeadsetService;
private BluetoothAdapter mAdapter;
@@ -106,6 +111,8 @@ public class HeadsetServiceAndStateMachineTest {
boolean mIsAdapterServiceSet;
boolean mIsHeadsetServiceStarted;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private HeadsetNativeInterface mNativeInterface;
private class HeadsetIntentReceiver extends BroadcastReceiver {
@@ -161,7 +168,6 @@ public class HeadsetServiceAndStateMachineTest {
@Before
public void setUp() throws Exception {
mTargetContext = InstrumentationRegistry.getTargetContext();
- MockitoAnnotations.initMocks(this);
PowerManager powerManager = mTargetContext.getSystemService(PowerManager.class);
mVoiceRecognitionWakeLock =
powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "VoiceRecognitionTest");
@@ -687,6 +693,26 @@ public class HeadsetServiceAndStateMachineTest {
}
/**
+ * Same process as {@link
+ * HeadsetServiceAndStateMachineTest#testVoiceRecognition_SingleHfInitiatedSuccess()} except the
+ * SCO connection is handled by the Audio Framework
+ */
+ @Test
+ public void testVoiceRecognition_SingleHfInitiatedSuccess_ScoManagedByAudio() {
+ mSetFlagsRule.enableFlags(Flags.FLAG_IS_SCO_MANAGED_BY_AUDIO);
+ // Connect HF
+ BluetoothDevice device = TestUtils.getTestDevice(mAdapter, 0);
+ connectTestDevice(device);
+ // Make device active
+ Assert.assertTrue(mHeadsetService.setActiveDevice(device));
+ verify(mNativeInterface).setActiveDevice(device);
+ Assert.assertEquals(device, mHeadsetService.getActiveDevice());
+ verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).sendBsir(eq(device), eq(true));
+ // Start voice recognition
+ startVoiceRecognitionFromHf_ScoManagedByAudio(device);
+ }
+
+ /**
* Test to verify the following behavior regarding active HF stop voice recognition
* in the successful scenario
* 1. HF device sends AT+BVRA=0
@@ -812,6 +838,26 @@ public class HeadsetServiceAndStateMachineTest {
}
/**
+ * Same process as {@link
+ * HeadsetServiceAndStateMachineTest#testVoiceRecognition_SingleAgInitiatedSuccess()} except the
+ * SCO connection is handled by the Audio Framework
+ */
+ @Test
+ public void testVoiceRecognition_SingleAgInitiatedSuccess_ScoManagedByAudio() {
+ mSetFlagsRule.enableFlags(Flags.FLAG_IS_SCO_MANAGED_BY_AUDIO);
+ // Connect HF
+ BluetoothDevice device = TestUtils.getTestDevice(mAdapter, 0);
+ connectTestDevice(device);
+ // Make device active
+ Assert.assertTrue(mHeadsetService.setActiveDevice(device));
+ verify(mNativeInterface).setActiveDevice(device);
+ Assert.assertEquals(device, mHeadsetService.getActiveDevice());
+ verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).sendBsir(eq(device), eq(true));
+ // Start voice recognition
+ startVoiceRecognitionFromAg_ScoManagedByAudio();
+ }
+
+ /**
* Test to verify the following behavior regarding AG initiated voice recognition
* in the successful scenario
* 1. AG starts voice recognition and notify the Bluetooth stack via
@@ -1167,6 +1213,26 @@ public class HeadsetServiceAndStateMachineTest {
verifyNoMoreInteractions(mNativeInterface);
}
+ private void startVoiceRecognitionFromHf_ScoManagedByAudio(BluetoothDevice device) {
+ if (!Flags.isScoManagedByAudio()) {
+ Log.i(TAG, "isScoManagedByAudio is disabled");
+ return;
+ }
+ // Start voice recognition
+ HeadsetStackEvent startVrEvent =
+ new HeadsetStackEvent(
+ HeadsetStackEvent.EVENT_TYPE_VR_STATE_CHANGED,
+ HeadsetHalConstants.VR_STATE_STARTED,
+ device);
+ mHeadsetService.messageFromNative(startVrEvent);
+ verify(mSystemInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).activateVoiceRecognition();
+ // has not add verification AudioDeviceInfo because it is final, unless add a wrapper
+ mHeadsetService.startVoiceRecognition(device);
+ verify(mAudioManager, times(0)).setA2dpSuspended(true);
+ verify(mAudioManager, times(0)).setLeAudioSuspended(true);
+ verify(mNativeInterface, times(0)).connectAudio(device);
+ }
+
private void startVoiceRecognitionFromAg() {
BluetoothDevice device = mHeadsetService.getActiveDevice();
Assert.assertNotNull(device);
@@ -1185,6 +1251,57 @@ public class HeadsetServiceAndStateMachineTest {
verifyNoMoreInteractions(mNativeInterface);
}
+ private void startVoiceRecognitionFromAg_ScoManagedByAudio() {
+ BluetoothDevice device = mHeadsetService.getActiveDevice();
+ Assert.assertNotNull(device);
+ mHeadsetService.startVoiceRecognition(device);
+ // has not add verification AudioDeviceInfo because it is final, unless add a wrapper
+ verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).startVoiceRecognition(device);
+ verify(mAudioManager, times(0)).setA2dpSuspended(true);
+ verify(mAudioManager, times(0)).setLeAudioSuspended(true);
+ verify(mNativeInterface, times(0)).connectAudio(device);
+ }
+
+ /**
+ * Test to verify the following behavior regarding phoneStateChanged when the SCO is managed by
+ * the Audio: When phoneStateChange returns, HeadsetStateMachine completes processing
+ * mActiveDevice's CALL_STATE_CHANGED message
+ */
+ @Test
+ public void testPhoneStateChange_SynchronousCallStateChanged() {
+ mSetFlagsRule.enableFlags(Flags.FLAG_IS_SCO_MANAGED_BY_AUDIO);
+
+ BluetoothDevice device = TestUtils.getTestDevice(mAdapter, 0);
+ Assert.assertNotNull(device);
+ connectTestDevice(device);
+
+ BluetoothDevice device2 = TestUtils.getTestDevice(mAdapter, 1);
+ Assert.assertNotNull(device2);
+ connectTestDevice(device2);
+
+ BluetoothDevice device3 = TestUtils.getTestDevice(mAdapter, 2);
+ Assert.assertNotNull(device3);
+ connectTestDevice(device3);
+
+ mHeadsetService.setActiveDevice(device);
+ Assert.assertTrue(mHeadsetService.setActiveDevice(device));
+
+ HeadsetCallState headsetCallState =
+ new HeadsetCallState(
+ 0, 0, HeadsetHalConstants.CALL_STATE_INCOMING, TEST_PHONE_NUMBER, 128, "");
+ mHeadsetService.phoneStateChanged(
+ headsetCallState.mNumActive,
+ headsetCallState.mNumHeld,
+ headsetCallState.mCallState,
+ headsetCallState.mNumber,
+ headsetCallState.mType,
+ headsetCallState.mName,
+ false);
+ // verify phoneStateChanged runs synchronously, which means when phoneStateChange returns,
+ // HeadsetStateMachine completes processing CALL_STATE_CHANGED message
+ verify(mNativeInterface, times(1)).phoneStateChange(device, headsetCallState);
+ }
+
private void connectTestDevice(BluetoothDevice device) {
when(mDatabaseManager.getProfileConnectionPolicy(device, BluetoothProfile.HEADSET))
.thenReturn(BluetoothProfile.CONNECTION_POLICY_UNKNOWN);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/hfp/HeadsetServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/hfp/HeadsetServiceTest.java
index 2aa1e1ff0d..95d70a9aa2 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/hfp/HeadsetServiceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/hfp/HeadsetServiceTest.java
@@ -59,11 +59,13 @@ import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.lang.reflect.Method;
import java.util.ArrayList;
@@ -89,6 +91,8 @@ public class HeadsetServiceTest {
private final HashMap<BluetoothDevice, HeadsetStateMachine> mStateMachines = new HashMap<>();
@Spy private HeadsetObjectsFactory mObjectsFactory = HeadsetObjectsFactory.getInstance();
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private ActiveDeviceManager mActiveDeviceManager;
@Mock private SilenceDeviceManager mSilenceDeviceManager;
@@ -102,7 +106,6 @@ public class HeadsetServiceTest {
@Before
public void setUp() throws Exception {
mTargetContext = InstrumentationRegistry.getTargetContext();
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
// We cannot mock HeadsetObjectsFactory.getInstance() with Mockito.
// Hence we need to use reflection to call a private method to
diff --git a/android/app/tests/unit/src/com/android/bluetooth/hfp/HeadsetStateMachineTest.java b/android/app/tests/unit/src/com/android/bluetooth/hfp/HeadsetStateMachineTest.java
index cc5119997d..c5fcd84cf4 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/hfp/HeadsetStateMachineTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/hfp/HeadsetStateMachineTest.java
@@ -71,7 +71,8 @@ import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.ArrayList;
@@ -96,6 +97,8 @@ public class HeadsetStateMachineTest {
private BluetoothDevice mTestDevice;
private ArgumentCaptor<Intent> mIntentArgument = ArgumentCaptor.forClass(Intent.class);
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private ActiveDeviceManager mActiveDeviceManager;
@Mock private SilenceDeviceManager mSilenceDeviceManager;
@@ -113,7 +116,6 @@ public class HeadsetStateMachineTest {
public void setUp() throws Exception {
mTargetContext = InstrumentationRegistry.getTargetContext();
// Setup mocks and test assets
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
// Stub system interface
doReturn(mPhoneState).when(mSystemInterface).getHeadsetPhoneState();
@@ -1724,6 +1726,29 @@ public class HeadsetStateMachineTest {
verifyAudioSystemSetParametersInvocation(false, false);
}
+ @Test
+ public void testSetAudioParameters_isScoManagedByAudio() {
+ mSetFlagsRule.enableFlags(Flags.FLAG_IS_SCO_MANAGED_BY_AUDIO);
+
+ setUpConnectedState();
+ mHeadsetStateMachine.sendMessage(
+ HeadsetStateMachine.STACK_EVENT,
+ new HeadsetStackEvent(
+ HeadsetStackEvent.EVENT_TYPE_SWB,
+ HeadsetHalConstants.BTHF_SWB_CODEC_LC3,
+ HeadsetHalConstants.BTHF_SWB_YES,
+ mTestDevice));
+
+ mHeadsetStateMachine.sendMessage(
+ HeadsetStateMachine.STACK_EVENT,
+ new HeadsetStackEvent(
+ HeadsetStackEvent.EVENT_TYPE_AUDIO_STATE_CHANGED,
+ HeadsetHalConstants.AUDIO_STATE_CONNECTED,
+ mTestDevice));
+
+ verify(mAudioManager, times(0)).setParameters(any());
+ }
+
/**
* verify parameters given to audio system
*
diff --git a/android/app/tests/unit/src/com/android/bluetooth/hfpclient/HeadsetClientServiceBinderTest.java b/android/app/tests/unit/src/com/android/bluetooth/hfpclient/HeadsetClientServiceBinderTest.java
index 9f686827ca..5fee0b31c9 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/hfpclient/HeadsetClientServiceBinderTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/hfpclient/HeadsetClientServiceBinderTest.java
@@ -28,16 +28,20 @@ import androidx.test.runner.AndroidJUnit4;
import com.android.bluetooth.x.com.android.modules.utils.SynchronousResultReceiver;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@SmallTest
@RunWith(AndroidJUnit4.class)
public class HeadsetClientServiceBinderTest {
private static final String REMOTE_DEVICE_ADDRESS = "00:00:00:00:00:00";
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private HeadsetClientService mService;
@@ -47,7 +51,6 @@ public class HeadsetClientServiceBinderTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mRemoteDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(REMOTE_DEVICE_ADDRESS);
mBinder = new HeadsetClientService.BluetoothHeadsetClientBinder(mService);
}
diff --git a/android/app/tests/unit/src/com/android/bluetooth/hfpclient/HeadsetClientServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/hfpclient/HeadsetClientServiceTest.java
index a6288f647f..fc08492d05 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/hfpclient/HeadsetClientServiceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/hfpclient/HeadsetClientServiceTest.java
@@ -47,11 +47,13 @@ import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@MediumTest
@RunWith(AndroidJUnit4.class)
@@ -64,6 +66,8 @@ public class HeadsetClientServiceTest {
private static final int STANDARD_WAIT_MILLIS = 1000;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private HeadsetClientStateMachine mStateMachine;
@Mock private NativeInterface mNativeInterface;
@@ -73,7 +77,6 @@ public class HeadsetClientServiceTest {
@Before
public void setUp() throws Exception {
mTargetContext = InstrumentationRegistry.getTargetContext();
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
mIsAdapterServiceSet = true;
diff --git a/android/app/tests/unit/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachineTest.java b/android/app/tests/unit/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachineTest.java
index f95bd870e6..1228ba1be5 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachineTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachineTest.java
@@ -68,13 +68,15 @@ import org.hamcrest.core.IsInstanceOf;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
import org.mockito.hamcrest.MockitoHamcrest;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.List;
import java.util.Set;
@@ -91,6 +93,8 @@ public class HeadsetClientStateMachineTest {
private BluetoothDevice mTestDevice;
private Context mTargetContext;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private Resources mMockHfpResources;
@Mock private HeadsetService mHeadsetService;
@@ -110,7 +114,6 @@ public class HeadsetClientStateMachineTest {
public void setUp() throws Exception {
mTargetContext = InstrumentationRegistry.getTargetContext();
// Setup mocks and test assets
- MockitoAnnotations.initMocks(this);
// Set a valid volume
when(mAudioManager.getStreamVolume(anyInt())).thenReturn(2);
when(mAudioManager.getStreamMaxVolume(anyInt())).thenReturn(10);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/hfpclient/HfpNativeInterfaceTest.java b/android/app/tests/unit/src/com/android/bluetooth/hfpclient/HfpNativeInterfaceTest.java
index 1db59c0774..5dc40be314 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/hfpclient/HfpNativeInterfaceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/hfpclient/HfpNativeInterfaceTest.java
@@ -27,14 +27,18 @@ import com.android.bluetooth.btservice.AdapterService;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
public class HfpNativeInterfaceTest {
private static final byte[] TEST_DEVICE_ADDRESS =
new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
HeadsetClientService mService;
@Mock
@@ -44,7 +48,6 @@ public class HfpNativeInterfaceTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
when(mService.isAvailable()).thenReturn(true);
HeadsetClientService.setHeadsetClientService(mService);
TestUtils.setAdapterService(mAdapterService);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/hfpclient/VendorCommandResponseProcessorTest.java b/android/app/tests/unit/src/com/android/bluetooth/hfpclient/VendorCommandResponseProcessorTest.java
index 3876a4aa27..48428b7044 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/hfpclient/VendorCommandResponseProcessorTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/hfpclient/VendorCommandResponseProcessorTest.java
@@ -32,10 +32,12 @@ import com.android.bluetooth.btservice.AdapterService;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@SmallTest
@RunWith(AndroidJUnit4.class)
@@ -44,6 +46,8 @@ public class VendorCommandResponseProcessorTest {
private BluetoothAdapter mAdapter;
private BluetoothDevice mTestDevice;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private NativeInterface mNativeInterface;
private VendorCommandResponseProcessor mProcessor;
@@ -54,7 +58,6 @@ public class VendorCommandResponseProcessorTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
mAdapter = BluetoothAdapter.getDefaultAdapter();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/hfpclient/connserv/HeadsetClientServiceInterfaceTest.java b/android/app/tests/unit/src/com/android/bluetooth/hfpclient/connserv/HeadsetClientServiceInterfaceTest.java
index c35ed99425..68918e5965 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/hfpclient/connserv/HeadsetClientServiceInterfaceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/hfpclient/connserv/HeadsetClientServiceInterfaceTest.java
@@ -31,10 +31,12 @@ import androidx.test.runner.AndroidJUnit4;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.List;
import java.util.Set;
@@ -58,12 +60,13 @@ public class HeadsetClientServiceInterfaceTest {
TEST_BUNDLE.putInt("test_int", 0);
}
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private HeadsetClientService mMockHeadsetClientService;
private HeadsetClientServiceInterface mServiceInterface;
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
HeadsetClientService.setHeadsetClientService(mMockHeadsetClientService);
mServiceInterface = new HeadsetClientServiceInterface();
}
diff --git a/android/app/tests/unit/src/com/android/bluetooth/hfpclient/connserv/HfpClientConnectionServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/hfpclient/connserv/HfpClientConnectionServiceTest.java
index 4be3028948..a4258951d6 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/hfpclient/connserv/HfpClientConnectionServiceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/hfpclient/connserv/HfpClientConnectionServiceTest.java
@@ -49,10 +49,12 @@ import com.android.bluetooth.btservice.AdapterService;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.Arrays;
import java.util.List;
@@ -67,6 +69,8 @@ public class HfpClientConnectionServiceTest {
.getAdapter().getRemoteDevice(TEST_DEVICE_ADDRESS);
private static final String TEST_NUMBER = "000-111-2222";
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private HeadsetClientService mMockHeadsetClientService;
@Mock private TelecomManager mMockTelecomManager;
@@ -77,7 +81,6 @@ public class HfpClientConnectionServiceTest {
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
Context targetContext = InstrumentationRegistry.getTargetContext();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/hfpclient/connserv/HfpClientDeviceBlockTest.java b/android/app/tests/unit/src/com/android/bluetooth/hfpclient/connserv/HfpClientDeviceBlockTest.java
index f9839328f5..c30e2b86a3 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/hfpclient/connserv/HfpClientDeviceBlockTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/hfpclient/connserv/HfpClientDeviceBlockTest.java
@@ -33,11 +33,13 @@ import androidx.test.runner.AndroidJUnit4;
import org.junit.Before;
import org.junit.Ignore;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@MediumTest
@RunWith(AndroidJUnit4.class)
@@ -47,6 +49,8 @@ public class HfpClientDeviceBlockTest {
private static final String KEY_SCO_STATE = "com.android.bluetooth.hfpclient.SCO_STATE";
private static final String TEST_PACKAGE = "test";
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private HeadsetClientService mHeadsetClientService;
@Mock
@@ -65,7 +69,6 @@ public class HfpClientDeviceBlockTest {
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
// HfpClientConnectionService.createAccount is static and can't be mocked, so the
// application context and resources must be mocked to avoid NPE when creating an
diff --git a/android/app/tests/unit/src/com/android/bluetooth/hid/BluetoothHidDeviceBinderTest.java b/android/app/tests/unit/src/com/android/bluetooth/hid/BluetoothHidDeviceBinderTest.java
index 2138729b74..6c6b311240 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/hid/BluetoothHidDeviceBinderTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/hid/BluetoothHidDeviceBinderTest.java
@@ -34,14 +34,18 @@ import android.content.AttributionSource;
import com.android.bluetooth.x.com.android.modules.utils.SynchronousResultReceiver;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
public class BluetoothHidDeviceBinderTest {
private static final String TEST_DEVICE_ADDRESS = "00:00:00:00:00:00";
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private HidDeviceService mService;
private AttributionSource mAttributionSource;
@@ -50,7 +54,6 @@ public class BluetoothHidDeviceBinderTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
when(mService.isAvailable()).thenReturn(true);
mBinder = new HidDeviceService.BluetoothHidDeviceBinder(mService);
mAttributionSource = new AttributionSource.Builder(1).build();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/hid/HidDeviceNativeInterfaceTest.java b/android/app/tests/unit/src/com/android/bluetooth/hid/HidDeviceNativeInterfaceTest.java
index fd70351493..41b4006ee8 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/hid/HidDeviceNativeInterfaceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/hid/HidDeviceNativeInterfaceTest.java
@@ -29,13 +29,17 @@ import com.android.bluetooth.btservice.AdapterService;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
public class HidDeviceNativeInterfaceTest {
private static final byte[] TEST_DEVICE_ADDRESS =
new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
HidDeviceService mService;
@Mock
@@ -45,7 +49,6 @@ public class HidDeviceNativeInterfaceTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
when(mService.isAvailable()).thenReturn(true);
HidDeviceService.setHidDeviceService(mService);
TestUtils.setAdapterService(mAdapterService);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/hid/HidDeviceTest.java b/android/app/tests/unit/src/com/android/bluetooth/hid/HidDeviceTest.java
index db4a62ee35..4b6672ec6c 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/hid/HidDeviceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/hid/HidDeviceTest.java
@@ -41,10 +41,12 @@ import com.android.bluetooth.btservice.storage.DatabaseManager;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
@@ -70,6 +72,8 @@ public class HidDeviceTest {
private static final int CALLBACK_ON_INTR_DATA = 5;
private static final int CALLBACK_ON_VIRTUAL_UNPLUG = 6;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private DatabaseManager mDatabaseManager;
@Mock private HidDeviceNativeInterface mHidDeviceNativeInterface;
@@ -100,8 +104,6 @@ public class HidDeviceTest {
}
Assert.assertNotNull(Looper.myLooper());
- // Set up mocks and test assets
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
doReturn(mDatabaseManager).when(mAdapterService).getDatabase();
setHidDeviceNativeInterfaceInstance(mHidDeviceNativeInterface);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/hid/HidHostServiceBinderTest.java b/android/app/tests/unit/src/com/android/bluetooth/hid/HidHostServiceBinderTest.java
index 8bedfb3e2a..aeabb31e42 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/hid/HidHostServiceBinderTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/hid/HidHostServiceBinderTest.java
@@ -30,7 +30,8 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@SmallTest
@RunWith(AndroidJUnit4.class)
@@ -38,6 +39,8 @@ public class HidHostServiceBinderTest {
@Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
private static final String REMOTE_DEVICE_ADDRESS = "00:00:00:00:00:00";
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private HidHostService mService;
@@ -47,7 +50,6 @@ public class HidHostServiceBinderTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mRemoteDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(REMOTE_DEVICE_ADDRESS);
mBinder = new HidHostService.BluetoothHidHostBinder(mService);
}
diff --git a/android/app/tests/unit/src/com/android/bluetooth/hid/HidHostServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/hid/HidHostServiceTest.java
index 41652ab673..e21145d79d 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/hid/HidHostServiceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/hid/HidHostServiceTest.java
@@ -33,10 +33,12 @@ import com.android.bluetooth.btservice.storage.DatabaseManager;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@MediumTest
@RunWith(AndroidJUnit4.class)
@@ -46,6 +48,8 @@ public class HidHostServiceTest {
private BluetoothDevice mTestDevice;
private Context mTargetContext;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private DatabaseManager mDatabaseManager;
@Mock private HidHostNativeInterface mNativeInterface;
@@ -53,7 +57,6 @@ public class HidHostServiceTest {
@Before
public void setUp() throws Exception {
mTargetContext = InstrumentationRegistry.getTargetContext();
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
when(mAdapterService.getDatabase()).thenReturn(mDatabaseManager);
HidHostNativeInterface.setInstance(mNativeInterface);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/le_audio/ContentControlIdKeeperTest.java b/android/app/tests/unit/src/com/android/bluetooth/le_audio/ContentControlIdKeeperTest.java
index 9e8ebe5d36..6a3443387d 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/le_audio/ContentControlIdKeeperTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/le_audio/ContentControlIdKeeperTest.java
@@ -30,10 +30,12 @@ import com.android.bluetooth.btservice.ServiceFactory;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.Map;
import java.util.UUID;
@@ -41,6 +43,8 @@ import java.util.UUID;
@MediumTest
@RunWith(AndroidJUnit4.class)
public class ContentControlIdKeeperTest {
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
ServiceFactory mServiceFactoryMock;
@Mock
@@ -48,7 +52,6 @@ public class ContentControlIdKeeperTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
doReturn(mLeAudioServiceMock).when(mServiceFactoryMock).getLeAudioService();
ContentControlIdKeeper.initForTesting(mServiceFactoryMock);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioBinderTest.java b/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioBinderTest.java
index d7f7d419d3..df2877473f 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioBinderTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioBinderTest.java
@@ -52,7 +52,8 @@ import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.List;
import java.util.UUID;
@@ -62,6 +63,8 @@ public class LeAudioBinderTest {
@Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
private LeAudioService mLeAudioService;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private LeAudioNativeInterface mNativeInterface;
@Mock private DatabaseManager mDatabaseManager;
@@ -79,7 +82,6 @@ public class LeAudioBinderTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
doReturn(false).when(mAdapterService).isQuietModeEnabled();
doReturn(mDatabaseManager).when(mAdapterService).getDatabase();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioBroadcastServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioBroadcastServiceTest.java
index 17057c9f3e..8a6a4de6c5 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioBroadcastServiceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioBroadcastServiceTest.java
@@ -54,8 +54,9 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;
@@ -76,6 +77,8 @@ public class LeAudioBroadcastServiceTest {
private LeAudioService mService;
private LeAudioIntentReceiver mLeAudioIntentReceiver;
private LinkedBlockingQueue<Intent> mIntentQueue;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private ActiveDeviceManager mActiveDeviceManager;
@Mock
private AdapterService mAdapterService;
@@ -195,8 +198,6 @@ public class LeAudioBroadcastServiceTest {
public void setUp() throws Exception {
mTargetContext = InstrumentationRegistry.getTargetContext();
- // Set up mocks and test assets
- MockitoAnnotations.initMocks(this);
// Use spied objects factory
doNothing().when(mTmapGattServer).start(anyInt());
diff --git a/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioBroadcasterNativeInterfaceTest.java b/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioBroadcasterNativeInterfaceTest.java
index 5e4e44a9e6..045b5a2667 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioBroadcasterNativeInterfaceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioBroadcasterNativeInterfaceTest.java
@@ -27,14 +27,18 @@ import androidx.test.runner.AndroidJUnit4;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@RunWith(AndroidJUnit4.class)
public class LeAudioBroadcasterNativeInterfaceTest {
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private LeAudioService mMockService;
@@ -42,7 +46,6 @@ public class LeAudioBroadcasterNativeInterfaceTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
when(mMockService.isAvailable()).thenReturn(true);
LeAudioService.setLeAudioService(mMockService);
mNativeInterface = LeAudioBroadcasterNativeInterface.getInstance();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioNativeInterfaceTest.java b/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioNativeInterfaceTest.java
index 7b45a9fa64..cf88ce4925 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioNativeInterfaceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioNativeInterfaceTest.java
@@ -28,14 +28,18 @@ import androidx.test.runner.AndroidJUnit4;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@RunWith(AndroidJUnit4.class)
public class LeAudioNativeInterfaceTest {
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private LeAudioService mMockService;
@@ -43,7 +47,6 @@ public class LeAudioNativeInterfaceTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
when(mMockService.isAvailable()).thenReturn(true);
LeAudioService.setLeAudioService(mMockService);
mNativeInterface = LeAudioNativeInterface.getInstance();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioServiceTest.java
index 30bb834a44..9ae849428d 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioServiceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioServiceTest.java
@@ -78,8 +78,9 @@ import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.HashMap;
import java.util.HashSet;
@@ -118,6 +119,8 @@ public class LeAudioServiceTest {
private BroadcastReceiver mLeAudioIntentReceiver;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private ActiveDeviceManager mActiveDeviceManager;
@Mock private AudioManager mAudioManager;
@@ -166,8 +169,6 @@ public class LeAudioServiceTest {
public void setUp() throws Exception {
mTargetContext = InstrumentationRegistry.getTargetContext();
- // Set up mocks and test assets
- MockitoAnnotations.initMocks(this);
// Use spied objects factory
doNothing().when(mTmapGattServer).start(anyInt());
diff --git a/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioStateMachineTest.java b/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioStateMachineTest.java
index d372c172fd..2921483669 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioStateMachineTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioStateMachineTest.java
@@ -45,10 +45,12 @@ import com.android.bluetooth.btservice.AdapterService;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@MediumTest
@RunWith(AndroidJUnit4.class)
@@ -60,6 +62,8 @@ public class LeAudioStateMachineTest {
private BluetoothDevice mTestDevice;
private static final int TIMEOUT_MS = 1000;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private LeAudioService mLeAudioService;
@Mock private LeAudioNativeInterface mLeAudioNativeInterface;
@@ -67,8 +71,6 @@ public class LeAudioStateMachineTest {
@Before
public void setUp() throws Exception {
mTargetContext = InstrumentationRegistry.getTargetContext();
- // Set up mocks and test assets
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
mAdapter = BluetoothAdapter.getDefaultAdapter();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioTmapGattServerTest.java b/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioTmapGattServerTest.java
index da9e348712..6afe455ca1 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioTmapGattServerTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioTmapGattServerTest.java
@@ -37,11 +37,13 @@ import androidx.test.runner.AndroidJUnit4;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@MediumTest
@RunWith(AndroidJUnit4.class)
@@ -49,6 +51,8 @@ public class LeAudioTmapGattServerTest {
private static final int TEST_ROLE_MASK =
LeAudioTmapGattServer.TMAP_ROLE_FLAG_CG | LeAudioTmapGattServer.TMAP_ROLE_FLAG_UMS;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private LeAudioTmapGattServer.BluetoothGattServerProxy mGattServerProxy;
@@ -56,7 +60,6 @@ public class LeAudioTmapGattServerTest {
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
doReturn(true).when(mGattServerProxy).open(any());
doReturn(true).when(mGattServerProxy).addService(any());
mServer = new LeAudioTmapGattServer(mGattServerProxy);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/le_scan/AppScanStatsTest.java b/android/app/tests/unit/src/com/android/bluetooth/le_scan/AppScanStatsTest.java
index 5814b6944f..d7b92e0ec6 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/le_scan/AppScanStatsTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/le_scan/AppScanStatsTest.java
@@ -41,7 +41,8 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.ArrayList;
import java.util.List;
@@ -56,6 +57,8 @@ public class AppScanStatsTest {
@Rule
public final ServiceTestRule mServiceRule = new ServiceTestRule();
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private ContextMap map;
@@ -70,7 +73,6 @@ public class AppScanStatsTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/le_scan/PeriodicScanManagerTest.java b/android/app/tests/unit/src/com/android/bluetooth/le_scan/PeriodicScanManagerTest.java
index 61517270c3..1137a51dc8 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/le_scan/PeriodicScanManagerTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/le_scan/PeriodicScanManagerTest.java
@@ -42,16 +42,20 @@ import com.android.bluetooth.btservice.AdapterService;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
/** Test cases for {@link PeriodicScanManagerTest}. */
@SmallTest
@RunWith(AndroidJUnit4.class)
public class PeriodicScanManagerTest {
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private PeriodicScanNativeInterface mPeriodicScanNativeInterface;
@Mock private AdapterService mAdapterService;
@Mock private IPeriodicAdvertisingCallback mCallback;
@@ -68,7 +72,6 @@ public class PeriodicScanManagerTest {
@Before
public void setUp() throws Exception {
mTargetContext = InstrumentationRegistry.getTargetContext();
- MockitoAnnotations.initMocks(this);
PeriodicScanNativeInterface.setInstance(mPeriodicScanNativeInterface);
mPeriodicScanManager = new PeriodicScanManager(mAdapterService);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/le_scan/ScanManagerTest.java b/android/app/tests/unit/src/com/android/bluetooth/le_scan/ScanManagerTest.java
index f074e57dcf..b1804031b9 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/le_scan/ScanManagerTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/le_scan/ScanManagerTest.java
@@ -85,8 +85,9 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.ArrayList;
import java.util.List;
@@ -125,6 +126,8 @@ public class ScanManagerTest {
@Rule public final ServiceTestRule mServiceRule = new ServiceTestRule();
@Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private GattService mMockGattService;
@Mock private TransitionalScanHelper mMockScanHelper;
@@ -142,7 +145,6 @@ public class ScanManagerTest {
@Before
public void setUp() throws Exception {
mTargetContext = InstrumentationRegistry.getTargetContext();
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
when(mAdapterService.getScanTimeoutMillis())
diff --git a/android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapContentObserverTest.java b/android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapContentObserverTest.java
index 8d052d2455..3607fbb035 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapContentObserverTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapContentObserverTest.java
@@ -53,12 +53,14 @@ import com.google.android.mms.pdu.PduHeaders;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.io.IOException;
import java.text.SimpleDateFormat;
@@ -116,6 +118,8 @@ public class BluetoothMapContentObserverTest {
static final int TEST_PRIORITY = 1;
static final int TEST_LAST_ONLINE = 1;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private BluetoothMnsObexClient mClient;
@Mock
@@ -171,7 +175,6 @@ public class BluetoothMapContentObserverTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
BluetoothMethodProxy.setInstanceForTesting(mMapMethodProxy);
if (Looper.myLooper() == null) {
Looper.prepare();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapContentTest.java b/android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapContentTest.java
index 71f2f5af38..20237fe896 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapContentTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapContentTest.java
@@ -54,11 +54,13 @@ import com.google.android.mms.pdu.PduHeaders;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.io.ByteArrayInputStream;
import java.io.FileDescriptor;
@@ -111,6 +113,8 @@ public class BluetoothMapContentTest {
private static final String TEST_RECEPTION_STATUS = "complete";
private static final String TEST_EMAIL = "test@google.com";
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private BluetoothMapAccountItem mAccountItem;
@Mock
@@ -134,7 +138,6 @@ public class BluetoothMapContentTest {
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
BluetoothMethodProxy.setInstanceForTesting(mMapMethodProxy);
mContent = new BluetoothMapContent(mContext, mAccountItem, mMasInstance);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapConvoContactElementTest.java b/android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapConvoContactElementTest.java
index 35c4a3e2e5..68d0e0d92e 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapConvoContactElementTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapConvoContactElementTest.java
@@ -26,11 +26,12 @@ import androidx.test.runner.AndroidJUnit4;
import com.android.bluetooth.SignedLongLong;
-import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlSerializer;
@@ -53,14 +54,11 @@ public class BluetoothMapConvoContactElementTest {
private final SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd'T'HHmmss");
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private MapContact mMapContact;
- @Before
- public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
- }
-
@Test
public void constructorWithArguments() {
BluetoothMapConvoContactElement contactElement =
@@ -201,4 +199,4 @@ public class BluetoothMapConvoContactElementTest {
assertThat(contactElement.compareTo(contactElementSameLastActivity)).isEqualTo(0);
}
-} \ No newline at end of file
+}
diff --git a/android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapMasInstanceTest.java b/android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapMasInstanceTest.java
index 34105afb67..b985cd3a4a 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapMasInstanceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapMasInstanceTest.java
@@ -26,10 +26,12 @@ import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@SmallTest
@RunWith(AndroidJUnit4.class)
@@ -47,6 +49,8 @@ public class BluetoothMapMasInstanceTest {
private BluetoothMapAccountItem mAccountItem;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private Context mContext;
@Mock
@@ -54,7 +58,6 @@ public class BluetoothMapMasInstanceTest {
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
mAccountItem = BluetoothMapAccountItem.create(TEST_ID, TEST_NAME, TEST_PACKAGE_NAME,
TEST_PROVIDER_AUTHORITY, TEST_DRAWABLE, TEST_TYPE, TEST_UCI, TEST_UCI_PREFIX);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapObexServerTest.java b/android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapObexServerTest.java
index 5aedef3c26..40503a775f 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapObexServerTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapObexServerTest.java
@@ -42,11 +42,13 @@ import com.android.bluetooth.mapapi.BluetoothMapContract;
import com.android.obex.ResponseCodes;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@SmallTest
@RunWith(AndroidJUnit4.class)
@@ -67,6 +69,8 @@ public class BluetoothMapObexServerTest {
private BluetoothMapObexServer mObexServer;
private BluetoothMapAppParams mParams;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private Context mContext;
@Mock
@@ -80,7 +84,6 @@ public class BluetoothMapObexServerTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
BluetoothMethodProxy.setInstanceForTesting(mMapMethodProxy);
doReturn(mProviderClient).when(
mMapMethodProxy).contentResolverAcquireUnstableContentProviderClient(any(), any());
diff --git a/android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapServiceBinderTest.java b/android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapServiceBinderTest.java
index 498fefa79c..e87c55b7d9 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapServiceBinderTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapServiceBinderTest.java
@@ -28,16 +28,20 @@ import androidx.test.runner.AndroidJUnit4;
import com.android.bluetooth.x.com.android.modules.utils.SynchronousResultReceiver;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@SmallTest
@RunWith(AndroidJUnit4.class)
public class BluetoothMapServiceBinderTest {
private static final String REMOTE_DEVICE_ADDRESS = "00:00:00:00:00:00";
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private BluetoothMapService mService;
@@ -47,7 +51,6 @@ public class BluetoothMapServiceBinderTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mRemoteDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(REMOTE_DEVICE_ADDRESS);
mBinder = new BluetoothMapService.BluetoothMapBinder(mService);
}
diff --git a/android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapServiceTest.java
index 5989177b80..009d79d494 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapServiceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapServiceTest.java
@@ -48,10 +48,12 @@ import com.android.bluetooth.btservice.storage.DatabaseManager;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@MediumTest
@RunWith(AndroidJUnit4.class)
@@ -62,6 +64,7 @@ public class BluetoothMapServiceTest {
private BluetoothAdapter mAdapter = null;
private BluetoothDevice mRemoteDevice;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
@Mock private AdapterService mAdapterService;
@Mock private DatabaseManager mDatabaseManager;
@@ -69,7 +72,6 @@ public class BluetoothMapServiceTest {
@Before
public void setUp() throws Exception {
Context targetContext = InstrumentationRegistry.getTargetContext();
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
doReturn(mDatabaseManager).when(mAdapterService).getDatabase();
mService = new BluetoothMapService(targetContext);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapSmsPduTest.java b/android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapSmsPduTest.java
index f8bed9641c..ab6f9cf469 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapSmsPduTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapSmsPduTest.java
@@ -33,10 +33,12 @@ import com.android.bluetooth.map.BluetoothMapSmsPdu.SmsPdu;
import org.junit.Assume;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
@@ -57,6 +59,8 @@ public class BluetoothMapSmsPduTest {
private int TEST_LANGUAGE_TABLE;
private SmsManager mSmsManager = SmsManager.getDefault();
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private Context mTargetContext;
@Mock
@@ -64,7 +68,6 @@ public class BluetoothMapSmsPduTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
when(mTargetContext.getSystemServiceName(TelephonyManager.class)).thenReturn(
"TELEPHONY_SERVICE");
when(mTargetContext.getSystemService("TELEPHONY_SERVICE")).thenReturn(mTelephonyManager);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/map/SmsMmsContactsTest.java b/android/app/tests/unit/src/com/android/bluetooth/map/SmsMmsContactsTest.java
index c65053e81c..38f9ca46b2 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/map/SmsMmsContactsTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/map/SmsMmsContactsTest.java
@@ -31,11 +31,13 @@ import com.android.bluetooth.BluetoothMethodProxy;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@SmallTest
@RunWith(AndroidJUnit4.class)
@@ -46,6 +48,8 @@ public class SmsMmsContactsTest {
private static final String TEST_PHONE = "test_phone";
private static final String TEST_CONTACT_NAME_FILTER = "test_contact_name_filter";
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private ContentResolver mResolver;
@Spy
@@ -55,7 +59,6 @@ public class SmsMmsContactsTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
BluetoothMethodProxy.setInstanceForTesting(mMapMethodProxy);
mContacts = new SmsMmsContacts();
}
diff --git a/android/app/tests/unit/src/com/android/bluetooth/mapapi/BluetoothMapEmailProviderTest.java b/android/app/tests/unit/src/com/android/bluetooth/mapapi/BluetoothMapEmailProviderTest.java
index 0ef6e4e95a..c109dcceb4 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/mapapi/BluetoothMapEmailProviderTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/mapapi/BluetoothMapEmailProviderTest.java
@@ -36,10 +36,12 @@ import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -55,12 +57,13 @@ public class BluetoothMapEmailProviderTest {
private Context mContext;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Spy
private BluetoothMapEmailProvider mProvider = new TestBluetoothMapEmailProvider();
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mContext = InstrumentationRegistry.getTargetContext();
}
diff --git a/android/app/tests/unit/src/com/android/bluetooth/mapapi/BluetoothMapIMProviderTest.java b/android/app/tests/unit/src/com/android/bluetooth/mapapi/BluetoothMapIMProviderTest.java
index f9e6bb35c8..cae5876491 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/mapapi/BluetoothMapIMProviderTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/mapapi/BluetoothMapIMProviderTest.java
@@ -41,11 +41,13 @@ import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.time.Instant;
import java.util.AbstractMap;
@@ -66,12 +68,13 @@ public class BluetoothMapIMProviderTest {
private Context mContext;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Spy
private BluetoothMapIMProvider mProvider = new TestBluetoothMapIMProvider();
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mContext = InstrumentationRegistry.getTargetContext();
}
diff --git a/android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientContentTest.java b/android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientContentTest.java
index 5c735c9d45..f58e0992ca 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientContentTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientContentTest.java
@@ -55,12 +55,14 @@ import com.android.vcard.VCardProperty;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.Arrays;
import java.util.HashMap;
@@ -92,6 +94,8 @@ public class MapClientContentTest {
private MapClientContent mMapClientContent;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private AdapterService mAdapterService;
@Mock
@@ -115,7 +119,6 @@ public class MapClientContentTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mMockSmsContentProvider = new FakeContentProvider(mMockContext);
mMockMmsContentProvider = new FakeContentProvider(mMockContext);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientServiceBinderTest.java b/android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientServiceBinderTest.java
index 1604459c36..e95088f583 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientServiceBinderTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientServiceBinderTest.java
@@ -29,16 +29,20 @@ import androidx.test.runner.AndroidJUnit4;
import com.android.bluetooth.x.com.android.modules.utils.SynchronousResultReceiver;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@MediumTest
@RunWith(AndroidJUnit4.class)
public class MapClientServiceBinderTest {
private static final String REMOTE_DEVICE_ADDRESS = "00:00:00:00:00:00";
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private MapClientService mService;
@@ -48,7 +52,6 @@ public class MapClientServiceBinderTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mRemoteDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(REMOTE_DEVICE_ADDRESS);
mBinder = new MapClientService.Binder(mService);
}
diff --git a/android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientServiceTest.java
index 0622a7eba3..c24df8b84d 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientServiceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientServiceTest.java
@@ -44,16 +44,19 @@ import com.android.bluetooth.btservice.storage.DatabaseManager;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@MediumTest
@RunWith(AndroidJUnit4.class)
public class MapClientServiceTest {
private static final String REMOTE_DEVICE_ADDRESS = "00:00:00:00:00:00";
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
@Mock private AdapterService mAdapterService;
@Mock private DatabaseManager mDatabaseManager;
@@ -66,7 +69,6 @@ public class MapClientServiceTest {
@Before
public void setUp() throws Exception {
Context targetContext = InstrumentationRegistry.getTargetContext();
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
doReturn(mDatabaseManager).when(mAdapterService).getDatabase();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientStateMachineTest.java b/android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientStateMachineTest.java
index baadbd75e7..2c18e366ff 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientStateMachineTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientStateMachineTest.java
@@ -74,7 +74,8 @@ import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.time.Instant;
import java.util.ArrayList;
@@ -125,6 +126,8 @@ public class MapClientStateMachineTest {
private Context mTargetContext;
private Handler mHandler;
private ArgumentCaptor<Intent> mIntentArgument = ArgumentCaptor.forClass(Intent.class);
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private AdapterService mAdapterService;
@Mock
@@ -202,7 +205,6 @@ public class MapClientStateMachineTest {
@Before
public void setUp() throws Exception {
mTargetContext = InstrumentationRegistry.getTargetContext();
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
mIsAdapterServiceSet = true;
mMockContentProvider = new MockSmsContentProvider();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientTest.java b/android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientTest.java
index ab5f97b95d..e36a25ab8d 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientTest.java
@@ -37,10 +37,12 @@ import com.android.bluetooth.btservice.storage.DatabaseManager;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.ArrayList;
import java.util.List;
@@ -56,6 +58,8 @@ public class MapClientTest {
private boolean mIsAdapterServiceSet;
private boolean mIsMapClientServiceStarted;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private MnsService mMockMnsService;
@Mock private DatabaseManager mDatabaseManager;
@@ -64,7 +68,6 @@ public class MapClientTest {
@Before
public void setUp() throws Exception {
mTargetContext = InstrumentationRegistry.getTargetContext();
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
mIsAdapterServiceSet = true;
when(mAdapterService.getDatabase()).thenReturn(mDatabaseManager);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/mapclient/MnsObexServerTest.java b/android/app/tests/unit/src/com/android/bluetooth/mapclient/MnsObexServerTest.java
index fb9d899cf3..ffef488313 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/mapclient/MnsObexServerTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/mapclient/MnsObexServerTest.java
@@ -31,10 +31,12 @@ import com.android.obex.Operation;
import com.android.obex.ResponseCodes;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
@@ -43,6 +45,8 @@ import java.io.DataInputStream;
@RunWith(AndroidJUnit4.class)
public class MnsObexServerTest {
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
MceStateMachine mStateMachine;
@@ -50,7 +54,6 @@ public class MnsObexServerTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mServer = new MnsObexServer(mStateMachine, null);
}
diff --git a/android/app/tests/unit/src/com/android/bluetooth/mcp/McpServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/mcp/McpServiceTest.java
index 5c77c88ba5..ceb34661f2 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/mcp/McpServiceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/mcp/McpServiceTest.java
@@ -34,10 +34,12 @@ import com.android.bluetooth.btservice.AdapterService;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@MediumTest
@RunWith(AndroidJUnit4.class)
@@ -46,6 +48,8 @@ public class McpServiceTest {
private McpService mMcpService;
private Context mTargetContext;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private AdapterService mAdapterService;
@Mock
@@ -60,7 +64,6 @@ public class McpServiceTest {
Looper.prepare();
}
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
mAdapter = BluetoothAdapter.getDefaultAdapter();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/mcp/MediaControlGattServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/mcp/MediaControlGattServiceTest.java
index 6f16c76557..f57c002c56 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/mcp/MediaControlGattServiceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/mcp/MediaControlGattServiceTest.java
@@ -48,7 +48,8 @@ import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@@ -73,6 +74,8 @@ public class MediaControlGattServiceTest {
private MediaControlGattService mMcpService;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private MediaControlGattService.BluetoothGattServerProxy mMockGattServer;
@Mock private McpService mMockMcpService;
@@ -88,7 +91,6 @@ public class MediaControlGattServiceTest {
Looper.prepare();
}
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
mAdapter = BluetoothAdapter.getDefaultAdapter();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/mcp/MediaControlProfileTest.java b/android/app/tests/unit/src/com/android/bluetooth/mcp/MediaControlProfileTest.java
index e230378e3e..7ce0374564 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/mcp/MediaControlProfileTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/mcp/MediaControlProfileTest.java
@@ -43,12 +43,14 @@ import com.android.bluetooth.btservice.AdapterService;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.ArrayList;
import java.util.HashMap;
@@ -71,6 +73,8 @@ public class MediaControlProfileTest {
private CharSequence charSequence = "TestPlayer";
private MediaControlServiceCallbacks mMcpServiceCallbacks;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private MediaData mMockMediaData;
@Mock private MediaPlayerList mMockMediaPlayerList;
@@ -94,7 +98,6 @@ public class MediaControlProfileTest {
mTargetContext = InstrumentationRegistry.getTargetContext();
MediaControlProfile.ListCallback listCallback;
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
mAdapter = BluetoothAdapter.getDefaultAdapter();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppBtEnableActivityTest.java b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppBtEnableActivityTest.java
index 7156c70804..08f539de2d 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppBtEnableActivityTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppBtEnableActivityTest.java
@@ -42,7 +42,6 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-import org.mockito.MockitoAnnotations;
public class BluetoothOppBtEnableActivityTest {
@@ -56,7 +55,6 @@ public class BluetoothOppBtEnableActivityTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mTargetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
mIntent = new Intent();
mIntent.setClass(mTargetContext, BluetoothOppBtEnableActivity.class);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppBtEnablingActivityTest.java b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppBtEnablingActivityTest.java
index c4abf9a292..07b634279f 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppBtEnablingActivityTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppBtEnablingActivityTest.java
@@ -48,13 +48,16 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.concurrent.atomic.AtomicBoolean;
@RunWith(AndroidJUnit4.class)
public class BluetoothOppBtEnablingActivityTest {
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Spy
BluetoothMethodProxy mBluetoothMethodProxy;
@@ -70,7 +73,6 @@ public class BluetoothOppBtEnablingActivityTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mBluetoothMethodProxy = Mockito.spy(BluetoothMethodProxy.getInstance());
BluetoothMethodProxy.setInstanceForTesting(mBluetoothMethodProxy);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppHandoverReceiverTest.java b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppHandoverReceiverTest.java
index fd6261e308..b27740bf0b 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppHandoverReceiverTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppHandoverReceiverTest.java
@@ -39,10 +39,12 @@ import com.android.bluetooth.BluetoothMethodProxy;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.ArrayList;
import java.util.List;
@@ -52,12 +54,13 @@ import java.util.List;
public class BluetoothOppHandoverReceiverTest {
Context mContext;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Spy
BluetoothMethodProxy mCallProxy = BluetoothMethodProxy.getInstance();
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
mContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
BluetoothMethodProxy.setInstanceForTesting(mCallProxy);
doReturn(0).when(mCallProxy).contentResolverDelete(any(), any(Uri.class), any(), any());
diff --git a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppLauncherActivityTest.java b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppLauncherActivityTest.java
index 58ee1b6067..ddd18d5250 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppLauncherActivityTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppLauncherActivityTest.java
@@ -57,7 +57,8 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.io.File;
@@ -68,6 +69,8 @@ public class BluetoothOppLauncherActivityTest {
Intent mIntent;
BluetoothMethodProxy mMethodProxy;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
BluetoothOppManager mBluetoothOppManager;
@@ -78,7 +81,6 @@ public class BluetoothOppLauncherActivityTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mTargetContext = spy(new ContextWrapper(
ApplicationProvider.getApplicationContext()));
mMethodProxy = spy(BluetoothMethodProxy.getInstance());
diff --git a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppManagerTest.java b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppManagerTest.java
index b588b2c1b9..695703c1f3 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppManagerTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppManagerTest.java
@@ -51,7 +51,6 @@ import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.MockitoAnnotations;
import java.util.ArrayList;
import java.util.List;
@@ -65,7 +64,6 @@ public class BluetoothOppManagerTest {
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
mContext = spy(new ContextWrapper(
InstrumentationRegistry.getInstrumentation().getTargetContext()));
diff --git a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppNotificationTest.java b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppNotificationTest.java
index 3dc2a51674..f76d5e859e 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppNotificationTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppNotificationTest.java
@@ -53,13 +53,16 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@RunWith(AndroidJUnit4.class)
public class BluetoothOppNotificationTest {
static final int TIMEOUT_MS = 3000;
static final int WORKAROUND_TIMEOUT = 3000;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
BluetoothMethodProxy mMethodProxy;
@@ -77,7 +80,6 @@ public class BluetoothOppNotificationTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mTargetContext = spy(new ContextWrapper(
ApplicationProvider.getApplicationContext()));
BluetoothMethodProxy.setInstanceForTesting(mMethodProxy);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppObexClientSessionTest.java b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppObexClientSessionTest.java
index 4cc481020a..60a04b6149 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppObexClientSessionTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppObexClientSessionTest.java
@@ -44,10 +44,12 @@ import com.android.obex.ClientSession;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.io.IOException;
import java.io.InputStream;
@@ -57,6 +59,8 @@ import java.util.concurrent.TimeUnit;
@RunWith(AndroidJUnit4.class)
public class BluetoothOppObexClientSessionTest {
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
BluetoothMethodProxy mMethodProxy;
@@ -68,7 +72,6 @@ public class BluetoothOppObexClientSessionTest {
@Before
public void setUp() throws IOException {
- MockitoAnnotations.initMocks(this);
mTargetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
mClientSession = new BluetoothOppObexClientSession(mTargetContext, mTransport);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppObexServerSessionTest.java b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppObexServerSessionTest.java
index 3971d0e7b0..2e5bf6383e 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppObexServerSessionTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppObexServerSessionTest.java
@@ -47,10 +47,12 @@ import com.android.obex.ResponseCodes;
import org.junit.After;
import org.junit.Assume;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.io.IOException;
import java.io.InputStream;
@@ -58,6 +60,8 @@ import java.io.OutputStream;
@RunWith(AndroidJUnit4.class)
public class BluetoothOppObexServerSessionTest {
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
BluetoothMethodProxy mMethodProxy;
@@ -74,7 +78,6 @@ public class BluetoothOppObexServerSessionTest {
@Before
public void setUp() throws IOException {
- MockitoAnnotations.initMocks(this);
mTargetContext = spy(
new ContextWrapper(
InstrumentationRegistry.getInstrumentation().getTargetContext()));
diff --git a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppPreferenceTest.java b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppPreferenceTest.java
index 8869f282c1..fa690958bc 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppPreferenceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppPreferenceTest.java
@@ -39,7 +39,6 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.MockitoAnnotations;
@RunWith(AndroidJUnit4.class)
public class BluetoothOppPreferenceTest {
@@ -49,7 +48,6 @@ public class BluetoothOppPreferenceTest {
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
mContext = spy(new ContextWrapper(
InstrumentationRegistry.getInstrumentation().getTargetContext()));
diff --git a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppReceiverTest.java b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppReceiverTest.java
index faadf25f6e..3887ade6f5 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppReceiverTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppReceiverTest.java
@@ -62,7 +62,8 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.ArrayList;
import java.util.List;
@@ -74,13 +75,14 @@ public class BluetoothOppReceiverTest {
Context mContext;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
BluetoothMethodProxy mBluetoothMethodProxy;
BluetoothOppReceiver mReceiver;
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mContext = spy(new ContextWrapper(
InstrumentationRegistry.getInstrumentation().getTargetContext()));
diff --git a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppSendFileInfoTest.java b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppSendFileInfoTest.java
index de7de37b5d..7d39d32d37 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppSendFileInfoTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppSendFileInfoTest.java
@@ -39,10 +39,12 @@ import com.android.bluetooth.BluetoothMethodProxy;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.io.FileInputStream;
import java.io.IOException;
@@ -52,12 +54,13 @@ public class BluetoothOppSendFileInfoTest {
Context mContext;
MatrixCursor mCursor;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
BluetoothMethodProxy mCallProxy;
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
mContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
BluetoothMethodProxy.setInstanceForTesting(mCallProxy);
}
diff --git a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppServiceCleanupTest.java b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppServiceCleanupTest.java
index 04ab4ee821..f2f566e6cd 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppServiceCleanupTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppServiceCleanupTest.java
@@ -40,7 +40,8 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@SmallTest
@RunWith(AndroidJUnit4.class)
@@ -51,11 +52,12 @@ public class BluetoothOppServiceCleanupTest {
private Context mTargetContext;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mTargetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
TestUtils.setAdapterService(mAdapterService);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppServiceTest.java
index 05b0460834..95acf7749e 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppServiceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppServiceTest.java
@@ -45,11 +45,13 @@ import com.android.bluetooth.btservice.AdapterService;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@MediumTest
@RunWith(AndroidJUnit4.class)
@@ -59,6 +61,7 @@ public class BluetoothOppServiceTest {
private boolean mIsAdapterServiceSet;
private boolean mIsBluetoothOppServiceStarted;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
@Mock BluetoothMethodProxy mBluetoothMethodProxy;
@@ -67,7 +70,6 @@ public class BluetoothOppServiceTest {
@Before
public void setUp() throws Exception {
Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
- MockitoAnnotations.initMocks(this);
BluetoothMethodProxy.setInstanceForTesting(mBluetoothMethodProxy);
// BluetoothOppService can create a UpdateThread, which will call
diff --git a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppTransferActivityTest.java b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppTransferActivityTest.java
index 40580e651f..2fef847508 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppTransferActivityTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppTransferActivityTest.java
@@ -50,8 +50,9 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.ArrayList;
import java.util.List;
@@ -59,6 +60,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
@RunWith(AndroidJUnit4.class)
public class BluetoothOppTransferActivityTest {
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
Cursor mCursor;
@Spy
@@ -76,7 +79,6 @@ public class BluetoothOppTransferActivityTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mBluetoothMethodProxy = Mockito.spy(BluetoothMethodProxy.getInstance());
BluetoothMethodProxy.setInstanceForTesting(mBluetoothMethodProxy);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppTransferHistoryTest.java b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppTransferHistoryTest.java
index 7739c3109d..9cc3c0397b 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppTransferHistoryTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppTransferHistoryTest.java
@@ -57,8 +57,9 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.ArrayList;
import java.util.List;
@@ -68,6 +69,8 @@ import java.util.List;
*/
@RunWith(AndroidJUnit4.class)
public class BluetoothOppTransferHistoryTest {
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
Cursor mCursor;
@Spy
@@ -85,7 +88,6 @@ public class BluetoothOppTransferHistoryTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mBluetoothMethodProxy = Mockito.spy(BluetoothMethodProxy.getInstance());
BluetoothMethodProxy.setInstanceForTesting(mBluetoothMethodProxy);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppTransferTest.java b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppTransferTest.java
index f1e2a777fb..b9905a000e 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppTransferTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppTransferTest.java
@@ -53,10 +53,12 @@ import com.android.obex.ObexTransport;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.Objects;
@@ -77,6 +79,8 @@ public class BluetoothOppTransferTest {
private final int mTimestamp = 123456789;
private final boolean mMediaScanned = false;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
BluetoothOppObexSession mSession;
@Mock
@@ -89,7 +93,6 @@ public class BluetoothOppTransferTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
BluetoothMethodProxy.setInstanceForTesting(mCallProxy);
doReturn(0).when(mCallProxy).contentResolverDelete(any(), nullable(Uri.class),
nullable(String.class), nullable(String[].class));
diff --git a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppUtilityTest.java b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppUtilityTest.java
index c3897b1168..9f447e4744 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppUtilityTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppUtilityTest.java
@@ -24,6 +24,7 @@ import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
@@ -49,10 +50,12 @@ import com.android.bluetooth.opp.BluetoothOppTestUtils.CursorMockData;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.io.FileNotFoundException;
import java.util.ArrayList;
@@ -67,6 +70,8 @@ public class BluetoothOppUtilityTest {
private static final Uri INCORRECT_FORMAT_URI = Uri.parse("www.google.com");
Context mContext;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
Cursor mCursor;
@@ -76,7 +81,6 @@ public class BluetoothOppUtilityTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
BluetoothMethodProxy.setInstanceForTesting(mCallProxy);
TestUtils.setUpUiTest();
@@ -160,6 +164,9 @@ public class BluetoothOppUtilityTest {
doReturn(0).when(mCallProxy).contentResolverDelete(any(), any(), nullable(String.class),
nullable(String[].class));
+ // Do nothing since we don't need the actual activity to be launched.
+ doNothing().when(spiedContext).startActivity(any());
+
BluetoothOppUtility.openReceivedFile(spiedContext, "randomFileName.txt",
"text/plain", 0L, contentResolverUri);
@@ -229,6 +236,9 @@ public class BluetoothOppUtilityTest {
doReturn(mockManager).when(spiedContext).getPackageManager();
doReturn(List.of()).when(mockManager).queryIntentActivities(any(), anyInt());
+ // Do nothing since we don't need the actual activity to be launched.
+ doNothing().when(spiedContext).startActivity(any());
+
BluetoothOppUtility.openReceivedFile(spiedContext, "randomFileName.txt",
"text/plain", 0L, contentResolverUri);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/opp/IncomingFileConfirmActivityTest.java b/android/app/tests/unit/src/com/android/bluetooth/opp/IncomingFileConfirmActivityTest.java
index 77872410ce..68756b67e6 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/opp/IncomingFileConfirmActivityTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/opp/IncomingFileConfirmActivityTest.java
@@ -61,8 +61,9 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.ArrayList;
import java.util.List;
@@ -71,6 +72,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
// Long class name cause problem with Junit4. It will raise java.lang.NoClassDefFoundError
@RunWith(AndroidJUnit4.class)
public class IncomingFileConfirmActivityTest {
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
Cursor mCursor;
@Spy
@@ -90,7 +93,6 @@ public class IncomingFileConfirmActivityTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mBluetoothMethodProxy = Mockito.spy(BluetoothMethodProxy.getInstance());
BluetoothMethodProxy.setInstanceForTesting(mBluetoothMethodProxy);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/pan/BluetoothTetheringNetworkFactoryTest.java b/android/app/tests/unit/src/com/android/bluetooth/pan/BluetoothTetheringNetworkFactoryTest.java
index 8357e12fb7..4adb1889e9 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/pan/BluetoothTetheringNetworkFactoryTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/pan/BluetoothTetheringNetworkFactoryTest.java
@@ -32,11 +32,12 @@ import androidx.test.core.app.ApplicationProvider;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
-import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.ArrayList;
import java.util.List;
@@ -48,16 +49,13 @@ import java.util.List;
@RunWith(AndroidJUnit4.class)
public class BluetoothTetheringNetworkFactoryTest {
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private PanService mPanService;
private Context mContext = ApplicationProvider.getApplicationContext();
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- }
-
@Test
public void networkStartReverseTetherEmptyIface() {
if (Looper.myLooper() == null) {
diff --git a/android/app/tests/unit/src/com/android/bluetooth/pan/PanServiceBinderTest.java b/android/app/tests/unit/src/com/android/bluetooth/pan/PanServiceBinderTest.java
index 51e1ae7529..fe54c79872 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/pan/PanServiceBinderTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/pan/PanServiceBinderTest.java
@@ -28,16 +28,20 @@ import androidx.test.runner.AndroidJUnit4;
import com.android.bluetooth.x.com.android.modules.utils.SynchronousResultReceiver;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@SmallTest
@RunWith(AndroidJUnit4.class)
public class PanServiceBinderTest {
private static final String REMOTE_DEVICE_ADDRESS = "00:00:00:00:00:00";
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private PanService mService;
@@ -47,7 +51,6 @@ public class PanServiceBinderTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mRemoteDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(REMOTE_DEVICE_ADDRESS);
mBinder = new PanService.BluetoothPanBinder(mService);
}
diff --git a/android/app/tests/unit/src/com/android/bluetooth/pan/PanServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/pan/PanServiceTest.java
index e08f5207d9..f1daf38341 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/pan/PanServiceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/pan/PanServiceTest.java
@@ -42,10 +42,12 @@ import com.android.bluetooth.pan.PanService.BluetoothPanDevice;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@MediumTest
@RunWith(AndroidJUnit4.class)
@@ -57,6 +59,7 @@ public class PanServiceTest {
private BluetoothAdapter mAdapter = null;
private BluetoothDevice mRemoteDevice;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
@Mock private AdapterService mAdapterService;
@Mock private DatabaseManager mDatabaseManager;
@@ -66,7 +69,6 @@ public class PanServiceTest {
@Before
public void setUp() throws Exception {
Context targetContext = InstrumentationRegistry.getTargetContext();
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
doReturn(mDatabaseManager).when(mAdapterService).getDatabase();
PanNativeInterface.setInstance(mNativeInterface);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapAuthenticatorTest.java b/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapAuthenticatorTest.java
index 431c8cd599..9c00501b63 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapAuthenticatorTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapAuthenticatorTest.java
@@ -27,10 +27,12 @@ import androidx.test.runner.AndroidJUnit4;
import com.android.obex.PasswordAuthentication;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@MediumTest
@RunWith(AndroidJUnit4.class)
@@ -38,12 +40,13 @@ public class BluetoothPbapAuthenticatorTest {
private BluetoothPbapAuthenticator mAuthenticator;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
PbapStateMachine mMockPbapStateMachine;
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mAuthenticator = new BluetoothPbapAuthenticator(mMockPbapStateMachine);
}
diff --git a/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapCallLogComposerTest.java b/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapCallLogComposerTest.java
index 33089f4cc0..1ea6786e8b 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapCallLogComposerTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapCallLogComposerTest.java
@@ -42,11 +42,13 @@ import com.android.bluetooth.BluetoothMethodProxy;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@SmallTest
@RunWith(AndroidJUnit4.class)
@@ -65,12 +67,13 @@ public class BluetoothPbapCallLogComposerTest {
@Spy
BluetoothMethodProxy mPbapCallProxy = BluetoothMethodProxy.getInstance();
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
Cursor mMockCursor;
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
BluetoothMethodProxy.setInstanceForTesting(mPbapCallProxy);
doReturn(mMockCursor).when(mPbapCallProxy)
diff --git a/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapConfigTest.java b/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapConfigTest.java
index 097f46d8d5..30445b1399 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapConfigTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapConfigTest.java
@@ -29,15 +29,19 @@ import androidx.test.runner.AndroidJUnit4;
import com.android.bluetooth.R;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@SmallTest
@RunWith(AndroidJUnit4.class)
public class BluetoothPbapConfigTest {
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
Context mContext;
@@ -46,7 +50,6 @@ public class BluetoothPbapConfigTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
when(mContext.getResources()).thenReturn(mResources);
}
diff --git a/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapObexServerTest.java b/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapObexServerTest.java
index 62834b49d8..6d22c2e78c 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapObexServerTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapObexServerTest.java
@@ -67,11 +67,13 @@ import com.android.obex.ResponseCodes;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.io.IOException;
import java.io.OutputStream;
@@ -82,6 +84,8 @@ public class BluetoothPbapObexServerTest {
private static final String TAG = BluetoothPbapObexServerTest.class.getSimpleName();
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock Handler mMockHandler;
@Mock PbapStateMachine mMockStateMachine;
@@ -107,7 +111,6 @@ public class BluetoothPbapObexServerTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
BluetoothMethodProxy.setInstanceForTesting(mPbapMethodProxy);
mServer = new BluetoothPbapObexServer(
mMockHandler, InstrumentationRegistry.getTargetContext(), mMockStateMachine);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapServiceBinderTest.java b/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapServiceBinderTest.java
index 4bd3a10e31..116fe9e743 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapServiceBinderTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapServiceBinderTest.java
@@ -26,16 +26,20 @@ import androidx.test.filters.MediumTest;
import androidx.test.runner.AndroidJUnit4;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@MediumTest
@RunWith(AndroidJUnit4.class)
public class BluetoothPbapServiceBinderTest {
private static final String REMOTE_DEVICE_ADDRESS = "00:00:00:00:00:00";
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private BluetoothPbapService mService;
@@ -45,7 +49,6 @@ public class BluetoothPbapServiceBinderTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mRemoteDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(REMOTE_DEVICE_ADDRESS);
mBinder = new BluetoothPbapService.PbapBinder(mService);
}
diff --git a/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapServiceTest.java
index 69dac461ad..b509e7e7c4 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapServiceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapServiceTest.java
@@ -44,12 +44,14 @@ import com.android.bluetooth.btservice.storage.DatabaseManager;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@MediumTest
@RunWith(AndroidJUnit4.class)
@@ -63,6 +65,7 @@ public class BluetoothPbapServiceTest {
private boolean mIsBluetoothPabpServiceStarted;
private TestLooper mTestLooper;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
@Mock private AdapterService mAdapterService;
@Mock private DatabaseManager mDatabaseManager;
@@ -71,7 +74,6 @@ public class BluetoothPbapServiceTest {
@Before
public void setUp() throws Exception {
Context targetContext = InstrumentationRegistry.getTargetContext();
- MockitoAnnotations.initMocks(this);
mTestLooper = new TestLooper();
BluetoothMethodProxy.setInstanceForTesting(mMethodProxy);
doReturn(mTestLooper.getLooper()).when(mMethodProxy).handlerThreadGetLooper(any());
diff --git a/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapSimVcardManagerTest.java b/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapSimVcardManagerTest.java
index 46302cb441..2e46515c56 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapSimVcardManagerTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapSimVcardManagerTest.java
@@ -41,10 +41,12 @@ import com.android.obex.ResponseCodes;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import org.mockito.stubbing.Answer;
import java.io.OutputStream;
@@ -60,6 +62,8 @@ public class BluetoothPbapSimVcardManagerTest {
private static final String TAG = BluetoothPbapSimVcardManagerTest.class.getSimpleName();
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Spy
BluetoothMethodProxy mPbapMethodProxy = BluetoothMethodProxy.getInstance();
@@ -70,7 +74,6 @@ public class BluetoothPbapSimVcardManagerTest {
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
BluetoothMethodProxy.setInstanceForTesting(mPbapMethodProxy);
mContext = InstrumentationRegistry.getTargetContext();
mManager = new BluetoothPbapSimVcardManager(mContext);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapUtilsTest.java b/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapUtilsTest.java
index 875042f8b0..a98d782fdd 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapUtilsTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapUtilsTest.java
@@ -48,11 +48,13 @@ import com.android.vcard.VCardConfig;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.ArrayList;
import java.util.Calendar;
@@ -62,6 +64,8 @@ import java.util.List;
@RunWith(AndroidJUnit4.class)
public class BluetoothPbapUtilsTest {
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
Context mContext;
@@ -73,7 +77,6 @@ public class BluetoothPbapUtilsTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
BluetoothMethodProxy.setInstanceForTesting(mProxy);
when(mContext.getResources()).thenReturn(mResources);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapVcardManagerNestedClassesTest.java b/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapVcardManagerNestedClassesTest.java
index a6c16aaa42..9fab5c1d8f 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapVcardManagerNestedClassesTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapVcardManagerNestedClassesTest.java
@@ -34,10 +34,12 @@ import com.android.bluetooth.pbap.BluetoothPbapVcardManager.PropertySelector;
import com.android.bluetooth.pbap.BluetoothPbapVcardManager.VCardFilter;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.concurrent.atomic.AtomicInteger;
@@ -45,6 +47,8 @@ import java.util.concurrent.atomic.AtomicInteger;
@RunWith(AndroidJUnit4.class)
public class BluetoothPbapVcardManagerNestedClassesTest {
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
Context mContext;
@@ -53,7 +57,6 @@ public class BluetoothPbapVcardManagerNestedClassesTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
when(mContext.getResources()).thenReturn(mResources);
}
diff --git a/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapVcardManagerTest.java b/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapVcardManagerTest.java
index a6ed5593ca..3c623679f5 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapVcardManagerTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapVcardManagerTest.java
@@ -39,10 +39,12 @@ import com.android.bluetooth.R;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import org.mockito.stubbing.Answer;
import java.util.Arrays;
@@ -55,6 +57,8 @@ public class BluetoothPbapVcardManagerTest {
private static final String TAG = BluetoothPbapVcardManagerTest.class.getSimpleName();
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Spy
BluetoothMethodProxy mPbapMethodProxy = BluetoothMethodProxy.getInstance();
@@ -63,7 +67,6 @@ public class BluetoothPbapVcardManagerTest {
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
BluetoothMethodProxy.setInstanceForTesting(mPbapMethodProxy);
mContext = InstrumentationRegistry.getTargetContext();
mManager = new BluetoothPbapVcardManager(mContext);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/pbap/HandlerForStringBufferTest.java b/android/app/tests/unit/src/com/android/bluetooth/pbap/HandlerForStringBufferTest.java
index 3e8dd1fff4..6c1e252aab 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/pbap/HandlerForStringBufferTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/pbap/HandlerForStringBufferTest.java
@@ -30,10 +30,12 @@ import androidx.test.runner.AndroidJUnit4;
import com.android.obex.Operation;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.io.IOException;
import java.io.OutputStream;
@@ -42,6 +44,8 @@ import java.io.OutputStream;
@RunWith(AndroidJUnit4.class)
public class HandlerForStringBufferTest {
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private Operation mOperation;
@@ -50,7 +54,6 @@ public class HandlerForStringBufferTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
when(mOperation.openOutputStream()).thenReturn(mOutputStream);
}
diff --git a/android/app/tests/unit/src/com/android/bluetooth/pbap/PbapStateMachineTest.java b/android/app/tests/unit/src/com/android/bluetooth/pbap/PbapStateMachineTest.java
index b372f18ad5..978f9dfb0e 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/pbap/PbapStateMachineTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/pbap/PbapStateMachineTest.java
@@ -38,10 +38,12 @@ import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@MediumTest
@RunWith(AndroidJUnit4.class)
@@ -58,12 +60,13 @@ public class PbapStateMachineTest {
private BluetoothPbapService mBluetoothPbapService;
private boolean mIsAdapterServiceSet;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Before
public void setUp() throws Exception {
mTargetContext = InstrumentationRegistry.getTargetContext();
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
mIsAdapterServiceSet = true;
// This line must be called to make sure relevant objects are initialized properly
diff --git a/android/app/tests/unit/src/com/android/bluetooth/pbapclient/BluetoothPbapRequestTest.java b/android/app/tests/unit/src/com/android/bluetooth/pbapclient/BluetoothPbapRequestTest.java
index e258921547..b947c62dc2 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/pbapclient/BluetoothPbapRequestTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/pbapclient/BluetoothPbapRequestTest.java
@@ -30,10 +30,12 @@ import com.android.obex.ObexTransport;
import com.android.obex.ResponseCodes;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.io.InputStream;
@@ -43,12 +45,13 @@ public class BluetoothPbapRequestTest {
private BluetoothPbapRequest mRequest = new BluetoothPbapRequest() {};
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private ObexTransport mObexTransport;
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mRequest = new BluetoothPbapRequest() {};
}
diff --git a/android/app/tests/unit/src/com/android/bluetooth/pbapclient/CallLogPullRequestTest.java b/android/app/tests/unit/src/com/android/bluetooth/pbapclient/CallLogPullRequestTest.java
index ceb85e5727..6a5440ad74 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/pbapclient/CallLogPullRequestTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/pbapclient/CallLogPullRequestTest.java
@@ -39,10 +39,12 @@ import com.android.vcard.VCardProperty;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.ArrayList;
import java.util.HashMap;
@@ -56,12 +58,13 @@ public class CallLogPullRequestTest {
private final HashMap<String, Integer> mCallCounter = new HashMap<>();
private Context mTargetContext;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Spy
private BluetoothMethodProxy mMapMethodProxy = BluetoothMethodProxy.getInstance();
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
BluetoothMethodProxy.setInstanceForTesting(mMapMethodProxy);
mTargetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
}
diff --git a/android/app/tests/unit/src/com/android/bluetooth/pbapclient/PbapClientConnectionHandlerTest.java b/android/app/tests/unit/src/com/android/bluetooth/pbapclient/PbapClientConnectionHandlerTest.java
index 50f96db865..84806cc383 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/pbapclient/PbapClientConnectionHandlerTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/pbapclient/PbapClientConnectionHandlerTest.java
@@ -42,10 +42,12 @@ import com.android.bluetooth.btservice.storage.DatabaseManager;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@SmallTest
@RunWith(AndroidJUnit4.class)
@@ -59,6 +61,8 @@ public class PbapClientConnectionHandlerTest {
private Context mTargetContext;
private BluetoothDevice mRemoteDevice;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private AdapterService mAdapterService;
@@ -77,7 +81,6 @@ public class PbapClientConnectionHandlerTest {
public void setUp() throws Exception {
mTargetContext = spy(new ContextWrapper(
InstrumentationRegistry.getInstrumentation().getTargetContext()));
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
doReturn(mDatabaseManager).when(mAdapterService).getDatabase();
mService = new PbapClientService(mTargetContext);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/pbapclient/PbapClientServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/pbapclient/PbapClientServiceTest.java
index 06e63c9519..959439d1dd 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/pbapclient/PbapClientServiceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/pbapclient/PbapClientServiceTest.java
@@ -48,11 +48,13 @@ import com.android.bluetooth.x.com.android.modules.utils.SynchronousResultReceiv
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@MediumTest
@RunWith(AndroidJUnit4.class)
@@ -66,6 +68,8 @@ public class PbapClientServiceTest {
boolean mIsAdapterServiceSet;
boolean mIsPbapClientServiceStarted;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private DatabaseManager mDatabaseManager;
@@ -73,7 +77,6 @@ public class PbapClientServiceTest {
@Before
public void setUp() throws Exception {
mTargetContext = InstrumentationRegistry.getTargetContext();
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
mIsAdapterServiceSet = true;
doReturn(mDatabaseManager).when(mAdapterService).getDatabase();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/pbapclient/PbapClientStateMachineTest.java b/android/app/tests/unit/src/com/android/bluetooth/pbapclient/PbapClientStateMachineTest.java
index ae3bd808a7..d40aa8d5d1 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/pbapclient/PbapClientStateMachineTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/pbapclient/PbapClientStateMachineTest.java
@@ -38,12 +38,14 @@ import com.android.bluetooth.TestUtils;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@MediumTest
@RunWith(AndroidJUnit4.class)
@@ -52,6 +54,8 @@ public class PbapClientStateMachineTest{
private PbapClientStateMachine mPbapClientStateMachine = null;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private PbapClientService mMockPbapClientService;
@Mock
@@ -69,7 +73,6 @@ public class PbapClientStateMachineTest{
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
// This line must be called to make sure relevant objects are initialized properly
mAdapter = BluetoothAdapter.getDefaultAdapter();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/sap/SapRilReceiverHidlTest.java b/android/app/tests/unit/src/com/android/bluetooth/sap/SapRilReceiverHidlTest.java
index 0fa5520c12..94565511f0 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/sap/SapRilReceiverHidlTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/sap/SapRilReceiverHidlTest.java
@@ -60,12 +60,14 @@ import com.android.bluetooth.x.android.hardware.radio.V1_0.ISap;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentMatcher;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.ArrayList;
import java.util.Arrays;
@@ -82,6 +84,8 @@ public class SapRilReceiverHidlTest {
@Spy
private TestHandlerCallback mCallback = new TestHandlerCallback();
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private Handler mServiceHandler;
@@ -92,7 +96,6 @@ public class SapRilReceiverHidlTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mHandlerThread = new HandlerThread("SapRilReceiverTest");
mHandlerThread.start();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/sap/SapRilReceiverTest.java b/android/app/tests/unit/src/com/android/bluetooth/sap/SapRilReceiverTest.java
index 3d0e350fb9..293b892a7d 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/sap/SapRilReceiverTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/sap/SapRilReceiverTest.java
@@ -63,12 +63,14 @@ import androidx.test.runner.AndroidJUnit4;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentMatcher;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.Arrays;
@@ -84,6 +86,8 @@ public class SapRilReceiverTest {
@Spy
private TestHandlerCallback mCallback = new TestHandlerCallback();
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private Handler mServiceHandler;
@@ -94,7 +98,6 @@ public class SapRilReceiverTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mHandlerThread = new HandlerThread("SapRilReceiverTest");
mHandlerThread.start();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/sap/SapServerTest.java b/android/app/tests/unit/src/com/android/bluetooth/sap/SapServerTest.java
index e88c5f122b..0de1343d3a 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/sap/SapServerTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/sap/SapServerTest.java
@@ -71,13 +71,15 @@ import androidx.test.runner.AndroidJUnit4;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentMatcher;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.io.InputStream;
import java.io.OutputStream;
@@ -98,6 +100,8 @@ public class SapServerTest {
@Spy
private TestHandlerCallback mCallback = new TestHandlerCallback();
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private InputStream mInputStream;
@@ -108,7 +112,6 @@ public class SapServerTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mHandlerThread = new HandlerThread("SapServerTest");
mHandlerThread.start();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/sap/SapServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/sap/SapServiceTest.java
index 27cb3a96dc..6e3071ea4e 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/sap/SapServiceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/sap/SapServiceTest.java
@@ -36,11 +36,12 @@ import com.android.bluetooth.btservice.storage.DatabaseManager;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@MediumTest
@RunWith(AndroidJUnit4.class)
@@ -51,6 +52,8 @@ public class SapServiceTest {
private BluetoothAdapter mAdapter = null;
private Context mTargetContext;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private DatabaseManager mDatabaseManager;
private BluetoothDevice mDevice;
@@ -58,7 +61,6 @@ public class SapServiceTest {
@Before
public void setUp() throws Exception {
mTargetContext = InstrumentationRegistry.getTargetContext();
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
mService = new SapService(mTargetContext);
mService.start();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/sdp/DipTest.java b/android/app/tests/unit/src/com/android/bluetooth/sdp/DipTest.java
index 60dfc9df71..5292940b12 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/sdp/DipTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/sdp/DipTest.java
@@ -41,11 +41,13 @@ import com.android.bluetooth.btservice.AdapterService;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@SmallTest
@RunWith(AndroidJUnit4.class)
@@ -59,14 +61,14 @@ public class DipTest {
private ArgumentCaptor<String> mStringArgument = ArgumentCaptor.forClass(String.class);
private ArgumentCaptor<Bundle> mBundleArgument = ArgumentCaptor.forClass(Bundle.class);
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService = null;
@Mock private SdpManagerNativeInterface mNativeInterface;
@Before
public void setUp() throws Exception {
mTargetContext = InstrumentationRegistry.getTargetContext();
- // Set up mocks and test assets
- MockitoAnnotations.initMocks(this);
SdpManagerNativeInterface.setInstance(mNativeInterface);
TestUtils.setAdapterService(mAdapterService);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/tbs/TbsGattTest.java b/android/app/tests/unit/src/com/android/bluetooth/tbs/TbsGattTest.java
index f56789f1ce..d619b6136f 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/tbs/TbsGattTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/tbs/TbsGattTest.java
@@ -46,7 +46,8 @@ import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
@@ -72,6 +73,8 @@ public class TbsGattTest {
private TbsGatt mTbsGatt;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private AdapterService mAdapterService;
@Mock
@@ -95,7 +98,6 @@ public class TbsGattTest {
getInstrumentation().getUiAutomation().adoptShellPermissionIdentity();
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
mAdapter = BluetoothAdapter.getDefaultAdapter();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/tbs/TbsGenericTest.java b/android/app/tests/unit/src/com/android/bluetooth/tbs/TbsGenericTest.java
index 856845fda8..7d6b512f48 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/tbs/TbsGenericTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/tbs/TbsGenericTest.java
@@ -35,12 +35,14 @@ import com.android.bluetooth.le_audio.LeAudioService;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.ArrayList;
import java.util.Arrays;
@@ -56,6 +58,8 @@ public class TbsGenericTest {
private TbsGeneric mTbsGeneric;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
private @Mock TbsGatt mTbsGatt;
private @Mock IBluetoothLeCallControlCallback mIBluetoothLeCallControlCallback;
private @Captor ArgumentCaptor<Integer> mGtbsCcidCaptor;
@@ -70,7 +74,6 @@ public class TbsGenericTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mAdapter = BluetoothAdapter.getDefaultAdapter();
mContext = getInstrumentation().getTargetContext();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/telephony/BluetoothInCallServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/telephony/BluetoothInCallServiceTest.java
index 5b295f4b55..060fdee686 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/telephony/BluetoothInCallServiceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/telephony/BluetoothInCallServiceTest.java
@@ -60,7 +60,8 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.ArrayList;
import java.util.Arrays;
@@ -102,6 +103,8 @@ public class BluetoothInCallServiceTest {
public final ServiceTestRule mServiceRule
= ServiceTestRule.withTimeout(1, TimeUnit.SECONDS);
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private BluetoothHeadsetProxy mMockBluetoothHeadset;
@Mock
@@ -136,7 +139,6 @@ public class BluetoothInCallServiceTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
InstrumentationRegistry.getInstrumentation().getUiAutomation().adoptShellPermissionIdentity();
// Create the service Intent.
diff --git a/android/app/tests/unit/src/com/android/bluetooth/telephony/CallInfoTest.java b/android/app/tests/unit/src/com/android/bluetooth/telephony/CallInfoTest.java
index af77f4fac5..102389c364 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/telephony/CallInfoTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/telephony/CallInfoTest.java
@@ -36,10 +36,12 @@ import androidx.test.runner.AndroidJUnit4;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.ArrayList;
import java.util.LinkedHashSet;
@@ -53,6 +55,8 @@ public class CallInfoTest {
private static final String TEST_ACCOUNT_ADDRESS = "https://foo.com/";
private static final int TEST_ACCOUNT_INDEX = 0;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private TelecomManager mMockTelecomManager;
@@ -61,7 +65,6 @@ public class CallInfoTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
mBluetoothInCallService = new BluetoothInCallService();
mMockCallInfo = spy(mBluetoothInCallService.new CallInfo());
diff --git a/android/app/tests/unit/src/com/android/bluetooth/vc/VolumeControlNativeInterfaceTest.java b/android/app/tests/unit/src/com/android/bluetooth/vc/VolumeControlNativeInterfaceTest.java
index fbf4697121..7d19671151 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/vc/VolumeControlNativeInterfaceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/vc/VolumeControlNativeInterfaceTest.java
@@ -25,14 +25,18 @@ import androidx.test.runner.AndroidJUnit4;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@RunWith(AndroidJUnit4.class)
public class VolumeControlNativeInterfaceTest {
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock
private VolumeControlService mService;
@@ -40,7 +44,6 @@ public class VolumeControlNativeInterfaceTest {
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
when(mService.isAvailable()).thenReturn(true);
VolumeControlService.setVolumeControlService(mService);
mNativeInterface = VolumeControlNativeInterface.getInstance();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/vc/VolumeControlServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/vc/VolumeControlServiceTest.java
index 79a327cd7a..5c00afb406 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/vc/VolumeControlServiceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/vc/VolumeControlServiceTest.java
@@ -58,7 +58,8 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.time.Duration;
import java.util.Arrays;
@@ -88,6 +89,8 @@ public class VolumeControlServiceTest {
private BroadcastReceiver mVolumeControlIntentReceiver;
private FakeFeatureFlagsImpl mFakeFlagsImpl;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private LeAudioService mLeAudioService;
@Mock private DatabaseManager mDatabaseManager;
@@ -101,8 +104,6 @@ public class VolumeControlServiceTest {
@Before
public void setUp() throws Exception {
mTargetContext = InstrumentationRegistry.getTargetContext();
- // Set up mocks and test assets
- MockitoAnnotations.initMocks(this);
if (Looper.myLooper() == null) {
Looper.prepare();
diff --git a/android/app/tests/unit/src/com/android/bluetooth/vc/VolumeControlStateMachineTest.java b/android/app/tests/unit/src/com/android/bluetooth/vc/VolumeControlStateMachineTest.java
index 2082abd598..80d25bdb4f 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/vc/VolumeControlStateMachineTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/vc/VolumeControlStateMachineTest.java
@@ -44,12 +44,14 @@ import org.hamcrest.core.IsInstanceOf;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
@MediumTest
@RunWith(AndroidJUnit4.class)
@@ -61,6 +63,8 @@ public class VolumeControlStateMachineTest {
private BluetoothDevice mTestDevice;
private static final int TIMEOUT_MS = 1000;
+ @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Mock private AdapterService mAdapterService;
@Mock private VolumeControlService mVolumeControlService;
@Mock private VolumeControlNativeInterface mVolumeControlNativeInterface;
@@ -69,8 +73,6 @@ public class VolumeControlStateMachineTest {
public void setUp() throws Exception {
mTargetContext = InstrumentationRegistry.getTargetContext();
InstrumentationRegistry.getInstrumentation().getUiAutomation().adoptShellPermissionIdentity();
- // Set up mocks and test assets
- MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
mAdapter = BluetoothAdapter.getDefaultAdapter();
diff --git a/flags/gap.aconfig b/flags/gap.aconfig
index 05d6ea38f5..5098a7461f 100644
--- a/flags/gap.aconfig
+++ b/flags/gap.aconfig
@@ -112,3 +112,10 @@ flag {
description: "Remove ACL when there is not resource to handle more gatt connections."
bug: "325929235"
}
+
+flag {
+ name: "ble_scan_adv_metrics_redesign"
+ namespace: "bluetooth"
+ description: "Reimplement BLE scan and advertisement metrics logging."
+ bug: "328303508"
+}
diff --git a/flags/map.aconfig b/flags/map.aconfig
new file mode 100644
index 0000000000..341b2b80e1
--- /dev/null
+++ b/flags/map.aconfig
@@ -0,0 +1,8 @@
+package: "com.android.bluetooth.flags"
+
+flag {
+ name: "map_limit_notification"
+ namespace: "bluetooth"
+ description: "Skip notyfing old messages in MAP"
+ bug: "325863406"
+}
diff --git a/floss/pandora/server/hid.py b/floss/pandora/server/hid.py
index d6067f71e2..b3246b8547 100644
--- a/floss/pandora/server/hid.py
+++ b/floss/pandora/server/hid.py
@@ -54,8 +54,9 @@ class HIDService(hid_grpc_aio.HIDServicer):
future = self.task['set_hid_report']
future.get_loop().call_soon_threadsafe(future.set_result, None)
- if request.address is None:
- raise ValueError('Request address field must be set.')
+ if not request.address:
+ await context.abort(grpc.StatusCode.INVALID_ARGUMENT, 'Request address field must be set.')
+
address = utils.address_from(request.address)
try:
@@ -64,9 +65,10 @@ class HIDService(hid_grpc_aio.HIDServicer):
name = utils.create_observer_name(observer)
self.bluetooth.qa_client.register_callback_observer(name, observer)
if request.report_type not in iter(floss_enums.BthhReportType):
- raise ValueError('Invalid report type.')
+ await context.abort(grpc.StatusCode.INVALID_ARGUMENT, 'Invalid report type.')
+
if not self.bluetooth.set_hid_report(address, request.report_type, request.report):
- raise RuntimeError('Failed to call set_hid_report.')
+ await context.abort(grpc.StatusCode.UNKNOWN, 'Failed to call set_hid_report.')
await asyncio.wait_for(set_hid_report, timeout=5)
diff --git a/floss/pandora/server/host.py b/floss/pandora/server/host.py
index 09245fc1e7..0ee3d86908 100644
--- a/floss/pandora/server/host.py
+++ b/floss/pandora/server/host.py
@@ -21,8 +21,8 @@ import uuid as uuid_module
from floss.pandora.floss import adapter_client
from floss.pandora.floss import advertising_client
from floss.pandora.floss import floss_enums
-from floss.pandora.floss import scanner_client
from floss.pandora.floss import gatt_client
+from floss.pandora.floss import scanner_client
from floss.pandora.floss import utils
from floss.pandora.server import bluetooth as bluetooth_module
from google.protobuf import empty_pb2
@@ -165,7 +165,8 @@ class HostService(host_grpc_aio.HostServicer):
success, reason = await connect_device
if not success:
- raise RuntimeError(f'Failed to connect to the {address}. Reason: {reason}')
+ await context.abort(grpc.StatusCode.UNKNOWN,
+ f'Failed to connect to the {address}. Reason: {reason}.')
else:
if not self.security.manually_confirm:
create_bond = asyncio.get_running_loop().create_future()
@@ -181,13 +182,14 @@ class HostService(host_grpc_aio.HostServicer):
self.bluetooth.adapter_client.register_callback_observer(name, observer)
if not self.bluetooth.create_bond(address, floss_enums.BtTransport.BREDR):
- raise RuntimeError('Failed to call create_bond.')
+ await context.abort(grpc.StatusCode.UNKNOWN, 'Failed to call create_bond.')
if not self.security.manually_confirm:
success, reason = await create_bond
if not success:
- raise RuntimeError(f'Failed to connect to the {address}. Reason: {reason}')
+ await context.abort(grpc.StatusCode.UNKNOWN,
+ f'Failed to connect to the {address}. Reason: {reason}.')
if self.bluetooth.is_bonded(address) and self.bluetooth.is_connected(address):
self.bluetooth.connect_device(address)
@@ -215,8 +217,9 @@ class HostService(host_grpc_aio.HostServicer):
future = self.task['wait_connection']
future.get_loop().call_soon_threadsafe(future.set_result, address)
- if request.address is None:
- raise ValueError('Request address field must be set.')
+ if not request.address:
+ await context.abort(grpc.StatusCode.INVALID_ARGUMENT, 'Request address field must be set.')
+
address = utils.address_from(request.address)
if not self.bluetooth.is_connected(address) or address not in self.waited_connections:
@@ -257,11 +260,11 @@ class HostService(host_grpc_aio.HostServicer):
future.get_loop().call_soon_threadsafe(future.set_result, (connected, None))
if not request.address:
- raise ValueError('Connect LE: Request address field must be set')
+ await context.abort(grpc.StatusCode.INVALID_ARGUMENT, 'Request address field must be set.')
own_address_type = request.own_address_type
if own_address_type not in (host_pb2.RANDOM, host_pb2.RESOLVABLE_OR_RANDOM):
- raise RuntimeError(f'ConnectLE: Unsupported OwnAddressType: {own_address_type}.')
+ await context.abort(grpc.StatusCode.UNIMPLEMENTED, f'Unsupported OwnAddressType: {own_address_type}.')
address = utils.address_from(request.address)
self.initiated_le_connection.add(address)
@@ -273,7 +276,8 @@ class HostService(host_grpc_aio.HostServicer):
self.bluetooth.gatt_connect(address, True, floss_enums.BtTransport.LE)
connected, reason = await connect_le_device
if not connected:
- raise RuntimeError(f'Failed to connect to the address: {address}. Reason: {reason}')
+ await context.abort(grpc.StatusCode.UNKNOWN,
+ f'Failed to connect to the address: {address}. Reason: {reason}.')
finally:
self.bluetooth.gatt_client.unregister_callback_observer(name, observer)
@@ -305,8 +309,9 @@ class HostService(host_grpc_aio.HostServicer):
future = self.task['wait_disconnection']
future.get_loop().call_soon_threadsafe(future.set_result, address)
- if request.address is None:
- raise ValueError('Request address field must be set')
+ if not request.address:
+ await context.abort(grpc.StatusCode.INVALID_ARGUMENT, 'Request address field must be set.')
+
address = utils.address_from(request.address)
if self.bluetooth.is_connected(address):
@@ -401,22 +406,21 @@ class HostService(host_grpc_aio.HostServicer):
self.bluetooth.adapter_client.register_callback_observer(name, observer)
observers.append((name, observer))
- while True:
- if not self.bluetooth.advertising_client.active_advs:
- reg_id = self.bluetooth.start_advertising_set(parameters, advertise_data, None, None, None, 0, 0)
-
- advertising_request = {
- 'start_advertising': asyncio.get_running_loop().create_future(),
- 'reg_id': reg_id
- }
- observer = AdvertisingObserver(advertising_request)
- name = utils.create_observer_name(observer)
- self.bluetooth.advertising_client.register_callback_observer(name, observer)
- observers.append((name, observer))
+ reg_id = self.bluetooth.start_advertising_set(parameters, advertise_data, None, None, None, 0, 0)
+
+ advertising_request = {'start_advertising': asyncio.get_running_loop().create_future(), 'reg_id': reg_id}
+ observer = AdvertisingObserver(advertising_request)
+ name = utils.create_observer_name(observer)
+ self.bluetooth.advertising_client.register_callback_observer(name, observer)
+ observers.append((name, observer))
+
+ advertiser_id = await asyncio.wait_for(advertising_request['start_advertising'], timeout=5)
+ if advertiser_id is None:
+ await context.abort(grpc.StatusCode.UNKNOWN, 'Failed to start advertising.')
- advertiser_id = await asyncio.wait_for(advertising_request['start_advertising'], timeout=5)
- started_ids.append(advertiser_id)
+ started_ids.append(advertiser_id)
+ while True:
if not request.connectable:
await asyncio.sleep(1)
continue
@@ -428,7 +432,6 @@ class HostService(host_grpc_aio.HostServicer):
yield host_pb2.AdvertiseResponse(
connection=utils.connection_to(utils.Connection(address, floss_enums.BtTransport.LE)))
- # Wait a small delay before restarting the advertisement.
await asyncio.sleep(1)
finally:
for name, observer in observers:
diff --git a/floss/pandora/server/security.py b/floss/pandora/server/security.py
index d96dc1d3d8..c4dd5cb44f 100644
--- a/floss/pandora/server/security.py
+++ b/floss/pandora/server/security.py
@@ -101,7 +101,8 @@ class SecurityService(security_grpc_aio.SecurityServicer):
if level == security_pb2.LE_LEVEL1:
return True
if level == security_pb2.LE_LEVEL4:
- raise RuntimeError(f'wait_le_security_level: Low-energy level 4 not supported')
+ logging.error('wait_le_security_level: Low-energy level 4 not supported.')
+ return False
if self.bluetooth.is_bonded(address):
is_bonded = True
@@ -122,7 +123,9 @@ class SecurityService(security_grpc_aio.SecurityServicer):
return is_encrypted
if level == security_pb2.LE_LEVEL3:
return is_encrypted and is_bonded
- raise ValueError(f'wait_le_security_level: Invalid security level {level}')
+
+ logging.error('wait_le_security_level: Invalid security level %s.', level)
+ return False
async def wait_classic_security_level(self, level, address):
@@ -151,7 +154,8 @@ class SecurityService(security_grpc_aio.SecurityServicer):
if level == security_pb2.LEVEL0:
return True
if level == security_pb2.LEVEL3:
- raise RuntimeError('wait_classic_security_level: Classic level 3 not supported')
+ logging.error('wait_classic_security_level: Classic level 3 not supported')
+ return False
if self.bluetooth.is_bonded(address):
is_bonded = True
@@ -311,28 +315,29 @@ class SecurityService(security_grpc_aio.SecurityServicer):
if transport == floss_enums.BtTransport.LE:
if not request.HasField('le'):
- raise RuntimeError('Secure: Request le field must be set.')
+ await context.abort(grpc.StatusCode.INVALID_ARGUMENT, 'Request le field must be set.')
if request.le == security_pb2.LE_LEVEL1:
security_level_reached = True
elif request.le == security_pb2.LE_LEVEL4:
- raise RuntimeError('Secure: Low-energy security level 4 not supported')
+ await context.abort(grpc.StatusCode.INVALID_ARGUMENT, 'Low-energy security level 4 is not supported.')
else:
if not self.bluetooth.is_bonded(address):
self.bluetooth.create_bond(address, transport)
security_level_reached = await self.wait_le_security_level(request.le, address)
elif transport == floss_enums.BtTransport.BREDR:
if not request.HasField('classic'):
- raise RuntimeError('Secure: Request classic field must be set.')
+ await context.abort(grpc.StatusCode.INVALID_ARGUMENT, 'Request classic field must be set.')
if request.classic == security_pb2.LEVEL0:
security_level_reached = True
elif request.classic >= security_pb2.LEVEL3:
- raise RuntimeError('Secure: Classic security level up to 3 not supported')
+ await context.abort(grpc.StatusCode.INVALID_ARGUMENT,
+ 'Classic security level up to 3 is not supported.')
else:
if not self.bluetooth.is_bonded(address):
self.bluetooth.create_bond(address, transport)
security_level_reached = await self.wait_classic_security_level(request.classic, address)
else:
- raise RuntimeError(f'Secure: Invalid bluetooth transport type: {transport}')
+ await context.abort(grpc.StatusCode.INVALID_ARGUMENT, f'Invalid bluetooth transport type: {transport}.')
secure_response = security_pb2.SecureResponse()
if security_level_reached:
@@ -351,7 +356,7 @@ class SecurityService(security_grpc_aio.SecurityServicer):
elif transport == floss_enums.BtTransport.BREDR:
security_level_reached = await self.wait_classic_security_level(request.classic, address)
else:
- raise RuntimeError(f'WaitSecurity: Invalid bluetooth transport type: {transport}')
+ await context.abort(grpc.StatusCode.INVALID_ARGUMENT, f'Invalid bluetooth transport type: {transport}.')
wait_security_response = security_pb2.WaitSecurityResponse()
if security_level_reached:
@@ -376,8 +381,6 @@ class SecurityStorageService(security_grpc_aio.SecurityStorageServicer):
async def IsBonded(self, request: security_pb2.IsBondedRequest,
context: grpc.ServicerContext) -> wrappers_pb2.BoolValue:
- if not (request.HasField('public') or request.HasField('random')):
- raise ValueError('Invalid request address field.')
address = utils.address_from(request.address)
is_bonded = self.bluetooth.is_bonded(address)
@@ -411,9 +414,6 @@ class SecurityStorageService(security_grpc_aio.SecurityStorageServicer):
future.set_result, (False, f'{address} failed on remove_bond, got bond state {state},'
f' want {floss_enums.BondState.NOT_BONDED}'))
- if not (request.HasField('public') or request.HasField('random')):
- raise ValueError('Invalid request address field.')
-
address = utils.address_from(request.address)
if not self.bluetooth.is_bonded(address):
return empty_pb2.Empty()
@@ -425,7 +425,8 @@ class SecurityStorageService(security_grpc_aio.SecurityStorageServicer):
self.bluetooth.remove_bond(address)
success, reason = await remove_bond
if not success:
- raise RuntimeError(f'Failed to remove bond of address: {address}. Reason: {reason}')
+ await context.abort(grpc.StatusCode.INVALID_ARGUMENT,
+ f'Failed to remove bond of address: {address}. Reason: {reason}.')
finally:
self.bluetooth.adapter_client.unregister_callback_observer(name, observer)
return empty_pb2.Empty()
diff --git a/framework/api/system-current.txt b/framework/api/system-current.txt
index 04a169142f..2e39f52773 100644
--- a/framework/api/system-current.txt
+++ b/framework/api/system-current.txt
@@ -492,6 +492,8 @@ package android.bluetooth {
field public static final int AUDIO_LOCATION_TOP_SIDE_LEFT = 262144; // 0x40000
field public static final int AUDIO_LOCATION_TOP_SIDE_RIGHT = 524288; // 0x80000
field public static final String EXTRA_LE_AUDIO_GROUP_ID = "android.bluetooth.extra.LE_AUDIO_GROUP_ID";
+ field @FlaggedApi("com.android.bluetooth.flags.leaudio_callback_on_group_stream_status") public static final int GROUP_STREAM_STATUS_IDLE = 0; // 0x0
+ field @FlaggedApi("com.android.bluetooth.flags.leaudio_callback_on_group_stream_status") public static final int GROUP_STREAM_STATUS_STREAMING = 1; // 0x1
}
public static interface BluetoothLeAudio.Callback {
diff --git a/framework/java/android/bluetooth/BluetoothAdapter.java b/framework/java/android/bluetooth/BluetoothAdapter.java
index e0cdc2ce7b..509f8f3b80 100644
--- a/framework/java/android/bluetooth/BluetoothAdapter.java
+++ b/framework/java/android/bluetooth/BluetoothAdapter.java
@@ -5810,9 +5810,8 @@ public final class BluetoothAdapter {
try {
return mManagerService.isAutoOnSupported();
} catch (RemoteException e) {
- e.rethrowFromSystemServer();
+ throw e.rethrowFromSystemServer();
}
- return false;
}
/**
@@ -5829,9 +5828,8 @@ public final class BluetoothAdapter {
try {
return mManagerService.isAutoOnEnabled();
} catch (RemoteException e) {
- e.rethrowFromSystemServer();
+ throw e.rethrowFromSystemServer();
}
- return false;
}
/**
diff --git a/framework/java/android/bluetooth/BluetoothLeAudio.java b/framework/java/android/bluetooth/BluetoothLeAudio.java
index ae0883b9b9..68bbdd9406 100644
--- a/framework/java/android/bluetooth/BluetoothLeAudio.java
+++ b/framework/java/android/bluetooth/BluetoothLeAudio.java
@@ -668,6 +668,7 @@ public final class BluetoothLeAudio implements BluetoothProfile, AutoCloseable {
* @hide
*/
@FlaggedApi(Flags.FLAG_LEAUDIO_CALLBACK_ON_GROUP_STREAM_STATUS)
+ @SystemApi
public static final int GROUP_STREAM_STATUS_IDLE = IBluetoothLeAudio.GROUP_STREAM_STATUS_IDLE;
/**
@@ -676,6 +677,7 @@ public final class BluetoothLeAudio implements BluetoothProfile, AutoCloseable {
* @hide
*/
@FlaggedApi(Flags.FLAG_LEAUDIO_CALLBACK_ON_GROUP_STREAM_STATUS)
+ @SystemApi
public static final int GROUP_STREAM_STATUS_STREAMING =
IBluetoothLeAudio.GROUP_STREAM_STATUS_STREAMING;
diff --git a/framework/java/android/bluetooth/BluetoothVolumeControl.java b/framework/java/android/bluetooth/BluetoothVolumeControl.java
index 76c92ed2b6..bad01020a0 100644
--- a/framework/java/android/bluetooth/BluetoothVolumeControl.java
+++ b/framework/java/android/bluetooth/BluetoothVolumeControl.java
@@ -39,6 +39,7 @@ import android.util.CloseGuard;
import android.util.Log;
import com.android.bluetooth.flags.Flags;
+import com.android.internal.annotations.GuardedBy;
import com.android.modules.utils.SynchronousResultReceiver;
import java.util.ArrayList;
@@ -48,6 +49,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeoutException;
+import java.util.function.Consumer;
/**
* This class provides the public APIs to control the Bluetooth Volume Control service.
@@ -64,6 +66,8 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose
private static final boolean VDBG = false;
private CloseGuard mCloseGuard;
+
+ @GuardedBy("mCallbackExecutorMap")
private final Map<Callback, Executor> mCallbackExecutorMap = new HashMap<>();
/**
@@ -161,81 +165,61 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose
@SuppressLint("AndroidFrameworkBluetoothPermission")
private final IBluetoothVolumeControlCallback mCallback =
- new IBluetoothVolumeControlCallback.Stub() {
- @Override
- public void onVolumeOffsetChanged(
- @NonNull BluetoothDevice device, int instanceId, int volumeOffset) {
- Attributable.setAttributionSource(device, mAttributionSource);
- for (Map.Entry<BluetoothVolumeControl.Callback, Executor>
- callbackExecutorEntry : mCallbackExecutorMap.entrySet()) {
- BluetoothVolumeControl.Callback callback = callbackExecutorEntry.getKey();
- Executor executor = callbackExecutorEntry.getValue();
-
- // The old API operates on the first instance only
- if (instanceId == 1) {
- try {
- executor.execute(
- () -> callback.onVolumeOffsetChanged(device, volumeOffset));
- } finally {
- // As this deprecated callback, might not be defined; continue
- }
- }
- if (Flags.leaudioMultipleVocsInstancesApi()) {
- executor.execute(
- () ->
- callback.onVolumeOffsetChanged(
- device, instanceId, volumeOffset));
- }
- }
- }
+ new VolumeControlNotifyCallback(mCallbackExecutorMap);
- @Override
- public void onVolumeOffsetAudioLocationChanged(
- @NonNull BluetoothDevice device, int instanceId, int audioLocation) {
- if (Flags.leaudioMultipleVocsInstancesApi()) {
- Attributable.setAttributionSource(device, mAttributionSource);
- for (Map.Entry<BluetoothVolumeControl.Callback, Executor>
- callbackExecutorEntry : mCallbackExecutorMap.entrySet()) {
- BluetoothVolumeControl.Callback callback =
- callbackExecutorEntry.getKey();
- Executor executor = callbackExecutorEntry.getValue();
- executor.execute(
- () ->
- callback.onVolumeOffsetAudioLocationChanged(
- device, instanceId, audioLocation));
- }
- }
- }
+ private class VolumeControlNotifyCallback extends IBluetoothVolumeControlCallback.Stub {
+ private final Map<Callback, Executor> mCallbackMap;
- @Override
- public void onVolumeOffsetAudioDescriptionChanged(
- @NonNull BluetoothDevice device, int instanceId, String audioDescription) {
- if (Flags.leaudioMultipleVocsInstancesApi()) {
- Attributable.setAttributionSource(device, mAttributionSource);
- for (Map.Entry<BluetoothVolumeControl.Callback, Executor>
- callbackExecutorEntry : mCallbackExecutorMap.entrySet()) {
- BluetoothVolumeControl.Callback callback =
- callbackExecutorEntry.getKey();
- Executor executor = callbackExecutorEntry.getValue();
- executor.execute(
- () ->
- callback.onVolumeOffsetAudioDescriptionChanged(
- device, instanceId, audioDescription));
- }
- }
- }
+ VolumeControlNotifyCallback(Map<Callback, Executor> callbackMap) {
+ mCallbackMap = callbackMap;
+ }
- @Override
- public void onDeviceVolumeChanged(@NonNull BluetoothDevice device, int volume) {
- Attributable.setAttributionSource(device, mAttributionSource);
- for (Map.Entry<BluetoothVolumeControl.Callback, Executor>
- callbackExecutorEntry : mCallbackExecutorMap.entrySet()) {
- BluetoothVolumeControl.Callback callback = callbackExecutorEntry.getKey();
- Executor executor = callbackExecutorEntry.getValue();
- executor.execute(() -> callback.onDeviceVolumeChanged(device, volume));
- }
- }
- };
+ private void forEach(Consumer<BluetoothVolumeControl.Callback> consumer) {
+ synchronized (mCallbackMap) {
+ mCallbackMap.forEach(
+ (callback, executor) -> executor.execute(() -> consumer.accept(callback)));
+ }
+ }
+
+ @Override
+ public void onVolumeOffsetChanged(
+ @NonNull BluetoothDevice device, int instanceId, int volumeOffset) {
+ Attributable.setAttributionSource(device, mAttributionSource);
+
+ if (instanceId == 1) {
+ forEach((cb) -> cb.onVolumeOffsetChanged(device, volumeOffset));
+ }
+ if (Flags.leaudioMultipleVocsInstancesApi()) {
+ forEach((cb) -> cb.onVolumeOffsetChanged(device, instanceId, volumeOffset));
+ }
+ }
+
+ @Override
+ public void onVolumeOffsetAudioLocationChanged(
+ @NonNull BluetoothDevice device, int instanceId, int audioLocation) {
+ Attributable.setAttributionSource(device, mAttributionSource);
+ forEach(
+ (cb) ->
+ cb.onVolumeOffsetAudioLocationChanged(
+ device, instanceId, audioLocation));
+ }
+
+ @Override
+ public void onVolumeOffsetAudioDescriptionChanged(
+ @NonNull BluetoothDevice device, int instanceId, String audioDescription) {
+ Attributable.setAttributionSource(device, mAttributionSource);
+ forEach(
+ (cb) ->
+ cb.onVolumeOffsetAudioDescriptionChanged(
+ device, instanceId, audioDescription));
+ }
+
+ @Override
+ public void onDeviceVolumeChanged(@NonNull BluetoothDevice device, int volume) {
+ Attributable.setAttributionSource(device, mAttributionSource);
+ forEach((cb) -> cb.onDeviceVolumeChanged(device, volume));
+ }
+ }
/**
* Intent used to broadcast the change in connection state of the Volume Control profile.
@@ -494,74 +478,7 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose
service.registerCallback(mCallback, mAttributionSource, recv);
} else {
service.notifyNewRegisteredCallback(
- new IBluetoothVolumeControlCallback.Stub() {
- @Override
- public void onVolumeOffsetChanged(
- BluetoothDevice device, int instanceId, int volumeOffset)
- throws RemoteException {
- Attributable.setAttributionSource(device, mAttributionSource);
-
- // The old API operates on the first instance only
- if (instanceId == 1) {
- try {
- executor.execute(
- () ->
- callback.onVolumeOffsetChanged(
- device, volumeOffset));
- } finally {
- // As this deprecated callback, might not be
- // defined; continue
- }
- }
- if (Flags.leaudioMultipleVocsInstancesApi()) {
- executor.execute(
- () ->
- callback.onVolumeOffsetChanged(
- device, instanceId, volumeOffset));
- }
- }
-
- @Override
- public void onVolumeOffsetAudioLocationChanged(
- BluetoothDevice device, int instanceId, int location)
- throws RemoteException {
- if (Flags.leaudioMultipleVocsInstancesApi()) {
- Attributable.setAttributionSource(
- device, mAttributionSource);
- executor.execute(
- () ->
- callback.onVolumeOffsetAudioLocationChanged(
- device, instanceId, location));
- }
- }
-
- @Override
- public void onVolumeOffsetAudioDescriptionChanged(
- BluetoothDevice device,
- int instanceId,
- String audioDescription)
- throws RemoteException {
- if (Flags.leaudioMultipleVocsInstancesApi()) {
- Attributable.setAttributionSource(
- device, mAttributionSource);
- executor.execute(
- () ->
- callback
- .onVolumeOffsetAudioDescriptionChanged(
- device,
- instanceId,
- audioDescription));
- }
- }
-
- @Override
- public void onDeviceVolumeChanged(
- BluetoothDevice device, int volume) throws RemoteException {
- Attributable.setAttributionSource(device, mAttributionSource);
- executor.execute(
- () -> callback.onDeviceVolumeChanged(device, volume));
- }
- },
+ new VolumeControlNotifyCallback(Map.of(callback, executor)),
mAttributionSource,
recv);
}
@@ -602,10 +519,10 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose
if (mCallbackExecutorMap.remove(callback) == null) {
throw new IllegalArgumentException("This callback has not been registered");
}
- }
- if (!mCallbackExecutorMap.isEmpty()) {
- return;
+ if (!mCallbackExecutorMap.isEmpty()) {
+ return;
+ }
}
// If the callback map is empty, we unregister the service-to-app callback
diff --git a/service/Android.bp b/service/Android.bp
index b2c2a06dcc..81283dee81 100644
--- a/service/Android.bp
+++ b/service/Android.bp
@@ -44,6 +44,8 @@ java_defaults {
"-Xep:ClassCanBeStatic:ERROR",
"-Xep:EqualsIncompatibleType:ERROR",
"-Xep:ReferenceEquality:ERROR",
+ "-Xep:UnusedMethod:ERROR",
+ "-Xep:UnusedVariable:ERROR",
],
},
diff --git a/service/src/com/android/server/bluetooth/BluetoothAirplaneModeListener.java b/service/src/com/android/server/bluetooth/BluetoothAirplaneModeListener.java
index 64eefcb311..0cc676b812 100644
--- a/service/src/com/android/server/bluetooth/BluetoothAirplaneModeListener.java
+++ b/service/src/com/android/server/bluetooth/BluetoothAirplaneModeListener.java
@@ -66,7 +66,6 @@ class BluetoothAirplaneModeListener extends Handler {
// keeps track of whether user enabling bt notification was shown
public static final String APM_BT_ENABLED_NOTIFICATION = "apm_bt_enabled_notification";
- private static final int MSG_AIRPLANE_MODE_CHANGED = 0;
public static final int NOTIFICATION_NOT_SHOWN = 0;
public static final int NOTIFICATION_SHOWN = 1;
public static final int UNUSED = 0;
@@ -356,9 +355,6 @@ class BluetoothAirplaneModeListener extends Handler {
// waive WRITE_SECURE_SETTINGS permission check
final long callingIdentity = Binder.clearCallingIdentity();
try {
- Context userContext =
- mContext.createContextAsUser(
- UserHandle.of(ActivityManager.getCurrentUser()), 0);
return mAirplaneHelper.getSettingsSecureInt(name, NOTIFICATION_NOT_SHOWN)
== NOTIFICATION_NOT_SHOWN;
} finally {
diff --git a/service/src/com/android/server/bluetooth/BluetoothManagerService.java b/service/src/com/android/server/bluetooth/BluetoothManagerService.java
index 13172e86d8..340ce70a91 100644
--- a/service/src/com/android/server/bluetooth/BluetoothManagerService.java
+++ b/service/src/com/android/server/bluetooth/BluetoothManagerService.java
@@ -108,13 +108,9 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
class BluetoothManagerService {
private static final String TAG = BluetoothManagerService.class.getSimpleName();
- private static final String BLUETOOTH_PRIVILEGED =
- android.Manifest.permission.BLUETOOTH_PRIVILEGED;
-
private static final int ACTIVE_LOG_MAX_SIZE = 20;
private static final int CRASH_LOG_MAX_SIZE = 100;
- private static final int DEFAULT_REBIND_COUNT = 3;
// Maximum msec to wait for a bind
private static final int TIMEOUT_BIND_MS =
3000 * SystemProperties.getInt("ro.hw_timeout_multiplier", 1);
@@ -177,9 +173,6 @@ class BluetoothManagerService {
// and Airplane mode will have higher priority.
@VisibleForTesting static final int BLUETOOTH_ON_AIRPLANE = 2;
- private static final int FLAGS_SYSTEM_APP =
- ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
-
// APM enhancement feature is enabled by default
// Set this value to 0 to disable the feature
private static final int DEFAULT_APM_ENHANCEMENT_STATE = 1;
@@ -189,11 +182,6 @@ class BluetoothManagerService {
private final UserManager mUserManager;
- // -3 match with Userhandle.USER_CURRENT_OR_SELF
- private static final UserHandle USER_HANDLE_CURRENT_OR_SELF = UserHandle.of(-3);
- // -10000 match with Userhandle.USER_NULL
- private static final UserHandle USER_HANDLE_NULL = UserHandle.of(-10000);
-
// Locks are not provided for mName and mAddress.
// They are accessed in handler or broadcast receiver, same thread context.
private String mAddress = null;
@@ -299,8 +287,6 @@ class BluetoothManagerService {
private final boolean mIsHearingAidProfileSupported;
- private volatile boolean mUnbindingAll = false;
-
private final IBluetoothCallback mBluetoothCallback =
new IBluetoothCallback.Stub() {
@Override
@@ -2023,7 +2009,7 @@ class BluetoothManagerService {
android.Manifest.permission.BLUETOOTH_CONNECT,
android.Manifest.permission.BLUETOOTH_PRIVILEGED
})
- private void restartForNewUser(UserHandle newUser) {
+ private void restartForNewUser(UserHandle unusedNewUser) {
mAdapterLock.readLock().lock();
try {
if (mAdapter != null) {
diff --git a/service/src/com/android/server/bluetooth/BluetoothServiceBinder.java b/service/src/com/android/server/bluetooth/BluetoothServiceBinder.java
index 99d94e7610..8bbdd135e6 100644
--- a/service/src/com/android/server/bluetooth/BluetoothServiceBinder.java
+++ b/service/src/com/android/server/bluetooth/BluetoothServiceBinder.java
@@ -56,12 +56,12 @@ class BluetoothServiceBinder extends IBluetoothManager.Stub {
private final AppOpsManager mAppOpsManager;
private final PermissionManager mPermissionManager;
private final BtPermissionUtils mPermissionUtils;
- private final Looper mLooper;
+ private final Looper unusedmLooper;
BluetoothServiceBinder(
BluetoothManagerService bms, Looper looper, Context ctx, UserManager userManager) {
mBluetoothManagerService = bms;
- mLooper = looper;
+ unusedmLooper = looper;
mContext = ctx;
mUserManager = userManager;
mAppOpsManager =
@@ -312,7 +312,7 @@ class BluetoothServiceBinder extends IBluetoothManager.Stub {
@NonNull ParcelFileDescriptor out,
@NonNull ParcelFileDescriptor err,
@NonNull String[] args) {
- return new BluetoothShellCommand(mBluetoothManagerService, mContext)
+ return new BluetoothShellCommand(mBluetoothManagerService)
.exec(
this,
in.getFileDescriptor(),
diff --git a/service/src/com/android/server/bluetooth/BluetoothShellCommand.java b/service/src/com/android/server/bluetooth/BluetoothShellCommand.java
index 712475f142..d4970b7b63 100644
--- a/service/src/com/android/server/bluetooth/BluetoothShellCommand.java
+++ b/service/src/com/android/server/bluetooth/BluetoothShellCommand.java
@@ -20,7 +20,6 @@ import static java.util.Objects.requireNonNull;
import android.bluetooth.BluetoothAdapter;
import android.content.AttributionSource;
-import android.content.Context;
import android.os.Binder;
import android.os.Process;
import android.os.RemoteException;
@@ -34,7 +33,6 @@ class BluetoothShellCommand extends BasicShellCommandHandler {
private static final String TAG = BluetoothShellCommand.class.getSimpleName();
private final BluetoothManagerService mManagerService;
- private final Context mContext;
@VisibleForTesting
final BluetoothCommand[] mBluetoothCommands = {
@@ -154,9 +152,8 @@ class BluetoothShellCommand extends BasicShellCommandHandler {
}
}
- BluetoothShellCommand(BluetoothManagerService managerService, Context context) {
+ BluetoothShellCommand(BluetoothManagerService managerService) {
mManagerService = managerService;
- mContext = context;
}
@Override
diff --git a/service/tests/src/com/android/server/bluetooth/BluetoothManagerServiceTest.java b/service/tests/src/com/android/server/bluetooth/BluetoothManagerServiceTest.java
index 268e866780..c58f081460 100644
--- a/service/tests/src/com/android/server/bluetooth/BluetoothManagerServiceTest.java
+++ b/service/tests/src/com/android/server/bluetooth/BluetoothManagerServiceTest.java
@@ -86,7 +86,6 @@ import java.util.stream.Stream;
public class BluetoothManagerServiceTest {
private static final String TAG = BluetoothManagerServiceTest.class.getSimpleName();
private static final int STATE_BLE_TURNING_ON = 14; // can't find the symbol because hidden api
- private static final int TIMEOUT_MS = 1000; // TO use to wait for handler execution
BluetoothManagerService mManagerService;
diff --git a/service/tests/src/com/android/server/bluetooth/BluetoothShellCommandTest.java b/service/tests/src/com/android/server/bluetooth/BluetoothShellCommandTest.java
index 8f71a563f1..39bc23a4b3 100644
--- a/service/tests/src/com/android/server/bluetooth/BluetoothShellCommandTest.java
+++ b/service/tests/src/com/android/server/bluetooth/BluetoothShellCommandTest.java
@@ -30,7 +30,6 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import android.bluetooth.BluetoothAdapter;
-import android.content.Context;
import android.os.Binder;
import android.os.RemoteException;
@@ -62,9 +61,6 @@ public class BluetoothShellCommandTest {
@Mock BluetoothServiceBinder mBinder;
- @Mock
- Context mContext;
-
BluetoothShellCommand mShellCommand;
@Before
@@ -72,7 +68,7 @@ public class BluetoothShellCommandTest {
MockitoAnnotations.initMocks(this);
doReturn(mBinder).when(mManagerService).getBinder();
- mShellCommand = new BluetoothShellCommand(mManagerService, mContext);
+ mShellCommand = new BluetoothShellCommand(mManagerService);
mShellCommand.init(
mock(Binder.class), mock(FileDescriptor.class), mock(FileDescriptor.class),
mock(FileDescriptor.class), new String[0], -1);
diff --git a/sysprop/Android.bp b/sysprop/Android.bp
index b399a8d7b8..c2e71a97c8 100644
--- a/sysprop/Android.bp
+++ b/sysprop/Android.bp
@@ -10,6 +10,7 @@ sysprop_library {
"avrcp.sysprop",
"ble.sysprop",
"bta.sysprop",
+ "device_id.sysprop",
"hfp.sysprop",
],
property_owner: "Platform",
diff --git a/sysprop/device_id.sysprop b/sysprop/device_id.sysprop
new file mode 100644
index 0000000000..b220abbe01
--- /dev/null
+++ b/sysprop/device_id.sysprop
@@ -0,0 +1,26 @@
+module: "android.sysprop.bluetooth.DeviceIDProperties"
+owner: Platform
+
+prop {
+ api_name: "vendor_id"
+ type: Integer
+ scope: Internal
+ access: Readonly
+ prop_name: "bluetooth.device_id.vendor_id"
+}
+
+prop {
+ api_name: "vendor_id_source"
+ type: Integer
+ scope: Internal
+ access: Readonly
+ prop_name: "bluetooth.device_id.vendor_id_source"
+}
+
+prop {
+ api_name: "product_id"
+ type: Integer
+ scope: Internal
+ access: Readonly
+ prop_name: "bluetooth.device_id.product_id"
+}
diff --git a/sysprop/exported_include/android_bluetooth_sysprop.h b/sysprop/exported_include/android_bluetooth_sysprop.h
index 3e76262114..e76411ef95 100644
--- a/sysprop/exported_include/android_bluetooth_sysprop.h
+++ b/sysprop/exported_include/android_bluetooth_sysprop.h
@@ -22,6 +22,7 @@
#include <avrcp.sysprop.h>
#include <ble.sysprop.h>
#include <bta.sysprop.h>
+#include <device_id.sysprop.h>
#include <hfp.sysprop.h>
#define GET_SYSPROP(namespace, prop, default) \
diff --git a/system/audio_hal_interface/a2dp_encoding_host.cc b/system/audio_hal_interface/a2dp_encoding_host.cc
index ec38b28f05..6b596e5861 100644
--- a/system/audio_hal_interface/a2dp_encoding_host.cc
+++ b/system/audio_hal_interface/a2dp_encoding_host.cc
@@ -132,12 +132,12 @@ bool StartRequest() {
return false;
}
- if (btif_av_stream_started_ready()) {
+ if (btif_av_stream_started_ready(A2dpType::kSource)) {
// Already started, ACK back immediately.
a2dp_data_path_open();
return true;
}
- if (btif_av_stream_ready()) {
+ if (btif_av_stream_ready(A2dpType::kSource)) {
a2dp_data_path_open();
/*
* Post start event and wait for audio path to open.
@@ -145,8 +145,8 @@ bool StartRequest() {
* procedure is completed.
*/
a2dp_pending_cmd_ = A2DP_CTRL_CMD_START;
- btif_av_stream_start();
- if (btif_av_get_peer_sep() != AVDT_TSEP_SRC) {
+ btif_av_stream_start(A2dpType::kSource);
+ if (btif_av_get_peer_sep(A2dpType::kSource) != AVDT_TSEP_SRC) {
LOG_INFO("%s: accepted", __func__);
return true; // NOTE: The request is placed, but could still fail.
}
@@ -159,9 +159,9 @@ bool StartRequest() {
// Invoked by audio server when audio streaming is done.
bool StopRequest() {
- if (btif_av_get_peer_sep() == AVDT_TSEP_SNK &&
- !btif_av_stream_started_ready()) {
- btif_av_clear_remote_suspend_flag();
+ if (btif_av_get_peer_sep(A2dpType::kSource) == AVDT_TSEP_SNK &&
+ !btif_av_stream_started_ready(A2dpType::kSource)) {
+ btif_av_clear_remote_suspend_flag(A2dpType::kSource);
return true;
}
LOG_INFO("%s: handling", __func__);
@@ -175,7 +175,7 @@ bool SuspendRequest() {
LOG_WARN("%s: busy in pending_cmd=%u", __func__, a2dp_pending_cmd_);
return false;
}
- if (!btif_av_stream_started_ready()) {
+ if (!btif_av_stream_started_ready(A2dpType::kSource)) {
LOG_WARN("%s: AV stream is not started", __func__);
return false;
}
diff --git a/system/audio_hal_interface/aidl/a2dp_encoding_aidl.cc b/system/audio_hal_interface/aidl/a2dp_encoding_aidl.cc
index a929d802b8..ccf21fff98 100644
--- a/system/audio_hal_interface/aidl/a2dp_encoding_aidl.cc
+++ b/system/audio_hal_interface/aidl/a2dp_encoding_aidl.cc
@@ -85,11 +85,11 @@ BluetoothAudioCtrlAck A2dpTransport::StartRequest(bool is_low_latency) {
return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_INCALL_FAILURE);
}
- if (btif_av_stream_started_ready()) {
+ if (btif_av_stream_started_ready(A2dpType::kSource)) {
// Already started, ACK back immediately.
return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_SUCCESS);
}
- if (btif_av_stream_ready()) {
+ if (btif_av_stream_ready(A2dpType::kSource)) {
// check if codec needs to be switched prior to stream start
invoke_switch_codec_cb(is_low_latency);
/*
@@ -99,7 +99,7 @@ BluetoothAudioCtrlAck A2dpTransport::StartRequest(bool is_low_latency) {
*/
a2dp_pending_cmd_ = A2DP_CTRL_CMD_START;
btif_av_stream_start_with_latency(is_low_latency);
- if (btif_av_get_peer_sep() != AVDT_TSEP_SRC) {
+ if (btif_av_get_peer_sep(A2dpType::kSource) != AVDT_TSEP_SRC) {
LOG(INFO) << __func__ << ": accepted";
return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_PENDING);
}
@@ -120,7 +120,7 @@ BluetoothAudioCtrlAck A2dpTransport::SuspendRequest() {
return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_FAILURE);
}
// Local suspend
- if (btif_av_stream_started_ready()) {
+ if (btif_av_stream_started_ready(A2dpType::kSource)) {
LOG(INFO) << __func__ << ": accepted";
a2dp_pending_cmd_ = A2DP_CTRL_CMD_SUSPEND;
btif_av_stream_suspend();
@@ -130,14 +130,14 @@ BluetoothAudioCtrlAck A2dpTransport::SuspendRequest() {
* audioflinger close the channel. This can happen if we are
* remotely suspended, clear REMOTE SUSPEND flag.
*/
- btif_av_clear_remote_suspend_flag();
+ btif_av_clear_remote_suspend_flag(A2dpType::kSource);
return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_SUCCESS);
}
void A2dpTransport::StopRequest() {
- if (btif_av_get_peer_sep() == AVDT_TSEP_SNK &&
- !btif_av_stream_started_ready()) {
- btif_av_clear_remote_suspend_flag();
+ if (btif_av_get_peer_sep(A2dpType::kSource) == AVDT_TSEP_SNK &&
+ !btif_av_stream_started_ready(A2dpType::kSource)) {
+ btif_av_clear_remote_suspend_flag(A2dpType::kSource);
return;
}
LOG(INFO) << __func__ << ": handling";
diff --git a/system/audio_hal_interface/hidl/a2dp_encoding_hidl.cc b/system/audio_hal_interface/hidl/a2dp_encoding_hidl.cc
index 77d3a434ed..6cd71ea08c 100644
--- a/system/audio_hal_interface/hidl/a2dp_encoding_hidl.cc
+++ b/system/audio_hal_interface/hidl/a2dp_encoding_hidl.cc
@@ -80,19 +80,19 @@ class A2dpTransport
return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_INCALL_FAILURE);
}
- if (btif_av_stream_started_ready()) {
+ if (btif_av_stream_started_ready(A2dpType::kSource)) {
// Already started, ACK back immediately.
return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_SUCCESS);
}
- if (btif_av_stream_ready()) {
+ if (btif_av_stream_ready(A2dpType::kSource)) {
/*
* Post start event and wait for audio path to open.
* If we are the source, the ACK will be sent after the start
* procedure is completed, othewise send it now.
*/
a2dp_pending_cmd_ = A2DP_CTRL_CMD_START;
- btif_av_stream_start();
- if (btif_av_get_peer_sep() != AVDT_TSEP_SRC) {
+ btif_av_stream_start(A2dpType::kSource);
+ if (btif_av_get_peer_sep(A2dpType::kSource) != AVDT_TSEP_SRC) {
LOG(INFO) << __func__ << ": accepted";
return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_PENDING);
}
@@ -113,7 +113,7 @@ class A2dpTransport
return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_FAILURE);
}
// Local suspend
- if (btif_av_stream_started_ready()) {
+ if (btif_av_stream_started_ready(A2dpType::kSource)) {
LOG(INFO) << __func__ << ": accepted";
a2dp_pending_cmd_ = A2DP_CTRL_CMD_SUSPEND;
btif_av_stream_suspend();
@@ -123,14 +123,14 @@ class A2dpTransport
* audioflinger close the channel. This can happen if we are
* remotely suspended, clear REMOTE SUSPEND flag.
*/
- btif_av_clear_remote_suspend_flag();
+ btif_av_clear_remote_suspend_flag(A2dpType::kSource);
return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_SUCCESS);
}
void StopRequest() override {
- if (btif_av_get_peer_sep() == AVDT_TSEP_SNK &&
- !btif_av_stream_started_ready()) {
- btif_av_clear_remote_suspend_flag();
+ if (btif_av_get_peer_sep(A2dpType::kSource) == AVDT_TSEP_SNK &&
+ !btif_av_stream_started_ready(A2dpType::kSource)) {
+ btif_av_clear_remote_suspend_flag(A2dpType::kSource);
return;
}
LOG(INFO) << __func__ << ": handling";
diff --git a/system/bta/Android.bp b/system/bta/Android.bp
index 780bfc1c75..47b1061223 100644
--- a/system/bta/Android.bp
+++ b/system/bta/Android.bp
@@ -451,6 +451,7 @@ cc_test {
"BluetoothGeneratedDumpsysDataSchema_h",
],
srcs: [
+ ":BluetoothLogRedactionSources",
":TestCommonMockFunctions",
":TestFakeOsi",
":TestMockBtaSys",
@@ -865,6 +866,7 @@ cc_test {
"le_audio/le_audio_set_configuration_provider_json.cc",
"le_audio/le_audio_types.cc",
"le_audio/le_audio_types_test.cc",
+ "le_audio/le_audio_utils.cc",
"le_audio/metrics_collector_linux.cc",
"le_audio/mock_codec_interface.cc",
"le_audio/mock_codec_manager.cc",
@@ -1053,11 +1055,12 @@ cc_test {
srcs: [
":TestCommonMockFunctions",
":TestCommonStackConfig",
+ ":TestMockMainShim",
"le_audio/broadcaster/broadcaster_types.cc",
- "le_audio/broadcaster/mock_ble_advertising_manager.cc",
"le_audio/broadcaster/state_machine.cc",
"le_audio/broadcaster/state_machine_test.cc",
"le_audio/le_audio_types.cc",
+ "le_audio/le_audio_utils.cc",
"le_audio/mock_codec_interface.cc",
"le_audio/mock_codec_manager.cc",
"le_audio/mock_iso_manager.cc",
@@ -1072,11 +1075,14 @@ cc_test {
"libbluetooth_gd",
"libbluetooth_log",
"libbt-common",
+ "libbt-platform-protos-lite",
"libbt_shim_bridge",
"libbt_shim_ffi",
"libchrome",
+ "libflatbuffers-cpp",
"libgmock",
"liblc3",
+ "libosi",
],
sanitize: {
cfi: true,
@@ -1114,7 +1120,6 @@ cc_test {
"le_audio/broadcaster/broadcaster.cc",
"le_audio/broadcaster/broadcaster_test.cc",
"le_audio/broadcaster/broadcaster_types.cc",
- "le_audio/broadcaster/mock_ble_advertising_manager.cc",
"le_audio/broadcaster/mock_state_machine.cc",
"le_audio/content_control_id_keeper.cc",
"le_audio/le_audio_types.cc",
@@ -1297,3 +1302,73 @@ cc_test {
},
cflags: ["-Wno-unused-parameter"],
}
+
+cc_test {
+ name: "net_test_bta_jv",
+ test_suites: ["general-tests"],
+ defaults: [
+ "fluoride_bta_defaults",
+ "mts_defaults",
+ ],
+ host_supported: true,
+ isolated: false,
+ include_dirs: [
+ "packages/modules/Bluetooth/system",
+ "packages/modules/Bluetooth/system/bta/include",
+ "packages/modules/Bluetooth/system/bta/test/common",
+ "packages/modules/Bluetooth/system/stack/include",
+ ],
+ srcs: [
+ ":BtaDmSources",
+ ":TestCommonMainHandler",
+ ":TestCommonMockFunctions",
+ ":TestFakeOsi",
+ ":TestMockBtaGatt",
+ ":TestMockBtaLeAudio",
+ ":TestMockBtaScn",
+ ":TestMockBtaSdp",
+ ":TestMockBtaSys",
+ ":TestMockBtif",
+ ":TestMockDevice",
+ ":TestMockMainShim",
+ ":TestMockMainShimEntry",
+ ":TestMockStack",
+ "jv/bta_jv_act.cc",
+ "test/bta_jv_test.cc",
+ ],
+ shared_libs: [
+ "libbase",
+ "libcrypto",
+ "liblog",
+ "server_configurable_flags",
+ ],
+ static_libs: [
+ "libbluetooth-types",
+ "libbluetooth_crypto_toolbox",
+ "libbluetooth_gd",
+ "libbluetooth_hci_pdl",
+ "libbluetooth_log",
+ "libbt-common",
+ "libbt-platform-protos-lite",
+ "libbt_shim_bridge",
+ "libbt_shim_ffi",
+ "libchrome",
+ "libcom.android.sysprop.bluetooth.wrapped",
+ "libevent",
+ "libgmock",
+ "libosi",
+ ],
+ generated_headers: [
+ "BluetoothGeneratedDumpsysDataSchema_h",
+ ],
+ sanitize: {
+ cfi: true,
+ scs: true,
+ address: true,
+ all_undefined: true,
+ integer_overflow: true,
+ diag: {
+ undefined: true,
+ },
+ },
+}
diff --git a/system/bta/ag/bta_ag_act.cc b/system/bta/ag/bta_ag_act.cc
index 92310678c0..b05d5d4560 100644
--- a/system/bta/ag/bta_ag_act.cc
+++ b/system/bta/ag/bta_ag_act.cc
@@ -789,6 +789,10 @@ void bta_ag_post_sco_close(tBTA_AG_SCB* p_scb, const tBTA_AG_DATA& data) {
"BTA_AG_POST_SCO_CALL_END_INCALL")) {
break;
}
+ if (IS_FLAG_ENABLED(is_sco_managed_by_audio)) {
+ // let Audio HAL open the SCO
+ break;
+ }
bta_ag_sco_open(p_scb, data);
} else {
p_scb->post_sco = BTA_AG_POST_SCO_NONE;
diff --git a/system/bta/ag/bta_ag_cmd.cc b/system/bta/ag/bta_ag_cmd.cc
index cea6374049..17d5c6ce10 100644
--- a/system/bta/ag/bta_ag_cmd.cc
+++ b/system/bta/ag/bta_ag_cmd.cc
@@ -1452,6 +1452,10 @@ static void bta_ag_hsp_result(tBTA_AG_SCB* p_scb,
bta_ag_result_text(result.result))) {
break;
}
+ if (IS_FLAG_ENABLED(is_sco_managed_by_audio)) {
+ // let Audio HAL open the SCO
+ break;
+ }
bta_ag_sco_open(p_scb, tBTA_AG_DATA::kEmpty);
}
break;
@@ -1471,6 +1475,10 @@ static void bta_ag_hsp_result(tBTA_AG_SCB* p_scb,
bta_ag_result_text(result.result))) {
break;
}
+ if (IS_FLAG_ENABLED(is_sco_managed_by_audio)) {
+ // let Audio HAL open the SCO
+ break;
+ }
bta_ag_sco_open(p_scb, tBTA_AG_DATA::kEmpty);
} else if (result.data.audio_handle == BTA_AG_HANDLE_NONE &&
bta_ag_sco_is_open(p_scb)) {
@@ -1565,6 +1573,10 @@ static void bta_ag_hfp_result(tBTA_AG_SCB* p_scb,
bta_ag_result_text(result.result))) {
break;
}
+ if (IS_FLAG_ENABLED(is_sco_managed_by_audio)) {
+ // let Audio HAL open the SCO
+ break;
+ }
bta_ag_sco_open(p_scb, tBTA_AG_DATA::kEmpty);
}
}
@@ -1585,6 +1597,10 @@ static void bta_ag_hfp_result(tBTA_AG_SCB* p_scb,
bta_ag_result_text(result.result))) {
break;
}
+ if (IS_FLAG_ENABLED(is_sco_managed_by_audio)) {
+ // let Audio HAL open the SCO
+ break;
+ }
bta_ag_sco_open(p_scb, tBTA_AG_DATA::kEmpty);
} else if ((result.data.audio_handle == BTA_AG_HANDLE_NONE) &&
bta_ag_sco_is_open(p_scb)) {
@@ -1608,6 +1624,10 @@ static void bta_ag_hfp_result(tBTA_AG_SCB* p_scb,
bta_ag_result_text(result.result))) {
break;
}
+ if (IS_FLAG_ENABLED(is_sco_managed_by_audio)) {
+ // let Audio HAL open the SCO
+ break;
+ }
bta_ag_sco_open(p_scb, tBTA_AG_DATA::kEmpty);
}
break;
@@ -1621,6 +1641,10 @@ static void bta_ag_hfp_result(tBTA_AG_SCB* p_scb,
bta_ag_result_text(result.result))) {
break;
}
+ if (IS_FLAG_ENABLED(is_sco_managed_by_audio)) {
+ // let Audio HAL open the SCO
+ break;
+ }
bta_ag_sco_open(p_scb, tBTA_AG_DATA::kEmpty);
}
break;
@@ -1634,6 +1658,10 @@ static void bta_ag_hfp_result(tBTA_AG_SCB* p_scb,
bta_ag_result_text(result.result))) {
break;
}
+ if (IS_FLAG_ENABLED(is_sco_managed_by_audio)) {
+ // let Audio HAL open the SCO
+ break;
+ }
bta_ag_sco_open(p_scb, tBTA_AG_DATA::kEmpty);
} else if (result.data.audio_handle == BTA_AG_HANDLE_NONE) {
bta_ag_sco_close(p_scb, tBTA_AG_DATA::kEmpty);
@@ -1652,6 +1680,10 @@ static void bta_ag_hfp_result(tBTA_AG_SCB* p_scb,
bta_ag_result_text(result.result))) {
break;
}
+ if (IS_FLAG_ENABLED(is_sco_managed_by_audio)) {
+ // let Audio HAL open the SCO
+ break;
+ }
bta_ag_sco_open(p_scb, tBTA_AG_DATA::kEmpty);
} else if (result.data.audio_handle == BTA_AG_HANDLE_NONE) {
bta_ag_sco_close(p_scb, tBTA_AG_DATA::kEmpty);
diff --git a/system/bta/ag/bta_ag_sco.cc b/system/bta/ag/bta_ag_sco.cc
index 710545273f..0b1fb3f94c 100644
--- a/system/bta/ag/bta_ag_sco.cc
+++ b/system/bta/ag/bta_ag_sco.cc
@@ -434,12 +434,10 @@ void bta_ag_create_sco(tBTA_AG_SCB* p_scb, bool is_orig) {
return;
}
-#if (DISABLE_WBS == FALSE)
if ((p_scb->sco_codec == BTM_SCO_CODEC_MSBC) && !p_scb->codec_fallback &&
hfp_hal_interface::get_wbs_supported()) {
esco_codec = UUID_CODEC_MSBC;
}
-#endif
if (is_hfp_aptx_voice_enabled()) {
if ((p_scb->sco_codec == BTA_AG_SCO_APTX_SWB_SETTINGS_Q0) &&
@@ -818,14 +816,9 @@ static void bta_ag_sco_event(tBTA_AG_SCB* p_scb, uint8_t event) {
/* remove listening connection */
bta_ag_remove_sco(p_scb, false);
-#if (DISABLE_WBS == FALSE)
/* start codec negotiation */
p_sco->state = BTA_AG_SCO_CODEC_ST;
bta_ag_codec_negotiate(p_scb);
-#else
- bta_ag_create_sco(p_scb, true);
- p_sco->state = BTA_AG_SCO_OPENING_ST;
-#endif
break;
case BTA_AG_SCO_SHUTDOWN_E:
@@ -928,13 +921,11 @@ static void bta_ag_sco_event(tBTA_AG_SCB* p_scb, uint8_t event) {
}
break;
-#if (DISABLE_WBS == FALSE)
case BTA_AG_SCO_REOPEN_E:
/* start codec negotiation */
p_sco->state = BTA_AG_SCO_CODEC_ST;
bta_ag_codec_negotiate(p_scb);
break;
-#endif
case BTA_AG_SCO_XFER_E:
/* save xfer scb */
@@ -1206,18 +1197,11 @@ static void bta_ag_sco_event(tBTA_AG_SCB* p_scb, uint8_t event) {
bta_ag_create_sco(p_scb, false);
bta_ag_remove_sco(p_sco->p_xfer_scb, false);
-#if (DISABLE_WBS == FALSE)
/* start codec negotiation */
p_sco->state = BTA_AG_SCO_CODEC_ST;
tBTA_AG_SCB* p_cn_scb = p_sco->p_xfer_scb;
p_sco->p_xfer_scb = nullptr;
bta_ag_codec_negotiate(p_cn_scb);
-#else
- /* create sco connection to peer */
- bta_ag_create_sco(p_sco->p_xfer_scb, true);
- p_sco->p_xfer_scb = nullptr;
- p_sco->state = BTA_AG_SCO_OPENING_ST;
-#endif
break;
}
diff --git a/system/bta/av/bta_av_main.cc b/system/bta/av/bta_av_main.cc
index 47abb2f79d..9a0215ea50 100644
--- a/system/bta/av/bta_av_main.cc
+++ b/system/bta/av/bta_av_main.cc
@@ -24,7 +24,6 @@
#define LOG_TAG "bt_bta_av"
-#include <base/logging.h>
#include <bluetooth/log.h>
#include <cstdint>
@@ -646,6 +645,7 @@ static void bta_av_api_register(tBTA_AV_DATA* p_data) {
btav_a2dp_codec_index_t codec_index =
static_cast<btav_a2dp_codec_index_t>(i);
if (!bta_av_co_is_supported_codec(codec_index)) {
+ log::warn("Skipping the codec index for codec index {}", i);
continue;
}
if (!(*bta_av_a2dp_cos.init)(codec_index, &avdtp_stream_config.cfg)) {
diff --git a/system/bta/dm/bta_dm_act.cc b/system/bta/dm/bta_dm_act.cc
index 9135769f54..e188bafa87 100644
--- a/system/bta/dm/bta_dm_act.cc
+++ b/system/bta/dm/bta_dm_act.cc
@@ -1076,11 +1076,7 @@ static void bta_dm_set_eir(char* local_name) {
uint8_t custom_uuid_idx;
#endif // BTA_EIR_SERVER_NUM_CUSTOM_UUID
#endif // BTA_EIR_CANNED_UUID_LIST
-#if (BTM_EIR_DEFAULT_FEC_REQUIRED == FALSE)
- uint8_t free_eir_length = HCI_EXT_INQ_RESPONSE_LEN;
-#else // BTM_EIR_DEFAULT_FEC_REQUIRED
uint8_t free_eir_length = HCI_DM5_PACKET_SIZE;
-#endif // BTM_EIR_DEFAULT_FEC_REQUIRED
uint8_t num_uuid;
uint8_t data_type;
uint8_t local_name_len;
diff --git a/system/bta/dm/bta_dm_cfg.cc b/system/bta/dm/bta_dm_cfg.cc
index 509fe6f935..01b474b834 100644
--- a/system/bta/dm/bta_dm_cfg.cc
+++ b/system/bta/dm/bta_dm_cfg.cc
@@ -614,7 +614,6 @@ const tBTM_PM_PWR_MD* p_bta_dm_pm_md = &bta_dm_pm_md[0];
/* The performance impact of EIR packet size
*
- * When BTM_EIR_DEFAULT_FEC_REQUIRED is true,
* 1 to 17 bytes, DM1 is used and most robust.
* 18 to 121 bytes, DM3 is used but impacts inquiry scan time with large number
* of devices.(almost double with 150 users)
@@ -622,14 +621,7 @@ const tBTM_PM_PWR_MD* p_bta_dm_pm_md = &bta_dm_pm_md[0];
* small number of users. so it is not recommended.
* 225 to 240 bytes, DH5 is used without FEC but it not recommended.
* (same reason of DM5)
- *
- * When BTM_EIR_DEFAULT_FEC_REQUIRED is false,
- * 1 to 27 bytes, DH1 is used but only robust at short range.
- * 28 to 183 bytes, DH3 is used but only robust at short range and impacts
- * inquiry
- * scan time with large number of devices.
- * 184 to 240 bytes, DH5 is used but it not recommended.
-*/
+ */
#if (BTA_EIR_CANNED_UUID_LIST == TRUE)
/* for example */
diff --git a/system/bta/dm/bta_dm_int.h b/system/bta/dm/bta_dm_int.h
index 8fcb4ec0f6..f48598cdaf 100644
--- a/system/bta/dm/bta_dm_int.h
+++ b/system/bta/dm/bta_dm_int.h
@@ -317,8 +317,6 @@ void bta_dm_disable();
void bta_dm_set_dev_name(const std::vector<uint8_t>&);
void bta_dm_close_acl(const RawAddress&, bool, tBT_TRANSPORT);
-void bta_dm_pm_btm_status(const RawAddress&, tBTM_PM_STATUS, uint16_t,
- tHCI_STATUS);
void bta_dm_pm_timer(const RawAddress&, tBTA_DM_PM_ACTION);
void bta_dm_ble_set_conn_params(const RawAddress&, uint16_t, uint16_t, uint16_t,
diff --git a/system/bta/dm/bta_dm_pm.cc b/system/bta/dm/bta_dm_pm.cc
index b296db43c6..a09ded2e35 100644
--- a/system/bta/dm/bta_dm_pm.cc
+++ b/system/bta/dm/bta_dm_pm.cc
@@ -58,13 +58,15 @@ static void bta_dm_pm_btm_cback(const RawAddress& bd_addr,
tBTM_PM_STATUS status, uint16_t value,
tHCI_STATUS hci_status);
static bool bta_dm_pm_park(const RawAddress& peer_addr);
-void bta_dm_pm_sniff(tBTA_DM_PEER_DEVICE* p_peer_dev, uint8_t index);
+static void bta_dm_pm_sniff(tBTA_DM_PEER_DEVICE* p_peer_dev, uint8_t index);
static void bta_dm_sniff_cback(uint8_t id, uint8_t app_id,
const RawAddress& peer_addr);
static int bta_dm_get_sco_index();
static void bta_dm_pm_stop_timer_by_index(tBTA_PM_TIMER* p_timer,
uint8_t timer_idx);
+static tBTM_PM_PWR_MD get_sniff_entry(uint8_t index);
+
#include "../hh/bta_hh_int.h"
/* BTA_DM_PM_SSR1 will be dedicated for HH SSR setting entry, no other profile
* can use it */
@@ -790,7 +792,7 @@ static bool bta_dm_pm_park(const RawAddress& peer_addr) {
* Returns tBTM_PM_PWR_MD with specified |index|.
*
******************************************************************************/
-tBTM_PM_PWR_MD get_sniff_entry(uint8_t index) {
+static tBTM_PM_PWR_MD get_sniff_entry(uint8_t index) {
static std::vector<tBTM_PM_PWR_MD> pwr_mds_cache;
if (pwr_mds_cache.size() == BTA_DM_PM_PARK_IDX) {
if (index >= BTA_DM_PM_PARK_IDX) {
@@ -843,7 +845,7 @@ tBTM_PM_PWR_MD get_sniff_entry(uint8_t index) {
* Returns true if sniff attempted, false otherwise.
*
******************************************************************************/
-void bta_dm_pm_sniff(tBTA_DM_PEER_DEVICE* p_peer_dev, uint8_t index) {
+static void bta_dm_pm_sniff(tBTA_DM_PEER_DEVICE* p_peer_dev, uint8_t index) {
tBTM_PM_MODE mode = BTM_PM_MD_ACTIVE;
tBTM_PM_PWR_MD pwr_md;
tBTM_STATUS status;
@@ -1020,6 +1022,10 @@ void bta_dm_pm_active(const RawAddress& peer_addr) {
}
}
+static void bta_dm_pm_btm_status(const RawAddress& bd_addr,
+ tBTM_PM_STATUS status, uint16_t interval,
+ tHCI_STATUS hci_status);
+
/** BTM power manager callback */
static void bta_dm_pm_btm_cback(const RawAddress& bd_addr,
tBTM_PM_STATUS status, uint16_t value,
@@ -1071,8 +1077,9 @@ static void bta_dm_pm_timer_cback(void* data) {
}
/** Process pm status event from btm */
-void bta_dm_pm_btm_status(const RawAddress& bd_addr, tBTM_PM_STATUS status,
- uint16_t interval, tHCI_STATUS hci_status) {
+static void bta_dm_pm_btm_status(const RawAddress& bd_addr,
+ tBTM_PM_STATUS status, uint16_t interval,
+ tHCI_STATUS hci_status) {
log::debug(
"Power mode notification event status:{} peer:{} interval:{} "
"hci_status:{}",
diff --git a/system/bta/hearing_aid/hearing_aid_audio_source.cc b/system/bta/hearing_aid/hearing_aid_audio_source.cc
index e8818e83c3..3c1b038934 100644
--- a/system/bta/hearing_aid/hearing_aid_audio_source.cc
+++ b/system/bta/hearing_aid/hearing_aid_audio_source.cc
@@ -40,8 +40,6 @@ using namespace bluetooth;
namespace fmt {
template <>
-struct formatter<bt_status_t> : enum_formatter<bt_status_t> {};
-template <>
struct formatter<tUIPC_EVENT> : enum_formatter<tUIPC_EVENT> {};
template <>
struct formatter<tHEARING_AID_CTRL_ACK>
diff --git a/system/bta/include/bta_api.h b/system/bta/include/bta_api.h
index 6601f95de9..7abc86d780 100644
--- a/system/bta/include/bta_api.h
+++ b/system/bta/include/bta_api.h
@@ -974,6 +974,8 @@ void DumpsysBtaDm(int fd);
namespace fmt {
template <>
struct formatter<tBTA_DM_SEARCH_EVT> : enum_formatter<tBTA_DM_SEARCH_EVT> {};
+template <>
+struct formatter<tBTA_DM_ACL_EVT> : enum_formatter<tBTA_DM_ACL_EVT> {};
} // namespace fmt
#endif /* BTA_API_H */
diff --git a/system/bta/include/bta_api_data_types.h b/system/bta/include/bta_api_data_types.h
index daa502608c..aa41dd397f 100644
--- a/system/bta/include/bta_api_data_types.h
+++ b/system/bta/include/bta_api_data_types.h
@@ -19,6 +19,7 @@
#pragma once
#include <base/strings/stringprintf.h>
+#include <bluetooth/log.h>
#include <cstdint>
#include <string>
@@ -61,3 +62,8 @@ typedef struct {
typedef struct {
RawAddress bd_addr;
} tBTA_DM_KEY_MISSING;
+
+namespace fmt {
+template <>
+struct formatter<tBTA_STATUS> : enum_formatter<tBTA_STATUS> {};
+} // namespace fmt
diff --git a/system/bta/include/bta_jv_api.h b/system/bta/include/bta_jv_api.h
index 6bb30d9f0a..dcf1995bc4 100644
--- a/system/bta/include/bta_jv_api.h
+++ b/system/bta/include/bta_jv_api.h
@@ -26,10 +26,12 @@
#include <cstdint>
#include <memory>
+#include <string>
#include "bta/include/bta_api.h"
#include "bta_sec_api.h"
#include "internal_include/bt_target.h"
+#include "macros.h"
#include "stack/include/bt_hdr.h"
#include "stack/include/l2c_api.h"
#include "types/bluetooth/uuid.h"
@@ -38,14 +40,20 @@
/*****************************************************************************
* Constants and data types
****************************************************************************/
-/* status values */
-#define BTA_JV_SUCCESS 0 /* Successful operation. */
-#define BTA_JV_FAILURE 1 /* Generic failure. */
-#define BTA_JV_BUSY 2 /* Temporarily can not handle this request. */
-#define BTA_JV_NO_DATA 3 /* no data. */
-#define BTA_JV_NO_RESOURCE 4 /* No more set pm control block */
-
-typedef uint8_t tBTA_JV_STATUS;
+enum class tBTA_JV_STATUS {
+ SUCCESS = 0, /* Successful operation. */
+ FAILURE = 1, /* Generic failure. */
+ BUSY = 2, /* Temporarily can not handle this request. */
+};
+
+inline std::string bta_jv_status_text(const tBTA_JV_STATUS& status) {
+ switch (status) {
+ CASE_RETURN_TEXT(tBTA_JV_STATUS::SUCCESS);
+ CASE_RETURN_TEXT(tBTA_JV_STATUS::FAILURE);
+ CASE_RETURN_TEXT(tBTA_JV_STATUS::BUSY);
+ }
+}
+
#define BTA_JV_INTERNAL_ERR (-1) /* internal error. */
/* L2CAP errors from underlying layers propagated via callbacks. */
diff --git a/system/bta/include/bta_sec_api.h b/system/bta/include/bta_sec_api.h
index 109fa94e86..9b3ae1f8ae 100644
--- a/system/bta/include/bta_sec_api.h
+++ b/system/bta/include/bta_sec_api.h
@@ -20,6 +20,7 @@
#include <base/functional/callback.h>
#include <base/strings/stringprintf.h>
+#include <bluetooth/log.h>
#include <cstdint>
@@ -495,3 +496,8 @@ void BTA_DmSirkSecCbRegister(tBTA_DM_SEC_CBACK* p_cback);
*
******************************************************************************/
void BTA_DmSirkConfirmDeviceReply(const RawAddress& bd_addr, bool accept);
+
+namespace fmt {
+template <>
+struct formatter<tBTA_DM_SEC_EVT> : enum_formatter<tBTA_DM_SEC_EVT> {};
+} // namespace fmt
diff --git a/system/bta/jv/bta_jv_act.cc b/system/bta/jv/bta_jv_act.cc
index 1f97702fa9..e97481362e 100644
--- a/system/bta/jv/bta_jv_act.cc
+++ b/system/bta/jv/bta_jv_act.cc
@@ -37,6 +37,7 @@
#include "bta/sys/bta_sys.h"
#include "internal_include/bt_target.h"
#include "internal_include/bt_trace.h"
+#include "os/logging/log_adapter.h"
#include "osi/include/allocator.h"
#include "osi/include/osi.h" // UNUSED_ATTR
#include "osi/include/properties.h"
@@ -296,20 +297,20 @@ tBTA_JV_RFC_CB* bta_jv_rfc_port_to_cb(uint16_t port_handle) {
static tBTA_JV_STATUS bta_jv_free_rfc_cb(tBTA_JV_RFC_CB* p_cb,
tBTA_JV_PCB* p_pcb) {
- tBTA_JV_STATUS status = BTA_JV_SUCCESS;
+ tBTA_JV_STATUS status = tBTA_JV_STATUS::SUCCESS;
bool remove_server = false;
int close_pending = 0;
if (!p_cb || !p_pcb) {
log::error("p_cb or p_pcb cannot be null");
- return BTA_JV_FAILURE;
+ return tBTA_JV_STATUS::FAILURE;
}
log::verbose(
"max_sess={}, curr_sess={}, p_pcb={}, user={}, state={}, jv handle={}",
p_cb->max_sess, p_cb->curr_sess, fmt::ptr(p_pcb), p_pcb->rfcomm_slot_id,
p_pcb->state, loghex(p_pcb->handle));
- if (p_cb->curr_sess <= 0) return BTA_JV_SUCCESS;
+ if (p_cb->curr_sess <= 0) return tBTA_JV_STATUS::SUCCESS;
switch (p_pcb->state) {
case BTA_JV_ST_CL_CLOSING:
@@ -317,7 +318,7 @@ static tBTA_JV_STATUS bta_jv_free_rfc_cb(tBTA_JV_RFC_CB* p_cb,
log::warn(
"return on closing, port state={}, scn={}, p_pcb={}, user_data={}",
p_pcb->state, p_cb->scn, fmt::ptr(p_pcb), p_pcb->rfcomm_slot_id);
- status = BTA_JV_FAILURE;
+ status = tBTA_JV_STATUS::FAILURE;
return status;
case BTA_JV_ST_CL_OPEN:
case BTA_JV_ST_CL_OPENING:
@@ -342,10 +343,10 @@ static tBTA_JV_STATUS bta_jv_free_rfc_cb(tBTA_JV_RFC_CB* p_cb,
"port_handle={}, user_data={}",
p_pcb->state, p_cb->scn, fmt::ptr(p_pcb), loghex(p_pcb->handle),
p_pcb->port_handle, p_pcb->rfcomm_slot_id);
- status = BTA_JV_FAILURE;
+ status = tBTA_JV_STATUS::FAILURE;
break;
}
- if (BTA_JV_SUCCESS == status) {
+ if (tBTA_JV_STATUS::SUCCESS == status) {
int port_status;
if (!remove_server)
@@ -353,7 +354,7 @@ static tBTA_JV_STATUS bta_jv_free_rfc_cb(tBTA_JV_RFC_CB* p_cb,
else
port_status = RFCOMM_RemoveServer(p_pcb->port_handle);
if (port_status != PORT_SUCCESS) {
- status = BTA_JV_FAILURE;
+ status = tBTA_JV_STATUS::FAILURE;
log::warn(
"Remove jv handle={}, state={}, port_status={}, port_handle={}, "
"close_pending={}",
@@ -393,11 +394,12 @@ static tBTA_JV_STATUS bta_jv_free_rfc_cb(tBTA_JV_RFC_CB* p_cb,
*
******************************************************************************/
tBTA_JV_STATUS bta_jv_free_l2c_cb(tBTA_JV_L2C_CB* p_cb) {
- tBTA_JV_STATUS status = BTA_JV_SUCCESS;
+ tBTA_JV_STATUS status = tBTA_JV_STATUS::SUCCESS;
if (BTA_JV_ST_NONE != p_cb->state) {
bta_jv_free_set_pm_profile_cb((uint32_t)p_cb->handle);
- if (GAP_ConnClose(p_cb->handle) != BT_PASS) status = BTA_JV_FAILURE;
+ if (GAP_ConnClose(p_cb->handle) != BT_PASS)
+ status = tBTA_JV_STATUS::FAILURE;
}
p_cb->psm = 0;
p_cb->state = BTA_JV_ST_NONE;
@@ -440,13 +442,13 @@ static void bta_jv_clear_pm_cb(tBTA_JV_PM_CB* p_pm_cb, bool close_conn) {
*
* Description free pm profile control block
*
- * Returns BTA_JV_SUCCESS if cb has been freed correctly,
- * BTA_JV_FAILURE in case of no profile has been registered or
- * already freed
+ * Returns tBTA_JV_STATUS::SUCCESS if cb has been freed correctly,
+ * tBTA_JV_STATUS::FAILURE in case of no profile has been registered
+ * or already freed
*
******************************************************************************/
static tBTA_JV_STATUS bta_jv_free_set_pm_profile_cb(uint32_t jv_handle) {
- tBTA_JV_STATUS status = BTA_JV_FAILURE;
+ tBTA_JV_STATUS status = tBTA_JV_STATUS::FAILURE;
tBTA_JV_PM_CB** p_cb;
int i, j, bd_counter = 0, appid_counter = 0;
@@ -502,7 +504,7 @@ static tBTA_JV_STATUS bta_jv_free_set_pm_profile_cb(uint32_t jv_handle) {
}
if (p_cb) {
*p_cb = NULL;
- status = BTA_JV_SUCCESS;
+ status = tBTA_JV_STATUS::SUCCESS;
}
}
}
@@ -633,11 +635,13 @@ bool bta_jv_check_psm(uint16_t psm) {
/* Initialises the JAVA I/F */
void bta_jv_enable(tBTA_JV_DM_CBACK* p_cback) {
- tBTA_JV_STATUS status = BTA_JV_SUCCESS;
bta_jv_cb.p_dm_cback = p_cback;
- tBTA_JV bta_jv;
- bta_jv.status = status;
- bta_jv_cb.p_dm_cback(BTA_JV_ENABLE_EVT, &bta_jv, 0);
+ if (bta_jv_cb.p_dm_cback) {
+ tBTA_JV bta_jv = {
+ .status = tBTA_JV_STATUS::SUCCESS,
+ };
+ bta_jv_cb.p_dm_cback(BTA_JV_ENABLE_EVT, &bta_jv, 0);
+ }
memset(bta_jv_cb.free_psm_list, 0, sizeof(bta_jv_cb.free_psm_list));
memset(bta_jv_cb.scn_in_use, 0, sizeof(bta_jv_cb.scn_in_use));
bta_jv_cb.scn_search_index = 1;
@@ -794,95 +798,157 @@ void bta_jv_free_scn(int32_t type /* One of BTA_JV_CONN_TYPE_ */,
static void bta_jv_start_discovery_cback(UNUSED_ATTR const RawAddress& bd_addr,
tSDP_RESULT result,
const void* user_data) {
- tBTA_JV_STATUS status;
- uint32_t* p_rfcomm_slot_id =
- static_cast<uint32_t*>(const_cast<void*>(user_data));
-
- log::verbose("res={}", loghex(static_cast<uint16_t>(result)));
+ if (!bta_jv_cb.sdp_cb.sdp_active) {
+ log::warn(
+ "Received unexpected service discovery callback bd_addr:{} result:{}",
+ ADDRESS_TO_LOGGABLE_CSTR(bd_addr), sdp_result_text(result),
+ bta_jv_cb.sdp_cb.sdp_active);
+ }
+ if (bta_jv_cb.sdp_cb.bd_addr != bta_jv_cb.sdp_cb.bd_addr) {
+ log::warn(
+ "Received incorrect service discovery callback expected_bd_addr:{} "
+ "actual_bd_addr:{} result:{}",
+ ADDRESS_TO_LOGGABLE_CSTR(bta_jv_cb.sdp_cb.bd_addr),
+ ADDRESS_TO_LOGGABLE_CSTR(bd_addr), sdp_result_text(result),
+ bta_jv_cb.sdp_cb.sdp_active);
+ }
- bta_jv_cb.sdp_active = BTA_JV_SDP_ACT_NONE;
if (bta_jv_cb.p_dm_cback) {
- tBTA_JV_DISCOVERY_COMP dcomp;
- dcomp.scn = 0;
- status = BTA_JV_FAILURE;
+ const uint32_t rfcomm_slot_id = *static_cast<const uint32_t*>(user_data);
+ tBTA_JV bta_jv = {
+ .disc_comp =
+ {
+ .status = tBTA_JV_STATUS::FAILURE,
+ .scn = 0,
+ },
+ };
if (result == SDP_SUCCESS || result == SDP_DB_FULL) {
- tSDP_DISC_REC* p_sdp_rec = NULL;
+ log::info(
+ "Received service discovery callback success bd_addr:{} result:{}",
+ ADDRESS_TO_LOGGABLE_CSTR(bd_addr), sdp_result_text(result));
tSDP_PROTOCOL_ELEM pe;
- log::verbose("bta_jv_cb.uuid={}", bta_jv_cb.uuid);
+ tSDP_DISC_REC* p_sdp_rec = NULL;
p_sdp_rec = get_legacy_stack_sdp_api()->db.SDP_FindServiceUUIDInDb(
- p_bta_jv_cfg->p_sdp_db, bta_jv_cb.uuid, p_sdp_rec);
- log::verbose("p_sdp_rec={}", fmt::ptr(p_sdp_rec));
+ p_bta_jv_cfg->p_sdp_db, bta_jv_cb.sdp_cb.uuid, p_sdp_rec);
+ log::verbose("bta_jv_cb.uuid={} p_sdp_rec={}", bta_jv_cb.sdp_cb.uuid,
+ fmt::ptr(p_sdp_rec));
if (p_sdp_rec &&
get_legacy_stack_sdp_api()->record.SDP_FindProtocolListElemInRec(
p_sdp_rec, UUID_PROTOCOL_RFCOMM, &pe)) {
- dcomp.scn = (uint8_t)pe.params[0];
- status = BTA_JV_SUCCESS;
+ bta_jv = {
+ .disc_comp =
+ {
+ .status = tBTA_JV_STATUS::SUCCESS,
+ .scn = (uint8_t)pe.params[0],
+ },
+ };
}
+ } else {
+ log::warn(
+ "Received service discovery callback failed bd_addr:{} result:{}",
+ ADDRESS_TO_LOGGABLE_CSTR(bd_addr), sdp_result_text(result));
}
-
- dcomp.status = status;
- tBTA_JV bta_jv;
- bta_jv.disc_comp = dcomp;
- bta_jv_cb.p_dm_cback(BTA_JV_DISCOVERY_COMP_EVT, &bta_jv, *p_rfcomm_slot_id);
- osi_free(p_rfcomm_slot_id);
- }
+ log::info(
+ "Issuing service discovery complete callback bd_addr:{} result:{} "
+ "status:{} scn:{}",
+ ADDRESS_TO_LOGGABLE_CSTR(bd_addr), sdp_result_text(result),
+ bta_jv_status_text(bta_jv.disc_comp.status), bta_jv.disc_comp.scn);
+ bta_jv_cb.p_dm_cback(BTA_JV_DISCOVERY_COMP_EVT, &bta_jv, rfcomm_slot_id);
+ } else {
+ log::warn(
+ "Received service discovery callback when disabled bd_addr:{} "
+ "result:{}",
+ ADDRESS_TO_LOGGABLE_CSTR(bd_addr), sdp_result_text(result));
+ }
+ // User data memory is allocated in `bta_jv_start_discovery`
+ osi_free(const_cast<void*>(user_data));
+ bta_jv_cb.sdp_cb = {};
}
/* Discovers services on a remote device */
void bta_jv_start_discovery(const RawAddress& bd_addr, uint16_t num_uuid,
bluetooth::Uuid* uuid_list,
uint32_t rfcomm_slot_id) {
- tBTA_JV_STATUS status = BTA_JV_FAILURE;
- log::verbose("in, sdp_active={}", bta_jv_cb.sdp_active);
- if (bta_jv_cb.sdp_active != BTA_JV_SDP_ACT_NONE) {
- /* SDP is still in progress */
- status = BTA_JV_BUSY;
+ ASSERT(uuid_list != nullptr);
+ if (bta_jv_cb.sdp_cb.sdp_active) {
+ log::warn(
+ "Unable to start discovery as already in progress active_bd_addr{} "
+ "request_bd_addr:{} "
+ "num:uuid:{} rfcomm_slot_id:{}",
+ ADDRESS_TO_LOGGABLE_CSTR(bta_jv_cb.sdp_cb.bd_addr),
+ ADDRESS_TO_LOGGABLE_CSTR(bd_addr), num_uuid, rfcomm_slot_id);
if (bta_jv_cb.p_dm_cback) {
- tBTA_JV bta_jv;
- bta_jv.status = status;
+ tBTA_JV bta_jv = {
+ .status = tBTA_JV_STATUS::BUSY,
+ };
bta_jv_cb.p_dm_cback(BTA_JV_DISCOVERY_COMP_EVT, &bta_jv, rfcomm_slot_id);
+ } else {
+ log::warn(
+ "bta::jv module DISABLED so unable to inform caller service "
+ "discovery is "
+ "unavailable");
}
return;
}
/* init the database/set up the filter */
- log::verbose("call SDP_InitDiscoveryDb, num_uuid={}", num_uuid);
- get_legacy_stack_sdp_api()->service.SDP_InitDiscoveryDb(
- p_bta_jv_cfg->p_sdp_db, p_bta_jv_cfg->sdp_db_size, num_uuid, uuid_list, 0,
- NULL);
+ if (!get_legacy_stack_sdp_api()->service.SDP_InitDiscoveryDb(
+ p_bta_jv_cfg->p_sdp_db, p_bta_jv_cfg->sdp_db_size, num_uuid,
+ uuid_list, 0, NULL)) {
+ log::warn(
+ "Unable to initialize service discovery db bd_addr:{} num:uuid:{} "
+ "rfcomm_slot_id:{}",
+ ADDRESS_TO_LOGGABLE_CSTR(bd_addr), num_uuid, rfcomm_slot_id);
+ }
/* tell SDP to keep the raw data */
p_bta_jv_cfg->p_sdp_db->raw_data = p_bta_jv_cfg->p_sdp_raw_data;
p_bta_jv_cfg->p_sdp_db->raw_size = p_bta_jv_cfg->sdp_raw_size;
bta_jv_cb.p_sel_raw_data = 0;
- bta_jv_cb.uuid = uuid_list[0];
- bta_jv_cb.sdp_active = BTA_JV_SDP_ACT_YES;
+ // Optimistically set this as active
+ bta_jv_cb.sdp_cb = {
+ .sdp_active = true,
+ .bd_addr = bd_addr,
+ .uuid = uuid_list[0],
+ };
+ // NOTE: This gets freed on the callback or when discovery failed to start
uint32_t* rfcomm_slot_id_copy = (uint32_t*)osi_malloc(sizeof(uint32_t));
*rfcomm_slot_id_copy = rfcomm_slot_id;
+ // user_data memory is freed in `bta_jv_start_discovery_cback` callback
if (!get_legacy_stack_sdp_api()->service.SDP_ServiceSearchAttributeRequest2(
bd_addr, p_bta_jv_cfg->p_sdp_db, bta_jv_start_discovery_cback,
- (void*)rfcomm_slot_id_copy)) {
- bta_jv_cb.sdp_active = BTA_JV_SDP_ACT_NONE;
+ (const void*)rfcomm_slot_id_copy)) {
+ bta_jv_cb.sdp_cb = {};
+ osi_free(rfcomm_slot_id_copy);
+ log::warn(
+ "Unable to original service discovery bd_addr:{} num:uuid:{} "
+ "rfcomm_slot_id:{}",
+ ADDRESS_TO_LOGGABLE_CSTR(bd_addr), num_uuid, rfcomm_slot_id);
/* failed to start SDP. report the failure right away */
if (bta_jv_cb.p_dm_cback) {
- tBTA_JV bta_jv;
- bta_jv.status = status;
+ tBTA_JV bta_jv = {
+ .status = tBTA_JV_STATUS::FAILURE,
+ };
bta_jv_cb.p_dm_cback(BTA_JV_DISCOVERY_COMP_EVT, &bta_jv, rfcomm_slot_id);
+ } else {
+ log::warn("No callback set for discovery complete event");
}
+ } else {
+ log::info(
+ "Started service discovery bd_addr:{} num_uuid:{} "
+ "rfcomm_slot_id:{}",
+ ADDRESS_TO_LOGGABLE_CSTR(bd_addr), num_uuid, rfcomm_slot_id);
}
- /*
- else report the result when the cback is called
- */
}
/* Create an SDP record with the given attributes */
void bta_jv_create_record(uint32_t rfcomm_slot_id) {
tBTA_JV_CREATE_RECORD evt_data;
- evt_data.status = BTA_JV_SUCCESS;
+ evt_data.status = tBTA_JV_STATUS::SUCCESS;
if (bta_jv_cb.p_dm_cback) {
// callback immediately to create the sdp record in stack thread context
tBTA_JV bta_jv;
@@ -916,7 +982,7 @@ static void bta_jv_l2cap_client_cback(uint16_t gap_handle, uint16_t event,
if (gap_handle >= BTA_JV_MAX_L2C_CONN && !p_cb->p_cback) return;
log::verbose("gap_handle={}, evt={}", gap_handle, loghex(event));
- evt_data.l2c_open.status = BTA_JV_SUCCESS;
+ evt_data.l2c_open.status = tBTA_JV_STATUS::SUCCESS;
evt_data.l2c_open.handle = gap_handle;
switch (event) {
@@ -987,7 +1053,7 @@ void bta_jv_l2cap_connect(int32_t type, tBTA_SEC sec_mask,
uint8_t sec_id = bta_jv_alloc_sec_id();
tBTA_JV_L2CAP_CL_INIT evt_data;
evt_data.sec_id = sec_id;
- evt_data.status = BTA_JV_FAILURE;
+ evt_data.status = tBTA_JV_STATUS::FAILURE;
if (sec_id) {
/* PSM checking is not required for LE COC */
@@ -999,12 +1065,12 @@ void bta_jv_l2cap_connect(int32_t type, tBTA_SEC sec_mask,
&cfg, ertm_info.get(), sec_mask,
bta_jv_l2cap_client_cback, type);
if (handle != GAP_INVALID_HANDLE) {
- evt_data.status = BTA_JV_SUCCESS;
+ evt_data.status = tBTA_JV_STATUS::SUCCESS;
}
}
}
- if (evt_data.status == BTA_JV_SUCCESS) {
+ if (evt_data.status == tBTA_JV_STATUS::SUCCESS) {
tBTA_JV_L2C_CB* p_cb;
p_cb = &bta_jv_cb.l2c_cb[handle];
p_cb->handle = handle;
@@ -1061,7 +1127,7 @@ static void bta_jv_l2cap_server_cback(uint16_t gap_handle, uint16_t event,
if (gap_handle >= BTA_JV_MAX_L2C_CONN && !p_cb->p_cback) return;
log::verbose("gap_handle={}, evt={}", gap_handle, loghex(event));
- evt_data.l2c_open.status = BTA_JV_SUCCESS;
+ evt_data.l2c_open.status = tBTA_JV_STATUS::SUCCESS;
evt_data.l2c_open.handle = gap_handle;
switch (event) {
@@ -1142,10 +1208,10 @@ void bta_jv_l2cap_start_server(int32_t type, tBTA_SEC sec_mask,
bta_jv_l2cap_server_cback, type)) ==
GAP_INVALID_HANDLE) {
bta_jv_free_sec_id(&sec_id);
- evt_data.status = BTA_JV_FAILURE;
+ evt_data.status = tBTA_JV_STATUS::FAILURE;
} else {
tBTA_JV_L2C_CB* p_cb = &bta_jv_cb.l2c_cb[handle];
- evt_data.status = BTA_JV_SUCCESS;
+ evt_data.status = tBTA_JV_STATUS::SUCCESS;
evt_data.handle = handle;
evt_data.sec_id = sec_id;
p_cb->p_cback = p_cback;
@@ -1212,7 +1278,7 @@ void bta_jv_l2cap_write(uint32_t handle, uint32_t req_id, BT_HDR* msg,
}
tBTA_JV_L2CAP_WRITE evt_data;
- evt_data.status = BTA_JV_FAILURE;
+ evt_data.status = tBTA_JV_STATUS::FAILURE;
evt_data.handle = handle;
evt_data.req_id = req_id;
evt_data.cong = p_cb->cong;
@@ -1227,7 +1293,7 @@ void bta_jv_l2cap_write(uint32_t handle, uint32_t req_id, BT_HDR* msg,
osi_free(msg);
} else {
if (GAP_ConnWriteData(handle, msg) == BT_PASS)
- evt_data.status = BTA_JV_SUCCESS;
+ evt_data.status = tBTA_JV_STATUS::SUCCESS;
}
tBTA_JV bta_jv;
@@ -1300,13 +1366,13 @@ static void bta_jv_port_mgmt_cl_cback(uint32_t code, uint16_t port_handle) {
if (code == PORT_SUCCESS) {
evt_data.rfc_open.handle = p_cb->handle;
- evt_data.rfc_open.status = BTA_JV_SUCCESS;
+ evt_data.rfc_open.status = tBTA_JV_STATUS::SUCCESS;
evt_data.rfc_open.rem_bda = rem_bda;
p_pcb->state = BTA_JV_ST_CL_OPEN;
p_cb->p_cback(BTA_JV_RFCOMM_OPEN_EVT, &evt_data, p_pcb->rfcomm_slot_id);
} else {
evt_data.rfc_close.handle = p_cb->handle;
- evt_data.rfc_close.status = BTA_JV_FAILURE;
+ evt_data.rfc_close.status = tBTA_JV_STATUS::FAILURE;
evt_data.rfc_close.port_status = code;
evt_data.rfc_close.async = true;
if (p_pcb->state == BTA_JV_ST_CL_CLOSING) {
@@ -1348,7 +1414,7 @@ static void bta_jv_port_event_cl_cback(uint32_t code, uint16_t port_handle) {
p_pcb->cong = (code & PORT_EV_FCS) ? false : true;
evt_data.rfc_cong.cong = p_pcb->cong;
evt_data.rfc_cong.handle = p_cb->handle;
- evt_data.rfc_cong.status = BTA_JV_SUCCESS;
+ evt_data.rfc_cong.status = tBTA_JV_STATUS::SUCCESS;
p_cb->p_cback(BTA_JV_RFCOMM_CONG_EVT, &evt_data, p_pcb->rfcomm_slot_id);
}
@@ -1368,7 +1434,7 @@ void bta_jv_rfcomm_connect(tBTA_SEC sec_mask, uint8_t remote_scn,
tBTA_JV_RFCOMM_CL_INIT evt_data;
memset(&evt_data, 0, sizeof(evt_data));
- evt_data.status = BTA_JV_SUCCESS;
+ evt_data.status = tBTA_JV_STATUS::SUCCESS;
#ifdef TARGET_FLOSS
if (true)
@@ -1384,15 +1450,15 @@ void bta_jv_rfcomm_connect(tBTA_SEC sec_mask, uint8_t remote_scn,
BTM_SEC_PROTO_RFCOMM, 0);
}
- if (evt_data.status == BTA_JV_SUCCESS &&
+ if (evt_data.status == tBTA_JV_STATUS::SUCCESS &&
RFCOMM_CreateConnectionWithSecurity(
UUID_SERVCLASS_SERIAL_PORT, remote_scn, false, BTA_JV_DEF_RFC_MTU,
peer_bd_addr, &handle, bta_jv_port_mgmt_cl_cback,
sec_mask) != PORT_SUCCESS) {
log::error("RFCOMM_CreateConnection failed");
- evt_data.status = BTA_JV_FAILURE;
+ evt_data.status = tBTA_JV_STATUS::FAILURE;
}
- if (evt_data.status == BTA_JV_SUCCESS) {
+ if (evt_data.status == tBTA_JV_STATUS::SUCCESS) {
tBTA_JV_PCB* p_pcb;
tBTA_JV_RFC_CB* p_cb = bta_jv_alloc_rfc_cb(handle, &p_pcb);
if (p_cb) {
@@ -1414,14 +1480,14 @@ void bta_jv_rfcomm_connect(tBTA_SEC sec_mask, uint8_t remote_scn,
evt_data.handle = p_cb->handle;
} else {
- evt_data.status = BTA_JV_FAILURE;
+ evt_data.status = tBTA_JV_STATUS::FAILURE;
log::error("run out of rfc control block");
}
}
tBTA_JV bta_jv;
bta_jv.rfc_cl_init = evt_data;
p_cback(BTA_JV_RFCOMM_CL_INIT_EVT, &bta_jv, rfcomm_slot_id);
- if (bta_jv.rfc_cl_init.status == BTA_JV_FAILURE) {
+ if (bta_jv.rfc_cl_init.status == tBTA_JV_STATUS::FAILURE) {
if (handle) RFCOMM_RemoveConnection(handle);
}
}
@@ -1502,7 +1568,7 @@ static void bta_jv_port_mgmt_sr_cback(uint32_t code, uint16_t port_handle) {
status);
}
evt_data.rfc_srv_open.handle = p_pcb->handle;
- evt_data.rfc_srv_open.status = BTA_JV_SUCCESS;
+ evt_data.rfc_srv_open.status = tBTA_JV_STATUS::SUCCESS;
evt_data.rfc_srv_open.rem_bda = rem_bda;
tBTA_JV_PCB* p_pcb_new_listen = bta_jv_add_rfc_port(p_cb, p_pcb);
if (p_pcb_new_listen) {
@@ -1517,7 +1583,7 @@ static void bta_jv_port_mgmt_sr_cback(uint32_t code, uint16_t port_handle) {
}
if (failed) {
evt_data.rfc_close.handle = p_cb->handle;
- evt_data.rfc_close.status = BTA_JV_FAILURE;
+ evt_data.rfc_close.status = tBTA_JV_STATUS::FAILURE;
evt_data.rfc_close.async = true;
evt_data.rfc_close.port_status = code;
p_pcb->cong = false;
@@ -1528,7 +1594,7 @@ static void bta_jv_port_mgmt_sr_cback(uint32_t code, uint16_t port_handle) {
p_cb->curr_sess, p_cb->max_sess);
if (BTA_JV_ST_SR_CLOSING == p_pcb->state) {
evt_data.rfc_close.async = false;
- evt_data.rfc_close.status = BTA_JV_SUCCESS;
+ evt_data.rfc_close.status = tBTA_JV_STATUS::SUCCESS;
}
// p_pcb->state = BTA_JV_ST_NONE;
p_cback(BTA_JV_RFCOMM_CLOSE_EVT, &evt_data, rfcomm_slot_id);
@@ -1573,7 +1639,7 @@ static void bta_jv_port_event_sr_cback(uint32_t code, uint16_t port_handle) {
p_pcb->cong = (code & PORT_EV_FCS) ? false : true;
evt_data.rfc_cong.cong = p_pcb->cong;
evt_data.rfc_cong.handle = p_cb->handle;
- evt_data.rfc_cong.status = BTA_JV_SUCCESS;
+ evt_data.rfc_cong.status = tBTA_JV_STATUS::SUCCESS;
p_cb->p_cback(BTA_JV_RFCOMM_CONG_EVT, &evt_data, user_data);
}
@@ -1682,7 +1748,7 @@ void bta_jv_rfcomm_start_server(tBTA_SEC sec_mask, uint8_t local_scn,
tBTA_JV_RFCOMM_START evt_data;
memset(&evt_data, 0, sizeof(evt_data));
- evt_data.status = BTA_JV_FAILURE;
+ evt_data.status = tBTA_JV_STATUS::FAILURE;
do {
if (RFCOMM_CreateConnectionWithSecurity(
@@ -1703,7 +1769,7 @@ void bta_jv_rfcomm_start_server(tBTA_SEC sec_mask, uint8_t local_scn,
p_cb->scn = local_scn;
p_pcb->state = BTA_JV_ST_SR_LISTEN;
p_pcb->rfcomm_slot_id = rfcomm_slot_id;
- evt_data.status = BTA_JV_SUCCESS;
+ evt_data.status = tBTA_JV_STATUS::SUCCESS;
evt_data.handle = p_cb->handle;
evt_data.use_co = true;
@@ -1720,7 +1786,7 @@ void bta_jv_rfcomm_start_server(tBTA_SEC sec_mask, uint8_t local_scn,
tBTA_JV bta_jv;
bta_jv.rfc_start = evt_data;
p_cback(BTA_JV_RFCOMM_START_EVT, &bta_jv, rfcomm_slot_id);
- if (bta_jv.rfc_start.status == BTA_JV_SUCCESS) {
+ if (bta_jv.rfc_start.status == tBTA_JV_STATUS::SUCCESS) {
PORT_SetDataCOCallback(handle, bta_jv_port_data_co_cback);
} else {
if (handle) RFCOMM_RemoveConnection(handle);
@@ -1753,7 +1819,7 @@ void bta_jv_rfcomm_write(uint32_t handle, uint32_t req_id, tBTA_JV_RFC_CB* p_cb,
}
tBTA_JV_RFCOMM_WRITE evt_data;
- evt_data.status = BTA_JV_FAILURE;
+ evt_data.status = tBTA_JV_STATUS::FAILURE;
evt_data.handle = handle;
evt_data.req_id = req_id;
evt_data.cong = p_pcb->cong;
@@ -1763,7 +1829,7 @@ void bta_jv_rfcomm_write(uint32_t handle, uint32_t req_id, tBTA_JV_RFC_CB* p_cb,
if (!evt_data.cong &&
PORT_WriteDataCO(p_pcb->port_handle, &evt_data.len) == PORT_SUCCESS) {
- evt_data.status = BTA_JV_SUCCESS;
+ evt_data.status = tBTA_JV_STATUS::SUCCESS;
}
// Update congestion flag
@@ -1792,8 +1858,8 @@ void bta_jv_set_pm_profile(uint32_t handle, tBTA_JV_PM_ID app_id,
if (app_id == BTA_JV_PM_ID_CLEAR) {
status = bta_jv_free_set_pm_profile_cb(handle);
- if (status != BTA_JV_SUCCESS) {
- log::warn("free pm cb failed: reason={}", status);
+ if (status != tBTA_JV_STATUS::SUCCESS) {
+ log::warn("free pm cb failed: reason={}", bta_jv_status_text(status));
}
} else /* set PM control block */
{
@@ -1914,3 +1980,12 @@ static void bta_jv_reset_sniff_timer(tBTA_JV_PM_CB* p_cb) {
}
}
/******************************************************************************/
+
+namespace bluetooth::legacy::testing {
+
+void bta_jv_start_discovery_cback(const RawAddress& bd_addr, tSDP_RESULT result,
+ const void* user_data) {
+ ::bta_jv_start_discovery_cback(bd_addr, result, user_data);
+}
+
+} // namespace bluetooth::legacy::testing
diff --git a/system/bta/jv/bta_jv_api.cc b/system/bta/jv/bta_jv_api.cc
index d8cc9dbb58..bafe77b4c7 100644
--- a/system/bta/jv/bta_jv_api.cc
+++ b/system/bta/jv/bta_jv_api.cc
@@ -60,15 +60,15 @@ bool bta_jv_enabled = false;
* be called before other function in the JV API are
* called.
*
- * Returns BTA_JV_SUCCESS if successful.
- * BTA_JV_FAIL if internal failure.
+ * Returns tBTA_JV_STATUS::SUCCESS if successful.
+ * tBTA_JV_STATUS::FAILURE if internal failure.
*
******************************************************************************/
tBTA_JV_STATUS BTA_JvEnable(tBTA_JV_DM_CBACK* p_cback) {
log::verbose("");
if (!p_cback || bta_jv_enabled) {
log::error("failure");
- return BTA_JV_FAILURE;
+ return tBTA_JV_STATUS::FAILURE;
}
memset(&bta_jv_cb, 0, sizeof(tBTA_JV_CB));
@@ -82,7 +82,7 @@ tBTA_JV_STATUS BTA_JvEnable(tBTA_JV_DM_CBACK* p_cback) {
bta_jv_enabled = true;
do_in_main_thread(FROM_HERE, Bind(&bta_jv_enable, p_cback));
- return BTA_JV_SUCCESS;
+ return tBTA_JV_STATUS::SUCCESS;
}
/** Disable the Java I/F */
@@ -139,15 +139,15 @@ void BTA_JvGetChannelId(int conn_type, uint32_t id, int32_t channel) {
* channel The channel to free
* conn_type one of BTA_JV_CONN_TYPE_
*
- * Returns BTA_JV_SUCCESS, if the request is being processed.
- * BTA_JV_FAILURE, otherwise.
+ * Returns tBTA_JV_STATUS::SUCCESS, if the request is being processed.
+ * tBTA_JV_STATUS::FAILURE, otherwise.
*
******************************************************************************/
tBTA_JV_STATUS BTA_JvFreeChannel(uint16_t channel, int conn_type) {
log::verbose("channel:{}, conn_type:{}", channel, conn_type);
do_in_main_thread(FROM_HERE, Bind(&bta_jv_free_scn, conn_type, channel));
- return BTA_JV_SUCCESS;
+ return tBTA_JV_STATUS::SUCCESS;
}
/*******************************************************************************
@@ -159,8 +159,8 @@ tBTA_JV_STATUS BTA_JvFreeChannel(uint16_t channel, int conn_type) {
* complete the tBTA_JV_DM_CBACK callback function will be
* called with a BTA_JV_DISCOVERY_COMP_EVT.
*
- * Returns BTA_JV_SUCCESS, if the request is being processed.
- * BTA_JV_FAILURE, otherwise.
+ * Returns tBTA_JV_STATUS::SUCCESS, if the request is being processed.
+ * tBTA_JV_STATUS::FAILURE, otherwise.
*
******************************************************************************/
tBTA_JV_STATUS BTA_JvStartDiscovery(const RawAddress& bd_addr,
@@ -175,7 +175,7 @@ tBTA_JV_STATUS BTA_JvStartDiscovery(const RawAddress& bd_addr,
do_in_main_thread(FROM_HERE,
Bind(&bta_jv_start_discovery, bd_addr, num_uuid,
base::Owned(uuid_list_copy), rfcomm_slot_id));
- return BTA_JV_SUCCESS;
+ return tBTA_JV_STATUS::SUCCESS;
}
/*******************************************************************************
@@ -186,15 +186,15 @@ tBTA_JV_STATUS BTA_JvStartDiscovery(const RawAddress& bd_addr,
* When the operation is complete the tBTA_JV_DM_CBACK callback
* function will be called with a BTA_JV_CREATE_RECORD_EVT.
*
- * Returns BTA_JV_SUCCESS, if the request is being processed.
- * BTA_JV_FAILURE, otherwise.
+ * Returns tBTA_JV_STATUS::SUCCESS, if the request is being processed.
+ * tBTA_JV_STATUS::FAILURE, otherwise.
*
******************************************************************************/
tBTA_JV_STATUS BTA_JvCreateRecordByUser(uint32_t rfcomm_slot_id) {
log::verbose("rfcomm_slot_id: {}", rfcomm_slot_id);
do_in_main_thread(FROM_HERE, Bind(&bta_jv_create_record, rfcomm_slot_id));
- return BTA_JV_SUCCESS;
+ return tBTA_JV_STATUS::SUCCESS;
}
/*******************************************************************************
@@ -203,15 +203,15 @@ tBTA_JV_STATUS BTA_JvCreateRecordByUser(uint32_t rfcomm_slot_id) {
*
* Description Delete a service record in the local SDP database.
*
- * Returns BTA_JV_SUCCESS, if the request is being processed.
- * BTA_JV_FAILURE, otherwise.
+ * Returns tBTA_JV_STATUS::SUCCESS, if the request is being processed.
+ * tBTA_JV_STATUS::FAILURE, otherwise.
*
******************************************************************************/
tBTA_JV_STATUS BTA_JvDeleteRecord(uint32_t handle) {
log::verbose("handle:{}", handle);
do_in_main_thread(FROM_HERE, Bind(&bta_jv_delete_record, handle));
- return BTA_JV_SUCCESS;
+ return tBTA_JV_STATUS::SUCCESS;
}
/*******************************************************************************
@@ -252,19 +252,19 @@ void BTA_JvL2capConnect(int conn_type, tBTA_SEC sec_mask, tBTA_JV_ROLE role,
*
* Description This function closes an L2CAP client connection
*
- * Returns BTA_JV_SUCCESS, if the request is being processed.
- * BTA_JV_FAILURE, otherwise.
+ * Returns tBTA_JV_STATUS::SUCCESS, if the request is being processed.
+ * tBTA_JV_STATUS::FAILURE, otherwise.
*
******************************************************************************/
tBTA_JV_STATUS BTA_JvL2capClose(uint32_t handle) {
log::verbose("handle:{}", handle);
if (handle >= BTA_JV_MAX_L2C_CONN || !bta_jv_cb.l2c_cb[handle].p_cback)
- return BTA_JV_FAILURE;
+ return tBTA_JV_STATUS::FAILURE;
do_in_main_thread(
FROM_HERE, Bind(&bta_jv_l2cap_close, handle, &bta_jv_cb.l2c_cb[handle]));
- return BTA_JV_SUCCESS;
+ return tBTA_JV_STATUS::SUCCESS;
}
/*******************************************************************************
@@ -304,8 +304,8 @@ void BTA_JvL2capStartServer(int conn_type, tBTA_SEC sec_mask, tBTA_JV_ROLE role,
* Description This function stops the L2CAP server. If the server has an
* active connection, it would be closed.
*
- * Returns BTA_JV_SUCCESS, if the request is being processed.
- * BTA_JV_FAILURE, otherwise.
+ * Returns tBTA_JV_STATUS::SUCCESS, if the request is being processed.
+ * tBTA_JV_STATUS::FAILURE, otherwise.
*
******************************************************************************/
tBTA_JV_STATUS BTA_JvL2capStopServer(uint16_t local_psm,
@@ -314,7 +314,7 @@ tBTA_JV_STATUS BTA_JvL2capStopServer(uint16_t local_psm,
do_in_main_thread(
FROM_HERE, Bind(&bta_jv_l2cap_stop_server, local_psm, l2cap_socket_id));
- return BTA_JV_SUCCESS;
+ return tBTA_JV_STATUS::SUCCESS;
}
/*******************************************************************************
@@ -325,8 +325,8 @@ tBTA_JV_STATUS BTA_JvL2capStopServer(uint16_t local_psm,
* When the operation is complete, tBTA_JV_L2CAP_CBACK is
* called with BTA_JV_L2CAP_READ_EVT.
*
- * Returns BTA_JV_SUCCESS, if the request is being processed.
- * BTA_JV_FAILURE, otherwise.
+ * Returns tBTA_JV_STATUS::SUCCESS, if the request is being processed.
+ * tBTA_JV_STATUS::FAILURE, otherwise.
*
******************************************************************************/
tBTA_JV_STATUS BTA_JvL2capRead(uint32_t handle, uint32_t req_id,
@@ -334,10 +334,10 @@ tBTA_JV_STATUS BTA_JvL2capRead(uint32_t handle, uint32_t req_id,
log::verbose("handle:{}, req_id:{}, len:{}", handle, req_id, len);
if (handle >= BTA_JV_MAX_L2C_CONN || !bta_jv_cb.l2c_cb[handle].p_cback)
- return BTA_JV_FAILURE;
+ return tBTA_JV_STATUS::FAILURE;
tBTA_JV_L2CAP_READ evt_data;
- evt_data.status = BTA_JV_FAILURE;
+ evt_data.status = tBTA_JV_STATUS::FAILURE;
evt_data.handle = handle;
evt_data.req_id = req_id;
evt_data.p_data = p_data;
@@ -345,11 +345,11 @@ tBTA_JV_STATUS BTA_JvL2capRead(uint32_t handle, uint32_t req_id,
if (BT_PASS ==
GAP_ConnReadData((uint16_t)handle, p_data, len, &evt_data.len)) {
- evt_data.status = BTA_JV_SUCCESS;
+ evt_data.status = tBTA_JV_STATUS::SUCCESS;
}
bta_jv_cb.l2c_cb[handle].p_cback(BTA_JV_L2CAP_READ_EVT, (tBTA_JV*)&evt_data,
bta_jv_cb.l2c_cb[handle].l2cap_socket_id);
- return BTA_JV_SUCCESS;
+ return tBTA_JV_STATUS::SUCCESS;
}
/*******************************************************************************
@@ -359,19 +359,20 @@ tBTA_JV_STATUS BTA_JvL2capRead(uint32_t handle, uint32_t req_id,
* Description This function determined if there is data to read from
* an L2CAP connection
*
- * Returns BTA_JV_SUCCESS, if data queue size is in *p_data_size.
- * BTA_JV_FAILURE, if error.
+ * Returns tBTA_JV_STATUS::SUCCESS, if data queue size is in
+ * *p_data_size.
+ * tBTA_JV_STATUS::FAILURE, if error.
*
******************************************************************************/
tBTA_JV_STATUS BTA_JvL2capReady(uint32_t handle, uint32_t* p_data_size) {
- tBTA_JV_STATUS status = BTA_JV_FAILURE;
+ tBTA_JV_STATUS status = tBTA_JV_STATUS::FAILURE;
log::verbose("handle:{}", handle);
if (p_data_size && handle < BTA_JV_MAX_L2C_CONN &&
bta_jv_cb.l2c_cb[handle].p_cback) {
*p_data_size = 0;
if (BT_PASS == GAP_GetRxQueueCnt((uint16_t)handle, p_data_size)) {
- status = BTA_JV_SUCCESS;
+ status = tBTA_JV_STATUS::SUCCESS;
}
}
@@ -389,8 +390,8 @@ tBTA_JV_STATUS BTA_JvL2capReady(uint32_t handle, uint32_t* p_data_size) {
* p_data, and will osi_free it. Data length must be smaller
* than remote maximum SDU size.
*
- * Returns BTA_JV_SUCCESS, if the request is being processed.
- * BTA_JV_FAILURE, otherwise.
+ * Returns tBTA_JV_STATUS::SUCCESS, if the request is being processed.
+ * tBTA_JV_STATUS::FAILURE, otherwise.
*
******************************************************************************/
tBTA_JV_STATUS BTA_JvL2capWrite(uint32_t handle, uint32_t req_id, BT_HDR* msg,
@@ -399,12 +400,12 @@ tBTA_JV_STATUS BTA_JvL2capWrite(uint32_t handle, uint32_t req_id, BT_HDR* msg,
if (handle >= BTA_JV_MAX_L2C_CONN || !bta_jv_cb.l2c_cb[handle].p_cback) {
osi_free(msg);
- return BTA_JV_FAILURE;
+ return tBTA_JV_STATUS::FAILURE;
}
do_in_main_thread(FROM_HERE, Bind(&bta_jv_l2cap_write, handle, req_id, msg,
user_id, &bta_jv_cb.l2c_cb[handle]));
- return BTA_JV_SUCCESS;
+ return tBTA_JV_STATUS::SUCCESS;
}
/*******************************************************************************
@@ -419,8 +420,8 @@ tBTA_JV_STATUS BTA_JvL2capWrite(uint32_t handle, uint32_t req_id, BT_HDR* msg,
* When the connection is established or failed,
* tBTA_JV_RFCOMM_CBACK is called with BTA_JV_RFCOMM_OPEN_EVT
*
- * Returns BTA_JV_SUCCESS, if the request is being processed.
- * BTA_JV_FAILURE, otherwise.
+ * Returns tBTA_JV_STATUS::SUCCESS, if the request is being processed.
+ * tBTA_JV_STATUS::FAILURE, otherwise.
*
******************************************************************************/
tBTA_JV_STATUS BTA_JvRfcommConnect(tBTA_SEC sec_mask, tBTA_JV_ROLE role,
@@ -431,12 +432,12 @@ tBTA_JV_STATUS BTA_JvRfcommConnect(tBTA_SEC sec_mask, tBTA_JV_ROLE role,
log::verbose("remote_scn:{}, peer_bd_addr:{}, rfcomm_slot_id:{}", remote_scn,
ADDRESS_TO_LOGGABLE_CSTR(peer_bd_addr), rfcomm_slot_id);
- if (!p_cback) return BTA_JV_FAILURE; /* Nothing to do */
+ if (!p_cback) return tBTA_JV_STATUS::FAILURE; /* Nothing to do */
do_in_main_thread(FROM_HERE,
Bind(&bta_jv_rfcomm_connect, sec_mask, remote_scn,
peer_bd_addr, p_cback, rfcomm_slot_id));
- return BTA_JV_SUCCESS;
+ return tBTA_JV_STATUS::SUCCESS;
}
/*******************************************************************************
@@ -445,8 +446,8 @@ tBTA_JV_STATUS BTA_JvRfcommConnect(tBTA_SEC sec_mask, tBTA_JV_ROLE role,
*
* Description This function closes an RFCOMM connection
*
- * Returns BTA_JV_SUCCESS, if the request is being processed.
- * BTA_JV_FAILURE, otherwise.
+ * Returns tBTA_JV_STATUS::SUCCESS, if the request is being processed.
+ * tBTA_JV_STATUS::FAILURE, otherwise.
*
******************************************************************************/
tBTA_JV_STATUS BTA_JvRfcommClose(uint32_t handle, uint32_t rfcomm_slot_id) {
@@ -457,11 +458,11 @@ tBTA_JV_STATUS BTA_JvRfcommClose(uint32_t handle, uint32_t rfcomm_slot_id) {
if (hi >= BTA_JV_MAX_RFC_CONN || !bta_jv_cb.rfc_cb[hi].p_cback ||
si >= BTA_JV_MAX_RFC_SR_SESSION || !bta_jv_cb.rfc_cb[hi].rfc_hdl[si])
- return BTA_JV_FAILURE;
+ return tBTA_JV_STATUS::FAILURE;
do_in_main_thread(FROM_HERE,
Bind(&bta_jv_rfcomm_close, handle, rfcomm_slot_id));
- return BTA_JV_SUCCESS;
+ return tBTA_JV_STATUS::SUCCESS;
}
/*******************************************************************************
@@ -475,8 +476,8 @@ tBTA_JV_STATUS BTA_JvRfcommClose(uint32_t handle, uint32_t rfcomm_slot_id) {
* When the connection is established, tBTA_JV_RFCOMM_CBACK
* is called with BTA_JV_RFCOMM_OPEN_EVT.
*
- * Returns BTA_JV_SUCCESS, if the request is being processed.
- * BTA_JV_FAILURE, otherwise.
+ * Returns tBTA_JV_STATUS::SUCCESS, if the request is being processed.
+ * tBTA_JV_STATUS::FAILURE, otherwise.
*
******************************************************************************/
tBTA_JV_STATUS BTA_JvRfcommStartServer(tBTA_SEC sec_mask, tBTA_JV_ROLE role,
@@ -485,7 +486,7 @@ tBTA_JV_STATUS BTA_JvRfcommStartServer(tBTA_SEC sec_mask, tBTA_JV_ROLE role,
uint32_t rfcomm_slot_id) {
log::verbose("local_scn:{}, rfcomm_slot_id:{}", local_scn, rfcomm_slot_id);
- if (p_cback == NULL) return BTA_JV_FAILURE; /* Nothing to do */
+ if (p_cback == NULL) return tBTA_JV_STATUS::FAILURE; /* Nothing to do */
if (max_session == 0) max_session = 1;
if (max_session > BTA_JV_MAX_RFC_SR_SESSION) {
@@ -496,7 +497,7 @@ tBTA_JV_STATUS BTA_JvRfcommStartServer(tBTA_SEC sec_mask, tBTA_JV_ROLE role,
do_in_main_thread(FROM_HERE,
Bind(&bta_jv_rfcomm_start_server, sec_mask, local_scn,
max_session, p_cback, rfcomm_slot_id));
- return BTA_JV_SUCCESS;
+ return tBTA_JV_STATUS::SUCCESS;
}
/*******************************************************************************
@@ -506,8 +507,8 @@ tBTA_JV_STATUS BTA_JvRfcommStartServer(tBTA_SEC sec_mask, tBTA_JV_ROLE role,
* Description This function stops the RFCOMM server. If the server has an
* active connection, it would be closed.
*
- * Returns BTA_JV_SUCCESS, if the request is being processed.
- * BTA_JV_FAILURE, otherwise.
+ * Returns tBTA_JV_STATUS::SUCCESS, if the request is being processed.
+ * tBTA_JV_STATUS::FAILURE, otherwise.
*
******************************************************************************/
tBTA_JV_STATUS BTA_JvRfcommStopServer(uint32_t handle,
@@ -516,7 +517,7 @@ tBTA_JV_STATUS BTA_JvRfcommStopServer(uint32_t handle,
do_in_main_thread(FROM_HERE,
Bind(&bta_jv_rfcomm_stop_server, handle, rfcomm_slot_id));
- return BTA_JV_SUCCESS;
+ return tBTA_JV_STATUS::SUCCESS;
}
/*******************************************************************************
@@ -545,8 +546,8 @@ uint16_t BTA_JvRfcommGetPortHdl(uint32_t handle) {
*
* Description This function writes data to an RFCOMM connection
*
- * Returns BTA_JV_SUCCESS, if the request is being processed.
- * BTA_JV_FAILURE, otherwise.
+ * Returns tBTA_JV_STATUS::SUCCESS, if the request is being processed.
+ * tBTA_JV_STATUS::FAILURE, otherwise.
*
******************************************************************************/
tBTA_JV_STATUS BTA_JvRfcommWrite(uint32_t handle, uint32_t req_id) {
@@ -556,7 +557,7 @@ tBTA_JV_STATUS BTA_JvRfcommWrite(uint32_t handle, uint32_t req_id) {
log::verbose("handle:{}, req_id:{}, hi:{}, si:{}", handle, req_id, hi, si);
if (hi >= BTA_JV_MAX_RFC_CONN || !bta_jv_cb.rfc_cb[hi].p_cback ||
si >= BTA_JV_MAX_RFC_SR_SESSION || !bta_jv_cb.rfc_cb[hi].rfc_hdl[si]) {
- return BTA_JV_FAILURE;
+ return tBTA_JV_STATUS::FAILURE;
}
log::verbose("write ok");
@@ -564,7 +565,7 @@ tBTA_JV_STATUS BTA_JvRfcommWrite(uint32_t handle, uint32_t req_id) {
tBTA_JV_RFC_CB* p_cb = &bta_jv_cb.rfc_cb[hi];
do_in_main_thread(FROM_HERE, Bind(&bta_jv_rfcomm_write, handle, req_id, p_cb,
&bta_jv_cb.port_cb[p_cb->rfc_hdl[si] - 1]));
- return BTA_JV_SUCCESS;
+ return tBTA_JV_STATUS::SUCCESS;
}
/*******************************************************************************
@@ -582,8 +583,8 @@ tBTA_JV_STATUS BTA_JvRfcommWrite(uint32_t handle, uint32_t req_id) {
* init_st: state after calling this API. typically it should be
* BTA_JV_CONN_OPEN
*
- * Returns BTA_JV_SUCCESS, if the request is being processed.
- * BTA_JV_FAILURE, otherwise.
+ * Returns tBTA_JV_STATUS::SUCCESS, if the request is being processed.
+ * tBTA_JV_STATUS::FAILURE, otherwise.
*
* NOTE: BTA_JV_PM_ID_CLEAR: In general no need to be called as jv pm
* calls automatically
@@ -596,5 +597,5 @@ tBTA_JV_STATUS BTA_JvSetPmProfile(uint32_t handle, tBTA_JV_PM_ID app_id,
do_in_main_thread(FROM_HERE,
Bind(&bta_jv_set_pm_profile, handle, app_id, init_st));
- return BTA_JV_SUCCESS;
+ return tBTA_JV_STATUS::SUCCESS;
}
diff --git a/system/bta/jv/bta_jv_int.h b/system/bta/jv/bta_jv_int.h
index d8a5061397..abe20f731b 100644
--- a/system/bta/jv/bta_jv_int.h
+++ b/system/bta/jv/bta_jv_int.h
@@ -110,7 +110,7 @@ typedef struct {
} tBTA_JV_RFC_CB;
/* JV control block */
-typedef struct {
+struct tBTA_JV_CB {
/* the SDP handle reported to JV user is the (index + 1) to sdp_handle[].
* if sdp_handle[i]==0, it's not used.
* otherwise sdp_handle[i] is the stack SDP handle. */
@@ -127,17 +127,16 @@ typedef struct {
bool scn_in_use[RFCOMM_MAX_SCN];
uint8_t scn_search_index; /* used to search for free scns */
- uint8_t sdp_active; /* see BTA_JV_SDP_ACT_* */
- bluetooth::Uuid uuid; /* current uuid of sdp discovery*/
+ struct sdp_cb {
+ bool sdp_active{false};
+ RawAddress bd_addr{RawAddress::kEmpty}; // current bd_addr of sdp discovery
+ bluetooth::Uuid uuid{
+ bluetooth::Uuid::kEmpty}; // current uuid of sdp discovery
+ } sdp_cb;
+
tBTA_JV_PM_CB pm_cb[BTA_JV_PM_MAX_NUM]; /* PM on a per JV handle bases */
uint16_t dyn_psm; /* Next dynamic PSM value to try to assign */
-} tBTA_JV_CB;
-
-enum {
- BTA_JV_SDP_ACT_NONE = 0,
- BTA_JV_SDP_ACT_YES, /* waiting for SDP result */
- BTA_JV_SDP_ACT_CANCEL /* waiting for cancel complete */
};
/* JV control block */
diff --git a/system/bta/le_audio/broadcaster/broadcaster.cc b/system/bta/le_audio/broadcaster/broadcaster.cc
index 315939ebe4..eb527ef184 100644
--- a/system/bta/le_audio/broadcaster/broadcaster.cc
+++ b/system/bta/le_audio/broadcaster/broadcaster.cc
@@ -421,9 +421,15 @@ class LeAudioBroadcasterImpl : public LeAudioBroadcaster, public BigCallbacks {
LeAudioContextType::MEDIA | LeAudioContextType::CONVERSATIONAL;
}
+ /* Subgroups with different audio qualities is not being supported now,
+ * if any subgroup preferred to use standard audio config, choose
+ * the standard audio config instead
+ */
+ uint8_t BIG_audio_quality = bluetooth::le_audio::QUALITY_HIGH;
for (const uint8_t quality : subgroup_quality) {
if (quality == bluetooth::le_audio::QUALITY_STANDARD) {
public_features |= bluetooth::le_audio::kLeAudioQualityStandard;
+ BIG_audio_quality = bluetooth::le_audio::QUALITY_STANDARD;
} else if (quality == bluetooth::le_audio::QUALITY_HIGH) {
public_features |= bluetooth::le_audio::kLeAudioQualityHigh;
}
@@ -481,13 +487,15 @@ class LeAudioBroadcasterImpl : public LeAudioBroadcaster, public BigCallbacks {
subgroup_ltvs.push_back(ltv);
}
- auto codec_qos_pair = [](AudioContexts context_type)
+ auto codec_qos_pair = [](AudioContexts context_type,
+ uint8_t BIG_audio_quality)
-> std::optional<
std::pair<const BroadcastCodecWrapper, const BroadcastQosConfig>> {
if (CodecManager::GetInstance()->GetCodecLocation() ==
CodecLocation::ADSP) {
auto offload_config =
- CodecManager::GetInstance()->GetBroadcastOffloadConfig();
+ CodecManager::GetInstance()->GetBroadcastOffloadConfig(
+ BIG_audio_quality);
if (offload_config == nullptr) {
return std::nullopt;
}
@@ -509,13 +517,24 @@ class LeAudioBroadcasterImpl : public LeAudioBroadcaster, public BigCallbacks {
} else {
return le_audio::broadcaster::getStreamConfigForContext(context_type);
}
- }(context_type);
+ }(context_type, BIG_audio_quality);
if (!codec_qos_pair) {
LOG_ERROR("No valid broadcast offload config");
+ callbacks_->OnBroadcastCreated(bluetooth::le_audio::kBroadcastIdInvalid,
+ false);
return;
}
+ if (BIG_audio_quality == bluetooth::le_audio::QUALITY_HIGH &&
+ codec_qos_pair->first.GetSampleRate() != 48000) {
+ LOG_WARN(
+ "Preferred quality isn't supported. Fallback to standard audio "
+ "quality");
+ public_features &= (0xFFFF & ~bluetooth::le_audio::kLeAudioQualityHigh);
+ public_features |= bluetooth::le_audio::kLeAudioQualityStandard;
+ }
+
BroadcastStateMachineConfig msg = {
.is_public = is_public,
.broadcast_id = broadcast_id,
diff --git a/system/bta/le_audio/broadcaster/mock_ble_advertising_manager.cc b/system/bta/le_audio/broadcaster/mock_ble_advertising_manager.cc
deleted file mode 100644
index baeecc23c6..0000000000
--- a/system/bta/le_audio/broadcaster/mock_ble_advertising_manager.cc
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 2021 HIMSA II K/S - www.himsa.com.
- * Represented by EHIMA - www.ehima.com
- *
- * 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.
- */
-
-#include "mock_ble_advertising_manager.h"
-
-#include <base/memory/weak_ptr.h>
-
-#include "main/shim/le_advertising_manager.h"
-
-namespace {
-MockBleAdvertisingManager* bt_le_advertiser_instance;
-} // namespace
-
-void MockBleAdvertisingManager::Initialize() {
- if (bt_le_advertiser_instance == nullptr) {
- bt_le_advertiser_instance = new MockBleAdvertisingManager();
- }
-}
-
-void MockBleAdvertisingManager::CleanUp() {
- delete bt_le_advertiser_instance;
- bt_le_advertiser_instance = nullptr;
-}
-
-MockBleAdvertisingManager* MockBleAdvertisingManager::Get() {
- return bt_le_advertiser_instance;
-}
-
-BleAdvertiserInterface* bluetooth::shim::get_ble_advertiser_instance() {
- return static_cast<BleAdvertiserInterface*>(bt_le_advertiser_instance);
-}
diff --git a/system/bta/le_audio/broadcaster/state_machine_test.cc b/system/bta/le_audio/broadcaster/state_machine_test.cc
index 527c12b35e..f02d3cce74 100644
--- a/system/bta/le_audio/broadcaster/state_machine_test.cc
+++ b/system/bta/le_audio/broadcaster/state_machine_test.cc
@@ -22,11 +22,11 @@
#include "../le_audio_types.h"
#include "btm_iso_api.h"
-#include "mock_ble_advertising_manager.h"
#include "mock_iso_manager.h"
#include "stack/include/btm_ble_api_types.h"
#include "state_machine.h"
#include "test/common/mock_functions.h"
+#include "test/mock/mock_main_shim_le_advertising_manager.h"
using namespace bluetooth::hci::iso_manager;
diff --git a/system/bta/le_audio/client.cc b/system/bta/le_audio/client.cc
index 4378553822..4c69c6f3c4 100644
--- a/system/bta/le_audio/client.cc
+++ b/system/bta/le_audio/client.cc
@@ -3442,10 +3442,6 @@ class LeAudioClientImpl : public LeAudioClient {
return;
}
- if (DsaDataConsume(group, cis_conn_hdl, data, size, timestamp)) {
- return;
- }
-
uint16_t left_cis_handle = 0;
uint16_t right_cis_handle = 0;
for (auto [cis_handle, audio_location] :
@@ -5262,6 +5258,10 @@ class LeAudioClientImpl : public LeAudioClient {
auto* event =
static_cast<bluetooth::hci::iso_manager::cis_data_evt*>(data);
+ if (DsaDataConsume(event)) {
+ return;
+ }
+
if (audio_receiver_state_ != AudioState::STARTED) {
LOG_ERROR("receiver state not ready, current state=%s",
ToString(audio_receiver_state_).c_str());
@@ -5809,16 +5809,34 @@ class LeAudioClientImpl : public LeAudioClient {
le_audio::MetricsCollector::Get()->OnStreamEnded(active_group_id_);
}
- bool DsaDataConsume(LeAudioDeviceGroup* group, uint16_t cis_conn_hdl,
- uint8_t* data, uint16_t size, uint32_t timestamp) {
+ bool DsaDataConsume(bluetooth::hci::iso_manager::cis_data_evt* event) {
if (!IS_FLAG_ENABLED(leaudio_dynamic_spatial_audio)) {
return false;
}
- if (iso_data_callback == nullptr || !group->dsa_.active ||
- group->dsa_.mode != DsaMode::ISO_SW) {
+ if (active_group_id_ == bluetooth::groups::kGroupUnknown) {
return false;
}
+ LeAudioDeviceGroup* group = aseGroups_.FindById(active_group_id_);
+ if (!group || !group->dsa_.active) {
+ return false;
+ }
+
+ if (group->dsa_.mode != DsaMode::ISO_SW) {
+ LOG_WARN("ISO packets received over HCI in DSA mode: %d",
+ group->dsa_.mode);
+ return false;
+ }
+
+ if (iso_data_callback == nullptr) {
+ LOG_WARN("Dsa data consumer not registered");
+ return false;
+ }
+
+ uint16_t cis_conn_hdl = event->cis_conn_hdl;
+ uint8_t* data = event->p_msg->data + event->p_msg->offset;
+ uint16_t size = event->p_msg->len - event->p_msg->offset;
+ uint32_t timestamp = event->ts;
// Find LE Audio device
LeAudioDevice* leAudioDevice = group->GetFirstDevice();
@@ -6202,6 +6220,7 @@ bool LeAudioClient::RegisterIsoDataConsumer(LeAudioIsoDataCallback callback) {
return false;
}
+ LOG_INFO("ISO data consumer changed");
iso_data_callback = callback;
return true;
}
diff --git a/system/bta/le_audio/client_parser.cc b/system/bta/le_audio/client_parser.cc
index 64937af92c..8024016855 100644
--- a/system/bta/le_audio/client_parser.cc
+++ b/system/bta/le_audio/client_parser.cc
@@ -32,6 +32,7 @@
#include "internal_include/bt_trace.h"
#include "le_audio_types.h"
+#include "le_audio_utils.h"
#include "os/log.h"
#include "stack/include/bt_types.h"
@@ -314,22 +315,33 @@ bool PrepareAseCtpCodecConfig(const std::vector<struct ctp_codec_conf>& confs,
std::vector<uint8_t>& value) {
if (confs.size() == 0) return false;
- std::string conf_ents_str;
+ std::stringstream conf_ents_str;
size_t msg_len = std::accumulate(
confs.begin(), confs.end(),
confs.size() * kCtpCodecConfMinLen + kAseNumSize + kCtpOpSize,
[&conf_ents_str](size_t cur_len, auto const& conf) {
- for (const auto& [type, value] : conf.codec_config.Values()) {
- conf_ents_str +=
- "\ttype: " + std::to_string(type) +
- "\tlen: " + std::to_string(value.size()) +
- "\tdata: " + base::HexEncode(value.data(), value.size()) + "\n";
- };
-
- return cur_len + conf.codec_config.RawPacketSize();
+ if (utils::IsCodecUsingLtvFormat(conf.codec_id)) {
+ types::LeAudioLtvMap ltv;
+ if (ltv.Parse(conf.codec_config.data(), conf.codec_config.size())) {
+ for (const auto& [type, value] : ltv.Values()) {
+ conf_ents_str
+ << "\ttype: " << std::to_string(type)
+ << "\tlen: " << std::to_string(value.size())
+ << "\tdata: " << base::HexEncode(value.data(), value.size())
+ << "\n";
+ }
+ return cur_len + conf.codec_config.size();
+ }
+ LOG_ERROR("Error parsing codec configuration LTV data.");
+ }
+
+ conf_ents_str << "\t"
+ << base::HexEncode(conf.codec_config.data(),
+ conf.codec_config.size());
+ return cur_len + conf.codec_config.size();
});
- value.resize(msg_len);
+ value.resize(msg_len);
uint8_t* msg = value.data();
UINT8_TO_STREAM(msg, kCtpOpcodeCodecConfiguration);
@@ -342,10 +354,9 @@ bool PrepareAseCtpCodecConfig(const std::vector<struct ctp_codec_conf>& confs,
UINT16_TO_STREAM(msg, conf.codec_id.vendor_company_id);
UINT16_TO_STREAM(msg, conf.codec_id.vendor_codec_id);
- auto codec_spec_conf_len = conf.codec_config.RawPacketSize();
-
- UINT8_TO_STREAM(msg, codec_spec_conf_len);
- msg = conf.codec_config.RawPacket(msg);
+ UINT8_TO_STREAM(msg, conf.codec_config.size());
+ ARRAY_TO_STREAM(msg, conf.codec_config.data(),
+ static_cast<int>(conf.codec_config.size()));
LOG(INFO) << __func__ << ", Codec configuration"
<< "\n\tAse id: " << loghex(conf.ase_id)
@@ -357,10 +368,10 @@ bool PrepareAseCtpCodecConfig(const std::vector<struct ctp_codec_conf>& confs,
<< "\n\tVendor codec ID: "
<< loghex(conf.codec_id.vendor_codec_id)
<< "\n\tCodec config len: "
- << static_cast<int>(codec_spec_conf_len)
+ << static_cast<int>(conf.codec_config.size())
<< "\n\tCodec spec conf: "
<< "\n"
- << conf_ents_str;
+ << conf_ents_str.str();
}
return true;
@@ -593,10 +604,14 @@ int ParseSinglePac(std::vector<struct acs_ac_record>& pac_recs, uint16_t len,
return -1;
}
- bool parsed;
- rec.codec_spec_caps =
- types::LeAudioLtvMap::Parse(value, codec_spec_cap_len, parsed);
- if (!parsed) return -1;
+ rec.codec_spec_caps_raw.assign(value, value + codec_spec_cap_len);
+
+ if (utils::IsCodecUsingLtvFormat(rec.codec_id)) {
+ bool parsed;
+ rec.codec_spec_caps =
+ types::LeAudioLtvMap::Parse(value, codec_spec_cap_len, parsed);
+ if (!parsed) return -1;
+ }
value += codec_spec_cap_len;
len -= codec_spec_cap_len;
diff --git a/system/bta/le_audio/client_parser.h b/system/bta/le_audio/client_parser.h
index 718c624b5d..7d2a69f71b 100644
--- a/system/bta/le_audio/client_parser.h
+++ b/system/bta/le_audio/client_parser.h
@@ -163,7 +163,7 @@ struct ctp_codec_conf {
uint8_t target_latency;
uint8_t target_phy;
types::LeAudioCodecId codec_id;
- types::LeAudioLtvMap codec_config;
+ std::vector<uint8_t> codec_config;
};
constexpr uint16_t kCtpQosConfMinLen = 16;
diff --git a/system/bta/le_audio/client_parser_test.cc b/system/bta/le_audio/client_parser_test.cc
index c9ef3c6262..bdaeb9abf0 100644
--- a/system/bta/le_audio/client_parser_test.cc
+++ b/system/bta/le_audio/client_parser_test.cc
@@ -153,11 +153,11 @@ TEST(LeAudioClientParserTest, testParsePacsInvalidCapsLtvLen) {
// Num records
0x01,
// Codec_ID
- 0x01,
- 0x03,
- 0x02,
- 0x05,
- 0x04,
+ 0x06,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
// Codec Spec. Caps. Len
0x07,
// Codec Spec. Caps.
@@ -177,11 +177,11 @@ TEST(LeAudioClientParserTest, testParsePacsInvalidCapsLtvLen) {
// Num records
0x01,
// Codec_ID
- 0x01,
- 0x03,
- 0x02,
- 0x05,
- 0x04,
+ 0x06,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
// Codec Spec. Caps. Len
0x07,
// Codec Spec. Caps.
@@ -205,11 +205,11 @@ TEST(LeAudioClientParserTest, testParsePacsNullLtv) {
// Num records
0x01,
// Codec_ID
- 0x01,
- 0x03,
- 0x02,
- 0x05,
- 0x04,
+ 0x06,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
// Codec Spec. Caps. Len
0x0A,
// Codec Spec. Caps.
@@ -229,9 +229,9 @@ TEST(LeAudioClientParserTest, testParsePacsNullLtv) {
ASSERT_TRUE(ParsePacs(pac_recs, sizeof(value), value));
ASSERT_EQ(pac_recs.size(), 1u);
- ASSERT_EQ(pac_recs[0].codec_id.coding_format, 0x01u);
- ASSERT_EQ(pac_recs[0].codec_id.vendor_company_id, 0x0203u);
- ASSERT_EQ(pac_recs[0].codec_id.vendor_codec_id, 0x0405u);
+ ASSERT_EQ(pac_recs[0].codec_id.coding_format, 0x06u);
+ ASSERT_EQ(pac_recs[0].codec_id.vendor_company_id, 0x0000u);
+ ASSERT_EQ(pac_recs[0].codec_id.vendor_codec_id, 0x0000u);
auto codec_spec_caps = pac_recs[0].codec_spec_caps.Values();
ASSERT_EQ(codec_spec_caps.size(), 3u);
@@ -244,6 +244,12 @@ TEST(LeAudioClientParserTest, testParsePacsNullLtv) {
ASSERT_EQ(codec_spec_caps[0x03u][1], 0x05u);
ASSERT_EQ(codec_spec_caps.count(0x04u), 1u);
ASSERT_EQ(codec_spec_caps[0x04u].size(), 0u);
+
+ // Validate the raw data from ltv matches the original pac record data buffer
+ // Add one redundant ltv length of 0, just like in the value[] above.
+ auto ltv_raw = pac_recs[0].codec_spec_caps.RawPacket();
+ ltv_raw.push_back(0x00);
+ ASSERT_EQ(ltv_raw, pac_recs[0].codec_spec_caps_raw);
}
TEST(LeAudioClientParserTest, testParsePacsEmptyMeta) {
@@ -253,11 +259,11 @@ TEST(LeAudioClientParserTest, testParsePacsEmptyMeta) {
// Num records
0x01,
// Codec_ID
- 0x01,
- 0x03,
- 0x02,
- 0x05,
- 0x04,
+ 0x06,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
// Codec Spec. Caps. Len
0x07,
// Codec Spec. Caps.
@@ -274,9 +280,9 @@ TEST(LeAudioClientParserTest, testParsePacsEmptyMeta) {
ASSERT_TRUE(ParsePacs(pac_recs, sizeof(value), value));
ASSERT_EQ(pac_recs.size(), 1u);
- ASSERT_EQ(pac_recs[0].codec_id.coding_format, 0x01u);
- ASSERT_EQ(pac_recs[0].codec_id.vendor_company_id, 0x0203u);
- ASSERT_EQ(pac_recs[0].codec_id.vendor_codec_id, 0x0405u);
+ ASSERT_EQ(pac_recs[0].codec_id.coding_format, 0x06u);
+ ASSERT_EQ(pac_recs[0].codec_id.vendor_company_id, 0x0000u);
+ ASSERT_EQ(pac_recs[0].codec_id.vendor_codec_id, 0x0000u);
auto codec_spec_caps = pac_recs[0].codec_spec_caps.Values();
ASSERT_EQ(codec_spec_caps.size(), 2u);
@@ -287,6 +293,10 @@ TEST(LeAudioClientParserTest, testParsePacsEmptyMeta) {
ASSERT_EQ(codec_spec_caps[0x03u].size(), 2u);
ASSERT_EQ(codec_spec_caps[0x03u][0], 0x04u);
ASSERT_EQ(codec_spec_caps[0x03u][1], 0x05u);
+
+ // Validate the raw data from ltv matches the original pac record data buffer
+ ASSERT_EQ(pac_recs[0].codec_spec_caps.RawPacket(),
+ pac_recs[0].codec_spec_caps_raw);
}
TEST(LeAudioClientParserTest, testParsePacsInvalidMetaLength) {
@@ -325,7 +335,7 @@ TEST(LeAudioClientParserTest, testParsePacsValidMeta) {
// Num records
0x01,
// Codec_ID
- 0x01, 0x03, 0x02, 0x05, 0x04,
+ 0x06, 0x00, 0x00, 0x00, 0x00,
// Codec Spec. Caps. Len
0x07,
// Codec Spec. Caps.
@@ -347,9 +357,9 @@ TEST(LeAudioClientParserTest, testParsePacsValidMeta) {
ASSERT_TRUE(ParsePacs(pac_recs, sizeof(value), value));
ASSERT_EQ(pac_recs.size(), 1u);
- ASSERT_EQ(pac_recs[0].codec_id.coding_format, 0x01u);
- ASSERT_EQ(pac_recs[0].codec_id.vendor_company_id, 0x0203u);
- ASSERT_EQ(pac_recs[0].codec_id.vendor_codec_id, 0x0405u);
+ ASSERT_EQ(pac_recs[0].codec_id.coding_format, 0x06u);
+ ASSERT_EQ(pac_recs[0].codec_id.vendor_company_id, 0x0000u);
+ ASSERT_EQ(pac_recs[0].codec_id.vendor_codec_id, 0x0000u);
auto codec_spec_caps = pac_recs[0].codec_spec_caps.Values();
ASSERT_EQ(codec_spec_caps.size(), 2u);
@@ -366,6 +376,10 @@ TEST(LeAudioClientParserTest, testParsePacsValidMeta) {
ASSERT_EQ(pac_recs[0].metadata[1], 0x02u);
ASSERT_EQ(pac_recs[0].metadata[2], 0x01u);
ASSERT_EQ(pac_recs[0].metadata[3], 0x00u);
+
+ // Validate the raw data from ltv matches the original pac record data buffer
+ ASSERT_EQ(pac_recs[0].codec_spec_caps.RawPacket(),
+ pac_recs[0].codec_spec_caps_raw);
}
TEST(LeAudioClientParserTest, testParsePacsInvalidNumRecords) {
@@ -410,7 +424,7 @@ TEST(LeAudioClientParserTest, testParsePacsMultipleRecords) {
// Metadata Length
0x00,
// Codec_ID
- 0x06, 0x08, 0x07, 0x0A, 0x09,
+ 0x06, 0x00, 0x00, 0x00, 0x00,
// Codec Spec. Caps. Len
0x03,
// Codec Spec. Caps.
@@ -453,15 +467,15 @@ TEST(LeAudioClientParserTest, testParsePacsMultipleRecords) {
ASSERT_EQ(record0.codec_id.coding_format, 0x01u);
ASSERT_EQ(record0.codec_id.vendor_company_id, 0x0203u);
ASSERT_EQ(record0.codec_id.vendor_codec_id, 0x0405u);
- ASSERT_EQ(record0.codec_spec_caps.Size(), 0u);
+ ASSERT_EQ(record0.codec_spec_caps_raw.size(), 0u);
ASSERT_EQ(record0.metadata.size(), 0u);
// Verify 2nd record
auto& record1 = pac_recs[1];
ASSERT_EQ(record1.codec_id.coding_format, 0x06u);
- ASSERT_EQ(record1.codec_id.vendor_company_id, 0x0708u);
- ASSERT_EQ(record1.codec_id.vendor_codec_id, 0x090Au);
+ ASSERT_EQ(record1.codec_id.vendor_company_id, 0x0000u);
+ ASSERT_EQ(record1.codec_id.vendor_codec_id, 0x0000u);
auto codec_spec_caps1 = record1.codec_spec_caps.Values();
ASSERT_EQ(codec_spec_caps1.size(), 1u);
@@ -475,6 +489,9 @@ TEST(LeAudioClientParserTest, testParsePacsMultipleRecords) {
ASSERT_EQ(record1.metadata[2], 0x01u);
ASSERT_EQ(record1.metadata[3], 0x00u);
+ // Validate the raw data from ltv matches the original pac record data buffer
+ ASSERT_EQ(record1.codec_spec_caps.RawPacket(), record1.codec_spec_caps_raw);
+
// Verify 3rd record
auto& record2 = pac_recs[2];
@@ -482,15 +499,11 @@ TEST(LeAudioClientParserTest, testParsePacsMultipleRecords) {
ASSERT_EQ(record2.codec_id.vendor_company_id, 0x1213u);
ASSERT_EQ(record2.codec_id.vendor_codec_id, 0x1415u);
- auto codec_spec_caps2 = record2.codec_spec_caps.Values();
- ASSERT_EQ(codec_spec_caps2.size(), 2u);
- ASSERT_EQ(codec_spec_caps2.count(0x12u), 1u);
- ASSERT_EQ(codec_spec_caps2[0x12u].size(), 1u);
- ASSERT_EQ(codec_spec_caps2[0x12u][0], 0x13u);
- ASSERT_EQ(codec_spec_caps2.count(0x13u), 1u);
- ASSERT_EQ(codec_spec_caps2[0x13u].size(), 2u);
- ASSERT_EQ(codec_spec_caps2[0x13u][0], 0x14u);
- ASSERT_EQ(codec_spec_caps2[0x13u][1], 0x15u);
+ // Codec is not known to use LTV format for codec specific parameters
+ ASSERT_EQ(record2.codec_spec_caps_raw.size(), 7u);
+ ASSERT_EQ(record2.codec_spec_caps.Size(), 0u);
+ ASSERT_EQ(0, memcmp(record2.codec_spec_caps_raw.data(), value + 28,
+ record2.codec_spec_caps_raw.size()));
ASSERT_EQ(record2.metadata.size(), 4u);
ASSERT_EQ(record2.metadata[0], 0x03u);
@@ -499,6 +512,44 @@ TEST(LeAudioClientParserTest, testParsePacsMultipleRecords) {
ASSERT_EQ(record2.metadata[3], 0x10u);
}
+TEST(LeAudioClientParserTest, testParsePacsVendorCodecRecords) {
+ std::vector<struct types::acs_ac_record> pac_recs;
+
+ const uint8_t value[] = {
+ // Num records
+ 0x01,
+ // Vendor Codec_ID
+ 0x01,
+ 0x03,
+ 0x02,
+ 0x05,
+ 0x04,
+ // Codec Spec. Caps. Len
+ 0x0A,
+ // Codec Spec. Caps. - proprietary format
+ 0x01,
+ 0x02,
+ 0x03,
+ 0x04,
+ 0x05,
+ 0x06,
+ 0x07,
+ 0x08,
+ 0x09,
+ 0x0A,
+ // Metadata Length
+ 0x00,
+ };
+ ASSERT_TRUE(ParsePacs(pac_recs, sizeof(value), value));
+
+ ASSERT_EQ(pac_recs.size(), 1u);
+ ASSERT_EQ(pac_recs[0].codec_id.coding_format, 0x01u);
+ ASSERT_EQ(pac_recs[0].codec_id.vendor_company_id, 0x0203u);
+ ASSERT_EQ(pac_recs[0].codec_id.vendor_codec_id, 0x0405u);
+ ASSERT_TRUE(pac_recs[0].codec_spec_caps.IsEmpty());
+ ASSERT_EQ(0x0Au, pac_recs[0].codec_spec_caps_raw.size());
+}
+
TEST(LeAudioClientParserTest, testParseAudioLocationsInvalidLength) {
types::AudioLocations locations = codec_spec_conf::kLeAudioLocationNotAllowed;
const uint8_t value1[] = {
@@ -1126,7 +1177,7 @@ TEST(LeAudioClientParserTest, testPrepareAseCtpCodecConfigSingle) {
.target_latency = 0x03,
.target_phy = 0x02,
.codec_id = codec_id,
- .codec_config = codec_conf,
+ .codec_config = codec_conf.RawPacket(),
});
PrepareAseCtpCodecConfig(confs, value);
@@ -1186,7 +1237,7 @@ TEST(LeAudioClientParserTest, testPrepareAseCtpCodecConfigMultiple) {
.target_latency = 0x03,
.target_phy = 0x02,
.codec_id = codec_id,
- .codec_config = codec_conf,
+ .codec_config = codec_conf.RawPacket(),
});
PrepareAseCtpCodecConfig(confs, value);
@@ -1241,7 +1292,7 @@ TEST(LeAudioClientParserTest, testPrepareAseCtpCodecConfigMultiple) {
.target_latency = 0x13,
.target_phy = 0x01,
.codec_id = codec_id2,
- .codec_config = codec_conf2,
+ .codec_config = codec_conf2.RawPacket(),
});
PrepareAseCtpCodecConfig(confs, value);
diff --git a/system/bta/le_audio/codec_manager.cc b/system/bta/le_audio/codec_manager.cc
index c01d34a0b8..7e42cfd941 100644
--- a/system/bta/le_audio/codec_manager.cc
+++ b/system/bta/le_audio/codec_manager.cc
@@ -235,32 +235,93 @@ struct codec_manager_impl {
}
}
- const broadcast_offload_config* GetBroadcastOffloadConfig() {
+ const broadcast_offload_config* GetBroadcastOffloadConfig(
+ uint8_t preferred_quality) {
if (supported_broadcast_config.empty()) {
LOG_ERROR("There is no valid broadcast offload config");
return nullptr;
}
+ /* Broadcast audio config selection based on source broadcast capability
+ *
+ * If the preferred_quality is HIGH, the configs ranking is
+ * 48_4 > 48_2 > 24_2(sink mandatory) > 16_2(source & sink mandatory)
+ *
+ * If the preferred_quality is STANDARD, the configs ranking is
+ * 24_2(sink mandatory) > 16_2(source & sink mandatory)
+ */
+ broadcast_target_config = -1;
+ for (int i = 0; i < (int)supported_broadcast_config.size(); i++) {
+ if (supported_broadcast_config[i].sampling_rate == 48000u) {
+ if (preferred_quality == bluetooth::le_audio::QUALITY_STANDARD)
+ continue;
+
+ if (supported_broadcast_config[i].octets_per_frame == 120) { // 48_4
+ broadcast_target_config = i;
+ break;
+ } else if (supported_broadcast_config[i].octets_per_frame ==
+ 100) { // 48_2
+ broadcast_target_config = i;
+ }
+ } else if (supported_broadcast_config[i].sampling_rate == 24000u &&
+ supported_broadcast_config[i].octets_per_frame ==
+ 60) { // 24_2
+ if (preferred_quality == bluetooth::le_audio::QUALITY_STANDARD) {
+ broadcast_target_config = i;
+ break;
+ } else if (broadcast_target_config ==
+ -1) { // preferred_quality is QUALITY_HIGH, and
+ // haven't get the 48_4 or 48_2
+ broadcast_target_config = i;
+ }
+ } else if (supported_broadcast_config[i].sampling_rate == 16000u &&
+ supported_broadcast_config[i].octets_per_frame ==
+ 40) { // 16_2
+ if (preferred_quality == bluetooth::le_audio::QUALITY_STANDARD) {
+ broadcast_target_config = i;
+ } else if (broadcast_target_config == -1 ||
+ supported_broadcast_config[broadcast_target_config]
+ .sampling_rate !=
+ 24000u) { // preferred_quality is QUALITY_HIGH, and
+ // haven't get the 48_4 or 48_2 or 24_2
+ broadcast_target_config = i;
+ }
+ }
+ }
+
+ if (broadcast_target_config == -1) {
+ LOG_ERROR(
+ "There is no valid broadcast offload config with preferred_quality");
+ return nullptr;
+ }
LOG_INFO(
"stream_map.size(): %zu, sampling_rate: %d, frame_duration(us): %d, "
"octets_per_frame: %d, blocks_per_sdu %d, "
"retransmission_number: %d, max_transport_latency: %d",
- supported_broadcast_config[0].stream_map.size(),
- supported_broadcast_config[0].sampling_rate,
- supported_broadcast_config[0].frame_duration,
- supported_broadcast_config[0].octets_per_frame,
- (int)supported_broadcast_config[0].blocks_per_sdu,
- (int)supported_broadcast_config[0].retransmission_number,
- supported_broadcast_config[0].max_transport_latency);
+ supported_broadcast_config[broadcast_target_config].stream_map.size(),
+ supported_broadcast_config[broadcast_target_config].sampling_rate,
+ supported_broadcast_config[broadcast_target_config].frame_duration,
+ supported_broadcast_config[broadcast_target_config].octets_per_frame,
+ (int)supported_broadcast_config[broadcast_target_config].blocks_per_sdu,
+ (int)supported_broadcast_config[broadcast_target_config]
+ .retransmission_number,
+ supported_broadcast_config[broadcast_target_config]
+ .max_transport_latency);
- return &supported_broadcast_config[0];
+ return &supported_broadcast_config[broadcast_target_config];
}
void UpdateBroadcastConnHandle(
const std::vector<uint16_t>& conn_handle,
std::function<void(const ::le_audio::broadcast_offload_config& config)>
update_receiver) {
- auto broadcast_config = supported_broadcast_config[0];
+ if (broadcast_target_config == -1 ||
+ broadcast_target_config >= (int)supported_broadcast_config.size()) {
+ LOG_ERROR("There is no valid broadcast offload config");
+ return;
+ }
+
+ auto broadcast_config = supported_broadcast_config[broadcast_target_config];
LOG_ASSERT(conn_handle.size() == broadcast_config.stream_map.size());
if (broadcast_config.stream_map.size() ==
@@ -639,6 +700,7 @@ struct codec_manager_impl {
std::vector<btle_audio_codec_config_t> codec_input_capa = {};
std::vector<btle_audio_codec_config_t> codec_output_capa = {};
+ int broadcast_target_config = -1;
}; // namespace le_audio
struct CodecManager::impl {
@@ -728,9 +790,10 @@ const AudioSetConfigurations* CodecManager::GetOffloadCodecConfig(
}
const ::le_audio::broadcast_offload_config*
-CodecManager::GetBroadcastOffloadConfig() {
+CodecManager::GetBroadcastOffloadConfig(uint8_t preferred_quality) {
if (pimpl_->IsRunning()) {
- return pimpl_->codec_manager_impl_->GetBroadcastOffloadConfig();
+ return pimpl_->codec_manager_impl_->GetBroadcastOffloadConfig(
+ preferred_quality);
}
return nullptr;
diff --git a/system/bta/le_audio/codec_manager.h b/system/bta/le_audio/codec_manager.h
index 7cd08d543f..bbd7e23f7a 100644
--- a/system/bta/le_audio/codec_manager.h
+++ b/system/bta/le_audio/codec_manager.h
@@ -78,8 +78,8 @@ class CodecManager {
update_receiver);
virtual const ::le_audio::set_configurations::AudioSetConfigurations*
GetOffloadCodecConfig(::le_audio::types::LeAudioContextType ctx_type);
- virtual const ::le_audio::broadcast_offload_config*
- GetBroadcastOffloadConfig();
+ virtual const ::le_audio::broadcast_offload_config* GetBroadcastOffloadConfig(
+ uint8_t preferred_quality);
virtual void UpdateBroadcastConnHandle(
const std::vector<uint16_t>& conn_handle,
std::function<void(const ::le_audio::broadcast_offload_config& config)>
diff --git a/system/bta/le_audio/devices.cc b/system/bta/le_audio/devices.cc
index c71b273c2b..6df3cf1081 100644
--- a/system/bta/le_audio/devices.cc
+++ b/system/bta/le_audio/devices.cc
@@ -24,6 +24,7 @@
#include "bta_gatt_queue.h"
#include "btif/include/btif_storage.h"
#include "internal_include/bt_trace.h"
+#include "le_audio_utils.h"
using bluetooth::hci::kIsoCigPhy1M;
using bluetooth::hci::kIsoCigPhy2M;
@@ -360,16 +361,24 @@ void LeAudioDevice::RegisterPACs(
/* TODO wrap this logging part with debug flag */
for (const struct types::acs_ac_record& pac : *pac_recs) {
- LOG(INFO) << "Registering PAC"
+ std::stringstream debug_str;
+ debug_str << "Registering PAC"
<< "\n\tCoding format: " << loghex(pac.codec_id.coding_format)
<< "\n\tVendor codec company ID: "
<< loghex(pac.codec_id.vendor_company_id)
<< "\n\tVendor codec ID: " << loghex(pac.codec_id.vendor_codec_id)
- << "\n\tCodec spec caps:\n"
- << pac.codec_spec_caps.ToString("",
- types::CodecCapabilitiesLtvFormat)
- << "\n\tMetadata: "
+ << "\n\tCodec spec caps:\n";
+ if (utils::IsCodecUsingLtvFormat(pac.codec_id) &&
+ !pac.codec_spec_caps.IsEmpty()) {
+ debug_str << pac.codec_spec_caps.ToString(
+ "", types::CodecCapabilitiesLtvFormat);
+ } else {
+ debug_str << base::HexEncode(pac.codec_spec_caps_raw.data(),
+ pac.codec_spec_caps_raw.size());
+ }
+ debug_str << "\n\tMetadata: "
<< base::HexEncode(pac.metadata.data(), pac.metadata.size());
+ LOG_DEBUG("%s", debug_str.str().c_str());
if (IS_FLAG_ENABLED(leaudio_dynamic_spatial_audio)) {
if (pac.codec_id == types::kLeAudioCodecHeadtracking) {
@@ -700,8 +709,13 @@ uint8_t LeAudioDevice::GetSupportedAudioChannelCounts(uint8_t direction) const {
auto& pac_recs = std::get<1>(pac_tuple);
for (const auto pac : pac_recs) {
- if (pac.codec_id.coding_format != types::kLeAudioCodingFormatLC3)
+ if (!utils::IsCodecUsingLtvFormat(pac.codec_id)) {
+ LOG_WARN("Unknown codec PAC record for codec: %s",
+ bluetooth::common::ToString(pac.codec_id).c_str());
continue;
+ }
+ ASSERT_LOG(!pac.codec_spec_caps.IsEmpty(),
+ "Codec specific capabilities are not parsed approprietly.");
auto supported_channel_count_ltv = pac.codec_spec_caps.Find(
codec_spec_caps::kLeAudioLtvTypeSupportedAudioChannelCounts);
@@ -803,9 +817,15 @@ void LeAudioDevice::DumpPacsDebugState(std::stringstream& stream,
<< static_cast<int>(record.codec_id.vendor_company_id)
<< ", Vendor codec ID: "
<< static_cast<int>(record.codec_id.vendor_codec_id) << ")";
- stream << "\n\t\tCodec specific capabilities:\n"
- << record.codec_spec_caps.ToString(
- "\t\t\t", types::CodecCapabilitiesLtvFormat);
+ stream << "\n\t\tCodec specific capabilities:\n";
+ if (utils::IsCodecUsingLtvFormat(record.codec_id)) {
+ stream << record.codec_spec_caps.ToString(
+ "\t\t\t", types::CodecCapabilitiesLtvFormat);
+ } else {
+ stream << "\t\t\t"
+ << base::HexEncode(record.codec_spec_caps_raw.data(),
+ record.codec_spec_caps_raw.size());
+ }
stream << "\t\tMetadata: "
<< base::HexEncode(record.metadata.data(),
record.metadata.size());
diff --git a/system/bta/le_audio/devices_test.cc b/system/bta/le_audio/devices_test.cc
index d7407c59be..61da229f62 100644
--- a/system/bta/le_audio/devices_test.cc
+++ b/system/bta/le_audio/devices_test.cc
@@ -385,20 +385,22 @@ class PublishedAudioCapabilitiesBuilder {
uint32_t octets_per_frame_range =
octets_per_frame | (octets_per_frame << 16);
+ auto ltv_map = LeAudioLtvMap({
+ {kLeAudioLtvTypeSupportedSamplingFrequencies,
+ UINT16_TO_VEC_UINT8(sampling_frequencies)},
+ {kLeAudioLtvTypeSupportedFrameDurations,
+ UINT8_TO_VEC_UINT8(frame_durations)},
+ {kLeAudioLtvTypeSupportedAudioChannelCounts,
+ UINT8_TO_VEC_UINT8(audio_channel_counts)},
+ {kLeAudioLtvTypeSupportedOctetsPerCodecFrame,
+ UINT32_TO_VEC_UINT8(octets_per_frame_range)},
+ {kLeAudioLtvTypeSupportedMaxCodecFramesPerSdu,
+ UINT8_TO_VEC_UINT8(max_codec_frames_per_sdu)},
+ });
pac_records_.push_back(
acs_ac_record({.codec_id = codec_id,
- .codec_spec_caps = LeAudioLtvMap({
- {kLeAudioLtvTypeSupportedSamplingFrequencies,
- UINT16_TO_VEC_UINT8(sampling_frequencies)},
- {kLeAudioLtvTypeSupportedFrameDurations,
- UINT8_TO_VEC_UINT8(frame_durations)},
- {kLeAudioLtvTypeSupportedAudioChannelCounts,
- UINT8_TO_VEC_UINT8(audio_channel_counts)},
- {kLeAudioLtvTypeSupportedOctetsPerCodecFrame,
- UINT32_TO_VEC_UINT8(octets_per_frame_range)},
- {kLeAudioLtvTypeSupportedMaxCodecFramesPerSdu,
- UINT8_TO_VEC_UINT8(max_codec_frames_per_sdu)},
- }),
+ .codec_spec_caps = ltv_map,
+ .codec_spec_caps_raw = ltv_map.RawPacket(),
.metadata = std::vector<uint8_t>(0)}));
}
@@ -409,20 +411,22 @@ class PublishedAudioCapabilitiesBuilder {
uint32_t octets_per_frame_range =
octets_per_frame_min | (ocets_per_frame_max << 16);
+ auto ltv_map = LeAudioLtvMap({
+ {kLeAudioLtvTypeSupportedSamplingFrequencies,
+ UINT16_TO_VEC_UINT8(capa_sampling_frequency)},
+ {kLeAudioLtvTypeSupportedFrameDurations,
+ UINT8_TO_VEC_UINT8(capa_frame_duration)},
+ {kLeAudioLtvTypeSupportedAudioChannelCounts,
+ UINT8_TO_VEC_UINT8(audio_channel_counts)},
+ {kLeAudioLtvTypeSupportedOctetsPerCodecFrame,
+ UINT32_TO_VEC_UINT8(octets_per_frame_range)},
+ {kLeAudioLtvTypeSupportedMaxCodecFramesPerSdu,
+ UINT8_TO_VEC_UINT8(codec_frames_per_sdu)},
+ });
pac_records_.push_back(
acs_ac_record({.codec_id = codec_id,
- .codec_spec_caps = LeAudioLtvMap({
- {kLeAudioLtvTypeSupportedSamplingFrequencies,
- UINT16_TO_VEC_UINT8(capa_sampling_frequency)},
- {kLeAudioLtvTypeSupportedFrameDurations,
- UINT8_TO_VEC_UINT8(capa_frame_duration)},
- {kLeAudioLtvTypeSupportedAudioChannelCounts,
- UINT8_TO_VEC_UINT8(audio_channel_counts)},
- {kLeAudioLtvTypeSupportedOctetsPerCodecFrame,
- UINT32_TO_VEC_UINT8(octets_per_frame_range)},
- {kLeAudioLtvTypeSupportedMaxCodecFramesPerSdu,
- UINT8_TO_VEC_UINT8(codec_frames_per_sdu)},
- }),
+ .codec_spec_caps = ltv_map,
+ .codec_spec_caps_raw = ltv_map.RawPacket(),
.metadata = std::vector<uint8_t>(0)}));
}
diff --git a/system/bta/le_audio/le_audio_types.cc b/system/bta/le_audio/le_audio_types.cc
index 407ed34651..621759bcf4 100644
--- a/system/bta/le_audio/le_audio_types.cc
+++ b/system/bta/le_audio/le_audio_types.cc
@@ -28,6 +28,7 @@
#include "audio_hal_client/audio_hal_client.h"
#include "common/strings.h"
#include "internal_include/bt_trace.h"
+#include "le_audio_utils.h"
#include "stack/include/bt_types.h"
namespace le_audio {
@@ -237,13 +238,16 @@ bool IsCodecConfigSettingSupported(
LOG_DEBUG(": Settings for format: 0x%02x ", codec_id.coding_format);
- switch (codec_id.coding_format) {
- case kLeAudioCodingFormatLC3:
- return IsCodecConfigCoreSupported(pac.codec_spec_caps,
- codec_config_setting.params);
- default:
- return false;
+ if (utils::IsCodecUsingLtvFormat(codec_id)) {
+ ASSERT_LOG(!pac.codec_spec_caps.IsEmpty(),
+ "Codec specific capabilities are not parsed approprietly.");
+ return IsCodecConfigCoreSupported(pac.codec_spec_caps,
+ codec_config_setting.params);
}
+
+ LOG_ERROR("Codec %s, seems to be not supported here.",
+ bluetooth::common::ToString(codec_id).c_str());
+ return false;
}
uint32_t CodecConfigSetting::GetSamplingFrequencyHz() const {
@@ -503,12 +507,21 @@ void LeAudioLtvMap::Append(const LeAudioLtvMap& other) {
for (auto& el : other.values) {
values[el.first] = el.second;
}
+
+ invalidate();
}
LeAudioLtvMap LeAudioLtvMap::Parse(const uint8_t* p_value, uint8_t len,
bool& success) {
LeAudioLtvMap ltv_map;
+ success = ltv_map.Parse(p_value, len);
+ if (!success) {
+ LOG(ERROR) << __func__ << "Error parsing LTV map";
+ }
+ return ltv_map;
+}
+bool LeAudioLtvMap::Parse(const uint8_t* p_value, uint8_t len) {
if (len > 0) {
const auto p_value_end = p_value + len;
@@ -522,8 +535,8 @@ LeAudioLtvMap LeAudioLtvMap::Parse(const uint8_t* p_value, uint8_t len,
if (p_value_end < (p_value + ltv_len)) {
LOG(ERROR) << __func__
<< " Invalid ltv_len: " << static_cast<int>(ltv_len);
- success = false;
- return LeAudioLtvMap();
+ invalidate();
+ return false;
}
uint8_t ltv_type;
@@ -534,12 +547,12 @@ LeAudioLtvMap LeAudioLtvMap::Parse(const uint8_t* p_value, uint8_t len,
p_value += ltv_len;
std::vector<uint8_t> ltv_value(p_temp, p_value);
- ltv_map.values.emplace(ltv_type, std::move(ltv_value));
+ values.emplace(ltv_type, std::move(ltv_value));
}
}
+ invalidate();
- success = true;
- return ltv_map;
+ return true;
}
size_t LeAudioLtvMap::RawPacketSize() const {
@@ -595,6 +608,24 @@ LeAudioLtvMap::GetAsCoreCodecCapabilities() const {
return *core_capabilities;
}
+void LeAudioLtvMap::RemoveAllTypes(const LeAudioLtvMap& other) {
+ for (auto const& [key, _] : other.values) {
+ Remove(key);
+ }
+}
+
+LeAudioLtvMap LeAudioLtvMap::GetIntersection(const LeAudioLtvMap& other) const {
+ LeAudioLtvMap result;
+ for (auto const& [key, value] : values) {
+ auto entry = other.Find(key);
+ if (entry->size() != value.size()) continue;
+ if (memcmp(entry->data(), value.data(), value.size()) == 0) {
+ result.Add(key, value);
+ }
+ }
+ return result;
+}
+
} // namespace types
void AppendMetadataLtvEntryForCcidList(std::vector<uint8_t>& metadata,
@@ -632,10 +663,12 @@ void AppendMetadataLtvEntryForStreamingContext(
}
uint8_t GetMaxCodecFramesPerSduFromPac(const acs_ac_record* pac) {
- auto tlv_ent = pac->codec_spec_caps.Find(
- codec_spec_caps::kLeAudioLtvTypeSupportedMaxCodecFramesPerSdu);
+ if (utils::IsCodecUsingLtvFormat(pac->codec_id)) {
+ auto tlv_ent = pac->codec_spec_caps.Find(
+ codec_spec_caps::kLeAudioLtvTypeSupportedMaxCodecFramesPerSdu);
- if (tlv_ent) return VEC_UINT8_TO_UINT8(tlv_ent.value());
+ if (tlv_ent) return VEC_UINT8_TO_UINT8(tlv_ent.value());
+ }
return 1;
}
@@ -680,6 +713,13 @@ std::ostream& operator<<(std::ostream& os, const types::AseState& state) {
return os;
}
+std::ostream& operator<<(std::ostream& os, const LeAudioCodecId& codec_id) {
+ os << "LeAudioCodecId(CodingFormat=" << loghex(codec_id.coding_format)
+ << ", CompanyId=" << loghex(codec_id.vendor_company_id)
+ << ", CodecId=" << loghex(codec_id.vendor_codec_id) << ")";
+ return os;
+}
+
std::ostream& operator<<(std::ostream& os,
const types::LeAudioCoreCodecConfig& config) {
os << " LeAudioCoreCodecConfig(SamplFreq="
diff --git a/system/bta/le_audio/le_audio_types.h b/system/bta/le_audio/le_audio_types.h
index 89731fb7e0..c42503967d 100644
--- a/system/bta/le_audio/le_audio_types.h
+++ b/system/bta/le_audio/le_audio_types.h
@@ -643,23 +643,56 @@ struct LeAudioCoreCodecCapabilities {
class LeAudioLtvMap {
public:
- LeAudioLtvMap() {}
LeAudioLtvMap(std::map<uint8_t, std::vector<uint8_t>> values)
- : values(std::move(values)), core_config(std::nullopt) {}
+ : values(values),
+ value_hash(0),
+ core_config(std::nullopt),
+ core_capabilities(std::nullopt) {}
+ LeAudioLtvMap() = default;
+ ~LeAudioLtvMap() = default;
+
+ bool operator==(const LeAudioLtvMap& other) const {
+ return GetHash() == other.GetHash();
+ }
+
+ bool operator!=(const LeAudioLtvMap& other) const {
+ return GetHash() != other.GetHash();
+ }
std::optional<std::vector<uint8_t>> Find(uint8_t type) const;
+ const auto& At(uint8_t type) const { return values.at(type); }
+
LeAudioLtvMap& Add(uint8_t type, std::vector<uint8_t> value) {
values.insert_or_assign(type, std::move(value));
- core_config = std::nullopt;
+ invalidate();
+ return *this;
+ }
+
+ LeAudioLtvMap& Add(uint8_t type, const std::string& value) {
+ std::vector<uint8_t> v(value.size());
+ auto ptr = v.data();
+ ARRAY_TO_STREAM(ptr, value.c_str(), (int)value.size());
+ values.insert_or_assign(type, v);
+ invalidate();
+ return *this;
+ }
+
+ LeAudioLtvMap& Add(uint8_t type, bool value) {
+ std::vector<uint8_t> v(1);
+ auto ptr = v.data();
+ UINT8_TO_STREAM(ptr, value ? 0x01 : 0x00);
+ values.insert_or_assign(type, v);
+ invalidate();
return *this;
}
+
LeAudioLtvMap& Add(uint8_t type, uint8_t value) {
std::vector<uint8_t> v(sizeof(value));
auto ptr = v.data();
UINT8_TO_STREAM(ptr, value);
values.insert_or_assign(type, v);
- core_config = std::nullopt;
+ invalidate();
return *this;
}
LeAudioLtvMap& Add(uint8_t type, uint16_t value) {
@@ -668,7 +701,7 @@ class LeAudioLtvMap {
UINT16_TO_STREAM(ptr, value);
values.insert_or_assign(type, std::move(v));
- core_config = std::nullopt;
+ invalidate();
return *this;
}
LeAudioLtvMap& Add(uint8_t type, uint32_t value) {
@@ -677,12 +710,19 @@ class LeAudioLtvMap {
UINT32_TO_STREAM(ptr, value);
values.insert_or_assign(type, std::move(v));
- core_config = std::nullopt;
+ invalidate();
return *this;
}
- void Remove(uint8_t type) { values.erase(type); }
+ void Remove(uint8_t type) {
+ values.erase(type);
+ invalidate();
+ }
+ void RemoveAllTypes(const LeAudioLtvMap& other);
bool IsEmpty() const { return values.empty(); }
- void Clear() { values.clear(); }
+ void Clear() {
+ invalidate();
+ values.clear();
+ }
size_t Size() const { return values.size(); }
const std::map<uint8_t, std::vector<uint8_t>>& Values() const {
return values;
@@ -690,6 +730,7 @@ class LeAudioLtvMap {
const struct LeAudioCoreCodecConfig& GetAsCoreCodecConfig() const;
const struct LeAudioCoreCodecCapabilities& GetAsCoreCodecCapabilities() const;
+ LeAudioLtvMap GetIntersection(const LeAudioLtvMap& other) const;
std::string ToString(
const std::string& indent_string,
@@ -698,10 +739,22 @@ class LeAudioLtvMap {
uint8_t* RawPacket(uint8_t* p_buf) const;
std::vector<uint8_t> RawPacket() const;
static LeAudioLtvMap Parse(const uint8_t* value, uint8_t len, bool& success);
+ bool Parse(const uint8_t* value, uint8_t len);
void Append(const LeAudioLtvMap& other);
+ size_t GetHash() const {
+ if (value_hash == 0) RecalculateValueHash();
+ return value_hash;
+ }
private:
- static LeAudioCoreCodecConfig LtvMapToCoreCodecConfig(LeAudioLtvMap ltvs) {
+ void invalidate() {
+ core_config = std::nullopt;
+ core_capabilities = std::nullopt;
+ value_hash = 0;
+ }
+
+ static LeAudioCoreCodecConfig LtvMapToCoreCodecConfig(
+ const LeAudioLtvMap& ltvs) {
LeAudioCoreCodecConfig core;
auto vec_opt = ltvs.Find(codec_spec_conf::kLeAudioLtvTypeSamplingFreq);
@@ -750,7 +803,7 @@ class LeAudioLtvMap {
}
static LeAudioCoreCodecCapabilities LtvMapToCoreCodecCapabilities(
- LeAudioLtvMap pacs) {
+ const LeAudioLtvMap& pacs) {
LeAudioCoreCodecCapabilities core;
auto pac =
@@ -819,10 +872,24 @@ class LeAudioLtvMap {
return core;
}
- std::map<uint8_t, std::vector<uint8_t>> values;
+ void RecalculateValueHash() const {
+ if (IsEmpty()) {
+ value_hash = 0;
+ return;
+ }
+
+ auto value_vec = RawPacket();
+ value_hash = std::hash<std::string_view>{}(
+ {reinterpret_cast<const char*>(value_vec.data()), value_vec.size()});
+ }
+
+ std::map<uint8_t, std::vector<uint8_t>> values = {};
+ mutable size_t value_hash = 0;
// Lazy-constructed views of the LTV data
- mutable std::optional<struct LeAudioCoreCodecConfig> core_config;
- mutable std::optional<struct LeAudioCoreCodecCapabilities> core_capabilities;
+ mutable std::optional<struct LeAudioCoreCodecConfig> core_config =
+ std::nullopt;
+ mutable std::optional<struct LeAudioCoreCodecCapabilities> core_capabilities =
+ std::nullopt;
};
struct LeAudioCodecId {
@@ -937,6 +1004,7 @@ struct ase {
struct acs_ac_record {
LeAudioCodecId codec_id;
LeAudioLtvMap codec_spec_caps;
+ std::vector<uint8_t> codec_spec_caps_raw;
std::vector<uint8_t> metadata;
};
@@ -946,6 +1014,7 @@ using AudioLocations = std::bitset<32>;
std::ostream& operator<<(std::ostream& os, const AseState& state);
std::ostream& operator<<(std::ostream& os, const CigState& state);
+std::ostream& operator<<(std::ostream& os, const LeAudioCodecId& codec_id);
std::ostream& operator<<(std::ostream& os,
const LeAudioCoreCodecConfig& config);
std::string contextTypeToStr(const LeAudioContextType& context);
diff --git a/system/bta/le_audio/le_audio_types_test.cc b/system/bta/le_audio/le_audio_types_test.cc
index fb3b86aaa8..341dcf3b67 100644
--- a/system/bta/le_audio/le_audio_types_test.cc
+++ b/system/bta/le_audio/le_audio_types_test.cc
@@ -58,7 +58,9 @@ TEST(LeAudioLtvMapTest, test_serialization) {
bool success;
LeAudioLtvMap ltv_map =
LeAudioLtvMap::Parse(ltv_test_vec.data(), ltv_test_vec.size(), success);
+ auto hash_one = ltv_map.GetHash();
ASSERT_TRUE(success);
+ ASSERT_NE(hash_one, 0lu);
ASSERT_FALSE(ltv_map.IsEmpty());
ASSERT_EQ((size_t)3, ltv_map.Size());
@@ -67,11 +69,17 @@ TEST(LeAudioLtvMapTest, test_serialization) {
LeAudioLtvMap ltv_map2 =
LeAudioLtvMap::Parse(ltv_test_vec2.data(), ltv_test_vec2.size(), success);
+ auto hash_two = ltv_map2.GetHash();
ASSERT_TRUE(success);
+ ASSERT_NE(hash_two, 0lu);
ASSERT_FALSE(ltv_map2.IsEmpty());
ASSERT_EQ((size_t)2, ltv_map2.Size());
+ ASSERT_NE(hash_one, hash_two);
ltv_map.Append(ltv_map2);
+ ASSERT_NE(ltv_map.GetHash(), 0lu);
+ ASSERT_NE(ltv_map.GetHash(), hash_one);
+ ASSERT_NE(ltv_map.GetHash(), hash_two);
ASSERT_EQ((size_t)4, ltv_map.Size());
ASSERT_TRUE(ltv_map.Find(0x01));
@@ -372,5 +380,240 @@ TEST(LeAudioLtvMapTest, test_capabilities_valid) {
ASSERT_FALSE(caps.IsCodecFramesPerSduSupported(3));
}
+TEST(LeAudioLtvMapTest, test_adding_types) {
+ LeAudioLtvMap ltv_map;
+ ltv_map.Add(1, (uint8_t)127);
+ ltv_map.Add(2, (uint16_t)32767);
+ ltv_map.Add(3, (uint32_t)65535);
+ ltv_map.Add(4, std::vector<uint8_t>{1, 2, 3, 4, 5, 6, 7, 8, 9});
+ ltv_map.Add(5, std::string("sample text"));
+ ltv_map.Add(6, true);
+
+ ASSERT_EQ(6lu, ltv_map.Size());
+
+ uint8_t u8;
+ auto pp = ltv_map.At(1).data();
+ STREAM_TO_UINT8(u8, pp);
+ ASSERT_EQ((uint8_t)127, u8);
+
+ uint16_t u16;
+ pp = ltv_map.At(2).data();
+ STREAM_TO_UINT16(u16, pp);
+ ASSERT_EQ((uint16_t)32767, u16);
+
+ uint32_t u32;
+ pp = ltv_map.At(3).data();
+ STREAM_TO_UINT32(u32, pp);
+ ASSERT_EQ((uint32_t)65535, u32);
+
+ ASSERT_EQ((std::vector<uint8_t>{1, 2, 3, 4, 5, 6, 7, 8, 9}), ltv_map.At(4));
+
+ ASSERT_EQ(std::string("sample text"),
+ std::string(ltv_map.At(5).begin(), ltv_map.At(5).end()));
+
+ ASSERT_EQ(true, (bool)ltv_map.At(6).data()[0]);
+}
+
+TEST(LeAudioLtvMapTest, test_hash_sanity) {
+ LeAudioLtvMap ltv_map;
+ ASSERT_EQ(ltv_map.GetHash(), 0lu);
+
+ auto hash = ltv_map.GetHash();
+ ltv_map.Add(0, (uint8_t)127);
+ ltv_map.Add(1, (uint16_t)32767);
+ ltv_map.Add(2, (uint32_t)65535);
+ ltv_map.Add(3, std::vector<uint8_t>{1, 2, 3, 4, 5, 6, 7, 8, 9});
+
+ ASSERT_NE(ltv_map.GetHash(), 0lu);
+ ASSERT_NE(ltv_map.GetHash(), hash);
+ ASSERT_EQ(ltv_map, ltv_map);
+
+ // Compare hashes of equal LTV maps, filled in a different order
+ LeAudioLtvMap ltv_map_two;
+ ltv_map_two.Add(3, std::vector<uint8_t>{1, 2, 3, 4, 5, 6, 7, 8, 9});
+ ltv_map_two.Add(0, (uint8_t)127);
+ ltv_map_two.Add(2, (uint32_t)65535);
+ ltv_map_two.Add(1, (uint16_t)32767);
+ ASSERT_EQ(ltv_map, ltv_map_two);
+}
+
+TEST(LeAudioLtvMapTest, test_value_hash_sanity) {
+ LeAudioLtvMap ltv_map;
+
+ ltv_map.Add(1, (uint16_t)32767);
+ auto hash = ltv_map.GetHash();
+
+ // Same value but type size is different
+ hash = ltv_map.GetHash();
+ ltv_map.Add(1, (uint32_t)32767);
+ ASSERT_NE(ltv_map.GetHash(), hash);
+}
+
+TEST(LeAudioLtvMapTest, test_type_change_same_value) {
+ LeAudioLtvMap ltv_map_one;
+ ltv_map_one.Add(1, (uint16_t)32767);
+
+ LeAudioLtvMap ltv_map_two;
+ // The same value but different type
+ ltv_map_two.Add(3, (uint16_t)32767);
+
+ ASSERT_NE(ltv_map_one.GetHash(), ltv_map_two.GetHash());
+}
+
+TEST(LeAudioLtvMapTest, test_add_changing_hash) {
+ LeAudioLtvMap ltv_map;
+
+ auto hash = ltv_map.GetHash();
+ ltv_map.Add(0, (uint8_t)127);
+ ASSERT_NE(ltv_map.GetHash(), hash);
+
+ hash = ltv_map.GetHash();
+ ltv_map.Add(1, (uint16_t)32767);
+ ASSERT_NE(ltv_map.GetHash(), hash);
+
+ hash = ltv_map.GetHash();
+ ltv_map.Add(2, (uint32_t)65535);
+ ASSERT_NE(ltv_map.GetHash(), hash);
+
+ hash = ltv_map.GetHash();
+ ltv_map.Add(3, std::vector<uint8_t>{1, 2, 3, 4, 5, 6, 7, 8, 9});
+ ASSERT_NE(ltv_map.GetHash(), hash);
+}
+
+TEST(LeAudioLtvMapTest, test_update_changing_hash) {
+ LeAudioLtvMap ltv_map;
+
+ auto hash = ltv_map.GetHash();
+ ltv_map.Add(0, (uint8_t)127);
+ ASSERT_NE(ltv_map.GetHash(), hash);
+
+ hash = ltv_map.GetHash();
+ ltv_map.Add(0, (uint16_t)32767);
+ ASSERT_NE(ltv_map.GetHash(), hash);
+
+ hash = ltv_map.GetHash();
+ ltv_map.Add(0, (uint32_t)65535);
+ ASSERT_NE(ltv_map.GetHash(), hash);
+
+ hash = ltv_map.GetHash();
+ ltv_map.Add(0, std::vector<uint8_t>{1, 2, 3, 4, 5, 6, 7, 8, 9});
+ ASSERT_NE(ltv_map.GetHash(), hash);
+}
+
+TEST(LeAudioLtvMapTest, test_update_same_not_changing_hash) {
+ LeAudioLtvMap ltv_map;
+
+ auto hash = ltv_map.GetHash();
+ ltv_map.Add(0, (uint8_t)127);
+ ASSERT_NE(ltv_map.GetHash(), hash);
+
+ hash = ltv_map.GetHash();
+ ltv_map.Add(0, (uint8_t)127);
+ ASSERT_EQ(ltv_map.GetHash(), hash);
+}
+
+TEST(LeAudioLtvMapTest, test_remove_changing_hash) {
+ LeAudioLtvMap ltv_map;
+
+ auto hash = ltv_map.GetHash();
+ ltv_map.Add(0, (uint8_t)127);
+ ltv_map.Add(1, (uint16_t)32767);
+ ltv_map.Add(2, (uint32_t)65535);
+ ltv_map.Add(3, std::vector<uint8_t>{1, 2, 3, 4, 5, 6, 7, 8, 9});
+
+ hash = ltv_map.GetHash();
+ ltv_map.Remove(0);
+ ASSERT_NE(ltv_map.GetHash(), hash);
+
+ hash = ltv_map.GetHash();
+ ltv_map.Remove(1);
+ ASSERT_NE(ltv_map.GetHash(), hash);
+
+ hash = ltv_map.GetHash();
+ ltv_map.Remove(2);
+ ASSERT_NE(ltv_map.GetHash(), hash);
+
+ hash = ltv_map.GetHash();
+ ltv_map.Remove(3);
+ ASSERT_NE(ltv_map.GetHash(), hash);
+}
+
+TEST(LeAudioLtvMapTest, test_clear_changing_hash) {
+ LeAudioLtvMap ltv_map;
+
+ auto hash = ltv_map.GetHash();
+ ltv_map.Add(0, (uint8_t)127);
+ ltv_map.Add(1, (uint16_t)32767);
+ ltv_map.Add(2, (uint32_t)65535);
+ ltv_map.Add(3, std::vector<uint8_t>{1, 2, 3, 4, 5, 6, 7, 8, 9});
+
+ hash = ltv_map.GetHash();
+ ltv_map.Clear();
+ ASSERT_NE(ltv_map.GetHash(), hash);
+
+ // 2nd clear should not change it
+ hash = ltv_map.GetHash();
+ ltv_map.Clear();
+ ASSERT_EQ(ltv_map.GetHash(), hash);
+
+ // Check if empty maps have equal hash
+ LeAudioLtvMap empty_ltv_map;
+ ASSERT_EQ(empty_ltv_map, ltv_map);
+}
+
+TEST(LeAudioLtvMapTest, test_remove_all_changing_hash) {
+ LeAudioLtvMap ltv_map;
+
+ auto hash = ltv_map.GetHash();
+ ltv_map.Add(0, (uint8_t)127);
+ ltv_map.Add(1, (uint16_t)32767);
+ ltv_map.Add(2, (uint32_t)65535);
+ ltv_map.Add(3, std::vector<uint8_t>{1, 2, 3, 4, 5, 6, 7, 8, 9});
+
+ LeAudioLtvMap ltv_map_1st_half;
+ ltv_map_1st_half.Add(1, (uint16_t)32767);
+ ltv_map_1st_half.Add(3, std::vector<uint8_t>{1, 2, 3, 4, 5, 6, 7, 8, 9});
+
+ LeAudioLtvMap ltv_map_2nd_half;
+ ltv_map_2nd_half.Add(0, (uint8_t)127);
+ ltv_map_2nd_half.Add(2, (uint32_t)65535);
+
+ ASSERT_NE(ltv_map_1st_half, ltv_map_2nd_half);
+ ASSERT_NE(ltv_map, ltv_map_2nd_half);
+
+ hash = ltv_map.GetHash();
+ ltv_map.RemoveAllTypes(ltv_map_1st_half);
+ ASSERT_NE(hash, ltv_map.GetHash());
+
+ hash = ltv_map.GetHash();
+ ltv_map.RemoveAllTypes(ltv_map_2nd_half);
+ ASSERT_NE(hash, ltv_map.GetHash());
+
+ // Check if empty maps have equal hash
+ LeAudioLtvMap empty_ltv_map;
+ ASSERT_EQ(empty_ltv_map, ltv_map);
+}
+
+TEST(LeAudioLtvMapTest, test_intersection) {
+ LeAudioLtvMap ltv_map_one;
+ ltv_map_one.Add(1, (uint16_t)32767);
+ ltv_map_one.Add(3, std::vector<uint8_t>{1, 2, 3, 4, 5, 6, 7, 8, 9});
+ ltv_map_one.Add(2, (uint32_t)65535);
+
+ LeAudioLtvMap ltv_map_two;
+ ltv_map_two.Add(0, (uint8_t)127);
+ // Not the type is the same but value differs
+ ltv_map_two.Add(1, (uint16_t)32766);
+ ltv_map_two.Add(2, (uint32_t)65535);
+
+ LeAudioLtvMap ltv_map_common;
+ ltv_map_common.Add(2, (uint32_t)65535);
+ ASSERT_NE(ltv_map_common.GetHash(), 0lu);
+
+ ASSERT_EQ(ltv_map_one.GetIntersection(ltv_map_two).GetHash(),
+ ltv_map_common.GetHash());
+ ASSERT_EQ(ltv_map_two.GetIntersection(ltv_map_one), ltv_map_common);
+}
+
} // namespace types
} // namespace le_audio
diff --git a/system/bta/le_audio/le_audio_utils.cc b/system/bta/le_audio/le_audio_utils.cc
index 01ffccadf9..52481c43a1 100644
--- a/system/bta/le_audio/le_audio_utils.cc
+++ b/system/bta/le_audio/le_audio_utils.cc
@@ -328,6 +328,15 @@ static bool is_known_codec(const types::LeAudioCodecId& codec_id) {
static void fillRemotePacsCapabitiliesToBtLeAudioCodecConfig(
const struct types::acs_ac_record& record,
std::vector<bluetooth::le_audio::btle_audio_codec_config_t>& vec) {
+ if (!utils::IsCodecUsingLtvFormat(record.codec_id)) {
+ LOG_WARN(
+ "Unknown codec capability format. Unable to report known codec "
+ "parameters.");
+ return;
+ }
+ ASSERT_LOG(!record.codec_spec_caps.IsEmpty(),
+ "Codec specific capabilities are not parsed approprietly.");
+
const struct types::LeAudioCoreCodecCapabilities capa =
record.codec_spec_caps.GetAsCoreCodecCapabilities();
for (uint8_t freq_bit = codec_spec_conf::kLeAudioSamplingFreq8000Hz;
@@ -389,5 +398,11 @@ GetRemoteBtLeAudioCodecConfigFromPac(
return vec;
}
+bool IsCodecUsingLtvFormat(const types::LeAudioCodecId& codec_id) {
+ if (codec_id == set_configurations::LeAudioCodecIdLc3) {
+ return true;
+ }
+ return false;
+}
} // namespace utils
} // namespace le_audio
diff --git a/system/bta/le_audio/le_audio_utils.h b/system/bta/le_audio/le_audio_utils.h
index c15e655f97..ae69856975 100644
--- a/system/bta/le_audio/le_audio_utils.h
+++ b/system/bta/le_audio/le_audio_utils.h
@@ -57,5 +57,6 @@ void fillStreamParamsToBtLeAudioCodecConfig(
std::vector<bluetooth::le_audio::btle_audio_codec_config_t>
GetRemoteBtLeAudioCodecConfigFromPac(
const types::PublishedAudioCapabilities& group_pacs);
+bool IsCodecUsingLtvFormat(const types::LeAudioCodecId& codec_id);
} // namespace utils
} // namespace le_audio
diff --git a/system/bta/le_audio/mock_codec_manager.cc b/system/bta/le_audio/mock_codec_manager.cc
index 2198c03326..ea155c249e 100644
--- a/system/bta/le_audio/mock_codec_manager.cc
+++ b/system/bta/le_audio/mock_codec_manager.cc
@@ -63,9 +63,9 @@ CodecManager::GetOffloadCodecConfig(types::LeAudioContextType ctx_type) {
}
const ::le_audio::broadcast_offload_config*
-CodecManager::GetBroadcastOffloadConfig() {
+CodecManager::GetBroadcastOffloadConfig(uint8_t preferred_quality) {
if (!pimpl_) return nullptr;
- return pimpl_->GetBroadcastOffloadConfig();
+ return pimpl_->GetBroadcastOffloadConfig(preferred_quality);
}
std::vector<bluetooth::le_audio::btle_audio_codec_config_t>
diff --git a/system/bta/le_audio/mock_codec_manager.h b/system/bta/le_audio/mock_codec_manager.h
index 0025b13245..3a26639e97 100644
--- a/system/bta/le_audio/mock_codec_manager.h
+++ b/system/bta/le_audio/mock_codec_manager.h
@@ -43,7 +43,7 @@ class MockCodecManager {
GetOffloadCodecConfig,
(le_audio::types::LeAudioContextType ctx_type), (const));
MOCK_METHOD((le_audio::broadcast_offload_config*), GetBroadcastOffloadConfig,
- (), (const));
+ (uint8_t preferred_quality), (const));
MOCK_METHOD((std::vector<bluetooth::le_audio::btle_audio_codec_config_t>),
GetLocalAudioOutputCodecCapa, ());
MOCK_METHOD((std::vector<bluetooth::le_audio::btle_audio_codec_config_t>),
diff --git a/system/bta/le_audio/state_machine.cc b/system/bta/le_audio/state_machine.cc
index 8dc4c44fa5..af9111fd53 100644
--- a/system/bta/le_audio/state_machine.cc
+++ b/system/bta/le_audio/state_machine.cc
@@ -1895,7 +1895,7 @@ class LeAudioGroupStateMachineImpl : public LeAudioGroupStateMachine {
conf.target_latency = ase->target_latency;
conf.target_phy = group->GetTargetPhy(ase->direction);
conf.codec_id = ase->codec_id;
- conf.codec_config = ase->codec_config;
+ conf.codec_config = ase->codec_config.RawPacket();
confs.push_back(conf);
msg_stream << "ASE_ID " << +conf.ase_id << ",";
diff --git a/system/bta/le_audio/state_machine_test.cc b/system/bta/le_audio/state_machine_test.cc
index 331050744b..75aa6b25fa 100644
--- a/system/bta/le_audio/state_machine_test.cc
+++ b/system/bta/le_audio/state_machine_test.cc
@@ -781,6 +781,24 @@ class StateMachineTestBase : public Test {
uint8_t coding_format = codec_specific::kLc3CodingFormat,
uint16_t vendor_company_id = 0x0000, uint16_t vendor_codec_id = 0x0000,
std::vector<uint8_t> metadata = {}) {
+ auto ltv_map = types::LeAudioLtvMap({
+ {codec_specific::kCapTypeSupportedSamplingFrequencies,
+ {(uint8_t)(sampling_frequencies_bitfield),
+ (uint8_t)(sampling_frequencies_bitfield >> 8)}},
+ {codec_specific::kCapTypeSupportedFrameDurations,
+ {supported_frame_durations_bitfield}},
+ {codec_specific::kCapTypeAudioChannelCount,
+ {audio_channel_count_bitfield}},
+ {codec_specific::kCapTypeSupportedOctetsPerCodecFrame,
+ {
+ // Min
+ (uint8_t)(supported_octets_per_codec_frame_min),
+ (uint8_t)(supported_octets_per_codec_frame_min >> 8),
+ // Max
+ (uint8_t)(supported_octets_per_codec_frame_max),
+ (uint8_t)(supported_octets_per_codec_frame_max >> 8),
+ }},
+ });
recs.push_back({
.codec_id =
{
@@ -788,24 +806,8 @@ class StateMachineTestBase : public Test {
.vendor_company_id = vendor_company_id,
.vendor_codec_id = vendor_codec_id,
},
- .codec_spec_caps = types::LeAudioLtvMap({
- {codec_specific::kCapTypeSupportedSamplingFrequencies,
- {(uint8_t)(sampling_frequencies_bitfield),
- (uint8_t)(sampling_frequencies_bitfield >> 8)}},
- {codec_specific::kCapTypeSupportedFrameDurations,
- {supported_frame_durations_bitfield}},
- {codec_specific::kCapTypeAudioChannelCount,
- {audio_channel_count_bitfield}},
- {codec_specific::kCapTypeSupportedOctetsPerCodecFrame,
- {
- // Min
- (uint8_t)(supported_octets_per_codec_frame_min),
- (uint8_t)(supported_octets_per_codec_frame_min >> 8),
- // Max
- (uint8_t)(supported_octets_per_codec_frame_max),
- (uint8_t)(supported_octets_per_codec_frame_max >> 8),
- }},
- }),
+ .codec_spec_caps = ltv_map,
+ .codec_spec_caps_raw = ltv_map.RawPacket(),
.metadata = std::move(metadata),
});
}
diff --git a/system/bta/le_audio/storage_helper.cc b/system/bta/le_audio/storage_helper.cc
index 92b9cbca27..8938d9358a 100644
--- a/system/bta/le_audio/storage_helper.cc
+++ b/system/bta/le_audio/storage_helper.cc
@@ -80,7 +80,7 @@ bool serializePacs(const le_audio::types::PublishedAudioCapabilities& pacs,
for (const auto& pac : pac_recs) {
pac_bin_size += LEAUDIO_PACS_ENTRY_SZ;
pac_bin_size += pac.metadata.size();
- pac_bin_size += pac.codec_spec_caps.RawPacketSize();
+ pac_bin_size += pac.codec_spec_caps_raw.size();
}
}
@@ -106,8 +106,8 @@ bool serializePacs(const le_audio::types::PublishedAudioCapabilities& pacs,
for (const auto& pac : pac_recs) {
/* Pac len */
- auto pac_len = LEAUDIO_PACS_ENTRY_SZ +
- pac.codec_spec_caps.RawPacketSize() + pac.metadata.size();
+ auto pac_len = LEAUDIO_PACS_ENTRY_SZ + pac.codec_spec_caps_raw.size() +
+ pac.metadata.size();
LOG_VERBOSE("Pac size %d", static_cast<int>(pac_len));
UINT8_TO_STREAM(ptr, pac_len - 1 /* Minus size */);
@@ -118,10 +118,11 @@ bool serializePacs(const le_audio::types::PublishedAudioCapabilities& pacs,
/* Codec caps */
LOG_VERBOSE("Codec capability size %d",
- static_cast<int>(pac.codec_spec_caps.RawPacketSize()));
- UINT8_TO_STREAM(ptr, pac.codec_spec_caps.RawPacketSize());
- if (pac.codec_spec_caps.RawPacketSize() > 0) {
- ptr = pac.codec_spec_caps.RawPacket(ptr);
+ static_cast<int>(pac.codec_spec_caps_raw.size()));
+ UINT8_TO_STREAM(ptr, pac.codec_spec_caps_raw.size());
+ if (pac.codec_spec_caps_raw.size() > 0) {
+ ARRAY_TO_STREAM(ptr, pac.codec_spec_caps_raw.data(),
+ static_cast<int>(pac.codec_spec_caps_raw.size()));
}
/* Metadata */
diff --git a/system/bta/test/bta_jv_test.cc b/system/bta/test/bta_jv_test.cc
new file mode 100644
index 0000000000..a1eeb1c46f
--- /dev/null
+++ b/system/bta/test/bta_jv_test.cc
@@ -0,0 +1,350 @@
+/*
+ * Copyright 2024 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.
+ */
+
+#include <gtest/gtest.h>
+
+#include <memory>
+
+#include "bta/jv/bta_jv_int.h"
+#include "bta_jv_api.h"
+#include "osi/include/allocator.h"
+#include "stack/include/sdp_status.h"
+#include "test/common/mock_functions.h"
+#include "test/fake/fake_osi.h"
+#include "test/mock/mock_stack_sdp_legacy_api.h"
+#include "types/bluetooth/uuid.h"
+#include "types/raw_address.h"
+
+namespace {
+const RawAddress kRawAddress = RawAddress({0x11, 0x22, 0x33, 0x44, 0x55, 0x66});
+const RawAddress kRawAddress2 =
+ RawAddress({0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc});
+const bluetooth::Uuid kUuid = bluetooth::Uuid::From16Bit(0x1234);
+const bluetooth::Uuid kUuid2 = bluetooth::Uuid::From16Bit(0x789a);
+
+constexpr uint32_t kSlotId = 0x1234568;
+constexpr uint8_t kScn = 123;
+
+} // namespace
+
+namespace bluetooth::legacy::testing {
+
+void bta_jv_start_discovery_cback(const RawAddress& bd_addr, tSDP_RESULT result,
+ const void* user_data);
+
+} // namespace bluetooth::legacy::testing
+
+class FakeSdp {
+ public:
+ FakeSdp() {
+ test::mock::stack_sdp_legacy::api_ = {
+ .service = {
+ .SDP_InitDiscoveryDb = [](tSDP_DISCOVERY_DB*, uint32_t, uint16_t,
+ const bluetooth::Uuid*, uint16_t,
+ const uint16_t*) -> bool { return true; },
+ .SDP_CancelServiceSearch = nullptr,
+ .SDP_ServiceSearchRequest = nullptr,
+ .SDP_ServiceSearchAttributeRequest = nullptr,
+ .SDP_ServiceSearchAttributeRequest2 =
+ [](const RawAddress& /* p_bd_addr */,
+ tSDP_DISCOVERY_DB* /* p_db */,
+ tSDP_DISC_CMPL_CB2* /* p_cb2 */, const void* user_data) {
+ if (user_data) osi_free((void*)user_data);
+ return true;
+ },
+ },
+ .db =
+ {
+ .SDP_FindServiceInDb = nullptr,
+ .SDP_FindServiceUUIDInDb =
+ [](const tSDP_DISCOVERY_DB* /* p_db */,
+ const bluetooth::Uuid& /* uuid */,
+ tSDP_DISC_REC* /* p_start_rec */) -> tSDP_DISC_REC* {
+ return nullptr;
+ },
+ .SDP_FindServiceInDb_128bit = nullptr,
+ },
+ .record =
+ {
+ .SDP_FindAttributeInRec = nullptr,
+ .SDP_FindServiceUUIDInRec_128bit = nullptr,
+ .SDP_FindProtocolListElemInRec =
+ [](const tSDP_DISC_REC* /* p_rec */,
+ uint16_t /* layer_uuid */,
+ tSDP_PROTOCOL_ELEM* /* p_elem */) -> bool {
+ return false;
+ },
+ .SDP_FindProfileVersionInRec = nullptr,
+ .SDP_FindServiceUUIDInRec = nullptr,
+ },
+ .handle =
+ {
+ .SDP_CreateRecord = nullptr,
+ .SDP_DeleteRecord = nullptr,
+ .SDP_AddAttribute = nullptr,
+ .SDP_AddSequence = nullptr,
+ .SDP_AddUuidSequence = nullptr,
+ .SDP_AddProtocolList = nullptr,
+ .SDP_AddAdditionProtoLists = nullptr,
+ .SDP_AddProfileDescriptorList = nullptr,
+ .SDP_AddLanguageBaseAttrIDList = nullptr,
+ .SDP_AddServiceClassIdList = nullptr,
+ },
+ .device_id =
+ {
+ .SDP_SetLocalDiRecord = nullptr,
+ .SDP_DiDiscover = nullptr,
+ .SDP_GetNumDiRecords = nullptr,
+ .SDP_GetDiRecord = nullptr,
+ },
+ };
+ }
+
+ ~FakeSdp() { test::mock::stack_sdp_legacy::api_ = {}; }
+};
+
+class BtaJvMockAndFakeTest : public ::testing::Test {
+ protected:
+ void SetUp() override {
+ reset_mock_function_count_map();
+ fake_osi_ = std::make_unique<test::fake::FakeOsi>();
+ fake_sdp_ = std::make_unique<FakeSdp>();
+ }
+
+ void TearDown() override {}
+
+ std::unique_ptr<test::fake::FakeOsi> fake_osi_;
+ std::unique_ptr<FakeSdp> fake_sdp_;
+};
+
+class BtaJvTest : public BtaJvMockAndFakeTest {
+ protected:
+ void SetUp() override {
+ BtaJvMockAndFakeTest::SetUp();
+ bta_jv_cb.sdp_cb = {};
+ }
+
+ void TearDown() override {
+ bta_jv_cb.sdp_cb = {};
+ BtaJvMockAndFakeTest::TearDown();
+ }
+};
+
+TEST_F(BtaJvTest, bta_jv_start_discovery_cback__no_callback) {
+ uint32_t* user_data = (uint32_t*)osi_malloc(sizeof(uint32_t));
+ *user_data = 0x12345678;
+
+ bta_jv_enable(nullptr);
+ bluetooth::legacy::testing::bta_jv_start_discovery_cback(
+ kRawAddress, SDP_SUCCESS, (const void*)user_data);
+}
+
+TEST_F(BtaJvTest,
+ bta_jv_start_discovery_cback__with_callback_success_no_record) {
+ uint32_t* user_data = (uint32_t*)osi_malloc(sizeof(uint32_t));
+ *user_data = kSlotId;
+
+ // Ensure that there was an sdp active
+ bta_jv_cb.sdp_cb = {
+ .sdp_active = true,
+ .bd_addr = kRawAddress,
+ .uuid = kUuid,
+ };
+ bta_jv_enable([](tBTA_JV_EVT event, tBTA_JV* p_data, uint32_t id) {
+ switch (event) {
+ case BTA_JV_DISCOVERY_COMP_EVT:
+ ASSERT_EQ(p_data->disc_comp.status, tBTA_JV_STATUS::FAILURE);
+ ASSERT_EQ(kSlotId, id);
+ break;
+
+ case BTA_JV_ENABLE_EVT:
+ ASSERT_EQ(p_data->disc_comp.status, tBTA_JV_STATUS::SUCCESS);
+ ASSERT_EQ(0U, id);
+ break;
+
+ default:
+ FAIL();
+ }
+ });
+ bluetooth::legacy::testing::bta_jv_start_discovery_cback(
+ kRawAddress, SDP_SUCCESS, (const void*)user_data);
+}
+
+TEST_F(BtaJvTest,
+ bta_jv_start_discovery_cback__with_callback_success_with_record) {
+ uint32_t* user_data = (uint32_t*)osi_malloc(sizeof(uint32_t));
+ *user_data = kSlotId;
+
+ static tSDP_DISC_REC sdp_disc_rec = {
+ .p_first_attr = nullptr,
+ .p_next_rec = nullptr,
+ .time_read = 1,
+ .remote_bd_addr = RawAddress::kAny,
+ };
+
+ test::mock::stack_sdp_legacy::api_.db.SDP_FindServiceUUIDInDb =
+ [](const tSDP_DISCOVERY_DB* /* p_db */, const bluetooth::Uuid& /* uuid */,
+ tSDP_DISC_REC* /* p_start_rec */) -> tSDP_DISC_REC* {
+ return &sdp_disc_rec;
+ };
+
+ test::mock::stack_sdp_legacy::api_.record.SDP_FindProtocolListElemInRec =
+ [](const tSDP_DISC_REC* /* p_rec */, uint16_t /* layer_uuid */,
+ tSDP_PROTOCOL_ELEM* p_elem) -> bool {
+ p_elem->params[0] = (uint16_t)kScn;
+ return true;
+ };
+
+ // Ensure that there was an sdp active
+ bta_jv_cb.sdp_cb = {
+ .sdp_active = true,
+ .bd_addr = kRawAddress,
+ .uuid = kUuid,
+ };
+ bta_jv_enable([](tBTA_JV_EVT event, tBTA_JV* p_data, uint32_t id) {
+ switch (event) {
+ case BTA_JV_DISCOVERY_COMP_EVT:
+ ASSERT_EQ(tBTA_JV_STATUS::SUCCESS, p_data->disc_comp.status);
+ ASSERT_EQ(kScn, p_data->disc_comp.scn);
+ ASSERT_EQ(kSlotId, id);
+ break;
+
+ case BTA_JV_ENABLE_EVT:
+ ASSERT_EQ(tBTA_JV_STATUS::SUCCESS, p_data->disc_comp.status);
+ ASSERT_EQ(0U, id);
+ break;
+
+ default:
+ FAIL();
+ }
+ });
+ bluetooth::legacy::testing::bta_jv_start_discovery_cback(
+ kRawAddress, SDP_SUCCESS, (const void*)user_data);
+}
+
+TEST_F(BtaJvTest, bta_jv_start_discovery_cback__with_callback_failure) {
+ tSDP_RESULT result = SDP_CONN_FAILED;
+ uint32_t* user_data = (uint32_t*)osi_malloc(sizeof(uint32_t));
+ *user_data = kSlotId;
+
+ // Ensure that there was an sdp active
+ bta_jv_cb.sdp_cb = {
+ .sdp_active = true,
+ .bd_addr = kRawAddress,
+ .uuid = kUuid,
+ };
+ bta_jv_enable([](tBTA_JV_EVT event, tBTA_JV* p_data, uint32_t id) {
+ switch (event) {
+ case BTA_JV_DISCOVERY_COMP_EVT:
+ ASSERT_EQ(tBTA_JV_STATUS::FAILURE, p_data->disc_comp.status);
+ ASSERT_EQ(kSlotId, id);
+ break;
+
+ case BTA_JV_ENABLE_EVT:
+ ASSERT_EQ(tBTA_JV_STATUS::SUCCESS, p_data->disc_comp.status);
+ ASSERT_EQ(0U, id);
+ break;
+
+ default:
+ FAIL();
+ }
+ });
+ bluetooth::legacy::testing::bta_jv_start_discovery_cback(
+ kRawAddress, result, (const void*)user_data);
+}
+
+TEST_F(BtaJvTest, bta_jv_start_discovery__idle) {
+ bluetooth::Uuid uuid_list[1] = {
+ kUuid,
+ };
+ uint16_t num_uuid = (uint16_t)(sizeof(uuid_list) / sizeof(uuid_list[0]));
+
+ bta_jv_start_discovery(kRawAddress, num_uuid, uuid_list, kSlotId);
+
+ ASSERT_EQ(true, bta_jv_cb.sdp_cb.sdp_active);
+ ASSERT_EQ(kRawAddress, bta_jv_cb.sdp_cb.bd_addr);
+ ASSERT_EQ(kUuid, bta_jv_cb.sdp_cb.uuid);
+}
+
+TEST_F(BtaJvTest, bta_jv_start_discovery__idle_failed_to_start) {
+ bluetooth::Uuid uuid_list[1] = {
+ kUuid,
+ };
+ uint16_t num_uuid = (uint16_t)(sizeof(uuid_list) / sizeof(uuid_list[0]));
+
+ test::mock::stack_sdp_legacy::api_.service
+ .SDP_ServiceSearchAttributeRequest2 =
+ [](const RawAddress& /* p_bd_addr */, tSDP_DISCOVERY_DB* /* p_db */,
+ tSDP_DISC_CMPL_CB2* /* p_cb2 */,
+ const void* /* user_data */) { return false; };
+
+ bta_jv_enable([](tBTA_JV_EVT event, tBTA_JV* p_data, uint32_t id) {
+ switch (event) {
+ case BTA_JV_DISCOVERY_COMP_EVT:
+ ASSERT_EQ(tBTA_JV_STATUS::FAILURE, p_data->disc_comp.status);
+ ASSERT_EQ(kSlotId, id);
+ break;
+
+ case BTA_JV_ENABLE_EVT:
+ ASSERT_EQ(tBTA_JV_STATUS::SUCCESS, p_data->disc_comp.status);
+ ASSERT_EQ(0U, id);
+ break;
+
+ default:
+ FAIL();
+ }
+ });
+ bta_jv_start_discovery(kRawAddress2, num_uuid, uuid_list, kSlotId);
+
+ ASSERT_EQ(false, bta_jv_cb.sdp_cb.sdp_active);
+ ASSERT_EQ(RawAddress::kEmpty, bta_jv_cb.sdp_cb.bd_addr);
+ ASSERT_EQ(bluetooth::Uuid::kEmpty, bta_jv_cb.sdp_cb.uuid);
+}
+
+TEST_F(BtaJvTest, bta_jv_start_discovery__already_active) {
+ bta_jv_cb.sdp_cb = {
+ .sdp_active = true,
+ .bd_addr = kRawAddress,
+ .uuid = kUuid,
+ };
+
+ bluetooth::Uuid uuid_list[1] = {
+ kUuid2,
+ };
+ uint16_t num_uuid = (uint16_t)(sizeof(uuid_list) / sizeof(uuid_list[0]));
+
+ bta_jv_enable([](tBTA_JV_EVT event, tBTA_JV* p_data, uint32_t id) {
+ switch (event) {
+ case BTA_JV_DISCOVERY_COMP_EVT:
+ ASSERT_EQ(tBTA_JV_STATUS::BUSY, p_data->disc_comp.status);
+ ASSERT_EQ(kSlotId, id);
+ break;
+
+ case BTA_JV_ENABLE_EVT:
+ ASSERT_EQ(tBTA_JV_STATUS::SUCCESS, p_data->disc_comp.status);
+ ASSERT_EQ(0U, id);
+ break;
+
+ default:
+ FAIL();
+ }
+ });
+ bta_jv_start_discovery(kRawAddress2, num_uuid, uuid_list, kSlotId);
+
+ ASSERT_EQ(true, bta_jv_cb.sdp_cb.sdp_active);
+ ASSERT_EQ(kRawAddress, bta_jv_cb.sdp_cb.bd_addr);
+ ASSERT_EQ(kUuid, bta_jv_cb.sdp_cb.uuid);
+}
diff --git a/system/btif/Android.bp b/system/btif/Android.bp
index 497cb5fe69..6faaac5095 100644
--- a/system/btif/Android.bp
+++ b/system/btif/Android.bp
@@ -244,6 +244,7 @@ cc_library_static {
"libbt-platform-protos-lite",
"libbt-stack-core",
"libbt_shim_bridge",
+ "libcom.android.sysprop.bluetooth.wrapped",
"libflatbuffers-cpp",
"libstatslog_bt",
],
@@ -287,6 +288,7 @@ cc_test {
],
header_libs: ["libbluetooth_headers"],
shared_libs: [
+ "libbase",
"libcrypto",
"libcutils",
"libhidlbase",
@@ -396,7 +398,10 @@ cc_test {
cflags: [
"-Wno-unused-parameter",
],
- shared_libs: ["liblog"],
+ shared_libs: [
+ "libbase",
+ "liblog",
+ ],
}
// btif avrcp audio track unit tests
@@ -430,6 +435,7 @@ cc_test {
"libosi",
],
shared_libs: [
+ "libbase",
"liblog",
],
cflags: [
@@ -460,6 +466,7 @@ cc_test {
],
header_libs: ["libbluetooth_headers"],
shared_libs: [
+ "libbase",
"libcrypto",
"libcutils",
"liblog",
@@ -510,6 +517,7 @@ cc_test {
],
header_libs: ["libbluetooth_headers"],
shared_libs: [
+ "libbase",
"libbinder_ndk",
"libcrypto",
"libcutils",
@@ -551,6 +559,7 @@ cc_test {
],
header_libs: ["libbluetooth_headers"],
shared_libs: [
+ "libbase",
"libcutils",
"liblog",
],
diff --git a/system/btif/avrcp/avrcp_service.cc b/system/btif/avrcp/avrcp_service.cc
index 627907ff56..aaa200b55d 100644
--- a/system/btif/avrcp/avrcp_service.cc
+++ b/system/btif/avrcp/avrcp_service.cc
@@ -20,6 +20,7 @@
#include <base/logging.h>
#include <base/task/cancelable_task_tracker.h>
#include <base/threading/thread.h>
+#include <bluetooth/log.h>
#include <mutex>
#include <sstream>
@@ -374,7 +375,7 @@ class PlayerSettingsInterfaceWrapper : public PlayerSettingsInterface {
void AvrcpService::Init(MediaInterface* media_interface,
VolumeInterface* volume_interface,
PlayerSettingsInterface* player_settings_interface) {
- LOG(INFO) << "AVRCP Target Service started";
+ log::info("AVRCP Target Service started");
profile_version = avrcp_interface_.GetAvrcpVersion();
@@ -435,7 +436,7 @@ uint16_t AvrcpService::GetSupportedFeatures(uint16_t profile_version) {
}
void AvrcpService::Cleanup() {
- LOG(INFO) << "AVRCP Target Service stopped";
+ log::info("AVRCP Target Service stopped");
avrcp_interface_.RemoveRecord(sdp_record_handle);
bta_sys_remove_uuid(UUID_SERVCLASS_AV_REM_CTRL_TARGET);
@@ -456,8 +457,8 @@ void AvrcpService::Cleanup() {
}
void AvrcpService::RegisterBipServer(int psm) {
- LOG(INFO) << "AVRCP Target Service has registered a BIP OBEX server, psm="
- << psm;
+ log::info("AVRCP Target Service has registered a BIP OBEX server, psm={}",
+ psm);
avrcp_interface_.RemoveRecord(sdp_record_handle);
uint16_t supported_features
= GetSupportedFeatures(profile_version) | AVRC_SUPF_TG_PLAYER_COVER_ART;
@@ -469,7 +470,7 @@ void AvrcpService::RegisterBipServer(int psm) {
}
void AvrcpService::UnregisterBipServer() {
- LOG(INFO) << "AVRCP Target Service has unregistered a BIP OBEX server";
+ log::info("AVRCP Target Service has unregistered a BIP OBEX server");
avrcp_interface_.RemoveRecord(sdp_record_handle);
uint16_t supported_features = GetSupportedFeatures(profile_version);
sdp_record_handle = get_legacy_stack_sdp_api()->handle.SDP_CreateRecord();
@@ -493,32 +494,27 @@ ServiceInterface* AvrcpService::GetServiceInterface() {
}
void AvrcpService::ConnectDevice(const RawAddress& bdaddr) {
- LOG(INFO) << __PRETTY_FUNCTION__
- << ": address=" << ADDRESS_TO_LOGGABLE_STR(bdaddr);
+ log::info("address={}", ADDRESS_TO_LOGGABLE_STR(bdaddr));
connection_handler_->ConnectDevice(bdaddr);
}
void AvrcpService::DisconnectDevice(const RawAddress& bdaddr) {
- LOG(INFO) << __PRETTY_FUNCTION__
- << ": address=" << ADDRESS_TO_LOGGABLE_STR(bdaddr);
+ log::info("address={}", ADDRESS_TO_LOGGABLE_STR(bdaddr));
connection_handler_->DisconnectDevice(bdaddr);
}
void AvrcpService::SetBipClientStatus(const RawAddress& bdaddr,
bool connected) {
- LOG(INFO) << __PRETTY_FUNCTION__
- << ": address=" << ADDRESS_TO_LOGGABLE_STR(bdaddr)
- << ", connected=" << connected;
+ log::info("address={}, connected={}", ADDRESS_TO_LOGGABLE_STR(bdaddr),
+ connected);
connection_handler_->SetBipClientStatus(bdaddr, connected);
}
void AvrcpService::SendMediaUpdate(bool track_changed, bool play_state,
bool queue) {
- LOG(INFO) << __PRETTY_FUNCTION__ << " track_changed=" << track_changed
- << " : "
- << " play_state=" << play_state << " : "
- << " queue=" << queue;
+ log::info("track_changed={} : play_state={} : queue={}", track_changed,
+ play_state, queue);
// This function may be called on any thread, we need to make sure that the
// device update happens on the main thread.
@@ -532,10 +528,8 @@ void AvrcpService::SendMediaUpdate(bool track_changed, bool play_state,
void AvrcpService::SendFolderUpdate(bool available_players,
bool addressed_players, bool uids) {
- LOG(INFO) << __PRETTY_FUNCTION__ << " available_players=" << available_players
- << " : "
- << " addressed_players=" << addressed_players << " : "
- << " uids=" << uids;
+ log::info("available_players={} : addressed_players={} : uids={}",
+ available_players, addressed_players, uids);
// Ensure that the update is posted to the correct thread
for (const auto& device :
@@ -554,7 +548,7 @@ void AvrcpService::SendActiveDeviceChanged(const RawAddress& address) {
void AvrcpService::SendPlayerSettingsChanged(
std::vector<PlayerAttribute> attributes, std::vector<uint8_t> values) {
- LOG(INFO) << __PRETTY_FUNCTION__;
+ log::info("");
std::stringstream ss;
for (size_t i = 0; i < attributes.size(); i++) {
ss << "attribute=" << attributes.at(i) << " : ";
@@ -568,7 +562,7 @@ void AvrcpService::SendPlayerSettingsChanged(
ss << std::endl;
}
- LOG(INFO) << ss.str();
+ log::info("{}", ss.str());
// Ensure that the update is posted to the correct thread
for (const auto& device :
@@ -694,7 +688,7 @@ void AvrcpService::DebugDump(int fd) {
/** when a2dp connected, btif will start register vol changed, so we need a
* interface for it. */
void AvrcpService::RegisterVolChanged(const RawAddress& bdaddr) {
- LOG(INFO) << ": address=" << ADDRESS_TO_LOGGABLE_STR(bdaddr);
+ log::info(": address={}", ADDRESS_TO_LOGGABLE_STR(bdaddr));
connection_handler_->RegisterVolChanged(bdaddr);
}
diff --git a/system/btif/co/bta_av_co.cc b/system/btif/co/bta_av_co.cc
index a567296a9e..667c40f545 100644
--- a/system/btif/co/bta_av_co.cc
+++ b/system/btif/co/bta_av_co.cc
@@ -25,6 +25,7 @@
#include "btif/include/bta_av_co.h"
+#include <android_bluetooth_flags.h>
#include <bluetooth/log.h>
#include <mutex>
@@ -105,6 +106,8 @@ void BtaAvCo::Init(
void BtaAvCo::Reset() {
bta_av_legacy_state_.Reset();
+ bta_av_source_state_.Reset();
+ bta_av_sink_state_.Reset();
content_protect_flag_ = 0;
if (ContentProtectEnabled()) {
@@ -130,7 +133,13 @@ bool BtaAvCo::IsSupportedCodec(btav_a2dp_codec_index_t codec_index) {
A2dpCodecConfig* BtaAvCo::GetActivePeerCurrentCodec() {
std::lock_guard<std::recursive_mutex> lock(peer_cache_->codec_lock_);
- BtaAvCoPeer* active_peer = bta_av_legacy_state_.getActivePeer();
+ BtaAvCoState* reference_state = nullptr;
+ if (IS_FLAG_ENABLED(a2dp_concurrent_source_sink)) {
+ reference_state = &bta_av_source_state_;
+ } else {
+ reference_state = &bta_av_legacy_state_;
+ }
+ BtaAvCoPeer* active_peer = reference_state->getActivePeer();
if (active_peer == nullptr || active_peer->GetCodecs() == nullptr) {
return nullptr;
}
@@ -277,7 +286,7 @@ tA2DP_STATUS BtaAvCo::ProcessSourceGetConfig(
return A2DP_FAIL;
}
} else {
- if (btif_av_peer_prefers_mandatory_codec(p_peer->addr)) {
+ if (btif_av_peer_prefers_mandatory_codec(p_peer->addr, A2dpType::kSource)) {
// Apply user preferred codec directly before first codec selected.
p_sink = peer_cache_->FindPeerSink(
p_peer, BTAV_A2DP_CODEC_INDEX_SOURCE_SBC, ContentProtectFlag());
@@ -530,7 +539,8 @@ void BtaAvCo::ProcessSetConfig(tBTA_AV_HNDL bta_av_handle,
if (codec_config_supported) {
// If Peer is Source, and our config subset matches with what is
// requested by peer, then just accept what peer wants.
- SaveNewCodecConfig(p_peer, p_codec_info, num_protect, p_protect_info);
+ SaveNewCodecConfig(p_peer, p_codec_info, num_protect, p_protect_info,
+ t_local_sep);
}
}
if (t_local_sep == AVDT_TSEP_SRC) {
@@ -541,7 +551,7 @@ void BtaAvCo::ProcessSetConfig(tBTA_AV_HNDL bta_av_handle,
bool dummy_restart_output = false;
if ((p_peer->GetCodecs() == nullptr) ||
!SetCodecOtaConfig(p_peer, p_codec_info, num_protect, p_protect_info,
- &dummy_restart_output)) {
+ &dummy_restart_output, t_local_sep)) {
log::error("cannot set source codec {} for peer {}",
A2DP_CodecName(p_codec_info),
ADDRESS_TO_LOGGABLE_CSTR(p_peer->addr));
@@ -596,10 +606,14 @@ void BtaAvCo::ProcessOpen(tBTA_AV_HNDL bta_av_handle,
p_peer->opened = true;
p_peer->mtu = mtu;
- // The first connected peer becomes the active peer
- BtaAvCoPeer* active_peer = bta_av_legacy_state_.getActivePeer();
+ BtaAvCoState* reference_state = getStateFromPeer(p_peer);
+ if (reference_state == nullptr) {
+ log::warn("Invalid bta av state");
+ return;
+ }
+ BtaAvCoPeer* active_peer = reference_state->getActivePeer();
if (active_peer == nullptr) {
- bta_av_legacy_state_.setActivePeer(p_peer);
+ reference_state->setActivePeer(p_peer);
}
}
@@ -618,10 +632,17 @@ void BtaAvCo::ProcessClose(tBTA_AV_HNDL bta_av_handle,
return;
}
// Reset the active peer
- BtaAvCoPeer* active_peer = bta_av_legacy_state_.getActivePeer();
+
+ BtaAvCoState* reference_state = getStateFromPeer(p_peer);
+ if (reference_state == nullptr) {
+ log::warn("Invalid bta av state");
+ return;
+ }
+ BtaAvCoPeer* active_peer = reference_state->getActivePeer();
if (active_peer == p_peer) {
- bta_av_legacy_state_.setActivePeer(nullptr);
+ reference_state->setActivePeer(nullptr);
}
+
// Mark the peer closed and clean the peer info
p_peer->Init(peer_cache_->codec_priorities_);
}
@@ -686,7 +707,13 @@ BT_HDR* BtaAvCo::GetNextSourceDataPacket(const uint8_t* p_codec_info,
return nullptr;
}
- BtaAvCoPeer* active_peer = bta_av_legacy_state_.getActivePeer();
+ BtaAvCoState* reference_state = nullptr;
+ if (IS_FLAG_ENABLED(a2dp_concurrent_source_sink)) {
+ reference_state = &bta_av_source_state_;
+ } else {
+ reference_state = &bta_av_legacy_state_;
+ }
+ BtaAvCoPeer* active_peer = reference_state->getActivePeer();
// if offset is 0, the decremental operation may result in
// underflow and OOB access
if (ContentProtectEnabled() && (active_peer != nullptr) &&
@@ -712,7 +739,7 @@ void BtaAvCo::ProcessAudioDelay(tBTA_AV_HNDL bta_av_handle,
log::verbose("peer {} bta_av_handle: 0x{:x} delay:0x{:x}",
ADDRESS_TO_LOGGABLE_CSTR(peer_address), bta_av_handle, delay);
- btif_av_set_audio_delay(peer_address, delay);
+ btif_av_set_audio_delay(peer_address, delay, A2dpType::kSource);
}
void BtaAvCo::UpdateMtu(tBTA_AV_HNDL bta_av_handle,
@@ -731,12 +758,19 @@ void BtaAvCo::UpdateMtu(tBTA_AV_HNDL bta_av_handle,
p_peer->mtu = mtu;
}
-bool BtaAvCo::SetActivePeer(const RawAddress& peer_address) {
+bool BtaAvCo::SetActivePeer(const RawAddress& peer_address,
+ const uint8_t t_local_sep) {
log::info("peer_address={}", ADDRESS_TO_LOGGABLE_STR(peer_address));
std::lock_guard<std::recursive_mutex> lock(peer_cache_->codec_lock_);
- BtaAvCoState* reference_state = &bta_av_legacy_state_;
+ BtaAvCoState* reference_state = getStateFromLocalProfile(t_local_sep);
+ if (reference_state == nullptr) {
+ log::warn(
+ "Invalid bta av state for peer_address : {} with local sep as :{}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_address), t_local_sep);
+ return false;
+ }
if (peer_address.IsEmpty()) {
// Reset the active peer;
reference_state->setActivePeer(nullptr);
@@ -759,8 +793,27 @@ bool BtaAvCo::SetActivePeer(const RawAddress& peer_address) {
return true;
}
+BtaAvCoState* BtaAvCo::getStateFromLocalProfile(const uint8_t t_local_sep) {
+ if (IS_FLAG_ENABLED(a2dp_concurrent_source_sink)) {
+ if (t_local_sep == AVDT_TSEP_SRC) {
+ return &bta_av_source_state_;
+ } else if (t_local_sep == AVDT_TSEP_SNK) {
+ return &bta_av_sink_state_;
+ } else {
+ log::warn("Invalid bta av state for local sep type {}", t_local_sep);
+ return nullptr;
+ }
+ } else {
+ return &bta_av_legacy_state_;
+ }
+}
+
void BtaAvCo::SaveCodec(const uint8_t* new_codec_config) {
- bta_av_legacy_state_.setCodecConfig(new_codec_config);
+ if (IS_FLAG_ENABLED(a2dp_concurrent_source_sink)) {
+ bta_av_sink_state_.setCodecConfig(new_codec_config);
+ } else {
+ bta_av_legacy_state_.setCodecConfig(new_codec_config);
+ }
}
void BtaAvCo::GetPeerEncoderParameters(
@@ -780,9 +833,10 @@ void BtaAvCo::GetPeerEncoderParameters(
if (p_peer->mtu < min_mtu) min_mtu = p_peer->mtu;
}
p_peer_params->peer_mtu = min_mtu;
- p_peer_params->is_peer_edr = btif_av_is_peer_edr(peer_address);
+ p_peer_params->is_peer_edr =
+ btif_av_is_peer_edr(peer_address, A2dpType::kSource);
p_peer_params->peer_supports_3mbps =
- btif_av_peer_supports_3mbps(peer_address);
+ btif_av_peer_supports_3mbps(peer_address, A2dpType::kSource);
log::verbose(
"peer_address={} peer_mtu={} is_peer_edr={} peer_supports_3mbps={}",
ADDRESS_TO_LOGGABLE_CSTR(peer_address), p_peer_params->peer_mtu,
@@ -792,7 +846,9 @@ void BtaAvCo::GetPeerEncoderParameters(
const tA2DP_ENCODER_INTERFACE* BtaAvCo::GetSourceEncoderInterface() {
std::lock_guard<std::recursive_mutex> lock(peer_cache_->codec_lock_);
-
+ if (IS_FLAG_ENABLED(a2dp_concurrent_source_sink)) {
+ return A2DP_GetEncoderInterface(bta_av_source_state_.getCodecConfig());
+ }
return A2DP_GetEncoderInterface(bta_av_legacy_state_.getCodecConfig());
}
@@ -887,7 +943,12 @@ done:
// and informing the Media Framework about the change.
// Find the peer that is currently open
- BtaAvCoPeer* active_peer = bta_av_legacy_state_.getActivePeer();
+ BtaAvCoPeer* active_peer;
+ if (IS_FLAG_ENABLED(a2dp_concurrent_source_sink)) {
+ active_peer = bta_av_source_state_.getActivePeer();
+ } else {
+ active_peer = bta_av_legacy_state_.getActivePeer();
+ }
if (p_peer != nullptr &&
(!restart_output || !success || p_peer != active_peer)) {
return ReportSourceCodecState(p_peer);
@@ -905,7 +966,12 @@ bool BtaAvCo::SetCodecAudioConfig(
log::verbose("codec_audio_config: {}", codec_audio_config.ToString());
// Find the peer that is currently open
- BtaAvCoPeer* p_peer = bta_av_legacy_state_.getActivePeer();
+ BtaAvCoPeer* p_peer;
+ if (IS_FLAG_ENABLED(a2dp_concurrent_source_sink)) {
+ p_peer = bta_av_source_state_.getActivePeer();
+ } else {
+ p_peer = bta_av_legacy_state_.getActivePeer();
+ }
if (p_peer == nullptr) {
log::error("no active peer to configure");
return false;
@@ -942,7 +1008,7 @@ bool BtaAvCo::SetCodecAudioConfig(
}
SaveNewCodecConfig(p_peer, result_codec_config, p_sink->num_protect,
- p_sink->protect_info);
+ p_sink->protect_info, AVDT_TSEP_SRC);
p_peer->acceptor = false;
log::verbose("call BTA_AvReconfig({})", loghex(p_peer->BtaAvHandle()));
@@ -962,6 +1028,10 @@ bool BtaAvCo::SetCodecAudioConfig(
int BtaAvCo::GetSourceEncoderEffectiveFrameSize() {
std::lock_guard<std::recursive_mutex> lock(peer_cache_->codec_lock_);
+ if (IS_FLAG_ENABLED(a2dp_concurrent_source_sink)) {
+ return A2DP_GetEecoderEffectiveFrameSize(
+ bta_av_source_state_.getCodecConfig());
+ }
return A2DP_GetEecoderEffectiveFrameSize(
bta_av_legacy_state_.getCodecConfig());
}
@@ -1022,6 +1092,18 @@ void BtaAvCo::DebugDump(int fd) {
a2dp_codecs->debug_codec_dump(fd);
}
}
+ if (bta_av_source_state_.getActivePeer() != nullptr) {
+ A2dpCodecs* a2dp_codecs = bta_av_source_state_.getActivePeer()->GetCodecs();
+ if (a2dp_codecs != nullptr) {
+ a2dp_codecs->debug_codec_dump(fd);
+ }
+ }
+ if (bta_av_sink_state_.getActivePeer() != nullptr) {
+ A2dpCodecs* a2dp_codecs = bta_av_sink_state_.getActivePeer()->GetCodecs();
+ if (a2dp_codecs != nullptr) {
+ a2dp_codecs->debug_codec_dump(fd);
+ }
+ }
dprintf(fd, "\nA2DP Peers State:\n");
dprintf(
@@ -1029,6 +1111,16 @@ void BtaAvCo::DebugDump(int fd) {
(bta_av_legacy_state_.getActivePeer() != nullptr)
? ADDRESS_TO_LOGGABLE_CSTR(bta_av_legacy_state_.getActivePeer()->addr)
: "null");
+ dprintf(
+ fd, " Source: active peer: %s\n",
+ (bta_av_source_state_.getActivePeer() != nullptr)
+ ? ADDRESS_TO_LOGGABLE_CSTR(bta_av_source_state_.getActivePeer()->addr)
+ : "null");
+ dprintf(
+ fd, " Sink: active peer: %s\n",
+ (bta_av_sink_state_.getActivePeer() != nullptr)
+ ? ADDRESS_TO_LOGGABLE_CSTR(bta_av_sink_state_.getActivePeer()->addr)
+ : "null");
for (size_t i = 0; i < BTA_AV_CO_NUM_ELEMENTS(peer_cache_->peers_); i++) {
const BtaAvCoPeer& peer = peer_cache_->peers_[i];
@@ -1108,7 +1200,7 @@ BtaAvCoSep* BtaAvCo::SelectProviderCodecConfiguration(
p_peer->GetCodecs()->setCurrentCodecConfig(codec_config);
p_peer->p_sink = p_sink;
SaveNewCodecConfig(p_peer, provider_codec_config.codec_config,
- p_sink->num_protect, p_sink->protect_info);
+ p_sink->num_protect, p_sink->protect_info, AVDT_TSEP_SRC);
return p_sink;
}
@@ -1216,7 +1308,7 @@ const BtaAvCoSep* BtaAvCo::AttemptSourceCodecSelection(
p_peer->p_sink = p_sink;
SaveNewCodecConfig(p_peer, new_codec_config, p_sink->num_protect,
- p_sink->protect_info);
+ p_sink->protect_info, AVDT_TSEP_SRC);
return p_sink;
}
@@ -1243,7 +1335,7 @@ const BtaAvCoSep* BtaAvCo::AttemptSinkCodecSelection(
p_peer->p_source = p_source;
SaveNewCodecConfig(p_peer, new_codec_config, p_source->num_protect,
- p_source->protect_info);
+ p_source->protect_info, AVDT_TSEP_SNK);
return p_source;
}
@@ -1318,12 +1410,20 @@ bool BtaAvCo::UpdateSelectableSinkCodec(const A2dpCodecConfig& codec_config,
void BtaAvCo::SaveNewCodecConfig(BtaAvCoPeer* p_peer,
const uint8_t* new_codec_config,
uint8_t num_protect,
- const uint8_t* p_protect_info) {
+ const uint8_t* p_protect_info,
+ const uint8_t t_local_sep) {
log::verbose("peer {}", ADDRESS_TO_LOGGABLE_CSTR(p_peer->addr));
log::verbose("codec: {}", A2DP_CodecInfoString(new_codec_config));
std::lock_guard<std::recursive_mutex> lock(peer_cache_->codec_lock_);
- bta_av_legacy_state_.setCodecConfig(new_codec_config);
+ BtaAvCoState* reference_state = getStateFromLocalProfile(t_local_sep);
+ if (reference_state == nullptr) {
+ log::warn(
+ "Invalid bta av state for peer_address : {} with local sep as :{}",
+ ADDRESS_TO_LOGGABLE_CSTR(p_peer->addr), t_local_sep);
+ return;
+ }
+ reference_state->setCodecConfig(new_codec_config);
memcpy(p_peer->codec_config, new_codec_config, AVDT_CODEC_SIZE);
if (ContentProtectEnabled()) {
@@ -1333,11 +1433,29 @@ void BtaAvCo::SaveNewCodecConfig(BtaAvCoPeer* p_peer,
}
}
+BtaAvCoState* BtaAvCo::getStateFromPeer(const BtaAvCoPeer* p_peer) {
+ if (IS_FLAG_ENABLED(a2dp_concurrent_source_sink)) {
+ if (p_peer->uuid_to_connect == UUID_SERVCLASS_AUDIO_SINK) {
+ return &bta_av_source_state_;
+ } else if (p_peer->uuid_to_connect == UUID_SERVCLASS_AUDIO_SOURCE) {
+ return &bta_av_sink_state_;
+ } else {
+ log::warn("Invalid bta av state for peer_address : {} with uuid as :{}",
+ ADDRESS_TO_LOGGABLE_CSTR(p_peer->addr),
+ p_peer->uuid_to_connect);
+ return nullptr;
+ }
+ } else {
+ return &bta_av_legacy_state_;
+ }
+}
+
bool BtaAvCo::SetCodecOtaConfig(BtaAvCoPeer* p_peer,
const uint8_t* p_ota_codec_config,
uint8_t num_protect,
const uint8_t* p_protect_info,
- bool* p_restart_output) {
+ bool* p_restart_output,
+ const uint8_t t_local_sep) {
uint8_t result_codec_config[AVDT_CODEC_SIZE];
bool restart_input = false;
bool restart_output = false;
@@ -1376,8 +1494,8 @@ bool BtaAvCo::SetCodecOtaConfig(BtaAvCoPeer* p_peer,
*p_restart_output = true;
p_peer->p_sink = p_sink;
- SaveNewCodecConfig(p_peer, result_codec_config, num_protect,
- p_protect_info);
+ SaveNewCodecConfig(p_peer, result_codec_config, num_protect, p_protect_info,
+ t_local_sep);
}
if (restart_input || config_updated) {
@@ -1569,7 +1687,15 @@ void bta_av_co_audio_update_mtu(tBTA_AV_HNDL bta_av_handle,
}
bool bta_av_co_set_active_peer(const RawAddress& peer_address) {
- return bta_av_co_cb.SetActivePeer(peer_address);
+ return bta_av_co_cb.SetActivePeer(peer_address, AVDT_TSEP_INVALID);
+}
+
+bool bta_av_co_set_active_sink_peer(const RawAddress& peer_address) {
+ return bta_av_co_cb.SetActivePeer(peer_address, AVDT_TSEP_SNK);
+}
+
+bool bta_av_co_set_active_source_peer(const RawAddress& peer_address) {
+ return bta_av_co_cb.SetActivePeer(peer_address, AVDT_TSEP_SRC);
}
void bta_av_co_save_codec(const uint8_t* new_codec_config) {
diff --git a/system/btif/include/bta_av_co.h b/system/btif/include/bta_av_co.h
index fe7ca50f59..4f6cd70ae4 100644
--- a/system/btif/include/bta_av_co.h
+++ b/system/btif/include/bta_av_co.h
@@ -288,9 +288,10 @@ class BtaAvCo {
* Set the active peer.
*
* @param peer_address the peer address
+ * @param t_local_sep update the active peer for the profile type.
* @return true on success, otherwise false
*/
- bool SetActivePeer(const RawAddress& peer_address);
+ bool SetActivePeer(const RawAddress& peer_address, const uint8_t t_local_sep);
/**
* Save the reconfig codec
@@ -434,9 +435,12 @@ class BtaAvCo {
* @param new_codec_config the new codec configuration to use
* @param num_protect the number of content protection elements
* @param p_protect_info the content protection info to use
+ * @param t_local_sep the profile for which the codec config needs to be
+ * saved.
*/
void SaveNewCodecConfig(BtaAvCoPeer* p_peer, const uint8_t* new_codec_config,
- uint8_t num_protect, const uint8_t* p_protect_info);
+ uint8_t num_protect, const uint8_t* p_protect_info,
+ const uint8_t t_local_sep);
/**
* Set the Over-The-Air preferred codec configuration.
@@ -455,11 +459,12 @@ class BtaAvCo {
* @param p_restart_output if there is a change in the encoder configuration
* that requires restarting of the A2DP connection, flag |p_restart_output|
* is set to true.
+ * @param t_local_sep the profile for which ota config needs to be set.
* @return true on success, otherwise false
*/
bool SetCodecOtaConfig(BtaAvCoPeer* p_peer, const uint8_t* p_ota_codec_config,
uint8_t num_protect, const uint8_t* p_protect_info,
- bool* p_restart_output);
+ bool* p_restart_output, const uint8_t t_local_sep);
/**
* Update all selectable Source codecs with the corresponding codec
@@ -540,9 +545,25 @@ class BtaAvCo {
const ::bluetooth::audio::a2dp::provider::a2dp_configuration&
provider_codec_config);
+ /**
+ * Returns the state that needs to be accessed.
+ * @param p_peer peer address.
+ * @return state of the profile.
+ */
+ BtaAvCoState* getStateFromPeer(const BtaAvCoPeer* p_peer);
+
+ /**
+ * Returns the state based on the local profile of the stack.
+ * @param t_local_sep local sep type
+ * @return state of the profile.
+ */
+ BtaAvCoState* getStateFromLocalProfile(const uint8_t t_local_sep);
+
bool ContentProtectEnabled() const { return content_protect_enabled_; }
const bool content_protect_enabled_; // True if Content Protect is enabled
uint8_t content_protect_flag_; // Content Protect flag
- BtaAvCoState bta_av_legacy_state_;
+ BtaAvCoState bta_av_legacy_state_; // Legacy state
+ BtaAvCoState bta_av_source_state_; // Source profile state
+ BtaAvCoState bta_av_sink_state_; // Sink profile state
};
diff --git a/system/btif/include/btif_a2dp.h b/system/btif/include/btif_a2dp.h
index d9c44d1175..24aacb8deb 100644
--- a/system/btif/include/btif_a2dp.h
+++ b/system/btif/include/btif_a2dp.h
@@ -23,28 +23,37 @@
#include <stdbool.h>
#include "bta/include/bta_av_api.h"
+#include "btif_av.h"
#include "types/raw_address.h"
// Process 'idle' request from the BTIF state machine during initialization.
-void btif_a2dp_on_idle(const RawAddress& peer_addr);
+void btif_a2dp_on_idle(const RawAddress& peer_addr,
+ const A2dpType local_a2dp_type);
// Process 'start' request from the BTIF state machine to prepare for A2DP
// streaming.
// |peer_addr| is the peer address.
// |p_av_start| is the data associated with the request - see |tBTA_AV_START|.
+// |local_a2dp_type| type of local a2dp profile.
// Returns true if an ACK for the local command was sent, otherwise false.
-bool btif_a2dp_on_started(const RawAddress& peer_addr, tBTA_AV_START* p_av_start);
+bool btif_a2dp_on_started(const RawAddress& peer_addr,
+ tBTA_AV_START* p_av_start,
+ const A2dpType local_a2dp_type);
// Process 'stop' request from the BTIF state machine to stop A2DP streaming.
// |p_av_suspend| is the data associated with the request - see
// |tBTA_AV_SUSPEND|.
-void btif_a2dp_on_stopped(tBTA_AV_SUSPEND* p_av_suspend);
+// |local_a2dp_type| type of local a2dp profile.
+void btif_a2dp_on_stopped(tBTA_AV_SUSPEND* p_av_suspend,
+ const A2dpType local_a2dp_type);
// Process 'suspend' request from the BTIF state machine to suspend A2DP
// streaming.
// |p_av_suspend| is the data associated with the request - see
// |tBTA_AV_SUSPEND|.
-void btif_a2dp_on_suspended(tBTA_AV_SUSPEND* p_av_suspend);
+// |local_a2dp_type| type of local a2dp profile.
+void btif_a2dp_on_suspended(tBTA_AV_SUSPEND* p_av_suspend,
+ const A2dpType local_a2dp_type);
// Process 'offload start' request from the BTIF state machine to start
// offloading of the A2DP streaming.
diff --git a/system/btif/include/btif_a2dp_sink.h b/system/btif/include/btif_a2dp_sink.h
index 8875eed850..72eca76654 100644
--- a/system/btif/include/btif_a2dp_sink.h
+++ b/system/btif/include/btif_a2dp_sink.h
@@ -20,6 +20,8 @@
#ifndef BTIF_A2DP_SINK_H
#define BTIF_A2DP_SINK_H
+#include <bluetooth/log.h>
+
#include <cstdint>
#include <future>
@@ -141,4 +143,10 @@ void btif_a2dp_sink_set_audio_track_gain(float gain);
// Get audio track handle
void * btif_a2dp_sink_get_audio_track(void);
+namespace fmt {
+template <>
+struct formatter<btif_a2dp_sink_focus_state_t>
+ : enum_formatter<btif_a2dp_sink_focus_state_t> {};
+} // namespace fmt
+
#endif /* BTIF_A2DP_SINK_H */
diff --git a/system/btif/include/btif_av.h b/system/btif/include/btif_av.h
index 3a44c29350..44b5a237d2 100644
--- a/system/btif/include/btif_av.h
+++ b/system/btif/include/btif_av.h
@@ -33,6 +33,10 @@
// #include "btif/include/btif_common.h"
/**
+ * Enum to represent the type of local a2dp profile.
+ */
+enum class A2dpType { kSource, kSink, kUnknown };
+/**
* When the local device is A2DP source, get the address of the active peer.
*/
RawAddress btif_av_source_active_peer(void);
@@ -54,8 +58,9 @@ bool btif_av_is_source_enabled(void);
/**
* Start streaming.
+ * @param local_a2dp_type type of local a2dp profile.
*/
-void btif_av_stream_start(void);
+void btif_av_stream_start(const A2dpType local_a2dp_type);
/**
* Start streaming with latency setting.
@@ -81,31 +86,36 @@ void btif_av_stream_start_offload(void);
/**
* Check whether ready to start the A2DP stream.
+ * @param local_a2dp_type type of local a2dp profile.
*/
-bool btif_av_stream_ready(void);
+bool btif_av_stream_ready(const A2dpType local_a2dp_type);
/**
* Check whether the A2DP stream is in started state and ready
* for media start.
+ * @param local_a2dp_type type of local a2dp profile.
*/
-bool btif_av_stream_started_ready(void);
+bool btif_av_stream_started_ready(const A2dpType local_a2dp_type);
/**
* Check whether there is a connected peer (either Source or Sink)
+ * @param local_a2dp_type type of local a2dp profile.
*/
-bool btif_av_is_connected(void);
+bool btif_av_is_connected(const A2dpType local_a2dp_type);
/**
* Get the Stream Endpoint Type of the Active peer.
+ * @param local_a2dp_type type of local a2dp profile.
*
* @return the stream endpoint type: either AVDT_TSEP_SRC or AVDT_TSEP_SNK
*/
-uint8_t btif_av_get_peer_sep(void);
+uint8_t btif_av_get_peer_sep(const A2dpType local_a2dp_type);
/**
* Clear the remote suspended flag for the active peer.
+ * @param local_a2dp_type type of local a2dp profile.
*/
-void btif_av_clear_remote_suspend_flag(void);
+void btif_av_clear_remote_suspend_flag(const A2dpType local_a2dp_type);
/**
* Check whether the connected A2DP peer supports EDR.
@@ -114,9 +124,11 @@ void btif_av_clear_remote_suspend_flag(void);
* Otherwise, the answer will be always false.
*
* @param peer_address the peer address
+ * @param local_a2dp_type type of local a2dp profile.
* @return true if the remote peer is capable of EDR
*/
-bool btif_av_is_peer_edr(const RawAddress& peer_address);
+bool btif_av_is_peer_edr(const RawAddress& peer_address,
+ const A2dpType local_a2dp_type);
/**
* Check whether the connected A2DP peer supports 3 Mbps EDR.
@@ -125,17 +137,21 @@ bool btif_av_is_peer_edr(const RawAddress& peer_address);
* Otherwise, the answer will be always false.
*
* @param peer_address the peer address
+ * @param local_a2dp_type type of local a2dp profile.
* @return true if the remote peer is capable of EDR and supports 3 Mbps
*/
-bool btif_av_peer_supports_3mbps(const RawAddress& peer_address);
+bool btif_av_peer_supports_3mbps(const RawAddress& peer_address,
+ const A2dpType local_a2dp_type);
/**
* Check whether the mandatory codec is more preferred for this peer.
*
* @param peer_address the target peer address
+ * @param local_a2dp_type type of local a2dp profile.
* @return true if optional codecs are not preferred to be used
*/
-bool btif_av_peer_prefers_mandatory_codec(const RawAddress& peer_address);
+bool btif_av_peer_prefers_mandatory_codec(const RawAddress& peer_address,
+ const A2dpType local_a2dp_type);
/**
* Report A2DP Source Codec State for a peer.
@@ -173,8 +189,10 @@ bt_status_t btif_av_sink_execute_service(bool enable);
* Peer ACL disconnected.
*
* @param peer_address the disconnected peer address
+ * @param local_a2dp_type type of local a2dp profile.
*/
-void btif_av_acl_disconnected(const RawAddress& peer_address);
+void btif_av_acl_disconnected(const RawAddress& peer_address,
+ const A2dpType local_a2dp_type);
/**
* Dump debug-related information for the BTIF AV module.
@@ -189,14 +207,16 @@ void btif_debug_av_dump(int fd);
*
* @param peer_address the address of the peer to report
* @param delay the delay to set in units of 1/10ms
+ * @param local_a2dp_type type of local a2dp profile.
*/
-void btif_av_set_audio_delay(const RawAddress& peer_address, uint16_t delay);
+void btif_av_set_audio_delay(const RawAddress& peer_address, uint16_t delay,
+ const A2dpType local_a2dp_type);
/**
* Get the audio delay for the stream.
- * @param none
+ * @param local_a2dp_type type of local a2dp profile.
*/
-uint16_t btif_av_get_audio_delay(void);
+uint16_t btif_av_get_audio_delay(const A2dpType local_a2dp_type);
/**
* Reset the audio delay and count of audio bytes sent to zero.
@@ -235,10 +255,12 @@ bool btif_av_is_peer_silenced(const RawAddress& peer_address);
/**
* check the a2dp connect status
*
- * @param address : checked device address
+ * @param peer_address : checked device address
+ * @param local_a2dp_type type of local a2dp profile.
*
*/
-bool btif_av_is_connected_addr(const RawAddress& peer_address);
+bool btif_av_is_connected_addr(const RawAddress& peer_address,
+ const A2dpType local_a2dp_type);
/**
* Set the dynamic audio buffer size
@@ -261,7 +283,8 @@ extern bool btif_av_is_source_enabled(void);
extern bool btif_av_both_enable(void);
extern bool btif_av_src_sink_coexist_enabled(void);
extern bool btif_av_is_sink_enabled(void);
-extern bool btif_av_is_connected_addr(const RawAddress& peer_address);
+extern bool btif_av_is_connected_addr(const RawAddress& peer_address,
+ const A2dpType local_a2dp_type);
extern bool btif_av_peer_is_connected_sink(const RawAddress& peer_address);
extern bool btif_av_peer_is_connected_source(const RawAddress& peer_address);
extern bool btif_av_peer_is_sink(const RawAddress& peer_address);
diff --git a/system/btif/include/btif_av_co.h b/system/btif/include/btif_av_co.h
index ce9b873fe9..36635b9ae5 100644
--- a/system/btif/include/btif_av_co.h
+++ b/system/btif/include/btif_av_co.h
@@ -27,6 +27,20 @@
// Returns true on success, otherwise false.
bool bta_av_co_set_active_peer(const RawAddress& peer_addr);
+/**
+ * Sets the active peer within the sink profile of the bta av co instance.
+ * @param peer_address peer address of the remote device.
+ * @return true on success, otherwise false.
+ */
+bool bta_av_co_set_active_sink_peer(const RawAddress& peer_address);
+
+/**
+ * Sets the active peer within the sink profile of the bta av co instance.
+ * @param peer_address peer address of the remote device.
+ * @return true on success, otherwise false.
+ */
+bool bta_av_co_set_active_source_peer(const RawAddress& peer_address);
+
void bta_av_co_save_codec(const uint8_t* new_codec_config);
// Gets the A2DP peer parameters that are used to initialize the encoder.
diff --git a/system/btif/include/btif_bqr.h b/system/btif/include/btif_bqr.h
index 374a387782..dd850c6241 100644
--- a/system/btif/include/btif_bqr.h
+++ b/system/btif/include/btif_bqr.h
@@ -17,6 +17,8 @@
#ifndef BTIF_BQR_H_
#define BTIF_BQR_H_
+#include <bluetooth/log.h>
+
#include "btm_api_types.h"
#include "common/leaky_bonded_queue.h"
#include "include/hardware/bt_bqr.h"
@@ -457,4 +459,12 @@ void DebugDump(int fd);
} // namespace bqr
} // namespace bluetooth
+namespace fmt {
+template <>
+struct formatter<bluetooth::bqr::BqrReportAction>
+ : enum_formatter<bluetooth::bqr::BqrReportAction> {};
+template <>
+struct formatter<bluetooth::bqr::BqrVseSubEvt> : ostream_formatter {};
+} // namespace fmt
+
#endif // BTIF_BQR_H_
diff --git a/system/btif/include/btif_common.h b/system/btif/include/btif_common.h
index b10b84581b..3a357ffdf4 100644
--- a/system/btif/include/btif_common.h
+++ b/system/btif/include/btif_common.h
@@ -22,6 +22,7 @@
#include <base/functional/bind.h>
#include <base/location.h>
+#include <bluetooth/log.h>
#include <hardware/bluetooth.h>
#include <stdlib.h>
@@ -38,12 +39,11 @@
* Constants & Macros
******************************************************************************/
-#define ASSERTC(cond, msg, val) \
- do { \
- if (!(cond)) { \
- LOG_ERROR("### ASSERT : %s %s line %d %s (%d) ###", __FILE__, __func__, \
- __LINE__, (msg), (val)); \
- } \
+#define ASSERTC(cond, msg, val) \
+ do { \
+ if (!(cond)) { \
+ bluetooth::log::error("### ASSERT : {} ({}) ###", (msg), (val)); \
+ } \
} while (0)
/*
@@ -63,14 +63,14 @@
#define maybe_non_aligned_memcpy(_a, _b, _c) \
memcpy((void*)(_a), (void*)(_b), (_c))
-#define HAL_CBACK(P_CB, P_CBACK, ...) \
- do { \
- if ((P_CB) && (P_CB)->P_CBACK) { \
- LOG_VERBOSE("%s: HAL %s->%s", __func__, #P_CB, #P_CBACK); \
- (P_CB)->P_CBACK(__VA_ARGS__); \
- } else { \
- ASSERTC(0, "Callback is NULL", 0); \
- } \
+#define HAL_CBACK(P_CB, P_CBACK, ...) \
+ do { \
+ if ((P_CB) && (P_CB)->P_CBACK) { \
+ bluetooth::log::verbose("HAL {}->{}", #P_CB, #P_CBACK); \
+ (P_CB)->P_CBACK(__VA_ARGS__); \
+ } else { \
+ ASSERTC(0, "Callback is NULL", 0); \
+ } \
} while (0)
/*******************************************************************************
diff --git a/system/btif/include/btif_hd.h b/system/btif/include/btif_hd.h
index 337deefc7a..ac29552cfb 100644
--- a/system/btif/include/btif_hd.h
+++ b/system/btif/include/btif_hd.h
@@ -20,6 +20,7 @@
#ifndef BTIF_HD_H
#define BTIF_HD_H
+#include <bluetooth/log.h>
#include <hardware/bluetooth.h>
#include <hardware/bt_hd.h>
#include <stdint.h>
@@ -46,4 +47,9 @@ extern btif_hd_cb_t btif_hd_cb;
void btif_hd_remove_device(RawAddress bd_addr);
void btif_hd_service_registration();
+namespace fmt {
+template <>
+struct formatter<BTIF_HD_STATUS> : enum_formatter<BTIF_HD_STATUS> {};
+} // namespace fmt
+
#endif
diff --git a/system/btif/include/btif_hh.h b/system/btif/include/btif_hh.h
index dbe3749276..7dd5aa1cdc 100644
--- a/system/btif/include/btif_hh.h
+++ b/system/btif/include/btif_hh.h
@@ -20,6 +20,7 @@
#define BTIF_HH_H
#include <base/strings/stringprintf.h>
+#include <bluetooth/log.h>
#include <hardware/bluetooth.h>
#include <hardware/bt_hh.h>
#include <pthread.h>
@@ -144,4 +145,9 @@ void btif_hh_service_registration(bool enable);
void DumpsysHid(int fd);
+namespace fmt {
+template <>
+struct formatter<BTIF_HH_STATUS> : enum_formatter<BTIF_HH_STATUS> {};
+} // namespace fmt
+
#endif
diff --git a/system/btif/src/bluetooth.cc b/system/btif/src/bluetooth.cc
index d6ba575929..81ff09954a 100644
--- a/system/btif/src/bluetooth.cc
+++ b/system/btif/src/bluetooth.cc
@@ -29,6 +29,7 @@
#include <android_bluetooth_flags.h>
#include <base/logging.h>
+#include <bluetooth/log.h>
#include <hardware/bluetooth.h>
#include <hardware/bluetooth_headset_interface.h>
#include <hardware/bt_av.h>
@@ -120,6 +121,7 @@ using bluetooth::hearing_aid::HearingAidInterface;
using bluetooth::le_audio::LeAudioBroadcasterInterface;
using bluetooth::le_audio::LeAudioClientInterface;
using bluetooth::vc::VolumeControlInterface;
+using namespace bluetooth;
/*******************************************************************************
* Static variables
@@ -199,7 +201,7 @@ struct ConfigInterfaceImpl : bluetooth::core::ConfigInterface {
"false");
auto a2dp_offload_enabled =
(strcmp(value_sup, "true") == 0) && (strcmp(value_dis, "false") == 0);
- LOG_VERBOSE("a2dp_offload.enable = %d", a2dp_offload_enabled);
+ log::verbose("a2dp_offload.enable = {}", a2dp_offload_enabled);
return a2dp_offload_enabled;
}
@@ -297,8 +299,8 @@ struct CoreInterfaceImpl : bluetooth::core::CoreInterface {
*/
} break;
default:
- LOG_ERROR("%s: Unknown service %d being %s", __func__, service_id,
- (enable) ? "enabled" : "disabled");
+ log::error("Unknown service {} being {}", service_id,
+ (enable) ? "enabled" : "disabled");
return BT_STATUS_FAIL;
}
return BT_STATUS_SUCCESS;
@@ -331,7 +333,12 @@ struct CoreInterfaceImpl : bluetooth::core::CoreInterface {
}
void onLinkDown(const RawAddress& bd_addr) override {
- btif_av_acl_disconnected(bd_addr);
+ if (IS_FLAG_ENABLED(a2dp_concurrent_source_sink)) {
+ btif_av_acl_disconnected(bd_addr, A2dpType::kSource);
+ btif_av_acl_disconnected(bd_addr, A2dpType::kSink);
+ } else {
+ btif_av_acl_disconnected(bd_addr, A2dpType::kUnknown);
+ }
}
};
@@ -409,11 +416,10 @@ static int init(bt_callbacks_t* callbacks, bool start_restricted,
const char** init_flags, bool is_atv,
const char* user_data_directory) {
(void)user_data_directory;
- LOG_INFO(
- "%s: start restricted = %d ; common criteria mode = %d, config compare "
- "result = %d",
- __func__, start_restricted, is_common_criteria_mode,
- config_compare_result);
+ log::info(
+ "start restricted = {} ; common criteria mode = {}, config compare "
+ "result = {}",
+ start_restricted, is_common_criteria_mode, config_compare_result);
bluetooth::common::InitFlags::Load(init_flags);
@@ -630,7 +636,7 @@ static int create_bond_out_of_band(const RawAddress* bd_addr, int transport,
}
static int generate_local_oob_data(tBT_TRANSPORT transport) {
- LOG_INFO("%s", __func__);
+ log::info("");
if (!interface_ready()) return BT_STATUS_NOT_READY;
return do_in_main_thread(
@@ -646,8 +652,8 @@ static int cancel_bond(const RawAddress* bd_addr) {
static int remove_bond(const RawAddress* bd_addr) {
if (is_restricted_mode() && !btif_storage_is_restricted_device(bd_addr)) {
- LOG_INFO("%s cannot be removed in restricted mode",
- ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
+ log::info("{} cannot be removed in restricted mode",
+ ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
return BT_STATUS_SUCCESS;
}
@@ -706,7 +712,7 @@ static int read_energy_info() {
}
static int clear_event_filter() {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
if (!interface_ready()) return BT_STATUS_NOT_READY;
do_in_main_thread(FROM_HERE, base::BindOnce(btif_dm_clear_event_filter));
@@ -714,7 +720,7 @@ static int clear_event_filter() {
}
static int clear_event_mask() {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
if (!interface_ready()) return BT_STATUS_NOT_READY;
do_in_main_thread(FROM_HERE, base::BindOnce(btif_dm_clear_event_mask));
@@ -722,7 +728,7 @@ static int clear_event_mask() {
}
static int clear_filter_accept_list() {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
if (!interface_ready()) return BT_STATUS_NOT_READY;
do_in_main_thread(FROM_HERE,
@@ -731,7 +737,7 @@ static int clear_filter_accept_list() {
}
static int disconnect_all_acls() {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
if (!interface_ready()) return BT_STATUS_NOT_READY;
do_in_main_thread(FROM_HERE, base::BindOnce(btif_dm_disconnect_all_acls));
@@ -739,7 +745,7 @@ static int disconnect_all_acls() {
}
static void le_rand_btif_cb(uint64_t random_number) {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
do_in_jni_thread(
FROM_HERE,
base::BindOnce(
@@ -748,7 +754,7 @@ static void le_rand_btif_cb(uint64_t random_number) {
}
static int le_rand() {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
if (!interface_ready()) return BT_STATUS_NOT_READY;
do_in_main_thread(
@@ -848,8 +854,8 @@ static int get_remote_pbap_pce_version(const RawAddress* bd_addr) {
if (!btif_config_get_bin(bd_addr->ToString(),
BTIF_STORAGE_KEY_PBAP_PCE_VERSION,
(uint8_t*)&pce_version, &version_value_size)) {
- LOG_WARN("Failed to read cached peer PCE version for %s",
- ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
+ log::warn("Failed to read cached peer PCE version for {}",
+ ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
}
return pce_version;
}
@@ -859,12 +865,12 @@ static bool pbap_pse_dynamic_version_upgrade_is_enabled() {
pbap_pse_dynamic_version_upgrade_is_enabled()) {
return true;
}
- LOG_WARN("PBAP PSE dynamic version upgrade is not enabled");
+ log::warn("PBAP PSE dynamic version upgrade is not enabled");
return false;
}
static const void* get_profile_interface(const char* profile_id) {
- LOG_INFO("%s: id = %s", __func__, profile_id);
+ log::info("id = {}", profile_id);
/* sanity check */
if (!interface_ready()) return NULL;
@@ -1017,15 +1023,15 @@ static int set_os_callouts(bt_os_callouts_t* callouts) {
}
static int config_clear(void) {
- LOG_INFO("%s", __func__);
+ log::info("");
int ret = BT_STATUS_SUCCESS;
if (!btif_config_clear()) {
- LOG_ERROR("Failed to clear btif config");
+ log::error("Failed to clear btif config");
ret = BT_STATUS_FAIL;
}
if (!device_iot_config_clear()) {
- LOG_ERROR("Failed to clear device iot config");
+ log::error("Failed to clear device iot config");
ret = BT_STATUS_FAIL;
}
@@ -1051,7 +1057,7 @@ static int set_dynamic_audio_buffer_size(int codec, int size) {
static bool allow_low_latency_audio(bool allowed,
const RawAddress& /* address */) {
- LOG_INFO("%s %s", __func__, allowed ? "true" : "false");
+ log::info("{}", allowed);
bluetooth::audio::a2dp::set_audio_low_latency_mode_allowed(allowed);
return true;
}
@@ -1059,7 +1065,7 @@ static bool allow_low_latency_audio(bool allowed,
static void metadata_changed(const RawAddress& remote_bd_addr, int key,
std::vector<uint8_t> value) {
if (!interface_ready()) {
- LOG_ERROR("Interface not ready!");
+ log::error("Interface not ready!");
return;
}
@@ -1076,7 +1082,7 @@ static bool interop_match_addr(const char* feature_name,
int feature = interop_feature_name_to_feature_id(feature_name);
if (feature == -1) {
- LOG_ERROR("%s: feature doesn't exist: %s", __func__, feature_name);
+ log::error("feature doesn't exist: {}", feature_name);
return false;
}
@@ -1090,7 +1096,7 @@ static bool interop_match_name(const char* feature_name, const char* name) {
int feature = interop_feature_name_to_feature_id(feature_name);
if (feature == -1) {
- LOG_ERROR("%s: feature doesn't exist: %s", __func__, feature_name);
+ log::error("feature doesn't exist: {}", feature_name);
return false;
}
@@ -1105,7 +1111,7 @@ static bool interop_match_addr_or_name(const char* feature_name,
int feature = interop_feature_name_to_feature_id(feature_name);
if (feature == -1) {
- LOG_ERROR("%s: feature doesn't exist: %s", __func__, feature_name);
+ log::error("feature doesn't exist: {}", feature_name);
return false;
}
@@ -1123,7 +1129,7 @@ static void interop_database_add_remove_addr(bool do_add,
int feature = interop_feature_name_to_feature_id(feature_name);
if (feature == -1) {
- LOG_ERROR("%s: feature doesn't exist: %s", __func__, feature_name);
+ log::error("feature doesn't exist: {}", feature_name);
return;
}
@@ -1143,7 +1149,7 @@ static void interop_database_add_remove_name(bool do_add,
int feature = interop_feature_name_to_feature_id(feature_name);
if (feature == -1) {
- LOG_ERROR("%s: feature doesn't exist: %s", __func__, feature_name);
+ log::error("feature doesn't exist: {}", feature_name);
return;
}
@@ -1350,7 +1356,7 @@ void invoke_ssp_request_cb(RawAddress bd_addr, bt_bdname_t bd_name,
void invoke_oob_data_request_cb(tBT_TRANSPORT t, bool valid, Octet16 c,
Octet16 r, RawAddress raw_address,
uint8_t address_type) {
- LOG_INFO("%s", __func__);
+ log::info("");
bt_oob_data_t oob_data = {};
const char* local_name;
BTM_ReadLocalDeviceName(&local_name);
@@ -1388,7 +1394,7 @@ void invoke_oob_data_request_cb(tBT_TRANSPORT t, bool valid, Octet16 c,
},
t, oob_data));
if (status != BT_STATUS_SUCCESS) {
- LOG_ERROR("%s: Failed to call callback!", __func__);
+ log::error("Failed to call callback!");
}
}
diff --git a/system/btif/src/btif_a2dp.cc b/system/btif/src/btif_a2dp.cc
index 0e6f217e49..a76d317037 100644
--- a/system/btif/src/btif_a2dp.cc
+++ b/system/btif/src/btif_a2dp.cc
@@ -21,7 +21,9 @@
#include "btif_a2dp.h"
+#include <android_bluetooth_flags.h>
#include <base/logging.h>
+#include <bluetooth/log.h>
#include <stdbool.h>
#include "audio_a2dp_hw/include/audio_a2dp_hw.h"
@@ -38,13 +40,20 @@
#include "os/log.h"
#include "types/raw_address.h"
-void btif_a2dp_on_idle(const RawAddress& peer_addr) {
- LOG_VERBOSE("Peer stream endpoint type:%s",
- peer_stream_endpoint_text(btif_av_get_peer_sep()).c_str());
- if (btif_av_src_sink_coexist_enabled()) {
+using namespace bluetooth;
+
+using namespace bluetooth;
+
+void btif_a2dp_on_idle(const RawAddress& peer_addr,
+ const A2dpType local_a2dp_type) {
+ log::verbose(
+ "Peer stream endpoint type:{}",
+ peer_stream_endpoint_text(btif_av_get_peer_sep(local_a2dp_type)).c_str());
+ if (!IS_FLAG_ENABLED(a2dp_concurrent_source_sink) &&
+ btif_av_src_sink_coexist_enabled()) {
bool is_sink = btif_av_peer_is_sink(peer_addr);
bool is_source = btif_av_peer_is_source(peer_addr);
- LOG_INFO("## ON A2DP IDLE ## is_sink:%d is_source:%d", is_sink, is_source);
+ log::info("## ON A2DP IDLE ## is_sink:{} is_source:{}", is_sink, is_source);
if (is_sink) {
btif_a2dp_source_on_idle();
} else if (is_source) {
@@ -52,24 +61,24 @@ void btif_a2dp_on_idle(const RawAddress& peer_addr) {
}
return;
}
-
- if (btif_av_get_peer_sep() == AVDT_TSEP_SNK) {
+ if (btif_av_get_peer_sep(local_a2dp_type) == AVDT_TSEP_SNK) {
btif_a2dp_source_on_idle();
- } else if (btif_av_get_peer_sep() == AVDT_TSEP_SRC) {
+ } else if (btif_av_get_peer_sep(local_a2dp_type) == AVDT_TSEP_SRC) {
btif_a2dp_sink_on_idle();
}
}
-bool btif_a2dp_on_started(const RawAddress& peer_addr, tBTA_AV_START* p_av_start) {
- LOG(INFO) << __func__ << ": ## ON A2DP STARTED ## peer "
- << ADDRESS_TO_LOGGABLE_STR(peer_addr) << " p_av_start:"
- << p_av_start;
+bool btif_a2dp_on_started(const RawAddress& peer_addr,
+ tBTA_AV_START* p_av_start,
+ const A2dpType local_a2dp_type) {
+ log::info("## ON A2DP STARTED ## peer {} p_av_start:{}",
+ ADDRESS_TO_LOGGABLE_STR(peer_addr), fmt::ptr(p_av_start));
if (p_av_start == NULL) {
tA2DP_CTRL_ACK status = A2DP_CTRL_ACK_SUCCESS;
if (!bluetooth::headset::IsCallIdle()) {
- LOG(ERROR) << __func__ << ": peer " << ADDRESS_TO_LOGGABLE_STR(peer_addr)
- << " call in progress, do not start A2DP stream";
+ log::error("peer {} call in progress, do not start A2DP stream",
+ ADDRESS_TO_LOGGABLE_STR(peer_addr));
status = A2DP_CTRL_ACK_INCALL_FAILURE;
}
/* just ack back a local start request, do not start the media encoder since
@@ -82,21 +91,20 @@ bool btif_a2dp_on_started(const RawAddress& peer_addr, tBTA_AV_START* p_av_start
return true;
}
- LOG(INFO) << __func__ << ": peer " << ADDRESS_TO_LOGGABLE_STR(peer_addr)
- << " status:" << +p_av_start->status
- << " suspending:" << logbool(p_av_start->suspending) << " initiator:" << logbool(p_av_start->initiator);
+ log::info("peer {} status:{} suspending:{} initiator:{}",
+ ADDRESS_TO_LOGGABLE_STR(peer_addr), p_av_start->status,
+ logbool(p_av_start->suspending), logbool(p_av_start->initiator));
if (p_av_start->status == BTA_AV_SUCCESS) {
if (p_av_start->suspending) {
- LOG(WARNING) << __func__ << ": peer "
- << ADDRESS_TO_LOGGABLE_STR(peer_addr)
- << " A2DP is suspending and ignores the started event";
+ log::warn("peer {} A2DP is suspending and ignores the started event",
+ ADDRESS_TO_LOGGABLE_STR(peer_addr));
return false;
}
if (btif_av_is_a2dp_offload_running()) {
btif_av_stream_start_offload();
} else if (bluetooth::audio::a2dp::is_hal_enabled()) {
- if (btif_av_get_peer_sep() == AVDT_TSEP_SNK) {
+ if (btif_av_get_peer_sep(local_a2dp_type) == AVDT_TSEP_SNK) {
/* Start the media encoder to do the SW audio stream */
btif_a2dp_source_start_audio_req();
}
@@ -112,8 +120,8 @@ bool btif_a2dp_on_started(const RawAddress& peer_addr, tBTA_AV_START* p_av_start
/* media task is auto-started upon UIPC connection of a2dp audiopath */
}
} else if (p_av_start->initiator) {
- LOG(ERROR) << __func__ << ": peer " << ADDRESS_TO_LOGGABLE_STR(peer_addr)
- << " A2DP start request failed: status = " << +p_av_start->status;
+ log::error("peer {} A2DP start request failed: status = {}",
+ ADDRESS_TO_LOGGABLE_STR(peer_addr), p_av_start->status);
if (bluetooth::audio::a2dp::is_hal_enabled()) {
bluetooth::audio::a2dp::ack_stream_started(A2DP_CTRL_ACK_FAILURE);
} else {
@@ -124,60 +132,81 @@ bool btif_a2dp_on_started(const RawAddress& peer_addr, tBTA_AV_START* p_av_start
return false;
}
-void btif_a2dp_on_stopped(tBTA_AV_SUSPEND* p_av_suspend) {
- LOG_INFO("%s: ## ON A2DP STOPPED ## p_av_suspend=%p", __func__, p_av_suspend);
+void btif_a2dp_on_stopped(tBTA_AV_SUSPEND* p_av_suspend,
+ const A2dpType local_a2dp_type) {
+ log::info("## ON A2DP STOPPED ## p_av_suspend={}", fmt::ptr(p_av_suspend));
- if (btif_av_get_peer_sep() == AVDT_TSEP_SRC) {
+ const uint8_t peer_type_sep = btif_av_get_peer_sep(local_a2dp_type);
+ if (peer_type_sep == AVDT_TSEP_SRC) {
btif_a2dp_sink_on_stopped(p_av_suspend);
return;
}
- if (bluetooth::audio::a2dp::is_hal_enabled() ||
- !btif_av_is_a2dp_offload_running()) {
- btif_a2dp_source_on_stopped(p_av_suspend);
+ if (!IS_FLAG_ENABLED(a2dp_concurrent_source_sink)) {
+ if (bluetooth::audio::a2dp::is_hal_enabled() ||
+ !btif_av_is_a2dp_offload_running()) {
+ btif_a2dp_source_on_stopped(p_av_suspend);
+ return;
+ }
+ } else if (peer_type_sep == AVDT_TSEP_SNK) {
+ if (bluetooth::audio::a2dp::is_hal_enabled() ||
+ !btif_av_is_a2dp_offload_running()) {
+ btif_a2dp_source_on_stopped(p_av_suspend);
+ return;
+ }
}
}
-void btif_a2dp_on_suspended(tBTA_AV_SUSPEND* p_av_suspend) {
- LOG_INFO("%s: ## ON A2DP SUSPENDED ## p_av_suspend=%p", __func__,
- p_av_suspend);
- if (btif_av_get_peer_sep() == AVDT_TSEP_SRC) {
+void btif_a2dp_on_suspended(tBTA_AV_SUSPEND* p_av_suspend,
+ const A2dpType local_a2dp_type) {
+ log::info("## ON A2DP SUSPENDED ## p_av_suspend={}", fmt::ptr(p_av_suspend));
+ const uint8_t peer_type_sep = btif_av_get_peer_sep(local_a2dp_type);
+ if (peer_type_sep == AVDT_TSEP_SRC) {
btif_a2dp_sink_on_suspended(p_av_suspend);
return;
}
- if (bluetooth::audio::a2dp::is_hal_enabled() ||
- !btif_av_is_a2dp_offload_running()) {
- btif_a2dp_source_on_suspended(p_av_suspend);
+ if (!IS_FLAG_ENABLED(a2dp_concurrent_source_sink)) {
+ if (bluetooth::audio::a2dp::is_hal_enabled() ||
+ !btif_av_is_a2dp_offload_running()) {
+ btif_a2dp_source_on_suspended(p_av_suspend);
+ return;
+ }
+ } else if (peer_type_sep == AVDT_TSEP_SNK) {
+ if (bluetooth::audio::a2dp::is_hal_enabled() ||
+ !btif_av_is_a2dp_offload_running()) {
+ btif_a2dp_source_on_suspended(p_av_suspend);
+ return;
+ }
}
}
void btif_a2dp_on_offload_started(const RawAddress& peer_addr,
tBTA_AV_STATUS status) {
tA2DP_CTRL_ACK ack;
- LOG_INFO("%s: peer %s status %d", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_addr), status);
+ log::info("peer {} status {}", ADDRESS_TO_LOGGABLE_CSTR(peer_addr), status);
switch (status) {
case BTA_AV_SUCCESS:
ack = A2DP_CTRL_ACK_SUCCESS;
break;
case BTA_AV_FAIL_RESOURCES:
- LOG_ERROR("%s: peer %s FAILED UNSUPPORTED", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_addr));
+ log::error("peer {} FAILED UNSUPPORTED",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_addr));
ack = A2DP_CTRL_ACK_UNSUPPORTED;
break;
default:
- LOG_ERROR("%s: peer %s FAILED: status = %d", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_addr), status);
+ log::error("peer {} FAILED: status = {}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_addr), status);
ack = A2DP_CTRL_ACK_FAILURE;
break;
}
if (btif_av_is_a2dp_offload_running()) {
- if (ack != BTA_AV_SUCCESS && btif_av_stream_started_ready()) {
+ if (ack != BTA_AV_SUCCESS &&
+ btif_av_stream_started_ready(A2dpType::kSource)) {
// Offload request will return with failure from btif_av sm if
// suspend is triggered for remote start. Disconnect only if SoC
// returned failure for offload VSC
- LOG_ERROR("%s: peer %s offload start failed", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_addr));
+ log::error("peer {} offload start failed",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_addr));
btif_av_src_disconnect_sink(peer_addr);
}
}
diff --git a/system/btif/src/btif_a2dp_control.cc b/system/btif/src/btif_a2dp_control.cc
index 8ed0ee5b1f..f2764f7eb9 100644
--- a/system/btif/src/btif_a2dp_control.cc
+++ b/system/btif/src/btif_a2dp_control.cc
@@ -22,6 +22,7 @@
#include "btif_a2dp_control.h"
#include <base/logging.h>
+#include <bluetooth/log.h>
#include <stdbool.h>
#include <stdint.h>
@@ -36,6 +37,17 @@
#define A2DP_DATA_READ_POLL_MS 10
+using namespace bluetooth;
+
+namespace fmt {
+template <>
+struct formatter<tA2DP_CTRL_CMD> : enum_formatter<tA2DP_CTRL_CMD> {};
+template <>
+struct formatter<tA2DP_CTRL_ACK> : enum_formatter<tA2DP_CTRL_ACK> {};
+template <>
+struct formatter<tUIPC_EVENT> : enum_formatter<tUIPC_EVENT> {};
+} // namespace fmt
+
struct {
uint64_t total_bytes_read = 0;
uint16_t audio_delay = 0;
@@ -63,17 +75,16 @@ void btif_a2dp_control_cleanup(void) {
static tA2DP_CTRL_ACK btif_a2dp_control_on_check_ready() {
if (btif_a2dp_source_media_task_is_shutting_down()) {
- LOG_WARN("%s: A2DP command check ready while media task shutting down",
- __func__);
+ log::warn("A2DP command check ready while media task shutting down");
return A2DP_CTRL_ACK_FAILURE;
}
/* check whether AV is ready to setup A2DP datapath */
- if (btif_av_stream_ready() || btif_av_stream_started_ready()) {
+ if (btif_av_stream_ready(A2dpType::kSource) ||
+ btif_av_stream_started_ready(A2dpType::kSource)) {
return A2DP_CTRL_ACK_SUCCESS;
} else {
- LOG_WARN("%s: A2DP command check ready while AV stream is not ready",
- __func__);
+ log::warn("A2DP command check ready while AV stream is not ready");
return A2DP_CTRL_ACK_FAILURE;
}
}
@@ -85,11 +96,11 @@ static tA2DP_CTRL_ACK btif_a2dp_control_on_start() {
* while in a call, and respond with BAD_STATE.
*/
if (!bluetooth::headset::IsCallIdle()) {
- LOG_WARN("%s: A2DP command start while call state is busy", __func__);
+ log::warn("A2DP command start while call state is busy");
return A2DP_CTRL_ACK_INCALL_FAILURE;
}
- if (btif_av_stream_ready()) {
+ if (btif_av_stream_ready(A2dpType::kSource)) {
/* Setup audio data channel listener */
UIPC_Open(*a2dp_uipc, UIPC_CH_ID_AV_AUDIO, btif_a2dp_data_cb,
A2DP_DATA_PATH);
@@ -99,11 +110,12 @@ static tA2DP_CTRL_ACK btif_a2dp_control_on_start() {
* If we are the source, the ACK will be sent after the start
* procedure is completed, othewise send it now.
*/
- btif_av_stream_start();
- if (btif_av_get_peer_sep() == AVDT_TSEP_SRC) return A2DP_CTRL_ACK_SUCCESS;
+ btif_av_stream_start(A2dpType::kSource);
+ if (btif_av_get_peer_sep(A2dpType::kSource) == AVDT_TSEP_SRC)
+ return A2DP_CTRL_ACK_SUCCESS;
}
- if (btif_av_stream_started_ready()) {
+ if (btif_av_stream_started_ready(A2dpType::kSource)) {
/*
* Already started, setup audio data channel listener and ACK
* back immediately.
@@ -112,7 +124,7 @@ static tA2DP_CTRL_ACK btif_a2dp_control_on_start() {
A2DP_DATA_PATH);
return A2DP_CTRL_ACK_SUCCESS;
}
- LOG_WARN("%s: A2DP command start while AV stream is not ready", __func__);
+ log::warn("A2DP command start while AV stream is not ready");
return A2DP_CTRL_ACK_FAILURE;
}
@@ -123,7 +135,7 @@ static tA2DP_CTRL_ACK btif_a2dp_control_on_stop() {
static void btif_a2dp_control_on_suspend() {
/* Local suspend */
- if (btif_av_stream_started_ready()) {
+ if (btif_av_stream_started_ready(A2dpType::kSource)) {
btif_av_stream_suspend();
return;
}
@@ -131,7 +143,7 @@ static void btif_a2dp_control_on_suspend() {
* audioflinger close the channel. This can happen if we are
* remotely suspended, clear REMOTE SUSPEND flag.
*/
- btif_av_clear_remote_suspend_flag();
+ btif_av_clear_remote_suspend_flag(A2dpType::kSource);
btif_a2dp_command_ack(A2DP_CTRL_ACK_SUCCESS);
}
@@ -198,28 +210,27 @@ static void btif_a2dp_control_on_set_output_audio_config() {
reinterpret_cast<uint8_t*>(&codec_config.sample_rate),
sizeof(btav_a2dp_codec_sample_rate_t)) !=
sizeof(btav_a2dp_codec_sample_rate_t)) {
- LOG_ERROR("%s: Error reading sample rate from audio HAL", __func__);
+ log::error("Error reading sample rate from audio HAL");
return;
}
if (UIPC_Read(*a2dp_uipc, UIPC_CH_ID_AV_CTRL,
reinterpret_cast<uint8_t*>(&codec_config.bits_per_sample),
sizeof(btav_a2dp_codec_bits_per_sample_t)) !=
sizeof(btav_a2dp_codec_bits_per_sample_t)) {
- LOG_ERROR("%s: Error reading bits per sample from audio HAL", __func__);
+ log::error("Error reading bits per sample from audio HAL");
return;
}
if (UIPC_Read(*a2dp_uipc, UIPC_CH_ID_AV_CTRL,
reinterpret_cast<uint8_t*>(&codec_config.channel_mode),
sizeof(btav_a2dp_codec_channel_mode_t)) !=
sizeof(btav_a2dp_codec_channel_mode_t)) {
- LOG_ERROR("%s: Error reading channel mode from audio HAL", __func__);
+ log::error("Error reading channel mode from audio HAL");
return;
}
- LOG_VERBOSE(
- "%s: A2DP_CTRL_SET_OUTPUT_AUDIO_CONFIG: "
- "sample_rate=0x%x bits_per_sample=0x%x "
- "channel_mode=0x%x",
- __func__, codec_config.sample_rate, codec_config.bits_per_sample,
+ log::verbose(
+ "A2DP_CTRL_SET_OUTPUT_AUDIO_CONFIG: sample_rate=0x{:x} "
+ "bits_per_sample=0x{:x} channel_mode=0x{:x}",
+ codec_config.sample_rate, codec_config.bits_per_sample,
codec_config.channel_mode);
btif_a2dp_source_feeding_update_req(codec_config);
}
@@ -250,7 +261,7 @@ static void btif_a2dp_recv_ctrl_data(void) {
/* detach on ctrl channel means audioflinger process was terminated */
if (n == 0) {
- LOG_WARN("%s: CTRL CH DETACHED", __func__);
+ log::warn("CTRL CH DETACHED");
UIPC_Close(*a2dp_uipc, UIPC_CH_ID_AV_CTRL);
return;
}
@@ -258,11 +269,9 @@ static void btif_a2dp_recv_ctrl_data(void) {
// Don't log A2DP_CTRL_GET_PRESENTATION_POSITION by default, because it
// could be very chatty when audio is streaming.
if (cmd == A2DP_CTRL_GET_PRESENTATION_POSITION) {
- LOG_VERBOSE("%s: a2dp-ctrl-cmd : %s", __func__,
- audio_a2dp_hw_dump_ctrl_event(cmd));
+ log::verbose("a2dp-ctrl-cmd : {}", audio_a2dp_hw_dump_ctrl_event(cmd));
} else {
- LOG_WARN("%s: a2dp-ctrl-cmd : %s", __func__,
- audio_a2dp_hw_dump_ctrl_event(cmd));
+ log::warn("a2dp-ctrl-cmd : {}", audio_a2dp_hw_dump_ctrl_event(cmd));
}
a2dp_cmd_pending = cmd;
@@ -300,7 +309,7 @@ static void btif_a2dp_recv_ctrl_data(void) {
break;
default:
- LOG_ERROR("%s: UNSUPPORTED CMD (%d)", __func__, cmd);
+ log::error("UNSUPPORTED CMD ({})", cmd);
btif_a2dp_command_ack(A2DP_CTRL_ACK_FAILURE);
break;
}
@@ -308,11 +317,9 @@ static void btif_a2dp_recv_ctrl_data(void) {
// Don't log A2DP_CTRL_GET_PRESENTATION_POSITION by default, because it
// could be very chatty when audio is streaming.
if (cmd == A2DP_CTRL_GET_PRESENTATION_POSITION) {
- LOG_VERBOSE("%s: a2dp-ctrl-cmd : %s DONE", __func__,
- audio_a2dp_hw_dump_ctrl_event(cmd));
+ log::verbose("a2dp-ctrl-cmd : {} DONE", audio_a2dp_hw_dump_ctrl_event(cmd));
} else {
- LOG_WARN("%s: a2dp-ctrl-cmd : %s DONE", __func__,
- audio_a2dp_hw_dump_ctrl_event(cmd));
+ log::warn("a2dp-ctrl-cmd : {} DONE", audio_a2dp_hw_dump_ctrl_event(cmd));
}
}
@@ -320,11 +327,9 @@ static void btif_a2dp_ctrl_cb(tUIPC_CH_ID /* ch_id */, tUIPC_EVENT event) {
// Don't log UIPC_RX_DATA_READY_EVT by default, because it
// could be very chatty when audio is streaming.
if (event == UIPC_RX_DATA_READY_EVT) {
- LOG_VERBOSE("%s: A2DP-CTRL-CHANNEL EVENT %s", __func__,
- dump_uipc_event(event));
+ log::verbose("A2DP-CTRL-CHANNEL EVENT {}", dump_uipc_event(event));
} else {
- LOG_WARN("%s: A2DP-CTRL-CHANNEL EVENT %s", __func__,
- dump_uipc_event(event));
+ log::warn("A2DP-CTRL-CHANNEL EVENT {}", dump_uipc_event(event));
}
switch (event) {
@@ -343,15 +348,13 @@ static void btif_a2dp_ctrl_cb(tUIPC_CH_ID /* ch_id */, tUIPC_EVENT event) {
break;
default:
- LOG_ERROR("%s: ### A2DP-CTRL-CHANNEL EVENT %d NOT HANDLED ###", __func__,
- event);
+ log::error("### A2DP-CTRL-CHANNEL EVENT {} NOT HANDLED ###", event);
break;
}
}
static void btif_a2dp_data_cb(tUIPC_CH_ID /* ch_id */, tUIPC_EVENT event) {
- LOG_WARN("%s: BTIF MEDIA (A2DP-DATA) EVENT %s", __func__,
- dump_uipc_event(event));
+ log::warn("BTIF MEDIA (A2DP-DATA) EVENT {}", dump_uipc_event(event));
switch (event) {
case UIPC_OPEN_EVT:
@@ -364,7 +367,7 @@ static void btif_a2dp_data_cb(tUIPC_CH_ID /* ch_id */, tUIPC_EVENT event) {
UIPC_Ioctl(*a2dp_uipc, UIPC_CH_ID_AV_AUDIO, UIPC_SET_READ_POLL_TMO,
reinterpret_cast<void*>(A2DP_DATA_READ_POLL_MS));
- if (btif_av_get_peer_sep() == AVDT_TSEP_SNK) {
+ if (btif_av_get_peer_sep(A2dpType::kSource) == AVDT_TSEP_SNK) {
/* Start the media task to encode the audio */
btif_a2dp_source_start_audio_req();
}
@@ -373,14 +376,14 @@ static void btif_a2dp_data_cb(tUIPC_CH_ID /* ch_id */, tUIPC_EVENT event) {
break;
case UIPC_CLOSE_EVT:
- LOG_VERBOSE("%s: ## AUDIO PATH DETACHED ##", __func__);
+ log::verbose("## AUDIO PATH DETACHED ##");
btif_a2dp_command_ack(A2DP_CTRL_ACK_SUCCESS);
/* Post stop event and wait for audio path to stop */
btif_av_stream_stop(RawAddress::kEmpty);
break;
default:
- LOG_ERROR("%s: ### A2DP-DATA EVENT %d NOT HANDLED ###", __func__, event);
+ log::error("### A2DP-DATA EVENT {} NOT HANDLED ###", event);
break;
}
}
@@ -391,16 +394,16 @@ void btif_a2dp_command_ack(tA2DP_CTRL_ACK status) {
// Don't log A2DP_CTRL_GET_PRESENTATION_POSITION by default, because it
// could be very chatty when audio is streaming.
if (a2dp_cmd_pending == A2DP_CTRL_GET_PRESENTATION_POSITION) {
- LOG_VERBOSE("%s: ## a2dp ack : %s, status %d ##", __func__,
- audio_a2dp_hw_dump_ctrl_event(a2dp_cmd_pending), status);
+ log::verbose("## a2dp ack : {}, status {} ##",
+ audio_a2dp_hw_dump_ctrl_event(a2dp_cmd_pending), status);
} else {
- LOG_WARN("%s: ## a2dp ack : %s, status %d ##", __func__,
- audio_a2dp_hw_dump_ctrl_event(a2dp_cmd_pending), status);
+ log::warn("## a2dp ack : {}, status {} ##",
+ audio_a2dp_hw_dump_ctrl_event(a2dp_cmd_pending), status);
}
/* Sanity check */
if (a2dp_cmd_pending == A2DP_CTRL_CMD_NONE) {
- LOG_ERROR("%s: warning : no command pending, ignore ack", __func__);
+ log::error("warning : no command pending, ignore ack");
return;
}
@@ -419,12 +422,12 @@ void btif_a2dp_control_log_bytes_read(uint32_t bytes_read) {
}
void btif_a2dp_control_set_audio_delay(uint16_t delay) {
- LOG_VERBOSE("%s: DELAY: %.1f ms", __func__, (float)delay / 10);
+ log::verbose("DELAY: {:.1f} ms", (float)delay / 10);
delay_report_stats.audio_delay = delay;
}
void btif_a2dp_control_reset_audio_delay(void) {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
delay_report_stats.audio_delay = 0;
delay_report_stats.total_bytes_read = 0;
delay_report_stats.timestamp = {};
diff --git a/system/btif/src/btif_a2dp_sink.cc b/system/btif/src/btif_a2dp_sink.cc
index e89b01f95a..d17bcae844 100644
--- a/system/btif/src/btif_a2dp_sink.cc
+++ b/system/btif/src/btif_a2dp_sink.cc
@@ -21,8 +21,10 @@
#include "btif/include/btif_a2dp_sink.h"
+#include <android_bluetooth_flags.h>
#include <base/functional/bind.h>
#include <base/logging.h>
+#include <bluetooth/log.h>
#include <atomic>
#include <mutex>
@@ -43,6 +45,7 @@
using bluetooth::common::MessageLoopThread;
using LockGuard = std::lock_guard<std::mutex>;
+using namespace bluetooth;
/**
* The receiving queue buffer size.
@@ -171,11 +174,11 @@ static const char* dump_media_event(uint16_t event) {
}
bool btif_a2dp_sink_init() {
- LOG_INFO("%s", __func__);
+ log::info("");
LockGuard lock(g_mutex);
if (btif_a2dp_sink_state != BTIF_A2DP_SINK_STATE_OFF) {
- LOG_ERROR("%s: A2DP Sink media task already running", __func__);
+ log::error("A2DP Sink media task already running");
return false;
}
@@ -185,7 +188,7 @@ bool btif_a2dp_sink_init() {
/* Start A2DP Sink media task */
btif_a2dp_sink_cb.worker_thread.StartUp();
if (!btif_a2dp_sink_cb.worker_thread.IsRunning()) {
- LOG_ERROR("%s: unable to start up media thread", __func__);
+ log::error("unable to start up media thread");
btif_a2dp_sink_state = BTIF_A2DP_SINK_STATE_OFF;
return false;
}
@@ -195,8 +198,7 @@ bool btif_a2dp_sink_init() {
/* Schedule the rest of the operations */
if (!btif_a2dp_sink_cb.worker_thread.EnableRealTimeScheduling()) {
#if defined(__ANDROID__)
- LOG(FATAL) << __func__
- << ": Failed to increase A2DP decoder thread priority";
+ log::fatal("Failed to increase A2DP decoder thread priority");
#endif
}
btif_a2dp_sink_cb.worker_thread.DoInThread(
@@ -205,43 +207,41 @@ bool btif_a2dp_sink_init() {
}
static void btif_a2dp_sink_init_delayed() {
- LOG_INFO("%s", __func__);
+ log::info("");
btif_a2dp_sink_state = BTIF_A2DP_SINK_STATE_RUNNING;
}
bool btif_a2dp_sink_startup() {
- LOG_INFO("%s", __func__);
+ log::info("");
btif_a2dp_sink_cb.worker_thread.DoInThread(
FROM_HERE, base::BindOnce(btif_a2dp_sink_startup_delayed));
return true;
}
static void btif_a2dp_sink_startup_delayed() {
- LOG_INFO("%s", __func__);
+ log::info("");
LockGuard lock(g_mutex);
// Nothing to do
}
bool btif_a2dp_sink_start_session(const RawAddress& peer_address,
std::promise<void> peer_ready_promise) {
- LOG(INFO) << __func__ << ": peer_address="
- << ADDRESS_TO_LOGGABLE_STR(peer_address);
+ log::info("peer_address={}", ADDRESS_TO_LOGGABLE_STR(peer_address));
if (btif_a2dp_sink_cb.worker_thread.DoInThread(
FROM_HERE, base::BindOnce(btif_a2dp_sink_start_session_delayed,
std::move(peer_ready_promise)))) {
return true;
} else {
// cannot set promise but triggers crash
- LOG(FATAL) << __func__ << ": peer_address="
- << ADDRESS_TO_LOGGABLE_STR(peer_address)
- << " fails to context switch";
+ log::fatal("peer_address={} fails to context switch",
+ ADDRESS_TO_LOGGABLE_STR(peer_address));
return false;
}
}
static void btif_a2dp_sink_start_session_delayed(
std::promise<void> peer_ready_promise) {
- LOG(INFO) << __func__;
+ log::info("");
LockGuard lock(g_mutex);
peer_ready_promise.set_value();
// Nothing to do
@@ -250,22 +250,29 @@ static void btif_a2dp_sink_start_session_delayed(
bool btif_a2dp_sink_restart_session(const RawAddress& old_peer_address,
const RawAddress& new_peer_address,
std::promise<void> peer_ready_promise) {
- LOG(INFO) << __func__ << ": old_peer_address="
- << ADDRESS_TO_LOGGABLE_STR(old_peer_address)
- << " new_peer_address=" << ADDRESS_TO_LOGGABLE_STR(new_peer_address);
+ log::info("old_peer_address={} new_peer_address={}",
+ ADDRESS_TO_LOGGABLE_STR(old_peer_address),
+ ADDRESS_TO_LOGGABLE_STR(new_peer_address));
CHECK(!new_peer_address.IsEmpty());
if (!old_peer_address.IsEmpty()) {
btif_a2dp_sink_end_session(old_peer_address);
}
-
- if (!bta_av_co_set_active_peer(new_peer_address)) {
- LOG(ERROR) << __func__
- << ": Cannot stream audio: cannot set active peer to "
- << ADDRESS_TO_LOGGABLE_STR(new_peer_address);
- peer_ready_promise.set_value();
- return false;
+ if (IS_FLAG_ENABLED(a2dp_concurrent_source_sink)) {
+ if (!bta_av_co_set_active_sink_peer(new_peer_address)) {
+ log::error("Cannot stream audio: cannot set active peer to {}",
+ ADDRESS_TO_LOGGABLE_STR(new_peer_address));
+ peer_ready_promise.set_value();
+ return false;
+ }
+ } else {
+ if (!bta_av_co_set_active_peer(new_peer_address)) {
+ log::error("Cannot stream audio: cannot set active peer to {}",
+ ADDRESS_TO_LOGGABLE_STR(new_peer_address));
+ peer_ready_promise.set_value();
+ return false;
+ }
}
if (old_peer_address.IsEmpty()) {
@@ -277,33 +284,32 @@ bool btif_a2dp_sink_restart_session(const RawAddress& old_peer_address,
}
bool btif_a2dp_sink_end_session(const RawAddress& peer_address) {
- LOG_INFO("%s: peer_address=%s", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_address));
+ log::info("peer_address={}", ADDRESS_TO_LOGGABLE_CSTR(peer_address));
btif_a2dp_sink_cb.worker_thread.DoInThread(
FROM_HERE, base::BindOnce(btif_a2dp_sink_end_session_delayed));
return true;
}
static void btif_a2dp_sink_end_session_delayed() {
- LOG_INFO("%s", __func__);
+ log::info("");
LockGuard lock(g_mutex);
// Nothing to do
}
void btif_a2dp_sink_shutdown() {
- LOG_INFO("%s", __func__);
+ log::info("");
btif_a2dp_sink_cb.worker_thread.DoInThread(
FROM_HERE, base::BindOnce(btif_a2dp_sink_shutdown_delayed));
}
static void btif_a2dp_sink_shutdown_delayed() {
- LOG_INFO("%s", __func__);
+ log::info("");
LockGuard lock(g_mutex);
// Nothing to do
}
void btif_a2dp_sink_cleanup() {
- LOG_INFO("%s", __func__);
+ log::info("");
alarm_t* decode_alarm;
@@ -333,7 +339,7 @@ void btif_a2dp_sink_cleanup() {
}
static void btif_a2dp_sink_cleanup_delayed() {
- LOG_INFO("%s", __func__);
+ log::info("");
LockGuard lock(g_mutex);
fixed_queue_free(btif_a2dp_sink_cb.rx_audio_queue, nullptr);
@@ -357,8 +363,7 @@ tA2DP_CHANNEL_COUNT btif_a2dp_sink_get_channel_count() {
}
static void btif_a2dp_sink_command_ready(BT_HDR_RIGID* p_msg) {
- LOG_VERBOSE("%s: event %d %s", __func__, p_msg->event,
- dump_media_event(p_msg->event));
+ log::verbose("event {} {}", p_msg->event, dump_media_event(p_msg->event));
switch (p_msg->event) {
case BTIF_MEDIA_SINK_DECODER_UPDATE:
@@ -384,23 +389,23 @@ static void btif_a2dp_sink_command_ready(BT_HDR_RIGID* p_msg) {
btif_a2dp_sink_on_suspend_event();
break;
default:
- LOG_ERROR("%s: unknown event %d", __func__, p_msg->event);
+ log::error("unknown event {}", p_msg->event);
break;
}
- LOG_VERBOSE("%s: %s DONE", __func__, dump_media_event(p_msg->event));
+ log::verbose("{} DONE", dump_media_event(p_msg->event));
osi_free(p_msg);
}
void btif_a2dp_sink_update_decoder(const uint8_t* p_codec_info) {
- LOG_INFO("%s", __func__);
+ log::info("");
tBTIF_MEDIA_SINK_DECODER_UPDATE* p_buf =
reinterpret_cast<tBTIF_MEDIA_SINK_DECODER_UPDATE*>(
osi_malloc(sizeof(tBTIF_MEDIA_SINK_DECODER_UPDATE)));
- LOG_VERBOSE("%s: p_codec_info[%x:%x:%x:%x:%x:%x]", __func__, p_codec_info[1],
- p_codec_info[2], p_codec_info[3], p_codec_info[4],
- p_codec_info[5], p_codec_info[6]);
+ log::verbose("p_codec_info[{:x}:{:x}:{:x}:{:x}:{:x}:{:x}]", p_codec_info[1],
+ p_codec_info[2], p_codec_info[3], p_codec_info[4],
+ p_codec_info[5], p_codec_info[6]);
memcpy(p_buf->codec_info, p_codec_info, AVDT_CODEC_SIZE);
p_buf->hdr.event = BTIF_MEDIA_SINK_DECODER_UPDATE;
@@ -411,7 +416,7 @@ void btif_a2dp_sink_update_decoder(const uint8_t* p_codec_info) {
}
void btif_a2dp_sink_on_idle() {
- LOG_INFO("%s", __func__);
+ log::info("");
BT_HDR_RIGID* p_buf =
reinterpret_cast<BT_HDR_RIGID*>(osi_malloc(sizeof(BT_HDR_RIGID)));
p_buf->event = BTIF_MEDIA_SINK_SUSPEND;
@@ -424,7 +429,7 @@ void btif_a2dp_sink_on_idle() {
}
void btif_a2dp_sink_on_stopped(tBTA_AV_SUSPEND* /* p_av_suspend */) {
- LOG_INFO("%s", __func__);
+ log::info("");
BT_HDR_RIGID* p_buf =
reinterpret_cast<BT_HDR_RIGID*>(osi_malloc(sizeof(BT_HDR_RIGID)));
p_buf->event = BTIF_MEDIA_SINK_SUSPEND;
@@ -436,7 +441,7 @@ void btif_a2dp_sink_on_stopped(tBTA_AV_SUSPEND* /* p_av_suspend */) {
}
void btif_a2dp_sink_on_suspended(tBTA_AV_SUSPEND* /* p_av_suspend */) {
- LOG_INFO("%s", __func__);
+ log::info("");
BT_HDR_RIGID* p_buf =
reinterpret_cast<BT_HDR_RIGID*>(osi_malloc(sizeof(BT_HDR_RIGID)));
p_buf->event = BTIF_MEDIA_SINK_SUSPEND;
@@ -448,7 +453,7 @@ void btif_a2dp_sink_on_suspended(tBTA_AV_SUSPEND* /* p_av_suspend */) {
}
bool btif_a2dp_sink_on_start() {
- LOG_INFO("%s", __func__);
+ log::info("");
BT_HDR_RIGID* p_buf =
reinterpret_cast<BT_HDR_RIGID*>(osi_malloc(sizeof(BT_HDR_RIGID)));
@@ -460,7 +465,7 @@ bool btif_a2dp_sink_on_start() {
}
static void btif_a2dp_sink_audio_handle_stop_decoding() {
- LOG_INFO("%s", __func__);
+ log::info("");
alarm_t* old_alarm;
{
LockGuard lock(g_mutex);
@@ -491,7 +496,7 @@ static void btif_decode_alarm_cb(void* /* context */) {
}
static void btif_a2dp_sink_clear_track_event() {
- LOG_INFO("%s", __func__);
+ log::info("");
LockGuard lock(g_mutex);
#ifdef __ANDROID__
@@ -503,7 +508,7 @@ static void btif_a2dp_sink_clear_track_event() {
// Must be called while locked.
static void btif_a2dp_sink_audio_handle_start_decoding() {
- LOG_INFO("%s", __func__);
+ log::info("");
if (btif_a2dp_sink_cb.decode_alarm != nullptr)
return; // Already started decoding
@@ -513,7 +518,7 @@ static void btif_a2dp_sink_audio_handle_start_decoding() {
btif_a2dp_sink_cb.decode_alarm = alarm_new_periodic("btif.a2dp_sink_decode");
if (btif_a2dp_sink_cb.decode_alarm == nullptr) {
- LOG_ERROR("%s: unable to allocate decode alarm", __func__);
+ log::error("unable to allocate decode alarm");
return;
}
alarm_set(btif_a2dp_sink_cb.decode_alarm, BTIF_SINK_MEDIA_TIME_TICK_MS,
@@ -529,15 +534,15 @@ static void btif_a2dp_sink_on_decode_complete(uint8_t* data, uint32_t len) {
// Must be called while locked.
static void btif_a2dp_sink_handle_inc_media(BT_HDR* p_msg) {
- if ((btif_av_get_peer_sep() == AVDT_TSEP_SNK) ||
+ if ((btif_av_get_peer_sep(A2dpType::kSink) == AVDT_TSEP_SNK) ||
(btif_a2dp_sink_cb.rx_flush)) {
- LOG_VERBOSE("%s: state changed happened in this tick", __func__);
+ log::verbose("state changed happened in this tick");
return;
}
CHECK(btif_a2dp_sink_cb.decoder_interface != nullptr);
if (!btif_a2dp_sink_cb.decoder_interface->decode_packet(p_msg)) {
- LOG_ERROR("%s: decoding failed", __func__);
+ log::error("decoding failed");
}
}
@@ -546,13 +551,13 @@ static void btif_a2dp_sink_avk_handle_timer() {
BT_HDR* p_msg;
if (fixed_queue_is_empty(btif_a2dp_sink_cb.rx_audio_queue)) {
- LOG_VERBOSE("%s: empty queue", __func__);
+ log::verbose("empty queue");
return;
}
/* Don't do anything in case of focus not granted */
if (btif_a2dp_sink_cb.rx_focus_state == BTIF_A2DP_SINK_FOCUS_NOT_GRANTED) {
- LOG_VERBOSE("%s: skipping frames since focus is not present", __func__);
+ log::verbose("skipping frames since focus is not present");
return;
}
/* Play only in BTIF_A2DP_SINK_FOCUS_GRANTED case */
@@ -561,32 +566,32 @@ static void btif_a2dp_sink_avk_handle_timer() {
return;
}
- LOG_VERBOSE("%s: process frames begin", __func__);
+ log::verbose("process frames begin");
while (true) {
p_msg = (BT_HDR*)fixed_queue_try_dequeue(btif_a2dp_sink_cb.rx_audio_queue);
if (p_msg == NULL) {
break;
}
- LOG_VERBOSE("%s: number of packets in queue %zu", __func__,
- fixed_queue_length(btif_a2dp_sink_cb.rx_audio_queue));
+ log::verbose("number of packets in queue {}",
+ fixed_queue_length(btif_a2dp_sink_cb.rx_audio_queue));
/* Queue packet has less frames */
btif_a2dp_sink_handle_inc_media(p_msg);
osi_free(p_msg);
}
- LOG_VERBOSE("%s: process frames end", __func__);
+ log::verbose("process frames end");
}
/* when true media task discards any rx frames */
void btif_a2dp_sink_set_rx_flush(bool enable) {
- LOG_INFO("%s: enable=%s", __func__, (enable) ? "true" : "false");
+ log::info("enable={}", (enable) ? "true" : "false");
LockGuard lock(g_mutex);
btif_a2dp_sink_cb.rx_flush = enable;
}
static void btif_a2dp_sink_audio_rx_flush_event() {
- LOG_INFO("%s", __func__);
+ log::info("");
LockGuard lock(g_mutex);
// Flush all received encoded audio buffers
fixed_queue_flush(btif_a2dp_sink_cb.rx_audio_queue, osi_free);
@@ -594,30 +599,31 @@ static void btif_a2dp_sink_audio_rx_flush_event() {
static void btif_a2dp_sink_decoder_update_event(
tBTIF_MEDIA_SINK_DECODER_UPDATE* p_buf) {
- LOG_INFO("%s", __func__);
+ log::info("");
LockGuard lock(g_mutex);
- LOG_VERBOSE("%s: p_codec_info[%x:%x:%x:%x:%x:%x]", __func__,
- p_buf->codec_info[1], p_buf->codec_info[2], p_buf->codec_info[3],
- p_buf->codec_info[4], p_buf->codec_info[5], p_buf->codec_info[6]);
+ log::verbose("p_codec_info[{:x}:{:x}:{:x}:{:x}:{:x}:{:x}]",
+ p_buf->codec_info[1], p_buf->codec_info[2], p_buf->codec_info[3],
+ p_buf->codec_info[4], p_buf->codec_info[5],
+ p_buf->codec_info[6]);
int sample_rate = A2DP_GetTrackSampleRate(p_buf->codec_info);
if (sample_rate == -1) {
- LOG_ERROR("%s: cannot get the track frequency", __func__);
+ log::error("cannot get the track frequency");
return;
}
int bits_per_sample = A2DP_GetTrackBitsPerSample(p_buf->codec_info);
if (bits_per_sample == -1) {
- LOG_ERROR("%s: cannot get the bits per sample", __func__);
+ log::error("cannot get the bits per sample");
return;
}
int channel_count = A2DP_GetTrackChannelCount(p_buf->codec_info);
if (channel_count == -1) {
- LOG_ERROR("%s: cannot get the channel count", __func__);
+ log::error("cannot get the channel count");
return;
}
int channel_type = A2DP_GetSinkTrackChannelType(p_buf->codec_info);
if (channel_type == -1) {
- LOG_ERROR("%s: cannot get the Sink channel type", __func__);
+ log::error("cannot get the Sink channel type");
return;
}
btif_a2dp_sink_cb.sample_rate = sample_rate;
@@ -625,7 +631,7 @@ static void btif_a2dp_sink_decoder_update_event(
btif_a2dp_sink_cb.channel_count = channel_count;
btif_a2dp_sink_cb.rx_flush = false;
- LOG_VERBOSE("%s: reset to Sink role", __func__);
+ log::verbose("reset to Sink role");
bta_av_co_save_codec(p_buf->codec_info);
@@ -633,13 +639,13 @@ static void btif_a2dp_sink_decoder_update_event(
A2DP_GetDecoderInterface(p_buf->codec_info);
if (btif_a2dp_sink_cb.decoder_interface == nullptr) {
- LOG_ERROR("%s: cannot stream audio: no source decoder interface", __func__);
+ log::error("cannot stream audio: no source decoder interface");
return;
}
if (!btif_a2dp_sink_cb.decoder_interface->decoder_init(
btif_a2dp_sink_on_decode_complete)) {
- LOG_ERROR("%s: failed to initialize decoder", __func__);
+ log::error("failed to initialize decoder");
return;
}
@@ -647,7 +653,7 @@ static void btif_a2dp_sink_decoder_update_event(
btif_a2dp_sink_cb.decoder_interface->decoder_configure(p_buf->codec_info);
}
- LOG_VERBOSE("%s: create audio track", __func__);
+ log::verbose("create audio track");
btif_a2dp_sink_cb.audio_track =
#ifdef __ANDROID__
BtifAvrcpAudioTrackCreate(sample_rate, bits_per_sample, channel_count);
@@ -655,7 +661,7 @@ static void btif_a2dp_sink_decoder_update_event(
NULL;
#endif
if (btif_a2dp_sink_cb.audio_track == nullptr) {
- LOG_ERROR("%s: track creation failed", __func__);
+ log::error("track creation failed");
return;
}
}
@@ -665,7 +671,7 @@ uint8_t btif_a2dp_sink_enqueue_buf(BT_HDR* p_pkt) {
if (btif_a2dp_sink_cb.rx_flush) /* Flush enabled, do not enqueue */
return fixed_queue_length(btif_a2dp_sink_cb.rx_audio_queue);
- LOG_VERBOSE("%s +", __func__);
+ log::verbose("+");
/* Allocate and queue this buffer */
BT_HDR* p_msg =
reinterpret_cast<BT_HDR*>(osi_malloc(sizeof(*p_msg) + p_pkt->len));
@@ -685,8 +691,8 @@ uint8_t btif_a2dp_sink_enqueue_buf(BT_HDR* p_pkt) {
if (btif_a2dp_sink_cb.decode_alarm == nullptr &&
fixed_queue_length(btif_a2dp_sink_cb.rx_audio_queue) >=
MAX_A2DP_DELAYED_START_FRAME_COUNT) {
- LOG_VERBOSE("%s: Initiate decoding. Current focus state:%d", __func__,
- btif_a2dp_sink_cb.rx_focus_state);
+ log::verbose("Initiate decoding. Current focus state:{}",
+ btif_a2dp_sink_cb.rx_focus_state);
if (btif_a2dp_sink_cb.rx_focus_state == BTIF_A2DP_SINK_FOCUS_GRANTED) {
btif_a2dp_sink_audio_handle_start_decoding();
}
@@ -696,7 +702,7 @@ uint8_t btif_a2dp_sink_enqueue_buf(BT_HDR* p_pkt) {
}
void btif_a2dp_sink_audio_rx_flush_req() {
- LOG_INFO("%s", __func__);
+ log::info("");
if (fixed_queue_is_empty(btif_a2dp_sink_cb.rx_audio_queue)) {
/* Queue is already empty */
return;
@@ -714,7 +720,7 @@ void btif_a2dp_sink_debug_dump(int /* fd */) {
}
void btif_a2dp_sink_set_focus_state_req(btif_a2dp_sink_focus_state_t state) {
- LOG_INFO("%s", __func__);
+ log::info("");
tBTIF_MEDIA_SINK_FOCUS_UPDATE* p_buf =
reinterpret_cast<tBTIF_MEDIA_SINK_FOCUS_UPDATE*>(
osi_malloc(sizeof(tBTIF_MEDIA_SINK_FOCUS_UPDATE)));
@@ -727,10 +733,10 @@ void btif_a2dp_sink_set_focus_state_req(btif_a2dp_sink_focus_state_t state) {
static void btif_a2dp_sink_set_focus_state_event(
btif_a2dp_sink_focus_state_t state) {
- LOG_INFO("%s: state=%d", __func__, state);
+ log::info("state={}", state);
LockGuard lock(g_mutex);
- LOG_VERBOSE("%s: setting focus state to %d", __func__, state);
+ log::verbose("setting focus state to {}", state);
btif_a2dp_sink_cb.rx_focus_state = state;
if (btif_a2dp_sink_cb.rx_focus_state == BTIF_A2DP_SINK_FOCUS_NOT_GRANTED) {
fixed_queue_flush(btif_a2dp_sink_cb.rx_audio_queue, osi_free);
@@ -741,7 +747,7 @@ static void btif_a2dp_sink_set_focus_state_event(
}
void btif_a2dp_sink_set_audio_track_gain(float gain) {
- LOG_DEBUG("%s: set gain to %f", __func__, gain);
+ log::debug("set gain to {:f}", gain);
LockGuard lock(g_mutex);
#ifdef __ANDROID__
@@ -755,7 +761,7 @@ void * btif_a2dp_sink_get_audio_track(void)
}
static void btif_a2dp_sink_clear_track_event_req() {
- LOG_INFO("%s", __func__);
+ log::info("");
BT_HDR_RIGID* p_buf =
reinterpret_cast<BT_HDR_RIGID*>(osi_malloc(sizeof(BT_HDR_RIGID)));
@@ -765,7 +771,7 @@ static void btif_a2dp_sink_clear_track_event_req() {
}
static void btif_a2dp_sink_on_start_event() {
- LOG_INFO("%s", __func__);
+ log::info("");
if ((btif_a2dp_sink_cb.decoder_interface != nullptr) &&
(btif_a2dp_sink_cb.decoder_interface->decoder_start != nullptr)) {
@@ -776,7 +782,7 @@ static void btif_a2dp_sink_on_start_event() {
}
static void btif_a2dp_sink_on_suspend_event() {
- LOG_INFO("%s", __func__);
+ log::info("");
if ((btif_a2dp_sink_cb.decoder_interface != nullptr) &&
(btif_a2dp_sink_cb.decoder_interface->decoder_suspend != nullptr)) {
diff --git a/system/btif/src/btif_a2dp_source.cc b/system/btif/src/btif_a2dp_source.cc
index ad4c3922fc..c07400390c 100644
--- a/system/btif/src/btif_a2dp_source.cc
+++ b/system/btif/src/btif_a2dp_source.cc
@@ -23,6 +23,7 @@
#include <android_bluetooth_flags.h>
#include <base/logging.h>
#include <base/run_loop.h>
+#include <bluetooth/log.h>
#ifdef __ANDROID__
#include <cutils/trace.h>
#endif
@@ -59,6 +60,7 @@
using bluetooth::common::A2dpSessionMetrics;
using bluetooth::common::BluetoothMetricsLogger;
using bluetooth::common::RepeatingTimer;
+using namespace bluetooth;
extern std::unique_ptr<tUIPC_STATE> a2dp_uipc;
@@ -329,7 +331,7 @@ void btif_a2dp_source_accumulate_stats(BtifMediaStats* src,
}
bool btif_a2dp_source_init(void) {
- LOG_INFO("%s", __func__);
+ log::info("");
// Start A2DP Source media task
btif_a2dp_source_thread.StartUp();
@@ -339,7 +341,7 @@ bool btif_a2dp_source_init(void) {
}
static void btif_a2dp_source_init_delayed(void) {
- LOG_INFO("%s", __func__);
+ log::info("");
// When codec extensibility is enabled in the audio HAL interface,
// the provider needs to be initialized earlier in order to ensure
// get_a2dp_configuration and parse_a2dp_configuration can be
@@ -350,10 +352,10 @@ static void btif_a2dp_source_init_delayed(void) {
}
bool btif_a2dp_source_startup(void) {
- LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str());
+ log::info("state={}", btif_a2dp_source_cb.StateStr());
if (btif_a2dp_source_cb.State() != BtifA2dpSource::kStateOff) {
- LOG_ERROR("%s: A2DP Source media task already running", __func__);
+ log::error("A2DP Source media task already running");
return false;
}
@@ -369,18 +371,18 @@ 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());
+ log::info("state={}", btif_a2dp_source_cb.StateStr());
if (!btif_a2dp_source_thread.EnableRealTimeScheduling()) {
#if defined(__ANDROID__)
- LOG(FATAL) << __func__ << ": unable to enable real time scheduling";
+ log::fatal("unable to enable real time scheduling");
#endif
}
if (!bluetooth::audio::a2dp::init(&btif_a2dp_source_thread)) {
if (btif_av_is_a2dp_offload_enabled()) {
// TODO: BluetoothA2dp@1.0 is deprecated
- LOG(WARNING) << __func__ << ": Using BluetoothA2dp HAL";
+ log::warn("Using BluetoothA2dp HAL");
} else {
- LOG(WARNING) << __func__ << ": Using legacy HAL";
+ log::warn("Using legacy HAL");
btif_a2dp_control_init();
}
}
@@ -389,9 +391,8 @@ static void btif_a2dp_source_startup_delayed() {
bool btif_a2dp_source_start_session(const RawAddress& peer_address,
std::promise<void> peer_ready_promise) {
- LOG(INFO) << __func__ << ": peer_address="
- << ADDRESS_TO_LOGGABLE_STR(peer_address)
- << " state=" << btif_a2dp_source_cb.StateStr();
+ log::info("peer_address={} state={}", ADDRESS_TO_LOGGABLE_STR(peer_address),
+ btif_a2dp_source_cb.StateStr());
btif_a2dp_source_setup_codec(peer_address);
if (btif_a2dp_source_thread.DoInThread(
FROM_HERE,
@@ -400,27 +401,26 @@ bool btif_a2dp_source_start_session(const RawAddress& peer_address,
return true;
} else {
// cannot set promise but triggers crash
- LOG(FATAL) << __func__ << ": peer_address="
- << ADDRESS_TO_LOGGABLE_STR(peer_address)
- << " state=" << btif_a2dp_source_cb.StateStr()
- << " fails to context switch";
+ log::fatal("peer_address={} state={} fails to context switch",
+ ADDRESS_TO_LOGGABLE_STR(peer_address),
+ btif_a2dp_source_cb.StateStr());
return false;
}
}
static void btif_a2dp_source_start_session_delayed(
const RawAddress& peer_address, std::promise<void> peer_ready_promise) {
- LOG(INFO) << __func__ << ": peer_address="
- << ADDRESS_TO_LOGGABLE_STR(peer_address)
- << " state=" << btif_a2dp_source_cb.StateStr();
+ log::info("peer_address={} state={}", ADDRESS_TO_LOGGABLE_STR(peer_address),
+ btif_a2dp_source_cb.StateStr());
if (btif_a2dp_source_cb.State() != BtifA2dpSource::kStateRunning) {
- LOG(ERROR) << __func__ << ": A2DP Source media task is not running";
+ log::error("A2DP Source media task is not running");
peer_ready_promise.set_value();
return;
}
if (bluetooth::audio::a2dp::is_hal_enabled()) {
bluetooth::audio::a2dp::start_session();
- bluetooth::audio::a2dp::set_remote_delay(btif_av_get_audio_delay());
+ bluetooth::audio::a2dp::set_remote_delay(
+ btif_av_get_audio_delay(A2dpType::kSource));
BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionStart(
bluetooth::common::CONNECTION_TECHNOLOGY_TYPE_BREDR, 0);
} else {
@@ -433,10 +433,10 @@ static void btif_a2dp_source_start_session_delayed(
bool btif_a2dp_source_restart_session(const RawAddress& old_peer_address,
const RawAddress& new_peer_address,
std::promise<void> peer_ready_promise) {
- LOG(INFO) << __func__ << ": old_peer_address="
- << ADDRESS_TO_LOGGABLE_STR(old_peer_address)
- << " new_peer_address=" << ADDRESS_TO_LOGGABLE_STR(new_peer_address)
- << " state=" << btif_a2dp_source_cb.StateStr();
+ log::info("old_peer_address={} new_peer_address={} state={}",
+ ADDRESS_TO_LOGGABLE_STR(old_peer_address),
+ ADDRESS_TO_LOGGABLE_STR(new_peer_address),
+ btif_a2dp_source_cb.StateStr());
CHECK(!new_peer_address.IsEmpty());
@@ -460,9 +460,8 @@ bool btif_a2dp_source_restart_session(const RawAddress& old_peer_address,
}
bool btif_a2dp_source_end_session(const RawAddress& peer_address) {
- LOG_INFO("%s: peer_address=%s state=%s", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_address),
- btif_a2dp_source_cb.StateStr().c_str());
+ log::info("peer_address={} state={}", ADDRESS_TO_LOGGABLE_CSTR(peer_address),
+ btif_a2dp_source_cb.StateStr());
btif_a2dp_source_thread.DoInThread(
FROM_HERE,
base::BindOnce(&btif_a2dp_source_end_session_delayed, peer_address));
@@ -472,14 +471,13 @@ bool btif_a2dp_source_end_session(const RawAddress& peer_address) {
static void btif_a2dp_source_end_session_delayed(
const RawAddress& peer_address) {
- LOG_INFO("%s: peer_address=%s state=%s", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_address),
- btif_a2dp_source_cb.StateStr().c_str());
+ log::info("peer_address={} state={}", ADDRESS_TO_LOGGABLE_CSTR(peer_address),
+ btif_a2dp_source_cb.StateStr());
if ((btif_a2dp_source_cb.State() == BtifA2dpSource::kStateRunning) ||
(btif_a2dp_source_cb.State() == BtifA2dpSource::kStateShuttingDown)) {
btif_av_stream_stop(peer_address);
} else {
- LOG_ERROR("%s: A2DP Source media task is not running", __func__);
+ log::error("A2DP Source media task is not running");
}
if (bluetooth::audio::a2dp::is_hal_enabled()) {
bluetooth::audio::a2dp::end_session();
@@ -492,7 +490,7 @@ static void btif_a2dp_source_end_session_delayed(
}
void btif_a2dp_source_shutdown(std::promise<void> shutdown_complete_promise) {
- LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str());
+ log::info("state={}", btif_a2dp_source_cb.StateStr());
if ((btif_a2dp_source_cb.State() == BtifA2dpSource::kStateOff) ||
(btif_a2dp_source_cb.State() == BtifA2dpSource::kStateShuttingDown)) {
@@ -509,7 +507,7 @@ void btif_a2dp_source_shutdown(std::promise<void> shutdown_complete_promise) {
static void btif_a2dp_source_shutdown_delayed(
std::promise<void> shutdown_complete_promise) {
- LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str());
+ log::info("state={}", btif_a2dp_source_cb.StateStr());
// Stop the timer
btif_a2dp_source_cb.media_alarm.CancelAndWait();
@@ -529,7 +527,7 @@ static void btif_a2dp_source_shutdown_delayed(
}
void btif_a2dp_source_cleanup(void) {
- LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str());
+ log::info("state={}", btif_a2dp_source_cb.StateStr());
// Make sure the source is shutdown
std::promise<void> shutdown_complete_promise;
@@ -543,7 +541,7 @@ void btif_a2dp_source_cleanup(void) {
}
static void btif_a2dp_source_cleanup_delayed(void) {
- LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str());
+ log::info("state={}", btif_a2dp_source_cb.StateStr());
// Nothing to do
}
@@ -561,9 +559,8 @@ bool btif_a2dp_source_is_streaming(void) {
}
static void btif_a2dp_source_setup_codec(const RawAddress& peer_address) {
- LOG_INFO("%s: peer_address=%s state=%s", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_address),
- btif_a2dp_source_cb.StateStr().c_str());
+ log::info("peer_address={} state={}", ADDRESS_TO_LOGGABLE_CSTR(peer_address),
+ btif_a2dp_source_cb.StateStr());
// Check to make sure the platform has 8 bits/byte since
// we're using that in frame size calculations now.
@@ -577,27 +574,33 @@ static void btif_a2dp_source_setup_codec(const RawAddress& peer_address) {
static void btif_a2dp_source_setup_codec_delayed(
const RawAddress& peer_address) {
- LOG_INFO("%s: peer_address=%s state=%s", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_address),
- btif_a2dp_source_cb.StateStr().c_str());
+ log::info("peer_address={} state={}", ADDRESS_TO_LOGGABLE_CSTR(peer_address),
+ btif_a2dp_source_cb.StateStr());
tA2DP_ENCODER_INIT_PEER_PARAMS peer_params;
bta_av_co_get_peer_params(peer_address, &peer_params);
-
- if (!bta_av_co_set_active_peer(peer_address)) {
- LOG_ERROR("%s: Cannot stream audio: cannot set active peer to %s", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_address));
- return;
+ if (IS_FLAG_ENABLED(a2dp_concurrent_source_sink)) {
+ if (!bta_av_co_set_active_source_peer(peer_address)) {
+ log::error("Cannot stream audio: cannot set active peer to {}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_address));
+ return;
+ }
+ } else {
+ if (!bta_av_co_set_active_peer(peer_address)) {
+ log::error("Cannot stream audio: cannot set active peer to {}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_address));
+ return;
+ }
}
btif_a2dp_source_cb.encoder_interface = bta_av_co_get_encoder_interface();
if (btif_a2dp_source_cb.encoder_interface == nullptr) {
- LOG_ERROR("%s: Cannot stream audio: no source encoder interface", __func__);
+ log::error("Cannot stream audio: no source encoder interface");
return;
}
A2dpCodecConfig* a2dp_codec_config = bta_av_get_a2dp_current_codec();
if (a2dp_codec_config == nullptr) {
- LOG_ERROR("%s: Cannot stream audio: current codec is not set", __func__);
+ log::error("Cannot stream audio: current codec is not set");
return;
}
@@ -615,7 +618,7 @@ static void btif_a2dp_source_setup_codec_delayed(
}
static void btif_a2dp_source_cleanup_codec() {
- LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str());
+ log::info("state={}", btif_a2dp_source_cb.StateStr());
// Must stop media task first before cleaning up the encoder
btif_a2dp_source_stop_audio_req();
btif_a2dp_source_thread.DoInThread(
@@ -623,7 +626,7 @@ static void btif_a2dp_source_cleanup_codec() {
}
static void btif_a2dp_source_cleanup_codec_delayed() {
- LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str());
+ log::info("state={}", btif_a2dp_source_cb.StateStr());
if (btif_a2dp_source_cb.encoder_interface != nullptr) {
btif_a2dp_source_cb.encoder_interface->encoder_cleanup();
btif_a2dp_source_cb.encoder_interface = nullptr;
@@ -631,14 +634,14 @@ static void btif_a2dp_source_cleanup_codec_delayed() {
}
void btif_a2dp_source_start_audio_req(void) {
- LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str());
+ log::info("state={}", btif_a2dp_source_cb.StateStr());
btif_a2dp_source_thread.DoInThread(
FROM_HERE, base::BindOnce(&btif_a2dp_source_audio_tx_start_event));
}
void btif_a2dp_source_stop_audio_req(void) {
- LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str());
+ log::info("state={}", btif_a2dp_source_cb.StateStr());
btif_a2dp_source_thread.DoInThread(
FROM_HERE, base::BindOnce(&btif_a2dp_source_audio_tx_stop_event));
@@ -648,20 +651,18 @@ void btif_a2dp_source_encoder_user_config_update_req(
const RawAddress& peer_address,
const std::vector<btav_a2dp_codec_config_t>& codec_user_preferences,
std::promise<void> peer_ready_promise) {
- LOG(INFO) << __func__ << ": peer_address="
- << ADDRESS_TO_LOGGABLE_STR(peer_address)
- << " state=" << btif_a2dp_source_cb.StateStr() << " "
- << codec_user_preferences.size() << " codec_preference(s)";
+ log::info("peer_address={} state={} {} codec_preference(s)",
+ ADDRESS_TO_LOGGABLE_STR(peer_address),
+ btif_a2dp_source_cb.StateStr(), codec_user_preferences.size());
if (!btif_a2dp_source_thread.DoInThread(
FROM_HERE,
base::BindOnce(&btif_a2dp_source_encoder_user_config_update_event,
peer_address, codec_user_preferences,
std::move(peer_ready_promise)))) {
// cannot set promise but triggers crash
- LOG(FATAL) << __func__ << ": peer_address="
- << ADDRESS_TO_LOGGABLE_STR(peer_address)
- << " state=" << btif_a2dp_source_cb.StateStr()
- << " fails to context switch";
+ log::fatal("peer_address={} state={} fails to context switch",
+ ADDRESS_TO_LOGGABLE_STR(peer_address),
+ btif_a2dp_source_cb.StateStr());
}
}
@@ -675,11 +676,10 @@ static void btif_a2dp_source_encoder_user_config_update_event(
success = bta_av_co_set_codec_user_config(peer_address, codec_user_config,
&restart_output);
if (success) {
- LOG(INFO) << __func__ << ": peer_address="
- << ADDRESS_TO_LOGGABLE_STR(peer_address)
- << " state=" << btif_a2dp_source_cb.StateStr()
- << " codec_preference={" << codec_user_config.ToString()
- << "} restart_output=" << (restart_output ? "true" : "false");
+ log::info(
+ "peer_address={} state={} codec_preference=[{}] restart_output={}",
+ ADDRESS_TO_LOGGABLE_STR(peer_address), btif_a2dp_source_cb.StateStr(),
+ codec_user_config.ToString(), (restart_output ? "true" : "false"));
break;
}
}
@@ -691,7 +691,7 @@ static void btif_a2dp_source_encoder_user_config_update_event(
return;
}
if (!success) {
- LOG(ERROR) << __func__ << ": cannot update codec user configuration(s)";
+ log::error("cannot update codec user configuration(s)");
}
if (!peer_address.IsEmpty() && peer_address == btif_av_source_active_peer()) {
// No more actions needed with remote, and if succeed, user had changed the
@@ -705,7 +705,7 @@ static void btif_a2dp_source_encoder_user_config_update_event(
void btif_a2dp_source_feeding_update_req(
const btav_a2dp_codec_config_t& codec_audio_config) {
- LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str());
+ log::info("state={}", btif_a2dp_source_cb.StateStr());
btif_a2dp_source_thread.DoInThread(
FROM_HERE, base::BindOnce(&btif_a2dp_source_audio_feeding_update_event,
codec_audio_config));
@@ -713,14 +713,14 @@ void btif_a2dp_source_feeding_update_req(
static void btif_a2dp_source_audio_feeding_update_event(
const btav_a2dp_codec_config_t& codec_audio_config) {
- LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str());
+ log::info("state={}", btif_a2dp_source_cb.StateStr());
if (!bta_av_co_set_codec_audio_config(codec_audio_config)) {
- LOG_ERROR("%s: cannot update codec audio feeding parameters", __func__);
+ log::error("cannot update codec audio feeding parameters");
}
}
void btif_a2dp_source_on_idle(void) {
- LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str());
+ log::info("state={}", btif_a2dp_source_cb.StateStr());
if (btif_a2dp_source_cb.State() == BtifA2dpSource::kStateOff) return;
/* Make sure media task is stopped */
@@ -728,16 +728,16 @@ void btif_a2dp_source_on_idle(void) {
}
void btif_a2dp_source_on_stopped(tBTA_AV_SUSPEND* p_av_suspend) {
- LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str());
+ log::info("state={}", btif_a2dp_source_cb.StateStr());
btif_a2dp_source_cb.sw_audio_is_encoding = false;
// allow using this API for other (acknowledgement and stopping media task)
// than suspend
if (p_av_suspend != nullptr && p_av_suspend->status != BTA_AV_SUCCESS) {
- LOG_ERROR("%s: A2DP stop failed: status=%d, initiator=%s", __func__,
- p_av_suspend->status,
- (p_av_suspend->initiator ? "true" : "false"));
+ log::error("A2DP stop failed: status={}, initiator={}",
+ p_av_suspend->status,
+ (p_av_suspend->initiator ? "true" : "false"));
if (p_av_suspend->initiator) {
if (bluetooth::audio::a2dp::is_hal_enabled()) {
bluetooth::audio::a2dp::ack_stream_suspended(A2DP_CTRL_ACK_FAILURE);
@@ -764,7 +764,7 @@ void btif_a2dp_source_on_stopped(tBTA_AV_SUSPEND* p_av_suspend) {
}
void btif_a2dp_source_on_suspended(tBTA_AV_SUSPEND* p_av_suspend) {
- LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str());
+ log::info("state={}", btif_a2dp_source_cb.StateStr());
if (btif_a2dp_source_cb.State() == BtifA2dpSource::kStateOff) return;
@@ -772,9 +772,9 @@ void btif_a2dp_source_on_suspended(tBTA_AV_SUSPEND* p_av_suspend) {
// check for status failures
if (p_av_suspend->status != BTA_AV_SUCCESS) {
- LOG_WARN("%s: A2DP suspend failed: status=%d, initiator=%s", __func__,
- p_av_suspend->status,
- (p_av_suspend->initiator ? "true" : "false"));
+ log::warn("A2DP suspend failed: status={}, initiator={}",
+ p_av_suspend->status,
+ (p_av_suspend->initiator ? "true" : "false"));
if (p_av_suspend->initiator) {
if (bluetooth::audio::a2dp::is_hal_enabled()) {
bluetooth::audio::a2dp::ack_stream_suspended(A2DP_CTRL_ACK_FAILURE);
@@ -798,15 +798,15 @@ void btif_a2dp_source_on_suspended(tBTA_AV_SUSPEND* p_av_suspend) {
/* when true media task discards any tx frames */
void btif_a2dp_source_set_tx_flush(bool enable) {
- LOG_INFO("%s: enable=%s state=%s", __func__, (enable) ? "true" : "false",
- btif_a2dp_source_cb.StateStr().c_str());
+ log::info("enable={} state={}", (enable) ? "true" : "false",
+ btif_a2dp_source_cb.StateStr());
btif_a2dp_source_cb.tx_flush = enable;
}
static void btif_a2dp_source_audio_tx_start_event(void) {
- LOG_INFO("%s: streaming %s state=%s", __func__,
- btif_a2dp_source_is_streaming() ? "true" : "false",
- btif_a2dp_source_cb.StateStr().c_str());
+ log::info("streaming {} state={}",
+ btif_a2dp_source_is_streaming() ? "true" : "false",
+ btif_a2dp_source_cb.StateStr());
if (btif_av_is_a2dp_offload_running()) return;
@@ -814,8 +814,9 @@ static void btif_a2dp_source_audio_tx_start_event(void) {
CHECK(btif_a2dp_source_cb.encoder_interface != nullptr);
btif_a2dp_source_cb.encoder_interface->feeding_reset();
- LOG_VERBOSE("%s: starting timer %" PRIu64 " ms", __func__,
- btif_a2dp_source_cb.encoder_interface->get_encoder_interval_ms());
+ log::verbose(
+ "starting timer {} ms",
+ btif_a2dp_source_cb.encoder_interface->get_encoder_interval_ms());
/* audio engine starting, reset tx suspended flag */
btif_a2dp_source_cb.tx_flush = false;
@@ -845,9 +846,9 @@ static void btif_a2dp_source_audio_tx_start_event(void) {
}
static void btif_a2dp_source_audio_tx_stop_event(void) {
- LOG_INFO("%s: streaming %s state=%s", __func__,
- btif_a2dp_source_is_streaming() ? "true" : "false",
- btif_a2dp_source_cb.StateStr().c_str());
+ log::info("streaming {} state={}",
+ btif_a2dp_source_is_streaming() ? "true" : "false",
+ btif_a2dp_source_cb.StateStr());
if (btif_av_is_a2dp_offload_running()) return;
if (!btif_a2dp_source_is_streaming()) return;
@@ -916,7 +917,7 @@ static void btif_a2dp_source_audio_handle_timer(void) {
log_tstamps_us("A2DP Source tx scheduling timer", timestamp_us);
if (!btif_a2dp_source_is_streaming()) {
- LOG_ERROR("%s: ERROR Media task Scheduled after Suspend", __func__);
+ log::error("ERROR Media task Scheduled after Suspend");
return;
}
CHECK(btif_a2dp_source_cb.encoder_interface != nullptr);
@@ -947,8 +948,7 @@ static uint32_t btif_a2dp_source_read_callback(uint8_t* p_buf, uint32_t len) {
}
if (btif_a2dp_source_cb.sw_audio_is_encoding && bytes_read < len) {
- LOG_WARN("%s: UNDERFLOW: ONLY READ %d BYTES OUT OF %d", __func__,
- bytes_read, len);
+ log::warn("UNDERFLOW: ONLY READ {} BYTES OUT OF {}", bytes_read, len);
btif_a2dp_source_cb.stats.media_read_total_underflow_bytes +=
(len - bytes_read);
btif_a2dp_source_cb.stats.media_read_total_underflow_count++;
@@ -975,7 +975,7 @@ static bool btif_a2dp_source_enqueue_callback(BT_HDR* p_buf, size_t frames_n,
/* Check if the transmission queue has been flushed */
if (btif_a2dp_source_cb.tx_flush) {
- LOG_VERBOSE("%s: tx suspended, discarded frame", __func__);
+ log::verbose("tx suspended, discarded frame");
btif_a2dp_source_cb.stats.tx_queue_total_flushed_messages +=
fixed_queue_length(btif_a2dp_source_cb.tx_audio_queue);
@@ -990,9 +990,9 @@ static bool btif_a2dp_source_enqueue_callback(BT_HDR* p_buf, size_t frames_n,
// TODO: Using frames_n here is probably wrong: should be "+ 1" instead.
if (fixed_queue_length(btif_a2dp_source_cb.tx_audio_queue) + frames_n >
btif_a2dp_source_dynamic_audio_buffer_size) {
- LOG_WARN("%s: TX queue buffer size now=%u adding=%u max=%d", __func__,
- (uint32_t)fixed_queue_length(btif_a2dp_source_cb.tx_audio_queue),
- (uint32_t)frames_n, btif_a2dp_source_dynamic_audio_buffer_size);
+ log::warn("TX queue buffer size now={} adding={} max={}",
+ (uint32_t)fixed_queue_length(btif_a2dp_source_cb.tx_audio_queue),
+ (uint32_t)frames_n, btif_a2dp_source_dynamic_audio_buffer_size);
// Keep track of drop-outs
btif_a2dp_source_cb.stats.tx_queue_dropouts++;
btif_a2dp_source_cb.stats.tx_queue_last_dropouts_us = now_us;
@@ -1022,7 +1022,7 @@ static bool btif_a2dp_source_enqueue_callback(BT_HDR* p_buf, size_t frames_n,
RawAddress peer_bda = btif_av_source_active_peer();
tBTM_STATUS status = BTM_ReadRSSI(peer_bda, btm_read_rssi_cb);
if (status != BTM_CMD_STARTED) {
- LOG_WARN("%s: Cannot read RSSI: status %d", __func__, status);
+ log::warn("Cannot read RSSI: status {}", status);
}
// Intel controllers don't handle ReadFailedContactCounter very well, it
@@ -1035,15 +1035,14 @@ static bool btif_a2dp_source_enqueue_callback(BT_HDR* p_buf, size_t frames_n,
status = BTM_ReadFailedContactCounter(peer_bda,
btm_read_failed_contact_counter_cb);
if (status != BTM_CMD_STARTED) {
- LOG_WARN("%s: Cannot read Failed Contact Counter: status %d", __func__,
- status);
+ log::warn("Cannot read Failed Contact Counter: status {}", status);
}
#endif
status =
BTM_ReadTxPower(peer_bda, BT_TRANSPORT_BR_EDR, btm_read_tx_power_cb);
if (status != BTM_CMD_STARTED) {
- LOG_WARN("%s: Cannot read Tx Power: status %d", __func__, status);
+ log::warn("Cannot read Tx Power: status {}", status);
}
}
@@ -1060,7 +1059,7 @@ static bool btif_a2dp_source_enqueue_callback(BT_HDR* p_buf, size_t frames_n,
static void btif_a2dp_source_audio_tx_flush_event(void) {
/* Flush all enqueued audio buffers (encoded) */
- LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str());
+ log::info("state={}", btif_a2dp_source_cb.StateStr());
if (btif_av_is_a2dp_offload_running()) return;
if (btif_a2dp_source_cb.encoder_interface != nullptr)
@@ -1078,7 +1077,7 @@ static void btif_a2dp_source_audio_tx_flush_event(void) {
}
static bool btif_a2dp_source_audio_tx_flush_req(void) {
- LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str());
+ log::info("state={}", btif_a2dp_source_cb.StateStr());
btif_a2dp_source_thread.DoInThread(
FROM_HERE, base::BindOnce(&btif_a2dp_source_audio_tx_flush_event));
@@ -1104,9 +1103,9 @@ BT_HDR* btif_a2dp_source_audio_readbuf(void) {
static void log_tstamps_us(const char* comment, uint64_t timestamp_us) {
static uint64_t prev_us = 0;
- LOG_VERBOSE("%s: [%s] ts %08" PRIu64 ", diff : %08" PRIu64 ", queue sz %zu",
- __func__, comment, timestamp_us, timestamp_us - prev_us,
- fixed_queue_length(btif_a2dp_source_cb.tx_audio_queue));
+ log::verbose("[{}] ts {:08}, diff : {:08}, queue sz {}", comment,
+ timestamp_us, timestamp_us - prev_us,
+ fixed_queue_length(btif_a2dp_source_cb.tx_audio_queue));
prev_us = timestamp_us;
}
@@ -1378,14 +1377,13 @@ void btif_a2dp_source_set_dynamic_audio_buffer_size(
static void btm_read_rssi_cb(void* data) {
if (data == nullptr) {
- LOG_ERROR("%s: Read RSSI request timed out", __func__);
+ log::error("Read RSSI request timed out");
return;
}
tBTM_RSSI_RESULT* result = (tBTM_RSSI_RESULT*)data;
if (result->status != BTM_SUCCESS) {
- LOG_ERROR("%s: unable to read remote RSSI (status %d)", __func__,
- result->status);
+ log::error("unable to read remote RSSI (status {})", result->status);
return;
}
@@ -1393,48 +1391,47 @@ static void btm_read_rssi_cb(void* data) {
bluetooth::common::kUnknownConnectionHandle,
result->hci_status, result->rssi);
- LOG_WARN("%s: device: %s, rssi: %d", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(result->rem_bda), result->rssi);
+ log::warn("device: {}, rssi: {}", ADDRESS_TO_LOGGABLE_CSTR(result->rem_bda),
+ result->rssi);
}
static void btm_read_failed_contact_counter_cb(void* data) {
if (data == nullptr) {
- LOG_ERROR("%s: Read Failed Contact Counter request timed out", __func__);
+ log::error("Read Failed Contact Counter request timed out");
return;
}
tBTM_FAILED_CONTACT_COUNTER_RESULT* result =
(tBTM_FAILED_CONTACT_COUNTER_RESULT*)data;
if (result->status != BTM_SUCCESS) {
- LOG_ERROR("%s: unable to read Failed Contact Counter (status %d)", __func__,
- result->status);
+ log::error("unable to read Failed Contact Counter (status {})",
+ result->status);
return;
}
log_read_failed_contact_counter_result(
result->rem_bda, bluetooth::common::kUnknownConnectionHandle,
result->hci_status, result->failed_contact_counter);
- LOG_WARN("%s: device: %s, Failed Contact Counter: %u", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(result->rem_bda),
- result->failed_contact_counter);
+ log::warn("device: {}, Failed Contact Counter: {}",
+ ADDRESS_TO_LOGGABLE_CSTR(result->rem_bda),
+ result->failed_contact_counter);
}
static void btm_read_tx_power_cb(void* data) {
if (data == nullptr) {
- LOG_ERROR("%s: Read Tx Power request timed out", __func__);
+ log::error("Read Tx Power request timed out");
return;
}
tBTM_TX_POWER_RESULT* result = (tBTM_TX_POWER_RESULT*)data;
if (result->status != BTM_SUCCESS) {
- LOG_ERROR("%s: unable to read Tx Power (status %d)", __func__,
- result->status);
+ log::error("unable to read Tx Power (status {})", result->status);
return;
}
log_read_tx_power_level_result(result->rem_bda,
bluetooth::common::kUnknownConnectionHandle,
result->hci_status, result->tx_power);
- LOG_WARN("%s: device: %s, Tx Power: %d", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(result->rem_bda), result->tx_power);
+ log::warn("device: {}, Tx Power: {}",
+ ADDRESS_TO_LOGGABLE_CSTR(result->rem_bda), result->tx_power);
}
diff --git a/system/btif/src/btif_av.cc b/system/btif/src/btif_av.cc
index 2ce600ef14..abb2246a46 100644
--- a/system/btif/src/btif_av.cc
+++ b/system/btif/src/btif_av.cc
@@ -23,8 +23,8 @@
#include <android_bluetooth_flags.h>
#include <android_bluetooth_sysprop.h>
#include <base/functional/bind.h>
-#include <base/logging.h>
#include <base/strings/stringprintf.h>
+#include <bluetooth/log.h>
#include <frameworks/proto_logging/stats/enums/bluetooth/a2dp/enums.pb.h>
#include <frameworks/proto_logging/stats/enums/bluetooth/enums.pb.h>
@@ -63,6 +63,8 @@
#include "stack/include/main_thread.h"
#include "types/raw_address.h"
+using namespace bluetooth;
+
/*****************************************************************************
* Constants & Macros
*****************************************************************************/
@@ -403,6 +405,7 @@ class BtifAvSource {
btav_source_callbacks_t* Callbacks() { return callbacks_; }
bool Enabled() const { return enabled_; }
bool A2dpOffloadEnabled() const { return a2dp_offload_enabled_; }
+ // TODO: b/321806163: Remove this method as part of flag cleanup
void SetInvalidPeerCheck(bool invalid_peer_check) {
invalid_peer_check_ = invalid_peer_check;
}
@@ -454,11 +457,11 @@ class BtifAvSource {
}
BtifAvPeer* peer = FindPeer(peer_address);
if (peer == nullptr) {
- LOG_WARN("%s: peer is null", __func__);
+ log::warn("peer is null");
return false;
}
if (!peer->IsConnected()) {
- LOG_WARN("%s: peer is not connected", __func__);
+ log::warn("peer is not connected");
return false;
}
return peer->IsInSilenceMode();
@@ -475,15 +478,14 @@ class BtifAvSource {
if (peer_address.IsEmpty()) {
return false;
}
- LOG_INFO("%s: peer: %s", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_address));
+ log::info("peer: {}", ADDRESS_TO_LOGGABLE_CSTR(peer_address));
BtifAvPeer* peer = FindPeer(peer_address);
if (peer == nullptr) {
- LOG_WARN("%s: peer is null", __func__);
+ log::warn("peer is null");
return false;
}
if (!peer->IsConnected()) {
- LOG_WARN("%s: peer is not connected", __func__);
+ log::warn("peer is not connected");
return false;
}
peer->SetSilence(silence);
@@ -499,22 +501,25 @@ class BtifAvSource {
*/
bool SetActivePeer(const RawAddress& peer_address,
std::promise<void> peer_ready_promise) {
- LOG(INFO) << __PRETTY_FUNCTION__ << ": peer: "
- << ADDRESS_TO_LOGGABLE_STR(peer_address);
+ log::info("peer: {}", ADDRESS_TO_LOGGABLE_STR(peer_address));
if (active_peer_ == peer_address) {
peer_ready_promise.set_value();
return true; // Nothing has changed
}
if (peer_address.IsEmpty()) {
- LOG_VERBOSE("%s: peer address is empty, shutdown the Audio source",
- __func__);
- if (!btif_av_src_sink_coexist_enabled() ||
- (btif_av_src_sink_coexist_enabled() &&
- btif_av_sink_active_peer().IsEmpty())) {
- if (!bta_av_co_set_active_peer(peer_address)) {
- LOG(WARNING) << __func__
- << ": unable to set active peer to empty in BtaAvCo";
+ log::verbose("peer address is empty, shutdown the Audio source");
+ if (IS_FLAG_ENABLED(a2dp_concurrent_source_sink)) {
+ if (!bta_av_co_set_active_source_peer(peer_address)) {
+ log::warn("unable to set active peer to empty in BtaAvCo");
+ }
+ } else {
+ if (!btif_av_src_sink_coexist_enabled() ||
+ (btif_av_src_sink_coexist_enabled() &&
+ btif_av_sink_active_peer().IsEmpty())) {
+ if (!bta_av_co_set_active_peer(peer_address)) {
+ log::warn("unable to set active peer to empty in BtaAvCo");
+ }
}
}
@@ -526,19 +531,21 @@ class BtifAvSource {
using namespace std::chrono_literals;
if (shutdown_complete_future.wait_for(1s) ==
std::future_status::timeout) {
- LOG_ERROR("Timed out waiting for A2DP source shutdown to complete.");
+ log::error("Timed out waiting for A2DP source shutdown to complete.");
}
active_peer_ = peer_address;
peer_ready_promise.set_value();
return true;
}
- if (btif_av_src_sink_coexist_enabled()) btif_av_sink_delete_active_peer();
+ if (!IS_FLAG_ENABLED(a2dp_concurrent_source_sink) &&
+ btif_av_src_sink_coexist_enabled()) {
+ btif_av_sink_delete_active_peer();
+ }
BtifAvPeer* peer = FindPeer(peer_address);
if (peer == nullptr || !peer->IsConnected()) {
- LOG(ERROR) << __func__ << ": Error setting "
- << ADDRESS_TO_LOGGABLE_STR(peer_address)
- << " as active Source peer";
+ log::error("Error setting {} as active Source peer",
+ ADDRESS_TO_LOGGABLE_STR(peer_address));
peer_ready_promise.set_value();
return false;
}
@@ -554,14 +561,19 @@ class BtifAvSource {
void DeleteActivePeer(void) {
std::promise<void> shutdown_complete_promise;
- LOG_VERBOSE("%s", __func__);
- if (btif_av_sink_active_peer().IsEmpty()) {
- if (!bta_av_co_set_active_peer(RawAddress::kEmpty)) {
- LOG_WARN("%s : unable to set active peer to empty in BtaAvCo",
- __func__);
+ log::verbose("");
+ if (IS_FLAG_ENABLED(a2dp_concurrent_source_sink)) {
+ if (!bta_av_co_set_active_source_peer(RawAddress::kEmpty)) {
+ log::warn("unable to set active peer to empty in BtaAvCo");
}
} else {
- LOG_WARN("%s : there is an active peer as source role", __func__);
+ if (btif_av_sink_active_peer().IsEmpty()) {
+ if (!bta_av_co_set_active_peer(RawAddress::kEmpty)) {
+ log::warn("unable to set active peer to empty in BtaAvCo");
+ }
+ } else {
+ log::warn("there is an active peer as source role");
+ }
}
btif_a2dp_source_end_session(active_peer_);
btif_a2dp_source_shutdown(std::move(shutdown_complete_promise));
@@ -632,6 +644,7 @@ class BtifAvSink {
btav_sink_callbacks_t* Callbacks() { return callbacks_; }
bool Enabled() const { return enabled_; }
+ // TODO: b/321806163: Remove this method as part of flag cleanup
void SetInvalidPeerCheck(bool invalid_peer_check) {
invalid_peer_check_ = invalid_peer_check;
}
@@ -680,22 +693,25 @@ class BtifAvSink {
*/
bool SetActivePeer(const RawAddress& peer_address,
std::promise<void> peer_ready_promise) {
- LOG(INFO) << __PRETTY_FUNCTION__ << ": peer: "
- << ADDRESS_TO_LOGGABLE_STR(peer_address);
+ log::info("peer: {}", ADDRESS_TO_LOGGABLE_STR(peer_address));
if (active_peer_ == peer_address) {
peer_ready_promise.set_value();
return true; // Nothing has changed
}
if (peer_address.IsEmpty()) {
- LOG_VERBOSE("%s: peer address is empty, shutdown the Audio sink",
- __func__);
- if (!btif_av_src_sink_coexist_enabled() ||
- (btif_av_src_sink_coexist_enabled() &&
- btif_av_source_active_peer().IsEmpty())) {
- if (!bta_av_co_set_active_peer(peer_address)) {
- LOG(WARNING) << __func__
- << ": unable to set active peer to empty in BtaAvCo";
+ log::verbose("peer address is empty, shutdown the Audio sink");
+ if (IS_FLAG_ENABLED(a2dp_concurrent_source_sink)) {
+ if (!bta_av_co_set_active_sink_peer(peer_address)) {
+ log::warn("unable to set active peer to empty in BtaAvCo");
+ }
+ } else {
+ if (!btif_av_src_sink_coexist_enabled() ||
+ (btif_av_src_sink_coexist_enabled() &&
+ btif_av_source_active_peer().IsEmpty())) {
+ if (!bta_av_co_set_active_peer(peer_address)) {
+ log::warn("unable to set active peer to empty in BtaAvCo");
+ }
}
}
@@ -706,14 +722,14 @@ class BtifAvSink {
return true;
}
- if (btif_av_src_sink_coexist_enabled()) {
+ if (!IS_FLAG_ENABLED(a2dp_concurrent_source_sink) &&
+ btif_av_src_sink_coexist_enabled()) {
btif_av_source_delete_active_peer();
}
BtifAvPeer* peer = FindPeer(peer_address);
if (peer == nullptr || !peer->IsConnected()) {
- LOG(ERROR) << __func__ << ": Error setting "
- << ADDRESS_TO_LOGGABLE_STR(peer_address)
- << " as active Sink peer";
+ log::error("Error setting {} as active Sink peer",
+ ADDRESS_TO_LOGGABLE_STR(peer_address));
peer_ready_promise.set_value();
return false;
}
@@ -723,21 +739,26 @@ class BtifAvSink {
// cannot set promise but need to be handled within restart_session
return false;
}
- LOG(INFO) << "Setting the active peer to peer address %s"
- << ADDRESS_TO_LOGGABLE_STR(peer_address);
+ log::info("Setting the active peer to peer address {}",
+ ADDRESS_TO_LOGGABLE_STR(peer_address));
active_peer_ = peer_address;
return true;
}
void DeleteActivePeer(void) {
- LOG_VERBOSE("%s", __func__);
- if (btif_av_source_active_peer().IsEmpty()) {
- if (!bta_av_co_set_active_peer(RawAddress::kEmpty)) {
- LOG(WARNING) << __func__
- << ": unable to set active peer to empty in BtaAvCo";
+ log::verbose("");
+ if (IS_FLAG_ENABLED(a2dp_concurrent_source_sink)) {
+ if (!bta_av_co_set_active_sink_peer(RawAddress::kEmpty)) {
+ log::warn("unable to set active peer to empty in BtaAvCo");
}
} else {
- LOG(WARNING) << __func__ << ": there is an active peer as sink role";
+ if (btif_av_source_active_peer().IsEmpty()) {
+ if (!bta_av_co_set_active_peer(RawAddress::kEmpty)) {
+ log::warn("unable to set active peer to empty in BtaAvCo");
+ }
+ } else {
+ log::warn("there is an active peer as sink role");
+ }
}
btif_a2dp_sink_end_session(active_peer_);
btif_a2dp_sink_shutdown();
@@ -798,9 +819,11 @@ static void btif_av_handle_event(uint8_t peer_sep,
static void btif_report_connection_state(const RawAddress& peer_address,
btav_connection_state_t state,
const bt_status_t status,
- uint8_t error_code);
+ uint8_t error_code,
+ const A2dpType local_a2dp_type);
static void btif_report_audio_state(const RawAddress& peer_address,
- btav_audio_state_t state);
+ btav_audio_state_t state,
+ const A2dpType local_a2dp_type);
static void btif_av_report_sink_audio_config_state(
const RawAddress& peer_address, int sample_rate, int channel_count);
static void btif_av_query_mandatory_codec_priority(
@@ -811,7 +834,8 @@ static void bta_av_sink_media_callback(const RawAddress& peer_address,
tBTA_AV_EVT event,
tBTA_AV_MEDIA* p_data);
extern bool btif_av_both_enable(void);
-extern bool btif_av_is_connected_addr(const RawAddress& peer_address);
+extern bool btif_av_is_connected_addr(const RawAddress& peer_address,
+ const A2dpType local_a2dp_type);
extern bool btif_av_peer_is_sink(const RawAddress& peer_address);
extern void btif_rc_check_pending_cmd(const RawAddress& peer_address);
extern void btif_rc_get_addr_by_handle(uint8_t handle, RawAddress& rc_addr);
@@ -822,7 +846,37 @@ static BtifAvPeer* btif_av_source_find_peer(const RawAddress& peer_address) {
static BtifAvPeer* btif_av_sink_find_peer(const RawAddress& peer_address) {
return btif_av_sink.FindPeer(peer_address);
}
-static BtifAvPeer* btif_av_find_peer(const RawAddress& peer_address) {
+static BtifAvPeer* btif_av_find_peer(const RawAddress& peer_address,
+ const A2dpType local_a2dp_type) {
+ if (IS_FLAG_ENABLED(a2dp_concurrent_source_sink)) {
+ if (btif_av_source.Enabled() && local_a2dp_type == A2dpType::kSource) {
+ BtifAvPeer* sourcePeer = btif_av_source_find_peer(peer_address);
+ if (sourcePeer != nullptr) {
+ return sourcePeer;
+ }
+ }
+ if (btif_av_sink.Enabled() && local_a2dp_type == A2dpType::kSink) {
+ BtifAvPeer* sinkPeer = btif_av_sink_find_peer(peer_address);
+ if (sinkPeer != nullptr) {
+ return sinkPeer;
+ }
+ }
+ if (btif_av_source.Enabled()) {
+ BtifAvPeer* sourcePeer = btif_av_source_find_peer(peer_address);
+ if (sourcePeer != nullptr) {
+ return sourcePeer;
+ }
+ }
+ if (btif_av_sink.Enabled()) {
+ BtifAvPeer* sinkPeer = btif_av_sink_find_peer(peer_address);
+ if (sinkPeer != nullptr) {
+ return sinkPeer;
+ }
+ }
+ log::info("Unable to find the peer {}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_address));
+ return nullptr;
+ }
if (btif_av_src_sink_coexist_enabled() && btif_av_both_enable()) {
BtifAvPeer* peer = nullptr;
peer = btif_av_source_find_peer(peer_address);
@@ -835,7 +889,15 @@ static BtifAvPeer* btif_av_find_peer(const RawAddress& peer_address) {
if (btif_av_sink.Enabled()) return btif_av_sink_find_peer(peer_address);
return nullptr;
}
-static BtifAvPeer* btif_av_find_active_peer() {
+static BtifAvPeer* btif_av_find_active_peer(const A2dpType local_a2dp_type) {
+ if (IS_FLAG_ENABLED(a2dp_concurrent_source_sink)) {
+ if (btif_av_source.Enabled() && local_a2dp_type == A2dpType::kSource)
+ return btif_av_source_find_peer(btif_av_source.ActivePeer());
+ if (btif_av_sink.Enabled() && local_a2dp_type == A2dpType::kSink)
+ return btif_av_sink_find_peer(btif_av_sink.ActivePeer());
+ return nullptr;
+ }
+
if (btif_av_src_sink_coexist_enabled() && btif_av_both_enable()) {
BtifAvPeer* peer = nullptr;
peer = btif_av_source_find_peer(btif_av_source.ActivePeer());
@@ -1089,6 +1151,19 @@ bool BtifAvPeer::CanBeDeleted() const {
}
const RawAddress& BtifAvPeer::ActivePeerAddress() const {
+ if (!IS_FLAG_ENABLED(a2dp_concurrent_source_sink)) {
+ if (btif_av_src_sink_coexist_enabled() && btif_av_both_enable()) {
+ RawAddress addr = btif_av_sink.ActivePeer();
+ if (RawAddress::kEmpty == addr) {
+ log::warn("A2DP peer {} is Sink",
+ ADDRESS_TO_LOGGABLE_STR(btif_av_source.ActivePeer()));
+ return btif_av_source.ActivePeer();
+ }
+ log::warn("A2DP peer {} is Source",
+ ADDRESS_TO_LOGGABLE_STR(btif_av_sink.ActivePeer()));
+ return btif_av_sink.ActivePeer();
+ }
+ }
if (IsSource()) {
return btif_av_sink.ActivePeer();
}
@@ -1096,20 +1171,8 @@ const RawAddress& BtifAvPeer::ActivePeerAddress() const {
return btif_av_source.ActivePeer();
}
- if (btif_av_src_sink_coexist_enabled() && btif_av_both_enable()) {
- RawAddress addr = btif_av_sink.ActivePeer();
- if (RawAddress::kEmpty == addr) {
- LOG(WARNING) << __PRETTY_FUNCTION__ << ": A2DP peer "
- << btif_av_source.ActivePeer() << " is Sink";
- return btif_av_source.ActivePeer();
- }
- LOG(WARNING) << __PRETTY_FUNCTION__ << ": A2DP peer "
- << btif_av_sink.ActivePeer() << " is Source";
- return btif_av_sink.ActivePeer();
- }
- LOG(FATAL) << __PRETTY_FUNCTION__ << ": A2DP peer "
- << ADDRESS_TO_LOGGABLE_STR(PeerAddress())
- << " is neither Source nor Sink";
+ log::fatal("A2DP peer {} is neither Source nor Sink",
+ ADDRESS_TO_LOGGABLE_STR(PeerAddress()));
return RawAddress::kEmpty;
}
@@ -1131,8 +1194,7 @@ bt_status_t BtifAvSource::Init(
const std::vector<btav_a2dp_codec_config_t>& codec_priorities,
const std::vector<btav_a2dp_codec_config_t>& offloading_preference,
std::vector<btav_a2dp_codec_info_t>* supported_codecs) {
- LOG_INFO("%s: max_connected_audio_devices=%d", __PRETTY_FUNCTION__,
- max_connected_audio_devices);
+ log::info("max_connected_audio_devices={}", max_connected_audio_devices);
if (enabled_) return BT_STATUS_SUCCESS;
CleanupAllPeers();
max_connected_peers_ = max_connected_audio_devices;
@@ -1140,7 +1202,7 @@ bt_status_t BtifAvSource::Init(
/* A2DP OFFLOAD */
a2dp_offload_enabled_ =
GetInterfaceToProfiles()->config->isA2DPOffloadEnabled();
- LOG_VERBOSE("a2dp_offload.enable = %d", a2dp_offload_enabled_);
+ log::verbose("a2dp_offload.enable = {}", a2dp_offload_enabled_);
callbacks_ = callbacks;
if (a2dp_offload_enabled_) {
@@ -1162,7 +1224,7 @@ bt_status_t BtifAvSource::Init(
}
void BtifAvSource::Cleanup() {
- LOG_INFO("%s", __PRETTY_FUNCTION__);
+ log::info("");
if (!enabled_) return;
enabled_ = false;
@@ -1211,8 +1273,8 @@ BtifAvPeer* BtifAvSource::FindPeerByPeerId(uint8_t peer_id) {
BtifAvPeer* BtifAvSource::FindOrCreatePeer(const RawAddress& peer_address,
tBTA_AV_HNDL bta_handle) {
std::unique_lock<std::mutex> lock1(mutex_);
- LOG_VERBOSE("%s: peer_address=%s bta_handle=0x%x", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_address), bta_handle);
+ log::verbose("peer_address={} bta_handle=0x{:x}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_address), bta_handle);
BtifAvPeer* peer = FindPeer(peer_address);
if (peer != nullptr) return peer;
@@ -1230,10 +1292,10 @@ BtifAvPeer* BtifAvSource::FindOrCreatePeer(const RawAddress& peer_address,
}
}
if (peer_id == kPeerIdMax) {
- LOG_ERROR(
- "%s: Cannot create peer for peer_address=%s : "
- "cannot allocate unique Peer ID",
- __PRETTY_FUNCTION__, ADDRESS_TO_LOGGABLE_CSTR(peer_address));
+ log::error(
+ "Cannot create peer for peer_address={} : cannot allocate unique Peer "
+ "ID",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_address));
return nullptr;
}
@@ -1241,18 +1303,17 @@ BtifAvPeer* BtifAvSource::FindOrCreatePeer(const RawAddress& peer_address,
if (bta_handle == kBtaHandleUnknown) {
auto it = peer_id2bta_handle_.find(peer_id);
if (it == peer_id2bta_handle_.end() || it->second == kBtaHandleUnknown) {
- LOG_ERROR(
- "%s: Cannot create peer for peer_address=%s : "
- "cannot convert Peer ID=%d to unique BTA Handle",
- __PRETTY_FUNCTION__, ADDRESS_TO_LOGGABLE_CSTR(peer_address), peer_id);
+ log::error(
+ "Cannot create peer for peer_address={} : cannot convert Peer ID={} "
+ "to unique BTA Handle",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_address), peer_id);
return nullptr;
}
bta_handle = it->second;
}
- LOG_INFO("%s: Create peer: peer_address=%s bta_handle=0x%x peer_id=%d",
- __PRETTY_FUNCTION__, ADDRESS_TO_LOGGABLE_CSTR(peer_address),
- bta_handle, peer_id);
+ log::info("Create peer: peer_address={} bta_handle=0x{:x} peer_id={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_address), bta_handle, peer_id);
peer = new BtifAvPeer(peer_address, AVDT_TSEP_SNK, bta_handle, peer_id);
peers_.insert(std::make_pair(peer_address, peer));
peer->Init();
@@ -1261,10 +1322,12 @@ BtifAvPeer* BtifAvSource::FindOrCreatePeer(const RawAddress& peer_address,
bool BtifAvSource::AllowedToConnect(const RawAddress& peer_address) const {
int connected = 0;
- if (btif_av_src_sink_coexist_enabled() && invalid_peer_check_) {
- LOG_INFO(
- "invalid_peer_check_ so allow to connect here, when"
- " BTA_AV_OPEN_EVT coming, would check again!");
+
+ if (!IS_FLAG_ENABLED(a2dp_concurrent_source_sink) &&
+ btif_av_src_sink_coexist_enabled() && invalid_peer_check_) {
+ log::info(
+ "invalid_peer_check_ so allow to connect here, when BTA_AV_OPEN_EVT "
+ "coming, would check again!");
return true;
}
@@ -1277,8 +1340,10 @@ bool BtifAvSource::AllowedToConnect(const RawAddress& peer_address) const {
case BtifAvStateMachine::kStateStarted:
if (peer->PeerAddress() == peer_address) {
/* we should check if another role is used */
- if (btif_av_src_sink_coexist_enabled() && btif_av_both_enable())
+ if (!IS_FLAG_ENABLED(a2dp_concurrent_source_sink) &&
+ btif_av_src_sink_coexist_enabled() && btif_av_both_enable()) {
break;
+ }
return true; // Already connected or accounted for
}
@@ -1288,10 +1353,10 @@ bool BtifAvSource::AllowedToConnect(const RawAddress& peer_address) const {
break;
}
}
- if (btif_av_src_sink_coexist_enabled() && btif_av_both_enable()) {
- LOG_INFO("%s: connected=%d, max_connected_peers_=%d, sink_peers=%d",
- __PRETTY_FUNCTION__, connected, max_connected_peers_,
- (int)btif_av_sink.Peers().size());
+ if (!IS_FLAG_ENABLED(a2dp_concurrent_source_sink) &&
+ btif_av_src_sink_coexist_enabled() && btif_av_both_enable()) {
+ log::info("connected={}, max_connected_peers_={}, sink_peers={}", connected,
+ max_connected_peers_, (int)btif_av_sink.Peers().size());
/* if source device connected, don't connect sink device */
if (connected >= max_connected_peers_ || !btif_av_sink.Peers().empty()) {
@@ -1318,8 +1383,8 @@ void BtifAvSource::DeleteIdlePeers() {
BtifAvPeer* peer = it->second;
auto prev_it = it++;
if (!peer->CanBeDeleted()) continue;
- LOG_INFO("%s: Deleting idle peer: %s bta_handle=0x%x", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), peer->BtaHandle());
+ log::info("Deleting idle peer: {} bta_handle=0x{:x}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), peer->BtaHandle());
peer->Cleanup();
peers_.erase(prev_it);
delete peer;
@@ -1359,15 +1424,14 @@ void BtifAvSource::BtaHandleRegistered(uint8_t peer_id,
BtifAvPeer* peer = FindPeerByPeerId(peer_id);
if (peer != nullptr && peer->BtaHandle() != bta_handle) {
if (peer->BtaHandle() == kBtaHandleUnknown) {
- LOG_VERBOSE("%s: Assign peer: peer_address=%s bta_handle=0x%x peer_id=%d",
- __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), bta_handle,
- peer_id);
+ log::verbose("Assign peer: peer_address={} bta_handle=0x{:x} peer_id={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), bta_handle,
+ peer_id);
} else {
- LOG_WARN(
- "%s: Correct peer: peer_address=%s bta_handle=0x%x->0x%x peer_id=%d",
- __PRETTY_FUNCTION__, ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()),
- peer->BtaHandle(), bta_handle, peer_id);
+ log::warn(
+ "Correct peer: peer_address={} bta_handle=0x{:x}->0x{:x} peer_id={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), peer->BtaHandle(),
+ bta_handle, peer_id);
}
peer->SetBtaHandle(bta_handle);
}
@@ -1378,24 +1442,23 @@ BtifAvPeer* BtifAvSource::popPeer(const RawAddress& peer_address) {
if (it == peers_.end()) return nullptr;
BtifAvPeer* peer = it->second;
peers_.erase(it);
- LOG_INFO("%s: peer_address=%s, state=%d", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()),
- peer->StateMachine().StateId());
+ log::info("peer_address={}, state={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()),
+ peer->StateMachine().StateId());
return peer;
}
void BtifAvSource::AddPeer(BtifAvPeer* peer) {
- LOG_INFO("%s: peer_address=%s, state=%d", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()),
- peer->StateMachine().StateId());
+ log::info("peer_address={}, state={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()),
+ peer->StateMachine().StateId());
peers_.insert(std::make_pair(peer->PeerAddress(), peer));
}
BtifAvSink::~BtifAvSink() { CleanupAllPeers(); }
bt_status_t BtifAvSink::Init(btav_sink_callbacks_t* callbacks,
int max_connected_audio_devices) {
- LOG_INFO("%s(max_connected_audio_devices=%d)", __PRETTY_FUNCTION__,
- max_connected_audio_devices);
+ log::info("(max_connected_audio_devices={})", max_connected_audio_devices);
if (enabled_) return BT_STATUS_SUCCESS;
CleanupAllPeers();
@@ -1420,7 +1483,7 @@ bt_status_t BtifAvSink::Init(btav_sink_callbacks_t* callbacks,
}
void BtifAvSink::Cleanup() {
- LOG_INFO("%s", __PRETTY_FUNCTION__);
+ log::info("");
if (!enabled_) return;
enabled_ = false;
@@ -1468,8 +1531,8 @@ BtifAvPeer* BtifAvSink::FindPeerByPeerId(uint8_t peer_id) {
BtifAvPeer* BtifAvSink::FindOrCreatePeer(const RawAddress& peer_address,
tBTA_AV_HNDL bta_handle) {
- LOG_VERBOSE("%s: peer_address=%s bta_handle=0x%x", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_address), bta_handle);
+ log::verbose("peer_address={} bta_handle=0x{:x}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_address), bta_handle);
BtifAvPeer* peer = FindPeer(peer_address);
if (peer != nullptr) return peer;
@@ -1488,10 +1551,10 @@ BtifAvPeer* BtifAvSink::FindOrCreatePeer(const RawAddress& peer_address,
}
}
if (peer_id == kPeerIdMax) {
- LOG_ERROR(
- "%s: Cannot create peer for peer_address=%s : "
- "cannot allocate unique Peer ID",
- __PRETTY_FUNCTION__, ADDRESS_TO_LOGGABLE_CSTR(peer_address));
+ log::error(
+ "Cannot create peer for peer_address={} : cannot allocate unique Peer "
+ "ID",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_address));
return nullptr;
}
@@ -1499,18 +1562,17 @@ BtifAvPeer* BtifAvSink::FindOrCreatePeer(const RawAddress& peer_address,
if (bta_handle == kBtaHandleUnknown) {
auto it = peer_id2bta_handle_.find(peer_id);
if (it == peer_id2bta_handle_.end() || it->second == kBtaHandleUnknown) {
- LOG_ERROR(
- "%s: Cannot create peer for peer_address=%s : "
- "cannot convert Peer ID=%d to unique BTA Handle",
- __PRETTY_FUNCTION__, ADDRESS_TO_LOGGABLE_CSTR(peer_address), peer_id);
+ log::error(
+ "Cannot create peer for peer_address={} : cannot convert Peer ID={} "
+ "to unique BTA Handle",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_address), peer_id);
return nullptr;
}
bta_handle = it->second;
}
- LOG_INFO("%s: Create peer: peer_address=%s bta_handle=0x%x peer_id=%d",
- __PRETTY_FUNCTION__, ADDRESS_TO_LOGGABLE_CSTR(peer_address),
- bta_handle, peer_id);
+ log::info("Create peer: peer_address={} bta_handle=0x{:x} peer_id={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_address), bta_handle, peer_id);
peer = new BtifAvPeer(peer_address, AVDT_TSEP_SRC, bta_handle, peer_id);
peers_.insert(std::make_pair(peer_address, peer));
peer->Init();
@@ -1520,10 +1582,11 @@ BtifAvPeer* BtifAvSink::FindOrCreatePeer(const RawAddress& peer_address,
bool BtifAvSink::AllowedToConnect(const RawAddress& peer_address) const {
int connected = 0;
- if (btif_av_src_sink_coexist_enabled() && invalid_peer_check_) {
- LOG_INFO(
- "invalid_peer_check_ so allow to connect here, when"
- " BTA_AV_OPEN_EVT coming, would check again!");
+ if (!IS_FLAG_ENABLED(a2dp_concurrent_source_sink) &&
+ btif_av_src_sink_coexist_enabled() && invalid_peer_check_) {
+ log::info(
+ "invalid_peer_check_ so allow to connect here, when BTA_AV_OPEN_EVT "
+ "coming, would check again!");
return true;
}
// Count peers that are in the process of connecting or already connected
@@ -1534,8 +1597,10 @@ bool BtifAvSink::AllowedToConnect(const RawAddress& peer_address) const {
case BtifAvStateMachine::kStateOpened:
case BtifAvStateMachine::kStateStarted:
if (peer->PeerAddress() == peer_address) {
- /* we should check if another role is used */
- if (btif_av_both_enable()) break;
+ if (!IS_FLAG_ENABLED(a2dp_concurrent_source_sink)) {
+ /* we should check if another role is used */
+ if (btif_av_both_enable()) break;
+ }
return true; // Already connected or accounted for
}
connected++;
@@ -1544,10 +1609,11 @@ bool BtifAvSink::AllowedToConnect(const RawAddress& peer_address) const {
case BtifAvStateMachine::kStateIdle:
if ((btif_a2dp_sink_get_audio_track() != nullptr) &&
(peer->PeerAddress() != peer_address)) {
- LOG_INFO("%s: there is another peer with audio track(%p), another=%s, peer=%s",
- __PRETTY_FUNCTION__, btif_a2dp_sink_get_audio_track(),
- ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()),
- ADDRESS_TO_LOGGABLE_CSTR(peer_address));
+ log::info(
+ "there is another peer with audio track({}), another={}, peer={}",
+ fmt::ptr(btif_a2dp_sink_get_audio_track()),
+ ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()),
+ ADDRESS_TO_LOGGABLE_CSTR(peer_address));
connected++;
}
break;
@@ -1555,10 +1621,10 @@ bool BtifAvSink::AllowedToConnect(const RawAddress& peer_address) const {
break;
}
}
- if (btif_av_both_enable()) {
- LOG_INFO("connected=%d, max_connected_peers_=%d, source_peers=%d",
- connected, max_connected_peers_,
- (int)btif_av_source.Peers().size());
+ if (!IS_FLAG_ENABLED(a2dp_concurrent_source_sink) && btif_av_both_enable()) {
+ log::info("connected={}, max_connected_peers_={}, source_peers={}",
+ connected, max_connected_peers_,
+ (int)btif_av_source.Peers().size());
/* if source device connected, don't connect sink device */
return (connected < max_connected_peers_) && btif_av_source.Peers().empty();
}
@@ -1581,8 +1647,8 @@ void BtifAvSink::DeleteIdlePeers() {
BtifAvPeer* peer = it->second;
auto prev_it = it++;
if (!peer->CanBeDeleted()) continue;
- LOG_INFO("%s: Deleting idle peer: %s bta_handle=0x%x", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), peer->BtaHandle());
+ log::info("Deleting idle peer: {} bta_handle=0x{:x}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), peer->BtaHandle());
peer->Cleanup();
peers_.erase(prev_it);
delete peer;
@@ -1621,15 +1687,14 @@ void BtifAvSink::BtaHandleRegistered(uint8_t peer_id, tBTA_AV_HNDL bta_handle) {
BtifAvPeer* peer = FindPeerByPeerId(peer_id);
if (peer != nullptr && peer->BtaHandle() != bta_handle) {
if (peer->BtaHandle() == kBtaHandleUnknown) {
- LOG_VERBOSE("%s: Assign peer: peer_address=%s bta_handle=0x%x peer_id=%d",
- __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), bta_handle,
- peer_id);
+ log::verbose("Assign peer: peer_address={} bta_handle=0x{:x} peer_id={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), bta_handle,
+ peer_id);
} else {
- LOG_WARN(
- "%s: Correct peer: peer_address=%s bta_handle=0x%x->0x%x peer_id=%d",
- __PRETTY_FUNCTION__, ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()),
- peer->BtaHandle(), bta_handle, peer_id);
+ log::warn(
+ "Correct peer: peer_address={} bta_handle=0x{:x}->0x{:x} peer_id={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), peer->BtaHandle(),
+ bta_handle, peer_id);
}
peer->SetBtaHandle(bta_handle);
}
@@ -1640,29 +1705,29 @@ BtifAvPeer* BtifAvSink::popPeer(const RawAddress& peer_address) {
if (it == peers_.end()) return nullptr;
BtifAvPeer* peer = it->second;
peers_.erase(it);
- LOG_INFO("%s: peer_address=%s, state=%d", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()),
- peer->StateMachine().StateId());
+ log::info("peer_address={}, state={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()),
+ peer->StateMachine().StateId());
return peer;
}
void BtifAvSink::AddPeer(BtifAvPeer* peer) {
- LOG_INFO("%s: peer_address=%s, state=%d", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()),
- peer->StateMachine().StateId());
+ log::info("peer_address={}, state={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()),
+ peer->StateMachine().StateId());
peers_.insert(std::make_pair(peer->PeerAddress(), peer));
}
void BtifAvStateMachine::StateIdle::OnEnter() {
- LOG_VERBOSE("%s: Peer %s", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
+ log::verbose("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
peer_.SetEdr(0);
peer_.ClearAllFlags();
// Stop A2DP if this is the active peer
if (peer_.IsActivePeer() || peer_.ActivePeerAddress().IsEmpty()) {
- btif_a2dp_on_idle(peer_.PeerAddress());
+ btif_a2dp_on_idle(peer_.PeerAddress(),
+ peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
}
// Reset the active peer if this was the active peer and
@@ -1691,16 +1756,14 @@ void BtifAvStateMachine::StateIdle::OnEnter() {
}
void BtifAvStateMachine::StateIdle::OnExit() {
- LOG_VERBOSE("%s: Peer %s", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
+ log::verbose("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
}
bool BtifAvStateMachine::StateIdle::ProcessEvent(uint32_t event, void* p_data) {
- LOG_VERBOSE(
- "%s: Peer %s : event=%s flags=%s active_peer=%s", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str(), peer_.FlagsToString().c_str(),
- logbool(peer_.IsActivePeer()).c_str());
+ log::verbose("Peer {} : event={} flags={} active_peer={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event), peer_.FlagsToString(),
+ logbool(peer_.IsActivePeer()));
switch (event) {
case BTA_AV_ENABLE_EVT:
@@ -1737,10 +1800,8 @@ bool BtifAvStateMachine::StateIdle::ProcessEvent(uint32_t event, void* p_data) {
if (!can_connect) sink_disconnect_src(peer_.PeerAddress());
}
if (!can_connect) {
- LOG_ERROR(
- "%s: Cannot connect to peer %s: too many connected "
- "peers",
- __PRETTY_FUNCTION__, ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
+ log::error("Cannot connect to peer {}: too many connected peers",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
if (peer_.SelfInitiatedConnection()) {
btif_queue_advance();
}
@@ -1774,16 +1835,17 @@ bool BtifAvStateMachine::StateIdle::ProcessEvent(uint32_t event, void* p_data) {
// connection first and then immediately initiate the AV connection
//
// TODO: We may need to do this only on an AVRCP Play. FixMe
- LOG_WARN("%s: Peer %s : event=%s received without AV",
- __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str());
+ log::warn("Peer {} : event={} received without AV",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event));
bool can_connect = true;
// Check whether connection is allowed
if (peer_.IsSink()) {
can_connect = btif_av_source.AllowedToConnect(peer_.PeerAddress());
if (!can_connect) {
+ log::error("Source profile doesn't allow connection to peer:{}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
if (btif_av_src_sink_coexist_enabled())
BTA_AvCloseRc(((tBTA_AV*)p_data)->rc_open.rc_handle);
else
@@ -1792,6 +1854,8 @@ bool BtifAvStateMachine::StateIdle::ProcessEvent(uint32_t event, void* p_data) {
} else if (peer_.IsSource()) {
can_connect = btif_av_sink.AllowedToConnect(peer_.PeerAddress());
if (!can_connect) {
+ log::error("Sink profile doesn't allow connection to peer:{}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
if (btif_av_src_sink_coexist_enabled())
BTA_AvCloseRc(((tBTA_AV*)p_data)->rc_open.rc_handle);
else
@@ -1799,10 +1863,8 @@ bool BtifAvStateMachine::StateIdle::ProcessEvent(uint32_t event, void* p_data) {
}
}
if (!can_connect) {
- LOG_ERROR(
- "%s: Cannot connect to peer %s: too many connected "
- "peers",
- __PRETTY_FUNCTION__, ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
+ log::error("Cannot connect to peer {}: too many connected peers",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
break;
}
/* if peer is source, then start timer for sink connect to src */
@@ -1852,30 +1914,32 @@ bool BtifAvStateMachine::StateIdle::ProcessEvent(uint32_t event, void* p_data) {
tBTA_AV_STATUS status = p_bta_data->open.status;
bool can_connect = true;
- LOG_INFO(
- "%s: Peer %s : event=%s flags=%s status=%d(%s) edr=0x%x",
- __PRETTY_FUNCTION__, ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str(), peer_.FlagsToString().c_str(),
- status, (status == BTA_AV_SUCCESS) ? "SUCCESS" : "FAILED",
- p_bta_data->open.edr);
+ log::info("Peer {} : event={} flags={} status={}({}) edr=0x{:x}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event), peer_.FlagsToString(), status,
+ (status == BTA_AV_SUCCESS) ? "SUCCESS" : "FAILED",
+ p_bta_data->open.edr);
btif_report_connection_state(
peer_.PeerAddress(), BTAV_CONNECTION_STATE_CONNECTING,
- bt_status_t::BT_STATUS_SUCCESS, BTA_AV_SUCCESS);
+ bt_status_t::BT_STATUS_SUCCESS, BTA_AV_SUCCESS,
+ peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
if (p_bta_data->open.status == BTA_AV_SUCCESS) {
peer_.SetEdr(p_bta_data->open.edr);
if (btif_av_src_sink_coexist_enabled()) {
- LOG_VERBOSE("%s: Peer %s sep=%d, open_sep=%d", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- peer_.PeerSep(), p_bta_data->open.sep);
+ log::verbose("Peer {} sep={}, open_sep={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ peer_.PeerSep(), p_bta_data->open.sep);
/* if peer is wrong sep type, move it to BtifAvSxxx */
- if (peer_.PeerSep() == AVDT_TSEP_SNK) {
- LOG_VERBOSE("set source invalid_peer_check as false");
- btif_av_source.SetInvalidPeerCheck(false);
- } else {
- LOG_VERBOSE("set sink invalid_peer_check as false");
- btif_av_sink.SetInvalidPeerCheck(false);
+ if (!IS_FLAG_ENABLED(a2dp_concurrent_source_sink)) {
+ if (peer_.PeerSep() == AVDT_TSEP_SNK) {
+ log::verbose("set source invalid_peer_check as false");
+ btif_av_source.SetInvalidPeerCheck(false);
+ } else {
+ log::verbose("set sink invalid_peer_check as false");
+ btif_av_sink.SetInvalidPeerCheck(false);
+ }
}
if (peer_.PeerSep() != p_bta_data->open.sep) {
BtifAvPeer* tmp_peer = nullptr;
@@ -1883,21 +1947,21 @@ bool BtifAvStateMachine::StateIdle::ProcessEvent(uint32_t event, void* p_data) {
tmp_peer = btif_av_source.popPeer(peer_.PeerAddress());
if (peer_.PeerAddress() != tmp_peer->PeerAddress())
- LOG_ERROR("error, not same peer");
+ log::error("error, not same peer");
btif_av_sink.AddPeer(tmp_peer);
} else {
tmp_peer = btif_av_sink.popPeer(peer_.PeerAddress());
if (peer_.PeerAddress() != tmp_peer->PeerAddress())
- LOG_ERROR("error, not same peer");
+ log::error("error, not same peer");
btif_av_source.AddPeer(tmp_peer);
}
peer_.SetSep(p_bta_data->open.sep);
}
if (btif_rc_is_connected_peer(peer_.PeerAddress())) {
- LOG_VERBOSE("%s, AVRCP connected, update avrc sep", __func__);
+ log::verbose("AVRCP connected, update avrc sep");
BTA_AvSetPeerSep(peer_.PeerAddress(), peer_.PeerSep());
}
btif_rc_check_pending_cmd(p_bta_data->open.bd_addr);
@@ -1909,11 +1973,8 @@ bool BtifAvStateMachine::StateIdle::ProcessEvent(uint32_t event, void* p_data) {
: btif_av_sink.AllowedToConnect(peer_.PeerAddress());
if (!can_connect) {
- LOG_ERROR(
- "%s: Cannot connect to peer %s: too many connected "
- "peers",
- __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
+ log::error("Cannot connect to peer {}: too many connected peers",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
if (peer_.IsSink()) {
src_disconnect_sink(peer_.PeerAddress());
@@ -1923,7 +1984,8 @@ bool BtifAvStateMachine::StateIdle::ProcessEvent(uint32_t event, void* p_data) {
btif_report_connection_state(
peer_.PeerAddress(), BTAV_CONNECTION_STATE_DISCONNECTED,
- bt_status_t::BT_STATUS_NOMEM, BTA_AV_FAIL_RESOURCES);
+ bt_status_t::BT_STATUS_NOMEM, BTA_AV_FAIL_RESOURCES,
+ peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
peer_.StateMachine().TransitionTo(BtifAvStateMachine::kStateIdle);
} else {
if (peer_.IsSink()) {
@@ -1938,13 +2000,15 @@ bool BtifAvStateMachine::StateIdle::ProcessEvent(uint32_t event, void* p_data) {
}
btif_report_connection_state(
peer_.PeerAddress(), BTAV_CONNECTION_STATE_CONNECTED,
- bt_status_t::BT_STATUS_SUCCESS, BTA_AV_SUCCESS);
+ bt_status_t::BT_STATUS_SUCCESS, BTA_AV_SUCCESS,
+ peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
peer_.StateMachine().TransitionTo(BtifAvStateMachine::kStateOpened);
}
} else {
- btif_report_connection_state(peer_.PeerAddress(),
- BTAV_CONNECTION_STATE_DISCONNECTED,
- bt_status_t::BT_STATUS_FAIL, status);
+ btif_report_connection_state(
+ peer_.PeerAddress(), BTAV_CONNECTION_STATE_DISCONNECTED,
+ bt_status_t::BT_STATUS_FAIL, status,
+ peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
peer_.StateMachine().TransitionTo(BtifAvStateMachine::kStateIdle);
DEVICE_IOT_CONFIG_ADDR_INT_ADD_ONE(peer_.PeerAddress(),
IOT_CONF_KEY_A2DP_CONN_FAIL_COUNT);
@@ -1963,10 +2027,9 @@ bool BtifAvStateMachine::StateIdle::ProcessEvent(uint32_t event, void* p_data) {
case BTIF_AV_AVRCP_CLOSE_EVT:
case BTA_AV_RC_CLOSE_EVT: {
- LOG_VERBOSE("%s: Peer %s : event=%s : Stopping AV timer",
- __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str());
+ log::verbose("Peer {} : event={} : Stopping AV timer",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event));
alarm_cancel(peer_.AvOpenOnRcTimer());
if (event == BTA_AV_RC_CLOSE_EVT) {
@@ -1975,17 +2038,16 @@ bool BtifAvStateMachine::StateIdle::ProcessEvent(uint32_t event, void* p_data) {
} break;
case BTIF_AV_OFFLOAD_START_REQ_EVT:
- LOG_ERROR("%s: Peer %s : event=%s: stream is not Opened",
- __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str());
+ log::error("Peer {} : event={}: stream is not Opened",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event));
btif_a2dp_on_offload_started(peer_.PeerAddress(), BTA_AV_FAIL);
break;
default:
- LOG_WARN("%s: Peer %s : Unhandled event=%s", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str());
+ log::warn("Peer {} : Unhandled event={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event));
return false;
}
@@ -1993,31 +2055,29 @@ bool BtifAvStateMachine::StateIdle::ProcessEvent(uint32_t event, void* p_data) {
}
void BtifAvStateMachine::StateOpening::OnEnter() {
- LOG_VERBOSE("%s: Peer %s", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
+ log::verbose("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
// Inform the application that we are entering connecting state
if (btif_av_both_enable()) {
/* if peer connect to us, don't know which role it is */
if (!peer_.SelfInitiatedConnection()) return;
}
- btif_report_connection_state(peer_.PeerAddress(),
- BTAV_CONNECTION_STATE_CONNECTING,
- bt_status_t::BT_STATUS_SUCCESS, BTA_AV_SUCCESS);
+ btif_report_connection_state(
+ peer_.PeerAddress(), BTAV_CONNECTION_STATE_CONNECTING,
+ bt_status_t::BT_STATUS_SUCCESS, BTA_AV_SUCCESS,
+ peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
}
void BtifAvStateMachine::StateOpening::OnExit() {
- LOG_VERBOSE("%s: Peer %s", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
+ log::verbose("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
}
bool BtifAvStateMachine::StateOpening::ProcessEvent(uint32_t event,
void* p_data) {
- LOG_VERBOSE(
- "%s: Peer %s : event=%s flags=%s active_peer=%s", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str(), peer_.FlagsToString().c_str(),
- logbool(peer_.IsActivePeer()).c_str());
+ log::verbose("Peer {} : event={} flags={} active_peer={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event), peer_.FlagsToString(),
+ logbool(peer_.IsActivePeer()));
switch (event) {
case BTIF_AV_STOP_STREAM_REQ_EVT:
@@ -2028,33 +2088,33 @@ bool BtifAvStateMachine::StateOpening::ProcessEvent(uint32_t event,
// ACL Disconnected needs to be handled only in Opening state, because
// it is in an intermediate state. In other states we can handle
// incoming/outgoing connect/disconnect requests.
- LOG_WARN(
- "%s: Peer %s : event=%s: transitioning to Idle due to ACL "
- "Disconnect",
- __PRETTY_FUNCTION__, ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str());
+ log::warn(
+ "Peer {} : event={}: transitioning to Idle due to ACL Disconnect",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event));
log_counter_metrics_btif(android::bluetooth::CodePathCounterKeyEnum::
A2DP_CONNECTION_ACL_DISCONNECTED,
1);
- btif_report_connection_state(peer_.PeerAddress(),
- BTAV_CONNECTION_STATE_DISCONNECTED,
- bt_status_t::BT_STATUS_FAIL, BTA_AV_FAIL);
+ btif_report_connection_state(
+ peer_.PeerAddress(), BTAV_CONNECTION_STATE_DISCONNECTED,
+ bt_status_t::BT_STATUS_FAIL, BTA_AV_FAIL,
+ peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
peer_.StateMachine().TransitionTo(BtifAvStateMachine::kStateIdle);
if (peer_.SelfInitiatedConnection()) {
btif_queue_advance();
}
break;
case BTA_AV_REJECT_EVT:
- LOG_WARN("%s: Peer %s : event=%s flags=%s", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str(),
- peer_.FlagsToString().c_str());
+ log::warn("Peer {} : event={} flags={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event), peer_.FlagsToString());
log_counter_metrics_btif(android::bluetooth::CodePathCounterKeyEnum::
A2DP_CONNECTION_REJECT_EVT,
1);
btif_report_connection_state(
peer_.PeerAddress(), BTAV_CONNECTION_STATE_DISCONNECTED,
- bt_status_t::BT_STATUS_AUTH_REJECTED, BTA_AV_FAIL);
+ bt_status_t::BT_STATUS_AUTH_REJECTED, BTA_AV_FAIL,
+ peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
peer_.StateMachine().TransitionTo(BtifAvStateMachine::kStateIdle);
if (peer_.SelfInitiatedConnection()) {
btif_queue_advance();
@@ -2066,27 +2126,28 @@ bool BtifAvStateMachine::StateOpening::ProcessEvent(uint32_t event,
int av_state;
tBTA_AV_STATUS status = p_bta_data->open.status;
- LOG_INFO(
- "%s: Peer %s : event=%s flags=%s status=%d(%s) edr=0x%x",
- __PRETTY_FUNCTION__, ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str(), peer_.FlagsToString().c_str(),
- status, (status == BTA_AV_SUCCESS) ? "SUCCESS" : "FAILED",
- p_bta_data->open.edr);
+ log::info("Peer {} : event={} flags={} status={}({}) edr=0x{:x}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event), peer_.FlagsToString(), status,
+ (status == BTA_AV_SUCCESS) ? "SUCCESS" : "FAILED",
+ p_bta_data->open.edr);
if (p_bta_data->open.status == BTA_AV_SUCCESS) {
av_state = BtifAvStateMachine::kStateOpened;
peer_.SetEdr(p_bta_data->open.edr);
if (btif_av_src_sink_coexist_enabled()) {
- LOG_VERBOSE("%s: Peer %s sep=%d, open_sep=%d", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- peer_.PeerSep(), p_bta_data->open.sep);
+ log::verbose("Peer {} sep={}, open_sep={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ peer_.PeerSep(), p_bta_data->open.sep);
/* if peer is wrong sep type, move it to BtifAvSxxx */
- if (peer_.PeerSep() == AVDT_TSEP_SNK) {
- LOG_VERBOSE("set source invalid_peer_check as false");
- btif_av_source.SetInvalidPeerCheck(false);
- } else {
- LOG_VERBOSE("set sink invalid_peer_check as false");
- btif_av_sink.SetInvalidPeerCheck(false);
+ if (!IS_FLAG_ENABLED(a2dp_concurrent_source_sink)) {
+ if (peer_.PeerSep() == AVDT_TSEP_SNK) {
+ log::verbose("set source invalid_peer_check as false");
+ btif_av_source.SetInvalidPeerCheck(false);
+ } else {
+ log::verbose("set sink invalid_peer_check as false");
+ btif_av_sink.SetInvalidPeerCheck(false);
+ }
}
if (peer_.PeerSep() != p_bta_data->open.sep) {
BtifAvPeer* tmp_peer = nullptr;
@@ -2094,21 +2155,21 @@ bool BtifAvStateMachine::StateOpening::ProcessEvent(uint32_t event,
tmp_peer = btif_av_source.popPeer(peer_.PeerAddress());
if (peer_.PeerAddress() != tmp_peer->PeerAddress())
- LOG_ERROR("error, not same peer");
+ log::error("error, not same peer");
btif_av_sink.AddPeer(tmp_peer);
} else {
tmp_peer = btif_av_sink.popPeer(peer_.PeerAddress());
if (peer_.PeerAddress() != tmp_peer->PeerAddress())
- LOG_ERROR("error, not same peer");
+ log::error("error, not same peer");
btif_av_source.AddPeer(tmp_peer);
}
peer_.SetSep(p_bta_data->open.sep);
}
if (btif_rc_is_connected_peer(peer_.PeerAddress())) {
- LOG_VERBOSE("%s, AVRCP connected, update avrc sep", __func__);
+ log::verbose("AVRCP connected, update avrc sep");
BTA_AvSetPeerSep(peer_.PeerAddress(), peer_.PeerSep());
}
btif_rc_check_pending_cmd(p_bta_data->open.bd_addr);
@@ -2135,7 +2196,8 @@ bool BtifAvStateMachine::StateOpening::ProcessEvent(uint32_t event,
// Report the connection state to the application
btif_report_connection_state(
peer_.PeerAddress(), BTAV_CONNECTION_STATE_CONNECTED,
- bt_status_t::BT_STATUS_SUCCESS, BTA_AV_SUCCESS);
+ bt_status_t::BT_STATUS_SUCCESS, BTA_AV_SUCCESS,
+ peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
log_counter_metrics_btif(
android::bluetooth::CodePathCounterKeyEnum::A2DP_CONNECTION_SUCCESS,
1);
@@ -2143,8 +2205,8 @@ bool BtifAvStateMachine::StateOpening::ProcessEvent(uint32_t event,
if (btif_rc_is_connected_peer(peer_.PeerAddress())) {
// Disconnect the AVRCP connection, in case the A2DP connectiton
// failed for any reason.
- LOG_WARN("%s: Peer %s : Disconnecting AVRCP", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
+ log::warn("Peer {} : Disconnecting AVRCP",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
uint8_t peer_handle =
btif_rc_get_connected_peer_handle(peer_.PeerAddress());
if (peer_handle != BTRC_HANDLE_NONE) {
@@ -2155,9 +2217,10 @@ bool BtifAvStateMachine::StateOpening::ProcessEvent(uint32_t event,
}
av_state = BtifAvStateMachine::kStateIdle;
// Report the connection state to the application
- btif_report_connection_state(peer_.PeerAddress(),
- BTAV_CONNECTION_STATE_DISCONNECTED,
- bt_status_t::BT_STATUS_FAIL, status);
+ btif_report_connection_state(
+ peer_.PeerAddress(), BTAV_CONNECTION_STATE_DISCONNECTED,
+ bt_status_t::BT_STATUS_FAIL, status,
+ peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
log_counter_metrics_btif(
android::bluetooth::CodePathCounterKeyEnum::A2DP_CONNECTION_FAILURE,
1);
@@ -2202,11 +2265,11 @@ bool BtifAvStateMachine::StateOpening::ProcessEvent(uint32_t event,
case BTIF_AV_CONNECT_REQ_EVT: {
// The device has moved already to Opening, hence don't report the
// connection state.
- LOG_WARN(
- "%s: Peer %s : event=%s : device is already connecting, "
- "ignore Connect request",
- __PRETTY_FUNCTION__, ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str());
+ log::warn(
+ "Peer {} : event={} : device is already connecting, ignore Connect "
+ "request",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event));
log_counter_metrics_btif(
android::bluetooth::CodePathCounterKeyEnum::A2DP_ALREADY_CONNECTING,
1);
@@ -2216,21 +2279,20 @@ bool BtifAvStateMachine::StateOpening::ProcessEvent(uint32_t event,
case BTA_AV_PENDING_EVT: {
// The device has moved already to Opening, hence don't report the
// connection state.
- LOG_WARN(
- "%s: Peer %s : event=%s : device is already connecting, "
- "ignore incoming request",
- __PRETTY_FUNCTION__, ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str());
+ log::warn(
+ "Peer {} : event={} : device is already connecting, ignore incoming "
+ "request",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event));
log_counter_metrics_btif(
android::bluetooth::CodePathCounterKeyEnum::A2DP_ALREADY_CONNECTING,
1);
} break;
case BTIF_AV_OFFLOAD_START_REQ_EVT:
- LOG_ERROR("%s: Peer %s : event=%s: stream is not Opened",
- __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str());
+ log::error("Peer {} : event={}: stream is not Opened",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event));
btif_a2dp_on_offload_started(peer_.PeerAddress(), BTA_AV_FAIL);
log_counter_metrics_btif(android::bluetooth::CodePathCounterKeyEnum::
A2DP_OFFLOAD_START_REQ_FAILURE,
@@ -2238,10 +2300,12 @@ bool BtifAvStateMachine::StateOpening::ProcessEvent(uint32_t event,
break;
case BTA_AV_CLOSE_EVT:
- btif_a2dp_on_stopped(nullptr);
- btif_report_connection_state(peer_.PeerAddress(),
- BTAV_CONNECTION_STATE_DISCONNECTED,
- bt_status_t::BT_STATUS_FAIL, BTA_AV_FAIL);
+ btif_a2dp_on_stopped(
+ nullptr, peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
+ btif_report_connection_state(
+ peer_.PeerAddress(), BTAV_CONNECTION_STATE_DISCONNECTED,
+ bt_status_t::BT_STATUS_FAIL, BTA_AV_FAIL,
+ peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
peer_.StateMachine().TransitionTo(BtifAvStateMachine::kStateIdle);
log_counter_metrics_btif(
android::bluetooth::CodePathCounterKeyEnum::A2DP_CONNECTION_CLOSE, 1);
@@ -2254,9 +2318,10 @@ bool BtifAvStateMachine::StateOpening::ProcessEvent(uint32_t event,
case BTIF_AV_DISCONNECT_REQ_EVT:
BTA_AvClose(peer_.BtaHandle());
- btif_report_connection_state(peer_.PeerAddress(),
- BTAV_CONNECTION_STATE_DISCONNECTED,
- bt_status_t::BT_STATUS_FAIL, BTA_AV_FAIL);
+ btif_report_connection_state(
+ peer_.PeerAddress(), BTAV_CONNECTION_STATE_DISCONNECTED,
+ bt_status_t::BT_STATUS_FAIL, BTA_AV_FAIL,
+ peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
peer_.StateMachine().TransitionTo(BtifAvStateMachine::kStateIdle);
DEVICE_IOT_CONFIG_ADDR_INT_ADD_ONE(peer_.PeerAddress(),
IOT_CONF_KEY_A2DP_CONN_FAIL_COUNT);
@@ -2274,17 +2339,16 @@ bool BtifAvStateMachine::StateOpening::ProcessEvent(uint32_t event,
log_counter_metrics_btif(android::bluetooth::CodePathCounterKeyEnum::
A2DP_CONNECTION_UNKNOWN_EVENT,
1);
- LOG_WARN("%s: Peer %s : Unhandled event=%s", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str());
+ log::warn("Peer {} : Unhandled event={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event));
return false;
}
return true;
}
void BtifAvStateMachine::StateOpened::OnEnter() {
- LOG_VERBOSE("%s: Peer %s", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
+ log::verbose("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
peer_.ClearFlags(BtifAvPeer::kFlagLocalSuspendPending |
BtifAvPeer::kFlagPendingStart |
@@ -2299,15 +2363,14 @@ void BtifAvStateMachine::StateOpened::OnEnter() {
std::promise<void> peer_ready_promise;
if (!btif_av_sink.SetActivePeer(peer_.PeerAddress(),
std::move(peer_ready_promise))) {
- LOG_ERROR("%s: Error setting %s as active Source peer", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
+ log::error("Error setting {} as active Source peer",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
}
}
}
void BtifAvStateMachine::StateOpened::OnExit() {
- LOG_VERBOSE("%s: Peer %s", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
+ log::verbose("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
peer_.ClearFlags(BtifAvPeer::kFlagPendingStart);
}
@@ -2316,18 +2379,16 @@ bool BtifAvStateMachine::StateOpened::ProcessEvent(uint32_t event,
void* p_data) {
tBTA_AV* p_av = (tBTA_AV*)p_data;
- LOG_VERBOSE(
- "%s: Peer %s : event=%s flags=%s active_peer=%s", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str(), peer_.FlagsToString().c_str(),
- logbool(peer_.IsActivePeer()).c_str());
+ log::verbose("Peer {} : event={} flags={} active_peer={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event), peer_.FlagsToString(),
+ logbool(peer_.IsActivePeer()));
if ((event == BTA_AV_REMOTE_CMD_EVT) &&
peer_.CheckFlags(BtifAvPeer::kFlagRemoteSuspend) &&
(p_av->remote_cmd.rc_id == AVRC_ID_PLAY)) {
- LOG_VERBOSE("%s: Peer %s : Resetting remote suspend flag on RC PLAY",
- __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
+ log::verbose("Peer {} : Resetting remote suspend flag on RC PLAY",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
peer_.ClearFlags(BtifAvPeer::kFlagRemoteSuspend);
}
@@ -2338,15 +2399,14 @@ bool BtifAvStateMachine::StateOpened::ProcessEvent(uint32_t event,
break; // Ignore
case BTIF_AV_START_STREAM_REQ_EVT: {
- LOG_INFO("%s: Peer %s : event=%s flags=%s", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str(),
- peer_.FlagsToString().c_str());
+ log::info("Peer {} : event={} flags={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event), peer_.FlagsToString());
if (p_data) {
const btif_av_start_stream_req_t* p_start_steam_req =
static_cast<const btif_av_start_stream_req_t*>(p_data);
- LOG_INFO("Stream use_latency_mode=%s",
- p_start_steam_req->use_latency_mode ? "true" : "false");
+ log::info("Stream use_latency_mode={}",
+ p_start_steam_req->use_latency_mode ? "true" : "false");
peer_.SetUseLatencyMode(p_start_steam_req->use_latency_mode);
}
@@ -2355,13 +2415,11 @@ bool BtifAvStateMachine::StateOpened::ProcessEvent(uint32_t event,
} break;
case BTA_AV_START_EVT: {
- LOG_INFO(
- "%s: Peer %s : event=%s status=%d suspending=%d "
- "initiator=%d flags=%s",
- __PRETTY_FUNCTION__, ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str(), p_av->start.status,
- p_av->start.suspending, p_av->start.initiator,
- peer_.FlagsToString().c_str());
+ log::info(
+ "Peer {} : event={} status={} suspending={} initiator={} flags={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event), p_av->start.status,
+ p_av->start.suspending, p_av->start.initiator, peer_.FlagsToString());
if ((p_av->start.status == BTA_SUCCESS) && p_av->start.suspending)
return true;
@@ -2373,20 +2431,20 @@ bool BtifAvStateMachine::StateOpened::ProcessEvent(uint32_t event,
if (peer_.IsSink()) {
if (!peer_.CheckFlags(BtifAvPeer::kFlagPendingStart |
BtifAvPeer::kFlagRemoteSuspend)) {
- LOG(WARNING) << __PRETTY_FUNCTION__ << ": Peer "
- << ADDRESS_TO_LOGGABLE_STR(peer_.PeerAddress())
- << " : trigger Suspend as remote initiated";
+ log::warn("Peer {} : trigger Suspend as remote initiated",
+ ADDRESS_TO_LOGGABLE_STR(peer_.PeerAddress()));
should_suspend = true;
} else if (!peer_.IsActivePeer()) {
- LOG(WARNING) << __PRETTY_FUNCTION__ << ": Peer "
- << ADDRESS_TO_LOGGABLE_STR(peer_.PeerAddress())
- << " : trigger Suspend as non-active";
+ log::warn("Peer {} : trigger Suspend as non-active",
+ ADDRESS_TO_LOGGABLE_STR(peer_.PeerAddress()));
should_suspend = true;
}
// If peer is A2DP Source, do ACK commands to audio HAL and start
// media task
- if (btif_a2dp_on_started(peer_.PeerAddress(), &p_av->start)) {
+ if (btif_a2dp_on_started(
+ peer_.PeerAddress(), &p_av->start,
+ peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource)) {
// Only clear pending flag after acknowledgement
peer_.ClearFlags(BtifAvPeer::kFlagPendingStart);
}
@@ -2418,7 +2476,8 @@ bool BtifAvStateMachine::StateOpened::ProcessEvent(uint32_t event,
// Inform the application that we are disconnecting
btif_report_connection_state(
peer_.PeerAddress(), BTAV_CONNECTION_STATE_DISCONNECTING,
- bt_status_t::BT_STATUS_SUCCESS, BTA_AV_SUCCESS);
+ bt_status_t::BT_STATUS_SUCCESS, BTA_AV_SUCCESS,
+ peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
// Wait in closing state until fully closed
peer_.StateMachine().TransitionTo(BtifAvStateMachine::kStateClosing);
@@ -2429,39 +2488,41 @@ bool BtifAvStateMachine::StateOpened::ProcessEvent(uint32_t event,
// Inform the application that we are disconnecting
btif_report_connection_state(
peer_.PeerAddress(), BTAV_CONNECTION_STATE_DISCONNECTING,
- bt_status_t::BT_STATUS_SUCCESS, BTA_AV_SUCCESS);
+ bt_status_t::BT_STATUS_SUCCESS, BTA_AV_SUCCESS,
+ peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
// Change state to Idle, send acknowledgement if start is pending
if (peer_.CheckFlags(BtifAvPeer::kFlagPendingStart)) {
- LOG_WARN("%s: Peer %s : failed pending start request",
- __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
+ log::warn("Peer {} : failed pending start request",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
tBTA_AV_START av_start = {.chnl = p_av->close.chnl,
.hndl = p_av->close.hndl,
.status = BTA_AV_FAIL_STREAM,
.initiator = true,
.suspending = true};
- btif_a2dp_on_started(peer_.PeerAddress(), &av_start);
+ btif_a2dp_on_started(
+ peer_.PeerAddress(), &av_start,
+ peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
// Pending start flag will be cleared when exit current state
} else if (peer_.IsActivePeer()) {
- btif_a2dp_on_stopped(nullptr);
+ btif_a2dp_on_stopped(
+ nullptr, peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
}
// Inform the application that we are disconnected
btif_report_connection_state(
peer_.PeerAddress(), BTAV_CONNECTION_STATE_DISCONNECTED,
- bt_status_t::BT_STATUS_SUCCESS, BTA_AV_SUCCESS);
+ bt_status_t::BT_STATUS_SUCCESS, BTA_AV_SUCCESS,
+ peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
peer_.StateMachine().TransitionTo(BtifAvStateMachine::kStateIdle);
break;
case BTA_AV_RECONFIG_EVT:
if (p_av->reconfig.status != BTA_AV_SUCCESS) {
- LOG(WARNING) << __PRETTY_FUNCTION__ << ": Peer "
- << ADDRESS_TO_LOGGABLE_STR(peer_.PeerAddress())
- << " : failed reconfiguration";
+ log::warn("Peer {} : failed reconfiguration",
+ ADDRESS_TO_LOGGABLE_STR(peer_.PeerAddress()));
if (peer_.CheckFlags(BtifAvPeer::kFlagPendingStart)) {
- LOG(ERROR) << __PRETTY_FUNCTION__ << ": Peer "
- << ADDRESS_TO_LOGGABLE_STR(peer_.PeerAddress())
- << " : cannot proceed to do AvStart";
+ log::error("Peer {} : cannot proceed to do AvStart",
+ ADDRESS_TO_LOGGABLE_STR(peer_.PeerAddress()));
peer_.ClearFlags(BtifAvPeer::kFlagPendingStart);
btif_a2dp_command_ack(A2DP_CTRL_ACK_FAILURE);
}
@@ -2474,43 +2535,40 @@ bool BtifAvStateMachine::StateOpened::ProcessEvent(uint32_t event,
}
if (peer_.IsActivePeer()) {
- LOG(INFO) << __PRETTY_FUNCTION__ << " : Peer "
- << ADDRESS_TO_LOGGABLE_STR(peer_.PeerAddress())
- << " : Reconfig done - calling startSession() to audio HAL";
+ log::info(
+ "Peer {} : Reconfig done - calling startSession() to audio HAL",
+ ADDRESS_TO_LOGGABLE_STR(peer_.PeerAddress()));
std::promise<void> peer_ready_promise;
std::future<void> peer_ready_future = peer_ready_promise.get_future();
btif_a2dp_source_start_session(peer_.PeerAddress(),
std::move(peer_ready_promise));
}
if (peer_.CheckFlags(BtifAvPeer::kFlagPendingStart)) {
- LOG(INFO) << __PRETTY_FUNCTION__ << " : Peer "
- << ADDRESS_TO_LOGGABLE_STR(peer_.PeerAddress())
- << " : Reconfig done - calling BTA_AvStart("
- << loghex(peer_.BtaHandle()) << ")";
+ log::info("Peer {} : Reconfig done - calling BTA_AvStart({})",
+ ADDRESS_TO_LOGGABLE_STR(peer_.PeerAddress()),
+ loghex(peer_.BtaHandle()));
BTA_AvStart(peer_.BtaHandle(), peer_.UseLatencyMode());
}
break;
case BTIF_AV_CONNECT_REQ_EVT: {
- LOG_WARN("%s: Peer %s : Ignore %s for same device", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str());
+ log::warn("Peer {} : Ignore {} for same device",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event));
btif_queue_advance();
} break;
case BTIF_AV_OFFLOAD_START_REQ_EVT:
- LOG_ERROR("%s: Peer %s : event=%s: stream is not Started",
- __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str());
+ log::error("Peer {} : event={}: stream is not Started",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event));
btif_a2dp_on_offload_started(peer_.PeerAddress(), BTA_AV_FAIL);
break;
case BTIF_AV_AVRCP_REMOTE_PLAY_EVT:
if (peer_.CheckFlags(BtifAvPeer::kFlagRemoteSuspend)) {
- LOG_VERBOSE("%s: Peer %s : Resetting remote suspend flag on RC PLAY",
- __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
+ log::verbose("Peer {} : Resetting remote suspend flag on RC PLAY",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
peer_.ClearFlags(BtifAvPeer::kFlagRemoteSuspend);
}
break;
@@ -2520,27 +2578,25 @@ bool BtifAvStateMachine::StateOpened::ProcessEvent(uint32_t event,
case BTIF_AV_SET_LATENCY_REQ_EVT: {
const btif_av_set_latency_req_t* p_set_latency_req =
static_cast<const btif_av_set_latency_req_t*>(p_data);
- LOG_INFO("Peer %s : event=%s flags=%s is_low_latency=%s",
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str(),
- peer_.FlagsToString().c_str(),
- p_set_latency_req->is_low_latency ? "true" : "false");
+ log::info("Peer {} : event={} flags={} is_low_latency={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event), peer_.FlagsToString(),
+ p_set_latency_req->is_low_latency ? "true" : "false");
BTA_AvSetLatency(peer_.BtaHandle(), p_set_latency_req->is_low_latency);
} break;
default:
- LOG_WARN("%s: Peer %s : Unhandled event=%s", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str());
+ log::warn("Peer {} : Unhandled event={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event));
return false;
}
return true;
}
void BtifAvStateMachine::StateStarted::OnEnter() {
- LOG_VERBOSE("%s: Peer %s", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
+ log::verbose("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
// We are again in started state, clear any remote suspend flags
peer_.ClearFlags(BtifAvPeer::kFlagRemoteSuspend);
@@ -2549,44 +2605,45 @@ void BtifAvStateMachine::StateStarted::OnEnter() {
// Report that we have entered the Streaming stage. Usually, this should
// be followed by focus grant. See update_audio_focus_state()
- btif_report_audio_state(peer_.PeerAddress(), BTAV_AUDIO_STATE_STARTED);
+ btif_report_audio_state(
+ peer_.PeerAddress(), BTAV_AUDIO_STATE_STARTED,
+ peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
}
void BtifAvStateMachine::StateStarted::OnExit() {
- LOG_VERBOSE("%s: Peer %s", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
+ log::verbose("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
}
bool BtifAvStateMachine::StateStarted::ProcessEvent(uint32_t event,
void* p_data) {
tBTA_AV* p_av = (tBTA_AV*)p_data;
- LOG_VERBOSE(
- "%s: Peer %s : event=%s flags=%s active_peer=%s", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str(), peer_.FlagsToString().c_str(),
- logbool(peer_.IsActivePeer()).c_str());
+ log::verbose("Peer {} : event={} flags={} active_peer={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event), peer_.FlagsToString(),
+ logbool(peer_.IsActivePeer()));
switch (event) {
case BTIF_AV_ACL_DISCONNECTED:
break; // Ignore
case BTIF_AV_START_STREAM_REQ_EVT:
- LOG_INFO("%s: Peer %s : event=%s flags=%s", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str(),
- peer_.FlagsToString().c_str());
+ log::info("Peer {} : event={} flags={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event), peer_.FlagsToString());
// We were started remotely, just ACK back the local request
- if (peer_.IsSink()) btif_a2dp_on_started(peer_.PeerAddress(), nullptr);
+ if (peer_.IsSink())
+ btif_a2dp_on_started(
+ peer_.PeerAddress(), nullptr,
+ peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
break;
// FIXME -- use suspend = true always to work around issue with BTA AV
case BTIF_AV_STOP_STREAM_REQ_EVT:
case BTIF_AV_SUSPEND_STREAM_REQ_EVT:
- LOG_INFO("%s: Peer %s : event=%s flags=%s", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str(),
- peer_.FlagsToString().c_str());
+ log::info("Peer {} : event={} flags={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event), peer_.FlagsToString());
// There is a pending LocalSuspend already, ignore.
if (peer_.CheckFlags(BtifAvPeer::kFlagLocalSuspendPending)) {
@@ -2602,25 +2659,27 @@ bool BtifAvStateMachine::StateStarted::ProcessEvent(uint32_t event,
peer_.ClearFlags(BtifAvPeer::kFlagRemoteSuspend);
if (peer_.IsSink() &&
- (peer_.IsActivePeer() || !btif_av_stream_started_ready())) {
+ (peer_.IsActivePeer() ||
+ !btif_av_stream_started_ready(A2dpType::kSource))) {
// Immediately stop transmission of frames while suspend is pending
if (event == BTIF_AV_STOP_STREAM_REQ_EVT) {
- btif_a2dp_on_stopped(nullptr);
+ btif_a2dp_on_stopped(
+ nullptr, peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
} else {
// ensure tx frames are immediately suspended
btif_a2dp_source_set_tx_flush(true);
}
} else if (peer_.IsSource()) {
- btif_a2dp_on_stopped(nullptr);
+ btif_a2dp_on_stopped(
+ nullptr, peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
}
BTA_AvStop(peer_.BtaHandle(), true);
break;
case BTIF_AV_DISCONNECT_REQ_EVT:
- LOG_INFO("%s: Peer %s : event=%s flags=%s", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str(),
- peer_.FlagsToString().c_str());
+ log::info("Peer {} : event={} flags={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event), peer_.FlagsToString());
// Request AVDTP to close
BTA_AvClose(peer_.BtaHandle());
@@ -2631,22 +2690,26 @@ bool BtifAvStateMachine::StateStarted::ProcessEvent(uint32_t event,
// Inform the application that we are disconnecting
btif_report_connection_state(
peer_.PeerAddress(), BTAV_CONNECTION_STATE_DISCONNECTING,
- bt_status_t::BT_STATUS_SUCCESS, BTA_AV_SUCCESS);
+ bt_status_t::BT_STATUS_SUCCESS, BTA_AV_SUCCESS,
+ peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
// Wait in closing state until fully closed
peer_.StateMachine().TransitionTo(BtifAvStateMachine::kStateClosing);
break;
case BTA_AV_SUSPEND_EVT: {
- LOG_INFO("%s: Peer %s : event=%s status=%d initiator=%d flags=%s",
- __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str(), p_av->suspend.status,
- p_av->suspend.initiator, peer_.FlagsToString().c_str());
+ log::info("Peer {} : event={} status={} initiator={} flags={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event), p_av->suspend.status,
+ p_av->suspend.initiator, peer_.FlagsToString());
// A2DP suspended, stop A2DP encoder / decoder until resumed
- if (peer_.IsActivePeer() || !btif_av_stream_started_ready()) {
- btif_a2dp_on_suspended(&p_av->suspend);
+ if (peer_.IsActivePeer() ||
+ !btif_av_stream_started_ready(peer_.IsSource() ? A2dpType::kSink
+ : A2dpType::kSource)) {
+ btif_a2dp_on_suspended(&p_av->suspend, peer_.IsSource()
+ ? A2dpType::kSink
+ : A2dpType::kSource);
}
// If not successful, remain in current state
@@ -2673,27 +2736,34 @@ bool BtifAvStateMachine::StateStarted::ProcessEvent(uint32_t event,
state = BTAV_AUDIO_STATE_STOPPED;
}
- btif_report_audio_state(peer_.PeerAddress(), state);
+ btif_report_audio_state(
+ peer_.PeerAddress(), state,
+ peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
// Suspend completed, clear local pending flags while entering Opened
peer_.StateMachine().TransitionTo(BtifAvStateMachine::kStateOpened);
} break;
case BTA_AV_STOP_EVT:
- LOG_INFO("%s: Peer %s : event=%s flags=%s", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str(),
- peer_.FlagsToString().c_str());
+ log::info("Peer {} : event={} flags={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event), peer_.FlagsToString());
peer_.SetFlags(BtifAvPeer::kFlagPendingStop);
peer_.ClearFlags(BtifAvPeer::kFlagLocalSuspendPending);
// Don't change the encoder and audio provider state by a non-active
// peer since they are shared between peers
- if (peer_.IsActivePeer() || !btif_av_stream_started_ready()) {
- btif_a2dp_on_stopped(&p_av->suspend);
+ if (peer_.IsActivePeer() ||
+ !btif_av_stream_started_ready(peer_.IsSource() ? A2dpType::kSink
+ : A2dpType::kSource)) {
+ btif_a2dp_on_stopped(&p_av->suspend, peer_.IsSource()
+ ? A2dpType::kSink
+ : A2dpType::kSource);
}
- btif_report_audio_state(peer_.PeerAddress(), BTAV_AUDIO_STATE_STOPPED);
+ btif_report_audio_state(
+ peer_.PeerAddress(), BTAV_AUDIO_STATE_STOPPED,
+ peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
// If stop was successful, change state to Open
if (p_av->suspend.status == BTA_AV_SUCCESS)
@@ -2702,26 +2772,28 @@ bool BtifAvStateMachine::StateStarted::ProcessEvent(uint32_t event,
break;
case BTA_AV_CLOSE_EVT:
- LOG_INFO("%s: Peer %s : event=%s flags=%s", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str(),
- peer_.FlagsToString().c_str());
+ log::info("Peer {} : event={} flags={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event), peer_.FlagsToString());
// Inform the application that we are disconnecting
btif_report_connection_state(
peer_.PeerAddress(), BTAV_CONNECTION_STATE_DISCONNECTING,
- bt_status_t::BT_STATUS_SUCCESS, BTA_AV_SUCCESS);
+ bt_status_t::BT_STATUS_SUCCESS, BTA_AV_SUCCESS,
+ peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
peer_.SetFlags(BtifAvPeer::kFlagPendingStop);
// AVDTP link is closed
if (peer_.IsActivePeer()) {
- btif_a2dp_on_stopped(nullptr);
+ btif_a2dp_on_stopped(
+ nullptr, peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
}
// Inform the application that we are disconnected
btif_report_connection_state(
peer_.PeerAddress(), BTAV_CONNECTION_STATE_DISCONNECTED,
- bt_status_t::BT_STATUS_SUCCESS, BTA_AV_SUCCESS);
+ bt_status_t::BT_STATUS_SUCCESS, BTA_AV_SUCCESS,
+ peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
peer_.StateMachine().TransitionTo(BtifAvStateMachine::kStateIdle);
break;
@@ -2730,11 +2802,9 @@ bool BtifAvStateMachine::StateStarted::ProcessEvent(uint32_t event,
if (peer_.CheckFlags(BtifAvPeer::kFlagLocalSuspendPending |
BtifAvPeer::kFlagRemoteSuspend |
BtifAvPeer::kFlagPendingStop)) {
- LOG_WARN("%s: Peer %s : event=%s flags=%s: stream is Suspending",
- __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str(),
- peer_.FlagsToString().c_str());
+ log::warn("Peer {} : event={} flags={}: stream is Suspending",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event), peer_.FlagsToString());
btif_a2dp_on_offload_started(peer_.PeerAddress(), BTA_AV_FAIL);
break;
}
@@ -2748,11 +2818,10 @@ bool BtifAvStateMachine::StateStarted::ProcessEvent(uint32_t event,
case BTIF_AV_SET_LATENCY_REQ_EVT: {
const btif_av_set_latency_req_t* p_set_latency_req =
static_cast<const btif_av_set_latency_req_t*>(p_data);
- LOG_INFO("Peer %s : event=%s flags=%s is_low_latency=%s",
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str(),
- peer_.FlagsToString().c_str(),
- p_set_latency_req->is_low_latency ? "true" : "false");
+ log::info("Peer {} : event={} flags={} is_low_latency={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event), peer_.FlagsToString(),
+ p_set_latency_req->is_low_latency ? "true" : "false");
BTA_AvSetLatency(peer_.BtaHandle(), p_set_latency_req->is_low_latency);
} break;
@@ -2760,9 +2829,9 @@ bool BtifAvStateMachine::StateStarted::ProcessEvent(uint32_t event,
CHECK_RC_EVENT(event, (tBTA_AV*)p_data);
default:
- LOG_WARN("%s: Peer %s : Unhandled event=%s", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str());
+ log::warn("Peer {} : Unhandled event={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event));
return false;
}
@@ -2770,8 +2839,7 @@ bool BtifAvStateMachine::StateStarted::ProcessEvent(uint32_t event,
}
void BtifAvStateMachine::StateClosing::OnEnter() {
- LOG_VERBOSE("%s: Peer %s", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
+ log::verbose("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
if (peer_.IsActivePeer()) {
if (peer_.IsSink()) {
@@ -2785,17 +2853,15 @@ void BtifAvStateMachine::StateClosing::OnEnter() {
}
void BtifAvStateMachine::StateClosing::OnExit() {
- LOG_VERBOSE("%s: Peer %s", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
+ log::verbose("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()));
}
bool BtifAvStateMachine::StateClosing::ProcessEvent(uint32_t event,
void* p_data) {
- LOG_VERBOSE(
- "%s: Peer %s : event=%s flags=%s active_peer=%s", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str(), peer_.FlagsToString().c_str(),
- logbool(peer_.IsActivePeer()).c_str());
+ log::verbose("Peer {} : event={} flags={} active_peer={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event), peer_.FlagsToString(),
+ logbool(peer_.IsActivePeer()));
switch (event) {
case BTIF_AV_SUSPEND_STREAM_REQ_EVT:
@@ -2805,7 +2871,8 @@ bool BtifAvStateMachine::StateClosing::ProcessEvent(uint32_t event,
case BTA_AV_STOP_EVT:
case BTIF_AV_STOP_STREAM_REQ_EVT:
if (peer_.IsActivePeer()) {
- btif_a2dp_on_stopped(nullptr);
+ btif_a2dp_on_stopped(
+ nullptr, peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
}
break;
@@ -2813,7 +2880,8 @@ bool BtifAvStateMachine::StateClosing::ProcessEvent(uint32_t event,
// Inform the application that we are disconnecting
btif_report_connection_state(
peer_.PeerAddress(), BTAV_CONNECTION_STATE_DISCONNECTED,
- bt_status_t::BT_STATUS_SUCCESS, BTA_AV_SUCCESS);
+ bt_status_t::BT_STATUS_SUCCESS, BTA_AV_SUCCESS,
+ peer_.IsSource() ? A2dpType::kSink : A2dpType::kSource);
peer_.StateMachine().TransitionTo(BtifAvStateMachine::kStateIdle);
break;
@@ -2829,25 +2897,24 @@ bool BtifAvStateMachine::StateClosing::ProcessEvent(uint32_t event,
break;
case BTIF_AV_OFFLOAD_START_REQ_EVT:
- LOG_ERROR("%s: Peer %s : event=%s: stream is not Opened",
- __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str());
+ log::error("Peer {} : event={}: stream is not Opened",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event));
btif_a2dp_on_offload_started(peer_.PeerAddress(), BTA_AV_FAIL);
break;
case BTIF_AV_CONNECT_REQ_EVT:
- LOG_WARN("%s: Peer %s : Ignore %s in StateClosing", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str());
+ log::warn("Peer {} : Ignore {} in StateClosing",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event));
btif_queue_advance();
peer_.StateMachine().TransitionTo(BtifAvStateMachine::kStateIdle);
break;
default:
- LOG_WARN("%s: Peer %s : Unhandled event=%s", __PRETTY_FUNCTION__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
- BtifAvEvent::EventName(event).c_str());
+ log::warn("Peer {} : Unhandled event={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_.PeerAddress()),
+ BtifAvEvent::EventName(event));
return false;
}
return true;
@@ -2861,21 +2928,20 @@ bool BtifAvStateMachine::StateClosing::ProcessEvent(uint32_t event,
static void btif_av_source_initiate_av_open_timer_timeout(void* data) {
BtifAvPeer* peer = (BtifAvPeer*)data;
- LOG_VERBOSE("%s: Peer %s", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()));
+ log::verbose("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()));
// Check if AVRCP is connected to the peer
if (!btif_rc_is_connected_peer(peer->PeerAddress())) {
- LOG_ERROR("%s: AVRCP peer %s is not connected", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()));
+ log::error("AVRCP peer {} is not connected",
+ ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()));
return;
}
// Connect to the AVRCP peer
if (btif_av_source.Enabled() &&
btif_av_source.FindPeer(peer->PeerAddress()) == peer) {
- LOG_VERBOSE("%s: Connecting to AVRCP peer %s", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()));
+ log::verbose("Connecting to AVRCP peer {}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()));
btif_av_source_dispatch_sm_event(peer->PeerAddress(),
BTIF_AV_CONNECT_REQ_EVT);
}
@@ -2888,21 +2954,20 @@ static void btif_av_source_initiate_av_open_timer_timeout(void* data) {
static void btif_av_sink_initiate_av_open_timer_timeout(void* data) {
BtifAvPeer* peer = (BtifAvPeer*)data;
- LOG_VERBOSE("%s: Peer %s", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()));
+ log::verbose("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()));
// Check if AVRCP is connected to the peer
if (!btif_rc_is_connected_peer(peer->PeerAddress())) {
- LOG_ERROR("%s: AVRCP peer %s is not connected", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()));
+ log::error("AVRCP peer {} is not connected",
+ ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()));
return;
}
// Connect to the AVRCP peer
if (btif_av_sink.Enabled() &&
btif_av_sink.FindPeer(peer->PeerAddress()) == peer) {
- LOG_VERBOSE("%s: Connecting to AVRCP peer %s", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()));
+ log::verbose("Connecting to AVRCP peer {}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()));
btif_av_sink_dispatch_sm_event(peer->PeerAddress(),
BTIF_AV_CONNECT_REQ_EVT);
}
@@ -2916,14 +2981,14 @@ static void btif_av_sink_initiate_av_open_timer_timeout(void* data) {
*/
static void btif_report_connection_state(const RawAddress& peer_address,
btav_connection_state_t state,
- bt_status_t status,
- uint8_t error_code) {
- LOG_INFO("%s: peer_address=%s state=%d", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_address), state);
+ bt_status_t status, uint8_t error_code,
+ const A2dpType local_a2dp_type) {
+ log::info("peer_address={} state={}", ADDRESS_TO_LOGGABLE_CSTR(peer_address),
+ state);
if (btif_av_src_sink_coexist_enabled() && btif_av_both_enable()) {
- BtifAvPeer* peer = btif_av_find_peer(peer_address);
+ BtifAvPeer* peer = btif_av_find_peer(peer_address, local_a2dp_type);
if (peer == nullptr) {
- LOG_ERROR("%s: peer is null", __func__);
+ log::error("peer is null");
return;
}
@@ -2966,12 +3031,13 @@ static void btif_report_connection_state(const RawAddress& peer_address,
* @param state the audio state
*/
static void btif_report_audio_state(const RawAddress& peer_address,
- btav_audio_state_t state) {
- LOG_INFO("%s: peer_address=%s state=%d", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_address), state);
+ btav_audio_state_t state,
+ const A2dpType local_a2dp_type) {
+ log::info("peer_address={} state={}", ADDRESS_TO_LOGGABLE_CSTR(peer_address),
+ state);
if (btif_av_both_enable()) {
- BtifAvPeer* peer = btif_av_find_peer(peer_address);
+ BtifAvPeer* peer = btif_av_find_peer(peer_address, local_a2dp_type);
if (peer->IsSink()) {
do_in_jni_thread(
FROM_HERE, base::BindOnce(btif_av_source.Callbacks()->audio_state_cb,
@@ -3020,8 +3086,7 @@ void btif_av_report_source_codec_state(
const std::vector<btav_a2dp_codec_config_t>& codecs_local_capabilities,
const std::vector<btav_a2dp_codec_config_t>&
codecs_selectable_capabilities) {
- LOG_VERBOSE("%s: peer_address=%s", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_address));
+ log::verbose("peer_address={}", ADDRESS_TO_LOGGABLE_CSTR(peer_address));
if (btif_av_source.Enabled()) {
do_in_jni_thread(
FROM_HERE,
@@ -3040,8 +3105,8 @@ void btif_av_report_source_codec_state(
*/
static void btif_av_report_sink_audio_config_state(
const RawAddress& peer_address, int sample_rate, int channel_count) {
- LOG_INFO("%s: Peer %s : sample_rate=%d channel_count=%d", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_address), sample_rate, channel_count);
+ log::info("Peer {} : sample_rate={} channel_count={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_address), sample_rate, channel_count);
if (btif_av_sink.Enabled()) {
do_in_jni_thread(FROM_HERE,
base::BindOnce(btif_av_sink.Callbacks()->audio_config_cb,
@@ -3059,7 +3124,7 @@ static void btif_av_query_mandatory_codec_priority(
const RawAddress& peer_address) {
auto query_priority = [](const RawAddress& peer_address) {
if (!btif_av_source.Enabled()) {
- LOG_WARN("BTIF AV Source is not enabled");
+ log::warn("BTIF AV Source is not enabled");
return;
}
btav_source_callbacks_t* callbacks = btif_av_source.Callbacks();
@@ -3067,9 +3132,9 @@ static void btif_av_query_mandatory_codec_priority(
callbacks->mandatory_codec_preferred_cb(peer_address);
if (preferred) {
auto apply_priority = [](const RawAddress& peer_address, bool preferred) {
- BtifAvPeer* peer = btif_av_find_peer(peer_address);
+ BtifAvPeer* peer = btif_av_find_peer(peer_address, A2dpType::kSource);
if (peer == nullptr) {
- LOG_WARN("btif_av_query_mandatory_codec_priority: peer is null");
+ log::warn("btif_av_query_mandatory_codec_priority: peer is null");
return;
}
peer->SetMandatoryCodecPreferred(preferred);
@@ -3090,48 +3155,45 @@ static BtifAvPeer* btif_av_handle_both_peer(uint8_t peer_sep,
if (peer_address != RawAddress::kEmpty) {
if (btif_av_both_enable()) {
- peer = btif_av_find_peer(peer_address);
+ peer = btif_av_find_peer(peer_address, A2dpType::kUnknown);
/* if no this peer, default it's sink device */
if (peer == nullptr) {
if (peer_sep == AVDT_TSEP_SRC) {
- LOG_VERBOSE("%s: peer_sep(%d), create a new source peer", __func__,
- peer_sep);
+ log::verbose("peer_sep({}), create a new source peer", peer_sep);
peer = btif_av_sink.FindOrCreatePeer(peer_address, bta_handle);
} else if (peer_sep == AVDT_TSEP_SNK) {
- LOG_VERBOSE("%s: peer_sep(%d), create a new sink peer", __func__,
- peer_sep);
+ log::verbose("peer_sep({}), create a new sink peer", peer_sep);
peer = btif_av_source.FindOrCreatePeer(peer_address, bta_handle);
} else {
- btif_av_source.SetInvalidPeerCheck(true);
+ if (!IS_FLAG_ENABLED(a2dp_concurrent_source_sink)) {
+ btif_av_source.SetInvalidPeerCheck(true);
+ }
if (!btif_av_source.Peers().empty()) {
- LOG_VERBOSE(
- "%s: peer_sep invalid, and already has sink peer,"
- " so try create a new sink peer",
- __func__);
+ log::verbose(
+ "peer_sep invalid, and already has sink peer, so try create a "
+ "new sink peer");
peer = btif_av_source.FindOrCreatePeer(peer_address, bta_handle);
} else if (!btif_av_sink.Peers().empty()) {
- LOG_VERBOSE(
- "%s: peer_sep invalid, and already has source peer,"
- " so try create a new source peer",
- __func__);
+ log::verbose(
+ "peer_sep invalid, and already has source peer, so try create "
+ "a new source peer");
peer = btif_av_sink.FindOrCreatePeer(peer_address, bta_handle);
} else {
- LOG_VERBOSE(
- "%s: peer_sep invalid, and no active peer,"
- " so try create a new sink peer",
- __func__);
+ log::verbose(
+ "peer_sep invalid, and no active peer, so try create a new "
+ "sink peer");
peer = btif_av_source.FindOrCreatePeer(peer_address, bta_handle);
}
}
}
} else {
if (peer_sep == AVDT_TSEP_SNK) {
- LOG_VERBOSE("%s: peer_sep(%d), only init src create a new source peer",
- __func__, peer_sep);
+ log::verbose("peer_sep({}), only init src create a new source peer",
+ peer_sep);
peer = btif_av_source.FindOrCreatePeer(peer_address, bta_handle);
} else if (peer_sep == AVDT_TSEP_SRC) {
- LOG_VERBOSE("%s: peer_sep(%d), only init sink create a new source peer",
- __func__, peer_sep);
+ log::verbose("peer_sep({}), only init sink create a new source peer",
+ peer_sep);
peer = btif_av_sink.FindOrCreatePeer(peer_address, bta_handle);
}
}
@@ -3141,7 +3203,7 @@ static BtifAvPeer* btif_av_handle_both_peer(uint8_t peer_sep,
} else if (peer_sep == AVDT_TSEP_SRC) {
peer = btif_av_sink.FindPeerByHandle(bta_handle);
}
- LOG_VERBOSE("%s:peer is check 3", __func__);
+ log::verbose("peer is check 3");
}
} else if (bta_handle != 0) {
if (peer_sep == AVDT_TSEP_INVALID) {
@@ -3174,8 +3236,8 @@ static void btif_av_handle_event(uint8_t peer_sep,
const RawAddress& peer_address,
tBTA_AV_HNDL bta_handle,
const BtifAvEvent& btif_av_event) {
- LOG_DEBUG("Handle event peer_address=%s bta_handle=0x%x",
- ADDRESS_TO_LOGGABLE_CSTR(peer_address), bta_handle);
+ log::debug("Handle event peer_address={} bta_handle=0x{:x}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_address), bta_handle);
BtifAvPeer* peer = nullptr;
@@ -3198,12 +3260,12 @@ static void btif_av_handle_event(uint8_t peer_sep,
}
}
if (peer == nullptr) {
- LOG_ERROR(
- "jni_thread: Cannot find or create %s peer for peer_address=%s "
- " bta_handle=0x%x : event dropped: %s",
- peer_stream_endpoint_text(peer_sep).c_str(),
+ log::error(
+ "jni_thread: Cannot find or create {} peer for peer_address={} "
+ "bta_handle=0x{:x} : event dropped: {}",
+ peer_stream_endpoint_text(peer_sep),
ADDRESS_TO_LOGGABLE_CSTR(peer_address), bta_handle,
- btif_av_event.ToString().c_str());
+ btif_av_event.ToString());
return;
}
@@ -3227,22 +3289,22 @@ static void btif_av_handle_bta_av_event(uint8_t peer_sep,
tBTA_AV* p_data = (tBTA_AV*)btif_av_event.Data();
std::string msg;
- LOG_DEBUG(
- "jni_thread: Handle BTA AV or AVRCP event %s: peer_sep=%hhu event=%s",
- peer_stream_endpoint_text(peer_sep).c_str(), peer_sep,
- btif_av_event.ToString().c_str());
+ log::debug(
+ "jni_thread: Handle BTA AV or AVRCP event {}: peer_sep={} event={}",
+ peer_stream_endpoint_text(peer_sep), peer_sep, btif_av_event.ToString());
switch (event) {
case BTA_AV_ENABLE_EVT: {
const tBTA_AV_ENABLE& enable = p_data->enable;
- LOG_DEBUG("Enable features=0x%x", enable.features);
+ log::debug("Enable features=0x{:x}", enable.features);
return; // Nothing to do
}
case BTA_AV_REGISTER_EVT: {
const tBTA_AV_REGISTER& reg = p_data->reg;
bta_handle = reg.hndl;
uint8_t peer_id = reg.app_id; // The PeerId is used as AppId
- LOG_DEBUG("Register bta_handle=0x%x app_id=%d", bta_handle, reg.app_id);
+ log::debug("Register bta_handle=0x{:x} app_id={}", bta_handle,
+ reg.app_id);
if (btif_av_src_sink_coexist_enabled()) {
if (peer_sep == AVDT_TSEP_INVALID) {
if (reg.peer_sep == AVDT_TSEP_SNK)
@@ -3395,7 +3457,7 @@ bool btif_av_src_sink_coexist_enabled(void) {
static void bta_av_source_callback(tBTA_AV_EVT event, tBTA_AV* p_data) {
BtifAvEvent btif_av_event(event, p_data, sizeof(tBTA_AV));
- LOG_VERBOSE("%s: event=%s", __func__, btif_av_event.ToString().c_str());
+ log::verbose("event={}", btif_av_event.ToString());
do_in_main_thread(
FROM_HERE, base::BindOnce(&btif_av_handle_bta_av_event,
@@ -3430,7 +3492,7 @@ static void bta_av_event_callback(tBTA_AV_EVT event, tBTA_AV* p_data) {
static void bta_av_sink_media_callback(const RawAddress& peer_address,
tBTA_AV_EVT event,
tBTA_AV_MEDIA* p_data) {
- LOG_VERBOSE("%s: event=%d", __func__, event);
+ log::verbose("event={}", event);
switch (event) {
case BTA_AV_SINK_MEDIA_DATA_EVT: {
@@ -3440,7 +3502,7 @@ static void bta_av_sink_media_callback(const RawAddress& peer_address,
if ((state == BtifAvStateMachine::kStateStarted) ||
(state == BtifAvStateMachine::kStateOpened)) {
uint8_t queue_len = btif_a2dp_sink_enqueue_buf((BT_HDR*)p_data);
- LOG_VERBOSE("%s: Packets in Sink queue %d", __func__, queue_len);
+ log::verbose("Packets in Sink queue {}", queue_len);
}
}
break;
@@ -3448,8 +3510,8 @@ static void bta_av_sink_media_callback(const RawAddress& peer_address,
case BTA_AV_SINK_MEDIA_CFG_EVT: {
btif_av_sink_config_req_t config_req;
- LOG_VERBOSE("%s: address=%s", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(p_data->avk_config.bd_addr));
+ log::verbose("address={}",
+ ADDRESS_TO_LOGGABLE_CSTR(p_data->avk_config.bd_addr));
// Update the codec info of the A2DP Sink decoder
btif_a2dp_sink_update_decoder((uint8_t*)(p_data->avk_config.codec_info));
@@ -3457,13 +3519,13 @@ static void bta_av_sink_media_callback(const RawAddress& peer_address,
config_req.sample_rate =
A2DP_GetTrackSampleRate(p_data->avk_config.codec_info);
if (config_req.sample_rate == -1) {
- LOG_ERROR("%s: Cannot get the track frequency", __func__);
+ log::error("Cannot get the track frequency");
break;
}
config_req.channel_count =
A2DP_GetTrackChannelCount(p_data->avk_config.codec_info);
if (config_req.channel_count == -1) {
- LOG_ERROR("%s: Cannot get the channel count", __func__);
+ log::error("Cannot get the channel count");
break;
}
config_req.peer_address = p_data->avk_config.bd_addr;
@@ -3487,7 +3549,7 @@ static bt_status_t init_src(
const std::vector<btav_a2dp_codec_config_t>& codec_priorities,
const std::vector<btav_a2dp_codec_config_t>& offloading_preference,
std::vector<btav_a2dp_codec_info_t>* supported_codecs) {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
return btif_av_source.Init(callbacks, max_connected_audio_devices,
codec_priorities, offloading_preference,
supported_codecs);
@@ -3496,26 +3558,26 @@ static bt_status_t init_src(
// Initializes the AV interface for sink mode
static bt_status_t init_sink(btav_sink_callbacks_t* callbacks,
int max_connected_audio_devices) {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
return btif_av_sink.Init(callbacks, max_connected_audio_devices);
}
// Updates the final focus state reported by components calling this module
static void update_audio_focus_state(int state) {
- LOG_VERBOSE("%s: state=%d", __func__, state);
+ log::verbose("state={}", state);
btif_a2dp_sink_set_focus_state_req((btif_a2dp_sink_focus_state_t)state);
}
// Updates the track gain (used for ducking).
static void update_audio_track_gain(float gain) {
- LOG_VERBOSE("%s: gain=%f", __func__, gain);
+ log::verbose("gain={:f}", gain);
btif_a2dp_sink_set_audio_track_gain(gain);
}
// Establishes the AV signalling channel with the remote headset
static bt_status_t connect_int(RawAddress* peer_address, uint16_t uuid) {
- LOG_VERBOSE("%s: peer_address=%s uuid=0x%x", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(*peer_address), uuid);
+ log::verbose("peer_address={} uuid=0x{:x}",
+ ADDRESS_TO_LOGGABLE_CSTR(*peer_address), uuid);
if (btif_av_both_enable()) {
const RawAddress tmp = *peer_address;
if (uuid == UUID_SERVCLASS_AUDIO_SOURCE) {
@@ -3542,19 +3604,19 @@ static bt_status_t connect_int(RawAddress* peer_address, uint16_t uuid) {
bt_status_t status = do_in_main_thread(
FROM_HERE, base::BindOnce(connection_task, peer_address, uuid));
if (status != BT_STATUS_SUCCESS) {
- LOG(ERROR) << __func__ << ": can't post connection task to main_thread";
+ log::error("can't post connection task to main_thread");
}
return status;
}
static void set_source_silence_peer_int(const RawAddress& peer_address,
bool silence) {
- LOG_VERBOSE("%s: peer_address=%s, silence=%s", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_address),
- silence ? "true" : "false");
+ log::verbose("peer_address={}, silence={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_address),
+ silence ? "true" : "false");
if (!btif_av_source.SetSilencePeer(peer_address, silence)) {
- LOG_ERROR("%s: Error setting silence state to %s", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_address));
+ log::error("Error setting silence state to {}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_address));
}
}
@@ -3562,17 +3624,17 @@ static void set_source_silence_peer_int(const RawAddress& peer_address,
static void set_active_peer_int(uint8_t peer_sep,
const RawAddress& peer_address,
std::promise<void> peer_ready_promise) {
- LOG_VERBOSE("%s: peer_sep=%s (%d) peer_address=%s", __func__,
- (peer_sep == AVDT_TSEP_SRC) ? "Source" : "Sink", peer_sep,
- ADDRESS_TO_LOGGABLE_CSTR(peer_address));
+ log::verbose("peer_sep={} ({}) peer_address={}",
+ (peer_sep == AVDT_TSEP_SRC) ? "Source" : "Sink", peer_sep,
+ ADDRESS_TO_LOGGABLE_CSTR(peer_address));
BtifAvPeer* peer = nullptr;
if (peer_sep == AVDT_TSEP_SNK) {
if (!btif_av_src_sink_coexist_enabled() || (btif_av_src_sink_coexist_enabled() &&
btif_av_both_enable() && (btif_av_sink.FindPeer(peer_address) == nullptr))) {
btif_av_source.SetActivePeer(peer_address,
std::move(peer_ready_promise));
- LOG_ERROR("%s: Error setting %s as active Sink peer", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_address));
+ log::error("Error setting {} as active Sink peer",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_address));
}
return;
}
@@ -3581,39 +3643,39 @@ static void set_active_peer_int(uint8_t peer_sep,
btif_av_both_enable() && (btif_av_source.FindPeer(peer_address) == nullptr))) {
if (!btif_av_sink.SetActivePeer(peer_address,
std::move(peer_ready_promise))) {
- LOG_ERROR("%s: Error setting %s as active Source peer", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_address));
+ log::error("Error setting {} as active Source peer",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_address));
}
}
return;
}
// If reached here, we could not set the active peer
- LOG_ERROR("%s: Cannot set active %s peer to %s: peer not %s", __func__,
- (peer_sep == AVDT_TSEP_SRC) ? "Source" : "Sink",
- ADDRESS_TO_LOGGABLE_CSTR(peer_address),
- (peer == nullptr) ? "found" : "connected");
+ log::error("Cannot set active {} peer to {}: peer not {}",
+ (peer_sep == AVDT_TSEP_SRC) ? "Source" : "Sink",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_address),
+ (peer == nullptr) ? "found" : "connected");
peer_ready_promise.set_value();
}
static bt_status_t src_connect_sink(const RawAddress& peer_address) {
if (!btif_av_source.Enabled()) {
- LOG_WARN("BTIF AV Source is not enabled");
+ log::warn("BTIF AV Source is not enabled");
return BT_STATUS_NOT_READY;
}
RawAddress peer_address_copy(peer_address);
- LOG_DEBUG("Connecting to AV sink peer:%s",
- ADDRESS_TO_LOGGABLE_CSTR(peer_address_copy));
+ log::debug("Connecting to AV sink peer:{}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_address_copy));
return btif_queue_connect(UUID_SERVCLASS_AUDIO_SOURCE, &peer_address_copy,
connect_int);
}
static bt_status_t sink_connect_src(const RawAddress& peer_address) {
- LOG_INFO("%s: Peer %s", __func__, ADDRESS_TO_LOGGABLE_CSTR(peer_address));
+ log::info("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_address));
if (!btif_av_sink.Enabled()) {
- LOG_WARN("%s: BTIF AV Sink is not enabled", __func__);
+ log::warn("BTIF AV Sink is not enabled");
return BT_STATUS_NOT_READY;
}
@@ -3623,10 +3685,10 @@ static bt_status_t sink_connect_src(const RawAddress& peer_address) {
}
static bt_status_t src_disconnect_sink(const RawAddress& peer_address) {
- LOG_INFO("%s: Peer %s", __func__, ADDRESS_TO_LOGGABLE_CSTR(peer_address));
+ log::info("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_address));
if (!btif_av_source.Enabled()) {
- LOG_WARN("%s: BTIF AV Source is not enabled", __func__);
+ log::warn("BTIF AV Source is not enabled");
return BT_STATUS_NOT_READY;
}
@@ -3640,10 +3702,10 @@ static bt_status_t src_disconnect_sink(const RawAddress& peer_address) {
}
static bt_status_t sink_disconnect_src(const RawAddress& peer_address) {
- LOG_INFO("%s: Peer %s", __func__, ADDRESS_TO_LOGGABLE_CSTR(peer_address));
+ log::info("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_address));
if (!btif_av_sink.Enabled()) {
- LOG_WARN("%s: BTIF AV Sink is not enabled", __func__);
+ log::warn("BTIF AV Sink is not enabled");
return BT_STATUS_NOT_READY;
}
@@ -3657,10 +3719,10 @@ static bt_status_t sink_disconnect_src(const RawAddress& peer_address) {
}
static bt_status_t sink_set_active_device(const RawAddress& peer_address) {
- LOG_VERBOSE("%s: Peer %s", __func__, ADDRESS_TO_LOGGABLE_CSTR(peer_address));
+ log::verbose("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_address));
if (!btif_av_sink.Enabled()) {
- LOG(WARNING) << __func__ << ": BTIF AV Source is not enabled";
+ log::warn("BTIF AV Source is not enabled");
return BT_STATUS_NOT_READY;
}
@@ -3673,16 +3735,16 @@ static bt_status_t sink_set_active_device(const RawAddress& peer_address) {
if (status == BT_STATUS_SUCCESS) {
peer_ready_future.wait();
} else {
- LOG(WARNING) << __func__ << ": BTIF AV Sink fails to change peer";
+ log::warn("BTIF AV Sink fails to change peer");
}
return status;
}
static bt_status_t src_set_silence_sink(const RawAddress& peer_address,
bool silence) {
- LOG_VERBOSE("%s: Peer %s", __func__, ADDRESS_TO_LOGGABLE_CSTR(peer_address));
+ log::verbose("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_address));
if (!btif_av_source.Enabled()) {
- LOG_WARN("%s: BTIF AV Source is not enabled", __func__);
+ log::warn("BTIF AV Source is not enabled");
return BT_STATUS_NOT_READY;
}
@@ -3692,10 +3754,10 @@ static bt_status_t src_set_silence_sink(const RawAddress& peer_address,
}
static bt_status_t src_set_active_sink(const RawAddress& peer_address) {
- LOG_VERBOSE("%s: Peer %s", __func__, ADDRESS_TO_LOGGABLE_CSTR(peer_address));
+ log::verbose("Peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_address));
if (!btif_av_source.Enabled()) {
- LOG(WARNING) << __func__ << ": BTIF AV Source is not enabled";
+ log::warn("BTIF AV Source is not enabled");
return BT_STATUS_NOT_READY;
}
@@ -3708,7 +3770,7 @@ static bt_status_t src_set_active_sink(const RawAddress& peer_address) {
if (status == BT_STATUS_SUCCESS) {
peer_ready_future.wait();
} else {
- LOG(WARNING) << __func__ << ": BTIF AV Source fails to change peer";
+ log::warn("BTIF AV Source fails to change peer");
}
return status;
}
@@ -3716,15 +3778,15 @@ static bt_status_t src_set_active_sink(const RawAddress& peer_address) {
static bt_status_t codec_config_src(
const RawAddress& peer_address,
std::vector<btav_a2dp_codec_config_t> codec_preferences) {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
if (!btif_av_source.Enabled()) {
- LOG(WARNING) << __func__ << ": BTIF AV Source is not enabled";
+ log::warn("BTIF AV Source is not enabled");
return BT_STATUS_NOT_READY;
}
if (peer_address.IsEmpty()) {
- LOG(WARNING) << __func__ << ": BTIF AV Source needs peer to config";
+ log::warn("BTIF AV Source needs peer to config");
return BT_STATUS_PARM_INVALID;
}
@@ -3738,20 +3800,20 @@ static bt_status_t codec_config_src(
if (status == BT_STATUS_SUCCESS) {
peer_ready_future.wait();
} else {
- LOG(WARNING) << __func__ << ": BTIF AV Source fails to config codec";
+ log::warn("BTIF AV Source fails to config codec");
}
return status;
}
static void cleanup_src(void) {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
do_in_main_thread(FROM_HERE,
base::BindOnce(&BtifAvSource::Cleanup,
base::Unretained(&btif_av_source)));
}
static void cleanup_sink(void) {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
do_in_main_thread(FROM_HERE, base::BindOnce(&BtifAvSink::Cleanup,
base::Unretained(&btif_av_sink)));
}
@@ -3786,23 +3848,22 @@ bool btif_av_is_sink_enabled(void) { return btif_av_sink.Enabled(); }
bool btif_av_is_source_enabled(void) { return btif_av_source.Enabled(); }
-void btif_av_stream_start(void) {
- LOG_INFO("%s", __func__);
+void btif_av_stream_start(const A2dpType local_a2dp_type) {
+ log::info("");
btif_av_source_dispatch_sm_event(btif_av_source_active_peer(),
BTIF_AV_START_STREAM_REQ_EVT);
}
void btif_av_stream_start_with_latency(bool use_latency_mode) {
- LOG_INFO("%s", __func__);
+ log::info("");
btif_av_start_stream_req_t start_stream_req;
start_stream_req.use_latency_mode = use_latency_mode;
BtifAvEvent btif_av_event(BTIF_AV_START_STREAM_REQ_EVT, &start_stream_req,
sizeof(start_stream_req));
- LOG_INFO("peer_address=%s event=%s use_latency_mode=%s",
- ADDRESS_TO_LOGGABLE_CSTR(btif_av_source_active_peer()),
- btif_av_event.ToString().c_str(),
- use_latency_mode ? "true" : "false");
+ log::info("peer_address={} event={} use_latency_mode={}",
+ ADDRESS_TO_LOGGABLE_CSTR(btif_av_source_active_peer()),
+ btif_av_event.ToString(), use_latency_mode ? "true" : "false");
do_in_main_thread(
FROM_HERE, base::BindOnce(&btif_av_handle_event,
@@ -3825,7 +3886,7 @@ void src_do_suspend_in_main_thread(btif_av_sm_event_t event) {
}
}
if (is_idle) {
- btif_a2dp_on_stopped(nullptr);
+ btif_a2dp_on_stopped(nullptr, A2dpType::kSource);
}
};
// switch to main thread to prevent a race condition of accessing peers
@@ -3833,7 +3894,7 @@ void src_do_suspend_in_main_thread(btif_av_sm_event_t event) {
}
void btif_av_stream_stop(const RawAddress& peer_address) {
- LOG_INFO("%s peer %s", __func__, ADDRESS_TO_LOGGABLE_CSTR(peer_address));
+ log::info("peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_address));
if (!peer_address.IsEmpty()) {
btif_av_source_dispatch_sm_event(peer_address, BTIF_AV_STOP_STREAM_REQ_EVT);
@@ -3846,40 +3907,40 @@ void btif_av_stream_stop(const RawAddress& peer_address) {
}
void btif_av_stream_suspend(void) {
- LOG_INFO("%s", __func__);
+ log::info("");
// The active peer might have changed and we might be in the process
// of reconfiguring the stream. We need to suspend the appropriate peer(s).
src_do_suspend_in_main_thread(BTIF_AV_SUSPEND_STREAM_REQ_EVT);
}
void btif_av_stream_start_offload(void) {
- LOG_INFO("%s", __func__);
+ log::info("");
btif_av_source_dispatch_sm_event(btif_av_source_active_peer(),
BTIF_AV_OFFLOAD_START_REQ_EVT);
}
void btif_av_src_disconnect_sink(const RawAddress& peer_address) {
- LOG_INFO("%s: peer %s", __func__, ADDRESS_TO_LOGGABLE_CSTR(peer_address));
+ log::info("peer {}", ADDRESS_TO_LOGGABLE_CSTR(peer_address));
src_disconnect_sink(peer_address);
}
-bool btif_av_stream_ready(void) {
+bool btif_av_stream_ready(const A2dpType local_a2dp_type) {
// Make sure the main adapter is enabled
if (btif_is_enabled() == 0) {
- LOG_VERBOSE("%s: Main adapter is not enabled", __func__);
+ log::verbose("Main adapter is not enabled");
return false;
}
- BtifAvPeer* peer = btif_av_find_active_peer();
+ BtifAvPeer* peer = btif_av_find_active_peer(local_a2dp_type);
if (peer == nullptr) {
- LOG_WARN("%s: No active peer found", __func__);
+ log::warn("No active peer found");
return false;
}
int state = peer->StateMachine().StateId();
- LOG_INFO("%s: Peer %s : state=%d, flags=%s", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), state,
- peer->FlagsToString().c_str());
+ log::info("Peer {} : state={}, flags={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), state,
+ peer->FlagsToString());
// check if we are remotely suspended or stop is pending
if (peer->CheckFlags(BtifAvPeer::kFlagRemoteSuspend |
BtifAvPeer::kFlagPendingStop)) {
@@ -3889,10 +3950,10 @@ bool btif_av_stream_ready(void) {
return (state == BtifAvStateMachine::kStateOpened);
}
-bool btif_av_stream_started_ready(void) {
- BtifAvPeer* peer = btif_av_find_active_peer();
+bool btif_av_stream_started_ready(const A2dpType local_a2dp_type) {
+ BtifAvPeer* peer = btif_av_find_active_peer(local_a2dp_type);
if (peer == nullptr) {
- LOG_WARN("%s: No active peer found", __func__);
+ log::warn("No active peer found");
return false;
}
@@ -3906,9 +3967,9 @@ bool btif_av_stream_started_ready(void) {
} else {
ready = (state == BtifAvStateMachine::kStateStarted);
}
- LOG_INFO("%s: Peer %s : state=%d flags=%s ready=%d", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), state,
- peer->FlagsToString().c_str(), ready);
+ log::info("Peer {} : state={} flags={} ready={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()), state,
+ peer->FlagsToString(), ready);
return ready;
}
@@ -3916,9 +3977,9 @@ bool btif_av_stream_started_ready(void) {
static void btif_av_source_dispatch_sm_event(const RawAddress& peer_address,
btif_av_sm_event_t event) {
BtifAvEvent btif_av_event(event, nullptr, 0);
- LOG_VERBOSE("%s: peer_address=%s event=%s", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_address),
- btif_av_event.ToString().c_str());
+ log::verbose("peer_address={} event={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_address),
+ btif_av_event.ToString());
do_in_main_thread(FROM_HERE, base::BindOnce(&btif_av_handle_event,
AVDT_TSEP_SNK, // peer_sep
@@ -3929,9 +3990,9 @@ static void btif_av_source_dispatch_sm_event(const RawAddress& peer_address,
static void btif_av_sink_dispatch_sm_event(const RawAddress& peer_address,
btif_av_sm_event_t event) {
BtifAvEvent btif_av_event(event, nullptr, 0);
- LOG_VERBOSE("%s: peer_address=%s event=%s", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_address),
- btif_av_event.ToString().c_str());
+ log::verbose("peer_address={} event={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_address),
+ btif_av_event.ToString());
do_in_main_thread(FROM_HERE, base::BindOnce(&btif_av_handle_event,
AVDT_TSEP_SRC, // peer_sep
@@ -3940,8 +4001,7 @@ static void btif_av_sink_dispatch_sm_event(const RawAddress& peer_address,
}
bt_status_t btif_av_source_execute_service(bool enable) {
- LOG_VERBOSE("%s: Source service: %s", __func__,
- (enable) ? "enable" : "disable");
+ log::verbose("Source service: {}", (enable) ? "enable" : "disable");
if (enable) {
// Added BTA_AV_FEAT_NO_SCO_SSPD - this ensures that the BTA does not
@@ -3977,8 +4037,7 @@ bt_status_t btif_av_source_execute_service(bool enable) {
}
bt_status_t btif_av_sink_execute_service(bool enable) {
- LOG_VERBOSE("%s: Sink service: %s", __func__,
- (enable) ? "enable" : "disable");
+ log::verbose("Sink service: {}", (enable) ? "enable" : "disable");
if (enable) {
// Added BTA_AV_FEAT_NO_SCO_SSPD - this ensures that the BTA does not
@@ -4009,110 +4068,114 @@ bt_status_t btif_av_sink_execute_service(bool enable) {
// Get the AV callback interface for A2DP source profile
const btav_source_interface_t* btif_av_get_src_interface(void) {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
return &bt_av_src_interface;
}
// Get the AV callback interface for A2DP sink profile
const btav_sink_interface_t* btif_av_get_sink_interface(void) {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
return &bt_av_sink_interface;
}
-bool btif_av_is_connected(void) {
- BtifAvPeer* peer = btif_av_find_active_peer();
+bool btif_av_is_connected(const A2dpType local_a2dp_type) {
+ BtifAvPeer* peer = btif_av_find_active_peer(local_a2dp_type);
if (peer == nullptr) {
- LOG_WARN("%s: No active peer found", __func__);
+ log::warn("No active peer found");
return false;
}
bool connected = peer->IsConnected();
- LOG_VERBOSE("%s: Peer %s is %s", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()),
- (connected) ? "connected" : "not connected");
+ log::verbose("Peer {} is {}", ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()),
+ (connected) ? "connected" : "not connected");
return connected;
}
-uint8_t btif_av_get_peer_sep(void) {
- BtifAvPeer* peer = btif_av_find_active_peer();
+uint8_t btif_av_get_peer_sep(const A2dpType local_a2dp_type) {
+ BtifAvPeer* peer = btif_av_find_active_peer(local_a2dp_type);
if (peer == nullptr) {
- LOG_INFO("No active sink or source peer found");
+ log::info("No active sink or source peer found");
return AVDT_TSEP_INVALID;
}
uint8_t peer_sep = peer->PeerSep();
- LOG_VERBOSE("Peer %s SEP is %s (%d)",
- ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()),
- (peer_sep == AVDT_TSEP_SRC) ? "Source" : "Sink", peer_sep);
+ log::verbose("Peer {} SEP is {} ({})",
+ ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()),
+ (peer_sep == AVDT_TSEP_SRC) ? "Source" : "Sink", peer_sep);
return peer_sep;
}
-void btif_av_clear_remote_suspend_flag(void) {
- auto clear_remote_suspend_flag = []() {
- BtifAvPeer* peer = btif_av_find_active_peer();
+void btif_av_clear_remote_suspend_flag(const A2dpType local_a2dp_type) {
+ auto clear_remote_suspend_flag = [](const A2dpType local_a2dp_type) {
+ BtifAvPeer* peer = btif_av_find_active_peer(local_a2dp_type);
if (peer == nullptr) {
- LOG_WARN("%s: No active peer found", __func__);
+ log::warn("No active peer found");
return;
}
- LOG_VERBOSE("%s: Peer %s : flags=%s are cleared", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()),
- peer->FlagsToString().c_str());
+ log::verbose("Peer {} : flags={} are cleared",
+ ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()),
+ peer->FlagsToString());
peer->ClearFlags(BtifAvPeer::kFlagRemoteSuspend);
};
// switch to main thread to prevent a race condition of accessing peers
- do_in_main_thread(FROM_HERE, base::BindOnce(clear_remote_suspend_flag));
+ do_in_main_thread(FROM_HERE,
+ base::BindOnce(clear_remote_suspend_flag, local_a2dp_type));
}
-bool btif_av_is_peer_edr(const RawAddress& peer_address) {
- BtifAvPeer* peer = btif_av_find_peer(peer_address);
+bool btif_av_is_peer_edr(const RawAddress& peer_address,
+ const A2dpType local_a2dp_type) {
+ BtifAvPeer* peer = btif_av_find_peer(peer_address, local_a2dp_type);
if (peer == nullptr) {
- LOG_WARN("%s: No peer found for peer_address=%s", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_address));
+ log::warn("No peer found for peer_address={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_address));
return false;
}
if (!peer->IsConnected()) {
- LOG_WARN("%s: Peer %s is not connected", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_address));
+ log::warn("Peer {} is not connected",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_address));
return false;
}
bool is_edr = peer->IsEdr();
- LOG_VERBOSE("%s: Peer %s : is_edr=%d", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_address), is_edr);
+ log::verbose("Peer {} : is_edr={}", ADDRESS_TO_LOGGABLE_CSTR(peer_address),
+ is_edr);
return is_edr;
}
-bool btif_av_peer_supports_3mbps(const RawAddress& peer_address) {
- BtifAvPeer* peer = btif_av_find_peer(peer_address);
+bool btif_av_peer_supports_3mbps(const RawAddress& peer_address,
+ const A2dpType local_a2dp_type) {
+ BtifAvPeer* peer = btif_av_find_peer(peer_address, local_a2dp_type);
if (peer == nullptr) {
- LOG_WARN("%s: No peer found for peer_address=%s", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_address));
+ log::warn("No peer found for peer_address={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_address));
return false;
}
bool is3mbps = peer->Is3Mbps();
bool is_connected = peer->IsConnected();
- LOG_VERBOSE("%s: Peer %s : connected=%d, edr_3mbps=%d", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_address), is_connected, is3mbps);
+ log::verbose("Peer {} : connected={}, edr_3mbps={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_address), is_connected, is3mbps);
return (is_connected && is3mbps);
}
-bool btif_av_peer_prefers_mandatory_codec(const RawAddress& peer_address) {
- BtifAvPeer* peer = btif_av_find_peer(peer_address);
+bool btif_av_peer_prefers_mandatory_codec(const RawAddress& peer_address,
+ const A2dpType local_a2dp_type) {
+ BtifAvPeer* peer = btif_av_find_peer(peer_address, local_a2dp_type);
if (peer == nullptr) {
- LOG_WARN("%s: No peer found for peer_address=%s", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_address));
+ log::warn("No peer found for peer_address={}",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_address));
return false;
}
return peer->IsMandatoryCodecPreferred();
}
-void btif_av_acl_disconnected(const RawAddress& peer_address) {
+void btif_av_acl_disconnected(const RawAddress& peer_address,
+ const A2dpType local_a2dp_type) {
// Inform the application that ACL is disconnected and move to idle state
- LOG_INFO("%s: Peer %s : ACL Disconnected", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer_address));
- if (btif_av_both_enable()) {
- BtifAvPeer* peer = btif_av_find_peer(peer_address);
+ log::info("Peer {} : ACL Disconnected",
+ ADDRESS_TO_LOGGABLE_CSTR(peer_address));
+ if (IS_FLAG_ENABLED(a2dp_concurrent_source_sink) || btif_av_both_enable()) {
+ BtifAvPeer* peer = btif_av_find_peer(peer_address, local_a2dp_type);
if (peer != nullptr) {
if (peer->IsSource()) {
btif_av_sink_dispatch_sm_event(peer_address, BTIF_AV_ACL_DISCONNECTED);
@@ -4211,9 +4274,10 @@ void btif_debug_av_dump(int fd) {
btif_debug_av_sink_dump(fd);
}
-void btif_av_set_audio_delay(const RawAddress& peer_address, uint16_t delay) {
+void btif_av_set_audio_delay(const RawAddress& peer_address, uint16_t delay,
+ const A2dpType local_a2dp_type) {
btif_a2dp_control_set_audio_delay(delay);
- BtifAvPeer* peer = btif_av_find_peer(peer_address);
+ BtifAvPeer* peer = btif_av_find_peer(peer_address, local_a2dp_type);
if (peer != nullptr && peer->IsSink()) {
peer->SetDelayReport(delay);
if (peer->IsActivePeer()) {
@@ -4222,8 +4286,8 @@ void btif_av_set_audio_delay(const RawAddress& peer_address, uint16_t delay) {
}
}
-uint16_t btif_av_get_audio_delay() {
- BtifAvPeer* peer = btif_av_find_active_peer();
+uint16_t btif_av_get_audio_delay(const A2dpType local_a2dp_type) {
+ BtifAvPeer* peer = btif_av_find_active_peer(local_a2dp_type);
if (peer != nullptr && peer->IsSink()) {
return peer->GetDelayReport();
}
@@ -4255,15 +4319,15 @@ void btif_av_set_dynamic_audio_buffer_size(uint8_t dynamic_audio_buffer_size) {
}
void btif_av_set_low_latency(bool is_low_latency) {
- LOG_INFO("is_low_latency: %s", is_low_latency ? "true" : "false");
+ log::info("is_low_latency: {}", is_low_latency ? "true" : "false");
btif_av_set_latency_req_t set_latency_req;
set_latency_req.is_low_latency = is_low_latency;
BtifAvEvent btif_av_event(BTIF_AV_SET_LATENCY_REQ_EVT, &set_latency_req,
sizeof(set_latency_req));
- LOG_INFO("peer_address=%s event=%s",
- ADDRESS_TO_LOGGABLE_CSTR(btif_av_source_active_peer()),
- btif_av_event.ToString().c_str());
+ log::info("peer_address={} event={}",
+ ADDRESS_TO_LOGGABLE_CSTR(btif_av_source_active_peer()),
+ btif_av_event.ToString());
do_in_main_thread(
FROM_HERE, base::BindOnce(&btif_av_handle_event,
AVDT_TSEP_SNK, // peer_sep
@@ -4279,52 +4343,50 @@ static void btif_av_source_delete_active_peer(void) {
btif_av_source.DeleteActivePeer();
}
-bool btif_av_is_connected_addr(const RawAddress& peer_address) {
- BtifAvPeer* peer = btif_av_find_peer(peer_address);
+bool btif_av_is_connected_addr(const RawAddress& peer_address,
+ const A2dpType local_a2dp_type) {
+ BtifAvPeer* peer = btif_av_find_peer(peer_address, local_a2dp_type);
if (peer == nullptr) {
- LOG_WARN("%s: No active peer found", __func__);
+ log::warn("No active peer found");
return false;
}
bool connected = peer->IsConnected();
- LOG_VERBOSE("%s: Peer %s is %s", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()),
- (connected) ? "connected" : "not connected");
+ log::verbose("Peer {} is {}", ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()),
+ (connected) ? "connected" : "not connected");
return connected;
}
bool btif_av_peer_is_connected_sink(const RawAddress& peer_address) {
BtifAvPeer* peer = btif_av_source_find_peer(peer_address);
if (peer == nullptr) {
- LOG_WARN("%s: No active peer found", __func__);
+ log::warn("No active peer found");
return false;
}
bool connected = peer->IsConnected();
- LOG_VERBOSE("%s: Peer %s is %s", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()),
- (connected) ? "connected" : "not connected");
+ log::verbose("Peer {} is {}", ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()),
+ (connected) ? "connected" : "not connected");
return connected;
}
bool btif_av_peer_is_connected_source(const RawAddress& peer_address) {
BtifAvPeer* peer = btif_av_sink_find_peer(peer_address);
if (peer == nullptr) {
- LOG_WARN("%s: No active peer found", __func__);
+ log::warn("No active peer found");
return false;
}
bool connected = peer->IsConnected();
- LOG_VERBOSE("%s: Peer %s is %s", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()),
- (connected) ? "connected" : "not connected");
+ log::verbose("Peer {} is {}", ADDRESS_TO_LOGGABLE_CSTR(peer->PeerAddress()),
+ (connected) ? "connected" : "not connected");
return connected;
}
bool btif_av_peer_is_sink(const RawAddress& peer_address) {
BtifAvPeer* peer = btif_av_source_find_peer(peer_address);
if (peer == nullptr) {
- LOG_WARN("%s: No active peer found", __func__);
+ log::warn("No active peer found");
return false;
}
@@ -4334,7 +4396,7 @@ bool btif_av_peer_is_sink(const RawAddress& peer_address) {
bool btif_av_peer_is_source(const RawAddress& peer_address) {
BtifAvPeer* peer = btif_av_sink_find_peer(peer_address);
if (peer == nullptr) {
- LOG_WARN("%s: No active peer found", __func__);
+ log::warn("No active peer found");
return false;
}
diff --git a/system/btif/src/btif_avrcp_audio_track.cc b/system/btif/src/btif_avrcp_audio_track.cc
index 0ad2c0a6ee..6c0ef2e8bf 100644
--- a/system/btif/src/btif_avrcp_audio_track.cc
+++ b/system/btif/src/btif_avrcp_audio_track.cc
@@ -25,6 +25,7 @@
#include <aaudio/AAudio.h>
#include <base/logging.h>
+#include <bluetooth/log.h>
#include <utils/StrongPointer.h>
#include <algorithm>
@@ -35,6 +36,7 @@
#include "os/log.h"
using namespace android;
+using namespace bluetooth;
typedef struct {
AAudioStream* stream;
@@ -45,11 +47,6 @@ typedef struct {
float gain;
} BtifAvrcpAudioTrack;
-#if (DUMP_PCM_DATA == TRUE)
-FILE* outputPcmSampleFile;
-char outputFilename[50] = "/data/misc/bluedroid/output_sample.pcm";
-#endif
-
// Maximum track gain that can be set.
constexpr float kMaxTrackGain = 1.0f;
// Minimum track gain that can be set.
@@ -85,8 +82,8 @@ void BtifAvrcpAudioErrorHandle() {
trackHolder->stream = stream;
if (trackHolder != NULL && trackHolder->stream != NULL) {
- LOG_DEBUG("%s AAudio Error handle: restart A2dp Sink AudioTrack", __func__);
- AAudioStream_requestStart(trackHolder->stream);
+ log::debug("AAudio Error handle: restart A2dp Sink AudioTrack");
+ AAudioStream_requestStart(trackHolder->stream);
}
s_AudioEngine.thread = nullptr;
}
@@ -101,8 +98,8 @@ void ErrorCallback(AAudioStream* stream,
void* BtifAvrcpAudioTrackCreate(int trackFreq, int bitsPerSample,
int channelCount) {
- LOG_INFO("%s Track.cpp: btCreateTrack freq %d bps %d channel %d ", __func__,
- trackFreq, bitsPerSample, channelCount);
+ log::info("Track.cpp: btCreateTrack freq {} bps {} channel {}", trackFreq,
+ bitsPerSample, channelCount);
AAudioStreamBuilder* builder;
AAudioStream* stream;
@@ -128,9 +125,6 @@ void* BtifAvrcpAudioTrackCreate(int trackFreq, int bitsPerSample,
trackHolder->gain = kMaxTrackGain;
trackHolder->buffer = new float[trackHolder->bufferLength]();
-#if (DUMP_PCM_DATA == TRUE)
- outputPcmSampleFile = fopen(outputFilename, "ab");
-#endif
s_AudioEngine.trackFreq = trackFreq;
s_AudioEngine.channelCount = channelCount;
s_AudioEngine.trackHandle = (void*)trackHolder;
@@ -140,57 +134,50 @@ void* BtifAvrcpAudioTrackCreate(int trackFreq, int bitsPerSample,
void BtifAvrcpAudioTrackStart(void* handle) {
if (handle == NULL) {
- LOG_ERROR("%s: handle is null!", __func__);
+ log::error("handle is null!");
return;
}
BtifAvrcpAudioTrack* trackHolder = static_cast<BtifAvrcpAudioTrack*>(handle);
CHECK(trackHolder != NULL);
CHECK(trackHolder->stream != NULL);
- LOG_VERBOSE("%s Track.cpp: btStartTrack", __func__);
+ log::verbose("Track.cpp: btStartTrack");
AAudioStream_requestStart(trackHolder->stream);
}
void BtifAvrcpAudioTrackStop(void* handle) {
if (handle == NULL) {
- LOG_INFO("%s handle is null.", __func__);
+ log::info("handle is null.");
return;
}
BtifAvrcpAudioTrack* trackHolder = static_cast<BtifAvrcpAudioTrack*>(handle);
if (trackHolder != NULL && trackHolder->stream != NULL) {
- LOG_VERBOSE("%s Track.cpp: btStopTrack", __func__);
+ log::verbose("Track.cpp: btStopTrack");
AAudioStream_requestStop(trackHolder->stream);
}
}
void BtifAvrcpAudioTrackDelete(void* handle) {
if (handle == NULL) {
- LOG_INFO("%s handle is null.", __func__);
+ log::info("handle is null.");
return;
}
BtifAvrcpAudioTrack* trackHolder = static_cast<BtifAvrcpAudioTrack*>(handle);
if (trackHolder != NULL && trackHolder->stream != NULL) {
- LOG_VERBOSE("%s Track.cpp: btStartTrack", __func__);
+ log::verbose("Track.cpp: btStartTrack");
AAudioStream_close(trackHolder->stream);
delete trackHolder->buffer;
delete trackHolder;
}
-
-#if (DUMP_PCM_DATA == TRUE)
- if (outputPcmSampleFile) {
- fclose(outputPcmSampleFile);
- }
- outputPcmSampleFile = NULL;
-#endif
}
void BtifAvrcpAudioTrackPause(void* handle) {
if (handle == NULL) {
- LOG_INFO("%s handle is null.", __func__);
+ log::info("handle is null.");
return;
}
BtifAvrcpAudioTrack* trackHolder = static_cast<BtifAvrcpAudioTrack*>(handle);
if (trackHolder != NULL && trackHolder->stream != NULL) {
- LOG_VERBOSE("%s Track.cpp: btPauseTrack", __func__);
+ log::verbose("Track.cpp: btPauseTrack");
AAudioStream_requestPause(trackHolder->stream);
AAudioStream_requestFlush(trackHolder->stream);
}
@@ -198,18 +185,18 @@ void BtifAvrcpAudioTrackPause(void* handle) {
void BtifAvrcpSetAudioTrackGain(void* handle, float gain) {
if (handle == NULL) {
- LOG_INFO("%s handle is null.", __func__);
+ log::info("handle is null.");
return;
}
BtifAvrcpAudioTrack* trackHolder = static_cast<BtifAvrcpAudioTrack*>(handle);
if (trackHolder != NULL) {
const float clampedGain = std::clamp(gain, kMinTrackGain, kMaxTrackGain);
if (clampedGain != gain) {
- LOG_WARN("Out of bounds gain set. Clamping the gain from :%f to %f", gain,
- clampedGain);
+ log::warn("Out of bounds gain set. Clamping the gain from :{:f} to {:f}",
+ gain, clampedGain);
}
trackHolder->gain = clampedGain;
- LOG_INFO("Avrcp audio track gain is set to %f", trackHolder->gain);
+ log::info("Avrcp audio track gain is set to {:f}", trackHolder->gain);
}
}
@@ -277,11 +264,6 @@ int BtifAvrcpAudioTrackWriteData(void* handle, void* audioBuffer,
CHECK(trackHolder != NULL);
CHECK(trackHolder->stream != NULL);
aaudio_result_t retval = -1;
-#if (DUMP_PCM_DATA == TRUE)
- if (outputPcmSampleFile) {
- fwrite((audioBuffer), 1, (size_t)bufferLength, outputPcmSampleFile);
- }
-#endif
size_t sampleSize = sampleSizeFor(trackHolder);
int transcodedCount = 0;
@@ -294,8 +276,8 @@ int BtifAvrcpAudioTrackWriteData(void* handle, void* audioBuffer,
trackHolder->stream, trackHolder->buffer,
transcodedCount / (sampleSize * trackHolder->channelCount),
kTimeoutNanos);
- LOG_VERBOSE("%s Track.cpp: btWriteData len = %d ret = %d", __func__,
- bufferLength, retval);
+ log::verbose("Track.cpp: btWriteData len = {} ret = {}", bufferLength,
+ retval);
} while (transcodedCount < bufferLength);
return transcodedCount;
diff --git a/system/btif/src/btif_bqr.cc b/system/btif/src/btif_bqr.cc
index 5ee7a9d44b..63e667daea 100644
--- a/system/btif/src/btif_bqr.cc
+++ b/system/btif/src/btif_bqr.cc
@@ -19,6 +19,7 @@
#ifdef __ANDROID__
#include <statslog_bt.h>
#endif
+#include <bluetooth/log.h>
#include <stdio.h>
#include <sys/stat.h>
@@ -58,10 +59,10 @@ std::unique_ptr<BluetoothQualityReportInterface> bluetoothQualityReportInstance;
void BqrVseSubEvt::ParseBqrLinkQualityEvt(uint8_t length,
const uint8_t* p_param_buf) {
if (length < kLinkQualityParamTotalLen) {
- LOG(FATAL) << __func__
- << ": Parameter total length: " << std::to_string(length)
- << " is abnormal. It shall be not shorter than: "
- << std::to_string(kLinkQualityParamTotalLen);
+ log::fatal(
+ "Parameter total length: {} is abnormal. It shall be not shorter than: "
+ "{}",
+ length, kLinkQualityParamTotalLen);
return;
}
@@ -91,17 +92,13 @@ void BqrVseSubEvt::ParseBqrLinkQualityEvt(uint8_t length,
if (vendor_cap_supported_version >= kBqrVersion5_0) {
if (length < kLinkQualityParamTotalLen + kISOLinkQualityParamTotalLen +
kVersion5_0ParamsTotalLen) {
- LOG(WARNING) << __func__
- << ": Parameter total length: " << std::to_string(length)
- << " is abnormal. "
- << "vendor_cap_supported_version: "
- << vendor_cap_supported_version << " "
- << " (>= "
- << "kBqrVersion5_0=" << kBqrVersion5_0 << "), "
- << "It should not be shorter than: "
- << std::to_string(kLinkQualityParamTotalLen +
- kISOLinkQualityParamTotalLen +
- kVersion5_0ParamsTotalLen);
+ log::warn(
+ "Parameter total length: {} is abnormal. "
+ "vendor_cap_supported_version: {} (>= kBqrVersion5_0={}), It should "
+ "not be shorter than: {}",
+ length, vendor_cap_supported_version, kBqrVersion5_0,
+ kLinkQualityParamTotalLen + kISOLinkQualityParamTotalLen +
+ kVersion5_0ParamsTotalLen);
} else {
STREAM_TO_BDADDR(bqr_link_quality_event_.bdaddr, p_param_buf);
STREAM_TO_UINT8(bqr_link_quality_event_.cal_failed_item_count,
@@ -111,16 +108,12 @@ void BqrVseSubEvt::ParseBqrLinkQualityEvt(uint8_t length,
if (vendor_cap_supported_version >= kBqrIsoVersion) {
if (length < kLinkQualityParamTotalLen + kISOLinkQualityParamTotalLen) {
- LOG(WARNING) << __func__
- << ": Parameter total length: " << std::to_string(length)
- << " is abnormal. "
- << "vendor_cap_supported_version: "
- << vendor_cap_supported_version << " "
- << " (>= "
- << "kBqrIsoVersion=" << kBqrIsoVersion << "), "
- << "It should not be shorter than: "
- << std::to_string(kLinkQualityParamTotalLen +
- kISOLinkQualityParamTotalLen);
+ log::warn(
+ "Parameter total length: {} is abnormal. "
+ "vendor_cap_supported_version: {} (>= kBqrIsoVersion={}), It should "
+ "not be shorter than: {}",
+ length, vendor_cap_supported_version, kBqrIsoVersion,
+ kLinkQualityParamTotalLen + kISOLinkQualityParamTotalLen);
} else {
STREAM_TO_UINT32(bqr_link_quality_event_.tx_total_packets, p_param_buf);
STREAM_TO_UINT32(bqr_link_quality_event_.tx_unacked_packets, p_param_buf);
@@ -313,7 +306,7 @@ std::string PacketTypeToString(uint8_t packet_type) {
}
void EnableBtQualityReport(bool is_enable) {
- LOG(INFO) << __func__ << ": is_enable: " << logbool(is_enable);
+ log::info("is_enable: {}", logbool(is_enable));
char bqr_prop_evtmask[PROPERTY_VALUE_MAX] = {0};
char bqr_prop_interval_ms[PROPERTY_VALUE_MAX] = {0};
@@ -325,9 +318,10 @@ void EnableBtQualityReport(bool is_enable) {
osi_property_get(kpPropertyVndTraceMask, bqr_prop_vnd_trace_mask, "");
if (strlen(bqr_prop_evtmask) == 0 || strlen(bqr_prop_interval_ms) == 0) {
- LOG(WARNING) << __func__ << ": Bluetooth Quality Report is disabled."
- << " bqr_prop_evtmask: " << bqr_prop_evtmask
- << ", bqr_prop_interval_ms: " << bqr_prop_interval_ms;
+ log::warn(
+ "Bluetooth Quality Report is disabled. bqr_prop_evtmask: {}, "
+ "bqr_prop_interval_ms: {}",
+ bqr_prop_evtmask, bqr_prop_interval_ms);
return;
}
@@ -355,11 +349,10 @@ void EnableBtQualityReport(bool is_enable) {
BTM_BleGetVendorCapabilities(&cmn_vsc_cb);
vendor_cap_supported_version = cmn_vsc_cb.version_supported;
- LOG(INFO) << __func__
- << ": Event Mask: " << loghex(bqr_config.quality_event_mask)
- << ", Interval: " << bqr_config.minimum_report_interval_ms
- << ", vendor_cap_supported_version: "
- << vendor_cap_supported_version;
+ log::info("Event Mask: {}, Interval: {}, vendor_cap_supported_version: {}",
+ loghex(bqr_config.quality_event_mask),
+ bqr_config.minimum_report_interval_ms,
+ vendor_cap_supported_version);
ConfigureBqr(bqr_config);
}
@@ -367,17 +360,16 @@ void ConfigureBqr(const BqrConfiguration& bqr_config) {
if (bqr_config.report_action > REPORT_ACTION_CLEAR ||
bqr_config.quality_event_mask > kQualityEventMaskAll ||
bqr_config.minimum_report_interval_ms > kMinReportIntervalMaxMs) {
- LOG(FATAL) << __func__ << ": Invalid Parameter"
- << ", Action: " << bqr_config.report_action
- << ", Mask: " << loghex(bqr_config.quality_event_mask)
- << ", Interval: " << bqr_config.minimum_report_interval_ms;
+ log::fatal("Invalid Parameter, Action: {}, Mask: {}, Interval: {}",
+ bqr_config.report_action, loghex(bqr_config.quality_event_mask),
+ bqr_config.minimum_report_interval_ms);
return;
}
- LOG(INFO) << __func__ << ": Action: "
- << loghex(static_cast<uint8_t>(bqr_config.report_action))
- << ", Mask: " << loghex(bqr_config.quality_event_mask)
- << ", Interval: " << bqr_config.minimum_report_interval_ms;
+ log::info("Action: {}, Mask: {}, Interval: {}",
+ loghex(static_cast<uint8_t>(bqr_config.report_action)),
+ loghex(bqr_config.quality_event_mask),
+ bqr_config.minimum_report_interval_ms);
uint8_t param[sizeof(BqrConfiguration)];
uint8_t* p_param = param;
@@ -395,8 +387,7 @@ void ConfigureBqr(const BqrConfiguration& bqr_config) {
void BqrVscCompleteCallback(tBTM_VSC_CMPL* p_vsc_cmpl_params) {
if (p_vsc_cmpl_params->param_len < 1) {
- LOG(ERROR) << __func__
- << ": The length of returned parameters is less than 1";
+ log::error("The length of returned parameters is less than 1");
return;
}
@@ -412,8 +403,7 @@ void BqrVscCompleteCallback(tBTM_VSC_CMPL* p_vsc_cmpl_params) {
// Vendor_Specific_Trace_Mask | 4 octets | vendor trace bit mask setting
STREAM_TO_UINT8(status, p_event_param_buf);
if (status != HCI_SUCCESS) {
- LOG(ERROR) << __func__
- << ": Fail to configure BQR. status: " << loghex(status);
+ log::error("Fail to configure BQR. status: {}", loghex(status));
return;
}
@@ -422,9 +412,8 @@ void BqrVscCompleteCallback(tBTM_VSC_CMPL* p_vsc_cmpl_params) {
}
if (p_vsc_cmpl_params->param_len != command_complete_param_len) {
- LOG(FATAL) << __func__
- << ": The length of returned parameters is incorrect: "
- << std::to_string(p_vsc_cmpl_params->param_len);
+ log::fatal("The length of returned parameters is incorrect: {}",
+ p_vsc_cmpl_params->param_len);
return;
}
@@ -436,10 +425,9 @@ void BqrVscCompleteCallback(tBTM_VSC_CMPL* p_vsc_cmpl_params) {
STREAM_TO_UINT32(current_vnd_trace_mask, p_event_param_buf);
}
- LOG(INFO) << __func__
- << ", current event mask: " << loghex(current_quality_event_mask)
- << ", vendor quality: " << loghex(current_vnd_quality_mask)
- << ", vendor trace: " << loghex(current_vnd_trace_mask);
+ log::info("current event mask: {}, vendor quality: {}, vendor trace: {}",
+ loghex(current_quality_event_mask),
+ loghex(current_vnd_quality_mask), loghex(current_vnd_trace_mask));
ConfigureBqrCmpl(current_quality_event_mask);
}
@@ -457,8 +445,8 @@ void ConfigBqrA2dpScoThreshold() {
sscanf(bqr_prop_threshold, "%hu,%hu", &a2dp_choppy_threshold,
&sco_choppy_threshold);
- LOG_WARN("a2dp_choppy_threshold: %d, sco_choppy_threshold: %d",
- a2dp_choppy_threshold, sco_choppy_threshold);
+ log::warn("a2dp_choppy_threshold: {}, sco_choppy_threshold: {}",
+ a2dp_choppy_threshold, sco_choppy_threshold);
UINT8_TO_STREAM(p_param, sub_opcode);
@@ -483,7 +471,7 @@ void ConfigBqrA2dpScoThreshold() {
}
void ConfigureBqrCmpl(uint32_t current_evt_mask) {
- LOG(INFO) << __func__ << ": current_evt_mask: " << loghex(current_evt_mask);
+ log::info("current_evt_mask: {}", loghex(current_evt_mask));
// (Un)Register for VSE of Bluetooth Quality Report sub event
tBTM_STATUS btm_status = BTM_BT_Quality_Report_VSE_Register(
current_evt_mask > kQualityEventMaskAllOff, CategorizeBqrEvent);
@@ -495,20 +483,20 @@ void ConfigureBqrCmpl(uint32_t current_evt_mask) {
}
if (btm_status != BTM_SUCCESS) {
- LOG(ERROR) << __func__ << ": Fail to (un)register VSE of BQR sub event."
- << " status: " << btm_status;
+ log::error("Fail to (un)register VSE of BQR sub event. status: {}",
+ btm_status);
return;
}
if (LmpLlMessageTraceLogFd != INVALID_FD &&
(current_evt_mask & kQualityEventMaskLmpMessageTrace) == 0) {
- LOG(INFO) << __func__ << ": Closing LMP/LL log file.";
+ log::info("Closing LMP/LL log file.");
close(LmpLlMessageTraceLogFd);
LmpLlMessageTraceLogFd = INVALID_FD;
}
if (BtSchedulingTraceLogFd != INVALID_FD &&
(current_evt_mask & kQualityEventMaskBtSchedulingTrace) == 0) {
- LOG(INFO) << __func__ << ": Closing Scheduling log file.";
+ log::info("Closing Scheduling log file.");
close(BtSchedulingTraceLogFd);
BtSchedulingTraceLogFd = INVALID_FD;
}
@@ -516,7 +504,7 @@ void ConfigureBqrCmpl(uint32_t current_evt_mask) {
void CategorizeBqrEvent(uint8_t length, const uint8_t* p_bqr_event) {
if (length == 0) {
- LOG(WARNING) << __func__ << ": Lengths of all of the parameters are zero.";
+ log::warn("Lengths of all of the parameters are zero.");
return;
}
@@ -529,10 +517,10 @@ void CategorizeBqrEvent(uint8_t length, const uint8_t* p_bqr_event) {
case QUALITY_REPORT_ID_LE_AUDIO_CHOPPY:
case QUALITY_REPORT_ID_CONNECT_FAIL:
if (length < kLinkQualityParamTotalLen) {
- LOG(FATAL) << __func__
- << ": Parameter total length: " << std::to_string(length)
- << " is abnormal. It shall be not shorter than: "
- << std::to_string(kLinkQualityParamTotalLen);
+ log::fatal(
+ "Parameter total length: {} is abnormal. It shall be not shorter "
+ "than: {}",
+ length, kLinkQualityParamTotalLen);
return;
}
@@ -547,12 +535,11 @@ void CategorizeBqrEvent(uint8_t length, const uint8_t* p_bqr_event) {
case QUALITY_REPORT_ID_BT_SCHEDULING_TRACE:
case QUALITY_REPORT_ID_CONTROLLER_DBG_INFO:
case QUALITY_REPORT_ID_VENDOR_SPECIFIC_TRACE:
- LOG(WARNING) << __func__
- << ": Unexpected ID: " << loghex(quality_report_id);
+ log::warn("Unexpected ID: {}", loghex(quality_report_id));
break;
default:
- LOG(WARNING) << __func__ << ": Unknown ID: " << loghex(quality_report_id);
+ log::warn("Unknown ID: {}", loghex(quality_report_id));
break;
}
}
@@ -564,7 +551,7 @@ void AddLinkQualityEventToQueue(uint8_t length,
p_bqr_event->ParseBqrLinkQualityEvt(length, p_link_quality_event);
- LOG(WARNING) << *p_bqr_event;
+ log::warn("{}", *p_bqr_event);
GetInterfaceToProfiles()->events->invoke_link_quality_report_cb(
bluetooth::common::time_get_os_boottime_ms(),
p_bqr_event->bqr_link_quality_event_.quality_report_id,
@@ -597,8 +584,7 @@ void AddLinkQualityEventToQueue(uint8_t length,
p_bqr_event->bqr_link_quality_event_.buffer_overflow_bytes,
p_bqr_event->bqr_link_quality_event_.buffer_underflow_bytes);
if (ret < 0) {
- LOG(WARNING) << __func__ << ": failed to log BQR event to statsd, error "
- << ret;
+ log::warn("failed to log BQR event to statsd, error {}", ret);
}
#else
// TODO(abps) Metrics for non-Android build
@@ -623,11 +609,10 @@ void AddLinkQualityEventToQueue(uint8_t length,
bqrItf->bqr_delivery_event(bd_addr, (uint8_t*)p_link_quality_event,
length);
} else {
- LOG(WARNING) << __func__ << ": failed to deliver BQR, "
- << "bdaddr is empty";
+ log::warn("failed to deliver BQR, bdaddr is empty");
}
} else {
- LOG(WARNING) << __func__ << ": failed to deliver BQR, bqrItf is NULL";
+ log::warn("failed to deliver BQR, bqrItf is NULL");
}
}
@@ -650,9 +635,8 @@ void DumpLmpLlMessage(uint8_t length, const uint8_t* p_lmp_ll_message_event) {
int OpenLmpLlTraceLogFile() {
if (rename(kpLmpLlMessageTraceLogPath, kpLmpLlMessageTraceLastLogPath) != 0 &&
errno != ENOENT) {
- LOG(ERROR) << __func__ << ": Unable to rename '"
- << kpLmpLlMessageTraceLogPath << "' to '"
- << kpLmpLlMessageTraceLastLogPath << "' : " << strerror(errno);
+ log::error("Unable to rename '{}' to '{}' : {}", kpLmpLlMessageTraceLogPath,
+ kpLmpLlMessageTraceLastLogPath, strerror(errno));
}
mode_t prevmask = umask(0);
@@ -661,8 +645,8 @@ int OpenLmpLlTraceLogFile() {
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
umask(prevmask);
if (logfile_fd == INVALID_FD) {
- LOG(ERROR) << __func__ << ": Unable to open '" << kpLmpLlMessageTraceLogPath
- << "' : " << strerror(errno);
+ log::error("Unable to open '{}' : {}", kpLmpLlMessageTraceLogPath,
+ strerror(errno));
} else {
LmpLlMessageTraceCounter = 0;
}
@@ -685,9 +669,8 @@ void DumpBtScheduling(uint8_t length, const uint8_t* p_bt_scheduling_event) {
int OpenBtSchedulingTraceLogFile() {
if (rename(kpBtSchedulingTraceLogPath, kpBtSchedulingTraceLastLogPath) != 0 &&
errno != ENOENT) {
- LOG(ERROR) << __func__ << ": Unable to rename '"
- << kpBtSchedulingTraceLogPath << "' to '"
- << kpBtSchedulingTraceLastLogPath << "' : " << strerror(errno);
+ log::error("Unable to rename '{}' to '{}' : {}", kpBtSchedulingTraceLogPath,
+ kpBtSchedulingTraceLastLogPath, strerror(errno));
}
mode_t prevmask = umask(0);
@@ -696,8 +679,8 @@ int OpenBtSchedulingTraceLogFile() {
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
umask(prevmask);
if (logfile_fd == INVALID_FD) {
- LOG(ERROR) << __func__ << ": Unable to open '" << kpBtSchedulingTraceLogPath
- << "' : " << strerror(errno);
+ log::error("Unable to open '{}' : {}", kpBtSchedulingTraceLogPath,
+ strerror(errno));
} else {
BtSchedulingTraceCounter = 0;
}
@@ -767,7 +750,7 @@ class BluetoothQualityReportInterfaceImpl
~BluetoothQualityReportInterfaceImpl() override = default;
void init(BluetoothQualityReportCallbacks* callbacks) override {
- LOG_INFO("BluetoothQualityReportInterfaceImpl ");
+ log::info("BluetoothQualityReportInterfaceImpl");
this->callbacks = callbacks;
}
@@ -775,7 +758,7 @@ class BluetoothQualityReportInterfaceImpl
const uint8_t* bqr_raw_data,
uint32_t bqr_raw_data_len) override {
if (bqr_raw_data == NULL) {
- LOG_ERROR("bqr data is null");
+ log::error("bqr data is null");
return;
}
@@ -800,13 +783,13 @@ class BluetoothQualityReportInterfaceImpl
uint16_t manufacturer_id = 0;
btif_get_remote_version(bd_addr, lmp_ver, manufacturer_id, lmp_subver);
- LOG_INFO(
- "len: %d, addr: %s, lmp_ver: %d, manufacturer_id: %d, lmp_subver: %d",
+ log::info(
+ "len: {}, addr: {}, lmp_ver: {}, manufacturer_id: {}, lmp_subver: {}",
bqr_raw_data_len, ADDRESS_TO_LOGGABLE_CSTR(bd_addr), lmp_ver,
manufacturer_id, lmp_subver);
if (callbacks == nullptr) {
- LOG_ERROR("callbacks is nullptr");
+ log::error("callbacks is nullptr");
return;
}
diff --git a/system/btif/src/btif_config.cc b/system/btif/src/btif_config.cc
index 9f304f8848..b3ea4a6396 100644
--- a/system/btif/src/btif_config.cc
+++ b/system/btif/src/btif_config.cc
@@ -21,6 +21,7 @@
#include "btif_config.h"
#include <base/logging.h>
+#include <bluetooth/log.h>
#include <openssl/rand.h>
#include <unistd.h>
@@ -54,6 +55,7 @@
using bluetooth::bluetooth_keystore::BluetoothKeystoreInterface;
using bluetooth::common::AddressObfuscator;
using bluetooth::common::MetricIdAllocator;
+using namespace bluetooth;
// Key attestation
static const std::string ENCRYPTED_STR = "encrypted";
@@ -84,25 +86,25 @@ static void read_or_set_metrics_salt() {
if (!btif_config_get_bin(BTIF_STORAGE_SECTION_METRICS,
BTIF_STORAGE_KEY_METRICS_SALT_256BIT,
metrics_salt.data(), &metrics_salt_length)) {
- LOG(WARNING) << __func__ << ": Failed to read metrics salt from config";
+ log::warn("Failed to read metrics salt from config");
// Invalidate salt
metrics_salt.fill(0);
}
if (metrics_salt_length != metrics_salt.size()) {
- LOG(ERROR) << __func__ << ": Metrics salt length incorrect, "
- << metrics_salt_length << " instead of " << metrics_salt.size();
+ log::error("Metrics salt length incorrect, {} instead of {}",
+ metrics_salt_length, metrics_salt.size());
// Invalidate salt
metrics_salt.fill(0);
}
if (!AddressObfuscator::IsSaltValid(metrics_salt)) {
- LOG(INFO) << __func__ << ": Metrics salt is invalid, creating new one";
+ log::info("Metrics salt is invalid, creating new one");
if (RAND_bytes(metrics_salt.data(), metrics_salt.size()) != 1) {
- LOG(FATAL) << __func__ << "Failed to generate salt for metrics";
+ log::fatal("Failed to generate salt for metrics");
}
if (!btif_config_set_bin(BTIF_STORAGE_SECTION_METRICS,
BTIF_STORAGE_KEY_METRICS_SALT_256BIT,
metrics_salt.data(), metrics_salt.size())) {
- LOG(FATAL) << __func__ << "Failed to write metrics salt to config";
+ log::fatal("Failed to write metrics salt to config");
}
}
AddressObfuscator::GetInstance()->Initialize(metrics_salt);
@@ -152,7 +154,7 @@ static void init_metric_id_allocator() {
if (!init_metric_id_allocator(paired_device_map,
std::move(save_device_callback),
std::move(forget_device_callback))) {
- LOG(FATAL) << __func__ << "Failed to initialize MetricIdAllocator";
+ log::fatal("Failed to initialize MetricIdAllocator");
}
// Add device_without_id
@@ -205,8 +207,7 @@ bool btif_get_device_clockoffset(const RawAddress& bda, int* p_clock_offset) {
p_clock_offset))
return false;
- LOG_DEBUG("%s: Device [%s] clock_offset %d", __func__, bd_addr_str,
- *p_clock_offset);
+ log::debug("Device [{}] clock_offset {}", bd_addr_str, *p_clock_offset);
return true;
}
@@ -219,8 +220,7 @@ bool btif_set_device_clockoffset(const RawAddress& bda, int clock_offset) {
clock_offset))
return false;
- LOG_DEBUG("%s: Device [%s] clock_offset %d", __func__, bd_addr_str,
- clock_offset);
+ log::debug("Device [{}] clock_offset {}", bd_addr_str, clock_offset);
return true;
}
diff --git a/system/btif/src/btif_config_cache.cc b/system/btif/src/btif_config_cache.cc
index c8f03cda71..05b1beca39 100644
--- a/system/btif/src/btif_config_cache.cc
+++ b/system/btif/src/btif_config_cache.cc
@@ -17,6 +17,7 @@
#include "btif_config_cache.h"
#include <base/logging.h>
+#include <bluetooth/log.h>
#include <limits>
#include <unordered_set>
@@ -25,6 +26,8 @@
#include "storage/config_keys.h"
#include "types/raw_address.h"
+using namespace bluetooth;
+
namespace {
const std::unordered_set<std::string> kLinkKeyTypes = {
@@ -67,7 +70,7 @@ bool trim_new_line(std::string& value) {
BtifConfigCache::BtifConfigCache(size_t capacity)
: unpaired_devices_cache_(capacity, "bt_config_cache") {
- LOG(INFO) << __func__ << ", capacity: " << capacity;
+ log::info("capacity: {}", capacity);
}
BtifConfigCache::~BtifConfigCache() { Clear(); }
@@ -178,11 +181,11 @@ void BtifConfigCache::SetString(std::string section_name, std::string key,
trim_new_line(key);
trim_new_line(value);
if (section_name.empty()) {
- LOG(FATAL) << "Empty section not allowed";
+ log::fatal("Empty section not allowed");
return;
}
if (key.empty()) {
- LOG(FATAL) << "Empty key not allowed";
+ log::fatal("Empty key not allowed");
return;
}
if (!paired_devices_list_.Has(section_name)) {
@@ -214,7 +217,7 @@ void BtifConfigCache::SetString(std::string section_name, std::string key,
// already have section in paired device list, add key-value entry.
auto section_found = paired_devices_list_.Find(section_name);
if (section_found == paired_devices_list_.sections.end()) {
- LOG(WARNING) << __func__ << " , section_found not found!";
+ log::warn("section_found not found!");
return;
}
section_found->Set(key, value);
@@ -258,13 +261,14 @@ std::optional<int> BtifConfigCache::GetInt(const std::string& section_name,
char* endptr;
long ret_long = strtol(value->c_str(), &endptr, 0);
if (*endptr != '\0') {
- LOG(WARNING) << "Failed to parse value to long for section " << section_name
- << ", key " << key;
+ log::warn("Failed to parse value to long for section {}, key {}",
+ section_name, key);
return std::nullopt;
}
if (ret_long >= std::numeric_limits<int>::max()) {
- LOG(WARNING) << "Integer overflow when parsing value to int for section "
- << section_name << ", key " << key;
+ log::warn(
+ "Integer overflow when parsing value to int for section {}, key {}",
+ section_name, key);
return std::nullopt;
}
return static_cast<int>(ret_long);
@@ -284,8 +288,8 @@ std::optional<uint64_t> BtifConfigCache::GetUint64(
char* endptr;
uint64_t ret = strtoull(value->c_str(), &endptr, 0);
if (*endptr != '\0') {
- LOG(WARNING) << "Failed to parse value to uint64 for section "
- << section_name << ", key " << key;
+ log::warn("Failed to parse value to uint64 for section {}, key {}",
+ section_name, key);
return std::nullopt;
}
return ret;
@@ -308,7 +312,7 @@ std::optional<bool> BtifConfigCache::GetBool(const std::string& section_name,
if (*value == "false") {
return false;
}
- LOG(WARNING) << "Failed to parse value to boolean for section "
- << section_name << ", key " << key;
+ log::warn("Failed to parse value to boolean for section {}, key {}",
+ section_name, key);
return std::nullopt;
}
diff --git a/system/btif/src/btif_core.cc b/system/btif/src/btif_core.cc
index 349722007b..9afbd01ec9 100644
--- a/system/btif/src/btif_core.cc
+++ b/system/btif/src/btif_core.cc
@@ -28,10 +28,13 @@
#define LOG_TAG "bt_btif_core"
+#include <android_bluetooth_flags.h>
+#include <android_bluetooth_sysprop.h>
#include <base/at_exit.h>
#include <base/functional/bind.h>
#include <base/logging.h>
#include <base/threading/platform_thread.h>
+#include <bluetooth/log.h>
#include <signal.h>
#include <sys/types.h>
@@ -68,6 +71,7 @@
using base::PlatformThread;
using bluetooth::Uuid;
using bluetooth::common::MessageLoopThread;
+using namespace bluetooth;
/*******************************************************************************
* Constants & Macros
@@ -154,11 +158,11 @@ void btif_init_ok() {
*
******************************************************************************/
bt_status_t btif_init_bluetooth() {
- LOG_INFO("%s entered", __func__);
+ log::info("entered");
exit_manager = new base::AtExitManager();
jni_thread_startup();
GetInterfaceToProfiles()->events->invoke_thread_evt_cb(ASSOCIATE_JVM);
- LOG_INFO("%s finished", __func__);
+ log::info("finished");
return BT_STATUS_SUCCESS;
}
@@ -190,8 +194,8 @@ void btif_enable_bluetooth_evt() {
strcmp(bdstr.c_str(), val) != 0) {
// We failed to get an address or the one in the config file does not match
// the address given by the controller interface. Update the config cache
- LOG_INFO("Storing '%s' into the config file",
- ADDRESS_TO_LOGGABLE_CSTR(local_bd_addr));
+ log::info("Storing '{}' into the config file",
+ ADDRESS_TO_LOGGABLE_CSTR(local_bd_addr));
btif_config_set_str(BTIF_STORAGE_SECTION_ADAPTER, BTIF_STORAGE_KEY_ADDRESS,
bdstr.c_str());
@@ -214,13 +218,30 @@ void btif_enable_bluetooth_evt() {
GetInterfaceToProfiles()->onBluetoothEnabled();
- /* load did configuration */
- bte_load_did_conf(BTE_DID_CONF_FILE);
+ if (!IS_FLAG_ENABLED(load_did_config_from_sysprops)) {
+ bte_load_did_conf(BTE_DID_CONF_FILE);
+ } else {
+ tSDP_DI_RECORD record = {
+ .vendor = uint16_t(
+ GET_SYSPROP(DeviceIDProperties, vendor_id, LMP_COMPID_GOOGLE)),
+ .vendor_id_source = uint16_t(GET_SYSPROP(
+ DeviceIDProperties, vendor_id_source, DI_VENDOR_ID_SOURCE_BTSIG)),
+ .product = uint16_t(GET_SYSPROP(DeviceIDProperties, product_id, 0)),
+ .primary_record = true,
+ };
+
+ uint32_t record_handle;
+ tBTA_STATUS status = BTA_DmSetLocalDiRecord(&record, &record_handle);
+ if (status != BTA_SUCCESS) {
+ log::error("unable to set device ID record error {}.",
+ bta_status_text(status));
+ }
+ }
btif_dm_load_local_oob();
future_ready(stack_manager_get_hack_future(), FUTURE_SUCCESS);
- LOG_INFO("Bluetooth enable event completed");
+ log::info("Bluetooth enable event completed");
}
/*******************************************************************************
@@ -234,7 +255,7 @@ void btif_enable_bluetooth_evt() {
******************************************************************************/
bt_status_t btif_cleanup_bluetooth() {
- LOG_INFO("%s entered", __func__);
+ log::info("entered");
btif_dm_cleanup();
GetInterfaceToProfiles()->events->invoke_thread_evt_cb(DISASSOCIATE_JVM);
btif_queue_release();
@@ -242,7 +263,7 @@ bt_status_t btif_cleanup_bluetooth() {
delete exit_manager;
exit_manager = nullptr;
btif_dut_mode = 0;
- LOG_INFO("%s finished", __func__);
+ log::info("finished");
return BT_STATUS_SUCCESS;
}
@@ -255,7 +276,7 @@ bt_status_t btif_cleanup_bluetooth() {
*
******************************************************************************/
void btif_dut_mode_configure(uint8_t enable) {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
btif_dut_mode = enable;
if (enable == 1) {
@@ -274,7 +295,7 @@ void btif_dut_mode_configure(uint8_t enable) {
*
******************************************************************************/
void btif_dut_mode_send(uint16_t opcode, uint8_t* buf, uint8_t len) {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
/* For now nothing to be done. */
BTM_VendorSpecificCommand(opcode, len, buf, [](tBTM_VSC_CMPL*) {});
}
@@ -401,7 +422,8 @@ static bt_status_t btif_in_get_remote_device_properties(RawAddress* bd_addr) {
}
static void btif_core_storage_adapter_write(bt_property_t* prop) {
- LOG_VERBOSE("type: %d, len %d, 0x%p", prop->type, prop->len, prop->val);
+ log::verbose("type: {}, len {}, {}", prop->type, prop->len,
+ fmt::ptr(prop->val));
bt_status_t status = btif_storage_set_adapter_property(prop);
GetInterfaceToProfiles()->events->invoke_adapter_properties_cb(status, 1,
prop);
@@ -427,7 +449,7 @@ void btif_remote_properties_evt(bt_status_t status, RawAddress* remote_addr,
******************************************************************************/
void btif_get_adapter_properties(void) {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
btif_in_get_adapter_properties();
}
@@ -441,7 +463,7 @@ void btif_get_adapter_properties(void) {
******************************************************************************/
void btif_get_adapter_property(bt_property_type_t type) {
- LOG_VERBOSE("%s %d", __func__, type);
+ log::verbose("{}", type);
bt_status_t status = BT_STATUS_SUCCESS;
char buf[512];
@@ -518,7 +540,7 @@ void btif_get_adapter_property(bt_property_type_t type) {
prop.len = sizeof(bt_dynamic_audio_buffer_item_t);
if (GetInterfaceToProfiles()->config->isA2DPOffloadEnabled() == false) {
- LOG_VERBOSE("%s Get buffer millis for A2DP software encoding", __func__);
+ log::verbose("Get buffer millis for A2DP software encoding");
for (int i = 0; i < CODEC_TYPE_NUMBER; i++) {
dynamic_audio_buffer_item.dab_item[i] = {
.default_buffer_time = DEFAULT_BUFFER_TIME,
@@ -528,7 +550,7 @@ void btif_get_adapter_property(bt_property_type_t type) {
memcpy(prop.val, &dynamic_audio_buffer_item, prop.len);
} else {
if (cmn_vsc_cb.dynamic_audio_buffer_support != 0) {
- LOG_VERBOSE("%s Get buffer millis for A2DP Offload", __func__);
+ log::verbose("Get buffer millis for A2DP Offload");
tBTM_BT_DYNAMIC_AUDIO_BUFFER_CB
bt_dynamic_audio_buffer_cb[CODEC_TYPE_NUMBER];
BTM_BleGetDynamicAudioBuffer(bt_dynamic_audio_buffer_cb);
@@ -544,7 +566,7 @@ void btif_get_adapter_property(bt_property_type_t type) {
}
memcpy(prop.val, &dynamic_audio_buffer_item, prop.len);
} else {
- LOG_VERBOSE("%s Don't support Dynamic Audio Buffer", __func__);
+ log::verbose("Don't support Dynamic Audio Buffer");
}
}
} else {
@@ -576,8 +598,8 @@ bt_property_t* property_deep_copy(const bt_property_t* prop) {
******************************************************************************/
void btif_set_adapter_property(bt_property_t* property) {
- LOG_VERBOSE("btif_set_adapter_property type: %d, len %d, 0x%p",
- property->type, property->len, property->val);
+ log::verbose("btif_set_adapter_property type: {}, len {}, {}", property->type,
+ property->len, fmt::ptr(property->val));
switch (property->type) {
case BT_PROPERTY_BDNAME: {
@@ -588,7 +610,7 @@ void btif_set_adapter_property(bt_property_t* property) {
memcpy(bd_name, property->val, name_len);
bd_name[name_len] = '\0';
- LOG_VERBOSE("set property name : %s", (char*)bd_name);
+ log::verbose("set property name : {}", (char*)bd_name);
BTA_DmSetDeviceName((const char*)bd_name);
@@ -597,7 +619,7 @@ void btif_set_adapter_property(bt_property_t* property) {
case BT_PROPERTY_ADAPTER_SCAN_MODE: {
bt_scan_mode_t mode = *(bt_scan_mode_t*)property->val;
- LOG_VERBOSE("set property scan mode : %x", mode);
+ log::verbose("set property scan mode : {:x}", mode);
if (BTA_DmSetVisibility(mode)) {
btif_core_storage_adapter_write(property);
@@ -692,7 +714,7 @@ tBTA_SERVICE_MASK btif_get_enabled_services_mask(void) {
void btif_enable_service(tBTA_SERVICE_ID service_id) {
btif_enabled_services |= (1 << service_id);
- LOG_VERBOSE("%s: current services:0x%x", __func__, btif_enabled_services);
+ log::verbose("current services:0x{:x}", btif_enabled_services);
if (btif_is_enabled()) {
btif_dm_enable_service(service_id, true);
@@ -710,7 +732,7 @@ void btif_enable_service(tBTA_SERVICE_ID service_id) {
void btif_disable_service(tBTA_SERVICE_ID service_id) {
btif_enabled_services &= (tBTA_SERVICE_MASK)(~(1 << service_id));
- LOG_VERBOSE("%s: Current Services:0x%x", __func__, btif_enabled_services);
+ log::verbose("Current Services:0x{:x}", btif_enabled_services);
if (btif_is_enabled()) {
btif_dm_enable_service(service_id, false);
@@ -718,24 +740,23 @@ void btif_disable_service(tBTA_SERVICE_ID service_id) {
}
bt_status_t btif_set_dynamic_audio_buffer_size(int codec, int size) {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
tBTM_BLE_VSC_CB cmn_vsc_cb;
BTM_BleGetVendorCapabilities(&cmn_vsc_cb);
if (!GetInterfaceToProfiles()->config->isA2DPOffloadEnabled()) {
- LOG_VERBOSE("%s Set buffer size (%d) for A2DP software encoding", __func__,
- size);
+ log::verbose("Set buffer size ({}) for A2DP software encoding", size);
GetInterfaceToProfiles()
->profileSpecific_HACK->btif_av_set_dynamic_audio_buffer_size(
uint8_t(size));
} else {
if (cmn_vsc_cb.dynamic_audio_buffer_support != 0) {
- LOG_VERBOSE("%s Set buffer size (%d) for A2DP offload", __func__, size);
+ log::verbose("Set buffer size ({}) for A2DP offload", size);
uint16_t firmware_tx_buffer_length_byte;
firmware_tx_buffer_length_byte = static_cast<uint16_t>(size);
- LOG(INFO) << __func__ << "firmware_tx_buffer_length_byte: "
- << firmware_tx_buffer_length_byte;
+ log::info("firmware_tx_buffer_length_byte: {}",
+ firmware_tx_buffer_length_byte);
bluetooth::shim::GetController()->SetDabAudioBufferTime(
firmware_tx_buffer_length_byte);
}
diff --git a/system/btif/src/btif_csis_client.cc b/system/btif/src/btif_csis_client.cc
index 70271286d1..387a8c2d1f 100644
--- a/system/btif/src/btif_csis_client.cc
+++ b/system/btif/src/btif_csis_client.cc
@@ -18,6 +18,7 @@
#include <base/functional/bind.h>
#include <base/location.h>
#include <base/logging.h>
+#include <bluetooth/log.h>
#include <hardware/bluetooth.h>
#include <hardware/bt_csis.h>
@@ -37,6 +38,7 @@ using bluetooth::csis::CsisClientInterface;
using bluetooth::csis::CsisGroupLockStatus;
using bluetooth::csis::CsisClient;
+using namespace bluetooth;
namespace {
std::unique_ptr<CsisClientInterface> csis_client_instance;
@@ -62,9 +64,9 @@ class CsipSetCoordinatorServiceInterfaceImpl : public CsisClientInterface,
void Connect(const RawAddress& addr) override {
if (!initialized || !CsisClient::IsCsisClientRunning()) {
- VLOG(1) << __func__
- << " call ignored, due to already started cleanup procedure or "
- "service being not read";
+ log::verbose(
+ "call ignored, due to already started cleanup procedure or service "
+ "being not read");
return;
}
@@ -74,9 +76,9 @@ class CsipSetCoordinatorServiceInterfaceImpl : public CsisClientInterface,
void Disconnect(const RawAddress& addr) override {
if (!initialized || !CsisClient::IsCsisClientRunning()) {
- VLOG(1) << __func__
- << " call ignored, due to already started cleanup procedure or "
- "service being not read";
+ log::verbose(
+ "call ignored, due to already started cleanup procedure or service "
+ "being not read");
return;
}
@@ -86,9 +88,9 @@ class CsipSetCoordinatorServiceInterfaceImpl : public CsisClientInterface,
void RemoveDevice(const RawAddress& addr) override {
if (!initialized || !CsisClient::IsCsisClientRunning()) {
- VLOG(1) << __func__
- << " call ignored, due to already started cleanup procedure or "
- "service being not ready";
+ log::verbose(
+ "call ignored, due to already started cleanup procedure or service "
+ "being not ready");
/* Clear storage */
do_in_jni_thread(FROM_HERE, Bind(&btif_storage_remove_csis_device, addr));
@@ -103,9 +105,9 @@ class CsipSetCoordinatorServiceInterfaceImpl : public CsisClientInterface,
void LockGroup(int group_id, bool lock) override {
if (!initialized || !CsisClient::IsCsisClientRunning()) {
- VLOG(1) << __func__
- << " call ignored, due to already started cleanup procedure or "
- "service being not read";
+ log::verbose(
+ "call ignored, due to already started cleanup procedure or service "
+ "being not read");
return;
}
@@ -116,9 +118,9 @@ class CsipSetCoordinatorServiceInterfaceImpl : public CsisClientInterface,
void Cleanup(void) override {
if (!initialized || !CsisClient::IsCsisClientRunning()) {
- VLOG(1) << __func__
- << " call ignored, due to already started cleanup procedure or "
- "service being not read";
+ log::verbose(
+ "call ignored, due to already started cleanup procedure or service "
+ "being not read");
return;
}
diff --git a/system/btif/src/btif_dm.cc b/system/btif/src/btif_dm.cc
index af393d7a00..100d9d905f 100644
--- a/system/btif/src/btif_dm.cc
+++ b/system/btif/src/btif_dm.cc
@@ -26,7 +26,6 @@
*
******************************************************************************/
-#include "bt_dev_class.h"
#define LOG_TAG "bt_btif_dm"
#include "btif_dm.h"
@@ -35,6 +34,7 @@
#include <base/functional/bind.h>
#include <base/logging.h>
#include <base/strings/stringprintf.h>
+#include <bluetooth/log.h>
#include <bluetooth/uuid.h>
#include <hardware/bluetooth.h>
#include <hardware/bt_csis.h>
@@ -53,6 +53,7 @@
#include <optional>
#include "advertise_data_parser.h"
+#include "bt_dev_class.h"
#include "bta/dm/bta_dm_disc.h"
#include "bta/include/bta_api.h"
#include "btif/include/stack_manager_t.h"
@@ -106,6 +107,7 @@
bool btif_get_device_type(const RawAddress& bda, int* p_device_type);
using bluetooth::Uuid;
+using namespace bluetooth;
namespace {
constexpr char kBtmLogTag[] = "API";
@@ -177,6 +179,12 @@ struct btif_dm_pairing_cb_t {
ServiceDiscoveryState sdp_over_classic;
};
+namespace fmt {
+template <>
+struct formatter<btif_dm_pairing_cb_t::ServiceDiscoveryState>
+ : enum_formatter<btif_dm_pairing_cb_t::ServiceDiscoveryState> {};
+} // namespace fmt
+
// TODO(jpawlowski): unify ?
// btif_dm_local_key_id_t == tBTM_BLE_LOCAL_ID_KEYS == tBTA_BLE_LOCAL_ID_KEYS
typedef struct {
@@ -318,7 +326,7 @@ void btif_dm_cleanup(void) {
bt_status_t btif_in_execute_service_request(tBTA_SERVICE_ID service_id,
bool b_enable) {
- LOG_VERBOSE("service_id:%d", service_id);
+ log::verbose("service_id:{}", service_id);
if (service_id == BTA_SDP_SERVICE_ID) {
btif_sdp_execute_service(b_enable);
@@ -359,15 +367,15 @@ static void get_asha_service_data(const tBTA_DM_INQ_RES& inq_res,
STREAM_TO_UINT16(uuid, p_uuid);
if (uuid == 0xfdf0 /* ASHA service*/) {
- LOG_INFO("ASHA found in %s", ADDRESS_TO_LOGGABLE_CSTR(bdaddr));
+ log::info("ASHA found in {}", ADDRESS_TO_LOGGABLE_CSTR(bdaddr));
// ASHA advertisement service data length should be at least 8
if (service_data_len < 8) {
- LOG_WARN("ASHA device service_data_len too short");
+ log::warn("ASHA device service_data_len too short");
} else {
// It is intended to save ASHA capability byte to int16_t
asha_capability = p_service_data[3];
- LOG_INFO("asha_capability: %d", asha_capability);
+ log::info("asha_capability: {}", asha_capability);
const uint8_t* p_truncated_hisyncid = &(p_service_data[4]);
STREAM_TO_UINT32(asha_truncated_hi_sync_id, p_truncated_hisyncid);
@@ -495,7 +503,7 @@ static uint32_t get_cod(const RawAddress* remote_bdaddr) {
sizeof(uint32_t), &remote_cod);
if (btif_storage_get_remote_device_property(
(RawAddress*)remote_bdaddr, &prop_name) == BT_STATUS_SUCCESS) {
- LOG_INFO("remote_cod=0x%08x", remote_cod);
+ log::info("remote_cod=0x{:08x}", remote_cod);
return remote_cod;
}
@@ -580,9 +588,9 @@ static void bond_state_changed(bt_status_t status, const RawAddress& bd_addr,
state = BT_BOND_STATE_NONE;
}
- LOG_INFO(
- "Bond state changed to state=%d[0:none, 1:bonding, 2:bonded],"
- "prev_state=%d, sdp_attempts=%d",
+ log::info(
+ "Bond state changed to state={}[0:none, 1:bonding, "
+ "2:bonded],prev_state={}, sdp_attempts={}",
state, pairing_cb.state, pairing_cb.sdp_attempts);
if (state == BT_BOND_STATE_NONE) {
@@ -597,8 +605,8 @@ static void bond_state_changed(bt_status_t status, const RawAddress& bd_addr,
} else if (state == BT_BOND_STATE_BONDED) {
allocate_metric_id_from_metric_id_allocator(bd_addr);
if (!save_metric_id_from_metric_id_allocator(bd_addr)) {
- LOG_ERROR("Fail to save metric id for device:%s",
- ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
+ log::error("Fail to save metric id for device:{}",
+ ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
}
}
BTM_LogHistory(
@@ -613,8 +621,10 @@ static void bond_state_changed(bt_status_t status, const RawAddress& bd_addr,
if ((state == BT_BOND_STATE_NONE) && (pairing_cb.bd_addr != bd_addr)
&& is_bonding_or_sdp()) {
- LOG_WARN("Ignoring bond state changed for unexpected device: %s pairing: %s",
- ADDRESS_TO_LOGGABLE_CSTR(bd_addr), ADDRESS_TO_LOGGABLE_CSTR(pairing_cb.bd_addr));
+ log::warn(
+ "Ignoring bond state changed for unexpected device: {} pairing: {}",
+ ADDRESS_TO_LOGGABLE_CSTR(bd_addr),
+ ADDRESS_TO_LOGGABLE_CSTR(pairing_cb.bd_addr));
return;
}
@@ -627,7 +637,7 @@ static void bond_state_changed(bt_status_t status, const RawAddress& bd_addr,
pairing_cb.state = state;
pairing_cb.bd_addr = bd_addr;
} else {
- LOG_DEBUG("clearing btif pairing_cb");
+ log::debug("clearing btif pairing_cb");
pairing_cb = {};
}
}
@@ -647,9 +657,9 @@ static void btif_update_remote_version_property(RawAddress* p_bd) {
const bool version_info_valid =
BTM_ReadRemoteVersion(*p_bd, &lmp_ver, &mfct_set, &lmp_subver);
- LOG_INFO("Remote version info valid:%s [%s]:0x%x,0x%x,0x%x",
- logbool(version_info_valid).c_str(),
- ADDRESS_TO_LOGGABLE_CSTR((*p_bd)), lmp_ver, mfct_set, lmp_subver);
+ log::info("Remote version info valid:{} [{}]:0x{:x},0x{:x},0x{:x}",
+ logbool(version_info_valid), ADDRESS_TO_LOGGABLE_CSTR((*p_bd)),
+ lmp_ver, mfct_set, lmp_subver);
if (version_info_valid) {
// Always update cache to ensure we have availability whenever BTM API is
@@ -691,18 +701,18 @@ static void btif_update_remote_properties(const RawAddress& bdaddr,
cod = devclass2uint(dev_class);
if ((cod == 0) || (cod == COD_UNCLASSIFIED)) {
/* Try to retrieve cod from storage */
- LOG_VERBOSE("class of device (cod) is unclassified, checking storage");
+ log::verbose("class of device (cod) is unclassified, checking storage");
BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
BT_PROPERTY_CLASS_OF_DEVICE, sizeof(cod), &cod);
status = btif_storage_get_remote_device_property(
&bdaddr, &properties[num_properties]);
- LOG_VERBOSE("cod retrieved from storage is 0x%06x", cod);
+ log::verbose("cod retrieved from storage is 0x{:06x}", cod);
if (cod == 0) {
- LOG_INFO("cod from storage is also unclassified");
+ log::info("cod from storage is also unclassified");
cod = COD_UNCLASSIFIED;
}
} else {
- LOG_INFO("class of device (cod) is 0x%06x", cod);
+ log::info("class of device (cod) is 0x{:06x}", cod);
}
BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
@@ -817,7 +827,7 @@ static void btif_dm_cb_create_bond(const RawAddress bd_addr,
bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDING);
if (transport == BT_TRANSPORT_AUTO && is_device_le_audio_capable(bd_addr)) {
- LOG_DEBUG("LE Audio capable, forcing LE transport for Bonding");
+ log::debug("LE Audio capable, forcing LE transport for Bonding");
transport = BT_TRANSPORT_LE;
}
@@ -910,8 +920,8 @@ uint16_t btif_dm_get_connection_state(const RawAddress& bd_addr) {
rc |= ENCRYPTED_LE;
}
} else {
- LOG_INFO("Acl is not connected to peer:%s",
- ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
+ log::info("Acl is not connected to peer:{}",
+ ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
}
BTM_LogHistory(
@@ -1007,7 +1017,7 @@ static void btif_dm_pin_req_evt(tBTA_DM_PIN_REQ* p_pin_req) {
if (pairing_cb.state == BT_BOND_STATE_BONDING &&
bd_addr != pairing_cb.bd_addr) {
- LOG_WARN("already in bonding state, reject request");
+ log::warn("already in bonding state, reject request");
return;
}
@@ -1016,7 +1026,7 @@ static void btif_dm_pin_req_evt(tBTA_DM_PIN_REQ* p_pin_req) {
cod = devclass2uint(p_pin_req->dev_class);
if (cod == 0) {
- LOG_WARN("cod is 0, set as unclassified");
+ log::warn("cod is 0, set as unclassified");
cod = COD_UNCLASSIFIED;
}
@@ -1033,7 +1043,7 @@ static void btif_dm_pin_req_evt(tBTA_DM_PIN_REQ* p_pin_req) {
!interop_match_name(INTEROP_DISABLE_AUTO_PAIRING,
(const char*)bd_name.name) &&
(pairing_cb.autopair_attempts == 0)) {
- LOG_DEBUG("Attempting auto pair w/ IOP");
+ log::debug("Attempting auto pair w/ IOP");
pin_code.pin[0] = 0x30;
pin_code.pin[1] = 0x30;
pin_code.pin[2] = 0x30;
@@ -1048,7 +1058,7 @@ static void btif_dm_pin_req_evt(tBTA_DM_PIN_REQ* p_pin_req) {
if ((interop_match_addr(INTEROP_KEYBOARD_REQUIRES_FIXED_PIN, &bd_addr) ==
true) &&
(pairing_cb.autopair_attempts == 0)) {
- LOG_DEBUG("Attempting auto pair w/ IOP");
+ log::debug("Attempting auto pair w/ IOP");
pin_code.pin[0] = 0x30;
pin_code.pin[1] = 0x30;
pin_code.pin[2] = 0x30;
@@ -1083,10 +1093,10 @@ static void btif_dm_ssp_cfm_req_evt(tBTA_DM_SP_CFM_REQ* p_ssp_cfm_req) {
uint32_t cod;
int dev_type;
- LOG_VERBOSE("addr:%s, just_works:%d, loc_auth_req=%d, rmt_auth_req=%d",
- ADDRESS_TO_LOGGABLE_CSTR(p_ssp_cfm_req->bd_addr),
- p_ssp_cfm_req->just_works, p_ssp_cfm_req->loc_auth_req,
- p_ssp_cfm_req->rmt_auth_req);
+ log::verbose("addr:{}, just_works:{}, loc_auth_req={}, rmt_auth_req={}",
+ ADDRESS_TO_LOGGABLE_CSTR(p_ssp_cfm_req->bd_addr),
+ p_ssp_cfm_req->just_works, p_ssp_cfm_req->loc_auth_req,
+ p_ssp_cfm_req->rmt_auth_req);
/* Remote properties update */
if (BTM_GetPeerDeviceTypeFromFeatures(p_ssp_cfm_req->bd_addr) ==
BT_DEVICE_TYPE_DUMO) {
@@ -1104,7 +1114,7 @@ static void btif_dm_ssp_cfm_req_evt(tBTA_DM_SP_CFM_REQ* p_ssp_cfm_req) {
if (pairing_cb.state == BT_BOND_STATE_BONDING &&
bd_addr != pairing_cb.bd_addr) {
- LOG_WARN("already in bonding state, reject request");
+ log::warn("already in bonding state, reject request");
btif_dm_ssp_reply(bd_addr, BT_SSP_VARIANT_PASSKEY_CONFIRMATION, 0);
return;
}
@@ -1132,7 +1142,8 @@ static void btif_dm_ssp_cfm_req_evt(tBTA_DM_SP_CFM_REQ* p_ssp_cfm_req) {
* Incoming temporary pairing is detected
*/
if (is_incoming && pairing_cb.bond_type == BOND_TYPE_TEMPORARY) {
- LOG_DEBUG("Auto-accept JustWorks incoming pairing for temporary bonding");
+ log::debug(
+ "Auto-accept JustWorks incoming pairing for temporary bonding");
btif_dm_ssp_reply(bd_addr, BT_SSP_VARIANT_CONSENT, true);
return;
}
@@ -1141,7 +1152,7 @@ static void btif_dm_ssp_cfm_req_evt(tBTA_DM_SP_CFM_REQ* p_ssp_cfm_req) {
cod = devclass2uint(p_ssp_cfm_req->dev_class);
if (cod == 0) {
- LOG_WARN("cod is 0, set as unclassified");
+ log::warn("cod is 0, set as unclassified");
cod = COD_UNCLASSIFIED;
}
@@ -1163,7 +1174,7 @@ static void btif_dm_ssp_key_notif_evt(tBTA_DM_SP_KEY_NOTIF* p_ssp_key_notif) {
uint32_t cod;
int dev_type;
- LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_ssp_key_notif->bd_addr));
+ log::verbose("addr:{}", ADDRESS_TO_LOGGABLE_CSTR(p_ssp_key_notif->bd_addr));
/* Remote properties update */
if (BTM_GetPeerDeviceTypeFromFeatures(p_ssp_key_notif->bd_addr) ==
@@ -1186,7 +1197,7 @@ static void btif_dm_ssp_key_notif_evt(tBTA_DM_SP_KEY_NOTIF* p_ssp_key_notif) {
cod = devclass2uint(p_ssp_key_notif->dev_class);
if (cod == 0) {
- LOG_WARN("cod is 0, set as unclassified");
+ log::warn("cod is 0, set as unclassified");
cod = COD_UNCLASSIFIED;
}
@@ -1213,8 +1224,8 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
bt_bond_state_t state = BT_BOND_STATE_NONE;
bool skip_sdp = false;
- LOG_INFO("bond state=%d, success=%d, key_present=%d", pairing_cb.state,
- p_auth_cmpl->success, p_auth_cmpl->key_present);
+ log::info("bond state={}, success={}, key_present={}", pairing_cb.state,
+ p_auth_cmpl->success, p_auth_cmpl->key_present);
pairing_cb.fail_reason = p_auth_cmpl->fail_reason;
@@ -1229,21 +1240,21 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
bt_status_t ret;
if (!bd_addr.IsEmpty()) {
- LOG_DEBUG("Storing link key. key_type=0x%x, bond_type=%d",
- p_auth_cmpl->key_type, pairing_cb.bond_type);
+ log::debug("Storing link key. key_type=0x{:x}, bond_type={}",
+ p_auth_cmpl->key_type, pairing_cb.bond_type);
ret = btif_storage_add_bonded_device(&bd_addr, p_auth_cmpl->key,
p_auth_cmpl->key_type,
pairing_cb.pin_code_len);
} else {
- LOG_WARN("bd_addr is empty");
+ log::warn("bd_addr is empty");
ret = BT_STATUS_FAIL;
}
ASSERTC(ret == BT_STATUS_SUCCESS, "storing link key failed", ret);
} else {
- LOG_DEBUG("Temporary key. Not storing. key_type=0x%x, bond_type=%d",
- p_auth_cmpl->key_type, pairing_cb.bond_type);
+ log::debug("Temporary key. Not storing. key_type=0x{:x}, bond_type={}",
+ p_auth_cmpl->key_type, pairing_cb.bond_type);
if (pairing_cb.bond_type == BOND_TYPE_TEMPORARY) {
- LOG_DEBUG("sending BT_BOND_STATE_NONE for Temp pairing");
+ log::debug("sending BT_BOND_STATE_NONE for Temp pairing");
btif_storage_remove_bonded_device(&bd_addr);
bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_NONE);
return;
@@ -1264,8 +1275,8 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
// the derived link key.
if (p_auth_cmpl->bd_addr != pairing_cb.bd_addr &&
(!pairing_cb.ble.is_penc_key_rcvd)) {
- LOG_WARN("skipping SDP for unknown device %s",
- ADDRESS_TO_LOGGABLE_CSTR(p_auth_cmpl->bd_addr));
+ log::warn("skipping SDP for unknown device {}",
+ ADDRESS_TO_LOGGABLE_CSTR(p_auth_cmpl->bd_addr));
return;
}
@@ -1280,7 +1291,7 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
bool is_crosskey = false;
if (pairing_cb.state == BT_BOND_STATE_BONDING && p_auth_cmpl->is_ctkd) {
- LOG_DEBUG("bonding initiated due to cross key pairing");
+ log::debug("bonding initiated due to cross key pairing");
is_crosskey = true;
}
@@ -1295,13 +1306,13 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
bd_addr = p_auth_cmpl->bd_addr;
if (check_sdp_bl(&bd_addr) && check_cod_hid(&bd_addr)) {
- LOG_WARN("skip SDP");
+ log::warn("skip SDP");
skip_sdp = true;
}
if (!pairing_cb.is_local_initiated && skip_sdp) {
bond_state_changed(status, bd_addr, state);
- LOG_WARN("Incoming HID Connection");
+ log::warn("Incoming HID Connection");
bt_property_t prop;
Uuid uuid = Uuid::From16Bit(UUID_SERVCLASS_HUMAN_INTERFACE);
@@ -1314,7 +1325,7 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
} else {
/* If bonded due to cross-key, save the static address too*/
if (is_crosskey) {
- LOG_DEBUG("bonding initiated due to cross key, adding static address");
+ log::debug("bonding initiated due to cross key, adding static address");
pairing_cb.static_bdaddr = bd_addr;
}
if (!is_crosskey ||
@@ -1340,7 +1351,7 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
if (pairing_cb.sdp_over_classic ==
btif_dm_pairing_cb_t::ServiceDiscoveryState::NOT_STARTED) {
- LOG_INFO("scheduling SDP for %s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
+ log::info("scheduling SDP for {}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
pairing_cb.sdp_over_classic =
btif_dm_pairing_cb_t::ServiceDiscoveryState::SCHEDULED;
btif_dm_get_remote_services(bd_addr, BT_TRANSPORT_BR_EDR);
@@ -1350,8 +1361,8 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
// Do not call bond_state_changed_cb yet. Wait until remote service
// discovery is complete
} else {
- LOG_WARN("Bonding failed with failure reason:%s",
- hci_reason_code_text(p_auth_cmpl->fail_reason).c_str());
+ log::warn("Bonding failed with failure reason:{}",
+ hci_reason_code_text(p_auth_cmpl->fail_reason));
bool is_bonded_device_removed = false;
// Map the HCI fail reason to bt status
switch (p_auth_cmpl->fail_reason) {
@@ -1359,8 +1370,8 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
case HCI_ERR_LMP_RESPONSE_TIMEOUT:
if (interop_match_addr(INTEROP_AUTO_RETRY_PAIRING, &bd_addr) &&
pairing_cb.timeout_retries) {
- LOG_WARN("Pairing timeout; retrying (%d) ...",
- pairing_cb.timeout_retries);
+ log::warn("Pairing timeout; retrying ({}) ...",
+ pairing_cb.timeout_retries);
--pairing_cb.timeout_retries;
if (addr_type == BLE_ADDR_RANDOM) {
btif_dm_cb_create_bond_le(bd_addr, addr_type);
@@ -1391,11 +1402,11 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
case HCI_ERR_INSUFFCIENT_SECURITY:
case HCI_ERR_PEER_USER:
case HCI_ERR_UNSPECIFIED:
- LOG_WARN("Authentication fail:%s",
- hci_reason_code_text(p_auth_cmpl->fail_reason).c_str());
+ log::warn("Authentication fail:{}",
+ hci_reason_code_text(p_auth_cmpl->fail_reason));
if (pairing_cb.autopair_attempts == 1) {
/* Create the Bond once again */
- LOG_WARN("auto pair failed. Reinitiate Bond");
+ log::warn("auto pair failed. Reinitiate Bond");
if (addr_type == BLE_ADDR_RANDOM) {
btif_dm_cb_create_bond_le(bd_addr, addr_type);
} else {
@@ -1414,7 +1425,7 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
/* Special Handling for HID Devices */
if (check_cod_hid_major(bd_addr, COD_HID_POINTING)) {
/* Remove Device as bonded in nvram as authentication failed */
- LOG_VERBOSE("removing hid pointing device from nvram");
+ log::verbose("removing hid pointing device from nvram");
is_bonded_device_removed = false;
}
// Report bond state change to java only if we are bonding to a device or
@@ -1436,7 +1447,7 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
*****************************************************************************/
static void btif_dm_search_devices_evt(tBTA_DM_SEARCH_EVT event,
tBTA_DM_SEARCH* p_search_data) {
- LOG_VERBOSE("event=%s", dump_dm_search_event(event));
+ log::verbose("event={}", dump_dm_search_event(event));
switch (event) {
case BTA_DM_NAME_READ_EVT: {
@@ -1464,20 +1475,21 @@ static void btif_dm_search_devices_evt(tBTA_DM_SEARCH_EVT event,
BTIF_STORAGE_FILL_PROPERTY(&properties[2], BT_PROPERTY_CLASS_OF_DEVICE, sizeof(uint32_t), &cod);
if (btif_storage_get_remote_device_property(
&bdaddr, &properties[2]) == BT_STATUS_SUCCESS) {
- LOG_VERBOSE("BTA_DM_NAME_READ_EVT, cod in storage=0x%08x", cod);
+ log::verbose("BTA_DM_NAME_READ_EVT, cod in storage=0x{:08x}", cod);
} else {
- LOG_INFO("BTA_DM_NAME_READ_EVT, no cod in storage");
+ log::info("BTA_DM_NAME_READ_EVT, no cod in storage");
cod = 0;
}
if (cod != 0) {
BTIF_STORAGE_FILL_PROPERTY(&properties[1], BT_PROPERTY_BDADDR, sizeof(bdaddr), &bdaddr);
BTIF_STORAGE_FILL_PROPERTY(&properties[2], BT_PROPERTY_CLASS_OF_DEVICE, sizeof(uint32_t), &cod);
- LOG_DEBUG("report new device to JNI");
+ log::debug("report new device to JNI");
GetInterfaceToProfiles()->events->invoke_device_found_cb(3, properties);
} else {
- LOG_INFO("Skipping RNR callback because cod is zero addr:%s name:%s",
- ADDRESS_TO_LOGGABLE_CSTR(bdaddr),
- PRIVATE_NAME(p_search_data->disc_res.bd_name));
+ log::info("Skipping RNR callback because cod is zero addr:{} name:{}",
+ ADDRESS_TO_LOGGABLE_CSTR(bdaddr),
+ PRIVATE_NAME(reinterpret_cast<char const*>(
+ p_search_data->disc_res.bd_name)));
}
/** @} */
}
@@ -1497,8 +1509,9 @@ static void btif_dm_search_devices_evt(tBTA_DM_SEARCH_EVT event,
}
RawAddress& bdaddr = p_search_data->inq_res.bd_addr;
- LOG_VERBOSE("addr:%s device_type=0x%x", ADDRESS_TO_LOGGABLE_CSTR(bdaddr),
- p_search_data->inq_res.device_type);
+ log::verbose("addr:{} device_type=0x{:x}",
+ ADDRESS_TO_LOGGABLE_CSTR(bdaddr),
+ p_search_data->inq_res.device_type);
bdname.name[0] = 0;
if (!check_eir_remote_name(p_search_data, bdname.name, &remote_name_len))
@@ -1506,9 +1519,9 @@ static void btif_dm_search_devices_evt(tBTA_DM_SEARCH_EVT event,
/* Check EIR for services */
if (p_search_data->inq_res.p_eir) {
- BTM_GetEirUuidList(p_search_data->inq_res.p_eir,
- p_search_data->inq_res.eir_len, Uuid::kNumBytes16,
- &num_uuids, uuid_list, max_num_uuid);
+ get_btm_client_interface().eir.BTM_GetEirUuidList(
+ p_search_data->inq_res.p_eir, p_search_data->inq_res.eir_len,
+ Uuid::kNumBytes16, &num_uuids, uuid_list, max_num_uuid);
}
{
@@ -1534,7 +1547,7 @@ static void btif_dm_search_devices_evt(tBTA_DM_SEARCH_EVT event,
/* DEV_CLASS */
uint32_t cod = devclass2uint(p_search_data->inq_res.dev_class);
- LOG_VERBOSE("cod is 0x%06x", cod);
+ log::verbose("cod is 0x{:06x}", cod);
if (cod != 0) {
BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
BT_PROPERTY_CLASS_OF_DEVICE, sizeof(cod),
@@ -1542,8 +1555,8 @@ static void btif_dm_search_devices_evt(tBTA_DM_SEARCH_EVT event,
num_properties++;
}
- LOG_VERBOSE("clock_offset is 0x%x",
- p_search_data->inq_res.clock_offset);
+ log::verbose("clock_offset is 0x{:x}",
+ p_search_data->inq_res.clock_offset);
if (p_search_data->inq_res.clock_offset & BTM_CLOCK_OFFSET_VALID) {
btif_set_device_clockoffset(bdaddr, (int)p_search_data->inq_res.clock_offset);
}
@@ -1624,10 +1637,10 @@ static void btif_dm_search_devices_evt(tBTA_DM_SEARCH_EVT event,
auto triple = eir_uuids_cache.try_emplace(bdaddr, std::set<Uuid>{});
uuid_iter = std::get<0>(triple);
}
- LOG_INFO("EIR UUIDs for %s:", ADDRESS_TO_LOGGABLE_CSTR(bdaddr));
+ log::info("EIR UUIDs for {}:", ADDRESS_TO_LOGGABLE_CSTR(bdaddr));
for (int i = 0; i < num_uuids; ++i) {
Uuid uuid = Uuid::From16Bit(p_uuid16[i]);
- LOG_INFO(" %s", uuid.ToString().c_str());
+ log::info("{}", uuid.ToString());
uuid_iter->second.insert(uuid);
}
@@ -1668,8 +1681,8 @@ static void btif_dm_search_devices_evt(tBTA_DM_SEARCH_EVT event,
if (restrict_report &&
p_search_data->inq_res.device_type == BT_DEVICE_TYPE_BLE &&
!(p_search_data->inq_res.ble_evt_type & BTM_BLE_CONNECTABLE_MASK)) {
- LOG_DEBUG("Ble device %s is not connectable",
- ADDRESS_TO_LOGGABLE_CSTR(bdaddr));
+ log::debug("Ble device {} is not connectable",
+ ADDRESS_TO_LOGGABLE_CSTR(bdaddr));
break;
}
@@ -1705,7 +1718,7 @@ static void btif_dm_search_devices_evt(tBTA_DM_SEARCH_EVT event,
case BTA_DM_DID_RES_EVT:
case BTA_DM_GATT_OVER_SDP_RES_EVT:
default:
- LOG_WARN("Unhandled event:%s", bta_dm_search_evt_text(event).c_str());
+ log::warn("Unhandled event:{}", bta_dm_search_evt_text(event));
break;
}
}
@@ -1736,9 +1749,10 @@ static bool btif_is_gatt_service_discovery_post_pairing(const RawAddress bd_addr
if (bd_addr == pairing_cb.bd_addr || bd_addr == pairing_cb.static_bdaddr) {
if (pairing_cb.gatt_over_le !=
btif_dm_pairing_cb_t::ServiceDiscoveryState::SCHEDULED) {
- LOG_ERROR("gatt_over_le should be SCHEDULED, did someone clear the "
- "control block for %s ?",
- ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
+ log::error(
+ "gatt_over_le should be SCHEDULED, did someone clear the control "
+ "block for {} ?",
+ ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
}
return true;
@@ -1774,14 +1788,14 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
RawAddress& bd_addr = p_data->disc_res.bd_addr;
- LOG_VERBOSE("result=0x%x, services 0x%x", p_data->disc_res.result,
- p_data->disc_res.services);
+ log::verbose("result=0x{:x}, services 0x{:x}", p_data->disc_res.result,
+ p_data->disc_res.services);
if (p_data->disc_res.result != BTA_SUCCESS &&
pairing_cb.state == BT_BOND_STATE_BONDED &&
pairing_cb.sdp_attempts < BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING) {
if (pairing_cb.sdp_attempts) {
- LOG_WARN("SDP failed after bonding re-attempting for %s",
- ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
+ log::warn("SDP failed after bonding re-attempting for {}",
+ ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
pairing_cb.sdp_attempts++;
if (IS_FLAG_ENABLED(force_bredr_for_sdp_retry)) {
btif_dm_get_remote_services(bd_addr, BT_TRANSPORT_BR_EDR);
@@ -1789,14 +1803,14 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
btif_dm_get_remote_services(bd_addr, BT_TRANSPORT_AUTO);
}
} else {
- LOG_WARN("SDP triggered by someone failed when bonding");
+ log::warn("SDP triggered by someone failed when bonding");
}
return;
}
if ((bd_addr == pairing_cb.bd_addr ||
bd_addr == pairing_cb.static_bdaddr)) {
- LOG_INFO("SDP finished for %s:", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
+ log::info("SDP finished for {}:", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
pairing_cb.sdp_over_classic =
btif_dm_pairing_cb_t::ServiceDiscoveryState::FINISHED;
}
@@ -1805,13 +1819,13 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
prop.len = 0;
if ((p_data->disc_res.result == BTA_SUCCESS) &&
(p_data->disc_res.num_uuids > 0)) {
- LOG_INFO("New UUIDs for %s:", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
+ log::info("New UUIDs for {}:", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
for (i = 0; i < p_data->disc_res.num_uuids; i++) {
auto uuid = p_data->disc_res.p_uuid_list + i;
if (btif_should_ignore_uuid(*uuid)) {
continue;
}
- LOG_INFO("index:%d uuid:%s", i, uuid->ToString().c_str());
+ log::info("index:{} uuid:{}", i, uuid->ToString());
uuids.insert(*uuid);
}
@@ -1824,8 +1838,7 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
continue;
}
if (btif_is_interesting_le_service(uuid)) {
- LOG_INFO("interesting le service %s insert",
- uuid.ToString().c_str());
+ log::info("interesting le service {} insert", uuid.ToString());
uuids.insert(uuid);
}
}
@@ -1861,7 +1874,7 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
if (pairing_cb.state == BT_BOND_STATE_BONDED && pairing_cb.sdp_attempts &&
(p_data->disc_res.bd_addr == pairing_cb.bd_addr ||
p_data->disc_res.bd_addr == pairing_cb.static_bdaddr)) {
- LOG_INFO("SDP search done for %s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
+ log::info("SDP search done for {}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
pairing_cb.sdp_attempts = 0;
// Send UUIDs discovered through EIR to Java to unblock pairing intent
@@ -1870,8 +1883,8 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
auto uuids_iter = eir_uuids_cache.find(bd_addr);
if (uuids_iter != eir_uuids_cache.end()) {
num_eir_uuids = uuids_iter->second.size();
- LOG_INFO("SDP failed, send %zu EIR UUIDs to unblock bonding %s",
- num_eir_uuids, ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
+ log::info("SDP failed, send {} EIR UUIDs to unblock bonding {}",
+ num_eir_uuids, ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
for (auto eir_uuid : uuids_iter->second) {
auto uuid_128bit = eir_uuid.To128BitBE();
property_value.insert(property_value.end(), uuid_128bit.begin(),
@@ -1883,7 +1896,7 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
prop.val = (void*)property_value.data();
prop.len = num_eir_uuids * Uuid::kNumBytes128;
} else {
- LOG_WARN("SDP failed and we have no EIR UUIDs to report either");
+ log::warn("SDP failed and we have no EIR UUIDs to report either");
prop.val = &uuid;
prop.len = Uuid::kNumBytes128;
}
@@ -1893,7 +1906,7 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
// Both SDP and bonding are done, clear pairing control block in case
// it is not already cleared
pairing_cb = {};
- LOG_DEBUG("clearing btif pairing_cb");
+ log::debug("clearing btif pairing_cb");
}
}
@@ -1912,9 +1925,9 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
ret);
if (skip_reporting_wait_for_le) {
- LOG_INFO(
- "Bonding LE Audio sink - must wait for le services discovery "
- "to pass all services to java %s",
+ log::info(
+ "Bonding LE Audio sink - must wait for le services discovery to "
+ "pass all services to java {}",
ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
/* For LE Audio capable devices, we care more about passing GATT LE
* services than about just finishing pairing. Service discovery
@@ -1949,8 +1962,8 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
is_le_audio_capable_during_service_discovery(bd_addr);
if (event == BTA_DM_GATT_OVER_LE_RES_EVT) {
- LOG_INFO("New GATT over LE UUIDs for %s:",
- ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
+ log::info("New GATT over LE UUIDs for {}:",
+ ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
BTM_LogHistory(kBtmLogTag, bd_addr,
"Discovered GATT services using LE transport");
if (btif_is_gatt_service_discovery_post_pairing(bd_addr)) {
@@ -1961,15 +1974,15 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
btif_dm_pairing_cb_t::ServiceDiscoveryState::SCHEDULED) {
// Both SDP and bonding are either done, or not scheduled,
// we are safe to clear the service discovery part of CB.
- LOG_DEBUG("clearing pairing_cb");
+ log::debug("clearing pairing_cb");
pairing_cb = {};
}
if (IS_FLAG_ENABLED(le_audio_fast_bond_params) && lea_supported) {
/* LE Audio profile should relax parameters when it connects. If
* profile is not enabled, relax parameters after timeout. */
- LOG_DEBUG("Scheduling conn params unlock for %s",
- ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
+ log::debug("Scheduling conn params unlock for {}",
+ ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
do_in_main_thread_delayed(
FROM_HERE,
base::BindOnce(
@@ -1982,8 +1995,8 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
}
}
} else {
- LOG_DEBUG("New GATT over SDP UUIDs for %s:",
- ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
+ log::debug("New GATT over SDP UUIDs for {}:",
+ ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
BTM_LogHistory(kBtmLogTag, bd_addr,
"Discovered GATT services using SDP transport");
}
@@ -1993,14 +2006,14 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
if (btif_should_ignore_uuid(uuid)) {
continue;
}
- LOG_INFO("index:%d uuid:%s", static_cast<int>(uuids.size()),
- uuid.ToString().c_str());
+ log::info("index:{} uuid:{}", static_cast<int>(uuids.size()),
+ uuid.ToString());
uuids.insert(uuid);
}
}
if (uuids.empty()) {
- LOG_INFO("No well known GATT services discovered");
+ log::info("No well known GATT services discovered");
/* If services were returned as part of SDP discovery, we will
* immediately send them with rest of SDP results in BTA_DM_DISC_RES_EVT
@@ -2012,18 +2025,18 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
if (lea_supported) {
if (bluetooth::common::init_flags::
sdp_return_classic_services_when_le_discovery_fails_is_enabled()) {
- LOG_INFO(
+ log::info(
"Will return Classic SDP results, if done, to unblock bonding");
} else {
// LEA device w/o this flag
// TODO: we might want to remove bond or do some action on
// half-discovered device
- LOG_WARN("No GATT service found for the LE Audio device %s",
- ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
+ log::warn("No GATT service found for the LE Audio device {}",
+ ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
return;
}
} else {
- LOG_INFO("LE audio not supported, no need to report any UUIDs");
+ log::info("LE audio not supported, no need to report any UUIDs");
return;
}
}
@@ -2035,8 +2048,8 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
btif_get_existing_uuids(&bd_addr, existing_uuids);
if (existing_lookup_result != BT_STATUS_FAIL) {
- LOG_INFO("Got some existing UUIDs by address %s",
- ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
+ log::info("Got some existing UUIDs by address {}",
+ ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
for (int i = 0; i < BT_MAX_NUM_UUIDS; i++) {
Uuid uuid = existing_uuids[i];
@@ -2052,8 +2065,8 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
existing_lookup_result =
btif_get_existing_uuids(&static_addr_copy, existing_uuids);
if (existing_lookup_result != BT_STATUS_FAIL) {
- LOG_INFO("Got some existing UUIDs by static address %s",
- ADDRESS_TO_LOGGABLE_CSTR(static_addr_copy));
+ log::info("Got some existing UUIDs by static address {}",
+ ADDRESS_TO_LOGGABLE_CSTR(static_addr_copy));
for (int i = 0; i < BT_MAX_NUM_UUIDS; i++) {
Uuid uuid = existing_uuids[i];
if (uuid.IsEmpty()) {
@@ -2130,14 +2143,14 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
if (IS_FLAG_ENABLED(rnr_present_during_service_discovery)) {
const tBTA_DM_DISC_RES& disc_res = p_data->disc_res;
if (disc_res.hci_status != HCI_SUCCESS) {
- LOG_WARN("Received RNR event with bad status addr:%s hci_status:%s",
- ADDRESS_TO_LOGGABLE_CSTR(disc_res.bd_addr),
- hci_error_code_text(disc_res.hci_status).c_str());
+ log::warn("Received RNR event with bad status addr:{} hci_status:{}",
+ ADDRESS_TO_LOGGABLE_CSTR(disc_res.bd_addr),
+ hci_error_code_text(disc_res.hci_status));
break;
}
if (disc_res.bd_name[0] == '\0') {
- LOG_WARN("Received RNR event without valid name addr:%s",
- ADDRESS_TO_LOGGABLE_CSTR(disc_res.bd_addr));
+ log::warn("Received RNR event without valid name addr:{}",
+ ADDRESS_TO_LOGGABLE_CSTR(disc_res.bd_addr));
break;
}
bt_property_t properties[] = {{
@@ -2153,11 +2166,12 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
const size_t num_props = sizeof(properties) / sizeof(bt_property_t);
GetInterfaceToProfiles()->events->invoke_remote_device_properties_cb(
status, disc_res.bd_addr, (int)num_props, properties);
- LOG_INFO("Callback for read name event addr:%s name:%s",
- ADDRESS_TO_LOGGABLE_CSTR(disc_res.bd_addr),
- PRIVATE_NAME(disc_res.bd_name));
+ log::info(
+ "Callback for read name event addr:{} name:{}",
+ ADDRESS_TO_LOGGABLE_CSTR(disc_res.bd_addr),
+ PRIVATE_NAME(reinterpret_cast<char const*>(disc_res.bd_name)));
} else {
- LOG_INFO("Skipping name read event - called on bad callback.");
+ log::info("Skipping name read event - called on bad callback.");
}
} break;
@@ -2172,14 +2186,14 @@ static void btif_dm_update_allowlisted_media_players() {
bt_property_t wlplayers_prop;
list_t* wl_players = list_new(nullptr);
if (!wl_players) {
- LOG_ERROR("Unable to allocate space for allowlist players");
+ log::error("Unable to allocate space for allowlist players");
return;
}
- LOG_DEBUG("btif_dm_update_allowlisted_media_players");
+ log::debug("btif_dm_update_allowlisted_media_players");
wlplayers_prop.len = 0;
if (!interop_get_allowlisted_media_players_list(wl_players)) {
- LOG_DEBUG("Allowlisted media players not found");
+ log::debug("Allowlisted media players not found");
list_free(wl_players);
return;
}
@@ -2242,7 +2256,7 @@ void BTIF_dm_enable() {
bool ble_privacy_enabled =
osi_property_get_bool(PROPERTY_BLE_PRIVACY_ENABLED, /*default=*/true);
- LOG_INFO("Local BLE Privacy enabled:%d", ble_privacy_enabled);
+ log::info("Local BLE Privacy enabled:{}", ble_privacy_enabled);
BTA_DmBleConfigLocalPrivacy(ble_privacy_enabled);
/* for each of the enabled services in the mask, trigger the profile
@@ -2279,7 +2293,7 @@ void BTIF_dm_disable() {
}
}
bluetooth::bqr::EnableBtQualityReport(false);
- LOG_INFO("Stack device manager shutdown finished");
+ log::info("Stack device manager shutdown finished");
future_ready(stack_manager_get_hack_future(), FUTURE_SUCCESS);
}
@@ -2295,7 +2309,7 @@ void BTIF_dm_disable() {
void btif_dm_sec_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC* p_data) {
RawAddress bd_addr;
- LOG_VERBOSE("ev:%s", dump_dm_event(event));
+ log::verbose("ev:{}", dump_dm_event(event));
switch (event) {
case BTA_DM_PIN_REQ_EVT:
@@ -2332,8 +2346,8 @@ void btif_dm_sec_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC* p_data) {
break;
case BTA_DM_BLE_KEY_EVT:
- LOG_VERBOSE("BTA_DM_BLE_KEY_EVT key_type=0x%02x ",
- p_data->ble_key.key_type);
+ log::verbose("BTA_DM_BLE_KEY_EVT key_type=0x{:02x}",
+ p_data->ble_key.key_type);
/* If this pairing is by-product of local initiated GATT client Read or
Write,
@@ -2342,93 +2356,94 @@ void btif_dm_sec_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC* p_data) {
have setup properly. Setup pairing_cb and notify App about Bonding state
now*/
if (pairing_cb.state != BT_BOND_STATE_BONDING) {
- LOG_VERBOSE("Bond state not sent to App so far.Notify the app now");
+ log::verbose("Bond state not sent to App so far.Notify the app now");
bond_state_changed(BT_STATUS_SUCCESS, p_data->ble_key.bd_addr,
BT_BOND_STATE_BONDING);
} else if (pairing_cb.bd_addr != p_data->ble_key.bd_addr) {
- LOG_ERROR("BD mismatch discard BLE key_type=%d ",
- p_data->ble_key.key_type);
+ log::error("BD mismatch discard BLE key_type={}",
+ p_data->ble_key.key_type);
break;
}
switch (p_data->ble_key.key_type) {
case BTM_LE_KEY_PENC:
- LOG_VERBOSE("Rcv BTM_LE_KEY_PENC");
+ log::verbose("Rcv BTM_LE_KEY_PENC");
pairing_cb.ble.is_penc_key_rcvd = true;
pairing_cb.ble.penc_key = p_data->ble_key.p_key_value->penc_key;
break;
case BTM_LE_KEY_PID:
- LOG_VERBOSE("Rcv BTM_LE_KEY_PID");
+ log::verbose("Rcv BTM_LE_KEY_PID");
pairing_cb.ble.is_pid_key_rcvd = true;
pairing_cb.ble.pid_key = p_data->ble_key.p_key_value->pid_key;
break;
case BTM_LE_KEY_PCSRK:
- LOG_VERBOSE("Rcv BTM_LE_KEY_PCSRK");
+ log::verbose("Rcv BTM_LE_KEY_PCSRK");
pairing_cb.ble.is_pcsrk_key_rcvd = true;
pairing_cb.ble.pcsrk_key = p_data->ble_key.p_key_value->pcsrk_key;
break;
case BTM_LE_KEY_LENC:
- LOG_VERBOSE("Rcv BTM_LE_KEY_LENC");
+ log::verbose("Rcv BTM_LE_KEY_LENC");
pairing_cb.ble.is_lenc_key_rcvd = true;
pairing_cb.ble.lenc_key = p_data->ble_key.p_key_value->lenc_key;
break;
case BTM_LE_KEY_LCSRK:
- LOG_VERBOSE("Rcv BTM_LE_KEY_LCSRK");
+ log::verbose("Rcv BTM_LE_KEY_LCSRK");
pairing_cb.ble.is_lcsrk_key_rcvd = true;
pairing_cb.ble.lcsrk_key = p_data->ble_key.p_key_value->lcsrk_key;
break;
case BTM_LE_KEY_LID:
- LOG_VERBOSE("Rcv BTM_LE_KEY_LID");
+ log::verbose("Rcv BTM_LE_KEY_LID");
pairing_cb.ble.is_lidk_key_rcvd = true;
break;
default:
- LOG_ERROR("unknown BLE key type (0x%02x)", p_data->ble_key.key_type);
+ log::error("unknown BLE key type (0x{:02x})",
+ p_data->ble_key.key_type);
break;
}
break;
case BTA_DM_BLE_CONSENT_REQ_EVT:
- LOG_VERBOSE("BTA_DM_BLE_CONSENT_REQ_EVT");
+ log::verbose("BTA_DM_BLE_CONSENT_REQ_EVT");
btif_dm_ble_sec_req_evt(&p_data->ble_req, true);
break;
case BTA_DM_BLE_SEC_REQ_EVT:
- LOG_VERBOSE("BTA_DM_BLE_SEC_REQ_EVT");
+ log::verbose("BTA_DM_BLE_SEC_REQ_EVT");
btif_dm_ble_sec_req_evt(&p_data->ble_req, false);
break;
case BTA_DM_BLE_PASSKEY_NOTIF_EVT:
- LOG_VERBOSE("BTA_DM_BLE_PASSKEY_NOTIF_EVT");
+ log::verbose("BTA_DM_BLE_PASSKEY_NOTIF_EVT");
btif_dm_ble_key_notif_evt(&p_data->key_notif);
break;
case BTA_DM_BLE_PASSKEY_REQ_EVT:
- LOG_VERBOSE("BTA_DM_BLE_PASSKEY_REQ_EVT");
+ log::verbose("BTA_DM_BLE_PASSKEY_REQ_EVT");
btif_dm_ble_passkey_req_evt(&p_data->pin_req);
break;
case BTA_DM_BLE_NC_REQ_EVT:
- LOG_VERBOSE("BTA_DM_BLE_PASSKEY_REQ_EVT");
+ log::verbose("BTA_DM_BLE_PASSKEY_REQ_EVT");
btif_dm_ble_key_nc_req_evt(&p_data->key_notif);
break;
case BTA_DM_BLE_OOB_REQ_EVT:
- LOG_VERBOSE("BTA_DM_BLE_OOB_REQ_EVT");
+ log::verbose("BTA_DM_BLE_OOB_REQ_EVT");
btif_dm_ble_oob_req_evt(&p_data->rmt_oob);
break;
case BTA_DM_BLE_SC_OOB_REQ_EVT:
- LOG_VERBOSE("BTA_DM_BLE_SC_OOB_REQ_EVT");
+ log::verbose("BTA_DM_BLE_SC_OOB_REQ_EVT");
btif_dm_ble_sc_oob_req_evt(&p_data->rmt_oob);
break;
case BTA_DM_BLE_SC_CR_LOC_OOB_EVT:
- LOG_VERBOSE("BTA_DM_BLE_SC_CR_LOC_OOB_EVT");
+ log::verbose("BTA_DM_BLE_SC_CR_LOC_OOB_EVT");
btif_dm_proc_loc_oob(BT_TRANSPORT_LE, true,
p_data->local_oob_data.local_oob_c,
p_data->local_oob_data.local_oob_r);
break;
case BTA_DM_BLE_LOCAL_IR_EVT:
- LOG_VERBOSE("BTA_DM_BLE_LOCAL_IR_EVT");
+ log::verbose("BTA_DM_BLE_LOCAL_IR_EVT");
ble_local_key_cb.is_id_keys_rcvd = true;
ble_local_key_cb.id_keys.irk = p_data->ble_id_keys.irk;
ble_local_key_cb.id_keys.ir = p_data->ble_id_keys.ir;
@@ -2441,7 +2456,7 @@ void btif_dm_sec_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC* p_data) {
BTIF_DM_LE_LOCAL_KEY_DHK);
break;
case BTA_DM_BLE_LOCAL_ER_EVT:
- LOG_VERBOSE("BTA_DM_BLE_LOCAL_ER_EVT");
+ log::verbose("BTA_DM_BLE_LOCAL_ER_EVT");
ble_local_key_cb.is_er_rcvd = true;
ble_local_key_cb.er = p_data->ble_er;
btif_storage_add_ble_local_key(ble_local_key_cb.er,
@@ -2449,7 +2464,7 @@ void btif_dm_sec_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC* p_data) {
break;
case BTA_DM_BLE_AUTH_CMPL_EVT:
- LOG_VERBOSE("BTA_DM_BLE_AUTH_CMPL_EVT");
+ log::verbose("BTA_DM_BLE_AUTH_CMPL_EVT");
btif_dm_ble_auth_cmpl_evt(&p_data->auth_cmpl);
break;
@@ -2469,7 +2484,7 @@ void btif_dm_sec_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC* p_data) {
break;
default:
- LOG_WARN("unhandled event(%d)", event);
+ log::warn("unhandled event({})", event);
break;
}
}
@@ -2489,7 +2504,7 @@ void btif_dm_acl_evt(tBTA_DM_ACL_EVT event, tBTA_DM_ACL* p_data) {
switch (event) {
case BTA_DM_LINK_UP_EVT:
bd_addr = p_data->link_up.bd_addr;
- LOG_VERBOSE("BTA_DM_LINK_UP_EVT. Sending BT_ACL_STATE_CONNECTED");
+ log::verbose("BTA_DM_LINK_UP_EVT. Sending BT_ACL_STATE_CONNECTED");
btif_update_remote_version_property(&bd_addr);
@@ -2544,13 +2559,12 @@ void btif_dm_acl_evt(tBTA_DM_ACL_EVT event, tBTA_DM_ACL* p_data) {
(int)p_data->link_down.transport_link_type,
static_cast<bt_hci_error_code_t>(btm_get_acl_disc_reason_code()),
direction, INVALID_ACL_HANDLE);
- LOG_DEBUG(
+ log::debug(
"Sent BT_ACL_STATE_DISCONNECTED upward as ACL link down event "
- "device:%s reason:%s",
+ "device:{} reason:{}",
ADDRESS_TO_LOGGABLE_CSTR(bd_addr),
hci_reason_code_text(
- static_cast<tHCI_REASON>(btm_get_acl_disc_reason_code()))
- .c_str());
+ static_cast<tHCI_REASON>(btm_get_acl_disc_reason_code())));
} break;
case BTA_DM_LE_FEATURES_READ:
btif_get_adapter_property(BT_PROPERTY_LOCAL_LE_FEATURES);
@@ -2558,7 +2572,7 @@ void btif_dm_acl_evt(tBTA_DM_ACL_EVT event, tBTA_DM_ACL* p_data) {
default: {
- LOG_ERROR("Unexpected tBTA_DM_ACL_EVT:%d", event);
+ log::error("Unexpected tBTA_DM_ACL_EVT:{}", event);
} break;
}
@@ -2579,9 +2593,9 @@ static void bta_energy_info_cb(tBTM_BLE_TX_TIME_MS tx_time,
tBTM_BLE_ENERGY_USED energy_used,
tBTM_CONTRL_STATE ctrl_state,
tBTA_STATUS status) {
- LOG_VERBOSE(
- "energy_info_cb-Status:%d,state=%d,tx_t=%u, rx_t=%u, "
- "idle_time=%u,used=%u",
+ log::verbose(
+ "energy_info_cb-Status:{},state={},tx_t={}, rx_t={}, "
+ "idle_time={},used={}",
status, ctrl_state, tx_time, rx_time, idle_time, energy_used);
if (uid_set != nullptr) {
@@ -2596,7 +2610,7 @@ static void bta_energy_info_cb(tBTM_BLE_TX_TIME_MS tx_time,
bt_uid_traffic_t* data = uid_set_read_and_clear(uid_set);
GetInterfaceToProfiles()->events->invoke_energy_info_cb(energy_info, data);
} else {
- LOG_WARN("Energy info event dropped as module is inactive");
+ log::warn("Energy info event dropped as module is inactive");
}
}
@@ -2614,7 +2628,7 @@ static void bta_energy_info_cb(tBTM_BLE_TX_TIME_MS tx_time,
*
******************************************************************************/
void btif_dm_start_discovery(void) {
- LOG_VERBOSE("start device discover/inquiry");
+ log::verbose("start device discover/inquiry");
BTM_LogHistory(
kBtmLogTag, RawAddress::kEmpty, "Device discovery",
@@ -2623,7 +2637,7 @@ void btif_dm_start_discovery(void) {
/* no race here because we're guaranteed to be in the main thread */
if (bta_dm_is_search_request_queued()) {
- LOG_INFO("skipping start discovery because a request is queued");
+ log::info("skipping start discovery because a request is queued");
return;
}
@@ -2642,7 +2656,7 @@ void btif_dm_start_discovery(void) {
*
******************************************************************************/
void btif_dm_cancel_discovery(void) {
- LOG_INFO("Cancel search");
+ log::info("Cancel search");
BTM_LogHistory(kBtmLogTag, RawAddress::kEmpty, "Cancel discovery");
BTA_DmSearchCancel();
@@ -2660,8 +2674,8 @@ bool btif_dm_pairing_is_busy() {
*
******************************************************************************/
void btif_dm_create_bond(const RawAddress bd_addr, int transport) {
- LOG_VERBOSE("bd_addr=%s, transport=%d", ADDRESS_TO_LOGGABLE_CSTR(bd_addr),
- transport);
+ log::verbose("bd_addr={}, transport={}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr),
+ transport);
BTM_LogHistory(
kBtmLogTag, bd_addr, "Create bond",
@@ -2683,8 +2697,8 @@ void btif_dm_create_bond(const RawAddress bd_addr, int transport) {
******************************************************************************/
void btif_dm_create_bond_le(const RawAddress bd_addr,
tBLE_ADDR_TYPE addr_type) {
- LOG_VERBOSE("bd_addr=%s, addr_type=%d", ADDRESS_TO_LOGGABLE_CSTR(bd_addr),
- addr_type);
+ log::verbose("bd_addr={}, addr_type={}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr),
+ addr_type);
const tBLE_BD_ADDR ble_bd_addr{
.type = addr_type,
.bda = bd_addr,
@@ -2748,13 +2762,13 @@ void btif_dm_create_bond_out_of_band(const RawAddress bd_addr,
// The controller only supports P192
switch (oob_cb.data_present) {
case BTM_OOB_PRESENT_192_AND_256:
- LOG_INFO("Have both P192 and P256");
+ log::info("Have both P192 and P256");
[[fallthrough]];
case BTM_OOB_PRESENT_192:
- LOG_INFO("Using P192");
+ log::info("Using P192");
break;
case BTM_OOB_PRESENT_256:
- LOG_INFO("Using P256");
+ log::info("Using P256");
// TODO(181889116):
// Upgrade to support p256 (for now we just ignore P256)
// because the controllers do not yet support it.
@@ -2762,27 +2776,27 @@ void btif_dm_create_bond_out_of_band(const RawAddress bd_addr,
BT_BOND_STATE_NONE);
return;
default:
- LOG_ERROR("Invalid data present for controller:%d",
- oob_cb.data_present);
+ log::error("Invalid data present for controller:{}",
+ oob_cb.data_present);
bond_state_changed(BT_STATUS_PARM_INVALID, bd_addr,
BT_BOND_STATE_NONE);
return;
}
pairing_cb.is_local_initiated = true;
- LOG_ERROR("Classic not implemented yet");
+ log::error("Classic not implemented yet");
bond_state_changed(BT_STATUS_UNSUPPORTED, bd_addr, BT_BOND_STATE_NONE);
return;
case BT_TRANSPORT_LE: {
// Guess default RANDOM for address type for LE
tBLE_ADDR_TYPE address_type = BLE_ADDR_RANDOM;
- LOG_INFO("Using LE Transport");
+ log::info("Using LE Transport");
switch (oob_cb.data_present) {
case BTM_OOB_PRESENT_192_AND_256:
- LOG_INFO("Have both P192 and P256");
+ log::info("Have both P192 and P256");
[[fallthrough]];
// Always prefer 256 for LE
case BTM_OOB_PRESENT_256:
- LOG_INFO("Using P256");
+ log::info("Using P256");
// If we have an address, lets get the type
if (memcmp(p256_data.address, empty, 7) != 0) {
/* byte no 7 is address type in LE Bluetooth Address OOB data */
@@ -2790,7 +2804,7 @@ void btif_dm_create_bond_out_of_band(const RawAddress bd_addr,
}
break;
case BTM_OOB_PRESENT_192:
- LOG_INFO("Using P192");
+ log::info("Using P192");
// If we have an address, lets get the type
if (memcmp(p192_data.address, empty, 7) != 0) {
/* byte no 7 is address type in LE Bluetooth Address OOB data */
@@ -2805,7 +2819,7 @@ void btif_dm_create_bond_out_of_band(const RawAddress bd_addr,
break;
}
default:
- LOG_ERROR("Invalid transport: %d", transport);
+ log::error("Invalid transport: {}", transport);
bond_state_changed(BT_STATUS_PARM_INVALID, bd_addr, BT_BOND_STATE_NONE);
return;
}
@@ -2819,7 +2833,7 @@ void btif_dm_create_bond_out_of_band(const RawAddress bd_addr,
*
******************************************************************************/
void btif_dm_cancel_bond(const RawAddress bd_addr) {
- LOG_VERBOSE("bd_addr=%s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
+ log::verbose("bd_addr={}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
BTM_LogHistory(kBtmLogTag, bd_addr, "Cancel bond");
@@ -2878,7 +2892,7 @@ void btif_dm_hh_open_failed(RawAddress* bdaddr) {
******************************************************************************/
void btif_dm_remove_bond(const RawAddress bd_addr) {
- LOG_VERBOSE("bd_addr=%s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
+ log::verbose("bd_addr={}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
BTM_LogHistory(kBtmLogTag, bd_addr, "Remove bond");
@@ -2899,7 +2913,7 @@ void btif_dm_remove_bond(const RawAddress bd_addr) {
&link_spec) != BT_STATUS_SUCCESS)
#endif
{
- LOG_DEBUG("Removing HH device");
+ log::debug("Removing HH device");
BTA_DmRemoveDevice(bd_addr);
}
}
@@ -2914,7 +2928,7 @@ void btif_dm_remove_bond(const RawAddress bd_addr) {
void btif_dm_pin_reply(const RawAddress bd_addr, uint8_t accept,
uint8_t pin_len, bt_pin_code_t pin_code) {
- LOG_VERBOSE("accept=%d", accept);
+ log::verbose("accept={}", accept);
if (pairing_cb.is_le_only) {
int i;
@@ -2925,7 +2939,7 @@ void btif_dm_pin_reply(const RawAddress bd_addr, uint8_t accept,
}
// TODO:
// FIXME: should we hide part of passkey here?
- LOG_VERBOSE("btif_dm_pin_reply: passkey: %d", passkey);
+ log::verbose("btif_dm_pin_reply: passkey: {}", passkey);
BTA_DmBlePasskeyReply(bd_addr, accept, passkey);
} else {
@@ -2944,7 +2958,7 @@ void btif_dm_pin_reply(const RawAddress bd_addr, uint8_t accept,
******************************************************************************/
void btif_dm_ssp_reply(const RawAddress bd_addr, bt_ssp_variant_t variant,
uint8_t accept) {
- LOG_VERBOSE("accept=%d", accept);
+ log::verbose("accept={}", accept);
BTM_LogHistory(
kBtmLogTag, bd_addr, "Ssp reply",
base::StringPrintf(
@@ -2992,7 +3006,7 @@ DEV_CLASS btif_dm_get_local_class_of_device() {
// If the property is empty, use the default
if (prop_cod[0] == '\0') {
- LOG_ERROR("COD property is empty");
+ log::error("COD property is empty");
return kDevClassUnclassified;
}
@@ -3009,7 +3023,7 @@ DEV_CLASS btif_dm_get_local_class_of_device() {
prop_cod[i] != '\0') {
char c = prop_cod[i++];
if (!std::isdigit(c)) {
- LOG_ERROR("COD malformed, '%c' is a non-digit", c);
+ log::error("COD malformed, '{:c}' is a non-digit", c);
return kDevClassUnclassified;
}
value += c;
@@ -3017,20 +3031,20 @@ DEV_CLASS btif_dm_get_local_class_of_device() {
// If we hit the end and it wasn't null terminated then return the default
if (i == PROPERTY_VALUE_MAX && prop_cod[PROPERTY_VALUE_MAX - 1] != '\0') {
- LOG_ERROR("COD malformed, value was truncated");
+ log::error("COD malformed, value was truncated");
return kDevClassUnclassified;
}
// Each number in the list must be one byte, meaning 0 (0x00) -> 255 (0xFF)
if (value.size() > 3 || value.size() == 0) {
- LOG_ERROR("COD malformed, '%s' must be between [0, 255]", value.c_str());
+ log::error("COD malformed, '{}' must be between [0, 255]", value);
return kDevClassUnclassified;
}
// Grab the value. If it's too large, then return the default
uint32_t uint32_val = static_cast<uint32_t>(std::stoul(value.c_str()));
if (uint32_val > 0xFF) {
- LOG_ERROR("COD malformed, '%s' must be between [0, 255]", value.c_str());
+ log::error("COD malformed, '{}' must be between [0, 255]", value);
return kDevClassUnclassified;
}
@@ -3040,7 +3054,7 @@ DEV_CLASS btif_dm_get_local_class_of_device() {
// If we've reached 3 numbers then make sure we're at a null terminator
if (j >= 3) {
if (prop_cod[i] != '\0') {
- LOG_ERROR("COD malformed, more than three numbers");
+ log::error("COD malformed, more than three numbers");
return kDevClassUnclassified;
}
break;
@@ -3062,11 +3076,12 @@ DEV_CLASS btif_dm_get_local_class_of_device() {
device_class[1] = temp_device_class[1];
device_class[2] = temp_device_class[2];
} else {
- LOG_ERROR("COD malformed, fewer than three numbers");
+ log::error("COD malformed, fewer than three numbers");
}
- LOG_DEBUG("Using class of device '0x%x, 0x%x, 0x%x' from CoD system property",
- device_class[0], device_class[1], device_class[2]);
+ log::debug(
+ "Using class of device '0x{:x}, 0x{:x}, 0x{:x}' from CoD system property",
+ device_class[0], device_class[1], device_class[2]);
#ifdef __ANDROID__
// Per BAP 1.0.1, 8.2.3. Device discovery, the stack needs to set Class of
@@ -3085,9 +3100,9 @@ DEV_CLASS btif_dm_get_local_class_of_device() {
} else {
device_class[1] &= ~(0x01 << 6);
}
- LOG_DEBUG(
- "Check LE audio enabled status, update class of device to '0x%x, 0x%x, "
- "0x%x'",
+ log::debug(
+ "Check LE audio enabled status, update class of device to '0x{:x}, "
+ "0x{:x}, 0x{:x}'",
device_class[0], device_class[1], device_class[2]);
#endif
return device_class;
@@ -3103,7 +3118,7 @@ DEV_CLASS btif_dm_get_local_class_of_device() {
*
******************************************************************************/
bt_status_t btif_dm_get_adapter_property(bt_property_t* prop) {
- LOG_VERBOSE("type=0x%x", prop->type);
+ log::verbose("type=0x{:x}", prop->type);
switch (prop->type) {
case BT_PROPERTY_BDNAME: {
bt_bdname_t* bd_name = (bt_bdname_t*)prop->val;
@@ -3154,9 +3169,8 @@ bt_status_t btif_dm_get_adapter_property(bt_property_t* prop) {
*
******************************************************************************/
void btif_dm_get_remote_services(RawAddress remote_addr, const int transport) {
- LOG_VERBOSE("transport=%s, remote_addr=%s",
- bt_transport_text(transport).c_str(),
- ADDRESS_TO_LOGGABLE_CSTR(remote_addr));
+ log::verbose("transport={}, remote_addr={}", bt_transport_text(transport),
+ ADDRESS_TO_LOGGABLE_CSTR(remote_addr));
BTM_LogHistory(
kBtmLogTag, remote_addr, "Service discovery",
@@ -3192,7 +3206,7 @@ void btif_dm_proc_io_req(tBTM_AUTH_REQ* p_auth_req, bool is_orig) {
** as a fallback set MITM+GB if peer had MITM set
*/
- LOG_VERBOSE("original p_auth_req=%d", *p_auth_req);
+ log::verbose("original p_auth_req={}", *p_auth_req);
if (pairing_cb.is_local_initiated) {
/* if initing/responding to a dedicated bonding, use dedicate bonding bit */
*p_auth_req = BTA_AUTH_DD_BOND | BTA_AUTH_SP_YES;
@@ -3200,8 +3214,8 @@ void btif_dm_proc_io_req(tBTM_AUTH_REQ* p_auth_req, bool is_orig) {
/* peer initiated paring. They probably know what they want.
** Copy the mitm from peer device.
*/
- LOG_DEBUG("peer initiated, setting p_auth_req to peer's: %d",
- pairing_cb.auth_req);
+ log::debug("peer initiated, setting p_auth_req to peer's: {}",
+ pairing_cb.auth_req);
*p_auth_req = (pairing_cb.auth_req & BTA_AUTH_BONDS);
/* copy over the MITM bit as well. In addition if the peer has DisplayYesNo,
@@ -3212,13 +3226,13 @@ void btif_dm_proc_io_req(tBTM_AUTH_REQ* p_auth_req, bool is_orig) {
/* set the general bonding bit for stored device */
*p_auth_req = BTA_AUTH_GEN_BOND | yes_no_bit;
}
- LOG_VERBOSE("updated p_auth_req=%d", *p_auth_req);
+ log::verbose("updated p_auth_req={}", *p_auth_req);
}
void btif_dm_proc_io_rsp(const RawAddress& /* bd_addr */, tBTM_IO_CAP io_cap,
tBTM_OOB_DATA /* oob_data */, tBTM_AUTH_REQ auth_req) {
if (auth_req & BTA_AUTH_BONDS) {
- LOG_DEBUG("auth_req:%d", auth_req);
+ log::debug("auth_req:{}", auth_req);
pairing_cb.auth_req = auth_req;
pairing_cb.io_cap = io_cap;
}
@@ -3230,7 +3244,7 @@ void btif_dm_set_oob_for_io_req(tBTM_OOB_DATA* p_has_oob_data) {
} else {
*p_has_oob_data = true;
}
- LOG_VERBOSE("*p_has_oob_data=%d", *p_has_oob_data);
+ log::verbose("*p_has_oob_data={}", *p_has_oob_data);
}
void btif_dm_set_oob_for_le_io_req(const RawAddress& bd_addr,
@@ -3238,11 +3252,11 @@ void btif_dm_set_oob_for_le_io_req(const RawAddress& bd_addr,
tBTM_LE_AUTH_REQ* p_auth_req) {
switch (oob_cb.data_present) {
case BTM_OOB_PRESENT_192_AND_256:
- LOG_INFO("Have both P192 and P256");
+ log::info("Have both P192 and P256");
[[fallthrough]];
// Always prefer 256 for LE
case BTM_OOB_PRESENT_256:
- LOG_INFO("Using P256");
+ log::info("Using P256");
if (!is_empty_128bit(oob_cb.p256_data.c) &&
!is_empty_128bit(oob_cb.p256_data.r)) {
/* make sure OOB data is for this particular device */
@@ -3251,7 +3265,7 @@ void btif_dm_set_oob_for_le_io_req(const RawAddress& bd_addr,
*p_has_oob_data = true;
} else {
*p_has_oob_data = false;
- LOG_WARN("P256-1: Remote address didn't match OOB data address");
+ log::warn("P256-1: Remote address didn't match OOB data address");
}
} else if (!is_empty_128bit(oob_cb.p256_data.sm_tk)) {
/* We have security manager TK */
@@ -3264,14 +3278,14 @@ void btif_dm_set_oob_for_le_io_req(const RawAddress& bd_addr,
*p_has_oob_data = true;
} else {
*p_has_oob_data = false;
- LOG_WARN("P256-2: Remote address didn't match OOB data address");
+ log::warn("P256-2: Remote address didn't match OOB data address");
}
} else {
*p_has_oob_data = false;
}
break;
case BTM_OOB_PRESENT_192:
- LOG_INFO("Using P192");
+ log::info("Using P192");
if (!is_empty_128bit(oob_cb.p192_data.c) &&
!is_empty_128bit(oob_cb.p192_data.r)) {
/* make sure OOB data is for this particular device */
@@ -3280,7 +3294,7 @@ void btif_dm_set_oob_for_le_io_req(const RawAddress& bd_addr,
*p_has_oob_data = true;
} else {
*p_has_oob_data = false;
- LOG_WARN("P192-1: Remote address didn't match OOB data address");
+ log::warn("P192-1: Remote address didn't match OOB data address");
}
} else if (!is_empty_128bit(oob_cb.p192_data.sm_tk)) {
/* We have security manager TK */
@@ -3293,23 +3307,23 @@ void btif_dm_set_oob_for_le_io_req(const RawAddress& bd_addr,
*p_has_oob_data = true;
} else {
*p_has_oob_data = false;
- LOG_WARN("P192-2: Remote address didn't match OOB data address");
+ log::warn("P192-2: Remote address didn't match OOB data address");
}
} else {
*p_has_oob_data = false;
}
break;
}
- LOG_VERBOSE("*p_has_oob_data=%d", *p_has_oob_data);
+ log::verbose("*p_has_oob_data={}", *p_has_oob_data);
}
void btif_dm_load_local_oob(void) {
char prop_oob[PROPERTY_VALUE_MAX];
osi_property_get("service.brcm.bt.oob", prop_oob, "3");
- LOG_VERBOSE("prop_oob = %s", prop_oob);
+ log::verbose("prop_oob = {}", prop_oob);
if (prop_oob[0] != '3') {
if (is_empty_128bit(oob_cb.p192_data.c)) {
- LOG_VERBOSE("read OOB, call BTA_DmLocalOob()");
+ log::verbose("read OOB, call BTA_DmLocalOob()");
BTA_DmLocalOob();
}
}
@@ -3319,7 +3333,7 @@ static bool waiting_on_oob_advertiser_start = false;
static std::optional<uint8_t> oob_advertiser_id_;
static void stop_oob_advertiser() {
// For chasing an advertising bug b/237023051
- LOG_DEBUG("oob_advertiser_id: %d", oob_advertiser_id_.value());
+ log::debug("oob_advertiser_id: {}", oob_advertiser_id_.value());
auto advertiser = bluetooth::shim::get_ble_advertiser_instance();
advertiser->Unregister(oob_advertiser_id_.value());
oob_advertiser_id_ = {};
@@ -3335,7 +3349,7 @@ static void stop_oob_advertiser() {
*
******************************************************************************/
void btif_dm_generate_local_oob_data(tBT_TRANSPORT transport) {
- LOG_DEBUG("Transport %s", bt_transport_text(transport).c_str());
+ log::debug("Transport {}", bt_transport_text(transport));
if (transport == BT_TRANSPORT_BR_EDR) {
BTM_ReadLocalOobData();
} else if (transport == BT_TRANSPORT_LE) {
@@ -3344,7 +3358,7 @@ void btif_dm_generate_local_oob_data(tBT_TRANSPORT transport) {
// advertising then request the address.
if (!waiting_on_oob_advertiser_start) {
// For chasing an advertising bug b/237023051
- LOG_DEBUG("oob_advertiser_id: %d", oob_advertiser_id_.value_or(255));
+ log::debug("oob_advertiser_id: {}", oob_advertiser_id_.value_or(255));
if (oob_advertiser_id_.has_value()) {
stop_oob_advertiser();
}
@@ -3375,7 +3389,7 @@ static void start_advertising_callback(uint8_t id, tBT_TRANSPORT transport,
bool is_valid, const Octet16& c,
const Octet16& r, tBTM_STATUS status) {
if (status != 0) {
- LOG_INFO("OOB get advertiser ID failed with status %hhd", status);
+ log::info("OOB get advertiser ID failed with status {}", status);
GetInterfaceToProfiles()->events->invoke_oob_data_request_cb(
transport, false, c, r, RawAddress{}, 0x00);
SMP_ClearLocScOobData();
@@ -3383,15 +3397,14 @@ static void start_advertising_callback(uint8_t id, tBT_TRANSPORT transport,
oob_advertiser_id_ = {};
return;
}
- LOG_DEBUG("OOB advertiser with id %hhd", id);
+ log::debug("OOB advertiser with id {}", id);
auto advertiser = bluetooth::shim::get_ble_advertiser_instance();
advertiser->GetOwnAddress(
id, base::Bind(&get_address_callback, transport, is_valid, c, r));
}
static void timeout_cb(uint8_t id, tBTM_STATUS status) {
- LOG_INFO("OOB advertiser with id %hhd timed out with status %hhd", id,
- status);
+ log::info("OOB advertiser with id {} timed out with status {}", id, status);
auto advertiser = bluetooth::shim::get_ble_advertiser_instance();
advertiser->Unregister(id);
SMP_ClearLocScOobData();
@@ -3404,7 +3417,7 @@ static void id_status_callback(tBT_TRANSPORT transport, bool is_valid,
const Octet16& c, const Octet16& r, uint8_t id,
tBTM_STATUS status) {
if (status != 0) {
- LOG_INFO("OOB get advertiser ID failed with status %hhd", status);
+ log::info("OOB get advertiser ID failed with status {}", status);
GetInterfaceToProfiles()->events->invoke_oob_data_request_cb(
transport, false, c, r, RawAddress{}, 0x00);
SMP_ClearLocScOobData();
@@ -3414,7 +3427,7 @@ static void id_status_callback(tBT_TRANSPORT transport, bool is_valid,
}
oob_advertiser_id_ = id;
- LOG_INFO("oob_advertiser_id: %d", id);
+ log::info("oob_advertiser_id: {}", id);
auto advertiser = bluetooth::shim::get_ble_advertiser_instance();
AdvertiseParameters parameters{};
@@ -3486,7 +3499,7 @@ void btif_dm_proc_loc_oob(tBT_TRANSPORT transport, bool is_valid,
bool btif_dm_get_smp_config(tBTE_APPL_CFG* p_cfg) {
const std::string* recv = stack_config_get_interface()->get_pts_smp_options();
if (!recv) {
- LOG_WARN("SMP pairing options not found in stack configuration");
+ log::warn("SMP pairing options not found in stack configuration");
return false;
}
@@ -3537,23 +3550,23 @@ bool btif_dm_proc_rmt_oob(const RawAddress& bd_addr, Octet16* p_c,
const char* path = NULL;
char prop_oob[PROPERTY_VALUE_MAX];
osi_property_get("service.brcm.bt.oob", prop_oob, "3");
- LOG_DEBUG("prop_oob = %s", prop_oob);
+ log::debug("prop_oob = {}", prop_oob);
if (prop_oob[0] == '1')
path = path_b;
else if (prop_oob[0] == '2')
path = path_a;
if (!path) {
- LOG_DEBUG("can't open path!");
+ log::debug("can't open path!");
return false;
}
FILE* fp = fopen(path, "rb");
if (fp == NULL) {
- LOG_DEBUG("failed to read OOB keys from %s", path);
+ log::debug("failed to read OOB keys from {}", path);
return false;
}
- LOG_VERBOSE("read OOB data from %s", path);
+ log::verbose("read OOB data from {}", path);
(void)fread(p_c->data(), 1, OCTET16_LEN, fp);
(void)fread(p_r->data(), 1, OCTET16_LEN, fp);
fclose(fp);
@@ -3568,7 +3581,7 @@ static void btif_dm_ble_key_notif_evt(tBTA_DM_SP_KEY_NOTIF* p_ssp_key_notif) {
uint32_t cod;
int dev_type;
- LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_ssp_key_notif->bd_addr));
+ log::verbose("addr:{}", ADDRESS_TO_LOGGABLE_CSTR(p_ssp_key_notif->bd_addr));
/* Remote name update */
if (!btif_get_device_type(p_ssp_key_notif->bd_addr, &dev_type)) {
@@ -3640,7 +3653,7 @@ static void btif_dm_ble_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
/* Test for temporary bonding */
if (btif_dm_ble_is_temp_pairing(bd_addr, p_auth_cmpl->is_ctkd)) {
- LOG_DEBUG("sending BT_BOND_STATE_NONE for Temp pairing");
+ log::debug("sending BT_BOND_STATE_NONE for Temp pairing");
btif_storage_remove_bonded_device(&bd_addr);
state = BT_BOND_STATE_NONE;
} else {
@@ -3648,15 +3661,15 @@ static void btif_dm_ble_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
if (pairing_cb.gatt_over_le ==
btif_dm_pairing_cb_t::ServiceDiscoveryState::NOT_STARTED) {
- LOG_INFO("scheduling GATT discovery over LE for %s",
- ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
+ log::info("scheduling GATT discovery over LE for {}",
+ ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
pairing_cb.gatt_over_le =
btif_dm_pairing_cb_t::ServiceDiscoveryState::SCHEDULED;
btif_dm_get_remote_services(bd_addr, BT_TRANSPORT_LE);
} else {
- LOG_INFO(
+ log::info(
"skipping GATT discovery over LE - was already scheduled or "
- "finished for %s, state: %d",
+ "finished for {}, state: {}",
ADDRESS_TO_LOGGABLE_CSTR(bd_addr), pairing_cb.gatt_over_le);
}
}
@@ -3664,8 +3677,8 @@ static void btif_dm_ble_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
/* Map the HCI fail reason to bt status */
// TODO This is not a proper use of the type
uint8_t fail_reason = static_cast<uint8_t>(p_auth_cmpl->fail_reason);
- LOG_ERROR("LE authentication for %s failed with reason %d",
- ADDRESS_TO_LOGGABLE_CSTR(bd_addr), p_auth_cmpl->fail_reason);
+ log::error("LE authentication for {} failed with reason {}",
+ ADDRESS_TO_LOGGABLE_CSTR(bd_addr), p_auth_cmpl->fail_reason);
switch (fail_reason) {
case BTA_DM_AUTH_SMP_PAIR_AUTH_FAIL:
case BTA_DM_AUTH_SMP_CONFIRM_VALUE_FAIL:
@@ -3676,15 +3689,15 @@ static void btif_dm_ble_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
case BTA_DM_AUTH_SMP_CONN_TOUT: {
if (!p_auth_cmpl->is_ctkd && btm_sec_is_a_bonded_dev(bd_addr)) {
- LOG_WARN(
- "Bonded device addr=%s, timed out - will not remove the keys",
+ log::warn(
+ "Bonded device addr={}, timed out - will not remove the keys",
ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
// Don't send state change to upper layers - otherwise Java think we
// unbonded, and will disconnect HID profile.
return;
}
- LOG_INFO(
- "Removing ble bonding keys on SMP_CONN_TOUT during crosskey: %d",
+ log::info(
+ "Removing ble bonding keys on SMP_CONN_TOUT during crosskey: {}",
p_auth_cmpl->is_ctkd);
btif_dm_remove_ble_bonding_keys();
status = BT_STATUS_AUTH_FAILURE;
@@ -3715,7 +3728,7 @@ void btif_dm_load_ble_local_keys(void) {
if (btif_storage_get_ble_local_key(
BTIF_DM_LE_LOCAL_KEY_ER, &ble_local_key_cb.er) == BT_STATUS_SUCCESS) {
ble_local_key_cb.is_er_rcvd = true;
- LOG_VERBOSE("BLE ER key loaded");
+ log::verbose("BLE ER key loaded");
}
if ((btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_IR,
@@ -3728,7 +3741,7 @@ void btif_dm_load_ble_local_keys(void) {
&ble_local_key_cb.id_keys.dhk) ==
BT_STATUS_SUCCESS)) {
ble_local_key_cb.is_id_keys_rcvd = true;
- LOG_VERBOSE("BLE ID keys loaded");
+ log::verbose("BLE ID keys loaded");
}
}
void btif_dm_get_ble_local_keys(tBTA_DM_BLE_LOCAL_KEY_MASK* p_key_mask,
@@ -3748,14 +3761,14 @@ void btif_dm_get_ble_local_keys(tBTA_DM_BLE_LOCAL_KEY_MASK* p_key_mask,
p_id_keys->dhk = ble_local_key_cb.id_keys.dhk;
*p_key_mask |= BTA_BLE_LOCAL_KEY_TYPE_ID;
}
- LOG_VERBOSE("*p_key_mask=0x%02x", *p_key_mask);
+ log::verbose("*p_key_mask=0x{:02x}", *p_key_mask);
}
static void btif_dm_save_ble_bonding_keys(RawAddress& bd_addr) {
- LOG_VERBOSE("%s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
+ log::verbose("{}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
if (bd_addr.IsEmpty()) {
- LOG_WARN("bd_addr is empty");
+ log::warn("bd_addr is empty");
return;
}
@@ -3796,7 +3809,7 @@ static void btif_dm_save_ble_bonding_keys(RawAddress& bd_addr) {
}
static void btif_dm_remove_ble_bonding_keys(void) {
- LOG_VERBOSE("removing ble bonding keys");
+ log::verbose("removing ble bonding keys");
RawAddress bd_addr = pairing_cb.bd_addr;
btif_storage_remove_ble_bonding_keys(&bd_addr);
@@ -3817,10 +3830,10 @@ static void btif_dm_ble_sec_req_evt(tBTA_DM_BLE_SEC_REQ* p_ble_req,
uint32_t cod;
int dev_type;
- LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_ble_req->bd_addr));
+ log::verbose("addr:{}", ADDRESS_TO_LOGGABLE_CSTR(p_ble_req->bd_addr));
if (!is_consent && pairing_cb.state == BT_BOND_STATE_BONDING) {
- LOG_WARN("Discard security request");
+ log::warn("Discard security request");
return;
}
@@ -3893,7 +3906,7 @@ static void btif_dm_ble_passkey_req_evt(tBTA_DM_PIN_REQ* p_pin_req) {
}
static void btif_dm_ble_key_nc_req_evt(tBTA_DM_SP_KEY_NOTIF* p_notif_req) {
/* TODO implement key notification for numeric comparison */
- LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_notif_req->bd_addr));
+ log::verbose("addr:{}", ADDRESS_TO_LOGGABLE_CSTR(p_notif_req->bd_addr));
/* Remote name update */
btif_update_remote_properties(p_notif_req->bd_addr, p_notif_req->bd_name,
@@ -3921,7 +3934,7 @@ static void btif_dm_ble_key_nc_req_evt(tBTA_DM_SP_KEY_NOTIF* p_notif_req) {
}
static void btif_dm_ble_oob_req_evt(tBTA_DM_SP_RMT_OOB* req_oob_type) {
- LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(req_oob_type->bd_addr));
+ log::verbose("addr:{}", ADDRESS_TO_LOGGABLE_CSTR(req_oob_type->bd_addr));
RawAddress bd_addr = req_oob_type->bd_addr;
/* We already checked if OOB data is present in
@@ -3934,7 +3947,7 @@ static void btif_dm_ble_oob_req_evt(tBTA_DM_SP_RMT_OOB* req_oob_type) {
/* make sure OOB data is for this particular device */
if (req_oob_type->bd_addr != oob_cb.bdaddr) {
- LOG_WARN("remote address didn't match OOB data address");
+ log::warn("remote address didn't match OOB data address");
return;
}
@@ -3952,12 +3965,12 @@ static void btif_dm_ble_oob_req_evt(tBTA_DM_SP_RMT_OOB* req_oob_type) {
static void btif_dm_ble_sc_oob_req_evt(tBTA_DM_SP_RMT_OOB* req_oob_type) {
RawAddress bd_addr = req_oob_type->bd_addr;
- LOG_VERBOSE("bd_addr: %s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
- LOG_VERBOSE("oob_cb.bdaddr: %s", ADDRESS_TO_LOGGABLE_CSTR(oob_cb.bdaddr));
+ log::verbose("bd_addr: {}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
+ log::verbose("oob_cb.bdaddr: {}", ADDRESS_TO_LOGGABLE_CSTR(oob_cb.bdaddr));
/* make sure OOB data is for this particular device */
if (req_oob_type->bd_addr != oob_cb.bdaddr) {
- LOG_ERROR("remote address didn't match OOB data address");
+ log::error("remote address didn't match OOB data address");
return;
}
@@ -3968,23 +3981,23 @@ static void btif_dm_ble_sc_oob_req_evt(tBTA_DM_SP_RMT_OOB* req_oob_type) {
bt_oob_data_t oob_data_to_use = {};
switch (oob_cb.data_present) {
case BTM_OOB_PRESENT_192_AND_256:
- LOG_INFO("Have both P192 and P256");
+ log::info("Have both P192 and P256");
[[fallthrough]];
// Always prefer 256 for LE
case BTM_OOB_PRESENT_256:
- LOG_INFO("Using P256");
+ log::info("Using P256");
if (is_empty_128bit(oob_cb.p256_data.c) &&
is_empty_128bit(oob_cb.p256_data.r)) {
- LOG_WARN("P256 LE SC OOB data is empty");
+ log::warn("P256 LE SC OOB data is empty");
return;
}
oob_data_to_use = oob_cb.p256_data;
break;
case BTM_OOB_PRESENT_192:
- LOG_INFO("Using P192");
+ log::info("Using P192");
if (is_empty_128bit(oob_cb.p192_data.c) &&
is_empty_128bit(oob_cb.p192_data.r)) {
- LOG_WARN("P192 LE SC OOB data is empty");
+ log::warn("P192 LE SC OOB data is empty");
return;
}
oob_data_to_use = oob_cb.p192_data;
@@ -4052,7 +4065,7 @@ void btif_ble_test_end() { BTM_BleTestEnd(btif_dm_ble_test_end_cback); }
void btif_dm_on_disable() {
/* cancel any pending pairing requests */
if (is_bonding_or_sdp()) {
- LOG_VERBOSE("Cancel pending pairing request");
+ log::verbose("Cancel pending pairing request");
btif_dm_cancel_bond(pairing_cb.bd_addr);
}
}
@@ -4201,8 +4214,8 @@ bool btif_get_device_type(const RawAddress& bda, int* p_device_type) {
p_device_type))
return false;
tBT_DEVICE_TYPE device_type = static_cast<tBT_DEVICE_TYPE>(*p_device_type);
- LOG_DEBUG("bd_addr:%s device_type:%s", ADDRESS_TO_LOGGABLE_CSTR(bda),
- DeviceTypeText(device_type).c_str());
+ log::debug("bd_addr:{} device_type:{}", ADDRESS_TO_LOGGABLE_CSTR(bda),
+ DeviceTypeText(device_type));
return true;
}
@@ -4217,8 +4230,8 @@ bool btif_get_address_type(const RawAddress& bda, tBLE_ADDR_TYPE* p_addr_type) {
if (!btif_config_get_int(bd_addr_str, BTIF_STORAGE_KEY_ADDR_TYPE, &val))
return false;
*p_addr_type = static_cast<tBLE_ADDR_TYPE>(val);
- LOG_DEBUG("bd_addr:%s[%s]", ADDRESS_TO_LOGGABLE_CSTR(bda),
- AddressTypeText(*p_addr_type).c_str());
+ log::debug("bd_addr:{}[{}]", ADDRESS_TO_LOGGABLE_CSTR(bda),
+ AddressTypeText(*p_addr_type));
return true;
}
@@ -4266,7 +4279,8 @@ void btif_dm_metadata_changed(const RawAddress& remote_bd_addr, int key,
static const int METADATA_LE_AUDIO = 26;
/* If METADATA_LE_AUDIO is present, device is LE Audio capable */
if (key == METADATA_LE_AUDIO) {
- LOG_INFO("Device is LE Audio Capable %s", ADDRESS_TO_LOGGABLE_CSTR(remote_bd_addr));
+ log::info("Device is LE Audio Capable {}",
+ ADDRESS_TO_LOGGABLE_CSTR(remote_bd_addr));
metadata_cb.le_audio_cache.insert_or_assign(remote_bd_addr, value);
}
}
diff --git a/system/btif/src/btif_gatt_client.cc b/system/btif/src/btif_gatt_client.cc
index 6796db048a..73bf14975d 100644
--- a/system/btif/src/btif_gatt_client.cc
+++ b/system/btif/src/btif_gatt_client.cc
@@ -30,6 +30,7 @@
#include <base/functional/bind.h>
#include <base/logging.h>
#include <base/threading/thread.h>
+#include <bluetooth/log.h>
#include <hardware/bluetooth.h>
#include <hardware/bt_gatt.h>
#include <hardware/bt_gatt_types.h>
@@ -60,6 +61,7 @@ using base::Bind;
using base::Owned;
using bluetooth::Uuid;
using std::vector;
+using namespace bluetooth;
bool btif_get_address_type(const RawAddress& bda, tBLE_ADDR_TYPE* p_addr_type);
bool btif_get_device_type(const RawAddress& bda, int* p_device_type);
@@ -74,7 +76,7 @@ extern const btgatt_callbacks_t* bt_gatt_callbacks;
#define CLI_CBACK_WRAP_IN_JNI(P_CBACK, P_CBACK_WRAP) \
do { \
if (bt_gatt_callbacks && bt_gatt_callbacks->client->P_CBACK) { \
- LOG_VERBOSE("HAL bt_gatt_callbacks->client->%s", #P_CBACK); \
+ log::verbose("HAL bt_gatt_callbacks->client->{}", #P_CBACK); \
do_in_jni_thread(P_CBACK_WRAP); \
} else { \
ASSERTC(0, "Callback is NULL", 0); \
@@ -84,21 +86,21 @@ extern const btgatt_callbacks_t* bt_gatt_callbacks;
#define CLI_CBACK_IN_JNI(P_CBACK, ...) \
do { \
if (bt_gatt_callbacks && bt_gatt_callbacks->client->P_CBACK) { \
- LOG_VERBOSE("HAL bt_gatt_callbacks->client->%s", #P_CBACK); \
+ log::verbose("HAL bt_gatt_callbacks->client->{}", #P_CBACK); \
do_in_jni_thread(Bind(bt_gatt_callbacks->client->P_CBACK, __VA_ARGS__)); \
} else { \
ASSERTC(0, "Callback is NULL", 0); \
} \
} while (0)
-#define CHECK_BTGATT_INIT() \
- do { \
- if (bt_gatt_callbacks == NULL) { \
- LOG_WARN("%s: BTGATT not initialized", __func__); \
- return BT_STATUS_NOT_READY; \
- } else { \
- LOG_DEBUG("%s", __func__); \
- } \
+#define CHECK_BTGATT_INIT() \
+ do { \
+ if (bt_gatt_callbacks == NULL) { \
+ log::warn("BTGATT not initialized"); \
+ return BT_STATUS_NOT_READY; \
+ } else { \
+ log::debug(""); \
+ } \
} while (0)
namespace {
@@ -106,9 +108,8 @@ namespace {
uint8_t rssi_request_client_if;
static void btif_gattc_upstreams_evt(uint16_t event, char* p_param) {
- LOG_DEBUG("Event %s [%d]",
- gatt_client_event_text(static_cast<tBTA_GATTC_EVT>(event)).c_str(),
- event);
+ log::debug("Event {} [{}]",
+ gatt_client_event_text(static_cast<tBTA_GATTC_EVT>(event)), event);
tBTA_GATTC* p_data = (tBTA_GATTC*)p_param;
switch (event) {
@@ -144,8 +145,8 @@ static void btif_gattc_upstreams_evt(uint16_t event, char* p_param) {
}
case BTA_GATTC_OPEN_EVT: {
- LOG_DEBUG("BTA_GATTC_OPEN_EVT %s",
- ADDRESS_TO_LOGGABLE_CSTR(p_data->open.remote_bda));
+ log::debug("BTA_GATTC_OPEN_EVT {}",
+ ADDRESS_TO_LOGGABLE_CSTR(p_data->open.remote_bda));
HAL_CBACK(bt_gatt_callbacks, client->open_cb, p_data->open.conn_id,
p_data->open.status, p_data->open.client_if,
p_data->open.remote_bda);
@@ -173,7 +174,7 @@ static void btif_gattc_upstreams_evt(uint16_t event, char* p_param) {
case BTA_GATTC_SEARCH_RES_EVT:
case BTA_GATTC_CANCEL_OPEN_EVT:
case BTA_GATTC_SRVC_DISC_DONE_EVT:
- LOG_DEBUG("Ignoring event (%d)", event);
+ log::debug("Ignoring event ({})", event);
break;
case BTA_GATTC_CFG_MTU_EVT: {
@@ -214,14 +215,14 @@ static void btif_gattc_upstreams_evt(uint16_t event, char* p_param) {
break;
default:
- LOG_ERROR("Unhandled event (%d)!", event);
+ log::error("Unhandled event ({})!", event);
break;
}
}
static void bta_gattc_cback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data) {
- LOG_DEBUG(" gatt client callback event:%s [%d]",
- gatt_client_event_text(event).c_str(), event);
+ log::debug("gatt client callback event:{} [{}]",
+ gatt_client_event_text(event), event);
bt_status_t status =
btif_transfer_context(btif_gattc_upstreams_evt, (uint16_t)event,
(char*)p_data, sizeof(tBTA_GATTC), NULL);
@@ -330,14 +331,14 @@ void btif_gattc_open_impl(int client_if, RawAddress address,
transport = BT_TRANSPORT_BR_EDR;
break;
default:
- LOG_ERROR("Unknown device type %d", +device_type);
+ log::error("Unknown device type {}", device_type);
break;
}
}
// Connect!
- LOG_INFO("Transport=%d, device type=%d, address type =%d, phy=%d", transport,
- device_type, addr_type, initiating_phys);
+ log::info("Transport={}, device type={}, address type ={}, phy={}", transport,
+ device_type, addr_type, initiating_phys);
tBTM_BLE_CONN_TYPE type =
is_direct ? BTM_BLE_DIRECT_CONNECTION : BTM_BLE_BKG_CONNECT_ALLOW_LIST;
BTA_GATTC_Open(client_if, address, addr_type, type, transport, opportunistic,
@@ -356,8 +357,8 @@ static bt_status_t btif_gattc_open(int client_if, const RawAddress& bd_addr,
}
void btif_gattc_close_impl(int client_if, RawAddress address, int conn_id) {
- LOG_INFO("client_if=%d, conn_id=%d, address=%s", client_if, conn_id,
- ADDRESS_TO_LOGGABLE_CSTR(address));
+ log::info("client_if={}, conn_id={}, address={}", client_if, conn_id,
+ ADDRESS_TO_LOGGABLE_CSTR(address));
// Disconnect established connections
if (conn_id != 0) {
BTA_GATTC_Close(conn_id);
diff --git a/system/btif/src/btif_gatt_server.cc b/system/btif/src/btif_gatt_server.cc
index 7f4ecdb58f..8b5fe9d016 100644
--- a/system/btif/src/btif_gatt_server.cc
+++ b/system/btif/src/btif_gatt_server.cc
@@ -27,6 +27,7 @@
#define LOG_TAG "bt_btif_gatt"
#include <base/functional/bind.h>
+#include <bluetooth/log.h>
#include <hardware/bluetooth.h>
#include <hardware/bt_gatt.h>
#include <hardware/bt_gatt_types.h>
@@ -53,19 +54,20 @@ bool btif_get_device_type(const RawAddress& bda, int* p_device_type);
using base::Bind;
using bluetooth::Uuid;
using std::vector;
+using namespace bluetooth;
/*******************************************************************************
* Constants & Macros
******************************************************************************/
-#define CHECK_BTGATT_INIT() \
- do { \
- if (bt_gatt_callbacks == NULL) { \
- LOG_WARN("%s: BTGATT not initialized", __func__); \
- return BT_STATUS_NOT_READY; \
- } else { \
- LOG_VERBOSE("%s", __func__); \
- } \
+#define CHECK_BTGATT_INIT() \
+ do { \
+ if (bt_gatt_callbacks == NULL) { \
+ log::warn("BTGATT not initialized"); \
+ return BT_STATUS_NOT_READY; \
+ } else { \
+ log::verbose(""); \
+ } \
} while (0)
/*******************************************************************************
@@ -124,7 +126,7 @@ static void btapp_gatts_free_req_data(uint16_t event, tBTA_GATTS* p_data) {
}
static void btapp_gatts_handle_cback(uint16_t event, char* p_param) {
- LOG_VERBOSE("%s: Event %d", __func__, event);
+ log::verbose("Event {}", event);
tBTA_GATTS* p_data = (tBTA_GATTS*)p_param;
switch (event) {
@@ -229,7 +231,7 @@ static void btapp_gatts_handle_cback(uint16_t event, char* p_param) {
case BTA_GATTS_OPEN_EVT:
case BTA_GATTS_CANCEL_OPEN_EVT:
case BTA_GATTS_CLOSE_EVT:
- LOG_INFO("%s: Empty event (%d)!", __func__, event);
+ log::info("Empty event ({})!", event);
break;
case BTA_GATTS_PHY_UPDATE_EVT:
@@ -253,7 +255,7 @@ static void btapp_gatts_handle_cback(uint16_t event, char* p_param) {
break;
default:
- LOG_ERROR("%s: Unhandled event (%d)!", __func__, event);
+ log::error("Unhandled event ({})!", event);
break;
}
@@ -362,7 +364,7 @@ static void add_service_impl(int server_if,
// refactored, and one can distinguish stack-internal aps from external apps
if (service[0].uuid == Uuid::From16Bit(UUID_SERVCLASS_GATT_SERVER) ||
service[0].uuid == Uuid::From16Bit(UUID_SERVCLASS_GAP_SERVER)) {
- LOG_ERROR("%s: Attept to register restricted service", __func__);
+ log::error("Attept to register restricted service");
HAL_CBACK(bt_gatt_callbacks, server->service_added_cb, BT_STATUS_FAIL,
server_if, service.data(), service.size());
return;
diff --git a/system/btif/src/btif_gatt_test.cc b/system/btif/src/btif_gatt_test.cc
index ce5446310a..e8ac0276c8 100644
--- a/system/btif/src/btif_gatt_test.cc
+++ b/system/btif/src/btif_gatt_test.cc
@@ -18,6 +18,7 @@
#define LOG_TAG "bt_btif_gatt"
+#include <bluetooth/log.h>
#include <hardware/bluetooth.h>
#include <hardware/bt_gatt.h>
#include <stdio.h>
@@ -33,6 +34,8 @@
#include "types/raw_address.h"
using bluetooth::Uuid;
+using namespace bluetooth;
+
/*******************************************************************************
* Typedefs & Macros
******************************************************************************/
@@ -62,15 +65,15 @@ static btif_test_cb_t test_cb;
static void btif_test_connect_cback(tGATT_IF, const RawAddress&,
uint16_t conn_id, bool connected,
tGATT_DISCONN_REASON, tBT_TRANSPORT) {
- LOG_INFO("%s: conn_id=%d, connected=%d", __func__, conn_id, connected);
+ log::info("conn_id={}, connected={}", conn_id, connected);
test_cb.conn_id = connected ? conn_id : 0;
}
static void btif_test_command_complete_cback(uint16_t conn_id, tGATTC_OPTYPE op,
tGATT_STATUS status,
tGATT_CL_COMPLETE* p_data) {
- LOG_INFO("%s: op_code=0x%02x, conn_id=0x%x. status=0x%x", __func__, op,
- conn_id, status);
+ log::info("op_code=0x{:02x}, conn_id=0x{:x}. status=0x{:x}", op, conn_id,
+ status);
switch (op) {
case GATTC_OPTYPE_READ:
@@ -85,7 +88,7 @@ static void btif_test_command_complete_cback(uint16_t conn_id, tGATTC_OPTYPE op,
break;
default:
- LOG_INFO("%s: Unknown op_code (0x%02x)", __func__, op);
+ log::info("Unknown op_code (0x{:02x})", op);
break;
}
}
@@ -93,61 +96,59 @@ static void btif_test_command_complete_cback(uint16_t conn_id, tGATTC_OPTYPE op,
static void btif_test_discovery_result_cback(uint16_t /* conn_id */,
tGATT_DISC_TYPE disc_type,
tGATT_DISC_RES* p_data) {
- LOG_INFO("------ GATT Discovery result %-22s -------", disc_name[disc_type]);
- LOG_INFO(" Attribute handle: 0x%04x (%d)", p_data->handle,
- p_data->handle);
+ log::info("------ GATT Discovery result {:<22s} -------",
+ disc_name[disc_type]);
+ log::info("Attribute handle: 0x{:04x} ({})", p_data->handle, p_data->handle);
if (disc_type != GATT_DISC_CHAR_DSCPT) {
- LOG_INFO(" Attribute type: %s", p_data->type.ToString().c_str());
+ log::info("Attribute type: {}", p_data->type.ToString());
}
switch (disc_type) {
case GATT_DISC_SRVC_ALL:
- LOG_INFO(" Handle range: 0x%04x ~ 0x%04x (%d ~ %d)",
- p_data->handle, p_data->value.group_value.e_handle,
- p_data->handle, p_data->value.group_value.e_handle);
- LOG_INFO(" Service UUID: %s",
- p_data->value.group_value.service_type.ToString().c_str());
+ log::info("Handle range: 0x{:04x} ~ 0x{:04x} ({} ~ {})", p_data->handle,
+ p_data->value.group_value.e_handle, p_data->handle,
+ p_data->value.group_value.e_handle);
+ log::info("Service UUID: {}",
+ p_data->value.group_value.service_type.ToString());
break;
case GATT_DISC_SRVC_BY_UUID:
- LOG_INFO(" Handle range: 0x%04x ~ 0x%04x (%d ~ %d)",
- p_data->handle, p_data->value.handle, p_data->handle,
- p_data->value.handle);
+ log::info("Handle range: 0x{:04x} ~ 0x{:04x} ({} ~ {})", p_data->handle,
+ p_data->value.handle, p_data->handle, p_data->value.handle);
break;
case GATT_DISC_INC_SRVC:
- LOG_INFO(" Handle range: 0x%04x ~ 0x%04x (%d ~ %d)",
- p_data->value.incl_service.s_handle,
- p_data->value.incl_service.e_handle,
- p_data->value.incl_service.s_handle,
- p_data->value.incl_service.e_handle);
- LOG_INFO(" Service UUID: %s",
- p_data->value.incl_service.service_type.ToString().c_str());
+ log::info("Handle range: 0x{:04x} ~ 0x{:04x} ({} ~ {})",
+ p_data->value.incl_service.s_handle,
+ p_data->value.incl_service.e_handle,
+ p_data->value.incl_service.s_handle,
+ p_data->value.incl_service.e_handle);
+ log::info("Service UUID: {}",
+ p_data->value.incl_service.service_type.ToString());
break;
case GATT_DISC_CHAR:
- LOG_INFO(" Properties: 0x%02x",
- p_data->value.dclr_value.char_prop);
- LOG_INFO(" Characteristic UUID: %s",
- p_data->value.dclr_value.char_uuid.ToString().c_str());
+ log::info("Properties: 0x{:02x}", p_data->value.dclr_value.char_prop);
+ log::info("Characteristic UUID: {}",
+ p_data->value.dclr_value.char_uuid.ToString());
break;
case GATT_DISC_CHAR_DSCPT:
- LOG_INFO(" Descriptor UUID: %s", p_data->type.ToString().c_str());
+ log::info("Descriptor UUID: {}", p_data->type.ToString());
break;
case GATT_DISC_MAX:
- LOG_ERROR(" Unknown discovery item");
+ log::error("Unknown discovery item");
break;
}
- LOG_INFO("-----------------------------------------------------------");
+ log::info("-----------------------------------------------------------");
}
static void btif_test_discovery_complete_cback(uint16_t /* conn_id */,
tGATT_DISC_TYPE /* disc_type */,
tGATT_STATUS status) {
- LOG_INFO("%s: status=%d", __func__, status);
+ log::info("status={}", status);
}
static tGATT_CBACK btif_test_callbacks = {
@@ -172,7 +173,7 @@ bt_status_t btif_gattc_test_command_impl(int command,
switch (command) {
case 0x01: /* Enable */
{
- LOG_INFO("%s: ENABLE - enable=%d", __func__, params->u1);
+ log::info("ENABLE - enable={}", params->u1);
if (params->u1) {
std::array<uint8_t, Uuid::kNumBytes128> tmp;
tmp.fill(0xAE);
@@ -189,8 +190,9 @@ bt_status_t btif_gattc_test_command_impl(int command,
case 0x02: /* Connect */
{
- LOG_INFO("%s: CONNECT - device=%s (dev_type=%d, addr_type=%d)", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(*params->bda1), params->u1, params->u2);
+ log::info("CONNECT - device={} (dev_type={}, addr_type={})",
+ ADDRESS_TO_LOGGABLE_CSTR(*params->bda1), params->u1,
+ params->u2);
if (params->u1 == BT_DEVICE_TYPE_BLE)
BTM_SecAddBleDevice(*params->bda1, BT_DEVICE_TYPE_BLE,
@@ -198,14 +200,14 @@ bt_status_t btif_gattc_test_command_impl(int command,
if (!GATT_Connect(test_cb.gatt_if, *params->bda1,
BTM_BLE_DIRECT_CONNECTION, BT_TRANSPORT_LE, false)) {
- LOG_ERROR("%s: GATT_Connect failed!", __func__);
+ log::error("GATT_Connect failed!");
}
break;
}
case 0x03: /* Disconnect */
{
- LOG_INFO("%s: DISCONNECT - conn_id=%d", __func__, test_cb.conn_id);
+ log::info("DISCONNECT - conn_id={}", test_cb.conn_id);
GATT_Disconnect(test_cb.conn_id);
break;
}
@@ -213,22 +215,21 @@ bt_status_t btif_gattc_test_command_impl(int command,
case 0x04: /* Discover */
{
if (params->u1 >= GATT_DISC_MAX) {
- LOG_ERROR("%s: DISCOVER - Invalid type (%d)!", __func__, params->u1);
+ log::error("DISCOVER - Invalid type ({})!", params->u1);
return (bt_status_t)0;
}
- LOG_INFO("%s: DISCOVER (%s), conn_id=%d, uuid=%s, handles=0x%04x-0x%04x",
- __func__, disc_name[params->u1], test_cb.conn_id,
- params->uuid1->ToString().c_str(), params->u2, params->u3);
+ log::info("DISCOVER ({}), conn_id={}, uuid={}, handles=0x{:04x}-0x{:04x}",
+ disc_name[params->u1], test_cb.conn_id,
+ params->uuid1->ToString(), params->u2, params->u3);
GATTC_Discover(test_cb.conn_id, static_cast<tGATT_DISC_TYPE>(params->u1),
params->u2, params->u3, *params->uuid1);
break;
}
case 0xF0: /* Pairing configuration */
- LOG_INFO("%s: Setting pairing config auth=%d, iocaps=%d, keys=%d/%d/%d",
- __func__, params->u1, params->u2, params->u3, params->u4,
- params->u5);
+ log::info("Setting pairing config auth={}, iocaps={}, keys={}/{}/{}",
+ params->u1, params->u2, params->u3, params->u4, params->u5);
bte_appl_cfg.ble_auth_req = params->u1;
bte_appl_cfg.ble_io_cap = params->u2;
@@ -238,7 +239,7 @@ bt_status_t btif_gattc_test_command_impl(int command,
break;
default:
- LOG_ERROR("%s: UNKNOWN TEST COMMAND 0x%02x", __func__, command);
+ log::error("UNKNOWN TEST COMMAND 0x{:02x}", command);
break;
}
return (bt_status_t)0;
diff --git a/system/btif/src/btif_gatt_util.cc b/system/btif/src/btif_gatt_util.cc
index a054bc8fc1..858876d04a 100644
--- a/system/btif/src/btif_gatt_util.cc
+++ b/system/btif/src/btif_gatt_util.cc
@@ -20,6 +20,7 @@
#include "btif_gatt_util.h"
+#include <bluetooth/log.h>
#include <hardware/bluetooth.h>
#include <hardware/bt_gatt.h>
#include <stdio.h>
@@ -41,6 +42,7 @@
#include "types/raw_address.h"
using bluetooth::Uuid;
+using namespace bluetooth;
/*******************************************************************************
* BTIF -> BTA conversion functions
@@ -66,7 +68,7 @@ static void btif_gatt_set_encryption_cb(const RawAddress& /* bd_addr */,
tBT_TRANSPORT /* transport */,
tBTA_STATUS result) {
if (result != BTA_SUCCESS && result != BTA_BUSY) {
- LOG_WARN("%s() - Encryption failed (%d)", __func__, result);
+ log::warn("Encryption failed ({})", result);
}
}
@@ -77,14 +79,14 @@ void btif_gatt_check_encrypted_link(RawAddress bd_addr,
BTM_ReadConnectionAddr(bd_addr, raw_local_addr, &local_addr_type);
tBLE_BD_ADDR local_addr{local_addr_type, raw_local_addr};
if (!local_addr.IsPublic() && !local_addr.IsAddressResolvable()) {
- LOG_DEBUG("Not establishing encryption since address type is NRPA");
+ log::debug("Not establishing encryption since address type is NRPA");
return;
}
static const bool check_encrypted = bluetooth::os::GetSystemPropertyBool(
"bluetooth.gatt.check_encrypted_link.enabled", true);
if (!check_encrypted) {
- LOG_DEBUG("Check skipped due to system config");
+ log::debug("Check skipped due to system config");
return;
}
tBTM_LE_PENC_KEYS key;
@@ -92,9 +94,9 @@ void btif_gatt_check_encrypted_link(RawAddress bd_addr,
bd_addr, BTM_LE_KEY_PENC, (uint8_t*)&key,
sizeof(tBTM_LE_PENC_KEYS)) == BT_STATUS_SUCCESS) &&
!btif_gatt_is_link_encrypted(bd_addr)) {
- LOG_DEBUG("Checking gatt link peer:%s transport:%s",
- ADDRESS_TO_LOGGABLE_CSTR(bd_addr),
- bt_transport_text(transport_link).c_str());
+ log::debug("Checking gatt link peer:{} transport:{}",
+ ADDRESS_TO_LOGGABLE_CSTR(bd_addr),
+ bt_transport_text(transport_link));
BTA_DmSetEncryption(bd_addr, transport_link, &btif_gatt_set_encryption_cb,
BTM_BLE_SEC_ENCRYPT);
}
diff --git a/system/btif/src/btif_hd.cc b/system/btif/src/btif_hd.cc
index f2f93cfe5d..4112c16061 100644
--- a/system/btif/src/btif_hd.cc
+++ b/system/btif/src/btif_hd.cc
@@ -29,6 +29,8 @@
#include "btif/include/btif_hd.h"
+#include <bluetooth/log.h>
+
#include <cstdint>
#include "bta/include/bta_hd_api.h"
@@ -54,6 +56,8 @@
#define COD_HID_COMBO 0x05C0
#define COD_HID_MAJOR 0x0500
+using namespace bluetooth;
+
bool bta_dm_check_if_only_hd_connected(const RawAddress& peer_addr);
bool check_cod_hid(const RawAddress* remote_bdaddr);
bool check_cod_hid(const RawAddress& bd_addr);
@@ -142,11 +146,11 @@ void btif_hd_remove_device(RawAddress bd_addr) {
static void btif_hd_upstreams_evt(uint16_t event, char* p_param) {
tBTA_HD* p_data = (tBTA_HD*)p_param;
- LOG_VERBOSE("%s: event=%s", __func__, dump_hd_event(event));
+ log::verbose("event={}", dump_hd_event(event));
switch (event) {
case BTA_HD_ENABLE_EVT:
- LOG_VERBOSE("%s: status=%d", __func__, p_data->status);
+ log::verbose("status={}", p_data->status);
if (p_data->status == BTA_HD_OK) {
btif_storage_load_hidd();
btif_hd_cb.status = BTIF_HD_ENABLED;
@@ -157,16 +161,16 @@ static void btif_hd_upstreams_evt(uint16_t event, char* p_param) {
}
} else {
btif_hd_cb.status = BTIF_HD_DISABLED;
- LOG_WARN("Failed to enable BT-HD, status=%d", p_data->status);
+ log::warn("Failed to enable BT-HD, status={}", p_data->status);
}
break;
case BTA_HD_DISABLE_EVT:
- LOG_VERBOSE("%s: status=%d", __func__, p_data->status);
+ log::verbose("status={}", p_data->status);
btif_hd_cb.status = BTIF_HD_DISABLED;
if (btif_hd_cb.service_dereg_active) {
bta_sys_deregister(BTA_ID_HD);
- LOG_WARN("registering hid host now");
+ log::warn("registering hid host now");
btif_hh_service_registration(TRUE);
btif_hd_cb.service_dereg_active = FALSE;
}
@@ -174,7 +178,7 @@ static void btif_hd_upstreams_evt(uint16_t event, char* p_param) {
if (p_data->status == BTA_HD_OK)
memset(&btif_hd_cb, 0, sizeof(btif_hd_cb));
else
- LOG_WARN("Failed to disable BT-HD, status=%d", p_data->status);
+ log::warn("Failed to disable BT-HD, status={}", p_data->status);
break;
case BTA_HD_REGISTER_APP_EVT: {
@@ -184,7 +188,7 @@ static void btif_hd_upstreams_evt(uint16_t event, char* p_param) {
addr = NULL;
}
- LOG_INFO("Registering HID device app");
+ log::info("Registering HID device app");
btif_hd_cb.app_registered = TRUE;
HAL_CBACK(bt_hd_callbacks, application_state_cb, addr,
BTHD_APP_STATE_REGISTERED);
@@ -195,7 +199,7 @@ static void btif_hd_upstreams_evt(uint16_t event, char* p_param) {
HAL_CBACK(bt_hd_callbacks, application_state_cb, NULL,
BTHD_APP_STATE_NOT_REGISTERED);
if (btif_hd_cb.service_dereg_active) {
- LOG_WARN("disabling hid device service now");
+ log::warn("disabling hid device service now");
if (!bluetooth::common::init_flags::
delay_hidh_cleanup_until_hidh_ready_start_is_enabled()) {
btif_hd_free_buf();
@@ -206,11 +210,11 @@ static void btif_hd_upstreams_evt(uint16_t event, char* p_param) {
case BTA_HD_OPEN_EVT: {
RawAddress* addr = (RawAddress*)&p_data->conn.bda;
- LOG_WARN("BTA_HD_OPEN_EVT, address=%s", ADDRESS_TO_LOGGABLE_CSTR(*addr));
+ log::warn("BTA_HD_OPEN_EVT, address={}", ADDRESS_TO_LOGGABLE_CSTR(*addr));
/* Check if the connection is from hid host and not hid device */
if (check_cod_hid(addr)) {
/* Incoming connection from hid device, reject it */
- LOG_WARN("remote device is not hid host, disconnecting");
+ log::warn("remote device is not hid host, disconnecting");
btif_hd_cb.forced_disc = TRUE;
BTA_HdDisconnect();
break;
@@ -224,7 +228,7 @@ static void btif_hd_upstreams_evt(uint16_t event, char* p_param) {
case BTA_HD_CLOSE_EVT:
if (btif_hd_cb.forced_disc) {
RawAddress* addr = (RawAddress*)&p_data->conn.bda;
- LOG_WARN("remote device was forcefully disconnected");
+ log::warn("remote device was forcefully disconnected");
btif_hd_remove_device(*addr);
btif_hd_cb.forced_disc = FALSE;
break;
@@ -257,15 +261,11 @@ static void btif_hd_upstreams_evt(uint16_t event, char* p_param) {
HAL_CBACK(bt_hd_callbacks, connection_state_cb,
(RawAddress*)&p_data->conn.bda, BTHD_CONN_STATE_DISCONNECTED);
if (bta_dm_check_if_only_hd_connected(p_data->conn.bda)) {
- LOG_VERBOSE("%s: Removing bonding as only HID profile connected",
- __func__);
+ log::verbose("Removing bonding as only HID profile connected");
BTA_DmRemoveDevice(p_data->conn.bda);
} else {
RawAddress* bd_addr = (RawAddress*)&p_data->conn.bda;
- LOG_VERBOSE(
- "%s: Only removing HID data as some other profiles "
- "connected",
- __func__);
+ log::verbose("Only removing HID data as some other profiles connected");
btif_hd_remove_device(*bd_addr);
}
HAL_CBACK(bt_hd_callbacks, vc_unplug_cb);
@@ -278,7 +278,7 @@ static void btif_hd_upstreams_evt(uint16_t event, char* p_param) {
break;
default:
- LOG_WARN("%s: unknown event (%d)", __func__, event);
+ log::warn("unknown event ({})", event);
break;
}
}
@@ -298,7 +298,7 @@ static void bte_hd_evt(tBTA_HD_EVT event, tBTA_HD* p_data) {
int param_len = 0;
tBTIF_COPY_CBACK* p_copy_cback = NULL;
- LOG_VERBOSE("%s event=%d", __func__, event);
+ log::verbose("event={}", event);
switch (event) {
case BTA_HD_ENABLE_EVT:
@@ -353,7 +353,7 @@ static void bte_hd_evt(tBTA_HD_EVT event, tBTA_HD* p_data) {
*
******************************************************************************/
static bt_status_t init(bthd_callbacks_t* callbacks) {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
bt_hd_callbacks = callbacks;
memset(&btif_hd_cb, 0, sizeof(btif_hd_cb));
@@ -373,7 +373,7 @@ static bt_status_t init(bthd_callbacks_t* callbacks) {
*
******************************************************************************/
static void cleanup(void) {
- LOG_VERBOSE("hd:%s", __func__);
+ log::verbose("");
if (bt_hd_callbacks) {
/* update flag, not to enable hid host service now as BT is switching off */
@@ -395,10 +395,10 @@ static void cleanup(void) {
static bt_status_t register_app(bthd_app_param_t* p_app_param,
bthd_qos_param_t* p_in_qos,
bthd_qos_param_t* p_out_qos) {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
if (btif_hd_cb.app_registered) {
- LOG_WARN("%s: application already registered", __func__);
+ log::warn("application already registered");
return BT_STATUS_DONE;
}
@@ -447,20 +447,20 @@ static bt_status_t register_app(bthd_app_param_t* p_app_param,
*
******************************************************************************/
static bt_status_t unregister_app(void) {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
if (!btif_hd_cb.app_registered) {
- LOG_WARN("%s: application not yet registered", __func__);
+ log::warn("application not yet registered");
return BT_STATUS_NOT_READY;
}
if (btif_hd_cb.status != BTIF_HD_ENABLED) {
- LOG_WARN("%s: BT-HD not enabled, status=%d", __func__, btif_hd_cb.status);
+ log::warn("BT-HD not enabled, status={}", btif_hd_cb.status);
return BT_STATUS_NOT_READY;
}
if (btif_hd_cb.service_dereg_active) {
- LOG_WARN("%s: BT-HD deregistering in progress", __func__);
+ log::warn("BT-HD deregistering in progress");
return BT_STATUS_BUSY;
}
@@ -480,15 +480,15 @@ static bt_status_t unregister_app(void) {
*
******************************************************************************/
static bt_status_t connect(RawAddress* bd_addr) {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
if (!btif_hd_cb.app_registered) {
- LOG_WARN("%s: application not yet registered", __func__);
+ log::warn("application not yet registered");
return BT_STATUS_NOT_READY;
}
if (btif_hd_cb.status != BTIF_HD_ENABLED) {
- LOG_WARN("%s: BT-HD not enabled, status=%d", __func__, btif_hd_cb.status);
+ log::warn("BT-HD not enabled, status={}", btif_hd_cb.status);
return BT_STATUS_NOT_READY;
}
@@ -507,15 +507,15 @@ static bt_status_t connect(RawAddress* bd_addr) {
*
******************************************************************************/
static bt_status_t disconnect(void) {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
if (!btif_hd_cb.app_registered) {
- LOG_WARN("%s: application not yet registered", __func__);
+ log::warn("application not yet registered");
return BT_STATUS_NOT_READY;
}
if (btif_hd_cb.status != BTIF_HD_ENABLED) {
- LOG_WARN("%s: BT-HD not enabled, status=%d", __func__, btif_hd_cb.status);
+ log::warn("BT-HD not enabled, status={}", btif_hd_cb.status);
return BT_STATUS_NOT_READY;
}
@@ -537,15 +537,15 @@ static bt_status_t send_report(bthd_report_type_t type, uint8_t id,
uint16_t len, uint8_t* p_data) {
tBTA_HD_REPORT report;
- LOG_VERBOSE("%s: type=%d id=%d len=%d", __func__, type, id, len);
+ log::verbose("type={} id={} len={}", type, id, len);
if (!btif_hd_cb.app_registered) {
- LOG_WARN("%s: application not yet registered", __func__);
+ log::warn("application not yet registered");
return BT_STATUS_NOT_READY;
}
if (btif_hd_cb.status != BTIF_HD_ENABLED) {
- LOG_WARN("%s: BT-HD not enabled, status=%d", __func__, btif_hd_cb.status);
+ log::warn("BT-HD not enabled, status={}", btif_hd_cb.status);
return BT_STATUS_NOT_READY;
}
@@ -576,15 +576,15 @@ static bt_status_t send_report(bthd_report_type_t type, uint8_t id,
*
******************************************************************************/
static bt_status_t report_error(uint8_t error) {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
if (!btif_hd_cb.app_registered) {
- LOG_WARN("%s: application not yet registered", __func__);
+ log::warn("application not yet registered");
return BT_STATUS_NOT_READY;
}
if (btif_hd_cb.status != BTIF_HD_ENABLED) {
- LOG_WARN("%s: BT-HD not enabled, status=%d", __func__, btif_hd_cb.status);
+ log::warn("BT-HD not enabled, status={}", btif_hd_cb.status);
return BT_STATUS_NOT_READY;
}
@@ -603,15 +603,15 @@ static bt_status_t report_error(uint8_t error) {
*
******************************************************************************/
static bt_status_t virtual_cable_unplug(void) {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
if (!btif_hd_cb.app_registered) {
- LOG_WARN("%s: application not yet registered", __func__);
+ log::warn("application not yet registered");
return BT_STATUS_NOT_READY;
}
if (btif_hd_cb.status != BTIF_HD_ENABLED) {
- LOG_WARN("%s: BT-HD not enabled, status=%d", __func__, btif_hd_cb.status);
+ log::warn("BT-HD not enabled, status={}", btif_hd_cb.status);
return BT_STATUS_NOT_READY;
}
@@ -643,7 +643,7 @@ static const bthd_interface_t bthdInterface = {
*
******************************************************************************/
bt_status_t btif_hd_execute_service(bool b_enable) {
- LOG_VERBOSE("%s: b_enable=%d", __func__, b_enable);
+ log::verbose("b_enable={}", b_enable);
if (!b_enable) BTA_HdDisable();
@@ -660,7 +660,7 @@ bt_status_t btif_hd_execute_service(bool b_enable) {
*
******************************************************************************/
const bthd_interface_t* btif_hd_get_interface() {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
return &bthdInterface;
}
@@ -674,7 +674,7 @@ const bthd_interface_t* btif_hd_get_interface() {
*
******************************************************************************/
void btif_hd_service_registration() {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
/* enable HD */
if (bt_hd_callbacks != NULL) {
BTA_HdEnable(bte_hd_evt);
diff --git a/system/btif/src/btif_hf.cc b/system/btif/src/btif_hf.cc
index 84cfb6c363..6539d66df7 100644
--- a/system/btif/src/btif_hf.cc
+++ b/system/btif/src/btif_hf.cc
@@ -31,6 +31,7 @@
#include <android_bluetooth_sysprop.h>
#include <base/functional/callback.h>
#include <base/logging.h>
+#include <bluetooth/log.h>
#include <frameworks/proto_logging/stats/enums/bluetooth/enums.pb.h>
#include <cstdint>
@@ -94,14 +95,14 @@ static RawAddress active_bda = {};
******************************************************************************/
static Callbacks* bt_hf_callbacks = nullptr;
-#define CHECK_BTHF_INIT() \
- do { \
- if (!bt_hf_callbacks) { \
- LOG_WARN("BTHF: %s: BTHF not initialized", __func__); \
- return BT_STATUS_NOT_READY; \
- } else { \
- LOG_VERBOSE("BTHF: %s", __func__); \
- } \
+#define CHECK_BTHF_INIT() \
+ do { \
+ if (!bt_hf_callbacks) { \
+ log::warn("BTHF not initialized"); \
+ return BT_STATUS_NOT_READY; \
+ } else { \
+ log::verbose("BTHF ok"); \
+ } \
} while (false)
/* BTIF-HF control block to map bdaddr to BTA handle */
@@ -285,13 +286,13 @@ static void reset_control_block(btif_hf_cb_t* hf_cb) {
*/
static bool IsSlcConnected(RawAddress* bd_addr) {
if (!bd_addr) {
- LOG(WARNING) << __func__ << ": bd_addr is null";
+ log::warn("bd_addr is null");
return false;
}
int idx = btif_hf_idx_by_bdaddr(bd_addr);
if (idx < 0 || idx > BTA_AG_MAX_NUM_CLIENTS) {
- LOG(WARNING) << __func__ << ": invalid index " << idx << " for "
- << ADDRESS_TO_LOGGABLE_STR(*bd_addr);
+ log::warn("invalid index {} for {}", idx,
+ ADDRESS_TO_LOGGABLE_STR(*bd_addr));
return false;
}
return btif_hf_cb[idx].state == BTHF_CONNECTION_STATE_SLC_CONNECTED;
@@ -308,32 +309,32 @@ static bool IsSlcConnected(RawAddress* bd_addr) {
******************************************************************************/
static void btif_hf_upstreams_evt(uint16_t event, char* p_param) {
if (event == BTA_AG_ENABLE_EVT || event == BTA_AG_DISABLE_EVT) {
- LOG(INFO) << __func__ << ": AG enable/disable event " << event;
+ log::info("AG enable/disable event {}", event);
return;
}
if (p_param == nullptr) {
- LOG(ERROR) << __func__ << ": parameter is null";
+ log::error("parameter is null");
return;
}
tBTA_AG* p_data = (tBTA_AG*)p_param;
int idx = p_data->hdr.handle - 1;
- LOG_DEBUG("HF Upstream event:%s", dump_hf_event(event));
+ log::debug("HF Upstream event:{}", dump_hf_event(event));
if ((idx < 0) || (idx >= BTA_AG_MAX_NUM_CLIENTS)) {
- LOG_ERROR("%s Invalid client index:%d", dump_hf_event(event), idx);
+ log::error("{} Invalid client index:{}", dump_hf_event(event), idx);
return;
}
if (!bt_hf_callbacks) {
- LOG_ERROR("%s Headset callback is not set", dump_hf_event(event));
+ log::error("{} Headset callback is not set", dump_hf_event(event));
return;
}
switch (event) {
case BTA_AG_REGISTER_EVT:
btif_hf_cb[idx].handle = p_data->reg.hdr.handle;
- LOG_DEBUG("%s idx:%d btif_hf_cb.handle = %d", dump_hf_event(event), idx,
- btif_hf_cb[idx].handle);
+ log::debug("{} idx:{} btif_hf_cb.handle = {}", dump_hf_event(event), idx,
+ btif_hf_cb[idx].handle);
break;
// RFCOMM connected or failed to connect
case BTA_AG_OPEN_EVT:
@@ -349,22 +350,21 @@ static void btif_hf_upstreams_evt(uint16_t event, char* p_param) {
// Check if the incoming open event and the outgoing connection are
// for the same device.
if (p_data->open.bd_addr == btif_hf_cb[idx].connected_bda) {
- LOG(WARNING) << __func__ << ": btif_hf_cb state["
- << p_data->open.status
- << "] is not expected, possible connection collision, "
- "ignoring AG open "
- "failure event for the same device "
- << ADDRESS_TO_LOGGABLE_STR(p_data->open.bd_addr);
+ log::warn(
+ "btif_hf_cb state[{}] is not expected, possible connection "
+ "collision, ignoring AG open failure event for the same device "
+ "{}",
+ p_data->open.status,
+ ADDRESS_TO_LOGGABLE_STR(p_data->open.bd_addr));
} else {
- LOG(WARNING) << __func__ << ": btif_hf_cb state["
- << p_data->open.status
- << "] is not expected, possible connection collision, "
- "ignoring AG open failure "
- "event for the different devices btif_hf_cb bda: "
- << btif_hf_cb[idx].connected_bda
- << ", p_data bda: "
- << ADDRESS_TO_LOGGABLE_STR(p_data->open.bd_addr)
- << ", report disconnect state for p_data bda.";
+ log::warn(
+ "btif_hf_cb state[{}] is not expected, possible connection "
+ "collision, ignoring AG open failure event for the different "
+ "devices btif_hf_cb bda: {}, p_data bda: {}, report disconnect "
+ "state for p_data bda.",
+ p_data->open.status,
+ ADDRESS_TO_LOGGABLE_STR(btif_hf_cb[idx].connected_bda),
+ ADDRESS_TO_LOGGABLE_STR(p_data->open.bd_addr));
bt_hf_callbacks->ConnectionStateCallback(
BTHF_CONNECTION_STATE_DISCONNECTED, &(p_data->open.bd_addr));
log_counter_metrics_btif(
@@ -384,14 +384,12 @@ static void btif_hf_upstreams_evt(uint16_t event, char* p_param) {
// Check if the incoming open event and the outgoing connection are
// for the same device.
if (btif_hf_cb[idx].connected_bda != p_data->open.bd_addr) {
- LOG(WARNING) << __func__
- << ": possible connection collision, ignore the "
- "outgoing connection for the "
- "different devices btif_hf_cb bda: "
- << ADDRESS_TO_LOGGABLE_STR(btif_hf_cb[idx].connected_bda)
- << ", p_data bda: "
- << ADDRESS_TO_LOGGABLE_STR(p_data->open.bd_addr)
- << ", report disconnect state for btif_hf_cb bda.";
+ log::warn(
+ "possible connection collision, ignore the outgoing connection "
+ "for the different devices btif_hf_cb bda: {}, p_data bda: {}, "
+ "report disconnect state for btif_hf_cb bda.",
+ ADDRESS_TO_LOGGABLE_STR(btif_hf_cb[idx].connected_bda),
+ ADDRESS_TO_LOGGABLE_STR(p_data->open.bd_addr));
bt_hf_callbacks->ConnectionStateCallback(
BTHF_CONNECTION_STATE_DISCONNECTED,
&(btif_hf_cb[idx].connected_bda));
@@ -425,16 +423,14 @@ static void btif_hf_upstreams_evt(uint16_t event, char* p_param) {
} else {
if (!btif_hf_cb[idx].is_initiator) {
// Ignore remote initiated open failures
- LOG(WARNING) << __func__ << ": Unexpected AG open failure "
- << std::to_string(p_data->open.status) << " for "
- << ADDRESS_TO_LOGGABLE_STR(p_data->open.bd_addr)
- << " is ignored";
+ log::warn("Unexpected AG open failure {} for {} is ignored",
+ p_data->open.status,
+ ADDRESS_TO_LOGGABLE_STR(p_data->open.bd_addr));
break;
}
- LOG(ERROR) << __func__ << ": self initiated AG open failed for "
- << ADDRESS_TO_LOGGABLE_STR(btif_hf_cb[idx].connected_bda)
- << ", status "
- << std::to_string(p_data->open.status);
+ log::error("self initiated AG open failed for {}, status {}",
+ ADDRESS_TO_LOGGABLE_STR(btif_hf_cb[idx].connected_bda),
+ p_data->open.status);
RawAddress connected_bda = btif_hf_cb[idx].connected_bda;
reset_control_block(&btif_hf_cb[idx]);
bt_hf_callbacks->ConnectionStateCallback(btif_hf_cb[idx].state,
@@ -448,9 +444,9 @@ static void btif_hf_upstreams_evt(uint16_t event, char* p_param) {
}
break;
case BTA_AG_CLOSE_EVT: {
- LOG_DEBUG(
- "SLC and RFCOMM both disconnected event:%s idx:%d"
- " btif_hf_cb.handle:%d",
+ log::debug(
+ "SLC and RFCOMM both disconnected event:{} idx:{} "
+ "btif_hf_cb.handle:{}",
dump_hf_event(event), idx, btif_hf_cb[idx].handle);
RawAddress connected_bda = btif_hf_cb[idx].connected_bda;
bt_hf_callbacks->ConnectionStateCallback(
@@ -465,7 +461,8 @@ static void btif_hf_upstreams_evt(uint16_t event, char* p_param) {
bt_hf_callbacks->ConnectionStateCallback(btif_hf_cb[idx].state,
&connected_bda);
if (failed_to_setup_slc) {
- LOG(ERROR) << __func__ << ": failed to setup SLC for " << connected_bda;
+ log::error("failed to setup SLC for {}",
+ ADDRESS_TO_LOGGABLE_STR(connected_bda));
log_counter_metrics_btif(
android::bluetooth::CodePathCounterKeyEnum::HFP_SLC_SETUP_FAILED,
1);
@@ -486,7 +483,7 @@ static void btif_hf_upstreams_evt(uint16_t event, char* p_param) {
btif_hf_cb[idx].connected_bda, IOT_CONF_KEY_HFP_FEATURES,
p_data->conn.peer_feat, IOT_CONF_BYTE_NUM_2);
- LOG_DEBUG("SLC connected event:%s idx:%d", dump_hf_event(event), idx);
+ log::debug("SLC connected event:{} idx:{}", dump_hf_event(event), idx);
btif_hf_cb[idx].peer_feat = p_data->conn.peer_feat;
btif_hf_cb[idx].state = BTHF_CONNECTION_STATE_SLC_CONNECTED;
bt_hf_callbacks->ConnectionStateCallback(btif_hf_cb[idx].state,
@@ -497,13 +494,13 @@ static void btif_hf_upstreams_evt(uint16_t event, char* p_param) {
break;
case BTA_AG_AUDIO_OPEN_EVT:
- LOG_DEBUG("Audio open event:%s", dump_hf_event(event));
+ log::debug("Audio open event:{}", dump_hf_event(event));
bt_hf_callbacks->AudioStateCallback(BTHF_AUDIO_STATE_CONNECTED,
&btif_hf_cb[idx].connected_bda);
break;
case BTA_AG_AUDIO_CLOSE_EVT:
- LOG_DEBUG("Audio close event:%s", dump_hf_event(event));
+ log::debug("Audio close event:{}", dump_hf_event(event));
DEVICE_IOT_CONFIG_ADDR_INT_ADD_ONE(btif_hf_cb[idx].connected_bda,
IOT_CONF_KEY_HFP_SCO_CONN_FAIL_COUNT);
@@ -514,8 +511,8 @@ static void btif_hf_upstreams_evt(uint16_t event, char* p_param) {
case BTA_AG_SPK_EVT:
case BTA_AG_MIC_EVT:
- LOG_DEBUG("BTA auto-responds, silently discard event:%s",
- dump_hf_event(event));
+ log::debug("BTA auto-responds, silently discard event:{}",
+ dump_hf_event(event));
bt_hf_callbacks->VolumeControlCallback(
(event == BTA_AG_SPK_EVT) ? BTHF_VOLUME_TYPE_SPK
: BTHF_VOLUME_TYPE_MIC,
@@ -569,8 +566,8 @@ static void btif_hf_upstreams_evt(uint16_t event, char* p_param) {
break;
case BTA_AG_CODEC_EVT:
- LOG_VERBOSE(
- "BTA_AG_CODEC_EVT Set codec status %d codec %d 1=CVSD 2=MSBC 4=LC3",
+ log::verbose(
+ "BTA_AG_CODEC_EVT Set codec status {} codec {} 1=CVSD 2=MSBC 4=LC3",
p_data->val.hdr.status, p_data->val.num);
if (p_data->val.num == BTM_SCO_CODEC_CVSD) {
bt_hf_callbacks->WbsCallback(BTHF_WBS_NO,
@@ -597,8 +594,8 @@ static void btif_hf_upstreams_evt(uint16_t event, char* p_param) {
if (is_hfp_aptx_voice_enabled()) {
codec = BTHF_SWB_CODEC_VENDOR_APTX;
- LOG_VERBOSE(
- "AG final selected SWB codec is 0x%02x 0=Q0 4=Q1 6=Q2 7=Q3",
+ log::verbose(
+ "AG final selected SWB codec is 0x{:02x} 0=Q0 4=Q1 6=Q2 7=Q3",
p_data->val.num);
if (p_data->val.num == BTA_AG_SCO_APTX_SWB_SETTINGS_Q0 ||
p_data->val.num == BTA_AG_SCO_APTX_SWB_SETTINGS_Q1 ||
@@ -644,27 +641,27 @@ static void btif_hf_upstreams_evt(uint16_t event, char* p_param) {
send_at_result(BTA_AG_OK_ERROR, BTA_AG_ERR_OP_NOT_SUPPORTED, idx);
break;
case BTA_AG_AT_BAC_EVT:
- LOG_VERBOSE("AG Bitmap of peer-codecs %d", p_data->val.num);
+ log::verbose("AG Bitmap of peer-codecs {}", p_data->val.num);
/* If the peer supports mSBC and the BTIF preferred codec is also mSBC,
* then we should set the BTA AG Codec to mSBC. This would trigger a +BCS
* to mSBC at the time of SCO connection establishment */
if (hfp_hal_interface::get_swb_supported() &&
(p_data->val.num & BTM_SCO_CODEC_LC3)) {
- LOG_VERBOSE("%s: btif_hf override-Preferred Codec to LC3", __func__);
+ log::verbose("btif_hf override-Preferred Codec to LC3");
BTA_AgSetCodec(btif_hf_cb[idx].handle, BTM_SCO_CODEC_LC3);
} else if (hfp_hal_interface::get_wbs_supported() &&
(p_data->val.num & BTM_SCO_CODEC_MSBC)) {
- LOG_VERBOSE("%s: btif_hf override-Preferred Codec to mSBC", __func__);
+ log::verbose("btif_hf override-Preferred Codec to mSBC");
BTA_AgSetCodec(btif_hf_cb[idx].handle, BTM_SCO_CODEC_MSBC);
} else {
- LOG_VERBOSE("%s btif_hf override-Preferred Codec to CVSD", __func__);
+ log::verbose("btif_hf override-Preferred Codec to CVSD");
BTA_AgSetCodec(btif_hf_cb[idx].handle, BTM_SCO_CODEC_CVSD);
}
break;
case BTA_AG_AT_BCS_EVT:
- LOG_VERBOSE("AG final selected codec is 0x%02x 1=CVSD 2=MSBC",
- p_data->val.num);
+ log::verbose("AG final selected codec is 0x{:02x} 1=CVSD 2=MSBC",
+ p_data->val.num);
/* No BTHF_WBS_NONE case, because HF1.6 supported device can send BCS */
/* Only CVSD is considered narrow band speech */
bt_hf_callbacks->WbsCallback(
@@ -704,13 +701,12 @@ static void btif_hf_upstreams_evt(uint16_t event, char* p_param) {
case BTA_AG_AT_QCS_EVT:
if (!is_hfp_aptx_voice_enabled()) {
- LOG(WARNING) << __func__ << ": unhandled event " << event
- << ". Aptx codec is not enabled";
+ log::warn("unhandled event {}. Aptx codec is not enabled", event);
break;
}
- LOG_INFO("AG final selected SWB codec is %#02x 0=Q0 4=Q1 6=Q2 7=Q3",
- p_data->val.num);
+ log::info("AG final selected SWB codec is {:#02x} 0=Q0 4=Q1 6=Q2 7=Q3",
+ p_data->val.num);
bt_hf_callbacks->SwbCallback(
BTHF_SWB_CODEC_VENDOR_APTX,
p_data->val.num <= BTA_AG_SCO_APTX_SWB_SETTINGS_Q3 ? BTHF_SWB_YES
@@ -719,7 +715,7 @@ static void btif_hf_upstreams_evt(uint16_t event, char* p_param) {
break;
default:
- LOG(WARNING) << __func__ << ": unhandled event " << event;
+ log::warn("unhandled event {}", event);
break;
}
}
@@ -773,8 +769,8 @@ static void bte_hf_evt(tBTA_AG_EVT event, tBTA_AG* p_data) {
static bt_status_t connect_int(RawAddress* bd_addr, uint16_t uuid) {
CHECK_BTHF_INIT();
if (is_connected(bd_addr)) {
- LOG_WARN("%s: device %s is already connected", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
+ log::warn("device {} is already connected",
+ ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
return BT_STATUS_DONE;
}
btif_hf_cb_t* hf_cb = nullptr;
@@ -787,15 +783,14 @@ static bt_status_t connect_int(RawAddress* bd_addr, uint16_t uuid) {
// control block should be in connecting state
// Crash here to prevent future code changes from breaking this mechanism
if (btif_hf_cb[i].state == BTHF_CONNECTION_STATE_CONNECTING) {
- LOG(FATAL) << __func__ << ": "
- << ADDRESS_TO_LOGGABLE_STR(btif_hf_cb[i].connected_bda)
- << ", handle " << btif_hf_cb[i].handle
- << ", is still in connecting state " << btif_hf_cb[i].state;
+ log::fatal("{}, handle {}, is still in connecting state {}",
+ ADDRESS_TO_LOGGABLE_STR(btif_hf_cb[i].connected_bda),
+ btif_hf_cb[i].handle, btif_hf_cb[i].state);
}
}
if (hf_cb == nullptr) {
- LOG_WARN("%s: Cannot connect %s: maximum %d clients already connected",
- __func__, ADDRESS_TO_LOGGABLE_CSTR(*bd_addr), btif_max_hf_clients);
+ log::warn("Cannot connect {}: maximum {} clients already connected",
+ ADDRESS_TO_LOGGABLE_CSTR(*bd_addr), btif_max_hf_clients);
return BT_STATUS_BUSY;
}
hf_cb->state = BTHF_CONNECTION_STATE_CONNECTING;
@@ -901,10 +896,9 @@ bt_status_t HeadsetInterface::Init(Callbacks* callbacks, int max_hf_clients,
" maximum is "
<< BTA_AG_MAX_NUM_CLIENTS << " was given " << max_hf_clients;
btif_max_hf_clients = max_hf_clients;
- LOG_VERBOSE("%s: btif_hf_features=%" PRIu32
- ", max_hf_clients=%d, inband_ringing_enabled=%d",
- __func__, btif_hf_features, btif_max_hf_clients,
- inband_ringing_enabled);
+ log::verbose(
+ "btif_hf_features={}, max_hf_clients={}, inband_ringing_enabled={}",
+ btif_hf_features, btif_max_hf_clients, inband_ringing_enabled);
bt_hf_callbacks = callbacks;
for (btif_hf_cb_t& hf_cb : btif_hf_cb) {
reset_control_block(&hf_cb);
@@ -931,12 +925,11 @@ bt_status_t HeadsetInterface::Disconnect(RawAddress* bd_addr) {
CHECK_BTHF_INIT();
int idx = btif_hf_idx_by_bdaddr(bd_addr);
if ((idx < 0) || (idx >= BTA_AG_MAX_NUM_CLIENTS)) {
- LOG_ERROR("%s: Invalid index %d", __func__, idx);
+ log::error("Invalid index {}", idx);
return BT_STATUS_FAIL;
}
if (!is_connected(bd_addr)) {
- LOG_ERROR("%s: %s is not connected", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
+ log::error("{} is not connected", ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
return BT_STATUS_FAIL;
}
BTA_AgClose(btif_hf_cb[idx].handle);
@@ -948,13 +941,12 @@ bt_status_t HeadsetInterface::ConnectAudio(RawAddress* bd_addr,
CHECK_BTHF_INIT();
int idx = btif_hf_idx_by_bdaddr(bd_addr);
if ((idx < 0) || (idx >= BTA_AG_MAX_NUM_CLIENTS)) {
- LOG_ERROR("%s: Invalid index %d", __func__, idx);
+ log::error("Invalid index {}", idx);
return BT_STATUS_FAIL;
}
/* Check if SLC is connected */
if (!IsSlcConnected(bd_addr)) {
- LOG(ERROR) << ": SLC not connected for "
- << ADDRESS_TO_LOGGABLE_STR(*bd_addr);
+ log::error("SLC not connected for {}", ADDRESS_TO_LOGGABLE_STR(*bd_addr));
return BT_STATUS_NOT_READY;
}
do_in_jni_thread(base::BindOnce(&Callbacks::AudioStateCallback,
@@ -973,12 +965,11 @@ bt_status_t HeadsetInterface::DisconnectAudio(RawAddress* bd_addr) {
CHECK_BTHF_INIT();
int idx = btif_hf_idx_by_bdaddr(bd_addr);
if ((idx < 0) || (idx >= BTA_AG_MAX_NUM_CLIENTS)) {
- LOG_ERROR("%s: Invalid index %d", __func__, idx);
+ log::error("Invalid index {}", idx);
return BT_STATUS_FAIL;
}
if (!is_connected(bd_addr)) {
- LOG_ERROR("%s: %s is not connected", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
+ log::error("{} is not connected", ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
return BT_STATUS_FAIL;
}
BTA_AgAudioClose(btif_hf_cb[idx].handle);
@@ -989,7 +980,7 @@ bt_status_t HeadsetInterface::isNoiseReductionSupported(RawAddress* bd_addr) {
CHECK_BTHF_INIT();
int idx = btif_hf_idx_by_bdaddr(bd_addr);
if ((idx < 0) || (idx >= BTA_AG_MAX_NUM_CLIENTS)) {
- LOG_ERROR("%s: Invalid index %d", __func__, idx);
+ log::error("Invalid index {}", idx);
return BT_STATUS_FAIL;
}
if (!(btif_hf_cb[idx].peer_feat & BTA_AG_PEER_FEAT_ECNR)) {
@@ -1002,7 +993,7 @@ bt_status_t HeadsetInterface::isVoiceRecognitionSupported(RawAddress* bd_addr) {
CHECK_BTHF_INIT();
int idx = btif_hf_idx_by_bdaddr(bd_addr);
if ((idx < 0) || (idx >= BTA_AG_MAX_NUM_CLIENTS)) {
- LOG_ERROR("%s: Invalid index %d", __func__, idx);
+ log::error("Invalid index {}", idx);
return BT_STATUS_FAIL;
}
if (!(btif_hf_cb[idx].peer_feat & BTA_AG_PEER_FEAT_VREC)) {
@@ -1015,17 +1006,16 @@ bt_status_t HeadsetInterface::StartVoiceRecognition(RawAddress* bd_addr) {
CHECK_BTHF_INIT();
int idx = btif_hf_idx_by_bdaddr(bd_addr);
if ((idx < 0) || (idx >= BTA_AG_MAX_NUM_CLIENTS)) {
- LOG_ERROR("%s: Invalid index %d", __func__, idx);
+ log::error("Invalid index {}", idx);
return BT_STATUS_FAIL;
}
if (!is_connected(bd_addr)) {
- LOG_ERROR("%s: %s is not connected", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
+ log::error("{} is not connected", ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
return BT_STATUS_NOT_READY;
}
if (!(btif_hf_cb[idx].peer_feat & BTA_AG_PEER_FEAT_VREC)) {
- LOG_ERROR("%s: voice recognition not supported, features=0x%x", __func__,
- btif_hf_cb[idx].peer_feat);
+ log::error("voice recognition not supported, features=0x{:x}",
+ btif_hf_cb[idx].peer_feat);
return BT_STATUS_UNSUPPORTED;
}
tBTA_AG_RES_DATA ag_res = {};
@@ -1039,17 +1029,16 @@ bt_status_t HeadsetInterface::StopVoiceRecognition(RawAddress* bd_addr) {
int idx = btif_hf_idx_by_bdaddr(bd_addr);
if ((idx < 0) || (idx >= BTA_AG_MAX_NUM_CLIENTS)) {
- LOG_ERROR("%s: Invalid index %d", __func__, idx);
+ log::error("Invalid index {}", idx);
return BT_STATUS_FAIL;
}
if (!is_connected(bd_addr)) {
- LOG_ERROR("%s: %s is not connected", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
+ log::error("{} is not connected", ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
return BT_STATUS_NOT_READY;
}
if (!(btif_hf_cb[idx].peer_feat & BTA_AG_PEER_FEAT_VREC)) {
- LOG_ERROR("%s: voice recognition not supported, features=0x%x", __func__,
- btif_hf_cb[idx].peer_feat);
+ log::error("voice recognition not supported, features=0x{:x}",
+ btif_hf_cb[idx].peer_feat);
return BT_STATUS_UNSUPPORTED;
}
tBTA_AG_RES_DATA ag_res = {};
@@ -1063,12 +1052,11 @@ bt_status_t HeadsetInterface::VolumeControl(bthf_volume_type_t type, int volume,
CHECK_BTHF_INIT();
int idx = btif_hf_idx_by_bdaddr(bd_addr);
if ((idx < 0) || (idx >= BTA_AG_MAX_NUM_CLIENTS)) {
- LOG_ERROR("%s: Invalid index %d", __func__, idx);
+ log::error("Invalid index {}", idx);
return BT_STATUS_FAIL;
}
if (!is_connected(bd_addr)) {
- LOG_ERROR("%s: %s is not connected", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
+ log::error("{} is not connected", ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
return BT_STATUS_FAIL;
}
tBTA_AG_RES_DATA ag_res = {};
@@ -1084,13 +1072,13 @@ bt_status_t HeadsetInterface::DeviceStatusNotification(
int batt_chg, RawAddress* bd_addr) {
CHECK_BTHF_INIT();
if (!bd_addr) {
- LOG_WARN("%s: bd_addr is null", __func__);
+ log::warn("bd_addr is null");
return BT_STATUS_FAIL;
}
int idx = btif_hf_idx_by_bdaddr(bd_addr);
if (idx < 0 || idx > BTA_AG_MAX_NUM_CLIENTS) {
- LOG_WARN("%s: invalid index %d for %s", __func__, idx,
- ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
+ log::warn("invalid index {} for {}", idx,
+ ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
return BT_STATUS_FAIL;
}
const btif_hf_cb_t& control_block = btif_hf_cb[idx];
@@ -1113,12 +1101,11 @@ bt_status_t HeadsetInterface::CopsResponse(const char* cops,
CHECK_BTHF_INIT();
int idx = btif_hf_idx_by_bdaddr(bd_addr);
if ((idx < 0) || (idx >= BTA_AG_MAX_NUM_CLIENTS)) {
- LOG_ERROR("%s: Invalid index %d", __func__, idx);
+ log::error("Invalid index {}", idx);
return BT_STATUS_FAIL;
}
if (!is_connected(bd_addr)) {
- LOG_ERROR("%s: %s is not connected", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
+ log::error("{} is not connected", ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
return BT_STATUS_FAIL;
}
tBTA_AG_RES_DATA ag_res = {};
@@ -1137,12 +1124,11 @@ bt_status_t HeadsetInterface::CindResponse(int svc, int num_active,
CHECK_BTHF_INIT();
int idx = btif_hf_idx_by_bdaddr(bd_addr);
if ((idx < 0) || (idx >= BTA_AG_MAX_NUM_CLIENTS)) {
- LOG_ERROR("%s: Invalid index %d", __func__, idx);
+ log::error("Invalid index {}", idx);
return BT_STATUS_FAIL;
}
if (!is_connected(bd_addr)) {
- LOG_ERROR("%s: %s is not connected", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
+ log::error("{} is not connected", ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
return BT_STATUS_FAIL;
}
tBTA_AG_RES_DATA ag_res = {};
@@ -1167,12 +1153,11 @@ bt_status_t HeadsetInterface::FormattedAtResponse(const char* rsp,
tBTA_AG_RES_DATA ag_res = {};
int idx = btif_hf_idx_by_bdaddr(bd_addr);
if ((idx < 0) || (idx >= BTA_AG_MAX_NUM_CLIENTS)) {
- LOG_ERROR("%s: Invalid index %d", __func__, idx);
+ log::error("Invalid index {}", idx);
return BT_STATUS_FAIL;
}
if (!is_connected(bd_addr)) {
- LOG_ERROR("%s: %s is not connected", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
+ log::error("{} is not connected", ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
return BT_STATUS_FAIL;
}
/* Format the response and send */
@@ -1186,12 +1171,11 @@ bt_status_t HeadsetInterface::AtResponse(bthf_at_response_t response_code,
CHECK_BTHF_INIT();
int idx = btif_hf_idx_by_bdaddr(bd_addr);
if ((idx < 0) || (idx >= BTA_AG_MAX_NUM_CLIENTS)) {
- LOG_ERROR("%s: Invalid index %d", __func__, idx);
+ log::error("Invalid index {}", idx);
return BT_STATUS_FAIL;
}
if (!is_connected(bd_addr)) {
- LOG_ERROR("%s: %s is not connected", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
+ log::error("{} is not connected", ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
return BT_STATUS_FAIL;
}
send_at_result(
@@ -1207,12 +1191,11 @@ bt_status_t HeadsetInterface::ClccResponse(
CHECK_BTHF_INIT();
int idx = btif_hf_idx_by_bdaddr(bd_addr);
if ((idx < 0) || (idx >= BTA_AG_MAX_NUM_CLIENTS)) {
- LOG_ERROR("%s: Invalid index %d", __func__, idx);
+ log::error("Invalid index {}", idx);
return BT_STATUS_FAIL;
}
if (!is_connected(bd_addr)) {
- LOG_ERROR("%s: %s is not connected", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
+ log::error("{} is not connected", ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
return BT_STATUS_FAIL;
}
tBTA_AG_RES_DATA ag_res = {};
@@ -1221,8 +1204,8 @@ bt_status_t HeadsetInterface::ClccResponse(
ag_res.ok_flag = BTA_AG_OK_DONE;
} else {
std::string cell_number(number ? number : "");
- LOG_VERBOSE(
- "clcc_response: [%d] dir %d state %d mode %d number = %s type = %d",
+ log::verbose(
+ "clcc_response: [{}] dir {} state {} mode {} number = {} type = {}",
index, dir, state, mode, PRIVATE_CELL(cell_number), type);
int res_strlen = snprintf(ag_res.str, sizeof(ag_res.str), "%d,%d,%d,%d,%d",
index, dir, state, mode, mpty);
@@ -1259,38 +1242,37 @@ bt_status_t HeadsetInterface::PhoneStateChange(
RawAddress* bd_addr) {
CHECK_BTHF_INIT();
if (bd_addr == nullptr) {
- LOG_WARN("bd_addr is null");
+ log::warn("bd_addr is null");
return BT_STATUS_FAIL;
}
const RawAddress raw_address(*bd_addr);
int idx = btif_hf_idx_by_bdaddr(bd_addr);
if (idx < 0 || idx >= BTA_AG_MAX_NUM_CLIENTS) {
- LOG_WARN("Invalid index %d for %s", idx, ADDRESS_TO_LOGGABLE_CSTR(raw_address));
+ log::warn("Invalid index {} for {}", idx,
+ ADDRESS_TO_LOGGABLE_CSTR(raw_address));
return BT_STATUS_FAIL;
}
const btif_hf_cb_t& control_block = btif_hf_cb[idx];
if (!IsSlcConnected(bd_addr)) {
- LOG(WARNING) << ": SLC not connected for "
- << ADDRESS_TO_LOGGABLE_STR(*bd_addr);
+ log::warn("SLC not connected for {}", ADDRESS_TO_LOGGABLE_STR(*bd_addr));
return BT_STATUS_NOT_READY;
}
if (call_setup_state == BTHF_CALL_STATE_DISCONNECTED) {
// HFP spec does not handle cases when a call is being disconnected.
// Since DISCONNECTED state must lead to IDLE state, ignoring it here.s
- LOG(INFO) << __func__
- << ": Ignore call state change to DISCONNECTED, idx=" << idx
- << ", addr="
- << ADDRESS_TO_LOGGABLE_STR(*bd_addr)
- << ", num_active=" << num_active
- << ", num_held=" << num_held;
+ log::info(
+ "Ignore call state change to DISCONNECTED, idx={}, addr={}, "
+ "num_active={}, num_held={}",
+ idx, ADDRESS_TO_LOGGABLE_STR(*bd_addr), num_active, num_held);
return BT_STATUS_SUCCESS;
}
- LOG_DEBUG(
- "bd_addr:%s active_bda:%s num_active:%u prev_num_active:%u num_held:%u "
- "prev_num_held:%u call_state:%s prev_call_state:%s",
- ADDRESS_TO_LOGGABLE_CSTR((*bd_addr)), ADDRESS_TO_LOGGABLE_CSTR(active_bda), num_active,
+ log::debug(
+ "bd_addr:{} active_bda:{} num_active:{} prev_num_active:{} num_held:{} "
+ "prev_num_held:{} call_state:{} prev_call_state:{}",
+ ADDRESS_TO_LOGGABLE_CSTR((*bd_addr)),
+ ADDRESS_TO_LOGGABLE_CSTR(active_bda), num_active,
control_block.num_active, num_held, control_block.num_held,
dump_hf_call_state(call_setup_state),
dump_hf_call_state(control_block.call_setup_state));
@@ -1329,10 +1311,8 @@ bt_status_t HeadsetInterface::PhoneStateChange(
(control_block.num_held == 0) &&
(control_block.call_setup_state == BTHF_CALL_STATE_IDLE)) {
tBTA_AG_RES_DATA ag_res = {};
- LOG_VERBOSE(
- "%s: Active/Held call notification received without call setup "
- "update",
- __func__);
+ log::verbose(
+ "Active/Held call notification received without call setup update");
ag_res.audio_handle = BTA_AG_HANDLE_SCO_NO_CHANGE;
// Addition call setup with the Active call
@@ -1351,9 +1331,9 @@ bt_status_t HeadsetInterface::PhoneStateChange(
if (call_setup_state != control_block.call_setup_state) {
tBTA_AG_RES_DATA ag_res = {};
ag_res.audio_handle = BTA_AG_HANDLE_SCO_NO_CHANGE;
- LOG_VERBOSE("%s: Call setup states changed. old: %s new: %s", __func__,
- dump_hf_call_state(control_block.call_setup_state),
- dump_hf_call_state(call_setup_state));
+ log::verbose("Call setup states changed. old: {} new: {}",
+ dump_hf_call_state(control_block.call_setup_state),
+ dump_hf_call_state(call_setup_state));
switch (call_setup_state) {
case BTHF_CALL_STATE_IDLE: {
switch (control_block.call_setup_state) {
@@ -1376,8 +1356,8 @@ bt_status_t HeadsetInterface::PhoneStateChange(
res = BTA_AG_CALL_CANCEL_RES;
break;
default:
- LOG_ERROR("%s: Incorrect call state prev=%d, now=%d", __func__,
- control_block.call_setup_state, call_setup_state);
+ log::error("Incorrect call state prev={}, now={}",
+ control_block.call_setup_state, call_setup_state);
status = BT_STATUS_PARM_INVALID;
break;
}
@@ -1464,13 +1444,13 @@ bt_status_t HeadsetInterface::PhoneStateChange(
res = BTA_AG_OUT_CALL_ALERT_RES;
break;
default:
- LOG_ERROR("%s: Incorrect call state prev=%d, now=%d", __func__,
- control_block.call_setup_state, call_setup_state);
+ log::error("Incorrect call state prev={}, now={}",
+ control_block.call_setup_state, call_setup_state);
status = BT_STATUS_PARM_INVALID;
break;
}
- LOG_VERBOSE("%s: Call setup state changed. res=%d, audio_handle=%d",
- __func__, res, ag_res.audio_handle);
+ log::verbose("Call setup state changed. res={}, audio_handle={}", res,
+ ag_res.audio_handle);
if (res != 0xFF) {
BTA_AgResult(control_block.handle, res, ag_res);
@@ -1500,9 +1480,9 @@ bt_status_t HeadsetInterface::PhoneStateChange(
if (!active_call_updated &&
((num_active + num_held) !=
(control_block.num_active + control_block.num_held))) {
- VLOG(1) << __func__ << ": in progress call states changed, active=["
- << control_block.num_active << "->" << num_active << "], held=["
- << control_block.num_held << "->" << num_held;
+ log::verbose(
+ "in progress call states changed, active=[{}->{}], held=[{}->{}]",
+ control_block.num_active, num_active, control_block.num_held, num_held);
send_indicator_update(control_block, BTA_AG_IND_CALL,
((num_active + num_held) > 0) ? BTA_AG_CALL_ACTIVE
: BTA_AG_CALL_INACTIVE);
@@ -1511,8 +1491,8 @@ bt_status_t HeadsetInterface::PhoneStateChange(
/* Held Changed? */
if (num_held != control_block.num_held ||
((num_active == 0) && ((num_held + control_block.num_held) > 1))) {
- LOG_VERBOSE("%s: Held call states changed. old: %d new: %d", __func__,
- control_block.num_held, num_held);
+ log::verbose("Held call states changed. old: {} new: {}",
+ control_block.num_held, num_held);
send_indicator_update(control_block, BTA_AG_IND_CALLHELD,
((num_held == 0) ? 0 : ((num_active == 0) ? 2 : 1)));
}
@@ -1521,7 +1501,7 @@ bt_status_t HeadsetInterface::PhoneStateChange(
if ((call_setup_state == control_block.call_setup_state) &&
(num_active && num_held) && (num_active == control_block.num_active) &&
(num_held == control_block.num_held)) {
- LOG_VERBOSE("%s: Calls swapped", __func__);
+ log::verbose("Calls swapped");
send_indicator_update(control_block, BTA_AG_IND_CALLHELD, 1);
}
@@ -1548,7 +1528,7 @@ bt_status_t HeadsetInterface::PhoneStateChange(
}
void HeadsetInterface::Cleanup() {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
btif_queue_cleanup(UUID_SERVCLASS_AG_HANDSFREE);
@@ -1583,13 +1563,12 @@ bt_status_t HeadsetInterface::SendBsir(bool value, RawAddress* bd_addr) {
CHECK_BTHF_INIT();
int idx = btif_hf_idx_by_bdaddr(bd_addr);
if ((idx < 0) || (idx >= BTA_AG_MAX_NUM_CLIENTS)) {
- LOG_ERROR("%s: Invalid index %d for %s", __func__, idx,
- ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
+ log::error("Invalid index {} for {}", idx,
+ ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
return BT_STATUS_FAIL;
}
if (!is_connected(bd_addr)) {
- LOG_ERROR("%s: %s not connected", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
+ log::error("{} not connected", ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
return BT_STATUS_FAIL;
}
tBTA_AG_RES_DATA ag_result = {};
@@ -1628,7 +1607,7 @@ bt_status_t HeadsetInterface::DebugDump() {
*
******************************************************************************/
bt_status_t ExecuteService(bool b_enable) {
- LOG_INFO("service starts to: %s", b_enable ? "Initialize" : "Shutdown");
+ log::info("service starts to: {}", b_enable ? "Initialize" : "Shutdown");
const char* service_names_raw[] = BTIF_HF_SERVICE_NAMES;
std::vector<std::string> service_names;
for (const char* service_name_raw : service_names_raw) {
@@ -1664,7 +1643,7 @@ bt_status_t ExecuteService(bool b_enable) {
*
******************************************************************************/
Interface* GetInterface() {
- VLOG(0) << __func__;
+ log::verbose("");
return HeadsetInterface::GetInstance();
}
diff --git a/system/btif/src/btif_hf_client.cc b/system/btif/src/btif_hf_client.cc
index c46f85e5c9..b66b48b2e3 100644
--- a/system/btif/src/btif_hf_client.cc
+++ b/system/btif/src/btif_hf_client.cc
@@ -47,6 +47,7 @@
#endif
#include <base/logging.h>
+#include <bluetooth/log.h>
#include <hardware/bluetooth.h>
#include <hardware/bt_hf_client.h>
#include <string.h>
@@ -68,6 +69,8 @@
#define BTIF_HF_CLIENT_SERVICE_NAME ("Handsfree")
#endif
+using namespace bluetooth;
+
/*******************************************************************************
* Local type definitions
******************************************************************************/
@@ -112,28 +115,28 @@ static const char* dump_hf_client_conn_state(uint16_t event) {
}
}
-#define CHECK_BTHF_CLIENT_INIT() \
- do { \
- if (bt_hf_client_callbacks == NULL) { \
- LOG_WARN("BTHF CLIENT: %s: not initialized", __func__); \
- return BT_STATUS_NOT_READY; \
- } else { \
- LOG_VERBOSE("BTHF CLIENT: %s", __func__); \
- } \
+#define CHECK_BTHF_CLIENT_INIT() \
+ do { \
+ if (bt_hf_client_callbacks == NULL) { \
+ log::warn("BTHF CLIENT: not initialized"); \
+ return BT_STATUS_NOT_READY; \
+ } else { \
+ log::verbose("BTHF CLIENT: ok"); \
+ } \
} while (0)
-#define CHECK_BTHF_CLIENT_SLC_CONNECTED(cb) \
- do { \
- if (bt_hf_client_callbacks == NULL) { \
- LOG_WARN("BTHF CLIENT: %s: not initialized", __func__); \
- return BT_STATUS_NOT_READY; \
- } else if ((cb)->state != BTHF_CLIENT_CONNECTION_STATE_SLC_CONNECTED) { \
- LOG_WARN("BTHF CLIENT: %s: SLC connection not up. state=%s", __func__, \
- dump_hf_client_conn_state((cb)->state)); \
- return BT_STATUS_NOT_READY; \
- } else { \
- LOG_VERBOSE("BTHF CLIENT: %s", __func__); \
- } \
+#define CHECK_BTHF_CLIENT_SLC_CONNECTED(cb) \
+ do { \
+ if (bt_hf_client_callbacks == NULL) { \
+ log::warn("BTHF CLIENT: not initialized"); \
+ return BT_STATUS_NOT_READY; \
+ } else if ((cb)->state != BTHF_CLIENT_CONNECTION_STATE_SLC_CONNECTED) { \
+ log::warn("BTHF CLIENT: SLC connection not up. state={}", \
+ dump_hf_client_conn_state((cb)->state)); \
+ return BT_STATUS_NOT_READY; \
+ } else { \
+ log::verbose("BTHF CLIENT: ok"); \
+ } \
} while (0)
static btif_hf_client_cb_arr_t btif_hf_client_cb_arr;
@@ -155,22 +158,22 @@ static btif_hf_client_cb_arr_t btif_hf_client_cb_arr;
******************************************************************************/
constexpr uint16_t BTIF_HF_CLIENT_CB_AUDIO_CONNECTING = 0x8501;
static void btif_in_hf_client_generic_evt(uint16_t event, char* p_param) {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
RawAddress* bd_addr = (RawAddress*)p_param;
btif_hf_client_cb_t* cb = btif_hf_client_get_cb_by_bda(*bd_addr);
if (cb == NULL || !is_connected(cb)) {
- LOG_ERROR("%s: failed to find block for bda", __func__);
+ log::error("failed to find block for bda");
return;
}
- LOG_VERBOSE("%s: event=%d", __func__, event);
+ log::verbose("event={}", event);
switch (event) {
case BTIF_HF_CLIENT_CB_AUDIO_CONNECTING: {
HAL_CBACK(bt_hf_client_callbacks, audio_state_cb, &cb->peer_bda,
(bthf_client_audio_state_t)BTHF_CLIENT_AUDIO_STATE_CONNECTING);
} break;
default: {
- LOG_WARN("%s: : Unknown event 0x%x", __func__, event);
+ log::warn(": Unknown event 0x{:x}", event);
} break;
}
}
@@ -183,7 +186,7 @@ bool is_connected(const btif_hf_client_cb_t* cb) {
(cb->state == BTHF_CLIENT_CONNECTION_STATE_SLC_CONNECTED))
return true;
- LOG_ERROR("%s: not connected!", __func__);
+ log::error("not connected!");
return false;
}
@@ -197,7 +200,7 @@ bool is_connected(const btif_hf_client_cb_t* cb) {
*
******************************************************************************/
btif_hf_client_cb_t* btif_hf_client_get_cb_by_handle(uint16_t handle) {
- LOG_VERBOSE("%s: cb by handle %d", __func__, handle);
+ log::verbose("cb by handle {}", handle);
for (int i = 0; i < HF_CLIENT_MAX_DEVICES; i++) {
// Block is valid only if it is allocated i.e. state is not DISCONNECTED
if (btif_hf_client_cb_arr.cb[i].state !=
@@ -206,7 +209,7 @@ btif_hf_client_cb_t* btif_hf_client_get_cb_by_handle(uint16_t handle) {
return &btif_hf_client_cb_arr.cb[i];
}
}
- LOG_ERROR("%s: could not find block for handle %d", __func__, handle);
+ log::error("could not find block for handle {}", handle);
return NULL;
}
@@ -220,7 +223,7 @@ btif_hf_client_cb_t* btif_hf_client_get_cb_by_handle(uint16_t handle) {
*
******************************************************************************/
btif_hf_client_cb_t* btif_hf_client_get_cb_by_bda(const RawAddress& bd_addr) {
- VLOG(1) << __func__ << " incoming addr " << ADDRESS_TO_LOGGABLE_CSTR(bd_addr);
+ log::verbose("incoming addr {}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
for (int i = 0; i < HF_CLIENT_MAX_DEVICES; i++) {
// Block is valid only if it is allocated i.e. state is not DISCONNECTED
@@ -230,7 +233,7 @@ btif_hf_client_cb_t* btif_hf_client_get_cb_by_bda(const RawAddress& bd_addr) {
return &btif_hf_client_cb_arr.cb[i];
}
}
- LOG_ERROR("%s: could not find block for bdaddr", __func__);
+ log::error("could not find block for bdaddr");
return NULL;
}
@@ -250,7 +253,7 @@ btif_hf_client_cb_t* btif_hf_client_allocate_cb() {
return cb;
}
}
- LOG_ERROR("%s: unable to allocate control block", __func__);
+ log::error("unable to allocate control block");
return NULL;
}
@@ -270,7 +273,7 @@ btif_hf_client_cb_t* btif_hf_client_allocate_cb() {
*
******************************************************************************/
static bt_status_t init(bthf_client_callbacks_t* callbacks) {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
bt_hf_client_callbacks = callbacks;
@@ -293,7 +296,7 @@ static bt_status_t init(bthf_client_callbacks_t* callbacks) {
static bt_status_t connect_int(RawAddress* bd_addr, uint16_t uuid) {
btif_hf_client_cb_t* cb = btif_hf_client_allocate_cb();
if (cb == NULL) {
- LOG_ERROR("%s: could not allocate block!", __func__);
+ log::error("could not allocate block!");
return BT_STATUS_BUSY;
}
@@ -311,7 +314,7 @@ static bt_status_t connect_int(RawAddress* bd_addr, uint16_t uuid) {
}
static bt_status_t connect(const RawAddress* bd_addr) {
- LOG_VERBOSE("HFP Client version is %s", btif_hf_client_version);
+ log::verbose("HFP Client version is {}", btif_hf_client_version);
CHECK_BTHF_CLIENT_INIT();
return btif_queue_connect(UUID_SERVCLASS_HF_HANDSFREE, bd_addr, connect_int);
}
@@ -704,7 +707,7 @@ static bt_status_t request_last_voice_tag_number(const RawAddress* bd_addr) {
*
******************************************************************************/
static void cleanup(void) {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
btif_queue_cleanup(UUID_SERVCLASS_HF_HANDSFREE);
if (bt_hf_client_callbacks) {
@@ -729,8 +732,8 @@ static bt_status_t send_at_cmd(const RawAddress* bd_addr, int cmd, int val1,
CHECK_BTHF_CLIENT_SLC_CONNECTED(cb);
- LOG_VERBOSE("%s: Cmd %d val1 %d val2 %d arg %s", __func__, cmd, val1, val2,
- (arg != NULL) ? arg : "<null>");
+ log::verbose("Cmd {} val1 {} val2 {} arg {}", cmd, val1, val2,
+ (arg != NULL) ? arg : "<null>");
BTA_HfClientSendAT(cb->handle, cmd, val1, val2, arg);
return BT_STATUS_SUCCESS;
@@ -751,7 +754,7 @@ static bt_status_t send_android_at(const RawAddress* bd_addr, const char* arg) {
CHECK_BTHF_CLIENT_SLC_CONNECTED(cb);
- LOG_VERBOSE("%s: val1 %s", __func__, arg);
+ log::verbose("val1 {}", arg);
BTA_HfClientSendAT(cb->handle, BTA_HF_CLIENT_AT_CMD_ANDROID, 0, 0, arg);
return BT_STATUS_SUCCESS;
@@ -781,7 +784,7 @@ static const bthf_client_interface_t bthfClientInterface = {
};
static void process_ind_evt(tBTA_HF_CLIENT_IND* ind) {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
btif_hf_client_cb_t* cb = btif_hf_client_get_cb_by_bda(ind->bd_addr);
if (cb == NULL || !is_connected(cb)) return;
@@ -840,23 +843,20 @@ static void btif_hf_client_upstreams_evt(uint16_t event, char* p_param) {
btif_hf_client_cb_t* cb = btif_hf_client_get_cb_by_bda(p_data->bd_addr);
if (cb == NULL && event == BTA_HF_CLIENT_OPEN_EVT) {
- LOG_VERBOSE("%s: event BTA_HF_CLIENT_OPEN_EVT allocating block", __func__);
+ log::verbose("event BTA_HF_CLIENT_OPEN_EVT allocating block");
cb = btif_hf_client_allocate_cb();
if (cb == NULL) {
- LOG_ERROR("%s: event BTA_HF_CLIENT_OPEN_EVT failed to allocate cb",
- __func__);
+ log::error("event BTA_HF_CLIENT_OPEN_EVT failed to allocate cb");
return;
}
cb->handle = p_data->open.handle;
cb->peer_bda = p_data->open.bd_addr;
} else if (cb == NULL) {
- LOG_ERROR("%s: event %d but not allocating block: cb not found", __func__,
- event);
+ log::error("event {} but not allocating block: cb not found", event);
return;
}
- LOG_VERBOSE("%s: event=%s (%u)", __func__, dump_hf_client_event(event),
- event);
+ log::verbose("event={} ({})", dump_hf_client_event(event), event);
switch (event) {
case BTA_HF_CLIENT_OPEN_EVT:
@@ -868,10 +868,10 @@ static void btif_hf_client_upstreams_evt(uint16_t event, char* p_param) {
} else if (cb->state == BTHF_CLIENT_CONNECTION_STATE_CONNECTING) {
cb->state = BTHF_CLIENT_CONNECTION_STATE_DISCONNECTED;
} else {
- LOG_WARN(
- "%s: HF CLient open failed, but another device connected. "
- "status=%d state=%d connected device=%s",
- __func__, p_data->open.status, cb->state,
+ log::warn(
+ "HF CLient open failed, but another device connected. status={} "
+ "state={} connected device={}",
+ p_data->open.status, cb->state,
ADDRESS_TO_LOGGABLE_CSTR(cb->peer_bda));
break;
}
@@ -1040,7 +1040,7 @@ static void btif_hf_client_upstreams_evt(uint16_t event, char* p_param) {
p_data->unknown.event_string);
break;
default:
- LOG_WARN("%s: Unhandled event: %d", __func__, event);
+ log::warn("Unhandled event: {}", event);
break;
}
}
@@ -1078,7 +1078,7 @@ static void bta_hf_client_evt(tBTA_HF_CLIENT_EVT event,
*
******************************************************************************/
bt_status_t btif_hf_client_execute_service(bool b_enable) {
- LOG_VERBOSE("%s: enable: %d", __func__, b_enable);
+ log::verbose("enable: {}", b_enable);
tBTA_HF_CLIENT_FEAT features = get_default_hf_client_features();
uint16_t hfp_version = get_default_hfp_version();
@@ -1092,7 +1092,7 @@ bt_status_t btif_hf_client_execute_service(bool b_enable) {
if (b_enable) {
/* Enable and register with BTA-HFClient */
- LOG_VERBOSE("%s: support codec negotiation %d ", __func__, features);
+ log::verbose("support codec negotiation {}", features);
BTA_HfClientEnable(bta_hf_client_evt, features,
BTIF_HF_CLIENT_SERVICE_NAME);
} else {
@@ -1111,6 +1111,6 @@ bt_status_t btif_hf_client_execute_service(bool b_enable) {
*
******************************************************************************/
const bthf_client_interface_t* btif_hf_client_get_interface(void) {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
return &bthfClientInterface;
}
diff --git a/system/btif/src/btif_hh.cc b/system/btif/src/btif_hh.cc
index 968af1ae12..56887822a0 100644
--- a/system/btif/src/btif_hh.cc
+++ b/system/btif/src/btif_hh.cc
@@ -30,6 +30,7 @@
#include "btif/include/btif_hh.h"
#include <base/logging.h>
+#include <bluetooth/log.h>
#include <cstdint>
@@ -62,6 +63,8 @@
#define LOGITECH_KB_MX5500_VENDOR_ID 0x046D
#define LOGITECH_KB_MX5500_PRODUCT_ID 0xB30B
+using namespace bluetooth;
+
static int btif_hh_keylockstates = 0; // The current key state of each key
#define BTIF_TIMEOUT_VUP_MS (3 * 1000)
@@ -103,12 +106,12 @@ static tHID_KB_LIST hid_kb_numlock_on_list[] = {{LOGITECH_KB_MX5500_PRODUCT_ID,
LOGITECH_KB_MX5500_VENDOR_ID,
"Logitech MX5500 Keyboard"}};
-#define CHECK_BTHH_INIT() \
- do { \
- if (bt_hh_callbacks == NULL) { \
- LOG_WARN("BTHH: %s: BTHH not initialized", __func__); \
- return BT_STATUS_NOT_READY; \
- } \
+#define CHECK_BTHH_INIT() \
+ do { \
+ if (bt_hh_callbacks == NULL) { \
+ log::warn("BTHH: BTHH not initialized"); \
+ return BT_STATUS_NOT_READY; \
+ } \
} while (0)
/*******************************************************************************
@@ -160,8 +163,7 @@ static void set_keylockstate(int keymask, bool isSet) {
******************************************************************************/
static void toggle_os_keylockstates(int fd, int changedlockstates) {
- LOG_VERBOSE("%s: fd = %d, changedlockstates = 0x%x", __func__, fd,
- changedlockstates);
+ log::verbose("fd = {}, changedlockstates = 0x{:x}", fd, changedlockstates);
uint8_t hidreport[9];
int reportIndex;
memset(hidreport, 0, 9);
@@ -169,40 +171,32 @@ static void toggle_os_keylockstates(int fd, int changedlockstates) {
reportIndex = 4;
if (changedlockstates & BTIF_HH_KEYSTATE_MASK_CAPSLOCK) {
- LOG_VERBOSE("%s Setting CAPSLOCK", __func__);
+ log::verbose("Setting CAPSLOCK");
hidreport[reportIndex++] = (uint8_t)HID_REPORT_CAPSLOCK;
}
if (changedlockstates & BTIF_HH_KEYSTATE_MASK_NUMLOCK) {
- LOG_VERBOSE("%s Setting NUMLOCK", __func__);
+ log::verbose("Setting NUMLOCK");
hidreport[reportIndex++] = (uint8_t)HID_REPORT_NUMLOCK;
}
if (changedlockstates & BTIF_HH_KEYSTATE_MASK_SCROLLLOCK) {
- LOG_VERBOSE("%s Setting SCROLLLOCK", __func__);
+ log::verbose("Setting SCROLLLOCK");
hidreport[reportIndex++] = (uint8_t)HID_REPORT_SCROLLLOCK;
}
- LOG_VERBOSE(
- "Writing hidreport #1 to os: "
- "%s: %x %x %x",
- __func__, hidreport[0], hidreport[1], hidreport[2]);
- LOG_VERBOSE("%s: %x %x %x", __func__, hidreport[3], hidreport[4],
- hidreport[5]);
- LOG_VERBOSE("%s: %x %x %x", __func__, hidreport[6], hidreport[7],
- hidreport[8]);
+ log::verbose("Writing hidreport #1 to os:");
+ log::verbose("| {:x} {:x} {:x}", hidreport[0], hidreport[1], hidreport[2]);
+ log::verbose("| {:x} {:x} {:x}", hidreport[3], hidreport[4], hidreport[5]);
+ log::verbose("| {:x} {:x} {:x}", hidreport[6], hidreport[7], hidreport[8]);
bta_hh_co_write(fd, hidreport, sizeof(hidreport));
usleep(200000);
memset(hidreport, 0, 9);
hidreport[0] = 1;
- LOG_VERBOSE(
- "Writing hidreport #2 to os: "
- "%s: %x %x %x",
- __func__, hidreport[0], hidreport[1], hidreport[2]);
- LOG_VERBOSE("%s: %x %x %x", __func__, hidreport[3], hidreport[4],
- hidreport[5]);
- LOG_VERBOSE("%s: %x %x %x ", __func__, hidreport[6], hidreport[7],
- hidreport[8]);
+ log::verbose("Writing hidreport #2 to os:");
+ log::verbose("| {:x} {:x} {:x}", hidreport[0], hidreport[1], hidreport[2]);
+ log::verbose("| {:x} {:x} {:x}", hidreport[3], hidreport[4], hidreport[5]);
+ log::verbose("| {:x} {:x} {:x}", hidreport[6], hidreport[7], hidreport[8]);
bta_hh_co_write(fd, hidreport, sizeof(hidreport));
}
@@ -241,8 +235,8 @@ static void update_keyboard_lockstates(btif_hh_device_t* p_dev) {
static_cast<uint8_t>(btif_hh_keylockstates)}; /* keystate */
/* Set report for other keyboards */
- LOG_VERBOSE("%s: setting report on dev_handle %d to 0x%x", __func__,
- p_dev->dev_handle, btif_hh_keylockstates);
+ log::verbose("setting report on dev_handle {} to 0x{:x}", p_dev->dev_handle,
+ btif_hh_keylockstates);
/* Get SetReport buffer */
p_buf = create_pbuf(len, data);
@@ -265,10 +259,7 @@ static void update_keyboard_lockstates(btif_hh_device_t* p_dev) {
static void sync_lockstate_on_connect(btif_hh_device_t* p_dev) {
int keylockstates;
- LOG_VERBOSE(
- "%s: Syncing keyboard lock states after "
- "reconnect...",
- __func__);
+ log::verbose("Syncing keyboard lock states after reconnect...");
/*If the device is connected, update keyboard state */
update_keyboard_lockstates(p_dev);
@@ -277,17 +268,15 @@ static void sync_lockstate_on_connect(btif_hh_device_t* p_dev) {
so the lockstate is in sync */
keylockstates = get_keylockstates();
if (keylockstates) {
- LOG_VERBOSE(
- "%s: Sending hid report to kernel "
- "indicating lock key state 0x%x",
- __func__, keylockstates);
+ log::verbose(
+ "Sending hid report to kernel indicating lock key state 0x{:x}",
+ keylockstates);
usleep(200000);
toggle_os_keylockstates(p_dev->fd, keylockstates);
} else {
- LOG_VERBOSE(
- "%s: NOT sending hid report to kernel "
- "indicating lock key state 0x%x",
- __func__, keylockstates);
+ log::verbose(
+ "NOT sending hid report to kernel indicating lock key state 0x{:x}",
+ keylockstates);
}
}
@@ -364,7 +353,7 @@ static void btif_hh_stop_vup_timer(tAclLinkSpec* link_spec) {
btif_hh_device_t* p_dev = btif_hh_find_connected_dev_by_bda(*link_spec);
if (p_dev != NULL) {
- LOG_VERBOSE("stop VUP timer");
+ log::verbose("stop VUP timer");
alarm_free(p_dev->vup_timer);
p_dev->vup_timer = NULL;
}
@@ -378,7 +367,7 @@ static void btif_hh_stop_vup_timer(tAclLinkSpec* link_spec) {
* Returns void
******************************************************************************/
static void btif_hh_start_vup_timer(const tAclLinkSpec* link_spec) {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
btif_hh_device_t* p_dev = btif_hh_find_connected_dev_by_bda(*link_spec);
CHECK(p_dev != NULL);
@@ -402,7 +391,7 @@ static void hh_connect_complete(uint8_t handle, tAclLinkSpec& link_spec,
}
static void hh_open_handler(tBTA_HH_CONN& conn) {
- LOG_DEBUG("status = %d, handle = %d", conn.status, conn.handle);
+ log::debug("status = {}, handle = {}", conn.status, conn.handle);
HAL_CBACK(bt_hh_callbacks, connection_state_cb,
(RawAddress*)&conn.link_spec.addrt.bda, BTHH_CONN_STATE_CONNECTING);
@@ -422,7 +411,7 @@ static void hh_open_handler(tBTA_HH_CONN& conn) {
/* Initialize device driver */
if (!bta_hh_co_open(conn.handle, conn.sub_class, conn.attr_mask,
conn.app_id)) {
- LOG_WARN("Failed to find the uhid driver");
+ log::warn("Failed to find the uhid driver");
hh_connect_complete(conn.handle, conn.link_spec, BTIF_HH_DEV_DISCONNECTED);
return;
}
@@ -431,12 +420,12 @@ static void hh_open_handler(tBTA_HH_CONN& conn) {
if (p_dev == NULL) {
/* The connect request must have come from device side and exceeded the
* connected HID device number. */
- LOG_WARN("Cannot find device with handle %d", conn.handle);
+ log::warn("Cannot find device with handle {}", conn.handle);
hh_connect_complete(conn.handle, conn.link_spec, BTIF_HH_DEV_DISCONNECTED);
return;
}
- LOG_INFO("Found device, getting dscp info for handle %d", conn.handle);
+ log::info("Found device, getting dscp info for handle {}", conn.handle);
p_dev->link_spec = conn.link_spec;
p_dev->dev_status = BTHH_CONN_STATE_CONNECTED;
@@ -463,14 +452,13 @@ bool btif_hh_add_added_dev(const tAclLinkSpec& link_spec,
for (i = 0; i < BTIF_HH_MAX_ADDED_DEV; i++) {
if (btif_hh_cb.added_devices[i].link_spec.addrt.bda ==
link_spec.addrt.bda) {
- LOG(WARNING) << " Device " << ADDRESS_TO_LOGGABLE_STR(link_spec)
- << " already added";
+ log::warn("Device {} already added", ADDRESS_TO_LOGGABLE_STR(link_spec));
return false;
}
}
for (i = 0; i < BTIF_HH_MAX_ADDED_DEV; i++) {
if (btif_hh_cb.added_devices[i].link_spec.addrt.bda.IsEmpty()) {
- LOG(WARNING) << " Added device " << ADDRESS_TO_LOGGABLE_STR(link_spec);
+ log::warn("Added device {}", ADDRESS_TO_LOGGABLE_STR(link_spec));
btif_hh_cb.added_devices[i].link_spec = link_spec;
btif_hh_cb.added_devices[i].dev_handle = BTA_HH_INVALID_HANDLE;
btif_hh_cb.added_devices[i].attr_mask = attr_mask;
@@ -478,7 +466,7 @@ bool btif_hh_add_added_dev(const tAclLinkSpec& link_spec,
}
}
- LOG_WARN("%s: Error, out of space to add device", __func__);
+ log::warn("Error, out of space to add device");
return false;
}
@@ -495,7 +483,7 @@ void btif_hh_remove_device(const tAclLinkSpec& link_spec) {
btif_hh_device_t* p_dev;
btif_hh_added_device_t* p_added_dev;
- LOG(INFO) << __func__ << ": transport = " << link_spec.ToString();
+ log::info("transport = {}", link_spec.ToString());
for (i = 0; i < BTIF_HH_MAX_ADDED_DEV; i++) {
p_added_dev = &btif_hh_cb.added_devices[i];
@@ -510,8 +498,7 @@ void btif_hh_remove_device(const tAclLinkSpec& link_spec) {
p_dev = btif_hh_find_dev_by_bda(link_spec);
if (p_dev == NULL) {
- LOG(WARNING) << " Oops, can't find device "
- << ADDRESS_TO_LOGGABLE_STR(link_spec);
+ log::warn("Oops, can't find device {}", ADDRESS_TO_LOGGABLE_STR(link_spec));
return;
}
@@ -532,7 +519,7 @@ void btif_hh_remove_device(const tAclLinkSpec& link_spec) {
if (btif_hh_cb.device_num > 0) {
btif_hh_cb.device_num--;
} else {
- LOG_WARN("%s: device_num = 0", __func__);
+ log::warn("device_num = 0");
}
bta_hh_co_close(p_dev);
@@ -569,13 +556,13 @@ bool btif_hh_copy_hid_info(tBTA_HH_DEV_DSCP_INFO* dest,
******************************************************************************/
bt_status_t btif_hh_virtual_unplug(const tAclLinkSpec* link_spec) {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
btif_hh_device_t* p_dev;
p_dev = btif_hh_find_dev_by_bda(*link_spec);
if ((p_dev != NULL) && (p_dev->dev_status == BTHH_CONN_STATE_CONNECTED) &&
(p_dev->attr_mask & HID_VIRTUAL_CABLE)) {
- LOG_VERBOSE("%s: Sending BTA_HH_CTRL_VIRTUAL_CABLE_UNPLUG for: %s",
- __func__, ADDRESS_TO_LOGGABLE_CSTR(*link_spec));
+ log::verbose("Sending BTA_HH_CTRL_VIRTUAL_CABLE_UNPLUG for: {}",
+ ADDRESS_TO_LOGGABLE_CSTR(*link_spec));
/* start the timer */
btif_hh_start_vup_timer(link_spec);
p_dev->local_vup = true;
@@ -583,16 +570,16 @@ bt_status_t btif_hh_virtual_unplug(const tAclLinkSpec* link_spec) {
return BT_STATUS_SUCCESS;
} else if ((p_dev != NULL) &&
(p_dev->dev_status == BTHH_CONN_STATE_CONNECTED)) {
- LOG_ERROR("%s: Virtual unplug not supported, disconnecting device: %s",
- __func__, ADDRESS_TO_LOGGABLE_CSTR(*link_spec));
+ log::error("Virtual unplug not supported, disconnecting device: {}",
+ ADDRESS_TO_LOGGABLE_CSTR(*link_spec));
/* start the timer */
btif_hh_start_vup_timer(link_spec);
p_dev->local_vup = true;
BTA_HhClose(p_dev->dev_handle);
return BT_STATUS_SUCCESS;
} else {
- LOG_ERROR("%s: Error, device %s not opened, status = %d", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(*link_spec), btif_hh_cb.status);
+ log::error("Error, device {} not opened, status = {}",
+ ADDRESS_TO_LOGGABLE_CSTR(*link_spec), btif_hh_cb.status);
if ((btif_hh_cb.pending_link_spec.addrt.bda == link_spec->addrt.bda) &&
(btif_hh_cb.status == BTIF_HH_DEV_CONNECTING)) {
btif_hh_cb.status = (BTIF_HH_STATUS)BTIF_HH_DEV_DISCONNECTED;
@@ -625,12 +612,12 @@ bt_status_t btif_hh_connect(const tAclLinkSpec* link_spec) {
btif_hh_added_device_t* added_dev = NULL;
CHECK_BTHH_INIT();
- LOG_VERBOSE("BTHH: %s", __func__);
+ log::verbose("BTHH");
btif_hh_device_t* dev = btif_hh_find_dev_by_bda(*link_spec);
if (!dev && btif_hh_cb.device_num >= BTIF_HH_MAX_HID) {
// No space for more HID device now.
- LOG_WARN("%s: Error, exceeded the maximum supported HID device number %d",
- __func__, BTIF_HH_MAX_HID);
+ log::warn("Error, exceeded the maximum supported HID device number {}",
+ BTIF_HH_MAX_HID);
return BT_STATUS_NOMEM;
}
@@ -638,19 +625,16 @@ bt_status_t btif_hh_connect(const tAclLinkSpec* link_spec) {
if (btif_hh_cb.added_devices[i].link_spec.addrt.bda ==
link_spec->addrt.bda) {
added_dev = &btif_hh_cb.added_devices[i];
- LOG(WARNING) << __func__ << ": Device "
- << ADDRESS_TO_LOGGABLE_STR(*link_spec)
- << " already added, attr_mask = 0x" << std::hex
- << added_dev->attr_mask;
+ log::warn("Device {} already added, attr_mask = 0x{:x}",
+ ADDRESS_TO_LOGGABLE_STR(*link_spec), added_dev->attr_mask);
}
}
if (added_dev != NULL) {
if (added_dev->dev_handle == BTA_HH_INVALID_HANDLE) {
// No space for more HID device now.
- LOG(ERROR) << __func__ << ": Error, device "
- << ADDRESS_TO_LOGGABLE_STR(*link_spec)
- << " added but addition failed";
+ log::error("Error, device {} added but addition failed",
+ ADDRESS_TO_LOGGABLE_STR(*link_spec));
added_dev->link_spec = {};
added_dev->dev_handle = BTA_HH_INVALID_HANDLE;
return BT_STATUS_NOMEM;
@@ -658,8 +642,8 @@ bt_status_t btif_hh_connect(const tAclLinkSpec* link_spec) {
}
if (dev && dev->dev_status == BTHH_CONN_STATE_CONNECTED) {
- LOG_DEBUG("HidHost profile already connected for %s",
- ADDRESS_TO_LOGGABLE_CSTR((*link_spec)));
+ log::debug("HidHost profile already connected for {}",
+ ADDRESS_TO_LOGGABLE_CSTR((*link_spec)));
return BT_STATUS_SUCCESS;
}
@@ -694,12 +678,12 @@ void btif_hh_disconnect(tAclLinkSpec* link_spec) {
CHECK(link_spec != nullptr);
const btif_hh_device_t* p_dev = btif_hh_find_connected_dev_by_bda(*link_spec);
if (p_dev == nullptr) {
- LOG_DEBUG("Unable to disconnect unknown HID device:%s",
- ADDRESS_TO_LOGGABLE_CSTR((*link_spec)));
+ log::debug("Unable to disconnect unknown HID device:{}",
+ ADDRESS_TO_LOGGABLE_CSTR((*link_spec)));
return;
}
- LOG_DEBUG("Disconnect and close request for HID device:%s",
- ADDRESS_TO_LOGGABLE_CSTR((*link_spec)));
+ log::debug("Disconnect and close request for HID device:{}",
+ ADDRESS_TO_LOGGABLE_CSTR((*link_spec)));
BTA_HhClose(p_dev->dev_handle);
}
@@ -716,8 +700,7 @@ void btif_hh_setreport(btif_hh_device_t* p_dev, bthh_report_type_t r_type,
uint16_t size, uint8_t* report) {
BT_HDR* p_buf = create_pbuf(size, report);
if (p_buf == NULL) {
- LOG_ERROR("%s: Error, failed to allocate RPT buffer, size = %d", __func__,
- size);
+ log::error("Error, failed to allocate RPT buffer, size = {}", size);
return;
}
BTA_HhSetReport(p_dev->dev_handle, r_type, p_buf);
@@ -735,8 +718,7 @@ void btif_hh_setreport(btif_hh_device_t* p_dev, bthh_report_type_t r_type,
void btif_hh_senddata(btif_hh_device_t* p_dev, uint16_t size, uint8_t* report) {
BT_HDR* p_buf = create_pbuf(size, report);
if (p_buf == NULL) {
- LOG_ERROR("%s: Error, failed to allocate RPT buffer, size = %d", __func__,
- size);
+ log::error("Error, failed to allocate RPT buffer, size = {}", size);
return;
}
p_buf->layer_specific = BTA_HH_RPTT_OUTPUT;
@@ -753,9 +735,9 @@ void btif_hh_senddata(btif_hh_device_t* p_dev, uint16_t size, uint8_t* report) {
*
******************************************************************************/
void btif_hh_service_registration(bool enable) {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
- LOG_VERBOSE("enable = %d", enable);
+ log::verbose("enable = {}", enable);
if (bt_hh_callbacks == NULL) {
// The HID Host service was never initialized (it is either disabled or not
// available in this build). We should proceed directly to changing the HID
@@ -812,22 +794,21 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) {
int i;
int len, tmplen;
- LOG_VERBOSE("%s: event=%s dereg = %d", __func__, dump_hh_event(event),
- btif_hh_cb.service_dereg_active);
+ log::verbose("event={} dereg = {}", dump_hh_event(event),
+ btif_hh_cb.service_dereg_active);
switch (event) {
case BTA_HH_ENABLE_EVT:
- LOG_VERBOSE("%s: BTA_HH_ENABLE_EVT: status =%d", __func__,
- p_data->status);
+ log::verbose("BTA_HH_ENABLE_EVT: status ={}", p_data->status);
if (p_data->status == BTA_HH_OK) {
btif_hh_cb.status = BTIF_HH_ENABLED;
- LOG_VERBOSE("%s--Loading added devices", __func__);
+ log::verbose("Loading added devices");
/* Add hid descriptors for already bonded hid devices*/
btif_storage_load_bonded_hid_info();
} else {
btif_hh_cb.status = BTIF_HH_DISABLED;
- LOG_WARN("BTA_HH_ENABLE_EVT: Error, HH enabling failed, status = %d",
- p_data->status);
+ log::warn("BTA_HH_ENABLE_EVT: Error, HH enabling failed, status = {}",
+ p_data->status);
}
break;
@@ -838,7 +819,7 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) {
btif_hh_cb.status = BTIF_HH_DISABLED;
if (btif_hh_cb.service_dereg_active) {
- LOG_VERBOSE("BTA_HH_DISABLE_EVT: enabling HID Device service");
+ log::verbose("BTA_HH_DISABLE_EVT: enabling HID Device service");
btif_hd_service_registration();
btif_hh_cb.service_dereg_active = FALSE;
}
@@ -853,8 +834,8 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) {
btif_hh_cb.devices[i].dev_status = BTHH_CONN_STATE_UNKNOWN;
}
} else
- LOG_WARN("BTA_HH_DISABLE_EVT: Error, HH disabling failed, status = %d",
- p_data->status);
+ log::warn("BTA_HH_DISABLE_EVT: Error, HH disabling failed, status = {}",
+ p_data->status);
break;
case BTA_HH_OPEN_EVT:
@@ -862,14 +843,13 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) {
break;
case BTA_HH_CLOSE_EVT:
- LOG_VERBOSE("BTA_HH_CLOSE_EVT: status = %d, handle = %d",
- p_data->dev_status.status, p_data->dev_status.handle);
+ log::verbose("BTA_HH_CLOSE_EVT: status = {}, handle = {}",
+ p_data->dev_status.status, p_data->dev_status.handle);
p_dev = btif_hh_find_connected_dev_by_handle(p_data->dev_status.handle);
if (p_dev != NULL) {
HAL_CBACK(bt_hh_callbacks, connection_state_cb,
&(p_dev->link_spec.addrt.bda), BTHH_CONN_STATE_DISCONNECTING);
- LOG_VERBOSE("%s: uhid fd=%d local_vup=%d", __func__, p_dev->fd,
- p_dev->local_vup);
+ log::verbose("uhid fd={} local_vup={}", p_dev->fd, p_dev->local_vup);
btif_hh_stop_vup_timer(&(p_dev->link_spec));
/* If this is a locally initiated VUP, remove the bond as ACL got
* disconnected while VUP being processed.
@@ -880,8 +860,8 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) {
} else if (p_data->dev_status.status == BTA_HH_HS_SERVICE_CHANGED) {
/* Local disconnection due to service change in the HOGP device.
HID descriptor would be read again, so remove it from cache. */
- LOG_WARN(
- "Removing cached descriptor due to service change, handle = %d",
+ log::warn(
+ "Removing cached descriptor due to service change, handle = {}",
p_data->dev_status.handle);
btif_storage_remove_hid_info(p_dev->link_spec.addrt.bda);
}
@@ -893,14 +873,14 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) {
HAL_CBACK(bt_hh_callbacks, connection_state_cb,
&(p_dev->link_spec.addrt.bda), p_dev->dev_status);
} else {
- LOG_WARN("Error: cannot find device with handle %d",
- p_data->dev_status.handle);
+ log::warn("Error: cannot find device with handle {}",
+ p_data->dev_status.handle);
}
break;
case BTA_HH_GET_RPT_EVT: {
- LOG_VERBOSE("BTA_HH_GET_RPT_EVT: status = %d, handle = %d",
- p_data->hs_data.status, p_data->hs_data.handle);
+ log::verbose("BTA_HH_GET_RPT_EVT: status = {}, handle = {}",
+ p_data->hs_data.status, p_data->hs_data.handle);
p_dev = btif_hh_find_connected_dev_by_handle(p_data->hs_data.handle);
if (p_dev) {
BT_HDR* hdr = p_data->hs_data.rsp_data.p_rpt_data;
@@ -921,15 +901,15 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) {
(bthh_status_t)p_data->hs_data.status);
}
} else {
- LOG_WARN("Error: cannot find device with handle %d",
- p_data->hs_data.handle);
+ log::warn("Error: cannot find device with handle {}",
+ p_data->hs_data.handle);
}
break;
}
case BTA_HH_SET_RPT_EVT:
- LOG_VERBOSE("BTA_HH_SET_RPT_EVT: status = %d, handle = %d",
- p_data->dev_status.status, p_data->dev_status.handle);
+ log::verbose("BTA_HH_SET_RPT_EVT: status = {}, handle = {}",
+ p_data->dev_status.status, p_data->dev_status.handle);
p_dev = btif_hh_find_connected_dev_by_handle(p_data->dev_status.handle);
if (p_dev != NULL) {
HAL_CBACK(bt_hh_callbacks, handshake_cb,
@@ -943,13 +923,13 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) {
case BTA_HH_GET_PROTO_EVT:
p_dev = btif_hh_find_connected_dev_by_handle(p_data->hs_data.handle);
if (p_dev == NULL) {
- LOG_WARN(
- "BTA_HH_GET_PROTO_EVT: Error, cannot find device with handle %d",
+ log::warn(
+ "BTA_HH_GET_PROTO_EVT: Error, cannot find device with handle {}",
p_data->hs_data.handle);
return;
}
- LOG_WARN(
- "BTA_HH_GET_PROTO_EVT: status = %d, handle = %d, proto = [%d], %s",
+ log::warn(
+ "BTA_HH_GET_PROTO_EVT: status = {}, handle = {}, proto = [{}], {}",
p_data->hs_data.status, p_data->hs_data.handle,
p_data->hs_data.rsp_data.proto_mode,
(p_data->hs_data.rsp_data.proto_mode == BTA_HH_PROTO_RPT_MODE)
@@ -970,8 +950,8 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) {
break;
case BTA_HH_SET_PROTO_EVT:
- LOG_VERBOSE("BTA_HH_SET_PROTO_EVT: status = %d, handle = %d",
- p_data->dev_status.status, p_data->dev_status.handle);
+ log::verbose("BTA_HH_SET_PROTO_EVT: status = {}, handle = {}",
+ p_data->dev_status.status, p_data->dev_status.handle);
p_dev = btif_hh_find_connected_dev_by_handle(p_data->dev_status.handle);
if (p_dev) {
HAL_CBACK(bt_hh_callbacks, handshake_cb,
@@ -981,9 +961,9 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) {
break;
case BTA_HH_GET_IDLE_EVT:
- LOG_VERBOSE("BTA_HH_GET_IDLE_EVT: handle = %d, status = %d, rate = %d",
- p_data->hs_data.handle, p_data->hs_data.status,
- p_data->hs_data.rsp_data.idle_rate);
+ log::verbose("BTA_HH_GET_IDLE_EVT: handle = {}, status = {}, rate = {}",
+ p_data->hs_data.handle, p_data->hs_data.status,
+ p_data->hs_data.rsp_data.idle_rate);
p_dev = btif_hh_find_connected_dev_by_handle(p_data->hs_data.handle);
if (p_dev) {
HAL_CBACK(bt_hh_callbacks, idle_time_cb,
@@ -994,23 +974,22 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) {
break;
case BTA_HH_SET_IDLE_EVT:
- LOG_VERBOSE("BTA_HH_SET_IDLE_EVT: status = %d, handle = %d",
- p_data->dev_status.status, p_data->dev_status.handle);
+ log::verbose("BTA_HH_SET_IDLE_EVT: status = {}, handle = {}",
+ p_data->dev_status.status, p_data->dev_status.handle);
break;
case BTA_HH_GET_DSCP_EVT:
len = p_data->dscp_info.descriptor.dl_len;
- LOG_VERBOSE("BTA_HH_GET_DSCP_EVT: len = %d", len);
+ log::verbose("BTA_HH_GET_DSCP_EVT: len = {}", len);
p_dev =
btif_hh_find_connected_dev_by_handle(p_data->dscp_info.hid_handle);
if (p_dev == NULL) {
- LOG_ERROR("BTA_HH_GET_DSCP_EVT: No HID device is currently connected");
+ log::error("BTA_HH_GET_DSCP_EVT: No HID device is currently connected");
p_data->dscp_info.hid_handle = BTA_HH_INVALID_HANDLE;
return;
}
if (p_dev->fd < 0) {
- LOG_ERROR(
-
+ log::error(
"BTA_HH_GET_DSCP_EVT: Error, failed to find the uhid driver...");
return;
}
@@ -1027,7 +1006,7 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) {
cached_name = "Bluetooth HID";
}
- LOG_WARN("%s: name = %s", __func__, cached_name);
+ log::warn("name = {}", cached_name);
bta_hh_co_send_hid_info(p_dev, cached_name, p_data->dscp_info.vendor_id,
p_data->dscp_info.product_id,
p_data->dscp_info.version,
@@ -1037,8 +1016,8 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) {
tBTA_HH_DEV_DSCP_INFO dscp_info;
bt_status_t ret;
btif_hh_copy_hid_info(&dscp_info, &p_data->dscp_info);
- VLOG(1) << "BTA_HH_GET_DSCP_EVT:bda = "
- << ADDRESS_TO_LOGGABLE_STR(p_dev->link_spec.addrt.bda);
+ log::verbose("BTA_HH_GET_DSCP_EVT:bda = {}",
+ ADDRESS_TO_LOGGABLE_STR(p_dev->link_spec.addrt.bda));
BTA_HhAddDev(p_dev->link_spec, p_dev->attr_mask, p_dev->sub_class,
p_dev->app_id, dscp_info);
// write hid info to nvram
@@ -1051,7 +1030,7 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) {
p_data->dscp_info.descriptor.dsc_list);
ASSERTC(ret == BT_STATUS_SUCCESS, "storing hid info failed", ret);
- LOG_WARN("BTA_HH_GET_DSCP_EVT: Called add device");
+ log::warn("BTA_HH_GET_DSCP_EVT: Called add device");
// Free buffer created for dscp_info;
if (dscp_info.descriptor.dl_len > 0 &&
@@ -1061,7 +1040,7 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) {
}
} else {
// Device already added.
- LOG_WARN("%s: Device already added ", __func__);
+ log::warn("Device already added");
}
/*Sync HID Keyboard lockstates */
tmplen = sizeof(hid_kb_numlock_on_list) / sizeof(tHID_KB_LIST);
@@ -1070,10 +1049,8 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) {
hid_kb_numlock_on_list[i].version_id &&
p_data->dscp_info.product_id ==
hid_kb_numlock_on_list[i].product_id) {
- LOG_VERBOSE(
- "%s() idx[%d] Enabling "
- "NUMLOCK for device :: %s",
- __func__, i, hid_kb_numlock_on_list[i].kb_name);
+ log::verbose("idx[{}] Enabling NUMLOCK for device :: {}", i,
+ hid_kb_numlock_on_list[i].kb_name);
/* Enable NUMLOCK by default so that numeric
keys work from first keyboard connect */
set_keylockstate(BTIF_HH_KEYSTATE_MASK_NUMLOCK, true);
@@ -1086,8 +1063,8 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) {
break;
case BTA_HH_ADD_DEV_EVT:
- LOG_WARN("BTA_HH_ADD_DEV_EVT: status = %d, handle = %d",
- p_data->dev_info.status, p_data->dev_info.handle);
+ log::warn("BTA_HH_ADD_DEV_EVT: status = {}, handle = {}",
+ p_data->dev_info.status, p_data->dev_info.handle);
int i;
for (i = 0; i < BTIF_HH_MAX_ADDED_DEV; i++) {
if (btif_hh_cb.added_devices[i].link_spec.addrt.bda ==
@@ -1103,27 +1080,29 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) {
}
break;
case BTA_HH_RMV_DEV_EVT:
- LOG_VERBOSE("BTA_HH_RMV_DEV_EVT: status = %d, handle = %d",
- p_data->dev_info.status, p_data->dev_info.handle);
- VLOG(1) << "BTA_HH_RMV_DEV_EVT:bda = "
- << p_data->dev_info.link_spec.addrt.bda;
+ log::verbose("BTA_HH_RMV_DEV_EVT: status = {}, handle = {}",
+ p_data->dev_info.status, p_data->dev_info.handle);
+ log::verbose(
+ "BTA_HH_RMV_DEV_EVT:bda = {}",
+ ADDRESS_TO_LOGGABLE_STR(p_data->dev_info.link_spec.addrt.bda));
break;
case BTA_HH_VC_UNPLUG_EVT:
- LOG_VERBOSE("BTA_HH_VC_UNPLUG_EVT: status = %d, handle = %d",
- p_data->dev_status.status, p_data->dev_status.handle);
+ log::verbose("BTA_HH_VC_UNPLUG_EVT: status = {}, handle = {}",
+ p_data->dev_status.status, p_data->dev_status.handle);
p_dev = btif_hh_find_connected_dev_by_handle(p_data->dev_status.handle);
btif_hh_cb.status = (BTIF_HH_STATUS)BTIF_HH_DEV_DISCONNECTED;
if (p_dev != NULL) {
- VLOG(1) << "BTA_HH_VC_UNPLUG_EVT:bda = " << p_dev->link_spec.addrt.bda;
+ log::verbose("BTA_HH_VC_UNPLUG_EVT:bda = {}",
+ ADDRESS_TO_LOGGABLE_STR(p_dev->link_spec.addrt.bda));
/* Stop the VUP timer */
btif_hh_stop_vup_timer(&(p_dev->link_spec));
p_dev->dev_status = BTHH_CONN_STATE_DISCONNECTED;
- LOG_VERBOSE("%s---Sending connection state change", __func__);
+ log::verbose("--Sending connection state change");
HAL_CBACK(bt_hh_callbacks, connection_state_cb,
&(p_dev->link_spec.addrt.bda), p_dev->dev_status);
- LOG_VERBOSE("%s---Removing HID bond", __func__);
+ log::verbose("--Removing HID bond");
/* If it is locally initiated VUP or remote device has its major COD as
Peripheral removed the bond.*/
if (p_dev->local_vup || check_cod_hid(&(p_dev->link_spec.addrt.bda))) {
@@ -1138,11 +1117,11 @@ static void btif_hh_upstreams_evt(uint16_t event, char* p_param) {
break;
case BTA_HH_API_ERR_EVT:
- LOG_INFO("BTA_HH API_ERR");
+ log::info("BTA_HH API_ERR");
break;
default:
- LOG_WARN("%s: Unhandled event: %d", __func__, event);
+ log::warn("Unhandled event: {}", event);
break;
}
}
@@ -1164,7 +1143,7 @@ static void btif_hh_hsdata_rpt_copy_cb(uint16_t event, char* p_dest,
BT_HDR* hdr;
if (!p_src) {
- LOG_ERROR("%s: Nothing to copy", __func__);
+ log::error("Nothing to copy");
return;
}
@@ -1245,8 +1224,8 @@ static void btif_hh_handle_evt(uint16_t event, char* p_param) {
tAclLinkSpec* p_link_spec = (tAclLinkSpec*)p_param;
switch (event) {
case BTIF_HH_CONNECT_REQ_EVT: {
- LOG_DEBUG("Connect request received remote:%s",
- ADDRESS_TO_LOGGABLE_CSTR((*p_link_spec)));
+ log::debug("Connect request received remote:{}",
+ ADDRESS_TO_LOGGABLE_CSTR((*p_link_spec)));
if (btif_hh_connect(p_link_spec) == BT_STATUS_SUCCESS) {
HAL_CBACK(bt_hh_callbacks, connection_state_cb, &p_link_spec->addrt.bda,
BTHH_CONN_STATE_CONNECTING);
@@ -1256,25 +1235,25 @@ static void btif_hh_handle_evt(uint16_t event, char* p_param) {
} break;
case BTIF_HH_DISCONNECT_REQ_EVT: {
- LOG_DEBUG("Disconnect request received remote:%s",
- ADDRESS_TO_LOGGABLE_CSTR((*p_link_spec)));
+ log::debug("Disconnect request received remote:{}",
+ ADDRESS_TO_LOGGABLE_CSTR((*p_link_spec)));
btif_hh_disconnect(p_link_spec);
HAL_CBACK(bt_hh_callbacks, connection_state_cb, &p_link_spec->addrt.bda,
BTHH_CONN_STATE_DISCONNECTING);
} break;
case BTIF_HH_VUP_REQ_EVT: {
- LOG_DEBUG("Virtual unplug request received remote:%s",
- ADDRESS_TO_LOGGABLE_CSTR((*p_link_spec)));
- if (btif_hh_virtual_unplug(p_link_spec) != BT_STATUS_SUCCESS) {
- LOG_WARN("Unable to virtual unplug device remote:%s",
+ log::debug("Virtual unplug request received remote:{}",
ADDRESS_TO_LOGGABLE_CSTR((*p_link_spec)));
+ if (btif_hh_virtual_unplug(p_link_spec) != BT_STATUS_SUCCESS) {
+ log::warn("Unable to virtual unplug device remote:{}",
+ ADDRESS_TO_LOGGABLE_CSTR((*p_link_spec)));
}
} break;
default: {
- LOG_WARN("Unknown event received:%d remote:%s", event,
- ADDRESS_TO_LOGGABLE_CSTR((*p_link_spec)));
+ log::warn("Unknown event received:{} remote:{}", event,
+ ADDRESS_TO_LOGGABLE_CSTR((*p_link_spec)));
} break;
}
}
@@ -1293,7 +1272,7 @@ void btif_hh_timer_timeout(void* data) {
tBTA_HH p_data;
int param_len = sizeof(tBTA_HH_CBDATA);
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
if (p_dev->dev_status != BTHH_CONN_STATE_CONNECTED) return;
memset(&p_data, 0, sizeof(tBTA_HH));
@@ -1316,7 +1295,7 @@ void btif_hh_timer_timeout(void* data) {
******************************************************************************/
static bt_status_t init(bthh_callbacks_t* callbacks) {
uint32_t i;
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
bt_hh_callbacks = callbacks;
memset(&btif_hh_cb, 0, sizeof(btif_hh_cb));
@@ -1343,11 +1322,11 @@ static bt_status_t connect(RawAddress* bd_addr) {
tAclLinkSpec link_spec;
if (btif_hh_cb.status == BTIF_HH_DEV_CONNECTING) {
- LOG_WARN("%s: Error, HH status = %d", __func__, btif_hh_cb.status);
+ log::warn("Error, HH status = {}", btif_hh_cb.status);
return BT_STATUS_BUSY;
} else if (btif_hh_cb.status == BTIF_HH_DISABLED ||
btif_hh_cb.status == BTIF_HH_DISABLING) {
- LOG_WARN("%s: Error, HH status = %d", __func__, btif_hh_cb.status);
+ log::warn("Error, HH status = {}", btif_hh_cb.status);
return BT_STATUS_NOT_READY;
}
link_spec.addrt.bda = *bd_addr;
@@ -1359,12 +1338,12 @@ static bt_status_t connect(RawAddress* bd_addr) {
if (p_dev) {
if (p_dev->dev_status == BTHH_CONN_STATE_CONNECTED ||
p_dev->dev_status == BTHH_CONN_STATE_CONNECTING) {
- LOG_ERROR("%s: Error, device %s already connected.", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
+ log::error("Error, device {} already connected.",
+ ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
return BT_STATUS_DONE;
} else if (p_dev->dev_status == BTHH_CONN_STATE_DISCONNECTING) {
- LOG_ERROR("%s: Error, device %s is busy with (dis)connecting.", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
+ log::error("Error, device {} is busy with (dis)connecting.",
+ ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
return BT_STATUS_BUSY;
}
}
@@ -1384,13 +1363,13 @@ static bt_status_t connect(RawAddress* bd_addr) {
******************************************************************************/
static bt_status_t disconnect(RawAddress* bd_addr) {
CHECK_BTHH_INIT();
- LOG_VERBOSE("BTHH: %s", __func__);
+ log::verbose("BTHH");
btif_hh_device_t* p_dev;
tAclLinkSpec link_spec;
if (btif_hh_cb.status == BTIF_HH_DISABLED ||
btif_hh_cb.status == BTIF_HH_DISABLING) {
- LOG_WARN("%s: Error, HH status = %d", __func__, btif_hh_cb.status);
+ log::warn("Error, HH status = {}", btif_hh_cb.status);
return BT_STATUS_UNHANDLED;
}
link_spec.addrt.bda = *bd_addr;
@@ -1400,19 +1379,19 @@ static bt_status_t disconnect(RawAddress* bd_addr) {
p_dev = btif_hh_find_connected_dev_by_bda(link_spec);
if (!p_dev) {
- LOG_ERROR("%s: Error, device %s not opened.", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
+ log::error("Error, device {} not opened.",
+ ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
return BT_STATUS_UNHANDLED;
}
if (p_dev->dev_status == BTHH_CONN_STATE_DISCONNECTED ||
p_dev->dev_status == BTHH_CONN_STATE_DISCONNECTING) {
- LOG_ERROR("%s: Error, device %s already disconnected.", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
+ log::error("Error, device {} already disconnected.",
+ ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
return BT_STATUS_DONE;
} else if (p_dev->dev_status == BTHH_CONN_STATE_CONNECTING) {
- LOG_ERROR("%s: Error, device %s is busy with (dis)connecting.", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
+ log::error("Error, device {} is busy with (dis)connecting.",
+ ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
return BT_STATUS_BUSY;
}
@@ -1431,11 +1410,11 @@ static bt_status_t disconnect(RawAddress* bd_addr) {
******************************************************************************/
static bt_status_t virtual_unplug(RawAddress* bd_addr) {
CHECK_BTHH_INIT();
- LOG_VERBOSE("BTHH: %s", __func__);
+ log::verbose("BTHH");
btif_hh_device_t* p_dev;
tAclLinkSpec link_spec;
if (btif_hh_cb.status == BTIF_HH_DISABLED) {
- LOG_ERROR("%s: Error, HH status = %d", __func__, btif_hh_cb.status);
+ log::error("Error, HH status = {}", btif_hh_cb.status);
return BT_STATUS_FAIL;
}
link_spec.addrt.bda = *bd_addr;
@@ -1445,8 +1424,8 @@ static bt_status_t virtual_unplug(RawAddress* bd_addr) {
p_dev = btif_hh_find_dev_by_bda(link_spec);
if (!p_dev) {
- LOG_ERROR("%s: Error, device %s not opened.", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
+ log::error("Error, device {} not opened.",
+ ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
return BT_STATUS_FAIL;
}
btif_transfer_context(btif_hh_handle_evt, BTIF_HH_VUP_REQ_EVT,
@@ -1467,10 +1446,10 @@ static bt_status_t get_idle_time(RawAddress* bd_addr) {
CHECK_BTHH_INIT();
tAclLinkSpec link_spec;
- LOG_VERBOSE("%s: addr = %s", __func__, ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
+ log::verbose("addr = {}", ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
if (btif_hh_cb.status == BTIF_HH_DISABLED) {
- LOG_ERROR("%s: Error, HH status = %d", __func__, btif_hh_cb.status);
+ log::error("Error, HH status = {}", btif_hh_cb.status);
return BT_STATUS_FAIL;
}
link_spec.addrt.bda = *bd_addr;
@@ -1498,11 +1477,11 @@ static bt_status_t set_idle_time(RawAddress* bd_addr, uint8_t idle_time) {
CHECK_BTHH_INIT();
tAclLinkSpec link_spec;
- LOG_VERBOSE("%s: addr = %s, idle time = %d", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(*bd_addr), idle_time);
+ log::verbose("addr = {}, idle time = {}", ADDRESS_TO_LOGGABLE_CSTR(*bd_addr),
+ idle_time);
if (btif_hh_cb.status == BTIF_HH_DISABLED) {
- LOG_ERROR("%s: Error, HH status = %d", __func__, btif_hh_cb.status);
+ log::error("Error, HH status = {}", btif_hh_cb.status);
return BT_STATUS_FAIL;
}
link_spec.addrt.bda = *bd_addr;
@@ -1512,8 +1491,7 @@ static bt_status_t set_idle_time(RawAddress* bd_addr, uint8_t idle_time) {
btif_hh_device_t* p_dev = btif_hh_find_connected_dev_by_bda(link_spec);
if (p_dev == NULL) {
- LOG_WARN("%s: addr = %s not opened", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
+ log::warn("addr = {} not opened", ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
return BT_STATUS_FAIL;
}
@@ -1535,15 +1513,15 @@ static bt_status_t set_info(RawAddress* bd_addr, bthh_hid_info_t hid_info) {
tBTA_HH_DEV_DSCP_INFO dscp_info;
tAclLinkSpec link_spec;
- VLOG(1) << __func__ << " BTHH: addr = " << *bd_addr;
- LOG_VERBOSE(
- "BTHH: %s: sub_class = 0x%02x, app_id = %d, vendor_id = 0x%04x, "
- "product_id = 0x%04x, version= 0x%04x",
- __func__, hid_info.sub_class, hid_info.app_id, hid_info.vendor_id,
+ log::verbose("BTHH: addr = {}", ADDRESS_TO_LOGGABLE_STR(*bd_addr));
+ log::verbose(
+ "BTHH: sub_class = 0x{:02x}, app_id = {}, vendor_id = 0x{:04x}, "
+ "product_id = 0x{:04x}, version= 0x{:04x}",
+ hid_info.sub_class, hid_info.app_id, hid_info.vendor_id,
hid_info.product_id, hid_info.version);
if (btif_hh_cb.status == BTIF_HH_DISABLED) {
- LOG_ERROR("%s: Error, HH status = %d", __func__, btif_hh_cb.status);
+ log::error("Error, HH status = {}", btif_hh_cb.status);
return BT_STATUS_FAIL;
}
@@ -1587,10 +1565,10 @@ static bt_status_t get_protocol(RawAddress* bd_addr,
CHECK_BTHH_INIT();
tAclLinkSpec link_spec;
- VLOG(1) << __func__ << " BTHH: addr = " << ADDRESS_TO_LOGGABLE_STR(*bd_addr);
+ log::verbose("BTHH: addr = {}", ADDRESS_TO_LOGGABLE_STR(*bd_addr));
if (btif_hh_cb.status == BTIF_HH_DISABLED) {
- LOG_ERROR("%s: Error, HH status = %d", __func__, btif_hh_cb.status);
+ log::error("Error, HH status = {}", btif_hh_cb.status);
return BT_STATUS_FAIL;
}
link_spec.addrt.bda = *bd_addr;
@@ -1621,11 +1599,11 @@ static bt_status_t set_protocol(RawAddress* bd_addr,
uint8_t proto_mode = protocolMode;
tAclLinkSpec link_spec;
- VLOG(1) << __func__ << " BTHH: proto_mod=" << protocolMode
- << " addr = " << *bd_addr;
+ log::verbose("BTHH: proto_mod={} addr = {}", protocolMode,
+ ADDRESS_TO_LOGGABLE_STR(*bd_addr));
if (btif_hh_cb.status == BTIF_HH_DISABLED) {
- LOG_ERROR("%s: Error, HH status = %d", __func__, btif_hh_cb.status);
+ log::error("Error, HH status = {}", btif_hh_cb.status);
return BT_STATUS_FAIL;
}
link_spec.addrt.bda = *bd_addr;
@@ -1635,11 +1613,11 @@ static bt_status_t set_protocol(RawAddress* bd_addr,
p_dev = btif_hh_find_connected_dev_by_bda(link_spec);
if (p_dev == NULL) {
- LOG(WARNING) << " Error, device" << ADDRESS_TO_LOGGABLE_STR(*bd_addr) << " not opened";
+ log::warn("Error, device {} not opened", ADDRESS_TO_LOGGABLE_STR(*bd_addr));
return BT_STATUS_FAIL;
} else if (protocolMode != BTA_HH_PROTO_RPT_MODE &&
protocolMode != BTA_HH_PROTO_BOOT_MODE) {
- LOG_WARN("%s: Error, device proto_mode = %d.", __func__, proto_mode);
+ log::warn("Error, device proto_mode = {}.", proto_mode);
return BT_STATUS_FAIL;
} else {
BTA_HhSetProtoMode(p_dev->dev_handle, protocolMode);
@@ -1664,12 +1642,12 @@ static bt_status_t get_report(RawAddress* bd_addr,
btif_hh_device_t* p_dev;
tAclLinkSpec link_spec;
- VLOG(1) << __func__ << " BTHH: r_type = " << reportType
- << ", rpt_id = " << reportId << ", buf_size = " << bufferSize
- << " addr = " << ADDRESS_TO_LOGGABLE_STR(*bd_addr);
+ log::verbose("BTHH: r_type = {}, rpt_id = {}, buf_size = {} addr = {}",
+ reportType, reportId, bufferSize,
+ ADDRESS_TO_LOGGABLE_STR(*bd_addr));
if (btif_hh_cb.status == BTIF_HH_DISABLED) {
- LOG_ERROR("%s: Error, HH status = %d", __func__, btif_hh_cb.status);
+ log::error("Error, HH status = {}", btif_hh_cb.status);
return BT_STATUS_FAIL;
}
link_spec.addrt.bda = *bd_addr;
@@ -1679,11 +1657,12 @@ static bt_status_t get_report(RawAddress* bd_addr,
p_dev = btif_hh_find_connected_dev_by_bda(link_spec);
if (p_dev == NULL) {
- LOG(ERROR) << " Error, device" << ADDRESS_TO_LOGGABLE_STR(*bd_addr) << " not opened";
+ log::error("Error, device {} not opened",
+ ADDRESS_TO_LOGGABLE_STR(*bd_addr));
return BT_STATUS_FAIL;
} else if (((int)reportType) <= BTA_HH_RPTT_RESRV ||
((int)reportType) > BTA_HH_RPTT_FEATURE) {
- LOG(ERROR) << " Error, report type=" << +reportType << " not supported";
+ log::error("Error, report type={} not supported", reportType);
return BT_STATUS_FAIL;
} else {
BTA_HhGetReport(p_dev->dev_handle, reportType, reportId, bufferSize);
@@ -1707,10 +1686,10 @@ static bt_status_t get_report_reply(RawAddress* bd_addr, bthh_status_t status,
btif_hh_device_t* p_dev;
tAclLinkSpec link_spec;
- VLOG(1) << __func__ << " BTHH: addr=" << ADDRESS_TO_LOGGABLE_STR(*bd_addr);
+ log::verbose("BTHH: addr={}", ADDRESS_TO_LOGGABLE_STR(*bd_addr));
if (btif_hh_cb.status == BTIF_HH_DISABLED) {
- LOG_ERROR("%s: Error, HH status = %d", __func__, btif_hh_cb.status);
+ log::error("Error, HH status = {}", btif_hh_cb.status);
return BT_STATUS_FAIL;
}
link_spec.addrt.bda = *bd_addr;
@@ -1720,7 +1699,8 @@ static bt_status_t get_report_reply(RawAddress* bd_addr, bthh_status_t status,
p_dev = btif_hh_find_connected_dev_by_bda(link_spec);
if (p_dev == NULL) {
- LOG(ERROR) << " Error, device" << ADDRESS_TO_LOGGABLE_STR(*bd_addr) << " not opened";
+ log::error("Error, device {} not opened",
+ ADDRESS_TO_LOGGABLE_STR(*bd_addr));
return BT_STATUS_FAIL;
}
@@ -1744,11 +1724,11 @@ static bt_status_t set_report(RawAddress* bd_addr,
btif_hh_device_t* p_dev;
tAclLinkSpec link_spec;
- VLOG(1) << __func__ << " BTHH: reportType=" << reportType
- << " addr=" << ADDRESS_TO_LOGGABLE_STR(*bd_addr);
+ log::verbose("BTHH: reportType={} addr={}", reportType,
+ ADDRESS_TO_LOGGABLE_STR(*bd_addr));
if (btif_hh_cb.status == BTIF_HH_DISABLED) {
- LOG_ERROR("%s: Error, HH status = %d", __func__, btif_hh_cb.status);
+ log::error("Error, HH status = {}", btif_hh_cb.status);
return BT_STATUS_FAIL;
}
link_spec.addrt.bda = *bd_addr;
@@ -1758,11 +1738,11 @@ static bt_status_t set_report(RawAddress* bd_addr,
p_dev = btif_hh_find_connected_dev_by_bda(link_spec);
if (p_dev == NULL) {
- LOG(ERROR) << " Error, device" << ADDRESS_TO_LOGGABLE_STR(*bd_addr) << " not opened";
+ log::error("Error, device{} not opened", ADDRESS_TO_LOGGABLE_STR(*bd_addr));
return BT_STATUS_FAIL;
} else if (((int)reportType) <= BTA_HH_RPTT_RESRV ||
((int)reportType) > BTA_HH_RPTT_FEATURE) {
- LOG(ERROR) << " Error, report type=" << +reportType << " not supported";
+ log::error("Error, report type={} not supported", reportType);
return BT_STATUS_FAIL;
} else {
int hex_bytes_filled;
@@ -1772,12 +1752,12 @@ static bt_status_t set_report(RawAddress* bd_addr,
/* Build a SetReport data buffer */
// TODO
hex_bytes_filled = ascii_2_hex(report, len, hexbuf);
- LOG_INFO("Hex bytes filled, hex value: %d", hex_bytes_filled);
+ log::info("Hex bytes filled, hex value: {}", hex_bytes_filled);
if (hex_bytes_filled) {
BT_HDR* p_buf = create_pbuf(hex_bytes_filled, hexbuf);
if (p_buf == NULL) {
- LOG_ERROR("%s: Error, failed to allocate RPT buffer, len = %d",
- __func__, hex_bytes_filled);
+ log::error("Error, failed to allocate RPT buffer, len = {}",
+ hex_bytes_filled);
osi_free(hexbuf);
return BT_STATUS_FAIL;
}
@@ -1804,10 +1784,10 @@ static bt_status_t send_data(RawAddress* bd_addr, char* data) {
btif_hh_device_t* p_dev;
tAclLinkSpec link_spec;
- VLOG(1) << __func__ << " addr=" << ADDRESS_TO_LOGGABLE_STR(*bd_addr);
+ log::verbose("addr={}", ADDRESS_TO_LOGGABLE_STR(*bd_addr));
if (btif_hh_cb.status == BTIF_HH_DISABLED) {
- LOG_ERROR("%s: Error, HH status = %d", __func__, btif_hh_cb.status);
+ log::error("Error, HH status = {}", btif_hh_cb.status);
return BT_STATUS_FAIL;
}
link_spec.addrt.bda = *bd_addr;
@@ -1817,8 +1797,7 @@ static bt_status_t send_data(RawAddress* bd_addr, char* data) {
p_dev = btif_hh_find_connected_dev_by_bda(link_spec);
if (p_dev == NULL) {
- LOG(ERROR) << " Error, device"
- << ADDRESS_TO_LOGGABLE_STR(*bd_addr) << " not opened";
+ log::error("Error, device{} not opened", ADDRESS_TO_LOGGABLE_STR(*bd_addr));
return BT_STATUS_FAIL;
}
@@ -1829,13 +1808,13 @@ static bt_status_t send_data(RawAddress* bd_addr, char* data) {
/* Build a SendData data buffer */
hex_bytes_filled = ascii_2_hex(data, len, hexbuf);
- LOG_ERROR("Hex bytes filled, hex value: %d, %zu", hex_bytes_filled, len);
+ log::error("Hex bytes filled, hex value: {}, {}", hex_bytes_filled, len);
if (hex_bytes_filled) {
BT_HDR* p_buf = create_pbuf(hex_bytes_filled, hexbuf);
if (p_buf == NULL) {
- LOG_ERROR("%s: Error, failed to allocate RPT buffer, len = %d",
- __func__, hex_bytes_filled);
+ log::error("Error, failed to allocate RPT buffer, len = {}",
+ hex_bytes_filled);
osi_free(hexbuf);
return BT_STATUS_FAIL;
}
@@ -1859,13 +1838,13 @@ static bt_status_t send_data(RawAddress* bd_addr, char* data) {
*
******************************************************************************/
static void cleanup(void) {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
btif_hh_device_t* p_dev;
int i;
if (btif_hh_cb.status == BTIF_HH_DISABLED ||
btif_hh_cb.status == BTIF_HH_DISABLING) {
- LOG_WARN("%s: HH disabling or disabled already, status = %d", __func__,
- btif_hh_cb.status);
+ log::warn("HH disabling or disabled already, status = {}",
+ btif_hh_cb.status);
return;
}
if (bt_hh_callbacks) {
@@ -1878,7 +1857,7 @@ static void cleanup(void) {
for (i = 0; i < BTIF_HH_MAX_HID; i++) {
p_dev = &btif_hh_cb.devices[i];
if (p_dev->dev_status != BTHH_CONN_STATE_UNKNOWN && p_dev->fd >= 0) {
- LOG_VERBOSE("%s: Closing uhid fd = %d", __func__, p_dev->fd);
+ log::verbose("Closing uhid fd = {}", p_dev->fd);
bta_hh_co_close(p_dev);
}
}
@@ -1949,7 +1928,7 @@ bt_status_t btif_hh_execute_service(bool b_enable) {
*
******************************************************************************/
const bthh_interface_t* btif_hh_get_interface() {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
return &bthhInterface;
}
diff --git a/system/btif/src/btif_iot_config.cc b/system/btif/src/btif_iot_config.cc
index 967df79ead..59b513f013 100644
--- a/system/btif/src/btif_iot_config.cc
+++ b/system/btif/src/btif_iot_config.cc
@@ -16,6 +16,8 @@
*
******************************************************************************/
+#include <bluetooth/log.h>
+
#include "bta_sec_api.h"
#include "btif_storage.h"
#include "device/include/device_iot_config.h"
@@ -23,6 +25,8 @@
#include "os/log.h"
#include "stack/include/btm_ble_api.h"
+using namespace bluetooth;
+
/*******************************************************************************
* Constants & Macros
******************************************************************************/
@@ -100,9 +104,9 @@ void btif_iot_update_remote_info(tBTA_DM_AUTH_CMPL* p_auth_cmpl, bool is_ble,
if (btif_storage_get_remote_device_property(&p_auth_cmpl->bd_addr,
&properties[num_properties]) ==
BT_STATUS_SUCCESS)
- LOG_VERBOSE("%s cod retrieved from storage is 0x%06x", __func__, cod);
+ log::verbose("cod retrieved from storage is 0x{:06x}", cod);
if (cod == 0) {
- LOG_VERBOSE("%s cod is 0, set as unclassified", __func__);
+ log::verbose("cod is 0, set as unclassified");
cod = COD_UNCLASSIFIED;
}
DEVICE_IOT_CONFIG_ADDR_SET_INT(p_auth_cmpl->bd_addr, IOT_CONF_KEY_DEVCLASS,
@@ -118,7 +122,7 @@ void btif_iot_update_remote_info(tBTA_DM_AUTH_CMPL* p_auth_cmpl, bool is_ble,
if (btif_storage_get_remote_device_property(&p_auth_cmpl->bd_addr,
&properties[num_properties]) ==
BT_STATUS_SUCCESS) {
- LOG_VERBOSE("%s retrieve dev type from storage", __func__);
+ log::verbose("retrieve dev type from storage");
dev_type = (bt_device_type_t)(remote_dev_type | p_auth_cmpl->dev_type);
} else {
dev_type = (bt_device_type_t)(p_auth_cmpl->dev_type);
diff --git a/system/btif/src/btif_jni_task.cc b/system/btif/src/btif_jni_task.cc
index 5a54253055..083515c872 100644
--- a/system/btif/src/btif_jni_task.cc
+++ b/system/btif/src/btif_jni_task.cc
@@ -20,6 +20,7 @@
#include <base/location.h>
#include <base/logging.h>
#include <base/threading/platform_thread.h>
+#include <bluetooth/log.h>
#include <cstdint>
#include <utility>
@@ -30,6 +31,7 @@
#include "stack/include/bt_types.h"
using base::PlatformThread;
+using namespace bluetooth;
static bluetooth::common::MessageLoopThread jni_thread("bt_jni_thread");
@@ -76,7 +78,7 @@ bt_status_t btif_transfer_context(tBTIF_CBACK* p_cback, uint16_t event,
tBTIF_CONTEXT_SWITCH_CBACK* p_msg = (tBTIF_CONTEXT_SWITCH_CBACK*)osi_malloc(
sizeof(tBTIF_CONTEXT_SWITCH_CBACK) + param_len);
- LOG_VERBOSE("btif_transfer_context event %d, len %d", event, param_len);
+ log::verbose("btif_transfer_context event {}, len {}", event, param_len);
/* allocate and send message that will be executed in btif context */
p_msg->hdr.event = BT_EVT_CONTEXT_SWITCH_EVT; /* internal event */
@@ -101,7 +103,7 @@ bt_status_t btif_transfer_context(tBTIF_CBACK* p_cback, uint16_t event,
bt_status_t do_in_jni_thread(const base::Location& from_here,
base::OnceClosure task) {
if (!jni_thread.DoInThread(from_here, std::move(task))) {
- LOG(ERROR) << __func__ << ": Post task to task runner failed!";
+ log::error("Post task to task runner failed!");
return BT_STATUS_FAIL;
}
return BT_STATUS_SUCCESS;
diff --git a/system/btif/src/btif_keystore.cc b/system/btif/src/btif_keystore.cc
index 8125f0a107..734fb3d8f8 100644
--- a/system/btif/src/btif_keystore.cc
+++ b/system/btif/src/btif_keystore.cc
@@ -21,6 +21,7 @@
#include <base/functional/bind.h>
#include <base/location.h>
#include <base/logging.h>
+#include <bluetooth/log.h>
#include <hardware/bluetooth.h>
#include <map>
@@ -47,7 +48,7 @@ class BluetoothKeystoreInterfaceImpl
~BluetoothKeystoreInterfaceImpl() override = default;
void init(BluetoothKeystoreCallbacks* callbacks) override {
- VLOG(2) << __func__;
+ log::verbose("");
this->callbacks = callbacks;
bluetooth::os::ParameterProvider::SetCommonCriteriaConfigCompareResult(
@@ -56,9 +57,9 @@ class BluetoothKeystoreInterfaceImpl
}
void ConvertEncryptOrDecryptKeyIfNeeded() {
- VLOG(2) << __func__;
+ log::verbose("");
if (!callbacks) {
- LOG(INFO) << __func__ << " callback isn't ready.";
+ log::info("callback isn't ready.");
return;
}
do_in_jni_thread(
@@ -69,10 +70,10 @@ class BluetoothKeystoreInterfaceImpl
bool set_encrypt_key_or_remove_key(std::string prefix,
std::string decryptedString) override {
- VLOG(2) << __func__ << " prefix: " << prefix;
+ log::verbose("prefix: {}", prefix);
if (!callbacks) {
- LOG(WARNING) << __func__ << " callback isn't ready. prefix: " << prefix;
+ log::warn("callback isn't ready. prefix: {}", prefix);
return false;
}
@@ -87,10 +88,10 @@ class BluetoothKeystoreInterfaceImpl
}
std::string get_key(std::string prefix) override {
- VLOG(2) << __func__ << " prefix: " << prefix;
+ log::verbose("prefix: {}", prefix);
if (!callbacks) {
- LOG(WARNING) << __func__ << " callback isn't ready. prefix: " << prefix;
+ log::warn("callback isn't ready. prefix: {}", prefix);
return "";
}
@@ -101,7 +102,7 @@ class BluetoothKeystoreInterfaceImpl
decryptedString = callbacks->get_key(prefix);
// Save the value into a map.
key_map[prefix] = decryptedString;
- VLOG(2) << __func__ << ": get key from bluetoothkeystore.";
+ log::verbose("get key from bluetoothkeystore.");
} else {
decryptedString = iter->second;
}
@@ -109,7 +110,7 @@ class BluetoothKeystoreInterfaceImpl
}
void clear_map() override {
- VLOG(2) << __func__;
+ log::verbose("");
std::map<std::string, std::string> empty_map;
key_map.swap(empty_map);
diff --git a/system/btif/src/btif_le_audio.cc b/system/btif/src/btif_le_audio.cc
index 40138606d7..65760220f2 100644
--- a/system/btif/src/btif_le_audio.cc
+++ b/system/btif/src/btif_le_audio.cc
@@ -16,6 +16,7 @@
*/
#include <base/logging.h>
+#include <bluetooth/log.h>
#include <hardware/bluetooth.h>
#include <hardware/bt_le_audio.h>
@@ -36,6 +37,7 @@ using bluetooth::le_audio::GroupStreamStatus;
using bluetooth::le_audio::LeAudioClientCallbacks;
using bluetooth::le_audio::LeAudioClientInterface;
using bluetooth::le_audio::UnicastMonitorModeStatus;
+using namespace bluetooth;
namespace {
class LeAudioClientInterfaceImpl;
@@ -154,7 +156,7 @@ class LeAudioClientInterfaceImpl : public LeAudioClientInterface,
this->callbacks = callbacks;
for (auto codec : offloading_preference) {
- LOG_INFO("supported codec: %s", codec.ToString().c_str());
+ log::info("supported codec: {}", codec.ToString());
}
do_in_main_thread(
@@ -174,9 +176,9 @@ class LeAudioClientInterfaceImpl : public LeAudioClientInterface,
void Cleanup(void) override {
if (!initialized || !LeAudioClient::IsLeAudioClientRunning()) {
- VLOG(1) << __func__
- << " call ignored, due to already started cleanup procedure or "
- "service being not read";
+ log::verbose(
+ "call ignored, due to already started cleanup procedure or service "
+ "being not read");
return;
}
@@ -187,9 +189,9 @@ class LeAudioClientInterfaceImpl : public LeAudioClientInterface,
void RemoveDevice(const RawAddress& address) override {
if (!initialized || !LeAudioClient::IsLeAudioClientRunning()) {
- VLOG(1) << __func__
- << " call ignored, due to already started cleanup procedure or "
- "service being not read";
+ log::verbose(
+ "call ignored, due to already started cleanup procedure or service "
+ "being not read");
do_in_jni_thread(FROM_HERE, Bind(&btif_storage_remove_leaudio, address));
return;
@@ -204,9 +206,9 @@ class LeAudioClientInterfaceImpl : public LeAudioClientInterface,
void Connect(const RawAddress& address) override {
if (!initialized || !LeAudioClient::IsLeAudioClientRunning()) {
- VLOG(1) << __func__
- << " call ignored, due to already started cleanup procedure or "
- "service being not read";
+ log::verbose(
+ "call ignored, due to already started cleanup procedure or service "
+ "being not read");
return;
}
@@ -217,9 +219,9 @@ class LeAudioClientInterfaceImpl : public LeAudioClientInterface,
void Disconnect(const RawAddress& address) override {
if (!initialized || !LeAudioClient::IsLeAudioClientRunning()) {
- VLOG(1) << __func__
- << " call ignored, due to already started cleanup procedure or "
- "service being not read";
+ log::verbose(
+ "call ignored, due to already started cleanup procedure or service "
+ "being not read");
return;
}
@@ -230,9 +232,9 @@ class LeAudioClientInterfaceImpl : public LeAudioClientInterface,
void SetEnableState(const RawAddress& address, bool enabled) override {
if (!initialized || !LeAudioClient::IsLeAudioClientRunning()) {
- VLOG(1) << __func__
- << " call ignored, due to already started cleanup procedure or "
- "service being not read";
+ log::verbose(
+ "call ignored, due to already started cleanup procedure or service "
+ "being not read");
return;
}
@@ -243,9 +245,9 @@ class LeAudioClientInterfaceImpl : public LeAudioClientInterface,
void GroupAddNode(const int group_id, const RawAddress& address) override {
if (!initialized || !LeAudioClient::IsLeAudioClientRunning()) {
- VLOG(1) << __func__
- << " call ignored, due to already started cleanup procedure or "
- "service being not read";
+ log::verbose(
+ "call ignored, due to already started cleanup procedure or service "
+ "being not read");
return;
}
@@ -256,9 +258,9 @@ class LeAudioClientInterfaceImpl : public LeAudioClientInterface,
void GroupRemoveNode(const int group_id, const RawAddress& address) override {
if (!initialized || !LeAudioClient::IsLeAudioClientRunning()) {
- VLOG(1) << __func__
- << " call ignored, due to already started cleanup procedure or "
- "service being not read";
+ log::verbose(
+ "call ignored, due to already started cleanup procedure or service "
+ "being not read");
return;
}
@@ -269,9 +271,9 @@ class LeAudioClientInterfaceImpl : public LeAudioClientInterface,
void GroupSetActive(const int group_id) override {
if (!initialized || !LeAudioClient::IsLeAudioClientRunning()) {
- VLOG(1) << __func__
- << " call ignored, due to already started cleanup procedure or "
- "service being not read";
+ log::verbose(
+ "call ignored, due to already started cleanup procedure or service "
+ "being not read");
return;
}
@@ -284,9 +286,9 @@ class LeAudioClientInterfaceImpl : public LeAudioClientInterface,
btle_audio_codec_config_t input_codec_config,
btle_audio_codec_config_t output_codec_config) {
if (!initialized || !LeAudioClient::IsLeAudioClientRunning()) {
- VLOG(1) << __func__
- << " call ignored, due to already started cleanup procedure or "
- "service being not read";
+ log::verbose(
+ "call ignored, due to already started cleanup procedure or service "
+ "being not read");
return;
}
do_in_main_thread(FROM_HERE,
@@ -297,9 +299,9 @@ class LeAudioClientInterfaceImpl : public LeAudioClientInterface,
void SetCcidInformation(int ccid, int context_type) {
if (!initialized || !LeAudioClient::IsLeAudioClientRunning()) {
- VLOG(1) << __func__
- << " call ignored, due to already started cleanup procedure or "
- "service being not read";
+ log::verbose(
+ "call ignored, due to already started cleanup procedure or service "
+ "being not read");
return;
}
@@ -310,9 +312,9 @@ class LeAudioClientInterfaceImpl : public LeAudioClientInterface,
void SetInCall(bool in_call) {
if (!initialized || !LeAudioClient::IsLeAudioClientRunning()) {
- VLOG(1) << __func__
- << " call ignored, due to already started cleanup procedure or "
- "service being not read";
+ log::verbose(
+ "call ignored, due to already started cleanup procedure or service "
+ "being not read");
return;
}
@@ -339,9 +341,9 @@ class LeAudioClientInterfaceImpl : public LeAudioClientInterface,
bool is_output_preference_le_audio,
bool is_duplex_preference_le_audio) {
if (!initialized || !LeAudioClient::IsLeAudioClientRunning()) {
- VLOG(1) << __func__
- << " call ignored, due to already started cleanup procedure or "
- "service being not read";
+ log::verbose(
+ "call ignored, due to already started cleanup procedure or service "
+ "being not read");
return;
}
diff --git a/system/btif/src/btif_pan.cc b/system/btif/src/btif_pan.cc
index 7ed00ae2f8..b69d886786 100644
--- a/system/btif/src/btif_pan.cc
+++ b/system/btif/src/btif_pan.cc
@@ -31,6 +31,7 @@
#include <arpa/inet.h>
#include <base/functional/bind.h>
#include <base/location.h>
+#include <bluetooth/log.h>
#include <fcntl.h>
#include <linux/if_ether.h>
#include <linux/if_tun.h>
@@ -64,15 +65,15 @@
#define FORWARD_FAILURE (-1)
#define FORWARD_CONGEST (-2)
-#define asrt(s) \
- do { \
- if (!(s)) \
- LOG_ERROR("btif_pan: ## %s assert %s failed at line:%d ##", __func__, \
- #s, __LINE__); \
+#define asrt(s) \
+ do { \
+ if (!(s)) log::error("btif_pan: ## assert {} failed ##", #s); \
} while (0)
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
+using namespace bluetooth;
+
btpan_cb_t btpan_cb;
static bool jni_initialized;
@@ -108,12 +109,12 @@ const btpan_interface_t* btif_pan_get_interface() { return &pan_if; }
**
******************************************************************************/
void btif_pan_init() {
- LOG_VERBOSE("jni_initialized = %d, btpan_cb.enabled:%d", jni_initialized,
- btpan_cb.enabled);
+ log::verbose("jni_initialized = {}, btpan_cb.enabled:{}", jni_initialized,
+ btpan_cb.enabled);
stack_initialized = true;
if (jni_initialized && !btpan_cb.enabled) {
- LOG_VERBOSE("Enabling PAN....");
+ log::verbose("Enabling PAN....");
memset(&btpan_cb, 0, sizeof(btpan_cb));
btpan_cb.tap_fd = INVALID_FD;
btpan_cb.flow = 1;
@@ -158,8 +159,8 @@ void btif_pan_cleanup() {
static btpan_callbacks_t callback;
static bt_status_t btpan_jni_init(const btpan_callbacks_t* callbacks) {
- LOG_VERBOSE("stack_initialized = %d, btpan_cb.enabled:%d", stack_initialized,
- btpan_cb.enabled);
+ log::verbose("stack_initialized = {}, btpan_cb.enabled:{}", stack_initialized,
+ btpan_cb.enabled);
callback = *callbacks;
jni_initialized = true;
if (stack_initialized && !btpan_cb.enabled) btif_pan_init();
@@ -212,7 +213,7 @@ static bt_status_t btpan_connect(const RawAddress* bd_addr, int local_role,
constexpr uint16_t BTIF_PAN_CB_DISCONNECTING = 0x8401;
static void btif_in_pan_generic_evt(uint16_t event, char* p_param) {
- LOG_VERBOSE("%s: event=%d", __func__, event);
+ log::verbose("event={}", event);
switch (event) {
case BTIF_PAN_CB_DISCONNECTING: {
RawAddress* bd_addr = (RawAddress*)p_param;
@@ -229,7 +230,7 @@ static void btif_in_pan_generic_evt(uint16_t event, char* p_param) {
}
} break;
default: {
- LOG_WARN("%s : Unknown event 0x%x", __func__, event);
+ log::warn("Unknown event 0x{:x}", event);
} break;
}
}
@@ -273,8 +274,8 @@ static int tap_if_up(const char* devname, const RawAddress* addr) {
strlcpy(ifr.ifr_name, devname, IFNAMSIZ);
err = ioctl(sk, SIOCGIFHWADDR, &ifr);
if (err < 0) {
- LOG_ERROR("Could not get network hardware for interface:%s, errno:%s",
- devname, strerror(errno));
+ log::error("Could not get network hardware for interface:{}, errno:{}",
+ devname, strerror(errno));
close(sk);
return -1;
}
@@ -291,15 +292,15 @@ static int tap_if_up(const char* devname, const RawAddress* addr) {
* Mask this bit to avoid any issue with auto generated address.
*/
if (ifr.ifr_hwaddr.sa_data[0] & 0x01) {
- LOG_WARN("Not a unicast MAC address, force multicast bit flipping");
+ log::warn("Not a unicast MAC address, force multicast bit flipping");
ifr.ifr_hwaddr.sa_data[0] &= ~0x01;
}
err = ioctl(sk, SIOCSIFHWADDR, (caddr_t)&ifr);
if (err < 0) {
- LOG_ERROR("Could not set bt address for interface:%s, errno:%s", devname,
- strerror(errno));
+ log::error("Could not set bt address for interface:{}, errno:{}", devname,
+ strerror(errno));
close(sk);
return -1;
}
@@ -314,13 +315,13 @@ static int tap_if_up(const char* devname, const RawAddress* addr) {
err = ioctl(sk, SIOCSIFFLAGS, (caddr_t)&ifr);
if (err < 0) {
- LOG_ERROR("Could not bring up network interface:%s, errno:%d", devname,
- errno);
+ log::error("Could not bring up network interface:{}, errno:{}", devname,
+ errno);
close(sk);
return -1;
}
close(sk);
- LOG_VERBOSE("network interface: %s is up", devname);
+ log::verbose("network interface: {} is up", devname);
return 0;
}
@@ -363,7 +364,7 @@ int btpan_tap_open() {
fd = open(clonedev, O_RDWR);
if (fd < 0) {
- LOG_VERBOSE("could not open %s, err:%d", clonedev, errno);
+ log::verbose("could not open {}, err:{}", clonedev, errno);
return fd;
}
@@ -375,7 +376,7 @@ int btpan_tap_open() {
/* try to create the device */
err = ioctl(fd, TUNSETIFF, (void*)&ifr);
if (err < 0) {
- LOG_VERBOSE("ioctl error:%d, errno:%s", err, strerror(errno));
+ log::verbose("ioctl error:{}, errno:{}", err, strerror(errno));
close(fd);
return err;
}
@@ -384,7 +385,7 @@ int btpan_tap_open() {
fcntl(fd, F_SETFL, flags | O_NONBLOCK);
return fd;
}
- LOG_ERROR("can not bring up tap interface:%s", TAP_IF_NAME);
+ log::error("can not bring up tap interface:{}", TAP_IF_NAME);
close(fd);
return INVALID_FD;
}
@@ -400,7 +401,7 @@ int btpan_tap_send(int tap_fd, const RawAddress& src, const RawAddress& dst,
char packet[TAP_MAX_PKT_WRITE_LEN + sizeof(tETH_HDR)];
memcpy(packet, &eth_hdr, sizeof(tETH_HDR));
if (len > TAP_MAX_PKT_WRITE_LEN) {
- LOG_ERROR("btpan_tap_send eth packet size:%d is exceeded limit!", len);
+ log::error("btpan_tap_send eth packet size:{} is exceeded limit!", len);
return -1;
}
memcpy(packet + sizeof(tETH_HDR), buf, len);
@@ -408,7 +409,7 @@ int btpan_tap_send(int tap_fd, const RawAddress& src, const RawAddress& dst,
/* Send data to network interface */
ssize_t ret;
OSI_NO_INTR(ret = write(tap_fd, packet, len + sizeof(tETH_HDR)));
- LOG_VERBOSE("ret:%zd", ret);
+ log::verbose("ret:{}", ret);
return (int)ret;
}
return -1;
@@ -435,18 +436,18 @@ btpan_conn_t* btpan_find_conn_addr(const RawAddress& addr) {
}
static void btpan_open_conn(btpan_conn_t* conn, tBTA_PAN* p_data) {
- LOG_VERBOSE(
- "btpan_open_conn: local_role:%d, peer_role: %d, handle:%d, conn: %p",
+ log::verbose(
+ "btpan_open_conn: local_role:{}, peer_role: {}, handle:{}, conn: {}",
p_data->open.local_role, p_data->open.peer_role, p_data->open.handle,
- conn);
+ fmt::ptr(conn));
if (conn == NULL)
conn = btpan_new_conn(p_data->open.handle, p_data->open.bd_addr,
p_data->open.local_role, p_data->open.peer_role);
if (conn) {
- LOG_VERBOSE(
- "btpan_open_conn:tap_fd:%d, open_count:%d, "
- "conn->handle:%d should = handle:%d, local_role:%d, remote_role:%d",
+ log::verbose(
+ "btpan_open_conn:tap_fd:{}, open_count:{}, conn->handle:{} should = "
+ "handle:{}, local_role:{}, remote_role:{}",
btpan_cb.tap_fd, btpan_cb.open_count, conn->handle, p_data->open.handle,
conn->local_role, conn->remote_role);
@@ -465,10 +466,10 @@ static void btpan_open_conn(btpan_conn_t* conn, tBTA_PAN* p_data) {
}
static void btpan_close_conn(btpan_conn_t* conn) {
- LOG_VERBOSE("btpan_close_conn: %p", conn);
+ log::verbose("btpan_close_conn: {}", fmt::ptr(conn));
if (conn && conn->state == PAN_STATE_OPEN) {
- LOG_VERBOSE("btpan_close_conn: PAN_STATE_OPEN");
+ log::verbose("btpan_close_conn: PAN_STATE_OPEN");
conn->state = PAN_STATE_CLOSE;
btpan_cb.open_count--;
@@ -498,9 +499,8 @@ btpan_conn_t* btpan_new_conn(int handle, const RawAddress& addr,
tBTA_PAN_ROLE remote_role) {
for (int i = 0; i < MAX_PAN_CONNS; i++) {
if (btpan_cb.conns[i].handle == -1) {
- LOG_DEBUG(
- "Allocated new pan connection handle:%d local_role:%hhu"
- " remote_role:%hhu",
+ log::debug(
+ "Allocated new pan connection handle:{} local_role:{} remote_role:{}",
handle, local_role, remote_role);
btpan_cb.conns[i].handle = handle;
btpan_cb.conns[i].peer = addr;
@@ -509,12 +509,12 @@ btpan_conn_t* btpan_new_conn(int handle, const RawAddress& addr,
return &btpan_cb.conns[i];
}
}
- LOG_WARN("Unable to create new pan connection max:%d", MAX_PAN_CONNS);
+ log::warn("Unable to create new pan connection max:{}", MAX_PAN_CONNS);
return nullptr;
}
void btpan_close_handle(btpan_conn_t* p) {
- LOG_VERBOSE("btpan_close_handle : close handle %d", p->handle);
+ log::verbose("btpan_close_handle : close handle {}", p->handle);
p->handle = -1;
p->local_role = -1;
p->remote_role = -1;
@@ -525,7 +525,7 @@ static inline bool should_forward(tETH_HDR* hdr) {
uint16_t proto = ntohs(hdr->h_proto);
if (proto == ETH_P_IP || proto == ETH_P_ARP || proto == ETH_P_IPV6)
return true;
- LOG_VERBOSE("unknown proto:%x", proto);
+ log::verbose("unknown proto:{:x}", proto);
return false;
}
@@ -559,7 +559,7 @@ static void bta_pan_callback_transfer(uint16_t event, char* p_param) {
switch (event) {
case BTA_PAN_ENABLE_EVT:
- LOG_VERBOSE("BTA_PAN_ENABLE_EVT");
+ log::verbose("BTA_PAN_ENABLE_EVT");
break;
case BTA_PAN_SET_ROLE_EVT: {
int btpan_role = bta_role_to_btpan(p_data->set_role.role);
@@ -572,9 +572,9 @@ static void bta_pan_callback_transfer(uint16_t event, char* p_param) {
}
case BTA_PAN_OPENING_EVT: {
btpan_conn_t* conn;
- LOG_VERBOSE("BTA_PAN_OPENING_EVT handle %d, addr: %s",
- p_data->opening.handle,
- ADDRESS_TO_LOGGABLE_CSTR(p_data->opening.bd_addr));
+ log::verbose("BTA_PAN_OPENING_EVT handle {}, addr: {}",
+ p_data->opening.handle,
+ ADDRESS_TO_LOGGABLE_CSTR(p_data->opening.bd_addr));
conn = btpan_find_conn_addr(p_data->opening.bd_addr);
asrt(conn != NULL);
@@ -586,7 +586,7 @@ static void bta_pan_callback_transfer(uint16_t event, char* p_param) {
&p_data->opening.bd_addr,
btpan_conn_local_role, btpan_remote_role);
} else
- LOG_ERROR("connection not found");
+ log::error("connection not found");
break;
}
case BTA_PAN_OPEN_EVT: {
@@ -594,8 +594,7 @@ static void bta_pan_callback_transfer(uint16_t event, char* p_param) {
bt_status_t status;
btpan_conn_t* conn = btpan_find_conn_handle(p_data->open.handle);
- LOG_VERBOSE("%s pan connection open status: %d", __func__,
- p_data->open.status);
+ log::verbose("pan connection open status: {}", p_data->open.status);
if (p_data->open.status) {
state = BTPAN_STATE_CONNECTED;
status = BT_STATUS_SUCCESS;
@@ -616,8 +615,7 @@ static void bta_pan_callback_transfer(uint16_t event, char* p_param) {
break;
}
case BTA_PAN_CLOSE_EVT: {
- LOG_INFO("%s: event = BTA_PAN_CLOSE_EVT handle %d", __func__,
- p_data->close.handle);
+ log::info("event = BTA_PAN_CLOSE_EVT handle {}", p_data->close.handle);
btpan_conn_t* conn = btpan_find_conn_handle(p_data->close.handle);
btpan_close_conn(conn);
@@ -629,11 +627,11 @@ static void bta_pan_callback_transfer(uint16_t event, char* p_param) {
btpan_remote_role);
btpan_cleanup_conn(conn);
} else
- LOG_ERROR("pan handle not found (%d)", p_data->close.handle);
+ log::error("pan handle not found ({})", p_data->close.handle);
break;
}
default:
- LOG_WARN("Unknown pan event %d", event);
+ log::warn("Unknown pan event {}", event);
break;
}
}
@@ -670,14 +668,13 @@ static void btu_exec_tap_fd_read(int fd) {
sizeof(btpan_cb.congest_packet)));
switch (ret) {
case -1:
- LOG_ERROR("%s unable to read from driver: %s", __func__,
- strerror(errno));
+ log::error("unable to read from driver: {}", strerror(errno));
osi_free(buffer);
// add fd back to monitor thread to try it again later
btsock_thread_add_fd(pan_pth, fd, 0, SOCK_THREAD_FD_RD, 0);
return;
case 0:
- LOG_WARN("%s end of file reached.", __func__);
+ log::warn("end of file reached.");
osi_free(buffer);
// add fd back to monitor thread to process the exception
btsock_thread_add_fd(pan_pth, fd, 0, SOCK_THREAD_FD_RD, 0);
@@ -706,7 +703,7 @@ static void btu_exec_tap_fd_read(int fd) {
if (forward_bnep(&hdr, buffer) != FORWARD_CONGEST)
btpan_cb.congest_packet_size = 0;
} else {
- LOG_WARN("%s dropping packet of length %d", __func__, buffer->len);
+ log::warn("dropping packet of length {}", buffer->len);
btpan_cb.congest_packet_size = 0;
osi_free(buffer);
}
@@ -740,8 +737,7 @@ static void btpan_tap_fd_signaled(int fd, int type, int flags,
CHECK(btpan_cb.tap_fd == INVALID_FD || btpan_cb.tap_fd == fd);
if (btpan_cb.tap_fd != fd) {
- LOG_WARN("%s Signaled on mismatched fds exp:%d act:%d\n", __func__,
- btpan_cb.tap_fd, fd);
+ log::warn("Signaled on mismatched fds exp:{} act:{}", btpan_cb.tap_fd, fd);
return;
}
diff --git a/system/btif/src/btif_profile_queue.cc b/system/btif/src/btif_profile_queue.cc
index 658bda6243..74788c2264 100644
--- a/system/btif/src/btif_profile_queue.cc
+++ b/system/btif/src/btif_profile_queue.cc
@@ -32,6 +32,7 @@
#include <base/functional/callback.h>
#include <base/logging.h>
#include <base/strings/stringprintf.h>
+#include <bluetooth/log.h>
#include <string.h>
#include <list>
@@ -41,6 +42,8 @@
#include "include/check.h"
#include "types/raw_address.h"
+using namespace bluetooth;
+
/*******************************************************************************
* Local type definitions
******************************************************************************/
@@ -101,13 +104,13 @@ static void queue_int_add(uint16_t uuid, const RawAddress& bda,
ConnectNode param(bda, uuid, connect_cb);
for (const auto& node : connect_queue) {
if (node.uuid() == param.uuid() && node.address() == param.address()) {
- LOG_ERROR("Dropping duplicate profile connection request:%s",
- param.ToString().c_str());
+ log::error("Dropping duplicate profile connection request:{}",
+ param.ToString());
return;
}
}
- LOG_INFO("Queueing profile connection request:%s", param.ToString().c_str());
+ log::info("Queueing profile connection request:{}", param.ToString());
connect_queue.push_back(param);
btif_queue_connect_next();
@@ -117,22 +120,20 @@ static void queue_int_advance() {
if (connect_queue.empty()) return;
const ConnectNode& head = connect_queue.front();
- LOG_INFO("%s: removing connection request: %s", __func__,
- head.ToString().c_str());
+ log::info("removing connection request: {}", head.ToString());
connect_queue.pop_front();
btif_queue_connect_next();
}
static void queue_int_cleanup(uint16_t uuid) {
- LOG_INFO("%s: UUID=%04X", __func__, uuid);
+ log::info("UUID={:04X}", uuid);
for (auto it = connect_queue.begin(); it != connect_queue.end();) {
auto it_prev = it++;
const ConnectNode& node = *it_prev;
if (node.uuid() == uuid) {
- LOG_INFO("%s: removing connection request: %s", __func__,
- node.ToString().c_str());
+ log::info("removing connection request: {}", node.ToString());
connect_queue.erase(it_prev);
}
}
@@ -194,11 +195,11 @@ bt_status_t btif_queue_connect_next(void) {
ConnectNode& head = connect_queue.front();
- LOG_INFO("Executing profile connection request:%s", head.ToString().c_str());
+ log::info("Executing profile connection request:{}", head.ToString());
bt_status_t b_status = head.connect();
if (b_status != BT_STATUS_SUCCESS) {
- LOG_INFO("%s: connect %s failed, advance to next scheduled connection.",
- __func__, head.ToString().c_str());
+ log::info("connect {} failed, advance to next scheduled connection.",
+ head.ToString());
btif_queue_advance();
}
return b_status;
@@ -214,9 +215,9 @@ bt_status_t btif_queue_connect_next(void) {
*
******************************************************************************/
void btif_queue_release() {
- LOG_INFO("%s", __func__);
+ log::info("");
if (do_in_jni_thread(FROM_HERE, base::BindOnce(&queue_int_release)) !=
BT_STATUS_SUCCESS) {
- LOG(FATAL) << __func__ << ": Failed to schedule on JNI thread";
+ log::fatal("Failed to schedule on JNI thread");
}
}
diff --git a/system/btif/src/btif_profile_storage.cc b/system/btif/src/btif_profile_storage.cc
index 3f6d17260a..2884fb15d0 100644
--- a/system/btif/src/btif_profile_storage.cc
+++ b/system/btif/src/btif_profile_storage.cc
@@ -21,6 +21,7 @@
#include <alloca.h>
#include <base/logging.h>
+#include <bluetooth/log.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
@@ -50,6 +51,7 @@ using base::Bind;
using bluetooth::Uuid;
using bluetooth::csis::CsisClient;
using bluetooth::groups::DeviceGroups;
+using namespace bluetooth;
/*******************************************************************************
* Constants & Macros
@@ -95,7 +97,7 @@ bt_status_t btif_storage_add_hid_device_info(
uint8_t app_id, uint16_t vendor_id, uint16_t product_id, uint16_t version,
uint8_t ctry_code, uint16_t ssr_max_latency, uint16_t ssr_min_tout,
uint16_t dl_len, uint8_t* dsc_list) {
- LOG_VERBOSE("btif_storage_add_hid_device_info:");
+ log::verbose("btif_storage_add_hid_device_info:");
std::string bdstr = remote_bd_addr->ToString();
btif_config_set_int(bdstr, BTIF_STORAGE_KEY_HID_ATTR_MASK, attr_mask);
btif_config_set_int(bdstr, BTIF_STORAGE_KEY_HID_SUB_CLASS, sub_class);
@@ -129,7 +131,7 @@ bt_status_t btif_storage_load_bonded_hid_info(void) {
auto name = bd_addr.ToString();
tAclLinkSpec link_spec;
- LOG_VERBOSE("Remote device:%s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
+ log::verbose("Remote device:{}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
int value;
if (!btif_config_get_int(name, BTIF_STORAGE_KEY_HID_ATTR_MASK, &value))
@@ -272,7 +274,7 @@ std::vector<std::pair<RawAddress, uint8_t>> btif_storage_get_le_hid_devices(
btif_get_address_type(bd_addr, &type);
hid_addresses.push_back({bd_addr, type});
- LOG_DEBUG("Remote device: %s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
+ log::debug("Remote device: {}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
}
}
@@ -299,7 +301,7 @@ std::vector<RawAddress> btif_storage_get_wake_capable_classic_hid_devices(
}
hid_addresses.push_back(bd_addr);
- LOG_DEBUG("Remote device: %s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
+ log::debug("Remote device: {}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
}
}
@@ -312,8 +314,8 @@ void btif_storage_add_hearing_aid(const HearingDevice& dev_info) {
Bind(
[](const HearingDevice& dev_info) {
std::string bdstr = dev_info.address.ToString();
- VLOG(2) << "saving hearing aid device: "
- << ADDRESS_TO_LOGGABLE_STR(dev_info.address);
+ log::verbose("saving hearing aid device: {}",
+ ADDRESS_TO_LOGGABLE_STR(dev_info.address));
btif_config_set_int(
bdstr, BTIF_STORAGE_KEY_HEARING_AID_SERVICE_CHANGED_CCC_HANDLE,
dev_info.service_changed_ccc_handle);
@@ -375,7 +377,7 @@ void btif_storage_load_bonded_hearing_aids() {
continue;
}
- LOG_VERBOSE("Remote device:%s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
+ log::verbose("Remote device:{}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
if (btif_in_fetch_bonded_device(name) != BT_STATUS_SUCCESS) {
btif_storage_remove_hearing_aid(bd_addr);
@@ -537,8 +539,9 @@ void btif_storage_set_leaudio_autoconnect(const RawAddress& addr,
do_in_jni_thread(FROM_HERE, Bind(
[](const RawAddress& addr, bool autoconnect) {
std::string bdstr = addr.ToString();
- VLOG(2) << "saving le audio device: "
- << ADDRESS_TO_LOGGABLE_CSTR(addr);
+ log::verbose(
+ "saving le audio device: {}",
+ ADDRESS_TO_LOGGABLE_CSTR(addr));
btif_config_set_int(
bdstr,
BTIF_STORAGE_KEY_LEAUDIO_AUTOCONNECT,
@@ -621,8 +624,8 @@ void btif_storage_set_leaudio_audio_location(const RawAddress& addr,
Bind(
[](const RawAddress& addr, int sink_location, int source_location) {
std::string bdstr = addr.ToString();
- LOG_DEBUG("saving le audio device: %s",
- ADDRESS_TO_LOGGABLE_CSTR(addr));
+ log::debug("saving le audio device: {}",
+ ADDRESS_TO_LOGGABLE_CSTR(addr));
btif_config_set_int(bdstr,
BTIF_STORAGE_KEY_LEAUDIO_SINK_AUDIOLOCATION,
sink_location);
@@ -643,8 +646,8 @@ void btif_storage_set_leaudio_supported_context_types(
[](const RawAddress& addr, int sink_supported_context_type,
int source_supported_context_type) {
std::string bdstr = addr.ToString();
- LOG_DEBUG("saving le audio device: %s",
- ADDRESS_TO_LOGGABLE_CSTR(addr));
+ log::debug("saving le audio device: {}",
+ ADDRESS_TO_LOGGABLE_CSTR(addr));
btif_config_set_int(
bdstr, BTIF_STORAGE_KEY_LEAUDIO_SINK_SUPPORTED_CONTEXT_TYPE,
sink_supported_context_type);
@@ -679,7 +682,7 @@ void btif_storage_load_bonded_leaudio() {
continue;
}
- LOG_VERBOSE("Remote device:%s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
+ log::verbose("Remote device:{}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
int value;
bool autoconnect = false;
@@ -848,8 +851,9 @@ void btif_storage_load_bonded_leaudio_has_devices() {
if (btif_config_get_int(name, BTIF_STORAGE_KEY_LEAUDIO_HAS_FLAGS, &value))
features = value;
- do_in_main_thread(FROM_HERE, Bind(&le_audio::has::HasClient::AddFromStorage,
- bd_addr, features, is_acceptlisted));
+ do_in_main_thread(FROM_HERE,
+ Bind(&::le_audio::has::HasClient::AddFromStorage, bd_addr,
+ features, is_acceptlisted));
#else
ASSERT_LOG(false, "TODO - Fix LE audio build.");
#endif
@@ -940,7 +944,7 @@ void btif_storage_load_bonded_groups(void) {
btif_config_get_bin_length(name, BTIF_STORAGE_KEY_DEVICE_GROUP_BIN);
if (buffer_size == 0) continue;
- LOG_VERBOSE("Grouped device:%s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
+ log::verbose("Grouped device:{}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
std::vector<uint8_t> in(buffer_size);
if (btif_config_get_bin(name, BTIF_STORAGE_KEY_DEVICE_GROUP_BIN, in.data(),
@@ -985,7 +989,7 @@ void btif_storage_load_bonded_csis_devices(void) {
for (const auto& bd_addr : btif_config_get_paired_devices()) {
auto name = bd_addr.ToString();
- LOG_VERBOSE("Loading CSIS device:%s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
+ log::verbose("Loading CSIS device:{}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
size_t buffer_size =
btif_config_get_bin_length(name, BTIF_STORAGE_KEY_CSIS_SET_INFO_BIN);
@@ -1019,7 +1023,7 @@ bt_status_t btif_storage_load_hidd(void) {
for (const auto& bd_addr : btif_config_get_paired_devices()) {
auto name = bd_addr.ToString();
- LOG_VERBOSE("Remote device:%s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
+ log::verbose("Remote device:{}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
int value;
if (btif_in_fetch_bonded_device(name) == BT_STATUS_SUCCESS) {
if (btif_config_get_int(name, BTIF_STORAGE_KEY_HID_DEVICE_CABLED,
@@ -1084,14 +1088,14 @@ bt_status_t btif_storage_remove_hidd(RawAddress* remote_bd_addr) {
******************************************************************************/
void btif_storage_set_pce_profile_version(const RawAddress& remote_bd_addr,
uint16_t peer_pce_version) {
- LOG_VERBOSE("peer_pce_version : 0x%x", peer_pce_version);
+ log::verbose("peer_pce_version : 0x{:x}", peer_pce_version);
if (btif_config_set_bin(
remote_bd_addr.ToString(), BTIF_STORAGE_KEY_PBAP_PCE_VERSION,
(const uint8_t*)&peer_pce_version, sizeof(peer_pce_version))) {
} else {
- LOG_WARN("Failed to store peer_pce_version for %s",
- ADDRESS_TO_LOGGABLE_CSTR(remote_bd_addr));
+ log::warn("Failed to store peer_pce_version for {}",
+ ADDRESS_TO_LOGGABLE_CSTR(remote_bd_addr));
}
}
@@ -1113,8 +1117,8 @@ bool btif_storage_is_pce_version_102(const RawAddress& remote_bd_addr) {
if (!btif_config_get_bin(remote_bd_addr.ToString(),
BTIF_STORAGE_KEY_PBAP_PCE_VERSION,
(uint8_t*)&pce_version, &version_value_size)) {
- LOG_VERBOSE("Failed to read cached peer PCE version for %s",
- ADDRESS_TO_LOGGABLE_CSTR(remote_bd_addr));
+ log::verbose("Failed to read cached peer PCE version for {}",
+ ADDRESS_TO_LOGGABLE_CSTR(remote_bd_addr));
return entry_found;
}
@@ -1122,8 +1126,8 @@ bool btif_storage_is_pce_version_102(const RawAddress& remote_bd_addr) {
entry_found = true;
}
- LOG_VERBOSE("read cached peer PCE version 0x%04x for %s", pce_version,
- ADDRESS_TO_LOGGABLE_CSTR(remote_bd_addr));
+ log::verbose("read cached peer PCE version 0x{:04x} for {}", pce_version,
+ ADDRESS_TO_LOGGABLE_CSTR(remote_bd_addr));
return entry_found;
}
diff --git a/system/btif/src/btif_rc.cc b/system/btif/src/btif_rc.cc
index 20f4ddac94..79d4a69b70 100644
--- a/system/btif/src/btif_rc.cc
+++ b/system/btif/src/btif_rc.cc
@@ -27,6 +27,7 @@
#include "btif_rc.h"
#include <base/logging.h>
+#include <bluetooth/log.h>
#include <fcntl.h>
#include <hardware/bluetooth.h>
#include <hardware/bt_rc.h>
@@ -95,22 +96,24 @@
#define PLAY_STATUS_PLAYING 1
#define BTIF_RC_NUM_CONN BT_RC_NUM_APP
-#define CHECK_RC_CONNECTED(p_dev) \
- do { \
- if ((p_dev) == NULL || !(p_dev)->rc_connected) { \
- LOG_WARN("%s: called when RC is not connected", __func__); \
- return BT_STATUS_NOT_READY; \
- } \
+#define CHECK_RC_CONNECTED(p_dev) \
+ do { \
+ if ((p_dev) == NULL || !(p_dev)->rc_connected) { \
+ log::warn("called when RC is not connected"); \
+ return BT_STATUS_NOT_READY; \
+ } \
} while (0)
-#define CHECK_BR_CONNECTED(p_dev) \
- do { \
- if ((p_dev) == NULL || !(p_dev)->br_connected) { \
- LOG_WARN("%s: called when BR is not connected", __func__); \
- return BT_STATUS_NOT_READY; \
- } \
+#define CHECK_BR_CONNECTED(p_dev) \
+ do { \
+ if ((p_dev) == NULL || !(p_dev)->br_connected) { \
+ log::warn("called when BR is not connected"); \
+ return BT_STATUS_NOT_READY; \
+ } \
} while (0)
+using namespace bluetooth;
+
/*****************************************************************************
* Local type definitions
*****************************************************************************/
@@ -411,18 +414,18 @@ static const uint8_t media_attr_list_no_cover_art_size =
bool check_cod(const RawAddress& remote_bdaddr, uint32_t cod);
void btif_rc_get_addr_by_handle(uint8_t handle, RawAddress& rc_addr) {
- LOG_VERBOSE("%s: handle: 0x%x", __func__, handle);
+ log::verbose("handle: 0x{:x}", handle);
for (int idx = 0; idx < BTIF_RC_NUM_CONN; idx++) {
if ((btif_rc_cb.rc_multi_cb[idx].rc_state !=
BTRC_CONNECTION_STATE_DISCONNECTED) &&
(btif_rc_cb.rc_multi_cb[idx].rc_handle == handle)) {
- LOG_VERBOSE("%s: btif_rc_cb.rc_multi_cb[idx].rc_handle: 0x%x", __func__,
- btif_rc_cb.rc_multi_cb[idx].rc_handle);
+ log::verbose("btif_rc_cb.rc_multi_cb[idx].rc_handle: 0x{:x}",
+ btif_rc_cb.rc_multi_cb[idx].rc_handle);
rc_addr = btif_rc_cb.rc_multi_cb[idx].rc_addr;
return;
}
}
- LOG_ERROR("%s: returning NULL", __func__);
+ log::error("returning NULL");
rc_addr = RawAddress::kEmpty;
return;
}
@@ -479,22 +482,21 @@ void initialize_device(btif_rc_device_cb_t* p_dev) {
}
static btif_rc_device_cb_t* get_connected_device(int index) {
- LOG_VERBOSE("%s: index: %d", __func__, index);
+ log::verbose("index: {}", index);
if (index >= BTIF_RC_NUM_CONN) {
- LOG_ERROR("%s: can't support more than %d connections", __func__,
- BTIF_RC_NUM_CONN);
+ log::error("can't support more than {} connections", BTIF_RC_NUM_CONN);
return NULL;
}
if (btif_rc_cb.rc_multi_cb[index].rc_state !=
BTRC_CONNECTION_STATE_CONNECTED) {
- LOG_ERROR("%s: returning NULL", __func__);
+ log::error("returning NULL");
return NULL;
}
return (&btif_rc_cb.rc_multi_cb[index]);
}
btif_rc_device_cb_t* btif_rc_get_device_by_bda(const RawAddress& bd_addr) {
- VLOG(1) << __func__ << ": bd_addr: " << ADDRESS_TO_LOGGABLE_STR(bd_addr);
+ log::verbose("bd_addr: {}", ADDRESS_TO_LOGGABLE_STR(bd_addr));
for (int idx = 0; idx < BTIF_RC_NUM_CONN; idx++) {
if ((btif_rc_cb.rc_multi_cb[idx].rc_state !=
@@ -503,22 +505,22 @@ btif_rc_device_cb_t* btif_rc_get_device_by_bda(const RawAddress& bd_addr) {
return (&btif_rc_cb.rc_multi_cb[idx]);
}
}
- LOG_ERROR("%s: device not found, returning NULL!", __func__);
+ log::error("device not found, returning NULL!");
return NULL;
}
btif_rc_device_cb_t* btif_rc_get_device_by_handle(uint8_t handle) {
- LOG_VERBOSE("%s: handle: 0x%x", __func__, handle);
+ log::verbose("handle: 0x{:x}", handle);
for (int idx = 0; idx < BTIF_RC_NUM_CONN; idx++) {
if ((btif_rc_cb.rc_multi_cb[idx].rc_state !=
BTRC_CONNECTION_STATE_DISCONNECTED) &&
(btif_rc_cb.rc_multi_cb[idx].rc_handle == handle)) {
- LOG_VERBOSE("%s: btif_rc_cb.rc_multi_cb[idx].rc_handle: 0x%x", __func__,
- btif_rc_cb.rc_multi_cb[idx].rc_handle);
+ log::verbose("btif_rc_cb.rc_multi_cb[idx].rc_handle: 0x{:x}",
+ btif_rc_cb.rc_multi_cb[idx].rc_handle);
return (&btif_rc_cb.rc_multi_cb[idx]);
}
}
- LOG_ERROR("%s: returning NULL", __func__);
+ log::error("returning NULL");
return NULL;
}
@@ -549,15 +551,15 @@ void fill_avrc_attr_entry(tAVRC_ATTR_ENTRY* attr_vals, int num_attrs,
attr_vals[attr_cnt].name.str_len =
(uint16_t)strlen((char*)p_attrs[attr_cnt].text);
attr_vals[attr_cnt].name.p_str = p_attrs[attr_cnt].text;
- LOG_VERBOSE("%s: attr_id: 0x%x, charset_id: 0x%x, str_len: %d, str: %s",
- __func__, (unsigned int)attr_vals[attr_cnt].attr_id,
- attr_vals[attr_cnt].name.charset_id,
- attr_vals[attr_cnt].name.str_len,
- attr_vals[attr_cnt].name.p_str);
+ log::verbose("attr_id: 0x{:x}, charset_id: 0x{:x}, str_len: {}, str: {}",
+ (unsigned int)attr_vals[attr_cnt].attr_id,
+ attr_vals[attr_cnt].name.charset_id,
+ attr_vals[attr_cnt].name.str_len,
+ reinterpret_cast<char const*>(attr_vals[attr_cnt].name.p_str));
}
}
-void rc_cleanup_sent_cmd(void* p_data) { LOG_VERBOSE("%s: ", __func__); }
+void rc_cleanup_sent_cmd(void* p_data) { log::verbose(""); }
void handle_rc_ctrl_features_all(btif_rc_device_cb_t* p_dev) {
if (!(p_dev->peer_tg_features & BTA_AV_FEAT_RCTG) &&
@@ -568,11 +570,11 @@ void handle_rc_ctrl_features_all(btif_rc_device_cb_t* p_dev) {
int rc_features = 0;
- LOG_VERBOSE(
- "%s: peer_tg_features: 0x%x, rc_features_processed=%d, connected=%d, "
- "peer_is_src:%d",
- __func__, p_dev->peer_tg_features, p_dev->rc_features_processed,
- btif_av_is_connected_addr(p_dev->rc_addr),
+ log::verbose(
+ "peer_tg_features: 0x{:x}, rc_features_processed={}, connected={}, "
+ "peer_is_src:{}",
+ p_dev->peer_tg_features, p_dev->rc_features_processed,
+ btif_av_is_connected_addr(p_dev->rc_addr, A2dpType::kSink),
btif_av_peer_is_source(p_dev->rc_addr));
if ((p_dev->peer_tg_features & BTA_AV_FEAT_ADV_CTRL) &&
@@ -592,7 +594,7 @@ void handle_rc_ctrl_features_all(btif_rc_device_cb_t* p_dev) {
p_dev->rc_features_processed = true;
}
- if (btif_av_is_connected_addr(p_dev->rc_addr)) {
+ if (btif_av_is_connected_addr(p_dev->rc_addr, A2dpType::kSink)) {
if (btif_av_peer_is_source(p_dev->rc_addr)) {
p_dev->rc_features = p_dev->peer_tg_features;
if ((p_dev->peer_tg_features & BTA_AV_FEAT_METADATA) &&
@@ -601,8 +603,8 @@ void handle_rc_ctrl_features_all(btif_rc_device_cb_t* p_dev) {
}
}
} else {
- LOG_VERBOSE("%s: %s is not connected, pending", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(p_dev->rc_addr));
+ log::verbose("{} is not connected, pending",
+ ADDRESS_TO_LOGGABLE_CSTR(p_dev->rc_addr));
p_dev->launch_cmd_pending |=
(RC_PENDING_ACT_GET_CAP | RC_PENDING_ACT_REG_VOL);
}
@@ -618,7 +620,7 @@ void handle_rc_ctrl_features_all(btif_rc_device_cb_t* p_dev) {
}
if (bt_rc_ctrl_callbacks != NULL) {
- LOG_VERBOSE("%s: Update rc features to CTRL: %d", __func__, rc_features);
+ log::verbose("Update rc features to CTRL: {}", rc_features);
do_in_jni_thread(FROM_HERE,
base::BindOnce(bt_rc_ctrl_callbacks->getrcfeatures_cb,
p_dev->rc_addr, rc_features));
@@ -670,7 +672,7 @@ void handle_rc_ctrl_features(btif_rc_device_cb_t* p_dev) {
rc_features |= BTRC_FEAT_COVER_ARTWORK;
}
- LOG_VERBOSE("%s: Update rc features to CTRL: %d", __func__, rc_features);
+ log::verbose("Update rc features to CTRL: {}", rc_features);
do_in_jni_thread(FROM_HERE,
base::BindOnce(bt_rc_ctrl_callbacks->getrcfeatures_cb,
p_dev->rc_addr, rc_features));
@@ -679,15 +681,15 @@ void btif_rc_check_pending_cmd(const RawAddress& peer_address) {
btif_rc_device_cb_t* p_dev = NULL;
p_dev = btif_rc_get_device_by_bda(peer_address);
if (p_dev == NULL) {
- LOG_ERROR("%s: p_dev NULL", __func__);
+ log::error("p_dev NULL");
return;
}
- LOG_VERBOSE(
- "%s: launch_cmd_pending=%d, rc_connected=%d, peer_ct_features=0x%x, "
- "peer_tg_features=0x%x",
- __FUNCTION__, p_dev->launch_cmd_pending, p_dev->rc_connected,
- p_dev->peer_ct_features, p_dev->peer_tg_features);
+ log::verbose(
+ "launch_cmd_pending={}, rc_connected={}, peer_ct_features=0x{:x}, "
+ "peer_tg_features=0x{:x}",
+ p_dev->launch_cmd_pending, p_dev->rc_connected, p_dev->peer_ct_features,
+ p_dev->peer_tg_features);
if (p_dev->launch_cmd_pending && p_dev->rc_connected) {
if ((p_dev->launch_cmd_pending & RC_PENDING_ACT_REG_VOL) &&
btif_av_peer_is_sink(p_dev->rc_addr)) {
@@ -714,8 +716,7 @@ void btif_rc_check_pending_cmd(const RawAddress& peer_address) {
void handle_rc_ctrl_psm(btif_rc_device_cb_t* p_dev) {
uint16_t cover_art_psm = p_dev->rc_cover_art_psm;
- LOG_VERBOSE("%s: Update rc cover art psm to CTRL: %d", __func__,
- cover_art_psm);
+ log::verbose("Update rc cover art psm to CTRL: {}", cover_art_psm);
if (bt_rc_ctrl_callbacks != NULL) {
do_in_jni_thread(FROM_HERE,
base::BindOnce(bt_rc_ctrl_callbacks->get_cover_art_psm_cb,
@@ -731,11 +732,10 @@ void handle_rc_features(btif_rc_device_cb_t* p_dev) {
RawAddress avdtp_source_active_peer_addr = btif_av_source_active_peer();
RawAddress avdtp_sink_active_peer_addr = btif_av_sink_active_peer();
- LOG_VERBOSE(
- "%s: AVDTP Source Active Peer Address: %s "
- "AVDTP Sink Active Peer Address: %s "
- "AVCTP address: %s",
- __func__, ADDRESS_TO_LOGGABLE_CSTR(avdtp_source_active_peer_addr),
+ log::verbose(
+ "AVDTP Source Active Peer Address: {} AVDTP Sink Active Peer Address: {} "
+ "AVCTP address: {}",
+ ADDRESS_TO_LOGGABLE_CSTR(avdtp_source_active_peer_addr),
ADDRESS_TO_LOGGABLE_CSTR(avdtp_sink_active_peer_addr),
ADDRESS_TO_LOGGABLE_CSTR(p_dev->rc_addr));
@@ -764,12 +764,11 @@ void handle_rc_features(btif_rc_device_cb_t* p_dev) {
(btrc_remote_features_t)(rc_features | BTRC_FEAT_ABSOLUTE_VOLUME);
}
- LOG_VERBOSE("%s: rc_features: 0x%x", __func__, rc_features);
+ log::verbose("rc_features: 0x{:x}", rc_features);
HAL_CBACK(bt_rc_callbacks, remote_features_cb, p_dev->rc_addr, rc_features);
- LOG_VERBOSE(
- "%s: Checking for feature flags in btif_rc_handler with label: %d",
- __func__, p_dev->rc_vol_label);
+ log::verbose("Checking for feature flags in btif_rc_handler with label: {}",
+ p_dev->rc_vol_label);
// Register for volume change on connect
if (p_dev->rc_features & BTA_AV_FEAT_ADV_CTRL &&
p_dev->rc_features & BTA_AV_FEAT_RCTG) {
@@ -786,13 +785,13 @@ void handle_rc_features(btif_rc_device_cb_t* p_dev) {
*
***************************************************************************/
void handle_rc_browse_connect(tBTA_AV_RC_BROWSE_OPEN* p_rc_br_open) {
- LOG_VERBOSE("%s: rc_handle %d status %d", __func__, p_rc_br_open->rc_handle,
- p_rc_br_open->status);
+ log::verbose("rc_handle {} status {}", p_rc_br_open->rc_handle,
+ p_rc_br_open->status);
btif_rc_device_cb_t* p_dev =
btif_rc_get_device_by_handle(p_rc_br_open->rc_handle);
if (!p_dev) {
- LOG_ERROR("%s p_dev is null", __func__);
+ log::error("p_dev is null");
return;
}
@@ -811,7 +810,7 @@ void handle_rc_browse_connect(tBTA_AV_RC_BROWSE_OPEN* p_rc_br_open) {
}
} else {
p_dev->launch_cmd_pending |= RC_PENDING_ACT_REPORT_CONN;
- LOG_VERBOSE("%s: pending rc browse connection event", __func__);
+ log::verbose("pending rc browse connection event");
}
} else {
if (bt_rc_ctrl_callbacks != NULL) {
@@ -820,7 +819,7 @@ void handle_rc_browse_connect(tBTA_AV_RC_BROWSE_OPEN* p_rc_br_open) {
base::BindOnce(bt_rc_ctrl_callbacks->connection_state_cb, true,
true, p_dev->rc_addr));
} else {
- LOG_WARN("%s: bt_rc_ctrl_callbacks is null.", __func__);
+ log::warn("bt_rc_ctrl_callbacks is null.");
}
}
}
@@ -835,17 +834,16 @@ void handle_rc_browse_connect(tBTA_AV_RC_BROWSE_OPEN* p_rc_br_open) {
*
***************************************************************************/
void handle_rc_connect(tBTA_AV_RC_OPEN* p_rc_open) {
- LOG_VERBOSE("%s: rc_handle: %d", __func__, p_rc_open->rc_handle);
+ log::verbose("rc_handle: {}", p_rc_open->rc_handle);
btif_rc_device_cb_t* p_dev = alloc_device();
if (p_dev == NULL) {
- LOG_ERROR("%s: p_dev is NULL", __func__);
+ log::error("p_dev is NULL");
return;
}
if (!(p_rc_open->status == BTA_AV_SUCCESS)) {
- LOG_ERROR("%s: Connect failed with error code: %d", __func__,
- p_rc_open->status);
+ log::error("Connect failed with error code: {}", p_rc_open->status);
p_dev->rc_connected = false;
BTA_AvCloseRc(p_rc_open->rc_handle);
p_dev->rc_handle = 0;
@@ -868,7 +866,7 @@ void handle_rc_connect(tBTA_AV_RC_OPEN* p_rc_open) {
__func__, p_dev->rc_handle, p_rc_open->rc_handle);
if (p_dev->rc_handle != p_rc_open->rc_handle &&
p_dev->rc_addr != p_rc_open->peer_addr) {
- LOG_VERBOSE("%s: Got RC connected for some other handle", __func__);
+ log::verbose("Got RC connected for some other handle");
BTA_AvCloseRc(p_rc_open->rc_handle);
return;
}
@@ -881,12 +879,11 @@ void handle_rc_connect(tBTA_AV_RC_OPEN* p_rc_open) {
p_dev->rc_vol_label = MAX_LABEL;
p_dev->rc_volume = MAX_VOLUME;
- LOG_VERBOSE(
- "%s: handle_rc_connect in features=%#x, out features=%#x, "
- "ct_feature=%#x, tg_feature=%#x, cover art psm=%#x",
- __func__, p_rc_open->peer_features, p_dev->rc_features,
- p_dev->peer_ct_features, p_dev->peer_tg_features,
- p_dev->rc_cover_art_psm);
+ log::verbose(
+ "handle_rc_connect in features={:#x}, out features={:#x}, "
+ "ct_feature={:#x}, tg_feature={:#x}, cover art psm={:#x}",
+ p_rc_open->peer_features, p_dev->rc_features, p_dev->peer_ct_features,
+ p_dev->peer_tg_features, p_dev->rc_cover_art_psm);
p_dev->rc_connected = true;
p_dev->rc_handle = p_rc_open->rc_handle;
@@ -897,7 +894,7 @@ void handle_rc_connect(tBTA_AV_RC_OPEN* p_rc_open) {
if (btif_av_src_sink_coexist_enabled() &&
!btif_av_peer_is_connected_source(p_dev->rc_addr)) {
p_dev->launch_cmd_pending |= RC_PENDING_ACT_REPORT_CONN;
- LOG_VERBOSE("%s: pending rc connection event", __func__);
+ log::verbose("pending rc connection event");
return;
}
if (bt_rc_ctrl_callbacks != NULL) {
@@ -922,17 +919,17 @@ void handle_rc_connect(tBTA_AV_RC_OPEN* p_rc_open) {
***************************************************************************/
void handle_rc_disconnect(tBTA_AV_RC_CLOSE* p_rc_close) {
btif_rc_device_cb_t* p_dev = NULL;
- LOG_VERBOSE("%s: rc_handle: %d", __func__, p_rc_close->rc_handle);
+ log::verbose("rc_handle: {}", p_rc_close->rc_handle);
p_dev = btif_rc_get_device_by_handle(p_rc_close->rc_handle);
if (p_dev == NULL) {
- LOG_ERROR("%s: Got disconnect from invalid rc handle", __func__);
+ log::error("Got disconnect from invalid rc handle");
return;
}
if (p_rc_close->rc_handle != p_dev->rc_handle &&
p_dev->rc_addr != p_rc_close->peer_addr) {
- LOG_ERROR("Got disconnect of unknown device");
+ log::error("Got disconnect of unknown device");
return;
}
@@ -959,24 +956,25 @@ void handle_rc_disconnect(tBTA_AV_RC_CLOSE* p_rc_close) {
***************************************************************************/
void handle_rc_passthrough_cmd(tBTA_AV_REMOTE_CMD* p_remote_cmd) {
if (p_remote_cmd == NULL) {
- LOG_ERROR("%s: No remote command!", __func__);
+ log::error("No remote command!");
return;
}
btif_rc_device_cb_t* p_dev =
btif_rc_get_device_by_handle(p_remote_cmd->rc_handle);
if (p_dev == NULL) {
- LOG_ERROR("%s: Got passthrough command from invalid rc handle", __func__);
+ log::error("Got passthrough command from invalid rc handle");
return;
}
- LOG_VERBOSE("%s: p_remote_cmd->rc_id: %d", __func__, p_remote_cmd->rc_id);
+ log::verbose("p_remote_cmd->rc_id: {}", p_remote_cmd->rc_id);
/* If AVRC is open and peer sends PLAY but there is no AVDT, then we queue-up
* this PLAY */
- if ((p_remote_cmd->rc_id == AVRC_ID_PLAY) && (!btif_av_is_connected())) {
+ if ((p_remote_cmd->rc_id == AVRC_ID_PLAY) &&
+ (!btif_av_is_connected(A2dpType::kSink))) {
if (p_remote_cmd->key_state == AVRC_STATE_PRESS) {
- LOG_WARN("%s: AVDT not open, queuing the PLAY command", __func__);
+ log::warn("AVDT not open, queuing the PLAY command");
p_dev->rc_pending_play = true;
}
return;
@@ -984,22 +982,22 @@ void handle_rc_passthrough_cmd(tBTA_AV_REMOTE_CMD* p_remote_cmd) {
/* If we previously queued a play and we get a PAUSE, clear it. */
if ((p_remote_cmd->rc_id == AVRC_ID_PAUSE) && (p_dev->rc_pending_play)) {
- LOG_WARN("%s: Clear the pending PLAY on PAUSE received", __func__);
+ log::warn("Clear the pending PLAY on PAUSE received");
p_dev->rc_pending_play = false;
return;
}
if ((p_remote_cmd->rc_id == AVRC_ID_STOP) &&
- (!btif_av_stream_started_ready())) {
- LOG_WARN("%s: Stream suspended, ignore STOP cmd", __func__);
+ (!btif_av_stream_started_ready(A2dpType::kSink))) {
+ log::warn("Stream suspended, ignore STOP cmd");
return;
}
int pressed = (p_remote_cmd->key_state == AVRC_STATE_PRESS) ? 1 : 0;
/* pass all commands up */
- LOG_VERBOSE("%s: rc_features: %d, cmd->rc_id: %d, pressed: %d", __func__,
- p_dev->rc_features, p_remote_cmd->rc_id, pressed);
+ log::verbose("rc_features: {}, cmd->rc_id: {}, pressed: {}",
+ p_dev->rc_features, p_remote_cmd->rc_id, pressed);
HAL_CBACK(bt_rc_callbacks, passthrough_cmd_cb, p_remote_cmd->rc_id, pressed,
p_dev->rc_addr);
}
@@ -1017,18 +1015,18 @@ void handle_rc_passthrough_rsp(tBTA_AV_REMOTE_RSP* p_remote_rsp) {
p_dev = btif_rc_get_device_by_handle(p_remote_rsp->rc_handle);
if (p_dev == NULL) {
- LOG_ERROR("%s: passthrough response for Invalid rc handle", __func__);
+ log::error("passthrough response for Invalid rc handle");
return;
}
if (!(p_dev->rc_features & BTA_AV_FEAT_RCTG)) {
- LOG_ERROR("%s: DUT does not support AVRCP controller role", __func__);
+ log::error("DUT does not support AVRCP controller role");
return;
}
const char* status = (p_remote_rsp->key_state == 1) ? "released" : "pressed";
- LOG_VERBOSE("%s: rc_id: %d state: %s", __func__, p_remote_rsp->rc_id, status);
+ log::verbose("rc_id: {} state: {}", p_remote_rsp->rc_id, status);
release_transaction(p_dev, p_remote_rsp->label);
if (bt_rc_ctrl_callbacks != NULL) {
@@ -1054,7 +1052,7 @@ void handle_rc_vendorunique_rsp(tBTA_AV_REMOTE_RSP* p_remote_rsp) {
p_dev = btif_rc_get_device_by_handle(p_remote_rsp->rc_handle);
if (p_dev == NULL) {
- LOG_ERROR("%s: Got vendorunique rsp from invalid rc handle", __func__);
+ log::error("Got vendorunique rsp from invalid rc handle");
return;
}
@@ -1073,14 +1071,14 @@ void handle_rc_vendorunique_rsp(tBTA_AV_REMOTE_RSP* p_remote_rsp) {
vendor_id = p_remote_rsp->p_data[AVRC_PASS_THRU_GROUP_LEN - 1];
osi_free_and_reset((void**)&p_remote_rsp->p_data);
}
- LOG_VERBOSE("%s: vendor_id: %d status: %s", __func__, vendor_id, status);
+ log::verbose("vendor_id: {} status: {}", vendor_id, status);
release_transaction(p_dev, p_remote_rsp->label);
do_in_jni_thread(
FROM_HERE, base::BindOnce(bt_rc_ctrl_callbacks->groupnavigation_rsp_cb,
vendor_id, key_state));
} else {
- LOG_ERROR("%s: Remote does not support AVRCP TG role", __func__);
+ log::error("Remote does not support AVRCP TG role");
}
}
@@ -1101,33 +1099,33 @@ void handle_rc_metamsg_cmd(tBTA_AV_META_MSG* pmeta_msg) {
btif_rc_device_cb_t* p_dev = NULL;
if (NULL == pmeta_msg) {
- LOG_VERBOSE("%s: Exiting as pmeta_msg is NULL", __func__);
+ log::verbose("Exiting as pmeta_msg is NULL");
return;
}
if (NULL == pmeta_msg->p_msg) {
- LOG_VERBOSE("%s: Exiting as pmeta_msg->p_msg is NULL", __func__);
+ log::verbose("Exiting as pmeta_msg->p_msg is NULL");
return;
}
- LOG_VERBOSE("%s: pmeta_msg: opcode: %x, code: %x", __func__,
- pmeta_msg->p_msg->hdr.opcode, pmeta_msg->code);
+ log::verbose("pmeta_msg: opcode: {:x}, code: {:x}",
+ pmeta_msg->p_msg->hdr.opcode, pmeta_msg->code);
p_dev = btif_rc_get_device_by_handle(pmeta_msg->rc_handle);
if (p_dev == NULL) {
- LOG_ERROR("%s: Meta msg event for Invalid rc handle", __func__);
+ log::error("Meta msg event for Invalid rc handle");
return;
}
if (pmeta_msg->p_msg->hdr.opcode != AVRC_OP_VENDOR &&
pmeta_msg->p_msg->hdr.opcode != AVRC_OP_BROWSE) {
- LOG_WARN("Invalid opcode: %x", pmeta_msg->p_msg->hdr.opcode);
+ log::warn("Invalid opcode: {:x}", pmeta_msg->p_msg->hdr.opcode);
return;
}
if (pmeta_msg->len < 3) {
- LOG_WARN("%s: Invalid length. opcode: 0x%x, len: 0x%x", __func__,
- pmeta_msg->p_msg->hdr.opcode, pmeta_msg->len);
+ log::warn("Invalid length. opcode: 0x{:x}, len: 0x{:x}",
+ pmeta_msg->p_msg->hdr.opcode, pmeta_msg->len);
return;
}
@@ -1138,8 +1136,8 @@ void handle_rc_metamsg_cmd(tBTA_AV_META_MSG* pmeta_msg) {
if (transaction != NULL) {
handle_rc_metamsg_rsp(pmeta_msg, p_dev);
} else {
- LOG_VERBOSE("%s: Discard vendor dependent rsp. code: %d label: %d.",
- __func__, pmeta_msg->code, pmeta_msg->label);
+ log::verbose("Discard vendor dependent rsp. code: {} label: {}.",
+ pmeta_msg->code, pmeta_msg->label);
}
return;
}
@@ -1147,14 +1145,13 @@ void handle_rc_metamsg_cmd(tBTA_AV_META_MSG* pmeta_msg) {
status = AVRC_ParsCommand(pmeta_msg->p_msg, &avrc_command, scratch_buf,
sizeof(scratch_buf));
- LOG_VERBOSE("%s: Received vendor command.code,PDU and label: %d, %d, %d",
- __func__, pmeta_msg->code, avrc_command.cmd.pdu,
- pmeta_msg->label);
+ log::verbose("Received vendor command.code,PDU and label: {}, {}, {}",
+ pmeta_msg->code, avrc_command.cmd.pdu, pmeta_msg->label);
if (status != AVRC_STS_NO_ERROR) {
/* return error */
- LOG_WARN("%s: Error in parsing received metamsg command. status: 0x%02x",
- __func__, status);
+ log::warn("Error in parsing received metamsg command. status: 0x{:02x}",
+ status);
send_reject_response(pmeta_msg->rc_handle, pmeta_msg->label,
avrc_command.pdu, status,
pmeta_msg->p_msg->hdr.opcode);
@@ -1164,10 +1161,10 @@ void handle_rc_metamsg_cmd(tBTA_AV_META_MSG* pmeta_msg) {
if (avrc_command.cmd.pdu == AVRC_PDU_REGISTER_NOTIFICATION) {
uint8_t event_id = avrc_command.reg_notif.event_id;
- LOG_VERBOSE(
- "%s: New register notification received.event_id: %s, label: 0x%x, "
- "code: %x",
- __func__, dump_rc_notification_event_id(event_id), pmeta_msg->label,
+ log::verbose(
+ "New register notification received.event_id: {}, label: 0x{:x}, "
+ "code: {:x}",
+ dump_rc_notification_event_id(event_id), pmeta_msg->label,
pmeta_msg->code);
p_dev->rc_notif[event_id - 1].bNotify = true;
p_dev->rc_notif[event_id - 1].label = pmeta_msg->label;
@@ -1182,8 +1179,8 @@ void handle_rc_metamsg_cmd(tBTA_AV_META_MSG* pmeta_msg) {
avrc_command.cmd.pdu == AVRC_PDU_SET_ABSOLUTE_VOLUME) {
return;
}
- LOG_VERBOSE("%s: Passing received metamsg command to app. pdu: %s",
- __func__, dump_rc_pdu(avrc_command.cmd.pdu));
+ log::verbose("Passing received metamsg command to app. pdu: {}",
+ dump_rc_pdu(avrc_command.cmd.pdu));
/* Since handle_rc_metamsg_cmd() itself is called from
*btif context, no context switching is required. Invoke
@@ -1201,12 +1198,13 @@ void handle_rc_metamsg_cmd(tBTA_AV_META_MSG* pmeta_msg) {
**
***************************************************************************/
void btif_rc_handler(tBTA_AV_EVT event, tBTA_AV* p_data) {
- LOG_VERBOSE("%s: event: %s", __func__, dump_rc_event(event));
+ log::verbose("event: {}", dump_rc_event(event));
btif_rc_device_cb_t* p_dev = NULL;
switch (event) {
case BTA_AV_RC_OPEN_EVT: {
- LOG_VERBOSE("%s: Peer_features: 0x%x Cover Art PSM: 0x%x", __func__,
- p_data->rc_open.peer_features, p_data->rc_open.cover_art_psm);
+ log::verbose("Peer_features: 0x{:x} Cover Art PSM: 0x{:x}",
+ p_data->rc_open.peer_features,
+ p_data->rc_open.cover_art_psm);
handle_rc_connect(&(p_data->rc_open));
} break;
@@ -1221,23 +1219,22 @@ void btif_rc_handler(tBTA_AV_EVT event, tBTA_AV* p_data) {
} break;
case BTA_AV_RC_BROWSE_CLOSE_EVT: {
- LOG_VERBOSE("%s: BTA_AV_RC_BROWSE_CLOSE_EVT", __func__);
+ log::verbose("BTA_AV_RC_BROWSE_CLOSE_EVT");
} break;
case BTA_AV_REMOTE_CMD_EVT: {
if (bt_rc_callbacks != NULL) {
- LOG_VERBOSE("%s: rc_id: 0x%x key_state: %d", __func__,
- p_data->remote_cmd.rc_id, p_data->remote_cmd.key_state);
+ log::verbose("rc_id: 0x{:x} key_state: {}", p_data->remote_cmd.rc_id,
+ p_data->remote_cmd.key_state);
handle_rc_passthrough_cmd((&p_data->remote_cmd));
} else {
- LOG_ERROR("%s: AVRCP TG role not up, drop passthrough commands",
- __func__);
+ log::error("AVRCP TG role not up, drop passthrough commands");
}
} break;
case BTA_AV_REMOTE_RSP_EVT: {
- LOG_VERBOSE("%s: RSP: rc_id: 0x%x key_state: %d", __func__,
- p_data->remote_rsp.rc_id, p_data->remote_rsp.key_state);
+ log::verbose("RSP: rc_id: 0x{:x} key_state: {}", p_data->remote_rsp.rc_id,
+ p_data->remote_rsp.key_state);
if (p_data->remote_rsp.rc_id == AVRC_ID_VENDOR) {
handle_rc_vendorunique_rsp((&p_data->remote_rsp));
@@ -1247,20 +1244,19 @@ void btif_rc_handler(tBTA_AV_EVT event, tBTA_AV* p_data) {
} break;
case BTA_AV_RC_FEAT_EVT: {
- LOG_VERBOSE("%s: Peer_features: %x", __func__,
- p_data->rc_feat.peer_features);
+ log::verbose("Peer_features: {:x}", p_data->rc_feat.peer_features);
p_dev = btif_rc_get_device_by_handle(p_data->rc_feat.rc_handle);
if (p_dev == NULL) {
- LOG_ERROR("%s: RC Feature event for Invalid rc handle", __func__);
+ log::error("RC Feature event for Invalid rc handle");
break;
}
- LOG_VERBOSE("%s peer_ct_features:0x%x, peer_tg_features=0x%x", __func__,
- p_data->rc_feat.peer_ct_features,
- p_data->rc_feat.peer_tg_features);
+ log::verbose("peer_ct_features:0x{:x}, peer_tg_features=0x{:x}",
+ p_data->rc_feat.peer_ct_features,
+ p_data->rc_feat.peer_tg_features);
if (btif_av_src_sink_coexist_enabled() &&
(p_dev->peer_ct_features == p_data->rc_feat.peer_ct_features) &&
(p_dev->peer_tg_features == p_data->rc_feat.peer_tg_features)) {
- LOG_ERROR(
+ log::error(
"do SDP twice, no need callback rc_feature to framework again");
break;
}
@@ -1278,11 +1274,11 @@ void btif_rc_handler(tBTA_AV_EVT event, tBTA_AV* p_data) {
} break;
case BTA_AV_RC_PSM_EVT: {
- LOG_VERBOSE("%s: Peer cover art PSM: %x", __func__,
- p_data->rc_cover_art_psm.cover_art_psm);
+ log::verbose("Peer cover art PSM: {:x}",
+ p_data->rc_cover_art_psm.cover_art_psm);
p_dev = btif_rc_get_device_by_handle(p_data->rc_cover_art_psm.rc_handle);
if (p_dev == NULL) {
- LOG_ERROR("%s: RC PSM event for Invalid rc handle", __func__);
+ log::error("RC PSM event for Invalid rc handle");
break;
}
@@ -1294,11 +1290,11 @@ void btif_rc_handler(tBTA_AV_EVT event, tBTA_AV* p_data) {
case BTA_AV_META_MSG_EVT: {
if (bt_rc_callbacks != NULL) {
- LOG_VERBOSE("%s: BTA_AV_META_MSG_EVT code: %d label: %d", __func__,
- p_data->meta_msg.code, p_data->meta_msg.label);
- LOG_VERBOSE("%s: company_id: 0x%x len: %d handle: %d", __func__,
- p_data->meta_msg.company_id, p_data->meta_msg.len,
- p_data->meta_msg.rc_handle);
+ log::verbose("BTA_AV_META_MSG_EVT code: {} label: {}",
+ p_data->meta_msg.code, p_data->meta_msg.label);
+ log::verbose("company_id: 0x{:x} len: {} handle: {}",
+ p_data->meta_msg.company_id, p_data->meta_msg.len,
+ p_data->meta_msg.rc_handle);
/* handle the metamsg command */
handle_rc_metamsg_cmd(&(p_data->meta_msg));
@@ -1306,14 +1302,13 @@ void btif_rc_handler(tBTA_AV_EVT event, tBTA_AV* p_data) {
/* Free the Memory allocated for tAVRC_MSG */
} else if (bt_rc_ctrl_callbacks != NULL) {
/* This is case of Sink + CT + TG(for abs vol)) */
- LOG_VERBOSE(
- "%s BTA_AV_META_MSG_EVT code:%d label:%d opcode %d ctype %d",
- __func__, p_data->meta_msg.code, p_data->meta_msg.label,
- p_data->meta_msg.p_msg->hdr.opcode,
- p_data->meta_msg.p_msg->hdr.ctype);
- LOG_VERBOSE("%s company_id:0x%x len:%d handle:%d", __func__,
- p_data->meta_msg.company_id, p_data->meta_msg.len,
- p_data->meta_msg.rc_handle);
+ log::verbose("BTA_AV_META_MSG_EVT code:{} label:{} opcode {} ctype {}",
+ p_data->meta_msg.code, p_data->meta_msg.label,
+ p_data->meta_msg.p_msg->hdr.opcode,
+ p_data->meta_msg.p_msg->hdr.ctype);
+ log::verbose("company_id:0x{:x} len:{} handle:{}",
+ p_data->meta_msg.company_id, p_data->meta_msg.len,
+ p_data->meta_msg.rc_handle);
switch (p_data->meta_msg.p_msg->hdr.opcode) {
case AVRC_OP_VENDOR:
if ((p_data->meta_msg.code >= AVRC_RSP_NOT_IMPL) &&
@@ -1335,12 +1330,12 @@ void btif_rc_handler(tBTA_AV_EVT event, tBTA_AV* p_data) {
break;
}
} else {
- LOG_ERROR("Neither CTRL, nor TG is up, drop meta commands");
+ log::error("Neither CTRL, nor TG is up, drop meta commands");
}
} break;
default:
- LOG_VERBOSE("%s: Unhandled RC event : 0x%x", __func__, event);
+ log::verbose("Unhandled RC event : 0x{:x}", event);
}
}
@@ -1367,7 +1362,7 @@ uint8_t btif_rc_get_connected_peer_handle(const RawAddress& peer_addr) {
p_dev = btif_rc_get_device_by_bda(peer_addr);
if (p_dev == NULL) {
- LOG_ERROR("%s: p_dev NULL", __func__);
+ log::error("p_dev NULL");
return BTRC_HANDLE_NONE;
}
return p_dev->rc_handle;
@@ -1389,15 +1384,15 @@ void btif_rc_check_handle_pending_play(const RawAddress& peer_addr,
p_dev = btif_rc_get_device_by_bda(peer_addr);
if (p_dev == NULL) {
- LOG_ERROR("%s: p_dev NULL", __func__);
+ log::error("p_dev NULL");
return;
}
- LOG_VERBOSE("%s: bSendToApp: %d", __func__, bSendToApp);
+ log::verbose("bSendToApp: {}", bSendToApp);
if (p_dev->rc_pending_play) {
if (bSendToApp) {
tBTA_AV_REMOTE_CMD remote_cmd;
- LOG_VERBOSE("%s: Sending queued PLAYED event to app", __func__);
+ log::verbose("Sending queued PLAYED event to app");
memset(&remote_cmd, 0, sizeof(tBTA_AV_REMOTE_CMD));
remote_cmd.rc_handle = p_dev->rc_handle;
@@ -1438,13 +1433,13 @@ static void send_reject_response(uint8_t rc_handle, uint8_t label, uint8_t pdu,
status = AVRC_BldResponse(rc_handle, &avrc_rsp, &p_msg);
if (status != AVRC_STS_NO_ERROR) {
- LOG_ERROR("%s: status not AVRC_STS_NO_ERROR", __func__);
+ log::error("status not AVRC_STS_NO_ERROR");
return;
}
- LOG_VERBOSE(
- "%s: Sending error notification to handle: %d. pdu: %s,status: 0x%02x",
- __func__, rc_handle, dump_rc_pdu(pdu), status);
+ log::verbose(
+ "Sending error notification to handle: {}. pdu: {},status: 0x{:02x}",
+ rc_handle, dump_rc_pdu(pdu), status);
BTA_AvMetaRsp(rc_handle, label, ctype, p_msg);
}
@@ -1491,21 +1486,21 @@ static void send_metamsg_rsp(btif_rc_device_cb_t* p_dev, int index,
uint8_t ctype;
if (p_dev == NULL) {
- LOG_ERROR("%s: p_dev NULL", __func__);
+ log::error("p_dev NULL");
return;
}
if (pmetamsg_resp == NULL) {
- LOG_WARN("%s: Invalid response received from application", __func__);
+ log::warn("Invalid response received from application");
return;
}
- LOG_VERBOSE("%s: rc_handle: %d, index: %d, label: %d, code: 0x%02x, pdu: %s",
- __func__, p_dev->rc_handle, index, label, code,
- dump_rc_pdu(pmetamsg_resp->rsp.pdu));
+ log::verbose("rc_handle: {}, index: {}, label: {}, code: 0x{:02x}, pdu: {}",
+ p_dev->rc_handle, index, label, code,
+ dump_rc_pdu(pmetamsg_resp->rsp.pdu));
if (index >= 0 && !p_dev->rc_pdu_info[index].is_rsp_pending) {
- LOG_ERROR("%s: is_rsp_pending false, returning", __func__);
+ log::error("is_rsp_pending false, returning");
return;
}
@@ -1522,23 +1517,21 @@ static void send_metamsg_rsp(btif_rc_device_cb_t* p_dev, int index,
/* de-register this notification for a CHANGED response */
p_dev->rc_notif[event_id - 1].bNotify = false;
- LOG_VERBOSE("%s: rc_handle: %d. event_id: 0x%02d bNotify: %u", __func__,
- p_dev->rc_handle, event_id, bNotify);
+ log::verbose("rc_handle: {}. event_id: 0x{:02} bNotify: {}",
+ p_dev->rc_handle, event_id, bNotify);
if (bNotify) {
BT_HDR* p_msg = NULL;
tAVRC_STS status;
if (AVRC_STS_NO_ERROR == (status = AVRC_BldResponse(
p_dev->rc_handle, pmetamsg_resp, &p_msg))) {
- LOG_VERBOSE(
- "%s: Sending notification to rc_handle: %d. event_id: 0x%02d",
- __func__, p_dev->rc_handle, event_id);
+ log::verbose("Sending notification to rc_handle: {}. event_id: 0x{:02}",
+ p_dev->rc_handle, event_id);
bSent = true;
BTA_AvMetaRsp(p_dev->rc_handle, p_dev->rc_notif[event_id - 1].label,
ctype, p_msg);
} else {
- LOG_WARN("%s: failed to build metamsg response. status: 0x%02x",
- __func__, status);
+ log::warn("failed to build metamsg response. status: 0x{:02x}", status);
}
}
@@ -1559,8 +1552,7 @@ static void send_metamsg_rsp(btif_rc_device_cb_t* p_dev, int index,
if (status == AVRC_STS_NO_ERROR) {
BTA_AvMetaRsp(p_dev->rc_handle, label, ctype, p_msg);
} else {
- LOG_ERROR("%s: failed to build metamsg response. status: 0x%02x",
- __func__, status);
+ log::error("failed to build metamsg response. status: 0x{:02x}", status);
}
}
@@ -1669,9 +1661,9 @@ static uint8_t fill_attribute_id_array(
static void btif_rc_upstreams_evt(uint16_t event, tAVRC_COMMAND* pavrc_cmd,
uint8_t ctype, uint8_t label,
btif_rc_device_cb_t* p_dev) {
- LOG_VERBOSE("%s: pdu: %s handle: 0x%x ctype: %x label: %x event ID: %x",
- __func__, dump_rc_pdu(pavrc_cmd->pdu), p_dev->rc_handle, ctype,
- label, pavrc_cmd->reg_notif.event_id);
+ log::verbose("pdu: {} handle: 0x{:x} ctype: {:x} label: {:x} event ID: {:x}",
+ dump_rc_pdu(pavrc_cmd->pdu), p_dev->rc_handle, ctype, label,
+ pavrc_cmd->reg_notif.event_id);
switch (event) {
case AVRC_PDU_GET_PLAY_STATUS: {
@@ -1694,8 +1686,7 @@ static void btif_rc_upstreams_evt(uint16_t event, tAVRC_COMMAND* pavrc_cmd,
pavrc_cmd->get_elem_attrs.num_attr, pavrc_cmd->get_elem_attrs.attrs,
BTRC_MAX_ELEM_ATTR_SIZE, element_attrs);
if (num_attr == 0) {
- LOG_ERROR("%s: No valid attributes requested in GET_ELEMENT_ATTRIBUTES",
- __func__);
+ log::error("No valid attributes requested in GET_ELEMENT_ATTRIBUTES");
send_reject_response(p_dev->rc_handle, label, pavrc_cmd->pdu,
AVRC_STS_BAD_PARAM, pavrc_cmd->cmd.opcode);
return;
@@ -1707,9 +1698,7 @@ static void btif_rc_upstreams_evt(uint16_t event, tAVRC_COMMAND* pavrc_cmd,
case AVRC_PDU_REGISTER_NOTIFICATION: {
if (pavrc_cmd->reg_notif.event_id == BTRC_EVT_PLAY_POS_CHANGED &&
pavrc_cmd->reg_notif.param == 0) {
- LOG_WARN(
- "%s: Device registering position changed with illegal param 0.",
- __func__);
+ log::warn("Device registering position changed with illegal param 0.");
send_reject_response(p_dev->rc_handle, label, pavrc_cmd->pdu,
AVRC_STS_BAD_PARAM, pavrc_cmd->cmd.opcode);
/* de-register this notification for a rejected response */
@@ -1722,7 +1711,7 @@ static void btif_rc_upstreams_evt(uint16_t event, tAVRC_COMMAND* pavrc_cmd,
} break;
case AVRC_PDU_INFORM_DISPLAY_CHARSET: {
tAVRC_RESPONSE avrc_rsp;
- LOG_VERBOSE("%s: AVRC_PDU_INFORM_DISPLAY_CHARSET", __func__);
+ log::verbose("AVRC_PDU_INFORM_DISPLAY_CHARSET");
if (p_dev->rc_connected) {
memset(&(avrc_rsp.inform_charset), 0, sizeof(tAVRC_RSP));
avrc_rsp.inform_charset.opcode =
@@ -1782,8 +1771,8 @@ static void btif_rc_upstreams_evt(uint16_t event, tAVRC_COMMAND* pavrc_cmd,
} break;
case AVRC_PDU_REQUEST_CONTINUATION_RSP: {
- LOG_VERBOSE("%s() REQUEST CONTINUATION: target_pdu: 0x%02d", __func__,
- pavrc_cmd->continu.target_pdu);
+ log::verbose("REQUEST CONTINUATION: target_pdu: 0x{:02d}",
+ pavrc_cmd->continu.target_pdu);
tAVRC_RESPONSE avrc_rsp;
if (p_dev->rc_connected == TRUE) {
memset(&(avrc_rsp.continu), 0, sizeof(tAVRC_NEXT_RSP));
@@ -1797,8 +1786,8 @@ static void btif_rc_upstreams_evt(uint16_t event, tAVRC_COMMAND* pavrc_cmd,
} break;
case AVRC_PDU_ABORT_CONTINUATION_RSP: {
- LOG_VERBOSE("%s() ABORT CONTINUATION: target_pdu: 0x%02d", __func__,
- pavrc_cmd->abort.target_pdu);
+ log::verbose("ABORT CONTINUATION: target_pdu: 0x{:02d}",
+ pavrc_cmd->abort.target_pdu);
tAVRC_RESPONSE avrc_rsp;
if (p_dev->rc_connected == TRUE) {
memset(&(avrc_rsp.abort), 0, sizeof(tAVRC_NEXT_RSP));
@@ -1830,14 +1819,13 @@ static void btif_rc_upstreams_evt(uint16_t event, tAVRC_COMMAND* pavrc_cmd,
pavrc_cmd->get_attrs.attr_count, pavrc_cmd->get_attrs.p_attr_list,
BTRC_MAX_ELEM_ATTR_SIZE, item_attrs);
if (num_attr == 0) {
- LOG_ERROR("%s: No valid attributes requested in GET_ITEM_ATTRIBUTES",
- __func__);
+ log::error("No valid attributes requested in GET_ITEM_ATTRIBUTES");
send_reject_response(p_dev->rc_handle, label, pavrc_cmd->pdu,
AVRC_STS_BAD_PARAM, pavrc_cmd->cmd.opcode);
return;
}
fill_pdu_queue(IDX_GET_ITEM_ATTR_RSP, ctype, label, true, p_dev);
- LOG_VERBOSE("%s: GET_ITEM_ATTRIBUTES: num_attr: %d", __func__, num_attr);
+ log::verbose("GET_ITEM_ATTRIBUTES: num_attr: {}", num_attr);
HAL_CBACK(bt_rc_callbacks, get_item_attr_cb, pavrc_cmd->get_attrs.scope,
pavrc_cmd->get_attrs.uid, pavrc_cmd->get_attrs.uid_counter,
num_attr, item_attrs, p_dev->rc_addr);
@@ -1884,8 +1872,8 @@ static void btif_rc_ctrl_upstreams_rsp_cmd(uint8_t event,
tAVRC_COMMAND* pavrc_cmd,
uint8_t label,
btif_rc_device_cb_t* p_dev) {
- LOG_VERBOSE("%s: pdu: %s: handle: 0x%x", __func__,
- dump_rc_pdu(pavrc_cmd->pdu), p_dev->rc_handle);
+ log::verbose("pdu: {}: handle: 0x{:x}", dump_rc_pdu(pavrc_cmd->pdu),
+ p_dev->rc_handle);
switch (event) {
case AVRC_PDU_SET_ABSOLUTE_VOLUME:
do_in_jni_thread(
@@ -1917,8 +1905,8 @@ static void btif_rc_upstreams_rsp_evt(uint16_t event,
tAVRC_RESPONSE* pavrc_resp, uint8_t ctype,
uint8_t label,
btif_rc_device_cb_t* p_dev) {
- LOG_VERBOSE("%s: pdu: %s: handle: 0x%x ctype: %x label: %x", __func__,
- dump_rc_pdu(pavrc_resp->pdu), p_dev->rc_handle, ctype, label);
+ log::verbose("pdu: {}: handle: 0x{:x} ctype: {:x} label: {:x}",
+ dump_rc_pdu(pavrc_resp->pdu), p_dev->rc_handle, ctype, label);
switch (event) {
case AVRC_PDU_REGISTER_NOTIFICATION: {
@@ -1929,10 +1917,9 @@ static void btif_rc_upstreams_rsp_evt(uint16_t event,
} break;
case AVRC_PDU_SET_ABSOLUTE_VOLUME: {
- LOG_VERBOSE(
- "%s: Set absolute volume change event received: volume: %d, ctype: "
- "%d",
- __func__, pavrc_resp->volume.volume, ctype);
+ log::verbose(
+ "Set absolute volume change event received: volume: {}, ctype: {}",
+ pavrc_resp->volume.volume, ctype);
if (AVRC_RSP_ACCEPT == ctype)
p_dev->rc_volume = pavrc_resp->volume.volume;
HAL_CBACK(bt_rc_callbacks, volume_change_cb, pavrc_resp->volume.volume,
@@ -1958,7 +1945,7 @@ static void btif_rc_upstreams_rsp_evt(uint16_t event,
*
******************************************************************************/
static bt_status_t init(btrc_callbacks_t* callbacks) {
- LOG_VERBOSE("%s: ", __func__);
+ log::verbose("");
bt_status_t result = BT_STATUS_SUCCESS;
if (bt_rc_callbacks) return BT_STATUS_DONE;
@@ -1983,7 +1970,7 @@ static bt_status_t init(btrc_callbacks_t* callbacks) {
*
******************************************************************************/
static bt_status_t init_ctrl(btrc_ctrl_callbacks_t* callbacks) {
- LOG_VERBOSE("%s: ", __func__);
+ log::verbose("");
bt_status_t result = BT_STATUS_SUCCESS;
if (bt_rc_ctrl_callbacks) return BT_STATUS_DONE;
@@ -2000,7 +1987,7 @@ static bt_status_t init_ctrl(btrc_ctrl_callbacks_t* callbacks) {
static void rc_ctrl_procedure_complete(btif_rc_device_cb_t* p_dev) {
if (p_dev == NULL) {
- LOG_ERROR("%s: p_dev NULL", __func__);
+ log::error("p_dev NULL");
return;
}
@@ -2030,7 +2017,7 @@ static bt_status_t get_play_status_rsp(const RawAddress& bd_addr,
tAVRC_RESPONSE avrc_rsp;
btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr);
- LOG_VERBOSE("%s: song len %d song pos %d", __func__, song_len, song_pos);
+ log::verbose("song len {} song pos {}", song_len, song_pos);
CHECK_RC_CONNECTED(p_dev);
memset(&(avrc_rsp.get_play_status), 0, sizeof(tAVRC_GET_PLAY_STATUS_RSP));
@@ -2072,13 +2059,12 @@ static bt_status_t get_element_attr_rsp(const RawAddress& bd_addr,
tAVRC_ATTR_ENTRY element_attrs[BTRC_MAX_ELEM_ATTR_SIZE];
btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr);
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
CHECK_RC_CONNECTED(p_dev);
if (num_attr > BTRC_MAX_ELEM_ATTR_SIZE) {
- LOG(WARNING) << __func__
- << " Exceeded number attributes:" << static_cast<int>(num_attr)
- << " max:" << BTRC_MAX_ELEM_ATTR_SIZE;
+ log::warn("Exceeded number attributes:{} max:{}",
+ static_cast<int>(num_attr), BTRC_MAX_ELEM_ATTR_SIZE);
num_attr = BTRC_MAX_ELEM_ATTR_SIZE;
}
memset(element_attrs, 0, sizeof(tAVRC_ATTR_ENTRY) * num_attr);
@@ -2092,10 +2078,11 @@ static bt_status_t get_element_attr_rsp(const RawAddress& bd_addr,
element_attrs[i].name.str_len =
(uint16_t)strnlen((char*)p_attrs[i].text, BTRC_MAX_ATTR_STR_LEN);
element_attrs[i].name.p_str = p_attrs[i].text;
- LOG_VERBOSE("%s: attr_id: 0x%x, charset_id: 0x%x, str_len: %d, str: %s",
- __func__, (unsigned int)element_attrs[i].attr_id,
- element_attrs[i].name.charset_id,
- element_attrs[i].name.str_len, element_attrs[i].name.p_str);
+ log::verbose("attr_id: 0x{:x}, charset_id: 0x{:x}, str_len: {}, str: {}",
+ (unsigned int)element_attrs[i].attr_id,
+ element_attrs[i].name.charset_id,
+ element_attrs[i].name.str_len,
+ reinterpret_cast<char const*>(element_attrs[i].name.p_str));
}
avrc_rsp.get_play_status.status = AVRC_STS_NO_ERROR;
}
@@ -2126,12 +2113,11 @@ static bt_status_t register_notification_rsp(
btrc_event_id_t event_id, btrc_notification_type_t type,
btrc_register_notification_t* p_param) {
tAVRC_RESPONSE avrc_rsp;
- LOG_VERBOSE("%s: event_id: %s", __func__,
- dump_rc_notification_event_id(event_id));
+ log::verbose("event_id: {}", dump_rc_notification_event_id(event_id));
std::unique_lock<std::mutex> lock(btif_rc_cb.lock);
if (event_id > MAX_RC_NOTIFICATIONS) {
- LOG_ERROR("Invalid event id");
+ log::error("Invalid event id");
return BT_STATUS_PARM_INVALID;
}
@@ -2146,26 +2132,26 @@ static bt_status_t register_notification_rsp(
memset(&(avrc_rsp.reg_notif.param), 0, sizeof(tAVRC_NOTIF_RSP_PARAM));
if (!(btif_rc_cb.rc_multi_cb[idx].rc_connected)) {
- LOG_ERROR("%s: Avrcp device is not connected, handle: 0x%x", __func__,
- btif_rc_cb.rc_multi_cb[idx].rc_handle);
+ log::error("Avrcp device is not connected, handle: 0x{:x}",
+ btif_rc_cb.rc_multi_cb[idx].rc_handle);
continue;
}
if (!btif_rc_cb.rc_multi_cb[idx].rc_notif[event_id - 1].bNotify) {
- LOG_WARN(
- "%s: Avrcp Event id is not registered: event_id: %x, handle: 0x%x",
- __func__, event_id, btif_rc_cb.rc_multi_cb[idx].rc_handle);
+ log::warn(
+ "Avrcp Event id is not registered: event_id: {:x}, handle: 0x{:x}",
+ event_id, btif_rc_cb.rc_multi_cb[idx].rc_handle);
continue;
}
- LOG_VERBOSE("%s: Avrcp Event id is registered: event_id: %x handle: 0x%x",
- __func__, event_id, btif_rc_cb.rc_multi_cb[idx].rc_handle);
+ log::verbose("Avrcp Event id is registered: event_id: {:x} handle: 0x{:x}",
+ event_id, btif_rc_cb.rc_multi_cb[idx].rc_handle);
switch (event_id) {
case BTRC_EVT_PLAY_STATUS_CHANGED:
avrc_rsp.reg_notif.param.play_status = p_param->play_status;
if (avrc_rsp.reg_notif.param.play_status == PLAY_STATUS_PLAYING)
- btif_av_clear_remote_suspend_flag();
+ btif_av_clear_remote_suspend_flag(A2dpType::kSink);
break;
case BTRC_EVT_TRACK_CHANGE:
memcpy(&(avrc_rsp.reg_notif.param.track), &(p_param->track),
@@ -2190,7 +2176,7 @@ static bt_status_t register_notification_rsp(
break;
default:
- LOG_WARN("%s: Unhandled event ID: 0x%x", __func__, event_id);
+ log::warn("Unhandled event ID: 0x{:x}", event_id);
return BT_STATUS_UNHANDLED;
}
@@ -2234,13 +2220,12 @@ static bt_status_t get_folder_items_list_rsp(const RawAddress& bd_addr,
btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr);
btrc_folder_items_t* cur_item = NULL;
- LOG_VERBOSE("%s: uid_counter %d num_items %d", __func__, uid_counter,
- num_items);
+ log::verbose("uid_counter {} num_items {}", uid_counter, num_items);
CHECK_RC_CONNECTED(p_dev);
/* check if rsp to previous cmd was completed */
if (!p_dev->rc_pdu_info[IDX_GET_FOLDER_ITEMS_RSP].is_rsp_pending) {
- LOG_WARN("%s: Not sending response as no PDU was registered", __func__);
+ log::warn("Not sending response as no PDU was registered");
return BT_STATUS_UNHANDLED;
}
@@ -2252,9 +2237,9 @@ static bt_status_t get_folder_items_list_rsp(const RawAddress& bd_addr,
avrc_rsp.get_items.status = status_code_map[rsp_status];
if (avrc_rsp.get_items.status != AVRC_STS_NO_ERROR) {
- LOG_WARN(
- "%s: Error in parsing the received getfolderitems cmd. status: 0x%02x",
- __func__, avrc_rsp.get_items.status);
+ log::warn(
+ "Error in parsing the received getfolderitems cmd. status: 0x{:02x}",
+ avrc_rsp.get_items.status);
status = avrc_rsp.get_items.status;
} else {
avrc_rsp.get_items.uid_counter = uid_counter;
@@ -2313,8 +2298,8 @@ static bt_status_t get_folder_items_list_rsp(const RawAddress& bd_addr,
} break;
default: {
- LOG_ERROR("%s: Unknown item_type: %d. Internal Error", __func__,
- p_items->item_type);
+ log::error("Unknown item_type: {}. Internal Error",
+ p_items->item_type);
status = AVRC_STS_INTERNAL_ERR;
} break;
}
@@ -2330,10 +2315,10 @@ static bt_status_t get_folder_items_list_rsp(const RawAddress& bd_addr,
}
int len_before = p_msg ? p_msg->len : 0;
- LOG_VERBOSE("%s: item_cnt: %d len: %d", __func__, item_cnt, len_before);
+ log::verbose("item_cnt: {} len: {}", item_cnt, len_before);
status = AVRC_BldResponse(p_dev->rc_handle, &avrc_rsp, &p_msg);
- LOG_VERBOSE("%s: Build rsp status: %d len: %d", __func__, status,
- (p_msg ? p_msg->len : 0));
+ log::verbose("Build rsp status: {} len: {}", status,
+ (p_msg ? p_msg->len : 0));
int len_after = p_msg ? p_msg->len : 0;
if (status != AVRC_STS_NO_ERROR || len_before == len_after) {
/* Error occured in build response or we ran out of buffer so break the
@@ -2355,8 +2340,8 @@ static bt_status_t get_folder_items_list_rsp(const RawAddress& bd_addr,
p_msg);
} else /* Error occured, send reject response */
{
- LOG_ERROR("%s: Error status: 0x%02X. Sending reject rsp", __func__,
- avrc_rsp.rsp.status);
+ log::error("Error status: 0x{:02X}. Sending reject rsp",
+ avrc_rsp.rsp.status);
send_reject_response(
p_dev->rc_handle, p_dev->rc_pdu_info[IDX_GET_FOLDER_ITEMS_RSP].label,
avrc_rsp.pdu, avrc_rsp.get_items.status, avrc_rsp.get_items.opcode);
@@ -2387,7 +2372,7 @@ static bt_status_t set_addressed_player_rsp(const RawAddress& bd_addr,
tAVRC_RESPONSE avrc_rsp;
btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr);
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
CHECK_RC_CONNECTED(p_dev);
avrc_rsp.addr_player.pdu = AVRC_PDU_SET_ADDRESSED_PLAYER;
@@ -2444,12 +2429,12 @@ static bt_status_t set_browsed_player_rsp(const RawAddress& bd_addr,
avrc_rsp.br_player.pdu = AVRC_PDU_SET_BROWSED_PLAYER;
avrc_rsp.br_player.opcode = opcode_from_pdu(AVRC_PDU_SET_BROWSED_PLAYER);
- LOG_VERBOSE("%s: rsp_status: 0x%02X avrc_rsp.br_player.status: 0x%02X",
- __func__, rsp_status, avrc_rsp.br_player.status);
+ log::verbose("rsp_status: 0x{:02X} avrc_rsp.br_player.status: 0x{:02X}",
+ rsp_status, avrc_rsp.br_player.status);
/* check if rsp to previous cmd was completed */
if (!p_dev->rc_pdu_info[IDX_SET_BROWSED_PLAYER_RSP].is_rsp_pending) {
- LOG_WARN("%s: Not sending response as no PDU was registered", __func__);
+ log::warn("Not sending response as no PDU was registered");
return BT_STATUS_UNHANDLED;
}
@@ -2459,15 +2444,15 @@ static bt_status_t set_browsed_player_rsp(const RawAddress& bd_addr,
avrc_rsp.br_player.folder_depth = folder_depth;
avrc_rsp.br_player.p_folders = (tAVRC_NAME*)p_folders;
- LOG_VERBOSE("%s: folder_depth: 0x%02X num_items: %d", __func__,
- folder_depth, num_items);
+ log::verbose("folder_depth: 0x{:02X} num_items: {}", folder_depth,
+ num_items);
if (folder_depth > 0) {
/* Iteratively build response for all folders across folder depth upto
* current path */
avrc_rsp.br_player.folder_depth = 1;
for (item_cnt = 0; item_cnt < folder_depth; item_cnt++) {
- LOG_VERBOSE("%s: iteration: %d", __func__, item_cnt);
+ log::verbose("iteration: {}", item_cnt);
item.str_len = p_folders[item_cnt].str_len;
item.p_str = p_folders[item_cnt].p_str;
avrc_rsp.br_player.p_folders = &item;
@@ -2475,7 +2460,7 @@ static bt_status_t set_browsed_player_rsp(const RawAddress& bd_addr,
/* Add current item to buffer and build response */
status = AVRC_BldResponse(p_dev->rc_handle, &avrc_rsp, &p_msg);
if (AVRC_STS_NO_ERROR != status) {
- LOG_WARN("%s: Build rsp status: %d", __func__, status);
+ log::warn("Build rsp status: {}", status);
/* if the build fails, it is likely that we ran out of buffer. so if
* we have
* some items to send, reset this error to no error for sending what we
@@ -2495,9 +2480,9 @@ static bt_status_t set_browsed_player_rsp(const RawAddress& bd_addr,
avrc_rsp.br_player.status = status;
} else /* error received from above layer */
{
- LOG_WARN(
- "%s: Error in parsing the received setbrowsed command. status: 0x%02x",
- __func__, avrc_rsp.br_player.status);
+ log::warn(
+ "Error in parsing the received setbrowsed command. status: 0x{:02x}",
+ avrc_rsp.br_player.status);
status = avrc_rsp.br_player.status;
}
@@ -2510,8 +2495,8 @@ static bt_status_t set_browsed_player_rsp(const RawAddress& bd_addr,
p_msg);
} else /* Error occured, send reject response */
{
- LOG_ERROR("%s: Error status: 0x%02X. Sending reject rsp", __func__,
- avrc_rsp.br_player.status);
+ log::error("Error status: 0x{:02X}. Sending reject rsp",
+ avrc_rsp.br_player.status);
send_reject_response(
p_dev->rc_handle, p_dev->rc_pdu_info[IDX_SET_BROWSED_PLAYER_RSP].label,
avrc_rsp.pdu, avrc_rsp.br_player.status, avrc_rsp.get_items.opcode);
@@ -2543,7 +2528,7 @@ static bt_status_t change_path_rsp(const RawAddress& bd_addr,
tAVRC_RESPONSE avrc_rsp;
btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr);
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
CHECK_RC_CONNECTED(p_dev);
avrc_rsp.chg_path.pdu = AVRC_PDU_CHANGE_PATH;
@@ -2576,7 +2561,7 @@ static bt_status_t search_rsp(const RawAddress& bd_addr,
tAVRC_RESPONSE avrc_rsp;
btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr);
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
CHECK_RC_CONNECTED(p_dev);
avrc_rsp.search.pdu = AVRC_PDU_SEARCH;
@@ -2611,7 +2596,7 @@ static bt_status_t get_item_attr_rsp(const RawAddress& bd_addr,
tAVRC_ATTR_ENTRY item_attrs[BTRC_MAX_ELEM_ATTR_SIZE];
btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr);
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
CHECK_RC_CONNECTED(p_dev);
memset(item_attrs, 0, sizeof(tAVRC_ATTR_ENTRY) * num_attr);
@@ -2651,7 +2636,7 @@ static bt_status_t add_to_now_playing_rsp(const RawAddress& bd_addr,
tAVRC_RESPONSE avrc_rsp;
btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr);
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
CHECK_RC_CONNECTED(p_dev);
avrc_rsp.add_to_play.pdu = AVRC_PDU_ADD_TO_NOW_PLAYING;
@@ -2683,7 +2668,7 @@ static bt_status_t play_item_rsp(const RawAddress& bd_addr,
tAVRC_RESPONSE avrc_rsp;
btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr);
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
CHECK_RC_CONNECTED(p_dev);
avrc_rsp.play_item.pdu = AVRC_PDU_PLAY_ITEM;
@@ -2717,7 +2702,7 @@ static bt_status_t get_total_num_of_items_rsp(const RawAddress& bd_addr,
tAVRC_RESPONSE avrc_rsp;
btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr);
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
CHECK_RC_CONNECTED(p_dev);
avrc_rsp.get_num_of_items.pdu = AVRC_PDU_GET_TOTAL_NUM_OF_ITEMS;
@@ -2751,7 +2736,7 @@ static bt_status_t get_total_num_of_items_rsp(const RawAddress& bd_addr,
*
**************************************************************************/
static bt_status_t set_volume(uint8_t volume) {
- LOG_VERBOSE("%s: volume: %d", __func__, volume);
+ log::verbose("volume: {}", volume);
tAVRC_STS status = BT_STATUS_UNSUPPORTED;
for (int idx = 0; idx < BTIF_RC_NUM_CONN; idx++) {
@@ -2760,8 +2745,7 @@ static bt_status_t set_volume(uint8_t volume) {
if (p_dev->rc_volume == volume) {
status = BT_STATUS_DONE;
- LOG_ERROR("%s: volume value already set earlier: 0x%02x", __func__,
- volume);
+ log::error("volume value already set earlier: 0x{:02x}", volume);
continue;
}
@@ -2779,8 +2763,7 @@ static bt_status_t set_volume(uint8_t volume) {
if (!(p_dev->rc_features & BTA_AV_FEAT_ADV_CTRL))
continue;
- LOG_VERBOSE("%s: Peer supports absolute volume. newVolume: %d", __func__,
- volume);
+ log::verbose("Peer supports absolute volume. newVolume: {}", volume);
tAVRC_COMMAND avrc_cmd = {.volume = {.pdu = AVRC_PDU_SET_ABSOLUTE_VOLUME,
.status = AVRC_STS_NO_ERROR,
@@ -2789,8 +2772,8 @@ static bt_status_t set_volume(uint8_t volume) {
BT_HDR* p_msg = NULL;
if (AVRC_BldCommand(&avrc_cmd, &p_msg) != AVRC_STS_NO_ERROR) {
- LOG_ERROR("%s: failed to build absolute volume command. status: 0x%02x",
- __func__, status);
+ log::error("failed to build absolute volume command. status: 0x{:02x}",
+ status);
status = BT_STATUS_FAIL;
continue;
}
@@ -2806,14 +2789,13 @@ static bt_status_t set_volume(uint8_t volume) {
if (tran_status != BT_STATUS_SUCCESS || !p_transaction) {
osi_free_and_reset((void**)&p_msg);
- LOG_ERROR("%s: failed to get label, pdu_id=%s, status=0x%02x", __func__,
- dump_rc_pdu(avrc_cmd.pdu), tran_status);
+ log::error("failed to get label, pdu_id={}, status=0x{:02x}",
+ dump_rc_pdu(avrc_cmd.pdu), tran_status);
status = BT_STATUS_FAIL;
continue;
}
- LOG_VERBOSE("%s: msgreq being sent out with label: %d", __func__,
- p_transaction->label);
+ log::verbose("msgreq being sent out with label: {}", p_transaction->label);
BTA_AvMetaCmd(p_dev->rc_handle, p_transaction->label, AVRC_CMD_CTRL, p_msg);
status = BT_STATUS_SUCCESS;
start_transaction_timer(p_dev, p_transaction->label, BTIF_RC_TIMEOUT_MS);
@@ -2833,7 +2815,7 @@ static bt_status_t set_volume(uint8_t volume) {
static void register_volumechange(btif_rc_device_cb_t* p_dev) {
if (p_dev == nullptr) {
- LOG_ERROR("%s: device was null", __func__);
+ log::error("device was null");
return;
}
@@ -2854,8 +2836,7 @@ static void register_volumechange(btif_rc_device_cb_t* p_dev) {
} else {
p_transaction = get_transaction_by_lbl(p_dev, p_dev->rc_vol_label);
if (NULL != p_transaction) {
- LOG_VERBOSE("%s: already in progress for label: %d", __func__,
- p_dev->rc_vol_label);
+ log::verbose("already in progress for label: {}", p_dev->rc_vol_label);
return;
}
status = get_transaction(p_dev, context, &p_transaction);
@@ -2864,11 +2845,11 @@ static void register_volumechange(btif_rc_device_cb_t* p_dev) {
if (BT_STATUS_SUCCESS == status && NULL != p_transaction) {
p_dev->rc_vol_label = p_transaction->label;
} else {
- LOG_ERROR("%s: failed to get a transaction label", __func__);
+ log::error("failed to get a transaction label");
return;
}
- LOG_VERBOSE("%s: label: %d", __func__, p_dev->rc_vol_label);
+ log::verbose("label: {}", p_dev->rc_vol_label);
avrc_cmd.cmd.opcode = 0x00;
avrc_cmd.pdu = AVRC_PDU_REGISTER_NOTIFICATION;
@@ -2880,9 +2861,9 @@ static void register_volumechange(btif_rc_device_cb_t* p_dev) {
if (AVRC_STS_NO_ERROR == BldResp && p_msg) {
BTA_AvMetaCmd(p_dev->rc_handle, p_transaction->label, AVRC_CMD_NOTIF,
p_msg);
- LOG_VERBOSE("%s: BTA_AvMetaCmd called", __func__);
+ log::verbose("BTA_AvMetaCmd called");
} else {
- LOG_ERROR("%s: failed to build command: %d", __func__, BldResp);
+ log::error("failed to build command: {}", BldResp);
}
}
@@ -2901,7 +2882,7 @@ static void handle_rc_metamsg_rsp(tBTA_AV_META_MSG* pmeta_msg,
uint8_t scratch_buf[512] = {0};
tAVRC_STS status = BT_STATUS_UNSUPPORTED;
- LOG_VERBOSE("%s: ", __func__);
+ log::verbose("");
if (AVRC_OP_VENDOR == pmeta_msg->p_msg->hdr.opcode &&
(AVRC_RSP_CHANGED == pmeta_msg->code ||
@@ -2910,9 +2891,9 @@ static void handle_rc_metamsg_rsp(tBTA_AV_META_MSG* pmeta_msg,
AVRC_RSP_NOT_IMPL == pmeta_msg->code)) {
status = AVRC_ParsResponse(pmeta_msg->p_msg, &avrc_response, scratch_buf,
sizeof(scratch_buf));
- LOG_VERBOSE(
- "%s: code:%d, event ID: %d, PDU: %x, parsing status: %d, label: %d",
- __func__, pmeta_msg->code, avrc_response.reg_notif.event_id,
+ log::verbose(
+ "code:{}, event ID: {}, PDU: {:x}, parsing status: {}, label: {}",
+ pmeta_msg->code, avrc_response.reg_notif.event_id,
avrc_response.reg_notif.pdu, status, pmeta_msg->label);
if (status != AVRC_STS_NO_ERROR) {
@@ -2932,9 +2913,9 @@ static void handle_rc_metamsg_rsp(tBTA_AV_META_MSG* pmeta_msg,
p_dev->rc_vol_label != pmeta_msg->label) {
// Just discard the message, if the device sends back with an incorrect
// label
- LOG_VERBOSE(
- "%s: Discarding register notification in rsp.code: %d and label: %d",
- __func__, pmeta_msg->code, pmeta_msg->label);
+ log::verbose(
+ "Discarding register notification in rsp.code: {} and label: {}",
+ pmeta_msg->code, pmeta_msg->label);
return;
}
@@ -2942,16 +2923,16 @@ static void handle_rc_metamsg_rsp(tBTA_AV_META_MSG* pmeta_msg,
AVRC_EVT_VOLUME_CHANGE == avrc_response.reg_notif.event_id &&
(AVRC_RSP_REJ == pmeta_msg->code ||
AVRC_RSP_NOT_IMPL == pmeta_msg->code)) {
- LOG_VERBOSE("%s remove AbsoluteVolume feature flag.", __func__);
+ log::verbose("remove AbsoluteVolume feature flag.");
p_dev->rc_features &= ~BTA_AV_FEAT_ADV_CTRL;
handle_rc_features(p_dev);
return;
}
} else {
- LOG_VERBOSE(
- "%s: Received vendor dependent in adv ctrl rsp. code: %d len: %d. Not "
+ log::verbose(
+ "Received vendor dependent in adv ctrl rsp. code: {} len: {}. Not "
"processing it.",
- __func__, pmeta_msg->code, pmeta_msg->len);
+ pmeta_msg->code, pmeta_msg->len);
return;
}
@@ -2966,8 +2947,8 @@ static void handle_rc_metamsg_rsp(tBTA_AV_META_MSG* pmeta_msg,
release_transaction(p_dev, pmeta_msg->label);
}
- LOG_VERBOSE("%s: Passing received metamsg response to app. pdu: %s", __func__,
- dump_rc_pdu(avrc_response.pdu));
+ log::verbose("Passing received metamsg response to app. pdu: {}",
+ dump_rc_pdu(avrc_response.pdu));
btif_rc_upstreams_rsp_evt((uint16_t)avrc_response.rsp.pdu, &avrc_response,
pmeta_msg->code, pmeta_msg->label, p_dev);
}
@@ -3008,7 +2989,7 @@ static void rc_notification_interim_timeout(btif_rc_device_cb_t* p_dev,
uint8_t event_id) {
/* Device disconnections clear the event list but can't free the timer */
if (p_dev == NULL || p_dev->rc_supported_event_list == NULL) {
- LOG_WARN("%s: timeout for null device or event list", __func__);
+ log::warn("timeout for null device or event list");
return;
}
@@ -3063,7 +3044,7 @@ static void register_for_event_notification(btif_rc_supported_event_t* p_event,
bt_status_t status =
register_notification_cmd(p_event->event_id, interval_in_seconds, p_dev);
if (status != BT_STATUS_SUCCESS) {
- LOG_ERROR("%s: failed, status=%d", __func__, status);
+ log::error("failed, status={}", status);
return;
}
@@ -3100,8 +3081,8 @@ static bt_status_t build_and_send_vendor_cmd(tAVRC_COMMAND* avrc_cmd,
bt_status_t tran_status = get_transaction(p_dev, context, &p_transaction);
if (BT_STATUS_SUCCESS != tran_status || p_transaction == NULL) {
- LOG_ERROR("%s: failed to get label, pdu_id=%s, status=0x%02x", __func__,
- dump_rc_pdu(avrc_cmd->pdu), tran_status);
+ log::error("failed to get label, pdu_id={}, status=0x{:02x}",
+ dump_rc_pdu(avrc_cmd->pdu), tran_status);
return BT_STATUS_FAIL;
}
@@ -3109,14 +3090,14 @@ static bt_status_t build_and_send_vendor_cmd(tAVRC_COMMAND* avrc_cmd,
tAVRC_STS status = AVRC_BldCommand(avrc_cmd, &p_msg);
if (status == AVRC_STS_NO_ERROR && p_msg != NULL) {
uint8_t* data_start = (uint8_t*)(p_msg + 1) + p_msg->offset;
- LOG_VERBOSE("%s: %s msgreq being sent out with label: %d", __func__,
- dump_rc_pdu(avrc_cmd->pdu), p_transaction->label);
+ log::verbose("{} msgreq being sent out with label: {}",
+ dump_rc_pdu(avrc_cmd->pdu), p_transaction->label);
BTA_AvVendorCmd(p_dev->rc_handle, p_transaction->label, cmd_code,
data_start, p_msg->len);
status = BT_STATUS_SUCCESS;
start_transaction_timer(p_dev, p_transaction->label, BTIF_RC_TIMEOUT_MS);
} else {
- LOG_ERROR("%s: failed to build command. status: 0x%02x", __func__, status);
+ log::error("failed to build command. status: 0x{:02x}", status);
release_transaction(p_dev, p_transaction->label);
}
osi_free(p_msg);
@@ -3146,21 +3127,21 @@ static bt_status_t build_and_send_browsing_cmd(tAVRC_COMMAND* avrc_cmd,
bt_status_t tran_status = get_transaction(p_dev, context, &p_transaction);
if (tran_status != BT_STATUS_SUCCESS || p_transaction == NULL) {
- LOG_ERROR("%s: failed to get label, pdu_id=%s, status=0x%02x", __func__,
- dump_rc_pdu(avrc_cmd->pdu), tran_status);
+ log::error("failed to get label, pdu_id={}, status=0x{:02x}",
+ dump_rc_pdu(avrc_cmd->pdu), tran_status);
return BT_STATUS_FAIL;
}
BT_HDR* p_msg = NULL;
tAVRC_STS status = AVRC_BldCommand(avrc_cmd, &p_msg);
if (status != AVRC_STS_NO_ERROR) {
- LOG_ERROR("%s: failed to build command status %d", __func__, status);
+ log::error("failed to build command status {}", status);
release_transaction(p_dev, p_transaction->label);
return BT_STATUS_FAIL;
}
- LOG_VERBOSE("%s: Send pdu_id=%s, label=%d", __func__,
- dump_rc_pdu(avrc_cmd->pdu), p_transaction->label);
+ log::verbose("Send pdu_id={}, label={}", dump_rc_pdu(avrc_cmd->pdu),
+ p_transaction->label);
BTA_AvMetaCmd(p_dev->rc_handle, p_transaction->label, AVRC_CMD_CTRL, p_msg);
start_transaction_timer(p_dev, p_transaction->label, BTIF_RC_TIMEOUT_MS);
return BT_STATUS_SUCCESS;
@@ -3184,7 +3165,7 @@ static void handle_get_capability_response(tBTA_AV_META_MSG* pmeta_msg,
/* Todo: Do we need to retry on command timeout */
if (p_rsp->status != AVRC_STS_NO_ERROR) {
- LOG_ERROR("%s: Error capability response: 0x%02X", __func__, p_rsp->status);
+ log::error("Error capability response: 0x{:02X}", p_rsp->status);
return;
}
@@ -3226,9 +3207,9 @@ static void handle_get_capability_response(tBTA_AV_META_MSG* pmeta_msg,
}
} else if (p_rsp->capability_id == AVRC_CAP_COMPANY_ID) {
getcapabilities_cmd(AVRC_CAP_EVENTS_SUPPORTED, p_dev);
- LOG_VERBOSE("%s: AVRC_CAP_COMPANY_ID: ", __func__);
+ log::verbose("AVRC_CAP_COMPANY_ID:");
for (xx = 0; xx < p_rsp->count; xx++) {
- LOG_VERBOSE("%s: company_id: %d", __func__, p_rsp->param.company_id[xx]);
+ log::verbose("company_id: {}", p_rsp->param.company_id[xx]);
}
}
}
@@ -3268,16 +3249,14 @@ static void handle_notification_response(tBTA_AV_META_MSG* pmeta_msg,
btif_rc_get_device_by_handle(pmeta_msg->rc_handle);
if (p_dev == NULL) {
- LOG_ERROR("%s: p_dev NULL", __func__);
+ log::error("p_dev NULL");
return;
}
if (btif_av_src_sink_coexist_enabled() &&
p_rsp->event_id == AVRC_EVT_VOLUME_CHANGE) {
- LOG_ERROR(
- "%s: legacy TG don't handle absolute volume change. leave it to new "
- "avrcp",
- __func__);
+ log::error(
+ "legacy TG don't handle absolute volume change. leave it to new avrcp");
return;
}
@@ -3288,7 +3267,7 @@ static void handle_notification_response(tBTA_AV_META_MSG* pmeta_msg,
btif_rc_supported_event_t* p_event;
list_node_t* node;
- LOG_VERBOSE("%s: Interim response: 0x%2X ", __func__, p_rsp->event_id);
+ log::verbose("Interim response: 0x{:2X}", p_rsp->event_id);
switch (p_rsp->event_id) {
case AVRC_EVT_PLAY_STATUS_CHANGE:
get_play_status_cmd(p_dev);
@@ -3323,7 +3302,7 @@ static void handle_notification_response(tBTA_AV_META_MSG* pmeta_msg,
break;
case AVRC_EVT_AVAL_PLAYERS_CHANGE:
- LOG_VERBOSE("%s: AVRC_EVT_AVAL_PLAYERS_CHANGE", __func__);
+ log::verbose("AVRC_EVT_AVAL_PLAYERS_CHANGE");
do_in_jni_thread(
FROM_HERE,
base::BindOnce(bt_rc_ctrl_callbacks->available_player_changed_cb,
@@ -3352,8 +3331,7 @@ static void handle_notification_response(tBTA_AV_META_MSG* pmeta_msg,
case AVRC_EVT_BATTERY_STATUS_CHANGE:
case AVRC_EVT_SYSTEM_STATUS_CHANGE:
default:
- LOG_ERROR("%s: Unhandled interim response: 0x%2X", __func__,
- p_rsp->event_id);
+ log::error("Unhandled interim response: 0x{:2X}", p_rsp->event_id);
return;
}
@@ -3381,8 +3359,7 @@ static void handle_notification_response(tBTA_AV_META_MSG* pmeta_msg,
if (p_dev->rc_features & BTA_AV_FEAT_APP_SETTING) {
list_player_app_setting_attrib_cmd(p_dev);
} else {
- LOG_VERBOSE("%s: App setting not supported, complete procedure",
- __func__);
+ log::verbose("App setting not supported, complete procedure");
rc_ctrl_procedure_complete(p_dev);
}
}
@@ -3390,8 +3367,7 @@ static void handle_notification_response(tBTA_AV_META_MSG* pmeta_msg,
btif_rc_supported_event_t* p_event;
list_node_t* node;
- LOG_VERBOSE("%s: Notification completed: 0x%2X ", __func__,
- p_rsp->event_id);
+ log::verbose("Notification completed: 0x{:2X}", p_rsp->event_id);
node = list_begin(p_dev->rc_supported_event_list);
@@ -3463,8 +3439,7 @@ static void handle_notification_response(tBTA_AV_META_MSG* pmeta_msg,
case AVRC_EVT_BATTERY_STATUS_CHANGE:
case AVRC_EVT_SYSTEM_STATUS_CHANGE:
default:
- LOG_ERROR("%s: Unhandled completion response: 0x%2X", __func__,
- p_rsp->event_id);
+ log::error("Unhandled completion response: 0x{:2X}", p_rsp->event_id);
return;
}
}
@@ -3486,8 +3461,8 @@ static void handle_app_attr_response(tBTA_AV_META_MSG* pmeta_msg,
btif_rc_get_device_by_handle(pmeta_msg->rc_handle);
if (p_dev == NULL || p_rsp->status != AVRC_STS_NO_ERROR) {
- LOG_ERROR("%s: Error getting Player application settings: 0x%2X", __func__,
- p_rsp->status);
+ log::error("Error getting Player application settings: 0x{:2X}",
+ p_rsp->status);
rc_ctrl_procedure_complete(p_dev);
return;
}
@@ -3514,7 +3489,7 @@ static void handle_app_attr_response(tBTA_AV_META_MSG* pmeta_msg,
list_player_app_setting_value_cmd(p_dev->rc_app_settings.attrs[0].attr_id,
p_dev);
} else {
- LOG_ERROR("%s: No Player application settings found", __func__);
+ log::error("No Player application settings found");
}
}
@@ -3540,8 +3515,7 @@ static void handle_app_val_response(tBTA_AV_META_MSG* pmeta_msg,
/* Todo: Do we need to retry on command timeout */
if (p_dev == NULL || p_rsp->status != AVRC_STS_NO_ERROR) {
- LOG_ERROR("%s: Error fetching attribute values: 0x%02X", __func__,
- p_rsp->status);
+ log::error("Error fetching attribute values: 0x{:02X}", p_rsp->status);
return;
}
@@ -3616,13 +3590,12 @@ static void handle_app_cur_val_response(tBTA_AV_META_MSG* pmeta_msg,
/* Todo: Do we need to retry on command timeout */
if (p_rsp->status != AVRC_STS_NO_ERROR) {
- LOG_ERROR("%s: Error fetching current settings: 0x%02X", __func__,
- p_rsp->status);
+ log::error("Error fetching current settings: 0x{:02X}", p_rsp->status);
return;
}
p_dev = btif_rc_get_device_by_handle(pmeta_msg->rc_handle);
if (p_dev == NULL) {
- LOG_ERROR("%s: Error in getting Device Address", __func__);
+ log::error("Error in getting Device Address");
osi_free_and_reset((void**)&p_rsp->p_vals);
return;
}
@@ -3671,7 +3644,7 @@ static void handle_app_attr_txt_response(tBTA_AV_META_MSG* pmeta_msg,
btif_rc_get_device_by_handle(pmeta_msg->rc_handle);
if (p_dev == NULL) {
- LOG_ERROR("%s: p_dev NULL", __func__);
+ log::error("p_dev NULL");
return;
}
@@ -3681,8 +3654,7 @@ static void handle_app_attr_txt_response(tBTA_AV_META_MSG* pmeta_msg,
if (p_rsp->status != AVRC_STS_NO_ERROR) {
uint8_t attrs[AVRC_MAX_APP_ATTR_SIZE];
- LOG_ERROR("%s: Error fetching attribute text: 0x%02X", __func__,
- p_rsp->status);
+ log::error("Error fetching attribute text: 0x{:02X}", p_rsp->status);
/* Not able to fetch Text for extended Menu, skip the process
* and cleanup used memory. Proceed to get the current settings
* for standard attributes.
@@ -3751,7 +3723,7 @@ static void handle_app_attr_val_txt_response(
btif_rc_get_device_by_handle(pmeta_msg->rc_handle);
if (p_dev == NULL) {
- LOG_ERROR("%s: p_dev NULL", __func__);
+ log::error("p_dev NULL");
return;
}
@@ -3761,8 +3733,7 @@ static void handle_app_attr_val_txt_response(
if (p_rsp->status != AVRC_STS_NO_ERROR) {
uint8_t attrs[AVRC_MAX_APP_ATTR_SIZE];
- LOG_ERROR("%s: Error fetching attribute value text: 0x%02X", __func__,
- p_rsp->status);
+ log::error("Error fetching attribute value text: 0x{:02X}", p_rsp->status);
/* Not able to fetch Text for extended Menu, skip the process
* and cleanup used memory. Proceed to get the current settings
@@ -3796,8 +3767,8 @@ static void handle_app_attr_val_txt_response(
}
if (p_app_settings->ext_val_index >= AVRC_MAX_APP_ATTR_SIZE) {
- LOG_ERROR("ext_val_index is 0x%02x, overflow!",
- p_app_settings->ext_val_index);
+ log::error("ext_val_index is 0x{:02x}, overflow!",
+ p_app_settings->ext_val_index);
return;
}
@@ -3888,7 +3859,7 @@ static void handle_set_app_attr_val_response(tBTA_AV_META_MSG* pmeta_msg,
btif_rc_get_device_by_handle(pmeta_msg->rc_handle);
if (p_dev == NULL) {
- LOG_ERROR("%s: p_dev NULL", __func__);
+ log::error("p_dev NULL");
return;
}
@@ -3925,7 +3896,7 @@ static void handle_get_metadata_attr_response(tBTA_AV_META_MSG* pmeta_msg,
(btrc_element_attr_val_t*)osi_calloc(buf_size);
if (p_dev == NULL) {
- LOG_ERROR("%s: p_dev NULL", __func__);
+ log::error("p_dev NULL");
return;
}
@@ -3954,8 +3925,7 @@ static void handle_get_metadata_attr_response(tBTA_AV_META_MSG* pmeta_msg,
const uint8_t attr_list_size = get_requested_attributes_list_size(p_dev);
get_metadata_attribute_cmd(attr_list_size, attr_list, p_dev);
} else {
- LOG_ERROR("%s: Error in get element attr procedure: %d", __func__,
- p_rsp->status);
+ log::error("Error in get element attr procedure: {}", p_rsp->status);
}
}
@@ -3975,7 +3945,7 @@ static void handle_get_playstatus_response(tBTA_AV_META_MSG* pmeta_msg,
btif_rc_get_device_by_handle(pmeta_msg->rc_handle);
if (p_dev == NULL) {
- LOG_ERROR("%s: p_dev NULL", __func__);
+ log::error("p_dev NULL");
return;
}
@@ -3990,8 +3960,7 @@ static void handle_get_playstatus_response(tBTA_AV_META_MSG* pmeta_msg,
base::BindOnce(bt_rc_ctrl_callbacks->play_position_changed_cb,
p_dev->rc_addr, p_rsp->song_len, p_rsp->song_pos));
} else {
- LOG_ERROR("%s: Error in get play status procedure: %d", __func__,
- p_rsp->status);
+ log::error("Error in get play status procedure: {}", p_rsp->status);
}
}
@@ -4011,7 +3980,7 @@ static void handle_set_addressed_player_response(tBTA_AV_META_MSG* pmeta_msg,
btif_rc_get_device_by_handle(pmeta_msg->rc_handle);
if (p_dev == NULL) {
- LOG_ERROR("%s: p_dev NULL", __func__);
+ log::error("p_dev NULL");
return;
}
@@ -4021,8 +3990,7 @@ static void handle_set_addressed_player_response(tBTA_AV_META_MSG* pmeta_msg,
FROM_HERE, base::BindOnce(bt_rc_ctrl_callbacks->set_addressed_player_cb,
p_dev->rc_addr, p_rsp->status));
} else {
- LOG_ERROR("%s: Error in get play status procedure %d", __func__,
- p_rsp->status);
+ log::error("Error in get play status procedure {}", p_rsp->status);
}
}
@@ -4050,10 +4018,10 @@ static void handle_get_folder_items_response(tBTA_AV_META_MSG* pmeta_msg,
for (uint8_t i = 0; i < item_count; i++) {
const tAVRC_ITEM* avrc_item = &(p_rsp->p_item_list[i]);
btrc_folder_items_t* btrc_item = &(btrc_items[i]);
- LOG_VERBOSE("%s folder item type %d", __func__, avrc_item->item_type);
+ log::verbose("folder item type {}", avrc_item->item_type);
switch (avrc_item->item_type) {
case AVRC_ITEM_MEDIA:
- LOG_VERBOSE("%s setting type to %d", __func__, BTRC_ITEM_MEDIA);
+ log::verbose("setting type to {}", BTRC_ITEM_MEDIA);
/* Allocate Space for Attributes */
btrc_item->media.num_attrs = avrc_item->u.media.attr_count;
btrc_item->media.p_attrs = (btrc_element_attr_val_t*)osi_malloc(
@@ -4062,18 +4030,18 @@ static void handle_get_folder_items_response(tBTA_AV_META_MSG* pmeta_msg,
break;
case AVRC_ITEM_FOLDER:
- LOG_VERBOSE("%s setting type to BTRC_ITEM_FOLDER", __func__);
+ log::verbose("setting type to BTRC_ITEM_FOLDER");
get_folder_item_type_folder(avrc_item, btrc_item);
break;
case AVRC_ITEM_PLAYER:
- LOG_VERBOSE("%s setting type to BTRC_ITEM_PLAYER", __func__);
+ log::verbose("setting type to BTRC_ITEM_PLAYER");
get_folder_item_type_player(avrc_item, btrc_item);
break;
default:
- LOG_ERROR("%s cannot understand folder item type %d", __func__,
- avrc_item->item_type);
+ log::error("cannot understand folder item type {}",
+ avrc_item->item_type);
}
}
@@ -4096,9 +4064,9 @@ static void handle_get_folder_items_response(tBTA_AV_META_MSG* pmeta_msg,
do_in_jni_thread(FROM_HERE, base::BindOnce(cleanup_btrc_folder_items,
btrc_items, item_count));
- LOG_VERBOSE("%s get_folder_items_cb sent to JNI thread", __func__);
+ log::verbose("get_folder_items_cb sent to JNI thread");
} else {
- LOG_ERROR("%s: Error %d", __func__, p_rsp->status);
+ log::error("Error {}", p_rsp->status);
do_in_jni_thread(
FROM_HERE, base::BindOnce(bt_rc_ctrl_callbacks->get_folder_items_cb,
p_dev->rc_addr, (btrc_status_t)p_rsp->status,
@@ -4126,7 +4094,7 @@ static void cleanup_btrc_folder_items(btrc_folder_items_t* btrc_items,
/*Nothing to free*/
break;
default:
- LOG_WARN("%s free unspecified type", __func__);
+ log::warn("free unspecified type");
}
}
osi_free(btrc_items);
@@ -4165,8 +4133,8 @@ void get_folder_item_type_media(const tAVRC_ITEM* avrc_item,
btrc_item_media->charset_id = avrc_item_media->name.charset_id;
/* Copy the name */
- LOG_VERBOSE("%s max len %d str len %d", __func__, BTRC_MAX_ATTR_STR_LEN,
- avrc_item_media->name.str_len);
+ log::verbose("max len {} str len {}", BTRC_MAX_ATTR_STR_LEN,
+ avrc_item_media->name.str_len);
memset(btrc_item_media->name, 0, BTRC_MAX_ATTR_STR_LEN * sizeof(uint8_t));
memcpy(btrc_item_media->name, avrc_item_media->name.p_str,
sizeof(uint8_t) * (avrc_item_media->name.str_len));
@@ -4176,7 +4144,7 @@ void get_folder_item_type_media(const tAVRC_ITEM* avrc_item,
btrc_element_attr_val_t* btrc_attr_pair = &(btrc_item_media->p_attrs[i]);
tAVRC_ATTR_ENTRY* avrc_attr_pair = &(avrc_item_media->p_attr_list[i]);
- LOG_VERBOSE("%s media attr id 0x%x", __func__, avrc_attr_pair->attr_id);
+ log::verbose("media attr id 0x{:x}", avrc_attr_pair->attr_id);
switch (avrc_attr_pair->attr_id) {
case AVRC_MEDIA_ATTR_ID_TITLE:
@@ -4204,8 +4172,7 @@ void get_folder_item_type_media(const tAVRC_ITEM* avrc_item,
btrc_attr_pair->attr_id = BTRC_MEDIA_ATTR_ID_COVER_ARTWORK_HANDLE;
break;
default:
- LOG_ERROR("%s invalid media attr id: 0x%x", __func__,
- avrc_attr_pair->attr_id);
+ log::error("invalid media attr id: 0x{:x}", avrc_attr_pair->attr_id);
btrc_attr_pair->attr_id = BTRC_MEDIA_ATTR_ID_INVALID;
}
@@ -4263,8 +4230,8 @@ void get_folder_item_type_folder(const tAVRC_ITEM* avrc_item,
btrc_item_folder->playable = avrc_item_folder->playable;
/* Copy name */
- LOG_VERBOSE("%s max len %d str len %d", __func__, BTRC_MAX_ATTR_STR_LEN,
- avrc_item_folder->name.str_len);
+ log::verbose("max len {} str len {}", BTRC_MAX_ATTR_STR_LEN,
+ avrc_item_folder->name.str_len);
memset(btrc_item_folder->name, 0, BTRC_MAX_ATTR_STR_LEN * sizeof(uint8_t));
memcpy(btrc_item_folder->name, avrc_item_folder->name.p_str,
avrc_item_folder->name.str_len * sizeof(uint8_t));
@@ -4319,7 +4286,7 @@ static void handle_change_path_response(tBTA_AV_META_MSG* pmeta_msg,
btif_rc_get_device_by_handle(pmeta_msg->rc_handle);
if (p_dev == NULL) {
- LOG_ERROR("%s: Invalid rc handle", __func__);
+ log::error("Invalid rc handle");
return;
}
@@ -4328,8 +4295,7 @@ static void handle_change_path_response(tBTA_AV_META_MSG* pmeta_msg,
base::BindOnce(bt_rc_ctrl_callbacks->change_folder_path_cb,
p_dev->rc_addr, p_rsp->num_items));
} else {
- LOG_ERROR("%s error in handle_change_path_response %d", __func__,
- p_rsp->status);
+ log::error("error in handle_change_path_response {}", p_rsp->status);
}
}
@@ -4348,7 +4314,7 @@ static void handle_set_browsed_player_response(tBTA_AV_META_MSG* pmeta_msg,
btif_rc_get_device_by_handle(pmeta_msg->rc_handle);
if (p_dev == NULL) {
- LOG_ERROR("%s: Invalid rc handle", __func__);
+ log::error("Invalid rc handle");
return;
}
@@ -4358,7 +4324,7 @@ static void handle_set_browsed_player_response(tBTA_AV_META_MSG* pmeta_msg,
base::BindOnce(bt_rc_ctrl_callbacks->set_browsed_player_cb,
p_dev->rc_addr, p_rsp->num_items, p_rsp->folder_depth));
} else {
- LOG_ERROR("%s error %d", __func__, p_rsp->status);
+ log::error("error {}", p_rsp->status);
}
}
@@ -4375,7 +4341,7 @@ static void clear_cmd_timeout(btif_rc_device_cb_t* p_dev, uint8_t label) {
p_txn = get_transaction_by_lbl(p_dev, label);
if (p_txn == NULL) {
- LOG_ERROR("%s: Error in transaction label lookup", __func__);
+ log::error("Error in transaction label lookup");
return;
}
@@ -4402,8 +4368,8 @@ static void handle_avk_rc_metamsg_rsp(tBTA_AV_META_MSG* pmeta_msg) {
tAVRC_STS status;
btif_rc_device_cb_t* p_dev = NULL;
- LOG_VERBOSE("%s: opcode: %d rsp_code: %d ", __func__,
- pmeta_msg->p_msg->hdr.opcode, pmeta_msg->code);
+ log::verbose("opcode: {} rsp_code: {}", pmeta_msg->p_msg->hdr.opcode,
+ pmeta_msg->code);
p_dev = btif_rc_get_device_by_handle(pmeta_msg->rc_handle);
status = AVRC_Ctrl_ParsResponse(pmeta_msg->p_msg, &avrc_response, scratch_buf,
@@ -4411,8 +4377,8 @@ static void handle_avk_rc_metamsg_rsp(tBTA_AV_META_MSG* pmeta_msg) {
if ((AVRC_OP_VENDOR == pmeta_msg->p_msg->hdr.opcode) &&
(pmeta_msg->code >= AVRC_RSP_NOT_IMPL) &&
(pmeta_msg->code <= AVRC_RSP_INTERIM)) {
- LOG_VERBOSE("%s parse status %d pdu = %d rsp_status = %d", __func__, status,
- avrc_response.pdu, pmeta_msg->p_msg->vendor.hdr.ctype);
+ log::verbose("parse status {} pdu = {} rsp_status = {}", status,
+ avrc_response.pdu, pmeta_msg->p_msg->vendor.hdr.ctype);
switch (avrc_response.pdu) {
case AVRC_PDU_REGISTER_NOTIFICATION:
@@ -4468,7 +4434,7 @@ static void handle_avk_rc_metamsg_rsp(tBTA_AV_META_MSG* pmeta_msg) {
break;
}
} else if (AVRC_OP_BROWSE == pmeta_msg->p_msg->hdr.opcode) {
- LOG_VERBOSE("%s AVRC_OP_BROWSE pdu %d", __func__, avrc_response.pdu);
+ log::verbose("AVRC_OP_BROWSE pdu {}", avrc_response.pdu);
/* check what kind of command it is for browsing */
switch (avrc_response.pdu) {
case AVRC_PDU_GET_FOLDER_ITEMS:
@@ -4484,16 +4450,14 @@ static void handle_avk_rc_metamsg_rsp(tBTA_AV_META_MSG* pmeta_msg) {
handle_get_metadata_attr_response(pmeta_msg, &avrc_response.get_attrs);
break;
default:
- LOG_ERROR("%s cannot handle browse pdu %d", __func__,
- pmeta_msg->p_msg->hdr.opcode);
+ log::error("cannot handle browse pdu {}", pmeta_msg->p_msg->hdr.opcode);
}
} else {
- LOG_VERBOSE(
- "%s: Invalid Vendor Command code: %d len: %d. Not processing it.",
- __func__, pmeta_msg->code, pmeta_msg->len);
+ log::verbose("Invalid Vendor Command code: {} len: {}. Not processing it.",
+ pmeta_msg->code, pmeta_msg->len);
return;
}
- LOG_VERBOSE("%s: release transaction %d", __func__, pmeta_msg->label);
+ log::verbose("release transaction {}", pmeta_msg->label);
release_transaction(p_dev, pmeta_msg->label);
}
@@ -4511,18 +4475,18 @@ static void handle_avk_rc_metamsg_cmd(tBTA_AV_META_MSG* pmeta_msg) {
tAVRC_STS status = BT_STATUS_UNSUPPORTED;
btif_rc_device_cb_t* p_dev = NULL;
- LOG_VERBOSE("%s: opcode: %d rsp_code: %d", __func__,
- pmeta_msg->p_msg->hdr.opcode, pmeta_msg->code);
+ log::verbose("opcode: {} rsp_code: {}", pmeta_msg->p_msg->hdr.opcode,
+ pmeta_msg->code);
status = AVRC_Ctrl_ParsCommand(pmeta_msg->p_msg, &avrc_cmd);
if ((AVRC_OP_VENDOR == pmeta_msg->p_msg->hdr.opcode) &&
(pmeta_msg->code <= AVRC_CMD_GEN_INQ)) {
- LOG_VERBOSE("%s Received vendor command.code %d, PDU %d label %d", __func__,
- pmeta_msg->code, avrc_cmd.pdu, pmeta_msg->label);
+ log::verbose("Received vendor command.code {}, PDU {} label {}",
+ pmeta_msg->code, avrc_cmd.pdu, pmeta_msg->label);
if (status != AVRC_STS_NO_ERROR) {
/* return error */
- LOG_WARN("%s: Error in parsing received metamsg command. status: 0x%02x",
- __func__, status);
+ log::warn("Error in parsing received metamsg command. status: 0x{:02x}",
+ status);
if (true == btif_av_both_enable()) {
if (AVRC_PDU_GET_CAPABILITIES == avrc_cmd.pdu ||
AVRC_PDU_GET_ELEMENT_ATTR == avrc_cmd.pdu ||
@@ -4536,25 +4500,24 @@ static void handle_avk_rc_metamsg_cmd(tBTA_AV_META_MSG* pmeta_msg) {
} else {
p_dev = btif_rc_get_device_by_handle(pmeta_msg->rc_handle);
if (p_dev == NULL) {
- LOG_ERROR("%s: avk rc meta msg cmd for Invalid rc handle", __func__);
+ log::error("avk rc meta msg cmd for Invalid rc handle");
return;
}
if (avrc_cmd.pdu == AVRC_PDU_REGISTER_NOTIFICATION) {
uint8_t event_id = avrc_cmd.reg_notif.event_id;
- LOG_VERBOSE("%s: Register notification event_id: %s", __func__,
- dump_rc_notification_event_id(event_id));
+ log::verbose("Register notification event_id: {}",
+ dump_rc_notification_event_id(event_id));
} else if (avrc_cmd.pdu == AVRC_PDU_SET_ABSOLUTE_VOLUME) {
- LOG_VERBOSE("%s: Abs Volume Cmd Recvd", __func__);
+ log::verbose("Abs Volume Cmd Recvd");
}
btif_rc_ctrl_upstreams_rsp_cmd(avrc_cmd.pdu, &avrc_cmd, pmeta_msg->label,
p_dev);
}
} else {
- LOG_VERBOSE(
- "%s: Invalid Vendor Command code: %d len: %d. Not processing it.",
- __func__, pmeta_msg->code, pmeta_msg->len);
+ log::verbose("Invalid Vendor Command code: {} len: {}. Not processing it.",
+ pmeta_msg->code, pmeta_msg->len);
return;
}
}
@@ -4569,7 +4532,7 @@ static void handle_avk_rc_metamsg_cmd(tBTA_AV_META_MSG* pmeta_msg) {
*
**************************************************************************/
static void cleanup() {
- LOG_VERBOSE("%s: ", __func__);
+ log::verbose("");
if (bt_rc_callbacks) {
bt_rc_callbacks = NULL;
}
@@ -4580,7 +4543,7 @@ static void cleanup() {
sizeof(btif_rc_cb.rc_multi_cb[idx]));
}
- LOG_VERBOSE("%s: completed", __func__);
+ log::verbose("completed");
}
/***************************************************************************
@@ -4593,7 +4556,7 @@ static void cleanup() {
*
**************************************************************************/
static void cleanup_ctrl() {
- LOG_VERBOSE("%s: ", __func__);
+ log::verbose("");
if (bt_rc_ctrl_callbacks) {
bt_rc_ctrl_callbacks = NULL;
@@ -4606,7 +4569,7 @@ static void cleanup_ctrl() {
}
memset(&btif_rc_cb.rc_multi_cb, 0, sizeof(btif_rc_cb.rc_multi_cb));
- LOG_VERBOSE("%s: completed", __func__);
+ log::verbose("completed");
}
/***************************************************************************
@@ -4620,7 +4583,7 @@ static void cleanup_ctrl() {
**************************************************************************/
static bt_status_t getcapabilities_cmd(uint8_t cap_id,
btif_rc_device_cb_t* p_dev) {
- LOG_VERBOSE("%s: cap_id: %d", __func__, cap_id);
+ log::verbose("cap_id: {}", cap_id);
CHECK_RC_CONNECTED(p_dev);
tAVRC_COMMAND avrc_cmd = {0};
@@ -4643,7 +4606,7 @@ static bt_status_t getcapabilities_cmd(uint8_t cap_id,
**************************************************************************/
static bt_status_t list_player_app_setting_attrib_cmd(
btif_rc_device_cb_t* p_dev) {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
CHECK_RC_CONNECTED(p_dev);
tAVRC_COMMAND avrc_cmd = {0};
@@ -4665,7 +4628,7 @@ static bt_status_t list_player_app_setting_attrib_cmd(
**************************************************************************/
static bt_status_t list_player_app_setting_value_cmd(
uint8_t attrib_id, btif_rc_device_cb_t* p_dev) {
- LOG_VERBOSE("%s: attrib_id: %d", __func__, attrib_id);
+ log::verbose("attrib_id: {}", attrib_id);
CHECK_RC_CONNECTED(p_dev);
tAVRC_COMMAND avrc_cmd = {0};
@@ -4689,7 +4652,7 @@ static bt_status_t list_player_app_setting_value_cmd(
static bt_status_t get_player_app_setting_cmd(uint8_t num_attrib,
uint8_t* attrib_ids,
btif_rc_device_cb_t* p_dev) {
- LOG_VERBOSE("%s: num_attrib: %d", __func__, num_attrib);
+ log::verbose("num_attrib: {}", num_attrib);
CHECK_RC_CONNECTED(p_dev);
tAVRC_COMMAND avrc_cmd = {0};
@@ -4716,10 +4679,10 @@ static bt_status_t get_player_app_setting_cmd(uint8_t num_attrib,
*
**************************************************************************/
static bt_status_t get_current_metadata_cmd(const RawAddress& bd_addr) {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr);
if (p_dev == NULL) {
- LOG_ERROR("%s: p_dev NULL", __func__);
+ log::error("p_dev NULL");
return BT_STATUS_FAIL;
}
const uint32_t* attr_list = get_requested_attributes_list(p_dev);
@@ -4738,7 +4701,7 @@ static bt_status_t get_current_metadata_cmd(const RawAddress& bd_addr) {
*
**************************************************************************/
static bt_status_t get_playback_state_cmd(const RawAddress& bd_addr) {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr);
return get_play_status_cmd(p_dev);
}
@@ -4759,7 +4722,7 @@ static bt_status_t get_playback_state_cmd(const RawAddress& bd_addr) {
static bt_status_t get_now_playing_list_cmd(const RawAddress& bd_addr,
uint32_t start_item,
uint32_t end_item) {
- LOG_VERBOSE("%s start, end: (%d, %d)", __func__, start_item, end_item);
+ log::verbose("start, end: ({}, {})", start_item, end_item);
return get_folder_items_cmd(bd_addr, AVRC_SCOPE_NOW_PLAYING, start_item,
end_item);
}
@@ -4808,7 +4771,7 @@ static bt_status_t get_item_attribute_cmd(uint64_t uid, int scope,
**************************************************************************/
static bt_status_t get_folder_list_cmd(const RawAddress& bd_addr,
uint32_t start_item, uint32_t end_item) {
- LOG_VERBOSE("%s start, end: (%d, %d)", __func__, start_item, end_item);
+ log::verbose("start, end: ({}, {})", start_item, end_item);
return get_folder_items_cmd(bd_addr, AVRC_SCOPE_FILE_SYSTEM, start_item,
end_item);
}
@@ -4828,7 +4791,7 @@ static bt_status_t get_folder_list_cmd(const RawAddress& bd_addr,
**************************************************************************/
static bt_status_t get_player_list_cmd(const RawAddress& bd_addr,
uint32_t start_item, uint32_t end_item) {
- LOG_VERBOSE("%s start, end: (%d, %d)", __func__, start_item, end_item);
+ log::verbose("start, end: ({}, {})", start_item, end_item);
return get_folder_items_cmd(bd_addr, AVRC_SCOPE_PLAYER_LIST, start_item,
end_item);
}
@@ -4850,7 +4813,7 @@ static bt_status_t get_player_list_cmd(const RawAddress& bd_addr,
**************************************************************************/
static bt_status_t change_folder_path_cmd(const RawAddress& bd_addr,
uint8_t direction, uint8_t* uid) {
- LOG_VERBOSE("%s: direction %d", __func__, direction);
+ log::verbose("direction {}", direction);
btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr);
CHECK_RC_CONNECTED(p_dev);
CHECK_BR_CONNECTED(p_dev);
@@ -4883,7 +4846,7 @@ static bt_status_t change_folder_path_cmd(const RawAddress& bd_addr,
**************************************************************************/
static bt_status_t set_browsed_player_cmd(const RawAddress& bd_addr,
uint16_t id) {
- LOG_VERBOSE("%s: id %d", __func__, id);
+ log::verbose("id {}", id);
btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr);
CHECK_RC_CONNECTED(p_dev);
CHECK_BR_CONNECTED(p_dev);
@@ -4911,7 +4874,7 @@ static bt_status_t set_browsed_player_cmd(const RawAddress& bd_addr,
***************************************************************************/
static bt_status_t set_addressed_player_cmd(const RawAddress& bd_addr,
uint16_t id) {
- LOG_VERBOSE("%s: id %d", __func__, id);
+ log::verbose("id {}", id);
btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr);
CHECK_RC_CONNECTED(p_dev);
@@ -4947,7 +4910,7 @@ static bt_status_t get_folder_items_cmd(const RawAddress& bd_addr,
uint32_t end_item) {
/* Check that both avrcp and browse channel are connected. */
btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr);
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
CHECK_RC_CONNECTED(p_dev);
CHECK_BR_CONNECTED(p_dev);
@@ -4979,7 +4942,7 @@ static bt_status_t change_player_app_setting(const RawAddress& bd_addr,
uint8_t num_attrib,
uint8_t* attrib_ids,
uint8_t* attrib_vals) {
- LOG_VERBOSE("%s: num_attrib: %d", __func__, num_attrib);
+ log::verbose("num_attrib: {}", num_attrib);
btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr);
CHECK_RC_CONNECTED(p_dev);
@@ -5011,7 +4974,7 @@ static bt_status_t change_player_app_setting(const RawAddress& bd_addr,
**************************************************************************/
static bt_status_t play_item_cmd(const RawAddress& bd_addr, uint8_t scope,
uint8_t* uid, uint16_t uid_counter) {
- LOG_VERBOSE("%s: scope %d uid_counter %d", __func__, scope, uid_counter);
+ log::verbose("scope {} uid_counter {}", scope, uid_counter);
btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr);
CHECK_RC_CONNECTED(p_dev);
CHECK_BR_CONNECTED(p_dev);
@@ -5038,7 +5001,7 @@ static bt_status_t play_item_cmd(const RawAddress& bd_addr, uint8_t scope,
**************************************************************************/
static bt_status_t get_player_app_setting_attr_text_cmd(
uint8_t* attrs, uint8_t num_attrs, btif_rc_device_cb_t* p_dev) {
- LOG_VERBOSE("%s: num attrs: %d", __func__, num_attrs);
+ log::verbose("num attrs: {}", num_attrs);
CHECK_RC_CONNECTED(p_dev);
tAVRC_COMMAND avrc_cmd = {0};
@@ -5064,7 +5027,7 @@ static bt_status_t get_player_app_setting_attr_text_cmd(
**************************************************************************/
static bt_status_t get_player_app_setting_value_text_cmd(
uint8_t* vals, uint8_t num_vals, btif_rc_device_cb_t* p_dev) {
- LOG_VERBOSE("%s: num_vals: %d", __func__, num_vals);
+ log::verbose("num_vals: {}", num_vals);
CHECK_RC_CONNECTED(p_dev);
tAVRC_COMMAND avrc_cmd = {0};
@@ -5091,8 +5054,7 @@ static bt_status_t get_player_app_setting_value_text_cmd(
static bt_status_t register_notification_cmd(uint8_t event_id,
uint32_t event_value,
btif_rc_device_cb_t* p_dev) {
- LOG_VERBOSE("%s: event_id: %d event_value %d", __func__, event_id,
- event_value);
+ log::verbose("event_id: {} event_value {}", event_id, event_value);
CHECK_RC_CONNECTED(p_dev);
tAVRC_COMMAND avrc_cmd = {0};
@@ -5120,8 +5082,8 @@ static bt_status_t register_notification_cmd(uint8_t event_id,
static bt_status_t get_metadata_attribute_cmd(uint8_t num_attribute,
const uint32_t* p_attr_ids,
btif_rc_device_cb_t* p_dev) {
- LOG_VERBOSE("%s: num_attribute: %d attribute_id: %d", __func__, num_attribute,
- p_attr_ids[0]);
+ log::verbose("num_attribute: {} attribute_id: {}", num_attribute,
+ p_attr_ids[0]);
// If browsing is connected then send the command out that channel
if (p_dev->br_connected) {
@@ -5146,8 +5108,8 @@ static bt_status_t get_metadata_attribute_cmd(uint8_t num_attribute,
static bt_status_t get_element_attribute_cmd(uint8_t num_attribute,
const uint32_t* p_attr_ids,
btif_rc_device_cb_t* p_dev) {
- LOG_VERBOSE("%s: num_attribute: %d attribute_id: %d", __func__, num_attribute,
- p_attr_ids[0]);
+ log::verbose("num_attribute: {} attribute_id: {}", num_attribute,
+ p_attr_ids[0]);
CHECK_RC_CONNECTED(p_dev);
tAVRC_COMMAND avrc_cmd = {0};
avrc_cmd.get_elem_attrs.opcode = AVRC_OP_VENDOR;
@@ -5171,7 +5133,7 @@ static bt_status_t get_element_attribute_cmd(uint8_t num_attribute,
*
**************************************************************************/
static bt_status_t get_play_status_cmd(btif_rc_device_cb_t* p_dev) {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
CHECK_RC_CONNECTED(p_dev);
tAVRC_COMMAND avrc_cmd = {0};
@@ -5200,7 +5162,7 @@ static bt_status_t set_volume_rsp(const RawAddress& bd_addr, uint8_t abs_vol,
CHECK_RC_CONNECTED(p_dev);
- LOG_VERBOSE("%s: abs_vol: %d", __func__, abs_vol);
+ log::verbose("abs_vol: {}", abs_vol);
avrc_rsp.volume.opcode = AVRC_OP_VENDOR;
avrc_rsp.volume.pdu = AVRC_PDU_SET_ABSOLUTE_VOLUME;
@@ -5209,15 +5171,14 @@ static bt_status_t set_volume_rsp(const RawAddress& bd_addr, uint8_t abs_vol,
status = AVRC_BldResponse(p_dev->rc_handle, &avrc_rsp, &p_msg);
if (status == AVRC_STS_NO_ERROR) {
uint8_t* data_start = (uint8_t*)(p_msg + 1) + p_msg->offset;
- LOG_VERBOSE("%s: msgreq being sent out with label: %d", __func__,
- p_dev->rc_vol_label);
+ log::verbose("msgreq being sent out with label: {}", p_dev->rc_vol_label);
if (p_msg != NULL) {
BTA_AvVendorRsp(p_dev->rc_handle, label, AVRC_RSP_ACCEPT, data_start,
p_msg->len, 0);
status = BT_STATUS_SUCCESS;
}
} else {
- LOG_ERROR("%s: failed to build command. status: 0x%02x", __func__, status);
+ log::error("failed to build command. status: 0x{:02x}", status);
}
osi_free(p_msg);
return (bt_status_t)status;
@@ -5238,7 +5199,7 @@ static bt_status_t volume_change_notification_rsp(
tAVRC_STS status = BT_STATUS_UNSUPPORTED;
tAVRC_RESPONSE avrc_rsp;
BT_HDR* p_msg = NULL;
- LOG_VERBOSE("%s: rsp_type: %d abs_vol: %d", __func__, rsp_type, abs_vol);
+ log::verbose("rsp_type: {} abs_vol: {}", rsp_type, abs_vol);
btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr);
@@ -5252,7 +5213,7 @@ static bt_status_t volume_change_notification_rsp(
status = AVRC_BldResponse(p_dev->rc_handle, &avrc_rsp, &p_msg);
if (status == AVRC_STS_NO_ERROR) {
- LOG_VERBOSE("%s: msgreq being sent out with label: %d", __func__, label);
+ log::verbose("msgreq being sent out with label: {}", label);
uint8_t* data_start = (uint8_t*)(p_msg + 1) + p_msg->offset;
BTA_AvVendorRsp(p_dev->rc_handle, label,
(rsp_type == BTRC_NOTIFICATION_TYPE_INTERIM)
@@ -5261,7 +5222,7 @@ static bt_status_t volume_change_notification_rsp(
data_start, p_msg->len, 0);
status = BT_STATUS_SUCCESS;
} else {
- LOG_ERROR("%s: failed to build command. status: 0x%02x", __func__, status);
+ log::error("failed to build command. status: 0x{:02x}", status);
}
osi_free(p_msg);
@@ -5282,7 +5243,7 @@ static bt_status_t send_groupnavigation_cmd(const RawAddress& bd_addr,
uint8_t key_state) {
tAVRC_STS status = BT_STATUS_UNSUPPORTED;
rc_transaction_t* p_transaction = NULL;
- LOG_VERBOSE("%s: key-code: %d, key-state: %d", __func__, key_code, key_state);
+ log::verbose("key-code: {}, key-state: {}", key_code, key_state);
btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(bd_addr);
CHECK_RC_CONNECTED(p_dev);
@@ -5305,16 +5266,16 @@ static bt_status_t send_groupnavigation_cmd(const RawAddress& bd_addr,
AVRC_PASS_THRU_GROUP_LEN);
status = BT_STATUS_SUCCESS;
start_transaction_timer(p_dev, p_transaction->label, BTIF_RC_TIMEOUT_MS);
- LOG_VERBOSE("%s: Send command, key-code=%d, key-state=%d, label=%d",
- __func__, key_code, key_state, p_transaction->label);
+ log::verbose("Send command, key-code={}, key-state={}, label={}",
+ key_code, key_state, p_transaction->label);
} else {
status = BT_STATUS_FAIL;
- LOG_ERROR("%s: failed to get label, key-code=%d, key-state=%d, status=%d",
- __func__, key_code, key_state, tran_status);
+ log::error("failed to get label, key-code={}, key-state={}, status={}",
+ key_code, key_state, tran_status);
}
} else {
status = BT_STATUS_FAIL;
- LOG_VERBOSE("%s: feature not supported", __func__);
+ log::verbose("feature not supported");
}
return (bt_status_t)status;
}
@@ -5332,13 +5293,13 @@ static bt_status_t send_passthrough_cmd(const RawAddress& bd_addr,
uint8_t key_code, uint8_t key_state) {
tAVRC_STS status = BT_STATUS_UNSUPPORTED;
btif_rc_device_cb_t* p_dev = NULL;
- LOG_ERROR("%s: calling btif_rc_get_device_by_bda", __func__);
+ log::error("calling btif_rc_get_device_by_bda");
p_dev = btif_rc_get_device_by_bda(bd_addr);
CHECK_RC_CONNECTED(p_dev);
rc_transaction_t* p_transaction = NULL;
- LOG_VERBOSE("%s: key-code: %d, key-state: %d", __func__, key_code, key_state);
+ log::verbose("key-code: {}, key-state: {}", key_code, key_state);
if (p_dev->rc_features & BTA_AV_FEAT_RCTG) {
rc_transaction_context_t context = {
.rc_addr = p_dev->rc_addr,
@@ -5351,16 +5312,16 @@ static bt_status_t send_passthrough_cmd(const RawAddress& bd_addr,
(tBTA_AV_RC)key_code, (tBTA_AV_STATE)key_state);
status = BT_STATUS_SUCCESS;
start_transaction_timer(p_dev, p_transaction->label, BTIF_RC_TIMEOUT_MS);
- LOG_VERBOSE("%s: Send command, key-code=%d, key-state=%d, label=%d",
- __func__, key_code, key_state, p_transaction->label);
+ log::verbose("Send command, key-code={}, key-state={}, label={}",
+ key_code, key_state, p_transaction->label);
} else {
status = BT_STATUS_FAIL;
- LOG_ERROR("%s: failed to get label, key-code=%d, key-state=%d, status=%d",
- __func__, key_code, key_state, tran_status);
+ log::error("failed to get label, key-code={}, key-state={}, status={}",
+ key_code, key_state, tran_status);
}
} else {
status = BT_STATUS_FAIL;
- LOG_VERBOSE("%s: feature not supported", __func__);
+ log::verbose("feature not supported");
}
return (bt_status_t)status;
}
@@ -5420,7 +5381,7 @@ static const btrc_ctrl_interface_t bt_rc_ctrl_interface = {
*
******************************************************************************/
const btrc_interface_t* btif_rc_get_interface(void) {
- LOG_VERBOSE("%s: ", __func__);
+ log::verbose("");
return &bt_rc_interface;
}
@@ -5434,7 +5395,7 @@ const btrc_interface_t* btif_rc_get_interface(void) {
*
******************************************************************************/
const btrc_ctrl_interface_t* btif_rc_ctrl_get_interface(void) {
- LOG_VERBOSE("%s: ", __func__);
+ log::verbose("");
return &bt_rc_ctrl_interface;
}
@@ -5532,13 +5493,12 @@ static bt_status_t get_transaction(btif_rc_device_cb_t* p_dev,
transaction_set->transaction[i].context = context;
transaction_set->transaction[i].in_use = true;
*ptransaction = &(transaction_set->transaction[i]);
- LOG_VERBOSE("%s: Assigned transaction=%s", __func__,
- dump_transaction(*ptransaction).c_str());
+ log::verbose("Assigned transaction={}", dump_transaction(*ptransaction));
return BT_STATUS_SUCCESS;
}
}
- LOG_ERROR("%s: p_dev=%s, failed to find free transaction", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(p_dev->rc_addr));
+ log::error("p_dev={}, failed to find free transaction",
+ ADDRESS_TO_LOGGABLE_CSTR(p_dev->rc_addr));
return BT_STATUS_NOMEM;
}
@@ -5556,12 +5516,12 @@ static void start_transaction_timer(btif_rc_device_cb_t* p_dev, uint8_t label,
uint64_t timeout_ms) {
rc_transaction_t* transaction = get_transaction_by_lbl(p_dev, label);
if (transaction == nullptr) {
- LOG_ERROR("%s: transaction is null", __func__);
+ log::error("transaction is null");
return;
}
if (alarm_is_scheduled(transaction->timer)) {
- LOG_WARN("%s: Restarting timer that's already scheduled", __func__);
+ log::warn("Restarting timer that's already scheduled");
}
std::stringstream ss;
@@ -5582,9 +5542,9 @@ static void start_transaction_timer(btif_rc_device_cb_t* p_dev, uint8_t label,
* Returns bt_status_t
******************************************************************************/
void release_transaction(btif_rc_device_cb_t* p_dev, uint8_t lbl) {
- LOG_VERBOSE("%s: p_dev=%s, label=%d", __func__,
- p_dev == NULL ? "null" : ADDRESS_TO_LOGGABLE_CSTR(p_dev->rc_addr),
- lbl);
+ log::verbose(
+ "p_dev={}, label={}",
+ p_dev == NULL ? "null" : ADDRESS_TO_LOGGABLE_CSTR(p_dev->rc_addr), lbl);
if (p_dev == nullptr) return;
rc_transaction_set_t* transaction_set = &(p_dev->transaction_set);
@@ -5657,17 +5617,17 @@ static void vendor_cmd_timeout_handler(btif_rc_device_cb_t* p_dev,
uint8_t label,
rc_vendor_context_t* p_context) {
if (p_dev == NULL) {
- LOG_ERROR("%s: p_dev NULL", __func__);
+ log::error("p_dev NULL");
return;
}
tAVRC_RESPONSE avrc_response = {0};
tBTA_AV_META_MSG meta_msg = {.rc_handle = p_dev->rc_handle};
- LOG_WARN("%s: timeout, addr=%s, label=%d, pdu_id=%s, event_id=%s", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(p_dev->rc_addr), label,
- dump_rc_pdu(p_context->pdu_id),
- dump_rc_notification_event_id(p_context->event_id));
+ log::warn("timeout, addr={}, label={}, pdu_id={}, event_id={}",
+ ADDRESS_TO_LOGGABLE_CSTR(p_dev->rc_addr), label,
+ dump_rc_pdu(p_context->pdu_id),
+ dump_rc_notification_event_id(p_context->event_id));
switch (p_context->pdu_id) {
case AVRC_PDU_REGISTER_NOTIFICATION:
@@ -5724,8 +5684,7 @@ static void vendor_cmd_timeout_handler(btif_rc_device_cb_t* p_dev,
break;
default:
- LOG_WARN("%s: timeout for unknown pdu_id=%d", __func__,
- p_context->pdu_id);
+ log::warn("timeout for unknown pdu_id={}", p_context->pdu_id);
break;
}
}
@@ -5742,7 +5701,7 @@ static void browse_cmd_timeout_handler(btif_rc_device_cb_t* p_dev,
uint8_t label,
rc_browse_context_t* p_context) {
if (p_dev == NULL) {
- LOG_ERROR("%s: p_dev NULL", __func__);
+ log::error("p_dev NULL");
return;
}
@@ -5757,9 +5716,9 @@ static void browse_cmd_timeout_handler(btif_rc_device_cb_t* p_dev,
.p_msg = nullptr,
};
- LOG_WARN("%s: timeout, addr=%s, label=%d, pdu_id=%s", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(p_dev->rc_addr), label,
- dump_rc_pdu(p_context->pdu_id));
+ log::warn("timeout, addr={}, label={}, pdu_id={}",
+ ADDRESS_TO_LOGGABLE_CSTR(p_dev->rc_addr), label,
+ dump_rc_pdu(p_context->pdu_id));
switch (p_context->pdu_id) {
case AVRC_PDU_GET_FOLDER_ITEMS:
@@ -5779,8 +5738,7 @@ static void browse_cmd_timeout_handler(btif_rc_device_cb_t* p_dev,
handle_get_metadata_attr_response(&meta_msg, &avrc_response.get_attrs);
break;
default:
- LOG_WARN("%s: timeout for unknown pdu_id=%d", __func__,
- p_context->pdu_id);
+ log::warn("timeout for unknown pdu_id={}", p_context->pdu_id);
break;
}
}
@@ -5797,13 +5755,13 @@ static void passthru_cmd_timeout_handler(btif_rc_device_cb_t* p_dev,
uint8_t label,
rc_passthru_context_t* p_context) {
if (p_dev == NULL) {
- LOG_ERROR("%s: p_dev NULL", __func__);
+ log::error("p_dev NULL");
return;
}
- LOG_WARN("%s: timeout, addr=%s, label=%d, rc_id=%d, key_state=%d", __func__,
- ADDRESS_TO_LOGGABLE_CSTR(p_dev->rc_addr), label, p_context->rc_id,
- p_context->key_state);
+ log::warn("timeout, addr={}, label={}, rc_id={}, key_state={}",
+ ADDRESS_TO_LOGGABLE_CSTR(p_dev->rc_addr), label, p_context->rc_id,
+ p_context->key_state);
// Other requests are wrapped in a tAVRC_RESPONSE response object, but these
// passthru events are not in there. As well, the upper layers don't handle
@@ -5824,13 +5782,13 @@ static void btif_rc_transaction_timeout_handler(uint16_t /* event */,
char* data) {
rc_transaction_context_t* p_context = (rc_transaction_context_t*)data;
if (p_context == nullptr) {
- LOG_ERROR("%s: p_context is null", __func__);
+ log::error("p_context is null");
return;
}
btif_rc_device_cb_t* p_dev = btif_rc_get_device_by_bda(p_context->rc_addr);
if (p_dev == NULL) {
- LOG_ERROR("%s: p_dev is null", __func__);
+ log::error("p_dev is null");
return;
}
@@ -5847,8 +5805,7 @@ static void btif_rc_transaction_timeout_handler(uint16_t /* event */,
&(p_context->command.passthru));
break;
default:
- LOG_WARN("%s: received timeout for unknown opcode=%d", __func__,
- p_context->opcode);
+ log::warn("received timeout for unknown opcode={}", p_context->opcode);
return;
}
release_transaction(p_dev, label);
@@ -5926,7 +5883,7 @@ static bool absolute_volume_disabled() {
char volume_disabled[PROPERTY_VALUE_MAX] = {0};
osi_property_get("persist.bluetooth.disableabsvol", volume_disabled, "false");
if (strncmp(volume_disabled, "true", 4) == 0) {
- LOG_WARN("%s: Absolute volume disabled by property", __func__);
+ log::warn("Absolute volume disabled by property");
return true;
}
return false;
diff --git a/system/btif/src/btif_sdp.cc b/system/btif/src/btif_sdp.cc
index 0169a7f22c..7688c3cc76 100644
--- a/system/btif/src/btif_sdp.cc
+++ b/system/btif/src/btif_sdp.cc
@@ -28,6 +28,7 @@
#define LOG_TAG "bt_btif_sdp"
+#include <bluetooth/log.h>
#include <hardware/bluetooth.h>
#include <hardware/bt_sdp.h>
#include <stdlib.h>
@@ -40,6 +41,7 @@
#include "types/raw_address.h"
using bluetooth::Uuid;
+using namespace bluetooth;
/*****************************************************************************
* Functions implemented in sdp_server.c
@@ -65,7 +67,7 @@ static btsdp_callbacks_t* bt_sdp_callbacks = NULL;
static void btif_sdp_search_comp_evt(uint16_t event, char* p_param) {
tBTA_SDP_SEARCH_COMP* evt_data = (tBTA_SDP_SEARCH_COMP*)p_param;
- LOG_VERBOSE("%s: event = %d", __func__, event);
+ log::verbose("event = {}", event);
if (event != BTA_SDP_SEARCH_COMP_EVT) return;
@@ -116,7 +118,7 @@ static void sdp_dm_cback(tBTA_SDP_EVT event, tBTA_SDP* p_data,
}
static bt_status_t init(btsdp_callbacks_t* callbacks) {
- LOG_VERBOSE("Sdp Search %s", __func__);
+ log::verbose("Sdp Search Init");
bt_sdp_callbacks = callbacks;
sdp_server_init();
@@ -127,7 +129,7 @@ static bt_status_t init(btsdp_callbacks_t* callbacks) {
}
static bt_status_t deinit() {
- LOG_VERBOSE("Sdp Search %s", __func__);
+ log::verbose("Sdp Search Deinit");
bt_sdp_callbacks = NULL;
sdp_server_cleanup();
@@ -146,7 +148,7 @@ static const btsdp_interface_t sdp_if = {
remove_sdp_record};
const btsdp_interface_t* btif_sdp_get_interface(void) {
- LOG_VERBOSE("%s", __func__);
+ log::verbose("");
return &sdp_if;
}
@@ -160,7 +162,7 @@ const btsdp_interface_t* btif_sdp_get_interface(void) {
*
******************************************************************************/
bt_status_t btif_sdp_execute_service(bool b_enable) {
- LOG_VERBOSE("%s enable:%d", __func__, b_enable);
+ log::verbose("enable:{}", b_enable);
if (b_enable) {
BTA_SdpEnable(sdp_dm_cback);
diff --git a/system/btif/src/btif_sdp_server.cc b/system/btif/src/btif_sdp_server.cc
index 75653a7b2a..6591791d0f 100644
--- a/system/btif/src/btif_sdp_server.cc
+++ b/system/btif/src/btif_sdp_server.cc
@@ -28,6 +28,7 @@
#define LOG_TAG "bt_btif_sdp_server"
+#include <bluetooth/log.h>
#include <hardware/bluetooth.h>
#include <hardware/bt_sdp.h>
#include <pthread.h>
@@ -50,6 +51,7 @@
#include "utl.h"
using namespace bluetooth::legacy::stack::sdp;
+using namespace bluetooth;
// Protects the sdp_slots array from concurrent access.
static std::recursive_mutex sdp_lock;
@@ -69,6 +71,11 @@ typedef struct {
bluetooth_sdp_record* record_data;
} sdp_slot_t;
+namespace fmt {
+template <>
+struct formatter<sdp_state_t> : enum_formatter<sdp_state_t> {};
+} // namespace fmt
+
#define MAX_SDP_SLOTS 128
static sdp_slot_t sdp_slots[MAX_SDP_SLOTS];
@@ -109,13 +116,13 @@ static void init_sdp_slots() {
}
bt_status_t sdp_server_init() {
- LOG_VERBOSE("Sdp Server %s", __func__);
+ log::verbose("Sdp Server Init");
init_sdp_slots();
return BT_STATUS_SUCCESS;
}
void sdp_server_cleanup() {
- LOG_VERBOSE("Sdp Server %s", __func__);
+ log::verbose("Sdp Server Cleanup");
std::unique_lock<std::recursive_mutex> lock(sdp_lock);
int i;
for (i = 0; i < MAX_SDP_SLOTS; i++) {
@@ -213,7 +220,7 @@ static int alloc_sdp_slot(bluetooth_sdp_record* in_record) {
}
}
}
- LOG_ERROR("%s() failed - no more free slots!", __func__);
+ log::error("failed - no more free slots!");
/* Rearly the optimist is too optimistic, and cleanup is needed...*/
osi_free(record);
return -1;
@@ -223,7 +230,7 @@ static int free_sdp_slot(int id) {
int handle = -1;
bluetooth_sdp_record* record = NULL;
if (id < 0 || id >= MAX_SDP_SLOTS) {
- LOG_ERROR("%s() failed - id %d is invalid", __func__, id);
+ log::error("failed - id {} is invalid", id);
return handle;
}
@@ -253,17 +260,16 @@ static int free_sdp_slot(int id) {
*/
static const sdp_slot_t* start_create_sdp(int id) {
if (id >= MAX_SDP_SLOTS) {
- LOG_ERROR("%s() failed - id %d is invalid", __func__, id);
+ log::error("failed - id {} is invalid", id);
return NULL;
}
std::unique_lock<std::recursive_mutex> lock(sdp_lock);
if (sdp_slots[id].state != SDP_RECORD_ALLOCED) {
/* The record have been removed before this event occurred - e.g. deinit */
- LOG_ERROR(
- "%s() failed - state for id %d is "
- "sdp_slots[id].state = %d expected %d",
- __func__, id, sdp_slots[id].state, SDP_RECORD_ALLOCED);
+ log::error(
+ "failed - state for id {} is sdp_slots[id].state = {} expected {}", id,
+ sdp_slots[id].state, SDP_RECORD_ALLOCED);
return NULL;
}
@@ -280,7 +286,7 @@ bt_status_t create_sdp_record(bluetooth_sdp_record* record,
int handle;
handle = alloc_sdp_slot(record);
- LOG_VERBOSE("%s() handle = 0x%08x", __func__, handle);
+ log::verbose("handle = 0x{:08x}", handle);
if (handle < 0) return BT_STATUS_FAIL;
@@ -332,16 +338,14 @@ bt_status_t remove_sdp_record(int record_id) {
/* Get the Record handle, and free the slot */
handle = free_sdp_slot(record_id);
- LOG_VERBOSE("Sdp Server %s id=%d to handle=0x%08x", __func__, record_id,
- handle);
+ log::verbose("Sdp Server id={} to handle=0x{:08x}", record_id, handle);
/* Pass the actual record handle */
if (handle > 0) {
BTA_SdpRemoveRecordByUser(INT_TO_PTR(handle));
return BT_STATUS_SUCCESS;
}
- LOG_VERBOSE("Sdp Server %s - record already removed - or never created",
- __func__);
+ log::verbose("Sdp Server - record already removed - or never created");
return BT_STATUS_FAIL;
}
@@ -357,7 +361,7 @@ void on_create_record_event(int id) {
* 3) Update state on completion
* 4) What to do at fail?
* */
- LOG_VERBOSE("Sdp Server %s", __func__);
+ log::verbose("Sdp Server");
const sdp_slot_t* sdp_slot = start_create_sdp(id);
tBTA_SERVICE_ID service_id = -1;
bluetooth_sdp_record* record;
@@ -397,7 +401,7 @@ void on_create_record_event(int id) {
}
break;
default:
- LOG_VERBOSE("Record type %d is not supported", record->hdr.type);
+ log::verbose("Record type {} is not supported", record->hdr.type);
break;
}
if (handle != -1) {
@@ -419,14 +423,14 @@ void on_create_record_event(int id) {
}
void on_remove_record_event(int handle) {
- LOG_VERBOSE("Sdp Server %s", __func__);
+ log::verbose("Sdp Server");
// User data carries the actual SDP handle, not the ID.
if (handle != -1 && handle != 0) {
bool result;
result = get_legacy_stack_sdp_api()->handle.SDP_DeleteRecord(handle);
if (!result) {
- LOG_ERROR(" Unable to remove handle 0x%08x", handle);
+ log::error("Unable to remove handle 0x{:08x}", handle);
}
}
}
@@ -449,7 +453,7 @@ static int add_maps_sdp(const bluetooth_sdp_mas_record* rec) {
sdp_handle = get_legacy_stack_sdp_api()->handle.SDP_CreateRecord();
if (sdp_handle == 0) {
- LOG_ERROR("Unable to register MAPS Service");
+ log::error("Unable to register MAPS Service");
return sdp_handle;
}
@@ -510,10 +514,10 @@ static int add_maps_sdp(const bluetooth_sdp_mas_record* rec) {
if (!status) {
get_legacy_stack_sdp_api()->handle.SDP_DeleteRecord(sdp_handle);
sdp_handle = 0;
- LOG_ERROR("%s() FAILED", __func__);
+ log::error("FAILED");
} else {
bta_sys_add_uuid(service); /* UUID_SERVCLASS_MESSAGE_ACCESS */
- LOG_VERBOSE("%s(): SDP Registered (handle 0x%08x)", __func__, sdp_handle);
+ log::verbose("SDP Registered (handle 0x{:08x})", sdp_handle);
}
return sdp_handle;
}
@@ -531,7 +535,7 @@ static int add_mapc_sdp(const bluetooth_sdp_mns_record* rec) {
sdp_handle = get_legacy_stack_sdp_api()->handle.SDP_CreateRecord();
if (sdp_handle == 0) {
- LOG_ERROR("Unable to register MAP Notification Service");
+ log::error("Unable to register MAP Notification Service");
return sdp_handle;
}
@@ -582,10 +586,10 @@ static int add_mapc_sdp(const bluetooth_sdp_mns_record* rec) {
if (!status) {
get_legacy_stack_sdp_api()->handle.SDP_DeleteRecord(sdp_handle);
sdp_handle = 0;
- LOG_ERROR("%s() FAILED", __func__);
+ log::error("FAILED");
} else {
bta_sys_add_uuid(service); /* UUID_SERVCLASS_MESSAGE_ACCESS */
- LOG_VERBOSE("%s(): SDP Registered (handle 0x%08x)", __func__, sdp_handle);
+ log::verbose("SDP Registered (handle 0x{:08x})", sdp_handle);
}
return sdp_handle;
}
@@ -600,7 +604,7 @@ static int add_pbapc_sdp(const bluetooth_sdp_pce_record* rec) {
sdp_handle = get_legacy_stack_sdp_api()->handle.SDP_CreateRecord();
if (sdp_handle == 0) {
- LOG_ERROR("Unable to register PBAP Client Service");
+ log::error("Unable to register PBAP Client Service");
return sdp_handle;
}
@@ -624,11 +628,11 @@ static int add_pbapc_sdp(const bluetooth_sdp_pce_record* rec) {
if (!status) {
get_legacy_stack_sdp_api()->handle.SDP_DeleteRecord(sdp_handle);
sdp_handle = 0;
- LOG_ERROR("%s() FAILED", __func__);
+ log::error("FAILED");
return sdp_handle;
}
bta_sys_add_uuid(service); /* UUID_SERVCLASS_PBAP_PCE */
- LOG_VERBOSE("%s(): SDP Registered (handle 0x%08x)", __func__, sdp_handle);
+ log::verbose("SDP Registered (handle 0x{:08x})", sdp_handle);
return sdp_handle;
}
@@ -645,7 +649,7 @@ static int add_pbaps_sdp(const bluetooth_sdp_pse_record* rec) {
sdp_handle = get_legacy_stack_sdp_api()->handle.SDP_CreateRecord();
if (sdp_handle == 0) {
- LOG_ERROR("Unable to register PBAP Server Service");
+ log::error("Unable to register PBAP Server Service");
return sdp_handle;
}
@@ -688,8 +692,8 @@ static int add_pbaps_sdp(const bluetooth_sdp_pse_record* rec) {
status &= get_legacy_stack_sdp_api()->handle.SDP_AddAttribute(
sdp_handle, ATTR_ID_SUPPORTED_REPOSITORIES, UINT_DESC_TYPE, (uint32_t)1,
(uint8_t*)&supported_repositories_1_1);
- LOG_VERBOSE(" supported_repositories_1_1: 0x%x",
- supported_repositories_1_1);
+ log::verbose("supported_repositories_1_1: 0x{:x}",
+ supported_repositories_1_1);
sdp_save_local_pse_record_attributes(
rec->hdr.rfcomm_channel_number, rec->hdr.l2cap_psm,
rec->hdr.profile_version, rec->supported_features,
@@ -754,10 +758,10 @@ static int add_pbaps_sdp(const bluetooth_sdp_pse_record* rec) {
if (!status) {
get_legacy_stack_sdp_api()->handle.SDP_DeleteRecord(sdp_handle);
sdp_handle = 0;
- LOG_ERROR("%s() FAILED", __func__);
+ log::error("FAILED");
} else {
bta_sys_add_uuid(service); /* UUID_SERVCLASS_MESSAGE_ACCESS */
- LOG_VERBOSE("%s(): SDP Registered (handle 0x%08x)", __func__, sdp_handle);
+ log::verbose("SDP Registered (handle 0x{:08x})", sdp_handle);
}
return sdp_handle;
}
@@ -780,7 +784,7 @@ static int add_opps_sdp(const bluetooth_sdp_ops_record* rec) {
sdp_handle = get_legacy_stack_sdp_api()->handle.SDP_CreateRecord();
if (sdp_handle == 0) {
- LOG_ERROR("Unable to register Object Push Server Service");
+ log::error("Unable to register Object Push Server Service");
return sdp_handle;
}
@@ -837,14 +841,14 @@ static int add_opps_sdp(const bluetooth_sdp_ops_record* rec) {
if (!status) {
get_legacy_stack_sdp_api()->handle.SDP_DeleteRecord(sdp_handle);
sdp_handle = 0;
- LOG_ERROR("%s() FAILED", __func__);
+ log::error("FAILED");
} else {
/* set class of device */
cod.service = BTM_COD_SERVICE_OBJ_TRANSFER;
utl_set_device_class(&cod, BTA_UTL_SET_COD_SERVICE_CLASS);
bta_sys_add_uuid(service); /* UUID_SERVCLASS_OBEX_OBJECT_PUSH */
- LOG_VERBOSE("%s(): SDP Registered (handle 0x%08x)", __func__, sdp_handle);
+ log::verbose("SDP Registered (handle 0x{:08x})", sdp_handle);
}
return sdp_handle;
}
@@ -860,7 +864,7 @@ static int add_saps_sdp(const bluetooth_sdp_sap_record* rec) {
sdp_handle = get_legacy_stack_sdp_api()->handle.SDP_CreateRecord();
if (sdp_handle == 0) {
- LOG_ERROR("Unable to register SAPS Service");
+ log::error("Unable to register SAPS Service");
return sdp_handle;
}
@@ -898,10 +902,10 @@ static int add_saps_sdp(const bluetooth_sdp_sap_record* rec) {
if (!status) {
get_legacy_stack_sdp_api()->handle.SDP_DeleteRecord(sdp_handle);
sdp_handle = 0;
- LOG_ERROR("%s(): FAILED deleting record", __func__);
+ log::error("FAILED deleting record");
} else {
bta_sys_add_uuid(UUID_SERVCLASS_SAP);
- LOG_VERBOSE("%s(): SDP Registered (handle 0x%08x)", __func__, sdp_handle);
+ log::verbose("SDP Registered (handle 0x{:08x})", sdp_handle);
}
return sdp_handle;
}
@@ -916,7 +920,7 @@ static int add_mps_sdp(const bluetooth_sdp_mps_record* rec) {
sdp_handle = get_legacy_stack_sdp_api()->handle.SDP_CreateRecord();
if (sdp_handle == 0) {
- LOG_ERROR("Unable to register MPS record");
+ log::error("Unable to register MPS record");
return sdp_handle;
}
@@ -947,10 +951,10 @@ static int add_mps_sdp(const bluetooth_sdp_mps_record* rec) {
if (!status) {
get_legacy_stack_sdp_api()->handle.SDP_DeleteRecord(sdp_handle);
sdp_handle = 0;
- LOG_ERROR("%s() FAILED", __func__);
+ log::error("FAILED");
return sdp_handle;
}
bta_sys_add_uuid(service); /* UUID_SERVCLASS_MPS_SC */
- LOG_VERBOSE("%s(): SDP Registered (handle 0x%08x)", __func__, sdp_handle);
+ log::verbose("SDP Registered (handle 0x{:08x})", sdp_handle);
return sdp_handle;
}
diff --git a/system/btif/src/btif_sock.cc b/system/btif/src/btif_sock.cc
index ecf7f5f614..944297113a 100644
--- a/system/btif/src/btif_sock.cc
+++ b/system/btif/src/btif_sock.cc
@@ -22,6 +22,7 @@
#include <base/functional/callback.h>
#include <base/logging.h>
+#include <bluetooth/log.h>
#include <frameworks/proto_logging/stats/enums/bluetooth/enums.pb.h>
#include <hardware/bluetooth.h>
#include <hardware/bt_sock.h>
@@ -48,6 +49,7 @@ bool btif_get_address_type(const RawAddress& bda, tBLE_ADDR_TYPE* p_addr_type);
bool btif_get_device_type(const RawAddress& bda, int* p_device_type);
using bluetooth::Uuid;
+using namespace bluetooth;
static bt_status_t btsock_listen(btsock_type_t type, const char* service_name,
const Uuid* uuid, int channel, int* sock_fd,
@@ -105,32 +107,32 @@ bt_status_t btif_sock_init(uid_set_t* uid_set) {
btsock_thread_init();
thread_handle = btsock_thread_create(btsock_signaled, NULL);
if (thread_handle == -1) {
- LOG_ERROR("%s unable to create btsock_thread.", __func__);
+ log::error("unable to create btsock_thread.");
goto error;
}
status = btsock_rfc_init(thread_handle, uid_set);
if (status != BT_STATUS_SUCCESS) {
- LOG_ERROR("%s error initializing RFCOMM sockets: %d", __func__, status);
+ log::error("error initializing RFCOMM sockets: {}", status);
goto error;
}
status = btsock_l2cap_init(thread_handle, uid_set);
if (status != BT_STATUS_SUCCESS) {
- LOG_ERROR("%s error initializing L2CAP sockets: %d", __func__, status);
+ log::error("error initializing L2CAP sockets: {}", status);
goto error;
}
thread = thread_new("btif_sock");
if (!thread) {
- LOG_ERROR("%s error creating new thread.", __func__);
+ log::error("error creating new thread.");
btsock_rfc_cleanup();
goto error;
}
status = btsock_sco_init(thread);
if (status != BT_STATUS_SUCCESS) {
- LOG_ERROR("%s error initializing SCO sockets: %d", __func__, status);
+ log::error("error initializing SCO sockets: {}", status);
btsock_rfc_cleanup();
goto error;
}
@@ -160,8 +162,8 @@ void btif_sock_cleanup(void) {
void btif_sock_connection_logger(int state, int role, const RawAddress& addr,
int channel, const char* server_name) {
- LOG_INFO("address=%s, state=%d, role=%d, server_name=%s, channel=%d",
- ADDRESS_TO_LOGGABLE_CSTR(addr), state, role, server_name, channel);
+ log::info("address={}, state={}, role={}, server_name={}, channel={}",
+ ADDRESS_TO_LOGGABLE_CSTR(addr), state, role, server_name, channel);
uint8_t index = logger_index++ % SOCK_LOGGER_SIZE_MAX;
@@ -267,7 +269,6 @@ static bt_status_t btsock_listen(btsock_type_t type, const char* service_name,
*sock_fd = INVALID_FD;
bt_status_t status = BT_STATUS_FAIL;
- int original_channel = channel;
log_socket_connection_state(RawAddress::kEmpty, 0, type,
android::bluetooth::SocketConnectionstateEnum::
@@ -284,28 +285,15 @@ static bt_status_t btsock_listen(btsock_type_t type, const char* service_name,
btsock_l2cap_listen(service_name, channel, sock_fd, flags, app_uid);
break;
case BTSOCK_L2CAP_LE:
- if (flags & BTSOCK_FLAG_NO_SDP) {
- /* Set channel to zero so that it will be assigned */
- channel = 0;
- } else if (channel <= 0) {
- LOG_ERROR("%s: type BTSOCK_L2CAP_LE: invalid channel=%d", __func__,
- channel);
- break;
- }
- flags |= BTSOCK_FLAG_LE_COC;
- LOG_INFO(
-
- "%s: type=BTSOCK_L2CAP_LE, channel=0x%x, original=0x%x, flags=0x%x",
- __func__, channel, original_channel, flags);
- status =
- btsock_l2cap_listen(service_name, channel, sock_fd, flags, app_uid);
+ status = btsock_l2cap_listen(service_name, channel, sock_fd,
+ flags | BTSOCK_FLAG_LE_COC, app_uid);
break;
case BTSOCK_SCO:
status = btsock_sco_listen(sock_fd, flags);
break;
default:
- LOG_ERROR("%s unknown/unsupported socket type: %d", __func__, type);
+ log::error("unknown/unsupported socket type: {}", type);
status = BT_STATUS_UNSUPPORTED;
break;
}
@@ -328,7 +316,7 @@ static bt_status_t btsock_connect(const RawAddress* bd_addr, btsock_type_t type,
CHECK(bd_addr != NULL);
CHECK(sock_fd != NULL);
- LOG_INFO("%s", __func__);
+ log::info("");
*sock_fd = INVALID_FD;
bt_status_t status = BT_STATUS_FAIL;
@@ -364,8 +352,8 @@ static bt_status_t btsock_connect(const RawAddress* bd_addr, btsock_type_t type,
BTA_DmAddBleDevice(*bd_addr, addr_type, device_type);
}
- LOG_INFO("%s: type=BTSOCK_L2CAP_LE, channel=0x%x, flags=0x%x", __func__,
- channel, flags);
+ log::info("type=BTSOCK_L2CAP_LE, channel=0x{:x}, flags=0x{:x}", channel,
+ flags);
status = btsock_l2cap_connect(bd_addr, channel, sock_fd, flags, app_uid);
break;
}
@@ -375,7 +363,7 @@ static bt_status_t btsock_connect(const RawAddress* bd_addr, btsock_type_t type,
break;
default:
- LOG_ERROR("%s unknown/unsupported socket type: %d", __func__, type);
+ log::error("unknown/unsupported socket type: {}", type);
status = BT_STATUS_UNSUPPORTED;
break;
}
@@ -408,8 +396,8 @@ static void btsock_signaled(int fd, int type, int flags, uint32_t user_id) {
btsock_l2cap_signaled(fd, flags, user_id);
break;
default:
- LOG(FATAL) << "Invalid socket type! type=" << type << " fd=" << fd
- << " flags=" << flags << " user_id=" << user_id;
+ log::fatal("Invalid socket type! type={} fd={} flags={} user_id={}", type,
+ fd, flags, user_id);
break;
}
}
@@ -421,8 +409,7 @@ static bt_status_t btsock_disconnect_all(const RawAddress* bd_addr) {
bt_status_t l2cap_status = btsock_l2cap_disconnect(bd_addr);
/* SCO is disconnected via btif_hf, so is not handled here. */
- LOG_INFO("%s: rfc status: %d, l2cap status: %d", __func__, rfc_status,
- l2cap_status);
+ log::info("rfc status: {}, l2cap status: {}", rfc_status, l2cap_status);
/* Return error status, if any. */
if (rfc_status == BT_STATUS_SUCCESS) {
diff --git a/system/btif/src/btif_sock_l2cap.cc b/system/btif/src/btif_sock_l2cap.cc
index 8e1150f086..0ba85551b2 100644
--- a/system/btif/src/btif_sock_l2cap.cc
+++ b/system/btif/src/btif_sock_l2cap.cc
@@ -16,6 +16,7 @@
*/
#include <base/logging.h>
+#include <bluetooth/log.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
@@ -38,6 +39,8 @@
#include "stack/include/bt_hdr.h"
#include "types/raw_address.h"
+using namespace bluetooth;
+
struct packet {
struct packet *next, *prev;
uint32_t len;
@@ -163,8 +166,8 @@ static char packet_put_head_l(l2cap_socket* sock, const void* data,
static char packet_put_tail_l(l2cap_socket* sock, const void* data,
uint32_t len) {
if (sock->bytes_buffered >= L2CAP_MAX_RX_BUFFER) {
- LOG_ERROR("Unable to add to buffer due to buffer overflow socket_id:%u",
- sock->id);
+ log::error("Unable to add to buffer due to buffer overflow socket_id:{}",
+ sock->id);
return false;
}
@@ -230,8 +233,8 @@ static void btsock_l2cap_free_l(l2cap_socket* sock) {
if (sock->app_fd != -1) {
close(sock->app_fd);
} else {
- LOG_INFO("Application has already closed l2cap socket socket_id:%u",
- sock->id);
+ log::info("Application has already closed l2cap socket socket_id:{}",
+ sock->id);
}
while (packet_get_head_l(sock, &buf, NULL)) osi_free(buf);
@@ -244,8 +247,8 @@ static void btsock_l2cap_free_l(l2cap_socket* sock) {
}
if ((sock->channel >= 0) && (sock->server)) {
BTA_JvFreeChannel(sock->channel, BTA_JV_CONN_TYPE_L2CAP_LE);
- LOG_INFO("Stopped L2CAP LE COC server socket_id:%u channel:%u", sock->id,
- sock->channel);
+ log::info("Stopped L2CAP LE COC server socket_id:{} channel:{}", sock->id,
+ sock->channel);
BTA_JvL2capStopServer(sock->channel, sock->id);
}
} else {
@@ -285,7 +288,7 @@ static l2cap_socket* btsock_l2cap_alloc_l(const char* name,
sock_type = SOCK_STREAM;
#endif
if (socketpair(AF_LOCAL, sock_type, 0, fds)) {
- LOG_ERROR("socketpair failed:%s", strerror(errno));
+ log::error("socketpair failed:{}", strerror(errno));
goto fail_sockpair;
}
@@ -328,7 +331,7 @@ static l2cap_socket* btsock_l2cap_alloc_l(const char* name,
sock->id++;
}
last_sock_id = sock->id;
- LOG_INFO("Allocated l2cap socket structure socket_id:%u", sock->id);
+ log::info("Allocated l2cap socket structure socket_id:{}", sock->id);
return sock;
fail_sockpair:
@@ -352,15 +355,15 @@ bt_status_t btsock_l2cap_cleanup() {
}
static inline bool send_app_psm_or_chan_l(l2cap_socket* sock) {
- LOG_INFO("Sending l2cap socket socket_id:%u channel:%d", sock->id,
- sock->channel);
+ log::info("Sending l2cap socket socket_id:{} channel:{}", sock->id,
+ sock->channel);
return sock_send_all(sock->our_fd, (const uint8_t*)&sock->channel,
sizeof(sock->channel)) == sizeof(sock->channel);
}
static bool send_app_err_code(l2cap_socket* sock, tBTA_JV_L2CAP_REASON code) {
- LOG_INFO("Sending l2cap failure reason socket_id:%u reason code:%d", sock->id,
- code);
+ log::info("Sending l2cap failure reason socket_id:{} reason code:{}",
+ sock->id, code);
int err_channel = 0;
if (sock_send_all(sock->our_fd, (const uint8_t*)&err_channel,
sizeof(err_channel)) != sizeof(err_channel)) {
@@ -388,7 +391,7 @@ static bool send_app_connect_signal(int fd, const RawAddress* addr, int channel,
return true;
}
- LOG_ERROR("Unable to send data to socket fd:%d send_fd:%d", fd, send_fd);
+ log::error("Unable to send data to socket fd:{} send_fd:{}", fd, send_fd);
return false;
}
@@ -399,12 +402,12 @@ static void on_srv_l2cap_listen_started(tBTA_JV_L2CAP_START* p_start,
std::unique_lock<std::mutex> lock(state_lock);
sock = btsock_l2cap_find_by_id_l(id);
if (!sock) {
- LOG_ERROR("Unable to find l2cap socket with socket_id:%u", id);
+ log::error("Unable to find l2cap socket with socket_id:{}", id);
return;
}
- if (p_start->status != BTA_JV_SUCCESS) {
- LOG_ERROR("Unable to start l2cap server socket_id:%u", sock->id);
+ if (p_start->status != tBTA_JV_STATUS::SUCCESS) {
+ log::error("Unable to start l2cap server socket_id:{}", sock->id);
btsock_l2cap_free_l(sock);
return;
}
@@ -427,7 +430,7 @@ static void on_srv_l2cap_listen_started(tBTA_JV_L2CAP_START* p_start,
if (!sock->server_psm_sent) {
if (!send_app_psm_or_chan_l(sock)) {
// closed
- LOG_INFO("Unable to send socket to application socket_id:%u", sock->id);
+ log::info("Unable to send socket to application socket_id:{}", sock->id);
btsock_l2cap_free_l(sock);
} else {
sock->server_psm_sent = true;
@@ -441,12 +444,12 @@ static void on_cl_l2cap_init(tBTA_JV_L2CAP_CL_INIT* p_init, uint32_t id) {
std::unique_lock<std::mutex> lock(state_lock);
sock = btsock_l2cap_find_by_id_l(id);
if (!sock) {
- LOG_ERROR("Unable to find l2cap socket with socket_id:%u", id);
+ log::error("Unable to find l2cap socket with socket_id:{}", id);
return;
}
- if (p_init->status != BTA_JV_SUCCESS) {
- LOG_ERROR("Initialization status failed socket_id:%u", id);
+ if (p_init->status != tBTA_JV_STATUS::SUCCESS) {
+ log::error("Initialization status failed socket_id:{}", id);
btsock_l2cap_free_l(sock);
return;
}
@@ -512,15 +515,15 @@ static void on_cl_l2cap_psm_connect_l(tBTA_JV_L2CAP_OPEN* p_open,
sock->tx_mtu = p_open->tx_mtu;
if (!send_app_psm_or_chan_l(sock)) {
- LOG_ERROR("Unable to send l2cap socket to application socket_id:%u",
- sock->id);
+ log::error("Unable to send l2cap socket to application socket_id:{}",
+ sock->id);
return;
}
if (!send_app_connect_signal(sock->our_fd, &sock->addr, sock->channel, 0, -1,
sock->rx_mtu, p_open->tx_mtu)) {
- LOG_ERROR("Unable to connect l2cap socket to application socket_id:%u",
- sock->id);
+ log::error("Unable to connect l2cap socket to application socket_id:{}",
+ sock->id);
return;
}
@@ -539,7 +542,7 @@ static void on_cl_l2cap_psm_connect_l(tBTA_JV_L2CAP_OPEN* p_open,
// start monitoring the socketpair to get call back when app writing data
btsock_thread_add_fd(pth, sock->our_fd, BTSOCK_L2CAP, SOCK_THREAD_FD_RD,
sock->id);
- LOG_INFO("Connected l2cap socket socket_id:%u", sock->id);
+ log::info("Connected l2cap socket socket_id:{}", sock->id);
sock->connected = true;
}
@@ -551,20 +554,20 @@ static void on_l2cap_connect(tBTA_JV* p_data, uint32_t id) {
std::unique_lock<std::mutex> lock(state_lock);
sock = btsock_l2cap_find_by_id_l(id);
if (!sock) {
- LOG_ERROR("Unable to find l2cap socket with socket_id:%u", id);
+ log::error("Unable to find l2cap socket with socket_id:{}", id);
return;
}
sock->tx_mtu = le_open->tx_mtu;
- if (psm_open->status == BTA_JV_SUCCESS) {
+ if (psm_open->status == tBTA_JV_STATUS::SUCCESS) {
if (!sock->server) {
on_cl_l2cap_psm_connect_l(psm_open, sock);
} else {
on_srv_l2cap_psm_connect_l(psm_open, sock);
}
} else {
- LOG_ERROR("Unable to open socket after receiving connection socket_id:%u",
- sock->id);
+ log::error("Unable to open socket after receiving connection socket_id:{}",
+ sock->id);
btsock_l2cap_free_l(sock);
}
}
@@ -575,8 +578,8 @@ static void on_l2cap_close(tBTA_JV_L2CAP_CLOSE* p_close, uint32_t id) {
std::unique_lock<std::mutex> lock(state_lock);
sock = btsock_l2cap_find_by_id_l(id);
if (!sock) {
- LOG_INFO(
- "Unable to find probably already closed l2cap socket with socket_id:%u",
+ log::info(
+ "Unable to find probably already closed l2cap socket with socket_id:{}",
id);
return;
}
@@ -594,8 +597,8 @@ static void on_l2cap_close(tBTA_JV_L2CAP_CLOSE* p_close, uint32_t id) {
: android::bluetooth::SOCKET_ROLE_CONNECTION);
if (!send_app_err_code(sock, p_close->reason)) {
- LOG_ERROR("Unable to send l2cap socket to application socket_id:%u",
- sock->id);
+ log::error("Unable to send l2cap socket to application socket_id:{}",
+ sock->id);
}
// TODO: This does not seem to be called...
// I'm not sure if this will be called for non-server sockets?
@@ -611,15 +614,15 @@ static void on_l2cap_outgoing_congest(tBTA_JV_L2CAP_CONG* p, uint32_t id) {
std::unique_lock<std::mutex> lock(state_lock);
sock = btsock_l2cap_find_by_id_l(id);
if (!sock) {
- LOG_ERROR("Unable to find l2cap socket with socket_id:%u", id);
+ log::error("Unable to find l2cap socket with socket_id:{}", id);
return;
}
sock->outgoing_congest = p->cong ? 1 : 0;
if (!sock->outgoing_congest) {
- LOG_VERBOSE("Monitoring l2cap socket for outgoing data socket_id:%u",
- sock->id);
+ log::verbose("Monitoring l2cap socket for outgoing data socket_id:{}",
+ sock->id);
btsock_thread_add_fd(pth, sock->our_fd, BTSOCK_L2CAP, SOCK_THREAD_FD_RD,
sock->id);
}
@@ -629,7 +632,7 @@ static void on_l2cap_write_done(uint16_t len, uint32_t id) {
std::unique_lock<std::mutex> lock(state_lock);
l2cap_socket* sock = btsock_l2cap_find_by_id_l(id);
if (!sock) {
- LOG_ERROR("Unable to find l2cap socket with socket_id:%u", id);
+ log::error("Unable to find l2cap socket with socket_id:{}", id);
return;
}
@@ -638,7 +641,7 @@ static void on_l2cap_write_done(uint16_t len, uint32_t id) {
btsock_thread_add_fd(pth, sock->our_fd, BTSOCK_L2CAP, SOCK_THREAD_FD_RD,
sock->id);
} else {
- LOG_INFO("Socket congestion on socket_id:%u", sock->id);
+ log::info("Socket congestion on socket_id:{}", sock->id);
}
sock->tx_bytes += len;
@@ -654,7 +657,7 @@ static void on_l2cap_data_ind(tBTA_JV* evt, uint32_t id) {
std::unique_lock<std::mutex> lock(state_lock);
sock = btsock_l2cap_find_by_id_l(id);
if (!sock) {
- LOG_ERROR("Unable to find l2cap socket with socket_id:%u", id);
+ log::error("Unable to find l2cap socket with socket_id:{}", id);
return;
}
@@ -662,17 +665,18 @@ static void on_l2cap_data_ind(tBTA_JV* evt, uint32_t id) {
uint32_t count;
- if (BTA_JvL2capReady(sock->handle, &count) == BTA_JV_SUCCESS) {
+ if (BTA_JvL2capReady(sock->handle, &count) == tBTA_JV_STATUS::SUCCESS) {
std::vector<uint8_t> buffer(count);
if (BTA_JvL2capRead(sock->handle, sock->id, buffer.data(), count) ==
- BTA_JV_SUCCESS) {
+ tBTA_JV_STATUS::SUCCESS) {
if (packet_put_tail_l(sock, buffer.data(), count)) {
bytes_read = count;
btsock_thread_add_fd(pth, sock->our_fd, BTSOCK_L2CAP, SOCK_THREAD_FD_WR,
sock->id);
} else { // connection must be dropped
- LOG_WARN("Closing socket as unable to push data to socket socket_id:%u",
- sock->id);
+ log::warn(
+ "Closing socket as unable to push data to socket socket_id:{}",
+ sock->id);
BTA_JvL2capClose(sock->handle);
btsock_l2cap_free_l(sock);
return;
@@ -721,8 +725,8 @@ static void btsock_l2cap_cbk(tBTA_JV_EVT event, tBTA_JV* p_data,
break;
default:
- LOG_ERROR("Unhandled event:%hu l2cap_socket_id:%u", event,
- l2cap_socket_id);
+ log::error("Unhandled event:{} l2cap_socket_id:{}", event,
+ l2cap_socket_id);
break;
}
}
@@ -743,7 +747,7 @@ void on_l2cap_psm_assigned(int id, int psm) {
std::unique_lock<std::mutex> lock(state_lock);
l2cap_socket* sock = btsock_l2cap_find_by_id_l(id);
if (!sock) {
- LOG_ERROR("Unable to find l2cap socket with socket_id:%u", id);
+ log::error("Unable to find l2cap socket with socket_id:{}", id);
return;
}
@@ -782,15 +786,25 @@ static bt_status_t btsock_l2cap_listen_or_connect(const char* name,
int channel, int* sock_fd,
int flags, char listen,
int app_uid) {
+ if (!is_inited()) return BT_STATUS_NOT_READY;
+
bool is_le_coc = (flags & BTSOCK_FLAG_LE_COC) != 0;
+ if (is_le_coc && listen) {
+ if (flags & BTSOCK_FLAG_NO_SDP) {
+ /* For LE COC server; set channel to zero so that it will be assigned */
+ channel = 0;
+ } else if (channel <= 0) {
+ log::error("type BTSOCK_L2CAP_LE: invalid channel={}", channel);
+ return BT_STATUS_FAIL;
+ }
+ }
+
if (!sock_fd) {
- LOG_INFO("Invalid socket descriptor");
+ log::info("Invalid socket descriptor");
return BT_STATUS_PARM_INVALID;
}
- if (!is_inited()) return BT_STATUS_NOT_READY;
-
// TODO: This is kind of bad to lock here, but it is needed for the current
// design.
std::unique_lock<std::mutex> lock(state_lock);
@@ -925,7 +939,7 @@ void btsock_l2cap_signaled(int fd, int flags, uint32_t user_id) {
if (count > sock->tx_mtu) {
/* This can't happen thanks to check in BluetoothSocket.java but leave
* this in case this socket is ever used anywhere else*/
- LOG(ERROR) << "recv more than MTU. Data will be lost: " << count;
+ log::error("recv more than MTU. Data will be lost: {}", count);
count = sock->tx_mtu;
}
diff --git a/system/btif/src/btif_sock_rfc.cc b/system/btif/src/btif_sock_rfc.cc
index cff0648f6f..e20f39ea73 100644
--- a/system/btif/src/btif_sock_rfc.cc
+++ b/system/btif/src/btif_sock_rfc.cc
@@ -18,6 +18,7 @@
#define LOG_TAG "bt_btif_sock_rfcomm"
+#include <bluetooth/log.h>
#include <frameworks/proto_logging/stats/enums/bluetooth/enums.pb.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
@@ -47,6 +48,7 @@
#include "types/raw_address.h"
using bluetooth::Uuid;
+using namespace bluetooth;
// Maximum number of RFCOMM channels (1-30 inclusive).
#define MAX_RFC_CHANNEL 30
@@ -139,7 +141,7 @@ void btsock_rfc_cleanup(void) {
uid_set = NULL;
- LOG_DEBUG("cleanup finished");
+ log::debug("cleanup finished");
}
static rfc_slot_t* find_free_slot(void) {
@@ -149,8 +151,6 @@ static rfc_slot_t* find_free_slot(void) {
}
static rfc_slot_t* find_rfc_slot_by_id(uint32_t id) {
- CHECK(id != 0);
-
for (size_t i = 0; i < ARRAY_SIZE(rfc_slots); ++i)
if (rfc_slots[i].id == id) return &rfc_slots[i];
@@ -173,7 +173,7 @@ static rfc_slot_t* find_rfc_slot_by_pending_sdp(void) {
static bool is_requesting_sdp(void) {
for (size_t i = 0; i < ARRAY_SIZE(rfc_slots); ++i)
if (rfc_slots[i].id && rfc_slots[i].f.doing_sdp_request) {
- LOG_INFO("slot id %u is doing sdp request", rfc_slots[i].id);
+ log::info("slot id {} is doing sdp request", rfc_slots[i].id);
return true;
}
return false;
@@ -194,13 +194,13 @@ static rfc_slot_t* alloc_rfc_slot(const RawAddress* addr, const char* name,
rfc_slot_t* slot = find_free_slot();
if (!slot) {
- LOG_ERROR("%s unable to find free RFCOMM slot.", __func__);
+ log::error("unable to find free RFCOMM slot.");
return NULL;
}
int fds[2] = {INVALID_FD, INVALID_FD};
if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds) == -1) {
- LOG_ERROR("%s error creating socketpair: %s", __func__, strerror(errno));
+ log::error("error creating socketpair: {}", strerror(errno));
return NULL;
}
@@ -241,7 +241,7 @@ static rfc_slot_t* create_srv_accept_rfc_slot(rfc_slot_t* srv_rs,
rfc_slot_t* accept_rs = alloc_rfc_slot(
addr, srv_rs->service_name, srv_rs->service_uuid, srv_rs->scn, 0, false);
if (!accept_rs) {
- LOG_ERROR("%s unable to allocate RFCOMM slot.", __func__);
+ log::error("unable to allocate RFCOMM slot.");
return NULL;
}
@@ -275,7 +275,7 @@ bt_status_t btsock_rfc_control_req(uint8_t dlci, const RawAddress& bd_addr,
RFCOMM_ControlReqFromBTSOCK(dlci, bd_addr, modem_signal, break_signal,
discard_buffers, break_signal_seq, fc);
if (status != PORT_SUCCESS) {
- LOG_WARN("failed to send control parameters, status=%d", status);
+ log::warn("failed to send control parameters, status={}", status);
return BT_STATUS_FAIL;
}
return BT_STATUS_SUCCESS;
@@ -296,7 +296,7 @@ bt_status_t btsock_rfc_listen(const char* service_name,
// functions on RFCOMM sockets before initializing the module. Probably
// should be an assert.
if (!is_init_done()) {
- LOG_ERROR("BT not ready");
+ log::error("BT not ready");
return BT_STATUS_NOT_READY;
}
@@ -318,11 +318,11 @@ bt_status_t btsock_rfc_listen(const char* service_name,
rfc_slot_t* slot =
alloc_rfc_slot(NULL, service_name, *service_uuid, channel, flags, true);
if (!slot) {
- LOG_ERROR("unable to allocate RFCOMM slot");
+ log::error("unable to allocate RFCOMM slot");
return BT_STATUS_FAIL;
}
- LOG_INFO("Adding listening socket service_name: %s - channel: %d",
- service_name, channel);
+ log::info("Adding listening socket service_name: {} - channel: {}",
+ service_name, channel);
BTA_JvGetChannelId(BTA_JV_CONN_TYPE_RFCOMM, slot->id, channel);
*sock_fd = slot->app_fd; // Transfer ownership of fd to caller.
/*TODO:
@@ -354,7 +354,7 @@ bt_status_t btsock_rfc_connect(const RawAddress* bd_addr,
// functions on RFCOMM sockets before initializing the module. Probably should
// be an assert.
if (!is_init_done()) {
- LOG_ERROR("BT not ready");
+ log::error("BT not ready");
return BT_STATUS_NOT_READY;
}
@@ -363,8 +363,8 @@ bt_status_t btsock_rfc_connect(const RawAddress* bd_addr,
rfc_slot_t* slot =
alloc_rfc_slot(bd_addr, NULL, *service_uuid, channel, flags, false);
if (!slot) {
- LOG_ERROR("unable to allocate RFCOMM slot. bd_addr:%s",
- ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
+ log::error("unable to allocate RFCOMM slot. bd_addr:{}",
+ ADDRESS_TO_LOGGABLE_CSTR(*bd_addr));
return BT_STATUS_FAIL;
}
@@ -372,23 +372,24 @@ bt_status_t btsock_rfc_connect(const RawAddress* bd_addr,
tBTA_JV_STATUS ret =
BTA_JvRfcommConnect(slot->security, slot->role, slot->scn, slot->addr,
rfcomm_cback, slot->id);
- if (ret != BTA_JV_SUCCESS) {
- LOG_ERROR(
- "unable to initiate RFCOMM connection. status:%d, scn:%d, bd_addr:%s",
- ret, slot->scn, ADDRESS_TO_LOGGABLE_CSTR(slot->addr));
+ if (ret != tBTA_JV_STATUS::SUCCESS) {
+ log::error(
+ "unable to initiate RFCOMM connection. status:{}, scn:{}, bd_addr:{}",
+ bta_jv_status_text(ret), slot->scn,
+ ADDRESS_TO_LOGGABLE_CSTR(slot->addr));
cleanup_rfc_slot(slot);
return BT_STATUS_FAIL;
}
if (!send_app_scn(slot)) {
- LOG_ERROR("send_app_scn() failed, closing slot->id:%u", slot->id);
+ log::error("send_app_scn() failed, closing slot->id:{}", slot->id);
cleanup_rfc_slot(slot);
return BT_STATUS_FAIL;
}
} else {
- LOG_INFO("service_uuid:%s, bd_addr:%s, slot_id:%u",
- service_uuid->ToString().c_str(),
- ADDRESS_TO_LOGGABLE_CSTR(*bd_addr), slot->id);
+ log::info("service_uuid:{}, bd_addr:{}, slot_id:{}",
+ service_uuid->ToString(), ADDRESS_TO_LOGGABLE_CSTR(*bd_addr),
+ slot->id);
if (!is_requesting_sdp()) {
BTA_JvStartDiscovery(*bd_addr, 1, service_uuid, slot->id);
slot->f.pending_sdp_request = false;
@@ -479,8 +480,8 @@ static bool send_app_scn(rfc_slot_t* slot) {
// already sent, just return success.
return true;
}
- LOG_DEBUG("Sending scn for slot %u. bd_addr:%s", slot->id,
- ADDRESS_TO_LOGGABLE_CSTR(slot->addr));
+ log::debug("Sending scn for slot {}. bd_addr:{}", slot->id,
+ ADDRESS_TO_LOGGABLE_CSTR(slot->addr));
slot->scn_notified = true;
return sock_send_all(slot->fd, (const uint8_t*)&slot->scn,
sizeof(slot->scn)) == sizeof(slot->scn);
@@ -506,11 +507,11 @@ static void on_cl_rfc_init(tBTA_JV_RFCOMM_CL_INIT* p_init, uint32_t id) {
std::unique_lock<std::recursive_mutex> lock(slot_lock);
rfc_slot_t* slot = find_rfc_slot_by_id(id);
if (!slot) {
- LOG_ERROR("RFCOMM slot with id %u not found. p_init->status=%u", id,
- p_init->status);
- } else if (p_init->status != BTA_JV_SUCCESS) {
- LOG_WARN("INIT unsuccessful, status %u. Cleaning up slot with id %u",
- p_init->status, slot->id);
+ log::error("RFCOMM slot with id {} not found. p_init->status={}", id,
+ bta_jv_status_text(p_init->status).c_str());
+ } else if (p_init->status != tBTA_JV_STATUS::SUCCESS) {
+ log::warn("INIT unsuccessful, status {}. Cleaning up slot with id {}",
+ bta_jv_status_text(p_init->status).c_str(), slot->id);
cleanup_rfc_slot(slot);
} else {
slot->rfc_handle = p_init->handle;
@@ -522,11 +523,11 @@ static void on_srv_rfc_listen_started(tBTA_JV_RFCOMM_START* p_start,
std::unique_lock<std::recursive_mutex> lock(slot_lock);
rfc_slot_t* slot = find_rfc_slot_by_id(id);
if (!slot) {
- LOG_ERROR("RFCOMM slot with id %u not found", id);
+ log::error("RFCOMM slot with id {} not found", id);
return;
- } else if (p_start->status != BTA_JV_SUCCESS) {
- LOG_WARN("START unsuccessful, status %u. Cleaning up slot with id %u",
- p_start->status, slot->id);
+ } else if (p_start->status != tBTA_JV_STATUS::SUCCESS) {
+ log::warn("START unsuccessful, status {}. Cleaning up slot with id {}",
+ bta_jv_status_text(p_start->status).c_str(), slot->id);
cleanup_rfc_slot(slot);
return;
}
@@ -547,12 +548,12 @@ static void on_srv_rfc_listen_started(tBTA_JV_RFCOMM_START* p_start,
static uint32_t on_srv_rfc_connect(tBTA_JV_RFCOMM_SRV_OPEN* p_open,
uint32_t id) {
- LOG_VERBOSE("id:%u", id);
+ log::verbose("id:{}", id);
std::unique_lock<std::recursive_mutex> lock(slot_lock);
rfc_slot_t* accept_rs;
rfc_slot_t* srv_rs = find_rfc_slot_by_id(id);
if (!srv_rs) {
- LOG_ERROR("RFCOMM slot with id %u not found.", id);
+ log::error("RFCOMM slot with id {} not found.", id);
return 0;
}
@@ -584,17 +585,17 @@ static uint32_t on_srv_rfc_connect(tBTA_JV_RFCOMM_SRV_OPEN* p_open,
}
static void on_cli_rfc_connect(tBTA_JV_RFCOMM_OPEN* p_open, uint32_t id) {
- LOG_VERBOSE("id:%u", id);
+ log::verbose("id:{}", id);
std::unique_lock<std::recursive_mutex> lock(slot_lock);
rfc_slot_t* slot = find_rfc_slot_by_id(id);
if (!slot) {
- LOG_ERROR("RFCOMM slot with id %u not found.", id);
+ log::error("RFCOMM slot with id {} not found.", id);
return;
}
- if (p_open->status != BTA_JV_SUCCESS) {
- LOG_WARN("CONNECT unsuccessful, status %u. Cleaning up slot with id %u",
- p_open->status, slot->id);
+ if (p_open->status != tBTA_JV_STATUS::SUCCESS) {
+ log::warn("CONNECT unsuccessful, status {}. Cleaning up slot with id {}",
+ bta_jv_status_text(p_open->status).c_str(), slot->id);
cleanup_rfc_slot(slot);
return;
}
@@ -616,20 +617,19 @@ static void on_cli_rfc_connect(tBTA_JV_RFCOMM_OPEN* p_open, uint32_t id) {
if (send_app_connect_signal(slot->fd, &slot->addr, slot->scn, 0, -1)) {
slot->f.connected = true;
} else {
- LOG_ERROR("%s unable to send connect completion signal to caller.",
- __func__);
+ log::error("unable to send connect completion signal to caller.");
}
}
static void on_rfc_close(UNUSED_ATTR tBTA_JV_RFCOMM_CLOSE* p_close,
uint32_t id) {
- LOG_VERBOSE("id:%u", id);
+ log::verbose("id:{}", id);
std::unique_lock<std::recursive_mutex> lock(slot_lock);
// rfc_handle already closed when receiving rfcomm close event from stack.
rfc_slot_t* slot = find_rfc_slot_by_id(id);
if (!slot) {
- LOG_WARN("RFCOMM slot with id %u not found.", id);
+ log::warn("RFCOMM slot with id {} not found.", id);
return;
}
log_socket_connection_state(
@@ -642,9 +642,8 @@ static void on_rfc_close(UNUSED_ATTR tBTA_JV_RFCOMM_CLOSE* p_close,
}
static void on_rfc_write_done(tBTA_JV_RFCOMM_WRITE* p, uint32_t id) {
- if (p->status != BTA_JV_SUCCESS) {
- LOG_ERROR("%s error writing to RFCOMM socket with slot %u.", __func__,
- p->req_id);
+ if (p->status != tBTA_JV_STATUS::SUCCESS) {
+ log::error("error writing to RFCOMM socket with slot {}.", p->req_id);
return;
}
@@ -653,7 +652,7 @@ static void on_rfc_write_done(tBTA_JV_RFCOMM_WRITE* p, uint32_t id) {
rfc_slot_t* slot = find_rfc_slot_by_id(id);
if (!slot) {
- LOG_ERROR("RFCOMM slot with id %u not found.", id);
+ log::error("RFCOMM slot with id {} not found.", id);
return;
}
app_uid = slot->app_uid;
@@ -669,7 +668,7 @@ static void on_rfc_outgoing_congest(tBTA_JV_RFCOMM_CONG* p, uint32_t id) {
rfc_slot_t* slot = find_rfc_slot_by_id(id);
if (!slot) {
- LOG_ERROR("RFCOMM slot with id %u not found.", id);
+ log::error("RFCOMM slot with id {} not found.", id);
return;
}
@@ -685,9 +684,9 @@ static uint32_t rfcomm_cback(tBTA_JV_EVT event, tBTA_JV* p_data,
// Write events are too frequent to log at info level
if (event != BTA_JV_RFCOMM_WRITE_EVT) {
- LOG_INFO("handling event:%d id:%u", event, rfcomm_slot_id);
+ log::info("handling event:{} id:{}", event, rfcomm_slot_id);
} else {
- LOG_VERBOSE("handling event:%d id:%u", event, rfcomm_slot_id);
+ log::verbose("handling event:{} id:{}", event, rfcomm_slot_id);
}
switch (event) {
@@ -712,7 +711,8 @@ static uint32_t rfcomm_cback(tBTA_JV_EVT event, tBTA_JV* p_data,
break;
case BTA_JV_RFCOMM_CLOSE_EVT:
- LOG_VERBOSE("BTA_JV_RFCOMM_CLOSE_EVT: rfcomm_slot_id:%d", rfcomm_slot_id);
+ log::verbose("BTA_JV_RFCOMM_CLOSE_EVT: rfcomm_slot_id:{}",
+ rfcomm_slot_id);
on_rfc_close(&p_data->rfc_close, rfcomm_slot_id);
break;
@@ -729,27 +729,26 @@ static uint32_t rfcomm_cback(tBTA_JV_EVT event, tBTA_JV* p_data,
break;
default:
- LOG_ERROR("%s unhandled event %d, slot id: %u", __func__, event,
- rfcomm_slot_id);
+ log::error("unhandled event {}, slot id: {}", event, rfcomm_slot_id);
break;
}
return id;
}
static void jv_dm_cback(tBTA_JV_EVT event, tBTA_JV* p_data, uint32_t id) {
- LOG_INFO("handling event:%d, id:%u", event, id);
+ log::info("handling event:{}, id:{}", event, id);
switch (event) {
case BTA_JV_GET_SCN_EVT: {
std::unique_lock<std::recursive_mutex> lock(slot_lock);
rfc_slot_t* rs = find_rfc_slot_by_id(id);
if (!rs) {
- LOG_ERROR("RFCOMM slot with id %u not found. event:%d", id, event);
+ log::error("RFCOMM slot with id {} not found. event:{}", id, event);
break;
}
if (p_data->scn == 0) {
- LOG_ERROR(
- "Unable to allocate scn: all resources exhausted. slot found: %p",
- rs);
+ log::error(
+ "Unable to allocate scn: all resources exhausted. slot found: {}",
+ fmt::ptr(rs));
cleanup_rfc_slot(rs);
break;
}
@@ -757,7 +756,7 @@ static void jv_dm_cback(tBTA_JV_EVT event, tBTA_JV* p_data, uint32_t id) {
rs->scn = p_data->scn;
// Send channel ID to java layer
if (!send_app_scn(rs)) {
- LOG_WARN("send_app_scn() failed, closing rs->id:%d", rs->id);
+ log::warn("send_app_scn() failed, closing rs->id:{}", id);
cleanup_rfc_slot(rs);
break;
}
@@ -765,24 +764,24 @@ static void jv_dm_cback(tBTA_JV_EVT event, tBTA_JV* p_data, uint32_t id) {
if (rs->is_service_uuid_valid) {
// BTA_JvCreateRecordByUser will only create a record if a UUID is
// specified. RFC-only profiles
- BTA_JvCreateRecordByUser(rs->id);
+ BTA_JvCreateRecordByUser(id);
} else {
// If uuid is null, just allocate a RFC channel and start the RFCOMM
// thread needed for the java layer to get a RFCOMM channel.
// create_sdp_record() will be called from Java when it has received the
// RFCOMM and L2CAP channel numbers through the sockets.
- LOG_DEBUG(
+ log::debug(
"Since UUID is not valid; not setting SDP-record and just starting "
"the RFCOMM server");
// now start the rfcomm server after sdp & channel # assigned
BTA_JvRfcommStartServer(rs->security, rs->role, rs->scn,
- MAX_RFC_SESSION, rfcomm_cback, rs->id);
+ MAX_RFC_SESSION, rfcomm_cback, id);
}
break;
}
case BTA_JV_GET_PSM_EVT: {
- LOG_VERBOSE("Received PSM: 0x%04x", p_data->psm);
+ log::verbose("Received PSM: 0x{:04x}", p_data->psm);
on_l2cap_psm_assigned(id, p_data->psm);
break;
}
@@ -792,19 +791,19 @@ static void jv_dm_cback(tBTA_JV_EVT event, tBTA_JV* p_data, uint32_t id) {
rfc_slot_t* slot = find_rfc_slot_by_id(id);
if (!slot) {
- LOG_ERROR("RFCOMM slot with id %u not found. event:%d", id, event);
+ log::error("RFCOMM slot with id {} not found. event:{}", id, event);
break;
}
if (!create_server_sdp_record(slot)) {
- LOG_ERROR("cannot start server, slot found: %p", slot);
+ log::error("cannot start server, slot found: {}", fmt::ptr(slot));
cleanup_rfc_slot(slot);
break;
}
// Start the rfcomm server after sdp & channel # assigned.
BTA_JvRfcommStartServer(slot->security, slot->role, slot->scn,
- MAX_RFC_SESSION, rfcomm_cback, slot->id);
+ MAX_RFC_SESSION, rfcomm_cback, id);
break;
}
@@ -823,7 +822,7 @@ static void jv_dm_cback(tBTA_JV_EVT event, tBTA_JV* p_data, uint32_t id) {
}
default:
- LOG_DEBUG("unhandled event:%d, slot id:%d", event, id);
+ log::debug("unhandled event:{}, slot id:{}", event, id);
break;
}
}
@@ -831,33 +830,33 @@ static void jv_dm_cback(tBTA_JV_EVT event, tBTA_JV* p_data, uint32_t id) {
static void handle_discovery_comp(tBTA_JV_STATUS status, int scn, uint32_t id) {
rfc_slot_t* slot = find_rfc_slot_by_id(id);
if (!slot) {
- LOG_ERROR(
- "RFCOMM slot with id %u not found. event: BTA_JV_DISCOVERY_COMP_EVT",
+ log::error(
+ "RFCOMM slot with id {} not found. event: BTA_JV_DISCOVERY_COMP_EVT",
id);
return;
}
if (!slot->f.doing_sdp_request) {
- LOG_ERROR(
- "SDP response returned but RFCOMM slot %d did not request SDP record.",
+ log::error(
+ "SDP response returned but RFCOMM slot {} did not request SDP record.",
id);
return;
}
- if (status != BTA_JV_SUCCESS || !scn) {
- LOG_ERROR(
- "SDP service discovery completed for slot id: %u with the result "
- "status: %u, scn: %d",
- id, status, scn);
+ if (status != tBTA_JV_STATUS::SUCCESS || !scn) {
+ log::error(
+ "SDP service discovery completed for slot id: {} with the result "
+ "status: {}, scn: {}",
+ id, bta_jv_status_text(status).c_str(), scn);
cleanup_rfc_slot(slot);
return;
}
if (BTA_JvRfcommConnect(slot->security, slot->role, scn, slot->addr,
- rfcomm_cback, slot->id) != BTA_JV_SUCCESS) {
- LOG_WARN(
+ rfcomm_cback, slot->id) != tBTA_JV_STATUS::SUCCESS) {
+ log::warn(
"BTA_JvRfcommConnect() returned BTA_JV_FAILURE for RFCOMM slot with "
- "id: %u",
+ "id: {}",
id);
cleanup_rfc_slot(slot);
return;
@@ -867,7 +866,7 @@ static void handle_discovery_comp(tBTA_JV_STATUS status, int scn, uint32_t id) {
slot->f.doing_sdp_request = false;
if (!send_app_scn(slot)) {
- LOG_WARN("send_app_scn() failed, closing slot->id %u", slot->id);
+ log::warn("send_app_scn() failed, closing slot->id {}", slot->id);
cleanup_rfc_slot(slot);
return;
}
@@ -889,8 +888,7 @@ static sent_status_t send_data_to_app(int fd, BT_HDR* p_buf) {
if (sent == -1) {
if (errno == EAGAIN || errno == EWOULDBLOCK) return SENT_NONE;
- LOG_ERROR("%s error writing RFCOMM data back to app: %s", __func__,
- strerror(errno));
+ log::error("error writing RFCOMM data back to app: {}", strerror(errno));
return SENT_FAILED;
}
@@ -926,8 +924,8 @@ static bool flush_incoming_que_on_wr_signal(rfc_slot_t* slot) {
// app is ready to receive data, tell stack to start the data flow
// fix me: need a jv flow control api to serialize the call in stack
- LOG_VERBOSE(
- "enable data flow, rfc_handle:0x%x, rfc_port_handle:0x%x, user_id:%d",
+ log::verbose(
+ "enable data flow, rfc_handle:0x{:x}, rfc_port_handle:0x{:x}, user_id:{}",
slot->rfc_handle, slot->rfc_port_handle, slot->id);
PORT_FlowControl_MaxCredit(slot->rfc_port_handle, true);
return true;
@@ -938,7 +936,7 @@ void btsock_rfc_signaled(UNUSED_ATTR int fd, int flags, uint32_t id) {
std::unique_lock<std::recursive_mutex> lock(slot_lock);
rfc_slot_t* slot = find_rfc_slot_by_id(id);
if (!slot) {
- LOG_ERROR("RFCOMM slot with id %u not found.", id);
+ log::error("RFCOMM slot with id {} not found.", id);
return;
}
@@ -952,10 +950,9 @@ void btsock_rfc_signaled(UNUSED_ATTR int fd, int flags, uint32_t id) {
BTA_JvRfcommWrite(slot->rfc_handle, slot->id);
}
} else {
- LOG_ERROR(
- "%s socket signaled for read while disconnected, slot: %d, "
- "channel: %d",
- __func__, slot->id, slot->scn);
+ log::error(
+ "socket signaled for read while disconnected, slot: {}, channel: {}",
+ slot->id, slot->scn);
need_close = true;
}
}
@@ -963,10 +960,10 @@ void btsock_rfc_signaled(UNUSED_ATTR int fd, int flags, uint32_t id) {
if (flags & SOCK_THREAD_FD_WR) {
// App is ready to receive more data, tell stack to enable data flow.
if (!slot->f.connected || !flush_incoming_que_on_wr_signal(slot)) {
- LOG_ERROR(
- "%s socket signaled for write while disconnected (or write "
- "failure), slot: %d, channel: %d",
- __func__, slot->id, slot->scn);
+ log::error(
+ "socket signaled for write while disconnected (or write failure), "
+ "slot: {}, channel: {}",
+ slot->id, slot->scn);
need_close = true;
}
}
@@ -986,7 +983,7 @@ int bta_co_rfc_data_incoming(uint32_t id, BT_HDR* p_buf) {
std::unique_lock<std::recursive_mutex> lock(slot_lock);
rfc_slot_t* slot = find_rfc_slot_by_id(id);
if (!slot) {
- LOG_ERROR("RFCOMM slot with id %u not found.", id);
+ log::error("RFCOMM slot with id {} not found.", id);
return 0;
}
@@ -1027,13 +1024,13 @@ int bta_co_rfc_data_outgoing_size(uint32_t id, int* size) {
std::unique_lock<std::recursive_mutex> lock(slot_lock);
rfc_slot_t* slot = find_rfc_slot_by_id(id);
if (!slot) {
- LOG_ERROR("RFCOMM slot with id %u not found.", id);
+ log::error("RFCOMM slot with id {} not found.", id);
return false;
}
if (ioctl(slot->fd, FIONREAD, size) != 0) {
- LOG_ERROR("%s unable to determine bytes remaining to be read on fd %d: %s",
- __func__, slot->fd, strerror(errno));
+ log::error("unable to determine bytes remaining to be read on fd {}: {}",
+ slot->fd, strerror(errno));
cleanup_rfc_slot(slot);
return false;
}
@@ -1045,7 +1042,7 @@ int bta_co_rfc_data_outgoing(uint32_t id, uint8_t* buf, uint16_t size) {
std::unique_lock<std::recursive_mutex> lock(slot_lock);
rfc_slot_t* slot = find_rfc_slot_by_id(id);
if (!slot) {
- LOG_ERROR("RFCOMM slot with id %u not found.", id);
+ log::error("RFCOMM slot with id {} not found.", id);
return false;
}
@@ -1053,8 +1050,7 @@ int bta_co_rfc_data_outgoing(uint32_t id, uint8_t* buf, uint16_t size) {
OSI_NO_INTR(received = recv(slot->fd, buf, size, 0));
if (received != size) {
- LOG_ERROR("%s error receiving RFCOMM data from app: %s", __func__,
- strerror(errno));
+ log::error("error receiving RFCOMM data from app: {}", strerror(errno));
cleanup_rfc_slot(slot);
return false;
}
@@ -1065,7 +1061,7 @@ int bta_co_rfc_data_outgoing(uint32_t id, uint8_t* buf, uint16_t size) {
bt_status_t btsock_rfc_disconnect(const RawAddress* bd_addr) {
CHECK(bd_addr != NULL);
if (!is_init_done()) {
- LOG_ERROR("BT not ready");
+ log::error("BT not ready");
return BT_STATUS_NOT_READY;
}
diff --git a/system/btif/src/btif_sock_sco.cc b/system/btif/src/btif_sock_sco.cc
index a847323e77..66fee0349f 100644
--- a/system/btif/src/btif_sock_sco.cc
+++ b/system/btif/src/btif_sock_sco.cc
@@ -18,6 +18,7 @@
#define LOG_TAG "bt_btif_sock_sco"
+#include <bluetooth/log.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
@@ -54,6 +55,8 @@
// socket_read_ready_cb() - local host closed SCO socket
// disconnect_completed_cb() - connection terminated
+using namespace bluetooth;
+
typedef struct {
uint16_t sco_handle;
socket_t* socket;
@@ -134,14 +137,13 @@ static sco_socket_t* sco_socket_establish_locked(bool is_listening,
tBTM_STATUS status;
enh_esco_params_t params;
if (socketpair(AF_LOCAL, SOCK_STREAM, 0, pair) == -1) {
- LOG_ERROR("%s unable to allocate socket pair: %s", __func__,
- strerror(errno));
+ log::error("unable to allocate socket pair: {}", strerror(errno));
goto error;
}
sco_socket = sco_socket_new();
if (!sco_socket) {
- LOG_ERROR("%s unable to allocate new SCO socket.", __func__);
+ log::error("unable to allocate new SCO socket.");
goto error;
}
@@ -150,14 +152,13 @@ static sco_socket_t* sco_socket_establish_locked(bool is_listening,
&sco_socket->sco_handle, connect_completed_cb,
disconnect_completed_cb);
if (status != BTM_CMD_STARTED) {
- LOG_ERROR("%s unable to create SCO socket: %d", __func__, status);
+ log::error("unable to create SCO socket: {}", status);
goto error;
}
socket = socket_new_from_fd(pair[1]);
if (!socket) {
- LOG_ERROR("%s unable to allocate socket from file descriptor %d.", __func__,
- pair[1]);
+ log::error("unable to allocate socket from file descriptor {}.", pair[1]);
goto error;
}
@@ -222,22 +223,19 @@ static void connection_request_cb(tBTM_ESCO_EVT event,
sco_socket_t* new_sco_socket;
if (!sco_socket) {
- LOG_ERROR("%s unable to find sco_socket for handle: %hu", __func__,
- conn_data->sco_inx);
+ log::error("unable to find sco_socket for handle: {}", conn_data->sco_inx);
goto error;
}
if (sco_socket != listen_sco_socket) {
- LOG_ERROR(
-
- "%s received connection request on non-listening socket handle: %hu",
- __func__, conn_data->sco_inx);
+ log::error("received connection request on non-listening socket handle: {}",
+ conn_data->sco_inx);
goto error;
}
new_sco_socket = sco_socket_establish_locked(true, NULL, &client_fd);
if (!new_sco_socket) {
- LOG_ERROR("%s unable to allocate new sco_socket.", __func__);
+ log::error("unable to allocate new sco_socket.");
goto error;
}
@@ -255,8 +253,7 @@ static void connection_request_cb(tBTM_ESCO_EVT event,
if (socket_write_and_transfer_fd(sco_socket->socket, &connect_signal,
sizeof(connect_signal),
client_fd) != sizeof(connect_signal)) {
- LOG_ERROR("%s unable to send new file descriptor to listening socket.",
- __func__);
+ log::error("unable to send new file descriptor to listening socket.");
goto error;
}
@@ -275,8 +272,7 @@ static void connect_completed_cb(uint16_t sco_handle) {
sco_socket_t* sco_socket = sco_socket_find_locked(sco_handle);
if (!sco_socket) {
- LOG_ERROR("%s SCO socket not found on connect for handle: %hu", __func__,
- sco_handle);
+ log::error("SCO socket not found on connect for handle: {}", sco_handle);
return;
}
@@ -297,8 +293,7 @@ static void disconnect_completed_cb(uint16_t sco_handle) {
sco_socket_t* sco_socket = sco_socket_find_locked(sco_handle);
if (!sco_socket) {
- LOG_ERROR("%s SCO socket not found on disconnect for handle: %hu", __func__,
- sco_handle);
+ log::error("SCO socket not found on disconnect for handle: {}", sco_handle);
return;
}
diff --git a/system/btif/src/btif_sock_sdp.cc b/system/btif/src/btif_sock_sdp.cc
index b550bf3059..5c53bdf211 100644
--- a/system/btif/src/btif_sock_sdp.cc
+++ b/system/btif/src/btif_sock_sdp.cc
@@ -20,6 +20,8 @@
#include "btif/include/btif_sock_sdp.h"
+#include <bluetooth/log.h>
+
#include "bta/include/bta_jv_api.h"
#include "bta/include/bta_op_api.h"
#include "bta/include/utl.h"
@@ -33,6 +35,7 @@
#include "types/bluetooth/uuid.h"
using namespace bluetooth::legacy::stack::sdp;
+using namespace bluetooth;
using bluetooth::Uuid;
@@ -90,8 +93,8 @@ static const tBTA_OP_FMT bta_ops_obj_fmt[OBEX_PUSH_NUM_FORMATS] = {
// Returns true if successful, otherwise false.
static bool create_base_record(const uint32_t sdp_handle, const char* name,
const uint16_t channel, const bool with_obex) {
- LOG_VERBOSE("create_base_record: scn: %d, name: %s, with_obex: %d", channel,
- name, with_obex);
+ log::verbose("create_base_record: scn: {}, name: {}, with_obex: {}", channel,
+ name, with_obex);
// Setup the protocol list and add it.
tSDP_PROTOCOL_ELEM proto_list[SDP_MAX_LIST_ELEMS];
@@ -132,16 +135,16 @@ static bool create_base_record(const uint32_t sdp_handle, const char* name,
sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1, &list))
goto error;
- LOG_VERBOSE(
- "create_base_record: successfully created base service "
- "record, handle: 0x%08x, scn: %d, name: %s, with_obex: %d",
+ log::verbose(
+ "create_base_record: successfully created base service record, handle: "
+ "0x{:08x}, scn: {}, name: {}, with_obex: {}",
sdp_handle, channel, name, with_obex);
return true;
error:
- LOG_ERROR(
- "create_base_record: failed to create base service "
- "record, stage: %s, scn: %d, name: %s, with_obex: %d",
+ log::error(
+ "create_base_record: failed to create base service record, stage: {}, "
+ "scn: {}, name: {}, with_obex: {}",
stage, channel, name, with_obex);
return false;
}
@@ -151,13 +154,13 @@ error:
// class sequence.
static int add_sdp_by_uuid(const char* name, const Uuid& uuid,
const uint16_t channel) {
- LOG_VERBOSE("%s: uuid: %s, scn: %d, service_name: %s", __func__,
- uuid.ToString().c_str(), channel, name);
+ log::verbose("uuid: {}, scn: {}, service_name: {}", uuid.ToString(), channel,
+ name);
uint32_t handle = get_legacy_stack_sdp_api()->handle.SDP_CreateRecord();
if (handle == 0) {
- LOG_ERROR("%s: failed to create sdp record, scn: %d, service_name: %s",
- __func__, channel, name);
+ log::error("failed to create sdp record, scn: {}, service_name: {}",
+ channel, name);
return 0;
}
@@ -188,9 +191,9 @@ static int add_sdp_by_uuid(const char* name, const Uuid& uuid,
&type_buf_ptr))
goto error;
- LOG_VERBOSE(
- "%s: service registered successfully, service_name: %s, handle: 0x%08x",
- __func__, name, handle);
+ log::verbose(
+ "service registered successfully, service_name: {}, handle: 0x{:08x}",
+ name, handle);
{
// Write the custom 128-bit UUID to EIR
@@ -202,22 +205,20 @@ static int add_sdp_by_uuid(const char* name, const Uuid& uuid,
error:
get_legacy_stack_sdp_api()->handle.SDP_DeleteRecord(handle);
- LOG_ERROR("%s: failed to register service stage: %s, service_name: %s",
- __func__, stage, name);
+ log::error("failed to register service stage: {}, service_name: {}", stage,
+ name);
return 0;
}
// Registers a service with the given |name| and |channel| in the SDP
// database as a PBAP protocol.
static int add_pbap_sdp(const char* name, const int channel) {
- LOG_VERBOSE("add_pbap_sdp: scn %d, service_name %s", channel, name);
+ log::verbose("add_pbap_sdp: scn {}, service_name {}", channel, name);
uint32_t handle = get_legacy_stack_sdp_api()->handle.SDP_CreateRecord();
if (handle == 0) {
- LOG_ERROR(
- "add_pbap_sdp: failed to create sdp record, "
- "service_name: %s",
- name);
+ log::error("add_pbap_sdp: failed to create sdp record, service_name: {}",
+ name);
return 0;
}
@@ -249,32 +250,30 @@ static int add_pbap_sdp(const char* name, const int channel) {
// Notify the system that we've got a new service class UUID.
bta_sys_add_uuid(UUID_SERVCLASS_PBAP_PSE);
- LOG_VERBOSE(
- "add_pbap_sdp: service registered successfully, "
- "service_name: %s, handle: 0x%08x",
+ log::verbose(
+ "add_pbap_sdp: service registered successfully, service_name: {}, "
+ "handle: 0x{:08x}",
name, handle);
return handle;
error:
get_legacy_stack_sdp_api()->handle.SDP_DeleteRecord(handle);
- LOG_ERROR(
- "add_pbap_sdp: failed to register PBAP service, stage: %s, "
- "service_name: %s",
+ log::error(
+ "add_pbap_sdp: failed to register PBAP service, stage: {}, service_name: "
+ "{}",
stage, name);
return 0;
}
// Registers a service with the given |name| and |channel| as an OBEX Push
// protocol.
static int add_ops_sdp(const char* name, const int channel) {
- LOG_VERBOSE("add_ops_sdp: scn %d, service_name %s", channel, name);
+ log::verbose("add_ops_sdp: scn {}, service_name {}", channel, name);
uint32_t handle = get_legacy_stack_sdp_api()->handle.SDP_CreateRecord();
if (handle == 0) {
- LOG_ERROR(
- "add_ops_sdp: failed to create sdp record, "
- "service_name: %s",
- name);
+ log::error("add_ops_sdp: failed to create sdp record, service_name: {}",
+ name);
return 0;
}
@@ -325,18 +324,18 @@ static int add_ops_sdp(const char* name, const int channel) {
// Notify the system that we've got a new service class UUID.
bta_sys_add_uuid(UUID_SERVCLASS_OBEX_OBJECT_PUSH);
- LOG_VERBOSE(
- "ad_maps_sdp: service registered successfully, "
- "service_name: %s, handle 0x%08x)",
+ log::verbose(
+ "ad_maps_sdp: service registered successfully, service_name: {}, handle "
+ "0x{:08x})",
name, handle);
return handle;
error:
get_legacy_stack_sdp_api()->handle.SDP_DeleteRecord(handle);
- LOG_ERROR(
- "add_ops_sdp: failed to register OPS service, "
- "stage: %s, service_name: %s",
+ log::error(
+ "add_ops_sdp: failed to register OPS service, stage: {}, service_name: "
+ "{}",
stage, name);
return 0;
}
@@ -344,14 +343,12 @@ error:
// Registers a service with the given |name| and |channel| as a serial port
// profile protocol.
static int add_spp_sdp(const char* name, const int channel) {
- LOG_VERBOSE("add_spp_sdp: scn %d, service_name %s", channel, name);
+ log::verbose("add_spp_sdp: scn {}, service_name {}", channel, name);
int handle = get_legacy_stack_sdp_api()->handle.SDP_CreateRecord();
if (handle == 0) {
- LOG_ERROR(
- "add_spp_sdp: failed to create sdp record, "
- "service_name: %s",
- name);
+ log::error("add_spp_sdp: failed to create sdp record, service_name: {}",
+ name);
return 0;
}
@@ -372,18 +369,18 @@ static int add_spp_sdp(const char* name, const int channel) {
handle, UUID_SERVCLASS_SERIAL_PORT, SPP_PROFILE_VERSION))
goto error;
- LOG_VERBOSE(
- "add_spp_sdp: service registered successfully, "
- "service_name: %s, handle 0x%08x)",
+ log::verbose(
+ "add_spp_sdp: service registered successfully, service_name: {}, handle "
+ "0x{:08x})",
name, handle);
return handle;
error:
get_legacy_stack_sdp_api()->handle.SDP_DeleteRecord(handle);
- LOG_ERROR(
- "add_spp_sdp: failed to register SPP service, "
- "stage: %s, service_name: %s",
+ log::error(
+ "add_spp_sdp: failed to register SPP service, stage: {}, service_name: "
+ "{}",
stage, name);
return 0;
}
@@ -394,8 +391,8 @@ error:
// number if the |uuid| matches one of the preregistered bluez SDP records.
static int add_rfc_sdp_by_uuid(const char* name, const Uuid& uuid,
const int channel) {
- LOG_VERBOSE("%s: uuid: %s, service_name: %s, channel: %d", __func__,
- uuid.ToString().c_str(), name, channel);
+ log::verbose("uuid: {}, service_name: {}, channel: {}", uuid.ToString(), name,
+ channel);
/*
* Bluetooth Socket API relies on having preregistered bluez sdp records for
@@ -479,7 +476,7 @@ int add_rfc_sdp_rec(const char* name, Uuid uuid, const int channel) {
// Deletes an SDP record with the given |handle|.
void del_rfc_sdp_rec(int handle) {
- LOG_VERBOSE("del_rfc_sdp_rec: handle:0x%x", handle);
+ log::verbose("del_rfc_sdp_rec: handle:0x{:x}", handle);
if ((handle != -1) && (handle != 0)) {
// Remove the custom 128-bit UUID from EIR
diff --git a/system/btif/src/btif_sock_thread.cc b/system/btif/src/btif_sock_thread.cc
index 7dbdf79cb9..c3cefcbd74 100644
--- a/system/btif/src/btif_sock_thread.cc
+++ b/system/btif/src/btif_sock_thread.cc
@@ -29,6 +29,7 @@
#include "btif_sock_thread.h"
#include <alloca.h>
+#include <bluetooth/log.h>
#include <fcntl.h>
#include <features.h>
#include <poll.h>
@@ -50,11 +51,9 @@
#include "os/log.h"
#include "osi/include/osi.h" // OSI_NO_INTR
-#define asrt(s) \
- do { \
- if (!(s)) \
- LOG_ERROR("## %s assert %s failed at line:%d ##", __func__, #s, \
- __LINE__); \
+#define asrt(s) \
+ do { \
+ if (!(s)) log::error("## assert {} failed ##", #s); \
} while (0)
#define MAX_THREAD 8
@@ -70,6 +69,8 @@
#define CMD_REMOVE_FD 4
#define CMD_USER_PRIVATE 5
+using namespace bluetooth;
+
struct poll_slot_t {
struct pollfd pfd;
uint32_t user_id;
@@ -108,7 +109,7 @@ static inline int create_thread(void* (*start_routine)(void*), void* arg,
ret = pthread_create(thread_id, &thread_attr, start_routine, arg);
if (ret != 0) {
- LOG_ERROR("pthread_create : %s", strerror(errno));
+ log::error("pthread_create : {}", strerror(errno));
return ret;
}
/* We need to lower the priority of this thread to ensure the stack gets
@@ -132,7 +133,7 @@ static int alloc_thread_slot() {
return i;
}
}
- LOG_ERROR("execeeded max thread count");
+ log::error("execeeded max thread count");
return -1;
}
static void free_thread_slot(int h) {
@@ -140,7 +141,7 @@ static void free_thread_slot(int h) {
close_cmd_fd(h);
ts[h].used = 0;
} else
- LOG_ERROR("invalid thread handle:%d", h);
+ log::error("invalid thread handle:{}", h);
}
void btsock_thread_init() {
static int initialized;
@@ -166,7 +167,7 @@ int btsock_thread_create(btsock_signaled_cb callback,
pthread_t thread;
int status = create_thread(sock_poll_thread, (void*)(uintptr_t)h, &thread);
if (status) {
- LOG_ERROR("create_thread failed: %s", strerror(status));
+ log::error("create_thread failed: {}", strerror(status));
free_thread_slot(h);
return -1;
}
@@ -182,7 +183,7 @@ int btsock_thread_create(btsock_signaled_cb callback,
static inline void init_cmd_fd(int h) {
asrt(ts[h].cmd_fdr == -1 && ts[h].cmd_fdw == -1);
if (socketpair(AF_UNIX, SOCK_STREAM, 0, &ts[h].cmd_fdr) < 0) {
- LOG_ERROR("socketpair failed: %s", strerror(errno));
+ log::error("socketpair failed: {}", strerror(errno));
return;
}
// add the cmd fd for read & write
@@ -207,11 +208,11 @@ typedef struct {
} sock_cmd_t;
int btsock_thread_add_fd(int h, int fd, int type, int flags, uint32_t user_id) {
if (h < 0 || h >= MAX_THREAD) {
- LOG_ERROR("invalid bt thread handle:%d", h);
+ log::error("invalid bt thread handle:{}", h);
return false;
}
if (ts[h].cmd_fdw == -1) {
- LOG_ERROR("cmd socket is not created. socket thread may not initialized");
+ log::error("cmd socket is not created. socket thread may not initialized");
return false;
}
if (flags & SOCK_THREAD_ADD_FD_SYNC) {
@@ -222,7 +223,7 @@ int btsock_thread_add_fd(int h, int fd, int type, int flags, uint32_t user_id) {
add_poll(h, fd, type, flags, user_id);
return true;
}
- LOG_WARN(
+ log::warn(
"THREAD_ADD_FD_SYNC is not called in poll thread, fallback to async");
}
sock_cmd_t cmd = {CMD_ADD_FD, fd, type, flags, user_id};
@@ -235,11 +236,11 @@ int btsock_thread_add_fd(int h, int fd, int type, int flags, uint32_t user_id) {
bool btsock_thread_remove_fd_and_close(int thread_handle, int fd) {
if (thread_handle < 0 || thread_handle >= MAX_THREAD) {
- LOG_ERROR("%s invalid thread handle: %d", __func__, thread_handle);
+ log::error("invalid thread handle: {}", thread_handle);
return false;
}
if (fd == -1) {
- LOG_ERROR("%s invalid file descriptor.", __func__);
+ log::error("invalid file descriptor.");
return false;
}
@@ -254,11 +255,11 @@ bool btsock_thread_remove_fd_and_close(int thread_handle, int fd) {
int btsock_thread_post_cmd(int h, int type, const unsigned char* data, int size,
uint32_t user_id) {
if (h < 0 || h >= MAX_THREAD) {
- LOG_ERROR("invalid bt thread handle:%d", h);
+ log::error("invalid bt thread handle:{}", h);
return false;
}
if (ts[h].cmd_fdw == -1) {
- LOG_ERROR("cmd socket is not created. socket thread may not initialized");
+ log::error("cmd socket is not created. socket thread may not initialized");
return false;
}
sock_cmd_t cmd = {CMD_USER_PRIVATE, 0, type, size, user_id};
@@ -271,8 +272,8 @@ int btsock_thread_post_cmd(int h, int type, const unsigned char* data, int size,
*cmd_send = cmd;
memcpy(cmd_send + 1, data, size);
} else {
- LOG_ERROR("alloca failed at h:%d, cmd type:%d, size:%d", h, type,
- size_send);
+ log::error("alloca failed at h:{}, cmd type:{}, size:{}", h, type,
+ size_send);
return false;
}
}
@@ -284,11 +285,11 @@ int btsock_thread_post_cmd(int h, int type, const unsigned char* data, int size,
}
int btsock_thread_wakeup(int h) {
if (h < 0 || h >= MAX_THREAD) {
- LOG_ERROR("invalid bt thread handle:%d", h);
+ log::error("invalid bt thread handle:{}", h);
return false;
}
if (ts[h].cmd_fdw == -1) {
- LOG_ERROR("thread handle:%d, cmd socket is not created", h);
+ log::error("thread handle:{}, cmd socket is not created", h);
return false;
}
sock_cmd_t cmd = {CMD_WAKEUP, 0, 0, 0, 0};
@@ -300,11 +301,11 @@ int btsock_thread_wakeup(int h) {
}
int btsock_thread_exit(int h) {
if (h < 0 || h >= MAX_THREAD) {
- LOG_ERROR("invalid bt thread slot:%d", h);
+ log::error("invalid bt thread slot:{}", h);
return false;
}
if (ts[h].cmd_fdw == -1) {
- LOG_ERROR("cmd socket is not created");
+ log::error("cmd socket is not created");
return false;
}
sock_cmd_t cmd = {CMD_EXIT, 0, 0, 0, 0};
@@ -347,8 +348,8 @@ static inline void set_poll(poll_slot_t* ps, int fd, int type, int flags,
ps->pfd.fd = fd;
ps->user_id = user_id;
if (ps->type != 0 && ps->type != type)
- LOG_ERROR("poll socket type should not changed! type was:%d, type now:%d",
- ps->type, type);
+ log::error("poll socket type should not changed! type was:{}, type now:{}",
+ ps->type, type);
ps->type = type;
ps->flags = flags;
ps->pfd.events = flags2pevents(flags);
@@ -376,7 +377,7 @@ static inline void add_poll(int h, int fd, int type, int flags,
++ts[h].poll_count;
return;
}
- LOG_ERROR("exceeded max poll slot:%d!", MAX_POLL);
+ log::error("exceeded max poll slot:{}!", MAX_POLL);
}
static inline void remove_poll(int h, poll_slot_t* ps, int flags) {
if (flags == ps->flags) {
@@ -399,7 +400,7 @@ static int process_cmd_sock(int h) {
OSI_NO_INTR(ret = recv(fd, &cmd, sizeof(cmd), MSG_WAITALL));
if (ret != sizeof(cmd)) {
- LOG_ERROR("recv cmd errno:%d", errno);
+ log::error("recv cmd errno:{}", errno);
return false;
}
switch (cmd.id) {
@@ -426,7 +427,7 @@ static int process_cmd_sock(int h) {
case CMD_EXIT:
return false;
default:
- LOG_WARN("unknown cmd: %d", cmd.id);
+ log::warn("unknown cmd: {}", cmd.id);
break;
}
return true;
@@ -440,7 +441,7 @@ static void process_data_sock(int h, struct pollfd* pfds, int pfds_count,
if (pfds[i].revents) {
int ps_i = ts[h].psi[i];
if (ts[h].ps[ps_i].pfd.fd == -1) {
- LOG_INFO("Socket has been removed from poll set");
+ log::info("Socket has been removed from poll set");
continue;
}
asrt(pfds[i].fd == ts[h].ps[ps_i].pfd.fd);
@@ -472,9 +473,9 @@ static void prepare_poll_fds(int h, struct pollfd* pfds) {
asrt(ts[h].poll_count <= MAX_POLL);
while (count < ts[h].poll_count) {
if (ps_i >= MAX_POLL) {
- LOG_ERROR(
- "exceed max poll range, ps_i:%d, MAX_POLL:%d, count:%d, "
- "ts[h].poll_count:%d",
+ log::error(
+ "exceed max poll range, ps_i:{}, MAX_POLL:{}, count:{}, "
+ "ts[h].poll_count:{}",
ps_i, MAX_POLL, count, ts[h].poll_count);
return;
}
@@ -497,8 +498,8 @@ static void* sock_poll_thread(void* arg) {
int ret;
OSI_NO_INTR(ret = poll(pfds.data(), ts[h].poll_count, -1));
if (ret == -1) {
- LOG_ERROR("poll ret -1, exit the thread, errno:%d, err:%s", errno,
- strerror(errno));
+ log::error("poll ret -1, exit the thread, errno:{}, err:{}", errno,
+ strerror(errno));
break;
}
if (ret != 0) {
@@ -508,7 +509,7 @@ static void* sock_poll_thread(void* arg) {
{
asrt(pfds[0].fd == ts[h].cmd_fdr);
if (!process_cmd_sock(h)) {
- LOG_INFO("h:%d, process_cmd_sock return false, exit...", h);
+ log::info("h:{}, process_cmd_sock return false, exit...", h);
break;
}
if (ret == 1)
@@ -519,9 +520,9 @@ static void* sock_poll_thread(void* arg) {
if (need_process_data_fd)
process_data_sock(h, pfds.data(), pfds_count, ret);
} else {
- LOG_INFO("no data, select ret: %d", ret);
+ log::info("no data, select ret: {}", ret);
};
}
- LOG_INFO("socket poll thread exiting, h:%d", h);
+ log::info("socket poll thread exiting, h:{}", h);
return 0;
}
diff --git a/system/btif/src/btif_sock_util.cc b/system/btif/src/btif_sock_util.cc
index 72f7bbb972..536f824d9e 100644
--- a/system/btif/src/btif_sock_util.cc
+++ b/system/btif/src/btif_sock_util.cc
@@ -21,6 +21,7 @@
#include "btif_sock_util.h"
#include <arpa/inet.h>
+#include <bluetooth/log.h>
#include <hardware/bluetooth.h>
#include <hardware/bt_sock.h>
#include <netinet/in.h>
@@ -37,13 +38,13 @@
#include "os/log.h"
#include "osi/include/osi.h"
-#define asrt(s) \
- do { \
- if (!(s)) \
- LOG_ERROR("## %s assert %s failed at line:%d ##", __func__, #s, \
- __LINE__); \
+#define asrt(s) \
+ do { \
+ if (!(s)) log::error("## assert {} failed ##", #s); \
} while (0)
+using namespace bluetooth;
+
int sock_send_all(int sock_fd, const uint8_t* buf, int len) {
int s = len;
@@ -51,7 +52,7 @@ int sock_send_all(int sock_fd, const uint8_t* buf, int len) {
ssize_t ret;
OSI_NO_INTR(ret = send(sock_fd, buf, s, 0));
if (ret <= 0) {
- LOG_ERROR("sock fd:%d send errno:%d, ret:%zd", sock_fd, errno, ret);
+ log::error("sock fd:{} send errno:{}, ret:{}", sock_fd, errno, ret);
return -1;
}
buf += ret;
@@ -66,7 +67,7 @@ int sock_recv_all(int sock_fd, uint8_t* buf, int len) {
ssize_t ret;
OSI_NO_INTR(ret = recv(sock_fd, buf, r, MSG_WAITALL));
if (ret <= 0) {
- LOG_ERROR("sock fd:%d recv errno:%d, ret:%zd", sock_fd, errno, ret);
+ log::error("sock fd:{} recv errno:{}, ret:{}", sock_fd, errno, ret);
return -1;
}
buf += ret;
@@ -109,8 +110,8 @@ int sock_send_fd(int sock_fd, const uint8_t* buf, int len, int send_fd) {
ssize_t ret;
OSI_NO_INTR(ret = sendmsg(sock_fd, &msg, MSG_NOSIGNAL));
if (ret < 0) {
- LOG_ERROR("fd:%d, send_fd:%d, sendmsg ret:%d, errno:%d, %s", sock_fd,
- send_fd, (int)ret, errno, strerror(errno));
+ log::error("fd:{}, send_fd:{}, sendmsg ret:{}, errno:{}, {}", sock_fd,
+ send_fd, (int)ret, errno, strerror(errno));
ret_len = -1;
break;
}
@@ -121,7 +122,7 @@ int sock_send_fd(int sock_fd, const uint8_t* buf, int len, int send_fd) {
// Wipes out any msg_control too
memset(&msg, 0, sizeof(msg));
}
- LOG_VERBOSE("close fd:%d after sent", send_fd);
+ log::verbose("close fd:{} after sent", send_fd);
// TODO: This seems wrong - if the FD is not opened in JAVA before this is
// called
// we get a "socket closed" exception in java, when reading from the
diff --git a/system/btif/src/btif_storage.cc b/system/btif/src/btif_storage.cc
index 8cfc4e8177..930fda8a1e 100644
--- a/system/btif/src/btif_storage.cc
+++ b/system/btif/src/btif_storage.cc
@@ -34,6 +34,7 @@
#include <alloca.h>
#include <base/logging.h>
+#include <bluetooth/log.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
@@ -62,6 +63,7 @@
using base::Bind;
using bluetooth::Uuid;
+using namespace bluetooth;
/*******************************************************************************
* Constants & Macros
@@ -112,8 +114,8 @@ static bool btif_has_ble_keys(const std::string& bdstr);
static void btif_storage_set_mode(RawAddress* remote_bd_addr) {
std::string bdstr = remote_bd_addr->ToString();
if (GetInterfaceToProfiles()->config->isRestrictedMode()) {
- LOG_INFO("%s will be removed exiting restricted mode",
- ADDRESS_TO_LOGGABLE_CSTR(*remote_bd_addr));
+ log::info("{} will be removed exiting restricted mode",
+ ADDRESS_TO_LOGGABLE_CSTR(*remote_bd_addr));
btif_config_set_int(bdstr, BTIF_STORAGE_KEY_RESTRICTED, 1);
}
}
@@ -126,9 +128,9 @@ static bool prop2cfg(const RawAddress* remote_bd_addr, bt_property_t* prop) {
char value[1024];
if (prop->len <= 0 || prop->len > (int)sizeof(value) - 1) {
- LOG_WARN(
- "Unable to save property to configuration file type:%d, "
- " len:%d is invalid",
+ log::warn(
+ "Unable to save property to configuration file type:{}, len:{} is "
+ "invalid",
prop->type, prop->len);
return false;
}
@@ -214,7 +216,7 @@ static bool prop2cfg(const RawAddress* remote_bd_addr, bt_property_t* prop) {
btif_config_set_str(bdstr, BTIF_STORAGE_KEY_DIS_MODEL_NUM, value);
} break;
default:
- LOG_ERROR("Unknown prop type:%d", prop->type);
+ log::error("Unknown prop type:{}", prop->type);
return false;
}
@@ -227,8 +229,8 @@ static bool cfg2prop(const RawAddress* remote_bd_addr, bt_property_t* prop) {
bdstr = remote_bd_addr->ToString();
}
if (prop->len <= 0) {
- LOG_WARN("Invalid property read from configuration file type:%d, len:%d",
- prop->type, prop->len);
+ log::warn("Invalid property read from configuration file type:{}, len:{}",
+ prop->type, prop->len);
return false;
}
bool ret = false;
@@ -383,7 +385,7 @@ static bool cfg2prop(const RawAddress* remote_bd_addr, bt_property_t* prop) {
} break;
default:
- LOG_ERROR("Unknown prop type:%d", prop->type);
+ log::error("Unknown prop type:{}", prop->type);
return false;
}
return ret;
@@ -442,7 +444,7 @@ static bt_status_t btif_in_fetch_bonded_devices(
for (const auto& bd_addr : btif_config_get_paired_devices()) {
auto name = bd_addr.ToString();
- LOG_VERBOSE("Remote device:%s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
+ log::verbose("Remote device:{}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
LinkKey link_key;
size_t size = sizeof(link_key);
if (btif_config_get_bin(name, BTIF_STORAGE_KEY_LINK_KEY, link_key.data(),
@@ -470,7 +472,7 @@ static bt_status_t btif_in_fetch_bonded_devices(
if (p_bonded_devices->num_devices < BTM_SEC_MAX_DEVICE_RECORDS) {
p_bonded_devices->devices[p_bonded_devices->num_devices++] = bd_addr;
} else {
- LOG_WARN("Exceed the max number of bonded devices");
+ log::warn("Exceed the max number of bonded devices");
}
} else {
bt_linkkey_file_found = false;
@@ -478,8 +480,8 @@ static bt_status_t btif_in_fetch_bonded_devices(
}
if (!btif_in_fetch_bonded_ble_device(name, add, p_bonded_devices) &&
!bt_linkkey_file_found) {
- LOG_VERBOSE("No link key or ble key found for device:%s",
- ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
+ log::verbose("No link key or ble key found for device:{}",
+ ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
}
}
return BT_STATUS_SUCCESS;
@@ -503,8 +505,8 @@ static void btif_read_le_key(const uint8_t key_type, const size_t key_len,
*device_added = true;
}
- LOG_VERBOSE("Adding key type %d for %s", key_type,
- ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
+ log::verbose("Adding key type {} for {}", key_type,
+ ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
BTA_DmAddBleKey(bd_addr, &key, key_type);
}
@@ -619,11 +621,11 @@ bt_status_t btif_storage_get_adapter_property(bt_property_t* property) {
/* Fetch the local BD ADDR */
const controller_t* controller = controller_get_interface();
if (!controller->get_is_ready()) {
- LOG_ERROR("Controller not ready! Unable to return Bluetooth Address");
+ log::error("Controller not ready! Unable to return Bluetooth Address");
*bd_addr = RawAddress::kEmpty;
return BT_STATUS_FAIL;
} else {
- LOG_INFO("Controller ready!");
+ log::info("Controller ready!");
*bd_addr = *controller->get_address();
}
property->len = RawAddress::kLength;
@@ -633,8 +635,8 @@ bt_status_t btif_storage_get_adapter_property(bt_property_t* property) {
btif_in_fetch_bonded_devices(&bonded_devices, 0);
- LOG_VERBOSE(
- "BT_PROPERTY_ADAPTER_BONDED_DEVICES: Number of bonded devices=%d",
+ log::verbose(
+ "BT_PROPERTY_ADAPTER_BONDED_DEVICES: Number of bonded devices={}",
bonded_devices.num_devices);
property->len = bonded_devices.num_devices * RawAddress::kLength;
@@ -649,7 +651,7 @@ bt_status_t btif_storage_get_adapter_property(bt_property_t* property) {
uint32_t i;
tBTA_SERVICE_MASK service_mask = btif_get_enabled_services_mask();
- LOG_INFO("Service_mask=0x%x", service_mask);
+ log::info("Service_mask=0x{:x}", service_mask);
for (i = 0; i < BTA_MAX_SERVICE_ID; i++) {
/* This should eventually become a function when more services are enabled
*/
@@ -857,8 +859,8 @@ bt_status_t btif_storage_add_bonded_device(RawAddress* remote_bd_addr,
bt_status_t btif_storage_remove_bonded_device(
const RawAddress* remote_bd_addr) {
std::string bdstr = remote_bd_addr->ToString();
- LOG_INFO("Removing bonded device addr=%s",
- ADDRESS_TO_LOGGABLE_CSTR(*remote_bd_addr));
+ log::info("Removing bonded device addr={}",
+ ADDRESS_TO_LOGGABLE_CSTR(*remote_bd_addr));
btif_config_remove_device(bdstr);
@@ -866,7 +868,7 @@ bt_status_t btif_storage_remove_bonded_device(
auto paired_devices = btif_config_get_paired_devices();
if (paired_devices.empty() &&
bluetooth::common::init_flags::irk_rotation_is_enabled()) {
- LOG_INFO("Last paired device removed, resetting IRK");
+ log::info("Last paired device removed, resetting IRK");
BTA_DmBleResetId();
}
return BT_STATUS_SUCCESS;
@@ -897,8 +899,8 @@ static void remove_devices_with_sample_ltk() {
}
for (RawAddress address : bad_ltk) {
- LOG_ERROR("Removing bond to device using test TLK: %s",
- ADDRESS_TO_LOGGABLE_CSTR(address));
+ log::error("Removing bond to device using test TLK: {}",
+ ADDRESS_TO_LOGGABLE_CSTR(address));
btif_storage_remove_bonded_device(&address);
}
@@ -932,13 +934,13 @@ void btif_storage_load_le_devices(void) {
bonded_devices.devices[i], BTM_LE_KEY_PID, (uint8_t*)&key,
sizeof(tBTM_LE_PID_KEYS)) == BT_STATUS_SUCCESS) {
if (bonded_devices.devices[i] != key.pid_key.identity_addr) {
- LOG_INFO("Found device with a known identity address %s %s",
- ADDRESS_TO_LOGGABLE_CSTR(bonded_devices.devices[i]),
- ADDRESS_TO_LOGGABLE_CSTR(key.pid_key.identity_addr));
+ log::info("Found device with a known identity address {} {}",
+ ADDRESS_TO_LOGGABLE_CSTR(bonded_devices.devices[i]),
+ ADDRESS_TO_LOGGABLE_CSTR(key.pid_key.identity_addr));
if (bonded_devices.devices[i].IsEmpty() ||
key.pid_key.identity_addr.IsEmpty()) {
- LOG_WARN("Address is empty! Skip");
+ log::warn("Address is empty! Skip");
} else {
consolidated_devices.emplace_back(bonded_devices.devices[i],
key.pid_key.identity_addr);
@@ -1065,7 +1067,7 @@ bt_status_t btif_storage_load_bonded_devices(void) {
osi_free(devices_list);
}
- LOG_VERBOSE("Number of bonded devices found=%d", bonded_devices.num_devices);
+ log::verbose("Number of bonded devices found={}", bonded_devices.num_devices);
{
for (i = 0; i < bonded_devices.num_devices; i++) {
@@ -1174,7 +1176,7 @@ bt_status_t btif_storage_add_ble_bonding_key(RawAddress* remote_bd_addr,
}
}
- LOG_WARN("Unknown LE key type: %d", key_type);
+ log::warn("Unknown LE key type: {}", key_type);
return BT_STATUS_FAIL;
}
@@ -1202,7 +1204,7 @@ bt_status_t btif_storage_get_ble_bonding_key(const RawAddress& remote_bd_addr,
}
}
- LOG_WARN("Unknown LE key type: %d", key_type);
+ log::warn("Unknown LE key type: {}", key_type);
return BT_STATUS_FAIL;
}
@@ -1219,8 +1221,8 @@ bt_status_t btif_storage_get_ble_bonding_key(const RawAddress& remote_bd_addr,
bt_status_t btif_storage_remove_ble_bonding_keys(
const RawAddress* remote_bd_addr) {
std::string bdstr = remote_bd_addr->ToString();
- LOG_INFO("Removing bonding keys for bd addr:%s",
- ADDRESS_TO_LOGGABLE_CSTR(*remote_bd_addr));
+ log::info("Removing bonding keys for bd addr:{}",
+ ADDRESS_TO_LOGGABLE_CSTR(*remote_bd_addr));
bool ret = true;
for (size_t i = 0; i < std::size(BTIF_STORAGE_LE_KEYS); i++) {
auto key_name = BTIF_STORAGE_LE_KEYS[i].name;
@@ -1252,7 +1254,7 @@ bt_status_t btif_storage_add_ble_local_key(const Octet16& key_value,
return ret ? BT_STATUS_SUCCESS : BT_STATUS_FAIL;
}
}
- LOG_WARN("Unknown LE key type: %d", key_type);
+ log::warn("Unknown LE key type: {}", key_type);
return BT_STATUS_FAIL;
}
@@ -1272,7 +1274,7 @@ bt_status_t btif_storage_get_ble_local_key(uint8_t key_type,
return ret ? BT_STATUS_SUCCESS : BT_STATUS_FAIL;
}
}
- LOG_WARN("Unknown LE key type: %d", key_type);
+ log::warn("Unknown LE key type: {}", key_type);
return BT_STATUS_FAIL;
}
@@ -1313,7 +1315,7 @@ bt_status_t btif_in_fetch_bonded_ble_device(
if ((device_type & BT_DEVICE_TYPE_BLE) == BT_DEVICE_TYPE_BLE ||
btif_has_ble_keys(remote_bd_addr)) {
- LOG_VERBOSE("Found a LE device: %s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
+ log::verbose("Found a LE device: {}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
if (btif_storage_get_remote_addr_type(&bd_addr, &addr_type) !=
BT_STATUS_SUCCESS) {
@@ -1332,7 +1334,7 @@ bt_status_t btif_in_fetch_bonded_ble_device(
if (p_bonded_devices->num_devices < BTM_SEC_MAX_DEVICE_RECORDS) {
p_bonded_devices->devices[p_bonded_devices->num_devices++] = bd_addr;
} else {
- LOG_WARN("Exceed the max number of bonded devices");
+ log::warn("Exceed the max number of bonded devices");
}
btif_gatts_add_bonded_dev_from_nv(bd_addr);
}
@@ -1370,7 +1372,7 @@ void btif_storage_set_remote_addr_type(const RawAddress& remote_bd_addr,
if (!btif_config_set_int(remote_bd_addr.ToString(),
BTIF_STORAGE_KEY_ADDR_TYPE,
static_cast<int>(addr_type)))
- LOG_ERROR("Unable to set storage property");
+ log::error("Unable to set storage property");
else {
#if TARGET_FLOSS
// Floss needs to get address type for diagnosis API.
@@ -1383,7 +1385,7 @@ void btif_storage_set_remote_device_type(const RawAddress& remote_bd_addr,
const tBT_DEVICE_TYPE& device_type) {
if (!btif_config_set_int(remote_bd_addr.ToString(), BTIF_STORAGE_KEY_DEV_TYPE,
static_cast<int>(device_type)))
- LOG_ERROR("Unable to set storage property");
+ log::error("Unable to set storage property");
}
bool btif_has_ble_keys(const std::string& bdstr) {
@@ -1433,9 +1435,10 @@ void btif_storage_set_gatt_sr_supp_feat(const RawAddress& addr, uint8_t feat) {
FROM_HERE, Bind(
[](const RawAddress& addr, uint8_t feat) {
std::string bdstr = addr.ToString();
- VLOG(2) << "GATT server supported features for: "
- << ADDRESS_TO_LOGGABLE_STR(addr)
- << " features: " << +feat;
+ log::verbose(
+ "GATT server supported features for: {} features: "
+ "{}",
+ ADDRESS_TO_LOGGABLE_STR(addr), feat);
btif_config_set_int(
bdstr, BTIF_STORAGE_KEY_GATT_SERVER_SUPPORTED, feat);
},
@@ -1448,8 +1451,8 @@ uint8_t btif_storage_get_sr_supp_feat(const RawAddress& bd_addr) {
int value = 0;
btif_config_get_int(name, BTIF_STORAGE_KEY_GATT_SERVER_SUPPORTED, &value);
- LOG_VERBOSE("Remote device: %s GATT server supported features 0x%02x",
- ADDRESS_TO_LOGGABLE_CSTR(bd_addr), value);
+ log::verbose("Remote device: {} GATT server supported features 0x{:02x}",
+ ADDRESS_TO_LOGGABLE_CSTR(bd_addr), value);
return value;
}
@@ -1496,8 +1499,8 @@ void btif_storage_set_gatt_cl_supp_feat(const RawAddress& bd_addr,
FROM_HERE, Bind(
[](const RawAddress& bd_addr, uint8_t feat) {
std::string bdstr = bd_addr.ToString();
- VLOG(2) << "saving gatt client supported feat: "
- << ADDRESS_TO_LOGGABLE_STR(bd_addr);
+ log::verbose("saving gatt client supported feat: {}",
+ ADDRESS_TO_LOGGABLE_STR(bd_addr));
btif_config_set_int(
bdstr, BTIF_STORAGE_KEY_GATT_CLIENT_SUPPORTED, feat);
},
@@ -1510,8 +1513,8 @@ uint8_t btif_storage_get_gatt_cl_supp_feat(const RawAddress& bd_addr) {
int value = 0;
btif_config_get_int(name, BTIF_STORAGE_KEY_GATT_CLIENT_SUPPORTED, &value);
- LOG_VERBOSE("Remote device: %s GATT client supported features 0x%02x",
- ADDRESS_TO_LOGGABLE_CSTR(bd_addr), value);
+ log::verbose("Remote device: {} GATT client supported features 0x{:02x}",
+ ADDRESS_TO_LOGGABLE_CSTR(bd_addr), value);
return value;
}
diff --git a/system/btif/src/btif_vc.cc b/system/btif/src/btif_vc.cc
index 21e8edc77c..3a29255e43 100644
--- a/system/btif/src/btif_vc.cc
+++ b/system/btif/src/btif_vc.cc
@@ -20,6 +20,7 @@
#include <base/functional/bind.h>
#include <base/location.h>
#include <base/logging.h>
+#include <bluetooth/log.h>
#include <hardware/bluetooth.h>
#include <hardware/bt_vc.h>
@@ -34,6 +35,7 @@ using base::Unretained;
using bluetooth::vc::ConnectionState;
using bluetooth::vc::VolumeControlCallbacks;
using bluetooth::vc::VolumeControlInterface;
+using namespace bluetooth;
namespace {
std::unique_ptr<VolumeControlInterface> vc_instance;
@@ -119,9 +121,9 @@ class VolumeControlInterfaceImpl : public VolumeControlInterface,
void Connect(const RawAddress& address) override {
if (!initialized || !VolumeControl::IsVolumeControlRunning()) {
- VLOG(1) << __func__
- << " call ignored, due to already started cleanup procedure or "
- "service being not read";
+ log::verbose(
+ "call ignored, due to already started cleanup procedure or service "
+ "being not read");
return;
}
@@ -132,9 +134,9 @@ class VolumeControlInterfaceImpl : public VolumeControlInterface,
void Disconnect(const RawAddress& address) override {
if (!initialized || !VolumeControl::IsVolumeControlRunning()) {
- VLOG(1) << __func__
- << " call ignored, due to already started cleanup procedure or "
- "service being not read";
+ log::verbose(
+ "call ignored, due to already started cleanup procedure or service "
+ "being not read");
return;
}
do_in_main_thread(FROM_HERE,
@@ -145,9 +147,9 @@ class VolumeControlInterfaceImpl : public VolumeControlInterface,
void SetVolume(std::variant<RawAddress, int> addr_or_group_id,
uint8_t volume) override {
if (!initialized || !VolumeControl::IsVolumeControlRunning()) {
- VLOG(1) << __func__
- << " call ignored, due to already started cleanup procedure or "
- "service being not read";
+ log::verbose(
+ "call ignored, due to already started cleanup procedure or service "
+ "being not read");
return;
}
@@ -158,9 +160,9 @@ class VolumeControlInterfaceImpl : public VolumeControlInterface,
void Mute(std::variant<RawAddress, int> addr_or_group_id) override {
if (!initialized || !VolumeControl::IsVolumeControlRunning()) {
- VLOG(1) << __func__
- << " call ignored, due to already started cleanup procedure or "
- "service being not read";
+ log::verbose(
+ "call ignored, due to already started cleanup procedure or service "
+ "being not read");
return;
}
@@ -171,9 +173,9 @@ class VolumeControlInterfaceImpl : public VolumeControlInterface,
void Unmute(std::variant<RawAddress, int> addr_or_group_id) override {
if (!initialized || !VolumeControl::IsVolumeControlRunning()) {
- VLOG(1) << __func__
- << " call ignored, due to already started cleanup procedure or "
- "service being not read";
+ log::verbose(
+ "call ignored, due to already started cleanup procedure or service "
+ "being not read");
return;
}
@@ -184,9 +186,9 @@ class VolumeControlInterfaceImpl : public VolumeControlInterface,
void RemoveDevice(const RawAddress& address) override {
if (!initialized || !VolumeControl::IsVolumeControlRunning()) {
- VLOG(1) << __func__
- << " call ignored, due to already started cleanup procedure or "
- "service being not read";
+ log::verbose(
+ "call ignored, due to already started cleanup procedure or service "
+ "being not read");
return;
}
@@ -201,9 +203,9 @@ class VolumeControlInterfaceImpl : public VolumeControlInterface,
void GetExtAudioOutVolumeOffset(const RawAddress& address,
uint8_t ext_output_id) override {
if (!initialized || !VolumeControl::IsVolumeControlRunning()) {
- VLOG(1) << __func__
- << " call ignored, due to already started cleanup procedure or "
- "service being not read";
+ log::verbose(
+ "call ignored, due to already started cleanup procedure or service "
+ "being not read");
return;
}
@@ -217,9 +219,9 @@ class VolumeControlInterfaceImpl : public VolumeControlInterface,
uint8_t ext_output_id,
int16_t offset_val) override {
if (!initialized || !VolumeControl::IsVolumeControlRunning()) {
- VLOG(1) << __func__
- << " call ignored, due to already started cleanup procedure or "
- "service being not read";
+ log::verbose(
+ "call ignored, due to already started cleanup procedure or service "
+ "being not read");
return;
}
@@ -232,9 +234,9 @@ class VolumeControlInterfaceImpl : public VolumeControlInterface,
void GetExtAudioOutLocation(const RawAddress& address,
uint8_t ext_output_id) override {
if (!initialized || !VolumeControl::IsVolumeControlRunning()) {
- VLOG(1) << __func__
- << " call ignored, due to already started cleanup procedure or "
- "service being not read";
+ log::verbose(
+ "call ignored, due to already started cleanup procedure or service "
+ "being not read");
return;
}
@@ -246,9 +248,9 @@ class VolumeControlInterfaceImpl : public VolumeControlInterface,
void SetExtAudioOutLocation(const RawAddress& address, uint8_t ext_output_id,
uint32_t location) override {
if (!initialized || !VolumeControl::IsVolumeControlRunning()) {
- VLOG(1) << __func__
- << " call ignored, due to already started cleanup procedure or "
- "service being not read";
+ log::verbose(
+ "call ignored, due to already started cleanup procedure or service "
+ "being not read");
return;
}
@@ -260,9 +262,9 @@ class VolumeControlInterfaceImpl : public VolumeControlInterface,
void GetExtAudioOutDescription(const RawAddress& address,
uint8_t ext_output_id) override {
if (!initialized || !VolumeControl::IsVolumeControlRunning()) {
- VLOG(1) << __func__
- << " call ignored, due to already started cleanup procedure or "
- "service being not read";
+ log::verbose(
+ "call ignored, due to already started cleanup procedure or service "
+ "being not read");
return;
}
@@ -275,9 +277,9 @@ class VolumeControlInterfaceImpl : public VolumeControlInterface,
uint8_t ext_output_id,
std::string descr) override {
if (!initialized || !VolumeControl::IsVolumeControlRunning()) {
- VLOG(1) << __func__
- << " call ignored, due to already started cleanup procedure or "
- "service being not read";
+ log::verbose(
+ "call ignored, due to already started cleanup procedure or service "
+ "being not read");
return;
}
@@ -288,9 +290,9 @@ class VolumeControlInterfaceImpl : public VolumeControlInterface,
void Cleanup(void) override {
if (!initialized || !VolumeControl::IsVolumeControlRunning()) {
- VLOG(1) << __func__
- << " call ignored, due to already started cleanup procedure or "
- "service being not read";
+ log::verbose(
+ "call ignored, due to already started cleanup procedure or service "
+ "being not read");
return;
}
diff --git a/system/btif/src/stack_manager.cc b/system/btif/src/stack_manager.cc
index 8fdc1e691a..d388e6f4c9 100644
--- a/system/btif/src/stack_manager.cc
+++ b/system/btif/src/stack_manager.cc
@@ -18,6 +18,7 @@
#define LOG_TAG "bt_stack_manager"
+#include <bluetooth/log.h>
#include <hardware/bluetooth.h>
#include <cstdlib>
@@ -109,6 +110,7 @@ void BTA_dm_on_hw_on();
void BTA_dm_on_hw_off();
using bluetooth::common::MessageLoopThread;
+using namespace bluetooth;
static MessageLoopThread management_thread("bt_stack_manager_thread");
@@ -183,7 +185,7 @@ static void clean_up_stack(ProfileStopCallback stopProfiles) {
if (status == std::future_status::ready) {
management_thread.ShutDown();
} else {
- LOG_ERROR("cleanup could not be completed in time, abandon it");
+ log::error("cleanup could not be completed in time, abandon it");
}
}
@@ -228,7 +230,7 @@ inline const module_t* get_local_module(const char* name) {
}
}
- LOG_ALWAYS_FATAL("Cannot find module %s, aborting", name);
+ log::fatal("Cannot find module {}, aborting", name);
return nullptr;
}
@@ -256,15 +258,15 @@ static void init_stack_internal(bluetooth::core::CoreInterface* interface) {
// Synchronous function to initialize the stack
static void event_init_stack(std::promise<void> promise,
bluetooth::core::CoreInterface* interface) {
- LOG_INFO("is initializing the stack");
+ log::info("is initializing the stack");
if (stack_is_initialized) {
- LOG_INFO("found the stack already in initialized state");
+ log::info("found the stack already in initialized state");
} else {
init_stack_internal(interface);
}
- LOG_INFO("finished");
+ log::info("finished");
promise.set_value();
}
@@ -272,7 +274,7 @@ static void event_init_stack(std::promise<void> promise,
static void ensure_stack_is_initialized(
bluetooth::core::CoreInterface* interface) {
if (!stack_is_initialized) {
- LOG_WARN("found the stack was uninitialized. Initializing now.");
+ log::warn("found the stack was uninitialized. Initializing now.");
// No future needed since we are calling it directly
init_stack_internal(interface);
}
@@ -283,17 +285,17 @@ static void event_start_up_stack(bluetooth::core::CoreInterface* interface,
ProfileStartCallback startProfiles,
ProfileStopCallback stopProfiles) {
if (stack_is_running) {
- LOG_INFO("%s stack already brought up", __func__);
+ log::info("stack already brought up");
return;
}
ensure_stack_is_initialized(interface);
- LOG_INFO("%s is bringing up the stack", __func__);
+ log::info("is bringing up the stack");
future_t* local_hack_future = future_new();
hack_future = local_hack_future;
- LOG_INFO("%s Gd shim module enabled", __func__);
+ log::info("Gd shim module enabled");
get_btm_client_interface().lifecycle.btm_init();
module_start_up(get_local_module(BTIF_CONFIG_MODULE));
@@ -323,7 +325,7 @@ static void event_start_up_stack(bluetooth::core::CoreInterface* interface,
BTA_dm_on_hw_on();
if (future_await(local_hack_future) != FUTURE_SUCCESS) {
- LOG_ERROR("%s failed to start up the stack", __func__);
+ log::error("failed to start up the stack");
stack_is_running = true; // So stack shutdown actually happens
event_shut_down_stack(stopProfiles);
return;
@@ -332,18 +334,18 @@ static void event_start_up_stack(bluetooth::core::CoreInterface* interface,
module_start_up(get_local_module(RUST_MODULE));
stack_is_running = true;
- LOG_INFO("%s finished", __func__);
+ log::info("finished");
do_in_jni_thread(FROM_HERE, base::BindOnce(event_signal_stack_up, nullptr));
}
// Synchronous function to shut down the stack
static void event_shut_down_stack(ProfileStopCallback stopProfiles) {
if (!stack_is_running) {
- LOG_INFO("%s stack is already brought down", __func__);
+ log::info("stack is already brought down");
return;
}
- LOG_INFO("%s is bringing down the stack", __func__);
+ log::info("is bringing down the stack");
future_t* local_hack_future = future_new();
hack_future = local_hack_future;
stack_is_running = false;
@@ -383,13 +385,12 @@ static void event_shut_down_stack(ProfileStopCallback stopProfiles) {
hack_future = future_new();
do_in_jni_thread(FROM_HERE, base::BindOnce(event_signal_stack_down, nullptr));
future_await(hack_future);
- LOG_INFO("%s finished", __func__);
+ log::info("finished");
}
static void ensure_stack_is_not_running(ProfileStopCallback stopProfiles) {
if (stack_is_running) {
- LOG_WARN("%s found the stack was still running. Bringing it down now.",
- __func__);
+ log::warn("found the stack was still running. Bringing it down now.");
event_shut_down_stack(stopProfiles);
}
}
@@ -398,13 +399,13 @@ static void ensure_stack_is_not_running(ProfileStopCallback stopProfiles) {
static void event_clean_up_stack(std::promise<void> promise,
ProfileStopCallback stopProfiles) {
if (!stack_is_initialized) {
- LOG_INFO("%s found the stack already in a clean state", __func__);
+ log::info("found the stack already in a clean state");
goto cleanup;
}
ensure_stack_is_not_running(stopProfiles);
- LOG_INFO("%s is cleaning up the stack", __func__);
+ log::info("is cleaning up the stack");
stack_is_initialized = false;
btif_cleanup_bluetooth();
@@ -416,13 +417,13 @@ static void event_clean_up_stack(std::promise<void> promise,
module_clean_up(get_local_module(DEVICE_IOT_CONFIG_MODULE));
module_clean_up(get_local_module(OSI_MODULE));
- LOG_INFO("%s Gd shim module disabled", __func__);
+ log::info("Gd shim module disabled");
module_shut_down(get_local_module(GD_SHIM_MODULE));
main_thread_shut_down();
module_management_stop();
- LOG_INFO("%s finished", __func__);
+ log::info("finished");
cleanup:;
promise.set_value();
@@ -447,7 +448,7 @@ static void ensure_manager_initialized() {
management_thread.StartUp();
if (!management_thread.IsRunning()) {
- LOG_ERROR("%s unable to start stack management thread", __func__);
+ log::error("unable to start stack management thread");
return;
}
}
diff --git a/system/btif/test/btif_rc_test.cc b/system/btif/test/btif_rc_test.cc
index 10b3c3dc23..cc43214226 100644
--- a/system/btif/test/btif_rc_test.cc
+++ b/system/btif/test/btif_rc_test.cc
@@ -17,6 +17,7 @@
#undef LOG_TAG // Undefine the LOG_TAG by this compilation unit
#include "btif/src/btif_rc.cc"
+#include <bluetooth/log.h>
#include <gtest/gtest.h>
#include <cstdint>
@@ -80,19 +81,24 @@ namespace {
const RawAddress kDeviceAddress({0x11, 0x22, 0x33, 0x44, 0x55, 0x66});
} // namespace
-void btif_av_clear_remote_suspend_flag(void) {}
-bool btif_av_is_connected(void) { return true; }
+void btif_av_clear_remote_suspend_flag(const A2dpType local_a2dp_type) {}
+bool btif_av_is_connected(const A2dpType local_a2dp_type) { return true; }
bool btif_av_is_sink_enabled(void) { return true; }
RawAddress btif_av_sink_active_peer(void) { return RawAddress(); }
RawAddress btif_av_source_active_peer(void) { return RawAddress(); }
-bool btif_av_stream_started_ready(void) { return false; }
+bool btif_av_stream_started_ready(const A2dpType local_a2dp_type) {
+ return false;
+}
bt_status_t btif_transfer_context(tBTIF_CBACK* p_cback, uint16_t event,
char* p_params, int param_len,
tBTIF_COPY_CBACK* p_copy_cback) {
return BT_STATUS_SUCCESS;
}
bool btif_av_src_sink_coexist_enabled() { return true; }
-bool btif_av_is_connected_addr(const RawAddress& peer_address) { return true; }
+bool btif_av_is_connected_addr(const RawAddress& peer_address,
+ const A2dpType local_a2dp_type) {
+ return true;
+}
bool btif_av_peer_is_connected_sink(const RawAddress& peer_address) {
return false;
}
@@ -107,7 +113,7 @@ static bluetooth::common::MessageLoopThread jni_thread("bt_jni_thread");
bt_status_t do_in_jni_thread(const base::Location& from_here,
base::OnceClosure task) {
if (!jni_thread.DoInThread(from_here, std::move(task))) {
- LOG(ERROR) << __func__ << ": Post task to task runner failed!";
+ log::error("Post task to task runner failed!");
return BT_STATUS_FAIL;
}
return BT_STATUS_SUCCESS;
@@ -264,7 +270,7 @@ TEST_F(BtifRcWithCallbacksTest, handle_rc_ctrl_features) {
CHECK(std::future_status::ready == future.wait_for(std::chrono::seconds(2)));
auto res = future.get();
- LOG_INFO("FEATURES:%d", res.feature);
+ log::info("FEATURES:{}", res.feature);
CHECK(res.feature == (BTRC_FEAT_ABSOLUTE_VOLUME | BTRC_FEAT_METADATA |
BTRC_FEAT_BROWSE | BTRC_FEAT_COVER_ARTWORK));
}
diff --git a/system/gd/storage/storage_module.cc b/system/gd/storage/storage_module.cc
index febcf95a61..ff5eaab7e7 100644
--- a/system/gd/storage/storage_module.cc
+++ b/system/gd/storage/storage_module.cc
@@ -123,10 +123,22 @@ void StorageModule::SaveImmediately() {
}
// 1. rename old config to backup name
if (os::FileExists(config_file_path_)) {
+#ifndef TARGET_FLOSS
ASSERT(os::RenameFile(config_file_path_, config_backup_path_));
+#else
+ if (!os::RenameFile(config_file_path_, config_backup_path_)) {
+ LOG_ERROR("Unable to rename old config to back up name");
+ }
+#endif
}
// 2. write in-memory config to disk, if failed, backup can still be used
+#ifndef TARGET_FLOSS
ASSERT(LegacyConfigFile::FromPath(config_file_path_).Write(pimpl_->cache_));
+#else
+ if (!LegacyConfigFile::FromPath(config_file_path_).Write(pimpl_->cache_)) {
+ LOG_ERROR("Unable to write config file to disk");
+ }
+#endif
// 3. now write back up to disk as well
if (!LegacyConfigFile::FromPath(config_backup_path_).Write(pimpl_->cache_)) {
LOG_ERROR("Unable to write backup config file");
diff --git a/system/include/hardware/bluetooth.h b/system/include/hardware/bluetooth.h
index aabe594abc..683fb5525d 100644
--- a/system/include/hardware/bluetooth.h
+++ b/system/include/hardware/bluetooth.h
@@ -989,4 +989,20 @@ typedef struct {
#define BLUETOOTH_INTERFACE_STRING "bluetoothInterface"
+#if __has_include(<bluetooth/log.h>)
+#include <bluetooth/log.h>
+
+namespace fmt {
+template <>
+struct formatter<bt_status_t> : enum_formatter<bt_status_t> {};
+template <>
+struct formatter<bt_scan_mode_t> : enum_formatter<bt_scan_mode_t> {};
+template <>
+struct formatter<bt_bond_state_t> : enum_formatter<bt_bond_state_t> {};
+template <>
+struct formatter<bt_property_type_t> : enum_formatter<bt_property_type_t> {};
+} // namespace fmt
+
+#endif // __has_include(<bluetooth/log.h>)
+
#endif /* ANDROID_INCLUDE_BLUETOOTH_H */
diff --git a/system/include/hardware/bt_av.h b/system/include/hardware/bt_av.h
index 2a45af62d8..80512e34ed 100644
--- a/system/include/hardware/bt_av.h
+++ b/system/include/hardware/bt_av.h
@@ -436,6 +436,11 @@ __END_DECLS
namespace fmt {
template <>
+struct formatter<btav_connection_state_t>
+ : enum_formatter<btav_connection_state_t> {};
+template <>
+struct formatter<btav_audio_state_t> : enum_formatter<btav_audio_state_t> {};
+template <>
struct formatter<btav_a2dp_codec_bits_per_sample_t>
: enum_formatter<btav_a2dp_codec_bits_per_sample_t> {};
template <>
diff --git a/system/include/hardware/bt_hd.h b/system/include/hardware/bt_hd.h
index 0566e89455..732dc6168b 100644
--- a/system/include/hardware/bt_hd.h
+++ b/system/include/hardware/bt_hd.h
@@ -126,4 +126,14 @@ typedef struct {
__END_DECLS
+#if __has_include(<bluetooth/log.h>)
+#include <bluetooth/log.h>
+
+namespace fmt {
+template <>
+struct formatter<bthd_report_type_t> : enum_formatter<bthd_report_type_t> {};
+} // namespace fmt
+
+#endif // __has_include(<bluetooth/log.h>)
+
#endif /* ANDROID_INCLUDE_BT_HD_H */
diff --git a/system/include/hardware/bt_hf.h b/system/include/hardware/bt_hf.h
index e69e8412b4..074c896fec 100644
--- a/system/include/hardware/bt_hf.h
+++ b/system/include/hardware/bt_hf.h
@@ -144,8 +144,19 @@ namespace fmt {
template <>
struct formatter<bluetooth::headset::bthf_connection_state_t>
: enum_formatter<bluetooth::headset::bthf_connection_state_t> {};
-
template <>
struct formatter<bluetooth::headset::bthf_audio_state_t>
: enum_formatter<bluetooth::headset::bthf_audio_state_t> {};
+template <>
+struct formatter<bluetooth::headset::bthf_call_addrtype_t>
+ : enum_formatter<bluetooth::headset::bthf_call_addrtype_t> {};
+template <>
+struct formatter<bluetooth::headset::bthf_call_mode_t>
+ : enum_formatter<bluetooth::headset::bthf_call_mode_t> {};
+template <>
+struct formatter<bluetooth::headset::bthf_call_state_t>
+ : enum_formatter<bluetooth::headset::bthf_call_state_t> {};
+template <>
+struct formatter<bluetooth::headset::bthf_call_direction_t>
+ : enum_formatter<bluetooth::headset::bthf_call_direction_t> {};
} // namespace fmt
diff --git a/system/include/hardware/bt_hh.h b/system/include/hardware/bt_hh.h
index 3cedd88566..c9ee0a95f1 100644
--- a/system/include/hardware/bt_hh.h
+++ b/system/include/hardware/bt_hh.h
@@ -228,8 +228,14 @@ __END_DECLS
#include <bluetooth/log.h>
namespace fmt {
-template <> struct formatter<bthh_connection_state_t> :
-enum_formatter<bthh_connection_state_t> {};
+template <>
+struct formatter<bthh_connection_state_t>
+ : enum_formatter<bthh_connection_state_t> {};
+template <>
+struct formatter<bthh_protocol_mode_t> : enum_formatter<bthh_protocol_mode_t> {
+};
+template <>
+struct formatter<bthh_report_type_t> : enum_formatter<bthh_report_type_t> {};
} // namespace fmt
#endif // __has_include(<bluetooth/log.h>)
diff --git a/system/include/hardware/bt_rc.h b/system/include/hardware/bt_rc.h
index dc3179a292..8497939441 100644
--- a/system/include/hardware/bt_rc.h
+++ b/system/include/hardware/bt_rc.h
@@ -727,4 +727,22 @@ typedef struct {
__END_DECLS
+#if __has_include(<bluetooth/log.h>)
+#include <bluetooth/log.h>
+
+namespace fmt {
+template <>
+struct formatter<btrc_status_t> : enum_formatter<btrc_status_t> {};
+template <>
+struct formatter<btrc_event_id_t> : enum_formatter<btrc_event_id_t> {};
+template <>
+struct formatter<btrc_remote_features_t>
+ : enum_formatter<btrc_remote_features_t> {};
+template <>
+struct formatter<btrc_notification_type_t>
+ : enum_formatter<btrc_notification_type_t> {};
+} // namespace fmt
+
+#endif // __has_include(<bluetooth/log.h>)
+
#endif /* ANDROID_INCLUDE_BT_RC_H */
diff --git a/system/include/hardware/bt_sdp.h b/system/include/hardware/bt_sdp.h
index 77d00bd43d..fd4a970e05 100644
--- a/system/include/hardware/bt_sdp.h
+++ b/system/include/hardware/bt_sdp.h
@@ -178,3 +178,13 @@ typedef struct {
} btsdp_interface_t;
__END_DECLS
+
+#if __has_include(<bluetooth/log.h>)
+#include <bluetooth/log.h>
+
+namespace fmt {
+template <>
+struct formatter<bluetooth_sdp_types> : enum_formatter<bluetooth_sdp_types> {};
+} // namespace fmt
+
+#endif // __has_include(<bluetooth/log.h>)
diff --git a/system/include/hardware/bt_sock.h b/system/include/hardware/bt_sock.h
index 7d5060e005..47e53ca0da 100644
--- a/system/include/hardware/bt_sock.h
+++ b/system/include/hardware/bt_sock.h
@@ -110,3 +110,13 @@ typedef struct {
} btsock_interface_t;
__END_DECLS
+
+#if __has_include(<bluetooth/log.h>)
+#include <bluetooth/log.h>
+
+namespace fmt {
+template <>
+struct formatter<btsock_type_t> : enum_formatter<btsock_type_t> {};
+} // namespace fmt
+
+#endif // __has_include(<bluetooth/log.h>)
diff --git a/system/internal_include/bt_target.h b/system/internal_include/bt_target.h
index be8ddc3575..fff9a7043a 100644
--- a/system/internal_include/bt_target.h
+++ b/system/internal_include/bt_target.h
@@ -192,15 +192,6 @@
*
*****************************************************************************/
-/* Cancel Inquiry on incoming SSP */
-#ifndef BTM_NO_SSP_ON_INQUIRY
-#define BTM_NO_SSP_ON_INQUIRY FALSE
-#endif
-
-#ifndef DISABLE_WBS
-#define DISABLE_WBS FALSE
-#endif
-
/**************************
* Initial SCO TX credit
************************/
@@ -253,12 +244,6 @@
#define BTM_SEC_MAX_SERVICE_RECORDS 32
#endif
-/* If True, force a retrieval of remote device name for each bond in case it's
- * changed */
-#ifndef BTM_SEC_FORCE_RNR_FOR_DBOND
-#define BTM_SEC_FORCE_RNR_FOR_DBOND FALSE
-#endif
-
/* Maximum device name length used in btm database. */
#ifndef BTM_MAX_REM_BD_NAME_LEN
#define BTM_MAX_REM_BD_NAME_LEN 248
@@ -269,11 +254,6 @@
#define BTM_MAX_LOC_BD_NAME_LEN 248
#endif
-/* Maximum service name stored with security authorization (0 if not needed) */
-#ifndef BTM_SEC_SERVICE_NAME_LEN
-#define BTM_SEC_SERVICE_NAME_LEN BT_MAX_SERVICE_NAME_LEN
-#endif
-
/* Maximum length of the service name. */
#ifndef BT_MAX_SERVICE_NAME_LEN
#define BT_MAX_SERVICE_NAME_LEN 21
@@ -300,10 +280,6 @@
/******************************************
* Lisbon Features
******************************************/
-/* This is set to TRUE if the FEC is required for EIR packet. */
-#ifndef BTM_EIR_DEFAULT_FEC_REQUIRED
-#define BTM_EIR_DEFAULT_FEC_REQUIRED TRUE
-#endif
/* The IO capability of the local device (for Simple Pairing) */
#ifndef BTM_LOCAL_IO_CAPS
@@ -400,10 +376,6 @@
*
*****************************************************************************/
-#ifndef LOCAL_BLE_CONTROLLER_ID
-#define LOCAL_BLE_CONTROLLER_ID 1
-#endif
-
/* The maximum number of simultaneous applications that can register with LE
* L2CAP. */
#ifndef BLE_MAX_L2CAP_CLIENTS
@@ -476,11 +448,7 @@
Prefer greater than 0 second, and no less than default inactivity link idle
timer(L2CAP_LINK_INACTIVITY_TOUT) in l2cap) */
#ifndef SMP_LINK_TOUT_MIN
-#if (L2CAP_LINK_INACTIVITY_TOUT > 0)
#define SMP_LINK_TOUT_MIN L2CAP_LINK_INACTIVITY_TOUT
-#else
-#define SMP_LINK_TOUT_MIN 2
-#endif
#endif
/******************************************************************************
*
@@ -609,11 +577,6 @@
#define PORT_TX_BUF_CRITICAL_WM 15
#endif
-/* The RFCOMM multiplexer preferred flow control mechanism. */
-#ifndef PORT_FC_DEFAULT
-#define PORT_FC_DEFAULT PORT_FC_CREDIT
-#endif
-
/******************************************************************************
*
* BNEP
@@ -820,16 +783,6 @@
/******************************************************************************
*
- * AVRCP
- *
- *****************************************************************************/
-
-#ifndef DUMP_PCM_DATA
-#define DUMP_PCM_DATA FALSE
-#endif
-
-/******************************************************************************
- *
* BTA
*
*****************************************************************************/
diff --git a/system/log/src/vlog_android.cc b/system/log/src/vlog_android.cc
index e5ca8f1fc8..0f235b0b6f 100644
--- a/system/log/src/vlog_android.cc
+++ b/system/log/src/vlog_android.cc
@@ -33,8 +33,13 @@ void vlog(Level level, char const* tag, char const* file_name, int line,
}
// Format to stack buffer.
+ // liblog uses a different default depending on the execution context
+ // (host or device); the file and line are not systematically included.
+ // In order to have consistent logs we include it manually in the log
+ // message.
truncating_buffer<kBufferSize> buffer;
- fmt::format_to(std::back_insert_iterator(buffer), "{}: ", function_name);
+ fmt::format_to(std::back_insert_iterator(buffer), "{}:{} {}: ", file_name,
+ line, function_name);
fmt::vformat_to(std::back_insert_iterator(buffer), fmt, vargs);
// Send message to liblog.
@@ -43,8 +48,8 @@ void vlog(Level level, char const* tag, char const* file_name, int line,
.buffer_id = LOG_ID_MAIN,
.priority = static_cast<android_LogPriority>(level),
.tag = tag,
- .file = file_name,
- .line = static_cast<uint32_t>(line),
+ .file = nullptr,
+ .line = 0,
.message = buffer.c_str(),
};
__android_log_write_log_message(&message);
diff --git a/system/log/src/vlog_test.cc b/system/log/src/vlog_test.cc
index f5f41b6c5d..5e341c7a33 100644
--- a/system/log/src/vlog_test.cc
+++ b/system/log/src/vlog_test.cc
@@ -51,10 +51,11 @@ TEST(BluetoothLoggerTest, verbose) {
ASSERT_TRUE(androidLogMessage.has_value());
EXPECT_EQ(androidLogMessage->priority, ANDROID_LOG_VERBOSE);
EXPECT_STREQ(androidLogMessage->tag, LOG_TAG);
- EXPECT_STREQ(androidLogMessage->file,
- "packages/modules/Bluetooth/system/log/src/vlog_test.cc");
- EXPECT_EQ(androidLogMessage->line, 49);
- EXPECT_STREQ(androidLogMessage->message, "TestBody: verbose test");
+ EXPECT_EQ(androidLogMessage->file, nullptr);
+ EXPECT_EQ(androidLogMessage->line, 0);
+ EXPECT_STREQ(androidLogMessage->message,
+ "packages/modules/Bluetooth/system/log/src/vlog_test.cc:49 "
+ "TestBody: verbose test");
}
TEST(BluetoothLoggerTest, debug) {
@@ -65,10 +66,11 @@ TEST(BluetoothLoggerTest, debug) {
ASSERT_TRUE(androidLogMessage.has_value());
EXPECT_EQ(androidLogMessage->priority, ANDROID_LOG_DEBUG);
EXPECT_STREQ(androidLogMessage->tag, LOG_TAG);
- EXPECT_STREQ(androidLogMessage->file,
- "packages/modules/Bluetooth/system/log/src/vlog_test.cc");
- EXPECT_EQ(androidLogMessage->line, 63);
- EXPECT_STREQ(androidLogMessage->message, "TestBody: debug test");
+ EXPECT_STREQ(androidLogMessage->file, nullptr);
+ EXPECT_EQ(androidLogMessage->line, 0);
+ EXPECT_STREQ(androidLogMessage->message,
+ "packages/modules/Bluetooth/system/log/src/vlog_test.cc:64 "
+ "TestBody: debug test");
}
TEST(BluetoothLoggerTest, info) {
@@ -79,10 +81,11 @@ TEST(BluetoothLoggerTest, info) {
ASSERT_TRUE(androidLogMessage.has_value());
EXPECT_EQ(androidLogMessage->priority, ANDROID_LOG_INFO);
EXPECT_STREQ(androidLogMessage->tag, LOG_TAG);
- EXPECT_STREQ(androidLogMessage->file,
- "packages/modules/Bluetooth/system/log/src/vlog_test.cc");
- EXPECT_EQ(androidLogMessage->line, 77);
- EXPECT_STREQ(androidLogMessage->message, "TestBody: info test");
+ EXPECT_STREQ(androidLogMessage->file, nullptr);
+ EXPECT_EQ(androidLogMessage->line, 0);
+ EXPECT_STREQ(androidLogMessage->message,
+ "packages/modules/Bluetooth/system/log/src/vlog_test.cc:79 "
+ "TestBody: info test");
}
TEST(BluetoothLoggerTest, warn) {
@@ -93,10 +96,11 @@ TEST(BluetoothLoggerTest, warn) {
ASSERT_TRUE(androidLogMessage.has_value());
EXPECT_EQ(androidLogMessage->priority, ANDROID_LOG_WARN);
EXPECT_STREQ(androidLogMessage->tag, LOG_TAG);
- EXPECT_STREQ(androidLogMessage->file,
- "packages/modules/Bluetooth/system/log/src/vlog_test.cc");
- EXPECT_EQ(androidLogMessage->line, 91);
- EXPECT_STREQ(androidLogMessage->message, "TestBody: warn test");
+ EXPECT_STREQ(androidLogMessage->file, nullptr);
+ EXPECT_EQ(androidLogMessage->line, 0);
+ EXPECT_STREQ(androidLogMessage->message,
+ "packages/modules/Bluetooth/system/log/src/vlog_test.cc:94 "
+ "TestBody: warn test");
}
TEST(BluetoothLoggerTest, error) {
@@ -107,10 +111,11 @@ TEST(BluetoothLoggerTest, error) {
ASSERT_TRUE(androidLogMessage.has_value());
EXPECT_EQ(androidLogMessage->priority, ANDROID_LOG_ERROR);
EXPECT_STREQ(androidLogMessage->tag, LOG_TAG);
- EXPECT_STREQ(androidLogMessage->file,
- "packages/modules/Bluetooth/system/log/src/vlog_test.cc");
- EXPECT_EQ(androidLogMessage->line, 105);
- EXPECT_STREQ(androidLogMessage->message, "TestBody: error test");
+ EXPECT_STREQ(androidLogMessage->file, nullptr);
+ EXPECT_EQ(androidLogMessage->line, 0);
+ EXPECT_STREQ(androidLogMessage->message,
+ "packages/modules/Bluetooth/system/log/src/vlog_test.cc:109 "
+ "TestBody: error test");
}
TEST(BluetoothLoggerTest, null_string_parameter) {
@@ -118,17 +123,23 @@ TEST(BluetoothLoggerTest, null_string_parameter) {
char const* const_null_str = nullptr;
log::info("input: {}", const_null_str);
- EXPECT_STREQ(androidLogMessage->message, "TestBody: input: (nullptr)");
+ EXPECT_STREQ(androidLogMessage->message,
+ "packages/modules/Bluetooth/system/log/src/vlog_test.cc:125 "
+ "TestBody: input: (nullptr)");
androidLogMessage.reset();
char* null_str = nullptr;
log::info("input: {}", null_str);
- EXPECT_STREQ(androidLogMessage->message, "TestBody: input: (nullptr)");
+ EXPECT_STREQ(androidLogMessage->message,
+ "packages/modules/Bluetooth/system/log/src/vlog_test.cc:133 "
+ "TestBody: input: (nullptr)");
androidLogMessage.reset();
char const* nonnull_str = "hello world";
log::info("input: {}", nonnull_str);
- EXPECT_STREQ(androidLogMessage->message, "TestBody: input: hello world");
+ EXPECT_STREQ(androidLogMessage->message,
+ "packages/modules/Bluetooth/system/log/src/vlog_test.cc:141 "
+ "TestBody: input: hello world");
}
diff --git a/system/stack/Android.bp b/system/stack/Android.bp
index ae8e45b431..969a0a674e 100644
--- a/system/stack/Android.bp
+++ b/system/stack/Android.bp
@@ -137,6 +137,7 @@ cc_library_static {
"pan/pan_utils.cc",
],
static_libs: [
+ "bluetooth_flags_c_lib",
"libbluetooth_crypto_toolbox",
"libbluetooth_hci_pdl",
"libbluetooth_log",
@@ -336,6 +337,8 @@ cc_defaults {
],
static_libs: [
"libchrome",
+ "libgmock",
+ "libgtest",
],
shared_libs: [
"libbase",
@@ -465,7 +468,6 @@ cc_fuzz {
"libbt-platform-protos-lite",
"libbt_shim_bridge",
"libbt_shim_ffi",
- "libgmock",
],
}
@@ -515,7 +517,6 @@ cc_fuzz {
"libbt-platform-protos-lite",
"libbt_shim_bridge",
"libbt_shim_ffi",
- "libgmock",
],
}
@@ -560,7 +561,6 @@ cc_fuzz {
"libbt-platform-protos-lite",
"libbt_shim_bridge",
"libbt_shim_ffi",
- "libgmock",
],
}
@@ -598,7 +598,11 @@ cc_fuzz {
"avrc/*.cc",
"fuzzers/avrc_fuzzer.cc",
],
+ shared_libs: [
+ "server_configurable_flags",
+ ],
static_libs: [
+ "bluetooth_flags_c_lib",
"libbase",
"libbluetooth-types",
"libbluetooth_hci_pdl",
@@ -609,7 +613,6 @@ cc_fuzz {
"libbt_shim_bridge",
"libbt_shim_ffi",
"libcom.android.sysprop.bluetooth.wrapped",
- "libgmock",
],
}
@@ -645,6 +648,7 @@ cc_fuzz {
"l2cap/*.cc",
],
static_libs: [
+ "bluetooth_flags_c_lib",
"libbluetooth-types",
"libbluetooth_hci_pdl",
"libbluetooth_l2cap_pdl",
@@ -653,7 +657,9 @@ cc_fuzz {
"libbt-platform-protos-lite",
"libbt_shim_bridge",
"libbt_shim_ffi",
- "libgmock",
+ ],
+ shared_libs: [
+ "server_configurable_flags",
],
target: {
android: {
@@ -2141,6 +2147,7 @@ cc_test {
":TestMockStackBtm",
":TestMockStackL2cap",
":TestMockStackMetrics",
+ "test/sdp/stack_sdp_db_test.cc",
"test/sdp/stack_sdp_test.cc",
"test/sdp/stack_sdp_utils_test.cc",
],
diff --git a/system/stack/a2dp/a2dp_aac_encoder_linux.cc b/system/stack/a2dp/a2dp_aac_encoder_linux.cc
index f374bcf18d..d8dd1db065 100644
--- a/system/stack/a2dp/a2dp_aac_encoder_linux.cc
+++ b/system/stack/a2dp/a2dp_aac_encoder_linux.cc
@@ -39,6 +39,8 @@ const int A2DP_AAC_MAX_LEN_REPR = 4;
const int A2DP_AAC_MAX_PREFIX_SIZE =
AVDT_MEDIA_HDR_SIZE + A2DP_AAC_HEADER_LEN + A2DP_AAC_MAX_LEN_REPR;
+using namespace bluetooth;
+
class FFmpegInterface {
public:
// Updates the context and configures codec parameters.
diff --git a/system/stack/avct/avct_lcb_act.cc b/system/stack/avct/avct_lcb_act.cc
index 2aa38d56f8..c660d30843 100644
--- a/system/stack/avct/avct_lcb_act.cc
+++ b/system/stack/avct/avct_lcb_act.cc
@@ -21,6 +21,7 @@
* This module contains action functions of the link control state machine.
*
******************************************************************************/
+#include <android_bluetooth_flags.h>
#include <android_bluetooth_sysprop.h>
#include <bluetooth/log.h>
#include <string.h>
@@ -718,9 +719,12 @@ bool avct_msg_ind_for_src_sink_coexist(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data,
tAVCT_CCB* p_ccb;
int p_buf_len;
uint8_t* p;
- uint16_t pid;
+ uint16_t pid, type;
p = (uint8_t*)(p_data->p_buf + 1) + p_data->p_buf->offset;
+ if (IS_FLAG_ENABLED(a2dp_concurrent_source_sink)) {
+ AVCT_PARSE_HDR(p, label, type, cr_ipid);
+ }
BE_STREAM_TO_UINT16(pid, p);
diff --git a/system/stack/btm/btm_inq.cc b/system/stack/btm/btm_inq.cc
index 5cb52a7819..ba8db4128f 100644
--- a/system/stack/btm/btm_inq.cc
+++ b/system/stack/btm/btm_inq.cc
@@ -1084,7 +1084,6 @@ void btm_inq_db_init(void) {
alarm_free(btm_cb.btm_inq_vars.remote_name_timer);
btm_cb.btm_inq_vars.remote_name_timer =
alarm_new("btm_inq.remote_name_timer");
- btm_cb.btm_inq_vars.no_inc_ssp = BTM_NO_SSP_ON_INQUIRY;
btm_inq_db_set_inq_by_rssi();
}
@@ -1098,43 +1097,6 @@ void btm_inq_db_set_inq_by_rssi(void) {
/*******************************************************************************
*
- * Function btm_inq_stop_on_ssp
- *
- * Description This function is called on incoming SSP
- *
- * Returns void
- *
- ******************************************************************************/
-void btm_inq_stop_on_ssp(void) {
- uint8_t normal_active = (BTM_GENERAL_INQUIRY_ACTIVE);
-
-#if (BTM_INQ_DEBUG == TRUE)
- log::verbose("btm_inq_stop_on_ssp: no_inc_ssp={} inq_active:0x{:x} state:{} ",
- btm_cb.btm_inq_vars.no_inc_ssp, btm_cb.btm_inq_vars.inq_active,
- btm_cb.btm_inq_vars.state);
-#endif
- if (btm_cb.btm_inq_vars.no_inc_ssp) {
- if (btm_cb.btm_inq_vars.state == BTM_INQ_ACTIVE_STATE) {
- if (btm_cb.btm_inq_vars.inq_active & normal_active) {
- /* can not call BTM_CancelInquiry() here. We need to report inquiry
- * complete evt */
- bluetooth::shim::GetHciLayer()->EnqueueCommand(
- bluetooth::hci::InquiryCancelBuilder::Create(),
- get_main_thread()->BindOnce(
- [](bluetooth::hci::CommandCompleteView complete_view) {
- bluetooth::hci::check_complete<
- bluetooth::hci::InquiryCancelCompleteView>(complete_view);
- btm_process_cancel_complete(HCI_SUCCESS, BTM_BR_INQUIRY_MASK);
- }));
- }
- }
- /* do not allow inquiry to start */
- btm_cb.btm_inq_vars.inq_active |= BTM_SSP_INQUIRY_ACTIVE;
- }
-}
-
-/*******************************************************************************
- *
* Function btm_inq_clear_ssp
*
* Description This function is called when pairing_state becomes idle
@@ -2105,7 +2067,7 @@ void btm_inq_rmt_name_failed_cancelled(void) {
tBTM_STATUS BTM_WriteEIR(BT_HDR* p_buff) {
if (bluetooth::shim::GetController()->SupportsExtendedInquiryResponse()) {
log::verbose("Write Extended Inquiry Response to controller");
- btsnd_hcic_write_ext_inquiry_response(p_buff, BTM_EIR_DEFAULT_FEC_REQUIRED);
+ btsnd_hcic_write_ext_inquiry_response(p_buff, TRUE);
return BTM_SUCCESS;
} else {
osi_free(p_buff);
diff --git a/system/stack/btm/btm_sco_hfp_hal.cc b/system/stack/btm/btm_sco_hfp_hal.cc
index e10a92148d..058afba3fb 100644
--- a/system/stack/btm/btm_sco_hfp_hal.cc
+++ b/system/stack/btm/btm_sco_hfp_hal.cc
@@ -54,7 +54,7 @@ bool is_coding_format_supported(esco_coding_format_t coding_format) {
}
// Android statically compiles WBS support.
-bool get_wbs_supported() { return !DISABLE_WBS; }
+bool get_wbs_supported() { return true; }
bool get_swb_supported() {
return osi_property_get_bool("bluetooth.hfp.swb.supported", false) &&
@@ -93,7 +93,7 @@ bool enable_offload(bool enable) {
void set_codec_datapath(int codec_uuid) {}
// No packet size limits on Android since it will be offloaded.
-int get_packet_size(int codec) { return kDefaultPacketSize; }
+size_t get_packet_size(int codec) { return kDefaultPacketSize; }
void notify_sco_connection_change(RawAddress device, bool is_connected,
int codec) {
diff --git a/system/stack/btm/btm_sco_hfp_hal.h b/system/stack/btm/btm_sco_hfp_hal.h
index 624f387bc4..463c230fbe 100644
--- a/system/stack/btm/btm_sco_hfp_hal.h
+++ b/system/stack/btm/btm_sco_hfp_hal.h
@@ -48,7 +48,7 @@ struct bt_codecs {
};
// Use default packet size for codec if this value is given.
-constexpr int kDefaultPacketSize = 0;
+constexpr size_t kDefaultPacketSize = 0;
constexpr inline int esco_coding_to_codec(esco_coding_format_t esco_coding) {
switch (esco_coding) {
@@ -94,7 +94,7 @@ bool enable_offload(bool enable);
void set_codec_datapath(int codec_uuid);
// Get the maximum supported packet size from the lower layer.
-int get_packet_size(int codec);
+size_t get_packet_size(int codec);
// Notify the lower layer about SCO connection change.
void notify_sco_connection_change(RawAddress device, bool is_connected,
diff --git a/system/stack/btm/btm_sco_hfp_hal_linux.cc b/system/stack/btm/btm_sco_hfp_hal_linux.cc
index 122a22339f..7dfa0ea243 100644
--- a/system/stack/btm/btm_sco_hfp_hal_linux.cc
+++ b/system/stack/btm/btm_sco_hfp_hal_linux.cc
@@ -38,17 +38,9 @@ namespace {
bool offload_supported = false;
bool offload_enabled = false;
-struct mgmt_bt_codec {
- uint8_t codec;
- uint8_t packet_size;
- uint8_t data_path;
- uint32_t data_length;
- uint8_t data[];
-} __attribute__((packed));
-
typedef struct cached_codec_info {
struct bt_codec inner;
- uint8_t pkt_size;
+ size_t pkt_size;
} cached_codec_info;
std::vector<cached_codec_info> cached_codecs;
@@ -93,46 +85,41 @@ struct mgmt_rp_get_codec_capabilities {
#define MGMT_POLL_TIMEOUT_MS 2000
void cache_codec_capabilities(struct mgmt_rp_get_codec_capabilities* rp) {
- const uint8_t kCodecCvsd = 0x2;
- const uint8_t kCodecTransparent = 0x3;
const uint8_t kCodecMsbc = 0x5;
+ // TODO(b/323087725): Query the codec capabilities and fill in c.inner.data.
+ // The capabilities are not used currently so it's safe to keep this for a
+ // while.
+
+ // CVSD is mandatory in HFP.
+ cached_codecs.push_back({
+ .inner = {.codec = codec::CVSD},
+ });
+
+ // No need to check GetLocalSupportedBrEdrCodecIds. Some legacy devices don't
+ // even support HCI command Read Local Supported Codecs so WBS quirk is more
+ // reliable.
+ if (rp->transparent_wbs_supported) {
+ cached_codecs.push_back({
+ .inner = {.codec = codec::MSBC_TRANSPARENT},
+ .pkt_size = rp->wbs_pkt_len,
+ });
+ }
+
auto codecs =
bluetooth::shim::GetController()->GetLocalSupportedBrEdrCodecIds();
+ if (std::find(codecs.begin(), codecs.end(), kCodecMsbc) != codecs.end()) {
+ offload_supported = true;
+ cached_codecs.push_back({
+ .inner = {.codec = codec::MSBC, .data_path = rp->hci_data_path_id},
+ .pkt_size = rp->wbs_pkt_len,
+ });
+ }
- for (uint8_t codec_id : codecs) {
- // TODO(b/323087725): Query the codec capabilities and fill in c.inner.data.
- // The capabilities are not used currently so it's safe to keep this for a
- // while.
- cached_codec_info c{};
- switch (codec_id) {
- case kCodecCvsd:
- c.inner.codec = codec::CVSD;
- break;
- case kCodecTransparent:
- if (!rp->transparent_wbs_supported) {
- // Transparent wideband speech not supported, skip it.
- continue;
- }
- c.inner.codec = codec::MSBC_TRANSPARENT;
- c.pkt_size = rp->wbs_pkt_len;
- break;
- case kCodecMsbc:
- offload_supported = true;
- c.inner.codec = codec::MSBC;
- c.inner.data_path = rp->hci_data_path_id;
- c.pkt_size = rp->wbs_pkt_len;
- break;
- default:
- log::debug("Unsupported codec ID: {}", codec_id);
- continue;
- }
-
+ for (const auto& c : cached_codecs) {
log::info("Caching HFP codec {}, data path {}, data len {}, pkt_size {}",
(uint64_t)c.inner.codec, c.inner.data_path, c.inner.data.size(),
c.pkt_size);
-
- cached_codecs.push_back(c);
}
}
@@ -451,7 +438,7 @@ void set_codec_datapath(int codec_uuid) {
}
}
-int get_packet_size(int codec) {
+size_t get_packet_size(int codec) {
for (const cached_codec_info& c : cached_codecs) {
if (c.inner.codec == codec) {
return c.pkt_size;
diff --git a/system/stack/btm/btm_sec.cc b/system/stack/btm/btm_sec.cc
index 91bb7f669d..2d96c926b4 100644
--- a/system/stack/btm/btm_sec.cc
+++ b/system/stack/btm/btm_sec.cc
@@ -93,7 +93,6 @@ extern tBTM_CB btm_cb;
(BTM_SEC_LE_AUTHENTICATED | BTM_SEC_LE_ENCRYPTED | \
BTM_SEC_LE_LINK_KEY_KNOWN | BTM_SEC_LE_LINK_KEY_AUTHED)
-void btm_inq_stop_on_ssp(void);
bool btm_ble_init_pseudo_addr(tBTM_SEC_DEV_REC* p_dev_rec,
const RawAddress& new_pseudo_addr);
void bta_dm_remove_device(const RawAddress& bd_addr);
@@ -690,10 +689,6 @@ tBTM_STATUS btm_sec_bond_by_transport(const RawAddress& bd_addr,
log::verbose("BTM_SecBond: Remote sm4: 0x{:x} HCI Handle: 0x{:04x}",
p_dev_rec->sm4, p_dev_rec->hci_handle);
-#if (BTM_SEC_FORCE_RNR_FOR_DBOND == TRUE)
- p_dev_rec->sec_rec.sec_flags &= ~BTM_SEC_NAME_KNOWN;
-#endif
-
/* If connection already exists... */
if (BTM_IsAclConnectionUpAndHandleValid(bd_addr, transport)) {
btm_sec_wait_and_start_authentication(p_dev_rec);
@@ -2646,9 +2641,6 @@ void btm_io_capabilities_rsp(const tBTM_SP_IO_RSP evt_data) {
btm_sec_cb.pairing_bda = evt_data.bd_addr;
btm_sec_cb.change_pairing_state(BTM_PAIR_STATE_INCOMING_SSP);
-
- /* work around for FW bug */
- btm_inq_stop_on_ssp();
}
/* Notify L2CAP to increase timeout */
diff --git a/system/stack/btm/neighbor_inquiry.h b/system/stack/btm/neighbor_inquiry.h
index c667b24e84..4c9f9a9544 100644
--- a/system/stack/btm/neighbor_inquiry.h
+++ b/system/stack/btm/neighbor_inquiry.h
@@ -264,7 +264,6 @@ struct tBTM_INQUIRY_VAR_ST {
uint8_t state; /* Current state that the inquiry process is in */
uint8_t inq_active; /* Bit Mask indicating type of inquiry is active */
- bool no_inc_ssp; /* true, to stop inquiry on incoming SSP */
bool registered_for_hci_events;
@@ -300,7 +299,6 @@ struct tBTM_INQUIRY_VAR_ST {
per_max_delay = 0;
state = BTM_INQ_INACTIVE_STATE;
inq_active = 0;
- no_inc_ssp = BTM_NO_SSP_ON_INQUIRY;
registered_for_hci_events = false;
}
void Free() {
diff --git a/system/stack/gatt/gatt_main.cc b/system/stack/gatt/gatt_main.cc
index c09cbc6d0e..2c545d4018 100644
--- a/system/stack/gatt/gatt_main.cc
+++ b/system/stack/gatt/gatt_main.cc
@@ -318,8 +318,8 @@ bool gatt_disconnect(tGATT_TCB* p_tcb) {
* when it already exists, false otherwise.
*
******************************************************************************/
-bool gatt_update_app_hold_link_status(tGATT_IF gatt_if, tGATT_TCB* p_tcb,
- bool is_add) {
+static bool gatt_update_app_hold_link_status(tGATT_IF gatt_if, tGATT_TCB* p_tcb,
+ bool is_add) {
log::debug("gatt_if={}, is_add={}, peer_bda={}", gatt_if, is_add,
ADDRESS_TO_LOGGABLE_CSTR(p_tcb->peer_bda));
auto& holders = p_tcb->app_hold_link;
diff --git a/system/stack/include/btm_sec_api_types.h b/system/stack/include/btm_sec_api_types.h
index 341cadc5a0..77985ec4e5 100644
--- a/system/stack/include/btm_sec_api_types.h
+++ b/system/stack/include/btm_sec_api_types.h
@@ -529,4 +529,6 @@ inline std::string bond_type_text(const tBTM_BOND_TYPE& bond_type) {
namespace fmt {
template <>
struct formatter<tBTM_BLE_SEC_ACT> : enum_formatter<tBTM_BLE_SEC_ACT> {};
+template <>
+struct formatter<tBTM_BOND_TYPE> : enum_formatter<tBTM_BOND_TYPE> {};
} // namespace fmt
diff --git a/system/stack/include/security_client_callbacks.h b/system/stack/include/security_client_callbacks.h
index d07b08d3bf..c4de3db415 100644
--- a/system/stack/include/security_client_callbacks.h
+++ b/system/stack/include/security_client_callbacks.h
@@ -31,8 +31,7 @@
* Security Manager Callback Functions
****************************************/
/* Authorize device for service. Parameters are
- * Service Id (NULL - unknown service or unused
- * [BTM_SEC_SERVICE_NAME_LEN set to 0])
+ * Service Id (NULL - unknown service or unused)
*/
typedef uint8_t(tBTM_AUTHORIZE_CALLBACK)(uint8_t service_id);
diff --git a/system/stack/l2cap/l2c_link.cc b/system/stack/l2cap/l2c_link.cc
index 9279a66311..b1463418c4 100644
--- a/system/stack/l2cap/l2c_link.cc
+++ b/system/stack/l2cap/l2c_link.cc
@@ -25,6 +25,7 @@
******************************************************************************/
#define LOG_TAG "l2c_link"
+#include <android_bluetooth_flags.h>
#include <bluetooth/log.h>
#include <cstdint>
@@ -214,27 +215,60 @@ void l2c_link_sec_comp(const RawAddress* p_bda,
return;
}
- /* Match p_ccb with p_ref_data returned by sec manager */
- for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; p_ccb = p_next_ccb) {
- p_next_ccb = p_ccb->p_next_ccb;
+ if (IS_FLAG_ENABLED(l2cap_p_ccb_check_rewrite)) {
+ if (!p_ref_data) {
+ log::warn("Argument p_ref_data is NULL");
+ return;
+ }
- if (p_ccb == p_ref_data) {
- switch (status) {
- case BTM_SUCCESS:
- l2c_csm_execute(p_ccb, L2CEVT_SEC_COMP, &ci);
- break;
+ /* Match p_ccb with p_ref_data returned by sec manager */
+ p_ccb = (tL2C_CCB*)p_ref_data;
+
+ if (p_lcb != p_ccb->p_lcb) {
+ log::warn("p_ref_data doesn't match with sec manager record");
+ return;
+ }
- case BTM_DELAY_CHECK:
- /* start a timer - encryption change not received before L2CAP connect
- * req */
- alarm_set_on_mloop(p_ccb->l2c_ccb_timer,
- L2CAP_DELAY_CHECK_SM4_TIMEOUT_MS,
- l2c_ccb_timer_timeout, p_ccb);
- return;
+ switch (status) {
+ case BTM_SUCCESS:
+ l2c_csm_execute(p_ccb, L2CEVT_SEC_COMP, &ci);
+ break;
- default:
- l2c_csm_execute(p_ccb, L2CEVT_SEC_COMP_NEG, &ci);
- break;
+ case BTM_DELAY_CHECK:
+ /* start a timer - encryption change not received before L2CAP connect
+ * req */
+ alarm_set_on_mloop(p_ccb->l2c_ccb_timer,
+ L2CAP_DELAY_CHECK_SM4_TIMEOUT_MS,
+ l2c_ccb_timer_timeout, p_ccb);
+ return;
+
+ default:
+ l2c_csm_execute(p_ccb, L2CEVT_SEC_COMP_NEG, &ci);
+ break;
+ }
+ } else {
+ /* Match p_ccb with p_ref_data returned by sec manager */
+ for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; p_ccb = p_next_ccb) {
+ p_next_ccb = p_ccb->p_next_ccb;
+
+ if (p_ccb == p_ref_data) {
+ switch (status) {
+ case BTM_SUCCESS:
+ l2c_csm_execute(p_ccb, L2CEVT_SEC_COMP, &ci);
+ break;
+
+ case BTM_DELAY_CHECK:
+ /* start a timer - encryption change not received before L2CAP
+ * connect req */
+ alarm_set_on_mloop(p_ccb->l2c_ccb_timer,
+ L2CAP_DELAY_CHECK_SM4_TIMEOUT_MS,
+ l2c_ccb_timer_timeout, p_ccb);
+ return;
+
+ default:
+ l2c_csm_execute(p_ccb, L2CEVT_SEC_COMP_NEG, &ci);
+ break;
+ }
}
}
}
diff --git a/system/stack/mmc/codec_server/BUILD.gn b/system/stack/mmc/codec_server/BUILD.gn
index 7cb958ef28..5adfac90e3 100644
--- a/system/stack/mmc/codec_server/BUILD.gn
+++ b/system/stack/mmc/codec_server/BUILD.gn
@@ -18,6 +18,7 @@ source_set("libcodec_server_a2dp_aac") {
configs += [
"//bt/system:target_defaults",
"//bt/system/stack/mmc:target_defaults",
+ "//bt/system/log:log_defaults",
]
include_dirs = [
"//bt/system",
diff --git a/system/stack/rfcomm/port_rfc.cc b/system/stack/rfcomm/port_rfc.cc
index 973740bf79..140efd69c4 100644
--- a/system/stack/rfcomm/port_rfc.cc
+++ b/system/stack/rfcomm/port_rfc.cc
@@ -320,8 +320,7 @@ void PORT_ParNegInd(tRFC_MCB* p_mcb, uint8_t dlci, uint16_t mtu, uint8_t cl,
*/
/* already defined for this mux, we respond with that value. */
if (p_mcb->flow == PORT_FC_UNDEFINED) {
- if ((PORT_FC_DEFAULT == PORT_FC_TS710) ||
- (cl == RFCOMM_PN_CONV_LAYER_TYPE_1)) {
+ if (cl == RFCOMM_PN_CONV_LAYER_TYPE_1) {
p_mcb->flow = PORT_FC_TS710;
} else {
p_mcb->flow = PORT_FC_CREDIT;
@@ -380,16 +379,7 @@ void PORT_ParNegCnf(tRFC_MCB* p_mcb, uint8_t dlci, uint16_t mtu, uint8_t cl,
/* Flow control mechanism not set yet. Negotiate flow control mechanism. */
if (p_mcb->flow == PORT_FC_UNDEFINED) {
- /* Our stack is configured for TS07.10 and they responded with credit-based.
- */
- /* This is illegal-- negotiation fails. */
- if ((PORT_FC_DEFAULT == PORT_FC_TS710) &&
- (cl == RFCOMM_PN_CONV_LAYER_CBFC_R)) {
- log::warn("negotiation fails, index={}", p_port->handle);
- rfc_send_disc(p_mcb, p_port->dlci);
- rfc_port_closed(p_port);
- return;
- } else if (cl == RFCOMM_PN_CONV_LAYER_CBFC_R) {
+ if (cl == RFCOMM_PN_CONV_LAYER_CBFC_R) {
// Our stack is configured for credit-based and they responded with
// credit-based.
p_mcb->flow = PORT_FC_CREDIT;
diff --git a/system/stack/rfcomm/rfc_port_if.cc b/system/stack/rfcomm/rfc_port_if.cc
index ca7eb8f33d..5144985ec8 100644
--- a/system/stack/rfcomm/rfc_port_if.cc
+++ b/system/stack/rfcomm/rfc_port_if.cc
@@ -147,10 +147,10 @@ void RFCOMM_ParameterNegotiationRequest(tRFC_MCB* p_mcb, uint8_t dlci,
return;
}
- /* Negotiate the flow control mechanism. If flow control mechanism for */
- /* mux has not been set yet, use our default value. If it has been set, */
- /* use that value. */
- flow = (p_mcb->flow == PORT_FC_UNDEFINED) ? PORT_FC_DEFAULT : p_mcb->flow;
+ /* Negotiate the flow control mechanism. If flow control mechanism for the
+ * mux has not been set yet, use credits. If it has been set, use that value.
+ */
+ flow = (p_mcb->flow == PORT_FC_UNDEFINED) ? PORT_FC_CREDIT : p_mcb->flow;
/* Set convergence layer and number of credits (k) */
if (flow == PORT_FC_CREDIT) {
diff --git a/system/stack/test/sdp/stack_sdp_db_test.cc b/system/stack/test/sdp/stack_sdp_db_test.cc
new file mode 100644
index 0000000000..8b07ac43de
--- /dev/null
+++ b/system/stack/test/sdp/stack_sdp_db_test.cc
@@ -0,0 +1,198 @@
+/*
+ * Copyright 2022 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.
+ */
+
+#include <gtest/gtest.h>
+
+#include "stack/include/sdp_api.h"
+#include "stack/include/sdpdefs.h"
+#include "stack/sdp/sdpint.h"
+
+namespace {
+constexpr char service_name[] = "TestServiceName";
+constexpr uint32_t kFirstRecordHandle = 0x10000;
+} // namespace
+
+using bluetooth::legacy::stack::sdp::get_legacy_stack_sdp_api;
+
+class StackSdpDbTest : public ::testing::Test {
+ protected:
+ void SetUp() override {
+ // Ensure no records exist in global state
+ ASSERT_EQ((uint16_t)0, sdp_cb.server_db.num_records);
+ }
+
+ void TearDown() override {
+ // Ensure all records have been deleted from global state
+ ASSERT_EQ((uint16_t)0, sdp_cb.server_db.num_records);
+ }
+};
+
+TEST_F(StackSdpDbTest, SDP_AddAttribute__create_record) {
+ uint32_t record_handle =
+ get_legacy_stack_sdp_api()->handle.SDP_CreateRecord();
+
+ ASSERT_NE((uint32_t)0, record_handle);
+ ASSERT_EQ((uint16_t)1, sdp_cb.server_db.num_records);
+
+ tSDP_RECORD* record = sdp_db_find_record(record_handle);
+ ASSERT_TRUE(record != nullptr);
+
+ // The sdp handle is always the first attribute
+ ASSERT_EQ((uint16_t)1, record->num_attributes);
+ ASSERT_EQ(kFirstRecordHandle, record->record_handle);
+ ASSERT_EQ(sizeof(uint32_t), record->free_pad_ptr);
+
+ ASSERT_TRUE(
+ get_legacy_stack_sdp_api()->handle.SDP_DeleteRecord(record_handle));
+}
+
+TEST_F(StackSdpDbTest, SDP_AddAttribute__add_service_name) {
+ uint32_t record_handle =
+ get_legacy_stack_sdp_api()->handle.SDP_CreateRecord();
+
+ ASSERT_NE((uint32_t)0, record_handle);
+ ASSERT_TRUE(get_legacy_stack_sdp_api()->handle.SDP_AddAttribute(
+ record_handle, ATTR_ID_SERVICE_NAME, TEXT_STR_DESC_TYPE,
+ (uint32_t)(strlen(service_name) + 1), (uint8_t*)service_name));
+
+ tSDP_RECORD* record = sdp_db_find_record(record_handle);
+ ASSERT_TRUE(record != nullptr);
+
+ // The sdp handle is always the first attribute
+ ASSERT_EQ((uint16_t)(1 /* record_handle */ + 1 /* service name */),
+ record->num_attributes);
+ ASSERT_EQ(kFirstRecordHandle, record->record_handle);
+ ASSERT_EQ(sizeof(uint32_t) + strlen(service_name) + 1, record->free_pad_ptr);
+
+ const tSDP_ATTRIBUTE* attribute = sdp_db_find_attr_in_rec(
+ record, ATTR_ID_SERVICE_NAME, ATTR_ID_SERVICE_NAME);
+ ASSERT_TRUE(attribute != nullptr);
+
+ ASSERT_TRUE(
+ get_legacy_stack_sdp_api()->handle.SDP_DeleteRecord(record_handle));
+}
+
+TEST_F(StackSdpDbTest, SDP_AddAttribute__three_attributes) {
+ uint32_t record_handle =
+ get_legacy_stack_sdp_api()->handle.SDP_CreateRecord();
+
+ ASSERT_NE((uint32_t)0, record_handle);
+
+ ASSERT_TRUE(get_legacy_stack_sdp_api()->handle.SDP_AddAttribute(
+ record_handle, ATTR_ID_SERVICE_NAME, TEXT_STR_DESC_TYPE,
+ (uint32_t)(strlen(service_name) + 1), (uint8_t*)service_name));
+ ASSERT_TRUE(get_legacy_stack_sdp_api()->handle.SDP_AddAttribute(
+ record_handle, ATTR_ID_SERVICE_DESCRIPTION, TEXT_STR_DESC_TYPE,
+ (uint32_t)(strlen(service_name) + 1), (uint8_t*)service_name));
+ ASSERT_TRUE(get_legacy_stack_sdp_api()->handle.SDP_AddAttribute(
+ record_handle, ATTR_ID_PROVIDER_NAME, TEXT_STR_DESC_TYPE,
+ (uint32_t)(strlen(service_name) + 1), (uint8_t*)service_name));
+
+ tSDP_RECORD* record = sdp_db_find_record(record_handle);
+ ASSERT_TRUE(record != nullptr);
+
+ // The sdp handle is always the first attribute
+ ASSERT_EQ((uint16_t)(1 /* record_handle */ + 3 /* service name */),
+ record->num_attributes);
+ ASSERT_EQ(kFirstRecordHandle, record->record_handle);
+ ASSERT_EQ(sizeof(uint32_t) + (3 * (strlen(service_name) + 1)),
+ record->free_pad_ptr);
+
+ ASSERT_TRUE(sdp_db_find_attr_in_rec(record, ATTR_ID_SERVICE_NAME,
+ ATTR_ID_SERVICE_NAME) != nullptr);
+ ASSERT_TRUE(sdp_db_find_attr_in_rec(record, ATTR_ID_SERVICE_DESCRIPTION,
+ ATTR_ID_SERVICE_DESCRIPTION) != nullptr);
+ ASSERT_TRUE(sdp_db_find_attr_in_rec(record, ATTR_ID_PROVIDER_NAME,
+ ATTR_ID_PROVIDER_NAME) != nullptr);
+
+ ASSERT_TRUE(
+ get_legacy_stack_sdp_api()->handle.SDP_DeleteRecord(record_handle));
+}
+
+TEST_F(StackSdpDbTest, SDP_AddAttribute__too_many_attributes) {
+ uint32_t record_handle =
+ get_legacy_stack_sdp_api()->handle.SDP_CreateRecord();
+ ASSERT_NE((uint32_t)0, record_handle);
+
+ uint8_t boolean = 1;
+ for (size_t i = 0; i < SDP_MAX_REC_ATTR; i++) {
+ ASSERT_TRUE(get_legacy_stack_sdp_api()->handle.SDP_AddAttribute(
+ record_handle, (uint16_t)i, BOOLEAN_DESC_TYPE, boolean, &boolean));
+ }
+
+ ASSERT_FALSE(get_legacy_stack_sdp_api()->handle.SDP_AddAttribute(
+ record_handle, SDP_MAX_REC_ATTR + 1, BOOLEAN_DESC_TYPE, boolean,
+ &boolean));
+ ASSERT_TRUE(
+ get_legacy_stack_sdp_api()->handle.SDP_DeleteRecord(record_handle));
+}
+
+TEST_F(StackSdpDbTest, SDP_AddAttribute__three_attributes_replace_middle) {
+ uint32_t record_handle =
+ get_legacy_stack_sdp_api()->handle.SDP_CreateRecord();
+
+ ASSERT_NE((uint32_t)0, record_handle);
+
+ // Add 3 attributes to this record handle
+ ASSERT_TRUE(get_legacy_stack_sdp_api()->handle.SDP_AddAttribute(
+ record_handle, ATTR_ID_SERVICE_NAME, TEXT_STR_DESC_TYPE,
+ (uint32_t)(strlen(service_name) + 1), (uint8_t*)service_name));
+ ASSERT_TRUE(get_legacy_stack_sdp_api()->handle.SDP_AddAttribute(
+ record_handle, ATTR_ID_SERVICE_DESCRIPTION, TEXT_STR_DESC_TYPE,
+ (uint32_t)(strlen(service_name) + 1), (uint8_t*)service_name));
+ ASSERT_TRUE(get_legacy_stack_sdp_api()->handle.SDP_AddAttribute(
+ record_handle, ATTR_ID_PROVIDER_NAME, TEXT_STR_DESC_TYPE,
+ (uint32_t)(strlen(service_name) + 1), (uint8_t*)service_name));
+
+ tSDP_RECORD* record = sdp_db_find_record(record_handle);
+ ASSERT_TRUE(record != nullptr);
+
+ // The sdp handle is always the first attribute
+ ASSERT_EQ((uint16_t)(1 /* record_handle */ + 3 /* attribute count */),
+ record->num_attributes);
+ ASSERT_EQ(kFirstRecordHandle, record->record_handle);
+ ASSERT_EQ(sizeof(uint32_t) + (3 * (strlen(service_name) + 1)),
+ record->free_pad_ptr);
+
+ ASSERT_TRUE(sdp_db_find_attr_in_rec(record, ATTR_ID_SERVICE_NAME,
+ ATTR_ID_SERVICE_NAME) != nullptr);
+ ASSERT_TRUE(sdp_db_find_attr_in_rec(record, ATTR_ID_SERVICE_DESCRIPTION,
+ ATTR_ID_SERVICE_DESCRIPTION) != nullptr);
+ ASSERT_TRUE(sdp_db_find_attr_in_rec(record, ATTR_ID_PROVIDER_NAME,
+ ATTR_ID_PROVIDER_NAME) != nullptr);
+
+ // Attempt to replace the middle attribute with an invalid attribute
+ ASSERT_FALSE(get_legacy_stack_sdp_api()->handle.SDP_AddAttribute(
+ record_handle, ATTR_ID_SERVICE_DESCRIPTION, TEXT_STR_DESC_TYPE,
+ (uint32_t)0, (uint8_t*)nullptr));
+
+ // Ensure database is still intact.
+ ASSERT_EQ((uint16_t)(1 /* record_handle */ + 3 /* attribute count */),
+ record->num_attributes);
+ ASSERT_EQ(kFirstRecordHandle, record->record_handle);
+ ASSERT_EQ(sizeof(uint32_t) + (3 * (strlen(service_name) + 1)),
+ record->free_pad_ptr);
+
+ ASSERT_TRUE(sdp_db_find_attr_in_rec(record, ATTR_ID_SERVICE_NAME,
+ ATTR_ID_SERVICE_NAME) != nullptr);
+ ASSERT_TRUE(sdp_db_find_attr_in_rec(record, ATTR_ID_SERVICE_DESCRIPTION,
+ ATTR_ID_SERVICE_DESCRIPTION) != nullptr);
+ ASSERT_TRUE(sdp_db_find_attr_in_rec(record, ATTR_ID_PROVIDER_NAME,
+ ATTR_ID_PROVIDER_NAME) != nullptr);
+
+ ASSERT_TRUE(
+ get_legacy_stack_sdp_api()->handle.SDP_DeleteRecord(record_handle));
+}
diff --git a/system/test/mock/mock_bta_jv_api.cc b/system/test/mock/mock_bta_jv_api.cc
index 8d6b72fb5a..b2398a8040 100644
--- a/system/test/mock/mock_bta_jv_api.cc
+++ b/system/test/mock/mock_bta_jv_api.cc
@@ -34,46 +34,46 @@
tBTA_JV_STATUS BTA_JvCreateRecordByUser(uint32_t rfcomm_slot_id) {
inc_func_call_count(__func__);
- return 0;
+ return tBTA_JV_STATUS::SUCCESS;
}
tBTA_JV_STATUS BTA_JvDeleteRecord(uint32_t handle) {
inc_func_call_count(__func__);
- return 0;
+ return tBTA_JV_STATUS::SUCCESS;
}
tBTA_JV_STATUS BTA_JvEnable(tBTA_JV_DM_CBACK* p_cback) {
inc_func_call_count(__func__);
- return 0;
+ return tBTA_JV_STATUS::SUCCESS;
}
tBTA_JV_STATUS BTA_JvFreeChannel(uint16_t channel, int conn_type) {
inc_func_call_count(__func__);
- return 0;
+ return tBTA_JV_STATUS::SUCCESS;
}
tBTA_JV_STATUS BTA_JvL2capClose(uint32_t handle) {
inc_func_call_count(__func__);
- return 0;
+ return tBTA_JV_STATUS::SUCCESS;
}
tBTA_JV_STATUS BTA_JvL2capRead(uint32_t handle, uint32_t req_id,
uint8_t* p_data, uint16_t len) {
inc_func_call_count(__func__);
- return 0;
+ return tBTA_JV_STATUS::SUCCESS;
}
tBTA_JV_STATUS BTA_JvL2capReady(uint32_t handle, uint32_t* p_data_size) {
inc_func_call_count(__func__);
- return 0;
+ return tBTA_JV_STATUS::SUCCESS;
}
tBTA_JV_STATUS BTA_JvL2capStopServer(uint16_t local_psm,
uint32_t l2cap_socket_id) {
inc_func_call_count(__func__);
- return 0;
+ return tBTA_JV_STATUS::SUCCESS;
}
tBTA_JV_STATUS BTA_JvL2capWrite(uint32_t handle, uint32_t req_id, BT_HDR* msg,
uint32_t user_id) {
inc_func_call_count(__func__);
- return 0;
+ return tBTA_JV_STATUS::SUCCESS;
}
tBTA_JV_STATUS BTA_JvRfcommClose(uint32_t handle, uint32_t rfcomm_slot_id) {
inc_func_call_count(__func__);
- return 0;
+ return tBTA_JV_STATUS::SUCCESS;
}
tBTA_JV_STATUS BTA_JvRfcommConnect(tBTA_SEC sec_mask, tBTA_JV_ROLE role,
uint8_t remote_scn,
@@ -81,35 +81,35 @@ tBTA_JV_STATUS BTA_JvRfcommConnect(tBTA_SEC sec_mask, tBTA_JV_ROLE role,
tBTA_JV_RFCOMM_CBACK* p_cback,
uint32_t rfcomm_slot_id) {
inc_func_call_count(__func__);
- return 0;
+ return tBTA_JV_STATUS::SUCCESS;
}
tBTA_JV_STATUS BTA_JvRfcommStartServer(tBTA_SEC sec_mask, tBTA_JV_ROLE role,
uint8_t local_scn, uint8_t max_session,
tBTA_JV_RFCOMM_CBACK* p_cback,
uint32_t rfcomm_slot_id) {
inc_func_call_count(__func__);
- return 0;
+ return tBTA_JV_STATUS::SUCCESS;
}
tBTA_JV_STATUS BTA_JvRfcommStopServer(uint32_t handle,
uint32_t rfcomm_slot_id) {
inc_func_call_count(__func__);
- return 0;
+ return tBTA_JV_STATUS::SUCCESS;
}
tBTA_JV_STATUS BTA_JvRfcommWrite(uint32_t handle, uint32_t req_id) {
inc_func_call_count(__func__);
- return 0;
+ return tBTA_JV_STATUS::SUCCESS;
}
tBTA_JV_STATUS BTA_JvSetPmProfile(uint32_t handle, tBTA_JV_PM_ID app_id,
tBTA_JV_CONN_STATE init_st) {
inc_func_call_count(__func__);
- return 0;
+ return tBTA_JV_STATUS::SUCCESS;
}
tBTA_JV_STATUS BTA_JvStartDiscovery(const RawAddress& bd_addr,
uint16_t num_uuid,
const bluetooth::Uuid* p_uuid_list,
uint32_t rfcomm_slot_id) {
inc_func_call_count(__func__);
- return 0;
+ return tBTA_JV_STATUS::SUCCESS;
}
uint16_t BTA_JvRfcommGetPortHdl(uint32_t handle) {
inc_func_call_count(__func__);
diff --git a/system/test/mock/mock_btif_av.cc b/system/test/mock/mock_btif_av.cc
index cb939efb24..229309e5fc 100644
--- a/system/test/mock/mock_btif_av.cc
+++ b/system/test/mock/mock_btif_av.cc
@@ -22,6 +22,8 @@
// Mock include file to share data between tests and mock
#include "test/mock/mock_btif_av.h"
+#include <btif/include/btif_av.h>
+
#include <cstdint>
#include "test/common/mock_functions.h"
@@ -123,25 +125,26 @@ const char* dump_av_sm_event_name::return_value = nullptr;
} // namespace test
// Mocked functions, if any
-void btif_av_acl_disconnected(const RawAddress& peer_address) {
+void btif_av_acl_disconnected(const RawAddress& peer_address,
+ const A2dpType local_a2dp_type) {
inc_func_call_count(__func__);
- test::mock::btif_av::btif_av_acl_disconnected(peer_address);
+ test::mock::btif_av::btif_av_acl_disconnected(peer_address, local_a2dp_type);
}
-void btif_av_clear_remote_suspend_flag(void) {
+void btif_av_clear_remote_suspend_flag(const A2dpType local_a2dp_type) {
inc_func_call_count(__func__);
- test::mock::btif_av::btif_av_clear_remote_suspend_flag();
+ test::mock::btif_av::btif_av_clear_remote_suspend_flag(local_a2dp_type);
}
const RawAddress& btif_av_find_by_handle(tBTA_AV_HNDL bta_handle) {
inc_func_call_count(__func__);
return test::mock::btif_av::btif_av_find_by_handle(bta_handle);
}
-uint16_t btif_av_get_audio_delay() {
+uint16_t btif_av_get_audio_delay(const A2dpType local_a2dp_type) {
inc_func_call_count(__func__);
- return test::mock::btif_av::btif_av_get_audio_delay();
+ return test::mock::btif_av::btif_av_get_audio_delay(local_a2dp_type);
}
-uint8_t btif_av_get_peer_sep(void) {
+uint8_t btif_av_get_peer_sep(const A2dpType local_a2dp_type) {
inc_func_call_count(__func__);
- return test::mock::btif_av::btif_av_get_peer_sep();
+ return test::mock::btif_av::btif_av_get_peer_sep(local_a2dp_type);
}
const btav_sink_interface_t* btif_av_get_sink_interface(void) {
inc_func_call_count(__func__);
@@ -159,17 +162,21 @@ bool btif_av_is_a2dp_offload_running() {
inc_func_call_count(__func__);
return test::mock::btif_av::btif_av_is_a2dp_offload_running();
}
-bool btif_av_is_connected(void) {
+bool btif_av_is_connected(const A2dpType local_a2dp_type) {
inc_func_call_count(__func__);
- return test::mock::btif_av::btif_av_is_connected();
+ return test::mock::btif_av::btif_av_is_connected(local_a2dp_type);
}
-bool btif_av_is_connected_addr(const RawAddress& peer_address) {
+bool btif_av_is_connected_addr(const RawAddress& peer_address,
+ const A2dpType local_a2dp_type) {
inc_func_call_count(__func__);
- return test::mock::btif_av::btif_av_is_connected_addr(peer_address);
+ return test::mock::btif_av::btif_av_is_connected_addr(peer_address,
+ local_a2dp_type);
}
-bool btif_av_is_peer_edr(const RawAddress& peer_address) {
+bool btif_av_is_peer_edr(const RawAddress& peer_address,
+ const A2dpType local_a2dp_type) {
inc_func_call_count(__func__);
- return test::mock::btif_av::btif_av_is_peer_edr(peer_address);
+ return test::mock::btif_av::btif_av_is_peer_edr(peer_address,
+ local_a2dp_type);
}
bool btif_av_is_peer_silenced(const RawAddress& peer_address) {
inc_func_call_count(__func__);
@@ -199,14 +206,17 @@ bool btif_av_peer_is_source(const RawAddress& peer_address) {
inc_func_call_count(__func__);
return test::mock::btif_av::btif_av_peer_is_source(peer_address);
}
-bool btif_av_peer_prefers_mandatory_codec(const RawAddress& peer_address) {
+bool btif_av_peer_prefers_mandatory_codec(const RawAddress& peer_address,
+ const A2dpType local_a2dp_type) {
inc_func_call_count(__func__);
return test::mock::btif_av::btif_av_peer_prefers_mandatory_codec(
- peer_address);
+ peer_address, local_a2dp_type);
}
-bool btif_av_peer_supports_3mbps(const RawAddress& peer_address) {
+bool btif_av_peer_supports_3mbps(const RawAddress& peer_address,
+ const A2dpType local_a2dp_type) {
inc_func_call_count(__func__);
- return test::mock::btif_av::btif_av_peer_supports_3mbps(peer_address);
+ return test::mock::btif_av::btif_av_peer_supports_3mbps(peer_address,
+ local_a2dp_type);
}
void btif_av_report_source_codec_state(
const RawAddress& peer_address,
@@ -223,9 +233,11 @@ void btif_av_reset_audio_delay(void) {
inc_func_call_count(__func__);
test::mock::btif_av::btif_av_reset_audio_delay();
}
-void btif_av_set_audio_delay(const RawAddress& peer_address, uint16_t delay) {
+void btif_av_set_audio_delay(const RawAddress& peer_address, uint16_t delay,
+ const A2dpType local_a2dp_type) {
inc_func_call_count(__func__);
- test::mock::btif_av::btif_av_set_audio_delay(peer_address, delay);
+ test::mock::btif_av::btif_av_set_audio_delay(peer_address, delay,
+ local_a2dp_type);
}
void btif_av_set_dynamic_audio_buffer_size(uint8_t dynamic_audio_buffer_size) {
inc_func_call_count(__func__);
@@ -260,13 +272,13 @@ bool btif_av_src_sink_coexist_enabled(void) {
inc_func_call_count(__func__);
return test::mock::btif_av::btif_av_src_sink_coexist_enabled();
}
-bool btif_av_stream_ready(void) {
+bool btif_av_stream_ready(const A2dpType local_a2dp_type) {
inc_func_call_count(__func__);
- return test::mock::btif_av::btif_av_stream_ready();
+ return test::mock::btif_av::btif_av_stream_ready(local_a2dp_type);
}
-void btif_av_stream_start(void) {
+void btif_av_stream_start(const A2dpType local_a2dp_type) {
inc_func_call_count(__func__);
- test::mock::btif_av::btif_av_stream_start();
+ test::mock::btif_av::btif_av_stream_start(local_a2dp_type);
}
void btif_av_stream_start_offload(void) {
inc_func_call_count(__func__);
@@ -276,9 +288,9 @@ void btif_av_stream_start_with_latency(bool use_latency_mode) {
inc_func_call_count(__func__);
test::mock::btif_av::btif_av_stream_start_with_latency(use_latency_mode);
}
-bool btif_av_stream_started_ready(void) {
+bool btif_av_stream_started_ready(const A2dpType local_a2dp_type) {
inc_func_call_count(__func__);
- return test::mock::btif_av::btif_av_stream_started_ready();
+ return test::mock::btif_av::btif_av_stream_started_ready(local_a2dp_type);
}
void btif_av_stream_stop(const RawAddress& peer_address) {
inc_func_call_count(__func__);
diff --git a/system/test/mock/mock_btif_av.h b/system/test/mock/mock_btif_av.h
index 519c394d96..689a6ff762 100644
--- a/system/test/mock/mock_btif_av.h
+++ b/system/test/mock/mock_btif_av.h
@@ -28,6 +28,7 @@
// Original included files, if any
#include "bta/include/bta_av_api.h"
+#include "btif/include/btif_av.h"
#include "include/hardware/bt_av.h"
#include "types/raw_address.h"
@@ -57,20 +58,27 @@ namespace btif_av {
// Shared state between mocked functions and tests
// Name: btif_av_acl_disconnected
// Params: const RawAddress& peer_address
+// Params: const A2dpType local_a2dp_type.
// Return: void
struct btif_av_acl_disconnected {
- std::function<void(const RawAddress& peer_address)> body{
- [](const RawAddress& /* peer_address */) {}};
- void operator()(const RawAddress& peer_address) { body(peer_address); };
+ std::function<void(const RawAddress& peer_address,
+ const A2dpType local_a2dp_type)>
+ body{[](const RawAddress& /* peer_address */,
+ const A2dpType /* local_a2dp_type */) {}};
+ void operator()(const RawAddress& peer_address,
+ const A2dpType local_a2dp_type) {
+ body(peer_address, local_a2dp_type);
+ };
};
extern struct btif_av_acl_disconnected btif_av_acl_disconnected;
// Name: btif_av_clear_remote_suspend_flag
-// Params: void
+// Params: const A2dpType local_a2dp_type.
// Return: void
struct btif_av_clear_remote_suspend_flag {
- std::function<void(void)> body{[](void) {}};
- void operator()(void) { body(); };
+ std::function<void(const A2dpType local_a2dp_type)> body{
+ [](const A2dpType /* local_a2dp_type */) {}};
+ void operator()(const A2dpType local_a2dp_type) { body(local_a2dp_type); };
};
extern struct btif_av_clear_remote_suspend_flag
btif_av_clear_remote_suspend_flag;
@@ -89,22 +97,28 @@ struct btif_av_find_by_handle {
extern struct btif_av_find_by_handle btif_av_find_by_handle;
// Name: btif_av_get_audio_delay
-// Params:
+// Params: const A2dpType local_a2dp_type.
// Return: uint16_t
struct btif_av_get_audio_delay {
static uint16_t return_value;
- std::function<uint16_t()> body{[]() { return return_value; }};
- uint16_t operator()() { return body(); };
+ std::function<uint16_t(const A2dpType local_a2dp_type)> body{
+ [](const A2dpType /* local_a2dp_type */) { return return_value; }};
+ uint16_t operator()(const A2dpType local_a2dp_type) {
+ return body(local_a2dp_type);
+ };
};
extern struct btif_av_get_audio_delay btif_av_get_audio_delay;
// Name: btif_av_get_peer_sep
-// Params: void
+// Params: const A2dpType local_a2dp_type.
// Return: uint8_t
struct btif_av_get_peer_sep {
static uint8_t return_value;
- std::function<uint8_t(void)> body{[](void) { return return_value; }};
- uint8_t operator()(void) { return body(); };
+ std::function<uint8_t(const A2dpType local_a2dp_type)> body{
+ [](const A2dpType /* local_a2dp_type */) { return return_value; }};
+ uint8_t operator()(const A2dpType local_a2dp_type) {
+ return body(local_a2dp_type);
+ };
};
extern struct btif_av_get_peer_sep btif_av_get_peer_sep;
@@ -151,37 +165,46 @@ struct btif_av_is_a2dp_offload_running {
extern struct btif_av_is_a2dp_offload_running btif_av_is_a2dp_offload_running;
// Name: btif_av_is_connected
-// Params: void
+// Params: const A2dpType local_a2dp_type.
// Return: bool
struct btif_av_is_connected {
static bool return_value;
- std::function<bool(void)> body{[](void) { return return_value; }};
- bool operator()(void) { return body(); };
+ std::function<bool(const A2dpType local_a2dp_type)> body{
+ [](const A2dpType /* local_a2dp_type */) { return return_value; }};
+ bool operator()(const A2dpType local_a2dp_type) {
+ return body(local_a2dp_type);
+ };
};
extern struct btif_av_is_connected btif_av_is_connected;
// Name: btif_av_is_connected_addr
-// Params: const RawAddress& peer_address
+// Params: const RawAddress& peer_address, const A2dpType local_a2dp_type
// Return: bool
struct btif_av_is_connected_addr {
static bool return_value;
- std::function<bool(const RawAddress& peer_address)> body{
- [](const RawAddress& /* peer_address */) { return return_value; }};
- bool operator()(const RawAddress& peer_address) {
- return body(peer_address);
+ std::function<bool(const RawAddress& peer_address,
+ const A2dpType local_a2dp_type)>
+ body{[](const RawAddress& /* peer_address */,
+ const A2dpType /* local_a2dp_type */) { return return_value; }};
+ bool operator()(const RawAddress& peer_address,
+ const A2dpType local_a2dp_type) {
+ return body(peer_address, local_a2dp_type);
};
};
extern struct btif_av_is_connected_addr btif_av_is_connected_addr;
// Name: btif_av_is_peer_edr
-// Params: const RawAddress& peer_address
+// Params: const RawAddress& peer_address, const A2dpType local_a2dp_type
// Return: bool
struct btif_av_is_peer_edr {
static bool return_value;
- std::function<bool(const RawAddress& peer_address)> body{
- [](const RawAddress& /* peer_address */) { return return_value; }};
- bool operator()(const RawAddress& peer_address) {
- return body(peer_address);
+ std::function<bool(const RawAddress& peer_address,
+ const A2dpType local_a2dp_type)>
+ body{[](const RawAddress& /* peer_address */,
+ const A2dpType /* local_a2dp_type */) { return return_value; }};
+ bool operator()(const RawAddress& peer_address,
+ const A2dpType local_a2dp_type) {
+ return body(peer_address, local_a2dp_type);
};
};
extern struct btif_av_is_peer_edr btif_av_is_peer_edr;
@@ -272,28 +295,40 @@ struct btif_av_peer_is_source {
extern struct btif_av_peer_is_source btif_av_peer_is_source;
// Name: btif_av_peer_prefers_mandatory_codec
-// Params: const RawAddress& peer_address
+// Params: const RawAddress& peer_address, const A2dpType local_a2dp_type
// Return: bool
struct btif_av_peer_prefers_mandatory_codec {
static bool return_value;
- std::function<bool(const RawAddress& peer_address)> body{
- [](const RawAddress& /* peer_address */) { return return_value; }};
- bool operator()(const RawAddress& peer_address) {
- return body(peer_address);
+ std::function<bool(const RawAddress& peer_address,
+ const A2dpType local_a2dp_type)>
+ body{[](const RawAddress& /* peer_address */,
+ const A2dpType /* local_a2dp_type */) {
+ ;
+ return return_value;
+ }};
+ bool operator()(const RawAddress& peer_address,
+ const A2dpType local_a2dp_type) {
+ return body(peer_address, local_a2dp_type);
};
};
extern struct btif_av_peer_prefers_mandatory_codec
btif_av_peer_prefers_mandatory_codec;
// Name: btif_av_peer_supports_3mbps
-// Params: const RawAddress& peer_address
+// Params: const RawAddress& peer_address, const A2dpType local_a2dp_type
// Return: bool
struct btif_av_peer_supports_3mbps {
static bool return_value;
- std::function<bool(const RawAddress& peer_address)> body{
- [](const RawAddress& /* peer_address */) { return return_value; }};
- bool operator()(const RawAddress& peer_address) {
- return body(peer_address);
+ std::function<bool(const RawAddress& peer_address,
+ const A2dpType local_a2dp_type)>
+ body{[](const RawAddress& /* peer_address */,
+ const A2dpType /* local_a2dp_type */) {
+ ;
+ return return_value;
+ }};
+ bool operator()(const RawAddress& peer_address,
+ const A2dpType local_a2dp_type) {
+ return body(peer_address, local_a2dp_type);
};
};
extern struct btif_av_peer_supports_3mbps btif_av_peer_supports_3mbps;
@@ -339,13 +374,16 @@ struct btif_av_reset_audio_delay {
extern struct btif_av_reset_audio_delay btif_av_reset_audio_delay;
// Name: btif_av_set_audio_delay
-// Params: const RawAddress& peer_address, uint16_t delay
-// Return: void
+// Params: const RawAddress& peer_address, uint16_t delay, const A2dpType
+// local_a2dp_type Return: void
struct btif_av_set_audio_delay {
- std::function<void(const RawAddress& peer_address, uint16_t delay)> body{
- [](const RawAddress& /* peer_address */, uint16_t /* delay */) {}};
- void operator()(const RawAddress& peer_address, uint16_t delay) {
- body(peer_address, delay);
+ std::function<void(const RawAddress& peer_address, uint16_t delay,
+ const A2dpType local_a2dp_type)>
+ body{[](const RawAddress& /* peer_address */, uint16_t /* delay */,
+ const A2dpType /* local_a2dp_type */) {}};
+ void operator()(const RawAddress& peer_address, uint16_t delay,
+ const A2dpType local_a2dp_type) {
+ body(peer_address, delay, local_a2dp_type);
};
};
extern struct btif_av_set_audio_delay btif_av_set_audio_delay;
@@ -436,21 +474,25 @@ struct btif_av_src_sink_coexist_enabled {
extern struct btif_av_src_sink_coexist_enabled btif_av_src_sink_coexist_enabled;
// Name: btif_av_stream_ready
-// Params: void
+// Params: const A2dpType local_a2dp_type
// Return: bool
struct btif_av_stream_ready {
static bool return_value;
- std::function<bool(void)> body{[](void) { return return_value; }};
- bool operator()(void) { return body(); };
+ std::function<bool(const A2dpType local_a2dp_type)> body{
+ [](const A2dpType /* local_a2dp_type */) { return return_value; }};
+ bool operator()(const A2dpType local_a2dp_type) {
+ return body(local_a2dp_type);
+ };
};
extern struct btif_av_stream_ready btif_av_stream_ready;
// Name: btif_av_stream_start
-// Params: void
+// Params: const A2dpType local_a2dp_type
// Return: void
struct btif_av_stream_start {
- std::function<void(void)> body{[](void) {}};
- void operator()(void) { body(); };
+ std::function<void(const A2dpType local_a2dp_type)> body{
+ [](const A2dpType /* local_a2dp_type */) {}};
+ void operator()(const A2dpType local_a2dp_type) { body(local_a2dp_type); };
};
extern struct btif_av_stream_start btif_av_stream_start;
@@ -475,12 +517,15 @@ extern struct btif_av_stream_start_with_latency
btif_av_stream_start_with_latency;
// Name: btif_av_stream_started_ready
-// Params: void
+// Params: const A2dpType local_a2dp_type
// Return: bool
struct btif_av_stream_started_ready {
static bool return_value;
- std::function<bool(void)> body{[](void) { return return_value; }};
- bool operator()(void) { return body(); };
+ std::function<bool(const A2dpType local_a2dp_type)> body{
+ [](const A2dpType /* local_a2dp_type */) { return return_value; }};
+ bool operator()(const A2dpType local_a2dp_type) {
+ return body(local_a2dp_type);
+ };
};
extern struct btif_av_stream_started_ready btif_av_stream_started_ready;
diff --git a/system/test/mock/mock_main_shim_le_advertising_manager.cc b/system/test/mock/mock_main_shim_le_advertising_manager.cc
index f8488dabfc..a137f25a53 100644
--- a/system/test/mock/mock_main_shim_le_advertising_manager.cc
+++ b/system/test/mock/mock_main_shim_le_advertising_manager.cc
@@ -1,5 +1,6 @@
/*
- * Copyright 2021 The Android Open Source Project
+ * Copyright 2021 HIMSA II K/S - www.himsa.com.
+ * Represented by EHIMA - www.ehima.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,19 +15,31 @@
* limitations under the License.
*/
-/*
- * Generated mock file from original source file
- * Functions generated:3
- */
+#include "mock_main_shim_le_advertising_manager.h"
+
+#include <base/memory/weak_ptr.h>
-#include "include/hardware/ble_advertiser.h"
#include "main/shim/le_advertising_manager.h"
-#include "test/common/mock_functions.h"
-BleAdvertiserInterface* bluetooth::shim::get_ble_advertiser_instance() {
- inc_func_call_count(__func__);
- return nullptr;
+namespace {
+MockBleAdvertisingManager* bt_le_advertiser_instance;
+} // namespace
+
+void MockBleAdvertisingManager::Initialize() {
+ if (bt_le_advertiser_instance == nullptr) {
+ bt_le_advertiser_instance = new MockBleAdvertisingManager();
+ }
}
-void bluetooth::shim::init_advertising_manager() {
- inc_func_call_count(__func__);
+
+void MockBleAdvertisingManager::CleanUp() {
+ delete bt_le_advertiser_instance;
+ bt_le_advertiser_instance = nullptr;
+}
+
+MockBleAdvertisingManager* MockBleAdvertisingManager::Get() {
+ return bt_le_advertiser_instance;
+}
+
+BleAdvertiserInterface* bluetooth::shim::get_ble_advertiser_instance() {
+ return static_cast<BleAdvertiserInterface*>(bt_le_advertiser_instance);
}
diff --git a/system/bta/le_audio/broadcaster/mock_ble_advertising_manager.h b/system/test/mock/mock_main_shim_le_advertising_manager.h
index 9f60b58aed..9f60b58aed 100644
--- a/system/bta/le_audio/broadcaster/mock_ble_advertising_manager.h
+++ b/system/test/mock/mock_main_shim_le_advertising_manager.h
diff --git a/system/test/mock/mock_stack_btm_inq.cc b/system/test/mock/mock_stack_btm_inq.cc
index fbdd94138c..4e82f527a9 100644
--- a/system/test/mock/mock_stack_btm_inq.cc
+++ b/system/test/mock/mock_stack_btm_inq.cc
@@ -68,7 +68,6 @@ struct btm_inq_db_reset btm_inq_db_reset;
struct btm_inq_find_bdaddr btm_inq_find_bdaddr;
struct btm_inq_remote_name_timer_timeout btm_inq_remote_name_timer_timeout;
struct btm_inq_rmt_name_failed_cancelled btm_inq_rmt_name_failed_cancelled;
-struct btm_inq_stop_on_ssp btm_inq_stop_on_ssp;
struct btm_process_inq_complete btm_process_inq_complete;
struct btm_process_remote_name btm_process_remote_name;
struct btm_set_eir_uuid btm_set_eir_uuid;
@@ -250,10 +249,6 @@ void btm_inq_rmt_name_failed_cancelled(void) {
inc_func_call_count(__func__);
test::mock::stack_btm_inq::btm_inq_rmt_name_failed_cancelled();
}
-void btm_inq_stop_on_ssp(void) {
- inc_func_call_count(__func__);
- test::mock::stack_btm_inq::btm_inq_stop_on_ssp();
-}
void btm_process_inq_complete(tHCI_STATUS status, uint8_t mode) {
inc_func_call_count(__func__);
test::mock::stack_btm_inq::btm_process_inq_complete(status, mode);
diff --git a/system/test/mock/mock_stack_btm_inq.h b/system/test/mock/mock_stack_btm_inq.h
index 39f62a1dbd..7765328742 100644
--- a/system/test/mock/mock_stack_btm_inq.h
+++ b/system/test/mock/mock_stack_btm_inq.h
@@ -420,15 +420,6 @@ struct btm_inq_rmt_name_failed_cancelled {
extern struct btm_inq_rmt_name_failed_cancelled
btm_inq_rmt_name_failed_cancelled;
-// Name: btm_inq_stop_on_ssp
-// Params: void
-// Return: void
-struct btm_inq_stop_on_ssp {
- std::function<void(void)> body{[](void) {}};
- void operator()(void) { body(); };
-};
-extern struct btm_inq_stop_on_ssp btm_inq_stop_on_ssp;
-
// Name: btm_process_inq_complete
// Params: tHCI_STATUS status, uint8_t mode
// Return: void
diff --git a/system/test/mock/mock_stack_btm_sco_hfp_hal.cc b/system/test/mock/mock_stack_btm_sco_hfp_hal.cc
index 1083a3601a..ed43dae0d1 100644
--- a/system/test/mock/mock_stack_btm_sco_hfp_hal.cc
+++ b/system/test/mock/mock_stack_btm_sco_hfp_hal.cc
@@ -62,7 +62,7 @@ bool enable_offload::return_value = false;
hfp_hal_interface::bt_codecs get_codec_capabilities::return_value = {};
bool get_offload_enabled::return_value = false;
bool get_offload_supported::return_value = false;
-int get_packet_size::return_value = 0;
+size_t get_packet_size::return_value = 0;
bool get_wbs_supported::return_value = false;
bool get_swb_supported::return_value = false;
bool is_coding_format_supported::return_value = false;
@@ -90,7 +90,7 @@ bool get_offload_supported() {
inc_func_call_count(__func__);
return test::mock::stack_btm_sco_hfp_hal::get_offload_supported();
}
-int get_packet_size(int codec) {
+size_t get_packet_size(int codec) {
inc_func_call_count(__func__);
return test::mock::stack_btm_sco_hfp_hal::get_packet_size(codec);
}
diff --git a/system/test/mock/mock_stack_btm_sco_hfp_hal.h b/system/test/mock/mock_stack_btm_sco_hfp_hal.h
index 9474d4c9c6..ecb87c480f 100644
--- a/system/test/mock/mock_stack_btm_sco_hfp_hal.h
+++ b/system/test/mock/mock_stack_btm_sco_hfp_hal.h
@@ -85,12 +85,12 @@ extern struct get_offload_supported get_offload_supported;
// Name: get_packet_size
// Params: int codec
-// Return: int
+// Return: size_t
struct get_packet_size {
- static int return_value;
- std::function<int(int /* codec */)> body{
+ static size_t return_value;
+ std::function<size_t(int /* codec */)> body{
[](int /* codec */) { return return_value; }};
- int operator()(int codec) { return body(codec); };
+ size_t operator()(int codec) { return body(codec); };
};
extern struct get_packet_size get_packet_size;
diff --git a/system/test/mock/mock_stack_gatt_main.cc b/system/test/mock/mock_stack_gatt_main.cc
index 50cd730a67..c6963a2dfd 100644
--- a/system/test/mock/mock_stack_gatt_main.cc
+++ b/system/test/mock/mock_stack_gatt_main.cc
@@ -43,12 +43,6 @@ bool gatt_disconnect(tGATT_TCB* /* p_tcb */) {
inc_func_call_count(__func__);
return false;
}
-bool gatt_update_app_hold_link_status(tGATT_IF /* gatt_if */,
- tGATT_TCB* /* p_tcb */,
- bool /* is_add */) {
- inc_func_call_count(__func__);
- return false;
-}
tGATT_CH_STATE gatt_get_ch_state(tGATT_TCB* /* p_tcb */) {
inc_func_call_count(__func__);
return GATT_CH_CLOSE;
@@ -109,6 +103,4 @@ void gatt_update_app_use_link_flag(tGATT_IF /* gatt_if */,
inc_func_call_count(__func__);
}
-void gatt_tcb_dump(int fd) {
- inc_func_call_count(__func__);
-}
+void gatt_tcb_dump(int /* fd */) { inc_func_call_count(__func__); }
diff --git a/system/test/suite/Android.bp b/system/test/suite/Android.bp
index fcfe5c88fa..505d7ab089 100644
--- a/system/test/suite/Android.bp
+++ b/system/test/suite/Android.bp
@@ -41,9 +41,6 @@ cc_defaults {
"adapter/bluetooth_test.cc",
],
shared_libs: [
- "android.hardware.bluetooth.audio@2.0",
- "android.hardware.bluetooth.audio@2.1",
- "android.system.suspend-V1-ndk",
"libPlatformProperties",
"libaaudio",
"libbinder",
@@ -57,7 +54,13 @@ cc_defaults {
"libutils",
],
static_libs: [
+ "android.hardware.audio.common@5.0",
"android.hardware.bluetooth.a2dp@1.0",
+ "android.hardware.bluetooth.audio@2.0",
+ "android.hardware.bluetooth.audio@2.1",
+ "android.hardware.common-V2-ndk",
+ "android.hardware.common.fmq-V1-ndk",
+ "android.system.suspend-V1-ndk",
"android.system.suspend.control-V1-ndk",
"avrcp-target-service",
"lib-bt-packets",
diff --git a/system/test/tool/mockcify.pl b/system/test/tool/mockcify.pl
index 724f26d03c..1f9978489e 100755
--- a/system/test/tool/mockcify.pl
+++ b/system/test/tool/mockcify.pl
@@ -18,6 +18,9 @@ use File::Basename;
## mockcify version
##
+## 0.7.1 Add tBTA_JV_STATUS return value
+## Remove unused compiler definition HAS_NO_BDROID_BUILDCFG
+##
## 0.7.0 Comment out unused mock variables
##
## 0.6.3 Streamline inclusion for headers and source
@@ -44,7 +47,7 @@ use File::Basename;
##
## 0.2.0 First version
##
-my $VERSION = "0.7.0";
+my $VERSION = "0.7.1";
use diagnostics;
use strict;
@@ -257,14 +260,14 @@ sub compilation_screen {
"test/mock/",
"types/",
);
- my @defs = (
- "HAS_NO_BDROID_BUILDCFG",
+ ## Any additional compiler definitions that may be required
+ my @compiler_defs = (
);
my $link="test/mock/$hdr";
unlink "$INCDIR/$link";
symlink "$OUTDIR/$hdr", "$INCDIR/$link";
- system("$CC -c -std=c++20 -o /dev/null -D" . join(" -D", @defs) . " -I" . join(" -I", @incs) . " $OUTDIR/$src");
+ system("$CC -c -std=c++20 -o /dev/null -D" . join(" -D", @compiler_defs) . " -I" . join(" -I", @incs) . " $OUTDIR/$src");
my $rc = $?;
($? == 0)
? printf(STDERR "SUCCESS Compiled unit \'$src\'\n")
@@ -582,6 +585,8 @@ sub get_default_return_value_from_type {
return "BTA_SDP_SUCCESS";
} elsif(/tBTA_STATUS/) {
return "BTA_SUCCESS";
+ } elsif(/tBTA_JV_STATUS/) {
+ return "tBTA_JV_STATUS::SUCCESS";
} else {
## Decay to int type
return "0";
diff --git a/tools/rootcanal/model/controller/dual_mode_controller.cc b/tools/rootcanal/model/controller/dual_mode_controller.cc
index d7f7dc28db..9345253261 100644
--- a/tools/rootcanal/model/controller/dual_mode_controller.cc
+++ b/tools/rootcanal/model/controller/dual_mode_controller.cc
@@ -3141,8 +3141,18 @@ void DualModeController::LeApcf(CommandView command) {
break;
}
default:
- FATAL(id_, "unknown APCF opcode {}",
+ ERROR(id_, "unknown APCF opcode {:#x}",
static_cast<uint8_t>(command_view.GetApcfOpcode()));
+
+ send_event_(bluetooth::hci::LeApcfCompleteBuilder::Create(
+ kNumCommandPackets, ErrorCode::INVALID_HCI_COMMAND_PARAMETERS,
+ command_view.GetApcfOpcode(), std::vector<uint8_t>{}));
+
+ invalid_packet_handler_(
+ id_, InvalidPacketReason::kUnsupported,
+ fmt::format("unsupported APCF opcode {:#x}",
+ static_cast<uint8_t>(command_view.GetApcfOpcode())),
+ command_view.bytes().bytes());
}
}