summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2012-03-09 17:07:21 -0800
committerJeff Sharkey <jsharkey@android.com>2012-03-09 17:10:05 -0800
commit9bf3150cfae03421c9dd237b46657714859d871c (patch)
treef62a9a964ba0c745ec0cd45814a45cf8fbf922e4 /core
parent92d291ef6481c6cbb1305780dd4f450a16bb9a7a (diff)
downloadframeworks_base-9bf3150cfae03421c9dd237b46657714859d871c.zip
frameworks_base-9bf3150cfae03421c9dd237b46657714859d871c.tar.gz
frameworks_base-9bf3150cfae03421c9dd237b46657714859d871c.tar.bz2
Save timezone when setting data cycle reset date.
Instead of cycle reset at midnight UTC, use midnight of timezone active when user last set cycle reset date. Tests to verify, and also to test leap year behavior. Bug: 5938567 Change-Id: Ie06f7f0fa242d23110f9586a3f4f7037af87b31b
Diffstat (limited to 'core')
-rw-r--r--core/java/android/net/NetworkPolicy.java37
-rw-r--r--core/java/android/net/NetworkPolicyManager.java6
2 files changed, 26 insertions, 17 deletions
diff --git a/core/java/android/net/NetworkPolicy.java b/core/java/android/net/NetworkPolicy.java
index 04cf1a3..5b94784 100644
--- a/core/java/android/net/NetworkPolicy.java
+++ b/core/java/android/net/NetworkPolicy.java
@@ -36,6 +36,7 @@ public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> {
public final NetworkTemplate template;
public int cycleDay;
+ public String cycleTimezone;
public long warningBytes;
public long limitBytes;
public long lastWarningSnooze;
@@ -44,15 +45,18 @@ public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> {
private static final long DEFAULT_MTU = 1500;
- public NetworkPolicy(NetworkTemplate template, int cycleDay, long warningBytes,
- long limitBytes, boolean metered) {
- this(template, cycleDay, warningBytes, limitBytes, SNOOZE_NEVER, SNOOZE_NEVER, metered);
+ public NetworkPolicy(NetworkTemplate template, int cycleDay, String cycleTimezone,
+ long warningBytes, long limitBytes, boolean metered) {
+ this(template, cycleDay, cycleTimezone, warningBytes, limitBytes, SNOOZE_NEVER,
+ SNOOZE_NEVER, metered);
}
- public NetworkPolicy(NetworkTemplate template, int cycleDay, long warningBytes,
- long limitBytes, long lastWarningSnooze, long lastLimitSnooze, boolean metered) {
+ public NetworkPolicy(NetworkTemplate template, int cycleDay, String cycleTimezone,
+ long warningBytes, long limitBytes, long lastWarningSnooze, long lastLimitSnooze,
+ boolean metered) {
this.template = checkNotNull(template, "missing NetworkTemplate");
this.cycleDay = cycleDay;
+ this.cycleTimezone = checkNotNull(cycleTimezone, "missing cycleTimezone");
this.warningBytes = warningBytes;
this.limitBytes = limitBytes;
this.lastWarningSnooze = lastWarningSnooze;
@@ -63,6 +67,7 @@ public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> {
public NetworkPolicy(Parcel in) {
template = in.readParcelable(null);
cycleDay = in.readInt();
+ cycleTimezone = in.readString();
warningBytes = in.readLong();
limitBytes = in.readLong();
lastWarningSnooze = in.readLong();
@@ -70,10 +75,11 @@ public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> {
metered = in.readInt() != 0;
}
- /** {@inheritDoc} */
+ @Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeParcelable(template, flags);
dest.writeInt(cycleDay);
+ dest.writeString(cycleTimezone);
dest.writeLong(warningBytes);
dest.writeLong(limitBytes);
dest.writeLong(lastWarningSnooze);
@@ -81,7 +87,7 @@ public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> {
dest.writeInt(metered ? 1 : 0);
}
- /** {@inheritDoc} */
+ @Override
public int describeContents() {
return 0;
}
@@ -112,7 +118,7 @@ public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> {
lastLimitSnooze = SNOOZE_NEVER;
}
- /** {@inheritDoc} */
+ @Override
public int compareTo(NetworkPolicy another) {
if (another == null || another.limitBytes == LIMIT_DISABLED) {
// other value is missing or disabled; we win
@@ -127,8 +133,8 @@ public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> {
@Override
public int hashCode() {
- return Objects.hashCode(template, cycleDay, warningBytes, limitBytes, lastWarningSnooze,
- lastLimitSnooze, metered);
+ return Objects.hashCode(template, cycleDay, cycleTimezone, warningBytes, limitBytes,
+ lastWarningSnooze, lastLimitSnooze, metered);
}
@Override
@@ -139,6 +145,7 @@ public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> {
&& limitBytes == other.limitBytes
&& lastWarningSnooze == other.lastWarningSnooze
&& lastLimitSnooze == other.lastLimitSnooze && metered == other.metered
+ && Objects.equal(cycleTimezone, other.cycleTimezone)
&& Objects.equal(template, other.template);
}
return false;
@@ -146,17 +153,19 @@ public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> {
@Override
public String toString() {
- return "NetworkPolicy[" + template + "]: cycleDay=" + cycleDay + ", warningBytes="
- + warningBytes + ", limitBytes=" + limitBytes + ", lastWarningSnooze="
- + lastWarningSnooze + ", lastLimitSnooze=" + lastLimitSnooze + ", metered="
- + metered;
+ return "NetworkPolicy[" + template + "]: cycleDay=" + cycleDay + ", cycleTimezone="
+ + cycleTimezone + ", warningBytes=" + warningBytes + ", limitBytes=" + limitBytes
+ + ", lastWarningSnooze=" + lastWarningSnooze + ", lastLimitSnooze="
+ + lastLimitSnooze + ", metered=" + metered;
}
public static final Creator<NetworkPolicy> CREATOR = new Creator<NetworkPolicy>() {
+ @Override
public NetworkPolicy createFromParcel(Parcel in) {
return new NetworkPolicy(in);
}
+ @Override
public NetworkPolicy[] newArray(int size) {
return new NetworkPolicy[size];
}
diff --git a/core/java/android/net/NetworkPolicyManager.java b/core/java/android/net/NetworkPolicyManager.java
index 9d253c7..7173751 100644
--- a/core/java/android/net/NetworkPolicyManager.java
+++ b/core/java/android/net/NetworkPolicyManager.java
@@ -131,7 +131,7 @@ public class NetworkPolicyManager {
* @hide
*/
public static long computeLastCycleBoundary(long currentTime, NetworkPolicy policy) {
- final Time now = new Time(Time.TIMEZONE_UTC);
+ final Time now = new Time(policy.cycleTimezone);
now.set(currentTime);
// first, find cycle boundary for current month
@@ -157,7 +157,7 @@ public class NetworkPolicyManager {
/** {@hide} */
public static long computeNextCycleBoundary(long currentTime, NetworkPolicy policy) {
- final Time now = new Time(Time.TIMEZONE_UTC);
+ final Time now = new Time(policy.cycleTimezone);
now.set(currentTime);
// first, find cycle boundary for current month
@@ -183,7 +183,7 @@ public class NetworkPolicyManager {
/**
* Snap to the cycle day for the current month given; when cycle day doesn't
- * exist, it snaps to 1st of following month.
+ * exist, it snaps to last second of current month.
*
* @hide
*/