1 /*
2 * Copyright (c) 2021-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_volume_key_event_callback_stub.h"
17 #include "audio_log.h"
18
19 namespace OHOS {
20 namespace AudioStandard {
AudioVolumeKeyEventCallbackStub()21 AudioVolumeKeyEventCallbackStub::AudioVolumeKeyEventCallbackStub()
22 {
23 }
24
~AudioVolumeKeyEventCallbackStub()25 AudioVolumeKeyEventCallbackStub::~AudioVolumeKeyEventCallbackStub()
26 {
27 }
28
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)29 int AudioVolumeKeyEventCallbackStub::OnRemoteRequest(
30 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
31 {
32 AUDIO_DEBUG_LOG("AudioVolumeKeyEventCallbackStub::OnRemoteRequest");
33 if (data.ReadInterfaceToken() != GetDescriptor()) {
34 AUDIO_ERR_LOG("AudioVolumeKeyEventCallbackStub: ReadInterfaceToken failed");
35 return -1;
36 }
37 switch (code) {
38 case ON_VOLUME_KEY_EVENT: {
39 VolumeEvent volumeEvent;
40 volumeEvent.volumeType = static_cast<AudioStreamType>(data.ReadInt32());
41 volumeEvent.volume = data.ReadInt32();
42 volumeEvent.updateUi = data.ReadBool();
43 volumeEvent.volumeGroupId = data.ReadInt32();
44 volumeEvent.networkId = data.ReadString();
45 OnVolumeKeyEvent(volumeEvent);
46 reply.WriteInt32(0);
47 break;
48 }
49 default: {
50 reply.WriteInt32(-1);
51 break;
52 }
53 }
54 return 0;
55 }
56
OnVolumeKeyEvent(VolumeEvent volumeEvent)57 void AudioVolumeKeyEventCallbackStub::OnVolumeKeyEvent(VolumeEvent volumeEvent)
58 {
59 AUDIO_DEBUG_LOG("AudioVolumeKeyEventCallbackStub::OnVolumeKeyEvent");
60 std::shared_ptr<VolumeKeyEventCallback> cb = callback_.lock();
61 if (cb != nullptr) {
62 AUDIO_DEBUG_LOG("AudioVolumeKeyEventCallbackStub::OnVolumeKeyEvent CALLBACK NOT NULL");
63 cb->OnVolumeKeyEvent(volumeEvent);
64 } else {
65 AUDIO_DEBUG_LOG("AudioVolumeKeyEventCallbackStub::OnVolumeKeyEvent CALLBACK NULL");
66 }
67 }
68
SetOnVolumeKeyEventCallback(const std::weak_ptr<VolumeKeyEventCallback> & callback)69 void AudioVolumeKeyEventCallbackStub::SetOnVolumeKeyEventCallback(
70 const std::weak_ptr<VolumeKeyEventCallback> &callback)
71 {
72 AUDIO_DEBUG_LOG("AudioVolumeKeyEventCallbackStub::SetOnVolumeKeyEventCallback");
73 callback_ = callback;
74 }
75 } // namespace AudioStandard
76 } // namespace OHOS
77