diff options
| author | Jeff Sharkey <jsharkey@android.com> | 2011-07-25 15:21:22 -0700 |
|---|---|---|
| committer | Jeff Sharkey <jsharkey@android.com> | 2011-07-27 09:31:39 -0700 |
| commit | 41ff7ec82422a5b6d00892afdb3232bc0e53d851 (patch) | |
| tree | 9085ebb6bcc39a20f98eeb71860f2dad01f604ed /core/java/android | |
| parent | a94b9ad23ac1f281c9d2dac02d01aa07ca5e1682 (diff) | |
Revise data limit notifs, watch kernel alerts.
Teach NetworkPolicy limits to "snooze" when requested by user, and
notify with both dialog and notification. Register for network alerts
through NMS to trigger updates immediately instead of waiting for
next stats update.
Enforce that all NetworkPolicy are unique on a template basis, and
move SCREEN_ON/OFF broadcasts to background thread. Launch SystemUI
and Settings directly instead of using actions, and include full
NetworkTemplate in extras.
Tests to verify notification and snooze behavior.
Bug: 5057979, 5023579, 4723336, 5045721
Change-Id: I03724beff94a7c0547cb5220431ba8d4cd44d077
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/net/INetworkPolicyManager.aidl | 3 | ||||
| -rw-r--r-- | core/java/android/net/NetworkPolicy.java | 31 | ||||
| -rw-r--r-- | core/java/android/net/NetworkPolicyManager.java | 22 | ||||
| -rw-r--r-- | core/java/android/os/INetworkManagementService.aidl | 17 |
4 files changed, 48 insertions, 25 deletions
diff --git a/core/java/android/net/INetworkPolicyManager.aidl b/core/java/android/net/INetworkPolicyManager.aidl index 82495e381214..6fde746a556d 100644 --- a/core/java/android/net/INetworkPolicyManager.aidl +++ b/core/java/android/net/INetworkPolicyManager.aidl @@ -18,6 +18,7 @@ package android.net; import android.net.INetworkPolicyListener; import android.net.NetworkPolicy; +import android.net.NetworkTemplate; /** * Interface that creates and modifies network policy rules. @@ -37,4 +38,6 @@ interface INetworkPolicyManager { void setNetworkPolicies(in NetworkPolicy[] policies); NetworkPolicy[] getNetworkPolicies(); + void snoozePolicy(in NetworkTemplate template); + } diff --git a/core/java/android/net/NetworkPolicy.java b/core/java/android/net/NetworkPolicy.java index 52cab30f9ccc..aaad8a1c7a98 100644 --- a/core/java/android/net/NetworkPolicy.java +++ b/core/java/android/net/NetworkPolicy.java @@ -21,6 +21,8 @@ import static com.android.internal.util.Preconditions.checkNotNull; import android.os.Parcel; import android.os.Parcelable; +import com.android.internal.util.Objects; + /** * Policy for networks matching a {@link NetworkTemplate}, including usage cycle * and limits to be enforced. @@ -30,20 +32,21 @@ import android.os.Parcelable; public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> { public static final long WARNING_DISABLED = -1; public static final long LIMIT_DISABLED = -1; + public static final long SNOOZE_NEVER = -1; public final NetworkTemplate template; public int cycleDay; public long warningBytes; public long limitBytes; + public long lastSnooze; - // TODO: teach how to snooze limit for current cycle - - public NetworkPolicy( - NetworkTemplate template, int cycleDay, long warningBytes, long limitBytes) { + public NetworkPolicy(NetworkTemplate template, int cycleDay, long warningBytes, long limitBytes, + long lastSnooze) { this.template = checkNotNull(template, "missing NetworkTemplate"); this.cycleDay = cycleDay; this.warningBytes = warningBytes; this.limitBytes = limitBytes; + this.lastSnooze = lastSnooze; } public NetworkPolicy(Parcel in) { @@ -51,6 +54,7 @@ public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> { cycleDay = in.readInt(); warningBytes = in.readLong(); limitBytes = in.readLong(); + lastSnooze = in.readLong(); } /** {@inheritDoc} */ @@ -59,6 +63,7 @@ public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> { dest.writeInt(cycleDay); dest.writeLong(warningBytes); dest.writeLong(limitBytes); + dest.writeLong(lastSnooze); } /** {@inheritDoc} */ @@ -80,9 +85,25 @@ public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> { } @Override + public int hashCode() { + return Objects.hashCode(template, cycleDay, warningBytes, limitBytes, lastSnooze); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof NetworkPolicy) { + final NetworkPolicy other = (NetworkPolicy) obj; + return Objects.equal(template, other.template) && cycleDay == other.cycleDay + && warningBytes == other.warningBytes && limitBytes == other.limitBytes + && lastSnooze == other.lastSnooze; + } + return false; + } + + @Override public String toString() { return "NetworkPolicy[" + template + "]: cycleDay=" + cycleDay + ", warningBytes=" - + warningBytes + ", limitBytes=" + limitBytes; + + warningBytes + ", limitBytes=" + limitBytes + ", lastSnooze=" + lastSnooze; } 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 593b2b74e301..1e9d81319297 100644 --- a/core/java/android/net/NetworkPolicyManager.java +++ b/core/java/android/net/NetworkPolicyManager.java @@ -52,26 +52,10 @@ public class NetworkPolicyManager { private static final boolean ALLOW_PLATFORM_APP_POLICY = true; /** - * {@link Intent} action launched when user selects {@link NetworkPolicy} - * warning notification. + * {@link Intent} extra that indicates which {@link NetworkTemplate} rule it + * applies to. */ - public static final String ACTION_DATA_USAGE_WARNING = - "android.intent.action.DATA_USAGE_WARNING"; - - /** - * {@link Intent} action launched when user selects {@link NetworkPolicy} - * limit notification. - */ - public static final String ACTION_DATA_USAGE_LIMIT = - "android.intent.action.DATA_USAGE_LIMIT"; - - /** - * {@link Intent} extra included in {@link #ACTION_DATA_USAGE_WARNING} and - * {@link #ACTION_DATA_USAGE_LIMIT} to indicate which - * {@link NetworkTemplate} rule it applies to. - */ - public static final String EXTRA_NETWORK_TEMPLATE = - "android.intent.extra.NETWORK_TEMPLATE"; + public static final String EXTRA_NETWORK_TEMPLATE = "android.net.NETWORK_TEMPLATE"; private INetworkPolicyManager mService; diff --git a/core/java/android/os/INetworkManagementService.aidl b/core/java/android/os/INetworkManagementService.aidl index 03a6c07e6448..3704248e8076 100644 --- a/core/java/android/os/INetworkManagementService.aidl +++ b/core/java/android/os/INetworkManagementService.aidl @@ -212,7 +212,7 @@ interface INetworkManagementService /** * Set quota for an interface. */ - void setInterfaceQuota(String iface, long quota); + void setInterfaceQuota(String iface, long quotaBytes); /** * Remove quota for an interface. @@ -220,6 +220,21 @@ interface INetworkManagementService void removeInterfaceQuota(String iface); /** + * Set alert for an interface; requires that iface already has quota. + */ + void setInterfaceAlert(String iface, long alertBytes); + + /** + * Remove alert for an interface. + */ + void removeInterfaceAlert(String iface); + + /** + * Set alert across all interfaces. + */ + void setGlobalAlert(long alertBytes); + + /** * Control network activity of a UID over interfaces with a quota limit. */ void setUidNetworkRules(int uid, boolean rejectOnQuotaInterfaces); |
