use of android.net.NetworkPolicy in project android_frameworks_base by ParanoidAndroid.
the class NetworkPolicyManagerServiceTest method testLastCycleBoundaryThisMonth.
public void testLastCycleBoundaryThisMonth() throws Exception {
// assume cycle day of "5th", which should be in same month
final long currentTime = parseTime("2007-11-14T00:00:00.000Z");
final long expectedCycle = parseTime("2007-11-05T00:00:00.000Z");
final NetworkPolicy policy = new NetworkPolicy(sTemplateWifi, 5, TIMEZONE_UTC, 1024L, 1024L, false);
final long actualCycle = computeLastCycleBoundary(currentTime, policy);
assertTimeEquals(expectedCycle, actualCycle);
}
use of android.net.NetworkPolicy in project android_frameworks_base by ParanoidAndroid.
the class NetworkPolicyManagerServiceTest method testCycleBoundaryLeapYear.
public void testCycleBoundaryLeapYear() throws Exception {
final NetworkPolicy policy = new NetworkPolicy(sTemplateWifi, 29, TIMEZONE_UTC, 1024L, 1024L, false);
assertTimeEquals(parseTime("2012-01-29T00:00:00.000Z"), computeNextCycleBoundary(parseTime("2012-01-14T00:00:00.000Z"), policy));
assertTimeEquals(parseTime("2012-02-29T00:00:00.000Z"), computeNextCycleBoundary(parseTime("2012-02-14T00:00:00.000Z"), policy));
assertTimeEquals(parseTime("2012-02-29T00:00:00.000Z"), computeLastCycleBoundary(parseTime("2012-03-14T00:00:00.000Z"), policy));
assertTimeEquals(parseTime("2012-03-29T00:00:00.000Z"), computeNextCycleBoundary(parseTime("2012-03-14T00:00:00.000Z"), policy));
assertTimeEquals(parseTime("2007-01-29T00:00:00.000Z"), computeNextCycleBoundary(parseTime("2007-01-14T00:00:00.000Z"), policy));
assertTimeEquals(parseTime("2007-02-28T23:59:59.000Z"), computeNextCycleBoundary(parseTime("2007-02-14T00:00:00.000Z"), policy));
assertTimeEquals(parseTime("2007-02-28T23:59:59.000Z"), computeLastCycleBoundary(parseTime("2007-03-14T00:00:00.000Z"), policy));
assertTimeEquals(parseTime("2007-03-29T00:00:00.000Z"), computeNextCycleBoundary(parseTime("2007-03-14T00:00:00.000Z"), policy));
}
use of android.net.NetworkPolicy in project android_frameworks_base by ResurrectionRemix.
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 ResurrectionRemix.
the class NetworkPolicyEditor method buildDefaultPolicy.
@Deprecated
private static NetworkPolicy buildDefaultPolicy(NetworkTemplate template) {
// TODO: move this into framework to share with NetworkPolicyManagerService
final int cycleDay;
final String cycleTimezone;
final boolean metered;
if (template.getMatchRule() == MATCH_WIFI) {
cycleDay = CYCLE_NONE;
cycleTimezone = Time.TIMEZONE_UTC;
metered = false;
} else {
final Time time = new Time();
time.setToNow();
cycleDay = time.monthDay;
cycleTimezone = time.timezone;
metered = true;
}
return new NetworkPolicy(template, cycleDay, cycleTimezone, WARNING_DISABLED, LIMIT_DISABLED, SNOOZE_NEVER, SNOOZE_NEVER, metered, true);
}
use of android.net.NetworkPolicy in project android_frameworks_base by ResurrectionRemix.
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();
}
Aggregations