OSDN Git Service

Add back the setDelay function
authorChih-Wei Huang <cwhuang@linux.org.tw>
Tue, 30 Jan 2018 06:04:53 +0000 (14:04 +0800)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Tue, 30 Jan 2018 06:04:53 +0000 (14:04 +0800)
According to https://source.android.com/devices/sensors/versioning

"Implement the batch function

... It replaces setDelay. setDelay will not be called anymore."

However, it is wrong. The setDelay is still called sometimes
as show in the system_server crashing log:

01-26 18:36:11.536 27879 27879 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
01-26 18:36:11.536 27879 27879 F DEBUG   : Build fingerprint: 'Android-x86/android_x86_64/x86_64:7.1.2/N2G48H/cwhuan01041741:userdebug/test-keys'
01-26 18:36:11.536 27879 27879 F DEBUG   : Revision: '0'
01-26 18:36:11.537 27879 27879 F DEBUG   : ABI: 'x86_64'
01-26 18:36:11.537 27879 27879 F DEBUG   : pid: 24500, tid: 27162, name: Binder:24500_12  >>> system_server <<<
01-26 18:36:11.537 27879 27879 F DEBUG   : signal 11 (SIGSEGV), code 128 (SI_KERNEL), fault addr 0x0
01-26 18:36:11.537 27879 27879 F DEBUG   :     rax 332f83dbf746df52  rbx 0000794e04c48500  rcx 0000000000000000  rdx 0000000001312d00
01-26 18:36:11.537 27879 27879 F DEBUG   :     rsi 0000000000000000  rdi 0000794e04d19000
01-26 18:36:11.537 27879 27879 F DEBUG   :     r8  0000794df0f4f7b0  r9  0000794e0c62d47a  r10 000000000000006e  r11 0000000000000246
01-26 18:36:11.537 27879 27879 F DEBUG   :     r12 0000794e04c1b938  r13 0000000001312d00  r14 0000794e04c48518  r15 0000000000000000
01-26 18:36:11.537 27879 27879 F DEBUG   :     cs  0000000000000033  ss  000000000000002b
01-26 18:36:11.537 27879 27879 F DEBUG   :     rip 0000794e0af228ca  rbp 0000794e04c1b920  rsp 0000794decc04fc0  eflags 0000000000010206
01-26 18:36:11.542 27879 27879 F DEBUG   :
01-26 18:36:11.542 27879 27879 F DEBUG   : backtrace:
01-26 18:36:11.542 27879 27879 F DEBUG   :     #00 pc 00000000000128ca  /system/lib64/libsensorservice.so
01-26 18:36:11.542 27879 27879 F DEBUG   :     #01 pc 000000000001e51b  /system/lib64/libsensorservice.so
01-26 18:36:11.542 27879 27879 F DEBUG   :     #02 pc 00000000000151af  /system/lib64/libsensorservice.so

hdaps.c
kbdsensor.cpp
s103t_sensor.c
w500_sensor.c

diff --git a/hdaps.c b/hdaps.c
index c524aa2..09da80b 100644 (file)
--- a/hdaps.c
+++ b/hdaps.c
@@ -89,6 +89,13 @@ static int device__activate(struct sensors_poll_device_t *dev, int handle,
        return 0;
 }
 
+static int device__set_delay(struct sensors_poll_device_t *device, int handle,
+               int64_t ns) {
+       forced_delay = ns / 1000;
+       return 0;
+
+}
+
 static int device__poll(struct sensors_poll_device_t *device,
                sensors_event_t *data, int count) {
 
@@ -304,6 +311,7 @@ static int open_sensors(const struct hw_module_t* module, const char* name,
        dev->device.common.module = (struct hw_module_t*) module;
        dev->device.common.close = common__close;
        dev->device.activate = device__activate;
+       dev->device.setDelay = device__set_delay;
        dev->device.poll = device__poll;
        dev->device.batch = device__batch;
        dev->device.flush = device__flush;
index 3a4ec3a..79864f1 100644 (file)
@@ -64,6 +64,7 @@ struct SensorPollContext : SensorFd<sensors_poll_device_1> {
   private:
        static int poll_close(struct hw_device_t *dev);
        static int poll_activate(struct sensors_poll_device_t *dev, int handle, int enabled);
+       static int poll_setDelay(struct sensors_poll_device_t *dev, int handle, int64_t ns);
        static int poll_poll(struct sensors_poll_device_t *dev, sensors_event_t *data, int count);
        static int poll_batch(struct sensors_poll_device_1* dev, int sensor_handle, int flags, int64_t sampling_period_ns, int64_t max_report_latency_ns);
        static int poll_flush(struct sensors_poll_device_1* dev, int sensor_handle);
@@ -90,6 +91,7 @@ SensorPollContext::SensorPollContext(const struct hw_module_t *module, struct hw
 {
        common.close = poll_close;
        activate     = poll_activate;
+       setDelay     = poll_setDelay;
        poll         = poll_poll;
        batch        = poll_batch;
        flush        = poll_flush;
@@ -187,6 +189,14 @@ int SensorPollContext::poll_activate(struct sensors_poll_device_t *dev, int hand
        return 0;
 }
 
+int SensorPollContext::poll_setDelay(struct sensors_poll_device_t *dev, int handle, int64_t ns)
+{
+       ALOGD("%s: dev=%p handle=%d ns=%" PRId64, __FUNCTION__, dev, handle, ns);
+       SensorPollContext *ctx = reinterpret_cast<SensorPollContext *>(dev);
+       ctx->sampling_period_ns = ns;
+       return EXIT_SUCCESS;
+}
+
 int SensorPollContext::poll_poll(struct sensors_poll_device_t *dev, sensors_event_t *data, int count)
 {
        ALOGV("%s: dev=%p data=%p count=%d", __FUNCTION__, dev, data, count);
@@ -198,9 +208,7 @@ int SensorPollContext::poll_batch(struct sensors_poll_device_1* dev, int sensor_
 {
        ALOGD("%s: dev=%p sensor_handle=%d flags=%d sampling_period_ns=%" PRId64 " max_report_latency_ns=%" PRId64,
                        __FUNCTION__, dev, sensor_handle, flags, sampling_period_ns, max_report_latency_ns);
-       SensorPollContext *ctx = reinterpret_cast<SensorPollContext *>(dev);
-       ctx->sampling_period_ns = sampling_period_ns;
-       return EXIT_SUCCESS;
+       return poll_setDelay(&dev->v0, sensor_handle, sampling_period_ns);
 }
 
 int SensorPollContext::poll_flush(struct sensors_poll_device_1* dev, int sensor_handle)
index 37abf04..8ea3a8a 100644 (file)
@@ -37,6 +37,12 @@ static int context__activate(struct sensors_poll_device_t *dev, int handle, int
     return 0;
 }
 
+static int context__setDelay(struct sensors_poll_device_t *dev, int handle, int64_t ns)
+{
+    ALOGD("%s: called", __FUNCTION__);
+    return 0;
+}
+
 static int context__close(struct hw_device_t *dev)
 {
     ALOGD("%s: called", __FUNCTION__);
@@ -189,6 +195,7 @@ static int open_sensors(const struct hw_module_t* module, const char* id, struct
 
     ctx->device.common.close = context__close;
     ctx->device.activate = context__activate;
+    ctx->device.setDelay = context__setDelay;
     ctx->device.poll = context__poll;
     ctx->device.batch = context__batch;
     ctx->device.flush = context__flush;
index 8f925a0..6c76d56 100644 (file)
@@ -138,6 +138,17 @@ static int context__activate(struct sensors_poll_device_t *dev,
        return -EINVAL;
 }
 
+static int context__setDelay(struct sensors_poll_device_t *dev,
+                               int handle, int64_t ns)
+{
+       struct sensor_context* ctx = (struct sensor_context *)dev;
+
+       ctx->delay.tv_sec = 0;
+       ctx->delay.tv_nsec = ns;
+
+       return 0;
+}
+
 static int context__close(struct hw_device_t *dev)
 {
        struct sensor_context* ctx = (struct sensor_context *)dev;
@@ -348,10 +359,7 @@ static int context__batch(struct sensors_poll_device_1* dev, int sensor_handle,
        ALOGD("%s: dev=%p sensor_handle=%d flags=%d sampling_period_ns=%" PRId64 " max_report_latency_ns=%" PRId64,
                        __FUNCTION__, dev, sensor_handle, flags, sampling_period_ns, max_report_latency_ns);
 
-       struct sensor_context* ctx = (struct sensor_context *)dev;
-       ctx->delay.tv_sec = 0;
-       ctx->delay.tv_nsec = sampling_period_ns;
-       return EXIT_SUCCESS;
+       return context__setDelay(&dev->v0, sensor_handle, sampling_period_ns);
 }
 
 static int context__flush(struct sensors_poll_device_1* dev, int sensor_handle)
@@ -431,6 +439,7 @@ static int open_sensors(const struct hw_module_t *module, const char* id,
        ctx->device.common.close = context__close;
 
        ctx->device.activate = context__activate;
+       ctx->device.setDelay = context__setDelay;
        ctx->device.poll = context__poll;
        ctx->device.batch = context__batch;
        ctx->device.flush = context__flush;