Merge "DefaultVehicleHal: Add null callback checking"
diff --git a/audio/effect/all-versions/default/Android.bp b/audio/effect/all-versions/default/Android.bp
index 1e01ffb..a3c3ed6 100644
--- a/audio/effect/all-versions/default/Android.bp
+++ b/audio/effect/all-versions/default/Android.bp
@@ -30,6 +30,7 @@
],
shared_libs: [
+ "libaudioutils",
"libbase",
"libcutils",
"libeffects",
@@ -48,6 +49,7 @@
"libeffects_headers",
"libhardware_headers",
"libmedia_headers",
+ "libmediautils_headers",
],
}
diff --git a/audio/effect/all-versions/default/Effect.cpp b/audio/effect/all-versions/default/Effect.cpp
index 49f6bf2..3baafc9 100644
--- a/audio/effect/all-versions/default/Effect.cpp
+++ b/audio/effect/all-versions/default/Effect.cpp
@@ -22,13 +22,11 @@
#include "Effect.h"
#include "common/all-versions/default/EffectMap.h"
-#include <memory.h>
-
#define ATRACE_TAG ATRACE_TAG_AUDIO
-
#include <HidlUtils.h>
#include <android/log.h>
#include <media/EffectsFactoryApi.h>
+#include <mediautils/ScopedStatistics.h>
#include <util/EffectUtils.h>
#include <utils/Trace.h>
@@ -49,21 +47,27 @@
namespace {
+#define SCOPED_STATS() \
+ ::android::mediautils::ScopedStatistics scopedStatistics { \
+ std::string("EffectHal::").append(__func__), mEffectHal->mStatistics \
+ }
+
class ProcessThread : public Thread {
public:
// ProcessThread's lifespan never exceeds Effect's lifespan.
- ProcessThread(std::atomic<bool>* stop, effect_handle_t effect,
- std::atomic<audio_buffer_t*>* inBuffer, std::atomic<audio_buffer_t*>* outBuffer,
- Effect::StatusMQ* statusMQ, EventFlag* efGroup)
- : Thread(false /*canCallJava*/),
- mStop(stop),
- mEffect(effect),
- mHasProcessReverse((*mEffect)->process_reverse != NULL),
- mInBuffer(inBuffer),
- mOutBuffer(outBuffer),
- mStatusMQ(statusMQ),
- mEfGroup(efGroup) {}
- virtual ~ProcessThread() {}
+ ProcessThread(std::atomic<bool>* stop, effect_handle_t effect,
+ std::atomic<audio_buffer_t*>* inBuffer, std::atomic<audio_buffer_t*>* outBuffer,
+ Effect::StatusMQ* statusMQ, EventFlag* efGroup, Effect* effectHal)
+ : Thread(false /*canCallJava*/),
+ mStop(stop),
+ mEffect(effect),
+ mHasProcessReverse((*mEffect)->process_reverse != NULL),
+ mInBuffer(inBuffer),
+ mOutBuffer(outBuffer),
+ mStatusMQ(statusMQ),
+ mEfGroup(efGroup),
+ mEffectHal(effectHal) {}
+ virtual ~ProcessThread() {}
private:
std::atomic<bool>* mStop;
@@ -73,6 +77,7 @@
std::atomic<audio_buffer_t*>* mOutBuffer;
Effect::StatusMQ* mStatusMQ;
EventFlag* mEfGroup;
+ Effect* const mEffectHal;
bool threadLoop() override;
};
@@ -102,6 +107,9 @@
audio_buffer_t* outBuffer =
std::atomic_load_explicit(mOutBuffer, std::memory_order_relaxed);
if (inBuffer != nullptr && outBuffer != nullptr) {
+ // Time this effect process
+ SCOPED_STATS();
+
if (efState & static_cast<uint32_t>(MessageQueueFlagBits::REQUEST_PROCESS)) {
processResult = (*mEffect)->process(mEffect, inBuffer, outBuffer);
} else {
@@ -359,7 +367,7 @@
// Create and launch the thread.
mProcessThread = new ProcessThread(&mStopProcessThread, mHandle, &mHalInBufferPtr,
- &mHalOutBufferPtr, tempStatusMQ.get(), mEfGroup);
+ &mHalOutBufferPtr, tempStatusMQ.get(), mEfGroup, this);
status = mProcessThread->run("effect", PRIORITY_URGENT_AUDIO);
if (status != OK) {
ALOGW("failed to start effect processing thread: %s", strerror(-status));
@@ -749,6 +757,8 @@
if (fd.getNativeHandle() != nullptr && fd->numFds == 1) {
uint32_t cmdData = fd->data[0];
(void)sendCommand(EFFECT_CMD_DUMP, "DUMP", sizeof(cmdData), &cmdData);
+ const std::string s = mStatistics->dump();
+ if (s.size() != 0) write(cmdData, s.c_str(), s.size());
}
return Void();
}
diff --git a/audio/effect/all-versions/default/Effect.h b/audio/effect/all-versions/default/Effect.h
index f9a6796..011544d 100644
--- a/audio/effect/all-versions/default/Effect.h
+++ b/audio/effect/all-versions/default/Effect.h
@@ -29,6 +29,7 @@
#include <fmq/MessageQueue.h>
#include <hidl/MQDescriptor.h>
#include <hidl/Status.h>
+#include <mediautils/MethodStatistics.h>
#include <utils/Thread.h>
#include <hardware/audio_effect.h>
@@ -169,7 +170,11 @@
Result setParameterImpl(uint32_t paramSize, const void* paramData, uint32_t valueSize,
const void* valueData);
- private:
+ // process execution statistics
+ const std::shared_ptr<mediautils::MethodStatistics<std::string>> mStatistics =
+ std::make_shared<mediautils::MethodStatistics<std::string>>();
+
+ private:
friend struct VirtualizerEffect; // for getParameterImpl
friend struct VisualizerEffect; // to allow executing commands
diff --git a/automotive/vehicle/2.0/default/impl/vhal_v2_0/GeneratorHub.cpp b/automotive/vehicle/2.0/default/impl/vhal_v2_0/GeneratorHub.cpp
index 9be9ea7..503afd2 100644
--- a/automotive/vehicle/2.0/default/impl/vhal_v2_0/GeneratorHub.cpp
+++ b/automotive/vehicle/2.0/default/impl/vhal_v2_0/GeneratorHub.cpp
@@ -28,11 +28,18 @@
namespace impl {
-GeneratorHub::GeneratorHub(const OnHalEvent& onHalEvent)
- : mOnHalEvent(onHalEvent), mThread(&GeneratorHub::run, this) {}
+GeneratorHub::GeneratorHub(const OnHalEvent& onHalEvent) : mOnHalEvent(onHalEvent) {
+ mThread = std::thread(&GeneratorHub::run, this);
+}
GeneratorHub::~GeneratorHub() {
- mShuttingDownFlag.store(true);
+ {
+ // Even if the shared variable is atomic, it must be modified under the
+ // mutex in order to correctly publish the modification to the waiting
+ // thread.
+ std::unique_lock<std::mutex> g(mLock);
+ mShuttingDownFlag.store(true);
+ }
mCond.notify_all();
if (mThread.joinable()) {
mThread.join();
diff --git a/automotive/vehicle/aidl/impl/fake_impl/GeneratorHub/src/GeneratorHub.cpp b/automotive/vehicle/aidl/impl/fake_impl/GeneratorHub/src/GeneratorHub.cpp
index 1690c78..d815456 100644
--- a/automotive/vehicle/aidl/impl/fake_impl/GeneratorHub/src/GeneratorHub.cpp
+++ b/automotive/vehicle/aidl/impl/fake_impl/GeneratorHub/src/GeneratorHub.cpp
@@ -29,11 +29,18 @@
using ::android::base::ScopedLockAssertion;
-GeneratorHub::GeneratorHub(OnHalEvent&& onHalEvent)
- : mOnHalEvent(onHalEvent), mThread(&GeneratorHub::run, this) {}
+GeneratorHub::GeneratorHub(OnHalEvent&& onHalEvent) : mOnHalEvent(onHalEvent) {
+ mThread = std::thread(&GeneratorHub::run, this);
+}
GeneratorHub::~GeneratorHub() {
- mShuttingDownFlag.store(true);
+ {
+ // Even if the shared variable is atomic, it must be modified under the
+ // mutex in order to correctly publish the modification to the waiting
+ // thread.
+ std::unique_lock<std::mutex> lock(mGeneratorsLock);
+ mShuttingDownFlag.store(true);
+ }
mCond.notify_all();
if (mThread.joinable()) {
mThread.join();
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 a7e986b..7f9b63a 100644
--- a/automotive/vehicle/aidl/impl/fake_impl/hardware/src/FakeVehicleHardware.cpp
+++ b/automotive/vehicle/aidl/impl/fake_impl/hardware/src/FakeVehicleHardware.cpp
@@ -1339,11 +1339,15 @@
template <class CallbackType, class RequestType>
FakeVehicleHardware::PendingRequestHandler<CallbackType, RequestType>::PendingRequestHandler(
FakeVehicleHardware* hardware)
- : mHardware(hardware), mThread([this] {
- while (mRequests.waitForItems()) {
- handleRequestsOnce();
- }
- }) {}
+ : mHardware(hardware) {
+ // Don't initialize mThread in initialization list because mThread depends on mRequests and we
+ // want mRequests to be initialized first.
+ mThread = std::thread([this] {
+ while (mRequests.waitForItems()) {
+ handleRequestsOnce();
+ }
+ });
+}
template <class CallbackType, class RequestType>
void FakeVehicleHardware::PendingRequestHandler<CallbackType, RequestType>::addRequest(
diff --git a/automotive/vehicle/aidl/impl/utils/common/include/PendingRequestPool.h b/automotive/vehicle/aidl/impl/utils/common/include/PendingRequestPool.h
index 3f8db93..28cf08e 100644
--- a/automotive/vehicle/aidl/impl/utils/common/include/PendingRequestPool.h
+++ b/automotive/vehicle/aidl/impl/utils/common/include/PendingRequestPool.h
@@ -21,7 +21,6 @@
#include <android-base/result.h>
#include <android-base/thread_annotations.h>
-#include <atomic>
#include <list>
#include <mutex>
#include <thread>
@@ -85,7 +84,7 @@
std::unordered_map<const void*, std::list<PendingRequest>> mPendingRequestsByClient
GUARDED_BY(mLock);
std::thread mThread;
- std::atomic<bool> mThreadStop = false;
+ bool mThreadStop = false;
std::condition_variable mCv;
std::mutex mCvLock;
diff --git a/automotive/vehicle/aidl/impl/utils/common/src/PendingRequestPool.cpp b/automotive/vehicle/aidl/impl/utils/common/src/PendingRequestPool.cpp
index 0196edd..ab50499 100644
--- a/automotive/vehicle/aidl/impl/utils/common/src/PendingRequestPool.cpp
+++ b/automotive/vehicle/aidl/impl/utils/common/src/PendingRequestPool.cpp
@@ -39,20 +39,27 @@
} // namespace
-PendingRequestPool::PendingRequestPool(int64_t timeoutInNano)
- : mTimeoutInNano(timeoutInNano), mThread([this] {
- // [this] must be alive within this thread because destructor would wait for this thread
- // to exit.
- int64_t sleepTime = std::min(mTimeoutInNano, static_cast<int64_t>(CHECK_TIME_IN_NANO));
- std::unique_lock<std::mutex> lk(mCvLock);
- while (!mCv.wait_for(lk, std::chrono::nanoseconds(sleepTime),
- [this] { return mThreadStop.load(); })) {
- checkTimeout();
- }
- }) {}
+PendingRequestPool::PendingRequestPool(int64_t timeoutInNano) : mTimeoutInNano(timeoutInNano) {
+ mThread = std::thread([this] {
+ // [this] must be alive within this thread because destructor would wait for this thread
+ // to exit.
+ int64_t sleepTime = std::min(mTimeoutInNano, static_cast<int64_t>(CHECK_TIME_IN_NANO));
+ std::unique_lock<std::mutex> lk(mCvLock);
+ while (!mCv.wait_for(lk, std::chrono::nanoseconds(sleepTime),
+ [this] { return mThreadStop; })) {
+ checkTimeout();
+ }
+ });
+}
PendingRequestPool::~PendingRequestPool() {
- mThreadStop = true;
+ {
+ // Even if the shared variable is atomic, it must be modified under the
+ // mutex in order to correctly publish the modification to the waiting
+ // thread.
+ std::unique_lock<std::mutex> lk(mCvLock);
+ mThreadStop = true;
+ }
mCv.notify_all();
if (mThread.joinable()) {
mThread.join();
diff --git a/automotive/vehicle/aidl/impl/utils/common/src/RecurrentTimer.cpp b/automotive/vehicle/aidl/impl/utils/common/src/RecurrentTimer.cpp
index 8521c4d..fbc79fa 100644
--- a/automotive/vehicle/aidl/impl/utils/common/src/RecurrentTimer.cpp
+++ b/automotive/vehicle/aidl/impl/utils/common/src/RecurrentTimer.cpp
@@ -29,7 +29,9 @@
using ::android::base::ScopedLockAssertion;
-RecurrentTimer::RecurrentTimer() : mThread(&RecurrentTimer::loop, this) {}
+RecurrentTimer::RecurrentTimer() {
+ mThread = std::thread(&RecurrentTimer::loop, this);
+}
RecurrentTimer::~RecurrentTimer() {
{
diff --git a/biometrics/fingerprint/aidl/default/WorkerThread.cpp b/biometrics/fingerprint/aidl/default/WorkerThread.cpp
index d1a63d0..34ebb5c 100644
--- a/biometrics/fingerprint/aidl/default/WorkerThread.cpp
+++ b/biometrics/fingerprint/aidl/default/WorkerThread.cpp
@@ -31,7 +31,10 @@
WorkerThread::~WorkerThread() {
// This is a signal for threadFunc to terminate as soon as possible, and a hint for schedule
// that it doesn't need to do any work.
- mIsDestructing = true;
+ {
+ std::unique_lock<std::mutex> lock(mQueueMutex);
+ mIsDestructing = true;
+ }
mQueueCond.notify_all();
mThread.join();
}
diff --git a/bluetooth/1.0/default/test/fuzzer/bluetoothV1.0_fuzzer.cpp b/bluetooth/1.0/default/test/fuzzer/bluetoothV1.0_fuzzer.cpp
index 90cdc66..fb8df99 100644
--- a/bluetooth/1.0/default/test/fuzzer/bluetoothV1.0_fuzzer.cpp
+++ b/bluetooth/1.0/default/test/fuzzer/bluetoothV1.0_fuzzer.cpp
@@ -88,11 +88,18 @@
}
mBtHci->close();
mBtHci.clear();
+ for (size_t i = 0; i < mFdCount; ++i) {
+ if (mFdList[i]) {
+ close(mFdList[i]);
+ }
+ }
}
bool init(const uint8_t* data, size_t size);
void process();
private:
+ size_t mFdCount = 1;
+ int32_t mFdList[CH_MAX] = {0};
sp<BluetoothHci> mBtHci = nullptr;
FuzzedDataProvider* mFdp = nullptr;
};
@@ -143,17 +150,15 @@
bool shouldSetH4Protocol = mFdp->ConsumeBool();
BtVendor* btVendor = BtVendor::getInstance();
- size_t fdcount = 1;
- int32_t fdList[CH_MAX] = {0};
if (!shouldSetH4Protocol) {
- fdcount = mFdp->ConsumeIntegralInRange<size_t>(kMinFdcount, CH_MAX - 1);
+ mFdCount = mFdp->ConsumeIntegralInRange<size_t>(kMinFdcount, CH_MAX - 1);
}
- for (size_t i = 0; i < fdcount; ++i) {
- fdList[i] = open("/dev/null", O_RDWR | O_CREAT);
+ for (size_t i = 0; i < mFdCount; ++i) {
+ mFdList[i] = open("/dev/null", O_RDWR | O_CREAT);
}
- btVendor->populateFdList(fdList, fdcount);
+ btVendor->populateFdList(mFdList, mFdCount);
mBtHci->initialize(bluetoothCallback);
if (!bluetoothCallback->isInitialized) {
@@ -181,12 +186,6 @@
}
btVendor->callRemainingCbacks();
-
- for (size_t i = 0; i < fdcount; ++i) {
- if (fdList[i]) {
- close(fdList[i]);
- }
- }
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
diff --git a/broadcastradio/common/utils/WorkerThread.cpp b/broadcastradio/common/utils/WorkerThread.cpp
index 31f4d3f..dd87f53 100644
--- a/broadcastradio/common/utils/WorkerThread.cpp
+++ b/broadcastradio/common/utils/WorkerThread.cpp
@@ -31,7 +31,11 @@
return lhs.when > rhs.when;
}
-WorkerThread::WorkerThread() : mIsTerminating(false), mThread(&WorkerThread::threadLoop, this) {}
+WorkerThread::WorkerThread() : mIsTerminating(false) {
+ // putting mThread in constructor instead of initializer list
+ // to ensure all class members are init before mThread starts
+ mThread = std::thread(&WorkerThread::threadLoop, this);
+}
WorkerThread::~WorkerThread() {
{
diff --git a/graphics/composer/2.4/vts/functional/VtsHalGraphicsComposerV2_4TargetTest.cpp b/graphics/composer/2.4/vts/functional/VtsHalGraphicsComposerV2_4TargetTest.cpp
index fa294ff..35225d9 100644
--- a/graphics/composer/2.4/vts/functional/VtsHalGraphicsComposerV2_4TargetTest.cpp
+++ b/graphics/composer/2.4/vts/functional/VtsHalGraphicsComposerV2_4TargetTest.cpp
@@ -737,6 +737,39 @@
}
}
+/*
+ * Test that no two display configs are exactly the same.
+ */
+TEST_P(GraphicsComposerHidlTest, GetDisplayConfigNoRepetitions) {
+ for (const auto& display : mDisplays) {
+ std::vector<Config> configs = mComposerClient->getDisplayConfigs(display.get());
+ for (int i = 0; i < configs.size(); i++) {
+ for (int j = i + 1; j < configs.size(); j++) {
+ const int32_t width1 = mComposerClient->getDisplayAttribute_2_4(
+ display.get(), configs[i], IComposerClient::Attribute::WIDTH);
+ const int32_t height1 = mComposerClient->getDisplayAttribute_2_4(
+ display.get(), configs[i], IComposerClient::Attribute::HEIGHT);
+ const int32_t vsyncPeriod1 = mComposerClient->getDisplayAttribute_2_4(
+ display.get(), configs[i], IComposerClient::Attribute::VSYNC_PERIOD);
+ const int32_t group1 = mComposerClient->getDisplayAttribute_2_4(
+ display.get(), configs[i], IComposerClient::Attribute::CONFIG_GROUP);
+
+ const int32_t width2 = mComposerClient->getDisplayAttribute_2_4(
+ display.get(), configs[j], IComposerClient::Attribute::WIDTH);
+ const int32_t height2 = mComposerClient->getDisplayAttribute_2_4(
+ display.get(), configs[j], IComposerClient::Attribute::HEIGHT);
+ const int32_t vsyncPeriod2 = mComposerClient->getDisplayAttribute_2_4(
+ display.get(), configs[j], IComposerClient::Attribute::VSYNC_PERIOD);
+ const int32_t group2 = mComposerClient->getDisplayAttribute_2_4(
+ display.get(), configs[j], IComposerClient::Attribute::CONFIG_GROUP);
+
+ ASSERT_FALSE(width1 == width2 && height1 == height2 &&
+ vsyncPeriod1 == vsyncPeriod2 && group1 == group2);
+ }
+ }
+ }
+}
+
} // namespace
} // namespace vts
} // namespace V2_4
diff --git a/graphics/composer/aidl/vts/VtsHalGraphicsComposer3_TargetTest.cpp b/graphics/composer/aidl/vts/VtsHalGraphicsComposer3_TargetTest.cpp
index 759bfec..ece1fd3 100644
--- a/graphics/composer/aidl/vts/VtsHalGraphicsComposer3_TargetTest.cpp
+++ b/graphics/composer/aidl/vts/VtsHalGraphicsComposer3_TargetTest.cpp
@@ -2122,6 +2122,41 @@
EXPECT_TRUE(mComposerClient->setPowerMode(getPrimaryDisplayId(), PowerMode::OFF).isOk());
}
+/*
+ * Test that no two display configs are exactly the same.
+ */
+TEST_P(GraphicsComposerAidlTest, GetDisplayConfigNoRepetitions) {
+ for (const auto& display : mDisplays) {
+ const auto& [status, configs] = mComposerClient->getDisplayConfigs(display.getDisplayId());
+ for (std::vector<int>::size_type i = 0; i < configs.size(); i++) {
+ for (std::vector<int>::size_type j = i + 1; j < configs.size(); j++) {
+ const auto& [widthStatus1, width1] = mComposerClient->getDisplayAttribute(
+ display.getDisplayId(), configs[i], DisplayAttribute::WIDTH);
+ const auto& [heightStatus1, height1] = mComposerClient->getDisplayAttribute(
+ display.getDisplayId(), configs[i], DisplayAttribute::HEIGHT);
+ const auto& [vsyncPeriodStatus1, vsyncPeriod1] =
+ mComposerClient->getDisplayAttribute(display.getDisplayId(), configs[i],
+ DisplayAttribute::VSYNC_PERIOD);
+ const auto& [groupStatus1, group1] = mComposerClient->getDisplayAttribute(
+ display.getDisplayId(), configs[i], DisplayAttribute::CONFIG_GROUP);
+
+ const auto& [widthStatus2, width2] = mComposerClient->getDisplayAttribute(
+ display.getDisplayId(), configs[j], DisplayAttribute::WIDTH);
+ const auto& [heightStatus2, height2] = mComposerClient->getDisplayAttribute(
+ display.getDisplayId(), configs[j], DisplayAttribute::HEIGHT);
+ const auto& [vsyncPeriodStatus2, vsyncPeriod2] =
+ mComposerClient->getDisplayAttribute(display.getDisplayId(), configs[j],
+ DisplayAttribute::VSYNC_PERIOD);
+ const auto& [groupStatus2, group2] = mComposerClient->getDisplayAttribute(
+ display.getDisplayId(), configs[j], DisplayAttribute::CONFIG_GROUP);
+
+ ASSERT_FALSE(width1 == width2 && height1 == height2 &&
+ vsyncPeriod1 == vsyncPeriod2 && group1 == group2);
+ }
+ }
+ }
+}
+
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsComposerAidlCommandTest);
INSTANTIATE_TEST_SUITE_P(
PerInstance, GraphicsComposerAidlCommandTest,
diff --git a/security/keymint/aidl/android/hardware/security/keymint/RpcHardwareInfo.aidl b/security/keymint/aidl/android/hardware/security/keymint/RpcHardwareInfo.aidl
index 3a4c233..0cb33ce 100644
--- a/security/keymint/aidl/android/hardware/security/keymint/RpcHardwareInfo.aidl
+++ b/security/keymint/aidl/android/hardware/security/keymint/RpcHardwareInfo.aidl
@@ -59,13 +59,17 @@
* client should NOT interpret the content of the identifier in any way. The client can only
* compare identifiers to determine if two IRemotelyProvisionedComponents share the same
* implementation. Each IRemotelyProvisionedComponent implementation must have a distinct
- * identifier from all other implementations on the same device.
+ * identifier from all other implementations, and it must be consistent across all devices.
+ * It's critical that this identifier not be usable to uniquely identify a specific device.
*
* This identifier must be consistent across reboots, as it is used to store and track
* provisioned keys in a persistent, on-device database.
*
* uniqueId may not be empty, and must not be any longer than 32 characters.
*
+ * A recommended construction for this value is "[Vendor] [Component Name] [Major Version]",
+ * e.g. "Google Trusty KeyMint 1".
+ *
* This field was added in API version 2.
*
*/