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

Commit 431e41c9 authored by Andreas Huber's avatar Andreas Huber Committed by Android (Google) Code Review
Browse files

Merge "sensor HAL v3"

parents 0ebdc7f7 99fdbb5f
Loading
Loading
Loading
Loading
+21 −3
Original line number Original line Diff line number Diff line
@@ -10,7 +10,6 @@ LOCAL_SRC_FILES:= \
    OrientationSensor.cpp \
    OrientationSensor.cpp \
    RecentEventLogger.cpp \
    RecentEventLogger.cpp \
    RotationVectorSensor.cpp \
    RotationVectorSensor.cpp \
    SensorDevice.cpp \
    SensorEventConnection.cpp \
    SensorEventConnection.cpp \
    SensorFusion.cpp \
    SensorFusion.cpp \
    SensorInterface.cpp \
    SensorInterface.cpp \
@@ -19,13 +18,19 @@ LOCAL_SRC_FILES:= \
    SensorService.cpp \
    SensorService.cpp \
    SensorServiceUtils.cpp \
    SensorServiceUtils.cpp \



LOCAL_CFLAGS:= -DLOG_TAG=\"SensorService\"
LOCAL_CFLAGS:= -DLOG_TAG=\"SensorService\"


LOCAL_CFLAGS += -Wall -Werror -Wextra
LOCAL_CFLAGS += -Wall -Werror -Wextra


LOCAL_CFLAGS += -fvisibility=hidden
LOCAL_CFLAGS += -fvisibility=hidden


ifeq ($(ENABLE_TREBLE), true)
LOCAL_SRC_FILES += SensorDeviceTreble.cpp
LOCAL_CFLAGS += -DENABLE_TREBLE=1
else
LOCAL_SRC_FILES += SensorDevice.cpp
endif

LOCAL_SHARED_LIBRARIES := \
LOCAL_SHARED_LIBRARIES := \
    libcutils \
    libcutils \
    libhardware \
    libhardware \
@@ -35,7 +40,20 @@ LOCAL_SHARED_LIBRARIES := \
    libbinder \
    libbinder \
    libui \
    libui \
    libgui \
    libgui \
    libcrypto
    libcrypto \

ifeq ($(ENABLE_TREBLE), true)

LOCAL_SHARED_LIBRARIES += \
    libbase \
    libhidl \
    libhwbinder \
    android.hardware.sensors@1.0

LOCAL_STATIC_LIBRARIES := \
    android.hardware.sensors@1.0-convert

endif  # ENABLE_TREBLE


LOCAL_MODULE:= libsensorservice
LOCAL_MODULE:= libsensorservice


+30 −0
Original line number Original line Diff line number Diff line
@@ -27,19 +27,29 @@
#include <stdint.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/types.h>


#ifdef ENABLE_TREBLE
#include <map>

#include "android/hardware/sensors/1.0/ISensors.h"
#endif

// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------


namespace android {
namespace android {

// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
using SensorServiceUtil::Dumpable;
using SensorServiceUtil::Dumpable;


class SensorDevice : public Singleton<SensorDevice>, public Dumpable {
class SensorDevice : public Singleton<SensorDevice>, public Dumpable {
public:
public:
    ssize_t getSensorList(sensor_t const** list);
    ssize_t getSensorList(sensor_t const** list);

    void handleDynamicSensorConnection(int handle, bool connected);
    void handleDynamicSensorConnection(int handle, bool connected);
    status_t initCheck() const;
    status_t initCheck() const;
    int getHalDeviceVersion() const;
    int getHalDeviceVersion() const;

    ssize_t poll(sensors_event_t* buffer, size_t count);
    ssize_t poll(sensors_event_t* buffer, size_t count);

    status_t activate(void* ident, int handle, int enabled);
    status_t activate(void* ident, int handle, int enabled);
    status_t batch(void* ident, int handle, int flags, int64_t samplingPeriodNs,
    status_t batch(void* ident, int handle, int flags, int64_t samplingPeriodNs,
                   int64_t maxBatchReportLatencyNs);
                   int64_t maxBatchReportLatencyNs);
@@ -50,6 +60,7 @@ public:
    void disableAllSensors();
    void disableAllSensors();
    void enableAllSensors();
    void enableAllSensors();
    void autoDisable(void *ident, int handle);
    void autoDisable(void *ident, int handle);

    status_t injectSensorData(const sensors_event_t *event);
    status_t injectSensorData(const sensors_event_t *event);
    void notifyConnectionDestroyed(void *ident);
    void notifyConnectionDestroyed(void *ident);


@@ -57,8 +68,15 @@ public:
    virtual std::string dump() const;
    virtual std::string dump() const;
private:
private:
    friend class Singleton<SensorDevice>;
    friend class Singleton<SensorDevice>;
#ifdef ENABLE_TREBLE
    sp<android::hardware::sensors::V1_0::ISensors> mSensors;
    Vector<sensor_t> mSensorList;
    std::map<int32_t, sensor_t*> mConnectedDynamicSensors;
#else
    sensors_poll_device_1_t* mSensorDevice;
    sensors_poll_device_1_t* mSensorDevice;
    struct sensors_module_t* mSensorModule;
    struct sensors_module_t* mSensorModule;
#endif

    static const nsecs_t MINIMUM_EVENTS_PERIOD =   1000000; // 1000 Hz
    static const nsecs_t MINIMUM_EVENTS_PERIOD =   1000000; // 1000 Hz
    mutable Mutex mLock; // protect mActivationCount[].batchParams
    mutable Mutex mLock; // protect mActivationCount[].batchParams
    // fixed-size array after construction
    // fixed-size array after construction
@@ -111,6 +129,18 @@ private:


    bool isClientDisabled(void* ident);
    bool isClientDisabled(void* ident);
    bool isClientDisabledLocked(void* ident);
    bool isClientDisabledLocked(void* ident);

#ifdef ENABLE_TREBLE
    using Event = hardware::sensors::V1_0::Event;
    using SensorInfo = hardware::sensors::V1_0::SensorInfo;

    void convertToSensorEvent(const Event &src, sensors_event_t *dst);

    void convertToSensorEvents(
            const hardware::hidl_vec<Event> &src,
            const hardware::hidl_vec<SensorInfo> &dynamicSensorsAdded,
            sensors_event_t *dst);
#endif  // ENABLE_TREBLE
};
};


// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
+610 −0

File added.

Preview size limit exceeded, changes collapsed.