status_t AudioPolicyService::setAudioPortConfig(const struct audio_port_config *config) { Mutex::Autolock _l(mLock); if(!modifyAudioRoutingAllowed()) { return PERMISSION_DENIED; } if (mAudioPolicyManager == NULL) { return NO_INIT; } return mAudioPolicyManager->setAudioPortConfig(config); }
status_t AudioPolicyService::getAudioPort(struct audio_port *port) { Mutex::Autolock _l(mLock); if(!modifyAudioRoutingAllowed()) { return PERMISSION_DENIED; } if (mAudioPolicyManager == NULL) { return NO_INIT; } return mAudioPolicyManager->getAudioPort(port); }
status_t AudioPolicyService::releaseAudioPatch(audio_patch_handle_t handle) { Mutex::Autolock _l(mLock); if(!modifyAudioRoutingAllowed()) { return PERMISSION_DENIED; } if (mAudioPolicyManager == NULL) { return NO_INIT; } return mAudioPolicyManager->releaseAudioPatch(handle, IPCThreadState::self()->getCallingUid()); }
status_t AudioPolicyService::listAudioPatches(unsigned int *num_patches, struct audio_patch *patches, unsigned int *generation) { Mutex::Autolock _l(mLock); if(!modifyAudioRoutingAllowed()) { return PERMISSION_DENIED; } if (mAudioPolicyManager == NULL) { return NO_INIT; } return mAudioPolicyManager->listAudioPatches(num_patches, patches, generation); }
status_t AudioPolicyService::registerPolicyMixes(Vector<AudioMix> mixes, bool registration) { Mutex::Autolock _l(mLock); if(!modifyAudioRoutingAllowed()) { return PERMISSION_DENIED; } if (mAudioPolicyManager == NULL) { return NO_INIT; } if (registration) { return mAudioPolicyManager->registerPolicyMixes(mixes); } else { return mAudioPolicyManager->unregisterPolicyMixes(mixes); } }
status_t AudioPolicyService::listAudioPorts(audio_port_role_t role, audio_port_type_t type, unsigned int *num_ports, struct audio_port *ports, unsigned int *generation) { Mutex::Autolock _l(mLock); if(!modifyAudioRoutingAllowed()) { return PERMISSION_DENIED; } if (mAudioPolicyManager == NULL) { return NO_INIT; } return mAudioPolicyManager->listAudioPorts(role, type, num_ports, ports, generation); }
status_t AudioPolicyService::getInputForAttr(const audio_attributes_t *attr, audio_io_handle_t *input, audio_session_t session, uid_t uid, uint32_t samplingRate, audio_format_t format, audio_channel_mask_t channelMask, audio_input_flags_t flags, audio_port_handle_t selectedDeviceId) { if (mAudioPolicyManager == NULL) { return NO_INIT; } // already checked by client, but double-check in case the client wrapper is bypassed if (attr->source >= AUDIO_SOURCE_CNT && attr->source != AUDIO_SOURCE_HOTWORD && attr->source != AUDIO_SOURCE_FM_TUNER) { return BAD_VALUE; } if ((attr->source == AUDIO_SOURCE_HOTWORD) && !captureHotwordAllowed()) { return BAD_VALUE; } sp<AudioPolicyEffects>audioPolicyEffects; status_t status; AudioPolicyInterface::input_type_t inputType; // if the caller is us, trust the specified uid if (IPCThreadState::self()->getCallingPid() != getpid_cached || uid == (uid_t)-1) { uid_t newclientUid = IPCThreadState::self()->getCallingUid(); if (uid != (uid_t)-1 && uid != newclientUid) { ALOGW("%s uid %d tried to pass itself off as %d", __FUNCTION__, newclientUid, uid); } uid = newclientUid; } { Mutex::Autolock _l(mLock); // the audio_in_acoustics_t parameter is ignored by get_input() status = mAudioPolicyManager->getInputForAttr(attr, input, session, uid, samplingRate, format, channelMask, flags, selectedDeviceId, &inputType); audioPolicyEffects = mAudioPolicyEffects; if (status == NO_ERROR) { // enforce permission (if any) required for each type of input switch (inputType) { case AudioPolicyInterface::API_INPUT_LEGACY: break; case AudioPolicyInterface::API_INPUT_TELEPHONY_RX: // FIXME: use the same permission as for remote submix for now. case AudioPolicyInterface::API_INPUT_MIX_CAPTURE: if (!captureAudioOutputAllowed()) { ALOGE("getInputForAttr() permission denied: capture not allowed"); status = PERMISSION_DENIED; } break; case AudioPolicyInterface::API_INPUT_MIX_EXT_POLICY_REROUTE: if (!modifyAudioRoutingAllowed()) { ALOGE("getInputForAttr() permission denied: modify audio routing not allowed"); status = PERMISSION_DENIED; } break; case AudioPolicyInterface::API_INPUT_INVALID: default: LOG_ALWAYS_FATAL("getInputForAttr() encountered an invalid input type %d", (int)inputType); } } if (status != NO_ERROR) { if (status == PERMISSION_DENIED) { mAudioPolicyManager->releaseInput(*input, session); } return status; } } if (audioPolicyEffects != 0) { // create audio pre processors according to input source status_t status = audioPolicyEffects->addInputEffects(*input, attr->source, session); if (status != NO_ERROR && status != ALREADY_EXISTS) { ALOGW("Failed to add effects on input %d", *input); } } return NO_ERROR; }