diff options
author | alk3pInjection <webmaster@raspii.tech> | 2023-04-20 00:08:54 +0800 |
---|---|---|
committer | alk3pInjection <webmaster@raspii.tech> | 2023-04-20 00:08:54 +0800 |
commit | 0111525d5a8fccbe18a9c1d11e67e4ea78289790 (patch) | |
tree | a580e3f8f49aa35d8a8256aab06b3de0c9542aca | |
parent | f2e9f05ae87a2a4155798e80bc86f827e020a62a (diff) | |
parent | 8053558411d145636e2bb05f443e3436dc53e4bd (diff) |
Merge tag 'LA.QSSI.13.0.r1-09800-qssi.0' into tachibana
"LA.QSSI.13.0.r1-09800-qssi.0"
Change-Id: Ic76606f2ea0ed3f21712ea081b19c5fc802404c0
75 files changed, 3315 insertions, 512 deletions
diff --git a/audio/common/all-versions/default/service/android.hardware.audio.service.rc b/audio/common/all-versions/default/service/android.hardware.audio.service.rc index 45fef9a936..0de4eea373 100644 --- a/audio/common/all-versions/default/service/android.hardware.audio.service.rc +++ b/audio/common/all-versions/default/service/android.hardware.audio.service.rc @@ -3,7 +3,9 @@ service vendor.audio-hal /vendor/bin/hw/android.hardware.audio.service user audioserver # media gid needed for /dev/fm (radio) and for /data/misc/media (tee) group audio camera drmrpc inet media mediadrm net_bt net_bt_admin net_bw_acct wakelock context_hub - capabilities BLOCK_SUSPEND + capabilities BLOCK_SUSPEND SYS_NICE + # setting RLIMIT_RTPRIO allows binder RT priority inheritance + rlimit rtprio 10 10 ioprio rt 4 task_profiles ProcessCapacityHigh HighPerformance onrestart restart audioserver diff --git a/audio/core/all-versions/default/Device.cpp b/audio/core/all-versions/default/Device.cpp index b954fcd6f8..d03118ae5d 100644 --- a/audio/core/all-versions/default/Device.cpp +++ b/audio/core/all-versions/default/Device.cpp @@ -30,6 +30,7 @@ #include <algorithm> #include <android/log.h> +#include <hidl/HidlTransportSupport.h> #include <mediautils/MemoryLeakTrackUtil.h> #include <memunreachable/memunreachable.h> @@ -183,6 +184,7 @@ std::tuple<Result, sp<IStreamOut>> Device::openOutputStreamCore(int32_t ioHandle if (status == OK) { streamOut = new StreamOut(this, halStream); ++mOpenedStreamsCount; + android::hardware::setMinSchedulerPolicy(streamOut, SCHED_NORMAL, ANDROID_PRIORITY_AUDIO); } status_t convertStatus = HidlUtils::audioConfigFromHal(halConfig, false /*isInput*/, suggestedConfig); @@ -220,6 +222,7 @@ std::tuple<Result, sp<IStreamIn>> Device::openInputStreamCore( if (status == OK) { streamIn = new StreamIn(this, halStream); ++mOpenedStreamsCount; + android::hardware::setMinSchedulerPolicy(streamIn, SCHED_NORMAL, ANDROID_PRIORITY_AUDIO); } status_t convertStatus = HidlUtils::audioConfigFromHal(halConfig, true /*isInput*/, suggestedConfig); diff --git a/audio/core/all-versions/default/DevicesFactory.cpp b/audio/core/all-versions/default/DevicesFactory.cpp index f44daf0b0e..011f9ac4c2 100644 --- a/audio/core/all-versions/default/DevicesFactory.cpp +++ b/audio/core/all-versions/default/DevicesFactory.cpp @@ -23,6 +23,8 @@ #include <string.h> #include <android/log.h> +#include <hidl/HidlTransportSupport.h> +#include <system/thread_defs.h> namespace android { namespace hardware { @@ -103,6 +105,7 @@ Return<void> DevicesFactory::openDevice(const char* moduleName, Callback _hidl_c int halStatus = loadAudioInterface(moduleName, &halDevice); if (halStatus == OK) { result = new DeviceShim(halDevice); + android::hardware::setMinSchedulerPolicy(result, SCHED_NORMAL, ANDROID_PRIORITY_AUDIO); retval = Result::OK; } else if (halStatus == -EINVAL) { retval = Result::NOT_INITIALIZED; diff --git a/audio/core/all-versions/vts/functional/7.0/AudioPrimaryHidlHalTest.cpp b/audio/core/all-versions/vts/functional/7.0/AudioPrimaryHidlHalTest.cpp index dfc238623c..505c54c1df 100644 --- a/audio/core/all-versions/vts/functional/7.0/AudioPrimaryHidlHalTest.cpp +++ b/audio/core/all-versions/vts/functional/7.0/AudioPrimaryHidlHalTest.cpp @@ -14,7 +14,11 @@ * limitations under the License. */ +#include <fstream> +#include <numeric> + #include <android-base/chrono_utils.h> +#include <cutils/properties.h> #include "Generators.h" @@ -517,20 +521,10 @@ class PcmOnlyConfigOutputStreamTest : public OutputStreamTest { } bool canQueryPresentationPosition() const { - auto maybeSinkAddress = - getCachedPolicyConfig().getSinkDeviceForMixPort(getDeviceName(), getMixPortName()); - // Returning 'true' when no sink is found so the test can fail later with a more clear - // problem description. - return !maybeSinkAddress.has_value() || - !xsd::isTelephonyDevice(maybeSinkAddress.value().deviceType); + return !xsd::isTelephonyDevice(address.deviceType); } void createPatchIfNeeded() { - auto maybeSinkAddress = - getCachedPolicyConfig().getSinkDeviceForMixPort(getDeviceName(), getMixPortName()); - ASSERT_TRUE(maybeSinkAddress.has_value()) - << "No sink device found for mix port " << getMixPortName() << " (module " - << getDeviceName() << ")"; if (areAudioPatchesSupported()) { AudioPortConfig source; source.base.format.value(getConfig().base.format); @@ -540,13 +534,13 @@ class PcmOnlyConfigOutputStreamTest : public OutputStreamTest { source.ext.mix().ioHandle = helper.getIoHandle(); source.ext.mix().useCase.stream({}); AudioPortConfig sink; - sink.ext.device(maybeSinkAddress.value()); + sink.ext.device(address); EXPECT_OK(getDevice()->createAudioPatch(hidl_vec<AudioPortConfig>{source}, hidl_vec<AudioPortConfig>{sink}, returnIn(res, mPatchHandle))); mHasPatch = res == Result::OK; } else { - EXPECT_OK(stream->setDevices({maybeSinkAddress.value()})); + EXPECT_OK(stream->setDevices({address})); } } @@ -556,10 +550,6 @@ class PcmOnlyConfigOutputStreamTest : public OutputStreamTest { EXPECT_OK(getDevice()->releaseAudioPatch(mPatchHandle)); mHasPatch = false; } - } else { - if (stream) { - EXPECT_OK(stream->setDevices({address})); - } } } @@ -575,16 +565,22 @@ class PcmOnlyConfigOutputStreamTest : public OutputStreamTest { // Sometimes HAL doesn't have enough information until the audio data actually gets // consumed by the hardware. bool timedOut = false; - res = Result::INVALID_STATE; - for (android::base::Timer elapsed; - res != Result::OK && !writer.hasError() && - !(timedOut = (elapsed.duration() >= kPositionChangeTimeout));) { - usleep(kWriteDurationUs); - ASSERT_OK(stream->getPresentationPosition(returnIn(res, framesInitial, ts))); - ASSERT_RESULT(okOrInvalidState, res); + if (!firstPosition || *firstPosition == std::numeric_limits<uint64_t>::max()) { + res = Result::INVALID_STATE; + for (android::base::Timer elapsed; + res != Result::OK && !writer.hasError() && + !(timedOut = (elapsed.duration() >= kPositionChangeTimeout));) { + usleep(kWriteDurationUs); + ASSERT_OK(stream->getPresentationPosition(returnIn(res, framesInitial, ts))); + ASSERT_RESULT(okOrInvalidState, res); + } + ASSERT_FALSE(writer.hasError()); + ASSERT_FALSE(timedOut); + } else { + // Use `firstPosition` instead of querying it from the HAL. This is used when + // `waitForPresentationPositionAdvance` is called in a loop. + framesInitial = *firstPosition; } - ASSERT_FALSE(writer.hasError()); - ASSERT_FALSE(timedOut); uint64_t frames = framesInitial; for (android::base::Timer elapsed; @@ -646,7 +642,7 @@ TEST_P(PcmOnlyConfigOutputStreamTest, PresentationPositionPreservedOnStandby) { ASSERT_OK(stream->standby()); writer.resume(); - uint64_t frames; + uint64_t frames = std::numeric_limits<uint64_t>::max(); ASSERT_NO_FATAL_FAILURE(waitForPresentationPositionAdvance(writer, &frames)); EXPECT_GT(frames, framesInitial); @@ -691,24 +687,12 @@ class PcmOnlyConfigInputStreamTest : public InputStreamTest { InputStreamTest::TearDown(); } - bool canQueryCapturePosition() const { - auto maybeSourceAddress = getCachedPolicyConfig().getSourceDeviceForMixPort( - getDeviceName(), getMixPortName()); - // Returning 'true' when no source is found so the test can fail later with a more clear - // problem description. - return !maybeSourceAddress.has_value() || - !xsd::isTelephonyDevice(maybeSourceAddress.value().deviceType); - } + bool canQueryCapturePosition() const { return !xsd::isTelephonyDevice(address.deviceType); } void createPatchIfNeeded() { - auto maybeSourceAddress = getCachedPolicyConfig().getSourceDeviceForMixPort( - getDeviceName(), getMixPortName()); - ASSERT_TRUE(maybeSourceAddress.has_value()) - << "No source device found for mix port " << getMixPortName() << " (module " - << getDeviceName() << ")"; if (areAudioPatchesSupported()) { AudioPortConfig source; - source.ext.device(maybeSourceAddress.value()); + source.ext.device(address); AudioPortConfig sink; sink.base.format.value(getConfig().base.format); sink.base.sampleRateHz.value(getConfig().base.sampleRateHz); @@ -721,7 +705,7 @@ class PcmOnlyConfigInputStreamTest : public InputStreamTest { returnIn(res, mPatchHandle))); mHasPatch = res == Result::OK; } else { - EXPECT_OK(stream->setDevices({maybeSourceAddress.value()})); + EXPECT_OK(stream->setDevices({address})); } } @@ -731,10 +715,6 @@ class PcmOnlyConfigInputStreamTest : public InputStreamTest { EXPECT_OK(getDevice()->releaseAudioPatch(mPatchHandle)); mHasPatch = false; } - } else { - if (stream) { - EXPECT_OK(stream->setDevices({address})); - } } } @@ -864,14 +844,8 @@ TEST_P(MicrophoneInfoInputStreamTest, GetActiveMicrophones) { } ASSERT_OK(res); - auto maybeSourceAddress = - getCachedPolicyConfig().getSourceDeviceForMixPort(getDeviceName(), getMixPortName()); - ASSERT_TRUE(maybeSourceAddress.has_value()) - << "No source device found for mix port " << getMixPortName() << " (module " - << getDeviceName() << ")"; - for (auto microphone : microphones) { - if (microphone.deviceAddress == maybeSourceAddress.value()) { + if (microphone.deviceAddress == address) { StreamReader reader(stream.get(), stream->getBufferSize()); ASSERT_TRUE(reader.start()); reader.pause(); // This ensures that at least one read has happened. @@ -889,3 +863,176 @@ INSTANTIATE_TEST_CASE_P(MicrophoneInfoInputStream, MicrophoneInfoInputStreamTest ::testing::ValuesIn(getBuiltinMicConfigParameters()), &DeviceConfigParameterToString); GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(MicrophoneInfoInputStreamTest); + +static const std::vector<DeviceConfigParameter>& getOutputDeviceCompressedConfigParameters( + const AudioConfigBase& configToMatch) { + static const std::vector<DeviceConfigParameter> parameters = [&] { + auto allParams = getOutputDeviceConfigParameters(); + std::vector<DeviceConfigParameter> compressedParams; + std::copy_if(allParams.begin(), allParams.end(), std::back_inserter(compressedParams), + [&](auto cfg) { + if (std::get<PARAM_CONFIG>(cfg).base != configToMatch) return false; + const auto& flags = std::get<PARAM_FLAGS>(cfg); + return std::find_if(flags.begin(), flags.end(), [](const auto& flag) { + return flag == + toString(xsd::AudioInOutFlag:: + AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD); + }) != flags.end(); + }); + return compressedParams; + }(); + return parameters; +} + +class CompressedOffloadOutputStreamTest : public PcmOnlyConfigOutputStreamTest { + public: + void loadData(const std::string& fileName, std::vector<uint8_t>* data) { + std::ifstream is(fileName, std::ios::in | std::ios::binary); + ASSERT_TRUE(is.good()) << "Failed to open file " << fileName; + is.seekg(0, is.end); + data->reserve(data->size() + is.tellg()); + is.seekg(0, is.beg); + data->insert(data->end(), std::istreambuf_iterator<char>(is), + std::istreambuf_iterator<char>()); + ASSERT_TRUE(!is.fail()) << "Failed to read from file " << fileName; + } +}; + +class OffloadCallbacks : public IStreamOutCallback { + public: + Return<void> onDrainReady() override { + ALOGI("onDrainReady"); + { + std::lock_guard lg(mLock); + mOnDrainReady = true; + } + mCondVar.notify_one(); + return {}; + } + Return<void> onWriteReady() override { return {}; } + Return<void> onError() override { + ALOGW("onError"); + { + std::lock_guard lg(mLock); + mOnError = true; + } + mCondVar.notify_one(); + return {}; + } + bool waitForDrainReadyOrError() { + std::unique_lock l(mLock); + if (!mOnDrainReady && !mOnError) { + mCondVar.wait(l, [&]() { return mOnDrainReady || mOnError; }); + } + const bool success = !mOnError; + mOnDrainReady = mOnError = false; + return success; + } + + private: + std::mutex mLock; + bool mOnDrainReady = false; + bool mOnError = false; + std::condition_variable mCondVar; +}; + +TEST_P(CompressedOffloadOutputStreamTest, Mp3FormatGaplessOffload) { + doc::test("Check that compressed offload mix ports for MP3 implement gapless offload"); + const auto& flags = getOutputFlags(); + const bool isNewDeviceLaunchingOnTPlus = property_get_int32("ro.vendor.api_level", 0) >= 33; + // See test instantiation, only offload MP3 mix ports are used. + if (std::find_if(flags.begin(), flags.end(), [](const auto& flag) { + return flag == toString(xsd::AudioInOutFlag::AUDIO_OUTPUT_FLAG_GAPLESS_OFFLOAD); + }) == flags.end()) { + if (isNewDeviceLaunchingOnTPlus) { + FAIL() << "New devices launching on Android T+ must support gapless offload, " + << "see VSR-4.3-001"; + } else { + GTEST_SKIP() << "Compressed offload mix port does not support gapless offload"; + } + } + std::vector<uint8_t> offloadData; + ASSERT_NO_FATAL_FAILURE(loadData("/data/local/tmp/sine882hz3s.mp3", &offloadData)); + ASSERT_FALSE(offloadData.empty()); + ASSERT_NO_FATAL_FAILURE(createPatchIfNeeded()); + const int presentationeEndPrecisionMs = 1000; + const int sampleRate = 44100; + const int significantSampleNumber = (presentationeEndPrecisionMs * sampleRate) / 1000; + const int delay = 576 + 1000; + const int padding = 756 + 1000; + const int durationMs = 3000 - 44; + auto start = std::chrono::steady_clock::now(); + auto callbacks = sp<OffloadCallbacks>::make(); + std::mutex presentationEndLock; + std::vector<float> presentationEndTimes; + // StreamWriter plays 'offloadData' in a loop, possibly using multiple calls to 'write', this + // depends on the relative sizes of 'offloadData' and the HAL buffer. Writer calls 'onDataStart' + // each time it starts writing the buffer from the beginning, and 'onDataWrap' callback each + // time it wraps around the buffer. + StreamWriter writer( + stream.get(), stream->getBufferSize(), std::move(offloadData), + [&]() /* onDataStart */ { start = std::chrono::steady_clock::now(); }, + [&]() /* onDataWrap */ { + Return<Result> ret(Result::OK); + // Decrease the volume since the test plays a loud sine wave. + ret = stream->setVolume(0.1, 0.1); + if (!ret.isOk() || ret != Result::OK) { + ALOGE("%s: setVolume failed: %s", __func__, toString(ret).c_str()); + return false; + } + ret = Parameters::set( + stream, {{AUDIO_OFFLOAD_CODEC_DELAY_SAMPLES, std::to_string(delay)}, + {AUDIO_OFFLOAD_CODEC_PADDING_SAMPLES, std::to_string(padding)}}); + if (!ret.isOk() || ret != Result::OK) { + ALOGE("%s: setParameters failed: %s", __func__, toString(ret).c_str()); + return false; + } + ret = stream->drain(AudioDrain::EARLY_NOTIFY); + if (!ret.isOk() || ret != Result::OK) { + ALOGE("%s: drain failed: %s", __func__, toString(ret).c_str()); + return false; + } + // FIXME: On some SoCs intermittent errors are possible, ignore them. + if (callbacks->waitForDrainReadyOrError()) { + const float duration = std::chrono::duration_cast<std::chrono::milliseconds>( + std::chrono::steady_clock::now() - start) + .count(); + std::lock_guard lg(presentationEndLock); + presentationEndTimes.push_back(duration); + } + return true; + }); + ASSERT_OK(stream->setCallback(callbacks)); + ASSERT_TRUE(writer.start()); + // How many times to loop the track so that the sum of gapless delay and padding from + // the first presentation end to the last is at least 'presentationeEndPrecisionMs'. + const int playbackNumber = (int)(significantSampleNumber / ((float)delay + padding) + 1); + for (bool done = false; !done;) { + usleep(presentationeEndPrecisionMs * 1000); + { + std::lock_guard lg(presentationEndLock); + done = presentationEndTimes.size() >= playbackNumber; + } + ASSERT_FALSE(writer.hasError()) << "Recent write or drain operation has failed"; + } + const float avgDuration = + std::accumulate(presentationEndTimes.begin(), presentationEndTimes.end(), 0.0) / + presentationEndTimes.size(); + std::stringstream observedEndTimes; + std::copy(presentationEndTimes.begin(), presentationEndTimes.end(), + std::ostream_iterator<float>(observedEndTimes, ", ")); + EXPECT_NEAR(durationMs, avgDuration, presentationeEndPrecisionMs * 0.1) + << "Observed durations: " << observedEndTimes.str(); + writer.stop(); + EXPECT_OK(stream->clearCallback()); + releasePatchIfNeeded(); +} + +INSTANTIATE_TEST_CASE_P( + CompressedOffloadOutputStream, CompressedOffloadOutputStreamTest, + ::testing::ValuesIn(getOutputDeviceCompressedConfigParameters(AudioConfigBase{ + .format = xsd::toString(xsd::AudioFormat::AUDIO_FORMAT_MP3), + .sampleRateHz = 44100, + .channelMask = xsd::toString(xsd::AudioChannelMask::AUDIO_CHANNEL_OUT_STEREO)})), + &DeviceConfigParameterToString); +GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(CompressedOffloadOutputStreamTest); diff --git a/audio/core/all-versions/vts/functional/7.0/Generators.cpp b/audio/core/all-versions/vts/functional/7.0/Generators.cpp index f936d0afbf..8b955b6c84 100644 --- a/audio/core/all-versions/vts/functional/7.0/Generators.cpp +++ b/audio/core/all-versions/vts/functional/7.0/Generators.cpp @@ -57,9 +57,6 @@ static std::vector<AudioConfig> combineAudioConfig(std::vector<xsd::AudioChannel static std::tuple<std::vector<AudioInOutFlag>, bool> generateOutFlags( const xsd::MixPorts::MixPort& mixPort) { - static const std::vector<AudioInOutFlag> offloadFlags = { - toString(xsd::AudioInOutFlag::AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD), - toString(xsd::AudioInOutFlag::AUDIO_OUTPUT_FLAG_DIRECT)}; std::vector<AudioInOutFlag> flags; bool isOffload = false; if (mixPort.hasFlags()) { @@ -67,14 +64,10 @@ static std::tuple<std::vector<AudioInOutFlag>, bool> generateOutFlags( isOffload = std::find(xsdFlags.begin(), xsdFlags.end(), xsd::AudioInOutFlag::AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) != xsdFlags.end(); - if (!isOffload) { - for (auto flag : xsdFlags) { - if (flag != xsd::AudioInOutFlag::AUDIO_OUTPUT_FLAG_PRIMARY) { - flags.push_back(toString(flag)); - } + for (auto flag : xsdFlags) { + if (flag != xsd::AudioInOutFlag::AUDIO_OUTPUT_FLAG_PRIMARY) { + flags.push_back(toString(flag)); } - } else { - flags = offloadFlags; } } return {flags, isOffload}; @@ -85,10 +78,10 @@ static AudioOffloadInfo generateOffloadInfo(const AudioConfigBase& base) { .base = base, .streamType = toString(xsd::AudioStreamType::AUDIO_STREAM_MUSIC), .usage = toString(xsd::AudioUsage::AUDIO_USAGE_MEDIA), - .bitRatePerSecond = 320, + .bitRatePerSecond = 192, // as in sine882hz3s.mp3 .durationMicroseconds = -1, .bitWidth = 16, - .bufferSize = 256 // arbitrary value + .bufferSize = 72000 // 3 seconds at 192 kbps, as in sine882hz3s.mp3 }; } @@ -100,11 +93,10 @@ std::vector<DeviceConfigParameter> generateOutputDeviceConfigParameters(bool one if (!module || !module->getFirstMixPorts()) break; for (const auto& mixPort : module->getFirstMixPorts()->getMixPort()) { if (mixPort.getRole() != xsd::Role::source) continue; // not an output profile - if (getCachedPolicyConfig() - .getAttachedSinkDeviceForMixPort(moduleName, mixPort.getName()) - .empty()) { - continue; // no attached device - } + const auto attachedDeviceAddress = + getCachedPolicyConfig().getDeviceAddressOfSinkDeviceAttachedToMixPort( + moduleName, mixPort.getName()); + if (!attachedDeviceAddress.has_value()) continue; auto [flags, isOffload] = generateOutFlags(mixPort); for (const auto& profile : mixPort.getProfile()) { if (!profile.hasFormat() || !profile.hasSamplingRates() || @@ -118,7 +110,8 @@ std::vector<DeviceConfigParameter> generateOutputDeviceConfigParameters(bool one if (isOffload) { config.offloadInfo.info(generateOffloadInfo(config.base)); } - result.emplace_back(device, mixPort.getName(), config, flags); + result.emplace_back(device, mixPort.getName(), attachedDeviceAddress.value(), + config, flags); if (oneProfilePerDevice) break; } if (oneProfilePerDevice) break; @@ -162,13 +155,16 @@ const std::vector<DeviceConfigParameter>& getOutputDeviceInvalidConfigParameters profile.getFormat(), static_cast<uint32_t>(profile.getSamplingRates()[0]), toString(profile.getChannelMasks()[0])}; + DeviceAddress defaultDevice = { + toString(xsd::AudioDevice::AUDIO_DEVICE_OUT_DEFAULT), {}}; { AudioConfig config{.base = validBase}; config.base.channelMask = "random_string"; if (isOffload) { config.offloadInfo.info(generateOffloadInfo(validBase)); } - result.emplace_back(device, mixPort.getName(), config, validFlags); + result.emplace_back(device, mixPort.getName(), defaultDevice, config, + validFlags); } { AudioConfig config{.base = validBase}; @@ -176,7 +172,8 @@ const std::vector<DeviceConfigParameter>& getOutputDeviceInvalidConfigParameters if (isOffload) { config.offloadInfo.info(generateOffloadInfo(validBase)); } - result.emplace_back(device, mixPort.getName(), config, validFlags); + result.emplace_back(device, mixPort.getName(), defaultDevice, config, + validFlags); } if (generateInvalidFlags) { AudioConfig config{.base = validBase}; @@ -184,32 +181,37 @@ const std::vector<DeviceConfigParameter>& getOutputDeviceInvalidConfigParameters config.offloadInfo.info(generateOffloadInfo(validBase)); } std::vector<AudioInOutFlag> flags = {"random_string", ""}; - result.emplace_back(device, mixPort.getName(), config, flags); + result.emplace_back(device, mixPort.getName(), defaultDevice, config, + flags); } if (isOffload) { { AudioConfig config{.base = validBase}; config.offloadInfo.info(generateOffloadInfo(validBase)); config.offloadInfo.info().base.channelMask = "random_string"; - result.emplace_back(device, mixPort.getName(), config, validFlags); + result.emplace_back(device, mixPort.getName(), defaultDevice, config, + validFlags); } { AudioConfig config{.base = validBase}; config.offloadInfo.info(generateOffloadInfo(validBase)); config.offloadInfo.info().base.format = "random_string"; - result.emplace_back(device, mixPort.getName(), config, validFlags); + result.emplace_back(device, mixPort.getName(), defaultDevice, config, + validFlags); } { AudioConfig config{.base = validBase}; config.offloadInfo.info(generateOffloadInfo(validBase)); config.offloadInfo.info().streamType = "random_string"; - result.emplace_back(device, mixPort.getName(), config, validFlags); + result.emplace_back(device, mixPort.getName(), defaultDevice, config, + validFlags); } { AudioConfig config{.base = validBase}; config.offloadInfo.info(generateOffloadInfo(validBase)); config.offloadInfo.info().usage = "random_string"; - result.emplace_back(device, mixPort.getName(), config, validFlags); + result.emplace_back(device, mixPort.getName(), defaultDevice, config, + validFlags); } hasOffloadConfig = true; } else { @@ -233,11 +235,10 @@ std::vector<DeviceConfigParameter> generateInputDeviceConfigParameters(bool oneP if (!module || !module->getFirstMixPorts()) break; for (const auto& mixPort : module->getFirstMixPorts()->getMixPort()) { if (mixPort.getRole() != xsd::Role::sink) continue; // not an input profile - if (getCachedPolicyConfig() - .getAttachedSourceDeviceForMixPort(moduleName, mixPort.getName()) - .empty()) { - continue; // no attached device - } + const auto attachedDeviceAddress = + getCachedPolicyConfig().getDeviceAddressOfSourceDeviceAttachedToMixPort( + moduleName, mixPort.getName()); + if (!attachedDeviceAddress.has_value()) continue; std::vector<AudioInOutFlag> flags; if (mixPort.hasFlags()) { std::transform(mixPort.getFlags().begin(), mixPort.getFlags().end(), @@ -250,7 +251,8 @@ std::vector<DeviceConfigParameter> generateInputDeviceConfigParameters(bool oneP auto configs = combineAudioConfig(profile.getChannelMasks(), profile.getSamplingRates(), profile.getFormat()); for (const auto& config : configs) { - result.emplace_back(device, mixPort.getName(), config, flags); + result.emplace_back(device, mixPort.getName(), attachedDeviceAddress.value(), + config, flags); if (oneProfilePerDevice) break; } if (oneProfilePerDevice) break; @@ -298,20 +300,25 @@ const std::vector<DeviceConfigParameter>& getInputDeviceInvalidConfigParameters( profile.getFormat(), static_cast<uint32_t>(profile.getSamplingRates()[0]), toString(profile.getChannelMasks()[0])}; + DeviceAddress defaultDevice = { + toString(xsd::AudioDevice::AUDIO_DEVICE_IN_DEFAULT), {}}; { AudioConfig config{.base = validBase}; config.base.channelMask = "random_string"; - result.emplace_back(device, mixPort.getName(), config, validFlags); + result.emplace_back(device, mixPort.getName(), defaultDevice, config, + validFlags); } { AudioConfig config{.base = validBase}; config.base.format = "random_string"; - result.emplace_back(device, mixPort.getName(), config, validFlags); + result.emplace_back(device, mixPort.getName(), defaultDevice, config, + validFlags); } if (generateInvalidFlags) { AudioConfig config{.base = validBase}; std::vector<AudioInOutFlag> flags = {"random_string", ""}; - result.emplace_back(device, mixPort.getName(), config, flags); + result.emplace_back(device, mixPort.getName(), defaultDevice, config, + flags); } hasConfig = true; break; diff --git a/audio/core/all-versions/vts/functional/7.0/PolicyConfig.h b/audio/core/all-versions/vts/functional/7.0/PolicyConfig.h index 4aea503938..c1d5669775 100644 --- a/audio/core/all-versions/vts/functional/7.0/PolicyConfig.h +++ b/audio/core/all-versions/vts/functional/7.0/PolicyConfig.h @@ -61,6 +61,18 @@ class PolicyConfig { const std::set<std::string>& getModulesWithDevicesNames() const { return mModulesWithDevicesNames; } + std::optional<DeviceAddress> getDeviceAddressOfSinkDeviceAttachedToMixPort( + const std::string& moduleName, const std::string& mixPortName) const { + const auto attachedDevicePort = getAttachedSinkDeviceForMixPort(moduleName, mixPortName); + if (attachedDevicePort.empty()) return {}; + return getDeviceAddressOfDevicePort(moduleName, attachedDevicePort); + } + std::optional<DeviceAddress> getDeviceAddressOfSourceDeviceAttachedToMixPort( + const std::string& moduleName, const std::string& mixPortName) const { + const auto attachedDevicePort = getAttachedSourceDeviceForMixPort(moduleName, mixPortName); + if (attachedDevicePort.empty()) return {}; + return getDeviceAddressOfDevicePort(moduleName, attachedDevicePort); + } std::string getAttachedSinkDeviceForMixPort(const std::string& moduleName, const std::string& mixPortName) const { return findAttachedDevice(getAttachedDevices(moduleName), @@ -84,8 +96,6 @@ class PolicyConfig { const std::vector<std::string>& getAttachedDevices(const std::string& moduleName) const; std::optional<DeviceAddress> getDeviceAddressOfDevicePort( const std::string& moduleName, const std::string& devicePortName) const; - std::string getDevicePortTagNameFromType(const std::string& moduleName, - const AudioDevice& deviceType) const; std::set<std::string> getSinkDevicesForMixPort(const std::string& moduleName, const std::string& mixPortName) const; std::set<std::string> getSourceDevicesForMixPort(const std::string& moduleName, diff --git a/audio/core/all-versions/vts/functional/Android.bp b/audio/core/all-versions/vts/functional/Android.bp index c757032e0f..daed7a8afd 100644 --- a/audio/core/all-versions/vts/functional/Android.bp +++ b/audio/core/all-versions/vts/functional/Android.bp @@ -34,6 +34,7 @@ cc_defaults { ], shared_libs: [ "libbinder", + "libcutils", "libfmq", "libxml2", ], @@ -190,6 +191,7 @@ cc_test { ], data: [ ":audio_policy_configuration_V7_0", + "data/sine882hz3s.mp3", ], // Use test_config for vts suite. // TODO(b/146104851): Add auto-gen rules and remove it. @@ -223,6 +225,7 @@ cc_test { ], data: [ ":audio_policy_configuration_V7_1", + "data/sine882hz3s.mp3", ], // Use test_config for vts suite. // TODO(b/146104851): Add auto-gen rules and remove it. diff --git a/audio/core/all-versions/vts/functional/AudioPrimaryHidlHalTest.h b/audio/core/all-versions/vts/functional/AudioPrimaryHidlHalTest.h index 38e9e5f467..e46e5b4f52 100644 --- a/audio/core/all-versions/vts/functional/AudioPrimaryHidlHalTest.h +++ b/audio/core/all-versions/vts/functional/AudioPrimaryHidlHalTest.h @@ -617,7 +617,8 @@ static std::string DeviceConfigParameterToString( std::get<PARAM_FLAGS>(info.param))); #elif MAJOR_VERSION >= 7 const auto configPart = - std::to_string(config.base.sampleRateHz) + "_" + + ::testing::PrintToString(std::get<PARAM_ATTACHED_DEV_ADDR>(info.param).deviceType) + + "_" + std::to_string(config.base.sampleRateHz) + "_" + // The channel masks and flags are vectors of strings, just need to sanitize them. SanitizeStringForGTestName(::testing::PrintToString(config.base.channelMask)) + "_" + SanitizeStringForGTestName(::testing::PrintToString(std::get<PARAM_FLAGS>(info.param))); @@ -658,6 +659,9 @@ class AudioHidlTestWithDeviceConfigParameter std::get<INDEX_OUTPUT>(std::get<PARAM_FLAGS>(GetParam()))); } #elif MAJOR_VERSION >= 7 + DeviceAddress getAttachedDeviceAddress() const { + return std::get<PARAM_ATTACHED_DEV_ADDR>(GetParam()); + } hidl_vec<AudioInOutFlag> getInputFlags() const { return std::get<PARAM_FLAGS>(GetParam()); } hidl_vec<AudioInOutFlag> getOutputFlags() const { return std::get<PARAM_FLAGS>(GetParam()); } #endif @@ -933,6 +937,15 @@ class StreamWriter : public StreamWorker<StreamWriter> { StreamWriter(IStreamOut* stream, size_t bufferSize) : mStream(stream), mBufferSize(bufferSize), mData(mBufferSize) {} + StreamWriter(IStreamOut* stream, size_t bufferSize, std::vector<uint8_t>&& data, + std::function<void()> onDataStart, std::function<bool()> onDataWrap) + : mStream(stream), + mBufferSize(bufferSize), + mData(std::move(data)), + mOnDataStart(onDataStart), + mOnDataWrap(onDataWrap) { + ALOGI("StreamWriter data size: %d", (int)mData.size()); + } ~StreamWriter() { stop(); if (mEfGroup) { @@ -998,9 +1011,12 @@ class StreamWriter : public StreamWorker<StreamWriter> { ALOGE("command message queue write failed"); return false; } - const size_t dataSize = std::min(mData.size(), mDataMQ->availableToWrite()); - bool success = mDataMQ->write(mData.data(), dataSize); + if (mDataPosition == 0) mOnDataStart(); + const size_t dataSize = std::min(mData.size() - mDataPosition, mDataMQ->availableToWrite()); + bool success = mDataMQ->write(mData.data() + mDataPosition, dataSize); ALOGE_IF(!success, "data message queue write failed"); + mDataPosition += dataSize; + if (mDataPosition >= mData.size()) mDataPosition = 0; mEfGroup->wake(static_cast<uint32_t>(MessageQueueFlagBits::NOT_EMPTY)); uint32_t efState = 0; @@ -1026,6 +1042,9 @@ class StreamWriter : public StreamWorker<StreamWriter> { ALOGE("bad wait status: %d", ret); success = false; } + if (success && mDataPosition == 0) { + success = mOnDataWrap(); + } return success; } @@ -1033,6 +1052,9 @@ class StreamWriter : public StreamWorker<StreamWriter> { IStreamOut* const mStream; const size_t mBufferSize; std::vector<uint8_t> mData; + std::function<void()> mOnDataStart = []() {}; + std::function<bool()> mOnDataWrap = []() { return true; }; + size_t mDataPosition = 0; std::unique_ptr<CommandMQ> mCommandMQ; std::unique_ptr<DataMQ> mDataMQ; std::unique_ptr<StatusMQ> mStatusMQ; @@ -1047,7 +1069,7 @@ class OutputStreamTest #if MAJOR_VERSION <= 6 address.device = AudioDevice::OUT_DEFAULT; #elif MAJOR_VERSION >= 7 - address.deviceType = toString(xsd::AudioDevice::AUDIO_DEVICE_OUT_DEFAULT); + address = getAttachedDeviceAddress(); #endif const AudioConfig& config = getConfig(); auto flags = getOutputFlags(); @@ -1243,16 +1265,11 @@ class InputStreamTest #if MAJOR_VERSION <= 6 address.device = AudioDevice::IN_DEFAULT; #elif MAJOR_VERSION >= 7 - auto maybeSourceAddress = getCachedPolicyConfig().getSourceDeviceForMixPort( - getDeviceName(), getMixPortName()); + address = getAttachedDeviceAddress(); auto& metadata = initMetadata.tracks[0]; - if (maybeSourceAddress.has_value() && - !xsd::isTelephonyDevice(maybeSourceAddress.value().deviceType)) { - address = maybeSourceAddress.value(); + if (!xsd::isTelephonyDevice(address.deviceType)) { metadata.source = toString(xsd::AudioSource::AUDIO_SOURCE_UNPROCESSED); metadata.channelMask = getConfig().base.channelMask; - } else { - address.deviceType = toString(xsd::AudioDevice::AUDIO_DEVICE_IN_DEFAULT); } #if MAJOR_VERSION == 7 && MINOR_VERSION >= 1 auto flagsIt = std::find(flags.begin(), flags.end(), diff --git a/audio/core/all-versions/vts/functional/AudioTestDefinitions.h b/audio/core/all-versions/vts/functional/AudioTestDefinitions.h index 802b87bc36..3de06c35ac 100644 --- a/audio/core/all-versions/vts/functional/AudioTestDefinitions.h +++ b/audio/core/all-versions/vts/functional/AudioTestDefinitions.h @@ -39,9 +39,10 @@ using DeviceConfigParameter = std::tuple< std::variant<android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::AudioInputFlag, android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::AudioOutputFlag>>; #elif MAJOR_VERSION >= 7 -enum { PARAM_DEVICE, PARAM_PORT_NAME, PARAM_CONFIG, PARAM_FLAGS }; +enum { PARAM_DEVICE, PARAM_PORT_NAME, PARAM_ATTACHED_DEV_ADDR, PARAM_CONFIG, PARAM_FLAGS }; using DeviceConfigParameter = std::tuple<DeviceParameter, std::string, + android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::DeviceAddress, android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::AudioConfig, std::vector<android::hardware::audio::CORE_TYPES_CPP_VERSION::AudioInOutFlag>>; #endif diff --git a/audio/core/all-versions/vts/functional/VtsHalAudioV7_0TargetTest.xml b/audio/core/all-versions/vts/functional/VtsHalAudioV7_0TargetTest.xml index f0e26958b9..8da5744089 100644 --- a/audio/core/all-versions/vts/functional/VtsHalAudioV7_0TargetTest.xml +++ b/audio/core/all-versions/vts/functional/VtsHalAudioV7_0TargetTest.xml @@ -29,6 +29,7 @@ <option name="cleanup" value="true" /> <option name="push" value="VtsHalAudioV7_0TargetTest->/data/local/tmp/VtsHalAudioV7_0TargetTest" /> <option name="push" value="audio_policy_configuration_V7_0.xsd->/data/local/tmp/audio_policy_configuration_V7_0.xsd" /> + <option name="push" value="sine882hz3s.mp3->/data/local/tmp/sine882hz3s.mp3" /> </target_preparer> <test class="com.android.tradefed.testtype.GTest" > diff --git a/audio/core/all-versions/vts/functional/VtsHalAudioV7_1TargetTest.xml b/audio/core/all-versions/vts/functional/VtsHalAudioV7_1TargetTest.xml index 7ce1477e1a..227df1803d 100644 --- a/audio/core/all-versions/vts/functional/VtsHalAudioV7_1TargetTest.xml +++ b/audio/core/all-versions/vts/functional/VtsHalAudioV7_1TargetTest.xml @@ -29,6 +29,8 @@ <option name="cleanup" value="true" /> <option name="push" value="VtsHalAudioV7_1TargetTest->/data/local/tmp/VtsHalAudioV7_1TargetTest" /> <option name="push" value="audio_policy_configuration_V7_1.xsd->/data/local/tmp/audio_policy_configuration_V7_1.xsd" /> + <option name="push" value="sine882hz3s.mp3->/data/local/tmp/sine882hz3s.mp3" /> + </target_preparer> <test class="com.android.tradefed.testtype.GTest" > diff --git a/audio/core/all-versions/vts/functional/data/sine882hz3s.mp3 b/audio/core/all-versions/vts/functional/data/sine882hz3s.mp3 Binary files differnew file mode 100644 index 0000000000..0604f9b3b4 --- /dev/null +++ b/audio/core/all-versions/vts/functional/data/sine882hz3s.mp3 diff --git a/audio/effect/all-versions/default/Effect.cpp b/audio/effect/all-versions/default/Effect.cpp index 3baafc9343..87e1ab7a7d 100644 --- a/audio/effect/all-versions/default/Effect.cpp +++ b/audio/effect/all-versions/default/Effect.cpp @@ -25,8 +25,11 @@ #define ATRACE_TAG ATRACE_TAG_AUDIO #include <HidlUtils.h> #include <android/log.h> +#include <cutils/properties.h> #include <media/EffectsFactoryApi.h> #include <mediautils/ScopedStatistics.h> +#include <sys/syscall.h> +#include <system/audio_effects/effect_spatializer.h> #include <util/EffectUtils.h> #include <utils/Trace.h> @@ -47,6 +50,160 @@ using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::implementati namespace { +/** + * Some basic scheduling tools. + */ +namespace scheduler { + +int getCpu() { + return sched_getcpu(); +} + +uint64_t getAffinity(pid_t tid) { + cpu_set_t set; + CPU_ZERO_S(sizeof(set), &set); + + if (sched_getaffinity(tid, sizeof(set), &set)) { + ALOGW("%s: for tid:%d returning 0, failed %s", __func__, tid, strerror(errno)); + return 0; + } + const int count = CPU_COUNT_S(sizeof(set), &set); + uint64_t mask = 0; + for (int i = 0; i < CPU_SETSIZE; ++i) { + if (CPU_ISSET_S(i, sizeof(set), &set)) { + mask |= 1 << i; + } + } + ALOGV("%s: for tid:%d returning cpu count %d mask %llu", __func__, tid, count, + (unsigned long long)mask); + return mask; +} + +status_t setAffinity(pid_t tid, uint64_t mask) { + cpu_set_t set; + CPU_ZERO_S(sizeof(set), &set); + + for (uint64_t m = mask; m != 0;) { + uint64_t tz = __builtin_ctz(m); + CPU_SET_S(tz, sizeof(set), &set); + m &= ~(1 << tz); + } + if (sched_setaffinity(tid, sizeof(set), &set)) { + ALOGW("%s: for tid:%d setting cpu mask %llu failed %s", __func__, tid, + (unsigned long long)mask, strerror(errno)); + return -errno; + } + ALOGV("%s: for tid:%d setting cpu mask %llu", __func__, tid, (unsigned long long)mask); + return OK; +} + +__unused status_t setPriority(pid_t tid, int policy, int priority) { + struct sched_param param { + .sched_priority = priority, + }; + if (sched_setscheduler(tid, policy, ¶m) != 0) { + ALOGW("%s: Cannot set FIFO priority for tid %d to policy %d priority %d %s", __func__, tid, + policy, priority, strerror(errno)); + return -errno; + } + ALOGV("%s: Successfully set priority for tid %d to policy %d priority %d", __func__, tid, + policy, priority); + return NO_ERROR; +} + +status_t setUtilMin(pid_t tid, uint32_t utilMin) { + // Currently, there is no wrapper in bionic: b/183240349. + struct { + uint32_t size; + uint32_t sched_policy; + uint64_t sched_flags; + int32_t sched_nice; + uint32_t sched_priority; + uint64_t sched_runtime; + uint64_t sched_deadline; + uint64_t sched_period; + uint32_t sched_util_min; + uint32_t sched_util_max; + } attr{ + .size = sizeof(attr), + .sched_flags = SCHED_FLAG_KEEP_ALL | SCHED_FLAG_UTIL_CLAMP_MIN, + .sched_util_min = utilMin, + }; + + if (syscall(__NR_sched_setattr, tid, &attr, 0 /* flags */)) { + ALOGW("%s: Cannot set sched_util_min for pid %d to %u %s", __func__, tid, utilMin, + strerror(errno)); + return -errno; + } + ALOGV("%s: Successfully set sched_util_min for pid %d to %u", __func__, tid, utilMin); + return NO_ERROR; +} + +/* + Attempts to raise the priority and usage of tid for spatialization. + Returns OK if everything works. +*/ +status_t updateSpatializerPriority(pid_t tid) { + status_t status = OK; + + const int cpu = getCpu(); + ALOGV("%s: current CPU:%d", __func__, cpu); + + const auto currentAffinity = getAffinity(tid); + ALOGV("%s: current Affinity:%llx", __func__, (unsigned long long)currentAffinity); + + // Set the desired CPU core affinity. + // Typically this would be done to move the Spatializer effect off of the little cores. + // The mid cores and large cores typically have more FP/NEON units + // and will advantageously reduce power and prevent glitches due CPU limitations. + // + // Since this is SOC dependent, we do not set the core affinity here but + // prefer to set the util_clamp_min below. + // + constexpr uint64_t kDefaultAffinity = 0; + const int32_t desiredAffinity = + property_get_int32("audio.spatializer.effect.affinity", kDefaultAffinity); + if (desiredAffinity != 0 && (desiredAffinity & ~currentAffinity) == 0) { + const status_t localStatus = setAffinity(tid, desiredAffinity); + status = status ? status : localStatus; + } + + // Set the util_clamp_min. + // This is beneficial to reduce glitches when starting up, or due to scheduler + // thread statistics reset (e.g. core migration), which cause the CPU frequency to drop + // to minimum. + // + // Experimentation has found that moving to a mid core over a little core reduces + // power if the mid core (e.g. A76/78) has more (e.g. 2x) FP/NEON units + // than the little core (e.g. A55). + // A possible value is 300. + // + constexpr uint32_t kUtilMin = 0; + const int32_t utilMin = property_get_int32("audio.spatializer.effect.util_clamp_min", kUtilMin); + if (utilMin > 0 && utilMin <= 1024) { + const status_t localStatus = setUtilMin(tid, utilMin); + status = status ? status : localStatus; + } + +#if 0 + // Provided for local vendor testing but not enabled as audioserver does this for us. + // + // Set priority if specified. + constexpr int32_t kRTPriorityMin = 1; + constexpr int32_t kRTPriorityMax = 3; + const int32_t priorityBoost = + property_get_int32("audio.spatializer.priority", kRTPriorityMin); + if (priorityBoost >= kRTPriorityMin && priorityBoost <= kRTPriorityMax) { + const status_t localStatus = scheduler::setPriority(threadId, SCHED_FIFO, priorityBoost); + status = status ? status : localStatus; + } +#endif + + return status; +} + +} // namespace scheduler + #define SCOPED_STATS() \ ::android::mediautils::ScopedStatistics scopedStatistics { \ std::string("EffectHal::").append(__func__), mEffectHal->mStatistics \ @@ -83,6 +240,16 @@ class ProcessThread : public Thread { }; bool ProcessThread::threadLoop() { + // For a spatializer effect, we perform scheduler adjustments to reduce glitches and power. + { + effect_descriptor_t halDescriptor{}; + if ((*mEffect)->get_descriptor(mEffect, &halDescriptor) == NO_ERROR && + memcmp(&halDescriptor.type, FX_IID_SPATIALIZER, sizeof(effect_uuid_t)) == 0) { + const status_t status = scheduler::updateSpatializerPriority(gettid()); + ALOGW_IF(status != OK, "Failed to update Spatializer priority"); + } + } + // This implementation doesn't return control back to the Thread until it decides to stop, // as the Thread uses mutexes, and this can lead to priority inversion. while (!std::atomic_load_explicit(mStop, std::memory_order_acquire)) { @@ -238,12 +405,27 @@ void Effect::effectOffloadParamToHal(const EffectOffloadParameter& offload, } // static -std::vector<uint8_t> Effect::parameterToHal(uint32_t paramSize, const void* paramData, - uint32_t valueSize, const void** valueData) { +bool Effect::parameterToHal(uint32_t paramSize, const void* paramData, uint32_t valueSize, + const void** valueData, std::vector<uint8_t>* halParamBuffer) { + constexpr size_t kMaxSize = EFFECT_PARAM_SIZE_MAX - sizeof(effect_param_t); + if (paramSize > kMaxSize) { + ALOGE("%s: Parameter size is too big: %" PRIu32, __func__, paramSize); + return false; + } size_t valueOffsetFromData = alignedSizeIn<uint32_t>(paramSize) * sizeof(uint32_t); + if (valueOffsetFromData > kMaxSize) { + ALOGE("%s: Aligned parameter size is too big: %zu", __func__, valueOffsetFromData); + return false; + } + if (valueSize > kMaxSize - valueOffsetFromData) { + ALOGE("%s: Value size is too big: %" PRIu32 ", max size is %zu", __func__, valueSize, + kMaxSize - valueOffsetFromData); + android_errorWriteLog(0x534e4554, "237291425"); + return false; + } size_t halParamBufferSize = sizeof(effect_param_t) + valueOffsetFromData + valueSize; - std::vector<uint8_t> halParamBuffer(halParamBufferSize, 0); - effect_param_t* halParam = reinterpret_cast<effect_param_t*>(&halParamBuffer[0]); + halParamBuffer->resize(halParamBufferSize, 0); + effect_param_t* halParam = reinterpret_cast<effect_param_t*>(halParamBuffer->data()); halParam->psize = paramSize; halParam->vsize = valueSize; memcpy(halParam->data, paramData, paramSize); @@ -256,7 +438,7 @@ std::vector<uint8_t> Effect::parameterToHal(uint32_t paramSize, const void* para *valueData = halParam->data + valueOffsetFromData; } } - return halParamBuffer; + return true; } Result Effect::analyzeCommandStatus(const char* commandName, const char* context, status_t status) { @@ -301,6 +483,11 @@ void Effect::getConfigImpl(int commandCode, const char* commandName, GetConfigCa Result Effect::getCurrentConfigImpl(uint32_t featureId, uint32_t configSize, GetCurrentConfigSuccessCallback onSuccess) { + if (configSize > kMaxDataSize - sizeof(uint32_t)) { + ALOGE("%s: Config size is too big: %" PRIu32, __func__, configSize); + android_errorWriteLog(0x534e4554, "240266798"); + return Result::INVALID_ARGUMENTS; + } uint32_t halCmd = featureId; std::vector<uint32_t> halResult(alignedSizeIn<uint32_t>(sizeof(uint32_t) + configSize), 0); uint32_t halResultSize = 0; @@ -314,11 +501,15 @@ Result Effect::getParameterImpl(uint32_t paramSize, const void* paramData, GetParameterSuccessCallback onSuccess) { // As it is unknown what method HAL uses for copying the provided parameter data, // it is safer to make sure that input and output buffers do not overlap. - std::vector<uint8_t> halCmdBuffer = - parameterToHal(paramSize, paramData, requestValueSize, nullptr); + std::vector<uint8_t> halCmdBuffer; + if (!parameterToHal(paramSize, paramData, requestValueSize, nullptr, &halCmdBuffer)) { + return Result::INVALID_ARGUMENTS; + } const void* valueData = nullptr; - std::vector<uint8_t> halParamBuffer = - parameterToHal(paramSize, paramData, replyValueSize, &valueData); + std::vector<uint8_t> halParamBuffer; + if (!parameterToHal(paramSize, paramData, replyValueSize, &valueData, &halParamBuffer)) { + return Result::INVALID_ARGUMENTS; + } uint32_t halParamBufferSize = halParamBuffer.size(); return sendCommandReturningStatusAndData( @@ -331,8 +522,12 @@ Result Effect::getParameterImpl(uint32_t paramSize, const void* paramData, Result Effect::getSupportedConfigsImpl(uint32_t featureId, uint32_t maxConfigs, uint32_t configSize, GetSupportedConfigsSuccessCallback onSuccess) { + if (maxConfigs != 0 && configSize > (kMaxDataSize - 2 * sizeof(uint32_t)) / maxConfigs) { + ALOGE("%s: Config size is too big: %" PRIu32, __func__, configSize); + return Result::INVALID_ARGUMENTS; + } uint32_t halCmd[2] = {featureId, maxConfigs}; - uint32_t halResultSize = 2 * sizeof(uint32_t) + maxConfigs * sizeof(configSize); + uint32_t halResultSize = 2 * sizeof(uint32_t) + maxConfigs * configSize; std::vector<uint8_t> halResult(static_cast<size_t>(halResultSize), 0); return sendCommandReturningStatusAndData( EFFECT_CMD_GET_FEATURE_SUPPORTED_CONFIGS, "GET_FEATURE_SUPPORTED_CONFIGS", sizeof(halCmd), @@ -472,8 +667,10 @@ Result Effect::setConfigImpl(int commandCode, const char* commandName, const Eff Result Effect::setParameterImpl(uint32_t paramSize, const void* paramData, uint32_t valueSize, const void* valueData) { - std::vector<uint8_t> halParamBuffer = - parameterToHal(paramSize, paramData, valueSize, &valueData); + std::vector<uint8_t> halParamBuffer; + if (!parameterToHal(paramSize, paramData, valueSize, &valueData, &halParamBuffer)) { + return Result::INVALID_ARGUMENTS; + } return sendCommandReturningStatus(EFFECT_CMD_SET_PARAM, "SET_PARAM", halParamBuffer.size(), &halParamBuffer[0]); } @@ -670,8 +867,21 @@ Return<void> Effect::command(uint32_t commandId, const hidl_vec<uint8_t>& data, void* dataPtr = halDataSize > 0 ? &halData[0] : NULL; void* resultPtr = halResultSize > 0 ? &halResult[0] : NULL; - status_t status = - (*mHandle)->command(mHandle, commandId, halDataSize, dataPtr, &halResultSize, resultPtr); + status_t status = BAD_VALUE; + switch (commandId) { + case 'gtid': // retrieve the tid, used for spatializer priority boost + if (halDataSize == 0 && resultMaxSize == sizeof(int32_t)) { + auto ptid = (int32_t*)resultPtr; + ptid[0] = mProcessThread ? mProcessThread->getTid() : -1; + status = OK; + break; // we have handled 'gtid' here. + } + [[fallthrough]]; // allow 'gtid' overload (checked halDataSize and resultMaxSize). + default: + status = (*mHandle)->command(mHandle, commandId, halDataSize, dataPtr, &halResultSize, + resultPtr); + break; + } hidl_vec<uint8_t> result; if (status == OK && resultPtr != NULL) { result.setToExternal(&halResult[0], halResultSize); diff --git a/audio/effect/all-versions/default/Effect.h b/audio/effect/all-versions/default/Effect.h index 011544d760..5d8dcccba6 100644 --- a/audio/effect/all-versions/default/Effect.h +++ b/audio/effect/all-versions/default/Effect.h @@ -184,6 +184,9 @@ struct Effect : public IEffect { using GetSupportedConfigsSuccessCallback = std::function<void(uint32_t supportedConfigs, void* configsData)>; + // Sets the limit on the maximum size of vendor-provided data structures. + static constexpr size_t kMaxDataSize = 1 << 20; + static const char* sContextResultOfCommand; static const char* sContextCallToCommand; static const char* sContextCallFunction; @@ -211,8 +214,8 @@ struct Effect : public IEffect { channel_config_t* halConfig); static void effectOffloadParamToHal(const EffectOffloadParameter& offload, effect_offload_param_t* halOffload); - static std::vector<uint8_t> parameterToHal(uint32_t paramSize, const void* paramData, - uint32_t valueSize, const void** valueData); + static bool parameterToHal(uint32_t paramSize, const void* paramData, uint32_t valueSize, + const void** valueData, std::vector<uint8_t>* halParamBuffer); Result analyzeCommandStatus(const char* commandName, const char* context, status_t status); void getConfigImpl(int commandCode, const char* commandName, GetConfigCallback cb); diff --git a/audio/effect/all-versions/default/EffectsFactory.cpp b/audio/effect/all-versions/default/EffectsFactory.cpp index e93ad893a8..9bf309c224 100644 --- a/audio/effect/all-versions/default/EffectsFactory.cpp +++ b/audio/effect/all-versions/default/EffectsFactory.cpp @@ -32,6 +32,7 @@ #include <UuidUtils.h> #include <android/log.h> +#include <hidl/HidlTransportSupport.h> #include <media/EffectsFactoryApi.h> #include <system/audio_effects/effect_aec.h> #include <system/audio_effects/effect_agc.h> @@ -44,6 +45,7 @@ #include <system/audio_effects/effect_presetreverb.h> #include <system/audio_effects/effect_virtualizer.h> #include <system/audio_effects/effect_visualizer.h> +#include <system/thread_defs.h> #include <util/EffectUtils.h> namespace android { @@ -189,6 +191,7 @@ Return<void> EffectsFactory::createEffectImpl(const Uuid& uuid, int32_t session, status = (*handle)->get_descriptor(handle, &halDescriptor); if (status == OK) { effect = dispatchEffectInstanceCreation(halDescriptor, handle); + android::hardware::setMinSchedulerPolicy(effect, SCHED_NORMAL, ANDROID_PRIORITY_AUDIO); effectId = EffectMap::getInstance().add(handle); } else { ALOGE("Error querying effect descriptor for %s: %s", diff --git a/audio/effect/all-versions/vts/functional/VtsHalAudioEffectTargetTest.cpp b/audio/effect/all-versions/vts/functional/VtsHalAudioEffectTargetTest.cpp index e59423fa98..d95bb06c3a 100644 --- a/audio/effect/all-versions/vts/functional/VtsHalAudioEffectTargetTest.cpp +++ b/audio/effect/all-versions/vts/functional/VtsHalAudioEffectTargetTest.cpp @@ -35,6 +35,7 @@ #include <common/all-versions/VersionUtils.h> +#include <cutils/properties.h> #include <gtest/gtest.h> #include <hidl/GtestPrinter.h> #include <hidl/ServiceManagement.h> @@ -623,6 +624,27 @@ TEST_P(AudioEffectHidlTest, GetParameter) { EXPECT_TRUE(ret.isOk()); } +TEST_P(AudioEffectHidlTest, GetParameterInvalidMaxReplySize) { + description("Verify that GetParameter caps the maximum reply size"); + const bool isNewDeviceLaunchingOnTPlus = property_get_int32("ro.vendor.api_level", 0) >= 33; + if (!isNewDeviceLaunchingOnTPlus) { + GTEST_SKIP() << "The test only applies to devices launching on T or later"; + } + // Use a non-empty parameter to avoid being rejected by any earlier checks. + hidl_vec<uint8_t> parameter; + parameter.resize(16); + // Use very large size to ensure that the service does not crash. Since parameters + // are specific to each effect, and some effects may not have parameters at all, + // simply checking the return value would not reveal an issue of using an uncapped value. + const uint32_t veryLargeReplySize = std::numeric_limits<uint32_t>::max() - 100; + Result retval = Result::OK; + Return<void> ret = + effect->getParameter(parameter, veryLargeReplySize, + [&](Result r, const hidl_vec<uint8_t>&) { retval = r; }); + EXPECT_TRUE(ret.isOk()); + EXPECT_EQ(Result::INVALID_ARGUMENTS, retval); +} + TEST_P(AudioEffectHidlTest, GetSupportedConfigsForFeature) { description("Verify that GetSupportedConfigsForFeature does not crash"); Return<void> ret = effect->getSupportedConfigsForFeature( @@ -643,6 +665,37 @@ TEST_P(AudioEffectHidlTest, SetCurrentConfigForFeature) { EXPECT_TRUE(ret.isOk()); } +TEST_P(AudioEffectHidlTest, GetSupportedConfigsForFeatureInvalidConfigSize) { + description("Verify that GetSupportedConfigsForFeature caps the maximum config size"); + const bool isNewDeviceLaunchingOnTPlus = property_get_int32("ro.vendor.api_level", 0) >= 33; + if (!isNewDeviceLaunchingOnTPlus) { + GTEST_SKIP() << "The test only applies to devices launching on T or later"; + } + // Use very large size to ensure that the service does not crash. + const uint32_t veryLargeConfigSize = std::numeric_limits<uint32_t>::max() - 100; + Result retval = Result::OK; + Return<void> ret = effect->getSupportedConfigsForFeature( + 0, 1, veryLargeConfigSize, + [&](Result r, uint32_t, const hidl_vec<uint8_t>&) { retval = r; }); + EXPECT_TRUE(ret.isOk()); + EXPECT_EQ(Result::INVALID_ARGUMENTS, retval); +} + +TEST_P(AudioEffectHidlTest, GetCurrentConfigForFeatureInvalidConfigSize) { + description("Verify that GetCurrentConfigForFeature caps the maximum config size"); + const bool isNewDeviceLaunchingOnTPlus = property_get_int32("ro.vendor.api_level", 0) >= 33; + if (!isNewDeviceLaunchingOnTPlus) { + GTEST_SKIP() << "The test only applies to devices launching on T or later"; + } + // Use very large size to ensure that the service does not crash. + const uint32_t veryLargeConfigSize = std::numeric_limits<uint32_t>::max() - 100; + Result retval = Result::OK; + Return<void> ret = effect->getCurrentConfigForFeature( + 0, veryLargeConfigSize, [&](Result r, const hidl_vec<uint8_t>&) { retval = r; }); + EXPECT_TRUE(ret.isOk()); + EXPECT_EQ(Result::INVALID_ARGUMENTS, retval); +} + // The main test class for Equalizer Audio Effect HIDL HAL. class EqualizerAudioEffectHidlTest : public AudioEffectHidlTest { public: diff --git a/automotive/evs/aidl/android/hardware/automotive/evs/EvsEventDesc.aidl b/automotive/evs/aidl/android/hardware/automotive/evs/EvsEventDesc.aidl index ebff98f077..3abdb54e6c 100644 --- a/automotive/evs/aidl/android/hardware/automotive/evs/EvsEventDesc.aidl +++ b/automotive/evs/aidl/android/hardware/automotive/evs/EvsEventDesc.aidl @@ -33,7 +33,9 @@ parcelable EvsEventDesc { @utf8InCpp String deviceId; /** - * Possible additional vendor information that is opaque to the EvsManager + * Possible additional vendor information that is opaque to the EvsManager. + * The size of the payload must not exceed 16-byte if the HIDL recipients are + * expected to exist. */ int[] payload; } diff --git a/automotive/evs/aidl/android/hardware/automotive/evs/IEvsCameraStream.aidl b/automotive/evs/aidl/android/hardware/automotive/evs/IEvsCameraStream.aidl index 2c2b44caf5..c599d58635 100644 --- a/automotive/evs/aidl/android/hardware/automotive/evs/IEvsCameraStream.aidl +++ b/automotive/evs/aidl/android/hardware/automotive/evs/IEvsCameraStream.aidl @@ -47,7 +47,10 @@ oneway interface IEvsCameraStream { /** * Receives calls from the HAL each time an event happens. * - * @param in event EVS event with possible event information. + * @param in event EVS event with possible event information. If ths HIDL + * recipients are expected to exist, the size of the event + * payload must not exceed 16 bytes; otherwise, a notification + * will not reach them. */ void notify(in EvsEventDesc event); } diff --git a/automotive/vehicle/2.0/default/Android.bp b/automotive/vehicle/2.0/default/Android.bp index 0d3253b9f8..33e211ca8c 100644 --- a/automotive/vehicle/2.0/default/Android.bp +++ b/automotive/vehicle/2.0/default/Android.bp @@ -84,7 +84,10 @@ cc_library_static { name: "android.hardware.automotive.vehicle@2.0-default-impl-lib", vendor: true, defaults: ["vhal_v2_0_target_defaults"], - cflags: ["-DENABLE_VENDOR_CLUSTER_PROPERTY_FOR_TESTING"], + cflags: [ + "-DENABLE_VENDOR_CLUSTER_PROPERTY_FOR_TESTING", + "-DENABLE_GET_PROP_CONFIGS_BY_MULTIPLE_REQUESTS", + ], srcs: [ "impl/vhal_v2_0/DefaultVehicleHal.cpp", "impl/vhal_v2_0/VehicleHalClient.cpp", @@ -225,6 +228,25 @@ cc_test { test_suites: ["general-tests"], } +cc_test { + name: "android.hardware.automotive.vehicle@2.0-default-config-test", + vendor: true, + defaults: ["vhal_v2_0_target_defaults"], + srcs: [ + "impl/vhal_v2_0/tests/DefaultConfigSupportedPropertyIds_test.cpp", + ], + cflags: [ + "-DENABLE_VENDOR_CLUSTER_PROPERTY_FOR_TESTING", + "-DENABLE_GET_PROP_CONFIGS_BY_MULTIPLE_REQUESTS", + ], + static_libs: [ + "android.hardware.automotive.vehicle@2.0-default-impl-lib", + "libgtest", + "libgmock", + ], + test_suites: ["general-tests"], +} + cc_binary { name: "android.hardware.automotive.vehicle@2.0-default-service", defaults: ["vhal_v2_0_target_defaults"], diff --git a/automotive/vehicle/2.0/default/impl/vhal_v2_0/DefaultConfig.h b/automotive/vehicle/2.0/default/impl/vhal_v2_0/DefaultConfig.h index cfbbbd3224..55a7720fc2 100644 --- a/automotive/vehicle/2.0/default/impl/vhal_v2_0/DefaultConfig.h +++ b/automotive/vehicle/2.0/default/impl/vhal_v2_0/DefaultConfig.h @@ -1109,6 +1109,19 @@ const ConfigDeclaration kVehicleProperties[]{ }, .initialValue = {.stringValue = {"Test"}}, }, + // This property is later defined in the AIDL VHAL interface. However, HIDL VHAL might + // require support for this property to meet EU regulation. + { + .config = + { + // GENERAL_SAFETY_REGULATION_COMPLIANCE_REQUIREMENT + .prop = 0x11400F47, + .access = VehiclePropertyAccess::READ, + .changeMode = VehiclePropertyChangeMode::STATIC, + }, + // GsrComplianceRequirementType::GSR_COMPLIANCE_REQUIRED_V1 + .initialValue = {.int32Values = {1}}, + }, #ifdef ENABLE_VENDOR_CLUSTER_PROPERTY_FOR_TESTING // Vendor propetry for E2E ClusterHomeService testing. { @@ -1157,6 +1170,46 @@ const ConfigDeclaration kVehicleProperties[]{ }, }, #endif // ENABLE_VENDOR_CLUSTER_PROPERTY_FOR_TESTING +#ifdef ENABLE_GET_PROP_CONFIGS_BY_MULTIPLE_REQUESTS + { + .config = + { + // VHAL_SUPPORTED_PROPERTY_IDS + .prop = 289476424, + .access = VehiclePropertyAccess::READ, + .changeMode = VehiclePropertyChangeMode::STATIC, + // Fetch 100 configs in one request. This number is just arbitrarily + // chosen here. But some HAL impl with bigger config data may need a + // smaller number. + .configArray = {100}, + }, + // All supported property IDs. This list is checked by + // DefaultConfigSupportedPropertyIds_test. + .initialValue = + {.int32Values = + {291504388, 289472773, 291504390, 289472775, 289407240, 289407241, + 289472780, 286261505, 286261506, 289407235, 289472779, 291504647, + 289408517, 356518832, 356516106, 291504644, 291504649, 291504656, + 291504901, 291504903, 287310600, 291504905, 287310602, 287310603, + 291504908, 291504904, 392168201, 392168202, 289408514, 289408001, + 287310850, 287310851, 287310853, 289475088, 289475104, 289475120, + 354419984, 320865540, 320865556, 354419975, 354419976, 354419986, + 354419973, 354419974, 354419978, 354419977, 356517120, 356517121, + 356582673, 356517139, 289408269, 356517131, 358614275, 291570965, + 291505923, 289408270, 289408512, 287310855, 289408000, 289408008, + 289408009, 289407747, 291504900, 568332561, 371198722, 373295872, + 320867268, 322964416, 290521862, 287310858, 287310859, 289475072, + 289475073, 289409539, 299896064, 299896065, 299896066, 299896067, + 289410560, 289410561, 289410562, 289410563, 289410576, 289410577, + 289410578, 289410579, 289476368, 299895808, 639631617, 627048706, + 591397123, 554696964, 289410873, 289410874, 287313669, 299896583, + 299896584, 299896585, 299896586, 299896587, 286265121, 286265122, + 286265123, 290457094, 290459441, 299896626, 290459443, 289410868, + 289476405, 299896630, 289410871, 292556600, 557853201, 559950353, + 555756049, 554707473, 289410887, 557846324, 557911861, 568332086, + 557846327, 560992056, 289476424}}, + }, +#endif // ENABLE_GET_PROP_CONFIGS_BY_MULTIPLE_REQUESTS }; } // impl diff --git a/automotive/vehicle/2.0/default/impl/vhal_v2_0/tests/DefaultConfigSupportedPropertyIds_test.cpp b/automotive/vehicle/2.0/default/impl/vhal_v2_0/tests/DefaultConfigSupportedPropertyIds_test.cpp new file mode 100644 index 0000000000..aa05daafdc --- /dev/null +++ b/automotive/vehicle/2.0/default/impl/vhal_v2_0/tests/DefaultConfigSupportedPropertyIds_test.cpp @@ -0,0 +1,56 @@ +/* + * 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. + */ + +#include <gmock/gmock.h> +#include <gtest/gtest.h> +#include <vector> + +#include "vhal_v2_0/DefaultConfig.h" + +namespace android { +namespace hardware { +namespace automotive { +namespace vehicle { +namespace V2_0 { +namespace impl { + +using ::testing::ElementsAreArray; + +// Test that VHAL_SUPPORTED_PROPERTY_IDS contains all supported property IDs. +TEST(DefaultConfigSupportedPropertyIdsTest, testIncludeAllSupportedIds) { + const int32_t vhalSupportedPropertyIdsPropId = 289476424; + + std::vector<int32_t> allSupportedIds; + std::vector<int32_t> configuredSupportedIds; + + for (const auto& property : impl::kVehicleProperties) { + int propId = property.config.prop; + allSupportedIds.push_back(propId); + + if (propId == vhalSupportedPropertyIdsPropId) { + configuredSupportedIds = property.initialValue.int32Values; + } + } + + ASSERT_THAT(allSupportedIds, ElementsAreArray(configuredSupportedIds)); +} + +} // namespace impl +} // namespace V2_0 +} // namespace vehicle +} // namespace automotive +} // namespace hardware +} // namespace android diff --git a/automotive/vehicle/2.0/default/impl/vhal_v2_0/tests/DefaultVhalImpl_test.cpp b/automotive/vehicle/2.0/default/impl/vhal_v2_0/tests/DefaultVhalImpl_test.cpp index e3c8dd6c79..25a1940e0e 100644 --- a/automotive/vehicle/2.0/default/impl/vhal_v2_0/tests/DefaultVhalImpl_test.cpp +++ b/automotive/vehicle/2.0/default/impl/vhal_v2_0/tests/DefaultVhalImpl_test.cpp @@ -141,7 +141,7 @@ class DefaultVhalImplTest : public ::testing::Test { TEST_F(DefaultVhalImplTest, testListProperties) { std::vector<VehiclePropConfig> configs = mHal->listProperties(); - EXPECT_EQ((size_t)121, configs.size()); + EXPECT_EQ((size_t)123, configs.size()); } TEST_F(DefaultVhalImplTest, testGetDefaultPropertyFloat) { diff --git a/automotive/vehicle/aidl/impl/default_config/include/DefaultConfig.h b/automotive/vehicle/aidl/impl/default_config/include/DefaultConfig.h index e00f775a04..622846a301 100644 --- a/automotive/vehicle/aidl/impl/default_config/include/DefaultConfig.h +++ b/automotive/vehicle/aidl/impl/default_config/include/DefaultConfig.h @@ -40,6 +40,7 @@ using ::aidl::android::hardware::automotive::vehicle::RawPropValues; using ::aidl::android::hardware::automotive::vehicle::VehicleApPowerStateReport; using ::aidl::android::hardware::automotive::vehicle::VehicleApPowerStateReq; using ::aidl::android::hardware::automotive::vehicle::VehicleAreaConfig; +using ::aidl::android::hardware::automotive::vehicle::VehicleAreaMirror; using ::aidl::android::hardware::automotive::vehicle::VehicleAreaWindow; using ::aidl::android::hardware::automotive::vehicle::VehicleGear; using ::aidl::android::hardware::automotive::vehicle::VehicleHvacFanDirection; @@ -124,6 +125,13 @@ const std::vector<ConfigDeclaration> kVehicleProperties = { {.config = { + .prop = toInt(VehicleProperty::INFO_VIN), + .access = VehiclePropertyAccess::READ, + .changeMode = VehiclePropertyChangeMode::STATIC, + }, + .initialValue = {.stringValue = "1GCARVIN123456789"}}, + {.config = + { .prop = toInt(VehicleProperty::INFO_MAKE), .access = VehiclePropertyAccess::READ, .changeMode = VehiclePropertyChangeMode::STATIC, @@ -173,6 +181,557 @@ const std::vector<ConfigDeclaration> kVehicleProperties = { {.config = { + .prop = toInt(VehicleProperty::EV_BATTERY_DISPLAY_UNITS), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .configArray = {toInt(VehicleUnit::WATT_HOUR), + toInt(VehicleUnit::AMPERE_HOURS), + toInt(VehicleUnit::KILOWATT_HOUR)}, + }, + .initialValue = {.int32Values = {toInt(VehicleUnit::KILOWATT_HOUR)}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_MEMORY_SELECT), + .access = VehiclePropertyAccess::WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = 0, + .maxInt32Value = 3}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = 0, + .maxInt32Value = 3}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = 0, + .maxInt32Value = 3}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = 0, + .maxInt32Value = 3}}}, + .initialValue = {.int32Values = {1}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_MEMORY_SET), + .access = VehiclePropertyAccess::WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = 0, + .maxInt32Value = 3}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = 0, + .maxInt32Value = 3}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = 0, + .maxInt32Value = 3}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = 0, + .maxInt32Value = 3}}}, + .initialValue = {.int32Values = {1}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_BELT_BUCKLED), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER}}}, + .initialAreaValues = {{SEAT_1_LEFT, {.int32Values = {0}}}, + {SEAT_1_RIGHT, {.int32Values = {0}}}, + {SEAT_2_LEFT, {.int32Values = {0}}}, + {SEAT_2_RIGHT, {.int32Values = {0}}}, + {SEAT_2_CENTER, {.int32Values = {0}}}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_BELT_HEIGHT_POS), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = 0, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = 0, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = 0, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = 0, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = 0, + .maxInt32Value = 10}}}, + .initialAreaValues = {{SEAT_1_LEFT, {.int32Values = {10}}}, + {SEAT_1_RIGHT, {.int32Values = {10}}}, + {SEAT_2_LEFT, {.int32Values = {10}}}, + {SEAT_2_RIGHT, {.int32Values = {10}}}, + {SEAT_2_CENTER, {.int32Values = {10}}}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_BELT_HEIGHT_MOVE), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = -1, + .maxInt32Value = 1}}}, + .initialAreaValues = {{SEAT_1_LEFT, {.int32Values = {0}}}, + {SEAT_1_RIGHT, {.int32Values = {0}}}, + {SEAT_2_LEFT, {.int32Values = {0}}}, + {SEAT_2_RIGHT, {.int32Values = {0}}}, + {SEAT_2_CENTER, {.int32Values = {0}}}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_FORE_AFT_POS), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = -10, + .maxInt32Value = 10}}}, + .initialAreaValues = {{SEAT_1_LEFT, {.int32Values = {0}}}, + {SEAT_1_RIGHT, {.int32Values = {0}}}, + {SEAT_2_LEFT, {.int32Values = {0}}}, + {SEAT_2_RIGHT, {.int32Values = {0}}}, + {SEAT_2_CENTER, {.int32Values = {0}}}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_FORE_AFT_MOVE), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = -1, + .maxInt32Value = 1}}}, + .initialAreaValues = {{SEAT_1_LEFT, {.int32Values = {0}}}, + {SEAT_1_RIGHT, {.int32Values = {0}}}, + {SEAT_2_LEFT, {.int32Values = {0}}}, + {SEAT_2_RIGHT, {.int32Values = {0}}}, + {SEAT_2_CENTER, {.int32Values = {0}}}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_BACKREST_ANGLE_1_POS), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = -10, + .maxInt32Value = 10}}}, + .initialAreaValues = {{SEAT_1_LEFT, {.int32Values = {0}}}, + {SEAT_1_RIGHT, {.int32Values = {0}}}, + {SEAT_2_LEFT, {.int32Values = {0}}}, + {SEAT_2_RIGHT, {.int32Values = {0}}}, + {SEAT_2_CENTER, {.int32Values = {0}}}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_BACKREST_ANGLE_1_MOVE), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = -1, + .maxInt32Value = 1}}}, + .initialAreaValues = {{SEAT_1_LEFT, {.int32Values = {0}}}, + {SEAT_1_RIGHT, {.int32Values = {0}}}, + {SEAT_2_LEFT, {.int32Values = {0}}}, + {SEAT_2_RIGHT, {.int32Values = {0}}}, + {SEAT_2_CENTER, {.int32Values = {0}}}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_BACKREST_ANGLE_2_POS), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = -10, + .maxInt32Value = 10}}}, + .initialAreaValues = {{SEAT_1_LEFT, {.int32Values = {0}}}, + {SEAT_1_RIGHT, {.int32Values = {0}}}, + {SEAT_2_LEFT, {.int32Values = {0}}}, + {SEAT_2_RIGHT, {.int32Values = {0}}}, + {SEAT_2_CENTER, {.int32Values = {0}}}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_BACKREST_ANGLE_2_MOVE), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = -1, + .maxInt32Value = 1}}}, + .initialAreaValues = {{SEAT_1_LEFT, {.int32Values = {0}}}, + {SEAT_1_RIGHT, {.int32Values = {0}}}, + {SEAT_2_LEFT, {.int32Values = {0}}}, + {SEAT_2_RIGHT, {.int32Values = {0}}}, + {SEAT_2_CENTER, {.int32Values = {0}}}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_HEIGHT_POS), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = -10, + .maxInt32Value = 10}}}, + .initialValue = {.int32Values = {0}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_HEIGHT_MOVE), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = -1, + .maxInt32Value = 1}}}, + .initialValue = {.int32Values = {0}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_DEPTH_POS), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = -10, + .maxInt32Value = 10}}}, + .initialValue = {.int32Values = {0}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_DEPTH_MOVE), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = -1, + .maxInt32Value = 1}}}, + .initialValue = {.int32Values = {0}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_TILT_POS), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = -10, + .maxInt32Value = 10}}}, + .initialValue = {.int32Values = {0}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_TILT_MOVE), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = -1, + .maxInt32Value = 1}}}, + .initialValue = {.int32Values = {0}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_LUMBAR_FORE_AFT_POS), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = -10, + .maxInt32Value = 10}}}, + .initialValue = {.int32Values = {0}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_LUMBAR_FORE_AFT_MOVE), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = -1, + .maxInt32Value = 1}}}, + .initialValue = {.int32Values = {0}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_LUMBAR_SIDE_SUPPORT_POS), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = 0, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = 0, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = 0, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = 0, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = 0, + .maxInt32Value = 10}}}, + .initialValue = {.int32Values = {0}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_LUMBAR_SIDE_SUPPORT_MOVE), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = -1, + .maxInt32Value = 1}}}, + .initialValue = {.int32Values = {0}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_HEADREST_HEIGHT_MOVE), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = -1, + .maxInt32Value = 1}}}, + .initialValue = {.int32Values = {0}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_HEADREST_ANGLE_POS), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = 0, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = 0, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = 0, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = 0, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = 0, + .maxInt32Value = 10}}}, + .initialValue = {.int32Values = {0}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_HEADREST_ANGLE_MOVE), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = -1, + .maxInt32Value = 1}}}, + .initialValue = {.int32Values = {0}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_HEADREST_FORE_AFT_POS), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = 0, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = 0, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = 0, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = 0, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = 0, + .maxInt32Value = 10}}}, + .initialValue = {.int32Values = {0}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_HEADREST_FORE_AFT_MOVE), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = -1, + .maxInt32Value = 1}}}, + .initialValue = {.int32Values = {0}}}, + + {.config = + { .prop = toInt(VehicleProperty::SEAT_OCCUPANCY), .access = VehiclePropertyAccess::READ, .changeMode = VehiclePropertyChangeMode::ON_CHANGE, @@ -352,8 +911,9 @@ const std::vector<ConfigDeclaration> kVehicleProperties = { .prop = toInt(VehicleProperty::VEHICLE_CURB_WEIGHT), .access = VehiclePropertyAccess::READ, .changeMode = VehiclePropertyChangeMode::STATIC, + .configArray = {/*gross weight kg=*/2948}, }, - .initialValue = {.int32Values = {30}}}, + .initialValue = {.int32Values = {2211 /*kg*/}}}, {.config = { @@ -460,6 +1020,24 @@ const std::vector<ConfigDeclaration> kVehicleProperties = { {.config = { + .prop = toInt(VehicleProperty::FUEL_VOLUME_DISPLAY_UNITS), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .configArray = {(int)VehicleUnit::LITER, (int)VehicleUnit::US_GALLON}, + }, + .initialValue = {.int32Values = {(int)VehicleUnit::LITER}}}, + + {.config = + { + .prop = toInt( + VehicleProperty::FUEL_CONSUMPTION_UNITS_DISTANCE_OVER_VOLUME), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + }, + .initialValue = {.int32Values = {1}}}, + + {.config = + { .prop = toInt(VehicleProperty::HW_KEY_INPUT), .access = VehiclePropertyAccess::READ, .changeMode = VehiclePropertyChangeMode::ON_CHANGE, @@ -486,6 +1064,12 @@ const std::vector<ConfigDeclaration> kVehicleProperties = { .int32Values = {0, 0, 0}, }}, + {.config = {.prop = toInt(VehicleProperty::HVAC_ACTUAL_FAN_SPEED_RPM), + .access = VehiclePropertyAccess::READ, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = HVAC_ALL}}}, + .initialValue = {.int32Values = {50}}}, + {.config = {.prop = toInt(VehicleProperty::HVAC_POWER_ON), .access = VehiclePropertyAccess::READ_WRITE, .changeMode = VehiclePropertyChangeMode::ON_CHANGE, @@ -623,6 +1207,25 @@ const std::vector<ConfigDeclaration> kVehicleProperties = { }}}, .initialValue = {.int32Values = {0}}}, // +ve values for heating and -ve for cooling + {.config = {.prop = toInt(VehicleProperty::HVAC_SIDE_MIRROR_HEAT), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{ + .areaId = toInt(VehicleAreaMirror::DRIVER_LEFT) | + toInt(VehicleAreaMirror::DRIVER_RIGHT), + .minInt32Value = 0, + .maxInt32Value = 2, + }}}, + .initialValue = {.int32Values = {0}}}, + + {.config = {.prop = toInt(VehicleProperty::HVAC_TEMPERATURE_CURRENT), + .access = VehiclePropertyAccess::READ, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = HVAC_LEFT}, + VehicleAreaConfig{.areaId = HVAC_RIGHT}}}, + .initialAreaValues = {{HVAC_LEFT, {.floatValues = {17.3f}}}, + {HVAC_RIGHT, {.floatValues = {19.1f}}}}}, + {.config = {.prop = toInt(VehicleProperty::HVAC_TEMPERATURE_SET), .access = VehiclePropertyAccess::READ_WRITE, .changeMode = VehiclePropertyChangeMode::ON_CHANGE, @@ -715,6 +1318,16 @@ const std::vector<ConfigDeclaration> kVehicleProperties = { {.config = { + .prop = toInt(VehicleProperty::ENGINE_COOLANT_TEMP), + .access = VehiclePropertyAccess::READ, + .changeMode = VehiclePropertyChangeMode::CONTINUOUS, + .minSampleRate = 1.0f, + .maxSampleRate = 10.0f, + }, + .initialValue = {.floatValues = {75.0f}}}, + + {.config = + { .prop = toInt(VehicleProperty::ENGINE_OIL_LEVEL), .access = VehiclePropertyAccess::READ, .changeMode = VehiclePropertyChangeMode::ON_CHANGE, @@ -774,6 +1387,76 @@ const std::vector<ConfigDeclaration> kVehicleProperties = { .areaId = DOOR_REAR, .minInt32Value = 0, .maxInt32Value = 1}}}, .initialValue = {.int32Values = {0}}}, + {.config = {.prop = toInt(VehicleProperty::MIRROR_Z_POS), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = + {VehicleAreaConfig{.areaId = toInt(VehicleAreaMirror::DRIVER_LEFT), + .minInt32Value = -3, + .maxInt32Value = 3}, + VehicleAreaConfig{.areaId = toInt(VehicleAreaMirror::DRIVER_RIGHT), + .minInt32Value = -3, + .maxInt32Value = 3}, + VehicleAreaConfig{.areaId = toInt(VehicleAreaMirror::DRIVER_CENTER), + .minInt32Value = -3, + .maxInt32Value = 3}}}, + .initialValue = {.int32Values = {0}}}, + + {.config = {.prop = toInt(VehicleProperty::MIRROR_Z_MOVE), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = + {VehicleAreaConfig{.areaId = toInt(VehicleAreaMirror::DRIVER_LEFT), + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = toInt(VehicleAreaMirror::DRIVER_RIGHT), + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = toInt(VehicleAreaMirror::DRIVER_CENTER), + .minInt32Value = -1, + .maxInt32Value = 1}}}, + .initialValue = {.int32Values = {0}}}, + + {.config = {.prop = toInt(VehicleProperty::MIRROR_Y_POS), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = + {VehicleAreaConfig{.areaId = toInt(VehicleAreaMirror::DRIVER_LEFT), + .minInt32Value = -3, + .maxInt32Value = 3}, + VehicleAreaConfig{.areaId = toInt(VehicleAreaMirror::DRIVER_RIGHT), + .minInt32Value = -3, + .maxInt32Value = 3}, + VehicleAreaConfig{.areaId = toInt(VehicleAreaMirror::DRIVER_CENTER), + .minInt32Value = -3, + .maxInt32Value = 3}}}, + .initialValue = {.int32Values = {0}}}, + + {.config = {.prop = toInt(VehicleProperty::MIRROR_Y_MOVE), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = + {VehicleAreaConfig{.areaId = toInt(VehicleAreaMirror::DRIVER_LEFT), + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = toInt(VehicleAreaMirror::DRIVER_RIGHT), + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = toInt(VehicleAreaMirror::DRIVER_CENTER), + .minInt32Value = -1, + .maxInt32Value = 1}}}, + .initialValue = {.int32Values = {0}}}, + + {.config = {.prop = toInt(VehicleProperty::MIRROR_LOCK), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE}, + .initialValue = {.int32Values = {1}}}, + + {.config = {.prop = toInt(VehicleProperty::MIRROR_FOLD), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE}, + .initialValue = {.int32Values = {1}}}, + {.config = {.prop = toInt(VehicleProperty::WINDOW_LOCK), .access = VehiclePropertyAccess::READ_WRITE, .changeMode = VehiclePropertyChangeMode::ON_CHANGE, @@ -802,6 +1485,26 @@ const std::vector<ConfigDeclaration> kVehicleProperties = { .maxInt32Value = 10}}}, .initialValue = {.int32Values = {0}}}, + {.config = {.prop = toInt(VehicleProperty::WINDOW_MOVE), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = WINDOW_1_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = WINDOW_1_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = WINDOW_2_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = WINDOW_2_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = WINDOW_ROOF_TOP_1, + .minInt32Value = -1, + .maxInt32Value = 1}}}, + .initialValue = {.int32Values = {0}}}, + {.config = { .prop = WHEEL_TICK, @@ -884,7 +1587,7 @@ const std::vector<ConfigDeclaration> kVehicleProperties = { {.config = { - .prop = toInt(VehicleProperty::FOG_LIGHTS_STATE), + .prop = toInt(VehicleProperty::FRONT_FOG_LIGHTS_STATE), .access = VehiclePropertyAccess::READ, .changeMode = VehiclePropertyChangeMode::ON_CHANGE, }, @@ -892,7 +1595,7 @@ const std::vector<ConfigDeclaration> kVehicleProperties = { {.config = { - .prop = toInt(VehicleProperty::FRONT_FOG_LIGHTS_STATE), + .prop = toInt(VehicleProperty::REAR_FOG_LIGHTS_STATE), .access = VehiclePropertyAccess::READ, .changeMode = VehiclePropertyChangeMode::ON_CHANGE, }, @@ -900,7 +1603,7 @@ const std::vector<ConfigDeclaration> kVehicleProperties = { {.config = { - .prop = toInt(VehicleProperty::REAR_FOG_LIGHTS_STATE), + .prop = toInt(VehicleProperty::HAZARD_LIGHTS_STATE), .access = VehiclePropertyAccess::READ, .changeMode = VehiclePropertyChangeMode::ON_CHANGE, }, @@ -908,12 +1611,22 @@ const std::vector<ConfigDeclaration> kVehicleProperties = { {.config = { - .prop = toInt(VehicleProperty::HAZARD_LIGHTS_STATE), + .prop = toInt(VehicleProperty::CABIN_LIGHTS_STATE), .access = VehiclePropertyAccess::READ, .changeMode = VehiclePropertyChangeMode::ON_CHANGE, }, .initialValue = {.int32Values = {LIGHT_STATE_ON}}}, + {.config = {.prop = toInt(VehicleProperty::READING_LIGHTS_STATE), + .access = VehiclePropertyAccess::READ, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER}}}, + .initialValue = {.int32Values = {LIGHT_STATE_ON}}}, + {.config = { .prop = toInt(VehicleProperty::HEADLIGHTS_SWITCH), @@ -930,17 +1643,19 @@ const std::vector<ConfigDeclaration> kVehicleProperties = { }, .initialValue = {.int32Values = {LIGHT_SWITCH_AUTO}}}, + // FOG_LIGHTS_SWITCH must not be implemented when FRONT_FOG_LIGHTS_SWITCH is implemented {.config = { - .prop = toInt(VehicleProperty::FOG_LIGHTS_SWITCH), + .prop = toInt(VehicleProperty::FRONT_FOG_LIGHTS_SWITCH), .access = VehiclePropertyAccess::READ_WRITE, .changeMode = VehiclePropertyChangeMode::ON_CHANGE, }, .initialValue = {.int32Values = {LIGHT_SWITCH_AUTO}}}, + // FOG_LIGHTS_SWITCH must not be implemented when REAR_FOG_LIGHTS_SWITCH is implemented {.config = { - .prop = toInt(VehicleProperty::FRONT_FOG_LIGHTS_SWITCH), + .prop = toInt(VehicleProperty::REAR_FOG_LIGHTS_SWITCH), .access = VehiclePropertyAccess::READ_WRITE, .changeMode = VehiclePropertyChangeMode::ON_CHANGE, }, @@ -948,7 +1663,7 @@ const std::vector<ConfigDeclaration> kVehicleProperties = { {.config = { - .prop = toInt(VehicleProperty::REAR_FOG_LIGHTS_SWITCH), + .prop = toInt(VehicleProperty::HAZARD_LIGHTS_SWITCH), .access = VehiclePropertyAccess::READ_WRITE, .changeMode = VehiclePropertyChangeMode::ON_CHANGE, }, @@ -956,11 +1671,21 @@ const std::vector<ConfigDeclaration> kVehicleProperties = { {.config = { - .prop = toInt(VehicleProperty::HAZARD_LIGHTS_SWITCH), + .prop = toInt(VehicleProperty::CABIN_LIGHTS_SWITCH), .access = VehiclePropertyAccess::READ_WRITE, .changeMode = VehiclePropertyChangeMode::ON_CHANGE, }, - .initialValue = {.int32Values = {LIGHT_SWITCH_AUTO}}}, + .initialValue = {.int32Values = {LIGHT_STATE_ON}}}, + + {.config = {.prop = toInt(VehicleProperty::READING_LIGHTS_SWITCH), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER}}}, + .initialValue = {.int32Values = {LIGHT_STATE_ON}}}, {.config = { diff --git a/automotive/vehicle/aidl/impl/fake_impl/hardware/src/FakeVehicleHardware.cpp b/automotive/vehicle/aidl/impl/fake_impl/hardware/src/FakeVehicleHardware.cpp index b64c1a65cc..20c34aa12e 100644 --- a/automotive/vehicle/aidl/impl/fake_impl/hardware/src/FakeVehicleHardware.cpp +++ b/automotive/vehicle/aidl/impl/fake_impl/hardware/src/FakeVehicleHardware.cpp @@ -217,17 +217,16 @@ VhalResult<void> FakeVehicleHardware::setApPowerStateReport(const VehiclePropVal [[fallthrough]]; case toInt(VehicleApPowerStateReport::WAIT_FOR_VHAL): // CPMS is in WAIT_FOR_VHAL state, simply move to ON and send back to HAL. - // Must erase existing state because in the case when Car Service crashes, the power - // state would already be ON when we receive WAIT_FOR_VHAL and thus new property change - // event would be generated. However, Car Service always expect a property change event - // even though there is not actual state change. - mServerSidePropStore->removeValuesForProperty( - toInt(VehicleProperty::AP_POWER_STATE_REQ)); prop = createApPowerStateReq(VehicleApPowerStateReq::ON); - // ALWAYS update status for generated property value + // ALWAYS update status for generated property value, and force a property update event + // because in the case when Car Service crashes, the power state would already be ON + // when we receive WAIT_FOR_VHAL and thus new property change event would be generated. + // However, Car Service always expect a property change event even though there is no + // actual state change. if (auto writeResult = - mServerSidePropStore->writeValue(std::move(prop), /*updateStatus=*/true); + mServerSidePropStore->writeValue(std::move(prop), /*updateStatus=*/true, + VehiclePropertyStore::EventMode::ALWAYS); !writeResult.ok()) { return StatusError(getErrorCode(writeResult)) << "failed to write AP_POWER_STATE_REQ into property store, error: " @@ -894,10 +893,10 @@ StatusCode FakeVehicleHardware::updateSampleRate(int32_t propId, int32_t areaId, return; } result.value()->timestamp = elapsedRealtimeNano(); - // Must remove the value before writing, otherwise, we would generate no update event since - // the value is the same. - mServerSidePropStore->removeValue(*result.value()); - mServerSidePropStore->writeValue(std::move(result.value())); + // For continuous properties, we must generate a new onPropertyChange event periodically + // according to the sample rate. + mServerSidePropStore->writeValue(std::move(result.value()), /*updateStatus=*/true, + VehiclePropertyStore::EventMode::ALWAYS); }); mRecurrentTimer->registerTimerCallback(interval, action); mRecurrentActions[propIdAreaId] = action; diff --git a/automotive/vehicle/aidl/impl/utils/common/include/RecurrentTimer.h b/automotive/vehicle/aidl/impl/utils/common/include/RecurrentTimer.h index 5f0f7161c2..cd2b72713c 100644 --- a/automotive/vehicle/aidl/impl/utils/common/include/RecurrentTimer.h +++ b/automotive/vehicle/aidl/impl/utils/common/include/RecurrentTimer.h @@ -83,8 +83,9 @@ class RecurrentTimer final { // each time we might introduce outdated elements to the top. We must make sure the heap is // always valid from the top. void removeInvalidCallbackLocked() REQUIRES(mLock); - // Pops the next closest callback (must be valid) from the heap. - std::unique_ptr<CallbackInfo> popNextCallbackLocked() REQUIRES(mLock); + // Gets the next calblack to run (must be valid) from the heap, update its nextTime and put + // it back to the heap. + std::shared_ptr<Callback> getNextCallbackLocked(int64_t now) REQUIRES(mLock); }; } // namespace vehicle diff --git a/automotive/vehicle/aidl/impl/utils/common/include/VehicleHalTypes.h b/automotive/vehicle/aidl/impl/utils/common/include/VehicleHalTypes.h index a7fcdcf99d..8bc3c20ad8 100644 --- a/automotive/vehicle/aidl/impl/utils/common/include/VehicleHalTypes.h +++ b/automotive/vehicle/aidl/impl/utils/common/include/VehicleHalTypes.h @@ -42,6 +42,7 @@ #include <aidl/android/hardware/automotive/vehicle/VehicleApPowerStateReq.h> #include <aidl/android/hardware/automotive/vehicle/VehicleArea.h> #include <aidl/android/hardware/automotive/vehicle/VehicleAreaDoor.h> +#include <aidl/android/hardware/automotive/vehicle/VehicleAreaMirror.h> #include <aidl/android/hardware/automotive/vehicle/VehicleAreaSeat.h> #include <aidl/android/hardware/automotive/vehicle/VehicleAreaWheel.h> #include <aidl/android/hardware/automotive/vehicle/VehicleAreaWindow.h> diff --git a/automotive/vehicle/aidl/impl/utils/common/include/VehiclePropertyStore.h b/automotive/vehicle/aidl/impl/utils/common/include/VehiclePropertyStore.h index ddc4f684aa..3d25cd3a41 100644 --- a/automotive/vehicle/aidl/impl/utils/common/include/VehiclePropertyStore.h +++ b/automotive/vehicle/aidl/impl/utils/common/include/VehiclePropertyStore.h @@ -46,6 +46,33 @@ class VehiclePropertyStore final { using ValueResultType = VhalResult<VehiclePropValuePool::RecyclableType>; using ValuesResultType = VhalResult<std::vector<VehiclePropValuePool::RecyclableType>>; + enum class EventMode : uint8_t { + /** + * Only invoke OnValueChangeCallback if the new property value (ignoring timestamp) is + * different than the existing value. + * + * This should be used for regular cases. + */ + ON_VALUE_CHANGE, + /** + * Always invoke OnValueChangeCallback. + * + * This should be used for the special properties that are used for delivering event, e.g. + * HW_KEY_INPUT. + */ + ALWAYS, + /** + * Never invoke OnValueChangeCallback. + * + * This should be used for continuous property subscription when the sample rate for the + * subscription is smaller than the refresh rate for the property. E.g., the vehicle speed + * is refreshed at 20hz, but we are only subscribing at 10hz. In this case, we want to + * generate the property change event at 10hz, not 20hz, but we still want to refresh the + * timestamp (via writeValue) at 20hz. + */ + NEVER, + }; + explicit VehiclePropertyStore(std::shared_ptr<VehiclePropValuePool> valuePool) : mValuePool(valuePool) {} @@ -72,8 +99,10 @@ class VehiclePropertyStore final { // 'status' would be initialized to {@code VehiclePropertyStatus::AVAILABLE}, if this is to // override an existing value, the status for the existing value would be used for the // overridden value. + // 'EventMode' controls whether the 'OnValueChangeCallback' will be called for this operation. VhalResult<void> writeValue(VehiclePropValuePool::RecyclableType propValue, - bool updateStatus = false); + bool updateStatus = false, + EventMode mode = EventMode::ON_VALUE_CHANGE); // Remove a given property value from the property store. The 'propValue' would be used to // generate the key for the value to remove. diff --git a/automotive/vehicle/aidl/impl/utils/common/src/RecurrentTimer.cpp b/automotive/vehicle/aidl/impl/utils/common/src/RecurrentTimer.cpp index 8521c4db7c..908564c2ff 100644 --- a/automotive/vehicle/aidl/impl/utils/common/src/RecurrentTimer.cpp +++ b/automotive/vehicle/aidl/impl/utils/common/src/RecurrentTimer.cpp @@ -48,7 +48,7 @@ void RecurrentTimer::registerTimerCallback(int64_t intervalInNano, std::scoped_lock<std::mutex> lockGuard(mLock); // Aligns the nextTime to multiply of interval. - int64_t nextTime = ceil(elapsedRealtimeNano() / intervalInNano) * intervalInNano; + int64_t nextTime = ceil(uptimeNanos() / intervalInNano) * intervalInNano; std::unique_ptr<CallbackInfo> info = std::make_unique<CallbackInfo>(); info->callback = callback; @@ -101,68 +101,71 @@ void RecurrentTimer::removeInvalidCallbackLocked() { } } -std::unique_ptr<RecurrentTimer::CallbackInfo> RecurrentTimer::popNextCallbackLocked() { +std::shared_ptr<RecurrentTimer::Callback> RecurrentTimer::getNextCallbackLocked(int64_t now) { std::pop_heap(mCallbackQueue.begin(), mCallbackQueue.end(), CallbackInfo::cmp); - std::unique_ptr<CallbackInfo> info = std::move(mCallbackQueue[mCallbackQueue.size() - 1]); - mCallbackQueue.pop_back(); + auto& callbackInfo = mCallbackQueue[mCallbackQueue.size() - 1]; + auto nextCallback = callbackInfo->callback; + // intervalCount is the number of interval we have to advance until we pass now. + size_t intervalCount = (now - callbackInfo->nextTime) / callbackInfo->interval + 1; + callbackInfo->nextTime += intervalCount * callbackInfo->interval; + std::push_heap(mCallbackQueue.begin(), mCallbackQueue.end(), CallbackInfo::cmp); + // Make sure the first element is always valid. removeInvalidCallbackLocked(); - return info; + + return nextCallback; } void RecurrentTimer::loop() { - std::unique_lock<std::mutex> uniqueLock(mLock); - + std::vector<std::shared_ptr<Callback>> callbacksToRun; while (true) { - // Wait until the timer exits or we have at least one recurrent callback. - mCond.wait(uniqueLock, [this] { - ScopedLockAssertion lockAssertion(mLock); - return mStopRequested || mCallbackQueue.size() != 0; - }); - - int64_t interval; { + std::unique_lock<std::mutex> uniqueLock(mLock); ScopedLockAssertion lockAssertion(mLock); + // Wait until the timer exits or we have at least one recurrent callback. + mCond.wait(uniqueLock, [this] { + ScopedLockAssertion lockAssertion(mLock); + return mStopRequested || mCallbackQueue.size() != 0; + }); + + int64_t interval; if (mStopRequested) { return; } // The first element is the nearest next event. int64_t nextTime = mCallbackQueue[0]->nextTime; - int64_t now = elapsedRealtimeNano(); + int64_t now = uptimeNanos(); + if (nextTime > now) { interval = nextTime - now; } else { interval = 0; } - } - // Wait for the next event or the timer exits. - if (mCond.wait_for(uniqueLock, std::chrono::nanoseconds(interval), [this] { - ScopedLockAssertion lockAssertion(mLock); - return mStopRequested; - })) { - return; - } + // Wait for the next event or the timer exits. + if (mCond.wait_for(uniqueLock, std::chrono::nanoseconds(interval), [this] { + ScopedLockAssertion lockAssertion(mLock); + return mStopRequested; + })) { + return; + } - { - ScopedLockAssertion lockAssertion(mLock); - int64_t now = elapsedRealtimeNano(); + now = uptimeNanos(); + callbacksToRun.clear(); while (mCallbackQueue.size() > 0) { int64_t nextTime = mCallbackQueue[0]->nextTime; if (nextTime > now) { break; } - std::unique_ptr<CallbackInfo> info = popNextCallbackLocked(); - info->nextTime += info->interval; - - auto callback = info->callback; - mCallbackQueue.push_back(std::move(info)); - std::push_heap(mCallbackQueue.begin(), mCallbackQueue.end(), CallbackInfo::cmp); - - (*callback)(); + callbacksToRun.push_back(getNextCallbackLocked(now)); } } + + // Do not execute the callback while holding the lock. + for (size_t i = 0; i < callbacksToRun.size(); i++) { + (*callbacksToRun[i])(); + } } } diff --git a/automotive/vehicle/aidl/impl/utils/common/src/VehiclePropertyStore.cpp b/automotive/vehicle/aidl/impl/utils/common/src/VehiclePropertyStore.cpp index c8fb994684..646dc0e618 100644 --- a/automotive/vehicle/aidl/impl/utils/common/src/VehiclePropertyStore.cpp +++ b/automotive/vehicle/aidl/impl/utils/common/src/VehiclePropertyStore.cpp @@ -106,7 +106,8 @@ void VehiclePropertyStore::registerProperty(const VehiclePropConfig& config, } VhalResult<void> VehiclePropertyStore::writeValue(VehiclePropValuePool::RecyclableType propValue, - bool updateStatus) { + bool updateStatus, + VehiclePropertyStore::EventMode eventMode) { std::scoped_lock<std::mutex> g(mLock); int32_t propId = propValue->prop; @@ -145,7 +146,12 @@ VhalResult<void> VehiclePropertyStore::writeValue(VehiclePropValuePool::Recyclab } record->values[recId] = std::move(propValue); - if (valueUpdated && mOnValueChangeCallback != nullptr) { + + if (eventMode == EventMode::NEVER) { + return {}; + } + + if ((eventMode == EventMode::ALWAYS || valueUpdated) && mOnValueChangeCallback != nullptr) { mOnValueChangeCallback(*(record->values[recId])); } return {}; diff --git a/automotive/vehicle/aidl/impl/utils/common/test/RecurrentTimerTest.cpp b/automotive/vehicle/aidl/impl/utils/common/test/RecurrentTimerTest.cpp index a033a248cd..141efc135b 100644 --- a/automotive/vehicle/aidl/impl/utils/common/test/RecurrentTimerTest.cpp +++ b/automotive/vehicle/aidl/impl/utils/common/test/RecurrentTimerTest.cpp @@ -186,6 +186,33 @@ TEST_F(RecurrentTimerTest, testRegisterSameCallbackMultipleTimes) { ASSERT_EQ(countTimerCallbackQueue(&timer), static_cast<size_t>(0)); } +TEST_F(RecurrentTimerTest, testRegisterCallbackMultipleTimesNoDeadLock) { + // We want to avoid the following situation: + // Caller holds a lock while calling registerTimerCallback, registerTimerCallback will try + // to obtain an internal lock inside timer. + // Meanwhile an recurrent action happens with timer holding an internal lock. The action + // tries to obtain the lock currently hold by the caller. + // The solution is that while calling recurrent actions, timer must not hold the internal lock. + + std::unique_ptr<RecurrentTimer> timer = std::make_unique<RecurrentTimer>(); + std::mutex lock; + for (size_t i = 0; i < 1000; i++) { + std::scoped_lock<std::mutex> lockGuard(lock); + auto action = std::make_shared<RecurrentTimer::Callback>([&lock] { + // While calling this function, the timer must not hold lock in order not to dead + // lock. + std::scoped_lock<std::mutex> lockGuard(lock); + }); + // 10ms + int64_t interval = 10'000'000; + timer->registerTimerCallback(interval, action); + // Sleep for a little while to let the recurrent actions begin. + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + } + // Make sure we stop the timer before we destroy lock. + timer.reset(); +} + } // namespace vehicle } // namespace automotive } // namespace hardware diff --git a/automotive/vehicle/aidl/impl/utils/common/test/VehiclePropertyStoreTest.cpp b/automotive/vehicle/aidl/impl/utils/common/test/VehiclePropertyStoreTest.cpp index 4d6f811795..fea5034db9 100644 --- a/automotive/vehicle/aidl/impl/utils/common/test/VehiclePropertyStoreTest.cpp +++ b/automotive/vehicle/aidl/impl/utils/common/test/VehiclePropertyStoreTest.cpp @@ -448,6 +448,67 @@ TEST_F(VehiclePropertyStoreTest, testPropertyChangeCallbackNoUpdate) { ASSERT_EQ(updatedValue.prop, INVALID_PROP_ID); } +TEST_F(VehiclePropertyStoreTest, testPropertyChangeCallbackNoUpdateForTimestampChange) { + VehiclePropValue updatedValue{ + .prop = INVALID_PROP_ID, + }; + VehiclePropValue fuelCapacity = { + .prop = toInt(VehicleProperty::INFO_FUEL_CAPACITY), + .value = {.floatValues = {1.0}}, + }; + ASSERT_RESULT_OK(mStore->writeValue(mValuePool->obtain(fuelCapacity))); + + mStore->setOnValueChangeCallback( + [&updatedValue](const VehiclePropValue& value) { updatedValue = value; }); + + // Write the same value with different timestamp should succeed but should not trigger callback. + fuelCapacity.timestamp = 1; + ASSERT_RESULT_OK(mStore->writeValue(mValuePool->obtain(fuelCapacity))); + + ASSERT_EQ(updatedValue.prop, INVALID_PROP_ID); +} + +TEST_F(VehiclePropertyStoreTest, testPropertyChangeCallbackForceUpdate) { + VehiclePropValue updatedValue{ + .prop = INVALID_PROP_ID, + }; + VehiclePropValue fuelCapacity = { + .prop = toInt(VehicleProperty::INFO_FUEL_CAPACITY), + .value = {.floatValues = {1.0}}, + }; + ASSERT_RESULT_OK(mStore->writeValue(mValuePool->obtain(fuelCapacity))); + + mStore->setOnValueChangeCallback( + [&updatedValue](const VehiclePropValue& value) { updatedValue = value; }); + + fuelCapacity.timestamp = 1; + ASSERT_RESULT_OK(mStore->writeValue(mValuePool->obtain(fuelCapacity), /*updateStatus=*/false, + VehiclePropertyStore::EventMode::ALWAYS)); + + ASSERT_EQ(updatedValue, fuelCapacity); +} + +TEST_F(VehiclePropertyStoreTest, testPropertyChangeCallbackForceNoUpdate) { + VehiclePropValue updatedValue{ + .prop = INVALID_PROP_ID, + }; + VehiclePropValue fuelCapacity = { + .prop = toInt(VehicleProperty::INFO_FUEL_CAPACITY), + .value = {.floatValues = {1.0}}, + }; + ASSERT_RESULT_OK(mStore->writeValue(mValuePool->obtain(fuelCapacity))); + + mStore->setOnValueChangeCallback( + [&updatedValue](const VehiclePropValue& value) { updatedValue = value; }); + fuelCapacity.value.floatValues[0] = 2.0; + fuelCapacity.timestamp = 1; + + ASSERT_RESULT_OK(mStore->writeValue(mValuePool->obtain(fuelCapacity), /*updateStatus=*/false, + VehiclePropertyStore::EventMode::NEVER)); + + ASSERT_EQ(updatedValue.prop, INVALID_PROP_ID); +} + } // namespace vehicle } // namespace automotive } // namespace hardware diff --git a/bluetooth/audio/aidl/default/LeAudioOffloadAudioProvider.cpp b/bluetooth/audio/aidl/default/LeAudioOffloadAudioProvider.cpp index 0e22e44490..7f610ef3d0 100644 --- a/bluetooth/audio/aidl/default/LeAudioOffloadAudioProvider.cpp +++ b/bluetooth/audio/aidl/default/LeAudioOffloadAudioProvider.cpp @@ -55,21 +55,20 @@ ndk::ScopedAStatus LeAudioOffloadAudioProvider::startSession( const std::shared_ptr<IBluetoothAudioPort>& host_if, const AudioConfiguration& audio_config, const std::vector<LatencyMode>& latency_modes, DataMQDesc* _aidl_return) { - if (audio_config.getTag() != AudioConfiguration::leAudioConfig) { + if (session_type_ == + SessionType::LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH) { + if (audio_config.getTag() != AudioConfiguration::leAudioBroadcastConfig) { + LOG(WARNING) << __func__ << " - Invalid Audio Configuration=" + << audio_config.toString(); + *_aidl_return = DataMQDesc(); + return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); + } + } else if (audio_config.getTag() != AudioConfiguration::leAudioConfig) { LOG(WARNING) << __func__ << " - Invalid Audio Configuration=" << audio_config.toString(); *_aidl_return = DataMQDesc(); return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); } - const auto& le_audio_config = - audio_config.get<AudioConfiguration::leAudioConfig>(); - if (!BluetoothAudioCodecs::IsOffloadLeAudioConfigurationValid( - session_type_, le_audio_config)) { - LOG(WARNING) << __func__ << " - Unsupported LC3 Offloaded Configuration=" - << le_audio_config.toString(); - *_aidl_return = DataMQDesc(); - return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); - } return BluetoothAudioProvider::startSession( host_if, audio_config, latency_modes, _aidl_return); diff --git a/bluetooth/audio/aidl/vts/VtsHalBluetoothAudioTargetTest.cpp b/bluetooth/audio/aidl/vts/VtsHalBluetoothAudioTargetTest.cpp index ebd728db34..e9b74b771c 100644 --- a/bluetooth/audio/aidl/vts/VtsHalBluetoothAudioTargetTest.cpp +++ b/bluetooth/audio/aidl/vts/VtsHalBluetoothAudioTargetTest.cpp @@ -23,6 +23,7 @@ #include <android/binder_process.h> #include <binder/IServiceManager.h> #include <binder/ProcessState.h> +#include <cutils/properties.h> #include <fmq/AidlMessageQueue.h> #include <cstdint> @@ -248,7 +249,8 @@ class BluetoothAudioProviderFactoryAidl case SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH: case SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH: case SessionType::LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH: { - ASSERT_FALSE(temp_provider_capabilities_.empty()); + // empty capability means offload is unsupported since capabilities are + // not hardcoded for (auto audio_capability : temp_provider_capabilities_) { ASSERT_EQ(audio_capability.getTag(), AudioCapabilities::leAudioCapabilities); @@ -513,8 +515,9 @@ class BluetoothAudioProviderFactoryAidl for (auto channel_mode : opus_capability->channelMode) { OpusConfiguration opus_data{ .samplingFrequencyHz = samplingFrequencyHz, + .frameDurationUs = frameDurationUs, .channelMode = channel_mode, - .frameDurationUs = frameDurationUs}; + }; opus_codec_specifics.push_back( CodecConfiguration::CodecSpecific(opus_data)); } @@ -623,8 +626,8 @@ TEST_P(BluetoothAudioProviderA2dpEncodingSoftwareAidl, for (auto channel_mode : a2dp_channel_modes) { PcmConfiguration pcm_config{ .sampleRateHz = sample_rate, - .bitsPerSample = bits_per_sample, .channelMode = channel_mode, + .bitsPerSample = bits_per_sample, }; bool is_codec_config_valid = IsPcmConfigSupported(pcm_config); DataMQDesc mq_desc; @@ -937,8 +940,8 @@ TEST_P(BluetoothAudioProviderHearingAidSoftwareAidl, for (auto channel_mode : hearing_aid_channel_modes_) { PcmConfiguration pcm_config{ .sampleRateHz = sample_rate, - .bitsPerSample = bits_per_sample, .channelMode = channel_mode, + .bitsPerSample = bits_per_sample, }; bool is_codec_config_valid = IsPcmConfigSupported(pcm_config); DataMQDesc mq_desc; @@ -1008,8 +1011,8 @@ TEST_P(BluetoothAudioProviderLeAudioOutputSoftwareAidl, for (auto data_interval_us : le_audio_output_data_interval_us_) { PcmConfiguration pcm_config{ .sampleRateHz = sample_rate, - .bitsPerSample = bits_per_sample, .channelMode = channel_mode, + .bitsPerSample = bits_per_sample, .dataIntervalUs = data_interval_us, }; bool is_codec_config_valid = @@ -1081,8 +1084,8 @@ TEST_P(BluetoothAudioProviderLeAudioInputSoftwareAidl, for (auto data_interval_us : le_audio_input_data_interval_us_) { PcmConfiguration pcm_config{ .sampleRateHz = sample_rate, - .bitsPerSample = bits_per_sample, .channelMode = channel_mode, + .bitsPerSample = bits_per_sample, .dataIntervalUs = data_interval_us, }; bool is_codec_config_valid = @@ -1144,7 +1147,7 @@ class BluetoothAudioProviderLeAudioOutputHardwareAidl bool supported) { std::vector<Lc3Configuration> le_audio_codec_configs; if (!supported) { - Lc3Configuration lc3_config{.samplingFrequencyHz = 0, .pcmBitDepth = 0}; + Lc3Configuration lc3_config{.pcmBitDepth = 0, .samplingFrequencyHz = 0}; le_audio_codec_configs.push_back(lc3_config); return le_audio_codec_configs; } @@ -1428,8 +1431,8 @@ TEST_P(BluetoothAudioProviderLeAudioBroadcastSoftwareAidl, for (auto data_interval_us : le_audio_output_data_interval_us_) { PcmConfiguration pcm_config{ .sampleRateHz = sample_rate, - .bitsPerSample = bits_per_sample, .channelMode = channel_mode, + .bitsPerSample = bits_per_sample, .dataIntervalUs = data_interval_us, }; bool is_codec_config_valid = @@ -1490,7 +1493,7 @@ class BluetoothAudioProviderLeAudioBroadcastHardwareAidl std::vector<Lc3Configuration> GetBroadcastLc3SupportedList(bool supported) { std::vector<Lc3Configuration> le_audio_codec_configs; if (!supported) { - Lc3Configuration lc3_config{.samplingFrequencyHz = 0, .pcmBitDepth = 0}; + Lc3Configuration lc3_config{.pcmBitDepth = 0, .samplingFrequencyHz = 0}; le_audio_codec_configs.push_back(lc3_config); return le_audio_codec_configs; } @@ -1650,8 +1653,8 @@ TEST_P(BluetoothAudioProviderA2dpDecodingSoftwareAidl, for (auto channel_mode : a2dp_channel_modes) { PcmConfiguration pcm_config{ .sampleRateHz = sample_rate, - .bitsPerSample = bits_per_sample, .channelMode = channel_mode, + .bitsPerSample = bits_per_sample, }; bool is_codec_config_valid = IsPcmConfigSupported(pcm_config); DataMQDesc mq_desc; diff --git a/bluetooth/audio/utils/Android.bp b/bluetooth/audio/utils/Android.bp index d08cb0a8e6..70797a7aaf 100644 --- a/bluetooth/audio/utils/Android.bp +++ b/bluetooth/audio/utils/Android.bp @@ -40,9 +40,13 @@ cc_library_shared { "aidl_session/BluetoothAudioCodecs.cpp", "aidl_session/BluetoothAudioSession.cpp", "aidl_session/HidlToAidlMiddleware.cpp", + "aidl_session/BluetoothLeAudioCodecsProvider.cpp", ], export_include_dirs: ["aidl_session/"], - header_libs: ["libhardware_headers"], + header_libs: [ + "libhardware_headers", + "libxsdc-utils", + ], shared_libs: [ "android.hardware.bluetooth.audio@2.0", "android.hardware.bluetooth.audio@2.1", @@ -53,5 +57,40 @@ cc_library_shared { "liblog", "android.hardware.bluetooth.audio-V2-ndk", "libhidlbase", + "libxml2", + ], + generated_sources: ["le_audio_codec_capabilities"], + generated_headers: ["le_audio_codec_capabilities"], +} + +cc_test { + name: "BluetoothLeAudioCodecsProviderTest", + srcs: [ + "aidl_session/BluetoothLeAudioCodecsProvider.cpp", + "aidl_session/BluetoothLeAudioCodecsProviderTest.cpp", ], + header_libs: [ + "libxsdc-utils", + ], + shared_libs: [ + "libbase", + "libbinder_ndk", + "android.hardware.bluetooth.audio-V2-ndk", + "libxml2", + ], + test_suites: [ + "general-tests", + ], + test_options: { + unit_test: false, + }, + generated_sources: ["le_audio_codec_capabilities"], + generated_headers: ["le_audio_codec_capabilities"], +} + +xsd_config { + name: "le_audio_codec_capabilities", + srcs: ["le_audio_codec_capabilities/le_audio_codec_capabilities.xsd"], + package_name: "aidl.android.hardware.bluetooth.audio.setting", + api_dir: "le_audio_codec_capabilities/schema", } diff --git a/bluetooth/audio/utils/aidl_session/BluetoothAudioCodecs.cpp b/bluetooth/audio/utils/aidl_session/BluetoothAudioCodecs.cpp index b858f504ed..faebbbf32b 100644 --- a/bluetooth/audio/utils/aidl_session/BluetoothAudioCodecs.cpp +++ b/bluetooth/audio/utils/aidl_session/BluetoothAudioCodecs.cpp @@ -32,6 +32,8 @@ #include <aidl/android/hardware/bluetooth/audio/SbcChannelMode.h> #include <android-base/logging.h> +#include "BluetoothLeAudioCodecsProvider.h" + namespace aidl { namespace android { namespace hardware { @@ -96,67 +98,6 @@ const std::vector<CodecCapabilities> kDefaultOffloadA2dpCodecCapabilities = { std::vector<LeAudioCodecCapabilitiesSetting> kDefaultOffloadLeAudioCapabilities; -static const UnicastCapability kInvalidUnicastCapability = { - .codecType = CodecType::UNKNOWN}; - -static const BroadcastCapability kInvalidBroadcastCapability = { - .codecType = CodecType::UNKNOWN}; - -// Default Supported Codecs -// LC3 16_1: sample rate: 16 kHz, frame duration: 7.5 ms, octets per frame: 30 -static const Lc3Capabilities kLc3Capability_16_1 = { - .samplingFrequencyHz = {16000}, - .frameDurationUs = {7500}, - .octetsPerFrame = {30}}; - -// Default Supported Codecs -// LC3 16_2: sample rate: 16 kHz, frame duration: 10 ms, octets per frame: 40 -static const Lc3Capabilities kLc3Capability_16_2 = { - .samplingFrequencyHz = {16000}, - .frameDurationUs = {10000}, - .octetsPerFrame = {40}}; - -// Default Supported Codecs -// LC3 24_2: sample rate: 24 kHz, frame duration: 10 ms, octets per frame: 60 -static const Lc3Capabilities kLc3Capability_24_2 = { - .samplingFrequencyHz = {24000}, - .frameDurationUs = {10000}, - .octetsPerFrame = {60}}; - -// Default Supported Codecs -// LC3 32_2: sample rate: 32 kHz, frame duration: 10 ms, octets per frame: 80 -static const Lc3Capabilities kLc3Capability_32_2 = { - .samplingFrequencyHz = {32000}, - .frameDurationUs = {10000}, - .octetsPerFrame = {80}}; - -// Default Supported Codecs -// LC3 48_4: sample rate: 48 kHz, frame duration: 10 ms, octets per frame: 120 -static const Lc3Capabilities kLc3Capability_48_4 = { - .samplingFrequencyHz = {48000}, - .frameDurationUs = {10000}, - .octetsPerFrame = {120}}; - -static const std::vector<Lc3Capabilities> supportedLc3CapabilityList = { - kLc3Capability_48_4, kLc3Capability_32_2, kLc3Capability_24_2, - kLc3Capability_16_2, kLc3Capability_16_1}; - -static AudioLocation stereoAudio = static_cast<AudioLocation>( - static_cast<uint8_t>(AudioLocation::FRONT_LEFT) | - static_cast<uint8_t>(AudioLocation::FRONT_RIGHT)); -static AudioLocation monoAudio = AudioLocation::UNKNOWN; - -// Stores the supported setting of audio location, connected device, and the -// channel count for each device -std::vector<std::tuple<AudioLocation, uint8_t, uint8_t>> - supportedDeviceSetting = { - // Stereo, two connected device, one for L one for R - std::make_tuple(stereoAudio, 2, 1), - // Stereo, one connected device for both L and R - std::make_tuple(stereoAudio, 1, 2), - // Mono - std::make_tuple(monoAudio, 1, 1)}; - template <class T> bool BluetoothAudioCodecs::ContainedInVector( const std::vector<T>& vector, const typename identity<T>::type& target) { @@ -321,19 +262,6 @@ bool BluetoothAudioCodecs::IsOffloadOpusConfigurationValid( return false; } -bool BluetoothAudioCodecs::IsOffloadLeAudioConfigurationValid( - const SessionType& session_type, const LeAudioConfiguration&) { - if (session_type != - SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH && - session_type != - SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH && - session_type != - SessionType::LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH) { - return false; - } - return true; -} - std::vector<PcmCapabilities> BluetoothAudioCodecs::GetSoftwarePcmCapabilities() { return {kDefaultSoftwarePcmCapabilities}; @@ -457,19 +385,6 @@ bool BluetoothAudioCodecs::IsOffloadCodecConfigurationValid( return false; } -UnicastCapability composeUnicastLc3Capability( - AudioLocation audioLocation, uint8_t deviceCnt, uint8_t channelCount, - const Lc3Capabilities& capability) { - return { - .codecType = CodecType::LC3, - .supportedChannel = audioLocation, - .deviceCount = deviceCnt, - .channelCountPerDevice = channelCount, - .leAudioCodecCapabilities = - UnicastCapability::LeAudioCodecCapabilities(capability), - }; -} - std::vector<LeAudioCodecCapabilitiesSetting> BluetoothAudioCodecs::GetLeAudioOffloadCodecCapabilities( const SessionType& session_type) { @@ -483,34 +398,11 @@ BluetoothAudioCodecs::GetLeAudioOffloadCodecCapabilities( } if (kDefaultOffloadLeAudioCapabilities.empty()) { - for (auto [audioLocation, deviceCnt, channelCount] : - supportedDeviceSetting) { - for (auto capability : supportedLc3CapabilityList) { - UnicastCapability lc3Capability = composeUnicastLc3Capability( - audioLocation, deviceCnt, channelCount, capability); - UnicastCapability lc3MonoDecodeCapability = - composeUnicastLc3Capability(monoAudio, 1, 1, capability); - - // Adds the capability for encode only - kDefaultOffloadLeAudioCapabilities.push_back( - {.unicastEncodeCapability = lc3Capability, - .unicastDecodeCapability = kInvalidUnicastCapability, - .broadcastCapability = kInvalidBroadcastCapability}); - - // Adds the capability for decode only - kDefaultOffloadLeAudioCapabilities.push_back( - {.unicastEncodeCapability = kInvalidUnicastCapability, - .unicastDecodeCapability = lc3Capability, - .broadcastCapability = kInvalidBroadcastCapability}); - - // Adds the capability for the case that encode and decode exist at the - // same time - kDefaultOffloadLeAudioCapabilities.push_back( - {.unicastEncodeCapability = lc3Capability, - .unicastDecodeCapability = lc3MonoDecodeCapability, - .broadcastCapability = kInvalidBroadcastCapability}); - } - } + auto le_audio_offload_setting = + BluetoothLeAudioCodecsProvider::ParseFromLeAudioOffloadSettingFile(); + kDefaultOffloadLeAudioCapabilities = + BluetoothLeAudioCodecsProvider::GetLeAudioCodecCapabilities( + le_audio_offload_setting); } return kDefaultOffloadLeAudioCapabilities; diff --git a/bluetooth/audio/utils/aidl_session/BluetoothAudioCodecs.h b/bluetooth/audio/utils/aidl_session/BluetoothAudioCodecs.h index ed0598b975..e3d657b497 100644 --- a/bluetooth/audio/utils/aidl_session/BluetoothAudioCodecs.h +++ b/bluetooth/audio/utils/aidl_session/BluetoothAudioCodecs.h @@ -44,9 +44,6 @@ class BluetoothAudioCodecs { static bool IsOffloadCodecConfigurationValid( const SessionType& session_type, const CodecConfiguration& codec_config); - static bool IsOffloadLeAudioConfigurationValid( - const SessionType& session_type, const LeAudioConfiguration&); - static std::vector<LeAudioCodecCapabilitiesSetting> GetLeAudioOffloadCodecCapabilities(const SessionType& session_type); diff --git a/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.cpp b/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.cpp index 3214bf2228..2b0caadeae 100644 --- a/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.cpp +++ b/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.cpp @@ -60,12 +60,14 @@ void BluetoothAudioSession::OnSessionStarted( LOG(ERROR) << __func__ << " - SessionType=" << toString(session_type_) << " MqDescriptor Invalid"; audio_config_ = nullptr; + leaudio_connection_map_ = nullptr; } else { stack_iface_ = stack_iface; latency_modes_ = latency_modes; LOG(INFO) << __func__ << " - SessionType=" << toString(session_type_) << ", AudioConfiguration=" << audio_config.toString(); ReportSessionStatus(); + is_streaming_ = false; } } @@ -74,11 +76,13 @@ void BluetoothAudioSession::OnSessionEnded() { bool toggled = IsSessionReady(); LOG(INFO) << __func__ << " - SessionType=" << toString(session_type_); audio_config_ = nullptr; + leaudio_connection_map_ = nullptr; stack_iface_ = nullptr; UpdateDataPath(nullptr); if (toggled) { ReportSessionStatus(); } + is_streaming_ = false; } /*** @@ -106,6 +110,14 @@ const AudioConfiguration BluetoothAudioSession::GetAudioConfig() { return *audio_config_; } +const AudioConfiguration BluetoothAudioSession::GetLeAudioConnectionMap() { + std::lock_guard<std::recursive_mutex> guard(mutex_); + if (!IsSessionReady()) { + return AudioConfiguration(LeAudioConfiguration{}); + } + return *leaudio_connection_map_; +} + void BluetoothAudioSession::ReportAudioConfigChanged( const AudioConfiguration& audio_config) { if (session_type_ != @@ -114,8 +126,56 @@ void BluetoothAudioSession::ReportAudioConfigChanged( SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH) { return; } + std::lock_guard<std::recursive_mutex> guard(mutex_); - audio_config_ = std::make_unique<AudioConfiguration>(audio_config); + if (audio_config.getTag() != AudioConfiguration::leAudioConfig) { + LOG(ERROR) << __func__ << " invalid audio config type for SessionType =" + << toString(session_type_); + return; + } + + if (is_streaming_) { + if (audio_config_ == nullptr) { + LOG(ERROR) << __func__ << " for SessionType=" << toString(session_type_) + << " audio_config_ is nullptr during streaming. It shouldn't " + "be happened"; + return; + } + + auto new_leaudio_config = + audio_config.get<AudioConfiguration::leAudioConfig>(); + auto current_leaudio_config = + (*audio_config_).get<AudioConfiguration::leAudioConfig>(); + if (new_leaudio_config.codecType != current_leaudio_config.codecType) { + LOG(ERROR) + << __func__ << " for SessionType=" << toString(session_type_) + << " codec type changed during streaming. It shouldn't be happened "; + } + auto new_lc3_config = new_leaudio_config.leAudioCodecConfig + .get<LeAudioCodecConfiguration::lc3Config>(); + auto current_lc3_config = current_leaudio_config.leAudioCodecConfig + .get<LeAudioCodecConfiguration::lc3Config>(); + if ((new_lc3_config.pcmBitDepth != current_lc3_config.pcmBitDepth) || + (new_lc3_config.samplingFrequencyHz != + current_lc3_config.samplingFrequencyHz) || + (new_lc3_config.frameDurationUs != + current_lc3_config.frameDurationUs) || + (new_lc3_config.octetsPerFrame != current_lc3_config.octetsPerFrame) || + (new_lc3_config.blocksPerSdu != current_lc3_config.blocksPerSdu)) { + LOG(ERROR) + << __func__ << " for SessionType=" << toString(session_type_) + << " lc3 config changed during streaming. It shouldn't be happened"; + return; + } + + leaudio_connection_map_ = + std::make_unique<AudioConfiguration>(audio_config); + } else { + audio_config_ = std::make_unique<AudioConfiguration>(audio_config); + leaudio_connection_map_ = + std::make_unique<AudioConfiguration>(audio_config); + } + if (observers_.empty()) { LOG(WARNING) << __func__ << " - SessionType=" << toString(session_type_) << " has NO port state observer"; @@ -127,7 +187,11 @@ void BluetoothAudioSession::ReportAudioConfigChanged( LOG(INFO) << __func__ << " for SessionType=" << toString(session_type_) << ", bluetooth_audio=0x" << ::android::base::StringPrintf("%04x", cookie); - if (cb->audio_configuration_changed_cb_ != nullptr) { + if (is_streaming_) { + if (cb->soft_audio_configuration_changed_cb_ != nullptr) { + cb->soft_audio_configuration_changed_cb_(cookie); + } + } else if (cb->audio_configuration_changed_cb_ != nullptr) { cb->audio_configuration_changed_cb_(cookie); } } @@ -274,11 +338,14 @@ bool BluetoothAudioSession::UpdateAudioConfig( bool is_offload_a2dp_session = (session_type_ == SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH || session_type_ == SessionType::A2DP_HARDWARE_OFFLOAD_DECODING_DATAPATH); - bool is_offload_le_audio_session = + bool is_offload_le_audio_unicast_session = (session_type_ == SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH || session_type_ == SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH); + bool is_offload_le_audio_broadcast_session = + (session_type_ == + SessionType::LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH); auto audio_config_tag = audio_config.getTag(); bool is_software_audio_config = (is_software_session && @@ -286,11 +353,15 @@ bool BluetoothAudioSession::UpdateAudioConfig( bool is_a2dp_offload_audio_config = (is_offload_a2dp_session && audio_config_tag == AudioConfiguration::a2dpConfig); - bool is_le_audio_offload_audio_config = - (is_offload_le_audio_session && + bool is_le_audio_offload_unicast_audio_config = + (is_offload_le_audio_unicast_session && audio_config_tag == AudioConfiguration::leAudioConfig); + bool is_le_audio_offload_broadcast_audio_config = + (is_offload_le_audio_broadcast_session && + audio_config_tag == AudioConfiguration::leAudioBroadcastConfig); if (!is_software_audio_config && !is_a2dp_offload_audio_config && - !is_le_audio_offload_audio_config) { + !is_le_audio_offload_unicast_audio_config && + !is_le_audio_offload_broadcast_audio_config) { return false; } audio_config_ = std::make_unique<AudioConfiguration>(audio_config); @@ -410,6 +481,12 @@ void BluetoothAudioSession::ReportControlStatus(bool start_resp, << " has NO port state observer"; return; } + if (start_resp && status == BluetoothAudioStatus::SUCCESS) { + is_streaming_ = true; + } else if (!start_resp && (status == BluetoothAudioStatus::SUCCESS || + status == BluetoothAudioStatus::RECONFIGURATION)) { + is_streaming_ = false; + } for (auto& observer : observers_) { uint16_t cookie = observer.first; std::shared_ptr<PortStatusCallbacks> callback = observer.second; diff --git a/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.h b/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.h index 5bf17bd3d2..faf4ffbabe 100644 --- a/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.h +++ b/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.h @@ -102,6 +102,13 @@ struct PortStatusCallbacks { ***/ std::function<void(uint16_t cookie, bool allowed)> low_latency_mode_allowed_cb_; + /*** + * soft_audio_configuration_changed_cb_ - when the Bluetooth stack change + * the streamMap during the streaming, the BluetoothAudioProvider will invoke + * this callback to report to the bluetooth_audio module. + * @param: cookie - indicates which bluetooth_audio output should handle + ***/ + std::function<void(uint16_t cookie)> soft_audio_configuration_changed_cb_; }; class BluetoothAudioSession { @@ -159,6 +166,12 @@ class BluetoothAudioSession { const AudioConfiguration GetAudioConfig(); /*** + * The control function is for the bluetooth_audio module to get the current + * LE audio connection map + ***/ + const AudioConfiguration GetLeAudioConnectionMap(); + + /*** * The report function is used to report that the Bluetooth stack has notified * the audio configuration changed, and will invoke * audio_configuration_changed_cb_ to notify registered bluetooth_audio @@ -206,8 +219,11 @@ class BluetoothAudioSession { std::unique_ptr<DataMQ> data_mq_; // audio data configuration for both software and offloading std::unique_ptr<AudioConfiguration> audio_config_; + std::unique_ptr<AudioConfiguration> leaudio_connection_map_; std::vector<LatencyMode> latency_modes_; bool low_latency_allowed_ = true; + // saving those steaming state based on the session_type + bool is_streaming_ = false; // saving those registered bluetooth_audio's callbacks std::unordered_map<uint16_t, std::shared_ptr<struct PortStatusCallbacks>> diff --git a/bluetooth/audio/utils/aidl_session/BluetoothAudioSessionControl.h b/bluetooth/audio/utils/aidl_session/BluetoothAudioSessionControl.h index 0782c824e1..881c6c10b2 100644 --- a/bluetooth/audio/utils/aidl_session/BluetoothAudioSessionControl.h +++ b/bluetooth/audio/utils/aidl_session/BluetoothAudioSessionControl.h @@ -95,6 +95,25 @@ class BluetoothAudioSessionControl { } /*** + * The control API for the bluetooth_audio module to get current + * LE audio connection map + ***/ + static const AudioConfiguration GetLeAudioConnectionMap( + const SessionType& session_type) { + std::shared_ptr<BluetoothAudioSession> session_ptr = + BluetoothAudioSessionInstance::GetSessionInstance(session_type); + if ((session_type == + SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH || + session_type == + SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH) && + session_ptr != nullptr) { + return session_ptr->GetLeAudioConnectionMap(); + } + + return AudioConfiguration(LeAudioConfiguration{}); + } + + /*** * Those control APIs for the bluetooth_audio module to start / suspend / stop * stream, to check position, and to update metadata. diff --git a/bluetooth/audio/utils/aidl_session/BluetoothLeAudioCodecsProvider.cpp b/bluetooth/audio/utils/aidl_session/BluetoothLeAudioCodecsProvider.cpp new file mode 100644 index 0000000000..1dec900aed --- /dev/null +++ b/bluetooth/audio/utils/aidl_session/BluetoothLeAudioCodecsProvider.cpp @@ -0,0 +1,341 @@ +/* + * 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 "BTAudioCodecsProviderAidl" + +#include "BluetoothLeAudioCodecsProvider.h" + +namespace aidl { +namespace android { +namespace hardware { +namespace bluetooth { +namespace audio { + +static const char* kLeAudioCodecCapabilitiesFile = + "/vendor/etc/le_audio_codec_capabilities.xml"; + +static const AudioLocation kStereoAudio = static_cast<AudioLocation>( + static_cast<uint8_t>(AudioLocation::FRONT_LEFT) | + static_cast<uint8_t>(AudioLocation::FRONT_RIGHT)); +static const AudioLocation kMonoAudio = AudioLocation::UNKNOWN; + +static std::vector<LeAudioCodecCapabilitiesSetting> leAudioCodecCapabilities; + +static bool isInvalidFileContent = false; + +std::optional<setting::LeAudioOffloadSetting> +BluetoothLeAudioCodecsProvider::ParseFromLeAudioOffloadSettingFile() { + if (!leAudioCodecCapabilities.empty() || isInvalidFileContent) { + return std::nullopt; + } + auto le_audio_offload_setting = + setting::readLeAudioOffloadSetting(kLeAudioCodecCapabilitiesFile); + if (!le_audio_offload_setting.has_value()) { + LOG(ERROR) << __func__ << ": Failed to read " + << kLeAudioCodecCapabilitiesFile; + } + return le_audio_offload_setting; +} + +std::vector<LeAudioCodecCapabilitiesSetting> +BluetoothLeAudioCodecsProvider::GetLeAudioCodecCapabilities( + const std::optional<setting::LeAudioOffloadSetting>& + le_audio_offload_setting) { + if (!leAudioCodecCapabilities.empty()) { + return leAudioCodecCapabilities; + } + + if (!le_audio_offload_setting.has_value()) { + LOG(ERROR) + << __func__ + << ": input le_audio_offload_setting content need to be non empty"; + return {}; + } + + ClearLeAudioCodecCapabilities(); + isInvalidFileContent = true; + + std::vector<setting::Scenario> supported_scenarios = + GetScenarios(le_audio_offload_setting); + if (supported_scenarios.empty()) { + LOG(ERROR) << __func__ << ": No scenarios in " + << kLeAudioCodecCapabilitiesFile; + return {}; + } + + UpdateConfigurationsToMap(le_audio_offload_setting); + if (configuration_map_.empty()) { + LOG(ERROR) << __func__ << ": No configurations in " + << kLeAudioCodecCapabilitiesFile; + return {}; + } + + UpdateCodecConfigurationsToMap(le_audio_offload_setting); + if (codec_configuration_map_.empty()) { + LOG(ERROR) << __func__ << ": No codec configurations in " + << kLeAudioCodecCapabilitiesFile; + return {}; + } + + UpdateStrategyConfigurationsToMap(le_audio_offload_setting); + if (strategy_configuration_map_.empty()) { + LOG(ERROR) << __func__ << ": No strategy configurations in " + << kLeAudioCodecCapabilitiesFile; + return {}; + } + + leAudioCodecCapabilities = + ComposeLeAudioCodecCapabilities(supported_scenarios); + isInvalidFileContent = leAudioCodecCapabilities.empty(); + + return leAudioCodecCapabilities; +} + +void BluetoothLeAudioCodecsProvider::ClearLeAudioCodecCapabilities() { + leAudioCodecCapabilities.clear(); + configuration_map_.clear(); + codec_configuration_map_.clear(); + strategy_configuration_map_.clear(); +} + +std::vector<setting::Scenario> BluetoothLeAudioCodecsProvider::GetScenarios( + const std::optional<setting::LeAudioOffloadSetting>& + le_audio_offload_setting) { + std::vector<setting::Scenario> supported_scenarios; + if (le_audio_offload_setting->hasScenarioList()) { + for (const auto& scenario_list : + le_audio_offload_setting->getScenarioList()) { + if (!scenario_list.hasScenario()) { + continue; + } + for (const auto& scenario : scenario_list.getScenario()) { + if (scenario.hasEncode() && scenario.hasDecode()) { + supported_scenarios.push_back(scenario); + } + } + } + } + return supported_scenarios; +} + +void BluetoothLeAudioCodecsProvider::UpdateConfigurationsToMap( + const std::optional<setting::LeAudioOffloadSetting>& + le_audio_offload_setting) { + if (le_audio_offload_setting->hasConfigurationList()) { + for (const auto& configuration_list : + le_audio_offload_setting->getConfigurationList()) { + if (!configuration_list.hasConfiguration()) { + continue; + } + for (const auto& configuration : configuration_list.getConfiguration()) { + if (configuration.hasName() && configuration.hasCodecConfiguration() && + configuration.hasStrategyConfiguration()) { + configuration_map_.insert( + make_pair(configuration.getName(), configuration)); + } + } + } + } +} + +void BluetoothLeAudioCodecsProvider::UpdateCodecConfigurationsToMap( + const std::optional<setting::LeAudioOffloadSetting>& + le_audio_offload_setting) { + if (le_audio_offload_setting->hasCodecConfigurationList()) { + for (const auto& codec_configuration_list : + le_audio_offload_setting->getCodecConfigurationList()) { + if (!codec_configuration_list.hasCodecConfiguration()) { + continue; + } + for (const auto& codec_configuration : + codec_configuration_list.getCodecConfiguration()) { + if (IsValidCodecConfiguration(codec_configuration)) { + codec_configuration_map_.insert( + make_pair(codec_configuration.getName(), codec_configuration)); + } + } + } + } +} + +void BluetoothLeAudioCodecsProvider::UpdateStrategyConfigurationsToMap( + const std::optional<setting::LeAudioOffloadSetting>& + le_audio_offload_setting) { + if (le_audio_offload_setting->hasStrategyConfigurationList()) { + for (const auto& strategy_configuration_list : + le_audio_offload_setting->getStrategyConfigurationList()) { + if (!strategy_configuration_list.hasStrategyConfiguration()) { + continue; + } + for (const auto& strategy_configuration : + strategy_configuration_list.getStrategyConfiguration()) { + if (IsValidStrategyConfiguration(strategy_configuration)) { + strategy_configuration_map_.insert(make_pair( + strategy_configuration.getName(), strategy_configuration)); + } + } + } + } +} + +std::vector<LeAudioCodecCapabilitiesSetting> +BluetoothLeAudioCodecsProvider::ComposeLeAudioCodecCapabilities( + const std::vector<setting::Scenario>& supported_scenarios) { + std::vector<LeAudioCodecCapabilitiesSetting> le_audio_codec_capabilities; + for (const auto& scenario : supported_scenarios) { + UnicastCapability unicast_encode_capability = + GetUnicastCapability(scenario.getEncode()); + UnicastCapability unicast_decode_capability = + GetUnicastCapability(scenario.getDecode()); + // encode and decode cannot be unknown at the same time + if (unicast_encode_capability.codecType == CodecType::UNKNOWN && + unicast_decode_capability.codecType == CodecType::UNKNOWN) { + continue; + } + BroadcastCapability broadcast_capability = {.codecType = + CodecType::UNKNOWN}; + le_audio_codec_capabilities.push_back( + {.unicastEncodeCapability = unicast_encode_capability, + .unicastDecodeCapability = unicast_decode_capability, + .broadcastCapability = broadcast_capability}); + } + return le_audio_codec_capabilities; +} + +UnicastCapability BluetoothLeAudioCodecsProvider::GetUnicastCapability( + const std::string& coding_direction) { + if (coding_direction == "invalid") { + return {.codecType = CodecType::UNKNOWN}; + } + + auto configuration_iter = configuration_map_.find(coding_direction); + if (configuration_iter == configuration_map_.end()) { + return {.codecType = CodecType::UNKNOWN}; + } + + auto codec_configuration_iter = codec_configuration_map_.find( + configuration_iter->second.getCodecConfiguration()); + if (codec_configuration_iter == codec_configuration_map_.end()) { + return {.codecType = CodecType::UNKNOWN}; + } + + auto strategy_configuration_iter = strategy_configuration_map_.find( + configuration_iter->second.getStrategyConfiguration()); + if (strategy_configuration_iter == strategy_configuration_map_.end()) { + return {.codecType = CodecType::UNKNOWN}; + } + + CodecType codec_type = + GetCodecType(codec_configuration_iter->second.getCodec()); + if (codec_type == CodecType::LC3) { + return ComposeUnicastCapability( + codec_type, + GetAudioLocation( + strategy_configuration_iter->second.getAudioLocation()), + strategy_configuration_iter->second.getConnectedDevice(), + strategy_configuration_iter->second.getChannelCount(), + ComposeLc3Capability(codec_configuration_iter->second)); + } + return {.codecType = CodecType::UNKNOWN}; +} + +template <class T> +UnicastCapability BluetoothLeAudioCodecsProvider::ComposeUnicastCapability( + const CodecType& codec_type, const AudioLocation& audio_location, + const uint8_t& device_cnt, const uint8_t& channel_count, + const T& capability) { + return { + .codecType = codec_type, + .supportedChannel = audio_location, + .deviceCount = device_cnt, + .channelCountPerDevice = channel_count, + .leAudioCodecCapabilities = + UnicastCapability::LeAudioCodecCapabilities(capability), + }; +} + +Lc3Capabilities BluetoothLeAudioCodecsProvider::ComposeLc3Capability( + const setting::CodecConfiguration& codec_configuration) { + return {.samplingFrequencyHz = {codec_configuration.getSamplingFrequency()}, + .frameDurationUs = {codec_configuration.getFrameDurationUs()}, + .octetsPerFrame = {codec_configuration.getOctetsPerCodecFrame()}}; +} + +AudioLocation BluetoothLeAudioCodecsProvider::GetAudioLocation( + const setting::AudioLocation& audio_location) { + switch (audio_location) { + case setting::AudioLocation::MONO: + return kMonoAudio; + case setting::AudioLocation::STEREO: + return kStereoAudio; + default: + return AudioLocation::UNKNOWN; + } +} + +CodecType BluetoothLeAudioCodecsProvider::GetCodecType( + const setting::CodecType& codec_type) { + switch (codec_type) { + case setting::CodecType::LC3: + return CodecType::LC3; + default: + return CodecType::UNKNOWN; + } +} + +bool BluetoothLeAudioCodecsProvider::IsValidCodecConfiguration( + const setting::CodecConfiguration& codec_configuration) { + return codec_configuration.hasName() && codec_configuration.hasCodec() && + codec_configuration.hasSamplingFrequency() && + codec_configuration.hasFrameDurationUs() && + codec_configuration.hasOctetsPerCodecFrame(); +} + +bool BluetoothLeAudioCodecsProvider::IsValidStrategyConfiguration( + const setting::StrategyConfiguration& strategy_configuration) { + if (!strategy_configuration.hasName() || + !strategy_configuration.hasAudioLocation() || + !strategy_configuration.hasConnectedDevice() || + !strategy_configuration.hasChannelCount()) { + return false; + } + if (strategy_configuration.getAudioLocation() == + setting::AudioLocation::STEREO) { + if ((strategy_configuration.getConnectedDevice() == 2 && + strategy_configuration.getChannelCount() == 1) || + (strategy_configuration.getConnectedDevice() == 1 && + strategy_configuration.getChannelCount() == 2)) { + // Stereo + // 1. two connected device, one for L one for R + // 2. one connected device for both L and R + return true; + } + } else if (strategy_configuration.getAudioLocation() == + setting::AudioLocation::MONO) { + if (strategy_configuration.getConnectedDevice() == 1 && + strategy_configuration.getChannelCount() == 1) { + // Mono + return true; + } + } + return false; +} + +} // namespace audio +} // namespace bluetooth +} // namespace hardware +} // namespace android +} // namespace aidl diff --git a/bluetooth/audio/utils/aidl_session/BluetoothLeAudioCodecsProvider.h b/bluetooth/audio/utils/aidl_session/BluetoothLeAudioCodecsProvider.h new file mode 100644 index 0000000000..e8799843ef --- /dev/null +++ b/bluetooth/audio/utils/aidl_session/BluetoothLeAudioCodecsProvider.h @@ -0,0 +1,92 @@ +/* + * 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 <aidl/android/hardware/bluetooth/audio/LeAudioCodecCapabilitiesSetting.h> +#include <android-base/logging.h> + +#include <unordered_map> + +#include "aidl_android_hardware_bluetooth_audio_setting.h" + +namespace aidl { +namespace android { +namespace hardware { +namespace bluetooth { +namespace audio { + +class BluetoothLeAudioCodecsProvider { + public: + static std::optional<setting::LeAudioOffloadSetting> + ParseFromLeAudioOffloadSettingFile(); + static std::vector<LeAudioCodecCapabilitiesSetting> + GetLeAudioCodecCapabilities( + const std::optional<setting::LeAudioOffloadSetting>& + le_audio_offload_setting); + static void ClearLeAudioCodecCapabilities(); + + private: + static inline std::unordered_map<std::string, setting::Configuration> + configuration_map_; + static inline std::unordered_map<std::string, setting::CodecConfiguration> + codec_configuration_map_; + static inline std::unordered_map<std::string, setting::StrategyConfiguration> + strategy_configuration_map_; + + static std::vector<setting::Scenario> GetScenarios( + const std::optional<setting::LeAudioOffloadSetting>& + le_audio_offload_setting); + static void UpdateConfigurationsToMap( + const std::optional<setting::LeAudioOffloadSetting>& + le_audio_offload_setting); + static void UpdateCodecConfigurationsToMap( + const std::optional<setting::LeAudioOffloadSetting>& + le_audio_offload_setting); + static void UpdateStrategyConfigurationsToMap( + const std::optional<setting::LeAudioOffloadSetting>& + le_audio_offload_setting); + + static std::vector<LeAudioCodecCapabilitiesSetting> + ComposeLeAudioCodecCapabilities( + const std::vector<setting::Scenario>& supported_scenarios); + + static UnicastCapability GetUnicastCapability( + const std::string& coding_direction); + template <class T> + static inline UnicastCapability ComposeUnicastCapability( + const CodecType& codec_type, const AudioLocation& audio_location, + const uint8_t& device_cnt, const uint8_t& channel_count, + const T& capability); + + static inline Lc3Capabilities ComposeLc3Capability( + const setting::CodecConfiguration& codec_configuration); + + static inline AudioLocation GetAudioLocation( + const setting::AudioLocation& audio_location); + static inline CodecType GetCodecType(const setting::CodecType& codec_type); + + static inline bool IsValidCodecConfiguration( + const setting::CodecConfiguration& codec_configuration); + static inline bool IsValidStrategyConfiguration( + const setting::StrategyConfiguration& strategy_configuration); +}; + +} // namespace audio +} // namespace bluetooth +} // namespace hardware +} // namespace android +} // namespace aidl diff --git a/bluetooth/audio/utils/aidl_session/BluetoothLeAudioCodecsProviderTest.cpp b/bluetooth/audio/utils/aidl_session/BluetoothLeAudioCodecsProviderTest.cpp new file mode 100644 index 0000000000..5393cd70e8 --- /dev/null +++ b/bluetooth/audio/utils/aidl_session/BluetoothLeAudioCodecsProviderTest.cpp @@ -0,0 +1,373 @@ +/* + * 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. + */ + +#include <gtest/gtest.h> + +#include <optional> +#include <tuple> + +#include "BluetoothLeAudioCodecsProvider.h" + +using aidl::android::hardware::bluetooth::audio::BluetoothLeAudioCodecsProvider; +using aidl::android::hardware::bluetooth::audio:: + LeAudioCodecCapabilitiesSetting; +using aidl::android::hardware::bluetooth::audio::setting::AudioLocation; +using aidl::android::hardware::bluetooth::audio::setting::CodecConfiguration; +using aidl::android::hardware::bluetooth::audio::setting:: + CodecConfigurationList; +using aidl::android::hardware::bluetooth::audio::setting::CodecType; +using aidl::android::hardware::bluetooth::audio::setting::Configuration; +using aidl::android::hardware::bluetooth::audio::setting::ConfigurationList; +using aidl::android::hardware::bluetooth::audio::setting::LeAudioOffloadSetting; +using aidl::android::hardware::bluetooth::audio::setting::Scenario; +using aidl::android::hardware::bluetooth::audio::setting::ScenarioList; +using aidl::android::hardware::bluetooth::audio::setting::StrategyConfiguration; +using aidl::android::hardware::bluetooth::audio::setting:: + StrategyConfigurationList; + +typedef std::tuple<std::vector<ScenarioList>, std::vector<ConfigurationList>, + std::vector<CodecConfigurationList>, + std::vector<StrategyConfigurationList>> + OffloadSetting; + +// Define valid components for each list +// Scenario +static const Scenario kValidScenario(std::make_optional("OneChanStereo_16_1"), + std::make_optional("OneChanStereo_16_1")); +// Configuration +static const Configuration kValidConfigOneChanStereo_16_1( + std::make_optional("OneChanStereo_16_1"), std::make_optional("LC3_16k_1"), + std::make_optional("STEREO_ONE_CIS_PER_DEVICE")); +// CodecConfiguration +static const CodecConfiguration kValidCodecLC3_16k_1( + std::make_optional("LC3_16k_1"), std::make_optional(CodecType::LC3), + std::nullopt, std::make_optional(16000), std::make_optional(7500), + std::make_optional(30), std::nullopt); +// StrategyConfiguration +static const StrategyConfiguration kValidStrategyStereoOneCis( + std::make_optional("STEREO_ONE_CIS_PER_DEVICE"), + std::make_optional(AudioLocation::STEREO), std::make_optional(2), + std::make_optional(1)); +static const StrategyConfiguration kValidStrategyStereoTwoCis( + std::make_optional("STEREO_TWO_CISES_PER_DEVICE"), + std::make_optional(AudioLocation::STEREO), std::make_optional(1), + std::make_optional(2)); +static const StrategyConfiguration kValidStrategyMonoOneCis( + std::make_optional("MONO_ONE_CIS_PER_DEVICE"), + std::make_optional(AudioLocation::MONO), std::make_optional(1), + std::make_optional(1)); + +// Define valid test list built from above valid components +// Scenario, Configuration, CodecConfiguration, StrategyConfiguration +static const std::vector<ScenarioList> kValidScenarioList = { + ScenarioList(std::vector<Scenario>{kValidScenario})}; +static const std::vector<ConfigurationList> kValidConfigurationList = { + ConfigurationList( + std::vector<Configuration>{kValidConfigOneChanStereo_16_1})}; +static const std::vector<CodecConfigurationList> kValidCodecConfigurationList = + {CodecConfigurationList( + std::vector<CodecConfiguration>{kValidCodecLC3_16k_1})}; +static const std::vector<StrategyConfigurationList> + kValidStrategyConfigurationList = { + StrategyConfigurationList(std::vector<StrategyConfiguration>{ + kValidStrategyStereoOneCis, kValidStrategyStereoTwoCis, + kValidStrategyMonoOneCis})}; + +class BluetoothLeAudioCodecsProviderTest + : public ::testing::TestWithParam<OffloadSetting> { + public: + static std::vector<OffloadSetting> CreateTestCases( + const std::vector<ScenarioList>& scenario_lists, + const std::vector<ConfigurationList>& configuration_lists, + const std::vector<CodecConfigurationList>& codec_configuration_lists, + const std::vector<StrategyConfigurationList>& + strategy_configuration_lists) { + // make each vector in output test_cases has only one element + // to match the input of test params + // normally only one vector in input has multiple elements + // we just split elements in this vector to several vector + std::vector<OffloadSetting> test_cases; + for (const auto& scenario_list : scenario_lists) { + for (const auto& configuration_list : configuration_lists) { + for (const auto& codec_configuration_list : codec_configuration_lists) { + for (const auto& strategy_configuration_list : + strategy_configuration_lists) { + test_cases.push_back(CreateTestCase( + scenario_list, configuration_list, codec_configuration_list, + strategy_configuration_list)); + } + } + } + } + return test_cases; + } + + protected: + void Initialize() { + BluetoothLeAudioCodecsProvider::ClearLeAudioCodecCapabilities(); + } + + std::vector<LeAudioCodecCapabilitiesSetting> RunTestCase() { + auto& [scenario_lists, configuration_lists, codec_configuration_lists, + strategy_configuration_lists] = GetParam(); + LeAudioOffloadSetting le_audio_offload_setting( + scenario_lists, configuration_lists, codec_configuration_lists, + strategy_configuration_lists); + auto le_audio_codec_capabilities = + BluetoothLeAudioCodecsProvider::GetLeAudioCodecCapabilities( + std::make_optional(le_audio_offload_setting)); + return le_audio_codec_capabilities; + } + + private: + static inline OffloadSetting CreateTestCase( + const ScenarioList& scenario_list, + const ConfigurationList& configuration_list, + const CodecConfigurationList& codec_configuration_list, + const StrategyConfigurationList& strategy_configuration_list) { + return std::make_tuple( + std::vector<ScenarioList>{scenario_list}, + std::vector<ConfigurationList>{configuration_list}, + std::vector<CodecConfigurationList>{codec_configuration_list}, + std::vector<StrategyConfigurationList>{strategy_configuration_list}); + } +}; + +class GetScenariosTest : public BluetoothLeAudioCodecsProviderTest { + public: + static std::vector<ScenarioList> CreateInvalidScenarios() { + std::vector<ScenarioList> invalid_scenario_test_cases; + invalid_scenario_test_cases.push_back(ScenarioList(std::vector<Scenario>{ + Scenario(std::nullopt, std::make_optional("OneChanStereo_16_1"))})); + + invalid_scenario_test_cases.push_back(ScenarioList(std::vector<Scenario>{ + Scenario(std::make_optional("OneChanStereo_16_1"), std::nullopt)})); + + invalid_scenario_test_cases.push_back(ScenarioList( + std::vector<Scenario>{Scenario(std::nullopt, std::nullopt)})); + + invalid_scenario_test_cases.push_back( + ScenarioList(std::vector<Scenario>{})); + + return invalid_scenario_test_cases; + } +}; + +TEST_P(GetScenariosTest, InvalidScenarios) { + Initialize(); + auto le_audio_codec_capabilities = RunTestCase(); + ASSERT_TRUE(le_audio_codec_capabilities.empty()); +} + +class UpdateConfigurationsToMapTest + : public BluetoothLeAudioCodecsProviderTest { + public: + static std::vector<ConfigurationList> CreateInvalidConfigurations() { + std::vector<ConfigurationList> invalid_configuration_test_cases; + invalid_configuration_test_cases.push_back( + ConfigurationList(std::vector<Configuration>{ + Configuration(std::nullopt, std::make_optional("LC3_16k_1"), + std::make_optional("STEREO_ONE_CIS_PER_DEVICE"))})); + + invalid_configuration_test_cases.push_back( + ConfigurationList(std::vector<Configuration>{Configuration( + std::make_optional("OneChanStereo_16_1"), std::nullopt, + std::make_optional("STEREO_ONE_CIS_PER_DEVICE"))})); + + invalid_configuration_test_cases.push_back( + ConfigurationList(std::vector<Configuration>{ + Configuration(std::make_optional("OneChanStereo_16_1"), + std::make_optional("LC3_16k_1"), std::nullopt)})); + + invalid_configuration_test_cases.push_back( + ConfigurationList(std::vector<Configuration>{})); + + return invalid_configuration_test_cases; + } +}; + +TEST_P(UpdateConfigurationsToMapTest, InvalidConfigurations) { + Initialize(); + auto le_audio_codec_capabilities = RunTestCase(); + ASSERT_TRUE(le_audio_codec_capabilities.empty()); +} + +class UpdateCodecConfigurationsToMapTest + : public BluetoothLeAudioCodecsProviderTest { + public: + static std::vector<CodecConfigurationList> + CreateInvalidCodecConfigurations() { + std::vector<CodecConfigurationList> invalid_codec_configuration_test_cases; + invalid_codec_configuration_test_cases.push_back(CodecConfigurationList( + std::vector<CodecConfiguration>{CodecConfiguration( + std::nullopt, std::make_optional(CodecType::LC3), std::nullopt, + std::make_optional(16000), std::make_optional(7500), + std::make_optional(30), std::nullopt)})); + + invalid_codec_configuration_test_cases.push_back(CodecConfigurationList( + std::vector<CodecConfiguration>{CodecConfiguration( + std::make_optional("LC3_16k_1"), std::nullopt, std::nullopt, + std::make_optional(16000), std::make_optional(7500), + std::make_optional(30), std::nullopt)})); + + invalid_codec_configuration_test_cases.push_back(CodecConfigurationList( + std::vector<CodecConfiguration>{CodecConfiguration( + std::make_optional("LC3_16k_1"), std::make_optional(CodecType::LC3), + std::nullopt, std::nullopt, std::make_optional(7500), + std::make_optional(30), std::nullopt)})); + + invalid_codec_configuration_test_cases.push_back(CodecConfigurationList( + std::vector<CodecConfiguration>{CodecConfiguration( + std::make_optional("LC3_16k_1"), std::make_optional(CodecType::LC3), + std::nullopt, std::make_optional(16000), std::nullopt, + std::make_optional(30), std::nullopt)})); + + invalid_codec_configuration_test_cases.push_back(CodecConfigurationList( + std::vector<CodecConfiguration>{CodecConfiguration( + std::make_optional("LC3_16k_1"), std::make_optional(CodecType::LC3), + std::nullopt, std::make_optional(16000), std::make_optional(7500), + std::nullopt, std::nullopt)})); + + invalid_codec_configuration_test_cases.push_back( + CodecConfigurationList(std::vector<CodecConfiguration>{})); + + return invalid_codec_configuration_test_cases; + } +}; + +TEST_P(UpdateCodecConfigurationsToMapTest, InvalidCodecConfigurations) { + Initialize(); + auto le_audio_codec_capabilities = RunTestCase(); + ASSERT_TRUE(le_audio_codec_capabilities.empty()); +} + +class UpdateStrategyConfigurationsToMapTest + : public BluetoothLeAudioCodecsProviderTest { + public: + static std::vector<StrategyConfigurationList> + CreateInvalidStrategyConfigurations() { + std::vector<StrategyConfigurationList> + invalid_strategy_configuration_test_cases; + invalid_strategy_configuration_test_cases.push_back( + StrategyConfigurationList( + std::vector<StrategyConfiguration>{StrategyConfiguration( + std::make_optional("STEREO_ONE_CIS_PER_DEVICE"), + std::make_optional(AudioLocation::STEREO), + std::make_optional(2), std::make_optional(2))})); + + invalid_strategy_configuration_test_cases.push_back( + StrategyConfigurationList( + std::vector<StrategyConfiguration>{StrategyConfiguration( + std::make_optional("MONO_ONE_CIS_PER_DEVICE"), + std::make_optional(AudioLocation::STEREO), + std::make_optional(2), std::make_optional(2))})); + + invalid_strategy_configuration_test_cases.push_back( + StrategyConfigurationList( + std::vector<StrategyConfiguration>{StrategyConfiguration( + std::nullopt, std::make_optional(AudioLocation::STEREO), + std::make_optional(2), std::make_optional(1))})); + + invalid_strategy_configuration_test_cases.push_back( + StrategyConfigurationList( + std::vector<StrategyConfiguration>{StrategyConfiguration( + std::make_optional("STEREO_ONE_CIS_PER_DEVICE"), std::nullopt, + std::make_optional(2), std::make_optional(1))})); + + invalid_strategy_configuration_test_cases.push_back( + StrategyConfigurationList( + std::vector<StrategyConfiguration>{StrategyConfiguration( + std::make_optional("STEREO_ONE_CIS_PER_DEVICE"), + std::make_optional(AudioLocation::STEREO), std::nullopt, + std::make_optional(1))})); + + invalid_strategy_configuration_test_cases.push_back( + StrategyConfigurationList( + std::vector<StrategyConfiguration>{StrategyConfiguration( + std::make_optional("STEREO_ONE_CIS_PER_DEVICE"), + std::make_optional(AudioLocation::STEREO), + std::make_optional(2), std::nullopt)})); + + invalid_strategy_configuration_test_cases.push_back( + StrategyConfigurationList(std::vector<StrategyConfiguration>{})); + + return invalid_strategy_configuration_test_cases; + } +}; + +TEST_P(UpdateStrategyConfigurationsToMapTest, InvalidStrategyConfigurations) { + Initialize(); + auto le_audio_codec_capabilities = RunTestCase(); + ASSERT_TRUE(le_audio_codec_capabilities.empty()); +} + +class ComposeLeAudioCodecCapabilitiesTest + : public BluetoothLeAudioCodecsProviderTest { + public: +}; + +TEST_P(ComposeLeAudioCodecCapabilitiesTest, CodecCapabilitiesNotEmpty) { + Initialize(); + auto le_audio_codec_capabilities = RunTestCase(); + ASSERT_TRUE(!le_audio_codec_capabilities.empty()); +} + +GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GetScenariosTest); +INSTANTIATE_TEST_SUITE_P( + BluetoothLeAudioCodecsProviderTest, GetScenariosTest, + ::testing::ValuesIn(BluetoothLeAudioCodecsProviderTest::CreateTestCases( + GetScenariosTest::CreateInvalidScenarios(), kValidConfigurationList, + kValidCodecConfigurationList, kValidStrategyConfigurationList))); + +GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(UpdateConfigurationsToMapTest); +INSTANTIATE_TEST_SUITE_P( + BluetoothLeAudioCodecsProviderTest, UpdateConfigurationsToMapTest, + ::testing::ValuesIn(BluetoothLeAudioCodecsProviderTest::CreateTestCases( + kValidScenarioList, + UpdateConfigurationsToMapTest::CreateInvalidConfigurations(), + kValidCodecConfigurationList, kValidStrategyConfigurationList))); + +GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( + UpdateCodecConfigurationsToMapTest); +INSTANTIATE_TEST_SUITE_P( + BluetoothLeAudioCodecsProviderTest, UpdateCodecConfigurationsToMapTest, + ::testing::ValuesIn(BluetoothLeAudioCodecsProviderTest::CreateTestCases( + kValidScenarioList, kValidConfigurationList, + UpdateCodecConfigurationsToMapTest::CreateInvalidCodecConfigurations(), + kValidStrategyConfigurationList))); + +GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( + UpdateStrategyConfigurationsToMapTest); +INSTANTIATE_TEST_SUITE_P( + BluetoothLeAudioCodecsProviderTest, UpdateStrategyConfigurationsToMapTest, + ::testing::ValuesIn(BluetoothLeAudioCodecsProviderTest::CreateTestCases( + kValidScenarioList, kValidConfigurationList, + kValidCodecConfigurationList, + UpdateStrategyConfigurationsToMapTest:: + CreateInvalidStrategyConfigurations()))); + +GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST( + ComposeLeAudioCodecCapabilitiesTest); +INSTANTIATE_TEST_SUITE_P( + BluetoothLeAudioCodecsProviderTest, ComposeLeAudioCodecCapabilitiesTest, + ::testing::ValuesIn(BluetoothLeAudioCodecsProviderTest::CreateTestCases( + kValidScenarioList, kValidConfigurationList, + kValidCodecConfigurationList, kValidStrategyConfigurationList))); + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/bluetooth/audio/utils/le_audio_codec_capabilities/le_audio_codec_capabilities.xml b/bluetooth/audio/utils/le_audio_codec_capabilities/le_audio_codec_capabilities.xml new file mode 100644 index 0000000000..c7904b338c --- /dev/null +++ b/bluetooth/audio/utils/le_audio_codec_capabilities/le_audio_codec_capabilities.xml @@ -0,0 +1,61 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!--- + This is an example to configure LE Audio hardware offload supported capability settings + In the follow list, there would be only one list in this file. Add element into each list as needed. + + codecConfigurationList: + Supported codec capability along with its parameter setting + + strategyConfigurationList: + ASE Configuration strategies + + configurationList: + For each configuration , there are two attributes + - codecConfiguration + - strategyConfiguration + + scenarioList: + There would be only one `scenarios` group + For each scenario, the are two attributes + - encode + - decode + If a scenario is unidirectional, mark another direction as `invalid` + The configuration should be chosen from `configurationList` +--> +<leAudioOffloadSetting> + <scenarioList> + <!-- encode only --> + <scenario encode="OneChanMono_16_1" decode="invalid"/> + <scenario encode="TwoChanStereo_16_1" decode="invalid"/> + <scenario encode="OneChanStereo_16_1" decode="invalid"/> + <scenario encode="OneChanMono_16_2" decode="invalid"/> + <scenario encode="TwoChanStereo_16_2" decode="invalid"/> + <scenario encode="OneChanStereo_16_2" decode="invalid"/> + <!-- encode and decode --> + <scenario encode="OneChanStereo_16_1" decode="OneChanStereo_16_1"/> + <scenario encode="OneChanStereo_16_1" decode="OneChanMono_16_1"/> + <scenario encode="TwoChanStereo_16_1" decode="OneChanMono_16_1"/> + <scenario encode="OneChanMono_16_1" decode="OneChanMono_16_1"/> + <scenario encode="OneChanStereo_16_2" decode="OneChanStereo_16_2"/> + <scenario encode="OneChanStereo_16_2" decode="OneChanMono_16_2"/> + <scenario encode="TwoChanStereo_16_2" decode="OneChanMono_16_2"/> + <scenario encode="OneChanMono_16_2" decode="OneChanMono_16_2"/> + </scenarioList> + <configurationList> + <configuration name="OneChanMono_16_1" codecConfiguration="LC3_16k_1" strategyConfiguration="MONO_ONE_CIS_PER_DEVICE"/> + <configuration name="TwoChanStereo_16_1" codecConfiguration="LC3_16k_1" strategyConfiguration="STEREO_TWO_CISES_PER_DEVICE"/> + <configuration name="OneChanStereo_16_1" codecConfiguration="LC3_16k_1" strategyConfiguration="STEREO_ONE_CIS_PER_DEVICE"/> + <configuration name="OneChanMono_16_2" codecConfiguration="LC3_16k_2" strategyConfiguration="MONO_ONE_CIS_PER_DEVICE"/> + <configuration name="TwoChanStereo_16_2" codecConfiguration="LC3_16k_2" strategyConfiguration="STEREO_TWO_CISES_PER_DEVICE"/> + <configuration name="OneChanStereo_16_2" codecConfiguration="LC3_16k_2" strategyConfiguration="STEREO_ONE_CIS_PER_DEVICE"/> + </configurationList> + <codecConfigurationList> + <codecConfiguration name="LC3_16k_1" codec="LC3" samplingFrequency="16000" frameDurationUs="7500" octetsPerCodecFrame="30"/> + <codecConfiguration name="LC3_16k_2" codec="LC3" samplingFrequency="16000" frameDurationUs="10000" octetsPerCodecFrame="40"/> + </codecConfigurationList> + <strategyConfigurationList> + <strategyConfiguration name="STEREO_ONE_CIS_PER_DEVICE" audioLocation="STEREO" connectedDevice="2" channelCount="1"/> + <strategyConfiguration name="STEREO_TWO_CISES_PER_DEVICE" audioLocation="STEREO" connectedDevice="1" channelCount="2"/> + <strategyConfiguration name="MONO_ONE_CIS_PER_DEVICE" audioLocation="MONO" connectedDevice="1" channelCount="1"/> + </strategyConfigurationList> +</leAudioOffloadSetting> diff --git a/bluetooth/audio/utils/le_audio_codec_capabilities/le_audio_codec_capabilities.xsd b/bluetooth/audio/utils/le_audio_codec_capabilities/le_audio_codec_capabilities.xsd new file mode 100644 index 0000000000..213e5974da --- /dev/null +++ b/bluetooth/audio/utils/le_audio_codec_capabilities/le_audio_codec_capabilities.xsd @@ -0,0 +1,74 @@ +<!-- LE Audio Offload Codec Capability Schema --> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> + <xs:element name="leAudioOffloadSetting"> + <xs:complexType> + <xs:element ref="scenarioList" minOccurs="1" maxOccurs="1"/> + <xs:element ref="configurationList" minOccurs="1" maxOccurs="1"/> + <xs:element ref="codecConfigurationList" minOccurs="1" maxOccurs="1"/> + <xs:element ref="strategyConfigurationList" minOccurs="1" maxOccurs="1"/> + </xs:complexType> + </xs:element> + <xs:element name="scenarioList"> + <xs:complexType> + <xs:element ref="scenario" minOccurs="1" maxOccurs="unbounded"/> + </xs:complexType> + </xs:element> + <xs:element name="configurationList"> + <xs:complexType> + <xs:element ref="configuration" minOccurs="1" maxOccurs="unbounded"/> + </xs:complexType> + </xs:element> + <xs:element name="codecConfigurationList"> + <xs:complexType> + <xs:element ref="codecConfiguration" minOccurs="1" maxOccurs="unbounded"/> + </xs:complexType> + </xs:element> + <xs:element name="strategyConfigurationList"> + <xs:complexType> + <xs:element ref="strategyConfiguration" minOccurs="1" maxOccurs="unbounded"/> + </xs:complexType> + </xs:element> + <xs:element name="scenario"> + <xs:complexType> + <xs:attribute name="encode" type="xs:string"/> + <xs:attribute name="decode" type="xs:string"/> + </xs:complexType> + </xs:element> + <xs:element name="configuration"> + <xs:complexType> + <xs:attribute name="name" type="xs:string"/> + <xs:attribute name="codecConfiguration" type="xs:string"/> + <xs:attribute name="strategyConfiguration" type="xs:string"/> + </xs:complexType> + </xs:element> + <xs:element name="codecConfiguration"> + <xs:complexType> + <xs:attribute name="name" type="xs:string"/> + <xs:attribute name="codec" type="codecType"/> + <xs:attribute name="pcmBitDepth" type="xs:unsignedByte"/> + <xs:attribute name="samplingFrequency" type="xs:int"/> + <xs:attribute name="frameDurationUs" type="xs:int"/> + <xs:attribute name="octetsPerCodecFrame" type="xs:int"/> + <xs:attribute name="codecFrameBlocksPerSdu" type="xs:unsignedByte"/> + </xs:complexType> + </xs:element> + <xs:element name="strategyConfiguration"> + <xs:complexType> + <xs:attribute name="name" type="xs:string"/> + <xs:attribute name="audioLocation" type="audioLocation"/> + <xs:attribute name="connectedDevice" type="xs:unsignedByte"/> + <xs:attribute name="channelCount" type="xs:unsignedByte"/> + </xs:complexType> + </xs:element> + <xs:simpleType name="audioLocation"> + <xs:restriction base="xs:string"> + <xs:enumeration value="MONO"/> + <xs:enumeration value="STEREO"/> + </xs:restriction> + </xs:simpleType> + <xs:simpleType name="codecType"> + <xs:restriction base="xs:string"> + <xs:enumeration value="LC3"/> + </xs:restriction> + </xs:simpleType> +</xs:schema> diff --git a/bluetooth/audio/utils/le_audio_codec_capabilities/schema/current.txt b/bluetooth/audio/utils/le_audio_codec_capabilities/schema/current.txt new file mode 100644 index 0000000000..06aa21a7b3 --- /dev/null +++ b/bluetooth/audio/utils/le_audio_codec_capabilities/schema/current.txt @@ -0,0 +1,111 @@ +// Signature format: 2.0 +package aidl.android.hardware.bluetooth.audio.setting { + + public enum AudioLocation { + method public String getRawName(); + enum_constant public static final aidl.android.hardware.bluetooth.audio.setting.AudioLocation MONO; + enum_constant public static final aidl.android.hardware.bluetooth.audio.setting.AudioLocation STEREO; + } + + public class CodecConfiguration { + ctor public CodecConfiguration(); + method public aidl.android.hardware.bluetooth.audio.setting.CodecType getCodec(); + method public short getCodecFrameBlocksPerSdu(); + method public int getFrameDurationUs(); + method public String getName(); + method public int getOctetsPerCodecFrame(); + method public short getPcmBitDepth(); + method public int getSamplingFrequency(); + method public void setCodec(aidl.android.hardware.bluetooth.audio.setting.CodecType); + method public void setCodecFrameBlocksPerSdu(short); + method public void setFrameDurationUs(int); + method public void setName(String); + method public void setOctetsPerCodecFrame(int); + method public void setPcmBitDepth(short); + method public void setSamplingFrequency(int); + } + + public class CodecConfigurationList { + ctor public CodecConfigurationList(); + method public java.util.List<aidl.android.hardware.bluetooth.audio.setting.CodecConfiguration> getCodecConfiguration(); + } + + public enum CodecType { + method public String getRawName(); + enum_constant public static final aidl.android.hardware.bluetooth.audio.setting.CodecType LC3; + } + + public class Configuration { + ctor public Configuration(); + method public String getCodecConfiguration(); + method public String getName(); + method public String getStrategyConfiguration(); + method public void setCodecConfiguration(String); + method public void setName(String); + method public void setStrategyConfiguration(String); + } + + public class ConfigurationList { + ctor public ConfigurationList(); + method public java.util.List<aidl.android.hardware.bluetooth.audio.setting.Configuration> getConfiguration(); + } + + public class LeAudioOffloadSetting { + ctor public LeAudioOffloadSetting(); + method public aidl.android.hardware.bluetooth.audio.setting.CodecConfigurationList getCodecConfigurationList(); + method public aidl.android.hardware.bluetooth.audio.setting.ConfigurationList getConfigurationList(); + method public aidl.android.hardware.bluetooth.audio.setting.ScenarioList getScenarioList(); + method public aidl.android.hardware.bluetooth.audio.setting.StrategyConfigurationList getStrategyConfigurationList(); + method public void setCodecConfigurationList(aidl.android.hardware.bluetooth.audio.setting.CodecConfigurationList); + method public void setConfigurationList(aidl.android.hardware.bluetooth.audio.setting.ConfigurationList); + method public void setScenarioList(aidl.android.hardware.bluetooth.audio.setting.ScenarioList); + method public void setStrategyConfigurationList(aidl.android.hardware.bluetooth.audio.setting.StrategyConfigurationList); + } + + public class Scenario { + ctor public Scenario(); + method public String getDecode(); + method public String getEncode(); + method public void setDecode(String); + method public void setEncode(String); + } + + public class ScenarioList { + ctor public ScenarioList(); + method public java.util.List<aidl.android.hardware.bluetooth.audio.setting.Scenario> getScenario(); + } + + public class StrategyConfiguration { + ctor public StrategyConfiguration(); + method public aidl.android.hardware.bluetooth.audio.setting.AudioLocation getAudioLocation(); + method public short getChannelCount(); + method public short getConnectedDevice(); + method public String getName(); + method public void setAudioLocation(aidl.android.hardware.bluetooth.audio.setting.AudioLocation); + method public void setChannelCount(short); + method public void setConnectedDevice(short); + method public void setName(String); + } + + public class StrategyConfigurationList { + ctor public StrategyConfigurationList(); + method public java.util.List<aidl.android.hardware.bluetooth.audio.setting.StrategyConfiguration> getStrategyConfiguration(); + } + + public class XmlParser { + ctor public XmlParser(); + method public static aidl.android.hardware.bluetooth.audio.setting.CodecConfiguration readCodecConfiguration(java.io.InputStream) throws javax.xml.datatype.DatatypeConfigurationException, java.io.IOException, org.xmlpull.v1.XmlPullParserException; + method public static aidl.android.hardware.bluetooth.audio.setting.CodecConfigurationList readCodecConfigurationList(java.io.InputStream) throws javax.xml.datatype.DatatypeConfigurationException, java.io.IOException, org.xmlpull.v1.XmlPullParserException; + method public static aidl.android.hardware.bluetooth.audio.setting.Configuration readConfiguration(java.io.InputStream) throws javax.xml.datatype.DatatypeConfigurationException, java.io.IOException, org.xmlpull.v1.XmlPullParserException; + method public static aidl.android.hardware.bluetooth.audio.setting.ConfigurationList readConfigurationList(java.io.InputStream) throws javax.xml.datatype.DatatypeConfigurationException, java.io.IOException, org.xmlpull.v1.XmlPullParserException; + method public static aidl.android.hardware.bluetooth.audio.setting.LeAudioOffloadSetting readLeAudioOffloadSetting(java.io.InputStream) throws javax.xml.datatype.DatatypeConfigurationException, java.io.IOException, org.xmlpull.v1.XmlPullParserException; + method public static aidl.android.hardware.bluetooth.audio.setting.Scenario readScenario(java.io.InputStream) throws javax.xml.datatype.DatatypeConfigurationException, java.io.IOException, org.xmlpull.v1.XmlPullParserException; + method public static aidl.android.hardware.bluetooth.audio.setting.ScenarioList readScenarioList(java.io.InputStream) throws javax.xml.datatype.DatatypeConfigurationException, java.io.IOException, org.xmlpull.v1.XmlPullParserException; + method public static aidl.android.hardware.bluetooth.audio.setting.StrategyConfiguration readStrategyConfiguration(java.io.InputStream) throws javax.xml.datatype.DatatypeConfigurationException, java.io.IOException, org.xmlpull.v1.XmlPullParserException; + method public static aidl.android.hardware.bluetooth.audio.setting.StrategyConfigurationList readStrategyConfigurationList(java.io.InputStream) throws javax.xml.datatype.DatatypeConfigurationException, java.io.IOException, org.xmlpull.v1.XmlPullParserException; + method public static String readText(org.xmlpull.v1.XmlPullParser) throws java.io.IOException, org.xmlpull.v1.XmlPullParserException; + method public static void skip(org.xmlpull.v1.XmlPullParser) throws java.io.IOException, org.xmlpull.v1.XmlPullParserException; + } + +} + diff --git a/bluetooth/audio/utils/le_audio_codec_capabilities/schema/last_current.txt b/bluetooth/audio/utils/le_audio_codec_capabilities/schema/last_current.txt new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/bluetooth/audio/utils/le_audio_codec_capabilities/schema/last_current.txt diff --git a/bluetooth/audio/utils/le_audio_codec_capabilities/schema/last_removed.txt b/bluetooth/audio/utils/le_audio_codec_capabilities/schema/last_removed.txt new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/bluetooth/audio/utils/le_audio_codec_capabilities/schema/last_removed.txt diff --git a/bluetooth/audio/utils/le_audio_codec_capabilities/schema/removed.txt b/bluetooth/audio/utils/le_audio_codec_capabilities/schema/removed.txt new file mode 100644 index 0000000000..d802177e24 --- /dev/null +++ b/bluetooth/audio/utils/le_audio_codec_capabilities/schema/removed.txt @@ -0,0 +1 @@ +// Signature format: 2.0 diff --git a/camera/common/1.0/default/HandleImporter.cpp b/camera/common/1.0/default/HandleImporter.cpp index fbe8686766..d2fdf02457 100644 --- a/camera/common/1.0/default/HandleImporter.cpp +++ b/camera/common/1.0/default/HandleImporter.cpp @@ -18,6 +18,7 @@ #include "HandleImporter.h" #include <gralloctypes/Gralloc4.h> +#include "aidl/android/hardware/graphics/common/Smpte2086.h" #include <log/log.h> namespace android { @@ -30,6 +31,7 @@ namespace helper { using aidl::android::hardware::graphics::common::PlaneLayout; using aidl::android::hardware::graphics::common::PlaneLayoutComponent; using aidl::android::hardware::graphics::common::PlaneLayoutComponentType; +using aidl::android::hardware::graphics::common::Smpte2086; using MetadataType = android::hardware::graphics::mapper::V4_0::IMapper::MetadataType; using MapperErrorV2 = android::hardware::graphics::mapper::V2_0::Error; using MapperErrorV3 = android::hardware::graphics::mapper::V3_0::Error; @@ -127,16 +129,35 @@ YCbCrLayout HandleImporter::lockYCbCrInternal(const sp<M> mapper, buffer_handle_ bool isMetadataPesent(const sp<IMapperV4> mapper, const buffer_handle_t& buf, MetadataType metadataType) { auto buffer = const_cast<native_handle_t*>(buf); - mapper->get(buffer, metadataType, [] (const auto& tmpError, + bool ret = false; + hidl_vec<uint8_t> vec; + mapper->get(buffer, metadataType, [&] (const auto& tmpError, const auto& tmpMetadata) { if (tmpError == MapperErrorV4::NONE) { - return tmpMetadata.size() > 0; + vec = tmpMetadata; } else { ALOGE("%s: failed to get metadata %d!", __FUNCTION__, tmpError); - return false; }}); - return false; + if (vec.size() > 0) { + if (metadataType == gralloc4::MetadataType_Smpte2086){ + std::optional<Smpte2086> realSmpte2086; + gralloc4::decodeSmpte2086(vec, &realSmpte2086); + ret = realSmpte2086.has_value(); + } else if (metadataType == gralloc4::MetadataType_Smpte2094_10) { + std::optional<std::vector<uint8_t>> realSmpte2094_10; + gralloc4::decodeSmpte2094_10(vec, &realSmpte2094_10); + ret = realSmpte2094_10.has_value(); + } else if (metadataType == gralloc4::MetadataType_Smpte2094_40) { + std::optional<std::vector<uint8_t>> realSmpte2094_40; + gralloc4::decodeSmpte2094_40(vec, &realSmpte2094_40); + ret = realSmpte2094_40.has_value(); + } else { + ALOGE("%s: Unknown metadata type!", __FUNCTION__); + } + } + + return ret; } std::vector<PlaneLayout> getPlaneLayouts(const sp<IMapperV4> mapper, buffer_handle_t& buf) { diff --git a/camera/device/aidl/android/hardware/camera/device/ICameraDevice.aidl b/camera/device/aidl/android/hardware/camera/device/ICameraDevice.aidl index 57705bc621..f9400006c8 100644 --- a/camera/device/aidl/android/hardware/camera/device/ICameraDevice.aidl +++ b/camera/device/aidl/android/hardware/camera/device/ICameraDevice.aidl @@ -279,8 +279,10 @@ interface ICameraDevice { * with specified torchStrength if the torch is OFF. * * The torchStrength value must be within the valid range i.e. >=1 and - * <= FLASH_INFO_STRENGTH_MAXIMUM_LEVEL. Whenever the torch is turned OFF, - * the brightness level will reset to FLASH_INFO_STRENGTH_DEFAULT_LEVEL. + * <= FLASH_INFO_STRENGTH_MAXIMUM_LEVEL. The FLASH_INFO_STRENGTH_MAXIMUM_LEVEL must + * be set to a level which will not cause any burn out issues. Whenever + * the torch is turned OFF, the brightness level will reset to + * FLASH_INFO_STRENGTH_DEFAULT_LEVEL. * When the client calls setTorchMode(ON) after turnOnTorchWithStrengthLevel(N), * the flash unit will have brightness level equal to N. This level does not * represent the real brightness units. It is linear in nature i.e. flashlight diff --git a/camera/provider/aidl/vts/VtsAidlHalCameraProvider_TargetTest.cpp b/camera/provider/aidl/vts/VtsAidlHalCameraProvider_TargetTest.cpp index fe03732aff..70ab7a02b3 100644 --- a/camera/provider/aidl/vts/VtsAidlHalCameraProvider_TargetTest.cpp +++ b/camera/provider/aidl/vts/VtsAidlHalCameraProvider_TargetTest.cpp @@ -1739,6 +1739,10 @@ TEST_P(CameraAidlTest, processUltraHighResolutionRequest) { std::list<PixelFormat> pixelFormats = {PixelFormat::YCBCR_420_888, PixelFormat::RAW16}; for (PixelFormat format : pixelFormats) { + previewStream.usage = + static_cast<aidl::android::hardware::graphics::common::BufferUsage>( + GRALLOC1_CONSUMER_USAGE_CPU_READ); + previewStream.dataSpace = Dataspace::UNKNOWN; configureStreams(name, mProvider, format, &mSession, &previewStream, &halStreams, &supportsPartialResults, &partialResultCount, &useHalBufManager, &cb, 0, /*maxResolution*/ true); @@ -1843,7 +1847,6 @@ TEST_P(CameraAidlTest, processUltraHighResolutionRequest) { TEST_P(CameraAidlTest, process10BitDynamicRangeRequest) { std::vector<std::string> cameraDeviceNames = getCameraDeviceNames(mProvider); int64_t bufferId = 1; - int32_t frameNumber = 1; CameraMetadata settings; for (const auto& name : cameraDeviceNames) { @@ -1866,7 +1869,7 @@ TEST_P(CameraAidlTest, process10BitDynamicRangeRequest) { CameraMetadata req; android::hardware::camera::common::V1_0::helper::CameraMetadata defaultSettings; ndk::ScopedAStatus ret = - mSession->constructDefaultRequestSettings(RequestTemplate::STILL_CAPTURE, &req); + mSession->constructDefaultRequestSettings(RequestTemplate::PREVIEW, &req); ASSERT_TRUE(ret.isOk()); const camera_metadata_t* metadata = @@ -1896,6 +1899,10 @@ TEST_P(CameraAidlTest, process10BitDynamicRangeRequest) { Stream previewStream; std::shared_ptr<DeviceCb> cb; for (const auto& profile : profileList) { + previewStream.usage = + static_cast<aidl::android::hardware::graphics::common::BufferUsage>( + GRALLOC1_CONSUMER_USAGE_HWCOMPOSER); + previewStream.dataSpace = getDataspace(PixelFormat::IMPLEMENTATION_DEFINED); configureStreams(name, mProvider, PixelFormat::IMPLEMENTATION_DEFINED, &mSession, &previewStream, &halStreams, &supportsPartialResults, &partialResultCount, &useHalBufManager, &cb, 0, @@ -1916,63 +1923,75 @@ TEST_P(CameraAidlTest, process10BitDynamicRangeRequest) { // Don't use the queue onwards. } - std::vector<buffer_handle_t> graphicBuffers; - graphicBuffers.reserve(halStreams.size()); - - std::shared_ptr<InFlightRequest> inflightReq = std::make_shared<InFlightRequest>( - static_cast<ssize_t>(halStreams.size()), false, supportsPartialResults, - partialResultCount, std::unordered_set<std::string>(), resultQueue); - - std::vector<CaptureRequest> requests(1); - CaptureRequest& request = requests[0]; - std::vector<StreamBuffer>& outputBuffers = request.outputBuffers; - outputBuffers.resize(halStreams.size()); - - size_t k = 0; - for (const auto& halStream : halStreams) { - buffer_handle_t buffer_handle; - if (useHalBufManager) { - outputBuffers[k] = {halStream.id, 0, - NativeHandle(), BufferStatus::OK, - NativeHandle(), NativeHandle()}; - } else { - allocateGraphicBuffer(previewStream.width, previewStream.height, - android_convertGralloc1To0Usage( - static_cast<uint64_t>(halStream.producerUsage), - static_cast<uint64_t>(halStream.consumerUsage)), - halStream.overrideFormat, &buffer_handle); - - graphicBuffers.push_back(buffer_handle); - outputBuffers[k] = { - halStream.id, bufferId, android::makeToAidl(buffer_handle), - BufferStatus::OK, NativeHandle(), NativeHandle()}; - bufferId++; + mInflightMap.clear(); + // Stream as long as needed to fill the Hal inflight queue + std::vector<CaptureRequest> requests(halStreams[0].maxBuffers); + + for (int32_t frameNumber = 0; frameNumber < requests.size(); frameNumber++) { + std::shared_ptr<InFlightRequest> inflightReq = std::make_shared<InFlightRequest>( + static_cast<ssize_t>(halStreams.size()), false, supportsPartialResults, + partialResultCount, std::unordered_set<std::string>(), resultQueue); + + CaptureRequest& request = requests[frameNumber]; + std::vector<StreamBuffer>& outputBuffers = request.outputBuffers; + outputBuffers.resize(halStreams.size()); + + size_t k = 0; + inflightReq->mOutstandingBufferIds.resize(halStreams.size()); + std::vector<buffer_handle_t> graphicBuffers; + graphicBuffers.reserve(halStreams.size()); + + for (const auto& halStream : halStreams) { + buffer_handle_t buffer_handle; + if (useHalBufManager) { + outputBuffers[k] = {halStream.id, 0, + NativeHandle(), BufferStatus::OK, + NativeHandle(), NativeHandle()}; + } else { + auto usage = android_convertGralloc1To0Usage( + static_cast<uint64_t>(halStream.producerUsage), + static_cast<uint64_t>(halStream.consumerUsage)); + allocateGraphicBuffer(previewStream.width, previewStream.height, usage, + halStream.overrideFormat, &buffer_handle); + + inflightReq->mOutstandingBufferIds[halStream.id][bufferId] = buffer_handle; + graphicBuffers.push_back(buffer_handle); + outputBuffers[k] = {halStream.id, bufferId, + android::makeToAidl(buffer_handle), BufferStatus::OK, NativeHandle(), + NativeHandle()}; + bufferId++; + } + k++; } - k++; - } - request.inputBuffer = { - -1, 0, NativeHandle(), BufferStatus::ERROR, NativeHandle(), NativeHandle()}; - request.frameNumber = frameNumber; - request.fmqSettingsSize = 0; - request.settings = settings; - request.inputWidth = 0; - request.inputHeight = 0; + request.inputBuffer = { + -1, 0, NativeHandle(), BufferStatus::ERROR, NativeHandle(), NativeHandle()}; + request.frameNumber = frameNumber; + request.fmqSettingsSize = 0; + request.settings = settings; + request.inputWidth = 0; + request.inputHeight = 0; + + { + std::unique_lock<std::mutex> l(mLock); + mInflightMap[frameNumber] = inflightReq; + } - { - std::unique_lock<std::mutex> l(mLock); - mInflightMap.clear(); - mInflightMap[frameNumber] = inflightReq; } int32_t numRequestProcessed = 0; std::vector<BufferCache> cachesToRemove; ndk::ScopedAStatus returnStatus = - mSession->processCaptureRequest(requests, cachesToRemove, &numRequestProcessed); + mSession->processCaptureRequest(requests, cachesToRemove, &numRequestProcessed); ASSERT_TRUE(returnStatus.isOk()); - ASSERT_EQ(numRequestProcessed, 1u); + ASSERT_EQ(numRequestProcessed, requests.size()); - { + returnStatus = mSession->repeatingRequestEnd(requests.size() - 1, + std::vector<int32_t> {halStreams[0].id}); + ASSERT_TRUE(returnStatus.isOk()); + + for (int32_t frameNumber = 0; frameNumber < requests.size(); frameNumber++) { + const auto& inflightReq = mInflightMap[frameNumber]; std::unique_lock<std::mutex> l(mLock); while (!inflightReq->errorCodeValid && ((0 < inflightReq->numBuffersLeft) || (!inflightReq->haveResultMetadata))) { @@ -1985,6 +2004,7 @@ TEST_P(CameraAidlTest, process10BitDynamicRangeRequest) { ASSERT_NE(inflightReq->resultOutputBuffers.size(), 0u); verify10BitMetadata(mHandleImporter, *inflightReq, profile); } + if (useHalBufManager) { std::vector<int32_t> streamIds(halStreams.size()); for (size_t i = 0; i < streamIds.size(); i++) { diff --git a/camera/provider/aidl/vts/camera_aidl_test.cpp b/camera/provider/aidl/vts/camera_aidl_test.cpp index c11fc0cd2b..20f32bfe21 100644 --- a/camera/provider/aidl/vts/camera_aidl_test.cpp +++ b/camera/provider/aidl/vts/camera_aidl_test.cpp @@ -2639,8 +2639,20 @@ void CameraAidlTest::configureStreams(const std::string& name, outputStreams.clear(); Size maxSize; - auto rc = getMaxOutputSizeForFormat(staticMeta, format, &maxSize, maxResolution); - ASSERT_EQ(Status::OK, rc); + if (maxResolution) { + auto rc = getMaxOutputSizeForFormat(staticMeta, format, &maxSize, maxResolution); + ASSERT_EQ(Status::OK, rc); + } else { + AvailableStream previewThreshold = {kMaxPreviewWidth, kMaxPreviewHeight, + static_cast<int32_t>(format)}; + auto rc = getAvailableOutputStreams(staticMeta, outputStreams, &previewThreshold); + + ASSERT_EQ(Status::OK, rc); + ASSERT_FALSE(outputStreams.empty()); + maxSize.width = outputStreams[0].width; + maxSize.height = outputStreams[0].height; + } + std::vector<Stream> streams(1); streams[0] = {0, @@ -2648,9 +2660,8 @@ void CameraAidlTest::configureStreams(const std::string& name, maxSize.width, maxSize.height, format, - static_cast<::aidl::android::hardware::graphics::common::BufferUsage>( - GRALLOC1_CONSUMER_USAGE_CPU_READ), - Dataspace::UNKNOWN, + previewStream->usage, + previewStream->dataSpace, StreamRotation::ROTATION_0, "", 0, @@ -2736,7 +2747,8 @@ void CameraAidlTest::verify10BitMetadata( HandleImporter& importer, const InFlightRequest& request, aidl::android::hardware::camera::metadata::RequestAvailableDynamicRangeProfilesMap profile) { - for (const auto& b : request.resultOutputBuffers) { + for (auto b : request.resultOutputBuffers) { + importer.importBuffer(b.buffer.buffer); bool smpte2086Present = importer.isSmpte2086Present(b.buffer.buffer); bool smpte2094_10Present = importer.isSmpte2094_10Present(b.buffer.buffer); bool smpte2094_40Present = importer.isSmpte2094_40Present(b.buffer.buffer); @@ -2753,7 +2765,6 @@ void CameraAidlTest::verify10BitMetadata( ASSERT_FALSE(smpte2094_40Present); break; case ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_HDR10_PLUS: - ASSERT_FALSE(smpte2086Present); ASSERT_FALSE(smpte2094_10Present); ASSERT_TRUE(smpte2094_40Present); break; @@ -2774,6 +2785,7 @@ void CameraAidlTest::verify10BitMetadata( profile); ADD_FAILURE(); } + importer.freeBuffer(b.buffer.buffer); } } diff --git a/camera/provider/aidl/vts/camera_aidl_test.h b/camera/provider/aidl/vts/camera_aidl_test.h index ac4b2c9d0e..d828cee4a8 100644 --- a/camera/provider/aidl/vts/camera_aidl_test.h +++ b/camera/provider/aidl/vts/camera_aidl_test.h @@ -399,6 +399,10 @@ class CameraAidlTest : public ::testing::TestWithParam<std::string> { // Result metadata ::android::hardware::camera::common::V1_0::helper::CameraMetadata collectedResult; + // Inflight buffers + using OutstandingBuffers = std::unordered_map<uint64_t, buffer_handle_t>; + std::vector<OutstandingBuffers> mOutstandingBufferIds; + // A copy-able StreamBuffer using buffer_handle_t instead of AIDLs NativeHandle struct NativeStreamBuffer { int32_t streamId; diff --git a/camera/provider/aidl/vts/device_cb.cpp b/camera/provider/aidl/vts/device_cb.cpp index e5f2f1eae4..4698b4ae89 100644 --- a/camera/provider/aidl/vts/device_cb.cpp +++ b/camera/provider/aidl/vts/device_cb.cpp @@ -155,7 +155,7 @@ ScopedAStatus DeviceCb::requestStreamBuffers(const std::vector<BufferRequest>& b BufferStatus::OK, NativeHandle(), NativeHandle(), }; - mOutstandingBufferIds[idx][mNextBufferId++] = ::android::dupToAidl(handle); + mOutstandingBufferIds[idx][mNextBufferId++] = handle; } atLeastOneStreamOk = true; bufRets[i].streamId = stream.id; @@ -427,9 +427,13 @@ bool DeviceCb::processCaptureResultLocked( } CameraAidlTest::InFlightRequest::StreamBufferAndTimestamp streamBufferAndTimestamp; + auto outstandingBuffers = mUseHalBufManager ? mOutstandingBufferIds : + request->mOutstandingBufferIds; + auto outputBuffer = outstandingBuffers.empty() ? ::android::makeFromAidl(buffer.buffer) : + outstandingBuffers[buffer.streamId][buffer.bufferId]; streamBufferAndTimestamp.buffer = {buffer.streamId, buffer.bufferId, - ::android::makeFromAidl(buffer.buffer), + outputBuffer, buffer.status, ::android::makeFromAidl(buffer.acquireFence), ::android::makeFromAidl(buffer.releaseFence)}; diff --git a/camera/provider/aidl/vts/device_cb.h b/camera/provider/aidl/vts/device_cb.h index 82ca10ddcb..3ae7d10596 100644 --- a/camera/provider/aidl/vts/device_cb.h +++ b/camera/provider/aidl/vts/device_cb.h @@ -73,7 +73,7 @@ class DeviceCb : public BnCameraDeviceCallback { std::vector<Stream> mStreams; std::vector<HalStream> mHalStreams; int64_t mNextBufferId = 1; - using OutstandingBuffers = std::unordered_map<uint64_t, NativeHandle>; + using OutstandingBuffers = std::unordered_map<uint64_t, buffer_handle_t>; // size == mStreams.size(). Tracking each streams outstanding buffers std::vector<OutstandingBuffers> mOutstandingBufferIds; std::condition_variable mFlushedCondition; diff --git a/contexthub/aidl/default/ContextHub.cpp b/contexthub/aidl/default/ContextHub.cpp index 4c23cbc8bf..35e4650ef2 100644 --- a/contexthub/aidl/default/ContextHub.cpp +++ b/contexthub/aidl/default/ContextHub.cpp @@ -107,10 +107,9 @@ ScopedAStatus ContextHub::onHostEndpointConnected(const HostEndpointInfo& in_inf ScopedAStatus ContextHub::onHostEndpointDisconnected(char16_t in_hostEndpointId) { if (mConnectedHostEndpoints.count(in_hostEndpointId) > 0) { mConnectedHostEndpoints.erase(in_hostEndpointId); - return ndk::ScopedAStatus::ok(); - } else { - return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_ILLEGAL_ARGUMENT)); } + + return ndk::ScopedAStatus::ok(); } } // namespace contexthub diff --git a/dumpstate/aidl/Android.bp b/dumpstate/aidl/Android.bp index d9acc7a59c..b250d74aa0 100644 --- a/dumpstate/aidl/Android.bp +++ b/dumpstate/aidl/Android.bp @@ -31,7 +31,8 @@ aidl_interface { enabled: false, }, java: { - enabled: false, + enabled: true, + sdk_version: "module_current", }, ndk: { vndk: { diff --git a/gnss/aidl/default/Gnss.cpp b/gnss/aidl/default/Gnss.cpp index cf2c90d359..2d6490c832 100644 --- a/gnss/aidl/default/Gnss.cpp +++ b/gnss/aidl/default/Gnss.cpp @@ -68,7 +68,7 @@ ScopedAStatus Gnss::setCallback(const std::shared_ptr<IGnssCallback>& callback) IGnssCallback::GnssSystemInfo systemInfo = { .yearOfHw = 2022, - .name = "Google Mock GNSS Implementation AIDL v2", + .name = "Google, Cuttlefish, AIDL v2", }; status = sGnssCallback->gnssSetSystemInfoCb(systemInfo); if (!status.isOk()) { diff --git a/neuralnetworks/1.2/utils/src/BurstUtils.cpp b/neuralnetworks/1.2/utils/src/BurstUtils.cpp index b589c468ce..c4c096da2d 100644 --- a/neuralnetworks/1.2/utils/src/BurstUtils.cpp +++ b/neuralnetworks/1.2/utils/src/BurstUtils.cpp @@ -190,12 +190,13 @@ nn::Result<std::tuple<V1_0::Request, std::vector<int32_t>, V1_2::MeasureTiming>> size_t index = 0; // validate packet information - if (data.size() == 0 || data[index].getDiscriminator() != discriminator::packetInformation) { + if (index >= data.size() || + data.at(index).getDiscriminator() != discriminator::packetInformation) { return NN_ERROR() << "FMQ Request packet ill-formed"; } // unpackage packet information - const FmqRequestDatum::PacketInformation& packetInfo = data[index].packetInformation(); + const FmqRequestDatum::PacketInformation& packetInfo = data.at(index).packetInformation(); index++; const uint32_t packetSize = packetInfo.packetSize; const uint32_t numberOfInputOperands = packetInfo.numberOfInputOperands; @@ -212,13 +213,14 @@ nn::Result<std::tuple<V1_0::Request, std::vector<int32_t>, V1_2::MeasureTiming>> inputs.reserve(numberOfInputOperands); for (size_t operand = 0; operand < numberOfInputOperands; ++operand) { // validate input operand information - if (data[index].getDiscriminator() != discriminator::inputOperandInformation) { + if (index >= data.size() || + data.at(index).getDiscriminator() != discriminator::inputOperandInformation) { return NN_ERROR() << "FMQ Request packet ill-formed"; } // unpackage operand information const FmqRequestDatum::OperandInformation& operandInfo = - data[index].inputOperandInformation(); + data.at(index).inputOperandInformation(); index++; const bool hasNoValue = operandInfo.hasNoValue; const V1_0::DataLocation location = operandInfo.location; @@ -229,12 +231,13 @@ nn::Result<std::tuple<V1_0::Request, std::vector<int32_t>, V1_2::MeasureTiming>> dimensions.reserve(numberOfDimensions); for (size_t i = 0; i < numberOfDimensions; ++i) { // validate dimension - if (data[index].getDiscriminator() != discriminator::inputOperandDimensionValue) { + if (index >= data.size() || + data.at(index).getDiscriminator() != discriminator::inputOperandDimensionValue) { return NN_ERROR() << "FMQ Request packet ill-formed"; } // unpackage dimension - const uint32_t dimension = data[index].inputOperandDimensionValue(); + const uint32_t dimension = data.at(index).inputOperandDimensionValue(); index++; // store result @@ -251,13 +254,14 @@ nn::Result<std::tuple<V1_0::Request, std::vector<int32_t>, V1_2::MeasureTiming>> outputs.reserve(numberOfOutputOperands); for (size_t operand = 0; operand < numberOfOutputOperands; ++operand) { // validate output operand information - if (data[index].getDiscriminator() != discriminator::outputOperandInformation) { + if (index >= data.size() || + data.at(index).getDiscriminator() != discriminator::outputOperandInformation) { return NN_ERROR() << "FMQ Request packet ill-formed"; } // unpackage operand information const FmqRequestDatum::OperandInformation& operandInfo = - data[index].outputOperandInformation(); + data.at(index).outputOperandInformation(); index++; const bool hasNoValue = operandInfo.hasNoValue; const V1_0::DataLocation location = operandInfo.location; @@ -268,12 +272,13 @@ nn::Result<std::tuple<V1_0::Request, std::vector<int32_t>, V1_2::MeasureTiming>> dimensions.reserve(numberOfDimensions); for (size_t i = 0; i < numberOfDimensions; ++i) { // validate dimension - if (data[index].getDiscriminator() != discriminator::outputOperandDimensionValue) { + if (index >= data.size() || + data.at(index).getDiscriminator() != discriminator::outputOperandDimensionValue) { return NN_ERROR() << "FMQ Request packet ill-formed"; } // unpackage dimension - const uint32_t dimension = data[index].outputOperandDimensionValue(); + const uint32_t dimension = data.at(index).outputOperandDimensionValue(); index++; // store result @@ -290,12 +295,13 @@ nn::Result<std::tuple<V1_0::Request, std::vector<int32_t>, V1_2::MeasureTiming>> slots.reserve(numberOfPools); for (size_t pool = 0; pool < numberOfPools; ++pool) { // validate input operand information - if (data[index].getDiscriminator() != discriminator::poolIdentifier) { + if (index >= data.size() || + data.at(index).getDiscriminator() != discriminator::poolIdentifier) { return NN_ERROR() << "FMQ Request packet ill-formed"; } // unpackage operand information - const int32_t poolId = data[index].poolIdentifier(); + const int32_t poolId = data.at(index).poolIdentifier(); index++; // store result @@ -303,17 +309,17 @@ nn::Result<std::tuple<V1_0::Request, std::vector<int32_t>, V1_2::MeasureTiming>> } // validate measureTiming - if (data[index].getDiscriminator() != discriminator::measureTiming) { + if (index >= data.size() || data.at(index).getDiscriminator() != discriminator::measureTiming) { return NN_ERROR() << "FMQ Request packet ill-formed"; } // unpackage measureTiming - const V1_2::MeasureTiming measure = data[index].measureTiming(); + const V1_2::MeasureTiming measure = data.at(index).measureTiming(); index++; // validate packet information if (index != packetSize) { - return NN_ERROR() << "FMQ Result packet ill-formed"; + return NN_ERROR() << "FMQ Request packet ill-formed"; } // return request @@ -328,12 +334,13 @@ nn::Result<std::tuple<V1_0::ErrorStatus, std::vector<V1_2::OutputShape>, V1_2::T size_t index = 0; // validate packet information - if (data.size() == 0 || data[index].getDiscriminator() != discriminator::packetInformation) { + if (index >= data.size() || + data.at(index).getDiscriminator() != discriminator::packetInformation) { return NN_ERROR() << "FMQ Result packet ill-formed"; } // unpackage packet information - const FmqResultDatum::PacketInformation& packetInfo = data[index].packetInformation(); + const FmqResultDatum::PacketInformation& packetInfo = data.at(index).packetInformation(); index++; const uint32_t packetSize = packetInfo.packetSize; const V1_0::ErrorStatus errorStatus = packetInfo.errorStatus; @@ -349,12 +356,13 @@ nn::Result<std::tuple<V1_0::ErrorStatus, std::vector<V1_2::OutputShape>, V1_2::T outputShapes.reserve(numberOfOperands); for (size_t operand = 0; operand < numberOfOperands; ++operand) { // validate operand information - if (data[index].getDiscriminator() != discriminator::operandInformation) { + if (index >= data.size() || + data.at(index).getDiscriminator() != discriminator::operandInformation) { return NN_ERROR() << "FMQ Result packet ill-formed"; } // unpackage operand information - const FmqResultDatum::OperandInformation& operandInfo = data[index].operandInformation(); + const FmqResultDatum::OperandInformation& operandInfo = data.at(index).operandInformation(); index++; const bool isSufficient = operandInfo.isSufficient; const uint32_t numberOfDimensions = operandInfo.numberOfDimensions; @@ -364,12 +372,13 @@ nn::Result<std::tuple<V1_0::ErrorStatus, std::vector<V1_2::OutputShape>, V1_2::T dimensions.reserve(numberOfDimensions); for (size_t i = 0; i < numberOfDimensions; ++i) { // validate dimension - if (data[index].getDiscriminator() != discriminator::operandDimensionValue) { + if (index >= data.size() || + data.at(index).getDiscriminator() != discriminator::operandDimensionValue) { return NN_ERROR() << "FMQ Result packet ill-formed"; } // unpackage dimension - const uint32_t dimension = data[index].operandDimensionValue(); + const uint32_t dimension = data.at(index).operandDimensionValue(); index++; // store result @@ -381,12 +390,13 @@ nn::Result<std::tuple<V1_0::ErrorStatus, std::vector<V1_2::OutputShape>, V1_2::T } // validate execution timing - if (data[index].getDiscriminator() != discriminator::executionTiming) { + if (index >= data.size() || + data.at(index).getDiscriminator() != discriminator::executionTiming) { return NN_ERROR() << "FMQ Result packet ill-formed"; } // unpackage execution timing - const V1_2::Timing timing = data[index].executionTiming(); + const V1_2::Timing timing = data.at(index).executionTiming(); index++; // validate packet information diff --git a/sensors/aidl/vts/AndroidTest.xml b/sensors/aidl/vts/AndroidTest.xml new file mode 100644 index 0000000000..99caf28422 --- /dev/null +++ b/sensors/aidl/vts/AndroidTest.xml @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- 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. +--> +<configuration description="Runs VtsAidlHalSensorsTargetTest."> + <option name="test-suite-tag" value="apct" /> + <option name="test-suite-tag" value="apct-native" /> + + <target_preparer class="com.android.tradefed.targetprep.RootTargetPreparer"/> + <target_preparer class="com.android.tradefed.targetprep.StopServicesSetup"/> + + <target_preparer class="com.android.tradefed.targetprep.PushFilePreparer"> + <option name="cleanup" value="true" /> + <option name="push" value="VtsAidlHalSensorsTargetTest->/data/local/tmp/VtsAidlHalSensorsTargetTest" /> + </target_preparer> + + <test class="com.android.tradefed.testtype.GTest" > + <option name="native-test-timeout" value="900000" /> + <option name="runtime-hint" value="300000"/> + <option name="native-test-device-path" value="/data/local/tmp" /> + <option name="module-name" value="VtsAidlHalSensorsTargetTest" /> + </test> +</configuration> diff --git a/usb/gadget/1.1/default/UsbGadget.cpp b/usb/gadget/1.1/default/UsbGadget.cpp index 36d865dc2e..0d0b4032d4 100644 --- a/usb/gadget/1.1/default/UsbGadget.cpp +++ b/usb/gadget/1.1/default/UsbGadget.cpp @@ -46,6 +46,8 @@ void currentFunctionsAppliedCallback(bool functionsApplied, void* payload) { } Return<void> UsbGadget::getCurrentUsbFunctions(const sp<V1_0::IUsbGadgetCallback>& callback) { + if (!callback) return Void(); + Return<void> ret = callback->getCurrentUsbFunctionsCb( mCurrentUsbFunctions, mCurrentUsbFunctionsApplied ? Status::FUNCTIONS_APPLIED : Status::FUNCTIONS_NOT_APPLIED); diff --git a/usb/gadget/1.2/default/UsbGadget.cpp b/usb/gadget/1.2/default/UsbGadget.cpp index 8dd229e0fd..a59e983f69 100644 --- a/usb/gadget/1.2/default/UsbGadget.cpp +++ b/usb/gadget/1.2/default/UsbGadget.cpp @@ -46,6 +46,8 @@ void currentFunctionsAppliedCallback(bool functionsApplied, void* payload) { } Return<void> UsbGadget::getCurrentUsbFunctions(const sp<V1_0::IUsbGadgetCallback>& callback) { + if (!callback) return Void(); + Return<void> ret = callback->getCurrentUsbFunctionsCb( mCurrentUsbFunctions, mCurrentUsbFunctionsApplied ? Status::FUNCTIONS_APPLIED : Status::FUNCTIONS_NOT_APPLIED); diff --git a/vibrator/aidl/default/Vibrator.cpp b/vibrator/aidl/default/Vibrator.cpp index ddc6ee0d02..01602abffb 100644 --- a/vibrator/aidl/default/Vibrator.cpp +++ b/vibrator/aidl/default/Vibrator.cpp @@ -59,7 +59,10 @@ ndk::ScopedAStatus Vibrator::on(int32_t timeoutMs, const std::shared_ptr<IVibratorCallback>& callback) { LOG(VERBOSE) << "Vibrator on for timeoutMs: " << timeoutMs; if (callback != nullptr) { - std::thread([=] { + // Note that thread lambdas aren't using implicit capture [=], to avoid capturing "this", + // which may be asynchronously destructed. + // If "this" is needed, use [sharedThis = this->ref<Vibrator>()]. + std::thread([timeoutMs, callback] { LOG(VERBOSE) << "Starting on on another thread"; usleep(timeoutMs * 1000); LOG(VERBOSE) << "Notifying on complete"; @@ -87,7 +90,7 @@ ndk::ScopedAStatus Vibrator::perform(Effect effect, EffectStrength strength, constexpr size_t kEffectMillis = 100; if (callback != nullptr) { - std::thread([=] { + std::thread([callback] { LOG(VERBOSE) << "Starting perform on another thread"; usleep(kEffectMillis * 1000); LOG(VERBOSE) << "Notifying perform complete"; @@ -174,7 +177,8 @@ ndk::ScopedAStatus Vibrator::compose(const std::vector<CompositeEffect>& composi } } - std::thread([=] { + // The thread may theoretically outlive the vibrator, so take a proper reference to it. + std::thread([sharedThis = this->ref<Vibrator>(), composite, callback] { LOG(VERBOSE) << "Starting compose on another thread"; for (auto& e : composite) { @@ -185,7 +189,7 @@ ndk::ScopedAStatus Vibrator::compose(const std::vector<CompositeEffect>& composi << e.scale; int32_t durationMs; - getPrimitiveDuration(e.primitive, &durationMs); + sharedThis->getPrimitiveDuration(e.primitive, &durationMs); usleep(durationMs * 1000); } @@ -396,7 +400,7 @@ ndk::ScopedAStatus Vibrator::composePwle(const std::vector<PrimitivePwle> &compo } } - std::thread([=] { + std::thread([totalDuration, callback] { LOG(VERBOSE) << "Starting composePwle on another thread"; usleep(totalDuration * 1000); if (callback != nullptr) { diff --git a/vibrator/aidl/default/VibratorManager.cpp b/vibrator/aidl/default/VibratorManager.cpp index 7cf9e6a5d8..26edf5a805 100644 --- a/vibrator/aidl/default/VibratorManager.cpp +++ b/vibrator/aidl/default/VibratorManager.cpp @@ -66,7 +66,7 @@ ndk::ScopedAStatus VibratorManager::prepareSynced(const std::vector<int32_t>& vi ndk::ScopedAStatus VibratorManager::triggerSynced( const std::shared_ptr<IVibratorCallback>& callback) { LOG(INFO) << "Vibrator Manager trigger synced"; - std::thread([=] { + std::thread([callback] { if (callback != nullptr) { LOG(INFO) << "Notifying perform complete"; callback->onComplete(); diff --git a/vibrator/aidl/vts/VtsHalVibratorManagerTargetTest.cpp b/vibrator/aidl/vts/VtsHalVibratorManagerTargetTest.cpp index 44fa3be7ab..e8ed26ab69 100644 --- a/vibrator/aidl/vts/VtsHalVibratorManagerTargetTest.cpp +++ b/vibrator/aidl/vts/VtsHalVibratorManagerTargetTest.cpp @@ -96,6 +96,7 @@ TEST_P(VibratorAidl, ValidatePrepareSyncedExistingVibrators) { if (!(capabilities & IVibratorManager::CAP_SYNC)) return; if (vibratorIds.empty()) return; EXPECT_TRUE(manager->prepareSynced(vibratorIds).isOk()); + EXPECT_TRUE(manager->cancelSynced().isOk()); } TEST_P(VibratorAidl, PrepareSyncedEmptySetIsInvalid) { @@ -208,6 +209,7 @@ TEST_P(VibratorAidl, TriggerCallbackNotSupported) { EXPECT_TRUE(manager->prepareSynced(vibratorIds).isOk()); Status status = manager->triggerSynced(callback); EXPECT_TRUE(isUnknownOrUnsupported(status)) << status; + EXPECT_TRUE(manager->cancelSynced().isOk()); } } diff --git a/wifi/1.4/vts/functional/Android.bp b/wifi/1.4/vts/functional/Android.bp index f86869bf61..cac8c0b2f8 100644 --- a/wifi/1.4/vts/functional/Android.bp +++ b/wifi/1.4/vts/functional/Android.bp @@ -44,6 +44,27 @@ cc_test { ], } +cc_library_static { + name: "VtsHalWifiV1_4TargetTestUtil", + defaults: ["VtsHalTargetTestDefaults"], + srcs: [ + "wifi_hidl_test_utils_1_4.cpp", + ], + export_include_dirs: [ + ".", + ], + shared_libs: [ + "libnativehelper", + ], + static_libs: [ + "VtsHalWifiV1_0TargetTestUtil", + "android.hardware.wifi@1.0", + "android.hardware.wifi@1.3", + "android.hardware.wifi@1.4", + "libwifi-system-iface", + ], +} + // SoftAP-specific tests, similar to VtsHalWifiApV1_0TargetTest. cc_test { name: "VtsHalWifiApV1_4TargetTest", diff --git a/wifi/1.4/vts/functional/wifi_hidl_test_utils_1_4.cpp b/wifi/1.4/vts/functional/wifi_hidl_test_utils_1_4.cpp new file mode 100644 index 0000000000..02e8320954 --- /dev/null +++ b/wifi/1.4/vts/functional/wifi_hidl_test_utils_1_4.cpp @@ -0,0 +1,54 @@ +/* + * 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. + */ + +#include <VtsHalHidlTargetCallbackBase.h> +#include <android-base/logging.h> + +#undef NAN // NAN is defined in bionic/libc/include/math.h:38 + +#include <android/hardware/wifi/1.4/IWifi.h> +#include <android/hardware/wifi/1.4/IWifiApIface.h> +#include <android/hardware/wifi/1.4/IWifiChip.h> +#include <gtest/gtest.h> +#include <hidl/GtestPrinter.h> +#include <hidl/ServiceManagement.h> + +#include "wifi_hidl_call_util.h" +#include "wifi_hidl_test_utils.h" + +using ::android::sp; +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::wifi::V1_0::ChipModeId; +using ::android::hardware::wifi::V1_0::IfaceType; +using ::android::hardware::wifi::V1_4::IWifiApIface; +using ::android::hardware::wifi::V1_4::IWifiChip; + +sp<IWifiChip> getWifiChip_1_4(const std::string& instance_name) { + return IWifiChip::castFrom(getWifiChip(instance_name)); +} + +sp<IWifiApIface> getWifiApIface_1_4(const std::string& instance_name) { + LOG(INFO) << "getWifiApIface_1_4"; + ChipModeId mode_id; + sp<IWifiChip> wifi_chip_ = getWifiChip_1_4(instance_name); + configureChipToSupportIfaceType(wifi_chip_, IfaceType::AP, &mode_id); + const auto& status_and_iface = HIDL_INVOKE(wifi_chip_, createApIface); + LOG(INFO) << "getWifiApIface_1_4 done to status_and_iface"; + return IWifiApIface::castFrom(status_and_iface.second); +} diff --git a/wifi/1.4/vts/functional/wifi_hidl_test_utils_1_4.h b/wifi/1.4/vts/functional/wifi_hidl_test_utils_1_4.h new file mode 100644 index 0000000000..a2c58154a1 --- /dev/null +++ b/wifi/1.4/vts/functional/wifi_hidl_test_utils_1_4.h @@ -0,0 +1,33 @@ +/* + * 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 <android/hardware/wifi/1.4/IWifi.h> +#include <android/hardware/wifi/1.4/IWifiApIface.h> +#include <android/hardware/wifi/1.4/IWifiChip.h> + +#include <getopt.h> + +#include <VtsHalHidlTargetTestEnvBase.h> +// Helper functions to obtain references to the various HIDL interface objects. +// Note: We only have a single instance of each of these objects currently. +// These helper functions should be modified to return vectors if we support +// multiple instances. +android::sp<android::hardware::wifi::V1_4::IWifiChip> getWifiChip_1_4( + const std::string& instance_name); +android::sp<android::hardware::wifi::V1_4::IWifiApIface> getWifiApIface_1_4( + const std::string& instance_name); diff --git a/wifi/1.6/default/hidl_struct_util.cpp b/wifi/1.6/default/hidl_struct_util.cpp index ff3105dd77..9c4d881aad 100644 --- a/wifi/1.6/default/hidl_struct_util.cpp +++ b/wifi/1.6/default/hidl_struct_util.cpp @@ -156,10 +156,8 @@ bool convertLegacyFeaturesToHidlChipCapabilities(uint64_t legacy_feature_set, } } - // There are no flags for these 3 in the legacy feature set. Adding them to + // There is no flag for this in the legacy feature set. Adding this to // the set because all the current devices support it. - *hidl_caps |= HidlChipCaps::DEBUG_RING_BUFFER_VENDOR_DATA; - *hidl_caps |= HidlChipCaps::DEBUG_HOST_WAKE_REASON_STATS; *hidl_caps |= HidlChipCaps::DEBUG_ERROR_ALERTS; return true; } diff --git a/wifi/hostapd/1.2/vts/functional/Android.bp b/wifi/hostapd/1.2/vts/functional/Android.bp index 9609da5d41..26edab576b 100644 --- a/wifi/hostapd/1.2/vts/functional/Android.bp +++ b/wifi/hostapd/1.2/vts/functional/Android.bp @@ -31,12 +31,17 @@ cc_test { ], static_libs: [ "VtsHalWifiV1_0TargetTestUtil", + "VtsHalWifiV1_4TargetTestUtil", "VtsHalWifiHostapdV1_0TargetTestUtil", "android.hardware.wifi.hostapd@1.0", "android.hardware.wifi.hostapd@1.1", "android.hardware.wifi.hostapd@1.2", "android.hardware.wifi.hostapd@1.3", "android.hardware.wifi@1.0", + "android.hardware.wifi@1.1", + "android.hardware.wifi@1.2", + "android.hardware.wifi@1.3", + "android.hardware.wifi@1.4", "libgmock", "libwifi-system", "libwifi-system-iface", diff --git a/wifi/hostapd/1.2/vts/functional/hostapd_hidl_test.cpp b/wifi/hostapd/1.2/vts/functional/hostapd_hidl_test.cpp index c40c582406..2fade4dc6b 100644 --- a/wifi/hostapd/1.2/vts/functional/hostapd_hidl_test.cpp +++ b/wifi/hostapd/1.2/vts/functional/hostapd_hidl_test.cpp @@ -29,6 +29,7 @@ #include "hostapd_hidl_call_util.h" #include "hostapd_hidl_test_utils.h" +#include "wifi_hidl_test_utils_1_4.h" using ::android::sp; using ::android::hardware::hidl_string; @@ -39,6 +40,9 @@ using ::android::hardware::wifi::hostapd::V1_2::HostapdStatusCode; using ::android::hardware::wifi::hostapd::V1_2::Ieee80211ReasonCode; using ::android::hardware::wifi::hostapd::V1_2::IHostapd; using ::android::hardware::wifi::V1_0::IWifi; +using ::android::hardware::wifi::V1_0::WifiStatusCode; +using ::android::hardware::wifi::V1_4::IWifiApIface; +using ::android::hardware::wifi::V1_4::IWifiChip; namespace { constexpr unsigned char kNwSsid[] = {'t', 'e', 's', 't', '1', @@ -81,23 +85,25 @@ class HostapdHidlTest protected: bool isWpa3SaeSupport_ = false; bool isAcsSupport_ = false; - std::string getPrimaryWlanIfaceName() { - std::array<char, PROPERTY_VALUE_MAX> buffer; - auto res = property_get("ro.vendor.wifi.sap.interface", buffer.data(), - nullptr); - if (res > 0) return buffer.data(); - property_get("wifi.interface", buffer.data(), "wlan0"); - return buffer.data(); + + std::string setupApIfaceIfNeededAndGetName() { + sp<IWifiApIface> wifi_ap_iface; + wifi_ap_iface = getWifiApIface_1_4(wifi_instance_name_); + EXPECT_NE(nullptr, wifi_ap_iface.get()); + + const auto& status_and_name = HIDL_INVOKE(wifi_ap_iface, getName); + EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_name.first.code); + return status_and_name.second; } - IHostapd::IfaceParams getIfaceParamsWithoutAcs() { + IHostapd::IfaceParams getIfaceParamsWithoutAcs(std::string iface_name) { ::android::hardware::wifi::hostapd::V1_0::IHostapd::IfaceParams iface_params; ::android::hardware::wifi::hostapd::V1_1::IHostapd::IfaceParams iface_params_1_1; IHostapd::IfaceParams iface_params_1_2; - iface_params.ifaceName = getPrimaryWlanIfaceName(); + iface_params.ifaceName = iface_name; iface_params.hwModeParams.enable80211N = true; iface_params.hwModeParams.enable80211AC = false; iface_params.channelParams.enableAcs = false; @@ -114,9 +120,9 @@ class HostapdHidlTest return iface_params_1_2; } - IHostapd::IfaceParams getIfaceParamsWithAcs() { + IHostapd::IfaceParams getIfaceParamsWithAcs(std::string iface_name) { // First get the settings for WithoutAcs and then make changes - IHostapd::IfaceParams iface_params_1_2 = getIfaceParamsWithoutAcs(); + IHostapd::IfaceParams iface_params_1_2 = getIfaceParamsWithoutAcs(iface_name); iface_params_1_2.V1_1.V1_0.channelParams.enableAcs = true; iface_params_1_2.V1_1.V1_0.channelParams.acsShouldExcludeDfs = true; iface_params_1_2.V1_1.V1_0.channelParams.channel = 0; @@ -126,8 +132,8 @@ class HostapdHidlTest return iface_params_1_2; } - IHostapd::IfaceParams getIfaceParamsWithAcsAndFreqRange() { - IHostapd::IfaceParams iface_params_1_2 = getIfaceParamsWithAcs(); + IHostapd::IfaceParams getIfaceParamsWithAcsAndFreqRange(std::string iface_name) { + IHostapd::IfaceParams iface_params_1_2 = getIfaceParamsWithAcs(iface_name); ::android::hardware::wifi::hostapd::V1_2::IHostapd::AcsFrequencyRange acsFrequencyRange; acsFrequencyRange.start = 2412; @@ -141,9 +147,8 @@ class HostapdHidlTest return iface_params_1_2; } - IHostapd::IfaceParams getIfaceParamsWithAcsAndInvalidFreqRange() { - IHostapd::IfaceParams iface_params_1_2 = - getIfaceParamsWithAcsAndFreqRange(); + IHostapd::IfaceParams getIfaceParamsWithAcsAndInvalidFreqRange(std::string iface_name) { + IHostapd::IfaceParams iface_params_1_2 = getIfaceParamsWithAcsAndFreqRange(iface_name); iface_params_1_2.channelParams.acsChannelFreqRangesMhz[0].start = 222; iface_params_1_2.channelParams.acsChannelFreqRangesMhz[0].end = 999; return iface_params_1_2; @@ -205,8 +210,8 @@ class HostapdHidlTest return nw_params_1_2; } - IHostapd::IfaceParams getIfaceParamsWithInvalidChannel() { - IHostapd::IfaceParams iface_params_1_2 = getIfaceParamsWithoutAcs(); + IHostapd::IfaceParams getIfaceParamsWithInvalidChannel(std::string iface_name) { + IHostapd::IfaceParams iface_params_1_2 = getIfaceParamsWithoutAcs(iface_name); iface_params_1_2.V1_1.V1_0.channelParams.channel = kIfaceInvalidChannel; return iface_params_1_2; } @@ -231,8 +236,9 @@ TEST_P(HostapdHidlTest, AddPskAccessPointWithAcs) { if (!isAcsSupport_) GTEST_SKIP() << "Missing ACS support"; if (is_1_3(hostapd_)) GTEST_SKIP() << "Ignore addAccessPoint_1_2 on hostapd 1_3"; - auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_2, - getIfaceParamsWithAcs(), getPskNwParams()); + std::string ifname = setupApIfaceIfNeededAndGetName(); + auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_2, getIfaceParamsWithAcs(ifname), + getPskNwParams()); EXPECT_EQ(HostapdStatusCode::SUCCESS, status.code); } @@ -244,9 +250,9 @@ TEST_P(HostapdHidlTest, AddPskAccessPointWithAcsAndFreqRange) { if (!isAcsSupport_) GTEST_SKIP() << "Missing ACS support"; if (is_1_3(hostapd_)) GTEST_SKIP() << "Ignore addAccessPoint_1_2 on hostapd 1_3"; - auto status = - HIDL_INVOKE(hostapd_, addAccessPoint_1_2, - getIfaceParamsWithAcsAndFreqRange(), getPskNwParams()); + std::string ifname = setupApIfaceIfNeededAndGetName(); + auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_2, + getIfaceParamsWithAcsAndFreqRange(ifname), getPskNwParams()); EXPECT_EQ(HostapdStatusCode::SUCCESS, status.code); } @@ -258,9 +264,9 @@ TEST_P(HostapdHidlTest, AddPskAccessPointWithAcsAndInvalidFreqRange) { if (!isAcsSupport_) GTEST_SKIP() << "Missing ACS support"; if (is_1_3(hostapd_)) GTEST_SKIP() << "Ignore addAccessPoint_1_2 on hostapd 1_3"; + std::string ifname = setupApIfaceIfNeededAndGetName(); auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_2, - getIfaceParamsWithAcsAndInvalidFreqRange(), - getPskNwParams()); + getIfaceParamsWithAcsAndInvalidFreqRange(ifname), getPskNwParams()); EXPECT_NE(HostapdStatusCode::SUCCESS, status.code); } @@ -272,8 +278,9 @@ TEST_P(HostapdHidlTest, AddOpenAccessPointWithAcs) { if (!isAcsSupport_) GTEST_SKIP() << "Missing ACS support"; if (is_1_3(hostapd_)) GTEST_SKIP() << "Ignore addAccessPoint_1_2 on hostapd 1_3"; - auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_2, - getIfaceParamsWithAcs(), getOpenNwParams()); + std::string ifname = setupApIfaceIfNeededAndGetName(); + auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_2, getIfaceParamsWithAcs(ifname), + getOpenNwParams()); EXPECT_EQ(HostapdStatusCode::SUCCESS, status.code); } @@ -284,8 +291,9 @@ TEST_P(HostapdHidlTest, AddOpenAccessPointWithAcs) { TEST_P(HostapdHidlTest, AddPskAccessPointWithoutAcs) { if (is_1_3(hostapd_)) GTEST_SKIP() << "Ignore addAccessPoint_1_2 on hostapd 1_3"; - auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_2, - getIfaceParamsWithoutAcs(), getPskNwParams()); + std::string ifname = setupApIfaceIfNeededAndGetName(); + auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_2, getIfaceParamsWithoutAcs(ifname), + getPskNwParams()); EXPECT_EQ(HostapdStatusCode::SUCCESS, status.code); } @@ -296,8 +304,9 @@ TEST_P(HostapdHidlTest, AddPskAccessPointWithoutAcs) { TEST_P(HostapdHidlTest, AddOpenAccessPointWithoutAcs) { if (is_1_3(hostapd_)) GTEST_SKIP() << "Ignore addAccessPoint_1_2 on hostapd 1_3"; - auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_2, - getIfaceParamsWithoutAcs(), getOpenNwParams()); + std::string ifname = setupApIfaceIfNeededAndGetName(); + auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_2, getIfaceParamsWithoutAcs(ifname), + getOpenNwParams()); EXPECT_EQ(HostapdStatusCode::SUCCESS, status.code); } @@ -309,9 +318,9 @@ TEST_P(HostapdHidlTest, AddSaeTransitionAccessPointWithoutAcs) { if (!isWpa3SaeSupport_) GTEST_SKIP() << "Missing SAE support"; if (is_1_3(hostapd_)) GTEST_SKIP() << "Ignore addAccessPoint_1_2 on hostapd 1_3"; - auto status = - HIDL_INVOKE(hostapd_, addAccessPoint_1_2, getIfaceParamsWithoutAcs(), - getSaeTransitionNwParams()); + std::string ifname = setupApIfaceIfNeededAndGetName(); + auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_2, getIfaceParamsWithoutAcs(ifname), + getSaeTransitionNwParams()); EXPECT_EQ(HostapdStatusCode::SUCCESS, status.code); } @@ -323,8 +332,9 @@ TEST_P(HostapdHidlTest, AddSAEAccessPointWithoutAcs) { if (!isWpa3SaeSupport_) GTEST_SKIP() << "Missing SAE support"; if (is_1_3(hostapd_)) GTEST_SKIP() << "Ignore addAccessPoint_1_2 on hostapd 1_3"; - auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_2, - getIfaceParamsWithoutAcs(), getSaeNwParams()); + std::string ifname = setupApIfaceIfNeededAndGetName(); + auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_2, getIfaceParamsWithoutAcs(ifname), + getSaeNwParams()); EXPECT_EQ(HostapdStatusCode::SUCCESS, status.code); } @@ -336,11 +346,11 @@ TEST_P(HostapdHidlTest, RemoveAccessPointWithAcs) { if (!isAcsSupport_) GTEST_SKIP() << "Missing ACS support"; if (is_1_3(hostapd_)) GTEST_SKIP() << "Ignore addAccessPoint_1_2 on hostapd 1_3"; - auto status_1_2 = HIDL_INVOKE(hostapd_, addAccessPoint_1_2, - getIfaceParamsWithAcs(), getPskNwParams()); + std::string ifname = setupApIfaceIfNeededAndGetName(); + auto status_1_2 = HIDL_INVOKE(hostapd_, addAccessPoint_1_2, getIfaceParamsWithAcs(ifname), + getPskNwParams()); EXPECT_EQ(HostapdStatusCode::SUCCESS, status_1_2.code); - auto status = - HIDL_INVOKE(hostapd_, removeAccessPoint, getPrimaryWlanIfaceName()); + auto status = HIDL_INVOKE(hostapd_, removeAccessPoint, ifname); EXPECT_EQ( android::hardware::wifi::hostapd::V1_0::HostapdStatusCode::SUCCESS, status.code); @@ -353,11 +363,11 @@ TEST_P(HostapdHidlTest, RemoveAccessPointWithAcs) { TEST_P(HostapdHidlTest, RemoveAccessPointWithoutAcs) { if (is_1_3(hostapd_)) GTEST_SKIP() << "Ignore addAccessPoint_1_2 on hostapd 1_3"; - auto status_1_2 = HIDL_INVOKE(hostapd_, addAccessPoint_1_2, - getIfaceParamsWithoutAcs(), getPskNwParams()); + std::string ifname = setupApIfaceIfNeededAndGetName(); + auto status_1_2 = HIDL_INVOKE(hostapd_, addAccessPoint_1_2, getIfaceParamsWithoutAcs(ifname), + getPskNwParams()); EXPECT_EQ(HostapdStatusCode::SUCCESS, status_1_2.code); - auto status = - HIDL_INVOKE(hostapd_, removeAccessPoint, getPrimaryWlanIfaceName()); + auto status = HIDL_INVOKE(hostapd_, removeAccessPoint, ifname); EXPECT_EQ( android::hardware::wifi::hostapd::V1_0::HostapdStatusCode::SUCCESS, status.code); @@ -370,9 +380,9 @@ TEST_P(HostapdHidlTest, RemoveAccessPointWithoutAcs) { TEST_P(HostapdHidlTest, AddPskAccessPointWithInvalidChannel) { if (is_1_3(hostapd_)) GTEST_SKIP() << "Ignore addAccessPoint_1_2 on hostapd 1_3"; - auto status = - HIDL_INVOKE(hostapd_, addAccessPoint_1_2, - getIfaceParamsWithInvalidChannel(), getPskNwParams()); + std::string ifname = setupApIfaceIfNeededAndGetName(); + auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_2, + getIfaceParamsWithInvalidChannel(ifname), getPskNwParams()); EXPECT_NE(HostapdStatusCode::SUCCESS, status.code); } @@ -383,9 +393,9 @@ TEST_P(HostapdHidlTest, AddPskAccessPointWithInvalidChannel) { TEST_P(HostapdHidlTest, AddInvalidPskAccessPointWithoutAcs) { if (is_1_3(hostapd_)) GTEST_SKIP() << "Ignore addAccessPoint_1_2 on hostapd 1_3"; - auto status = - HIDL_INVOKE(hostapd_, addAccessPoint_1_2, getIfaceParamsWithoutAcs(), - getInvalidPskNwParams()); + std::string ifname = setupApIfaceIfNeededAndGetName(); + auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_2, getIfaceParamsWithoutAcs(ifname), + getInvalidPskNwParams()); EXPECT_NE(HostapdStatusCode::SUCCESS, status.code); } @@ -397,9 +407,9 @@ TEST_P(HostapdHidlTest, AddInvalidSaeTransitionAccessPointWithoutAcs) { if (!isWpa3SaeSupport_) GTEST_SKIP() << "Missing SAE support"; if (is_1_3(hostapd_)) GTEST_SKIP() << "Ignore addAccessPoint_1_2 on hostapd 1_3"; - auto status = - HIDL_INVOKE(hostapd_, addAccessPoint_1_2, getIfaceParamsWithoutAcs(), - getInvalidSaeTransitionNwParams()); + std::string ifname = setupApIfaceIfNeededAndGetName(); + auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_2, getIfaceParamsWithoutAcs(ifname), + getInvalidSaeTransitionNwParams()); EXPECT_NE(HostapdStatusCode::SUCCESS, status.code); } @@ -411,9 +421,9 @@ TEST_P(HostapdHidlTest, AddInvalidSaeAccessPointWithoutAcs) { if (!isWpa3SaeSupport_) GTEST_SKIP() << "Missing SAE support"; if (is_1_3(hostapd_)) GTEST_SKIP() << "Ignore addAccessPoint_1_2 on hostapd 1_3"; - auto status = - HIDL_INVOKE(hostapd_, addAccessPoint_1_2, getIfaceParamsWithoutAcs(), - getInvalidSaeNwParams()); + std::string ifname = setupApIfaceIfNeededAndGetName(); + auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_2, getIfaceParamsWithoutAcs(ifname), + getInvalidSaeNwParams()); EXPECT_NE(HostapdStatusCode::SUCCESS, status.code); } @@ -422,9 +432,9 @@ TEST_P(HostapdHidlTest, AddInvalidSaeAccessPointWithoutAcs) { * when hotspot interface doesn't init.. */ TEST_P(HostapdHidlTest, DisconnectClientWhenIfaceNotAvailable) { - auto status = - HIDL_INVOKE(hostapd_, forceClientDisconnect, getPrimaryWlanIfaceName(), - kTestZeroMacAddr, kTestDisconnectReasonCode); + std::string ifname = setupApIfaceIfNeededAndGetName(); + auto status = HIDL_INVOKE(hostapd_, forceClientDisconnect, ifname, kTestZeroMacAddr, + kTestDisconnectReasonCode); EXPECT_EQ(HostapdStatusCode::FAILURE_IFACE_UNKNOWN, status.code); } @@ -435,14 +445,13 @@ TEST_P(HostapdHidlTest, DisconnectClientWhenIfaceNotAvailable) { TEST_P(HostapdHidlTest, DisconnectClientWhenIfacAvailable) { if (is_1_3(hostapd_)) GTEST_SKIP() << "Ignore addAccessPoint_1_2 on hostapd 1_3"; - auto status_1_2 = - HIDL_INVOKE(hostapd_, addAccessPoint_1_2, getIfaceParamsWithoutAcs(), - getOpenNwParams()); + std::string ifname = setupApIfaceIfNeededAndGetName(); + auto status_1_2 = HIDL_INVOKE(hostapd_, addAccessPoint_1_2, getIfaceParamsWithoutAcs(ifname), + getOpenNwParams()); EXPECT_EQ(HostapdStatusCode::SUCCESS, status_1_2.code); - status_1_2 = - HIDL_INVOKE(hostapd_, forceClientDisconnect, getPrimaryWlanIfaceName(), - kTestZeroMacAddr, kTestDisconnectReasonCode); + status_1_2 = HIDL_INVOKE(hostapd_, forceClientDisconnect, ifname, kTestZeroMacAddr, + kTestDisconnectReasonCode); EXPECT_EQ(HostapdStatusCode::FAILURE_CLIENT_UNKNOWN, status_1_2.code); } diff --git a/wifi/supplicant/1.0/vts/functional/supplicant_hidl_test.cpp b/wifi/supplicant/1.0/vts/functional/supplicant_hidl_test.cpp index eabbf1b141..da3ff3a29b 100644 --- a/wifi/supplicant/1.0/vts/functional/supplicant_hidl_test.cpp +++ b/wifi/supplicant/1.0/vts/functional/supplicant_hidl_test.cpp @@ -38,11 +38,12 @@ class SupplicantHidlTest : public ::testing::TestWithParam<std::tuple<std::string, std::string>> { public: virtual void SetUp() override { - // Stop Wi-Fi - ASSERT_TRUE(stopWifiFramework()); // stop & wait for wifi to shutdown. - wifi_instance_name_ = std::get<0>(GetParam()); supplicant_instance_name_ = std::get<1>(GetParam()); + + // Stop & wait for wifi to shutdown. + ASSERT_TRUE(stopWifiFramework(wifi_instance_name_)); + std::system("/system/bin/start"); ASSERT_TRUE(waitForFrameworkReady()); isP2pOn_ = diff --git a/wifi/supplicant/1.0/vts/functional/supplicant_hidl_test_utils.cpp b/wifi/supplicant/1.0/vts/functional/supplicant_hidl_test_utils.cpp index 086166a5de..6760663d77 100644 --- a/wifi/supplicant/1.0/vts/functional/supplicant_hidl_test_utils.cpp +++ b/wifi/supplicant/1.0/vts/functional/supplicant_hidl_test_utils.cpp @@ -28,26 +28,42 @@ using ::android::sp; using ::android::hardware::configureRpcThreadpool; -using ::android::hardware::joinRpcThreadpool; using ::android::hardware::hidl_string; using ::android::hardware::hidl_vec; +using ::android::hardware::joinRpcThreadpool; using ::android::hardware::Return; using ::android::hardware::Void; -using ::android::hardware::wifi::V1_0::ChipModeId; -using ::android::hardware::wifi::V1_0::IWifiChip; +using ::android::hardware::wifi::supplicant::V1_0::IfaceType; using ::android::hardware::wifi::supplicant::V1_0::ISupplicant; using ::android::hardware::wifi::supplicant::V1_0::ISupplicantIface; using ::android::hardware::wifi::supplicant::V1_0::ISupplicantNetwork; +using ::android::hardware::wifi::supplicant::V1_0::ISupplicantP2pIface; using ::android::hardware::wifi::supplicant::V1_0::ISupplicantStaIface; using ::android::hardware::wifi::supplicant::V1_0::ISupplicantStaNetwork; -using ::android::hardware::wifi::supplicant::V1_0::ISupplicantP2pIface; -using ::android::hardware::wifi::supplicant::V1_0::IfaceType; using ::android::hardware::wifi::supplicant::V1_0::SupplicantStatus; using ::android::hardware::wifi::supplicant::V1_0::SupplicantStatusCode; +using ::android::hardware::wifi::V1_0::ChipModeId; +using ::android::hardware::wifi::V1_0::IWifi; +using ::android::hardware::wifi::V1_0::IWifiChip; using ::android::wifi_system::InterfaceTool; using ::android::wifi_system::SupplicantManager; namespace { + +bool waitForWifiHalStop(const std::string& wifi_instance_name) { + sp<IWifi> wifi = getWifi(wifi_instance_name); + int count = 50; /* wait at most 5 seconds for completion */ + while (count-- > 0) { + if (wifi != nullptr && !wifi->isStarted()) { + return true; + } + usleep(100000); + wifi = getWifi(wifi_instance_name); + } + LOG(ERROR) << "Wifi HAL was not stopped"; + return false; +} + bool waitForSupplicantState(bool is_running) { SupplicantManager supplicant_manager; int count = 50; /* wait at most 5 seconds for completion */ @@ -113,10 +129,10 @@ bool startWifiFramework() { return waitForSupplicantStart(); // wait for wifi to start. } -bool stopWifiFramework() { +bool stopWifiFramework(const std::string& wifi_instance_name) { std::system("svc wifi disable"); std::system("cmd wifi set-scan-always-available disabled"); - return waitForSupplicantStop(); // wait for wifi to shutdown. + return waitForSupplicantStop() && waitForWifiHalStop(wifi_instance_name); } void stopSupplicant() { stopSupplicant(""); } diff --git a/wifi/supplicant/1.0/vts/functional/supplicant_hidl_test_utils.h b/wifi/supplicant/1.0/vts/functional/supplicant_hidl_test_utils.h index 72286231b4..2198d7cbf8 100644 --- a/wifi/supplicant/1.0/vts/functional/supplicant_hidl_test_utils.h +++ b/wifi/supplicant/1.0/vts/functional/supplicant_hidl_test_utils.h @@ -33,7 +33,7 @@ bool startWifiFramework(); // Used to stop the android wifi framework before every test. -bool stopWifiFramework(); +bool stopWifiFramework(const std::string& wifi_instance_name); void stopSupplicant(const std::string& wifi_instance_name); // Used to configure the chip, driver and start wpa_supplicant before every @@ -77,12 +77,13 @@ class SupplicantHidlTestBase : public ::testing::TestWithParam<std::tuple<std::string, std::string>> { public: virtual void SetUp() override { - // Stop Wi-Fi - ASSERT_TRUE(stopWifiFramework()); // stop & wait for wifi to shutdown. - - // should always be v1.0 wifi - wifi_v1_0_instance_name_ = std::get<0>(GetParam()); + wifi_v1_0_instance_name_ = + std::get<0>(GetParam()); // should always be v1.0 wifi supplicant_instance_name_ = std::get<1>(GetParam()); + + // Stop & wait for wifi to shutdown. + ASSERT_TRUE(stopWifiFramework(wifi_v1_0_instance_name_)); + std::system("/system/bin/start"); ASSERT_TRUE(waitForFrameworkReady()); isP2pOn_ = diff --git a/wifi/supplicant/aidl/vts/functional/supplicant_test_utils.h b/wifi/supplicant/aidl/vts/functional/supplicant_test_utils.h index 17e0394892..31042a2b7c 100644 --- a/wifi/supplicant/aidl/vts/functional/supplicant_test_utils.h +++ b/wifi/supplicant/aidl/vts/functional/supplicant_test_utils.h @@ -78,7 +78,7 @@ void startSupplicant() { void stopSupplicantService() { stopSupplicant(getWifiInstanceName()); } void initializeService() { - ASSERT_TRUE(stopWifiFramework()); + ASSERT_TRUE(stopWifiFramework(getWifiInstanceName())); std::system("/system/bin/start"); ASSERT_TRUE(waitForFrameworkReady()); stopSupplicantService(); |