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

Commit 058f94b4 authored by Ahaan Ugale's avatar Ahaan Ugale
Browse files

Enable HotwordDetectionService to access audioflinger.

HotwordDetectionService is an isolated service which ordinarily cannot
access audioflinger due to selinux restrictions on isolated processes.
To bypass those restrictions, the audioflinger binder is passed from
the system server to the HotwordDetectionService. This follows the
existing pattern of providing access to the ContentCapture service.

In T we *may* instead solve this at the selinux layer. For now, this
simpler approach is used.

Bug: 190011174
Test: manual - sample app can read audio (with a few other wip changes)
Change-Id: I86ac0820fd72676db4740658ffd096df3d20d30e
parent 632eedc2
Loading
Loading
Loading
Loading
+31 −8
Original line number Diff line number Diff line
@@ -71,6 +71,25 @@ class CaptureStateListenerImpl;
Mutex gSoundTriggerCaptureStateListenerLock;
sp<CaptureStateListenerImpl> gSoundTriggerCaptureStateListener = nullptr;

// Binder for the AudioFlinger service that's passed to this client process from the system server.
// This allows specific isolated processes to access the audio system. Currently used only for the
// HotwordDetectionService.
sp<IBinder> gAudioFlingerBinder = nullptr;

void AudioSystem::setAudioFlingerBinder(const sp<IBinder>& audioFlinger) {
    if (audioFlinger->getInterfaceDescriptor() != media::IAudioFlingerService::descriptor) {
        ALOGE("setAudioFlingerBinder: received a binder of type %s",
              String8(audioFlinger->getInterfaceDescriptor()).string());
        return;
    }
    Mutex::Autolock _l(gLock);
    if (gAudioFlinger != nullptr) {
        ALOGW("setAudioFlingerBinder: ignoring; AudioFlinger connection already established.");
        return;
    }
    gAudioFlingerBinder = audioFlinger;
}

// establish binder interface to AudioFlinger service
const sp<IAudioFlinger> AudioSystem::get_audio_flinger() {
    sp<IAudioFlinger> af;
@@ -79,8 +98,11 @@ const sp<IAudioFlinger> AudioSystem::get_audio_flinger() {
    {
        Mutex::Autolock _l(gLock);
        if (gAudioFlinger == 0) {
            sp<IServiceManager> sm = defaultServiceManager();
            sp<IBinder> binder;
            if (gAudioFlingerBinder != nullptr) {
                binder = gAudioFlingerBinder;
            } else {
                sp<IServiceManager> sm = defaultServiceManager();
                do {
                    binder = sm->getService(String16(IAudioFlinger::DEFAULT_SERVICE_NAME));
                    if (binder != 0)
@@ -88,6 +110,7 @@ const sp<IAudioFlinger> AudioSystem::get_audio_flinger() {
                    ALOGW("AudioFlinger not published, waiting...");
                    usleep(500000); // 0.5 s
                } while (true);
            }
            if (gAudioFlingerClient == NULL) {
                gAudioFlingerClient = new AudioFlingerClient();
            } else {
+5 −0
Original line number Diff line number Diff line
@@ -148,6 +148,11 @@ public:
    static void setRecordConfigCallback(record_config_callback);
    static void setRoutingCallback(routing_callback cb);

    // Sets the binder to use for accessing the AudioFlinger service. This enables the system server
    // to grant specific isolated processes access to the audio system. Currently used only for the
    // HotwordDetectionService.
    static void setAudioFlingerBinder(const sp<IBinder>& audioFlinger);

    // helper function to obtain AudioFlinger service handle
    static const sp<IAudioFlinger> get_audio_flinger();