2010-07-15 06:41:37 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2014-03-12 20:12:44 +00:00
|
|
|
#include <inttypes.h>
|
2010-11-12 01:58:51 +00:00
|
|
|
#include <math.h>
|
2014-03-12 20:12:44 +00:00
|
|
|
#include <stdint.h>
|
2010-07-15 06:41:37 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
2011-05-28 01:18:13 +00:00
|
|
|
#include <cutils/properties.h>
|
|
|
|
|
2010-07-15 06:41:37 +00:00
|
|
|
#include <utils/SortedVector.h>
|
|
|
|
#include <utils/KeyedVector.h>
|
|
|
|
#include <utils/threads.h>
|
|
|
|
#include <utils/Atomic.h>
|
|
|
|
#include <utils/Errors.h>
|
|
|
|
#include <utils/RefBase.h>
|
2010-07-19 22:03:55 +00:00
|
|
|
#include <utils/Singleton.h>
|
2010-07-23 05:19:43 +00:00
|
|
|
#include <utils/String16.h>
|
2010-07-15 06:41:37 +00:00
|
|
|
|
|
|
|
#include <binder/BinderService.h>
|
2010-07-19 22:03:55 +00:00
|
|
|
#include <binder/IServiceManager.h>
|
2011-06-27 23:05:52 +00:00
|
|
|
#include <binder/PermissionCache.h>
|
2010-07-15 06:41:37 +00:00
|
|
|
|
|
|
|
#include <gui/ISensorServer.h>
|
|
|
|
#include <gui/ISensorEventConnection.h>
|
2012-04-03 01:38:02 +00:00
|
|
|
#include <gui/SensorEventQueue.h>
|
2010-07-15 06:41:37 +00:00
|
|
|
|
|
|
|
#include <hardware/sensors.h>
|
2013-04-08 23:43:12 +00:00
|
|
|
#include <hardware_legacy/power.h>
|
2010-07-15 06:41:37 +00:00
|
|
|
|
2012-09-19 01:49:18 +00:00
|
|
|
#include "BatteryService.h"
|
2011-05-18 05:54:42 +00:00
|
|
|
#include "CorrectedGyroSensor.h"
|
2010-11-12 01:58:51 +00:00
|
|
|
#include "GravitySensor.h"
|
|
|
|
#include "LinearAccelerationSensor.h"
|
2011-05-18 05:54:42 +00:00
|
|
|
#include "OrientationSensor.h"
|
2010-11-12 01:58:51 +00:00
|
|
|
#include "RotationVectorSensor.h"
|
2011-05-18 05:54:42 +00:00
|
|
|
#include "SensorFusion.h"
|
|
|
|
#include "SensorService.h"
|
2010-07-15 06:41:37 +00:00
|
|
|
|
|
|
|
namespace android {
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2011-05-28 01:18:13 +00:00
|
|
|
/*
|
|
|
|
* Notes:
|
|
|
|
*
|
|
|
|
* - what about a gyro-corrected magnetic-field sensor?
|
|
|
|
* - run mag sensor from time to time to force calibration
|
|
|
|
* - gravity sensor length is wrong (=> drift in linear-acc sensor)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-04-08 23:43:12 +00:00
|
|
|
const char* SensorService::WAKE_LOCK_NAME = "SensorService";
|
|
|
|
|
2010-07-15 06:41:37 +00:00
|
|
|
SensorService::SensorService()
|
2011-06-27 23:05:52 +00:00
|
|
|
: mInitCheck(NO_INIT)
|
2010-07-15 06:41:37 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void SensorService::onFirstRef()
|
|
|
|
{
|
2011-12-20 16:23:08 +00:00
|
|
|
ALOGD("nuSensorService starting...");
|
2010-07-20 02:09:10 +00:00
|
|
|
|
2010-11-12 01:58:51 +00:00
|
|
|
SensorDevice& dev(SensorDevice::getInstance());
|
2010-07-15 06:41:37 +00:00
|
|
|
|
2010-11-12 01:58:51 +00:00
|
|
|
if (dev.initCheck() == NO_ERROR) {
|
|
|
|
sensor_t const* list;
|
2011-07-14 23:39:46 +00:00
|
|
|
ssize_t count = dev.getSensorList(&list);
|
|
|
|
if (count > 0) {
|
|
|
|
ssize_t orientationIndex = -1;
|
|
|
|
bool hasGyro = false;
|
|
|
|
uint32_t virtualSensorsNeeds =
|
|
|
|
(1<<SENSOR_TYPE_GRAVITY) |
|
|
|
|
(1<<SENSOR_TYPE_LINEAR_ACCELERATION) |
|
|
|
|
(1<<SENSOR_TYPE_ROTATION_VECTOR);
|
|
|
|
|
|
|
|
mLastEventSeen.setCapacity(count);
|
|
|
|
for (ssize_t i=0 ; i<count ; i++) {
|
|
|
|
registerSensor( new HardwareSensor(list[i]) );
|
|
|
|
switch (list[i].type) {
|
|
|
|
case SENSOR_TYPE_ORIENTATION:
|
|
|
|
orientationIndex = i;
|
|
|
|
break;
|
|
|
|
case SENSOR_TYPE_GYROSCOPE:
|
2013-05-11 02:32:39 +00:00
|
|
|
case SENSOR_TYPE_GYROSCOPE_UNCALIBRATED:
|
2011-07-14 23:39:46 +00:00
|
|
|
hasGyro = true;
|
|
|
|
break;
|
|
|
|
case SENSOR_TYPE_GRAVITY:
|
|
|
|
case SENSOR_TYPE_LINEAR_ACCELERATION:
|
|
|
|
case SENSOR_TYPE_ROTATION_VECTOR:
|
|
|
|
virtualSensorsNeeds &= ~(1<<list[i].type);
|
|
|
|
break;
|
|
|
|
}
|
2010-07-20 02:09:10 +00:00
|
|
|
}
|
2010-07-15 06:41:37 +00:00
|
|
|
|
2011-07-14 23:39:46 +00:00
|
|
|
// it's safe to instantiate the SensorFusion object here
|
|
|
|
// (it wants to be instantiated after h/w sensors have been
|
|
|
|
// registered)
|
|
|
|
const SensorFusion& fusion(SensorFusion::getInstance());
|
|
|
|
|
2013-05-11 02:32:39 +00:00
|
|
|
// build the sensor list returned to users
|
|
|
|
mUserSensorList = mSensorList;
|
|
|
|
|
2011-07-14 23:39:46 +00:00
|
|
|
if (hasGyro) {
|
2013-05-11 02:32:39 +00:00
|
|
|
Sensor aSensor;
|
2011-07-14 23:39:46 +00:00
|
|
|
|
2013-05-11 02:32:39 +00:00
|
|
|
// Add Android virtual sensors if they're not already
|
|
|
|
// available in the HAL
|
2011-07-14 23:39:46 +00:00
|
|
|
|
2013-05-11 02:32:39 +00:00
|
|
|
aSensor = registerVirtualSensor( new RotationVectorSensor() );
|
|
|
|
if (virtualSensorsNeeds & (1<<SENSOR_TYPE_ROTATION_VECTOR)) {
|
|
|
|
mUserSensorList.add(aSensor);
|
|
|
|
}
|
2010-11-12 01:58:51 +00:00
|
|
|
|
2013-05-11 02:32:39 +00:00
|
|
|
aSensor = registerVirtualSensor( new GravitySensor(list, count) );
|
|
|
|
if (virtualSensorsNeeds & (1<<SENSOR_TYPE_GRAVITY)) {
|
|
|
|
mUserSensorList.add(aSensor);
|
|
|
|
}
|
2012-06-29 02:46:54 +00:00
|
|
|
|
2013-05-11 02:32:39 +00:00
|
|
|
aSensor = registerVirtualSensor( new LinearAccelerationSensor(list, count) );
|
|
|
|
if (virtualSensorsNeeds & (1<<SENSOR_TYPE_LINEAR_ACCELERATION)) {
|
|
|
|
mUserSensorList.add(aSensor);
|
|
|
|
}
|
2012-06-29 02:46:54 +00:00
|
|
|
|
2013-05-11 02:32:39 +00:00
|
|
|
aSensor = registerVirtualSensor( new OrientationSensor() );
|
|
|
|
if (virtualSensorsNeeds & (1<<SENSOR_TYPE_ROTATION_VECTOR)) {
|
|
|
|
// if we are doing our own rotation-vector, also add
|
|
|
|
// the orientation sensor and remove the HAL provided one.
|
|
|
|
mUserSensorList.replaceAt(aSensor, orientationIndex);
|
2011-07-14 23:39:46 +00:00
|
|
|
}
|
2013-05-11 02:32:39 +00:00
|
|
|
|
|
|
|
// virtual debugging sensors are not added to mUserSensorList
|
|
|
|
registerVirtualSensor( new CorrectedGyroSensor(list, count) );
|
|
|
|
registerVirtualSensor( new GyroDriftSensor() );
|
2011-06-09 03:06:50 +00:00
|
|
|
}
|
|
|
|
|
2012-06-29 02:46:54 +00:00
|
|
|
// debugging sensor list
|
2013-05-11 02:32:39 +00:00
|
|
|
mUserSensorListDebug = mSensorList;
|
2012-06-29 02:46:54 +00:00
|
|
|
|
2013-09-06 00:03:38 +00:00
|
|
|
mSocketBufferSize = SOCKET_BUFFER_SIZE_NON_BATCHED;
|
|
|
|
FILE *fp = fopen("/proc/sys/net/core/wmem_max", "r");
|
|
|
|
char line[128];
|
|
|
|
if (fp != NULL && fgets(line, sizeof(line), fp) != NULL) {
|
|
|
|
line[sizeof(line) - 1] = '\0';
|
2014-03-12 20:12:44 +00:00
|
|
|
sscanf(line, "%zu", &mSocketBufferSize);
|
2013-09-06 00:03:38 +00:00
|
|
|
if (mSocketBufferSize > MAX_SOCKET_BUFFER_SIZE_BATCHED) {
|
|
|
|
mSocketBufferSize = MAX_SOCKET_BUFFER_SIZE_BATCHED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fp) {
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
2014-02-12 02:58:52 +00:00
|
|
|
mWakeLockAcquired = false;
|
2011-07-14 23:39:46 +00:00
|
|
|
run("SensorService", PRIORITY_URGENT_DISPLAY);
|
|
|
|
mInitCheck = NO_ERROR;
|
|
|
|
}
|
2010-07-15 06:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-11 02:32:39 +00:00
|
|
|
Sensor SensorService::registerSensor(SensorInterface* s)
|
2010-11-12 01:58:51 +00:00
|
|
|
{
|
|
|
|
sensors_event_t event;
|
|
|
|
memset(&event, 0, sizeof(event));
|
|
|
|
|
|
|
|
const Sensor sensor(s->getSensor());
|
|
|
|
// add to the sensor list (returned to clients)
|
|
|
|
mSensorList.add(sensor);
|
|
|
|
// add to our handle->SensorInterface mapping
|
|
|
|
mSensorMap.add(sensor.getHandle(), s);
|
|
|
|
// create an entry in the mLastEventSeen array
|
|
|
|
mLastEventSeen.add(sensor.getHandle(), event);
|
2013-05-11 02:32:39 +00:00
|
|
|
|
|
|
|
return sensor;
|
2010-11-12 01:58:51 +00:00
|
|
|
}
|
|
|
|
|
2013-05-11 02:32:39 +00:00
|
|
|
Sensor SensorService::registerVirtualSensor(SensorInterface* s)
|
2010-11-12 01:58:51 +00:00
|
|
|
{
|
2013-05-11 02:32:39 +00:00
|
|
|
Sensor sensor = registerSensor(s);
|
2010-11-12 01:58:51 +00:00
|
|
|
mVirtualSensorList.add( s );
|
2013-05-11 02:32:39 +00:00
|
|
|
return sensor;
|
2010-11-12 01:58:51 +00:00
|
|
|
}
|
|
|
|
|
2010-07-15 06:41:37 +00:00
|
|
|
SensorService::~SensorService()
|
|
|
|
{
|
2010-11-12 01:58:51 +00:00
|
|
|
for (size_t i=0 ; i<mSensorMap.size() ; i++)
|
|
|
|
delete mSensorMap.valueAt(i);
|
2010-07-15 06:41:37 +00:00
|
|
|
}
|
|
|
|
|
2011-06-27 23:05:52 +00:00
|
|
|
static const String16 sDump("android.permission.DUMP");
|
|
|
|
|
2014-03-12 20:12:44 +00:00
|
|
|
status_t SensorService::dump(int fd, const Vector<String16>& /*args*/)
|
2010-07-15 06:41:37 +00:00
|
|
|
{
|
|
|
|
String8 result;
|
2011-06-27 23:05:52 +00:00
|
|
|
if (!PermissionCache::checkCallingPermission(sDump)) {
|
2013-07-03 23:20:57 +00:00
|
|
|
result.appendFormat("Permission Denial: "
|
2014-04-07 22:52:37 +00:00
|
|
|
"can't dump SensorService from pid=%d, uid=%d\n",
|
2010-07-15 06:41:37 +00:00
|
|
|
IPCThreadState::self()->getCallingPid(),
|
|
|
|
IPCThreadState::self()->getCallingUid());
|
|
|
|
} else {
|
|
|
|
Mutex::Autolock _l(mLock);
|
2013-07-03 23:20:57 +00:00
|
|
|
result.append("Sensor List:\n");
|
2010-07-23 04:24:39 +00:00
|
|
|
for (size_t i=0 ; i<mSensorList.size() ; i++) {
|
|
|
|
const Sensor& s(mSensorList[i]);
|
|
|
|
const sensors_event_t& e(mLastEventSeen.valueFor(s.getHandle()));
|
2013-07-03 23:20:57 +00:00
|
|
|
result.appendFormat(
|
2014-04-07 22:52:37 +00:00
|
|
|
"%-48s| %-32s| %-48s| 0x%08x | \"%s\"\n\t",
|
2010-07-23 04:24:39 +00:00
|
|
|
s.getName().string(),
|
|
|
|
s.getVendor().string(),
|
2014-04-07 22:52:37 +00:00
|
|
|
s.getStringType().string(),
|
|
|
|
s.getHandle(),
|
|
|
|
s.getRequiredPermission().string());
|
2013-07-03 23:20:57 +00:00
|
|
|
|
2014-06-04 02:19:57 +00:00
|
|
|
const int reportingMode = s.getReportingMode();
|
|
|
|
if (reportingMode == AREPORTING_MODE_CONTINUOUS) {
|
|
|
|
result.append("continuous |");
|
|
|
|
} else if (reportingMode == AREPORTING_MODE_ON_CHANGE) {
|
|
|
|
result.append("on-change | ");
|
|
|
|
} else if (reportingMode == AREPORTING_MODE_ONE_SHOT) {
|
|
|
|
result.append("one-shot | ");
|
|
|
|
} else {
|
|
|
|
result.append("special-trigger | ");
|
|
|
|
}
|
|
|
|
|
2013-07-03 23:20:57 +00:00
|
|
|
if (s.getMinDelay() > 0) {
|
2014-06-04 02:19:57 +00:00
|
|
|
result.appendFormat("maxRate=%7.2fHz | ", 1e6f / s.getMinDelay());
|
2013-07-03 23:20:57 +00:00
|
|
|
} else {
|
2014-06-04 02:19:57 +00:00
|
|
|
result.appendFormat("minDelay=%5dus |", s.getMinDelay());
|
2013-07-03 23:20:57 +00:00
|
|
|
}
|
2014-06-04 02:19:57 +00:00
|
|
|
|
2013-06-27 19:04:23 +00:00
|
|
|
if (s.getFifoMaxEventCount() > 0) {
|
2014-04-07 22:52:37 +00:00
|
|
|
result.appendFormat("FifoMax=%d events | ",
|
|
|
|
s.getFifoMaxEventCount());
|
2013-06-27 19:04:23 +00:00
|
|
|
} else {
|
|
|
|
result.append("no batching support | ");
|
|
|
|
}
|
2013-07-03 23:20:57 +00:00
|
|
|
|
|
|
|
switch (s.getType()) {
|
|
|
|
case SENSOR_TYPE_ROTATION_VECTOR:
|
|
|
|
case SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR:
|
|
|
|
result.appendFormat(
|
|
|
|
"last=<%5.1f,%5.1f,%5.1f,%5.1f,%5.1f>\n",
|
|
|
|
e.data[0], e.data[1], e.data[2], e.data[3], e.data[4]);
|
|
|
|
break;
|
|
|
|
case SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED:
|
|
|
|
case SENSOR_TYPE_GYROSCOPE_UNCALIBRATED:
|
|
|
|
result.appendFormat(
|
|
|
|
"last=<%5.1f,%5.1f,%5.1f,%5.1f,%5.1f,%5.1f>\n",
|
|
|
|
e.data[0], e.data[1], e.data[2], e.data[3], e.data[4], e.data[5]);
|
|
|
|
break;
|
|
|
|
case SENSOR_TYPE_GAME_ROTATION_VECTOR:
|
|
|
|
result.appendFormat(
|
|
|
|
"last=<%5.1f,%5.1f,%5.1f,%5.1f>\n",
|
|
|
|
e.data[0], e.data[1], e.data[2], e.data[3]);
|
|
|
|
break;
|
|
|
|
case SENSOR_TYPE_SIGNIFICANT_MOTION:
|
|
|
|
case SENSOR_TYPE_STEP_DETECTOR:
|
|
|
|
result.appendFormat( "last=<%f>\n", e.data[0]);
|
|
|
|
break;
|
|
|
|
case SENSOR_TYPE_STEP_COUNTER:
|
2014-03-12 20:12:44 +00:00
|
|
|
result.appendFormat( "last=<%" PRIu64 ">\n", e.u64.step_counter);
|
2013-07-03 23:20:57 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// default to 3 values
|
|
|
|
result.appendFormat(
|
|
|
|
"last=<%5.1f,%5.1f,%5.1f>\n",
|
|
|
|
e.data[0], e.data[1], e.data[2]);
|
|
|
|
break;
|
|
|
|
}
|
2010-07-23 04:24:39 +00:00
|
|
|
}
|
2013-07-03 23:20:57 +00:00
|
|
|
SensorFusion::getInstance().dump(result);
|
|
|
|
SensorDevice::getInstance().dump(result);
|
|
|
|
|
|
|
|
result.append("Active sensors:\n");
|
2010-07-15 06:41:37 +00:00
|
|
|
for (size_t i=0 ; i<mActiveSensors.size() ; i++) {
|
2010-07-19 22:20:39 +00:00
|
|
|
int handle = mActiveSensors.keyAt(i);
|
2014-03-12 20:12:44 +00:00
|
|
|
result.appendFormat("%s (handle=0x%08x, connections=%zu)\n",
|
2010-07-19 22:20:39 +00:00
|
|
|
getSensorName(handle).string(),
|
|
|
|
handle,
|
2010-07-15 06:41:37 +00:00
|
|
|
mActiveSensors.valueAt(i)->getNumConnections());
|
|
|
|
}
|
2013-09-06 00:03:38 +00:00
|
|
|
|
2014-03-12 20:12:44 +00:00
|
|
|
result.appendFormat("%zu Max Socket Buffer size\n", mSocketBufferSize);
|
2014-02-12 02:58:52 +00:00
|
|
|
result.appendFormat("WakeLock Status: %s \n", mWakeLockAcquired ? "acquired" : "not held");
|
2014-03-12 20:12:44 +00:00
|
|
|
result.appendFormat("%zd active connections\n", mActiveConnections.size());
|
2013-09-06 00:03:38 +00:00
|
|
|
|
|
|
|
for (size_t i=0 ; i < mActiveConnections.size() ; i++) {
|
|
|
|
sp<SensorEventConnection> connection(mActiveConnections[i].promote());
|
|
|
|
if (connection != 0) {
|
2014-03-12 20:12:44 +00:00
|
|
|
result.appendFormat("Connection Number: %zu \n", i);
|
2013-09-06 00:03:38 +00:00
|
|
|
connection->dump(result);
|
|
|
|
}
|
|
|
|
}
|
2010-07-15 06:41:37 +00:00
|
|
|
}
|
|
|
|
write(fd, result.string(), result.size());
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2014-02-12 02:58:52 +00:00
|
|
|
void SensorService::cleanupAutoDisabledSensorLocked(const sp<SensorEventConnection>& connection,
|
2013-04-08 23:43:12 +00:00
|
|
|
sensors_event_t const* buffer, const int count) {
|
|
|
|
for (int i=0 ; i<count ; i++) {
|
|
|
|
int handle = buffer[i].sensor;
|
2014-06-04 02:19:57 +00:00
|
|
|
if (connection->hasSensor(handle)) {
|
|
|
|
SensorInterface* sensor = mSensorMap.valueFor(handle);
|
|
|
|
// If this buffer has an event from a one_shot sensor and this connection is registered
|
|
|
|
// for this particular one_shot sensor, try cleaning up the connection.
|
|
|
|
if (sensor != NULL &&
|
|
|
|
sensor->getSensor().getReportingMode() == AREPORTING_MODE_ONE_SHOT) {
|
|
|
|
sensor->autoDisable(connection.get(), handle);
|
2014-02-12 02:58:52 +00:00
|
|
|
cleanupWithoutDisableLocked(connection, handle);
|
2013-04-08 23:43:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-15 06:41:37 +00:00
|
|
|
bool SensorService::threadLoop()
|
|
|
|
{
|
2011-12-20 16:23:08 +00:00
|
|
|
ALOGD("nuSensorService thread starting...");
|
2010-07-15 06:41:37 +00:00
|
|
|
|
2013-09-10 06:36:25 +00:00
|
|
|
// each virtual sensor could generate an event per "real" event, that's why we need
|
|
|
|
// to size numEventMax much smaller than MAX_RECEIVE_BUFFER_EVENT_COUNT.
|
|
|
|
// in practice, this is too aggressive, but guaranteed to be enough.
|
|
|
|
const size_t minBufferSize = SensorEventQueue::MAX_RECEIVE_BUFFER_EVENT_COUNT;
|
|
|
|
const size_t numEventMax = minBufferSize / (1 + mVirtualSensorList.size());
|
|
|
|
|
2012-05-30 02:46:14 +00:00
|
|
|
sensors_event_t buffer[minBufferSize];
|
|
|
|
sensors_event_t scratch[minBufferSize];
|
2010-11-12 01:58:51 +00:00
|
|
|
SensorDevice& device(SensorDevice::getInstance());
|
|
|
|
const size_t vcount = mVirtualSensorList.size();
|
2010-07-15 06:41:37 +00:00
|
|
|
|
2010-11-12 01:58:51 +00:00
|
|
|
ssize_t count;
|
2013-04-08 23:43:12 +00:00
|
|
|
const int halVersion = device.getHalDeviceVersion();
|
2010-07-15 06:41:37 +00:00
|
|
|
do {
|
2010-11-12 01:58:51 +00:00
|
|
|
count = device.poll(buffer, numEventMax);
|
2010-07-15 06:41:37 +00:00
|
|
|
if (count<0) {
|
2012-01-06 19:20:56 +00:00
|
|
|
ALOGE("sensor poll failed (%s)", strerror(-count));
|
2010-07-15 06:41:37 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-02-12 02:58:52 +00:00
|
|
|
Mutex::Autolock _l(mLock);
|
|
|
|
// Poll has returned. Hold a wakelock if one of the events is from a wake up sensor. The
|
|
|
|
// rest of this loop is under a critical section protected by mLock. Acquiring a wakeLock,
|
|
|
|
// sending events to clients (incrementing SensorEventConnection::mWakeLockRefCount) should
|
|
|
|
// not be interleaved with decrementing SensorEventConnection::mWakeLockRefCount and
|
|
|
|
// releasing the wakelock.
|
|
|
|
bool bufferHasWakeUpEvent = false;
|
2013-04-08 23:43:12 +00:00
|
|
|
for (int i = 0; i < count; i++) {
|
2014-02-12 02:58:52 +00:00
|
|
|
if (isWakeUpSensorEvent(buffer[i])) {
|
|
|
|
bufferHasWakeUpEvent = true;
|
|
|
|
break;
|
2013-04-08 23:43:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-12 02:58:52 +00:00
|
|
|
if (bufferHasWakeUpEvent && !mWakeLockAcquired) {
|
|
|
|
acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_NAME);
|
|
|
|
mWakeLockAcquired = true;
|
|
|
|
ALOGD_IF(DEBUG_CONNECTIONS, "acquired wakelock %s", WAKE_LOCK_NAME);
|
|
|
|
}
|
|
|
|
recordLastValueLocked(buffer, count);
|
2010-11-11 01:50:28 +00:00
|
|
|
|
2010-11-12 01:58:51 +00:00
|
|
|
// handle virtual sensors
|
|
|
|
if (count && vcount) {
|
2011-05-18 05:54:42 +00:00
|
|
|
sensors_event_t const * const event = buffer;
|
2014-02-12 02:58:52 +00:00
|
|
|
const size_t activeVirtualSensorCount = mActiveVirtualSensors.size();
|
2010-11-12 01:58:51 +00:00
|
|
|
if (activeVirtualSensorCount) {
|
|
|
|
size_t k = 0;
|
2011-05-18 05:54:42 +00:00
|
|
|
SensorFusion& fusion(SensorFusion::getInstance());
|
|
|
|
if (fusion.isEnabled()) {
|
|
|
|
for (size_t i=0 ; i<size_t(count) ; i++) {
|
|
|
|
fusion.process(event[i]);
|
|
|
|
}
|
|
|
|
}
|
2012-05-30 02:46:14 +00:00
|
|
|
for (size_t i=0 ; i<size_t(count) && k<minBufferSize ; i++) {
|
2010-11-12 01:58:51 +00:00
|
|
|
for (size_t j=0 ; j<activeVirtualSensorCount ; j++) {
|
2012-05-30 02:46:14 +00:00
|
|
|
if (count + k >= minBufferSize) {
|
|
|
|
ALOGE("buffer too small to hold all events: "
|
2014-06-10 21:50:02 +00:00
|
|
|
"count=%zd, k=%zu, size=%zu",
|
2012-05-30 02:46:14 +00:00
|
|
|
count, k, minBufferSize);
|
|
|
|
break;
|
|
|
|
}
|
2010-11-12 01:58:51 +00:00
|
|
|
sensors_event_t out;
|
2014-02-12 02:58:52 +00:00
|
|
|
SensorInterface* si = mActiveVirtualSensors.valueAt(j);
|
2012-05-30 02:46:14 +00:00
|
|
|
if (si->process(&out, event[i])) {
|
2010-11-12 01:58:51 +00:00
|
|
|
buffer[count + k] = out;
|
|
|
|
k++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (k) {
|
|
|
|
// record the last synthesized values
|
2014-02-12 02:58:52 +00:00
|
|
|
recordLastValueLocked(&buffer[count], k);
|
2010-11-12 01:58:51 +00:00
|
|
|
count += k;
|
|
|
|
// sort the buffer by time-stamps
|
|
|
|
sortEventBuffer(buffer, count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-08 23:43:12 +00:00
|
|
|
// handle backward compatibility for RotationVector sensor
|
|
|
|
if (halVersion < SENSORS_DEVICE_API_VERSION_1_0) {
|
|
|
|
for (int i = 0; i < count; i++) {
|
2013-07-08 19:50:39 +00:00
|
|
|
if (buffer[i].type == SENSOR_TYPE_ROTATION_VECTOR) {
|
2013-04-08 23:43:12 +00:00
|
|
|
// All the 4 components of the quaternion should be available
|
|
|
|
// No heading accuracy. Set it to -1
|
|
|
|
buffer[i].data[4] = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-12 02:58:52 +00:00
|
|
|
// Send our events to clients. Check the state of wake lock for each client and release the
|
|
|
|
// lock if none of the clients need it.
|
|
|
|
bool needsWakeLock = false;
|
|
|
|
for (size_t i=0 ; i < mActiveConnections.size(); i++) {
|
|
|
|
sp<SensorEventConnection> connection(mActiveConnections[i].promote());
|
2010-11-12 01:58:51 +00:00
|
|
|
if (connection != 0) {
|
|
|
|
connection->sendEvents(buffer, count, scratch);
|
2014-02-12 02:58:52 +00:00
|
|
|
needsWakeLock |= connection->needsWakeLock();
|
2013-04-08 23:43:12 +00:00
|
|
|
// Some sensors need to be auto disabled after the trigger
|
2014-02-12 02:58:52 +00:00
|
|
|
cleanupAutoDisabledSensorLocked(connection, buffer, count);
|
2010-07-15 06:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
2013-04-08 23:43:12 +00:00
|
|
|
|
2014-02-12 02:58:52 +00:00
|
|
|
if (mWakeLockAcquired && !needsWakeLock) {
|
|
|
|
release_wake_lock(WAKE_LOCK_NAME);
|
|
|
|
mWakeLockAcquired = false;
|
|
|
|
ALOGD_IF(DEBUG_CONNECTIONS, "released wakelock %s", WAKE_LOCK_NAME);
|
|
|
|
}
|
2010-07-15 06:41:37 +00:00
|
|
|
} while (count >= 0 || Thread::exitPending());
|
|
|
|
|
2012-01-05 23:22:43 +00:00
|
|
|
ALOGW("Exiting SensorService::threadLoop => aborting...");
|
2011-11-10 01:50:15 +00:00
|
|
|
abort();
|
2010-07-15 06:41:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-12 02:58:52 +00:00
|
|
|
void SensorService::recordLastValueLocked(
|
2014-03-04 03:02:46 +00:00
|
|
|
const sensors_event_t* buffer, size_t count) {
|
|
|
|
const sensors_event_t* last = NULL;
|
|
|
|
for (size_t i = 0; i < count; i++) {
|
|
|
|
const sensors_event_t* event = &buffer[i];
|
|
|
|
if (event->type != SENSOR_TYPE_META_DATA) {
|
|
|
|
if (last && event->sensor != last->sensor) {
|
|
|
|
mLastEventSeen.editValueFor(last->sensor) = *last;
|
|
|
|
}
|
|
|
|
last = event;
|
2010-11-11 01:50:28 +00:00
|
|
|
}
|
|
|
|
}
|
2014-03-04 03:02:46 +00:00
|
|
|
if (last) {
|
|
|
|
mLastEventSeen.editValueFor(last->sensor) = *last;
|
|
|
|
}
|
2010-11-11 01:50:28 +00:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:58:51 +00:00
|
|
|
void SensorService::sortEventBuffer(sensors_event_t* buffer, size_t count)
|
|
|
|
{
|
|
|
|
struct compar {
|
|
|
|
static int cmp(void const* lhs, void const* rhs) {
|
|
|
|
sensors_event_t const* l = static_cast<sensors_event_t const*>(lhs);
|
|
|
|
sensors_event_t const* r = static_cast<sensors_event_t const*>(rhs);
|
2012-04-20 01:18:24 +00:00
|
|
|
return l->timestamp - r->timestamp;
|
2010-11-12 01:58:51 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
qsort(buffer, count, sizeof(sensors_event_t), compar::cmp);
|
|
|
|
}
|
|
|
|
|
2010-07-19 22:20:39 +00:00
|
|
|
String8 SensorService::getSensorName(int handle) const {
|
2011-06-09 03:06:50 +00:00
|
|
|
size_t count = mUserSensorList.size();
|
2010-07-19 22:20:39 +00:00
|
|
|
for (size_t i=0 ; i<count ; i++) {
|
2011-06-09 03:06:50 +00:00
|
|
|
const Sensor& sensor(mUserSensorList[i]);
|
2010-07-19 22:20:39 +00:00
|
|
|
if (sensor.getHandle() == handle) {
|
|
|
|
return sensor.getName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String8 result("unknown");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-10-15 22:43:10 +00:00
|
|
|
bool SensorService::isVirtualSensor(int handle) const {
|
|
|
|
SensorInterface* sensor = mSensorMap.valueFor(handle);
|
|
|
|
return sensor->isVirtual();
|
|
|
|
}
|
|
|
|
|
2014-02-12 02:58:52 +00:00
|
|
|
bool SensorService::isWakeUpSensorEvent(const sensors_event_t& event) const {
|
|
|
|
SensorInterface* sensor = mSensorMap.valueFor(event.sensor);
|
|
|
|
return sensor->getSensor().isWakeUpSensor();
|
|
|
|
}
|
|
|
|
|
2010-07-15 06:41:37 +00:00
|
|
|
Vector<Sensor> SensorService::getSensorList()
|
|
|
|
{
|
2012-06-29 02:46:54 +00:00
|
|
|
char value[PROPERTY_VALUE_MAX];
|
|
|
|
property_get("debug.sensors", value, "0");
|
2014-04-07 22:52:37 +00:00
|
|
|
const Vector<Sensor>& initialSensorList = (atoi(value)) ?
|
|
|
|
mUserSensorListDebug : mUserSensorList;
|
|
|
|
Vector<Sensor> accessibleSensorList;
|
|
|
|
for (size_t i = 0; i < initialSensorList.size(); i++) {
|
|
|
|
Sensor sensor = initialSensorList[i];
|
|
|
|
if (canAccessSensor(sensor)) {
|
|
|
|
accessibleSensorList.add(sensor);
|
|
|
|
} else {
|
|
|
|
String8 infoMessage;
|
|
|
|
infoMessage.appendFormat(
|
|
|
|
"Skipped sensor %s because it requires permission %s",
|
|
|
|
sensor.getName().string(),
|
|
|
|
sensor.getRequiredPermission().string());
|
|
|
|
ALOGI(infoMessage.string());
|
|
|
|
}
|
2012-06-29 02:46:54 +00:00
|
|
|
}
|
2014-04-07 22:52:37 +00:00
|
|
|
return accessibleSensorList;
|
2010-07-15 06:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sp<ISensorEventConnection> SensorService::createSensorEventConnection()
|
|
|
|
{
|
2012-09-19 00:02:43 +00:00
|
|
|
uid_t uid = IPCThreadState::self()->getCallingUid();
|
|
|
|
sp<SensorEventConnection> result(new SensorEventConnection(this, uid));
|
2010-07-15 06:41:37 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-02-03 22:52:47 +00:00
|
|
|
void SensorService::cleanupConnection(SensorEventConnection* c)
|
2010-07-15 06:41:37 +00:00
|
|
|
{
|
|
|
|
Mutex::Autolock _l(mLock);
|
2011-02-03 22:52:47 +00:00
|
|
|
const wp<SensorEventConnection> connection(c);
|
2010-07-21 22:59:50 +00:00
|
|
|
size_t size = mActiveSensors.size();
|
2014-06-10 21:50:02 +00:00
|
|
|
ALOGD_IF(DEBUG_CONNECTIONS, "%zu active sensors", size);
|
2010-07-21 22:59:50 +00:00
|
|
|
for (size_t i=0 ; i<size ; ) {
|
2011-02-03 22:52:47 +00:00
|
|
|
int handle = mActiveSensors.keyAt(i);
|
|
|
|
if (c->hasSensor(handle)) {
|
2014-06-10 21:50:02 +00:00
|
|
|
ALOGD_IF(DEBUG_CONNECTIONS, "%zu: disabling handle=0x%08x", i, handle);
|
2010-11-12 01:58:51 +00:00
|
|
|
SensorInterface* sensor = mSensorMap.valueFor( handle );
|
2012-01-06 19:20:56 +00:00
|
|
|
ALOGE_IF(!sensor, "mSensorMap[handle=0x%08x] is null!", handle);
|
2010-11-12 01:58:51 +00:00
|
|
|
if (sensor) {
|
2011-02-03 22:52:47 +00:00
|
|
|
sensor->activate(c, false);
|
2010-11-12 01:58:51 +00:00
|
|
|
}
|
2011-02-03 22:52:47 +00:00
|
|
|
}
|
|
|
|
SensorRecord* rec = mActiveSensors.valueAt(i);
|
2014-06-10 21:50:02 +00:00
|
|
|
ALOGE_IF(!rec, "mActiveSensors[%zu] is null (handle=0x%08x)!", i, handle);
|
2011-12-20 16:23:08 +00:00
|
|
|
ALOGD_IF(DEBUG_CONNECTIONS,
|
2014-06-10 21:50:02 +00:00
|
|
|
"removing connection %p for sensor[%zu].handle=0x%08x",
|
2011-05-27 23:23:58 +00:00
|
|
|
c, i, handle);
|
|
|
|
|
2011-02-03 22:52:47 +00:00
|
|
|
if (rec && rec->removeConnection(connection)) {
|
2011-12-20 16:23:08 +00:00
|
|
|
ALOGD_IF(DEBUG_CONNECTIONS, "... and it was the last connection");
|
2010-07-21 22:59:50 +00:00
|
|
|
mActiveSensors.removeItemsAt(i, 1);
|
2010-11-12 01:58:51 +00:00
|
|
|
mActiveVirtualSensors.removeItem(handle);
|
2010-07-21 22:59:50 +00:00
|
|
|
delete rec;
|
|
|
|
size--;
|
|
|
|
} else {
|
|
|
|
i++;
|
2010-07-15 06:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
2010-07-21 22:59:50 +00:00
|
|
|
mActiveConnections.remove(connection);
|
2012-09-19 01:49:18 +00:00
|
|
|
BatteryService::cleanup(c->getUid());
|
2014-02-12 02:58:52 +00:00
|
|
|
if (c->needsWakeLock()) {
|
|
|
|
checkWakeLockStateLocked();
|
|
|
|
}
|
2010-07-15 06:41:37 +00:00
|
|
|
}
|
|
|
|
|
2014-04-07 22:52:37 +00:00
|
|
|
Sensor SensorService::getSensorFromHandle(int handle) const {
|
|
|
|
return mSensorMap.valueFor(handle)->getSensor();
|
|
|
|
}
|
|
|
|
|
2010-07-15 06:41:37 +00:00
|
|
|
status_t SensorService::enable(const sp<SensorEventConnection>& connection,
|
2013-06-27 19:04:23 +00:00
|
|
|
int handle, nsecs_t samplingPeriodNs, nsecs_t maxBatchReportLatencyNs, int reservedFlags)
|
2010-07-15 06:41:37 +00:00
|
|
|
{
|
2010-07-20 02:09:10 +00:00
|
|
|
if (mInitCheck != NO_ERROR)
|
|
|
|
return mInitCheck;
|
|
|
|
|
2010-11-12 01:58:51 +00:00
|
|
|
SensorInterface* sensor = mSensorMap.valueFor(handle);
|
2013-07-12 09:01:16 +00:00
|
|
|
if (sensor == NULL) {
|
|
|
|
return BAD_VALUE;
|
|
|
|
}
|
2014-04-07 22:52:37 +00:00
|
|
|
|
|
|
|
if (!verifyCanAccessSensor(sensor->getSensor(), "Tried enabling")) {
|
|
|
|
return BAD_VALUE;
|
|
|
|
}
|
|
|
|
|
2013-07-12 09:01:16 +00:00
|
|
|
Mutex::Autolock _l(mLock);
|
2013-04-08 23:43:12 +00:00
|
|
|
SensorRecord* rec = mActiveSensors.valueFor(handle);
|
|
|
|
if (rec == 0) {
|
|
|
|
rec = new SensorRecord(connection);
|
|
|
|
mActiveSensors.add(handle, rec);
|
|
|
|
if (sensor->isVirtual()) {
|
|
|
|
mActiveVirtualSensors.add(handle, sensor);
|
2010-07-23 04:24:39 +00:00
|
|
|
}
|
2013-04-08 23:43:12 +00:00
|
|
|
} else {
|
|
|
|
if (rec->addConnection(connection)) {
|
2014-02-12 02:58:52 +00:00
|
|
|
// this sensor is already activated, but we are adding a connection that uses it.
|
|
|
|
// Immediately send down the last known value of the requested sensor if it's not a
|
2013-04-08 23:43:12 +00:00
|
|
|
// "continuous" sensor.
|
2014-06-04 02:19:57 +00:00
|
|
|
if (sensor->getSensor().getReportingMode() == AREPORTING_MODE_ON_CHANGE) {
|
2014-02-12 02:58:52 +00:00
|
|
|
// NOTE: The wake_up flag of this event may get set to
|
|
|
|
// WAKE_UP_SENSOR_EVENT_NEEDS_ACK if this is a wake_up event.
|
2013-04-08 23:43:12 +00:00
|
|
|
sensors_event_t& event(mLastEventSeen.editValueFor(handle));
|
|
|
|
if (event.version == sizeof(sensors_event_t)) {
|
2014-02-12 02:58:52 +00:00
|
|
|
if (isWakeUpSensorEvent(event) && !mWakeLockAcquired) {
|
|
|
|
acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_NAME);
|
|
|
|
mWakeLockAcquired = true;
|
|
|
|
ALOGD_IF(DEBUG_CONNECTIONS, "acquired wakelock for on_change sensor %s",
|
|
|
|
WAKE_LOCK_NAME);
|
|
|
|
}
|
|
|
|
connection->sendEvents(&event, 1, NULL);
|
|
|
|
if (!connection->needsWakeLock() && mWakeLockAcquired) {
|
|
|
|
checkWakeLockStateLocked();
|
|
|
|
}
|
2010-11-12 01:58:51 +00:00
|
|
|
}
|
2010-07-21 22:59:50 +00:00
|
|
|
}
|
2010-07-15 06:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
2013-04-08 23:43:12 +00:00
|
|
|
|
|
|
|
if (connection->addSensor(handle)) {
|
|
|
|
BatteryService::enableSensor(connection->getUid(), handle);
|
|
|
|
// the sensor was added (which means it wasn't already there)
|
|
|
|
// so, see if this connection becomes active
|
|
|
|
if (mActiveConnections.indexOf(connection) < 0) {
|
|
|
|
mActiveConnections.add(connection);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ALOGW("sensor %08x already enabled in connection %p (ignoring)",
|
|
|
|
handle, connection.get());
|
|
|
|
}
|
|
|
|
|
2013-06-27 19:04:23 +00:00
|
|
|
nsecs_t minDelayNs = sensor->getSensor().getMinDelayNs();
|
|
|
|
if (samplingPeriodNs < minDelayNs) {
|
|
|
|
samplingPeriodNs = minDelayNs;
|
|
|
|
}
|
|
|
|
|
2014-06-10 21:50:02 +00:00
|
|
|
ALOGD_IF(DEBUG_CONNECTIONS, "Calling batch handle==%d flags=%d rate=%" PRId64 " timeout== %" PRId64,
|
2013-06-27 19:04:23 +00:00
|
|
|
handle, reservedFlags, samplingPeriodNs, maxBatchReportLatencyNs);
|
|
|
|
|
|
|
|
status_t err = sensor->batch(connection.get(), handle, reservedFlags, samplingPeriodNs,
|
|
|
|
maxBatchReportLatencyNs);
|
2013-09-06 00:03:38 +00:00
|
|
|
if (err == NO_ERROR) {
|
|
|
|
connection->setFirstFlushPending(handle, true);
|
|
|
|
status_t err_flush = sensor->flush(connection.get(), handle);
|
|
|
|
// Flush may return error if the sensor is not activated or the underlying h/w sensor does
|
|
|
|
// not support flush.
|
|
|
|
if (err_flush != NO_ERROR) {
|
|
|
|
connection->setFirstFlushPending(handle, false);
|
|
|
|
}
|
|
|
|
}
|
2013-06-27 19:04:23 +00:00
|
|
|
|
|
|
|
if (err == NO_ERROR) {
|
|
|
|
ALOGD_IF(DEBUG_CONNECTIONS, "Calling activate on %d", handle);
|
|
|
|
err = sensor->activate(connection.get(), true);
|
|
|
|
}
|
|
|
|
|
2013-04-08 23:43:12 +00:00
|
|
|
if (err != NO_ERROR) {
|
2013-06-27 19:04:23 +00:00
|
|
|
// batch/activate has failed, reset our state.
|
2013-07-12 09:01:16 +00:00
|
|
|
cleanupWithoutDisableLocked(connection, handle);
|
2013-04-08 23:43:12 +00:00
|
|
|
}
|
2010-07-15 06:41:37 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t SensorService::disable(const sp<SensorEventConnection>& connection,
|
|
|
|
int handle)
|
|
|
|
{
|
2010-07-20 02:09:10 +00:00
|
|
|
if (mInitCheck != NO_ERROR)
|
|
|
|
return mInitCheck;
|
|
|
|
|
2013-07-12 09:01:16 +00:00
|
|
|
Mutex::Autolock _l(mLock);
|
|
|
|
status_t err = cleanupWithoutDisableLocked(connection, handle);
|
2013-04-08 23:43:12 +00:00
|
|
|
if (err == NO_ERROR) {
|
|
|
|
SensorInterface* sensor = mSensorMap.valueFor(handle);
|
|
|
|
err = sensor ? sensor->activate(connection.get(), false) : status_t(BAD_VALUE);
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2013-07-12 09:01:16 +00:00
|
|
|
status_t SensorService::cleanupWithoutDisable(
|
|
|
|
const sp<SensorEventConnection>& connection, int handle) {
|
2010-07-15 06:41:37 +00:00
|
|
|
Mutex::Autolock _l(mLock);
|
2013-07-12 09:01:16 +00:00
|
|
|
return cleanupWithoutDisableLocked(connection, handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t SensorService::cleanupWithoutDisableLocked(
|
|
|
|
const sp<SensorEventConnection>& connection, int handle) {
|
2010-07-15 06:41:37 +00:00
|
|
|
SensorRecord* rec = mActiveSensors.valueFor(handle);
|
|
|
|
if (rec) {
|
|
|
|
// see if this connection becomes inactive
|
2012-09-19 01:49:18 +00:00
|
|
|
if (connection->removeSensor(handle)) {
|
|
|
|
BatteryService::disableSensor(connection->getUid(), handle);
|
|
|
|
}
|
2010-07-15 06:41:37 +00:00
|
|
|
if (connection->hasAnySensor() == false) {
|
|
|
|
mActiveConnections.remove(connection);
|
|
|
|
}
|
|
|
|
// see if this sensor becomes inactive
|
|
|
|
if (rec->removeConnection(connection)) {
|
|
|
|
mActiveSensors.removeItem(handle);
|
2010-11-12 01:58:51 +00:00
|
|
|
mActiveVirtualSensors.removeItem(handle);
|
2010-07-15 06:41:37 +00:00
|
|
|
delete rec;
|
|
|
|
}
|
2013-04-08 23:43:12 +00:00
|
|
|
return NO_ERROR;
|
2010-07-21 22:59:50 +00:00
|
|
|
}
|
2013-04-08 23:43:12 +00:00
|
|
|
return BAD_VALUE;
|
2010-07-15 06:41:37 +00:00
|
|
|
}
|
|
|
|
|
2010-07-21 22:59:50 +00:00
|
|
|
status_t SensorService::setEventRate(const sp<SensorEventConnection>& connection,
|
2010-07-15 06:41:37 +00:00
|
|
|
int handle, nsecs_t ns)
|
|
|
|
{
|
2010-07-20 02:09:10 +00:00
|
|
|
if (mInitCheck != NO_ERROR)
|
|
|
|
return mInitCheck;
|
|
|
|
|
2011-11-02 00:37:49 +00:00
|
|
|
SensorInterface* sensor = mSensorMap.valueFor(handle);
|
|
|
|
if (!sensor)
|
|
|
|
return BAD_VALUE;
|
|
|
|
|
2014-04-07 22:52:37 +00:00
|
|
|
if (!verifyCanAccessSensor(sensor->getSensor(), "Tried configuring")) {
|
|
|
|
return BAD_VALUE;
|
|
|
|
}
|
|
|
|
|
2010-07-21 22:59:50 +00:00
|
|
|
if (ns < 0)
|
|
|
|
return BAD_VALUE;
|
|
|
|
|
2011-11-08 05:21:47 +00:00
|
|
|
nsecs_t minDelayNs = sensor->getSensor().getMinDelayNs();
|
|
|
|
if (ns < minDelayNs) {
|
|
|
|
ns = minDelayNs;
|
2011-11-02 00:37:49 +00:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:58:51 +00:00
|
|
|
return sensor->setDelay(connection.get(), handle, ns);
|
2010-07-15 06:41:37 +00:00
|
|
|
}
|
|
|
|
|
2013-06-27 19:04:23 +00:00
|
|
|
status_t SensorService::flushSensor(const sp<SensorEventConnection>& connection,
|
|
|
|
int handle) {
|
2014-04-07 22:52:37 +00:00
|
|
|
if (mInitCheck != NO_ERROR) return mInitCheck;
|
|
|
|
SensorInterface* sensor = mSensorMap.valueFor(handle);
|
|
|
|
if (sensor == NULL) {
|
|
|
|
return BAD_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!verifyCanAccessSensor(sensor->getSensor(), "Tried flushing")) {
|
|
|
|
return BAD_VALUE;
|
|
|
|
}
|
|
|
|
|
2014-06-04 02:19:57 +00:00
|
|
|
if (sensor->getSensor().getReportingMode() == AREPORTING_MODE_ONE_SHOT) {
|
|
|
|
ALOGE("flush called on a one-shot sensor");
|
2014-04-07 22:52:37 +00:00
|
|
|
return INVALID_OPERATION;
|
|
|
|
}
|
|
|
|
return sensor->flush(connection.get(), handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SensorService::canAccessSensor(const Sensor& sensor) {
|
|
|
|
String16 permissionString(sensor.getRequiredPermission());
|
|
|
|
return permissionString.size() == 0 ||
|
|
|
|
PermissionCache::checkCallingPermission(permissionString);
|
2013-06-27 19:04:23 +00:00
|
|
|
}
|
2014-04-07 22:52:37 +00:00
|
|
|
|
|
|
|
bool SensorService::verifyCanAccessSensor(const Sensor& sensor, const char* operation) {
|
|
|
|
if (canAccessSensor(sensor)) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
String8 errorMessage;
|
|
|
|
errorMessage.appendFormat(
|
|
|
|
"%s a sensor (%s) without holding its required permission: %s",
|
|
|
|
operation,
|
|
|
|
sensor.getName().string(),
|
|
|
|
sensor.getRequiredPermission().string());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-12 02:58:52 +00:00
|
|
|
void SensorService::checkWakeLockState() {
|
|
|
|
Mutex::Autolock _l(mLock);
|
|
|
|
checkWakeLockStateLocked();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SensorService::checkWakeLockStateLocked() {
|
|
|
|
if (!mWakeLockAcquired) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bool releaseLock = true;
|
|
|
|
for (size_t i=0 ; i<mActiveConnections.size() ; i++) {
|
|
|
|
sp<SensorEventConnection> connection(mActiveConnections[i].promote());
|
|
|
|
if (connection != 0) {
|
|
|
|
if (connection->needsWakeLock()) {
|
|
|
|
releaseLock = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (releaseLock) {
|
|
|
|
ALOGD_IF(DEBUG_CONNECTIONS, "releasing wakelock %s", WAKE_LOCK_NAME);
|
|
|
|
release_wake_lock(WAKE_LOCK_NAME);
|
|
|
|
mWakeLockAcquired = false;
|
|
|
|
}
|
|
|
|
}
|
2010-07-15 06:41:37 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
SensorService::SensorRecord::SensorRecord(
|
|
|
|
const sp<SensorEventConnection>& connection)
|
|
|
|
{
|
|
|
|
mConnections.add(connection);
|
|
|
|
}
|
|
|
|
|
2010-07-21 22:59:50 +00:00
|
|
|
bool SensorService::SensorRecord::addConnection(
|
2010-07-15 06:41:37 +00:00
|
|
|
const sp<SensorEventConnection>& connection)
|
|
|
|
{
|
|
|
|
if (mConnections.indexOf(connection) < 0) {
|
|
|
|
mConnections.add(connection);
|
2010-07-21 22:59:50 +00:00
|
|
|
return true;
|
2010-07-15 06:41:37 +00:00
|
|
|
}
|
2010-07-21 22:59:50 +00:00
|
|
|
return false;
|
2010-07-15 06:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SensorService::SensorRecord::removeConnection(
|
|
|
|
const wp<SensorEventConnection>& connection)
|
|
|
|
{
|
|
|
|
ssize_t index = mConnections.indexOf(connection);
|
|
|
|
if (index >= 0) {
|
|
|
|
mConnections.removeItemsAt(index, 1);
|
|
|
|
}
|
|
|
|
return mConnections.size() ? false : true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
SensorService::SensorEventConnection::SensorEventConnection(
|
2012-09-19 00:02:43 +00:00
|
|
|
const sp<SensorService>& service, uid_t uid)
|
2014-02-12 02:58:52 +00:00
|
|
|
: mService(service), mUid(uid), mWakeLockRefCount(0)
|
2010-07-15 06:41:37 +00:00
|
|
|
{
|
2013-09-06 00:03:38 +00:00
|
|
|
const SensorDevice& device(SensorDevice::getInstance());
|
|
|
|
if (device.getHalDeviceVersion() >= SENSORS_DEVICE_API_VERSION_1_1) {
|
|
|
|
// Increase socket buffer size to 1MB for batching capabilities.
|
|
|
|
mChannel = new BitTube(service->mSocketBufferSize);
|
|
|
|
} else {
|
|
|
|
mChannel = new BitTube(SOCKET_BUFFER_SIZE_NON_BATCHED);
|
|
|
|
}
|
2010-07-15 06:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SensorService::SensorEventConnection::~SensorEventConnection()
|
|
|
|
{
|
2011-12-20 16:23:08 +00:00
|
|
|
ALOGD_IF(DEBUG_CONNECTIONS, "~SensorEventConnection(%p)", this);
|
2010-07-15 06:41:37 +00:00
|
|
|
mService->cleanupConnection(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SensorService::SensorEventConnection::onFirstRef()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-12 02:58:52 +00:00
|
|
|
bool SensorService::SensorEventConnection::needsWakeLock() {
|
|
|
|
Mutex::Autolock _l(mConnectionLock);
|
|
|
|
return mWakeLockRefCount > 0;
|
|
|
|
}
|
|
|
|
|
2013-09-06 00:03:38 +00:00
|
|
|
void SensorService::SensorEventConnection::dump(String8& result) {
|
|
|
|
Mutex::Autolock _l(mConnectionLock);
|
2014-02-12 02:58:52 +00:00
|
|
|
result.appendFormat("%d WakeLockRefCount\n", mWakeLockRefCount);
|
2013-09-06 00:03:38 +00:00
|
|
|
for (size_t i = 0; i < mSensorInfo.size(); ++i) {
|
|
|
|
const FlushInfo& flushInfo = mSensorInfo.valueAt(i);
|
2014-02-05 23:06:03 +00:00
|
|
|
result.appendFormat("\t %s | status: %s | pending flush events %d | uid %d\n",
|
2013-09-06 00:03:38 +00:00
|
|
|
mService->getSensorName(mSensorInfo.keyAt(i)).string(),
|
|
|
|
flushInfo.mFirstFlushPending ? "First flush pending" :
|
|
|
|
"active",
|
2014-02-05 23:06:03 +00:00
|
|
|
flushInfo.mPendingFlushEventsToSend,
|
|
|
|
mUid);
|
2013-09-06 00:03:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-21 22:59:50 +00:00
|
|
|
bool SensorService::SensorEventConnection::addSensor(int32_t handle) {
|
2010-11-15 04:55:25 +00:00
|
|
|
Mutex::Autolock _l(mConnectionLock);
|
2014-04-07 22:52:37 +00:00
|
|
|
if (!verifyCanAccessSensor(mService->getSensorFromHandle(handle), "Tried adding")) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-09-06 00:03:38 +00:00
|
|
|
if (mSensorInfo.indexOfKey(handle) < 0) {
|
|
|
|
mSensorInfo.add(handle, FlushInfo());
|
2010-07-21 22:59:50 +00:00
|
|
|
return true;
|
2010-07-15 06:41:37 +00:00
|
|
|
}
|
2010-07-21 22:59:50 +00:00
|
|
|
return false;
|
2010-07-15 06:41:37 +00:00
|
|
|
}
|
|
|
|
|
2010-07-21 22:59:50 +00:00
|
|
|
bool SensorService::SensorEventConnection::removeSensor(int32_t handle) {
|
2010-11-15 04:55:25 +00:00
|
|
|
Mutex::Autolock _l(mConnectionLock);
|
2013-09-06 00:03:38 +00:00
|
|
|
if (mSensorInfo.removeItem(handle) >= 0) {
|
2010-07-21 22:59:50 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2010-07-15 06:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SensorService::SensorEventConnection::hasSensor(int32_t handle) const {
|
2010-11-15 04:55:25 +00:00
|
|
|
Mutex::Autolock _l(mConnectionLock);
|
2013-09-06 00:03:38 +00:00
|
|
|
return mSensorInfo.indexOfKey(handle) >= 0;
|
2010-07-15 06:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SensorService::SensorEventConnection::hasAnySensor() const {
|
2010-11-15 04:55:25 +00:00
|
|
|
Mutex::Autolock _l(mConnectionLock);
|
2010-07-21 22:59:50 +00:00
|
|
|
return mSensorInfo.size() ? true : false;
|
|
|
|
}
|
|
|
|
|
2013-09-06 00:03:38 +00:00
|
|
|
void SensorService::SensorEventConnection::setFirstFlushPending(int32_t handle,
|
|
|
|
bool value) {
|
|
|
|
Mutex::Autolock _l(mConnectionLock);
|
|
|
|
ssize_t index = mSensorInfo.indexOfKey(handle);
|
|
|
|
if (index >= 0) {
|
|
|
|
FlushInfo& flushInfo = mSensorInfo.editValueAt(index);
|
|
|
|
flushInfo.mFirstFlushPending = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-15 06:41:37 +00:00
|
|
|
status_t SensorService::SensorEventConnection::sendEvents(
|
2010-07-22 23:18:10 +00:00
|
|
|
sensors_event_t const* buffer, size_t numEvents,
|
|
|
|
sensors_event_t* scratch)
|
2010-07-15 06:41:37 +00:00
|
|
|
{
|
2010-07-22 23:18:10 +00:00
|
|
|
// filter out events not for this connection
|
2010-07-23 04:24:39 +00:00
|
|
|
size_t count = 0;
|
2014-02-12 02:58:52 +00:00
|
|
|
Mutex::Autolock _l(mConnectionLock);
|
2010-07-23 04:24:39 +00:00
|
|
|
if (scratch) {
|
|
|
|
size_t i=0;
|
|
|
|
while (i<numEvents) {
|
2013-06-27 19:04:23 +00:00
|
|
|
int32_t curr = buffer[i].sensor;
|
|
|
|
if (buffer[i].type == SENSOR_TYPE_META_DATA) {
|
|
|
|
ALOGD_IF(DEBUG_CONNECTIONS, "flush complete event sensor==%d ",
|
|
|
|
buffer[i].meta_data.sensor);
|
|
|
|
// Setting curr to the correct sensor to ensure the sensor events per connection are
|
|
|
|
// filtered correctly. buffer[i].sensor is zero for meta_data events.
|
|
|
|
curr = buffer[i].meta_data.sensor;
|
|
|
|
}
|
2013-09-06 00:03:38 +00:00
|
|
|
ssize_t index = mSensorInfo.indexOfKey(curr);
|
|
|
|
if (index >= 0 && mSensorInfo[index].mFirstFlushPending == true &&
|
|
|
|
buffer[i].type == SENSOR_TYPE_META_DATA) {
|
|
|
|
// This is the first flush before activate is called. Events can now be sent for
|
|
|
|
// this sensor on this connection.
|
|
|
|
ALOGD_IF(DEBUG_CONNECTIONS, "First flush event for sensor==%d ",
|
|
|
|
buffer[i].meta_data.sensor);
|
|
|
|
mSensorInfo.editValueAt(index).mFirstFlushPending = false;
|
|
|
|
}
|
|
|
|
if (index >= 0 && mSensorInfo[index].mFirstFlushPending == false) {
|
2010-07-23 04:24:39 +00:00
|
|
|
do {
|
2013-09-06 00:03:38 +00:00
|
|
|
scratch[count++] = buffer[i++];
|
2013-06-27 19:04:23 +00:00
|
|
|
} while ((i<numEvents) && ((buffer[i].sensor == curr) ||
|
|
|
|
(buffer[i].type == SENSOR_TYPE_META_DATA &&
|
|
|
|
buffer[i].meta_data.sensor == curr)));
|
2010-07-23 04:24:39 +00:00
|
|
|
} else {
|
|
|
|
i++;
|
|
|
|
}
|
2010-07-22 23:18:10 +00:00
|
|
|
}
|
2010-07-23 04:24:39 +00:00
|
|
|
} else {
|
|
|
|
scratch = const_cast<sensors_event_t *>(buffer);
|
|
|
|
count = numEvents;
|
2010-07-22 23:18:10 +00:00
|
|
|
}
|
2010-07-15 06:41:37 +00:00
|
|
|
|
2013-09-06 00:03:38 +00:00
|
|
|
// Send pending flush events (if any) before sending events from the cache.
|
|
|
|
{
|
|
|
|
ASensorEvent flushCompleteEvent;
|
|
|
|
flushCompleteEvent.type = SENSOR_TYPE_META_DATA;
|
|
|
|
flushCompleteEvent.sensor = 0;
|
|
|
|
// Loop through all the sensors for this connection and check if there are any pending
|
|
|
|
// flush complete events to be sent.
|
|
|
|
for (size_t i = 0; i < mSensorInfo.size(); ++i) {
|
|
|
|
FlushInfo& flushInfo = mSensorInfo.editValueAt(i);
|
|
|
|
while (flushInfo.mPendingFlushEventsToSend > 0) {
|
|
|
|
flushCompleteEvent.meta_data.sensor = mSensorInfo.keyAt(i);
|
|
|
|
ssize_t size = SensorEventQueue::write(mChannel, &flushCompleteEvent, 1);
|
|
|
|
if (size < 0) {
|
|
|
|
// ALOGW("dropping %d events on the floor", count);
|
2013-10-15 00:04:42 +00:00
|
|
|
countFlushCompleteEventsLocked(scratch, count);
|
2013-09-06 00:03:38 +00:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
ALOGD_IF(DEBUG_CONNECTIONS, "sent dropped flush complete event==%d ",
|
|
|
|
flushCompleteEvent.meta_data.sensor);
|
|
|
|
flushInfo.mPendingFlushEventsToSend--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-15 22:43:10 +00:00
|
|
|
// Early return if there are no events for this connection.
|
|
|
|
if (count == 0) {
|
|
|
|
return status_t(NO_ERROR);
|
|
|
|
}
|
|
|
|
|
2014-02-12 02:58:52 +00:00
|
|
|
int numWakeUpSensorEvents = countWakeUpSensorEventsLocked(scratch, count);
|
2012-04-03 01:38:02 +00:00
|
|
|
// NOTE: ASensorEvent and sensors_event_t are the same type
|
|
|
|
ssize_t size = SensorEventQueue::write(mChannel,
|
|
|
|
reinterpret_cast<ASensorEvent const*>(scratch), count);
|
2010-07-15 06:41:37 +00:00
|
|
|
if (size == -EAGAIN) {
|
|
|
|
// the destination doesn't accept events anymore, it's probably
|
|
|
|
// full. For now, we just drop the events on the floor.
|
2013-09-06 00:03:38 +00:00
|
|
|
// ALOGW("dropping %d events on the floor", count);
|
2013-10-15 00:04:42 +00:00
|
|
|
countFlushCompleteEventsLocked(scratch, count);
|
2014-02-12 02:58:52 +00:00
|
|
|
mWakeLockRefCount -= numWakeUpSensorEvents;
|
2010-07-15 06:41:37 +00:00
|
|
|
return size;
|
|
|
|
}
|
2010-09-14 06:17:30 +00:00
|
|
|
return size < 0 ? status_t(size) : status_t(NO_ERROR);
|
2010-07-15 06:41:37 +00:00
|
|
|
}
|
|
|
|
|
2013-10-15 00:04:42 +00:00
|
|
|
void SensorService::SensorEventConnection::countFlushCompleteEventsLocked(
|
2013-09-06 00:03:38 +00:00
|
|
|
sensors_event_t* scratch, const int numEventsDropped) {
|
|
|
|
ALOGD_IF(DEBUG_CONNECTIONS, "dropping %d events ", numEventsDropped);
|
|
|
|
// Count flushComplete events in the events that are about to the dropped. These will be sent
|
|
|
|
// separately before the next batch of events.
|
|
|
|
for (int j = 0; j < numEventsDropped; ++j) {
|
|
|
|
if (scratch[j].type == SENSOR_TYPE_META_DATA) {
|
|
|
|
FlushInfo& flushInfo = mSensorInfo.editValueFor(scratch[j].meta_data.sensor);
|
|
|
|
flushInfo.mPendingFlushEventsToSend++;
|
|
|
|
ALOGD_IF(DEBUG_CONNECTIONS, "increment pendingFlushCount %d",
|
|
|
|
flushInfo.mPendingFlushEventsToSend);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-12 02:58:52 +00:00
|
|
|
int SensorService::SensorEventConnection::countWakeUpSensorEventsLocked(
|
|
|
|
sensors_event_t* scratch, const int count) {
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
if (mService->isWakeUpSensorEvent(scratch[i])) {
|
|
|
|
scratch[i].flags |= WAKE_UP_SENSOR_EVENT_NEEDS_ACK;
|
|
|
|
++mWakeLockRefCount;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-10-21 01:42:02 +00:00
|
|
|
sp<BitTube> SensorService::SensorEventConnection::getSensorChannel() const
|
2010-07-15 06:41:37 +00:00
|
|
|
{
|
|
|
|
return mChannel;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t SensorService::SensorEventConnection::enableDisable(
|
2013-06-27 19:04:23 +00:00
|
|
|
int handle, bool enabled, nsecs_t samplingPeriodNs, nsecs_t maxBatchReportLatencyNs,
|
|
|
|
int reservedFlags)
|
2010-07-15 06:41:37 +00:00
|
|
|
{
|
|
|
|
status_t err;
|
|
|
|
if (enabled) {
|
2013-06-27 19:04:23 +00:00
|
|
|
err = mService->enable(this, handle, samplingPeriodNs, maxBatchReportLatencyNs,
|
|
|
|
reservedFlags);
|
2010-07-15 06:41:37 +00:00
|
|
|
} else {
|
|
|
|
err = mService->disable(this, handle);
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t SensorService::SensorEventConnection::setEventRate(
|
2013-06-27 19:04:23 +00:00
|
|
|
int handle, nsecs_t samplingPeriodNs)
|
2010-07-15 06:41:37 +00:00
|
|
|
{
|
2013-06-27 19:04:23 +00:00
|
|
|
return mService->setEventRate(this, handle, samplingPeriodNs);
|
2010-07-15 06:41:37 +00:00
|
|
|
}
|
|
|
|
|
2013-10-08 21:59:26 +00:00
|
|
|
status_t SensorService::SensorEventConnection::flush() {
|
2013-10-15 00:04:42 +00:00
|
|
|
SensorDevice& dev(SensorDevice::getInstance());
|
|
|
|
const int halVersion = dev.getHalDeviceVersion();
|
2013-10-08 21:59:26 +00:00
|
|
|
Mutex::Autolock _l(mConnectionLock);
|
|
|
|
status_t err(NO_ERROR);
|
2013-10-15 00:04:42 +00:00
|
|
|
// Loop through all sensors for this connection and call flush on each of them.
|
2013-10-08 21:59:26 +00:00
|
|
|
for (size_t i = 0; i < mSensorInfo.size(); ++i) {
|
|
|
|
const int handle = mSensorInfo.keyAt(i);
|
2013-10-15 22:43:10 +00:00
|
|
|
if (halVersion < SENSORS_DEVICE_API_VERSION_1_1 || mService->isVirtualSensor(handle)) {
|
2013-10-15 00:04:42 +00:00
|
|
|
// For older devices just increment pending flush count which will send a trivial
|
|
|
|
// flush complete event.
|
|
|
|
FlushInfo& flushInfo = mSensorInfo.editValueFor(handle);
|
|
|
|
flushInfo.mPendingFlushEventsToSend++;
|
|
|
|
} else {
|
|
|
|
status_t err_flush = mService->flushSensor(this, handle);
|
|
|
|
if (err_flush != NO_ERROR) {
|
|
|
|
ALOGE("Flush error handle=%d %s", handle, strerror(-err_flush));
|
|
|
|
}
|
|
|
|
err = (err_flush != NO_ERROR) ? err_flush : err;
|
2013-10-08 21:59:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return err;
|
2013-06-27 19:04:23 +00:00
|
|
|
}
|
2013-09-06 00:03:38 +00:00
|
|
|
|
2014-02-12 02:58:52 +00:00
|
|
|
void SensorService::SensorEventConnection::decreaseWakeLockRefCount() {
|
|
|
|
{
|
|
|
|
Mutex::Autolock _l(mConnectionLock);
|
|
|
|
--mWakeLockRefCount;
|
|
|
|
}
|
|
|
|
// Release the lock before calling checkWakeLockState which also needs the same connectionLock.
|
|
|
|
if (mWakeLockRefCount == 0) {
|
|
|
|
mService->checkWakeLockState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-15 06:41:37 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
}; // namespace android
|
|
|
|
|