• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_manager_base.h"
17 #include "audio_system_manager.h"
18 #include "audio_log.h"
19 
20 using namespace std;
21 
22 namespace OHOS {
23 namespace AudioStandard {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)24 int AudioManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
25 {
26     AUDIO_DEBUG_LOG("OnRemoteRequest, cmd = %{public}u", code);
27     if (data.ReadInterfaceToken() != GetDescriptor()) {
28         AUDIO_ERR_LOG("AudioManagerStub: ReadInterfaceToken failed");
29         return -1;
30     }
31 
32     switch (code) {
33         case GET_MAX_VOLUME: {
34             AUDIO_DEBUG_LOG("GET_MAX_VOLUME AudioManagerStub");
35             int volumeType = data.ReadInt32();
36             AUDIO_DEBUG_LOG("GET_MAX_VOLUME volumeType received from client= %{public}d", volumeType);
37             AudioVolumeType volumeStreamConfig =
38                    static_cast<AudioVolumeType>(volumeType);
39             AUDIO_DEBUG_LOG("GET_MAX_VOLUME volumeType= %{public}d", volumeStreamConfig);
40             int32_t ret = GetMaxVolume(volumeStreamConfig);
41             reply.WriteInt32(ret);
42             return AUDIO_OK;
43         }
44         case GET_MIN_VOLUME: {
45             AUDIO_DEBUG_LOG("GET_MIN_VOLUME AudioManagerStub");
46             int volumeType = data.ReadInt32();
47             AUDIO_DEBUG_LOG("GET_MIN_VOLUME volumeType received from client= %{public}d", volumeType);
48             AudioVolumeType volumeStreamConfig =
49                    static_cast<AudioVolumeType>(volumeType);
50             AUDIO_DEBUG_LOG("GET_MIN_VOLUME volumeType= %{public}d", volumeStreamConfig);
51             int32_t ret = GetMinVolume(volumeStreamConfig);
52             reply.WriteInt32(ret);
53             return AUDIO_OK;
54         }
55         case SET_AUDIO_PARAMETER: {
56             AUDIO_DEBUG_LOG("SET_AUDIO_PARAMETER AudioManagerStub");
57             const std::string key = data.ReadString();
58             const std::string value = data.ReadString();
59             AUDIO_DEBUG_LOG("SET_AUDIO_PARAMETER key-value pair from client= %{public}s, %{public}s",
60                             key.c_str(), value.c_str());
61             SetAudioParameter(key, value);
62             return AUDIO_OK;
63         }
64         case GET_AUDIO_PARAMETER: {
65             AUDIO_DEBUG_LOG("GET_AUDIO_PARAMETER AudioManagerStub");
66             const std::string key = data.ReadString();
67             AUDIO_DEBUG_LOG("GET_AUDIO_PARAMETER key received from client= %{public}s", key.c_str());
68             const std::string value = GetAudioParameter(key);
69             reply.WriteString(value);
70             return AUDIO_OK;
71         }
72         case RETRIEVE_COOKIE: {
73             AUDIO_DEBUG_LOG("RETRIEVE_COOKIE AudioManagerStub");
74             int32_t size = 0;
75             const char *cookieInfo = RetrieveCookie(size);
76             reply.WriteInt32(size);
77             if (size > 0) {
78                 AUDIO_DEBUG_LOG("cookie received from server");
79                 reply.WriteRawData(static_cast<const void *>(cookieInfo), size);
80                 free((void *)cookieInfo);
81                 cookieInfo = nullptr;
82             }
83 
84             return AUDIO_OK;
85         }
86         case GET_TRANSACTION_ID: {
87             AUDIO_DEBUG_LOG("GET_TRANSACTION_ID AudioManagerStub");
88             DeviceType deviceType = (static_cast<DeviceType>(data.ReadInt32()));
89             DeviceRole deviceRole = (static_cast<DeviceRole>(data.ReadInt32()));
90             uint64_t transactionId = GetTransactionId(deviceType, deviceRole);
91 
92             reply.WriteUint64(transactionId);
93 
94             return AUDIO_OK;
95         }
96         case SET_MICROPHONE_MUTE: {
97             AUDIO_DEBUG_LOG("SET_MICROPHONE_MUTE AudioManagerStub");
98             bool isMute = data.ReadBool();
99             AUDIO_DEBUG_LOG("SET_MICROPHONE_MUTE isMute value from client= %{public}d", isMute);
100             int32_t result = SetMicrophoneMute(isMute);
101             reply.WriteInt32(result);
102             return AUDIO_OK;
103         }
104         case IS_MICROPHONE_MUTE: {
105             AUDIO_DEBUG_LOG("IS_MICROPHONE_MUTE AudioManagerStub");
106             bool isMute = IsMicrophoneMute();
107             reply.WriteBool(isMute);
108             return AUDIO_OK;
109         }
110         case SET_AUDIO_SCENE: {
111             AUDIO_DEBUG_LOG("SET_AUDIO_SCENE AudioManagerStub");
112             AudioScene audioScene = (static_cast<AudioScene>(data.ReadInt32()));
113             DeviceType activeDevice = (static_cast<DeviceType>(data.ReadInt32()));
114             int32_t result = SetAudioScene(audioScene, activeDevice);
115             reply.WriteInt32(result);
116             return AUDIO_OK;
117         }
118         case UPDATE_ROUTE_REQ: {
119             AUDIO_DEBUG_LOG("UPDATE_ROUTE_REQ AudioManagerStub");
120             DeviceType type = static_cast<DeviceType>(data.ReadInt32());
121             DeviceFlag flag = static_cast<DeviceFlag>(data.ReadInt32());
122             int32_t ret = UpdateActiveDeviceRoute(type, flag);
123             reply.WriteInt32(ret);
124             return AUDIO_OK;
125         }
126         case SET_PARAMETER_CALLBACK: {
127             AUDIO_DEBUG_LOG("SET_PARAMETER_CALLBACK AudioManagerStub");
128             sptr<IRemoteObject> object = data.ReadRemoteObject();
129             if (object == nullptr) {
130                 AUDIO_ERR_LOG("AudioManagerStub: SET_PARAMETER_CALLBACK obj is null");
131                 return AUDIO_ERR;
132             }
133             int32_t result = SetParameterCallback(object);
134             reply.WriteInt32(result);
135             return AUDIO_OK;
136         }
137         case SET_REMOTE_AUDIO_PARAMETER: {
138             AUDIO_DEBUG_LOG("SET_AUDIO_PARAMETER AudioManagerStub");
139             const std::string networkId = data.ReadString();
140             AudioParamKey key = static_cast<AudioParamKey>(data.ReadInt32());
141             const std::string condtion = data.ReadString();
142             const std::string value = data.ReadString();
143             AUDIO_DEBUG_LOG("SET_AUDIO_PARAMETER key-value pair from client= %{public}d, %{public}s",
144                 key, value.c_str());
145             SetAudioParameter(networkId, key, condtion, value);
146             return AUDIO_OK;
147         }
148         case GET_REMOTE_AUDIO_PARAMETER: {
149             AUDIO_DEBUG_LOG("GET_AUDIO_PARAMETER AudioManagerStub");
150             const std::string networkId = data.ReadString();
151             AudioParamKey key = static_cast<AudioParamKey>(data.ReadInt32());
152             const std::string condition = data.ReadString();
153             AUDIO_DEBUG_LOG("GET_AUDIO_PARAMETER key received from client= %{public}d", key);
154             const std::string value = GetAudioParameter(networkId, key, condition);
155             reply.WriteString(value);
156             return AUDIO_OK;
157         }
158         case NOTIFY_DEVICE_INFO: {
159             AUDIO_DEBUG_LOG("NOTIFY_DEVICE_INFO AudioManagerStub");
160             const std::string networkId = data.ReadString();
161             const bool connected = data.ReadBool();
162             NotifyDeviceInfo(networkId, connected);
163             return AUDIO_OK;
164         }
165         case CHECK_REMOTE_DEVICE_STATE: {
166             AUDIO_DEBUG_LOG("CHECK_REMOTE_DEVICE_STATE AudioManagerStub");
167             std::string networkId = data.ReadString();
168             DeviceRole deviceRole = static_cast<DeviceRole>(data.ReadInt32());
169             bool isStartDevice = data.ReadBool();
170             int32_t result = CheckRemoteDeviceState(networkId, deviceRole, isStartDevice);
171             reply.WriteInt32(result);
172             return AUDIO_OK;
173         }
174         case SET_VOICE_VOLUME: {
175             AUDIO_DEBUG_LOG("SET_VOICE_VOLUME AudioManagerStub");
176             const float volume = data.ReadFloat();
177             int32_t result = SetVoiceVolume(volume);
178             reply.WriteInt32(result);
179             return AUDIO_OK;
180         }
181         case SET_AUDIO_MONO_STATE: {
182             AUDIO_DEBUG_LOG("SET_AUDIO_MONO_STATE AudioManagerStub");
183             bool audioMonoState = data.ReadBool();
184             SetAudioMonoState(audioMonoState);
185             return AUDIO_OK;
186         }
187         case SET_AUDIO_BALANCE_VALUE: {
188             AUDIO_DEBUG_LOG("SET_AUDIO_BALANCE_VALUE AudioManagerStub");
189             float audioBalanceValue = data.ReadFloat();
190             SetAudioBalanceValue(audioBalanceValue);
191             return AUDIO_OK;
192         }
193         default: {
194             AUDIO_ERR_LOG("default case, need check AudioManagerStub");
195             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
196         }
197     }
198 }
199 } // namespace AudioStandard
200 } // namespace OHOS
201