Add Hinge Angle Sensor to default impl for HAL 2.1
Bug: 144139857
Test: Verify this type is exposed when VTS is run
Change-Id: I994f1b4c77729b76760b7cafc19b825c98ca97ca
diff --git a/sensors/common/default/2.X/Android.bp b/sensors/common/default/2.X/Android.bp
index ea75a10..8b0d52f 100644
--- a/sensors/common/default/2.X/Android.bp
+++ b/sensors/common/default/2.X/Android.bp
@@ -26,6 +26,7 @@
shared_libs: [
"android.hardware.sensors@1.0",
"android.hardware.sensors@2.0",
+ "android.hardware.sensors@2.1",
"libcutils",
"libfmq",
"libhidlbase",
diff --git a/sensors/common/default/2.X/Sensor.cpp b/sensors/common/default/2.X/Sensor.cpp
index 4c40d1f..1841dff 100644
--- a/sensors/common/default/2.X/Sensor.cpp
+++ b/sensors/common/default/2.X/Sensor.cpp
@@ -26,16 +26,14 @@
namespace V2_X {
namespace implementation {
-using ::android::hardware::sensors::V1_0::Event;
using ::android::hardware::sensors::V1_0::MetaDataEventType;
using ::android::hardware::sensors::V1_0::OperationMode;
using ::android::hardware::sensors::V1_0::Result;
using ::android::hardware::sensors::V1_0::SensorFlagBits;
-using ::android::hardware::sensors::V1_0::SensorInfo;
using ::android::hardware::sensors::V1_0::SensorStatus;
-using ::android::hardware::sensors::V1_0::SensorType;
-
-static constexpr float kDefaultMaxDelayUs = 10 * 1000 * 1000;
+using ::android::hardware::sensors::V2_1::Event;
+using ::android::hardware::sensors::V2_1::SensorInfo;
+using ::android::hardware::sensors::V2_1::SensorType;
Sensor::Sensor(ISensorsEventCallback* callback)
: mIsEnabled(false),
diff --git a/sensors/common/default/2.X/Sensor.h b/sensors/common/default/2.X/Sensor.h
index 8592c41..2f8a143 100644
--- a/sensors/common/default/2.X/Sensor.h
+++ b/sensors/common/default/2.X/Sensor.h
@@ -18,6 +18,7 @@
#define ANDROID_HARDWARE_SENSORS_V2_X_SENSOR_H
#include <android/hardware/sensors/1.0/types.h>
+#include <android/hardware/sensors/2.1/types.h>
#include <condition_variable>
#include <memory>
@@ -31,9 +32,11 @@
namespace V2_X {
namespace implementation {
+static constexpr float kDefaultMaxDelayUs = 10 * 1000 * 1000;
+
class ISensorsEventCallback {
public:
- using Event = ::android::hardware::sensors::V1_0::Event;
+ using Event = ::android::hardware::sensors::V2_1::Event;
virtual ~ISensorsEventCallback(){};
virtual void postEvents(const std::vector<Event>& events, bool wakeup) = 0;
@@ -41,11 +44,11 @@
class Sensor {
public:
- using Event = ::android::hardware::sensors::V1_0::Event;
using OperationMode = ::android::hardware::sensors::V1_0::OperationMode;
using Result = ::android::hardware::sensors::V1_0::Result;
- using SensorInfo = ::android::hardware::sensors::V1_0::SensorInfo;
- using SensorType = ::android::hardware::sensors::V1_0::SensorType;
+ using Event = ::android::hardware::sensors::V2_1::Event;
+ using SensorInfo = ::android::hardware::sensors::V2_1::SensorInfo;
+ using SensorType = ::android::hardware::sensors::V2_1::SensorType;
Sensor(ISensorsEventCallback* callback);
virtual ~Sensor();
diff --git a/sensors/common/default/2.X/Sensors.h b/sensors/common/default/2.X/Sensors.h
index de998eb..ee8240d 100644
--- a/sensors/common/default/2.X/Sensors.h
+++ b/sensors/common/default/2.X/Sensors.h
@@ -82,7 +82,8 @@
Return<void> getSensorsList(V2_0::ISensors::getSensorsList_cb _hidl_cb) override {
std::vector<V1_0::SensorInfo> sensors;
for (const auto& sensor : mSensors) {
- sensors.push_back(sensor.second->getSensorInfo());
+ sensors.push_back(
+ V2_1::implementation::convertToOldSensorInfo(sensor.second->getSensorInfo()));
}
// Call the HIDL callback with the SensorInfo
@@ -187,7 +188,7 @@
Return<Result> injectSensorData(const Event& event) override {
auto sensor = mSensors.find(event.sensorHandle);
if (sensor != mSensors.end()) {
- return sensor->second->injectEvent(event);
+ return sensor->second->injectEvent(V2_1::implementation::convertToNewEvent(event));
}
return Result::BAD_VALUE;
@@ -210,9 +211,9 @@
return Return<void>();
}
- void postEvents(const std::vector<Event>& events, bool wakeup) override {
+ void postEvents(const std::vector<V2_1::Event>& events, bool wakeup) override {
std::lock_guard<std::mutex> lock(mWriteLock);
- if (mEventQueue->write(V2_1::implementation::convertToNewEvents(events))) {
+ if (mEventQueue->write(events)) {
mEventQueueFlag->wake(static_cast<uint32_t>(EventQueueFlagBits::READ_AND_PROCESS));
if (wakeup) {