summaryrefslogtreecommitdiffstats
path: root/services
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 /services
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 'services')
-rw-r--r--services/java/com/android/server/net/NetworkPolicyManagerService.java23
-rw-r--r--services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java63
2 files changed, 69 insertions, 17 deletions
diff --git a/services/java/com/android/server/net/NetworkPolicyManagerService.java b/services/java/com/android/server/net/NetworkPolicyManagerService.java
index a890068..2ad24e2 100644
--- a/services/java/com/android/server/net/NetworkPolicyManagerService.java
+++ b/services/java/com/android/server/net/NetworkPolicyManagerService.java
@@ -156,6 +156,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
private static final int VERSION_ADDED_RESTRICT_BACKGROUND = 3;
private static final int VERSION_ADDED_METERED = 4;
private static final int VERSION_SPLIT_SNOOZE = 5;
+ private static final int VERSION_ADDED_TIMEZONE = 6;
// @VisibleForTesting
public static final int TYPE_WARNING = 0x1;
@@ -171,6 +172,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
private static final String ATTR_NETWORK_TEMPLATE = "networkTemplate";
private static final String ATTR_SUBSCRIBER_ID = "subscriberId";
private static final String ATTR_CYCLE_DAY = "cycleDay";
+ private static final String ATTR_CYCLE_TIMEZONE = "cycleTimezone";
private static final String ATTR_WARNING_BYTES = "warningBytes";
private static final String ATTR_LIMIT_BYTES = "limitBytes";
private static final String ATTR_LAST_SNOOZE = "lastSnooze";
@@ -922,13 +924,15 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
com.android.internal.R.integer.config_networkPolicyDefaultWarning)
* MB_IN_BYTES;
- final Time time = new Time(Time.TIMEZONE_UTC);
+ final Time time = new Time();
time.setToNow();
+
final int cycleDay = time.monthDay;
+ final String cycleTimezone = time.timezone;
final NetworkTemplate template = buildTemplateMobileAll(subscriberId);
- mNetworkPolicy.put(template, new NetworkPolicy(template, cycleDay, warningBytes,
- LIMIT_DISABLED, SNOOZE_NEVER, SNOOZE_NEVER, true));
+ mNetworkPolicy.put(template, new NetworkPolicy(template, cycleDay, cycleTimezone,
+ warningBytes, LIMIT_DISABLED, SNOOZE_NEVER, SNOOZE_NEVER, true));
writePolicyLocked();
}
}
@@ -964,6 +968,12 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
final int networkTemplate = readIntAttribute(in, ATTR_NETWORK_TEMPLATE);
final String subscriberId = in.getAttributeValue(null, ATTR_SUBSCRIBER_ID);
final int cycleDay = readIntAttribute(in, ATTR_CYCLE_DAY);
+ final String cycleTimezone;
+ if (version >= VERSION_ADDED_TIMEZONE) {
+ cycleTimezone = in.getAttributeValue(null, ATTR_CYCLE_TIMEZONE);
+ } else {
+ cycleTimezone = Time.TIMEZONE_UTC;
+ }
final long warningBytes = readLongAttribute(in, ATTR_WARNING_BYTES);
final long limitBytes = readLongAttribute(in, ATTR_LIMIT_BYTES);
final long lastLimitSnooze;
@@ -998,8 +1008,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
final NetworkTemplate template = new NetworkTemplate(
networkTemplate, subscriberId);
mNetworkPolicy.put(template, new NetworkPolicy(template, cycleDay,
- warningBytes, limitBytes, lastWarningSnooze, lastLimitSnooze,
- metered));
+ cycleTimezone, warningBytes, limitBytes, lastWarningSnooze,
+ lastLimitSnooze, metered));
} else if (TAG_UID_POLICY.equals(tag)) {
final int uid = readIntAttribute(in, ATTR_UID);
@@ -1054,7 +1064,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
out.startDocument(null, true);
out.startTag(null, TAG_POLICY_LIST);
- writeIntAttribute(out, ATTR_VERSION, VERSION_SPLIT_SNOOZE);
+ writeIntAttribute(out, ATTR_VERSION, VERSION_ADDED_TIMEZONE);
writeBooleanAttribute(out, ATTR_RESTRICT_BACKGROUND, mRestrictBackground);
// write all known network policies
@@ -1068,6 +1078,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
out.attribute(null, ATTR_SUBSCRIBER_ID, subscriberId);
}
writeIntAttribute(out, ATTR_CYCLE_DAY, policy.cycleDay);
+ out.attribute(null, ATTR_CYCLE_TIMEZONE, policy.cycleTimezone);
writeLongAttribute(out, ATTR_WARNING_BYTES, policy.warningBytes);
writeLongAttribute(out, ATTR_LIMIT_BYTES, policy.limitBytes);
writeLongAttribute(out, ATTR_LAST_WARNING_SNOOZE, policy.lastWarningSnooze);
diff --git a/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java
index e863f8b..b4fd55e 100644
--- a/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java
@@ -32,6 +32,7 @@ import static android.net.TrafficStats.KB_IN_BYTES;
import static android.net.TrafficStats.MB_IN_BYTES;
import static android.text.format.DateUtils.DAY_IN_MILLIS;
import static android.text.format.DateUtils.MINUTE_IN_MILLIS;
+import static android.text.format.Time.TIMEZONE_UTC;
import static com.android.server.net.NetworkPolicyManagerService.TYPE_LIMIT;
import static com.android.server.net.NetworkPolicyManagerService.TYPE_LIMIT_SNOOZED;
import static com.android.server.net.NetworkPolicyManagerService.TYPE_WARNING;
@@ -439,7 +440,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
final long expectedCycle = parseTime("2007-11-05T00:00:00.000Z");
final NetworkPolicy policy = new NetworkPolicy(
- sTemplateWifi, 5, 1024L, 1024L, false);
+ sTemplateWifi, 5, TIMEZONE_UTC, 1024L, 1024L, false);
final long actualCycle = computeLastCycleBoundary(currentTime, policy);
assertTimeEquals(expectedCycle, actualCycle);
}
@@ -450,7 +451,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
final long expectedCycle = parseTime("2007-10-20T00:00:00.000Z");
final NetworkPolicy policy = new NetworkPolicy(
- sTemplateWifi, 20, 1024L, 1024L, false);
+ sTemplateWifi, 20, TIMEZONE_UTC, 1024L, 1024L, false);
final long actualCycle = computeLastCycleBoundary(currentTime, policy);
assertTimeEquals(expectedCycle, actualCycle);
}
@@ -461,7 +462,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
final long expectedCycle = parseTime("2007-01-30T00:00:00.000Z");
final NetworkPolicy policy = new NetworkPolicy(
- sTemplateWifi, 30, 1024L, 1024L, false);
+ sTemplateWifi, 30, TIMEZONE_UTC, 1024L, 1024L, false);
final long actualCycle = computeLastCycleBoundary(currentTime, policy);
assertTimeEquals(expectedCycle, actualCycle);
}
@@ -472,14 +473,53 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
final long expectedCycle = parseTime("2007-02-28T23:59:59.000Z");
final NetworkPolicy policy = new NetworkPolicy(
- sTemplateWifi, 30, 1024L, 1024L, false);
+ sTemplateWifi, 30, TIMEZONE_UTC, 1024L, 1024L, false);
final long actualCycle = computeLastCycleBoundary(currentTime, policy);
assertTimeEquals(expectedCycle, actualCycle);
}
+ public void testCycleBoundaryLeapYear() throws Exception {
+ final NetworkPolicy policy = new NetworkPolicy(
+ sTemplateWifi, 29, TIMEZONE_UTC, 1024L, 1024L, false);
+
+ assertTimeEquals(parseTime("2012-01-29T00:00:00.000Z"),
+ computeNextCycleBoundary(parseTime("2012-01-14T00:00:00.000Z"), policy));
+ assertTimeEquals(parseTime("2012-02-29T00:00:00.000Z"),
+ computeNextCycleBoundary(parseTime("2012-02-14T00:00:00.000Z"), policy));
+ assertTimeEquals(parseTime("2012-02-29T00:00:00.000Z"),
+ computeLastCycleBoundary(parseTime("2012-03-14T00:00:00.000Z"), policy));
+ assertTimeEquals(parseTime("2012-03-29T00:00:00.000Z"),
+ computeNextCycleBoundary(parseTime("2012-03-14T00:00:00.000Z"), policy));
+
+ assertTimeEquals(parseTime("2007-01-29T00:00:00.000Z"),
+ computeNextCycleBoundary(parseTime("2007-01-14T00:00:00.000Z"), policy));
+ assertTimeEquals(parseTime("2007-02-28T23:59:59.000Z"),
+ computeNextCycleBoundary(parseTime("2007-02-14T00:00:00.000Z"), policy));
+ assertTimeEquals(parseTime("2007-02-28T23:59:59.000Z"),
+ computeLastCycleBoundary(parseTime("2007-03-14T00:00:00.000Z"), policy));
+ assertTimeEquals(parseTime("2007-03-29T00:00:00.000Z"),
+ computeNextCycleBoundary(parseTime("2007-03-14T00:00:00.000Z"), policy));
+ }
+
+ public void testNextCycleTimezoneAfterUtc() throws Exception {
+ // US/Central is UTC-6
+ final NetworkPolicy policy = new NetworkPolicy(
+ sTemplateWifi, 10, "US/Central", 1024L, 1024L, false);
+ assertTimeEquals(parseTime("2012-01-10T06:00:00.000Z"),
+ computeNextCycleBoundary(parseTime("2012-01-05T00:00:00.000Z"), policy));
+ }
+
+ public void testNextCycleTimezoneBeforeUtc() throws Exception {
+ // Israel is UTC+2
+ final NetworkPolicy policy = new NetworkPolicy(
+ sTemplateWifi, 10, "Israel", 1024L, 1024L, false);
+ assertTimeEquals(parseTime("2012-01-09T22:00:00.000Z"),
+ computeNextCycleBoundary(parseTime("2012-01-05T00:00:00.000Z"), policy));
+ }
+
public void testNextCycleSane() throws Exception {
final NetworkPolicy policy = new NetworkPolicy(
- sTemplateWifi, 31, WARNING_DISABLED, LIMIT_DISABLED, false);
+ sTemplateWifi, 31, TIMEZONE_UTC, WARNING_DISABLED, LIMIT_DISABLED, false);
final LinkedHashSet<Long> seen = new LinkedHashSet<Long>();
// walk forwards, ensuring that cycle boundaries don't get stuck
@@ -494,7 +534,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
public void testLastCycleSane() throws Exception {
final NetworkPolicy policy = new NetworkPolicy(
- sTemplateWifi, 31, WARNING_DISABLED, LIMIT_DISABLED, false);
+ sTemplateWifi, 31, TIMEZONE_UTC, WARNING_DISABLED, LIMIT_DISABLED, false);
final LinkedHashSet<Long> seen = new LinkedHashSet<Long>();
// walk backwards, ensuring that cycle boundaries look sane
@@ -552,7 +592,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
replay();
setNetworkPolicies(new NetworkPolicy(
- sTemplateWifi, CYCLE_DAY, 1 * MB_IN_BYTES, 2 * MB_IN_BYTES, false));
+ sTemplateWifi, CYCLE_DAY, TIMEZONE_UTC, 1 * MB_IN_BYTES, 2 * MB_IN_BYTES, false));
future.get();
verifyAndReset();
}
@@ -609,8 +649,8 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
future = expectMeteredIfacesChanged();
replay();
- setNetworkPolicies(new NetworkPolicy(sTemplateWifi, CYCLE_DAY, 1 * MB_IN_BYTES,
- 2 * MB_IN_BYTES, false));
+ setNetworkPolicies(new NetworkPolicy(sTemplateWifi, CYCLE_DAY, TIMEZONE_UTC, 1
+ * MB_IN_BYTES, 2 * MB_IN_BYTES, false));
future.get();
verifyAndReset();
}
@@ -740,8 +780,9 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
future = expectMeteredIfacesChanged(TEST_IFACE);
replay();
- setNetworkPolicies(new NetworkPolicy(sTemplateWifi, CYCLE_DAY, WARNING_DISABLED,
- LIMIT_DISABLED, true));
+ setNetworkPolicies(new NetworkPolicy(
+ sTemplateWifi, CYCLE_DAY, TIMEZONE_UTC, WARNING_DISABLED, LIMIT_DISABLED,
+ true));
future.get();
verifyAndReset();
}