Merge changes from topic "upstream-hal-v7_1-p4"
* changes: audio VTS: Fix HAL device management Make AUDIO_USAGE_NOTIFICATION_EVENT available to HALs audio: Add android.hardware.audio[.common]@7.1-util modules audio: add Ultrasound materials to 7.1
This commit is contained in:
commit
7ed70a8033
14 changed files with 257 additions and 78 deletions
|
@ -86,6 +86,7 @@ package android.audio.policy.configuration.V7_1 {
|
|||
enum_constant public static final android.audio.policy.configuration.V7_1.AudioContentType AUDIO_CONTENT_TYPE_MUSIC;
|
||||
enum_constant public static final android.audio.policy.configuration.V7_1.AudioContentType AUDIO_CONTENT_TYPE_SONIFICATION;
|
||||
enum_constant public static final android.audio.policy.configuration.V7_1.AudioContentType AUDIO_CONTENT_TYPE_SPEECH;
|
||||
enum_constant public static final android.audio.policy.configuration.V7_1.AudioContentType AUDIO_CONTENT_TYPE_ULTRASOUND;
|
||||
enum_constant public static final android.audio.policy.configuration.V7_1.AudioContentType AUDIO_CONTENT_TYPE_UNKNOWN;
|
||||
}
|
||||
|
||||
|
@ -273,6 +274,7 @@ package android.audio.policy.configuration.V7_1 {
|
|||
enum_constant public static final android.audio.policy.configuration.V7_1.AudioInOutFlag AUDIO_INPUT_FLAG_MMAP_NOIRQ;
|
||||
enum_constant public static final android.audio.policy.configuration.V7_1.AudioInOutFlag AUDIO_INPUT_FLAG_RAW;
|
||||
enum_constant public static final android.audio.policy.configuration.V7_1.AudioInOutFlag AUDIO_INPUT_FLAG_SYNC;
|
||||
enum_constant public static final android.audio.policy.configuration.V7_1.AudioInOutFlag AUDIO_INPUT_FLAG_ULTRASOUND;
|
||||
enum_constant public static final android.audio.policy.configuration.V7_1.AudioInOutFlag AUDIO_INPUT_FLAG_VOIP_TX;
|
||||
enum_constant public static final android.audio.policy.configuration.V7_1.AudioInOutFlag AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD;
|
||||
enum_constant public static final android.audio.policy.configuration.V7_1.AudioInOutFlag AUDIO_OUTPUT_FLAG_DEEP_BUFFER;
|
||||
|
@ -290,6 +292,7 @@ package android.audio.policy.configuration.V7_1 {
|
|||
enum_constant public static final android.audio.policy.configuration.V7_1.AudioInOutFlag AUDIO_OUTPUT_FLAG_SPATIALIZER;
|
||||
enum_constant public static final android.audio.policy.configuration.V7_1.AudioInOutFlag AUDIO_OUTPUT_FLAG_SYNC;
|
||||
enum_constant public static final android.audio.policy.configuration.V7_1.AudioInOutFlag AUDIO_OUTPUT_FLAG_TTS;
|
||||
enum_constant public static final android.audio.policy.configuration.V7_1.AudioInOutFlag AUDIO_OUTPUT_FLAG_ULTRASOUND;
|
||||
enum_constant public static final android.audio.policy.configuration.V7_1.AudioInOutFlag AUDIO_OUTPUT_FLAG_VOIP_RX;
|
||||
}
|
||||
|
||||
|
@ -314,6 +317,7 @@ package android.audio.policy.configuration.V7_1 {
|
|||
enum_constant public static final android.audio.policy.configuration.V7_1.AudioSource AUDIO_SOURCE_HOTWORD;
|
||||
enum_constant public static final android.audio.policy.configuration.V7_1.AudioSource AUDIO_SOURCE_MIC;
|
||||
enum_constant public static final android.audio.policy.configuration.V7_1.AudioSource AUDIO_SOURCE_REMOTE_SUBMIX;
|
||||
enum_constant public static final android.audio.policy.configuration.V7_1.AudioSource AUDIO_SOURCE_ULTRASOUND;
|
||||
enum_constant public static final android.audio.policy.configuration.V7_1.AudioSource AUDIO_SOURCE_UNPROCESSED;
|
||||
enum_constant public static final android.audio.policy.configuration.V7_1.AudioSource AUDIO_SOURCE_VOICE_CALL;
|
||||
enum_constant public static final android.audio.policy.configuration.V7_1.AudioSource AUDIO_SOURCE_VOICE_COMMUNICATION;
|
||||
|
@ -355,6 +359,7 @@ package android.audio.policy.configuration.V7_1 {
|
|||
enum_constant public static final android.audio.policy.configuration.V7_1.AudioUsage AUDIO_USAGE_GAME;
|
||||
enum_constant public static final android.audio.policy.configuration.V7_1.AudioUsage AUDIO_USAGE_MEDIA;
|
||||
enum_constant public static final android.audio.policy.configuration.V7_1.AudioUsage AUDIO_USAGE_NOTIFICATION;
|
||||
enum_constant public static final android.audio.policy.configuration.V7_1.AudioUsage AUDIO_USAGE_NOTIFICATION_EVENT;
|
||||
enum_constant public static final android.audio.policy.configuration.V7_1.AudioUsage AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE;
|
||||
enum_constant public static final android.audio.policy.configuration.V7_1.AudioUsage AUDIO_USAGE_SAFETY;
|
||||
enum_constant public static final android.audio.policy.configuration.V7_1.AudioUsage AUDIO_USAGE_UNKNOWN;
|
||||
|
|
|
@ -180,6 +180,7 @@
|
|||
<xs:enumeration value="AUDIO_OUTPUT_FLAG_INCALL_MUSIC" />
|
||||
<xs:enumeration value="AUDIO_OUTPUT_FLAG_GAPLESS_OFFLOAD" />
|
||||
<xs:enumeration value="AUDIO_OUTPUT_FLAG_SPATIALIZER" />
|
||||
<xs:enumeration value="AUDIO_OUTPUT_FLAG_ULTRASOUND" />
|
||||
<xs:enumeration value="AUDIO_INPUT_FLAG_FAST" />
|
||||
<xs:enumeration value="AUDIO_INPUT_FLAG_HW_HOTWORD" />
|
||||
<xs:enumeration value="AUDIO_INPUT_FLAG_RAW" />
|
||||
|
@ -188,6 +189,7 @@
|
|||
<xs:enumeration value="AUDIO_INPUT_FLAG_VOIP_TX" />
|
||||
<xs:enumeration value="AUDIO_INPUT_FLAG_HW_AV_SYNC" />
|
||||
<xs:enumeration value="AUDIO_INPUT_FLAG_DIRECT" />
|
||||
<xs:enumeration value="AUDIO_INPUT_FLAG_ULTRASOUND" />
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
<xs:simpleType name="audioInOutFlags">
|
||||
|
@ -441,6 +443,7 @@
|
|||
<xs:enumeration value="AUDIO_USAGE_ALARM" />
|
||||
<xs:enumeration value="AUDIO_USAGE_NOTIFICATION" />
|
||||
<xs:enumeration value="AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE" />
|
||||
<xs:enumeration value="AUDIO_USAGE_NOTIFICATION_EVENT" />
|
||||
<xs:enumeration value="AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY" />
|
||||
<xs:enumeration value="AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE" />
|
||||
<xs:enumeration value="AUDIO_USAGE_ASSISTANCE_SONIFICATION" />
|
||||
|
@ -471,6 +474,7 @@
|
|||
<xs:enumeration value="AUDIO_CONTENT_TYPE_MUSIC"/>
|
||||
<xs:enumeration value="AUDIO_CONTENT_TYPE_MOVIE"/>
|
||||
<xs:enumeration value="AUDIO_CONTENT_TYPE_SONIFICATION"/>
|
||||
<xs:enumeration value="AUDIO_CONTENT_TYPE_ULTRASOUND"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
<xs:simpleType name="samplingRates">
|
||||
|
@ -742,6 +746,7 @@
|
|||
<xs:enumeration value="AUDIO_SOURCE_ECHO_REFERENCE"/>
|
||||
<xs:enumeration value="AUDIO_SOURCE_FM_TUNER"/>
|
||||
<xs:enumeration value="AUDIO_SOURCE_HOTWORD"/>
|
||||
<xs:enumeration value="AUDIO_SOURCE_ULTRASOUND"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
<!-- Enum values of device_category from Volume.h. -->
|
||||
|
|
|
@ -485,8 +485,12 @@ status_t HidlUtils::audioGainToHal(const AudioGain& gain, struct audio_gain* hal
|
|||
status_t HidlUtils::audioUsageFromHal(audio_usage_t halUsage, AudioUsage* usage) {
|
||||
if (halUsage == AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST ||
|
||||
halUsage == AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT ||
|
||||
#if MAJOR_VERSION == 7 && MINOR_VERSION == 1
|
||||
halUsage == AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED) {
|
||||
#else
|
||||
halUsage == AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED ||
|
||||
halUsage == AUDIO_USAGE_NOTIFICATION_EVENT) {
|
||||
#endif
|
||||
halUsage = AUDIO_USAGE_NOTIFICATION;
|
||||
}
|
||||
*usage = audio_usage_to_string(halUsage);
|
||||
|
|
|
@ -157,6 +157,28 @@ cc_library {
|
|||
],
|
||||
}
|
||||
|
||||
cc_library {
|
||||
name: "android.hardware.audio.common@7.1-util",
|
||||
defaults: ["android.hardware.audio.common-util_default"],
|
||||
srcs: [
|
||||
"7.0/HidlUtils.cpp",
|
||||
"HidlUtilsCommon.cpp",
|
||||
"UuidUtils.cpp",
|
||||
],
|
||||
shared_libs: [
|
||||
"android.hardware.audio.common@7.0",
|
||||
"android.hardware.audio.common@7.1-enums",
|
||||
"libbase",
|
||||
],
|
||||
cflags: [
|
||||
"-DMAJOR_VERSION=7",
|
||||
"-DMINOR_VERSION=1",
|
||||
"-DCOMMON_TYPES_MINOR_VERSION=0",
|
||||
"-DCORE_TYPES_MINOR_VERSION=0",
|
||||
"-include common/all-versions/VersionMacro.h",
|
||||
],
|
||||
}
|
||||
|
||||
// Note: this isn't a VTS test, but rather a unit test
|
||||
// to verify correctness of conversion utilities.
|
||||
cc_test {
|
||||
|
@ -214,3 +236,35 @@ cc_test {
|
|||
|
||||
test_suites: ["device-tests"],
|
||||
}
|
||||
|
||||
cc_test {
|
||||
name: "android.hardware.audio.common@7.1-util_tests",
|
||||
defaults: ["android.hardware.audio.common-util_default"],
|
||||
|
||||
srcs: ["tests/hidlutils_tests.cpp"],
|
||||
|
||||
// Use static linking to allow running in presubmit on
|
||||
// targets that don't have HAL V7.1.
|
||||
static_libs: [
|
||||
"android.hardware.audio.common@7.1-enums",
|
||||
"android.hardware.audio.common@7.1-util",
|
||||
"android.hardware.audio.common@7.0",
|
||||
],
|
||||
|
||||
shared_libs: [
|
||||
"libbase",
|
||||
"libxml2",
|
||||
],
|
||||
|
||||
cflags: [
|
||||
"-Werror",
|
||||
"-Wall",
|
||||
"-DMAJOR_VERSION=7",
|
||||
"-DMINOR_VERSION=1",
|
||||
"-DCOMMON_TYPES_MINOR_VERSION=0",
|
||||
"-DCORE_TYPES_MINOR_VERSION=0",
|
||||
"-include common/all-versions/VersionMacro.h",
|
||||
],
|
||||
|
||||
test_suites: ["device-tests"],
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace android {
|
|||
namespace hardware {
|
||||
namespace audio {
|
||||
namespace common {
|
||||
namespace CPP_VERSION {
|
||||
namespace COMMON_TYPES_CPP_VERSION {
|
||||
namespace implementation {
|
||||
|
||||
status_t HidlUtils::audioPortConfigsFromHal(unsigned int numHalConfigs,
|
||||
|
@ -51,7 +51,7 @@ status_t HidlUtils::audioPortConfigsToHal(const hidl_vec<AudioPortConfig>& confi
|
|||
}
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace CPP_VERSION
|
||||
} // namespace COMMON_TYPES_CPP_VERSION
|
||||
} // namespace common
|
||||
} // namespace audio
|
||||
} // namespace hardware
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
},
|
||||
{
|
||||
"name": "android.hardware.audio.common@7.0-util_tests"
|
||||
},
|
||||
{
|
||||
"name": "android.hardware.audio.common@7.1-util_tests"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#include <log/log.h>
|
||||
|
||||
#include <HidlUtils.h>
|
||||
#include <android_audio_policy_configuration_V7_0-enums.h>
|
||||
#include PATH(APM_XSD_ENUMS_H_FILENAME)
|
||||
#include <system/audio.h>
|
||||
#include <xsdc/XsdcSupport.h>
|
||||
|
||||
|
@ -32,7 +32,7 @@ using ::android::hardware::hidl_vec;
|
|||
using namespace ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION;
|
||||
using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::implementation::HidlUtils;
|
||||
namespace xsd {
|
||||
using namespace ::android::audio::policy::configuration::V7_0;
|
||||
using namespace ::android::audio::policy::configuration::CPP_VERSION;
|
||||
}
|
||||
|
||||
static constexpr audio_channel_mask_t kInvalidHalChannelMask = AUDIO_CHANNEL_INVALID;
|
||||
|
|
|
@ -168,10 +168,10 @@ cc_defaults {
|
|||
shared_libs: [
|
||||
"android.hardware.audio@7.0",
|
||||
"android.hardware.audio@7.1",
|
||||
"android.hardware.audio@7.0-util",
|
||||
"android.hardware.audio@7.1-util",
|
||||
"android.hardware.audio.common@7.0",
|
||||
"android.hardware.audio.common@7.1-enums",
|
||||
"android.hardware.audio.common@7.0-util",
|
||||
"android.hardware.audio.common@7.1-util",
|
||||
"libbase",
|
||||
],
|
||||
cflags: [
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
{
|
||||
"name": "android.hardware.audio@7.0-util_tests"
|
||||
},
|
||||
{
|
||||
"name": "android.hardware.audio@7.1-util_tests"
|
||||
},
|
||||
{
|
||||
"name": "HalAudioV6_0GeneratorTest"
|
||||
},
|
||||
|
|
|
@ -112,6 +112,25 @@ cc_library {
|
|||
],
|
||||
}
|
||||
|
||||
cc_library {
|
||||
name: "android.hardware.audio@7.1-util",
|
||||
defaults: ["android.hardware.audio-util_default"],
|
||||
shared_libs: [
|
||||
"android.hardware.audio.common@7.0",
|
||||
"android.hardware.audio.common@7.1-enums",
|
||||
"android.hardware.audio.common@7.1-util",
|
||||
"android.hardware.audio@7.1",
|
||||
"libbase",
|
||||
],
|
||||
cflags: [
|
||||
"-DMAJOR_VERSION=7",
|
||||
"-DMINOR_VERSION=1",
|
||||
"-DCOMMON_TYPES_MINOR_VERSION=0",
|
||||
"-DCORE_TYPES_MINOR_VERSION=0",
|
||||
"-include common/all-versions/VersionMacro.h",
|
||||
],
|
||||
}
|
||||
|
||||
// Note: this isn't a VTS test, but rather a unit test
|
||||
// to verify correctness of conversion utilities.
|
||||
cc_test {
|
||||
|
@ -145,3 +164,37 @@ cc_test {
|
|||
|
||||
test_suites: ["device-tests"],
|
||||
}
|
||||
|
||||
cc_test {
|
||||
name: "android.hardware.audio@7.1-util_tests",
|
||||
defaults: ["android.hardware.audio-util_default"],
|
||||
|
||||
srcs: ["tests/coreutils_tests.cpp"],
|
||||
|
||||
// Use static linking to allow running in presubmit on
|
||||
// targets that don't have HAL V7.1.
|
||||
static_libs: [
|
||||
"android.hardware.audio.common@7.0",
|
||||
"android.hardware.audio.common@7.1-enums",
|
||||
"android.hardware.audio.common@7.1-util",
|
||||
"android.hardware.audio@7.1",
|
||||
"android.hardware.audio@7.1-util",
|
||||
],
|
||||
|
||||
shared_libs: [
|
||||
"libbase",
|
||||
"libxml2",
|
||||
],
|
||||
|
||||
cflags: [
|
||||
"-Werror",
|
||||
"-Wall",
|
||||
"-DMAJOR_VERSION=7",
|
||||
"-DMINOR_VERSION=1",
|
||||
"-DCOMMON_TYPES_MINOR_VERSION=0",
|
||||
"-DCORE_TYPES_MINOR_VERSION=0",
|
||||
"-include common/all-versions/VersionMacro.h",
|
||||
],
|
||||
|
||||
test_suites: ["device-tests"],
|
||||
}
|
||||
|
|
|
@ -22,18 +22,18 @@
|
|||
#define LOG_TAG "CoreUtils_Test"
|
||||
#include <log/log.h>
|
||||
|
||||
#include <android_audio_policy_configuration_V7_0-enums.h>
|
||||
#include PATH(APM_XSD_ENUMS_H_FILENAME)
|
||||
#include <system/audio.h>
|
||||
#include <util/CoreUtils.h>
|
||||
#include <xsdc/XsdcSupport.h>
|
||||
|
||||
using namespace android;
|
||||
using namespace ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION;
|
||||
using namespace ::android::hardware::audio::CPP_VERSION;
|
||||
using namespace ::android::hardware::audio::CORE_TYPES_CPP_VERSION;
|
||||
using ::android::hardware::hidl_vec;
|
||||
using ::android::hardware::audio::CPP_VERSION::implementation::CoreUtils;
|
||||
using ::android::hardware::audio::CORE_TYPES_CPP_VERSION::implementation::CoreUtils;
|
||||
namespace xsd {
|
||||
using namespace ::android::audio::policy::configuration::V7_0;
|
||||
using namespace ::android::audio::policy::configuration::CPP_VERSION;
|
||||
}
|
||||
|
||||
static constexpr audio_channel_mask_t kInvalidHalChannelMask = AUDIO_CHANNEL_INVALID;
|
||||
|
|
|
@ -28,8 +28,7 @@ TEST_P(AudioHidlTest, OpenPrimaryDeviceUsingGetDevice) {
|
|||
if (getDeviceName() != DeviceManager::kPrimaryDevice) {
|
||||
GTEST_SKIP() << "No primary device on this factory"; // returns
|
||||
}
|
||||
EXPECT_TRUE(
|
||||
DeviceManager::getInstance().reset(getFactoryName(), DeviceManager::kPrimaryDevice));
|
||||
EXPECT_TRUE(DeviceManager::getInstance().resetPrimary(getFactoryName()));
|
||||
|
||||
// Must use IDevicesFactory directly because DeviceManager always uses
|
||||
// the latest interfaces version and corresponding methods for opening
|
||||
|
|
|
@ -195,7 +195,7 @@ cc_test {
|
|||
"android.hardware.audio.common@7.0",
|
||||
"android.hardware.audio.common@7.0-enums",
|
||||
"android.hardware.audio.common@7.1-enums",
|
||||
"android.hardware.audio.common@7.0-util",
|
||||
"android.hardware.audio.common@7.1-util",
|
||||
],
|
||||
cflags: [
|
||||
"-DMAJOR_VERSION=7",
|
||||
|
|
|
@ -96,40 +96,83 @@ class DevicesFactoryManager
|
|||
}
|
||||
};
|
||||
|
||||
using FactoryAndDevice = std::tuple<std::string, std::string>;
|
||||
class DeviceManager : public InterfaceManager<DeviceManager, FactoryAndDevice, IDevice> {
|
||||
namespace impl {
|
||||
|
||||
class PrimaryDeviceManager
|
||||
: public InterfaceManager<PrimaryDeviceManager, std::string, IPrimaryDevice> {
|
||||
public:
|
||||
static DeviceManager& getInstance() {
|
||||
static DeviceManager instance;
|
||||
return instance;
|
||||
static sp<IPrimaryDevice> createInterfaceInstance(const std::string& factoryName) {
|
||||
sp<IDevicesFactory> factory = DevicesFactoryManager::getInstance().get(factoryName);
|
||||
return openPrimaryDevice(factory);
|
||||
}
|
||||
|
||||
bool reset(const std::string& factoryName) __attribute__((warn_unused_result)) {
|
||||
#if MAJOR_VERSION <= 5
|
||||
return InterfaceManager::reset(factoryName, true);
|
||||
#elif MAJOR_VERSION >= 6
|
||||
{
|
||||
sp<IPrimaryDevice> device = getExisting(factoryName);
|
||||
if (device != nullptr) {
|
||||
auto ret = device->close();
|
||||
ALOGE_IF(!ret.isOk(), "PrimaryDevice %s close failed: %s", factoryName.c_str(),
|
||||
ret.description().c_str());
|
||||
}
|
||||
}
|
||||
return InterfaceManager::reset(factoryName, false);
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
static sp<IPrimaryDevice> openPrimaryDevice(const sp<IDevicesFactory>& factory) {
|
||||
if (factory == nullptr) return {};
|
||||
Result result;
|
||||
sp<IPrimaryDevice> primaryDevice;
|
||||
#if !(MAJOR_VERSION == 7 && MINOR_VERSION == 1)
|
||||
sp<IDevice> device;
|
||||
#if MAJOR_VERSION == 2
|
||||
auto ret = factory->openDevice(IDevicesFactory::Device::PRIMARY, returnIn(result, device));
|
||||
if (ret.isOk() && result == Result::OK && device != nullptr) {
|
||||
primaryDevice = IPrimaryDevice::castFrom(device);
|
||||
}
|
||||
#elif MAJOR_VERSION >= 4
|
||||
auto ret = factory->openPrimaryDevice(returnIn(result, device));
|
||||
if (ret.isOk() && result == Result::OK && device != nullptr) {
|
||||
primaryDevice = IPrimaryDevice::castFrom(device);
|
||||
}
|
||||
#endif
|
||||
if (!ret.isOk() || result != Result::OK || primaryDevice == nullptr) {
|
||||
ALOGW("Primary device can not be opened, transaction: %s, result %d, device %p",
|
||||
ret.description().c_str(), result, device.get());
|
||||
return nullptr;
|
||||
}
|
||||
#else // V7.1
|
||||
auto ret = factory->openPrimaryDevice_7_1(returnIn(result, primaryDevice));
|
||||
if (!ret.isOk() || result != Result::OK) {
|
||||
ALOGW("Primary device can not be opened, transaction: %s, result %d",
|
||||
ret.description().c_str(), result);
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
return primaryDevice;
|
||||
}
|
||||
};
|
||||
|
||||
using FactoryAndDevice = std::tuple<std::string, std::string>;
|
||||
class RegularDeviceManager
|
||||
: public InterfaceManager<RegularDeviceManager, FactoryAndDevice, IDevice> {
|
||||
public:
|
||||
static sp<IDevice> createInterfaceInstance(const FactoryAndDevice& factoryAndDevice) {
|
||||
auto [factoryName, name] = factoryAndDevice;
|
||||
sp<IDevicesFactory> factory = DevicesFactoryManager::getInstance().get(factoryName);
|
||||
return openDevice(factory, name);
|
||||
}
|
||||
using InterfaceManager::reset;
|
||||
|
||||
static constexpr const char* kPrimaryDevice = "primary";
|
||||
|
||||
sp<IDevice> get(const std::string& factoryName, const std::string& name) {
|
||||
if (name == kPrimaryDevice) {
|
||||
(void)getPrimary(factoryName); // for initializing primaryDevice if needed.
|
||||
}
|
||||
return InterfaceManager::get(std::make_tuple(factoryName, name));
|
||||
}
|
||||
sp<IPrimaryDevice> getPrimary(const std::string& factoryName) {
|
||||
if (primaryDevice == nullptr) {
|
||||
sp<IDevicesFactory> factory = DevicesFactoryManager::getInstance().get(factoryName);
|
||||
primaryDevice = openPrimaryDevice(factory);
|
||||
}
|
||||
return primaryDevice;
|
||||
}
|
||||
|
||||
bool reset(const std::string& factoryName, const std::string& name)
|
||||
__attribute__((warn_unused_result)) {
|
||||
if (name == kPrimaryDevice) {
|
||||
primaryDevice.clear();
|
||||
}
|
||||
#if MAJOR_VERSION <= 5
|
||||
return InterfaceManager::reset(std::make_tuple(factoryName, name), true);
|
||||
#elif MAJOR_VERSION >= 6
|
||||
|
@ -144,9 +187,6 @@ class DeviceManager : public InterfaceManager<DeviceManager, FactoryAndDevice, I
|
|||
return InterfaceManager::reset(std::make_tuple(factoryName, name), false);
|
||||
#endif
|
||||
}
|
||||
bool resetPrimary(const std::string& factoryName) __attribute__((warn_unused_result)) {
|
||||
return reset(factoryName, kPrimaryDevice);
|
||||
}
|
||||
|
||||
private:
|
||||
static sp<IDevice> openDevice(const sp<IDevicesFactory>& factory, const std::string& name) {
|
||||
|
@ -155,9 +195,7 @@ class DeviceManager : public InterfaceManager<DeviceManager, FactoryAndDevice, I
|
|||
sp<IDevice> device;
|
||||
#if MAJOR_VERSION == 2
|
||||
IDevicesFactory::Device dev = IDevicesFactory::IDevicesFactory::Device(-1);
|
||||
if (name == AUDIO_HARDWARE_MODULE_ID_PRIMARY) {
|
||||
dev = IDevicesFactory::Device::PRIMARY;
|
||||
} else if (name == AUDIO_HARDWARE_MODULE_ID_A2DP) {
|
||||
if (name == AUDIO_HARDWARE_MODULE_ID_A2DP) {
|
||||
dev = IDevicesFactory::Device::A2DP;
|
||||
} else if (name == AUDIO_HARDWARE_MODULE_ID_USB) {
|
||||
dev = IDevicesFactory::Device::USB;
|
||||
|
@ -179,47 +217,62 @@ class DeviceManager : public InterfaceManager<DeviceManager, FactoryAndDevice, I
|
|||
}
|
||||
return device;
|
||||
}
|
||||
};
|
||||
|
||||
static sp<IPrimaryDevice> openPrimaryDevice(const sp<IDevicesFactory>& factory) {
|
||||
if (factory == nullptr) return {};
|
||||
Result result;
|
||||
sp<IDevice> device;
|
||||
sp<IPrimaryDevice> primaryDevice;
|
||||
#if MAJOR_VERSION == 2
|
||||
auto ret = factory->openDevice(IDevicesFactory::Device::PRIMARY, returnIn(result, device));
|
||||
if (ret.isOk() && result == Result::OK && device != nullptr) {
|
||||
primaryDevice = IPrimaryDevice::castFrom(device);
|
||||
} // namespace impl
|
||||
|
||||
class DeviceManager {
|
||||
public:
|
||||
static DeviceManager& getInstance() {
|
||||
static DeviceManager instance;
|
||||
return instance;
|
||||
}
|
||||
#elif MAJOR_VERSION >= 4 && (MAJOR_VERSION < 7 || (MAJOR_VERSION == 7 && MINOR_VERSION == 0))
|
||||
auto ret = factory->openPrimaryDevice(returnIn(result, device));
|
||||
if (ret.isOk() && result == Result::OK && device != nullptr) {
|
||||
primaryDevice = IPrimaryDevice::castFrom(device);
|
||||
|
||||
static constexpr const char* kPrimaryDevice = "primary";
|
||||
|
||||
sp<IDevice> get(const std::string& factoryName, const std::string& name) {
|
||||
if (name == kPrimaryDevice) {
|
||||
auto primary = getPrimary(factoryName);
|
||||
return primary ? deviceFromPrimary(primary) : nullptr;
|
||||
}
|
||||
#elif MAJOR_VERSION == 7 && MINOR_VERSION == 1
|
||||
auto ret = factory->openPrimaryDevice_7_1(returnIn(result, primaryDevice));
|
||||
if (ret.isOk() && result == Result::OK && primaryDevice != nullptr) {
|
||||
auto getDeviceRet = primaryDevice->getDevice();
|
||||
if (getDeviceRet.isOk()) {
|
||||
device = getDeviceRet;
|
||||
} else {
|
||||
primaryDevice.clear();
|
||||
ALOGW("Primary device can not downcast, transaction: %s, primary %p",
|
||||
getDeviceRet.description().c_str(), primaryDevice.get());
|
||||
return {};
|
||||
return mDevices.get(factoryName, name);
|
||||
}
|
||||
|
||||
sp<IPrimaryDevice> getPrimary(const std::string& factoryName) {
|
||||
return mPrimary.get(factoryName);
|
||||
}
|
||||
#endif
|
||||
if (!ret.isOk() || result != Result::OK || device == nullptr) {
|
||||
ALOGW("Primary device can not be opened, transaction: %s, result %d, device %p",
|
||||
ret.description().c_str(), result, device.get());
|
||||
return {};
|
||||
|
||||
bool reset(const std::string& factoryName, const std::string& name)
|
||||
__attribute__((warn_unused_result)) {
|
||||
return name == kPrimaryDevice ? resetPrimary(factoryName)
|
||||
: mDevices.reset(factoryName, name);
|
||||
}
|
||||
return primaryDevice;
|
||||
|
||||
bool resetPrimary(const std::string& factoryName) __attribute__((warn_unused_result)) {
|
||||
return mPrimary.reset(factoryName);
|
||||
}
|
||||
|
||||
static void waitForInstanceDestruction() {
|
||||
// Does not matter which device manager to use.
|
||||
impl::RegularDeviceManager::waitForInstanceDestruction();
|
||||
}
|
||||
|
||||
private:
|
||||
// There can only be one primary device across all HAL modules.
|
||||
// A reference to a complete interface is used because in V7.1 IDevice can not
|
||||
// be upcasted to IPrimaryDevice.
|
||||
sp<IPrimaryDevice> primaryDevice;
|
||||
sp<IDevice> deviceFromPrimary(const sp<IPrimaryDevice>& primary) {
|
||||
#if MAJOR_VERSION == 7 && MINOR_VERSION == 1
|
||||
auto ret = primary->getDevice();
|
||||
if (ret.isOk()) {
|
||||
return ret;
|
||||
} else {
|
||||
ALOGW("Error retrieving IDevice from primary: transaction: %s, primary %p",
|
||||
ret.description().c_str(), primary.get());
|
||||
return nullptr;
|
||||
}
|
||||
#else
|
||||
return primary;
|
||||
#endif
|
||||
}
|
||||
|
||||
impl::PrimaryDeviceManager mPrimary;
|
||||
impl::RegularDeviceManager mDevices;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue