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

Commit 724d91d7 authored by Aravind Akella's avatar Aravind Akella
Browse files

Sensor batching. Changes to the native code.

Bug: 10109508
Change-Id: I7333f3aac76125a8226a4c99c901fb904588df04
parent 9b5534b0
Loading
Loading
Loading
Loading
+28 −1
Original line number Diff line number Diff line
@@ -106,6 +106,30 @@ typedef struct ASensorVector {
    uint8_t reserved[3];
} ASensorVector;

typedef struct AMetaDataEvent {
    int32_t what;
    int32_t sensor;
} AMetaDataEvent;

typedef struct AUncalibratedEvent {
  union {
    float uncalib[3];
    struct {
      float x_uncalib;
      float y_uncalib;
      float z_uncalib;
    };
  };
  union {
    float bias[3];
    struct {
      float x_bias;
      float y_bias;
      float z_bias;
    };
  };
} AUncalibratedEvent;

/* NOTE: Must match hardware/sensors.h */
typedef struct ASensorEvent {
    int32_t version; /* sizeof(struct ASensorEvent) */
@@ -123,6 +147,10 @@ typedef struct ASensorEvent {
            float           distance;
            float           light;
            float           pressure;
            float           relative_humidity;
            AUncalibratedEvent uncalibrated_gyro;
            AUncalibratedEvent uncalibrated_magnetic;
            AMetaDataEvent meta_data;
        };
        union {
            uint64_t        data[8];
@@ -132,7 +160,6 @@ typedef struct ASensorEvent {
    int32_t reserved1[4];
} ASensorEvent;


struct ASensorManager;
typedef struct ASensorManager ASensorManager;

+3 −1
Original line number Diff line number Diff line
@@ -36,8 +36,10 @@ public:
    DECLARE_META_INTERFACE(SensorEventConnection);

    virtual sp<BitTube> getSensorChannel() const = 0;
    virtual status_t enableDisable(int handle, bool enabled) = 0;
    virtual status_t enableDisable(int handle, bool enabled, nsecs_t samplingPeriodNs,
                                   nsecs_t maxBatchReportLatencyNs, int reservedFlags) = 0;
    virtual status_t setEventRate(int handle, nsecs_t ns) = 0;
    virtual status_t flushSensor(int handle) = 0;
};

// ----------------------------------------------------------------------------
+5 −1
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ public:
    };

            Sensor();
            Sensor(struct sensor_t const* hwSensor);
            Sensor(struct sensor_t const* hwSensor, int halVersion = 0);
            ~Sensor();

    const String8& getName() const;
@@ -67,6 +67,8 @@ public:
    int32_t getMinDelay() const;
    nsecs_t getMinDelayNs() const;
    int32_t getVersion() const;
    int32_t getFifoReservedEventCount() const;
    int32_t getFifoMaxEventCount() const;

    // LightFlattenable protocol
    inline bool isFixedSize() const { return false; }
@@ -85,6 +87,8 @@ private:
    float   mPower;
    int32_t mMinDelay;
    int32_t mVersion;
    int32_t mFifoReservedEventCount;
    int32_t mFifoMaxEventCount;
};

// ----------------------------------------------------------------------------
+3 −1
Original line number Diff line number Diff line
@@ -68,8 +68,10 @@ public:
    status_t setEventRate(Sensor const* sensor, nsecs_t ns) const;

    // these are here only to support SensorManager.java
    status_t enableSensor(int32_t handle, int32_t us) const;
    status_t enableSensor(int32_t handle, int32_t samplingPeriodUs, int maxBatchReportLatencyUs,
                          int reservedFlags) const;
    status_t disableSensor(int32_t handle) const;
    status_t flushSensor(int32_t handle) const;

private:
    sp<Looper> getLooper() const;
+27 −3
Original line number Diff line number Diff line
@@ -33,7 +33,8 @@ namespace android {
enum {
    GET_SENSOR_CHANNEL = IBinder::FIRST_CALL_TRANSACTION,
    ENABLE_DISABLE,
    SET_EVENT_RATE
    SET_EVENT_RATE,
    FLUSH_SENSOR
};

class BpSensorEventConnection : public BpInterface<ISensorEventConnection>
@@ -52,12 +53,16 @@ public:
        return new BitTube(reply);
    }

    virtual status_t enableDisable(int handle, bool enabled)
    virtual status_t enableDisable(int handle, bool enabled, nsecs_t samplingPeriodNs,
                                   nsecs_t maxBatchReportLatencyNs, int reservedFlags)
    {
        Parcel data, reply;
        data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor());
        data.writeInt32(handle);
        data.writeInt32(enabled);
        data.writeInt64(samplingPeriodNs);
        data.writeInt64(maxBatchReportLatencyNs);
        data.writeInt32(reservedFlags);
        remote()->transact(ENABLE_DISABLE, data, &reply);
        return reply.readInt32();
    }
@@ -71,6 +76,14 @@ public:
        remote()->transact(SET_EVENT_RATE, data, &reply);
        return reply.readInt32();
    }

    virtual status_t flushSensor(int handle) {
        Parcel data, reply;
        data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor());
        data.writeInt32(handle);
        remote()->transact(FLUSH_SENSOR, data, &reply);
        return reply.readInt32();
    }
};

IMPLEMENT_META_INTERFACE(SensorEventConnection, "android.gui.SensorEventConnection");
@@ -91,7 +104,11 @@ status_t BnSensorEventConnection::onTransact(
            CHECK_INTERFACE(ISensorEventConnection, data, reply);
            int handle = data.readInt32();
            int enabled = data.readInt32();
            status_t result = enableDisable(handle, enabled);
            nsecs_t samplingPeriodNs = data.readInt64();
            nsecs_t maxBatchReportLatencyNs = data.readInt64();
            int reservedFlags = data.readInt32();
            status_t result = enableDisable(handle, enabled, samplingPeriodNs,
                                            maxBatchReportLatencyNs, reservedFlags);
            reply->writeInt32(result);
            return NO_ERROR;
        } break;
@@ -103,6 +120,13 @@ status_t BnSensorEventConnection::onTransact(
            reply->writeInt32(result);
            return NO_ERROR;
        } break;
        case FLUSH_SENSOR: {
            CHECK_INTERFACE(ISensorEventConnection, data, reply);
            int handle = data.readInt32();
            status_t result = flushSensor(handle);
            reply->writeInt32(result);
            return NO_ERROR;
        } break;
    }
    return BBinder::onTransact(code, data, reply, flags);
}
Loading