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;
}
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);
}
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();
}
}
}
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);
}
}
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;
}
Aggregations