Revert "Partially enforce permission when calling getNetworkInfoForUid"
This reverts commit 163cb98751.
Reason for revert: b/257407201
Change-Id: I412140117d25f4a4b439fff5aaa50785f33b0689
This commit is contained in:
committed by
Gerrit Code Review
parent
163cb98751
commit
d0cf7784dc
@@ -1976,9 +1976,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
@Nullable
|
@Nullable
|
||||||
public NetworkInfo getNetworkInfoForUid(Network network, int uid, boolean ignoreBlocked) {
|
public NetworkInfo getNetworkInfoForUid(Network network, int uid, boolean ignoreBlocked) {
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
if (uid != mDeps.getCallingUid()) {
|
|
||||||
enforceNetworkStackPermission(mContext);
|
|
||||||
}
|
|
||||||
final NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(network);
|
final NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(network);
|
||||||
if (nai == null) return null;
|
if (nai == null) return null;
|
||||||
return getFilteredNetworkInfo(nai, uid, ignoreBlocked);
|
return getFilteredNetworkInfo(nai, uid, ignoreBlocked);
|
||||||
|
|||||||
@@ -1603,9 +1603,9 @@ public class ConnectivityServiceTest {
|
|||||||
mMockVpn = new MockVpn(userId);
|
mMockVpn = new MockVpn(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mockUidNetworkingBlocked(int uid) {
|
private void mockUidNetworkingBlocked() {
|
||||||
doAnswer(i -> isUidBlocked(mBlockedReasons, i.getArgument(1))
|
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) {
|
private boolean isUidBlocked(int blockedReasons, boolean meteredNetwork) {
|
||||||
@@ -8903,7 +8903,7 @@ public class ConnectivityServiceTest {
|
|||||||
final DetailedBlockedStatusCallback detailedCallback = new DetailedBlockedStatusCallback();
|
final DetailedBlockedStatusCallback detailedCallback = new DetailedBlockedStatusCallback();
|
||||||
mCm.registerNetworkCallback(cellRequest, detailedCallback);
|
mCm.registerNetworkCallback(cellRequest, detailedCallback);
|
||||||
|
|
||||||
mockUidNetworkingBlocked(Process.myUid());
|
mockUidNetworkingBlocked();
|
||||||
|
|
||||||
mCellNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_CELLULAR);
|
mCellNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_CELLULAR);
|
||||||
mCellNetworkAgent.connect(true);
|
mCellNetworkAgent.connect(true);
|
||||||
@@ -9018,7 +9018,7 @@ public class ConnectivityServiceTest {
|
|||||||
public void testNetworkBlockedStatusBeforeAndAfterConnect() throws Exception {
|
public void testNetworkBlockedStatusBeforeAndAfterConnect() throws Exception {
|
||||||
final TestNetworkCallback defaultCallback = new TestNetworkCallback();
|
final TestNetworkCallback defaultCallback = new TestNetworkCallback();
|
||||||
mCm.registerDefaultNetworkCallback(defaultCallback);
|
mCm.registerDefaultNetworkCallback(defaultCallback);
|
||||||
mockUidNetworkingBlocked(Process.myUid());
|
mockUidNetworkingBlocked();
|
||||||
|
|
||||||
// No Networkcallbacks invoked before any network is active.
|
// No Networkcallbacks invoked before any network is active.
|
||||||
setBlockedReasonChanged(BLOCKED_REASON_BATTERY_SAVER);
|
setBlockedReasonChanged(BLOCKED_REASON_BATTERY_SAVER);
|
||||||
@@ -16781,43 +16781,4 @@ public class ConnectivityServiceTest {
|
|||||||
verify(mTetheringManager).getTetherableWifiRegexs();
|
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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user