IAudioManager.cpp revision 0008a48aadba9d59b1d72586224d0a5afb9fb684
10008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi/*
20008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi * Copyright (C) 2016 The Android Open Source Project
30008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi *
40008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi * Licensed under the Apache License, Version 2.0 (the "License");
50008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi * you may not use this file except in compliance with the License.
60008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi * You may obtain a copy of the License at
70008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi *
80008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi *      http://www.apache.org/licenses/LICENSE-2.0
90008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi *
100008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi * Unless required by applicable law or agreed to in writing, software
110008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi * distributed under the License is distributed on an "AS IS" BASIS,
120008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
130008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi * See the License for the specific language governing permissions and
140008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi * limitations under the License.
150008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi */
160008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi
170008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi#define LOG_TAG "IAudioManager"
180008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi//#define LOG_NDEBUG 0
190008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi#include <utils/Log.h>
200008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi
210008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi#include <stdint.h>
220008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi#include <sys/types.h>
230008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi
240008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi#include <binder/Parcel.h>
250008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi#include <audiomanager/AudioManager.h>
260008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi#include <audiomanager/IAudioManager.h>
270008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi
280008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivinamespace android {
290008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi
300008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Triviclass BpAudioManager : public BpInterface<IAudioManager>
310008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi{
320008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivipublic:
330008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi    explicit BpAudioManager(const sp<IBinder>& impl)
340008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        : BpInterface<IAudioManager>(impl)
350008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi    {
360008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi    }
370008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi
380008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi    virtual audio_unique_id_t trackPlayer(int playerType, int usage, int content) {
390008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        Parcel data, reply;
400008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInterfaceToken(IAudioManager::getInterfaceDescriptor());
410008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInt32(1); // non-null PlayerIdCard parcelable
420008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        // marshall PlayerIdCard data
430008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInt32((int32_t) playerType);
440008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        //   write attributes of PlayerIdCard
450008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInt32(usage);
460008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInt32(content);
470008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInt32(0 /*source: none here, this is a player*/);
480008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInt32(0 /*flags*/);
490008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        //   write attributes' tags
500008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInt32(1 /*FLATTEN_TAGS*/);
510008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeString16(String16("")); // no tags
520008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        //   write attributes' bundle
530008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInt32(-1977 /*ATTR_PARCEL_IS_NULL_BUNDLE*/); // no bundle
540008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        // get new PIId in reply
550008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        const status_t res = remote()->transact(TRACK_PLAYER, data, &reply, 0);
560008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        if (res != OK || reply.readExceptionCode() != 0) {
570008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi            ALOGE("trackPlayer() failed, piid is %d", PLAYER_PIID_INVALID);
580008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi            return PLAYER_PIID_INVALID;
590008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        } else {
600008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi            const audio_unique_id_t piid = (audio_unique_id_t) reply.readInt32();
610008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi            ALOGV("trackPlayer() returned piid %d", piid);
620008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi            return piid;
630008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        }
640008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi    }
650008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi
660008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi    virtual status_t playerAttributes(audio_unique_id_t piid, int usage, int content) {
670008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        Parcel data, reply;
680008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInterfaceToken(IAudioManager::getInterfaceDescriptor());
690008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInt32(piid);
700008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInt32(1); // non-null AudioAttributes parcelable
710008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInt32(usage);
720008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInt32(content);
730008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInt32(0 /*source: none here, this is a player*/);
740008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInt32(0 /*flags*/);
750008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        //   write attributes' tags
760008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInt32(1 /*FLATTEN_TAGS*/);
770008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeString16(String16("")); // no tags
780008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        //   write attributes' bundle
790008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInt32(-1977 /*ATTR_PARCEL_IS_NULL_BUNDLE*/); // no bundle
800008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        return remote()->transact(PLAYER_ATTRIBUTES, data, &reply, IBinder::FLAG_ONEWAY);
810008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi    }
820008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi
830008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi    virtual status_t playerEvent(int piid, int event) {
840008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        Parcel data, reply;
850008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInterfaceToken(IAudioManager::getInterfaceDescriptor());
860008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInt32(piid);
870008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInt32(event);
880008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        return remote()->transact(PLAYER_EVENT, data, &reply, IBinder::FLAG_ONEWAY);
890008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi    }
900008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi
910008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi    virtual status_t releasePlayer(int piid) {
920008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        Parcel data, reply;
930008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInterfaceToken(IAudioManager::getInterfaceDescriptor());
940008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInt32(piid);
950008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        return remote()->transact(RELEASE_PLAYER, data, &reply, IBinder::FLAG_ONEWAY);
960008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi    }
970008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi};
980008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi
990008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel TriviIMPLEMENT_META_INTERFACE(AudioManager, "android.media.IAudioService");
1000008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi
1010008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi// ----------------------------------------------------------------------------
1020008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi
1030008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi}; // namespace android
104