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

Commit c34a20b5 authored by Chen Chen's avatar Chen Chen Committed by Cherrypicker Worker
Browse files

BluetoothMetrics: Upload readable sha256, instead of bytes

Bug: 264937355
Test: atest BluetoothInstrumentationTests
(cherry picked from https://android-review.googlesource.com/q/commit:c5a164cfbf2771d49ccfa2a501fd8e6fcc490745)
Merged-In: Ica31ffcc22d5a75aa82b9e2f91b9239d63506a40
Change-Id: Ica31ffcc22d5a75aa82b9e2f91b9239d63506a40
parent ceb25ac1
Loading
Loading
Loading
Loading
+8 −5
Original line number Original line Diff line number Diff line
@@ -27,6 +27,7 @@ import com.android.bluetooth.BluetoothStatsLog;


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.File;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileInputStream;
@@ -276,16 +277,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);
        }
        }
    }
    }