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

Commit 88b30d2c authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

Plumb the notification about audio HAL services update to APM

AudioFlinger registers a callback with libaudiohal to receive
notifications when new HAL services get registered. It relays
the notification to AudioPolicyManager via AudioSystem /
IAudioPolicyService interface.

Because AF / APM only interact via Binder interfaces and APM's
interface gets registered later than AF's, the notification
from AF is made asynchronous.

Bug: 149854039
Test: audio test on a regular phone configuration
      audio test on a phone with MSD audio HAL module
Change-Id: I158e941b8f75e2a4614b9d84ca798b0f1f47aa6a
parent 88de22ff
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -792,6 +792,13 @@ const sp<IAudioPolicyService> AudioSystem::get_audio_policy_service()

// ---------------------------------------------------------------------------

void AudioSystem::onNewAudioModulesAvailable()
{
    const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
    if (aps == 0) return;
    aps->onNewAudioModulesAvailable();
}

status_t AudioSystem::setDeviceConnectionState(audio_devices_t device,
                                               audio_policy_dev_state_t state,
                                               const char *device_address,
+16 −1
Original line number Diff line number Diff line
@@ -113,6 +113,7 @@ enum {
    REMOVE_PREFERRED_DEVICE_FOR_PRODUCT_STRATEGY,
    GET_PREFERRED_DEVICE_FOR_PRODUCT_STRATEGY,
    GET_DEVICES_FOR_ATTRIBUTES,
    AUDIO_MODULES_UPDATED,  // oneway
};

#define MAX_ITEMS_PER_LIST 1024
@@ -1451,6 +1452,13 @@ public:
        }
        return NO_ERROR;
    }

    virtual void onNewAudioModulesAvailable()
    {
        Parcel data, reply;
        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
        remote()->transact(AUDIO_MODULES_UPDATED, data, &reply, IBinder::FLAG_ONEWAY);
    }
};

IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
@@ -1522,7 +1530,8 @@ status_t BnAudioPolicyService::onTransact(
        case REMOVE_PREFERRED_DEVICE_FOR_PRODUCT_STRATEGY:
        case GET_PREFERRED_DEVICE_FOR_PRODUCT_STRATEGY:
        case GET_DEVICES_FOR_ATTRIBUTES:
        case SET_ALLOWED_CAPTURE_POLICY: {
        case SET_ALLOWED_CAPTURE_POLICY:
        case AUDIO_MODULES_UPDATED: {
            if (!isServiceUid(IPCThreadState::self()->getCallingUid())) {
                ALOGW("%s: transaction %d received from PID %d unauthorized UID %d",
                      __func__, code, IPCThreadState::self()->getCallingPid(),
@@ -2672,6 +2681,12 @@ status_t BnAudioPolicyService::onTransact(
            return NO_ERROR;
        }

        case AUDIO_MODULES_UPDATED: {
            CHECK_INTERFACE(IAudioPolicyService, data, reply);
            onNewAudioModulesAvailable();
            return NO_ERROR;
        } break;

        default:
            return BBinder::onTransact(code, data, reply, flags);
    }
+1 −0
Original line number Diff line number Diff line
@@ -221,6 +221,7 @@ public:
    //
    // IAudioPolicyService interface (see AudioPolicyInterface for method descriptions)
    //
    static void onNewAudioModulesAvailable();
    static status_t setDeviceConnectionState(audio_devices_t device, audio_policy_dev_state_t state,
                                             const char *device_address, const char *device_name,
                                             audio_format_t encodedFormat);
+1 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ public:
    //
    // IAudioPolicyService interface (see AudioPolicyInterface for method descriptions)
    //
    virtual void onNewAudioModulesAvailable() = 0;
    virtual status_t setDeviceConnectionState(audio_devices_t device,
                                              audio_policy_dev_state_t state,
                                              const char *device_address,
+17 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@
#include <string>
#include <sys/time.h>
#include <sys/resource.h>
#include <thread>

#include <android/os/IExternalVibratorService.h>
#include <binder/IPCThreadState.h>
@@ -144,6 +145,19 @@ static sp<os::IExternalVibratorService> getExternalVibratorService() {
    return sExternalVibratorService;
}

class DevicesFactoryHalCallbackImpl : public DevicesFactoryHalCallback {
  public:
    void onNewDevicesAvailable() override {
        // Start a detached thread to execute notification in parallel.
        // This is done to prevent mutual blocking of audio_flinger and
        // audio_policy services during system initialization.
        std::thread notifier([]() {
            AudioSystem::onNewAudioModulesAvailable();
        });
        notifier.detach();
    }
};

// ----------------------------------------------------------------------------

std::string formatToString(audio_format_t format) {
@@ -227,6 +241,9 @@ void AudioFlinger::onFirstRef()
    mMode = AUDIO_MODE_NORMAL;

    gAudioFlinger = this;

    mDevicesFactoryHalCallback = new DevicesFactoryHalCallbackImpl;
    mDevicesFactoryHal->setCallbackOnce(mDevicesFactoryHalCallback);
}

status_t AudioFlinger::setAudioHalPids(const std::vector<pid_t>& pids) {
Loading