From 18a58468c46d31e6cfad338d0ae90803b638f9a3 Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Thu, 16 Apr 2020 01:52:40 +0900 Subject: [PATCH] Add a function to process LinkProperties coming from an agent. There are tasks that need to be performed when receiving LinkProperties directly from a NetworkAgent (either at registration time or in subsequent updates). Currently, the only example of such a task is calling ensureDirectlyConnectedRoutes. This is currently done in handleUpdateLinkProperties, which is often unnecessary, because that method iscalled in many other cases than when receiving properties directly from an agent. Ensuring directly connected routes only needs to be done when receiving LinkProperties from the agent, because ConnectivityService does not directly manipulate routes. This CL does not do much except remove these superfluous calls and add the method. A future CL will add more code to the method. Bug: 150648313 Test: atest ConnectivityServiceTest Change-Id: Ibeeb5f79e8afd3350c935934713d7882f2e0281f --- .../android/server/ConnectivityService.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index ea91395bbd..651fa4166a 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -2712,7 +2712,9 @@ public class ConnectivityService extends IConnectivityManager.Stub break; } case NetworkAgent.EVENT_NETWORK_PROPERTIES_CHANGED: { - handleUpdateLinkProperties(nai, (LinkProperties) msg.obj); + LinkProperties newLp = (LinkProperties) msg.obj; + processLinkPropertiesFromAgent(nai, newLp); + handleUpdateLinkProperties(nai, newLp); break; } case NetworkAgent.EVENT_NETWORK_INFO_CHANGED: { @@ -5805,7 +5807,7 @@ public class ConnectivityService extends IConnectivityManager.Stub } LinkProperties lp = new LinkProperties(linkProperties); - lp.ensureDirectlyConnectedRoutes(); + // TODO: Instead of passing mDefaultRequest, provide an API to determine whether a Network // satisfies mDefaultRequest. final NetworkCapabilities nc = new NetworkCapabilities(networkCapabilities); @@ -5813,8 +5815,11 @@ public class ConnectivityService extends IConnectivityManager.Stub new Network(mNetIdManager.reserveNetId()), new NetworkInfo(networkInfo), lp, nc, currentScore, mContext, mTrackerHandler, new NetworkAgentConfig(networkAgentConfig), this, mNetd, mDnsResolver, mNMS, providerId); - // Make sure the network capabilities reflect what the agent info says. + + // Make sure the LinkProperties and NetworkCapabilities reflect what the agent info says. nai.getAndSetNetworkCapabilities(mixInCapabilities(nai, nc)); + processLinkPropertiesFromAgent(nai, nai.linkProperties); + final String extraInfo = networkInfo.getExtraInfo(); final String name = TextUtils.isEmpty(extraInfo) ? nai.networkCapabilities.getSsid() : extraInfo; @@ -5852,6 +5857,10 @@ public class ConnectivityService extends IConnectivityManager.Stub updateUids(nai, null, nai.networkCapabilities); } + private void processLinkPropertiesFromAgent(NetworkAgentInfo nai, LinkProperties lp) { + lp.ensureDirectlyConnectedRoutes(); + } + private void updateLinkProperties(NetworkAgentInfo networkAgent, LinkProperties newLp, @NonNull LinkProperties oldLp) { int netId = networkAgent.network.netId; @@ -6369,13 +6378,13 @@ public class ConnectivityService extends IConnectivityManager.Stub // Ignore updates for disconnected networks return; } - // newLp is already a defensive copy. - newLp.ensureDirectlyConnectedRoutes(); if (VDBG || DDBG) { log("Update of LinkProperties for " + nai.toShortString() + "; created=" + nai.created + "; everConnected=" + nai.everConnected); } + // TODO: eliminate this defensive copy after confirming that updateLinkProperties does not + // modify its oldLp parameter. updateLinkProperties(nai, newLp, new LinkProperties(nai.linkProperties)); }