Merge "Restriction changes of #simulateDataStall" am: 0bb76546e6

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2328562

Change-Id: I1098dc8373babc0224d217f2b83fe3ece0ae7f9b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Yan Yan 2023-03-15 20:57:51 +00:00 • committed by Automerger Merge Worker
commit 4279a667ce

View file

@ -10734,6 +10734,18 @@ public class ConnectivityService extends IConnectivityManager.Stub
callback));
}
private boolean hasUnderlyingTestNetworks(NetworkCapabilities nc) {
final List<Network> 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) {
@ -10744,14 +10756,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