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

Commit 4f33ab9e authored by Peng Xu's avatar Peng Xu Committed by Gerrit Code Review
Browse files

Merge changes from topic "equalizer"

* changes:
  Initialize native Sensor object correctly
  Clarify sensor NDK struct has to be backward compatible
  [sensor] Clarify sequence requirement between setEventRate and enable
  sensorservice: Android.mk -> Android.bp
  Checking exisitence before calling editValueFor in SensorDevice
  Adding package name for HIDL connection and default package name
  Fix hidl_ssvc_poll thread issues
  Use appendFormat instead of append when passing arguments
  Synchronous resource recover  mechanism for ISensorEventConnection
  Check key before edit value in countFlushCompleteEventsLocked
  Support custom permission, slight adjust of dumpsys print
  sensors: pass sensor handle along with injected event
  Adding OWNERS files for services/sensorservice, libs/sensor
parents 8260e06c 4acb1999
Loading
Loading
Loading
Loading
+61 −27
Original line number Diff line number Diff line
@@ -197,7 +197,7 @@ enum {
 * A sensor event.
 */

/* NOTE: Must match hardware/sensors.h */
/* NOTE: changes to these structs have to be backward compatible */
typedef struct ASensorVector {
    union {
        float v[3];
@@ -259,7 +259,7 @@ typedef struct {
    };
} AAdditionalInfoEvent;

/* NOTE: Must match hardware/sensors.h */
/* NOTE: changes to this struct has to be backward compatible */
typedef struct ASensorEvent {
    int32_t version; /* sizeof(struct ASensorEvent) */
    int32_t sensor;
@@ -388,7 +388,7 @@ ASensorManager* ASensorManager_getInstance();
#endif

#if __ANDROID_API__ >= __ANDROID_API_O__
/*
/**
 * Get a reference to the sensor manager. ASensorManager is a singleton
 * per package as different packages may have access to different sensors.
 *
@@ -503,14 +503,12 @@ void ASensorManager_destroyDirectChannel(ASensorManager* manager, int channelId)
 * {@link ASensor_isDirectChannelTypeSupported}, respectively.
 *
 * Example:
 * \code{.cpp}
 *
 *     ASensorManager *manager = ...;
 *     ASensor *sensor = ...;
 *     int channelId = ...;
 *
 *      ASensorManager_configureDirectReport(
 *              manager, sensor, channel_id, ASENSOR_DIRECT_RATE_FAST);
 * \endcode
 *     ASensorManager_configureDirectReport(manager, sensor, channel_id, ASENSOR_DIRECT_RATE_FAST);
 *
 * \param manager   the {@link ASensorManager} instance obtained from
 *                  {@link ASensorManager_getInstanceForPackage}.
@@ -530,45 +528,81 @@ int ASensorManager_configureDirectReport(
/*****************************************************************************/

/**
 * Enable the selected sensor with a specified sampling period and max batch report latency.
 * Returns a negative error code on failure.
 * Note: To disable the selected sensor, use ASensorEventQueue_disableSensor() same as before.
 * Enable the selected sensor with sampling and report parameters
 *
 * Enable the selected sensor at a specified sampling period and max batch report latency.
 * To disable  sensor, use {@link ASensorEventQueue_disableSensor}.
 *
 * \param queue {@link ASensorEventQueue} for sensor event to be report to.
 * \param sensor {@link ASensor} to be enabled.
 * \param samplingPeriodUs sampling period of sensor in microseconds.
 * \param maxBatchReportLatencyus maximum time interval between two batch of sensor events are
 *                                delievered in microseconds. For sensor streaming, set to 0.
 * \return 0 on success or a negative error code on failure.
 */
int ASensorEventQueue_registerSensor(ASensorEventQueue* queue, ASensor const* sensor,
        int32_t samplingPeriodUs, int64_t maxBatchReportLatencyUs);

/**
 * Enable the selected sensor. Returns a negative error code on failure.
 * Enable the selected sensor at default sampling rate.
 *
 * Start event reports of a sensor to specified sensor event queue at a default rate.
 *
 * \param queue {@link ASensorEventQueue} for sensor event to be report to.
 * \param sensor {@link ASensor} to be enabled.
 *
 * \return 0 on success or a negative error code on failure.
 */
int ASensorEventQueue_enableSensor(ASensorEventQueue* queue, ASensor const* sensor);

/**
 * Disable the selected sensor. Returns a negative error code on failure.
 * Disable the selected sensor.
 *
 * Stop event reports from the sensor to specified sensor event queue.
 *
 * \param queue {@link ASensorEventQueue} to be changed
 * \param sensor {@link ASensor} to be disabled
 * \return 0 on success or a negative error code on failure.
 */
int ASensorEventQueue_disableSensor(ASensorEventQueue* queue, ASensor const* sensor);

/**
 * Sets the delivery rate of events in microseconds for the given sensor.
 *
 * This function has to be called after {@link ASensorEventQueue_enableSensor}.
 * Note that this is a hint only, generally event will arrive at a higher
 * rate. It is an error to set a rate inferior to the value returned by
 * ASensor_getMinDelay().
 * Returns a negative error code on failure.
 *
 * \param queue {@link ASensorEventQueue} to which sensor event is delivered.
 * \param sensor {@link ASensor} of which sampling rate to be updated.
 * \param usec sensor sampling period (1/sampling rate) in microseconds
 * \return 0 on sucess or a negative error code on failure.
 */
int ASensorEventQueue_setEventRate(ASensorEventQueue* queue, ASensor const* sensor, int32_t usec);

/**
 * Returns true if there are one or more events available in the
 * sensor queue.  Returns 1 if the queue has events; 0 if
 * it does not have events; and a negative value if there is an error.
 * Determine if a sensor event queue has pending event to be processed.
 *
 * \param queue {@link ASensorEventQueue} to be queried
 * \return 1 if the queue has events; 0 if it does not have events;
 *         or a negative value if there is an error.
 */
int ASensorEventQueue_hasEvents(ASensorEventQueue* queue);

/**
 * Returns the next available events from the queue.  Returns a negative
 * value if no events are available or an error has occurred, otherwise
 * the number of events returned.
 * Retrieve pending events in sensor event queue
 *
 * Retrieve next available events from the queue to a specified event array.
 *
 * \param queue {@link ASensorEventQueue} to get events from
 * \param events pointer to an array of {@link ASensorEvents}.
 * \param count max number of event that can be filled into array event.
 * \return number of events returned on success; negative error code when
 *         no events are pending or an error has occurred.
 *
 * Examples:
 *
 *     ASensorEvent event;
 *     ssize_t numEvent = ASensorEventQueue_getEvents(queue, &event, 1);
 *
+18 −2
Original line number Diff line number Diff line
@@ -36,7 +36,8 @@ enum {
    ENABLE_DISABLE,
    SET_EVENT_RATE,
    FLUSH_SENSOR,
    CONFIGURE_CHANNEL
    CONFIGURE_CHANNEL,
    DESTROY,
};

class BpSensorEventConnection : public BpInterface<ISensorEventConnection>
@@ -96,6 +97,17 @@ public:
        remote()->transact(CONFIGURE_CHANNEL, data, &reply);
        return reply.readInt32();
    }

    virtual void onLastStrongRef(const void* id) {
        destroy();
        BpInterface<ISensorEventConnection>::onLastStrongRef(id);
    }

protected:
    virtual void destroy() {
        Parcel data, reply;
        remote()->transact(DESTROY, data, &reply);
    }
};

// Out-of-line virtual method definition to trigger vtable emission in this
@@ -150,6 +162,10 @@ status_t BnSensorEventConnection::onTransact(
            reply->writeInt32(result);
            return NO_ERROR;
        }
        case DESTROY: {
            destroy();
            return NO_ERROR;
        }

    }
    return BBinder::onTransact(code, data, reply, flags);
+7 −3
Original line number Diff line number Diff line
@@ -119,10 +119,12 @@ public:
        return interface_cast<ISensorEventConnection>(reply.readStrongBinder());
    }

    virtual int setOperationParameter(
            int32_t type, const Vector<float> &floats, const Vector<int32_t> &ints) {
    virtual int setOperationParameter(int32_t handle, int32_t type,
                                      const Vector<float> &floats,
                                      const Vector<int32_t> &ints) {
        Parcel data, reply;
        data.writeInterfaceToken(ISensorServer::getInterfaceDescriptor());
        data.writeInt32(handle);
        data.writeInt32(type);
        data.writeUint32(static_cast<uint32_t>(floats.size()));
        for (auto i : floats) {
@@ -203,10 +205,12 @@ status_t BnSensorServer::onTransact(
        }
        case SET_OPERATION_PARAMETER: {
            CHECK_INTERFACE(ISensorServer, data, reply);
            int32_t handle;
            int32_t type;
            Vector<float> floats;
            Vector<int32_t> ints;

            handle = data.readInt32();
            type = data.readInt32();
            floats.resize(data.readUint32());
            for (auto &i : floats) {
@@ -217,7 +221,7 @@ status_t BnSensorServer::onTransact(
                i = data.readInt32();
            }

            int32_t ret = setOperationParameter(type, floats, ints);
            int32_t ret = setOperationParameter(handle, type, floats, ints);
            reply->writeInt32(ret);
            return NO_ERROR;
        }

libs/sensor/OWNERS

0 → 100644
+2 −0
Original line number Diff line number Diff line
ashutoshj@google.com
pengxu@google.com
+7 −2
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ Sensor::Sensor(const char * name) :
        mName(name), mHandle(0), mType(0),
        mMinValue(0), mMaxValue(0), mResolution(0),
        mPower(0), mMinDelay(0), mVersion(0), mFifoReservedEventCount(0),
        mFifoMaxEventCount(0), mRequiredAppOp(0),
        mFifoMaxEventCount(0), mRequiredAppOp(-1),
        mMaxDelay(0), mFlags(0) {
}

@@ -38,7 +38,8 @@ Sensor::Sensor(struct sensor_t const* hwSensor, int halVersion) :
        Sensor(*hwSensor, uuid_t(), halVersion) {
}

Sensor::Sensor(struct sensor_t const& hwSensor, const uuid_t& uuid, int halVersion) {
Sensor::Sensor(struct sensor_t const& hwSensor, const uuid_t& uuid, int halVersion) :
        Sensor("") {
    mName = hwSensor.name;
    mVendor = hwSensor.vendor;
    mVersion = hwSensor.version;
@@ -412,6 +413,10 @@ bool Sensor::isDynamicSensor() const {
    return (mFlags & SENSOR_FLAG_DYNAMIC_SENSOR) != 0;
}

bool Sensor::isDataInjectionSupported() const {
    return (mFlags & SENSOR_FLAG_DATA_INJECTION) != 0;
}

bool Sensor::hasAdditionalInfo() const {
    return (mFlags & SENSOR_FLAG_ADDITIONAL_INFO) != 0;
}
Loading