Make constants static import
Bug: 238843364 Test: FrameworksNetTests Change-Id: Id88bcc175db0a599dd3205812b1bce78012e2216
This commit is contained in:
@@ -16,7 +16,16 @@
|
|||||||
|
|
||||||
package android.app.usage;
|
package android.app.usage;
|
||||||
|
|
||||||
|
import static android.net.ConnectivityManager.TYPE_MOBILE;
|
||||||
|
import static android.net.ConnectivityManager.TYPE_WIFI;
|
||||||
|
import static android.net.NetworkStats.DEFAULT_NETWORK_NO;
|
||||||
|
import static android.net.NetworkStats.METERED_NO;
|
||||||
import static android.net.NetworkStats.METERED_YES;
|
import static android.net.NetworkStats.METERED_YES;
|
||||||
|
import static android.net.NetworkStats.ROAMING_NO;
|
||||||
|
import static android.net.NetworkStats.SET_ALL;
|
||||||
|
import static android.net.NetworkStats.SET_DEFAULT;
|
||||||
|
import static android.net.NetworkStats.TAG_NONE;
|
||||||
|
import static android.net.NetworkStatsHistory.FIELD_ALL;
|
||||||
import static android.net.NetworkTemplate.MATCH_MOBILE;
|
import static android.net.NetworkTemplate.MATCH_MOBILE;
|
||||||
import static android.net.NetworkTemplate.MATCH_WIFI;
|
import static android.net.NetworkTemplate.MATCH_WIFI;
|
||||||
|
|
||||||
@@ -34,7 +43,6 @@ import static org.mockito.Mockito.times;
|
|||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.net.ConnectivityManager;
|
|
||||||
import android.net.INetworkStatsService;
|
import android.net.INetworkStatsService;
|
||||||
import android.net.INetworkStatsSession;
|
import android.net.INetworkStatsSession;
|
||||||
import android.net.NetworkStats.Entry;
|
import android.net.NetworkStats.Entry;
|
||||||
@@ -86,31 +94,17 @@ public class NetworkStatsManagerTest {
|
|||||||
final int uid2 = 10002;
|
final int uid2 = 10002;
|
||||||
final int uid3 = 10003;
|
final int uid3 = 10003;
|
||||||
|
|
||||||
Entry uid1Entry1 = new Entry("if1", uid1,
|
Entry uid1Entry1 = new Entry("if1", uid1, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
|
||||||
android.net.NetworkStats.SET_DEFAULT, android.net.NetworkStats.TAG_NONE,
|
DEFAULT_NETWORK_NO, 100, 10, 200, 20, 0);
|
||||||
android.net.NetworkStats.METERED_NO, android.net.NetworkStats.ROAMING_NO,
|
|
||||||
android.net.NetworkStats.DEFAULT_NETWORK_NO,
|
|
||||||
100, 10, 200, 20, 0);
|
|
||||||
|
|
||||||
Entry uid1Entry2 = new Entry(
|
Entry uid1Entry2 = new Entry("if2", uid1, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
|
||||||
"if2", uid1,
|
DEFAULT_NETWORK_NO, 100, 10, 200, 20, 0);
|
||||||
android.net.NetworkStats.SET_DEFAULT, android.net.NetworkStats.TAG_NONE,
|
|
||||||
android.net.NetworkStats.METERED_NO, android.net.NetworkStats.ROAMING_NO,
|
|
||||||
android.net.NetworkStats.DEFAULT_NETWORK_NO,
|
|
||||||
100, 10, 200, 20, 0);
|
|
||||||
|
|
||||||
Entry uid2Entry1 = new Entry("if1", uid2,
|
Entry uid2Entry1 = new Entry("if1", uid2, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
|
||||||
android.net.NetworkStats.SET_DEFAULT, android.net.NetworkStats.TAG_NONE,
|
DEFAULT_NETWORK_NO, 150, 10, 250, 20, 0);
|
||||||
android.net.NetworkStats.METERED_NO, android.net.NetworkStats.ROAMING_NO,
|
|
||||||
android.net.NetworkStats.DEFAULT_NETWORK_NO,
|
|
||||||
150, 10, 250, 20, 0);
|
|
||||||
|
|
||||||
Entry uid2Entry2 = new Entry(
|
Entry uid2Entry2 = new Entry("if2", uid2, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
|
||||||
"if2", uid2,
|
DEFAULT_NETWORK_NO, 150, 10, 250, 20, 0);
|
||||||
android.net.NetworkStats.SET_DEFAULT, android.net.NetworkStats.TAG_NONE,
|
|
||||||
android.net.NetworkStats.METERED_NO, android.net.NetworkStats.ROAMING_NO,
|
|
||||||
android.net.NetworkStats.DEFAULT_NETWORK_NO,
|
|
||||||
150, 10, 250, 20, 0);
|
|
||||||
|
|
||||||
NetworkStatsHistory history1 = new NetworkStatsHistory(10, 2);
|
NetworkStatsHistory history1 = new NetworkStatsHistory(10, 2);
|
||||||
history1.recordData(10, 20, uid1Entry1);
|
history1.recordData(10, 20, uid1Entry1);
|
||||||
@@ -125,9 +119,8 @@ public class NetworkStatsManagerTest {
|
|||||||
when(mStatsSession.getRelevantUids()).thenReturn(new int[] { uid1, uid2, uid3 });
|
when(mStatsSession.getRelevantUids()).thenReturn(new int[] { uid1, uid2, uid3 });
|
||||||
|
|
||||||
when(mStatsSession.getHistoryIntervalForUid(any(NetworkTemplate.class),
|
when(mStatsSession.getHistoryIntervalForUid(any(NetworkTemplate.class),
|
||||||
eq(uid1), eq(android.net.NetworkStats.SET_ALL),
|
eq(uid1), eq(SET_ALL), eq(TAG_NONE),
|
||||||
eq(android.net.NetworkStats.TAG_NONE),
|
eq(FIELD_ALL), eq(startTime), eq(endTime)))
|
||||||
eq(NetworkStatsHistory.FIELD_ALL), eq(startTime), eq(endTime)))
|
|
||||||
.then((InvocationOnMock inv) -> {
|
.then((InvocationOnMock inv) -> {
|
||||||
NetworkTemplate template = inv.getArgument(0);
|
NetworkTemplate template = inv.getArgument(0);
|
||||||
assertEquals(MATCH_MOBILE_ALL, template.getMatchRule());
|
assertEquals(MATCH_MOBILE_ALL, template.getMatchRule());
|
||||||
@@ -136,9 +129,8 @@ public class NetworkStatsManagerTest {
|
|||||||
});
|
});
|
||||||
|
|
||||||
when(mStatsSession.getHistoryIntervalForUid(any(NetworkTemplate.class),
|
when(mStatsSession.getHistoryIntervalForUid(any(NetworkTemplate.class),
|
||||||
eq(uid2), eq(android.net.NetworkStats.SET_ALL),
|
eq(uid2), eq(SET_ALL), eq(TAG_NONE),
|
||||||
eq(android.net.NetworkStats.TAG_NONE),
|
eq(FIELD_ALL), eq(startTime), eq(endTime)))
|
||||||
eq(NetworkStatsHistory.FIELD_ALL), eq(startTime), eq(endTime)))
|
|
||||||
.then((InvocationOnMock inv) -> {
|
.then((InvocationOnMock inv) -> {
|
||||||
NetworkTemplate template = inv.getArgument(0);
|
NetworkTemplate template = inv.getArgument(0);
|
||||||
assertEquals(MATCH_MOBILE_ALL, template.getMatchRule());
|
assertEquals(MATCH_MOBILE_ALL, template.getMatchRule());
|
||||||
@@ -148,7 +140,7 @@ public class NetworkStatsManagerTest {
|
|||||||
|
|
||||||
|
|
||||||
NetworkStats stats = mManager.queryDetails(
|
NetworkStats stats = mManager.queryDetails(
|
||||||
ConnectivityManager.TYPE_MOBILE, TEST_SUBSCRIBER_ID, startTime, endTime);
|
TYPE_MOBILE, TEST_SUBSCRIBER_ID, startTime, endTime);
|
||||||
|
|
||||||
NetworkStats.Bucket bucket = new NetworkStats.Bucket();
|
NetworkStats.Bucket bucket = new NetworkStats.Bucket();
|
||||||
|
|
||||||
@@ -202,35 +194,34 @@ public class NetworkStatsManagerTest {
|
|||||||
|
|
||||||
verify(mStatsSession, times(1)).getHistoryIntervalForUid(
|
verify(mStatsSession, times(1)).getHistoryIntervalForUid(
|
||||||
eq(expectedTemplate),
|
eq(expectedTemplate),
|
||||||
eq(uid1), eq(android.net.NetworkStats.SET_ALL),
|
eq(uid1), eq(SET_ALL),
|
||||||
eq(android.net.NetworkStats.TAG_NONE),
|
eq(TAG_NONE),
|
||||||
eq(NetworkStatsHistory.FIELD_ALL), eq(startTime), eq(endTime));
|
eq(FIELD_ALL), eq(startTime), eq(endTime));
|
||||||
|
|
||||||
verify(mStatsSession, times(1)).getHistoryIntervalForUid(
|
verify(mStatsSession, times(1)).getHistoryIntervalForUid(
|
||||||
eq(expectedTemplate),
|
eq(expectedTemplate),
|
||||||
eq(uid2), eq(android.net.NetworkStats.SET_ALL),
|
eq(uid2), eq(SET_ALL),
|
||||||
eq(android.net.NetworkStats.TAG_NONE),
|
eq(TAG_NONE),
|
||||||
eq(NetworkStatsHistory.FIELD_ALL), eq(startTime), eq(endTime));
|
eq(FIELD_ALL), eq(startTime), eq(endTime));
|
||||||
|
|
||||||
assertFalse(stats.hasNextBucket());
|
assertFalse(stats.hasNextBucket());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNetworkTemplateWhenRunningQueryDetails_NoSubscriberId() throws RemoteException {
|
public void testNetworkTemplateWhenRunningQueryDetails_NoSubscriberId() throws RemoteException {
|
||||||
runQueryDetailsAndCheckTemplate(ConnectivityManager.TYPE_MOBILE,
|
runQueryDetailsAndCheckTemplate(TYPE_MOBILE, null /* subscriberId */,
|
||||||
null /* subscriberId */, new NetworkTemplate.Builder(MATCH_MOBILE)
|
new NetworkTemplate.Builder(MATCH_MOBILE).setMeteredness(METERED_YES).build());
|
||||||
.setMeteredness(METERED_YES).build());
|
runQueryDetailsAndCheckTemplate(TYPE_WIFI, "" /* subscriberId */,
|
||||||
runQueryDetailsAndCheckTemplate(ConnectivityManager.TYPE_WIFI,
|
new NetworkTemplate.Builder(MATCH_WIFI).build());
|
||||||
"" /* subscriberId */, new NetworkTemplate.Builder(MATCH_WIFI).build());
|
runQueryDetailsAndCheckTemplate(TYPE_WIFI, null /* subscriberId */,
|
||||||
runQueryDetailsAndCheckTemplate(ConnectivityManager.TYPE_WIFI,
|
new NetworkTemplate.Builder(MATCH_WIFI).build());
|
||||||
null /* subscriberId */, new NetworkTemplate.Builder(MATCH_WIFI).build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNetworkTemplateWhenRunningQueryDetails_MergedCarrierWifi()
|
public void testNetworkTemplateWhenRunningQueryDetails_MergedCarrierWifi()
|
||||||
throws RemoteException {
|
throws RemoteException {
|
||||||
runQueryDetailsAndCheckTemplate(ConnectivityManager.TYPE_WIFI,
|
runQueryDetailsAndCheckTemplate(TYPE_WIFI, TEST_SUBSCRIBER_ID,
|
||||||
TEST_SUBSCRIBER_ID, new NetworkTemplate.Builder(MATCH_WIFI)
|
new NetworkTemplate.Builder(MATCH_WIFI)
|
||||||
.setSubscriberIds(Set.of(TEST_SUBSCRIBER_ID)).build());
|
.setSubscriberIds(Set.of(TEST_SUBSCRIBER_ID)).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,7 +235,7 @@ public class NetworkStatsManagerTest {
|
|||||||
when(mStatsSession.getTaggedSummaryForAllUid(any(NetworkTemplate.class),
|
when(mStatsSession.getTaggedSummaryForAllUid(any(NetworkTemplate.class),
|
||||||
anyLong(), anyLong()))
|
anyLong(), anyLong()))
|
||||||
.thenReturn(new android.net.NetworkStats(0, 0));
|
.thenReturn(new android.net.NetworkStats(0, 0));
|
||||||
final NetworkTemplate template = new NetworkTemplate.Builder(NetworkTemplate.MATCH_MOBILE)
|
final NetworkTemplate template = new NetworkTemplate.Builder(MATCH_MOBILE)
|
||||||
.setMeteredness(NetworkStats.Bucket.METERED_YES).build();
|
.setMeteredness(NetworkStats.Bucket.METERED_YES).build();
|
||||||
NetworkStats stats = mManager.queryTaggedSummary(template, startTime, endTime);
|
NetworkStats stats = mManager.queryTaggedSummary(template, startTime, endTime);
|
||||||
|
|
||||||
@@ -265,12 +256,12 @@ public class NetworkStatsManagerTest {
|
|||||||
when(mStatsSession.getHistoryIntervalForNetwork(any(NetworkTemplate.class),
|
when(mStatsSession.getHistoryIntervalForNetwork(any(NetworkTemplate.class),
|
||||||
anyInt(), anyLong(), anyLong()))
|
anyInt(), anyLong(), anyLong()))
|
||||||
.thenReturn(new NetworkStatsHistory(10, 0));
|
.thenReturn(new NetworkStatsHistory(10, 0));
|
||||||
final NetworkTemplate template = new NetworkTemplate.Builder(NetworkTemplate.MATCH_MOBILE)
|
final NetworkTemplate template = new NetworkTemplate.Builder(MATCH_MOBILE)
|
||||||
.setMeteredness(NetworkStats.Bucket.METERED_YES).build();
|
.setMeteredness(NetworkStats.Bucket.METERED_YES).build();
|
||||||
NetworkStats stats = mManager.queryDetailsForDevice(template, startTime, endTime);
|
NetworkStats stats = mManager.queryDetailsForDevice(template, startTime, endTime);
|
||||||
|
|
||||||
verify(mStatsSession, times(1)).getHistoryIntervalForNetwork(
|
verify(mStatsSession, times(1)).getHistoryIntervalForNetwork(
|
||||||
eq(template), eq(NetworkStatsHistory.FIELD_ALL), eq(startTime), eq(endTime));
|
eq(template), eq(FIELD_ALL), eq(startTime), eq(endTime));
|
||||||
|
|
||||||
assertFalse(stats.hasNextBucket());
|
assertFalse(stats.hasNextBucket());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user