From 356878d4f2ebbf2b7c05f1388f86f639da91c402 Mon Sep 17 00:00:00 2001 From: zhangwt3652 Date: Tue, 24 Jun 2025 10:11:18 +0800 Subject: [PATCH] audio idl Change-Id: Iac10ff527be7b14fb2ad7f9d5b1d01e72ad4c679 Signed-off-by: zhangwt3652 --- config.gni | 1 + frameworks/native/audiocapturer/BUILD.gn | 1 + .../include/audio_capturer_private.h | 2 +- .../audiocapturer/test/benchmark/BUILD.gn | 5 + .../test/unittest/capturer_test/BUILD.gn | 1 + .../audio_capturer_extra_plus_unit_test.cpp | 1 + .../unittest/multiple_capturer_test/BUILD.gn | 6 +- .../include/audio_stream_descriptor.h | 6 +- .../src/audio_stream_descriptor.cpp | 45 +- .../audio_effect_chain_manager_unit_test.cpp | 7 +- .../include/audio_policy_manager.h | 21 +- .../audiopolicy/include/audio_zone_info.h | 41 +- .../test/unittest/policy_test/BUILD.gn | 1 + .../src/audio_policy_ext_unit_test.cpp | 4 +- .../src/audio_policy_unit_test.cpp | 142 +- .../audiorenderer/test/benchmark/BUILD.gn | 2 + .../test/multithreadtest/BUILD.gn | 3 + .../test/unittest/renderer_test/BUILD.gn | 9 +- .../src/renderer_in_client_unit_test.cpp | 86 +- .../native/audioutils/include/audio_utils.h | 10 + .../native/audioutils/src/audio_utils.cpp | 24 + .../include/common/hdi_adapter_type.h | 104 +- .../sink/file_audio_render_sink.cpp | 3 - .../sink/remote_audio_render_sink.cpp | 2 +- .../source/file_audio_capture_source.cpp | 3 - frameworks/native/offlineaudioeffect/BUILD.gn | 1 + ...offline_audio_effect_manager_unit_test.cpp | 2 +- .../unittest/oh_audio_capture_test/BUILD.gn | 7 +- .../unittest/oh_audio_manager_test/BUILD.gn | 1 - .../oh_audio_volume_manager_test/BUILD.gn | 8 +- .../hdi_adapter_intf/sink/sink_adapter.cpp | 23 +- .../source/source_adapter.cpp | 37 +- frameworks/native/toneplayer/BUILD.gn | 1 + .../native/toneplayer/test/unittest/BUILD.gn | 7 + .../include/audio_device_descriptor.h | 43 +- .../audiocommon/include/audio_device_info.h | 19 +- .../native/audiocommon/include/audio_effect.h | 418 ++- .../native/audiocommon/include/audio_info.h | 453 ++- .../include/audio_interrupt_info.h | 101 +- .../include/audio_stream_change_info.h | 129 +- .../audiocommon/include/audio_stream_info.h | 20 +- .../audiocommon/include/audio_stutter.h | 55 +- .../audiocommon/include/audio_workgroup_ipc.h | 24 + .../include/microphone_descriptor.h | 2 +- .../include/audio_policy_interface.h | 49 +- .../include/audio_system_manager.h | 49 +- services/audio_policy/BUILD.gn | 192 +- .../client/interface/audio_policy_base.h | 544 --- .../client/interface/audio_policy_client.h | 57 +- .../i_standard_audio_anahs_manager_listener.h | 39 - ...i_standard_audio_policy_manager_listener.h | 57 - ..._standard_audio_routing_manager_listener.h | 49 - .../interface/i_standard_audio_zone_client.h | 72 - .../interface/i_standard_client_tracker.h | 58 - .../i_standard_concurrency_state_listener.h | 42 - .../client/proxy/include/audio_policy_proxy.h | 530 --- .../proxy/src/audio_policy_callback_proxy.cpp | 517 --- .../src/audio_policy_microphone_proxy.cpp | 161 - .../client/proxy/src/audio_policy_proxy.cpp | 2925 ----------------- .../proxy/src/audio_policy_volume_proxy.cpp | 540 --- .../proxy/src/audio_policy_zone_proxy.cpp | 378 --- .../include/audio_anahs_manager_listener.h} | 21 +- .../service/include/audio_general_manager.h | 1 + .../include/audio_routing_manager_listener.h} | 30 +- .../src/audio_anahs_manager_listener.cpp} | 40 +- .../service/src/audio_general_manager.cpp | 7 +- .../service/src/audio_policy_manager.cpp | 402 ++- .../src/audio_policy_manager_device.cpp | 98 +- .../service/src/audio_policy_manager_zone.cpp | 28 +- .../src/audio_routing_manager_listener.cpp} | 155 +- .../stub/include/audio_policy_client_stub.h | 69 - .../include/audio_policy_client_stub_impl.h | 76 +- ...audio_policy_manager_listener_stub_impl.h} | 37 +- .../client/stub/include/audio_zone_client.h | 44 +- .../sle_audio_operation_callback_stub.h | 64 - .../sle_audio_operation_callback_stub_impl.h} | 43 +- .../stub/src/audio_policy_client_stub.cpp | 467 --- .../src/audio_policy_client_stub_impl.cpp | 186 +- ...dio_policy_manager_listener_stub_impl.cpp} | 194 +- ...tialization_state_change_listener_stub.cpp | 81 - .../client/stub/src/audio_zone_client.cpp | 187 +- ...le_audio_operation_callback_stub_impl.cpp} | 227 +- .../include/audio_policy_ipc_interface_code.h | 14 +- .../i_standard_sle_audio_operation_callback.h | 61 - services/audio_policy/idl/IAudioPolicy.idl | 294 ++ .../audio_policy/idl/IAudioPolicyClient.idl | 86 + .../IAudioWorkgroupCallback.idl} | 28 +- .../IStandardAudioAnahsManagerListener.idl} | 26 +- .../IStandardAudioPolicyManagerListener.idl | 30 + .../IStandardAudioRoutingManagerListener.idl} | 39 +- .../idl/IStandardAudioZoneClient.idl | 38 + .../idl/IStandardClientTracker.idl | 29 + .../idl/IStandardConcurrencyStateListener.idl | 19 + .../IStandardSleAudioOperationCallback.idl} | 47 +- ...ndardSpatializationStateChangeListener.idl | 21 + .../device/include/audio_connected_device.h | 2 + .../device/include/audio_state_manager.h | 2 +- .../device/include/device_status_listener.h | 4 +- .../domain/device/src/audio_active_device.cpp | 1 - .../device/src/audio_connected_device.cpp | 1 - .../device/src/audio_device_descriptor.cpp | 225 +- .../src/audio_microphone_descriptor.cpp | 1 - .../domain/device/src/audio_scene_manager.cpp | 1 - .../domain/device/src/audio_state_manager.cpp | 5 +- .../device/src/device_status_listener.cpp | 6 +- .../src/sle/sle_audio_device_manager.cpp | 32 +- .../device/src/sle/sle_audio_device_manager.h | 2 +- .../include/audio_spatialization_service.h | 3 +- .../src/audio_spatialization_service.cpp | 8 +- .../include/audio_interrupt_service.h | 1 + .../interrupt/include/audio_interrupt_zone.h | 2 +- .../src/audio_interrupt_group_info.cpp | 4 +- .../interrupt/src/audio_interrupt_service.cpp | 25 +- .../src/audio_interrupt_service_ext.cpp | 2 +- .../interrupt/src/power_state_listener.cpp | 12 +- .../pipe/src/audio_a2dp_offload_flag.cpp | 1 - .../pipe/src/audio_a2dp_offload_manager.cpp | 1 - .../pipe/src/audio_concurrency_service.cpp | 2 +- .../domain/pipe/src/audio_config_manager.cpp | 1 - .../domain/stream/audio_stream_collector.cpp | 2 +- .../domain/stream/audio_stream_collector.h | 4 +- .../volume/include/audio_adapter_manager.h | 1 + .../include/audio_adapter_manager_handler.h | 2 +- .../volume/include/iaudio_policy_interface.h | 1 + .../volume/src/audio_adapter_manager.cpp | 22 +- .../volume/src/audio_volume_group_info.cpp | 2 +- .../volume/src/audio_volume_manager.cpp | 1 - .../zone/include/audio_zone_client_manager.h | 2 +- .../zone/include/audio_zone_client_proxy.h | 47 - .../domain/zone/include/audio_zone_service.h | 2 +- .../zone/src/audio_zone_client_manager.cpp | 12 +- .../zone/src/audio_zone_client_proxy.cpp | 149 - .../domain/zone/src/audio_zone_service.cpp | 1 - .../audio_client_tracker_callback_listener.h} | 32 +- .../audio_client_tracker_callback_service.h} | 42 +- ...dio_concurrency_state_listener_callback.h} | 20 +- ...udio_concurrency_state_listener_service.h} | 20 +- .../audio_policy_manager_listener.h} | 32 +- ...io_spatialization_state_change_callback.h} | 84 +- ...io_spatialization_state_change_listener.h} | 75 +- .../include/client_type_manager_handler.h | 2 +- .../src/audio_background_manager.cpp | 1 - .../include/audio_policy_server_handler.h | 19 +- .../include/i_audio_zone_event_dispatcher.h | 2 + .../src/audio_policy_server_handler.cpp | 55 +- .../parser/src/audio_converter_parser.cpp | 3 +- .../parser/src/audio_effect_config_parser.cpp | 14 +- .../datashare/src/audio_policy_utils.cpp | 1 - .../include/audio_policy_client_holder.h} | 91 +- .../ipc_proxy/include/audio_server_proxy.h | 1 + .../ipc_proxy/src/audio_ability_manager.cpp | 5 +- .../src/audio_policy_client_holder.cpp | 263 ++ .../ipc_proxy/src/audio_server_proxy.cpp | 82 +- .../audio_anahs_manager_listener_proxy.h | 32 - .../audio_routing_manager_listener_proxy.h | 42 - .../audio_anahs_manager_listener_proxy.cpp | 58 - .../proxy/src/audio_policy_client_proxy.cpp | 701 ---- .../audio_policy_manager_listener_proxy.cpp | 214 -- .../audio_routing_manager_listener_proxy.cpp | 163 - ...ialization_state_change_listener_proxy.cpp | 84 - .../sle_audio_operation_callback_proxy.cpp | 225 -- .../include/audio_policy_server.h | 424 +-- .../include/audio_policy_service.h | 1 - .../service_main/src/audio_policy_dump.cpp | 1 - .../service_main/src/audio_policy_server.cpp | 1202 ++++--- .../service_main/src/audio_policy_service.cpp | 11 +- ...udio_client_tracker_callback_listener.cpp} | 158 +- ...audio_client_tracker_callback_service.cpp} | 145 +- ...o_concurrency_state_listener_callback.cpp} | 31 +- ...io_concurrency_state_listener_service.cpp} | 39 +- .../src/audio_policy_manager_listener.cpp | 88 + ..._spatialization_state_change_callback.cpp} | 83 +- ..._spatialization_state_change_listener.cpp} | 96 +- .../stub/include/audio_policy_manager_stub.h | 286 -- .../src/audio_policy_manager_device_stub.cpp | 376 --- .../stub/src/audio_policy_manager_stub.cpp | 2658 --------------- .../src/audio_policy_manager_zone_stub.cpp | 313 -- services/audio_policy/test/BUILD.gn | 556 +--- ..._client_tracker_callback_proxy_unit_test.h | 72 - ...lient_tracker_callback_proxy_unit_test.cpp | 305 -- ...o_client_tracker_callback_stub_unit_test.h | 72 - ...client_tracker_callback_stub_unit_test.cpp | 350 -- .../audio_core_service_entry_unit_test.cpp | 32 +- .../src/audio_core_service_unit_test.cpp | 14 +- .../audio_device_common_unit_next_test.cpp | 6 +- .../audio_interrupt_service_pro_unit_test.cpp | 9 +- .../src/audio_policy_server_unit_test.cpp | 178 +- .../audio_policy_server_unit_test_second.cpp | 31 +- .../audio_policy_client_proxy_unit_test.cpp | 408 --- .../audio_policy_client_stub_impl_test.cpp | 36 +- .../audio_policy_client_stub_unit_test.cpp | 353 -- .../include/audio_policy_manager_stub_test.h | 39 - .../src/audio_policy_manager_stub_test.cpp | 873 ----- .../audio_policy_manager_stub_unit_test.h | 2 +- .../audio_policy_manager_stub_unit_test.cpp | 248 +- .../audio_policy_server_handler_unit_test.cpp | 67 +- .../audio_policy_service_second_unit_test.h | 30 +- .../audio_policy_service_first_unit_test.cpp | 12 +- .../audio_policy_service_third_unit_test.cpp | 1 + ..._routing_manager_listener_stub_unit_test.h | 38 - ...outing_manager_listener_stub_unit_test.cpp | 143 - ...audio_spatialization_service_unit_test.cpp | 2 +- .../audio_stream_collector_unit_test.h | 2 +- .../audio_stream_collector_pro_unit_test.cpp | 2 +- .../src/audio_stream_collector_unit_test.cpp | 26 +- .../audio_zone_interrupt_unit_test.cpp | 332 -- .../audio_zone_unit_test.cpp | 36 - .../audio_zone_unit_test_base.h | 113 - ...dio_policy_manager_zone_stub_unit_test.cpp | 131 - .../src/audio_zone_client_unit_test.cpp | 62 - services/audio_service/BUILD.gn | 57 +- .../client/include/audio_manager_base.h | 773 +---- ...b.h => audio_manager_listener_stub_impl.h} | 27 +- .../client/include/audio_manager_proxy.h | 165 - .../client/include/audio_process_proxy.h | 67 - ...stub.h => audio_workgroup_callback_impl.h} | 17 +- .../client/include/capturer_in_client_inner.h | 7 +- .../include/core_service_provider_stub.h | 34 +- .../client/include/ipc_offline_stream_proxy.h | 51 - .../client/include/ipc_stream_listener_impl.h | 5 +- .../client/include/ipc_stream_listener_stub.h | 36 - .../client/include/ipc_stream_proxy.h | 112 - .../client/include/offline_stream_in_client.h | 6 +- .../client/include/policy_provider_stub.h | 46 +- .../include/pulseaudio_ipc_interface_code.h | 1 + .../include/renderer_in_client_private.h | 4 +- .../src/audio_collaborative_manager.cpp | 1 - .../audio_service/client/src/audio_filter.cpp | 26 +- .../client/src/audio_group_manager.cpp | 16 +- ...p => audio_manager_listener_stub_impl.cpp} | 93 +- .../client/src/audio_manager_proxy.cpp | 2017 ------------ .../client/src/audio_process_in_client.cpp | 20 +- .../client/src/audio_process_proxy.cpp | 292 -- .../client/src/audio_routing_manager.cpp | 1 - .../src/audio_spatialization_manager.cpp | 1 - .../client/src/audio_system_manager.cpp | 80 +- .../src/audio_workgroup_callback_impl.cpp} | 57 +- .../src/audio_workgroup_callback_stub.cpp | 78 - .../client/src/capturer_in_client.cpp | 13 +- .../client/src/core_service_provider_stub.cpp | 109 +- .../client/src/ipc_offline_stream_proxy.cpp | 125 - .../client/src/ipc_stream_listener_impl.cpp | 10 +- .../client/src/ipc_stream_listener_stub.cpp | 70 - .../client/src/ipc_stream_proxy.cpp | 636 ---- .../client/src/microphone_descriptor.cpp | 24 +- .../client/src/offline_stream_in_client.cpp | 11 +- .../client/src/policy_provider_stub.cpp | 229 +- .../client/src/renderer_in_client.cpp | 13 +- .../client/src/renderer_in_client_public.cpp | 6 +- .../common/include/audio_process_config.h | 8 - .../common/include/audio_shared_memory.h | 4 +- .../common/include/i_audio_process.h | 109 - .../common/include/i_audio_process_stream.h | 2 +- .../include/i_core_service_provider_ipc.h | 48 - .../common/include/i_policy_provider_ipc.h | 59 - ...i_standard_audio_server_manager_listener.h | 48 - .../common/include/ipc_offline_stream.h | 63 - .../common/include/oh_audio_buffer.h | 18 +- .../common/src/audio_process_config.cpp | 219 -- .../common/src/oh_audio_buffer.cpp | 68 + .../common/src/oh_audio_buffer_base.cpp | 123 + .../idl/AudioServiceTypes.idl} | 32 +- services/audio_service/idl/BUILD.gn | 147 + services/audio_service/idl/IAudioProcess.idl | 39 + .../idl/ICoreServiceProviderIpc.idl | 40 + .../idl/IIpcOfflineStream.idl} | 38 +- services/audio_service/idl/IIpcStream.idl | 65 + .../IIpcStreamListener.idl} | 33 +- .../audio_service/idl/IPolicyProviderIpc.idl | 40 + services/audio_service/idl/IProcessCb.idl | 20 + .../IStandardAudioServerManagerListener.idl | 24 + .../idl/IStandardAudioService.idl | 144 + .../libaudio_process_service.versionscript | 1 + ...tener_proxy.h => audio_manager_listener.h} | 29 +- .../server/include/audio_process_in_server.h | 36 +- .../server/include/audio_process_stub.h | 61 - .../server/include/audio_server.h | 189 +- .../server/include/audio_service.h | 1 - ...ack_proxy.h => audio_workgroup_callback.h} | 15 +- .../server/include/core_service_handler.h | 3 +- .../include/core_service_provider_proxy.h | 42 - .../server/include/ipc_offline_stream_stub.h | 45 - .../server/include/ipc_stream_in_server.h | 20 +- .../server/include/ipc_stream_stub.h | 91 - .../server/include/offline_stream_in_server.h | 2 +- .../server/include/policy_handler.h | 3 +- .../server/include/policy_provider_proxy.h | 67 - ...r_proxy.cpp => audio_manager_listener.cpp} | 92 +- .../server/src/audio_manager_stub.cpp | 1546 --------- .../server/src/audio_process_in_server.cpp | 34 +- .../server/src/audio_process_stub.cpp | 230 -- .../server/src/audio_resource_service.cpp | 2 +- .../audio_service/server/src/audio_server.cpp | 485 ++- .../server/src/audio_server_asr.cpp | 49 +- .../server/src/audio_server_effect.cpp | 188 +- ...proxy.cpp => audio_workgroup_callback.cpp} | 34 +- .../server/src/core_service_handler.cpp | 8 +- .../src/core_service_provider_proxy.cpp | 127 - .../server/src/ipc_offline_stream_stub.cpp | 146 - .../server/src/ipc_stream_in_server.cpp | 30 +- .../server/src/ipc_stream_listener_proxy.cpp | 60 - .../server/src/ipc_stream_stub.cpp | 499 --- .../server/src/offline_stream_in_server.cpp | 5 +- .../server/src/policy_handler.cpp | 4 +- .../server/src/policy_provider_proxy.cpp | 260 -- services/audio_service/test/unittest/BUILD.gn | 206 +- ...audio_manager_listener_proxy_unit_test.cpp | 211 -- .../audio_manager_stub_unit_test/BUILD.gn | 84 - .../include/audio_manager_stub_unit_test.h | 37 - .../audio_process_in_server_unit_test.cpp | 13 +- .../audio_server_dump_unit_test/BUILD.gn | 6 +- .../unittest/audio_server_unit_test/BUILD.gn | 6 +- .../src/audio_server_unit_test.cpp | 164 +- .../audio_service_common_unit_test.cpp | 21 +- .../test/unittest/audio_service_unit_test.cpp | 166 - .../client/capturer_in_client_unit_test.cpp | 98 +- .../ipc_stream_in_server_unit_test.cpp | 12 +- .../offline_stream_in_server_unit_test.cpp | 1 + .../unittest/policy_handler_unit_test.cpp | 18 +- .../BUILD.gn | 1 + .../BUILD.gn | 6 +- .../renderer_in_server_unit_test/BUILD.gn | 10 +- .../server/audio_server_unit_test.cpp | 11 +- test/BUILD.gn | 22 +- .../audioadaptermanager_fuzzer/BUILD.gn | 6 +- .../audioadaptorbluetooth_fuzzer/BUILD.gn | 3 +- .../audiobluetoothmanager_fuzzer/BUILD.gn | 6 +- .../audioconnecteddevice_fuzzer/BUILD.gn | 11 +- .../audio_effect_chain_fuzzer.cpp | 7 +- .../audiointerruptservice_fuzzer/BUILD.gn | 7 +- .../audiointerruptservicemore_fuzzer/BUILD.gn | 1 + .../audio_interrupt_service_more_fuzzer.cpp | 3 +- .../audio_manager_stub_fuzzer.cpp | 4 +- .../fuzztest/audiopipemanager_fuzzer/BUILD.gn | 4 +- .../audiopipeselector_fuzzer/BUILD.gn | 4 +- test/fuzztest/audiopolicy_fuzzer/BUILD.gn | 1 + .../audio_policy_another_fuzzer.cpp | 2 +- .../audiopolicyclient_fuzzer/BUILD.gn | 9 +- .../audio_policy_client_proxy_fuzzer.cpp | 37 +- .../audiopolicyconcurrency_fuzzer/BUILD.gn | 3 +- .../fuzztest/audiopolicyproxy_fuzzer/BUILD.gn | 3 +- .../audio_policy_proxy_fuzzer.cpp | 423 +-- .../audiopowerstatelistener_fuzzer/BUILD.gn | 3 +- test/fuzztest/audioserver_fuzzer/BUILD.gn | 3 +- .../audio_server_fuzzer.cpp | 34 +- .../audioserverbalance_fuzzer/BUILD.gn | 7 +- .../audio_server_balance_fuzzer.cpp | 1 + .../audio_server_more_fuzzer.cpp | 5 +- test/fuzztest/audioservice_fuzzer/BUILD.gn | 5 +- .../audioserviceclient_fuzzer/BUILD.gn | 5 +- .../audio_service_client_fuzzer.cpp | 2 +- .../audio_service_server_src_fuzzer.cpp | 2 +- ...udio_service_server_src_enhance_fuzzer.cpp | 83 - test/fuzztest/audiostream_fuzzer/BUILD.gn | 5 +- .../audio_stream_fuzzer.cpp | 38 +- .../audiostreamcollector_fuzzer/BUILD.gn | 2 + .../audio_stream_collector_fuzzer.cpp | 22 +- test/fuzztest/audioutils_fuzzer/BUILD.gn | 3 +- .../audiovolumemanager_fuzzer/BUILD.gn | 6 +- .../captureclockmanager_fuzzer/BUILD.gn | 8 +- .../devicestatuslistener_fuzzer/BUILD.gn | 1 + .../istandardaudiozoneclient_fuzzer/BUILD.gn | 12 +- .../BUILD.gn | 12 +- .../sleaudiodevicemanager_fuzzer/BUILD.gn | 2 +- 364 files changed, 7663 insertions(+), 30133 deletions(-) delete mode 100644 services/audio_policy/client/interface/audio_policy_base.h delete mode 100644 services/audio_policy/client/interface/i_standard_audio_anahs_manager_listener.h delete mode 100644 services/audio_policy/client/interface/i_standard_audio_policy_manager_listener.h delete mode 100644 services/audio_policy/client/interface/i_standard_audio_routing_manager_listener.h delete mode 100644 services/audio_policy/client/interface/i_standard_audio_zone_client.h delete mode 100644 services/audio_policy/client/interface/i_standard_client_tracker.h delete mode 100644 services/audio_policy/client/interface/i_standard_concurrency_state_listener.h delete mode 100644 services/audio_policy/client/proxy/include/audio_policy_proxy.h delete mode 100644 services/audio_policy/client/proxy/src/audio_policy_callback_proxy.cpp delete mode 100644 services/audio_policy/client/proxy/src/audio_policy_microphone_proxy.cpp delete mode 100644 services/audio_policy/client/proxy/src/audio_policy_proxy.cpp delete mode 100644 services/audio_policy/client/proxy/src/audio_policy_volume_proxy.cpp delete mode 100644 services/audio_policy/client/proxy/src/audio_policy_zone_proxy.cpp rename services/audio_policy/client/{stub/include/audio_anahs_manager_listener_stub.h => service/include/audio_anahs_manager_listener.h} (53%) rename services/audio_policy/client/{stub/include/audio_routing_manager_listener_stub.h => service/include/audio_routing_manager_listener.h} (53%) rename services/audio_policy/client/{stub/src/audio_anahs_manager_listener_stub.cpp => service/src/audio_anahs_manager_listener.cpp} (48%) rename services/audio_policy/client/{stub/src/audio_routing_manager_listener_stub.cpp => service/src/audio_routing_manager_listener.cpp} (37%) delete mode 100644 services/audio_policy/client/stub/include/audio_policy_client_stub.h rename services/audio_policy/client/stub/include/{audio_policy_manager_listener_stub.h => audio_policy_manager_listener_stub_impl.h} (60%) delete mode 100644 services/audio_policy/client/stub/include/sle_audio_operation_callback_stub.h rename services/audio_policy/{server/proxy/include/sle_audio_operation_callback_proxy.h => client/stub/include/sle_audio_operation_callback_stub_impl.h} (49%) delete mode 100644 services/audio_policy/client/stub/src/audio_policy_client_stub.cpp rename services/audio_policy/client/stub/src/{audio_policy_manager_listener_stub.cpp => audio_policy_manager_listener_stub_impl.cpp} (32%) delete mode 100644 services/audio_policy/client/stub/src/audio_spatialization_state_change_listener_stub.cpp rename services/audio_policy/client/stub/src/{sle_audio_operation_callback_stub.cpp => sle_audio_operation_callback_stub_impl.cpp} (39%) delete mode 100644 services/audio_policy/common/include/i_standard_sle_audio_operation_callback.h create mode 100644 services/audio_policy/idl/IAudioPolicy.idl create mode 100644 services/audio_policy/idl/IAudioPolicyClient.idl rename services/audio_policy/{test/unittest/audio_policy_client_stub_unit_test/include/audio_policy_client_stub_unit_test.h => idl/IAudioWorkgroupCallback.idl} (47%) rename services/audio_policy/{test/unittest/audio_policy_client_proxy_unit_test/include/audio_policy_client_proxy_unit_test.h => idl/IStandardAudioAnahsManagerListener.idl} (47%) create mode 100644 services/audio_policy/idl/IStandardAudioPolicyManagerListener.idl rename services/audio_policy/{test/unittest/audio_zone_unit_test/include/audio_policy_manager_zone_stub_unit_test.h => idl/IStandardAudioRoutingManagerListener.idl} (40%) create mode 100644 services/audio_policy/idl/IStandardAudioZoneClient.idl create mode 100644 services/audio_policy/idl/IStandardClientTracker.idl create mode 100644 services/audio_policy/idl/IStandardConcurrencyStateListener.idl rename services/audio_policy/{test/unittest/audio_zone_unit_test/src/audio_zone_class_unit_test.cpp => idl/IStandardSleAudioOperationCallback.idl} (35%) create mode 100644 services/audio_policy/idl/IStandardSpatializationStateChangeListener.idl delete mode 100644 services/audio_policy/server/domain/zone/include/audio_zone_client_proxy.h delete mode 100644 services/audio_policy/server/domain/zone/src/audio_zone_client_proxy.cpp rename services/audio_policy/server/{proxy/include/audio_client_tracker_callback_proxy.h => include/audio_client_tracker_callback_listener.h} (57%) rename services/audio_policy/{client/stub/include/audio_client_tracker_callback_stub.h => server/include/audio_client_tracker_callback_service.h} (39%) rename services/audio_policy/server/{proxy/include/audio_concurrency_state_listener_proxy.h => include/audio_concurrency_state_listener_callback.h} (64%) rename services/audio_policy/{client/stub/include/audio_concurrency_state_listener_stub.h => server/include/audio_concurrency_state_listener_service.h} (60%) rename services/audio_policy/server/{proxy/include/audio_policy_manager_listener_proxy.h => include/audio_policy_manager_listener.h} (63%) rename services/audio_policy/server/{proxy/include/audio_spatialization_state_change_listener_proxy.h => include/audio_spatialization_state_change_callback.h} (57%) rename services/audio_policy/{client/stub/include/audio_spatialization_state_change_listener_stub.h => server/include/audio_spatialization_state_change_listener.h} (51%) rename services/audio_policy/server/{proxy/include/audio_policy_client_proxy.h => infra/ipc_proxy/include/audio_policy_client_holder.h} (51%) create mode 100644 services/audio_policy/server/infra/ipc_proxy/src/audio_policy_client_holder.cpp delete mode 100644 services/audio_policy/server/proxy/include/audio_anahs_manager_listener_proxy.h delete mode 100644 services/audio_policy/server/proxy/include/audio_routing_manager_listener_proxy.h delete mode 100644 services/audio_policy/server/proxy/src/audio_anahs_manager_listener_proxy.cpp delete mode 100644 services/audio_policy/server/proxy/src/audio_policy_client_proxy.cpp delete mode 100644 services/audio_policy/server/proxy/src/audio_policy_manager_listener_proxy.cpp delete mode 100644 services/audio_policy/server/proxy/src/audio_routing_manager_listener_proxy.cpp delete mode 100644 services/audio_policy/server/proxy/src/audio_spatialization_state_change_listener_proxy.cpp delete mode 100644 services/audio_policy/server/proxy/src/sle_audio_operation_callback_proxy.cpp rename services/audio_policy/server/{proxy/src/audio_client_tracker_callback_proxy.cpp => src/audio_client_tracker_callback_listener.cpp} (31%) rename services/audio_policy/{client/stub/src/audio_client_tracker_callback_stub.cpp => server/src/audio_client_tracker_callback_service.cpp} (41%) rename services/audio_policy/server/{proxy/src/audio_concurrency_state_listener_proxy.cpp => src/audio_concurrency_state_listener_callback.cpp} (55%) rename services/audio_policy/{client/stub/src/audio_concurrency_state_listener_stub.cpp => server/src/audio_concurrency_state_listener_service.cpp} (47%) create mode 100644 services/audio_policy/server/src/audio_policy_manager_listener.cpp rename services/{audio_service/server/include/ipc_stream_listener_proxy.h => audio_policy/server/src/audio_spatialization_state_change_callback.cpp} (41%) rename services/audio_policy/{client/interface/i_standard_spatialization_state_change_listener.h => server/src/audio_spatialization_state_change_listener.cpp} (34%) delete mode 100644 services/audio_policy/server/stub/include/audio_policy_manager_stub.h delete mode 100644 services/audio_policy/server/stub/src/audio_policy_manager_device_stub.cpp delete mode 100644 services/audio_policy/server/stub/src/audio_policy_manager_stub.cpp delete mode 100644 services/audio_policy/server/stub/src/audio_policy_manager_zone_stub.cpp delete mode 100644 services/audio_policy/test/unittest/audio_client_tracker_callback_proxy_unit_test/include/audio_client_tracker_callback_proxy_unit_test.h delete mode 100644 services/audio_policy/test/unittest/audio_client_tracker_callback_proxy_unit_test/src/audio_client_tracker_callback_proxy_unit_test.cpp delete mode 100644 services/audio_policy/test/unittest/audio_client_tracker_callback_stub_unit_test/include/audio_client_tracker_callback_stub_unit_test.h delete mode 100644 services/audio_policy/test/unittest/audio_client_tracker_callback_stub_unit_test/src/audio_client_tracker_callback_stub_unit_test.cpp delete mode 100644 services/audio_policy/test/unittest/audio_policy_client_proxy_unit_test/src/audio_policy_client_proxy_unit_test.cpp delete mode 100644 services/audio_policy/test/unittest/audio_policy_client_stub_unit_test/src/audio_policy_client_stub_unit_test.cpp delete mode 100644 services/audio_policy/test/unittest/audio_policy_manager_stub_test/include/audio_policy_manager_stub_test.h delete mode 100644 services/audio_policy/test/unittest/audio_policy_manager_stub_test/src/audio_policy_manager_stub_test.cpp delete mode 100644 services/audio_policy/test/unittest/audio_routing_manager_listener_stub_unit_test/include/audio_routing_manager_listener_stub_unit_test.h delete mode 100644 services/audio_policy/test/unittest/audio_routing_manager_listener_stub_unit_test/src/audio_routing_manager_listener_stub_unit_test.cpp delete mode 100644 services/audio_policy/test/unittest/audio_zone_service_unit_test/audio_zone_interrupt_unit_test.cpp delete mode 100644 services/audio_policy/test/unittest/audio_zone_unit_test/src/audio_policy_manager_zone_stub_unit_test.cpp delete mode 100644 services/audio_policy/test/unittest/audio_zone_unit_test/src/audio_zone_client_unit_test.cpp rename services/audio_service/client/include/{audio_manager_listener_stub.h => audio_manager_listener_stub_impl.h} (65%) delete mode 100644 services/audio_service/client/include/audio_manager_proxy.h delete mode 100644 services/audio_service/client/include/audio_process_proxy.h rename services/audio_service/client/include/{audio_workgroup_callback_stub.h => audio_workgroup_callback_impl.h} (65%) delete mode 100644 services/audio_service/client/include/ipc_offline_stream_proxy.h delete mode 100644 services/audio_service/client/include/ipc_stream_listener_stub.h delete mode 100644 services/audio_service/client/include/ipc_stream_proxy.h rename services/audio_service/client/src/{audio_manager_listener_stub.cpp => audio_manager_listener_stub_impl.cpp} (47%) delete mode 100644 services/audio_service/client/src/audio_manager_proxy.cpp delete mode 100644 services/audio_service/client/src/audio_process_proxy.cpp rename services/audio_service/{common/include/i_audio_workgroup_callback.h => client/src/audio_workgroup_callback_impl.cpp} (43%) delete mode 100644 services/audio_service/client/src/audio_workgroup_callback_stub.cpp delete mode 100644 services/audio_service/client/src/ipc_offline_stream_proxy.cpp delete mode 100644 services/audio_service/client/src/ipc_stream_listener_stub.cpp delete mode 100644 services/audio_service/client/src/ipc_stream_proxy.cpp delete mode 100644 services/audio_service/common/include/i_audio_process.h delete mode 100644 services/audio_service/common/include/i_core_service_provider_ipc.h delete mode 100644 services/audio_service/common/include/i_policy_provider_ipc.h delete mode 100755 services/audio_service/common/include/i_standard_audio_server_manager_listener.h delete mode 100644 services/audio_service/common/include/ipc_offline_stream.h rename services/{audio_policy/test/unittest/audio_zone_unit_test/include/audio_zone_class_unit_test.h => audio_service/idl/AudioServiceTypes.idl} (48%) create mode 100644 services/audio_service/idl/BUILD.gn create mode 100644 services/audio_service/idl/IAudioProcess.idl create mode 100644 services/audio_service/idl/ICoreServiceProviderIpc.idl rename services/{audio_policy/test/unittest/audio_zone_unit_test/include/audio_zone_client_unit_test.h => audio_service/idl/IIpcOfflineStream.idl} (44%) create mode 100644 services/audio_service/idl/IIpcStream.idl rename services/audio_service/{client/include/audio_process_cb_stub.h => idl/IIpcStreamListener.idl} (45%) create mode 100644 services/audio_service/idl/IPolicyProviderIpc.idl create mode 100644 services/audio_service/idl/IProcessCb.idl create mode 100644 services/audio_service/idl/IStandardAudioServerManagerListener.idl create mode 100644 services/audio_service/idl/IStandardAudioService.idl rename services/audio_service/server/include/{audio_manager_listener_proxy.h => audio_manager_listener.h} (57%) delete mode 100644 services/audio_service/server/include/audio_process_stub.h rename services/audio_service/server/include/{audio_workgroup_callback_proxy.h => audio_workgroup_callback.h} (66%) delete mode 100644 services/audio_service/server/include/core_service_provider_proxy.h delete mode 100644 services/audio_service/server/include/ipc_offline_stream_stub.h delete mode 100644 services/audio_service/server/include/ipc_stream_stub.h delete mode 100644 services/audio_service/server/include/policy_provider_proxy.h rename services/audio_service/server/src/{audio_manager_listener_proxy.cpp => audio_manager_listener.cpp} (38%) delete mode 100644 services/audio_service/server/src/audio_manager_stub.cpp delete mode 100644 services/audio_service/server/src/audio_process_stub.cpp rename services/audio_service/server/src/{audio_workgroup_callback_proxy.cpp => audio_workgroup_callback.cpp} (55%) delete mode 100644 services/audio_service/server/src/core_service_provider_proxy.cpp delete mode 100644 services/audio_service/server/src/ipc_offline_stream_stub.cpp delete mode 100644 services/audio_service/server/src/ipc_stream_listener_proxy.cpp delete mode 100644 services/audio_service/server/src/ipc_stream_stub.cpp delete mode 100644 services/audio_service/server/src/policy_provider_proxy.cpp delete mode 100644 services/audio_service/test/unittest/audio_manager_listener_proxy_unit_test.cpp delete mode 100644 services/audio_service/test/unittest/audio_manager_stub_unit_test/BUILD.gn delete mode 100755 services/audio_service/test/unittest/audio_manager_stub_unit_test/include/audio_manager_stub_unit_test.h diff --git a/config.gni b/config.gni index 96d48d6e2b..df2b5b314d 100644 --- a/config.gni +++ b/config.gni @@ -104,3 +104,4 @@ declare_args() { } third_party_path = "//third_party" +audio_framework_root = "//foundation/multimedia/audio_framework" \ No newline at end of file diff --git a/frameworks/native/audiocapturer/BUILD.gn b/frameworks/native/audiocapturer/BUILD.gn index 123c34c7eb..6a59c6ff5b 100644 --- a/frameworks/native/audiocapturer/BUILD.gn +++ b/frameworks/native/audiocapturer/BUILD.gn @@ -68,6 +68,7 @@ ohos_shared_library("audio_capturer") { } deps = [ + "${audio_framework_root}/services/audio_service:audio_common", "../../../services/audio_policy:audio_policy_client", "../../../services/audio_service:audio_client", "../audiodefinitions:audio_definitions", diff --git a/frameworks/native/audiocapturer/include/audio_capturer_private.h b/frameworks/native/audiocapturer/include/audio_capturer_private.h index ce3f3113af..e65d598558 100644 --- a/frameworks/native/audiocapturer/include/audio_capturer_private.h +++ b/frameworks/native/audiocapturer/include/audio_capturer_private.h @@ -112,7 +112,7 @@ public: std::shared_ptr audioStream_; AudioCapturerInfo capturerInfo_ = {}; - AudioPlaybackCaptureConfig filterConfig_ = {{{}, FilterMode::INCLUDE, {}, FilterMode::INCLUDE}, false}; + AudioPlaybackCaptureConfig filterConfig_ = {}; AudioStreamType audioStreamType_; bool abortRestore_ = false; AudioSessionStrategy strategy_ = { AudioConcurrencyMode::INVALID }; diff --git a/frameworks/native/audiocapturer/test/benchmark/BUILD.gn b/frameworks/native/audiocapturer/test/benchmark/BUILD.gn index 29430d01ab..d163652c7c 100644 --- a/frameworks/native/audiocapturer/test/benchmark/BUILD.gn +++ b/frameworks/native/audiocapturer/test/benchmark/BUILD.gn @@ -24,6 +24,11 @@ ohos_benchmarktest("BenchmarkAudioCapturerTest") { ] sources = [ "benchmark_audiocapturer_test.cpp" ] deps = [ "../../../audiocapturer:audio_capturer" ] + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_single", + ] } group("benchmarktest") { diff --git a/frameworks/native/audiocapturer/test/unittest/capturer_test/BUILD.gn b/frameworks/native/audiocapturer/test/unittest/capturer_test/BUILD.gn index 1b72329914..6e664f5979 100644 --- a/frameworks/native/audiocapturer/test/unittest/capturer_test/BUILD.gn +++ b/frameworks/native/audiocapturer/test/unittest/capturer_test/BUILD.gn @@ -23,6 +23,7 @@ ohos_unittest("audio_capturer_unit_test") { "../../../include", "../../../../../../interfaces/inner_api/native/audiocommon/include", "../../../../audiostream/include", + "../../../../../../services/audio_policy/server/include", ] cflags = [ diff --git a/frameworks/native/audiocapturer/test/unittest/capturer_test/src/audio_capturer_extra_plus_unit_test.cpp b/frameworks/native/audiocapturer/test/unittest/capturer_test/src/audio_capturer_extra_plus_unit_test.cpp index 1c98e5f989..05274adabf 100644 --- a/frameworks/native/audiocapturer/test/unittest/capturer_test/src/audio_capturer_extra_plus_unit_test.cpp +++ b/frameworks/native/audiocapturer/test/unittest/capturer_test/src/audio_capturer_extra_plus_unit_test.cpp @@ -25,6 +25,7 @@ #include "audio_info.h" #include "audio_system_manager.h" #include "fast_audio_stream.h" +#include "audio_client_tracker_callback_service.h" using namespace std; using namespace testing::ext; diff --git a/frameworks/native/audiocapturer/test/unittest/multiple_capturer_test/BUILD.gn b/frameworks/native/audiocapturer/test/unittest/multiple_capturer_test/BUILD.gn index d4e41455d2..2d8c307fe3 100644 --- a/frameworks/native/audiocapturer/test/unittest/multiple_capturer_test/BUILD.gn +++ b/frameworks/native/audiocapturer/test/unittest/multiple_capturer_test/BUILD.gn @@ -12,6 +12,7 @@ # limitations under the License. import("//build/test.gni") +import("../../../../../../config.gni") module_output_path = "audio_framework/audio_framework_route/multiple_audio_capturer" @@ -32,5 +33,8 @@ ohos_unittest("multiple_audio_capturer_unit_test") { deps = [ "../../../../audiocapturer:audio_capturer" ] - external_deps = [ "hilog:libhilog" ] + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + ] } diff --git a/frameworks/native/audiodefinitions/include/audio_stream_descriptor.h b/frameworks/native/audiodefinitions/include/audio_stream_descriptor.h index b32fc2120d..6d799d418c 100644 --- a/frameworks/native/audiodefinitions/include/audio_stream_descriptor.h +++ b/frameworks/native/audiodefinitions/include/audio_stream_descriptor.h @@ -31,7 +31,7 @@ enum AudioStreamAction : uint32_t { AUDIO_STREAM_ACTION_RECREATE, }; -class AudioStreamDescriptor { +class AudioStreamDescriptor : public Parcelable { public: AudioStreamInfo streamInfo_; AudioMode audioMode_ = AUDIO_MODE_PLAYBACK; @@ -53,8 +53,8 @@ public: AudioStreamDescriptor(); virtual ~AudioStreamDescriptor(); - bool Marshalling(Parcel &parcel) const; - void Unmarshalling(Parcel &parcel); + bool Marshalling(Parcel &parcel) const override; + static AudioStreamDescriptor *Unmarshalling(Parcel &parcel); bool WriteDeviceDescVectorToParcel( Parcel &parcel, std::vector> &descs) const; void UnmarshallingDeviceDescVector(Parcel &parcel, std::vector> &descs); diff --git a/frameworks/native/audiodefinitions/src/audio_stream_descriptor.cpp b/frameworks/native/audiodefinitions/src/audio_stream_descriptor.cpp index 5372a5cfdb..a1df052a77 100644 --- a/frameworks/native/audiodefinitions/src/audio_stream_descriptor.cpp +++ b/frameworks/native/audiodefinitions/src/audio_stream_descriptor.cpp @@ -70,25 +70,32 @@ bool AudioStreamDescriptor::Marshalling(Parcel &parcel) const WriteDeviceDescVectorToParcel(parcel, newDeviceDescs_); } -void AudioStreamDescriptor::Unmarshalling(Parcel &parcel) +AudioStreamDescriptor *AudioStreamDescriptor::Unmarshalling(Parcel &parcel) { - streamInfo_.Unmarshalling(parcel); - audioMode_ = static_cast(parcel.ReadUint32()); - audioFlag_ = static_cast(parcel.ReadUint32()); - routeFlag_ = static_cast(parcel.ReadUint32()); - startTimeStamp_ = parcel.ReadInt64(); - rendererInfo_.Unmarshalling(parcel); - capturerInfo_.Unmarshalling(parcel); - appInfo_.appUid = parcel.ReadInt32(); - appInfo_.appTokenId = parcel.ReadUint32(); - appInfo_.appPid = parcel.ReadInt32(); - appInfo_.appFullTokenId = parcel.ReadUint64(); - sessionId_ = parcel.ReadUint32(); - callerUid_ = parcel.ReadInt32(); - callerPid_ = parcel.ReadInt32(); - streamAction_ = static_cast(parcel.ReadUint32()); - UnmarshallingDeviceDescVector(parcel, oldDeviceDescs_); - UnmarshallingDeviceDescVector(parcel, newDeviceDescs_); + auto info = new AudioStreamDescriptor(); + if (info == nullptr) { + return nullptr; + } + + info->streamInfo_.UnmarshallingSelf(parcel); + info->audioMode_ = static_cast(parcel.ReadUint32()); + info->audioFlag_ = static_cast(parcel.ReadUint32()); + info->routeFlag_ = static_cast(parcel.ReadUint32()); + info->startTimeStamp_ = parcel.ReadInt64(); + info->rendererInfo_.UnmarshallingSelf(parcel); + info->capturerInfo_.UnmarshallingSelf(parcel); + info->appInfo_.appUid = parcel.ReadInt32(); + info->appInfo_.appTokenId = parcel.ReadUint32(); + info->appInfo_.appPid = parcel.ReadInt32(); + info->appInfo_.appFullTokenId = parcel.ReadUint64(); + info->sessionId_ = parcel.ReadUint32(); + info->callerUid_ = parcel.ReadInt32(); + info->callerPid_ = parcel.ReadInt32(); + info->streamAction_ = static_cast(parcel.ReadUint32()); + info->UnmarshallingDeviceDescVector(parcel, info->oldDeviceDescs_); + info->UnmarshallingDeviceDescVector(parcel, info->newDeviceDescs_); + + return info; } bool AudioStreamDescriptor::WriteDeviceDescVectorToParcel( @@ -118,7 +125,7 @@ void AudioStreamDescriptor::UnmarshallingDeviceDescVector( return; } for (int32_t i = 0; i < size; i++) { - descs.push_back(AudioDeviceDescriptor::UnmarshallingPtr(parcel)); + descs.push_back(std::shared_ptr(AudioDeviceDescriptor::Unmarshalling(parcel))); } } diff --git a/frameworks/native/audioeffect/test/unittest/effect_unit_test/src/audio_effect_chain_manager_unit_test.cpp b/frameworks/native/audioeffect/test/unittest/effect_unit_test/src/audio_effect_chain_manager_unit_test.cpp index e133bc89c5..f8ab8f78bf 100644 --- a/frameworks/native/audioeffect/test/unittest/effect_unit_test/src/audio_effect_chain_manager_unit_test.cpp +++ b/frameworks/native/audioeffect/test/unittest/effect_unit_test/src/audio_effect_chain_manager_unit_test.cpp @@ -945,7 +945,7 @@ HWTEST(AudioEffectChainManagerUnitTest, UpdateSpatializationState_003, TestSize. */ HWTEST(AudioEffectChainManagerUnitTest, UpdateSpatializationState_004, TestSize.Level1) { - AudioSpatializationState spatializationState = {false, true}; + AudioSpatializationState spatializationState(false, true); AudioEffectChainManager::GetInstance()->InitAudioEffectChainManager(DEFAULT_EFFECT_CHAINS, DEFAULT_EFFECT_CHAIN_MANAGER_PARAM, DEFAULT_EFFECT_LIBRARY_LIST); @@ -2042,10 +2042,7 @@ HWTEST(AudioEffectChainManagerUnitTest, UpdateSpatializationEnabled_001, TestSiz AudioEffectChainManager::GetInstance()->sceneTypeToEffectChainMap_[sceneTypeAndDeviceKey] = audioEffectChain; int32_t result = AudioEffectChainManager::GetInstance()->InitAudioEffectChainDynamic(sceneType); EXPECT_EQ(SUCCESS, result); - AudioSpatializationState audioSpatializationState = { - .spatializationEnabled = true, - .headTrackingEnabled = false, - }; + AudioSpatializationState audioSpatializationState(true, false); AudioEffectChainManager::GetInstance()->UpdateSpatializationEnabled(audioSpatializationState); audioSpatializationState.spatializationEnabled = false; AudioEffectChainManager::GetInstance()->UpdateSpatializationEnabled(audioSpatializationState); diff --git a/frameworks/native/audiopolicy/include/audio_policy_manager.h b/frameworks/native/audiopolicy/include/audio_policy_manager.h index 640343bf5c..1f4fbacc13 100644 --- a/frameworks/native/audiopolicy/include/audio_policy_manager.h +++ b/frameworks/native/audiopolicy/include/audio_policy_manager.h @@ -18,28 +18,27 @@ #include #include -#include "audio_client_tracker_callback_stub.h" +#include "audio_client_tracker_callback_service.h" +#include "audio_client_tracker_callback_listener.h" #include "audio_effect.h" #include "audio_concurrency_callback.h" -#include "audio_concurrency_state_listener_stub.h" +#include "audio_concurrency_state_listener_callback.h" #include "audio_interrupt_callback.h" -#include "audio_policy_base.h" -#include "audio_policy_manager_listener_stub.h" +#include "iaudio_policy.h" +#include "audio_policy_manager_listener_stub_impl.h" #include "audio_policy_client_stub_impl.h" #include "audio_routing_manager.h" -#include "audio_routing_manager_listener_stub.h" -#include "audio_anahs_manager_listener_stub.h" +#include "audio_routing_manager_listener.h" +#include "audio_anahs_manager_listener.h" #include "audio_policy_interface.h" #include "audio_system_manager.h" -#include "i_standard_client_tracker.h" +#include "istandard_client_tracker.h" #include "audio_policy_log.h" #include "microphone_descriptor.h" #include "audio_spatialization_manager.h" -#include "audio_spatialization_state_change_listener_stub.h" -#include "i_standard_spatialization_state_change_listener.h" #include "audio_combine_denoising_manager.h" #include "audio_stream_descriptor.h" -#include "sle_audio_operation_callback_stub.h" +#include "sle_audio_operation_callback_stub_impl.h" namespace OHOS { namespace AudioStandard { @@ -686,7 +685,7 @@ private: static std::unordered_map> rendererCBMap_; static std::weak_ptr capturerCB_; static std::vector> audioStreamCBMap_; - static std::unordered_map> clientTrackerStubMap_; + static std::unordered_map> clientTrackerStubMap_; bool isAudioRendererEventListenerRegistered = false; bool isAudioCapturerEventListenerRegistered = false; diff --git a/frameworks/native/audiopolicy/include/audio_zone_info.h b/frameworks/native/audiopolicy/include/audio_zone_info.h index 2be8ce0a4a..a0edd619cf 100644 --- a/frameworks/native/audiopolicy/include/audio_zone_info.h +++ b/frameworks/native/audiopolicy/include/audio_zone_info.h @@ -46,7 +46,7 @@ enum class AudioZoneFocusStrategy { DISTRIBUTED_FOCUS_STRATEGY = 1, }; -class AudioZoneContext { +class AudioZoneContext : public Parcelable { public: AudioZoneFocusStrategy focusStrategy_ = AudioZoneFocusStrategy::LOCAL_FOCUS_STRATEGY; @@ -57,9 +57,15 @@ public: return parcel.WriteInt32(static_cast(focusStrategy_)); } - void Unmarshalling(Parcel &parcel) + static AudioZoneContext *Unmarshalling(Parcel &parcel) { - focusStrategy_ = static_cast(parcel.ReadInt32()); + auto info = new AudioZoneContext(); + if (info == nullptr) { + return nullptr; + } + + info->focusStrategy_ = static_cast(parcel.ReadInt32()); + return info; } }; @@ -93,7 +99,7 @@ public: return true; } - void Unmarshalling(Parcel &parcel) + void UnmarshallingSelf(Parcel &parcel) { zoneId_ = parcel.ReadInt32(); name_ = parcel.ReadString(); @@ -105,29 +111,28 @@ public: } for (size_t i = 0; i < size; i++) { - std::shared_ptr device = std::make_shared(); + std::shared_ptr device(AudioDeviceDescriptor::Unmarshalling(parcel)); if (device == nullptr) { devices_.clear(); return; } - device->UnmarshallingToDeviceDescriptor(parcel); devices_.emplace_back(device); } } - static std::shared_ptr UnmarshallingPtr(Parcel &parcel) + static AudioZoneDescriptor *Unmarshalling(Parcel &parcel) { - std::shared_ptr desc = std::make_shared(); + auto desc = new AudioZoneDescriptor(); if (desc == nullptr) { return nullptr; } - desc->Unmarshalling(parcel); + desc->UnmarshallingSelf(parcel); return desc; } }; -struct AudioZoneStream { +struct AudioZoneStream : public Parcelable { StreamUsage streamUsage = STREAM_USAGE_INVALID; SourceType sourceType = SOURCE_TYPE_INVALID; bool isPlay = true; @@ -146,18 +151,24 @@ struct AudioZoneStream { return streamUsage > value.streamUsage || (streamUsage == value.streamUsage && sourceType > value.sourceType); } - bool Marshalling(Parcel &parcel) const + bool Marshalling(Parcel &parcel) const override { return parcel.WriteInt32(static_cast(streamUsage)) && parcel.WriteInt32(static_cast(sourceType)) && parcel.WriteBool(isPlay); } - void Unmarshalling(Parcel &parcel) + static AudioZoneStream *Unmarshalling(Parcel &parcel) { - streamUsage = static_cast(parcel.ReadInt32()); - sourceType = static_cast(parcel.ReadInt32()); - isPlay = parcel.ReadBool(); + auto stream = new AudioZoneStream(); + if (stream == nullptr) { + return nullptr; + } + + stream->streamUsage = static_cast(parcel.ReadInt32()); + stream->sourceType = static_cast(parcel.ReadInt32()); + stream->isPlay = parcel.ReadBool(); + return stream; } }; } // namespace AudioStandard diff --git a/frameworks/native/audiopolicy/test/unittest/policy_test/BUILD.gn b/frameworks/native/audiopolicy/test/unittest/policy_test/BUILD.gn index 14c2149e78..738f29d840 100644 --- a/frameworks/native/audiopolicy/test/unittest/policy_test/BUILD.gn +++ b/frameworks/native/audiopolicy/test/unittest/policy_test/BUILD.gn @@ -62,6 +62,7 @@ ohos_unittest("audio_policy_unit_test") { } deps = [ + "${audio_framework_root}/services/audio_service/idl:audio_framework_interface", "../../../../../../frameworks/native/audioutils:audio_utils", "../../../../../../services/audio_policy:audio_policy_client_static", "../../../../../../services/audio_policy:audio_policy_service_static", diff --git a/frameworks/native/audiopolicy/test/unittest/policy_test/src/audio_policy_ext_unit_test.cpp b/frameworks/native/audiopolicy/test/unittest/policy_test/src/audio_policy_ext_unit_test.cpp index a325d5068e..fcafc2616f 100644 --- a/frameworks/native/audiopolicy/test/unittest/policy_test/src/audio_policy_ext_unit_test.cpp +++ b/frameworks/native/audiopolicy/test/unittest/policy_test/src/audio_policy_ext_unit_test.cpp @@ -20,12 +20,12 @@ #include "audio_errors.h" #include "audio_info.h" #include "parcel.h" -#include "audio_policy_client.h" +#include "iaudio_policy_client.h" #include "audio_policy_unit_test.h" #include "audio_system_manager.h" #include "iservice_registry.h" #include "system_ability_definition.h" -#include "audio_client_tracker_callback_stub.h" +#include "standard_client_tracker_stub.h" #include "audio_policy_client_stub_impl.h" #include "audio_adapter_manager.h" #include "audio_policy_manager.h" diff --git a/frameworks/native/audiopolicy/test/unittest/policy_test/src/audio_policy_unit_test.cpp b/frameworks/native/audiopolicy/test/unittest/policy_test/src/audio_policy_unit_test.cpp index 32019a8bed..684747e8ad 100644 --- a/frameworks/native/audiopolicy/test/unittest/policy_test/src/audio_policy_unit_test.cpp +++ b/frameworks/native/audiopolicy/test/unittest/policy_test/src/audio_policy_unit_test.cpp @@ -20,12 +20,12 @@ #include "audio_errors.h" #include "audio_info.h" #include "parcel.h" -#include "audio_policy_client.h" +#include "iaudio_policy_client.h" #include "audio_policy_unit_test.h" #include "audio_system_manager.h" #include "iservice_registry.h" #include "system_ability_definition.h" -#include "audio_client_tracker_callback_stub.h" +#include "standard_client_tracker_stub.h" #include "audio_policy_client_stub_impl.h" #include "audio_adapter_manager.h" @@ -645,110 +645,6 @@ HWTEST(AudioPolicyUnitTest, Audio_Policy_Manager_GetCurrentCapturerChangeInfos_0 EXPECT_EQ(SUCCESS, ret); } -/** - * @tc.name : Test Audio_Capturer_State_Change_001 via legal state - * @tc.number: Audio_Capturer_State_Change_001 - * @tc.desc : Test AudioCapturerStateChangeListenerStub interface. Returns invalid. - */ -HWTEST(AudioPolicyUnitTest, Audio_Capturer_State_Change_001, TestSize.Level1) -{ - std::shared_ptr capturerStub = - std::make_shared(); - - vector> audioCapturerChangeInfos; - capturerStub->OnCapturerStateChange(audioCapturerChangeInfos); - - std::shared_ptr callback = - std::make_shared(); - capturerStub->AddCapturerStateChangeCallback(callback); - - uint32_t code = static_cast(AudioPolicyClientCode::ON_CAPTURERSTATE_CHANGE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int ret = capturerStub->OnRemoteRequest(code, data, reply, option); - EXPECT_LE(ret, 0); -} - -/** - * @tc.name : Test Audio_Renderer_State_Change_001 via legal state - * @tc.number: Audio_Renderer_State_Change_001 - * @tc.desc : Test AudioRendererStateChangeListenerStub interface. Returns success. - */ -HWTEST(AudioPolicyUnitTest, Audio_Renderer_State_Change_001, TestSize.Level1) -{ - std::shared_ptr rendererStub = - std::make_shared(); - - vector> audioRendererChangeInfos; - rendererStub->OnRendererStateChange(audioRendererChangeInfos); - - std::shared_ptr callback = - std::make_shared(); - rendererStub->AddRendererStateChangeCallback(callback); - - uint32_t code = static_cast(AudioPolicyClientCode::ON_RENDERERSTATE_CHANGE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int ret = rendererStub->OnRemoteRequest(code, data, reply, option); - EXPECT_LE(ret, 0); -} - -/** - * @tc.name : Test Audio_Ringermode_Update_Listener_001 via legal state - * @tc.number: Audio_Ringermode_Update_Listener_001 - * @tc.desc : Test AudioRingerModeUpdateListenerStub interface. Returns success. - */ -HWTEST(AudioPolicyUnitTest, Audio_Ringermode_Update_Listener_001, TestSize.Level1) -{ - std::shared_ptr ringermodeStub = - std::make_shared(); - std::shared_ptr callback = std::make_shared(); - AudioRingerMode ringerMode = AudioRingerMode::RINGER_MODE_SILENT; - - ringermodeStub->OnRingerModeUpdated(ringerMode); - - ringermodeStub->AddRingerModeCallback(callback); - - ringermodeStub->OnRingerModeUpdated(ringerMode); - - uint32_t code = static_cast(AudioPolicyClientCode::ON_RINGERMODE_UPDATE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int ret = ringermodeStub->OnRemoteRequest(code, data, reply, option); - EXPECT_LE(ret, 0); -} - -/** - * @tc.name : Test Audio_Rounting_Manager_Listener_001 via legal state - * @tc.number: Audio_Rounting_Manager_Listener_001 - * @tc.desc : Test AudioRoutingManagerListenerStub interface. Returns success. - */ -HWTEST(AudioPolicyUnitTest, Audio_Rounting_Manager_Listener_001, TestSize.Level1) -{ - std::shared_ptr audioPolicyClientStubImpl = - std::make_shared(); - std::shared_ptr callback = - std::make_shared(); - MicStateChangeEvent micStateChangeEvent; - micStateChangeEvent.mute = true; - - audioPolicyClientStubImpl->OnMicStateUpdated(micStateChangeEvent); - - audioPolicyClientStubImpl->AddMicStateChangeCallback(callback); - - audioPolicyClientStubImpl->OnMicStateUpdated(micStateChangeEvent); - - uint32_t code = static_cast(AudioPolicyClientCode::ON_MIC_STATE_UPDATED); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int ret = audioPolicyClientStubImpl->OnRemoteRequest(code, data, reply, option); - EXPECT_LE(ret, 0); -} - /** * @tc.name : Test Audio_Volume_Group_Info_001 via legal state * @tc.number: Audio_Volume_Group_Info_001 @@ -770,40 +666,6 @@ HWTEST(AudioPolicyUnitTest, Audio_Volume_Group_Info_001, TestSize.Level1) EXPECT_EQ(true, ret); } -/** - * @tc.name : Test Audio_Client_Tracker_Callback_Stub_001 via legal state - * @tc.number: Audio_Client_Tracker_Callback_Stub_001 - * @tc.desc : Test AudioClientTrackerCallbackStub interface. Returns success. - */ -HWTEST(AudioPolicyUnitTest, Audio_Client_Tracker_Callback_Stub_001, TestSize.Level1) -{ - std::shared_ptr audioClientTrackerCallbackStub = - std::make_shared(); - - StreamSetStateEventInternal streamSetStateEventInternal = {}; - streamSetStateEventInternal.streamUsage = STREAM_USAGE_MUSIC; - std::weak_ptr callback = std::make_shared(); - - float volume = 0.5; - audioClientTrackerCallbackStub->SetLowPowerVolumeImpl(volume); - audioClientTrackerCallbackStub->GetLowPowerVolumeImpl(volume); - audioClientTrackerCallbackStub->GetSingleStreamVolumeImpl(volume); - - streamSetStateEventInternal.streamSetState= StreamSetState::STREAM_RESUME; - audioClientTrackerCallbackStub->ResumeStreamImpl(streamSetStateEventInternal); - - streamSetStateEventInternal.streamSetState= StreamSetState::STREAM_PAUSE; - audioClientTrackerCallbackStub->PausedStreamImpl(streamSetStateEventInternal); - - audioClientTrackerCallbackStub->SetClientTrackerCallback(callback); - - streamSetStateEventInternal.streamSetState= StreamSetState::STREAM_RESUME; - audioClientTrackerCallbackStub->ResumeStreamImpl(streamSetStateEventInternal); - - streamSetStateEventInternal.streamSetState= StreamSetState::STREAM_PAUSE; - audioClientTrackerCallbackStub->PausedStreamImpl(streamSetStateEventInternal); -} - /** * @tc.name : Test Audio_Policy_SetSystemSoundUri_001 * @tc.number: Audio_Policy_SetSystemSoundUri_001 diff --git a/frameworks/native/audiorenderer/test/benchmark/BUILD.gn b/frameworks/native/audiorenderer/test/benchmark/BUILD.gn index 364083841f..8575b6db4a 100644 --- a/frameworks/native/audiorenderer/test/benchmark/BUILD.gn +++ b/frameworks/native/audiorenderer/test/benchmark/BUILD.gn @@ -12,6 +12,7 @@ # limitations under the License. import("//build/test.gni") +import("//foundation/multimedia/audio_framework/config.gni") module_output_path = "audio_framework/audio_framework_route/audio_renderer" @@ -24,6 +25,7 @@ ohos_benchmarktest("BenchmarkAudioRendererTest") { ] sources = [ "benchmark_audiorenderer_test.cpp" ] deps = [ "../../../audiorenderer:audio_renderer" ] + external_deps = [ "c_utils:utils" ] resource_config_file = "../../../../../test/resource/audio_renderer/ohos_test.xml" } diff --git a/frameworks/native/audiorenderer/test/multithreadtest/BUILD.gn b/frameworks/native/audiorenderer/test/multithreadtest/BUILD.gn index d18160c2d5..da834bb13f 100644 --- a/frameworks/native/audiorenderer/test/multithreadtest/BUILD.gn +++ b/frameworks/native/audiorenderer/test/multithreadtest/BUILD.gn @@ -12,6 +12,7 @@ # limitations under the License. import("//build/test.gni") +import("//foundation/multimedia/audio_framework/config.gni") module_output_path = "audio_framework/audio_framework_route/audio_renderer_multitest" @@ -37,12 +38,14 @@ ohos_unittest("audio_renderer_multi_test") { deps = [ "../../../../../services/audio_policy:audio_policy_client", "../../../../../services/audio_service:audio_client", + "../../../../../services/audio_service:audio_common", "../../../audiorenderer:audio_renderer", ] external_deps = [ "c_utils:utils", "hilog:libhilog", + "ipc:ipc_single", "pulseaudio:pulse", ] diff --git a/frameworks/native/audiorenderer/test/unittest/renderer_test/BUILD.gn b/frameworks/native/audiorenderer/test/unittest/renderer_test/BUILD.gn index aaeebf7004..6b1ee773ca 100644 --- a/frameworks/native/audiorenderer/test/unittest/renderer_test/BUILD.gn +++ b/frameworks/native/audiorenderer/test/unittest/renderer_test/BUILD.gn @@ -38,11 +38,11 @@ ohos_unittest("audio_renderer_unit_test") { "-fno-access-control", ] - sources = [ - "src/audio_renderer_unit_test.cpp", + sources = [ "src/audio_renderer_getter_unit_test.cpp", - "src/audio_renderer_setter_unit_test.cpp" - ] + "src/audio_renderer_setter_unit_test.cpp", + "src/audio_renderer_unit_test.cpp", + ] deps = [ "../../../../../../services/audio_policy:audio_policy_client", @@ -86,6 +86,7 @@ ohos_unittest("audio_fast_renderer_unit_test") { sources = [ "src/audio_fast_renderer_unit_test.cpp" ] deps = [ + "${audio_framework_root}/services/audio_service/idl:audio_framework_interface", "../../../../../../services/audio_policy:audio_policy_client", "../../../../../../services/audio_service:audio_client", "../../../../audiorenderer:audio_renderer", diff --git a/frameworks/native/audiorenderer/test/unittest/renderer_test/src/renderer_in_client_unit_test.cpp b/frameworks/native/audiorenderer/test/unittest/renderer_test/src/renderer_in_client_unit_test.cpp index 447a4c40ec..808a36e017 100644 --- a/frameworks/native/audiorenderer/test/unittest/renderer_test/src/renderer_in_client_unit_test.cpp +++ b/frameworks/native/audiorenderer/test/unittest/renderer_test/src/renderer_in_client_unit_test.cpp @@ -20,6 +20,7 @@ #include "renderer_in_client_private.h" #include "i_stream_listener.h" + using namespace testing::ext; using namespace testing; @@ -33,95 +34,98 @@ public: void TearDown(); }; -class IpcStreamTest : public IpcStream { +class IpcStreamTest : public IIpcStream { public: virtual ~IpcStreamTest() = default; - virtual int32_t RegisterStreamListener(sptr object) { return 0; } + virtual int32_t RegisterStreamListener(const sptr &object) override { return 0; } - virtual int32_t ResolveBuffer(std::shared_ptr &buffer) { return 0; } + virtual int32_t ResolveBuffer(std::shared_ptr &buffer) override { return 0; } - virtual int32_t UpdatePosition() { return 0; } + virtual int32_t UpdatePosition() override { return 0; } - virtual int32_t GetAudioSessionID(uint32_t &sessionId) { return 0; } + virtual int32_t GetAudioSessionID(uint32_t &sessionId) override { return 0; } - virtual int32_t Start() { return 0; } + virtual int32_t Start() override { return 0; } - virtual int32_t Pause() { return 0; } + virtual int32_t Pause() override { return 0; } - virtual int32_t Stop() { return 0; } + virtual int32_t Stop() override { return 0; } - virtual int32_t Release(bool isSwitchStream = false) { return 0; } + virtual int32_t Release(bool isSwitchStream) override { return 0; } - virtual int32_t Flush() { return 0; } + virtual int32_t Flush() override { return 0; } - virtual int32_t Drain(bool stopFlag = false) { return 0; } + virtual int32_t Drain(bool stopFlag) override { return 0; } - virtual int32_t UpdatePlaybackCaptureConfig(const AudioPlaybackCaptureConfig &config) { return 0; } + virtual int32_t UpdatePlaybackCaptureConfig(const AudioPlaybackCaptureConfig &config) override { return 0; } - virtual int32_t GetAudioTime(uint64_t &framePos, uint64_t ×tamp) { return 0; } + virtual int32_t GetAudioTime(uint64_t &framePos, uint64_t ×tamp) override { return 0; } - virtual int32_t GetAudioPosition(uint64_t &framePos, uint64_t ×tamp, uint64_t &latency, int32_t base) + virtual int32_t GetAudioPosition(uint64_t &framePos, uint64_t ×tamp, uint64_t &latency, int32_t base) override { return 0; } - virtual int32_t GetLatency(uint64_t &latency) { return 0; } + virtual int32_t GetLatency(uint64_t &latency) override { return 0; } - virtual int32_t SetRate(int32_t rate) { return 0; } // SetRenderRate + virtual int32_t SetRate(int32_t rate) override { return 0; } // SetRenderRate - virtual int32_t GetRate(int32_t &rate) { return 0; } // SetRenderRate + virtual int32_t GetRate(int32_t &rate) override { return 0; } // SetRenderRate - virtual int32_t SetLowPowerVolume(float volume) { return 0; } // renderer only + virtual int32_t SetLowPowerVolume(float volume) override { return 0; } // renderer only - virtual int32_t GetLowPowerVolume(float &volume) { return 0; } // renderer only + virtual int32_t GetLowPowerVolume(float &volume) override { return 0; } // renderer only - virtual int32_t SetAudioEffectMode(int32_t effectMode) { return 0; } // renderer only + virtual int32_t SetAudioEffectMode(int32_t effectMode) override { return 0; } // renderer only - virtual int32_t GetAudioEffectMode(int32_t &effectMode) { return 0; } // renderer only + virtual int32_t GetAudioEffectMode(int32_t &effectMode) override { return 0; } // renderer only - virtual int32_t SetPrivacyType(int32_t privacyType) { return 0; } // renderer only + virtual int32_t SetPrivacyType(int32_t privacyType) override { return 0; } // renderer only - virtual int32_t GetPrivacyType(int32_t &privacyType) { return 0; } // renderer only + virtual int32_t GetPrivacyType(int32_t &privacyType) override { return 0; } // renderer only - virtual int32_t SetOffloadMode(int32_t state, bool isAppBack) { return 0; } // renderer only + virtual int32_t SetOffloadMode(int32_t state, bool isAppBack) override { return 0; } // renderer only - virtual int32_t UnsetOffloadMode() { return 0; } // renderer only + virtual int32_t UnsetOffloadMode() override { return 0; } // renderer only virtual int32_t GetOffloadApproximatelyCacheTime(uint64_t ×tamp, uint64_t &paWriteIndex, - uint64_t &cacheTimeDsp, uint64_t &cacheTimePa) { return 0; } // renderer only + uint64_t &cacheTimeDsp, uint64_t &cacheTimePa) override { return 0; } // renderer only - virtual int32_t UpdateSpatializationState(bool spatializationEnabled, bool headTrackingEnabled) { return 0; } + virtual int32_t UpdateSpatializationState(bool spatializationEnabled, bool headTrackingEnabled) override + { + return 0; + } - virtual int32_t GetStreamManagerType() { return 0; } + virtual int32_t GetStreamManagerType() override { return 0; } - virtual int32_t SetSilentModeAndMixWithOthers(bool on) { return 0; } + virtual int32_t SetSilentModeAndMixWithOthers(bool on) override { return 0; } - virtual int32_t SetClientVolume() { return 0; } + virtual int32_t SetClientVolume() override { return 0; } - virtual int32_t SetLoudnessGain(float loudnessGain) { return 0; } + virtual int32_t SetLoudnessGain(float loudnessGain) override { return 0; } - virtual int32_t SetMute(bool isMute) { return (isMute ? SUCCESS : ERROR); } + virtual int32_t SetMute(bool isMute) override { return (isMute ? SUCCESS : ERROR); } - virtual int32_t SetDuckFactor(float duckFactor) { return 0; } + virtual int32_t SetDuckFactor(float duckFactor) override { return 0; } - virtual int32_t RegisterThreadPriority(pid_t tid, const std::string &bundleName, BoostTriggerMethod method) + virtual int32_t RegisterThreadPriority(pid_t tid, const std::string &bundleName, uint32_t method) override { return 0; } - virtual int32_t SetDefaultOutputDevice(const DeviceType defaultOuputDevice) { return 0; } + virtual int32_t SetDefaultOutputDevice(const int32_t defaultOuputDevice) override { return 0; } - virtual int32_t SetSourceDuration(int64_t duration) { return 0; } + virtual int32_t SetSourceDuration(int64_t duration) override { return 0; } - virtual int32_t SetOffloadDataCallbackState(int32_t state) { return 0; } + virtual int32_t SetOffloadDataCallbackState(int32_t state) override { return 0; } - virtual sptr AsObject() { return nullptr; } + virtual sptr AsObject() override { return nullptr; } virtual int32_t ResolveBufferBaseAndGetServerSpanSize(std::shared_ptr &buffer, - uint32_t &spanSizeInFrame, uint64_t &engineTotalSizeInFrame) { return SUCCESS; } - - virtual int32_t SetAudioHapticsSyncId(const int32_t &audioHapticsSyncId) { return 0; } + uint32_t &spanSizeInFrame, uint64_t &engineTotalSizeInFrame) override { return SUCCESS; } + + virtual int32_t SetAudioHapticsSyncId(int32_t audioHapticsSyncId) override { return 0; } }; class AudioCapturerReadCallbackTest : public AudioCapturerReadCallback { diff --git a/frameworks/native/audioutils/include/audio_utils.h b/frameworks/native/audioutils/include/audio_utils.h index 2452cfce8d..33eeb42cbb 100644 --- a/frameworks/native/audioutils/include/audio_utils.h +++ b/frameworks/native/audioutils/include/audio_utils.h @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -55,6 +56,9 @@ const uint32_t AUDIO_ID = 1041; // Ringer or alarmer dual tone const size_t AUDIO_CONCURRENT_ACTIVE_DEVICES_LIMIT = 2; +constexpr int32_t AUDIO_EXTRA_PARAMETERS_COUNT_UPPER_LIMIT = 40; +constexpr int32_t AUDIO_EFFECT_CHAIN_COUNT_UPPER_LIMIT = 32; + /* Define AudioXcollie timeout flag, consistent with xcollie_define.h in hiviewdfx */ static constexpr unsigned int AUDIO_XCOLLIE_FLAG_DEFAULT = (~0); // do all callback function static constexpr unsigned int AUDIO_XCOLLIE_FLAG_NOOP = (0); // do nothing but the caller defined function @@ -572,6 +576,12 @@ uint32_t GenerateUniqueID(AudioHdiUniqueIDBase base, uint32_t offset); void CloseFd(int fd); int32_t CheckSupportedParams(const AudioStreamInfo &info); + +std::vector> ToIpcInterrupts( + const std::list> &from); + +std::list> FromIpcInterrupts( + const std::vector> &from); } // namespace AudioStandard } // namespace OHOS #endif // AUDIO_UTILS_H diff --git a/frameworks/native/audioutils/src/audio_utils.cpp b/frameworks/native/audioutils/src/audio_utils.cpp index 79d592ae3a..c7723cd68b 100644 --- a/frameworks/native/audioutils/src/audio_utils.cpp +++ b/frameworks/native/audioutils/src/audio_utils.cpp @@ -2069,6 +2069,30 @@ int32_t CheckSupportedParams(const AudioStreamInfo &info) ERR_INVALID_PARAM, "channelLayout not supported"); return SUCCESS; } + +std::vector> ToIpcInterrupts( + const std::list> &from) +{ + std::vector> ipcInterrupts; + for (const auto &pair : from) { + std::map mapEntry; + mapEntry[pair.first] = static_cast(pair.second); + ipcInterrupts.push_back(mapEntry); + } + return ipcInterrupts; +} + +std::list> FromIpcInterrupts( + const std::vector> &from) +{ + std::list> interrupts; + for (const auto &map : from) { + for (const auto &entry : map) { + interrupts.push_back(std::make_pair(entry.first, static_cast(entry.second))); + } + } + return interrupts; +} } // namespace AudioStandard } // namespace OHOS diff --git a/frameworks/native/hdiadapter_new/include/common/hdi_adapter_type.h b/frameworks/native/hdiadapter_new/include/common/hdi_adapter_type.h index 4b22ac2a03..0605898ff7 100644 --- a/frameworks/native/hdiadapter_new/include/common/hdi_adapter_type.h +++ b/frameworks/native/hdiadapter_new/include/common/hdi_adapter_type.h @@ -23,23 +23,63 @@ namespace OHOS { namespace AudioStandard { // if attr struct change, please check ipc serialize and deserialize code -typedef struct IAudioSinkAttr { +typedef struct IAudioSinkAttr : public Parcelable { std::string adapterName = ""; uint32_t openMicSpeaker = 0; AudioSampleFormat format = AudioSampleFormat::INVALID_WIDTH; uint32_t sampleRate = 0; uint32_t channel = 0; float volume = 0.0f; - const char *filePath = nullptr; - const char *deviceNetworkId = nullptr; + std::string filePath = ""; + std::string deviceNetworkId = ""; int32_t deviceType = 0; uint64_t channelLayout = 0; int32_t audioStreamFlag = 0; std::string address; - const char *aux = nullptr; + std::string aux = ""; + + bool Marshalling(Parcel &parcel) const override + { + return parcel.WriteString(adapterName) && + parcel.WriteUint32(openMicSpeaker) && + parcel.WriteUint8(static_cast(format)) && + parcel.WriteUint32(sampleRate) && + parcel.WriteUint32(channel) && + parcel.WriteFloat(volume) && + parcel.WriteString(filePath) && + parcel.WriteString(deviceNetworkId) && + parcel.WriteInt32(deviceType) && + parcel.WriteUint64(channelLayout) && + parcel.WriteInt32(audioStreamFlag) && + parcel.WriteString(address) && + parcel.WriteString(aux); + } + + static IAudioSinkAttr *Unmarshalling(Parcel &parcel) + { + auto attr = new IAudioSinkAttr(); + if (attr == nullptr) { + return nullptr; + } + + attr->adapterName = parcel.ReadString(); + attr->openMicSpeaker = parcel.ReadUint32(); + attr->format = static_cast(parcel.ReadUint8()); + attr->sampleRate = parcel.ReadUint32(); + attr->channel = parcel.ReadUint32(); + attr->volume = parcel.ReadFloat(); + attr->filePath = parcel.ReadString(); + attr->deviceNetworkId = parcel.ReadString(); + attr->deviceType = parcel.ReadInt32(); + attr->channelLayout = parcel.ReadUint64(); + attr->audioStreamFlag = parcel.ReadInt32(); + attr->address = parcel.ReadString(); + attr->aux = parcel.ReadString(); + return attr; + } } IAudioSinkAttr; -typedef struct IAudioSourceAttr { +typedef struct IAudioSourceAttr : public Parcelable { std::string adapterName = ""; uint32_t openMicSpeaker = 0; AudioSampleFormat format = AudioSampleFormat::INVALID_WIDTH; @@ -48,8 +88,8 @@ typedef struct IAudioSourceAttr { float volume = 0.0f; uint32_t bufferSize = 0; bool isBigEndian = false; - const char *filePath = nullptr; - const char *deviceNetworkId = nullptr; + std::string filePath = ""; + std::string deviceNetworkId = ""; int32_t deviceType = 0; int32_t sourceType = 0; uint64_t channelLayout = 0; @@ -58,6 +98,56 @@ typedef struct IAudioSourceAttr { AudioSampleFormat formatEc = AudioSampleFormat::INVALID_WIDTH; uint32_t sampleRateEc = 0; uint32_t channelEc = 0; + + bool Marshalling(Parcel &parcel) const override + { + return parcel.WriteString(adapterName) && + parcel.WriteUint32(openMicSpeaker) && + parcel.WriteUint8(static_cast(format)) && + parcel.WriteUint32(sampleRate) && + parcel.WriteUint32(channel) && + parcel.WriteFloat(volume) && + parcel.WriteUint32(bufferSize) && + parcel.WriteBool(isBigEndian) && + parcel.WriteString(filePath) && + parcel.WriteString(deviceNetworkId) && + parcel.WriteInt32(deviceType) && + parcel.WriteInt32(sourceType) && + parcel.WriteUint64(channelLayout) && + parcel.WriteInt32(audioStreamFlag) && + parcel.WriteBool(hasEcConfig) && + parcel.WriteUint8(static_cast(formatEc)) && + parcel.WriteUint32(sampleRateEc) && + parcel.WriteUint32(channelEc); + } + + static IAudioSourceAttr *Unmarshalling(Parcel &parcel) + { + auto attr = new IAudioSourceAttr(); + if (attr == nullptr) { + return nullptr; + } + + attr->adapterName = parcel.ReadString(); + attr->openMicSpeaker = parcel.ReadUint32(); + attr->format = static_cast(parcel.ReadUint8()); + attr->sampleRate = parcel.ReadUint32(); + attr->channel = parcel.ReadUint32(); + attr->volume = parcel.ReadFloat(); + attr->bufferSize = parcel.ReadUint32(); + attr->isBigEndian = parcel.ReadBool(); + attr->filePath = parcel.ReadString(); + attr->deviceNetworkId = parcel.ReadString(); + attr->deviceType = parcel.ReadInt32(); + attr->sourceType = parcel.ReadInt32(); + attr->channelLayout = parcel.ReadUint64(); + attr->audioStreamFlag = parcel.ReadInt32(); + attr->hasEcConfig = parcel.ReadBool(); + attr->formatEc = static_cast(parcel.ReadUint8()); + attr->sampleRateEc = parcel.ReadUint32(); + attr->channelEc = parcel.ReadUint32(); + return attr; + } } IAudioSourceAttr; typedef struct FrameDesc { diff --git a/frameworks/native/hdiadapter_new/sink/file_audio_render_sink.cpp b/frameworks/native/hdiadapter_new/sink/file_audio_render_sink.cpp index e0a80c071c..89d99115d3 100644 --- a/frameworks/native/hdiadapter_new/sink/file_audio_render_sink.cpp +++ b/frameworks/native/hdiadapter_new/sink/file_audio_render_sink.cpp @@ -30,9 +30,6 @@ FileAudioRenderSink::~FileAudioRenderSink() int32_t FileAudioRenderSink::Init(const IAudioSinkAttr &attr) { - if (attr.filePath == nullptr) { - return ERROR; - } filePath_.assign(attr.filePath); return SUCCESS; } diff --git a/frameworks/native/hdiadapter_new/sink/remote_audio_render_sink.cpp b/frameworks/native/hdiadapter_new/sink/remote_audio_render_sink.cpp index e72f6df398..84ea9e0294 100644 --- a/frameworks/native/hdiadapter_new/sink/remote_audio_render_sink.cpp +++ b/frameworks/native/hdiadapter_new/sink/remote_audio_render_sink.cpp @@ -61,7 +61,7 @@ int32_t RemoteAudioRenderSink::Init(const IAudioSinkAttr &attr) AUDIO_INFO_LOG("in"); attr_ = attr; std::vector splitStreamVector; - InitSplitStream(attr_.aux, splitStreamVector); + InitSplitStream(attr_.aux.c_str(), splitStreamVector); for (auto &splitStream : splitStreamVector) { audioRenderWrapperMap_[splitStream] = {}; } diff --git a/frameworks/native/hdiadapter_new/source/file_audio_capture_source.cpp b/frameworks/native/hdiadapter_new/source/file_audio_capture_source.cpp index 8933116295..5d288143ec 100644 --- a/frameworks/native/hdiadapter_new/source/file_audio_capture_source.cpp +++ b/frameworks/native/hdiadapter_new/source/file_audio_capture_source.cpp @@ -30,9 +30,6 @@ FileAudioCaptureSource::~FileAudioCaptureSource() int32_t FileAudioCaptureSource::Init(const IAudioSourceAttr &attr) { - if (attr.filePath == nullptr) { - return ERROR; - } std::string filePath(attr.filePath); std::string dirPath; std::string fileName; diff --git a/frameworks/native/offlineaudioeffect/BUILD.gn b/frameworks/native/offlineaudioeffect/BUILD.gn index 073925f040..c67f04fad3 100644 --- a/frameworks/native/offlineaudioeffect/BUILD.gn +++ b/frameworks/native/offlineaudioeffect/BUILD.gn @@ -61,6 +61,7 @@ if (!audio_framework_feature_offline_effect) { ] public_configs = [ ":offline_audio_effect_config" ] + configs = [ "${audio_framework_root}/services/audio_service/idl:audio_service_sa_idl_config" ] version_script = "../../../audio_framework.versionscript" innerapi_tags = [ "platformsdk" ] diff --git a/frameworks/native/offlineaudioeffect/test/unittest/offline_audio_effect_manager_unit_test.cpp b/frameworks/native/offlineaudioeffect/test/unittest/offline_audio_effect_manager_unit_test.cpp index 3779379d56..cf2f171de4 100644 --- a/frameworks/native/offlineaudioeffect/test/unittest/offline_audio_effect_manager_unit_test.cpp +++ b/frameworks/native/offlineaudioeffect/test/unittest/offline_audio_effect_manager_unit_test.cpp @@ -30,7 +30,7 @@ namespace AudioStandard { namespace { const std::string INVALID_EFFECT_NAME = "0d000721"; - constexpr AudioStreamInfo NORMAL_STREAM_INFO( + AudioStreamInfo NORMAL_STREAM_INFO( AudioSamplingRate::SAMPLE_RATE_48000, AudioEncodingType::ENCODING_PCM, AudioSampleFormat::SAMPLE_S16LE, AudioChannel::STEREO, AudioChannelLayout::CH_LAYOUT_STEREO); } diff --git a/frameworks/native/ohaudio/test/unittest/oh_audio_capture_test/BUILD.gn b/frameworks/native/ohaudio/test/unittest/oh_audio_capture_test/BUILD.gn index 77350e82e7..f47d163e33 100644 --- a/frameworks/native/ohaudio/test/unittest/oh_audio_capture_test/BUILD.gn +++ b/frameworks/native/ohaudio/test/unittest/oh_audio_capture_test/BUILD.gn @@ -64,5 +64,10 @@ ohos_unittest("audio_oh_capture_unit_test") { "../../../../ohaudio:ohaudio", ] - external_deps = [ "hilog:libhilog" ] + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "init:libbegetutil", + "ipc:ipc_single", + ] } diff --git a/frameworks/native/ohaudio/test/unittest/oh_audio_manager_test/BUILD.gn b/frameworks/native/ohaudio/test/unittest/oh_audio_manager_test/BUILD.gn index 6efc0f5876..2fc2154a34 100644 --- a/frameworks/native/ohaudio/test/unittest/oh_audio_manager_test/BUILD.gn +++ b/frameworks/native/ohaudio/test/unittest/oh_audio_manager_test/BUILD.gn @@ -15,7 +15,6 @@ import("//build/test.gni") import("../../../../../../config.gni") module_output_path = "audio_framework/audio_framework_route/audio_ndk" -audio_framework_root = "//foundation/multimedia/audio_framework" config("audio_manager_config") { include_dirs = [ diff --git a/frameworks/native/ohaudio/test/unittest/oh_audio_volume_manager_test/BUILD.gn b/frameworks/native/ohaudio/test/unittest/oh_audio_volume_manager_test/BUILD.gn index 919ebb9146..f67346cfce 100644 --- a/frameworks/native/ohaudio/test/unittest/oh_audio_volume_manager_test/BUILD.gn +++ b/frameworks/native/ohaudio/test/unittest/oh_audio_volume_manager_test/BUILD.gn @@ -15,7 +15,6 @@ import("//build/test.gni") import("../../../../../../config.gni") module_output_path = "audio_framework/audio_framework_route/audio_ndk" -audio_framework_root = "//foundation/multimedia/audio_framework" config("audio_volume_manager_config") { include_dirs = [ @@ -52,5 +51,10 @@ ohos_unittest("audio_oh_volume_manager_unit_test") { deps = [ "${audio_framework_root}/frameworks/native/ohaudio:ohaudio" ] - external_deps = [ "hilog:libhilog" ] + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "init:libbegetutil", + "ipc:ipc_single", + ] } diff --git a/frameworks/native/pulseaudio/modules/hdi/hdi_adapter_intf/sink/sink_adapter.cpp b/frameworks/native/pulseaudio/modules/hdi/hdi_adapter_intf/sink/sink_adapter.cpp index 70709b594c..3544c0d8a3 100644 --- a/frameworks/native/pulseaudio/modules/hdi/hdi_adapter_intf/sink/sink_adapter.cpp +++ b/frameworks/native/pulseaudio/modules/hdi/hdi_adapter_intf/sink/sink_adapter.cpp @@ -84,18 +84,17 @@ int32_t SinkAdapterInit(struct SinkAdapter *adapter, const struct SinkAdapterAtt return SUCCESS; } - IAudioSinkAttr sinkAttr = { - .adapterName = attr->adapterName, - .openMicSpeaker = attr->openMicSpeaker, - .format = static_cast(attr->format), - .sampleRate = attr->sampleRate, - .channel = attr->channel, - .volume = attr->volume, - .deviceNetworkId = attr->deviceNetworkId, - .deviceType = attr->deviceType, - .channelLayout = attr->channelLayout, - .aux = attr->aux, - }; + IAudioSinkAttr sinkAttr = {}; + sinkAttr.adapterName = attr->adapterName; + sinkAttr.openMicSpeaker = attr->openMicSpeaker; + sinkAttr.format = static_cast(attr->format); + sinkAttr.sampleRate = attr->sampleRate; + sinkAttr.channel = attr->channel; + sinkAttr.volume = attr->volume; + sinkAttr.deviceNetworkId = attr->deviceNetworkId; + sinkAttr.deviceType = attr->deviceType; + sinkAttr.channelLayout = attr->channelLayout; + sinkAttr.aux = attr->aux; return sink->Init(sinkAttr); } diff --git a/frameworks/native/pulseaudio/modules/hdi/hdi_adapter_intf/source/source_adapter.cpp b/frameworks/native/pulseaudio/modules/hdi/hdi_adapter_intf/source/source_adapter.cpp index ad8dc0fca1..3b75f7aae4 100644 --- a/frameworks/native/pulseaudio/modules/hdi/hdi_adapter_intf/source/source_adapter.cpp +++ b/frameworks/native/pulseaudio/modules/hdi/hdi_adapter_intf/source/source_adapter.cpp @@ -83,25 +83,24 @@ int32_t SourceAdapterInit(struct SourceAdapter *adapter, const struct SourceAdap return SUCCESS; } - IAudioSourceAttr sourceAttr = { - .adapterName = attr->adapterName, - .openMicSpeaker = attr->openMicSpeaker, - .format = static_cast(attr->format), - .sampleRate = attr->sampleRate, - .channel = attr->channel, - .volume = attr->volume, - .bufferSize = attr->bufferSize, - .isBigEndian = attr->isBigEndian, - .filePath = attr->filePath, - .deviceNetworkId = attr->deviceNetworkId, - .deviceType = attr->deviceType, - .sourceType = attr->sourceType, - .channelLayout = attr->channelLayout, - .hasEcConfig = attr->hasEcConfig, - .formatEc = static_cast(attr->formatEc), - .sampleRateEc = attr->sampleRateEc, - .channelEc = attr->channelEc, - }; + IAudioSourceAttr sourceAttr = {}; + sourceAttr.adapterName = attr->adapterName; + sourceAttr.openMicSpeaker = attr->openMicSpeaker; + sourceAttr.format = static_cast(attr->format); + sourceAttr.sampleRate = attr->sampleRate; + sourceAttr.channel = attr->channel; + sourceAttr.volume = attr->volume; + sourceAttr.bufferSize = attr->bufferSize; + sourceAttr.isBigEndian = attr->isBigEndian; + sourceAttr.filePath = attr->filePath; + sourceAttr.deviceNetworkId = attr->deviceNetworkId; + sourceAttr.deviceType = attr->deviceType; + sourceAttr.sourceType = attr->sourceType; + sourceAttr.channelLayout = attr->channelLayout; + sourceAttr.hasEcConfig = attr->hasEcConfig; + sourceAttr.formatEc = static_cast(attr->formatEc); + sourceAttr.sampleRateEc = attr->sampleRateEc; + sourceAttr.channelEc = attr->channelEc; return source->Init(sourceAttr); } diff --git a/frameworks/native/toneplayer/BUILD.gn b/frameworks/native/toneplayer/BUILD.gn index 00751d927c..b0315a5792 100644 --- a/frameworks/native/toneplayer/BUILD.gn +++ b/frameworks/native/toneplayer/BUILD.gn @@ -61,6 +61,7 @@ if (!audio_framework_feature_dtmf_tone) { defines = [ "FEATURE_DTMF_TONE" ] deps = [ + "${audio_framework_root}/services/audio_service:audio_common", "../../../services/audio_policy:audio_policy_client", "../audiorenderer:audio_renderer", "../audioutils:audio_utils", diff --git a/frameworks/native/toneplayer/test/unittest/BUILD.gn b/frameworks/native/toneplayer/test/unittest/BUILD.gn index e73bd18036..46868ed3d2 100644 --- a/frameworks/native/toneplayer/test/unittest/BUILD.gn +++ b/frameworks/native/toneplayer/test/unittest/BUILD.gn @@ -44,4 +44,11 @@ ohos_unittest("audio_toneplayer_unit_test") { "../../../toneplayer:audio_toneplayer", "./../../../../../frameworks/native/audiorenderer:audio_renderer", ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "init:libbegetutil", + "ipc:ipc_single", + ] } diff --git a/interfaces/inner_api/native/audiocommon/include/audio_device_descriptor.h b/interfaces/inner_api/native/audiocommon/include/audio_device_descriptor.h index 2802dd1d2f..add47bf448 100644 --- a/interfaces/inner_api/native/audiocommon/include/audio_device_descriptor.h +++ b/interfaces/inner_api/native/audiocommon/include/audio_device_descriptor.h @@ -42,6 +42,19 @@ public: DEVICE_INFO, }; + class ClientInfo { + public: + bool hasBTPermission_ = false; + bool hasSystemPermission_ = false; + int32_t apiVersion_ = 0; + + ClientInfo() = default; + ClientInfo(int32_t apiVersion) + : apiVersion_(apiVersion) {} + ClientInfo(bool hasBTPermission, bool hasSystemPermission, int32_t apiVersion) + : hasBTPermission_(hasBTPermission), hasSystemPermission_(hasSystemPermission), apiVersion_(apiVersion) {} + }; + AudioDeviceDescriptor(int32_t descriptorType = AUDIO_DEVICE_DESCRIPTOR); AudioDeviceDescriptor(DeviceType type, DeviceRole role); @@ -65,24 +78,9 @@ public: bool Marshalling(Parcel &parcel) const override; - bool Marshalling(Parcel &parcel, int32_t apiVersion) const; - - bool MarshallingToDeviceDescriptor(Parcel &parcel, int32_t apiVersion) const; - - bool MarshallingToDeviceInfo(Parcel &parcel) const; - - bool Marshalling(Parcel &parcel, bool hasBTPermission, bool hasSystemPermission, int32_t apiVersion) const; - - bool MarshallingToDeviceInfo(Parcel &parcel, bool hasBTPermission, bool hasSystemPermission, - int32_t apiVersion) const; - - void Unmarshalling(Parcel &parcel); + void UnmarshallingSelf(Parcel &parcel); - static std::shared_ptr UnmarshallingPtr(Parcel &parcel); - - void UnmarshallingToDeviceDescriptor(Parcel &parcel); - - void UnmarshallingToDeviceInfo(Parcel &parcel); + static AudioDeviceDescriptor *Unmarshalling(Parcel &parcel); void SetDeviceInfo(std::string deviceName, std::string macAddress); @@ -134,6 +132,16 @@ public: } }; + void SetClientInfo(std::shared_ptr clientInfo) const; +private: + static void FixApiCompatibility(int apiVersion, DeviceRole deviceRole, + DeviceType &deviceType, int32_t &deviceId, std::list &streamInfo); + + bool MarshallingInner(Parcel &parcel) const; + + bool MarshallingToDeviceInfo(Parcel &parcel, bool hasBTPermission, bool hasSystemPermission, + int32_t apiVersion) const; +public: DeviceType deviceType_ = DEVICE_TYPE_NONE; DeviceRole deviceRole_ = DEVICE_ROLE_NONE; int32_t deviceId_ = 0; @@ -166,6 +174,7 @@ public: bool hasPair_{false}; RouterType routerType_ = ROUTER_TYPE_NONE; bool isVrSupported_ = true; + mutable std::shared_ptr clientInfo_ = nullptr; private: bool IsOutput() diff --git a/interfaces/inner_api/native/audiocommon/include/audio_device_info.h b/interfaces/inner_api/native/audiocommon/include/audio_device_info.h index 5239ffde09..48e10eed5a 100644 --- a/interfaces/inner_api/native/audiocommon/include/audio_device_info.h +++ b/interfaces/inner_api/native/audiocommon/include/audio_device_info.h @@ -388,7 +388,7 @@ enum class AudioStreamDeviceChangeReason { OVERRODE = 3 }; -class AudioStreamDeviceChangeReasonExt { +class AudioStreamDeviceChangeReasonExt : public Parcelable { public: enum class ExtEnum { UNKNOWN = 0, @@ -417,6 +417,8 @@ public: return static_cast(reason_); } + AudioStreamDeviceChangeReasonExt() + : reason_(ExtEnum::UNKNOWN) {} AudioStreamDeviceChangeReasonExt(const AudioStreamDeviceChangeReason &reason) : reason_(static_cast(reason)) {} @@ -452,6 +454,21 @@ public: return reason_ == ExtEnum::SET_DEFAULT_OUTPUT_DEVICE; } + bool Marshalling(Parcel &parcel) const override + { + return parcel.WriteInt32(static_cast(reason_)); + } + + static AudioStreamDeviceChangeReasonExt *Unmarshalling(Parcel &parcel) + { + auto info = new AudioStreamDeviceChangeReasonExt(); + if (info == nullptr) { + return nullptr; + } + info->reason_ = static_cast(parcel.ReadInt32()); + return info; + } + private: ExtEnum reason_; }; diff --git a/interfaces/inner_api/native/audiocommon/include/audio_effect.h b/interfaces/inner_api/native/audiocommon/include/audio_effect.h index 3fac3d9ba3..37945d39b4 100644 --- a/interfaces/inner_api/native/audiocommon/include/audio_effect.h +++ b/interfaces/inner_api/native/audiocommon/include/audio_effect.h @@ -67,28 +67,144 @@ enum FoldState : uint32_t { FOLD_STATE_MIDDLE = 3, }; -struct AudioSpatialDeviceState { +struct AudioSpatialDeviceState : public Parcelable { std::string address; bool isSpatializationSupported; bool isHeadTrackingSupported; AudioSpatialDeviceType spatialDeviceType; + + AudioSpatialDeviceState() = default; + AudioSpatialDeviceState(const std::string &address, bool isSpatializationSupported, + bool isHeadTrackingSupported, AudioSpatialDeviceType spatialDeviceType) + : address(address), isSpatializationSupported(isSpatializationSupported), + isHeadTrackingSupported(isHeadTrackingSupported), spatialDeviceType(spatialDeviceType) + { + } + + bool Marshalling(Parcel &parcel) const override + { + return parcel.WriteString(address) && + parcel.WriteBool(isSpatializationSupported) && + parcel.WriteBool(isHeadTrackingSupported) && + parcel.WriteInt32(spatialDeviceType); + } + + static AudioSpatialDeviceState *Unmarshalling(Parcel &parcel) + { + auto deviceState = new AudioSpatialDeviceState(); + if (deviceState == nullptr) { + return nullptr; + } + deviceState->address = parcel.ReadString(); + deviceState->isSpatializationSupported = parcel.ReadBool(); + deviceState->isHeadTrackingSupported = parcel.ReadBool(); + deviceState->spatialDeviceType = static_cast(parcel.ReadInt32()); + return deviceState; + } }; -struct Library { +struct Library : public Parcelable { std::string name; std::string path; + + bool Marshalling(Parcel &parcel) const override + { + return parcel.WriteString(name) && parcel.WriteString(path); + } + + void UnmarshallingSelf(Parcel &parcel) + { + name = parcel.ReadString(); + path = parcel.ReadString(); + } + + static Library *Unmarshalling(Parcel &parcel) + { + auto library = new Library(); + if (library == nullptr) { + return nullptr; + } + library->UnmarshallingSelf(parcel); + return library; + } }; -struct Effect { +struct Effect : public Parcelable { std::string name; std::string libraryName; std::vector effectProperty; + + bool Marshalling(Parcel &parcel) const override + { + parcel.WriteString(name); + parcel.WriteString(libraryName); + int32_t size = static_cast(effectProperty.size()); + parcel.WriteInt32(size); + for (auto &property : effectProperty) { + parcel.WriteString(property); + } + return true; + } + + static Effect *Unmarshalling(Parcel &parcel) + { + auto effect = new Effect(); + if (effect == nullptr) { + return nullptr; + } + + effect->name = parcel.ReadString(); + effect->libraryName = parcel.ReadString(); + int32_t size = parcel.ReadInt32(); + for (int32_t i = 0; i < size; ++i) { + effect->effectProperty.push_back(parcel.ReadString()); + } + return effect; + } }; -struct EffectChain { +struct EffectChain : public Parcelable { std::string name; std::vector apply; std::string label = ""; + static constexpr int32_t AUDIO_EFFECT_COUNT_PER_CHAIN_UPPER_LIMIT = 16; + + EffectChain() = default; + EffectChain(std::string sName, std::vector applyVec, std::string sLabel) + : name(sName), apply(applyVec), label(sLabel) + { + } + + bool Marshalling(Parcel &parcel) const override + { + parcel.WriteString(name); + int32_t size = static_cast(apply.size()); + parcel.WriteInt32(size); + for (auto &effect : apply) { + parcel.WriteString(effect); + } + parcel.WriteString(label); + return true; + } + + static EffectChain *Unmarshalling(Parcel &parcel) + { + auto effectChain = new EffectChain(); + if (effectChain == nullptr) { + return nullptr; + } + effectChain->name = parcel.ReadString(); + int32_t size = parcel.ReadInt32(); + if (size < 0 || size > AUDIO_EFFECT_COUNT_PER_CHAIN_UPPER_LIMIT) { + delete effectChain; + return nullptr; + } + for (int32_t i = 0; i < size; ++i) { + effectChain->apply.push_back(parcel.ReadString()); + } + effectChain->label = parcel.ReadString(); + return effectChain; + } }; struct Device { @@ -137,12 +253,72 @@ struct OriginalEffectConfig { PostProcessConfig postProcess; }; -struct EffectChainManagerParam { +struct EffectChainManagerParam : public Parcelable { uint32_t maxExtraNum = 0; std::string defaultSceneName; std::vector priorSceneList; std::unordered_map sceneTypeToChainNameMap; std::unordered_map effectDefaultProperty; + + EffectChainManagerParam() = default; + EffectChainManagerParam(uint32_t maxExtraNum, std::string defaultSceneName, std::vector priorSceneList, + std::unordered_map sceneTypeToChainNameMap, + std::unordered_map effectDefaultProperty) + : maxExtraNum(maxExtraNum), defaultSceneName(defaultSceneName), priorSceneList(priorSceneList), + sceneTypeToChainNameMap(sceneTypeToChainNameMap), effectDefaultProperty(effectDefaultProperty) + { + } + + bool Marshalling(Parcel &parcel) const override + { + parcel.WriteInt32(maxExtraNum); + parcel.WriteString(defaultSceneName); + int32_t size = static_cast(priorSceneList.size()); + parcel.WriteInt32(size); + for (auto &scene : priorSceneList) { + parcel.WriteString(scene); + } + size = static_cast(sceneTypeToChainNameMap.size()); + parcel.WriteInt32(size); + for (const auto &[scene, chain] : sceneTypeToChainNameMap) { + parcel.WriteString(scene); + parcel.WriteString(chain); + } + size = static_cast(effectDefaultProperty.size()); + parcel.WriteInt32(size); + for (const auto &[effect, property] : effectDefaultProperty) { + parcel.WriteString(effect); + parcel.WriteString(property); + } + return true; + } + + static EffectChainManagerParam *Unmarshalling(Parcel &parcel) + { + auto param = new EffectChainManagerParam(); + if (param == nullptr) { + return nullptr; + } + param->maxExtraNum = parcel.ReadInt32(); + param->defaultSceneName = parcel.ReadString(); + int32_t size = parcel.ReadInt32(); + for (int32_t i = 0; i < size; ++i) { + param->priorSceneList.push_back(parcel.ReadString()); + } + size = parcel.ReadInt32(); + for (int32_t i = 0; i < size; ++i) { + std::string scene = parcel.ReadString(); + std::string chain = parcel.ReadString(); + param->sceneTypeToChainNameMap[scene] = chain; + } + size = parcel.ReadInt32(); + for (int32_t i = 0; i < size; ++i) { + std::string effect = parcel.ReadString(); + std::string property = parcel.ReadString(); + param->effectDefaultProperty[effect] = property; + } + return param; + } }; struct StreamEffectMode { @@ -166,13 +342,98 @@ struct ProcessNew { std::vector stream; }; -struct SupportedEffectConfig { +struct SupportedEffectConfig : public Parcelable { std::vector effectChains; ProcessNew preProcessNew; ProcessNew postProcessNew; std::vector postProcessSceneMap; -}; + bool MarshallingStream(Parcel &parcel, const Stream &stream) const + { + parcel.WriteString(stream.scene); + uint32_t count = static_cast(stream.streamEffectMode.size()); + parcel.WriteInt32(count); + for (const auto &item : stream.streamEffectMode) { + parcel.WriteString(item.mode); + uint32_t deviceCount = static_cast(item.devicePort.size()); + parcel.WriteInt32(deviceCount); + for (const auto &device : item.devicePort) { + parcel.WriteString(device.type); + parcel.WriteString(device.chain); + } + } + return true; + } + + bool Marshalling(Parcel &parcel) const override + { + uint32_t countPre = static_cast(preProcessNew.stream.size()); + parcel.WriteInt32(countPre); + for (const auto &item : preProcessNew.stream) { + MarshallingStream(parcel, item); + } + + uint32_t countPost = static_cast(preProcessNew.stream.size()); + parcel.WriteInt32(countPost); + for (const auto &item : postProcessNew.stream) { + MarshallingStream(parcel, item); + } + + uint32_t countPostMap = static_cast(postProcessSceneMap.size()); + parcel.WriteInt32(countPostMap); + for (const auto &item : postProcessSceneMap) { + parcel.WriteString(item.name); + parcel.WriteString(item.sceneType); + } + return true; + } + + static Stream UnmarshallingStream(Parcel &parcel) + { + Stream stream; + stream.scene = parcel.ReadString(); + uint32_t count = parcel.ReadUint32(); + for (uint32_t i = 0; i < count; ++i) { + StreamEffectMode mode; + mode.mode = parcel.ReadString(); + uint32_t deviceCount = parcel.ReadUint32(); + for (uint32_t j = 0; j < deviceCount; ++j) { + Device device; + device.type = parcel.ReadString(); + device.chain = parcel.ReadString(); + mode.devicePort.push_back(device); + } + stream.streamEffectMode.push_back(mode); + } + return stream; + } + + static SupportedEffectConfig *Unmarshalling(Parcel &parcel) + { + auto config = new SupportedEffectConfig(); + if (config == nullptr) { + return nullptr; + } + uint32_t countPre = parcel.ReadUint32(); + for (uint32_t i = 0; i < countPre; ++i) { + config->preProcessNew.stream.push_back(UnmarshallingStream(parcel)); + } + + uint32_t countPost = parcel.ReadUint32(); + for (uint32_t i = 0; i < countPost; ++i) { + config->postProcessNew.stream.push_back(UnmarshallingStream(parcel)); + } + + uint32_t countPostMap = parcel.ReadUint32(); + for (uint32_t i = 0; i < countPostMap; ++i) { + SceneMappingItem item; + item.name = parcel.ReadString(); + item.sceneType = parcel.ReadString(); + config->postProcessSceneMap.push_back(item); + } + return config; + } +}; /** * Enumerates the audio scene effect type. @@ -241,7 +502,7 @@ struct AudioEffectPropertyV3 { parcel.WriteString(category)&& parcel.WriteInt32(flag); }; - void Unmarshalling(Parcel &parcel) + void UnmarshallingSelf(Parcel &parcel) { name = parcel.ReadString(); category = parcel.ReadString(); @@ -249,8 +510,36 @@ struct AudioEffectPropertyV3 { }; }; -struct AudioEffectPropertyArrayV3 { +struct AudioEffectPropertyArrayV3 : public Parcelable { std::vector property; + + bool Marshalling(Parcel &parcel) const override + { + int32_t size = static_cast(property.size()); + parcel.WriteInt32(size); + for (const auto &item : property) { + if (!item.Marshalling(parcel)) { + return false; + } + } + return true; + } + + static AudioEffectPropertyArrayV3 *Unmarshalling(Parcel &parcel) + { + auto propertyArray = new AudioEffectPropertyArrayV3(); + if (propertyArray == nullptr) { + return nullptr; + } + + int32_t size = parcel.ReadInt32(); + for (int32_t i = 0; i < size; i++) { + AudioEffectPropertyV3 property; + property.UnmarshallingSelf(parcel); + propertyArray->property.push_back(property); + } + return propertyArray; + } }; struct AudioEnhanceProperty { @@ -265,15 +554,43 @@ struct AudioEnhanceProperty { return parcel.WriteString(enhanceClass)&& parcel.WriteString(enhanceProp); } - void Unmarshalling(Parcel &parcel) + void UnmarshallingSelf(Parcel &parcel) { enhanceClass = parcel.ReadString(); enhanceProp = parcel.ReadString(); } }; -struct AudioEnhancePropertyArray { +struct AudioEnhancePropertyArray : public Parcelable { std::vector property; + + bool Marshalling(Parcel &parcel) const override + { + int32_t size = static_cast(property.size()); + parcel.WriteInt32(size); + for (const auto &item : property) { + if (!item.Marshalling(parcel)) { + return false; + } + } + return true; + } + + static AudioEnhancePropertyArray *Unmarshalling(Parcel &parcel) + { + auto propertyArray = new AudioEnhancePropertyArray(); + if (propertyArray == nullptr) { + return nullptr; + } + + int32_t size = parcel.ReadInt32(); + for (int32_t i = 0; i < size; i++) { + AudioEnhanceProperty property; + property.UnmarshallingSelf(parcel); + propertyArray->property.push_back(property); + } + return propertyArray; + } }; struct AudioEffectProperty { @@ -288,15 +605,43 @@ struct AudioEffectProperty { return parcel.WriteString(effectClass)&& parcel.WriteString(effectProp); } - void Unmarshalling(Parcel &parcel) + void UnmarshallingSelf(Parcel &parcel) { effectClass = parcel.ReadString(); effectProp = parcel.ReadString(); } }; -struct AudioEffectPropertyArray { +struct AudioEffectPropertyArray : public Parcelable { std::vector property; + + bool Marshalling(Parcel &parcel) const override + { + int32_t size = static_cast(property.size()); + parcel.WriteInt32(size); + for (const auto &item : property) { + if (!item.Marshalling(parcel)) { + return false; + } + } + return true; + } + + static AudioEffectPropertyArray *Unmarshalling(Parcel &parcel) + { + auto propertyArray = new AudioEffectPropertyArray(); + if (propertyArray == nullptr) { + return nullptr; + } + + int32_t size = parcel.ReadInt32(); + for (int32_t i = 0; i < size; i++) { + AudioEffectProperty property; + property.UnmarshallingSelf(parcel); + propertyArray->property.push_back(property); + } + return propertyArray; + } }; enum AudioEffectChainSetParamIndex { @@ -405,15 +750,58 @@ struct AudioEffectLibEntry { std::vector effectName; }; -struct AudioSpatializationState { +struct AudioSpatializationState : public Parcelable { bool spatializationEnabled = false; bool headTrackingEnabled = false; + + AudioSpatializationState() = default; + AudioSpatializationState(bool spatializationEnabled, bool headTrackingEnabled) + { + this->spatializationEnabled = spatializationEnabled; + this->headTrackingEnabled = headTrackingEnabled; + } + + bool Marshalling(Parcel &parcel) const override + { + return parcel.WriteBool(spatializationEnabled) + && parcel.WriteBool(headTrackingEnabled); + } + + static AudioSpatializationState *Unmarshalling(Parcel &parcel) + { + auto info = new AudioSpatializationState(); + if (info == nullptr) { + return nullptr; + } + info->spatializationEnabled = parcel.ReadBool(); + info->headTrackingEnabled = parcel.ReadBool(); + return info; + } }; -struct ConverterConfig { +struct ConverterConfig : public Parcelable { std::string version; Library library; uint64_t outChannelLayout = 0; + + bool Marshalling(Parcel &parcel) const override + { + return parcel.WriteString(version) && + library.Marshalling(parcel) && + parcel.WriteUint64(outChannelLayout); + } + + static ConverterConfig *Unmarshalling(Parcel &parcel) + { + auto config = new ConverterConfig(); + if (config == nullptr) { + return nullptr; + } + config->version = parcel.ReadString(); + config->library.UnmarshallingSelf(parcel); + config->outChannelLayout = parcel.ReadUint64(); + return config; + } }; enum AudioSpatializationSceneType { diff --git a/interfaces/inner_api/native/audiocommon/include/audio_info.h b/interfaces/inner_api/native/audiocommon/include/audio_info.h index 3bfcb458b5..1937326fb9 100644 --- a/interfaces/inner_api/native/audiocommon/include/audio_info.h +++ b/interfaces/inner_api/native/audiocommon/include/audio_info.h @@ -92,7 +92,7 @@ const char* REMOTE_CAST_INNER_CAPTURER_SINK_NAME = "RemoteCastInnerCapturer"; const char* DUP_STREAM = "DupStream"; } -#ifdef FEATURE_DTMF_TONE +//#ifdef FEATURE_DTMF_TONE cant contain this macro due to idl dependency // Maximun number of sine waves in a tone segment constexpr uint32_t TONEINFO_MAX_WAVES = 3; //Maximun number of SupportedTones @@ -100,12 +100,15 @@ constexpr uint32_t MAX_SUPPORTED_TONEINFO_SIZE = 65535; // Maximun number of segments in a tone descriptor constexpr uint32_t TONEINFO_MAX_SEGMENTS = 12; constexpr uint32_t TONEINFO_INF = 0xFFFFFFFF; + class ToneSegment : public Parcelable { public: uint32_t duration; uint16_t waveFreq[TONEINFO_MAX_WAVES+1]; uint16_t loopCnt; uint16_t loopIndx; + + ToneSegment() = default; bool Marshalling(Parcel &parcel) const override { parcel.WriteUint32(duration); @@ -116,7 +119,8 @@ public: } return true; } - void Unmarshalling(Parcel &parcel) + + void UnmarshallingSelf(Parcel &parcel) { duration = parcel.ReadUint32(); loopCnt = parcel.ReadUint16(); @@ -125,6 +129,17 @@ public: waveFreq[i] = parcel.ReadUint16(); } } + + static ToneSegment *Unmarshalling(Parcel &parcel) + { + auto info = new ToneSegment(); + if (info == nullptr) { + return nullptr; + } + + info->UnmarshallingSelf(parcel); + return info; + } }; class ToneInfo : public Parcelable { @@ -133,6 +148,7 @@ public: uint32_t segmentCnt; uint32_t repeatCnt; uint32_t repeatSegment; + ToneInfo() = default; bool Marshalling(Parcel &parcel) const override { parcel.WriteUint32(segmentCnt); @@ -146,20 +162,26 @@ public: } return true; } - void Unmarshalling(Parcel &parcel) + static ToneInfo *Unmarshalling(Parcel &parcel) { - segmentCnt = parcel.ReadUint32(); - repeatCnt = parcel.ReadUint32(); - repeatSegment = parcel.ReadUint32(); - if (!(segmentCnt >= 0 && segmentCnt <= TONEINFO_MAX_SEGMENTS + 1)) { - return; + auto info = new ToneInfo(); + if (info == nullptr) { + return nullptr; } - for (uint32_t i = 0; i < segmentCnt; i++) { - segments[i].Unmarshalling(parcel); + info->segmentCnt = parcel.ReadUint32(); + info->repeatCnt = parcel.ReadUint32(); + info->repeatSegment = parcel.ReadUint32(); + if (!(info->segmentCnt >= 0 && info->segmentCnt <= TONEINFO_MAX_SEGMENTS + 1)) { + delete info; + return nullptr; + } + for (uint32_t i = 0; i < info->segmentCnt; i++) { + info->segments[i].UnmarshallingSelf(parcel); } + return info; } }; -#endif +//#endif enum VolumeAdjustType { /** @@ -379,7 +401,7 @@ constexpr CallbackChange CALLBACK_ENUMS[] = { static_assert((sizeof(CALLBACK_ENUMS) / sizeof(CallbackChange)) == static_cast(CALLBACK_MAX), "check CALLBACK_ENUMS"); -struct VolumeEvent { +struct VolumeEvent : public Parcelable { AudioVolumeType volumeType; int32_t volume; bool updateUi; @@ -392,7 +414,7 @@ struct VolumeEvent { volume(volLevel), updateUi(isUiUpdated) {} VolumeEvent() = default; - bool Marshalling(Parcel &parcel) const + bool Marshalling(Parcel &parcel) const override { return parcel.WriteInt32(static_cast(volumeType)) && parcel.WriteInt32(volume) @@ -402,7 +424,7 @@ struct VolumeEvent { && parcel.WriteInt32(static_cast(volumeMode)) && parcel.WriteBool(notifyRssWhenAccountsChange); } - void Unmarshalling(Parcel &parcel) + void UnmarshallingSelf(Parcel &parcel) { volumeType = static_cast(parcel.ReadInt32()); volume = parcel.ReadInt32(); @@ -412,16 +434,26 @@ struct VolumeEvent { volumeMode = static_cast(parcel.ReadInt32()); notifyRssWhenAccountsChange = parcel.ReadBool(); } + + static VolumeEvent *Unmarshalling(Parcel &parcel) + { + auto event = new VolumeEvent(); + if (event == nullptr) { + return nullptr; + } + event->UnmarshallingSelf(parcel); + return event; + } }; -struct StreamVolumeEvent { +struct StreamVolumeEvent : public Parcelable { StreamUsage streamUsage = STREAM_USAGE_INVALID; int32_t volume = -1; bool updateUi = false; int32_t volumeGroupId = -1; std::string networkId = ""; AudioVolumeMode volumeMode = AUDIOSTREAM_VOLUMEMODE_SYSTEM_GLOBAL; - bool Marshalling(Parcel &parcel) const + bool Marshalling(Parcel &parcel) const override { return parcel.WriteInt32(static_cast(streamUsage)) && parcel.WriteInt32(volume) @@ -430,7 +462,7 @@ struct StreamVolumeEvent { && parcel.WriteString(networkId) && parcel.WriteInt32(static_cast(volumeMode)); } - void Unmarshalling(Parcel &parcel) + void UnmarshallingSelf(Parcel &parcel) { streamUsage = static_cast(parcel.ReadInt32()); volume = parcel.ReadInt32(); @@ -439,6 +471,17 @@ struct StreamVolumeEvent { networkId = parcel.ReadString(); volumeMode = static_cast(parcel.ReadInt32()); } + + static StreamVolumeEvent *Unmarshalling(Parcel &parcel) + { + auto event = new StreamVolumeEvent(); + if (event == nullptr) { + return nullptr; + } + + event->UnmarshallingSelf(parcel); + return event; + } }; struct AudioParameters { @@ -511,7 +554,7 @@ enum AudioLoopbackState { LOOPBACK_STATE_DESTROYED, }; -struct AudioRendererInfo { +struct AudioRendererInfo : public Parcelable { ContentType contentType = CONTENT_TYPE_UNKNOWN; StreamUsage streamUsage = STREAM_USAGE_UNKNOWN; int32_t rendererFlags = AUDIO_FLAG_NORMAL; @@ -537,7 +580,15 @@ struct AudioRendererInfo { AudioLoopbackMode loopbackMode = LOOPBACK_HARDWARE; bool isVirtualKeyboard = false; - bool Marshalling(Parcel &parcel) const + AudioRendererInfo() {} + AudioRendererInfo(ContentType contentTypeIn, StreamUsage streamUsageIn, int32_t rendererFlagsIn) + : contentType(contentTypeIn), streamUsage(streamUsageIn), rendererFlags(rendererFlagsIn) {} + AudioRendererInfo(ContentType contentTypeIn, StreamUsage streamUsageIn, + int32_t rendererFlagsIn, AudioVolumeMode volumeModeIn) + : contentType(contentTypeIn), streamUsage(streamUsageIn), + rendererFlags(rendererFlagsIn), volumeMode(volumeModeIn) {} + + bool Marshalling(Parcel &parcel) const override { return parcel.WriteInt32(static_cast(contentType)) && parcel.WriteInt32(static_cast(streamUsage)) @@ -560,7 +611,7 @@ struct AudioRendererInfo { && parcel.WriteInt32(static_cast(loopbackMode)) && parcel.WriteBool(isVirtualKeyboard); } - void Unmarshalling(Parcel &parcel) + void UnmarshallingSelf(Parcel &parcel) { contentType = static_cast(parcel.ReadInt32()); streamUsage = static_cast(parcel.ReadInt32()); @@ -583,9 +634,19 @@ struct AudioRendererInfo { loopbackMode = static_cast(parcel.ReadInt32()); isVirtualKeyboard = parcel.ReadBool(); } + + static AudioRendererInfo *Unmarshalling(Parcel &parcel) + { + auto info = new AudioRendererInfo(); + if (info == nullptr) { + return nullptr; + } + info->UnmarshallingSelf(parcel); + return info; + } }; -class AudioCapturerInfo { +class AudioCapturerInfo : public Parcelable { public: SourceType sourceType = SOURCE_TYPE_INVALID; int32_t capturerFlags = 0; @@ -607,7 +668,7 @@ public: } AudioCapturerInfo() = default; ~AudioCapturerInfo()= default; - bool Marshalling(Parcel &parcel) const + bool Marshalling(Parcel &parcel) const override { return parcel.WriteInt32(static_cast(sourceType)) && parcel.WriteInt32(capturerFlags) && @@ -621,7 +682,8 @@ public: parcel.WriteBool(isLoopback) && parcel.WriteInt32(static_cast(loopbackMode)); } - void Unmarshalling(Parcel &parcel) + + void UnmarshallingSelf(Parcel &parcel) { sourceType = static_cast(parcel.ReadInt32()); capturerFlags = parcel.ReadInt32(); @@ -635,6 +697,16 @@ public: isLoopback = parcel.ReadBool(); loopbackMode = static_cast(parcel.ReadInt32()); } + + static AudioCapturerInfo *Unmarshalling(Parcel &parcel) + { + auto audioCapturerInfo = new AudioCapturerInfo(); + if (audioCapturerInfo == nullptr) { + return nullptr; + } + audioCapturerInfo->UnmarshallingSelf(parcel); + return audioCapturerInfo; + } }; struct AudioRendererDesc { @@ -649,8 +721,23 @@ struct AudioRendererOptions { AudioSessionStrategy strategy = { AudioConcurrencyMode::INVALID }; }; -struct MicStateChangeEvent { +struct MicStateChangeEvent : public Parcelable { bool mute; + + bool Marshalling(Parcel &parcel) const override + { + return parcel.WriteBool(mute); + } + + static MicStateChangeEvent *Unmarshalling(Parcel &parcel) + { + auto event = new MicStateChangeEvent(); + if (event == nullptr) { + return nullptr; + } + event->mute = parcel.ReadBool(); + return event; + } }; enum AudioScene : int32_t { @@ -764,6 +851,24 @@ struct CaptureFilterOptions { std::vector pids; FilterMode pidFilterMode {FilterMode::INCLUDE}; + CaptureFilterOptions() = default; + CaptureFilterOptions(const std::vector &usage, FilterMode uFilterMode, + const std::vector &pid, FilterMode pFilterMode) + { + this->usages = usage; + this->usageFilterMode = uFilterMode; + this->pids = pid; + this->pidFilterMode = pFilterMode; + } + + CaptureFilterOptions(const CaptureFilterOptions &filter) + { + usages = filter.usages; + usageFilterMode = filter.usageFilterMode; + pids = filter.pids; + pidFilterMode = filter.pidFilterMode; + } + bool operator ==(CaptureFilterOptions& filter) { std::sort(filter.usages.begin(), filter.usages.end()); @@ -775,14 +880,118 @@ struct CaptureFilterOptions { } }; -struct AudioPlaybackCaptureConfig { +inline constexpr uint32_t MAX_VALID_USAGE_SIZE = 30; // 128 for pids +inline constexpr uint32_t MAX_VALID_PIDS_SIZE = 128; // 128 for pids + +struct AudioPlaybackCaptureConfig : public Parcelable { CaptureFilterOptions filterOptions; bool silentCapture {false}; // To be deprecated since 12 + AudioPlaybackCaptureConfig() = default; + AudioPlaybackCaptureConfig(const CaptureFilterOptions &filter, const bool slient) + : filterOptions(filter), silentCapture(slient) + { + } + + AudioPlaybackCaptureConfig(const AudioPlaybackCaptureConfig &capturerConfig) + : filterOptions(capturerConfig.filterOptions), silentCapture(capturerConfig.silentCapture) + { + } + bool operator ==(AudioPlaybackCaptureConfig& filter) { return (filter.filterOptions == filterOptions && filter.silentCapture == silentCapture); } + + bool Marshalling(Parcel &parcel) const override + { + // filterOptions.usages + size_t usageSize = filterOptions.usages.size(); + if (usageSize >= MAX_VALID_USAGE_SIZE) return false; + parcel.WriteUint32(usageSize); + for (size_t i = 0; i < usageSize; i++) { + parcel.WriteInt32(static_cast(filterOptions.usages[i])); + } + + // filterOptions.usageFilterMode + parcel.WriteUint32(filterOptions.usageFilterMode); + + // filterOptions.pids + size_t pidSize = filterOptions.pids.size(); + if (pidSize >= MAX_VALID_PIDS_SIZE) return false; + parcel.WriteUint32(pidSize); + for (size_t i = 0; i < pidSize; i++) { + parcel.WriteUint32(filterOptions.pids[i]); + } + + // filterOptions.pidFilterMode + parcel.WriteUint32(filterOptions.pidFilterMode); + + // silentCapture + parcel.WriteBool(silentCapture); + return true; + } + + static AudioPlaybackCaptureConfig *Unmarshalling(Parcel &parcel) + { + auto config = new AudioPlaybackCaptureConfig(); + if (config == nullptr) return nullptr; + // filterOptions.usages + uint32_t usageSize = parcel.ReadUint32(); + if (usageSize > MAX_VALID_USAGE_SIZE) { + delete config; + return nullptr; + } + std::vector usages = {}; + for (uint32_t i = 0; i < usageSize; i++) { + int32_t tmpUsage = parcel.ReadInt32(); + if (std::find(AUDIO_SUPPORTED_STREAM_USAGES.begin(), AUDIO_SUPPORTED_STREAM_USAGES.end(), tmpUsage) == + AUDIO_SUPPORTED_STREAM_USAGES.end()) { + delete config; + return nullptr; + } + usages.push_back(static_cast(tmpUsage)); + } + config->filterOptions.usages = usages; + + // filterOptions.usageFilterMode + uint32_t tempMode = parcel.ReadUint32(); + if (tempMode >= FilterMode::MAX_FILTER_MODE) { + delete config; + return nullptr; + } + config->filterOptions.usageFilterMode = static_cast(tempMode); + + // filterOptions.pids + uint32_t pidSize = parcel.ReadUint32(); + if (pidSize > MAX_VALID_PIDS_SIZE) { + delete config; + return nullptr; + } + std::vector pids = {}; + for (uint32_t i = 0; i < pidSize; i++) { + int32_t tmpPid = parcel.ReadInt32(); + if (tmpPid <= 0) { + delete config; + return nullptr; + } + pids.push_back(tmpPid); + } + config->filterOptions.pids = pids; + + // filterOptions.pidFilterMode + tempMode = parcel.ReadUint32(); + if (tempMode >= FilterMode::MAX_FILTER_MODE) { + delete config; + return nullptr; + } + config->filterOptions.pidFilterMode = static_cast(tempMode); + + // silentCapture + config->silentCapture = parcel.ReadBool(); + + return config; + } }; struct AudioCapturerOptions { @@ -820,7 +1029,7 @@ struct SinkInfo { std::string adapterName; }; -struct SinkInput { +struct SinkInput : public Parcelable { int32_t streamId; AudioStreamType streamType; @@ -832,7 +1041,7 @@ struct SinkInput { std::string sinkName; // sink name int32_t statusMark; // mark the router status uint64_t startTime; // when this router is created - bool Marshalling(Parcel &parcel) const + bool Marshalling(Parcel &parcel) const override { return parcel.WriteInt32(streamId) && parcel.WriteInt32(static_cast(streamType)) && @@ -840,13 +1049,20 @@ struct SinkInput { parcel.WriteInt32(pid) && parcel.WriteUint32(paStreamId); } - void Unmarshalling(Parcel &parcel) + + static SinkInput *Unmarshalling(Parcel &parcel) { - streamId = parcel.ReadInt32(); - streamType = static_cast(parcel.ReadInt32()); - uid = parcel.ReadInt32(); - pid = parcel.ReadInt32(); - paStreamId = parcel.ReadUint32(); + auto sinkInput = new SinkInput(); + if (sinkInput == nullptr) { + return nullptr; + } + + sinkInput->streamId = parcel.ReadInt32(); + sinkInput->streamType = static_cast(parcel.ReadInt32()); + sinkInput->uid = parcel.ReadInt32(); + sinkInput->pid = parcel.ReadInt32(); + sinkInput->paStreamId = parcel.ReadUint32(); + return sinkInput; } }; @@ -992,7 +1208,7 @@ enum InnerCapMode : uint32_t { INVALID_CAP_MODE }; -struct AudioProcessConfig { +struct AudioProcessConfig : public Parcelable { int32_t callerUid = INVALID_UID; AppInfo appInfo; @@ -1020,6 +1236,131 @@ struct AudioProcessConfig { InnerCapMode innerCapMode {InnerCapMode::INVALID_CAP_MODE}; int32_t innerCapId = 0; + + AudioProcessConfig() {} + bool Marshalling(Parcel &parcel) const override + { + // AppInfo + parcel.WriteInt32(appInfo.appUid); + parcel.WriteUint32(appInfo.appTokenId); + parcel.WriteInt32(appInfo.appPid); + parcel.WriteUint64(appInfo.appFullTokenId); + + // AudioStreamInfo + parcel.WriteInt32(streamInfo.samplingRate); + parcel.WriteInt32(streamInfo.encoding); + parcel.WriteInt32(streamInfo.format); + parcel.WriteInt32(streamInfo.channels); + parcel.WriteUint64(streamInfo.channelLayout); + + // AudioMode + parcel.WriteInt32(audioMode); + + // AudioRendererInfo + parcel.WriteInt32(rendererInfo.contentType); + parcel.WriteInt32(rendererInfo.streamUsage); + parcel.WriteInt32(rendererInfo.rendererFlags); + parcel.WriteInt32(rendererInfo.volumeMode); + parcel.WriteInt32(rendererInfo.originalFlag); + parcel.WriteString(rendererInfo.sceneType); + parcel.WriteBool(rendererInfo.spatializationEnabled); + parcel.WriteBool(rendererInfo.headTrackingEnabled); + parcel.WriteBool(rendererInfo.isSatellite); + parcel.WriteInt32(rendererInfo.pipeType); + parcel.WriteInt32(rendererInfo.playerType); + parcel.WriteUint64(rendererInfo.expectedPlaybackDurationBytes); + parcel.WriteInt32(rendererInfo.effectMode); + + //AudioPrivacyType + parcel.WriteInt32(privacyType); + + // AudioCapturerInfo + parcel.WriteInt32(capturerInfo.sourceType); + parcel.WriteInt32(capturerInfo.capturerFlags); + parcel.WriteInt32(capturerInfo.originalFlag); + parcel.WriteInt32(capturerInfo.pipeType); + parcel.WriteInt32(capturerInfo.recorderType); + + // streamType + parcel.WriteInt32(streamType); + + // deviceType + parcel.WriteInt32(deviceType); + + // Recorder only + parcel.WriteBool(isInnerCapturer); + parcel.WriteBool(isWakeupCapturer); + + // Original session id for re-create stream + parcel.WriteUint32(originalSessionId); + parcel.WriteInt32(innerCapId); + + return true; + } + + static AudioProcessConfig *Unmarshalling(Parcel &parcel) + { + auto config = new AudioProcessConfig(); + if (config == nullptr) { + return nullptr; + } + // AppInfo + config->appInfo.appUid = parcel.ReadInt32(); + config->appInfo.appTokenId = parcel.ReadUint32(); + config->appInfo.appPid = parcel.ReadInt32(); + config->appInfo.appFullTokenId = parcel.ReadUint64(); + + // AudioStreamInfo + config->streamInfo.samplingRate = static_cast(parcel.ReadInt32()); + config->streamInfo.encoding = static_cast(parcel.ReadInt32()); + config->streamInfo.format = static_cast(parcel.ReadInt32()); + config->streamInfo.channels = static_cast(parcel.ReadInt32()); + config->streamInfo.channelLayout = static_cast(parcel.ReadUint64()); + + // AudioMode + config->audioMode = static_cast(parcel.ReadInt32()); + + // AudioRendererInfo + config->rendererInfo.contentType = static_cast(parcel.ReadInt32()); + config->rendererInfo.streamUsage = static_cast(parcel.ReadInt32()); + config->rendererInfo.rendererFlags = parcel.ReadInt32(); + config->rendererInfo.volumeMode = static_cast(parcel.ReadInt32()); + config->rendererInfo.originalFlag = parcel.ReadInt32(); + config->rendererInfo.sceneType = parcel.ReadString(); + config->rendererInfo.spatializationEnabled = parcel.ReadBool(); + config->rendererInfo.headTrackingEnabled = parcel.ReadBool(); + config->rendererInfo.isSatellite = parcel.ReadBool(); + config->rendererInfo.pipeType = static_cast(parcel.ReadInt32()); + config->rendererInfo.playerType = static_cast(parcel.ReadInt32()); + config->rendererInfo.expectedPlaybackDurationBytes = parcel.ReadUint64(); + config->rendererInfo.effectMode = parcel.ReadInt32(); + + //AudioPrivacyType + config->privacyType = static_cast(parcel.ReadInt32()); + + // AudioCapturerInfo + config->capturerInfo.sourceType = static_cast(parcel.ReadInt32()); + config->capturerInfo.capturerFlags = parcel.ReadInt32(); + config->capturerInfo.originalFlag = parcel.ReadInt32(); + config->capturerInfo.pipeType = static_cast(parcel.ReadInt32()); + config->capturerInfo.recorderType = static_cast(parcel.ReadInt32()); + + // streamType + config->streamType = static_cast(parcel.ReadInt32()); + + // deviceType + config->deviceType = static_cast(parcel.ReadInt32()); + + // Recorder only + config->isInnerCapturer = parcel.ReadBool(); + config->isWakeupCapturer = parcel.ReadBool(); + + // Original session id for re-create stream + config->originalSessionId = parcel.ReadUint32(); + config->innerCapId = parcel.ReadInt32(); + + return config; + } }; struct Volume { @@ -1098,9 +1439,25 @@ struct SwitchStreamInfo { } }; -struct StreamSetStateEventInternal { +struct StreamSetStateEventInternal : public Parcelable { StreamSetState streamSetState; StreamUsage streamUsage; + + bool Marshalling(Parcel &parcel) const override + { + return parcel.WriteInt32(static_cast(streamSetState)) && + parcel.WriteInt32(static_cast(streamUsage)); + } + static StreamSetStateEventInternal *Unmarshalling(Parcel &parcel) + { + auto event = new StreamSetStateEventInternal(); + if (event == nullptr) { + return nullptr; + } + event->streamSetState = static_cast(parcel.ReadInt32()); + event->streamUsage = static_cast(parcel.ReadInt32()); + return event; + } }; enum AudioPin { @@ -1493,6 +1850,32 @@ struct RestoreInfo { uint32_t routeFlag = 0; }; +struct RestoreInfoIpc : public Parcelable { + RestoreInfo restoreInfo; + + bool Marshalling(Parcel &parcel) const override + { + return parcel.WriteInt32(restoreInfo.restoreReason) && + parcel.WriteInt32(restoreInfo.deviceChangeReason) && + parcel.WriteInt32(restoreInfo.targetStreamFlag) && + parcel.WriteUint32(restoreInfo.routeFlag); + } + + static RestoreInfoIpc *Unmarshalling(Parcel &parcel) + { + auto info = new RestoreInfoIpc(); + if (info == nullptr) { + return nullptr; + } + + info->restoreInfo.restoreReason = static_cast(parcel.ReadInt32()); + info->restoreInfo.deviceChangeReason = parcel.ReadInt32(); + info->restoreInfo.targetStreamFlag = parcel.ReadInt32(); + info->restoreInfo.routeFlag = parcel.ReadUint32(); + return info; + } +}; + /** * Enumerates the method sources that trigger priority boosting. * Used to distinguish between different triggering entry points. diff --git a/interfaces/inner_api/native/audiocommon/include/audio_interrupt_info.h b/interfaces/inner_api/native/audiocommon/include/audio_interrupt_info.h index bc2039d7f0..1c0e90d6ec 100644 --- a/interfaces/inner_api/native/audiocommon/include/audio_interrupt_info.h +++ b/interfaces/inner_api/native/audiocommon/include/audio_interrupt_info.h @@ -99,7 +99,33 @@ enum InterruptForceType { INTERRUPT_SHARE }; -struct InterruptEvent { +struct InterruptEvent : public Parcelable { + InterruptEvent() {} + InterruptEvent(InterruptType eventTypeIn, InterruptForceType forceTypeIn, + InterruptHint hintType, bool callbackToAppIn = true) + : eventType(eventTypeIn), forceType(forceTypeIn), hintType(hintType), callbackToApp(callbackToAppIn) {} + bool Marshalling(Parcel &parcel) const override + { + parcel.WriteInt32(static_cast(eventType)); + parcel.WriteInt32(static_cast(forceType)); + parcel.WriteInt32(static_cast(hintType)); + parcel.WriteBool(callbackToApp); + return true; + } + + static InterruptEvent *Unmarshalling(Parcel &parcel) + { + auto info = new InterruptEvent(); + if (info == nullptr) { + return nullptr; + } + info->eventType = static_cast(parcel.ReadInt32()); + info->forceType = static_cast(parcel.ReadInt32()); + info->hintType = static_cast(parcel.ReadInt32()); + info->callbackToApp = parcel.ReadBool(); + return info; + } + /** * Interrupt event type, begin or end */ @@ -121,12 +147,46 @@ struct InterruptEvent { }; // Used internally only by AudioFramework -struct InterruptEventInternal { +struct InterruptEventInternal : public Parcelable { InterruptType eventType; InterruptForceType forceType; InterruptHint hintType; float duckVolume; bool callbackToApp = true; + + InterruptEventInternal() = default; + + InterruptEventInternal(InterruptType eventtype, InterruptForceType forcetype, + InterruptHint hinttype, float duckvolume) + { + eventType = eventtype; + forceType = forcetype; + hintType = hinttype; + duckVolume = duckvolume; + } + + bool Marshalling(Parcel &parcel) const override + { + return parcel.WriteInt32(static_cast(eventType)) + && parcel.WriteInt32(static_cast(forceType)) + && parcel.WriteInt32(static_cast(hintType)) + && parcel.WriteFloat(duckVolume) + && parcel.WriteBool(callbackToApp); + } + + static InterruptEventInternal *Unmarshalling(Parcel &parcel) + { + auto interupt = new InterruptEventInternal(); + if (interupt == nullptr) { + return nullptr; + } + interupt->eventType = static_cast(parcel.ReadInt32()); + interupt->forceType = static_cast(parcel.ReadInt32()); + interupt->hintType = static_cast(parcel.ReadInt32()); + interupt->duckVolume = parcel.ReadFloat(); + interupt->callbackToApp = parcel.ReadBool(); + return interupt; + } }; enum AudioInterruptChangeType { @@ -222,7 +282,7 @@ enum InterruptEventCallbackType { INTERRUPT_EVENT_CALLBACK_DEFAULT = 2 }; -class AudioInterrupt { +class AudioInterrupt : public Parcelable { public: static constexpr int32_t MAX_SOURCE_TYPE_NUM = 20; StreamUsage streamUsage = STREAM_USAGE_INVALID; @@ -246,6 +306,26 @@ public: uint32_t streamId_) : streamUsage(streamUsage_), contentType(contentType_), audioFocusType(audioFocusType_), streamId(streamId_) {} ~AudioInterrupt() = default; + + bool operator==(const AudioInterrupt &other) const + { + return streamId == other.streamId && + streamUsage == other.streamUsage && + audioFocusType == other.audioFocusType && + pid == other.pid && + uid == other.uid; + } + + bool operator<(const AudioInterrupt &other) const + { + return streamId < other.streamId || pid < other.pid || uid < other.uid; + } + + bool operator>(const AudioInterrupt &other) const + { + return streamId > other.streamId || pid > other.pid || uid > other.uid; + } + static bool Marshalling(Parcel &parcel, const AudioInterrupt &interrupt) { bool res = parcel.WriteInt32(static_cast(interrupt.streamUsage)); @@ -299,6 +379,21 @@ public: interrupt.strategy = static_cast(parcel.ReadInt32()); interrupt.callbackType = static_cast(parcel.ReadInt32()); } + + bool Marshalling(Parcel &parcel) const override + { + return Marshalling(parcel, *this); + } + + static AudioInterrupt *Unmarshalling(Parcel &parcel) + { + auto interrupt = new AudioInterrupt(); + if (interrupt == nullptr) { + return nullptr; + } + Unmarshalling(parcel, *interrupt); + return interrupt; + } }; } // namespace AudioStandard } // namespace OHOS diff --git a/interfaces/inner_api/native/audiocommon/include/audio_stream_change_info.h b/interfaces/inner_api/native/audiocommon/include/audio_stream_change_info.h index 8bdf24d30c..7b00940a27 100644 --- a/interfaces/inner_api/native/audiocommon/include/audio_stream_change_info.h +++ b/interfaces/inner_api/native/audiocommon/include/audio_stream_change_info.h @@ -21,7 +21,7 @@ namespace OHOS { namespace AudioStandard { -class AudioRendererChangeInfo { +class AudioRendererChangeInfo : public Parcelable { public: int32_t createrUID; int32_t clientUID; @@ -36,6 +36,7 @@ public: bool prerunningState = false; bool backMute = false; int32_t appVolume; + mutable std::shared_ptr clientInfo_ = nullptr; AudioRendererChangeInfo(const AudioRendererChangeInfo &audioRendererChangeInfo) { @@ -43,31 +44,24 @@ public: } AudioRendererChangeInfo() = default; ~AudioRendererChangeInfo() = default; - bool Marshalling(Parcel &parcel) const + + void SetClientInfo(std::shared_ptr clientInfo) const { - return parcel.WriteInt32(createrUID) - && parcel.WriteInt32(clientUID) - && parcel.WriteInt32(sessionId) - && parcel.WriteInt32(callerPid) - && parcel.WriteInt32(clientPid) - && parcel.WriteInt32(tokenId) - && parcel.WriteInt32(channelCount) - && parcel.WriteBool(backMute) - && parcel.WriteInt32(static_cast(rendererInfo.contentType)) - && parcel.WriteInt32(static_cast(rendererInfo.streamUsage)) - && parcel.WriteInt32(rendererInfo.rendererFlags) - && parcel.WriteInt32(rendererInfo.originalFlag) - && parcel.WriteInt32(rendererInfo.samplingRate) - && parcel.WriteInt32(rendererInfo.format) - && rendererInfo.Marshalling(parcel) - && parcel.WriteInt32(static_cast(rendererState)) - && outputDeviceInfo.Marshalling(parcel) - && parcel.WriteInt32(appVolume); + clientInfo_ = clientInfo; + outputDeviceInfo.SetClientInfo(clientInfo); } - bool Marshalling(Parcel &parcel, bool hasBTPermission, bool hasSystemPermission, int32_t apiVersion) const + + bool Marshalling(Parcel &parcel) const override { + int32_t clientUIDTemp = clientUID; + RendererState rendererStateTemp = rendererState; + if (clientInfo_ != nullptr) { + clientUIDTemp = clientInfo_->hasSystemPermission_ ? clientUID : EMPTY_UID; + rendererStateTemp = clientInfo_->hasSystemPermission_ ? rendererState : RENDERER_INVALID; + clientInfo_ = nullptr; + } return parcel.WriteInt32(createrUID) - && parcel.WriteInt32(hasSystemPermission ? clientUID : EMPTY_UID) + && parcel.WriteInt32(clientUIDTemp) && parcel.WriteInt32(sessionId) && parcel.WriteInt32(callerPid) && parcel.WriteInt32(clientPid) @@ -81,12 +75,12 @@ public: && parcel.WriteInt32(rendererInfo.samplingRate) && parcel.WriteInt32(rendererInfo.format) && rendererInfo.Marshalling(parcel) - && parcel.WriteInt32(hasSystemPermission ? static_cast(rendererState) : - RENDERER_INVALID) - && outputDeviceInfo.Marshalling(parcel, hasBTPermission, hasSystemPermission, apiVersion) + && parcel.WriteInt32(static_cast(rendererStateTemp)) + && outputDeviceInfo.Marshalling(parcel) && parcel.WriteInt32(appVolume); } - void Unmarshalling(Parcel &parcel) + + void UnmarshallingSelf(Parcel &parcel) { createrUID = parcel.ReadInt32(); clientUID = parcel.ReadInt32(); @@ -103,15 +97,24 @@ public: rendererInfo.originalFlag = parcel.ReadInt32(); rendererInfo.samplingRate = static_cast(parcel.ReadInt32()); rendererInfo.format = static_cast(parcel.ReadInt32()); - rendererInfo.Unmarshalling(parcel); - + rendererInfo.UnmarshallingSelf(parcel); rendererState = static_cast(parcel.ReadInt32()); - outputDeviceInfo.Unmarshalling(parcel); + outputDeviceInfo.UnmarshallingSelf(parcel); appVolume = parcel.ReadInt32(); } + + static AudioRendererChangeInfo *Unmarshalling(Parcel &parcel) + { + auto info = new AudioRendererChangeInfo(); + if (info == nullptr) { + return nullptr; + } + info->UnmarshallingSelf(parcel); + return info; + } }; -class AudioCapturerChangeInfo { +class AudioCapturerChangeInfo : public Parcelable { public: int32_t createrUID; int32_t clientUID; @@ -124,6 +127,7 @@ public: bool prerunningState = false; bool muted; uint32_t appTokenId; + mutable std::shared_ptr clientInfo_ = nullptr; AudioCapturerChangeInfo(const AudioCapturerChangeInfo &audioCapturerChangeInfo) { @@ -131,52 +135,79 @@ public: } AudioCapturerChangeInfo() = default; ~AudioCapturerChangeInfo() = default; - bool Marshalling(Parcel &parcel) const + + void SetClientInfo(std::shared_ptr clientInfo) const { - return parcel.WriteInt32(createrUID) - && parcel.WriteInt32(clientUID) - && parcel.WriteInt32(sessionId) - && parcel.WriteInt32(callerPid) - && parcel.WriteInt32(clientPid) - && capturerInfo.Marshalling(parcel) - && parcel.WriteInt32(static_cast(capturerState)) - && inputDeviceInfo.Marshalling(parcel) - && parcel.WriteBool(muted) - && parcel.WriteUint32(appTokenId); + clientInfo_ = clientInfo; + inputDeviceInfo.SetClientInfo(clientInfo); } - bool Marshalling(Parcel &parcel, bool hasBTPermission, bool hasSystemPermission, int32_t apiVersion) const + bool Marshalling(Parcel &parcel) const override { + int32_t clientUIDTemp = clientUID; + CapturerState capturerStateTemp = capturerState; + if (clientInfo_ != nullptr) { + clientUIDTemp = clientInfo_->hasSystemPermission_ ? clientUID : EMPTY_UID; + capturerStateTemp = clientInfo_->hasSystemPermission_ ? capturerState : CAPTURER_INVALID; + clientInfo_ = nullptr; + } return parcel.WriteInt32(createrUID) - && parcel.WriteInt32(hasSystemPermission ? clientUID : EMPTY_UID) + && parcel.WriteInt32(clientUIDTemp) && parcel.WriteInt32(sessionId) && parcel.WriteInt32(callerPid) && parcel.WriteInt32(clientPid) && capturerInfo.Marshalling(parcel) - && parcel.WriteInt32(hasSystemPermission ? static_cast(capturerState) : CAPTURER_INVALID) - && inputDeviceInfo.Marshalling(parcel, hasBTPermission, hasSystemPermission, apiVersion) + && parcel.WriteInt32(static_cast(capturerStateTemp)) + && inputDeviceInfo.Marshalling(parcel) && parcel.WriteBool(muted) && parcel.WriteUint32(appTokenId); } - void Unmarshalling(Parcel &parcel) + void UnmarshallingSelf(Parcel &parcel) { createrUID = parcel.ReadInt32(); clientUID = parcel.ReadInt32(); sessionId = parcel.ReadInt32(); callerPid = parcel.ReadInt32(); clientPid = parcel.ReadInt32(); - capturerInfo.Unmarshalling(parcel); + capturerInfo.UnmarshallingSelf(parcel); capturerState = static_cast(parcel.ReadInt32()); - inputDeviceInfo.Unmarshalling(parcel); + inputDeviceInfo.UnmarshallingSelf(parcel); muted = parcel.ReadBool(); appTokenId = parcel.ReadUint32(); } + + static AudioCapturerChangeInfo *Unmarshalling(Parcel &parcel) + { + auto info = new AudioCapturerChangeInfo(); + if (info == nullptr) { + return nullptr; + } + info->UnmarshallingSelf(parcel); + return info; + } }; -struct AudioStreamChangeInfo { +struct AudioStreamChangeInfo : public Parcelable { AudioRendererChangeInfo audioRendererChangeInfo; AudioCapturerChangeInfo audioCapturerChangeInfo; + + bool Marshalling(Parcel &parcel) const override + { + return audioRendererChangeInfo.Marshalling(parcel) + && audioCapturerChangeInfo.Marshalling(parcel); + } + + static AudioStreamChangeInfo *Unmarshalling(Parcel &parcel) + { + auto info = new AudioStreamChangeInfo(); + if (info == nullptr) { + return nullptr; + } + info->audioRendererChangeInfo.UnmarshallingSelf(parcel); + info->audioCapturerChangeInfo.UnmarshallingSelf(parcel); + return info; + } }; } // namespace AudioStandard } // namespace OHOS diff --git a/interfaces/inner_api/native/audiocommon/include/audio_stream_info.h b/interfaces/inner_api/native/audiocommon/include/audio_stream_info.h index 22d35d7713..6d15354731 100644 --- a/interfaces/inner_api/native/audiocommon/include/audio_stream_info.h +++ b/interfaces/inner_api/native/audiocommon/include/audio_stream_info.h @@ -553,20 +553,20 @@ const std::vector AUDIO_SUPPORTED_STREAM_USAGES { STREAM_USAGE_VOICE_CALL_ASSISTANT, }; -class AudioStreamInfo { +class AudioStreamInfo : public Parcelable { public: AudioSamplingRate samplingRate; AudioEncodingType encoding = AudioEncodingType::ENCODING_PCM; AudioSampleFormat format = AudioSampleFormat::INVALID_WIDTH; AudioChannel channels; AudioChannelLayout channelLayout = AudioChannelLayout::CH_LAYOUT_UNKNOWN; - constexpr AudioStreamInfo(AudioSamplingRate samplingRate_, AudioEncodingType encoding_, AudioSampleFormat format_, + AudioStreamInfo(AudioSamplingRate samplingRate_, AudioEncodingType encoding_, AudioSampleFormat format_, AudioChannel channels_, AudioChannelLayout channelLayout_ = AudioChannelLayout::CH_LAYOUT_UNKNOWN) : samplingRate(samplingRate_), encoding(encoding_), format(format_), channels(channels_), channelLayout(channelLayout_) {} AudioStreamInfo() = default; - bool Marshalling(Parcel &parcel) const + bool Marshalling(Parcel &parcel) const override { return parcel.WriteInt32(static_cast(samplingRate)) && parcel.WriteInt32(static_cast(encoding)) @@ -574,7 +574,8 @@ public: && parcel.WriteInt32(static_cast(channels)) && parcel.WriteInt64(static_cast(channelLayout)); } - void Unmarshalling(Parcel &parcel) + + void UnmarshallingSelf(Parcel &parcel) { samplingRate = static_cast(parcel.ReadInt32()); encoding = static_cast(parcel.ReadInt32()); @@ -582,6 +583,17 @@ public: channels = static_cast(parcel.ReadInt32()); channelLayout = static_cast(parcel.ReadInt64()); } + + static AudioStreamInfo *Unmarshalling(Parcel &parcel) + { + auto info = new AudioStreamInfo(); + if (info == nullptr) { + return nullptr; + } + + info->UnmarshallingSelf(parcel); + return info; + } }; struct AudioStreamData { diff --git a/interfaces/inner_api/native/audiocommon/include/audio_stutter.h b/interfaces/inner_api/native/audiocommon/include/audio_stutter.h index 4893434ed5..4fccde3cb0 100644 --- a/interfaces/inner_api/native/audiocommon/include/audio_stutter.h +++ b/interfaces/inner_api/native/audiocommon/include/audio_stutter.h @@ -36,7 +36,7 @@ enum BadDataTransferType { MAX_DATATRANS_TYPE }; -struct AudioRendererDataTransferStateChangeInfo { +struct AudioRendererDataTransferStateChangeInfo : public Parcelable { int32_t clientPid; // client pid int32_t clientUID; // client uid int32_t sessionId; // session id @@ -47,7 +47,7 @@ struct AudioRendererDataTransferStateChangeInfo { AudioRendererDataTransferStateChangeInfo() = default; ~AudioRendererDataTransferStateChangeInfo() = default; - bool Marshalling(Parcel &parcel) const + bool Marshalling(Parcel &parcel) const override { bool ret = parcel.WriteInt32(clientPid) && parcel.WriteInt32(clientUID) && parcel.WriteInt32(sessionId) && parcel.WriteInt32(static_cast(streamUsage)) && @@ -60,22 +60,28 @@ struct AudioRendererDataTransferStateChangeInfo { return ret; } - void Unmarshalling(Parcel &parcel) + static AudioRendererDataTransferStateChangeInfo *Unmarshalling(Parcel &parcel) { - clientPid = parcel.ReadInt32(); - clientUID = parcel.ReadInt32(); - sessionId = parcel.ReadInt32(); - streamUsage = static_cast(parcel.ReadInt32()); - stateChangeType = static_cast(parcel.ReadInt32()); - isBackground = parcel.ReadBool(); + auto info = new AudioRendererDataTransferStateChangeInfo(); + if (info == nullptr) { + return nullptr; + } + + info->clientPid = parcel.ReadInt32(); + info->clientUID = parcel.ReadInt32(); + info->sessionId = parcel.ReadInt32(); + info->streamUsage = static_cast(parcel.ReadInt32()); + info->stateChangeType = static_cast(parcel.ReadInt32()); + info->isBackground = parcel.ReadBool(); for (uint32_t i = 0; i < MAX_DATATRANS_TYPE; i++) { - badDataRatio[i] = parcel.ReadInt32(); + info->badDataRatio[i] = parcel.ReadInt32(); } + return info; } }; -struct DataTransferMonitorParam { +struct DataTransferMonitorParam : public Parcelable { int32_t clientUID; int32_t badDataTransferTypeBitMap; int64_t timeInterval; @@ -88,19 +94,26 @@ struct DataTransferMonitorParam { return clientUID == param.clientUID && badDataTransferTypeBitMap == param.badDataTransferTypeBitMap && timeInterval == param.timeInterval && badFramesRatio == param.badFramesRatio; } - bool Marshalling(Parcel &parcel) const + + bool Marshalling(Parcel &parcel) const override { - return parcel.WriteInt32(clientUID) - && parcel.WriteInt32(badDataTransferTypeBitMap) - && parcel.WriteInt32(timeInterval) - && parcel.WriteInt32(badFramesRatio); + return parcel.WriteInt32(clientUID) && + parcel.WriteInt32(badDataTransferTypeBitMap) && + parcel.WriteInt32(timeInterval) && + parcel.WriteInt32(badFramesRatio); } - void Unmarshalling(Parcel &parcel) + + static DataTransferMonitorParam *Unmarshalling(Parcel &parcel) { - clientUID = parcel.ReadInt32(); - badDataTransferTypeBitMap = parcel.ReadInt32(); - timeInterval = parcel.ReadInt32(); - badFramesRatio = parcel.ReadInt32(); + auto param = new DataTransferMonitorParam(); + if (param == nullptr) { + return nullptr; + } + param->clientUID = parcel.ReadInt32(); + param->badDataTransferTypeBitMap = parcel.ReadInt32(); + param->timeInterval = parcel.ReadInt32(); + param->badFramesRatio = parcel.ReadInt32(); + return param; } }; } // namespace AudioStandard diff --git a/interfaces/inner_api/native/audiocommon/include/audio_workgroup_ipc.h b/interfaces/inner_api/native/audiocommon/include/audio_workgroup_ipc.h index ef4a77dd6b..ff5190717d 100644 --- a/interfaces/inner_api/native/audiocommon/include/audio_workgroup_ipc.h +++ b/interfaces/inner_api/native/audiocommon/include/audio_workgroup_ipc.h @@ -26,6 +26,30 @@ struct AudioWorkgroupChangeInfo { bool startAllowed; }; +struct AudioWorkgroupChangeInfoIpc : public Parcelable { + AudioWorkgroupChangeInfo changeInfo; + + bool Marshalling(Parcel &parcel) const override + { + return parcel.WriteInt32(changeInfo.pid) && + parcel.WriteUint32(changeInfo.groupId) && + parcel.WriteBool(changeInfo.startAllowed); + } + + static AudioWorkgroupChangeInfoIpc *Unmarshalling(Parcel &parcel) + { + auto info = new AudioWorkgroupChangeInfoIpc(); + if (info == nullptr) { + return nullptr; + } + + info->changeInfo.pid = parcel.ReadInt32(); + info->changeInfo.groupId = parcel.ReadUint32(); + info->changeInfo.startAllowed = parcel.ReadBool(); + return info; + } +}; + } // namespace AudioStandard } // namespace OHOS #endif // AUDIO_WORKGROUP_IPC_H \ No newline at end of file diff --git a/interfaces/inner_api/native/audiocommon/include/microphone_descriptor.h b/interfaces/inner_api/native/audiocommon/include/microphone_descriptor.h index 741eaccdc0..3b519f2e1b 100644 --- a/interfaces/inner_api/native/audiocommon/include/microphone_descriptor.h +++ b/interfaces/inner_api/native/audiocommon/include/microphone_descriptor.h @@ -40,7 +40,7 @@ public: virtual ~MicrophoneDescriptor(); bool Marshalling(Parcel &parcel) const override; - static sptr Unmarshalling(Parcel &in); + static MicrophoneDescriptor *Unmarshalling(Parcel &parcel); void SetMicPositionInfo(const Vector3D &pos); void SetMicOrientationInfo(const Vector3D &orientation); diff --git a/interfaces/inner_api/native/audiomanager/include/audio_policy_interface.h b/interfaces/inner_api/native/audiomanager/include/audio_policy_interface.h index a76b20c7f4..ac49f7e100 100644 --- a/interfaces/inner_api/native/audiomanager/include/audio_policy_interface.h +++ b/interfaces/inner_api/native/audiomanager/include/audio_policy_interface.h @@ -32,10 +32,57 @@ namespace AudioStandard { * * @since 7 */ -struct DeviceChangeAction { +struct DeviceChangeAction : public Parcelable { DeviceChangeType type; DeviceFlag flag; std::vector> deviceDescriptors; + static constexpr int32_t DEVICE_CHANGE_VALID_SIZE = 128; + + void SetClientInfo(std::shared_ptr clientInfo) const + { + for (auto &des : deviceDescriptors) { + if (des != nullptr) { + des->SetClientInfo(clientInfo); + } + } + } + + bool Marshalling(Parcel &parcel) const override + { + parcel.WriteInt32(static_cast(type)); + parcel.WriteInt32(static_cast(flag)); + int32_t size = static_cast(deviceDescriptors.size()); + parcel.WriteInt32(size); + for (auto &des : deviceDescriptors) { + if (des == nullptr) { + return false; + } + des->Marshalling(parcel); + } + return true; + } + + static DeviceChangeAction *Unmarshalling(Parcel &parcel) + { + auto info = new DeviceChangeAction(); + if (info == nullptr) { + return nullptr; + } + + info->type = static_cast(parcel.ReadUint32()); + info->flag = static_cast(parcel.ReadUint32()); + int32_t size = parcel.ReadInt32(); + if (size >= DEVICE_CHANGE_VALID_SIZE) { + delete info; + return nullptr; + } + + for (int32_t i = 0; i < size; i++) { + info->deviceDescriptors.emplace_back( + std::shared_ptr(AudioDeviceDescriptor::Unmarshalling(parcel))); + } + return info; + } }; class AudioFocusInfoChangeCallback { diff --git a/interfaces/inner_api/native/audiomanager/include/audio_system_manager.h b/interfaces/inner_api/native/audiomanager/include/audio_system_manager.h index 0e3796421c..30fbb9f742 100644 --- a/interfaces/inner_api/native/audiomanager/include/audio_system_manager.h +++ b/interfaces/inner_api/native/audiomanager/include/audio_system_manager.h @@ -60,7 +60,7 @@ public: ConnectType type); virtual ~InterruptGroupInfo(); bool Marshalling(Parcel &parcel) const override; - static sptr Unmarshalling(Parcel &parcel); + static InterruptGroupInfo *Unmarshalling(Parcel &parcel); }; class VolumeGroupInfo; @@ -108,7 +108,7 @@ public: * @since 8 * @return Returns volume group info */ - static sptr Unmarshalling(Parcel &parcel); + static VolumeGroupInfo *Unmarshalling(Parcel &parcel); }; /** @@ -116,9 +116,48 @@ public: * * @since 13 */ -struct MicrophoneBlockedInfo { +struct MicrophoneBlockedInfo : public Parcelable { DeviceBlockStatus blockStatus; std::vector> devices; + + void SetClientInfo(std::shared_ptr clientInfo) const + { + for (auto &dev : devices) { + if (dev != nullptr) { + dev->SetClientInfo(clientInfo); + } + } + } + + bool Marshalling(Parcel &parcel) const override + { + parcel.WriteInt32(static_cast(blockStatus)); + int32_t size = static_cast(devices.size()); + parcel.WriteInt32(size); + for (auto &dev : devices) { + if (dev == nullptr) { + return false; + } + dev->Marshalling(parcel); + } + return true; + } + + static MicrophoneBlockedInfo *Unmarshalling(Parcel &parcel) + { + auto info = new MicrophoneBlockedInfo(); + if (info == nullptr) { + return nullptr; + } + + info->blockStatus = static_cast(parcel.ReadInt32()); + int32_t size = parcel.ReadInt32(); + for (int32_t i = 0; i < size; i++) { + info->devices.emplace_back( + std::shared_ptr(AudioDeviceDescriptor::Unmarshalling(parcel))); + } + return info; + } }; /** @@ -137,7 +176,7 @@ public: int32_t streamId = -1; bool Marshalling(Parcel &parcel) const override; - static sptr Unmarshalling(Parcel &in); + static AudioRendererFilter* Unmarshalling(Parcel &parcel); }; /** @@ -154,7 +193,7 @@ public: AudioCapturerInfo capturerInfo = {SOURCE_TYPE_INVALID, 0}; bool Marshalling(Parcel &parcel) const override; - static sptr Unmarshalling(Parcel &in); + static AudioCapturerFilter *Unmarshalling(Parcel &in); }; // AudioManagerCallback OnInterrupt is added to handle compilation error in call manager diff --git a/services/audio_policy/BUILD.gn b/services/audio_policy/BUILD.gn index 03f6717732..87d0509b68 100644 --- a/services/audio_policy/BUILD.gn +++ b/services/audio_policy/BUILD.gn @@ -175,68 +175,49 @@ audio_ohos_library("audio_policy_service") { install_enable = true sources = [ "../audio_service/client/src/audio_filter.cpp", - "../audio_service/client/src/audio_manager_listener_stub.cpp", + "../audio_service/client/src/audio_manager_listener_stub_impl.cpp", "../audio_service/client/src/core_service_provider_stub.cpp", "../audio_service/client/src/microphone_descriptor.cpp", "../audio_service/client/src/policy_provider_stub.cpp", - "server/domain/interrupt/src/audio_interrupt_group_info.cpp", - "server/domain/volume/src/audio_volume_group_info.cpp", - "server/domain/pipe/src/audio_definition_adapter_info.cpp", - "server/domain/pipe/src/audio_definition_policy_utils.cpp", - "server/infra/appclient/src/app_state_listener.cpp", - "server/infra/appclient/src/audio_background_manager.cpp", - "server/infra/appclient/src/audio_bundle_manager.cpp", - "server/infra/appclient/src/client_type_manager.cpp", - "server/infra/appclient/src/client_type_manager_handler.cpp", - "server/infra/async_action_handler/src/audio_policy_async_action_handler.cpp", - "server/infra/config/parser/src/audio_affinity_parser.cpp", - "server/infra/config/parser/src/audio_concurrency_parser.cpp", - "server/infra/config/parser/src/audio_converter_parser.cpp", - "server/infra/config/parser/src/audio_device_parser.cpp", - "server/infra/config/parser/src/audio_effect_config_parser.cpp", - "server/infra/config/parser/src/audio_focus_parser.cpp", - "server/infra/config/parser/src/audio_policy_config_parser.cpp", - "server/infra/config/parser/src/audio_policy_global_parser.cpp", - "server/infra/config/parser/src/audio_policy_parser.cpp", - "server/infra/config/parser/src/audio_strategy_router_parser.cpp", - "server/infra/config/parser/src/audio_usage_strategy_parser.cpp", - "server/infra/config/parser/src/audio_volume_parser.cpp", - "server/infra/datashare/src/audio_policy_utils.cpp", - "server/infra/datashare/src/audio_policy_datashare_listener.cpp", - "server/infra/ipc_proxy/src/audio_ability_manager.cpp", - "server/infra/ipc_proxy/src/audio_server_proxy.cpp", - "server/infra/state_monitor/audio_policy_state_monitor.cpp", - "server/proxy/src/audio_anahs_manager_listener_proxy.cpp", - "server/proxy/src/audio_client_tracker_callback_proxy.cpp", - "server/proxy/src/audio_concurrency_state_listener_proxy.cpp", - "server/proxy/src/audio_policy_client_proxy.cpp", - "server/proxy/src/audio_policy_manager_listener_proxy.cpp", - "server/proxy/src/audio_routing_manager_listener_proxy.cpp", - "server/proxy/src/audio_spatialization_state_change_listener_proxy.cpp", - "server/domain/zone/src/audio_zone_client_proxy.cpp", - "server/proxy/src/sle_audio_operation_callback_proxy.cpp", "server/common/src/audio_group_handle.cpp", - "server/service/service_main/src/audio_policy_server.cpp", - "server/infra/async_action_handler/src/audio_policy_server_handler.cpp", - "server/domain/stream/audio_stream_collector.cpp", - "server/infra/appclient/src/background_task_listener.cpp", + "server/domain/device/src/a2dp/audio_a2dp_device.cpp", + "server/domain/device/src/audio_active_device.cpp", "server/domain/device/src/audio_affinity_manager.cpp", + "server/domain/device/src/audio_connected_device.cpp", + "server/domain/device/src/audio_device_common.cpp", + "server/domain/device/src/audio_device_lock.cpp", "server/domain/device/src/audio_device_manager.cpp", - "server/domain/pipe/src/audio_global_config_manager.cpp", - "server/service/service_main/src/audio_policy_service.cpp", + "server/domain/device/src/audio_device_status.cpp", + "server/domain/device/src/audio_microphone_descriptor.cpp", + "server/domain/device/src/audio_recovery_device.cpp", + "server/domain/device/src/audio_router_map.cpp", + "server/domain/device/src/audio_scene_manager.cpp", "server/domain/device/src/audio_state_manager.cpp", - "server/domain/pipe/src/audio_concurrency_service.cpp", - "server/service/service_main/src/device_init_callback.cpp", + "server/domain/device/src/device_status_listener.cpp", + "server/domain/device/src/sle/sle_audio_device_manager.cpp", + "server/domain/effect/src/audio_collaborative_service.cpp", "server/domain/effect/src/audio_effect_service.cpp", + "server/domain/effect/src/audio_spatialization_service.cpp", "server/domain/interrupt/src/audio_interrupt_dfx_collector.cpp", + "server/domain/interrupt/src/audio_interrupt_group_info.cpp", "server/domain/interrupt/src/audio_interrupt_service.cpp", "server/domain/interrupt/src/audio_interrupt_service_ext.cpp", "server/domain/interrupt/src/audio_interrupt_zone.cpp", - "server/domain/device/src/device_status_listener.cpp", "server/domain/interrupt/src/power_state_listener.cpp", - "server/domain/volume/src/audio_adapter_manager.cpp", - "server/domain/volume/src/audio_adapter_manager_handler.cpp", - "server/domain/volume/src/volume_data_maintainer.cpp", + "server/domain/pipe/src/audio_a2dp_offload_flag.cpp", + "server/domain/pipe/src/audio_a2dp_offload_manager.cpp", + "server/domain/pipe/src/audio_capturer_session.cpp", + "server/domain/pipe/src/audio_concurrency_service.cpp", + "server/domain/pipe/src/audio_config_manager.cpp", + "server/domain/pipe/src/audio_definition_adapter_info.cpp", + "server/domain/pipe/src/audio_definition_policy_utils.cpp", + "server/domain/pipe/src/audio_ec_manager.cpp", + "server/domain/pipe/src/audio_global_config_manager.cpp", + "server/domain/pipe/src/audio_iohandle_map.cpp", + "server/domain/pipe/src/audio_offload_stream.cpp", + "server/domain/pipe/src/audio_pipe_manager.cpp", + "server/domain/pipe/src/audio_pipe_selector.cpp", + "server/domain/pipe/src/audio_policy_config_manager.cpp", "server/domain/router/app_select_router.cpp", "server/domain/router/audio_router_center.cpp", "server/domain/router/cockpit_phone_router.cpp", @@ -247,46 +228,61 @@ audio_ohos_library("audio_policy_service") { "server/domain/router/public_priority_router.cpp", "server/domain/router/stream_filter_router.cpp", "server/domain/router/user_select_router.cpp", - "server/domain/device/src/a2dp/audio_a2dp_device.cpp", - "server/domain/pipe/src/audio_a2dp_offload_flag.cpp", - "server/domain/pipe/src/audio_a2dp_offload_manager.cpp", - "server/domain/device/src/audio_active_device.cpp", - "server/domain/pipe/src/audio_capturer_session.cpp", - "server/domain/pipe/src/audio_config_manager.cpp", - "server/domain/device/src/audio_connected_device.cpp", - "server/domain/device/src/audio_device_common.cpp", - "server/domain/device/src/audio_device_lock.cpp", - "server/domain/device/src/audio_device_status.cpp", - "server/domain/pipe/src/audio_ec_manager.cpp", - "server/domain/pipe/src/audio_iohandle_map.cpp", - "server/domain/device/src/audio_microphone_descriptor.cpp", - "server/domain/pipe/src/audio_offload_stream.cpp", - "server/service/service_main/src/audio_policy_dump.cpp", - "server/domain/device/src/audio_recovery_device.cpp", - "server/domain/device/src/audio_router_map.cpp", - "server/domain/device/src/audio_scene_manager.cpp", - "server/domain/device/src/sle/sle_audio_device_manager.cpp", - "server/domain/tone/audio_tone_manager.cpp", - "server/domain/volume/src/audio_volume_manager.cpp", "server/domain/session/src/audio_session.cpp", "server/domain/session/src/audio_session_service.cpp", "server/domain/session/src/audio_session_state_monitor.cpp", - "server/domain/effect/src/audio_collaborative_service.cpp", - "server/domain/effect/src/audio_spatialization_service.cpp", + "server/domain/stream/audio_stream_collector.cpp", + "server/domain/tone/audio_tone_manager.cpp", + "server/domain/volume/src/audio_adapter_manager.cpp", + "server/domain/volume/src/audio_adapter_manager_handler.cpp", + "server/domain/volume/src/audio_volume_group_info.cpp", + "server/domain/volume/src/audio_volume_manager.cpp", + "server/domain/volume/src/volume_data_maintainer.cpp", "server/domain/zone/src/audio_zone.cpp", "server/domain/zone/src/audio_zone_client_manager.cpp", "server/domain/zone/src/audio_zone_interrupt_reporter.cpp", "server/domain/zone/src/audio_zone_service.cpp", - "server/stub/src/audio_policy_manager_device_stub.cpp", - "server/stub/src/audio_policy_manager_stub.cpp", - "server/stub/src/audio_policy_manager_zone_stub.cpp", - "server/domain/pipe/src/audio_policy_config_manager.cpp", + "server/infra/appclient/src/app_state_listener.cpp", + "server/infra/appclient/src/audio_background_manager.cpp", + "server/infra/appclient/src/audio_bundle_manager.cpp", + "server/infra/appclient/src/background_task_listener.cpp", + "server/infra/appclient/src/client_type_manager.cpp", + "server/infra/appclient/src/client_type_manager_handler.cpp", + "server/infra/async_action_handler/src/audio_policy_async_action_handler.cpp", + "server/infra/async_action_handler/src/audio_policy_server_handler.cpp", + "server/infra/config/parser/src/audio_affinity_parser.cpp", + "server/infra/config/parser/src/audio_concurrency_parser.cpp", + "server/infra/config/parser/src/audio_converter_parser.cpp", + "server/infra/config/parser/src/audio_device_parser.cpp", + "server/infra/config/parser/src/audio_effect_config_parser.cpp", + "server/infra/config/parser/src/audio_focus_parser.cpp", + "server/infra/config/parser/src/audio_policy_config_parser.cpp", + "server/infra/config/parser/src/audio_policy_global_parser.cpp", + "server/infra/config/parser/src/audio_policy_parser.cpp", + "server/infra/config/parser/src/audio_strategy_router_parser.cpp", + "server/infra/config/parser/src/audio_usage_strategy_parser.cpp", + "server/infra/config/parser/src/audio_volume_parser.cpp", + "server/infra/datashare/src/audio_policy_datashare_listener.cpp", + "server/infra/datashare/src/audio_policy_utils.cpp", + "server/infra/ipc_proxy/src/audio_ability_manager.cpp", + "server/infra/ipc_proxy/src/audio_policy_client_holder.cpp", + "server/infra/ipc_proxy/src/audio_server_proxy.cpp", + "server/infra/state_monitor/audio_policy_state_monitor.cpp", "server/service/service_main/src/audio_core_service.cpp", "server/service/service_main/src/audio_core_service_entry.cpp", "server/service/service_main/src/audio_core_service_private.cpp", "server/service/service_main/src/audio_core_service_utils.cpp", - "server/domain/pipe/src/audio_pipe_manager.cpp", - "server/domain/pipe/src/audio_pipe_selector.cpp", + "server/service/service_main/src/audio_policy_dump.cpp", + "server/service/service_main/src/audio_policy_server.cpp", + "server/service/service_main/src/audio_policy_service.cpp", + "server/service/service_main/src/device_init_callback.cpp", + "server/src/audio_client_tracker_callback_listener.cpp", + "server/src/audio_client_tracker_callback_service.cpp", + "server/src/audio_concurrency_state_listener_callback.cpp", + "server/src/audio_concurrency_state_listener_service.cpp", + "server/src/audio_policy_manager_listener.cpp", + "server/src/audio_spatialization_state_change_callback.cpp", + "server/src/audio_spatialization_state_change_listener.cpp", ] defines = [] @@ -329,6 +325,7 @@ audio_ohos_library("audio_policy_service") { public_configs = [ ":audio_policy_public_config" ] deps = [ + "${audio_framework_root}/services/audio_service/idl:audio_framework_interface", "../../frameworks/native/audioadapter:pulse_audio_service_adapter", "../../frameworks/native/audiodefinitions:audio_definitions", "../../frameworks/native/audioinnercall:audio_inner_call", @@ -524,6 +521,7 @@ config("audio_policy_client_config") { include_dirs = [ "client/proxy/include", "client/stub/include", + "client/service/include", "common/include", "client/interface", "server/include", @@ -565,36 +563,34 @@ audio_ohos_library("audio_policy_client") { "../audio_policy/server/domain/device/src/audio_device_descriptor.cpp", "../audio_service/client/src/audio_filter.cpp", "../audio_service/client/src/microphone_descriptor.cpp", - "client/proxy/src/audio_policy_callback_proxy.cpp", - "client/proxy/src/audio_policy_microphone_proxy.cpp", - "client/proxy/src/audio_policy_proxy.cpp", - "client/proxy/src/audio_policy_volume_proxy.cpp", - "client/proxy/src/audio_policy_zone_proxy.cpp", + "client/service/src/audio_anahs_manager_listener.cpp", "client/service/src/audio_policy_manager.cpp", "client/service/src/audio_policy_manager_device.cpp", "client/service/src/audio_policy_manager_zone.cpp", + "client/service/src/audio_routing_manager_listener.cpp", "client/service/src/audio_zone_manager.cpp", - "server/domain/volume/src/audio_volume_group_info.cpp", - "client/stub/src/audio_anahs_manager_listener_stub.cpp", - "client/stub/src/audio_client_tracker_callback_stub.cpp", - "client/stub/src/audio_concurrency_state_listener_stub.cpp", - "client/stub/src/audio_policy_client_stub.cpp", "client/stub/src/audio_policy_client_stub_impl.cpp", - "client/stub/src/audio_policy_manager_listener_stub.cpp", - "client/stub/src/audio_routing_manager_listener_stub.cpp", - "client/stub/src/audio_spatialization_state_change_listener_stub.cpp", + "client/stub/src/audio_policy_manager_listener_stub_impl.cpp", "client/stub/src/audio_zone_client.cpp", - "client/stub/src/sle_audio_operation_callback_stub.cpp", + "client/stub/src/sle_audio_operation_callback_stub_impl.cpp", + "server/domain/volume/src/audio_volume_group_info.cpp", + "server/src/audio_client_tracker_callback_service.cpp", + "server/src/audio_concurrency_state_listener_service.cpp", + "server/src/audio_spatialization_state_change_listener.cpp", ] deps = [ + "${audio_framework_root}/services/audio_service/idl:audio_framework_interface", "../../frameworks/native/audiodefinitions:audio_definitions", "../../frameworks/native/audioutils:audio_utils", ] public_configs = [ ":audio_policy_client_config" ] - include_dirs = [ "../../frameworks/native/audioutils/include" ] + include_dirs = [ + "../../frameworks/native/audioutils/include", + "${audio_framework_root}/services/audio_service/common/include/", + ] external_deps = [ "bounds_checking_function:libsec_shared", @@ -715,7 +711,11 @@ ohos_shared_library("audio_foundation") { "server/domain/effect/src/audio_effect_map.cpp", ] - public_configs = [ ":audio_foundation_public_config" ] + public_configs = [ + ":audio_foundation_public_config", + "${audio_framework_root}/services/audio_service/idl:audio_service_sa_idl_config", + "${audio_framework_root}/services/audio_service/idl:audio_policy_sa_idl_config", + ] deps = [ "../../frameworks/native/audioutils:audio_utils", @@ -847,9 +847,7 @@ ohos_shared_library("audio_policy_common") { } config("audio_policy_ipc_config") { - include_dirs = [ - "common/include", - ] + include_dirs = [ "common/include" ] } ohos_shared_library("audio_policy_ipc") { diff --git a/services/audio_policy/client/interface/audio_policy_base.h b/services/audio_policy/client/interface/audio_policy_base.h deleted file mode 100644 index de2e10fd50..0000000000 --- a/services/audio_policy/client/interface/audio_policy_base.h +++ /dev/null @@ -1,544 +0,0 @@ -/* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef I_AUDIO_POLICY_BASE_H -#define I_AUDIO_POLICY_BASE_H - -#include "audio_interrupt_callback.h" -#include "audio_policy_ipc_interface_code.h" -#include "ipc_types.h" -#include "iremote_broker.h" -#include "iremote_proxy.h" -#include "iremote_stub.h" -#include "audio_system_manager.h" -#include "audio_effect.h" -#include "microphone_descriptor.h" -#include "audio_zone_manager.h" -#include "audio_stream_descriptor.h" - -namespace OHOS { -namespace AudioStandard { -using InternalDeviceType = DeviceType; -using InternalAudioCapturerOptions = AudioCapturerOptions; - -class IAudioPolicy : public IRemoteBroker { -public: - - virtual int32_t GetMaxVolumeLevel(AudioVolumeType volumeType) = 0; - - virtual int32_t GetMinVolumeLevel(AudioVolumeType volumeType) = 0; - - virtual int32_t SetSystemVolumeLevelLegacy(AudioVolumeType volumeType, int32_t volumeLevel) = 0; - - virtual int32_t SetSystemVolumeLevel(AudioVolumeType volumeType, int32_t volumeLevel, int32_t volumeFlag = 0, - int32_t uid = 0) = 0; - - virtual int32_t SetSystemVolumeLevelWithDevice(AudioVolumeType volumeType, int32_t volumeLevel, - DeviceType deviceType, int32_t volumeFlag = 0) = 0; - - virtual int32_t GetAppVolumeLevel(int32_t appUid, int32_t &volumeLevel) = 0; - - virtual int32_t GetSelfAppVolumeLevel(int32_t &volumeLevel) = 0; - - virtual int32_t SetAppVolumeLevel(int32_t appUid, int32_t volumeLevel, int32_t volumeFlag = 0) = 0; - - virtual int32_t IsAppVolumeMute(int32_t appUid, bool muted, bool &isMute) = 0; - - virtual int32_t SetAppVolumeMuted(int32_t appUid, bool muted, int32_t volumeFlag = 0) = 0; - - virtual int32_t SetAdjustVolumeForZone(int32_t zoneId) = 0; - - virtual int32_t SetSelfAppVolumeLevel(int32_t volumeLevel, int32_t volumeFlag = 0) = 0; - - virtual AudioStreamType GetSystemActiveVolumeType(const int32_t clientUid) = 0; - - virtual int32_t GetSystemVolumeLevel(AudioVolumeType volumeType, int32_t uid) = 0; - - virtual int32_t SetLowPowerVolume(int32_t streamId, float volume) = 0; - - virtual AudioStreamInfo GetFastStreamInfo() = 0; - - virtual float GetLowPowerVolume(int32_t streamId) = 0; - - virtual float GetSingleStreamVolume(int32_t streamId) = 0; - - virtual int32_t SetStreamMuteLegacy(AudioVolumeType volumeType, bool mute, - const DeviceType &deviceType = DEVICE_TYPE_NONE) = 0; - - virtual int32_t SetStreamMute(AudioVolumeType volumeType, bool mute, - const DeviceType &deviceType = DEVICE_TYPE_NONE) = 0; - - virtual bool GetStreamMute(AudioVolumeType volumeType) = 0; - - virtual bool IsStreamActive(AudioVolumeType volumeType) = 0; - - virtual bool IsStreamActiveByStreamUsage(StreamUsage streamUsage) = 0; - - virtual bool IsFastPlaybackSupported(AudioStreamInfo &streamInfo, StreamUsage usage) = 0; - virtual bool IsFastRecordingSupported(AudioStreamInfo &streamInfo, SourceType source) = 0; - - virtual std::vector> GetDevices(DeviceFlag deviceFlag) = 0; - - virtual std::vector> GetDevicesInner(DeviceFlag deviceFlag) = 0; - - virtual std::vector> GetOutputDevice( - sptr audioRendererFilter) = 0; - - virtual std::vector> GetInputDevice( - sptr audioCapturerFilter) = 0; - - virtual int32_t SetDeviceActive(InternalDeviceType deviceType, bool active, const int32_t uid = INVALID_UID) = 0; - - virtual bool IsDeviceActive(InternalDeviceType deviceType) = 0; - - virtual DeviceType GetActiveOutputDevice() = 0; - - virtual uint16_t GetDmDeviceType() = 0; - - virtual DeviceType GetActiveInputDevice() = 0; - -#ifdef FEATURE_DTMF_TONE - virtual std::shared_ptr GetToneConfig(int32_t ltonetype, const std::string &countryCode) = 0; - - virtual std::vector GetSupportedTones(const std::string &countryCode) = 0; -#endif - - virtual int32_t SetRingerModeLegacy(AudioRingerMode ringMode) = 0; - - virtual int32_t SetRingerMode(AudioRingerMode ringMode) = 0; - - virtual AudioRingerMode GetRingerMode() = 0; - - virtual int32_t SetAudioScene(AudioScene scene) = 0; - - virtual int32_t SetMicrophoneMute(bool isMute) = 0; - - virtual int32_t SetMicrophoneMuteAudioConfig(bool isMute) = 0; - - virtual int32_t SetMicrophoneMutePersistent(const bool isMute, const PolicyType type) = 0; - - virtual bool GetPersistentMicMuteState() = 0; - - virtual bool IsMicrophoneMuteLegacy() = 0; - - virtual bool IsMicrophoneMute() = 0; - - virtual AudioScene GetAudioScene() = 0; - - virtual int32_t ActivateAudioSession(const AudioSessionStrategy &strategy) = 0; - - virtual int32_t DeactivateAudioSession() = 0; - - virtual bool IsAudioSessionActivated() = 0; - - virtual int32_t SetAudioSessionScene(const AudioSessionScene audioSessionScene) = 0; - - virtual int32_t GetDefaultOutputDevice(DeviceType &deviceType) = 0; - - virtual int32_t SetDefaultOutputDevice(DeviceType deviceType) = 0; - - virtual int32_t SetAudioInterruptCallback(const uint32_t sessionID, const sptr &object, - uint32_t clientUid, const int32_t zoneID = 0 /* default value: 0 -- local device */) = 0; - - virtual int32_t UnsetAudioInterruptCallback(const uint32_t sessionID, - const int32_t zoneID = 0 /* default value: 0 -- local device */) = 0; - - virtual int32_t ActivateAudioInterrupt(AudioInterrupt &audioInterrupt, - const int32_t zoneID = 0 /* default value: 0 -- local device */, - const bool isUpdatedAudioStrategy = false /* default value: false -- is update audio strategy */) = 0; - - virtual int32_t DeactivateAudioInterrupt(const AudioInterrupt &audioInterrupt, - const int32_t zoneID = 0 /* default value: 0 -- local device */) = 0; - - virtual int32_t ActivatePreemptMode(void) = 0; - - virtual int32_t DeactivatePreemptMode(void) = 0; - - virtual int32_t SetAudioManagerInterruptCallback(const int32_t clientId, const sptr &object) = 0; - - virtual int32_t UnsetAudioManagerInterruptCallback(const int32_t clientId) = 0; - - virtual int32_t SetQueryClientTypeCallback(const sptr &object) = 0; - - virtual int32_t SetAudioClientInfoMgrCallback(const sptr &object) = 0; - - virtual int32_t SetAudioVKBInfoMgrCallback(const sptr &object) = 0; - - virtual int32_t CheckVKBInfo(const std::string &bundleName, bool &isValid) = 0; - - virtual int32_t SetQueryBundleNameListCallback(const sptr &object) = 0; - - virtual int32_t RequestAudioFocus(const int32_t clientId, const AudioInterrupt &audioInterrupt) = 0; - - virtual int32_t AbandonAudioFocus(const int32_t clientId, const AudioInterrupt &audioInterrupt) = 0; - - virtual AudioStreamType GetStreamInFocus(const int32_t zoneID = 0 /* default value: 0 -- local device */) = 0; - - virtual AudioStreamType GetStreamInFocusByUid( - const int32_t uid, const int32_t zoneID = 0 /* default value: 0 -- local device */) = 0; - - virtual int32_t GetSessionInfoInFocus(AudioInterrupt &audioInterrupt, - const int32_t zoneID = 0 /* default value: 0 -- local device */) = 0; - - virtual int32_t ReconfigureAudioChannel(const uint32_t &count, DeviceType deviceType) = 0; - - virtual int32_t GetPreferredOutputStreamType(AudioRendererInfo &rendererInfo) = 0; - - virtual int32_t GetPreferredInputStreamType(AudioCapturerInfo &capturerInfo) = 0; - - virtual int32_t CreateRendererClient( - std::shared_ptr streamDesc, uint32_t &flag, uint32_t &sessionId) = 0; - - virtual int32_t CreateCapturerClient( - std::shared_ptr streamDesc, uint32_t &flag, uint32_t &sessionId) = 0; - - virtual int32_t RegisterTracker(AudioMode &mode, - AudioStreamChangeInfo &streamChangeInfo, const sptr &object) = 0; - - virtual int32_t UpdateTracker(AudioMode &mode, AudioStreamChangeInfo &streamChangeInfo) = 0; - - virtual int32_t GetCurrentRendererChangeInfos( - std::vector> &audioRendererChangeInfos) = 0; - - virtual int32_t GetCurrentCapturerChangeInfos( - std::vector> &audioCapturerChangeInfos) = 0; - - virtual int32_t UpdateStreamState(const int32_t clientUid, StreamSetState streamSetState, - StreamUsage streamUsage) = 0; - - virtual int32_t SelectOutputDevice(sptr audioRendererFilter, - std::vector> audioDeviceDescriptors) = 0; - - virtual std::string GetSelectedDeviceInfo(int32_t uid, int32_t pid, AudioStreamType streamType) = 0; - - virtual int32_t SelectInputDevice(sptr audioCapturerFilter, - std::vector> audioDeviceDescriptors) = 0; - - virtual int32_t ExcludeOutputDevices(AudioDeviceUsage audioDevUsage, - std::vector> &audioDeviceDescriptors) = 0; - - virtual int32_t UnexcludeOutputDevices(AudioDeviceUsage audioDevUsage, - std::vector> &audioDeviceDescriptors) = 0; - - virtual std::vector> GetExcludedDevices( - AudioDeviceUsage audioDevUsage) = 0; - - virtual int32_t GetVolumeGroupInfos(std::string networkId, std::vector> &infos) = 0; - - virtual int32_t GetNetworkIdByGroupId(int32_t groupId, std::string &networkId) = 0; - - virtual std::vector> GetPreferredOutputDeviceDescriptors( - AudioRendererInfo &rendererInfo, bool forceNoBTPermission) = 0; - - virtual std::vector> GetPreferredInputDeviceDescriptors( - AudioCapturerInfo &captureInfo) = 0; - - virtual int32_t SetClientCallbacksEnable(const CallbackChange &callbackchange, const bool &enable) = 0; - - virtual int32_t SetCallbackRendererInfo(const AudioRendererInfo &rendererInfo) = 0; - - virtual int32_t SetCallbackCapturerInfo(const AudioCapturerInfo &capturerInfo) = 0; - - virtual int32_t GetAudioFocusInfoList(std::list> &focusInfoList, - const int32_t zoneID = 0 /* default value: 0 -- local device */) = 0; - - virtual int32_t SetSystemSoundUri(const std::string &key, const std::string &uri) = 0; - - virtual std::string GetSystemSoundUri(const std::string &key) = 0; - - virtual float GetMinStreamVolume(void) = 0; - - virtual float GetMaxStreamVolume(void) = 0; - - virtual int32_t GetMaxRendererInstances() = 0; - - virtual bool IsVolumeUnadjustable(void) = 0; - - virtual int32_t AdjustVolumeByStep(VolumeAdjustType adjustType) = 0; - - virtual int32_t AdjustSystemVolumeByStep(AudioVolumeType volumeType, VolumeAdjustType adjustType) = 0; - - virtual float GetSystemVolumeInDb(AudioVolumeType volumeType, int32_t volumeLevel, DeviceType deviceType) = 0; - - virtual int32_t QueryEffectSceneMode(SupportedEffectConfig &supportedEffectConfig) = 0; - - virtual int32_t GetHardwareOutputSamplingRate(const std::shared_ptr &desc) = 0; - - virtual std::vector> GetAudioCapturerMicrophoneDescriptors(int32_t sessionId) = 0; - - virtual std::vector> GetAvailableMicrophones() = 0; - - virtual int32_t SetDeviceAbsVolumeSupported(const std::string &macAddress, const bool support) = 0; - - virtual bool IsAbsVolumeScene() = 0; - - virtual int32_t SetA2dpDeviceVolume(const std::string &macAddress, const int32_t volume, bool updateUi) = 0; - - virtual int32_t SetNearlinkDeviceVolume(const std::string &macAddress, AudioVolumeType volumeType, - const int32_t volume, bool updateUi) = 0; - - virtual std::vector> GetAvailableDevices(AudioDeviceUsage usage) = 0; - - virtual int32_t SetAvailableDeviceChangeCallback(const int32_t clientId, const AudioDeviceUsage usage, - const sptr &object) = 0; - - virtual int32_t UnsetAvailableDeviceChangeCallback(const int32_t clientId, AudioDeviceUsage usage) = 0; - - virtual int32_t ConfigDistributedRoutingRole( - const std::shared_ptr descriptor, CastType type) = 0; - - virtual int32_t SetDistributedRoutingRoleCallback(const sptr &object) = 0; - - virtual int32_t UnsetDistributedRoutingRoleCallback() = 0; - - virtual bool IsSpatializationEnabled() = 0; - - virtual bool IsSpatializationEnabled(const std::string address) = 0; - - virtual bool IsSpatializationEnabledForCurrentDevice() = 0; - - virtual int32_t SetSpatializationEnabled(const bool enable) = 0; - - virtual int32_t SetSpatializationEnabled(const std::shared_ptr &selectedAudioDevice, - const bool enable) = 0; - - virtual bool IsHeadTrackingEnabled() = 0; - - virtual bool IsHeadTrackingEnabled(const std::string address) = 0; - - virtual int32_t SetHeadTrackingEnabled(const bool enable) = 0; - - virtual int32_t SetHeadTrackingEnabled(const std::shared_ptr &selectedAudioDevice, - const bool enable) = 0; - - virtual AudioSpatializationState GetSpatializationState(const StreamUsage streamUsage) = 0; - - virtual bool IsSpatializationSupported() = 0; - - virtual bool IsSpatializationSupportedForDevice(const std::string address) = 0; - - virtual bool IsHeadTrackingSupported() = 0; - - virtual bool IsHeadTrackingSupportedForDevice(const std::string address) = 0; - - virtual int32_t UpdateSpatialDeviceState(const AudioSpatialDeviceState audioSpatialDeviceState) = 0; - - virtual int32_t RegisterSpatializationStateEventListener(const uint32_t sessionID, const StreamUsage streamUsage, - const sptr &object) = 0; - - virtual int32_t UnregisterSpatializationStateEventListener(const uint32_t sessionID) = 0; - - virtual int32_t RegisterPolicyCallbackClient(const sptr &object, - const int32_t zoneID = 0 /* default value: 0 -- local device */) = 0; - - virtual int32_t CreateAudioInterruptZone(const std::set &pids, - const int32_t zoneID = 0 /* default value: 0 -- local device */) = 0; - - virtual int32_t AddAudioInterruptZonePids(const std::set &pids, - const int32_t zoneID = 0 /* default value: 0 -- local device */) = 0; - - virtual int32_t RemoveAudioInterruptZonePids(const std::set &pids, - const int32_t zoneID = 0 /* default value: 0 -- local device */) = 0; - - virtual int32_t ReleaseAudioInterruptZone(const int32_t zoneID = 0 /* default value: 0 -- local device */) = 0; - - virtual int32_t RegisterAudioZoneClient(const sptr& object) = 0; - - virtual int32_t CreateAudioZone(const std::string &name, const AudioZoneContext &context) = 0; - - virtual void ReleaseAudioZone(int32_t zoneId) = 0; - - virtual const std::vector> GetAllAudioZone() = 0; - - virtual const std::shared_ptr GetAudioZone(int32_t zoneId) = 0; - - virtual int32_t BindDeviceToAudioZone(int32_t zoneId, - std::vector> devices) = 0; - - virtual int32_t UnBindDeviceToAudioZone(int32_t zoneId, - std::vector> devices) = 0; - - virtual int32_t EnableAudioZoneReport (bool enable) = 0; - - virtual int32_t EnableAudioZoneChangeReport(int32_t zoneId, bool enable) = 0; - - virtual int32_t AddUidToAudioZone(int32_t zoneId, int32_t uid) = 0; - - virtual int32_t RemoveUidFromAudioZone(int32_t zoneId, int32_t uid) = 0; - - virtual int32_t AddStreamToAudioZone(int32_t zoneId, AudioZoneStream stream) = 0; - - virtual int32_t RemoveStreamFromAudioZone(int32_t zoneId, AudioZoneStream stream) = 0; - - virtual void SetZoneDeviceVisible(bool visible) = 0; - - virtual int32_t EnableSystemVolumeProxy(int32_t zoneId, bool enable) = 0; - - virtual std::list> GetAudioInterruptForZone(int32_t zoneId) = 0; - - virtual std::list> GetAudioInterruptForZone( - int32_t zoneId, const std::string &deviceTag) = 0; - - virtual int32_t EnableAudioZoneInterruptReport(int32_t zoneId, const std::string &deviceTag, bool enable) = 0; - - virtual int32_t InjectInterruptToAudioZone(int32_t zoneId, - const std::list> &interrupts) = 0; - - virtual int32_t InjectInterruptToAudioZone(int32_t zoneId, const std::string &deviceTag, - const std::list> &interrupts) = 0; - - virtual int32_t SetCallDeviceActive(InternalDeviceType deviceType, bool active, std::string address, - const int32_t uid = INVALID_UID) = 0; - - virtual std::shared_ptr GetActiveBluetoothDevice() = 0; - - virtual ConverterConfig GetConverterConfig() = 0; - - virtual void FetchOutputDeviceForTrack(AudioStreamChangeInfo &streamChangeInfo, - const AudioStreamDeviceChangeReasonExt reason) = 0; - - virtual void FetchInputDeviceForTrack(AudioStreamChangeInfo &streamChangeInfo) = 0; - - virtual bool IsHighResolutionExist(void) = 0; - - virtual int32_t SetHighResolutionExist(bool highResExist) = 0; - - virtual AudioSpatializationSceneType GetSpatializationSceneType() = 0; - - virtual int32_t SetSpatializationSceneType(const AudioSpatializationSceneType spatializationSceneType) = 0; - - virtual float GetMaxAmplitude(const int32_t deviceId) = 0; - - virtual int32_t DisableSafeMediaVolume() = 0; - - virtual bool IsHeadTrackingDataRequested(const std::string &macAddress) = 0; - - virtual int32_t SetAudioDeviceRefinerCallback(const sptr &object) = 0; - - virtual int32_t UnsetAudioDeviceRefinerCallback() = 0; - - virtual int32_t TriggerFetchDevice(AudioStreamDeviceChangeReasonExt reason) = 0; - - virtual int32_t SetPreferredDevice(const PreferredType preferredType, - const std::shared_ptr &desc, const int32_t uid = INVALID_UID) = 0; - - virtual int32_t SetAudioDeviceAnahsCallback(const sptr &object) = 0; - - virtual int32_t UnsetAudioDeviceAnahsCallback() = 0; - - virtual int32_t SetAudioConcurrencyCallback(const uint32_t sessionID, const sptr &object) = 0; - - virtual int32_t UnsetAudioConcurrencyCallback(const uint32_t sessionID) = 0; - - virtual int32_t ActivateAudioConcurrency(const AudioPipeType &pipeType) = 0; - - virtual int32_t MoveToNewPipe(const uint32_t sessionId, const AudioPipeType pipeType) = 0; - - virtual int32_t InjectInterruption(const std::string networkId, InterruptEvent &event) = 0; - - virtual int32_t LoadSplitModule(const std::string &splitArgs, const std::string &networkId) = 0; - - virtual int32_t SetInputDevice(const DeviceType deviceType, const uint32_t session_ID, - const SourceType sourceType, bool isRunning) = 0; - - virtual bool IsAllowedPlayback(const int32_t &uid, const int32_t &pid) = 0; - - virtual int32_t SetVoiceRingtoneMute(bool isMute) = 0; - - virtual int32_t NotifySessionStateChange(const int32_t uid, const int32_t pid, const bool hasSession) = 0; - - virtual int32_t NotifyFreezeStateChange(const std::set &pidList, const bool isFreeze) = 0; - - virtual int32_t ResetAllProxy() = 0; - - virtual int32_t NotifyProcessBackgroundState(const int32_t uid, const int32_t pid) = 0; - - virtual void SaveRemoteInfo(const std::string &networkId, DeviceType deviceType) = 0; - - virtual int32_t SetDeviceConnectionStatus(const std::shared_ptr &desc, - const bool isConnected) = 0; - - virtual int32_t GetSupportedAudioEffectProperty(AudioEffectPropertyArrayV3 &propertyArray) = 0; - - virtual int32_t SetAudioEffectProperty(const AudioEffectPropertyArrayV3 &propertyArray) = 0; - - virtual int32_t GetAudioEffectProperty(AudioEffectPropertyArrayV3 &propertyArray) = 0; - - virtual int32_t GetSupportedAudioEffectProperty(AudioEffectPropertyArray &propertyArray) = 0; - - virtual int32_t GetSupportedAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray) = 0; - - virtual int32_t SetAudioEffectProperty(const AudioEffectPropertyArray &propertyArray) = 0; - - virtual int32_t GetAudioEffectProperty(AudioEffectPropertyArray &propertyArray) = 0; - - virtual int32_t SetAudioEnhanceProperty(const AudioEnhancePropertyArray &propertyArray) = 0; - - virtual int32_t GetAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray) = 0; - - virtual int32_t SetVirtualCall(const bool isVirtual) = 0; - - virtual int32_t SetQueryAllowedPlaybackCallback(const sptr &object) = 0; - - virtual int32_t SetBackgroundMuteCallback(const sptr &object) = 0; - - virtual DirectPlaybackMode GetDirectPlaybackSupport(const AudioStreamInfo &streamInfo, - const StreamUsage &streamUsage) = 0; - - virtual bool IsAcousticEchoCancelerSupported(SourceType sourceType) = 0; - - virtual bool IsAudioLoopbackSupported(AudioLoopbackMode mode) = 0; - - virtual int32_t ForceStopAudioStream(StopAudioType audioType) = 0; - - virtual bool IsCapturerFocusAvailable(const AudioCapturerInfo &capturerInfo) = 0; - - virtual bool SetKaraokeParameters(const std::string ¶meters) = 0; - - virtual int32_t GetMaxVolumeLevelByUsage(StreamUsage streamUsage) = 0; - - virtual int32_t GetMinVolumeLevelByUsage(StreamUsage streamUsage) = 0; - - virtual int32_t GetVolumeLevelByUsage(StreamUsage streamUsage) = 0; - - virtual bool GetStreamMuteByUsage(StreamUsage streamUsage) = 0; - - virtual float GetVolumeInDbByStream(StreamUsage streamUsage, int32_t volumeLevel, DeviceType deviceType) = 0; - - virtual std::vector GetSupportedAudioVolumeTypes() = 0; - - virtual AudioVolumeType GetAudioVolumeTypeByStreamUsage(StreamUsage streamUsage) = 0; - - virtual std::vector GetStreamUsagesByVolumeType(AudioVolumeType audioVolumeType) = 0; - - virtual int32_t SetCallbackStreamUsageInfo(const std::set &streamUsages) = 0; - - virtual int32_t UpdateDeviceInfo(const std::shared_ptr &deviceDesc, - const DeviceInfoUpdateCommand command) = 0; - virtual int32_t SetSleAudioOperationCallback(const sptr &object) = 0; - - virtual bool IsCollaborativePlaybackSupported() = 0; - - virtual int32_t SetCollaborativePlaybackEnabledForDevice( - const std::shared_ptr &selectedAudioDevice, bool enabled) = 0; - - virtual bool IsCollaborativePlaybackEnabledForDevice( - const std::shared_ptr &selectedAudioDevice) = 0; -public: - DECLARE_INTERFACE_DESCRIPTOR(u"IAudioPolicy"); -}; -} // namespace AudioStandard -} // namespace OHOS -#endif // I_AUDIO_POLICY_BASE_H diff --git a/services/audio_policy/client/interface/audio_policy_client.h b/services/audio_policy/client/interface/audio_policy_client.h index db427747e0..4d2ce3813f 100644 --- a/services/audio_policy/client/interface/audio_policy_client.h +++ b/services/audio_policy/client/interface/audio_policy_client.h @@ -16,13 +16,7 @@ #ifndef ST_AUDIO_POLICY_CLIENT_H #define ST_AUDIO_POLICY_CLIENT_H -#include "ipc_types.h" -#include "iremote_broker.h" -#include "iremote_proxy.h" -#include "iremote_stub.h" -#include "audio_system_manager.h" -#include "audio_interrupt_info.h" -#include "audio_stream_manager.h" +#include namespace OHOS { namespace AudioStandard { @@ -62,55 +56,6 @@ enum class AudioPolicyClientCode { ON_AUDIO_SESSION_STATE_CHANGED, AUDIO_POLICY_CLIENT_CODE_MAX = ON_AUDIO_SESSION_STATE_CHANGED, }; -class IAudioPolicyClient : public IRemoteBroker { -public: - virtual void OnVolumeKeyEvent(VolumeEvent volumeEvent) = 0; - virtual void OnAudioFocusInfoChange(const std::list> &focusInfoList) = 0; - virtual void OnAudioFocusRequested(const AudioInterrupt &requestFocus) = 0; - virtual void OnAudioFocusAbandoned(const AudioInterrupt &abandonFocus) = 0; - virtual void OnDeviceChange(const DeviceChangeAction &deviceChangeAction) = 0; - virtual void OnMicrophoneBlocked(const MicrophoneBlockedInfo µphoneBlockedInfo) = 0; - virtual void OnRingerModeUpdated(const AudioRingerMode &ringerMode) = 0; - virtual void OnAppVolumeChanged(int32_t appUid, const VolumeEvent& volumeEvent) = 0; - virtual void OnActiveVolumeTypeChanged(const AudioVolumeType& volumeType) = 0; - virtual void OnMicStateUpdated(const MicStateChangeEvent &micStateChangeEvent) = 0; - virtual void OnPreferredOutputDeviceUpdated(const AudioRendererInfo &rendererInfo, - const std::vector> &desc) = 0; - virtual void OnPreferredInputDeviceUpdated(const AudioCapturerInfo &capturerInfo, - const std::vector> &desc) = 0; - virtual void OnRendererStateChange( - std::vector> &audioRendererChangeInfos) = 0; - virtual void OnCapturerStateChange( - std::vector> &audioCapturerChangeInfos) = 0; - virtual void OnRendererDeviceChange(const uint32_t sessionId, - const AudioDeviceDescriptor &deviceInfo, const AudioStreamDeviceChangeReasonExt reason) = 0; - virtual void OnRecreateRendererStreamEvent(const uint32_t sessionId, const int32_t streamFlag, - const AudioStreamDeviceChangeReasonExt reason) = 0; - virtual void OnRecreateCapturerStreamEvent(const uint32_t sessionId, const int32_t streamFlag, - const AudioStreamDeviceChangeReasonExt reason) = 0; - virtual void OnHeadTrackingDeviceChange(const std::unordered_map &changeInfo) = 0; - virtual void OnSpatializationEnabledChange(const bool &enabled) = 0; - virtual void OnSpatializationEnabledChangeForAnyDevice( - const std::shared_ptr &deviceDescriptor, const bool &enabled) = 0; - virtual void OnSpatializationEnabledChangeForCurrentDevice(const bool &enabled) = 0; - virtual void OnHeadTrackingEnabledChange(const bool &enabled) = 0; - virtual void OnHeadTrackingEnabledChangeForAnyDevice( - const std::shared_ptr &deviceDescriptor, const bool &enabled) = 0; - virtual void OnNnStateChange(const int32_t &nnState) = 0; - virtual void OnAudioSessionDeactive(const AudioSessionDeactiveEvent &deactiveEvent) = 0; - virtual void OnAudioSessionStateChanged(const AudioSessionStateChangedEvent &stateChangedEvent) = 0; - virtual void OnAudioSceneChange(const AudioScene &audioScene) = 0; - virtual void OnFormatUnsupportedError(const AudioErrors &errorCode) = 0; - virtual void OnStreamVolumeChange(StreamVolumeEvent streamVolumeEvent) = 0; - virtual void OnSystemVolumeChange(VolumeEvent volumeEvent) = 0; - - bool hasBTPermission_ = true; - bool hasSystemPermission_ = true; - int32_t apiVersion_ = API_VERSION_MAX; - -public: - DECLARE_INTERFACE_DESCRIPTOR(u"IAudioPolicyClient"); -}; } // namespace AudioStandard } // namespace OHOS #endif // ST_AUDIO_POLICY_CLIENT_H diff --git a/services/audio_policy/client/interface/i_standard_audio_anahs_manager_listener.h b/services/audio_policy/client/interface/i_standard_audio_anahs_manager_listener.h deleted file mode 100644 index e46edcf6b5..0000000000 --- a/services/audio_policy/client/interface/i_standard_audio_anahs_manager_listener.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef I_STANDARD_AUDIO_ANAHS_MANAGER_LISTENER_H -#define I_STANDARD_AUDIO_ANAHS_MANAGER_LISTENER_H - -#include "ipc_types.h" -#include "iremote_broker.h" -#include "iremote_proxy.h" -#include "iremote_stub.h" - -namespace OHOS { -namespace AudioStandard { -class IStandardAudioAnahsManagerListener : public IRemoteBroker, public AudioDeviceAnahs { -public: - virtual ~IStandardAudioAnahsManagerListener() = default; - - enum AudioRingerModeUpdateListenerMsg { - ON_ERROR = 0, - ON_AUDIO_ANAHS_DEVICE_CHANGE, - }; - - DECLARE_INTERFACE_DESCRIPTOR(u"IStandardAudioAnahsManagerListener"); -}; -} // namespace AudioStandard -} // namespace OHOS -#endif // I_STANDARD_AUDIO_ANAHS_MANAGER_LISTENER_H diff --git a/services/audio_policy/client/interface/i_standard_audio_policy_manager_listener.h b/services/audio_policy/client/interface/i_standard_audio_policy_manager_listener.h deleted file mode 100644 index cdfecdf8b7..0000000000 --- a/services/audio_policy/client/interface/i_standard_audio_policy_manager_listener.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef I_STANDARD_AUDIO_POLICY_MANAGER_LISTENER_H -#define I_STANDARD_AUDIO_POLICY_MANAGER_LISTENER_H - -#include "ipc_types.h" -#include "iremote_broker.h" -#include "iremote_proxy.h" -#include "iremote_stub.h" - -namespace OHOS { -namespace AudioStandard { -class IStandardAudioPolicyManagerListener : public IRemoteBroker { -public: - virtual ~IStandardAudioPolicyManagerListener() = default; - virtual void OnInterrupt(const InterruptEventInternal &interruptEvent) = 0; - virtual void OnAvailableDeviceChange(const AudioDeviceUsage usage, - const DeviceChangeAction &deviceChangeAction) = 0; - virtual bool OnQueryClientType(const std::string &bundleName, uint32_t uid) = 0; - virtual bool OnCheckClientInfo(const std::string &bundleName, int32_t &uid, int32_t pid) = 0; - virtual bool OnCheckVKBInfo(const std::string &bundleName) = 0; - virtual bool OnQueryAllowedPlayback(int32_t uid, int32_t pid) = 0; - virtual void OnBackgroundMute(const int32_t uid) = 0; - virtual bool OnQueryBundleNameIsInList(const std::string &bundleName, const std::string &listType) = 0; - - bool hasBTPermission_ = true; - bool hasSystemPermission_ = true; - - enum AudioPolicyManagerListenerMsg { - ON_ERROR = 0, - ON_INTERRUPT, - ON_AVAILABLE_DEVICE_CAHNGE, - ON_QUERY_CLIENT_TYPE, - ON_CHECK_CLIENT_INFO, - ON_QUERY_ALLOWED_PLAYBACK, - ON_BACKGROUND_MUTE, - ON_QUERY_BUNDLE_NAME_LIST, - ON_CHECK_VKB_INFO, - }; - DECLARE_INTERFACE_DESCRIPTOR(u"IStandardAudioManagerListener"); -}; -} // namespace AudioStandard -} // namespace OHOS -#endif // I_STANDARD_AUDIO_POLICY_MANAGER_LISTENER_H diff --git a/services/audio_policy/client/interface/i_standard_audio_routing_manager_listener.h b/services/audio_policy/client/interface/i_standard_audio_routing_manager_listener.h deleted file mode 100644 index c49caf4be4..0000000000 --- a/services/audio_policy/client/interface/i_standard_audio_routing_manager_listener.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef I_STANDARD_AUDIO_ROUTING_MANAGER_LISTENER_H -#define I_STANDARD_AUDIO_ROUTING_MANAGER_LISTENER_H - -#include "ipc_types.h" -#include "iremote_broker.h" -#include "iremote_proxy.h" -#include "iremote_stub.h" -#include "audio_policy_interface.h" - -namespace OHOS { -namespace AudioStandard { -class IStandardAudioRoutingManagerListener : public IRemoteBroker, public AudioDeviceRefiner { -public: - virtual ~IStandardAudioRoutingManagerListener() = default; - virtual void OnDistributedRoutingRoleChange( - const std::shared_ptr descriptor, const CastType type) = 0; - - bool hasBTPermission_ = true; - bool hasSystemPermission_ = true; - - enum AudioRingerModeUpdateListenerMsg { - ON_ERROR = 0, - ON_DISTRIBUTED_ROUTING_ROLE_CHANGE, - ON_AUDIO_OUTPUT_DEVICE_REFINERD, - ON_AUDIO_INPUT_DEVICE_REFINERD, - GET_SPLIT_INFO_REFINED, - ON_DISTRIBUTED_OUTPUT_CHANGE, - }; - - DECLARE_INTERFACE_DESCRIPTOR(u"IStandardAudioRoutingManagerListener"); -}; -} // namespace AudioStandard -} // namespace OHOS -#endif // I_STANDARD_AUDIO_ROUTING_MANAGER_LISTENER_H diff --git a/services/audio_policy/client/interface/i_standard_audio_zone_client.h b/services/audio_policy/client/interface/i_standard_audio_zone_client.h deleted file mode 100644 index 4f599a72bd..0000000000 --- a/services/audio_policy/client/interface/i_standard_audio_zone_client.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef I_STANDARD_AUDIO_ZONE_CLIENT_H -#define I_STANDARD_AUDIO_ZONE_CLIENT_H - -#include -#include -#include "ipc_types.h" -#include "iremote_broker.h" -#include "iremote_proxy.h" -#include "iremote_stub.h" -#include "audio_info.h" -#include "audio_zone_info.h" -#include "audio_interrupt_info.h" - -namespace OHOS { -namespace AudioStandard { -enum class AudioZoneClientCode { - ON_AUDIO_ZONE_ADD = 0, - ON_AUDIO_ZONE_REMOVE, - ON_AUDIO_ZONE_CHANGE, - ON_AUDIO_ZONE_INTERRUPT, - ON_AUDIO_ZONE_DEVICE_INTERRUPT, - ON_AUDIO_ZONE_SYSTEM_VOLUME_SET, - ON_AUDIO_ZONE_SYSTEM_VOLUME_GET, -}; - -class IStandardAudioZoneClient : public IRemoteBroker { -public: - virtual ~IStandardAudioZoneClient() = default; - - virtual void OnAudioZoneAdd(const AudioZoneDescriptor &zoneDescriptor) = 0; - - virtual void OnAudioZoneRemove(int32_t zoneId) = 0; - - virtual void OnAudioZoneChange(int32_t zoneId, const AudioZoneDescriptor &zoneDescriptor, - AudioZoneChangeReason reason) = 0; - - virtual void OnInterruptEvent(int32_t zoneId, - const std::list> &interrupts, - AudioZoneInterruptReason reason) = 0; - - virtual void OnInterruptEvent(int32_t zoneId, const std::string &deviceTag, - const std::list> &interrupts, - AudioZoneInterruptReason reason) = 0; - - virtual int32_t SetSystemVolume(const int32_t zoneId, const AudioVolumeType volumeType, - const int32_t volumeLevel, const int32_t volumeFlag) = 0; - - virtual int32_t GetSystemVolume(int32_t zoneId, AudioVolumeType volumeType) = 0; - - bool hasBTPermission_ = true; - bool hasSystemPermission_ = true; - - DECLARE_INTERFACE_DESCRIPTOR(u"IStandardAudioZoneClient"); -}; -} // namespace AudioStandard -} // namespace OHOS -#endif // I_STANDARD_AUDIO_ZONE_CLIENT_H \ No newline at end of file diff --git a/services/audio_policy/client/interface/i_standard_client_tracker.h b/services/audio_policy/client/interface/i_standard_client_tracker.h deleted file mode 100644 index e7422fd389..0000000000 --- a/services/audio_policy/client/interface/i_standard_client_tracker.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef I_STANDARD_CLIENT_TRACKER_H -#define I_STANDARD_CLIENT_TRACKER_H - -#include "ipc_types.h" -#include "iremote_broker.h" -#include "iremote_proxy.h" -#include "iremote_stub.h" - -namespace OHOS { -namespace AudioStandard { -class IStandardClientTracker : public IRemoteBroker { -public: - virtual ~IStandardClientTracker() = default; - - virtual void MuteStreamImpl(const StreamSetStateEventInternal &streamSetStateEventInternal) = 0; - virtual void UnmuteStreamImpl(const StreamSetStateEventInternal &streamSetStateEventInternal) = 0; - virtual void PausedStreamImpl(const StreamSetStateEventInternal &streamSetStateEventInternal) = 0; - virtual void ResumeStreamImpl(const StreamSetStateEventInternal &streamSetStateEventInternal) = 0; - virtual void SetLowPowerVolumeImpl(float volume) = 0; - virtual void GetLowPowerVolumeImpl(float& volume) = 0; - virtual void SetOffloadModeImpl(int32_t state, bool isAppBack) = 0; - virtual void UnsetOffloadModeImpl() = 0; - virtual void GetSingleStreamVolumeImpl(float& volume) = 0; - - enum AudioClientTrackerMsg { - ON_ERROR = 0, - ON_INIT, - SETLOWPOWERVOL, - GETLOWPOWERVOL, - PAUSEDSTREAM, - RESUMESTREAM, - MUTESTREAM, - UNMUTESTREAM, - GETSINGLESTREAMVOL, - SETOFFLOADMODE, - UNSETOFFLOADMODE, - }; - - DECLARE_INTERFACE_DESCRIPTOR(u"IStandardClientTracker"); -}; -} // namespace AudioStandard -} // namespace OHOS -#endif // I_STANDARD_CLIENT_TRACKER_H diff --git a/services/audio_policy/client/interface/i_standard_concurrency_state_listener.h b/services/audio_policy/client/interface/i_standard_concurrency_state_listener.h deleted file mode 100644 index bd2fd71e75..0000000000 --- a/services/audio_policy/client/interface/i_standard_concurrency_state_listener.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef I_STANDARD_CONCURRENCY_STATE_MANAGER_LISTENER_H -#define I_STANDARD_CONCURRENCY_STATE_MANAGER_LISTENER_H - -#include "ipc_types.h" -#include "iremote_broker.h" -#include "iremote_proxy.h" -#include "iremote_stub.h" - -namespace OHOS { -namespace AudioStandard { -class IStandardConcurrencyStateListener : public IRemoteBroker { -public: - virtual ~IStandardConcurrencyStateListener() = default; - virtual void OnConcedeStream() = 0; - - bool hasBTPermission_ = true; - bool hasSystemPermission_ = true; - - enum AudioPolicyManagerListenerMsg { - ON_ERROR = 0, - ON_CONCEDE_STREAM, - }; - DECLARE_INTERFACE_DESCRIPTOR(u"IStandardConcurrencyStateListener"); -}; -} // namespace AudioStandard -} // namespace OHOS -#endif \ No newline at end of file diff --git a/services/audio_policy/client/proxy/include/audio_policy_proxy.h b/services/audio_policy/client/proxy/include/audio_policy_proxy.h deleted file mode 100644 index 77e2382b94..0000000000 --- a/services/audio_policy/client/proxy/include/audio_policy_proxy.h +++ /dev/null @@ -1,530 +0,0 @@ -/* - * Copyright (c) 2021-2025 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef ST_AUDIO_POLICY_PROXY_H -#define ST_AUDIO_POLICY_PROXY_H - -#include -#include "iremote_proxy.h" -#include "audio_policy_base.h" -#include "audio_errors.h" -#include "microphone_descriptor.h" - -namespace OHOS { -namespace AudioStandard { -class AudioPolicyProxy : public IRemoteProxy { -public: - explicit AudioPolicyProxy(const sptr &impl); - virtual ~AudioPolicyProxy() = default; - - int32_t GetMaxVolumeLevel(AudioVolumeType volumeType) override; - - int32_t GetMinVolumeLevel(AudioVolumeType volumeType) override; - - int32_t SetSystemVolumeLevelLegacy(AudioVolumeType volumeType, int32_t volumeLevel) override; - - int32_t SetSystemVolumeLevel(AudioVolumeType volumeType, int32_t volumeLevel, int32_t volumeFlag = 0, - int32_t uid = 0) override; - - int32_t SetSystemVolumeLevelWithDevice(AudioVolumeType volumeType, int32_t volumeLevel, DeviceType deviceType, - int32_t volumeFlag = 0) override; - - int32_t SetAppVolumeLevel(int32_t appUid, int32_t volumeLevel, int32_t volumeFlag = 0) override; - - int32_t SetAppVolumeMuted(int32_t appUid, bool muted, int32_t volumeFlag = 0) override; - - int32_t SetAdjustVolumeForZone(int32_t zoneId) override; - - int32_t IsAppVolumeMute(int32_t appUid, bool owned, bool &isMute) override; - - int32_t SetSelfAppVolumeLevel(int32_t volumeLevel, int32_t volumeFlag = 0) override; - - int32_t GetAppVolumeLevel(int32_t appUid, int32_t &volumeLevel) override; - - int32_t GetSelfAppVolumeLevel(int32_t &volumeLevel) override; - - AudioStreamType GetSystemActiveVolumeType(const int32_t clientUid) override; - - int32_t GetSystemVolumeLevel(AudioVolumeType volumeType, int32_t uid = 0) override; - - int32_t SetLowPowerVolume(int32_t streamId, float volume) override; - - AudioStreamInfo GetFastStreamInfo() override; - - float GetLowPowerVolume(int32_t streamId) override; - - float GetSingleStreamVolume(int32_t streamId) override; - - int32_t SetStreamMuteLegacy(AudioVolumeType volumeType, bool mute, - const DeviceType &deviceType = DEVICE_TYPE_NONE) override; - - int32_t SetStreamMute(AudioVolumeType volumeType, bool mute, - const DeviceType &deviceType = DEVICE_TYPE_NONE) override; - - bool GetStreamMute(AudioVolumeType volumeType) override; - - bool IsStreamActive(AudioVolumeType volumeType) override; - - bool IsStreamActiveByStreamUsage(StreamUsage streamUsage) override; - - bool IsFastPlaybackSupported(AudioStreamInfo &streamInfo, StreamUsage usage) override; - bool IsFastRecordingSupported(AudioStreamInfo &streamInfo, SourceType source) override; - - std::vector> GetDevices(DeviceFlag deviceFlag) override; - - std::vector> GetDevicesInner(DeviceFlag deviceFlag) override; - - int32_t SetDeviceActive(InternalDeviceType deviceType, bool active, const int32_t uid = INVALID_UID) override; - - bool IsDeviceActive(InternalDeviceType deviceType) override; - - DeviceType GetActiveOutputDevice() override; - - uint16_t GetDmDeviceType() override; - - DeviceType GetActiveInputDevice() override; - - int32_t SelectOutputDevice(sptr audioRendererFilter, - std::vector> audioDeviceDescriptors) override; - - std::string GetSelectedDeviceInfo(int32_t uid, int32_t pid, AudioStreamType streamType) override; - - int32_t SelectInputDevice(sptr audioCapturerFilter, - std::vector> audioDeviceDescriptors) override; - - int32_t ExcludeOutputDevices(AudioDeviceUsage audioDevUsage, - std::vector> &audioDeviceDescriptors) override; - - int32_t UnexcludeOutputDevices(AudioDeviceUsage audioDevUsage, - std::vector> &audioDeviceDescriptors) override; - - std::vector> GetExcludedDevices( - AudioDeviceUsage audioDevUsage) override; - - int32_t SetRingerModeLegacy(AudioRingerMode ringMode) override; - - int32_t SetRingerMode(AudioRingerMode ringMode) override; - - int32_t ConfigDistributedRoutingRole( - const std::shared_ptr descriptor, CastType type) override; - - int32_t SetDistributedRoutingRoleCallback(const sptr &object) override; - - int32_t UnsetDistributedRoutingRoleCallback() override; - -#ifdef FEATURE_DTMF_TONE - std::vector GetSupportedTones(const std::string &countryCode) override; - - std::shared_ptr GetToneConfig(int32_t ltonetype, const std::string &countryCode) override; -#endif - - AudioRingerMode GetRingerMode() override; - - int32_t SetAudioScene(AudioScene scene) override; - - int32_t SetMicrophoneMute(bool isMute) override; - - int32_t SetMicrophoneMuteAudioConfig(bool isMute) override; - - int32_t SetMicrophoneMutePersistent(const bool isMute, const PolicyType type) override; - - bool GetPersistentMicMuteState() override; - - bool IsMicrophoneMuteLegacy() override; - - bool IsMicrophoneMute() override; - - AudioScene GetAudioScene() override; - - int32_t ActivateAudioSession(const AudioSessionStrategy &strategy) override; - - int32_t DeactivateAudioSession() override; - - bool IsAudioSessionActivated() override; - - int32_t SetAudioSessionScene(const AudioSessionScene audioSessionScene) override; - - int32_t GetDefaultOutputDevice(DeviceType &deviceType) override; - - int32_t SetDefaultOutputDevice(DeviceType deviceType) override; - - int32_t SetInputDevice(const DeviceType deviceType, const uint32_t sessionID, - const SourceType sourceType, bool isRunning) override; - - int32_t SetAudioInterruptCallback(const uint32_t sessionID, - const sptr &object, uint32_t clientUid, const int32_t zoneID = 0) override; - - int32_t UnsetAudioInterruptCallback(const uint32_t sessionID, const int32_t zoneID = 0) override; - - int32_t ActivateAudioInterrupt(AudioInterrupt &audioInterrupt, const int32_t zoneID = 0, - const bool isUpdatedAudioStrategy = false) override; - - int32_t DeactivateAudioInterrupt(const AudioInterrupt &audioInterrupt, const int32_t zoneID = 0) override; - - int32_t ActivatePreemptMode(void) override; - - int32_t DeactivatePreemptMode(void) override; - - int32_t SetAudioManagerInterruptCallback(const int32_t clientId, const sptr &object) override; - - int32_t UnsetAudioManagerInterruptCallback(const int32_t clientId) override; - - int32_t SetQueryClientTypeCallback(const sptr &object) override; - - int32_t SetAudioClientInfoMgrCallback(const sptr &object) override; - - int32_t SetAudioVKBInfoMgrCallback(const sptr &object) override; - - int32_t CheckVKBInfo(const std::string &bundleName, bool &isValid) override; - - int32_t SetQueryBundleNameListCallback(const sptr &object) override; - - int32_t RequestAudioFocus(const int32_t clientId, const AudioInterrupt &audioInterrupt) override; - - int32_t AbandonAudioFocus(const int32_t clientId, const AudioInterrupt &audioInterrupt) override; - - AudioStreamType GetStreamInFocus(const int32_t zoneID = 0) override; - - AudioStreamType GetStreamInFocusByUid(const int32_t uid, const int32_t zoneID = 0) override; - - int32_t GetSessionInfoInFocus(AudioInterrupt &audioInterrupt, const int32_t zoneID = 0) override; - - int32_t ReconfigureAudioChannel(const uint32_t &count, DeviceType deviceType) override; - - int32_t GetPreferredOutputStreamType(AudioRendererInfo &rendererInfo) override; - - int32_t GetPreferredInputStreamType(AudioCapturerInfo &capturerInfo) override; - - int32_t CreateRendererClient( - std::shared_ptr streamDesc, uint32_t &flag, uint32_t &sessionId) override; - - int32_t CreateCapturerClient( - std::shared_ptr streamDesc, uint32_t &flag, uint32_t &sessionId) override; - - int32_t RegisterTracker(AudioMode &mode, - AudioStreamChangeInfo &streamChangeInfo, const sptr &object) override; - - int32_t UpdateTracker(AudioMode &mode, AudioStreamChangeInfo &streamChangeInfo) override; - - int32_t GetCurrentRendererChangeInfos( - std::vector> &audioRendererChangeInfos) override; - - int32_t GetCurrentCapturerChangeInfos( - std::vector> &audioCapturerChangeInfos) override; - - int32_t UpdateStreamState(const int32_t clientUid, StreamSetState streamSetState, - StreamUsage streamUsage) override; - - int32_t GetVolumeGroupInfos(std::string networkId, std::vector> &infos) override; - - int32_t GetNetworkIdByGroupId(int32_t groupId, std::string &networkId) override; - - std::vector> GetPreferredOutputDeviceDescriptors( - AudioRendererInfo &rendererInfo, bool forceNoBTPermission) override; - - std::vector> GetPreferredInputDeviceDescriptors( - AudioCapturerInfo &captureInfo) override; - - std::vector> GetOutputDevice( - sptr audioRendererFilter) override; - - std::vector> GetInputDevice( - sptr audioCapturerFilter) override; - - int32_t SetClientCallbacksEnable(const CallbackChange &callbackchange, const bool &enable) override; - - int32_t SetCallbackRendererInfo(const AudioRendererInfo &rendererInfo) override; - - int32_t SetCallbackCapturerInfo(const AudioCapturerInfo &capturerInfo) override; - - int32_t GetAudioFocusInfoList(std::list> &focusInfoList, - const int32_t zoneID = 0) override; - - int32_t SetSystemSoundUri(const std::string &key, const std::string &uri) override; - - std::string GetSystemSoundUri(const std::string &key) override; - - float GetMinStreamVolume(void) override; - - float GetMaxStreamVolume(void) override; - - int32_t GetMaxRendererInstances() override; - - bool IsVolumeUnadjustable() override; - - int32_t AdjustVolumeByStep(VolumeAdjustType adjustType) override; - - int32_t AdjustSystemVolumeByStep(AudioVolumeType volumeType, VolumeAdjustType adjustType) override; - - float GetSystemVolumeInDb(AudioVolumeType volumeType, int32_t volumeLevel, DeviceType deviceType) override; - - int32_t QueryEffectSceneMode(SupportedEffectConfig &supportedEffectConfig) override; - - int32_t GetHardwareOutputSamplingRate(const std::shared_ptr &desc) override; - - std::vector> GetAudioCapturerMicrophoneDescriptors(int32_t sessionId) override; - - std::vector> GetAvailableMicrophones() override; - - int32_t SetDeviceAbsVolumeSupported(const std::string &macAddress, const bool support) override; - - bool IsAbsVolumeScene() override; - - int32_t SetA2dpDeviceVolume(const std::string &macAddress, const int32_t volume, const bool updateUi) override; - - int32_t SetNearlinkDeviceVolume(const std::string &macAddress, AudioVolumeType volumeType, - const int32_t volume, const bool updateUi) override; - - std::vector> GetAvailableDevices(AudioDeviceUsage usage) override; - - int32_t SetAvailableDeviceChangeCallback(const int32_t clientId, const AudioDeviceUsage usage, - const sptr &object) override; - - int32_t UnsetAvailableDeviceChangeCallback(const int32_t clientId, AudioDeviceUsage usage) override; - - bool IsSpatializationEnabled() override; - - bool IsSpatializationEnabled(const std::string address) override; - - bool IsSpatializationEnabledForCurrentDevice() override; - - int32_t SetSpatializationEnabled(const bool enable) override; - - int32_t SetSpatializationEnabled(const std::shared_ptr &selectedAudioDevice, - const bool enable) override; - - bool IsHeadTrackingEnabled() override; - - bool IsHeadTrackingEnabled(const std::string address) override; - - int32_t SetHeadTrackingEnabled(const bool enable) override; - - int32_t SetHeadTrackingEnabled( - const std::shared_ptr &selectedAudioDevice, const bool enable) override; - - AudioSpatializationState GetSpatializationState(const StreamUsage streamUsage) override; - - bool IsSpatializationSupported() override; - - bool IsSpatializationSupportedForDevice(const std::string address) override; - - bool IsHeadTrackingSupported() override; - - bool IsHeadTrackingSupportedForDevice(const std::string address) override; - - int32_t UpdateSpatialDeviceState(const AudioSpatialDeviceState audioSpatialDeviceState) override; - - int32_t RegisterSpatializationStateEventListener(const uint32_t sessionID, const StreamUsage streamUsage, - const sptr &object) override; - - int32_t UnregisterSpatializationStateEventListener(const uint32_t sessionID) override; - - int32_t RegisterPolicyCallbackClient(const sptr &object, const int32_t zoneID = 0) override; - - int32_t CreateAudioInterruptZone(const std::set &pids, const int32_t zoneID) override; - - int32_t AddAudioInterruptZonePids(const std::set &pids, const int32_t zoneID) override; - - int32_t RemoveAudioInterruptZonePids(const std::set &pids, const int32_t zoneID) override; - - int32_t ReleaseAudioInterruptZone(const int32_t zoneID) override; - - int32_t RegisterAudioZoneClient(const sptr& object) override; - - int32_t CreateAudioZone(const std::string &name, const AudioZoneContext &context) override; - - void ReleaseAudioZone(int32_t zoneId) override; - - const std::vector> GetAllAudioZone() override; - - const std::shared_ptr GetAudioZone(int32_t zoneId) override; - - int32_t BindDeviceToAudioZone(int32_t zoneId, - std::vector> devices) override; - - int32_t UnBindDeviceToAudioZone(int32_t zoneId, - std::vector> devices) override; - - int32_t EnableAudioZoneReport (bool enable) override; - - int32_t EnableAudioZoneChangeReport(int32_t zoneId, bool enable) override; - - int32_t AddUidToAudioZone(int32_t zoneId, int32_t uid) override; - - int32_t RemoveUidFromAudioZone(int32_t zoneId, int32_t uid) override; - - int32_t AddStreamToAudioZone(int32_t zoneId, AudioZoneStream stream) override; - - int32_t RemoveStreamFromAudioZone(int32_t zoneId, AudioZoneStream stream) override; - - int32_t EnableSystemVolumeProxy(int32_t zoneId, bool enable) override; - - void SetZoneDeviceVisible(bool visible) override; - - std::list> GetAudioInterruptForZone(int32_t zoneId) override; - - std::list> GetAudioInterruptForZone(int32_t zoneId, - const std::string &deviceTag) override; - - int32_t EnableAudioZoneInterruptReport(int32_t zoneId, const std::string &deviceTag, bool enable) override; - - int32_t InjectInterruptToAudioZone(int32_t zoneId, - const std::list> &interrupts) override; - - int32_t InjectInterruptToAudioZone(int32_t zoneId, const std::string &deviceTag, - const std::list> &interrupts) override; - - int32_t SetCallDeviceActive(InternalDeviceType deviceType, bool active, std::string address, - const int32_t uid = INVALID_UID) override; - - std::shared_ptr GetActiveBluetoothDevice() override; - - ConverterConfig GetConverterConfig() override; - - void FetchOutputDeviceForTrack(AudioStreamChangeInfo &streamChangeInfo, - const AudioStreamDeviceChangeReasonExt reason) override; - - void FetchInputDeviceForTrack(AudioStreamChangeInfo &streamChangeInfo) override; - - bool IsHighResolutionExist() override; - - int32_t SetHighResolutionExist(bool highResExist) override; - - AudioSpatializationSceneType GetSpatializationSceneType() override; - - int32_t SetSpatializationSceneType(const AudioSpatializationSceneType spatializationSceneType) override; - - float GetMaxAmplitude(const int32_t deviceId) override; - - int32_t DisableSafeMediaVolume() override; - - bool IsHeadTrackingDataRequested(const std::string &macAddress) override; - int32_t SetAudioDeviceRefinerCallback(const sptr &object) override; - - int32_t UnsetAudioDeviceRefinerCallback() override; - - int32_t TriggerFetchDevice(AudioStreamDeviceChangeReasonExt reason) override; - - int32_t SetPreferredDevice(const PreferredType preferredType, - const std::shared_ptr &desc, const int32_t uid = INVALID_UID) override; - - void SaveRemoteInfo(const std::string &networkId, DeviceType deviceType) override; - - int32_t SetAudioDeviceAnahsCallback(const sptr &object) override; - - int32_t UnsetAudioDeviceAnahsCallback() override; - - int32_t MoveToNewPipe(const uint32_t sessionId, const AudioPipeType pipeType) override; - - int32_t SetAudioConcurrencyCallback(const uint32_t sessionID, const sptr &object) override; - - int32_t UnsetAudioConcurrencyCallback(const uint32_t sessionID) override; - - int32_t ActivateAudioConcurrency(const AudioPipeType &pipeType) override; - - int32_t InjectInterruption(const std::string networkId, InterruptEvent &event) override; - - int32_t LoadSplitModule(const std::string &splitArgs, const std::string &networkId) override; - - bool IsAllowedPlayback(const int32_t &uid, const int32_t &pid) override; - - int32_t SetVoiceRingtoneMute(bool isMute) override; - - int32_t GetSupportedAudioEffectProperty(AudioEffectPropertyArrayV3 &propertyArray) override; - - int32_t SetAudioEffectProperty(const AudioEffectPropertyArrayV3 &propertyArray) override; - - int32_t GetAudioEffectProperty(AudioEffectPropertyArrayV3 &propertyArray) override; - - int32_t GetSupportedAudioEffectProperty(AudioEffectPropertyArray &propertyArray) override; - - int32_t GetSupportedAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray) override; - - int32_t SetAudioEffectProperty(const AudioEffectPropertyArray &propertyArray) override; - - int32_t GetAudioEffectProperty(AudioEffectPropertyArray &propertyArray) override; - - int32_t SetAudioEnhanceProperty(const AudioEnhancePropertyArray &propertyArray) override; - - int32_t GetAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray) override; - - int32_t SetVirtualCall(const bool isVirtual) override; - - int32_t SetDeviceConnectionStatus(const std::shared_ptr &desc, - const bool isConnected) override; - - int32_t SetQueryAllowedPlaybackCallback(const sptr &object) override; - - int32_t SetBackgroundMuteCallback(const sptr &object) override; - - int32_t NotifySessionStateChange(const int32_t uid, const int32_t pid, const bool hasSession) override; - - int32_t NotifyFreezeStateChange(const std::set &pidList, const bool isFreeze) override; - - int32_t ResetAllProxy() override; - - int32_t NotifyProcessBackgroundState(const int32_t uid, const int32_t pid) override; - - DirectPlaybackMode GetDirectPlaybackSupport(const AudioStreamInfo &streamInfo, - const StreamUsage &streamUsage) override; - - bool IsAcousticEchoCancelerSupported(SourceType sourceType) override; - - bool IsAudioLoopbackSupported(AudioLoopbackMode mode) override; - - int32_t ForceStopAudioStream(StopAudioType audioType) override; - - bool IsCapturerFocusAvailable(const AudioCapturerInfo &capturerInfo) override; - - bool SetKaraokeParameters(const std::string ¶meters) override; - - int32_t GetMaxVolumeLevelByUsage(StreamUsage streamUsage) override; - - int32_t GetMinVolumeLevelByUsage(StreamUsage streamUsage) override; - - int32_t GetVolumeLevelByUsage(StreamUsage streamUsage) override; - - bool GetStreamMuteByUsage(StreamUsage streamUsage) override; - - float GetVolumeInDbByStream(StreamUsage streamUsage, int32_t volumeLevel, DeviceType deviceType) override; - - std::vector GetSupportedAudioVolumeTypes() override; - - AudioVolumeType GetAudioVolumeTypeByStreamUsage(StreamUsage streamUsage) override; - - std::vector GetStreamUsagesByVolumeType(AudioVolumeType audioVolumeType) override; - - int32_t SetCallbackStreamUsageInfo(const std::set &streamUsages) override; - int32_t UpdateDeviceInfo(const std::shared_ptr &deviceDesc, - const DeviceInfoUpdateCommand command) override; - int32_t SetSleAudioOperationCallback(const sptr &object) override; - - bool IsCollaborativePlaybackSupported() override; - - bool IsCollaborativePlaybackEnabledForDevice( - const std::shared_ptr &selectedAudioDevice) override; - - int32_t SetCollaborativePlaybackEnabledForDevice( - const std::shared_ptr &selectedAudioDevice, const bool enable) override; -private: - static inline BrokerDelegator mDdelegator; - void WriteStreamChangeInfo(MessageParcel &data, const AudioMode &mode, - const AudioStreamChangeInfo &streamChangeInfo); - void ReadAudioFocusInfo( - MessageParcel &reply, std::list> &focusInfoList); -}; -} // namespace AudioStandard -} // namespace OHOS -#endif // ST_AUDIO_POLICY_PROXY_H diff --git a/services/audio_policy/client/proxy/src/audio_policy_callback_proxy.cpp b/services/audio_policy/client/proxy/src/audio_policy_callback_proxy.cpp deleted file mode 100644 index 49e8b93f56..0000000000 --- a/services/audio_policy/client/proxy/src/audio_policy_callback_proxy.cpp +++ /dev/null @@ -1,517 +0,0 @@ -/* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. - * 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. - */ -#ifndef LOG_TAG -#define LOG_TAG "AudioPolicyProxy" -#endif - - -#include "audio_policy_log.h" -#include "audio_policy_proxy.h" - - -namespace OHOS { -namespace AudioStandard { -using namespace std; - -int32_t AudioPolicyProxy::SetAudioInterruptCallback(const uint32_t sessionID, const sptr &object, - uint32_t clientUid, const int32_t zoneID) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT, - "SetAudioInterruptCallback object is null"); - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteUint32(sessionID); - (void)data.WriteRemoteObject(object); - data.WriteInt32(zoneID); - data.WriteUint32(clientUid); - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_CALLBACK), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, - "set callback failed, error: %{public}d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::UnsetAudioInterruptCallback(const uint32_t sessionID, - const int32_t zoneID) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteUint32(sessionID); - data.WriteInt32(zoneID); - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::UNSET_CALLBACK), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, - "unset callback failed, error: %{public}d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetAudioManagerInterruptCallback(const int32_t clientId, const sptr &object) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT, - "SetAudioManagerInterruptCallback object is null"); - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteInt32(clientId); - (void)data.WriteRemoteObject(object); - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_INTERRUPT_CALLBACK), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, - "set callback failed, error: %{public}d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::UnsetAudioManagerInterruptCallback(const int32_t clientId) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - - data.WriteInt32(clientId); - - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::UNSET_INTERRUPT_CALLBACK), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, - "unset callback failed, error: %{public}d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetQueryClientTypeCallback(const sptr &object) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT, - "SetQueryClientTypeCallback object is null"); - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - (void)data.WriteRemoteObject(object); - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_QUERY_CLIENT_TYPE_CALLBACK), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, - "set callback failed, error: %{public}d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetAudioClientInfoMgrCallback(const sptr &object) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT, - "SetAudioClientInfoMgrCallback object is null"); - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - (void)data.WriteRemoteObject(object); - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_CLIENT_INFO_MGR_CALLBACK), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, - "set callback failed, error: %{public}d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetAudioVKBInfoMgrCallback(const sptr &object) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT, - "SetAudioVKBInfoMgrCallback object is null"); - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - (void)data.WriteRemoteObject(object); - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_VKB_INFO_MGR_CALLBACK), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, - "set callback failed, error: %{public}d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetQueryBundleNameListCallback(const sptr &object) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT, - "SetQueryClientTypeCallback object is null"); - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - (void)data.WriteRemoteObject(object); - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_QUERY_BUNDLE_NAME_LIST_CALLBACK), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, - "set callback failed, error: %{public}d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetAvailableDeviceChangeCallback(const int32_t clientId, const AudioDeviceUsage usage, - const sptr &object) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT, "SetAvailableDeviceChangeCallback object is null"); - - bool token = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(token, ERROR, "data WriteInterfaceToken failed"); - token = data.WriteInt32(clientId) && data.WriteInt32(usage); - CHECK_AND_RETURN_RET_LOG(token, ERROR, "data write failed"); - - token = data.WriteRemoteObject(object); - CHECK_AND_RETURN_RET_LOG(token, ERROR, "data WriteRemoteObject failed"); - - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_AVAILABLE_DEVICE_CHANGE_CALLBACK), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, - "SetAvailableDeviceChangeCallback failed, error: %{public}d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::UnsetAvailableDeviceChangeCallback(const int32_t clientId, AudioDeviceUsage usage) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool token = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(token, ERROR, "data WriteInterfaceToken failed"); - token = data.WriteInt32(clientId) && data.WriteInt32(usage); - CHECK_AND_RETURN_RET_LOG(token, ERROR, "data write failed"); - - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::UNSET_AVAILABLE_DEVICE_CHANGE_CALLBACK), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, - "UnsetAvailableDeviceChangeCallback failed, error: %{public}d", error); - - return reply.ReadInt32(); -} - - -int32_t AudioPolicyProxy::SetAudioConcurrencyCallback(const uint32_t sessionID, - const sptr &object) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT, - "SetAudioConcurrencyCallback object is null"); - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - - data.WriteUint32(sessionID); - (void)data.WriteRemoteObject(object); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_AUDIO_CONCURRENCY_CALLBACK), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::UnsetAudioConcurrencyCallback(const uint32_t sessionID) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteUint32(sessionID); - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::UNSET_AUDIO_CONCURRENCY_CALLBACK), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, - "unset concurrency callback failed, error: %{public}d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetDistributedRoutingRoleCallback(const sptr &object) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT, "object is null"); - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - (void)data.WriteRemoteObject(object); - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_DISTRIBUTED_ROUTING_ROLE_CALLBACK), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "failed error : %{public}d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::UnsetDistributedRoutingRoleCallback() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool token = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(token, ERROR, "data writeInterfaceToken failed"); - - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::UNSET_DISTRIBUTED_ROUTING_ROLE_CALLBACK), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, - "AudioPolicyProxy UnsetDistributedRoutingRoleCallback failed error : %{public}d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetClientCallbacksEnable(const CallbackChange &callbackchange, const bool &enable) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteInt32(static_cast(callbackchange)); - data.WriteBool(enable); - - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_CALLBACKS_ENABLE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Set client callback failed, error: %{public}d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetCallbackRendererInfo(const AudioRendererInfo &rendererInfo) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - rendererInfo.Marshalling(data); - - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_CALLBACK_RENDERER_INFO), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Set renderer info failed, error: %{public}d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetCallbackCapturerInfo(const AudioCapturerInfo &capturerInfo) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - capturerInfo.Marshalling(data); - - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_CALLBACK_CAPTURER_INFO), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Set capturer info failed, error: %{public}d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::RegisterPolicyCallbackClient(const sptr &object, const int32_t zoneID) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT, "RegisterPolicyCallbackClient object is null"); - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed"); - - data.WriteRemoteObject(object); - data.WriteInt32(zoneID); - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::REGISTER_POLICY_CALLBACK_CLIENT), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "SendRequest failed , error: %{public}d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetAudioDeviceRefinerCallback(const sptr &object) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT, "object is null"); - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - - (void)data.WriteRemoteObject(object); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_AUDIO_DEVICE_REFINER_CALLBACK), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::UnsetAudioDeviceRefinerCallback() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::UNSET_AUDIO_DEVICE_REFINER_CALLBACK), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error); - return reply.ReadInt32(); -} - - -int32_t AudioPolicyProxy::RegisterSpatializationStateEventListener(const uint32_t sessionID, - const StreamUsage streamUsage, const sptr &object) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed"); - CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT, "SpatializationStateEventListener object is null"); - - data.WriteInt32(static_cast(sessionID)); - data.WriteInt32(static_cast(streamUsage)); - data.WriteRemoteObject(object); - int32_t error = Remote() ->SendRequest( - static_cast(AudioPolicyInterfaceCode::REGISTER_SPATIALIZATION_STATE_EVENT), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "SendRequest failed , error: %{public}d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::UnregisterSpatializationStateEventListener(const uint32_t sessionID) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed"); - - data.WriteInt32(static_cast(sessionID)); - int32_t error = Remote() ->SendRequest( - static_cast(AudioPolicyInterfaceCode::UNREGISTER_SPATIALIZATION_STATE_EVENT), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "SendRequest failed , error: %{public}d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetQueryAllowedPlaybackCallback(const sptr &object) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT, "SetQueryAllowedPlaybackCallback object is null"); - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - (void)data.WriteRemoteObject(object); - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_QUERY_ALLOWED_PLAYBACK_CALLBACK), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "set callback failed, error: %{public}d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetBackgroundMuteCallback(const sptr &object) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT, "SetBackgroundMuteCallback object is null"); - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - (void)data.WriteRemoteObject(object); - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_BACKGROUND_MUTE_CALLBACK), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "set callback failed, error: %{public}d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::UpdateDeviceInfo(const std::shared_ptr &deviceDesc, - const DeviceInfoUpdateCommand command) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - CHECK_AND_RETURN_RET_LOG(deviceDesc != nullptr, ERR_NULL_OBJECT, "deviceDesc is null"); - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - - bool result = deviceDesc->Marshalling(data); - CHECK_AND_RETURN_RET_LOG(result, -1, "AudioDeviceDescriptor Marshalling failed"); - - data.WriteInt32(static_cast(command)); - - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::UPDATE_DEVICE_INFO), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "failed, error: %{public}d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetSleAudioOperationCallback(const sptr &object) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT, "callback object is null"); - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - - (void)data.WriteRemoteObject(object); - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_SLE_AUDIO_OPERATION_CALLBACK), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "set callback failed, error: %{public}d", error); - - return reply.ReadInt32(); -} -} // namespace AudioStandard -} // namespace OHOS diff --git a/services/audio_policy/client/proxy/src/audio_policy_microphone_proxy.cpp b/services/audio_policy/client/proxy/src/audio_policy_microphone_proxy.cpp deleted file mode 100644 index 0a93ee1b86..0000000000 --- a/services/audio_policy/client/proxy/src/audio_policy_microphone_proxy.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * 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. - */ -#ifndef LOG_TAG -#define LOG_TAG "AudioPolicyProxy" -#endif - -#include "audio_policy_proxy.h" - -#include "audio_policy_log.h" - -namespace OHOS { -namespace AudioStandard { -using namespace std; - -int32_t AudioPolicyProxy::SetMicrophoneMute(bool isMute) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteBool(isMute); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_MICROPHONE_MUTE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "set microphoneMute failed, error: %d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetMicrophoneMuteAudioConfig(bool isMute) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteBool(isMute); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_MICROPHONE_MUTE_AUDIO_CONFIG), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "set microphoneMute failed, error: %d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetMicrophoneMutePersistent(const bool isMute, const PolicyType type) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteBool(isMute); - data.WriteInt32(static_cast(type)); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_MICROPHONE_MUTE_PERSISTENT), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "set microphoneMute persistent failed, error: %d", error); - - return reply.ReadInt32(); -} - -bool AudioPolicyProxy::IsMicrophoneMuteLegacy() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::IS_MICROPHONE_MUTE_LEGACY), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "set microphoneMute failed, error: %d", error); - - return reply.ReadBool(); -} - -bool AudioPolicyProxy::IsMicrophoneMute() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::IS_MICROPHONE_MUTE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "set microphoneMute failed, error: %d", error); - - return reply.ReadBool(); -} - -std::vector> AudioPolicyProxy::GetAudioCapturerMicrophoneDescriptors( - int32_t sessionId) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - std::vector> micDescs; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, micDescs, "WriteInterfaceToken failed"); - - data.WriteInt32(sessionId); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_AUDIO_CAPTURER_MICROPHONE_DESCRIPTORS), - data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, micDescs, - "Get audio capturer microphonedescriptors failed, error: %d", error); - - int32_t size = reply.ReadInt32(); - CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= static_cast(AUDIO_DEVICE_INFO_SIZE_LIMIT), - micDescs, "Using tainted data [size:%{public}d] as loop bound", size); - for (int32_t i = 0; i < size; i++) { - micDescs.push_back(MicrophoneDescriptor::Unmarshalling(reply)); - } - - return micDescs; -} - -std::vector> AudioPolicyProxy::GetAvailableMicrophones() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - std::vector> micDescs; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, micDescs, "WriteInterfaceToken failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_AVAILABLE_MICROPHONE_DESCRIPTORS), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, micDescs, - "Get available microphonedescriptors failed, error: %d", error); - - int32_t size = reply.ReadInt32(); - CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= static_cast(AUDIO_DEVICE_INFO_SIZE_LIMIT), - micDescs, "Using tainted data [size:%{public}d] as loop bound", size); - for (int32_t i = 0; i < size; i++) { - micDescs.push_back(MicrophoneDescriptor::Unmarshalling(reply)); - } - - return micDescs; -} - -} // namespace AudioStandard -} // namespace OHOS \ No newline at end of file diff --git a/services/audio_policy/client/proxy/src/audio_policy_proxy.cpp b/services/audio_policy/client/proxy/src/audio_policy_proxy.cpp deleted file mode 100644 index 21a8d42353..0000000000 --- a/services/audio_policy/client/proxy/src/audio_policy_proxy.cpp +++ /dev/null @@ -1,2925 +0,0 @@ -/* - * Copyright (c) 2021-2025 Huawei Device Co., Ltd. - * 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. - */ -#ifndef LOG_TAG -#define LOG_TAG "AudioPolicyProxy" -#endif - - -#include "audio_policy_log.h" -#include "audio_policy_proxy.h" - - -namespace { -constexpr int MAX_PID_COUNT = 1000; -constexpr int32_t MAX_STREAM_USAGE_COUNT = OHOS::AudioStandard::StreamUsage::STREAM_USAGE_MAX + 1; -} - -namespace OHOS { -namespace AudioStandard { -using namespace std; - -AudioPolicyProxy::AudioPolicyProxy(const sptr &impl) - : IRemoteProxy(impl) -{ -} - -void AudioPolicyProxy::WriteStreamChangeInfo(MessageParcel &data, - const AudioMode &mode, const AudioStreamChangeInfo &streamChangeInfo) -{ - if (mode == AUDIO_MODE_PLAYBACK) { - streamChangeInfo.audioRendererChangeInfo.Marshalling(data); - } else { - streamChangeInfo.audioCapturerChangeInfo.Marshalling(data); - } -} - -int32_t AudioPolicyProxy::SetRingerModeLegacy(AudioRingerMode ringMode) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteInt32(static_cast(ringMode)); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_RINGER_MODE_LEGACY), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "set SetRingerModeLegacy failed, error: %d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetRingerMode(AudioRingerMode ringMode) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteInt32(static_cast(ringMode)); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_RINGER_MODE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "set ringermode failed, error: %d", error); - - return reply.ReadInt32(); -} - -#ifdef FEATURE_DTMF_TONE -std::vector AudioPolicyProxy::GetSupportedTones(const std::string &countryCode) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t lListSize = 0; - AUDIO_DEBUG_LOG("get GetSupportedTones,"); - std::vector lSupportedToneList = {}; - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, lSupportedToneList, "WriteInterfaceToken failed"); - data.WriteString(countryCode); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_SUPPORTED_TONES), data, reply, option); - if (error != ERR_NONE) { - AUDIO_ERR_LOG("get ringermode failed, error: %d", error); - } - lListSize = reply.ReadInt32(); - CHECK_AND_RETURN_RET_LOG(lListSize >= 0 && lListSize <= static_cast(MAX_SUPPORTED_TONEINFO_SIZE), - lSupportedToneList, "Using tainted data lListSize:%{public}d as loop bound", lListSize); - for (int i = 0; i < lListSize; i++) { - lSupportedToneList.push_back(reply.ReadInt32()); - } - AUDIO_DEBUG_LOG("get GetSupportedTones, %{public}d", lListSize); - return lSupportedToneList; -} - -std::shared_ptr AudioPolicyProxy::GetToneConfig(int32_t ltonetype, const std::string &countryCode) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - std::shared_ptr spToneInfo = std::make_shared(); - if (spToneInfo == nullptr) { - return nullptr; - } - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, spToneInfo, "WriteInterfaceToken failed"); - data.WriteInt32(ltonetype); - data.WriteString(countryCode); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_TONEINFO), data, reply, option); - if (error != ERR_NONE) { - AUDIO_ERR_LOG("get toneinfo failed, error: %d", error); - } - - spToneInfo->Unmarshalling(reply); - AUDIO_DEBUG_LOG("get rGetToneConfig returned,"); - return spToneInfo; -} -#endif - -bool AudioPolicyProxy::GetPersistentMicMuteState() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_MICROPHONE_MUTE_PERSISTENT), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "get persistent microphoneMute state failed, error: %d", error); - - return reply.ReadBool(); -} - -AudioRingerMode AudioPolicyProxy::GetRingerMode() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, RINGER_MODE_NORMAL, "WriteInterfaceToken failed"); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_RINGER_MODE), data, reply, option); - if (error != ERR_NONE) { - AUDIO_ERR_LOG("get ringermode failed, error: %d", error); - } - return static_cast(reply.ReadInt32()); -} - -int32_t AudioPolicyProxy::SetAudioScene(AudioScene scene) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, RINGER_MODE_NORMAL, "WriteInterfaceToken failed"); - data.WriteInt32(static_cast(scene)); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_AUDIO_SCENE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "set audio scene failed, error: %d", error); - - return reply.ReadInt32(); -} - -AudioScene AudioPolicyProxy::GetAudioScene() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, AUDIO_SCENE_DEFAULT, "WriteInterfaceToken failed"); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_AUDIO_SCENE), data, reply, option); - if (error != ERR_NONE) { - AUDIO_ERR_LOG("get audio scene failed, error: %d", error); - } - return static_cast(reply.ReadInt32()); -} - -int32_t AudioPolicyProxy::SetStreamMuteLegacy(AudioVolumeType volumeType, bool mute, - const DeviceType &deviceType) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteInt32(static_cast(volumeType)); - data.WriteBool(mute); - data.WriteInt32(static_cast(deviceType)); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_STREAM_MUTE_LEGACY), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "set mute failed, error: %d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetStreamMute(AudioVolumeType volumeType, bool mute, - const DeviceType &deviceType) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteInt32(static_cast(volumeType)); - data.WriteBool(mute); - data.WriteInt32(static_cast(deviceType)); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_STREAM_MUTE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "set mute failed, error: %d", error); - return reply.ReadInt32(); -} - -bool AudioPolicyProxy::GetStreamMute(AudioVolumeType volumeType) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed"); - data.WriteInt32(static_cast(volumeType)); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_STREAM_MUTE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "get mute failed, error: %d", error); - return reply.ReadBool(); -} - -bool AudioPolicyProxy::IsStreamActive(AudioVolumeType volumeType) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed"); - data.WriteInt32(static_cast(volumeType)); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::IS_STREAM_ACTIVE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "isStreamActive failed, error: %d", error); - return reply.ReadBool(); -} - -bool AudioPolicyProxy::IsStreamActiveByStreamUsage(StreamUsage streamUsage) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed"); - data.WriteInt32(static_cast(streamUsage)); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::IS_STREAM_ACTIVE_BY_STREAM_USAGE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "IsStreamActiveByStreamUsage failed, error: %d", error); - return reply.ReadBool(); -} - -bool AudioPolicyProxy::IsFastPlaybackSupported(AudioStreamInfo &streamInfo, StreamUsage usage) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed"); - bool tmp = streamInfo.Marshalling(data); - CHECK_AND_RETURN_RET_LOG(tmp, false, "AudioStreamInfo Marshalling() failed"); - - data.WriteInt32(static_cast(usage)); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::IS_FAST_PLAYBACK_SUPPORTED), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "IsFastPlaybackSupported failed, error: %{public}d", error); - - return reply.ReadBool(); -} - -bool AudioPolicyProxy::IsFastRecordingSupported(AudioStreamInfo &streamInfo, SourceType source) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed"); - bool tmp = streamInfo.Marshalling(data); - CHECK_AND_RETURN_RET_LOG(tmp, false, "AudioStreamInfo Marshalling() failed"); - - data.WriteInt32(static_cast(source)); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::IS_FAST_RECORDING_SUPPORTED), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "IsFastRecordingSupported failed, error: %{public}d", error); - - return reply.ReadBool(); -} - -std::vector> AudioPolicyProxy::GetDevices(DeviceFlag deviceFlag) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - std::vector> deviceInfo; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, deviceInfo, "WriteInterfaceToken failed"); - data.WriteInt32(static_cast(deviceFlag)); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_DEVICES), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, deviceInfo, "Get devices failed, error: %d", error); - - int32_t size = reply.ReadInt32(); - CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= static_cast(AUDIO_DEVICE_INFO_SIZE_LIMIT), - deviceInfo, "Using tainted data size: %{public}d as loop bound", size); - for (int32_t i = 0; i < size; i++) { - deviceInfo.push_back(AudioDeviceDescriptor::UnmarshallingPtr(reply)); - } - - return deviceInfo; -} - -std::vector> AudioPolicyProxy::GetDevicesInner(DeviceFlag deviceFlag) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - std::vector> deviceInfo; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, deviceInfo, "WriteInterfaceToken failed"); - data.WriteInt32(static_cast(deviceFlag)); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_DEVICES_INNER), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, deviceInfo, "Get devices failed, error: %d", error); - - int32_t size = reply.ReadInt32(); - CHECK_AND_RETURN_RET_LOG(size > 0 && size <= static_cast(AUDIO_DEVICE_INFO_SIZE_LIMIT), - deviceInfo, "Using tainted data size: %{public}d as loop bound", size); - for (int32_t i = 0; i < size; i++) { - deviceInfo.push_back(AudioDeviceDescriptor::UnmarshallingPtr(reply)); - } - - return deviceInfo; -} - -std::vector> AudioPolicyProxy::GetPreferredOutputDeviceDescriptors( - AudioRendererInfo &rendererInfo, bool forceNoBTPermission) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - std::vector> deviceInfo; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, deviceInfo, "WriteInterfaceToken failed"); - - bool res = rendererInfo.Marshalling(data); - CHECK_AND_RETURN_RET_LOG(res, deviceInfo, "AudioRendererInfo Marshalling() failed"); - - data.WriteBool(forceNoBTPermission); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_ACTIVE_OUTPUT_DEVICE_DESCRIPTORS), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, deviceInfo, "Get out devices failed, error: %d", error); - - int32_t size = reply.ReadInt32(); - CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= static_cast(AUDIO_DEVICE_INFO_SIZE_LIMIT), - deviceInfo, "Using tainted data size: %{public}d as loop bound", size); - for (int32_t i = 0; i < size; i++) { - deviceInfo.push_back(AudioDeviceDescriptor::UnmarshallingPtr(reply)); - } - - return deviceInfo; -} - -std::vector> AudioPolicyProxy::GetPreferredInputDeviceDescriptors( - AudioCapturerInfo &captureInfo) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - std::vector> deviceInfo; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, deviceInfo, "WriteInterfaceToken failed"); - - bool res = captureInfo.Marshalling(data); - CHECK_AND_RETURN_RET_LOG(res, deviceInfo, "AudioCapturerInfo Marshalling() failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_PREFERRED_INTPUT_DEVICE_DESCRIPTORS), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, deviceInfo, "Get preferred input devices failed, error: %d", error); - - int32_t size = reply.ReadInt32(); - CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= static_cast(AUDIO_DEVICE_INFO_SIZE_LIMIT), - deviceInfo, "Using tainted data size: %{public}d as loop bound", size); - for (int32_t i = 0; i < size; i++) { - deviceInfo.push_back(AudioDeviceDescriptor::UnmarshallingPtr(reply)); - } - - return deviceInfo; -} - -std::vector> AudioPolicyProxy::GetOutputDevice( - sptr audioRendererFilter) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - std::vector> deviceInfo; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, deviceInfo, "WriteInterfaceToken failed"); - - bool tmp = audioRendererFilter->Marshalling(data); - CHECK_AND_RETURN_RET_LOG(tmp, deviceInfo, "AudioRendererFilter Marshalling() failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_OUTPUT_DEVICE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, deviceInfo, "Get preferred input devices failed, error: %d", error); - - int32_t size = reply.ReadInt32(); - CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= static_cast(AUDIO_DEVICE_INFO_SIZE_LIMIT), - deviceInfo, "Using tainted data size: %{public}d as loop bound", size); - for (int32_t i = 0; i < size; i++) { - deviceInfo.push_back(AudioDeviceDescriptor::UnmarshallingPtr(reply)); - } - - return deviceInfo; -} - -std::vector> AudioPolicyProxy::GetInputDevice( - sptr audioCapturerFilter) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - std::vector> deviceInfo; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, deviceInfo, "WriteInterfaceToken failed"); - - bool res = audioCapturerFilter->Marshalling(data); - CHECK_AND_RETURN_RET_LOG(res, deviceInfo, "AudioCapturerFilter Marshalling() failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_INPUT_DEVICE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, deviceInfo, "Get preferred input devices failed, error: %d", error); - - int32_t size = reply.ReadInt32(); - CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= static_cast(AUDIO_DEVICE_INFO_SIZE_LIMIT), - deviceInfo, "Using tainted data size: %{public}d as loop bound", size); - for (int32_t i = 0; i < size; i++) { - deviceInfo.push_back(AudioDeviceDescriptor::UnmarshallingPtr(reply)); - } - - return deviceInfo; -} - -int32_t AudioPolicyProxy::SetDeviceActive(InternalDeviceType deviceType, bool active, const int32_t uid) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteInt32(static_cast(deviceType)); - data.WriteBool(active); - data.WriteInt32(uid); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_DEVICE_ACTIVE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "set device active failed, error: %d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::LoadSplitModule(const std::string &splitArgs, const std::string &networkId) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteString(splitArgs); - data.WriteString(networkId); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::LOAD_SPLIT_MODULE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "load split module failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -bool AudioPolicyProxy::IsAllowedPlayback(const int32_t &uid, const int32_t &pid) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteInt32(uid); - data.WriteInt32(pid); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::IS_ALLOWED_PLAYBACK), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "IsAllowedPlayback failed, error: %{public}d", error); - return reply.ReadBool(); -} - -int32_t AudioPolicyProxy::SetInputDevice(const DeviceType deviceType, const uint32_t sessionID, - const SourceType sourceType, bool isRunning) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteInt32(static_cast(deviceType)); - data.WriteUint32(sessionID); - data.WriteInt32(static_cast(sourceType)); - data.WriteBool(isRunning); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_INPUT_DEVICE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SetInputDevice failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetVoiceRingtoneMute(bool isMute) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteBool(isMute); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_VOICE_RINGTONE_MUTE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SetVoiceRingtoneMute failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::NotifySessionStateChange(const int32_t uid, const int32_t pid, const bool hasSession) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteInt32(uid); - data.WriteInt32(pid); - data.WriteBool(hasSession); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::NOFITY_SESSION_STATE_CHANGE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "NotifySessionStateChange failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::NotifyFreezeStateChange(const std::set &pidList, const bool isFreeze) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteBool(isFreeze); - data.WriteInt32(pidList.size()); - for (int32_t pid : pidList) { - data.WriteInt32(pid); - } - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::NOFITY_FREEZE_STATE_CHANGE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "NotifyFreezeStateChange failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::ResetAllProxy() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::RESET_ALL_PROXY), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "ResetAllProxy failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::NotifyProcessBackgroundState(const int32_t uid, const int32_t pid) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteInt32(uid); - data.WriteInt32(pid); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::NOTIFY_PROCESS_BACKGROUND_STATE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "NotifyProcessBackgroundState failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetVirtualCall(const bool isVirtual) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteBool(isVirtual); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_VIRTUAL_CALL), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SetVirtualCall failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -bool AudioPolicyProxy::IsDeviceActive(InternalDeviceType deviceType) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed"); - data.WriteInt32(static_cast(deviceType)); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::IS_DEVICE_ACTIVE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "is device active failed, error: %d", error); - return reply.ReadBool(); -} - -DeviceType AudioPolicyProxy::GetActiveOutputDevice() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, DEVICE_TYPE_INVALID, "WriteInterfaceToken failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_ACTIVE_OUTPUT_DEVICE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, DEVICE_TYPE_INVALID, - "get active output device failed, error: %d", error); - - return static_cast(reply.ReadInt32()); -} - -uint16_t AudioPolicyProxy::GetDmDeviceType() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, DEVICE_TYPE_INVALID, "WriteInterfaceToken failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_DM_DEVICE_TYPE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, DEVICE_TYPE_INVALID, - "get dmDevice failed, error: %d", error); - - return static_cast(reply.ReadUint16()); -} - -DeviceType AudioPolicyProxy::GetActiveInputDevice() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, DEVICE_TYPE_INVALID, "WriteInterfaceToken failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_ACTIVE_INPUT_DEVICE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, DEVICE_TYPE_INVALID, - "get active input device failed, error: %d", error); - - return static_cast(reply.ReadInt32()); -} - -int32_t AudioPolicyProxy::SelectOutputDevice(sptr audioRendererFilter, - std::vector> audioDeviceDescriptors) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - bool tmp = audioRendererFilter->Marshalling(data); - CHECK_AND_RETURN_RET_LOG(tmp, -1, "AudioRendererFilter Marshalling() failed"); - - uint32_t size = audioDeviceDescriptors.size(); - CHECK_AND_RETURN_RET_LOG(size > 0 && size <= AUDIO_DEVICE_INFO_SIZE_LIMIT, - -1, "SelectOutputDevice get invalid device size."); - data.WriteInt32(size); - for (auto audioDeviceDescriptor : audioDeviceDescriptors) { - bool audioDeviceTmp = audioDeviceDescriptor->Marshalling(data); - CHECK_AND_RETURN_RET_LOG(audioDeviceTmp, -1, "AudioDeviceDescriptor Marshalling() failed"); - } - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SELECT_OUTPUT_DEVICE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SelectOutputDevice failed, error: %{public}d", error); - - return reply.ReadInt32(); -} -std::string AudioPolicyProxy::GetSelectedDeviceInfo(int32_t uid, int32_t pid, AudioStreamType streamType) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, "", "WriteInterfaceToken failed"); - data.WriteInt32(uid); - data.WriteInt32(pid); - data.WriteInt32(static_cast(streamType)); - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_SELECTED_DEVICE_INFO), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, "", "GetSelectedDeviceInfo failed, error: %{public}d", error); - - return reply.ReadString(); -} - -int32_t AudioPolicyProxy::SelectInputDevice(sptr audioCapturerFilter, - std::vector> audioDeviceDescriptors) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - bool tmp = audioCapturerFilter->Marshalling(data); - CHECK_AND_RETURN_RET_LOG(tmp, -1, "AudioCapturerFilter Marshalling() failed"); - - uint32_t size = audioDeviceDescriptors.size(); - CHECK_AND_RETURN_RET_LOG(size > 0 && size <= AUDIO_DEVICE_INFO_SIZE_LIMIT, - -1, "SelectOutputDevice get invalid device size."); - data.WriteInt32(size); - for (auto audioDeviceDescriptor : audioDeviceDescriptors) { - bool audioDeviceTmp = audioDeviceDescriptor->Marshalling(data); - CHECK_AND_RETURN_RET_LOG(audioDeviceTmp, -1, "AudioDeviceDescriptor Marshalling() failed"); - } - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SELECT_INPUT_DEVICE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SelectInputDevice failed, error: %{public}d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::ExcludeOutputDevices(AudioDeviceUsage audioDevUsage, - std::vector> &audioDeviceDescriptors) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteInt32(static_cast(audioDevUsage)); - uint32_t size = audioDeviceDescriptors.size(); - CHECK_AND_RETURN_RET_LOG(size > 0 && size <= AUDIO_DEVICE_INFO_SIZE_LIMIT, - -1, "ExcludeOutputDevices get invalid device size."); - data.WriteInt32(size); - for (auto audioDeviceDescriptor : audioDeviceDescriptors) { - bool audioDeviceTmp = audioDeviceDescriptor->Marshalling(data); - CHECK_AND_RETURN_RET_LOG(audioDeviceTmp, -1, "AudioDeviceDescriptor Marshalling() failed"); - } - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::EXCLUDE_OUTPUT_DEVICES), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "ExcludeOutputDevices failed, error: %{public}d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::UnexcludeOutputDevices(AudioDeviceUsage audioDevUsage, - std::vector> &audioDeviceDescriptors) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteInt32(static_cast(audioDevUsage)); - uint32_t size = audioDeviceDescriptors.size(); - CHECK_AND_RETURN_RET_LOG(size > 0 && size <= AUDIO_DEVICE_INFO_SIZE_LIMIT, - -1, "UnexcludeOutputDevices get invalid device size."); - data.WriteInt32(size); - for (auto audioDeviceDescriptor : audioDeviceDescriptors) { - bool audioDeviceTmp = audioDeviceDescriptor->Marshalling(data); - CHECK_AND_RETURN_RET_LOG(audioDeviceTmp, -1, "AudioDeviceDescriptor Marshalling() failed"); - } - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::UNEXCLUDE_OUTPUT_DEVICES), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "UnexcludeOutputDevices failed, error: %{public}d", error); - - return reply.ReadInt32(); -} - -std::vector> AudioPolicyProxy::GetExcludedDevices( - AudioDeviceUsage audioDevUsage) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - std::vector> excludedDevices; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, excludedDevices, "WriteInterfaceToken failed"); - data.WriteInt32(static_cast(audioDevUsage)); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_EXCLUDED_OUTPUT_DEVICES), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, excludedDevices, - "Get excluded output devices failed, error: %d", error); - - int32_t size = reply.ReadInt32(); - CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= static_cast(AUDIO_DEVICE_INFO_SIZE_LIMIT), - excludedDevices, "Using tainted data size: %{public}d as loop bound", size); - for (int32_t i = 0; i < size; i++) { - excludedDevices.push_back(AudioDeviceDescriptor::UnmarshallingPtr(reply)); - } - - return excludedDevices; -} - -int32_t AudioPolicyProxy::ConfigDistributedRoutingRole( - const std::shared_ptr descriptor, CastType type) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - CHECK_AND_RETURN_RET_LOG(descriptor != nullptr, -1, "descriptor is null"); - bool res = descriptor->Marshalling(data); - CHECK_AND_RETURN_RET_LOG(res, -1, "AudioDeviceDescriptor marshalling failed"); - data.WriteInt32(static_cast(type)); - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::CONFIG_DISTRIBUTED_ROUTING_ROLE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "failed error : %{public}d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::ActivateAudioSession(const AudioSessionStrategy &strategy) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteInt32(static_cast(strategy.concurrencyMode)); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::ACTIVATE_AUDIO_SESSION), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Failed to activate audio session. Error: %{public}d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::DeactivateAudioSession() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::DEACTIVATE_AUDIO_SESSION), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Failed to deactivate audio session. Error: %{public}d", error); - - return reply.ReadInt32(); -} - -bool AudioPolicyProxy::IsAudioSessionActivated() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed"); - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::IS_AUDIO_SESSION_ACTIVATED), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, - "Failed to query IsAudioSessionActivated, error: %{public}d", error); - - return reply.ReadBool(); -} - -int32_t AudioPolicyProxy::SetAudioSessionScene(const AudioSessionScene audioSessionScene) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteInt32(static_cast(audioSessionScene)); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_AUDIO_SESSION_SCENE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Failed to audioSessionScene. Error: %{public}d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::GetDefaultOutputDevice(DeviceType &deviceType) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_SESSION_DEFAULT_OUTPUT_DEVICE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "GetDefaultOutputDevice failed, Error: %{public}d", error); - - deviceType = static_cast(reply.ReadInt32()); - return SUCCESS; -} - -int32_t AudioPolicyProxy::SetDefaultOutputDevice(DeviceType deviceType) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteInt32(static_cast(deviceType)); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_SESSION_DEFAULT_OUTPUT_DEVICE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SetDefaultOutputDevice failed, Error: %{public}d", error); - - return reply.ReadInt32(); -} - -void AudioPolicyProxy::ReadAudioFocusInfo(MessageParcel &reply, - std::list> &focusInfoList) -{ - std::pair focusInfo; - AudioInterrupt::Unmarshalling(reply, focusInfo.first); - focusInfo.second = static_cast(reply.ReadInt32()); - focusInfoList.push_back(focusInfo); -} - -int32_t AudioPolicyProxy::GetAudioFocusInfoList(std::list> &focusInfoList, - const int32_t zoneID) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool res = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(res, ERROR, "WriteInterfaceToken failed"); - data.WriteInt32(zoneID); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_AUDIO_FOCUS_INFO_LIST), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "GetAudioFocusInfoList, error: %d", error); - int32_t ret = reply.ReadInt32(); - int32_t size = reply.ReadInt32(); - CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= AUDIO_INTERRUPT_INFO_SIZE_LIMIT, - ERROR, "Using tainted data focusInfoSize:%{public}d as loop bound", size); - focusInfoList = {}; - if (ret < 0) { - return ret; - } else { - for (int32_t i = 0; i < size; i++) { - ReadAudioFocusInfo(reply, focusInfoList); - } - return SUCCESS; - } -} - -int32_t AudioPolicyProxy::ActivateAudioInterrupt( - AudioInterrupt &audioInterrupt, const int32_t zoneID, const bool isUpdatedAudioStrategy) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteInt32(zoneID); - data.WriteBool(isUpdatedAudioStrategy); - ret = AudioInterrupt::Marshalling(data, audioInterrupt); - CHECK_AND_RETURN_RET_LOG(ret, -1, "Marshalling failed"); - - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::ACTIVATE_INTERRUPT), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "activate interrupt failed, error: %{public}d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::DeactivateAudioInterrupt(const AudioInterrupt &audioInterrupt, const int32_t zoneID) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteInt32(zoneID); - ret = AudioInterrupt::Marshalling(data, audioInterrupt); - CHECK_AND_RETURN_RET_LOG(ret, -1, "Marshalling failed"); - - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::DEACTIVATE_INTERRUPT), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "deactivate interrupt failed, error: %{public}d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::ActivatePreemptMode() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::ACTIVATE_PREEMPT_MODE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "activate preemptMode failed, error: %{public}d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::DeactivatePreemptMode() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::DEACTIVATE_PREEMPT_MODE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "deactivate preemptMode failed, error: %{public}d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::CheckVKBInfo(const std::string &bundleName, bool &isValid) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - - data.WriteString(bundleName); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::CHECK_VKB_INFO), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "CheckVKBInfo failed, error: %d", error); - isValid = reply.ReadBool(); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::RequestAudioFocus(const int32_t clientId, const AudioInterrupt &audioInterrupt) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - - data.WriteInt32(clientId); - ret = AudioInterrupt::Marshalling(data, audioInterrupt); - CHECK_AND_RETURN_RET_LOG(ret, -1, "Marshalling failed"); - - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::REQUEST_AUDIO_FOCUS), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "activate interrupt failed, error: %{public}d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::AbandonAudioFocus(const int32_t clientId, const AudioInterrupt &audioInterrupt) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteInt32(clientId); - ret = AudioInterrupt::Marshalling(data, audioInterrupt); - CHECK_AND_RETURN_RET_LOG(ret, -1, "Marshalling failed"); - - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::ABANDON_AUDIO_FOCUS), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "deactivate interrupt failed, error: %{public}d", error); - - return reply.ReadInt32(); -} - -AudioStreamType AudioPolicyProxy::GetStreamInFocus(const int32_t zoneID) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, STREAM_DEFAULT, "WriteInterfaceToken failed"); - data.WriteInt32(zoneID); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_STREAM_IN_FOCUS), data, reply, option); - if (error != ERR_NONE) { - AUDIO_ERR_LOG("get stream in focus failed, error: %d", error); - } - return static_cast(reply.ReadInt32()); -} - -AudioStreamType AudioPolicyProxy::GetStreamInFocusByUid(const int32_t uid, const int32_t zoneID) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, STREAM_DEFAULT, "WriteInterfaceToken failed"); - data.WriteInt32(zoneID); - data.WriteInt32(uid); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_STREAM_IN_FOCUS_BY_UID), data, reply, option); - if (error != ERR_NONE) { - AUDIO_ERR_LOG("get stream in focus by uid failed, error: %d", error); - } - return static_cast(reply.ReadInt32()); -} - -int32_t AudioPolicyProxy::GetSessionInfoInFocus(AudioInterrupt &audioInterrupt, const int32_t zoneID) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteInt32(zoneID); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_SESSION_INFO_IN_FOCUS), data, reply, option); - if (error != ERR_NONE) { - AUDIO_ERR_LOG("AudioPolicyProxy::GetSessionInfoInFocus failed, error: %d", error); - } - AudioInterrupt::Unmarshalling(reply, audioInterrupt); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::ReconfigureAudioChannel(const uint32_t &count, DeviceType deviceType) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, IPC_PROXY_ERR, "WriteInterfaceToken failed"); - - data.WriteUint32(count); - data.WriteInt32(deviceType); - - int result = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::RECONFIGURE_CHANNEL), data, reply, option); - CHECK_AND_RETURN_RET_LOG(result == ERR_NONE, ERR_TRANSACTION_FAILED, - "ReconfigureAudioChannel failed, result: %{public}d", result); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::GetPreferredOutputStreamType(AudioRendererInfo &rendererInfo) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, AUDIO_FLAG_INVALID, "WriteInterfaceToken failed"); - - ret = rendererInfo.Marshalling(data); - CHECK_AND_RETURN_RET_LOG(ret, AUDIO_FLAG_INVALID, "Marshalling rendererInfo failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_PREFERRED_OUTPUT_STREAM_TYPE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, AUDIO_FLAG_INVALID, "Failed to send request, error: %{public}d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::GetPreferredInputStreamType(AudioCapturerInfo &capturerInfo) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, AUDIO_FLAG_INVALID, "WriteInterfaceToken failed"); - - ret = capturerInfo.Marshalling(data); - CHECK_AND_RETURN_RET_LOG(ret, AUDIO_FLAG_INVALID, "Marshalling capturerInfo failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_PREFERRED_INPUT_STREAM_TYPE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, AUDIO_FLAG_INVALID, "Failed to send request, error: %{public}d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::CreateRendererClient( - std::shared_ptr streamDesc, uint32_t &flag, uint32_t &sessionId) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, AUDIO_FLAG_INVALID, "WriteInterfaceToken failed"); - - ret = streamDesc->Marshalling(data); - CHECK_AND_RETURN_RET_LOG(ret, AUDIO_FLAG_INVALID, "Marshalling capturerInfo failed"); - - data.WriteUint32(sessionId); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::CREATE_RENDERER_CLIENT), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, AUDIO_FLAG_INVALID, "Failed to send request, error: %{public}d", error); - - flag = static_cast(reply.ReadUint32()); - sessionId = reply.ReadUint32(); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::CreateCapturerClient( - std::shared_ptr streamDesc, uint32_t &flag, uint32_t &sessionId) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, AUDIO_FLAG_INVALID, "WriteInterfaceToken failed"); - - ret = streamDesc->Marshalling(data); - CHECK_AND_RETURN_RET_LOG(ret, AUDIO_FLAG_INVALID, "Marshalling capturerInfo failed"); - - data.WriteUint32(sessionId); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::CREATE_CAPTURER_CLIENT), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, AUDIO_FLAG_INVALID, "Failed to send request, error: %{public}d", error); - - flag = static_cast(reply.ReadUint32()); - sessionId = reply.ReadUint32(); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::RegisterTracker(AudioMode &mode, AudioStreamChangeInfo &streamChangeInfo, - const sptr &object) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed"); - - CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT, "Register Tracker Event object is null"); - - data.WriteUint32(mode); - WriteStreamChangeInfo(data, mode, streamChangeInfo); - data.WriteRemoteObject(object); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::REGISTER_TRACKER), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "event failed , error: %d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::UpdateTracker(AudioMode &mode, AudioStreamChangeInfo &streamChangeInfo) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed"); - - data.WriteUint32(mode); - WriteStreamChangeInfo(data, mode, streamChangeInfo); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::UPDATE_TRACKER), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "UpdateTracker event failed , error: %d", error); - - return reply.ReadInt32(); -} - -void AudioPolicyProxy::FetchOutputDeviceForTrack(AudioStreamChangeInfo &streamChangeInfo, - const AudioStreamDeviceChangeReasonExt reason) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - if (!ret) { - AUDIO_ERR_LOG("WriteInterfaceToken failed"); - } - - streamChangeInfo.audioRendererChangeInfo.Marshalling(data); - - data.WriteInt32(static_cast(reason)); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::FETCH_OUTPUT_DEVICE_FOR_TRACK), data, reply, option); - if (error != ERR_NONE) { - AUDIO_ERR_LOG("event failed , error: %d", error); - } - return; -} - -void AudioPolicyProxy::FetchInputDeviceForTrack(AudioStreamChangeInfo &streamChangeInfo) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - if (!ret) { - AUDIO_ERR_LOG("WriteInterfaceToken failed"); - } - - streamChangeInfo.audioCapturerChangeInfo.Marshalling(data); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::FETCH_INPUT_DEVICE_FOR_TRACK), data, reply, option); - if (error != ERR_NONE) { - AUDIO_ERR_LOG("event failed , error: %d", error); - } - return; -} - -int32_t AudioPolicyProxy::GetCurrentRendererChangeInfos( - vector> &audioRendererChangeInfos) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_RENDERER_CHANGE_INFOS), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "Get Renderer change info event failed , error: %d", error); - - int32_t size = reply.ReadInt32(); - while (size > 0) { - shared_ptr rendererChangeInfo = make_shared(); - CHECK_AND_RETURN_RET_LOG(rendererChangeInfo != nullptr, ERR_MEMORY_ALLOC_FAILED, "No memory!!"); - rendererChangeInfo->Unmarshalling(reply); - audioRendererChangeInfos.push_back(move(rendererChangeInfo)); - size--; - } - - return SUCCESS; -} - -int32_t AudioPolicyProxy::GetCurrentCapturerChangeInfos( - vector> &audioCapturerChangeInfos) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - AUDIO_DEBUG_LOG("AudioPolicyProxy::GetCurrentCapturerChangeInfos"); - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_CAPTURER_CHANGE_INFOS), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "Get capturer change info event failed , error: %d", error); - - int32_t size = reply.ReadInt32(); - while (size > 0) { - shared_ptr capturerChangeInfo = make_shared(); - CHECK_AND_RETURN_RET_LOG(capturerChangeInfo != nullptr, ERR_MEMORY_ALLOC_FAILED, "No memory!!"); - capturerChangeInfo->Unmarshalling(reply); - audioCapturerChangeInfos.push_back(move(capturerChangeInfo)); - size--; - } - - return SUCCESS; -} - -int32_t AudioPolicyProxy::UpdateStreamState(const int32_t clientUid, StreamSetState streamSetState, - StreamUsage streamUsage) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed"); - - data.WriteInt32(static_cast(clientUid)); - data.WriteInt32(static_cast(streamSetState)); - data.WriteInt32(static_cast(streamUsage)); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::UPDATE_STREAM_STATE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, - "UPDATE_STREAM_STATE stream changed info event failed , error: %d", error); - - return SUCCESS; -} - -int32_t AudioPolicyProxy::GetNetworkIdByGroupId(int32_t groupId, std::string &networkId) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool res = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(res, ERROR, "WriteInterfaceToken failed"); - data.WriteInt32(groupId); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_NETWORKID_BY_GROUP_ID), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "GetNetworkIdByGroupId, error: %d", error); - - networkId = reply.ReadString(); - int32_t ret = reply.ReadInt32(); - return ret; -} - -int32_t AudioPolicyProxy::SetSystemSoundUri(const std::string &key, const std::string &uri) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, IPC_PROXY_ERR, "WriteInterfaceToken failed"); - data.WriteString(key); - data.WriteString(uri); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_SYSTEM_SOUND_URI), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SetSystemSoundUri failed, error: %d", error); - return reply.ReadInt32(); -} - -std::string AudioPolicyProxy::GetSystemSoundUri(const std::string &key) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, "", "WriteInterfaceToken failed"); - data.WriteString(key); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_SYSTEM_SOUND_URI), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, "", "GetSystemSoundUri failed, error: %d", error); - return reply.ReadString(); -} - -int32_t AudioPolicyProxy::GetMaxRendererInstances() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed"); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_MAX_RENDERER_INSTANCES), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "GetMaxRendererInstances failed, error: %d", error); - return reply.ReadInt32(); -} - -static void PreprocessMode(Stream &stream, MessageParcel &reply, int countMode) -{ - for (int j = 0; j < countMode; j++) { - StreamEffectMode streamEffectMode; - streamEffectMode.mode = reply.ReadString(); - int countDev = reply.ReadInt32(); - if (countDev > 0) { - for (int k = 0; k < countDev; k++) { - string type = reply.ReadString(); - string chain = reply.ReadString(); - streamEffectMode.devicePort.push_back({type, chain}); - } - } - stream.streamEffectMode.push_back(streamEffectMode); - } -} - -static Stream PreprocessProcess(MessageParcel &reply) -{ - Stream stream; - stream.scene = reply.ReadString(); - int countMode = reply.ReadInt32(); - if (countMode > 0) { - PreprocessMode(stream, reply, countMode); - } - return stream; -} - -static void PostprocessMode(Stream &stream, MessageParcel &reply, int countMode) -{ - for (int j = 0; j < countMode; j++) { - StreamEffectMode streamEffectMode; - streamEffectMode.mode = reply.ReadString(); - int countDev = reply.ReadInt32(); - if (countDev > 0) { - for (int k = 0; k < countDev; k++) { - string type = reply.ReadString(); - string chain = reply.ReadString(); - streamEffectMode.devicePort.push_back({type, chain}); - } - } - stream.streamEffectMode.push_back(streamEffectMode); - } -} - -static Stream PostprocessProcess(MessageParcel &reply) -{ - Stream stream; - stream.scene = reply.ReadString(); - int countMode = reply.ReadInt32(); - if (countMode > 0) { - PostprocessMode(stream, reply, countMode); - } - return stream; -} - -static int32_t QueryEffectSceneModeChkReply(uint32_t countPre, uint32_t countPost) -{ - CHECK_AND_RETURN_RET_LOG((countPre >= 0) && (countPre <= AUDIO_EFFECT_COUNT_UPPER_LIMIT), -1, - "QUERY_EFFECT_SCENEMODE read replyParcel failed"); - CHECK_AND_RETURN_RET_LOG((countPost >= 0) && (countPost <= AUDIO_EFFECT_COUNT_UPPER_LIMIT), -1, - "QUERY_EFFECT_SCENEMODE read replyParcel failed"); - return 0; -} - -int32_t AudioPolicyProxy::QueryEffectSceneMode(SupportedEffectConfig &supportedEffectConfig) -{ - uint32_t i; - int32_t error; - MessageParcel data; - MessageParcel reply; - MessageOption option; - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::QUERY_EFFECT_SCENEMODE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "get scene & mode failed, error: %d", error); - uint32_t countPre = reply.ReadUint32(); - uint32_t countPost = reply.ReadUint32(); - uint32_t countPostMap = reply.ReadUint32(); - error = QueryEffectSceneModeChkReply(countPre, countPost); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "get scene & mode failed, error: %d", error); - // preprocess - Stream stream; - if (countPre > 0) { - ProcessNew preProcessNew; - for (i = 0; i < countPre; i++) { - stream = PreprocessProcess(reply); - preProcessNew.stream.push_back(stream); - } - supportedEffectConfig.preProcessNew = preProcessNew; - } - // postprocess - if (countPost > 0) { - ProcessNew postProcessNew; - for (i = 0; i < countPost; i++) { - stream = PostprocessProcess(reply); - postProcessNew.stream.push_back(stream); - } - supportedEffectConfig.postProcessNew = postProcessNew; - } - if (countPostMap > 0) { - SceneMappingItem item; - for (i = 0; i < countPostMap; i++) { - item.name = reply.ReadString(); - item.sceneType = reply.ReadString(); - supportedEffectConfig.postProcessSceneMap.push_back(item); - } - } - return 0; -} - -int32_t AudioPolicyProxy::GetHardwareOutputSamplingRate(const std::shared_ptr &desc) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - - bool result = desc->Marshalling(data); - CHECK_AND_RETURN_RET_LOG(result, -1, "AudioDeviceDescriptor Marshalling() failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_HARDWARE_OUTPUT_SAMPLING_RATE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "event failed , error: %d", error); - - return reply.ReadInt32(); -} - -std::vector> AudioPolicyProxy::GetAvailableDevices(AudioDeviceUsage usage) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - std::vector> audioDeviceDescriptors; - - CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), - audioDeviceDescriptors, "WriteInterfaceToken failed"); - - bool token = data.WriteInt32(static_cast(usage)); - CHECK_AND_RETURN_RET_LOG(token, audioDeviceDescriptors, "WriteInt32 usage failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_AVAILABLE_DESCRIPTORS), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, audioDeviceDescriptors, "GetAvailableDevices failed, error: %d", error); - - int32_t size = reply.ReadInt32(); - CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= static_cast(AUDIO_DEVICE_INFO_SIZE_LIMIT), - audioDeviceDescriptors, "Using tainted data size: %{public}d as loop bound", size); - for (int32_t i = 0; i < size; i++) { - std::shared_ptr desc = - std::make_shared(AudioDeviceDescriptor::UnmarshallingPtr(reply)); - audioDeviceDescriptors.push_back(move(desc)); - } - return audioDeviceDescriptors; -} - -bool AudioPolicyProxy::IsSpatializationEnabled() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::IS_SPATIALIZATION_ENABLED), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "IsSpatializationEnabled failed, error: %{public}d", error); - return reply.ReadBool(); -} - -bool AudioPolicyProxy::IsSpatializationEnabled(const std::string address) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed"); - data.WriteString(address); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::IS_SPATIALIZATION_ENABLED_FOR_DEVICE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "IsSpatializationEnabled failed, error: %{public}d", error); - return reply.ReadBool(); -} - -bool AudioPolicyProxy::IsSpatializationEnabledForCurrentDevice() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::IS_SPATIALIZATION_ENABLED_FOR_CURRENT_DEVICE), - data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "IsSpatializationEnabled failed, error: %{public}d", error); - return reply.ReadBool(); -} - -int32_t AudioPolicyProxy::SetSpatializationEnabled(const bool enable) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed"); - data.WriteBool(enable); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_SPATIALIZATION_ENABLED), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "SetSpatializationEnabled failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetSpatializationEnabled(const std::shared_ptr &selectedAudioDevice, - const bool enable) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed"); - - bool result = selectedAudioDevice->Marshalling(data); - CHECK_AND_RETURN_RET_LOG(result, -1, "SelectedAudioDevice Marshalling() failed"); - - data.WriteBool(enable); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_SPATIALIZATION_ENABLED_FOR_DEVICE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "SetSpatializationEnabled failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -bool AudioPolicyProxy::IsHeadTrackingEnabled() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::IS_HEAD_TRACKING_ENABLED), data, reply, option); - - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "IsHeadTrackingEnabled failed, error: %{public}d", error); - return reply.ReadBool(); -} - -bool AudioPolicyProxy::IsHeadTrackingEnabled(const std::string address) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed"); - data.WriteString(address); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::IS_HEAD_TRACKING_ENABLED_FOR_DEVICE), data, reply, option); - - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "IsHeadTrackingEnabled failed, error: %{public}d", error); - return reply.ReadBool(); -} - -int32_t AudioPolicyProxy::SetHeadTrackingEnabled(const bool enable) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed"); - data.WriteBool(enable); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_HEAD_TRACKING_ENABLED), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "SetHeadTrackingEnabled failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetHeadTrackingEnabled(const std::shared_ptr &selectedAudioDevice, - const bool enable) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed"); - - bool result = selectedAudioDevice->Marshalling(data); - CHECK_AND_RETURN_RET_LOG(result, -1, "SelectedAudioDevice Marshalling() failed"); - data.WriteBool(enable); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_HEAD_TRACKING_ENABLED_FOR_DEVICE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "SetHeadTrackingEnabled failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -AudioSpatializationState AudioPolicyProxy::GetSpatializationState(const StreamUsage streamUsage) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - AudioSpatializationState spatializationState = {false, false}; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, spatializationState, "WriteInterfaceToken failed"); - - data.WriteInt32(static_cast(streamUsage)); - int32_t error = Remote() ->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_SPATIALIZATION_STATE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, spatializationState, "SendRequest failed, error: %{public}d", error); - - spatializationState.spatializationEnabled = reply.ReadBool(); - spatializationState.headTrackingEnabled = reply.ReadBool(); - - return spatializationState; -} - -bool AudioPolicyProxy::IsSpatializationSupported() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::IS_SPATIALIZATION_SUPPORTED), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "IsSpatializationSupported failed, error: %d", error); - return reply.ReadBool(); -} - -bool AudioPolicyProxy::IsSpatializationSupportedForDevice(const std::string address) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed"); - data.WriteString(address); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::IS_SPATIALIZATION_SUPPORTED_FOR_DEVICE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "IsSpatializationSupportedForDevice failed, error: %d", error); - return reply.ReadBool(); -} - -bool AudioPolicyProxy::IsHeadTrackingSupported() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::IS_HEAD_TRACKING_SUPPORTED), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "IsHeadTrackingSupported failed, error: %d", error); - return reply.ReadBool(); -} - -bool AudioPolicyProxy::IsHeadTrackingSupportedForDevice(const std::string address) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed"); - data.WriteString(address); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::IS_HEAD_TRACKING_SUPPORTED_FOR_DEVICE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "IsHeadTrackingSupportedForDevice failed, error: %d", error); - return reply.ReadBool(); -} - -int32_t AudioPolicyProxy::UpdateSpatialDeviceState(const AudioSpatialDeviceState audioSpatialDeviceState) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed"); - data.WriteString(audioSpatialDeviceState.address); - data.WriteBool(audioSpatialDeviceState.isSpatializationSupported); - data.WriteBool(audioSpatialDeviceState.isHeadTrackingSupported); - data.WriteInt32(static_cast(audioSpatialDeviceState.spatialDeviceType)); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::UPDATE_SPATIAL_DEVICE_STATE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "UpdateSpatialDeviceState failed, error: %d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::CreateAudioInterruptZone(const std::set &pids, const int32_t zoneID) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), -1, "WriteInterfaceToken failed"); - - data.WriteInt32(zoneID); - data.WriteInt32(pids.size()); - int32_t count = 0; - for (int32_t pid : pids) { - data.WriteInt32(pid); - count++; - if (count >= MAX_PID_COUNT) { - break; - } - } - - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::CREATE_AUDIO_INTERRUPT_ZONE), data, reply, option); - - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "CreateAudioInterruptZone failed, error: %d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::AddAudioInterruptZonePids(const std::set &pids, const int32_t zoneID) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), -1, "WriteInterfaceToken failed"); - data.WriteInt32(zoneID); - data.WriteInt32(pids.size()); - int32_t count = 0; - for (int32_t pid : pids) { - data.WriteInt32(pid); - count++; - if (count >= MAX_PID_COUNT) { - break; - } - } - - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::ADD_AUDIO_INTERRUPT_ZONE_PIDS), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "AddAudioInterruptZonePids failed, error: %d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::RemoveAudioInterruptZonePids(const std::set &pids, const int32_t zoneID) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), -1, "WriteInterfaceToken failed"); - data.WriteInt32(zoneID); - data.WriteInt32(pids.size()); - int32_t count = 0; - for (int32_t pid : pids) { - data.WriteInt32(pid); - count++; - if (count >= MAX_PID_COUNT) { - break; - } - } - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::REMOVE_AUDIO_INTERRUPT_ZONE_PIDS), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "RemoveAudioInterruptZonePids failed, error: %d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::ReleaseAudioInterruptZone(const int32_t zoneID) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), -1, "WriteInterfaceToken failed"); - data.WriteInt32(zoneID); - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::RELEASE_AUDIO_INTERRUPT_ZONE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "ReleaseAudioInterruptZone failed, error: %d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetCallDeviceActive(InternalDeviceType deviceType, bool active, std::string address, - const int32_t uid) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteInt32(static_cast(deviceType)); - data.WriteBool(active); - data.WriteString(address); - data.WriteInt32(uid); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_CALL_DEVICE_ACTIVE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %d", error); - return reply.ReadInt32(); -} - -std::shared_ptr AudioPolicyProxy::GetActiveBluetoothDevice() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - std::shared_ptr audioDeviceDescriptor; - - CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), - audioDeviceDescriptor, "WriteInterfaceToken failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_ACTIVE_BLUETOOTH_DESCRIPTOR), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, audioDeviceDescriptor, - "GetActiveBluetoothDevice failed, error: %d", error); - - std::shared_ptr desc = - std::make_shared(AudioDeviceDescriptor::UnmarshallingPtr(reply)); - return desc; -} - -ConverterConfig AudioPolicyProxy::GetConverterConfig() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - ConverterConfig result; - - CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), result, "WriteInterfaceToken failed"); - int32_t error = Remote()->SendRequest(static_cast(AudioPolicyInterfaceCode::GET_AUDIO_CONVERTER_CONFIG), - data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, result, "failed, error: %d", error); - - result.library = {reply.ReadString(), reply.ReadString()}; - result.outChannelLayout = reply.ReadUint64(); - return result; -} - -bool AudioPolicyProxy::IsHighResolutionExist() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed"); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::IS_HIGH_RESOLUTION_EXIST), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERR_TRANSACTION_FAILED, "SendRequest failed, error: %d", error); - - bool replyReadBool = reply.ReadBool(); - return replyReadBool; -} - -int32_t AudioPolicyProxy::SetHighResolutionExist(bool highResExist) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - - data.WriteBool(highResExist); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_HIGH_RESOLUTION_EXIST), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %d", error); - return SUCCESS; -} - -AudioSpatializationSceneType AudioPolicyProxy::GetSpatializationSceneType() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, SPATIALIZATION_SCENE_TYPE_MUSIC, "WriteInterfaceToken failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_SPATIALIZATION_SCENE_TYPE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, SPATIALIZATION_SCENE_TYPE_MUSIC, - "SendRequest failed, error: %{public}d", error); - return static_cast(reply.ReadInt32()); -} - -int32_t AudioPolicyProxy::SetSpatializationSceneType(const AudioSpatializationSceneType spatializationSceneType) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed"); - data.WriteInt32(static_cast(spatializationSceneType)); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_SPATIALIZATION_SCENE_TYPE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "SendRequest failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -float AudioPolicyProxy::GetMaxAmplitude(const int32_t deviceId) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - - data.WriteInt32(deviceId); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_MAX_AMPLITUDE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error); - return reply.ReadFloat(); -} - -bool AudioPolicyProxy::IsHeadTrackingDataRequested(const std::string &macAddress) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed"); - data.WriteString(macAddress); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::IS_HEAD_TRACKING_DATA_REQUESTED), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "SendRequest failed, error: %d", error); - return reply.ReadBool(); -} - -int32_t AudioPolicyProxy::TriggerFetchDevice(AudioStreamDeviceChangeReasonExt reason) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - - data.WriteInt32(static_cast(reason)); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::TRIGGER_FETCH_DEVICE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetPreferredDevice(const PreferredType preferredType, - const std::shared_ptr &desc, const int32_t uid) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - - data.WriteInt32(static_cast(preferredType)); - data.WriteInt32(static_cast(uid)); - bool result = desc->Marshalling(data); - CHECK_AND_RETURN_RET_LOG(result, -1, "Desc Marshalling() faild"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_PREFERRED_DEVICE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "SendRequest failed, error: %d", error); - return reply.ReadInt32(); -} - -void AudioPolicyProxy::SaveRemoteInfo(const std::string &networkId, DeviceType deviceType) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - if (!ret) { - AUDIO_ERR_LOG("WriteInterfaceToken failed"); - } - - data.WriteString(networkId); - data.WriteInt32(static_cast(deviceType)); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SAVE_REMOTE_INFO), data, reply, option); - if (error != ERR_NONE) { - AUDIO_ERR_LOG("SendRequest failed, error: %{public}d", error); - } -} - -int32_t AudioPolicyProxy::SetAudioDeviceAnahsCallback(const sptr &object) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT, "object is null"); - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - - (void)data.WriteRemoteObject(object); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_AUDIO_DEVICE_ANAHS_CALLBACK), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::UnsetAudioDeviceAnahsCallback() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::UNSET_AUDIO_DEVICE_ANAHS_CALLBACK), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::MoveToNewPipe(const uint32_t sessionId, const AudioPipeType pipeType) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed"); - data.WriteUint32(sessionId); - data.WriteInt32(pipeType); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::MOVE_TO_NEW_PIPE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "SendRequest failed, error: %d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::ActivateAudioConcurrency(const AudioPipeType &pipeType) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteInt32(pipeType); - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::ACTIVATE_AUDIO_CONCURRENCY), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "activate concurrency failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::GetSupportedAudioEffectProperty(AudioEffectPropertyArrayV3 &propertyArray) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool res = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(res, ERROR, "WriteInterfaceToken failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_SUPPORT_AUDIO_EFFECT_PROPERTY_V3), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Get Supported Audio Effect Property, error: %d", error); - int32_t result = reply.ReadInt32(); - int32_t size = reply.ReadInt32(); - CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT, - ERROR_INVALID_PARAM, "get audio supported effect property array size invalid"); - for (int32_t i = 0; i < size; i++) { - AudioEffectPropertyV3 prop = {}; - prop.Unmarshalling(reply); - // write and read must keep same order - propertyArray.property.push_back(prop); - } - return result; -} - -int32_t AudioPolicyProxy::GetAudioEffectProperty(AudioEffectPropertyArrayV3 &propertyArray) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool res = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(res, ERROR, "WriteInterfaceToken failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_AUDIO_EFFECT_PROPERTY_V3), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Get Audio Effect Property, error: %d", error); - int32_t result = reply.ReadInt32(); - int32_t size = reply.ReadInt32(); - CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT, - ERROR_INVALID_PARAM, "get audio effect property array size invalid"); - for (int32_t i = 0; i < size; i++) { - AudioEffectPropertyV3 prop = {}; - prop.Unmarshalling(reply); - // write and read must keep same order - propertyArray.property.push_back(prop); - } - return result; -} - -int32_t AudioPolicyProxy::SetAudioEffectProperty(const AudioEffectPropertyArrayV3 &propertyArray) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed"); - - int32_t size = static_cast(propertyArray.property.size()); - data.WriteInt32(size); - CHECK_AND_RETURN_RET_LOG(size > 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT, - ERROR_INVALID_PARAM, "set audio effect property array size invalid"); - for (int32_t i = 0; i < size; i++) { - propertyArray.property[i].Marshalling(data); - } - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_AUDIO_EFFECT_PROPERTY_V3), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::GetSupportedAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool res = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(res, ERROR, "WriteInterfaceToken failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_SUPPORT_AUDIO_ENHANCE_PROPERTY), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Get Supported Audio Enhance Property, error: %d", error); - - int32_t size = reply.ReadInt32(); - CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT, - ERROR_INVALID_PARAM, "get audio supported enhance property array size invalid"); - for (int32_t i = 0; i < size; i++) { - // write and read must keep same order - AudioEnhanceProperty prop = {}; - prop.Unmarshalling(reply); - propertyArray.property.push_back(prop); - } - return AUDIO_OK; -} - -int32_t AudioPolicyProxy::GetSupportedAudioEffectProperty(AudioEffectPropertyArray &propertyArray) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool res = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(res, ERROR, "WriteInterfaceToken failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_SUPPORT_AUDIO_EFFECT_PROPERTY), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Get Supported Audio Effect Property, error: %d", error); - - int32_t size = reply.ReadInt32(); - CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT, - ERROR_INVALID_PARAM, "get audio supported effect property array size invalid"); - for (int32_t i = 0; i < size; i++) { - AudioEffectProperty prop = {}; - prop.Unmarshalling(reply); - // write and read must keep same order - propertyArray.property.push_back(prop); - } - return AUDIO_OK; -} - -int32_t AudioPolicyProxy::GetAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool res = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(res, ERROR, "WriteInterfaceToken failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_AUDIO_ENHANCE_PROPERTY), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Get Audio Enhance Property, error: %d", error); - - int32_t size = reply.ReadInt32(); - CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT, - ERROR_INVALID_PARAM, "get audio enhance property array size invalid"); - for (int32_t i = 0; i < size; i++) { - // write and read must keep same order - AudioEnhanceProperty prop = {}; - prop.Unmarshalling(reply); - propertyArray.property.push_back(prop); - } - return AUDIO_OK; -} - -int32_t AudioPolicyProxy::GetAudioEffectProperty(AudioEffectPropertyArray &propertyArray) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool res = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(res, ERROR, "WriteInterfaceToken failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_AUDIO_EFFECT_PROPERTY), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Get Audio Effect Property, error: %d", error); - - int32_t size = reply.ReadInt32(); - CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT, - ERROR_INVALID_PARAM, "get audio effect property array size invalid"); - for (int32_t i = 0; i < size; i++) { - AudioEffectProperty prop = {}; - prop.Unmarshalling(reply); - // write and read must keep same order - propertyArray.property.push_back(prop); - } - return AUDIO_OK; -} - -int32_t AudioPolicyProxy::SetAudioEnhanceProperty(const AudioEnhancePropertyArray &propertyArray) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed"); - - int32_t size = static_cast(propertyArray.property.size()); - data.WriteInt32(size); - CHECK_AND_RETURN_RET_LOG(size > 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT, - ERROR_INVALID_PARAM, "set audio enhance property array size invalid"); - for (int32_t i = 0; i < size; i++) { - // write and read must keep same order - propertyArray.property[i].Marshalling(data); - } - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_AUDIO_ENHANCE_PROPERTY), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "SendRequest failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetAudioEffectProperty(const AudioEffectPropertyArray &propertyArray) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed"); - - int32_t size = static_cast(propertyArray.property.size()); - data.WriteInt32(size); - CHECK_AND_RETURN_RET_LOG(size > 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT, - ERROR_INVALID_PARAM, "set audio effect property array size invalid"); - for (int32_t i = 0; i < size; i++) { - propertyArray.property[i].Marshalling(data); - } - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_AUDIO_EFFECT_PROPERTY), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "SendRequest failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::InjectInterruption(const std::string networkId, InterruptEvent &event) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteString(networkId); - data.WriteInt32(event.eventType); - data.WriteInt32(event.forceType); - data.WriteInt32(event.hintType); - - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::INJECT_INTERRUPTION), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetDeviceConnectionStatus(const std::shared_ptr &desc, - const bool isConnected) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - - bool res = desc->Marshalling(data); - CHECK_AND_RETURN_RET_LOG(res, -1, "Desc Marshalling() failed"); - data.WriteBool(isConnected); - - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_DEVICE_CONNECTION_STATUS), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -DirectPlaybackMode AudioPolicyProxy::GetDirectPlaybackSupport(const AudioStreamInfo &streamInfo, - const StreamUsage &streamUsage) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, DIRECT_PLAYBACK_NOT_SUPPORTED, "WriteInterfaceToken failed"); - - bool res = streamInfo.Marshalling(data); - CHECK_AND_RETURN_RET_LOG(res, DIRECT_PLAYBACK_NOT_SUPPORTED, "streamInfo Marshalling() failed"); - data.WriteInt32(static_cast(streamUsage)); - - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_DIRECT_PLAYBACK_SUPPORT), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, DIRECT_PLAYBACK_NOT_SUPPORTED, "SendRequest failed, error: %{public}d", - error); - return static_cast(reply.ReadInt32()); -} - -bool AudioPolicyProxy::IsAcousticEchoCancelerSupported(SourceType sourceType) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed"); - - data.WriteInt32(static_cast(sourceType)); - - CHECK_AND_RETURN_RET_LOG(Remote() != nullptr, false, "Remote() is nullptr"); - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::IS_ACOSTIC_ECHO_CAMCELER_SUPPORTED), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "SendRequest failed, error: %{public}d", - error); - - return reply.ReadBool(); -} - -bool AudioPolicyProxy::SetKaraokeParameters(const std::string ¶meters) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed"); - - data.WriteString(parameters); - - CHECK_AND_RETURN_RET_LOG(Remote() != nullptr, false, "Remote() is nullptr"); - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_KARAOKE_PARAMETERS), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "SendRequest failed, error: %{public}d", - error); - - return reply.ReadBool(); -} - -bool AudioPolicyProxy::IsAudioLoopbackSupported(AudioLoopbackMode mode) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed"); - - data.WriteInt32(static_cast(mode)); - - CHECK_AND_RETURN_RET_LOG(Remote() != nullptr, false, "Remote() is nullptr"); - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::IS_AUDIO_LOOPBACK_SUPPORTED), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "SendRequest failed, error: %{public}d", - error); - - return reply.ReadBool(); -} - -int32_t AudioPolicyProxy::GetMaxVolumeLevelByUsage(StreamUsage streamUsage) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed"); - - data.WriteInt32(static_cast(streamUsage)); - - CHECK_AND_RETURN_RET_LOG(Remote() != nullptr, ERROR, "Remote() is nullptr"); - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_MAX_VOLUME_LEVEL_BY_USAGE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::GetMinVolumeLevelByUsage(StreamUsage streamUsage) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed"); - - data.WriteInt32(static_cast(streamUsage)); - - CHECK_AND_RETURN_RET_LOG(Remote() != nullptr, ERROR, "Remote() is nullptr"); - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_MIN_VOLUME_LEVEL_BY_USAGE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::GetVolumeLevelByUsage(StreamUsage streamUsage) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed"); - - data.WriteInt32(static_cast(streamUsage)); - - CHECK_AND_RETURN_RET_LOG(Remote() != nullptr, ERROR, "Remote() is nullptr"); - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_VOLUME_LEVEL_BY_USAGE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "SendRequest failed, error: %{public}d", error); - - return reply.ReadInt32(); -} - -bool AudioPolicyProxy::GetStreamMuteByUsage(StreamUsage streamUsage) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed"); - - data.WriteInt32(static_cast(streamUsage)); - - CHECK_AND_RETURN_RET_LOG(Remote() != nullptr, false, "Remote() is nullptr"); - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_STREAM_MUTE_BY_USAGE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "SendRequest failed, error: %{public}d", error); - - return reply.ReadBool(); -} - -float AudioPolicyProxy::GetVolumeInDbByStream(StreamUsage streamUsage, int32_t volumeLevel, DeviceType deviceType) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed"); - - data.WriteInt32(static_cast(streamUsage)); - data.WriteInt32(volumeLevel); - data.WriteInt32(static_cast(deviceType)); - - CHECK_AND_RETURN_RET_LOG(Remote() != nullptr, false, "Remote() is nullptr"); - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_VOLUME_IN_DB_BY_STREAM), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "SendRequest failed, error: %{public}d", error); - - return reply.ReadFloat(); -} - -std::vector AudioPolicyProxy::GetSupportedAudioVolumeTypes() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - std::vector supportedVolumeTypes = {}; - size_t volumeTypeNum = 0; - if (ret == false) { - AUDIO_ERR_LOG("WriteInterfaceToken failed"); - return supportedVolumeTypes; - } - CHECK_AND_RETURN_RET_LOG(Remote() != nullptr, supportedVolumeTypes, "Remote() is nullptr"); - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_SUPPORTED_AUDIO_VOLUME_TYPES), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, supportedVolumeTypes, "SendRequest failed, error: %{public}d", error); - volumeTypeNum = reply.ReadInt32(); - for (size_t idx = 0; idx < volumeTypeNum; idx++) { - supportedVolumeTypes.push_back(static_cast(reply.ReadInt32())); - } - - return supportedVolumeTypes; -} - -AudioVolumeType AudioPolicyProxy::GetAudioVolumeTypeByStreamUsage(StreamUsage streamUsage) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - AudioVolumeType audioVolumeType = AudioStreamType::STREAM_DEFAULT; - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, audioVolumeType, "WriteInterfaceToken failed"); - - data.WriteInt32(static_cast(streamUsage)); - - CHECK_AND_RETURN_RET_LOG(Remote() != nullptr, audioVolumeType, "Remote() is nullptr"); - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_AUDIO_VOLUME_TYPE_BY_STREAM_USAGE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, audioVolumeType, "SendRequest failed, error: %{public}d", error); - - audioVolumeType = static_cast(reply.ReadInt32()); - return audioVolumeType; -} - -std::vector AudioPolicyProxy::GetStreamUsagesByVolumeType(AudioVolumeType audioVolumeType) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - vector streamUsages = {}; - size_t streamUsageNum = 0; - if (ret == false) { - AUDIO_ERR_LOG("WriteInterfaceToken failed"); - return streamUsages; - } - - data.WriteInt32(static_cast(audioVolumeType)); - - CHECK_AND_RETURN_RET_LOG(Remote() != nullptr, streamUsages, "Remote() is nullptr"); - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_STREAM_USAGES_BY_VOLUME_TYPE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, streamUsages, "SendRequest failed, error: %{public}d", error); - streamUsageNum = reply.ReadInt32(); - for (size_t idx = 0; idx < streamUsageNum; idx++) { - streamUsages.push_back(static_cast(reply.ReadInt32())); - } - - return streamUsages; -} - - -int32_t AudioPolicyProxy::SetCallbackStreamUsageInfo(const std::set &streamUsages) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed"); - - int32_t size = static_cast(streamUsages.size()); - CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= MAX_STREAM_USAGE_COUNT, ERROR, "size upper limit."); - data.WriteInt32(size); - for (auto streamUsage : streamUsages) { - data.WriteInt32(static_cast(streamUsage)); - } - - CHECK_AND_RETURN_RET_LOG(Remote() != nullptr, ERROR, "Remote() is nullptr"); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_CALLBACK_STREAM_USAGE_INFO), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::ForceStopAudioStream(StopAudioType audioType) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed"); - - data.WriteInt32(static_cast(audioType)); - - CHECK_AND_RETURN_RET_LOG(Remote() != nullptr, ERROR, "Remote() is nullptr"); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::FORCE_STOP_AUDIO_STREAM), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error); - - return reply.ReadInt32(); -} - -bool AudioPolicyProxy::IsCapturerFocusAvailable(const AudioCapturerInfo &capturerInfo) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed"); - - ret = capturerInfo.Marshalling(data); - CHECK_AND_RETURN_RET_LOG(ret, false, "Marshalling failed"); - - CHECK_AND_RETURN_RET_LOG(Remote() != nullptr, false, "Remote() is nullptr"); - int error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::IS_CAPTURER_FOCUS_AVAILABLE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "SendRequest failed, error: %{public}d", error); - - return reply.ReadBool(); -} - -int32_t AudioPolicyProxy::SetCollaborativePlaybackEnabledForDevice( - const std::shared_ptr &selectedAudioDevice, const bool enable) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed"); - - bool result = selectedAudioDevice->Marshalling(data); - CHECK_AND_RETURN_RET_LOG(result, -1, "SelectedAudioDevice Marshalling() failed"); - - data.WriteBool(enable); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_COLLABORATIVE_PLAYBACK_ENABLED_FOR_DEVICE), - data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "SendRequest failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -bool AudioPolicyProxy::IsCollaborativePlaybackSupported() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::IS_COLLABORATIVE_PALYBACK_SUPPORTED), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "SendRequest failed, error: %{public}d", error); - return reply.ReadBool(); -} - -bool AudioPolicyProxy::IsCollaborativePlaybackEnabledForDevice( - const std::shared_ptr &selectedAudioDevice) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed"); - - bool result = selectedAudioDevice->Marshalling(data); - CHECK_AND_RETURN_RET_LOG(result, false, "SelectedAudioDevice Marshalling() failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::IS_COLLABORATIVE_PLAYBACK_ENABLED_FOR_DEVICE), - data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "SendRequest failed, error: %{public}d", error); - return reply.ReadBool(); -} -} // namespace AudioStandard -} // namespace OHOS diff --git a/services/audio_policy/client/proxy/src/audio_policy_volume_proxy.cpp b/services/audio_policy/client/proxy/src/audio_policy_volume_proxy.cpp deleted file mode 100644 index f9af2cd780..0000000000 --- a/services/audio_policy/client/proxy/src/audio_policy_volume_proxy.cpp +++ /dev/null @@ -1,540 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * 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. - */ -#ifndef LOG_TAG -#define LOG_TAG "AudioPolicyProxy" -#endif - -#include "audio_policy_proxy.h" - -#include "audio_policy_log.h" - -namespace OHOS { -namespace AudioStandard { -using namespace std; - -int32_t AudioPolicyProxy::GetMaxVolumeLevel(AudioVolumeType volumeType) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - - data.WriteInt32(static_cast(volumeType)); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_MAX_VOLUMELEVEL), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "get max volume failed, error: %d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::GetMinVolumeLevel(AudioVolumeType volumeType) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteInt32(static_cast(volumeType)); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_MIN_VOLUMELEVEL), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "get min volume failed, error: %d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetSystemVolumeLevelLegacy(AudioVolumeType volumeType, int32_t volumeLevel) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - - data.WriteInt32(static_cast(volumeType)); - data.WriteInt32(volumeLevel); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_SYSTEM_VOLUMELEVEL_LEGACY), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "set volume failed, error: %d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetSelfAppVolumeLevel(int32_t volumeLevel, int32_t volumeFlag) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - - data.WriteInt32(volumeLevel); - data.WriteInt32(volumeFlag); - int32_t error = Remote()->SendRequest(static_cast( - AudioPolicyInterfaceCode::SET_SELF_APP_VOLUMELEVEL), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "set app volume failed, error: %d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::IsAppVolumeMute(int32_t appUid, bool owned, bool &isMute) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - - data.WriteInt32(appUid); - data.WriteBool(owned); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::IS_APP_MUTE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "is app muted failed, error: %d", error); - isMute = reply.ReadBool(); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetAppVolumeMuted(int32_t appUid, bool muted, int32_t volumeFlag) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - - data.WriteInt32(appUid); - data.WriteBool(muted); - data.WriteInt32(volumeFlag); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_APP_VOLUME_MUTED), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "set app muted failed, error: %d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetAdjustVolumeForZone(int32_t zoneId) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - - data.WriteInt32(zoneId); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_ADJUST_VOLUME_FOR_ZONE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "set app muted failed, error: %d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetAppVolumeLevel(int32_t appUid, int32_t volumeLevel, int32_t volumeFlag) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - - data.WriteInt32(appUid); - data.WriteInt32(volumeLevel); - data.WriteInt32(volumeFlag); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_APP_VOLUMELEVEL), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "set app volume failed, error: %d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetSystemVolumeLevel(AudioVolumeType volumeType, int32_t volumeLevel, int32_t volumeFlag, - int32_t uid) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - - data.WriteInt32(static_cast(volumeType)); - data.WriteInt32(volumeLevel); - data.WriteInt32(volumeFlag); - data.WriteInt32(uid); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_SYSTEM_VOLUMELEVEL), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "set volume failed, error: %d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetSystemVolumeLevelWithDevice(AudioVolumeType volumeType, int32_t volumeLevel, - DeviceType deviceType, int32_t volumeFlag) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - - data.WriteInt32(static_cast(volumeType)); - data.WriteInt32(volumeLevel); - data.WriteInt32(static_cast(deviceType)); - data.WriteInt32(volumeFlag); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_SYSTEM_VOLUMELEVEL_WITH_DEVICE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "set volume failed, error: %d", error); - return reply.ReadInt32(); -} - -AudioStreamType AudioPolicyProxy::GetSystemActiveVolumeType(const int32_t clientUid) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, STREAM_DEFAULT, "WriteInterfaceToken failed"); - data.WriteInt32(clientUid); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_SYSTEM_ACTIVEVOLUME_TYPE), data, reply, option); - if (error != ERR_NONE) { - AUDIO_ERR_LOG("get stream in focus failed, error: %d", error); - } - return static_cast(reply.ReadInt32()); -} - -int32_t AudioPolicyProxy::GetSystemVolumeLevel(AudioVolumeType volumeType, int32_t uid) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteInt32(static_cast(volumeType)); - data.WriteInt32(uid); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_SYSTEM_VOLUMELEVEL), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "get volume failed, error: %d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::GetSelfAppVolumeLevel(int32_t &volumeLevel) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_SELF_APP_VOLUME_LEVEL), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "get volume failed, error: %d", error); - volumeLevel = reply.ReadInt32(); - AUDIO_INFO_LOG("client get volumeLevel = %{public}d", volumeLevel); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::GetAppVolumeLevel(int32_t appUid, int32_t &volumeLevel) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteInt32(appUid); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_APP_VOLUMELEVEL), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "get volume failed, error: %d", error); - volumeLevel = reply.ReadInt32(); - AUDIO_INFO_LOG("client get volumeLevel = %{public}d", volumeLevel); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetLowPowerVolume(int32_t streamId, float volume) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - - data.WriteInt32(streamId); - data.WriteFloat(volume); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_LOW_POWER_STREAM_VOLUME), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "set low power stream volume failed, error: %d", error); - return reply.ReadInt32(); -} - -AudioStreamInfo AudioPolicyProxy::GetFastStreamInfo() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - AudioStreamInfo streamInfo = {SAMPLE_RATE_48000, ENCODING_PCM, SAMPLE_S16LE, STEREO}; - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, streamInfo, "WriteInterfaceToken failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_FAST_STREAM_INFO), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, streamInfo, "failed, error: %d", error); - - streamInfo.Unmarshalling(reply); - return streamInfo; -} - -float AudioPolicyProxy::GetLowPowerVolume(int32_t streamId) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteInt32(streamId); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_LOW_POWER_STREAM_VOLUME), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "get low power stream volume failed, error: %d", error); - return reply.ReadFloat(); -} - -float AudioPolicyProxy::GetSingleStreamVolume(int32_t streamId) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - data.WriteInt32(streamId); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_SINGLE_STREAM_VOLUME), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "get single stream volume failed, error: %d", error); - return reply.ReadFloat(); -} - -bool AudioPolicyProxy::IsVolumeUnadjustable() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed"); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::IS_VOLUME_UNADJUSTABLE), data, reply, option); - if (error != ERR_NONE) { - AUDIO_ERR_LOG("isvolumeadjustable failed, error: %d", error); - } - return reply.ReadBool(); -} - -int32_t AudioPolicyProxy::AdjustVolumeByStep(VolumeAdjustType adjustType) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, IPC_PROXY_ERR, "WriteInterfaceToken failed"); - - data.WriteInt32(adjustType); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::ADJUST_VOLUME_BY_STEP), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERR_TRANSACTION_FAILED, "error: %d", error); - - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::AdjustSystemVolumeByStep(AudioVolumeType volumeType, VolumeAdjustType adjustType) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, IPC_PROXY_ERR, "WriteInterfaceToken failed"); - data.WriteInt32(volumeType); - data.WriteInt32(adjustType); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::ADJUST_SYSTEM_VOLUME_BY_STEP), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERR_TRANSACTION_FAILED, "error: %d", error); - - return reply.ReadInt32(); -} - -float AudioPolicyProxy::GetSystemVolumeInDb(AudioVolumeType volumeType, int32_t volumeLevel, DeviceType deviceType) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed"); - - data.WriteInt32(static_cast(volumeType)); - data.WriteInt32(volumeLevel); - data.WriteInt32(static_cast(deviceType)); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_SYSTEM_VOLUME_IN_DB), data, reply, option); - if (error != ERR_NONE) { - AUDIO_ERR_LOG("GetSystemVolumeInDb failed, error: %d", error); - } - - return reply.ReadFloat(); -} - -int32_t AudioPolicyProxy::GetVolumeGroupInfos(std::string networkId, std::vector> &infos) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool res = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(res, ERROR, "WriteInterfaceToken failed"); - - data.WriteString(networkId); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_VOLUME_GROUP_INFO), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "GetVolumeGroupInfo, error: %d", error); - - int32_t ret = reply.ReadInt32(); - if (ret > 0) { - for (int32_t i = 0; i < ret; i++) { - infos.push_back(VolumeGroupInfo::Unmarshalling(reply)); - } - return SUCCESS; - } else { - return ret; - } -} - -float AudioPolicyProxy::GetMinStreamVolume() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_MIN_VOLUME_STREAM), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "get min volume for stream failed, error: %d", error); - return reply.ReadFloat(); -} - -float AudioPolicyProxy::GetMaxStreamVolume() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_MAX_VOLUME_STREAM), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "get max volume for stream failed, error: %d", error); - return reply.ReadFloat(); -} - -int32_t AudioPolicyProxy::SetDeviceAbsVolumeSupported(const std::string &macAddress, const bool support) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed"); - data.WriteString(macAddress); - data.WriteBool(support); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_DEVICE_ABSOLUTE_VOLUME_SUPPORTED), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, - "SetDeviceAbsVolumeSupported failed, error: %d", error); - return reply.ReadInt32(); -} - -bool AudioPolicyProxy::IsAbsVolumeScene() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_ABS_VOLUME_SCENE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "IsAbsVolumeScene failed, error: %d", error); - return reply.ReadBool(); -} - -int32_t AudioPolicyProxy::SetA2dpDeviceVolume(const std::string &macAddress, const int32_t volume, - const bool updateUi) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed"); - data.WriteString(macAddress); - data.WriteInt32(volume); - data.WriteBool(updateUi); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_A2DP_DEVICE_VOLUME), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "SetA2dpDeviceVolume failed, error: %d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::SetNearlinkDeviceVolume(const std::string &macAddress, AudioVolumeType volumeType, - const int32_t volume, const bool updateUi) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed"); - - data.WriteString(macAddress); - data.WriteInt32(static_cast(volumeType)); - data.WriteInt32(volume); - data.WriteBool(updateUi); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::SET_NEARLINK_DEVICE_VOLUME), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "Failed, error: %d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::DisableSafeMediaVolume() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed"); - - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::DISABLE_SAFE_MEDIA_VOLUME), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "SendRequest failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -} // namespace AudioStandard -} // namespace OHOS \ No newline at end of file diff --git a/services/audio_policy/client/proxy/src/audio_policy_zone_proxy.cpp b/services/audio_policy/client/proxy/src/audio_policy_zone_proxy.cpp deleted file mode 100644 index 3c65766641..0000000000 --- a/services/audio_policy/client/proxy/src/audio_policy_zone_proxy.cpp +++ /dev/null @@ -1,378 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * 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. - */ -#ifndef LOG_TAG -#define LOG_TAG "AudioPolicyZoneProxy" -#endif - -#include "audio_policy_log.h" -#include "audio_policy_proxy.h" - -namespace OHOS { -namespace AudioStandard { -int32_t AudioPolicyProxy::RegisterAudioZoneClient(const sptr& object) -{ - CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT, "object is nullptr"); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERROR, "WriteInterfaceToken failed"); - - (void)data.WriteRemoteObject(object); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::REGISTER_AUDIO_ZONE_CLIENT), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::CreateAudioZone(const std::string &name, const AudioZoneContext &context) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERROR, "WriteInterfaceToken failed"); - - data.WriteString(name); - context.Marshalling(data); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::CREATE_AUDIO_ZONE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -void AudioPolicyProxy::ReleaseAudioZone(int32_t zoneId) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "WriteInterfaceToken failed"); - - data.WriteInt32(zoneId); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::RELEASE_AUDIO_ZONE), data, reply, option); - CHECK_AND_RETURN_LOG(error == ERR_NONE, "ReleaseAudioZone failed, error: %{public}d", error); -} - -const std::vector> AudioPolicyProxy::GetAllAudioZone() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - std::vector> zoneDescriptor; - - CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), zoneDescriptor, - "WriteInterfaceToken failed"); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_ALL_AUDIO_ZONE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, zoneDescriptor, "SendRequest failed, error: %{public}d", error); - - int32_t retCode = reply.ReadInt32(); - CHECK_AND_RETURN_RET_LOG(retCode == ERR_NONE, zoneDescriptor, "GetAllAudioZone failed, error: %{public}d", retCode); - - int32_t zoneSize = reply.ReadInt32(); - for (int32_t i = 0; i < zoneSize; i++) { - zoneDescriptor.push_back(AudioZoneDescriptor::UnmarshallingPtr(reply)); - } - return zoneDescriptor; -} - -const std::shared_ptr AudioPolicyProxy::GetAudioZone(int32_t zoneId) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), nullptr, "WriteInterfaceToken failed"); - - data.WriteInt32(zoneId); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_AUDIO_ZONE_BY_ID), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, nullptr, "SendRequest failed, error: %{public}d", error); - - int32_t retCode = reply.ReadInt32(); - CHECK_AND_RETURN_RET_LOG(retCode == ERR_NONE, nullptr, "GetAudioZone failed, error: %{public}d", retCode); - return AudioZoneDescriptor::UnmarshallingPtr(reply); -} - -int32_t AudioPolicyProxy::BindDeviceToAudioZone(int32_t zoneId, - std::vector> devices) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERROR, "WriteInterfaceToken failed"); - data.WriteInt32(zoneId); - data.WriteInt32(static_cast(devices.size())); - for (auto &device : devices) { - bool ret = device->Marshalling(data); - CHECK_AND_RETURN_RET_LOG(ret, ERROR, "Marshalling device failed"); - } - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::BIND_AUDIO_ZONE_DEVICE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::UnBindDeviceToAudioZone(int32_t zoneId, - std::vector> devices) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERROR, "WriteInterfaceToken failed"); - data.WriteInt32(zoneId); - data.WriteInt32(static_cast(devices.size())); - for (auto &device : devices) { - bool ret = device->Marshalling(data); - CHECK_AND_RETURN_RET_LOG(ret, ERROR, "Marshalling device failed"); - } - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::UNBIND_AUDIO_ZONE_DEVICE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::EnableAudioZoneReport(bool enable) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERROR, "WriteInterfaceToken failed"); - - (void)data.WriteBool(enable); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::ENABLE_AUDIO_ZONE_REPORT), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::EnableAudioZoneChangeReport(int32_t zoneId, bool enable) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERROR, "WriteInterfaceToken failed"); - - (void)data.WriteInt32(zoneId); - (void)data.WriteBool(enable); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::ENABLE_AUDIO_ZONE_CHANGE_REPORT), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::AddUidToAudioZone(int32_t zoneId, int32_t uid) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERROR, "WriteInterfaceToken failed"); - - (void)data.WriteInt32(zoneId); - (void)data.WriteInt32(uid); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::ADD_UID_TO_AUDIO_ZONE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::RemoveUidFromAudioZone(int32_t zoneId, int32_t uid) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERROR, "WriteInterfaceToken failed"); - - (void)data.WriteInt32(zoneId); - (void)data.WriteInt32(uid); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::REMOVE_UID_FROM_AUDIO_ZONE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::AddStreamToAudioZone(int32_t zoneId, AudioZoneStream stream) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - - data.WriteInt32(zoneId); - stream.Marshalling(data); - int32_t error = Remote()->SendRequest(static_cast( - AudioPolicyInterfaceCode::ADD_STREAM_TO_AUDIO_ZONE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "sendrequest, error: %d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::RemoveStreamFromAudioZone(int32_t zoneId, AudioZoneStream stream) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed"); - - data.WriteInt32(zoneId); - stream.Marshalling(data); - int32_t error = Remote()->SendRequest(static_cast( - AudioPolicyInterfaceCode::REMOVE_STREAM_FROM_AUDIO_ZONE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "sendrequest, error: %d", error); - return reply.ReadInt32(); -} - -void AudioPolicyProxy::SetZoneDeviceVisible(bool visible) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - bool ret = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed"); - - data.WriteBool(visible); - int32_t error = Remote()->SendRequest(static_cast( - AudioPolicyInterfaceCode::SET_ZONE_DEVICE_VISIBLE), data, reply, option); - CHECK_AND_RETURN_LOG(error == ERR_NONE, "sendrequest, error: %d", error); -} - -int32_t AudioPolicyProxy::EnableSystemVolumeProxy(int32_t zoneId, bool enable) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERROR, "WriteInterfaceToken failed"); - - (void)data.WriteInt32(zoneId); - (void)data.WriteBool(enable); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::ENABLE_SYSTEM_VOLUME_PROXY), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -std::list> AudioPolicyProxy::GetAudioInterruptForZone( - int32_t zoneId) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - std::list> interrupts; - CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), interrupts, "WriteInterfaceToken failed"); - - (void)data.WriteInt32(zoneId); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_AUDIO_INTERRUPT_FOR_ZONE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, interrupts, "SendRequest failed, error: %{public}d", error); - - int32_t retCode = reply.ReadInt32(); - CHECK_AND_RETURN_RET_LOG(retCode == ERR_NONE, interrupts, - "GetAudioInterruptForZone failed, error: %{public}d", retCode); - int32_t size = reply.ReadInt32(); - for (int i = 0; i < size; i++) { - AudioInterrupt temp; - AudioInterrupt::Unmarshalling(reply, temp); - AudioFocuState state = static_cast(reply.ReadInt32()); - interrupts.emplace_back(std::make_pair(temp, state)); - } - return interrupts; -} - -std::list> AudioPolicyProxy::GetAudioInterruptForZone( - int32_t zoneId, const std::string &deviceTag) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - std::list> interrupts; - CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), interrupts, "WriteInterfaceToken failed"); - - (void)data.WriteInt32(zoneId); - (void)data.WriteString(deviceTag); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::GET_AUDIO_INTERRUPT_OF_DEVICE_FOR_ZONE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, interrupts, "SendRequest failed, error: %{public}d", error); - - int32_t retCode = reply.ReadInt32(); - CHECK_AND_RETURN_RET_LOG(retCode == ERR_NONE, interrupts, - "GetAudioInterruptForZone failed, error: %{public}d", retCode); - int32_t size = reply.ReadInt32(); - for (int i = 0; i < size; i++) { - AudioInterrupt temp; - AudioInterrupt::Unmarshalling(reply, temp); - AudioFocuState state = static_cast(reply.ReadInt32()); - interrupts.emplace_back(std::make_pair(temp, state)); - } - return interrupts; -} - -int32_t AudioPolicyProxy::EnableAudioZoneInterruptReport(int32_t zoneId, const std::string &deviceTag, bool enable) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERROR, "WriteInterfaceToken failed"); - - (void)data.WriteInt32(zoneId); - (void)data.WriteString(deviceTag); - (void)data.WriteBool(enable); - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::ENABLE_AUDIO_ZONE_INTERRUPT_REPORT), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::InjectInterruptToAudioZone(int32_t zoneId, - const std::list> &interrupts) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERROR, "WriteInterfaceToken failed"); - - (void)data.WriteInt32(zoneId); - (void)data.WriteInt32(static_cast(interrupts.size())); - for (auto &it : interrupts) { - AudioInterrupt::Marshalling(data, it.first); - (void)data.WriteInt32(static_cast(it.second)); - } - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::INJECT_INTERRUPT_TO_AUDIO_ZONE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error); - return reply.ReadInt32(); -} - -int32_t AudioPolicyProxy::InjectInterruptToAudioZone(int32_t zoneId, const std::string &deviceTag, - const std::list> &interrupts) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERROR, "WriteInterfaceToken failed"); - - (void)data.WriteInt32(zoneId); - (void)data.WriteString(deviceTag); - (void)data.WriteInt32(static_cast(interrupts.size())); - for (auto &it : interrupts) { - AudioInterrupt::Marshalling(data, it.first); - (void)data.WriteInt32(static_cast(it.second)); - } - int32_t error = Remote()->SendRequest( - static_cast(AudioPolicyInterfaceCode::INJECT_INTERRUPT_OF_DEVICE_TO_AUDIO_ZONE), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error); - return reply.ReadInt32(); -} -} // namespace AudioStandard -} // namespace OHOS \ No newline at end of file diff --git a/services/audio_policy/client/stub/include/audio_anahs_manager_listener_stub.h b/services/audio_policy/client/service/include/audio_anahs_manager_listener.h similarity index 53% rename from services/audio_policy/client/stub/include/audio_anahs_manager_listener_stub.h rename to services/audio_policy/client/service/include/audio_anahs_manager_listener.h index 4699546ff0..8a6eae4edb 100644 --- a/services/audio_policy/client/stub/include/audio_anahs_manager_listener_stub.h +++ b/services/audio_policy/client/service/include/audio_anahs_manager_listener.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * 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 @@ -13,27 +13,24 @@ * limitations under the License. */ -#ifndef AUDIO_ANAHS_MANAGER_LISTENER_STUB_H -#define AUDIO_ANAHS_MANAGER_LISTENER_STUB_H +#ifndef AUDIO_ANAHS_MANAGER_LISTENER_H +#define AUDIO_ANAHS_MANAGER_LISTENER_H #include "audio_anahs_manager.h" -#include "i_standard_audio_anahs_manager_listener.h" +#include "standard_audio_anahs_manager_listener_stub.h" namespace OHOS { namespace AudioStandard { -class AudioAnahsManagerListenerStub : public IRemoteStub { +class AudioAnahsManagerListener : public StandardAudioAnahsManagerListenerStub { public: - AudioAnahsManagerListenerStub(); - virtual ~AudioAnahsManagerListenerStub(); + AudioAnahsManagerListener(); + virtual ~AudioAnahsManagerListener(); - int OnRemoteRequest(uint32_t code, MessageParcel &data, - MessageParcel &reply, MessageOption &option) override; void SetAudioDeviceAnahsCallback(const std::weak_ptr &callback); - int32_t OnExtPnpDeviceStatusChanged(std::string anahsStatus, std::string anahsShowType) override; + int32_t OnExtPnpDeviceStatusChanged(const std::string &anahsStatus, const std::string &anahsShowType) override; private: - void OnExtPnpDeviceStatusChangedInternal(MessageParcel &data, MessageParcel &reply); std::weak_ptr audioDeviceAnahsCallback_; }; } // namespace AudioStandard } // namespace OHOS -#endif // AUDIO_RINGERMODE_UPDATE_LISTENER_STUB_H +#endif // AUDIO_ANAHS_MANAGER_LISTENER_H diff --git a/services/audio_policy/client/service/include/audio_general_manager.h b/services/audio_policy/client/service/include/audio_general_manager.h index 464c1c1a92..16645b8357 100644 --- a/services/audio_policy/client/service/include/audio_general_manager.h +++ b/services/audio_policy/client/service/include/audio_general_manager.h @@ -20,6 +20,7 @@ #include "audio_policy_interface.h" #include "audio_manager_base.h" #include "audio_system_manager.h" +#include "istandard_audio_service.h" namespace OHOS { namespace AudioStandard { diff --git a/services/audio_policy/client/stub/include/audio_routing_manager_listener_stub.h b/services/audio_policy/client/service/include/audio_routing_manager_listener.h similarity index 53% rename from services/audio_policy/client/stub/include/audio_routing_manager_listener_stub.h rename to services/audio_policy/client/service/include/audio_routing_manager_listener.h index e9313a32e7..245fb91929 100644 --- a/services/audio_policy/client/stub/include/audio_routing_manager_listener_stub.h +++ b/services/audio_policy/client/service/include/audio_routing_manager_listener.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * 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 @@ -13,40 +13,34 @@ * limitations under the License. */ -#ifndef AUDIO_ROUTING_MANAGER_LISTENER_STUB_H -#define AUDIO_ROUTING_MANAGER_LISTENER_STUB_H +#ifndef AUDIO_ROUTING_MANAGER_LISTENER_H +#define AUDIO_ROUTING_MANAGER_LISTENER_H #include "audio_routing_manager.h" -#include "i_standard_audio_routing_manager_listener.h" +#include "standard_audio_routing_manager_listener_stub.h" namespace OHOS { namespace AudioStandard { -class AudioRoutingManagerListenerStub : public IRemoteStub { +class AudioRoutingManagerListener : public StandardAudioRoutingManagerListenerStub { public: - AudioRoutingManagerListenerStub(); - virtual ~AudioRoutingManagerListenerStub(); + AudioRoutingManagerListener(); + virtual ~AudioRoutingManagerListener(); - int OnRemoteRequest(uint32_t code, MessageParcel &data, - MessageParcel &reply, MessageOption &option) override; - void OnDistributedRoutingRoleChange( - const std::shared_ptr descriptor, const CastType type) override; + int32_t OnDistributedRoutingRoleChange( + const std::shared_ptr &descriptor, int32_t type) override; void SetDistributedRoutingRoleCallback(const std::weak_ptr &callback); void SetAudioDeviceRefinerCallback(const std::weak_ptr &callback); int32_t OnAudioOutputDeviceRefined(std::vector> &descs, - RouterType routerType, StreamUsage streamUsage, int32_t clientUid, AudioPipeType audioPipeType) override; + int32_t routerType, int32_t streamUsage, int32_t clientUid, int32_t audioPipeType) override; int32_t OnAudioInputDeviceRefined(std::vector> &descs, - RouterType routerType, SourceType sourceType, int32_t clientUid, AudioPipeType audioPipeType) override; + int32_t routerType, int32_t sourceType, int32_t clientUid, int32_t audioPipeType) override; int32_t GetSplitInfoRefined(std::string &splitInfo) override; int32_t OnDistributedOutputChange(bool isRemote) override; private: - void OnAudioOutputDeviceRefinedInternal(MessageParcel &data, MessageParcel &reply); - void OnAudioInputDeviceRefinedInternal(MessageParcel &data, MessageParcel &reply); - void GetSplitInfoRefinedInternal(MessageParcel &data, MessageParcel &reply); - void OnDistributedOutputChangeInternal(MessageParcel &data, MessageParcel &reply); std::mutex deviceRefinerCallbackMutex_; std::weak_ptr audioDistributedRoutingRoleCallback_; std::weak_ptr audioDeviceRefinerCallback_; }; } // namespace AudioStandard } // namespace OHOS -#endif // AUDIO_RINGERMODE_UPDATE_LISTENER_STUB_H +#endif // AUDIO_ROUTING_MANAGER_LISTENER_H diff --git a/services/audio_policy/client/stub/src/audio_anahs_manager_listener_stub.cpp b/services/audio_policy/client/service/src/audio_anahs_manager_listener.cpp similarity index 48% rename from services/audio_policy/client/stub/src/audio_anahs_manager_listener_stub.cpp rename to services/audio_policy/client/service/src/audio_anahs_manager_listener.cpp index 9438dd2495..36ffb4044a 100644 --- a/services/audio_policy/client/stub/src/audio_anahs_manager_listener_stub.cpp +++ b/services/audio_policy/client/service/src/audio_anahs_manager_listener.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * 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 @@ -13,10 +13,10 @@ * limitations under the License. */ #ifndef LOG_TAG -#define LOG_TAG "AudioAnahsManagerListenerStub" +#define LOG_TAG "AudioAnahsManagerListener" #endif -#include "audio_anahs_manager_listener_stub.h" +#include "audio_anahs_manager_listener.h" #include "audio_errors.h" #include "audio_policy_log.h" @@ -26,47 +26,23 @@ using namespace std; namespace OHOS { namespace AudioStandard { -AudioAnahsManagerListenerStub::AudioAnahsManagerListenerStub() +AudioAnahsManagerListener::AudioAnahsManagerListener() { } -AudioAnahsManagerListenerStub::~AudioAnahsManagerListenerStub() +AudioAnahsManagerListener::~AudioAnahsManagerListener() { } -int AudioAnahsManagerListenerStub::OnRemoteRequest( - uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - CHECK_AND_RETURN_RET_LOG(data.ReadInterfaceToken() == GetDescriptor(), - -1, "AudioRingerModeUpdateListenerStub: ReadInterfaceToken failed"); - switch (code) { - case ON_AUDIO_ANAHS_DEVICE_CHANGE: { - OnExtPnpDeviceStatusChangedInternal(data, reply); - return AUDIO_OK; - } - default: { - AUDIO_ERR_LOG("default case, need check AudioListenerStub"); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } - } -} - -void AudioAnahsManagerListenerStub::SetAudioDeviceAnahsCallback(const std::weak_ptr &callback) +void AudioAnahsManagerListener::SetAudioDeviceAnahsCallback(const std::weak_ptr &callback) { audioDeviceAnahsCallback_ = callback; std::shared_ptr audioDeviceAnahsCallback = audioDeviceAnahsCallback_.lock(); CHECK_AND_RETURN_LOG(audioDeviceAnahsCallback != nullptr, "audioDeviceAnahsCallback_ is nullptr"); } -void AudioAnahsManagerListenerStub::OnExtPnpDeviceStatusChangedInternal(MessageParcel &data, MessageParcel &reply) -{ - std::string anahsName = data.ReadString(); - std::string anahsShowType = data.ReadString(); - int32_t result = OnExtPnpDeviceStatusChanged(anahsName, anahsShowType); - reply.WriteInt32(result); -} - -int32_t AudioAnahsManagerListenerStub::OnExtPnpDeviceStatusChanged(std::string anahsStatus, std::string anahsShowType) +int32_t AudioAnahsManagerListener::OnExtPnpDeviceStatusChanged(const std::string &anahsStatus, + const std::string &anahsShowType) { std::shared_ptr audioDeviceAnahsCallback = audioDeviceAnahsCallback_.lock(); CHECK_AND_RETURN_RET_LOG(audioDeviceAnahsCallback != nullptr, ERR_CALLBACK_NOT_REGISTERED, diff --git a/services/audio_policy/client/service/src/audio_general_manager.cpp b/services/audio_policy/client/service/src/audio_general_manager.cpp index 1c1122784d..5395744f2e 100644 --- a/services/audio_policy/client/service/src/audio_general_manager.cpp +++ b/services/audio_policy/client/service/src/audio_general_manager.cpp @@ -28,6 +28,7 @@ #include "audio_utils.h" #include "iservice_registry.h" #include "system_ability_definition.h" +#include "istandard_audio_service.h" namespace OHOS { namespace AudioStandard { @@ -184,7 +185,11 @@ int32_t AudioGeneralManager::SetExtraParameters(const std::string &key, { const sptr gasp = GetAudioGeneralManagerProxy(); CHECK_AND_RETURN_RET_LOG(gasp != nullptr, 0, "Audio service unavailable."); - return gasp->SetExtraParameters(key, kvpairs); + std::vector pairs; + for (auto &pair : kvpairs) { + pairs.push_back({pair.first, pair.second}); + } + return gasp->SetExtraParameters(key, pairs); } int32_t AudioGeneralManager::GetVolume(AudioVolumeType volumeType) const diff --git a/services/audio_policy/client/service/src/audio_policy_manager.cpp b/services/audio_policy/client/service/src/audio_policy_manager.cpp index 9257185333..06edcebe97 100644 --- a/services/audio_policy/client/service/src/audio_policy_manager.cpp +++ b/services/audio_policy/client/service/src/audio_policy_manager.cpp @@ -27,6 +27,8 @@ #include "audio_utils.h" #include "audio_policy_proxy.h" #include "audio_server_death_recipient.h" +#include "audio_spatialization_state_change_listener.h" +#include "audio_concurrency_state_listener_service.h" namespace OHOS { namespace AudioStandard { @@ -46,7 +48,7 @@ std::weak_ptr AudioPolicyManager::captur std::vector> AudioPolicyManager::audioStreamCBMap_; std::vector AudioPolicyManager::serverDiedCbks_; std::mutex AudioPolicyManager::serverDiedCbkMutex_; -std::unordered_map> AudioPolicyManager::clientTrackerStubMap_; +std::unordered_map> AudioPolicyManager::clientTrackerStubMap_; static bool RegisterDeathRecipientInner(sptr object) { @@ -133,7 +135,8 @@ int32_t AudioPolicyManager::RegisterPolicyCallbackClientFunc(const sptrRegisterPolicyCallbackClient(object); + CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERROR, "AudioPolicy is nullptr"); + int32_t ret = gsp->RegisterPolicyCallbackClient(object, 0); if (ret == SUCCESS) { isAudioPolicyClientRegisted_ = true; } @@ -174,7 +177,7 @@ void AudioPolicyManager::RecoverAudioPolicyCallbackClient() return; } - gsp->RegisterPolicyCallbackClient(object); + gsp->RegisterPolicyCallbackClient(object, 0); if (audioPolicyClientStubCB_->HasMicStateChangeCallback()) { AUDIO_INFO_LOG("RecoverAudioPolicyCallbackClient has micStateChangeCallback"); gsp->SetClientCallbacksEnable(CALLBACK_MICMUTE_STATE_CHANGE, true); @@ -278,7 +281,9 @@ int32_t AudioPolicyManager::GetMaxVolumeLevel(AudioVolumeType volumeType) const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, -1, "audio policy manager proxy is NULL."); - return gsp->GetMaxVolumeLevel(volumeType); + int32_t volumeLevel = -1; + gsp->GetMaxVolumeLevel(volumeType, volumeLevel); + return volumeLevel; } int32_t AudioPolicyManager::GetMinVolumeLevel(AudioVolumeType volumeType) @@ -286,7 +291,9 @@ int32_t AudioPolicyManager::GetMinVolumeLevel(AudioVolumeType volumeType) const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, -1, "audio policy manager proxy is NULL."); - return gsp->GetMinVolumeLevel(volumeType); + int32_t volumeLevel = -1; + gsp->GetMinVolumeLevel(volumeType, volumeLevel); + return volumeLevel; } int32_t AudioPolicyManager::SetSelfAppVolumeLevel(int32_t volumeLevel, int32_t volumeFlag) @@ -365,7 +372,10 @@ AudioRingerMode AudioPolicyManager::GetRingerMode() nullptr, nullptr, AUDIO_XCOLLIE_FLAG_LOG); const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, RINGER_MODE_NORMAL, "audio policy manager proxy is NULL."); - return gsp->GetRingerMode(); + + int32_t out = RINGER_MODE_NORMAL; + gsp->GetRingerMode(out); + return static_cast(out); } int32_t AudioPolicyManager::SetAudioScene(AudioScene scene) @@ -400,7 +410,10 @@ bool AudioPolicyManager::GetPersistentMicMuteState() { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, -1, "audio policy manager proxy is NULL."); - return gsp->GetPersistentMicMuteState(); + + bool mute = true; + gsp->GetPersistentMicMuteState(mute); + return mute; } bool AudioPolicyManager::IsMicrophoneMuteLegacy() @@ -411,7 +424,9 @@ bool AudioPolicyManager::IsMicrophoneMuteLegacy() RegisterPolicyCallbackClientFunc(gsp); } - return gsp->IsMicrophoneMuteLegacy(); + bool mute = true; + gsp->IsMicrophoneMuteLegacy(mute); + return mute; } bool AudioPolicyManager::IsMicrophoneMute() @@ -422,21 +437,27 @@ bool AudioPolicyManager::IsMicrophoneMute() RegisterPolicyCallbackClientFunc(gsp); } - return gsp->IsMicrophoneMute(); + bool mute = true; + gsp->IsMicrophoneMute(mute); + return mute; } AudioScene AudioPolicyManager::GetAudioScene() { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, AUDIO_SCENE_DEFAULT, "audio policy manager proxy is NULL."); - return gsp->GetAudioScene(); + int32_t scene = AUDIO_SCENE_DEFAULT; + gsp->GetAudioScene(scene); + return static_cast(scene); } AudioStreamType AudioPolicyManager::GetSystemActiveVolumeType(const int32_t clientUid) { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, STREAM_DEFAULT, "audio policy manager proxy is NULL."); - return gsp->GetSystemActiveVolumeType(clientUid); + int32_t streamType = STREAM_DEFAULT; + gsp->GetSystemActiveVolumeType(clientUid, streamType); + return static_cast(streamType); } int32_t AudioPolicyManager::GetSelfAppVolumeLevel(int32_t &volumeLevel) @@ -457,7 +478,10 @@ int32_t AudioPolicyManager::GetSystemVolumeLevel(AudioVolumeType volumeType, int { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, -1, "audio policy manager proxy is NULL."); - return gsp->GetSystemVolumeLevel(volumeType, uid); + + int32_t volumeLevel = -1; + gsp->GetSystemVolumeLevel(volumeType, uid, volumeLevel); + return volumeLevel; } int32_t AudioPolicyManager::SetStreamMute(AudioVolumeType volumeType, bool mute, bool isLegacy, @@ -475,7 +499,10 @@ bool AudioPolicyManager::GetStreamMute(AudioVolumeType volumeType) { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "audio policy manager proxy is NULL."); - return gsp->GetStreamMute(volumeType); + + bool mute = false; + gsp->GetStreamMute(volumeType, mute); + return mute; } int32_t AudioPolicyManager::SetLowPowerVolume(int32_t streamId, float volume) @@ -489,7 +516,10 @@ float AudioPolicyManager::GetLowPowerVolume(int32_t streamId) { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, -1, "audio policy manager proxy is NULL."); - return gsp->GetLowPowerVolume(streamId); + + float outVolume = -1; + gsp->GetLowPowerVolume(streamId, outVolume); + return outVolume; } AudioStreamInfo AudioPolicyManager::GetFastStreamInfo() @@ -497,7 +527,7 @@ AudioStreamInfo AudioPolicyManager::GetFastStreamInfo() AudioStreamInfo streamInfo = {SAMPLE_RATE_48000, ENCODING_PCM, SAMPLE_S16LE, STEREO}; const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, streamInfo, "audio policy manager proxy is NULL."); - streamInfo = gsp->GetFastStreamInfo(); + gsp->GetFastStreamInfo(streamInfo); return streamInfo; } @@ -505,35 +535,49 @@ float AudioPolicyManager::GetSingleStreamVolume(int32_t streamId) { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, -1, "audio policy manager proxy is NULL."); - return gsp->GetSingleStreamVolume(streamId); + + float outVolume = -1; + gsp->GetSingleStreamVolume(streamId, outVolume); + return outVolume; } bool AudioPolicyManager::IsStreamActive(AudioVolumeType volumeType) { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "audio policy manager proxy is NULL."); - return gsp->IsStreamActive(volumeType); + + bool active = false; + gsp->IsStreamActive(volumeType, active); + return active; } bool AudioPolicyManager::IsStreamActiveByStreamUsage(StreamUsage streamUsage) { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "audio policy manager proxy is NULL."); - return gsp->IsStreamActiveByStreamUsage(streamUsage); + bool active = false; + gsp->IsStreamActiveByStreamUsage(streamUsage, active); + return active; } bool AudioPolicyManager::IsFastPlaybackSupported(AudioStreamInfo &streamInfo, StreamUsage usage) { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "audio policy manager proxy is NULL."); - return gsp->IsFastPlaybackSupported(streamInfo, usage); + + bool support = false; + gsp->IsFastPlaybackSupported(streamInfo, static_cast(usage), support); + return support; } bool AudioPolicyManager::IsFastRecordingSupported(AudioStreamInfo &streamInfo, SourceType source) { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "audio policy manager proxy is NULL."); - return gsp->IsFastRecordingSupported(streamInfo, source); + + bool support = false; + gsp->IsFastRecordingSupported(streamInfo, static_cast(source), support); + return support; } int32_t AudioPolicyManager::GetAudioFocusInfoList(std::list> &focusInfoList, @@ -541,7 +585,10 @@ int32_t AudioPolicyManager::GetAudioFocusInfoList(std::list gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, -1, "audio policy manager proxy is NULL."); - return gsp->GetAudioFocusInfoList(focusInfoList, zoneID); + auto ipcInterrupts = ToIpcInterrupts(focusInfoList); + int32_t ret = gsp->GetAudioFocusInfoList(ipcInterrupts, zoneID); + focusInfoList = FromIpcInterrupts(ipcInterrupts); + return ret; } int32_t AudioPolicyManager::SetClientCallbacksEnable(const CallbackChange &callbackchange, const bool &enable) @@ -610,21 +657,30 @@ int32_t AudioPolicyManager::UnregisterFocusInfoChangeCallback(const int32_t clie std::vector AudioPolicyManager::GetSupportedTones(const std::string &countryCode) { const sptr gsp = GetAudioPolicyManagerProxy(); + std::vector lSupportedToneList = {}; if (gsp == nullptr) { AUDIO_ERR_LOG("audio policy manager proxy is NULL."); - std::vector lSupportedToneList = {}; return lSupportedToneList; } - return gsp->GetSupportedTones(countryCode); + + gsp->GetSupportedTones(countryCode, lSupportedToneList); + + int32_t lListSize = static_cast(lSupportedToneList.size()); + CHECK_AND_RETURN_RET_LOG(lListSize >= 0 && lListSize <= static_cast(MAX_SUPPORTED_TONEINFO_SIZE), + {}, "supported tone size exceed limits"); + + return lSupportedToneList; } std::shared_ptr AudioPolicyManager::GetToneConfig(int32_t ltonetype, const std::string &countryCode) { AUDIO_DEBUG_LOG("AudioPolicyManager::GetToneConfig"); - const sptr gsp = GetAudioPolicyManagerProxy(); + std::shared_ptr config = nullptr; CHECK_AND_RETURN_RET_LOG(gsp != nullptr, nullptr, "audio policy manager proxy is NULL."); - return gsp->GetToneConfig(ltonetype, countryCode); + + gsp->GetToneConfig(ltonetype, countryCode, config); + return config; } #endif @@ -982,13 +1038,12 @@ int32_t AudioPolicyManager::SetAudioInterruptCallback(const uint32_t sessionID, CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERROR, "audio policy manager proxy is NULL."); CHECK_AND_RETURN_RET_LOG(callback != nullptr, ERR_INVALID_PARAM, "callback is nullptr"); - sptr listener = new(std::nothrow) AudioPolicyManagerListenerStub(); + sptr listener = new(std::nothrow) AudioPolicyManagerListenerStubImpl(); CHECK_AND_RETURN_RET_LOG(listener != nullptr, ERROR, "object null"); listener->SetInterruptCallback(callback); sptr object = listener->AsObject(); CHECK_AND_RETURN_RET_LOG(object != nullptr, ERROR, "listenerStub->AsObject is nullptr.."); - return gsp->SetAudioInterruptCallback(sessionID, object, clientUid, zoneID); } @@ -1006,7 +1061,7 @@ int32_t AudioPolicyManager::SetQueryClientTypeCallback(const std::shared_ptr listener = new(std::nothrow) AudioPolicyManagerListenerStub(); + sptr listener = new(std::nothrow) AudioPolicyManagerListenerStubImpl(); CHECK_AND_RETURN_RET_LOG(listener != nullptr, ERROR, "object null"); listener->SetQueryClientTypeCallback(callback); @@ -1024,7 +1079,7 @@ int32_t AudioPolicyManager::SetQueryBundleNameListCallback( CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERROR, "audio policy manager proxy is NULL."); CHECK_AND_RETURN_RET_LOG(callback != nullptr, ERR_INVALID_PARAM, "callback is nullptr"); - sptr listener = new(std::nothrow) AudioPolicyManagerListenerStub(); + sptr listener = new(std::nothrow) AudioPolicyManagerListenerStubImpl(); CHECK_AND_RETURN_RET_LOG(listener != nullptr, ERROR, "object null"); listener->SetQueryBundleNameListCallback(callback); @@ -1071,7 +1126,8 @@ int32_t AudioPolicyManager::SetAudioManagerInterruptCallback(const int32_t clien CHECK_AND_RETURN_RET_LOG(callback != nullptr, ERR_INVALID_PARAM, "callback is nullptr"); std::unique_lock lock(listenerStubMutex_); - sptr interruptListenerStub = new(std::nothrow) AudioPolicyManagerListenerStub(); + sptr interruptListenerStub = + new(std::nothrow) AudioPolicyManagerListenerStubImpl(); CHECK_AND_RETURN_RET_LOG(interruptListenerStub != nullptr, ERROR, "object null"); interruptListenerStub->SetInterruptCallback(callback); @@ -1114,14 +1170,18 @@ AudioStreamType AudioPolicyManager::GetStreamInFocus(const int32_t zoneID) { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, STREAM_DEFAULT, "audio policy manager proxy is NULL."); - return gsp->GetStreamInFocus(zoneID); + int32_t out = STREAM_DEFAULT; + gsp->GetStreamInFocus(zoneID, out); + return static_cast(out); } AudioStreamType AudioPolicyManager::GetStreamInFocusByUid(const int32_t uid, const int32_t zoneID) { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, STREAM_DEFAULT, "audio policy manager proxy is NULL."); - return gsp->GetStreamInFocusByUid(uid, zoneID); + int32_t out = STREAM_DEFAULT; + gsp->GetStreamInFocusByUid(uid, zoneID, out); + return static_cast(out); } int32_t AudioPolicyManager::GetSessionInfoInFocus(AudioInterrupt &audioInterrupt, const int32_t zoneID) @@ -1327,7 +1387,7 @@ int32_t AudioPolicyManager::RegisterTracker(AudioMode &mode, AudioStreamChangeIn CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERROR, "audio policy manager proxy is NULL."); std::lock_guard lock(clientTrackerStubMutex_); - sptr callback = new(std::nothrow) AudioClientTrackerCallbackStub(); + sptr callback = new(std::nothrow) AudioClientTrackerCallbackService(); CHECK_AND_RETURN_RET_LOG(callback != nullptr, ERROR, "clientTrackerCbStub: memory allocation failed"); callback->SetClientTrackerCallback(clientTrackerObj); @@ -1364,14 +1424,18 @@ int32_t AudioPolicyManager::GetPreferredOutputStreamType(AudioRendererInfo &rend { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, AUDIO_FLAG_INVALID, "audio policy manager proxy is NULL."); - return gsp->GetPreferredOutputStreamType(rendererInfo); + int32_t streamType = AUDIO_FLAG_INVALID; + gsp->GetPreferredOutputStreamType(rendererInfo, streamType); + return streamType; } int32_t AudioPolicyManager::GetPreferredInputStreamType(AudioCapturerInfo &capturerInfo) { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, AUDIO_FLAG_INVALID, "audio policy manager proxy is NULL."); - return gsp->GetPreferredInputStreamType(capturerInfo); + int32_t streamType = AUDIO_FLAG_INVALID; + gsp->GetPreferredInputStreamType(capturerInfo, streamType); + return streamType; } int32_t AudioPolicyManager::CreateRendererClient( @@ -1448,21 +1512,27 @@ std::string AudioPolicyManager::GetSystemSoundUri(const std::string &key) const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, "", "audio policy manager proxy is NULL."); - return gsp->GetSystemSoundUri(key); + std::string out{}; + gsp->GetSystemSoundUri(key, out); + return out; } float AudioPolicyManager::GetMinStreamVolume() { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERROR, "audio policy manager proxy is NULL."); - return gsp->GetMinStreamVolume(); + float out = -1; + gsp->GetMinStreamVolume(out); + return out; } float AudioPolicyManager::GetMaxStreamVolume() { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERROR, "audio policy manager proxy is NULL."); - return gsp->GetMaxStreamVolume(); + float out = -1; + gsp->GetMaxStreamVolume(out); + return out; } int32_t AudioPolicyManager::RegisterAudioPolicyServerDiedCb(const int32_t clientPid, @@ -1526,14 +1596,18 @@ int32_t AudioPolicyManager::GetMaxRendererInstances() const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERROR, "audio policy manager proxy is NULL."); - return gsp->GetMaxRendererInstances(); + int32_t ret = -1; + gsp->GetMaxRendererInstances(ret); + return ret; } bool AudioPolicyManager::IsVolumeUnadjustable() { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "audio policy manager proxy is NULL."); - return gsp->IsVolumeUnadjustable(); + bool out = false; + gsp->IsVolumeUnadjustable(out); + return out; } int32_t AudioPolicyManager::AdjustVolumeByStep(VolumeAdjustType adjustType) @@ -1554,7 +1628,9 @@ float AudioPolicyManager::GetSystemVolumeInDb(AudioVolumeType volumeType, int32_ { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERROR, "audio policy manager proxy is NULL."); - return gsp->GetSystemVolumeInDb(volumeType, volumeLevel, deviceType); + float out = -1; + gsp->GetSystemVolumeInDb(volumeType, volumeLevel, deviceType, out); + return out; } int32_t AudioPolicyManager::QueryEffectSceneMode(SupportedEffectConfig &supportedEffectConfig) @@ -1569,18 +1645,21 @@ int32_t AudioPolicyManager::GetHardwareOutputSamplingRate(const std::shared_ptr< { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERROR, "audio policy manager proxy is NULL."); - return gsp->GetHardwareOutputSamplingRate(desc); + int32_t ret = ERROR; + gsp->GetHardwareOutputSamplingRate(desc, ret); + return ret; } vector> AudioPolicyManager::GetAudioCapturerMicrophoneDescriptors(int32_t sessionID) { const sptr gsp = GetAudioPolicyManagerProxy(); + std::vector> descs; if (gsp == nullptr) { AUDIO_ERR_LOG("audio policy manager proxy is NULL."); - std::vector> descs; return descs; } - return gsp->GetAudioCapturerMicrophoneDescriptors(sessionID); + gsp->GetAudioCapturerMicrophoneDescriptors(sessionID, descs); + return descs; } vector> AudioPolicyManager::GetAvailableMicrophones() @@ -1591,7 +1670,9 @@ vector> AudioPolicyManager::GetAvailableMicrophones() std::vector> descs; return descs; } - return gsp->GetAvailableMicrophones(); + vector> retMicList; + gsp->GetAvailableMicrophones(retMicList); + return retMicList; } int32_t AudioPolicyManager::SetDeviceAbsVolumeSupported(const std::string &macAddress, const bool support) @@ -1605,7 +1686,9 @@ bool AudioPolicyManager::IsAbsVolumeScene() { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERROR, "audio policy manager proxy is NULL."); - return gsp->IsAbsVolumeScene(); + bool ret = true; + gsp->IsAbsVolumeScene(ret); + return ret; } int32_t AudioPolicyManager::SetA2dpDeviceVolume(const std::string &macAddress, const int32_t volume, @@ -1629,7 +1712,7 @@ int32_t AudioPolicyManager::ConfigDistributedRoutingRole( { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, -1, "audio policy manager proxy is NULL."); - return gsp->ConfigDistributedRoutingRole(descriptor, type); + return gsp->ConfigDistributedRoutingRole(descriptor, static_cast(type)); } int32_t AudioPolicyManager::SetDistributedRoutingRoleCallback( @@ -1643,7 +1726,7 @@ int32_t AudioPolicyManager::SetDistributedRoutingRoleCallback( } std::unique_lock lock(listenerStubMutex_); - auto activeDistributedRoutingRoleCb = new(std::nothrow) AudioRoutingManagerListenerStub(); + auto activeDistributedRoutingRoleCb = new(std::nothrow) AudioRoutingManagerListener(); if (activeDistributedRoutingRoleCb == nullptr) { AUDIO_ERR_LOG("SetDistributedRoutingRoleCallback: object is nullptr"); return ERROR; @@ -1669,21 +1752,25 @@ bool AudioPolicyManager::IsSpatializationEnabled() { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "audio policy manager proxy is NULL."); - return gsp->IsSpatializationEnabled(); + bool ret = false; + return gsp->IsSpatializationEnabled(ret); } bool AudioPolicyManager::IsSpatializationEnabled(const std::string address) { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "audio policy manager proxy is NULL."); - return gsp->IsSpatializationEnabled(address); + bool ret = false; + return gsp->IsSpatializationEnabled(address, ret); } bool AudioPolicyManager::IsSpatializationEnabledForCurrentDevice() { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "audio policy manager proxy is NULL."); - return gsp->IsSpatializationEnabledForCurrentDevice(); + bool ret = false; + gsp->IsSpatializationEnabledForCurrentDevice(ret); + return ret; } int32_t AudioPolicyManager::SetSpatializationEnabled(const bool enable) @@ -1705,14 +1792,18 @@ bool AudioPolicyManager::IsHeadTrackingEnabled() { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "audio policy manager proxy is NULL."); - return gsp->IsHeadTrackingEnabled(); + bool ret = false; + gsp->IsHeadTrackingEnabled(ret); + return ret; } bool AudioPolicyManager::IsHeadTrackingEnabled(const std::string address) { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "audio policy manager proxy is NULL."); - return gsp->IsHeadTrackingEnabled(address); + bool ret = false; + gsp->IsHeadTrackingEnabled(address, ret); + return ret; } int32_t AudioPolicyManager::SetHeadTrackingEnabled(const bool enable) @@ -1898,35 +1989,45 @@ AudioSpatializationState AudioPolicyManager::GetSpatializationState(const Stream AudioSpatializationState spatializationState = {false, false}; return spatializationState; } - return gsp->GetSpatializationState(streamUsage); + AudioSpatializationState state; + gsp->GetSpatializationState(streamUsage, state); + return state; } bool AudioPolicyManager::IsSpatializationSupported() { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "audio policy manager proxy is NULL."); - return gsp->IsSpatializationSupported(); + bool ret = false; + gsp->IsSpatializationSupported(ret); + return ret; } bool AudioPolicyManager::IsSpatializationSupportedForDevice(const std::string address) { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "audio policy manager proxy is NULL."); - return gsp->IsSpatializationSupportedForDevice(address); + bool ret = false; + gsp->IsSpatializationSupportedForDevice(address, ret); + return ret; } bool AudioPolicyManager::IsHeadTrackingSupported() { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "audio policy manager proxy is NULL."); - return gsp->IsHeadTrackingSupported(); + bool ret = false; + gsp->IsHeadTrackingSupported(ret); + return ret; } bool AudioPolicyManager::IsHeadTrackingSupportedForDevice(const std::string address) { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "audio policy manager proxy is NULL."); - return gsp->IsHeadTrackingSupportedForDevice(address); + bool ret = false; + gsp->IsHeadTrackingSupportedForDevice(address, ret); + return ret; } int32_t AudioPolicyManager::UpdateSpatialDeviceState(const AudioSpatialDeviceState audioSpatialDeviceState) @@ -1944,8 +2045,8 @@ int32_t AudioPolicyManager::RegisterSpatializationStateEventListener(const uint3 CHECK_AND_RETURN_RET_LOG(callback != nullptr, ERR_INVALID_PARAM, "Spatialization state callback is nullptr"); - sptr spatializationStateChangeListenerStub = - new(std::nothrow) AudioSpatializationStateChangeListenerStub(); + sptr spatializationStateChangeListenerStub = + new(std::nothrow) AudioSpatializationStateChangeListener(); CHECK_AND_RETURN_RET_LOG(spatializationStateChangeListenerStub != nullptr, ERROR, "object null"); spatializationStateChangeListenerStub->SetCallback(callback); @@ -2003,7 +2104,9 @@ ConverterConfig AudioPolicyManager::GetConverterConfig() AUDIO_ERR_LOG("audio policy manager proxy is NULL."); return ConverterConfig(); } - return gsp->GetConverterConfig(); + ConverterConfig cfg; + gsp->GetConverterConfig(cfg); + return cfg; } bool AudioPolicyManager::IsHighResolutionExist() @@ -2013,7 +2116,8 @@ bool AudioPolicyManager::IsHighResolutionExist() AUDIO_ERR_LOG("audio policy manager proxy is NULL."); return false; } - bool gspIsHighResolutionExist = gsp->IsHighResolutionExist(); + bool gspIsHighResolutionExist = false; + gsp->IsHighResolutionExist(gspIsHighResolutionExist); return gspIsHighResolutionExist; } @@ -2039,7 +2143,7 @@ int32_t AudioPolicyManager::ActivateAudioSession(const AudioSessionStrategy &str return result; } } - return gsp->ActivateAudioSession(strategy); + return gsp->ActivateAudioSession(static_cast(strategy.concurrencyMode)); } int32_t AudioPolicyManager::DeactivateAudioSession() @@ -2053,7 +2157,9 @@ bool AudioPolicyManager::IsAudioSessionActivated() { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "audio policy manager proxy is NULL."); - return gsp->IsAudioSessionActivated(); + bool active = false; + gsp->IsAudioSessionActivated(active); + return active; } int32_t AudioPolicyManager::SetInputDevice(const DeviceType deviceType, const uint32_t sessionID, @@ -2153,7 +2259,7 @@ int32_t AudioPolicyManager::SetAudioSessionScene(const AudioSessionScene audioSe return result; } } - return gsp->SetAudioSessionScene(audioSessionScene); + return gsp->SetAudioSessionScene(static_cast(audioSessionScene)); } int32_t AudioPolicyManager::SetAudioSessionStateChangeCallback( @@ -2246,7 +2352,10 @@ int32_t AudioPolicyManager::GetDefaultOutputDevice(DeviceType &deviceType) return result; } } - return gsp->GetDefaultOutputDevice(deviceType); + int32_t deviceTypeOut = DEVICE_TYPE_NONE; + int32_t ret = gsp->GetDefaultOutputDevice(deviceTypeOut); + deviceType = static_cast(deviceTypeOut); + return ret; } int32_t AudioPolicyManager::SetDefaultOutputDevice(DeviceType deviceType) @@ -2260,14 +2369,16 @@ int32_t AudioPolicyManager::SetDefaultOutputDevice(DeviceType deviceType) return result; } } - return gsp->SetDefaultOutputDevice(deviceType); + return gsp->SetDefaultOutputDevice(static_cast(deviceType)); } AudioSpatializationSceneType AudioPolicyManager::GetSpatializationSceneType() { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, SPATIALIZATION_SCENE_TYPE_MUSIC, "audio policy manager proxy is NULL."); - return gsp->GetSpatializationSceneType(); + int32_t type = SPATIALIZATION_SCENE_TYPE_MUSIC; + gsp->GetSpatializationSceneType(type); + return static_cast(type); } int32_t AudioPolicyManager::SetSpatializationSceneType(const AudioSpatializationSceneType spatializationSceneType) @@ -2281,7 +2392,9 @@ float AudioPolicyManager::GetMaxAmplitude(const int32_t deviceId) { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, SPATIALIZATION_SCENE_TYPE_DEFAULT, "audio policy manager proxy is NULL."); - return gsp->GetMaxAmplitude(deviceId); + float ret = SPATIALIZATION_SCENE_TYPE_DEFAULT; + gsp->GetMaxAmplitude(deviceId, ret); + return ret; } int32_t AudioPolicyManager::DisableSafeMediaVolume() @@ -2295,7 +2408,9 @@ bool AudioPolicyManager::IsHeadTrackingDataRequested(const std::string &macAddre { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "audio policy manager proxy is NULL."); - return gsp->IsHeadTrackingDataRequested(macAddress); + bool ret = false; + gsp->IsHeadTrackingDataRequested(macAddress, ret); + return ret; } int32_t AudioPolicyManager::RegisterHeadTrackingDataRequestedEventListener(const std::string &macAddress, @@ -2347,7 +2462,7 @@ int32_t AudioPolicyManager::SetAudioDeviceRefinerCallback(const std::shared_ptr< }; std::unique_lock lock(listenerStubMutex_); - auto activeDistributedRoutingRoleCb = new (std::nothrow) AudioRoutingManagerListenerStub(); + auto activeDistributedRoutingRoleCb = new (std::nothrow) AudioRoutingManagerListener(); if (activeDistributedRoutingRoleCb == nullptr) { AUDIO_ERR_LOG("object is nullptr"); return ERROR; @@ -2379,7 +2494,7 @@ int32_t AudioPolicyManager::SetAudioClientInfoMgrCallback( return ERR_INVALID_PARAM; }; - sptr listener = new (std::nothrow) AudioPolicyManagerListenerStub(); + sptr listener = new (std::nothrow) AudioPolicyManagerListenerStubImpl(); CHECK_AND_RETURN_RET_LOG(listener != nullptr, ERROR, "object null"); listener->SetAudioClientInfoMgrCallback(callback); @@ -2398,7 +2513,7 @@ int32_t AudioPolicyManager::SetAudioVKBInfoMgrCallback( return ERR_INVALID_PARAM; }; - sptr listener = new (std::nothrow) AudioPolicyManagerListenerStub(); + sptr listener = new (std::nothrow) AudioPolicyManagerListenerStubImpl(); CHECK_AND_RETURN_RET_LOG(listener != nullptr, ERROR, "object null"); listener->SetAudioVKBInfoMgrCallback(callback); @@ -2415,7 +2530,7 @@ int32_t AudioPolicyManager::SetAudioConcurrencyCallback(const uint32_t sessionID CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERROR, "audio policy manager proxy is NULL."); CHECK_AND_RETURN_RET_LOG(callback != nullptr, ERR_INVALID_PARAM, "callback is nullptr"); - sptr listener = new(std::nothrow) AudioConcurrencyStateListenerStub(); + sptr listener = new(std::nothrow) AudioConcurrencyStateListenerService(); CHECK_AND_RETURN_RET_LOG(listener != nullptr, ERROR, "object null"); listener->SetConcurrencyCallback(callback); @@ -2484,7 +2599,13 @@ int32_t AudioPolicyManager::GetSupportedAudioEffectProperty(AudioEffectPropertyA { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_INVALID_PARAM, "audio policy manager proxy is NULL."); - return gsp->GetSupportedAudioEffectProperty(propertyArray); + int32_t result = gsp->GetSupportedAudioEffectProperty(propertyArray); + CHECK_AND_RETURN_RET_LOG(result == ERR_NONE, result, "Get Supported Audio Effect Property, error: %d", result); + + int32_t size = static_cast(propertyArray.property.size()); + CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT, + ERROR_INVALID_PARAM, "size invalid"); + return result; } int32_t AudioPolicyManager::SetAudioEffectProperty(const AudioEffectPropertyArrayV3 &propertyArray) @@ -2498,21 +2619,39 @@ int32_t AudioPolicyManager::GetAudioEffectProperty(AudioEffectPropertyArrayV3 &p { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_INVALID_PARAM, "audio policy manager proxy is NULL."); - return gsp->GetAudioEffectProperty(propertyArray); + int32_t result = gsp->GetAudioEffectProperty(propertyArray); + CHECK_AND_RETURN_RET_LOG(result == ERR_NONE, result, "Get Audio Effect Property, error: %d", result); + + int32_t size = static_cast(propertyArray.property.size()); + CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT, + ERROR_INVALID_PARAM, "size invalid"); + return result; } int32_t AudioPolicyManager::GetSupportedAudioEffectProperty(AudioEffectPropertyArray &propertyArray) { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_INVALID_PARAM, "audio policy manager proxy is NULL."); - return gsp->GetSupportedAudioEffectProperty(propertyArray); + int32_t result = gsp->GetSupportedAudioEffectProperty(propertyArray); + CHECK_AND_RETURN_RET_LOG(result == ERR_NONE, result, "Get Supported Audio Effect Property, error: %d", result); + + int32_t size = static_cast(propertyArray.property.size()); + CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT, + ERROR_INVALID_PARAM, "size invalid"); + return result; } int32_t AudioPolicyManager::GetSupportedAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray) { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_INVALID_PARAM, "audio policy manager proxy is NULL."); - return gsp->GetSupportedAudioEnhanceProperty(propertyArray); + int32_t result = gsp->GetSupportedAudioEnhanceProperty(propertyArray); + CHECK_AND_RETURN_RET_LOG(result == ERR_NONE, result, "Get Supported Audio Enhance Property, error: %d", result); + + int32_t size = static_cast(propertyArray.property.size()); + CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT, + ERROR_INVALID_PARAM, "size invalid"); + return result; } int32_t AudioPolicyManager::SetAudioEffectProperty(const AudioEffectPropertyArray &propertyArray) @@ -2526,7 +2665,13 @@ int32_t AudioPolicyManager::GetAudioEffectProperty(AudioEffectPropertyArray &pro { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_INVALID_PARAM, "audio policy manager proxy is NULL."); - return gsp->GetAudioEffectProperty(propertyArray); + int32_t result = gsp->GetAudioEffectProperty(propertyArray); + CHECK_AND_RETURN_RET_LOG(result == ERR_NONE, result, "Get Audio Effect Property, error: %d", result); + + int32_t size = static_cast(propertyArray.property.size()); + CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT, + ERROR_INVALID_PARAM, "size invalid"); + return result; } int32_t AudioPolicyManager::SetAudioEnhanceProperty(const AudioEnhancePropertyArray &propertyArray) @@ -2540,7 +2685,13 @@ int32_t AudioPolicyManager::GetAudioEnhanceProperty(AudioEnhancePropertyArray &p { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_INVALID_PARAM, "audio policy manager proxy is NULL."); - return gsp->GetAudioEnhanceProperty(propertyArray); + int32_t result = gsp->GetAudioEnhanceProperty(propertyArray); + CHECK_AND_RETURN_RET_LOG(result == ERR_NONE, result, "Get Audio Enhance Property, error: %d", result); + + int32_t size = static_cast(propertyArray.property.size()); + CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT, + ERROR_INVALID_PARAM, "size invalid"); + return result; } int32_t AudioPolicyManager::InjectInterruption(const std::string networkId, InterruptEvent &event) @@ -2561,7 +2712,9 @@ bool AudioPolicyManager::IsAllowedPlayback(const int32_t &uid, const int32_t &pi { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, -1, "audio policy manager proxy is NULL."); - return gsp->IsAllowedPlayback(uid, pid); + bool isAllowed = false; + gsp->IsAllowedPlayback(uid, pid, isAllowed); + return isAllowed; } int32_t AudioPolicyManager::SetVoiceRingtoneMute(bool isMute) @@ -2586,7 +2739,7 @@ int32_t AudioPolicyManager::SetQueryAllowedPlaybackCallback( CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERROR, "audio policy manager proxy is NULL."); CHECK_AND_RETURN_RET_LOG(callback != nullptr, ERR_INVALID_PARAM, "callback is nullptr"); - sptr listener = new(std::nothrow) AudioPolicyManagerListenerStub(); + sptr listener = new(std::nothrow) AudioPolicyManagerListenerStubImpl(); CHECK_AND_RETURN_RET_LOG(listener != nullptr, ERROR, "object null"); listener->SetQueryAllowedPlaybackCallback(callback); @@ -2604,7 +2757,7 @@ int32_t AudioPolicyManager::SetBackgroundMuteCallback( CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERROR, "audio policy manager proxy is NULL."); CHECK_AND_RETURN_RET_LOG(callback != nullptr, ERR_INVALID_PARAM, "callback is nullptr"); - sptr listener = new(std::nothrow) AudioPolicyManagerListenerStub(); + sptr listener = new(std::nothrow) AudioPolicyManagerListenerStubImpl(); CHECK_AND_RETURN_RET_LOG(listener != nullptr, ERROR, "object null"); listener->SetBackgroundMuteCallback(callback); @@ -2681,21 +2834,28 @@ DirectPlaybackMode AudioPolicyManager::GetDirectPlaybackSupport(const AudioStrea { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, DIRECT_PLAYBACK_NOT_SUPPORTED, "audio policy manager proxy is NULL."); - return gsp->GetDirectPlaybackSupport(streamInfo, streamUsage); + int32_t ret = DIRECT_PLAYBACK_NOT_SUPPORTED; + gsp->GetDirectPlaybackSupport(streamInfo, streamUsage, ret); + return static_cast(ret); } bool AudioPolicyManager::IsAcousticEchoCancelerSupported(SourceType sourceType) { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "audio policy manager proxy is NULL."); - return gsp->IsAcousticEchoCancelerSupported(sourceType); + + bool isSupport = false; + gsp->IsAcousticEchoCancelerSupported(sourceType, isSupport); + return isSupport; } bool AudioPolicyManager::SetKaraokeParameters(const std::string ¶meters) { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "audio policy manager proxy is NULL."); - return gsp->SetKaraokeParameters(parameters); + bool ret = false; + gsp->SetKaraokeParameters(parameters, ret); + return ret; } bool AudioPolicyManager::IsAudioLoopbackSupported(AudioLoopbackMode mode) @@ -2703,70 +2863,95 @@ bool AudioPolicyManager::IsAudioLoopbackSupported(AudioLoopbackMode mode) Trace trace("AudioPolicyManager::IsAudioLoopbackSupported"); const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "audio policy manager proxy is NULL."); - return gsp->IsAudioLoopbackSupported(mode); + bool support = false; + gsp->IsAudioLoopbackSupported(mode, support); + return support; } int32_t AudioPolicyManager::GetMaxVolumeLevelByUsage(StreamUsage streamUsage) { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_INVALID_PARAM, "audio policy manager proxy is NULL."); - return gsp->GetMaxVolumeLevelByUsage(streamUsage); + int32_t maxVolumeLevel = 0; + gsp->GetMaxVolumeLevelByUsage(streamUsage, maxVolumeLevel); + return maxVolumeLevel; } int32_t AudioPolicyManager::GetMinVolumeLevelByUsage(StreamUsage streamUsage) { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_INVALID_PARAM, "audio policy manager proxy is NULL."); - return gsp->GetMinVolumeLevelByUsage(streamUsage); + int32_t minVolumeLevel = 0; + gsp->GetMinVolumeLevelByUsage(streamUsage, minVolumeLevel); + return minVolumeLevel; } int32_t AudioPolicyManager::GetVolumeLevelByUsage(StreamUsage streamUsage) { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERR_INVALID_PARAM, "audio policy manager proxy is NULL."); - return gsp->GetVolumeLevelByUsage(streamUsage); + int32_t volumeLevel = 0; + gsp->GetVolumeLevelByUsage(streamUsage, volumeLevel); + return volumeLevel; } bool AudioPolicyManager::GetStreamMuteByUsage(StreamUsage streamUsage) { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "audio policy manager proxy is NULL."); - return gsp->GetStreamMuteByUsage(streamUsage); + bool isMute = false; + gsp->GetStreamMuteByUsage(streamUsage, isMute); + return isMute; } float AudioPolicyManager::GetVolumeInDbByStream(StreamUsage streamUsage, int32_t volumeLevel, DeviceType deviceType) { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERROR, "audio policy manager proxy is NULL."); - return gsp->GetVolumeInDbByStream(streamUsage, volumeLevel, deviceType); + float volume = -1; + gsp->GetVolumeInDbByStream(static_cast(streamUsage), volumeLevel, + static_cast(deviceType), volume); + return volume; } std::vector AudioPolicyManager::GetSupportedAudioVolumeTypes() { const sptr gsp = GetAudioPolicyManagerProxy(); + std::vector retList = {}; if (gsp == nullptr) { AUDIO_ERR_LOG("audio policy manager proxy is NULL."); - std::vector nullList = {}; - return nullList; + return retList; + } + std::vector inList = {}; + gsp->GetSupportedAudioVolumeTypes(inList); + for (auto &item : inList) { + retList.push_back(static_cast(item)); } - return gsp->GetSupportedAudioVolumeTypes(); + return retList; } AudioVolumeType AudioPolicyManager::GetAudioVolumeTypeByStreamUsage(StreamUsage streamUsage) { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, AudioVolumeType::STREAM_DEFAULT, "audio policy manager proxy is NULL."); - return gsp->GetAudioVolumeTypeByStreamUsage(streamUsage); + int32_t volumeType = AudioVolumeType::STREAM_DEFAULT; + gsp->GetAudioVolumeTypeByStreamUsage(streamUsage, volumeType); + return static_cast(volumeType); } std::vector AudioPolicyManager::GetStreamUsagesByVolumeType(AudioVolumeType audioVolumeType) { const sptr gsp = GetAudioPolicyManagerProxy(); + std::vector retList{}; if (gsp == nullptr) { AUDIO_ERR_LOG("audio policy manager proxy is NULL."); - std::vector nullList = {}; - return nullList; + return retList; } - return gsp->GetStreamUsagesByVolumeType(audioVolumeType); + std::vector inList = {}; + gsp->GetStreamUsagesByVolumeType(static_cast(audioVolumeType), inList); + for (auto &item : inList) { + retList.push_back(static_cast(item)); + } + return retList; } @@ -2818,14 +3003,21 @@ int32_t AudioPolicyManager::SetCallbackStreamUsageInfo(const std::set gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, -1, "audio policy manager proxy is NULL."); - return gsp->SetCallbackStreamUsageInfo(streamUsages); + + std::set streamUsagesIn; + for (auto item : streamUsages) { + streamUsagesIn.insert(static_cast(item)); + } + return gsp->SetCallbackStreamUsageInfo(streamUsagesIn); } bool AudioPolicyManager::IsCollaborativePlaybackSupported() { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "audio policy manager proxy is NULL."); - return gsp->IsCollaborativePlaybackSupported(); + bool support = false; + gsp->IsCollaborativePlaybackSupported(support); + return support; } bool AudioPolicyManager::IsCollaborativePlaybackEnabledForDevice( @@ -2833,7 +3025,9 @@ bool AudioPolicyManager::IsCollaborativePlaybackEnabledForDevice( { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "audio policy manager proxy is NULL."); - return gsp->IsCollaborativePlaybackEnabledForDevice(selectedAudioDevice); + bool enable = false; + gsp->IsCollaborativePlaybackEnabledForDevice(selectedAudioDevice, enable); + return enable; } int32_t AudioPolicyManager::SetCollaborativePlaybackEnabledForDevice( @@ -2855,7 +3049,9 @@ bool AudioPolicyManager::IsCapturerFocusAvailable(const AudioCapturerInfo &captu { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "audio policy manager proxy is NULL."); - return gsp->IsCapturerFocusAvailable(capturerInfo); + bool isAvailable = false; + gsp->IsCapturerFocusAvailable(capturerInfo, isAvailable); + return isAvailable; } AudioPolicyManager& AudioPolicyManager::GetInstance() diff --git a/services/audio_policy/client/service/src/audio_policy_manager_device.cpp b/services/audio_policy/client/service/src/audio_policy_manager_device.cpp index 3bd731d73a..537bafe836 100644 --- a/services/audio_policy/client/service/src/audio_policy_manager_device.cpp +++ b/services/audio_policy/client/service/src/audio_policy_manager_device.cpp @@ -35,6 +35,14 @@ int32_t AudioPolicyManager::SelectOutputDevice(sptr audioRe { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, -1, "audio policy manager proxy is NULL."); + + int32_t validSize = 20; // Use 20 as limit. + int32_t size = static_cast(audioDeviceDescriptors.size()); + if (size <= 0 || size > validSize) { + AUDIO_ERR_LOG("SelectOutputDevice get invalid device size."); + return -1; + } + return gsp->SelectOutputDevice(audioRendererFilter, audioDeviceDescriptors); } @@ -42,7 +50,10 @@ std::string AudioPolicyManager::GetSelectedDeviceInfo(int32_t uid, int32_t pid, { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, "", "audio policy manager proxy is NULL."); - return gsp->GetSelectedDeviceInfo(uid, pid, streamType); + + std::string out{}; + gsp->GetSelectedDeviceInfo(uid, pid, streamType, out); + return out; } int32_t AudioPolicyManager::SelectInputDevice(sptr audioCapturerFilter, @@ -50,6 +61,10 @@ int32_t AudioPolicyManager::SelectInputDevice(sptr audioCap { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, -1, "audio policy manager proxy is NULL."); + + int32_t validSize = 10; // Use 10 as limit. + int32_t size = static_cast(audioDeviceDescriptors.size()); + CHECK_AND_RETURN_RET_LOG(size > 0 && size <= validSize, -1, "SelectInputDevice get invalid device size."); return gsp->SelectInputDevice(audioCapturerFilter, audioDeviceDescriptors); } @@ -58,6 +73,10 @@ int32_t AudioPolicyManager::ExcludeOutputDevices(AudioDeviceUsage audioDevUsage, { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, -1, "audio policy manager proxy is NULL."); + + int32_t validSize = 20; // Use 20 as limit. + int32_t size = static_cast(audioDeviceDescriptors.size()); + CHECK_AND_RETURN_RET_LOG(size > 0 && size <= validSize, -1, "ExcludeOutputDevices get invalid device size."); return gsp->ExcludeOutputDevices(audioDevUsage, audioDeviceDescriptors); } @@ -66,6 +85,10 @@ int32_t AudioPolicyManager::UnexcludeOutputDevices(AudioDeviceUsage audioDevUsag { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, -1, "audio policy manager proxy is NULL."); + + int32_t validSize = 20; // Use 20 as limit. + int32_t size = static_cast(audioDeviceDescriptors.size()); + CHECK_AND_RETURN_RET_LOG(size > 0 && size <= validSize, -1, "UnexcludeOutputDevices get invalid device size."); return gsp->UnexcludeOutputDevices(audioDevUsage, audioDeviceDescriptors); } @@ -73,34 +96,37 @@ std::vector> AudioPolicyManager::GetExclu AudioDeviceUsage audioDevUsage) { const sptr gsp = GetAudioPolicyManagerProxy(); + std::vector> deviceInfo; if (gsp == nullptr) { AUDIO_ERR_LOG("GetExcludedDevices: audio policy manager proxy is NULL."); - std::vector> deviceInfo; return deviceInfo; } - return gsp->GetExcludedDevices(audioDevUsage); + gsp->GetExcludedDevices(audioDevUsage, deviceInfo); + return deviceInfo; } std::vector> AudioPolicyManager::GetDevices(DeviceFlag deviceFlag) { const sptr gsp = GetAudioPolicyManagerProxy(); + std::vector> deviceInfo; if (gsp == nullptr) { AUDIO_ERR_LOG("GetDevices: audio policy manager proxy is NULL."); - std::vector> deviceInfo; return deviceInfo; } - return gsp->GetDevices(deviceFlag); + gsp->GetDevices(deviceFlag, deviceInfo); + return deviceInfo; } std::vector> AudioPolicyManager::GetDevicesInner(DeviceFlag deviceFlag) { const sptr gsp = GetAudioPolicyManagerProxy(); + std::vector> deviceInfo; if (gsp == nullptr) { AUDIO_ERR_LOG("audio policy manager proxy is NULL."); - std::vector> deviceInfo; return deviceInfo; } - return gsp->GetDevicesInner(deviceFlag); + gsp->GetDevicesInner(deviceFlag, deviceInfo); + return deviceInfo; } std::vector> AudioPolicyManager::GetPreferredOutputDeviceDescriptors( @@ -109,83 +135,96 @@ std::vector> AudioPolicyManager::GetPrefe AudioXCollie audioXCollie("AudioPolicyManager::GetPreferredOutputDeviceDescriptors", TIME_OUT_SECONDS, nullptr, nullptr, AUDIO_XCOLLIE_FLAG_LOG); const sptr gsp = GetAudioPolicyManagerProxy(); + std::vector> deviceInfo; if (gsp == nullptr) { AUDIO_ERR_LOG("GetPreferredOutputDeviceDescriptors: audio policy manager proxy is NULL."); - std::vector> deviceInfo; return deviceInfo; } - return gsp->GetPreferredOutputDeviceDescriptors(rendererInfo, forceNoBTPermission); + gsp->GetPreferredOutputDeviceDescriptors(rendererInfo, forceNoBTPermission, deviceInfo); + return deviceInfo; } std::vector> AudioPolicyManager::GetPreferredInputDeviceDescriptors( AudioCapturerInfo &captureInfo) { const sptr gsp = GetAudioPolicyManagerProxy(); + std::vector> deviceInfo; if (gsp == nullptr) { AUDIO_ERR_LOG("audio policy manager proxy is NULL."); - std::vector> deviceInfo; return deviceInfo; } - return gsp->GetPreferredInputDeviceDescriptors(captureInfo); + gsp->GetPreferredInputDeviceDescriptors(captureInfo, deviceInfo); + return deviceInfo; } std::vector> AudioPolicyManager::GetOutputDevice( sptr audioRendererFilter) { const sptr gsp = GetAudioPolicyManagerProxy(); + std::vector> deviceInfo; if (gsp == nullptr) { AUDIO_ERR_LOG("audio policy manager proxy is NULL."); - std::vector> deviceInfo; return deviceInfo; } - return gsp->GetOutputDevice(audioRendererFilter); + gsp->GetOutputDevice(audioRendererFilter, deviceInfo); + return deviceInfo; } std::vector> AudioPolicyManager::GetInputDevice( sptr audioCapturerFilter) { const sptr gsp = GetAudioPolicyManagerProxy(); + std::vector> deviceInfo; if (gsp == nullptr) { AUDIO_ERR_LOG("audio policy manager proxy is NULL."); - std::vector> deviceInfo; return deviceInfo; } - return gsp->GetInputDevice(audioCapturerFilter); + gsp->GetInputDevice(audioCapturerFilter, deviceInfo); + return deviceInfo; } int32_t AudioPolicyManager::SetDeviceActive(InternalDeviceType deviceType, bool active, const int32_t uid) { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, -1, "audio policy manager proxy is NULL."); - return gsp->SetDeviceActive(deviceType, active, uid); + int32_t uidIn = uid; + return gsp->SetDeviceActive(deviceType, active, uidIn); } bool AudioPolicyManager::IsDeviceActive(InternalDeviceType deviceType) { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, false, "audio policy manager proxy is NULL."); - return gsp->IsDeviceActive(deviceType); + bool active = false; + gsp->IsDeviceActive(deviceType, active); + return active; } DeviceType AudioPolicyManager::GetActiveOutputDevice() { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, DEVICE_TYPE_INVALID, "audio policy manager proxy is NULL."); - return gsp->GetActiveOutputDevice(); + int32_t out = DEVICE_TYPE_INVALID; + gsp->GetActiveOutputDevice(out); + return static_cast(out); } uint16_t AudioPolicyManager::GetDmDeviceType() { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, DEVICE_TYPE_INVALID, "audio policy manager proxy is NULL."); - return gsp->GetDmDeviceType(); + uint16_t out = DEVICE_TYPE_INVALID; + gsp->GetDmDeviceType(out); + return out; } DeviceType AudioPolicyManager::GetActiveInputDevice() { const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, DEVICE_TYPE_INVALID, "audio policy manager proxy is NULL."); - return gsp->GetActiveInputDevice(); + int32_t out = DEVICE_TYPE_INVALID; + gsp->GetActiveInputDevice(out); + return static_cast(out); } // LCOV_EXCL_START @@ -384,13 +423,14 @@ int32_t AudioPolicyManager::UnregisterDeviceChangeWithInfoCallback(const uint32_ std::vector> AudioPolicyManager::GetAvailableDevices(AudioDeviceUsage usage) { + std::vector> descs; const sptr gsp = GetAudioPolicyManagerProxy(); if (gsp == nullptr) { AUDIO_ERR_LOG("GetAvailableMicrophones: audio policy manager proxy is NULL."); - std::vector> descs; return descs; } - return gsp->GetAvailableDevices(usage); + gsp->GetAvailableDevices(usage, descs); + return descs; } int32_t AudioPolicyManager::SetAvailableDeviceChangeCallback(const int32_t clientId, const AudioDeviceUsage usage, @@ -400,7 +440,7 @@ int32_t AudioPolicyManager::SetAvailableDeviceChangeCallback(const int32_t clien CHECK_AND_RETURN_RET_LOG(gsp != nullptr, -1, "audio policy manager proxy is NULL."); CHECK_AND_RETURN_RET_LOG(callback != nullptr, ERR_INVALID_PARAM, "callback is nullptr"); - auto deviceChangeCbStub = new(std::nothrow) AudioPolicyManagerListenerStub(); + auto deviceChangeCbStub = new(std::nothrow) AudioPolicyManagerListenerStubImpl(); CHECK_AND_RETURN_RET_LOG(deviceChangeCbStub != nullptr, ERROR, "object null"); deviceChangeCbStub->SetAvailableDeviceChangeCallback(callback); @@ -430,7 +470,7 @@ int32_t AudioPolicyManager::UnsetAvailableDeviceChangeCallback(const int32_t cli availableDeviceChangeCbsMap_.erase({clientId, usage}); } - return gsp->UnsetAvailableDeviceChangeCallback(clientId, usage); + return gsp->UnsetAvailableDeviceChangeCallback(clientId, static_cast(usage)); } int32_t AudioPolicyManager::SetCallDeviceActive(InternalDeviceType deviceType, bool active, std::string address, @@ -441,7 +481,7 @@ int32_t AudioPolicyManager::SetCallDeviceActive(InternalDeviceType deviceType, b AUDIO_ERR_LOG("audio policy manager proxy is NULL."); return -1; } - return gsp->SetCallDeviceActive(deviceType, active, address, uid); + return gsp->SetCallDeviceActive(static_cast(deviceType), active, address, uid); } std::shared_ptr AudioPolicyManager::GetActiveBluetoothDevice() @@ -451,7 +491,9 @@ std::shared_ptr AudioPolicyManager::GetActiveBluetoothDev AUDIO_ERR_LOG("audio policy manager proxy is NULL."); return make_shared(); } - return gsp->GetActiveBluetoothDevice(); + std::shared_ptr descs = make_shared(); + gsp->GetActiveBluetoothDevice(descs); + return descs; } void AudioPolicyManager::FetchOutputDeviceForTrack(AudioStreamChangeInfo &streamChangeInfo, @@ -499,7 +541,7 @@ int32_t AudioPolicyManager::SetAudioDeviceAnahsCallback(const std::shared_ptr lock(listenerStubMutex_); - auto activeDistributedAnahsRoleCb = new (std::nothrow) AudioAnahsManagerListenerStub(); + auto activeDistributedAnahsRoleCb = new (std::nothrow) AudioAnahsManagerListener(); if (activeDistributedAnahsRoleCb == nullptr) { AUDIO_ERR_LOG("object is nullptr"); return ERROR; @@ -562,7 +604,7 @@ int32_t AudioPolicyManager::SetSleAudioOperationCallback(const std::shared_ptr lock(listenerStubMutex_); - auto audioSleCb = new (std::nothrow) SleAudioOperationCallbackStub(); + auto audioSleCb = new (std::nothrow) SleAudioOperationCallbackStubImpl(); CHECK_AND_RETURN_RET_LOG(audioSleCb != nullptr, ERROR, "object is nullptr"); audioSleCb->SetSleAudioOperationCallback(callback); diff --git a/services/audio_policy/client/service/src/audio_policy_manager_zone.cpp b/services/audio_policy/client/service/src/audio_policy_manager_zone.cpp index 5f52c4b1a3..3e9c71fa0d 100644 --- a/services/audio_policy/client/service/src/audio_policy_manager_zone.cpp +++ b/services/audio_policy/client/service/src/audio_policy_manager_zone.cpp @@ -39,7 +39,9 @@ int32_t AudioPolicyManager::CreateAudioZone(const std::string &name, const Audio const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERROR, "audio policy manager proxy is NULL."); - return gsp->CreateAudioZone(name, context); + int32_t zoneId = ERROR; + gsp->CreateAudioZone(name, context, zoneId); + return zoneId; } void AudioPolicyManager::ReleaseAudioZone(int32_t zoneId) @@ -56,7 +58,9 @@ const std::vector> AudioPolicyManager::GetA std::vector> zoneDescriptors; CHECK_AND_RETURN_RET_LOG(gsp != nullptr, zoneDescriptors, "audio policy manager proxy is NULL."); - return gsp->GetAllAudioZone(); + std::vector> descs; + gsp->GetAllAudioZone(descs); + return descs; } const std::shared_ptr AudioPolicyManager::GetAudioZone(int32_t zoneId) @@ -64,7 +68,9 @@ const std::shared_ptr AudioPolicyManager::GetAudioZone(int3 const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, nullptr, "audio policy manager proxy is NULL."); - return gsp->GetAudioZone(zoneId); + std::shared_ptr desc; + gsp->GetAudioZone(zoneId, desc); + return desc; } int32_t AudioPolicyManager::BindDeviceToAudioZone(int32_t zoneId, @@ -151,7 +157,10 @@ std::list> AudioPolicyManager::GetAudi const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, {}, "audio policy manager proxy is NULL."); - return gsp->GetAudioInterruptForZone(zoneId); + std::vector> retList; + gsp->GetAudioInterruptForZone(zoneId, retList); + auto focusInfoList = FromIpcInterrupts(retList); + return focusInfoList; } std::list> AudioPolicyManager::GetAudioInterruptForZone( @@ -160,7 +169,10 @@ std::list> AudioPolicyManager::GetAudi const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, {}, "audio policy manager proxy is NULL."); - return gsp->GetAudioInterruptForZone(zoneId, deviceTag); + std::vector> retList; + gsp->GetAudioInterruptForZone(zoneId, deviceTag, retList); + auto focusInfoList = FromIpcInterrupts(retList); + return focusInfoList; } int32_t AudioPolicyManager::EnableAudioZoneInterruptReport(int32_t zoneId, const std::string &deviceTag, bool enable) @@ -177,7 +189,8 @@ int32_t AudioPolicyManager::InjectInterruptToAudioZone(int32_t zoneId, const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERROR, "audio policy manager proxy is NULL."); - return gsp->InjectInterruptToAudioZone(zoneId, interrupts); + auto ipcInterrupts = ToIpcInterrupts(interrupts); + return gsp->InjectInterruptToAudioZone(zoneId, ipcInterrupts); } int32_t AudioPolicyManager::InjectInterruptToAudioZone(int32_t zoneId, const std::string &deviceTag, @@ -186,7 +199,8 @@ int32_t AudioPolicyManager::InjectInterruptToAudioZone(int32_t zoneId, const std const sptr gsp = GetAudioPolicyManagerProxy(); CHECK_AND_RETURN_RET_LOG(gsp != nullptr, ERROR, "audio policy manager proxy is NULL."); - return gsp->InjectInterruptToAudioZone(zoneId, deviceTag, interrupts); + auto ipcInterrupts = ToIpcInterrupts(interrupts); + return gsp->InjectInterruptToAudioZone(zoneId, deviceTag, ipcInterrupts); } } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_policy/client/stub/src/audio_routing_manager_listener_stub.cpp b/services/audio_policy/client/service/src/audio_routing_manager_listener.cpp similarity index 37% rename from services/audio_policy/client/stub/src/audio_routing_manager_listener_stub.cpp rename to services/audio_policy/client/service/src/audio_routing_manager_listener.cpp index 6572e32fe3..a0ed547b37 100644 --- a/services/audio_policy/client/stub/src/audio_routing_manager_listener_stub.cpp +++ b/services/audio_policy/client/service/src/audio_routing_manager_listener.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * 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 @@ -13,83 +13,45 @@ * limitations under the License. */ #ifndef LOG_TAG -#define LOG_TAG "AudioRoutingManagerListenerStub" +#define LOG_TAG "AudioRoutingManagerListener" #endif -#include "audio_routing_manager_listener_stub.h" - +#include "audio_routing_manager_listener.h" #include "audio_errors.h" #include "audio_policy_log.h" -using namespace std; - namespace OHOS { namespace AudioStandard { -static const int32_t PREFERRED_DEVICE_VALID_SIZE = 128; - -AudioRoutingManagerListenerStub::AudioRoutingManagerListenerStub() -{ -} - -AudioRoutingManagerListenerStub::~AudioRoutingManagerListenerStub() +AudioRoutingManagerListener::AudioRoutingManagerListener() { } -int AudioRoutingManagerListenerStub::OnRemoteRequest( - uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) +AudioRoutingManagerListener::~AudioRoutingManagerListener() { - CHECK_AND_RETURN_RET_LOG(data.ReadInterfaceToken() == GetDescriptor(), - -1, "AudioRingerModeUpdateListenerStub: ReadInterfaceToken failed"); - switch (code) { - case ON_DISTRIBUTED_ROUTING_ROLE_CHANGE: { - std::shared_ptr descriptor = AudioDeviceDescriptor::UnmarshallingPtr(data); - CastType type = static_cast(data.ReadInt32()); - OnDistributedRoutingRoleChange(descriptor, type); - return AUDIO_OK; - } - case ON_AUDIO_OUTPUT_DEVICE_REFINERD: { - OnAudioOutputDeviceRefinedInternal(data, reply); - return AUDIO_OK; - } - case ON_AUDIO_INPUT_DEVICE_REFINERD: { - OnAudioInputDeviceRefinedInternal(data, reply); - return AUDIO_OK; - } - case GET_SPLIT_INFO_REFINED: { - GetSplitInfoRefinedInternal(data, reply); - return AUDIO_OK; - } - case ON_DISTRIBUTED_OUTPUT_CHANGE: { - OnDistributedOutputChangeInternal(data, reply); - return AUDIO_OK; - } - default: { - AUDIO_ERR_LOG("default case, need check AudioListenerStub"); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } - } } -void AudioRoutingManagerListenerStub::OnDistributedRoutingRoleChange( - const std::shared_ptr descriptor, const CastType type) +int32_t AudioRoutingManagerListener::OnDistributedRoutingRoleChange( + const std::shared_ptr &descriptor, int32_t type) { std::shared_ptr audioDistributedRoutingRoleCallback = audioDistributedRoutingRoleCallback_.lock(); - CHECK_AND_RETURN_LOG(audioDistributedRoutingRoleCallback != nullptr, + CHECK_AND_RETURN_RET_LOG(audioDistributedRoutingRoleCallback != nullptr, + ERR_CALLBACK_NOT_REGISTERED, "OnDistributedRoutingRoleChange: audioDistributedRoutingRoleCallback_ is nullptr"); - audioDistributedRoutingRoleCallback->OnDistributedRoutingRoleChange(descriptor, type); + audioDistributedRoutingRoleCallback->OnDistributedRoutingRoleChange(descriptor, static_cast(type)); + return SUCCESS; } -void AudioRoutingManagerListenerStub::SetDistributedRoutingRoleCallback( +void AudioRoutingManagerListener::SetDistributedRoutingRoleCallback( const std::weak_ptr &callback) { audioDistributedRoutingRoleCallback_ = callback; } -void AudioRoutingManagerListenerStub::SetAudioDeviceRefinerCallback(const std::weak_ptr &callback) +void AudioRoutingManagerListener::SetAudioDeviceRefinerCallback(const std::weak_ptr &callback) { std::lock_guard lock(deviceRefinerCallbackMutex_); audioDeviceRefinerCallback_ = callback; @@ -97,75 +59,9 @@ void AudioRoutingManagerListenerStub::SetAudioDeviceRefinerCallback(const std::w CHECK_AND_RETURN_LOG(audioDeviceRefinerCallback != nullptr, "audioDeviceRefinerCallback_ is nullptr"); } -void AudioRoutingManagerListenerStub::OnAudioOutputDeviceRefinedInternal(MessageParcel &data, MessageParcel &reply) -{ - std::vector> descs; - int32_t size = data.ReadInt32(); - CHECK_AND_RETURN_LOG(size < PREFERRED_DEVICE_VALID_SIZE, "get invalid size : %{public}d", size); - for (int32_t i = 0; i < size; i++) { - descs.push_back(make_shared(AudioDeviceDescriptor::UnmarshallingPtr(data))); - } - RouterType routerType = static_cast(data.ReadInt32()); - StreamUsage streamUsage = static_cast(data.ReadInt32()); - int32_t clientUid = data.ReadInt32(); - AudioPipeType audioPipeType = static_cast(data.ReadInt32()); - - int32_t result = OnAudioOutputDeviceRefined(descs, routerType, streamUsage, clientUid, audioPipeType); - if (result == SUCCESS) { - reply.WriteInt32(result); - reply.WriteInt32(descs.size()); - for (auto &desc : descs) { - desc->Marshalling(reply); - } - } else { - reply.WriteInt32(result); - } -} - -void AudioRoutingManagerListenerStub::OnDistributedOutputChangeInternal(MessageParcel &data, MessageParcel &reply) -{ - bool isRemote = data.ReadBool(); - int32_t result = OnDistributedOutputChange(isRemote); - reply.WriteInt32(result); -} - -void AudioRoutingManagerListenerStub::OnAudioInputDeviceRefinedInternal(MessageParcel &data, MessageParcel &reply) -{ - std::vector> descs; - int32_t size = data.ReadInt32(); - CHECK_AND_RETURN_LOG(size < PREFERRED_DEVICE_VALID_SIZE, "get invalid size : %{public}d", size); - for (int32_t i = 0; i < size; i++) { - descs.push_back(make_shared(AudioDeviceDescriptor::UnmarshallingPtr(data))); - } - RouterType routerType = static_cast(data.ReadInt32()); - SourceType sourceType = static_cast(data.ReadInt32()); - int32_t clientUid = data.ReadInt32(); - AudioPipeType audioPipeType = static_cast(data.ReadInt32()); - - int32_t result = OnAudioInputDeviceRefined(descs, routerType, sourceType, clientUid, audioPipeType); - if (result == SUCCESS) { - reply.WriteInt32(result); - reply.WriteInt32(descs.size()); - for (auto &desc : descs) { - desc->Marshalling(reply); - } - } else { - reply.WriteInt32(result); - } -} - -void AudioRoutingManagerListenerStub::GetSplitInfoRefinedInternal(MessageParcel &data, MessageParcel &reply) -{ - std::string splitInfo = ""; - - int32_t result = GetSplitInfoRefined(splitInfo); - reply.WriteInt32(result); - reply.WriteString(splitInfo); -} - -int32_t AudioRoutingManagerListenerStub::OnAudioOutputDeviceRefined( - std::vector> &descs, RouterType routerType, StreamUsage streamUsage, - int32_t clientUid, AudioPipeType audioPipeType) +int32_t AudioRoutingManagerListener::OnAudioOutputDeviceRefined( + std::vector> &descs, int32_t routerType, int32_t streamUsage, + int32_t clientUid, int32_t audioPipeType) { std::unique_lock lock(deviceRefinerCallbackMutex_); std::shared_ptr audioDeviceRefinerCallback = audioDeviceRefinerCallback_.lock(); @@ -173,11 +69,12 @@ int32_t AudioRoutingManagerListenerStub::OnAudioOutputDeviceRefined( ERR_CALLBACK_NOT_REGISTERED, "audioDeviceRefinerCallback_ is nullptr"); lock.unlock(); - return audioDeviceRefinerCallback->OnAudioOutputDeviceRefined(descs, routerType, streamUsage, clientUid, - audioPipeType); + return audioDeviceRefinerCallback->OnAudioOutputDeviceRefined(descs, + static_cast(routerType), static_cast(streamUsage), clientUid, + static_cast(audioPipeType)); } -int32_t AudioRoutingManagerListenerStub::OnDistributedOutputChange(bool isRemote) +int32_t AudioRoutingManagerListener::OnDistributedOutputChange(bool isRemote) { std::unique_lock lock(deviceRefinerCallbackMutex_); std::shared_ptr audioDeviceRefinerCallback = audioDeviceRefinerCallback_.lock(); @@ -188,9 +85,9 @@ int32_t AudioRoutingManagerListenerStub::OnDistributedOutputChange(bool isRemote return audioDeviceRefinerCallback->OnDistributedOutputChange(isRemote); } -int32_t AudioRoutingManagerListenerStub::OnAudioInputDeviceRefined( - std::vector> &descs, RouterType routerType, SourceType sourceType, - int32_t clientUid, AudioPipeType audioPipeType) +int32_t AudioRoutingManagerListener::OnAudioInputDeviceRefined( + std::vector> &descs, int32_t routerType, int32_t sourceType, + int32_t clientUid, int32_t audioPipeType) { std::unique_lock lock(deviceRefinerCallbackMutex_); std::shared_ptr audioDeviceRefinerCallback = audioDeviceRefinerCallback_.lock(); @@ -198,11 +95,11 @@ int32_t AudioRoutingManagerListenerStub::OnAudioInputDeviceRefined( "audioDeviceRefinerCallback_ is nullptr"); lock.unlock(); - return audioDeviceRefinerCallback->OnAudioInputDeviceRefined(descs, routerType, - sourceType, clientUid, audioPipeType); + return audioDeviceRefinerCallback->OnAudioInputDeviceRefined(descs, static_cast(routerType), + static_cast(sourceType), clientUid, static_cast(audioPipeType)); } -int32_t AudioRoutingManagerListenerStub::GetSplitInfoRefined(std::string &splitInfo) +int32_t AudioRoutingManagerListener::GetSplitInfoRefined(std::string &splitInfo) { std::unique_lock lock(deviceRefinerCallbackMutex_); std::shared_ptr audioDeviceRefinerCallback = audioDeviceRefinerCallback_.lock(); diff --git a/services/audio_policy/client/stub/include/audio_policy_client_stub.h b/services/audio_policy/client/stub/include/audio_policy_client_stub.h deleted file mode 100644 index 2b7d78ee2a..0000000000 --- a/services/audio_policy/client/stub/include/audio_policy_client_stub.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef AUDIO_POLICY_CLIENT_STUB_H -#define AUDIO_POLICY_CLIENT_STUB_H - -#include "event_handler.h" -#include "event_runner.h" -#include "audio_policy_client.h" -#include "audio_system_manager.h" - -namespace OHOS { -namespace AudioStandard { -class AudioPolicyClientStub : public IRemoteStub { -public: - AudioPolicyClientStub(); - ~AudioPolicyClientStub(); - virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &option) override; -private: - void HandleActiveVolumeTypeChange(MessageParcel &data, MessageParcel &reply); - void HandleAppVolumeChange(MessageParcel &data, MessageParcel &reply); - void HandleVolumeKeyEvent(MessageParcel &data, MessageParcel &reply); - void HandleAudioFocusInfoChange(MessageParcel &data, MessageParcel &reply); - void HandleAudioFocusRequested(MessageParcel &data, MessageParcel &reply); - void HandleAudioFocusAbandoned(MessageParcel &data, MessageParcel &reply); - void HandleDeviceChange(MessageParcel &data, MessageParcel &reply); - void HandleMicrophoneBlocked(MessageParcel &data, MessageParcel &reply); - void HandleRingerModeUpdated(MessageParcel &data, MessageParcel &reply); - void HandleMicStateChange(MessageParcel &data, MessageParcel &reply); - void HandlePreferredOutputDeviceUpdated(MessageParcel &data, MessageParcel &reply); - void HandlePreferredInputDeviceUpdated(MessageParcel &data, MessageParcel &reply); - void HandleRendererStateChange(MessageParcel &data, MessageParcel &reply); - void HandleCapturerStateChange(MessageParcel &data, MessageParcel &reply); - void HandleRendererDeviceChange(MessageParcel &data, MessageParcel &reply); - void HandleRecreateRendererStreamEvent(MessageParcel &data, MessageParcel &reply); - void HandleRecreateCapturerStreamEvent(MessageParcel &data, MessageParcel &reply); - void HandleHeadTrackingDeviceChange(MessageParcel &data, MessageParcel &reply); - void HandleSpatializationEnabledChange(MessageParcel &data, MessageParcel &reply); - void HandleSpatializationEnabledChangeForAnyDevice(MessageParcel &data, MessageParcel &reply); - void HandleSpatializationEnabledChangeForCurrentDevice(MessageParcel &data, MessageParcel &reply); - void HandleHeadTrackingEnabledChange(MessageParcel &data, MessageParcel &reply); - void HandleHeadTrackingEnabledChangeForAnyDevice(MessageParcel &data, MessageParcel &reply); - void HandleNnStateChange(MessageParcel &data, MessageParcel &reply); - void HandleAudioSessionCallback(MessageParcel &data, MessageParcel &reply); - void HandleAudioSceneChange(MessageParcel &data, MessageParcel &reply); - void HandleFormatUnsupportedError(MessageParcel &data, MessageParcel &reply); - void HandleStreamVolumeChange(MessageParcel &data, MessageParcel &reply); - void HandleSystemVolumeChange(MessageParcel &data, MessageParcel &reply); - void HandleAudioSessionStateCallback(MessageParcel &data, MessageParcel &reply); - - void OnMaxRemoteRequest(uint32_t updateCode, MessageParcel &data, MessageParcel &reply); - void OnFirMaxRemoteRequest(uint32_t updateCode, MessageParcel &data, MessageParcel &reply); -}; -} // namespace AudioStandard -} // namespace OHOS -#endif // AUDIO_POLICY_CLIENT_STUB_H \ No newline at end of file diff --git a/services/audio_policy/client/stub/include/audio_policy_client_stub_impl.h b/services/audio_policy/client/stub/include/audio_policy_client_stub_impl.h index 69d7b095d5..7454379be6 100644 --- a/services/audio_policy/client/stub/include/audio_policy_client_stub_impl.h +++ b/services/audio_policy/client/stub/include/audio_policy_client_stub_impl.h @@ -26,6 +26,7 @@ #include "audio_spatialization_manager.h" #include "audio_combine_denoising_manager.h" #include "audio_policy_interface.h" +#include "audio_stream_manager.h" namespace OHOS { namespace AudioStandard { @@ -135,46 +136,45 @@ public: int32_t RemoveAudioFormatUnsupportedErrorCallback(); size_t GetAudioFormatUnsupportedErrorCallbackSize() const; - void OnRecreateRendererStreamEvent(const uint32_t sessionId, const int32_t streamFlag, - const AudioStreamDeviceChangeReasonExt reason) override; - void OnRecreateCapturerStreamEvent(const uint32_t sessionId, const int32_t streamFlag, - const AudioStreamDeviceChangeReasonExt reason) override; - void OnVolumeKeyEvent(VolumeEvent volumeEvent) override; - void OnAudioFocusInfoChange(const std::list> &focusInfoList) override; - void OnAudioFocusRequested(const AudioInterrupt &requestFocus) override; - void OnAudioFocusAbandoned(const AudioInterrupt &abandonFocus) override; - void OnDeviceChange(const DeviceChangeAction &deviceChangeAction) override; - void OnMicrophoneBlocked(const MicrophoneBlockedInfo µphoneBlockedInfo) override; - void OnRingerModeUpdated(const AudioRingerMode &ringerMode) override; - void OnActiveVolumeTypeChanged(const AudioVolumeType& volumeType) override; - void OnAppVolumeChanged(int32_t appUid, const VolumeEvent& volumeEvent) override; - void OnMicStateUpdated(const MicStateChangeEvent &micStateChangeEvent) override; - void OnPreferredOutputDeviceUpdated(const AudioRendererInfo &rendererInfo, + int32_t OnRecreateRendererStreamEvent(uint32_t sessionId, int32_t streamFlag, + const AudioStreamDeviceChangeReasonExt &reason) override; + int32_t OnRecreateCapturerStreamEvent(uint32_t sessionId, int32_t streamFlag, + const AudioStreamDeviceChangeReasonExt &reason) override; + int32_t OnVolumeKeyEvent(const VolumeEvent &volumeEvent) override; + int32_t OnAudioFocusInfoChange(const std::vector> &focusInfoList) override; + int32_t OnAudioFocusRequested(const AudioInterrupt &requestFocus) override; + int32_t OnAudioFocusAbandoned(const AudioInterrupt &abandonFocus) override; + int32_t OnDeviceChange(const DeviceChangeAction &deviceChangeAction) override; + int32_t OnMicrophoneBlocked(const MicrophoneBlockedInfo µphoneBlockedInfo) override; + int32_t OnRingerModeUpdated(int32_t ringerMode) override; + int32_t OnActiveVolumeTypeChanged(int32_t volumeType) override; + int32_t OnAppVolumeChanged(int32_t appUid, const VolumeEvent& volumeEvent) override; + int32_t OnMicStateUpdated(const MicStateChangeEvent &micStateChangeEvent) override; + int32_t OnPreferredOutputDeviceUpdated(const AudioRendererInfo &rendererInfo, const std::vector> &desc) override; - void OnPreferredInputDeviceUpdated(const AudioCapturerInfo &capturerInfo, + int32_t OnPreferredInputDeviceUpdated(const AudioCapturerInfo &capturerInfo, const std::vector> &desc) override; - void OnRendererStateChange( - std::vector> &audioRendererChangeInfos) override; - void OnCapturerStateChange( - std::vector> &audioCapturerChangeInfos) override; - void OnRendererDeviceChange(const uint32_t sessionId, - const AudioDeviceDescriptor &deviceInfo, const AudioStreamDeviceChangeReasonExt reason) override; - void OnHeadTrackingDeviceChange(const std::unordered_map &changeInfo) override; - void OnSpatializationEnabledChange(const bool &enabled) override; - void OnSpatializationEnabledChangeForAnyDevice(const std::shared_ptr &deviceDescriptor, - const bool &enabled) override; - void OnSpatializationEnabledChangeForCurrentDevice(const bool &enabled) override; - void OnHeadTrackingEnabledChange(const bool &enabled) override; - void OnHeadTrackingEnabledChangeForAnyDevice(const std::shared_ptr &deviceDescriptor, - const bool &enabled) override; - void OnNnStateChange(const int32_t &nnState) override; - void OnAudioSessionDeactive(const AudioSessionDeactiveEvent &deactiveEvent) override; - void OnAudioSessionStateChanged(const AudioSessionStateChangedEvent &stateChangedEvent) override; - void OnAudioSceneChange(const AudioScene &audioScene) override; - void OnFormatUnsupportedError(const AudioErrors &errorCode) override; - void OnStreamVolumeChange(StreamVolumeEvent streamVolumeEvent) override; - void OnSystemVolumeChange(VolumeEvent volumeEvent) override; - + int32_t OnRendererStateChange( + const std::vector> &audioRendererChangeInfos) override; + int32_t OnCapturerStateChange( + const std::vector> &audioCapturerChangeInfos) override; + int32_t OnRendererDeviceChange(uint32_t sessionId, + const AudioDeviceDescriptor &deviceInfo, const AudioStreamDeviceChangeReasonExt &reason) override; + int32_t OnHeadTrackingDeviceChange(const std::unordered_map &changeInfo) override; + int32_t OnSpatializationEnabledChange(bool enabled) override; + int32_t OnSpatializationEnabledChangeForAnyDevice(const std::shared_ptr &deviceDescriptor, + bool enabled) override; + int32_t OnSpatializationEnabledChangeForCurrentDevice(bool enabled) override; + int32_t OnHeadTrackingEnabledChange(bool enabled) override; + int32_t OnHeadTrackingEnabledChangeForAnyDevice(const std::shared_ptr &deviceDescriptor, + bool enabled) override; + int32_t OnNnStateChange(int32_t nnState) override; + int32_t OnAudioSessionDeactive(int32_t deactiveEvent) override; + int32_t OnAudioSceneChange(int32_t audioScene) override; + int32_t OnAudioSessionStateChanged(int32_t stateChangeHint) override; + int32_t OnFormatUnsupportedError(int32_t errorCode) override; + int32_t OnStreamVolumeChange(const StreamVolumeEvent &streamVolumeEvent) override; + int32_t OnSystemVolumeChange(const VolumeEvent &volumeEvent) override; private: std::vector> DeviceFilterByFlag(DeviceFlag flag, const std::vector>& desc); diff --git a/services/audio_policy/client/stub/include/audio_policy_manager_listener_stub.h b/services/audio_policy/client/stub/include/audio_policy_manager_listener_stub_impl.h similarity index 60% rename from services/audio_policy/client/stub/include/audio_policy_manager_listener_stub.h rename to services/audio_policy/client/stub/include/audio_policy_manager_listener_stub_impl.h index 176700bfc6..b3c4ced8dd 100644 --- a/services/audio_policy/client/stub/include/audio_policy_manager_listener_stub.h +++ b/services/audio_policy/client/stub/include/audio_policy_manager_listener_stub_impl.h @@ -13,34 +13,32 @@ * limitations under the License. */ -#ifndef AUDIO_POLICY_MANAGER_LISTENER_STUB_H -#define AUDIO_POLICY_MANAGER_LISTENER_STUB_H +#ifndef AUDIO_POLICY_MANAGER_LISTENER_STUB_IMPL_H +#define AUDIO_POLICY_MANAGER_LISTENER_STUB_IMPL_H #include #include "audio_system_manager.h" #include "audio_interrupt_callback.h" -#include "i_standard_audio_policy_manager_listener.h" +#include "standard_audio_policy_manager_listener_stub.h" namespace OHOS { namespace AudioStandard { -class AudioPolicyManagerListenerStub : public IRemoteStub { +class AudioPolicyManagerListenerStubImpl : public StandardAudioPolicyManagerListenerStub { public: - AudioPolicyManagerListenerStub(); - virtual ~AudioPolicyManagerListenerStub(); + AudioPolicyManagerListenerStubImpl(); + virtual ~AudioPolicyManagerListenerStubImpl(); // IStandardAudioManagerListener override - int OnRemoteRequest(uint32_t code, MessageParcel &data, - MessageParcel &reply, MessageOption &option) override; - void OnInterrupt(const InterruptEventInternal &interruptEvent) override; - void OnAvailableDeviceChange(const AudioDeviceUsage usage, const DeviceChangeAction &deviceChangeAction) override; - bool OnQueryClientType(const std::string &bundleName, uint32_t uid) override; - bool OnCheckClientInfo(const std::string &bundleName, int32_t &uid, int32_t pid) override; - bool OnCheckVKBInfo(const std::string &bundleName) override; - bool OnQueryAllowedPlayback(int32_t uid, int32_t pid) override; - void OnBackgroundMute(const int32_t uid) override; - bool OnQueryBundleNameIsInList(const std::string &bundleName, const std::string &listType) override; - // AudioManagerListenerStub + int32_t OnInterrupt(const InterruptEventInternal &interruptEvent) override; + int32_t OnAvailableDeviceChange(uint32_t usage, const DeviceChangeAction &deviceChangeAction) override; + int32_t OnQueryClientType(const std::string &bundleName, uint32_t uid, bool &ret) override; + int32_t OnCheckClientInfo(const std::string &bundleName, int32_t &uid, int32_t pid, bool &ret) override; + int32_t OnCheckVKBInfo(const std::string &bundleName, bool &isValid) override; + int32_t OnQueryAllowedPlayback(int32_t uid, int32_t pid, bool &ret) override; + int32_t OnBackgroundMute(const int32_t uid) override; + int32_t OnQueryBundleNameIsInList(const std::string &bundleName, const std::string &listType, bool &ret) override; + // AudioManagerListenerStubImpl void SetInterruptCallback(const std::weak_ptr &callback); void SetAvailableDeviceChangeCallback(const std::weak_ptr &cb); void SetQueryClientTypeCallback(const std::weak_ptr &cb); @@ -50,9 +48,6 @@ public: void SetBackgroundMuteCallback(const std::weak_ptr &cb); void SetQueryBundleNameListCallback(const std::weak_ptr &cb); private: - void ReadInterruptEventParams(MessageParcel &data, InterruptEventInternal &interruptEvent); - void ReadAudioDeviceChangeData(MessageParcel &data, DeviceChangeAction &devChange); - int32_t OnMiddleFirRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); std::weak_ptr callback_; std::weak_ptr audioAvailableDeviceChangeCallback_; @@ -65,4 +60,4 @@ private: }; } // namespace AudioStandard } // namespace OHOS -#endif // AUDIO_POLICY_MANAGER_LISTENER_STUB_H +#endif // AUDIO_POLICY_MANAGER_LISTENER_STUB_IMPL_H diff --git a/services/audio_policy/client/stub/include/audio_zone_client.h b/services/audio_policy/client/stub/include/audio_zone_client.h index f450f24d7b..ff7518c291 100644 --- a/services/audio_policy/client/stub/include/audio_zone_client.h +++ b/services/audio_policy/client/stub/include/audio_zone_client.h @@ -16,30 +16,13 @@ #ifndef AUDIO_ZONE_CLIENT_H #define AUDIO_ZONE_CLIENT_H -#include "i_standard_audio_zone_client.h" +#include "standard_audio_zone_client_stub.h" #include "audio_zone_manager.h" namespace OHOS { namespace AudioStandard { -class AudioZoneClientStub : public IRemoteStub { -public: - AudioZoneClientStub(); - ~AudioZoneClientStub(); - - int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &option) override; - -private: - void HandleAudioZoneAdd(MessageParcel &data, MessageParcel &reply); - void HandleAudioZoneRemove(MessageParcel &data, MessageParcel &reply); - void HandleAudioZoneChange(MessageParcel &data, MessageParcel &reply); - void HandleAudioZoneInterrupt(MessageParcel &data, MessageParcel &reply); - void HandleAudioZoneDeviceInterrupt(MessageParcel &data, MessageParcel &reply); - void HandleAudioZoneSetSystemVolume(MessageParcel &data, MessageParcel &reply); - void HandleAudioZoneGetSystemVolume(MessageParcel &data, MessageParcel &reply); -}; -class AudioZoneClient : public AudioZoneClientStub { +class AudioZoneClient : public StandardAudioZoneClientStub { public: AudioZoneClient(); ~AudioZoneClient(); @@ -73,18 +56,19 @@ private: std::string GetInterruptKeyId(int32_t zoneId, const std::string &deviceTag); - void OnAudioZoneAdd(const AudioZoneDescriptor &zoneDescriptor) override; - void OnAudioZoneRemove(int32_t zoneId) override; - void OnAudioZoneChange(int32_t zoneId, const AudioZoneDescriptor &zoneDescriptor, - AudioZoneChangeReason reason) override; - void OnInterruptEvent(int32_t zoneId, const std::list> &interrupts, - AudioZoneInterruptReason reason) override; - void OnInterruptEvent(int32_t zoneId, const std::string &deviceTag, - const std::list> &interrupts, - AudioZoneInterruptReason reason) override; - int32_t SetSystemVolume(const int32_t zoneId, const AudioVolumeType volumeType, + int32_t OnAudioZoneAdd(const AudioZoneDescriptor &zoneDescriptor) override; + int32_t OnAudioZoneRemove(int32_t zoneId) override; + int32_t OnAudioZoneChange(int32_t zoneId, const AudioZoneDescriptor &zoneDescriptor, + int32_t reason) override; + int32_t OnInterruptEvent(int32_t zoneId, + const std::vector> &ipcInterrupts, + int32_t reason) override; + int32_t OnInterruptEvent(int32_t zoneId, const std::string &deviceTag, + const std::vector> &ipcInterrupts, + int32_t reason) override; + int32_t SetSystemVolume(const int32_t zoneId, const int32_t volumeType, const int32_t volumeLevel, const int32_t volumeFlag) override; - int32_t GetSystemVolume(int32_t zoneId, AudioVolumeType volumeType) override; + int32_t GetSystemVolume(int32_t zoneId, int32_t volumeType, float &outVolume) override; }; } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_policy/client/stub/include/sle_audio_operation_callback_stub.h b/services/audio_policy/client/stub/include/sle_audio_operation_callback_stub.h deleted file mode 100644 index f3afffeae1..0000000000 --- a/services/audio_policy/client/stub/include/sle_audio_operation_callback_stub.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef SLE_AUDIO_OPERATION_CALLBACK_STUB_H -#define SLE_AUDIO_OPERATION_CALLBACK_STUB_H - -#include "audio_policy_interface.h" -#include "i_standard_sle_audio_operation_callback.h" - -namespace OHOS { -namespace AudioStandard { -class SleAudioOperationCallbackStub : public IRemoteStub { -public: - SleAudioOperationCallbackStub(); - virtual ~SleAudioOperationCallbackStub(); - - int32_t SetSleAudioOperationCallback(const std::weak_ptr &callback); - - int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - void GetSleAudioDeviceList(std::vector &devices) override; - void GetSleVirtualAudioDeviceList(std::vector &devices) override; - bool IsInBandRingOpen(const std::string &device) override; - uint32_t GetSupportStreamType(const std::string &device) override; - int32_t SetActiveSinkDevice(const std::string &device, uint32_t streamType) override; - int32_t StartPlaying(const std::string &device, uint32_t streamType) override; - int32_t StopPlaying(const std::string &device, uint32_t streamType) override; - int32_t ConnectAllowedProfiles(const std::string &remoteAddr) override; - int32_t SetDeviceAbsVolume(const std::string &remoteAddr, uint32_t volume, uint32_t streamType) override; - int32_t SendUserSelection(const std::string &device, uint32_t streamType) override; - int32_t GetRenderPosition(const std::string &device, uint32_t &delayValue) override; - -private: - int OnRemoteRequestSecondPartCode(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); - - void GetSleAudioDeviceListInternal(MessageParcel &data, MessageParcel &reply); - void GetSleVirtualAudioDeviceListInternal(MessageParcel &data, MessageParcel &reply); - void IsInBandRingOpenInternal(MessageParcel &data, MessageParcel &reply); - void GetSupportStreamTypeInternal(MessageParcel &data, MessageParcel &reply); - void SetActiveSinkDeviceInternal(MessageParcel &data, MessageParcel &reply); - void StartPlayingInternal(MessageParcel &data, MessageParcel &reply); - void StopPlayingInternal(MessageParcel &data, MessageParcel &reply); - void ConnectAllowedProfilesInternal(MessageParcel &data, MessageParcel &reply); - void SetDeviceAbsVolumeInternal(MessageParcel &data, MessageParcel &reply); - void SendUserSelectionInternal(MessageParcel &data, MessageParcel &reply); - void GetRenderPositionInternal(MessageParcel &data, MessageParcel &reply); - - std::mutex sleAudioOperationCallbackMutex_; - std::weak_ptr sleAudioOperationCallback_; -}; -} // namespace AudioStandard -} // namespace OHOS -#endif // SLE_AUDIO_OPERATION_CALLBACK_STUB_H diff --git a/services/audio_policy/server/proxy/include/sle_audio_operation_callback_proxy.h b/services/audio_policy/client/stub/include/sle_audio_operation_callback_stub_impl.h similarity index 49% rename from services/audio_policy/server/proxy/include/sle_audio_operation_callback_proxy.h rename to services/audio_policy/client/stub/include/sle_audio_operation_callback_stub_impl.h index 6a27cbd19f..28c188a78d 100644 --- a/services/audio_policy/server/proxy/include/sle_audio_operation_callback_proxy.h +++ b/services/audio_policy/client/stub/include/sle_audio_operation_callback_stub_impl.h @@ -13,34 +13,37 @@ * limitations under the License. */ -#ifndef SLE_AUDIO_OPERATION_CALLBACK_PROXY_H -#define SLE_AUDIO_OPERATION_CALLBACK_PROXY_H +#ifndef SLE_AUDIO_OPERATION_CALLBACK_STUB_H +#define SLE_AUDIO_OPERATION_CALLBACK_STUB_H -#include "audio_general_manager.h" -#include "i_standard_sle_audio_operation_callback.h" +#include "audio_policy_interface.h" +#include "standard_sle_audio_operation_callback_stub.h" namespace OHOS { namespace AudioStandard { -class SleAudioOperationCallbackProxy : public IRemoteProxy { +class SleAudioOperationCallbackStubImpl : public StandardSleAudioOperationCallbackStub { public: - explicit SleAudioOperationCallbackProxy(const sptr &impl); - virtual ~SleAudioOperationCallbackProxy(); - DISALLOW_COPY_AND_MOVE(SleAudioOperationCallbackProxy); + SleAudioOperationCallbackStubImpl(); + virtual ~SleAudioOperationCallbackStubImpl(); - void GetSleAudioDeviceList(std::vector &devices) override; - void GetSleVirtualAudioDeviceList(std::vector &devices) override; - bool IsInBandRingOpen(const std::string &device) override; - uint32_t GetSupportStreamType(const std::string &device) override; - int32_t SetActiveSinkDevice(const std::string &device, uint32_t streamType) override; - int32_t StartPlaying(const std::string &device, uint32_t streamType) override; - int32_t StopPlaying(const std::string &device, uint32_t streamType) override; - int32_t ConnectAllowedProfiles(const std::string &remoteAddr) override; - int32_t SetDeviceAbsVolume(const std::string &remoteAddr, uint32_t volume, uint32_t streamType) override; - int32_t SendUserSelection(const std::string &device, uint32_t streamType) override; + int32_t SetSleAudioOperationCallback(const std::weak_ptr &callback); + + int32_t GetSleAudioDeviceList(std::vector &devices) override; + int32_t GetSleVirtualAudioDeviceList(std::vector &devices) override; + int32_t IsInBandRingOpen(const std::string &device, bool& ret) override; + int32_t GetSupportStreamType(const std::string &device, uint32_t& retType) override; + int32_t SetActiveSinkDevice(const std::string &device, uint32_t streamType, int32_t& ret) override; + int32_t StartPlaying(const std::string &device, uint32_t streamType, int32_t& ret) override; + int32_t StopPlaying(const std::string &device, uint32_t streamType, int32_t& ret) override; + int32_t ConnectAllowedProfiles(const std::string &remoteAddr, int32_t& ret) override; + int32_t SetDeviceAbsVolume(const std::string &remoteAddr, uint32_t volume, uint32_t streamType, + int32_t& ret) override; + int32_t SendUserSelection(const std::string &device, uint32_t streamType, int32_t& ret) override; int32_t GetRenderPosition(const std::string &device, uint32_t &delayValue) override; private: - static inline BrokerDelegator delegator_; + std::mutex sleAudioOperationCallbackMutex_; + std::weak_ptr sleAudioOperationCallback_; }; } // namespace AudioStandard } // namespace OHOS -#endif // SLE_AUDIO_OPERATION_CALLBACK_PROXY_H +#endif // SLE_AUDIO_OPERATION_CALLBACK_STUB_H diff --git a/services/audio_policy/client/stub/src/audio_policy_client_stub.cpp b/services/audio_policy/client/stub/src/audio_policy_client_stub.cpp deleted file mode 100644 index e4473aabe7..0000000000 --- a/services/audio_policy/client/stub/src/audio_policy_client_stub.cpp +++ /dev/null @@ -1,467 +0,0 @@ -/* - * Copyright (c) 2023-2023 Huawei Device Co., Ltd. - * 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. - */ -#ifndef LOG_TAG -#define LOG_TAG "AudioPolicyClientStub" -#endif - -#include "audio_policy_client_stub.h" -#include "audio_errors.h" -#include "audio_policy_log.h" -#include "audio_utils.h" - -using namespace std; -namespace OHOS { -namespace AudioStandard { - -static const int32_t FOCUS_INFO_VALID_SIZE = 128; -static const int32_t DEVICE_CHANGE_VALID_SIZE = 128; -static const int32_t PREFERRED_DEVICE_VALID_SIZE = 128; -static const int32_t STATE_VALID_SIZE = 1024; -static const int32_t MIC_BLOCKED_VALID_SIZE = 128; - -AudioPolicyClientStub::AudioPolicyClientStub() -{} - -AudioPolicyClientStub::~AudioPolicyClientStub() -{} - -void AudioPolicyClientStub::OnFirMaxRemoteRequest(uint32_t updateCode, MessageParcel &data, MessageParcel &reply) -{ - switch (updateCode) { - case static_cast(AudioPolicyClientCode::ON_HEAD_TRACKING_DEVICE_CHANGE): - HandleHeadTrackingDeviceChange(data, reply); - break; - case static_cast(AudioPolicyClientCode::ON_SPATIALIZATION_ENABLED_CHANGE): - HandleSpatializationEnabledChange(data, reply); - break; - case static_cast(AudioPolicyClientCode::ON_SPATIALIZATION_ENABLED_CHANGE_FOR_ANY_DEVICE): - HandleSpatializationEnabledChangeForAnyDevice(data, reply); - break; - case static_cast(AudioPolicyClientCode::ON_SPATIALIZATION_ENABLED_CHANGE_FOR_CURRENT_DEVICE): - HandleSpatializationEnabledChangeForCurrentDevice(data, reply); - break; - case static_cast(AudioPolicyClientCode::ON_HEAD_TRACKING_ENABLED_CHANGE): - HandleHeadTrackingEnabledChange(data, reply); - break; - case static_cast(AudioPolicyClientCode::ON_HEAD_TRACKING_ENABLED_CHANGE_FOR_ANY_DEVICE): - HandleHeadTrackingEnabledChangeForAnyDevice(data, reply); - break; - case static_cast(AudioPolicyClientCode::ON_NN_STATE_CHANGE): - HandleNnStateChange(data, reply); - break; - case static_cast(AudioPolicyClientCode::ON_AUDIO_SESSION_DEACTIVE): - HandleAudioSessionCallback(data, reply); - break; - case static_cast(AudioPolicyClientCode::ON_AUDIO_SCENE_CHANGED): - HandleAudioSceneChange(data, reply); - break; - case static_cast(AudioPolicyClientCode::ON_FORMAT_UNSUPPORTED_ERROR): - HandleFormatUnsupportedError(data, reply); - break; - case static_cast(AudioPolicyClientCode::ON_STREAM_VOLUME_CHANGE): - HandleStreamVolumeChange(data, reply); - break; - case static_cast(AudioPolicyClientCode::ON_SYSTEM_VOLUME_CHANGE): - HandleSystemVolumeChange(data, reply); - break; - case static_cast(AudioPolicyClientCode::ON_AUDIO_SESSION_STATE_CHANGED): - HandleAudioSessionStateCallback(data, reply); - break; - default: - break; - } -} - -void AudioPolicyClientStub::OnMaxRemoteRequest(uint32_t updateCode, MessageParcel &data, MessageParcel &reply) -{ - switch (updateCode) { - case static_cast(AudioPolicyClientCode::ON_RINGERMODE_UPDATE): - HandleRingerModeUpdated(data, reply); - break; - case static_cast(AudioPolicyClientCode::ON_MIC_STATE_UPDATED): - HandleMicStateChange(data, reply); - break; - case static_cast(AudioPolicyClientCode::ON_ACTIVE_OUTPUT_DEVICE_UPDATED): - HandlePreferredOutputDeviceUpdated(data, reply); - break; - case static_cast(AudioPolicyClientCode::ON_ACTIVE_INPUT_DEVICE_UPDATED): - HandlePreferredInputDeviceUpdated(data, reply); - break; - case static_cast(AudioPolicyClientCode::ON_RENDERERSTATE_CHANGE): - HandleRendererStateChange(data, reply); - break; - case static_cast(AudioPolicyClientCode::ON_CAPTURERSTATE_CHANGE): - HandleCapturerStateChange(data, reply); - break; - case static_cast(AudioPolicyClientCode::ON_RENDERER_DEVICE_CHANGE): - HandleRendererDeviceChange(data, reply); - break; - case static_cast(AudioPolicyClientCode::ON_RECREATE_RENDERER_STREAM_EVENT): - HandleRecreateRendererStreamEvent(data, reply); - break; - case static_cast(AudioPolicyClientCode::ON_RECREATE_CAPTURER_STREAM_EVENT): - HandleRecreateCapturerStreamEvent(data, reply); - break; - default: - OnFirMaxRemoteRequest(updateCode, data, reply); - break; - } -} - -int AudioPolicyClientStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &option) -{ - if (data.ReadInterfaceToken() != GetDescriptor()) { - AUDIO_ERR_LOG("AudioPolicyClientStub: ReadInterfaceToken failed"); - return -1; - } - switch (code) { - case UPDATE_CALLBACK_CLIENT: { - uint32_t updateCode = static_cast(data.ReadInt32()); - if (updateCode > static_cast(AudioPolicyClientCode::AUDIO_POLICY_CLIENT_CODE_MAX)) { - return -1; - } - switch (updateCode) { - case static_cast(AudioPolicyClientCode::ON_VOLUME_KEY_EVENT): - HandleVolumeKeyEvent(data, reply); - break; - case static_cast(AudioPolicyClientCode::ON_FOCUS_INFO_CHANGED): - HandleAudioFocusInfoChange(data, reply); - break; - case static_cast(AudioPolicyClientCode::ON_FOCUS_REQUEST_CHANGED): - HandleAudioFocusRequested(data, reply); - break; - case static_cast(AudioPolicyClientCode::ON_FOCUS_ABANDON_CHANGED): - HandleAudioFocusAbandoned(data, reply); - break; - case static_cast(AudioPolicyClientCode::ON_DEVICE_CHANGE): - HandleDeviceChange(data, reply); - break; - case static_cast(AudioPolicyClientCode::ON_MICRO_PHONE_BLOCKED): - HandleMicrophoneBlocked(data, reply); - break; - case static_cast(AudioPolicyClientCode::ON_APP_VOLUME_CHANGE): - HandleAppVolumeChange(data, reply); - break; - case static_cast(AudioPolicyClientCode::ON_ACTIVE_VOLUME_TYPE_CHANGE): - HandleActiveVolumeTypeChange(data, reply); - break; - default: - OnMaxRemoteRequest(updateCode, data, reply); - break; - } - break; - } - default: { - reply.WriteInt32(ERR_INVALID_OPERATION); - break; - } - } - return SUCCESS; -} - -void AudioPolicyClientStub::HandleActiveVolumeTypeChange(MessageParcel &data, MessageParcel &reply) -{ - AUDIO_INFO_LOG("Handle Active VolumeType Change"); - AudioVolumeType volumeType = static_cast(data.ReadInt32()); - OnActiveVolumeTypeChanged(volumeType); -} - -void AudioPolicyClientStub::HandleAppVolumeChange(MessageParcel &data, MessageParcel &reply) -{ - AUDIO_INFO_LOG("Handle AppVolume Change"); - int32_t appUid = data.ReadInt32(); - VolumeEvent volumeEvent; - volumeEvent.Unmarshalling(data); - OnAppVolumeChanged(appUid, volumeEvent); -} - -void AudioPolicyClientStub::HandleVolumeKeyEvent(MessageParcel &data, MessageParcel &reply) -{ - VolumeEvent event; - event.volumeType = static_cast(data.ReadInt32()); - event.volume = data.ReadInt32(); - event.updateUi = data.ReadBool(); - event.volumeGroupId = data.ReadInt32(); - event.networkId = data.ReadString(); - OnVolumeKeyEvent(event); -} - -void AudioPolicyClientStub::HandleAudioFocusInfoChange(MessageParcel &data, MessageParcel &reply) -{ - std::list> infoList; - std::pair focusInfo = {}; - int32_t size = data.ReadInt32(); - CHECK_AND_RETURN_LOG(size < FOCUS_INFO_VALID_SIZE, "get invalid size : %{public}d", size); - - for (int32_t i = 0; i < size; i++) { - AudioInterrupt::Unmarshalling(data, focusInfo.first); - focusInfo.second = static_cast(data.ReadInt32()); - infoList.emplace_back(focusInfo); - } - OnAudioFocusInfoChange(infoList); -} - -void AudioPolicyClientStub::HandleAudioFocusRequested(MessageParcel &data, MessageParcel &reply) -{ - AudioInterrupt requestFocus = {}; - AudioInterrupt::Unmarshalling(data, requestFocus); - OnAudioFocusRequested(requestFocus); -} - -void AudioPolicyClientStub::HandleAudioFocusAbandoned(MessageParcel &data, MessageParcel &reply) -{ - AudioInterrupt abandonFocus = {}; - AudioInterrupt::Unmarshalling(data, abandonFocus); - OnAudioFocusAbandoned(abandonFocus); -} - -void AudioPolicyClientStub::HandleDeviceChange(MessageParcel &data, MessageParcel &reply) -{ - DeviceChangeAction deviceChange; - deviceChange.type = static_cast(data.ReadUint32()); - deviceChange.flag = static_cast(data.ReadUint32()); - int32_t size = data.ReadInt32(); - CHECK_AND_RETURN_LOG(size < DEVICE_CHANGE_VALID_SIZE, "get invalid size : %{public}d", size); - - for (int32_t i = 0; i < size; i++) { - deviceChange.deviceDescriptors.emplace_back(AudioDeviceDescriptor::UnmarshallingPtr(data)); - } - OnDeviceChange(deviceChange); -} - -void AudioPolicyClientStub::HandleMicrophoneBlocked(MessageParcel &data, MessageParcel &reply) -{ - MicrophoneBlockedInfo microphoneBlocked; - microphoneBlocked.blockStatus = static_cast(data.ReadUint32()); - int32_t size = data.ReadInt32(); - CHECK_AND_RETURN_LOG(size < MIC_BLOCKED_VALID_SIZE, "get invalid size : %{public}d", size); - - for (int32_t i = 0; i < size; i++) { - microphoneBlocked.devices.emplace_back(AudioDeviceDescriptor::UnmarshallingPtr(data)); - } - OnMicrophoneBlocked(microphoneBlocked); -} - -void AudioPolicyClientStub::HandleRingerModeUpdated(MessageParcel &data, MessageParcel &reply) -{ - AudioRingerMode ringMode = static_cast(data.ReadInt32()); - OnRingerModeUpdated(ringMode); -} - -void AudioPolicyClientStub::HandleMicStateChange(MessageParcel &data, MessageParcel &reply) -{ - MicStateChangeEvent micState; - micState.mute = data.ReadBool(); - OnMicStateUpdated(micState); -} - -void AudioPolicyClientStub::HandlePreferredOutputDeviceUpdated(MessageParcel &data, MessageParcel &reply) -{ - AudioRendererInfo rendererInfo; - rendererInfo.Unmarshalling(data); - std::vector> deviceDescriptor; - int32_t size = data.ReadInt32(); - CHECK_AND_RETURN_LOG(size < PREFERRED_DEVICE_VALID_SIZE, "get invalid size : %{public}d", size); - - for (int32_t i = 0; i < size; i++) { - deviceDescriptor.push_back(AudioDeviceDescriptor::UnmarshallingPtr(data)); - } - OnPreferredOutputDeviceUpdated(rendererInfo, deviceDescriptor); -} - -void AudioPolicyClientStub::HandlePreferredInputDeviceUpdated(MessageParcel &data, MessageParcel &reply) -{ - AudioCapturerInfo capturerInfo; - capturerInfo.Unmarshalling(data); - std::vector> deviceDescriptor; - int32_t size = data.ReadInt32(); - CHECK_AND_RETURN_LOG(size < PREFERRED_DEVICE_VALID_SIZE, "get invalid size : %{public}d", size); - - for (int32_t i = 0; i < size; i++) { - deviceDescriptor.push_back(AudioDeviceDescriptor::UnmarshallingPtr(data)); - } - OnPreferredInputDeviceUpdated(capturerInfo, deviceDescriptor); -} - -void AudioPolicyClientStub::HandleRendererStateChange(MessageParcel &data, MessageParcel &reply) -{ - std::vector> audioRenderChangeInfo; - int32_t size = data.ReadInt32(); - Trace trace("HandleRendererStateChange size:" + std::to_string(size)); - CHECK_AND_RETURN_LOG(size < STATE_VALID_SIZE, "get invalid size : %{public}d", size); - - while (size > 0) { - std::shared_ptr rendererChangeInfo = std::make_shared(); - if (rendererChangeInfo == nullptr) { - AUDIO_ERR_LOG("AudioPolicyClientStub::HandleRendererStateChange, No memory!"); - return; - } - rendererChangeInfo->Unmarshalling(data); - audioRenderChangeInfo.push_back(move(rendererChangeInfo)); - size--; - } - OnRendererStateChange(audioRenderChangeInfo); -} - -void AudioPolicyClientStub::HandleCapturerStateChange(MessageParcel &data, MessageParcel &reply) -{ - std::vector> audioCapturerChangeInfo; - int32_t size = data.ReadInt32(); - CHECK_AND_RETURN_LOG(size < STATE_VALID_SIZE, "get invalid size : %{public}d", size); - - while (size > 0) { - std::shared_ptr capturerChangeInfo = std::make_shared(); - if (capturerChangeInfo == nullptr) { - AUDIO_ERR_LOG("AudioPolicyClientStub::HandleCapturerStateChange, No memory!"); - return; - } - capturerChangeInfo->Unmarshalling(data); - audioCapturerChangeInfo.push_back(move(capturerChangeInfo)); - size--; - } - OnCapturerStateChange(audioCapturerChangeInfo); -} - -void AudioPolicyClientStub::HandleRendererDeviceChange(MessageParcel &data, MessageParcel &reply) -{ - const uint32_t sessionId = data.ReadUint32(); - AudioDeviceDescriptor deviceInfo(AudioDeviceDescriptor::DEVICE_INFO); - deviceInfo.Unmarshalling(data); - const AudioStreamDeviceChangeReasonExt reason - = static_cast (data.ReadInt32()); - - OnRendererDeviceChange(sessionId, deviceInfo, reason); -} - -void AudioPolicyClientStub::HandleRecreateRendererStreamEvent(MessageParcel &data, MessageParcel &reply) -{ - const uint32_t sessionId = data.ReadUint32(); - const uint32_t streamFlag = data.ReadUint32(); - const AudioStreamDeviceChangeReasonExt reason - = static_cast (data.ReadInt32()); - OnRecreateRendererStreamEvent(sessionId, streamFlag, reason); -} - -void AudioPolicyClientStub::HandleRecreateCapturerStreamEvent(MessageParcel &data, MessageParcel &reply) -{ - const uint32_t sessionId = data.ReadUint32(); - const uint32_t streamFlag = data.ReadUint32(); - const AudioStreamDeviceChangeReasonExt reason - = static_cast (data.ReadInt32()); - OnRecreateCapturerStreamEvent(sessionId, streamFlag, reason); -} - -void AudioPolicyClientStub::HandleHeadTrackingDeviceChange(MessageParcel &data, MessageParcel &reply) -{ - std::unordered_map changeInfo; - int32_t size = data.ReadInt32(); - CHECK_AND_RETURN_LOG(size < DEVICE_CHANGE_VALID_SIZE, "get invalid size : %{public}d", size); - - while (size > 0) { - std::string macAddress = data.ReadString(); - bool isHeadTrackingDataRequested = data.ReadBool(); - changeInfo[macAddress] = isHeadTrackingDataRequested; - size--; - } - OnHeadTrackingDeviceChange(changeInfo); -} - -void AudioPolicyClientStub::HandleSpatializationEnabledChange(MessageParcel &data, MessageParcel &reply) -{ - bool enabled = data.ReadBool(); - OnSpatializationEnabledChange(enabled); -} - -void AudioPolicyClientStub::HandleAudioSceneChange(MessageParcel &data, MessageParcel &reply) -{ - AudioScene audioScene = static_cast(data.ReadInt32()); - CHECK_AND_RETURN_LOG(audioScene < AUDIO_SCENE_MAX && audioScene > AUDIO_SCENE_INVALID, \ - "get invalid audioScene : %{public}d", audioScene); - - OnAudioSceneChange(audioScene); -} - -void AudioPolicyClientStub::HandleSpatializationEnabledChangeForAnyDevice(MessageParcel &data, MessageParcel &reply) -{ - std::shared_ptr audioDeviceDescriptor = AudioDeviceDescriptor::UnmarshallingPtr(data); - CHECK_AND_RETURN_LOG(audioDeviceDescriptor != nullptr, "Unmarshalling fail."); - bool enabled = data.ReadBool(); - OnSpatializationEnabledChangeForAnyDevice(audioDeviceDescriptor, enabled); -} - -void AudioPolicyClientStub::HandleSpatializationEnabledChangeForCurrentDevice(MessageParcel &data, MessageParcel &reply) -{ - bool enabled = data.ReadBool(); - OnSpatializationEnabledChangeForCurrentDevice(enabled); -} - -void AudioPolicyClientStub::HandleHeadTrackingEnabledChange(MessageParcel &data, MessageParcel &reply) -{ - bool enabled = data.ReadBool(); - OnHeadTrackingEnabledChange(enabled); -} - -void AudioPolicyClientStub::HandleHeadTrackingEnabledChangeForAnyDevice(MessageParcel &data, MessageParcel &reply) -{ - std::shared_ptr audioDeviceDescriptor = AudioDeviceDescriptor::UnmarshallingPtr(data); - CHECK_AND_RETURN_LOG(audioDeviceDescriptor != nullptr, "Unmarshalling fail."); - bool enabled = data.ReadBool(); - OnHeadTrackingEnabledChangeForAnyDevice(audioDeviceDescriptor, enabled); -} - -void AudioPolicyClientStub::HandleNnStateChange(MessageParcel &data, MessageParcel &reply) -{ - int32_t state = data.ReadInt32(); - OnNnStateChange(state); -} - -void AudioPolicyClientStub::HandleAudioSessionCallback(MessageParcel &data, MessageParcel &reply) -{ - AUDIO_INFO_LOG("HandleAudioSessionCallback"); - AudioSessionDeactiveEvent deactiveEvent; - deactiveEvent.deactiveReason = static_cast(data.ReadInt32()); - OnAudioSessionDeactive(deactiveEvent); -} - -void AudioPolicyClientStub::HandleAudioSessionStateCallback(MessageParcel &data, MessageParcel &reply) -{ - AUDIO_INFO_LOG("HandleAudioSessionStateCallback"); - AudioSessionStateChangedEvent stateChangedEvent; - stateChangedEvent.stateChangeHint = static_cast(data.ReadInt32()); - OnAudioSessionStateChanged(stateChangedEvent); -} - -void AudioPolicyClientStub::HandleFormatUnsupportedError(MessageParcel &data, MessageParcel &reply) -{ - AudioErrors code = static_cast(data.ReadInt32()); - OnFormatUnsupportedError(code); -} - -void AudioPolicyClientStub::HandleStreamVolumeChange(MessageParcel &data, MessageParcel &reply) -{ - StreamVolumeEvent streamVolumeEvent; - streamVolumeEvent.Unmarshalling(data); - OnStreamVolumeChange(streamVolumeEvent); -} - -void AudioPolicyClientStub::HandleSystemVolumeChange(MessageParcel &data, MessageParcel &reply) -{ - VolumeEvent volumeEvent; - volumeEvent.Unmarshalling(data); - OnSystemVolumeChange(volumeEvent); -} -} // namespace AudioStandard -} // namespace OHOS diff --git a/services/audio_policy/client/stub/src/audio_policy_client_stub_impl.cpp b/services/audio_policy/client/stub/src/audio_policy_client_stub_impl.cpp index ffac7c1856..aa1867bf8e 100644 --- a/services/audio_policy/client/stub/src/audio_policy_client_stub_impl.cpp +++ b/services/audio_policy/client/stub/src/audio_policy_client_stub_impl.cpp @@ -16,6 +16,8 @@ #define LOG_TAG "AudioPolicyClientStubImpl" #endif +#include + #include "audio_policy_client_stub_impl.h" #include "audio_errors.h" #include "audio_policy_log.h" @@ -24,6 +26,12 @@ namespace OHOS { namespace AudioStandard { constexpr int32_t RSS_UID = 1096; +static const int32_t FOCUS_INFO_VALID_SIZE = 128; +static const int32_t DEVICE_CHANGE_VALID_SIZE = 128; +static const int32_t PREFERRED_DEVICE_VALID_SIZE = 128; +static const int32_t STATE_VALID_SIZE = 1024; +static const int32_t MIC_BLOCKED_VALID_SIZE = 128; + int32_t AudioPolicyClientStubImpl::AddVolumeKeyEventCallback(const std::shared_ptr &cb) { std::lock_guard lockCbMap(volumeKeyEventMutex_); @@ -54,7 +62,7 @@ size_t AudioPolicyClientStubImpl::GetVolumeKeyEventCallbackSize() const return volumeKeyEventCallbackList_.size(); } -void AudioPolicyClientStubImpl::OnVolumeKeyEvent(VolumeEvent volumeEvent) +int32_t AudioPolicyClientStubImpl::OnVolumeKeyEvent(const VolumeEvent &volumeEvent) { std::lock_guard lockCbMap(volumeKeyEventMutex_); for (auto it = volumeKeyEventCallbackList_.begin(); it != volumeKeyEventCallbackList_.end(); ++it) { @@ -63,6 +71,7 @@ void AudioPolicyClientStubImpl::OnVolumeKeyEvent(VolumeEvent volumeEvent) volumeKeyEventCallback->OnVolumeKeyEvent(volumeEvent); } } + return SUCCESS; } int32_t AudioPolicyClientStubImpl::AddSystemVolumeChangeCallback(const std::shared_ptr &cb) @@ -96,7 +105,7 @@ size_t AudioPolicyClientStubImpl::GetSystemVolumeChangeCallbackSize() const return systemVolumeChangeCallbackList_.size(); } -void AudioPolicyClientStubImpl::OnSystemVolumeChange(VolumeEvent volumeEvent) +int32_t AudioPolicyClientStubImpl::OnSystemVolumeChange(const VolumeEvent &volumeEvent) { std::lock_guard lockCbMap(systemVolumeChangeMutex_); for (auto it = systemVolumeChangeCallbackList_.begin(); it != systemVolumeChangeCallbackList_.end(); ++it) { @@ -105,6 +114,7 @@ void AudioPolicyClientStubImpl::OnSystemVolumeChange(VolumeEvent volumeEvent) systemVolumeChangeCallback->OnSystemVolumeChange(volumeEvent); } } + return SUCCESS; } int32_t AudioPolicyClientStubImpl::AddFocusInfoChangeCallback(const std::shared_ptr &cb) @@ -121,29 +131,42 @@ int32_t AudioPolicyClientStubImpl::RemoveFocusInfoChangeCallback() return SUCCESS; } -void AudioPolicyClientStubImpl::OnAudioFocusInfoChange( - const std::list> &focusInfoList) +int32_t AudioPolicyClientStubImpl::OnAudioFocusInfoChange( + const std::vector> &focusInfoList) { + int32_t size = static_cast(focusInfoList.size()); + CHECK_AND_RETURN_RET_LOG(size < FOCUS_INFO_VALID_SIZE, ERR_INVALID_PARAM, "get invalid size : %{public}d", size); std::lock_guard lockCbMap(focusInfoChangeMutex_); + + std::list> newFocusInfoList; + for (const auto& map : focusInfoList) { + for (const auto& [key, value] : map) { + newFocusInfoList.emplace_back(key, static_cast(value)); + } + } + for (auto it = focusInfoChangeCallbackList_.begin(); it != focusInfoChangeCallbackList_.end(); ++it) { - (*it)->OnAudioFocusInfoChange(focusInfoList); + (*it)->OnAudioFocusInfoChange(newFocusInfoList); } + return SUCCESS; } -void AudioPolicyClientStubImpl::OnAudioFocusRequested(const AudioInterrupt &requestFocus) +int32_t AudioPolicyClientStubImpl::OnAudioFocusRequested(const AudioInterrupt &requestFocus) { std::lock_guard lockCbMap(focusInfoChangeMutex_); for (auto it = focusInfoChangeCallbackList_.begin(); it != focusInfoChangeCallbackList_.end(); ++it) { (*it)->OnAudioFocusRequested(requestFocus); } + return SUCCESS; } -void AudioPolicyClientStubImpl::OnAudioFocusAbandoned(const AudioInterrupt &abandonFocus) +int32_t AudioPolicyClientStubImpl::OnAudioFocusAbandoned(const AudioInterrupt &abandonFocus) { std::lock_guard lockCbMap(focusInfoChangeMutex_); for (auto it = focusInfoChangeCallbackList_.begin(); it != focusInfoChangeCallbackList_.end(); ++it) { (*it)->OnAudioFocusAbandoned(abandonFocus); } + return SUCCESS; } size_t AudioPolicyClientStubImpl::GetFocusInfoChangeCallbackSize() const @@ -229,8 +252,11 @@ size_t AudioPolicyClientStubImpl::GetDeviceChangeCallbackSize() const return deviceChangeCallbackList_.size(); } -void AudioPolicyClientStubImpl::OnDeviceChange(const DeviceChangeAction &dca) +int32_t AudioPolicyClientStubImpl::OnDeviceChange(const DeviceChangeAction &dca) { + int32_t size = static_cast(dca.deviceDescriptors.size()); + CHECK_AND_RETURN_RET_LOG(size < DEVICE_CHANGE_VALID_SIZE, ERR_INVALID_PARAM, + "get invalid size : %{public}d", size); std::lock_guard lockCbMap(deviceChangeMutex_); DeviceChangeAction deviceChangeAction; deviceChangeAction.type = dca.type; @@ -241,19 +267,24 @@ void AudioPolicyClientStubImpl::OnDeviceChange(const DeviceChangeAction &dca) it->second->OnDeviceChange(deviceChangeAction); } } + return SUCCESS; } -void AudioPolicyClientStubImpl::OnMicrophoneBlocked(const MicrophoneBlockedInfo &blockedInfo) +int32_t AudioPolicyClientStubImpl::OnMicrophoneBlocked(const MicrophoneBlockedInfo &blockedInfo) { + int32_t size = static_cast(blockedInfo.devices.size()); + CHECK_AND_RETURN_RET_LOG(size < MIC_BLOCKED_VALID_SIZE, ERR_INVALID_PARAM, + "get invalid size : %{public}d", size); std::lock_guard lockCbMap(microphoneBlockedMutex_); MicrophoneBlockedInfo microphoneBlockedInfo; microphoneBlockedInfo.blockStatus = blockedInfo.blockStatus; for (auto it = microphoneBlockedCallbackList_.begin(); it != microphoneBlockedCallbackList_.end(); ++it) { - microphoneBlockedInfo.devices= blockedInfo.devices; + microphoneBlockedInfo.devices = blockedInfo.devices; if (it->second && microphoneBlockedInfo.devices.size() > 0) { it->second->OnMicrophoneBlocked(microphoneBlockedInfo); } } + return SUCCESS; } int32_t AudioPolicyClientStubImpl::AddMicrophoneBlockedCallback(const int32_t clientId, @@ -317,12 +348,17 @@ size_t AudioPolicyClientStubImpl::GetAudioSceneChangedCallbackSize() const return audioSceneChangedCallbackList_.size(); } -void AudioPolicyClientStubImpl::OnAudioSceneChange(const AudioScene &audioScene) +int32_t AudioPolicyClientStubImpl::OnAudioSceneChange(int32_t audioScene) { + CHECK_AND_RETURN_RET_LOG(audioScene < AUDIO_SCENE_MAX && audioScene > AUDIO_SCENE_INVALID, + ERR_INVALID_PARAM, "get invalid audioScene : %{public}d", audioScene); + std::lock_guard lockCbMap(audioSceneChangedMutex_); for (const auto &callback : audioSceneChangedCallbackList_) { - callback->OnAudioSceneChange(audioScene); + CHECK_AND_CONTINUE(callback != nullptr); + callback->OnAudioSceneChange(static_cast(audioScene)); } + return SUCCESS; } int32_t AudioPolicyClientStubImpl::RemoveAllActiveVolumeTypeChangeCallback() @@ -507,25 +543,27 @@ size_t AudioPolicyClientStubImpl::GetSelfAppVolumeChangeCallbackSize() const return selfAppVolumeChangeCallback_.size(); } -void AudioPolicyClientStubImpl::OnRingerModeUpdated(const AudioRingerMode &ringerMode) +int32_t AudioPolicyClientStubImpl::OnRingerModeUpdated(int32_t ringerMode) { std::lock_guard lockCbMap(ringerModeMutex_); for (auto it = ringerModeCallbackList_.begin(); it != ringerModeCallbackList_.end(); ++it) { - (*it)->OnRingerModeUpdated(ringerMode); + (*it)->OnRingerModeUpdated(static_cast(ringerMode)); } + return SUCCESS; } -void AudioPolicyClientStubImpl::OnActiveVolumeTypeChanged(const AudioVolumeType &volumeType) +int32_t AudioPolicyClientStubImpl::OnActiveVolumeTypeChanged(int32_t volumeType) { std::lock_guard lockCbMap(activeVolumeTypeChangeMutex_); for (auto it = activeVolumeTypeChangeCallbackList_.begin(); it != activeVolumeTypeChangeCallbackList_.end(); ++it) { if (*it != nullptr) { - (*it)->OnActiveVolumeTypeChanged(volumeType); + (*it)->OnActiveVolumeTypeChanged(static_cast(volumeType)); } } + return SUCCESS; } -void AudioPolicyClientStubImpl::OnAppVolumeChanged(int32_t appUid, const VolumeEvent& volumeEvent) +int32_t AudioPolicyClientStubImpl::OnAppVolumeChanged(int32_t appUid, const VolumeEvent& volumeEvent) { { std::lock_guard lockCbMap(appVolumeChangeForUidMutex_); @@ -545,6 +583,7 @@ void AudioPolicyClientStubImpl::OnAppVolumeChanged(int32_t appUid, const VolumeE iter.second->OnSelfAppVolumeChanged(volumeEvent); } } + return SUCCESS; } int32_t AudioPolicyClientStubImpl::AddAudioSessionCallback(const std::shared_ptr &cb) @@ -584,13 +623,16 @@ size_t AudioPolicyClientStubImpl::GetAudioSessionCallbackSize() const return audioSessionCallbackList_.size(); } -void AudioPolicyClientStubImpl::OnAudioSessionDeactive(const AudioSessionDeactiveEvent &deactiveEvent) +int32_t AudioPolicyClientStubImpl::OnAudioSessionDeactive(int32_t deactiveEvent) { AUDIO_INFO_LOG("OnAudioSessionDeactive in"); std::lock_guard lockCbMap(audioSessionMutex_); + AudioSessionDeactiveEvent newDeactiveEvent; + newDeactiveEvent.deactiveReason = static_cast(deactiveEvent); for (auto it = audioSessionCallbackList_.begin(); it != audioSessionCallbackList_.end(); ++it) { - (*it)->OnAudioSessionDeactive(deactiveEvent); + (*it)->OnAudioSessionDeactive(newDeactiveEvent); } + return SUCCESS; } int32_t AudioPolicyClientStubImpl::AddAudioSessionStateCallback( @@ -632,8 +674,10 @@ size_t AudioPolicyClientStubImpl::GetAudioSessionStateCallbackSize() const return audioSessionStateCallbackList_.size(); } -void AudioPolicyClientStubImpl::OnAudioSessionStateChanged(const AudioSessionStateChangedEvent &stateChangedEvent) +int32_t AudioPolicyClientStubImpl::OnAudioSessionStateChanged(int32_t stateChangeHint) { + AudioSessionStateChangedEvent stateChangedEvent; + stateChangedEvent.stateChangeHint = static_cast(stateChangeHint); AUDIO_INFO_LOG("OnAudioSessionStateChanged in"); std::lock_guard lockCbMap(audioSessionStateMutex_); for (auto it = audioSessionStateCallbackList_.begin(); it != audioSessionStateCallbackList_.end(); ++it) { @@ -642,6 +686,7 @@ void AudioPolicyClientStubImpl::OnAudioSessionStateChanged(const AudioSessionSta audioSessionStateChangedCallback->OnAudioSessionStateChanged(stateChangedEvent); } } + return SUCCESS; } int32_t AudioPolicyClientStubImpl::AddMicStateChangeCallback( @@ -674,12 +719,13 @@ bool AudioPolicyClientStubImpl::HasMicStateChangeCallback() return true; } -void AudioPolicyClientStubImpl::OnMicStateUpdated(const MicStateChangeEvent &micStateChangeEvent) +int32_t AudioPolicyClientStubImpl::OnMicStateUpdated(const MicStateChangeEvent &micStateChangeEvent) { std::lock_guard lockCbMap(micStateChangeMutex_); for (auto it = micStateChangeCallbackList_.begin(); it != micStateChangeCallbackList_.end(); ++it) { (*it)->OnMicStateUpdated(micStateChangeEvent); } + return SUCCESS; } int32_t AudioPolicyClientStubImpl::AddPreferredOutputDeviceChangeCallback(const AudioRendererInfo &rendererInfo, @@ -713,16 +759,21 @@ size_t AudioPolicyClientStubImpl::GetPreferredOutputDeviceChangeCallbackSize() c return preferredOutputDeviceCallbackMap_.size(); } -void AudioPolicyClientStubImpl::OnPreferredOutputDeviceUpdated(const AudioRendererInfo &rendererInfo, +int32_t AudioPolicyClientStubImpl::OnPreferredOutputDeviceUpdated(const AudioRendererInfo &rendererInfo, const std::vector> &desc) { + int32_t size = static_cast(desc.size()); + CHECK_AND_RETURN_RET_LOG(size < PREFERRED_DEVICE_VALID_SIZE, ERR_INVALID_PARAM, + "get invalid size : %{public}d", size); std::lock_guard lockCbMap(pOutputDeviceChangeMutex_); auto it = preferredOutputDeviceCallbackMap_.find(rendererInfo.streamUsage); - CHECK_AND_RETURN_LOG(it != preferredOutputDeviceCallbackMap_.end(), "streamUsage not found"); + CHECK_AND_RETURN_RET_LOG(it != preferredOutputDeviceCallbackMap_.end(), + ERR_CALLBACK_NOT_REGISTERED, "streamUsage not found"); for (auto iter = it->second.begin(); iter != it->second.end(); ++iter) { CHECK_AND_CONTINUE_LOG(iter != it->second.end() && (*iter) != nullptr, "iter is null"); - (*iter)->OnPreferredOutputDeviceUpdated(desc); + (*iter)->OnPreferredOutputDeviceUpdated(desc); } + return SUCCESS; } int32_t AudioPolicyClientStubImpl::AddPreferredInputDeviceChangeCallback(const AudioCapturerInfo &capturerInfo, @@ -756,16 +807,21 @@ size_t AudioPolicyClientStubImpl::GetPreferredInputDeviceChangeCallbackSize() co return preferredInputDeviceCallbackMap_.size(); } -void AudioPolicyClientStubImpl::OnPreferredInputDeviceUpdated(const AudioCapturerInfo &capturerInfo, +int32_t AudioPolicyClientStubImpl::OnPreferredInputDeviceUpdated(const AudioCapturerInfo &capturerInfo, const std::vector> &desc) { + int32_t size = static_cast(desc.size()); + CHECK_AND_RETURN_RET_LOG(size < PREFERRED_DEVICE_VALID_SIZE, ERR_INVALID_PARAM, + "get invalid size : %{public}d", size); std::lock_guard lockCbMap(pInputDeviceChangeMutex_); auto it = preferredInputDeviceCallbackMap_.find(capturerInfo.sourceType); - CHECK_AND_RETURN_LOG(it != preferredInputDeviceCallbackMap_.end(), "sourceType not found"); + CHECK_AND_RETURN_RET_LOG(it != preferredInputDeviceCallbackMap_.end(), + ERR_CALLBACK_NOT_REGISTERED, "sourceType not found"); for (auto iter = it->second.begin(); iter != it->second.end(); ++iter) { CHECK_AND_CONTINUE_LOG(iter != it->second.end() && (*iter) != nullptr, "iter is null"); (*iter)->OnPreferredInputDeviceUpdated(desc); } + return SUCCESS; } int32_t AudioPolicyClientStubImpl::AddRendererStateChangeCallback( @@ -829,20 +885,20 @@ size_t AudioPolicyClientStubImpl::GetDeviceChangeWithInfoCallbackkSize() const return deviceChangeWithInfoCallbackMap_.size(); } -void AudioPolicyClientStubImpl::OnRendererDeviceChange(const uint32_t sessionId, - const AudioDeviceDescriptor &deviceInfo, const AudioStreamDeviceChangeReasonExt reason) +int32_t AudioPolicyClientStubImpl::OnRendererDeviceChange(uint32_t sessionId, + const AudioDeviceDescriptor &deviceInfo, const AudioStreamDeviceChangeReasonExt &reason) { Trace trace("AudioPolicyClientStubImpl::OnRendererDeviceChange"); std::shared_ptr callback = nullptr; { std::lock_guard lockCbMap(deviceChangeWithInfoCallbackMutex_); if (deviceChangeWithInfoCallbackMap_.count(sessionId) == 0) { - return; + return ERR_OPERATION_FAILED; } callback = deviceChangeWithInfoCallbackMap_.at(sessionId).lock(); if (callback == nullptr) { deviceChangeWithInfoCallbackMap_.erase(sessionId); - return; + return ERR_CALLBACK_NOT_REGISTERED; } } if (callback != nullptr) { @@ -850,11 +906,15 @@ void AudioPolicyClientStubImpl::OnRendererDeviceChange(const uint32_t sessionId, + " reason:" + std::to_string(static_cast(reason))); callback->OnDeviceChangeWithInfo(sessionId, deviceInfo, reason); } + return SUCCESS; } -void AudioPolicyClientStubImpl::OnRendererStateChange( - std::vector> &audioRendererChangeInfos) +int32_t AudioPolicyClientStubImpl::OnRendererStateChange( + const std::vector> &audioRendererChangeInfos) { + int32_t size = static_cast(audioRendererChangeInfos.size()); + CHECK_AND_RETURN_RET_LOG(size < STATE_VALID_SIZE, ERR_INVALID_PARAM, + "get invalid size : %{public}d", size); std::vector> callbacks; { std::lock_guard lockCbMap(rendererStateChangeMutex_); @@ -873,10 +933,11 @@ void AudioPolicyClientStubImpl::OnRendererStateChange( Trace traceCallback("OnRendererStateChange"); cb->OnRendererStateChange(audioRendererChangeInfos); } + return SUCCESS; } -void AudioPolicyClientStubImpl::OnRecreateRendererStreamEvent(const uint32_t sessionId, const int32_t streamFlag, - const AudioStreamDeviceChangeReasonExt reason) +int32_t AudioPolicyClientStubImpl::OnRecreateRendererStreamEvent(uint32_t sessionId, int32_t streamFlag, + const AudioStreamDeviceChangeReasonExt &reason) { AUDIO_INFO_LOG("Enter"); std::shared_ptr callback = nullptr; @@ -884,17 +945,18 @@ void AudioPolicyClientStubImpl::OnRecreateRendererStreamEvent(const uint32_t ses std::lock_guard lockCbMap(deviceChangeWithInfoCallbackMutex_); if (deviceChangeWithInfoCallbackMap_.count(sessionId) == 0) { AUDIO_ERR_LOG("No session id %{public}d", sessionId); - return; + return ERR_OPERATION_FAILED; } callback = deviceChangeWithInfoCallbackMap_.at(sessionId).lock(); } if (callback != nullptr) { callback->OnRecreateStreamEvent(sessionId, streamFlag, reason); } + return SUCCESS; } -void AudioPolicyClientStubImpl::OnRecreateCapturerStreamEvent(const uint32_t sessionId, const int32_t streamFlag, - const AudioStreamDeviceChangeReasonExt reason) +int32_t AudioPolicyClientStubImpl::OnRecreateCapturerStreamEvent(uint32_t sessionId, int32_t streamFlag, + const AudioStreamDeviceChangeReasonExt &reason) { AUDIO_INFO_LOG("Enter"); std::shared_ptr callback = nullptr; @@ -902,13 +964,14 @@ void AudioPolicyClientStubImpl::OnRecreateCapturerStreamEvent(const uint32_t ses std::lock_guard lockCbMap(deviceChangeWithInfoCallbackMutex_); if (deviceChangeWithInfoCallbackMap_.count(sessionId) == 0) { AUDIO_ERR_LOG("No session id %{public}d", sessionId); - return; + return ERR_OPERATION_FAILED; } callback = deviceChangeWithInfoCallbackMap_.at(sessionId).lock(); } if (callback != nullptr) { callback->OnRecreateStreamEvent(sessionId, streamFlag, reason); } + return SUCCESS; } int32_t AudioPolicyClientStubImpl::AddCapturerStateChangeCallback( @@ -932,9 +995,12 @@ size_t AudioPolicyClientStubImpl::GetCapturerStateChangeCallbackSize() const return capturerStateChangeCallbackList_.size(); } -void AudioPolicyClientStubImpl::OnCapturerStateChange( - std::vector> &audioCapturerChangeInfos) +int32_t AudioPolicyClientStubImpl::OnCapturerStateChange( + const std::vector> &audioCapturerChangeInfos) { + int32_t size = static_cast(audioCapturerChangeInfos.size()); + CHECK_AND_RETURN_RET_LOG(size < STATE_VALID_SIZE, ERR_INVALID_PARAM, + "get invalid size : %{public}d", size); std::vector> tmpCallbackList; { std::lock_guard lockCbMap(capturerStateChangeMutex_); @@ -952,6 +1018,7 @@ void AudioPolicyClientStubImpl::OnCapturerStateChange( } (*it)->OnCapturerStateChange(audioCapturerChangeInfos); } + return SUCCESS; } int32_t AudioPolicyClientStubImpl::AddHeadTrackingDataRequestedChangeCallback(const std::string &macAddress, @@ -981,11 +1048,14 @@ size_t AudioPolicyClientStubImpl::GetHeadTrackingDataRequestedChangeCallbackSize return headTrackingDataRequestedChangeCallbackMap_.size(); } -void AudioPolicyClientStubImpl::OnHeadTrackingDeviceChange(const std::unordered_map &changeInfo) +int32_t AudioPolicyClientStubImpl::OnHeadTrackingDeviceChange(const std::unordered_map &changeInfo) { + int32_t size = static_cast(changeInfo.size()); + CHECK_AND_RETURN_RET_LOG(size < DEVICE_CHANGE_VALID_SIZE, ERR_INVALID_PARAM, + "get invalid size : %{public}d", size); std::lock_guard lockCbMap(headTrackingDataRequestedChangeMutex_); if (headTrackingDataRequestedChangeCallbackMap_.size() == 0) { - return; + return ERR_INVALID_PARAM; } for (const auto &pair : changeInfo) { if (!headTrackingDataRequestedChangeCallbackMap_.count(pair.first)) { @@ -999,6 +1069,7 @@ void AudioPolicyClientStubImpl::OnHeadTrackingDeviceChange(const std::unordered_ headTrackingDataRequestedChangeCallback->OnHeadTrackingDataRequestedChange(pair.second); } } + return SUCCESS; } int32_t AudioPolicyClientStubImpl::AddSpatializationEnabledChangeCallback( @@ -1022,21 +1093,23 @@ size_t AudioPolicyClientStubImpl::GetSpatializationEnabledChangeCallbackSize() c return spatializationEnabledChangeCallbackList_.size(); } -void AudioPolicyClientStubImpl::OnSpatializationEnabledChange(const bool &enabled) +int32_t AudioPolicyClientStubImpl::OnSpatializationEnabledChange(bool enabled) { std::lock_guard lockCbMap(spatializationEnabledChangeMutex_); for (const auto &callback : spatializationEnabledChangeCallbackList_) { callback->OnSpatializationEnabledChange(enabled); } + return SUCCESS; } -void AudioPolicyClientStubImpl::OnSpatializationEnabledChangeForAnyDevice( - const std::shared_ptr &deviceDescriptor, const bool &enabled) +int32_t AudioPolicyClientStubImpl::OnSpatializationEnabledChangeForAnyDevice( + const std::shared_ptr &deviceDescriptor, bool enabled) { std::lock_guard lockCbMap(spatializationEnabledChangeMutex_); for (const auto &callback : spatializationEnabledChangeCallbackList_) { callback->OnSpatializationEnabledChangeForAnyDevice(deviceDescriptor, enabled); } + return SUCCESS; } int32_t AudioPolicyClientStubImpl::AddSpatializationEnabledChangeForCurrentDeviceCallback( @@ -1060,12 +1133,13 @@ size_t AudioPolicyClientStubImpl::GetSpatializationEnabledChangeForCurrentDevice return spatializationEnabledChangeForCurrentDeviceCallbackList_.size(); } -void AudioPolicyClientStubImpl::OnSpatializationEnabledChangeForCurrentDevice(const bool &enabled) +int32_t AudioPolicyClientStubImpl::OnSpatializationEnabledChangeForCurrentDevice(bool enabled) { std::lock_guard lockCbMap(spatializationEnabledChangeForCurrentDeviceMutex_); for (const auto &callback : spatializationEnabledChangeForCurrentDeviceCallbackList_) { callback->OnSpatializationEnabledChangeForCurrentDevice(enabled); } + return SUCCESS; } int32_t AudioPolicyClientStubImpl::AddHeadTrackingEnabledChangeCallback( @@ -1089,21 +1163,23 @@ size_t AudioPolicyClientStubImpl::GetHeadTrackingEnabledChangeCallbacSize() cons return headTrackingEnabledChangeCallbackList_.size(); } -void AudioPolicyClientStubImpl::OnHeadTrackingEnabledChange(const bool &enabled) +int32_t AudioPolicyClientStubImpl::OnHeadTrackingEnabledChange(bool enabled) { std::lock_guard lockCbMap(headTrackingEnabledChangeMutex_); for (const auto &callback : headTrackingEnabledChangeCallbackList_) { callback->OnHeadTrackingEnabledChange(enabled); } + return SUCCESS; } -void AudioPolicyClientStubImpl::OnHeadTrackingEnabledChangeForAnyDevice( - const std::shared_ptr &deviceDescriptor, const bool &enabled) +int32_t AudioPolicyClientStubImpl::OnHeadTrackingEnabledChangeForAnyDevice( + const std::shared_ptr &deviceDescriptor, bool enabled) { std::lock_guard lockCbMap(headTrackingEnabledChangeMutex_); for (const auto &callback : headTrackingEnabledChangeCallbackList_) { callback->OnHeadTrackingEnabledChangeForAnyDevice(deviceDescriptor, enabled); } + return SUCCESS; } int32_t AudioPolicyClientStubImpl::AddNnStateChangeCallback(const std::shared_ptr &cb) @@ -1126,12 +1202,13 @@ size_t AudioPolicyClientStubImpl::GetNnStateChangeCallbackSize() const return nnStateChangeCallbackList_.size(); } -void AudioPolicyClientStubImpl::OnNnStateChange(const int32_t &nnState) +int32_t AudioPolicyClientStubImpl::OnNnStateChange(int32_t nnState) { std::lock_guard lockCbMap(nnStateChangeMutex_); for (const auto &callback : nnStateChangeCallbackList_) { callback->OnNnStateChange(nnState); } + return SUCCESS; } int32_t AudioPolicyClientStubImpl::AddAudioFormatUnsupportedErrorCallback( @@ -1155,12 +1232,14 @@ size_t AudioPolicyClientStubImpl::GetAudioFormatUnsupportedErrorCallbackSize() c return AudioFormatUnsupportedErrorCallbackList_.size(); } -void AudioPolicyClientStubImpl::OnFormatUnsupportedError(const AudioErrors &errorCode) +int32_t AudioPolicyClientStubImpl::OnFormatUnsupportedError(int32_t errorCode) { std::lock_guard lockCbMap(formatUnsupportedErrorMutex_); for (const auto &callback : AudioFormatUnsupportedErrorCallbackList_) { - callback->OnFormatUnsupportedError(errorCode); + CHECK_AND_CONTINUE(callback != nullptr); + callback->OnFormatUnsupportedError(static_cast(errorCode)); } + return SUCCESS; } size_t AudioPolicyClientStubImpl::GetStreamVolumeChangeCallbackSize() const @@ -1206,7 +1285,7 @@ int32_t AudioPolicyClientStubImpl::RemoveStreamVolumeChangeCallback( return SUCCESS; } -void AudioPolicyClientStubImpl::OnStreamVolumeChange(StreamVolumeEvent streamVolumeEvent) +int32_t AudioPolicyClientStubImpl::OnStreamVolumeChange(const StreamVolumeEvent &streamVolumeEvent) { std::lock_guard lockCbMap(volumeKeyEventMutex_); for (auto &[streamUsages, cb] : streamVolumeChangeCallbackList_) { @@ -1215,6 +1294,7 @@ void AudioPolicyClientStubImpl::OnStreamVolumeChange(StreamVolumeEvent streamVol streamVolumeChangeCallback->OnStreamVolumeChange(streamVolumeEvent); } } + return SUCCESS; } } // namespace AudioStandard } // namespace OHOS \ No newline at end of file diff --git a/services/audio_policy/client/stub/src/audio_policy_manager_listener_stub.cpp b/services/audio_policy/client/stub/src/audio_policy_manager_listener_stub_impl.cpp similarity index 32% rename from services/audio_policy/client/stub/src/audio_policy_manager_listener_stub.cpp rename to services/audio_policy/client/stub/src/audio_policy_manager_listener_stub_impl.cpp index f017874756..9de338ee97 100644 --- a/services/audio_policy/client/stub/src/audio_policy_manager_listener_stub.cpp +++ b/services/audio_policy/client/stub/src/audio_policy_manager_listener_stub_impl.cpp @@ -13,251 +13,157 @@ * limitations under the License. */ #ifndef LOG_TAG -#define LOG_TAG "AudioPolicyManagerListenerStub" +#define LOG_TAG "AudioPolicyManagerListenerStubImpl" #endif - +#include "audio_errors.h" #include "audio_policy_log.h" -#include "audio_policy_manager_listener_stub.h" +#include "audio_policy_manager_listener_stub_impl.h" #include "audio_utils.h" namespace OHOS { namespace AudioStandard { - -static const int32_t DEVICE_CHANGE_VALID_SIZE = 128; - -AudioPolicyManagerListenerStub::AudioPolicyManagerListenerStub() +AudioPolicyManagerListenerStubImpl::AudioPolicyManagerListenerStubImpl() { } -AudioPolicyManagerListenerStub::~AudioPolicyManagerListenerStub() +AudioPolicyManagerListenerStubImpl::~AudioPolicyManagerListenerStubImpl() { } -void AudioPolicyManagerListenerStub::ReadInterruptEventParams(MessageParcel &data, - InterruptEventInternal &interruptEvent) -{ - interruptEvent.eventType = static_cast(data.ReadInt32()); - interruptEvent.forceType = static_cast(data.ReadInt32()); - interruptEvent.hintType = static_cast(data.ReadInt32()); - interruptEvent.duckVolume = data.ReadFloat(); - interruptEvent.callbackToApp = data.ReadBool(); -} - -void AudioPolicyManagerListenerStub::ReadAudioDeviceChangeData(MessageParcel &data, DeviceChangeAction &devChange) -{ - std::vector> deviceChangeDesc = {}; - - int32_t type = data.ReadInt32(); - int32_t flag = data.ReadInt32(); - int32_t size = data.ReadInt32(); - CHECK_AND_RETURN_LOG(size < DEVICE_CHANGE_VALID_SIZE, "get invalid size : %{public}d", size); - - for (int32_t i = 0; i < size; i++) { - deviceChangeDesc.push_back(AudioDeviceDescriptor::UnmarshallingPtr(data)); - } - - devChange.type = static_cast(type); - devChange.flag = static_cast(flag); - devChange.deviceDescriptors = deviceChangeDesc; -} - -int AudioPolicyManagerListenerStub::OnRemoteRequest( - uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - CHECK_AND_RETURN_RET_LOG(data.ReadInterfaceToken() == GetDescriptor(), AUDIO_INVALID_PARAM, - "ReadInterfaceToken failed"); - Trace trace("AudioPolicyManagerListenerStub::OnRemoteRequest:" + std::to_string(code)); - switch (code) { - case ON_INTERRUPT: { - InterruptEventInternal interruptEvent = {}; - ReadInterruptEventParams(data, interruptEvent); - // To be modified by enqueuing the interrupt action scheduler - OnInterrupt(interruptEvent); - return AUDIO_OK; - } - case ON_AVAILABLE_DEVICE_CAHNGE: { - AudioDeviceUsage usage = static_cast(data.ReadInt32()); - DeviceChangeAction deviceChangeAction = {}; - ReadAudioDeviceChangeData(data, deviceChangeAction); - OnAvailableDeviceChange(usage, deviceChangeAction); - return AUDIO_OK; - } - case ON_QUERY_CLIENT_TYPE: { - std::string bundleName = data.ReadString(); - uint32_t uid = data.ReadUint32(); - OnQueryClientType(bundleName, uid); - return AUDIO_OK; - } - case ON_QUERY_ALLOWED_PLAYBACK: { - int32_t uid = data.ReadInt32(); - int32_t pid = data.ReadInt32(); - bool ret = OnQueryAllowedPlayback(uid, pid); - reply.WriteBool(ret); - return AUDIO_OK; - } - case ON_BACKGROUND_MUTE: { - int32_t uid = data.ReadInt32(); - OnBackgroundMute(uid); - return AUDIO_OK; - } - case ON_CHECK_CLIENT_INFO: { - std::string bundleName = data.ReadString(); - int32_t uid = data.ReadInt32(); - int32_t pid = data.ReadInt32(); - OnCheckClientInfo(bundleName, uid, pid); - return AUDIO_OK; - } - default: - return OnMiddleFirRemoteRequest(code, data, reply, option); - } -} - -int32_t AudioPolicyManagerListenerStub::OnMiddleFirRemoteRequest( - uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - switch (code) { - case ON_QUERY_BUNDLE_NAME_LIST: { - std::string bundleName = data.ReadString(); - std::string listType = data.ReadString(); - OnQueryBundleNameIsInList(bundleName, listType); - return AUDIO_OK; - } - case ON_CHECK_VKB_INFO: { - std::string bundleName = data.ReadString(); - OnCheckVKBInfo(bundleName); - return AUDIO_OK; - } - default: { - AUDIO_ERR_LOG("default case, need check AudioListenerStub"); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } - } -} - -void AudioPolicyManagerListenerStub::OnInterrupt(const InterruptEventInternal &interruptEvent) +int32_t AudioPolicyManagerListenerStubImpl::OnInterrupt(const InterruptEventInternal &interruptEvent) { std::shared_ptr cb = callback_.lock(); if (cb != nullptr) { cb->OnInterrupt(interruptEvent); } else { - AUDIO_WARNING_LOG("AudioPolicyManagerListenerStub: callback_ is nullptr"); + AUDIO_WARNING_LOG("AudioPolicyManagerListenerStubImpl: callback_ is nullptr"); } + return SUCCESS; } -void AudioPolicyManagerListenerStub::OnAvailableDeviceChange(const AudioDeviceUsage usage, +int32_t AudioPolicyManagerListenerStubImpl::OnAvailableDeviceChange(uint32_t usage, const DeviceChangeAction &deviceChangeAction) { std::shared_ptr availabledeviceChangedCallback = audioAvailableDeviceChangeCallback_.lock(); - CHECK_AND_RETURN_LOG(availabledeviceChangedCallback != nullptr, + CHECK_AND_RETURN_RET_LOG(availabledeviceChangedCallback != nullptr, AUDIO_INVALID_PARAM, "OnAvailableDeviceChange: deviceChangeCallback_ or deviceChangeAction is nullptr"); - availabledeviceChangedCallback->OnAvailableDeviceChange(usage, deviceChangeAction); + availabledeviceChangedCallback->OnAvailableDeviceChange(static_cast(usage), deviceChangeAction); + return SUCCESS; } -bool AudioPolicyManagerListenerStub::OnQueryClientType(const std::string &bundleName, uint32_t uid) +int32_t AudioPolicyManagerListenerStubImpl::OnQueryClientType(const std::string &bundleName, uint32_t uid, bool &ret) { std::shared_ptr audioQueryClientTypeCallback = audioQueryClientTypeCallback_.lock(); - CHECK_AND_RETURN_RET_LOG(audioQueryClientTypeCallback != nullptr, false, + CHECK_AND_RETURN_RET_LOG(audioQueryClientTypeCallback != nullptr, AUDIO_INVALID_PARAM, "audioQueryClientTypeCallback_ is nullptr"); - - return audioQueryClientTypeCallback->OnQueryClientType(bundleName, uid); + ret = audioQueryClientTypeCallback->OnQueryClientType(bundleName, uid); + return SUCCESS; } -bool AudioPolicyManagerListenerStub::OnCheckClientInfo(const std::string &bundleName, - int32_t &uid, int32_t pid) +int32_t AudioPolicyManagerListenerStubImpl::OnCheckClientInfo( + const std::string &bundleName, int32_t &uid, int32_t pid, bool &ret) { std::shared_ptr audioClientInfoMgrCallback = audioClientInfoMgrCallback_.lock(); - CHECK_AND_RETURN_RET_LOG(audioClientInfoMgrCallback != nullptr, false, "audioClientInfoMgrCallback is nullptr"); - - return audioClientInfoMgrCallback->OnCheckClientInfo(bundleName, uid, pid); + CHECK_AND_RETURN_RET_LOG(audioClientInfoMgrCallback != nullptr, AUDIO_INVALID_PARAM, + "audioClientInfoMgrCallback is nullptr"); + ret = audioClientInfoMgrCallback->OnCheckClientInfo(bundleName, uid, pid); + return SUCCESS; } -bool AudioPolicyManagerListenerStub::OnCheckVKBInfo(const std::string &bundleName) +int32_t AudioPolicyManagerListenerStubImpl::OnCheckVKBInfo(const std::string &bundleName, bool &isValid) { std::shared_ptr audioVKBInfoMgrCallback = audioVKBInfoMgrCallback_.lock(); CHECK_AND_RETURN_RET_LOG(audioVKBInfoMgrCallback != nullptr, false, "audioVKBInfoMgrCallback is nullptr"); - return audioVKBInfoMgrCallback->OnCheckVKBInfo(bundleName); + isValid = audioVKBInfoMgrCallback->OnCheckVKBInfo(bundleName); + return SUCCESS; } -bool AudioPolicyManagerListenerStub::OnQueryAllowedPlayback(int32_t uid, int32_t pid) +int32_t AudioPolicyManagerListenerStubImpl::OnQueryAllowedPlayback(int32_t uid, int32_t pid, bool &ret) { std::shared_ptr audioQueryAllowedPlaybackCallback = audioQueryAllowedPlaybackCallback_.lock(); - CHECK_AND_RETURN_RET_LOG(audioQueryAllowedPlaybackCallback != nullptr, false, + CHECK_AND_RETURN_RET_LOG(audioQueryAllowedPlaybackCallback != nullptr, AUDIO_INVALID_PARAM, "audioQueryAllowedPlaybackCallback_ is nullptr"); - - return audioQueryAllowedPlaybackCallback->OnQueryAllowedPlayback(uid, pid); + ret = audioQueryAllowedPlaybackCallback->OnQueryAllowedPlayback(uid, pid); + return SUCCESS; } -void AudioPolicyManagerListenerStub::OnBackgroundMute(const int32_t uid) +int32_t AudioPolicyManagerListenerStubImpl::OnBackgroundMute(const int32_t uid) { std::shared_ptr audioBackgroundMuteCallback = audioBackgroundMuteCallback_.lock(); - CHECK_AND_RETURN_LOG(audioBackgroundMuteCallback != nullptr, "audioBackgroundMuteCallback_ is nullptr"); + CHECK_AND_RETURN_RET_LOG(audioBackgroundMuteCallback != nullptr, AUDIO_INVALID_PARAM, + "audioBackgroundMuteCallback_ is nullptr"); audioBackgroundMuteCallback->OnBackgroundMute(uid); + return SUCCESS; } -bool AudioPolicyManagerListenerStub::OnQueryBundleNameIsInList(const std::string &bundleName, - const std::string &listType) +int32_t AudioPolicyManagerListenerStubImpl::OnQueryBundleNameIsInList(const std::string &bundleName, + const std::string &listType, bool& ret) { std::shared_ptr audioQueryBundleNameListCallback = audioQueryBundleNameListCallback_.lock(); - CHECK_AND_RETURN_RET_LOG(audioQueryBundleNameListCallback != nullptr, false, + CHECK_AND_RETURN_RET_LOG(audioQueryBundleNameListCallback != nullptr, AUDIO_INVALID_PARAM, "audioQueryBundleNameListCallback_ is nullptr"); - - return audioQueryBundleNameListCallback->OnQueryBundleNameIsInList(bundleName, listType); + ret = audioQueryBundleNameListCallback->OnQueryBundleNameIsInList(bundleName, listType); + return SUCCESS; } -void AudioPolicyManagerListenerStub::SetInterruptCallback(const std::weak_ptr &callback) +void AudioPolicyManagerListenerStubImpl::SetInterruptCallback(const std::weak_ptr &callback) { callback_ = callback; } -void AudioPolicyManagerListenerStub::SetAvailableDeviceChangeCallback( +void AudioPolicyManagerListenerStubImpl::SetAvailableDeviceChangeCallback( const std::weak_ptr &cb) { audioAvailableDeviceChangeCallback_ = cb; } -void AudioPolicyManagerListenerStub::SetQueryClientTypeCallback(const std::weak_ptr &cb) +void AudioPolicyManagerListenerStubImpl::SetQueryClientTypeCallback( + const std::weak_ptr &cb) { audioQueryClientTypeCallback_ = cb; } -void AudioPolicyManagerListenerStub::SetAudioClientInfoMgrCallback(const std::weak_ptr &cb) +void AudioPolicyManagerListenerStubImpl::SetAudioClientInfoMgrCallback( + const std::weak_ptr &cb) { audioClientInfoMgrCallback_ = cb; } -void AudioPolicyManagerListenerStub::SetAudioVKBInfoMgrCallback(const std::weak_ptr &cb) +void AudioPolicyManagerListenerStubImpl::SetAudioVKBInfoMgrCallback( + const std::weak_ptr &cb) { audioVKBInfoMgrCallback_ = cb; } -void AudioPolicyManagerListenerStub::SetQueryAllowedPlaybackCallback( +void AudioPolicyManagerListenerStubImpl::SetQueryAllowedPlaybackCallback( const std::weak_ptr &cb) { audioQueryAllowedPlaybackCallback_ = cb; } -void AudioPolicyManagerListenerStub::SetBackgroundMuteCallback(const std::weak_ptr &cb) +void AudioPolicyManagerListenerStubImpl::SetBackgroundMuteCallback( + const std::weak_ptr &cb) { audioBackgroundMuteCallback_ = cb; } -void AudioPolicyManagerListenerStub::SetQueryBundleNameListCallback( +void AudioPolicyManagerListenerStubImpl::SetQueryBundleNameListCallback( const std::weak_ptr &cb) { audioQueryBundleNameListCallback_ = cb; diff --git a/services/audio_policy/client/stub/src/audio_spatialization_state_change_listener_stub.cpp b/services/audio_policy/client/stub/src/audio_spatialization_state_change_listener_stub.cpp deleted file mode 100644 index 1a93e1a24e..0000000000 --- a/services/audio_policy/client/stub/src/audio_spatialization_state_change_listener_stub.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * 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. - */ -#ifndef LOG_TAG -#define LOG_TAG "AudioSpatializationStateChangeListenerStub" -#endif - -#include "audio_spatialization_state_change_listener_stub.h" -#include "audio_policy_log.h" - -using namespace std; - -namespace OHOS { -namespace AudioStandard { -AudioSpatializationStateChangeListenerStub::AudioSpatializationStateChangeListenerStub() -{ - AUDIO_DEBUG_LOG("AudioSpatializationStateChangeListenerStub Instance create"); -} - -AudioSpatializationStateChangeListenerStub::~AudioSpatializationStateChangeListenerStub() -{ - AUDIO_DEBUG_LOG("AudioSpatializationStateChangeListenerStub Instance destroy"); -} - -int AudioSpatializationStateChangeListenerStub::OnRemoteRequest( - uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - if (data.ReadInterfaceToken() != GetDescriptor()) { - AUDIO_ERR_LOG("AudioSpatializationStateChangeListenerStub: ReadInterfaceToken failed"); - return -1; - } - - switch (code) { - case ON_SPATIALIZATION_STATE_CHANGE: { - AudioSpatializationState spatializationState; - spatializationState.spatializationEnabled = data.ReadBool(); - spatializationState.headTrackingEnabled = data.ReadBool(); - OnSpatializationStateChange(spatializationState); - return AUDIO_OK; - } - default: { - AUDIO_ERR_LOG("default case, need check AudioListenerStub"); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } - } -} - -void AudioSpatializationStateChangeListenerStub::OnSpatializationStateChange( - const AudioSpatializationState &spatializationState) -{ - AUDIO_DEBUG_LOG("AudioSpatializationStateChangeListenerStub OnSpatializationStateChange"); - - shared_ptr cb = callback_.lock(); - if (cb == nullptr) { - AUDIO_ERR_LOG("AudioSpatializationStateChangeListenerStub: callback_ is nullptr"); - return; - } - - cb->OnSpatializationStateChange(spatializationState); - return; -} - -void AudioSpatializationStateChangeListenerStub::SetCallback( - const weak_ptr &callback) -{ - AUDIO_DEBUG_LOG("AudioSpatializationStateChangeListenerStub SetCallback"); - callback_ = callback; -} -} // namespace AudioStandard -} // namespace OHOS diff --git a/services/audio_policy/client/stub/src/audio_zone_client.cpp b/services/audio_policy/client/stub/src/audio_zone_client.cpp index 87466e1273..227511ca9d 100644 --- a/services/audio_policy/client/stub/src/audio_zone_client.cpp +++ b/services/audio_policy/client/stub/src/audio_zone_client.cpp @@ -24,117 +24,6 @@ namespace OHOS { namespace AudioStandard { static constexpr int32_t MAX_SIZE = 1024; -AudioZoneClientStub::AudioZoneClientStub() -{} - -AudioZoneClientStub::~AudioZoneClientStub() -{} - -int32_t AudioZoneClientStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &option) -{ - switch (code) { - case static_cast(AudioZoneClientCode::ON_AUDIO_ZONE_ADD): - HandleAudioZoneAdd(data, reply); - break; - case static_cast(AudioZoneClientCode::ON_AUDIO_ZONE_REMOVE): - HandleAudioZoneRemove(data, reply); - break; - case static_cast(AudioZoneClientCode::ON_AUDIO_ZONE_CHANGE): - HandleAudioZoneChange(data, reply); - break; - case static_cast(AudioZoneClientCode::ON_AUDIO_ZONE_INTERRUPT): - HandleAudioZoneInterrupt(data, reply); - break; - case static_cast(AudioZoneClientCode::ON_AUDIO_ZONE_DEVICE_INTERRUPT): - HandleAudioZoneDeviceInterrupt(data, reply); - break; - case static_cast(AudioZoneClientCode::ON_AUDIO_ZONE_SYSTEM_VOLUME_SET): - HandleAudioZoneSetSystemVolume(data, reply); - break; - case static_cast(AudioZoneClientCode::ON_AUDIO_ZONE_SYSTEM_VOLUME_GET): - HandleAudioZoneGetSystemVolume(data, reply); - break; - default: - break; - } - return SUCCESS; -} - -void AudioZoneClientStub::HandleAudioZoneAdd(MessageParcel &data, MessageParcel &reply) -{ - CHECK_AND_RETURN_LOG(data.ReadInterfaceToken() == GetDescriptor(), - "AudioZoneClientStub: ReadInterfaceToken failed"); - AudioZoneDescriptor desc; - desc.Unmarshalling(data); - OnAudioZoneAdd(desc); -} - -void AudioZoneClientStub::HandleAudioZoneRemove(MessageParcel &data, MessageParcel &reply) -{ - CHECK_AND_RETURN_LOG(data.ReadInterfaceToken() == GetDescriptor(), - "AudioZoneClientStub: ReadInterfaceToken failed"); - OnAudioZoneRemove(data.ReadInt32()); -} - -void AudioZoneClientStub::HandleAudioZoneChange(MessageParcel &data, MessageParcel &reply) -{ - int32_t zoneId = data.ReadInt32(); - AudioZoneDescriptor desc; - desc.Unmarshalling(data); - AudioZoneChangeReason reason = static_cast(data.ReadInt32()); - OnAudioZoneChange(zoneId, desc, reason); -} - -void AudioZoneClientStub::HandleAudioZoneInterrupt(MessageParcel &data, MessageParcel &reply) -{ - int32_t zoneId = data.ReadInt32(); - int32_t size = data.ReadInt32(); - CHECK_AND_RETURN_LOG(size > 0 && size < MAX_SIZE, "invalid interrupt size: %{public}d", size); - std::list> interrupts; - for (int32_t i = 0; i < size; i++) { - AudioInterrupt temp; - AudioInterrupt::Unmarshalling(data, temp); - AudioFocuState state = static_cast(data.ReadInt32()); - interrupts.emplace_back(std::make_pair(temp, state)); - } - AudioZoneInterruptReason reason = static_cast(data.ReadInt32()); - OnInterruptEvent(zoneId, interrupts, reason); -} - -void AudioZoneClientStub::HandleAudioZoneDeviceInterrupt(MessageParcel &data, MessageParcel &reply) -{ - int32_t zoneId = data.ReadInt32(); - std::string deviceTag = data.ReadString(); - int32_t size = data.ReadInt32(); - CHECK_AND_RETURN_LOG(size > 0 && size < MAX_SIZE, "invalid interrupt size: %{public}d", size); - std::list> interrupts; - for (int32_t i = 0; i < size; i++) { - AudioInterrupt temp; - AudioInterrupt::Unmarshalling(data, temp); - AudioFocuState state = static_cast(data.ReadInt32()); - interrupts.emplace_back(std::make_pair(temp, state)); - } - AudioZoneInterruptReason reason = static_cast(data.ReadInt32()); - OnInterruptEvent(zoneId, deviceTag, interrupts, reason); -} - -void AudioZoneClientStub::HandleAudioZoneSetSystemVolume(MessageParcel &data, MessageParcel &reply) -{ - int32_t zoneId = data.ReadInt32(); - AudioVolumeType volumeType = static_cast(data.ReadInt32()); - int32_t volumeLevel = data.ReadInt32(); - int32_t volumeFlag = data.ReadInt32(); - reply.WriteInt32(SetSystemVolume(zoneId, volumeType, volumeLevel, volumeFlag)); -} - -void AudioZoneClientStub::HandleAudioZoneGetSystemVolume(MessageParcel &data, MessageParcel &reply) -{ - int32_t zoneId = data.ReadInt32(); - AudioVolumeType volumeType = static_cast(data.ReadInt32()); - reply.WriteInt32(GetSystemVolume(zoneId, volumeType)); -} - AudioZoneClient::AudioZoneClient() {} @@ -290,67 +179,93 @@ std::string AudioZoneClient::GetInterruptKeyId(int32_t zoneId, const std::string return std::to_string(zoneId) + "&" + deviceTag; } -void AudioZoneClient::OnAudioZoneAdd(const AudioZoneDescriptor &zoneDescriptor) +int32_t AudioZoneClient::OnAudioZoneAdd(const AudioZoneDescriptor &zoneDescriptor) { std::lock_guard lk(audioZoneCallbackMutex_); - CHECK_AND_RETURN_LOG(audioZoneCallback_ != nullptr, "audioZoneCallback_ is null."); + CHECK_AND_RETURN_RET_LOG(audioZoneCallback_ != nullptr, ERR_OPERATION_FAILED, "audioZoneCallback_ is null."); audioZoneCallback_->OnAudioZoneAdd(zoneDescriptor); + return SUCCESS; } -void AudioZoneClient::OnAudioZoneRemove(int32_t zoneId) +int32_t AudioZoneClient::OnAudioZoneRemove(int32_t zoneId) { std::lock_guard lk(audioZoneCallbackMutex_); - CHECK_AND_RETURN_LOG(audioZoneCallback_ != nullptr, "audioZoneCallback_ is null."); + CHECK_AND_RETURN_RET_LOG(audioZoneCallback_ != nullptr, ERR_OPERATION_FAILED, "audioZoneCallback_ is null."); audioZoneCallback_->OnAudioZoneRemove(zoneId); + return SUCCESS; } -void AudioZoneClient::OnAudioZoneChange(int32_t zoneId, const AudioZoneDescriptor &zoneDescriptor, - AudioZoneChangeReason reason) +int32_t AudioZoneClient::OnAudioZoneChange(int32_t zoneId, const AudioZoneDescriptor &zoneDescriptor, + int32_t reason) { std::lock_guard lk(audioZoneCallbackMutex_); - CHECK_AND_RETURN_LOG(audioZoneChangeCallbackMap_.find(zoneId) != audioZoneChangeCallbackMap_.end(), - "audioZoneChangeCallbackMap_ not find zoneId %{public}d.", zoneId); - - audioZoneChangeCallbackMap_[zoneId]->OnAudioZoneChange(zoneDescriptor, reason); + CHECK_AND_RETURN_RET_LOG(audioZoneChangeCallbackMap_.find(zoneId) != audioZoneChangeCallbackMap_.end(), + ERR_OPERATION_FAILED, "audioZoneChangeCallbackMap_ not find zoneId %{public}d.", zoneId); + CHECK_AND_RETURN_RET_LOG(audioZoneChangeCallbackMap_[zoneId] != nullptr, + ERR_OPERATION_FAILED, "audioZoneChangeCallback is nullptr, zoneId %{public}d.", zoneId); + audioZoneChangeCallbackMap_[zoneId]->OnAudioZoneChange(zoneDescriptor, + static_cast(reason)); + return SUCCESS; } -void AudioZoneClient::OnInterruptEvent(int32_t zoneId, - const std::list> &interrupts, - AudioZoneInterruptReason reason) +int32_t AudioZoneClient::OnInterruptEvent(int32_t zoneId, + const std::vector> &ipcInterrupts, + int32_t reason) { - OnInterruptEvent(zoneId, "", interrupts, reason); + int32_t size = static_cast(ipcInterrupts.size()); + CHECK_AND_RETURN_RET_LOG(size > 0 && size < MAX_SIZE, ERR_INVALID_PARAM, + "invalid interrupt size: %{public}d", size); + OnInterruptEvent(zoneId, "", ipcInterrupts, reason); + return SUCCESS; } -void AudioZoneClient::OnInterruptEvent(int32_t zoneId, const std::string &deviceTag, - const std::list> &interrupts, - AudioZoneInterruptReason reason) +int32_t AudioZoneClient::OnInterruptEvent(int32_t zoneId, const std::string &deviceTag, + const std::vector> &ipcInterrupts, + int32_t reason) { + std::list> interrupts; + for (const auto& map : ipcInterrupts) { + for (const auto& [key, value] : map) { + interrupts.emplace_back(key, static_cast(value)); + } + } + std::string key = GetInterruptKeyId(zoneId, deviceTag); std::lock_guard lk(audioZoneInterruptMutex_); - CHECK_AND_RETURN_LOG(audioZoneInterruptCallbackMap_.find(key) != audioZoneInterruptCallbackMap_.end(), - "audioZoneInterruptCallbackMap_ not find key %{public}s.", key.c_str()); + CHECK_AND_RETURN_RET_LOG(audioZoneInterruptCallbackMap_.find(key) != audioZoneInterruptCallbackMap_.end(), + ERR_OPERATION_FAILED, "audioZoneInterruptCallbackMap_ not find key %{public}s.", key.c_str()); + CHECK_AND_RETURN_RET_LOG(audioZoneInterruptCallbackMap_[key] != nullptr, + ERR_OPERATION_FAILED, "audioZoneInterruptCallback is nullptr, key %{public}s.", key.c_str()); - audioZoneInterruptCallbackMap_[key]->OnInterruptEvent(interrupts, reason); + audioZoneInterruptCallbackMap_[key]->OnInterruptEvent(interrupts, + static_cast(reason)); + return SUCCESS; } -int32_t AudioZoneClient::SetSystemVolume(const int32_t zoneId, const AudioVolumeType volumeType, - const int32_t volumeLevel, const int32_t volumeFlag) +int32_t AudioZoneClient::SetSystemVolume(int32_t zoneId, int32_t volumeType, + int32_t volumeLevel, int32_t volumeFlag) { std::lock_guard lk(audioZoneVolumeProxyMutex_); CHECK_AND_RETURN_RET_LOG(audioZoneVolumeProxyMap_.find(zoneId) != audioZoneVolumeProxyMap_.end(), ERR_OPERATION_FAILED, "audioZoneVolumeProxyMap_ not find zoneId %{public}d.", zoneId); + CHECK_AND_RETURN_RET_LOG(audioZoneVolumeProxyMap_[zoneId] != nullptr, + ERR_OPERATION_FAILED, "audioZoneVolumeProxy is nullptr, zoneId %{public}d.", zoneId); - audioZoneVolumeProxyMap_[zoneId]->SetSystemVolume(volumeType, volumeLevel); + audioZoneVolumeProxyMap_[zoneId]->SetSystemVolume(static_cast(volumeType), + volumeLevel); return SUCCESS; } -int32_t AudioZoneClient::GetSystemVolume(int32_t zoneId, AudioVolumeType volumeType) +int32_t AudioZoneClient::GetSystemVolume(int32_t zoneId, int32_t volumeType, float &outVolume) { std::lock_guard lk(audioZoneVolumeProxyMutex_); CHECK_AND_RETURN_RET_LOG(audioZoneVolumeProxyMap_.find(zoneId) != audioZoneVolumeProxyMap_.end(), ERR_OPERATION_FAILED, "audioZoneVolumeProxyMap_ not find zoneId %{public}d.", zoneId); + CHECK_AND_RETURN_RET_LOG(audioZoneVolumeProxyMap_[zoneId] != nullptr, + ERR_OPERATION_FAILED, "audioZoneVolumeProxy is nullptr, zoneId %{public}d.", zoneId); - return audioZoneVolumeProxyMap_[zoneId]->GetSystemVolume(volumeType); + outVolume = audioZoneVolumeProxyMap_[zoneId]->GetSystemVolume(static_cast(volumeType)); + return SUCCESS; } } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_policy/client/stub/src/sle_audio_operation_callback_stub.cpp b/services/audio_policy/client/stub/src/sle_audio_operation_callback_stub_impl.cpp similarity index 39% rename from services/audio_policy/client/stub/src/sle_audio_operation_callback_stub.cpp rename to services/audio_policy/client/stub/src/sle_audio_operation_callback_stub_impl.cpp index b7815e0402..11f5849351 100644 --- a/services/audio_policy/client/stub/src/sle_audio_operation_callback_stub.cpp +++ b/services/audio_policy/client/stub/src/sle_audio_operation_callback_stub_impl.cpp @@ -14,10 +14,10 @@ */ #ifndef LOG_TAG -#define LOG_TAG "SleAudioOperationCallbackStub" +#define LOG_TAG "SleAudioOperationCallbackStubImpl" #endif -#include "sle_audio_operation_callback_stub.h" +#include "sle_audio_operation_callback_stub_impl.h" #include "audio_errors.h" #include "audio_policy_log.h" @@ -26,82 +26,15 @@ using namespace std; namespace OHOS { namespace AudioStandard { -SleAudioOperationCallbackStub::SleAudioOperationCallbackStub() +SleAudioOperationCallbackStubImpl::SleAudioOperationCallbackStubImpl() { } -SleAudioOperationCallbackStub::~SleAudioOperationCallbackStub() +SleAudioOperationCallbackStubImpl::~SleAudioOperationCallbackStubImpl() { } -int SleAudioOperationCallbackStub::OnRemoteRequest( - uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - CHECK_AND_RETURN_RET_LOG(data.ReadInterfaceToken() == GetDescriptor(), - -1, "SleAudioOperationCallbackStub: ReadInterfaceToken failed"); - switch (code) { - case GET_SLE_AUDIO_DEVICE_LIST: { - GetSleAudioDeviceListInternal(data, reply); - return AUDIO_OK; - } - case GET_SLE_VIRTUAL_AUDIO_DEVICE_LIST: { - GetSleVirtualAudioDeviceListInternal(data, reply); - return AUDIO_OK; - } - case IS_IN_BAND_RING_OPEN: { - IsInBandRingOpenInternal(data, reply); - return AUDIO_OK; - } - case GET_SUPPORT_STREAM_TYPE: { - GetSupportStreamTypeInternal(data, reply); - return AUDIO_OK; - } - case SET_ACTIVE_SINK_DEVICE: { - SetActiveSinkDeviceInternal(data, reply); - return AUDIO_OK; - } - case START_PLAYING: { - StartPlayingInternal(data, reply); - return AUDIO_OK; - } - case STOP_PLAYING: { - StopPlayingInternal(data, reply); - return AUDIO_OK; - } - case CONNECT_ALLOWED_PROFILES: { - ConnectAllowedProfilesInternal(data, reply); - return AUDIO_OK; - } - case SET_DEVICE_ABS_VOLUME: { - SetDeviceAbsVolumeInternal(data, reply); - return AUDIO_OK; - } - case SEND_USER_SELECTION: { - SendUserSelectionInternal(data, reply); - return AUDIO_OK; - } - default: { - return OnRemoteRequestSecondPartCode(code, data, reply, option); - } - } -} - -int SleAudioOperationCallbackStub::OnRemoteRequestSecondPartCode( - uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - switch (code) { - case GET_RENDER_POSITION: { - GetRenderPositionInternal(data, reply); - return AUDIO_OK; - } - default: { - AUDIO_ERR_LOG("default case, need check AudioListenerStub"); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } - } -} - -int32_t SleAudioOperationCallbackStub::SetSleAudioOperationCallback( +int32_t SleAudioOperationCallbackStubImpl::SetSleAudioOperationCallback( const std::weak_ptr &callback) { std::lock_guard lock(sleAudioOperationCallbackMutex_); @@ -112,128 +45,42 @@ int32_t SleAudioOperationCallbackStub::SetSleAudioOperationCallback( return SUCCESS; } -void SleAudioOperationCallbackStub::GetSleAudioDeviceListInternal(MessageParcel &data, MessageParcel &reply) -{ - std::vector devices; - GetSleAudioDeviceList(devices); - reply.WriteInt32(devices.size()); - for (auto &desc : devices) { - desc.Marshalling(reply); - } -} - -void SleAudioOperationCallbackStub::GetSleVirtualAudioDeviceListInternal(MessageParcel &data, MessageParcel &reply) -{ - std::vector devices; - GetSleVirtualAudioDeviceList(devices); - reply.WriteInt32(devices.size()); - for (auto &desc : devices) { - desc.Marshalling(reply); - } -} - -void SleAudioOperationCallbackStub::IsInBandRingOpenInternal(MessageParcel &data, MessageParcel &reply) -{ - std::string device = data.ReadString(); - int32_t result = IsInBandRingOpen(device); - reply.WriteInt32(result); -} - -void SleAudioOperationCallbackStub::GetSupportStreamTypeInternal(MessageParcel &data, MessageParcel &reply) -{ - std::string device = data.ReadString(); - uint32_t streamType = GetSupportStreamType(device); - reply.WriteUint32(streamType); -} - -void SleAudioOperationCallbackStub::SetActiveSinkDeviceInternal(MessageParcel &data, MessageParcel &reply) -{ - std::string device = data.ReadString(); - uint32_t streamType = data.ReadUint32(); - int32_t result = SetActiveSinkDevice(device, streamType); - reply.WriteInt32(result); -} - -void SleAudioOperationCallbackStub::StartPlayingInternal(MessageParcel &data, MessageParcel &reply) -{ - std::string device = data.ReadString(); - uint32_t streamType = data.ReadUint32(); - int32_t result = StartPlaying(device, streamType); - reply.WriteInt32(result); -} - -void SleAudioOperationCallbackStub::StopPlayingInternal(MessageParcel &data, MessageParcel &reply) -{ - std::string device = data.ReadString(); - uint32_t streamType = data.ReadUint32(); - int32_t result = StopPlaying(device, streamType); - reply.WriteInt32(result); -} - -void SleAudioOperationCallbackStub::ConnectAllowedProfilesInternal(MessageParcel &data, MessageParcel &reply) -{ - std::string remoteAddr = data.ReadString(); - int32_t result = ConnectAllowedProfiles(remoteAddr); - reply.WriteInt32(result); -} - -void SleAudioOperationCallbackStub::SetDeviceAbsVolumeInternal(MessageParcel &data, MessageParcel &reply) -{ - std::string remoteAddr = data.ReadString(); - uint32_t volume = data.ReadUint32(); - uint32_t streamType = data.ReadUint32(); - int32_t result = SetDeviceAbsVolume(remoteAddr, volume, streamType); - reply.WriteInt32(result); -} - -void SleAudioOperationCallbackStub::SendUserSelectionInternal(MessageParcel &data, MessageParcel &reply) -{ - std::string device = data.ReadString(); - uint32_t streamType = data.ReadUint32(); - int32_t result = SendUserSelection(device, streamType); - reply.WriteInt32(result); -} - -void SleAudioOperationCallbackStub::GetRenderPositionInternal(MessageParcel &data, MessageParcel &reply) -{ - std::string device = data.ReadString(); - uint32_t delayValue = 0; - int32_t result = GetRenderPosition(device, delayValue); - reply.WriteInt32(result); - reply.WriteUint32(delayValue); -} - -void SleAudioOperationCallbackStub::GetSleAudioDeviceList(std::vector &devices) +int32_t SleAudioOperationCallbackStubImpl::GetSleAudioDeviceList(std::vector &devices) { std::unique_lock lock(sleAudioOperationCallbackMutex_); std::shared_ptr sleAudioOperationCallback = sleAudioOperationCallback_.lock(); - CHECK_AND_RETURN_LOG(sleAudioOperationCallback != nullptr, "sleAudioOperationCallback_ is nullptr"); + CHECK_AND_RETURN_RET_LOG(sleAudioOperationCallback != nullptr, ERROR, + "sleAudioOperationCallback_ is nullptr"); lock.unlock(); sleAudioOperationCallback->GetSleAudioDeviceList(devices); + return SUCCESS; } -void SleAudioOperationCallbackStub::GetSleVirtualAudioDeviceList(std::vector &devices) +int32_t SleAudioOperationCallbackStubImpl::GetSleVirtualAudioDeviceList(std::vector &devices) { std::unique_lock lock(sleAudioOperationCallbackMutex_); std::shared_ptr sleAudioOperationCallback = sleAudioOperationCallback_.lock(); - CHECK_AND_RETURN_LOG(sleAudioOperationCallback != nullptr, "sleAudioOperationCallback_ is nullptr"); + CHECK_AND_RETURN_RET_LOG(sleAudioOperationCallback != nullptr, ERROR, + "sleAudioOperationCallback_ is nullptr"); lock.unlock(); sleAudioOperationCallback->GetSleVirtualAudioDeviceList(devices); + return SUCCESS; } -bool SleAudioOperationCallbackStub::IsInBandRingOpen(const std::string &device) +int32_t SleAudioOperationCallbackStubImpl::IsInBandRingOpen(const std::string &device, bool& ret) { std::unique_lock lock(sleAudioOperationCallbackMutex_); std::shared_ptr sleAudioOperationCallback = sleAudioOperationCallback_.lock(); CHECK_AND_RETURN_RET_LOG(sleAudioOperationCallback != nullptr, false, "sleAudioOperationCallback_ is nullptr"); lock.unlock(); - return sleAudioOperationCallback->IsInBandRingOpen(device); + ret = sleAudioOperationCallback->IsInBandRingOpen(device); + return SUCCESS; } -uint32_t SleAudioOperationCallbackStub::GetSupportStreamType(const std::string &device) +int32_t SleAudioOperationCallbackStubImpl::GetSupportStreamType(const std::string &device, uint32_t& retType) { uint32_t streamType = 0; std::unique_lock lock(sleAudioOperationCallbackMutex_); @@ -241,71 +88,80 @@ uint32_t SleAudioOperationCallbackStub::GetSupportStreamType(const std::string & CHECK_AND_RETURN_RET_LOG(sleAudioOperationCallback != nullptr, streamType, "sleAudioOperationCallback_ is nullptr"); lock.unlock(); - return sleAudioOperationCallback->GetSupportStreamType(device); + retType = sleAudioOperationCallback->GetSupportStreamType(device); + return SUCCESS; } -int32_t SleAudioOperationCallbackStub::SetActiveSinkDevice(const std::string &device, uint32_t streamType) +int32_t SleAudioOperationCallbackStubImpl::SetActiveSinkDevice( + const std::string &device, uint32_t streamType, int32_t& ret) { std::unique_lock lock(sleAudioOperationCallbackMutex_); std::shared_ptr sleAudioOperationCallback = sleAudioOperationCallback_.lock(); CHECK_AND_RETURN_RET_LOG(sleAudioOperationCallback != nullptr, ERROR, "sleAudioOperationCallback_ is nullptr"); lock.unlock(); - return sleAudioOperationCallback->SetActiveSinkDevice(device, streamType); + ret = sleAudioOperationCallback->SetActiveSinkDevice(device, streamType); + return SUCCESS; } -int32_t SleAudioOperationCallbackStub::StartPlaying(const std::string &device, uint32_t streamType) +int32_t SleAudioOperationCallbackStubImpl::StartPlaying(const std::string &device, uint32_t streamType, int32_t& ret) { std::unique_lock lock(sleAudioOperationCallbackMutex_); std::shared_ptr sleAudioOperationCallback = sleAudioOperationCallback_.lock(); CHECK_AND_RETURN_RET_LOG(sleAudioOperationCallback != nullptr, ERROR, "sleAudioOperationCallback_ is nullptr"); lock.unlock(); - return sleAudioOperationCallback->StartPlaying(device, streamType); + ret = sleAudioOperationCallback->StartPlaying(device, streamType); + return SUCCESS; } -int32_t SleAudioOperationCallbackStub::StopPlaying(const std::string &device, uint32_t streamType) +int32_t SleAudioOperationCallbackStubImpl::StopPlaying(const std::string &device, uint32_t streamType, int32_t& ret) { std::unique_lock lock(sleAudioOperationCallbackMutex_); std::shared_ptr sleAudioOperationCallback = sleAudioOperationCallback_.lock(); CHECK_AND_RETURN_RET_LOG(sleAudioOperationCallback != nullptr, ERROR, "sleAudioOperationCallback_ is nullptr"); lock.unlock(); - return sleAudioOperationCallback->StopPlaying(device, streamType); + ret = sleAudioOperationCallback->StopPlaying(device, streamType); + return SUCCESS; } -int32_t SleAudioOperationCallbackStub::ConnectAllowedProfiles(const std::string &remoteAddr) +int32_t SleAudioOperationCallbackStubImpl::ConnectAllowedProfiles(const std::string &remoteAddr, int32_t& ret) { std::unique_lock lock(sleAudioOperationCallbackMutex_); std::shared_ptr sleAudioOperationCallback = sleAudioOperationCallback_.lock(); CHECK_AND_RETURN_RET_LOG(sleAudioOperationCallback != nullptr, ERROR, "sleAudioOperationCallback_ is nullptr"); lock.unlock(); - return sleAudioOperationCallback->ConnectAllowedProfiles(remoteAddr); + ret = sleAudioOperationCallback->ConnectAllowedProfiles(remoteAddr); + return SUCCESS; } -int32_t SleAudioOperationCallbackStub::SetDeviceAbsVolume( - const std::string &remoteAddr, uint32_t volume, uint32_t streamType) +int32_t SleAudioOperationCallbackStubImpl::SetDeviceAbsVolume( + const std::string &remoteAddr, uint32_t volume, uint32_t streamType, int32_t& ret) { std::unique_lock lock(sleAudioOperationCallbackMutex_); std::shared_ptr sleAudioOperationCallback = sleAudioOperationCallback_.lock(); CHECK_AND_RETURN_RET_LOG(sleAudioOperationCallback != nullptr, ERROR, "sleAudioOperationCallback_ is nullptr"); lock.unlock(); - return sleAudioOperationCallback->SetDeviceAbsVolume(remoteAddr, volume, streamType); + ret = sleAudioOperationCallback->SetDeviceAbsVolume(remoteAddr, volume, streamType); + return SUCCESS; } -int32_t SleAudioOperationCallbackStub::SendUserSelection(const std::string &device, uint32_t streamType) +int32_t SleAudioOperationCallbackStubImpl::SendUserSelection(const std::string &device, uint32_t streamType, + int32_t &ret) { std::unique_lock lock(sleAudioOperationCallbackMutex_); std::shared_ptr sleAudioOperationCallback = sleAudioOperationCallback_.lock(); CHECK_AND_RETURN_RET_LOG(sleAudioOperationCallback != nullptr, ERROR, "sleAudioOperationCallback_ is nullptr"); lock.unlock(); - return sleAudioOperationCallback->SendUserSelection(device, streamType); + ret = sleAudioOperationCallback->SendUserSelection(device, streamType); + return SUCCESS; } -int32_t SleAudioOperationCallbackStub::GetRenderPosition(const std::string &device, uint32_t &delayValue) +int32_t SleAudioOperationCallbackStubImpl::GetRenderPosition(const std::string &device, uint32_t &delayValue) { std::unique_lock lock(sleAudioOperationCallbackMutex_); std::shared_ptr sleAudioOperationCallback = sleAudioOperationCallback_.lock(); @@ -314,5 +170,6 @@ int32_t SleAudioOperationCallbackStub::GetRenderPosition(const std::string &devi return sleAudioOperationCallback->GetRenderPosition(device, delayValue); } + } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_policy/common/include/audio_policy_ipc_interface_code.h b/services/audio_policy/common/include/audio_policy_ipc_interface_code.h index bd53a37250..7e505ec4cb 100644 --- a/services/audio_policy/common/include/audio_policy_ipc_interface_code.h +++ b/services/audio_policy/common/include/audio_policy_ipc_interface_code.h @@ -19,6 +19,7 @@ /* SAID: 3009 */ namespace OHOS { namespace AudioStandard { +// WARNING: below functions correspond with IAudioPolicy.idl enum class AudioPolicyInterfaceCode { GET_MAX_VOLUMELEVEL, GET_MIN_VOLUMELEVEL, @@ -71,8 +72,6 @@ enum class AudioPolicyInterfaceCode { GET_SELECTED_DEVICE_INFO, SELECT_INPUT_DEVICE, RECONFIGURE_CHANNEL, - GET_AUDIO_LATENCY, - GET_SINK_LATENCY, GET_PREFERRED_OUTPUT_STREAM_TYPE, GET_PREFERRED_INPUT_STREAM_TYPE, CREATE_RENDERER_CLIENT, @@ -88,11 +87,8 @@ enum class AudioPolicyInterfaceCode { GET_SINGLE_STREAM_VOLUME, GET_VOLUME_GROUP_INFO, GET_NETWORKID_BY_GROUP_ID, -#ifdef FEATURE_DTMF_TONE GET_TONEINFO, GET_SUPPORTED_TONES, -#endif - IS_AUDIO_RENDER_LOW_LATENCY_SUPPORTED, GET_ACTIVE_OUTPUT_DEVICE_DESCRIPTORS, GET_PREFERRED_INTPUT_DEVICE_DESCRIPTORS, SET_CALLBACKS_ENABLE, @@ -198,7 +194,6 @@ enum class AudioPolicyInterfaceCode { IS_AUDIO_SESSION_ACTIVATED, SET_INPUT_DEVICE, LOAD_SPLIT_MODULE, - SET_DEFAULT_OUTPUT_DEVICE, GET_SYSTEM_ACTIVEVOLUME_TYPE, GET_OUTPUT_DEVICE, GET_INPUT_DEVICE, @@ -251,7 +246,12 @@ enum class AudioPolicyInterfaceCode { SET_AUDIO_SESSION_SCENE, GET_SESSION_DEFAULT_OUTPUT_DEVICE, SET_SESSION_DEFAULT_OUTPUT_DEVICE, - AUDIO_POLICY_MANAGER_CODE_MAX = SET_SESSION_DEFAULT_OUTPUT_DEVICE, + // New ipc code needs to be added before that + GET_AUDIO_LATENCY, // deprecated + GET_SINK_LATENCY, // deprecated + IS_AUDIO_RENDER_LOW_LATENCY_SUPPORTED, // deprecated + SET_DEFAULT_OUTPUT_DEVICE, // deprecated + AUDIO_POLICY_MANAGER_CODE_MAX = SET_DEFAULT_OUTPUT_DEVICE, }; } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_policy/common/include/i_standard_sle_audio_operation_callback.h b/services/audio_policy/common/include/i_standard_sle_audio_operation_callback.h deleted file mode 100644 index 7a9ddb7807..0000000000 --- a/services/audio_policy/common/include/i_standard_sle_audio_operation_callback.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef I_STANDARD_SLE_AUDIO_OPERATION_CALLBACK_H -#define I_STANDARD_SLE_AUDIO_OPERATION_CALLBACK_H - -#include "ipc_types.h" -#include "iremote_broker.h" -#include "iremote_proxy.h" -#include "iremote_stub.h" - -namespace OHOS { -namespace AudioStandard { -class IStandardSleAudioOperationCallback : public IRemoteBroker { -public: - virtual ~IStandardSleAudioOperationCallback() = default; - - virtual void GetSleAudioDeviceList(std::vector &devices) = 0; - virtual void GetSleVirtualAudioDeviceList(std::vector &devices) = 0; - virtual bool IsInBandRingOpen(const std::string &device) = 0; - virtual uint32_t GetSupportStreamType(const std::string &device) = 0; - virtual int32_t SetActiveSinkDevice(const std::string &device, uint32_t streamType) = 0; - virtual int32_t StartPlaying(const std::string &device, uint32_t streamType) = 0; - virtual int32_t StopPlaying(const std::string &device, uint32_t streamType) = 0; - virtual int32_t ConnectAllowedProfiles(const std::string &remoteAddr) = 0; - virtual int32_t SetDeviceAbsVolume(const std::string &remoteAddr, uint32_t volume, uint32_t streamType) = 0; - virtual int32_t SendUserSelection(const std::string &device, uint32_t streamType) = 0; - virtual int32_t GetRenderPosition(const std::string &device, uint32_t &delayValue) = 0; - - enum AudioSleAudioOperationCallbackMsg { - ON_ERROR = 0, - GET_SLE_AUDIO_DEVICE_LIST, - GET_SLE_VIRTUAL_AUDIO_DEVICE_LIST, - IS_IN_BAND_RING_OPEN, - GET_SUPPORT_STREAM_TYPE, - SET_ACTIVE_SINK_DEVICE, - START_PLAYING, - STOP_PLAYING, - CONNECT_ALLOWED_PROFILES, - SET_DEVICE_ABS_VOLUME, - SEND_USER_SELECTION, - GET_RENDER_POSITION, - }; - - DECLARE_INTERFACE_DESCRIPTOR(u"IStandardSleAudioOperationCallback"); -}; -} // namespace AudioStandard -} // namespace OHOS -#endif // I_STANDARD_SLE_AUDIO_OPERATION_CALLBACK_H diff --git a/services/audio_policy/idl/IAudioPolicy.idl b/services/audio_policy/idl/IAudioPolicy.idl new file mode 100644 index 0000000000..4ae0492848 --- /dev/null +++ b/services/audio_policy/idl/IAudioPolicy.idl @@ -0,0 +1,294 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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. + */ + +package OHOS.AudioStandard; + +sequenceable OHOS.IRemoteObject; +sequenceable audio_info..OHOS.AudioStandard.AudioRendererInfo; +sequenceable audio_info..OHOS.AudioStandard.AudioCapturerInfo; +sequenceable audio_stream_info..OHOS.AudioStandard.AudioStreamInfo; +sequenceable audio_device_descriptor..OHOS.AudioStandard.AudioDeviceDescriptor; +sequenceable audio_system_manager..OHOS.AudioStandard.AudioRendererFilter; +sequenceable audio_system_manager..OHOS.AudioStandard.AudioCapturerFilter; +sequenceable audio_interrupt_info..OHOS.AudioStandard.AudioInterrupt; +sequenceable audio_stream_descriptor..OHOS.AudioStandard.AudioStreamDescriptor; +sequenceable audio_stream_change_info..OHOS.AudioStandard.AudioStreamChangeInfo; +sequenceable audio_stream_change_info..OHOS.AudioStandard.AudioRendererChangeInfo; +sequenceable audio_stream_change_info..OHOS.AudioStandard.AudioCapturerChangeInfo; +sequenceable audio_system_manager..OHOS.AudioStandard.VolumeGroupInfo; +sequenceable audio_effect..OHOS.AudioStandard.SupportedEffectConfig; +sequenceable microphone_descriptor..OHOS.AudioStandard.MicrophoneDescriptor; +sequenceable audio_effect..OHOS.AudioStandard.AudioSpatializationState; +sequenceable audio_effect..OHOS.AudioStandard.AudioSpatialDeviceState; +sequenceable audio_zone_info..OHOS.AudioStandard.AudioZoneContext; +sequenceable audio_zone_info..OHOS.AudioStandard.AudioZoneDescriptor; +sequenceable audio_effect..OHOS.AudioStandard.ConverterConfig; +sequenceable audio_device_info..OHOS.AudioStandard.AudioStreamDeviceChangeReasonExt; +sequenceable audio_interrupt_info..OHOS.AudioStandard.InterruptEvent; +sequenceable audio_effect..OHOS.AudioStandard.AudioEffectPropertyArrayV3; +sequenceable audio_effect..OHOS.AudioStandard.AudioEffectPropertyArray; +sequenceable audio_effect..OHOS.AudioStandard.AudioEnhancePropertyArray; +sequenceable audio_info..OHOS.AudioStandard.ToneInfo; +sequenceable audio_zone_info..OHOS.AudioStandard.AudioZoneStream; + +interface IAudioPolicy { + [ipccode 0] void GetMaxVolumeLevel([in] int volumeType, [out] int volumeLevel); + void GetMinVolumeLevel([in] int volumeType, [out] int volumeLevel); // AudioVolumeType volumeType + void SetSystemVolumeLevelLegacy([in] int streamTypeIn, [in] int volumeLevel); // AudioVolumeType volumeType + void SetSystemVolumeLevel( + [in] int volumeType, /* volumeType type is AudioVolumeType */ + [in] int volumeLevel, + [in] int volumeFlag, /* volumeFlag default 0 */ + [in] int uid /* uid default 0 */); + void SetAppVolumeLevel([in] int appUid, [in] int volumeLevel, [in] int volumeFlag); /*volumeFlag default 0*/ + void SetAppVolumeMuted([in] int appUid, [in] boolean muted, [in] int volumeFlag); /*volumeFlag default 0*/ + void SetAdjustVolumeForZone([in] int zoneId); + void IsAppVolumeMute([in] int appUid, [in] boolean muted, [out] boolean isMute); + void SetSelfAppVolumeLevel([in] int volumeLevel, [in] int volumeFlag); /*volumeFlag default 0*/ + void SetSystemVolumeLevelWithDevice([in] int volumeType, [in] int volumeLevel, [in] int deviceType, [in] int volumeFlag); /*volumeFlag default 0, DeviceType deviceType*/ + void GetSystemVolumeLevel( + [in] int volumeType, /* volumeType type is AudioVolumeType */ + [in] int uid, + [out] int volumeLevel); + void GetAppVolumeLevel([in] int appUid, [out] int volumeLevel); + void GetSelfAppVolumeLevel([out] int volumeLevel); + void SetStreamMuteLegacy([in] int volumeType, [in] boolean mute, [in] int deviceType); /*deviceType default DEVICE_TYPE_NONE, AudioVolumeType volumeType*/ + void SetStreamMute([in] int volumeType, [in] boolean mute, [in] int deviceType); /*deviceType default DEVICE_TYPE_NONE*/ + void GetStreamMute([in] int volumeType, [out] boolean retMute); + void IsStreamActive([in] int volumeType, [out] boolean retActive); + void IsStreamActiveByStreamUsage([in] int streamUsage, [out] boolean active); + void SetDeviceActive([in] int deviceType, [in] boolean active, [in] int uid); /*uid default INVALID_UID*/ + void IsDeviceActive([in] int deviceType, [out] boolean retActive); + void GetActiveOutputDevice([out] int retDeviceType); + void GetActiveInputDevice([out] int deviceType); + void SetRingerModeLegacy([in] int ringMode); + void SetRingerMode([in] int ringMode); + void GetRingerMode([out] int retRingMode); + void SetAudioScene([in] int scene); + void GetAudioScene([out] int retScene); + void SetMicrophoneMute([in] boolean isMute); + void SetMicrophoneMuteAudioConfig([in] boolean isMute); + void IsMicrophoneMuteLegacy([out] boolean retIsMute); + void IsMicrophoneMute([out] boolean retIsMute); + void SetAudioInterruptCallback([in] unsigned int sessionID, [in] IRemoteObject object, [in] unsigned int clientUid, [in] int zoneId); /* zoneID default value: 0 -- local device */ + void UnsetAudioInterruptCallback([in] unsigned int sessionID, [in] int zoneID); + void SetQueryClientTypeCallback([in] IRemoteObject object); + void SetAudioClientInfoMgrCallback([in] IRemoteObject object); + void SetAudioVKBInfoMgrCallback([in] IRemoteObject object); + void CheckVKBInfo([in] String bundleName, [out] boolean isValid); + void SetQueryBundleNameListCallback([in] IRemoteObject object); + void ActivateAudioInterrupt([in] AudioInterrupt audioInterrupt, [in] int zoneID, [in] boolean isUpdatedAudioStrategy); + void DeactivateAudioInterrupt([in] AudioInterrupt audioInterrupt, [in] int zoneId); /* zoneID default value: 0 -- local device */ + void SetAudioManagerInterruptCallback([in] int clientId, [in] IRemoteObject object); + void UnsetAudioManagerInterruptCallback([in] int clientId); + void RequestAudioFocus([in] int clientId, [in] AudioInterrupt audioInterrupt); + void AbandonAudioFocus([in] int clientId, [in] AudioInterrupt audioInterrupt); + void GetStreamInFocus( + [in] int zoneId, /* zoneID default value: 0 -- local device */ + [out] int retStreamType /* AudioStreamType */); + void GetSessionInfoInFocus( + [out] AudioInterrupt audioInterrupt, + [in] int zoneId /* zoneID default value: 0 -- local device */); + void GetDevices([in] int deviceFlag, [out] List> retDevicesList); + void SelectOutputDevice([in] sptr audioRendererFilter, [in] List> audioDeviceDescriptors); + void GetSelectedDeviceInfo([in] int uid, [in] int pid, [in] int streamType, [out] String retStr); + void SelectInputDevice([in] sptr audioCapturerFilter, [in] List> audioDeviceDescriptors); + void ReconfigureAudioChannel([in] unsigned int count, [in] int deviceType); + void GetPreferredOutputStreamType([in] AudioRendererInfo rendererInfo, [out] int streamType); + void GetPreferredInputStreamType([in] AudioCapturerInfo capturerInfo, [out] int streamType); + void CreateRendererClient([in] sharedptr streamDesc, [out] unsigned int flag, [out] unsigned int sessionId); + void CreateCapturerClient([in] sharedptr streamDesc, [out] unsigned int flag, [out] unsigned int sessionId); + void RegisterTracker([in] int mode, [in] AudioStreamChangeInfo streamChangeInfo, [in] IRemoteObject object); + void UpdateTracker([in] int mode, [in] AudioStreamChangeInfo streamChangeInfo); + void GetCurrentRendererChangeInfos([out] List> audioRendererChangeInfos); + void GetCurrentCapturerChangeInfos([out] List> audioCapturerChangeInfos); + void SetLowPowerVolume([in] int streamId, [in] float volume); + void GetFastStreamInfo([out] AudioStreamInfo streamInfo); + void GetLowPowerVolume([in] int streamId, [out] float retVolume); + void UpdateStreamState([in] int clientUid, [in] int streamSetState, [in] int streamUsage); + void GetSingleStreamVolume([in] int streamId, [out] float retVolume); + void GetVolumeGroupInfos([in] String networkId, [out] List> infos); + void GetNetworkIdByGroupId([in] int groupId, [out] String networkId); + void GetToneConfig([in] int ltonetype, [in] String countryCode, [out] sharedptr config); // [macrodef FEATURE_DTMF_TONE] + void GetSupportedTones([in] String countryCode, [out] List tones); // [macrodef FEATURE_DTMF_TONE] + void GetPreferredOutputDeviceDescriptors([in] AudioRendererInfo rendererInfo, [in] boolean forceNoBTPermission, [out] List> retDevList); + void GetPreferredInputDeviceDescriptors([in] AudioCapturerInfo captureInfo, [out] List> retDevList); + void SetClientCallbacksEnable([in] int callbackchange, [in] boolean enable); + void GetAudioFocusInfoList([out] List> focusInfoList, [in] int zoneId); /* zoneID default value: 0 -- local device */ + void SetSystemSoundUri([in] String key, [in] String uri); + void GetSystemSoundUri([in] String key, [out] String retUri); + void GetMinStreamVolume([out] float retVolume); + void GetMaxStreamVolume([out] float retVolume); + void GetMaxRendererInstances([out] int ret); + void IsVolumeUnadjustable([out] boolean retIsUnadjustable); + void AdjustVolumeByStep([in] int adjustType); + void AdjustSystemVolumeByStep([in] int volumeType, [in] int adjustType); + void GetSystemVolumeInDb([in] int volumeType, [in] int volumeLevel, [in] int deviceType, [out] float retVolume); + void QueryEffectSceneMode([out] SupportedEffectConfig supportedEffectConfig); + void GetHardwareOutputSamplingRate([in] sharedptr desc, [out] int ret); + void GetAudioCapturerMicrophoneDescriptors([in] int sessionId, [out] List> retMicList); + void GetAvailableMicrophones([out] List> retMicList); + void SetDeviceAbsVolumeSupported([in] String macAddress, [in] boolean support); + void IsAbsVolumeScene([out] boolean retVolume); + void SetA2dpDeviceVolume([in] String macAddress, [in] int volume, [in] boolean updateUi); + void SetNearlinkDeviceVolume([in] String macAddress, [in] int volumeType, [in] int volume, [in] boolean updateUi); + void GetAvailableDevices([in] int usage, [out] List> retDeviceList); + void SetAvailableDeviceChangeCallback([in] int clientId, [in] int usage, [in] IRemoteObject object); + void UnsetAvailableDeviceChangeCallback([in] int clientId, [in] int usage); + void IsSpatializationEnabled([out] boolean ret); + void IsSpatializationEnabled([in] String address, [out] boolean ret); + void SetSpatializationEnabled([in] boolean enable); + void SetSpatializationEnabled([in] sharedptr selectedAudioDevice, [in] boolean enable); + void IsHeadTrackingEnabled([out] boolean ret); + void IsHeadTrackingEnabled([in] String address, [out] boolean ret); + void SetHeadTrackingEnabled([in] boolean enable); + void SetHeadTrackingEnabled([in] sharedptr selectedAudioDevice, [in] boolean enable); + void GetSpatializationState([in] int streamUsage, [out] AudioSpatializationState retState); + void IsSpatializationSupported([out] boolean ret); + void IsSpatializationSupportedForDevice([in] String address, [out] boolean ret); + void IsHeadTrackingSupported([out] boolean ret); + void IsHeadTrackingSupportedForDevice([in] String address, [out] boolean ret); + void UpdateSpatialDeviceState([in] AudioSpatialDeviceState audioSpatialDeviceState); + void RegisterSpatializationStateEventListener([in] unsigned int sessionID, [in] int streamUsage, [in] IRemoteObject object); + void ConfigDistributedRoutingRole([in] sharedptr descriptor, [in] int type); + void SetDistributedRoutingRoleCallback([in] IRemoteObject object); + void UnsetDistributedRoutingRoleCallback(); + void UnregisterSpatializationStateEventListener([in] unsigned int sessionID); + void RegisterPolicyCallbackClient( + [in] IRemoteObject object, + [in] int zoneID /* default value: 0 -- local device */); + void CreateAudioInterruptZone( + [in] Set pids, + [in] int zoneID /* default value: 0 -- local device */); + void AddAudioInterruptZonePids( + [in] Set pids, + [in] int zoneID /* default value: 0 -- local device */); + void RemoveAudioInterruptZonePids( + [in] Set pids, + [in] int zoneID /* default value: 0 -- local device */); + void ReleaseAudioInterruptZone([in] int zoneId /* default value: 0 -- local device */); + void RegisterAudioZoneClient([in] IRemoteObject object); + void CreateAudioZone([in] String name, [in] AudioZoneContext context, [out] int zoneId); + void ReleaseAudioZone([in] int zoneId); + void GetAllAudioZone([out] List> retZoneDesc); + void GetAudioZone([in] int zoneId, [out] sharedptr desc); + void BindDeviceToAudioZone([in] int zoneId, [in] List> devices); + void UnBindDeviceToAudioZone([in] int zoneId, [in] List> devices); + void EnableAudioZoneReport([in] boolean enable); + void EnableAudioZoneChangeReport([in] int zoneId, [in] boolean enable); + void AddUidToAudioZone([in] int zoneId, [in] int uid); + void RemoveUidFromAudioZone([in] int zoneId, [in] int uid); + void AddStreamToAudioZone([in] int zoneId, [in] AudioZoneStream stream); + void RemoveStreamFromAudioZone([in] int zoneId, [in] AudioZoneStream stream); + void SetZoneDeviceVisible([in] boolean visible); + void EnableSystemVolumeProxy([in] int zoneId, [in] boolean enable); + void GetAudioInterruptForZone([in] int zoneId, [out] List> interrupts); + void GetAudioInterruptForZone([in] int zoneId, [in] String deviceTag, [out] List> interrupts); + void EnableAudioZoneInterruptReport([in] int zoneId, [in] String deviceTag, [in] boolean enable); + void InjectInterruptToAudioZone([in] int zoneId, [in] List> interrupts); + void InjectInterruptToAudioZone([in] int zoneId, [in] String deviceTag, [in] List> interrupts); + void SetCallDeviceActive([in] int deviceType, [in] boolean active, [in] String address, [in] int uid); + void GetConverterConfig([out] ConverterConfig retCnf); + void GetActiveBluetoothDevice([out] sharedptr descs); + void FetchOutputDeviceForTrack([in] AudioStreamChangeInfo streamChangeInfo, [in] AudioStreamDeviceChangeReasonExt reason); + void FetchInputDeviceForTrack([in] AudioStreamChangeInfo streamChangeInfo); + void IsHighResolutionExist([out] boolean ret); + void SetHighResolutionExist([in] boolean highResExist); + void GetSpatializationSceneType([out] int type); + void SetSpatializationSceneType([in] int spatializationSceneType); + void GetMaxAmplitude([in] int deviceId, [out] float retMaxAmplitude); + void IsHeadTrackingDataRequested([in] String macAddress, [out] boolean ret); + void SetAudioDeviceRefinerCallback([in] IRemoteObject object); + void UnsetAudioDeviceRefinerCallback(); + void TriggerFetchDevice([in] AudioStreamDeviceChangeReasonExt reason); + void MoveToNewPipe([in] unsigned int sessionId, [in] int pipeType); + void DisableSafeMediaVolume(); + void GetDevicesInner([in] int deviceFlag, [out] List> retDevicesList); + void SetAudioConcurrencyCallback([in] unsigned int sessionID, [in] IRemoteObject object); + void UnsetAudioConcurrencyCallback([in] unsigned int sessionID); + void ActivateAudioConcurrency([in] int pipeType); + void SetMicrophoneMutePersistent([in] boolean isMute, [in] int type); + void GetPersistentMicMuteState([out] boolean retMuteState); + void GetSupportedAudioEffectProperty([out] AudioEffectPropertyArrayV3 propertyArray); + void GetAudioEffectProperty([out] AudioEffectPropertyArrayV3 propertyArray); + void SetAudioEffectProperty([in] AudioEffectPropertyArrayV3 propertyArray); + void GetSupportedAudioEnhanceProperty([out] AudioEnhancePropertyArray propertyArray); + void GetSupportedAudioEffectProperty([out] AudioEffectPropertyArray propertyArray); + void GetAudioEnhanceProperty([out] AudioEnhancePropertyArray propertyArray); + void GetAudioEffectProperty([out] AudioEffectPropertyArray propertyArray); + void SetAudioEnhanceProperty([in] AudioEnhancePropertyArray propertyArray); + void SetAudioEffectProperty([in] AudioEffectPropertyArray propertyArray); + void InjectInterruption([in] String networkId, [in] InterruptEvent event); + void ActivateAudioSession([in] int strategy); + void DeactivateAudioSession(); + void IsAudioSessionActivated([out] boolean retIsActivated); + void SetInputDevice([in] int deviceType, [in] unsigned int session_ID, [in] int sourceType, [in] boolean isRunning); + void LoadSplitModule([in] String splitArgs, [in] String networkId); + void GetSystemActiveVolumeType([in] int clientUid, [out] int audioStreamType); // AudioStreamType audioStreamType + void GetOutputDevice([in] sptr audioRendererFilter, [out] List> retDevicesList); + void GetInputDevice([in] sptr audioCapturerFilter, [out] List> retDevicesList); + void SetAudioDeviceAnahsCallback([in] IRemoteObject object); + void UnsetAudioDeviceAnahsCallback(); + void IsAllowedPlayback([in] int uid, [in] int pid, [out] boolean isAllowed); + void SetVoiceRingtoneMute([in] boolean isMute); + void SetCallbackRendererInfo([in] AudioRendererInfo rendererInfo); + void SetCallbackCapturerInfo([in] AudioCapturerInfo capturerInfo); + void GetStreamInFocusByUid([in] int uid, [in] int zoneId, [out] int retStreamType); /* zoneID default value: 0 -- local device */ + void SetPreferredDevice([in] int preferredType, [in] sharedptr desc, [in] int uid); + void SaveRemoteInfo([in] String networkId, [in] int deviceType); + void SetVirtualCall([in] boolean isVirtual); + void SetDeviceConnectionStatus([in] sharedptr desc, [in] boolean isConnected); + void ExcludeOutputDevices([in] int audioDevUsage, [in] List> audioDeviceDescriptors); + void UnexcludeOutputDevices([in] int audioDevUsage, [in] List> audioDeviceDescriptors); + void GetExcludedDevices([in] int audioDevUsage, [out] List> retDevList); + void IsSpatializationEnabledForCurrentDevice([out] boolean ret); + void SetQueryAllowedPlaybackCallback([in] IRemoteObject object); + void ActivatePreemptMode(); + void DeactivatePreemptMode(); + void IsFastPlaybackSupported([in] AudioStreamInfo streamInfo, [in] int usage, [out] boolean retSupported); + void IsFastRecordingSupported([in] AudioStreamInfo streamInfo, [in] int source, [out] boolean retSupported); + void GetDmDeviceType([out] unsigned short retDeviceType); + void GetDirectPlaybackSupport([in] AudioStreamInfo streamInfo, [in] int streamUsage, [out] int retMode); + void NotifySessionStateChange([in] int uid, [in] int pid, [in] boolean hasSession); + void NotifyFreezeStateChange([in] Set pidList, [in] boolean isFreeze); + void ResetAllProxy(); + void NotifyProcessBackgroundState([in] int uid, [in] int pid); + void SetBackgroundMuteCallback([in] IRemoteObject object); + void IsAcousticEchoCancelerSupported([in] int sourceType, [out] boolean ret); + void ForceStopAudioStream([in] int audioType); + void IsCapturerFocusAvailable([in] AudioCapturerInfo capturerInfo, [out] boolean ret); + void GetMaxVolumeLevelByUsage([in] int streamUsage, [out] int retMaxVolumeLevel); + void GetMinVolumeLevelByUsage([in] int streamUsage, [out] int retMinVolumeLevel); + void GetVolumeLevelByUsage([in] int streamUsage, [out] int retVolumeLevel); + void GetStreamMuteByUsage([in] int streamUsage, [out] boolean isMute); + void GetVolumeInDbByStream([in] int streamUsage, [in] int volumeLevel, [in] int deviceType, [out] float ret); + void GetSupportedAudioVolumeTypes([out] List ret); + void GetAudioVolumeTypeByStreamUsage([in] int streamUsage, [out] int volumeType); + void GetStreamUsagesByVolumeType([in] int audioVolumeType, [out] List ret); + void SetCallbackStreamUsageInfo([in] Set streamUsages); + void UpdateDeviceInfo([in] sharedptr deviceDesc, [in] int command); + void SetSleAudioOperationCallback([in] IRemoteObject object); + void SetKaraokeParameters([in] String parameters, [out] boolean ret); + void IsAudioLoopbackSupported([in] int mode, [out] boolean isSupported); + void SetCollaborativePlaybackEnabledForDevice([in] sharedptr selectedAudioDevice, [in] boolean enabled); + void IsCollaborativePlaybackSupported([out] boolean ret); + void IsCollaborativePlaybackEnabledForDevice([in] sharedptr selectedAudioDevice, [out] boolean enabled); + void SetAudioSessionScene([in] int audioSessionScene /* AudioSessionScene */); + void GetDefaultOutputDevice([out] int deviceType /* deviceType */); + void SetDefaultOutputDevice([in] int deviceType /* deviceType */); + + // WARNING: above functions correspond with AudioPolicyInterfaceCode +} + diff --git a/services/audio_policy/idl/IAudioPolicyClient.idl b/services/audio_policy/idl/IAudioPolicyClient.idl new file mode 100644 index 0000000000..a4da7335af --- /dev/null +++ b/services/audio_policy/idl/IAudioPolicyClient.idl @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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. + */ + +package OHOS.AudioStandard; + +sequenceable audio_info..OHOS.AudioStandard.VolumeEvent; +sequenceable audio_interrupt_info..OHOS.AudioStandard.AudioInterrupt; +sequenceable audio_policy_interface..OHOS.AudioStandard.DeviceChangeAction; +sequenceable audio_system_manager..OHOS.AudioStandard.MicrophoneBlockedInfo; +sequenceable audio_info..OHOS.AudioStandard.MicStateChangeEvent; +sequenceable audio_info..OHOS.AudioStandard.AudioRendererInfo; +sequenceable audio_info..OHOS.AudioStandard.AudioCapturerInfo; +sequenceable audio_device_descriptor..OHOS.AudioStandard.AudioDeviceDescriptor; +sequenceable audio_stream_change_info..OHOS.AudioStandard.AudioRendererChangeInfo; +sequenceable audio_stream_change_info..OHOS.AudioStandard.AudioCapturerChangeInfo; +sequenceable audio_device_info..OHOS.AudioStandard.AudioStreamDeviceChangeReasonExt; +sequenceable audio_info..OHOS.AudioStandard.StreamVolumeEvent; +interface IAudioPolicyClient { + [ipccode 0, customMsgOption flags=MessageOption::TF_ASYNC_WAKEUP_LATER | MessageOption::TF_ASYNC] + void OnVolumeKeyEvent([in] VolumeEvent volumeEvent); + [oneway] void OnAudioFocusInfoChange([in] List> focusInfoList); // const std::list> &focusInfoList + [oneway] void OnAudioFocusRequested([in] AudioInterrupt requestFocus); + [oneway] void OnAudioFocusAbandoned([in] AudioInterrupt abandonFocus); + [customMsgOption flags=MessageOption::TF_ASYNC_WAKEUP_LATER | MessageOption::TF_ASYNC] + void OnDeviceChange([in] DeviceChangeAction deviceChangeAction); + [oneway] void OnAppVolumeChanged([in] int appUid, [in] VolumeEvent volumeEvent); + [oneway] void OnActiveVolumeTypeChanged([in] int volumeType); // const AudioVolumeType& volumeType + [customMsgOption flags=MessageOption::TF_ASYNC_WAKEUP_LATER | MessageOption::TF_ASYNC] + void OnRingerModeUpdated([in] int ringerMode); // AudioRingerMode ringerMode + [customMsgOption flags=MessageOption::TF_ASYNC_WAKEUP_LATER | MessageOption::TF_ASYNC] + void OnMicStateUpdated([in] MicStateChangeEvent micStateChangeEvent); + [customMsgOption flags=MessageOption::TF_ASYNC_WAKEUP_LATER | MessageOption::TF_ASYNC] + void OnPreferredOutputDeviceUpdated([in] AudioRendererInfo rendererInfo, + [in] List> desc); // const std::vector> &desc + [customMsgOption flags=MessageOption::TF_ASYNC_WAKEUP_LATER | MessageOption::TF_ASYNC] + void OnPreferredInputDeviceUpdated([in] AudioCapturerInfo capturerInfo, + [in] List> desc); // const std::vector> &desc + [customMsgOption flags=MessageOption::TF_ASYNC_WAKEUP_LATER | MessageOption::TF_ASYNC] + void OnRendererStateChange([in] List> audioRendererChangeInfos); // std::vector> & + [customMsgOption flags=MessageOption::TF_ASYNC_WAKEUP_LATER | MessageOption::TF_ASYNC] + void OnCapturerStateChange([in] List> audioCapturerChangeInfos); // std::vector> & + [customMsgOption flags=MessageOption::TF_ASYNC_WAKEUP_LATER | MessageOption::TF_ASYNC] + void OnRendererDeviceChange([in] unsigned int sessionId, + [in] AudioDeviceDescriptor deviceInfo, [in] AudioStreamDeviceChangeReasonExt reason); + [oneway] void OnRecreateRendererStreamEvent([in] unsigned int sessionId, [in] int streamFlag, + [in] AudioStreamDeviceChangeReasonExt reason); + [oneway] void OnRecreateCapturerStreamEvent([in] unsigned int sessionId, [in] int streamFlag, + [in] AudioStreamDeviceChangeReasonExt reason); + [oneway] void OnHeadTrackingDeviceChange([in] Map changeInfo); // const std::unordered_map & + [customMsgOption flags=MessageOption::TF_ASYNC_WAKEUP_LATER | MessageOption::TF_ASYNC] + void OnSpatializationEnabledChange([in] boolean enabled); + [customMsgOption flags=MessageOption::TF_ASYNC_WAKEUP_LATER | MessageOption::TF_ASYNC] + void OnSpatializationEnabledChangeForAnyDevice( + [in] sharedptr deviceDescriptor, [in] boolean enabled); + [customMsgOption flags=MessageOption::TF_ASYNC_WAKEUP_LATER | MessageOption::TF_ASYNC] + void OnHeadTrackingEnabledChange([in] boolean enabled); + [customMsgOption flags=MessageOption::TF_ASYNC_WAKEUP_LATER | MessageOption::TF_ASYNC] + void OnHeadTrackingEnabledChangeForAnyDevice( + [in] sharedptr deviceDescriptor, [in] boolean enabled); + [oneway] void OnNnStateChange([in] int nnState); + [customMsgOption flags=MessageOption::TF_ASYNC_WAKEUP_LATER | MessageOption::TF_ASYNC] + void OnAudioSessionDeactive([in] int deactiveEvent); // AudioSessionDeactiveEvent deactiveEvent + [oneway] void OnMicrophoneBlocked([in] MicrophoneBlockedInfo microphoneBlockedInfo); + [oneway] void OnAudioSceneChange([in] int audioScene); // const AudioScene &audioScene + [customMsgOption flags=MessageOption::TF_ASYNC_WAKEUP_LATER | MessageOption::TF_ASYNC] + void OnSpatializationEnabledChangeForCurrentDevice([in] boolean enabled); + [oneway] void OnFormatUnsupportedError([in] int errorCode); // const AudioErrors &errorCode + [customMsgOption flags=MessageOption::TF_ASYNC_WAKEUP_LATER | MessageOption::TF_ASYNC] + void OnStreamVolumeChange([in]StreamVolumeEvent streamVolumeEvent); + [customMsgOption flags=MessageOption::TF_ASYNC_WAKEUP_LATER | MessageOption::TF_ASYNC] + void OnSystemVolumeChange([in] VolumeEvent volumeEvent); + [customMsgOption flags=MessageOption::TF_ASYNC_WAKEUP_LATER | MessageOption::TF_ASYNC] + void OnAudioSessionStateChanged([in] int stateChangeHint /* AudioSessionStateChangedEvent */); +} diff --git a/services/audio_policy/test/unittest/audio_policy_client_stub_unit_test/include/audio_policy_client_stub_unit_test.h b/services/audio_policy/idl/IAudioWorkgroupCallback.idl similarity index 47% rename from services/audio_policy/test/unittest/audio_policy_client_stub_unit_test/include/audio_policy_client_stub_unit_test.h rename to services/audio_policy/idl/IAudioWorkgroupCallback.idl index 3d5bc89100..a541586eaa 100644 --- a/services/audio_policy/test/unittest/audio_policy_client_stub_unit_test/include/audio_policy_client_stub_unit_test.h +++ b/services/audio_policy/idl/IAudioWorkgroupCallback.idl @@ -13,26 +13,10 @@ * limitations under the License. */ -#ifndef AUDIO_POLICY_CLIENT_STUB_UNIT_TEST_H -#define AUDIO_POLICY_CLIENT_STUB_UNIT_TEST_H +package OHOS.AudioStandard; -#include "gtest/gtest.h" -#include "gmock/gmock.h" - -namespace OHOS { -namespace AudioStandard { - -class AudioPolicyClientStubUnitTest : public testing::Test { -public: - // SetUpTestCase: Called before all test cases - static void SetUpTestCase(void); - // TearDownTestCase: Called after all test case - static void TearDownTestCase(void); - // SetUp: Called before each test cases - void SetUp(void); - // TearDown: Called after each test cases - void TearDown(void); -}; -} // namespace AudioStandard -} // namespace OHOS -#endif //AUDIO_POLICY_CLIENT_STUB_UNIT_TEST_H \ No newline at end of file +sequenceable audio_workgroup_ipc..OHOS.AudioStandard.AudioWorkgroupChangeInfoIpc; +interface IAudioWorkgroupCallback { + [ipccode 1, oneway] + void OnWorkgroupChange([in] AudioWorkgroupChangeInfoIpc info); +} \ No newline at end of file diff --git a/services/audio_policy/test/unittest/audio_policy_client_proxy_unit_test/include/audio_policy_client_proxy_unit_test.h b/services/audio_policy/idl/IStandardAudioAnahsManagerListener.idl similarity index 47% rename from services/audio_policy/test/unittest/audio_policy_client_proxy_unit_test/include/audio_policy_client_proxy_unit_test.h rename to services/audio_policy/idl/IStandardAudioAnahsManagerListener.idl index b721832a79..2b520a203e 100644 --- a/services/audio_policy/test/unittest/audio_policy_client_proxy_unit_test/include/audio_policy_client_proxy_unit_test.h +++ b/services/audio_policy/idl/IStandardAudioAnahsManagerListener.idl @@ -13,26 +13,8 @@ * limitations under the License. */ -#ifndef AUDIO_POLICY_CLIENT_PROXY_UNIT_TEST_H -#define AUDIO_POLICY_CLIENT_PROXY_UNIT_TEST_H -#include "gtest/gtest.h" -#include "audio_policy_client_proxy.h" +package OHOS.AudioStandard; - -namespace OHOS { -namespace AudioStandard { - -class AudioPolicyClientProxyUnitTest : public testing::Test { -public: - // SetUpTestCase: Called before all test cases - static void SetUpTestCase(void); - // TearDownTestCase: Called after all test case - static void TearDownTestCase(void); - // SetUp: Called before each test cases - void SetUp(void); - // TearDown: Called after each test cases - void TearDown(void); -}; -} // namespace AudioStandard -} // namespace OHOS -#endif //AUDIO_POLICY_CLIENT_PROXY_UNIT_TEST_H \ No newline at end of file +interface IStandardAudioAnahsManagerListener { + [ipccode 1] void OnExtPnpDeviceStatusChanged([in] String anahsStatus, [in] String anahsShowType); +} diff --git a/services/audio_policy/idl/IStandardAudioPolicyManagerListener.idl b/services/audio_policy/idl/IStandardAudioPolicyManagerListener.idl new file mode 100644 index 0000000000..3c72b384df --- /dev/null +++ b/services/audio_policy/idl/IStandardAudioPolicyManagerListener.idl @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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. + */ + +package OHOS.AudioStandard; + +sequenceable audio_interrupt_info..OHOS.AudioStandard.InterruptEventInternal; +sequenceable audio_policy_interface..OHOS.AudioStandard.DeviceChangeAction; +interface IStandardAudioPolicyManagerListener { + [ipccode 1, oneway] void OnInterrupt([in] InterruptEventInternal interruptEvent); + [customMsgOption flags=MessageOption::TF_ASYNC_WAKEUP_LATER | MessageOption::TF_ASYNC] + void OnAvailableDeviceChange([in] unsigned int usage, [in] DeviceChangeAction deviceChangeAction); + void OnQueryClientType([in] String bundleName, [in] unsigned int uid, [out] boolean ret); + void OnCheckClientInfo([in] String bundleName, [out] int uid, [in] int pid, [out] boolean ret); + void OnCheckVKBInfo([in] String bundleName, [out] boolean isValid); + void OnQueryAllowedPlayback([in] int uid, [in] int pid, [out] boolean ret); + [oneway] void OnBackgroundMute([in] int uid); + void OnQueryBundleNameIsInList([in] String bundleName, [in] String listType, [out] boolean ret); +} diff --git a/services/audio_policy/test/unittest/audio_zone_unit_test/include/audio_policy_manager_zone_stub_unit_test.h b/services/audio_policy/idl/IStandardAudioRoutingManagerListener.idl similarity index 40% rename from services/audio_policy/test/unittest/audio_zone_unit_test/include/audio_policy_manager_zone_stub_unit_test.h rename to services/audio_policy/idl/IStandardAudioRoutingManagerListener.idl index e2caf33d47..aa2b99e094 100644 --- a/services/audio_policy/test/unittest/audio_zone_unit_test/include/audio_policy_manager_zone_stub_unit_test.h +++ b/services/audio_policy/idl/IStandardAudioRoutingManagerListener.idl @@ -13,32 +13,15 @@ * limitations under the License. */ -#ifndef AUDIO_POLICY_MANAGER_ZONE_STUB_UNIT_TEST_H -#define AUDIO_POLICY_MANAGER_ZONE_STUB_UNIT_TEST_H - -#include "gtest/gtest.h" -#include "audio_policy_manager_stub.h" -#include "audio_utils.h" - -namespace OHOS { -namespace AudioStandard { - -class AudioPolicyManagerZoneStubUnitTest : public testing::Test { -public: - // SetUpTestCase: Called before all test cases - static void SetUpTestCase(void); - // TearDownTestCase: Called after all test case - static void TearDownTestCase(void); - // SetUp: Called before each test cases - void SetUp(void); - // TearDown: Called after each test cases - void TearDown(void); +package OHOS.AudioStandard; - std::shared_ptr stub_ = nullptr; - MessageParcel data; - MessageParcel reply; - MessageOption option; -}; -} // namespace AudioStandard -} // namespace OHOS -#endif // AUDIO_POLICY_MANAGER_ZONE_STUB_UNIT_TEST_H \ No newline at end of file +sequenceable audio_device_descriptor..OHOS.AudioStandard.AudioDeviceDescriptor; +interface IStandardAudioRoutingManagerListener { + [ipccode 1] void OnDistributedRoutingRoleChange([in] sharedptr descriptor, [in] int type); // CastType type + void OnAudioOutputDeviceRefined([inout] List> descs, + [in] int routerType, [in] int streamUsage, [in] int clientUid, [in] int audioPipeType); // RouterType routerType, StreamUsage streamUsage, AudioPipeType audioPipeType + void OnAudioInputDeviceRefined([inout] List> descs, + [in] int routerType, [in] int sourceType, [in] int clientUid, [in] int audioPipeType); // SourceType sourceType, AudioPipeType audioPipeType + void GetSplitInfoRefined([out] String splitInfo); + void OnDistributedOutputChange([in] boolean isRemote); +} diff --git a/services/audio_policy/idl/IStandardAudioZoneClient.idl b/services/audio_policy/idl/IStandardAudioZoneClient.idl new file mode 100644 index 0000000000..7b0ec88658 --- /dev/null +++ b/services/audio_policy/idl/IStandardAudioZoneClient.idl @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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. + */ + +package OHOS.AudioStandard; + +sequenceable audio_zone_info..OHOS.AudioStandard.AudioZoneDescriptor; +sequenceable audio_interrupt_info..OHOS.AudioStandard.AudioInterrupt; +interface IStandardAudioZoneClient { + [ipccode 0] void OnAudioZoneAdd([in] AudioZoneDescriptor zoneDescriptor); + void OnAudioZoneRemove([in] int zoneId); + void OnAudioZoneChange([in] int zoneId, [in] AudioZoneDescriptor zoneDescriptor, + [in] int reason); // AudioZoneChangeReason reason + + void OnInterruptEvent([in] int zoneId, + [in] List> ipcInterrupts, // std::list> ==> List> + [in] int reason); // AudioZoneInterruptReason reason + + void OnInterruptEvent([in] int zoneId, [in] String deviceTag, + [in] List> ipcInterrupts, // std::list> ==> List> + [in] int reason); // AudioZoneInterruptReason reason + + void SetSystemVolume([in] int zoneId, [in] int volumeType, // AudioVolumeType volumeType + [in] int volumeLevel, [in] int volumeFlag); + + void GetSystemVolume([in] int zoneId, [in] int volumeType, [out] float outVolume); // AudioVolumeType volumeType +} diff --git a/services/audio_policy/idl/IStandardClientTracker.idl b/services/audio_policy/idl/IStandardClientTracker.idl new file mode 100644 index 0000000000..f2159fd776 --- /dev/null +++ b/services/audio_policy/idl/IStandardClientTracker.idl @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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. + */ + +package OHOS.AudioStandard; + +sequenceable audio_info..OHOS.AudioStandard.StreamSetStateEventInternal; +interface IStandardClientTracker { + [ipccode 2, oneway] void SetLowPowerVolumeImpl([in] float volume); + void GetLowPowerVolumeImpl([out] float volume); + [oneway] void PausedStreamImpl([in] StreamSetStateEventInternal streamSetStateEventInternal); + [oneway] void ResumeStreamImpl([in] StreamSetStateEventInternal streamSetStateEventInternal); + [oneway] void MuteStreamImpl([in] StreamSetStateEventInternal streamSetStateEventInternal); + [oneway] void UnmuteStreamImpl([in] StreamSetStateEventInternal streamSetStateEventInternal); + void GetSingleStreamVolumeImpl([out] float volume); + void SetOffloadModeImpl([in] int state, [in] boolean isAppBack); + void UnsetOffloadModeImpl(); +} diff --git a/services/audio_policy/idl/IStandardConcurrencyStateListener.idl b/services/audio_policy/idl/IStandardConcurrencyStateListener.idl new file mode 100644 index 0000000000..5212b46c67 --- /dev/null +++ b/services/audio_policy/idl/IStandardConcurrencyStateListener.idl @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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. + */ + +package OHOS.AudioStandard; +interface IStandardConcurrencyStateListener { + [ipccode 1, oneway] void OnConcedeStream(); +} diff --git a/services/audio_policy/test/unittest/audio_zone_unit_test/src/audio_zone_class_unit_test.cpp b/services/audio_policy/idl/IStandardSleAudioOperationCallback.idl similarity index 35% rename from services/audio_policy/test/unittest/audio_zone_unit_test/src/audio_zone_class_unit_test.cpp rename to services/audio_policy/idl/IStandardSleAudioOperationCallback.idl index a5706fc5e0..c37004fda9 100644 --- a/services/audio_policy/test/unittest/audio_zone_unit_test/src/audio_zone_class_unit_test.cpp +++ b/services/audio_policy/idl/IStandardSleAudioOperationCallback.idl @@ -13,37 +13,20 @@ * limitations under the License. */ -#include "audio_zone_class_unit_test.h" -#include "audio_errors.h" -#include "audio_policy_log.h" +package OHOS.AudioStandard; -#include -#include -#include -using namespace testing::ext; +sequenceable audio_device_descriptor..OHOS.AudioStandard.AudioDeviceDescriptor; -namespace OHOS { -namespace AudioStandard { - -void AudioZoneClassUnitTest::SetUpTestCase(void) {} -void AudioZoneClassUnitTest::TearDownTestCase(void) {} -void AudioZoneClassUnitTest::SetUp(void) {} -void AudioZoneClassUnitTest::TearDown(void) {} - -/** - * @tc.name : Test AudioZoneUnitTest. - * @tc.number: AudioZone_001 - * @tc.desc : Test EnableAudioZoneReport interface. - */ -HWTEST_F(AudioZoneClassUnitTest, AudioZone_001, TestSize.Level1) -{ - std::shared_ptr manager = - std::make_shared(DelayedSingleton::GetInstance()); - AudioZoneContext context; - std::shared_ptr zone = std::make_shared(manager, "", context); - EXPECT_EQ(zone->EnableChangeReport(0, true), SUCCESS); - EXPECT_EQ(zone->EnableChangeReport(0, false), SUCCESS); -} -} // namespace AudioStandard -} // namespace OHOS - \ No newline at end of file +interface IStandardSleAudioOperationCallback { + [ipccode 1] void GetSleAudioDeviceList([out] List devices); + void GetSleVirtualAudioDeviceList([out] List devices); + void IsInBandRingOpen([in] String device, [out] boolean ret); + void GetSupportStreamType([in] String device, [out] unsigned int retType); + void SetActiveSinkDevice([in] String device, [in] unsigned int streamType, [out] int ret); + void StartPlaying([in] String device, [in] unsigned int streamType, [out] int ret); + void StopPlaying([in] String device, [in] unsigned int streamType, [out] int ret); + void ConnectAllowedProfiles([in] String remoteAddr, [out] int ret); + void SetDeviceAbsVolume([in] String remoteAddr, [in] unsigned int volume, [in] unsigned int streamType, [out] int ret); + void SendUserSelection([in] String device, [in] unsigned int streamType, [out] int ret); + void GetRenderPosition([in] String device, [out] unsigned int delayValue); +} \ No newline at end of file diff --git a/services/audio_policy/idl/IStandardSpatializationStateChangeListener.idl b/services/audio_policy/idl/IStandardSpatializationStateChangeListener.idl new file mode 100644 index 0000000000..f3a199f001 --- /dev/null +++ b/services/audio_policy/idl/IStandardSpatializationStateChangeListener.idl @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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. + */ + +package OHOS.AudioStandard; +sequenceable audio_effect..OHOS.AudioStandard.AudioSpatializationState; +interface IStandardSpatializationStateChangeListener { + [ipccode 1, customMsgOption flags=MessageOption::TF_ASYNC_WAKEUP_LATER | MessageOption::TF_ASYNC] + void OnSpatializationStateChange([in] AudioSpatializationState spatializationState); +} diff --git a/services/audio_policy/server/domain/device/include/audio_connected_device.h b/services/audio_policy/server/domain/device/include/audio_connected_device.h index 33b6696bc4..16aead07c3 100644 --- a/services/audio_policy/server/domain/device/include/audio_connected_device.h +++ b/services/audio_policy/server/domain/device/include/audio_connected_device.h @@ -21,12 +21,14 @@ #include #include #include +#include #include "singleton.h" #include "audio_group_handle.h" #include "audio_manager_base.h" #include "audio_module_info.h" #include "audio_volume_config.h" #include "audio_errors.h" +#include "audio_device_descriptor.h" namespace OHOS { namespace AudioStandard { diff --git a/services/audio_policy/server/domain/device/include/audio_state_manager.h b/services/audio_policy/server/domain/device/include/audio_state_manager.h index b65c8b9e1a..e44ad7e105 100644 --- a/services/audio_policy/server/domain/device/include/audio_state_manager.h +++ b/services/audio_policy/server/domain/device/include/audio_state_manager.h @@ -19,7 +19,7 @@ #include #include #include "audio_system_manager.h" -#include "i_standard_audio_policy_manager_listener.h" +#include "istandard_audio_policy_manager_listener.h" namespace OHOS { namespace AudioStandard { diff --git a/services/audio_policy/server/domain/device/include/device_status_listener.h b/services/audio_policy/server/domain/device/include/device_status_listener.h index ea13401748..e6d11e0e86 100644 --- a/services/audio_policy/server/domain/device/include/device_status_listener.h +++ b/services/audio_policy/server/domain/device/include/device_status_listener.h @@ -25,8 +25,8 @@ #include "iremote_broker.h" #include "iremote_proxy.h" #include "iremote_stub.h" -#include "i_standard_audio_routing_manager_listener.h" -#include "i_standard_audio_anahs_manager_listener.h" +#include "istandard_audio_routing_manager_listener.h" +#include "istandard_audio_anahs_manager_listener.h" namespace OHOS { namespace AudioStandard { diff --git a/services/audio_policy/server/domain/device/src/audio_active_device.cpp b/services/audio_policy/server/domain/device/src/audio_active_device.cpp index f897b899f6..d645f3af2a 100644 --- a/services/audio_policy/server/domain/device/src/audio_active_device.cpp +++ b/services/audio_policy/server/domain/device/src/audio_active_device.cpp @@ -23,7 +23,6 @@ #include "parameter.h" #include "parameters.h" #include "audio_policy_log.h" -#include "audio_manager_listener_stub.h" #include "audio_inner_call.h" #include "media_monitor_manager.h" diff --git a/services/audio_policy/server/domain/device/src/audio_connected_device.cpp b/services/audio_policy/server/domain/device/src/audio_connected_device.cpp index 116f463d7c..705b63854e 100644 --- a/services/audio_policy/server/domain/device/src/audio_connected_device.cpp +++ b/services/audio_policy/server/domain/device/src/audio_connected_device.cpp @@ -22,7 +22,6 @@ #include "parameter.h" #include "parameters.h" #include "audio_policy_log.h" -#include "audio_manager_listener_stub.h" #include "audio_inner_call.h" #include "media_monitor_manager.h" #include "audio_spatialization_service.h" diff --git a/services/audio_policy/server/domain/device/src/audio_device_descriptor.cpp b/services/audio_policy/server/domain/device/src/audio_device_descriptor.cpp index 9cccb63a9e..a88966e28a 100644 --- a/services/audio_policy/server/domain/device/src/audio_device_descriptor.cpp +++ b/services/audio_policy/server/domain/device/src/audio_device_descriptor.cpp @@ -92,6 +92,24 @@ static void UnmarshallingDeviceStreamInfoList(Parcel &parcel, std::list &streamInfo) +{ + if (streamInfo.empty()) { + streamInfo.push_back(DEFAULT_DEVICE_STREAM_INFO); + } else { + for (auto &info : streamInfo) { + // If does not set sampleRates use SAMPLE_RATE_44100 instead. + if (info.samplingRate.empty()) { + info.samplingRate = DEFAULT_DEVICE_STREAM_INFO.samplingRate; + } + // If does not set channelCounts use STEREO instead. + if (info.channelLayout.empty()) { + info.channelLayout = DEFAULT_DEVICE_STREAM_INFO.channelLayout; + } + } + } +} + AudioDeviceDescriptor::AudioDeviceDescriptor(int32_t descriptorType) : AudioDeviceDescriptor(DeviceType::DEVICE_TYPE_NONE, DeviceRole::DEVICE_ROLE_NONE) { @@ -130,6 +148,11 @@ AudioDeviceDescriptor::AudioDeviceDescriptor(DeviceType type, DeviceRole role) isVrSupported_ = true; } +AudioDeviceDescriptor::~AudioDeviceDescriptor() +{ + pairDeviceDescriptor_ = nullptr; +} + AudioDeviceDescriptor::AudioDeviceDescriptor(DeviceType type, DeviceRole role, int32_t interruptGroupId, int32_t volumeGroupId, std::string networkId) : deviceType_(type), deviceRole_(role), interruptGroupId_(interruptGroupId), volumeGroupId_(volumeGroupId), @@ -221,11 +244,6 @@ AudioDeviceDescriptor::AudioDeviceDescriptor(const std::shared_ptrisVrSupported_; } -AudioDeviceDescriptor::~AudioDeviceDescriptor() -{ - pairDeviceDescriptor_ = nullptr; -} - DeviceType AudioDeviceDescriptor::getType() const { return deviceType_; @@ -246,85 +264,77 @@ bool AudioDeviceDescriptor::IsAudioDeviceDescriptor() const return descriptorType_ == AUDIO_DEVICE_DESCRIPTOR; } -bool AudioDeviceDescriptor::Marshalling(Parcel &parcel) const +void AudioDeviceDescriptor::SetClientInfo(std::shared_ptr clientInfo) const { - return Marshalling(parcel, 0); + clientInfo_ = clientInfo; } -bool AudioDeviceDescriptor::Marshalling(Parcel &parcel, int32_t apiVersion) const +bool AudioDeviceDescriptor::Marshalling(Parcel &parcel) const { - if (IsAudioDeviceDescriptor()) { - return MarshallingToDeviceDescriptor(parcel, apiVersion); + bool ret = MarshallingInner(parcel); + if (clientInfo_) { + clientInfo_ = nullptr; } - - return MarshallingToDeviceInfo(parcel); -} - -bool AudioDeviceDescriptor::MarshallingToDeviceDescriptor(Parcel &parcel, int32_t apiVersion) const -{ - parcel.WriteInt32(MapInternalToExternalDeviceType(apiVersion)); - parcel.WriteInt32(deviceRole_); - parcel.WriteInt32(deviceId_); - MarshallingDeviceStreamInfoList(audioStreamInfo_, parcel); - parcel.WriteInt32(channelMasks_); - parcel.WriteInt32(channelIndexMasks_); - parcel.WriteString(deviceName_); - parcel.WriteString(macAddress_); - parcel.WriteInt32(interruptGroupId_); - parcel.WriteInt32(volumeGroupId_); - parcel.WriteString(networkId_); - parcel.WriteUint16(dmDeviceType_); - parcel.WriteString(displayName_); - parcel.WriteInt32(deviceCategory_); - parcel.WriteInt32(connectState_); - parcel.WriteBool(spatializationSupported_); - parcel.WriteInt32(mediaVolume_); - parcel.WriteInt32(callVolume_); - return true; + return ret; } -bool AudioDeviceDescriptor::MarshallingToDeviceInfo(Parcel &parcel) const +bool AudioDeviceDescriptor::MarshallingInner(Parcel &parcel) const { - return parcel.WriteInt32(static_cast(deviceType_)) && + if (clientInfo_ && !IsAudioDeviceDescriptor()) { + return MarshallingToDeviceInfo(parcel, clientInfo_->hasBTPermission_, + clientInfo_->hasSystemPermission_, clientInfo_->apiVersion_); + } + + int32_t devType = deviceType_; + if (IsAudioDeviceDescriptor()) { + devType = MapInternalToExternalDeviceType(clientInfo_ ? clientInfo_->apiVersion_ : 0); + } + + return parcel.WriteInt32(devType) && parcel.WriteInt32(static_cast(deviceRole_)) && parcel.WriteInt32(deviceId_) && parcel.WriteInt32(channelMasks_) && parcel.WriteInt32(channelIndexMasks_) && parcel.WriteString(deviceName_) && parcel.WriteString(macAddress_) && - MarshallingDeviceStreamInfoList(audioStreamInfo_, parcel) && + parcel.WriteInt32(interruptGroupId_) && + parcel.WriteInt32(volumeGroupId_) && parcel.WriteString(networkId_) && parcel.WriteUint16(dmDeviceType_) && parcel.WriteString(displayName_) && - parcel.WriteInt32(interruptGroupId_) && - parcel.WriteInt32(volumeGroupId_) && + MarshallingDeviceStreamInfoList(audioStreamInfo_, parcel) && + parcel.WriteInt32(static_cast(deviceCategory_)) && + parcel.WriteInt32(static_cast(connectState_)) && + parcel.WriteBool(exceptionFlag_) && + parcel.WriteInt64(connectTimeStamp_) && + parcel.WriteBool(isScoRealConnected_) && + parcel.WriteBool(isEnable_) && + parcel.WriteInt32(mediaVolume_) && + parcel.WriteInt32(callVolume_) && parcel.WriteBool(isLowLatencyDevice_) && parcel.WriteInt32(a2dpOffloadFlag_) && - parcel.WriteInt32(static_cast(deviceCategory_)) && - parcel.WriteBool(spatializationSupported_); + parcel.WriteBool(descriptorType_) && + parcel.WriteBool(spatializationSupported_) && + parcel.WriteBool(hasPair_) && + parcel.WriteInt32(routerType_) && + parcel.WriteInt32(isVrSupported_); } -bool AudioDeviceDescriptor::Marshalling(Parcel &parcel, bool hasBTPermission, bool hasSystemPermission, - int32_t apiVersion) const -{ - return MarshallingToDeviceInfo(parcel, hasBTPermission, hasSystemPermission, apiVersion); -} - -static void SetDefaultStreamInfoIfEmpty(std::list &streamInfo) +void AudioDeviceDescriptor::FixApiCompatibility(int apiVersion, DeviceRole deviceRole, + DeviceType &deviceType, int32_t &deviceId, std::list &streamInfo) { - if (streamInfo.empty()) { - streamInfo.push_back(DEFAULT_DEVICE_STREAM_INFO); - } else { - for (auto &info : streamInfo) { - // If does not set sampleRates use SAMPLE_RATE_44100 instead. - if (info.samplingRate.empty()) { - info.samplingRate = DEFAULT_DEVICE_STREAM_INFO.samplingRate; - } - // If does not set channelCounts use STEREO instead. - if (info.channelLayout.empty()) { - info.channelLayout = DEFAULT_DEVICE_STREAM_INFO.channelLayout; - } + // If api target version < 11 && does not set deviceType, fix api compatibility. + if (apiVersion < API_11 && (deviceType == DEVICE_TYPE_NONE || deviceType == DEVICE_TYPE_INVALID)) { + // DeviceType use speaker or mic instead. + if (deviceRole == OUTPUT_DEVICE) { + deviceType = DEVICE_TYPE_SPEAKER; + deviceId = 1; // 1 default speaker device id. + } else if (deviceRole == INPUT_DEVICE) { + deviceType = DEVICE_TYPE_MIC; + deviceId = 2; // 2 default mic device id. } + + SetDefaultStreamInfoIfEmpty(streamInfo); } } @@ -335,19 +345,7 @@ bool AudioDeviceDescriptor::MarshallingToDeviceInfo(Parcel &parcel, bool hasBTPe int32_t devId = deviceId_; std::list streamInfo = audioStreamInfo_; - // If api target version < 11 && does not set deviceType, fix api compatibility. - if (apiVersion < API_11 && (deviceType_ == DEVICE_TYPE_NONE || deviceType_ == DEVICE_TYPE_INVALID)) { - // DeviceType use speaker or mic instead. - if (deviceRole_ == OUTPUT_DEVICE) { - devType = DEVICE_TYPE_SPEAKER; - devId = 1; // 1 default speaker device id. - } else if (deviceRole_ == INPUT_DEVICE) { - devType = DEVICE_TYPE_MIC; - devId = 2; // 2 default mic device id. - } - - SetDefaultStreamInfoIfEmpty(streamInfo); - } + FixApiCompatibility(apiVersion, deviceRole_, devType, devId, streamInfo); return parcel.WriteInt32(static_cast(devType)) && parcel.WriteInt32(static_cast(deviceRole_)) && @@ -358,40 +356,34 @@ bool AudioDeviceDescriptor::MarshallingToDeviceInfo(Parcel &parcel, bool hasBTPe deviceType_ == DEVICE_TYPE_BLUETOOTH_SCO)) ? "" : deviceName_) && parcel.WriteString((!hasBTPermission && (deviceType_ == DEVICE_TYPE_BLUETOOTH_A2DP || deviceType_ == DEVICE_TYPE_BLUETOOTH_SCO)) ? "" : macAddress_) && - MarshallingDeviceStreamInfoList(streamInfo, parcel) && + parcel.WriteInt32(hasSystemPermission ? interruptGroupId_ : INVALID_GROUP_ID) && + parcel.WriteInt32(hasSystemPermission ? volumeGroupId_ : INVALID_GROUP_ID) && parcel.WriteString(hasSystemPermission ? networkId_ : "") && parcel.WriteUint16(dmDeviceType_) && parcel.WriteString(displayName_) && - parcel.WriteInt32(hasSystemPermission ? interruptGroupId_ : INVALID_GROUP_ID) && - parcel.WriteInt32(hasSystemPermission ? volumeGroupId_ : INVALID_GROUP_ID) && + MarshallingDeviceStreamInfoList(streamInfo, parcel) && + parcel.WriteInt32(static_cast(deviceCategory_)) && + parcel.WriteInt32(static_cast(connectState_)) && + parcel.WriteBool(exceptionFlag_) && + parcel.WriteInt64(connectTimeStamp_) && + parcel.WriteBool(isScoRealConnected_) && + parcel.WriteBool(isEnable_) && + parcel.WriteInt32(mediaVolume_) && + parcel.WriteInt32(callVolume_) && parcel.WriteBool(isLowLatencyDevice_) && parcel.WriteInt32(a2dpOffloadFlag_) && - parcel.WriteInt32(static_cast(deviceCategory_)) && - parcel.WriteBool(spatializationSupported_); -} - -void AudioDeviceDescriptor::Unmarshalling(Parcel &parcel) -{ - return UnmarshallingToDeviceInfo(parcel); -} - -std::shared_ptr AudioDeviceDescriptor::UnmarshallingPtr(Parcel &parcel) -{ - std::shared_ptr audioDeviceDescriptor = std::make_shared(); - if (audioDeviceDescriptor == nullptr) { - return nullptr; - } - - audioDeviceDescriptor->UnmarshallingToDeviceDescriptor(parcel); - return audioDeviceDescriptor; + parcel.WriteBool(descriptorType_) && + parcel.WriteBool(spatializationSupported_) && + parcel.WriteBool(hasPair_) && + parcel.WriteInt32(routerType_) && + parcel.WriteInt32(isVrSupported_); } -void AudioDeviceDescriptor::UnmarshallingToDeviceDescriptor(Parcel &parcel) +void AudioDeviceDescriptor::UnmarshallingSelf(Parcel &parcel) { deviceType_ = static_cast(parcel.ReadInt32()); deviceRole_ = static_cast(parcel.ReadInt32()); deviceId_ = parcel.ReadInt32(); - UnmarshallingDeviceStreamInfoList(parcel, audioStreamInfo_); channelMasks_ = parcel.ReadInt32(); channelIndexMasks_ = parcel.ReadInt32(); deviceName_ = parcel.ReadString(); @@ -401,32 +393,33 @@ void AudioDeviceDescriptor::UnmarshallingToDeviceDescriptor(Parcel &parcel) networkId_ = parcel.ReadString(); dmDeviceType_ = parcel.ReadUint16(); displayName_ = parcel.ReadString(); + UnmarshallingDeviceStreamInfoList(parcel, audioStreamInfo_); deviceCategory_ = static_cast(parcel.ReadInt32()); connectState_ = static_cast(parcel.ReadInt32()); - spatializationSupported_ = parcel.ReadBool(); + exceptionFlag_ = parcel.ReadBool(); + connectTimeStamp_ = parcel.ReadInt64(); + isScoRealConnected_ = parcel.ReadBool(); + isEnable_ = parcel.ReadBool(); mediaVolume_ = parcel.ReadInt32(); callVolume_ = parcel.ReadInt32(); -} - -void AudioDeviceDescriptor::UnmarshallingToDeviceInfo(Parcel &parcel) -{ - deviceType_ = static_cast(parcel.ReadInt32()); - deviceRole_ = static_cast(parcel.ReadInt32()); - deviceId_ = parcel.ReadInt32(); - channelMasks_ = parcel.ReadInt32(); - channelIndexMasks_ = parcel.ReadInt32(); - deviceName_ = parcel.ReadString(); - macAddress_ = parcel.ReadString(); - UnmarshallingDeviceStreamInfoList(parcel, audioStreamInfo_); - networkId_ = parcel.ReadString(); - dmDeviceType_ = parcel.ReadUint16(); - displayName_ = parcel.ReadString(); - interruptGroupId_ = parcel.ReadInt32(); - volumeGroupId_ = parcel.ReadInt32(); isLowLatencyDevice_ = parcel.ReadBool(); a2dpOffloadFlag_ = parcel.ReadInt32(); - deviceCategory_ = static_cast(parcel.ReadInt32()); + descriptorType_ = parcel.ReadBool(); spatializationSupported_ = parcel.ReadBool(); + hasPair_ = parcel.ReadBool(); + routerType_ = static_cast(parcel.ReadInt32()); + isVrSupported_ = parcel.ReadInt32(); +} + +AudioDeviceDescriptor *AudioDeviceDescriptor::Unmarshalling(Parcel &parcel) +{ + auto deviceDescriptor = new AudioDeviceDescriptor(); + if (deviceDescriptor == nullptr) { + return nullptr; + } + + deviceDescriptor->UnmarshallingSelf(parcel); + return deviceDescriptor; } void AudioDeviceDescriptor::SetDeviceInfo(std::string deviceName, std::string macAddress) diff --git a/services/audio_policy/server/domain/device/src/audio_microphone_descriptor.cpp b/services/audio_policy/server/domain/device/src/audio_microphone_descriptor.cpp index baeea7d381..fc4461cc74 100644 --- a/services/audio_policy/server/domain/device/src/audio_microphone_descriptor.cpp +++ b/services/audio_policy/server/domain/device/src/audio_microphone_descriptor.cpp @@ -22,7 +22,6 @@ #include "parameter.h" #include "parameters.h" #include "audio_policy_log.h" -#include "audio_manager_listener_stub.h" #include "audio_inner_call.h" #include "media_monitor_manager.h" #include "audio_policy_manager_factory.h" diff --git a/services/audio_policy/server/domain/device/src/audio_scene_manager.cpp b/services/audio_policy/server/domain/device/src/audio_scene_manager.cpp index edf0dc289b..80fbf0df68 100644 --- a/services/audio_policy/server/domain/device/src/audio_scene_manager.cpp +++ b/services/audio_policy/server/domain/device/src/audio_scene_manager.cpp @@ -23,7 +23,6 @@ #include "parameter.h" #include "parameters.h" #include "audio_policy_log.h" -#include "audio_manager_listener_stub.h" #include "audio_inner_call.h" #include "media_monitor_manager.h" diff --git a/services/audio_policy/server/domain/device/src/audio_state_manager.cpp b/services/audio_policy/server/domain/device/src/audio_state_manager.cpp index 3456c49126..62c969ed03 100644 --- a/services/audio_policy/server/domain/device/src/audio_state_manager.cpp +++ b/services/audio_policy/server/domain/device/src/audio_state_manager.cpp @@ -43,6 +43,7 @@ void AudioStateManager::SetPreferredCallRenderDevice(const std::shared_ptr