use of android.net.NetworkPolicy in project android_frameworks_base by DirtyUnicorns.
the class NetworkPolicyEditor method setPolicyMetered.
public void setPolicyMetered(NetworkTemplate template, boolean metered) {
boolean modified = false;
NetworkPolicy policy = getPolicy(template);
if (metered) {
if (policy == null) {
policy = buildDefaultPolicy(template);
policy.metered = true;
policy.inferred = false;
mPolicies.add(policy);
modified = true;
} else if (!policy.metered) {
policy.metered = true;
policy.inferred = false;
modified = true;
}
} else {
if (policy == null) {
// ignore when policy doesn't exist
} else if (policy.metered) {
policy.metered = false;
policy.inferred = false;
modified = true;
}
}
// Remove legacy unquoted policies while we're here
final NetworkTemplate unquoted = buildUnquotedNetworkTemplate(template);
final NetworkPolicy unquotedPolicy = getPolicy(unquoted);
if (unquotedPolicy != null) {
mPolicies.remove(unquotedPolicy);
modified = true;
}
if (modified)
writeAsync();
}
use of android.net.NetworkPolicy in project android_frameworks_base by DirtyUnicorns.
the class NetworkPolicyEditor method getOrCreatePolicy.
public NetworkPolicy getOrCreatePolicy(NetworkTemplate template) {
NetworkPolicy policy = getPolicy(template);
if (policy == null) {
policy = buildDefaultPolicy(template);
mPolicies.add(policy);
}
return policy;
}
use of android.net.NetworkPolicy in project android_frameworks_base by DirtyUnicorns.
the class NetworkPolicyEditor method read.
public void read() {
final NetworkPolicy[] policies = mPolicyManager.getNetworkPolicies();
boolean modified = false;
mPolicies.clear();
for (NetworkPolicy policy : policies) {
// TODO: find better place to clamp these
if (policy.limitBytes < -1) {
policy.limitBytes = LIMIT_DISABLED;
modified = true;
}
if (policy.warningBytes < -1) {
policy.warningBytes = WARNING_DISABLED;
modified = true;
}
mPolicies.add(policy);
}
// when we cleaned policies above, write back changes
if (modified)
writeAsync();
}
use of android.net.NetworkPolicy in project android_frameworks_base by DirtyUnicorns.
the class NetworkPolicyEditor method setPolicyLimitBytes.
public void setPolicyLimitBytes(NetworkTemplate template, long limitBytes) {
final NetworkPolicy policy = getOrCreatePolicy(template);
policy.limitBytes = limitBytes;
policy.inferred = false;
policy.clearSnooze();
writeAsync();
}
use of android.net.NetworkPolicy in project android_frameworks_base by AOSPA.
the class NetworkPolicyEditor method setPolicyWarningBytes.
public void setPolicyWarningBytes(NetworkTemplate template, long warningBytes) {
final NetworkPolicy policy = getOrCreatePolicy(template);
policy.warningBytes = warningBytes;
policy.inferred = false;
policy.clearSnooze();
writeAsync();
}
Aggregations