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

Commit fac82021 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge changes Ie755c7c2,I2259105e am: d387cf7c

parents 2825fde2 d387cf7c
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -165,7 +165,8 @@ int main(int argc __unused, char **argv)
        const auto af = sp<AudioFlinger>::make();
        const auto afAdapter = sp<AudioFlingerServerAdapter>::make(af);
        ALOGD("%s: AudioFlinger created", __func__);
        AudioSystem::setAudioFlingerBinder(afAdapter);
        ALOGW_IF(AudioSystem::setLocalAudioFlinger(af) != OK,
                "%s: AudioSystem already has an AudioFlinger instance!", __func__);
        const auto aps = sp<AudioPolicyService>::make();
        ALOGD("%s: AudioPolicy created", __func__);

+33 −20
Original line number Diff line number Diff line
@@ -81,7 +81,7 @@ 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;
static sp<IBinder> gAudioFlingerBinder = nullptr;

void AudioSystem::setAudioFlingerBinder(const sp<IBinder>& audioFlinger) {
    if (audioFlinger->getInterfaceDescriptor() != media::IAudioFlingerService::descriptor) {
@@ -97,6 +97,15 @@ void AudioSystem::setAudioFlingerBinder(const sp<IBinder>& audioFlinger) {
    gAudioFlingerBinder = audioFlinger;
}

static sp<IAudioFlinger> gLocalAudioFlinger; // set if we are local.

status_t AudioSystem::setLocalAudioFlinger(const sp<IAudioFlinger>& af) {
    Mutex::Autolock _l(gLock);
    if (gAudioFlinger != nullptr) return INVALID_OPERATION;
    gLocalAudioFlinger = af;
    return OK;
}

// establish binder interface to AudioFlinger service
const sp<IAudioFlinger> AudioSystem::get_audio_flinger() {
    sp<IAudioFlinger> af;
@@ -104,7 +113,19 @@ const sp<IAudioFlinger> AudioSystem::get_audio_flinger() {
    bool reportNoError = false;
    {
        Mutex::Autolock _l(gLock);
        if (gAudioFlinger == 0) {
        if (gAudioFlinger != nullptr) {
            return gAudioFlinger;
        }

        if (gAudioFlingerClient == nullptr) {
            gAudioFlingerClient = sp<AudioFlingerClient>::make();
        } else {
            reportNoError = true;
        }

        if (gLocalAudioFlinger != nullptr) {
            gAudioFlinger = gLocalAudioFlinger;
        } else {
            sp<IBinder> binder;
            if (gAudioFlingerBinder != nullptr) {
                binder = gAudioFlingerBinder;
@@ -112,32 +133,24 @@ const sp<IAudioFlinger> AudioSystem::get_audio_flinger() {
                sp<IServiceManager> sm = defaultServiceManager();
                do {
                    binder = sm->getService(String16(IAudioFlinger::DEFAULT_SERVICE_NAME));
                    if (binder != 0)
                        break;
                    if (binder != nullptr) break;
                    ALOGW("AudioFlinger not published, waiting...");
                    usleep(500000); // 0.5 s
                } while (true);
            }
            if (gAudioFlingerClient == NULL) {
                gAudioFlingerClient = new AudioFlingerClient();
            } else {
                reportNoError = true;
            }
            binder->linkToDeath(gAudioFlingerClient);
            gAudioFlinger = new AudioFlingerClientAdapter(
                    interface_cast<media::IAudioFlingerService>(binder));
            LOG_ALWAYS_FATAL_IF(gAudioFlinger == 0);
            const auto afs = interface_cast<media::IAudioFlingerService>(binder);
            LOG_ALWAYS_FATAL_IF(afs == nullptr);
            gAudioFlinger = sp<AudioFlingerClientAdapter>::make(afs);
        }
        afc = gAudioFlingerClient;
        af = gAudioFlinger;
        // Make sure callbacks can be received by gAudioFlingerClient
        ProcessState::self()->startThreadPool();
    }
        af = gAudioFlinger;
    }
    if (afc != 0) {
        int64_t token = IPCThreadState::self()->clearCallingIdentity();
    const int64_t token = IPCThreadState::self()->clearCallingIdentity();
    af->registerClient(afc);
    IPCThreadState::self()->restoreCallingIdentity(token);
    }
    if (reportNoError) reportError(NO_ERROR);
    return af;
}
+4 −0
Original line number Diff line number Diff line
@@ -166,6 +166,10 @@ public:
    // HotwordDetectionService.
    static void setAudioFlingerBinder(const sp<IBinder>& audioFlinger);

    // Sets a local AudioFlinger interface to be used by AudioSystem.
    // This is used by audioserver main() to avoid binder AIDL translation.
    static status_t setLocalAudioFlinger(const sp<IAudioFlinger>& af);

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