Fix the bug that causes setDelay not working

Fix the bug that causes setDelay not working. Many native sensor
apps, such as camera EIS, still use this API.

Bug: b/27790706
Change-Id: Iaf7eeb3311a2148ca556d27dbd117e1992715644
This commit is contained in:
Peng Xu
2016-03-22 18:44:12 -07:00
parent fc2363284e
commit 2b7c19d0bc
3 changed files with 30 additions and 18 deletions

View File

@@ -888,7 +888,7 @@ void HubConnection::queueActivate(int handle, bool enable)
initConfigCmd(&cmd, handle);
ALOGI("queueActive: sensor=%d, enable=%d", cmd.sensorType, enable);
ALOGI("queueActive: sensor=%d, handle=%d, enable=%d", cmd.sensorType, handle, enable);
do {
ret = write(mFd, &cmd, sizeof(cmd));
} while(ret != sizeof(cmd));
@@ -897,47 +897,53 @@ void HubConnection::queueActivate(int handle, bool enable)
}
}
void HubConnection::queueSetDelay(int handle, nsecs_t delayNs)
void HubConnection::queueSetDelay(int handle, nsecs_t sampling_period_ns)
{
struct ConfigCmd cmd;
int ret;
if (mSensorState[handle].sensorType) {
mSensorState[handle].latency = delayNs;
mSensorState[handle].rate = period_ns_to_frequency_q10(sampling_period_ns);
initConfigCmd(&cmd, handle);
ALOGI("queueSetDelay: sensor=%d, delay=%" PRId64, cmd.sensorType, delayNs);
ALOGI("queueSetDelay: sensor=%d, handle=%d, period=%" PRId64,
cmd.sensorType, handle, sampling_period_ns);
do {
ret = write(mFd, &cmd, sizeof(cmd));
} while(ret != sizeof(cmd));
} else {
ALOGI("queueSetDelay: unhandled handle=%d, delay=%" PRId64, handle, delayNs);
ALOGI("queueSetDelay: unhandled handle=%d, period=%" PRId64, handle, sampling_period_ns);
}
}
void HubConnection::queueBatch(
int handle,
__attribute__((unused)) int flags,
int64_t sampling_period_ns,
int64_t max_report_latency_ns)
nsecs_t sampling_period_ns,
nsecs_t max_report_latency_ns)
{
struct ConfigCmd cmd;
int ret;
if (mSensorState[handle].sensorType) {
if (sampling_period_ns > 0 && mSensorState[handle].rate != SENSOR_RATE_ONCHANGE && mSensorState[handle].rate != SENSOR_RATE_ONESHOT)
mSensorState[handle].rate = 1024000000000ULL / sampling_period_ns;
if (sampling_period_ns > 0 &&
mSensorState[handle].rate != SENSOR_RATE_ONCHANGE &&
mSensorState[handle].rate != SENSOR_RATE_ONESHOT) {
mSensorState[handle].rate = period_ns_to_frequency_q10(sampling_period_ns);
}
mSensorState[handle].latency = max_report_latency_ns;
initConfigCmd(&cmd, handle);
ALOGI("queueBatch: sensor=%d, period=%" PRId64 ", latency=%" PRId64, cmd.sensorType, sampling_period_ns, max_report_latency_ns);
ALOGI("queueBatch: sensor=%d, handle=%d, period=%" PRId64 ", latency=%" PRId64,
cmd.sensorType, handle, sampling_period_ns, max_report_latency_ns);
do {
ret = write(mFd, &cmd, sizeof(cmd));
} while(ret != sizeof(cmd));
} else {
ALOGI("queueBatch: unhandled handle=%d, period=%" PRId64 ", latency=%" PRId64, handle, sampling_period_ns, max_report_latency_ns);
ALOGI("queueBatch: unhandled handle=%d, period=%" PRId64 ", latency=%" PRId64,
handle, sampling_period_ns, max_report_latency_ns);
}
}
@@ -952,7 +958,7 @@ void HubConnection::queueFlush(int handle)
initConfigCmd(&cmd, handle);
cmd.cmd = CONFIG_CMD_FLUSH;
ALOGI("queueFlush: sensor=%d", cmd.sensorType);
ALOGI("queueFlush: sensor=%d, handle=%d", cmd.sensorType, handle);
do {
ret = write(mFd, &cmd, sizeof(cmd));
} while(ret != sizeof(cmd));

View File

@@ -58,8 +58,8 @@ struct HubConnection : public Thread {
void queueBatch(
int handle,
int flags,
int64_t sampling_period_ns,
int64_t max_report_latency_ns);
nsecs_t sampling_period_ns,
nsecs_t max_report_latency_ns);
void queueFlush(int handle);
@@ -83,6 +83,12 @@ protected:
virtual void onFirstRef();
private:
typedef uint32_t rate_q10_t; // q10 means lower 10 bits are for fractions
static inline uint64_t period_ns_to_frequency_q10(nsecs_t period_ns) {
return 1024000000000ULL / period_ns;
}
enum
{
CONFIG_CMD_DISABLE = 0,
@@ -96,7 +102,7 @@ private:
{
uint32_t evtType;
uint64_t latency;
uint32_t rate;
rate_q10_t rate;
uint8_t sensorType;
uint8_t cmd;
uint16_t flags;
@@ -111,7 +117,7 @@ private:
struct SensorState {
uint64_t latency;
uint32_t rate;
rate_q10_t rate;
uint8_t sensorType;
uint8_t alt;
uint8_t flushCnt;

View File

@@ -580,7 +580,7 @@ int SensorContext::setDelay(int handle, int64_t delayNs) {
continue;
}
if ((sensor.flags & 0xE) == SENSOR_FLAG_CONTINUOUS_MODE) {
if ((sensor.flags & REPORTING_MODE_MASK) == SENSOR_FLAG_CONTINUOUS_MODE) {
if ((delayNs/1000) < sensor.minDelay) {
delayNsClamped = sensor.minDelay * 1000;
} else if ((delayNs/1000) > sensor.maxDelay) {
@@ -624,7 +624,7 @@ int SensorContext::batch(
continue;
}
if ((sensor.flags & 0xE) == SENSOR_FLAG_CONTINUOUS_MODE) {
if ((sensor.flags & REPORTING_MODE_MASK) == SENSOR_FLAG_CONTINUOUS_MODE) {
if ((sampling_period_ns/1000) < sensor.minDelay) {
sampling_period_ns_clamped = sensor.minDelay * 1000;
} else if ((sampling_period_ns/1000) > sensor.maxDelay) {