Refactored NetworkStatsServiceTest to use Mockito instead of EasyMock.
Test: m -j32 FrameworksServicesTests && adb install -r -g ${ANDROID_PRODUCT_OUT}/data/app/FrameworksServicesTests/FrameworksServicesTests.apk && adb shell am instrument -e class "com.android.server.net.NetworkStatsServiceTest" -w "com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner"
BUG: 30943463
(cherry picked from commit de2a6f1b1d)
Change-Id: Ia9929295ab2396a7ebb133e65d157f98414e4dfa
This commit is contained in:
committed by
Lorenzo Colitti
parent
ab6ab9bd36
commit
d67fae88b6
@@ -43,18 +43,16 @@ import static android.text.format.DateUtils.WEEK_IN_MILLIS;
|
|||||||
|
|
||||||
import static com.android.server.net.NetworkStatsService.ACTION_NETWORK_STATS_POLL;
|
import static com.android.server.net.NetworkStatsService.ACTION_NETWORK_STATS_POLL;
|
||||||
|
|
||||||
import static org.easymock.EasyMock.anyInt;
|
|
||||||
import static org.easymock.EasyMock.anyLong;
|
|
||||||
import static org.easymock.EasyMock.anyObject;
|
|
||||||
import static org.easymock.EasyMock.capture;
|
|
||||||
import static org.easymock.EasyMock.createMock;
|
|
||||||
import static org.easymock.EasyMock.eq;
|
|
||||||
import static org.easymock.EasyMock.expect;
|
|
||||||
import static org.easymock.EasyMock.expectLastCall;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
import static org.mockito.Matchers.any;
|
||||||
|
import static org.mockito.Matchers.anyInt;
|
||||||
|
import static org.mockito.Matchers.anyLong;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import android.app.AlarmManager;
|
import android.app.AlarmManager;
|
||||||
import android.app.usage.NetworkStatsManager;
|
import android.app.usage.NetworkStatsManager;
|
||||||
@@ -97,13 +95,14 @@ import com.android.server.net.NetworkStatsService.NetworkStatsSettings.Config;
|
|||||||
|
|
||||||
import libcore.io.IoUtils;
|
import libcore.io.IoUtils;
|
||||||
|
|
||||||
import org.easymock.Capture;
|
|
||||||
import org.easymock.EasyMock;
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -113,8 +112,8 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* Tests for {@link NetworkStatsService}.
|
* Tests for {@link NetworkStatsService}.
|
||||||
*
|
*
|
||||||
* TODO: This test is really brittle, largely due to overly-strict use of Easymock.
|
* TODO: This test used to be really brittle because it used Easymock - it uses Mockito now, but
|
||||||
* Rewrite w/ Mockito.
|
* still uses the Easymock structure, which could be simplified.
|
||||||
*/
|
*/
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class NetworkStatsServiceTest {
|
public class NetworkStatsServiceTest {
|
||||||
@@ -144,10 +143,12 @@ public class NetworkStatsServiceTest {
|
|||||||
private BroadcastInterceptingContext mServiceContext;
|
private BroadcastInterceptingContext mServiceContext;
|
||||||
private File mStatsDir;
|
private File mStatsDir;
|
||||||
|
|
||||||
private INetworkManagementService mNetManager;
|
private @Mock INetworkManagementService mNetManager;
|
||||||
private TrustedTime mTime;
|
private @Mock TrustedTime mTime;
|
||||||
private NetworkStatsSettings mSettings;
|
private @Mock NetworkStatsSettings mSettings;
|
||||||
private IConnectivityManager mConnManager;
|
private @Mock IConnectivityManager mConnManager;
|
||||||
|
private @Mock IBinder mBinder;
|
||||||
|
private @Mock AlarmManager mAlarmManager;
|
||||||
private IdleableHandlerThread mHandlerThread;
|
private IdleableHandlerThread mHandlerThread;
|
||||||
private Handler mHandler;
|
private Handler mHandler;
|
||||||
|
|
||||||
@@ -157,6 +158,7 @@ public class NetworkStatsServiceTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
final Context context = InstrumentationRegistry.getContext();
|
final Context context = InstrumentationRegistry.getContext();
|
||||||
|
|
||||||
mServiceContext = new BroadcastInterceptingContext(context);
|
mServiceContext = new BroadcastInterceptingContext(context);
|
||||||
@@ -165,22 +167,13 @@ public class NetworkStatsServiceTest {
|
|||||||
IoUtils.deleteContents(mStatsDir);
|
IoUtils.deleteContents(mStatsDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
mNetManager = createMock(INetworkManagementService.class);
|
|
||||||
|
|
||||||
// TODO: Mock AlarmManager when migrating this test to Mockito.
|
|
||||||
AlarmManager alarmManager = (AlarmManager) mServiceContext
|
|
||||||
.getSystemService(Context.ALARM_SERVICE);
|
|
||||||
mTime = createMock(TrustedTime.class);
|
|
||||||
mSettings = createMock(NetworkStatsSettings.class);
|
|
||||||
mConnManager = createMock(IConnectivityManager.class);
|
|
||||||
|
|
||||||
PowerManager powerManager = (PowerManager) mServiceContext.getSystemService(
|
PowerManager powerManager = (PowerManager) mServiceContext.getSystemService(
|
||||||
Context.POWER_SERVICE);
|
Context.POWER_SERVICE);
|
||||||
PowerManager.WakeLock wakeLock =
|
PowerManager.WakeLock wakeLock =
|
||||||
powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
|
powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
|
||||||
|
|
||||||
mService = new NetworkStatsService(
|
mService = new NetworkStatsService(
|
||||||
mServiceContext, mNetManager, alarmManager, wakeLock, mTime,
|
mServiceContext, mNetManager, mAlarmManager, wakeLock, mTime,
|
||||||
TelephonyManager.getDefault(), mSettings, new NetworkStatsObservers(),
|
TelephonyManager.getDefault(), mSettings, new NetworkStatsObservers(),
|
||||||
mStatsDir, getBaseDir(mStatsDir));
|
mStatsDir, getBaseDir(mStatsDir));
|
||||||
mHandlerThread = new IdleableHandlerThread("HandlerThread");
|
mHandlerThread = new IdleableHandlerThread("HandlerThread");
|
||||||
@@ -197,17 +190,15 @@ public class NetworkStatsServiceTest {
|
|||||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||||
expectSystemReady();
|
expectSystemReady();
|
||||||
|
|
||||||
// catch INetworkManagementEventObserver during systemReady()
|
|
||||||
final Capture<INetworkManagementEventObserver> networkObserver = new Capture<
|
|
||||||
INetworkManagementEventObserver>();
|
|
||||||
mNetManager.registerObserver(capture(networkObserver));
|
|
||||||
expectLastCall().atLeastOnce();
|
|
||||||
|
|
||||||
replay();
|
|
||||||
mService.systemReady();
|
mService.systemReady();
|
||||||
mSession = mService.openSession();
|
mSession = mService.openSession();
|
||||||
verifyAndReset();
|
assertNotNull("openSession() failed", mSession);
|
||||||
|
|
||||||
|
|
||||||
|
// catch INetworkManagementEventObserver during systemReady()
|
||||||
|
ArgumentCaptor<INetworkManagementEventObserver> networkObserver =
|
||||||
|
ArgumentCaptor.forClass(INetworkManagementEventObserver.class);
|
||||||
|
verify(mNetManager).registerObserver(networkObserver.capture());
|
||||||
mNetworkObserver = networkObserver.getValue();
|
mNetworkObserver = networkObserver.getValue();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -237,15 +228,13 @@ public class NetworkStatsServiceTest {
|
|||||||
expectNetworkState(buildWifiState());
|
expectNetworkState(buildWifiState());
|
||||||
expectNetworkStatsSummary(buildEmptyStats());
|
expectNetworkStatsSummary(buildEmptyStats());
|
||||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||||
expectNetworkStatsPoll();
|
|
||||||
expectBandwidthControlCheck();
|
expectBandwidthControlCheck();
|
||||||
|
|
||||||
replay();
|
|
||||||
mService.forceUpdateIfaces();
|
mService.forceUpdateIfaces();
|
||||||
|
|
||||||
// verify service has empty history for wifi
|
// verify service has empty history for wifi
|
||||||
assertNetworkTotal(sTemplateWifi, 0L, 0L, 0L, 0L, 0);
|
assertNetworkTotal(sTemplateWifi, 0L, 0L, 0L, 0L, 0);
|
||||||
verifyAndReset();
|
|
||||||
|
|
||||||
// modify some number on wifi, and trigger poll event
|
// modify some number on wifi, and trigger poll event
|
||||||
incrementCurrentTime(HOUR_IN_MILLIS);
|
incrementCurrentTime(HOUR_IN_MILLIS);
|
||||||
@@ -254,14 +243,11 @@ public class NetworkStatsServiceTest {
|
|||||||
expectNetworkStatsSummary(new NetworkStats(getElapsedRealtime(), 1)
|
expectNetworkStatsSummary(new NetworkStats(getElapsedRealtime(), 1)
|
||||||
.addIfaceValues(TEST_IFACE, 1024L, 1L, 2048L, 2L));
|
.addIfaceValues(TEST_IFACE, 1024L, 1L, 2048L, 2L));
|
||||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||||
expectNetworkStatsPoll();
|
|
||||||
|
|
||||||
replay();
|
|
||||||
forcePollAndWaitForIdle();
|
forcePollAndWaitForIdle();
|
||||||
|
|
||||||
// verify service recorded history
|
// verify service recorded history
|
||||||
assertNetworkTotal(sTemplateWifi, 1024L, 1L, 2048L, 2L, 0);
|
assertNetworkTotal(sTemplateWifi, 1024L, 1L, 2048L, 2L, 0);
|
||||||
verifyAndReset();
|
|
||||||
|
|
||||||
// and bump forward again, with counters going higher. this is
|
// and bump forward again, with counters going higher. this is
|
||||||
// important, since polling should correctly subtract last snapshot.
|
// important, since polling should correctly subtract last snapshot.
|
||||||
@@ -271,14 +257,10 @@ public class NetworkStatsServiceTest {
|
|||||||
expectNetworkStatsSummary(new NetworkStats(getElapsedRealtime(), 1)
|
expectNetworkStatsSummary(new NetworkStats(getElapsedRealtime(), 1)
|
||||||
.addIfaceValues(TEST_IFACE, 4096L, 4L, 8192L, 8L));
|
.addIfaceValues(TEST_IFACE, 4096L, 4L, 8192L, 8L));
|
||||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||||
expectNetworkStatsPoll();
|
|
||||||
|
|
||||||
replay();
|
|
||||||
forcePollAndWaitForIdle();
|
forcePollAndWaitForIdle();
|
||||||
|
|
||||||
// verify service recorded history
|
// verify service recorded history
|
||||||
assertNetworkTotal(sTemplateWifi, 4096L, 4L, 8192L, 8L, 0);
|
assertNetworkTotal(sTemplateWifi, 4096L, 4L, 8192L, 8L, 0);
|
||||||
verifyAndReset();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -293,15 +275,13 @@ public class NetworkStatsServiceTest {
|
|||||||
expectNetworkState(buildWifiState());
|
expectNetworkState(buildWifiState());
|
||||||
expectNetworkStatsSummary(buildEmptyStats());
|
expectNetworkStatsSummary(buildEmptyStats());
|
||||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||||
expectNetworkStatsPoll();
|
|
||||||
expectBandwidthControlCheck();
|
expectBandwidthControlCheck();
|
||||||
|
|
||||||
replay();
|
|
||||||
mService.forceUpdateIfaces();
|
mService.forceUpdateIfaces();
|
||||||
|
|
||||||
// verify service has empty history for wifi
|
// verify service has empty history for wifi
|
||||||
assertNetworkTotal(sTemplateWifi, 0L, 0L, 0L, 0L, 0);
|
assertNetworkTotal(sTemplateWifi, 0L, 0L, 0L, 0L, 0);
|
||||||
verifyAndReset();
|
|
||||||
|
|
||||||
// modify some number on wifi, and trigger poll event
|
// modify some number on wifi, and trigger poll event
|
||||||
incrementCurrentTime(HOUR_IN_MILLIS);
|
incrementCurrentTime(HOUR_IN_MILLIS);
|
||||||
@@ -315,14 +295,11 @@ public class NetworkStatsServiceTest {
|
|||||||
.addValues(TEST_IFACE, UID_RED, SET_FOREGROUND, TAG_NONE, 512L, 4L, 256L, 2L, 0L)
|
.addValues(TEST_IFACE, UID_RED, SET_FOREGROUND, TAG_NONE, 512L, 4L, 256L, 2L, 0L)
|
||||||
.addValues(TEST_IFACE, UID_RED, SET_FOREGROUND, 0xFAAD, 256L, 2L, 128L, 1L, 0L)
|
.addValues(TEST_IFACE, UID_RED, SET_FOREGROUND, 0xFAAD, 256L, 2L, 128L, 1L, 0L)
|
||||||
.addValues(TEST_IFACE, UID_BLUE, SET_DEFAULT, TAG_NONE, 128L, 1L, 128L, 1L, 0L));
|
.addValues(TEST_IFACE, UID_BLUE, SET_DEFAULT, TAG_NONE, 128L, 1L, 128L, 1L, 0L));
|
||||||
expectNetworkStatsPoll();
|
|
||||||
|
|
||||||
mService.setUidForeground(UID_RED, false);
|
mService.setUidForeground(UID_RED, false);
|
||||||
mService.incrementOperationCount(UID_RED, 0xFAAD, 4);
|
mService.incrementOperationCount(UID_RED, 0xFAAD, 4);
|
||||||
mService.setUidForeground(UID_RED, true);
|
mService.setUidForeground(UID_RED, true);
|
||||||
mService.incrementOperationCount(UID_RED, 0xFAAD, 6);
|
mService.incrementOperationCount(UID_RED, 0xFAAD, 6);
|
||||||
|
|
||||||
replay();
|
|
||||||
forcePollAndWaitForIdle();
|
forcePollAndWaitForIdle();
|
||||||
|
|
||||||
// verify service recorded history
|
// verify service recorded history
|
||||||
@@ -332,16 +309,13 @@ public class NetworkStatsServiceTest {
|
|||||||
assertUidTotal(sTemplateWifi, UID_RED, SET_FOREGROUND, ROAMING_NO, 512L, 4L, 256L, 2L,
|
assertUidTotal(sTemplateWifi, UID_RED, SET_FOREGROUND, ROAMING_NO, 512L, 4L, 256L, 2L,
|
||||||
6);
|
6);
|
||||||
assertUidTotal(sTemplateWifi, UID_BLUE, 128L, 1L, 128L, 1L, 0);
|
assertUidTotal(sTemplateWifi, UID_BLUE, 128L, 1L, 128L, 1L, 0);
|
||||||
verifyAndReset();
|
|
||||||
|
|
||||||
// graceful shutdown system, which should trigger persist of stats, and
|
// graceful shutdown system, which should trigger persist of stats, and
|
||||||
// clear any values in memory.
|
// clear any values in memory.
|
||||||
expectCurrentTime();
|
expectCurrentTime();
|
||||||
expectDefaultSettings();
|
expectDefaultSettings();
|
||||||
replay();
|
|
||||||
mServiceContext.sendBroadcast(new Intent(Intent.ACTION_SHUTDOWN));
|
mServiceContext.sendBroadcast(new Intent(Intent.ACTION_SHUTDOWN));
|
||||||
verifyAndReset();
|
|
||||||
|
|
||||||
assertStatsFilesExist(true);
|
assertStatsFilesExist(true);
|
||||||
|
|
||||||
// boot through serviceReady() again
|
// boot through serviceReady() again
|
||||||
@@ -350,17 +324,8 @@ public class NetworkStatsServiceTest {
|
|||||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||||
expectSystemReady();
|
expectSystemReady();
|
||||||
|
|
||||||
// catch INetworkManagementEventObserver during systemReady()
|
|
||||||
final Capture<INetworkManagementEventObserver> networkObserver = new Capture<
|
|
||||||
INetworkManagementEventObserver>();
|
|
||||||
mNetManager.registerObserver(capture(networkObserver));
|
|
||||||
expectLastCall().atLeastOnce();
|
|
||||||
|
|
||||||
replay();
|
|
||||||
mService.systemReady();
|
mService.systemReady();
|
||||||
|
|
||||||
mNetworkObserver = networkObserver.getValue();
|
|
||||||
|
|
||||||
// after systemReady(), we should have historical stats loaded again
|
// after systemReady(), we should have historical stats loaded again
|
||||||
assertNetworkTotal(sTemplateWifi, 1024L, 8L, 2048L, 16L, 0);
|
assertNetworkTotal(sTemplateWifi, 1024L, 8L, 2048L, 16L, 0);
|
||||||
assertUidTotal(sTemplateWifi, UID_RED, 1024L, 8L, 512L, 4L, 10);
|
assertUidTotal(sTemplateWifi, UID_RED, 1024L, 8L, 512L, 4L, 10);
|
||||||
@@ -368,7 +333,6 @@ public class NetworkStatsServiceTest {
|
|||||||
assertUidTotal(sTemplateWifi, UID_RED, SET_FOREGROUND, ROAMING_NO, 512L, 4L, 256L, 2L,
|
assertUidTotal(sTemplateWifi, UID_RED, SET_FOREGROUND, ROAMING_NO, 512L, 4L, 256L, 2L,
|
||||||
6);
|
6);
|
||||||
assertUidTotal(sTemplateWifi, UID_BLUE, 128L, 1L, 128L, 1L, 0);
|
assertUidTotal(sTemplateWifi, UID_BLUE, 128L, 1L, 128L, 1L, 0);
|
||||||
verifyAndReset();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -387,12 +351,10 @@ public class NetworkStatsServiceTest {
|
|||||||
expectNetworkState(buildWifiState());
|
expectNetworkState(buildWifiState());
|
||||||
expectNetworkStatsSummary(buildEmptyStats());
|
expectNetworkStatsSummary(buildEmptyStats());
|
||||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||||
expectNetworkStatsPoll();
|
|
||||||
expectBandwidthControlCheck();
|
expectBandwidthControlCheck();
|
||||||
|
|
||||||
replay();
|
|
||||||
mService.forceUpdateIfaces();
|
mService.forceUpdateIfaces();
|
||||||
verifyAndReset();
|
|
||||||
|
|
||||||
// modify some number on wifi, and trigger poll event
|
// modify some number on wifi, and trigger poll event
|
||||||
incrementCurrentTime(2 * HOUR_IN_MILLIS);
|
incrementCurrentTime(2 * HOUR_IN_MILLIS);
|
||||||
@@ -401,9 +363,6 @@ public class NetworkStatsServiceTest {
|
|||||||
expectNetworkStatsSummary(new NetworkStats(getElapsedRealtime(), 1)
|
expectNetworkStatsSummary(new NetworkStats(getElapsedRealtime(), 1)
|
||||||
.addIfaceValues(TEST_IFACE, 512L, 4L, 512L, 4L));
|
.addIfaceValues(TEST_IFACE, 512L, 4L, 512L, 4L));
|
||||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||||
expectNetworkStatsPoll();
|
|
||||||
|
|
||||||
replay();
|
|
||||||
forcePollAndWaitForIdle();
|
forcePollAndWaitForIdle();
|
||||||
|
|
||||||
// verify service recorded history
|
// verify service recorded history
|
||||||
@@ -411,7 +370,7 @@ public class NetworkStatsServiceTest {
|
|||||||
assertValues(history, Long.MIN_VALUE, Long.MAX_VALUE, 512L, 4L, 512L, 4L, 0);
|
assertValues(history, Long.MIN_VALUE, Long.MAX_VALUE, 512L, 4L, 512L, 4L, 0);
|
||||||
assertEquals(HOUR_IN_MILLIS, history.getBucketDuration());
|
assertEquals(HOUR_IN_MILLIS, history.getBucketDuration());
|
||||||
assertEquals(2, history.size());
|
assertEquals(2, history.size());
|
||||||
verifyAndReset();
|
|
||||||
|
|
||||||
// now change bucket duration setting and trigger another poll with
|
// now change bucket duration setting and trigger another poll with
|
||||||
// exact same values, which should resize existing buckets.
|
// exact same values, which should resize existing buckets.
|
||||||
@@ -419,9 +378,6 @@ public class NetworkStatsServiceTest {
|
|||||||
expectSettings(0L, 30 * MINUTE_IN_MILLIS, WEEK_IN_MILLIS);
|
expectSettings(0L, 30 * MINUTE_IN_MILLIS, WEEK_IN_MILLIS);
|
||||||
expectNetworkStatsSummary(buildEmptyStats());
|
expectNetworkStatsSummary(buildEmptyStats());
|
||||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||||
expectNetworkStatsPoll();
|
|
||||||
|
|
||||||
replay();
|
|
||||||
forcePollAndWaitForIdle();
|
forcePollAndWaitForIdle();
|
||||||
|
|
||||||
// verify identical stats, but spread across 4 buckets now
|
// verify identical stats, but spread across 4 buckets now
|
||||||
@@ -429,7 +385,6 @@ public class NetworkStatsServiceTest {
|
|||||||
assertValues(history, Long.MIN_VALUE, Long.MAX_VALUE, 512L, 4L, 512L, 4L, 0);
|
assertValues(history, Long.MIN_VALUE, Long.MAX_VALUE, 512L, 4L, 512L, 4L, 0);
|
||||||
assertEquals(30 * MINUTE_IN_MILLIS, history.getBucketDuration());
|
assertEquals(30 * MINUTE_IN_MILLIS, history.getBucketDuration());
|
||||||
assertEquals(4, history.size());
|
assertEquals(4, history.size());
|
||||||
verifyAndReset();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -441,12 +396,10 @@ public class NetworkStatsServiceTest {
|
|||||||
expectNetworkState(buildMobile3gState(IMSI_1));
|
expectNetworkState(buildMobile3gState(IMSI_1));
|
||||||
expectNetworkStatsSummary(buildEmptyStats());
|
expectNetworkStatsSummary(buildEmptyStats());
|
||||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||||
expectNetworkStatsPoll();
|
|
||||||
expectBandwidthControlCheck();
|
expectBandwidthControlCheck();
|
||||||
|
|
||||||
replay();
|
|
||||||
mService.forceUpdateIfaces();
|
mService.forceUpdateIfaces();
|
||||||
verifyAndReset();
|
|
||||||
|
|
||||||
// create some traffic on first network
|
// create some traffic on first network
|
||||||
incrementCurrentTime(HOUR_IN_MILLIS);
|
incrementCurrentTime(HOUR_IN_MILLIS);
|
||||||
@@ -458,11 +411,8 @@ public class NetworkStatsServiceTest {
|
|||||||
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, 1536L, 12L, 512L, 4L, 0L)
|
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, 1536L, 12L, 512L, 4L, 0L)
|
||||||
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, 512L, 4L, 512L, 4L, 0L)
|
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, 512L, 4L, 512L, 4L, 0L)
|
||||||
.addValues(TEST_IFACE, UID_BLUE, SET_DEFAULT, TAG_NONE, 512L, 4L, 0L, 0L, 0L));
|
.addValues(TEST_IFACE, UID_BLUE, SET_DEFAULT, TAG_NONE, 512L, 4L, 0L, 0L, 0L));
|
||||||
expectNetworkStatsPoll();
|
|
||||||
|
|
||||||
mService.incrementOperationCount(UID_RED, 0xF00D, 10);
|
mService.incrementOperationCount(UID_RED, 0xF00D, 10);
|
||||||
|
|
||||||
replay();
|
|
||||||
forcePollAndWaitForIdle();
|
forcePollAndWaitForIdle();
|
||||||
|
|
||||||
// verify service recorded history
|
// verify service recorded history
|
||||||
@@ -470,7 +420,7 @@ public class NetworkStatsServiceTest {
|
|||||||
assertNetworkTotal(sTemplateWifi, 0L, 0L, 0L, 0L, 0);
|
assertNetworkTotal(sTemplateWifi, 0L, 0L, 0L, 0L, 0);
|
||||||
assertUidTotal(sTemplateImsi1, UID_RED, 1536L, 12L, 512L, 4L, 10);
|
assertUidTotal(sTemplateImsi1, UID_RED, 1536L, 12L, 512L, 4L, 10);
|
||||||
assertUidTotal(sTemplateImsi1, UID_BLUE, 512L, 4L, 0L, 0L, 0);
|
assertUidTotal(sTemplateImsi1, UID_BLUE, 512L, 4L, 0L, 0L, 0);
|
||||||
verifyAndReset();
|
|
||||||
|
|
||||||
// now switch networks; this also tests that we're okay with interfaces
|
// now switch networks; this also tests that we're okay with interfaces
|
||||||
// disappearing, to verify we don't count backwards.
|
// disappearing, to verify we don't count backwards.
|
||||||
@@ -484,13 +434,11 @@ public class NetworkStatsServiceTest {
|
|||||||
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, 1536L, 12L, 512L, 4L, 0L)
|
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, 1536L, 12L, 512L, 4L, 0L)
|
||||||
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, 512L, 4L, 512L, 4L, 0L)
|
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, 512L, 4L, 512L, 4L, 0L)
|
||||||
.addValues(TEST_IFACE, UID_BLUE, SET_DEFAULT, TAG_NONE, 512L, 4L, 0L, 0L, 0L));
|
.addValues(TEST_IFACE, UID_BLUE, SET_DEFAULT, TAG_NONE, 512L, 4L, 0L, 0L, 0L));
|
||||||
expectNetworkStatsPoll();
|
|
||||||
expectBandwidthControlCheck();
|
expectBandwidthControlCheck();
|
||||||
|
|
||||||
replay();
|
|
||||||
mService.forceUpdateIfaces();
|
mService.forceUpdateIfaces();
|
||||||
forcePollAndWaitForIdle();
|
forcePollAndWaitForIdle();
|
||||||
verifyAndReset();
|
|
||||||
|
|
||||||
// create traffic on second network
|
// create traffic on second network
|
||||||
incrementCurrentTime(HOUR_IN_MILLIS);
|
incrementCurrentTime(HOUR_IN_MILLIS);
|
||||||
@@ -503,11 +451,8 @@ public class NetworkStatsServiceTest {
|
|||||||
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, 512L, 4L, 512L, 4L, 0L)
|
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, 512L, 4L, 512L, 4L, 0L)
|
||||||
.addValues(TEST_IFACE, UID_BLUE, SET_DEFAULT, TAG_NONE, 640L, 5L, 1024L, 8L, 0L)
|
.addValues(TEST_IFACE, UID_BLUE, SET_DEFAULT, TAG_NONE, 640L, 5L, 1024L, 8L, 0L)
|
||||||
.addValues(TEST_IFACE, UID_BLUE, SET_DEFAULT, 0xFAAD, 128L, 1L, 1024L, 8L, 0L));
|
.addValues(TEST_IFACE, UID_BLUE, SET_DEFAULT, 0xFAAD, 128L, 1L, 1024L, 8L, 0L));
|
||||||
expectNetworkStatsPoll();
|
|
||||||
|
|
||||||
mService.incrementOperationCount(UID_BLUE, 0xFAAD, 10);
|
mService.incrementOperationCount(UID_BLUE, 0xFAAD, 10);
|
||||||
|
|
||||||
replay();
|
|
||||||
forcePollAndWaitForIdle();
|
forcePollAndWaitForIdle();
|
||||||
|
|
||||||
// verify original history still intact
|
// verify original history still intact
|
||||||
@@ -520,7 +465,6 @@ public class NetworkStatsServiceTest {
|
|||||||
assertNetworkTotal(sTemplateImsi2, 128L, 1L, 1024L, 8L, 0);
|
assertNetworkTotal(sTemplateImsi2, 128L, 1L, 1024L, 8L, 0);
|
||||||
assertNetworkTotal(sTemplateWifi, 0L, 0L, 0L, 0L, 0);
|
assertNetworkTotal(sTemplateWifi, 0L, 0L, 0L, 0L, 0);
|
||||||
assertUidTotal(sTemplateImsi2, UID_BLUE, 128L, 1L, 1024L, 8L, 10);
|
assertUidTotal(sTemplateImsi2, UID_BLUE, 128L, 1L, 1024L, 8L, 10);
|
||||||
verifyAndReset();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -532,12 +476,10 @@ public class NetworkStatsServiceTest {
|
|||||||
expectNetworkState(buildWifiState());
|
expectNetworkState(buildWifiState());
|
||||||
expectNetworkStatsSummary(buildEmptyStats());
|
expectNetworkStatsSummary(buildEmptyStats());
|
||||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||||
expectNetworkStatsPoll();
|
|
||||||
expectBandwidthControlCheck();
|
expectBandwidthControlCheck();
|
||||||
|
|
||||||
replay();
|
|
||||||
mService.forceUpdateIfaces();
|
mService.forceUpdateIfaces();
|
||||||
verifyAndReset();
|
|
||||||
|
|
||||||
// create some traffic
|
// create some traffic
|
||||||
incrementCurrentTime(HOUR_IN_MILLIS);
|
incrementCurrentTime(HOUR_IN_MILLIS);
|
||||||
@@ -550,11 +492,8 @@ public class NetworkStatsServiceTest {
|
|||||||
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xFAAD, 16L, 1L, 16L, 1L, 0L)
|
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xFAAD, 16L, 1L, 16L, 1L, 0L)
|
||||||
.addValues(TEST_IFACE, UID_BLUE, SET_DEFAULT, TAG_NONE, 4096L, 258L, 512L, 32L, 0L)
|
.addValues(TEST_IFACE, UID_BLUE, SET_DEFAULT, TAG_NONE, 4096L, 258L, 512L, 32L, 0L)
|
||||||
.addValues(TEST_IFACE, UID_GREEN, SET_DEFAULT, TAG_NONE, 16L, 1L, 16L, 1L, 0L));
|
.addValues(TEST_IFACE, UID_GREEN, SET_DEFAULT, TAG_NONE, 16L, 1L, 16L, 1L, 0L));
|
||||||
expectNetworkStatsPoll();
|
|
||||||
|
|
||||||
mService.incrementOperationCount(UID_RED, 0xFAAD, 10);
|
mService.incrementOperationCount(UID_RED, 0xFAAD, 10);
|
||||||
|
|
||||||
replay();
|
|
||||||
forcePollAndWaitForIdle();
|
forcePollAndWaitForIdle();
|
||||||
|
|
||||||
// verify service recorded history
|
// verify service recorded history
|
||||||
@@ -562,7 +501,7 @@ public class NetworkStatsServiceTest {
|
|||||||
assertUidTotal(sTemplateWifi, UID_RED, 16L, 1L, 16L, 1L, 10);
|
assertUidTotal(sTemplateWifi, UID_RED, 16L, 1L, 16L, 1L, 10);
|
||||||
assertUidTotal(sTemplateWifi, UID_BLUE, 4096L, 258L, 512L, 32L, 0);
|
assertUidTotal(sTemplateWifi, UID_BLUE, 4096L, 258L, 512L, 32L, 0);
|
||||||
assertUidTotal(sTemplateWifi, UID_GREEN, 16L, 1L, 16L, 1L, 0);
|
assertUidTotal(sTemplateWifi, UID_GREEN, 16L, 1L, 16L, 1L, 0);
|
||||||
verifyAndReset();
|
|
||||||
|
|
||||||
// now pretend two UIDs are uninstalled, which should migrate stats to
|
// now pretend two UIDs are uninstalled, which should migrate stats to
|
||||||
// special "removed" bucket.
|
// special "removed" bucket.
|
||||||
@@ -575,9 +514,6 @@ public class NetworkStatsServiceTest {
|
|||||||
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xFAAD, 16L, 1L, 16L, 1L, 0L)
|
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xFAAD, 16L, 1L, 16L, 1L, 0L)
|
||||||
.addValues(TEST_IFACE, UID_BLUE, SET_DEFAULT, TAG_NONE, 4096L, 258L, 512L, 32L, 0L)
|
.addValues(TEST_IFACE, UID_BLUE, SET_DEFAULT, TAG_NONE, 4096L, 258L, 512L, 32L, 0L)
|
||||||
.addValues(TEST_IFACE, UID_GREEN, SET_DEFAULT, TAG_NONE, 16L, 1L, 16L, 1L, 0L));
|
.addValues(TEST_IFACE, UID_GREEN, SET_DEFAULT, TAG_NONE, 16L, 1L, 16L, 1L, 0L));
|
||||||
expectNetworkStatsPoll();
|
|
||||||
|
|
||||||
replay();
|
|
||||||
final Intent intent = new Intent(ACTION_UID_REMOVED);
|
final Intent intent = new Intent(ACTION_UID_REMOVED);
|
||||||
intent.putExtra(EXTRA_UID, UID_BLUE);
|
intent.putExtra(EXTRA_UID, UID_BLUE);
|
||||||
mServiceContext.sendBroadcast(intent);
|
mServiceContext.sendBroadcast(intent);
|
||||||
@@ -591,7 +527,6 @@ public class NetworkStatsServiceTest {
|
|||||||
assertUidTotal(sTemplateWifi, UID_BLUE, 0L, 0L, 0L, 0L, 0);
|
assertUidTotal(sTemplateWifi, UID_BLUE, 0L, 0L, 0L, 0L, 0);
|
||||||
assertUidTotal(sTemplateWifi, UID_GREEN, 16L, 1L, 16L, 1L, 0);
|
assertUidTotal(sTemplateWifi, UID_GREEN, 16L, 1L, 16L, 1L, 0);
|
||||||
assertUidTotal(sTemplateWifi, UID_REMOVED, 4112L, 259L, 528L, 33L, 10);
|
assertUidTotal(sTemplateWifi, UID_REMOVED, 4112L, 259L, 528L, 33L, 10);
|
||||||
verifyAndReset();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -603,12 +538,10 @@ public class NetworkStatsServiceTest {
|
|||||||
expectNetworkState(buildMobile3gState(IMSI_1));
|
expectNetworkState(buildMobile3gState(IMSI_1));
|
||||||
expectNetworkStatsSummary(buildEmptyStats());
|
expectNetworkStatsSummary(buildEmptyStats());
|
||||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||||
expectNetworkStatsPoll();
|
|
||||||
expectBandwidthControlCheck();
|
expectBandwidthControlCheck();
|
||||||
|
|
||||||
replay();
|
|
||||||
mService.forceUpdateIfaces();
|
mService.forceUpdateIfaces();
|
||||||
verifyAndReset();
|
|
||||||
|
|
||||||
// create some traffic
|
// create some traffic
|
||||||
incrementCurrentTime(HOUR_IN_MILLIS);
|
incrementCurrentTime(HOUR_IN_MILLIS);
|
||||||
@@ -618,16 +551,13 @@ public class NetworkStatsServiceTest {
|
|||||||
expectNetworkStatsUidDetail(new NetworkStats(getElapsedRealtime(), 1)
|
expectNetworkStatsUidDetail(new NetworkStats(getElapsedRealtime(), 1)
|
||||||
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, 1024L, 8L, 1024L, 8L, 0L)
|
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, 1024L, 8L, 1024L, 8L, 0L)
|
||||||
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, 512L, 4L, 512L, 4L, 0L));
|
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, 512L, 4L, 512L, 4L, 0L));
|
||||||
expectNetworkStatsPoll();
|
|
||||||
|
|
||||||
mService.incrementOperationCount(UID_RED, 0xF00D, 5);
|
mService.incrementOperationCount(UID_RED, 0xF00D, 5);
|
||||||
|
|
||||||
replay();
|
|
||||||
forcePollAndWaitForIdle();
|
forcePollAndWaitForIdle();
|
||||||
|
|
||||||
// verify service recorded history
|
// verify service recorded history
|
||||||
assertUidTotal(sTemplateImsi1, UID_RED, 1024L, 8L, 1024L, 8L, 5);
|
assertUidTotal(sTemplateImsi1, UID_RED, 1024L, 8L, 1024L, 8L, 5);
|
||||||
verifyAndReset();
|
|
||||||
|
|
||||||
// now switch over to 4g network
|
// now switch over to 4g network
|
||||||
incrementCurrentTime(HOUR_IN_MILLIS);
|
incrementCurrentTime(HOUR_IN_MILLIS);
|
||||||
@@ -638,13 +568,11 @@ public class NetworkStatsServiceTest {
|
|||||||
expectNetworkStatsUidDetail(new NetworkStats(getElapsedRealtime(), 1)
|
expectNetworkStatsUidDetail(new NetworkStats(getElapsedRealtime(), 1)
|
||||||
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, 1024L, 8L, 1024L, 8L, 0L)
|
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, 1024L, 8L, 1024L, 8L, 0L)
|
||||||
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, 512L, 4L, 512L, 4L, 0L));
|
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, 512L, 4L, 512L, 4L, 0L));
|
||||||
expectNetworkStatsPoll();
|
|
||||||
expectBandwidthControlCheck();
|
expectBandwidthControlCheck();
|
||||||
|
|
||||||
replay();
|
|
||||||
mService.forceUpdateIfaces();
|
mService.forceUpdateIfaces();
|
||||||
forcePollAndWaitForIdle();
|
forcePollAndWaitForIdle();
|
||||||
verifyAndReset();
|
|
||||||
|
|
||||||
// create traffic on second network
|
// create traffic on second network
|
||||||
incrementCurrentTime(HOUR_IN_MILLIS);
|
incrementCurrentTime(HOUR_IN_MILLIS);
|
||||||
@@ -656,17 +584,12 @@ public class NetworkStatsServiceTest {
|
|||||||
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, 512L, 4L, 512L, 4L, 0L)
|
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, 512L, 4L, 512L, 4L, 0L)
|
||||||
.addValues(TEST_IFACE2, UID_RED, SET_DEFAULT, TAG_NONE, 512L, 4L, 256L, 2L, 0L)
|
.addValues(TEST_IFACE2, UID_RED, SET_DEFAULT, TAG_NONE, 512L, 4L, 256L, 2L, 0L)
|
||||||
.addValues(TEST_IFACE2, UID_RED, SET_DEFAULT, 0xFAAD, 512L, 4L, 256L, 2L, 0L));
|
.addValues(TEST_IFACE2, UID_RED, SET_DEFAULT, 0xFAAD, 512L, 4L, 256L, 2L, 0L));
|
||||||
expectNetworkStatsPoll();
|
|
||||||
|
|
||||||
mService.incrementOperationCount(UID_RED, 0xFAAD, 5);
|
mService.incrementOperationCount(UID_RED, 0xFAAD, 5);
|
||||||
|
|
||||||
replay();
|
|
||||||
forcePollAndWaitForIdle();
|
forcePollAndWaitForIdle();
|
||||||
|
|
||||||
// verify that ALL_MOBILE template combines both
|
// verify that ALL_MOBILE template combines both
|
||||||
assertUidTotal(sTemplateImsi1, UID_RED, 1536L, 12L, 1280L, 10L, 10);
|
assertUidTotal(sTemplateImsi1, UID_RED, 1536L, 12L, 1280L, 10L, 10);
|
||||||
|
|
||||||
verifyAndReset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -677,12 +600,10 @@ public class NetworkStatsServiceTest {
|
|||||||
expectNetworkState(buildWifiState());
|
expectNetworkState(buildWifiState());
|
||||||
expectNetworkStatsSummary(buildEmptyStats());
|
expectNetworkStatsSummary(buildEmptyStats());
|
||||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||||
expectNetworkStatsPoll();
|
|
||||||
expectBandwidthControlCheck();
|
expectBandwidthControlCheck();
|
||||||
|
|
||||||
replay();
|
|
||||||
mService.forceUpdateIfaces();
|
mService.forceUpdateIfaces();
|
||||||
verifyAndReset();
|
|
||||||
|
|
||||||
// create some traffic for two apps
|
// create some traffic for two apps
|
||||||
incrementCurrentTime(HOUR_IN_MILLIS);
|
incrementCurrentTime(HOUR_IN_MILLIS);
|
||||||
@@ -693,17 +614,14 @@ public class NetworkStatsServiceTest {
|
|||||||
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, 50L, 5L, 50L, 5L, 0L)
|
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, 50L, 5L, 50L, 5L, 0L)
|
||||||
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, 10L, 1L, 10L, 1L, 0L)
|
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, 10L, 1L, 10L, 1L, 0L)
|
||||||
.addValues(TEST_IFACE, UID_BLUE, SET_DEFAULT, TAG_NONE, 1024L, 8L, 512L, 4L, 0L));
|
.addValues(TEST_IFACE, UID_BLUE, SET_DEFAULT, TAG_NONE, 1024L, 8L, 512L, 4L, 0L));
|
||||||
expectNetworkStatsPoll();
|
|
||||||
|
|
||||||
mService.incrementOperationCount(UID_RED, 0xF00D, 1);
|
mService.incrementOperationCount(UID_RED, 0xF00D, 1);
|
||||||
|
|
||||||
replay();
|
|
||||||
forcePollAndWaitForIdle();
|
forcePollAndWaitForIdle();
|
||||||
|
|
||||||
// verify service recorded history
|
// verify service recorded history
|
||||||
assertUidTotal(sTemplateWifi, UID_RED, 50L, 5L, 50L, 5L, 1);
|
assertUidTotal(sTemplateWifi, UID_RED, 50L, 5L, 50L, 5L, 1);
|
||||||
assertUidTotal(sTemplateWifi, UID_BLUE, 1024L, 8L, 512L, 4L, 0);
|
assertUidTotal(sTemplateWifi, UID_BLUE, 1024L, 8L, 512L, 4L, 0);
|
||||||
verifyAndReset();
|
|
||||||
|
|
||||||
// now create more traffic in next hour, but only for one app
|
// now create more traffic in next hour, but only for one app
|
||||||
incrementCurrentTime(HOUR_IN_MILLIS);
|
incrementCurrentTime(HOUR_IN_MILLIS);
|
||||||
@@ -714,9 +632,6 @@ public class NetworkStatsServiceTest {
|
|||||||
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, 50L, 5L, 50L, 5L, 0L)
|
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, 50L, 5L, 50L, 5L, 0L)
|
||||||
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, 10L, 1L, 10L, 1L, 0L)
|
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, 10L, 1L, 10L, 1L, 0L)
|
||||||
.addValues(TEST_IFACE, UID_BLUE, SET_DEFAULT, TAG_NONE, 2048L, 16L, 1024L, 8L, 0L));
|
.addValues(TEST_IFACE, UID_BLUE, SET_DEFAULT, TAG_NONE, 2048L, 16L, 1024L, 8L, 0L));
|
||||||
expectNetworkStatsPoll();
|
|
||||||
|
|
||||||
replay();
|
|
||||||
forcePollAndWaitForIdle();
|
forcePollAndWaitForIdle();
|
||||||
|
|
||||||
// first verify entire history present
|
// first verify entire history present
|
||||||
@@ -737,8 +652,6 @@ public class NetworkStatsServiceTest {
|
|||||||
assertEquals(1, stats.size());
|
assertEquals(1, stats.size());
|
||||||
assertValues(stats, IFACE_ALL, UID_BLUE, SET_DEFAULT, TAG_NONE, ROAMING_NO, 1024L, 8L,
|
assertValues(stats, IFACE_ALL, UID_BLUE, SET_DEFAULT, TAG_NONE, ROAMING_NO, 1024L, 8L,
|
||||||
512L, 4L, 0);
|
512L, 4L, 0);
|
||||||
|
|
||||||
verifyAndReset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -749,12 +662,10 @@ public class NetworkStatsServiceTest {
|
|||||||
expectNetworkState(buildWifiState());
|
expectNetworkState(buildWifiState());
|
||||||
expectNetworkStatsSummary(buildEmptyStats());
|
expectNetworkStatsSummary(buildEmptyStats());
|
||||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||||
expectNetworkStatsPoll();
|
|
||||||
expectBandwidthControlCheck();
|
expectBandwidthControlCheck();
|
||||||
|
|
||||||
replay();
|
|
||||||
mService.forceUpdateIfaces();
|
mService.forceUpdateIfaces();
|
||||||
verifyAndReset();
|
|
||||||
|
|
||||||
// create some initial traffic
|
// create some initial traffic
|
||||||
incrementCurrentTime(HOUR_IN_MILLIS);
|
incrementCurrentTime(HOUR_IN_MILLIS);
|
||||||
@@ -764,16 +675,13 @@ public class NetworkStatsServiceTest {
|
|||||||
expectNetworkStatsUidDetail(new NetworkStats(getElapsedRealtime(), 1)
|
expectNetworkStatsUidDetail(new NetworkStats(getElapsedRealtime(), 1)
|
||||||
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, 128L, 2L, 128L, 2L, 0L)
|
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, 128L, 2L, 128L, 2L, 0L)
|
||||||
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, 64L, 1L, 64L, 1L, 0L));
|
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, 64L, 1L, 64L, 1L, 0L));
|
||||||
expectNetworkStatsPoll();
|
|
||||||
|
|
||||||
mService.incrementOperationCount(UID_RED, 0xF00D, 1);
|
mService.incrementOperationCount(UID_RED, 0xF00D, 1);
|
||||||
|
|
||||||
replay();
|
|
||||||
forcePollAndWaitForIdle();
|
forcePollAndWaitForIdle();
|
||||||
|
|
||||||
// verify service recorded history
|
// verify service recorded history
|
||||||
assertUidTotal(sTemplateWifi, UID_RED, 128L, 2L, 128L, 2L, 1);
|
assertUidTotal(sTemplateWifi, UID_RED, 128L, 2L, 128L, 2L, 1);
|
||||||
verifyAndReset();
|
|
||||||
|
|
||||||
// now switch to foreground
|
// now switch to foreground
|
||||||
incrementCurrentTime(HOUR_IN_MILLIS);
|
incrementCurrentTime(HOUR_IN_MILLIS);
|
||||||
@@ -785,12 +693,9 @@ public class NetworkStatsServiceTest {
|
|||||||
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, 64L, 1L, 64L, 1L, 0L)
|
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, 64L, 1L, 64L, 1L, 0L)
|
||||||
.addValues(TEST_IFACE, UID_RED, SET_FOREGROUND, TAG_NONE, 32L, 2L, 32L, 2L, 0L)
|
.addValues(TEST_IFACE, UID_RED, SET_FOREGROUND, TAG_NONE, 32L, 2L, 32L, 2L, 0L)
|
||||||
.addValues(TEST_IFACE, UID_RED, SET_FOREGROUND, 0xFAAD, 1L, 1L, 1L, 1L, 0L));
|
.addValues(TEST_IFACE, UID_RED, SET_FOREGROUND, 0xFAAD, 1L, 1L, 1L, 1L, 0L));
|
||||||
expectNetworkStatsPoll();
|
|
||||||
|
|
||||||
mService.setUidForeground(UID_RED, true);
|
mService.setUidForeground(UID_RED, true);
|
||||||
mService.incrementOperationCount(UID_RED, 0xFAAD, 1);
|
mService.incrementOperationCount(UID_RED, 0xFAAD, 1);
|
||||||
|
|
||||||
replay();
|
|
||||||
forcePollAndWaitForIdle();
|
forcePollAndWaitForIdle();
|
||||||
|
|
||||||
// test that we combined correctly
|
// test that we combined correctly
|
||||||
@@ -808,8 +713,6 @@ public class NetworkStatsServiceTest {
|
|||||||
32L, 2L, 1);
|
32L, 2L, 1);
|
||||||
assertValues(stats, IFACE_ALL, UID_RED, SET_FOREGROUND, 0xFAAD, ROAMING_NO, 1L, 1L, 1L,
|
assertValues(stats, IFACE_ALL, UID_RED, SET_FOREGROUND, 0xFAAD, ROAMING_NO, 1L, 1L, 1L,
|
||||||
1L, 1);
|
1L, 1);
|
||||||
|
|
||||||
verifyAndReset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -820,12 +723,10 @@ public class NetworkStatsServiceTest {
|
|||||||
expectNetworkState(buildMobile3gState(IMSI_1, true /* isRoaming */));
|
expectNetworkState(buildMobile3gState(IMSI_1, true /* isRoaming */));
|
||||||
expectNetworkStatsSummary(buildEmptyStats());
|
expectNetworkStatsSummary(buildEmptyStats());
|
||||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||||
expectNetworkStatsPoll();
|
|
||||||
expectBandwidthControlCheck();
|
expectBandwidthControlCheck();
|
||||||
|
|
||||||
replay();
|
|
||||||
mService.forceUpdateIfaces();
|
mService.forceUpdateIfaces();
|
||||||
verifyAndReset();
|
|
||||||
|
|
||||||
// Create some traffic
|
// Create some traffic
|
||||||
incrementCurrentTime(HOUR_IN_MILLIS);
|
incrementCurrentTime(HOUR_IN_MILLIS);
|
||||||
@@ -840,9 +741,6 @@ public class NetworkStatsServiceTest {
|
|||||||
128L, 2L, 0L)
|
128L, 2L, 0L)
|
||||||
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, ROAMING_NO, 64L, 1L, 64L,
|
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, ROAMING_NO, 64L, 1L, 64L,
|
||||||
1L, 0L));
|
1L, 0L));
|
||||||
expectNetworkStatsPoll();
|
|
||||||
|
|
||||||
replay();
|
|
||||||
forcePollAndWaitForIdle();
|
forcePollAndWaitForIdle();
|
||||||
|
|
||||||
// verify service recorded history
|
// verify service recorded history
|
||||||
@@ -856,8 +754,6 @@ public class NetworkStatsServiceTest {
|
|||||||
128L, 2L, 0);
|
128L, 2L, 0);
|
||||||
assertValues(stats, IFACE_ALL, UID_RED, SET_DEFAULT, 0xF00D, ROAMING_YES, 64L, 1L, 64L,
|
assertValues(stats, IFACE_ALL, UID_RED, SET_DEFAULT, 0xF00D, ROAMING_YES, 64L, 1L, 64L,
|
||||||
1L, 0);
|
1L, 0);
|
||||||
|
|
||||||
verifyAndReset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -868,12 +764,10 @@ public class NetworkStatsServiceTest {
|
|||||||
expectNetworkState(buildMobile3gState(IMSI_1));
|
expectNetworkState(buildMobile3gState(IMSI_1));
|
||||||
expectNetworkStatsSummary(buildEmptyStats());
|
expectNetworkStatsSummary(buildEmptyStats());
|
||||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||||
expectNetworkStatsPoll();
|
|
||||||
expectBandwidthControlCheck();
|
expectBandwidthControlCheck();
|
||||||
|
|
||||||
replay();
|
|
||||||
mService.forceUpdateIfaces();
|
mService.forceUpdateIfaces();
|
||||||
verifyAndReset();
|
|
||||||
|
|
||||||
// create some tethering traffic
|
// create some tethering traffic
|
||||||
incrementCurrentTime(HOUR_IN_MILLIS);
|
incrementCurrentTime(HOUR_IN_MILLIS);
|
||||||
@@ -889,16 +783,12 @@ public class NetworkStatsServiceTest {
|
|||||||
.addValues(TEST_IFACE, UID_TETHERING, SET_DEFAULT, TAG_NONE, 1920L, 14L, 384L, 2L, 0L);
|
.addValues(TEST_IFACE, UID_TETHERING, SET_DEFAULT, TAG_NONE, 1920L, 14L, 384L, 2L, 0L);
|
||||||
|
|
||||||
expectNetworkStatsUidDetail(uidStats, tetherIfacePairs, tetherStats);
|
expectNetworkStatsUidDetail(uidStats, tetherIfacePairs, tetherStats);
|
||||||
expectNetworkStatsPoll();
|
|
||||||
|
|
||||||
replay();
|
|
||||||
forcePollAndWaitForIdle();
|
forcePollAndWaitForIdle();
|
||||||
|
|
||||||
// verify service recorded history
|
// verify service recorded history
|
||||||
assertNetworkTotal(sTemplateImsi1, 2048L, 16L, 512L, 4L, 0);
|
assertNetworkTotal(sTemplateImsi1, 2048L, 16L, 512L, 4L, 0);
|
||||||
assertUidTotal(sTemplateImsi1, UID_RED, 128L, 2L, 128L, 2L, 0);
|
assertUidTotal(sTemplateImsi1, UID_RED, 128L, 2L, 128L, 2L, 0);
|
||||||
assertUidTotal(sTemplateImsi1, UID_TETHERING, 1920L, 14L, 384L, 2L, 0);
|
assertUidTotal(sTemplateImsi1, UID_TETHERING, 1920L, 14L, 384L, 2L, 0);
|
||||||
verifyAndReset();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -911,16 +801,12 @@ public class NetworkStatsServiceTest {
|
|||||||
expectNetworkState(buildWifiState());
|
expectNetworkState(buildWifiState());
|
||||||
expectNetworkStatsSummary(buildEmptyStats());
|
expectNetworkStatsSummary(buildEmptyStats());
|
||||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||||
expectNetworkStatsPoll();
|
|
||||||
expectBandwidthControlCheck();
|
expectBandwidthControlCheck();
|
||||||
|
|
||||||
replay();
|
|
||||||
mService.forceUpdateIfaces();
|
mService.forceUpdateIfaces();
|
||||||
|
|
||||||
// verify service has empty history for wifi
|
// verify service has empty history for wifi
|
||||||
assertNetworkTotal(sTemplateWifi, 0L, 0L, 0L, 0L, 0);
|
assertNetworkTotal(sTemplateWifi, 0L, 0L, 0L, 0L, 0);
|
||||||
verifyAndReset();
|
|
||||||
|
|
||||||
String callingPackage = "the.calling.package";
|
String callingPackage = "the.calling.package";
|
||||||
long thresholdInBytes = 1L; // very small; should be overriden by framework
|
long thresholdInBytes = 1L; // very small; should be overriden by framework
|
||||||
DataUsageRequest inputRequest = new DataUsageRequest(
|
DataUsageRequest inputRequest = new DataUsageRequest(
|
||||||
@@ -931,23 +817,18 @@ public class NetworkStatsServiceTest {
|
|||||||
LatchedHandler latchedHandler = new LatchedHandler(Looper.getMainLooper(), cv);
|
LatchedHandler latchedHandler = new LatchedHandler(Looper.getMainLooper(), cv);
|
||||||
Messenger messenger = new Messenger(latchedHandler);
|
Messenger messenger = new Messenger(latchedHandler);
|
||||||
|
|
||||||
// Allow binder to connect
|
|
||||||
IBinder mockBinder = createMock(IBinder.class);
|
|
||||||
mockBinder.linkToDeath((IBinder.DeathRecipient) anyObject(), anyInt());
|
|
||||||
EasyMock.replay(mockBinder);
|
|
||||||
|
|
||||||
// Force poll
|
// Force poll
|
||||||
expectCurrentTime();
|
expectCurrentTime();
|
||||||
expectDefaultSettings();
|
expectDefaultSettings();
|
||||||
expectNetworkStatsSummary(buildEmptyStats());
|
expectNetworkStatsSummary(buildEmptyStats());
|
||||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||||
expectNetworkStatsPoll();
|
|
||||||
replay();
|
|
||||||
|
|
||||||
// Register and verify request and that binder was called
|
// Register and verify request and that binder was called
|
||||||
DataUsageRequest request =
|
DataUsageRequest request =
|
||||||
mService.registerUsageCallback(callingPackage, inputRequest,
|
mService.registerUsageCallback(callingPackage, inputRequest,
|
||||||
messenger, mockBinder);
|
messenger, mBinder);
|
||||||
assertTrue(request.requestId > 0);
|
assertTrue(request.requestId > 0);
|
||||||
assertTrue(Objects.equals(sTemplateWifi, request.template));
|
assertTrue(Objects.equals(sTemplateWifi, request.template));
|
||||||
long minThresholdInBytes = 2 * 1024 * 1024; // 2 MB
|
long minThresholdInBytes = 2 * 1024 * 1024; // 2 MB
|
||||||
@@ -957,11 +838,11 @@ public class NetworkStatsServiceTest {
|
|||||||
mHandler.sendMessage(mHandler.obtainMessage(-1));
|
mHandler.sendMessage(mHandler.obtainMessage(-1));
|
||||||
mHandlerThread.waitForIdle(WAIT_TIMEOUT);
|
mHandlerThread.waitForIdle(WAIT_TIMEOUT);
|
||||||
|
|
||||||
verifyAndReset();
|
|
||||||
|
|
||||||
// Make sure that the caller binder gets connected
|
// Make sure that the caller binder gets connected
|
||||||
EasyMock.verify(mockBinder);
|
verify(mBinder).linkToDeath(any(IBinder.DeathRecipient.class), anyInt());
|
||||||
EasyMock.reset(mockBinder);
|
|
||||||
|
|
||||||
// modify some number on wifi, and trigger poll event
|
// modify some number on wifi, and trigger poll event
|
||||||
// not enough traffic to call data usage callback
|
// not enough traffic to call data usage callback
|
||||||
@@ -971,13 +852,9 @@ public class NetworkStatsServiceTest {
|
|||||||
expectNetworkStatsSummary(new NetworkStats(getElapsedRealtime(), 1)
|
expectNetworkStatsSummary(new NetworkStats(getElapsedRealtime(), 1)
|
||||||
.addIfaceValues(TEST_IFACE, 1024L, 1L, 2048L, 2L));
|
.addIfaceValues(TEST_IFACE, 1024L, 1L, 2048L, 2L));
|
||||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||||
expectNetworkStatsPoll();
|
|
||||||
|
|
||||||
replay();
|
|
||||||
forcePollAndWaitForIdle();
|
forcePollAndWaitForIdle();
|
||||||
|
|
||||||
// verify service recorded history
|
// verify service recorded history
|
||||||
verifyAndReset();
|
|
||||||
assertNetworkTotal(sTemplateWifi, 1024L, 1L, 2048L, 2L, 0);
|
assertNetworkTotal(sTemplateWifi, 1024L, 1L, 2048L, 2L, 0);
|
||||||
|
|
||||||
// make sure callback has not being called
|
// make sure callback has not being called
|
||||||
@@ -991,14 +868,11 @@ public class NetworkStatsServiceTest {
|
|||||||
expectNetworkStatsSummary(new NetworkStats(getElapsedRealtime(), 1)
|
expectNetworkStatsSummary(new NetworkStats(getElapsedRealtime(), 1)
|
||||||
.addIfaceValues(TEST_IFACE, 4096000L, 4L, 8192000L, 8L));
|
.addIfaceValues(TEST_IFACE, 4096000L, 4L, 8192000L, 8L));
|
||||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||||
expectNetworkStatsPoll();
|
|
||||||
|
|
||||||
replay();
|
|
||||||
forcePollAndWaitForIdle();
|
forcePollAndWaitForIdle();
|
||||||
|
|
||||||
// verify service recorded history
|
// verify service recorded history
|
||||||
assertNetworkTotal(sTemplateWifi, 4096000L, 4L, 8192000L, 8L, 0);
|
assertNetworkTotal(sTemplateWifi, 4096000L, 4L, 8192000L, 8L, 0);
|
||||||
verifyAndReset();
|
|
||||||
|
|
||||||
// Wait for the caller to ack receipt of CALLBACK_LIMIT_REACHED
|
// Wait for the caller to ack receipt of CALLBACK_LIMIT_REACHED
|
||||||
assertTrue(cv.block(WAIT_TIMEOUT));
|
assertTrue(cv.block(WAIT_TIMEOUT));
|
||||||
@@ -1006,9 +880,7 @@ public class NetworkStatsServiceTest {
|
|||||||
cv.close();
|
cv.close();
|
||||||
|
|
||||||
// Allow binder to disconnect
|
// Allow binder to disconnect
|
||||||
expect(mockBinder.unlinkToDeath((IBinder.DeathRecipient) anyObject(), anyInt()))
|
when(mBinder.unlinkToDeath(any(IBinder.DeathRecipient.class), anyInt())).thenReturn(true);
|
||||||
.andReturn(true);
|
|
||||||
EasyMock.replay(mockBinder);
|
|
||||||
|
|
||||||
// Unregister request
|
// Unregister request
|
||||||
mService.unregisterUsageRequest(request);
|
mService.unregisterUsageRequest(request);
|
||||||
@@ -1018,7 +890,7 @@ public class NetworkStatsServiceTest {
|
|||||||
assertEquals(NetworkStatsManager.CALLBACK_RELEASED, latchedHandler.mLastMessageType);
|
assertEquals(NetworkStatsManager.CALLBACK_RELEASED, latchedHandler.mLastMessageType);
|
||||||
|
|
||||||
// Make sure that the caller binder gets disconnected
|
// Make sure that the caller binder gets disconnected
|
||||||
EasyMock.verify(mockBinder);
|
verify(mBinder).unlinkToDeath(any(IBinder.DeathRecipient.class), anyInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1078,33 +950,30 @@ public class NetworkStatsServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void expectSystemReady() throws Exception {
|
private void expectSystemReady() throws Exception {
|
||||||
mNetManager.setGlobalAlert(anyLong());
|
|
||||||
expectLastCall().atLeastOnce();
|
|
||||||
|
|
||||||
expectNetworkStatsSummary(buildEmptyStats());
|
expectNetworkStatsSummary(buildEmptyStats());
|
||||||
expectBandwidthControlCheck();
|
expectBandwidthControlCheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void expectNetworkState(NetworkState... state) throws Exception {
|
private void expectNetworkState(NetworkState... state) throws Exception {
|
||||||
expect(mConnManager.getAllNetworkState()).andReturn(state).atLeastOnce();
|
when(mConnManager.getAllNetworkState()).thenReturn(state);
|
||||||
|
|
||||||
final LinkProperties linkProp = state.length > 0 ? state[0].linkProperties : null;
|
final LinkProperties linkProp = state.length > 0 ? state[0].linkProperties : null;
|
||||||
expect(mConnManager.getActiveLinkProperties()).andReturn(linkProp).atLeastOnce();
|
when(mConnManager.getActiveLinkProperties()).thenReturn(linkProp);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void expectNetworkStatsSummary(NetworkStats summary) throws Exception {
|
private void expectNetworkStatsSummary(NetworkStats summary) throws Exception {
|
||||||
expect(mConnManager.getAllVpnInfo()).andReturn(new VpnInfo[0]).atLeastOnce();
|
when(mConnManager.getAllVpnInfo()).thenReturn(new VpnInfo[0]);
|
||||||
|
|
||||||
expectNetworkStatsSummaryDev(summary);
|
expectNetworkStatsSummaryDev(summary);
|
||||||
expectNetworkStatsSummaryXt(summary);
|
expectNetworkStatsSummaryXt(summary);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void expectNetworkStatsSummaryDev(NetworkStats summary) throws Exception {
|
private void expectNetworkStatsSummaryDev(NetworkStats summary) throws Exception {
|
||||||
expect(mNetManager.getNetworkStatsSummaryDev()).andReturn(summary).atLeastOnce();
|
when(mNetManager.getNetworkStatsSummaryDev()).thenReturn(summary);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void expectNetworkStatsSummaryXt(NetworkStats summary) throws Exception {
|
private void expectNetworkStatsSummaryXt(NetworkStats summary) throws Exception {
|
||||||
expect(mNetManager.getNetworkStatsSummaryXt()).andReturn(summary).atLeastOnce();
|
when(mNetManager.getNetworkStatsSummaryXt()).thenReturn(summary);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void expectNetworkStatsUidDetail(NetworkStats detail) throws Exception {
|
private void expectNetworkStatsUidDetail(NetworkStats detail) throws Exception {
|
||||||
@@ -1114,11 +983,10 @@ public class NetworkStatsServiceTest {
|
|||||||
private void expectNetworkStatsUidDetail(
|
private void expectNetworkStatsUidDetail(
|
||||||
NetworkStats detail, String[] tetherIfacePairs, NetworkStats tetherStats)
|
NetworkStats detail, String[] tetherIfacePairs, NetworkStats tetherStats)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
expect(mNetManager.getNetworkStatsUidDetail(eq(UID_ALL))).andReturn(detail).atLeastOnce();
|
when(mNetManager.getNetworkStatsUidDetail(UID_ALL)).thenReturn(detail);
|
||||||
|
|
||||||
// also include tethering details, since they are folded into UID
|
// also include tethering details, since they are folded into UID
|
||||||
expect(mNetManager.getNetworkStatsTethering())
|
when(mNetManager.getNetworkStatsTethering()).thenReturn(tetherStats);
|
||||||
.andReturn(tetherStats).atLeastOnce();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void expectDefaultSettings() throws Exception {
|
private void expectDefaultSettings() throws Exception {
|
||||||
@@ -1127,38 +995,33 @@ public class NetworkStatsServiceTest {
|
|||||||
|
|
||||||
private void expectSettings(long persistBytes, long bucketDuration, long deleteAge)
|
private void expectSettings(long persistBytes, long bucketDuration, long deleteAge)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
expect(mSettings.getPollInterval()).andReturn(HOUR_IN_MILLIS).anyTimes();
|
when(mSettings.getPollInterval()).thenReturn(HOUR_IN_MILLIS);
|
||||||
expect(mSettings.getTimeCacheMaxAge()).andReturn(DAY_IN_MILLIS).anyTimes();
|
when(mSettings.getTimeCacheMaxAge()).thenReturn(DAY_IN_MILLIS);
|
||||||
expect(mSettings.getSampleEnabled()).andReturn(true).anyTimes();
|
when(mSettings.getSampleEnabled()).thenReturn(true);
|
||||||
|
|
||||||
final Config config = new Config(bucketDuration, deleteAge, deleteAge);
|
final Config config = new Config(bucketDuration, deleteAge, deleteAge);
|
||||||
expect(mSettings.getDevConfig()).andReturn(config).anyTimes();
|
when(mSettings.getDevConfig()).thenReturn(config);
|
||||||
expect(mSettings.getXtConfig()).andReturn(config).anyTimes();
|
when(mSettings.getXtConfig()).thenReturn(config);
|
||||||
expect(mSettings.getUidConfig()).andReturn(config).anyTimes();
|
when(mSettings.getUidConfig()).thenReturn(config);
|
||||||
expect(mSettings.getUidTagConfig()).andReturn(config).anyTimes();
|
when(mSettings.getUidTagConfig()).thenReturn(config);
|
||||||
|
|
||||||
expect(mSettings.getGlobalAlertBytes(anyLong())).andReturn(MB_IN_BYTES).anyTimes();
|
when(mSettings.getGlobalAlertBytes(anyLong())).thenReturn(MB_IN_BYTES);
|
||||||
expect(mSettings.getDevPersistBytes(anyLong())).andReturn(MB_IN_BYTES).anyTimes();
|
when(mSettings.getDevPersistBytes(anyLong())).thenReturn(MB_IN_BYTES);
|
||||||
expect(mSettings.getXtPersistBytes(anyLong())).andReturn(MB_IN_BYTES).anyTimes();
|
when(mSettings.getXtPersistBytes(anyLong())).thenReturn(MB_IN_BYTES);
|
||||||
expect(mSettings.getUidPersistBytes(anyLong())).andReturn(MB_IN_BYTES).anyTimes();
|
when(mSettings.getUidPersistBytes(anyLong())).thenReturn(MB_IN_BYTES);
|
||||||
expect(mSettings.getUidTagPersistBytes(anyLong())).andReturn(MB_IN_BYTES).anyTimes();
|
when(mSettings.getUidTagPersistBytes(anyLong())).thenReturn(MB_IN_BYTES);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void expectCurrentTime() throws Exception {
|
private void expectCurrentTime() throws Exception {
|
||||||
expect(mTime.forceRefresh()).andReturn(false).anyTimes();
|
when(mTime.forceRefresh()).thenReturn(false);
|
||||||
expect(mTime.hasCache()).andReturn(true).anyTimes();
|
when(mTime.hasCache()).thenReturn(true);
|
||||||
expect(mTime.currentTimeMillis()).andReturn(currentTimeMillis()).anyTimes();
|
when(mTime.currentTimeMillis()).thenReturn(currentTimeMillis());
|
||||||
expect(mTime.getCacheAge()).andReturn(0L).anyTimes();
|
when(mTime.getCacheAge()).thenReturn(0L);
|
||||||
expect(mTime.getCacheCertainty()).andReturn(0L).anyTimes();
|
when(mTime.getCacheCertainty()).thenReturn(0L);
|
||||||
}
|
|
||||||
|
|
||||||
private void expectNetworkStatsPoll() throws Exception {
|
|
||||||
mNetManager.setGlobalAlert(anyLong());
|
|
||||||
expectLastCall().anyTimes();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void expectBandwidthControlCheck() throws Exception {
|
private void expectBandwidthControlCheck() throws Exception {
|
||||||
expect(mNetManager.isBandwidthControlEnabled()).andReturn(true).atLeastOnce();
|
when(mNetManager.isBandwidthControlEnabled()).thenReturn(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertStatsFilesExist(boolean exist) {
|
private void assertStatsFilesExist(boolean exist) {
|
||||||
@@ -1269,15 +1132,6 @@ public class NetworkStatsServiceTest {
|
|||||||
mElapsedRealtime += duration;
|
mElapsedRealtime += duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void replay() {
|
|
||||||
EasyMock.replay(mNetManager, mTime, mSettings, mConnManager);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void verifyAndReset() {
|
|
||||||
EasyMock.verify(mNetManager, mTime, mSettings, mConnManager);
|
|
||||||
EasyMock.reset(mNetManager, mTime, mSettings, mConnManager);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void forcePollAndWaitForIdle() {
|
private void forcePollAndWaitForIdle() {
|
||||||
mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL));
|
mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL));
|
||||||
// Send dummy message to make sure that any previous message has been handled
|
// Send dummy message to make sure that any previous message has been handled
|
||||||
|
|||||||
Reference in New Issue
Block a user