From fe96dde2986be5100aecb0f46db7b89089869615 Mon Sep 17 00:00:00 2001 From: Yan Yan Date: Mon, 5 Dec 2022 23:00:01 +0000 Subject: [PATCH] Restriction changes of #simulateDataStall This includes two restriction changes of simulateDataStall: - Allow simulation on a network that has an underlying test network - Allow simulation on networks created by the system server This commit allows VCN and VPN to CTS test their abilities of handling suspected data stall. This commit is safe because #simulateDataStall is already protected by two signature permissions MANAGE_TEST_NETWORKS and NETWORK_STACK, and those permissions are granted to only preinstalled apps. Bug: 263415068 Test: atest VcnManagerTest (new tests) Change-Id: Ic0cdb66abb291fbf4a7545efe4114179e965d2b6 --- .../android/server/ConnectivityService.java | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/service/src/com/android/server/ConnectivityService.java b/service/src/com/android/server/ConnectivityService.java index e32ea8f7d5..a85f2e07ae 100755 --- a/service/src/com/android/server/ConnectivityService.java +++ b/service/src/com/android/server/ConnectivityService.java @@ -10635,6 +10635,18 @@ public class ConnectivityService extends IConnectivityManager.Stub callback)); } + private boolean hasUnderlyingTestNetworks(NetworkCapabilities nc) { + final List underlyingNetworks = nc.getUnderlyingNetworks(); + if (underlyingNetworks == null) return false; + + for (Network network : underlyingNetworks) { + if (getNetworkCapabilitiesInternal(network).hasTransport(TRANSPORT_TEST)) { + return true; + } + } + return false; + } + @Override public void simulateDataStall(int detectionMethod, long timestampMillis, @NonNull Network network, @NonNull PersistableBundle extras) { @@ -10645,14 +10657,18 @@ public class ConnectivityService extends IConnectivityManager.Stub android.Manifest.permission.MANAGE_TEST_NETWORKS, android.Manifest.permission.NETWORK_STACK); final NetworkCapabilities nc = getNetworkCapabilitiesInternal(network); - if (!nc.hasTransport(TRANSPORT_TEST)) { - throw new SecurityException("Data Stall simulation is only possible for test networks"); + if (!nc.hasTransport(TRANSPORT_TEST) && !hasUnderlyingTestNetworks(nc)) { + throw new SecurityException( + "Data Stall simulation is only possible for test networks or networks built on" + + " top of test networks"); } final NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(network); - if (nai == null || nai.creatorUid != mDeps.getCallingUid()) { - throw new SecurityException("Data Stall simulation is only possible for network " - + "creators"); + if (nai == null + || (nai.creatorUid != mDeps.getCallingUid() + && nai.creatorUid != Process.SYSTEM_UID)) { + throw new SecurityException( + "Data Stall simulation is only possible for network " + "creators"); } // Instead of passing the data stall directly to the ConnectivityDiagnostics handler, treat