commit | 34f0951f964f6387afc33da749f3cb9ecdefc310 | [log] [tgz] |
---|---|---|
author | Presubmit Automerger Backend <android-build-presubmit-automerger-backend@system.gserviceaccount.com> | Wed Mar 23 09:33:53 2022 +0000 |
committer | Presubmit Automerger Backend <android-build-presubmit-automerger-backend@system.gserviceaccount.com> | Wed Mar 23 09:33:53 2022 +0000 |
tree | 4881a74e699ff126fe21403b748de7cba30a8b52 | |
parent | 16294cce9e1da4b8bbbcb170748c06448798c867 [diff] | |
parent | efc50877d2da0a6c2ad4939a6f954c3e988583af [diff] |
[automerge] Fix ServiceConnector failing unbind if not connected. 2p: efc50877d2 Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17321988 Change-Id: If7c0bf7ab6c89e98bdecbc1ef98bf93313fa8176 Merged-In: I6a8c01390130bcec9aff1460004343ca2b207031
diff --git a/core/java/com/android/internal/infra/ServiceConnector.java b/core/java/com/android/internal/infra/ServiceConnector.java index 9ced609..c379385 100644 --- a/core/java/com/android/internal/infra/ServiceConnector.java +++ b/core/java/com/android/internal/infra/ServiceConnector.java
@@ -507,10 +507,21 @@ 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; }