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

Commit a5e165d3 authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

audiopolicy: Make fields of HwModule private

It's a good practice not to expose fields of the class.
Use getter / setter methods instead.

Test: compiles
Change-Id: I9d939d17fafdfff016a300d4f5a979bdc8414f2b
parent 22f920a8
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -112,7 +112,7 @@ public:
        mAvailableOutputDevices.add(mDefaultOutputDevices);
        mAvailableInputDevices.add(defaultInputDevice);

        module = new HwModule("primary");
        module = new HwModule(AUDIO_HARDWARE_MODULE_ID_PRIMARY);

        sp<OutputProfile> outProfile;
        outProfile = new OutputProfile(String8("primary"));
@@ -121,7 +121,7 @@ public:
                new AudioProfile(AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, 44100));
        outProfile->addSupportedDevice(mDefaultOutputDevices);
        outProfile->setFlags(AUDIO_OUTPUT_FLAG_PRIMARY);
        module->mOutputProfiles.add(outProfile);
        module->addOutputProfile(outProfile);

        sp<InputProfile> inProfile;
        inProfile = new InputProfile(String8("primary"));
@@ -129,7 +129,7 @@ public:
        inProfile->addAudioProfile(
                new AudioProfile(AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_IN_MONO, 8000));
        inProfile->addSupportedDevice(defaultInputDevice);
        module->mInputProfiles.add(inProfile);
        module->addInputProfile(inProfile);

        mHwModules.add(module);
    }
+4 −6
Original line number Diff line number Diff line
@@ -44,12 +44,10 @@ public:

    const char *getName() const { return mName.string(); }


    const DeviceVector &getDeclaredDevices() const { return mDeclaredDevices; }
    void setDeclaredDevices(const DeviceVector &devices);

    const InputProfileCollection &getInputProfiles() const { return mInputProfiles; }

    const OutputProfileCollection &getOutputProfiles() const { return mOutputProfiles; }

    void setProfiles(const IOProfileCollection &profiles);
@@ -76,6 +74,7 @@ public:
    status_t removeInputProfile(const String8& name);

    audio_module_handle_t getHandle() const { return mHandle; }
    void setHandle(audio_module_handle_t handle);

    sp<AudioPort> findPortByTagName(const String8 &tagName) const
    {
@@ -85,14 +84,13 @@ public:
    // TODO remove from here (split serialization)
    void dump(int fd);

private:
    void refreshSupportedDevices();

    const String8 mName; // base name of the audio HW module (primary, a2dp ...)
    audio_module_handle_t mHandle;
    OutputProfileCollection mOutputProfiles; // output profiles exposed by this module
    InputProfileCollection mInputProfiles;  // input profiles exposed by this module

private:
    void refreshSupportedDevices();

    uint32_t mHalVersion; // audio HAL API version
    DeviceVector mDeclaredDevices; // devices declared in audio_policy configuration file.
    AudioRouteVector mRoutes;
+3 −12
Original line number Diff line number Diff line
@@ -45,26 +45,17 @@ audio_port_handle_t AudioPort::getNextUniqueId()

audio_module_handle_t AudioPort::getModuleHandle() const
{
    if (mModule == 0) {
        return AUDIO_MODULE_HANDLE_NONE;
    }
    return mModule->mHandle;
    return mModule != 0 ? mModule->getHandle() : AUDIO_MODULE_HANDLE_NONE;
}

uint32_t AudioPort::getModuleVersionMajor() const
{
    if (mModule == 0) {
        return 0;
    }
    return mModule->getHalVersionMajor();
    return mModule != 0 ? mModule->getHalVersionMajor() : 0;
}

const char *AudioPort::getModuleName() const
{
    if (mModule == 0) {
        return "invalid module";
    }
    return mModule->getName();
    return mModule != 0 ? mModule->getName() : "invalid module";
}

void AudioPort::toAudioPort(struct audio_port *port) const
+3 −2
Original line number Diff line number Diff line
@@ -245,7 +245,8 @@ void DeviceDescriptor::toAudioPortConfig(struct audio_port_config *dstConfig,
    // without the test?
    // This has been demonstrated to NOT be true (at start up)
    // ALOG_ASSERT(mModule != NULL);
    dstConfig->ext.device.hw_module = mModule != 0 ? mModule->mHandle : AUDIO_MODULE_HANDLE_NONE;
    dstConfig->ext.device.hw_module =
            mModule != 0 ? mModule->getHandle() : AUDIO_MODULE_HANDLE_NONE;
    strncpy(dstConfig->ext.device.address, mAddress.string(), AUDIO_DEVICE_MAX_ADDRESS_LEN);
}

@@ -256,7 +257,7 @@ void DeviceDescriptor::toAudioPort(struct audio_port *port) const
    port->id = mId;
    toAudioPortConfig(&port->active_config);
    port->ext.device.type = mDeviceType;
    port->ext.device.hw_module = mModule->mHandle;
    port->ext.device.hw_module = mModule->getHandle();
    strncpy(port->ext.device.address, mAddress.string(), AUDIO_DEVICE_MAX_ADDRESS_LEN);
}

+8 −2
Original line number Diff line number Diff line
@@ -212,6 +212,12 @@ void HwModule::refreshSupportedDevices()
    }
}

void HwModule::setHandle(audio_module_handle_t handle) {
    ALOGW_IF(mHandle != AUDIO_MODULE_HANDLE_NONE,
            "HwModule handle is changing from %d to %d", mHandle, handle);
    mHandle = handle;
}

void HwModule::dump(int fd)
{
    const size_t SIZE = 256;
@@ -258,8 +264,8 @@ sp <HwModule> HwModuleCollection::getModuleFromName(const char *name) const
sp <HwModule> HwModuleCollection::getModuleForDevice(audio_devices_t device) const
{
    for (const auto& module : *this) {
        IOProfileCollection& profiles = audio_is_output_device(device) ?
                module->mOutputProfiles : module->mInputProfiles;
        const auto& profiles = audio_is_output_device(device) ?
                module->getOutputProfiles() : module->getInputProfiles();
        for (const auto& profile : profiles) {
            if (profile->supportDevice(device)) {
                return module;
Loading