Observe mOwnerUID in NetworkCapabilities#equals.

Currently, NetworkCapabilities's equals and hashCode methods
ignore mOwnerUID. This is confusing because it is inconsistent
with pretty much every other member of this class.

Bug: 175188445
Test: atest CtsNetTestCases:NetworkAgentTest \
            CtsNetTestCases:Ikev2VpnTest \
	    CtsNetTestCases:VpnServiceTest HostsideVpnTests \
	    CtsNetTestCases:android.net.cts.ConnectivityDiagnosticsManagerTest \
	    ConnectivityServiceTest com.android.server.connectivity.VpnTest
Change-Id: I2348b7a35f32a931687f2d3c2fa57620a12fe06f
This commit is contained in:
Lorenzo Colitti
2020-11-27 14:46:42 +09:00
parent 6b44e92fde
commit 46fd589d89
2 changed files with 20 additions and 16 deletions

View File

@@ -975,6 +975,10 @@ public final class NetworkCapabilities implements Parcelable {
return mOwnerUid;
}
private boolean equalsOwnerUid(@NonNull final NetworkCapabilities nc) {
return mOwnerUid == nc.mOwnerUid;
}
/**
* UIDs of packages that are administrators of this network, or empty if none.
*
@@ -1684,6 +1688,7 @@ public final class NetworkCapabilities implements Parcelable {
&& equalsTransportInfo(that)
&& equalsUids(that)
&& equalsSSID(that)
&& equalsOwnerUid(that)
&& equalsPrivateDnsBroken(that)
&& equalsRequestor(that)
&& equalsAdministratorUids(that);
@@ -1697,17 +1702,18 @@ public final class NetworkCapabilities implements Parcelable {
+ ((int) (mUnwantedNetworkCapabilities >> 32) * 7)
+ ((int) (mTransportTypes & 0xFFFFFFFF) * 11)
+ ((int) (mTransportTypes >> 32) * 13)
+ (mLinkUpBandwidthKbps * 17)
+ (mLinkDownBandwidthKbps * 19)
+ mLinkUpBandwidthKbps * 17
+ mLinkDownBandwidthKbps * 19
+ Objects.hashCode(mNetworkSpecifier) * 23
+ (mSignalStrength * 29)
+ Objects.hashCode(mUids) * 31
+ Objects.hashCode(mSSID) * 37
+ Objects.hashCode(mTransportInfo) * 41
+ Objects.hashCode(mPrivateDnsBroken) * 43
+ Objects.hashCode(mRequestorUid) * 47
+ Objects.hashCode(mRequestorPackageName) * 53
+ Arrays.hashCode(mAdministratorUids) * 59;
+ mSignalStrength * 29
+ mOwnerUid * 31
+ Objects.hashCode(mUids) * 37
+ Objects.hashCode(mSSID) * 41
+ Objects.hashCode(mTransportInfo) * 43
+ Objects.hashCode(mPrivateDnsBroken) * 47
+ Objects.hashCode(mRequestorUid) * 53
+ Objects.hashCode(mRequestorPackageName) * 59
+ Arrays.hashCode(mAdministratorUids) * 61;
}
@Override

View File

@@ -1980,18 +1980,16 @@ public class ConnectivityServiceTest {
mWiFiNetworkAgent.setNetworkCapabilities(agentCapabilities, true);
waitForIdle();
// Check that the owner UID is not updated.
// Check that the owner UID is updated.
// The owner UID is -1 because it is visible only to the UID that owns the network.
NetworkCapabilities nc = mCm.getNetworkCapabilities(mWiFiNetworkAgent.getNetwork());
assertEquals(originalOwnerUid, nc.getOwnerUid());
assertEquals(-1, nc.getOwnerUid());
// Make an unrelated change to the capabilities.
// Make an unrelated change to the capabilities and check it. The owner UID remains -1.
assertFalse(agentCapabilities.hasCapability(NET_CAPABILITY_NOT_CONGESTED));
agentCapabilities.addCapability(NET_CAPABILITY_NOT_CONGESTED);
mWiFiNetworkAgent.setNetworkCapabilities(agentCapabilities, true);
waitForIdle();
// Check that both the capability change and the owner UID have been modified.
// The owner UID is -1 because it is visible only to the UID that owns the network.
nc = mCm.getNetworkCapabilities(mWiFiNetworkAgent.getNetwork());
assertEquals(-1, nc.getOwnerUid());
assertTrue(nc.hasCapability(NET_CAPABILITY_NOT_CONGESTED));