diff options
author | 2023-08-16 09:31:20 -0700 | |
---|---|---|
committer | 2023-08-16 09:31:20 -0700 | |
commit | ddcbe639fe1c0f8c5d815db643eea19f59051638 (patch) | |
tree | e050de438c94e64da12658b9a9c3fc97284032b7 | |
parent | d8ac0c199c10a45abf5a258c8841b03ca6cc29a3 (diff) |
Avoid duplicate map lookups in RemoteConnectionManager.
Use Map.computeIfAbsent or the result of get() calls to interact with
the map via a single access, avoiding duplicate lookups.
Test: atest cts/tests/tests/telecom/src/android/telecom/cts/RemoteConnectionTest.java
Bug: 274764512
Change-Id: I1e6b10381f0c9b408c4a734384e550dfaefc1f40
-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) { |