Merge "[MS68.1] Register usage callback from NetworkPolicyManagerService" am: 0534b453bc am: 4531d6630b am: 1fa0cb1ed0

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1958144

Change-Id: Idd6094d47a1dc7bba55d438a6ae5504ab1e5b7c7
This commit is contained in:
Junyu Lai
2022-01-25 14:26:41 +00:00
committed by Automerger Merge Worker
2 changed files with 9 additions and 6 deletions

View File

@@ -729,7 +729,8 @@ public class NetworkStatsManager {
* {@link #unregisterUsageCallback} is called.
*
* @param template Template used to match networks. See {@link NetworkTemplate}.
* @param thresholdBytes Threshold in bytes to be notified on.
* @param thresholdBytes Threshold in bytes to be notified on. The provided value that lower
* than 2MiB will be clamped for non-privileged callers.
* @param executor The executor on which callback will be invoked. The provided {@link Executor}
* must run callback sequentially, otherwise the order of callbacks cannot be
* guaranteed.

View File

@@ -76,7 +76,7 @@ class NetworkStatsObservers {
*/
public DataUsageRequest register(DataUsageRequest inputRequest, IUsageCallback callback,
int callingUid, @NetworkStatsAccess.Level int accessLevel) {
DataUsageRequest request = buildRequest(inputRequest);
DataUsageRequest request = buildRequest(inputRequest, callingUid);
RequestInfo requestInfo = buildRequestInfo(request, callback, callingUid,
accessLevel);
@@ -194,10 +194,12 @@ class NetworkStatsObservers {
}
}
private DataUsageRequest buildRequest(DataUsageRequest request) {
// Cap the minimum threshold to a safe default to avoid too many callbacks
long thresholdInBytes = Math.max(MIN_THRESHOLD_BYTES, request.thresholdInBytes);
if (thresholdInBytes < request.thresholdInBytes) {
private DataUsageRequest buildRequest(DataUsageRequest request, int callingUid) {
// For non-system uid, cap the minimum threshold to a safe default to avoid too
// many callbacks.
long thresholdInBytes = (callingUid == Process.SYSTEM_UID ? request.thresholdInBytes
: Math.max(MIN_THRESHOLD_BYTES, request.thresholdInBytes));
if (thresholdInBytes > request.thresholdInBytes) {
Log.w(TAG, "Threshold was too low for " + request
+ ". Overriding to a safer default of " + thresholdInBytes + " bytes");
}