Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e9c15cac authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Android Git Automerger
Browse files

am 084c71eb: am 8c58677e: Merge "Fix network stats and policy tests." into jb-dev

* commit '084c71eb':
  Fix network stats and policy tests.
parents 235554e8 084c71eb
Loading
Loading
Loading
Loading
+13 −0
Original line number Original line Diff line number Diff line
@@ -37,6 +37,7 @@ 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_LIMIT_SNOOZED;
import static com.android.server.net.NetworkPolicyManagerService.TYPE_WARNING;
import static com.android.server.net.NetworkPolicyManagerService.TYPE_WARNING;
import static org.easymock.EasyMock.anyInt;
import static org.easymock.EasyMock.anyInt;
import static org.easymock.EasyMock.anyLong;
import static org.easymock.EasyMock.aryEq;
import static org.easymock.EasyMock.aryEq;
import static org.easymock.EasyMock.capture;
import static org.easymock.EasyMock.capture;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.createMock;
@@ -229,6 +230,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {


        // expect to answer screen status during systemReady()
        // expect to answer screen status during systemReady()
        expect(mPowerManager.isScreenOn()).andReturn(true).atLeastOnce();
        expect(mPowerManager.isScreenOn()).andReturn(true).atLeastOnce();
        expect(mNetworkManager.isBandwidthControlEnabled()).andReturn(true).atLeastOnce();
        expectCurrentTime();
        expectCurrentTime();


        replay();
        replay();
@@ -613,6 +615,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
        expect(mConnManager.getAllNetworkState()).andReturn(state).atLeastOnce();
        expect(mConnManager.getAllNetworkState()).andReturn(state).atLeastOnce();
        expectCurrentTime();
        expectCurrentTime();
        expectClearNotifications();
        expectClearNotifications();
        expectAdvisePersistThreshold();
        future = expectMeteredIfacesChanged();
        future = expectMeteredIfacesChanged();


        replay();
        replay();
@@ -637,6 +640,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
        expectSetInterfaceQuota(TEST_IFACE, (2 * MB_IN_BYTES) - 512);
        expectSetInterfaceQuota(TEST_IFACE, (2 * MB_IN_BYTES) - 512);


        expectClearNotifications();
        expectClearNotifications();
        expectAdvisePersistThreshold();
        future = expectMeteredIfacesChanged(TEST_IFACE);
        future = expectMeteredIfacesChanged(TEST_IFACE);


        replay();
        replay();
@@ -704,6 +708,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
            expectPolicyDataEnable(TYPE_WIFI, true);
            expectPolicyDataEnable(TYPE_WIFI, true);


            expectClearNotifications();
            expectClearNotifications();
            expectAdvisePersistThreshold();
            future = expectMeteredIfacesChanged();
            future = expectMeteredIfacesChanged();


            replay();
            replay();
@@ -730,6 +735,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
            expectSetInterfaceQuota(TEST_IFACE, 2 * MB_IN_BYTES);
            expectSetInterfaceQuota(TEST_IFACE, 2 * MB_IN_BYTES);


            expectClearNotifications();
            expectClearNotifications();
            expectAdvisePersistThreshold();
            future = expectMeteredIfacesChanged(TEST_IFACE);
            future = expectMeteredIfacesChanged(TEST_IFACE);


            replay();
            replay();
@@ -794,6 +800,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
            // still restricted.
            // still restricted.
            expectRemoveInterfaceQuota(TEST_IFACE);
            expectRemoveInterfaceQuota(TEST_IFACE);
            expectSetInterfaceQuota(TEST_IFACE, Long.MAX_VALUE);
            expectSetInterfaceQuota(TEST_IFACE, Long.MAX_VALUE);
            expectAdvisePersistThreshold();
            expectMeteredIfacesChanged(TEST_IFACE);
            expectMeteredIfacesChanged(TEST_IFACE);


            future = expectClearNotifications();
            future = expectClearNotifications();
@@ -835,6 +842,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
            expectSetInterfaceQuota(TEST_IFACE, Long.MAX_VALUE);
            expectSetInterfaceQuota(TEST_IFACE, Long.MAX_VALUE);


            expectClearNotifications();
            expectClearNotifications();
            expectAdvisePersistThreshold();
            future = expectMeteredIfacesChanged(TEST_IFACE);
            future = expectMeteredIfacesChanged(TEST_IFACE);


            replay();
            replay();
@@ -943,6 +951,11 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
        return future;
        return future;
    }
    }


    private void expectAdvisePersistThreshold() throws Exception {
        mStatsService.advisePersistThreshold(anyLong());
        expectLastCall().anyTimes();
    }

    private static class TestAbstractFuture<T> extends AbstractFuture<T> {
    private static class TestAbstractFuture<T> extends AbstractFuture<T> {
        @Override
        @Override
        public T get() throws InterruptedException, ExecutionException {
        public T get() throws InterruptedException, ExecutionException {
+6 −6
Original line number Original line Diff line number Diff line
@@ -56,7 +56,7 @@ public class NetworkStatsCollectionTest extends AndroidTestCase {


        // verify that history read correctly
        // verify that history read correctly
        assertSummaryTotal(collection, buildTemplateMobileAll(TEST_IMSI),
        assertSummaryTotal(collection, buildTemplateMobileAll(TEST_IMSI),
                636014522L, 709291L, 88037144L, 518820L);
                636016770L, 709306L, 88038768L, 518836L);


        // now export into a unified format
        // now export into a unified format
        final ByteArrayOutputStream bos = new ByteArrayOutputStream();
        final ByteArrayOutputStream bos = new ByteArrayOutputStream();
@@ -70,7 +70,7 @@ public class NetworkStatsCollectionTest extends AndroidTestCase {
        // and read back into structure, verifying that totals are same
        // and read back into structure, verifying that totals are same
        collection.read(new ByteArrayInputStream(bos.toByteArray()));
        collection.read(new ByteArrayInputStream(bos.toByteArray()));
        assertSummaryTotal(collection, buildTemplateMobileAll(TEST_IMSI),
        assertSummaryTotal(collection, buildTemplateMobileAll(TEST_IMSI),
                636014522L, 709291L, 88037144L, 518820L);
                636016770L, 709306L, 88038768L, 518836L);
    }
    }


    public void testReadLegacyUid() throws Exception {
    public void testReadLegacyUid() throws Exception {
@@ -82,7 +82,7 @@ public class NetworkStatsCollectionTest extends AndroidTestCase {


        // verify that history read correctly
        // verify that history read correctly
        assertSummaryTotal(collection, buildTemplateMobileAll(TEST_IMSI),
        assertSummaryTotal(collection, buildTemplateMobileAll(TEST_IMSI),
                637073904L, 711398L, 88342093L, 521006L);
                637076152L, 711413L, 88343717L, 521022L);


        // now export into a unified format
        // now export into a unified format
        final ByteArrayOutputStream bos = new ByteArrayOutputStream();
        final ByteArrayOutputStream bos = new ByteArrayOutputStream();
@@ -96,7 +96,7 @@ public class NetworkStatsCollectionTest extends AndroidTestCase {
        // and read back into structure, verifying that totals are same
        // and read back into structure, verifying that totals are same
        collection.read(new ByteArrayInputStream(bos.toByteArray()));
        collection.read(new ByteArrayInputStream(bos.toByteArray()));
        assertSummaryTotal(collection, buildTemplateMobileAll(TEST_IMSI),
        assertSummaryTotal(collection, buildTemplateMobileAll(TEST_IMSI),
                637073904L, 711398L, 88342093L, 521006L);
                637076152L, 711413L, 88343717L, 521022L);
    }
    }


    public void testReadLegacyUidTags() throws Exception {
    public void testReadLegacyUidTags() throws Exception {