Search in sources :

Example 11 with NetworkPolicy

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);
}
Also used : NetworkPolicy(android.net.NetworkPolicy)

Example 12 with NetworkPolicy

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));
}
Also used : NetworkPolicy(android.net.NetworkPolicy)

Example 13 with NetworkPolicy

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();
}
Also used : NetworkPolicy(android.net.NetworkPolicy)

Example 14 with NetworkPolicy

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);
}
Also used : NetworkPolicy(android.net.NetworkPolicy) Time(android.text.format.Time)

Example 15 with NetworkPolicy

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();
}
Also used : NetworkPolicy(android.net.NetworkPolicy)

Aggregations

NetworkPolicy (android.net.NetworkPolicy)275 Test (org.junit.Test)57 NetworkTemplate (android.net.NetworkTemplate)40 NetworkPolicyManager.uidRulesToString (android.net.NetworkPolicyManager.uidRulesToString)30 NetworkIdentity (android.net.NetworkIdentity)24 IOException (java.io.IOException)22 NetworkState (android.net.NetworkState)21 Time (android.text.format.Time)16 NetworkStats (android.net.NetworkStats)15 RemoteException (android.os.RemoteException)11 Intent (android.content.Intent)10 NetworkPolicyManager (android.net.NetworkPolicyManager)10 WifiConfiguration (android.net.wifi.WifiConfiguration)10 ArraySet (android.util.ArraySet)10 PrintWriter (java.io.PrintWriter)10 ArrayList (java.util.ArrayList)10 LinkedHashSet (java.util.LinkedHashSet)10 Suppress (android.test.suitebuilder.annotation.Suppress)9 View (android.view.View)8 AdapterView (android.widget.AdapterView)8