am ca31da91: am 9d1dc789: b/17135753. Make sure to free ServiceConnection. automerge: 8c65e50

* commit 'ca31da91c8b844fc89595a055ccf08452f8273ee':
  b/17135753. Make sure to free ServiceConnection.
This commit is contained in:
Anthony Lee 2014-11-02 17:36:44 +00:00 committed by Android Git Automerger
commit 4ae25d3b45
1 changed files with 18 additions and 13 deletions

View File

@ -114,19 +114,24 @@ public abstract class ServiceProxy {
try {
mTask.run();
} catch (RemoteException e) {
}
try {
// Each ServiceProxy handles just one task, so we unbind after we're
// done with our work.
mContext.unbindService(mConnection);
} catch (RuntimeException e) {
// The exceptions that are thrown here look like IllegalStateException,
// IllegalArgumentException and RuntimeException. Catching RuntimeException
// which get them all. Reasons for these exceptions include services that
// have already been stopped or unbound. This can happen if the user ended
// the activity that was using the service. This is harmless, but we've got
// to catch it.
LogUtils.e(mTag, e, "RuntimeException when trying to unbind from service");
LogUtils.e(mTag, e, "RemoteException thrown running mTask!");
} finally {
// Make sure that we unbind the mConnection even on exceptions in the
// task provided by the subclass.
try {
// Each ServiceProxy handles just one task, so we unbind after we're
// done with our work.
mContext.unbindService(mConnection);
} catch (RuntimeException e) {
// The exceptions that are thrown here look like IllegalStateException,
// IllegalArgumentException and RuntimeException. Catching
// RuntimeException which get them all. Reasons for these exceptions
// include services that have already been stopped or unbound. This can
// happen if the user ended the activity that was using the service.
// This is harmless, but we've got to catch it.
LogUtils.e(mTag, e,
"RuntimeException when trying to unbind from service");
}
}
mTaskCompleted = true;
synchronized(mConnection) {