diff options
author | Scott Lobdell <slobdell@google.com> | 2022-04-22 23:23:53 +0000 |
---|---|---|
committer | Scott Lobdell <slobdell@google.com> | 2022-04-22 23:38:48 +0000 |
commit | c4629b765b60019d07e1fa54668c5ff0c0e4fd5b (patch) | |
tree | 7dbe50a267bc1371faee4b1a7425e83bba11d956 /sensors | |
parent | 9051e9b8460571e92d870afd584e06e1621800f7 (diff) | |
parent | 863fd304319a648f5e294892c3f2b3367dad40de (diff) |
Merge TP1A.220414.003
Change-Id: Id8894d5b946744d159e41f802b49bc770b28e4b5
Diffstat (limited to 'sensors')
-rw-r--r-- | sensors/aidl/android/hardware/sensors/ISensors.aidl | 5 | ||||
-rw-r--r-- | sensors/aidl/default/multihal/HalProxyAidl.cpp | 241 | ||||
-rw-r--r-- | sensors/aidl/default/multihal/include/HalProxyAidl.h | 2 | ||||
-rw-r--r-- | sensors/aidl/vts/VtsAidlHalSensorsTargetTest.cpp | 26 |
4 files changed, 156 insertions, 118 deletions
diff --git a/sensors/aidl/android/hardware/sensors/ISensors.aidl b/sensors/aidl/android/hardware/sensors/ISensors.aidl index 2ac188454b..2c684897cf 100644 --- a/sensors/aidl/android/hardware/sensors/ISensors.aidl +++ b/sensors/aidl/android/hardware/sensors/ISensors.aidl @@ -229,8 +229,7 @@ interface ISensors { * * @param mem shared memory info data structure. * @param out channelHandle The registered channel handle. - * @return The direct channel handle, which is positive if successfully registered, and -1 - * otherwise. + * @return The direct channel handle, which is positive if successfully registered. * @return Status::ok on success * EX_ILLEGAL_ARGUMENT if the shared memory information is not consistent. * EX_UNSUPPORTED_OPERATION if this functionality is unsupported. @@ -245,7 +244,7 @@ interface ISensors { * @see OperationMode * @param mode The operation mode. * @return Status::ok on success - * EX_UNSUPPORTED_OPERATION if requested mode is not supported. + * EX_UNSUPPORTED_OPERATION or EX_ILLEGAL_ARGUMENT if requested mode is not supported. * EX_SECURITY if the operation is not allowed. */ void setOperationMode(in OperationMode mode); diff --git a/sensors/aidl/default/multihal/HalProxyAidl.cpp b/sensors/aidl/default/multihal/HalProxyAidl.cpp index 64805e6638..e6bcdada52 100644 --- a/sensors/aidl/default/multihal/HalProxyAidl.cpp +++ b/sensors/aidl/default/multihal/HalProxyAidl.cpp @@ -29,6 +29,7 @@ using ::aidl::android::hardware::common::fmq::SynchronizedReadWrite; using ::aidl::android::hardware::sensors::ISensors; using ::aidl::android::hardware::sensors::ISensorsCallback; using ::android::hardware::sensors::V2_1::implementation::convertToOldEvent; +using ::ndk::ScopedAStatus; namespace aidl { namespace android { @@ -36,19 +37,22 @@ namespace hardware { namespace sensors { namespace implementation { -static binder_status_t resultToBinderStatus(::android::hardware::sensors::V1_0::Result result) { - switch (result) { - case ::android::hardware::sensors::V1_0::Result::OK: - return STATUS_OK; - case ::android::hardware::sensors::V1_0::Result::PERMISSION_DENIED: - return STATUS_PERMISSION_DENIED; - case ::android::hardware::sensors::V1_0::Result::NO_MEMORY: - return STATUS_NO_MEMORY; - case ::android::hardware::sensors::V1_0::Result::BAD_VALUE: - return STATUS_BAD_VALUE; - case ::android::hardware::sensors::V1_0::Result::INVALID_OPERATION: - return STATUS_INVALID_OPERATION; - } +static ScopedAStatus +resultToAStatus(::android::hardware::sensors::V1_0::Result result) { + switch (result) { + case ::android::hardware::sensors::V1_0::Result::OK: + return ScopedAStatus::ok(); + case ::android::hardware::sensors::V1_0::Result::PERMISSION_DENIED: + return ScopedAStatus::fromExceptionCode(EX_SECURITY); + case ::android::hardware::sensors::V1_0::Result::NO_MEMORY: + return ScopedAStatus::fromServiceSpecificError(ISensors::ERROR_NO_MEMORY); + case ::android::hardware::sensors::V1_0::Result::BAD_VALUE: + return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); + case ::android::hardware::sensors::V1_0::Result::INVALID_OPERATION: + return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); + default: + return ScopedAStatus::fromExceptionCode(EX_TRANSACTION_FAILED); + } } static ::android::hardware::sensors::V1_0::RateLevel convertRateLevel( @@ -62,6 +66,8 @@ static ::android::hardware::sensors::V1_0::RateLevel convertRateLevel( return ::android::hardware::sensors::V1_0::RateLevel::FAST; case ISensors::RateLevel::VERY_FAST: return ::android::hardware::sensors::V1_0::RateLevel::VERY_FAST; + default: + assert(false); } } @@ -72,6 +78,8 @@ static ::android::hardware::sensors::V1_0::OperationMode convertOperationMode( return ::android::hardware::sensors::V1_0::OperationMode::NORMAL; case ISensors::OperationMode::DATA_INJECTION: return ::android::hardware::sensors::V1_0::OperationMode::DATA_INJECTION; + default: + assert(false); } } @@ -82,6 +90,8 @@ static ::android::hardware::sensors::V1_0::SharedMemType convertSharedMemType( return ::android::hardware::sensors::V1_0::SharedMemType::ASHMEM; case ISensors::SharedMemInfo::SharedMemType::GRALLOC: return ::android::hardware::sensors::V1_0::SharedMemType::GRALLOC; + default: + assert(false); } } @@ -90,6 +100,8 @@ static ::android::hardware::sensors::V1_0::SharedMemFormat convertSharedMemForma switch (sharedMemFormat) { case ISensors::SharedMemInfo::SharedMemFormat::SENSORS_EVENT: return ::android::hardware::sensors::V1_0::SharedMemFormat::SENSORS_EVENT; + default: + assert(false); } } @@ -104,106 +116,125 @@ static ::android::hardware::sensors::V1_0::SharedMemInfo convertSharedMemInfo( return v1SharedMemInfo; } -::ndk::ScopedAStatus HalProxyAidl::activate(int32_t in_sensorHandle, bool in_enabled) { - return ndk::ScopedAStatus::fromStatus( - resultToBinderStatus(HalProxy::activate(in_sensorHandle, in_enabled))); +ScopedAStatus HalProxyAidl::activate(int32_t in_sensorHandle, bool in_enabled) { + return resultToAStatus(HalProxy::activate(in_sensorHandle, in_enabled)); +} + +ScopedAStatus HalProxyAidl::batch(int32_t in_sensorHandle, + int64_t in_samplingPeriodNs, + int64_t in_maxReportLatencyNs) { + return resultToAStatus(HalProxy::batch(in_sensorHandle, in_samplingPeriodNs, + in_maxReportLatencyNs)); } -::ndk::ScopedAStatus HalProxyAidl::batch(int32_t in_sensorHandle, int64_t in_samplingPeriodNs, - int64_t in_maxReportLatencyNs) { - return ndk::ScopedAStatus::fromStatus(resultToBinderStatus( - HalProxy::batch(in_sensorHandle, in_samplingPeriodNs, in_maxReportLatencyNs))); +ScopedAStatus HalProxyAidl::configDirectReport(int32_t in_sensorHandle, + int32_t in_channelHandle, + ISensors::RateLevel in_rate, + int32_t *_aidl_return) { + ScopedAStatus status = + ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); + HalProxy::configDirectReport( + in_sensorHandle, in_channelHandle, convertRateLevel(in_rate), + [&status, _aidl_return](::android::hardware::sensors::V1_0::Result result, + int32_t reportToken) { + status = resultToAStatus(result); + *_aidl_return = reportToken; + }); + + return status; } -::ndk::ScopedAStatus HalProxyAidl::configDirectReport(int32_t in_sensorHandle, - int32_t in_channelHandle, - ISensors::RateLevel in_rate, - int32_t* _aidl_return) { - binder_status_t binderStatus; - HalProxy::configDirectReport( - in_sensorHandle, in_channelHandle, convertRateLevel(in_rate), - [&binderStatus, _aidl_return](::android::hardware::sensors::V1_0::Result result, - int32_t reportToken) { - binderStatus = resultToBinderStatus(result); - *_aidl_return = reportToken; - }); - return ndk::ScopedAStatus::fromStatus(binderStatus); +ScopedAStatus HalProxyAidl::flush(int32_t in_sensorHandle) { + return resultToAStatus(HalProxy::flush(in_sensorHandle)); } -::ndk::ScopedAStatus HalProxyAidl::flush(int32_t in_sensorHandle) { - return ndk::ScopedAStatus::fromStatus(resultToBinderStatus(HalProxy::flush(in_sensorHandle))); +ScopedAStatus HalProxyAidl::getSensorsList( + std::vector<::aidl::android::hardware::sensors::SensorInfo> *_aidl_return) { + for (const auto &sensor : HalProxy::getSensors()) { + _aidl_return->push_back(convertSensorInfo(sensor.second)); + } + return ScopedAStatus::ok(); } -::ndk::ScopedAStatus HalProxyAidl::getSensorsList( - std::vector<::aidl::android::hardware::sensors::SensorInfo>* _aidl_return) { - for (const auto& sensor : HalProxy::getSensors()) { - _aidl_return->push_back(convertSensorInfo(sensor.second)); - } - return ndk::ScopedAStatus::ok(); -} - -::ndk::ScopedAStatus HalProxyAidl::initialize( - const MQDescriptor<::aidl::android::hardware::sensors::Event, SynchronizedReadWrite>& - in_eventQueueDescriptor, - const MQDescriptor<int32_t, SynchronizedReadWrite>& in_wakeLockDescriptor, - const std::shared_ptr<ISensorsCallback>& in_sensorsCallback) { - ::android::sp<::android::hardware::sensors::V2_1::implementation::ISensorsCallbackWrapperBase> - dynamicCallback = new ISensorsCallbackWrapperAidl(in_sensorsCallback); - - auto aidlEventQueue = - std::make_unique<::android::AidlMessageQueue<::aidl::android::hardware::sensors::Event, - SynchronizedReadWrite>>( - in_eventQueueDescriptor, true /* resetPointers */); - std::unique_ptr< - ::android::hardware::sensors::V2_1::implementation::EventMessageQueueWrapperBase> - eventQueue = std::make_unique<EventMessageQueueWrapperAidl>(aidlEventQueue); - - auto aidlWakeLockQueue = - std::make_unique<::android::AidlMessageQueue<int32_t, SynchronizedReadWrite>>( - in_wakeLockDescriptor, true /* resetPointers */); - std::unique_ptr< - ::android::hardware::sensors::V2_1::implementation::WakeLockMessageQueueWrapperBase> - wakeLockQueue = std::make_unique<WakeLockMessageQueueWrapperAidl>(aidlWakeLockQueue); - - return ndk::ScopedAStatus::fromStatus( - resultToBinderStatus(initializeCommon(eventQueue, wakeLockQueue, dynamicCallback))); -} - -::ndk::ScopedAStatus HalProxyAidl::injectSensorData( - const ::aidl::android::hardware::sensors::Event& in_event) { - ::android::hardware::sensors::V2_1::Event hidlEvent; - convertToHidlEvent(in_event, &hidlEvent); - return ndk::ScopedAStatus::fromStatus( - resultToBinderStatus(HalProxy::injectSensorData(convertToOldEvent(hidlEvent)))); -} - -::ndk::ScopedAStatus HalProxyAidl::registerDirectChannel(const ISensors::SharedMemInfo& in_mem, - int32_t* _aidl_return) { - binder_status_t binderStatus; - ::android::hardware::sensors::V1_0::SharedMemInfo sharedMemInfo = convertSharedMemInfo(in_mem); - - HalProxy::registerDirectChannel( - sharedMemInfo, - [&binderStatus, _aidl_return](::android::hardware::sensors::V1_0::Result result, - int32_t reportToken) { - binderStatus = resultToBinderStatus(result); - *_aidl_return = reportToken; - }); - - native_handle_delete( - const_cast<native_handle_t*>(sharedMemInfo.memoryHandle.getNativeHandle())); - return ndk::ScopedAStatus::fromStatus(binderStatus); -} - -::ndk::ScopedAStatus HalProxyAidl::setOperationMode( - ::aidl::android::hardware::sensors::ISensors::OperationMode in_mode) { - return ndk::ScopedAStatus::fromStatus( - resultToBinderStatus(HalProxy::setOperationMode(convertOperationMode(in_mode)))); -} - -::ndk::ScopedAStatus HalProxyAidl::unregisterDirectChannel(int32_t in_channelHandle) { - return ndk::ScopedAStatus::fromStatus( - resultToBinderStatus(HalProxy::unregisterDirectChannel(in_channelHandle))); +ScopedAStatus HalProxyAidl::initialize( + const MQDescriptor<::aidl::android::hardware::sensors::Event, + SynchronizedReadWrite> &in_eventQueueDescriptor, + const MQDescriptor<int32_t, SynchronizedReadWrite> &in_wakeLockDescriptor, + const std::shared_ptr<ISensorsCallback> &in_sensorsCallback) { + ::android::sp<::android::hardware::sensors::V2_1::implementation:: + ISensorsCallbackWrapperBase> + dynamicCallback = new ISensorsCallbackWrapperAidl(in_sensorsCallback); + + auto aidlEventQueue = std::make_unique<::android::AidlMessageQueue< + ::aidl::android::hardware::sensors::Event, SynchronizedReadWrite>>( + in_eventQueueDescriptor, true /* resetPointers */); + std::unique_ptr<::android::hardware::sensors::V2_1::implementation:: + EventMessageQueueWrapperBase> + eventQueue = + std::make_unique<EventMessageQueueWrapperAidl>(aidlEventQueue); + + auto aidlWakeLockQueue = std::make_unique< + ::android::AidlMessageQueue<int32_t, SynchronizedReadWrite>>( + in_wakeLockDescriptor, true /* resetPointers */); + std::unique_ptr<::android::hardware::sensors::V2_1::implementation:: + WakeLockMessageQueueWrapperBase> + wakeLockQueue = + std::make_unique<WakeLockMessageQueueWrapperAidl>(aidlWakeLockQueue); + + return resultToAStatus( + initializeCommon(eventQueue, wakeLockQueue, dynamicCallback)); +} + +ScopedAStatus HalProxyAidl::injectSensorData( + const ::aidl::android::hardware::sensors::Event &in_event) { + ::android::hardware::sensors::V2_1::Event hidlEvent; + convertToHidlEvent(in_event, &hidlEvent); + return resultToAStatus( + HalProxy::injectSensorData(convertToOldEvent(hidlEvent))); +} + +ScopedAStatus +HalProxyAidl::registerDirectChannel(const ISensors::SharedMemInfo &in_mem, + int32_t *_aidl_return) { + ScopedAStatus status = + ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); + ::android::hardware::sensors::V1_0::SharedMemInfo sharedMemInfo = + convertSharedMemInfo(in_mem); + + HalProxy::registerDirectChannel( + sharedMemInfo, + [&status, _aidl_return](::android::hardware::sensors::V1_0::Result result, + int32_t reportToken) { + status = resultToAStatus(result); + *_aidl_return = reportToken; + }); + + native_handle_delete(const_cast<native_handle_t *>( + sharedMemInfo.memoryHandle.getNativeHandle())); + + return status; +} + +ScopedAStatus HalProxyAidl::setOperationMode( + ::aidl::android::hardware::sensors::ISensors::OperationMode in_mode) { + return resultToAStatus( + HalProxy::setOperationMode(convertOperationMode(in_mode))); +} + +ScopedAStatus HalProxyAidl::unregisterDirectChannel(int32_t in_channelHandle) { + return resultToAStatus(HalProxy::unregisterDirectChannel(in_channelHandle)); +} + +binder_status_t HalProxyAidl::dump(int fd, const char ** /* args */, + uint32_t /* numArgs */) { + native_handle_t *nativeHandle = + native_handle_create(1 /* numFds */, 0 /* numInts */); + nativeHandle->data[0] = fd; + + HalProxy::debug(nativeHandle, {} /* args */); + + native_handle_delete(nativeHandle); + return STATUS_OK; } } // namespace implementation diff --git a/sensors/aidl/default/multihal/include/HalProxyAidl.h b/sensors/aidl/default/multihal/include/HalProxyAidl.h index 7401726cf9..5c81715933 100644 --- a/sensors/aidl/default/multihal/include/HalProxyAidl.h +++ b/sensors/aidl/default/multihal/include/HalProxyAidl.h @@ -55,6 +55,8 @@ class HalProxyAidl : public ::android::hardware::sensors::V2_1::implementation:: ::ndk::ScopedAStatus setOperationMode( ::aidl::android::hardware::sensors::ISensors::OperationMode in_mode) override; ::ndk::ScopedAStatus unregisterDirectChannel(int32_t in_channelHandle) override; + + binder_status_t dump(int fd, const char **args, uint32_t numArgs) override; }; } // namespace implementation diff --git a/sensors/aidl/vts/VtsAidlHalSensorsTargetTest.cpp b/sensors/aidl/vts/VtsAidlHalSensorsTargetTest.cpp index 83d0dc97e1..d536e290b2 100644 --- a/sensors/aidl/vts/VtsAidlHalSensorsTargetTest.cpp +++ b/sensors/aidl/vts/VtsAidlHalSensorsTargetTest.cpp @@ -599,10 +599,12 @@ TEST_P(SensorsAidlTest, SetOperationMode) { ASSERT_TRUE(getSensors()->setOperationMode(ISensors::OperationMode::DATA_INJECTION).isOk()); ASSERT_TRUE(getSensors()->setOperationMode(ISensors::OperationMode::NORMAL).isOk()); } else { - ASSERT_EQ(getSensors() - ->setOperationMode(ISensors::OperationMode::DATA_INJECTION) - .getExceptionCode(), - EX_UNSUPPORTED_OPERATION); + int errorCode = + getSensors() + ->setOperationMode(ISensors::OperationMode::DATA_INJECTION) + .getExceptionCode(); + ASSERT_TRUE((errorCode == EX_UNSUPPORTED_OPERATION) || + (errorCode == EX_ILLEGAL_ARGUMENT)); } } @@ -938,10 +940,10 @@ void SensorsAidlTest::checkRateLevel(const SensorInfo& sensor, int32_t directCha if (isDirectReportRateSupported(sensor, rateLevel)) { ASSERT_TRUE(status.isOk()); if (rateLevel != ISensors::RateLevel::STOP) { - ASSERT_GT(*reportToken, 0); - } else { - ASSERT_EQ(status.getExceptionCode(), EX_ILLEGAL_ARGUMENT); + ASSERT_GT(*reportToken, 0); } + } else { + ASSERT_EQ(status.getExceptionCode(), EX_ILLEGAL_ARGUMENT); } } @@ -982,11 +984,15 @@ void SensorsAidlTest::verifyRegisterDirectChannel( ::ndk::ScopedAStatus status = registerDirectChannel(mem->getSharedMemInfo(), &channelHandle); if (supportsSharedMemType) { ASSERT_TRUE(status.isOk()); - ASSERT_EQ(channelHandle, 0); + ASSERT_GT(channelHandle, 0); + + // Verify that the memory has been zeroed + for (size_t i = 0; i < mem->getSize(); i++) { + ASSERT_EQ(buffer[i], 0x00); + } } else { int32_t error = supportsAnyDirectChannel ? EX_ILLEGAL_ARGUMENT : EX_UNSUPPORTED_OPERATION; ASSERT_EQ(status.getExceptionCode(), error); - ASSERT_EQ(channelHandle, -1); } *directChannelHandle = channelHandle; } @@ -1038,7 +1044,7 @@ void SensorsAidlTest::verifyConfigure(const SensorInfo& sensor, // Verify that a sensor handle of -1 is only acceptable when using RateLevel::STOP ndk::ScopedAStatus status = configDirectReport(-1 /* sensorHandle */, directChannelHandle, ISensors::RateLevel::NORMAL, &reportToken); - ASSERT_EQ(status.getServiceSpecificError(), android::BAD_VALUE); + ASSERT_EQ(status.getExceptionCode(), EX_ILLEGAL_ARGUMENT); status = configDirectReport(-1 /* sensorHandle */, directChannelHandle, ISensors::RateLevel::STOP, &reportToken); |