am 23e8de26: propagate sensor event rate properly
Merge commit '23e8de26b7b3d04daf08526f314c2fdd2f8fee65' into gingerbread-plus-aosp * commit '23e8de26b7b3d04daf08526f314c2fdd2f8fee65': propagate sensor event rate properly
This commit is contained in:
@@ -100,13 +100,13 @@ sensors_destroy_queue(JNIEnv *env, jclass clazz, jint nativeQueue)
|
|||||||
|
|
||||||
static jboolean
|
static jboolean
|
||||||
sensors_enable_sensor(JNIEnv *env, jclass clazz,
|
sensors_enable_sensor(JNIEnv *env, jclass clazz,
|
||||||
jint nativeQueue, jstring name, jint sensor, jint enable)
|
jint nativeQueue, jstring name, jint sensor, jint delay)
|
||||||
{
|
{
|
||||||
sp<SensorEventQueue> queue(reinterpret_cast<SensorEventQueue *>(nativeQueue));
|
sp<SensorEventQueue> queue(reinterpret_cast<SensorEventQueue *>(nativeQueue));
|
||||||
if (queue == 0) return JNI_FALSE;
|
if (queue == 0) return JNI_FALSE;
|
||||||
status_t res;
|
status_t res;
|
||||||
if (enable) {
|
if (delay >= 0) {
|
||||||
res = queue->enableSensor(sensor);
|
res = queue->enableSensor(sensor, delay);
|
||||||
} else {
|
} else {
|
||||||
res = queue->disableSensor(sensor);
|
res = queue->disableSensor(sensor);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,10 +62,12 @@ public:
|
|||||||
|
|
||||||
status_t enableSensor(Sensor const* sensor) const;
|
status_t enableSensor(Sensor const* sensor) const;
|
||||||
status_t disableSensor(Sensor const* sensor) const;
|
status_t disableSensor(Sensor const* sensor) const;
|
||||||
status_t enableSensor(int32_t handle) const;
|
|
||||||
status_t disableSensor(int32_t handle) const;
|
|
||||||
status_t setEventRate(Sensor const* sensor, nsecs_t ns) const;
|
status_t setEventRate(Sensor const* sensor, nsecs_t ns) const;
|
||||||
|
|
||||||
|
// these are here only to support SensorManager.java
|
||||||
|
status_t enableSensor(int32_t handle, int32_t ms) const;
|
||||||
|
status_t disableSensor(int32_t handle) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
sp<PollLoop> getPollLoop() const;
|
sp<PollLoop> getPollLoop() const;
|
||||||
sp<ISensorEventConnection> mSensorEventConnection;
|
sp<ISensorEventConnection> mSensorEventConnection;
|
||||||
|
|||||||
@@ -114,8 +114,12 @@ status_t SensorEventQueue::disableSensor(Sensor const* sensor) const {
|
|||||||
return mSensorEventConnection->enableDisable(sensor->getHandle(), false);
|
return mSensorEventConnection->enableDisable(sensor->getHandle(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t SensorEventQueue::enableSensor(int32_t handle) const {
|
status_t SensorEventQueue::enableSensor(int32_t handle, int32_t ms) const {
|
||||||
return mSensorEventConnection->enableDisable(handle, true);
|
status_t err = mSensorEventConnection->enableDisable(handle, true);
|
||||||
|
if (err == NO_ERROR) {
|
||||||
|
mSensorEventConnection->setEventRate(handle, ms2ns(ms));
|
||||||
|
}
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t SensorEventQueue::disableSensor(int32_t handle) const {
|
status_t SensorEventQueue::disableSensor(int32_t handle) const {
|
||||||
|
|||||||
@@ -77,6 +77,9 @@ ANDROID_SINGLETON_STATIC_INSTANCE(BatteryService)
|
|||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// 100 events/s max
|
||||||
|
static const nsecs_t MINIMUM_EVENT_PERIOD = ms2ns(10);
|
||||||
|
|
||||||
SensorService::SensorService()
|
SensorService::SensorService()
|
||||||
: Thread(false),
|
: Thread(false),
|
||||||
mSensorDevice(0),
|
mSensorDevice(0),
|
||||||
@@ -284,7 +287,6 @@ status_t SensorService::disable(const sp<SensorEventConnection>& connection,
|
|||||||
status_t err = NO_ERROR;
|
status_t err = NO_ERROR;
|
||||||
Mutex::Autolock _l(mLock);
|
Mutex::Autolock _l(mLock);
|
||||||
SensorRecord* rec = mActiveSensors.valueFor(handle);
|
SensorRecord* rec = mActiveSensors.valueFor(handle);
|
||||||
LOGW("sensor (handle=%d) is not enabled", handle);
|
|
||||||
if (rec) {
|
if (rec) {
|
||||||
// see if this connection becomes inactive
|
// see if this connection becomes inactive
|
||||||
connection->removeSensor(handle);
|
connection->removeSensor(handle);
|
||||||
@@ -310,6 +312,12 @@ status_t SensorService::setRate(const sp<SensorEventConnection>& connection,
|
|||||||
if (mInitCheck != NO_ERROR)
|
if (mInitCheck != NO_ERROR)
|
||||||
return mInitCheck;
|
return mInitCheck;
|
||||||
|
|
||||||
|
if (ns < 0)
|
||||||
|
return BAD_VALUE;
|
||||||
|
|
||||||
|
if (ns < MINIMUM_EVENT_PERIOD)
|
||||||
|
ns = MINIMUM_EVENT_PERIOD;
|
||||||
|
|
||||||
status_t err = NO_ERROR;
|
status_t err = NO_ERROR;
|
||||||
Mutex::Autolock _l(mLock);
|
Mutex::Autolock _l(mLock);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user