use of android.net.NetworkPolicy in project android_frameworks_base by ResurrectionRemix.
the class NetworkPolicyManagerServiceTest method testLastCycleBoundaryLastMonth.
public void testLastCycleBoundaryLastMonth() throws Exception {
// assume cycle day of "20th", which should be in last month
final long currentTime = parseTime("2007-11-14T00:00:00.000Z");
final long expectedCycle = parseTime("2007-10-20T00:00:00.000Z");
final NetworkPolicy policy = new NetworkPolicy(sTemplateWifi, 20, TIMEZONE_UTC, 1024L, 1024L, false);
final long actualCycle = computeLastCycleBoundary(currentTime, policy);
assertTimeEquals(expectedCycle, actualCycle);
}
use of android.net.NetworkPolicy in project android_frameworks_base by ResurrectionRemix.
the class NetworkPolicyManagerServiceTest method testLastCycleBoundaryThisMonth.
public void testLastCycleBoundaryThisMonth() throws Exception {
// assume cycle day of "5th", which should be in same month
final long currentTime = parseTime("2007-11-14T00:00:00.000Z");
final long expectedCycle = parseTime("2007-11-05T00:00:00.000Z");
final NetworkPolicy policy = new NetworkPolicy(sTemplateWifi, 5, TIMEZONE_UTC, 1024L, 1024L, false);
final long actualCycle = computeLastCycleBoundary(currentTime, policy);
assertTimeEquals(expectedCycle, actualCycle);
}
use of android.net.NetworkPolicy in project android_frameworks_base by ResurrectionRemix.
the class NetworkPolicyManagerServiceTest method testOverWarningLimitNotification.
@Suppress
public void testOverWarningLimitNotification() throws Exception {
NetworkState[] state = null;
NetworkStats stats = null;
Future<Void> future;
Future<String> tagFuture;
final long TIME_FEB_15 = 1171497600000L;
final long TIME_MAR_10 = 1173484800000L;
final int CYCLE_DAY = 15;
setCurrentTimeMillis(TIME_MAR_10);
// assign wifi policy
state = new NetworkState[] {};
stats = new NetworkStats(getElapsedRealtime(), 1).addIfaceValues(TEST_IFACE, 0L, 0L, 0L, 0L);
{
expectCurrentTime();
expect(mConnManager.getAllNetworkState()).andReturn(state).atLeastOnce();
expect(mStatsService.getNetworkTotalBytes(sTemplateWifi, TIME_FEB_15, currentTimeMillis())).andReturn(stats.getTotalBytes()).atLeastOnce();
expectPolicyDataEnable(TYPE_WIFI, true);
expectClearNotifications();
expectAdvisePersistThreshold();
future = expectMeteredIfacesChanged();
replay();
setNetworkPolicies(new NetworkPolicy(sTemplateWifi, CYCLE_DAY, TIMEZONE_UTC, 1 * MB_IN_BYTES, 2 * MB_IN_BYTES, false));
future.get();
verifyAndReset();
}
// bring up wifi network
incrementCurrentTime(MINUTE_IN_MILLIS);
state = new NetworkState[] { buildWifi() };
stats = new NetworkStats(getElapsedRealtime(), 1).addIfaceValues(TEST_IFACE, 0L, 0L, 0L, 0L);
{
expectCurrentTime();
expect(mConnManager.getAllNetworkState()).andReturn(state).atLeastOnce();
expect(mStatsService.getNetworkTotalBytes(sTemplateWifi, TIME_FEB_15, currentTimeMillis())).andReturn(stats.getTotalBytes()).atLeastOnce();
expectPolicyDataEnable(TYPE_WIFI, true);
expectRemoveInterfaceQuota(TEST_IFACE);
expectSetInterfaceQuota(TEST_IFACE, 2 * MB_IN_BYTES);
expectClearNotifications();
expectAdvisePersistThreshold();
future = expectMeteredIfacesChanged(TEST_IFACE);
replay();
mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION));
future.get();
verifyAndReset();
}
// go over warning, which should kick notification
incrementCurrentTime(MINUTE_IN_MILLIS);
stats = new NetworkStats(getElapsedRealtime(), 1).addIfaceValues(TEST_IFACE, 1536 * KB_IN_BYTES, 15L, 0L, 0L);
{
expectCurrentTime();
expect(mStatsService.getNetworkTotalBytes(sTemplateWifi, TIME_FEB_15, currentTimeMillis())).andReturn(stats.getTotalBytes()).atLeastOnce();
expectPolicyDataEnable(TYPE_WIFI, true);
expectForceUpdate();
expectClearNotifications();
tagFuture = expectEnqueueNotification();
replay();
mNetworkObserver.limitReached(null, TEST_IFACE);
assertNotificationType(TYPE_WARNING, tagFuture.get());
verifyAndReset();
}
// go over limit, which should kick notification and dialog
incrementCurrentTime(MINUTE_IN_MILLIS);
stats = new NetworkStats(getElapsedRealtime(), 1).addIfaceValues(TEST_IFACE, 5 * MB_IN_BYTES, 512L, 0L, 0L);
{
expectCurrentTime();
expect(mStatsService.getNetworkTotalBytes(sTemplateWifi, TIME_FEB_15, currentTimeMillis())).andReturn(stats.getTotalBytes()).atLeastOnce();
expectPolicyDataEnable(TYPE_WIFI, false);
expectForceUpdate();
expectClearNotifications();
tagFuture = expectEnqueueNotification();
replay();
mNetworkObserver.limitReached(null, TEST_IFACE);
assertNotificationType(TYPE_LIMIT, tagFuture.get());
verifyAndReset();
}
// now snooze policy, which should remove quota
incrementCurrentTime(MINUTE_IN_MILLIS);
{
expectCurrentTime();
expect(mConnManager.getAllNetworkState()).andReturn(state).atLeastOnce();
expect(mStatsService.getNetworkTotalBytes(sTemplateWifi, TIME_FEB_15, currentTimeMillis())).andReturn(stats.getTotalBytes()).atLeastOnce();
expectPolicyDataEnable(TYPE_WIFI, true);
// snoozed interface still has high quota so background data is
// still restricted.
expectRemoveInterfaceQuota(TEST_IFACE);
expectSetInterfaceQuota(TEST_IFACE, Long.MAX_VALUE);
expectAdvisePersistThreshold();
expectMeteredIfacesChanged(TEST_IFACE);
future = expectClearNotifications();
tagFuture = expectEnqueueNotification();
replay();
mService.snoozeLimit(sTemplateWifi);
assertNotificationType(TYPE_LIMIT_SNOOZED, tagFuture.get());
future.get();
verifyAndReset();
}
}
use of android.net.NetworkPolicy in project android_frameworks_base by ResurrectionRemix.
the class NetworkPolicyManagerServiceTest method testLastCycleBoundaryLastMonthFebruary.
public void testLastCycleBoundaryLastMonthFebruary() throws Exception {
// assume cycle day of "30th" in february, which should clamp
final long currentTime = parseTime("2007-03-14T00:00:00.000Z");
final long expectedCycle = parseTime("2007-02-28T23:59:59.000Z");
final NetworkPolicy policy = new NetworkPolicy(sTemplateWifi, 30, TIMEZONE_UTC, 1024L, 1024L, false);
final long actualCycle = computeLastCycleBoundary(currentTime, policy);
assertTimeEquals(expectedCycle, actualCycle);
}
use of android.net.NetworkPolicy in project android_frameworks_base by ResurrectionRemix.
the class NetworkPolicyManagerServiceTest method testLastCycleBoundaryThisMonthFebruary.
public void testLastCycleBoundaryThisMonthFebruary() throws Exception {
// assume cycle day of "30th" in february; should go to january
final long currentTime = parseTime("2007-02-14T00:00:00.000Z");
final long expectedCycle = parseTime("2007-01-30T00:00:00.000Z");
final NetworkPolicy policy = new NetworkPolicy(sTemplateWifi, 30, TIMEZONE_UTC, 1024L, 1024L, false);
final long actualCycle = computeLastCycleBoundary(currentTime, policy);
assertTimeEquals(expectedCycle, actualCycle);
}
Aggregations