Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "IAudioPolicyServiceClient" |
| 18 | #include <utils/Log.h> |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
| 22 | |
| 23 | #include <binder/Parcel.h> |
| 24 | |
| 25 | #include <media/IAudioPolicyServiceClient.h> |
| 26 | #include <media/AudioSystem.h> |
| 27 | |
| 28 | namespace android { |
| 29 | |
| 30 | enum { |
| 31 | PORT_LIST_UPDATE = IBinder::FIRST_CALL_TRANSACTION, |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 32 | PATCH_LIST_UPDATE, |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 33 | MIX_STATE_UPDATE, |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 34 | RECORDING_CONFIGURATION_UPDATE, |
| 35 | VOLUME_GROUP_CHANGED, |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 36 | }; |
| 37 | |
Jean-Michel Trivi | 7281aa9 | 2016-02-17 15:33:40 -0800 | [diff] [blame] | 38 | // ---------------------------------------------------------------------- |
| 39 | inline void readAudioConfigBaseFromParcel(const Parcel& data, audio_config_base_t *config) { |
| 40 | config->sample_rate = data.readUint32(); |
| 41 | config->channel_mask = (audio_channel_mask_t) data.readInt32(); |
| 42 | config->format = (audio_format_t) data.readInt32(); |
| 43 | } |
| 44 | |
| 45 | inline void writeAudioConfigBaseToParcel(Parcel& data, const audio_config_base_t *config) |
| 46 | { |
| 47 | data.writeUint32(config->sample_rate); |
| 48 | data.writeInt32((int32_t) config->channel_mask); |
| 49 | data.writeInt32((int32_t) config->format); |
| 50 | } |
| 51 | |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 52 | inline void readRecordClientInfoFromParcel(const Parcel& data, record_client_info_t *clientInfo) { |
Mikhail Naganov | 2996f67 | 2019-04-18 12:29:59 -0700 | [diff] [blame] | 53 | clientInfo->riid = (audio_unique_id_t) data.readInt32(); |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 54 | clientInfo->uid = (uid_t) data.readUint32(); |
| 55 | clientInfo->session = (audio_session_t) data.readInt32(); |
| 56 | clientInfo->source = (audio_source_t) data.readInt32(); |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 57 | data.read(&clientInfo->port_id, sizeof(audio_port_handle_t)); |
| 58 | clientInfo->silenced = data.readBool(); |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 59 | } |
| 60 | |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 61 | inline void writeRecordClientInfoToParcel(Parcel& data, const record_client_info_t *clientInfo) { |
Mikhail Naganov | 2996f67 | 2019-04-18 12:29:59 -0700 | [diff] [blame] | 62 | data.writeInt32((int32_t) clientInfo->riid); |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 63 | data.writeUint32((uint32_t) clientInfo->uid); |
| 64 | data.writeInt32((int32_t) clientInfo->session); |
| 65 | data.writeInt32((int32_t) clientInfo->source); |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 66 | data.write(&clientInfo->port_id, sizeof(audio_port_handle_t)); |
| 67 | data.writeBool(clientInfo->silenced); |
| 68 | } |
| 69 | |
| 70 | inline void readEffectVectorFromParcel(const Parcel& data, |
| 71 | std::vector<effect_descriptor_t> *effects) { |
| 72 | int32_t numEffects = data.readInt32(); |
| 73 | for (int32_t i = 0; i < numEffects; i++) { |
| 74 | effect_descriptor_t effect; |
| 75 | if (data.read(&effect, sizeof(effect_descriptor_t)) != NO_ERROR) { |
| 76 | break; |
| 77 | } |
| 78 | (*effects).push_back(effect); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | inline void writeEffectVectorToParcel(Parcel& data, std::vector<effect_descriptor_t> effects) { |
| 83 | data.writeUint32((uint32_t) effects.size()); |
| 84 | for (const auto& effect : effects) { |
| 85 | if (data.write(&effect, sizeof(effect_descriptor_t)) != NO_ERROR) { |
| 86 | break; |
| 87 | } |
| 88 | } |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 89 | } |
| 90 | |
Jean-Michel Trivi | 7281aa9 | 2016-02-17 15:33:40 -0800 | [diff] [blame] | 91 | // ---------------------------------------------------------------------- |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 92 | class BpAudioPolicyServiceClient : public BpInterface<IAudioPolicyServiceClient> |
| 93 | { |
| 94 | public: |
Chih-Hung Hsieh | 090ef60 | 2016-04-27 10:39:54 -0700 | [diff] [blame] | 95 | explicit BpAudioPolicyServiceClient(const sp<IBinder>& impl) |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 96 | : BpInterface<IAudioPolicyServiceClient>(impl) |
| 97 | { |
| 98 | } |
| 99 | |
| 100 | void onAudioPortListUpdate() |
| 101 | { |
| 102 | Parcel data, reply; |
| 103 | data.writeInterfaceToken(IAudioPolicyServiceClient::getInterfaceDescriptor()); |
| 104 | remote()->transact(PORT_LIST_UPDATE, data, &reply, IBinder::FLAG_ONEWAY); |
| 105 | } |
| 106 | |
| 107 | void onAudioPatchListUpdate() |
| 108 | { |
| 109 | Parcel data, reply; |
| 110 | data.writeInterfaceToken(IAudioPolicyServiceClient::getInterfaceDescriptor()); |
| 111 | remote()->transact(PATCH_LIST_UPDATE, data, &reply, IBinder::FLAG_ONEWAY); |
| 112 | } |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 113 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 114 | void onAudioVolumeGroupChanged(volume_group_t group, int flags) |
| 115 | { |
| 116 | Parcel data, reply; |
| 117 | data.writeInterfaceToken(IAudioPolicyServiceClient::getInterfaceDescriptor()); |
| 118 | data.writeUint32(group); |
| 119 | data.writeInt32(flags); |
| 120 | remote()->transact(VOLUME_GROUP_CHANGED, data, &reply, IBinder::FLAG_ONEWAY); |
| 121 | } |
| 122 | |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 123 | void onDynamicPolicyMixStateUpdate(String8 regId, int32_t state) |
| 124 | { |
| 125 | Parcel data, reply; |
| 126 | data.writeInterfaceToken(IAudioPolicyServiceClient::getInterfaceDescriptor()); |
| 127 | data.writeString8(regId); |
| 128 | data.writeInt32(state); |
| 129 | remote()->transact(MIX_STATE_UPDATE, data, &reply, IBinder::FLAG_ONEWAY); |
| 130 | } |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 131 | |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 132 | void onRecordingConfigurationUpdate(int event, |
| 133 | const record_client_info_t *clientInfo, |
| 134 | const audio_config_base_t *clientConfig, |
| 135 | std::vector<effect_descriptor_t> clientEffects, |
| 136 | const audio_config_base_t *deviceConfig, |
| 137 | std::vector<effect_descriptor_t> effects, |
| 138 | audio_patch_handle_t patchHandle, |
| 139 | audio_source_t source) { |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 140 | Parcel data, reply; |
| 141 | data.writeInterfaceToken(IAudioPolicyServiceClient::getInterfaceDescriptor()); |
| 142 | data.writeInt32(event); |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 143 | writeRecordClientInfoToParcel(data, clientInfo); |
Jean-Michel Trivi | 7281aa9 | 2016-02-17 15:33:40 -0800 | [diff] [blame] | 144 | writeAudioConfigBaseToParcel(data, clientConfig); |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 145 | writeEffectVectorToParcel(data, clientEffects); |
Jean-Michel Trivi | 7281aa9 | 2016-02-17 15:33:40 -0800 | [diff] [blame] | 146 | writeAudioConfigBaseToParcel(data, deviceConfig); |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 147 | writeEffectVectorToParcel(data, effects); |
Jean-Michel Trivi | 8c7cf3b | 2016-02-25 17:08:24 -0800 | [diff] [blame] | 148 | data.writeInt32(patchHandle); |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 149 | data.writeInt32((int32_t) source); |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 150 | remote()->transact(RECORDING_CONFIGURATION_UPDATE, data, &reply, IBinder::FLAG_ONEWAY); |
| 151 | } |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 152 | }; |
| 153 | |
| 154 | IMPLEMENT_META_INTERFACE(AudioPolicyServiceClient, "android.media.IAudioPolicyServiceClient"); |
| 155 | |
| 156 | // ---------------------------------------------------------------------- |
| 157 | |
| 158 | status_t BnAudioPolicyServiceClient::onTransact( |
| 159 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 160 | { |
| 161 | switch (code) { |
| 162 | case PORT_LIST_UPDATE: { |
| 163 | CHECK_INTERFACE(IAudioPolicyServiceClient, data, reply); |
| 164 | onAudioPortListUpdate(); |
| 165 | return NO_ERROR; |
| 166 | } break; |
| 167 | case PATCH_LIST_UPDATE: { |
| 168 | CHECK_INTERFACE(IAudioPolicyServiceClient, data, reply); |
| 169 | onAudioPatchListUpdate(); |
| 170 | return NO_ERROR; |
| 171 | } break; |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 172 | case VOLUME_GROUP_CHANGED: { |
| 173 | CHECK_INTERFACE(IAudioPolicyServiceClient, data, reply); |
| 174 | volume_group_t group = static_cast<volume_group_t>(data.readUint32()); |
| 175 | int flags = data.readInt32(); |
| 176 | onAudioVolumeGroupChanged(group, flags); |
| 177 | return NO_ERROR; |
| 178 | } break; |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 179 | case MIX_STATE_UPDATE: { |
| 180 | CHECK_INTERFACE(IAudioPolicyServiceClient, data, reply); |
| 181 | String8 regId = data.readString8(); |
| 182 | int32_t state = data.readInt32(); |
| 183 | onDynamicPolicyMixStateUpdate(regId, state); |
| 184 | return NO_ERROR; |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 185 | } break; |
| 186 | case RECORDING_CONFIGURATION_UPDATE: { |
| 187 | CHECK_INTERFACE(IAudioPolicyServiceClient, data, reply); |
| 188 | int event = (int) data.readInt32(); |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 189 | record_client_info_t clientInfo; |
Jean-Michel Trivi | 7281aa9 | 2016-02-17 15:33:40 -0800 | [diff] [blame] | 190 | audio_config_base_t clientConfig; |
| 191 | audio_config_base_t deviceConfig; |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 192 | readRecordClientInfoFromParcel(data, &clientInfo); |
Jean-Michel Trivi | 7281aa9 | 2016-02-17 15:33:40 -0800 | [diff] [blame] | 193 | readAudioConfigBaseFromParcel(data, &clientConfig); |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 194 | std::vector<effect_descriptor_t> clientEffects; |
| 195 | readEffectVectorFromParcel(data, &clientEffects); |
Jean-Michel Trivi | 7281aa9 | 2016-02-17 15:33:40 -0800 | [diff] [blame] | 196 | readAudioConfigBaseFromParcel(data, &deviceConfig); |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 197 | std::vector<effect_descriptor_t> effects; |
| 198 | readEffectVectorFromParcel(data, &effects); |
Jean-Michel Trivi | 8c7cf3b | 2016-02-25 17:08:24 -0800 | [diff] [blame] | 199 | audio_patch_handle_t patchHandle = (audio_patch_handle_t) data.readInt32(); |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 200 | audio_source_t source = (audio_source_t) data.readInt32(); |
| 201 | onRecordingConfigurationUpdate(event, &clientInfo, &clientConfig, clientEffects, |
| 202 | &deviceConfig, effects, patchHandle, source); |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 203 | return NO_ERROR; |
| 204 | } break; |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 205 | default: |
| 206 | return BBinder::onTransact(code, data, reply, flags); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | // ---------------------------------------------------------------------------- |
| 211 | |
Glenn Kasten | 40bc906 | 2015-03-20 09:09:33 -0700 | [diff] [blame] | 212 | } // namespace android |