Loading media/libaudiohal/impl/DeviceHalAidl.cpp +37 −14 Original line number Diff line number Diff line Loading @@ -903,15 +903,39 @@ status_t DeviceHalAidl::getSoundDoseInterface(const std::string& module, } status_t DeviceHalAidl::prepareToDisconnectExternalDevice(const struct audio_port_v7* port) { // There is not AIDL API defined for `prepareToDisconnectExternalDevice`. ALOGD("%p %s::%s", this, getClassName().c_str(), __func__); TIME_CHECK(); if (mModule == nullptr) return NO_INIT; if (port == nullptr) { return BAD_VALUE; } const bool isInput = VALUE_OR_RETURN_STATUS( ::aidl::android::portDirection(port->role, port->type)) == ::aidl::android::AudioPortDirection::INPUT; AudioPort aidlPort = VALUE_OR_RETURN_STATUS( ::aidl::android::legacy2aidl_audio_port_v7_AudioPort(*port, isInput)); if (aidlPort.ext.getTag() != AudioPortExt::device) { ALOGE("%s: provided port is not a device port (module %s): %s", __func__, mInstance.c_str(), aidlPort.toString().c_str()); return BAD_VALUE; } status_t status = NO_ERROR; { std::lock_guard l(mLock); status = mMapper.prepareToDisconnectExternalDevice(aidlPort); } if (status == UNKNOWN_TRANSACTION) { // If there is not AIDL API defined for `prepareToDisconnectExternalDevice`. // Call `setConnectedState` instead. // TODO(b/279824103): call prepareToDisconnectExternalDevice when it is added. RETURN_STATUS_IF_ERROR(setConnectedState(port, false /*connected*/)); std::lock_guard l(mLock); mDeviceDisconnectionNotified.insert(port->id); // Return that there was no error as otherwise the disconnection procedure will not be // considered complete for upper layers, and 'setConnectedState' will not be called again return OK; } else { return status; } } status_t DeviceHalAidl::setConnectedState(const struct audio_port_v7 *port, bool connected) { Loading @@ -925,11 +949,10 @@ status_t DeviceHalAidl::setConnectedState(const struct audio_port_v7 *port, bool std::lock_guard l(mLock); if (mDeviceDisconnectionNotified.erase(port->id) > 0) { // For device disconnection, APM will first call `prepareToDisconnectExternalDevice` // and then call `setConnectedState`. However, there is no API for // `prepareToDisconnectExternalDevice` yet. In that case, `setConnectedState` will be // called when calling `prepareToDisconnectExternalDevice`. Do not call to the HAL if // previous call is successful. Also remove the cache here to avoid a large cache after // a long run. // and then call `setConnectedState`. If `prepareToDisconnectExternalDevice` doesn't // exit, `setConnectedState` will be called when calling // `prepareToDisconnectExternalDevice`. Do not call to the HAL if previous call is // successful. Also remove the cache here to avoid a large cache after a long run. return OK; } } Loading media/libaudiohal/impl/Hal2AidlMapper.cpp +8 −0 Original line number Diff line number Diff line Loading @@ -666,6 +666,14 @@ bool Hal2AidlMapper::isPortBeingHeld(int32_t portId) { return false; } status_t Hal2AidlMapper::prepareToDisconnectExternalDevice(const AudioPort& devicePort) { auto portsIt = findPort(devicePort.ext.get<AudioPortExt::device>().device); if (portsIt == mPorts.end()) { return BAD_VALUE; } return statusTFromBinderStatus(mModule->prepareToDisconnectExternalDevice(portsIt->second.id)); } status_t Hal2AidlMapper::prepareToOpenStream( int32_t ioHandle, const AudioDevice& device, const AudioIoFlags& flags, AudioSource source, Cleanups* cleanups, AudioConfig* config, Loading media/libaudiohal/impl/Hal2AidlMapper.h +2 −0 Original line number Diff line number Diff line Loading @@ -72,6 +72,8 @@ class Hal2AidlMapper { return ::aidl::android::convertContainer(mRoutes, routes, converter); } status_t initialize(); status_t prepareToDisconnectExternalDevice( const ::aidl::android::media::audio::common::AudioPort& devicePort); // If the resulting 'mixPortConfig->id' is 0, that means the stream was not created, // and 'config' is a suggested config. status_t prepareToOpenStream( Loading Loading
media/libaudiohal/impl/DeviceHalAidl.cpp +37 −14 Original line number Diff line number Diff line Loading @@ -903,15 +903,39 @@ status_t DeviceHalAidl::getSoundDoseInterface(const std::string& module, } status_t DeviceHalAidl::prepareToDisconnectExternalDevice(const struct audio_port_v7* port) { // There is not AIDL API defined for `prepareToDisconnectExternalDevice`. ALOGD("%p %s::%s", this, getClassName().c_str(), __func__); TIME_CHECK(); if (mModule == nullptr) return NO_INIT; if (port == nullptr) { return BAD_VALUE; } const bool isInput = VALUE_OR_RETURN_STATUS( ::aidl::android::portDirection(port->role, port->type)) == ::aidl::android::AudioPortDirection::INPUT; AudioPort aidlPort = VALUE_OR_RETURN_STATUS( ::aidl::android::legacy2aidl_audio_port_v7_AudioPort(*port, isInput)); if (aidlPort.ext.getTag() != AudioPortExt::device) { ALOGE("%s: provided port is not a device port (module %s): %s", __func__, mInstance.c_str(), aidlPort.toString().c_str()); return BAD_VALUE; } status_t status = NO_ERROR; { std::lock_guard l(mLock); status = mMapper.prepareToDisconnectExternalDevice(aidlPort); } if (status == UNKNOWN_TRANSACTION) { // If there is not AIDL API defined for `prepareToDisconnectExternalDevice`. // Call `setConnectedState` instead. // TODO(b/279824103): call prepareToDisconnectExternalDevice when it is added. RETURN_STATUS_IF_ERROR(setConnectedState(port, false /*connected*/)); std::lock_guard l(mLock); mDeviceDisconnectionNotified.insert(port->id); // Return that there was no error as otherwise the disconnection procedure will not be // considered complete for upper layers, and 'setConnectedState' will not be called again return OK; } else { return status; } } status_t DeviceHalAidl::setConnectedState(const struct audio_port_v7 *port, bool connected) { Loading @@ -925,11 +949,10 @@ status_t DeviceHalAidl::setConnectedState(const struct audio_port_v7 *port, bool std::lock_guard l(mLock); if (mDeviceDisconnectionNotified.erase(port->id) > 0) { // For device disconnection, APM will first call `prepareToDisconnectExternalDevice` // and then call `setConnectedState`. However, there is no API for // `prepareToDisconnectExternalDevice` yet. In that case, `setConnectedState` will be // called when calling `prepareToDisconnectExternalDevice`. Do not call to the HAL if // previous call is successful. Also remove the cache here to avoid a large cache after // a long run. // and then call `setConnectedState`. If `prepareToDisconnectExternalDevice` doesn't // exit, `setConnectedState` will be called when calling // `prepareToDisconnectExternalDevice`. Do not call to the HAL if previous call is // successful. Also remove the cache here to avoid a large cache after a long run. return OK; } } Loading
media/libaudiohal/impl/Hal2AidlMapper.cpp +8 −0 Original line number Diff line number Diff line Loading @@ -666,6 +666,14 @@ bool Hal2AidlMapper::isPortBeingHeld(int32_t portId) { return false; } status_t Hal2AidlMapper::prepareToDisconnectExternalDevice(const AudioPort& devicePort) { auto portsIt = findPort(devicePort.ext.get<AudioPortExt::device>().device); if (portsIt == mPorts.end()) { return BAD_VALUE; } return statusTFromBinderStatus(mModule->prepareToDisconnectExternalDevice(portsIt->second.id)); } status_t Hal2AidlMapper::prepareToOpenStream( int32_t ioHandle, const AudioDevice& device, const AudioIoFlags& flags, AudioSource source, Cleanups* cleanups, AudioConfig* config, Loading
media/libaudiohal/impl/Hal2AidlMapper.h +2 −0 Original line number Diff line number Diff line Loading @@ -72,6 +72,8 @@ class Hal2AidlMapper { return ::aidl::android::convertContainer(mRoutes, routes, converter); } status_t initialize(); status_t prepareToDisconnectExternalDevice( const ::aidl::android::media::audio::common::AudioPort& devicePort); // If the resulting 'mixPortConfig->id' is 0, that means the stream was not created, // and 'config' is a suggested config. status_t prepareToOpenStream( Loading