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

Commit ec8431f3 authored by Ricky Wai's avatar Ricky Wai Committed by android-build-merger
Browse files

Merge "Handle getNetworkWatchlistConfigHash() without config case" into pi-dev

am: 16ae4cd2

Change-Id: I246ff36bb9d04a2b013ce17bff236c9ab3df3218
parents 85696c66 16ae4cd2
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ class ReportEncoder {
     * Apply DP on watchlist results, and generate a serialized watchlist report ready to store
     * in DropBox.
     */
    @Nullable
    static byte[] encodeWatchlistReport(WatchlistConfig config, byte[] userSecret,
            List<String> appDigestList, WatchlistReportDbHelper.AggregatedResult aggregatedResult) {
        Map<String, Boolean> resultMap = PrivacyUtils.createDpEncodedReportMap(
+12 −6
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server.net.watchlist;

import android.annotation.Nullable;
import android.os.FileUtils;
import android.util.AtomicFile;
import android.util.Log;
@@ -55,9 +56,6 @@ class WatchlistConfig {
    private static final String NETWORK_WATCHLIST_DB_FOR_TEST_PATH =
            "/data/misc/network_watchlist/network_watchlist_for_test.xml";

    // Hash for null / unknown config, a 32 byte array filled with content 0x00
    private static final byte[] UNKNOWN_CONFIG_HASH = new byte[32];

    private static class XmlTags {
        private static final String WATCHLIST_CONFIG = "watchlist-config";
        private static final String SHA256_DOMAIN = "sha256-domain";
@@ -228,16 +226,21 @@ class WatchlistConfig {
        return mIsSecureConfig;
    }

    @Nullable
    /**
     * Get watchlist config SHA-256 digest.
     * Return null if watchlist config does not exist.
     */
    public byte[] getWatchlistConfigHash() {
        if (!mXmlFile.exists()) {
            return UNKNOWN_CONFIG_HASH;
            return null;
        }
        try {
            return DigestUtils.getSha256Hash(mXmlFile);
        } catch (IOException | NoSuchAlgorithmException e) {
            Log.e(TAG, "Unable to get watchlist config hash", e);
        }
        return UNKNOWN_CONFIG_HASH;
        return null;
    }

    /**
@@ -271,8 +274,10 @@ class WatchlistConfig {
    }

    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        pw.println("Watchlist config hash: " + HexDump.toHexString(getWatchlistConfigHash()));
        final byte[] hash = getWatchlistConfigHash();
        pw.println("Watchlist config hash: " + (hash != null ? HexDump.toHexString(hash) : null));
        pw.println("Domain CRC32 digest list:");
        // mDomainDigests won't go from non-null to null so it's safe
        if (mDomainDigests != null) {
            mDomainDigests.crc32Digests.dump(fd, pw, args);
        }
@@ -281,6 +286,7 @@ class WatchlistConfig {
            mDomainDigests.sha256Digests.dump(fd, pw, args);
        }
        pw.println("Ip CRC32 digest list:");
        // mIpDigests won't go from non-null to null so it's safe
        if (mIpDigests != null) {
            mIpDigests.crc32Digests.dump(fd, pw, args);
        }
+3 −0
Original line number Diff line number Diff line
@@ -346,6 +346,7 @@ class WatchlistLoggingHandler extends Handler {
     * @param ipAddresses Ip address that you want to search in watchlist.
     * @return Ip address that exists in watchlist, null if it does not match anything.
     */
    @Nullable
    private String searchIpInWatchlist(String[] ipAddresses) {
        for (String ipAddress : ipAddresses) {
            if (isIpInWatchlist(ipAddress)) {
@@ -377,6 +378,7 @@ class WatchlistLoggingHandler extends Handler {
     * @param host Host that we want to search.
     * @return Domain that exists in watchlist, null if it does not match anything.
     */
    @Nullable
    private String searchAllSubDomainsInWatchlist(String host) {
        if (host == null) {
            return null;
@@ -392,6 +394,7 @@ class WatchlistLoggingHandler extends Handler {

    /** Get all sub-domains in a host */
    @VisibleForTesting
    @Nullable
    static String[] getAllSubDomains(String host) {
        if (host == null) {
            return null;
+1 −0
Original line number Diff line number Diff line
@@ -144,6 +144,7 @@ class WatchlistReportDbHelper extends SQLiteOpenHelper {
     * Aggregate all records in database before input timestamp, and return a
     * rappor encoded result.
     */
    @Nullable
    public AggregatedResult getAggregatedRecords(long untilTimestamp) {
        final String selectStatement = WhiteListReportContract.TIMESTAMP + " < ?";

+1 −1
Original line number Diff line number Diff line
@@ -86,7 +86,7 @@ class WatchlistSettings {
        }
    }

    public void reloadSettings() {
    private void reloadSettings() {
        if (!mXmlFile.exists()) {
            // No settings config
            return;
Loading