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

Commit c5a164cf authored by Chen Chen's avatar Chen Chen
Browse files

BluetoothMetrics: Upload readable sha256, instead of bytes

Bug: 264937355
Test: atest BluetoothInstrumentationTests
Change-Id: Ica31ffcc22d5a75aa82b9e2f91b9239d63506a40
parent d70deb76
Loading
Loading
Loading
Loading
+8 −5
Original line number Original line Diff line number Diff line
@@ -29,6 +29,7 @@ import com.android.internal.annotations.VisibleForTesting;


import com.google.common.hash.BloomFilter;
import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnels;
import com.google.common.hash.Funnels;
import com.google.common.hash.Hashing;


import java.io.ByteArrayInputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.File;
@@ -304,16 +305,18 @@ public class MetricsLogger {
        if (matchedSha256 == null) {
        if (matchedSha256 == null) {
            return false;
            return false;
        }
        }
        statslogBluetoothDeviceNames(metricId, matchedString, matchedSha256);
        statslogBluetoothDeviceNames(
                metricId,
                matchedString,
                Hashing.sha256().hashString(matchedString, StandardCharsets.UTF_8).toString());
        return true;
        return true;
    }
    }


    protected void statslogBluetoothDeviceNames(int metricId, String matchedString, byte[] sha256) {
    protected void statslogBluetoothDeviceNames(int metricId, String matchedString, String sha256) {
        String sha256String = new String(sha256);
        Log.d(TAG,
        Log.d(TAG,
                "Uploading sha256 hash of matched bluetooth device name: " + sha256String);
                "Uploading sha256 hash of matched bluetooth device name: " + sha256);
        BluetoothStatsLog.write(
        BluetoothStatsLog.write(
                BluetoothStatsLog.BLUETOOTH_HASHED_DEVICE_NAME_REPORTED, metricId, sha256String);
                BluetoothStatsLog.BLUETOOTH_HASHED_DEVICE_NAME_REPORTED, metricId, sha256);
    }
    }


    protected static byte[] getSha256(String name) {
    protected static byte[] getSha256(String name) {
+1 −1
Original line number Original line Diff line number Diff line
@@ -74,7 +74,7 @@ public class MetricsLoggerTest {


        @Override
        @Override
        protected void statslogBluetoothDeviceNames(
        protected void statslogBluetoothDeviceNames(
                int metricId, String matchedString, byte[] sha256) {
                int metricId, String matchedString, String sha256) {
            mTestableDeviceNames.merge(matchedString, 1, Integer::sum);
            mTestableDeviceNames.merge(matchedString, 1, Integer::sum);
        }
        }
    }
    }