Jean-Michel Trivi | 0008a48 | 2016-12-26 15:58:24 -0800 | [diff] [blame] | 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 | |
| 28 | namespace android { |
| 29 | |
| 30 | class BpAudioManager : public BpInterface<IAudioManager> |
| 31 | { |
| 32 | public: |
| 33 | explicit BpAudioManager(const sp<IBinder>& impl) |
| 34 | : BpInterface<IAudioManager>(impl) |
| 35 | { |
| 36 | } |
| 37 | |
Jean-Michel Trivi | 6318932 | 2017-01-05 18:05:28 -0800 | [diff] [blame] | 38 | virtual audio_unique_id_t trackPlayer(player_type_t playerType, audio_usage_t usage, |
Eric Laurent | bf28ea6 | 2021-01-29 20:45:03 +0100 | [diff] [blame] | 39 | audio_content_type_t content, const sp<IBinder>& player, audio_session_t sessionId) { |
Jean-Michel Trivi | 0008a48 | 2016-12-26 15:58:24 -0800 | [diff] [blame] | 40 | Parcel data, reply; |
| 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 |
Jean-Michel Trivi | 6318932 | 2017-01-05 18:05:28 -0800 | [diff] [blame] | 46 | data.writeInt32((int32_t) usage); |
| 47 | data.writeInt32((int32_t) content); |
Jean-Michel Trivi | 0008a48 | 2016-12-26 15:58:24 -0800 | [diff] [blame] | 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 |
Jean-Michel Trivi | 6318932 | 2017-01-05 18:05:28 -0800 | [diff] [blame] | 55 | // write IPlayer |
| 56 | data.writeStrongBinder(player); |
Eric Laurent | bf28ea6 | 2021-01-29 20:45:03 +0100 | [diff] [blame] | 57 | // write session Id |
| 58 | data.writeInt32((int32_t)sessionId); |
Jean-Michel Trivi | 0008a48 | 2016-12-26 15:58:24 -0800 | [diff] [blame] | 59 | // get new PIId in reply |
| 60 | const status_t res = remote()->transact(TRACK_PLAYER, data, &reply, 0); |
| 61 | if (res != OK || reply.readExceptionCode() != 0) { |
| 62 | ALOGE("trackPlayer() failed, piid is %d", PLAYER_PIID_INVALID); |
| 63 | return PLAYER_PIID_INVALID; |
| 64 | } else { |
| 65 | const audio_unique_id_t piid = (audio_unique_id_t) reply.readInt32(); |
| 66 | ALOGV("trackPlayer() returned piid %d", piid); |
| 67 | return piid; |
| 68 | } |
| 69 | } |
| 70 | |
Jean-Michel Trivi | 6318932 | 2017-01-05 18:05:28 -0800 | [diff] [blame] | 71 | virtual status_t playerAttributes(audio_unique_id_t piid, audio_usage_t usage, |
| 72 | audio_content_type_t content) { |
Jean-Michel Trivi | 0008a48 | 2016-12-26 15:58:24 -0800 | [diff] [blame] | 73 | Parcel data, reply; |
| 74 | data.writeInterfaceToken(IAudioManager::getInterfaceDescriptor()); |
Jean-Michel Trivi | 6318932 | 2017-01-05 18:05:28 -0800 | [diff] [blame] | 75 | data.writeInt32((int32_t) piid); |
Jean-Michel Trivi | 0008a48 | 2016-12-26 15:58:24 -0800 | [diff] [blame] | 76 | data.writeInt32(1); // non-null AudioAttributes parcelable |
Jean-Michel Trivi | 6318932 | 2017-01-05 18:05:28 -0800 | [diff] [blame] | 77 | data.writeInt32((int32_t) usage); |
| 78 | data.writeInt32((int32_t) content); |
Jean-Michel Trivi | 0008a48 | 2016-12-26 15:58:24 -0800 | [diff] [blame] | 79 | data.writeInt32(0 /*source: none here, this is a player*/); |
| 80 | data.writeInt32(0 /*flags*/); |
| 81 | // write attributes' tags |
| 82 | data.writeInt32(1 /*FLATTEN_TAGS*/); |
| 83 | data.writeString16(String16("")); // no tags |
| 84 | // write attributes' bundle |
| 85 | data.writeInt32(-1977 /*ATTR_PARCEL_IS_NULL_BUNDLE*/); // no bundle |
| 86 | return remote()->transact(PLAYER_ATTRIBUTES, data, &reply, IBinder::FLAG_ONEWAY); |
| 87 | } |
| 88 | |
Oscar Azucena | fae808f | 2020-12-22 20:40:07 +0000 | [diff] [blame] | 89 | virtual status_t playerEvent(audio_unique_id_t piid, player_state_t event, |
Robert Wu | 4fcdbe7 | 2024-10-29 23:48:24 +0000 | [diff] [blame] | 90 | const std::vector<audio_port_handle_t>& eventIds) { |
Jean-Michel Trivi | 0008a48 | 2016-12-26 15:58:24 -0800 | [diff] [blame] | 91 | Parcel data, reply; |
| 92 | data.writeInterfaceToken(IAudioManager::getInterfaceDescriptor()); |
Jean-Michel Trivi | 6318932 | 2017-01-05 18:05:28 -0800 | [diff] [blame] | 93 | data.writeInt32((int32_t) piid); |
| 94 | data.writeInt32((int32_t) event); |
Robert Wu | 4fcdbe7 | 2024-10-29 23:48:24 +0000 | [diff] [blame] | 95 | data.writeInt32((int32_t) eventIds.size()); |
| 96 | for (auto eventId: eventIds) { |
| 97 | data.writeInt32((int32_t) eventId); |
| 98 | } |
Jean-Michel Trivi | 0008a48 | 2016-12-26 15:58:24 -0800 | [diff] [blame] | 99 | return remote()->transact(PLAYER_EVENT, data, &reply, IBinder::FLAG_ONEWAY); |
| 100 | } |
| 101 | |
Jean-Michel Trivi | 6318932 | 2017-01-05 18:05:28 -0800 | [diff] [blame] | 102 | virtual status_t releasePlayer(audio_unique_id_t piid) { |
Jean-Michel Trivi | 0008a48 | 2016-12-26 15:58:24 -0800 | [diff] [blame] | 103 | Parcel data, reply; |
| 104 | data.writeInterfaceToken(IAudioManager::getInterfaceDescriptor()); |
Jean-Michel Trivi | 6318932 | 2017-01-05 18:05:28 -0800 | [diff] [blame] | 105 | data.writeInt32((int32_t) piid); |
Jean-Michel Trivi | 0008a48 | 2016-12-26 15:58:24 -0800 | [diff] [blame] | 106 | return remote()->transact(RELEASE_PLAYER, data, &reply, IBinder::FLAG_ONEWAY); |
| 107 | } |
Mikhail Naganov | decb629 | 2019-04-10 16:49:02 -0700 | [diff] [blame] | 108 | |
| 109 | virtual audio_unique_id_t trackRecorder(const sp<IBinder>& recorder) { |
| 110 | Parcel data, reply; |
| 111 | data.writeInterfaceToken(IAudioManager::getInterfaceDescriptor()); |
| 112 | data.writeStrongBinder(recorder); |
| 113 | // get new RIId in reply |
| 114 | const status_t res = remote()->transact(TRACK_RECORDER, data, &reply, 0); |
| 115 | if (res != OK || reply.readExceptionCode() != 0) { |
| 116 | ALOGE("trackRecorder() failed, riid is %d", RECORD_RIID_INVALID); |
| 117 | return RECORD_RIID_INVALID; |
| 118 | } else { |
| 119 | const audio_unique_id_t riid = (audio_unique_id_t) reply.readInt32(); |
| 120 | ALOGV("trackRecorder() returned riid %d", riid); |
| 121 | return riid; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | virtual status_t recorderEvent(audio_unique_id_t riid, recorder_state_t event) { |
| 126 | Parcel data, reply; |
| 127 | data.writeInterfaceToken(IAudioManager::getInterfaceDescriptor()); |
| 128 | data.writeInt32((int32_t) riid); |
| 129 | data.writeInt32((int32_t) event); |
| 130 | return remote()->transact(RECORDER_EVENT, data, &reply, IBinder::FLAG_ONEWAY); |
| 131 | } |
Mikhail Naganov | b8bff0c | 2019-05-09 09:06:15 -0700 | [diff] [blame] | 132 | |
| 133 | virtual status_t releaseRecorder(audio_unique_id_t riid) { |
| 134 | Parcel data, reply; |
| 135 | data.writeInterfaceToken(IAudioManager::getInterfaceDescriptor()); |
| 136 | data.writeInt32((int32_t) riid); |
| 137 | return remote()->transact(RELEASE_RECORDER, data, &reply, IBinder::FLAG_ONEWAY); |
| 138 | } |
Eric Laurent | bf28ea6 | 2021-01-29 20:45:03 +0100 | [diff] [blame] | 139 | |
| 140 | virtual status_t playerSessionId(audio_unique_id_t piid, audio_session_t sessionId) { |
| 141 | Parcel data, reply; |
| 142 | data.writeInterfaceToken(IAudioManager::getInterfaceDescriptor()); |
| 143 | data.writeInt32((int32_t) piid); |
| 144 | data.writeInt32((int32_t) sessionId); |
| 145 | return remote()->transact(PLAYER_SESSION_ID, data, &reply, IBinder::FLAG_ONEWAY); |
| 146 | } |
Vlad Popa | 5cb9856 | 2022-06-30 15:48:16 +0200 | [diff] [blame] | 147 | |
| 148 | virtual status_t portEvent(audio_port_handle_t portId, player_state_t event, |
| 149 | const std::unique_ptr<os::PersistableBundle>& extras) { |
| 150 | Parcel data, reply; |
| 151 | data.writeInterfaceToken(IAudioManager::getInterfaceDescriptor()); |
| 152 | data.writeInt32((int32_t) portId); |
| 153 | data.writeInt32((int32_t) event); |
| 154 | // TODO: replace PersistableBundle with own struct |
| 155 | data.writeNullableParcelable(extras); |
| 156 | return remote()->transact(PORT_EVENT, data, &reply, IBinder::FLAG_ONEWAY); |
| 157 | } |
Atneya Nair | c54c364 | 2024-08-17 20:30:26 -0700 | [diff] [blame] | 158 | |
| 159 | virtual status_t permissionUpdateBarrier() { |
| 160 | Parcel data, reply; |
| 161 | data.writeInterfaceToken(IAudioManager::getInterfaceDescriptor()); |
| 162 | return remote()->transact(PERMISSION_UPDATE_BARRIER, data, &reply, 0); |
| 163 | } |
Jean-Michel Trivi | 0008a48 | 2016-12-26 15:58:24 -0800 | [diff] [blame] | 164 | }; |
| 165 | |
| 166 | IMPLEMENT_META_INTERFACE(AudioManager, "android.media.IAudioService"); |
| 167 | |
| 168 | // ---------------------------------------------------------------------------- |
| 169 | |
| 170 | }; // namespace android |