12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417 |
- /*
- **
- ** Copyright 2009, The Android Open Source Project
- **
- ** Licensed under the Apache License, Version 2.0 (the "License");
- ** you may not use this file except in compliance with the License.
- ** You may obtain a copy of the License at
- **
- ** http://www.apache.org/licenses/LICENSE-2.0
- **
- ** Unless required by applicable law or agreed to in writing, software
- ** distributed under the License is distributed on an "AS IS" BASIS,
- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ** See the License for the specific language governing permissions and
- ** limitations under the License.
- */
- #define LOG_TAG "IAudioPolicyService"
- #include <utils/Log.h>
- #include <stdint.h>
- #include <math.h>
- #include <sys/types.h>
- #include <binder/IPCThreadState.h>
- #include <binder/Parcel.h>
- #include <media/AudioEffect.h>
- #include <media/IAudioPolicyService.h>
- #include <media/TimeCheck.h>
- #include <mediautils/ServiceUtilities.h>
- #include <system/audio.h>
- namespace android {
- enum {
- SET_DEVICE_CONNECTION_STATE = IBinder::FIRST_CALL_TRANSACTION,
- GET_DEVICE_CONNECTION_STATE,
- HANDLE_DEVICE_CONFIG_CHANGE,
- SET_PHONE_STATE,
- SET_RINGER_MODE, // reserved, no longer used
- SET_FORCE_USE,
- GET_FORCE_USE,
- GET_OUTPUT,
- START_OUTPUT,
- STOP_OUTPUT,
- RELEASE_OUTPUT,
- GET_INPUT_FOR_ATTR,
- START_INPUT,
- STOP_INPUT,
- RELEASE_INPUT,
- INIT_STREAM_VOLUME,
- SET_STREAM_VOLUME,
- GET_STREAM_VOLUME,
- SET_VOLUME_ATTRIBUTES,
- GET_VOLUME_ATTRIBUTES,
- GET_MIN_VOLUME_FOR_ATTRIBUTES,
- GET_MAX_VOLUME_FOR_ATTRIBUTES,
- GET_STRATEGY_FOR_STREAM,
- GET_OUTPUT_FOR_EFFECT,
- REGISTER_EFFECT,
- UNREGISTER_EFFECT,
- IS_STREAM_ACTIVE,
- IS_SOURCE_ACTIVE,
- GET_DEVICES_FOR_STREAM,
- QUERY_DEFAULT_PRE_PROCESSING,
- SET_EFFECT_ENABLED,
- IS_STREAM_ACTIVE_REMOTELY,
- IS_OFFLOAD_SUPPORTED,
- IS_DIRECT_OUTPUT_SUPPORTED,
- LIST_AUDIO_PORTS,
- GET_AUDIO_PORT,
- CREATE_AUDIO_PATCH,
- RELEASE_AUDIO_PATCH,
- LIST_AUDIO_PATCHES,
- SET_AUDIO_PORT_CONFIG,
- REGISTER_CLIENT,
- GET_OUTPUT_FOR_ATTR,
- ACQUIRE_SOUNDTRIGGER_SESSION,
- RELEASE_SOUNDTRIGGER_SESSION,
- GET_PHONE_STATE,
- REGISTER_POLICY_MIXES,
- START_AUDIO_SOURCE,
- STOP_AUDIO_SOURCE,
- SET_AUDIO_PORT_CALLBACK_ENABLED,
- SET_AUDIO_VOLUME_GROUP_CALLBACK_ENABLED,
- SET_MASTER_MONO,
- GET_MASTER_MONO,
- GET_STREAM_VOLUME_DB,
- GET_SURROUND_FORMATS,
- SET_SURROUND_FORMAT_ENABLED,
- ADD_STREAM_DEFAULT_EFFECT,
- REMOVE_STREAM_DEFAULT_EFFECT,
- ADD_SOURCE_DEFAULT_EFFECT,
- REMOVE_SOURCE_DEFAULT_EFFECT,
- SET_ASSISTANT_UID,
- SET_A11Y_SERVICES_UIDS,
- IS_HAPTIC_PLAYBACK_SUPPORTED,
- SET_UID_DEVICE_AFFINITY,
- REMOVE_UID_DEVICE_AFFINITY,
- GET_OFFLOAD_FORMATS_A2DP,
- LIST_AUDIO_PRODUCT_STRATEGIES,
- GET_STRATEGY_FOR_ATTRIBUTES,
- LIST_AUDIO_VOLUME_GROUPS,
- GET_VOLUME_GROUP_FOR_ATTRIBUTES,
- SET_ALLOWED_CAPTURE_POLICY,
- MOVE_EFFECTS_TO_IO,
- SET_RTT_ENABLED
- };
- #define MAX_ITEMS_PER_LIST 1024
- class BpAudioPolicyService : public BpInterface<IAudioPolicyService>
- {
- public:
- explicit BpAudioPolicyService(const sp<IBinder>& impl)
- : BpInterface<IAudioPolicyService>(impl)
- {
- }
- virtual status_t setDeviceConnectionState(
- audio_devices_t device,
- audio_policy_dev_state_t state,
- const char *device_address,
- const char *device_name,
- audio_format_t encodedFormat)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32(static_cast <uint32_t>(device));
- data.writeInt32(static_cast <uint32_t>(state));
- data.writeCString(device_address);
- data.writeCString(device_name);
- data.writeInt32(static_cast <uint32_t>(encodedFormat));
- remote()->transact(SET_DEVICE_CONNECTION_STATE, data, &reply);
- return static_cast <status_t> (reply.readInt32());
- }
- virtual audio_policy_dev_state_t getDeviceConnectionState(
- audio_devices_t device,
- const char *device_address)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32(static_cast <uint32_t>(device));
- data.writeCString(device_address);
- remote()->transact(GET_DEVICE_CONNECTION_STATE, data, &reply);
- return static_cast <audio_policy_dev_state_t>(reply.readInt32());
- }
- virtual status_t handleDeviceConfigChange(audio_devices_t device,
- const char *device_address,
- const char *device_name,
- audio_format_t encodedFormat)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32(static_cast <uint32_t>(device));
- data.writeCString(device_address);
- data.writeCString(device_name);
- data.writeInt32(static_cast <uint32_t>(encodedFormat));
- remote()->transact(HANDLE_DEVICE_CONFIG_CHANGE, data, &reply);
- return static_cast <status_t> (reply.readInt32());
- }
- virtual status_t setPhoneState(audio_mode_t state)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32(state);
- remote()->transact(SET_PHONE_STATE, data, &reply);
- return static_cast <status_t> (reply.readInt32());
- }
- virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32(static_cast <uint32_t>(usage));
- data.writeInt32(static_cast <uint32_t>(config));
- remote()->transact(SET_FORCE_USE, data, &reply);
- return static_cast <status_t> (reply.readInt32());
- }
- virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32(static_cast <uint32_t>(usage));
- remote()->transact(GET_FORCE_USE, data, &reply);
- return static_cast <audio_policy_forced_cfg_t> (reply.readInt32());
- }
- virtual audio_io_handle_t getOutput(audio_stream_type_t stream)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32(static_cast <uint32_t>(stream));
- remote()->transact(GET_OUTPUT, data, &reply);
- return static_cast <audio_io_handle_t> (reply.readInt32());
- }
- status_t getOutputForAttr(audio_attributes_t *attr,
- audio_io_handle_t *output,
- audio_session_t session,
- audio_stream_type_t *stream,
- pid_t pid,
- uid_t uid,
- const audio_config_t *config,
- audio_output_flags_t flags,
- audio_port_handle_t *selectedDeviceId,
- audio_port_handle_t *portId,
- std::vector<audio_io_handle_t> *secondaryOutputs) override
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- if (attr == nullptr) {
- ALOGE("%s NULL audio attributes", __func__);
- return BAD_VALUE;
- }
- if (output == nullptr) {
- ALOGE("%s NULL output - shouldn't happen", __func__);
- return BAD_VALUE;
- }
- if (selectedDeviceId == nullptr) {
- ALOGE("%s NULL selectedDeviceId - shouldn't happen", __func__);
- return BAD_VALUE;
- }
- if (portId == nullptr) {
- ALOGE("%s NULL portId - shouldn't happen", __func__);
- return BAD_VALUE;
- }
- if (secondaryOutputs == nullptr) {
- ALOGE("%s NULL secondaryOutputs - shouldn't happen", __func__);
- return BAD_VALUE;
- }
- data.write(attr, sizeof(audio_attributes_t));
- data.writeInt32(session);
- if (stream == NULL) {
- data.writeInt32(0);
- } else {
- data.writeInt32(1);
- data.writeInt32(*stream);
- }
- data.writeInt32(pid);
- data.writeInt32(uid);
- data.write(config, sizeof(audio_config_t));
- data.writeInt32(static_cast <uint32_t>(flags));
- data.writeInt32(*selectedDeviceId);
- data.writeInt32(*portId);
- status_t status = remote()->transact(GET_OUTPUT_FOR_ATTR, data, &reply);
- if (status != NO_ERROR) {
- return status;
- }
- status = (status_t)reply.readInt32();
- if (status != NO_ERROR) {
- return status;
- }
- status = (status_t)reply.read(&attr, sizeof(audio_attributes_t));
- if (status != NO_ERROR) {
- return status;
- }
- *output = (audio_io_handle_t)reply.readInt32();
- audio_stream_type_t lStream = (audio_stream_type_t)reply.readInt32();
- if (stream != NULL) {
- *stream = lStream;
- }
- *selectedDeviceId = (audio_port_handle_t)reply.readInt32();
- *portId = (audio_port_handle_t)reply.readInt32();
- secondaryOutputs->resize(reply.readInt32());
- return reply.read(secondaryOutputs->data(),
- secondaryOutputs->size() * sizeof(audio_io_handle_t));
- }
- virtual status_t startOutput(audio_port_handle_t portId)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32((int32_t)portId);
- remote()->transact(START_OUTPUT, data, &reply);
- return static_cast <status_t> (reply.readInt32());
- }
- virtual status_t stopOutput(audio_port_handle_t portId)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32((int32_t)portId);
- remote()->transact(STOP_OUTPUT, data, &reply);
- return static_cast <status_t> (reply.readInt32());
- }
- virtual void releaseOutput(audio_port_handle_t portId)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32((int32_t)portId);
- remote()->transact(RELEASE_OUTPUT, data, &reply);
- }
- virtual status_t getInputForAttr(const audio_attributes_t *attr,
- audio_io_handle_t *input,
- audio_unique_id_t riid,
- audio_session_t session,
- pid_t pid,
- uid_t uid,
- const String16& opPackageName,
- const audio_config_base_t *config,
- audio_input_flags_t flags,
- audio_port_handle_t *selectedDeviceId,
- audio_port_handle_t *portId)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- if (attr == NULL) {
- ALOGE("getInputForAttr NULL attr - shouldn't happen");
- return BAD_VALUE;
- }
- if (input == NULL) {
- ALOGE("getInputForAttr NULL input - shouldn't happen");
- return BAD_VALUE;
- }
- if (selectedDeviceId == NULL) {
- ALOGE("getInputForAttr NULL selectedDeviceId - shouldn't happen");
- return BAD_VALUE;
- }
- if (portId == NULL) {
- ALOGE("getInputForAttr NULL portId - shouldn't happen");
- return BAD_VALUE;
- }
- data.write(attr, sizeof(audio_attributes_t));
- data.writeInt32(*input);
- data.writeInt32(riid);
- data.writeInt32(session);
- data.writeInt32(pid);
- data.writeInt32(uid);
- data.writeString16(opPackageName);
- data.write(config, sizeof(audio_config_base_t));
- data.writeInt32(flags);
- data.writeInt32(*selectedDeviceId);
- data.writeInt32(*portId);
- status_t status = remote()->transact(GET_INPUT_FOR_ATTR, data, &reply);
- if (status != NO_ERROR) {
- return status;
- }
- status = reply.readInt32();
- if (status != NO_ERROR) {
- return status;
- }
- *input = (audio_io_handle_t)reply.readInt32();
- *selectedDeviceId = (audio_port_handle_t)reply.readInt32();
- *portId = (audio_port_handle_t)reply.readInt32();
- return NO_ERROR;
- }
- virtual status_t startInput(audio_port_handle_t portId)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32(portId);
- remote()->transact(START_INPUT, data, &reply);
- status_t status = static_cast <status_t> (reply.readInt32());
- return status;
- }
- virtual status_t stopInput(audio_port_handle_t portId)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32(portId);
- remote()->transact(STOP_INPUT, data, &reply);
- return static_cast <status_t> (reply.readInt32());
- }
- virtual void releaseInput(audio_port_handle_t portId)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32(portId);
- remote()->transact(RELEASE_INPUT, data, &reply);
- }
- virtual status_t initStreamVolume(audio_stream_type_t stream,
- int indexMin,
- int indexMax)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32(static_cast <uint32_t>(stream));
- data.writeInt32(indexMin);
- data.writeInt32(indexMax);
- remote()->transact(INIT_STREAM_VOLUME, data, &reply);
- return static_cast <status_t> (reply.readInt32());
- }
- virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
- int index,
- audio_devices_t device)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32(static_cast <uint32_t>(stream));
- data.writeInt32(index);
- data.writeInt32(static_cast <uint32_t>(device));
- remote()->transact(SET_STREAM_VOLUME, data, &reply);
- return static_cast <status_t> (reply.readInt32());
- }
- virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
- int *index,
- audio_devices_t device)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32(static_cast <uint32_t>(stream));
- data.writeInt32(static_cast <uint32_t>(device));
- remote()->transact(GET_STREAM_VOLUME, data, &reply);
- int lIndex = reply.readInt32();
- if (index) *index = lIndex;
- return static_cast <status_t> (reply.readInt32());
- }
- virtual status_t setVolumeIndexForAttributes(const audio_attributes_t &attr, int index,
- audio_devices_t device)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.write(&attr, sizeof(audio_attributes_t));
- data.writeInt32(index);
- data.writeInt32(static_cast <uint32_t>(device));
- status_t status = remote()->transact(SET_VOLUME_ATTRIBUTES, data, &reply);
- if (status != NO_ERROR) {
- return status;
- }
- return static_cast <status_t> (reply.readInt32());
- }
- virtual status_t getVolumeIndexForAttributes(const audio_attributes_t &attr, int &index,
- audio_devices_t device)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.write(&attr, sizeof(audio_attributes_t));
- data.writeInt32(static_cast <uint32_t>(device));
- status_t status = remote()->transact(GET_VOLUME_ATTRIBUTES, data, &reply);
- if (status != NO_ERROR) {
- return status;
- }
- status = static_cast <status_t> (reply.readInt32());
- if (status != NO_ERROR) {
- return status;
- }
- index = reply.readInt32();
- return NO_ERROR;
- }
- virtual status_t getMinVolumeIndexForAttributes(const audio_attributes_t &attr, int &index)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.write(&attr, sizeof(audio_attributes_t));
- status_t status = remote()->transact(GET_MIN_VOLUME_FOR_ATTRIBUTES, data, &reply);
- if (status != NO_ERROR) {
- return status;
- }
- status = static_cast <status_t> (reply.readInt32());
- if (status != NO_ERROR) {
- return status;
- }
- index = reply.readInt32();
- return NO_ERROR;
- }
- virtual status_t getMaxVolumeIndexForAttributes(const audio_attributes_t &attr, int &index)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.write(&attr, sizeof(audio_attributes_t));
- status_t status = remote()->transact(GET_MAX_VOLUME_FOR_ATTRIBUTES, data, &reply);
- if (status != NO_ERROR) {
- return status;
- }
- status = static_cast <status_t> (reply.readInt32());
- if (status != NO_ERROR) {
- return status;
- }
- index = reply.readInt32();
- return NO_ERROR;
- }
- virtual uint32_t getStrategyForStream(audio_stream_type_t stream)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32(static_cast <uint32_t>(stream));
- remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply);
- return reply.readUint32();
- }
- virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32(static_cast <uint32_t>(stream));
- remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
- return (audio_devices_t) reply.readInt32();
- }
- virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.write(desc, sizeof(effect_descriptor_t));
- remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply);
- return static_cast <audio_io_handle_t> (reply.readInt32());
- }
- virtual status_t registerEffect(const effect_descriptor_t *desc,
- audio_io_handle_t io,
- uint32_t strategy,
- audio_session_t session,
- int id)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.write(desc, sizeof(effect_descriptor_t));
- data.writeInt32(io);
- data.writeInt32(strategy);
- data.writeInt32(session);
- data.writeInt32(id);
- remote()->transact(REGISTER_EFFECT, data, &reply);
- return static_cast <status_t> (reply.readInt32());
- }
- virtual status_t unregisterEffect(int id)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32(id);
- remote()->transact(UNREGISTER_EFFECT, data, &reply);
- return static_cast <status_t> (reply.readInt32());
- }
- virtual status_t setEffectEnabled(int id, bool enabled)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32(id);
- data.writeInt32(enabled);
- remote()->transact(SET_EFFECT_ENABLED, data, &reply);
- return static_cast <status_t> (reply.readInt32());
- }
- status_t moveEffectsToIo(const std::vector<int>& ids, audio_io_handle_t io) override
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32(ids.size());
- for (auto id : ids) {
- data.writeInt32(id);
- }
- data.writeInt32(io);
- status_t status = remote()->transact(MOVE_EFFECTS_TO_IO, data, &reply);
- if (status != NO_ERROR) {
- return status;
- }
- return static_cast <status_t> (reply.readInt32());
- }
- virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32((int32_t) stream);
- data.writeInt32(inPastMs);
- remote()->transact(IS_STREAM_ACTIVE, data, &reply);
- return reply.readInt32();
- }
- virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32((int32_t) stream);
- data.writeInt32(inPastMs);
- remote()->transact(IS_STREAM_ACTIVE_REMOTELY, data, &reply);
- return reply.readInt32();
- }
- virtual bool isSourceActive(audio_source_t source) const
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32((int32_t) source);
- remote()->transact(IS_SOURCE_ACTIVE, data, &reply);
- return reply.readInt32();
- }
- virtual status_t queryDefaultPreProcessing(audio_session_t audioSession,
- effect_descriptor_t *descriptors,
- uint32_t *count)
- {
- if (descriptors == NULL || count == NULL) {
- return BAD_VALUE;
- }
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32(audioSession);
- data.writeInt32(*count);
- status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply);
- if (status != NO_ERROR) {
- return status;
- }
- status = static_cast <status_t> (reply.readInt32());
- uint32_t retCount = reply.readInt32();
- if (retCount != 0) {
- uint32_t numDesc = (retCount < *count) ? retCount : *count;
- reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc);
- }
- *count = retCount;
- return status;
- }
- status_t setAllowedCapturePolicy(uid_t uid, audio_flags_mask_t flags) override {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32(uid);
- data.writeInt32(flags);
- remote()->transact(SET_ALLOWED_CAPTURE_POLICY, data, &reply);
- return reply.readInt32();
- }
- virtual bool isOffloadSupported(const audio_offload_info_t& info)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.write(&info, sizeof(audio_offload_info_t));
- remote()->transact(IS_OFFLOAD_SUPPORTED, data, &reply);
- return reply.readInt32();
- }
- virtual bool isDirectOutputSupported(const audio_config_base_t& config,
- const audio_attributes_t& attributes) {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.write(&config, sizeof(audio_config_base_t));
- data.write(&attributes, sizeof(audio_attributes_t));
- status_t status = remote()->transact(IS_DIRECT_OUTPUT_SUPPORTED, data, &reply);
- return status == NO_ERROR ? static_cast<bool>(reply.readInt32()) : false;
- }
- virtual status_t listAudioPorts(audio_port_role_t role,
- audio_port_type_t type,
- unsigned int *num_ports,
- struct audio_port *ports,
- unsigned int *generation)
- {
- if (num_ports == NULL || (*num_ports != 0 && ports == NULL) ||
- generation == NULL) {
- return BAD_VALUE;
- }
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- unsigned int numPortsReq = (ports == NULL) ? 0 : *num_ports;
- data.writeInt32(role);
- data.writeInt32(type);
- data.writeInt32(numPortsReq);
- status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
- if (status == NO_ERROR) {
- status = (status_t)reply.readInt32();
- *num_ports = (unsigned int)reply.readInt32();
- }
- if (status == NO_ERROR) {
- if (numPortsReq > *num_ports) {
- numPortsReq = *num_ports;
- }
- if (numPortsReq > 0) {
- reply.read(ports, numPortsReq * sizeof(struct audio_port));
- }
- *generation = reply.readInt32();
- }
- return status;
- }
- virtual status_t getAudioPort(struct audio_port *port)
- {
- if (port == NULL) {
- return BAD_VALUE;
- }
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.write(port, sizeof(struct audio_port));
- status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
- if (status != NO_ERROR ||
- (status = (status_t)reply.readInt32()) != NO_ERROR) {
- return status;
- }
- reply.read(port, sizeof(struct audio_port));
- return status;
- }
- virtual status_t createAudioPatch(const struct audio_patch *patch,
- audio_patch_handle_t *handle)
- {
- if (patch == NULL || handle == NULL) {
- return BAD_VALUE;
- }
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.write(patch, sizeof(struct audio_patch));
- data.write(handle, sizeof(audio_patch_handle_t));
- status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
- if (status != NO_ERROR ||
- (status = (status_t)reply.readInt32()) != NO_ERROR) {
- return status;
- }
- reply.read(handle, sizeof(audio_patch_handle_t));
- return status;
- }
- virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.write(&handle, sizeof(audio_patch_handle_t));
- status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
- if (status != NO_ERROR) {
- status = (status_t)reply.readInt32();
- }
- return status;
- }
- virtual status_t listAudioPatches(unsigned int *num_patches,
- struct audio_patch *patches,
- unsigned int *generation)
- {
- if (num_patches == NULL || (*num_patches != 0 && patches == NULL) ||
- generation == NULL) {
- return BAD_VALUE;
- }
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- unsigned int numPatchesReq = (patches == NULL) ? 0 : *num_patches;
- data.writeInt32(numPatchesReq);
- status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
- if (status == NO_ERROR) {
- status = (status_t)reply.readInt32();
- *num_patches = (unsigned int)reply.readInt32();
- }
- if (status == NO_ERROR) {
- if (numPatchesReq > *num_patches) {
- numPatchesReq = *num_patches;
- }
- if (numPatchesReq > 0) {
- reply.read(patches, numPatchesReq * sizeof(struct audio_patch));
- }
- *generation = reply.readInt32();
- }
- return status;
- }
- virtual status_t setAudioPortConfig(const struct audio_port_config *config)
- {
- if (config == NULL) {
- return BAD_VALUE;
- }
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.write(config, sizeof(struct audio_port_config));
- status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
- if (status != NO_ERROR) {
- status = (status_t)reply.readInt32();
- }
- return status;
- }
- virtual void registerClient(const sp<IAudioPolicyServiceClient>& client)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeStrongBinder(IInterface::asBinder(client));
- remote()->transact(REGISTER_CLIENT, data, &reply);
- }
- virtual void setAudioPortCallbacksEnabled(bool enabled)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32(enabled ? 1 : 0);
- remote()->transact(SET_AUDIO_PORT_CALLBACK_ENABLED, data, &reply);
- }
- virtual void setAudioVolumeGroupCallbacksEnabled(bool enabled)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32(enabled ? 1 : 0);
- remote()->transact(SET_AUDIO_VOLUME_GROUP_CALLBACK_ENABLED, data, &reply);
- }
- virtual status_t acquireSoundTriggerSession(audio_session_t *session,
- audio_io_handle_t *ioHandle,
- audio_devices_t *device)
- {
- if (session == NULL || ioHandle == NULL || device == NULL) {
- return BAD_VALUE;
- }
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- status_t status = remote()->transact(ACQUIRE_SOUNDTRIGGER_SESSION, data, &reply);
- if (status != NO_ERROR) {
- return status;
- }
- status = (status_t)reply.readInt32();
- if (status == NO_ERROR) {
- *session = (audio_session_t)reply.readInt32();
- *ioHandle = (audio_io_handle_t)reply.readInt32();
- *device = (audio_devices_t)reply.readInt32();
- }
- return status;
- }
- virtual status_t releaseSoundTriggerSession(audio_session_t session)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32(session);
- status_t status = remote()->transact(RELEASE_SOUNDTRIGGER_SESSION, data, &reply);
- if (status != NO_ERROR) {
- return status;
- }
- return (status_t)reply.readInt32();
- }
- virtual audio_mode_t getPhoneState()
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- status_t status = remote()->transact(GET_PHONE_STATE, data, &reply);
- if (status != NO_ERROR) {
- return AUDIO_MODE_INVALID;
- }
- return (audio_mode_t)reply.readInt32();
- }
- virtual status_t registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32(registration ? 1 : 0);
- size_t size = mixes.size();
- if (size > MAX_MIXES_PER_POLICY) {
- size = MAX_MIXES_PER_POLICY;
- }
- size_t sizePosition = data.dataPosition();
- data.writeInt32(size);
- size_t finalSize = size;
- for (size_t i = 0; i < size; i++) {
- size_t position = data.dataPosition();
- if (mixes[i].writeToParcel(&data) != NO_ERROR) {
- data.setDataPosition(position);
- finalSize--;
- }
- }
- if (size != finalSize) {
- size_t position = data.dataPosition();
- data.setDataPosition(sizePosition);
- data.writeInt32(finalSize);
- data.setDataPosition(position);
- }
- status_t status = remote()->transact(REGISTER_POLICY_MIXES, data, &reply);
- if (status == NO_ERROR) {
- status = (status_t)reply.readInt32();
- }
- return status;
- }
- virtual status_t startAudioSource(const struct audio_port_config *source,
- const audio_attributes_t *attributes,
- audio_port_handle_t *portId)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- if (source == NULL || attributes == NULL || portId == NULL) {
- return BAD_VALUE;
- }
- data.write(source, sizeof(struct audio_port_config));
- data.write(attributes, sizeof(audio_attributes_t));
- status_t status = remote()->transact(START_AUDIO_SOURCE, data, &reply);
- if (status != NO_ERROR) {
- return status;
- }
- status = (status_t)reply.readInt32();
- if (status != NO_ERROR) {
- return status;
- }
- *portId = (audio_port_handle_t)reply.readInt32();
- return status;
- }
- virtual status_t stopAudioSource(audio_port_handle_t portId)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32(portId);
- status_t status = remote()->transact(STOP_AUDIO_SOURCE, data, &reply);
- if (status != NO_ERROR) {
- return status;
- }
- status = (status_t)reply.readInt32();
- return status;
- }
- virtual status_t setMasterMono(bool mono)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32(static_cast<int32_t>(mono));
- status_t status = remote()->transact(SET_MASTER_MONO, data, &reply);
- if (status != NO_ERROR) {
- return status;
- }
- return static_cast<status_t>(reply.readInt32());
- }
- virtual status_t getMasterMono(bool *mono)
- {
- if (mono == nullptr) {
- return BAD_VALUE;
- }
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- status_t status = remote()->transact(GET_MASTER_MONO, data, &reply);
- if (status != NO_ERROR) {
- return status;
- }
- status = static_cast<status_t>(reply.readInt32());
- if (status == NO_ERROR) {
- *mono = static_cast<bool>(reply.readInt32());
- }
- return status;
- }
- virtual float getStreamVolumeDB(audio_stream_type_t stream, int index, audio_devices_t device)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32(static_cast <int32_t>(stream));
- data.writeInt32(static_cast <int32_t>(index));
- data.writeUint32(static_cast <uint32_t>(device));
- status_t status = remote()->transact(GET_STREAM_VOLUME_DB, data, &reply);
- if (status != NO_ERROR) {
- return NAN;
- }
- return reply.readFloat();
- }
- virtual status_t getSurroundFormats(unsigned int *numSurroundFormats,
- audio_format_t *surroundFormats,
- bool *surroundFormatsEnabled,
- bool reported)
- {
- if (numSurroundFormats == NULL || (*numSurroundFormats != 0 &&
- (surroundFormats == NULL || surroundFormatsEnabled == NULL))) {
- return BAD_VALUE;
- }
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- unsigned int numSurroundFormatsReq = *numSurroundFormats;
- data.writeUint32(numSurroundFormatsReq);
- data.writeBool(reported);
- status_t status = remote()->transact(GET_SURROUND_FORMATS, data, &reply);
- if (status == NO_ERROR && (status = (status_t)reply.readInt32()) == NO_ERROR) {
- *numSurroundFormats = reply.readUint32();
- }
- if (status == NO_ERROR) {
- if (numSurroundFormatsReq > *numSurroundFormats) {
- numSurroundFormatsReq = *numSurroundFormats;
- }
- if (numSurroundFormatsReq > 0) {
- status = reply.read(surroundFormats,
- numSurroundFormatsReq * sizeof(audio_format_t));
- if (status != NO_ERROR) {
- return status;
- }
- status = reply.read(surroundFormatsEnabled,
- numSurroundFormatsReq * sizeof(bool));
- }
- }
- return status;
- }
- virtual status_t setSurroundFormatEnabled(audio_format_t audioFormat, bool enabled)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32(audioFormat);
- data.writeBool(enabled);
- status_t status = remote()->transact(SET_SURROUND_FORMAT_ENABLED, data, &reply);
- if (status != NO_ERROR) {
- return status;
- }
- return reply.readInt32();
- }
- virtual status_t getHwOffloadEncodingFormatsSupportedForA2DP(
- std::vector<audio_format_t> *formats)
- {
- if (formats == NULL) {
- return BAD_VALUE;
- }
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- status_t status = remote()->transact(GET_OFFLOAD_FORMATS_A2DP, data, &reply);
- if (status != NO_ERROR || (status = (status_t)reply.readInt32()) != NO_ERROR) {
- return status;
- }
- size_t list_size = reply.readUint32();
- for (size_t i = 0; i < list_size; i++) {
- formats->push_back(static_cast<audio_format_t>(reply.readInt32()));
- }
- return NO_ERROR;
- }
- virtual status_t addStreamDefaultEffect(const effect_uuid_t *type,
- const String16& opPackageName,
- const effect_uuid_t *uuid,
- int32_t priority,
- audio_usage_t usage,
- audio_unique_id_t* id)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.write(type, sizeof(effect_uuid_t));
- data.writeString16(opPackageName);
- data.write(uuid, sizeof(effect_uuid_t));
- data.writeInt32(priority);
- data.writeInt32((int32_t) usage);
- status_t status = remote()->transact(ADD_STREAM_DEFAULT_EFFECT, data, &reply);
- if (status != NO_ERROR) {
- return status;
- }
- status = static_cast <status_t> (reply.readInt32());
- *id = reply.readInt32();
- return status;
- }
- virtual status_t removeStreamDefaultEffect(audio_unique_id_t id)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32(id);
- status_t status = remote()->transact(REMOVE_STREAM_DEFAULT_EFFECT, data, &reply);
- if (status != NO_ERROR) {
- return status;
- }
- return static_cast <status_t> (reply.readInt32());
- }
- virtual status_t addSourceDefaultEffect(const effect_uuid_t *type,
- const String16& opPackageName,
- const effect_uuid_t *uuid,
- int32_t priority,
- audio_source_t source,
- audio_unique_id_t* id)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.write(type, sizeof(effect_uuid_t));
- data.writeString16(opPackageName);
- data.write(uuid, sizeof(effect_uuid_t));
- data.writeInt32(priority);
- data.writeInt32((int32_t) source);
- status_t status = remote()->transact(ADD_SOURCE_DEFAULT_EFFECT, data, &reply);
- if (status != NO_ERROR) {
- return status;
- }
- status = static_cast <status_t> (reply.readInt32());
- *id = reply.readInt32();
- return status;
- }
- virtual status_t removeSourceDefaultEffect(audio_unique_id_t id)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32(id);
- status_t status = remote()->transact(REMOVE_SOURCE_DEFAULT_EFFECT, data, &reply);
- if (status != NO_ERROR) {
- return status;
- }
- return static_cast <status_t> (reply.readInt32());
- }
- virtual status_t setAssistantUid(uid_t uid)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32(uid);
- status_t status = remote()->transact(SET_ASSISTANT_UID, data, &reply);
- if (status != NO_ERROR) {
- return status;
- }
- return static_cast <status_t> (reply.readInt32());
- }
- virtual status_t setA11yServicesUids(const std::vector<uid_t>& uids)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32(uids.size());
- for (auto uid : uids) {
- data.writeInt32(uid);
- }
- status_t status = remote()->transact(SET_A11Y_SERVICES_UIDS, data, &reply);
- if (status != NO_ERROR) {
- return status;
- }
- return static_cast <status_t> (reply.readInt32());
- }
- virtual bool isHapticPlaybackSupported()
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- status_t status = remote()->transact(IS_HAPTIC_PLAYBACK_SUPPORTED, data, &reply);
- if (status != NO_ERROR) {
- return false;
- }
- return reply.readBool();
- }
- virtual status_t setUidDeviceAffinities(uid_t uid, const Vector<AudioDeviceTypeAddr>& devices)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32((int32_t) uid);
- size_t size = devices.size();
- size_t sizePosition = data.dataPosition();
- data.writeInt32((int32_t) size);
- size_t finalSize = size;
- for (size_t i = 0; i < size; i++) {
- size_t position = data.dataPosition();
- if (devices[i].writeToParcel(&data) != NO_ERROR) {
- data.setDataPosition(position);
- finalSize--;
- }
- }
- if (size != finalSize) {
- size_t position = data.dataPosition();
- data.setDataPosition(sizePosition);
- data.writeInt32(finalSize);
- data.setDataPosition(position);
- }
- status_t status = remote()->transact(SET_UID_DEVICE_AFFINITY, data, &reply);
- if (status == NO_ERROR) {
- status = (status_t)reply.readInt32();
- }
- return status;
- }
- virtual status_t removeUidDeviceAffinities(uid_t uid) {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32((int32_t) uid);
- status_t status =
- remote()->transact(REMOVE_UID_DEVICE_AFFINITY, data, &reply);
- if (status == NO_ERROR) {
- status = (status_t) reply.readInt32();
- }
- return status;
- }
- virtual status_t listAudioProductStrategies(AudioProductStrategyVector &strategies)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- status_t status = remote()->transact(LIST_AUDIO_PRODUCT_STRATEGIES, data, &reply);
- if (status != NO_ERROR) {
- ALOGE("%s: permission denied", __func__);
- return status;
- }
- status = static_cast<status_t>(reply.readInt32());
- if (status != NO_ERROR) {
- return status;
- }
- uint32_t numStrategies = static_cast<uint32_t>(reply.readInt32());
- for (size_t i = 0; i < numStrategies; i++) {
- AudioProductStrategy strategy;
- status = strategy.readFromParcel(&reply);
- if (status != NO_ERROR) {
- ALOGE("%s: failed to read strategies", __FUNCTION__);
- strategies.clear();
- return status;
- }
- strategies.push_back(strategy);
- }
- return NO_ERROR;
- }
- virtual status_t getProductStrategyFromAudioAttributes(const AudioAttributes &aa,
- product_strategy_t &productStrategy)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- status_t status = aa.writeToParcel(&data);
- if (status != NO_ERROR) {
- return status;
- }
- status = remote()->transact(GET_STRATEGY_FOR_ATTRIBUTES, data, &reply);
- if (status != NO_ERROR) {
- return status;
- }
- status = static_cast<status_t>(reply.readInt32());
- if (status != NO_ERROR) {
- return status;
- }
- productStrategy = static_cast<product_strategy_t>(reply.readInt32());
- return NO_ERROR;
- }
- virtual status_t listAudioVolumeGroups(AudioVolumeGroupVector &groups)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- status_t status = remote()->transact(LIST_AUDIO_VOLUME_GROUPS, data, &reply);
- if (status != NO_ERROR) {
- return status;
- }
- status = static_cast<status_t>(reply.readInt32());
- if (status != NO_ERROR) {
- return status;
- }
- uint32_t numGroups = static_cast<uint32_t>(reply.readInt32());
- for (size_t i = 0; i < numGroups; i++) {
- AudioVolumeGroup group;
- status = group.readFromParcel(&reply);
- if (status != NO_ERROR) {
- ALOGE("%s: failed to read volume groups", __FUNCTION__);
- groups.clear();
- return status;
- }
- groups.push_back(group);
- }
- return NO_ERROR;
- }
- virtual status_t getVolumeGroupFromAudioAttributes(const AudioAttributes &aa,
- volume_group_t &volumeGroup)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- status_t status = aa.writeToParcel(&data);
- if (status != NO_ERROR) {
- return status;
- }
- status = remote()->transact(GET_VOLUME_GROUP_FOR_ATTRIBUTES, data, &reply);
- if (status != NO_ERROR) {
- return status;
- }
- status = static_cast<status_t>(reply.readInt32());
- if (status != NO_ERROR) {
- return status;
- }
- volumeGroup = static_cast<volume_group_t>(reply.readInt32());
- return NO_ERROR;
- }
- virtual status_t setRttEnabled(bool enabled)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
- data.writeInt32(static_cast<int32_t>(enabled));
- status_t status = remote()->transact(SET_RTT_ENABLED, data, &reply);
- if (status != NO_ERROR) {
- return status;
- }
- return static_cast<status_t>(reply.readInt32());
- }
- };
- IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
- // ----------------------------------------------------------------------
- status_t BnAudioPolicyService::onTransact(
- uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
- {
- // make sure transactions reserved to AudioFlinger do not come from other processes
- switch (code) {
- case START_OUTPUT:
- case STOP_OUTPUT:
- case RELEASE_OUTPUT:
- case GET_INPUT_FOR_ATTR:
- case START_INPUT:
- case STOP_INPUT:
- case RELEASE_INPUT:
- case GET_OUTPUT_FOR_EFFECT:
- case REGISTER_EFFECT:
- case UNREGISTER_EFFECT:
- case SET_EFFECT_ENABLED:
- case GET_OUTPUT_FOR_ATTR:
- case ACQUIRE_SOUNDTRIGGER_SESSION:
- case RELEASE_SOUNDTRIGGER_SESSION:
- case MOVE_EFFECTS_TO_IO:
- ALOGW("%s: transaction %d received from PID %d",
- __func__, code, IPCThreadState::self()->getCallingPid());
- // return status only for non void methods
- switch (code) {
- case RELEASE_OUTPUT:
- case RELEASE_INPUT:
- break;
- default:
- reply->writeInt32(static_cast<int32_t> (INVALID_OPERATION));
- break;
- }
- return OK;
- default:
- break;
- }
- // make sure the following transactions come from system components
- switch (code) {
- case SET_DEVICE_CONNECTION_STATE:
- case HANDLE_DEVICE_CONFIG_CHANGE:
- case SET_PHONE_STATE:
- //FIXME: Allow SET_FORCE_USE calls from system apps until a better use case routing API is available
- // case SET_FORCE_USE:
- case INIT_STREAM_VOLUME:
- case SET_STREAM_VOLUME:
- case REGISTER_POLICY_MIXES:
- case SET_MASTER_MONO:
- case GET_SURROUND_FORMATS:
- case SET_SURROUND_FORMAT_ENABLED:
- case SET_ASSISTANT_UID:
- case SET_A11Y_SERVICES_UIDS:
- case SET_UID_DEVICE_AFFINITY:
- case REMOVE_UID_DEVICE_AFFINITY:
- case GET_OFFLOAD_FORMATS_A2DP:
- case LIST_AUDIO_VOLUME_GROUPS:
- case GET_VOLUME_GROUP_FOR_ATTRIBUTES:
- case SET_RTT_ENABLED: {
- if (!isServiceUid(IPCThreadState::self()->getCallingUid())) {
- ALOGW("%s: transaction %d received from PID %d unauthorized UID %d",
- __func__, code, IPCThreadState::self()->getCallingPid(),
- IPCThreadState::self()->getCallingUid());
- reply->writeInt32(static_cast<int32_t> (INVALID_OPERATION));
- return OK;
- }
- } break;
- default:
- break;
- }
- std::string tag("IAudioPolicyService command " + std::to_string(code));
- TimeCheck check(tag.c_str());
- switch (code) {
- case SET_DEVICE_CONNECTION_STATE: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- audio_devices_t device =
- static_cast <audio_devices_t>(data.readInt32());
- audio_policy_dev_state_t state =
- static_cast <audio_policy_dev_state_t>(data.readInt32());
- const char *device_address = data.readCString();
- const char *device_name = data.readCString();
- audio_format_t codecFormat = static_cast <audio_format_t>(data.readInt32());
- if (device_address == nullptr || device_name == nullptr) {
- ALOGE("Bad Binder transaction: SET_DEVICE_CONNECTION_STATE for device %u", device);
- reply->writeInt32(static_cast<int32_t> (BAD_VALUE));
- } else {
- reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
- state,
- device_address,
- device_name,
- codecFormat)));
- }
- return NO_ERROR;
- } break;
- case GET_DEVICE_CONNECTION_STATE: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- audio_devices_t device =
- static_cast<audio_devices_t> (data.readInt32());
- const char *device_address = data.readCString();
- if (device_address == nullptr) {
- ALOGE("Bad Binder transaction: GET_DEVICE_CONNECTION_STATE for device %u", device);
- reply->writeInt32(static_cast<int32_t> (AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE));
- } else {
- reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
- device_address)));
- }
- return NO_ERROR;
- } break;
- case HANDLE_DEVICE_CONFIG_CHANGE: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- audio_devices_t device =
- static_cast <audio_devices_t>(data.readInt32());
- const char *device_address = data.readCString();
- const char *device_name = data.readCString();
- audio_format_t codecFormat =
- static_cast <audio_format_t>(data.readInt32());
- if (device_address == nullptr || device_name == nullptr) {
- ALOGE("Bad Binder transaction: HANDLE_DEVICE_CONFIG_CHANGE for device %u", device);
- reply->writeInt32(static_cast<int32_t> (BAD_VALUE));
- } else {
- reply->writeInt32(static_cast<uint32_t> (handleDeviceConfigChange(device,
- device_address,
- device_name,
- codecFormat)));
- }
- return NO_ERROR;
- } break;
- case SET_PHONE_STATE: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- reply->writeInt32(static_cast <uint32_t>(setPhoneState(
- (audio_mode_t) data.readInt32())));
- return NO_ERROR;
- } break;
- case SET_FORCE_USE: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
- data.readInt32());
- audio_policy_forced_cfg_t config =
- static_cast <audio_policy_forced_cfg_t>(data.readInt32());
- reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
- return NO_ERROR;
- } break;
- case GET_FORCE_USE: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
- data.readInt32());
- reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
- return NO_ERROR;
- } break;
- case GET_OUTPUT: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- audio_stream_type_t stream =
- static_cast <audio_stream_type_t>(data.readInt32());
- audio_io_handle_t output = getOutput(stream);
- reply->writeInt32(static_cast <int>(output));
- return NO_ERROR;
- } break;
- case GET_OUTPUT_FOR_ATTR: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- audio_attributes_t attr = AUDIO_ATTRIBUTES_INITIALIZER;
- status_t status = data.read(&attr, sizeof(audio_attributes_t));
- if (status != NO_ERROR) {
- return status;
- }
- sanetizeAudioAttributes(&attr);
- audio_session_t session = (audio_session_t)data.readInt32();
- audio_stream_type_t stream = AUDIO_STREAM_DEFAULT;
- bool hasStream = data.readInt32() != 0;
- if (hasStream) {
- stream = (audio_stream_type_t)data.readInt32();
- }
- pid_t pid = (pid_t)data.readInt32();
- uid_t uid = (uid_t)data.readInt32();
- audio_config_t config;
- memset(&config, 0, sizeof(audio_config_t));
- data.read(&config, sizeof(audio_config_t));
- audio_output_flags_t flags =
- static_cast <audio_output_flags_t>(data.readInt32());
- audio_port_handle_t selectedDeviceId = data.readInt32();
- audio_port_handle_t portId = (audio_port_handle_t)data.readInt32();
- audio_io_handle_t output = 0;
- std::vector<audio_io_handle_t> secondaryOutputs;
- status = getOutputForAttr(&attr,
- &output, session, &stream, pid, uid,
- &config,
- flags, &selectedDeviceId, &portId, &secondaryOutputs);
- reply->writeInt32(status);
- status = reply->write(&attr, sizeof(audio_attributes_t));
- if (status != NO_ERROR) {
- return status;
- }
- reply->writeInt32(output);
- reply->writeInt32(stream);
- reply->writeInt32(selectedDeviceId);
- reply->writeInt32(portId);
- reply->writeInt32(secondaryOutputs.size());
- return reply->write(secondaryOutputs.data(),
- secondaryOutputs.size() * sizeof(audio_io_handle_t));
- } break;
- case START_OUTPUT: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
- reply->writeInt32(static_cast <uint32_t>(startOutput(portId)));
- return NO_ERROR;
- } break;
- case STOP_OUTPUT: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
- reply->writeInt32(static_cast <uint32_t>(stopOutput(portId)));
- return NO_ERROR;
- } break;
- case RELEASE_OUTPUT: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
- releaseOutput(portId);
- return NO_ERROR;
- } break;
- case GET_INPUT_FOR_ATTR: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- audio_attributes_t attr = {};
- data.read(&attr, sizeof(audio_attributes_t));
- sanetizeAudioAttributes(&attr);
- audio_io_handle_t input = (audio_io_handle_t)data.readInt32();
- audio_unique_id_t riid = (audio_unique_id_t)data.readInt32();
- audio_session_t session = (audio_session_t)data.readInt32();
- pid_t pid = (pid_t)data.readInt32();
- uid_t uid = (uid_t)data.readInt32();
- const String16 opPackageName = data.readString16();
- audio_config_base_t config;
- memset(&config, 0, sizeof(audio_config_base_t));
- data.read(&config, sizeof(audio_config_base_t));
- audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
- audio_port_handle_t selectedDeviceId = (audio_port_handle_t) data.readInt32();
- audio_port_handle_t portId = (audio_port_handle_t)data.readInt32();
- status_t status = getInputForAttr(&attr, &input, riid, session, pid, uid,
- opPackageName, &config,
- flags, &selectedDeviceId, &portId);
- reply->writeInt32(status);
- if (status == NO_ERROR) {
- reply->writeInt32(input);
- reply->writeInt32(selectedDeviceId);
- reply->writeInt32(portId);
- }
- return NO_ERROR;
- } break;
- case START_INPUT: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
- status_t status = startInput(portId);
- reply->writeInt32(static_cast <uint32_t>(status));
- return NO_ERROR;
- } break;
- case STOP_INPUT: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
- reply->writeInt32(static_cast <uint32_t>(stopInput(portId)));
- return NO_ERROR;
- } break;
- case RELEASE_INPUT: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
- releaseInput(portId);
- return NO_ERROR;
- } break;
- case INIT_STREAM_VOLUME: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- audio_stream_type_t stream =
- static_cast <audio_stream_type_t>(data.readInt32());
- int indexMin = data.readInt32();
- int indexMax = data.readInt32();
- reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
- return NO_ERROR;
- } break;
- case SET_STREAM_VOLUME: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- audio_stream_type_t stream =
- static_cast <audio_stream_type_t>(data.readInt32());
- int index = data.readInt32();
- audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
- reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream,
- index,
- device)));
- return NO_ERROR;
- } break;
- case GET_STREAM_VOLUME: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- audio_stream_type_t stream =
- static_cast <audio_stream_type_t>(data.readInt32());
- audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
- int index = 0;
- status_t status = getStreamVolumeIndex(stream, &index, device);
- reply->writeInt32(index);
- reply->writeInt32(static_cast <uint32_t>(status));
- return NO_ERROR;
- } break;
- case GET_STRATEGY_FOR_STREAM: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- audio_stream_type_t stream =
- static_cast <audio_stream_type_t>(data.readInt32());
- reply->writeUint32(getStrategyForStream(stream));
- return NO_ERROR;
- } break;
- case SET_VOLUME_ATTRIBUTES: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- audio_attributes_t attributes = {};
- status_t status = data.read(&attributes, sizeof(audio_attributes_t));
- if (status != NO_ERROR) {
- return status;
- }
- int index = data.readInt32();
- audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
- reply->writeInt32(static_cast <uint32_t>(setVolumeIndexForAttributes(attributes,
- index, device)));
- return NO_ERROR;
- } break;
- case GET_VOLUME_ATTRIBUTES: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- audio_attributes_t attributes = {};
- status_t status = data.read(&attributes, sizeof(audio_attributes_t));
- if (status != NO_ERROR) {
- return status;
- }
- audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
- int index = 0;
- status = getVolumeIndexForAttributes(attributes, index, device);
- reply->writeInt32(static_cast <uint32_t>(status));
- if (status == NO_ERROR) {
- reply->writeInt32(index);
- }
- return NO_ERROR;
- } break;
- case GET_MIN_VOLUME_FOR_ATTRIBUTES: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- audio_attributes_t attributes = {};
- status_t status = data.read(&attributes, sizeof(audio_attributes_t));
- if (status != NO_ERROR) {
- return status;
- }
- int index = 0;
- status = getMinVolumeIndexForAttributes(attributes, index);
- reply->writeInt32(static_cast <uint32_t>(status));
- if (status == NO_ERROR) {
- reply->writeInt32(index);
- }
- return NO_ERROR;
- } break;
- case GET_MAX_VOLUME_FOR_ATTRIBUTES: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- audio_attributes_t attributes = {};
- status_t status = data.read(&attributes, sizeof(audio_attributes_t));
- if (status != NO_ERROR) {
- return status;
- }
- int index = 0;
- status = getMaxVolumeIndexForAttributes(attributes, index);
- reply->writeInt32(static_cast <uint32_t>(status));
- if (status == NO_ERROR) {
- reply->writeInt32(index);
- }
- return NO_ERROR;
- } break;
- case GET_DEVICES_FOR_STREAM: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- audio_stream_type_t stream =
- static_cast <audio_stream_type_t>(data.readInt32());
- reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
- return NO_ERROR;
- } break;
- case GET_OUTPUT_FOR_EFFECT: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- effect_descriptor_t desc = {};
- if (data.read(&desc, sizeof(desc)) != NO_ERROR) {
- android_errorWriteLog(0x534e4554, "73126106");
- }
- (void)sanitizeEffectDescriptor(&desc);
- audio_io_handle_t output = getOutputForEffect(&desc);
- reply->writeInt32(static_cast <int>(output));
- return NO_ERROR;
- } break;
- case REGISTER_EFFECT: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- effect_descriptor_t desc = {};
- if (data.read(&desc, sizeof(desc)) != NO_ERROR) {
- android_errorWriteLog(0x534e4554, "73126106");
- }
- (void)sanitizeEffectDescriptor(&desc);
- audio_io_handle_t io = data.readInt32();
- uint32_t strategy = data.readInt32();
- audio_session_t session = (audio_session_t) data.readInt32();
- int id = data.readInt32();
- reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
- io,
- strategy,
- session,
- id)));
- return NO_ERROR;
- } break;
- case UNREGISTER_EFFECT: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- int id = data.readInt32();
- reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
- return NO_ERROR;
- } break;
- case SET_EFFECT_ENABLED: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- int id = data.readInt32();
- bool enabled = static_cast <bool>(data.readInt32());
- reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
- return NO_ERROR;
- } break;
- case MOVE_EFFECTS_TO_IO: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- std::vector<int> ids;
- int32_t size;
- status_t status = data.readInt32(&size);
- if (status != NO_ERROR) {
- return status;
- }
- if (size > MAX_ITEMS_PER_LIST) {
- return BAD_VALUE;
- }
- for (int32_t i = 0; i < size; i++) {
- int id;
- status = data.readInt32(&id);
- if (status != NO_ERROR) {
- return status;
- }
- ids.push_back(id);
- }
- audio_io_handle_t io = data.readInt32();
- reply->writeInt32(static_cast <int32_t>(moveEffectsToIo(ids, io)));
- return NO_ERROR;
- } break;
- case IS_STREAM_ACTIVE: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
- uint32_t inPastMs = (uint32_t)data.readInt32();
- reply->writeInt32( isStreamActive(stream, inPastMs) );
- return NO_ERROR;
- } break;
- case IS_STREAM_ACTIVE_REMOTELY: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
- uint32_t inPastMs = (uint32_t)data.readInt32();
- reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) );
- return NO_ERROR;
- } break;
- case IS_SOURCE_ACTIVE: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- audio_source_t source = (audio_source_t) data.readInt32();
- reply->writeInt32( isSourceActive(source));
- return NO_ERROR;
- }
- case QUERY_DEFAULT_PRE_PROCESSING: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- audio_session_t audioSession = (audio_session_t) data.readInt32();
- uint32_t count = data.readInt32();
- if (count > AudioEffect::kMaxPreProcessing) {
- count = AudioEffect::kMaxPreProcessing;
- }
- uint32_t retCount = count;
- effect_descriptor_t *descriptors = new effect_descriptor_t[count]{};
- status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
- reply->writeInt32(status);
- if (status != NO_ERROR && status != NO_MEMORY) {
- retCount = 0;
- }
- reply->writeInt32(retCount);
- if (retCount != 0) {
- if (retCount < count) {
- count = retCount;
- }
- reply->write(descriptors, sizeof(effect_descriptor_t) * count);
- }
- delete[] descriptors;
- return status;
- }
- case IS_OFFLOAD_SUPPORTED: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- audio_offload_info_t info = {};
- data.read(&info, sizeof(audio_offload_info_t));
- bool isSupported = isOffloadSupported(info);
- reply->writeInt32(isSupported);
- return NO_ERROR;
- }
- case IS_DIRECT_OUTPUT_SUPPORTED: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- audio_config_base_t config = {};
- audio_attributes_t attributes = {};
- status_t status = data.read(&config, sizeof(audio_config_base_t));
- if (status != NO_ERROR) return status;
- status = data.read(&attributes, sizeof(audio_attributes_t));
- if (status != NO_ERROR) return status;
- reply->writeInt32(isDirectOutputSupported(config, attributes));
- return NO_ERROR;
- }
- case LIST_AUDIO_PORTS: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- audio_port_role_t role = (audio_port_role_t)data.readInt32();
- audio_port_type_t type = (audio_port_type_t)data.readInt32();
- unsigned int numPortsReq = data.readInt32();
- if (numPortsReq > MAX_ITEMS_PER_LIST) {
- numPortsReq = MAX_ITEMS_PER_LIST;
- }
- unsigned int numPorts = numPortsReq;
- struct audio_port *ports =
- (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port));
- if (ports == NULL) {
- reply->writeInt32(NO_MEMORY);
- reply->writeInt32(0);
- return NO_ERROR;
- }
- unsigned int generation;
- status_t status = listAudioPorts(role, type, &numPorts, ports, &generation);
- reply->writeInt32(status);
- reply->writeInt32(numPorts);
- if (status == NO_ERROR) {
- if (numPortsReq > numPorts) {
- numPortsReq = numPorts;
- }
- reply->write(ports, numPortsReq * sizeof(struct audio_port));
- reply->writeInt32(generation);
- }
- free(ports);
- return NO_ERROR;
- }
- case GET_AUDIO_PORT: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- struct audio_port port = {};
- if (data.read(&port, sizeof(struct audio_port)) != NO_ERROR) {
- ALOGE("b/23912202");
- }
- status_t status = getAudioPort(&port);
- reply->writeInt32(status);
- if (status == NO_ERROR) {
- reply->write(&port, sizeof(struct audio_port));
- }
- return NO_ERROR;
- }
- case CREATE_AUDIO_PATCH: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- struct audio_patch patch = {};
- data.read(&patch, sizeof(struct audio_patch));
- audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
- if (data.read(&handle, sizeof(audio_patch_handle_t)) != NO_ERROR) {
- ALOGE("b/23912202");
- }
- status_t status = createAudioPatch(&patch, &handle);
- reply->writeInt32(status);
- if (status == NO_ERROR) {
- reply->write(&handle, sizeof(audio_patch_handle_t));
- }
- return NO_ERROR;
- }
- case RELEASE_AUDIO_PATCH: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
- data.read(&handle, sizeof(audio_patch_handle_t));
- status_t status = releaseAudioPatch(handle);
- reply->writeInt32(status);
- return NO_ERROR;
- }
- case LIST_AUDIO_PATCHES: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- unsigned int numPatchesReq = data.readInt32();
- if (numPatchesReq > MAX_ITEMS_PER_LIST) {
- numPatchesReq = MAX_ITEMS_PER_LIST;
- }
- unsigned int numPatches = numPatchesReq;
- struct audio_patch *patches =
- (struct audio_patch *)calloc(numPatchesReq,
- sizeof(struct audio_patch));
- if (patches == NULL) {
- reply->writeInt32(NO_MEMORY);
- reply->writeInt32(0);
- return NO_ERROR;
- }
- unsigned int generation;
- status_t status = listAudioPatches(&numPatches, patches, &generation);
- reply->writeInt32(status);
- reply->writeInt32(numPatches);
- if (status == NO_ERROR) {
- if (numPatchesReq > numPatches) {
- numPatchesReq = numPatches;
- }
- reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
- reply->writeInt32(generation);
- }
- free(patches);
- return NO_ERROR;
- }
- case SET_AUDIO_PORT_CONFIG: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- struct audio_port_config config = {};
- data.read(&config, sizeof(struct audio_port_config));
- (void)sanitizeAudioPortConfig(&config);
- status_t status = setAudioPortConfig(&config);
- reply->writeInt32(status);
- return NO_ERROR;
- }
- case REGISTER_CLIENT: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
- data.readStrongBinder());
- registerClient(client);
- return NO_ERROR;
- } break;
- case SET_AUDIO_PORT_CALLBACK_ENABLED: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- setAudioPortCallbacksEnabled(data.readInt32() == 1);
- return NO_ERROR;
- } break;
- case SET_AUDIO_VOLUME_GROUP_CALLBACK_ENABLED: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- setAudioVolumeGroupCallbacksEnabled(data.readInt32() == 1);
- return NO_ERROR;
- } break;
- case ACQUIRE_SOUNDTRIGGER_SESSION: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
- data.readStrongBinder());
- audio_session_t session = AUDIO_SESSION_NONE;
- audio_io_handle_t ioHandle = AUDIO_IO_HANDLE_NONE;
- audio_devices_t device = AUDIO_DEVICE_NONE;
- status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device);
- reply->writeInt32(status);
- if (status == NO_ERROR) {
- reply->writeInt32(session);
- reply->writeInt32(ioHandle);
- reply->writeInt32(device);
- }
- return NO_ERROR;
- } break;
- case RELEASE_SOUNDTRIGGER_SESSION: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
- data.readStrongBinder());
- audio_session_t session = (audio_session_t)data.readInt32();
- status_t status = releaseSoundTriggerSession(session);
- reply->writeInt32(status);
- return NO_ERROR;
- } break;
- case GET_PHONE_STATE: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- reply->writeInt32((int32_t)getPhoneState());
- return NO_ERROR;
- } break;
- case REGISTER_POLICY_MIXES: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- bool registration = data.readInt32() == 1;
- Vector<AudioMix> mixes;
- size_t size = (size_t)data.readInt32();
- if (size > MAX_MIXES_PER_POLICY) {
- size = MAX_MIXES_PER_POLICY;
- }
- for (size_t i = 0; i < size; i++) {
- AudioMix mix;
- if (mix.readFromParcel((Parcel*)&data) == NO_ERROR) {
- mixes.add(mix);
- }
- }
- status_t status = registerPolicyMixes(mixes, registration);
- reply->writeInt32(status);
- return NO_ERROR;
- } break;
- case START_AUDIO_SOURCE: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- struct audio_port_config source = {};
- data.read(&source, sizeof(struct audio_port_config));
- (void)sanitizeAudioPortConfig(&source);
- audio_attributes_t attributes = {};
- data.read(&attributes, sizeof(audio_attributes_t));
- sanetizeAudioAttributes(&attributes);
- audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE;
- status_t status = startAudioSource(&source, &attributes, &portId);
- reply->writeInt32(status);
- reply->writeInt32(portId);
- return NO_ERROR;
- } break;
- case STOP_AUDIO_SOURCE: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- audio_port_handle_t portId = (audio_port_handle_t) data.readInt32();
- status_t status = stopAudioSource(portId);
- reply->writeInt32(status);
- return NO_ERROR;
- } break;
- case SET_MASTER_MONO: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- bool mono = static_cast<bool>(data.readInt32());
- status_t status = setMasterMono(mono);
- reply->writeInt32(status);
- return NO_ERROR;
- } break;
- case GET_MASTER_MONO: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- bool mono;
- status_t status = getMasterMono(&mono);
- reply->writeInt32(status);
- if (status == NO_ERROR) {
- reply->writeInt32(static_cast<int32_t>(mono));
- }
- return NO_ERROR;
- } break;
- case GET_STREAM_VOLUME_DB: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- audio_stream_type_t stream =
- static_cast <audio_stream_type_t>(data.readInt32());
- int index = static_cast <int>(data.readInt32());
- audio_devices_t device =
- static_cast <audio_devices_t>(data.readUint32());
- reply->writeFloat(getStreamVolumeDB(stream, index, device));
- return NO_ERROR;
- }
- case GET_SURROUND_FORMATS: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- unsigned int numSurroundFormatsReq = data.readUint32();
- if (numSurroundFormatsReq > MAX_ITEMS_PER_LIST) {
- numSurroundFormatsReq = MAX_ITEMS_PER_LIST;
- }
- bool reported = data.readBool();
- unsigned int numSurroundFormats = numSurroundFormatsReq;
- audio_format_t *surroundFormats = (audio_format_t *)calloc(
- numSurroundFormats, sizeof(audio_format_t));
- bool *surroundFormatsEnabled = (bool *)calloc(numSurroundFormats, sizeof(bool));
- if (numSurroundFormatsReq > 0 &&
- (surroundFormats == NULL || surroundFormatsEnabled == NULL)) {
- free(surroundFormats);
- free(surroundFormatsEnabled);
- reply->writeInt32(NO_MEMORY);
- return NO_ERROR;
- }
- status_t status = getSurroundFormats(
- &numSurroundFormats, surroundFormats, surroundFormatsEnabled, reported);
- reply->writeInt32(status);
- if (status == NO_ERROR) {
- reply->writeUint32(numSurroundFormats);
- if (numSurroundFormatsReq > numSurroundFormats) {
- numSurroundFormatsReq = numSurroundFormats;
- }
- reply->write(surroundFormats, numSurroundFormatsReq * sizeof(audio_format_t));
- reply->write(surroundFormatsEnabled, numSurroundFormatsReq * sizeof(bool));
- }
- free(surroundFormats);
- free(surroundFormatsEnabled);
- return NO_ERROR;
- }
- case SET_SURROUND_FORMAT_ENABLED: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- audio_format_t audioFormat = (audio_format_t) data.readInt32();
- bool enabled = data.readBool();
- status_t status = setSurroundFormatEnabled(audioFormat, enabled);
- reply->writeInt32(status);
- return NO_ERROR;
- }
- case GET_OFFLOAD_FORMATS_A2DP: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- std::vector<audio_format_t> encodingFormats;
- status_t status = getHwOffloadEncodingFormatsSupportedForA2DP(&encodingFormats);
- reply->writeInt32(status);
- if (status != NO_ERROR) {
- return NO_ERROR;
- }
- reply->writeUint32(static_cast<uint32_t>(encodingFormats.size()));
- for (size_t i = 0; i < encodingFormats.size(); i++)
- reply->writeInt32(static_cast<int32_t>(encodingFormats[i]));
- return NO_ERROR;
- }
- case ADD_STREAM_DEFAULT_EFFECT: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- effect_uuid_t type;
- status_t status = data.read(&type, sizeof(effect_uuid_t));
- if (status != NO_ERROR) {
- return status;
- }
- String16 opPackageName;
- status = data.readString16(&opPackageName);
- if (status != NO_ERROR) {
- return status;
- }
- effect_uuid_t uuid;
- status = data.read(&uuid, sizeof(effect_uuid_t));
- if (status != NO_ERROR) {
- return status;
- }
- int32_t priority = data.readInt32();
- audio_usage_t usage = (audio_usage_t) data.readInt32();
- audio_unique_id_t id = 0;
- reply->writeInt32(static_cast <int32_t>(addStreamDefaultEffect(&type,
- opPackageName,
- &uuid,
- priority,
- usage,
- &id)));
- reply->writeInt32(id);
- return NO_ERROR;
- }
- case REMOVE_STREAM_DEFAULT_EFFECT: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- audio_unique_id_t id = static_cast<audio_unique_id_t>(data.readInt32());
- reply->writeInt32(static_cast <int32_t>(removeStreamDefaultEffect(id)));
- return NO_ERROR;
- }
- case ADD_SOURCE_DEFAULT_EFFECT: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- effect_uuid_t type;
- status_t status = data.read(&type, sizeof(effect_uuid_t));
- if (status != NO_ERROR) {
- return status;
- }
- String16 opPackageName;
- status = data.readString16(&opPackageName);
- if (status != NO_ERROR) {
- return status;
- }
- effect_uuid_t uuid;
- status = data.read(&uuid, sizeof(effect_uuid_t));
- if (status != NO_ERROR) {
- return status;
- }
- int32_t priority = data.readInt32();
- audio_source_t source = (audio_source_t) data.readInt32();
- audio_unique_id_t id = 0;
- reply->writeInt32(static_cast <int32_t>(addSourceDefaultEffect(&type,
- opPackageName,
- &uuid,
- priority,
- source,
- &id)));
- reply->writeInt32(id);
- return NO_ERROR;
- }
- case REMOVE_SOURCE_DEFAULT_EFFECT: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- audio_unique_id_t id = static_cast<audio_unique_id_t>(data.readInt32());
- reply->writeInt32(static_cast <int32_t>(removeSourceDefaultEffect(id)));
- return NO_ERROR;
- }
- case SET_ASSISTANT_UID: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- int32_t uid;
- status_t status = data.readInt32(&uid);
- if (status != NO_ERROR) {
- return status;
- }
- status = setAssistantUid(uid);
- reply->writeInt32(static_cast <int32_t>(status));
- return NO_ERROR;
- }
- case SET_A11Y_SERVICES_UIDS: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- std::vector<uid_t> uids;
- int32_t size;
- status_t status = data.readInt32(&size);
- if (status != NO_ERROR) {
- return status;
- }
- if (size > MAX_ITEMS_PER_LIST) {
- size = MAX_ITEMS_PER_LIST;
- }
- for (int32_t i = 0; i < size; i++) {
- int32_t uid;
- status = data.readInt32(&uid);
- if (status != NO_ERROR) {
- return status;
- }
- uids.push_back(uid);
- }
- status = setA11yServicesUids(uids);
- reply->writeInt32(static_cast <int32_t>(status));
- return NO_ERROR;
- }
- case IS_HAPTIC_PLAYBACK_SUPPORTED: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- bool isSupported = isHapticPlaybackSupported();
- reply->writeBool(isSupported);
- return NO_ERROR;
- }
- case SET_UID_DEVICE_AFFINITY: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- const uid_t uid = (uid_t) data.readInt32();
- Vector<AudioDeviceTypeAddr> devices;
- size_t size = (size_t)data.readInt32();
- for (size_t i = 0; i < size; i++) {
- AudioDeviceTypeAddr device;
- if (device.readFromParcel((Parcel*)&data) == NO_ERROR) {
- devices.add(device);
- }
- }
- status_t status = setUidDeviceAffinities(uid, devices);
- reply->writeInt32(status);
- return NO_ERROR;
- }
- case REMOVE_UID_DEVICE_AFFINITY: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- const uid_t uid = (uid_t) data.readInt32();
- status_t status = removeUidDeviceAffinities(uid);
- reply->writeInt32(status);
- return NO_ERROR;
- }
- case LIST_AUDIO_PRODUCT_STRATEGIES: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- AudioProductStrategyVector strategies;
- status_t status = listAudioProductStrategies(strategies);
- reply->writeInt32(status);
- if (status != NO_ERROR) {
- return NO_ERROR;
- }
- size_t size = strategies.size();
- size_t sizePosition = reply->dataPosition();
- reply->writeInt32(size);
- size_t finalSize = size;
- for (size_t i = 0; i < size; i++) {
- size_t position = reply->dataPosition();
- if (strategies[i].writeToParcel(reply) != NO_ERROR) {
- reply->setDataPosition(position);
- finalSize--;
- }
- }
- if (size != finalSize) {
- size_t position = reply->dataPosition();
- reply->setDataPosition(sizePosition);
- reply->writeInt32(finalSize);
- reply->setDataPosition(position);
- }
- return NO_ERROR;
- }
- case GET_STRATEGY_FOR_ATTRIBUTES: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- AudioAttributes attributes;
- status_t status = attributes.readFromParcel(&data);
- if (status != NO_ERROR) {
- return status;
- }
- product_strategy_t strategy;
- status = getProductStrategyFromAudioAttributes(attributes, strategy);
- reply->writeInt32(status);
- if (status != NO_ERROR) {
- return NO_ERROR;
- }
- reply->writeUint32(static_cast<int>(strategy));
- return NO_ERROR;
- }
- case LIST_AUDIO_VOLUME_GROUPS: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- AudioVolumeGroupVector groups;
- status_t status = listAudioVolumeGroups(groups);
- reply->writeInt32(status);
- if (status != NO_ERROR) {
- return NO_ERROR;
- }
- size_t size = groups.size();
- size_t sizePosition = reply->dataPosition();
- reply->writeInt32(size);
- size_t finalSize = size;
- for (size_t i = 0; i < size; i++) {
- size_t position = reply->dataPosition();
- if (groups[i].writeToParcel(reply) != NO_ERROR) {
- reply->setDataPosition(position);
- finalSize--;
- }
- }
- if (size != finalSize) {
- size_t position = reply->dataPosition();
- reply->setDataPosition(sizePosition);
- reply->writeInt32(finalSize);
- reply->setDataPosition(position);
- }
- return NO_ERROR;
- }
- case GET_VOLUME_GROUP_FOR_ATTRIBUTES: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- AudioAttributes attributes;
- status_t status = attributes.readFromParcel(&data);
- if (status != NO_ERROR) {
- return status;
- }
- volume_group_t group;
- status = getVolumeGroupFromAudioAttributes(attributes, group);
- reply->writeInt32(status);
- if (status != NO_ERROR) {
- return NO_ERROR;
- }
- reply->writeUint32(static_cast<int>(group));
- return NO_ERROR;
- }
- case SET_ALLOWED_CAPTURE_POLICY: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- uid_t uid = data.readInt32();
- audio_flags_mask_t flags = data.readInt32();
- status_t status = setAllowedCapturePolicy(uid, flags);
- reply->writeInt32(status);
- return NO_ERROR;
- }
- case SET_RTT_ENABLED: {
- CHECK_INTERFACE(IAudioPolicyService, data, reply);
- bool enabled = static_cast<bool>(data.readInt32());
- status_t status = setRttEnabled(enabled);
- reply->writeInt32(status);
- return NO_ERROR;
- }
- default:
- return BBinder::onTransact(code, data, reply, flags);
- }
- }
- /** returns true if string overflow was prevented by zero termination */
- template <size_t size>
- static bool preventStringOverflow(char (&s)[size]) {
- if (strnlen(s, size) < size) return false;
- s[size - 1] = '\0';
- return true;
- }
- void BnAudioPolicyService::sanetizeAudioAttributes(audio_attributes_t* attr)
- {
- const size_t tagsMaxSize = AUDIO_ATTRIBUTES_TAGS_MAX_SIZE;
- if (strnlen(attr->tags, tagsMaxSize) >= tagsMaxSize) {
- android_errorWriteLog(0x534e4554, "68953950"); // SafetyNet logging
- }
- attr->tags[tagsMaxSize - 1] = '\0';
- }
- /** returns BAD_VALUE if sanitization was required. */
- status_t BnAudioPolicyService::sanitizeEffectDescriptor(effect_descriptor_t* desc)
- {
- if (preventStringOverflow(desc->name)
- | /* always */ preventStringOverflow(desc->implementor)) {
- android_errorWriteLog(0x534e4554, "73126106"); // SafetyNet logging
- return BAD_VALUE;
- }
- return NO_ERROR;
- }
- /** returns BAD_VALUE if sanitization was required. */
- status_t BnAudioPolicyService::sanitizeAudioPortConfig(struct audio_port_config* config)
- {
- if (config->type == AUDIO_PORT_TYPE_DEVICE &&
- preventStringOverflow(config->ext.device.address)) {
- return BAD_VALUE;
- }
- return NO_ERROR;
- }
- // ----------------------------------------------------------------------------
- } // namespace android
|