Correct the comparison done in removeAdapter.

Since addAdapter is storing the proxy binder objects in the adapter set, we need
to compare the underlying binder objects when trying to remove the adapter
from the adapter set. This was resulting in adapters accumulating in adapter
set every time a RemoteService was created.

BUG: 22062692
Change-Id: Ib9cc25a8b95622a524ed5a07d3ef56673669cd27
This commit is contained in:
Roshan Pius
2015-07-08 16:52:37 -07:00
parent 1ca6207a1e
commit 75c36b681e

View File

@@ -48,6 +48,12 @@ final class ConnectionServiceAdapter implements DeathRecipient {
}
void addAdapter(IConnectionServiceAdapter adapter) {
for (IConnectionServiceAdapter it : mAdapters) {
if (it.asBinder() == adapter.asBinder()) {
Log.w(this, "Ignoring duplicate adapter addition.");
return;
}
}
if (mAdapters.add(adapter)) {
try {
adapter.asBinder().linkToDeath(this, 0);
@@ -58,8 +64,13 @@ final class ConnectionServiceAdapter implements DeathRecipient {
}
void removeAdapter(IConnectionServiceAdapter adapter) {
if (adapter != null && mAdapters.remove(adapter)) {
adapter.asBinder().unlinkToDeath(this, 0);
if (adapter != null) {
for (IConnectionServiceAdapter it : mAdapters) {
if (it.asBinder() == adapter.asBinder() && mAdapters.remove(it)) {
adapter.asBinder().unlinkToDeath(this, 0);
break;
}
}
}
}