Home | History | Annotate | Download | only in libmedia
      1 /*
      2 **
      3 ** Copyright 2009, The Android Open Source Project
      4 **
      5 ** Licensed under the Apache License, Version 2.0 (the "License");
      6 ** you may not use this file except in compliance with the License.
      7 ** You may obtain a copy of the License at
      8 **
      9 **     http://www.apache.org/licenses/LICENSE-2.0
     10 **
     11 ** Unless required by applicable law or agreed to in writing, software
     12 ** distributed under the License is distributed on an "AS IS" BASIS,
     13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 ** See the License for the specific language governing permissions and
     15 ** limitations under the License.
     16 */
     17 
     18 #define LOG_TAG "IAudioPolicyService"
     19 #include <utils/Log.h>
     20 
     21 #include <stdint.h>
     22 #include <sys/types.h>
     23 
     24 #include <binder/Parcel.h>
     25 
     26 #include <media/IAudioPolicyService.h>
     27 
     28 #include <system/audio.h>
     29 
     30 namespace android {
     31 
     32 enum {
     33     SET_DEVICE_CONNECTION_STATE = IBinder::FIRST_CALL_TRANSACTION,
     34     GET_DEVICE_CONNECTION_STATE,
     35     SET_PHONE_STATE,
     36     SET_RINGER_MODE,    // reserved, no longer used
     37     SET_FORCE_USE,
     38     GET_FORCE_USE,
     39     GET_OUTPUT,
     40     START_OUTPUT,
     41     STOP_OUTPUT,
     42     RELEASE_OUTPUT,
     43     GET_INPUT,
     44     START_INPUT,
     45     STOP_INPUT,
     46     RELEASE_INPUT,
     47     INIT_STREAM_VOLUME,
     48     SET_STREAM_VOLUME,
     49     GET_STREAM_VOLUME,
     50     GET_STRATEGY_FOR_STREAM,
     51     GET_OUTPUT_FOR_EFFECT,
     52     REGISTER_EFFECT,
     53     UNREGISTER_EFFECT,
     54     IS_STREAM_ACTIVE,
     55     IS_SOURCE_ACTIVE,
     56     GET_DEVICES_FOR_STREAM,
     57     QUERY_DEFAULT_PRE_PROCESSING,
     58     SET_EFFECT_ENABLED,
     59     IS_STREAM_ACTIVE_REMOTELY,
     60     IS_OFFLOAD_SUPPORTED
     61 };
     62 
     63 class BpAudioPolicyService : public BpInterface<IAudioPolicyService>
     64 {
     65 public:
     66     BpAudioPolicyService(const sp<IBinder>& impl)
     67         : BpInterface<IAudioPolicyService>(impl)
     68     {
     69     }
     70 
     71     virtual status_t setDeviceConnectionState(
     72                                     audio_devices_t device,
     73                                     audio_policy_dev_state_t state,
     74                                     const char *device_address)
     75     {
     76         Parcel data, reply;
     77         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
     78         data.writeInt32(static_cast <uint32_t>(device));
     79         data.writeInt32(static_cast <uint32_t>(state));
     80         data.writeCString(device_address);
     81         remote()->transact(SET_DEVICE_CONNECTION_STATE, data, &reply);
     82         return static_cast <status_t> (reply.readInt32());
     83     }
     84 
     85     virtual audio_policy_dev_state_t getDeviceConnectionState(
     86                                     audio_devices_t device,
     87                                     const char *device_address)
     88     {
     89         Parcel data, reply;
     90         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
     91         data.writeInt32(static_cast <uint32_t>(device));
     92         data.writeCString(device_address);
     93         remote()->transact(GET_DEVICE_CONNECTION_STATE, data, &reply);
     94         return static_cast <audio_policy_dev_state_t>(reply.readInt32());
     95     }
     96 
     97     virtual status_t setPhoneState(audio_mode_t state)
     98     {
     99         Parcel data, reply;
    100         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    101         data.writeInt32(state);
    102         remote()->transact(SET_PHONE_STATE, data, &reply);
    103         return static_cast <status_t> (reply.readInt32());
    104     }
    105 
    106     virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
    107     {
    108         Parcel data, reply;
    109         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    110         data.writeInt32(static_cast <uint32_t>(usage));
    111         data.writeInt32(static_cast <uint32_t>(config));
    112         remote()->transact(SET_FORCE_USE, data, &reply);
    113         return static_cast <status_t> (reply.readInt32());
    114     }
    115 
    116     virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage)
    117     {
    118         Parcel data, reply;
    119         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    120         data.writeInt32(static_cast <uint32_t>(usage));
    121         remote()->transact(GET_FORCE_USE, data, &reply);
    122         return static_cast <audio_policy_forced_cfg_t> (reply.readInt32());
    123     }
    124 
    125     virtual audio_io_handle_t getOutput(
    126                                         audio_stream_type_t stream,
    127                                         uint32_t samplingRate,
    128                                         audio_format_t format,
    129                                         audio_channel_mask_t channelMask,
    130                                         audio_output_flags_t flags,
    131                                         const audio_offload_info_t *offloadInfo)
    132     {
    133         Parcel data, reply;
    134         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    135         data.writeInt32(static_cast <uint32_t>(stream));
    136         data.writeInt32(samplingRate);
    137         data.writeInt32(static_cast <uint32_t>(format));
    138         data.writeInt32(channelMask);
    139         data.writeInt32(static_cast <uint32_t>(flags));
    140         if (offloadInfo == NULL) {
    141             data.writeInt32(0);
    142         } else {
    143             data.writeInt32(1);
    144             data.write(offloadInfo, sizeof(audio_offload_info_t));
    145         }
    146         remote()->transact(GET_OUTPUT, data, &reply);
    147         return static_cast <audio_io_handle_t> (reply.readInt32());
    148     }
    149 
    150     virtual status_t startOutput(audio_io_handle_t output,
    151                                  audio_stream_type_t stream,
    152                                  int session)
    153     {
    154         Parcel data, reply;
    155         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    156         data.writeInt32(output);
    157         data.writeInt32((int32_t) stream);
    158         data.writeInt32(session);
    159         remote()->transact(START_OUTPUT, data, &reply);
    160         return static_cast <status_t> (reply.readInt32());
    161     }
    162 
    163     virtual status_t stopOutput(audio_io_handle_t output,
    164                                 audio_stream_type_t stream,
    165                                 int session)
    166     {
    167         Parcel data, reply;
    168         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    169         data.writeInt32(output);
    170         data.writeInt32((int32_t) stream);
    171         data.writeInt32(session);
    172         remote()->transact(STOP_OUTPUT, data, &reply);
    173         return static_cast <status_t> (reply.readInt32());
    174     }
    175 
    176     virtual void releaseOutput(audio_io_handle_t output)
    177     {
    178         Parcel data, reply;
    179         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    180         data.writeInt32(output);
    181         remote()->transact(RELEASE_OUTPUT, data, &reply);
    182     }
    183 
    184     virtual audio_io_handle_t getInput(
    185                                     audio_source_t inputSource,
    186                                     uint32_t samplingRate,
    187                                     audio_format_t format,
    188                                     audio_channel_mask_t channelMask,
    189                                     int audioSession)
    190     {
    191         Parcel data, reply;
    192         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    193         data.writeInt32((int32_t) inputSource);
    194         data.writeInt32(samplingRate);
    195         data.writeInt32(static_cast <uint32_t>(format));
    196         data.writeInt32(channelMask);
    197         data.writeInt32(audioSession);
    198         remote()->transact(GET_INPUT, data, &reply);
    199         return static_cast <audio_io_handle_t> (reply.readInt32());
    200     }
    201 
    202     virtual status_t startInput(audio_io_handle_t input)
    203     {
    204         Parcel data, reply;
    205         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    206         data.writeInt32(input);
    207         remote()->transact(START_INPUT, data, &reply);
    208         return static_cast <status_t> (reply.readInt32());
    209     }
    210 
    211     virtual status_t stopInput(audio_io_handle_t input)
    212     {
    213         Parcel data, reply;
    214         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    215         data.writeInt32(input);
    216         remote()->transact(STOP_INPUT, data, &reply);
    217         return static_cast <status_t> (reply.readInt32());
    218     }
    219 
    220     virtual void releaseInput(audio_io_handle_t input)
    221     {
    222         Parcel data, reply;
    223         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    224         data.writeInt32(input);
    225         remote()->transact(RELEASE_INPUT, data, &reply);
    226     }
    227 
    228     virtual status_t initStreamVolume(audio_stream_type_t stream,
    229                                     int indexMin,
    230                                     int indexMax)
    231     {
    232         Parcel data, reply;
    233         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    234         data.writeInt32(static_cast <uint32_t>(stream));
    235         data.writeInt32(indexMin);
    236         data.writeInt32(indexMax);
    237         remote()->transact(INIT_STREAM_VOLUME, data, &reply);
    238         return static_cast <status_t> (reply.readInt32());
    239     }
    240 
    241     virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
    242                                           int index,
    243                                           audio_devices_t device)
    244     {
    245         Parcel data, reply;
    246         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    247         data.writeInt32(static_cast <uint32_t>(stream));
    248         data.writeInt32(index);
    249         data.writeInt32(static_cast <uint32_t>(device));
    250         remote()->transact(SET_STREAM_VOLUME, data, &reply);
    251         return static_cast <status_t> (reply.readInt32());
    252     }
    253 
    254     virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
    255                                           int *index,
    256                                           audio_devices_t device)
    257     {
    258         Parcel data, reply;
    259         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    260         data.writeInt32(static_cast <uint32_t>(stream));
    261         data.writeInt32(static_cast <uint32_t>(device));
    262 
    263         remote()->transact(GET_STREAM_VOLUME, data, &reply);
    264         int lIndex = reply.readInt32();
    265         if (index) *index = lIndex;
    266         return static_cast <status_t> (reply.readInt32());
    267     }
    268 
    269     virtual uint32_t getStrategyForStream(audio_stream_type_t stream)
    270     {
    271         Parcel data, reply;
    272         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    273         data.writeInt32(static_cast <uint32_t>(stream));
    274         remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply);
    275         return reply.readInt32();
    276     }
    277 
    278     virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream)
    279     {
    280         Parcel data, reply;
    281         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    282         data.writeInt32(static_cast <uint32_t>(stream));
    283         remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
    284         return (audio_devices_t) reply.readInt32();
    285     }
    286 
    287     virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc)
    288     {
    289         Parcel data, reply;
    290         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    291         data.write(desc, sizeof(effect_descriptor_t));
    292         remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply);
    293         return static_cast <audio_io_handle_t> (reply.readInt32());
    294     }
    295 
    296     virtual status_t registerEffect(const effect_descriptor_t *desc,
    297                                         audio_io_handle_t io,
    298                                         uint32_t strategy,
    299                                         int session,
    300                                         int id)
    301     {
    302         Parcel data, reply;
    303         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    304         data.write(desc, sizeof(effect_descriptor_t));
    305         data.writeInt32(io);
    306         data.writeInt32(strategy);
    307         data.writeInt32(session);
    308         data.writeInt32(id);
    309         remote()->transact(REGISTER_EFFECT, data, &reply);
    310         return static_cast <status_t> (reply.readInt32());
    311     }
    312 
    313     virtual status_t unregisterEffect(int id)
    314     {
    315         Parcel data, reply;
    316         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    317         data.writeInt32(id);
    318         remote()->transact(UNREGISTER_EFFECT, data, &reply);
    319         return static_cast <status_t> (reply.readInt32());
    320     }
    321 
    322     virtual status_t setEffectEnabled(int id, bool enabled)
    323     {
    324         Parcel data, reply;
    325         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    326         data.writeInt32(id);
    327         data.writeInt32(enabled);
    328         remote()->transact(SET_EFFECT_ENABLED, data, &reply);
    329         return static_cast <status_t> (reply.readInt32());
    330     }
    331 
    332     virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
    333     {
    334         Parcel data, reply;
    335         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    336         data.writeInt32((int32_t) stream);
    337         data.writeInt32(inPastMs);
    338         remote()->transact(IS_STREAM_ACTIVE, data, &reply);
    339         return reply.readInt32();
    340     }
    341 
    342     virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
    343     {
    344         Parcel data, reply;
    345         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    346         data.writeInt32((int32_t) stream);
    347         data.writeInt32(inPastMs);
    348         remote()->transact(IS_STREAM_ACTIVE_REMOTELY, data, &reply);
    349         return reply.readInt32();
    350     }
    351 
    352     virtual bool isSourceActive(audio_source_t source) const
    353     {
    354         Parcel data, reply;
    355         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    356         data.writeInt32((int32_t) source);
    357         remote()->transact(IS_SOURCE_ACTIVE, data, &reply);
    358         return reply.readInt32();
    359     }
    360 
    361     virtual status_t queryDefaultPreProcessing(int audioSession,
    362                                                effect_descriptor_t *descriptors,
    363                                                uint32_t *count)
    364     {
    365         if (descriptors == NULL || count == NULL) {
    366             return BAD_VALUE;
    367         }
    368         Parcel data, reply;
    369         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    370         data.writeInt32(audioSession);
    371         data.writeInt32(*count);
    372         status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply);
    373         if (status != NO_ERROR) {
    374             return status;
    375         }
    376         status = static_cast <status_t> (reply.readInt32());
    377         uint32_t retCount = reply.readInt32();
    378         if (retCount != 0) {
    379             uint32_t numDesc = (retCount < *count) ? retCount : *count;
    380             reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc);
    381         }
    382         *count = retCount;
    383         return status;
    384     }
    385 
    386     virtual bool isOffloadSupported(const audio_offload_info_t& info)
    387     {
    388         Parcel data, reply;
    389         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    390         data.write(&info, sizeof(audio_offload_info_t));
    391         remote()->transact(IS_OFFLOAD_SUPPORTED, data, &reply);
    392         return reply.readInt32();    }
    393 };
    394 
    395 IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
    396 
    397 // ----------------------------------------------------------------------
    398 
    399 
    400 status_t BnAudioPolicyService::onTransact(
    401     uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
    402 {
    403     switch (code) {
    404         case SET_DEVICE_CONNECTION_STATE: {
    405             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    406             audio_devices_t device =
    407                     static_cast <audio_devices_t>(data.readInt32());
    408             audio_policy_dev_state_t state =
    409                     static_cast <audio_policy_dev_state_t>(data.readInt32());
    410             const char *device_address = data.readCString();
    411             reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
    412                                                                               state,
    413                                                                               device_address)));
    414             return NO_ERROR;
    415         } break;
    416 
    417         case GET_DEVICE_CONNECTION_STATE: {
    418             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    419             audio_devices_t device =
    420                     static_cast<audio_devices_t> (data.readInt32());
    421             const char *device_address = data.readCString();
    422             reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
    423                                                                               device_address)));
    424             return NO_ERROR;
    425         } break;
    426 
    427         case SET_PHONE_STATE: {
    428             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    429             reply->writeInt32(static_cast <uint32_t>(setPhoneState(
    430                     (audio_mode_t) data.readInt32())));
    431             return NO_ERROR;
    432         } break;
    433 
    434         case SET_FORCE_USE: {
    435             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    436             audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
    437                     data.readInt32());
    438             audio_policy_forced_cfg_t config =
    439                     static_cast <audio_policy_forced_cfg_t>(data.readInt32());
    440             reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
    441             return NO_ERROR;
    442         } break;
    443 
    444         case GET_FORCE_USE: {
    445             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    446             audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
    447                     data.readInt32());
    448             reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
    449             return NO_ERROR;
    450         } break;
    451 
    452         case GET_OUTPUT: {
    453             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    454             audio_stream_type_t stream =
    455                     static_cast <audio_stream_type_t>(data.readInt32());
    456             uint32_t samplingRate = data.readInt32();
    457             audio_format_t format = (audio_format_t) data.readInt32();
    458             audio_channel_mask_t channelMask = data.readInt32();
    459             audio_output_flags_t flags =
    460                     static_cast <audio_output_flags_t>(data.readInt32());
    461             bool hasOffloadInfo = data.readInt32() != 0;
    462             audio_offload_info_t offloadInfo;
    463             if (hasOffloadInfo) {
    464                 data.read(&offloadInfo, sizeof(audio_offload_info_t));
    465             }
    466             audio_io_handle_t output = getOutput(stream,
    467                                                  samplingRate,
    468                                                  format,
    469                                                  channelMask,
    470                                                  flags,
    471                                                  hasOffloadInfo ? &offloadInfo : NULL);
    472             reply->writeInt32(static_cast <int>(output));
    473             return NO_ERROR;
    474         } break;
    475 
    476         case START_OUTPUT: {
    477             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    478             audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
    479             uint32_t stream = data.readInt32();
    480             int session = data.readInt32();
    481             reply->writeInt32(static_cast <uint32_t>(startOutput(output,
    482                                                                  (audio_stream_type_t)stream,
    483                                                                  session)));
    484             return NO_ERROR;
    485         } break;
    486 
    487         case STOP_OUTPUT: {
    488             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    489             audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
    490             uint32_t stream = data.readInt32();
    491             int session = data.readInt32();
    492             reply->writeInt32(static_cast <uint32_t>(stopOutput(output,
    493                                                                 (audio_stream_type_t)stream,
    494                                                                 session)));
    495             return NO_ERROR;
    496         } break;
    497 
    498         case RELEASE_OUTPUT: {
    499             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    500             audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
    501             releaseOutput(output);
    502             return NO_ERROR;
    503         } break;
    504 
    505         case GET_INPUT: {
    506             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    507             audio_source_t inputSource = (audio_source_t) data.readInt32();
    508             uint32_t samplingRate = data.readInt32();
    509             audio_format_t format = (audio_format_t) data.readInt32();
    510             audio_channel_mask_t channelMask = data.readInt32();
    511             int audioSession = data.readInt32();
    512             audio_io_handle_t input = getInput(inputSource,
    513                                                samplingRate,
    514                                                format,
    515                                                channelMask,
    516                                                audioSession);
    517             reply->writeInt32(static_cast <int>(input));
    518             return NO_ERROR;
    519         } break;
    520 
    521         case START_INPUT: {
    522             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    523             audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
    524             reply->writeInt32(static_cast <uint32_t>(startInput(input)));
    525             return NO_ERROR;
    526         } break;
    527 
    528         case STOP_INPUT: {
    529             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    530             audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
    531             reply->writeInt32(static_cast <uint32_t>(stopInput(input)));
    532             return NO_ERROR;
    533         } break;
    534 
    535         case RELEASE_INPUT: {
    536             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    537             audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
    538             releaseInput(input);
    539             return NO_ERROR;
    540         } break;
    541 
    542         case INIT_STREAM_VOLUME: {
    543             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    544             audio_stream_type_t stream =
    545                     static_cast <audio_stream_type_t>(data.readInt32());
    546             int indexMin = data.readInt32();
    547             int indexMax = data.readInt32();
    548             reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
    549             return NO_ERROR;
    550         } break;
    551 
    552         case SET_STREAM_VOLUME: {
    553             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    554             audio_stream_type_t stream =
    555                     static_cast <audio_stream_type_t>(data.readInt32());
    556             int index = data.readInt32();
    557             audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
    558             reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream,
    559                                                                           index,
    560                                                                           device)));
    561             return NO_ERROR;
    562         } break;
    563 
    564         case GET_STREAM_VOLUME: {
    565             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    566             audio_stream_type_t stream =
    567                     static_cast <audio_stream_type_t>(data.readInt32());
    568             audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
    569             int index;
    570             status_t status = getStreamVolumeIndex(stream, &index, device);
    571             reply->writeInt32(index);
    572             reply->writeInt32(static_cast <uint32_t>(status));
    573             return NO_ERROR;
    574         } break;
    575 
    576         case GET_STRATEGY_FOR_STREAM: {
    577             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    578             audio_stream_type_t stream =
    579                     static_cast <audio_stream_type_t>(data.readInt32());
    580             reply->writeInt32(getStrategyForStream(stream));
    581             return NO_ERROR;
    582         } break;
    583 
    584         case GET_DEVICES_FOR_STREAM: {
    585             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    586             audio_stream_type_t stream =
    587                     static_cast <audio_stream_type_t>(data.readInt32());
    588             reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
    589             return NO_ERROR;
    590         } break;
    591 
    592         case GET_OUTPUT_FOR_EFFECT: {
    593             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    594             effect_descriptor_t desc;
    595             data.read(&desc, sizeof(effect_descriptor_t));
    596             audio_io_handle_t output = getOutputForEffect(&desc);
    597             reply->writeInt32(static_cast <int>(output));
    598             return NO_ERROR;
    599         } break;
    600 
    601         case REGISTER_EFFECT: {
    602             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    603             effect_descriptor_t desc;
    604             data.read(&desc, sizeof(effect_descriptor_t));
    605             audio_io_handle_t io = data.readInt32();
    606             uint32_t strategy = data.readInt32();
    607             int session = data.readInt32();
    608             int id = data.readInt32();
    609             reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
    610                                                                    io,
    611                                                                    strategy,
    612                                                                    session,
    613                                                                    id)));
    614             return NO_ERROR;
    615         } break;
    616 
    617         case UNREGISTER_EFFECT: {
    618             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    619             int id = data.readInt32();
    620             reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
    621             return NO_ERROR;
    622         } break;
    623 
    624         case SET_EFFECT_ENABLED: {
    625             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    626             int id = data.readInt32();
    627             bool enabled = static_cast <bool>(data.readInt32());
    628             reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
    629             return NO_ERROR;
    630         } break;
    631 
    632         case IS_STREAM_ACTIVE: {
    633             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    634             audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
    635             uint32_t inPastMs = (uint32_t)data.readInt32();
    636             reply->writeInt32( isStreamActive((audio_stream_type_t) stream, inPastMs) );
    637             return NO_ERROR;
    638         } break;
    639 
    640         case IS_STREAM_ACTIVE_REMOTELY: {
    641             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    642             audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
    643             uint32_t inPastMs = (uint32_t)data.readInt32();
    644             reply->writeInt32( isStreamActiveRemotely((audio_stream_type_t) stream, inPastMs) );
    645             return NO_ERROR;
    646         } break;
    647 
    648         case IS_SOURCE_ACTIVE: {
    649             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    650             audio_source_t source = (audio_source_t) data.readInt32();
    651             reply->writeInt32( isSourceActive(source));
    652             return NO_ERROR;
    653         }
    654 
    655         case QUERY_DEFAULT_PRE_PROCESSING: {
    656             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    657             int audioSession = data.readInt32();
    658             uint32_t count = data.readInt32();
    659             uint32_t retCount = count;
    660             effect_descriptor_t *descriptors =
    661                     (effect_descriptor_t *)new char[count * sizeof(effect_descriptor_t)];
    662             status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
    663             reply->writeInt32(status);
    664             if (status != NO_ERROR && status != NO_MEMORY) {
    665                 retCount = 0;
    666             }
    667             reply->writeInt32(retCount);
    668             if (retCount) {
    669                 if (retCount < count) {
    670                     count = retCount;
    671                 }
    672                 reply->write(descriptors, sizeof(effect_descriptor_t) * count);
    673             }
    674             delete[] descriptors;
    675             return status;
    676         }
    677 
    678         case IS_OFFLOAD_SUPPORTED: {
    679             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    680             audio_offload_info_t info;
    681             data.read(&info, sizeof(audio_offload_info_t));
    682             bool isSupported = isOffloadSupported(info);
    683             reply->writeInt32(isSupported);
    684             return NO_ERROR;
    685         }
    686 
    687         default:
    688             return BBinder::onTransact(code, data, reply, flags);
    689     }
    690 }
    691 
    692 // ----------------------------------------------------------------------------
    693 
    694 }; // namespace android
    695