Search in sources :

Example 96 with NetworkPolicy

use of android.net.NetworkPolicy in project android_frameworks_base by ResurrectionRemix.

the class NetworkPolicyManagerService method ensureActiveMobilePolicyNL.

private void ensureActiveMobilePolicyNL(String subscriberId) {
    // Poke around to see if we already have a policy
    final NetworkIdentity probeIdent = new NetworkIdentity(TYPE_MOBILE, TelephonyManager.NETWORK_TYPE_UNKNOWN, subscriberId, null, false, true);
    for (int i = mNetworkPolicy.size() - 1; i >= 0; i--) {
        final NetworkTemplate template = mNetworkPolicy.keyAt(i);
        if (template.matches(probeIdent)) {
            if (LOGD) {
                Slog.d(TAG, "Found template " + template + " which matches subscriber " + NetworkIdentity.scrubSubscriberId(subscriberId));
            }
            return;
        }
    }
    Slog.i(TAG, "No policy for subscriber " + NetworkIdentity.scrubSubscriberId(subscriberId) + "; generating default policy");
    // Build default mobile policy, and assume usage cycle starts today
    final int dataWarningConfig = mContext.getResources().getInteger(com.android.internal.R.integer.config_networkPolicyDefaultWarning);
    final long warningBytes;
    if (dataWarningConfig == WARNING_DISABLED) {
        warningBytes = WARNING_DISABLED;
    } else {
        warningBytes = dataWarningConfig * MB_IN_BYTES;
    }
    final Time time = new Time();
    time.setToNow();
    final int cycleDay = time.monthDay;
    final String cycleTimezone = time.timezone;
    final NetworkTemplate template = buildTemplateMobileAll(subscriberId);
    final NetworkPolicy policy = new NetworkPolicy(template, cycleDay, cycleTimezone, warningBytes, LIMIT_DISABLED, SNOOZE_NEVER, SNOOZE_NEVER, true, true);
    addNetworkPolicyNL(policy);
}
Also used : NetworkTemplate(android.net.NetworkTemplate) NetworkIdentity(android.net.NetworkIdentity) NetworkPolicy(android.net.NetworkPolicy) Time(android.text.format.Time) TrustedTime(android.util.TrustedTime) NtpTrustedTime(android.util.NtpTrustedTime) NetworkPolicyManager.uidRulesToString(android.net.NetworkPolicyManager.uidRulesToString)

Example 97 with NetworkPolicy

use of android.net.NetworkPolicy in project android_frameworks_base by ResurrectionRemix.

the class NetworkPolicyManagerShellCommand method newPolicy.

private NetworkPolicy newPolicy(String ssid) {
    final NetworkTemplate template = NetworkTemplate.buildTemplateWifi(ssid);
    final NetworkPolicy policy = newWifiPolicy(template, false);
    return policy;
}
Also used : NetworkTemplate(android.net.NetworkTemplate) NetworkPolicy(android.net.NetworkPolicy)

Example 98 with NetworkPolicy

use of android.net.NetworkPolicy in project android_frameworks_base by ResurrectionRemix.

the class NetworkPolicyManagerShellCommand method listWifiNetworks.

private int listWifiNetworks() throws RemoteException {
    final PrintWriter pw = getOutPrintWriter();
    final String arg = getNextArg();
    final Boolean filter = arg == null ? null : Boolean.valueOf(arg);
    for (NetworkPolicy policy : getWifiPolicies()) {
        if (filter != null && filter.booleanValue() != policy.metered) {
            continue;
        }
        pw.print(getNetworkId(policy));
        pw.print(';');
        pw.println(policy.metered);
    }
    return 0;
}
Also used : NetworkPolicy(android.net.NetworkPolicy) PrintWriter(java.io.PrintWriter)

Example 99 with NetworkPolicy

use of android.net.NetworkPolicy in project android_frameworks_base by ResurrectionRemix.

the class NetworkPolicyManagerService method getNetworkQuotaInfoUnchecked.

private NetworkQuotaInfo getNetworkQuotaInfoUnchecked(NetworkState state) {
    final NetworkIdentity ident = NetworkIdentity.buildNetworkIdentity(mContext, state);
    final NetworkPolicy policy;
    synchronized (mNetworkPoliciesSecondLock) {
        policy = findPolicyForNetworkNL(ident);
    }
    if (policy == null || !policy.hasCycle()) {
        // missing policy means we can't derive useful quota info
        return null;
    }
    final long currentTime = currentTimeMillis();
    // find total bytes used under policy
    final long start = computeLastCycleBoundary(currentTime, policy);
    final long end = currentTime;
    final long totalBytes = getTotalBytes(policy.template, start, end);
    // report soft and hard limits under policy
    final long softLimitBytes = policy.warningBytes != WARNING_DISABLED ? policy.warningBytes : NetworkQuotaInfo.NO_LIMIT;
    final long hardLimitBytes = policy.limitBytes != LIMIT_DISABLED ? policy.limitBytes : NetworkQuotaInfo.NO_LIMIT;
    return new NetworkQuotaInfo(totalBytes, softLimitBytes, hardLimitBytes);
}
Also used : NetworkQuotaInfo(android.net.NetworkQuotaInfo) NetworkIdentity(android.net.NetworkIdentity) NetworkPolicy(android.net.NetworkPolicy)

Example 100 with NetworkPolicy

use of android.net.NetworkPolicy in project android_frameworks_base by ResurrectionRemix.

the class NetworkPolicyManagerService method performSnooze.

void performSnooze(NetworkTemplate template, int type) {
    maybeRefreshTrustedTime();
    final long currentTime = currentTimeMillis();
    synchronized (mUidRulesFirstLock) {
        synchronized (mNetworkPoliciesSecondLock) {
            // find and snooze local policy that matches
            final NetworkPolicy policy = mNetworkPolicy.get(template);
            if (policy == null) {
                throw new IllegalArgumentException("unable to find policy for " + template);
            }
            switch(type) {
                case TYPE_WARNING:
                    policy.lastWarningSnooze = currentTime;
                    break;
                case TYPE_LIMIT:
                    policy.lastLimitSnooze = currentTime;
                    break;
                default:
                    throw new IllegalArgumentException("unexpected type");
            }
            normalizePoliciesNL();
            updateNetworkEnabledNL();
            updateNetworkRulesNL();
            updateNotificationsNL();
            writePolicyAL();
        }
    }
}
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