diff --git a/audio/aidl/Android.bp b/audio/aidl/Android.bp index 674b6447f9..d4c9a658cb 100644 --- a/audio/aidl/Android.bp +++ b/audio/aidl/Android.bp @@ -168,6 +168,53 @@ cc_defaults { ], } +// Used for the standalone sounddose HAL +aidl_interface { + name: "android.hardware.audio.core.sounddose", + defaults: [ + "android.hardware.audio_defaults", + ], + srcs: [ + "android/hardware/audio/core/ISoundDose.aidl", + ], + imports: [ + "android.media.audio.common.types-V2", + ], + backend: { + // The C++ backend is disabled transitively due to use of FMQ by the core HAL. + cpp: { + enabled: false, + }, + java: { + sdk_version: "module_current", + }, + }, + versions_with_info: [ + // IMPORTANT: Update latest_android_hardware_audio_core_sounddose every time you + // add the latest frozen version to versions_with_info + ], +} + +// Note: This should always be one version ahead of the last frozen version +latest_android_hardware_audio_core_sounddose = "android.hardware.audio.core.sounddose-V1" + +// Modules that depend on android.hardware.audio.core.sounddose directly can include +// the following cc_defaults to avoid explicitly managing dependency versions +// across many scattered files. +cc_defaults { + name: "latest_android_hardware_audio_core_sounddose_ndk_shared", + shared_libs: [ + latest_android_hardware_audio_core_sounddose + "-ndk", + ], +} + +cc_defaults { + name: "latest_android_hardware_audio_core_sounddose_ndk_static", + static_libs: [ + latest_android_hardware_audio_core_sounddose + "-ndk", + ], +} + aidl_interface { name: "android.hardware.audio.effect", defaults: [ diff --git a/audio/aidl/aidl_api/android.hardware.audio.core.sounddose/current/android/hardware/audio/core/ISoundDose.aidl b/audio/aidl/aidl_api/android.hardware.audio.core.sounddose/current/android/hardware/audio/core/ISoundDose.aidl new file mode 100644 index 0000000000..bc010caaf5 --- /dev/null +++ b/audio/aidl/aidl_api/android.hardware.audio.core.sounddose/current/android/hardware/audio/core/ISoundDose.aidl @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/////////////////////////////////////////////////////////////////////////////// +// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. // +/////////////////////////////////////////////////////////////////////////////// + +// This file is a snapshot of an AIDL file. Do not edit it manually. There are +// two cases: +// 1). this is a frozen version file - do not edit this in any case. +// 2). this is a 'current' file. If you make a backwards compatible change to +// the interface (from the latest frozen version), the build system will +// prompt you to update this file with `m -update-api`. +// +// You must not make a backward incompatible change to any AIDL file built +// with the aidl_interface module type with versions property set. The module +// type is used to build AIDL files in a way that they can be used across +// independently updatable components of the system. If a device is shipped +// with such a backward incompatible change, it has a high risk of breaking +// later when a module using the interface is updated, e.g., Mainline modules. + +package android.hardware.audio.core; +@VintfStability +interface ISoundDose { + void setOutputRs2(float rs2ValueDbA); + float getOutputRs2(); + void registerSoundDoseCallback(in android.hardware.audio.core.ISoundDose.IHalSoundDoseCallback callback); + const int DEFAULT_MAX_RS2 = 100; + const int MIN_RS2 = 80; + @VintfStability + interface IHalSoundDoseCallback { + oneway void onMomentaryExposureWarning(float currentDbA, in android.media.audio.common.AudioDevice audioDevice); + oneway void onNewMelValues(in android.hardware.audio.core.ISoundDose.IHalSoundDoseCallback.MelRecord melRecord, in android.media.audio.common.AudioDevice audioDevice); + @VintfStability + parcelable MelRecord { + float[] melValues; + long timestamp; + } + } +} diff --git a/audio/aidl/default/Android.bp b/audio/aidl/default/Android.bp index b9b8cd8ce2..91fd4ed7de 100644 --- a/audio/aidl/default/Android.bp +++ b/audio/aidl/default/Android.bp @@ -29,6 +29,29 @@ cc_defaults { ], } +cc_library { + name: "libaudioservicesounddoseimpl", + vendor: true, + defaults: [ + "latest_android_media_audio_common_types_ndk_shared", + "latest_android_hardware_audio_core_sounddose_ndk_shared", + "latest_android_hardware_audio_sounddose_ndk_shared", + ], + export_include_dirs: ["include"], + srcs: [ + "SoundDose.cpp", + ], + shared_libs: [ + "libbase", + "libbinder_ndk", + "libcutils", + "libutils", + ], + visibility: [ + "//hardware/interfaces/audio/aidl/sounddose/default", + ], +} + cc_library_static { name: "libaudioserviceexampleimpl", defaults: [ diff --git a/audio/aidl/sounddose/Android.bp b/audio/aidl/sounddose/Android.bp new file mode 100644 index 0000000000..85d6e217a8 --- /dev/null +++ b/audio/aidl/sounddose/Android.bp @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package { + // See: http://go/android-license-faq + // A large-scale-change added 'default_applicable_licenses' to import + // all of the 'license_kinds' from "hardware_interfaces_license" + // to get the below license kinds: + // SPDX-license-identifier-Apache-2.0 + default_applicable_licenses: ["hardware_interfaces_license"], +} + +aidl_interface { + name: "android.hardware.audio.sounddose", + host_supported: true, + vendor_available: true, + stability: "vintf", + srcs: [ + "android/hardware/audio/sounddose/ISoundDoseFactory.aidl", + ], + imports: [ + latest_android_hardware_audio_core_sounddose, + ], + backend: { + // The C++ backend is disabled transitively due to use by core audio HAL. + cpp: { + enabled: false, + }, + java: { + sdk_version: "module_current", + }, + }, + versions_with_info: [ + // IMPORTANT: Update latest_android_hardware_audio_sounddose every time you + // add the latest frozen version to versions_with_info + ], +} + +// Note: This should always be one version ahead of the last frozen version +latest_android_hardware_audio_sounddose = "android.hardware.audio.sounddose-V1" + +// Modules that depend on android.hardware.audio.sounddose directly can include +// the following cc_defaults to avoid explicitly managing dependency versions +// across many scattered files. +cc_defaults { + name: "latest_android_hardware_audio_sounddose_ndk_shared", + shared_libs: [ + latest_android_hardware_audio_sounddose + "-ndk", + ], +} + +cc_defaults { + name: "latest_android_hardware_audio_sounddose_ndk_static", + static_libs: [ + latest_android_hardware_audio_sounddose + "-ndk", + ], +} diff --git a/audio/aidl/sounddose/aidl_api/android.hardware.audio.core.sounddose/current/android/hardware/audio/core/ISoundDose.aidl b/audio/aidl/sounddose/aidl_api/android.hardware.audio.core.sounddose/current/android/hardware/audio/core/ISoundDose.aidl new file mode 100644 index 0000000000..dff17e23b1 --- /dev/null +++ b/audio/aidl/sounddose/aidl_api/android.hardware.audio.core.sounddose/current/android/hardware/audio/core/ISoundDose.aidl @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/////////////////////////////////////////////////////////////////////////////// +// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. // +/////////////////////////////////////////////////////////////////////////////// + +// This file is a snapshot of an AIDL file. Do not edit it manually. There are +// two cases: +// 1). this is a frozen version file - do not edit this in any case. +// 2). this is a 'current' file. If you make a backwards compatible change to +// the interface (from the latest frozen version), the build system will +// prompt you to update this file with `m -update-api`. +// +// You must not make a backward incompatible change to any AIDL file built +// with the aidl_interface module type with versions property set. The module +// type is used to build AIDL files in a way that they can be used across +// independently updatable components of the system. If a device is shipped +// with such a backward incompatible change, it has a high risk of breaking +// later when a module using the interface is updated, e.g., Mainline modules. + +package android.hardware.audio.core; +@VintfStability +interface ISoundDose { + void setOutputRs2(float rs2ValueDbA); + float getOutputRs2(); + void registerSoundDoseCallback(in android.hardware.audio.core.ISoundDose.IHalSoundDoseCallback callback); + const int DEFAULT_MAX_RS2 = 100; + @VintfStability + interface IHalSoundDoseCallback { + oneway void onMomentaryExposureWarning(float currentDbA, in android.media.audio.common.AudioDevice audioDevice); + oneway void onNewMelValues(in android.hardware.audio.core.ISoundDose.IHalSoundDoseCallback.MelRecord melRecord, in android.media.audio.common.AudioDevice audioDevice); + @VintfStability + parcelable MelRecord { + float[] melValues; + long timestamp; + } + } +} diff --git a/audio/aidl/sounddose/aidl_api/android.hardware.audio.sounddose/current/android/hardware/audio/sounddose/ISoundDoseFactory.aidl b/audio/aidl/sounddose/aidl_api/android.hardware.audio.sounddose/current/android/hardware/audio/sounddose/ISoundDoseFactory.aidl new file mode 100644 index 0000000000..7dda011ccd --- /dev/null +++ b/audio/aidl/sounddose/aidl_api/android.hardware.audio.sounddose/current/android/hardware/audio/sounddose/ISoundDoseFactory.aidl @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/////////////////////////////////////////////////////////////////////////////// +// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. // +/////////////////////////////////////////////////////////////////////////////// + +// This file is a snapshot of an AIDL file. Do not edit it manually. There are +// two cases: +// 1). this is a frozen version file - do not edit this in any case. +// 2). this is a 'current' file. If you make a backwards compatible change to +// the interface (from the latest frozen version), the build system will +// prompt you to update this file with `m -update-api`. +// +// You must not make a backward incompatible change to any AIDL file built +// with the aidl_interface module type with versions property set. The module +// type is used to build AIDL files in a way that they can be used across +// independently updatable components of the system. If a device is shipped +// with such a backward incompatible change, it has a high risk of breaking +// later when a module using the interface is updated, e.g., Mainline modules. + +package android.hardware.audio.sounddose; +@VintfStability +interface ISoundDoseFactory { + @nullable android.hardware.audio.core.ISoundDose getSoundDose(in @utf8InCpp String module); +} diff --git a/audio/aidl/sounddose/android/hardware/audio/sounddose/ISoundDoseFactory.aidl b/audio/aidl/sounddose/android/hardware/audio/sounddose/ISoundDoseFactory.aidl new file mode 100644 index 0000000000..34872378c7 --- /dev/null +++ b/audio/aidl/sounddose/android/hardware/audio/sounddose/ISoundDoseFactory.aidl @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.hardware.audio.sounddose; + +import android.hardware.audio.core.ISoundDose; + +/** + * This interface is used to provide an easy way to implement the ISoundDose interface + * without switching the audio HAL to AIDL. The implementation is intended as a workaround + * for the certification with IEC62368-1 3rd edition and EN50332-3. + * Note that this interface will be deprecated in favor of the audio AIDL HAL. + */ +@VintfStability +interface ISoundDoseFactory { + /** + * Retrieve the sound dose interface for a given audio HAL module name. + * + * If a device must comply to IEC62368-1 3rd edition audio safety requirements and is + * implementing audio offload decoding or other direct playback paths where volume control + * happens below the audio HAL, it must return an instance of the ISoundDose interface. + * The same instance must be returned during the lifetime of the HAL module. + * If the HAL module does not support sound dose, null must be returned, without throwing + * any errors. + * + * @param module for which we trigger sound dose updates. + * @return An instance of the ISoundDose interface implementation. + * @throws EX_ILLEGAL_STATE If there was an error creating an instance. + */ + @nullable ISoundDose getSoundDose(in @utf8InCpp String module); +} diff --git a/audio/aidl/sounddose/default/Android.bp b/audio/aidl/sounddose/default/Android.bp new file mode 100644 index 0000000000..bd770fa5b5 --- /dev/null +++ b/audio/aidl/sounddose/default/Android.bp @@ -0,0 +1,46 @@ +package { + // See: http://go/android-license-faq + // A large-scale-change added 'default_applicable_licenses' to import + // all of the 'license_kinds' from "hardware_interfaces_license" + // to get the below license kinds: + // SPDX-license-identifier-Apache-2.0 + default_applicable_licenses: ["hardware_interfaces_license"], +} + +cc_defaults { + name: "aidlsounddoseservice_defaults", + vendor: true, + header_libs: [ + "libsounddoseaidl_headers", + ], +} + +cc_library { + name: "libsounddoseserviceexampleimpl", + defaults: [ + "aidlsounddoseservice_defaults", + "latest_android_media_audio_common_types_ndk_shared", + "latest_android_hardware_audio_core_sounddose_ndk_shared", + "latest_android_hardware_audio_sounddose_ndk_shared", + ], + export_include_dirs: ["include"], + srcs: [ + "SoundDoseFactory.cpp", + ], + shared_libs: [ + "libaudioservicesounddoseimpl", + "libbase", + "libbinder_ndk", + ], + + visibility: [ + "//hardware/interfaces/audio/common/all-versions/default/service", + ], +} + +cc_library_headers { + name: "libsounddoseaidl_headers", + export_include_dirs: ["include"], + vendor_available: true, + host_supported: true, +} diff --git a/audio/aidl/sounddose/default/SoundDoseFactory.cpp b/audio/aidl/sounddose/default/SoundDoseFactory.cpp new file mode 100644 index 0000000000..50796d0ce0 --- /dev/null +++ b/audio/aidl/sounddose/default/SoundDoseFactory.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "AHAL_SoundDoseFactory" + +#include "SoundDoseFactory.h" + +#include +#include + +namespace aidl::android::hardware::audio::sounddose { + +using ::aidl::android::hardware::audio::core::SoundDose; + +ndk::ScopedAStatus SoundDoseFactory::getSoundDose(const std::string& in_module, + std::shared_ptr* _aidl_return) { + auto soundDoseIt = mSoundDoseBinderMap.find(in_module); + if (soundDoseIt != mSoundDoseBinderMap.end()) { + *_aidl_return = ISoundDose::fromBinder(soundDoseIt->second); + + LOG(DEBUG) << __func__ + << ": returning cached instance of ISoundDose: " << _aidl_return->get() + << " for module " << in_module; + return ndk::ScopedAStatus::ok(); + } + + auto soundDose = ndk::SharedRefBase::make(); + mSoundDoseBinderMap[in_module] = soundDose->asBinder(); + *_aidl_return = soundDose; + + LOG(DEBUG) << __func__ << ": returning new instance of ISoundDose: " << _aidl_return->get() + << " for module " << in_module; + return ndk::ScopedAStatus::ok(); +} + +} // namespace aidl::android::hardware::audio::sounddose diff --git a/audio/aidl/sounddose/default/include/SoundDoseFactory.h b/audio/aidl/sounddose/default/include/SoundDoseFactory.h new file mode 100644 index 0000000000..4cf3277fc7 --- /dev/null +++ b/audio/aidl/sounddose/default/include/SoundDoseFactory.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include + +#include + +namespace aidl::android::hardware::audio::sounddose { + +using ::aidl::android::hardware::audio::core::ISoundDose; + +class SoundDoseFactory : public BnSoundDoseFactory { + public: + ndk::ScopedAStatus getSoundDose(const std::string& module, + std::shared_ptr* _aidl_return) override; + + private: + std::unordered_map mSoundDoseBinderMap; +}; + +} // namespace aidl::android::hardware::audio::sounddose diff --git a/audio/aidl/sounddose/vts/Android.bp b/audio/aidl/sounddose/vts/Android.bp new file mode 100644 index 0000000000..88be968f27 --- /dev/null +++ b/audio/aidl/sounddose/vts/Android.bp @@ -0,0 +1,36 @@ +package { + // See: http://go/android-license-faq + // A large-scale-change added 'default_applicable_licenses' to import + // all of the 'license_kinds' from "hardware_interfaces_license" + // to get the below license kinds: + // SPDX-license-identifier-Apache-2.0 + default_applicable_licenses: ["hardware_interfaces_license"], +} + +cc_test { + name: "VtsHalSoundDoseFactoryTargetTest", + defaults: [ + "latest_android_hardware_audio_core_sounddose_ndk_static", + "latest_android_hardware_audio_sounddose_ndk_static", + "latest_android_media_audio_common_types_ndk_static", + "use_libaidlvintf_gtest_helper_static", + "VtsHalTargetTestDefaults", + ], + shared_libs: [ + "libbinder_ndk", + "libcutils", + ], + srcs: [ + "VtsHalSoundDoseFactoryTargetTest.cpp", + ], + cflags: [ + "-Wall", + "-Wextra", + "-Werror", + "-Wthread-safety", + ], + test_suites: [ + "general-tests", + "vts", + ], +} diff --git a/audio/aidl/sounddose/vts/TEST_MAPPING b/audio/aidl/sounddose/vts/TEST_MAPPING new file mode 100644 index 0000000000..bebeed9128 --- /dev/null +++ b/audio/aidl/sounddose/vts/TEST_MAPPING @@ -0,0 +1,7 @@ +{ + "presubmit": [ + { + "name": "VtsHalSoundDoseFactoryTargetTest" + } + ] +} diff --git a/audio/aidl/sounddose/vts/VtsHalSoundDoseFactoryTargetTest.cpp b/audio/aidl/sounddose/vts/VtsHalSoundDoseFactoryTargetTest.cpp new file mode 100644 index 0000000000..7448c1ff5f --- /dev/null +++ b/audio/aidl/sounddose/vts/VtsHalSoundDoseFactoryTargetTest.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "VtsHalSoundDose.Factory" +#include + +#include +#include +#include +#include + +#include + +namespace android::hardware::audio::common::testing { + +namespace detail { + +inline ::testing::AssertionResult assertIsOk(const char* expr, const ::ndk::ScopedAStatus& status) { + if (status.isOk()) { + return ::testing::AssertionSuccess(); + } + return ::testing::AssertionFailure() + << "Expected the transaction \'" << expr << "\' to succeed\n" + << " but it has failed with: " << status; +} + +} // namespace detail + +} // namespace android::hardware::audio::common::testing + +// Test that the transaction status 'isOk' +#define EXPECT_IS_OK(ret) \ + EXPECT_PRED_FORMAT1(::android::hardware::audio::common::testing::detail::assertIsOk, ret) + +using namespace android; + +using aidl::android::hardware::audio::core::ISoundDose; +using aidl::android::hardware::audio::sounddose::ISoundDoseFactory; + +class SoundDoseFactory : public testing::TestWithParam { + public: + void SetUp() override { ASSERT_NO_FATAL_FAILURE(ConnectToService(GetParam())); } + + void TearDown() override {} + + void ConnectToService(const std::string& interfaceName) { + ndk::SpAIBinder binder = + ndk::SpAIBinder(AServiceManager_waitForService(interfaceName.c_str())); + if (binder == nullptr) { + LOG(ERROR) << "Failed to get service " << interfaceName; + } else { + LOG(DEBUG) << "Succeeded to get service " << interfaceName; + } + soundDoseFactory = ISoundDoseFactory::fromBinder(binder); + ASSERT_NE(soundDoseFactory, nullptr); + } + + std::shared_ptr soundDoseFactory; +}; + +TEST_P(SoundDoseFactory, GetSoundDoseForSameModule) { + const std::string module = "primary"; + + std::shared_ptr soundDose1; + EXPECT_IS_OK(soundDoseFactory->getSoundDose(module, &soundDose1)); + + if (soundDose1 == nullptr) { + LOG(WARNING) << "Primary module does not support sound dose"; + return; + } + + std::shared_ptr soundDose2; + EXPECT_IS_OK(soundDoseFactory->getSoundDose(module, &soundDose2)); + EXPECT_NE(nullptr, soundDose2); + EXPECT_EQ(soundDose1->asBinder(), soundDose2->asBinder()) + << "getSoundDose must return the same interface for the same module"; +} + +INSTANTIATE_TEST_SUITE_P( + SoundDoseFactoryTest, SoundDoseFactory, + testing::ValuesIn(android::getAidlHalInstanceNames(ISoundDoseFactory::descriptor)), + android::PrintInstanceNameToString); +GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SoundDoseFactory); diff --git a/audio/aidl/vts/Android.bp b/audio/aidl/vts/Android.bp index 4414e26e95..26467c9abf 100644 --- a/audio/aidl/vts/Android.bp +++ b/audio/aidl/vts/Android.bp @@ -24,6 +24,7 @@ cc_defaults { "android.hardware.common-V2-ndk", "android.hardware.common.fmq-V1-ndk", "libaudioaidlcommon", + "libaidlcommonsupport", ], header_libs: ["libaudioaidl_headers"], cflags: [ diff --git a/audio/common/all-versions/default/service/Android.bp b/audio/common/all-versions/default/service/Android.bp index 9890be2954..2fcfb235e7 100644 --- a/audio/common/all-versions/default/service/Android.bp +++ b/audio/common/all-versions/default/service/Android.bp @@ -38,9 +38,15 @@ cc_binary { name: "android.hardware.audio.service", init_rc: ["android.hardware.audio.service.rc"], + vintf_fragments: ["android.hardware.audio.sounddose-aidl.xml"], relative_install_path: "hw", vendor: true, + defaults: [ + "android_hardware_audio_config_defaults", + "latest_android_hardware_audio_sounddose_ndk_shared", + ], + srcs: ["service.cpp"], cflags: [ @@ -50,6 +56,7 @@ cc_binary { ], shared_libs: [ + "//hardware/interfaces/audio/aidl/sounddose/default:libsounddoseserviceexampleimpl", "libcutils", "libbinder", "libbinder_ndk", @@ -58,10 +65,6 @@ cc_binary { "libutils", "libhardware", ], - - defaults: [ - "android_hardware_audio_config_defaults", - ], } // Legacy service name, use android.hardware.audio.service instead diff --git a/audio/common/all-versions/default/service/android.hardware.audio.sounddose-aidl.xml b/audio/common/all-versions/default/service/android.hardware.audio.sounddose-aidl.xml new file mode 100644 index 0000000000..a297bfbbe5 --- /dev/null +++ b/audio/common/all-versions/default/service/android.hardware.audio.sounddose-aidl.xml @@ -0,0 +1,7 @@ + + + android.hardware.audio.sounddose + 1 + ISoundDoseFactory/default + + diff --git a/audio/common/all-versions/default/service/service.cpp b/audio/common/all-versions/default/service/service.cpp index fbf616563d..e79ad75680 100644 --- a/audio/common/all-versions/default/service/service.cpp +++ b/audio/common/all-versions/default/service/service.cpp @@ -20,6 +20,10 @@ #include #include +#include +#include +#include +#include #include #include #include @@ -33,6 +37,8 @@ using android::OK; using InterfacesList = std::vector; +using aidl::android::hardware::audio::sounddose::SoundDoseFactory; + /** Try to register the provided factories in the provided order. * If any registers successfully, do not register any other and return true. * If all fail, return false. @@ -164,5 +170,13 @@ int main(int /* argc */, char* /* argv */ []) { } } + // Register ISoundDoseFactory interface as a workaround for using the audio AIDL HAL + auto soundDoseDefault = ndk::SharedRefBase::make(); + const std::string soundDoseDefaultName = + std::string() + SoundDoseFactory::descriptor + "/default"; + binder_status_t status = AServiceManager_addService(soundDoseDefault->asBinder().get(), + soundDoseDefaultName.c_str()); + CHECK_EQ(STATUS_OK, status); + joinRpcThreadpool(); } diff --git a/compatibility_matrices/compatibility_matrix.current.xml b/compatibility_matrices/compatibility_matrix.current.xml index 99d4bb77f9..5e1589b49b 100644 --- a/compatibility_matrices/compatibility_matrix.current.xml +++ b/compatibility_matrices/compatibility_matrix.current.xml @@ -52,6 +52,14 @@ default + + android.hardware.audio.sounddose + 1 + + ISoundDoseFactory + default + + android.hardware.authsecret 1