From d764759ca3ecb943675688c08112d2d79c90601a Mon Sep 17 00:00:00 2001 From: James Mattis Date: Wed, 17 Feb 2021 16:13:05 -0800 Subject: [PATCH] Optimization when looking up requests for release Including an optimzation in handleReleaseNetworkRequest when looking up a request so that in the chance an app shuts down prior to the request being released, it doesn't cause errors when looking validating that apps uid->package name. Bug: 178729499 Test: atest FrameworksNetTests atest ExtServicesUnitTests on CF and making sure no remote exceptions. Change-Id: I2c49511a1385b47fba075b2794685ae2bc80abba --- .../core/java/com/android/server/ConnectivityService.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index 154e1831ce..5077cc6229 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -3721,7 +3721,12 @@ public class ConnectivityService extends IConnectivityManager.Stub // Looking up the app passed param request in mRequests isn't possible since it may return // null for a request managed by a per-app default. Therefore use getNriForAppRequest() to // do the lookup since that will also find per-app default managed requests. - final NetworkRequestInfo nri = getNriForAppRequest(request); + // Additionally, this lookup needs to be relatively fast (hence the lookup optimization) + // to avoid potential race conditions when validating a package->uid mapping when sending + // the callback on the very low-chance that an application shuts down prior to the callback + // being sent. + final NetworkRequestInfo nri = mNetworkRequests.get(request) != null + ? mNetworkRequests.get(request) : getNriForAppRequest(request); if (nri != null) { if (Process.SYSTEM_UID != callingUid && Process.NETWORK_STACK_UID != callingUid