Search in sources :

Example 46 with NetworkIdentity

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());
    }
}
Also used : NetworkIdentity(android.net.NetworkIdentity)

Example 47 with NetworkIdentity

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;
    }
}
Also used : NetworkIdentity(android.net.NetworkIdentity) NetworkPolicy(android.net.NetworkPolicy)

Example 48 with NetworkIdentity

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);
}
Also used : NetworkQuotaInfo(android.net.NetworkQuotaInfo) NetworkIdentity(android.net.NetworkIdentity) NetworkPolicy(android.net.NetworkPolicy)

Example 49 with NetworkIdentity

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;
    }
}
Also used : NetworkIdentity(android.net.NetworkIdentity) NetworkPolicy(android.net.NetworkPolicy)

Example 50 with NetworkIdentity

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;
    }
}
Also used : NetworkIdentity(android.net.NetworkIdentity) TelephonyManager(android.telephony.TelephonyManager) SubscriptionManager(android.telephony.SubscriptionManager) NetworkPolicyManager.uidRulesToString(android.net.NetworkPolicyManager.uidRulesToString)

Aggregations

NetworkIdentity (android.net.NetworkIdentity)82 NetworkStats (android.net.NetworkStats)32 DataUsageRequest (android.net.DataUsageRequest)28 NetworkPolicy (android.net.NetworkPolicy)24 NetworkPolicyManager.uidRulesToString (android.net.NetworkPolicyManager.uidRulesToString)20 NetworkState (android.net.NetworkState)11 RemoteException (android.os.RemoteException)11 TelephonyManager (android.telephony.TelephonyManager)11 LinkProperties (android.net.LinkProperties)10 SubscriptionManager (android.telephony.SubscriptionManager)10 ArraySet (android.util.ArraySet)10 NetworkQuotaInfo (android.net.NetworkQuotaInfo)6 NetworkTemplate (android.net.NetworkTemplate)6 Time (android.text.format.Time)6 NtpTrustedTime (android.util.NtpTrustedTime)6 TrustedTime (android.util.TrustedTime)6 Pair (android.util.Pair)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)1 Map (java.util.Map)1