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/AudioEffect.h>
27#include <media/IAudioPolicyService.h>
28
29#include <system/audio.h>
30
31namespace android {
32
33enum {
34    SET_DEVICE_CONNECTION_STATE = IBinder::FIRST_CALL_TRANSACTION,
35    GET_DEVICE_CONNECTION_STATE,
36    SET_PHONE_STATE,
37    SET_RINGER_MODE,    // reserved, no longer used
38    SET_FORCE_USE,
39    GET_FORCE_USE,
40    GET_OUTPUT,
41    START_OUTPUT,
42    STOP_OUTPUT,
43    RELEASE_OUTPUT,
44    GET_INPUT_FOR_ATTR,
45    START_INPUT,
46    STOP_INPUT,
47    RELEASE_INPUT,
48    INIT_STREAM_VOLUME,
49    SET_STREAM_VOLUME,
50    GET_STREAM_VOLUME,
51    GET_STRATEGY_FOR_STREAM,
52    GET_OUTPUT_FOR_EFFECT,
53    REGISTER_EFFECT,
54    UNREGISTER_EFFECT,
55    IS_STREAM_ACTIVE,
56    IS_SOURCE_ACTIVE,
57    GET_DEVICES_FOR_STREAM,
58    QUERY_DEFAULT_PRE_PROCESSING,
59    SET_EFFECT_ENABLED,
60    IS_STREAM_ACTIVE_REMOTELY,
61    IS_OFFLOAD_SUPPORTED,
62    LIST_AUDIO_PORTS,
63    GET_AUDIO_PORT,
64    CREATE_AUDIO_PATCH,
65    RELEASE_AUDIO_PATCH,
66    LIST_AUDIO_PATCHES,
67    SET_AUDIO_PORT_CONFIG,
68    REGISTER_CLIENT,
69    GET_OUTPUT_FOR_ATTR,
70    ACQUIRE_SOUNDTRIGGER_SESSION,
71    RELEASE_SOUNDTRIGGER_SESSION,
72    GET_PHONE_STATE,
73    REGISTER_POLICY_MIXES,
74};
75
76#define MAX_ITEMS_PER_LIST 1024
77
78class BpAudioPolicyService : public BpInterface<IAudioPolicyService>
79{
80public:
81    BpAudioPolicyService(const sp<IBinder>& impl)
82        : BpInterface<IAudioPolicyService>(impl)
83    {
84    }
85
86    virtual status_t setDeviceConnectionState(
87                                    audio_devices_t device,
88                                    audio_policy_dev_state_t state,
89                                    const char *device_address)
90    {
91        Parcel data, reply;
92        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
93        data.writeInt32(static_cast <uint32_t>(device));
94        data.writeInt32(static_cast <uint32_t>(state));
95        data.writeCString(device_address);
96        remote()->transact(SET_DEVICE_CONNECTION_STATE, data, &reply);
97        return static_cast <status_t> (reply.readInt32());
98    }
99
100    virtual audio_policy_dev_state_t getDeviceConnectionState(
101                                    audio_devices_t device,
102                                    const char *device_address)
103    {
104        Parcel data, reply;
105        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
106        data.writeInt32(static_cast <uint32_t>(device));
107        data.writeCString(device_address);
108        remote()->transact(GET_DEVICE_CONNECTION_STATE, data, &reply);
109        return static_cast <audio_policy_dev_state_t>(reply.readInt32());
110    }
111
112    virtual status_t setPhoneState(audio_mode_t state)
113    {
114        Parcel data, reply;
115        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
116        data.writeInt32(state);
117        remote()->transact(SET_PHONE_STATE, data, &reply);
118        return static_cast <status_t> (reply.readInt32());
119    }
120
121    virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
122    {
123        Parcel data, reply;
124        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
125        data.writeInt32(static_cast <uint32_t>(usage));
126        data.writeInt32(static_cast <uint32_t>(config));
127        remote()->transact(SET_FORCE_USE, data, &reply);
128        return static_cast <status_t> (reply.readInt32());
129    }
130
131    virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage)
132    {
133        Parcel data, reply;
134        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
135        data.writeInt32(static_cast <uint32_t>(usage));
136        remote()->transact(GET_FORCE_USE, data, &reply);
137        return static_cast <audio_policy_forced_cfg_t> (reply.readInt32());
138    }
139
140    virtual audio_io_handle_t getOutput(
141                                        audio_stream_type_t stream,
142                                        uint32_t samplingRate,
143                                        audio_format_t format,
144                                        audio_channel_mask_t channelMask,
145                                        audio_output_flags_t flags,
146                                        const audio_offload_info_t *offloadInfo)
147    {
148        Parcel data, reply;
149        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
150        data.writeInt32(static_cast <uint32_t>(stream));
151        data.writeInt32(samplingRate);
152        data.writeInt32(static_cast <uint32_t>(format));
153        data.writeInt32(channelMask);
154        data.writeInt32(static_cast <uint32_t>(flags));
155        // hasOffloadInfo
156        if (offloadInfo == NULL) {
157            data.writeInt32(0);
158        } else {
159            data.writeInt32(1);
160            data.write(offloadInfo, sizeof(audio_offload_info_t));
161        }
162        remote()->transact(GET_OUTPUT, data, &reply);
163        return static_cast <audio_io_handle_t> (reply.readInt32());
164    }
165
166    virtual status_t getOutputForAttr(const audio_attributes_t *attr,
167                                        audio_io_handle_t *output,
168                                        audio_session_t session,
169                                        audio_stream_type_t *stream,
170                                        uint32_t samplingRate,
171                                        audio_format_t format,
172                                        audio_channel_mask_t channelMask,
173                                        audio_output_flags_t flags,
174                                        const audio_offload_info_t *offloadInfo)
175        {
176            Parcel data, reply;
177            data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
178            if (attr == NULL) {
179                if (stream == NULL) {
180                    ALOGE("getOutputForAttr(): NULL audio attributes and stream type");
181                    return BAD_VALUE;
182                }
183                if (*stream == AUDIO_STREAM_DEFAULT) {
184                    ALOGE("getOutputForAttr unspecified stream type");
185                    return BAD_VALUE;
186                }
187            }
188            if (output == NULL) {
189                ALOGE("getOutputForAttr NULL output - shouldn't happen");
190                return BAD_VALUE;
191            }
192            if (attr == NULL) {
193                data.writeInt32(0);
194            } else {
195                data.writeInt32(1);
196                data.write(attr, sizeof(audio_attributes_t));
197            }
198            data.writeInt32(session);
199            if (stream == NULL) {
200                data.writeInt32(0);
201            } else {
202                data.writeInt32(1);
203                data.writeInt32(*stream);
204            }
205            data.writeInt32(samplingRate);
206            data.writeInt32(static_cast <uint32_t>(format));
207            data.writeInt32(channelMask);
208            data.writeInt32(static_cast <uint32_t>(flags));
209            // hasOffloadInfo
210            if (offloadInfo == NULL) {
211                data.writeInt32(0);
212            } else {
213                data.writeInt32(1);
214                data.write(offloadInfo, sizeof(audio_offload_info_t));
215            }
216            status_t status = remote()->transact(GET_OUTPUT_FOR_ATTR, data, &reply);
217            if (status != NO_ERROR) {
218                return status;
219            }
220            status = (status_t)reply.readInt32();
221            if (status != NO_ERROR) {
222                return status;
223            }
224            *output = (audio_io_handle_t)reply.readInt32();
225            if (stream != NULL) {
226                *stream = (audio_stream_type_t)reply.readInt32();
227            }
228            return status;
229        }
230
231    virtual status_t startOutput(audio_io_handle_t output,
232                                 audio_stream_type_t stream,
233                                 audio_session_t session)
234    {
235        Parcel data, reply;
236        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
237        data.writeInt32(output);
238        data.writeInt32((int32_t) stream);
239        data.writeInt32((int32_t)session);
240        remote()->transact(START_OUTPUT, data, &reply);
241        return static_cast <status_t> (reply.readInt32());
242    }
243
244    virtual status_t stopOutput(audio_io_handle_t output,
245                                audio_stream_type_t stream,
246                                audio_session_t session)
247    {
248        Parcel data, reply;
249        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
250        data.writeInt32(output);
251        data.writeInt32((int32_t) stream);
252        data.writeInt32((int32_t)session);
253        remote()->transact(STOP_OUTPUT, data, &reply);
254        return static_cast <status_t> (reply.readInt32());
255    }
256
257    virtual void releaseOutput(audio_io_handle_t output,
258                               audio_stream_type_t stream,
259                               audio_session_t session)
260    {
261        Parcel data, reply;
262        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
263        data.writeInt32(output);
264        data.writeInt32((int32_t)stream);
265        data.writeInt32((int32_t)session);
266        remote()->transact(RELEASE_OUTPUT, data, &reply);
267    }
268
269    virtual status_t getInputForAttr(const audio_attributes_t *attr,
270                                     audio_io_handle_t *input,
271                                     audio_session_t session,
272                                     uint32_t samplingRate,
273                                     audio_format_t format,
274                                     audio_channel_mask_t channelMask,
275                                     audio_input_flags_t flags)
276    {
277        Parcel data, reply;
278        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
279        if (attr == NULL) {
280            ALOGE("getInputForAttr NULL attr - shouldn't happen");
281            return BAD_VALUE;
282        }
283        if (input == NULL) {
284            ALOGE("getInputForAttr NULL input - shouldn't happen");
285            return BAD_VALUE;
286        }
287        data.write(attr, sizeof(audio_attributes_t));
288        data.writeInt32(session);
289        data.writeInt32(samplingRate);
290        data.writeInt32(static_cast <uint32_t>(format));
291        data.writeInt32(channelMask);
292        data.writeInt32(flags);
293        status_t status = remote()->transact(GET_INPUT_FOR_ATTR, data, &reply);
294        if (status != NO_ERROR) {
295            return status;
296        }
297        status = reply.readInt32();
298        if (status != NO_ERROR) {
299            return status;
300        }
301        *input = (audio_io_handle_t)reply.readInt32();
302        return NO_ERROR;
303    }
304
305    virtual status_t startInput(audio_io_handle_t input,
306                                audio_session_t session)
307    {
308        Parcel data, reply;
309        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
310        data.writeInt32(input);
311        data.writeInt32(session);
312        remote()->transact(START_INPUT, data, &reply);
313        return static_cast <status_t> (reply.readInt32());
314    }
315
316    virtual status_t stopInput(audio_io_handle_t input,
317                               audio_session_t session)
318    {
319        Parcel data, reply;
320        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
321        data.writeInt32(input);
322        data.writeInt32(session);
323        remote()->transact(STOP_INPUT, data, &reply);
324        return static_cast <status_t> (reply.readInt32());
325    }
326
327    virtual void releaseInput(audio_io_handle_t input,
328                              audio_session_t session)
329    {
330        Parcel data, reply;
331        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
332        data.writeInt32(input);
333        data.writeInt32(session);
334        remote()->transact(RELEASE_INPUT, data, &reply);
335    }
336
337    virtual status_t initStreamVolume(audio_stream_type_t stream,
338                                    int indexMin,
339                                    int indexMax)
340    {
341        Parcel data, reply;
342        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
343        data.writeInt32(static_cast <uint32_t>(stream));
344        data.writeInt32(indexMin);
345        data.writeInt32(indexMax);
346        remote()->transact(INIT_STREAM_VOLUME, data, &reply);
347        return static_cast <status_t> (reply.readInt32());
348    }
349
350    virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
351                                          int index,
352                                          audio_devices_t device)
353    {
354        Parcel data, reply;
355        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
356        data.writeInt32(static_cast <uint32_t>(stream));
357        data.writeInt32(index);
358        data.writeInt32(static_cast <uint32_t>(device));
359        remote()->transact(SET_STREAM_VOLUME, data, &reply);
360        return static_cast <status_t> (reply.readInt32());
361    }
362
363    virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
364                                          int *index,
365                                          audio_devices_t device)
366    {
367        Parcel data, reply;
368        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
369        data.writeInt32(static_cast <uint32_t>(stream));
370        data.writeInt32(static_cast <uint32_t>(device));
371
372        remote()->transact(GET_STREAM_VOLUME, data, &reply);
373        int lIndex = reply.readInt32();
374        if (index) *index = lIndex;
375        return static_cast <status_t> (reply.readInt32());
376    }
377
378    virtual uint32_t getStrategyForStream(audio_stream_type_t stream)
379    {
380        Parcel data, reply;
381        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
382        data.writeInt32(static_cast <uint32_t>(stream));
383        remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply);
384        return reply.readInt32();
385    }
386
387    virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream)
388    {
389        Parcel data, reply;
390        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
391        data.writeInt32(static_cast <uint32_t>(stream));
392        remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
393        return (audio_devices_t) reply.readInt32();
394    }
395
396    virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc)
397    {
398        Parcel data, reply;
399        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
400        data.write(desc, sizeof(effect_descriptor_t));
401        remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply);
402        return static_cast <audio_io_handle_t> (reply.readInt32());
403    }
404
405    virtual status_t registerEffect(const effect_descriptor_t *desc,
406                                        audio_io_handle_t io,
407                                        uint32_t strategy,
408                                        int session,
409                                        int id)
410    {
411        Parcel data, reply;
412        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
413        data.write(desc, sizeof(effect_descriptor_t));
414        data.writeInt32(io);
415        data.writeInt32(strategy);
416        data.writeInt32(session);
417        data.writeInt32(id);
418        remote()->transact(REGISTER_EFFECT, data, &reply);
419        return static_cast <status_t> (reply.readInt32());
420    }
421
422    virtual status_t unregisterEffect(int id)
423    {
424        Parcel data, reply;
425        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
426        data.writeInt32(id);
427        remote()->transact(UNREGISTER_EFFECT, data, &reply);
428        return static_cast <status_t> (reply.readInt32());
429    }
430
431    virtual status_t setEffectEnabled(int id, bool enabled)
432    {
433        Parcel data, reply;
434        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
435        data.writeInt32(id);
436        data.writeInt32(enabled);
437        remote()->transact(SET_EFFECT_ENABLED, data, &reply);
438        return static_cast <status_t> (reply.readInt32());
439    }
440
441    virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
442    {
443        Parcel data, reply;
444        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
445        data.writeInt32((int32_t) stream);
446        data.writeInt32(inPastMs);
447        remote()->transact(IS_STREAM_ACTIVE, data, &reply);
448        return reply.readInt32();
449    }
450
451    virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
452    {
453        Parcel data, reply;
454        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
455        data.writeInt32((int32_t) stream);
456        data.writeInt32(inPastMs);
457        remote()->transact(IS_STREAM_ACTIVE_REMOTELY, data, &reply);
458        return reply.readInt32();
459    }
460
461    virtual bool isSourceActive(audio_source_t source) const
462    {
463        Parcel data, reply;
464        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
465        data.writeInt32((int32_t) source);
466        remote()->transact(IS_SOURCE_ACTIVE, data, &reply);
467        return reply.readInt32();
468    }
469
470    virtual status_t queryDefaultPreProcessing(int audioSession,
471                                               effect_descriptor_t *descriptors,
472                                               uint32_t *count)
473    {
474        if (descriptors == NULL || count == NULL) {
475            return BAD_VALUE;
476        }
477        Parcel data, reply;
478        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
479        data.writeInt32(audioSession);
480        data.writeInt32(*count);
481        status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply);
482        if (status != NO_ERROR) {
483            return status;
484        }
485        status = static_cast <status_t> (reply.readInt32());
486        uint32_t retCount = reply.readInt32();
487        if (retCount != 0) {
488            uint32_t numDesc = (retCount < *count) ? retCount : *count;
489            reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc);
490        }
491        *count = retCount;
492        return status;
493    }
494
495    virtual bool isOffloadSupported(const audio_offload_info_t& info)
496    {
497        Parcel data, reply;
498        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
499        data.write(&info, sizeof(audio_offload_info_t));
500        remote()->transact(IS_OFFLOAD_SUPPORTED, data, &reply);
501        return reply.readInt32();
502    }
503
504    virtual status_t listAudioPorts(audio_port_role_t role,
505                                    audio_port_type_t type,
506                                    unsigned int *num_ports,
507                                    struct audio_port *ports,
508                                    unsigned int *generation)
509    {
510        if (num_ports == NULL || (*num_ports != 0 && ports == NULL) ||
511                generation == NULL) {
512            return BAD_VALUE;
513        }
514        Parcel data, reply;
515        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
516        unsigned int numPortsReq = (ports == NULL) ? 0 : *num_ports;
517        data.writeInt32(role);
518        data.writeInt32(type);
519        data.writeInt32(numPortsReq);
520        status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
521        if (status == NO_ERROR) {
522            status = (status_t)reply.readInt32();
523            *num_ports = (unsigned int)reply.readInt32();
524        }
525        if (status == NO_ERROR) {
526            if (numPortsReq > *num_ports) {
527                numPortsReq = *num_ports;
528            }
529            if (numPortsReq > 0) {
530                reply.read(ports, numPortsReq * sizeof(struct audio_port));
531            }
532            *generation = reply.readInt32();
533        }
534        return status;
535    }
536
537    virtual status_t getAudioPort(struct audio_port *port)
538    {
539        if (port == NULL) {
540            return BAD_VALUE;
541        }
542        Parcel data, reply;
543        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
544        data.write(port, sizeof(struct audio_port));
545        status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
546        if (status != NO_ERROR ||
547                (status = (status_t)reply.readInt32()) != NO_ERROR) {
548            return status;
549        }
550        reply.read(port, sizeof(struct audio_port));
551        return status;
552    }
553
554    virtual status_t createAudioPatch(const struct audio_patch *patch,
555                                       audio_patch_handle_t *handle)
556    {
557        if (patch == NULL || handle == NULL) {
558            return BAD_VALUE;
559        }
560        Parcel data, reply;
561        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
562        data.write(patch, sizeof(struct audio_patch));
563        data.write(handle, sizeof(audio_patch_handle_t));
564        status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
565        if (status != NO_ERROR ||
566                (status = (status_t)reply.readInt32()) != NO_ERROR) {
567            return status;
568        }
569        reply.read(handle, sizeof(audio_patch_handle_t));
570        return status;
571    }
572
573    virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
574    {
575        Parcel data, reply;
576        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
577        data.write(&handle, sizeof(audio_patch_handle_t));
578        status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
579        if (status != NO_ERROR) {
580            status = (status_t)reply.readInt32();
581        }
582        return status;
583    }
584
585    virtual status_t listAudioPatches(unsigned int *num_patches,
586                                      struct audio_patch *patches,
587                                      unsigned int *generation)
588    {
589        if (num_patches == NULL || (*num_patches != 0 && patches == NULL) ||
590                generation == NULL) {
591            return BAD_VALUE;
592        }
593        Parcel data, reply;
594        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
595        unsigned int numPatchesReq = (patches == NULL) ? 0 : *num_patches;
596        data.writeInt32(numPatchesReq);
597        status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
598        if (status == NO_ERROR) {
599            status = (status_t)reply.readInt32();
600            *num_patches = (unsigned int)reply.readInt32();
601        }
602        if (status == NO_ERROR) {
603            if (numPatchesReq > *num_patches) {
604                numPatchesReq = *num_patches;
605            }
606            if (numPatchesReq > 0) {
607                reply.read(patches, numPatchesReq * sizeof(struct audio_patch));
608            }
609            *generation = reply.readInt32();
610        }
611        return status;
612    }
613
614    virtual status_t setAudioPortConfig(const struct audio_port_config *config)
615    {
616        if (config == NULL) {
617            return BAD_VALUE;
618        }
619        Parcel data, reply;
620        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
621        data.write(config, sizeof(struct audio_port_config));
622        status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
623        if (status != NO_ERROR) {
624            status = (status_t)reply.readInt32();
625        }
626        return status;
627    }
628
629    virtual void registerClient(const sp<IAudioPolicyServiceClient>& client)
630    {
631        Parcel data, reply;
632        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
633        data.writeStrongBinder(client->asBinder());
634        remote()->transact(REGISTER_CLIENT, data, &reply);
635    }
636
637    virtual status_t acquireSoundTriggerSession(audio_session_t *session,
638                                            audio_io_handle_t *ioHandle,
639                                            audio_devices_t *device)
640    {
641        if (session == NULL || ioHandle == NULL || device == NULL) {
642            return BAD_VALUE;
643        }
644        Parcel data, reply;
645        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
646        status_t status = remote()->transact(ACQUIRE_SOUNDTRIGGER_SESSION, data, &reply);
647        if (status != NO_ERROR) {
648            return status;
649        }
650        status = (status_t)reply.readInt32();
651        if (status == NO_ERROR) {
652            *session = (audio_session_t)reply.readInt32();
653            *ioHandle = (audio_io_handle_t)reply.readInt32();
654            *device = (audio_devices_t)reply.readInt32();
655        }
656        return status;
657    }
658
659    virtual status_t releaseSoundTriggerSession(audio_session_t session)
660    {
661        Parcel data, reply;
662        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
663        data.writeInt32(session);
664        status_t status = remote()->transact(RELEASE_SOUNDTRIGGER_SESSION, data, &reply);
665        if (status != NO_ERROR) {
666            return status;
667        }
668        return (status_t)reply.readInt32();
669    }
670
671    virtual audio_mode_t getPhoneState()
672    {
673        Parcel data, reply;
674        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
675        status_t status = remote()->transact(GET_PHONE_STATE, data, &reply);
676        if (status != NO_ERROR) {
677            return AUDIO_MODE_INVALID;
678        }
679        return (audio_mode_t)reply.readInt32();
680    }
681
682    virtual status_t registerPolicyMixes(Vector<AudioMix> mixes, bool registration)
683    {
684        Parcel data, reply;
685        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
686        data.writeInt32(registration ? 1 : 0);
687        size_t size = mixes.size();
688        if (size > MAX_MIXES_PER_POLICY) {
689            size = MAX_MIXES_PER_POLICY;
690        }
691        size_t sizePosition = data.dataPosition();
692        data.writeInt32(size);
693        size_t finalSize = size;
694        for (size_t i = 0; i < size; i++) {
695            size_t position = data.dataPosition();
696            if (mixes[i].writeToParcel(&data) != NO_ERROR) {
697                data.setDataPosition(position);
698                finalSize--;
699            }
700        }
701        if (size != finalSize) {
702            size_t position = data.dataPosition();
703            data.setDataPosition(sizePosition);
704            data.writeInt32(finalSize);
705            data.setDataPosition(position);
706        }
707        status_t status = remote()->transact(REGISTER_POLICY_MIXES, data, &reply);
708        if (status == NO_ERROR) {
709            status = (status_t)reply.readInt32();
710        }
711        return status;
712    }
713};
714
715IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
716
717// ----------------------------------------------------------------------
718
719
720status_t BnAudioPolicyService::onTransact(
721    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
722{
723    switch (code) {
724        case SET_DEVICE_CONNECTION_STATE: {
725            CHECK_INTERFACE(IAudioPolicyService, data, reply);
726            audio_devices_t device =
727                    static_cast <audio_devices_t>(data.readInt32());
728            audio_policy_dev_state_t state =
729                    static_cast <audio_policy_dev_state_t>(data.readInt32());
730            const char *device_address = data.readCString();
731            reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
732                                                                              state,
733                                                                              device_address)));
734            return NO_ERROR;
735        } break;
736
737        case GET_DEVICE_CONNECTION_STATE: {
738            CHECK_INTERFACE(IAudioPolicyService, data, reply);
739            audio_devices_t device =
740                    static_cast<audio_devices_t> (data.readInt32());
741            const char *device_address = data.readCString();
742            reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
743                                                                              device_address)));
744            return NO_ERROR;
745        } break;
746
747        case SET_PHONE_STATE: {
748            CHECK_INTERFACE(IAudioPolicyService, data, reply);
749            reply->writeInt32(static_cast <uint32_t>(setPhoneState(
750                    (audio_mode_t) data.readInt32())));
751            return NO_ERROR;
752        } break;
753
754        case SET_FORCE_USE: {
755            CHECK_INTERFACE(IAudioPolicyService, data, reply);
756            audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
757                    data.readInt32());
758            audio_policy_forced_cfg_t config =
759                    static_cast <audio_policy_forced_cfg_t>(data.readInt32());
760            reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
761            return NO_ERROR;
762        } break;
763
764        case GET_FORCE_USE: {
765            CHECK_INTERFACE(IAudioPolicyService, data, reply);
766            audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
767                    data.readInt32());
768            reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
769            return NO_ERROR;
770        } break;
771
772        case GET_OUTPUT: {
773            CHECK_INTERFACE(IAudioPolicyService, data, reply);
774            audio_stream_type_t stream =
775                    static_cast <audio_stream_type_t>(data.readInt32());
776            uint32_t samplingRate = data.readInt32();
777            audio_format_t format = (audio_format_t) data.readInt32();
778            audio_channel_mask_t channelMask = data.readInt32();
779            audio_output_flags_t flags =
780                    static_cast <audio_output_flags_t>(data.readInt32());
781            bool hasOffloadInfo = data.readInt32() != 0;
782            audio_offload_info_t offloadInfo;
783            if (hasOffloadInfo) {
784                data.read(&offloadInfo, sizeof(audio_offload_info_t));
785            }
786            audio_io_handle_t output = getOutput(stream,
787                                                 samplingRate,
788                                                 format,
789                                                 channelMask,
790                                                 flags,
791                                                 hasOffloadInfo ? &offloadInfo : NULL);
792            reply->writeInt32(static_cast <int>(output));
793            return NO_ERROR;
794        } break;
795
796        case GET_OUTPUT_FOR_ATTR: {
797            CHECK_INTERFACE(IAudioPolicyService, data, reply);
798            audio_attributes_t attr;
799            bool hasAttributes = data.readInt32() != 0;
800            if (hasAttributes) {
801                data.read(&attr, sizeof(audio_attributes_t));
802            }
803            audio_session_t session = (audio_session_t)data.readInt32();
804            audio_stream_type_t stream = AUDIO_STREAM_DEFAULT;
805            bool hasStream = data.readInt32() != 0;
806            if (hasStream) {
807                stream = (audio_stream_type_t)data.readInt32();
808            }
809            uint32_t samplingRate = data.readInt32();
810            audio_format_t format = (audio_format_t) data.readInt32();
811            audio_channel_mask_t channelMask = data.readInt32();
812            audio_output_flags_t flags =
813                    static_cast <audio_output_flags_t>(data.readInt32());
814            bool hasOffloadInfo = data.readInt32() != 0;
815            audio_offload_info_t offloadInfo;
816            if (hasOffloadInfo) {
817                data.read(&offloadInfo, sizeof(audio_offload_info_t));
818            }
819            audio_io_handle_t output;
820            status_t status = getOutputForAttr(hasAttributes ? &attr : NULL,
821                    &output, session, &stream,
822                    samplingRate, format, channelMask,
823                    flags, hasOffloadInfo ? &offloadInfo : NULL);
824            reply->writeInt32(status);
825            reply->writeInt32(output);
826            reply->writeInt32(stream);
827            return NO_ERROR;
828        } break;
829
830        case START_OUTPUT: {
831            CHECK_INTERFACE(IAudioPolicyService, data, reply);
832            audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
833            audio_stream_type_t stream =
834                                static_cast <audio_stream_type_t>(data.readInt32());
835            audio_session_t session = (audio_session_t)data.readInt32();
836            reply->writeInt32(static_cast <uint32_t>(startOutput(output,
837                                                                 stream,
838                                                                 session)));
839            return NO_ERROR;
840        } break;
841
842        case STOP_OUTPUT: {
843            CHECK_INTERFACE(IAudioPolicyService, data, reply);
844            audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
845            audio_stream_type_t stream =
846                                static_cast <audio_stream_type_t>(data.readInt32());
847            audio_session_t session = (audio_session_t)data.readInt32();
848            reply->writeInt32(static_cast <uint32_t>(stopOutput(output,
849                                                                stream,
850                                                                session)));
851            return NO_ERROR;
852        } break;
853
854        case RELEASE_OUTPUT: {
855            CHECK_INTERFACE(IAudioPolicyService, data, reply);
856            audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
857            audio_stream_type_t stream = (audio_stream_type_t)data.readInt32();
858            audio_session_t session = (audio_session_t)data.readInt32();
859            releaseOutput(output, stream, session);
860            return NO_ERROR;
861        } break;
862
863        case GET_INPUT_FOR_ATTR: {
864            CHECK_INTERFACE(IAudioPolicyService, data, reply);
865            audio_attributes_t attr;
866            data.read(&attr, sizeof(audio_attributes_t));
867            audio_session_t session = (audio_session_t)data.readInt32();
868            uint32_t samplingRate = data.readInt32();
869            audio_format_t format = (audio_format_t) data.readInt32();
870            audio_channel_mask_t channelMask = data.readInt32();
871            audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
872            audio_io_handle_t input;
873            status_t status = getInputForAttr(&attr, &input, session,
874                                              samplingRate, format, channelMask,
875                                              flags);
876            reply->writeInt32(status);
877            if (status == NO_ERROR) {
878                reply->writeInt32(input);
879            }
880            return NO_ERROR;
881        } break;
882
883        case START_INPUT: {
884            CHECK_INTERFACE(IAudioPolicyService, data, reply);
885            audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
886            audio_session_t session = static_cast <audio_session_t>(data.readInt32());
887            reply->writeInt32(static_cast <uint32_t>(startInput(input, session)));
888            return NO_ERROR;
889        } break;
890
891        case STOP_INPUT: {
892            CHECK_INTERFACE(IAudioPolicyService, data, reply);
893            audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
894            audio_session_t session = static_cast <audio_session_t>(data.readInt32());
895            reply->writeInt32(static_cast <uint32_t>(stopInput(input, session)));
896            return NO_ERROR;
897        } break;
898
899        case RELEASE_INPUT: {
900            CHECK_INTERFACE(IAudioPolicyService, data, reply);
901            audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
902            audio_session_t session = static_cast <audio_session_t>(data.readInt32());
903            releaseInput(input, session);
904            return NO_ERROR;
905        } break;
906
907        case INIT_STREAM_VOLUME: {
908            CHECK_INTERFACE(IAudioPolicyService, data, reply);
909            audio_stream_type_t stream =
910                    static_cast <audio_stream_type_t>(data.readInt32());
911            int indexMin = data.readInt32();
912            int indexMax = data.readInt32();
913            reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
914            return NO_ERROR;
915        } break;
916
917        case SET_STREAM_VOLUME: {
918            CHECK_INTERFACE(IAudioPolicyService, data, reply);
919            audio_stream_type_t stream =
920                    static_cast <audio_stream_type_t>(data.readInt32());
921            int index = data.readInt32();
922            audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
923            reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream,
924                                                                          index,
925                                                                          device)));
926            return NO_ERROR;
927        } break;
928
929        case GET_STREAM_VOLUME: {
930            CHECK_INTERFACE(IAudioPolicyService, data, reply);
931            audio_stream_type_t stream =
932                    static_cast <audio_stream_type_t>(data.readInt32());
933            audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
934            int index;
935            status_t status = getStreamVolumeIndex(stream, &index, device);
936            reply->writeInt32(index);
937            reply->writeInt32(static_cast <uint32_t>(status));
938            return NO_ERROR;
939        } break;
940
941        case GET_STRATEGY_FOR_STREAM: {
942            CHECK_INTERFACE(IAudioPolicyService, data, reply);
943            audio_stream_type_t stream =
944                    static_cast <audio_stream_type_t>(data.readInt32());
945            reply->writeInt32(getStrategyForStream(stream));
946            return NO_ERROR;
947        } break;
948
949        case GET_DEVICES_FOR_STREAM: {
950            CHECK_INTERFACE(IAudioPolicyService, data, reply);
951            audio_stream_type_t stream =
952                    static_cast <audio_stream_type_t>(data.readInt32());
953            reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
954            return NO_ERROR;
955        } break;
956
957        case GET_OUTPUT_FOR_EFFECT: {
958            CHECK_INTERFACE(IAudioPolicyService, data, reply);
959            effect_descriptor_t desc;
960            data.read(&desc, sizeof(effect_descriptor_t));
961            audio_io_handle_t output = getOutputForEffect(&desc);
962            reply->writeInt32(static_cast <int>(output));
963            return NO_ERROR;
964        } break;
965
966        case REGISTER_EFFECT: {
967            CHECK_INTERFACE(IAudioPolicyService, data, reply);
968            effect_descriptor_t desc;
969            data.read(&desc, sizeof(effect_descriptor_t));
970            audio_io_handle_t io = data.readInt32();
971            uint32_t strategy = data.readInt32();
972            int session = data.readInt32();
973            int id = data.readInt32();
974            reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
975                                                                   io,
976                                                                   strategy,
977                                                                   session,
978                                                                   id)));
979            return NO_ERROR;
980        } break;
981
982        case UNREGISTER_EFFECT: {
983            CHECK_INTERFACE(IAudioPolicyService, data, reply);
984            int id = data.readInt32();
985            reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
986            return NO_ERROR;
987        } break;
988
989        case SET_EFFECT_ENABLED: {
990            CHECK_INTERFACE(IAudioPolicyService, data, reply);
991            int id = data.readInt32();
992            bool enabled = static_cast <bool>(data.readInt32());
993            reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
994            return NO_ERROR;
995        } break;
996
997        case IS_STREAM_ACTIVE: {
998            CHECK_INTERFACE(IAudioPolicyService, data, reply);
999            audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1000            uint32_t inPastMs = (uint32_t)data.readInt32();
1001            reply->writeInt32( isStreamActive(stream, inPastMs) );
1002            return NO_ERROR;
1003        } break;
1004
1005        case IS_STREAM_ACTIVE_REMOTELY: {
1006            CHECK_INTERFACE(IAudioPolicyService, data, reply);
1007            audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1008            uint32_t inPastMs = (uint32_t)data.readInt32();
1009            reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) );
1010            return NO_ERROR;
1011        } break;
1012
1013        case IS_SOURCE_ACTIVE: {
1014            CHECK_INTERFACE(IAudioPolicyService, data, reply);
1015            audio_source_t source = (audio_source_t) data.readInt32();
1016            reply->writeInt32( isSourceActive(source));
1017            return NO_ERROR;
1018        }
1019
1020        case QUERY_DEFAULT_PRE_PROCESSING: {
1021            CHECK_INTERFACE(IAudioPolicyService, data, reply);
1022            int audioSession = data.readInt32();
1023            uint32_t count = data.readInt32();
1024            if (count > AudioEffect::kMaxPreProcessing) {
1025                count = AudioEffect::kMaxPreProcessing;
1026            }
1027            uint32_t retCount = count;
1028            effect_descriptor_t *descriptors = new effect_descriptor_t[count];
1029            status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
1030            reply->writeInt32(status);
1031            if (status != NO_ERROR && status != NO_MEMORY) {
1032                retCount = 0;
1033            }
1034            reply->writeInt32(retCount);
1035            if (retCount != 0) {
1036                if (retCount < count) {
1037                    count = retCount;
1038                }
1039                reply->write(descriptors, sizeof(effect_descriptor_t) * count);
1040            }
1041            delete[] descriptors;
1042            return status;
1043        }
1044
1045        case IS_OFFLOAD_SUPPORTED: {
1046            CHECK_INTERFACE(IAudioPolicyService, data, reply);
1047            audio_offload_info_t info;
1048            data.read(&info, sizeof(audio_offload_info_t));
1049            bool isSupported = isOffloadSupported(info);
1050            reply->writeInt32(isSupported);
1051            return NO_ERROR;
1052        }
1053
1054        case LIST_AUDIO_PORTS: {
1055            CHECK_INTERFACE(IAudioPolicyService, data, reply);
1056            audio_port_role_t role = (audio_port_role_t)data.readInt32();
1057            audio_port_type_t type = (audio_port_type_t)data.readInt32();
1058            unsigned int numPortsReq = data.readInt32();
1059            if (numPortsReq > MAX_ITEMS_PER_LIST) {
1060                numPortsReq = MAX_ITEMS_PER_LIST;
1061            }
1062            unsigned int numPorts = numPortsReq;
1063            struct audio_port *ports =
1064                    (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port));
1065            if (ports == NULL) {
1066                reply->writeInt32(NO_MEMORY);
1067                reply->writeInt32(0);
1068                return NO_ERROR;
1069            }
1070            unsigned int generation;
1071            status_t status = listAudioPorts(role, type, &numPorts, ports, &generation);
1072            reply->writeInt32(status);
1073            reply->writeInt32(numPorts);
1074
1075            if (status == NO_ERROR) {
1076                if (numPortsReq > numPorts) {
1077                    numPortsReq = numPorts;
1078                }
1079                reply->write(ports, numPortsReq * sizeof(struct audio_port));
1080                reply->writeInt32(generation);
1081            }
1082            free(ports);
1083            return NO_ERROR;
1084        }
1085
1086        case GET_AUDIO_PORT: {
1087            CHECK_INTERFACE(IAudioPolicyService, data, reply);
1088            struct audio_port port;
1089            data.read(&port, sizeof(struct audio_port));
1090            status_t status = getAudioPort(&port);
1091            reply->writeInt32(status);
1092            if (status == NO_ERROR) {
1093                reply->write(&port, sizeof(struct audio_port));
1094            }
1095            return NO_ERROR;
1096        }
1097
1098        case CREATE_AUDIO_PATCH: {
1099            CHECK_INTERFACE(IAudioPolicyService, data, reply);
1100            struct audio_patch patch;
1101            data.read(&patch, sizeof(struct audio_patch));
1102            audio_patch_handle_t handle;
1103            data.read(&handle, sizeof(audio_patch_handle_t));
1104            status_t status = createAudioPatch(&patch, &handle);
1105            reply->writeInt32(status);
1106            if (status == NO_ERROR) {
1107                reply->write(&handle, sizeof(audio_patch_handle_t));
1108            }
1109            return NO_ERROR;
1110        }
1111
1112        case RELEASE_AUDIO_PATCH: {
1113            CHECK_INTERFACE(IAudioPolicyService, data, reply);
1114            audio_patch_handle_t handle;
1115            data.read(&handle, sizeof(audio_patch_handle_t));
1116            status_t status = releaseAudioPatch(handle);
1117            reply->writeInt32(status);
1118            return NO_ERROR;
1119        }
1120
1121        case LIST_AUDIO_PATCHES: {
1122            CHECK_INTERFACE(IAudioPolicyService, data, reply);
1123            unsigned int numPatchesReq = data.readInt32();
1124            if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1125                numPatchesReq = MAX_ITEMS_PER_LIST;
1126            }
1127            unsigned int numPatches = numPatchesReq;
1128            struct audio_patch *patches =
1129                    (struct audio_patch *)calloc(numPatchesReq,
1130                                                 sizeof(struct audio_patch));
1131            if (patches == NULL) {
1132                reply->writeInt32(NO_MEMORY);
1133                reply->writeInt32(0);
1134                return NO_ERROR;
1135            }
1136            unsigned int generation;
1137            status_t status = listAudioPatches(&numPatches, patches, &generation);
1138            reply->writeInt32(status);
1139            reply->writeInt32(numPatches);
1140            if (status == NO_ERROR) {
1141                if (numPatchesReq > numPatches) {
1142                    numPatchesReq = numPatches;
1143                }
1144                reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
1145                reply->writeInt32(generation);
1146            }
1147            free(patches);
1148            return NO_ERROR;
1149        }
1150
1151        case SET_AUDIO_PORT_CONFIG: {
1152            CHECK_INTERFACE(IAudioPolicyService, data, reply);
1153            struct audio_port_config config;
1154            data.read(&config, sizeof(struct audio_port_config));
1155            status_t status = setAudioPortConfig(&config);
1156            reply->writeInt32(status);
1157            return NO_ERROR;
1158        }
1159
1160        case REGISTER_CLIENT: {
1161            CHECK_INTERFACE(IAudioPolicyService, data, reply);
1162            sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1163                    data.readStrongBinder());
1164            registerClient(client);
1165            return NO_ERROR;
1166        } break;
1167
1168        case ACQUIRE_SOUNDTRIGGER_SESSION: {
1169            CHECK_INTERFACE(IAudioPolicyService, data, reply);
1170            sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1171                    data.readStrongBinder());
1172            audio_session_t session;
1173            audio_io_handle_t ioHandle;
1174            audio_devices_t device;
1175            status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device);
1176            reply->writeInt32(status);
1177            if (status == NO_ERROR) {
1178                reply->writeInt32(session);
1179                reply->writeInt32(ioHandle);
1180                reply->writeInt32(device);
1181            }
1182            return NO_ERROR;
1183        } break;
1184
1185        case RELEASE_SOUNDTRIGGER_SESSION: {
1186            CHECK_INTERFACE(IAudioPolicyService, data, reply);
1187            sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
1188                    data.readStrongBinder());
1189            audio_session_t session = (audio_session_t)data.readInt32();
1190            status_t status = releaseSoundTriggerSession(session);
1191            reply->writeInt32(status);
1192            return NO_ERROR;
1193        } break;
1194
1195        case GET_PHONE_STATE: {
1196            CHECK_INTERFACE(IAudioPolicyService, data, reply);
1197            reply->writeInt32((int32_t)getPhoneState());
1198            return NO_ERROR;
1199        } break;
1200
1201        case REGISTER_POLICY_MIXES: {
1202            CHECK_INTERFACE(IAudioPolicyService, data, reply);
1203            bool registration = data.readInt32() == 1;
1204            Vector<AudioMix> mixes;
1205            size_t size = (size_t)data.readInt32();
1206            if (size > MAX_MIXES_PER_POLICY) {
1207                size = MAX_MIXES_PER_POLICY;
1208            }
1209            for (size_t i = 0; i < size; i++) {
1210                AudioMix mix;
1211                if (mix.readFromParcel((Parcel*)&data) == NO_ERROR) {
1212                    mixes.add(mix);
1213                }
1214            }
1215            status_t status = registerPolicyMixes(mixes, registration);
1216            reply->writeInt32(status);
1217            return NO_ERROR;
1218        } break;
1219
1220        default:
1221            return BBinder::onTransact(code, data, reply, flags);
1222    }
1223}
1224
1225// ----------------------------------------------------------------------------
1226
1227}; // namespace android
1228