diff --git a/service/src/com/android/server/ConnectivityService.java b/service/src/com/android/server/ConnectivityService.java index db0e9e521f..93265e51ca 100755 --- a/service/src/com/android/server/ConnectivityService.java +++ b/service/src/com/android/server/ConnectivityService.java @@ -1976,9 +1976,6 @@ public class ConnectivityService extends IConnectivityManager.Stub @Nullable public NetworkInfo getNetworkInfoForUid(Network network, int uid, boolean ignoreBlocked) { enforceAccessPermission(); - if (uid != mDeps.getCallingUid()) { - enforceNetworkStackPermission(mContext); - } final NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(network); if (nai == null) return null; return getFilteredNetworkInfo(nai, uid, ignoreBlocked); diff --git a/tests/unit/java/com/android/server/ConnectivityServiceTest.java b/tests/unit/java/com/android/server/ConnectivityServiceTest.java index 61ba144d1a..d2a71354ec 100755 --- a/tests/unit/java/com/android/server/ConnectivityServiceTest.java +++ b/tests/unit/java/com/android/server/ConnectivityServiceTest.java @@ -1603,9 +1603,9 @@ public class ConnectivityServiceTest { mMockVpn = new MockVpn(userId); } - private void mockUidNetworkingBlocked(int uid) { + private void mockUidNetworkingBlocked() { doAnswer(i -> isUidBlocked(mBlockedReasons, i.getArgument(1)) - ).when(mNetworkPolicyManager).isUidNetworkingBlocked(eq(uid), anyBoolean()); + ).when(mNetworkPolicyManager).isUidNetworkingBlocked(anyInt(), anyBoolean()); } private boolean isUidBlocked(int blockedReasons, boolean meteredNetwork) { @@ -8903,7 +8903,7 @@ public class ConnectivityServiceTest { final DetailedBlockedStatusCallback detailedCallback = new DetailedBlockedStatusCallback(); mCm.registerNetworkCallback(cellRequest, detailedCallback); - mockUidNetworkingBlocked(Process.myUid()); + mockUidNetworkingBlocked(); mCellNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_CELLULAR); mCellNetworkAgent.connect(true); @@ -9018,7 +9018,7 @@ public class ConnectivityServiceTest { public void testNetworkBlockedStatusBeforeAndAfterConnect() throws Exception { final TestNetworkCallback defaultCallback = new TestNetworkCallback(); mCm.registerDefaultNetworkCallback(defaultCallback); - mockUidNetworkingBlocked(Process.myUid()); + mockUidNetworkingBlocked(); // No Networkcallbacks invoked before any network is active. setBlockedReasonChanged(BLOCKED_REASON_BATTERY_SAVER); @@ -16781,43 +16781,4 @@ public class ConnectivityServiceTest { verify(mTetheringManager).getTetherableWifiRegexs(); }); } - - @Test - public void testGetNetworkInfoForUid() throws Exception { - // Setup and verify getNetworkInfoForUid cannot be called without Network Stack permission, - // when querying NetworkInfo for other uid. - verifyNoNetwork(); - mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI); - mServiceContext.setPermission(NETWORK_STACK, PERMISSION_DENIED); - mServiceContext.setPermission(NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, - PERMISSION_DENIED); - - final int otherUid = Process.myUid() + 1; - assertNull(mCm.getActiveNetwork()); - assertNull(mCm.getNetworkInfoForUid(mCm.getActiveNetwork(), - Process.myUid(), false /* ignoreBlocked */)); - assertThrows(SecurityException.class, () -> mCm.getNetworkInfoForUid( - mCm.getActiveNetwork(), otherUid, false /* ignoreBlocked */)); - withPermission(NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, () -> - assertNull(mCm.getNetworkInfoForUid(mCm.getActiveNetwork(), - otherUid, false /* ignoreBlocked */))); - - // Bringing up validated wifi and verify again. Make the other uid be blocked, - // verify the method returns result accordingly. - mWiFiNetworkAgent.connect(true); - setBlockedReasonChanged(BLOCKED_REASON_BATTERY_SAVER); - mockUidNetworkingBlocked(otherUid); - withPermission(NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, () -> - verifyActiveNetwork(TRANSPORT_WIFI)); - checkNetworkInfo(mCm.getNetworkInfoForUid(mCm.getActiveNetwork(), - Process.myUid(), false /* ignoreBlocked */), TYPE_WIFI, DetailedState.CONNECTED); - assertThrows(SecurityException.class, () -> mCm.getNetworkInfoForUid( - mCm.getActiveNetwork(), otherUid, false /* ignoreBlocked */)); - withPermission(NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, () -> - checkNetworkInfo(mCm.getNetworkInfoForUid(mCm.getActiveNetwork(), - otherUid, false /* ignoreBlocked */), TYPE_WIFI, DetailedState.BLOCKED)); - withPermission(NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, () -> - checkNetworkInfo(mCm.getNetworkInfoForUid(mCm.getActiveNetwork(), - otherUid, true /* ignoreBlocked */), TYPE_WIFI, DetailedState.CONNECTED)); - } }