diff options
Diffstat (limited to 'core/java/android/net')
-rw-r--r-- | core/java/android/net/INetworkPolicyManager.aidl | 4 | ||||
-rw-r--r-- | core/java/android/net/NetworkPolicy.java | 32 | ||||
-rw-r--r-- | core/java/android/net/NetworkPolicyManager.java | 8 | ||||
-rw-r--r-- | core/java/android/net/TrafficStats.java | 19 |
4 files changed, 44 insertions, 19 deletions
diff --git a/core/java/android/net/INetworkPolicyManager.aidl b/core/java/android/net/INetworkPolicyManager.aidl index c9238eb..82495e3 100644 --- a/core/java/android/net/INetworkPolicyManager.aidl +++ b/core/java/android/net/INetworkPolicyManager.aidl @@ -34,7 +34,7 @@ interface INetworkPolicyManager { void registerListener(INetworkPolicyListener listener); void unregisterListener(INetworkPolicyListener listener); - void setNetworkPolicy(int networkType, String subscriberId, in NetworkPolicy policy); - NetworkPolicy getNetworkPolicy(int networkType, String subscriberId); + void setNetworkPolicies(in NetworkPolicy[] policies); + NetworkPolicy[] getNetworkPolicies(); } diff --git a/core/java/android/net/NetworkPolicy.java b/core/java/android/net/NetworkPolicy.java index b9909c3..1899281 100644 --- a/core/java/android/net/NetworkPolicy.java +++ b/core/java/android/net/NetworkPolicy.java @@ -26,17 +26,27 @@ import android.os.Parcelable; * @hide */ public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> { - public final int cycleDay; - public final long warningBytes; - public final long limitBytes; + public final int networkTemplate; + public final String subscriberId; + public int cycleDay; + public long warningBytes; + public long limitBytes; - public NetworkPolicy(int cycleDay, long warningBytes, long limitBytes) { + public static final long WARNING_DISABLED = -1; + public static final long LIMIT_DISABLED = -1; + + public NetworkPolicy(int networkTemplate, String subscriberId, int cycleDay, long warningBytes, + long limitBytes) { + this.networkTemplate = networkTemplate; + this.subscriberId = subscriberId; this.cycleDay = cycleDay; this.warningBytes = warningBytes; this.limitBytes = limitBytes; } public NetworkPolicy(Parcel in) { + networkTemplate = in.readInt(); + subscriberId = in.readString(); cycleDay = in.readInt(); warningBytes = in.readLong(); limitBytes = in.readLong(); @@ -44,6 +54,8 @@ public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> { /** {@inheritDoc} */ public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(networkTemplate); + dest.writeString(subscriberId); dest.writeInt(cycleDay); dest.writeLong(warningBytes); dest.writeLong(limitBytes); @@ -56,17 +68,21 @@ public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> { /** {@inheritDoc} */ public int compareTo(NetworkPolicy another) { - if (another == null || limitBytes < another.limitBytes) { + if (another == null || another.limitBytes == LIMIT_DISABLED) { + // other value is missing or disabled; we win return -1; - } else { + } + if (limitBytes == LIMIT_DISABLED || another.limitBytes < limitBytes) { + // we're disabled or other limit is smaller; they win return 1; } + return 0; } @Override public String toString() { - return "NetworkPolicy: cycleDay=" + cycleDay + ", warningBytes=" + warningBytes - + ", limitBytes=" + limitBytes; + return "NetworkPolicy: networkTemplate=" + networkTemplate + ", cycleDay=" + cycleDay + + ", warningBytes=" + warningBytes + ", limitBytes=" + limitBytes; } public static final Creator<NetworkPolicy> CREATOR = new Creator<NetworkPolicy>() { diff --git a/core/java/android/net/NetworkPolicyManager.java b/core/java/android/net/NetworkPolicyManager.java index 08b1a81..13ece40 100644 --- a/core/java/android/net/NetworkPolicyManager.java +++ b/core/java/android/net/NetworkPolicyManager.java @@ -55,17 +55,17 @@ public class NetworkPolicyManager { } /** {@hide} */ - public void setNetworkPolicy(int networkType, String subscriberId, NetworkPolicy policy) { + public void setNetworkPolicies(NetworkPolicy[] policies) { try { - mService.setNetworkPolicy(networkType, subscriberId, policy); + mService.setNetworkPolicies(policies); } catch (RemoteException e) { } } /** {@hide} */ - public NetworkPolicy getNetworkPolicy(int networkType, String subscriberId) { + public NetworkPolicy[] getNetworkPolicies() { try { - return mService.getNetworkPolicy(networkType, subscriberId); + return mService.getNetworkPolicies(); } catch (RemoteException e) { return null; } diff --git a/core/java/android/net/TrafficStats.java b/core/java/android/net/TrafficStats.java index 8a688d5..3725fa6 100644 --- a/core/java/android/net/TrafficStats.java +++ b/core/java/android/net/TrafficStats.java @@ -41,11 +41,9 @@ public class TrafficStats { */ public final static int UNSUPPORTED = -1; - // TODO: find better home for these template constants - /** * Template to combine all {@link ConnectivityManager#TYPE_MOBILE} style - * networks together. Only uses statistics for currently active IMSI. + * networks together. Only uses statistics for requested IMSI. * * @hide */ @@ -54,7 +52,7 @@ public class TrafficStats { /** * Template to combine all {@link ConnectivityManager#TYPE_MOBILE} style * networks together that roughly meet a "3G" definition, or lower. Only - * uses statistics for currently active IMSI. + * uses statistics for requested IMSI. * * @hide */ @@ -63,7 +61,7 @@ public class TrafficStats { /** * Template to combine all {@link ConnectivityManager#TYPE_MOBILE} style * networks together that meet a "4G" definition. Only uses statistics for - * currently active IMSI. + * requested IMSI. * * @hide */ @@ -184,6 +182,17 @@ public class TrafficStats { } } + /** {@hide} */ + public static boolean isNetworkTemplateMobile(int networkTemplate) { + switch (networkTemplate) { + case TEMPLATE_MOBILE_3G_LOWER: + case TEMPLATE_MOBILE_4G: + case TEMPLATE_MOBILE_ALL: + return true; + } + return false; + } + /** * Get the total number of packets transmitted through the mobile interface. * |