diff options
author | Mateus Azis <azis@google.com> | 2023-08-16 20:40:45 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-08-16 20:40:45 +0000 |
commit | fd1bd234846a0d5f6bf7a6e99f7e3760e4624bf1 (patch) | |
tree | b7268bd49d8731c6a4c08ff1013fbbbb99d58124 /telecomm | |
parent | 434635a850b0afbacd10f8eab2e5a655b96b55d0 (diff) | |
parent | 4aa21c7f75a1f582cfe6a3be61324121e89878a9 (diff) | |
download | base-fd1bd234846a0d5f6bf7a6e99f7e3760e4624bf1.tar.gz |
Merge "Avoid duplicate map lookups in RemoteConnectionManager." into main am: eecbc0b322 am: 4aa21c7f75
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2712273
Change-Id: I202c162e59e15247a3d64057c95a55fdee514ff5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
Diffstat (limited to 'telecomm')
-rw-r--r-- | telecomm/java/android/telecom/RemoteConnectionManager.java | 49 |
1 files changed, 23 insertions, 26 deletions
diff --git a/telecomm/java/android/telecom/RemoteConnectionManager.java b/telecomm/java/android/telecom/RemoteConnectionManager.java index fbbfefd9d00e..fbf8eeffd947 100644 --- a/telecomm/java/android/telecom/RemoteConnectionManager.java +++ b/telecomm/java/android/telecom/RemoteConnectionManager.java @@ -39,18 +39,21 @@ public class RemoteConnectionManager { void addConnectionService( ComponentName componentName, IConnectionService outgoingConnectionServiceRpc) { - if (!mRemoteConnectionServices.containsKey(componentName)) { - try { - RemoteConnectionService remoteConnectionService = new RemoteConnectionService( - outgoingConnectionServiceRpc, - mOurConnectionServiceImpl); - mRemoteConnectionServices.put(componentName, remoteConnectionService); - } catch (RemoteException e) { - Log.w(RemoteConnectionManager.this, - "error when addConnectionService of %s: %s", componentName, - e.toString()); - } - } + mRemoteConnectionServices.computeIfAbsent( + componentName, + key -> { + try { + return new RemoteConnectionService( + outgoingConnectionServiceRpc, mOurConnectionServiceImpl); + } catch (RemoteException e) { + Log.w( + RemoteConnectionManager.this, + "error when addConnectionService of %s: %s", + componentName, + e.toString()); + return null; + } + }); } public RemoteConnection createRemoteConnection( @@ -63,17 +66,14 @@ public class RemoteConnectionManager { } ComponentName componentName = request.getAccountHandle().getComponentName(); - if (!mRemoteConnectionServices.containsKey(componentName)) { + RemoteConnectionService remoteService = mRemoteConnectionServices.get(componentName); + if (remoteService == null) { throw new UnsupportedOperationException("accountHandle not supported: " + componentName); } - RemoteConnectionService remoteService = mRemoteConnectionServices.get(componentName); - if (remoteService != null) { - return remoteService.createRemoteConnection( - connectionManagerPhoneAccount, request, isIncoming); - } - return null; + return remoteService.createRemoteConnection( + connectionManagerPhoneAccount, request, isIncoming); } /** @@ -94,17 +94,14 @@ public class RemoteConnectionManager { } ComponentName componentName = request.getAccountHandle().getComponentName(); - if (!mRemoteConnectionServices.containsKey(componentName)) { + RemoteConnectionService remoteService = mRemoteConnectionServices.get(componentName); + if (remoteService == null) { throw new UnsupportedOperationException("accountHandle not supported: " + componentName); } - RemoteConnectionService remoteService = mRemoteConnectionServices.get(componentName); - if (remoteService != null) { - return remoteService.createRemoteConference( - connectionManagerPhoneAccount, request, isIncoming); - } - return null; + return remoteService.createRemoteConference( + connectionManagerPhoneAccount, request, isIncoming); } public void conferenceRemoteConnections(RemoteConnection a, RemoteConnection b) { |