Skip to content
Snippets Groups Projects
Commit 039971fa authored by Chen Chen's avatar Chen Chen Committed by Cherrypicker Worker
Browse files

BluetoothMetrics: Add fallback solution for device names

Bug: 264937355
Test: atest BluetoothInstrumentationTests
(cherry picked from https://android-review.googlesource.com/q/commit:41d98ac1632528f4a4aa240748773780e5236085)
Merged-In: If7d8aa463decc99cf95437d7a608ed2612323560
Change-Id: If7d8aa463decc99cf95437d7a608ed2612323560
parent ceb25ac1
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,7 @@ import com.android.bluetooth.BluetoothStatsLog;
import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnels;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
......@@ -41,8 +42,8 @@ import java.util.HashMap;
*/
public class MetricsLogger {
private static final String TAG = "BluetoothMetricsLogger";
private static final String BLOOMFILTER_PATH = "/data/misc/bluetooth/metrics";
private static final String BLOOMFILTER_FILE = "/devices";
private static final String BLOOMFILTER_PATH = "/data/misc/bluetooth";
private static final String BLOOMFILTER_FILE = "/devices_for_metrics";
public static final String BLOOMFILTER_FULL_PATH = BLOOMFILTER_PATH + BLOOMFILTER_FILE;
public static final boolean DEBUG = false;
......@@ -96,8 +97,19 @@ public class MetricsLogger {
FileInputStream in = new FileInputStream(new File(path));
mBloomFilter = BloomFilter.readFrom(in, Funnels.byteArrayFunnel());
mBloomFilterInitialized = true;
} catch (IOException e) {
Log.w(TAG, "MetricsLogger can't read the BloomFilter file");
} catch (IOException e1) {
Log.w(TAG, "MetricsLogger can't read the BloomFilter file.");
byte[] bloomfilterData = DeviceBloomfilterGenerator.hexStringToByteArray(
DeviceBloomfilterGenerator.BLOOM_FILTER_DEFAULT);
try {
mBloomFilter = BloomFilter.readFrom(
new ByteArrayInputStream(bloomfilterData), Funnels.byteArrayFunnel());
mBloomFilterInitialized = true;
Log.i(TAG, "The default bloomfilter is used");
return true;
} catch (IOException e2) {
Log.w(TAG, "The default bloomfilter can't be used.");
}
return false;
}
return true;
......@@ -237,7 +249,7 @@ public class MetricsLogger {
}
protected boolean logSanitizedBluetoothDeviceName(int metricId, String deviceName) {
if (!mBloomFilterInitialized) {
if (!mBloomFilterInitialized || deviceName == null) {
return false;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment