summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2022-03-23 18:35:38 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2022-03-23 18:35:38 +0000
commitd53d398625f5a11f0e8c1e268f1556e596b4b08c (patch)
tree2c8874ad0fb7a6341c08396df521c067401c5904
parent289609bdb38e356976c77c77e7cfcf6557779fac (diff)
parent34f0951f964f6387afc33da749f3cb9ecdefc310 (diff)
Merge changes from topic "presubmit-am-b147b224dae54740a8f3d8017cf416c9-sc-v2-dev" into sc-v2-dev-plus-aosp
* changes: [automerge] Fix ServiceConnector failing unbind if not connected. 2p: efc50877d2 Fix ServiceConnector failing unbind if not connected.
-rw-r--r--core/java/com/android/internal/infra/ServiceConnector.java13
1 files changed, 12 insertions, 1 deletions
diff --git a/core/java/com/android/internal/infra/ServiceConnector.java b/core/java/com/android/internal/infra/ServiceConnector.java
index 9ced6097804d..c379385429b5 100644
--- a/core/java/com/android/internal/infra/ServiceConnector.java
+++ b/core/java/com/android/internal/infra/ServiceConnector.java
@@ -507,10 +507,21 @@ public interface ServiceConnector<I extends IInterface> {
void unbindJobThread() {
cancelTimeout();
I service = mService;
+ // TODO(b/224695239): This is actually checking wasConnected. Rename and/or fix
+ // implementation based on what this should actually be checking. At least the first
+ // check for calling unbind is the correct behavior, though.
boolean wasBound = service != null;
+ if (wasBound || mBinding) {
+ try {
+ mContext.unbindService(mServiceConnection);
+ } catch (IllegalArgumentException e) { // TODO(b/224697137): Fix the race condition
+ // that requires catching this (crashes if
+ // service isn't currently bound).
+ Log.e(LOG_TAG, "Failed to unbind: " + e);
+ }
+ }
if (wasBound) {
onServiceConnectionStatusChanged(service, false);
- mContext.unbindService(mServiceConnection);
service.asBinder().unlinkToDeath(this, 0);
mService = null;
}