Sensors: Use a native_handle for the data channel instead of a single file descriptor.
This eliminates the requirement that all sensors share a single file descriptor. This, along with concurrent changes in other projects, fixes bugs b/1614524 and b/1614481 Signed-off-by: Mike Lockwood <lockwood@android.com>
This commit is contained in:
@@ -34,6 +34,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <cutils/log.h>
|
#include <cutils/log.h>
|
||||||
|
#include <cutils/native_handle.h>
|
||||||
#include <cutils/sockets.h>
|
#include <cutils/sockets.h>
|
||||||
#include <hardware/sensors.h>
|
#include <hardware/sensors.h>
|
||||||
|
|
||||||
@@ -123,16 +124,19 @@ typedef struct SensorControl {
|
|||||||
/* this must return a file descriptor that will be used to read
|
/* this must return a file descriptor that will be used to read
|
||||||
* the sensors data (it is passed to data__data_open() below
|
* the sensors data (it is passed to data__data_open() below
|
||||||
*/
|
*/
|
||||||
static int
|
static native_handle_t*
|
||||||
control__open_data_source(struct sensors_control_device_t *dev)
|
control__open_data_source(struct sensors_control_device_t *dev)
|
||||||
{
|
{
|
||||||
SensorControl* ctl = (void*)dev;
|
SensorControl* ctl = (void*)dev;
|
||||||
|
native_handle_t* handle;
|
||||||
|
|
||||||
if (ctl->fd < 0) {
|
if (ctl->fd < 0) {
|
||||||
ctl->fd = qemud_channel_open(SENSORS_SERVICE_NAME);
|
ctl->fd = qemud_channel_open(SENSORS_SERVICE_NAME);
|
||||||
}
|
}
|
||||||
D("%s: fd=%d", __FUNCTION__, ctl->fd);
|
D("%s: fd=%d", __FUNCTION__, ctl->fd);
|
||||||
return ctl->fd;
|
handle = native_handle_create(1, 0);
|
||||||
|
handle->data[0] = ctl->fd;
|
||||||
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@@ -244,7 +248,7 @@ data__now_ns(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
data__data_open(struct sensors_data_device_t *dev, int fd)
|
data__data_open(struct sensors_data_device_t *dev, native_handle_t* handle)
|
||||||
{
|
{
|
||||||
SensorData* data = (void*)dev;
|
SensorData* data = (void*)dev;
|
||||||
int i;
|
int i;
|
||||||
@@ -258,7 +262,9 @@ data__data_open(struct sensors_data_device_t *dev, int fd)
|
|||||||
data->timeStart = 0;
|
data->timeStart = 0;
|
||||||
data->timeOffset = 0;
|
data->timeOffset = 0;
|
||||||
|
|
||||||
data->events_fd = dup(fd);
|
data->events_fd = dup(handle->data[0]);
|
||||||
|
native_handle_close(handle);
|
||||||
|
native_handle_delete(handle);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user