From bcc926002801157e08ecb81a02a26473bf8a8bc0 Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Tue, 19 Aug 2014 21:31:08 -0700 Subject: [PATCH] Fix findConnectionTypeForIface. This is used by the VPN to notice when its underlying connection has gone away. I'm fixing this using network types and not NetworkCapabilities because 1. I don't know of a way to use the new API to get callbacks for a specific network. You can get them based on capabilities, but it's not clear how to construct a NetworkCapabilities object that will only match a specific network, or only match the default network. 2. It's a smaller change. Bug: 15070628 Change-Id: Id6a6a183da83636c0859db4c954093bd684c01ea --- .../java/com/android/server/ConnectivityService.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index 67c01e50bb..4d7b2ef8d4 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -2798,11 +2798,13 @@ public class ConnectivityService extends IConnectivityManager.Stub { enforceConnectivityInternalPermission(); if (TextUtils.isEmpty(iface)) return ConnectivityManager.TYPE_NONE; - for (NetworkStateTracker tracker : mNetTrackers) { - if (tracker != null) { - LinkProperties lp = tracker.getLinkProperties(); - if (lp != null && iface.equals(lp.getInterfaceName())) { - return tracker.getNetworkInfo().getType(); + + synchronized(mNetworkForNetId) { + for (int i = 0; i < mNetworkForNetId.size(); i++) { + NetworkAgentInfo nai = mNetworkForNetId.valueAt(i); + LinkProperties lp = nai.linkProperties; + if (lp != null && iface.equals(lp.getInterfaceName()) && nai.networkInfo != null) { + return nai.networkInfo.getType(); } } }