2 * Copyright (C) 2016 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #define LOG_TAG "IAudioManager"
18 //#define LOG_NDEBUG 0
19 #include <utils/Log.h>
22 #include <sys/types.h>
24 #include <binder/Parcel.h>
25 #include <audiomanager/AudioManager.h>
26 #include <audiomanager/IAudioManager.h>
30 class BpAudioManager : public BpInterface<IAudioManager>
33 explicit BpAudioManager(const sp<IBinder>& impl)
34 : BpInterface<IAudioManager>(impl)
38 virtual audio_unique_id_t trackPlayer(player_type_t playerType, audio_usage_t usage,
39 audio_content_type_t content, const sp<IBinder>& player) {
41 data.writeInterfaceToken(IAudioManager::getInterfaceDescriptor());
42 data.writeInt32(1); // non-null PlayerIdCard parcelable
43 // marshall PlayerIdCard data
44 data.writeInt32((int32_t) playerType);
45 // write attributes of PlayerIdCard
46 data.writeInt32((int32_t) usage);
47 data.writeInt32((int32_t) content);
48 data.writeInt32(0 /*source: none here, this is a player*/);
49 data.writeInt32(0 /*flags*/);
50 // write attributes' tags
51 data.writeInt32(1 /*FLATTEN_TAGS*/);
52 data.writeString16(String16("")); // no tags
53 // write attributes' bundle
54 data.writeInt32(-1977 /*ATTR_PARCEL_IS_NULL_BUNDLE*/); // no bundle
56 data.writeStrongBinder(player);
57 // get new PIId in reply
58 const status_t res = remote()->transact(TRACK_PLAYER, data, &reply, 0);
59 if (res != OK || reply.readExceptionCode() != 0) {
60 ALOGE("trackPlayer() failed, piid is %d", PLAYER_PIID_INVALID);
61 return PLAYER_PIID_INVALID;
63 const audio_unique_id_t piid = (audio_unique_id_t) reply.readInt32();
64 ALOGV("trackPlayer() returned piid %d", piid);
69 virtual status_t playerAttributes(audio_unique_id_t piid, audio_usage_t usage,
70 audio_content_type_t content) {
72 data.writeInterfaceToken(IAudioManager::getInterfaceDescriptor());
73 data.writeInt32((int32_t) piid);
74 data.writeInt32(1); // non-null AudioAttributes parcelable
75 data.writeInt32((int32_t) usage);
76 data.writeInt32((int32_t) content);
77 data.writeInt32(0 /*source: none here, this is a player*/);
78 data.writeInt32(0 /*flags*/);
79 // write attributes' tags
80 data.writeInt32(1 /*FLATTEN_TAGS*/);
81 data.writeString16(String16("")); // no tags
82 // write attributes' bundle
83 data.writeInt32(-1977 /*ATTR_PARCEL_IS_NULL_BUNDLE*/); // no bundle
84 return remote()->transact(PLAYER_ATTRIBUTES, data, &reply, IBinder::FLAG_ONEWAY);
87 virtual status_t playerEvent(audio_unique_id_t piid, player_state_t event) {
89 data.writeInterfaceToken(IAudioManager::getInterfaceDescriptor());
90 data.writeInt32((int32_t) piid);
91 data.writeInt32((int32_t) event);
92 return remote()->transact(PLAYER_EVENT, data, &reply, IBinder::FLAG_ONEWAY);
95 virtual status_t releasePlayer(audio_unique_id_t piid) {
97 data.writeInterfaceToken(IAudioManager::getInterfaceDescriptor());
98 data.writeInt32((int32_t) piid);
99 return remote()->transact(RELEASE_PLAYER, data, &reply, IBinder::FLAG_ONEWAY);
103 IMPLEMENT_META_INTERFACE(AudioManager, "android.media.IAudioService");
105 // ----------------------------------------------------------------------------
107 }; // namespace android