summaryrefslogtreecommitdiffstats
path: root/emailcommon
diff options
context:
space:
mode:
authorAnthony Lee <anthonylee@google.com>2014-08-20 13:59:59 -0700
committerAnthony Lee <anthonylee@google.com>2014-08-20 14:08:47 -0700
commit8c65e50bfe3b90b96985c2d87b8c459c348af6aa (patch)
tree1142e1ff15a2b13289cbe27e44c93028ecb38227 /emailcommon
parentb04201335cf33bded97e9019940e0b8f9ccfb6d9 (diff)
downloadandroid_packages_apps_Email-8c65e50bfe3b90b96985c2d87b8c459c348af6aa.tar.gz
android_packages_apps_Email-8c65e50bfe3b90b96985c2d87b8c459c348af6aa.tar.bz2
android_packages_apps_Email-8c65e50bfe3b90b96985c2d87b8c459c348af6aa.zip
b/17135753. Make sure to free ServiceConnection.
The only way that the ServiceConnection was not being freed is if there was an Exception (other than RemoteException) being thrown out of mTask.run(). Now the call to unbindService() is called in a finally() block surrounding that block of code. Change-Id: I597412233381894be76d3c8bdf99fc7d96794dc2
Diffstat (limited to 'emailcommon')
-rw-r--r--emailcommon/src/com/android/emailcommon/service/ServiceProxy.java31
1 files changed, 18 insertions, 13 deletions
diff --git a/emailcommon/src/com/android/emailcommon/service/ServiceProxy.java b/emailcommon/src/com/android/emailcommon/service/ServiceProxy.java
index 1c4f3b6bb..3669345c1 100644
--- a/emailcommon/src/com/android/emailcommon/service/ServiceProxy.java
+++ b/emailcommon/src/com/android/emailcommon/service/ServiceProxy.java
@@ -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) {