SensorManager fixes.

i) Use pingBinder() to check the status of sensorservice everytime an
   event_queue is created. Retry to establish the binder connection if
   SensorService has recovered from a runtime restart.
ii) LOG_ALWAYS_FATAL_IF getService(SensorService) returns NULL or malloc
    returns NULL.

Bug: 22634472
Change-Id: I4e3912839b6f4114be1a124510878774dbd576a4
This commit is contained in:
Aravind Akella 2015-08-17 15:22:12 -07:00
parent d213f5e7a4
commit 8f35ca9730

View File

@ -110,10 +110,20 @@ void SensorManager::sensorManagerDied()
}
status_t SensorManager::assertStateLocked() const {
bool initSensorManager = false;
if (mSensorServer == NULL) {
// try for 10 seconds before giving up ...
initSensorManager = true;
} else {
// Ping binder to check if sensorservice is alive.
status_t err = IInterface::asBinder(mSensorServer)->pingBinder();
if (err != NO_ERROR) {
initSensorManager = true;
}
}
if (initSensorManager) {
// try for 300 seconds (60*5(getService() tries for 5 seconds)) before giving up ...
const String16 name("sensorservice");
for (int i = 0;i < 10; i++) {
for (int i = 0; i < 60; i++) {
status_t err = getService(name, &mSensorServer);
if (err == NAME_NOT_FOUND) {
sleep(1);
@ -135,9 +145,7 @@ status_t SensorManager::assertStateLocked() const {
DeathObserver(SensorManager& mgr) : mSensorManger(mgr) { }
};
if (mSensorServer == NULL) {
ALOGE("FATAL getsensorservice returned NULL");
}
LOG_ALWAYS_FATAL_IF(mSensorServer.get() == NULL, "getService(SensorService) NULL");
mDeathObserver = new DeathObserver(*const_cast<SensorManager *>(this));
IInterface::asBinder(mSensorServer)->linkToDeath(mDeathObserver);
@ -146,6 +154,8 @@ status_t SensorManager::assertStateLocked() const {
size_t count = mSensors.size();
mSensorList =
static_cast<Sensor const**>(malloc(count * sizeof(Sensor*)));
LOG_ALWAYS_FATAL_IF(mSensorList == NULL, "mSensorList NULL");
for (size_t i=0 ; i<count ; i++) {
mSensorList[i] = mSensors.array() + i;
}