am 5df13ef3: SensorService doesn\'t crash if correct HAL is not present
Merge commit '5df13ef30e7dd58e4e718e6d949ac3d1f5af94e0' into gingerbread-plus-aosp * commit '5df13ef30e7dd58e4e718e6d949ac3d1f5af94e0': SensorService doesn't crash if correct HAL is not present
This commit is contained in:
@@ -79,35 +79,45 @@ ANDROID_SINGLETON_STATIC_INSTANCE(BatteryService)
|
|||||||
|
|
||||||
SensorService::SensorService()
|
SensorService::SensorService()
|
||||||
: Thread(false),
|
: Thread(false),
|
||||||
mDump("android.permission.DUMP")
|
mSensorDevice(0),
|
||||||
|
mSensorModule(0),
|
||||||
|
mDump("android.permission.DUMP"),
|
||||||
|
mInitCheck(NO_INIT)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void SensorService::onFirstRef()
|
void SensorService::onFirstRef()
|
||||||
{
|
{
|
||||||
|
LOGD("nuSensorService starting...");
|
||||||
|
|
||||||
status_t err = hw_get_module(SENSORS_HARDWARE_MODULE_ID,
|
status_t err = hw_get_module(SENSORS_HARDWARE_MODULE_ID,
|
||||||
(hw_module_t const**)&mSensorModule);
|
(hw_module_t const**)&mSensorModule);
|
||||||
|
|
||||||
LOGE_IF(err, "couldn't load %s module (%s)",
|
LOGE_IF(err, "couldn't load %s module (%s)",
|
||||||
SENSORS_HARDWARE_MODULE_ID, strerror(-err));
|
SENSORS_HARDWARE_MODULE_ID, strerror(-err));
|
||||||
|
|
||||||
err = sensors_open(&mSensorModule->common, &mSensorDevice);
|
if (mSensorModule) {
|
||||||
|
err = sensors_open(&mSensorModule->common, &mSensorDevice);
|
||||||
|
|
||||||
LOGE_IF(err, "couldn't open device for module %s (%s)",
|
LOGE_IF(err, "couldn't open device for module %s (%s)",
|
||||||
SENSORS_HARDWARE_MODULE_ID, strerror(-err));
|
SENSORS_HARDWARE_MODULE_ID, strerror(-err));
|
||||||
|
|
||||||
LOGD("nuSensorService starting...");
|
struct sensor_t const* list;
|
||||||
|
int count = mSensorModule->get_sensors_list(mSensorModule, &list);
|
||||||
|
for (int i=0 ; i<count ; i++) {
|
||||||
|
Sensor sensor(list + i);
|
||||||
|
LOGI("%s", sensor.getName().string());
|
||||||
|
mSensorList.add(sensor);
|
||||||
|
if (mSensorDevice) {
|
||||||
|
mSensorDevice->activate(mSensorDevice, sensor.getHandle(), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct sensor_t const* list;
|
if (mSensorDevice) {
|
||||||
int count = mSensorModule->get_sensors_list(mSensorModule, &list);
|
run("SensorService", PRIORITY_URGENT_DISPLAY);
|
||||||
for (int i=0 ; i<count ; i++) {
|
mInitCheck = NO_ERROR;
|
||||||
Sensor sensor(list + i);
|
}
|
||||||
LOGI("%s", sensor.getName().string());
|
|
||||||
mSensorList.add(sensor);
|
|
||||||
mSensorDevice->activate(mSensorDevice, sensor.getHandle(), 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
run("SensorService", PRIORITY_URGENT_DISPLAY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SensorService::~SensorService()
|
SensorService::~SensorService()
|
||||||
@@ -238,6 +248,9 @@ void SensorService::cleanupConnection(const wp<SensorEventConnection>& connectio
|
|||||||
status_t SensorService::enable(const sp<SensorEventConnection>& connection,
|
status_t SensorService::enable(const sp<SensorEventConnection>& connection,
|
||||||
int handle)
|
int handle)
|
||||||
{
|
{
|
||||||
|
if (mInitCheck != NO_ERROR)
|
||||||
|
return mInitCheck;
|
||||||
|
|
||||||
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);
|
||||||
@@ -265,6 +278,9 @@ status_t SensorService::enable(const sp<SensorEventConnection>& connection,
|
|||||||
status_t SensorService::disable(const sp<SensorEventConnection>& connection,
|
status_t SensorService::disable(const sp<SensorEventConnection>& connection,
|
||||||
int handle)
|
int handle)
|
||||||
{
|
{
|
||||||
|
if (mInitCheck != NO_ERROR)
|
||||||
|
return mInitCheck;
|
||||||
|
|
||||||
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);
|
||||||
@@ -291,6 +307,9 @@ status_t SensorService::disable(const sp<SensorEventConnection>& connection,
|
|||||||
status_t SensorService::setRate(const sp<SensorEventConnection>& connection,
|
status_t SensorService::setRate(const sp<SensorEventConnection>& connection,
|
||||||
int handle, nsecs_t ns)
|
int handle, nsecs_t ns)
|
||||||
{
|
{
|
||||||
|
if (mInitCheck != NO_ERROR)
|
||||||
|
return mInitCheck;
|
||||||
|
|
||||||
status_t err = NO_ERROR;
|
status_t err = NO_ERROR;
|
||||||
Mutex::Autolock _l(mLock);
|
Mutex::Autolock _l(mLock);
|
||||||
|
|
||||||
|
|||||||
@@ -98,6 +98,7 @@ class SensorService :
|
|||||||
struct sensors_poll_device_t* mSensorDevice;
|
struct sensors_poll_device_t* mSensorDevice;
|
||||||
struct sensors_module_t* mSensorModule;
|
struct sensors_module_t* mSensorModule;
|
||||||
Permission mDump;
|
Permission mDump;
|
||||||
|
status_t mInitCheck;
|
||||||
|
|
||||||
// protected by mLock
|
// protected by mLock
|
||||||
mutable Mutex mLock;
|
mutable Mutex mLock;
|
||||||
|
|||||||
Reference in New Issue
Block a user