Remove UID_RANGES_ADDED and REMOVED.

Test: runtest frameworks-net
Test: also tested with VPN app
Test: also cts passing
Change-Id: I3530030996daeba05a8f2fffc5c6e21ed62e3f40
This commit is contained in:
Chalard Jean
2018-01-16 18:43:05 +09:00
parent 753d9734d2
commit b2a4991781
2 changed files with 34 additions and 54 deletions

View File

@@ -29,7 +29,6 @@ import com.android.internal.util.AsyncChannel;
import com.android.internal.util.Protocol; import com.android.internal.util.Protocol;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
/** /**
@@ -101,20 +100,6 @@ public abstract class NetworkAgent extends Handler {
*/ */
public static final int EVENT_NETWORK_SCORE_CHANGED = BASE + 4; public static final int EVENT_NETWORK_SCORE_CHANGED = BASE + 4;
/**
* Sent by the NetworkAgent to ConnectivityService to add new UID ranges
* to be forced into this Network. For VPNs only.
* obj = UidRange[] to forward
*/
public static final int EVENT_UID_RANGES_ADDED = BASE + 5;
/**
* Sent by the NetworkAgent to ConnectivityService to remove UID ranges
* from being forced into this Network. For VPNs only.
* obj = UidRange[] to stop forwarding
*/
public static final int EVENT_UID_RANGES_REMOVED = BASE + 6;
/** /**
* Sent by ConnectivityService to the NetworkAgent to inform the agent of the * Sent by ConnectivityService to the NetworkAgent to inform the agent of the
* networks status - whether we could use the network or could not, due to * networks status - whether we could use the network or could not, due to
@@ -225,11 +210,6 @@ public abstract class NetworkAgent extends Handler {
Context.CONNECTIVITY_SERVICE); Context.CONNECTIVITY_SERVICE);
netId = cm.registerNetworkAgent(new Messenger(this), new NetworkInfo(ni), netId = cm.registerNetworkAgent(new Messenger(this), new NetworkInfo(ni),
new LinkProperties(lp), new NetworkCapabilities(nc), score, misc); new LinkProperties(lp), new NetworkCapabilities(nc), score, misc);
final Set<UidRange> uids = nc.getUids();
if (null != uids) {
addUidRanges(uids.toArray(new UidRange[uids.size()]));
}
} }
@Override @Override
@@ -395,22 +375,6 @@ public abstract class NetworkAgent extends Handler {
queueOrSendMessage(EVENT_NETWORK_SCORE_CHANGED, new Integer(score)); queueOrSendMessage(EVENT_NETWORK_SCORE_CHANGED, new Integer(score));
} }
/**
* Called by the VPN code when it wants to add ranges of UIDs to be routed
* through the VPN network.
*/
public void addUidRanges(UidRange[] ranges) {
queueOrSendMessage(EVENT_UID_RANGES_ADDED, ranges);
}
/**
* Called by the VPN code when it wants to remove ranges of UIDs from being routed
* through the VPN network.
*/
public void removeUidRanges(UidRange[] ranges) {
queueOrSendMessage(EVENT_UID_RANGES_REMOVED, ranges);
}
/** /**
* Called by the bearer to indicate this network was manually selected by the user. * Called by the bearer to indicate this network was manually selected by the user.
* This should be called before the NetworkInfo is marked CONNECTED so that this * This should be called before the NetworkInfo is marked CONNECTED so that this

View File

@@ -105,6 +105,7 @@ import android.security.Credentials;
import android.security.KeyStore; import android.security.KeyStore;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.ArraySet;
import android.util.LocalLog; import android.util.LocalLog;
import android.util.LocalLog.ReadOnlyLocalLog; import android.util.LocalLog.ReadOnlyLocalLog;
import android.util.Log; import android.util.Log;
@@ -174,6 +175,7 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.TreeSet; import java.util.TreeSet;
@@ -2050,24 +2052,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
if (score != null) updateNetworkScore(nai, score.intValue()); if (score != null) updateNetworkScore(nai, score.intValue());
break; break;
} }
case NetworkAgent.EVENT_UID_RANGES_ADDED: {
try {
mNetd.addVpnUidRanges(nai.network.netId, (UidRange[])msg.obj);
} catch (Exception e) {
// Never crash!
loge("Exception in addVpnUidRanges: " + e);
}
break;
}
case NetworkAgent.EVENT_UID_RANGES_REMOVED: {
try {
mNetd.removeVpnUidRanges(nai.network.netId, (UidRange[])msg.obj);
} catch (Exception e) {
// Never crash!
loge("Exception in removeVpnUidRanges: " + e);
}
break;
}
case NetworkAgent.EVENT_SET_EXPLICITLY_SELECTED: { case NetworkAgent.EVENT_SET_EXPLICITLY_SELECTED: {
if (nai.everConnected && !nai.networkMisc.explicitlySelected) { if (nai.everConnected && !nai.networkMisc.explicitlySelected) {
loge("ERROR: already-connected network explicitly selected."); loge("ERROR: already-connected network explicitly selected.");
@@ -4514,6 +4498,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
NetworkInfo networkInfo = na.networkInfo; NetworkInfo networkInfo = na.networkInfo;
na.networkInfo = null; na.networkInfo = null;
updateNetworkInfo(na, networkInfo); updateNetworkInfo(na, networkInfo);
updateUids(na, null, na.networkCapabilities);
} }
private void updateLinkProperties(NetworkAgentInfo networkAgent, LinkProperties oldLp) { private void updateLinkProperties(NetworkAgentInfo networkAgent, LinkProperties oldLp) {
@@ -4762,6 +4747,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
nai.networkCapabilities = newNc; nai.networkCapabilities = newNc;
} }
updateUids(nai, prevNc, newNc);
if (nai.getCurrentScore() == oldScore && newNc.equalRequestableCapabilities(prevNc)) { if (nai.getCurrentScore() == oldScore && newNc.equalRequestableCapabilities(prevNc)) {
// If the requestable capabilities haven't changed, and the score hasn't changed, then // If the requestable capabilities haven't changed, and the score hasn't changed, then
// the change we're processing can't affect any requests, it can only affect the listens // the change we're processing can't affect any requests, it can only affect the listens
@@ -4798,6 +4785,34 @@ public class ConnectivityService extends IConnectivityManager.Stub
} }
} }
private void updateUids(NetworkAgentInfo nai, NetworkCapabilities prevNc,
NetworkCapabilities newNc) {
Set<UidRange> prevRanges = null == prevNc ? null : prevNc.getUids();
Set<UidRange> newRanges = null == newNc ? null : newNc.getUids();
if (null == prevRanges) prevRanges = new ArraySet<>();
if (null == newRanges) newRanges = new ArraySet<>();
final Set<UidRange> prevRangesCopy = new ArraySet<>(prevRanges);
prevRanges.removeAll(newRanges);
newRanges.removeAll(prevRangesCopy);
try {
if (!newRanges.isEmpty()) {
final UidRange[] addedRangesArray = new UidRange[newRanges.size()];
newRanges.toArray(addedRangesArray);
mNetd.addVpnUidRanges(nai.network.netId, addedRangesArray);
}
if (!prevRanges.isEmpty()) {
final UidRange[] removedRangesArray = new UidRange[prevRanges.size()];
prevRanges.toArray(removedRangesArray);
mNetd.removeVpnUidRanges(nai.network.netId, removedRangesArray);
}
} catch (Exception e) {
// Never crash!
loge("Exception in updateUids: " + e);
}
}
public void handleUpdateLinkProperties(NetworkAgentInfo nai, LinkProperties newLp) { public void handleUpdateLinkProperties(NetworkAgentInfo nai, LinkProperties newLp) {
if (mNetworkForNetId.get(nai.network.netId) != nai) { if (mNetworkForNetId.get(nai.network.netId) != nai) {
// Ignore updates for disconnected networks // Ignore updates for disconnected networks
@@ -5413,6 +5428,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
} }
} }
} }
updateUids(networkAgent, networkAgent.networkCapabilities, null);
} }
} else if ((oldInfo != null && oldInfo.getState() == NetworkInfo.State.SUSPENDED) || } else if ((oldInfo != null && oldInfo.getState() == NetworkInfo.State.SUSPENDED) ||
state == NetworkInfo.State.SUSPENDED) { state == NetworkInfo.State.SUSPENDED) {