Search in sources :

Example 61 with NetworkPolicy

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

the class NetworkPolicyManagerService method updateNetworkEnabledNL.

/**
     * Proactively control network data connections when they exceed
     * {@link NetworkPolicy#limitBytes}.
     */
void updateNetworkEnabledNL() {
    if (LOGV)
        Slog.v(TAG, "updateNetworkEnabledNL()");
    // TODO: reset any policy-disabled networks when any policy is removed
    // completely, which is currently rare case.
    final long currentTime = currentTimeMillis();
    for (int i = mNetworkPolicy.size() - 1; i >= 0; i--) {
        final NetworkPolicy policy = mNetworkPolicy.valueAt(i);
        // shortcut when policy has no limit
        if (policy.limitBytes == LIMIT_DISABLED || !policy.hasCycle()) {
            setNetworkTemplateEnabled(policy.template, true);
            continue;
        }
        final long start = computeLastCycleBoundary(currentTime, policy);
        final long end = currentTime;
        final long totalBytes = getTotalBytes(policy.template, start, end);
        // disable data connection when over limit and not snoozed
        final boolean overLimitWithoutSnooze = policy.isOverLimit(totalBytes) && policy.lastLimitSnooze < start;
        final boolean networkEnabled = !overLimitWithoutSnooze;
        setNetworkTemplateEnabled(policy.template, networkEnabled);
    }
}
Also used : NetworkPolicy(android.net.NetworkPolicy)

Example 62 with NetworkPolicy

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

the class NetworkPolicyManagerShellCommand method setMeteredWifiNetwork.

private int setMeteredWifiNetwork() throws RemoteException {
    final PrintWriter pw = getOutPrintWriter();
    final String id = getNextArg();
    if (id == null) {
        pw.println("Error: didn't specify ID");
        return -1;
    }
    final String arg = getNextArg();
    if (arg == null) {
        pw.println("Error: didn't specify BOOLEAN");
        return -1;
    }
    final boolean metered = Boolean.valueOf(arg);
    final NetworkPolicy[] policies = mInterface.getNetworkPolicies(null);
    boolean changed = false;
    // First try to find a policy with such id
    for (NetworkPolicy policy : policies) {
        if (policy.template.isMatchRuleMobile() || policy.metered == metered) {
            continue;
        }
        final String networkId = getNetworkId(policy);
        if (id.equals(networkId)) {
            Log.i(TAG, "Changing " + networkId + " metered status to " + metered);
            policy.metered = metered;
            changed = true;
        }
    }
    if (changed) {
        mInterface.setNetworkPolicies(policies);
        return 0;
    }
    // Policy not found: check if there is a saved wi-fi with such id.
    for (WifiConfiguration config : mWifiManager.getConfiguredNetworks()) {
        final String ssid = removeDoubleQuotes(config.SSID);
        if (id.equals(ssid)) {
            final NetworkPolicy policy = newPolicy(ssid);
            policy.metered = true;
            Log.i(TAG, "Creating new policy for " + ssid + ": " + policy);
            final NetworkPolicy[] newPolicies = new NetworkPolicy[policies.length + 1];
            System.arraycopy(policies, 0, newPolicies, 0, policies.length);
            newPolicies[newPolicies.length - 1] = policy;
            mInterface.setNetworkPolicies(newPolicies);
        }
    }
    return 0;
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration) NetworkPolicy(android.net.NetworkPolicy) PrintWriter(java.io.PrintWriter)

Example 63 with NetworkPolicy

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

the class DataUsageController method findNetworkPolicy.

private NetworkPolicy findNetworkPolicy(NetworkTemplate template) {
    if (mPolicyManager == null || template == null)
        return null;
    final NetworkPolicy[] policies = mPolicyManager.getNetworkPolicies();
    if (policies == null)
        return null;
    final int N = policies.length;
    for (int i = 0; i < N; i++) {
        final NetworkPolicy policy = policies[i];
        if (policy != null && template.equals(policy.template)) {
            return policy;
        }
    }
    return null;
}
Also used : NetworkPolicy(android.net.NetworkPolicy)

Example 64 with NetworkPolicy

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

the class BillingCycleSettings method updatePrefs.

private void updatePrefs() {
    NetworkPolicy policy = services.mPolicyEditor.getPolicy(mNetworkTemplate);
    mBillingCycle.setSummary(getString(R.string.billing_cycle_summary, policy != null ? policy.cycleDay : 1));
    if (policy != null && policy.warningBytes != WARNING_DISABLED) {
        mDataWarning.setSummary(Formatter.formatFileSize(getContext(), policy.warningBytes));
        mDataWarning.setEnabled(true);
        mEnableDataWarning.setChecked(true);
    } else {
        mDataWarning.setSummary(null);
        mDataWarning.setEnabled(false);
        mEnableDataWarning.setChecked(false);
    }
    if (policy != null && policy.limitBytes != LIMIT_DISABLED) {
        mDataLimit.setSummary(Formatter.formatFileSize(getContext(), policy.limitBytes));
        mDataLimit.setEnabled(true);
        mEnableDataLimit.setChecked(true);
    } else {
        mDataLimit.setSummary(null);
        mDataLimit.setEnabled(false);
        mEnableDataLimit.setChecked(false);
    }
    mEnableDataTimeRange.setChecked(mShowDataUsage);
}
Also used : NetworkPolicy(android.net.NetworkPolicy)

Example 65 with NetworkPolicy

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

the class DataUsageList method updatePolicy.

/**
     * Update chart sweeps and cycle list to reflect {@link NetworkPolicy} for
     * current {@link #mTemplate}.
     */
private void updatePolicy(boolean refreshCycle) {
    final NetworkPolicy policy = services.mPolicyEditor.getPolicy(mTemplate);
    //SUB SELECT
    if (isNetworkPolicyModifiable(policy, mSubId) && isMobileDataAvailable(mSubId)) {
        if (mDataSelectionEnable) {
            mChartDeprecated.bindNetworkPolicy(policy);
        } else {
            mChart.setNetworkPolicy(policy);
        }
        mHeader.findViewById(R.id.filter_settings).setVisibility(View.VISIBLE);
        mHeader.findViewById(R.id.filter_settings).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Bundle args = new Bundle();
                args.putParcelable(DataUsageList.EXTRA_NETWORK_TEMPLATE, mTemplate);
                startFragment(DataUsageList.this, BillingCycleSettings.class.getName(), R.string.billing_cycle, 0, args);
            }
        });
    } else {
        // controls are disabled; don't bind warning/limit sweeps
        if (mDataSelectionEnable) {
            mChartDeprecated.bindNetworkPolicy(null);
        } else {
            mChart.setNetworkPolicy(null);
        }
        mHeader.findViewById(R.id.filter_settings).setVisibility(View.GONE);
    }
    if (refreshCycle) {
        // generate cycle list based on policy and available history
        if (mCycleAdapter.updateCycleList(policy, mChartData)) {
            updateDetailData();
        }
    }
}
Also used : NetworkPolicy(android.net.NetworkPolicy) Bundle(android.os.Bundle) View(android.view.View) AdapterView(android.widget.AdapterView)

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