IAudioManager.cpp revision 0008a48aadba9d59b1d72586224d0a5afb9fb684
1/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "IAudioManager"
18//#define LOG_NDEBUG 0
19#include <utils/Log.h>
20
21#include <stdint.h>
22#include <sys/types.h>
23
24#include <binder/Parcel.h>
25#include <audiomanager/AudioManager.h>
26#include <audiomanager/IAudioManager.h>
27
28namespace android {
29
30class BpAudioManager : public BpInterface<IAudioManager>
31{
32public:
33    explicit BpAudioManager(const sp<IBinder>& impl)
34        : BpInterface<IAudioManager>(impl)
35    {
36    }
37
38    virtual audio_unique_id_t trackPlayer(int playerType, int usage, int content) {
39        Parcel data, reply;
40        data.writeInterfaceToken(IAudioManager::getInterfaceDescriptor());
41        data.writeInt32(1); // non-null PlayerIdCard parcelable
42        // marshall PlayerIdCard data
43        data.writeInt32((int32_t) playerType);
44        //   write attributes of PlayerIdCard
45        data.writeInt32(usage);
46        data.writeInt32(content);
47        data.writeInt32(0 /*source: none here, this is a player*/);
48        data.writeInt32(0 /*flags*/);
49        //   write attributes' tags
50        data.writeInt32(1 /*FLATTEN_TAGS*/);
51        data.writeString16(String16("")); // no tags
52        //   write attributes' bundle
53        data.writeInt32(-1977 /*ATTR_PARCEL_IS_NULL_BUNDLE*/); // no bundle
54        // get new PIId in reply
55        const status_t res = remote()->transact(TRACK_PLAYER, data, &reply, 0);
56        if (res != OK || reply.readExceptionCode() != 0) {
57            ALOGE("trackPlayer() failed, piid is %d", PLAYER_PIID_INVALID);
58            return PLAYER_PIID_INVALID;
59        } else {
60            const audio_unique_id_t piid = (audio_unique_id_t) reply.readInt32();
61            ALOGV("trackPlayer() returned piid %d", piid);
62            return piid;
63        }
64    }
65
66    virtual status_t playerAttributes(audio_unique_id_t piid, int usage, int content) {
67        Parcel data, reply;
68        data.writeInterfaceToken(IAudioManager::getInterfaceDescriptor());
69        data.writeInt32(piid);
70        data.writeInt32(1); // non-null AudioAttributes parcelable
71        data.writeInt32(usage);
72        data.writeInt32(content);
73        data.writeInt32(0 /*source: none here, this is a player*/);
74        data.writeInt32(0 /*flags*/);
75        //   write attributes' tags
76        data.writeInt32(1 /*FLATTEN_TAGS*/);
77        data.writeString16(String16("")); // no tags
78        //   write attributes' bundle
79        data.writeInt32(-1977 /*ATTR_PARCEL_IS_NULL_BUNDLE*/); // no bundle
80        return remote()->transact(PLAYER_ATTRIBUTES, data, &reply, IBinder::FLAG_ONEWAY);
81    }
82
83    virtual status_t playerEvent(int piid, int event) {
84        Parcel data, reply;
85        data.writeInterfaceToken(IAudioManager::getInterfaceDescriptor());
86        data.writeInt32(piid);
87        data.writeInt32(event);
88        return remote()->transact(PLAYER_EVENT, data, &reply, IBinder::FLAG_ONEWAY);
89    }
90
91    virtual status_t releasePlayer(int piid) {
92        Parcel data, reply;
93        data.writeInterfaceToken(IAudioManager::getInterfaceDescriptor());
94        data.writeInt32(piid);
95        return remote()->transact(RELEASE_PLAYER, data, &reply, IBinder::FLAG_ONEWAY);
96    }
97};
98
99IMPLEMENT_META_INTERFACE(AudioManager, "android.media.IAudioService");
100
101// ----------------------------------------------------------------------------
102
103}; // namespace android
104