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