Merge changes from topic "bandwidth-limiting"
* changes: Add bandwidth limiting to CS Add setting that controls network rate limit
This commit is contained in:
@@ -383,6 +383,14 @@ public class ConnectivitySettingsManager {
|
||||
public static final String UIDS_ALLOWED_ON_RESTRICTED_NETWORKS =
|
||||
"uids_allowed_on_restricted_networks";
|
||||
|
||||
/**
|
||||
* A global rate limit that applies to all networks with NET_CAPABILITY_INTERNET when enabled.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public static final String INGRESS_RATE_LIMIT_BYTES_PER_SECOND =
|
||||
"ingress_rate_limit_bytes_per_second";
|
||||
|
||||
/**
|
||||
* Get mobile data activity timeout from {@link Settings}.
|
||||
*
|
||||
@@ -1071,4 +1079,37 @@ public class ConnectivitySettingsManager {
|
||||
Settings.Global.putString(context.getContentResolver(), UIDS_ALLOWED_ON_RESTRICTED_NETWORKS,
|
||||
uids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the global network bandwidth rate limit.
|
||||
*
|
||||
* The limit is only applicable to networks that provide internet connectivity. If the setting
|
||||
* is unset, it defaults to -1.
|
||||
*
|
||||
* @param context The {@link Context} to query the setting.
|
||||
* @return The rate limit in number of bytes per second or -1 if disabled.
|
||||
*/
|
||||
public static long getIngressRateLimitInBytesPerSecond(@NonNull Context context) {
|
||||
return Settings.Global.getLong(context.getContentResolver(),
|
||||
INGRESS_RATE_LIMIT_BYTES_PER_SECOND, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the global network bandwidth rate limit.
|
||||
*
|
||||
* The limit is only applicable to networks that provide internet connectivity.
|
||||
*
|
||||
* @param context The {@link Context} to set the setting.
|
||||
* @param rateLimitInBytesPerSec The rate limit in number of bytes per second or -1 to disable.
|
||||
*/
|
||||
public static void setIngressRateLimitInBytesPerSecond(@NonNull Context context,
|
||||
@IntRange(from = -1, to = Integer.MAX_VALUE) long rateLimitInBytesPerSec) {
|
||||
if (rateLimitInBytesPerSec < -1) {
|
||||
throw new IllegalArgumentException(
|
||||
"Rate limit must be within the range [-1, Integer.MAX_VALUE]");
|
||||
}
|
||||
Settings.Global.putLong(context.getContentResolver(),
|
||||
INGRESS_RATE_LIMIT_BYTES_PER_SECOND,
|
||||
rateLimitInBytesPerSec);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user