Send a proxy broadcast when apps moved from/to a VPN

When the apps moved from/to a VPN, a proxy broadcast is needed to
inform the apps that the proxy might be changed since the default
network satisfied by the apps might also changed.
Since the framework does not track the defautlt network of every
apps, thus, this is done when:
  1. VPN connects/disconnects.
  2. List of uids that apply to the VPN has changed.
While 1 is already covered by the current design, the CL implements
2 in order to fulfill the case that different networks have
different proxies.

Bug: 178727215
Test: atest FrameworksNetTests
Change-Id: Ifa103dd66394026d752b407a1bee740c9fcdad2b
This commit is contained in:
lucaslin
2021-06-08 01:43:59 +08:00
parent 9756b5d4f9
commit 53e8a267ab
3 changed files with 162 additions and 19 deletions

View File

@@ -1564,6 +1564,28 @@ public final class NetworkCapabilities implements Parcelable {
return false;
}
/**
* Compare if the given NetworkCapabilities have the same UIDs.
*
* @hide
*/
public static boolean hasSameUids(@Nullable NetworkCapabilities nc1,
@Nullable NetworkCapabilities nc2) {
final Set<UidRange> uids1 = (nc1 == null) ? null : nc1.mUids;
final Set<UidRange> uids2 = (nc2 == null) ? null : nc2.mUids;
if (null == uids1) return null == uids2;
if (null == uids2) return false;
// Make a copy so it can be mutated to check that all ranges in uids2 also are in uids.
final Set<UidRange> uids = new ArraySet<>(uids2);
for (UidRange range : uids1) {
if (!uids.contains(range)) {
return false;
}
uids.remove(range);
}
return uids.isEmpty();
}
/**
* Tests if the set of UIDs that this network applies to is the same as the passed network.
* <p>
@@ -1580,19 +1602,7 @@ public final class NetworkCapabilities implements Parcelable {
*/
@VisibleForTesting
public boolean equalsUids(@NonNull NetworkCapabilities nc) {
Set<UidRange> comparedUids = nc.mUids;
if (null == comparedUids) return null == mUids;
if (null == mUids) return false;
// Make a copy so it can be mutated to check that all ranges in mUids
// also are in uids.
final Set<UidRange> uids = new ArraySet<>(mUids);
for (UidRange range : comparedUids) {
if (!uids.contains(range)) {
return false;
}
uids.remove(range);
}
return uids.isEmpty();
return hasSameUids(nc, this);
}
/**