IAudioPolicyService.cpp 95 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417
  1. /*
  2. **
  3. ** Copyright 2009, The Android Open Source Project
  4. **
  5. ** Licensed under the Apache License, Version 2.0 (the "License");
  6. ** you may not use this file except in compliance with the License.
  7. ** You may obtain a copy of the License at
  8. **
  9. ** http://www.apache.org/licenses/LICENSE-2.0
  10. **
  11. ** Unless required by applicable law or agreed to in writing, software
  12. ** distributed under the License is distributed on an "AS IS" BASIS,
  13. ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. ** See the License for the specific language governing permissions and
  15. ** limitations under the License.
  16. */
  17. #define LOG_TAG "IAudioPolicyService"
  18. #include <utils/Log.h>
  19. #include <stdint.h>
  20. #include <math.h>
  21. #include <sys/types.h>
  22. #include <binder/IPCThreadState.h>
  23. #include <binder/Parcel.h>
  24. #include <media/AudioEffect.h>
  25. #include <media/IAudioPolicyService.h>
  26. #include <media/TimeCheck.h>
  27. #include <mediautils/ServiceUtilities.h>
  28. #include <system/audio.h>
  29. namespace android {
  30. enum {
  31. SET_DEVICE_CONNECTION_STATE = IBinder::FIRST_CALL_TRANSACTION,
  32. GET_DEVICE_CONNECTION_STATE,
  33. HANDLE_DEVICE_CONFIG_CHANGE,
  34. SET_PHONE_STATE,
  35. SET_RINGER_MODE, // reserved, no longer used
  36. SET_FORCE_USE,
  37. GET_FORCE_USE,
  38. GET_OUTPUT,
  39. START_OUTPUT,
  40. STOP_OUTPUT,
  41. RELEASE_OUTPUT,
  42. GET_INPUT_FOR_ATTR,
  43. START_INPUT,
  44. STOP_INPUT,
  45. RELEASE_INPUT,
  46. INIT_STREAM_VOLUME,
  47. SET_STREAM_VOLUME,
  48. GET_STREAM_VOLUME,
  49. SET_VOLUME_ATTRIBUTES,
  50. GET_VOLUME_ATTRIBUTES,
  51. GET_MIN_VOLUME_FOR_ATTRIBUTES,
  52. GET_MAX_VOLUME_FOR_ATTRIBUTES,
  53. GET_STRATEGY_FOR_STREAM,
  54. GET_OUTPUT_FOR_EFFECT,
  55. REGISTER_EFFECT,
  56. UNREGISTER_EFFECT,
  57. IS_STREAM_ACTIVE,
  58. IS_SOURCE_ACTIVE,
  59. GET_DEVICES_FOR_STREAM,
  60. QUERY_DEFAULT_PRE_PROCESSING,
  61. SET_EFFECT_ENABLED,
  62. IS_STREAM_ACTIVE_REMOTELY,
  63. IS_OFFLOAD_SUPPORTED,
  64. IS_DIRECT_OUTPUT_SUPPORTED,
  65. LIST_AUDIO_PORTS,
  66. GET_AUDIO_PORT,
  67. CREATE_AUDIO_PATCH,
  68. RELEASE_AUDIO_PATCH,
  69. LIST_AUDIO_PATCHES,
  70. SET_AUDIO_PORT_CONFIG,
  71. REGISTER_CLIENT,
  72. GET_OUTPUT_FOR_ATTR,
  73. ACQUIRE_SOUNDTRIGGER_SESSION,
  74. RELEASE_SOUNDTRIGGER_SESSION,
  75. GET_PHONE_STATE,
  76. REGISTER_POLICY_MIXES,
  77. START_AUDIO_SOURCE,
  78. STOP_AUDIO_SOURCE,
  79. SET_AUDIO_PORT_CALLBACK_ENABLED,
  80. SET_AUDIO_VOLUME_GROUP_CALLBACK_ENABLED,
  81. SET_MASTER_MONO,
  82. GET_MASTER_MONO,
  83. GET_STREAM_VOLUME_DB,
  84. GET_SURROUND_FORMATS,
  85. SET_SURROUND_FORMAT_ENABLED,
  86. ADD_STREAM_DEFAULT_EFFECT,
  87. REMOVE_STREAM_DEFAULT_EFFECT,
  88. ADD_SOURCE_DEFAULT_EFFECT,
  89. REMOVE_SOURCE_DEFAULT_EFFECT,
  90. SET_ASSISTANT_UID,
  91. SET_A11Y_SERVICES_UIDS,
  92. IS_HAPTIC_PLAYBACK_SUPPORTED,
  93. SET_UID_DEVICE_AFFINITY,
  94. REMOVE_UID_DEVICE_AFFINITY,
  95. GET_OFFLOAD_FORMATS_A2DP,
  96. LIST_AUDIO_PRODUCT_STRATEGIES,
  97. GET_STRATEGY_FOR_ATTRIBUTES,
  98. LIST_AUDIO_VOLUME_GROUPS,
  99. GET_VOLUME_GROUP_FOR_ATTRIBUTES,
  100. SET_ALLOWED_CAPTURE_POLICY,
  101. MOVE_EFFECTS_TO_IO,
  102. SET_RTT_ENABLED
  103. };
  104. #define MAX_ITEMS_PER_LIST 1024
  105. class BpAudioPolicyService : public BpInterface<IAudioPolicyService>
  106. {
  107. public:
  108. explicit BpAudioPolicyService(const sp<IBinder>& impl)
  109. : BpInterface<IAudioPolicyService>(impl)
  110. {
  111. }
  112. virtual status_t setDeviceConnectionState(
  113. audio_devices_t device,
  114. audio_policy_dev_state_t state,
  115. const char *device_address,
  116. const char *device_name,
  117. audio_format_t encodedFormat)
  118. {
  119. Parcel data, reply;
  120. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  121. data.writeInt32(static_cast <uint32_t>(device));
  122. data.writeInt32(static_cast <uint32_t>(state));
  123. data.writeCString(device_address);
  124. data.writeCString(device_name);
  125. data.writeInt32(static_cast <uint32_t>(encodedFormat));
  126. remote()->transact(SET_DEVICE_CONNECTION_STATE, data, &reply);
  127. return static_cast <status_t> (reply.readInt32());
  128. }
  129. virtual audio_policy_dev_state_t getDeviceConnectionState(
  130. audio_devices_t device,
  131. const char *device_address)
  132. {
  133. Parcel data, reply;
  134. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  135. data.writeInt32(static_cast <uint32_t>(device));
  136. data.writeCString(device_address);
  137. remote()->transact(GET_DEVICE_CONNECTION_STATE, data, &reply);
  138. return static_cast <audio_policy_dev_state_t>(reply.readInt32());
  139. }
  140. virtual status_t handleDeviceConfigChange(audio_devices_t device,
  141. const char *device_address,
  142. const char *device_name,
  143. audio_format_t encodedFormat)
  144. {
  145. Parcel data, reply;
  146. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  147. data.writeInt32(static_cast <uint32_t>(device));
  148. data.writeCString(device_address);
  149. data.writeCString(device_name);
  150. data.writeInt32(static_cast <uint32_t>(encodedFormat));
  151. remote()->transact(HANDLE_DEVICE_CONFIG_CHANGE, data, &reply);
  152. return static_cast <status_t> (reply.readInt32());
  153. }
  154. virtual status_t setPhoneState(audio_mode_t state)
  155. {
  156. Parcel data, reply;
  157. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  158. data.writeInt32(state);
  159. remote()->transact(SET_PHONE_STATE, data, &reply);
  160. return static_cast <status_t> (reply.readInt32());
  161. }
  162. virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
  163. {
  164. Parcel data, reply;
  165. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  166. data.writeInt32(static_cast <uint32_t>(usage));
  167. data.writeInt32(static_cast <uint32_t>(config));
  168. remote()->transact(SET_FORCE_USE, data, &reply);
  169. return static_cast <status_t> (reply.readInt32());
  170. }
  171. virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage)
  172. {
  173. Parcel data, reply;
  174. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  175. data.writeInt32(static_cast <uint32_t>(usage));
  176. remote()->transact(GET_FORCE_USE, data, &reply);
  177. return static_cast <audio_policy_forced_cfg_t> (reply.readInt32());
  178. }
  179. virtual audio_io_handle_t getOutput(audio_stream_type_t stream)
  180. {
  181. Parcel data, reply;
  182. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  183. data.writeInt32(static_cast <uint32_t>(stream));
  184. remote()->transact(GET_OUTPUT, data, &reply);
  185. return static_cast <audio_io_handle_t> (reply.readInt32());
  186. }
  187. status_t getOutputForAttr(audio_attributes_t *attr,
  188. audio_io_handle_t *output,
  189. audio_session_t session,
  190. audio_stream_type_t *stream,
  191. pid_t pid,
  192. uid_t uid,
  193. const audio_config_t *config,
  194. audio_output_flags_t flags,
  195. audio_port_handle_t *selectedDeviceId,
  196. audio_port_handle_t *portId,
  197. std::vector<audio_io_handle_t> *secondaryOutputs) override
  198. {
  199. Parcel data, reply;
  200. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  201. if (attr == nullptr) {
  202. ALOGE("%s NULL audio attributes", __func__);
  203. return BAD_VALUE;
  204. }
  205. if (output == nullptr) {
  206. ALOGE("%s NULL output - shouldn't happen", __func__);
  207. return BAD_VALUE;
  208. }
  209. if (selectedDeviceId == nullptr) {
  210. ALOGE("%s NULL selectedDeviceId - shouldn't happen", __func__);
  211. return BAD_VALUE;
  212. }
  213. if (portId == nullptr) {
  214. ALOGE("%s NULL portId - shouldn't happen", __func__);
  215. return BAD_VALUE;
  216. }
  217. if (secondaryOutputs == nullptr) {
  218. ALOGE("%s NULL secondaryOutputs - shouldn't happen", __func__);
  219. return BAD_VALUE;
  220. }
  221. data.write(attr, sizeof(audio_attributes_t));
  222. data.writeInt32(session);
  223. if (stream == NULL) {
  224. data.writeInt32(0);
  225. } else {
  226. data.writeInt32(1);
  227. data.writeInt32(*stream);
  228. }
  229. data.writeInt32(pid);
  230. data.writeInt32(uid);
  231. data.write(config, sizeof(audio_config_t));
  232. data.writeInt32(static_cast <uint32_t>(flags));
  233. data.writeInt32(*selectedDeviceId);
  234. data.writeInt32(*portId);
  235. status_t status = remote()->transact(GET_OUTPUT_FOR_ATTR, data, &reply);
  236. if (status != NO_ERROR) {
  237. return status;
  238. }
  239. status = (status_t)reply.readInt32();
  240. if (status != NO_ERROR) {
  241. return status;
  242. }
  243. status = (status_t)reply.read(&attr, sizeof(audio_attributes_t));
  244. if (status != NO_ERROR) {
  245. return status;
  246. }
  247. *output = (audio_io_handle_t)reply.readInt32();
  248. audio_stream_type_t lStream = (audio_stream_type_t)reply.readInt32();
  249. if (stream != NULL) {
  250. *stream = lStream;
  251. }
  252. *selectedDeviceId = (audio_port_handle_t)reply.readInt32();
  253. *portId = (audio_port_handle_t)reply.readInt32();
  254. secondaryOutputs->resize(reply.readInt32());
  255. return reply.read(secondaryOutputs->data(),
  256. secondaryOutputs->size() * sizeof(audio_io_handle_t));
  257. }
  258. virtual status_t startOutput(audio_port_handle_t portId)
  259. {
  260. Parcel data, reply;
  261. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  262. data.writeInt32((int32_t)portId);
  263. remote()->transact(START_OUTPUT, data, &reply);
  264. return static_cast <status_t> (reply.readInt32());
  265. }
  266. virtual status_t stopOutput(audio_port_handle_t portId)
  267. {
  268. Parcel data, reply;
  269. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  270. data.writeInt32((int32_t)portId);
  271. remote()->transact(STOP_OUTPUT, data, &reply);
  272. return static_cast <status_t> (reply.readInt32());
  273. }
  274. virtual void releaseOutput(audio_port_handle_t portId)
  275. {
  276. Parcel data, reply;
  277. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  278. data.writeInt32((int32_t)portId);
  279. remote()->transact(RELEASE_OUTPUT, data, &reply);
  280. }
  281. virtual status_t getInputForAttr(const audio_attributes_t *attr,
  282. audio_io_handle_t *input,
  283. audio_unique_id_t riid,
  284. audio_session_t session,
  285. pid_t pid,
  286. uid_t uid,
  287. const String16& opPackageName,
  288. const audio_config_base_t *config,
  289. audio_input_flags_t flags,
  290. audio_port_handle_t *selectedDeviceId,
  291. audio_port_handle_t *portId)
  292. {
  293. Parcel data, reply;
  294. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  295. if (attr == NULL) {
  296. ALOGE("getInputForAttr NULL attr - shouldn't happen");
  297. return BAD_VALUE;
  298. }
  299. if (input == NULL) {
  300. ALOGE("getInputForAttr NULL input - shouldn't happen");
  301. return BAD_VALUE;
  302. }
  303. if (selectedDeviceId == NULL) {
  304. ALOGE("getInputForAttr NULL selectedDeviceId - shouldn't happen");
  305. return BAD_VALUE;
  306. }
  307. if (portId == NULL) {
  308. ALOGE("getInputForAttr NULL portId - shouldn't happen");
  309. return BAD_VALUE;
  310. }
  311. data.write(attr, sizeof(audio_attributes_t));
  312. data.writeInt32(*input);
  313. data.writeInt32(riid);
  314. data.writeInt32(session);
  315. data.writeInt32(pid);
  316. data.writeInt32(uid);
  317. data.writeString16(opPackageName);
  318. data.write(config, sizeof(audio_config_base_t));
  319. data.writeInt32(flags);
  320. data.writeInt32(*selectedDeviceId);
  321. data.writeInt32(*portId);
  322. status_t status = remote()->transact(GET_INPUT_FOR_ATTR, data, &reply);
  323. if (status != NO_ERROR) {
  324. return status;
  325. }
  326. status = reply.readInt32();
  327. if (status != NO_ERROR) {
  328. return status;
  329. }
  330. *input = (audio_io_handle_t)reply.readInt32();
  331. *selectedDeviceId = (audio_port_handle_t)reply.readInt32();
  332. *portId = (audio_port_handle_t)reply.readInt32();
  333. return NO_ERROR;
  334. }
  335. virtual status_t startInput(audio_port_handle_t portId)
  336. {
  337. Parcel data, reply;
  338. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  339. data.writeInt32(portId);
  340. remote()->transact(START_INPUT, data, &reply);
  341. status_t status = static_cast <status_t> (reply.readInt32());
  342. return status;
  343. }
  344. virtual status_t stopInput(audio_port_handle_t portId)
  345. {
  346. Parcel data, reply;
  347. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  348. data.writeInt32(portId);
  349. remote()->transact(STOP_INPUT, data, &reply);
  350. return static_cast <status_t> (reply.readInt32());
  351. }
  352. virtual void releaseInput(audio_port_handle_t portId)
  353. {
  354. Parcel data, reply;
  355. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  356. data.writeInt32(portId);
  357. remote()->transact(RELEASE_INPUT, data, &reply);
  358. }
  359. virtual status_t initStreamVolume(audio_stream_type_t stream,
  360. int indexMin,
  361. int indexMax)
  362. {
  363. Parcel data, reply;
  364. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  365. data.writeInt32(static_cast <uint32_t>(stream));
  366. data.writeInt32(indexMin);
  367. data.writeInt32(indexMax);
  368. remote()->transact(INIT_STREAM_VOLUME, data, &reply);
  369. return static_cast <status_t> (reply.readInt32());
  370. }
  371. virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
  372. int index,
  373. audio_devices_t device)
  374. {
  375. Parcel data, reply;
  376. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  377. data.writeInt32(static_cast <uint32_t>(stream));
  378. data.writeInt32(index);
  379. data.writeInt32(static_cast <uint32_t>(device));
  380. remote()->transact(SET_STREAM_VOLUME, data, &reply);
  381. return static_cast <status_t> (reply.readInt32());
  382. }
  383. virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
  384. int *index,
  385. audio_devices_t device)
  386. {
  387. Parcel data, reply;
  388. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  389. data.writeInt32(static_cast <uint32_t>(stream));
  390. data.writeInt32(static_cast <uint32_t>(device));
  391. remote()->transact(GET_STREAM_VOLUME, data, &reply);
  392. int lIndex = reply.readInt32();
  393. if (index) *index = lIndex;
  394. return static_cast <status_t> (reply.readInt32());
  395. }
  396. virtual status_t setVolumeIndexForAttributes(const audio_attributes_t &attr, int index,
  397. audio_devices_t device)
  398. {
  399. Parcel data, reply;
  400. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  401. data.write(&attr, sizeof(audio_attributes_t));
  402. data.writeInt32(index);
  403. data.writeInt32(static_cast <uint32_t>(device));
  404. status_t status = remote()->transact(SET_VOLUME_ATTRIBUTES, data, &reply);
  405. if (status != NO_ERROR) {
  406. return status;
  407. }
  408. return static_cast <status_t> (reply.readInt32());
  409. }
  410. virtual status_t getVolumeIndexForAttributes(const audio_attributes_t &attr, int &index,
  411. audio_devices_t device)
  412. {
  413. Parcel data, reply;
  414. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  415. data.write(&attr, sizeof(audio_attributes_t));
  416. data.writeInt32(static_cast <uint32_t>(device));
  417. status_t status = remote()->transact(GET_VOLUME_ATTRIBUTES, data, &reply);
  418. if (status != NO_ERROR) {
  419. return status;
  420. }
  421. status = static_cast <status_t> (reply.readInt32());
  422. if (status != NO_ERROR) {
  423. return status;
  424. }
  425. index = reply.readInt32();
  426. return NO_ERROR;
  427. }
  428. virtual status_t getMinVolumeIndexForAttributes(const audio_attributes_t &attr, int &index)
  429. {
  430. Parcel data, reply;
  431. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  432. data.write(&attr, sizeof(audio_attributes_t));
  433. status_t status = remote()->transact(GET_MIN_VOLUME_FOR_ATTRIBUTES, data, &reply);
  434. if (status != NO_ERROR) {
  435. return status;
  436. }
  437. status = static_cast <status_t> (reply.readInt32());
  438. if (status != NO_ERROR) {
  439. return status;
  440. }
  441. index = reply.readInt32();
  442. return NO_ERROR;
  443. }
  444. virtual status_t getMaxVolumeIndexForAttributes(const audio_attributes_t &attr, int &index)
  445. {
  446. Parcel data, reply;
  447. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  448. data.write(&attr, sizeof(audio_attributes_t));
  449. status_t status = remote()->transact(GET_MAX_VOLUME_FOR_ATTRIBUTES, data, &reply);
  450. if (status != NO_ERROR) {
  451. return status;
  452. }
  453. status = static_cast <status_t> (reply.readInt32());
  454. if (status != NO_ERROR) {
  455. return status;
  456. }
  457. index = reply.readInt32();
  458. return NO_ERROR;
  459. }
  460. virtual uint32_t getStrategyForStream(audio_stream_type_t stream)
  461. {
  462. Parcel data, reply;
  463. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  464. data.writeInt32(static_cast <uint32_t>(stream));
  465. remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply);
  466. return reply.readUint32();
  467. }
  468. virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream)
  469. {
  470. Parcel data, reply;
  471. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  472. data.writeInt32(static_cast <uint32_t>(stream));
  473. remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
  474. return (audio_devices_t) reply.readInt32();
  475. }
  476. virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc)
  477. {
  478. Parcel data, reply;
  479. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  480. data.write(desc, sizeof(effect_descriptor_t));
  481. remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply);
  482. return static_cast <audio_io_handle_t> (reply.readInt32());
  483. }
  484. virtual status_t registerEffect(const effect_descriptor_t *desc,
  485. audio_io_handle_t io,
  486. uint32_t strategy,
  487. audio_session_t session,
  488. int id)
  489. {
  490. Parcel data, reply;
  491. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  492. data.write(desc, sizeof(effect_descriptor_t));
  493. data.writeInt32(io);
  494. data.writeInt32(strategy);
  495. data.writeInt32(session);
  496. data.writeInt32(id);
  497. remote()->transact(REGISTER_EFFECT, data, &reply);
  498. return static_cast <status_t> (reply.readInt32());
  499. }
  500. virtual status_t unregisterEffect(int id)
  501. {
  502. Parcel data, reply;
  503. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  504. data.writeInt32(id);
  505. remote()->transact(UNREGISTER_EFFECT, data, &reply);
  506. return static_cast <status_t> (reply.readInt32());
  507. }
  508. virtual status_t setEffectEnabled(int id, bool enabled)
  509. {
  510. Parcel data, reply;
  511. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  512. data.writeInt32(id);
  513. data.writeInt32(enabled);
  514. remote()->transact(SET_EFFECT_ENABLED, data, &reply);
  515. return static_cast <status_t> (reply.readInt32());
  516. }
  517. status_t moveEffectsToIo(const std::vector<int>& ids, audio_io_handle_t io) override
  518. {
  519. Parcel data, reply;
  520. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  521. data.writeInt32(ids.size());
  522. for (auto id : ids) {
  523. data.writeInt32(id);
  524. }
  525. data.writeInt32(io);
  526. status_t status = remote()->transact(MOVE_EFFECTS_TO_IO, data, &reply);
  527. if (status != NO_ERROR) {
  528. return status;
  529. }
  530. return static_cast <status_t> (reply.readInt32());
  531. }
  532. virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
  533. {
  534. Parcel data, reply;
  535. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  536. data.writeInt32((int32_t) stream);
  537. data.writeInt32(inPastMs);
  538. remote()->transact(IS_STREAM_ACTIVE, data, &reply);
  539. return reply.readInt32();
  540. }
  541. virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
  542. {
  543. Parcel data, reply;
  544. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  545. data.writeInt32((int32_t) stream);
  546. data.writeInt32(inPastMs);
  547. remote()->transact(IS_STREAM_ACTIVE_REMOTELY, data, &reply);
  548. return reply.readInt32();
  549. }
  550. virtual bool isSourceActive(audio_source_t source) const
  551. {
  552. Parcel data, reply;
  553. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  554. data.writeInt32((int32_t) source);
  555. remote()->transact(IS_SOURCE_ACTIVE, data, &reply);
  556. return reply.readInt32();
  557. }
  558. virtual status_t queryDefaultPreProcessing(audio_session_t audioSession,
  559. effect_descriptor_t *descriptors,
  560. uint32_t *count)
  561. {
  562. if (descriptors == NULL || count == NULL) {
  563. return BAD_VALUE;
  564. }
  565. Parcel data, reply;
  566. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  567. data.writeInt32(audioSession);
  568. data.writeInt32(*count);
  569. status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply);
  570. if (status != NO_ERROR) {
  571. return status;
  572. }
  573. status = static_cast <status_t> (reply.readInt32());
  574. uint32_t retCount = reply.readInt32();
  575. if (retCount != 0) {
  576. uint32_t numDesc = (retCount < *count) ? retCount : *count;
  577. reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc);
  578. }
  579. *count = retCount;
  580. return status;
  581. }
  582. status_t setAllowedCapturePolicy(uid_t uid, audio_flags_mask_t flags) override {
  583. Parcel data, reply;
  584. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  585. data.writeInt32(uid);
  586. data.writeInt32(flags);
  587. remote()->transact(SET_ALLOWED_CAPTURE_POLICY, data, &reply);
  588. return reply.readInt32();
  589. }
  590. virtual bool isOffloadSupported(const audio_offload_info_t& info)
  591. {
  592. Parcel data, reply;
  593. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  594. data.write(&info, sizeof(audio_offload_info_t));
  595. remote()->transact(IS_OFFLOAD_SUPPORTED, data, &reply);
  596. return reply.readInt32();
  597. }
  598. virtual bool isDirectOutputSupported(const audio_config_base_t& config,
  599. const audio_attributes_t& attributes) {
  600. Parcel data, reply;
  601. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  602. data.write(&config, sizeof(audio_config_base_t));
  603. data.write(&attributes, sizeof(audio_attributes_t));
  604. status_t status = remote()->transact(IS_DIRECT_OUTPUT_SUPPORTED, data, &reply);
  605. return status == NO_ERROR ? static_cast<bool>(reply.readInt32()) : false;
  606. }
  607. virtual status_t listAudioPorts(audio_port_role_t role,
  608. audio_port_type_t type,
  609. unsigned int *num_ports,
  610. struct audio_port *ports,
  611. unsigned int *generation)
  612. {
  613. if (num_ports == NULL || (*num_ports != 0 && ports == NULL) ||
  614. generation == NULL) {
  615. return BAD_VALUE;
  616. }
  617. Parcel data, reply;
  618. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  619. unsigned int numPortsReq = (ports == NULL) ? 0 : *num_ports;
  620. data.writeInt32(role);
  621. data.writeInt32(type);
  622. data.writeInt32(numPortsReq);
  623. status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
  624. if (status == NO_ERROR) {
  625. status = (status_t)reply.readInt32();
  626. *num_ports = (unsigned int)reply.readInt32();
  627. }
  628. if (status == NO_ERROR) {
  629. if (numPortsReq > *num_ports) {
  630. numPortsReq = *num_ports;
  631. }
  632. if (numPortsReq > 0) {
  633. reply.read(ports, numPortsReq * sizeof(struct audio_port));
  634. }
  635. *generation = reply.readInt32();
  636. }
  637. return status;
  638. }
  639. virtual status_t getAudioPort(struct audio_port *port)
  640. {
  641. if (port == NULL) {
  642. return BAD_VALUE;
  643. }
  644. Parcel data, reply;
  645. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  646. data.write(port, sizeof(struct audio_port));
  647. status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
  648. if (status != NO_ERROR ||
  649. (status = (status_t)reply.readInt32()) != NO_ERROR) {
  650. return status;
  651. }
  652. reply.read(port, sizeof(struct audio_port));
  653. return status;
  654. }
  655. virtual status_t createAudioPatch(const struct audio_patch *patch,
  656. audio_patch_handle_t *handle)
  657. {
  658. if (patch == NULL || handle == NULL) {
  659. return BAD_VALUE;
  660. }
  661. Parcel data, reply;
  662. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  663. data.write(patch, sizeof(struct audio_patch));
  664. data.write(handle, sizeof(audio_patch_handle_t));
  665. status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
  666. if (status != NO_ERROR ||
  667. (status = (status_t)reply.readInt32()) != NO_ERROR) {
  668. return status;
  669. }
  670. reply.read(handle, sizeof(audio_patch_handle_t));
  671. return status;
  672. }
  673. virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
  674. {
  675. Parcel data, reply;
  676. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  677. data.write(&handle, sizeof(audio_patch_handle_t));
  678. status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
  679. if (status != NO_ERROR) {
  680. status = (status_t)reply.readInt32();
  681. }
  682. return status;
  683. }
  684. virtual status_t listAudioPatches(unsigned int *num_patches,
  685. struct audio_patch *patches,
  686. unsigned int *generation)
  687. {
  688. if (num_patches == NULL || (*num_patches != 0 && patches == NULL) ||
  689. generation == NULL) {
  690. return BAD_VALUE;
  691. }
  692. Parcel data, reply;
  693. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  694. unsigned int numPatchesReq = (patches == NULL) ? 0 : *num_patches;
  695. data.writeInt32(numPatchesReq);
  696. status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
  697. if (status == NO_ERROR) {
  698. status = (status_t)reply.readInt32();
  699. *num_patches = (unsigned int)reply.readInt32();
  700. }
  701. if (status == NO_ERROR) {
  702. if (numPatchesReq > *num_patches) {
  703. numPatchesReq = *num_patches;
  704. }
  705. if (numPatchesReq > 0) {
  706. reply.read(patches, numPatchesReq * sizeof(struct audio_patch));
  707. }
  708. *generation = reply.readInt32();
  709. }
  710. return status;
  711. }
  712. virtual status_t setAudioPortConfig(const struct audio_port_config *config)
  713. {
  714. if (config == NULL) {
  715. return BAD_VALUE;
  716. }
  717. Parcel data, reply;
  718. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  719. data.write(config, sizeof(struct audio_port_config));
  720. status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
  721. if (status != NO_ERROR) {
  722. status = (status_t)reply.readInt32();
  723. }
  724. return status;
  725. }
  726. virtual void registerClient(const sp<IAudioPolicyServiceClient>& client)
  727. {
  728. Parcel data, reply;
  729. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  730. data.writeStrongBinder(IInterface::asBinder(client));
  731. remote()->transact(REGISTER_CLIENT, data, &reply);
  732. }
  733. virtual void setAudioPortCallbacksEnabled(bool enabled)
  734. {
  735. Parcel data, reply;
  736. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  737. data.writeInt32(enabled ? 1 : 0);
  738. remote()->transact(SET_AUDIO_PORT_CALLBACK_ENABLED, data, &reply);
  739. }
  740. virtual void setAudioVolumeGroupCallbacksEnabled(bool enabled)
  741. {
  742. Parcel data, reply;
  743. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  744. data.writeInt32(enabled ? 1 : 0);
  745. remote()->transact(SET_AUDIO_VOLUME_GROUP_CALLBACK_ENABLED, data, &reply);
  746. }
  747. virtual status_t acquireSoundTriggerSession(audio_session_t *session,
  748. audio_io_handle_t *ioHandle,
  749. audio_devices_t *device)
  750. {
  751. if (session == NULL || ioHandle == NULL || device == NULL) {
  752. return BAD_VALUE;
  753. }
  754. Parcel data, reply;
  755. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  756. status_t status = remote()->transact(ACQUIRE_SOUNDTRIGGER_SESSION, data, &reply);
  757. if (status != NO_ERROR) {
  758. return status;
  759. }
  760. status = (status_t)reply.readInt32();
  761. if (status == NO_ERROR) {
  762. *session = (audio_session_t)reply.readInt32();
  763. *ioHandle = (audio_io_handle_t)reply.readInt32();
  764. *device = (audio_devices_t)reply.readInt32();
  765. }
  766. return status;
  767. }
  768. virtual status_t releaseSoundTriggerSession(audio_session_t session)
  769. {
  770. Parcel data, reply;
  771. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  772. data.writeInt32(session);
  773. status_t status = remote()->transact(RELEASE_SOUNDTRIGGER_SESSION, data, &reply);
  774. if (status != NO_ERROR) {
  775. return status;
  776. }
  777. return (status_t)reply.readInt32();
  778. }
  779. virtual audio_mode_t getPhoneState()
  780. {
  781. Parcel data, reply;
  782. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  783. status_t status = remote()->transact(GET_PHONE_STATE, data, &reply);
  784. if (status != NO_ERROR) {
  785. return AUDIO_MODE_INVALID;
  786. }
  787. return (audio_mode_t)reply.readInt32();
  788. }
  789. virtual status_t registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration)
  790. {
  791. Parcel data, reply;
  792. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  793. data.writeInt32(registration ? 1 : 0);
  794. size_t size = mixes.size();
  795. if (size > MAX_MIXES_PER_POLICY) {
  796. size = MAX_MIXES_PER_POLICY;
  797. }
  798. size_t sizePosition = data.dataPosition();
  799. data.writeInt32(size);
  800. size_t finalSize = size;
  801. for (size_t i = 0; i < size; i++) {
  802. size_t position = data.dataPosition();
  803. if (mixes[i].writeToParcel(&data) != NO_ERROR) {
  804. data.setDataPosition(position);
  805. finalSize--;
  806. }
  807. }
  808. if (size != finalSize) {
  809. size_t position = data.dataPosition();
  810. data.setDataPosition(sizePosition);
  811. data.writeInt32(finalSize);
  812. data.setDataPosition(position);
  813. }
  814. status_t status = remote()->transact(REGISTER_POLICY_MIXES, data, &reply);
  815. if (status == NO_ERROR) {
  816. status = (status_t)reply.readInt32();
  817. }
  818. return status;
  819. }
  820. virtual status_t startAudioSource(const struct audio_port_config *source,
  821. const audio_attributes_t *attributes,
  822. audio_port_handle_t *portId)
  823. {
  824. Parcel data, reply;
  825. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  826. if (source == NULL || attributes == NULL || portId == NULL) {
  827. return BAD_VALUE;
  828. }
  829. data.write(source, sizeof(struct audio_port_config));
  830. data.write(attributes, sizeof(audio_attributes_t));
  831. status_t status = remote()->transact(START_AUDIO_SOURCE, data, &reply);
  832. if (status != NO_ERROR) {
  833. return status;
  834. }
  835. status = (status_t)reply.readInt32();
  836. if (status != NO_ERROR) {
  837. return status;
  838. }
  839. *portId = (audio_port_handle_t)reply.readInt32();
  840. return status;
  841. }
  842. virtual status_t stopAudioSource(audio_port_handle_t portId)
  843. {
  844. Parcel data, reply;
  845. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  846. data.writeInt32(portId);
  847. status_t status = remote()->transact(STOP_AUDIO_SOURCE, data, &reply);
  848. if (status != NO_ERROR) {
  849. return status;
  850. }
  851. status = (status_t)reply.readInt32();
  852. return status;
  853. }
  854. virtual status_t setMasterMono(bool mono)
  855. {
  856. Parcel data, reply;
  857. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  858. data.writeInt32(static_cast<int32_t>(mono));
  859. status_t status = remote()->transact(SET_MASTER_MONO, data, &reply);
  860. if (status != NO_ERROR) {
  861. return status;
  862. }
  863. return static_cast<status_t>(reply.readInt32());
  864. }
  865. virtual status_t getMasterMono(bool *mono)
  866. {
  867. if (mono == nullptr) {
  868. return BAD_VALUE;
  869. }
  870. Parcel data, reply;
  871. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  872. status_t status = remote()->transact(GET_MASTER_MONO, data, &reply);
  873. if (status != NO_ERROR) {
  874. return status;
  875. }
  876. status = static_cast<status_t>(reply.readInt32());
  877. if (status == NO_ERROR) {
  878. *mono = static_cast<bool>(reply.readInt32());
  879. }
  880. return status;
  881. }
  882. virtual float getStreamVolumeDB(audio_stream_type_t stream, int index, audio_devices_t device)
  883. {
  884. Parcel data, reply;
  885. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  886. data.writeInt32(static_cast <int32_t>(stream));
  887. data.writeInt32(static_cast <int32_t>(index));
  888. data.writeUint32(static_cast <uint32_t>(device));
  889. status_t status = remote()->transact(GET_STREAM_VOLUME_DB, data, &reply);
  890. if (status != NO_ERROR) {
  891. return NAN;
  892. }
  893. return reply.readFloat();
  894. }
  895. virtual status_t getSurroundFormats(unsigned int *numSurroundFormats,
  896. audio_format_t *surroundFormats,
  897. bool *surroundFormatsEnabled,
  898. bool reported)
  899. {
  900. if (numSurroundFormats == NULL || (*numSurroundFormats != 0 &&
  901. (surroundFormats == NULL || surroundFormatsEnabled == NULL))) {
  902. return BAD_VALUE;
  903. }
  904. Parcel data, reply;
  905. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  906. unsigned int numSurroundFormatsReq = *numSurroundFormats;
  907. data.writeUint32(numSurroundFormatsReq);
  908. data.writeBool(reported);
  909. status_t status = remote()->transact(GET_SURROUND_FORMATS, data, &reply);
  910. if (status == NO_ERROR && (status = (status_t)reply.readInt32()) == NO_ERROR) {
  911. *numSurroundFormats = reply.readUint32();
  912. }
  913. if (status == NO_ERROR) {
  914. if (numSurroundFormatsReq > *numSurroundFormats) {
  915. numSurroundFormatsReq = *numSurroundFormats;
  916. }
  917. if (numSurroundFormatsReq > 0) {
  918. status = reply.read(surroundFormats,
  919. numSurroundFormatsReq * sizeof(audio_format_t));
  920. if (status != NO_ERROR) {
  921. return status;
  922. }
  923. status = reply.read(surroundFormatsEnabled,
  924. numSurroundFormatsReq * sizeof(bool));
  925. }
  926. }
  927. return status;
  928. }
  929. virtual status_t setSurroundFormatEnabled(audio_format_t audioFormat, bool enabled)
  930. {
  931. Parcel data, reply;
  932. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  933. data.writeInt32(audioFormat);
  934. data.writeBool(enabled);
  935. status_t status = remote()->transact(SET_SURROUND_FORMAT_ENABLED, data, &reply);
  936. if (status != NO_ERROR) {
  937. return status;
  938. }
  939. return reply.readInt32();
  940. }
  941. virtual status_t getHwOffloadEncodingFormatsSupportedForA2DP(
  942. std::vector<audio_format_t> *formats)
  943. {
  944. if (formats == NULL) {
  945. return BAD_VALUE;
  946. }
  947. Parcel data, reply;
  948. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  949. status_t status = remote()->transact(GET_OFFLOAD_FORMATS_A2DP, data, &reply);
  950. if (status != NO_ERROR || (status = (status_t)reply.readInt32()) != NO_ERROR) {
  951. return status;
  952. }
  953. size_t list_size = reply.readUint32();
  954. for (size_t i = 0; i < list_size; i++) {
  955. formats->push_back(static_cast<audio_format_t>(reply.readInt32()));
  956. }
  957. return NO_ERROR;
  958. }
  959. virtual status_t addStreamDefaultEffect(const effect_uuid_t *type,
  960. const String16& opPackageName,
  961. const effect_uuid_t *uuid,
  962. int32_t priority,
  963. audio_usage_t usage,
  964. audio_unique_id_t* id)
  965. {
  966. Parcel data, reply;
  967. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  968. data.write(type, sizeof(effect_uuid_t));
  969. data.writeString16(opPackageName);
  970. data.write(uuid, sizeof(effect_uuid_t));
  971. data.writeInt32(priority);
  972. data.writeInt32((int32_t) usage);
  973. status_t status = remote()->transact(ADD_STREAM_DEFAULT_EFFECT, data, &reply);
  974. if (status != NO_ERROR) {
  975. return status;
  976. }
  977. status = static_cast <status_t> (reply.readInt32());
  978. *id = reply.readInt32();
  979. return status;
  980. }
  981. virtual status_t removeStreamDefaultEffect(audio_unique_id_t id)
  982. {
  983. Parcel data, reply;
  984. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  985. data.writeInt32(id);
  986. status_t status = remote()->transact(REMOVE_STREAM_DEFAULT_EFFECT, data, &reply);
  987. if (status != NO_ERROR) {
  988. return status;
  989. }
  990. return static_cast <status_t> (reply.readInt32());
  991. }
  992. virtual status_t addSourceDefaultEffect(const effect_uuid_t *type,
  993. const String16& opPackageName,
  994. const effect_uuid_t *uuid,
  995. int32_t priority,
  996. audio_source_t source,
  997. audio_unique_id_t* id)
  998. {
  999. Parcel data, reply;
  1000. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  1001. data.write(type, sizeof(effect_uuid_t));
  1002. data.writeString16(opPackageName);
  1003. data.write(uuid, sizeof(effect_uuid_t));
  1004. data.writeInt32(priority);
  1005. data.writeInt32((int32_t) source);
  1006. status_t status = remote()->transact(ADD_SOURCE_DEFAULT_EFFECT, data, &reply);
  1007. if (status != NO_ERROR) {
  1008. return status;
  1009. }
  1010. status = static_cast <status_t> (reply.readInt32());
  1011. *id = reply.readInt32();
  1012. return status;
  1013. }
  1014. virtual status_t removeSourceDefaultEffect(audio_unique_id_t id)
  1015. {
  1016. Parcel data, reply;
  1017. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  1018. data.writeInt32(id);
  1019. status_t status = remote()->transact(REMOVE_SOURCE_DEFAULT_EFFECT, data, &reply);
  1020. if (status != NO_ERROR) {
  1021. return status;
  1022. }
  1023. return static_cast <status_t> (reply.readInt32());
  1024. }
  1025. virtual status_t setAssistantUid(uid_t uid)
  1026. {
  1027. Parcel data, reply;
  1028. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  1029. data.writeInt32(uid);
  1030. status_t status = remote()->transact(SET_ASSISTANT_UID, data, &reply);
  1031. if (status != NO_ERROR) {
  1032. return status;
  1033. }
  1034. return static_cast <status_t> (reply.readInt32());
  1035. }
  1036. virtual status_t setA11yServicesUids(const std::vector<uid_t>& uids)
  1037. {
  1038. Parcel data, reply;
  1039. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  1040. data.writeInt32(uids.size());
  1041. for (auto uid : uids) {
  1042. data.writeInt32(uid);
  1043. }
  1044. status_t status = remote()->transact(SET_A11Y_SERVICES_UIDS, data, &reply);
  1045. if (status != NO_ERROR) {
  1046. return status;
  1047. }
  1048. return static_cast <status_t> (reply.readInt32());
  1049. }
  1050. virtual bool isHapticPlaybackSupported()
  1051. {
  1052. Parcel data, reply;
  1053. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  1054. status_t status = remote()->transact(IS_HAPTIC_PLAYBACK_SUPPORTED, data, &reply);
  1055. if (status != NO_ERROR) {
  1056. return false;
  1057. }
  1058. return reply.readBool();
  1059. }
  1060. virtual status_t setUidDeviceAffinities(uid_t uid, const Vector<AudioDeviceTypeAddr>& devices)
  1061. {
  1062. Parcel data, reply;
  1063. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  1064. data.writeInt32((int32_t) uid);
  1065. size_t size = devices.size();
  1066. size_t sizePosition = data.dataPosition();
  1067. data.writeInt32((int32_t) size);
  1068. size_t finalSize = size;
  1069. for (size_t i = 0; i < size; i++) {
  1070. size_t position = data.dataPosition();
  1071. if (devices[i].writeToParcel(&data) != NO_ERROR) {
  1072. data.setDataPosition(position);
  1073. finalSize--;
  1074. }
  1075. }
  1076. if (size != finalSize) {
  1077. size_t position = data.dataPosition();
  1078. data.setDataPosition(sizePosition);
  1079. data.writeInt32(finalSize);
  1080. data.setDataPosition(position);
  1081. }
  1082. status_t status = remote()->transact(SET_UID_DEVICE_AFFINITY, data, &reply);
  1083. if (status == NO_ERROR) {
  1084. status = (status_t)reply.readInt32();
  1085. }
  1086. return status;
  1087. }
  1088. virtual status_t removeUidDeviceAffinities(uid_t uid) {
  1089. Parcel data, reply;
  1090. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  1091. data.writeInt32((int32_t) uid);
  1092. status_t status =
  1093. remote()->transact(REMOVE_UID_DEVICE_AFFINITY, data, &reply);
  1094. if (status == NO_ERROR) {
  1095. status = (status_t) reply.readInt32();
  1096. }
  1097. return status;
  1098. }
  1099. virtual status_t listAudioProductStrategies(AudioProductStrategyVector &strategies)
  1100. {
  1101. Parcel data, reply;
  1102. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  1103. status_t status = remote()->transact(LIST_AUDIO_PRODUCT_STRATEGIES, data, &reply);
  1104. if (status != NO_ERROR) {
  1105. ALOGE("%s: permission denied", __func__);
  1106. return status;
  1107. }
  1108. status = static_cast<status_t>(reply.readInt32());
  1109. if (status != NO_ERROR) {
  1110. return status;
  1111. }
  1112. uint32_t numStrategies = static_cast<uint32_t>(reply.readInt32());
  1113. for (size_t i = 0; i < numStrategies; i++) {
  1114. AudioProductStrategy strategy;
  1115. status = strategy.readFromParcel(&reply);
  1116. if (status != NO_ERROR) {
  1117. ALOGE("%s: failed to read strategies", __FUNCTION__);
  1118. strategies.clear();
  1119. return status;
  1120. }
  1121. strategies.push_back(strategy);
  1122. }
  1123. return NO_ERROR;
  1124. }
  1125. virtual status_t getProductStrategyFromAudioAttributes(const AudioAttributes &aa,
  1126. product_strategy_t &productStrategy)
  1127. {
  1128. Parcel data, reply;
  1129. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  1130. status_t status = aa.writeToParcel(&data);
  1131. if (status != NO_ERROR) {
  1132. return status;
  1133. }
  1134. status = remote()->transact(GET_STRATEGY_FOR_ATTRIBUTES, data, &reply);
  1135. if (status != NO_ERROR) {
  1136. return status;
  1137. }
  1138. status = static_cast<status_t>(reply.readInt32());
  1139. if (status != NO_ERROR) {
  1140. return status;
  1141. }
  1142. productStrategy = static_cast<product_strategy_t>(reply.readInt32());
  1143. return NO_ERROR;
  1144. }
  1145. virtual status_t listAudioVolumeGroups(AudioVolumeGroupVector &groups)
  1146. {
  1147. Parcel data, reply;
  1148. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  1149. status_t status = remote()->transact(LIST_AUDIO_VOLUME_GROUPS, data, &reply);
  1150. if (status != NO_ERROR) {
  1151. return status;
  1152. }
  1153. status = static_cast<status_t>(reply.readInt32());
  1154. if (status != NO_ERROR) {
  1155. return status;
  1156. }
  1157. uint32_t numGroups = static_cast<uint32_t>(reply.readInt32());
  1158. for (size_t i = 0; i < numGroups; i++) {
  1159. AudioVolumeGroup group;
  1160. status = group.readFromParcel(&reply);
  1161. if (status != NO_ERROR) {
  1162. ALOGE("%s: failed to read volume groups", __FUNCTION__);
  1163. groups.clear();
  1164. return status;
  1165. }
  1166. groups.push_back(group);
  1167. }
  1168. return NO_ERROR;
  1169. }
  1170. virtual status_t getVolumeGroupFromAudioAttributes(const AudioAttributes &aa,
  1171. volume_group_t &volumeGroup)
  1172. {
  1173. Parcel data, reply;
  1174. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  1175. status_t status = aa.writeToParcel(&data);
  1176. if (status != NO_ERROR) {
  1177. return status;
  1178. }
  1179. status = remote()->transact(GET_VOLUME_GROUP_FOR_ATTRIBUTES, data, &reply);
  1180. if (status != NO_ERROR) {
  1181. return status;
  1182. }
  1183. status = static_cast<status_t>(reply.readInt32());
  1184. if (status != NO_ERROR) {
  1185. return status;
  1186. }
  1187. volumeGroup = static_cast<volume_group_t>(reply.readInt32());
  1188. return NO_ERROR;
  1189. }
  1190. virtual status_t setRttEnabled(bool enabled)
  1191. {
  1192. Parcel data, reply;
  1193. data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
  1194. data.writeInt32(static_cast<int32_t>(enabled));
  1195. status_t status = remote()->transact(SET_RTT_ENABLED, data, &reply);
  1196. if (status != NO_ERROR) {
  1197. return status;
  1198. }
  1199. return static_cast<status_t>(reply.readInt32());
  1200. }
  1201. };
  1202. IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
  1203. // ----------------------------------------------------------------------
  1204. status_t BnAudioPolicyService::onTransact(
  1205. uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
  1206. {
  1207. // make sure transactions reserved to AudioFlinger do not come from other processes
  1208. switch (code) {
  1209. case START_OUTPUT:
  1210. case STOP_OUTPUT:
  1211. case RELEASE_OUTPUT:
  1212. case GET_INPUT_FOR_ATTR:
  1213. case START_INPUT:
  1214. case STOP_INPUT:
  1215. case RELEASE_INPUT:
  1216. case GET_OUTPUT_FOR_EFFECT:
  1217. case REGISTER_EFFECT:
  1218. case UNREGISTER_EFFECT:
  1219. case SET_EFFECT_ENABLED:
  1220. case GET_OUTPUT_FOR_ATTR:
  1221. case ACQUIRE_SOUNDTRIGGER_SESSION:
  1222. case RELEASE_SOUNDTRIGGER_SESSION:
  1223. case MOVE_EFFECTS_TO_IO:
  1224. ALOGW("%s: transaction %d received from PID %d",
  1225. __func__, code, IPCThreadState::self()->getCallingPid());
  1226. // return status only for non void methods
  1227. switch (code) {
  1228. case RELEASE_OUTPUT:
  1229. case RELEASE_INPUT:
  1230. break;
  1231. default:
  1232. reply->writeInt32(static_cast<int32_t> (INVALID_OPERATION));
  1233. break;
  1234. }
  1235. return OK;
  1236. default:
  1237. break;
  1238. }
  1239. // make sure the following transactions come from system components
  1240. switch (code) {
  1241. case SET_DEVICE_CONNECTION_STATE:
  1242. case HANDLE_DEVICE_CONFIG_CHANGE:
  1243. case SET_PHONE_STATE:
  1244. //FIXME: Allow SET_FORCE_USE calls from system apps until a better use case routing API is available
  1245. // case SET_FORCE_USE:
  1246. case INIT_STREAM_VOLUME:
  1247. case SET_STREAM_VOLUME:
  1248. case REGISTER_POLICY_MIXES:
  1249. case SET_MASTER_MONO:
  1250. case GET_SURROUND_FORMATS:
  1251. case SET_SURROUND_FORMAT_ENABLED:
  1252. case SET_ASSISTANT_UID:
  1253. case SET_A11Y_SERVICES_UIDS:
  1254. case SET_UID_DEVICE_AFFINITY:
  1255. case REMOVE_UID_DEVICE_AFFINITY:
  1256. case GET_OFFLOAD_FORMATS_A2DP:
  1257. case LIST_AUDIO_VOLUME_GROUPS:
  1258. case GET_VOLUME_GROUP_FOR_ATTRIBUTES:
  1259. case SET_RTT_ENABLED: {
  1260. if (!isServiceUid(IPCThreadState::self()->getCallingUid())) {
  1261. ALOGW("%s: transaction %d received from PID %d unauthorized UID %d",
  1262. __func__, code, IPCThreadState::self()->getCallingPid(),
  1263. IPCThreadState::self()->getCallingUid());
  1264. reply->writeInt32(static_cast<int32_t> (INVALID_OPERATION));
  1265. return OK;
  1266. }
  1267. } break;
  1268. default:
  1269. break;
  1270. }
  1271. std::string tag("IAudioPolicyService command " + std::to_string(code));
  1272. TimeCheck check(tag.c_str());
  1273. switch (code) {
  1274. case SET_DEVICE_CONNECTION_STATE: {
  1275. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1276. audio_devices_t device =
  1277. static_cast <audio_devices_t>(data.readInt32());
  1278. audio_policy_dev_state_t state =
  1279. static_cast <audio_policy_dev_state_t>(data.readInt32());
  1280. const char *device_address = data.readCString();
  1281. const char *device_name = data.readCString();
  1282. audio_format_t codecFormat = static_cast <audio_format_t>(data.readInt32());
  1283. if (device_address == nullptr || device_name == nullptr) {
  1284. ALOGE("Bad Binder transaction: SET_DEVICE_CONNECTION_STATE for device %u", device);
  1285. reply->writeInt32(static_cast<int32_t> (BAD_VALUE));
  1286. } else {
  1287. reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
  1288. state,
  1289. device_address,
  1290. device_name,
  1291. codecFormat)));
  1292. }
  1293. return NO_ERROR;
  1294. } break;
  1295. case GET_DEVICE_CONNECTION_STATE: {
  1296. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1297. audio_devices_t device =
  1298. static_cast<audio_devices_t> (data.readInt32());
  1299. const char *device_address = data.readCString();
  1300. if (device_address == nullptr) {
  1301. ALOGE("Bad Binder transaction: GET_DEVICE_CONNECTION_STATE for device %u", device);
  1302. reply->writeInt32(static_cast<int32_t> (AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE));
  1303. } else {
  1304. reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
  1305. device_address)));
  1306. }
  1307. return NO_ERROR;
  1308. } break;
  1309. case HANDLE_DEVICE_CONFIG_CHANGE: {
  1310. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1311. audio_devices_t device =
  1312. static_cast <audio_devices_t>(data.readInt32());
  1313. const char *device_address = data.readCString();
  1314. const char *device_name = data.readCString();
  1315. audio_format_t codecFormat =
  1316. static_cast <audio_format_t>(data.readInt32());
  1317. if (device_address == nullptr || device_name == nullptr) {
  1318. ALOGE("Bad Binder transaction: HANDLE_DEVICE_CONFIG_CHANGE for device %u", device);
  1319. reply->writeInt32(static_cast<int32_t> (BAD_VALUE));
  1320. } else {
  1321. reply->writeInt32(static_cast<uint32_t> (handleDeviceConfigChange(device,
  1322. device_address,
  1323. device_name,
  1324. codecFormat)));
  1325. }
  1326. return NO_ERROR;
  1327. } break;
  1328. case SET_PHONE_STATE: {
  1329. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1330. reply->writeInt32(static_cast <uint32_t>(setPhoneState(
  1331. (audio_mode_t) data.readInt32())));
  1332. return NO_ERROR;
  1333. } break;
  1334. case SET_FORCE_USE: {
  1335. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1336. audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
  1337. data.readInt32());
  1338. audio_policy_forced_cfg_t config =
  1339. static_cast <audio_policy_forced_cfg_t>(data.readInt32());
  1340. reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
  1341. return NO_ERROR;
  1342. } break;
  1343. case GET_FORCE_USE: {
  1344. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1345. audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(
  1346. data.readInt32());
  1347. reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
  1348. return NO_ERROR;
  1349. } break;
  1350. case GET_OUTPUT: {
  1351. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1352. audio_stream_type_t stream =
  1353. static_cast <audio_stream_type_t>(data.readInt32());
  1354. audio_io_handle_t output = getOutput(stream);
  1355. reply->writeInt32(static_cast <int>(output));
  1356. return NO_ERROR;
  1357. } break;
  1358. case GET_OUTPUT_FOR_ATTR: {
  1359. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1360. audio_attributes_t attr = AUDIO_ATTRIBUTES_INITIALIZER;
  1361. status_t status = data.read(&attr, sizeof(audio_attributes_t));
  1362. if (status != NO_ERROR) {
  1363. return status;
  1364. }
  1365. sanetizeAudioAttributes(&attr);
  1366. audio_session_t session = (audio_session_t)data.readInt32();
  1367. audio_stream_type_t stream = AUDIO_STREAM_DEFAULT;
  1368. bool hasStream = data.readInt32() != 0;
  1369. if (hasStream) {
  1370. stream = (audio_stream_type_t)data.readInt32();
  1371. }
  1372. pid_t pid = (pid_t)data.readInt32();
  1373. uid_t uid = (uid_t)data.readInt32();
  1374. audio_config_t config;
  1375. memset(&config, 0, sizeof(audio_config_t));
  1376. data.read(&config, sizeof(audio_config_t));
  1377. audio_output_flags_t flags =
  1378. static_cast <audio_output_flags_t>(data.readInt32());
  1379. audio_port_handle_t selectedDeviceId = data.readInt32();
  1380. audio_port_handle_t portId = (audio_port_handle_t)data.readInt32();
  1381. audio_io_handle_t output = 0;
  1382. std::vector<audio_io_handle_t> secondaryOutputs;
  1383. status = getOutputForAttr(&attr,
  1384. &output, session, &stream, pid, uid,
  1385. &config,
  1386. flags, &selectedDeviceId, &portId, &secondaryOutputs);
  1387. reply->writeInt32(status);
  1388. status = reply->write(&attr, sizeof(audio_attributes_t));
  1389. if (status != NO_ERROR) {
  1390. return status;
  1391. }
  1392. reply->writeInt32(output);
  1393. reply->writeInt32(stream);
  1394. reply->writeInt32(selectedDeviceId);
  1395. reply->writeInt32(portId);
  1396. reply->writeInt32(secondaryOutputs.size());
  1397. return reply->write(secondaryOutputs.data(),
  1398. secondaryOutputs.size() * sizeof(audio_io_handle_t));
  1399. } break;
  1400. case START_OUTPUT: {
  1401. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1402. const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
  1403. reply->writeInt32(static_cast <uint32_t>(startOutput(portId)));
  1404. return NO_ERROR;
  1405. } break;
  1406. case STOP_OUTPUT: {
  1407. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1408. const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
  1409. reply->writeInt32(static_cast <uint32_t>(stopOutput(portId)));
  1410. return NO_ERROR;
  1411. } break;
  1412. case RELEASE_OUTPUT: {
  1413. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1414. const audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
  1415. releaseOutput(portId);
  1416. return NO_ERROR;
  1417. } break;
  1418. case GET_INPUT_FOR_ATTR: {
  1419. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1420. audio_attributes_t attr = {};
  1421. data.read(&attr, sizeof(audio_attributes_t));
  1422. sanetizeAudioAttributes(&attr);
  1423. audio_io_handle_t input = (audio_io_handle_t)data.readInt32();
  1424. audio_unique_id_t riid = (audio_unique_id_t)data.readInt32();
  1425. audio_session_t session = (audio_session_t)data.readInt32();
  1426. pid_t pid = (pid_t)data.readInt32();
  1427. uid_t uid = (uid_t)data.readInt32();
  1428. const String16 opPackageName = data.readString16();
  1429. audio_config_base_t config;
  1430. memset(&config, 0, sizeof(audio_config_base_t));
  1431. data.read(&config, sizeof(audio_config_base_t));
  1432. audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
  1433. audio_port_handle_t selectedDeviceId = (audio_port_handle_t) data.readInt32();
  1434. audio_port_handle_t portId = (audio_port_handle_t)data.readInt32();
  1435. status_t status = getInputForAttr(&attr, &input, riid, session, pid, uid,
  1436. opPackageName, &config,
  1437. flags, &selectedDeviceId, &portId);
  1438. reply->writeInt32(status);
  1439. if (status == NO_ERROR) {
  1440. reply->writeInt32(input);
  1441. reply->writeInt32(selectedDeviceId);
  1442. reply->writeInt32(portId);
  1443. }
  1444. return NO_ERROR;
  1445. } break;
  1446. case START_INPUT: {
  1447. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1448. audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
  1449. status_t status = startInput(portId);
  1450. reply->writeInt32(static_cast <uint32_t>(status));
  1451. return NO_ERROR;
  1452. } break;
  1453. case STOP_INPUT: {
  1454. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1455. audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
  1456. reply->writeInt32(static_cast <uint32_t>(stopInput(portId)));
  1457. return NO_ERROR;
  1458. } break;
  1459. case RELEASE_INPUT: {
  1460. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1461. audio_port_handle_t portId = static_cast <audio_port_handle_t>(data.readInt32());
  1462. releaseInput(portId);
  1463. return NO_ERROR;
  1464. } break;
  1465. case INIT_STREAM_VOLUME: {
  1466. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1467. audio_stream_type_t stream =
  1468. static_cast <audio_stream_type_t>(data.readInt32());
  1469. int indexMin = data.readInt32();
  1470. int indexMax = data.readInt32();
  1471. reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
  1472. return NO_ERROR;
  1473. } break;
  1474. case SET_STREAM_VOLUME: {
  1475. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1476. audio_stream_type_t stream =
  1477. static_cast <audio_stream_type_t>(data.readInt32());
  1478. int index = data.readInt32();
  1479. audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
  1480. reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream,
  1481. index,
  1482. device)));
  1483. return NO_ERROR;
  1484. } break;
  1485. case GET_STREAM_VOLUME: {
  1486. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1487. audio_stream_type_t stream =
  1488. static_cast <audio_stream_type_t>(data.readInt32());
  1489. audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
  1490. int index = 0;
  1491. status_t status = getStreamVolumeIndex(stream, &index, device);
  1492. reply->writeInt32(index);
  1493. reply->writeInt32(static_cast <uint32_t>(status));
  1494. return NO_ERROR;
  1495. } break;
  1496. case GET_STRATEGY_FOR_STREAM: {
  1497. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1498. audio_stream_type_t stream =
  1499. static_cast <audio_stream_type_t>(data.readInt32());
  1500. reply->writeUint32(getStrategyForStream(stream));
  1501. return NO_ERROR;
  1502. } break;
  1503. case SET_VOLUME_ATTRIBUTES: {
  1504. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1505. audio_attributes_t attributes = {};
  1506. status_t status = data.read(&attributes, sizeof(audio_attributes_t));
  1507. if (status != NO_ERROR) {
  1508. return status;
  1509. }
  1510. int index = data.readInt32();
  1511. audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
  1512. reply->writeInt32(static_cast <uint32_t>(setVolumeIndexForAttributes(attributes,
  1513. index, device)));
  1514. return NO_ERROR;
  1515. } break;
  1516. case GET_VOLUME_ATTRIBUTES: {
  1517. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1518. audio_attributes_t attributes = {};
  1519. status_t status = data.read(&attributes, sizeof(audio_attributes_t));
  1520. if (status != NO_ERROR) {
  1521. return status;
  1522. }
  1523. audio_devices_t device = static_cast <audio_devices_t>(data.readInt32());
  1524. int index = 0;
  1525. status = getVolumeIndexForAttributes(attributes, index, device);
  1526. reply->writeInt32(static_cast <uint32_t>(status));
  1527. if (status == NO_ERROR) {
  1528. reply->writeInt32(index);
  1529. }
  1530. return NO_ERROR;
  1531. } break;
  1532. case GET_MIN_VOLUME_FOR_ATTRIBUTES: {
  1533. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1534. audio_attributes_t attributes = {};
  1535. status_t status = data.read(&attributes, sizeof(audio_attributes_t));
  1536. if (status != NO_ERROR) {
  1537. return status;
  1538. }
  1539. int index = 0;
  1540. status = getMinVolumeIndexForAttributes(attributes, index);
  1541. reply->writeInt32(static_cast <uint32_t>(status));
  1542. if (status == NO_ERROR) {
  1543. reply->writeInt32(index);
  1544. }
  1545. return NO_ERROR;
  1546. } break;
  1547. case GET_MAX_VOLUME_FOR_ATTRIBUTES: {
  1548. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1549. audio_attributes_t attributes = {};
  1550. status_t status = data.read(&attributes, sizeof(audio_attributes_t));
  1551. if (status != NO_ERROR) {
  1552. return status;
  1553. }
  1554. int index = 0;
  1555. status = getMaxVolumeIndexForAttributes(attributes, index);
  1556. reply->writeInt32(static_cast <uint32_t>(status));
  1557. if (status == NO_ERROR) {
  1558. reply->writeInt32(index);
  1559. }
  1560. return NO_ERROR;
  1561. } break;
  1562. case GET_DEVICES_FOR_STREAM: {
  1563. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1564. audio_stream_type_t stream =
  1565. static_cast <audio_stream_type_t>(data.readInt32());
  1566. reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
  1567. return NO_ERROR;
  1568. } break;
  1569. case GET_OUTPUT_FOR_EFFECT: {
  1570. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1571. effect_descriptor_t desc = {};
  1572. if (data.read(&desc, sizeof(desc)) != NO_ERROR) {
  1573. android_errorWriteLog(0x534e4554, "73126106");
  1574. }
  1575. (void)sanitizeEffectDescriptor(&desc);
  1576. audio_io_handle_t output = getOutputForEffect(&desc);
  1577. reply->writeInt32(static_cast <int>(output));
  1578. return NO_ERROR;
  1579. } break;
  1580. case REGISTER_EFFECT: {
  1581. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1582. effect_descriptor_t desc = {};
  1583. if (data.read(&desc, sizeof(desc)) != NO_ERROR) {
  1584. android_errorWriteLog(0x534e4554, "73126106");
  1585. }
  1586. (void)sanitizeEffectDescriptor(&desc);
  1587. audio_io_handle_t io = data.readInt32();
  1588. uint32_t strategy = data.readInt32();
  1589. audio_session_t session = (audio_session_t) data.readInt32();
  1590. int id = data.readInt32();
  1591. reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
  1592. io,
  1593. strategy,
  1594. session,
  1595. id)));
  1596. return NO_ERROR;
  1597. } break;
  1598. case UNREGISTER_EFFECT: {
  1599. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1600. int id = data.readInt32();
  1601. reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
  1602. return NO_ERROR;
  1603. } break;
  1604. case SET_EFFECT_ENABLED: {
  1605. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1606. int id = data.readInt32();
  1607. bool enabled = static_cast <bool>(data.readInt32());
  1608. reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
  1609. return NO_ERROR;
  1610. } break;
  1611. case MOVE_EFFECTS_TO_IO: {
  1612. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1613. std::vector<int> ids;
  1614. int32_t size;
  1615. status_t status = data.readInt32(&size);
  1616. if (status != NO_ERROR) {
  1617. return status;
  1618. }
  1619. if (size > MAX_ITEMS_PER_LIST) {
  1620. return BAD_VALUE;
  1621. }
  1622. for (int32_t i = 0; i < size; i++) {
  1623. int id;
  1624. status = data.readInt32(&id);
  1625. if (status != NO_ERROR) {
  1626. return status;
  1627. }
  1628. ids.push_back(id);
  1629. }
  1630. audio_io_handle_t io = data.readInt32();
  1631. reply->writeInt32(static_cast <int32_t>(moveEffectsToIo(ids, io)));
  1632. return NO_ERROR;
  1633. } break;
  1634. case IS_STREAM_ACTIVE: {
  1635. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1636. audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
  1637. uint32_t inPastMs = (uint32_t)data.readInt32();
  1638. reply->writeInt32( isStreamActive(stream, inPastMs) );
  1639. return NO_ERROR;
  1640. } break;
  1641. case IS_STREAM_ACTIVE_REMOTELY: {
  1642. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1643. audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
  1644. uint32_t inPastMs = (uint32_t)data.readInt32();
  1645. reply->writeInt32( isStreamActiveRemotely(stream, inPastMs) );
  1646. return NO_ERROR;
  1647. } break;
  1648. case IS_SOURCE_ACTIVE: {
  1649. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1650. audio_source_t source = (audio_source_t) data.readInt32();
  1651. reply->writeInt32( isSourceActive(source));
  1652. return NO_ERROR;
  1653. }
  1654. case QUERY_DEFAULT_PRE_PROCESSING: {
  1655. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1656. audio_session_t audioSession = (audio_session_t) data.readInt32();
  1657. uint32_t count = data.readInt32();
  1658. if (count > AudioEffect::kMaxPreProcessing) {
  1659. count = AudioEffect::kMaxPreProcessing;
  1660. }
  1661. uint32_t retCount = count;
  1662. effect_descriptor_t *descriptors = new effect_descriptor_t[count]{};
  1663. status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
  1664. reply->writeInt32(status);
  1665. if (status != NO_ERROR && status != NO_MEMORY) {
  1666. retCount = 0;
  1667. }
  1668. reply->writeInt32(retCount);
  1669. if (retCount != 0) {
  1670. if (retCount < count) {
  1671. count = retCount;
  1672. }
  1673. reply->write(descriptors, sizeof(effect_descriptor_t) * count);
  1674. }
  1675. delete[] descriptors;
  1676. return status;
  1677. }
  1678. case IS_OFFLOAD_SUPPORTED: {
  1679. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1680. audio_offload_info_t info = {};
  1681. data.read(&info, sizeof(audio_offload_info_t));
  1682. bool isSupported = isOffloadSupported(info);
  1683. reply->writeInt32(isSupported);
  1684. return NO_ERROR;
  1685. }
  1686. case IS_DIRECT_OUTPUT_SUPPORTED: {
  1687. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1688. audio_config_base_t config = {};
  1689. audio_attributes_t attributes = {};
  1690. status_t status = data.read(&config, sizeof(audio_config_base_t));
  1691. if (status != NO_ERROR) return status;
  1692. status = data.read(&attributes, sizeof(audio_attributes_t));
  1693. if (status != NO_ERROR) return status;
  1694. reply->writeInt32(isDirectOutputSupported(config, attributes));
  1695. return NO_ERROR;
  1696. }
  1697. case LIST_AUDIO_PORTS: {
  1698. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1699. audio_port_role_t role = (audio_port_role_t)data.readInt32();
  1700. audio_port_type_t type = (audio_port_type_t)data.readInt32();
  1701. unsigned int numPortsReq = data.readInt32();
  1702. if (numPortsReq > MAX_ITEMS_PER_LIST) {
  1703. numPortsReq = MAX_ITEMS_PER_LIST;
  1704. }
  1705. unsigned int numPorts = numPortsReq;
  1706. struct audio_port *ports =
  1707. (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port));
  1708. if (ports == NULL) {
  1709. reply->writeInt32(NO_MEMORY);
  1710. reply->writeInt32(0);
  1711. return NO_ERROR;
  1712. }
  1713. unsigned int generation;
  1714. status_t status = listAudioPorts(role, type, &numPorts, ports, &generation);
  1715. reply->writeInt32(status);
  1716. reply->writeInt32(numPorts);
  1717. if (status == NO_ERROR) {
  1718. if (numPortsReq > numPorts) {
  1719. numPortsReq = numPorts;
  1720. }
  1721. reply->write(ports, numPortsReq * sizeof(struct audio_port));
  1722. reply->writeInt32(generation);
  1723. }
  1724. free(ports);
  1725. return NO_ERROR;
  1726. }
  1727. case GET_AUDIO_PORT: {
  1728. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1729. struct audio_port port = {};
  1730. if (data.read(&port, sizeof(struct audio_port)) != NO_ERROR) {
  1731. ALOGE("b/23912202");
  1732. }
  1733. status_t status = getAudioPort(&port);
  1734. reply->writeInt32(status);
  1735. if (status == NO_ERROR) {
  1736. reply->write(&port, sizeof(struct audio_port));
  1737. }
  1738. return NO_ERROR;
  1739. }
  1740. case CREATE_AUDIO_PATCH: {
  1741. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1742. struct audio_patch patch = {};
  1743. data.read(&patch, sizeof(struct audio_patch));
  1744. audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
  1745. if (data.read(&handle, sizeof(audio_patch_handle_t)) != NO_ERROR) {
  1746. ALOGE("b/23912202");
  1747. }
  1748. status_t status = createAudioPatch(&patch, &handle);
  1749. reply->writeInt32(status);
  1750. if (status == NO_ERROR) {
  1751. reply->write(&handle, sizeof(audio_patch_handle_t));
  1752. }
  1753. return NO_ERROR;
  1754. }
  1755. case RELEASE_AUDIO_PATCH: {
  1756. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1757. audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
  1758. data.read(&handle, sizeof(audio_patch_handle_t));
  1759. status_t status = releaseAudioPatch(handle);
  1760. reply->writeInt32(status);
  1761. return NO_ERROR;
  1762. }
  1763. case LIST_AUDIO_PATCHES: {
  1764. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1765. unsigned int numPatchesReq = data.readInt32();
  1766. if (numPatchesReq > MAX_ITEMS_PER_LIST) {
  1767. numPatchesReq = MAX_ITEMS_PER_LIST;
  1768. }
  1769. unsigned int numPatches = numPatchesReq;
  1770. struct audio_patch *patches =
  1771. (struct audio_patch *)calloc(numPatchesReq,
  1772. sizeof(struct audio_patch));
  1773. if (patches == NULL) {
  1774. reply->writeInt32(NO_MEMORY);
  1775. reply->writeInt32(0);
  1776. return NO_ERROR;
  1777. }
  1778. unsigned int generation;
  1779. status_t status = listAudioPatches(&numPatches, patches, &generation);
  1780. reply->writeInt32(status);
  1781. reply->writeInt32(numPatches);
  1782. if (status == NO_ERROR) {
  1783. if (numPatchesReq > numPatches) {
  1784. numPatchesReq = numPatches;
  1785. }
  1786. reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
  1787. reply->writeInt32(generation);
  1788. }
  1789. free(patches);
  1790. return NO_ERROR;
  1791. }
  1792. case SET_AUDIO_PORT_CONFIG: {
  1793. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1794. struct audio_port_config config = {};
  1795. data.read(&config, sizeof(struct audio_port_config));
  1796. (void)sanitizeAudioPortConfig(&config);
  1797. status_t status = setAudioPortConfig(&config);
  1798. reply->writeInt32(status);
  1799. return NO_ERROR;
  1800. }
  1801. case REGISTER_CLIENT: {
  1802. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1803. sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
  1804. data.readStrongBinder());
  1805. registerClient(client);
  1806. return NO_ERROR;
  1807. } break;
  1808. case SET_AUDIO_PORT_CALLBACK_ENABLED: {
  1809. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1810. setAudioPortCallbacksEnabled(data.readInt32() == 1);
  1811. return NO_ERROR;
  1812. } break;
  1813. case SET_AUDIO_VOLUME_GROUP_CALLBACK_ENABLED: {
  1814. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1815. setAudioVolumeGroupCallbacksEnabled(data.readInt32() == 1);
  1816. return NO_ERROR;
  1817. } break;
  1818. case ACQUIRE_SOUNDTRIGGER_SESSION: {
  1819. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1820. sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
  1821. data.readStrongBinder());
  1822. audio_session_t session = AUDIO_SESSION_NONE;
  1823. audio_io_handle_t ioHandle = AUDIO_IO_HANDLE_NONE;
  1824. audio_devices_t device = AUDIO_DEVICE_NONE;
  1825. status_t status = acquireSoundTriggerSession(&session, &ioHandle, &device);
  1826. reply->writeInt32(status);
  1827. if (status == NO_ERROR) {
  1828. reply->writeInt32(session);
  1829. reply->writeInt32(ioHandle);
  1830. reply->writeInt32(device);
  1831. }
  1832. return NO_ERROR;
  1833. } break;
  1834. case RELEASE_SOUNDTRIGGER_SESSION: {
  1835. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1836. sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
  1837. data.readStrongBinder());
  1838. audio_session_t session = (audio_session_t)data.readInt32();
  1839. status_t status = releaseSoundTriggerSession(session);
  1840. reply->writeInt32(status);
  1841. return NO_ERROR;
  1842. } break;
  1843. case GET_PHONE_STATE: {
  1844. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1845. reply->writeInt32((int32_t)getPhoneState());
  1846. return NO_ERROR;
  1847. } break;
  1848. case REGISTER_POLICY_MIXES: {
  1849. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1850. bool registration = data.readInt32() == 1;
  1851. Vector<AudioMix> mixes;
  1852. size_t size = (size_t)data.readInt32();
  1853. if (size > MAX_MIXES_PER_POLICY) {
  1854. size = MAX_MIXES_PER_POLICY;
  1855. }
  1856. for (size_t i = 0; i < size; i++) {
  1857. AudioMix mix;
  1858. if (mix.readFromParcel((Parcel*)&data) == NO_ERROR) {
  1859. mixes.add(mix);
  1860. }
  1861. }
  1862. status_t status = registerPolicyMixes(mixes, registration);
  1863. reply->writeInt32(status);
  1864. return NO_ERROR;
  1865. } break;
  1866. case START_AUDIO_SOURCE: {
  1867. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1868. struct audio_port_config source = {};
  1869. data.read(&source, sizeof(struct audio_port_config));
  1870. (void)sanitizeAudioPortConfig(&source);
  1871. audio_attributes_t attributes = {};
  1872. data.read(&attributes, sizeof(audio_attributes_t));
  1873. sanetizeAudioAttributes(&attributes);
  1874. audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE;
  1875. status_t status = startAudioSource(&source, &attributes, &portId);
  1876. reply->writeInt32(status);
  1877. reply->writeInt32(portId);
  1878. return NO_ERROR;
  1879. } break;
  1880. case STOP_AUDIO_SOURCE: {
  1881. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1882. audio_port_handle_t portId = (audio_port_handle_t) data.readInt32();
  1883. status_t status = stopAudioSource(portId);
  1884. reply->writeInt32(status);
  1885. return NO_ERROR;
  1886. } break;
  1887. case SET_MASTER_MONO: {
  1888. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1889. bool mono = static_cast<bool>(data.readInt32());
  1890. status_t status = setMasterMono(mono);
  1891. reply->writeInt32(status);
  1892. return NO_ERROR;
  1893. } break;
  1894. case GET_MASTER_MONO: {
  1895. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1896. bool mono;
  1897. status_t status = getMasterMono(&mono);
  1898. reply->writeInt32(status);
  1899. if (status == NO_ERROR) {
  1900. reply->writeInt32(static_cast<int32_t>(mono));
  1901. }
  1902. return NO_ERROR;
  1903. } break;
  1904. case GET_STREAM_VOLUME_DB: {
  1905. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1906. audio_stream_type_t stream =
  1907. static_cast <audio_stream_type_t>(data.readInt32());
  1908. int index = static_cast <int>(data.readInt32());
  1909. audio_devices_t device =
  1910. static_cast <audio_devices_t>(data.readUint32());
  1911. reply->writeFloat(getStreamVolumeDB(stream, index, device));
  1912. return NO_ERROR;
  1913. }
  1914. case GET_SURROUND_FORMATS: {
  1915. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1916. unsigned int numSurroundFormatsReq = data.readUint32();
  1917. if (numSurroundFormatsReq > MAX_ITEMS_PER_LIST) {
  1918. numSurroundFormatsReq = MAX_ITEMS_PER_LIST;
  1919. }
  1920. bool reported = data.readBool();
  1921. unsigned int numSurroundFormats = numSurroundFormatsReq;
  1922. audio_format_t *surroundFormats = (audio_format_t *)calloc(
  1923. numSurroundFormats, sizeof(audio_format_t));
  1924. bool *surroundFormatsEnabled = (bool *)calloc(numSurroundFormats, sizeof(bool));
  1925. if (numSurroundFormatsReq > 0 &&
  1926. (surroundFormats == NULL || surroundFormatsEnabled == NULL)) {
  1927. free(surroundFormats);
  1928. free(surroundFormatsEnabled);
  1929. reply->writeInt32(NO_MEMORY);
  1930. return NO_ERROR;
  1931. }
  1932. status_t status = getSurroundFormats(
  1933. &numSurroundFormats, surroundFormats, surroundFormatsEnabled, reported);
  1934. reply->writeInt32(status);
  1935. if (status == NO_ERROR) {
  1936. reply->writeUint32(numSurroundFormats);
  1937. if (numSurroundFormatsReq > numSurroundFormats) {
  1938. numSurroundFormatsReq = numSurroundFormats;
  1939. }
  1940. reply->write(surroundFormats, numSurroundFormatsReq * sizeof(audio_format_t));
  1941. reply->write(surroundFormatsEnabled, numSurroundFormatsReq * sizeof(bool));
  1942. }
  1943. free(surroundFormats);
  1944. free(surroundFormatsEnabled);
  1945. return NO_ERROR;
  1946. }
  1947. case SET_SURROUND_FORMAT_ENABLED: {
  1948. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1949. audio_format_t audioFormat = (audio_format_t) data.readInt32();
  1950. bool enabled = data.readBool();
  1951. status_t status = setSurroundFormatEnabled(audioFormat, enabled);
  1952. reply->writeInt32(status);
  1953. return NO_ERROR;
  1954. }
  1955. case GET_OFFLOAD_FORMATS_A2DP: {
  1956. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1957. std::vector<audio_format_t> encodingFormats;
  1958. status_t status = getHwOffloadEncodingFormatsSupportedForA2DP(&encodingFormats);
  1959. reply->writeInt32(status);
  1960. if (status != NO_ERROR) {
  1961. return NO_ERROR;
  1962. }
  1963. reply->writeUint32(static_cast<uint32_t>(encodingFormats.size()));
  1964. for (size_t i = 0; i < encodingFormats.size(); i++)
  1965. reply->writeInt32(static_cast<int32_t>(encodingFormats[i]));
  1966. return NO_ERROR;
  1967. }
  1968. case ADD_STREAM_DEFAULT_EFFECT: {
  1969. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1970. effect_uuid_t type;
  1971. status_t status = data.read(&type, sizeof(effect_uuid_t));
  1972. if (status != NO_ERROR) {
  1973. return status;
  1974. }
  1975. String16 opPackageName;
  1976. status = data.readString16(&opPackageName);
  1977. if (status != NO_ERROR) {
  1978. return status;
  1979. }
  1980. effect_uuid_t uuid;
  1981. status = data.read(&uuid, sizeof(effect_uuid_t));
  1982. if (status != NO_ERROR) {
  1983. return status;
  1984. }
  1985. int32_t priority = data.readInt32();
  1986. audio_usage_t usage = (audio_usage_t) data.readInt32();
  1987. audio_unique_id_t id = 0;
  1988. reply->writeInt32(static_cast <int32_t>(addStreamDefaultEffect(&type,
  1989. opPackageName,
  1990. &uuid,
  1991. priority,
  1992. usage,
  1993. &id)));
  1994. reply->writeInt32(id);
  1995. return NO_ERROR;
  1996. }
  1997. case REMOVE_STREAM_DEFAULT_EFFECT: {
  1998. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  1999. audio_unique_id_t id = static_cast<audio_unique_id_t>(data.readInt32());
  2000. reply->writeInt32(static_cast <int32_t>(removeStreamDefaultEffect(id)));
  2001. return NO_ERROR;
  2002. }
  2003. case ADD_SOURCE_DEFAULT_EFFECT: {
  2004. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  2005. effect_uuid_t type;
  2006. status_t status = data.read(&type, sizeof(effect_uuid_t));
  2007. if (status != NO_ERROR) {
  2008. return status;
  2009. }
  2010. String16 opPackageName;
  2011. status = data.readString16(&opPackageName);
  2012. if (status != NO_ERROR) {
  2013. return status;
  2014. }
  2015. effect_uuid_t uuid;
  2016. status = data.read(&uuid, sizeof(effect_uuid_t));
  2017. if (status != NO_ERROR) {
  2018. return status;
  2019. }
  2020. int32_t priority = data.readInt32();
  2021. audio_source_t source = (audio_source_t) data.readInt32();
  2022. audio_unique_id_t id = 0;
  2023. reply->writeInt32(static_cast <int32_t>(addSourceDefaultEffect(&type,
  2024. opPackageName,
  2025. &uuid,
  2026. priority,
  2027. source,
  2028. &id)));
  2029. reply->writeInt32(id);
  2030. return NO_ERROR;
  2031. }
  2032. case REMOVE_SOURCE_DEFAULT_EFFECT: {
  2033. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  2034. audio_unique_id_t id = static_cast<audio_unique_id_t>(data.readInt32());
  2035. reply->writeInt32(static_cast <int32_t>(removeSourceDefaultEffect(id)));
  2036. return NO_ERROR;
  2037. }
  2038. case SET_ASSISTANT_UID: {
  2039. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  2040. int32_t uid;
  2041. status_t status = data.readInt32(&uid);
  2042. if (status != NO_ERROR) {
  2043. return status;
  2044. }
  2045. status = setAssistantUid(uid);
  2046. reply->writeInt32(static_cast <int32_t>(status));
  2047. return NO_ERROR;
  2048. }
  2049. case SET_A11Y_SERVICES_UIDS: {
  2050. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  2051. std::vector<uid_t> uids;
  2052. int32_t size;
  2053. status_t status = data.readInt32(&size);
  2054. if (status != NO_ERROR) {
  2055. return status;
  2056. }
  2057. if (size > MAX_ITEMS_PER_LIST) {
  2058. size = MAX_ITEMS_PER_LIST;
  2059. }
  2060. for (int32_t i = 0; i < size; i++) {
  2061. int32_t uid;
  2062. status = data.readInt32(&uid);
  2063. if (status != NO_ERROR) {
  2064. return status;
  2065. }
  2066. uids.push_back(uid);
  2067. }
  2068. status = setA11yServicesUids(uids);
  2069. reply->writeInt32(static_cast <int32_t>(status));
  2070. return NO_ERROR;
  2071. }
  2072. case IS_HAPTIC_PLAYBACK_SUPPORTED: {
  2073. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  2074. bool isSupported = isHapticPlaybackSupported();
  2075. reply->writeBool(isSupported);
  2076. return NO_ERROR;
  2077. }
  2078. case SET_UID_DEVICE_AFFINITY: {
  2079. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  2080. const uid_t uid = (uid_t) data.readInt32();
  2081. Vector<AudioDeviceTypeAddr> devices;
  2082. size_t size = (size_t)data.readInt32();
  2083. for (size_t i = 0; i < size; i++) {
  2084. AudioDeviceTypeAddr device;
  2085. if (device.readFromParcel((Parcel*)&data) == NO_ERROR) {
  2086. devices.add(device);
  2087. }
  2088. }
  2089. status_t status = setUidDeviceAffinities(uid, devices);
  2090. reply->writeInt32(status);
  2091. return NO_ERROR;
  2092. }
  2093. case REMOVE_UID_DEVICE_AFFINITY: {
  2094. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  2095. const uid_t uid = (uid_t) data.readInt32();
  2096. status_t status = removeUidDeviceAffinities(uid);
  2097. reply->writeInt32(status);
  2098. return NO_ERROR;
  2099. }
  2100. case LIST_AUDIO_PRODUCT_STRATEGIES: {
  2101. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  2102. AudioProductStrategyVector strategies;
  2103. status_t status = listAudioProductStrategies(strategies);
  2104. reply->writeInt32(status);
  2105. if (status != NO_ERROR) {
  2106. return NO_ERROR;
  2107. }
  2108. size_t size = strategies.size();
  2109. size_t sizePosition = reply->dataPosition();
  2110. reply->writeInt32(size);
  2111. size_t finalSize = size;
  2112. for (size_t i = 0; i < size; i++) {
  2113. size_t position = reply->dataPosition();
  2114. if (strategies[i].writeToParcel(reply) != NO_ERROR) {
  2115. reply->setDataPosition(position);
  2116. finalSize--;
  2117. }
  2118. }
  2119. if (size != finalSize) {
  2120. size_t position = reply->dataPosition();
  2121. reply->setDataPosition(sizePosition);
  2122. reply->writeInt32(finalSize);
  2123. reply->setDataPosition(position);
  2124. }
  2125. return NO_ERROR;
  2126. }
  2127. case GET_STRATEGY_FOR_ATTRIBUTES: {
  2128. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  2129. AudioAttributes attributes;
  2130. status_t status = attributes.readFromParcel(&data);
  2131. if (status != NO_ERROR) {
  2132. return status;
  2133. }
  2134. product_strategy_t strategy;
  2135. status = getProductStrategyFromAudioAttributes(attributes, strategy);
  2136. reply->writeInt32(status);
  2137. if (status != NO_ERROR) {
  2138. return NO_ERROR;
  2139. }
  2140. reply->writeUint32(static_cast<int>(strategy));
  2141. return NO_ERROR;
  2142. }
  2143. case LIST_AUDIO_VOLUME_GROUPS: {
  2144. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  2145. AudioVolumeGroupVector groups;
  2146. status_t status = listAudioVolumeGroups(groups);
  2147. reply->writeInt32(status);
  2148. if (status != NO_ERROR) {
  2149. return NO_ERROR;
  2150. }
  2151. size_t size = groups.size();
  2152. size_t sizePosition = reply->dataPosition();
  2153. reply->writeInt32(size);
  2154. size_t finalSize = size;
  2155. for (size_t i = 0; i < size; i++) {
  2156. size_t position = reply->dataPosition();
  2157. if (groups[i].writeToParcel(reply) != NO_ERROR) {
  2158. reply->setDataPosition(position);
  2159. finalSize--;
  2160. }
  2161. }
  2162. if (size != finalSize) {
  2163. size_t position = reply->dataPosition();
  2164. reply->setDataPosition(sizePosition);
  2165. reply->writeInt32(finalSize);
  2166. reply->setDataPosition(position);
  2167. }
  2168. return NO_ERROR;
  2169. }
  2170. case GET_VOLUME_GROUP_FOR_ATTRIBUTES: {
  2171. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  2172. AudioAttributes attributes;
  2173. status_t status = attributes.readFromParcel(&data);
  2174. if (status != NO_ERROR) {
  2175. return status;
  2176. }
  2177. volume_group_t group;
  2178. status = getVolumeGroupFromAudioAttributes(attributes, group);
  2179. reply->writeInt32(status);
  2180. if (status != NO_ERROR) {
  2181. return NO_ERROR;
  2182. }
  2183. reply->writeUint32(static_cast<int>(group));
  2184. return NO_ERROR;
  2185. }
  2186. case SET_ALLOWED_CAPTURE_POLICY: {
  2187. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  2188. uid_t uid = data.readInt32();
  2189. audio_flags_mask_t flags = data.readInt32();
  2190. status_t status = setAllowedCapturePolicy(uid, flags);
  2191. reply->writeInt32(status);
  2192. return NO_ERROR;
  2193. }
  2194. case SET_RTT_ENABLED: {
  2195. CHECK_INTERFACE(IAudioPolicyService, data, reply);
  2196. bool enabled = static_cast<bool>(data.readInt32());
  2197. status_t status = setRttEnabled(enabled);
  2198. reply->writeInt32(status);
  2199. return NO_ERROR;
  2200. }
  2201. default:
  2202. return BBinder::onTransact(code, data, reply, flags);
  2203. }
  2204. }
  2205. /** returns true if string overflow was prevented by zero termination */
  2206. template <size_t size>
  2207. static bool preventStringOverflow(char (&s)[size]) {
  2208. if (strnlen(s, size) < size) return false;
  2209. s[size - 1] = '\0';
  2210. return true;
  2211. }
  2212. void BnAudioPolicyService::sanetizeAudioAttributes(audio_attributes_t* attr)
  2213. {
  2214. const size_t tagsMaxSize = AUDIO_ATTRIBUTES_TAGS_MAX_SIZE;
  2215. if (strnlen(attr->tags, tagsMaxSize) >= tagsMaxSize) {
  2216. android_errorWriteLog(0x534e4554, "68953950"); // SafetyNet logging
  2217. }
  2218. attr->tags[tagsMaxSize - 1] = '\0';
  2219. }
  2220. /** returns BAD_VALUE if sanitization was required. */
  2221. status_t BnAudioPolicyService::sanitizeEffectDescriptor(effect_descriptor_t* desc)
  2222. {
  2223. if (preventStringOverflow(desc->name)
  2224. | /* always */ preventStringOverflow(desc->implementor)) {
  2225. android_errorWriteLog(0x534e4554, "73126106"); // SafetyNet logging
  2226. return BAD_VALUE;
  2227. }
  2228. return NO_ERROR;
  2229. }
  2230. /** returns BAD_VALUE if sanitization was required. */
  2231. status_t BnAudioPolicyService::sanitizeAudioPortConfig(struct audio_port_config* config)
  2232. {
  2233. if (config->type == AUDIO_PORT_TYPE_DEVICE &&
  2234. preventStringOverflow(config->ext.device.address)) {
  2235. return BAD_VALUE;
  2236. }
  2237. return NO_ERROR;
  2238. }
  2239. // ----------------------------------------------------------------------------
  2240. } // namespace android