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
3863189325cc429140b14885061eb67d9c771b96a4Jean-Michel Trivi    virtual audio_unique_id_t trackPlayer(player_type_t playerType, audio_usage_t usage,
3963189325cc429140b14885061eb67d9c771b96a4Jean-Michel Trivi            audio_content_type_t content, const sp<IBinder>& player) {
400008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        Parcel data, reply;
410008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInterfaceToken(IAudioManager::getInterfaceDescriptor());
420008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInt32(1); // non-null PlayerIdCard parcelable
430008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        // marshall PlayerIdCard data
440008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInt32((int32_t) playerType);
450008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        //   write attributes of PlayerIdCard
4663189325cc429140b14885061eb67d9c771b96a4Jean-Michel Trivi        data.writeInt32((int32_t) usage);
4763189325cc429140b14885061eb67d9c771b96a4Jean-Michel Trivi        data.writeInt32((int32_t) content);
480008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInt32(0 /*source: none here, this is a player*/);
490008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInt32(0 /*flags*/);
500008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        //   write attributes' tags
510008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInt32(1 /*FLATTEN_TAGS*/);
520008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeString16(String16("")); // no tags
530008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        //   write attributes' bundle
540008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInt32(-1977 /*ATTR_PARCEL_IS_NULL_BUNDLE*/); // no bundle
5563189325cc429140b14885061eb67d9c771b96a4Jean-Michel Trivi        //   write IPlayer
5663189325cc429140b14885061eb67d9c771b96a4Jean-Michel Trivi        data.writeStrongBinder(player);
570008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        // get new PIId in reply
580008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        const status_t res = remote()->transact(TRACK_PLAYER, data, &reply, 0);
590008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        if (res != OK || reply.readExceptionCode() != 0) {
600008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi            ALOGE("trackPlayer() failed, piid is %d", PLAYER_PIID_INVALID);
610008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi            return PLAYER_PIID_INVALID;
620008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        } else {
630008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi            const audio_unique_id_t piid = (audio_unique_id_t) reply.readInt32();
640008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi            ALOGV("trackPlayer() returned piid %d", piid);
650008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi            return piid;
660008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        }
670008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi    }
680008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi
6963189325cc429140b14885061eb67d9c771b96a4Jean-Michel Trivi    virtual status_t playerAttributes(audio_unique_id_t piid, audio_usage_t usage,
7063189325cc429140b14885061eb67d9c771b96a4Jean-Michel Trivi            audio_content_type_t content) {
710008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        Parcel data, reply;
720008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInterfaceToken(IAudioManager::getInterfaceDescriptor());
7363189325cc429140b14885061eb67d9c771b96a4Jean-Michel Trivi        data.writeInt32((int32_t) piid);
740008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInt32(1); // non-null AudioAttributes parcelable
7563189325cc429140b14885061eb67d9c771b96a4Jean-Michel Trivi        data.writeInt32((int32_t) usage);
7663189325cc429140b14885061eb67d9c771b96a4Jean-Michel Trivi        data.writeInt32((int32_t) content);
770008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInt32(0 /*source: none here, this is a player*/);
780008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInt32(0 /*flags*/);
790008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        //   write attributes' tags
800008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInt32(1 /*FLATTEN_TAGS*/);
810008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeString16(String16("")); // no tags
820008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        //   write attributes' bundle
830008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInt32(-1977 /*ATTR_PARCEL_IS_NULL_BUNDLE*/); // no bundle
840008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        return remote()->transact(PLAYER_ATTRIBUTES, data, &reply, IBinder::FLAG_ONEWAY);
850008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi    }
860008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi
8763189325cc429140b14885061eb67d9c771b96a4Jean-Michel Trivi    virtual status_t playerEvent(audio_unique_id_t piid, player_state_t event) {
880008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        Parcel data, reply;
890008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInterfaceToken(IAudioManager::getInterfaceDescriptor());
9063189325cc429140b14885061eb67d9c771b96a4Jean-Michel Trivi        data.writeInt32((int32_t) piid);
9163189325cc429140b14885061eb67d9c771b96a4Jean-Michel Trivi        data.writeInt32((int32_t) event);
920008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        return remote()->transact(PLAYER_EVENT, data, &reply, IBinder::FLAG_ONEWAY);
930008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi    }
940008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi
9563189325cc429140b14885061eb67d9c771b96a4Jean-Michel Trivi    virtual status_t releasePlayer(audio_unique_id_t piid) {
960008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        Parcel data, reply;
970008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        data.writeInterfaceToken(IAudioManager::getInterfaceDescriptor());
9863189325cc429140b14885061eb67d9c771b96a4Jean-Michel Trivi        data.writeInt32((int32_t) piid);
990008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi        return remote()->transact(RELEASE_PLAYER, data, &reply, IBinder::FLAG_ONEWAY);
1000008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi    }
1010008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi};
1020008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi
1030008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel TriviIMPLEMENT_META_INTERFACE(AudioManager, "android.media.IAudioService");
1040008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi
1050008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi// ----------------------------------------------------------------------------
1060008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi
1070008a48aadba9d59b1d72586224d0a5afb9fb684Jean-Michel Trivi}; // namespace android
108