Merge "[MS68.1] Register usage callback from NetworkPolicyManagerService"
This commit is contained in:
@@ -729,7 +729,8 @@ public class NetworkStatsManager {
|
|||||||
* {@link #unregisterUsageCallback} is called.
|
* {@link #unregisterUsageCallback} is called.
|
||||||
*
|
*
|
||||||
* @param template Template used to match networks. See {@link NetworkTemplate}.
|
* @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}
|
* @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
|
* must run callback sequentially, otherwise the order of callbacks cannot be
|
||||||
* guaranteed.
|
* guaranteed.
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ class NetworkStatsObservers {
|
|||||||
*/
|
*/
|
||||||
public DataUsageRequest register(DataUsageRequest inputRequest, IUsageCallback callback,
|
public DataUsageRequest register(DataUsageRequest inputRequest, IUsageCallback callback,
|
||||||
int callingUid, @NetworkStatsAccess.Level int accessLevel) {
|
int callingUid, @NetworkStatsAccess.Level int accessLevel) {
|
||||||
DataUsageRequest request = buildRequest(inputRequest);
|
DataUsageRequest request = buildRequest(inputRequest, callingUid);
|
||||||
RequestInfo requestInfo = buildRequestInfo(request, callback, callingUid,
|
RequestInfo requestInfo = buildRequestInfo(request, callback, callingUid,
|
||||||
accessLevel);
|
accessLevel);
|
||||||
|
|
||||||
@@ -194,10 +194,12 @@ class NetworkStatsObservers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private DataUsageRequest buildRequest(DataUsageRequest request) {
|
private DataUsageRequest buildRequest(DataUsageRequest request, int callingUid) {
|
||||||
// Cap the minimum threshold to a safe default to avoid too many callbacks
|
// For non-system uid, cap the minimum threshold to a safe default to avoid too
|
||||||
long thresholdInBytes = Math.max(MIN_THRESHOLD_BYTES, request.thresholdInBytes);
|
// many callbacks.
|
||||||
if (thresholdInBytes < request.thresholdInBytes) {
|
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
|
Log.w(TAG, "Threshold was too low for " + request
|
||||||
+ ". Overriding to a safer default of " + thresholdInBytes + " bytes");
|
+ ". Overriding to a safer default of " + thresholdInBytes + " bytes");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user