use of android.net.NetworkPolicy in project android_frameworks_base by AOSPA.
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 AOSPA.
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 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 AOSPA.
the class NetworkPolicyEditor method setPolicyCycleDay.
public void setPolicyCycleDay(NetworkTemplate template, int cycleDay, String cycleTimezone) {
final NetworkPolicy policy = getOrCreatePolicy(template);
policy.cycleDay = cycleDay;
policy.cycleTimezone = cycleTimezone;
policy.inferred = false;
policy.clearSnooze();
writeAsync();
}
use of android.net.NetworkPolicy in project android_frameworks_base by AOSPA.
the class DataUsageController method getDataUsageInfo.
public DataUsageInfo getDataUsageInfo(NetworkTemplate template) {
final INetworkStatsSession session = getSession();
if (session == null) {
return warn("no stats session");
}
final NetworkPolicy policy = findNetworkPolicy(template);
try {
final NetworkStatsHistory history = session.getHistoryForNetwork(template, FIELDS);
final long now = System.currentTimeMillis();
final long start, end;
if (policy != null && policy.cycleDay > 0) {
// period = determined from cycleDay
if (DEBUG)
Log.d(TAG, "Cycle day=" + policy.cycleDay + " tz=" + policy.cycleTimezone);
final Time nowTime = new Time(policy.cycleTimezone);
nowTime.setToNow();
final Time policyTime = new Time(nowTime);
policyTime.set(policy.cycleDay, policyTime.month, policyTime.year);
policyTime.normalize(false);
if (nowTime.after(policyTime)) {
start = policyTime.toMillis(false);
end = addMonth(policyTime, 1).toMillis(false);
} else {
start = addMonth(policyTime, -1).toMillis(false);
end = policyTime.toMillis(false);
}
} else {
// period = last 4 wks
end = now;
start = now - DateUtils.WEEK_IN_MILLIS * 4;
}
final long callStart = System.currentTimeMillis();
final NetworkStatsHistory.Entry entry = history.getValues(start, end, now, null);
final long callEnd = System.currentTimeMillis();
if (DEBUG)
Log.d(TAG, String.format("history call from %s to %s now=%s took %sms: %s", new Date(start), new Date(end), new Date(now), callEnd - callStart, historyEntryToString(entry)));
if (entry == null) {
return warn("no entry data");
}
final long totalBytes = entry.rxBytes + entry.txBytes;
final DataUsageInfo usage = new DataUsageInfo();
usage.startDate = start;
usage.usageLevel = totalBytes;
usage.period = formatDateRange(start, end);
if (policy != null) {
usage.limitLevel = policy.limitBytes > 0 ? policy.limitBytes : 0;
usage.warningLevel = policy.warningBytes > 0 ? policy.warningBytes : 0;
} else {
usage.warningLevel = getDefaultWarningLevel();
}
if (usage != null && mNetworkController != null) {
usage.carrier = mNetworkController.getMobileDataNetworkName();
}
return usage;
} catch (RemoteException e) {
return warn("remote call failed");
}
}
Aggregations