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

Commit 516d398b authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

Implement use of Device.setConnectedState/_7_1 HAL method

Add 'Device.setConnectedState' to libaudiohal. It tries
to use Device.setConnectedState_7_1 when supported, or
fallbacks to Device.setConnectedState.

Remove direct use of setParameters from the framework
code. Add required plumbing between APM and AF.

Bug: 211601178
Test: on the device, check that HAL still receives the update
Change-Id: Ic9ac6fbea6ceea7db504d9c962392d90e21f57cb
parent d00fbcc3
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -803,6 +803,12 @@ int32_t AudioFlingerClientAdapter::getAAudioHardwareBurstMinUsec() {
    return result.value_or(0);
}

status_t AudioFlingerClientAdapter::setDeviceConnectedState(
        const struct audio_port_v7 *port, bool connected) {
    media::AudioPort aidlPort = VALUE_OR_RETURN_STATUS(
            legacy2aidl_audio_port_v7_AudioPort(*port));
    return statusTFromBinderStatus(mDelegate->setDeviceConnectedState(aidlPort, connected));
}

////////////////////////////////////////////////////////////////////////////////////////////////////
// AudioFlingerServerAdapter
@@ -1292,4 +1298,10 @@ Status AudioFlingerServerAdapter::getAAudioHardwareBurstMinUsec(int32_t* _aidl_r
    return Status::ok();
}

Status AudioFlingerServerAdapter::setDeviceConnectedState(
        const media::AudioPort& port, bool connected) {
    audio_port_v7 portLegacy = VALUE_OR_RETURN_BINDER(aidl2legacy_AudioPort_audio_port_v7(port));
    return Status::fromStatusT(mDelegate->setDeviceConnectedState(&portLegacy, connected));
}

} // namespace android
+2 −0
Original line number Diff line number Diff line
@@ -225,4 +225,6 @@ interface IAudioFlingerService {
    int getAAudioMixerBurstCount();

    int getAAudioHardwareBurstMinUsec();

    void setDeviceConnectedState(in AudioPort devicePort, boolean connected);
}
+5 −3
Original line number Diff line number Diff line
@@ -358,6 +358,8 @@ public:
    virtual int32_t getAAudioMixerBurstCount() = 0;

    virtual int32_t getAAudioHardwareBurstMinUsec() = 0;

    virtual status_t setDeviceConnectedState(const struct audio_port_v7 *port, bool connected) = 0;
};

/**
@@ -454,14 +456,12 @@ public:
    status_t setVibratorInfos(const std::vector<media::AudioVibratorInfo>& vibratorInfos) override;
    status_t updateSecondaryOutputs(
            const TrackSecondaryOutputsMap& trackSecondaryOutputs) override;

    status_t getMmapPolicyInfos(
            media::audio::common::AudioMMapPolicyType policyType,
            std::vector<media::audio::common::AudioMMapPolicyInfo> *policyInfos) override;

    int32_t getAAudioMixerBurstCount() override;

    int32_t getAAudioHardwareBurstMinUsec() override;
    status_t setDeviceConnectedState(const struct audio_port_v7 *port, bool connected) override;

private:
    const sp<media::IAudioFlingerService> mDelegate;
@@ -550,6 +550,7 @@ public:
            GET_MMAP_POLICY_INFOS = media::BnAudioFlingerService::TRANSACTION_getMmapPolicyInfos,
            GET_AAUDIO_MIXER_BURST_COUNT = media::BnAudioFlingerService::TRANSACTION_getAAudioMixerBurstCount,
            GET_AAUDIO_HARDWARE_BURST_MIN_USEC = media::BnAudioFlingerService::TRANSACTION_getAAudioHardwareBurstMinUsec,
            SET_DEVICE_CONNECTED_STATE = media::BnAudioFlingerService::TRANSACTION_setDeviceConnectedState,
        };

        /**
@@ -669,6 +670,7 @@ public:
            std::vector<media::audio::common::AudioMMapPolicyInfo> *_aidl_return) override;
    Status getAAudioMixerBurstCount(int32_t* _aidl_return) override;
    Status getAAudioHardwareBurstMinUsec(int32_t* _aidl_return) override;
    Status setDeviceConnectedState(const media::AudioPort& port, bool connected) override;

private:
    const sp<AudioFlingerServerAdapter::Delegate> mDelegate;
+26 −0
Original line number Diff line number Diff line
@@ -489,6 +489,32 @@ status_t DeviceHalHidl::removeDeviceEffect(
}
#endif

status_t DeviceHalHidl::setConnectedState(const struct audio_port_v7 *port, bool connected) {
    if (mDevice == 0) return NO_INIT;
#if MAJOR_VERSION == 7 && MINOR_VERSION == 1
    if (supportsSetConnectedState7_1) {
        AudioPort hidlPort;
        if (status_t result = HidlUtils::audioPortFromHal(*port, &hidlPort); result != NO_ERROR) {
            return result;
        }
        Return<Result> ret = mDevice->setConnectedState_7_1(hidlPort, connected);
        if (!ret.isOk() || ret != Result::NOT_SUPPORTED) {
            return processReturn("setConnectedState_7_1", ret);
        } else if (ret == Result::OK) {
            return NO_ERROR;
        }
        supportsSetConnectedState7_1 = false;
    }
#endif
    DeviceAddress hidlAddress;
    if (status_t result = CoreUtils::deviceAddressFromHal(
                    port->ext.device.type, port->ext.device.address, &hidlAddress);
            result != NO_ERROR) {
        return result;
    }
    return processReturn("setConnectedState", mDevice->setConnectedState(hidlAddress, connected));
}

status_t DeviceHalHidl::dump(int fd, const Vector<String16>& args) {
    if (mDevice == 0) return NO_INIT;
    native_handle_t* hidlHandle = native_handle_create(1, 0);
+4 −1
Original line number Diff line number Diff line
@@ -132,13 +132,16 @@ class DeviceHalHidl : public DeviceHalInterface, public ConversionHelperHidl
        return INVALID_OPERATION;
    }

    status_t setConnectedState(const struct audio_port_v7 *port, bool connected) override;

    status_t dump(int fd, const Vector<String16>& args) override;

  private:
    friend class DevicesFactoryHalHidl;
    sp<::android::hardware::audio::CPP_VERSION::IDevice> mDevice;
    sp<::android::hardware::audio::CPP_VERSION::IPrimaryDevice> mPrimaryDevice;
    // Null if it's not a primary device.
    sp<::android::hardware::audio::CPP_VERSION::IPrimaryDevice> mPrimaryDevice;
    bool supportsSetConnectedState7_1 = true;

    // Can not be constructed directly by clients.
    explicit DeviceHalHidl(const sp<::android::hardware::audio::CPP_VERSION::IDevice>& device);
Loading