From 0504d22eb78af34f5abf55f7891c7fe1b2c7b826 Mon Sep 17 00:00:00 2001 From: zhanhang Date: Thu, 14 Jul 2022 15:46:06 +0800 Subject: [PATCH] add groupId and networkId for VolumeEVentId Signed-off-by: zhanhang Change-Id: Iab60ab550328c58066c9daecc8ed31e4750993ca --- .../include/audio_volume_key_event_napi.h | 2 +- .../src/audio_volume_key_event_napi.cpp | 14 ++++++----- .../native/audiocommon/include/audio_info.h | 2 ++ .../include/audio_system_manager.h | 6 ++--- .../audio_volume_key_event_callback_stub.h | 2 +- .../i_audio_volume_key_event_callback.h | 2 +- .../audio_volume_key_event_callback_proxy.h | 4 ++-- .../audio_volume_key_event_callback_stub.cpp | 15 +++++++----- .../server/audio_policy_server.cpp | 24 ++++++++++++++++--- .../audio_volume_key_event_callback_proxy.cpp | 15 ++++++------ .../include/audio_volume_change_unit_test.h | 2 +- .../src/audio_volume_change_unit_test.cpp | 12 ++++++---- 12 files changed, 64 insertions(+), 36 deletions(-) diff --git a/frameworks/js/napi/audio_manager/include/audio_volume_key_event_napi.h b/frameworks/js/napi/audio_manager/include/audio_volume_key_event_napi.h index 1b99e5ca..535561aa 100644 --- a/frameworks/js/napi/audio_manager/include/audio_volume_key_event_napi.h +++ b/frameworks/js/napi/audio_manager/include/audio_volume_key_event_napi.h @@ -50,7 +50,7 @@ public: * @param volumeLevel the volume level to be updated. * @param isUpdateUi whether to update volume level in UI. **/ - void OnVolumeKeyEvent(AudioStreamType streamType, int volumeLevel, bool isUpdateUi) override; + void OnVolumeKeyEvent(VolumeEvent volumeEvent) override; void SaveCallbackReference(const std::string &callbackName, napi_value callback); private: diff --git a/frameworks/js/napi/audio_manager/src/audio_volume_key_event_napi.cpp b/frameworks/js/napi/audio_manager/src/audio_volume_key_event_napi.cpp index 7618cce9..8e65438f 100644 --- a/frameworks/js/napi/audio_manager/src/audio_volume_key_event_napi.cpp +++ b/frameworks/js/napi/audio_manager/src/audio_volume_key_event_napi.cpp @@ -36,11 +36,11 @@ AudioVolumeKeyEventNapi::~AudioVolumeKeyEventNapi() AUDIO_DEBUG_LOG("AudioVolumeKeyEventNapi::Destructor"); } -void AudioVolumeKeyEventNapi::OnVolumeKeyEvent(AudioStreamType streamType, int32_t volumeLevel, bool isUpdateUi) +void AudioVolumeKeyEventNapi::OnVolumeKeyEvent(VolumeEvent volumeEvent) { std::lock_guard lock(mutex_); - AUDIO_DEBUG_LOG("AudioVolumeKeyEventNapi: OnVolumeKeyEvent is called volumeLevel=%{public}d", volumeLevel); - AUDIO_DEBUG_LOG("AudioVolumeKeyEventNapi: isUpdateUi is called isUpdateUi=%{public}d", isUpdateUi); + AUDIO_DEBUG_LOG("AudioVolumeKeyEventNapi: OnVolumeKeyEvent is called volumeLevel=%{public}d", volumeEvent.volume); + AUDIO_DEBUG_LOG("AudioVolumeKeyEventNapi: isUpdateUi is called isUpdateUi=%{public}d", volumeEvent.updateUi); if (audioVolumeKeyEventJsCallback_ == nullptr) { AUDIO_DEBUG_LOG("AudioManagerCallbackNapi:No JS callback registered return"); return; @@ -49,9 +49,11 @@ void AudioVolumeKeyEventNapi::OnVolumeKeyEvent(AudioStreamType streamType, int32 CHECK_AND_RETURN_LOG(cb != nullptr, "No memory"); cb->callback = audioVolumeKeyEventJsCallback_; cb->callbackName = VOLUME_KEY_EVENT_CALLBACK_NAME; - cb->volumeEvent.volumeType = streamType; - cb->volumeEvent.volume = volumeLevel; - cb->volumeEvent.updateUi = isUpdateUi; + cb->volumeEvent.volumeType = volumeEvent.volumeType; + cb->volumeEvent.volume = volumeEvent.volume; + cb->volumeEvent.updateUi = volumeEvent.updateUi; + cb->volumeEvent.volumeGroupId = volumeEvent.volumeGroupId; + cb->volumeEvent.networkId = volumeEvent.networkId; return OnJsCallbackVolumeEvent(cb); } diff --git a/interfaces/inner_api/native/audiocommon/include/audio_info.h b/interfaces/inner_api/native/audiocommon/include/audio_info.h index 1aca205e..38cc8744 100644 --- a/interfaces/inner_api/native/audiocommon/include/audio_info.h +++ b/interfaces/inner_api/native/audiocommon/include/audio_info.h @@ -439,6 +439,8 @@ struct VolumeEvent { AudioStreamType volumeType; int32_t volume; bool updateUi; + int32_t volumeGroupId; + std::string networkId; }; struct AudioParameters { 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 d2cd2ff4..a4f39965 100644 --- a/interfaces/inner_api/native/audiomanager/include/audio_system_manager.h +++ b/interfaces/inner_api/native/audiomanager/include/audio_system_manager.h @@ -103,11 +103,9 @@ public: /** * @brief VolumeKeyEventCallback will be executed when hard volume key is pressed up/down * - * @param streamType the stream type for which volume must be updated. - * @param volumeLevel the volume level to be updated. - * @param isUpdateUi whether to update volume level in UI. + * @param volumeEvent the volume event info. **/ - virtual void OnVolumeKeyEvent(AudioStreamType streamType, int32_t volumeLevel, bool isUpdateUi) = 0; + virtual void OnVolumeKeyEvent(VolumeEvent volumeEvent) = 0; }; class AudioRingerModeCallback { diff --git a/services/include/audio_policy/client/audio_volume_key_event_callback_stub.h b/services/include/audio_policy/client/audio_volume_key_event_callback_stub.h index 4c3517cb..4704391f 100644 --- a/services/include/audio_policy/client/audio_volume_key_event_callback_stub.h +++ b/services/include/audio_policy/client/audio_volume_key_event_callback_stub.h @@ -27,7 +27,7 @@ public: virtual ~AudioVolumeKeyEventCallbackStub(); virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - void OnVolumeKeyEvent(AudioStreamType streamType, int32_t volumeLevel, bool isUpdateUi) override; + void OnVolumeKeyEvent(VolumeEvent volumeEvent) override; void SetOnVolumeKeyEventCallback(const std::weak_ptr &callback); private: diff --git a/services/include/audio_policy/common/i_audio_volume_key_event_callback.h b/services/include/audio_policy/common/i_audio_volume_key_event_callback.h index 9cf2748b..f623b51c 100644 --- a/services/include/audio_policy/common/i_audio_volume_key_event_callback.h +++ b/services/include/audio_policy/common/i_audio_volume_key_event_callback.h @@ -26,7 +26,7 @@ namespace OHOS { namespace AudioStandard { class IAudioVolumeKeyEventCallback : public IRemoteBroker { public: - virtual void OnVolumeKeyEvent(AudioStreamType streamType, int32_t volumeLevel, bool isUpdateUi) = 0; + virtual void OnVolumeKeyEvent(VolumeEvent volumeEvent) = 0; enum { ON_VOLUME_KEY_EVENT = 0, }; diff --git a/services/include/audio_policy/server/audio_volume_key_event_callback_proxy.h b/services/include/audio_policy/server/audio_volume_key_event_callback_proxy.h index c4f22b46..1cc6d971 100644 --- a/services/include/audio_policy/server/audio_volume_key_event_callback_proxy.h +++ b/services/include/audio_policy/server/audio_volume_key_event_callback_proxy.h @@ -27,7 +27,7 @@ public: explicit VolumeKeyEventCallbackListner(const sptr &listener); virtual ~VolumeKeyEventCallbackListner(); DISALLOW_COPY_AND_MOVE(VolumeKeyEventCallbackListner); - void OnVolumeKeyEvent(AudioStreamType streamType, int32_t volumeLevel, bool isUpdateUi) override; + void OnVolumeKeyEvent(VolumeEvent volumeEvent) override; private: sptr listener_ = nullptr; @@ -36,7 +36,7 @@ class AudioVolumeKeyEventCallbackProxy : public IRemoteProxy &impl); virtual ~AudioVolumeKeyEventCallbackProxy() = default; - void OnVolumeKeyEvent(AudioStreamType streamType, int32_t volumeLevel, bool isUpdateUi) override; + void OnVolumeKeyEvent(VolumeEvent volumeEvent) override; private: static inline BrokerDelegator delegator_; }; diff --git a/services/src/audio_policy/client/audio_volume_key_event_callback_stub.cpp b/services/src/audio_policy/client/audio_volume_key_event_callback_stub.cpp index 57978fc8..f2fe5954 100644 --- a/services/src/audio_policy/client/audio_volume_key_event_callback_stub.cpp +++ b/services/src/audio_policy/client/audio_volume_key_event_callback_stub.cpp @@ -36,10 +36,13 @@ int AudioVolumeKeyEventCallbackStub::OnRemoteRequest( } switch (code) { case ON_VOLUME_KEY_EVENT: { - AudioStreamType streamType = static_cast(data.ReadInt32()); - int32_t volume = data.ReadInt32(); - bool isUpdateUi = data.ReadBool(); - OnVolumeKeyEvent(streamType, volume, isUpdateUi); + VolumeEvent volumeEvent; + volumeEvent.volumeType = static_cast(data.ReadInt32()); + volumeEvent.volume = data.ReadInt32(); + volumeEvent.updateUi = data.ReadBool(); + volumeEvent.volumeGroupId = data.ReadInt32(); + volumeEvent.networkId = data.ReadString(); + OnVolumeKeyEvent(volumeEvent); reply.WriteInt32(0); break; } @@ -51,13 +54,13 @@ int AudioVolumeKeyEventCallbackStub::OnRemoteRequest( return 0; } -void AudioVolumeKeyEventCallbackStub::OnVolumeKeyEvent(AudioStreamType streamType, int32_t volumeLevel, bool isUpdateUi) +void AudioVolumeKeyEventCallbackStub::OnVolumeKeyEvent(VolumeEvent volumeEvent) { AUDIO_DEBUG_LOG("AudioVolumeKeyEventCallbackStub::OnVolumeKeyEvent"); std::shared_ptr cb = callback_.lock(); if (cb != nullptr) { AUDIO_DEBUG_LOG("AudioVolumeKeyEventCallbackStub::OnVolumeKeyEvent CALLBACK NOT NULL"); - cb->OnVolumeKeyEvent(streamType, volumeLevel, isUpdateUi); + cb->OnVolumeKeyEvent(volumeEvent); } else { AUDIO_DEBUG_LOG("AudioVolumeKeyEventCallbackStub::OnVolumeKeyEvent CALLBACK NULL"); } diff --git a/services/src/audio_policy/server/audio_policy_server.cpp b/services/src/audio_policy/server/audio_policy_server.cpp index 1966bd51..d04aaa87 100644 --- a/services/src/audio_policy/server/audio_policy_server.cpp +++ b/services/src/audio_policy/server/audio_policy_server.cpp @@ -166,7 +166,13 @@ void AudioPolicyServer::SubscribeKeyEvents() } AUDIO_DEBUG_LOG("AudioPolicyServer:: trigger volumeChangeCb clientPid : %{public}d", it->first); - volumeChangeCb->OnVolumeKeyEvent(streamInFocus, MIN_VOLUME_LEVEL, true); + VolumeEvent volumeEvent; + volumeEvent.volumeType = streamInFocus; + volumeEvent.volume = MIN_VOLUME_LEVEL; + volumeEvent.updateUi = true; + volumeEvent.volumeGroupId = 0; + volumeEvent.networkId = LOCAL_NETWORK_ID; + volumeChangeCb->OnVolumeKeyEvent(volumeEvent); } return; } @@ -194,7 +200,13 @@ void AudioPolicyServer::SubscribeKeyEvents() } AUDIO_DEBUG_LOG("AudioPolicyServer:: trigger volumeChangeCb clientPid : %{public}d", it->first); - volumeChangeCb->OnVolumeKeyEvent(streamInFocus, MAX_VOLUME_LEVEL, true); + VolumeEvent volumeEvent; + volumeEvent.volumeType = streamInFocus; + volumeEvent.volume = MAX_VOLUME_LEVEL; + volumeEvent.updateUi = true; + volumeEvent.volumeGroupId = 0; + volumeEvent.networkId = LOCAL_NETWORK_ID; + volumeChangeCb->OnVolumeKeyEvent(volumeEvent); } return; } @@ -258,7 +270,13 @@ int32_t AudioPolicyServer::SetStreamVolume(AudioStreamType streamType, float vol } AUDIO_DEBUG_LOG("AudioPolicyServer::SetStreamVolume trigger volumeChangeCb clientPid : %{public}d", it->first); - volumeChangeCb->OnVolumeKeyEvent(streamType, ConvertVolumeToInt(GetStreamVolume(streamType)), isUpdateUi); + VolumeEvent volumeEvent; + volumeEvent.volumeType = streamType; + volumeEvent.volume = ConvertVolumeToInt(GetStreamVolume(streamType)); + volumeEvent.updateUi = isUpdateUi; + volumeEvent.volumeGroupId = 0; + volumeEvent.networkId = LOCAL_NETWORK_ID; + volumeChangeCb->OnVolumeKeyEvent(volumeEvent); } return ret; diff --git a/services/src/audio_policy/server/audio_volume_key_event_callback_proxy.cpp b/services/src/audio_policy/server/audio_volume_key_event_callback_proxy.cpp index d7400cbf..c75ada40 100644 --- a/services/src/audio_policy/server/audio_volume_key_event_callback_proxy.cpp +++ b/services/src/audio_policy/server/audio_volume_key_event_callback_proxy.cpp @@ -20,8 +20,7 @@ namespace AudioStandard { AudioVolumeKeyEventCallbackProxy::AudioVolumeKeyEventCallbackProxy(const sptr &impl) : IRemoteProxy(impl) { } -void AudioVolumeKeyEventCallbackProxy::OnVolumeKeyEvent(AudioStreamType streamType, int32_t volumeLevel, - bool isUpdateUi) +void AudioVolumeKeyEventCallbackProxy::OnVolumeKeyEvent(VolumeEvent volumeEvent) { AUDIO_DEBUG_LOG("AudioVolumeKeyEventCallbackProxy::OnVolumeKeyEvent"); MessageParcel data; @@ -32,9 +31,11 @@ void AudioVolumeKeyEventCallbackProxy::OnVolumeKeyEvent(AudioStreamType streamTy AUDIO_ERR_LOG("AudioVolumeKeyEventCallbackProxy: WriteInterfaceToken failed"); return; } - data.WriteInt32(static_cast(streamType)); - data.WriteInt32(volumeLevel); - data.WriteBool(isUpdateUi); + data.WriteInt32(static_cast(volumeEvent.volumeType)); + data.WriteInt32(volumeEvent.volume); + data.WriteBool(volumeEvent.updateUi); + data.WriteInt32(volumeEvent.volumeGroupId); + data.WriteString(volumeEvent.networkId); int error = Remote()->SendRequest(ON_VOLUME_KEY_EVENT, data, reply, option); if (error != 0) { AUDIO_DEBUG_LOG("Error while sending volume key event %{public}d", error); @@ -53,11 +54,11 @@ VolumeKeyEventCallbackListner::~VolumeKeyEventCallbackListner() AUDIO_DEBUG_LOG("VolumeKeyEventCallbackListner desctrutor"); } -void VolumeKeyEventCallbackListner::OnVolumeKeyEvent(AudioStreamType streamType, int32_t volumeLevel, bool isUpdateUi) +void VolumeKeyEventCallbackListner::OnVolumeKeyEvent(VolumeEvent volumeEvent) { AUDIO_DEBUG_LOG("AudioVolumeKeyEventCallbackProxy VolumeKeyEventCallbackListner"); if (listener_ != nullptr) { - listener_->OnVolumeKeyEvent(streamType, volumeLevel, isUpdateUi); + listener_->OnVolumeKeyEvent(volumeEvent); } } } // namespace AudioStandard diff --git a/test/unittest/volume_change_test/include/audio_volume_change_unit_test.h b/test/unittest/volume_change_test/include/audio_volume_change_unit_test.h index ee344ddf..3092bdb6 100644 --- a/test/unittest/volume_change_test/include/audio_volume_change_unit_test.h +++ b/test/unittest/volume_change_test/include/audio_volume_change_unit_test.h @@ -34,7 +34,7 @@ public: explicit ApplicationCallback(const std::string &testCaseName); ~ApplicationCallback() = default; - void OnVolumeKeyEvent(AudioStreamType streamType, int32_t volumeLevel, bool isUpdateUi) override; + void OnVolumeKeyEvent(VolumeEvent volumeEvent) override; private: std::string testCaseName_; diff --git a/test/unittest/volume_change_test/src/audio_volume_change_unit_test.cpp b/test/unittest/volume_change_test/src/audio_volume_change_unit_test.cpp index 67b03d99..2d2f1d75 100644 --- a/test/unittest/volume_change_test/src/audio_volume_change_unit_test.cpp +++ b/test/unittest/volume_change_test/src/audio_volume_change_unit_test.cpp @@ -36,6 +36,8 @@ namespace { int32_t g_streamType(0); int32_t g_volumeLevel(0); bool g_isUpdateUi(false); + int32_t g_volumeGroupId(0); + std::string g_networkId(LOCAL_NETWORK_ID); bool g_isCallbackReceived(false); std::string g_callbackName(""); @@ -45,13 +47,15 @@ namespace { ApplicationCallback::ApplicationCallback(const std::string &testCaseName) : testCaseName_(testCaseName) {} -void ApplicationCallback::OnVolumeKeyEvent(AudioStreamType streamType, int32_t volumeLevel, bool isUpdateUi) +void ApplicationCallback::OnVolumeKeyEvent(VolumeEvent volumeEvent) { g_isCallbackReceived = true; - g_streamType = streamType; - g_volumeLevel = volumeLevel; + g_streamType = volumeEvent.volumeType; + g_volumeLevel = volumeEvent.volume; g_callbackName = testCaseName_; - g_isUpdateUi = isUpdateUi; + g_isUpdateUi = volumeEvent.updateUi; + g_volumeGroupId = volumeEvent.volumeGroupId; + g_networkId = volumeEvent.networkId; g_condVar.notify_all(); }