Merge "[SP29.1] Simplify logic of calculating and applying data limit" am: 6b9470ffc4
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1652211 Change-Id: Ie0f37b03ca6644d4be1de95b6ee9396dac101fe4
This commit is contained in:
@@ -2035,39 +2035,34 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
|
|
||||||
final boolean hasWarning = policy.warningBytes != LIMIT_DISABLED;
|
final boolean hasWarning = policy.warningBytes != LIMIT_DISABLED;
|
||||||
final boolean hasLimit = policy.limitBytes != LIMIT_DISABLED;
|
final boolean hasLimit = policy.limitBytes != LIMIT_DISABLED;
|
||||||
if (hasLimit || policy.metered) {
|
long limitBytes = Long.MAX_VALUE;
|
||||||
final long quotaBytes;
|
if (hasLimit && policy.hasCycle()) {
|
||||||
if (hasLimit && policy.hasCycle()) {
|
final Pair<ZonedDateTime, ZonedDateTime> cycle = NetworkPolicyManager
|
||||||
final Pair<ZonedDateTime, ZonedDateTime> cycle = NetworkPolicyManager
|
.cycleIterator(policy).next();
|
||||||
.cycleIterator(policy).next();
|
final long start = cycle.first.toInstant().toEpochMilli();
|
||||||
final long start = cycle.first.toInstant().toEpochMilli();
|
final long end = cycle.second.toInstant().toEpochMilli();
|
||||||
final long end = cycle.second.toInstant().toEpochMilli();
|
final long totalBytes = getTotalBytes(policy.template, start, end);
|
||||||
final long totalBytes = getTotalBytes(policy.template, start, end);
|
|
||||||
|
|
||||||
if (policy.lastLimitSnooze >= start) {
|
if (policy.lastLimitSnooze < start) {
|
||||||
// snoozing past quota, but we still need to restrict apps,
|
// remaining "quota" bytes are based on total usage in
|
||||||
// so push really high quota.
|
// current cycle. kernel doesn't like 0-byte rules, so we
|
||||||
quotaBytes = Long.MAX_VALUE;
|
// set 1-byte quota and disable the radio later.
|
||||||
} else {
|
limitBytes = Math.max(1, policy.limitBytes - totalBytes);
|
||||||
// remaining "quota" bytes are based on total usage in
|
|
||||||
// current cycle. kernel doesn't like 0-byte rules, so we
|
|
||||||
// set 1-byte quota and disable the radio later.
|
|
||||||
quotaBytes = Math.max(1, policy.limitBytes - totalBytes);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// metered network, but no policy limit; we still need to
|
|
||||||
// restrict apps, so push really high quota.
|
|
||||||
quotaBytes = Long.MAX_VALUE;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasLimit || policy.metered) {
|
||||||
if (matchingIfaces.size() > 1) {
|
if (matchingIfaces.size() > 1) {
|
||||||
// TODO: switch to shared quota once NMS supports
|
// TODO: switch to shared quota once NMS supports
|
||||||
Slog.w(TAG, "shared quota unsupported; generating rule for each iface");
|
Slog.w(TAG, "shared quota unsupported; generating rule for each iface");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the interface limit. For interfaces which has no cycle, or metered with
|
||||||
|
// no policy limit, or snoozed limit notification; we still need to put iptables
|
||||||
|
// rule hooks to restrict apps for data saver, so push really high quota.
|
||||||
for (int j = matchingIfaces.size() - 1; j >= 0; j--) {
|
for (int j = matchingIfaces.size() - 1; j >= 0; j--) {
|
||||||
final String iface = matchingIfaces.valueAt(j);
|
final String iface = matchingIfaces.valueAt(j);
|
||||||
setInterfaceQuotaAsync(iface, quotaBytes);
|
setInterfaceQuotaAsync(iface, limitBytes);
|
||||||
newMeteredIfaces.add(iface);
|
newMeteredIfaces.add(iface);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user