Merge "Explicitly include libhardware_header for vendors" into main
diff --git a/audio/aidl/default/EffectContext.cpp b/audio/aidl/default/EffectContext.cpp
index 5539177..26c88b2 100644
--- a/audio/aidl/default/EffectContext.cpp
+++ b/audio/aidl/default/EffectContext.cpp
@@ -63,13 +63,18 @@
}
void EffectContext::dupeFmqWithReopen(IEffect::OpenEffectReturn* effectRet) {
+ const size_t inBufferSizeInFloat = mCommon.input.frameCount * mInputFrameSize / sizeof(float);
+ const size_t outBufferSizeInFloat =
+ mCommon.output.frameCount * mOutputFrameSize / sizeof(float);
+ const size_t bufferSize = std::max(inBufferSizeInFloat, outBufferSizeInFloat);
if (!mInputMQ) {
- mInputMQ = std::make_shared<DataMQ>(mCommon.input.frameCount * mInputFrameSize /
- sizeof(float));
+ mInputMQ = std::make_shared<DataMQ>(inBufferSizeInFloat);
}
if (!mOutputMQ) {
- mOutputMQ = std::make_shared<DataMQ>(mCommon.output.frameCount * mOutputFrameSize /
- sizeof(float));
+ mOutputMQ = std::make_shared<DataMQ>(outBufferSizeInFloat);
+ }
+ if (mWorkBuffer.size() != bufferSize) {
+ mWorkBuffer.resize(bufferSize);
}
dupeFmq(effectRet);
}
@@ -222,8 +227,6 @@
}
if (needUpdateMq) {
- mWorkBuffer.resize(std::max(common.input.frameCount * mInputFrameSize / sizeof(float),
- common.output.frameCount * mOutputFrameSize / sizeof(float)));
return notifyDataMqUpdate();
}
return RetCode::SUCCESS;
diff --git a/audio/aidl/default/Stream.cpp b/audio/aidl/default/Stream.cpp
index eecc972..3e4650d 100644
--- a/audio/aidl/default/Stream.cpp
+++ b/audio/aidl/default/Stream.cpp
@@ -47,6 +47,17 @@
namespace aidl::android::hardware::audio::core {
+namespace {
+
+template <typename MQTypeError>
+auto fmqErrorHandler(const char* mqName) {
+ return [m = std::string(mqName)](MQTypeError fmqError, std::string&& errorMessage) {
+ CHECK_EQ(fmqError, MQTypeError::NONE) << m << ": " << errorMessage;
+ };
+}
+
+} // namespace
+
void StreamContext::fillDescriptor(StreamDescriptor* desc) {
if (mCommandMQ) {
desc->command = mCommandMQ->dupeDesc();
@@ -332,11 +343,7 @@
bool StreamInWorkerLogic::read(size_t clientSize, StreamDescriptor::Reply* reply) {
ATRACE_CALL();
StreamContext::DataMQ* const dataMQ = mContext->getDataMQ();
- StreamContext::DataMQ::Error fmqError = StreamContext::DataMQ::Error::NONE;
- std::string fmqErrorMsg;
- const size_t byteCount = std::min(
- {clientSize, dataMQ->availableToWrite(&fmqError, &fmqErrorMsg), mDataBufferSize});
- CHECK(fmqError == StreamContext::DataMQ::Error::NONE) << fmqErrorMsg;
+ const size_t byteCount = std::min({clientSize, dataMQ->availableToWrite(), mDataBufferSize});
const bool isConnected = mIsConnected;
const size_t frameSize = mContext->getFrameSize();
size_t actualFrameCount = 0;
@@ -612,10 +619,7 @@
bool StreamOutWorkerLogic::write(size_t clientSize, StreamDescriptor::Reply* reply) {
ATRACE_CALL();
StreamContext::DataMQ* const dataMQ = mContext->getDataMQ();
- StreamContext::DataMQ::Error fmqError = StreamContext::DataMQ::Error::NONE;
- std::string fmqErrorMsg;
- const size_t readByteCount = dataMQ->availableToRead(&fmqError, &fmqErrorMsg);
- CHECK(fmqError == StreamContext::DataMQ::Error::NONE) << fmqErrorMsg;
+ const size_t readByteCount = dataMQ->availableToRead();
const size_t frameSize = mContext->getFrameSize();
bool fatal = false;
int32_t latency = mContext->getNominalLatencyMs();
@@ -719,6 +723,14 @@
LOG(WARNING) << __func__ << ": invalid worker tid: " << workerTid;
}
}
+ getContext().getCommandMQ()->setErrorHandler(
+ fmqErrorHandler<StreamContext::CommandMQ::Error>("CommandMQ"));
+ getContext().getReplyMQ()->setErrorHandler(
+ fmqErrorHandler<StreamContext::ReplyMQ::Error>("ReplyMQ"));
+ if (getContext().getDataMQ() != nullptr) {
+ getContext().getDataMQ()->setErrorHandler(
+ fmqErrorHandler<StreamContext::DataMQ::Error>("DataMQ"));
+ }
return ndk::ScopedAStatus::ok();
}
diff --git a/audio/aidl/vts/EffectHelper.h b/audio/aidl/vts/EffectHelper.h
index 0fa170f..3877c60 100644
--- a/audio/aidl/vts/EffectHelper.h
+++ b/audio/aidl/vts/EffectHelper.h
@@ -83,6 +83,8 @@
return prefix;
}
+static constexpr float kMaxAudioSampleValue = 1;
+
class EffectHelper {
public:
void create(std::shared_ptr<IFactory> factory, std::shared_ptr<IEffect>& effect,
@@ -413,6 +415,19 @@
}
}
+ // Fill inputBuffer with random values between -maxAudioSampleValue to maxAudioSampleValue
+ void generateInputBuffer(std::vector<float>& inputBuffer, size_t startPosition, bool isStrip,
+ size_t channelCount,
+ float maxAudioSampleValue = kMaxAudioSampleValue) {
+ size_t increment = isStrip ? 1 /*Fill input at all the channels*/
+ : channelCount /*Fill input at only one channel*/;
+
+ for (size_t i = startPosition; i < inputBuffer.size(); i += increment) {
+ inputBuffer[i] =
+ ((static_cast<float>(std::rand()) / RAND_MAX) * 2 - 1) * maxAudioSampleValue;
+ }
+ }
+
// Generate multitone input between -1 to +1 using testFrequencies
void generateMultiTone(const std::vector<int>& testFrequencies, std::vector<float>& input,
const int samplingFrequency) {
diff --git a/audio/aidl/vts/VtsHalAudioCoreModuleTargetTest.cpp b/audio/aidl/vts/VtsHalAudioCoreModuleTargetTest.cpp
index 8d430de..2bf70c7 100644
--- a/audio/aidl/vts/VtsHalAudioCoreModuleTargetTest.cpp
+++ b/audio/aidl/vts/VtsHalAudioCoreModuleTargetTest.cpp
@@ -3072,8 +3072,8 @@
static bool skipStreamIoTestForMixPortConfig(const AudioPortConfig& portConfig) {
return (portConfig.flags.value().getTag() == AudioIoFlags::input &&
isAnyBitPositionFlagSet(portConfig.flags.value().template get<AudioIoFlags::input>(),
- {AudioInputFlags::VOIP_TX, AudioInputFlags::HW_HOTWORD,
- AudioInputFlags::HOTWORD_TAP})) ||
+ {AudioInputFlags::MMAP_NOIRQ, AudioInputFlags::VOIP_TX,
+ AudioInputFlags::HW_HOTWORD, AudioInputFlags::HOTWORD_TAP})) ||
(portConfig.flags.value().getTag() == AudioIoFlags::output &&
isAnyBitPositionFlagSet(
portConfig.flags.value().template get<AudioIoFlags::output>(),
@@ -3131,11 +3131,8 @@
EXPECT_FALSE(mWorker->hasError()) << mWorker->getError();
EXPECT_EQ("", mWorkerDriver->getUnexpectedStateTransition());
if (validatePosition) {
- if (IOTraits<Stream>::is_input &&
- !mStream->getStreamContext()->isMmapped() /*TODO(b/274456992) remove*/) {
- EXPECT_TRUE(mWorkerDriver->hasObservablePositionIncrease());
- EXPECT_TRUE(mWorkerDriver->hasHardwarePositionIncrease());
- }
+ EXPECT_TRUE(mWorkerDriver->hasObservablePositionIncrease());
+ EXPECT_TRUE(mWorkerDriver->hasHardwarePositionIncrease());
EXPECT_FALSE(mWorkerDriver->hasObservableRetrogradePosition());
EXPECT_FALSE(mWorkerDriver->hasHardwareRetrogradePosition());
}
@@ -4097,8 +4094,7 @@
EXPECT_FALSE(worker.hasError()) << worker.getError();
EXPECT_EQ("", driver.getUnexpectedStateTransition());
if (ValidatePosition(stream.getDevice())) {
- if (validatePositionIncrease &&
- !stream.getStreamContext()->isMmapped() /*TODO(b/274456992) remove*/) {
+ if (validatePositionIncrease) {
EXPECT_TRUE(driver.hasObservablePositionIncrease());
EXPECT_TRUE(driver.hasHardwarePositionIncrease());
}
@@ -4132,8 +4128,7 @@
EXPECT_FALSE(worker.hasError()) << worker.getError();
EXPECT_EQ("", driver.getUnexpectedStateTransition());
if (ValidatePosition(stream.getDevice())) {
- if (validatePositionIncrease &&
- !stream.getStreamContext()->isMmapped() /*TODO(b/274456992) remove*/) {
+ if (validatePositionIncrease) {
EXPECT_TRUE(driver.hasObservablePositionIncrease());
EXPECT_TRUE(driver.hasHardwarePositionIncrease());
}
diff --git a/audio/aidl/vts/VtsHalDownmixTargetTest.cpp b/audio/aidl/vts/VtsHalDownmixTargetTest.cpp
index a1491e6..bf22839 100644
--- a/audio/aidl/vts/VtsHalDownmixTargetTest.cpp
+++ b/audio/aidl/vts/VtsHalDownmixTargetTest.cpp
@@ -149,22 +149,6 @@
mOutputBuffer.resize(mOutputBufferSize);
}
- // Generate mInputBuffer values between -kMaxDownmixSample to kMaxDownmixSample
- void generateInputBuffer(size_t position, bool isStrip) {
- size_t increment;
- if (isStrip)
- // Fill input at all the channels
- increment = 1;
- else
- // Fill input at only one channel
- increment = mInputChannelCount;
-
- for (size_t i = position; i < mInputBuffer.size(); i += increment) {
- mInputBuffer[i] =
- ((static_cast<float>(std::rand()) / RAND_MAX) * 2 - 1) * kMaxDownmixSample;
- }
- }
-
bool isLayoutValid(int32_t inputLayout) {
if (inputLayout & kMaxChannelMask) {
return false;
@@ -365,7 +349,8 @@
for (int32_t channel : supportedChannels) {
size_t position = std::distance(supportedChannels.begin(), supportedChannels.find(channel));
- generateInputBuffer(position, false /*isStripe*/);
+ generateInputBuffer(mInputBuffer, position, false /*isStripe*/,
+ mInputChannelCount /*channelCount*/, kMaxDownmixSample);
ASSERT_NO_FATAL_FAILURE(
processAndWriteToOutput(mInputBuffer, mOutputBuffer, mEffect, &mOpenEffectReturn));
validateOutput(channel, position);
@@ -417,7 +402,8 @@
ASSERT_NO_FATAL_FAILURE(setParameters(Downmix::Type::STRIP));
// Generate input buffer, call process and compare outputs
- generateInputBuffer(0 /*position*/, true /*isStripe*/);
+ generateInputBuffer(mInputBuffer, 0 /*position*/, true /*isStripe*/,
+ mInputChannelCount /*channelCount*/, kMaxDownmixSample);
ASSERT_NO_FATAL_FAILURE(
processAndWriteToOutput(mInputBuffer, mOutputBuffer, mEffect, &mOpenEffectReturn));
validateOutput();
diff --git a/audio/aidl/vts/VtsHalHapticGeneratorTargetTest.cpp b/audio/aidl/vts/VtsHalHapticGeneratorTargetTest.cpp
index 6af326d..2b6dc3d 100644
--- a/audio/aidl/vts/VtsHalHapticGeneratorTargetTest.cpp
+++ b/audio/aidl/vts/VtsHalHapticGeneratorTargetTest.cpp
@@ -121,17 +121,23 @@
Parameter::Specific specific;
specific.set<Parameter::Specific::hapticGenerator>(setHg);
expectParam.set<Parameter::specific>(specific);
- EXPECT_STATUS(EX_NONE, mEffect->setParameter(expectParam)) << expectParam.toString();
- // get parameter
- Parameter getParam;
- Parameter::Id id;
- HapticGenerator::Id hgId;
- hgId.set<HapticGenerator::Id::commonTag>(tag);
- id.set<Parameter::Id::hapticGeneratorTag>(hgId);
- EXPECT_STATUS(EX_NONE, mEffect->getParameter(id, &getParam));
- EXPECT_EQ(expectParam, getParam) << expectParam.toString() << "\n"
- << getParam.toString();
+ const bool valid =
+ isParameterValid<HapticGenerator, Range::hapticGenerator>(setHg, mDescriptor);
+ const binder_exception_t expected = valid ? EX_NONE : EX_ILLEGAL_ARGUMENT;
+ EXPECT_STATUS(expected, mEffect->setParameter(expectParam)) << expectParam.toString();
+
+ // only get if parameter in range and set success
+ if (expected == EX_NONE) {
+ Parameter getParam;
+ Parameter::Id id;
+ HapticGenerator::Id hgId;
+ hgId.set<HapticGenerator::Id::commonTag>(tag);
+ id.set<Parameter::Id::hapticGeneratorTag>(hgId);
+ EXPECT_STATUS(EX_NONE, mEffect->getParameter(id, &getParam));
+ EXPECT_EQ(expectParam, getParam) << expectParam.toString() << "\n"
+ << getParam.toString();
+ }
}
}
diff --git a/audio/aidl/vts/VtsHalLoudnessEnhancerTargetTest.cpp b/audio/aidl/vts/VtsHalLoudnessEnhancerTargetTest.cpp
index 1fe8beb..4c868a9 100644
--- a/audio/aidl/vts/VtsHalLoudnessEnhancerTargetTest.cpp
+++ b/audio/aidl/vts/VtsHalLoudnessEnhancerTargetTest.cpp
@@ -32,7 +32,6 @@
using aidl::android::hardware::audio::effect::Parameter;
using android::hardware::audio::common::testing::detail::TestExecutionTracer;
-static constexpr float kMaxAudioSample = 1;
static constexpr int kZeroGain = 0;
static constexpr int kMaxGain = std::numeric_limits<int>::max();
static constexpr int kMinGain = std::numeric_limits<int>::min();
@@ -154,12 +153,14 @@
public:
LoudnessEnhancerDataTest() {
std::tie(mFactory, mDescriptor) = GetParam();
- mBufferSize = kFrameCount *
- getChannelCount(AudioChannelLayout::make<AudioChannelLayout::layoutMask>(
- AudioChannelLayout::LAYOUT_STEREO));
- generateInputBuffer();
+ size_t channelCount =
+ getChannelCount(AudioChannelLayout::make<AudioChannelLayout::layoutMask>(
+ AudioChannelLayout::LAYOUT_STEREO));
+ mBufferSizeInFrames = kFrameCount * channelCount;
+ mInputBuffer.resize(mBufferSizeInFrames);
+ generateInputBuffer(mInputBuffer, 0, true, channelCount, kMaxAudioSampleValue);
- mOutputBuffer.resize(mBufferSize);
+ mOutputBuffer.resize(mBufferSizeInFrames);
}
void SetUp() override {
@@ -177,14 +178,6 @@
TearDownLoudnessEnhancer();
}
- // Fill inputBuffer with random values between -kMaxAudioSample to kMaxAudioSample
- void generateInputBuffer() {
- for (size_t i = 0; i < mBufferSize; i++) {
- mInputBuffer.push_back(((static_cast<float>(std::rand()) / RAND_MAX) * 2 - 1) *
- kMaxAudioSample);
- }
- }
-
// Add gains to the mInputBuffer and store processed output to mOutputBuffer
void processAndWriteToOutput() {
// Check AidlMessageQueues are not null
@@ -220,7 +213,7 @@
}
void assertSequentialGains(const std::vector<int>& gainValues, bool isIncreasing) {
- std::vector<float> baseOutput(mBufferSize);
+ std::vector<float> baseOutput(mBufferSizeInFrames);
// Process a reference output buffer with 0 gain which gives compressed input values
binder_exception_t expected;
@@ -257,7 +250,7 @@
std::vector<float> mInputBuffer;
std::vector<float> mOutputBuffer;
- size_t mBufferSize;
+ size_t mBufferSizeInFrames;
};
TEST_P(LoudnessEnhancerDataTest, IncreasingGains) {
@@ -296,10 +289,10 @@
setParameters(kMaxGain, expected);
ASSERT_NO_FATAL_FAILURE(processAndWriteToOutput());
- // Validate that mOutputBuffer reaches to kMaxAudioSample for INT_MAX gain
+ // Validate that mOutputBuffer reaches to kMaxAudioSampleValue for INT_MAX gain
for (size_t i = 0; i < mOutputBuffer.size(); i++) {
if (mInputBuffer[i] != 0) {
- EXPECT_NEAR(kMaxAudioSample, abs(mOutputBuffer[i]), kAbsError);
+ EXPECT_NEAR(kMaxAudioSampleValue, abs(mOutputBuffer[i]), kAbsError);
} else {
ASSERT_EQ(mOutputBuffer[i], mInputBuffer[i]);
}
diff --git a/audio/aidl/vts/VtsHalVisualizerTargetTest.cpp b/audio/aidl/vts/VtsHalVisualizerTargetTest.cpp
index f215a8e..f89cb40 100644
--- a/audio/aidl/vts/VtsHalVisualizerTargetTest.cpp
+++ b/audio/aidl/vts/VtsHalVisualizerTargetTest.cpp
@@ -24,6 +24,7 @@
using namespace android;
+using aidl::android::hardware::audio::common::getChannelCount;
using aidl::android::hardware::audio::effect::Descriptor;
using aidl::android::hardware::audio::effect::getEffectTypeUuidVisualizer;
using aidl::android::hardware::audio::effect::IEffect;
@@ -56,6 +57,15 @@
mMeasurementMode(std::get<PARAM_MEASUREMENT_MODE>(GetParam())),
mLatency(std::get<PARAM_LATENCY>(GetParam())) {
std::tie(mFactory, mDescriptor) = std::get<PARAM_INSTANCE_NAME>(GetParam());
+
+ size_t channelCount =
+ getChannelCount(AudioChannelLayout::make<AudioChannelLayout::layoutMask>(
+ AudioChannelLayout::LAYOUT_STEREO));
+ mBufferSizeInFrames = kInputFrameCount * channelCount;
+ mInputBuffer.resize(mBufferSizeInFrames);
+ generateInputBuffer(mInputBuffer, 0, true, channelCount, kMaxAudioSampleValue);
+
+ mOutputBuffer.resize(mBufferSizeInFrames);
}
void SetUp() override {
@@ -65,14 +75,15 @@
Parameter::Common common = createParamCommon(
0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
- IEffect::OpenEffectReturn ret;
- ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt, &ret, EX_NONE));
+ ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt, &mOpenEffectReturn, EX_NONE));
ASSERT_NE(nullptr, mEffect);
+ mVersion = EffectFactoryHelper::getHalVersion(mFactory);
}
void TearDown() override {
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
+ mOpenEffectReturn = IEffect::OpenEffectReturn{};
}
static const long kInputFrameCount = 0x100, kOutputFrameCount = 0x100;
@@ -83,6 +94,12 @@
Visualizer::ScalingMode mScalingMode = Visualizer::ScalingMode::NORMALIZED;
Visualizer::MeasurementMode mMeasurementMode = Visualizer::MeasurementMode::NONE;
int mLatency = 0;
+ int mVersion = 0;
+ std::vector<float> mInputBuffer;
+ std::vector<float> mOutputBuffer;
+ size_t mBufferSizeInFrames;
+ IEffect::OpenEffectReturn mOpenEffectReturn;
+ bool mAllParamsValid = true;
void SetAndGetParameters() {
for (auto& it : mCommonTags) {
@@ -94,6 +111,7 @@
ASSERT_STATUS(EX_NONE, mEffect->getDescriptor(&desc));
const bool valid = isParameterValid<Visualizer, Range::visualizer>(vs, desc);
const binder_exception_t expected = valid ? EX_NONE : EX_ILLEGAL_ARGUMENT;
+ if (expected == EX_ILLEGAL_ARGUMENT) mAllParamsValid = false;
// set parameter
Parameter expectParam;
@@ -153,23 +171,50 @@
};
TEST_P(VisualizerParamTest, SetAndGetCaptureSize) {
- EXPECT_NO_FATAL_FAILURE(addCaptureSizeParam(mCaptureSize));
- SetAndGetParameters();
+ ASSERT_NO_FATAL_FAILURE(addCaptureSizeParam(mCaptureSize));
+ ASSERT_NO_FATAL_FAILURE(SetAndGetParameters());
}
TEST_P(VisualizerParamTest, SetAndGetScalingMode) {
- EXPECT_NO_FATAL_FAILURE(addScalingModeParam(mScalingMode));
- SetAndGetParameters();
+ ASSERT_NO_FATAL_FAILURE(addScalingModeParam(mScalingMode));
+ ASSERT_NO_FATAL_FAILURE(SetAndGetParameters());
}
TEST_P(VisualizerParamTest, SetAndGetMeasurementMode) {
- EXPECT_NO_FATAL_FAILURE(addMeasurementModeParam(mMeasurementMode));
- SetAndGetParameters();
+ ASSERT_NO_FATAL_FAILURE(addMeasurementModeParam(mMeasurementMode));
+ ASSERT_NO_FATAL_FAILURE(SetAndGetParameters());
}
TEST_P(VisualizerParamTest, SetAndGetLatency) {
- EXPECT_NO_FATAL_FAILURE(addLatencyParam(mLatency));
- SetAndGetParameters();
+ ASSERT_NO_FATAL_FAILURE(addLatencyParam(mLatency));
+ ASSERT_NO_FATAL_FAILURE(SetAndGetParameters());
+}
+
+TEST_P(VisualizerParamTest, testCaptureSampleBufferSizeAndOutput) {
+ SKIP_TEST_IF_DATA_UNSUPPORTED(mDescriptor.common.flags);
+ ASSERT_NO_FATAL_FAILURE(addCaptureSizeParam(mCaptureSize));
+ ASSERT_NO_FATAL_FAILURE(addScalingModeParam(mScalingMode));
+ ASSERT_NO_FATAL_FAILURE(addMeasurementModeParam(mMeasurementMode));
+ ASSERT_NO_FATAL_FAILURE(addLatencyParam(mLatency));
+ ASSERT_NO_FATAL_FAILURE(SetAndGetParameters());
+
+ Parameter getParam;
+ Parameter::Id id;
+ Visualizer::Id vsId;
+ vsId.set<Visualizer::Id::commonTag>(Visualizer::captureSampleBuffer);
+ id.set<Parameter::Id::visualizerTag>(vsId);
+ EXPECT_STATUS(EX_NONE, mEffect->getParameter(id, &getParam)) << " with: " << id.toString();
+
+ ASSERT_NO_FATAL_FAILURE(processAndWriteToOutput(mInputBuffer, mOutputBuffer, mEffect,
+ &mOpenEffectReturn, mVersion));
+ ASSERT_EQ(mInputBuffer, mOutputBuffer);
+
+ if (mAllParamsValid) {
+ std::vector<uint8_t> captureBuffer = getParam.get<Parameter::specific>()
+ .get<Parameter::Specific::visualizer>()
+ .get<Visualizer::captureSampleBuffer>();
+ ASSERT_EQ((size_t)mCaptureSize, captureBuffer.size());
+ }
}
std::vector<std::pair<std::shared_ptr<IFactory>, Descriptor>> kDescPair;
diff --git a/automotive/vehicle/aidl/emu_metadata/android.hardware.automotive.vehicle-types-meta.json b/automotive/vehicle/aidl/emu_metadata/android.hardware.automotive.vehicle-types-meta.json
index de0e398..8ef440d 100644
--- a/automotive/vehicle/aidl/emu_metadata/android.hardware.automotive.vehicle-types-meta.json
+++ b/automotive/vehicle/aidl/emu_metadata/android.hardware.automotive.vehicle-types-meta.json
@@ -501,7 +501,7 @@
{
"name": "AP_POWER_STATE_REQ",
"value": 289475072,
- "description": "Property to control power state of application processor\nIt is assumed that AP's power state is controlled by a separate power controller.\nFor configuration information, VehiclePropConfig.configArray must have bit flag combining values in VehicleApPowerStateConfigFlag.\nint32Values[0] : VehicleApPowerStateReq enum value int32Values[1] : additional parameter relevant for each state, 0 if not used."
+ "description": "Property to control power state of application processor\nIt is assumed that AP's power state is controlled by a separate power controller.\nFor configuration information, VehiclePropConfig.configArray must have bit flag combining values in VehicleApPowerStateConfigFlag.\nconfigArray[0] : Bit flag combining values in VehicleApPowerStateConfigFlag, 0x0 if not used, 0x1 for enabling suspend to ram, 0x2 for supporting powering on AP from off state after timeout. 0x4 for enabling suspend to disk,\nint32Values[0] : VehicleApPowerStateReq enum value int32Values[1] : additional parameter relevant for each state, 0 if not used."
},
{
"name": "AP_POWER_STATE_REPORT",
diff --git a/automotive/vehicle/aidl/impl/fake_impl/hardware/include/FakeVehicleHardware.h b/automotive/vehicle/aidl/impl/fake_impl/hardware/include/FakeVehicleHardware.h
index ec69894..5916307 100644
--- a/automotive/vehicle/aidl/impl/fake_impl/hardware/include/FakeVehicleHardware.h
+++ b/automotive/vehicle/aidl/impl/fake_impl/hardware/include/FakeVehicleHardware.h
@@ -56,6 +56,13 @@
FakeVehicleHardware(std::string defaultConfigDir, std::string overrideConfigDir,
bool forceOverride);
+ // s2rS2dConfig is the config for whether S2R or S2D is supported, must be a bit flag combining
+ // values from VehicleApPowerStateConfigFlag.
+ // The default implementation is reading this from system property:
+ // "ro.vendor.fake_vhal.ap_power_state_req.config".
+ FakeVehicleHardware(std::string defaultConfigDir, std::string overrideConfigDir,
+ bool forceOverride, int32_t s2rS2dConfig);
+
~FakeVehicleHardware();
// Get all the property configs.
@@ -193,7 +200,7 @@
// provides power controlling related properties.
std::string mPowerControllerServiceAddress = "";
- void init();
+ void init(int32_t s2rS2dConfig);
// Stores the initial value to property store.
void storePropInitialValue(const ConfigDeclaration& config);
// The callback that would be called when a vehicle property value change happens.
diff --git a/automotive/vehicle/aidl/impl/fake_impl/hardware/src/FakeVehicleHardware.cpp b/automotive/vehicle/aidl/impl/fake_impl/hardware/src/FakeVehicleHardware.cpp
index 54dcca2..6668d16 100644
--- a/automotive/vehicle/aidl/impl/fake_impl/hardware/src/FakeVehicleHardware.cpp
+++ b/automotive/vehicle/aidl/impl/fake_impl/hardware/src/FakeVehicleHardware.cpp
@@ -348,6 +348,13 @@
FakeVehicleHardware::FakeVehicleHardware(std::string defaultConfigDir,
std::string overrideConfigDir, bool forceOverride)
+ : FakeVehicleHardware(defaultConfigDir, overrideConfigDir, forceOverride,
+ /*s2rS2dConfig=*/
+ GetIntProperty(POWER_STATE_REQ_CONFIG_PROPERTY, /*default_value=*/0)) {}
+
+FakeVehicleHardware::FakeVehicleHardware(std::string defaultConfigDir,
+ std::string overrideConfigDir, bool forceOverride,
+ int32_t s2rS2dConfig)
: mValuePool(std::make_unique<VehiclePropValuePool>()),
mServerSidePropStore(new VehiclePropertyStore(mValuePool)),
mDefaultConfigDir(defaultConfigDir),
@@ -360,7 +367,7 @@
mPendingGetValueRequests(this),
mPendingSetValueRequests(this),
mForceOverride(forceOverride) {
- init();
+ init(s2rS2dConfig);
}
FakeVehicleHardware::~FakeVehicleHardware() {
@@ -388,7 +395,7 @@
return configsByPropId;
}
-void FakeVehicleHardware::init() {
+void FakeVehicleHardware::init(int32_t s2rS2dConfig) {
maybeGetGrpcServiceInfo(&mPowerControllerServiceAddress);
for (auto& [_, configDeclaration] : loadConfigDeclarations()) {
@@ -396,8 +403,7 @@
VehiclePropertyStore::TokenFunction tokenFunction = nullptr;
if (cfg.prop == toInt(VehicleProperty::AP_POWER_STATE_REQ)) {
- int config = GetIntProperty(POWER_STATE_REQ_CONFIG_PROPERTY, /*default_value=*/0);
- cfg.configArray[0] = config;
+ cfg.configArray[0] = s2rS2dConfig;
} else if (cfg.prop == OBD2_FREEZE_FRAME) {
tokenFunction = [](const VehiclePropValue& propValue) { return propValue.timestamp; };
}
diff --git a/automotive/vehicle/aidl/impl/fake_impl/hardware/test/FakeVehicleHardwareTest.cpp b/automotive/vehicle/aidl/impl/fake_impl/hardware/test/FakeVehicleHardwareTest.cpp
index 95647df..f6098ca 100644
--- a/automotive/vehicle/aidl/impl/fake_impl/hardware/test/FakeVehicleHardwareTest.cpp
+++ b/automotive/vehicle/aidl/impl/fake_impl/hardware/test/FakeVehicleHardwareTest.cpp
@@ -20,6 +20,7 @@
#include <FakeUserHal.h>
#include <PropertyUtils.h>
+#include <aidl/android/hardware/automotive/vehicle/VehicleApPowerStateConfigFlag.h>
#include <aidl/android/hardware/automotive/vehicle/VehicleApPowerStateShutdownParam.h>
#include <android/hardware/automotive/vehicle/TestVendorProperty.h>
@@ -73,6 +74,7 @@
using ::aidl::android::hardware::automotive::vehicle::SetValueResult;
using ::aidl::android::hardware::automotive::vehicle::StatusCode;
using ::aidl::android::hardware::automotive::vehicle::SubscribeOptions;
+using ::aidl::android::hardware::automotive::vehicle::VehicleApPowerStateConfigFlag;
using ::aidl::android::hardware::automotive::vehicle::VehicleApPowerStateReport;
using ::aidl::android::hardware::automotive::vehicle::VehicleApPowerStateReq;
using ::aidl::android::hardware::automotive::vehicle::VehicleApPowerStateShutdownParam;
@@ -3863,6 +3865,25 @@
}
}
+TEST_F(FakeVehicleHardwareTest, testOverrideApPowerStateReqConfig) {
+ auto hardware = std::make_unique<FakeVehicleHardware>(
+ android::base::GetExecutableDirectory(),
+ /*overrideConfigDir=*/"",
+ /*forceOverride=*/false,
+ toInt(VehicleApPowerStateConfigFlag::ENABLE_DEEP_SLEEP_FLAG) |
+ toInt(VehicleApPowerStateConfigFlag::ENABLE_HIBERNATION_FLAG));
+
+ std::vector<VehiclePropConfig> configs = hardware->getAllPropertyConfigs();
+
+ for (const auto& config : configs) {
+ if (config.prop != toInt(VehicleProperty::AP_POWER_STATE_REQ)) {
+ continue;
+ }
+ ASSERT_EQ(config.configArray[0], 0x5);
+ break;
+ }
+}
+
} // namespace fake
} // namespace vehicle
} // namespace automotive
diff --git a/automotive/vehicle/aidl/impl/vhal/include/DefaultVehicleHal.h b/automotive/vehicle/aidl/impl/vhal/include/DefaultVehicleHal.h
index fa2a310..b58d0f5 100644
--- a/automotive/vehicle/aidl/impl/vhal/include/DefaultVehicleHal.h
+++ b/automotive/vehicle/aidl/impl/vhal/include/DefaultVehicleHal.h
@@ -31,6 +31,7 @@
#include <android-base/thread_annotations.h>
#include <android/binder_auto_utils.h>
+#include <functional>
#include <memory>
#include <mutex>
#include <shared_mutex>
@@ -138,12 +139,11 @@
// Only used for testing.
int32_t mTestInterfaceVersion = 0;
- // mConfigsByPropId and mConfigFile is lazy initialized.
- mutable std::mutex mConfigInitLock;
- mutable bool mConfigInit GUARDED_BY(mConfigInitLock) = false;
+ mutable std::atomic<bool> mConfigInit = false;
+ mutable std::shared_timed_mutex mConfigLock;
mutable std::unordered_map<int32_t, aidlvhal::VehiclePropConfig> mConfigsByPropId
- GUARDED_BY(mConfigInitLock);
- mutable std::unique_ptr<ndk::ScopedFileDescriptor> mConfigFile GUARDED_BY(mConfigInitLock);
+ GUARDED_BY(mConfigLock);
+ mutable std::unique_ptr<ndk::ScopedFileDescriptor> mConfigFile GUARDED_BY(mConfigLock);
std::mutex mLock;
std::unordered_map<const AIBinder*, std::unique_ptr<OnBinderDiedContext>> mOnBinderDiedContexts
@@ -175,7 +175,10 @@
android::base::Result<std::vector<int64_t>> checkDuplicateRequests(
const std::vector<aidlvhal::SetValueRequest>& requests);
- VhalResult<void> checkSubscribeOptions(const std::vector<aidlvhal::SubscribeOptions>& options);
+ VhalResult<void> checkSubscribeOptions(
+ const std::vector<aidlvhal::SubscribeOptions>& options,
+ const std::unordered_map<int32_t, aidlvhal::VehiclePropConfig>& configsByPropId)
+ REQUIRES_SHARED(mConfigLock);
VhalResult<void> checkPermissionHelper(const aidlvhal::VehiclePropValue& value,
aidlvhal::VehiclePropertyAccess accessToTest) const;
@@ -184,7 +187,7 @@
VhalResult<void> checkWritePermission(const aidlvhal::VehiclePropValue& value) const;
- android::base::Result<const aidlvhal::VehiclePropConfig*> getConfig(int32_t propId) const;
+ android::base::Result<aidlvhal::VehiclePropConfig> getConfig(int32_t propId) const;
void onBinderDiedWithContext(const AIBinder* clientId);
@@ -196,7 +199,7 @@
bool checkDumpPermission();
- bool getAllPropConfigsFromHardwareLocked() const REQUIRES(mConfigInitLock);
+ bool getAllPropConfigsFromHardwareLocked() const EXCLUDES(mConfigLock);
// The looping handler function to process all onBinderDied or onBinderUnlinked events in
// mBinderEvents.
@@ -209,10 +212,12 @@
int32_t getVhalInterfaceVersion() const;
- // Gets mConfigsByPropId, lazy init it if necessary.
- const std::unordered_map<int32_t, aidlvhal::VehiclePropConfig>& getConfigsByPropId() const;
- // Gets mConfigFile, lazy init it if necessary.
- const ndk::ScopedFileDescriptor* getConfigFile() const;
+ // Gets mConfigsByPropId, lazy init it if necessary. Note that the reference is only valid in
+ // the scope of the callback and it is guaranteed that read lock is obtained during the
+ // callback.
+ void getConfigsByPropId(
+ std::function<void(const std::unordered_map<int32_t, aidlvhal::VehiclePropConfig>&)>
+ callback) const EXCLUDES(mConfigLock);
// Puts the property change events into a queue so that they can handled in batch.
static void batchPropertyChangeEvent(
@@ -239,6 +244,12 @@
static void onBinderUnlinked(void* cookie);
+ static void parseSubscribeOptions(
+ const std::vector<aidlvhal::SubscribeOptions>& options,
+ const std::unordered_map<int32_t, aidlvhal::VehiclePropConfig>& configsByPropId,
+ std::vector<aidlvhal::SubscribeOptions>& onChangeSubscriptions,
+ std::vector<aidlvhal::SubscribeOptions>& continuousSubscriptions);
+
// Test-only
// Set the default timeout for pending requests.
void setTimeout(int64_t timeoutInNano);
diff --git a/automotive/vehicle/aidl/impl/vhal/src/DefaultVehicleHal.cpp b/automotive/vehicle/aidl/impl/vhal/src/DefaultVehicleHal.cpp
index 9dc039d..e062a28 100644
--- a/automotive/vehicle/aidl/impl/vhal/src/DefaultVehicleHal.cpp
+++ b/automotive/vehicle/aidl/impl/vhal/src/DefaultVehicleHal.cpp
@@ -95,6 +95,18 @@
return sampleRateHz;
}
+class SCOPED_CAPABILITY SharedScopedLockAssertion {
+ public:
+ SharedScopedLockAssertion(std::shared_timed_mutex& mutex) ACQUIRE_SHARED(mutex) {}
+ ~SharedScopedLockAssertion() RELEASE() {}
+};
+
+class SCOPED_CAPABILITY UniqueScopedLockAssertion {
+ public:
+ UniqueScopedLockAssertion(std::shared_timed_mutex& mutex) ACQUIRE(mutex) {}
+ ~UniqueScopedLockAssertion() RELEASE() {}
+};
+
} // namespace
DefaultVehicleHal::DefaultVehicleHal(std::unique_ptr<IVehicleHardware> vehicleHardware)
@@ -355,68 +367,82 @@
}
filteredConfigs.push_back(std::move(config));
}
- for (auto& config : filteredConfigs) {
- mConfigsByPropId[config.prop] = config;
- }
- VehiclePropConfigs vehiclePropConfigs;
- vehiclePropConfigs.payloads = std::move(filteredConfigs);
- auto result = LargeParcelableBase::parcelableToStableLargeParcelable(vehiclePropConfigs);
- if (!result.ok()) {
- ALOGE("failed to convert configs to shared memory file, error: %s, code: %d",
- result.error().message().c_str(), static_cast<int>(result.error().code()));
- mConfigFile = nullptr;
- return false;
+
+ {
+ std::unique_lock<std::shared_timed_mutex> configWriteLock(mConfigLock);
+ UniqueScopedLockAssertion lockAssertion(mConfigLock);
+
+ for (auto& config : filteredConfigs) {
+ mConfigsByPropId[config.prop] = config;
+ }
+ VehiclePropConfigs vehiclePropConfigs;
+ vehiclePropConfigs.payloads = std::move(filteredConfigs);
+ auto result = LargeParcelableBase::parcelableToStableLargeParcelable(vehiclePropConfigs);
+ if (!result.ok()) {
+ ALOGE("failed to convert configs to shared memory file, error: %s, code: %d",
+ result.error().message().c_str(), static_cast<int>(result.error().code()));
+ mConfigFile = nullptr;
+ return false;
+ }
+
+ if (result.value() != nullptr) {
+ mConfigFile = std::move(result.value());
+ }
}
- if (result.value() != nullptr) {
- mConfigFile = std::move(result.value());
- }
+ mConfigInit = true;
return true;
}
-const ScopedFileDescriptor* DefaultVehicleHal::getConfigFile() const {
- std::scoped_lock lockGuard(mConfigInitLock);
+void DefaultVehicleHal::getConfigsByPropId(
+ std::function<void(const std::unordered_map<int32_t, VehiclePropConfig>&)> callback) const {
if (!mConfigInit) {
CHECK(getAllPropConfigsFromHardwareLocked())
<< "Failed to get property configs from hardware";
- mConfigInit = true;
}
- return mConfigFile.get();
-}
-const std::unordered_map<int32_t, VehiclePropConfig>& DefaultVehicleHal::getConfigsByPropId()
- const {
- std::scoped_lock lockGuard(mConfigInitLock);
- if (!mConfigInit) {
- CHECK(getAllPropConfigsFromHardwareLocked())
- << "Failed to get property configs from hardware";
- mConfigInit = true;
- }
- return mConfigsByPropId;
+ std::shared_lock<std::shared_timed_mutex> configReadLock(mConfigLock);
+ SharedScopedLockAssertion lockAssertion(mConfigLock);
+
+ callback(mConfigsByPropId);
}
ScopedAStatus DefaultVehicleHal::getAllPropConfigs(VehiclePropConfigs* output) {
- const ScopedFileDescriptor* configFile = getConfigFile();
- const auto& configsByPropId = getConfigsByPropId();
- if (configFile != nullptr) {
+ if (!mConfigInit) {
+ CHECK(getAllPropConfigsFromHardwareLocked())
+ << "Failed to get property configs from hardware";
+ }
+
+ std::shared_lock<std::shared_timed_mutex> configReadLock(mConfigLock);
+ SharedScopedLockAssertion lockAssertion(mConfigLock);
+
+ if (mConfigFile != nullptr) {
output->payloads.clear();
- output->sharedMemoryFd.set(dup(configFile->get()));
+ output->sharedMemoryFd.set(dup(mConfigFile->get()));
return ScopedAStatus::ok();
}
- output->payloads.reserve(configsByPropId.size());
- for (const auto& [_, config] : configsByPropId) {
+
+ output->payloads.reserve(mConfigsByPropId.size());
+ for (const auto& [_, config] : mConfigsByPropId) {
output->payloads.push_back(config);
}
return ScopedAStatus::ok();
}
-Result<const VehiclePropConfig*> DefaultVehicleHal::getConfig(int32_t propId) const {
- const auto& configsByPropId = getConfigsByPropId();
- auto it = configsByPropId.find(propId);
- if (it == configsByPropId.end()) {
- return Error() << "no config for property, ID: " << propId;
- }
- return &(it->second);
+Result<VehiclePropConfig> DefaultVehicleHal::getConfig(int32_t propId) const {
+ Result<VehiclePropConfig> result;
+ getConfigsByPropId([this, &result, propId](const auto& configsByPropId) {
+ SharedScopedLockAssertion lockAssertion(mConfigLock);
+
+ auto it = configsByPropId.find(propId);
+ if (it == configsByPropId.end()) {
+ result = Error() << "no config for property, ID: " << propId;
+ return;
+ }
+ // Copy the VehiclePropConfig
+ result = it->second;
+ });
+ return result;
}
Result<void> DefaultVehicleHal::checkProperty(const VehiclePropValue& propValue) {
@@ -425,15 +451,15 @@
if (!result.ok()) {
return result.error();
}
- const VehiclePropConfig* config = result.value();
- const VehicleAreaConfig* areaConfig = getAreaConfig(propValue, *config);
+ const VehiclePropConfig& config = result.value();
+ const VehicleAreaConfig* areaConfig = getAreaConfig(propValue, config);
if (!isGlobalProp(propId) && areaConfig == nullptr) {
// Ignore areaId for global property. For non global property, check whether areaId is
// allowed. areaId must appear in areaConfig.
return Error() << "invalid area ID: " << propValue.areaId << " for prop ID: " << propId
<< ", not listed in config";
}
- if (auto result = checkPropValue(propValue, config); !result.ok()) {
+ if (auto result = checkPropValue(propValue, &config); !result.ok()) {
return Error() << "invalid property value: " << propValue.toString()
<< ", error: " << getErrorMsg(result);
}
@@ -659,17 +685,27 @@
ScopedAStatus DefaultVehicleHal::getPropConfigs(const std::vector<int32_t>& props,
VehiclePropConfigs* output) {
std::vector<VehiclePropConfig> configs;
- const auto& configsByPropId = getConfigsByPropId();
- for (int32_t prop : props) {
- auto it = configsByPropId.find(prop);
- if (it != configsByPropId.end()) {
- configs.push_back(it->second);
- } else {
- return ScopedAStatus::fromServiceSpecificErrorWithMessage(
- toInt(StatusCode::INVALID_ARG),
- StringPrintf("no config for property, ID: %" PRId32, prop).c_str());
+ ScopedAStatus status = ScopedAStatus::ok();
+ getConfigsByPropId([this, &configs, &status, &props](const auto& configsByPropId) {
+ SharedScopedLockAssertion lockAssertion(mConfigLock);
+
+ for (int32_t prop : props) {
+ auto it = configsByPropId.find(prop);
+ if (it != configsByPropId.end()) {
+ configs.push_back(it->second);
+ } else {
+ status = ScopedAStatus::fromServiceSpecificErrorWithMessage(
+ toInt(StatusCode::INVALID_ARG),
+ StringPrintf("no config for property, ID: %" PRId32, prop).c_str());
+ return;
+ }
}
+ });
+
+ if (!status.isOk()) {
+ return status;
}
+
return vectorToStableLargeParcelable(std::move(configs), output);
}
@@ -691,8 +727,8 @@
}
VhalResult<void> DefaultVehicleHal::checkSubscribeOptions(
- const std::vector<SubscribeOptions>& options) {
- const auto& configsByPropId = getConfigsByPropId();
+ const std::vector<SubscribeOptions>& options,
+ const std::unordered_map<int32_t, VehiclePropConfig>& configsByPropId) {
for (const auto& option : options) {
int32_t propId = option.propId;
auto it = configsByPropId.find(propId);
@@ -757,23 +793,15 @@
}
}
}
+
return {};
}
-ScopedAStatus DefaultVehicleHal::subscribe(const CallbackType& callback,
- const std::vector<SubscribeOptions>& options,
- [[maybe_unused]] int32_t maxSharedMemoryFileCount) {
- // TODO(b/205189110): Use shared memory file count.
- if (callback == nullptr) {
- return ScopedAStatus::fromExceptionCode(EX_NULL_POINTER);
- }
- if (auto result = checkSubscribeOptions(options); !result.ok()) {
- ALOGE("subscribe: invalid subscribe options: %s", getErrorMsg(result).c_str());
- return toScopedAStatus(result);
- }
- std::vector<SubscribeOptions> onChangeSubscriptions;
- std::vector<SubscribeOptions> continuousSubscriptions;
- const auto& configsByPropId = getConfigsByPropId();
+void DefaultVehicleHal::parseSubscribeOptions(
+ const std::vector<SubscribeOptions>& options,
+ const std::unordered_map<int32_t, VehiclePropConfig>& configsByPropId,
+ std::vector<SubscribeOptions>& onChangeSubscriptions,
+ std::vector<SubscribeOptions>& continuousSubscriptions) {
for (const auto& option : options) {
int32_t propId = option.propId;
// We have already validate config exists.
@@ -831,6 +859,34 @@
onChangeSubscriptions.push_back(std::move(optionCopy));
}
}
+}
+
+ScopedAStatus DefaultVehicleHal::subscribe(const CallbackType& callback,
+ const std::vector<SubscribeOptions>& options,
+ [[maybe_unused]] int32_t maxSharedMemoryFileCount) {
+ // TODO(b/205189110): Use shared memory file count.
+ if (callback == nullptr) {
+ return ScopedAStatus::fromExceptionCode(EX_NULL_POINTER);
+ }
+ std::vector<SubscribeOptions> onChangeSubscriptions;
+ std::vector<SubscribeOptions> continuousSubscriptions;
+ ScopedAStatus returnStatus = ScopedAStatus::ok();
+ getConfigsByPropId([this, &returnStatus, &options, &onChangeSubscriptions,
+ &continuousSubscriptions](const auto& configsByPropId) {
+ SharedScopedLockAssertion lockAssertion(mConfigLock);
+
+ if (auto result = checkSubscribeOptions(options, configsByPropId); !result.ok()) {
+ ALOGE("subscribe: invalid subscribe options: %s", getErrorMsg(result).c_str());
+ returnStatus = toScopedAStatus(result);
+ return;
+ }
+ parseSubscribeOptions(options, configsByPropId, onChangeSubscriptions,
+ continuousSubscriptions);
+ });
+
+ if (!returnStatus.isOk()) {
+ return returnStatus;
+ }
{
// Lock to make sure onBinderDied would not be called concurrently.
@@ -891,13 +947,13 @@
return StatusError(StatusCode::INVALID_ARG) << getErrorMsg(result);
}
- const VehiclePropConfig* config = result.value();
- const VehicleAreaConfig* areaConfig = getAreaConfig(value, *config);
+ const VehiclePropConfig& config = result.value();
+ const VehicleAreaConfig* areaConfig = getAreaConfig(value, config);
if (areaConfig == nullptr && !isGlobalProp(propId)) {
return StatusError(StatusCode::INVALID_ARG) << "no config for area ID: " << value.areaId;
}
- if (!hasRequiredAccess(config->access, accessToTest) &&
+ if (!hasRequiredAccess(config.access, accessToTest) &&
(areaConfig == nullptr || !hasRequiredAccess(areaConfig->access, accessToTest))) {
return StatusError(StatusCode::ACCESS_DENIED)
<< StringPrintf("Property %" PRId32 " does not have the following access: %" PRId32,
@@ -966,7 +1022,6 @@
}
DumpResult result = mVehicleHardware->dump(options);
if (result.refreshPropertyConfigs) {
- std::scoped_lock lockGuard(mConfigInitLock);
getAllPropConfigsFromHardwareLocked();
}
dprintf(fd, "%s", (result.buffer + "\n").c_str());
@@ -974,11 +1029,16 @@
return STATUS_OK;
}
dprintf(fd, "Vehicle HAL State: \n");
- const auto& configsByPropId = getConfigsByPropId();
+ std::unordered_map<int32_t, VehiclePropConfig> configsByPropIdCopy;
+ getConfigsByPropId([this, &configsByPropIdCopy](const auto& configsByPropId) {
+ SharedScopedLockAssertion lockAssertion(mConfigLock);
+
+ configsByPropIdCopy = configsByPropId;
+ });
{
std::scoped_lock<std::mutex> lockGuard(mLock);
dprintf(fd, "Interface version: %" PRId32 "\n", getVhalInterfaceVersion());
- dprintf(fd, "Containing %zu property configs\n", configsByPropId.size());
+ dprintf(fd, "Containing %zu property configs\n", configsByPropIdCopy.size());
dprintf(fd, "Currently have %zu getValues clients\n", mGetValuesClients.size());
dprintf(fd, "Currently have %zu setValues clients\n", mSetValuesClients.size());
dprintf(fd, "Currently have %zu subscribe clients\n", countSubscribeClients());
diff --git a/automotive/vehicle/aidl_property/android/hardware/automotive/vehicle/VehicleProperty.aidl b/automotive/vehicle/aidl_property/android/hardware/automotive/vehicle/VehicleProperty.aidl
index 0863adf..e5c09b0 100644
--- a/automotive/vehicle/aidl_property/android/hardware/automotive/vehicle/VehicleProperty.aidl
+++ b/automotive/vehicle/aidl_property/android/hardware/automotive/vehicle/VehicleProperty.aidl
@@ -1677,6 +1677,12 @@
* For configuration information, VehiclePropConfig.configArray must have bit flag combining
* values in VehicleApPowerStateConfigFlag.
*
+ * configArray[0] : Bit flag combining values in VehicleApPowerStateConfigFlag,
+ * 0x0 if not used,
+ * 0x1 for enabling suspend to ram,
+ * 0x2 for supporting powering on AP from off state after timeout.
+ * 0x4 for enabling suspend to disk,
+ *
* int32Values[0] : VehicleApPowerStateReq enum value
* int32Values[1] : additional parameter relevant for each state,
* 0 if not used.
diff --git a/biometrics/common/aidl/Android.bp b/biometrics/common/aidl/Android.bp
index 246bcf2..4afecb4 100644
--- a/biometrics/common/aidl/Android.bp
+++ b/biometrics/common/aidl/Android.bp
@@ -22,6 +22,9 @@
cpp: {
enabled: false,
},
+ rust: {
+ enabled: true,
+ },
},
versions_with_info: [
{
diff --git a/biometrics/fingerprint/aidl/Android.bp b/biometrics/fingerprint/aidl/Android.bp
index a395c01..d0c1b8b 100644
--- a/biometrics/fingerprint/aidl/Android.bp
+++ b/biometrics/fingerprint/aidl/Android.bp
@@ -25,6 +25,9 @@
cpp: {
enabled: false,
},
+ rust: {
+ enabled: true,
+ },
},
versions_with_info: [
{
diff --git a/bluetooth/aidl/vts/VtsHalBluetoothTargetTest.cpp b/bluetooth/aidl/vts/VtsHalBluetoothTargetTest.cpp
index dcb5fac..fcf1649 100644
--- a/bluetooth/aidl/vts/VtsHalBluetoothTargetTest.cpp
+++ b/bluetooth/aidl/vts/VtsHalBluetoothTargetTest.cpp
@@ -988,7 +988,16 @@
ASSERT_EQ(status, std::future_status::ready);
}
+// @VsrTest = 5.3.14-001
+// @VsrTest = 5.3.14-002
+// @VsrTest = 5.3.14-004
TEST_P(BluetoothAidlTest, Vsr_Bluetooth5Requirements) {
+ int api_level = get_vsr_api_level();
+ if (api_level < __ANDROID_API_U__) {
+ GTEST_SKIP() << "API level is lower than 34";
+ return;
+ }
+
std::vector<uint8_t> version_event;
send_and_wait_for_cmd_complete(ReadLocalVersionInformationBuilder::Create(),
version_event);
@@ -998,10 +1007,12 @@
ASSERT_TRUE(version_view.IsValid());
ASSERT_EQ(::bluetooth::hci::ErrorCode::SUCCESS, version_view.GetStatus());
auto version = version_view.GetLocalVersionInformation();
+
if (version.hci_version_ < ::bluetooth::hci::HciVersion::V_5_0) {
- // This test does not apply to controllers below 5.0
+ GTEST_SKIP() << "Bluetooth version is lower than 5.0";
return;
- };
+ }
+
// When HCI version is 5.0, LMP version must also be at least 5.0
ASSERT_GE(static_cast<int>(version.lmp_version_),
static_cast<int>(version.hci_version_));
@@ -1014,6 +1025,16 @@
std::make_shared<std::vector<uint8_t>>(le_features_event)))));
ASSERT_TRUE(le_features_view.IsValid());
ASSERT_EQ(::bluetooth::hci::ErrorCode::SUCCESS, le_features_view.GetStatus());
+
+ // CHIPSETs that set ro.board.api_level to 34 and report 5.0 or higher for
+ // the Bluetooth version through the IBluetoothHci HAL:
+ //
+ // [VSR-5.3.14-001] Must return TRUE for
+ // - LE 2M PHY
+ // - LE Coded PHY
+ // - LE Advertising Extension
+ // - LE Periodic Advertising
+ // - LE Link Layer Privacy
auto le_features = le_features_view.GetLeFeatures();
ASSERT_TRUE(le_features & static_cast<uint64_t>(LLFeaturesBits::LL_PRIVACY));
ASSERT_TRUE(le_features & static_cast<uint64_t>(LLFeaturesBits::LE_2M_PHY));
@@ -1021,6 +1042,8 @@
static_cast<uint64_t>(LLFeaturesBits::LE_CODED_PHY));
ASSERT_TRUE(le_features &
static_cast<uint64_t>(LLFeaturesBits::LE_EXTENDED_ADVERTISING));
+ ASSERT_TRUE(le_features &
+ static_cast<uint64_t>(LLFeaturesBits::LE_PERIODIC_ADVERTISING));
std::vector<uint8_t> num_adv_set_event;
send_and_wait_for_cmd_complete(
@@ -1034,6 +1057,10 @@
ASSERT_EQ(::bluetooth::hci::ErrorCode::SUCCESS, num_adv_set_view.GetStatus());
auto num_adv_set = num_adv_set_view.GetNumberSupportedAdvertisingSets();
+ // CHIPSETs that set ro.board.api_level to 34 and report 5.0 or higher for
+ // the Bluetooth version through the IBluetoothHci HAL:
+ //
+ // [VSR-5.3.14-002] MUST support at least 10 advertising sets.
if (isTv() && get_vsr_api_level() == __ANDROID_API_U__) {
ASSERT_GE(num_adv_set, kMinLeAdvSetForBt5ForTv);
} else {
@@ -1050,6 +1077,11 @@
ASSERT_EQ(::bluetooth::hci::ErrorCode::SUCCESS,
num_resolving_list_view.GetStatus());
auto num_resolving_list = num_resolving_list_view.GetResolvingListSize();
+
+ // CHIPSETs that set ro.board.api_level to 34 and report 5.0 or higher for
+ // the Bluetooth version through the IBluetoothHci HAL:
+ //
+ // [VSR-5.3.14-004] MUST support a resolving list size of at least 8 entries.
ASSERT_GE(num_resolving_list, kMinLeResolvingListForBt5);
}
diff --git a/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.cpp b/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.cpp
index a458c5b..c62784e 100644
--- a/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.cpp
+++ b/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.cpp
@@ -145,6 +145,13 @@
<< toString(session_type_);
return;
}
+ } else if (session_type_ == SessionType::HFP_SOFTWARE_DECODING_DATAPATH ||
+ session_type_ == SessionType::HFP_SOFTWARE_ENCODING_DATAPATH) {
+ if (audio_config.getTag() != AudioConfiguration::pcmConfig) {
+ LOG(ERROR) << __func__ << " invalid audio config type for SessionType ="
+ << toString(session_type_);
+ return;
+ }
} else {
LOG(ERROR) << __func__ << " invalid SessionType ="
<< toString(session_type_);
@@ -166,6 +173,13 @@
<< toString(session_type_);
return;
}
+ } else if (session_type_ == SessionType::HFP_SOFTWARE_DECODING_DATAPATH ||
+ session_type_ == SessionType::HFP_SOFTWARE_ENCODING_DATAPATH) {
+ if (audio_config.getTag() != AudioConfiguration::pcmConfig) {
+ LOG(ERROR) << __func__ << " invalid audio config type for SessionType ="
+ << toString(session_type_);
+ return;
+ }
} else {
LOG(ERROR) << __func__
<< " invalid SessionType =" << toString(session_type_);
@@ -604,7 +618,9 @@
if (session_type_ == SessionType::A2DP_SOFTWARE_ENCODING_DATAPATH ||
session_type_ == SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH ||
session_type_ == SessionType::A2DP_SOFTWARE_DECODING_DATAPATH ||
- session_type_ == SessionType::A2DP_HARDWARE_OFFLOAD_DECODING_DATAPATH) {
+ session_type_ == SessionType::A2DP_HARDWARE_OFFLOAD_DECODING_DATAPATH ||
+ session_type_ == SessionType::HFP_SOFTWARE_ENCODING_DATAPATH ||
+ session_type_ == SessionType::HFP_SOFTWARE_DECODING_DATAPATH) {
return false;
}
@@ -629,7 +645,9 @@
if (session_type_ == SessionType::A2DP_SOFTWARE_ENCODING_DATAPATH ||
session_type_ == SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH ||
session_type_ == SessionType::A2DP_SOFTWARE_DECODING_DATAPATH ||
- session_type_ == SessionType::A2DP_HARDWARE_OFFLOAD_DECODING_DATAPATH) {
+ session_type_ == SessionType::A2DP_HARDWARE_OFFLOAD_DECODING_DATAPATH ||
+ session_type_ == SessionType::HFP_SOFTWARE_ENCODING_DATAPATH ||
+ session_type_ == SessionType::HFP_SOFTWARE_DECODING_DATAPATH) {
return false;
}
diff --git a/compatibility_matrices/bump.py b/compatibility_matrices/bump.py
index 35633c1..4e3ceaa 100755
--- a/compatibility_matrices/bump.py
+++ b/compatibility_matrices/bump.py
@@ -111,6 +111,25 @@
"kernel_configs", "-a", " ".join(next_kernel_configs), android_bp
])
+ # update the SYSTEM_MATRIX_DEPS variable and the phony module's
+ # product_variables entry.
+ lines = []
+ with open(android_bp) as f:
+ for line in f:
+ if f" \"{self.device_module_name}\",\n" in line:
+ lines.append(f" \"{self.current_module_name}\",\n")
+
+ if f" \"{self.current_module_name}\",\n" in line:
+ lines.append(f" \"{self.next_module_name}\",\n")
+ else:
+ lines.append(line)
+
+ with open(android_bp, "w") as f:
+ f.write("".join(lines))
+
+
+ # This Android.mk file may be deprecated soon and the functionality is
+ # replaced by the soong phony module system_compatibility_matrix.xml.
def edit_android_mk(self):
android_mk = self.interfaces_dir / "compatibility_matrices/Android.mk"
lines = []
diff --git a/graphics/composer/2.1/utils/command-buffer/include/composer-command-buffer/2.1/ComposerCommandBuffer.h b/graphics/composer/2.1/utils/command-buffer/include/composer-command-buffer/2.1/ComposerCommandBuffer.h
index 6a45987..9ce6eed 100644
--- a/graphics/composer/2.1/utils/command-buffer/include/composer-command-buffer/2.1/ComposerCommandBuffer.h
+++ b/graphics/composer/2.1/utils/command-buffer/include/composer-command-buffer/2.1/ComposerCommandBuffer.h
@@ -21,8 +21,7 @@
#warn "ComposerCommandBuffer.h included without LOG_TAG"
#endif
-#undef LOG_NDEBUG
-#define LOG_NDEBUG 0
+//#define LOG_NDEBUG 0
#include <algorithm>
#include <limits>
diff --git a/graphics/composer/2.2/default/Android.bp b/graphics/composer/2.2/default/Android.bp
new file mode 100644
index 0000000..5753bb0
--- /dev/null
+++ b/graphics/composer/2.2/default/Android.bp
@@ -0,0 +1,51 @@
+// Copyright (C) 2024 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package {
+ // See: http://go/android-license-faq
+ default_applicable_licenses: [
+ "hardware_interfaces_license",
+ ],
+}
+
+cc_binary {
+ name: "android.hardware.graphics.composer@2.2-service",
+ vendor: true,
+ relative_install_path: "hw",
+ cflags: [
+ "-Wall",
+ "-Werror",
+ "-DLOG_TAG=\"ComposerHal\"",
+ ],
+ srcs: ["service.cpp"],
+ init_rc: ["android.hardware.graphics.composer@2.2-service.rc"],
+ header_libs: ["android.hardware.graphics.composer@2.2-passthrough"],
+ shared_libs: [
+ "android.hardware.graphics.composer@2.1",
+ "android.hardware.graphics.composer@2.2",
+ "android.hardware.graphics.composer@2.1-resources",
+ "android.hardware.graphics.composer@2.2-resources",
+ "libbase",
+ "libbinder",
+ "libcutils",
+ "libfmq",
+ "libhardware",
+ "libhidlbase",
+ "libhwc2on1adapter",
+ "libhwc2onfbadapter",
+ "liblog",
+ "libsync",
+ "libutils",
+ ],
+}
diff --git a/graphics/composer/2.2/default/Android.mk b/graphics/composer/2.2/default/Android.mk
deleted file mode 100644
index 6f7ef85..0000000
--- a/graphics/composer/2.2/default/Android.mk
+++ /dev/null
@@ -1,35 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := android.hardware.graphics.composer@2.2-service
-LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0
-LOCAL_LICENSE_CONDITIONS := notice
-LOCAL_NOTICE_FILE := $(LOCAL_PATH)/../../../../NOTICE
-LOCAL_VENDOR_MODULE := true
-LOCAL_MODULE_RELATIVE_PATH := hw
-LOCAL_CFLAGS := -Wall -Werror -DLOG_TAG=\"ComposerHal\"
-LOCAL_SRC_FILES := service.cpp
-LOCAL_INIT_RC := android.hardware.graphics.composer@2.2-service.rc
-LOCAL_HEADER_LIBRARIES := android.hardware.graphics.composer@2.2-passthrough
-LOCAL_SHARED_LIBRARIES := \
- android.hardware.graphics.composer@2.1 \
- android.hardware.graphics.composer@2.2 \
- android.hardware.graphics.composer@2.1-resources \
- android.hardware.graphics.composer@2.2-resources \
- libbase \
- libbinder \
- libcutils \
- libfmq \
- libhardware \
- libhidlbase \
- libhwc2on1adapter \
- libhwc2onfbadapter \
- liblog \
- libsync \
- libutils
-
-ifdef TARGET_USES_DISPLAY_RENDER_INTENTS
-LOCAL_CFLAGS += -DUSES_DISPLAY_RENDER_INTENTS
-endif
-
-include $(BUILD_EXECUTABLE)
diff --git a/graphics/composer/2.2/utils/command-buffer/include/composer-command-buffer/2.2/ComposerCommandBuffer.h b/graphics/composer/2.2/utils/command-buffer/include/composer-command-buffer/2.2/ComposerCommandBuffer.h
index 00f427a..cd47374 100644
--- a/graphics/composer/2.2/utils/command-buffer/include/composer-command-buffer/2.2/ComposerCommandBuffer.h
+++ b/graphics/composer/2.2/utils/command-buffer/include/composer-command-buffer/2.2/ComposerCommandBuffer.h
@@ -20,8 +20,7 @@
#warn "ComposerCommandBuffer.h included without LOG_TAG"
#endif
-#undef LOG_NDEBUG
-#define LOG_NDEBUG 0
+//#define LOG_NDEBUG 0
#include <algorithm>
#include <limits>
diff --git a/graphics/composer/2.3/utils/command-buffer/include/composer-command-buffer/2.3/ComposerCommandBuffer.h b/graphics/composer/2.3/utils/command-buffer/include/composer-command-buffer/2.3/ComposerCommandBuffer.h
index 5e9a287..1a9276c 100644
--- a/graphics/composer/2.3/utils/command-buffer/include/composer-command-buffer/2.3/ComposerCommandBuffer.h
+++ b/graphics/composer/2.3/utils/command-buffer/include/composer-command-buffer/2.3/ComposerCommandBuffer.h
@@ -20,8 +20,7 @@
#warn "ComposerCommandBuffer.h included without LOG_TAG"
#endif
-#undef LOG_NDEBUG
-#define LOG_NDEBUG 0
+//#define LOG_NDEBUG 0
#include <android/hardware/graphics/composer/2.3/IComposer.h>
#include <android/hardware/graphics/composer/2.3/IComposerClient.h>
diff --git a/graphics/composer/2.4/utils/command-buffer/include/composer-command-buffer/2.4/ComposerCommandBuffer.h b/graphics/composer/2.4/utils/command-buffer/include/composer-command-buffer/2.4/ComposerCommandBuffer.h
index eb35e5c..e981da6 100644
--- a/graphics/composer/2.4/utils/command-buffer/include/composer-command-buffer/2.4/ComposerCommandBuffer.h
+++ b/graphics/composer/2.4/utils/command-buffer/include/composer-command-buffer/2.4/ComposerCommandBuffer.h
@@ -20,8 +20,7 @@
#warn "ComposerCommandBuffer.h included without LOG_TAG"
#endif
-#undef LOG_NDEBUG
-#define LOG_NDEBUG 0
+//#define LOG_NDEBUG 0
#include <android/hardware/graphics/composer/2.4/IComposer.h>
#include <android/hardware/graphics/composer/2.4/IComposerClient.h>
diff --git a/keymaster/aidl/Android.bp b/keymaster/aidl/Android.bp
index 0f2debd..56997a9 100644
--- a/keymaster/aidl/Android.bp
+++ b/keymaster/aidl/Android.bp
@@ -18,6 +18,9 @@
java: {
platform_apis: true,
},
+ rust: {
+ enabled: true,
+ },
},
versions_with_info: [
{
diff --git a/nfc/aidl/aidl_api/android.hardware.nfc/current/android/hardware/nfc/NfcConfig.aidl b/nfc/aidl/aidl_api/android.hardware.nfc/current/android/hardware/nfc/NfcConfig.aidl
index 92e0a9a..0261a0a 100644
--- a/nfc/aidl/aidl_api/android.hardware.nfc/current/android/hardware/nfc/NfcConfig.aidl
+++ b/nfc/aidl/aidl_api/android.hardware.nfc/current/android/hardware/nfc/NfcConfig.aidl
@@ -49,4 +49,5 @@
byte[] offHostRouteUicc;
byte[] offHostRouteEse;
byte defaultIsoDepRoute;
+ byte[] offHostSimPipeIds = {};
}
diff --git a/nfc/aidl/android/hardware/nfc/NfcConfig.aidl b/nfc/aidl/android/hardware/nfc/NfcConfig.aidl
index 1b4fcfb..870cdbd 100644
--- a/nfc/aidl/android/hardware/nfc/NfcConfig.aidl
+++ b/nfc/aidl/android/hardware/nfc/NfcConfig.aidl
@@ -86,4 +86,8 @@
* Default IsoDep route. 0x00 if there aren't any. Refer to NCI spec.
*/
byte defaultIsoDepRoute;
+ /**
+ * Pipe IDs for UICC. Empty if not available
+ */
+ byte[] offHostSimPipeIds = {};
}
diff --git a/nfc/aidl/vts/functional/VtsAidlHalNfcTargetTest.cpp b/nfc/aidl/vts/functional/VtsAidlHalNfcTargetTest.cpp
index 12f4364..6e6ca3e 100644
--- a/nfc/aidl/vts/functional/VtsAidlHalNfcTargetTest.cpp
+++ b/nfc/aidl/vts/functional/VtsAidlHalNfcTargetTest.cpp
@@ -423,6 +423,11 @@
EXPECT_GE((uint8_t)configValue.defaultIsoDepRoute, MIN_OFFHOST_ROUTE_ID);
EXPECT_LE((uint8_t)configValue.defaultIsoDepRoute, MAX_OFFHOST_ROUTE_ID);
}
+ for (auto simPipeId : configValue.offHostSimPipeIds) {
+ LOG(INFO) << StringPrintf("offHostSimPipeId= %x", simPipeId);
+ EXPECT_GE(simPipeId, MIN_OFFHOST_ROUTE_ID);
+ EXPECT_LE(simPipeId, MAX_OFFHOST_ROUTE_ID);
+ }
}
/*
diff --git a/security/rkp/OWNERS b/security/rkp/OWNERS
index d25977f..8f854b4 100644
--- a/security/rkp/OWNERS
+++ b/security/rkp/OWNERS
@@ -2,4 +2,3 @@
jbires@google.com
sethmo@google.com
-trong@google.com
diff --git a/security/rkp/aidl/android/hardware/security/keymint/generateCertificateRequestV2.cddl b/security/rkp/aidl/android/hardware/security/keymint/generateCertificateRequestV2.cddl
index 40cf685..7a02ff5 100644
--- a/security/rkp/aidl/android/hardware/security/keymint/generateCertificateRequestV2.cddl
+++ b/security/rkp/aidl/android/hardware/security/keymint/generateCertificateRequestV2.cddl
@@ -63,7 +63,7 @@
UdsCertChain = [
+ X509Certificate ; Root -> ... -> Leaf. "Root" is the vendor self-signed
- ; cert, "Leaf" contains UDS_Public. It's recommended to
+ ; cert, "Leaf" contains UDS_Pub. It's recommended to
; have at least 3 certificates in the chain.
; The Root certificate is recommended to be generated in an air-gapped,
; HSM-based secure environment. The intermediate signing keys may be
@@ -77,7 +77,7 @@
; The DICE Chain contains measurements about the device firmware.
; The first entry in the DICE Chain is the UDS_Pub, encoded as a COSE_key. All entries
; after the first describe a link in the boot chain (e.g. bootloaders: BL1, BL2, ... BLN)
-; Note that there is no DiceChainEntry for UDS_pub, only a "bare" COSE_key.
+; Note that there is no DiceChainEntry for UDS_Pub, only a "bare" COSE_key.
DiceCertChain = [
PubKeyEd25519 / PubKeyECDSA256 / PubKeyECDSA384, ; UDS_Pub
+ DiceChainEntry, ; First CDI_Certificate -> Last CDI_Certificate
diff --git a/threadnetwork/aidl/default/socket_interface.cpp b/threadnetwork/aidl/default/socket_interface.cpp
index a5aa2b4..71c6b4f 100644
--- a/threadnetwork/aidl/default/socket_interface.cpp
+++ b/threadnetwork/aidl/default/socket_interface.cpp
@@ -36,6 +36,7 @@
#include <vector>
#include "common/code_utils.hpp"
+#include "openthread/error.h"
#include "openthread/openthread-system.h"
#include "platform-posix.h"
@@ -56,14 +57,9 @@
otError SocketInterface::Init(ReceiveFrameCallback aCallback, void* aCallbackContext,
RxFrameBuffer& aFrameBuffer) {
- otError error = OT_ERROR_NONE;
+ otError error = InitSocket();
- VerifyOrExit(mSockFd == -1, error = OT_ERROR_ALREADY);
-
- WaitForSocketFileCreated(mRadioUrl.GetPath());
-
- mSockFd = OpenFile(mRadioUrl);
- VerifyOrExit(mSockFd != -1, error = OT_ERROR_FAILED);
+ VerifyOrExit(error == OT_ERROR_NONE);
mReceiveFrameCallback = aCallback;
mReceiveFrameContext = aCallbackContext;
@@ -155,9 +151,22 @@
VerifyOrExit(!mIsHardwareResetting, error = OT_ERROR_FAILED);
- WaitForSocketFileCreated(mRadioUrl.GetPath());
- mSockFd = OpenFile(mRadioUrl);
- VerifyOrExit(mSockFd != -1, error = OT_ERROR_FAILED);
+exit:
+ return error;
+}
+
+otError SocketInterface::InitSocket() {
+ otError error = OT_ERROR_NONE;
+ int retries = 0;
+
+ VerifyOrExit(mSockFd == -1, error = OT_ERROR_ALREADY);
+
+ while (retries++ < kMaxRetriesForSocketInit) {
+ WaitForSocketFileCreated(mRadioUrl.GetPath());
+ mSockFd = OpenFile(mRadioUrl);
+ VerifyOrExit(mSockFd == -1);
+ }
+ error = OT_ERROR_FAILED;
exit:
return error;
@@ -168,11 +177,16 @@
assert(context != nullptr);
+ VerifyOrExit(mSockFd != -1);
+
FD_SET(mSockFd, &context->mReadFdSet);
if (context->mMaxFd < mSockFd) {
context->mMaxFd = mSockFd;
}
+
+exit:
+ return;
}
void SocketInterface::Process(const void* aMainloopContext) {
@@ -181,9 +195,14 @@
assert(context != nullptr);
+ VerifyOrExit(mSockFd != -1);
+
if (FD_ISSET(mSockFd, &context->mReadFdSet)) {
Read();
}
+
+exit:
+ return;
}
otError SocketInterface::HardwareReset(void) {
@@ -198,22 +217,24 @@
void SocketInterface::Read(void) {
uint8_t buffer[kMaxFrameSize];
+ ssize_t rval;
- ssize_t rval = TEMP_FAILURE_RETRY(read(mSockFd, buffer, sizeof(buffer)));
+ VerifyOrExit(mSockFd != -1);
+
+ rval = TEMP_FAILURE_RETRY(read(mSockFd, buffer, sizeof(buffer)));
if (rval > 0) {
ProcessReceivedData(buffer, static_cast<uint16_t>(rval));
} else if (rval < 0) {
DieNow(OT_EXIT_ERROR_ERRNO);
} else {
- if (mIsHardwareResetting) {
- LogInfo("Socket connection is closed due to hardware reset.");
- ResetStates();
- } else {
- LogCrit("Socket connection is closed by remote.");
- exit(OT_EXIT_FAILURE);
- }
+ LogWarn("Socket connection is closed by remote, isHardwareReset: %d", mIsHardwareResetting);
+ ResetStates();
+ InitSocket();
}
+
+exit:
+ return;
}
void SocketInterface::Write(const uint8_t* aFrame, uint16_t aLength) {
diff --git a/threadnetwork/aidl/default/socket_interface.hpp b/threadnetwork/aidl/default/socket_interface.hpp
index 494d76a..83c86e8 100644
--- a/threadnetwork/aidl/default/socket_interface.hpp
+++ b/threadnetwork/aidl/default/socket_interface.hpp
@@ -247,6 +247,15 @@
otError WaitForHardwareResetCompletion(uint32_t aTimeoutMs);
/**
+ * Initialize socket
+ *
+ * @retval TRUE Socket initialization is successful.
+ * @retval FALSE Socket initialization is failed.
+ *
+ */
+ otError InitSocket();
+
+ /**
* Reset socket interface to intitial state.
*
*/
@@ -257,6 +266,7 @@
///< descriptor to become available.
kMaxRetriesForSocketCloseCheck = 3, ///< Maximum retry times for checking
///< if socket is closed.
+ kMaxRetriesForSocketInit = 3, ///< Maximum retry times for socket initialization.
};
ReceiveFrameCallback mReceiveFrameCallback;
diff --git a/uwb/aidl/default/Android.bp b/uwb/aidl/default/Android.bp
index eba18cf..037eac3 100644
--- a/uwb/aidl/default/Android.bp
+++ b/uwb/aidl/default/Android.bp
@@ -16,17 +16,13 @@
prefer_rlib: true,
rustlibs: [
"android.hardware.uwb-V1-rust",
- "liblibc",
"liblogger",
"liblog_rust",
"libbinder_rs",
"libbinder_tokio_rs",
"libtokio",
- "libtokio_util",
"libnix",
"libanyhow",
- "libpdl_runtime",
- "libuwb_uci_packets",
],
proc_macros: [
"libasync_trait",
diff --git a/uwb/aidl/default/src/service.rs b/uwb/aidl/default/src/service.rs
index e97b291..80fa8af 100644
--- a/uwb/aidl/default/src/service.rs
+++ b/uwb/aidl/default/src/service.rs
@@ -1,8 +1,6 @@
use android_hardware_uwb::aidl::android::hardware::uwb::IUwb::{self, IUwb as _};
use android_hardware_uwb::binder;
-use tokio::runtime::Runtime;
-
use std::env;
use std::panic;
@@ -25,13 +23,12 @@
log::info!("UWB HAL starting up");
- // Create the tokio runtime
- let rt = Runtime::new()?;
+ let rt = tokio::runtime::Runtime::new()?;
let chips = env::args()
.skip(1) // Skip binary name
.enumerate()
- .map(|(i, arg)| uwb_chip::UwbChip::new(i.to_string(), arg));
+ .map(|(i, arg)| rt.block_on(uwb_chip::UwbChip::new(i.to_string(), arg)));
binder::add_service(
&format!("{}/default", IUwb::BpUwb::get_descriptor()),
diff --git a/uwb/aidl/default/src/uwb_chip.rs b/uwb/aidl/default/src/uwb_chip.rs
index 956cf6c..0ed05d8 100644
--- a/uwb/aidl/default/src/uwb_chip.rs
+++ b/uwb/aidl/default/src/uwb_chip.rs
@@ -7,126 +7,113 @@
use binder::{DeathRecipient, IBinder, Result, Strong};
use std::sync::Arc;
-use tokio::io::unix::AsyncFd;
-use tokio::select;
+use tokio::fs;
+use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::sync::Mutex;
-use tokio_util::sync::CancellationToken;
-use std::fs::{File, OpenOptions};
-use std::io::{self, Read, Write};
-use std::os::unix::fs::OpenOptionsExt;
-
-use pdl_runtime::Packet;
-use uwb_uci_packets::{DeviceResetCmdBuilder, ResetConfig, UciControlPacket, UciControlPacketHal};
-
-enum State {
+enum ClientState {
Closed,
Opened {
callbacks: Strong<dyn IUwbClientCallback>,
- handle: tokio::task::JoinHandle<()>,
- serial: File,
- death_recipient: DeathRecipient,
- token: CancellationToken,
+ _death_recipient: DeathRecipient,
},
}
+struct ServiceState {
+ client_state: ClientState,
+ writer: fs::File,
+}
+
pub struct UwbChip {
name: String,
- path: String,
- state: Arc<Mutex<State>>,
+ _handle: tokio::task::JoinHandle<()>,
+ service_state: Arc<Mutex<ServiceState>>,
}
-impl UwbChip {
- pub fn new(name: String, path: String) -> Self {
- Self {
- name,
- path,
- state: Arc::new(Mutex::new(State::Closed)),
- }
- }
-}
-
-impl State {
- /// Terminate the reader task.
- async fn close(&mut self) -> Result<()> {
- if let State::Opened {
- ref mut token,
- ref callbacks,
- ref mut death_recipient,
- ref mut handle,
- ref mut serial,
- } = *self
- {
- log::info!("waiting for task cancellation");
- callbacks.as_binder().unlink_to_death(death_recipient)?;
- token.cancel();
- handle.await.unwrap();
- let packet: UciControlPacket = DeviceResetCmdBuilder {
- reset_config: ResetConfig::UwbsReset,
- }
- .build()
- .into();
- // DeviceResetCmd need to be send to reset the device to stop all running
- // activities on UWBS.
- let packet_vec: Vec<UciControlPacketHal> = packet.into();
- for hal_packet in packet_vec.into_iter() {
- serial
- .write(&hal_packet.encode_to_vec().unwrap())
- .map(|written| written as i32)
- .map_err(|_| binder::StatusCode::UNKNOWN_ERROR)?;
- }
- consume_device_reset_rsp_and_ntf(
- &mut serial
- .try_clone()
- .map_err(|_| binder::StatusCode::UNKNOWN_ERROR)?,
- );
- log::info!("task successfully cancelled");
- callbacks.onHalEvent(UwbEvent::CLOSE_CPLT, UwbStatus::OK)?;
- *self = State::Closed;
- }
- Ok(())
- }
-}
-
-fn consume_device_reset_rsp_and_ntf(reader: &mut File) {
- // Poll the DeviceResetRsp and DeviceStatusNtf before hal is closed to prevent
- // the host from getting response and notifications from a 'powered down' UWBS.
- // Do nothing when these packets are received.
- const DEVICE_RESET_RSP: [u8; 5] = [64, 0, 0, 1, 0];
- const DEVICE_STATUS_NTF: [u8; 5] = [96, 1, 0, 1, 1];
- let mut buffer = vec![0; DEVICE_RESET_RSP.len() + DEVICE_STATUS_NTF.len()];
- read_exact(reader, &mut buffer).unwrap();
-
- // Make sure received packets are the expected ones.
- assert_eq!(&buffer[0..DEVICE_RESET_RSP.len()], &DEVICE_RESET_RSP);
- assert_eq!(&buffer[DEVICE_RESET_RSP.len()..], &DEVICE_STATUS_NTF);
-}
-
-pub fn makeraw(file: File) -> io::Result<File> {
- // Configure the file descriptor as raw fd.
+/// Configure a file descriptor as raw fd.
+pub fn makeraw(file: fs::File) -> std::io::Result<fs::File> {
use nix::sys::termios::*;
let mut attrs = tcgetattr(&file)?;
cfmakeraw(&mut attrs);
tcsetattr(&file, SetArg::TCSANOW, &attrs)?;
-
Ok(file)
}
-/// Wrapper around Read::read to handle EWOULDBLOCK.
-/// /!\ will actively wait for more data, make sure to call
-/// this method only when data is immediately expected.
-fn read_exact(file: &mut File, mut buf: &mut [u8]) -> io::Result<()> {
- while buf.len() > 0 {
- match file.read(buf) {
- Ok(0) => panic!("unexpectedly reached end of file"),
- Ok(read_len) => buf = &mut buf[read_len..],
- Err(err) if err.kind() == io::ErrorKind::WouldBlock => continue,
- Err(err) => return Err(err),
+impl UwbChip {
+ pub async fn new(name: String, path: String) -> Self {
+ // Open the serial file and configure it as raw file
+ // descriptor.
+ let mut reader = fs::OpenOptions::new()
+ .read(true)
+ .write(true)
+ .create(false)
+ .open(&path)
+ .await
+ .and_then(makeraw)
+ .expect("failed to open the serial device");
+ let writer = reader
+ .try_clone()
+ .await
+ .expect("failed to clone serial for writing");
+
+ // Create the chip
+ let service_state = Arc::new(Mutex::new(ServiceState {
+ writer,
+ client_state: ClientState::Closed,
+ }));
+
+ // Spawn the task that will run the polling loop.
+ let handle = {
+ let service_state = service_state.clone();
+
+ tokio::task::spawn(async move {
+ log::info!("UCI reader task started");
+
+ const MESSAGE_TYPE_MASK: u8 = 0b11100000;
+ const DATA_MESSAGE_TYPE: u8 = 0b000;
+ const UCI_HEADER_SIZE: usize = 4;
+ const UCI_BUFFER_SIZE: usize = 1024;
+
+ let mut buffer = [0; UCI_BUFFER_SIZE];
+
+ loop {
+ reader
+ .read_exact(&mut buffer[0..UCI_HEADER_SIZE])
+ .await
+ .expect("failed to read uci header bytes");
+ let common_header = buffer[0];
+ let mt = (common_header & MESSAGE_TYPE_MASK) >> 5;
+ let payload_length = if mt == DATA_MESSAGE_TYPE {
+ u16::from_le_bytes([buffer[2], buffer[3]]) as usize
+ } else {
+ buffer[3] as usize
+ };
+
+ let total_packet_length = payload_length + UCI_HEADER_SIZE;
+ reader
+ .read_exact(&mut buffer[UCI_HEADER_SIZE..total_packet_length])
+ .await
+ .expect("failed to read uci payload bytes");
+
+ log::debug!(" <-- {:?}", &buffer[0..total_packet_length]);
+
+ let service_state = service_state.lock().await;
+ if let ClientState::Opened { ref callbacks, .. } = service_state.client_state {
+ callbacks
+ .onUciMessage(&buffer[0..total_packet_length])
+ .unwrap();
+ }
+ }
+ })
+ };
+
+ Self {
+ name,
+ _handle: handle,
+ service_state,
}
}
- Ok(())
}
-
impl binder::Interface for UwbChip {}
#[async_trait]
@@ -136,124 +123,30 @@
}
async fn open(&self, callbacks: &Strong<dyn IUwbClientCallback>) -> Result<()> {
- log::debug!("open: {:?}", &self.path);
+ log::debug!("open");
- let mut state = self.state.lock().await;
+ let mut service_state = self.service_state.lock().await;
- if matches!(*state, State::Opened { .. }) {
+ if matches!(service_state.client_state, ClientState::Opened { .. }) {
log::error!("the state is already opened");
return Err(binder::ExceptionCode::ILLEGAL_STATE.into());
}
- let serial = OpenOptions::new()
- .read(true)
- .write(true)
- .create(false)
- .custom_flags(libc::O_NONBLOCK)
- .open(&self.path)
- .and_then(makeraw)
- .map_err(|_| binder::StatusCode::UNKNOWN_ERROR)?;
-
- let state_death_recipient = self.state.clone();
- let mut death_recipient = DeathRecipient::new(move || {
- let mut state = state_death_recipient.blocking_lock();
- log::info!("Uwb service has died");
- if let State::Opened { ref mut token, .. } = *state {
- token.cancel();
- *state = State::Closed;
- }
- });
+ let mut death_recipient = {
+ let service_state = self.service_state.clone();
+ DeathRecipient::new(move || {
+ log::info!("Uwb service has died");
+ let mut service_state = service_state.blocking_lock();
+ service_state.client_state = ClientState::Closed;
+ })
+ };
callbacks.as_binder().link_to_death(&mut death_recipient)?;
-
- let token = CancellationToken::new();
- let cloned_token = token.clone();
-
- let client_callbacks = callbacks.clone();
-
- let reader = serial
- .try_clone()
- .map_err(|_| binder::StatusCode::UNKNOWN_ERROR)?;
-
- let join_handle = tokio::task::spawn(async move {
- log::info!("UCI reader task started");
- let mut reader = AsyncFd::new(reader).unwrap();
-
- loop {
- const MESSAGE_TYPE_MASK: u8 = 0b11100000;
- const DATA_MESSAGE_TYPE: u8 = 0b000;
- const UWB_HEADER_SIZE: usize = 4;
- let mut buffer = vec![0; UWB_HEADER_SIZE];
-
- // The only time where the task can be safely
- // cancelled is when no packet bytes have been read.
- //
- // - read_exact() cannot be used here since it is not
- // cancellation safe.
- // - read() cannot be used because it cannot be cancelled:
- // the syscall is executed blocking on the threadpool
- // and completes after termination of the task when
- // the pipe receives more data.
- let read_len = loop {
- // On some platforms, the readiness detecting mechanism
- // relies on edge-triggered notifications. This means that
- // the OS will only notify Tokio when the file descriptor
- // transitions from not-ready to ready. For this to work
- // you should first try to read or write and only poll for
- // readiness if that fails with an error of
- // std::io::ErrorKind::WouldBlock.
- match reader.get_mut().read(&mut buffer) {
- Ok(0) => {
- log::error!("file unexpectedly closed");
- return;
- }
- Ok(read_len) => break read_len,
- Err(err) if err.kind() == io::ErrorKind::WouldBlock => (),
- Err(_) => panic!("unexpected read failure"),
- }
-
- let mut guard = select! {
- _ = cloned_token.cancelled() => {
- log::info!("task is cancelled!");
- return;
- },
- result = reader.readable() => result.unwrap()
- };
-
- guard.clear_ready();
- };
-
- // Read the remaining header bytes, if truncated.
- read_exact(reader.get_mut(), &mut buffer[read_len..]).unwrap();
-
- let common_header = buffer[0];
- let mt = (common_header & MESSAGE_TYPE_MASK) >> 5;
- let payload_length = if mt == DATA_MESSAGE_TYPE {
- let payload_length_fields: [u8; 2] = buffer[2..=3].try_into().unwrap();
- u16::from_le_bytes(payload_length_fields) as usize
- } else {
- buffer[3] as usize
- };
-
- let length = payload_length + UWB_HEADER_SIZE;
- buffer.resize(length, 0);
-
- // Read the payload bytes.
- read_exact(reader.get_mut(), &mut buffer[UWB_HEADER_SIZE..]).unwrap();
-
- log::debug!(" <-- {:?}", buffer);
- client_callbacks.onUciMessage(&buffer).unwrap();
- }
- });
-
callbacks.onHalEvent(UwbEvent::OPEN_CPLT, UwbStatus::OK)?;
- *state = State::Opened {
+ service_state.client_state = ClientState::Opened {
callbacks: callbacks.clone(),
- handle: join_handle,
- serial,
- death_recipient,
- token,
+ _death_recipient: death_recipient,
};
Ok(())
@@ -262,19 +155,42 @@
async fn close(&self) -> Result<()> {
log::debug!("close");
- let mut state = self.state.lock().await;
+ let mut service_state = self.service_state.lock().await;
- if let State::Opened { .. } = *state {
- state.close().await
- } else {
- Err(binder::ExceptionCode::ILLEGAL_STATE.into())
+ if matches!(service_state.client_state, ClientState::Closed) {
+ log::error!("the state is already closed");
+ return Err(binder::ExceptionCode::ILLEGAL_STATE.into());
}
+
+ // Send the command Device Reset to stop all running activities
+ // on the UWBS emulator. This is necessary because the emulator
+ // is otherwise not notified of the power down (the serial stays
+ // open).
+ //
+ // The response to the command will be dropped by the polling loop,
+ // as the callbacks will have been removed then.
+ let uci_core_device_reset_cmd = [0x20, 0x00, 0x00, 0x01, 0x00];
+
+ service_state
+ .writer
+ .write_all(&uci_core_device_reset_cmd)
+ .await
+ .expect("failed to write UCI Device Reset command");
+
+ if let ClientState::Opened { ref callbacks, .. } = service_state.client_state {
+ callbacks.onHalEvent(UwbEvent::CLOSE_CPLT, UwbStatus::OK)?;
+ }
+
+ service_state.client_state = ClientState::Closed;
+ Ok(())
}
async fn coreInit(&self) -> Result<()> {
log::debug!("coreInit");
- if let State::Opened { ref callbacks, .. } = *self.state.lock().await {
+ let service_state = self.service_state.lock().await;
+
+ if let ClientState::Opened { ref callbacks, .. } = service_state.client_state {
callbacks.onHalEvent(UwbEvent::POST_INIT_CPLT, UwbStatus::OK)?;
Ok(())
} else {
@@ -289,22 +205,27 @@
}
async fn getSupportedAndroidUciVersion(&self) -> Result<i32> {
+ log::debug!("getSupportedAndroidUciVersion");
+
Ok(1)
}
async fn sendUciMessage(&self, data: &[u8]) -> Result<i32> {
log::debug!("sendUciMessage");
- if let State::Opened { ref mut serial, .. } = &mut *self.state.lock().await {
- log::debug!(" --> {:?}", data);
- let result = serial
- .write_all(data)
- .map(|_| data.len() as i32)
- .map_err(|_| binder::StatusCode::UNKNOWN_ERROR.into());
- log::debug!(" status: {:?}", result);
- result
- } else {
- Err(binder::ExceptionCode::ILLEGAL_STATE.into())
+ let mut service_state = self.service_state.lock().await;
+
+ if matches!(service_state.client_state, ClientState::Closed) {
+ log::error!("the state is not opened");
+ return Err(binder::ExceptionCode::ILLEGAL_STATE.into());
}
+
+ log::debug!(" --> {:?}", data);
+ service_state
+ .writer
+ .write_all(data)
+ .await
+ .map(|_| data.len() as i32)
+ .map_err(|_| binder::StatusCode::UNKNOWN_ERROR.into())
}
}
diff --git a/vibrator/aidl/Android.bp b/vibrator/aidl/Android.bp
index b5199e2..d3b72ee 100644
--- a/vibrator/aidl/Android.bp
+++ b/vibrator/aidl/Android.bp
@@ -25,4 +25,5 @@
"1",
"2",
],
+ frozen: true,
}