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
This commit is contained in:
parent
1d71acc129
commit
535c63e672
6 changed files with 50 additions and 14 deletions
|
@ -16,17 +16,48 @@
|
|||
|
||||
#include "SensorsV2_1.h"
|
||||
|
||||
#include "Sensor.h"
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace sensors {
|
||||
namespace V2_1 {
|
||||
namespace implementation {
|
||||
|
||||
using V2_X::implementation::ISensorsEventCallback;
|
||||
using V2_X::implementation::OnChangeSensor;
|
||||
|
||||
class HingeAngleSensor : public OnChangeSensor {
|
||||
public:
|
||||
HingeAngleSensor(int32_t sensorHandle, ISensorsEventCallback* callback)
|
||||
: OnChangeSensor(callback) {
|
||||
mSensorInfo.sensorHandle = sensorHandle;
|
||||
mSensorInfo.name = "Hinge Angle Sensor";
|
||||
mSensorInfo.vendor = "Vendor String";
|
||||
mSensorInfo.version = 1;
|
||||
mSensorInfo.type = SensorType::HINGE_ANGLE;
|
||||
mSensorInfo.typeAsString = "";
|
||||
mSensorInfo.maxRange = 360.0f;
|
||||
mSensorInfo.resolution = 1.0f;
|
||||
mSensorInfo.power = 0.001f;
|
||||
mSensorInfo.minDelay = 40 * 1000; // microseconds
|
||||
mSensorInfo.maxDelay = V2_X::implementation::kDefaultMaxDelayUs;
|
||||
mSensorInfo.fifoReservedEventCount = 0;
|
||||
mSensorInfo.fifoMaxEventCount = 0;
|
||||
mSensorInfo.requiredPermission = "";
|
||||
mSensorInfo.flags = static_cast<uint32_t>(V1_0::SensorFlagBits::ON_CHANGE_MODE);
|
||||
}
|
||||
};
|
||||
|
||||
SensorsV2_1::SensorsV2_1() {
|
||||
AddSensor<HingeAngleSensor>();
|
||||
}
|
||||
|
||||
// Methods from ::android::hardware::sensors::V2_1::ISensors follow.
|
||||
Return<void> SensorsV2_1::getSensorsList_2_1(ISensors::getSensorsList_2_1_cb _hidl_cb) {
|
||||
std::vector<SensorInfo> sensors;
|
||||
for (const auto& sensor : mSensors) {
|
||||
sensors.push_back(convertToNewSensorInfo(sensor.second->getSensorInfo()));
|
||||
sensors.push_back(sensor.second->getSensorInfo());
|
||||
}
|
||||
|
||||
// Call the HIDL callback with the SensorInfo
|
||||
|
|
|
@ -49,6 +49,8 @@ class ISensorsCallbackWrapper : public V2_0::ISensorsCallback {
|
|||
};
|
||||
|
||||
struct SensorsV2_1 : public Sensors {
|
||||
SensorsV2_1();
|
||||
|
||||
// Methods from ::android::hardware::sensors::V2_1::ISensors follow.
|
||||
Return<void> getSensorsList_2_1(ISensors::getSensorsList_2_1_cb _hidl_cb) override;
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ cc_library_static {
|
|||
shared_libs: [
|
||||
"android.hardware.sensors@1.0",
|
||||
"android.hardware.sensors@2.0",
|
||||
"android.hardware.sensors@2.1",
|
||||
"libcutils",
|
||||
"libfmq",
|
||||
"libhidlbase",
|
||||
|
|
|
@ -26,16 +26,14 @@ namespace sensors {
|
|||
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),
|
||||
|
|
|
@ -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 sensors {
|
|||
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 ISensorsEventCallback {
|
|||
|
||||
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();
|
||||
|
|
|
@ -82,7 +82,8 @@ struct Sensors : public ISensorsInterface, public ISensorsEventCallback {
|
|||
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 @@ struct Sensors : public ISensorsInterface, public ISensorsEventCallback {
|
|||
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 @@ struct Sensors : public ISensorsInterface, public ISensorsEventCallback {
|
|||
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) {
|
||||
|
|
Loading…
Reference in a new issue