Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6f6607e0 authored by Eric Laurent's avatar Eric Laurent Committed by android-build-merger
Browse files

Merge "soundtrigger: require RECORD_AUDIO permission for DSP hotword" into oc-mr1-dev

am: 78ae57b3

Change-Id: I320c31d1b629c311c90601bb309f0bf7bcbbfce0
parents 0154ccd5 78ae57b3
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -113,10 +113,15 @@ bool captureAudioOutputAllowed(pid_t pid, uid_t uid) {
    return ok;
}

bool captureHotwordAllowed() {
bool captureHotwordAllowed(pid_t pid, uid_t uid) {
    // CAPTURE_AUDIO_HOTWORD permission implies RECORD_AUDIO permission
    bool ok = recordingAllowed(String16(""), pid, uid);

    if (ok) {
        static const String16 sCaptureHotwordAllowed("android.permission.CAPTURE_AUDIO_HOTWORD");
        // IMPORTANT: Use PermissionCache - not a runtime permission and may not change.
    bool ok = PermissionCache::checkCallingPermission(sCaptureHotwordAllowed);
        ok = PermissionCache::checkCallingPermission(sCaptureHotwordAllowed);
    }
    if (!ok) ALOGE("android.permission.CAPTURE_AUDIO_HOTWORD");
    return ok;
}
+1 −1
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ extern pid_t getpid_cached;
bool isTrustedCallingUid(uid_t uid);
bool recordingAllowed(const String16& opPackageName, pid_t pid, uid_t uid);
bool captureAudioOutputAllowed(pid_t pid, uid_t uid);
bool captureHotwordAllowed();
bool captureHotwordAllowed(pid_t pid, uid_t uid);
bool settingsAllowed();
bool modifyAudioRoutingAllowed();
bool dumpAllowed();
+8 −7
Original line number Diff line number Diff line
@@ -289,13 +289,6 @@ status_t AudioPolicyService::getInputForAttr(const audio_attributes_t *attr,
        return BAD_VALUE;
    }

    if ((attr->source == AUDIO_SOURCE_HOTWORD) && !captureHotwordAllowed()) {
        return BAD_VALUE;
    }
    sp<AudioPolicyEffects>audioPolicyEffects;
    status_t status;
    AudioPolicyInterface::input_type_t inputType;

    bool updatePid = (pid == -1);
    const uid_t callingUid = IPCThreadState::self()->getCallingUid();
    if (!isTrustedCallingUid(callingUid)) {
@@ -313,7 +306,15 @@ status_t AudioPolicyService::getInputForAttr(const audio_attributes_t *attr,
        pid = callingPid;
    }

    if ((attr->source == AUDIO_SOURCE_HOTWORD) && !captureHotwordAllowed(pid, uid)) {
        return BAD_VALUE;
    }

    sp<AudioPolicyEffects>audioPolicyEffects;
    {
        status_t status;
        AudioPolicyInterface::input_type_t inputType;

        Mutex::Autolock _l(mLock);
        // the audio_in_acoustics_t parameter is ignored by get_input()
        status = mAudioPolicyManager->getInputForAttr(attr, input, session, uid,
+14 −7
Original line number Diff line number Diff line
@@ -89,7 +89,8 @@ status_t SoundTriggerHwService::listModules(struct sound_trigger_module_descript
                             uint32_t *numModules)
{
    ALOGV("listModules");
    if (!captureHotwordAllowed()) {
    if (!captureHotwordAllowed(IPCThreadState::self()->getCallingPid(),
                               IPCThreadState::self()->getCallingUid())) {
        return PERMISSION_DENIED;
    }

@@ -110,7 +111,8 @@ status_t SoundTriggerHwService::attach(const sound_trigger_module_handle_t handl
                        sp<ISoundTrigger>& moduleInterface)
{
    ALOGV("attach module %d", handle);
    if (!captureHotwordAllowed()) {
    if (!captureHotwordAllowed(IPCThreadState::self()->getCallingPid(),
                               IPCThreadState::self()->getCallingUid())) {
        return PERMISSION_DENIED;
    }

@@ -942,7 +944,8 @@ status_t SoundTriggerHwService::ModuleClient::dump(int fd __unused,

void SoundTriggerHwService::ModuleClient::detach() {
    ALOGV("detach()");
    if (!captureHotwordAllowed()) {
    if (!captureHotwordAllowed(IPCThreadState::self()->getCallingPid(),
                               IPCThreadState::self()->getCallingUid())) {
        return;
    }

@@ -965,7 +968,8 @@ status_t SoundTriggerHwService::ModuleClient::loadSoundModel(const sp<IMemory>&
                                sound_model_handle_t *handle)
{
    ALOGV("loadSoundModel() handle");
    if (!captureHotwordAllowed()) {
    if (!captureHotwordAllowed(IPCThreadState::self()->getCallingPid(),
                               IPCThreadState::self()->getCallingUid())) {
        return PERMISSION_DENIED;
    }

@@ -979,7 +983,8 @@ status_t SoundTriggerHwService::ModuleClient::loadSoundModel(const sp<IMemory>&
status_t SoundTriggerHwService::ModuleClient::unloadSoundModel(sound_model_handle_t handle)
{
    ALOGV("unloadSoundModel() model handle %d", handle);
    if (!captureHotwordAllowed()) {
    if (!captureHotwordAllowed(IPCThreadState::self()->getCallingPid(),
                               IPCThreadState::self()->getCallingUid())) {
        return PERMISSION_DENIED;
    }

@@ -994,7 +999,8 @@ status_t SoundTriggerHwService::ModuleClient::startRecognition(sound_model_handl
                                 const sp<IMemory>& dataMemory)
{
    ALOGV("startRecognition() model handle %d", handle);
    if (!captureHotwordAllowed()) {
    if (!captureHotwordAllowed(IPCThreadState::self()->getCallingPid(),
                               IPCThreadState::self()->getCallingUid())) {
        return PERMISSION_DENIED;
    }

@@ -1008,7 +1014,8 @@ status_t SoundTriggerHwService::ModuleClient::startRecognition(sound_model_handl
status_t SoundTriggerHwService::ModuleClient::stopRecognition(sound_model_handle_t handle)
{
    ALOGV("stopRecognition() model handle %d", handle);
    if (!captureHotwordAllowed()) {
    if (!captureHotwordAllowed(IPCThreadState::self()->getCallingPid(),
                               IPCThreadState::self()->getCallingUid())) {
        return PERMISSION_DENIED;
    }