Support metered Wi-Fi NetworkPolicy. am: 2d9e5a5f9e
Original change: undetermined Change-Id: Ie42f3a9978ff0e872014efbe0f9e4e6e0e76fd61
This commit is contained in:
@@ -20,6 +20,7 @@ import static com.android.internal.util.Preconditions.checkNotNull;
|
|||||||
|
|
||||||
import android.annotation.SdkConstant;
|
import android.annotation.SdkConstant;
|
||||||
import android.annotation.SdkConstant.SdkConstantType;
|
import android.annotation.SdkConstant.SdkConstantType;
|
||||||
|
import android.content.Context;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.Build.VERSION_CODES;
|
import android.os.Build.VERSION_CODES;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
@@ -610,6 +611,11 @@ public class ConnectivityManager {
|
|||||||
mService = checkNotNull(service, "missing IConnectivityManager");
|
mService = checkNotNull(service, "missing IConnectivityManager");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@hide} */
|
||||||
|
public static ConnectivityManager from(Context context) {
|
||||||
|
return (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@hide}
|
* {@hide}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.internal.net;
|
package com.android.internal.net;
|
||||||
|
|
||||||
|
import static android.net.NetworkStats.SET_ALL;
|
||||||
import static android.net.NetworkStats.SET_DEFAULT;
|
import static android.net.NetworkStats.SET_DEFAULT;
|
||||||
import static android.net.NetworkStats.SET_FOREGROUND;
|
import static android.net.NetworkStats.SET_FOREGROUND;
|
||||||
import static android.net.NetworkStats.TAG_NONE;
|
import static android.net.NetworkStats.TAG_NONE;
|
||||||
@@ -84,12 +85,12 @@ public class NetworkStatsFactoryTest extends AndroidTestCase {
|
|||||||
|
|
||||||
final NetworkStats stats = mFactory.readNetworkStatsSummary();
|
final NetworkStats stats = mFactory.readNetworkStatsSummary();
|
||||||
assertEquals(6, stats.size());
|
assertEquals(6, stats.size());
|
||||||
assertStatsEntry(stats, "lo", UID_ALL, SET_DEFAULT, TAG_NONE, 8308L, 8308L);
|
assertStatsEntry(stats, "lo", UID_ALL, SET_ALL, TAG_NONE, 8308L, 8308L);
|
||||||
assertStatsEntry(stats, "rmnet0", UID_ALL, SET_DEFAULT, TAG_NONE, 1507570L, 489339L);
|
assertStatsEntry(stats, "rmnet0", UID_ALL, SET_ALL, TAG_NONE, 1507570L, 489339L);
|
||||||
assertStatsEntry(stats, "ifb0", UID_ALL, SET_DEFAULT, TAG_NONE, 52454L, 0L);
|
assertStatsEntry(stats, "ifb0", UID_ALL, SET_ALL, TAG_NONE, 52454L, 0L);
|
||||||
assertStatsEntry(stats, "ifb1", UID_ALL, SET_DEFAULT, TAG_NONE, 52454L, 0L);
|
assertStatsEntry(stats, "ifb1", UID_ALL, SET_ALL, TAG_NONE, 52454L, 0L);
|
||||||
assertStatsEntry(stats, "sit0", UID_ALL, SET_DEFAULT, TAG_NONE, 0L, 0L);
|
assertStatsEntry(stats, "sit0", UID_ALL, SET_ALL, TAG_NONE, 0L, 0L);
|
||||||
assertStatsEntry(stats, "ip6tnl0", UID_ALL, SET_DEFAULT, TAG_NONE, 0L, 0L);
|
assertStatsEntry(stats, "ip6tnl0", UID_ALL, SET_ALL, TAG_NONE, 0L, 0L);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNetworkStatsSummaryDown() throws Exception {
|
public void testNetworkStatsSummaryDown() throws Exception {
|
||||||
@@ -102,8 +103,8 @@ public class NetworkStatsFactoryTest extends AndroidTestCase {
|
|||||||
|
|
||||||
final NetworkStats stats = mFactory.readNetworkStatsSummary();
|
final NetworkStats stats = mFactory.readNetworkStatsSummary();
|
||||||
assertEquals(7, stats.size());
|
assertEquals(7, stats.size());
|
||||||
assertStatsEntry(stats, "rmnet0", UID_ALL, SET_DEFAULT, TAG_NONE, 1507570L, 489339L);
|
assertStatsEntry(stats, "rmnet0", UID_ALL, SET_ALL, TAG_NONE, 1507570L, 489339L);
|
||||||
assertStatsEntry(stats, "wlan0", UID_ALL, SET_DEFAULT, TAG_NONE, 1024L, 2048L);
|
assertStatsEntry(stats, "wlan0", UID_ALL, SET_ALL, TAG_NONE, 1024L, 2048L);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNetworkStatsCombined() throws Exception {
|
public void testNetworkStatsCombined() throws Exception {
|
||||||
@@ -115,7 +116,7 @@ public class NetworkStatsFactoryTest extends AndroidTestCase {
|
|||||||
stageLong(40L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/tx_packets"));
|
stageLong(40L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/tx_packets"));
|
||||||
|
|
||||||
final NetworkStats stats = mFactory.readNetworkStatsSummary();
|
final NetworkStats stats = mFactory.readNetworkStatsSummary();
|
||||||
assertStatsEntry(stats, "rmnet0", UID_ALL, SET_DEFAULT, TAG_NONE, 1507570L + 10L,
|
assertStatsEntry(stats, "rmnet0", UID_ALL, SET_ALL, TAG_NONE, 1507570L + 10L,
|
||||||
2205L + 20L, 489339L + 30L, 2237L + 40L);
|
2205L + 20L, 489339L + 30L, 2237L + 40L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +129,7 @@ public class NetworkStatsFactoryTest extends AndroidTestCase {
|
|||||||
stageLong(40L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/tx_packets"));
|
stageLong(40L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/tx_packets"));
|
||||||
|
|
||||||
final NetworkStats stats = mFactory.readNetworkStatsSummary();
|
final NetworkStats stats = mFactory.readNetworkStatsSummary();
|
||||||
assertStatsEntry(stats, "rmnet0", UID_ALL, SET_DEFAULT, TAG_NONE, 10L, 20L, 30L, 40L);
|
assertStatsEntry(stats, "rmnet0", UID_ALL, SET_ALL, TAG_NONE, 10L, 20L, 30L, 40L);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKernelTags() throws Exception {
|
public void testKernelTags() throws Exception {
|
||||||
@@ -153,9 +154,9 @@ public class NetworkStatsFactoryTest extends AndroidTestCase {
|
|||||||
|
|
||||||
final NetworkStats stats = mFactory.readNetworkStatsSummary();
|
final NetworkStats stats = mFactory.readNetworkStatsSummary();
|
||||||
assertEquals(6, stats.size());
|
assertEquals(6, stats.size());
|
||||||
assertStatsEntry(stats, "rmnet0", UID_ALL, SET_DEFAULT, TAG_NONE, 2112L, 24L, 700L, 10L);
|
assertStatsEntry(stats, "rmnet0", UID_ALL, SET_ALL, TAG_NONE, 2112L, 24L, 700L, 10L);
|
||||||
assertStatsEntry(stats, "test1", UID_ALL, SET_DEFAULT, TAG_NONE, 6L, 8L, 10L, 12L);
|
assertStatsEntry(stats, "test1", UID_ALL, SET_ALL, TAG_NONE, 6L, 8L, 10L, 12L);
|
||||||
assertStatsEntry(stats, "test2", UID_ALL, SET_DEFAULT, TAG_NONE, 1L, 2L, 3L, 4L);
|
assertStatsEntry(stats, "test2", UID_ALL, SET_ALL, TAG_NONE, 1L, 2L, 3L, 4L);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ import libcore.io.IoUtils;
|
|||||||
*/
|
*/
|
||||||
@LargeTest
|
@LargeTest
|
||||||
public class NetworkStatsServiceTest extends AndroidTestCase {
|
public class NetworkStatsServiceTest extends AndroidTestCase {
|
||||||
private static final String TAG = "NetworkStatsServiceTest";
|
private static final String TAG = "NetworkStatsServiceTest";
|
||||||
|
|
||||||
private static final String TEST_IFACE = "test0";
|
private static final String TEST_IFACE = "test0";
|
||||||
private static final String TEST_IFACE2 = "test1";
|
private static final String TEST_IFACE2 = "test1";
|
||||||
|
|||||||
@@ -20,8 +20,6 @@ import static android.net.NetworkTemplate.buildTemplateMobileAll;
|
|||||||
import static android.text.format.DateUtils.MINUTE_IN_MILLIS;
|
import static android.text.format.DateUtils.MINUTE_IN_MILLIS;
|
||||||
|
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.net.ConnectivityManager;
|
|
||||||
import android.net.NetworkIdentity;
|
|
||||||
import android.net.NetworkStats;
|
import android.net.NetworkStats;
|
||||||
import android.net.NetworkTemplate;
|
import android.net.NetworkTemplate;
|
||||||
import android.test.AndroidTestCase;
|
import android.test.AndroidTestCase;
|
||||||
@@ -145,12 +143,6 @@ public class NetworkStatsCollectionTest extends AndroidTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NetworkIdentitySet buildWifiIdent() {
|
|
||||||
final NetworkIdentitySet set = new NetworkIdentitySet();
|
|
||||||
set.add(new NetworkIdentity(ConnectivityManager.TYPE_WIFI, 0, null, false));
|
|
||||||
return set;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void assertSummaryTotal(NetworkStatsCollection collection,
|
private static void assertSummaryTotal(NetworkStatsCollection collection,
|
||||||
NetworkTemplate template, long rxBytes, long rxPackets, long txBytes, long txPackets) {
|
NetworkTemplate template, long rxBytes, long rxPackets, long txBytes, long txPackets) {
|
||||||
final NetworkStats.Entry entry = collection.getSummary(
|
final NetworkStats.Entry entry = collection.getSummary(
|
||||||
|
|||||||
Reference in New Issue
Block a user