healthd: notify listeners using local copy of list, drop lock

Binder currently may service an incoming oneway transaction whenever
an outbound oneway call is made (if there is already a pending
incoming oneway call waiting).  The unexpected nested method call
blocks forever on a recursive mutex acquire because healthd is single-
threaded.  The binder behavior is considered a bug and may change in
the future.  For now, work around this in healthd.

Make a local copy of the listeners list, then drop the lock and
perform the outbound calls on the local copy of the list.

Bug: 38201220
Test: Marlin with modified client calling scheduleUpdate() repeatedly
Change-Id: If35c2847556245921e2aff808ff747bb60356811
This commit is contained in:
Todd Poynor 2017-06-26 14:34:38 -07:00
parent 4f5f558d38
commit fd68370074

View file

@ -36,9 +36,19 @@ void BatteryPropertiesRegistrar::publish(
}
void BatteryPropertiesRegistrar::notifyListeners(const struct BatteryProperties& props) {
Mutex::Autolock _l(mRegistrationLock);
for (size_t i = 0; i < mListeners.size(); i++) {
mListeners[i]->batteryPropertiesChanged(props);
Vector<sp<IBatteryPropertiesListener> > listenersCopy;
// Binder currently may service an incoming oneway transaction whenever an
// outbound oneway call is made (if there is already a pending incoming
// oneway call waiting). This is considered a bug and may change in the
// future. For now, avoid recursive mutex lock while making outbound
// calls by making a local copy of the current list of listeners.
{
Mutex::Autolock _l(mRegistrationLock);
listenersCopy = mListeners;
}
for (size_t i = 0; i < listenersCopy.size(); i++) {
listenersCopy[i]->batteryPropertiesChanged(props);
}
}