diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-10-03 23:25:19 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-10-03 23:25:19 +0000 |
commit | 9f41e2ccad3b89cbad30da29a1bf3566f4724b49 (patch) | |
tree | b522551f1ea7f066be8bf8d0222da12ea141b666 | |
parent | bfcf2eda1e26ec93c52f18bea459e2979a412ce2 (diff) | |
parent | fc74dada36d4b830edb726868cbb54018da8f03c (diff) |
Snap for 9133013 from fc74dada36d4b830edb726868cbb54018da8f03c to tm-qpr2-release
Change-Id: Iec700b28d767a450ac04250378144e3d57cd2ca9
34 files changed, 1537 insertions, 193 deletions
diff --git a/audio/effect/all-versions/default/Effect.cpp b/audio/effect/all-versions/default/Effect.cpp index def3a3f3fb..b57dc63368 100644 --- a/audio/effect/all-versions/default/Effect.cpp +++ b/audio/effect/all-versions/default/Effect.cpp @@ -316,6 +316,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; @@ -350,8 +355,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), diff --git a/audio/effect/all-versions/default/Effect.h b/audio/effect/all-versions/default/Effect.h index f0b65df0b9..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; diff --git a/audio/effect/all-versions/vts/functional/VtsHalAudioEffectTargetTest.cpp b/audio/effect/all-versions/vts/functional/VtsHalAudioEffectTargetTest.cpp index c808ff6cc2..d95bb06c3a 100644 --- a/audio/effect/all-versions/vts/functional/VtsHalAudioEffectTargetTest.cpp +++ b/audio/effect/all-versions/vts/functional/VtsHalAudioEffectTargetTest.cpp @@ -665,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 e276a39314..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 @@ -1170,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 d35792d4b2..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)122, 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 25f4b2153c..9a93e1a11a 100644 --- a/automotive/vehicle/aidl/impl/default_config/include/DefaultConfig.h +++ b/automotive/vehicle/aidl/impl/default_config/include/DefaultConfig.h @@ -125,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, @@ -389,6 +396,306 @@ const std::vector<ConfigDeclaration> kVehicleProperties = { {SEAT_2_RIGHT, {.int32Values = {0}}}, {SEAT_2_CENTER, {.int32Values = {0}}}}}, + {.config = {.prop = toInt(VehicleProperty::SEAT_HEIGHT_POS), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = -10, + .maxInt32Value = 10}}}, + .initialValue = {.int32Values = {0}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_HEIGHT_MOVE), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = -1, + .maxInt32Value = 1}}}, + .initialValue = {.int32Values = {0}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_DEPTH_POS), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = -10, + .maxInt32Value = 10}}}, + .initialValue = {.int32Values = {0}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_DEPTH_MOVE), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = -1, + .maxInt32Value = 1}}}, + .initialValue = {.int32Values = {0}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_TILT_POS), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = -10, + .maxInt32Value = 10}}}, + .initialValue = {.int32Values = {0}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_TILT_MOVE), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = -1, + .maxInt32Value = 1}}}, + .initialValue = {.int32Values = {0}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_LUMBAR_FORE_AFT_POS), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = -10, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = -10, + .maxInt32Value = 10}}}, + .initialValue = {.int32Values = {0}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_LUMBAR_FORE_AFT_MOVE), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = -1, + .maxInt32Value = 1}}}, + .initialValue = {.int32Values = {0}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_LUMBAR_SIDE_SUPPORT_POS), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = 0, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = 0, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = 0, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = 0, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = 0, + .maxInt32Value = 10}}}, + .initialValue = {.int32Values = {0}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_LUMBAR_SIDE_SUPPORT_MOVE), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = -1, + .maxInt32Value = 1}}}, + .initialValue = {.int32Values = {0}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_HEADREST_HEIGHT_MOVE), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = -1, + .maxInt32Value = 1}}}, + .initialValue = {.int32Values = {0}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_HEADREST_ANGLE_POS), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = 0, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = 0, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = 0, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = 0, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = 0, + .maxInt32Value = 10}}}, + .initialValue = {.int32Values = {0}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_HEADREST_ANGLE_MOVE), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = -1, + .maxInt32Value = 1}}}, + .initialValue = {.int32Values = {0}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_HEADREST_FORE_AFT_POS), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = 0, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = 0, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = 0, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = 0, + .maxInt32Value = 10}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = 0, + .maxInt32Value = 10}}}, + .initialValue = {.int32Values = {0}}}, + + {.config = {.prop = toInt(VehicleProperty::SEAT_HEADREST_FORE_AFT_MOVE), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + .areaConfigs = {VehicleAreaConfig{.areaId = SEAT_1_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_1_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_LEFT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_RIGHT, + .minInt32Value = -1, + .maxInt32Value = 1}, + VehicleAreaConfig{.areaId = SEAT_2_CENTER, + .minInt32Value = -1, + .maxInt32Value = 1}}}, + .initialValue = {.int32Values = {0}}}, + {.config = { .prop = toInt(VehicleProperty::SEAT_OCCUPANCY), @@ -723,6 +1030,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, @@ -871,6 +1184,14 @@ const std::vector<ConfigDeclaration> kVehicleProperties = { }}}, .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, @@ -1032,6 +1353,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, @@ -1060,6 +1451,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, @@ -1166,6 +1577,24 @@ const std::vector<ConfigDeclaration> kVehicleProperties = { {.config = { + .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), .access = VehiclePropertyAccess::READ_WRITE, .changeMode = VehiclePropertyChangeMode::ON_CHANGE, @@ -1208,6 +1637,24 @@ const std::vector<ConfigDeclaration> kVehicleProperties = { {.config = { + .prop = toInt(VehicleProperty::CABIN_LIGHTS_SWITCH), + .access = VehiclePropertyAccess::READ_WRITE, + .changeMode = VehiclePropertyChangeMode::ON_CHANGE, + }, + .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 = + { .prop = toInt(VehicleProperty::EVS_SERVICE_REQUEST), .access = VehiclePropertyAccess::READ, .changeMode = VehiclePropertyChangeMode::ON_CHANGE, diff --git a/automotive/vehicle/aidl/impl/utils/common/src/RecurrentTimer.cpp b/automotive/vehicle/aidl/impl/utils/common/src/RecurrentTimer.cpp index 8521c4db7c..2eca6b7a17 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; @@ -128,7 +128,7 @@ void RecurrentTimer::loop() { } // 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 { @@ -146,7 +146,7 @@ void RecurrentTimer::loop() { { ScopedLockAssertion lockAssertion(mLock); - int64_t now = elapsedRealtimeNano(); + int64_t now = uptimeNanos(); while (mCallbackQueue.size() > 0) { int64_t nextTime = mCallbackQueue[0]->nextTime; if (nextTime > now) { diff --git a/bluetooth/audio/aidl/vts/VtsHalBluetoothAudioTargetTest.cpp b/bluetooth/audio/aidl/vts/VtsHalBluetoothAudioTargetTest.cpp index ebd728db34..e9b74b771c 100644 --- a/bluetooth/audio/aidl/vts/VtsHalBluetoothAudioTargetTest.cpp +++ b/bluetooth/audio/aidl/vts/VtsHalBluetoothAudioTargetTest.cpp @@ -23,6 +23,7 @@ #include <android/binder_process.h> #include <binder/IServiceManager.h> #include <binder/ProcessState.h> +#include <cutils/properties.h> #include <fmq/AidlMessageQueue.h> #include <cstdint> @@ -248,7 +249,8 @@ class BluetoothAudioProviderFactoryAidl case SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH: case SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH: case SessionType::LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH: { - ASSERT_FALSE(temp_provider_capabilities_.empty()); + // empty capability means offload is unsupported since capabilities are + // not hardcoded for (auto audio_capability : temp_provider_capabilities_) { ASSERT_EQ(audio_capability.getTag(), AudioCapabilities::leAudioCapabilities); @@ -513,8 +515,9 @@ class BluetoothAudioProviderFactoryAidl for (auto channel_mode : opus_capability->channelMode) { OpusConfiguration opus_data{ .samplingFrequencyHz = samplingFrequencyHz, + .frameDurationUs = frameDurationUs, .channelMode = channel_mode, - .frameDurationUs = frameDurationUs}; + }; opus_codec_specifics.push_back( CodecConfiguration::CodecSpecific(opus_data)); } @@ -623,8 +626,8 @@ TEST_P(BluetoothAudioProviderA2dpEncodingSoftwareAidl, for (auto channel_mode : a2dp_channel_modes) { PcmConfiguration pcm_config{ .sampleRateHz = sample_rate, - .bitsPerSample = bits_per_sample, .channelMode = channel_mode, + .bitsPerSample = bits_per_sample, }; bool is_codec_config_valid = IsPcmConfigSupported(pcm_config); DataMQDesc mq_desc; @@ -937,8 +940,8 @@ TEST_P(BluetoothAudioProviderHearingAidSoftwareAidl, for (auto channel_mode : hearing_aid_channel_modes_) { PcmConfiguration pcm_config{ .sampleRateHz = sample_rate, - .bitsPerSample = bits_per_sample, .channelMode = channel_mode, + .bitsPerSample = bits_per_sample, }; bool is_codec_config_valid = IsPcmConfigSupported(pcm_config); DataMQDesc mq_desc; @@ -1008,8 +1011,8 @@ TEST_P(BluetoothAudioProviderLeAudioOutputSoftwareAidl, for (auto data_interval_us : le_audio_output_data_interval_us_) { PcmConfiguration pcm_config{ .sampleRateHz = sample_rate, - .bitsPerSample = bits_per_sample, .channelMode = channel_mode, + .bitsPerSample = bits_per_sample, .dataIntervalUs = data_interval_us, }; bool is_codec_config_valid = @@ -1081,8 +1084,8 @@ TEST_P(BluetoothAudioProviderLeAudioInputSoftwareAidl, for (auto data_interval_us : le_audio_input_data_interval_us_) { PcmConfiguration pcm_config{ .sampleRateHz = sample_rate, - .bitsPerSample = bits_per_sample, .channelMode = channel_mode, + .bitsPerSample = bits_per_sample, .dataIntervalUs = data_interval_us, }; bool is_codec_config_valid = @@ -1144,7 +1147,7 @@ class BluetoothAudioProviderLeAudioOutputHardwareAidl bool supported) { std::vector<Lc3Configuration> le_audio_codec_configs; if (!supported) { - Lc3Configuration lc3_config{.samplingFrequencyHz = 0, .pcmBitDepth = 0}; + Lc3Configuration lc3_config{.pcmBitDepth = 0, .samplingFrequencyHz = 0}; le_audio_codec_configs.push_back(lc3_config); return le_audio_codec_configs; } @@ -1428,8 +1431,8 @@ TEST_P(BluetoothAudioProviderLeAudioBroadcastSoftwareAidl, for (auto data_interval_us : le_audio_output_data_interval_us_) { PcmConfiguration pcm_config{ .sampleRateHz = sample_rate, - .bitsPerSample = bits_per_sample, .channelMode = channel_mode, + .bitsPerSample = bits_per_sample, .dataIntervalUs = data_interval_us, }; bool is_codec_config_valid = @@ -1490,7 +1493,7 @@ class BluetoothAudioProviderLeAudioBroadcastHardwareAidl std::vector<Lc3Configuration> GetBroadcastLc3SupportedList(bool supported) { std::vector<Lc3Configuration> le_audio_codec_configs; if (!supported) { - Lc3Configuration lc3_config{.samplingFrequencyHz = 0, .pcmBitDepth = 0}; + Lc3Configuration lc3_config{.pcmBitDepth = 0, .samplingFrequencyHz = 0}; le_audio_codec_configs.push_back(lc3_config); return le_audio_codec_configs; } @@ -1650,8 +1653,8 @@ TEST_P(BluetoothAudioProviderA2dpDecodingSoftwareAidl, for (auto channel_mode : a2dp_channel_modes) { PcmConfiguration pcm_config{ .sampleRateHz = sample_rate, - .bitsPerSample = bits_per_sample, .channelMode = channel_mode, + .bitsPerSample = bits_per_sample, }; bool is_codec_config_valid = IsPcmConfigSupported(pcm_config); DataMQDesc mq_desc; diff --git a/bluetooth/audio/utils/Android.bp b/bluetooth/audio/utils/Android.bp index d08cb0a8e6..674dd116cf 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,15 @@ cc_library_shared { "liblog", "android.hardware.bluetooth.audio-V2-ndk", "libhidlbase", + "libxml2", ], + 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 d5e85b8e93..855dd28718 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) { @@ -444,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) { @@ -470,34 +398,8 @@ 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}); - } - } + kDefaultOffloadLeAudioCapabilities = + BluetoothLeAudioCodecsProvider::GetLeAudioCodecCapabilities(); } return kDefaultOffloadLeAudioCapabilities; diff --git a/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.cpp b/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.cpp index 292d352b9c..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,18 +110,72 @@ 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_ != 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) { + 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"; @@ -129,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); } } @@ -419,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..bf492706c8 --- /dev/null +++ b/bluetooth/audio/utils/aidl_session/BluetoothLeAudioCodecsProvider.cpp @@ -0,0 +1,312 @@ +/* + * 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; + +std::vector<LeAudioCodecCapabilitiesSetting> +BluetoothLeAudioCodecsProvider::GetLeAudioCodecCapabilities() { + if (!leAudioCodecCapabilities.empty()) { + return leAudioCodecCapabilities; + } + + const auto le_audio_offload_setting = + setting::readLeAudioOffloadSetting(kLeAudioCodecCapabilitiesFile); + if (!le_audio_offload_setting.has_value()) { + LOG(ERROR) << __func__ << ": Failed to read " + << kLeAudioCodecCapabilitiesFile; + return {}; + } + + 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); + return leAudioCodecCapabilities; +} + +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..402235f0cd --- /dev/null +++ b/bluetooth/audio/utils/aidl_session/BluetoothLeAudioCodecsProvider.h @@ -0,0 +1,87 @@ +/* + * 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::vector<LeAudioCodecCapabilitiesSetting> + GetLeAudioCodecCapabilities(); + + 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/le_audio_codec_capabilities/le_audio_codec_capabilities.xml b/bluetooth/audio/utils/le_audio_codec_capabilities/le_audio_codec_capabilities.xml new file mode 100644 index 0000000000..c7904b338c --- /dev/null +++ b/bluetooth/audio/utils/le_audio_codec_capabilities/le_audio_codec_capabilities.xml @@ -0,0 +1,61 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!--- + This is an example to configure LE Audio hardware offload supported capability settings + In the follow list, there would be only one list in this file. Add element into each list as needed. + + codecConfigurationList: + Supported codec capability along with its parameter setting + + strategyConfigurationList: + ASE Configuration strategies + + configurationList: + For each configuration , there are two attributes + - codecConfiguration + - strategyConfiguration + + scenarioList: + There would be only one `scenarios` group + For each scenario, the are two attributes + - encode + - decode + If a scenario is unidirectional, mark another direction as `invalid` + The configuration should be chosen from `configurationList` +--> +<leAudioOffloadSetting> + <scenarioList> + <!-- encode only --> + <scenario encode="OneChanMono_16_1" decode="invalid"/> + <scenario encode="TwoChanStereo_16_1" decode="invalid"/> + <scenario encode="OneChanStereo_16_1" decode="invalid"/> + <scenario encode="OneChanMono_16_2" decode="invalid"/> + <scenario encode="TwoChanStereo_16_2" decode="invalid"/> + <scenario encode="OneChanStereo_16_2" decode="invalid"/> + <!-- encode and decode --> + <scenario encode="OneChanStereo_16_1" decode="OneChanStereo_16_1"/> + <scenario encode="OneChanStereo_16_1" decode="OneChanMono_16_1"/> + <scenario encode="TwoChanStereo_16_1" decode="OneChanMono_16_1"/> + <scenario encode="OneChanMono_16_1" decode="OneChanMono_16_1"/> + <scenario encode="OneChanStereo_16_2" decode="OneChanStereo_16_2"/> + <scenario encode="OneChanStereo_16_2" decode="OneChanMono_16_2"/> + <scenario encode="TwoChanStereo_16_2" decode="OneChanMono_16_2"/> + <scenario encode="OneChanMono_16_2" decode="OneChanMono_16_2"/> + </scenarioList> + <configurationList> + <configuration name="OneChanMono_16_1" codecConfiguration="LC3_16k_1" strategyConfiguration="MONO_ONE_CIS_PER_DEVICE"/> + <configuration name="TwoChanStereo_16_1" codecConfiguration="LC3_16k_1" strategyConfiguration="STEREO_TWO_CISES_PER_DEVICE"/> + <configuration name="OneChanStereo_16_1" codecConfiguration="LC3_16k_1" strategyConfiguration="STEREO_ONE_CIS_PER_DEVICE"/> + <configuration name="OneChanMono_16_2" codecConfiguration="LC3_16k_2" strategyConfiguration="MONO_ONE_CIS_PER_DEVICE"/> + <configuration name="TwoChanStereo_16_2" codecConfiguration="LC3_16k_2" strategyConfiguration="STEREO_TWO_CISES_PER_DEVICE"/> + <configuration name="OneChanStereo_16_2" codecConfiguration="LC3_16k_2" strategyConfiguration="STEREO_ONE_CIS_PER_DEVICE"/> + </configurationList> + <codecConfigurationList> + <codecConfiguration name="LC3_16k_1" codec="LC3" samplingFrequency="16000" frameDurationUs="7500" octetsPerCodecFrame="30"/> + <codecConfiguration name="LC3_16k_2" codec="LC3" samplingFrequency="16000" frameDurationUs="10000" octetsPerCodecFrame="40"/> + </codecConfigurationList> + <strategyConfigurationList> + <strategyConfiguration name="STEREO_ONE_CIS_PER_DEVICE" audioLocation="STEREO" connectedDevice="2" channelCount="1"/> + <strategyConfiguration name="STEREO_TWO_CISES_PER_DEVICE" audioLocation="STEREO" connectedDevice="1" channelCount="2"/> + <strategyConfiguration name="MONO_ONE_CIS_PER_DEVICE" audioLocation="MONO" connectedDevice="1" channelCount="1"/> + </strategyConfigurationList> +</leAudioOffloadSetting> diff --git a/bluetooth/audio/utils/le_audio_codec_capabilities/le_audio_codec_capabilities.xsd b/bluetooth/audio/utils/le_audio_codec_capabilities/le_audio_codec_capabilities.xsd new file mode 100644 index 0000000000..213e5974da --- /dev/null +++ b/bluetooth/audio/utils/le_audio_codec_capabilities/le_audio_codec_capabilities.xsd @@ -0,0 +1,74 @@ +<!-- LE Audio Offload Codec Capability Schema --> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> + <xs:element name="leAudioOffloadSetting"> + <xs:complexType> + <xs:element ref="scenarioList" minOccurs="1" maxOccurs="1"/> + <xs:element ref="configurationList" minOccurs="1" maxOccurs="1"/> + <xs:element ref="codecConfigurationList" minOccurs="1" maxOccurs="1"/> + <xs:element ref="strategyConfigurationList" minOccurs="1" maxOccurs="1"/> + </xs:complexType> + </xs:element> + <xs:element name="scenarioList"> + <xs:complexType> + <xs:element ref="scenario" minOccurs="1" maxOccurs="unbounded"/> + </xs:complexType> + </xs:element> + <xs:element name="configurationList"> + <xs:complexType> + <xs:element ref="configuration" minOccurs="1" maxOccurs="unbounded"/> + </xs:complexType> + </xs:element> + <xs:element name="codecConfigurationList"> + <xs:complexType> + <xs:element ref="codecConfiguration" minOccurs="1" maxOccurs="unbounded"/> + </xs:complexType> + </xs:element> + <xs:element name="strategyConfigurationList"> + <xs:complexType> + <xs:element ref="strategyConfiguration" minOccurs="1" maxOccurs="unbounded"/> + </xs:complexType> + </xs:element> + <xs:element name="scenario"> + <xs:complexType> + <xs:attribute name="encode" type="xs:string"/> + <xs:attribute name="decode" type="xs:string"/> + </xs:complexType> + </xs:element> + <xs:element name="configuration"> + <xs:complexType> + <xs:attribute name="name" type="xs:string"/> + <xs:attribute name="codecConfiguration" type="xs:string"/> + <xs:attribute name="strategyConfiguration" type="xs:string"/> + </xs:complexType> + </xs:element> + <xs:element name="codecConfiguration"> + <xs:complexType> + <xs:attribute name="name" type="xs:string"/> + <xs:attribute name="codec" type="codecType"/> + <xs:attribute name="pcmBitDepth" type="xs:unsignedByte"/> + <xs:attribute name="samplingFrequency" type="xs:int"/> + <xs:attribute name="frameDurationUs" type="xs:int"/> + <xs:attribute name="octetsPerCodecFrame" type="xs:int"/> + <xs:attribute name="codecFrameBlocksPerSdu" type="xs:unsignedByte"/> + </xs:complexType> + </xs:element> + <xs:element name="strategyConfiguration"> + <xs:complexType> + <xs:attribute name="name" type="xs:string"/> + <xs:attribute name="audioLocation" type="audioLocation"/> + <xs:attribute name="connectedDevice" type="xs:unsignedByte"/> + <xs:attribute name="channelCount" type="xs:unsignedByte"/> + </xs:complexType> + </xs:element> + <xs:simpleType name="audioLocation"> + <xs:restriction base="xs:string"> + <xs:enumeration value="MONO"/> + <xs:enumeration value="STEREO"/> + </xs:restriction> + </xs:simpleType> + <xs:simpleType name="codecType"> + <xs:restriction base="xs:string"> + <xs:enumeration value="LC3"/> + </xs:restriction> + </xs:simpleType> +</xs:schema> diff --git a/bluetooth/audio/utils/le_audio_codec_capabilities/schema/current.txt b/bluetooth/audio/utils/le_audio_codec_capabilities/schema/current.txt new file mode 100644 index 0000000000..06aa21a7b3 --- /dev/null +++ b/bluetooth/audio/utils/le_audio_codec_capabilities/schema/current.txt @@ -0,0 +1,111 @@ +// Signature format: 2.0 +package aidl.android.hardware.bluetooth.audio.setting { + + public enum AudioLocation { + method public String getRawName(); + enum_constant public static final aidl.android.hardware.bluetooth.audio.setting.AudioLocation MONO; + enum_constant public static final aidl.android.hardware.bluetooth.audio.setting.AudioLocation STEREO; + } + + public class CodecConfiguration { + ctor public CodecConfiguration(); + method public aidl.android.hardware.bluetooth.audio.setting.CodecType getCodec(); + method public short getCodecFrameBlocksPerSdu(); + method public int getFrameDurationUs(); + method public String getName(); + method public int getOctetsPerCodecFrame(); + method public short getPcmBitDepth(); + method public int getSamplingFrequency(); + method public void setCodec(aidl.android.hardware.bluetooth.audio.setting.CodecType); + method public void setCodecFrameBlocksPerSdu(short); + method public void setFrameDurationUs(int); + method public void setName(String); + method public void setOctetsPerCodecFrame(int); + method public void setPcmBitDepth(short); + method public void setSamplingFrequency(int); + } + + public class CodecConfigurationList { + ctor public CodecConfigurationList(); + method public java.util.List<aidl.android.hardware.bluetooth.audio.setting.CodecConfiguration> getCodecConfiguration(); + } + + public enum CodecType { + method public String getRawName(); + enum_constant public static final aidl.android.hardware.bluetooth.audio.setting.CodecType LC3; + } + + public class Configuration { + ctor public Configuration(); + method public String getCodecConfiguration(); + method public String getName(); + method public String getStrategyConfiguration(); + method public void setCodecConfiguration(String); + method public void setName(String); + method public void setStrategyConfiguration(String); + } + + public class ConfigurationList { + ctor public ConfigurationList(); + method public java.util.List<aidl.android.hardware.bluetooth.audio.setting.Configuration> getConfiguration(); + } + + public class LeAudioOffloadSetting { + ctor public LeAudioOffloadSetting(); + method public aidl.android.hardware.bluetooth.audio.setting.CodecConfigurationList getCodecConfigurationList(); + method public aidl.android.hardware.bluetooth.audio.setting.ConfigurationList getConfigurationList(); + method public aidl.android.hardware.bluetooth.audio.setting.ScenarioList getScenarioList(); + method public aidl.android.hardware.bluetooth.audio.setting.StrategyConfigurationList getStrategyConfigurationList(); + method public void setCodecConfigurationList(aidl.android.hardware.bluetooth.audio.setting.CodecConfigurationList); + method public void setConfigurationList(aidl.android.hardware.bluetooth.audio.setting.ConfigurationList); + method public void setScenarioList(aidl.android.hardware.bluetooth.audio.setting.ScenarioList); + method public void setStrategyConfigurationList(aidl.android.hardware.bluetooth.audio.setting.StrategyConfigurationList); + } + + public class Scenario { + ctor public Scenario(); + method public String getDecode(); + method public String getEncode(); + method public void setDecode(String); + method public void setEncode(String); + } + + public class ScenarioList { + ctor public ScenarioList(); + method public java.util.List<aidl.android.hardware.bluetooth.audio.setting.Scenario> getScenario(); + } + + public class StrategyConfiguration { + ctor public StrategyConfiguration(); + method public aidl.android.hardware.bluetooth.audio.setting.AudioLocation getAudioLocation(); + method public short getChannelCount(); + method public short getConnectedDevice(); + method public String getName(); + method public void setAudioLocation(aidl.android.hardware.bluetooth.audio.setting.AudioLocation); + method public void setChannelCount(short); + method public void setConnectedDevice(short); + method public void setName(String); + } + + public class StrategyConfigurationList { + ctor public StrategyConfigurationList(); + method public java.util.List<aidl.android.hardware.bluetooth.audio.setting.StrategyConfiguration> getStrategyConfiguration(); + } + + public class XmlParser { + ctor public XmlParser(); + method public static aidl.android.hardware.bluetooth.audio.setting.CodecConfiguration readCodecConfiguration(java.io.InputStream) throws javax.xml.datatype.DatatypeConfigurationException, java.io.IOException, org.xmlpull.v1.XmlPullParserException; + method public static aidl.android.hardware.bluetooth.audio.setting.CodecConfigurationList readCodecConfigurationList(java.io.InputStream) throws javax.xml.datatype.DatatypeConfigurationException, java.io.IOException, org.xmlpull.v1.XmlPullParserException; + method public static aidl.android.hardware.bluetooth.audio.setting.Configuration readConfiguration(java.io.InputStream) throws javax.xml.datatype.DatatypeConfigurationException, java.io.IOException, org.xmlpull.v1.XmlPullParserException; + method public static aidl.android.hardware.bluetooth.audio.setting.ConfigurationList readConfigurationList(java.io.InputStream) throws javax.xml.datatype.DatatypeConfigurationException, java.io.IOException, org.xmlpull.v1.XmlPullParserException; + method public static aidl.android.hardware.bluetooth.audio.setting.LeAudioOffloadSetting readLeAudioOffloadSetting(java.io.InputStream) throws javax.xml.datatype.DatatypeConfigurationException, java.io.IOException, org.xmlpull.v1.XmlPullParserException; + method public static aidl.android.hardware.bluetooth.audio.setting.Scenario readScenario(java.io.InputStream) throws javax.xml.datatype.DatatypeConfigurationException, java.io.IOException, org.xmlpull.v1.XmlPullParserException; + method public static aidl.android.hardware.bluetooth.audio.setting.ScenarioList readScenarioList(java.io.InputStream) throws javax.xml.datatype.DatatypeConfigurationException, java.io.IOException, org.xmlpull.v1.XmlPullParserException; + method public static aidl.android.hardware.bluetooth.audio.setting.StrategyConfiguration readStrategyConfiguration(java.io.InputStream) throws javax.xml.datatype.DatatypeConfigurationException, java.io.IOException, org.xmlpull.v1.XmlPullParserException; + method public static aidl.android.hardware.bluetooth.audio.setting.StrategyConfigurationList readStrategyConfigurationList(java.io.InputStream) throws javax.xml.datatype.DatatypeConfigurationException, java.io.IOException, org.xmlpull.v1.XmlPullParserException; + method public static String readText(org.xmlpull.v1.XmlPullParser) throws java.io.IOException, org.xmlpull.v1.XmlPullParserException; + method public static void skip(org.xmlpull.v1.XmlPullParser) throws java.io.IOException, org.xmlpull.v1.XmlPullParserException; + } + +} + diff --git a/bluetooth/audio/utils/le_audio_codec_capabilities/schema/last_current.txt b/bluetooth/audio/utils/le_audio_codec_capabilities/schema/last_current.txt new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/bluetooth/audio/utils/le_audio_codec_capabilities/schema/last_current.txt diff --git a/bluetooth/audio/utils/le_audio_codec_capabilities/schema/last_removed.txt b/bluetooth/audio/utils/le_audio_codec_capabilities/schema/last_removed.txt new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/bluetooth/audio/utils/le_audio_codec_capabilities/schema/last_removed.txt diff --git a/bluetooth/audio/utils/le_audio_codec_capabilities/schema/removed.txt b/bluetooth/audio/utils/le_audio_codec_capabilities/schema/removed.txt new file mode 100644 index 0000000000..d802177e24 --- /dev/null +++ b/bluetooth/audio/utils/le_audio_codec_capabilities/schema/removed.txt @@ -0,0 +1 @@ +// Signature format: 2.0 diff --git a/camera/common/1.0/default/HandleImporter.cpp b/camera/common/1.0/default/HandleImporter.cpp index fbe8686766..d2fdf02457 100644 --- a/camera/common/1.0/default/HandleImporter.cpp +++ b/camera/common/1.0/default/HandleImporter.cpp @@ -18,6 +18,7 @@ #include "HandleImporter.h" #include <gralloctypes/Gralloc4.h> +#include "aidl/android/hardware/graphics/common/Smpte2086.h" #include <log/log.h> namespace android { @@ -30,6 +31,7 @@ namespace helper { using aidl::android::hardware::graphics::common::PlaneLayout; using aidl::android::hardware::graphics::common::PlaneLayoutComponent; using aidl::android::hardware::graphics::common::PlaneLayoutComponentType; +using aidl::android::hardware::graphics::common::Smpte2086; using MetadataType = android::hardware::graphics::mapper::V4_0::IMapper::MetadataType; using MapperErrorV2 = android::hardware::graphics::mapper::V2_0::Error; using MapperErrorV3 = android::hardware::graphics::mapper::V3_0::Error; @@ -127,16 +129,35 @@ YCbCrLayout HandleImporter::lockYCbCrInternal(const sp<M> mapper, buffer_handle_ bool isMetadataPesent(const sp<IMapperV4> mapper, const buffer_handle_t& buf, MetadataType metadataType) { auto buffer = const_cast<native_handle_t*>(buf); - mapper->get(buffer, metadataType, [] (const auto& tmpError, + bool ret = false; + hidl_vec<uint8_t> vec; + mapper->get(buffer, metadataType, [&] (const auto& tmpError, const auto& tmpMetadata) { if (tmpError == MapperErrorV4::NONE) { - return tmpMetadata.size() > 0; + vec = tmpMetadata; } else { ALOGE("%s: failed to get metadata %d!", __FUNCTION__, tmpError); - return false; }}); - return false; + if (vec.size() > 0) { + if (metadataType == gralloc4::MetadataType_Smpte2086){ + std::optional<Smpte2086> realSmpte2086; + gralloc4::decodeSmpte2086(vec, &realSmpte2086); + ret = realSmpte2086.has_value(); + } else if (metadataType == gralloc4::MetadataType_Smpte2094_10) { + std::optional<std::vector<uint8_t>> realSmpte2094_10; + gralloc4::decodeSmpte2094_10(vec, &realSmpte2094_10); + ret = realSmpte2094_10.has_value(); + } else if (metadataType == gralloc4::MetadataType_Smpte2094_40) { + std::optional<std::vector<uint8_t>> realSmpte2094_40; + gralloc4::decodeSmpte2094_40(vec, &realSmpte2094_40); + ret = realSmpte2094_40.has_value(); + } else { + ALOGE("%s: Unknown metadata type!", __FUNCTION__); + } + } + + return ret; } std::vector<PlaneLayout> getPlaneLayouts(const sp<IMapperV4> mapper, buffer_handle_t& buf) { diff --git a/camera/provider/aidl/vts/VtsAidlHalCameraProvider_TargetTest.cpp b/camera/provider/aidl/vts/VtsAidlHalCameraProvider_TargetTest.cpp index fe03732aff..70ab7a02b3 100644 --- a/camera/provider/aidl/vts/VtsAidlHalCameraProvider_TargetTest.cpp +++ b/camera/provider/aidl/vts/VtsAidlHalCameraProvider_TargetTest.cpp @@ -1739,6 +1739,10 @@ TEST_P(CameraAidlTest, processUltraHighResolutionRequest) { std::list<PixelFormat> pixelFormats = {PixelFormat::YCBCR_420_888, PixelFormat::RAW16}; for (PixelFormat format : pixelFormats) { + previewStream.usage = + static_cast<aidl::android::hardware::graphics::common::BufferUsage>( + GRALLOC1_CONSUMER_USAGE_CPU_READ); + previewStream.dataSpace = Dataspace::UNKNOWN; configureStreams(name, mProvider, format, &mSession, &previewStream, &halStreams, &supportsPartialResults, &partialResultCount, &useHalBufManager, &cb, 0, /*maxResolution*/ true); @@ -1843,7 +1847,6 @@ TEST_P(CameraAidlTest, processUltraHighResolutionRequest) { TEST_P(CameraAidlTest, process10BitDynamicRangeRequest) { std::vector<std::string> cameraDeviceNames = getCameraDeviceNames(mProvider); int64_t bufferId = 1; - int32_t frameNumber = 1; CameraMetadata settings; for (const auto& name : cameraDeviceNames) { @@ -1866,7 +1869,7 @@ TEST_P(CameraAidlTest, process10BitDynamicRangeRequest) { CameraMetadata req; android::hardware::camera::common::V1_0::helper::CameraMetadata defaultSettings; ndk::ScopedAStatus ret = - mSession->constructDefaultRequestSettings(RequestTemplate::STILL_CAPTURE, &req); + mSession->constructDefaultRequestSettings(RequestTemplate::PREVIEW, &req); ASSERT_TRUE(ret.isOk()); const camera_metadata_t* metadata = @@ -1896,6 +1899,10 @@ TEST_P(CameraAidlTest, process10BitDynamicRangeRequest) { Stream previewStream; std::shared_ptr<DeviceCb> cb; for (const auto& profile : profileList) { + previewStream.usage = + static_cast<aidl::android::hardware::graphics::common::BufferUsage>( + GRALLOC1_CONSUMER_USAGE_HWCOMPOSER); + previewStream.dataSpace = getDataspace(PixelFormat::IMPLEMENTATION_DEFINED); configureStreams(name, mProvider, PixelFormat::IMPLEMENTATION_DEFINED, &mSession, &previewStream, &halStreams, &supportsPartialResults, &partialResultCount, &useHalBufManager, &cb, 0, @@ -1916,63 +1923,75 @@ TEST_P(CameraAidlTest, process10BitDynamicRangeRequest) { // Don't use the queue onwards. } - std::vector<buffer_handle_t> graphicBuffers; - graphicBuffers.reserve(halStreams.size()); - - std::shared_ptr<InFlightRequest> inflightReq = std::make_shared<InFlightRequest>( - static_cast<ssize_t>(halStreams.size()), false, supportsPartialResults, - partialResultCount, std::unordered_set<std::string>(), resultQueue); - - std::vector<CaptureRequest> requests(1); - CaptureRequest& request = requests[0]; - std::vector<StreamBuffer>& outputBuffers = request.outputBuffers; - outputBuffers.resize(halStreams.size()); - - size_t k = 0; - for (const auto& halStream : halStreams) { - buffer_handle_t buffer_handle; - if (useHalBufManager) { - outputBuffers[k] = {halStream.id, 0, - NativeHandle(), BufferStatus::OK, - NativeHandle(), NativeHandle()}; - } else { - allocateGraphicBuffer(previewStream.width, previewStream.height, - android_convertGralloc1To0Usage( - static_cast<uint64_t>(halStream.producerUsage), - static_cast<uint64_t>(halStream.consumerUsage)), - halStream.overrideFormat, &buffer_handle); - - graphicBuffers.push_back(buffer_handle); - outputBuffers[k] = { - halStream.id, bufferId, android::makeToAidl(buffer_handle), - BufferStatus::OK, NativeHandle(), NativeHandle()}; - bufferId++; + mInflightMap.clear(); + // Stream as long as needed to fill the Hal inflight queue + std::vector<CaptureRequest> requests(halStreams[0].maxBuffers); + + for (int32_t frameNumber = 0; frameNumber < requests.size(); frameNumber++) { + std::shared_ptr<InFlightRequest> inflightReq = std::make_shared<InFlightRequest>( + static_cast<ssize_t>(halStreams.size()), false, supportsPartialResults, + partialResultCount, std::unordered_set<std::string>(), resultQueue); + + CaptureRequest& request = requests[frameNumber]; + std::vector<StreamBuffer>& outputBuffers = request.outputBuffers; + outputBuffers.resize(halStreams.size()); + + size_t k = 0; + inflightReq->mOutstandingBufferIds.resize(halStreams.size()); + std::vector<buffer_handle_t> graphicBuffers; + graphicBuffers.reserve(halStreams.size()); + + for (const auto& halStream : halStreams) { + buffer_handle_t buffer_handle; + if (useHalBufManager) { + outputBuffers[k] = {halStream.id, 0, + NativeHandle(), BufferStatus::OK, + NativeHandle(), NativeHandle()}; + } else { + auto usage = android_convertGralloc1To0Usage( + static_cast<uint64_t>(halStream.producerUsage), + static_cast<uint64_t>(halStream.consumerUsage)); + allocateGraphicBuffer(previewStream.width, previewStream.height, usage, + halStream.overrideFormat, &buffer_handle); + + inflightReq->mOutstandingBufferIds[halStream.id][bufferId] = buffer_handle; + graphicBuffers.push_back(buffer_handle); + outputBuffers[k] = {halStream.id, bufferId, + android::makeToAidl(buffer_handle), BufferStatus::OK, NativeHandle(), + NativeHandle()}; + bufferId++; + } + k++; } - k++; - } - request.inputBuffer = { - -1, 0, NativeHandle(), BufferStatus::ERROR, NativeHandle(), NativeHandle()}; - request.frameNumber = frameNumber; - request.fmqSettingsSize = 0; - request.settings = settings; - request.inputWidth = 0; - request.inputHeight = 0; + request.inputBuffer = { + -1, 0, NativeHandle(), BufferStatus::ERROR, NativeHandle(), NativeHandle()}; + request.frameNumber = frameNumber; + request.fmqSettingsSize = 0; + request.settings = settings; + request.inputWidth = 0; + request.inputHeight = 0; + + { + std::unique_lock<std::mutex> l(mLock); + mInflightMap[frameNumber] = inflightReq; + } - { - std::unique_lock<std::mutex> l(mLock); - mInflightMap.clear(); - mInflightMap[frameNumber] = inflightReq; } int32_t numRequestProcessed = 0; std::vector<BufferCache> cachesToRemove; ndk::ScopedAStatus returnStatus = - mSession->processCaptureRequest(requests, cachesToRemove, &numRequestProcessed); + mSession->processCaptureRequest(requests, cachesToRemove, &numRequestProcessed); ASSERT_TRUE(returnStatus.isOk()); - ASSERT_EQ(numRequestProcessed, 1u); + ASSERT_EQ(numRequestProcessed, requests.size()); - { + returnStatus = mSession->repeatingRequestEnd(requests.size() - 1, + std::vector<int32_t> {halStreams[0].id}); + ASSERT_TRUE(returnStatus.isOk()); + + for (int32_t frameNumber = 0; frameNumber < requests.size(); frameNumber++) { + const auto& inflightReq = mInflightMap[frameNumber]; std::unique_lock<std::mutex> l(mLock); while (!inflightReq->errorCodeValid && ((0 < inflightReq->numBuffersLeft) || (!inflightReq->haveResultMetadata))) { @@ -1985,6 +2004,7 @@ TEST_P(CameraAidlTest, process10BitDynamicRangeRequest) { ASSERT_NE(inflightReq->resultOutputBuffers.size(), 0u); verify10BitMetadata(mHandleImporter, *inflightReq, profile); } + if (useHalBufManager) { std::vector<int32_t> streamIds(halStreams.size()); for (size_t i = 0; i < streamIds.size(); i++) { diff --git a/camera/provider/aidl/vts/camera_aidl_test.cpp b/camera/provider/aidl/vts/camera_aidl_test.cpp index c11fc0cd2b..20f32bfe21 100644 --- a/camera/provider/aidl/vts/camera_aidl_test.cpp +++ b/camera/provider/aidl/vts/camera_aidl_test.cpp @@ -2639,8 +2639,20 @@ void CameraAidlTest::configureStreams(const std::string& name, outputStreams.clear(); Size maxSize; - auto rc = getMaxOutputSizeForFormat(staticMeta, format, &maxSize, maxResolution); - ASSERT_EQ(Status::OK, rc); + if (maxResolution) { + auto rc = getMaxOutputSizeForFormat(staticMeta, format, &maxSize, maxResolution); + ASSERT_EQ(Status::OK, rc); + } else { + AvailableStream previewThreshold = {kMaxPreviewWidth, kMaxPreviewHeight, + static_cast<int32_t>(format)}; + auto rc = getAvailableOutputStreams(staticMeta, outputStreams, &previewThreshold); + + ASSERT_EQ(Status::OK, rc); + ASSERT_FALSE(outputStreams.empty()); + maxSize.width = outputStreams[0].width; + maxSize.height = outputStreams[0].height; + } + std::vector<Stream> streams(1); streams[0] = {0, @@ -2648,9 +2660,8 @@ void CameraAidlTest::configureStreams(const std::string& name, maxSize.width, maxSize.height, format, - static_cast<::aidl::android::hardware::graphics::common::BufferUsage>( - GRALLOC1_CONSUMER_USAGE_CPU_READ), - Dataspace::UNKNOWN, + previewStream->usage, + previewStream->dataSpace, StreamRotation::ROTATION_0, "", 0, @@ -2736,7 +2747,8 @@ void CameraAidlTest::verify10BitMetadata( HandleImporter& importer, const InFlightRequest& request, aidl::android::hardware::camera::metadata::RequestAvailableDynamicRangeProfilesMap profile) { - for (const auto& b : request.resultOutputBuffers) { + for (auto b : request.resultOutputBuffers) { + importer.importBuffer(b.buffer.buffer); bool smpte2086Present = importer.isSmpte2086Present(b.buffer.buffer); bool smpte2094_10Present = importer.isSmpte2094_10Present(b.buffer.buffer); bool smpte2094_40Present = importer.isSmpte2094_40Present(b.buffer.buffer); @@ -2753,7 +2765,6 @@ void CameraAidlTest::verify10BitMetadata( ASSERT_FALSE(smpte2094_40Present); break; case ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_HDR10_PLUS: - ASSERT_FALSE(smpte2086Present); ASSERT_FALSE(smpte2094_10Present); ASSERT_TRUE(smpte2094_40Present); break; @@ -2774,6 +2785,7 @@ void CameraAidlTest::verify10BitMetadata( profile); ADD_FAILURE(); } + importer.freeBuffer(b.buffer.buffer); } } diff --git a/camera/provider/aidl/vts/camera_aidl_test.h b/camera/provider/aidl/vts/camera_aidl_test.h index ac4b2c9d0e..d828cee4a8 100644 --- a/camera/provider/aidl/vts/camera_aidl_test.h +++ b/camera/provider/aidl/vts/camera_aidl_test.h @@ -399,6 +399,10 @@ class CameraAidlTest : public ::testing::TestWithParam<std::string> { // Result metadata ::android::hardware::camera::common::V1_0::helper::CameraMetadata collectedResult; + // Inflight buffers + using OutstandingBuffers = std::unordered_map<uint64_t, buffer_handle_t>; + std::vector<OutstandingBuffers> mOutstandingBufferIds; + // A copy-able StreamBuffer using buffer_handle_t instead of AIDLs NativeHandle struct NativeStreamBuffer { int32_t streamId; diff --git a/camera/provider/aidl/vts/device_cb.cpp b/camera/provider/aidl/vts/device_cb.cpp index e5f2f1eae4..4698b4ae89 100644 --- a/camera/provider/aidl/vts/device_cb.cpp +++ b/camera/provider/aidl/vts/device_cb.cpp @@ -155,7 +155,7 @@ ScopedAStatus DeviceCb::requestStreamBuffers(const std::vector<BufferRequest>& b BufferStatus::OK, NativeHandle(), NativeHandle(), }; - mOutstandingBufferIds[idx][mNextBufferId++] = ::android::dupToAidl(handle); + mOutstandingBufferIds[idx][mNextBufferId++] = handle; } atLeastOneStreamOk = true; bufRets[i].streamId = stream.id; @@ -427,9 +427,13 @@ bool DeviceCb::processCaptureResultLocked( } CameraAidlTest::InFlightRequest::StreamBufferAndTimestamp streamBufferAndTimestamp; + auto outstandingBuffers = mUseHalBufManager ? mOutstandingBufferIds : + request->mOutstandingBufferIds; + auto outputBuffer = outstandingBuffers.empty() ? ::android::makeFromAidl(buffer.buffer) : + outstandingBuffers[buffer.streamId][buffer.bufferId]; streamBufferAndTimestamp.buffer = {buffer.streamId, buffer.bufferId, - ::android::makeFromAidl(buffer.buffer), + outputBuffer, buffer.status, ::android::makeFromAidl(buffer.acquireFence), ::android::makeFromAidl(buffer.releaseFence)}; diff --git a/camera/provider/aidl/vts/device_cb.h b/camera/provider/aidl/vts/device_cb.h index 82ca10ddcb..3ae7d10596 100644 --- a/camera/provider/aidl/vts/device_cb.h +++ b/camera/provider/aidl/vts/device_cb.h @@ -73,7 +73,7 @@ class DeviceCb : public BnCameraDeviceCallback { std::vector<Stream> mStreams; std::vector<HalStream> mHalStreams; int64_t mNextBufferId = 1; - using OutstandingBuffers = std::unordered_map<uint64_t, NativeHandle>; + using OutstandingBuffers = std::unordered_map<uint64_t, buffer_handle_t>; // size == mStreams.size(). Tracking each streams outstanding buffers std::vector<OutstandingBuffers> mOutstandingBufferIds; std::condition_variable mFlushedCondition; diff --git a/contexthub/aidl/default/ContextHub.cpp b/contexthub/aidl/default/ContextHub.cpp index 4c23cbc8bf..35e4650ef2 100644 --- a/contexthub/aidl/default/ContextHub.cpp +++ b/contexthub/aidl/default/ContextHub.cpp @@ -107,10 +107,9 @@ ScopedAStatus ContextHub::onHostEndpointConnected(const HostEndpointInfo& in_inf ScopedAStatus ContextHub::onHostEndpointDisconnected(char16_t in_hostEndpointId) { if (mConnectedHostEndpoints.count(in_hostEndpointId) > 0) { mConnectedHostEndpoints.erase(in_hostEndpointId); - return ndk::ScopedAStatus::ok(); - } else { - return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_ILLEGAL_ARGUMENT)); } + + return ndk::ScopedAStatus::ok(); } } // namespace contexthub diff --git a/dumpstate/aidl/Android.bp b/dumpstate/aidl/Android.bp index d9acc7a59c..b250d74aa0 100644 --- a/dumpstate/aidl/Android.bp +++ b/dumpstate/aidl/Android.bp @@ -31,7 +31,8 @@ aidl_interface { enabled: false, }, java: { - enabled: false, + enabled: true, + sdk_version: "module_current", }, ndk: { vndk: { diff --git a/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()); } } |