am d968670d: Merge "Conservatively trim data usage stats." into ics-mr1
* commit 'd968670d8369e5d92ba9b7a45b3804d692a05a4e': Conservatively trim data usage stats.
This commit is contained in:
@@ -256,6 +256,10 @@ public class NetworkStatsHistoryTest extends AndroidTestCase {
|
|||||||
stats.recordData(TEST_START, TEST_START + DAY_IN_MILLIS, 24L, 24L);
|
stats.recordData(TEST_START, TEST_START + DAY_IN_MILLIS, 24L, 24L);
|
||||||
assertEquals(24, stats.size());
|
assertEquals(24, stats.size());
|
||||||
|
|
||||||
|
// try removing invalid data; should be no change
|
||||||
|
stats.removeBucketsBefore(0 - DAY_IN_MILLIS);
|
||||||
|
assertEquals(24, stats.size());
|
||||||
|
|
||||||
// try removing far before buckets; should be no change
|
// try removing far before buckets; should be no change
|
||||||
stats.removeBucketsBefore(TEST_START - YEAR_IN_MILLIS);
|
stats.removeBucketsBefore(TEST_START - YEAR_IN_MILLIS);
|
||||||
assertEquals(24, stats.size());
|
assertEquals(24, stats.size());
|
||||||
|
|||||||
@@ -1243,7 +1243,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
|
|
||||||
// trim any history beyond max
|
// trim any history beyond max
|
||||||
if (mTime.hasCache()) {
|
if (mTime.hasCache()) {
|
||||||
final long currentTime = mTime.currentTimeMillis();
|
final long currentTime = Math.min(
|
||||||
|
System.currentTimeMillis(), mTime.currentTimeMillis());
|
||||||
final long maxHistory = mSettings.getNetworkMaxHistory();
|
final long maxHistory = mSettings.getNetworkMaxHistory();
|
||||||
for (NetworkStatsHistory history : input.values()) {
|
for (NetworkStatsHistory history : input.values()) {
|
||||||
history.removeBucketsBefore(currentTime - maxHistory);
|
history.removeBucketsBefore(currentTime - maxHistory);
|
||||||
@@ -1287,7 +1288,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
|
|
||||||
// trim any history beyond max
|
// trim any history beyond max
|
||||||
if (mTime.hasCache()) {
|
if (mTime.hasCache()) {
|
||||||
final long currentTime = mTime.currentTimeMillis();
|
final long currentTime = Math.min(
|
||||||
|
System.currentTimeMillis(), mTime.currentTimeMillis());
|
||||||
final long maxUidHistory = mSettings.getUidMaxHistory();
|
final long maxUidHistory = mSettings.getUidMaxHistory();
|
||||||
final long maxTagHistory = mSettings.getTagMaxHistory();
|
final long maxTagHistory = mSettings.getTagMaxHistory();
|
||||||
for (UidStatsKey key : mUidStats.keySet()) {
|
for (UidStatsKey key : mUidStats.keySet()) {
|
||||||
|
|||||||
@@ -80,7 +80,6 @@ import com.google.common.util.concurrent.AbstractFuture;
|
|||||||
import org.easymock.Capture;
|
import org.easymock.Capture;
|
||||||
import org.easymock.EasyMock;
|
import org.easymock.EasyMock;
|
||||||
import org.easymock.IAnswer;
|
import org.easymock.IAnswer;
|
||||||
import org.easymock.IExpectationSetters;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
@@ -537,6 +536,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
|
|||||||
.addIfaceValues(TEST_IFACE, 256L, 2L, 256L, 2L);
|
.addIfaceValues(TEST_IFACE, 256L, 2L, 256L, 2L);
|
||||||
expect(mStatsService.getSummaryForNetwork(sTemplateWifi, TIME_FEB_15, TIME_MAR_10))
|
expect(mStatsService.getSummaryForNetwork(sTemplateWifi, TIME_FEB_15, TIME_MAR_10))
|
||||||
.andReturn(stats).atLeastOnce();
|
.andReturn(stats).atLeastOnce();
|
||||||
|
expectPolicyDataEnable(TYPE_WIFI, true);
|
||||||
|
|
||||||
// TODO: consider making strongly ordered mock
|
// TODO: consider making strongly ordered mock
|
||||||
expectRemoveInterfaceQuota(TEST_IFACE);
|
expectRemoveInterfaceQuota(TEST_IFACE);
|
||||||
@@ -580,7 +580,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
|
|||||||
NetworkState[] state = null;
|
NetworkState[] state = null;
|
||||||
NetworkStats stats = null;
|
NetworkStats stats = null;
|
||||||
Future<Void> future;
|
Future<Void> future;
|
||||||
Capture<String> tag;
|
Future<String> tagFuture;
|
||||||
|
|
||||||
final long TIME_FEB_15 = 1171497600000L;
|
final long TIME_FEB_15 = 1171497600000L;
|
||||||
final long TIME_MAR_10 = 1173484800000L;
|
final long TIME_MAR_10 = 1173484800000L;
|
||||||
@@ -598,6 +598,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
|
|||||||
expect(mConnManager.getAllNetworkState()).andReturn(state).atLeastOnce();
|
expect(mConnManager.getAllNetworkState()).andReturn(state).atLeastOnce();
|
||||||
expect(mStatsService.getSummaryForNetwork(sTemplateWifi, TIME_FEB_15, currentTimeMillis()))
|
expect(mStatsService.getSummaryForNetwork(sTemplateWifi, TIME_FEB_15, currentTimeMillis()))
|
||||||
.andReturn(stats).atLeastOnce();
|
.andReturn(stats).atLeastOnce();
|
||||||
|
expectPolicyDataEnable(TYPE_WIFI, true);
|
||||||
|
|
||||||
expectClearNotifications();
|
expectClearNotifications();
|
||||||
future = expectMeteredIfacesChanged();
|
future = expectMeteredIfacesChanged();
|
||||||
@@ -620,6 +621,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
|
|||||||
expect(mConnManager.getAllNetworkState()).andReturn(state).atLeastOnce();
|
expect(mConnManager.getAllNetworkState()).andReturn(state).atLeastOnce();
|
||||||
expect(mStatsService.getSummaryForNetwork(sTemplateWifi, TIME_FEB_15, currentTimeMillis()))
|
expect(mStatsService.getSummaryForNetwork(sTemplateWifi, TIME_FEB_15, currentTimeMillis()))
|
||||||
.andReturn(stats).atLeastOnce();
|
.andReturn(stats).atLeastOnce();
|
||||||
|
expectPolicyDataEnable(TYPE_WIFI, true);
|
||||||
|
|
||||||
expectRemoveInterfaceQuota(TEST_IFACE);
|
expectRemoveInterfaceQuota(TEST_IFACE);
|
||||||
expectSetInterfaceQuota(TEST_IFACE, 2 * MB_IN_BYTES);
|
expectSetInterfaceQuota(TEST_IFACE, 2 * MB_IN_BYTES);
|
||||||
@@ -642,14 +644,15 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
|
|||||||
expectCurrentTime();
|
expectCurrentTime();
|
||||||
expect(mStatsService.getSummaryForNetwork(sTemplateWifi, TIME_FEB_15, currentTimeMillis()))
|
expect(mStatsService.getSummaryForNetwork(sTemplateWifi, TIME_FEB_15, currentTimeMillis()))
|
||||||
.andReturn(stats).atLeastOnce();
|
.andReturn(stats).atLeastOnce();
|
||||||
|
expectPolicyDataEnable(TYPE_WIFI, true);
|
||||||
|
|
||||||
expectForceUpdate();
|
expectForceUpdate();
|
||||||
expectClearNotifications();
|
expectClearNotifications();
|
||||||
tag = expectEnqueueNotification();
|
tagFuture = expectEnqueueNotification();
|
||||||
|
|
||||||
replay();
|
replay();
|
||||||
mNetworkObserver.limitReached(null, TEST_IFACE);
|
mNetworkObserver.limitReached(null, TEST_IFACE);
|
||||||
assertNotificationType(TYPE_WARNING, tag.getValue());
|
assertNotificationType(TYPE_WARNING, tagFuture.get());
|
||||||
verifyAndReset();
|
verifyAndReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -662,15 +665,15 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
|
|||||||
expectCurrentTime();
|
expectCurrentTime();
|
||||||
expect(mStatsService.getSummaryForNetwork(sTemplateWifi, TIME_FEB_15, currentTimeMillis()))
|
expect(mStatsService.getSummaryForNetwork(sTemplateWifi, TIME_FEB_15, currentTimeMillis()))
|
||||||
.andReturn(stats).atLeastOnce();
|
.andReturn(stats).atLeastOnce();
|
||||||
expectPolicyDataEnable(TYPE_WIFI, false).atLeastOnce();
|
expectPolicyDataEnable(TYPE_WIFI, false);
|
||||||
|
|
||||||
expectForceUpdate();
|
expectForceUpdate();
|
||||||
expectClearNotifications();
|
expectClearNotifications();
|
||||||
tag = expectEnqueueNotification();
|
tagFuture = expectEnqueueNotification();
|
||||||
|
|
||||||
replay();
|
replay();
|
||||||
mNetworkObserver.limitReached(null, TEST_IFACE);
|
mNetworkObserver.limitReached(null, TEST_IFACE);
|
||||||
assertNotificationType(TYPE_LIMIT, tag.getValue());
|
assertNotificationType(TYPE_LIMIT, tagFuture.get());
|
||||||
verifyAndReset();
|
verifyAndReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -682,21 +685,20 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
|
|||||||
expect(mConnManager.getAllNetworkState()).andReturn(state).atLeastOnce();
|
expect(mConnManager.getAllNetworkState()).andReturn(state).atLeastOnce();
|
||||||
expect(mStatsService.getSummaryForNetwork(sTemplateWifi, TIME_FEB_15, currentTimeMillis()))
|
expect(mStatsService.getSummaryForNetwork(sTemplateWifi, TIME_FEB_15, currentTimeMillis()))
|
||||||
.andReturn(stats).atLeastOnce();
|
.andReturn(stats).atLeastOnce();
|
||||||
expectPolicyDataEnable(TYPE_WIFI, true).atLeastOnce();
|
expectPolicyDataEnable(TYPE_WIFI, true);
|
||||||
|
|
||||||
// snoozed interface still has high quota so background data is
|
// snoozed interface still has high quota so background data is
|
||||||
// still restricted.
|
// still restricted.
|
||||||
expectRemoveInterfaceQuota(TEST_IFACE);
|
expectRemoveInterfaceQuota(TEST_IFACE);
|
||||||
expectSetInterfaceQuota(TEST_IFACE, Long.MAX_VALUE);
|
expectSetInterfaceQuota(TEST_IFACE, Long.MAX_VALUE);
|
||||||
|
expectMeteredIfacesChanged(TEST_IFACE);
|
||||||
|
|
||||||
expectClearNotifications();
|
expectClearNotifications();
|
||||||
tag = expectEnqueueNotification();
|
tagFuture = expectEnqueueNotification();
|
||||||
future = expectMeteredIfacesChanged(TEST_IFACE);
|
|
||||||
|
|
||||||
replay();
|
replay();
|
||||||
mService.snoozePolicy(sTemplateWifi);
|
mService.snoozePolicy(sTemplateWifi);
|
||||||
future.get();
|
assertNotificationType(TYPE_LIMIT_SNOOZED, tagFuture.get());
|
||||||
assertNotificationType(TYPE_LIMIT_SNOOZED, tag.getValue());
|
|
||||||
verifyAndReset();
|
verifyAndReset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -737,9 +739,9 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
|
|||||||
expectLastCall().anyTimes();
|
expectLastCall().anyTimes();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Capture<String> expectEnqueueNotification() throws Exception {
|
private Future<String> expectEnqueueNotification() throws Exception {
|
||||||
final Capture<String> tag = new Capture<String>();
|
final FutureCapture<String> tag = new FutureCapture<String>();
|
||||||
mNotifManager.enqueueNotificationWithTag(isA(String.class), capture(tag), anyInt(),
|
mNotifManager.enqueueNotificationWithTag(isA(String.class), capture(tag.capture), anyInt(),
|
||||||
isA(Notification.class), isA(int[].class));
|
isA(Notification.class), isA(int[].class));
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
@@ -789,22 +791,25 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
|
|||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T> IExpectationSetters<T> expectPolicyDataEnable(int type, boolean enabled)
|
private Future<Void> expectPolicyDataEnable(int type, boolean enabled) throws Exception {
|
||||||
throws Exception {
|
final FutureAnswer future = new FutureAnswer();
|
||||||
mConnManager.setPolicyDataEnable(type, enabled);
|
mConnManager.setPolicyDataEnable(type, enabled);
|
||||||
return expectLastCall();
|
expectLastCall().andAnswer(future);
|
||||||
|
return future;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class FutureAnswer extends AbstractFuture<Void> implements IAnswer<Void> {
|
private static class TestAbstractFuture<T> extends AbstractFuture<T> {
|
||||||
@Override
|
@Override
|
||||||
public Void get() throws InterruptedException, ExecutionException {
|
public T get() throws InterruptedException, ExecutionException {
|
||||||
try {
|
try {
|
||||||
return get(5, TimeUnit.SECONDS);
|
return get(5, TimeUnit.SECONDS);
|
||||||
} catch (TimeoutException e) {
|
} catch (TimeoutException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class FutureAnswer extends TestAbstractFuture<Void> implements IAnswer<Void> {
|
||||||
@Override
|
@Override
|
||||||
public Void answer() {
|
public Void answer() {
|
||||||
set(null);
|
set(null);
|
||||||
@@ -812,6 +817,16 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class FutureCapture<T> extends TestAbstractFuture<T> {
|
||||||
|
public Capture<T> capture = new Capture<T>() {
|
||||||
|
@Override
|
||||||
|
public void setValue(T value) {
|
||||||
|
super.setValue(value);
|
||||||
|
set(value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private static class IdleFuture extends AbstractFuture<Void> implements IdleHandler {
|
private static class IdleFuture extends AbstractFuture<Void> implements IdleHandler {
|
||||||
@Override
|
@Override
|
||||||
public Void get() throws InterruptedException, ExecutionException {
|
public Void get() throws InterruptedException, ExecutionException {
|
||||||
|
|||||||
Reference in New Issue
Block a user