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) { |
| 53 | clientInfo->uid = (uid_t) data.readUint32(); |
| 54 | clientInfo->session = (audio_session_t) data.readInt32(); |
| 55 | clientInfo->source = (audio_source_t) data.readInt32(); |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 56 | data.read(&clientInfo->port_id, sizeof(audio_port_handle_t)); |
| 57 | clientInfo->silenced = data.readBool(); |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 58 | } |
| 59 | |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 60 | inline void writeRecordClientInfoToParcel(Parcel& data, const record_client_info_t *clientInfo) { |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 61 | data.writeUint32((uint32_t) clientInfo->uid); |
| 62 | data.writeInt32((int32_t) clientInfo->session); |
| 63 | data.writeInt32((int32_t) clientInfo->source); |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 64 | data.write(&clientInfo->port_id, sizeof(audio_port_handle_t)); |
| 65 | data.writeBool(clientInfo->silenced); |
| 66 | } |
| 67 | |
| 68 | inline void readEffectVectorFromParcel(const Parcel& data, |
| 69 | std::vector<effect_descriptor_t> *effects) { |
| 70 | int32_t numEffects = data.readInt32(); |
| 71 | for (int32_t i = 0; i < numEffects; i++) { |
| 72 | effect_descriptor_t effect; |
| 73 | if (data.read(&effect, sizeof(effect_descriptor_t)) != NO_ERROR) { |
| 74 | break; |
| 75 | } |
| 76 | (*effects).push_back(effect); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | inline void writeEffectVectorToParcel(Parcel& data, std::vector<effect_descriptor_t> effects) { |
| 81 | data.writeUint32((uint32_t) effects.size()); |
| 82 | for (const auto& effect : effects) { |
| 83 | if (data.write(&effect, sizeof(effect_descriptor_t)) != NO_ERROR) { |
| 84 | break; |
| 85 | } |
| 86 | } |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 87 | } |
| 88 | |
Jean-Michel Trivi | 7281aa9 | 2016-02-17 15:33:40 -0800 | [diff] [blame] | 89 | // ---------------------------------------------------------------------- |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 90 | class BpAudioPolicyServiceClient : public BpInterface<IAudioPolicyServiceClient> |
| 91 | { |
| 92 | public: |
Chih-Hung Hsieh | 090ef60 | 2016-04-27 10:39:54 -0700 | [diff] [blame] | 93 | explicit BpAudioPolicyServiceClient(const sp<IBinder>& impl) |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 94 | : BpInterface<IAudioPolicyServiceClient>(impl) |
| 95 | { |
| 96 | } |
| 97 | |
| 98 | void onAudioPortListUpdate() |
| 99 | { |
| 100 | Parcel data, reply; |
| 101 | data.writeInterfaceToken(IAudioPolicyServiceClient::getInterfaceDescriptor()); |
| 102 | remote()->transact(PORT_LIST_UPDATE, data, &reply, IBinder::FLAG_ONEWAY); |
| 103 | } |
| 104 | |
| 105 | void onAudioPatchListUpdate() |
| 106 | { |
| 107 | Parcel data, reply; |
| 108 | data.writeInterfaceToken(IAudioPolicyServiceClient::getInterfaceDescriptor()); |
| 109 | remote()->transact(PATCH_LIST_UPDATE, data, &reply, IBinder::FLAG_ONEWAY); |
| 110 | } |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 111 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 112 | void onAudioVolumeGroupChanged(volume_group_t group, int flags) |
| 113 | { |
| 114 | Parcel data, reply; |
| 115 | data.writeInterfaceToken(IAudioPolicyServiceClient::getInterfaceDescriptor()); |
| 116 | data.writeUint32(group); |
| 117 | data.writeInt32(flags); |
| 118 | remote()->transact(VOLUME_GROUP_CHANGED, data, &reply, IBinder::FLAG_ONEWAY); |
| 119 | } |
| 120 | |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 121 | void onDynamicPolicyMixStateUpdate(String8 regId, int32_t state) |
| 122 | { |
| 123 | Parcel data, reply; |
| 124 | data.writeInterfaceToken(IAudioPolicyServiceClient::getInterfaceDescriptor()); |
| 125 | data.writeString8(regId); |
| 126 | data.writeInt32(state); |
| 127 | remote()->transact(MIX_STATE_UPDATE, data, &reply, IBinder::FLAG_ONEWAY); |
| 128 | } |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 129 | |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 130 | void onRecordingConfigurationUpdate(int event, |
| 131 | const record_client_info_t *clientInfo, |
| 132 | const audio_config_base_t *clientConfig, |
| 133 | std::vector<effect_descriptor_t> clientEffects, |
| 134 | const audio_config_base_t *deviceConfig, |
| 135 | std::vector<effect_descriptor_t> effects, |
| 136 | audio_patch_handle_t patchHandle, |
| 137 | audio_source_t source) { |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 138 | Parcel data, reply; |
| 139 | data.writeInterfaceToken(IAudioPolicyServiceClient::getInterfaceDescriptor()); |
| 140 | data.writeInt32(event); |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 141 | writeRecordClientInfoToParcel(data, clientInfo); |
Jean-Michel Trivi | 7281aa9 | 2016-02-17 15:33:40 -0800 | [diff] [blame] | 142 | writeAudioConfigBaseToParcel(data, clientConfig); |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 143 | writeEffectVectorToParcel(data, clientEffects); |
Jean-Michel Trivi | 7281aa9 | 2016-02-17 15:33:40 -0800 | [diff] [blame] | 144 | writeAudioConfigBaseToParcel(data, deviceConfig); |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 145 | writeEffectVectorToParcel(data, effects); |
Jean-Michel Trivi | 8c7cf3b | 2016-02-25 17:08:24 -0800 | [diff] [blame] | 146 | data.writeInt32(patchHandle); |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 147 | data.writeInt32((int32_t) source); |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 148 | remote()->transact(RECORDING_CONFIGURATION_UPDATE, data, &reply, IBinder::FLAG_ONEWAY); |
| 149 | } |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 150 | }; |
| 151 | |
| 152 | IMPLEMENT_META_INTERFACE(AudioPolicyServiceClient, "android.media.IAudioPolicyServiceClient"); |
| 153 | |
| 154 | // ---------------------------------------------------------------------- |
| 155 | |
| 156 | status_t BnAudioPolicyServiceClient::onTransact( |
| 157 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 158 | { |
| 159 | switch (code) { |
| 160 | case PORT_LIST_UPDATE: { |
| 161 | CHECK_INTERFACE(IAudioPolicyServiceClient, data, reply); |
| 162 | onAudioPortListUpdate(); |
| 163 | return NO_ERROR; |
| 164 | } break; |
| 165 | case PATCH_LIST_UPDATE: { |
| 166 | CHECK_INTERFACE(IAudioPolicyServiceClient, data, reply); |
| 167 | onAudioPatchListUpdate(); |
| 168 | return NO_ERROR; |
| 169 | } break; |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 170 | case VOLUME_GROUP_CHANGED: { |
| 171 | CHECK_INTERFACE(IAudioPolicyServiceClient, data, reply); |
| 172 | volume_group_t group = static_cast<volume_group_t>(data.readUint32()); |
| 173 | int flags = data.readInt32(); |
| 174 | onAudioVolumeGroupChanged(group, flags); |
| 175 | return NO_ERROR; |
| 176 | } break; |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 177 | case MIX_STATE_UPDATE: { |
| 178 | CHECK_INTERFACE(IAudioPolicyServiceClient, data, reply); |
| 179 | String8 regId = data.readString8(); |
| 180 | int32_t state = data.readInt32(); |
| 181 | onDynamicPolicyMixStateUpdate(regId, state); |
| 182 | return NO_ERROR; |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 183 | } break; |
| 184 | case RECORDING_CONFIGURATION_UPDATE: { |
| 185 | CHECK_INTERFACE(IAudioPolicyServiceClient, data, reply); |
| 186 | int event = (int) data.readInt32(); |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 187 | record_client_info_t clientInfo; |
Jean-Michel Trivi | 7281aa9 | 2016-02-17 15:33:40 -0800 | [diff] [blame] | 188 | audio_config_base_t clientConfig; |
| 189 | audio_config_base_t deviceConfig; |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 190 | readRecordClientInfoFromParcel(data, &clientInfo); |
Jean-Michel Trivi | 7281aa9 | 2016-02-17 15:33:40 -0800 | [diff] [blame] | 191 | readAudioConfigBaseFromParcel(data, &clientConfig); |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 192 | std::vector<effect_descriptor_t> clientEffects; |
| 193 | readEffectVectorFromParcel(data, &clientEffects); |
Jean-Michel Trivi | 7281aa9 | 2016-02-17 15:33:40 -0800 | [diff] [blame] | 194 | readAudioConfigBaseFromParcel(data, &deviceConfig); |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 195 | std::vector<effect_descriptor_t> effects; |
| 196 | readEffectVectorFromParcel(data, &effects); |
Jean-Michel Trivi | 8c7cf3b | 2016-02-25 17:08:24 -0800 | [diff] [blame] | 197 | audio_patch_handle_t patchHandle = (audio_patch_handle_t) data.readInt32(); |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 198 | audio_source_t source = (audio_source_t) data.readInt32(); |
| 199 | onRecordingConfigurationUpdate(event, &clientInfo, &clientConfig, clientEffects, |
| 200 | &deviceConfig, effects, patchHandle, source); |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 201 | return NO_ERROR; |
| 202 | } break; |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 203 | default: |
| 204 | return BBinder::onTransact(code, data, reply, flags); |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | // ---------------------------------------------------------------------------- |
| 209 | |
Glenn Kasten | 40bc906 | 2015-03-20 09:09:33 -0700 | [diff] [blame] | 210 | } // namespace android |