diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java index 11d338d05c..166342dd4e 100644 --- a/core/java/android/net/ConnectivityManager.java +++ b/core/java/android/net/ConnectivityManager.java @@ -3763,4 +3763,20 @@ public class ConnectivityManager { throw e.rethrowFromSystemServer(); } } + + /** + * The network watchlist is a list of domains and IP addresses that are associated with + * potentially harmful apps. This method returns the hash of the watchlist currently + * used by the system. + * + * @return Hash of network watchlist config file. Null if config does not exist. + */ + public byte[] getNetworkWatchlistConfigHash() { + try { + return mService.getNetworkWatchlistConfigHash(); + } catch (RemoteException e) { + Log.e(TAG, "Unable to get watchlist config hash"); + throw e.rethrowFromSystemServer(); + } + } } diff --git a/core/java/android/net/IConnectivityManager.aidl b/core/java/android/net/IConnectivityManager.aidl index a6fe7389bc..ce95b60dd2 100644 --- a/core/java/android/net/IConnectivityManager.aidl +++ b/core/java/android/net/IConnectivityManager.aidl @@ -180,4 +180,6 @@ interface IConnectivityManager void stopKeepalive(in Network network, int slot); String getCaptivePortalServerUrl(); + + byte[] getNetworkWatchlistConfigHash(); } diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index c1f4b789e0..5030dce7cb 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -69,6 +69,7 @@ import android.net.NetworkRequest; import android.net.NetworkSpecifier; import android.net.NetworkState; import android.net.NetworkUtils; +import android.net.NetworkWatchlistManager; import android.net.Proxy; import android.net.ProxyInfo; import android.net.RouteInfo; @@ -5708,6 +5709,17 @@ public class ConnectivityService extends IConnectivityManager.Stub Settings.Global.NETWORK_AVOID_BAD_WIFI, null); } + @Override + public byte[] getNetworkWatchlistConfigHash() { + NetworkWatchlistManager nwm = mContext.getSystemService(NetworkWatchlistManager.class); + if (nwm == null) { + loge("Unable to get NetworkWatchlistManager"); + return null; + } + // Redirect it to network watchlist service to access watchlist file and calculate hash. + return nwm.getWatchlistConfigHash(); + } + @VisibleForTesting public NetworkMonitor createNetworkMonitor(Context context, Handler handler, NetworkAgentInfo nai, NetworkRequest defaultRequest) { diff --git a/tests/net/java/com/android/internal/net/NetworkStatsFactoryTest.java b/tests/net/java/com/android/internal/net/NetworkStatsFactoryTest.java index 56b8e608da..b14f5509b7 100644 --- a/tests/net/java/com/android/internal/net/NetworkStatsFactoryTest.java +++ b/tests/net/java/com/android/internal/net/NetworkStatsFactoryTest.java @@ -67,7 +67,7 @@ public class NetworkStatsFactoryTest { IoUtils.deleteContents(mTestProc); } - mFactory = new NetworkStatsFactory(mTestProc); + mFactory = new NetworkStatsFactory(mTestProc, false); } @After @@ -115,6 +115,20 @@ public class NetworkStatsFactoryTest { assertStatsEntry(stats, "rmnet1", 10021, SET_FOREGROUND, 0x30100000, 742L, 3L, 1265L, 3L); } + @Test + public void testNetworkStatsSummary() throws Exception { + stageFile(R.raw.net_dev_typical, file("net/dev")); + + final NetworkStats stats = mFactory.readNetworkStatsIfaceDev(); + assertEquals(6, stats.size()); + assertStatsEntry(stats, "lo", UID_ALL, SET_ALL, TAG_NONE, 8308L, 8308L); + assertStatsEntry(stats, "rmnet0", UID_ALL, SET_ALL, TAG_NONE, 1507570L, 489339L); + assertStatsEntry(stats, "ifb0", UID_ALL, SET_ALL, TAG_NONE, 52454L, 0L); + assertStatsEntry(stats, "ifb1", UID_ALL, SET_ALL, TAG_NONE, 52454L, 0L); + assertStatsEntry(stats, "sit0", UID_ALL, SET_ALL, TAG_NONE, 0L, 0L); + assertStatsEntry(stats, "ip6tnl0", UID_ALL, SET_ALL, TAG_NONE, 0L, 0L); + } + @Test public void testNetworkStatsSingle() throws Exception { stageFile(R.raw.xt_qtaguid_iface_typical, file("net/xt_qtaguid/iface_stat_all")); diff --git a/tests/net/java/com/android/server/IpSecServiceParameterizedTest.java b/tests/net/java/com/android/server/IpSecServiceParameterizedTest.java index d9d4eeba90..1618e07a79 100644 --- a/tests/net/java/com/android/server/IpSecServiceParameterizedTest.java +++ b/tests/net/java/com/android/server/IpSecServiceParameterizedTest.java @@ -268,6 +268,31 @@ public class IpSecServiceParameterizedTest { anyInt()); } + public void testCreateTwoTransformsWithSameSpis() throws Exception { + IpSecConfig ipSecConfig = new IpSecConfig(); + addDefaultSpisAndRemoteAddrToIpSecConfig(ipSecConfig); + addAuthAndCryptToIpSecConfig(ipSecConfig); + + IpSecTransformResponse createTransformResp = + mIpSecService.createTransform(ipSecConfig, new Binder()); + assertEquals(IpSecManager.Status.OK, createTransformResp.status); + + // Attempting to create transform a second time with the same SPIs should throw an error... + try { + mIpSecService.createTransform(ipSecConfig, new Binder()); + fail("IpSecService should have thrown an error for reuse of SPI"); + } catch (IllegalStateException expected) { + } + + // ... even if the transform is deleted + mIpSecService.deleteTransform(createTransformResp.resourceId); + try { + mIpSecService.createTransform(ipSecConfig, new Binder()); + fail("IpSecService should have thrown an error for reuse of SPI"); + } catch (IllegalStateException expected) { + } + } + @Test public void testDeleteTransform() throws Exception { IpSecConfig ipSecConfig = new IpSecConfig(); diff --git a/tests/net/res/raw/net_dev_typical b/tests/net/res/raw/net_dev_typical new file mode 100644 index 0000000000..290bf03eb9 --- /dev/null +++ b/tests/net/res/raw/net_dev_typical @@ -0,0 +1,8 @@ +Inter-| Receive | Transmit + face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed + lo: 8308 116 0 0 0 0 0 0 8308 116 0 0 0 0 0 0 +rmnet0: 1507570 2205 0 0 0 0 0 0 489339 2237 0 0 0 0 0 0 + ifb0: 52454 151 0 151 0 0 0 0 0 0 0 0 0 0 0 0 + ifb1: 52454 151 0 151 0 0 0 0 0 0 0 0 0 0 0 0 + sit0: 0 0 0 0 0 0 0 0 0 0 148 0 0 0 0 0 +ip6tnl0: 0 0 0 0 0 0 0 0 0 0 151 151 0 0 0 0