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
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) {
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;
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);
{
common.close = poll_close;
activate = poll_activate;
+ setDelay = poll_setDelay;
poll = poll_poll;
batch = poll_batch;
flush = poll_flush;
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);
{
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)
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__);
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;
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;
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)
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;