Merge "Create TestApi for simulating a Data Stall on ConnectivityService." am: e743a30aa7 am: b36fa34041
Change-Id: I17839cd271d984f76c203889293cc51375bb8bcb
This commit is contained in:
@@ -3088,10 +3088,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
|
||||
@Override
|
||||
public void notifyDataStallSuspected(DataStallReportParcelable p) {
|
||||
final Message msg = mConnectivityDiagnosticsHandler.obtainMessage(
|
||||
ConnectivityDiagnosticsHandler.EVENT_DATA_STALL_SUSPECTED,
|
||||
p.detectionMethod, mNetId, p.timestampMillis);
|
||||
|
||||
final PersistableBundle extras = new PersistableBundle();
|
||||
switch (p.detectionMethod) {
|
||||
case DETECTION_METHOD_DNS_EVENTS:
|
||||
@@ -3106,12 +3102,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
log("Unknown data stall detection method, ignoring: " + p.detectionMethod);
|
||||
return;
|
||||
}
|
||||
msg.setData(new Bundle(extras));
|
||||
|
||||
// NetworkStateTrackerHandler currently doesn't take any actions based on data
|
||||
// stalls so send the message directly to ConnectivityDiagnosticsHandler and avoid
|
||||
// the cost of going through two handlers.
|
||||
mConnectivityDiagnosticsHandler.sendMessage(msg);
|
||||
proxyDataStallToConnectivityDiagnosticsHandler(
|
||||
p.detectionMethod, mNetId, p.timestampMillis, extras);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -3125,6 +3118,19 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
}
|
||||
}
|
||||
|
||||
private void proxyDataStallToConnectivityDiagnosticsHandler(int detectionMethod, int netId,
|
||||
long timestampMillis, @NonNull PersistableBundle extras) {
|
||||
final Message msg = mConnectivityDiagnosticsHandler.obtainMessage(
|
||||
ConnectivityDiagnosticsHandler.EVENT_DATA_STALL_SUSPECTED,
|
||||
detectionMethod, netId, timestampMillis);
|
||||
msg.setData(new Bundle(extras));
|
||||
|
||||
// NetworkStateTrackerHandler currently doesn't take any actions based on data
|
||||
// stalls so send the message directly to ConnectivityDiagnosticsHandler and avoid
|
||||
// the cost of going through two handlers.
|
||||
mConnectivityDiagnosticsHandler.sendMessage(msg);
|
||||
}
|
||||
|
||||
private boolean networkRequiresPrivateDnsValidation(NetworkAgentInfo nai) {
|
||||
return isPrivateDnsValidationRequired(nai.networkCapabilities);
|
||||
}
|
||||
@@ -8167,4 +8173,24 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
0,
|
||||
callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void simulateDataStall(int detectionMethod, long timestampMillis,
|
||||
@NonNull Network network, @NonNull PersistableBundle extras) {
|
||||
enforceAnyPermissionOf(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 simluation is only possible for test networks");
|
||||
}
|
||||
|
||||
final NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(network);
|
||||
if (nai == null || nai.creatorUid != Binder.getCallingUid()) {
|
||||
throw new SecurityException("Data Stall simulation is only possible for network "
|
||||
+ "creators");
|
||||
}
|
||||
|
||||
proxyDataStallToConnectivityDiagnosticsHandler(
|
||||
detectionMethod, network.netId, timestampMillis, extras);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user