Search in sources :

Example 86 with NetworkPolicy

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

Example 87 with NetworkPolicy

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

Example 88 with NetworkPolicy

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

Example 89 with NetworkPolicy

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

Example 90 with NetworkPolicy

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

Aggregations

NetworkPolicy (android.net.NetworkPolicy)213 NetworkTemplate (android.net.NetworkTemplate)33 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 Test (org.junit.Test)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 EasyMock.anyLong (org.easymock.EasyMock.anyLong)8 NetworkQuotaInfo (android.net.NetworkQuotaInfo)6