1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "audio_manager_listener_stub.h"
17 #include "audio_log.h"
18
19 using namespace std;
20
21 namespace OHOS {
22 namespace AudioStandard {
AudioManagerListenerStub()23 AudioManagerListenerStub::AudioManagerListenerStub()
24 {
25 }
~AudioManagerListenerStub()26 AudioManagerListenerStub::~AudioManagerListenerStub()
27 {
28 }
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)29 int AudioManagerListenerStub::OnRemoteRequest(
30 uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
31 {
32 AUDIO_DEBUG_LOG("OnRemoteRequest, cmd = %{public}u", code);
33 if (data.ReadInterfaceToken() != GetDescriptor()) {
34 AUDIO_ERR_LOG("AudioManagerStub: ReadInterfaceToken failed");
35 return -1;
36 }
37
38 switch (code) {
39 case ON_PARAMETER_CHANGED: {
40 AUDIO_DEBUG_LOG("ON_PARAMETER_CHANGED AudioManagerStub");
41 string networkId = data.ReadString();
42 AudioParamKey key = static_cast<AudioParamKey>(data.ReadInt32());
43 string condition = data.ReadString();
44 string value = data.ReadString();
45 OnAudioParameterChange(networkId, key, condition, value);
46 return AUDIO_OK;
47 }
48 case ON_WAKEUP_CLOSE: {
49 AUDIO_DEBUG_LOG("ON_WAKEUP_CLOSE AudioManagerStub");
50 OnWakeupClose();
51 return AUDIO_OK;
52 }
53 case ON_CAPTURER_STATE: {
54 AUDIO_DEBUG_LOG("ON_CAPTURER_STATE AudioManagerStub");
55 bool isActive = data.ReadBool();
56 OnCapturerState(isActive);
57 return AUDIO_OK;
58 }
59 default: {
60 AUDIO_ERR_LOG("default case, need check AudioManagerStub");
61 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
62 }
63 }
64 }
65
SetParameterCallback(const std::weak_ptr<AudioParameterCallback> & callback)66 void AudioManagerListenerStub::SetParameterCallback(const std::weak_ptr<AudioParameterCallback>& callback)
67 {
68 callback_ = callback;
69 }
70
SetWakeupSourceCallback(const std::weak_ptr<WakeUpSourceCallback> & callback)71 void AudioManagerListenerStub::SetWakeupSourceCallback(const std::weak_ptr<WakeUpSourceCallback>& callback)
72 {
73 wakeUpCallback_ = callback;
74 }
75
OnAudioParameterChange(const std::string networkId,const AudioParamKey key,const std::string & condition,const std::string & value)76 void AudioManagerListenerStub::OnAudioParameterChange(const std::string networkId, const AudioParamKey key,
77 const std::string& condition, const std::string& value)
78 {
79 std::shared_ptr<AudioParameterCallback> cb = callback_.lock();
80 if (cb != nullptr) {
81 cb->OnAudioParameterChange(networkId, key, condition, value);
82 } else {
83 AUDIO_ERR_LOG("AudioRingerModeUpdateListenerStub: callback_ is nullptr");
84 }
85 }
86
OnCapturerState(bool isActive)87 void AudioManagerListenerStub::OnCapturerState(bool isActive)
88 {
89 std::shared_ptr<WakeUpSourceCallback> cb = wakeUpCallback_.lock();
90 if (cb != nullptr) {
91 cb->OnCapturerState(isActive);
92 } else {
93 AUDIO_ERR_LOG("AudioManagerListenerStub: OnWakeupClose error");
94 }
95 }
96
OnWakeupClose()97 void AudioManagerListenerStub::OnWakeupClose()
98 {
99 std::shared_ptr<WakeUpSourceCallback> cb = wakeUpCallback_.lock();
100 if (cb != nullptr) {
101 cb->OnWakeupClose();
102 } else {
103 AUDIO_ERR_LOG("AudioManagerListenerStub: OnWakeupClose error");
104 }
105 }
106
107 } // namespace AudioStandard
108 } // namespace OHOS
109