Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 535c63e6 authored by Anthony Stange's avatar Anthony Stange
Browse files

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
parent 1d71acc1
Loading
Loading
Loading
Loading
+32 −1
Original line number Diff line number Diff line
@@ -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
+2 −0
Original line number Diff line number Diff line
@@ -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;

+1 −0
Original line number Diff line number Diff line
@@ -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",
+3 −5
Original line number Diff line number Diff line
@@ -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),
+7 −4
Original line number Diff line number Diff line
@@ -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();
Loading