Loading services/core/java/com/android/server/net/watchlist/WatchlistConfig.java +14 −6 Original line number Diff line number Diff line Loading @@ -161,7 +161,7 @@ class WatchlistConfig { public boolean containsDomain(String domain) { final CrcShaDigests domainDigests = mDomainDigests; if (domainDigests == null) { Slog.wtf(TAG, "domainDigests should not be null"); // mDomainDigests is not initialized return false; } // First it does a quick CRC32 check. Loading @@ -177,7 +177,7 @@ class WatchlistConfig { public boolean containsIp(String ip) { final CrcShaDigests ipDigests = mIpDigests; if (ipDigests == null) { Slog.wtf(TAG, "ipDigests should not be null"); // mIpDigests is not initialized return false; } // First it does a quick CRC32 check. Loading Loading @@ -234,12 +234,20 @@ class WatchlistConfig { public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { pw.println("Domain CRC32 digest list:"); if (mDomainDigests != null) { mDomainDigests.crc32Digests.dump(fd, pw, args); } pw.println("Domain SHA256 digest list:"); if (mDomainDigests != null) { mDomainDigests.sha256Digests.dump(fd, pw, args); } pw.println("Ip CRC32 digest list:"); if (mIpDigests != null) { mIpDigests.crc32Digests.dump(fd, pw, args); } pw.println("Ip SHA256 digest list:"); if (mIpDigests != null) { mIpDigests.sha256Digests.dump(fd, pw, args); } } } services/tests/servicestests/src/com/android/server/net/watchlist/WatchlistConfigTests.java +12 −0 Original line number Diff line number Diff line Loading @@ -33,12 +33,15 @@ import org.junit.Test; import org.junit.runner.RunWith; import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; /** * runtest frameworks-services -c com.android.server.net.watchlist.WatchlistConfigTests */ Loading Loading @@ -117,6 +120,15 @@ public class WatchlistConfigTests { assertEquals(TEST_XML_1_HASH, HexDump.toHexString(config.getWatchlistConfigHash())); } @Test public void testWatchlistConfig_testDumpDoesNotCrash() throws Exception { WatchlistConfig config = new WatchlistConfig(new File("/not_exist_path.xml")); ByteArrayOutputStream bs = new ByteArrayOutputStream(2048); PrintWriter pw = new PrintWriter(bs); // Make sure dump still works even watchlist does not exist config.dump(null, pw, null); } private static void copyWatchlistConfigXml(Context context, String xmlAsset, File outFile) throws IOException { writeToFile(outFile, readAsset(context, xmlAsset)); Loading Loading
services/core/java/com/android/server/net/watchlist/WatchlistConfig.java +14 −6 Original line number Diff line number Diff line Loading @@ -161,7 +161,7 @@ class WatchlistConfig { public boolean containsDomain(String domain) { final CrcShaDigests domainDigests = mDomainDigests; if (domainDigests == null) { Slog.wtf(TAG, "domainDigests should not be null"); // mDomainDigests is not initialized return false; } // First it does a quick CRC32 check. Loading @@ -177,7 +177,7 @@ class WatchlistConfig { public boolean containsIp(String ip) { final CrcShaDigests ipDigests = mIpDigests; if (ipDigests == null) { Slog.wtf(TAG, "ipDigests should not be null"); // mIpDigests is not initialized return false; } // First it does a quick CRC32 check. Loading Loading @@ -234,12 +234,20 @@ class WatchlistConfig { public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { pw.println("Domain CRC32 digest list:"); if (mDomainDigests != null) { mDomainDigests.crc32Digests.dump(fd, pw, args); } pw.println("Domain SHA256 digest list:"); if (mDomainDigests != null) { mDomainDigests.sha256Digests.dump(fd, pw, args); } pw.println("Ip CRC32 digest list:"); if (mIpDigests != null) { mIpDigests.crc32Digests.dump(fd, pw, args); } pw.println("Ip SHA256 digest list:"); if (mIpDigests != null) { mIpDigests.sha256Digests.dump(fd, pw, args); } } }
services/tests/servicestests/src/com/android/server/net/watchlist/WatchlistConfigTests.java +12 −0 Original line number Diff line number Diff line Loading @@ -33,12 +33,15 @@ import org.junit.Test; import org.junit.runner.RunWith; import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; /** * runtest frameworks-services -c com.android.server.net.watchlist.WatchlistConfigTests */ Loading Loading @@ -117,6 +120,15 @@ public class WatchlistConfigTests { assertEquals(TEST_XML_1_HASH, HexDump.toHexString(config.getWatchlistConfigHash())); } @Test public void testWatchlistConfig_testDumpDoesNotCrash() throws Exception { WatchlistConfig config = new WatchlistConfig(new File("/not_exist_path.xml")); ByteArrayOutputStream bs = new ByteArrayOutputStream(2048); PrintWriter pw = new PrintWriter(bs); // Make sure dump still works even watchlist does not exist config.dump(null, pw, null); } private static void copyWatchlistConfigXml(Context context, String xmlAsset, File outFile) throws IOException { writeToFile(outFile, readAsset(context, xmlAsset)); Loading