use of android.net.NetworkIdentity in project platform_frameworks_base by android.
the class NetworkIdentitySet method writeToStream.
public void writeToStream(DataOutputStream out) throws IOException {
out.writeInt(VERSION_ADD_METERED);
out.writeInt(size());
for (NetworkIdentity ident : this) {
out.writeInt(ident.getType());
out.writeInt(ident.getSubType());
writeOptionalString(out, ident.getSubscriberId());
writeOptionalString(out, ident.getNetworkId());
out.writeBoolean(ident.getRoaming());
out.writeBoolean(ident.getMetered());
}
}
use of android.net.NetworkIdentity in project platform_frameworks_base by android.
the class NetworkPolicyManagerService method isNetworkMetered.
@Override
public boolean isNetworkMetered(NetworkState state) {
if (state.networkInfo == null) {
return false;
}
final NetworkIdentity ident = NetworkIdentity.buildNetworkIdentity(mContext, state);
final NetworkPolicy policy;
synchronized (mNetworkPoliciesSecondLock) {
policy = findPolicyForNetworkNL(ident);
}
if (policy != null) {
return policy.metered;
} else {
final int type = state.networkInfo.getType();
if ((isNetworkTypeMobile(type) && ident.getMetered()) || type == TYPE_WIMAX) {
return true;
}
return false;
}
}
use of android.net.NetworkIdentity in project android_frameworks_base by DirtyUnicorns.
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.NetworkIdentity in project android_frameworks_base by DirtyUnicorns.
the class NetworkPolicyManagerService method isNetworkMetered.
@Override
public boolean isNetworkMetered(NetworkState state) {
if (state.networkInfo == null) {
return false;
}
final NetworkIdentity ident = NetworkIdentity.buildNetworkIdentity(mContext, state);
final NetworkPolicy policy;
synchronized (mNetworkPoliciesSecondLock) {
policy = findPolicyForNetworkNL(ident);
}
if (policy != null) {
return policy.metered;
} else {
final int type = state.networkInfo.getType();
if ((isNetworkTypeMobile(type) && ident.getMetered()) || type == TYPE_WIMAX) {
return true;
}
return false;
}
}
use of android.net.NetworkIdentity in project android_frameworks_base by DirtyUnicorns.
the class NetworkPolicyManagerService method isTemplateRelevant.
/**
* Test if given {@link NetworkTemplate} is relevant to user based on
* current device state, such as when
* {@link TelephonyManager#getSubscriberId()} matches. This is regardless of
* data connection status.
*/
private boolean isTemplateRelevant(NetworkTemplate template) {
if (template.isMatchRuleMobile()) {
final TelephonyManager tele = TelephonyManager.from(mContext);
final SubscriptionManager sub = SubscriptionManager.from(mContext);
// Mobile template is relevant when any active subscriber matches
final int[] subIds = sub.getActiveSubscriptionIdList();
for (int subId : subIds) {
final String subscriberId = tele.getSubscriberId(subId);
final NetworkIdentity probeIdent = new NetworkIdentity(TYPE_MOBILE, TelephonyManager.NETWORK_TYPE_UNKNOWN, subscriberId, null, false, true);
if (template.matches(probeIdent)) {
return true;
}
}
return false;
} else {
return true;
}
}
Aggregations