diff options
47 files changed, 2637 insertions, 247 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/effect/all-versions/default/Effect.cpp b/audio/effect/all-versions/default/Effect.cpp index 3baafc9343..5aecd324eb 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 \ @@ -238,12 +395,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 +428,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 +473,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 +491,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 +512,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), @@ -375,6 +560,15 @@ Return<void> Effect::prepareForProcessing(prepareForProcessing_cb _hidl_cb) { return Void(); } + // For a spatializer effect, we perform scheduler adjustments to reduce glitches and power. + // We do it here instead of the ProcessThread::threadLoop to ensure that mHandle is valid. + if (effect_descriptor_t halDescriptor{}; + (*mHandle)->get_descriptor(mHandle, &halDescriptor) == NO_ERROR && + memcmp(&halDescriptor.type, FX_IID_SPATIALIZER, sizeof(effect_uuid_t)) == 0) { + const status_t status = scheduler::updateSpatializerPriority(mProcessThread->getTid()); + ALOGW_IF(status != OK, "Failed to update Spatializer priority"); + } + mStatusMQ = std::move(tempStatusMQ); _hidl_cb(Result::OK, *mStatusMQ->getDesc()); return Void(); @@ -472,8 +666,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 +866,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..f023fd2063 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, @@ -159,7 +167,15 @@ const std::vector<ConfigDeclaration> kVehicleProperties = { .maxSampleRate = 10.0f, }, .initialValue = {.floatValues = {0.0f}}}, - + {.config = + { + .prop = toInt(VehicleProperty::PERF_VEHICLE_SPEED_DISPLAY), + .access = VehiclePropertyAccess::READ, + .changeMode = VehiclePropertyChangeMode::CONTINUOUS, + .minSampleRate = 1.0f, + .maxSampleRate = 10.0f, + }, + .initialValue = {.floatValues = {0.0f}}}, {.config = { .prop = toInt(VehicleProperty::VEHICLE_SPEED_DISPLAY_UNITS), @@ -169,7 +185,558 @@ const std::vector<ConfigDeclaration> kVehicleProperties = { toInt(VehicleUnit::MILES_PER_HOUR), toInt(VehicleUnit::KILOMETERS_PER_HOUR)}, }, - .initialValue = {.int32Values = {toInt(VehicleUnit::KILOMETERS_PER_HOUR)}}}, + .initialValue = {.int32Values = {toInt(VehicleUnit::MILES_PER_HOUR)}}}, + + {.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 = { @@ -352,8 +919,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 +1028,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::US_GALLON}}}, + + {.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 +1072,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 +1215,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 +1326,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 +1395,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 +1493,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 +1595,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 +1603,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 +1611,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 +1619,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 +1651,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 +1671,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 +1679,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/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/device/3.2/default/convert.cpp b/camera/device/3.2/default/convert.cpp index 06ad7e963c..207560783f 100644 --- a/camera/device/3.2/default/convert.cpp +++ b/camera/device/3.2/default/convert.cpp @@ -16,6 +16,7 @@ #define LOG_TAG "android.hardware.camera.device@3.2-convert-impl" #include <log/log.h> +#include <system/camera_metadata.h> #include "include/convert.h" @@ -43,6 +44,13 @@ bool convertFromHidl(const CameraMetadata &src, const camera_metadata_t** dst) { ALOGE("%s: input CameraMetadata is corrupt!", __FUNCTION__); return false; } + + if (validate_camera_metadata_structure((camera_metadata_t*)data, /*expected_size=*/NULL) != + OK) { + ALOGE("%s: Failed to validate the metadata structure", __FUNCTION__); + return false; + } + *dst = (camera_metadata_t*) data; return true; } 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/common/utils/default/DeviceFileReader.cpp b/gnss/common/utils/default/DeviceFileReader.cpp index dfc086a8b8..91e75eb460 100644 --- a/gnss/common/utils/default/DeviceFileReader.cpp +++ b/gnss/common/utils/default/DeviceFileReader.cpp @@ -32,40 +32,52 @@ void DeviceFileReader::getDataFromDeviceFile(const std::string& command, int mMi return; } - int mGnssFd = open(deviceFilePath.c_str(), O_RDWR | O_NONBLOCK); - - if (mGnssFd == -1) { + int gnss_fd, epoll_fd; + if ((gnss_fd = open(deviceFilePath.c_str(), O_RDWR | O_NONBLOCK)) == -1) { + return; + } + if (write(gnss_fd, command.c_str(), command.size()) <= 0) { + close(gnss_fd); return; } - int bytes_write = write(mGnssFd, command.c_str(), command.size()); - if (bytes_write <= 0) { - close(mGnssFd); + // Create an epoll instance. + if ((epoll_fd = epoll_create1(EPOLL_CLOEXEC)) < 0) { + close(gnss_fd); return; } + // Add file descriptor to epoll instance. struct epoll_event ev, events[1]; - ev.data.fd = mGnssFd; + memset(&ev, 0, sizeof(ev)); + ev.data.fd = gnss_fd; ev.events = EPOLLIN; - int epoll_fd = epoll_create1(0); - epoll_ctl(epoll_fd, EPOLL_CTL_ADD, mGnssFd, &ev); - int bytes_read = -1; - std::string inputStr = ""; - int epoll_ret = epoll_wait(epoll_fd, events, 1, mMinIntervalMs); + if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, gnss_fd, &ev) == -1) { + close(gnss_fd); + close(epoll_fd); + return; + } - if (epoll_ret == -1) { - close(mGnssFd); + // Wait for device file event. + if (epoll_wait(epoll_fd, events, 1, mMinIntervalMs) == -1) { + close(gnss_fd); + close(epoll_fd); return; } + + // Handle event and write data to string buffer. + int bytes_read = -1; + std::string inputStr = ""; while (true) { memset(inputBuffer, 0, INPUT_BUFFER_SIZE); - bytes_read = read(mGnssFd, &inputBuffer, INPUT_BUFFER_SIZE); + bytes_read = read(gnss_fd, &inputBuffer, INPUT_BUFFER_SIZE); if (bytes_read <= 0) { break; } s_buffer_ += std::string(inputBuffer, bytes_read); } - close(mGnssFd); + close(gnss_fd); + close(epoll_fd); // Trim end of file mark(\n\n\n\n). auto pos = s_buffer_.find("\n\n\n\n"); diff --git a/graphics/composer/2.1/utils/hal/include/composer-hal/2.1/ComposerCommandEngine.h b/graphics/composer/2.1/utils/hal/include/composer-hal/2.1/ComposerCommandEngine.h index ab67eb10bc..9ae6173a91 100644 --- a/graphics/composer/2.1/utils/hal/include/composer-hal/2.1/ComposerCommandEngine.h +++ b/graphics/composer/2.1/utils/hal/include/composer-hal/2.1/ComposerCommandEngine.h @@ -207,7 +207,7 @@ class ComposerCommandEngine : protected CommandReaderBase { bool executeSetClientTarget(uint16_t length) { // 4 parameters followed by N rectangles - if ((length - 4) % 4 != 0) { + if (!length || (length - 4) % 4 != 0) { return false; } diff --git a/sensors/2.1/multihal/android.hardware.sensors@2.1-service-multihal.rc b/sensors/2.1/multihal/android.hardware.sensors@2.1-service-multihal.rc index f47e060f88..0b59841730 100644 --- a/sensors/2.1/multihal/android.hardware.sensors@2.1-service-multihal.rc +++ b/sensors/2.1/multihal/android.hardware.sensors@2.1-service-multihal.rc @@ -1,7 +1,7 @@ service vendor.sensors-hal-2-1-multihal /vendor/bin/hw/android.hardware.sensors@2.1-service.multihal class hal user system - group system wakelock context_hub + group system wakelock context_hub uhid task_profiles ServiceCapacityLow capabilities BLOCK_SUSPEND rlimit rtprio 10 10 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()); } } |