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 #ifndef LOG_TAG
16 #define LOG_TAG "AudioClientTrackerCallbackProxy"
17 #endif
18
19 #include "audio_policy_log.h"
20 #include "audio_client_tracker_callback_proxy.h"
21
22 namespace OHOS {
23 namespace AudioStandard {
AudioClientTrackerCallbackProxy(const sptr<IRemoteObject> & impl)24 AudioClientTrackerCallbackProxy::AudioClientTrackerCallbackProxy(const sptr<IRemoteObject> &impl)
25 : IRemoteProxy<IStandardClientTracker>(impl) { }
26
PausedStreamImpl(const StreamSetStateEventInternal & streamSetStateEventInternal)27 void AudioClientTrackerCallbackProxy::PausedStreamImpl(
28 const StreamSetStateEventInternal &streamSetStateEventInternal)
29 {
30 MessageParcel data;
31 MessageParcel reply;
32 MessageOption option(MessageOption::TF_ASYNC);
33 bool ret = data.WriteInterfaceToken(GetDescriptor());
34 CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
35
36 data.WriteInt32(static_cast<int32_t>(streamSetStateEventInternal.streamSetState));
37 data.WriteInt32(static_cast<int32_t>(streamSetStateEventInternal.streamUsage));
38 int error = Remote()->SendRequest(PAUSEDSTREAM, data, reply, option);
39 if (error != ERR_NONE) {
40 AUDIO_WARNING_LOG("PausedStreamImpl failed, error: %{public}d", error);
41 }
42 }
43
ResumeStreamImpl(const StreamSetStateEventInternal & streamSetStateEventInternal)44 void AudioClientTrackerCallbackProxy::ResumeStreamImpl(
45 const StreamSetStateEventInternal &streamSetStateEventInternal)
46 {
47 MessageParcel data;
48 MessageParcel reply;
49 MessageOption option(MessageOption::TF_ASYNC);
50 bool ret = data.WriteInterfaceToken(GetDescriptor());
51 CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
52
53 data.WriteInt32(static_cast<int32_t>(streamSetStateEventInternal.streamSetState));
54 data.WriteInt32(static_cast<int32_t>(streamSetStateEventInternal.streamUsage));
55 int error = Remote()->SendRequest(RESUMESTREAM, data, reply, option);
56 if (error != ERR_NONE) {
57 AUDIO_WARNING_LOG("ResumeStreamImpl failed, error: %{public}d", error);
58 }
59 }
60
SetLowPowerVolumeImpl(float volume)61 void AudioClientTrackerCallbackProxy::SetLowPowerVolumeImpl(float volume)
62 {
63 MessageParcel data;
64 MessageParcel reply;
65 MessageOption option(MessageOption::TF_ASYNC);
66 bool ret = data.WriteInterfaceToken(GetDescriptor());
67 CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
68
69 data.WriteFloat(static_cast<float>(volume));
70 int error = Remote()->SendRequest(SETLOWPOWERVOL, data, reply, option);
71 if (error != ERR_NONE) {
72 AUDIO_WARNING_LOG("SETLOWPOWERVOL failed, error: %{public}d", error);
73 }
74 }
75
GetLowPowerVolumeImpl(float & volume)76 void AudioClientTrackerCallbackProxy::GetLowPowerVolumeImpl(float &volume)
77 {
78 MessageParcel data;
79 MessageParcel reply;
80 MessageOption option;
81 bool ret = data.WriteInterfaceToken(GetDescriptor());
82 CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
83
84 int error = Remote()->SendRequest(GETLOWPOWERVOL, data, reply, option);
85 if (error != ERR_NONE) {
86 AUDIO_WARNING_LOG("GETLOWPOWERVOL failed, error: %{public}d", error);
87 }
88
89 volume = reply.ReadFloat();
90 }
91
GetSingleStreamVolumeImpl(float & volume)92 void AudioClientTrackerCallbackProxy::GetSingleStreamVolumeImpl(float &volume)
93 {
94 MessageParcel data;
95 MessageParcel reply;
96 MessageOption option;
97 bool ret = data.WriteInterfaceToken(GetDescriptor());
98 CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
99
100 int error = Remote()->SendRequest(GETSINGLESTREAMVOL, data, reply, option);
101 if (error != ERR_NONE) {
102 AUDIO_WARNING_LOG("GETSINGLESTREAMVOL failed, error: %{public}d", error);
103 }
104
105 volume = reply.ReadFloat();
106 }
107
SetOffloadModeImpl(int32_t state,bool isAppBack)108 void AudioClientTrackerCallbackProxy::SetOffloadModeImpl(int32_t state, bool isAppBack)
109 {
110 MessageParcel data;
111 MessageParcel reply;
112 MessageOption option;
113 bool ret = data.WriteInterfaceToken(GetDescriptor());
114 CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
115
116 data.WriteInt32(static_cast<int32_t>(state));
117 data.WriteBool(static_cast<bool>(isAppBack));
118
119 int error = Remote()->SendRequest(SETOFFLOADMODE, data, reply, option);
120 if (error != ERR_NONE) {
121 AUDIO_WARNING_LOG("SETOFFLOADMODE failed, error: %{public}d", error);
122 }
123 }
124
UnsetOffloadModeImpl()125 void AudioClientTrackerCallbackProxy::UnsetOffloadModeImpl()
126 {
127 MessageParcel data;
128 MessageParcel reply;
129 MessageOption option;
130 bool ret = data.WriteInterfaceToken(GetDescriptor());
131 CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
132
133 int error = Remote()->SendRequest(UNSETOFFLOADMODE, data, reply, option);
134 if (error != ERR_NONE) {
135 AUDIO_WARNING_LOG("UNSETOFFLOADMODE failed, error: %{public}d", error);
136 }
137 }
138
ClientTrackerCallbackListener(const sptr<IStandardClientTracker> & listener)139 ClientTrackerCallbackListener::ClientTrackerCallbackListener(const sptr<IStandardClientTracker> &listener)
140 : listener_(listener)
141 {
142 }
143
~ClientTrackerCallbackListener()144 ClientTrackerCallbackListener::~ClientTrackerCallbackListener()
145 {
146 }
147
148
PausedStreamImpl(const StreamSetStateEventInternal & streamSetStateEventInternal)149 void ClientTrackerCallbackListener::PausedStreamImpl(
150 const StreamSetStateEventInternal &streamSetStateEventInternal)
151 {
152 if (listener_ != nullptr) {
153 listener_->PausedStreamImpl(streamSetStateEventInternal);
154 }
155 }
156
ResumeStreamImpl(const StreamSetStateEventInternal & streamSetStateEventInternal)157 void ClientTrackerCallbackListener::ResumeStreamImpl(
158 const StreamSetStateEventInternal &streamSetStateEventInternal)
159 {
160 if (listener_ != nullptr) {
161 listener_->ResumeStreamImpl(streamSetStateEventInternal);
162 }
163 }
164
SetLowPowerVolumeImpl(float volume)165 void ClientTrackerCallbackListener::SetLowPowerVolumeImpl(float volume)
166 {
167 if (listener_ != nullptr) {
168 listener_->SetLowPowerVolumeImpl(volume);
169 }
170 }
171
GetLowPowerVolumeImpl(float & volume)172 void ClientTrackerCallbackListener::GetLowPowerVolumeImpl(float &volume)
173 {
174 if (listener_ != nullptr) {
175 listener_->GetLowPowerVolumeImpl(volume);
176 }
177 }
178
GetSingleStreamVolumeImpl(float & volume)179 void ClientTrackerCallbackListener::GetSingleStreamVolumeImpl(float &volume)
180 {
181 if (listener_ != nullptr) {
182 listener_->GetSingleStreamVolumeImpl(volume);
183 }
184 }
185
SetOffloadModeImpl(int32_t state,bool isAppBack)186 void ClientTrackerCallbackListener::SetOffloadModeImpl(int32_t state, bool isAppBack)
187 {
188 if (listener_ != nullptr) {
189 listener_->SetOffloadModeImpl(state, isAppBack);
190 }
191 }
192
UnsetOffloadModeImpl()193 void ClientTrackerCallbackListener::UnsetOffloadModeImpl()
194 {
195 if (listener_ != nullptr) {
196 listener_->UnsetOffloadModeImpl();
197 }
198 }
199 } // namespace AudioStandard
200 } // namespace OHOS
201